Lecture 7 · First-Order Logic: Semantics, Normal Forms, Resolution and Unification I

Introduction to Automated Reasoning · Lecture 07。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 7 · Tue 01/27/2026 · FOL: semantics, normal forms, resolution, unification I (Hanna Lachnitt). Reading: Bradley & Manna (CC) §2.2–2.5; Enderton (MI) §2.2 up to “Definability in a Structure”. Basis: The Stanford slides are on Canvas and not public. This lecture follows the public Iowa decks (CS:4980, Cesare Tinelli, Spring 2024), which say they are adapted from slides by Clark Barrett, Caroline Trippel and Andrew (Haoze) Wu (Stanford):

  • the semantics half of First-order Logic: Syntax and Semantics;
  • the first parts of Proof systems for First-order Logic: semantic arguments, PNF and clausal form, resolution with INST.

“The slides” below means those decks. Reused from them:

  • interpretations, the term and formula semantics, the set-theory and family examples;
  • entailment and validity, the entailment exercise;
  • invariance, the deduction theorem, the free-variable theorems;
  • the quantifier rules of semantic arguments and their three examples, the termination example;
  • the transformation to clausal form with its running example; Skolemization;
  • the INST rule and the unification-based resolvent example.

These notes add:

  • a finite model finder that grounds formulas to propositional logic and calls Lecture 5’s CDCL solver;
  • machine checks of every example, which find:
    • a clause-form step order that is unsound for ⇔;
    • a mislabelled rule on the termination slide;
    • a precise reading of the people-slide typo;
  • a tableau prover for FOL, tried on Pelletier’s problems;
  • unification (Robinson; Martelli–Montanari), with the occurs check and exponential blow-up measured.

The experiments and their code were designed for these notes and do not reflect what was said in class. Code: code/lecture07/ (5 scripts + 2 modules; Python standard library only, matplotlib optional; from 2 to about 25 seconds each) Reading time: 4 hours including running the code


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Define an interpretation of a signature, and compute the value of terms and the truth of formulas in it.
  2. Define satisfiability, validity, entailment and equivalence in FOL, and state the invariance, deduction and free-variable theorems.
  3. Find counter-models with a finite model finder, and explain why “no counter-model up to size n” is not a proof.
  4. Write semantic-argument proofs with the quantifier rules, and explain why proof search for FOL cannot always terminate.
  5. Transform a sentence into clausal form (NNF, prenex, PCNF, Skolemization), and explain why the result is only equisatisfiable.
  6. Compute a most general unifier, explain the occurs check, and say why unification, not instantiation, makes first-order resolution practical.

0.2 Prerequisites and scope

AssumedIntroduced hereDeveloped later
FOL syntax, FV, capture-avoiding substitution (Lecture 6)interpretations, truth, validitytheories: restricting the interpretations (Lecture 8, 10 on)
semantic arguments for PL (Lecture 1)quantifier rules, FOL tableauxHerbrand’s theorem (Lectures 8, 17)
CNF, Tseitin, CDCL (Lectures 2, 5)finite model finding by SATbit-blasting, model checking (Lectures 9, 16)
resolution for PL (Lecture 2)clausal form, unificationthe resolution prover (Lecture 8)

0.3 Map

§1  interpretations: giving the symbols a meaning                                       ← code 01
§2  truth, validity, entailment, and the slides' theorems                                 ← code 01, 02
§3  searching for models: a finite model finder built on CDCL                             ← code 02
§4  semantic arguments with quantifiers; why proof search may not terminate              ← code 03
§5  normal forms: prenex, Skolem, clausal                                                 ← code 04
§6  unification                                                                           ← code 05
§7  first-order resolution: the idea                                                      ← code 05
§8 summary   §9 common pitfalls   §10 exercises   §11 further reading   §12 next lecture

0.4 Notation

SymbolMeaning
II, σI\sigma^I, fIf^I, xIx^Ian interpretation; the domain of sort σ, the function for ff, the value of xx
I[x↦a]I[x \mapsto a]II with xx interpreted as aa
I⊨αI \models \alpha / I⊭αI \not\models \alphaII satisfies / falsifies α\alpha
Φ⊨α\Phi \models \alpha, ⊨α\models \alpha, α≡β\alpha \equiv \betaentailment, validity, equivalence
{x←t,… }\{x \leftarrow t, \dots\}a substitution; tσt\sigma applies it
mgumost general unifier
fxf_xthe Skolem symbol for ∃x\exists x

0.5 The code of this lecture

fol_semantics.py contains:

  • Structure and evaluate, plus term_steps for step-by-step term evaluation;
  • find_model, a finite model finder: grounding, symmetry breaking for constants, Tseitin (Lecture 2), CDCL (Lecture 5), and a re-check of every model;
  • enumerate_structures, brute force for tiny cases;
  • semantic_argument, a tableau prover with a fair strategy;
  • normal forms: nnf, pnf_steps, skolemize, clausal_form.

unify.py contains:

  • substitutions: apply, compose, is_instance_of;
  • Robinson’s algorithm, in eager and triangular modes;
  • Martelli–Montanari’s rules (unify_mm), with a trace;
  • match, and the blow-up family.

1. Interpretations: giving the symbols a meaning

A signature (Lecture 6) fixes vocabulary. An interpretation II of Σ (and of a sort context Γ) fixes meaning:

  1. each sort σ gets a non-empty set σI\sigma^I, its domain;
  2. each function symbol ff of rank ⟨σ1,..,σn,σ⟩\langle \sigma_1, .., \sigma_n, \sigma \rangle gets a total function fI:σ1I×⋯×σnI→σIf^I : \sigma_1^I \times \cdots \times \sigma_n^I \to \sigma^I; predicates are functions into {true,false}\{\mathit{true}, \mathit{false}\};
  3. each variable x:σx : \sigma in Γ gets an element xI∈σIx^I \in \sigma^I.

