Expand description
§First-Order Unification
This module implements Robinson’s unification algorithm for first-order terms. Unification is a fundamental operation in automated theorem proving, logic programming, and type inference.
§Overview
Unification finds a most general unifier (MGU) that makes two terms syntactically equal:
- Given terms
sandt, find substitutionθsuch thatsθ = tθ - The MGU is the most general such substitution (no more specific than necessary)
§Examples
use tensorlogic_ir::{Term, Substitution, unify_terms};
// Unify P(x, f(y)) with P(a, f(b))
let term1 = Term::var("x");
let term2 = Term::constant("a");
let result = unify_terms(&term1, &term2);
assert!(result.is_ok());
let subst = result.unwrap();
assert_eq!(subst.apply(&term1), term2);§Algorithm
We use Robinson’s unification algorithm with occur-check:
- If both terms are identical, return empty substitution
- If one is a variable, bind it to the other (with occur-check)
- If both are compound terms, recursively unify arguments
- Otherwise, unification fails
§Applications
- Theorem Proving: Resolution requires unification of complementary literals
- Logic Programming: Pattern matching in Prolog-style languages
- Type Inference: Hindley-Milner type inference uses unification
- Sequent Calculus: Term substitution in quantifier rules
Structs§
- Substitution
- A substitution maps variables to terms.
Functions§
- anti_
unify_ terms - Anti-unification finds the most specific generalization (MSG) of two terms.
- are_
unifiable - Check if two terms are unifiable (without computing the unifier).
- lgg_
terms - Compute the least general generalization (LGG) of a list of terms.
- rename_
vars - Rename variables in a term to avoid conflicts.
- unify_
term_ list - Attempt to unify a list of term pairs.
- unify_
terms - Unify two terms, returning the most general unifier (MGU).