AI Glossary / Graphs and symbolic AI / Intermediate
Unification
Definition
Unification is the process of finding substitutions for variables that make symbolic expressions identical. In ordinary first-order syntactic unification, the expressions must match in structure after the substitutions are applied consistently. If no suitable substitution exists, unification fails.
What it means
Suppose a rule refers to Delivers(X, Parcel7), and a fact says Delivers(Van2, Parcel7). Replacing X with Van2 makes the expressions agree. That replacement allows a reasoning system to apply a general rule to a particular case.
Variables can occur on either side, so unification is more general than matching a fixed record against a pattern on just one side. Repeated occurrences of a variable must receive the same replacement. A variable is not a blank that can mean something different at every occurrence.
The process compares formal symbols. It does not discover that two different names identify the same person, translate synonyms or assess whether an asserted fact is true in the world. Those tasks require additional representations or reasoning.
How it works
A unification procedure compares the outer symbols and then their corresponding arguments. Matching compound expressions must have compatible function or predicate symbols and the same number of arguments. Different fixed constants cannot be repaired by assigning a variable elsewhere.
When it encounters an unbound variable, the procedure may bind it to the corresponding term. Later comparisons must respect that binding, and substitutions must be propagated through other terms as needed. A successful procedure commonly returns a most general unifier, preserving freedom that the comparison does not require it to remove.
For finite first-order terms, an occurs check prevents a variable from being bound to a term containing itself, such as X = Box(X). Some programming systems support cyclic terms under different semantics. Their behavior must not be confused with ordinary finite-term unification.
Three practical examples
- A rule engine connects a general eligibility rule to a fact about a particular symbolic customer record.
- A logic program solves a query by unifying it with a rule's head and then pursuing the rule's remaining conditions.
- A type-inference system uses unification-style operations to reconcile type variables with structured type expressions, subject to that language's rules.
Think of it this way
Think of aligning two forms with named blanks. If both forms have the same structure, you can fill blanks so the completed forms agree. Every blank carrying the same name must receive the same content.
The analogy stops at structural agreement. Two completed forms can match perfectly while containing inaccurate information. Unification establishes a formal relationship between expressions, not the factual reliability of their contents.
Worked example
Following a repeated variable
Take the expressions Shipment(X, Pack(Y), Y) and Shipment(Van3, Pack(Crate8), Crate8). Their outer symbols and three argument positions agree.
The first arguments require X = Van3. Comparing the second arguments means comparing Y with Crate8 inside the matching Pack structures, so Y = Crate8. The third arguments then agree with that same binding. Applying {X → Van3, Y → Crate8} to the first expression makes it identical to the second.
Now change the second expression's final argument to Crate9. The second position still requires Y = Crate8, but the third requires Y = Crate9. With Crate8 and Crate9 treated as distinct constants, unification fails. Assigning Y differently in the two positions would violate the meaning of a single variable. This is an original symbolic example, not a claim about actual shipment data.
Illustrative case study
The fictional AlderRules team writes a rule that requires the same device identifier to appear in a service request and its maintenance record. A prototype accidentally uses two independent variables, so it can combine information about different devices.
The team replaces them with one shared variable where identity is required. Unification now enforces a consistent binding across those positions. It also gives separately invoked rules fresh local variable names to avoid unintended links between unrelated requests.
The case illustrates variable discipline. It does not suggest that correct symbolic matching verifies the real-world device label or the quality of the underlying maintenance record.
Common misconceptions and mistakes
- Unification is approximate text similarity. Ordinary syntactic unification requires exact structural agreement after substitution.
- A repeated variable can take different values in different positions. All its occurrences must respect the same substitution.
- Every implementation handles self-referential terms identically. Finite-term logic and systems supporting cyclic terms have different requirements.
Business use
Unification supports explainable symbolic rules, logic programming and some programming-language tools. It can make the connection between a general rule and a particular case explicit: the substitution shows which entities filled each variable.
Design predicate names, argument order and identifier conventions carefully. Keep variable scope clear, especially when combining rules. If a business process treats two identifiers as equivalent, encode and validate that relationship separately rather than expecting syntactic unification to infer it. When selecting an implementation, check its treatment of cyclic terms and its interaction with any additional constraint system.
People also ask
Does unification evaluate arithmetic automatically?
Not in ordinary syntactic unification. The term 2 + 3 is not simply replaced with 5 unless the surrounding system provides evaluation rules.
Can two expressions have several unifiers?
Yes. A most general unifier leaves unnecessary choices open, and more specific unifiers can be obtained from it.
Does successful unification prove a conclusion?
It can support an inference step, but the rule, premises and inference system still determine what follows.
Check your understanding
Can Pair(X, X) unify with Pair(Red, Blue), where Red and Blue are distinct constants?
Answer: No. The first position requires X = Red and the second requires X = Blue, which cannot both hold for the same variable.
Related terms
- Unifier
- Most general unifier
- First-order logic
- Occur check
- Standardizing apart
- Pattern matching
- substitution
- logic programming
- occurs check
Learn next
Read substitutions and most general unifiers. Practice comparing expressions with repeated variables, and verify each proposed substitution by applying it to both complete expressions.
More in Graphs and symbolic AI
- Type signature - A type signature specifies the types of inputs and outputs associated with a function or operation.
- UCB1 - UCB1 is a multi-armed bandit algorithm that selects an action using its average observed reward plus an exploration bonus.
- UCT - UCT is a method for guiding Monte Carlo tree search by applying upper-confidence-bound ideas at decision nodes.
- Łukasiewicz logic - Łukasiewicz logic is a family of many-valued logics associated with Jan Łukasiewicz.
- Unary constraint - A unary constraint is a rule that restricts the allowed values of one variable in a constraint satisfaction problem.
- Unbounded cost search - Unbounded-cost search seeks a valid solution without requiring its cost to fall below a specified threshold or within a specified factor of the best...
Sources
Stuart Russell and Peter Norvig, author-hosted chapter on inference in first-order logic, unification section: https://aima.cs.berkeley.edu/4th-ed/pdfs/newchap09.pdf
SWI-Prolog developers, unify_with_occurs_check/2 and cyclic-term behaviour: https://www.swi-prolog.org/pldoc/man?predicate=unify_with_occurs_check/2
The relevant primary explanations were read. Finite first-order terms are the default scope here; the software documentation shows why implementation behaviour needs an explicit qualification. The symbolic examples are original.
Previous: Unidirectional language model Next: Unifier