Every interpretation also treats three things the same way: Bool is {true,false}\{\mathit{true}, \mathit{false}\}, ⊤ and ⊥ are fixed, and ≐σ\doteq_\sigma is identity. Equality is one of the few symbols with a built-in meaning.

One signature, many meanings. The slides interpret a small set-theory signature in two ways:

  • I1I_1: elements are numbers, sets are sets of numbers, and member\mathit{member} is ∈;
  • I2I_2: both sorts are numbers, and member(m,n)\mathit{member}(m, n) means ”nn divides mm”.

Script 01 evaluates the same formulas in both, with the domains cut to 4 elements:

formulaI1I_1I2I_2
member(e1, s2)truefalse
member(e3, s2)falsefalse
member(e0, s0)truetrue
∃s:Set. ∀e:Elem. member(e, s)truetrue

There are infinitely many interpretations of any signature. That is why “true” is never a property of a formula alone: it is a relation between a formula and an interpretation.

Two details that matter later.

  • Domains are non-empty. So ∀x. p(x)⊨∃x. p(x)\forall x.\ p(x) \models \exists x.\ p(x) holds (§2).
  • Functions are total. In the slides’ family signature, papa and mama must give a father and a mother to everyone. Script 01 completes the slides’ partial tables with ancestors, and in a finite domain someone must then be their own ancestor (the pigeonhole principle). Section 3 shows that “everyone has a father and a mother” is therefore a valid sentence: a fact about the logic, not about families.

2. Truth, validity, entailment

Terms are evaluated from the inside out: xIx^I is given, and f(t1,..,tn)I=fI(t1I,..,tnI)f(t_1, .., t_n)^I = f^I(t_1^I, .., t_n^I). Script 01 reproduces the slides’ family example:

    pa(ma(x))  =  pa(ma(Jim))  =  pa(Jill)  =  Jay

Formulas follow the propositional rules for the connectives, plus two new clauses:

(∀x:σ. α)I=true  ⟺  αI[x↦a]=true for every a∈σI,(∃x:σ. α)I=true  ⟺  for some a.(\forall x{:}\sigma.\ \alpha)^I = \mathit{true} \iff \alpha^{I[x \mapsto a]} = \mathit{true} \text{ for every } a \in \sigma^I, \qquad (\exists x{:}\sigma.\ \alpha)^I = \mathit{true} \iff \text{for some } a.

fol_semantics.evaluate is exactly this definition. Over a finite domain, the quantifier clauses become a loop. Over an infinite domain they cannot be computed: this is the first sign of undecidability.

Definitions.

  • Satisfiable: some II satisfies α\alpha.
  • Valid: every II satisfies α\alpha.
  • Entailment Φ⊨α\Phi \models \alpha: every II that satisfies all of Φ also satisfies α.
  • Equivalence α≡β\alpha \equiv \beta: each entails the other.

As in propositional logic, α is valid iff ¬α is unsatisfiable.

The slides’ exercise (script 01) asks for interpretations that satisfy three formulas. The script counts all structures of sizes 1–3 for one binary predicate QQ, and asks the model finder for the smallest model:

formulasatisfying structures, size 1 / 2 / 3smallest model
∀x. ∀y. x = y2/2, 0/16, 0/512size 1 (any Q)
∀x. ∀y. Q(x, y)1/2, 1/16, 1/512size 1, Q everywhere
∀x. ∃y. Q(x, y)1/2, 9/16, 343/512size 1, Q(0,0)
∀x. ∃y. (Q(x, y) ∧ x ≠ y)0/2, 4/16, 216/512size 2

The slides’ theorems. Script 01 checks each instance on random formulas over all 132 structures of sizes 1–2 of a small signature:

theoreminstances checkedheld
Invariance: if II, JJ agree on Σ and on FV(α), then αI=αJ\alpha^I = \alpha^J71,38371,383
Deduction: α⊨β\alpha \models \beta iff ⊨α⇒β\models \alpha \Rightarrow \beta150150
Free variables 1: x∉FV(Φ)⇒(Φ⊨α  ⟺  Φ⊨∀x. α)x \notin \mathrm{FV}(\Phi) \Rightarrow (\Phi \models \alpha \iff \Phi \models \forall x.\ \alpha)6161
Free variables 2: x∉FV(β)⇒(α⊨β  ⟺  ∃x. α⊨β)x \notin \mathrm{FV}(\beta) \Rightarrow (\alpha \models \beta \iff \exists x.\ \alpha \models \beta)6161

This is evidence, not proof. ⊨ ranges over all interpretations, including infinite ones, and the slides prove the theorems by structural induction. A failure would have proved a bug, which makes such checks cheap insurance.

Invariance has an important corollary: the truth of a sentence does not depend on the variable assignment.


3. Searching for models

3.1 A finite model finder built on SAT

To show that Φ⊭α\Phi \not\models \alpha, it suffices to exhibit one interpretation that satisfies Φ and falsifies α: a counter-model. If one exists with a finite domain, it can be found by trying sizes 1, 2, 3, …

For a fixed domain {0,..,n−1}\{0, .., n-1\}, everything unknown about a structure is a finite table. Ground the formulas into propositional logic (Grounder):

  • Predicates: one Boolean variable P_p_a_bP\_p\_a\_b for each predicate pp and argument tuple (a,b)(a, b).
  • Functions: one Boolean variable F_f_a_is_vF\_f\_a\_is\_v for each function ff, argument tuple aa and candidate value vv. Constraints say that exactly one candidate value holds per argument tuple: functions are total and single-valued.
  • Quantifiers: ∀x\forall x becomes a conjunction over the domain, ∃x\exists x a disjunction.
  • Nested terms: a term like f(g(x))f(g(x)) is evaluated symbolically, case by case on the possible values of g(x)g(x).
  • Equality of two domain elements is just identity.

