Skip to content
The Lumenary
Advanced undergraduateUndergraduate 120 min

Completeness, compactness and Löwenheim–Skolem

Every consistent theory has a model — and three surprises follow: finiteness cannot be axiomatised, arithmetic has nonstandard models, and set theory has a countable model.

Formally verified · 13 LeanComputationally tested · 2 PythonAI-drafted · awaiting human reviewMathematically reviewed: Awaiting human review
MotivationH

Truth in every model, and proof

There are two ways to say that a sentence φ\varphi follows from a set of sentences Γ\Gamma.

  • Semantically: Γ⊨φ\Gamma \models \varphi if φ\varphi is true in every structure in which all the sentences of Γ\Gamma are true. To check this one must, in principle, survey all structures — infinitely many, of every size.
  • Syntactically: Γ⊢φ\Gamma \vdash \varphi if there is a formal derivation of φ\varphi from Γ\Gamma: a finite list of formulas, each an axiom, a member of Γ\Gamma or obtained from earlier lines by a rule.

The lesson on first-order logic proved soundness: if Γ⊢φ\Gamma \vdash \varphi then Γ⊨φ\Gamma \models \varphi, 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 Γ\Gamma and every sentence φ\varphi:  Γ⊨φ  ⟹  Γ⊢φ\ \Gamma \models \varphi \implies \Gamma \vdash \varphi. 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.

IntuitionH

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 cc, f(c)f(c), f(f(c),d)f(f(c), d) — 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 ∃x φ(x)\exists x\, \varphi(x), it must contain φ(c)\varphi(c) for some named constant cc. 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 C\C as R[x]/(x2+1)\R[x]/(x^2 + 1): one manufactures the new objects from symbols (polynomials, terms) and then identifies two of them when the rules force them to be equal (x2+1=0x^2 + 1 = 0, or "the theory proves t=st = s"). 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.

DefinitionsH

Definitions

Fix a first-order language LL (constant, function and relation symbols) and write ∣L∣|L| for the number of its symbols. An LL-structure MM is a non-empty set with interpretations of the symbols; M⊨φM \models \varphi means the sentence φ\varphi is true in MM.

Definition— models, consistency, satisfiability

A model of a set of sentences Γ\Gamma is a structure in which every sentence of Γ\Gamma is true. Γ\Gamma is satisfiable if it has a model, and finitely satisfiable if each of its finite subsets has a model. Γ\Gamma is consistent if there is no φ\varphi with Γ⊢φ\Gamma \vdash \varphi and Γ⊢¬φ\Gamma \vdash \neg\varphi (equivalently, Γ⊬⊥\Gamma \nvdash \bot).

Definition— complete theories, witnesses

Γ\Gamma is complete if for every sentence φ\varphi, Γ⊢φ\Gamma \vdash \varphi or Γ⊢¬φ\Gamma \vdash \neg\varphi. A consistent Γ\Gamma is maximal consistent if no proper superset is consistent. Γ\Gamma has the witness property (is a Henkin theory) if for every formula φ(x)\varphi(x) with one free variable there is a constant cc with (∃x φ(x)→φ(c))∈Γ(\exists x\, \varphi(x) \to \varphi(c)) \in \Gamma.

Definition— elementary substructure

