A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Substitution and Unification

College Depth 74 in the knowledge graph ☐ I know this ☆ Set as goal
588topics build on this
339prerequisites beneath it
See this on the map →
First-Order Logic SyntaxTerms and Atomic Formulas in FOL+1 more→→First-Order ResolutionMost General Unifier (MGU)+1 more
substitution unification most-general-unifier variable-capture automated-reasoning

Core Idea

Substitution replaces free occurrences of a variable x in a formula with a term t, written φ[t/x]. The operation must be capture-avoiding: if t contains a variable y that would become bound in φ, the bound variable must first be renamed (alpha-conversion) to prevent the substituted variable from being inadvertently captured. Unification is the inverse problem — given two terms or atoms, find a substitution (called a unifier) that makes them syntactically identical. The most general unifier (MGU) is the least committal such substitution. Robinson's unification algorithm computes the MGU in near-linear time, and it is the engine behind resolution-based theorem proving and logic programming.

How It's Best Learned

Perform substitutions by hand on formulas with nested quantifiers, deliberately encountering variable-capture problems and fixing them. Then unify pairs of atomic formulas step by step using Robinson's algorithm, building the MGU incrementally.

Common Misconceptions

Explainer

From your work on first-order logic syntax and terms and atoms, you know that a first-order formula is built from terms (variables, constants, function applications) and atomic formulas (predicate applications to terms), combined with logical connectives and quantifiers. Substitution is the operation of systematically replacing a variable with a term throughout a formula — it is how you instantiate general claims and how inference rules like universal instantiation are formally defined.

The notation φ[t/x] means "replace every free occurrence of variable x in φ with term t." The critical qualifier is *free*: bound occurrences of x (those under a quantifier ∀x or ∃x) are not touched, because they are not the same x — they are a different, locally scoped variable that happens to share the same name. The danger is variable capture: if t contains a free variable y, and y happens to be bound in φ at the location where x appears, substituting naively makes y's free occurrence "fall under" a quantifier it didn't before. For example, substituting y for x in ∃y (x = y) should give ∃y (y = y) — but naive substitution captures the free y under the ∃y, silently changing the formula's meaning. The fix is alpha-conversion: rename the bound variable first (∃y (x = y) → ∃z (x = z)), then substitute safely (∃z (y = z)).

Unification is the inverse problem: given two terms or atomic formulas s and t, find a substitution σ such that σ(s) = σ(t) — they become syntactically identical after applying σ. Such a σ is a unifier. The most general unifier (MGU) is the least committal one: it makes the minimum commitments necessary to achieve identity, leaving all other variables free to be instantiated later. For example, to unify P(f(x), y) with P(f(a), g(b)), the MGU sets x ↦ a and y ↦ g(b). Any other unifier for these two atoms could be obtained by composing the MGU with a further substitution.

Robinson's unification algorithm computes the MGU (or reports failure) by walking two terms in parallel. At each step, if both sides have the same function symbol or constant, recurse on subterms. If one side is a variable x not appearing in the other term t, extend the unifier with x ↦ t. If x appears in t (the occurs check), the algorithm fails — there is no finite term satisfying x = f(x). The algorithm runs in near-linear time (with path compression) and is the computational heart of resolution theorem proving and logic programming (Prolog). Every resolution step finds the MGU of two complementary literals and applies it before cancellation; every Prolog goal is solved by finding the MGU between the goal and a clause head.

Together, substitution and unification transform first-order inference from a semantic matching task — "does this formula follow from those?" — into a syntactic computation over term structure. The MGU is the minimal syntactic bridge between two expressions, and its minimality is essential: using a more specific unifier than necessary forecloses future flexibility, while the MGU commits only to what logic forces.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Introduction to Propositional Logic → Introduction to Predicate Logic (First-Order Logic) → First-Order Logic Syntax → Terms and Atomic Formulas in FOL → Variable Binding and Scope → Substitution and Unification

Longest path: 75 steps · 339 total prerequisite topics

Prerequisites (3)

Leads To (3)