The resulting propositional formula goes through Tseitin’s transformation (Lecture 2) to Lecture 5’s CDCL solver. A model is decoded into a Structure and re-checked with evaluate, so a bug in the grounding could not produce a wrong answer silently.

This is the design of MACE-style finders (McCune’s MACE, Claessen and Sörensson’s Paradox).

3.2 The slides’ entailment exercise

Script 02 runs both searches on each item: a counter-model search, and a proof search (the semantic arguments of §4):

entailmentslidescounter-modelsemantic argument
∀v1. p(v1) ⊨ p(v2)✓none ≤ 4VALID
p(v1) ⊨ ∀v1. p(v1)✗size 2COUNTERMODEL
∀v1. p(v1) ⊨ ∃v2. p(v2)✓none ≤ 4VALID
∃v2. ∀v1. q(v1, v2) ⊨ ∀v1. ∃v2. q(v1, v2)✓none ≤ 4VALID
∀v1. ∃v2. q(v1, v2) ⊨ ∃v2. ∀v1. q(v1, v2)✗size 2BUDGET
⊨ ∃v1. (p(v1) ⇒ ∀v2. p(v2))✓none ≤ 4VALID

Two invalid items.

  • Item 2: the free v1v_1 of the premise is one particular element, whose value is part of II, while ∀v1\forall v_1 speaks about all elements. The counter-model has pp true of one element only.
  • Item 5: the witness v2v_2 may depend on v1v_1. In the counter-model q={(0,1),(1,0)}q = \{(0,1), (1,0)\}, every element has a partner, but no element is everyone’s partner.

One subtlety. Free variables in an entailment are part of the interpretation. To search for a counter-model, they must be closed existentially (“is there an II, including values for the free variables, with …”). Read universally, item 2’s counter-model would be missed. entailment_countermodel does this.

Item 6 is the “drinker paradox”: in every non-empty bar there is someone such that, if they drink, everyone drinks. It sounds false and is valid.

3.3 The people slide, decoded

Lecture 6 found that item 8 of the people slide, as printed, is a well-formed sentence. Only semantics can show what it says. Script 02 asks for models of each size:

formulamodel of size 1?size 2?size 3?
item 8 as printed∀x. ¬∃y. ¬∃z. (x ≐ pa(y) ∧ z ≐ ma(z))yesnono
item 8 as intended∀x. ¬(∃y. x ≐ pa(y) ∧ ∃z. x ≐ ma(z))noyesyes

The two negations of the printed version cancel. It says ∀x. ∀y. ∃z. (x≐pa(y)∧… )\forall x.\ \forall y.\ \exists z.\ (x \doteq pa(y) \wedge \dots): everyone is the father of everyone. That forces a one-person world in which the single person is their own father. The intended sentence has no one-element model, since the single person would be both father and mother.

Item 1, “everyone has a father and a mother” (∀x. ∃y. ∃z. (y≐pa(x)∧z≐ma(x))\forall x.\ \exists y.\ \exists z.\ (y \doteq pa(x) \wedge z \doteq ma(x))), has no counter-model up to size 4. The semantic argument proves it valid in 18 lines, taking y:=pa(x)y := pa(x), z:=ma(x)z := ma(x). Total functions make it a truth of logic.

3.4 Algebra by model finding

Script 02 searches for small algebraic structures:

problemsmallest modelpropositional variables (last size)conflicts for sizes 1, 2, …time (s)
non-commutative monoid31,0841, 1, 70.1
group with an element of order 2 and one of larger order44,4781, 1, 5, 150.5
group of > 2 self-inverse elements44,4940, 1, 1, 00.3
non-commutative group632,5241, 1, 6, 40, 361, 44520.1

These structures are, respectively:

  • the smallest non-commutative monoid ({0,1,2}\{0, 1, 2\} with x⋅y=yx \cdot y = y for y≠0y \neq 0);
  • the cyclic group of order 4;
  • the Klein four-group;
  • the symmetries of a triangle, the smallest non-abelian group.

Where the time goes. Most of the work goes into showing that no smaller model exists: 361 conflicts to show there is no non-commutative group of order 5. Domain elements are interchangeable, so every failed attempt has symmetric copies. Symmetry breaking removes some of them. Requiring the kk-th constant to take a value ≤k\le k loses no model up to isomorphism. On the group search above it cut the conflicts from 1, 3, 16, 24 to 1, 1, 5, 15.

3.5 The limits

  • Only infinite models. “A strict order in which every element has a larger one” is satisfiable (ℕ with <), but every finite strict order has a largest element. Script 02’s finder reports no model up to size 7. No finite model finder can ever succeed here.
  • “No counter-model ≤ n” is not validity. “Among any five elements, two are equal” has no counter-model up to size 4 and one of size 5.

These limits are not accidental. By Church’s and Turing’s theorems (1936), validity in FOL is undecidable. No algorithm answers “valid?” for every formula.

What remains is a semi-decision procedure. If α is valid, a proof exists and proof search finds it (§4, Lecture 8). A finite counter-model, if one exists, is found by model search. Running both in parallel decides every formula that has a proof or a finite counter-model. The formulas with only infinite counter-models escape both searches.


4. Semantic arguments with quantifiers

The slides extend Lecture 1’s semantic arguments to FOL. The propositional rules (a)–(k) are unchanged, and four quantifier rules are added:

rulefromderiveterm
(m)I⊨∀v. αI \models \forall v.\ \alphaI⊨α[v←t]I \models \alpha[v \leftarrow t]any term tt (may be used again and again)
(n)I⊭∃v. αI \not\models \exists v.\ \alphaI⊭α[v←t]I \not\models \alpha[v \leftarrow t]any term tt
(o)I⊨∃v. αI \models \exists v.\ \alphaI⊨α[v←k]I \models \alpha[v \leftarrow k]a fresh constant kk
(p)I⊭∀v. αI \not\models \forall v.\ \alphaI⊭α[v←k]I \not\models \alpha[v \leftarrow k]a fresh constant kk