MM and NN are elementarily equivalent, M≡NM \equiv N, if they satisfy the same sentences. If N⊆MN \subseteq M is a substructure, it is an elementary substructure, N⪯MN \preceq M, if for every formula φ(x⃗)\varphi(\vec x) and every tuple b⃗\vec b from NN: N⊨φ(b⃗)  ⟺  M⊨φ(b⃗)N \models \varphi(\vec b) \iff M \models \varphi(\vec b).

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 ⊢\vdash, all standard for natural deduction or Hilbert-style systems:

  1. Finiteness. If Γ⊢φ\Gamma \vdash \varphi then Γ0⊢φ\Gamma_0 \vdash \varphi for some finite Γ0⊆Γ\Gamma_0 \subseteq \Gamma (a derivation uses finitely many hypotheses).
  2. Splitting. If Γ∪{φ}\Gamma \cup \{\varphi\} and Γ∪{¬φ}\Gamma \cup \{\neg\varphi\} are both inconsistent, so is Γ\Gamma (proof by cases).
  3. Constants are generic. If Γ⊢ψ(c)\Gamma \vdash \psi(c) and the constant cc occurs neither in Γ\Gamma nor in ψ(x)\psi(x), then Γ⊢∀x ψ(x)\Gamma \vdash \forall x\, \psi(x).
  4. Equality and logic. The usual rules for == (reflexivity, symmetry, transitivity, substitution) and for the connectives and quantifiers, e.g. ψ(t)⊢∃x ψ(x)\psi(t) \vdash \exists x\, \psi(x).
Worked examplesH

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 "∀x ∀y xy=yx\forall x\, \forall y\ xy = yx" 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 (Q,<)(\Q, <), (R,<)(\R, <) and (Q∩(0,1),<)(\Q \cap (0, 1), <). 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 Th(N)={φ∣(N,0,1,+,×,<)⊨φ}\mathrm{Th}(\N) = \{\varphi \mid (\N, 0, 1, +, \times, <) \models \varphi\} is complete by definition. We will show it has models not isomorphic to N\N.

Example— Saying 'at least n elements'

The sentence σn=∃x1⋯∃xn⋀i<jxi≠xj\sigma_n = \exists x_1 \cdots \exists x_n \bigwedge_{i < j} x_i \neq x_j is true in a structure exactly when it has at least nn elements. So {σ1,σ2,σ3,… }\{\sigma_1, \sigma_2, \sigma_3, \dots\} 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 cc, let Γ=Th(N)∪{ c>0‾, c>1‾, c>2‾,… }\Gamma = \mathrm{Th}(\N) \cup \{\, c > \overline{0},\ c > \overline{1},\ c > \overline{2}, \dots \}, where n‾\overline{n} is the numeral 1+1+⋯+11 + 1 + \cdots + 1. No natural number is larger than every numeral, so (N,c)(\N, c) is not a model, whatever cc is. But any finite subset mentions only finitely many numerals, and N\N with cc interpreted as a large enough number is a model of it. So Γ\Gamma is finitely satisfiable.

ProofH

The completeness theorem

Theorem— Theorem 1 (completeness, countable languages)

Let LL be a countable language. Every consistent set Γ\Gamma of LL-sentences has a model, of cardinality at most ℵ0\aleph_0. Consequently, if Γ⊨φ\Gamma \models \varphi then Γ⊢φ\Gamma \vdash \varphi.

Proof

Step 1: adding witnesses. Let L0=LL_0 = L. Given LnL_n, add a new constant cφc_\varphi for each LnL_n-formula φ(x)\varphi(x) with one free variable, obtaining Ln+1L_{n+1}, and let L∗=⋃nLnL^* = \bigcup_n L_n, still countable. Let HH be the set of Henkin axioms ∃x φ(x)→φ(cφ)\exists x\, \varphi(x) \to \varphi(c_\varphi), one for each L∗L^*-formula φ(x)\varphi(x) (each such formula lies in some LnL_n, and cφc_\varphi is a constant of Ln+1L_{n+1}).

