Truth in every model, and proof
There are two ways to say that a sentence follows from a set of sentences .
- Semantically: if is true in every structure in which all the sentences of are true. To check this one must, in principle, survey all structures — infinitely many, of every size.
- Syntactically: if there is a formal derivation of from : a finite list of formulas, each an axiom, a member of or obtained from earlier lines by a rule.
The lesson on first-order logic proved soundness: if then , so derivations never lead from truths to falsehoods. In 1928 David Hilbert and Wilhelm Ackermann asked whether the converse holds — whether the rules of first-order logic are strong enough to derive every consequence. In his 1929 doctoral thesis, Kurt Gödel proved that they are.
Theorem— Gödel's completeness theorem (1929)
For every set of first-order sentences and every sentence : . Equivalently, every consistent set of sentences has a model.
So the two notions of consequence coincide. That alone would make the theorem a cornerstone of logic. But it has consequences that reach far beyond logic, because "has a model" is a statement about mathematical structures, while "is consistent" is a statement about finite objects. This lesson proves the theorem and follows three of its consequences: the compactness theorem, which shows that "finite" cannot be expressed in first-order logic and produces numbers larger than every natural number; and the Löwenheim–Skolem theorems, which show that no first-order theory with an infinite model can pin down the size of its models — not even set theory.
Building a model out of words
How can one produce a model of a theory knowing only that it is consistent? Leon Henkin's idea (1949) is to build the model out of the language itself. Its elements will be the closed terms — expressions such as , , — with two terms identified when the theory proves them equal, and a relation holding of terms exactly when the theory says it does.
For this to work the theory must already decide everything (for each sentence, contain it or its negation) and must have witnesses: whenever it contains , it must contain for some named constant . Otherwise the theory might assert that something exists while no term names it. So the proof has three steps: add witnesses, extend to a complete theory, read off the model.
Analogy, not a formal construction
The construction resembles building as : one manufactures the new objects from symbols (polynomials, terms) and then identifies two of them when the rules force them to be equal (, or "the theory proves "). This is only an analogy — the Henkin model is built from a theory, not a ring — but in both cases the model is made of syntax up to provable equality.
Definitions
Fix a first-order language (constant, function and relation symbols) and write for the number of its symbols. An -structure is a non-empty set with interpretations of the symbols; means the sentence is true in .
Definition— models, consistency, satisfiability
A model of a set of sentences is a structure in which every sentence of is true. is satisfiable if it has a model, and finitely satisfiable if each of its finite subsets has a model. is consistent if there is no with and (equivalently, ).
Definition— complete theories, witnesses
is complete if for every sentence , or . A consistent is maximal consistent if no proper superset is consistent. has the witness property (is a Henkin theory) if for every formula with one free variable there is a constant with .
Definition— elementary substructure
and are elementarily equivalent, , if they satisfy the same sentences. If is a substructure, it is an elementary substructure, , if for every formula and every tuple from : .
Note
Two different uses of "complete" meet in this lesson. A proof system is complete if it derives every semantic consequence (Gödel's theorem). A theory is complete if it decides every sentence. The completeness theorem says first-order logic is complete in the first sense; Gödel's incompleteness theorem says that arithmetic has no consistent, effectively axiomatised theory that is complete in the second sense.
For the proof we only need four properties of the derivation relation , all standard for natural deduction or Hilbert-style systems:
- Finiteness. If then for some finite (a derivation uses finitely many hypotheses).
- Splitting. If and are both inconsistent, so is (proof by cases).
- Constants are generic. If and the constant occurs neither in nor in , then .
- Equality and logic. The usual rules for (reflexivity, symmetry, transitivity, substitution) and for the connectives and quantifiers, e.g. .
Examples: theories and their models
Example— Consistent theories with very different models
- The axioms of groups have finite and infinite models, abelian and non-abelian ones; they decide neither "" nor its negation, so the theory of groups is consistent but not complete.
- The theory DLO of dense linear orders without endpoints has the models , and . By Cantor's back-and-forth theorem, any two countable models are isomorphic, and (as we will see) this makes DLO complete.
- The complete theory of arithmetic is complete by definition. We will show it has models not isomorphic to .
Example— Saying 'at least n elements'
The sentence is true in a structure exactly when it has at least elements. So is an infinite set of sentences whose models are exactly the infinite structures. Can a set of sentences have exactly the finite structures as its models? The compactness theorem will say no.
Example— A finitely satisfiable set that looks impossible
In the language of arithmetic with one new constant , let , where is the numeral . No natural number is larger than every numeral, so is not a model, whatever is. But any finite subset mentions only finitely many numerals, and with interpreted as a large enough number is a model of it. So is finitely satisfiable.
The completeness theorem
Theorem— Theorem 1 (completeness, countable languages)
Let be a countable language. Every consistent set of -sentences has a model, of cardinality at most . Consequently, if then .
Proof
Step 1: adding witnesses. Let . Given , add a new constant for each -formula with one free variable, obtaining , and let , still countable. Let be the set of Henkin axioms , one for each -formula (each such formula lies in some , and is a constant of ).
Claim: is consistent. By finiteness it suffices to show consistent for finite . Add the axioms of to one at a time, in order of increasing level of their constants. When the axiom for is added to the set built so far, occurs neither in nor in : the axioms already in involve only constants of lower or equal level, and an axiom of the same level has a different constant and a formula from a lower level. Suppose is consistent but is not. Then , so and . By property 3, , i.e. , and is inconsistent — a contradiction.
Step 2: completing (Lindenbaum's lemma). List all -sentences as . Put and
By property 2, each is consistent. Let . It is consistent by finiteness (a derivation of would use hypotheses from a single ), it contains or for every sentence , and it is deductively closed: if then , since otherwise and would be inconsistent.
Step 3: the term model. For closed -terms put if . By the equality rules and deductive closure, is an equivalence relation compatible with the function symbols and relations. Let be the set of classes , and interpret: , , and iff . These are well defined by the substitution rule for equality. Every element of is named by a closed term, and is countable.
Step 4: the truth lemma. For every -sentence : . By induction on the number of connectives and quantifiers in .
- Atomic : by the definition of (closed terms denote their own classes).
- : , the last step because contains exactly one of and .
- : by deductive closure, iff both .
- : if , the Henkin axiom and deductive closure give ; by induction , so . Conversely, if , some element is a witness, so ; has fewer logical symbols than , so by induction , and since , deductive closure gives .
(The other connectives and are expressible by , , .) In particular , and forgetting the new constants gives a countable -structure that is a model of .
The second form. If , then is consistent (otherwise , hence ), so it has a model, which shows .
∎
For a language of any cardinality the same proof works with transfinite lists (or Zorn's lemma in Step 2) and gives a model of cardinality at most . The only step that is not purely finitary is Step 2: for countable languages it is an explicit induction, and in general it is exactly the Lindenbaum lemma formalised below.
Compactness and what it forbids
Theorem— Theorem 2 (compactness)
A set of first-order sentences has a model if and only if every finite subset of it has a model.
Proof
One direction is trivial. Conversely, suppose has no model. By completeness is inconsistent, i.e. . The derivation uses only a finite , so , and by soundness has no model.
∎
The theorem has a direct semantic proof too, by ultraproducts and Łoś's theorem — that is how Mathlib proves it, and it is done in the model theory lesson. Either way, it has striking consequences.
Theorem— Theorem 3 (finiteness is not first-order)
If a set of sentences has arbitrarily large finite models, then it has an infinite model. In particular, no set of sentences has exactly the finite structures as its models.
Proof
Let , where says "there are at least elements". A finite contains only with for some , and a model of with at least elements is a model of . By compactness has a model, which is a model of satisfying every — an infinite model. If 's models were exactly the finite structures, would have arbitrarily large finite models but no infinite one.
∎
Theorem— Corollary 4 (torsion groups)
The class of torsion groups (every element has finite order) is not first-order axiomatisable.
Proof
Suppose were a set of sentences in the language of groups whose models are exactly the torsion groups. Add a constant and let . A finite subset mentions only for ; it is satisfied in the torsion group with . By compactness has a model: a torsion group (it satisfies ) containing an element of infinite order. Contradiction.
∎
The same method shows that the classes of connected graphs, of well-orders, of fields of positive characteristic and of finite groups are not first-order axiomatisable (see the exercises). The class of infinite groups is axiomatisable — add to the group axioms — but not by finitely many sentences.
Theorem— Theorem 5 (nonstandard models of arithmetic)
There is a structure that contains an element larger than every numeral . In particular , and the same holds for models of Peano arithmetic.
Proof
The set is finitely satisfiable, as shown in the examples. By compactness it has a model , which satisfies (so ; in particular satisfies the axioms of PA) and contains for every . An isomorphism would have to send to , missing .
∎
Such an looks like followed by further "galaxies": every element has a successor and every non-zero element a predecessor, so sits in a copy of , and between and above these copies there are densely ordered families of others — a countable nonstandard model has order type , where is the order type of . Its arithmetic is wild: Stanley Tennenbaum (1959) proved that in a countable nonstandard model of PA neither nor is computable.
Example— Infinitesimals
Let be the structure with a symbol for every real number, every subset of and every function . Add a constant and the sentences for every real . Every finite subset is satisfied in by a small enough real , so by compactness there is a structure with a positive element smaller than every positive real: an infinitesimal. Because satisfies exactly the same sentences as , it is an ordered field, and every first-order statement about real functions transfers to it. This is the starting point of Abraham Robinson's nonstandard analysis (1961), in which is the standard part of — a rigorous version of Leibniz's infinitesimals.
The Löwenheim–Skolem theorems
Compactness says that first-order theories cannot express "finite". The Löwenheim–Skolem theorems say they cannot control infinite size either.
Theorem— Lemma 6 (Tarski–Vaught test)
Let be a substructure of . Then if and only if: for every formula and every tuple from , if then for some .
Proof
() If then by elementarity, so some has , hence . () Show by induction on . Atomic formulas agree because is a substructure, and the connective steps are immediate. For : if , a witness in is a witness in by induction; if , the test provides a witness with , so by induction, and .
∎
Theorem— Theorem 7 (downward Löwenheim–Skolem)
Let be countable, an -structure and countable. Then there is a countable with .
Proof
Put . Given a countable , there are countably many pairs with a tuple from ; for each with choose a witness (this uses countable choice), and let be together with the chosen witnesses — still countable. Let , which is countable. It is closed under the functions of (a witness for is itself) and contains the constants (witnesses for ), so it is a substructure, and it satisfies the Tarski–Vaught test by construction: a formula with parameters from has its parameters in some , and a witness was added in . So .
∎
Theorem— Theorem 8 (upward Löwenheim–Skolem)
If a theory in a countable language has an infinite model, then it has a model of every infinite cardinality .
Proof
Add new constants () and let . A finite subset mentions finitely many constants, which can be interpreted as distinct elements of an infinite model of ; so by compactness (for a language of size ) has a model, which has at least elements. The downward theorem for languages of size (same proof, with ) applied to gives an elementary substructure of cardinality exactly , still a model of and hence of .
∎
So a first-order theory with an infinite model has models of every infinite size, and no first-order theory with an infinite model determines its models up to isomorphism. has uncountable models; has countable ones. The best one can hope for is categoricity in a single cardinality, and the Łoś–Vaught test turns that into completeness: if has no finite models and all its models of some infinite cardinality are isomorphic, then is complete. For instance DLO is -categorical (Cantor), hence complete, so and satisfy exactly the same sentences.
Skolem's paradox. ZFC is a first-order theory in the countable language . If it is consistent, it has a model, and by Theorem 7 a countable model . But ZFC proves that is uncountable, so contains an element that believes is and believes is uncountable — while has only countably many -members, since itself is countable. There is no contradiction. " is uncountable" means, inside , "there is no bijection between and that is an element of ". A bijection between the -members of and of exists outside , but it is not one of 's sets. Countability is not absolute: it depends on which functions are available. Thoralf Skolem, who pointed this out in 1922, took it as evidence that set-theoretic notions are relative to a model.
Completeness versus incompleteness
Gödel proved the completeness theorem in 1929 and the incompleteness theorems in 1931. The names suggest a contradiction; there is none.
- Completeness is about all models: if a sentence is true in every model of a theory , then proves it.
- Incompleteness is about one intended model: for any consistent, effectively axiomatised theory containing enough arithmetic, such as PA, there is a sentence that is true in but not provable in (see Gödel's incompleteness theorems).
Put together: since , the completeness theorem says that has a model. That model satisfies PA but not , so it is not : it is a nonstandard model, whose existence we already know from compactness. True-in- and true-in-every-model-of-PA are different things, and the gap between them is exactly where the incompleteness theorem lives.
The completeness theorem also has a computational meaning. Derivations can be listed mechanically, so the set of sentences valid in all structures is computably enumerable: a machine can confirm validity, eventually, whenever it holds. Alonzo Church and Alan Turing (1936) proved that validity is nevertheless undecidable: no machine can also confirm invalidity in every case (see computability).
What Lean and Mathlib formalise
Mathlib has first-order syntax and semantics — languages, terms, formulas with bound variables indexed by Fin n, structures, M ⊨ φ, theories and models — and proves the compactness theorem semantically, by an ultraproduct of models of the finite subtheories. It does not yet contain a formal derivation relation for first-order logic, so Gödel's theorem in the form "consistent implies satisfiable" is not formalised here. What we can formalise is the combinatorial core of the Henkin proof, Lindenbaum's lemma, for an arbitrary finitary notion of consistency:
/-- A notion of consistency `Con` on sets of sentences is **finitary** if a set is consistent
exactly when each of its finite subsets is. Consistency in the sense of proofs is finitary,
because a derivation of a contradiction uses only finitely many hypotheses. -/
def Finitary {S : Type u} (Con : Set S → Prop) : Prop :=
∀ Γ : Set S, Con Γ ↔ ∀ Δ : Finset S, (Δ : Set S) ⊆ Γ → Con Δ/-- **Lindenbaum's lemma.** For a finitary notion of consistency, every consistent set `Γ` is
contained in a *maximal* consistent set. Zorn's lemma, applied to consistent supersets of `Γ`
ordered by `⊆`: the union of a non-empty chain is consistent, because each finite subset of the
union already lies in a single member of the chain. (For a countable language one can avoid
Zorn by listing the sentences `φ₀, φ₁, …` and adding each one if consistency allows.) -/
theorem lindenbaum {S : Type u} (Con : Set S → Prop) (hfin : Finitary Con) (Γ : Set S)
(hΓ : Con Γ) : ∃ Δ, Γ ⊆ Δ ∧ Maximal Con Δ := by
have chains : ∀ c ⊆ {Θ | Con Θ}, IsChain (· ⊆ ·) c → c.Nonempty →
∃ ub ∈ {Θ | Con Θ}, ∀ s ∈ c, s ⊆ ub := by
intro c hc hchain hne
refine ⟨⋃₀ c, ?_, fun s hs => Set.subset_sUnion_of_mem hs⟩
show Con (⋃₀ c)
rw [hfin]
intro Δ hΔ
rw [Set.sUnion_eq_biUnion] at hΔ
obtain ⟨t, htc, hΔt⟩ :=
DirectedOn.exists_mem_subset_of_finset_subset_biUnion (f := id) hne hchain.directedOn hΔ
exact (hfin t).mp (hc htc) Δ hΔt
obtain ⟨Δ, hΓΔ, hmax⟩ := zorn_subset_nonempty {Θ | Con Θ} chains Γ hΓ
exact ⟨Δ, hΓΔ, hmax⟩/-- **A maximal consistent set decides every sentence**, provided consistency *splits*: whenever
`Γ` is consistent, so is `Γ ∪ {φ}` or `Γ ∪ {¬φ}`. (For provability this holds because
`Γ ∪ {φ} ⊢ ⊥` and `Γ ∪ {¬φ} ⊢ ⊥` together give `Γ ⊢ ⊥`.) By maximality, whichever of the two
enlarged sets is consistent is `Γ` itself. -/
theorem maximal_mem_or_neg_mem {S : Type u} (Con : Set S → Prop) (neg : S → S)
(hsplit : ∀ Γ φ, Con Γ → Con (insert φ Γ) ∨ Con (insert (neg φ) Γ))
{Δ : Set S} (hΔ : Maximal Con Δ) (φ : S) : φ ∈ Δ ∨ neg φ ∈ Δ := by
rcases hsplit Δ φ hΔ.prop with h | h
· exact Or.inl (hΔ.mem_of_prop_insert h)
· exact Or.inr (hΔ.mem_of_prop_insert h)The proof uses Zorn's lemma; for countable languages Step 2 of the lesson avoids it by listing the sentences. Mathlib's compactness theorem says that satisfiability itself is finitary:
/-- **The compactness theorem:** a first-order theory has a model if and only if every finite
subset of it has a model. Mathlib proves this with an ultraproduct of models of the finite
subsets (Łoś's theorem). This applies `Theory.isSatisfiable_iff_isFinitelySatisfiable`. -/
theorem compactness {L : Language.{u, v}} (T : L.Theory) :
T.IsSatisfiable ↔ T.IsFinitelySatisfiable :=
Theory.isSatisfiable_iff_isFinitelySatisfiable/-- **Satisfiability is finitary** — this is just the compactness theorem
(`Theory.isSatisfiable_iff_isFinitelySatisfiable`), restated in the vocabulary of `Finitary`. -/
theorem satisfiable_finitary (L : Language.{u, v}) :
Finitary (fun T : L.Theory => T.IsSatisfiable) := by
intro T
show Theory.IsSatisfiable T ↔
∀ Δ : Finset L.Sentence, (Δ : L.Theory) ⊆ T → Theory.IsSatisfiable (Δ : L.Theory)
exact compactness T/-- **Satisfiability splits:** if `T` has a model `M`, then `M` makes `φ` true or false, so
`T ∪ {φ}` or `T ∪ {¬φ}` has a model. -/
theorem satisfiable_split {L : Language.{u, v}} (T : L.Theory) (φ : L.Sentence)
(hT : T.IsSatisfiable) : (insert φ T).IsSatisfiable ∨ (insert φ.not T).IsSatisfiable := by
obtain ⟨M⟩ := hT
by_cases hφ : M ⊨ φ
· left
have : M ⊨ insert φ T := Theory.model_insert_iff.mpr ⟨hφ, M.is_model⟩
exact Theory.Model.isSatisfiable M
· right
have hnot : M ⊨ φ.not := (Sentence.realize_not M).mpr hφ
have : M ⊨ insert φ.not T := Theory.model_insert_iff.mpr ⟨hnot, M.is_model⟩
exact Theory.Model.isSatisfiable Mso the abstract Lindenbaum lemma applies to it: every satisfiable theory extends to a maximal satisfiable theory, which decides every sentence.
/-- **Every satisfiable theory extends to a maximal satisfiable theory**, which contains each
sentence or its negation (so it is complete). This is the Lindenbaum step of the Henkin proof,
with satisfiability in place of consistency: `lindenbaum` + `satisfiable_finitary` +
`maximal_mem_or_neg_mem`. (Semantically there is a shortcut — the complete theory of one model,
`completeTheory.isMaximal` — but in the Henkin proof no model is available yet.) -/
theorem exists_maximal_extension {L : Language.{u, v}} (T : L.Theory) (hT : T.IsSatisfiable) :
∃ T' : L.Theory, T ⊆ T' ∧ T'.IsMaximal := by
obtain ⟨T', hTT', hmax⟩ := lindenbaum _ (satisfiable_finitary L) T hT
refine ⟨T', hTT', hmax.prop, fun φ => ?_⟩
exact maximal_mem_or_neg_mem (fun T : L.Theory => T.IsSatisfiable) (fun ψ => ψ.not)
(fun Γ ψ h => satisfiable_split Γ ψ h) hmax φTheorem 3 and its consequence, proved as in the lesson. In Lean the sets form a directed family whose union is , and Mathlib's compactness for directed unions does the rest:
/-- **A theory with arbitrarily large finite models has an infinite model.** Add to `T` the
sentences `σₖ` = "there are at least `k` elements" for all `k`. Any finite part of
`T ∪ {σₖ | k ∈ ℕ}` lies in `T ∪ {σₖ | k < n}` for some `n`, which a large enough model of `T`
satisfies; so by compactness the whole set has a model — a model of `T` that is infinite.
(In Lean: the theories `T ∪ {σₖ | k < n}` form a directed family whose union is
`T ∪ infiniteTheory`, and `isSatisfiable_directed_union_iff` is compactness for such a family.) -/
theorem exists_infinite_model {L : Language.{u, v}} (T : L.Theory)
(h : ∀ n : ℕ, ∃ M : Theory.ModelType.{u, v, w} T, (n : Cardinal) ≤ #M) :
∃ M : Theory.ModelType.{u, v, max u v} T, Infinite M := by
-- The theories `T ∪ {σₖ | k < n}`.
let Tn : ℕ → L.Theory := fun n => T ∪ Sentence.cardGe L '' Set.Iio n
have hdir : Directed (· ⊆ ·) Tn := by
intro m n
refine ⟨max m n, ?_, ?_⟩
· exact Set.union_subset_union_right T
(Set.image_mono (Set.Iio_subset_Iio (le_max_left m n)))
· exact Set.union_subset_union_right T
(Set.image_mono (Set.Iio_subset_Iio (le_max_right m n)))
have hunion : (⋃ n, Tn n) = T ∪ L.infiniteTheory := by
ext φ
simp only [Tn, Set.mem_iUnion, Set.mem_union, Set.mem_image, Set.mem_Iio,
Language.infiniteTheory, Set.mem_range]
constructor
· rintro ⟨n, hφ | ⟨k, -, hk⟩⟩
· exact Or.inl hφ
· exact Or.inr ⟨k, hk⟩
· rintro (hφ | ⟨k, hk⟩)
· exact ⟨0, Or.inl hφ⟩
· exact ⟨k + 1, Or.inr ⟨k, Nat.lt_succ_self k, hk⟩⟩
-- Each `T ∪ {σₖ | k < n}` is satisfied by a model of `T` with at least `n` elements.
have heach : ∀ n, (Tn n).IsSatisfiable := by
intro n
obtain ⟨M, hM⟩ := h n
have hcard : M ⊨ Sentence.cardGe L '' Set.Iio n := by
rw [Theory.model_iff]
rintro φ ⟨k, hk, rfl⟩
rw [Sentence.realize_cardGe]
exact le_trans (Nat.cast_le.mpr (le_of_lt (Set.mem_Iio.mp hk))) hM
have : M ⊨ Tn n := Theory.model_union_iff.mpr ⟨M.is_model, hcard⟩
exact Theory.Model.isSatisfiable M
-- Compactness for the directed family.
have hsat : (T ∪ L.infiniteTheory).IsSatisfiable := by
rw [← hunion]
exact (Theory.isSatisfiable_directed_union_iff hdir).mpr heach
obtain ⟨N⟩ := hsat
have hinf : Infinite N :=
(model_infiniteTheory_iff L).mp (Theory.Model.mono N.is_model Set.subset_union_right)
exact ⟨N.subtheoryModel Set.subset_union_left, hinf⟩/-- **Finiteness is not first-order.** No set of sentences in the language of pure equality has
exactly the finite non-empty sets as its models. If `T` did, `Fin (n + 1)` would be a model of
`T` for each `n`, so `T` would have arbitrarily large finite models — and therefore an infinite
model (`exists_infinite_model`), which is not finite. -/
theorem finiteness_not_axiomatizable :
¬ ∃ T : Language.empty.Theory,
∀ (M : Type) [Language.empty.Structure M] [Nonempty M], M ⊨ T ↔ Finite M := by
rintro ⟨T, hT⟩
have large : ∀ n : ℕ, ∃ M : Theory.ModelType.{0, 0, 0} T, (n : Cardinal) ≤ #M := by
intro n
-- A set is a structure for the empty language in exactly one way.
let _ : Language.empty.Structure (Fin (n + 1)) := Language.emptyStructure
have : Fin (n + 1) ⊨ T := (hT (Fin (n + 1))).mpr inferInstance
refine ⟨Theory.ModelType.of T (Fin (n + 1)), ?_⟩
show (n : Cardinal) ≤ #(Fin (n + 1))
rw [Cardinal.mk_fin]
exact Nat.cast_le.mpr (Nat.le_succ n)
obtain ⟨M, hM⟩ := exists_infinite_model T large
have hfin : Finite M := (hT M).mp M.is_model
exact not_finite MFrom Mathlib: the Löwenheim–Skolem theorem in "theory" form (models of every infinite cardinality at least ), compactness for consequence, and the theory DLO — Cantor's -categoricity and its completeness by the Łoś–Vaught test:
/-- **The Löwenheim–Skolem theorem**, upward and downward at once: if a theory `T` has an infinite
model, then it has a model of every infinite cardinality `κ` at least the number of symbols of
the language. For a countable language: models of *every* infinite size. This applies Mathlib's
`Theory.exists_model_card_eq`. -/
theorem lowenheim_skolem {L : Language.{u, v}} (T : L.Theory)
(h : ∃ M : Theory.ModelType.{u, v, max u v} T, Infinite M) (κ : Cardinal.{w})
(h1 : ℵ₀ ≤ κ) (h2 : Cardinal.lift.{w} L.card ≤ Cardinal.lift.{max u v} κ) :
∃ N : Theory.ModelType.{u, v, w} T, #N = κ :=
Theory.exists_model_card_eq h κ h1 h2/-- **Compactness for consequence:** `T ⊨ φ` exactly when some *finite* `T₀ ⊆ T` already has
`T₀ ⊨ φ`. This applies Mathlib's `Theory.models_iff_finset_models`. -/
theorem models_iff_finset_models {L : Language.{u, v}} {T : L.Theory} {φ : L.Sentence} :
T ⊨ᵇ φ ↔ ∃ T₀ : Finset L.Sentence, (T₀ : L.Theory) ⊆ T ∧ (T₀ : L.Theory) ⊨ᵇ φ :=
Theory.models_iff_finset_models/-- **Cantor's back-and-forth theorem:** any two countable dense linear orders without endpoints
are isomorphic — the theory `dlo` is `ℵ₀`-categorical. This applies Mathlib's
`aleph0_categorical_dlo`. -/
theorem dlo_categorical : (ℵ₀).Categorical Language.order.dlo :=
aleph0_categorical_dlo/-- **The Łoś–Vaught test at work:** `dlo` has no finite models and is `ℵ₀`-categorical, so it is
complete — every sentence about orders is decided by the axioms of dense linear orders without
endpoints. In particular `(ℚ, <)` and `(ℝ, <)` satisfy exactly the same first-order sentences.
This applies Mathlib's `dlo_isComplete`. -/
theorem dlo_complete : Language.order.dlo.IsComplete :=
dlo_isCompleteWhat is and is not formalised. Proved here: Lindenbaum's lemma for any finitary consistency notion, the decision property of maximal sets, its instance for satisfiable theories, Theorem 3 and the non-axiomatisability of finiteness (for the language of pure equality). From Mathlib: compactness, Löwenheim–Skolem and the DLO results. Not formalised: a proof calculus, soundness and completeness with respect to it, the Henkin term model and truth lemma, nonstandard models of arithmetic and Skolem's paradox.
Completeness and compactness, computed
For propositional logic both theorems can be watched in action. The first experiment uses the resolution proof system: clauses are sets of literals, and from and one derives . A clause set is consistent if the empty clause cannot be derived. The program compares this syntactic notion with satisfiability by truth tables on random clause sets — soundness and completeness say they always agree — and then builds a model of each consistent set the way Step 2 of the Henkin proof does: deciding the variables one by one, keeping the set consistent.
"""Consistent if and only if satisfiable: propositional resolution, tested.
The completeness theorem says a set of sentences is consistent (no proof of a
contradiction) exactly when it has a model. Its propositional shadow can be
checked by machine. Clauses are sets of literals (v or -v); the resolution
rule derives (C - {v}) U (D - {-v}) from C and D. The program saturates random
sets of 3-literal clauses under resolution, asks whether the empty clause
(a contradiction) appears, and compares the answer with a truth-table search
for a satisfying assignment: soundness says a refutation means no model, and
completeness says no model means a refutation. For the consistent sets it then
builds a model the way the Henkin-Lindenbaum proof does, deciding v1, v2, ...
in turn and keeping the set consistent, and checks the resulting assignment.
Evidence: exact and exhaustive for each clause set, but only for randomly
sampled sets over four variables.
"""
import random
from itertools import product
def resolvents(c, d):
"""All non-tautological resolvents of clauses c and d."""
out = []
for lit in c:
if -lit in d:
r = (c - {lit}) | (d - {-lit})
if not any(-x in r for x in r):
out.append(frozenset(r))
return out
def refutable(clauses):
"""True if resolution derives the empty clause from ``clauses``.
Saturates under resolution, discarding a new clause when a known clause
is contained in it (it would add nothing: forward subsumption).
"""
known = set(clauses)
if frozenset() in known:
return True
frontier = list(known)
while frontier:
new = set()
for c in frontier:
for d in list(known):
for r in resolvents(c, d):
if not r:
return True
if not any(k <= r for k in known) and r not in new:
new.add(r)
known |= new
frontier = list(new)
return False
def satisfies(assignment, clauses):
"""Does the assignment (dict var -> bool) make every clause true?"""
return all(any(assignment[abs(x)] == (x > 0) for x in c) for c in clauses)
def satisfiable(clauses, nvars):
"""Truth-table search for a satisfying assignment."""
for values in product([False, True], repeat=nvars):
if satisfies(dict(zip(range(1, nvars + 1), values)), clauses):
return True
return False
def lindenbaum_model(clauses, nvars):
"""Decide v1, v2, ... in turn, adding v or -v while consistency allows."""
current, assignment = set(clauses), {}
for v in range(1, nvars + 1):
if not refutable(current | {frozenset([v])}):
current.add(frozenset([v]))
assignment[v] = True
else:
current.add(frozenset([-v]))
assignment[v] = False
return assignment
def random_clauses(rng, nvars, count, width=3):
"""``count`` random clauses, each on ``width`` distinct variables."""
out = set()
while len(out) < count:
vs = rng.sample(range(1, nvars + 1), width)
out.add(frozenset(v if rng.random() < 0.5 else -v for v in vs))
return out
def main():
rng = random.Random(1929)
nvars, trials = 4, 150
tally = {(True, False): 0, (False, True): 0, (True, True): 0,
(False, False): 0}
good_models = consistent = 0
for _ in range(trials):
clauses = random_clauses(rng, nvars, rng.randint(6, 20))
sat, ref = satisfiable(clauses, nvars), refutable(clauses)
tally[(sat, ref)] += 1
if not ref:
consistent += 1
good_models += satisfies(lindenbaum_model(clauses, nvars), clauses)
print(f"{trials} random sets of 6..20 three-literal clauses over {nvars} "
"variables:")
print(f" satisfiable and not refutable: {tally[(True, False)]:>4}")
print(f" unsatisfiable and refutable: {tally[(False, True)]:>4}")
print(f" refutable yet satisfiable: {tally[(True, True)]:>4}"
" (would break soundness)")
print(f" unsatisfiable, not refutable: {tally[(False, False)]:>4}"
" (would break completeness)")
print(f"Lindenbaum-style models for the {consistent} consistent sets:")
print(f" assignments that satisfy every clause: {good_models} of {consistent}")
example = [frozenset(c) for c in ([1, 2], [1, -2], [-1, 2], [-1, -2])]
print("A small refutation: {1,2}, {1,-2}, {-1,2}, {-1,-2}")
print(" resolve on 2: {1} and {-1}; resolve on 1: {} (contradiction)")
print(f" refutable: {refutable(example)}; satisfiable: "
f"{satisfiable(example, 2)}")
print()
print("Epistemic status: each verdict is exact (full saturation and a full")
print("truth table), so every set tested agrees with soundness and")
print("completeness. But the sets were sampled at random over four variables;")
print("the theorem for all clause sets, and Goedel's theorem for first-order")
print("logic, are proved in the lesson, not by this experiment.")
if __name__ == "__main__":
main()The second experiment shows compactness in its most concrete form. Colour the natural numbers so that numbers whose difference lies in a set get different colours, and arrange the proper colourings of in a tree, level by level. If a level is empty, a finite part of the problem is already impossible. If every level is non-empty, König's lemma — a finitely branching infinite tree has an infinite branch — gives a colouring of all of . This is the compactness theorem for countably many propositional variables.
"""Compactness in miniature: colouring the natural numbers, level by level.
Join two natural numbers when their difference lies in a set D, and colour
the numbers with k colours so that joined numbers get different colours.
Level n of a tree lists the proper colourings of {0, ..., n - 1}; each node's
children extend it by one more number. If some level is empty, a finite piece
of the graph cannot be coloured. If every level is non-empty, Koenig's lemma
(a finitely branching infinite tree has an infinite branch) gives a colouring
of all of N - the compactness theorem in its simplest form. The program builds
the levels, counts dead ends, and follows a branch that survives to the
deepest level computed. Evidence: exact and exhaustive up to the levels
shown; the passage to infinity is the theorem.
"""
def levels(depth, k, distances):
"""Lists of proper k-colourings (tuples) of {0..n-1} for n = 0..depth."""
tree = [[()]]
for n in range(depth):
nxt = []
for c in tree[-1]:
used = {c[n - d] for d in distances if n - d >= 0}
nxt.extend(c + (col,) for col in range(k) if col not in used)
tree.append(nxt)
return tree
def dead_ends(tree):
"""For each level n < depth, how many nodes have no child at level n + 1."""
out = []
for n in range(len(tree) - 1):
extended = {c[:n] for c in tree[n + 1]}
out.append(len(tree[n]) - len(extended))
return out
def surviving_branch(tree):
"""Koenig's choice: the least child that still has descendants at the bottom."""
bottom = tree[-1]
if not bottom:
return None
branch = ()
for n in range(len(tree) - 1):
options = sorted({c[n] for c in bottom if c[:n] == branch})
branch += (options[0],)
return branch
def is_proper(colouring, distances):
"""Do numbers at a distance in D always get different colours?"""
return all(colouring[i] != colouring[i + d]
for d in distances for i in range(len(colouring) - d))
def main():
print("Numbers whose difference lies in D must get different colours.")
print("Level n = proper colourings of {0, ..., n-1}.")
print()
tree = levels(10, 3, (1, 3, 4))
sizes = [len(t) for t in tree]
print("1. D = {1, 3, 4}, 3 colours. Level sizes:", sizes[:9])
first_empty = sizes.index(0)
print(f" Level {first_empty} is empty: {{0, ..., {first_empty - 1}}} "
"cannot be 3-coloured, so neither can N.")
print()
tree = levels(24, 4, (2, 3, 5, 7))
sizes = [len(t) for t in tree]
print("2. D = {2, 3, 5, 7}, 4 colours. Level sizes for n = 0..24:")
print(" ", sizes[:13])
print(" ", sizes[13:])
dead = dead_ends(tree)
shown = ", ".join(f"{n}: {d}" for n, d in enumerate(dead) if d)
print(" dead ends by level (nodes with no child):")
print(" ", shown)
branch = surviving_branch(tree)
print(" a branch surviving to level 24, always taking the least colour")
print(" that still has descendants at level 24:")
print(" ", "".join(str(c) for c in branch))
mod4 = tuple(n % 4 for n in range(24))
print(f" equals n mod 4: {branch == mod4}; proper: "
f"{is_proper(branch, (2, 3, 5, 7))}")
print(" (n mod 4 colours all of N: 2, 3, 5, 7 are not multiples of 4.)")
print()
print("Epistemic status: exact, exhaustive enumeration up to level 24. No")
print("computation reaches infinity: that non-empty levels at every depth")
print("give a colouring of all of N is Koenig's lemma, a special case of the")
print("compactness theorem (here a proof by periodicity happens to exist).")
if __name__ == "__main__":
main()Both experiments are exact computations of finite cases. The first tests the propositional completeness theorem on randomly sampled clause sets; the second can only ever look at finitely many levels of an infinite tree, and the step to infinity is the theorem, not the computation.
Explore: a finite obstruction
Here is the finite piece of the graph on in which numbers are joined when they differ by , or .
Differences 1, 3 and 4
Can you colour these seven numbers with three colours?
0
colours used
0
clashes
7
uncoloured
Give every vertex a colour so that the two ends of each edge differ.
Try to colour it with three colours so that joined numbers differ. You will fail — the computation section shows that no proper -colouring of these seven vertices exists — and so the whole infinite graph cannot be -coloured. The de Bruijn–Erdős theorem (1951), a consequence of compactness, says that this is the only way an infinite graph can fail to be -colourable: a graph is -colourable if and only if every finite subgraph is. With four colours the obstruction disappears.
Exercises
1. Completeness, compactness and Löwenheim–Skolem
Warm-upHumanWhich statement is Gödel's completeness theorem (as opposed to soundness, or to the incompleteness theorem)?
2. Completeness, compactness and Löwenheim–Skolem
CoreHumanWhich of these classes of structures are first-order axiomatisable (by a possibly infinite set of sentences)? Select all.
3. Completeness, compactness and Löwenheim–Skolem
Warm-upHumanColour the numbers with colours so that numbers differing by or by get different colours. How many such colourings are there?
4. Completeness, compactness and Löwenheim–Skolem
CoreHumanIn the Henkin proof, why do we add a witness constant and the axiom for every formula ?
5. Completeness, compactness and Löwenheim–Skolem
CoreHumanSuppose axiomatised the torsion groups, and let . Why is every finite subset of satisfiable?
6. Completeness, compactness and Löwenheim–Skolem
StretchHumanLet contain an element larger than every numeral. Which statements are true? Select all.
7. Completeness, compactness and Löwenheim–Skolem
CoreHumanA countable model of ZFC contains an element that believes is , and " is uncountable". Yet has only countably many -members. What is the correct resolution?
8. Completeness, compactness and Löwenheim–Skolem
CoreFormalMathlib defines T.IsFinitelySatisfiable as ∀ T0 : Finset L.Sentence, ↑T0 ⊆ T → (↑T0 : L.Theory).IsSatisfiable. Which Lean statement is the compactness theorem?
9. Completeness, compactness and Löwenheim–Skolem
StretchComputationalNumbers are joined when . Write first_empty_level(k, D, max_n) returning the least max_n such that has no proper -colouring, or None if every max_n has one. (Build the colourings level by level: each proper colouring of is extended by a colour for that differs from the colours of , .)
Common misconceptions
Misconception
"The completeness and incompleteness theorems contradict each other." Completeness concerns truth in all models: whatever holds in every model of is provable from . Incompleteness concerns one intended model: some sentences true in are not provable in PA — and they are therefore false in some nonstandard model of PA.
Misconception
"Skolem's paradox shows set theory is inconsistent." A countable model of ZFC contains no bijection between and its version of , although one exists outside the model. "Uncountable" inside means "no bijection in ", so there is no contradiction — only the discovery that countability is relative to the available functions.
Misconception
"A complete proof system makes every theory complete." Completeness of first-order logic means every semantic consequence is derivable. A theory such as the theory of groups is still incomplete — it decides neither commutativity nor its negation — because some of its models satisfy a sentence and others do not.
Misconception
"A nonstandard number knows it is infinite." Inside a nonstandard model of PA, the element larger than every numeral satisfies every first-order property that natural numbers have: it is even or odd, it has a predecessor, it factors into primes. The set of "standard" numbers is not definable in : if it were, by the least-number principle (an instance of induction) the set of nonstandard elements would have a least element, whose predecessor would then be standard — but the successor of a standard number is standard.
Misconception
"Compactness holds for any logic." It is special to first-order logic. Second-order logic can express "the domain is finite" and characterises up to isomorphism, so it is not compact, and it has no sound and complete effective proof system. Per Lindström (1969) proved that first-order logic is the strongest logic satisfying both compactness and the downward Löwenheim–Skolem theorem.
Many ways of seeing
Topology— Why it is called compactness
Let be the set of complete consistent theories in a language (maximal consistent sets of sentences), and give it the topology whose basic open sets are . Each is also closed (its complement is ), so is totally disconnected and Hausdorff. The compactness theorem says precisely that is compact: a family of basic closed sets , , with the finite intersection property is a finitely satisfiable , and a point in the intersection is a complete theory containing . is the Stone space of the Boolean algebra of sentences. For propositional logic with variable set , models are points of the Cantor space , and compactness is Tychonoff's theorem for that product (see point-set topology).
Algebra— Ultrafilters, Boolean algebras and Ax–Grothendieck
Sentences modulo provable equivalence form a Boolean algebra, the Lindenbaum–Tarski algebra, and complete consistent theories are its ultrafilters. So Lindenbaum's lemma is the statement that every proper filter extends to an ultrafilter — the Boolean prime ideal theorem — and Helena Rasiowa and Roman Sikorski (1950) gave an algebraic proof of the completeness theorem along these lines. Compactness then becomes a tool of algebra. A famous example: a sentence of the language of rings that holds in algebraically closed fields of every large enough prime characteristic holds in ; since an injective polynomial map is surjective by a counting argument over finite fields, every injective polynomial map is surjective (the Ax–Grothendieck theorem; full proof in model theory).
Analysis— Infinitesimals made rigorous
For an analyst the most dramatic consequence of compactness is the hyperreal field : an ordered field containing , infinitesimals and infinite numbers, satisfying the transfer principle — every first-order statement about (with all its functions and sets) holds in for the starred versions. In Robinson's nonstandard analysis, is continuous at iff is infinitesimal whenever is, and is the standard part of a Riemann sum with infinitesimal mesh. The theorems obtained are ordinary theorems about : transfer guarantees that nonstandard proofs of standard statements are valid, and some results (for instance in probability and functional analysis) were first found this way.
Combinatorics— Infinite to finite, and back
Compactness moves combinatorics between the finite and the infinite. The de Bruijn–Erdős theorem (1951) says an infinite graph is -colourable iff all its finite subgraphs are: assign a propositional variable to "vertex gets colour " and apply compactness. In the other direction, the finite Ramsey theorem — for all there is such that every -colouring of the -subsets of has a monochromatic -set — follows from the infinite Ramsey theorem by compactness: if no such existed, a compactness (or König's lemma) argument would produce a bad colouring of the -subsets of . Such proofs give no bound on , and sometimes none can be extracted within weak systems: the Paris–Harrington variant (1977) is a true finite statement unprovable in Peano arithmetic.
Computation— What the theorems say about algorithms
The completeness theorem makes first-order validity semi-decidable: enumerate all derivations, and every valid sentence eventually appears. This is the basis of automated theorem provers (resolution, used in the computation section, was introduced by J. A. Robinson in 1965). By Church and Turing (1936) validity is not decidable, and by Gödel the truths of arithmetic are not even semi-decidable. Compactness has a computable shadow as well: König's lemma holds for finitely branching trees, but a computable infinite binary tree need not have a computable infinite branch (Kleene, 1953). Tennenbaum's theorem adds that nonstandard models of PA, which compactness guarantees, can never be computable.
History and global context
- Leopold Löwenheim (1915) proved that a first-order sentence with a model has a countable model; Thoralf Skolem (1920, 1922) simplified the proof, extended it to countable sets of sentences, and in 1922 formulated the "paradox" that bears his name. Skolem also constructed nonstandard models of arithmetic directly (1933–34).
- David Hilbert and Wilhelm Ackermann posed the completeness problem in their textbook Grundzüge der theoretischen Logik (1928). Kurt Gödel solved it in his Vienna doctoral thesis (1929, published 1930), proving compactness for countable languages along the way. Jacques Herbrand (1930) independently developed closely related results on the reduction of first-order provability to propositional logic.
- Anatolii Maltsev in the Soviet Union proved compactness for languages of arbitrary cardinality (1936) and applied it to group theory (1941). Alfred Tarski gave the mathematical definition of truth in a structure (1933), and with Robert Vaught developed elementary substructures (1957).
- Leon Henkin gave the proof used today in 1949; Helena Rasiowa and Roman Sikorski in Warsaw gave an algebraic proof (1950). Nicolaas de Bruijn and Paul Erdős proved their colouring theorem in 1951, and Abraham Robinson created nonstandard analysis in 1961.
- Stanley Tennenbaum proved the non-computability of nonstandard models of PA (1959), and Per Lindström in Sweden characterised first-order logic by compactness and Löwenheim–Skolem (1969).
Further reading
- Herbert B. Enderton, A Mathematical Introduction to Logic (1972; second edition 2001) — completeness, compactness and Löwenheim–Skolem at exactly this level.
- Heinz-Dieter Ebbinghaus, Jörg Flum and Wolfgang Thomas, Mathematical Logic (1984; third edition 2021) — includes Lindström's theorem.
- Dirk van Dalen, Logic and Structure (1980; fifth edition 2013) — natural deduction and the Henkin proof.
- David Marker, Model Theory: An Introduction (2002) — compactness and Löwenheim–Skolem as tools, with algebraic applications.
- Wilfrid Hodges, A Shorter Model Theory (1997).
- Robert Goldblatt, Lectures on the Hyperreals: An Introduction to Nonstandard Analysis (1998).
- Richard Kaye, Models of Peano Arithmetic (1991) — nonstandard models and Tennenbaum's theorem.