Why fresh?

  • From I⊨∃x. P(x)I \models \exists x.\ P(x) we only know that some element has PP. A new name x0x_0 assumes nothing else about it.
  • Reusing an existing term would assume that this element has PP, which is unsound.
  • A universal statement holds for every element, so (m) and (n) may use any term.

The substitutions must be capture-avoiding (Lecture 6, §7).

The slides’ examples, by machine (script 03; fol_semantics.semantic_argument). Examples 1 and 2 match the slides line for line. Example 3:

      1. I ⊭ ∃x. ∀y. Q(x, y) ⇒ ∀y. ∃x. Q(x, y)   assumption
      2. I ⊨ ∃x. ∀y. Q(x, y)   by (h) on 1
      3. I ⊭ ∀y. ∃x. Q(x, y)   by (h) on 1
      4. I ⊨ ∀y. Q(x0, y)   by (o) on 2, fresh x0
      5. I ⊭ ∃x. Q(x, y0)   by (p) on 3, fresh y0
      6. I ⊨ Q(x0, x0)   by (m) on 4 with x0
      7. I ⊨ Q(x0, y0)   by (m) on 4 with y0
      8. I ⊭ Q(x0, y0)   by (n) on 5 with x0
      9. I ⊨ ⊥   by (i) on 7, 8

Line 6 is the price of fairness. The prover instantiates a ∀ with every term on the branch, because it cannot know which one will close it.

The strategy. Apply α-rules and δ-rules (o)/(p) first, each δ-rule once per formula. Then split on β-rules, preferring splits whose branches close at once. Then run one round of γ-instances (m)/(n) with every ground term on the branch, and repeat. The result is fair: every applicable instance is eventually applied. By the slides’ completeness theorem (Gödel 1929, for formulas without equality), fairness means every valid formula is eventually proved.

Soundness and completeness. The slides state both: a closed tree proves validity, and every valid formula without equality has one. Completeness does not give termination.

Termination: what the slide shows, and what is true. The slides illustrate non-termination with ∀x. q(x,x)\forall x.\ q(x, x), which is invalid. They apply the rule for I⊭∀I \not\models \forall to line 1 again and again, producing q(x0,x0),q(x1,x1),…q(x_0, x_0), q(x_1, x_1), \dots, and label the steps “(m)”. The rule for I⊭∀I \not\models \forall is (p).

A δ-rule never needs a second application. With one application, the branch is complete after two lines and yields a counter-model (one element, qq false), which is what script 03 shows.

The slide’s conclusion is still right, with a different example. On I⊨∀x. ∃y. p(x,y)I \models \forall x.\ \exists y.\ p(x, y), every new element needs a new successor, and the branch grows forever (p(c0,y0),p(y0,y1),…p(c_0, y_0), p(y_0, y_1), \dots). Yet a one-element counter-model exists (p(0,0)p(0, 0)).

A tableau builds only Herbrand-style models, in which distinct terms are distinct elements. It cannot discover that y0y_0 may equal c0c_0. No strategy terminates on all invalid formulas, since validity is undecidable.

How strong is it? Script 03 runs 21 of Pelletier’s classic problems (1986):

  • 20 are proved, most in under 100 lines and a few milliseconds. P29 needs 839 lines, P43 (without equality) 2,515.
  • P26 is not proved within 5,000 lines, nor within 20,000 (tried while developing). Its ⇔ between quantified formulas splits branches early, and every branch re-instantiates every ∀ with every term.

Lecture 8’s resolution prover, which instantiates only by unification, takes P26 as a test.


5. Normal forms: prenex, Skolem, clausal

Resolution works on clauses, so first-order sentences must be brought into clausal form: universally closed CNF. The slides’ pipeline, run by script 04 on the running example (∀x. (p(x)⇒q(x)))⇒(∀x. p(x)⇒∀x. q(x))(\forall x.\ (p(x) \Rightarrow q(x))) \Rightarrow (\forall x.\ p(x) \Rightarrow \forall x.\ q(x)):

  1. Rename apart: ∀x. (p(x)⇒q(x))⇒∀y. p(y)⇒∀z. q(z)\forall x.\ (p(x) \Rightarrow q(x)) \Rightarrow \forall y.\ p(y) \Rightarrow \forall z.\ q(z).
  2. Eliminate ⇒, ⇔: ¬∀x. (¬p(x)∨q(x))∨¬∀y. p(y)∨∀z. q(z)\neg\forall x.\ (\neg p(x) \vee q(x)) \vee \neg\forall y.\ p(y) \vee \forall z.\ q(z).
  3. NNF, which needs the quantifier dualities ¬∀≡∃¬\neg\forall \equiv \exists\neg and ¬∃≡∀¬\neg\exists \equiv \forall\neg: ∃x. (p(x)∧¬q(x))∨∃y. ¬p(y)∨∀z. q(z)\exists x.\ (p(x) \wedge \neg q(x)) \vee \exists y.\ \neg p(y) \vee \forall z.\ q(z).
  4. Prenex: move quantifiers outward with (Qv. α)⋈β→Qv. (α⋈β)(Qv.\ \alpha) \bowtie \beta \to Qv.\ (\alpha \bowtie \beta). This is sound because, after renaming apart, vv is not free in β. One rewrite at a time, as on the slides:
    ∃x. (p(x) ∧ ¬q(x)) ∨ ∃y. ¬p(y) ∨ ∀z. q(z)
    ∃x. (p(x) ∧ ¬q(x) ∨ ∃y. ¬p(y) ∨ ∀z. q(z))
    ∃x. (p(x) ∧ ¬q(x) ∨ ∀z. (∃y. ¬p(y) ∨ q(z)))
    ∃x. ∀z. (p(x) ∧ ¬q(x) ∨ ∃y. ¬p(y) ∨ q(z))
    ∃x. ∀z. (p(x) ∧ ¬q(x) ∨ ∃y. (¬p(y) ∨ q(z)))
    ∃x. ∀z. ∃y. (p(x) ∧ ¬q(x) ∨ ¬p(y) ∨ q(z))
  5. PCNF, distributing in the matrix: ∃x. ∀z. ∃y. {p(x),¬p(y),q(z)} {¬q(x),¬p(y),q(z)}\exists x.\ \forall z.\ \exists y.\ \{p(x), \neg p(y), q(z)\}\ \{\neg q(x), \neg p(y), q(z)\}.
  6. Skolemize: each ∃v\exists v becomes a new function fvf_v applied to the universally quantified variables before it, giving ∀z. {p(fx),¬p(fy(z)),q(z)} {¬q(fx),¬p(fy(z)),q(z)}\forall z.\ \{p(f_x), \neg p(f_y(z)), q(z)\}\ \{\neg q(f_x), \neg p(f_y(z)), q(z)\}. This is exactly the slides’ result.