Claim: Γ∪H\Gamma \cup H is consistent. By finiteness it suffices to show Γ∪H0\Gamma \cup H_0 consistent for finite H0⊆HH_0 \subseteq H. Add the axioms of H0H_0 to Γ\Gamma one at a time, in order of increasing level of their constants. When the axiom for cφc_\varphi is added to the set Δ\Delta built so far, cφc_\varphi occurs neither in φ(x)\varphi(x) nor in Δ\Delta: the axioms already in Δ\Delta 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 Δ\Delta is consistent but Δ∪{∃x φ(x)→φ(c)}\Delta \cup \{\exists x\, \varphi(x) \to \varphi(c)\} is not. Then Δ⊢¬(∃x φ(x)→φ(c))\Delta \vdash \neg(\exists x\, \varphi(x) \to \varphi(c)), so Δ⊢∃x φ(x)\Delta \vdash \exists x\, \varphi(x) and Δ⊢¬φ(c)\Delta \vdash \neg\varphi(c). By property 3, Δ⊢∀x ¬φ(x)\Delta \vdash \forall x\, \neg\varphi(x), i.e. Δ⊢¬∃x φ(x)\Delta \vdash \neg \exists x\, \varphi(x), and Δ\Delta is inconsistent — a contradiction.

Step 2: completing (Lindenbaum's lemma). List all L∗L^*-sentences as ψ0,ψ1,ψ2,…\psi_0, \psi_1, \psi_2, \dots. Put Γ0=Γ∪H\Gamma_0 = \Gamma \cup H and

Γn+1={Γn∪{ψn}if this is consistent,Γn∪{¬ψn}otherwise.\Gamma_{n+1} = \begin{cases} \Gamma_n \cup \{\psi_n\} & \text{if this is consistent,} \\ \Gamma_n \cup \{\neg\psi_n\} & \text{otherwise.} \end{cases}

By property 2, each Γn\Gamma_n is consistent. Let Γ∗=⋃nΓn\Gamma^* = \bigcup_n \Gamma_n. It is consistent by finiteness (a derivation of ⊥\bot would use hypotheses from a single Γn\Gamma_n), it contains ψ\psi or ¬ψ\neg\psi for every sentence ψ\psi, and it is deductively closed: if Γ∗⊢ψ\Gamma^* \vdash \psi then ψ∈Γ∗\psi \in \Gamma^*, since otherwise ¬ψ∈Γ∗\neg\psi \in \Gamma^* and Γ∗\Gamma^* would be inconsistent.

Step 3: the term model. For closed L∗L^*-terms put t∼st \sim s if (t=s)∈Γ∗(t = s) \in \Gamma^*. By the equality rules and deductive closure, ∼\sim is an equivalence relation compatible with the function symbols and relations. Let MM be the set of classes [t][t], and interpret: cM=[c]c^M = [c], fM([t1],…,[tk])=[f(t1,…,tk)]f^M([t_1], \dots, [t_k]) = [f(t_1, \dots, t_k)], and RM([t1],…,[tk])R^M([t_1], \dots, [t_k]) iff R(t1,…,tk)∈Γ∗R(t_1, \dots, t_k) \in \Gamma^*. These are well defined by the substitution rule for equality. Every element of MM is named by a closed term, and MM is countable.

Step 4: the truth lemma. For every L∗L^*-sentence ψ\psi:  M⊨ψ  ⟺  ψ∈Γ∗\ M \models \psi \iff \psi \in \Gamma^*. By induction on the number of connectives and quantifiers in ψ\psi.

  • Atomic ψ\psi: by the definition of MM (closed terms denote their own classes).
  • ¬ψ\neg\psi: M⊨¬ψ  ⟺  M⊭ψ  ⟺  ψ∉Γ∗  ⟺  ¬ψ∈Γ∗M \models \neg\psi \iff M \not\models \psi \iff \psi \notin \Gamma^* \iff \neg\psi \in \Gamma^*, the last step because Γ∗\Gamma^* contains exactly one of ψ\psi and ¬ψ\neg\psi.
  • ψ∧χ\psi \land \chi: by deductive closure, ψ∧χ∈Γ∗\psi \land \chi \in \Gamma^* iff both ψ,χ∈Γ∗\psi, \chi \in \Gamma^*.
  • ∃x φ(x)\exists x\, \varphi(x): if ∃x φ(x)∈Γ∗\exists x\, \varphi(x) \in \Gamma^*, the Henkin axiom and deductive closure give φ(cφ)∈Γ∗\varphi(c_\varphi) \in \Gamma^*; by induction M⊨φ(cφ)M \models \varphi(c_\varphi), so M⊨∃x φ(x)M \models \exists x\, \varphi(x). Conversely, if M⊨∃x φ(x)M \models \exists x\, \varphi(x), some element [t][t] is a witness, so M⊨φ(t)M \models \varphi(t); φ(t)\varphi(t) has fewer logical symbols than ∃x φ(x)\exists x\, \varphi(x), so by induction φ(t)∈Γ∗\varphi(t) \in \Gamma^*, and since φ(t)⊢∃x φ(x)\varphi(t) \vdash \exists x\, \varphi(x), deductive closure gives ∃x φ(x)∈Γ∗\exists x\, \varphi(x) \in \Gamma^*.

(The other connectives and ∀\forall are expressible by ¬\neg, ∧\land, ∃\exists.) In particular M⊨ΓM \models \Gamma, and forgetting the new constants gives a countable LL-structure that is a model of Γ\Gamma.

The second form. If Γ⊬φ\Gamma \nvdash \varphi, then Γ∪{¬φ}\Gamma \cup \{\neg\varphi\} is consistent (otherwise Γ⊢¬¬φ\Gamma \vdash \neg\neg\varphi, hence Γ⊢φ\Gamma \vdash \varphi), so it has a model, which shows Γ⊭φ\Gamma \not\models \varphi.

∎

For a language of any cardinality κ\kappa the same proof works with transfinite lists (or Zorn's lemma in Step 2) and gives a model of cardinality at most κ+ℵ0\kappa + \aleph_0. 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.

ProofH

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 Γ\Gamma has no model. By completeness Γ\Gamma is inconsistent, i.e. Γ⊢⊥\Gamma \vdash \bot. The derivation uses only a finite Γ0⊆Γ\Gamma_0 \subseteq \Gamma, so Γ0⊢⊥\Gamma_0 \vdash \bot, and by soundness Γ0\Gamma_0 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 TT 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 Γ=T∪{σ1,σ2,… }\Gamma = T \cup \{\sigma_1, \sigma_2, \dots\}, where σn\sigma_n says "there are at least nn elements". A finite Γ0⊆Γ\Gamma_0 \subseteq \Gamma contains only σn\sigma_n with n≤Nn \le N for some NN, and a model of TT with at least NN elements is a model of Γ0\Gamma_0. By compactness Γ\Gamma has a model, which is a model of TT satisfying every σn\sigma_n — an infinite model. If TT's models were exactly the finite structures, TT 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 TT were a set of sentences in the language of groups whose models are exactly the torsion groups. Add a constant cc and let Γ=T∪{cn≠e∣n≥1}\Gamma = T \cup \{c^n \neq e \mid n \ge 1\}. A finite subset mentions only cn≠ec^n \neq e for n≤Nn \le N; it is satisfied in the torsion group Z/(N+1)\Z/(N + 1) with c=1c = 1. By compactness Γ\Gamma has a model: a torsion group (it satisfies TT) containing an element cc 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 σ1,σ2,…\sigma_1, \sigma_2, \dots to the group axioms — but not by finitely many sentences.

Theorem— Theorem 5 (nonstandard models of arithmetic)

There is a structure M≡(N,0,1,+,×,<)M \equiv (\N, 0, 1, +, \times, <) that contains an element larger than every numeral n‾\overline{n}. In particular M≇NM \not\cong \N, and the same holds for models of Peano arithmetic.

Proof

The set Γ=Th(N)∪{c>n‾∣n∈N}\Gamma = \mathrm{Th}(\N) \cup \{c > \overline{n} \mid n \in \N\} is finitely satisfiable, as shown in the examples. By compactness it has a model MM, which satisfies Th(N)\mathrm{Th}(\N) (so M≡NM \equiv \N; in particular MM satisfies the axioms of PA) and contains cM>n‾Mc^M > \overline{n}^M for every nn. An isomorphism N→M\N \to M would have to send nn to n‾M\overline{n}^M, missing cMc^M.

∎

Such an MM looks like N\N followed by further "galaxies": every element has a successor and every non-zero element a predecessor, so cMc^M sits in a copy of Z\Z, and between and above these copies there are densely ordered families of others — a countable nonstandard model has order type ω+(ω∗+ω)⋅η\omega + (\omega^* + \omega) \cdot \eta, where η\eta is the order type of Q\Q. Its arithmetic is wild: Stanley Tennenbaum (1959) proved that in a countable nonstandard model of PA neither ++ nor ×\times is computable.

Example— Infinitesimals

Let R♯\R^\sharp be the structure R\R with a symbol for every real number, every subset of Rn\R^n and every function Rn→R\R^n \to \R. Add a constant ε\varepsilon and the sentences 0<ε<r‾0 < \varepsilon < \overline{r} for every real r>0r > 0. Every finite subset is satisfied in R♯\R^\sharp by a small enough real ε\varepsilon, so by compactness there is a structure ∗R≡R♯{}^*\R \equiv \R^\sharp with a positive element smaller than every positive real: an infinitesimal. Because ∗R{}^*\R satisfies exactly the same sentences as R♯\R^\sharp, 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 f′(x)f'(x) is the standard part of (f(x+ε)−f(x))/ε(f(x + \varepsilon) - f(x))/\varepsilon — a rigorous version of Leibniz's infinitesimals.

ProofH

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 NN be a substructure of MM. Then N⪯MN \preceq M if and only if: for every formula φ(x,y⃗)\varphi(x, \vec y) and every tuple b⃗\vec b from NN, if M⊨∃x φ(x,b⃗)M \models \exists x\, \varphi(x, \vec b) then M⊨φ(a,b⃗)M \models \varphi(a, \vec b) for some a∈Na \in N.

Proof

(⇒\Rightarrow) If M⊨∃x φ(x,b⃗)M \models \exists x\, \varphi(x, \vec b) then N⊨∃x φ(x,b⃗)N \models \exists x\, \varphi(x, \vec b) by elementarity, so some a∈Na \in N has N⊨φ(a,b⃗)N \models \varphi(a, \vec b), hence M⊨φ(a,b⃗)M \models \varphi(a, \vec b). (⇐\Leftarrow) Show N⊨ψ(b⃗)  ⟺  M⊨ψ(b⃗)N \models \psi(\vec b) \iff M \models \psi(\vec b) by induction on ψ\psi. Atomic formulas agree because NN is a substructure, and the connective steps are immediate. For ψ=∃x φ(x,y⃗)\psi = \exists x\, \varphi(x, \vec y): if N⊨ψ(b⃗)N \models \psi(\vec b), a witness in NN is a witness in MM by induction; if M⊨ψ(b⃗)M \models \psi(\vec b), the test provides a witness a∈Na \in N with M⊨φ(a,b⃗)M \models \varphi(a, \vec b), so N⊨φ(a,b⃗)N \models \varphi(a, \vec b) by induction, and N⊨ψ(b⃗)N \models \psi(\vec b).

∎

Theorem— Theorem 7 (downward Löwenheim–Skolem)

Let LL be countable, MM an LL-structure and A⊆MA \subseteq M countable. Then there is a countable N⪯MN \preceq M with A⊆NA \subseteq N.

Proof

Put A0=AA_0 = A. Given a countable AnA_n, there are countably many pairs (φ,b⃗)(\varphi, \vec b) with b⃗\vec b a tuple from AnA_n; for each with M⊨∃x φ(x,b⃗)M \models \exists x\, \varphi(x, \vec b) choose a witness a∈Ma \in M (this uses countable choice), and let An+1A_{n+1} be AnA_n together with the chosen witnesses — still countable. Let N=⋃nAnN = \bigcup_n A_n, which is countable. It is closed under the functions of MM (a witness for ∃x (x=f(b⃗))\exists x\, (x = f(\vec b)) is f(b⃗)f(\vec b) itself) and contains the constants (witnesses for ∃x (x=c)\exists x\, (x = c)), so it is a substructure, and it satisfies the Tarski–Vaught test by construction: a formula with parameters from NN has its parameters in some AnA_n, and a witness was added in An+1A_{n+1}. So N⪯MN \preceq M.

∎

Theorem— Theorem 8 (upward Löwenheim–Skolem)

If a theory TT in a countable language has an infinite model, then it has a model of every infinite cardinality κ\kappa.

Proof

Add κ\kappa new constants cαc_\alpha (α<κ\alpha < \kappa) and let Γ=T∪{cα≠cβ∣α≠β}\Gamma = T \cup \{c_\alpha \neq c_\beta \mid \alpha \neq \beta\}. A finite subset mentions finitely many constants, which can be interpreted as distinct elements of an infinite model of TT; so by compactness (for a language of size κ\kappa) Γ\Gamma has a model, which has at least κ\kappa elements. The downward theorem for languages of size κ\kappa (same proof, with ∣An∣≤κ|A_n| \le \kappa) applied to A={cαM}A = \{c_\alpha^M\} gives an elementary substructure of cardinality exactly κ\kappa, still a model of Γ\Gamma and hence of TT.

∎

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. Th(N)\mathrm{Th}(\N) has uncountable models; Th(R,+,×,<)\mathrm{Th}(\R, +, \times, <) 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 TT has no finite models and all its models of some infinite cardinality κ≥∣L∣\kappa \ge |L| are isomorphic, then TT is complete. For instance DLO is ℵ0\aleph_0-categorical (Cantor), hence complete, so (Q,<)(\Q, <) and (R,<)(\R, <) satisfy exactly the same sentences.

Skolem's paradox. ZFC is a first-order theory in the countable language {∈}\{\in\}. If it is consistent, it has a model, and by Theorem 7 a countable model (M,E)(M, E). But ZFC proves that P(ω)\mathcal P(\omega) is uncountable, so MM contains an element pp that MM believes is P(ω)\mathcal P(\omega) and believes is uncountable — while pp has only countably many EE-members, since MM itself is countable. There is no contradiction. "pp is uncountable" means, inside MM, "there is no bijection between ω\omega and pp that is an element of MM". A bijection between the EE-members of ωM\omega^M and of pp exists outside MM, but it is not one of MM'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.

ExplanationH

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 TT, then TT proves it.
  • Incompleteness is about one intended model: for any consistent, effectively axiomatised theory TT containing enough arithmetic, such as PA, there is a sentence GG that is true in N\N but not provable in TT (see Gödel's incompleteness theorems).

Put together: since PA⊬G\mathrm{PA} \nvdash G, the completeness theorem says that PA∪{¬G}\mathrm{PA} \cup \{\neg G\} has a model. That model satisfies PA but not GG, so it is not N\N: it is a nonstandard model, whose existence we already know from compactness. True-in-N\N 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).

Formal mathematicsF

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 ⊢\vdash 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:

FinitaryLean 4Formally verified
/-- 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 Δ
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor
lindenbaumLean 4Proved here from basic factsFormally verified
/-- **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⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor
maximal_mem_or_neg_memLean 4Proved here from basic factsFormally verified
/-- **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)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor

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:

compactnessLean 4Applies a library theoremFormally verified
/-- **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
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor
satisfiable_finitaryLean 4Applies a library theoremFormally verified
/-- **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
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor
satisfiable_splitLean 4Proved here from basic factsFormally verified
/-- **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 M
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor

so the abstract Lindenbaum lemma applies to it: every satisfiable theory extends to a maximal satisfiable theory, which decides every sentence.

exists_maximal_extensionLean 4Proved here from basic factsFormally verified
/-- **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 φ
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor

Theorem 3 and its consequence, proved as in the lesson. In Lean the sets T∪{σk∣k<n}T \cup \{\sigma_k \mid k < n\} form a directed family whose union is T∪{σk∣k∈N}T \cup \{\sigma_k \mid k \in \N\}, and Mathlib's compactness for directed unions does the rest:

exists_infinite_modelLean 4Proved here from basic factsFormally verified
/-- **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⟩
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor
finiteness_not_axiomatizableLean 4Proved here from basic factsFormally verified
/-- **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 M
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor

From Mathlib: the Löwenheim–Skolem theorem in "theory" form (models of every infinite cardinality at least ∣L∣|L|), compactness for consequence, and the theory DLO — Cantor's ℵ0\aleph_0-categoricity and its completeness by the Łoś–Vaught test:

lowenheim_skolemLean 4Applies a library theoremFormally verified
/-- **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
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor
models_iff_finset_modelsLean 4Applies a library theoremFormally verified
/-- **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
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor
dlo_categoricalLean 4Applies a library theoremFormally verified
/-- **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
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor
dlo_completeLean 4Applies a library theoremFormally verified
/-- **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_isComplete
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/CompletenessTheorem.leanTry it in the Lean web editor

What 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.

ComputationC

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 C∪{v}C \cup \{v\} and D∪{¬v}D \cup \{\neg v\} one derives C∪DC \cup D. 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 iff satisfiable: resolution versus truth tablesPythonExact computationExperimental evidenceComputationally tested
"""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()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

The second experiment shows compactness in its most concrete form. Colour the natural numbers so that numbers whose difference lies in a set DD get different colours, and arrange the proper colourings of {0,…,n−1}\{0, \dots, n - 1\} 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 N\N. This is the compactness theorem for countably many propositional variables.

Compactness via Koenig's lemma: colouring N level by levelPythonExact computationExhaustive finite checkCounterexampleComputationally tested
"""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()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

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

Explore: a finite obstruction

Here is the finite piece {0,1,…,6}\{0, 1, \dots, 6\} of the graph on N\N in which numbers are joined when they differ by 11, 33 or 44.

Differences 1, 3 and 4

Can you colour these seven numbers with three colours?

0123456
|V| = 7|E| = 13Click a vertex to change its colour (Delete removes it).

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 33-colouring of these seven vertices exists — and so the whole infinite graph cannot be 33-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 kk-colourable: a graph is kk-colourable if and only if every finite subgraph is. With four colours the obstruction disappears.

Exercises

Exercises

1. Completeness, compactness and Löwenheim–Skolem

Warm-upHuman

Which statement is Gödel's completeness theorem (as opposed to soundness, or to the incompleteness theorem)?

Choose one

2. Completeness, compactness and Löwenheim–Skolem

CoreHuman

Which of these classes of structures are first-order axiomatisable (by a possibly infinite set of sentences)? Select all.

Choose all that apply

3. Completeness, compactness and Löwenheim–Skolem

Warm-upHuman

Colour the numbers 0,1,…,90, 1, \dots, 9 with 33 colours so that numbers differing by 11 or by 22 get different colours. How many such colourings are there?

4. Completeness, compactness and Löwenheim–Skolem

CoreHuman

In the Henkin proof, why do we add a witness constant cφc_\varphi and the axiom ∃x φ(x)→φ(cφ)\exists x\, \varphi(x) \to \varphi(c_\varphi) for every formula φ\varphi?

Choose one

5. Completeness, compactness and Löwenheim–Skolem

CoreHuman

Suppose TT axiomatised the torsion groups, and let Γ=T∪{cn≠e∣n≥1}\Gamma = T \cup \{c^n \neq e \mid n \ge 1\}. Why is every finite subset of Γ\Gamma satisfiable?

Choose one

6. Completeness, compactness and Löwenheim–Skolem

StretchHuman

Let M≡(N,0,1,+,×,<)M \equiv (\N, 0, 1, +, \times, <) contain an element cc larger than every numeral. Which statements are true? Select all.

Choose all that apply

7. Completeness, compactness and Löwenheim–Skolem

CoreHuman

A countable model (M,E)(M, E) of ZFC contains an element pp that MM believes is P(ω)\mathcal P(\omega), and M⊨M \models "pp is uncountable". Yet pp has only countably many EE-members. What is the correct resolution?

Choose one

8. Completeness, compactness and Löwenheim–Skolem

CoreFormal

Mathlib defines T.IsFinitelySatisfiable as ∀ T0 : Finset L.Sentence, ↑T0 ⊆ T → (↑T0 : L.Theory).IsSatisfiable. Which Lean statement is the compactness theorem?

Choose one

9. Completeness, compactness and Löwenheim–Skolem

StretchComputational

Numbers i,ji, j are joined when ∣i−j∣∈D|i - j| \in D. Write first_empty_level(k, D, max_n) returning the least n≤n \le max_n such that {0,…,n−1}\{0, \dots, n - 1\} has no proper kk-colouring, or None if every n≤n \le max_n has one. (Build the colourings level by level: each proper colouring of {0,…,n−1}\{0, \dots, n - 1\} is extended by a colour for nn that differs from the colours of n−dn - d, d∈Dd \in D.)

Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.
Common misconceptionsH

Common misconceptions

Misconception

"The completeness and incompleteness theorems contradict each other." Completeness concerns truth in all models: whatever holds in every model of TT is provable from TT. Incompleteness concerns one intended model: some sentences true in N\N 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 MM of ZFC contains no bijection between ω\omega and its version of P(ω)\mathcal P(\omega), although one exists outside the model. "Uncountable" inside MM means "no bijection in MM", 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 MM of PA, the element cc 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 {n‾M}\{\overline{n}^M\} is not definable in MM: 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 N\N 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.

ViewpointsH

Many ways of seeing

Topology— Why it is called compactness

Let SS be the set of complete consistent theories in a language LL (maximal consistent sets of sentences), and give it the topology whose basic open sets are [φ]={T∈S∣φ∈T}[\varphi] = \{T \in S \mid \varphi \in T\}. Each [φ][\varphi] is also closed (its complement is [¬φ][\neg\varphi]), so SS is totally disconnected and Hausdorff. The compactness theorem says precisely that SS is compact: a family of basic closed sets [φ][\varphi], φ∈Γ\varphi \in \Gamma, with the finite intersection property is a finitely satisfiable Γ\Gamma, and a point in the intersection is a complete theory containing Γ\Gamma. SS is the Stone space of the Boolean algebra of sentences. For propositional logic with variable set VV, models are points of the Cantor space {0,1}V\{0, 1\}^V, 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 C\C; since an injective polynomial map F‾p n→F‾p n\overline{\mathbb F}_p^{\,n} \to \overline{\mathbb F}_p^{\,n} is surjective by a counting argument over finite fields, every injective polynomial map Cn→Cn\C^n \to \C^n 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 ∗R{}^*\R: an ordered field containing R\R, infinitesimals and infinite numbers, satisfying the transfer principle — every first-order statement about R\R (with all its functions and sets) holds in ∗R{}^*\R for the starred versions. In Robinson's nonstandard analysis, ff is continuous at aa iff f(x)−f(a)f(x) - f(a) is infinitesimal whenever x−ax - a is, and ∫abf\int_a^b f is the standard part of a Riemann sum with infinitesimal mesh. The theorems obtained are ordinary theorems about R\R: 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 kk-colourable iff all its finite subgraphs are: assign a propositional variable xv,ix_{v, i} to "vertex vv gets colour ii" and apply compactness. In the other direction, the finite Ramsey theorem — for all k,mk, m there is NN such that every 22-colouring of the kk-subsets of {1,…,N}\{1, \dots, N\} has a monochromatic mm-set — follows from the infinite Ramsey theorem by compactness: if no such NN existed, a compactness (or König's lemma) argument would produce a bad colouring of the kk-subsets of N\N. Such proofs give no bound on NN, 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 & global context

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

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.