pub fn apply_subst_to_term(term: &ProofTerm, subst: &Substitution) -> ProofTermExpand description
Apply a substitution to a term.
Replaces all variables in the term according to the substitution mapping.
Handles transitive chains: if {x ↦ y, y ↦ z}, then applying to x yields z.
The substitution is read as TRIANGULAR, which is what a unifier produces: a replacement is itself
resolved against the map. That is sound only on an acyclic map, and a unifier’s is (its occurs check
refuses x ↦ …x…). A cyclic map has no resolution, so reaching x again while resolving x panics,
naming the cycle, instead of recursing until the stack is gone. Instantiating one binder,
body[x := t] with t free to mention x, is not this operation: use instantiate_expr.
§Arguments
term- The term to transformsubst- The substitution mapping variables to replacement terms
§Returns
A new term with all substitutions applied.
§Example
use logicaffeine_proof::{ProofTerm, unify::{Substitution, apply_subst_to_term}};
use std::collections::HashMap;
let mut subst = Substitution::new();
subst.insert("x".into(), ProofTerm::Constant("Socrates".into()));
let term = ProofTerm::Function(
"Mortal".into(),
vec![ProofTerm::Variable("x".into())]
);
let result = apply_subst_to_term(&term, &subst);
// result = Mortal(Socrates)