Equivalence and equisatisfiability. Steps 1–5 preserve equivalence. Skolemization preserves only satisfiability:

  • ∃x. p(x)\exists x.\ p(x) becomes p(fx)p(f_x);
  • a structure with pp true of one element and fxf_x pointing to another satisfies the first and not the second (script 04).

Every model of the clause set is a model of the sentence: just ignore the Skolem symbols. Every model of the sentence can be expanded to a model of the clause set: interpret fxf_x as a witness. So the sentence is unsatisfiable iff its clause set is, which is all refutation needs.

To prove ⊨ α, clausify ¬α and derive the empty clause (Lecture 8). Script 04 checks this on 300 random sentences: both have a model of size ≤ 3 or neither, 300/300; every model of a clause set satisfies the sentence, 268/268.

The order of steps 1 and 2 matters. The same check with the slides’ order, rename apart before eliminating ⇔, gives 299/300. The failing sentence is ¬(∀y. p(y)⇔∀y. p(y))\neg(\forall y.\ p(y) \Leftrightarrow \forall y.\ p(y)), which is unsatisfiable because α ⇔ α is valid.

What goes wrong. Eliminating α⇔β\alpha \Leftrightarrow \beta copies α and β, so the renamed quantifiers appear twice with the same bound names. Pulling them out then lets one capture the other’s variable. The clause set {p(fy(y)),p(fy′)},{¬p(fy′),¬p(fy(y))}\{p(f_y(y)), p(f_{y'})\}, \{\neg p(f_{y'}), \neg p(f_y(y))\} is satisfiable: a counter-example to the pipeline.

The fix is to rename apart after eliminating ⇔. fol_semantics.clausal_form does this by default and keeps the slides’ order as an option. The slides’ running example has no ⇔, so it is not affected.

The prenex form is not unique. The slides pull ∀z\forall z out before ∃y\exists y, so yy “depends” on zz and becomes the function fy(z)f_y(z). But ∃y. ¬p(y)\exists y.\ \neg p(y) never mentions zz. Pulling ∃ first gives the prefix ∃x. ∃y. ∀z\exists x.\ \exists y.\ \forall z and only constants fx,fyf_x, f_y.

On 300 random sentences (script 04), with 712 Skolem symbols in total:

pull firstSkolem constantsSkolem functionsmean arity
the right operand (the slides)2474651.64
the left operand2504621.64
∃ before ∀2734391.53

Real clausifiers go further with miniscoping: they push quantifiers inward first, so that each ∃ sits under as few ∀ as possible. Fewer Skolem arguments make proofs easier.


6. Unification

6.1 Why

Ground resolution needs complementary literals, like P(a)P(a) and ¬P(a)\neg P(a). The slides’ first answer for variables is the rule

\textscInst:C∈Δ  ⟹  Δ:=Δ∪{C[v←t]}\textsc{Inst}: \quad C \in \Delta \implies \Delta := \Delta \cup \{C[v \leftarrow t]\}

for any term tt. Script 05 replays the slides’ derivation with it:

clauserule
C1–C3{¬P(z), Q(z)}, {P(a)}, {¬Q(x)}input
C4{¬P(a), Q(a)}INST on C1 with z ← a
C5{Q(a)}RESOLVE C2, C4
C6{¬Q(a)}INST on C3 with x ← a
C7{}RESOLVE C5, C6

INST must guess tt, and with function symbols there are infinitely many terms. The slides call it “not constrained enough”.

The alternative is to compute, from the two literals themselves, the least instantiation that makes them complementary.

6.2 Unifiers

A substitution σ is a unifier of ss and tt if sσ=tσs\sigma = t\sigma. It is a most general unifier (mgu) if every unifier τ is an instance of it: τ=σθ\tau = \sigma\theta for some θ.

Robinson’s theorem (1965). If two terms have any unifier, they have an mgu, and an algorithm computes it.

Robinson’s algorithm (unify). Keep a list of pairs that must become equal, and take one pair at a time:

  • identical: drop it;
  • variable vs term (x,u)(x, u): if xx occurs in uu, fail (the occurs check). Otherwise bind x←ux \leftarrow u and apply the binding everywhere;
  • same function symbol f(sˉ),f(tˉ)f(\bar s), f(\bar t): add the pairs (si,ti)(s_i, t_i);
  • different symbols: fail (clash).
  unify f(x, f(x, y))  with  f(g(z), f(g(a), z)):  {x ← g(a), y ← a, z ← a}
      decompose f(x, f(x, y)) =? f(g(z), f(g(a), z))
      bind x ← g(z)
      decompose f(g(z), y) =? f(g(a), z)
      decompose g(z) =? g(a)
      bind z ← a
      bind y ← a

