To reason in FOL we can either convert it into propositional logic or work directly on quantified sentences using unification.
Reduction to Propositional Inference
Universal instantiation (UI) substitutes any ground term g for the variable: from ∀x α infer α{x/g}. Existential instantiation (EI) replaces the variable by a new constant (a Skolem constant) not used elsewhere: from ∃x α infer α{x/K}. A KB can be propositionalised by instantiating every quantified sentence with every constant; then propositional inference applies. This is sound and complete, but wasteful, since most instances are irrelevant, and with function symbols (FatherOf(FatherOf(x)), ...) there are infinitely many terms. Herbrand's theorem says that if a sentence is entailed, a proof uses only a finite set of instances, but we may not know how large.
Unification
Direct, lifted inference avoids creating irrelevant instances. It uses unification: finding a substitution θ, a set of variable bindings {x/term}, that makes two sentences identical. UNIFY(p, q) = θ if pθ = qθ. Examples: UNIFY(Knows(John, x), Knows(John, Jane)) = {x/Jane}; UNIFY(Knows(John, x), Knows(y, Mother(y))) = {y/John, x/Mother(John)}; UNIFY(Knows(John, x), Knows(x, Elizabeth)) fails, because x cannot be both John and Elizabeth (this is solved by standardising apart, renaming variables so the two sentences share none). The result should be the most general unifier (MGU), the one that places the fewest restrictions on the variables. The occur check prevents binding a variable to a term containing it (x with F(x)).
Definition: Unification. The process of finding a substitution for variables that makes two logical expressions identical; the most general unifier makes the fewest commitments.
Generalised Modus Ponens and Lifting
Generalised Modus Ponens (GMP) is the lifted version of modus ponens: for atomic sentences pᵢ, pᵢ′ and q, if there is a substitution θ with pᵢ′θ = pᵢθ for all i, then from p₁′, ..., pₙ′ and (p₁ ∧ ... ∧ pₙ → q) infer qθ. Example: rule King(x) ∧ Greedy(x) → Evil(x); facts King(John), Greedy(John); θ = {x/John} gives Evil(John) in a single step. The inference is lifted because it works directly on variables and does not instantiate the rule for every object. Lifted inference is the basis of forward chaining, backward chaining and resolution in FOL.
Efficiency
Finding matches between rule premises and known facts is the costly part: indexing facts by predicate speeds it up, and ordering the premises of a rule matters (most constrained first). The Rete algorithm keeps partial matches in a network so that expert-system shells do not repeat work.
Table 3.3: Propositionalisation versus lifting
| Basis | Propositionalisation | Lifted inference |
|---|---|---|
| Method | Instantiate rules with all constants | Unify directly |
| Instances | Many irrelevant | Only needed ones |
| Function symbols | Infinite instances | Handled by unification |
| Efficiency | Poor | Better |
Example 3.3: Unification examples
Problem: Find the most general unifier, if one exists: (a) Knows(John, x) and Knows(y, Mother(y)); (b) P(x, F(x)) and P(a, y); (c) Q(x, x) and Q(a, b).
Solution:
- (a) Match John with y: y/John. Then x with Mother(y) → Mother(John): θ = {y/John, x/Mother(John)}.
- (b) x/a, then y/F(a): θ = {x/a, y/F(a)}.
- (c) x/a makes the first Q(a, a); the second argument needs x = b, but x is already a: a ≠ b, so unification fails.
Result: (a) {y/John, x/Mother(John)}; (b) {x/a, y/F(a)}; (c) no unifier.
def is_var(t):
return isinstance(t, str) and t[0].islower()
def walk(t, s):
while is_var(t) and t in s:
t = s[t]
return t
def unify(a, b, s):
a, b = walk(a, s), walk(b, s)
if a == b:
return s
if is_var(a):
return {**s, a: b}
if is_var(b):
return {**s, b: a}
if isinstance(a, tuple) and isinstance(b, tuple) \
and len(a) == len(b):
for x, y in zip(a, b):
s = unify(x, y, s)
if s is None:
return None
return s
return None
def full(t, s):
t = walk(t, s)
if isinstance(t, tuple):
return tuple(full(u, s) for u in t)
return t
s1 = unify(("Knows", "John", "x"),
("Knows", "y", ("Mother", "y")), {})
print({k: full(v, s1) for k, v in s1.items()})
print(unify(("Q", "x", "x"), ("Q", "A", "B"), {}))
Output
{'y': 'John', 'x': ('Mother', 'John')}
None
Common mistakes
- Forgetting to standardise apart variables of the two sentences.
- Binding a constant to a different constant; constants never unify unless identical.
- Skipping the occur check and creating infinite terms.
- Instantiating existentials with an already used constant instead of a new Skolem constant.
Key takeaways
- UI substitutes ground terms for ∀ variables; EI uses a new Skolem constant for ∃.
- Unification finds a substitution making two expressions identical; the MGU is the most general.
- Generalised Modus Ponens does inference without instantiating every object (lifting).
- Occur check and standardising apart are needed.
Practice questions
- What is unification?
- What is lifting?
- Why does UNIFY(Knows(John, x), Knows(x, Elizabeth)) fail?
Answers to the practice questions
- Finding a substitution that makes two logical expressions identical.
- Doing inference directly on quantified rules using unification, instead of instantiating them for every object.
- Both sentences use x; x cannot be John and Elizabeth at once, unless the variables are standardised apart.
Sources
- Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit III