Martelli and Montanari (1982) present the same algorithm as six rules on sets of equations:

ruletransformation
Deletet≐tt \doteq t is removed
Decomposef(sˉ)≐f(tˉ)f(\bar s) \doteq f(\bar t) becomes the equations si≐tis_i \doteq t_i
Conflictf(… )≐g(… )f(\dots) \doteq g(\dots) with f≠gf \neq g: fail
Swapt≐xt \doteq x becomes x≐tx \doteq t
Eliminategiven x≐tx \doteq t, substitute x←tx \leftarrow t in all other equations
Checkx≐tx \doteq t with xx in tt: fail

The rules can be applied in any order. They terminate in a solved form, which is the mgu, or in failure. This is a small instance of Lecture 3’s idea: a rule system plus a strategy is a procedure. Script 05 traces both algorithms.

6.3 Checked

Script 05 generates 2,000 random problems over f/2f/2, g/1g/1, aa, bb with variables xx, yy, zz. The outcomes are 563 unifiable, 1,157 clashes and 280 occurs-check failures.

  • Agreement: eager Robinson, triangular Robinson and Martelli–Montanari agree on all 2,000, up to renaming.
  • Correctness: every result is a unifier, and every result is idempotent (σσ=σ\sigma\sigma = \sigma).
  • Generality: brute force finds 847 ground unifiers. Each one satisfies τ=στ\tau = \sigma\tau for the computed mgu σ, so each is an instance of it.

The mgu represents all solutions at once. That is why resolution with unification never needs to consider any other instance.

6.4 The occurs check

Do p(x,f(x))p(x, f(x)) and p(y,y)p(y, y) unify? That needs y=xy = x and y=f(x)y = f(x), so x=f(x)x = f(x). Only the infinite term f(f(f(… )))f(f(f(\dots))) would do, and the occurs check rejects it.

Without the check, the clauses {p(x,f(x))}\{p(x, f(x))\} and {¬p(y,y)}\{\neg p(y, y)\} would resolve to the empty clause. Yet they are satisfiable: script 05’s model finder gives a 2-element model (ff swaps the elements, and pp is “is the image of”). Dropping the check makes resolution unsound. Prolog omits it for speed, which is one reason Prolog is not a sound theorem prover.

6.5 The size of an mgu

Unifying f(x1,..,xn)f(x_1, .., x_n) with f(g(x0,x0),..,g(xn−1,xn−1))f(g(x_0, x_0), .., g(x_{n-1}, x_{n-1})) binds xnx_n to a term with 2n+1−12^{n+1} - 1 symbols. Script 05:

nsize of xnx_n (tree)size (DAG)eager: occurs-check visitstriangular: visits
6127724648
128,1911316,368168
18524,287191,048,554360

Occurs-check work: eager vs triangular

The size depends on the representation. The mgu has only n+1n + 1 distinct subterms, so written as a DAG it is small.

The textbook algorithm applies every binding everywhere and checks occurrences in the expanded terms, so its work grows like the tree. Triangular bindings fix this: keep x2←g(x1,x1)x_2 \leftarrow g(x_1, x_1), x1←g(x0,x0)x_1 \leftarrow g(x_0, x_0) unapplied, follow chains on lookup, and memoize the occurs check. The work is then linear here. Martelli and Montanari give an almost-linear algorithm, and Paterson and Wegman (1978) a linear one.

Matching is one-way unification: only the pattern’s variables are bound. It decides subsumption (Lecture 8).


7. First-order resolution: the idea

Unification turns resolution into a rule on clauses with variables:

C∪{L}D∪{¬L′}σ=mgu(L,L′)(C∪D)σ\frac{C \cup \{L\} \qquad D \cup \{\neg L'\} \qquad \sigma = \mathrm{mgu}(L, L')}{(C \cup D)\sigma}

The two clauses are first renamed apart: different clauses never share variables. The slides’ example is {P(x,y),Q(a,f(y))}, {¬Q(z,f(b)),R(g(z))}.\{P(x, y), Q(a, f(y))\},\ \{\neg Q(z, f(b)), R(g(z))\}. The literals unify by {y←b,z←a}\{y \leftarrow b, z \leftarrow a\}, which gives {P(x,b),R(g(a))}\{P(x, b), R(g(a))\} (script 05). One resolution step with unification stands for infinitely many ground steps.

Lecture 8 completes the rule set with factoring (merging unifiable literals of one clause) and builds a resolution prover with the given-clause loop, subsumption and proof output. It also states what resolution can and cannot do:

  • it is refutationally complete: every unsatisfiable clause set has a refutation;
  • it is not a decision procedure: on satisfiable sets it may run forever.

8. Summary

  1. An interpretation gives each sort a non-empty domain, each symbol a total function or relation, and each free variable a value. Equality is identity. Truth is defined by structural induction, with ∀ and ∃ ranging over the domain.
  2. Validity, entailment, equivalence are defined over all interpretations. Invariance means a sentence is true or false in an interpretation, with no assignment needed. The slides’ theorems hold on every instance script 01 tried.
  3. A finite model finder grounds formulas for a fixed domain size and calls CDCL. It produced counter-models for the invalid entailments and decoded the people-slide typo. It found the smallest non-commutative monoid (3) and group (6) and the Klein group, with symmetry breaking for speed. It cannot find infinite models, and “no counter-model ≤ n” is not a proof.
  4. Semantic arguments with quantifier rules are sound and complete, but not terminating: validity in FOL is undecidable. The slide’s non-termination example terminates once (p) is applied only once; ∀x. ∃y. p(x,y)\forall x.\ \exists y.\ p(x, y) is a true non-terminating case. 20 of 21 Pelletier problems are proved.
  5. Clausal form: NNF, then prenex, then PCNF, then Skolemize. It is equisatisfiable, not equivalent. Rename apart after eliminating ⇔, or the pipeline is unsound. Pulling ∃ first gives smaller Skolem functions.
  6. Unification computes the most general instance making two terms equal. Robinson and Martelli–Montanari agree on 2,000 random problems, and every ground unifier is an instance of the mgu. The occurs check is necessary for soundness. Eager substitution can blow up exponentially; triangular bindings avoid that.
  7. Resolution with unification is the rule Lecture 8 turns into a prover.

9. Common pitfalls

  • Empty domains. FOL domains are non-empty, so ∀x. p(x)⊨∃x. p(x)\forall x.\ p(x) \models \exists x.\ p(x). Some logics allow empty domains; ours does not.
  • Partial functions. pa(x)pa(x) always denotes someone. “Everyone has a father” is valid, not a modelling choice.
  • Free variables in entailments. They are part of the interpretation. For counter-models, close them existentially; for validity, universally.
  • “No counter-model found, so valid.” Only if a proof is found. Counter-models may be large, or infinite.
  • The quantifier precedence. ∃x. x≠e∧x⋅x=e\exists x.\ x \neq e \wedge x \cdot x = e means (∃x. x≠e)∧x⋅x=e(\exists x.\ x \neq e) \wedge x \cdot x = e under the slides’ convention. This bit the author while writing script 02.
  • Skolemization changes meaning. Only satisfiability is preserved. Never Skolemize a formula you want to prove valid; Skolemize its negation.
  • Rename apart before eliminating ⇔. It must come after (§5).
  • Unifying without renaming apart. {p(x)}\{p(x)\} and {¬p(f(x))}\{\neg p(f(x))\} do not unify as written (xx vs f(x)f(x)), but after renaming, p(x)p(x) and p(f(x′))p(f(x')) do. Clauses never share variables.
  • Dropping the occurs check makes resolution unsound (§6.4).

10. Exercises

Answers are collapsed; try each exercise first.

1. (evaluation) In the family structure of §2 (xx = Jim, yy = Joe), evaluate ma(pa(pa(x)))ma(pa(pa(x))) step by step.

Answer

ma(pa(pa(Jim)))=ma(pa(Joe))=ma(Bob)=Annma(pa(pa(\mathrm{Jim}))) = ma(pa(\mathrm{Joe})) = ma(\mathrm{Bob}) = \mathrm{Ann}, as script 01 prints.

2. (counter-model) Give a counter-model to ∀x. (P(x)∨Q(x))⊨∀x. P(x)∨∀x. Q(x)\forall x.\ (P(x) \vee Q(x)) \models \forall x.\ P(x) \vee \forall x.\ Q(x).

Answer

Take two elements, with PP true of 1 and QQ true of 0. Every element has PP or QQ, but neither holds for all. Script 03’s model finder returns exactly this.

3. (validity) Prove ∀x. p(x)⊨∃x. p(x)\forall x.\ p(x) \models \exists x.\ p(x) with semantic arguments. Which assumption about interpretations does the proof use?

Answer
  1. I⊭∀x. p(x)⇒∃x. p(x)I \not\models \forall x.\ p(x) \Rightarrow \exists x.\ p(x)
  2. I⊨∀x. p(x)I \models \forall x.\ p(x), by (h)
  3. I⊭∃x. p(x)I \not\models \exists x.\ p(x), by (h)
  4. Introduce a constant c0c_0 (any term will do), then I⊨p(c0)I \models p(c_0) by (m) on 2
  5. I⊭p(c0)I \not\models p(c_0), by (n) on 3
  6. I⊨⊥I \models \bot

Step 4 uses the existence of a term, which mirrors the non-empty domain. In an empty domain ∀x. p(x)\forall x.\ p(x) would be true and ∃x. p(x)\exists x.\ p(x) false.

4. (the drinker) Prove ⊨∃x. (D(x)⇒∀y. D(y))\models \exists x.\ (D(x) \Rightarrow \forall y.\ D(y)) informally by cases.

Answer
  • If everyone drinks, any xx works: the consequent is true.
  • If someone, cc, does not drink, take x=cx = c: the antecedent is false.

The domain is non-empty, so in both cases a witness exists.

5. (clausal form) Clausify ¬(∀x. ∃y. R(x,y)⇒∃y. ∀x. R(x,y))\neg(\forall x.\ \exists y.\ R(x, y) \Rightarrow \exists y.\ \forall x.\ R(x, y)), the negation of item 5 of the entailment exercise.

Answer
  1. NNF: ∀x. ∃y. R(x,y)∧∀y′. ∃x′. ¬R(x′,y′)\forall x.\ \exists y.\ R(x, y) \wedge \forall y'.\ \exists x'.\ \neg R(x', y').
  2. Prenex, ∃ first where possible: ∀x. ∃y. ∀y′. ∃x′. (R(x,y)∧¬R(x′,y′))\forall x.\ \exists y.\ \forall y'.\ \exists x'.\ (R(x, y) \wedge \neg R(x', y')).
  3. Skolemize: y↦fy(x)y \mapsto f_y(x) and x′↦fx′(x,y′)x' \mapsto f_{x'}(x, y').
  4. Clauses: {R(x,fy(x))}\{R(x, f_y(x))\}, {¬R(fx′(x,y′),y′)}\{\neg R(f_{x'}(x, y'), y')\}.

Miniscoping would give fx′(y′)f_{x'}(y'), since the second conjunct does not mention xx.

6. (Skolem) Show that ∃x. p(x)\exists x.\ p(x) and p(c)p(c) are equisatisfiable but not equivalent, as a pair of structures.

Answer

Every model of p(c)p(c) satisfies ∃x. p(x)\exists x.\ p(x), with cc as the witness. Conversely, a model of ∃x. p(x)\exists x.\ p(x) becomes a model of p(c)p(c) when cc is interpreted as a witness.

But the structure with domain {0, 1}, p={1}p = \{1\}, c=0c = 0 satisfies ∃x. p(x)\exists x.\ p(x) and not p(c)p(c). This is script 04’s example.

7. (step order) Explain in two sentences why renaming apart before eliminating ⇔ can make clausification unsound. Give the smallest example you can.

Answer

α⇔β\alpha \Leftrightarrow \beta becomes (α⇒β)∧(β⇒α)(\alpha \Rightarrow \beta) \wedge (\beta \Rightarrow \alpha), so every quantifier in α or β now occurs twice with the same name. Pulling both copies to the front puts one in the scope of the other, and occurrences get captured.

Example: ¬(∀y. p(y)⇔∀y. p(y))\neg(\forall y.\ p(y) \Leftrightarrow \forall y.\ p(y)), §5.

8. (unification) Compute mgus, or explain the failure: (a) f(x,g(y))f(x, g(y)) and f(g(a),x)f(g(a), x); (b) f(x,x)f(x, x) and f(y,g(y))f(y, g(y)); (c) h(x,f(y),z)h(x, f(y), z) and h(g(z),f(g(w)),w)h(g(z), f(g(w)), w).

Answer
  • (a) x←g(a)x \leftarrow g(a). Then g(y)≐g(a)g(y) \doteq g(a), so y←ay \leftarrow a. mgu {x←g(a),y←a}\{x \leftarrow g(a), y \leftarrow a\}.
  • (b) x←yx \leftarrow y, then y≐g(y)y \doteq g(y): the occurs check fails, so there is no unifier.
  • (c) x←g(z)x \leftarrow g(z), y←g(w)y \leftarrow g(w), z←wz \leftarrow w. mgu {x←g(w),y←g(w),z←w}\{x \leftarrow g(w), y \leftarrow g(w), z \leftarrow w\}.

9. (most general) Show that {x←f(a),y←a}\{x \leftarrow f(a), y \leftarrow a\} is a unifier of p(x,y)p(x, y) and p(f(y),y)p(f(y), y) but not most general. What is the mgu?

Answer

It is a unifier: both sides become p(f(a),a)p(f(a), a). The mgu is {x←f(y)}\{x \leftarrow f(y)\}, and the given unifier is its instance under {y←a}\{y \leftarrow a\}. It is not most general, because {x←f(b),y←b}\{x \leftarrow f(b), y \leftarrow b\} is a unifier that is not an instance of it.

10. (model finding, programming) Use find_model to find the smallest model of: “a binary relation that is reflexive, symmetric, not transitive”. Then add “every element is related to exactly two elements”.

Answer sketch

First part. Write the axioms:

  • ∀x. R(x,x)\forall x.\ R(x, x);
  • ∀x. ∀y. (R(x,y)⇒R(y,x))\forall x.\ \forall y.\ (R(x, y) \Rightarrow R(y, x));
  • ∃x. ∃y. ∃z. (R(x,y)∧R(y,z)∧¬R(x,z))\exists x.\ \exists y.\ \exists z.\ (R(x, y) \wedge R(y, z) \wedge \neg R(x, z)).

The smallest model has 3 elements: a path 0–1–2 plus loops.

Second part. Add “exactly two neighbours”, counting the element itself. Then R(x,x)R(x, x) plus exactly one other neighbour must hold, and that relation is transitive. So no model exists. Check this up to size 6.

This is a small taste of how model finders support mathematical exploration.

11. (tableau, programming) Extend semantic_argument with the substitution rule for equality, “from I⊨s≐tI \models s \doteq t and I⊨α[s]I \models \alpha[s] derive I⊨α[t]I \models \alpha[t]”, restricted to ground terms on the branch. Which formulas with equality does it now prove?

Answer sketch

Apply the rule when a branch contains s≐ts \doteq t and a literal containing ss; add the rewritten literal, with fairness as for γ-rules.

Valid examples now provable include a≐b∧p(a)⇒p(b)a \doteq b \wedge p(a) \Rightarrow p(b) and a≐b⇒f(a)≐f(b)a \doteq b \Rightarrow f(a) \doteq f(b); symmetry also follows, using reflexivity. The real solution is paramodulation and superposition (Lecture 8, further reading).


11. Further reading

  • A. Bradley, Z. Manna, The Calculus of Computation, §2.2–2.5: semantics, semantic arguments, normal forms.
  • H. Enderton, A Mathematical Introduction to Logic, §2.2: structures, truth and models, carefully.
  • J. A. Robinson, “A Machine-Oriented Logic Based on the Resolution Principle”, JACM 1965: unification and resolution.
  • A. Martelli, U. Montanari, “An Efficient Unification Algorithm”, ACM TOPLAS 1982.
  • F. Baader, W. Snyder, “Unification Theory”, Chapter 8 of the Handbook of Automated Reasoning (2001): all algorithms, with complexity.
  • F. J. Pelletier, “Seventy-Five Problems for Testing Automatic Theorem Provers”, JAR 1986.
  • W. McCune, “Mace4 Reference Manual and Guide” (2003); K. Claessen, N. Sörensson, “New Techniques that Improve MACE-style Finite Model Finding” (2003): finite model finding by SAT.
  • A. Nonnengart, C. Weidenbach, “Computing Small Clause Normal Forms”, Handbook of Automated Reasoning (2001): miniscoping and better clausification.

12. Next lecture

Lecture 8: resolution and unification II, first-order theories. We build prover.py, a resolution prover with:

  • factoring;
  • the given-clause loop;
  • subsumption;
  • proof output that an independent checker verifies.

We run it on the slides’ examples, on Pelletier’s problems (including P26), and on group theory: “every group in which x⋅x=ex \cdot x = e is commutative”. We then meet first-order theories: restricting interpretations to the intended ones, axiomatizing them, and what completeness and decidability of a theory mean. The model finder from this lecture returns there as a counter-model generator for theories.

← 返回课程目录