Skip to content
The Lumenary
First-year graduateGraduate 130 min

Gödel's incompleteness theorems

Arithmetic can talk about its own proofs — and so no consistent, computably axiomatised theory of arithmetic proves every arithmetical truth, or its own consistency.

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

Hilbert's question

In the 1920s David Hilbert proposed a programme for the foundations of mathematics: formalise each branch of mathematics in a precise axiomatic system, in which proofs are finite strings checkable by rule; show that the system is complete (every statement of its language is proved or refuted); and prove its consistency by "finitary" means that nobody could doubt. If it succeeded, mathematical truth would coincide with provability in a fixed, mechanically checkable system, and that system would certify its own reliability.

In 1931 Kurt Gödel showed that both hopes fail for any system strong enough to do elementary arithmetic — and the reason is not a defect of a particular axiom system but a structural fact. A theory whose proofs can be checked mechanically can talk about its own proofs, because syntax can be coded in arithmetic. A diagonal argument, of the same shape as Cantor's, then produces a sentence that says, in effect, "I am not provable".

Today every proof assistant, including the Lean system used throughout this curriculum, is a mechanical proof checker of exactly the kind Hilbert envisaged. The incompleteness theorems tell us what such systems can never do: there will always be true arithmetical statements that a given system does not prove, and a consistent system cannot prove its own consistency.

IntuitionH

The liar, tamed

The liar sentence "this sentence is false" is a paradox: it is true if and only if it is false. Gödel replaced truth by provability:

Gsays“G is not provable in T.”G \quad\text{says}\quad \text{“}G \text{ is not provable in } T\text{.”}

Now there is no paradox, only a dilemma. If TT proved GG, then TT would prove a sentence asserting its own unprovability — so (if TT proves only truths) GG would be both provable and false. Hence TT does not prove GG; and that is exactly what GG says, so GG is true but unprovable in TT.

Two ingredients make this rigorous, and both are mathematics rather than philosophy:

  1. Arithmetisation. Formulas and proofs are finite strings, so they can be coded by numbers. "xx is the code of a proof of the formula with code yy" becomes an arithmetical relation between numbers, which the theory can express.
  2. Diagonalisation. A sentence cannot literally contain itself, but it can contain a description that evaluates to its own code — just as Cantor's diagonal sequence differs from the nn-th listed sequence at place nn.

The common shape of these diagonal arguments was isolated by F. William Lawvere (1969): if every map A→BA \to B is of the form e(a,−)e(a, -), then every map f:B→Bf : B \to B has a fixed point. In the diagram, e^(a,a′)=e(a)(a′)\hat e(a, a') = e(a)(a') and the dashed map g=f∘e^∘Δg = f \circ \hat e \circ \Delta is the "diagonal"; if g=e(a0)g = e(a_0) then b=e(a0)(a0)b = e(a_0)(a_0) is a fixed point of ff.

A×AA \times A
BB
AA
BB
Δ\Delta
e^\hat e
ff
gg
Lawvere's fixed-point theorem: if e:A→BAe : A \to B^A is surjective, the diagonal map gg equals e(a0)e(a_0), and e(a0)(a0)e(a_0)(a_0) is a fixed point of ff.

Cantor's theorem is the case B={0,1}B = \{0, 1\} with ff = negation, which has no fixed point, so no surjection A→2AA \to 2^A exists. Tarski's theorem is the case where BB is the set of truth values of sentences and ff is negation. Gödel's theorem is the case where negation is replaced by "not provable", which does have a fixed point — the Gödel sentence.

DefinitionsH

Theories, codes and representability

We work in first-order logic (see the completeness theorem) in the language LA={0,S,+,×}L_A = \{0, S, +, \times\} of arithmetic. The numeral of n∈Nn \in \N is the term n‾=SS⋯S0\overline{n} = S S \cdots S 0 with nn copies of SS.

Definition— Robinson arithmetic and Peano arithmetic

Robinson arithmetic Q\mathsf{Q} (R. M. Robinson, 1950) is the theory with the seven axioms

Sx≠0,Sx=Sy→x=y,x≠0→∃y (x=Sy),x+0=x,x+Sy=S(x+y),x×0=0,x×Sy=(x×y)+x.\begin{aligned} &Sx \neq 0, \qquad Sx = Sy \to x = y, \qquad x \neq 0 \to \exists y\, (x = Sy),\\ &x + 0 = x, \qquad x + Sy = S(x + y), \qquad x \times 0 = 0, \qquad x \times Sy = (x \times y) + x . \end{aligned}

We write x≤yx \le y for ∃v (v+x=y)\exists v\,(v + x = y). Peano arithmetic PA\mathsf{PA} is Q\mathsf{Q} together with the induction schema (φ(0)∧∀x (φ(x)→φ(Sx)))→∀x φ(x)\big(\varphi(0) \wedge \forall x\,(\varphi(x) \to \varphi(Sx))\big) \to \forall x\, \varphi(x) for every formula φ\varphi. Q\mathsf{Q} has no induction at all; it cannot even prove ∀x (0+x=x)\forall x\,(0 + x = x).

Definition— consistent, complete, recursively axiomatised

A theory TT (a set of sentences, closed under consequence when convenient) is consistent if it proves no sentence together with its negation, and complete if for every sentence φ\varphi of its language, T⊢φT \vdash \varphi or T⊢¬φT \vdash \neg\varphi. It is recursively axiomatised if it has a decidable set of axioms (after coding sentences by numbers, below). Then the set of theorems of TT is computably enumerable: list all finite sequences of formulas and keep those that are proofs.

Definition— Gödel numbering

Fix an injective coding of the symbols by positive integers, c(⋅)c(\cdot), and code a string s1s2⋯sks_1 s_2 \cdots s_k by ⌜s1⋯sk⌝=2c(s1)3c(s2)⋯pkc(sk)\ulcorner s_1 \cdots s_k \urcorner = 2^{c(s_1)} 3^{c(s_2)} \cdots p_k^{c(s_k)}, where pkp_k is the kk-th prime. A proof — a finite sequence of formulas — is coded by coding the sequence of the codes of its formulas the same way. The coding is injective and computable in both directions.

Definition— Δ₀ and Σ₁ formulas

A formula is Δ0\Delta_0 if all its quantifiers are bounded, ∀x≤t\forall x \le t or ∃x≤t\exists x \le t; it is Σ1\Sigma_1 if it has the form ∃xˉ θ\exists \bar x\, \theta with θ\theta in Δ0\Delta_0, and Π1\Pi_1 if it has the form ∀xˉ θ\forall \bar x\, \theta. The truth of a Δ0\Delta_0 sentence in N\N can be decided by a finite search.

Definition— representability

A relation R⊆NkR \subseteq \N^k is represented in TT by a formula φ(xˉ)\varphi(\bar x) if for all nˉ\bar n: when R(nˉ)R(\bar n) holds, T⊢φ(n1‾,…,nk‾)T \vdash \varphi(\overline{n_1}, \dots, \overline{n_k}), and when it fails, T⊢¬φ(n1‾,…,nk‾)T \vdash \neg\varphi(\overline{n_1}, \dots, \overline{n_k}). A function f:Nk→Nf : \N^k \to \N is represented by φ(xˉ,y)\varphi(\bar x, y) if for all nˉ\bar n: T⊢∀y (φ(n‾ˉ,y)↔y=f(nˉ)‾)T \vdash \forall y\, \big(\varphi(\bar{\overline{n}}, y) \leftrightarrow y = \overline{f(\bar n)}\big).

Three facts carry the technical weight. Their proofs are long but elementary; full treatments are in Smith (2013, chapters 11–20) and Boolos, Burgess and Jeffrey (2007, chapters 15–17).

Theorem— Fact A (Σ₁-completeness of Q)

Every Σ1\Sigma_1 sentence that is true in N\N is provable in Q\mathsf{Q}. Moreover, for each nn, Q⊢∀x (x≤n‾→x=0‾∨⋯∨x=n‾)\mathsf{Q} \vdash \forall x\,\big(x \le \overline{n} \to x = \overline{0} \vee \cdots \vee x = \overline{n}\big) and Q⊢∀x (x≤n‾∨n‾≤x)\mathsf{Q} \vdash \forall x\,(x \le \overline{n} \vee \overline{n} \le x).

Theorem— Fact B (representability)

Every decidable relation and every computable total function on N\N is representable in Q\mathsf{Q}, hence in every consistent theory extending Q\mathsf{Q}.

Theorem— Fact C (arithmetisation of proof)

If TT is recursively axiomatised, the relation "mm is the code of a TT-proof of the formula with code nn" is decidable (indeed primitive recursive, after replacing the axioms by an equivalent primitive recursive set — Craig's trick). Hence it is represented in Q\mathsf{Q} by a formula PrfT(x,y)\mathrm{Prf}_T(x, y) that also defines it in N\N and can be chosen to be Σ1\Sigma_1. Then ProvT(y):=∃x PrfT(x,y)\mathrm{Prov}_T(y) := \exists x\, \mathrm{Prf}_T(x, y) is a Σ1\Sigma_1 formula, true in N\N of exactly the codes of theorems of TT.

Worked examplesH

Examples and non-examples

Example— Theories the theorems apply to

Q\mathsf{Q}, PA\mathsf{PA}, second-order arithmetic, and ZFC\mathsf{ZFC} (which interprets PA\mathsf{PA} by taking the finite von Neumann ordinals as numbers) are all recursively axiomatised and — we believe — consistent. Each is therefore incomplete, and none proves its own consistency. Adding the Gödel sentence as a new axiom does not help: T+GTT + G_T is again recursively axiomatised and consistent, and has its own Gödel sentence.

Example— Complete theories: not enough arithmetic

  • Presburger arithmetic, the theory of (N,0,1,+)(\N, 0, 1, +), is complete and decidable (Presburger, 1929, by quantifier elimination). Multiplication is not definable in it — the formal section cites Mathlib's proof of this.
  • The theory of real closed fields — the first-order theory of (R,0,1,+,×,<)(\R, 0, 1, +, \times, <) — is complete and decidable (Tarski, published 1948 and 1951). The integers are not definable in R\R by a first-order formula, so arithmetic cannot be interpreted.
  • True arithmetic Th(N)\mathrm{Th}(\N), the set of all sentences true in N\N, is complete and consistent — but by the first incompleteness theorem it is not recursively axiomatisable (indeed, by Tarski's theorem it is not even arithmetically definable).

Example— A Gödel number

With symbol codes c(0)=1c(0) = 1, c(S)=3c(S) = 3 and c(=)=5c(=) = 5, the string "S0S0" has code 23⋅31=242^3 \cdot 3^1 = 24, and "0=00 = 0" has code 21⋅35⋅51=24302^1 \cdot 3^5 \cdot 5^1 = 2430. Any injective computable coding would serve; the experiment below uses a bijective base-kk coding instead.

ProofH

The diagonal lemma and the first theorem

Throughout, TT is a recursively axiomatised theory extending Q\mathsf{Q}.

Theorem— Diagonal lemma (Gödel 1931; Carnap 1934)

For every formula φ(y)\varphi(y) with one free variable there is a sentence GG such that

Q⊢G↔φ(⌜G⌝),\mathsf{Q} \vdash G \leftrightarrow \varphi(\ulcorner G \urcorner),

where ⌜G⌝\ulcorner G \urcorner abbreviates the numeral of the code of GG.

Proof

Let diag:N→N\mathrm{diag} : \N \to \N send the code of a formula θ(x)\theta(x) to the code of the sentence θ(⌜θ⌝‾)\theta(\overline{\ulcorner \theta \urcorner}), and every other number to 00. It is computable, so by Fact B some formula D(x,y)D(x, y) represents it in Q\mathsf{Q}:

Q⊢∀y (D(n‾,y)↔y=diag(n)‾)for every n.\mathsf{Q} \vdash \forall y\,\big(D(\overline{n}, y) \leftrightarrow y = \overline{\mathrm{diag}(n)}\big) \quad\text{for every } n.

Put ψ(x):=∃y (D(x,y)∧φ(y))\psi(x) := \exists y\,\big(D(x, y) \wedge \varphi(y)\big), let n=⌜ψ⌝n = \ulcorner \psi \urcorner and let G:=ψ(n‾)G := \psi(\overline{n}). By definition diag(n)=⌜G⌝\mathrm{diag}(n) = \ulcorner G \urcorner. Reasoning in Q\mathsf{Q},

G  ↔  ∃y (D(n‾,y)∧φ(y))  ↔  ∃y (y=⌜G⌝∧φ(y))  ↔  φ(⌜G⌝).■G \;\leftrightarrow\; \exists y\,\big(D(\overline{n}, y) \wedge \varphi(y)\big) \;\leftrightarrow\; \exists y\,\big(y = \ulcorner G \urcorner \wedge \varphi(y)\big) \;\leftrightarrow\; \varphi(\ulcorner G \urcorner). \qquad\blacksquare

∎

Applying the lemma to ¬ProvT(y)\neg\mathrm{Prov}_T(y) gives a Gödel sentence GTG_T with Q⊢GT↔¬ProvT(⌜GT⌝)\mathsf{Q} \vdash G_T \leftrightarrow \neg\mathrm{Prov}_T(\ulcorner G_T \urcorner).

Theorem— First incompleteness theorem, Gödel's form

(a) If TT is consistent, then T⊬GTT \nvdash G_T. (b) If moreover TT is Σ1\Sigma_1-sound (every Σ1\Sigma_1 sentence it proves is true in N\N), then T⊬¬GTT \nvdash \neg G_T. Consequently GTG_T is true in N\N but not provable in TT.

Proof

(a) Suppose mm codes a TT-proof of GTG_T. By Fact C, Q⊢PrfT(m‾,⌜GT⌝)\mathsf{Q} \vdash \mathrm{Prf}_T(\overline{m}, \ulcorner G_T \urcorner), so T⊢ProvT(⌜GT⌝)T \vdash \mathrm{Prov}_T(\ulcorner G_T \urcorner), and by the diagonal equivalence T⊢¬GTT \vdash \neg G_T. Then TT is inconsistent.

(b) If T⊢¬GTT \vdash \neg G_T, then T⊢ProvT(⌜GT⌝)T \vdash \mathrm{Prov}_T(\ulcorner G_T \urcorner), a Σ1\Sigma_1 sentence; by Σ1\Sigma_1-soundness it is true, so T⊢GTT \vdash G_T, and TT is inconsistent, contradicting (a).

Finally, Q\mathsf{Q} is true in N\N, so the diagonal equivalence holds in N\N; since T⊬GTT \nvdash G_T, the sentence ¬ProvT(⌜GT⌝)\neg\mathrm{Prov}_T(\ulcorner G_T \urcorner) is true in N\N, hence so is GTG_T.

∎

Gödel's original hypothesis for (b) was ω\omega-consistency, which implies Σ1\Sigma_1-soundness. J. Barkley Rosser (1936) removed it with a cleverer sentence: "if I am provable, there is a shorter proof of my negation".

Theorem— First incompleteness theorem, Rosser's form

If TT is a consistent, recursively axiomatised theory extending Q\mathsf{Q}, then TT is incomplete: there is a sentence RR with T⊬RT \nvdash R and T⊬¬RT \nvdash \neg R.

Proof

Let neg\mathrm{neg} be the computable function ⌜χ⌝↦⌜¬χ⌝\ulcorner \chi \urcorner \mapsto \ulcorner \neg\chi \urcorner, and write PrfT(z,neg(y))\mathrm{Prf}_T(z, \mathrm{neg}(y)) for the formula expressing this via a representing formula (Fact B). By the diagonal lemma there is a sentence RR with

T⊢R↔∀x (PrfT(x,⌜R⌝)→∃z≤x  PrfT(z,⌜¬R⌝)).T \vdash R \leftrightarrow \forall x\,\Big(\mathrm{Prf}_T(x, \ulcorner R \urcorner) \to \exists z \le x\; \mathrm{Prf}_T(z, \ulcorner \neg R \urcorner)\Big).

T⊬RT \nvdash R. Suppose mm codes a proof of RR. As TT is consistent, no number codes a proof of ¬R\neg R, so by Fact C, T⊢¬PrfT(k‾,⌜¬R⌝)T \vdash \neg\mathrm{Prf}_T(\overline{k}, \ulcorner \neg R \urcorner) for each k≤mk \le m. By Fact A, every z≤m‾z \le \overline{m} is one of 0‾,…,m‾\overline{0}, \dots, \overline{m}, so T⊢¬∃z≤m‾ PrfT(z,⌜¬R⌝)T \vdash \neg\exists z \le \overline{m}\, \mathrm{Prf}_T(z, \ulcorner \neg R \urcorner). Together with T⊢PrfT(m‾,⌜R⌝)T \vdash \mathrm{Prf}_T(\overline{m}, \ulcorner R \urcorner) (take x=m‾x = \overline{m}) this gives T⊢¬RT \vdash \neg R, contradicting consistency.

T⊬¬RT \nvdash \neg R. Suppose mm codes a proof of ¬R\neg R, so T⊢PrfT(m‾,⌜¬R⌝)T \vdash \mathrm{Prf}_T(\overline{m}, \ulcorner \neg R \urcorner). As TT is consistent, T⊬RT \nvdash R, so T⊢¬PrfT(k‾,⌜R⌝)T \vdash \neg\mathrm{Prf}_T(\overline{k}, \ulcorner R \urcorner) for each k≤mk \le m. Now argue inside TT: let xx satisfy PrfT(x,⌜R⌝)\mathrm{Prf}_T(x, \ulcorner R \urcorner). By Fact A, x≤m‾x \le \overline{m} or m‾≤x\overline{m} \le x. The first case is impossible, since then xx is one of 0‾,…,m‾\overline{0}, \dots, \overline{m}; so m‾≤x\overline{m} \le x, and z=m‾z = \overline{m} witnesses ∃z≤x  PrfT(z,⌜¬R⌝)\exists z \le x\; \mathrm{Prf}_T(z, \ulcorner \neg R \urcorner). Hence T⊢RT \vdash R, again contradicting consistency.

With more care in the choice of PrfT\mathrm{Prf}_T, the Rosser sentence can be taken to be (equivalent to) a Π1\Pi_1 sentence, like the Gödel sentence.

∎

ProofH

The second theorem, and Tarski

Let ConT\mathrm{Con}_T be the sentence ¬ProvT(⌜0=S0⌝)\neg\mathrm{Prov}_T(\ulcorner 0 = S0 \urcorner), with ProvT\mathrm{Prov}_T the standard Σ1\Sigma_1 provability formula of Fact C. When TT extends PA\mathsf{PA}, it satisfies the Hilbert–Bernays–Löb derivability conditions: for all sentences φ,ψ\varphi, \psi,

  • D1 if T⊢φT \vdash \varphi then T⊢ProvT(⌜φ⌝)T \vdash \mathrm{Prov}_T(\ulcorner \varphi \urcorner);
  • D2 T⊢ProvT(⌜φ→ψ⌝)→(ProvT(⌜φ⌝)→ProvT(⌜ψ⌝))T \vdash \mathrm{Prov}_T(\ulcorner \varphi \to \psi \urcorner) \to \big(\mathrm{Prov}_T(\ulcorner \varphi \urcorner) \to \mathrm{Prov}_T(\ulcorner \psi \urcorner)\big);
  • D3 T⊢ProvT(⌜φ⌝)→ProvT(⌜ProvT(⌜φ⌝)⌝)T \vdash \mathrm{Prov}_T(\ulcorner \varphi \urcorner) \to \mathrm{Prov}_T(\ulcorner \mathrm{Prov}_T(\ulcorner \varphi \urcorner) \urcorner).

D1 is Fact A applied to a true Σ1\Sigma_1 sentence; D2 formalises modus ponens; D3, the hard one, is the formalisation inside PA\mathsf{PA} of Fact A itself (it needs induction; see Boolos 1993, chapter 2).

Theorem— Second incompleteness theorem (Gödel 1931; Hilbert–Bernays 1939)

If TT is consistent, recursively axiomatised and extends PA\mathsf{PA}, then T⊬ConTT \nvdash \mathrm{Con}_T.

Proof

Write □φ\square\varphi for ProvT(⌜φ⌝)\mathrm{Prov}_T(\ulcorner \varphi \urcorner), ⊥\bot for 0=S00 = S0 and GG for GTG_T, so T⊢G↔¬□GT \vdash G \leftrightarrow \neg\square G.

  1. From T⊢□G→¬GT \vdash \square G \to \neg G, by D1 and D2: T⊢□□G→□¬GT \vdash \square\square G \to \square\neg G.
  2. By D3: T⊢□G→□□GT \vdash \square G \to \square\square G; so T⊢□G→□¬GT \vdash \square G \to \square\neg G.
  3. Since T⊢G→(¬G→⊥)T \vdash G \to (\neg G \to \bot), D1 and D2 (twice) give T⊢□G→(□¬G→□⊥)T \vdash \square G \to (\square\neg G \to \square\bot).
  4. From 2 and 3: T⊢□G→□⊥T \vdash \square G \to \square\bot; contrapositively T⊢¬□⊥→¬□GT \vdash \neg\square\bot \to \neg\square G, that is, T⊢ConT→GT \vdash \mathrm{Con}_T \to G.

If T⊢ConTT \vdash \mathrm{Con}_T, then T⊢GT \vdash G, contradicting part (a) of the first theorem.

∎

The proof shows more: T⊢ConT→GTT \vdash \mathrm{Con}_T \to G_T, and in fact T⊢ConT↔GTT \vdash \mathrm{Con}_T \leftrightarrow G_T. Löb (1955) refined the argument to: if T⊢□φ→φT \vdash \square\varphi \to \varphi then T⊢φT \vdash \varphi — the second theorem is the case φ=⊥\varphi = \bot.

Theorem— Tarski's undefinability theorem (1933)

There is no formula True(y)\mathrm{True}(y) of LAL_A such that, for every sentence φ\varphi, N⊨φ↔True(⌜φ⌝)\N \models \varphi \leftrightarrow \mathrm{True}(\ulcorner \varphi \urcorner). The set of codes of true arithmetical sentences is not arithmetically definable.

Proof

Apply the diagonal lemma to ¬True(y)\neg\mathrm{True}(y): some sentence LL satisfies Q⊢L↔¬True(⌜L⌝)\mathsf{Q} \vdash L \leftrightarrow \neg\mathrm{True}(\ulcorner L \urcorner), so this holds in N\N. If True\mathrm{True} defined truth, we would have N⊨L↔¬L\N \models L \leftrightarrow \neg L.

∎

Since ProvT\mathrm{Prov}_T is definable, Tarski's theorem gives another proof that for a sound TT, provability and truth differ — without exhibiting the witness.

ProofH

Incompleteness from the halting problem

A computability-theoretic route, due essentially to Turing (1936) and Kleene, makes incompleteness look inevitable. Recall from computability that the halting set K={(c,n):program c halts on input n}K = \{(c, n) : \text{program } c \text{ halts on input } n\} is computably enumerable but not decidable, so its complement is not computably enumerable.

Theorem— Theorem (Turing–Kleene incompleteness)

Let T⊇QT \supseteq \mathsf{Q} be recursively axiomatised and sound (every theorem is true in N\N). For each program cc and input nn let Hc,nH_{c,n} be the natural Σ1\Sigma_1 sentence "the computation of cc on nn halts". Then there are c,nc, n such that ¬Hc,n\neg H_{c,n} is true but T⊬¬Hc,nT \nvdash \neg H_{c,n}.

Proof

The set {(c,n):T⊢¬Hc,n}\{(c, n) : T \vdash \neg H_{c,n}\} is computably enumerable (list the theorems of TT). By soundness it is contained in the complement of KK. If it contained every pair outside KK it would equal the complement of KK, which would then be computably enumerable — so KK would be decidable, which it is not.

∎

This version needs soundness. Using a pair of computably inseparable c.e. sets instead of KK recovers Rosser's version, which needs only consistency. The theorem also says something Gödel's construction hides: the unprovable sentences include very concrete ones — "this particular program never halts". By the MRDP theorem (see the viewpoints) they include "this particular polynomial equation has no solution in natural numbers".

Formal mathematicsF

The diagonal argument in Lean

Mathlib does not contain Gödel's theorems for PA\mathsf{PA}: Facts A–C are long and not yet formalised there. The Lean module therefore proves the logical skeleton of the theorems in full, with the arithmetical facts as explicit hypotheses, and proves one genuine incompleteness theorem about programs from Mathlib's computability library.

First, Lawvere's fixed-point theorem and Cantor's theorem as its corollary:

lawvere_fixed_pointLean 4Proved here from basic factsFormally verified
/-- **Lawvere's fixed-point theorem** (1969), the abstract core of the diagonal arguments of
Cantor, Russell, Gödel, Tarski and Turing. If `e : A → (A → B)` hits *every* function
`A → B`, then every map `f : B → B` has a fixed point.
Proof: the diagonal function `g a = f (e a a)` is `e a₀` for some `a₀`, and then
`e a₀ a₀ = g a₀ = f (e a₀ a₀)`. -/
theorem lawvere_fixed_point {A B : Type*} (e : A → A → B) (he : Function.Surjective e)
    (f : B → B) : ∃ b, f b = b := by
  obtain ⟨a₀, ha₀⟩ := he (fun a => f (e a a))
  -- Evaluate the equation `e a₀ = g` at the diagonal point `a₀`.
  exact ⟨e a₀ a₀, (congrFun ha₀ a₀).symm⟩
Axioms used: No axiomsformal/Lumenary/Incompleteness.leanTry it in the Lean web editor
cantor_from_lawvereLean 4Proved here from basic factsFormally verified
/-- Cantor's theorem as a corollary: there is no surjection from `A` onto the predicates
`A → Prop`, because negation `¬ : Prop → Prop` has no fixed point (`P ↔ ¬P` is absurd).
Mathlib's version for sets is `Function.cantor_surjective`. -/
theorem cantor_from_lawvere {A : Type*} (e : A → A → Prop) : ¬ Function.Surjective e := by
  intro he
  obtain ⟨P, hP⟩ := lawvere_fixed_point e he Not
  exact iff_not_self (Iff.of_eq hP.symm)
Axioms used: No axiomsformal/Lumenary/Incompleteness.leanTry it in the Lean web editor

Next, an abstract diagonalisable system in the sense of Smullyan (1992): formulas, sentences, Gödel numbers, substitution of numerals, negation, truth and provability. A set of numbers is expressible if some formula defines it.

DiagSystemLean 4Formally verified
/-- An abstract **diagonalisable system**, after R. M. Smullyan, *Gödel's Incompleteness
Theorems* (1992), chapter 1. It has formulas with one free variable, sentences, Gödel numbers
for both, the substitution `subst φ n = φ(n̄)` of a numeral, a negation, and two predicates on
sentences: truth (in the intended model) and provability (in the theory). The number
`diag (code ψ)` is the Gödel number of the *diagonalisation* `ψ(⌜ψ⌝)`. For first-order
arithmetic all of this is real: Gödel numbers are natural numbers and `diag` is primitive
recursive. -/
structure DiagSystem where
  /-- Formulas with one free variable. -/
  Formula : Type
  /-- Sentences (no free variables). -/
  Sentence : Type
  /-- The Gödel number `⌜ψ⌝` of a formula. -/
  code : Formula → ℕ
  /-- The Gödel number of a sentence. -/
  scode : Sentence → ℕ
  /-- Different sentences have different Gödel numbers. -/
  scode_injective : Function.Injective scode
  /-- `subst ψ n` is the sentence `ψ(n̄)`. -/
  subst : Formula → ℕ → Sentence
  /-- Negation of sentences. -/
  neg : Sentence → Sentence
  /-- Truth in the intended model. -/
  True : Sentence → Prop
  /-- Provability in the theory. -/
  Provable : Sentence → Prop
  true_neg : ∀ s, True (neg s) ↔ ¬ True s
  /-- The diagonal function on Gödel numbers. -/
  diag : ℕ → ℕ
  diag_code : ∀ ψ, diag (code ψ) = scode (subst ψ (code ψ))
Axioms used: No axiomsformal/Lumenary/Incompleteness.leanTry it in the Lean web editor
ExpressibleLean 4Formally verified
/-- A set `A` of natural numbers is **expressible** if some formula `ψ` defines it:
`ψ(n̄)` is true exactly when `n ∈ A`. -/
def Expressible (A : Set ℕ) : Prop :=
  ∃ ψ : S.Formula, ∀ n, S.True (S.subst ψ n) ↔ n ∈ A
Axioms used: No axiomsformal/Lumenary/Incompleteness.leanTry it in the Lean web editor

The diagonal lemma is proved exactly as on paper, by a three-step calc chain. Its hypothesis hdiag — expressible sets are closed under taking preimages along diag — is the abstract counterpart of "the diagonal function is representable" (Fact B):

diagonal_lemmaLean 4Proved here from basic factsFormally verified
/-- **The diagonal lemma (semantic form).** Suppose that whenever `A` is expressible, so is
`diag⁻¹(A) = {n | diag n ∈ A}` (in arithmetic: substitution is definable). Then for every
expressible `A` there is a sentence `G` that is true iff its own Gödel number lies in `A`.
Proof: let `ψ` express `diag⁻¹(A)` and put `G = ψ(⌜ψ⌝)`. Then
`G` true ⟺ `⌜ψ⌝ ∈ diag⁻¹(A)` ⟺ `diag ⌜ψ⌝ ∈ A` ⟺ `⌜G⌝ ∈ A`. -/
theorem diagonal_lemma
    (hdiag : ∀ A : Set ℕ, S.Expressible A → S.Expressible (S.diag ⁻¹' A))
    {A : Set ℕ} (hA : S.Expressible A) : ∃ G : S.Sentence, S.True G ↔ S.scode G ∈ A := by
  obtain ⟨ψ, hψ⟩ := hdiag A hA
  refine ⟨S.subst ψ (S.code ψ), ?_⟩
  calc S.True (S.subst ψ (S.code ψ)) ↔ S.code ψ ∈ S.diag ⁻¹' A := hψ (S.code ψ)
    _ ↔ S.diag (S.code ψ) ∈ A := Iff.rfl
    _ ↔ S.scode (S.subst ψ (S.code ψ)) ∈ A := by rw [S.diag_code ψ]
Axioms used: No axiomsformal/Lumenary/Incompleteness.leanTry it in the Lean web editor

From it, Tarski's theorem and the semantic first incompleteness theorem. Here hprov ("the provable codes form an expressible set") stands for Fact C, and sound for soundness. In the arithmetical setting all four hypotheses are theorems; here they are assumptions, and the formal content is that the conclusions follow from them by the diagonal argument and nothing else.

tarski_undefinabilityLean 4Proved here from basic factsFormally verified
/-- **Tarski's undefinability of truth (abstract form).** If expressible sets are closed under
complements (negation is definable) and under `diag⁻¹` (substitution is definable), then the set
of Gödel numbers of *true* sentences is not expressible.
Proof: otherwise its complement is expressible, and the diagonal lemma gives a sentence `G`
that is true iff `⌜G⌝` is not the number of a true sentence, i.e. iff `G` is false. -/
theorem tarski_undefinability
    (hcompl : ∀ A : Set ℕ, S.Expressible A → S.Expressible Aᶜ)
    (hdiag : ∀ A : Set ℕ, S.Expressible A → S.Expressible (S.diag ⁻¹' A)) :
    ¬ S.Expressible (S.scode '' {s | S.True s}) := by
  intro hT
  obtain ⟨G, hG⟩ := S.diagonal_lemma hdiag (hcompl _ hT)
  -- `⌜G⌝` is the code of a true sentence iff `G` is true, by injectivity of the coding.
  have hcode : S.scode G ∈ S.scode '' {s | S.True s} ↔ S.True G :=
    S.scode_injective.mem_set_image
  have : S.True G ↔ ¬ S.True G := hG.trans (not_congr hcode)
  exact iff_not_self this
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Incompleteness.leanTry it in the Lean web editor
first_incompletenessLean 4Proved here from basic factsFormally verified
/-- **The first incompleteness theorem (abstract, semantic form).** Suppose the theory is
*sound* (it proves only true sentences), that the set of Gödel numbers of provable sentences is
expressible (Gödel's arithmetisation), and that expressible sets are closed under complements
and `diag⁻¹`. Then there is a sentence `G` that is true but unprovable, and whose negation is
unprovable too: the theory is incomplete.
Proof: the diagonal lemma applied to the non-provable codes gives `G` with
"`G` true ⟺ `G` unprovable". If `G` were provable it would be true, hence unprovable; so `G`
is unprovable, hence true. If `¬G` were provable it would be true, so `G` would be false. -/
theorem first_incompleteness
    (sound : ∀ s, S.Provable s → S.True s)
    (hprov : S.Expressible (S.scode '' {s | S.Provable s}))
    (hcompl : ∀ A : Set ℕ, S.Expressible A → S.Expressible Aᶜ)
    (hdiag : ∀ A : Set ℕ, S.Expressible A → S.Expressible (S.diag ⁻¹' A)) :
    ∃ G : S.Sentence, S.True G ∧ ¬ S.Provable G ∧ ¬ S.Provable (S.neg G) := by
  obtain ⟨G, hG⟩ := S.diagonal_lemma hdiag (hcompl _ hprov)
  have hcode : S.scode G ∈ S.scode '' {s | S.Provable s} ↔ S.Provable G :=
    S.scode_injective.mem_set_image
  -- The fixed-point property: `G` is true iff `G` is not provable.
  have hfix : S.True G ↔ ¬ S.Provable G := hG.trans (not_congr hcode)
  have hunprov : ¬ S.Provable G := fun hp => hfix.mp (sound G hp) hp
  have htrue : S.True G := hfix.mpr hunprov
  refine ⟨G, htrue, hunprov, fun hneg => ?_⟩
  exact (S.true_neg G).mp (sound _ hneg) htrue
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Incompleteness.leanTry it in the Lean web editor

The computability route needs no hypotheses about arithmetic at all. Mathlib codes programs as Nat.Partrec.Code and proves the halting problem undecidable and its complement not semi-decidable. The theorem halting_incompleteness is the Turing–Kleene theorem above: any computably enumerable set of sentences that is sound for non-halting statements misses some true one.

halting_undecidableLean 4Applies a library theoremFormally verified
/-- **Turing (1936):** the halting problem is undecidable — no computable procedure decides,
for every program `c`, whether `c` halts on input `n`. Here programs are Mathlib's codes
`Nat.Partrec.Code` for partial recursive functions; this applies
`ComputablePred.halting_problem`. -/
theorem halting_undecidable (n : ℕ) :
    ¬ ComputablePred fun c : Nat.Partrec.Code => (c.eval n).Dom :=
  ComputablePred.halting_problem n
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Incompleteness.leanTry it in the Lean web editor
halting_incompletenessLean 4Proved here from basic factsFormally verified
/-- **Incompleteness from the halting problem** (after Turing 1936 and Kleene). Let `Provable`
be any set of (Gödel numbers of) sentences whose members can be computably listed — as the
theorems of every recursively axiomatised theory can — and let `nonHalt c` be a computable
assignment, to each program `c`, of a sentence meaning "`c` does not halt on input `n`". If the
theory is sound for these sentences, then some program never halts but the theory cannot prove
it. Proof: otherwise "`c` does not halt" would be semi-decidable — list the theorems and wait
for `nonHalt c` — and Mathlib's `ComputablePred.halting_problem_not_re` says it is not. -/
theorem halting_incompleteness (n : ℕ) (Provable : ℕ → Prop) (hre : REPred Provable)
    (nonHalt : Nat.Partrec.Code → ℕ) (hc : Computable nonHalt)
    (sound : ∀ c, Provable (nonHalt c) → ¬ (c.eval n).Dom) :
    ∃ c : Nat.Partrec.Code, ¬ (c.eval n).Dom ∧ ¬ Provable (nonHalt c) := by
  by_contra h
  push Not at h
  -- `h : ∀ c, ¬ (c.eval n).Dom → Provable (nonHalt c)`: the theory would be complete for
  -- non-halting, so non-halting would be semi-decidable.
  have hcomp : REPred fun c => Provable (nonHalt c) := hre.comp hc
  exact ComputablePred.halting_problem_not_re n (hcomp.of_eq fun c => ⟨sound c, h c⟩)
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Incompleteness.leanTry it in the Lean web editor

Finally two library facts: formulas over a countable language can be numbered (the first step of arithmetisation), and multiplication is not definable in Presburger arithmetic — which is why Presburger arithmetic can be complete.

formulas_countableLean 4Applies a library theoremFormally verified
/-- The first step of arithmetisation: over a countable language, the first-order formulas
(with variables indexed by `ℕ`) form a countable set, so they can be numbered. This is the
instance `FirstOrder.Language.Formula`'s `Countable` from `Mathlib.ModelTheory.Encoding`. -/
theorem formulas_countable (L : FirstOrder.Language) [Countable L.Symbols] :
    Countable (L.Formula ℕ) :=
  inferInstance
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Incompleteness.leanTry it in the Lean web editor
presburger_mul_not_definableLean 4Applies a library theoremFormally verified
/-- Incompleteness needs multiplication. In the language `(0, 1, +)` of Presburger arithmetic
the graph of multiplication `{(a, b, c) | a = b * c}` is **not definable** in `ℕ`, even with
any set `A` of parameters — and Presburger arithmetic is complete and decidable. This applies
Mathlib's `FirstOrder.Language.presburger.mul_not_definable` (the definable sets are exactly the
semilinear ones). -/
theorem presburger_mul_not_definable (A : Set ℕ) :
    ¬ A.Definable FirstOrder.Language.presburger {v : Fin 3 → ℕ | v 0 = v 1 * v 2} :=
  FirstOrder.Language.presburger.mul_not_definable
Axioms used: propext, Classical.choice, Quot.soundformal/Lumenary/Incompleteness.leanTry it in the Lean web editor

What is not formalised here: the representability theorem (Fact B), the arithmetisation of Q\mathsf{Q}-provability (Fact C), Rosser's theorem for consistent theories, and the second incompleteness theorem with its derivability conditions. Complete formalisations of the incompleteness theorems exist outside Mathlib — for example Shankar's in the Boyer–Moore prover (1986), O'Connor's in Coq (2005) and Paulson's in Isabelle/HOL (2015, including the second theorem), and there are Lean 4 developments outside Mathlib.

ComputationC

Computing a self-referential sentence

The first experiment Gödel-numbers strings, computes the function diag\mathrm{diag} and checks the fixed-point identity diag(⌜φ⌝)=⌜G⌝\mathrm{diag}(\ulcorner\varphi\urcorner) = \ulcorner G \urcorner for G=φ(⌜φ⌝)G = \varphi(\ulcorner\varphi\urcorner). With φ(x)=\varphi(x) = "P(diag(x))P(\mathrm{diag}(x))" for a decidable property PP of codes, it evaluates GG and confirms G↔P(⌜G⌝)G \leftrightarrow P(\ulcorner G \urcorner). With PP = "is true", the liar sentence has no consistent truth value. Notice that GG does not contain its own code (the code is far longer than GG): it contains a term that evaluates to its code.

The diagonal lemma, computed with Goedel numbersPythonExact computationComputationally tested
"""The diagonal lemma, computed: sentences that talk about their own codes.

Formulas are strings over a small alphabet, and a bijective base-k numbering
turns every string into a natural number (its Goedel number) and back. The
function diag sends the code n of a formula phi(x) to the code of phi(n), the
result of substituting phi's own code, written as a numeral, for x.

For a template phi(x) = "P(diag(x))" the sentence G = phi(code of phi) says
"P holds of the sentence numbered diag(code of phi)" - and that sentence is G
itself. We check this identity exactly, and evaluate G when P is a decidable
property of codes: G then has a definite truth value, and G <-> P(code of G).
When P is a truth predicate, evaluating G requires evaluating G: for the liar
"~True(diag(x))" no truth value is consistent, which is the heart of Tarski's
theorem.

Numerals are written in decimal as an abbreviation of S...S0. Nothing here
decides provability, so this exhibits the mechanism of self-reference, not
the incompleteness theorem itself.

Runs unchanged in the browser (Pyodide) using only the standard library.
"""

import textwrap

#: The alphabet (all symbols distinct). Each formula is a string over it.
ALPHABET = "0123456789()~&|>=+*SAPdiagxyEvenLoTru"
BASE = len(ALPHABET)

def encode(text):
    """Bijective base-k Goedel number of a string (the empty string is 0)."""
    code = 0
    for ch in text:
        index = ALPHABET.find(ch)
        if index < 0:
            raise ValueError(f"symbol {ch!r} is not in the alphabet")
        code = code * BASE + index + 1
    return code

def decode(code):
    """Inverse of encode: the string whose Goedel number is ``code``."""
    if code < 0:
        raise ValueError("codes are natural numbers")
    chars = []
    while code > 0:
        code, digit = divmod(code - 1, BASE)
        chars.append(ALPHABET[digit])
    return "".join(reversed(chars))

def substitute(formula, n):
    """Replace the free variable x by the numeral of n (x is never bound here)."""
    return formula.replace("x", str(n))

def diag(code):
    """Code of the diagonalisation phi(code of phi) of the formula with this code."""
    return encode(substitute(decode(code), code))

def fixed_point(template):
    """The sentence G = phi(code of phi) for a template phi(x)."""
    return substitute(template, encode(template))

#: Decidable properties of codes that sentences may mention.
PREDICATES = {
    "Even": lambda code: code % 2 == 0,
    "Long": lambda code: len(decode(code)) > 30,
}

def parse(sentence):
    """Split "P(diag(N))" or "~P(diag(N))" into (negated, P, diag(N))."""
    negated = sentence.startswith("~")
    body = sentence[1:] if negated else sentence
    name, _, rest = body.partition("(")
    if not (rest.startswith("diag(") and rest.endswith("))")):
        raise ValueError(f"not of the form P(diag(N)): {sentence!r}")
    return negated, name, diag(int(rest[len("diag("):-2]))

def evaluate(sentence):
    """Truth value of a sentence about a decidable property of a code."""
    negated, name, target = parse(sentence)
    value = PREDICATES[name](target)
    return (not value) if negated else value

def self_reference_values(sentence):
    """Truth values v consistent with a sentence "[~]True(diag(N))" about itself.

    If the sentence is about its own code, its value v must satisfy v = v
    (unnegated: both values fit) or v = not v (negated: none fits).
    """
    negated, name, target = parse(sentence)
    if name != "True" or target != encode(sentence):
        raise ValueError("expected a truth predicate applied to the sentence itself")
    return [v for v in (True, False) if v == ((not v) if negated else v)]

def main():
    phi = "~P(diag(x))"
    g = fixed_point(phi)
    n = encode(phi)
    print("1. Goedel's sentence, reading P(m) as 'sentence m is provable'")
    print(f"   phi(x) = {phi}; its code n has {len(str(n))} digits")
    print(f"   G = phi(n) = ~P(diag({str(n)[:10]}...)), {len(g)} symbols")
    print(f"   diag(n) == code of G: {diag(n) == encode(g)}")
    print(f"   code of G has {len(str(encode(g)))} digits, so G does not "
          f"contain it: {str(encode(g)) not in g}")
    print()
    print("2. Fixed points of decidable properties (Long = over 30 symbols)")
    for template in ["Even(diag(x))", "~Even(diag(x))", "Long(diag(x))",
                     "~Long(diag(x))"]:
        s = fixed_point(template)
        negated, name, _ = parse(s)
        value, own = evaluate(s), PREDICATES[name](encode(s))
        holds = value == ((not own) if negated else own)
        print(f"   {template:<15} G: {str(value):<5}  {name}(code G): "
              f"{str(own):<5}  equation holds: {holds}")
    print()
    print("3. A truth predicate inside the language")
    for template in ["True(diag(x))", "~True(diag(x))"]:
        values = self_reference_values(fixed_point(template))
        print(f"   {template:<15} consistent truth values for G: {values}")
    print()
    print(textwrap.fill(
        "Epistemic status: exact computation. Part 1 verifies the identity "
        "diag(code phi) = code G for one template; it holds for every template "
        "by construction, which is the diagonal lemma's proof in miniature. Part 2 "
        "checks G <-> P(code G) (or its negated form) for four fixed points. Part 3 "
        "shows only that the liar has no consistent value under this evaluation; "
        "that no arithmetical formula defines truth is Tarski's theorem, proved in "
        "the lesson. Nothing here computes provability.",
        width=78,
    ))

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

The second experiment makes the asymmetry between theorems and non-theorems tangible on a toy formal system, Hofstadter's MIU system. Its theorems can be listed mechanically, but no amount of listing shows that MU is not a theorem; an invariant (the number of I's is never divisible by 3) proves it. For a recursively axiomatised theory of arithmetic, the incompleteness theorems say that some truths of the second kind have no proof in the theory at all.

Listing the theorems of the MIU systemPythonExhaustive finite checkExact computationComputationally tested
"""Theorems can be listed; non-theorems need an argument: the MIU system.

Hofstadter's MIU system (Goedel, Escher, Bach, 1979) is a tiny formal system.
Its only axiom is MI and its rules, for strings x, y over {I, U}, are
    xI -> xIU,   Mx -> Mxx,   xIIIy -> xUy,   xUUy -> xy.
Like the theorems of any recursively axiomatised theory, its theorems can be
listed mechanically: apply every rule to every theorem found so far. Here we
list all theorems reachable through strings of at most 16 symbols.

Is MU a theorem? The search never finds it - but a search can only ever say
"not yet". The answer comes from an argument outside the system: the number
of I's is never divisible by 3 (it starts at 1, and the rules keep it, double
it, or subtract 3). We check this invariant on every theorem found, and check
the known characterisation "Mx is a theorem iff the number of I's in x is not
divisible by 3" on all strings of at most 7 symbols.

Runs unchanged in the browser (Pyodide) using only the standard library.
"""

from collections import Counter
from itertools import product
import textwrap

AXIOM = "MI"

def successors(s):
    """All strings obtained from s by one application of one rule."""
    out = set()
    if s.endswith("I"):
        out.add(s + "U")
    out.add("M" + s[1:] * 2)
    for i in range(1, len(s) - 2):
        if s[i:i + 3] == "III":
            out.add(s[:i] + "U" + s[i + 3:])
    for i in range(1, len(s) - 1):
        if s[i:i + 2] == "UU":
            out.add(s[:i] + s[i + 2:])
    return out

def theorems(max_len):
    """Theorems derivable with every intermediate string of length <= max_len."""
    seen = {AXIOM}
    frontier = [AXIOM]
    while frontier:
        new = []
        for s in frontier:
            for t in sorted(successors(s)):
                if len(t) <= max_len and t not in seen:
                    seen.add(t)
                    new.append(t)
        frontier = new
    return seen

def invariant(s):
    """Number of I's modulo 3; it is never 0 for a theorem."""
    return s.count("I") % 3

def characterisation_failures(found, max_len):
    """Strings Mx of length <= max_len where "#I not divisible by 3" and
    "found as a theorem" disagree."""
    bad = []
    for n in range(max_len):
        for tail in product("IU", repeat=n):
            s = "M" + "".join(tail)
            if (invariant(s) != 0) != (s in found):
                bad.append(s)
    return bad

def main():
    found = theorems(16)
    by_length = Counter(len(s) for s in found)
    print("Theorems of MIU reachable through strings of <= 16 symbols")
    print(f"   total found: {len(found)}")
    print("   by length:  " + " ".join(f"{k}:{by_length[k]}" for k in range(2, 12)))
    print("   shortest:   " + ", ".join(sorted(found, key=lambda s: (len(s), s))[:6]))
    print()
    counts = Counter(invariant(s) for s in found)
    print(f"Invariant (#I mod 3) over all theorems found: {dict(sorted(counts.items()))}")
    print(f"MU found: {'MU' in found}   (#I in MU mod 3 = {invariant('MU')})")
    bad = characterisation_failures(found, 7)
    print(f"Strings of <= 7 symbols where '#I mod 3 != 0' and 'theorem' disagree: "
          f"{len(bad)}")
    print()
    print(textwrap.fill(
        "Epistemic status: exhaustive within the stated bound. The search lists "
        "theorems (it is a semi-decision procedure), but its failure to find MU "
        "proves nothing; the invariant argument proves that MU is not a theorem. "
        "The agreement for strings of at most 7 symbols is a finite check of a "
        "characterisation that is proved in general by a separate argument.",
        width=78,
    ))

if __name__ == "__main__":
    main()
Runs entirely in your browser, in an isolated worker. Nothing is sent to a server.

Both are exact computations; neither computes provability in PA\mathsf{PA}, which is undecidable.

Explore

Explore: the diagonal

Gödel's construction is a diagonal argument. In the widget, every list of binary sequences you write is defeated by the flipped diagonal. Change an entry on the diagonal and watch the new sequence change at exactly that place.

The diagonal machine

Here is a list of infinite 0–1 sequences (we can only show the start). The gold sequence d flips the diagonal.

s1…
s2…
s3…
s4…
s5…
s6…
d101001????…

Point at (or tab to) a row to see where d differs from it. Click any digit to change the list.

Add d to the list and a new d appears that is different again. No list — however long — can contain every sequence.

Compare with the diagonal lemma: the "list" is the list of formulas θ0(x),θ1(x),…\theta_0(x), \theta_1(x), \dots in one free variable, the entry in row mm and column nn is the sentence θm(n‾)\theta_m(\overline{n}), and the diagonal is n↦θn(n‾)n \mapsto \theta_n(\overline{n}). Cantor flips the diagonal to escape the list; Gödel applies ¬Prov\neg\mathrm{Prov} to the diagonal and finds that the result lies on the list — at the row of ψ\psi — which produces the fixed point.

Exercises

Exercises

1. Gödel's incompleteness theorems

Warm-upHuman

To which of these theories does the first incompleteness theorem (Rosser's form) apply, assuming each is consistent? Choose all that apply.

Choose all that apply

2. Gödel's incompleteness theorems

Warm-upHuman

Code a string s1s2⋯sks_1 s_2 \cdots s_k by 2c(s1)3c(s2)5c(s3)⋯2^{c(s_1)} 3^{c(s_2)} 5^{c(s_3)} \cdots, with symbol codes c(0)=1c(0) = 1, c(=)=5c(=) = 5 and c(S)=3c(S) = 3. What is the Gödel number of the string S0=0S0 = 0?

3. Gödel's incompleteness theorems

CoreHuman

In Gödel's form of the first theorem, part (a) shows T⊬GTT \nvdash G_T and part (b) shows T⊬¬GTT \nvdash \neg G_T. Which hypothesis does part (b) need beyond those of part (a)?

Choose one

4. Gödel's incompleteness theorems

CoreHuman

Assume PA\mathsf{PA} is consistent, and let T′=PA+GT' = \mathsf{PA} + G where GG is the Gödel sentence of PA\mathsf{PA}. Which statements are true? Choose all that apply.

Choose all that apply

5. Gödel's incompleteness theorems

StretchHuman

Löb's theorem: if T⊢ProvT(⌜φ⌝)→φT \vdash \mathrm{Prov}_T(\ulcorner\varphi\urcorner) \to \varphi, then T⊢φT \vdash \varphi (for T⊇PAT \supseteq \mathsf{PA} recursively axiomatised). Apply it with φ\varphi the sentence 0=S00 = S0. What do you obtain?

Choose one

6. Gödel's incompleteness theorems

CoreFormal

In the Lean file, which statement correctly formalises the abstract form of Tarski's theorem for a diagonalisable system S (with hcompl and hdiag as hypotheses)?

Choose one

7. Gödel's incompleteness theorems

CoreFormal

The Lean theorem halting_incompleteness has hypotheses hre : REPred Provable, hc : Computable nonHalt and sound. Which hypothesis expresses that the theory is recursively axiomatised?

Choose one

8. Gödel's incompleteness theorems

StretchComputational

Write encode(codes), which sends a list of positive symbol codes [c1,…,ck][c_1, \dots, c_k] to 2c13c2⋯pkck2^{c_1} 3^{c_2} \cdots p_k^{c_k}, and decode(n), which recovers the list (and [] from 1). Why is decode(encode(xs)) == xs guaranteed?

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

Common misconceptions

Misconception

"Gödel showed that some truths can never be known." The theorems concern provability in a fixed formal theory. The Gödel sentence of PA\mathsf{PA} is provable in PA+ConPA\mathsf{PA} + \mathrm{Con}_{\mathsf{PA}}, and we know it is true (given that PA\mathsf{PA} is consistent). What is impossible is a single consistent, recursively axiomatised theory that proves all arithmetical truths.

Misconception

"The theorems apply to every axiomatic system." They need two hypotheses: the theory is recursively axiomatised (true arithmetic Th(N)\mathrm{Th}(\N) is complete but not), and it interprets enough arithmetic (Presburger arithmetic and the theory of real closed fields are complete and decidable). Group theory is incomplete for a different and much simpler reason: it has non-isomorphic models.

Misconception

"The second theorem leaves the consistency of PA\mathsf{PA} unsupported." It says only that PA\mathsf{PA} cannot prove its own (standard) consistency statement. ConPA\mathrm{Con}_{\mathsf{PA}} is provable in stronger systems — in ZFC\mathsf{ZFC}, which has a model of PA\mathsf{PA}, and in primitive recursive arithmetic plus induction up to ε0\varepsilon_0 (Gentzen 1936; see proof theory). Whether those proofs add confidence is a philosophical question; that they exist is a theorem.

Misconception

"Unprovable sentences are always artificial self-referential tricks." Paris and Harrington (1977) found a natural strengthening of the finite Ramsey theorem that is true but unprovable in PA\mathsf{PA}; Goodstein's theorem (see the proof theory lesson) is another. By the MRDP theorem, for each such TT some Diophantine equation has no solutions but TT cannot prove it.

Misconception

"Adding the Gödel sentence as an axiom completes the theory." T+GTT + G_T is still consistent and recursively axiomatised, so it has its own undecided sentence. Incompleteness is not a gap that can be filled; it regenerates.

ViewpointsH

Many ways of seeing

Topology— The space of completions is a Cantor set

Let S(T)S(T) be the set of complete consistent theories extending TT (in the same language), with the topology whose basic open sets are [φ]={Γ∈S(T):φ∈Γ}[\varphi] = \{\Gamma \in S(T) : \varphi \in \Gamma\}. It is the Stone space of the Lindenbaum algebra of TT: compact, Hausdorff and totally disconnected, and second countable because there are countably many sentences. A point Γ\Gamma is isolated exactly when {Γ}=[φ]\{\Gamma\} = [\varphi] for some φ\varphi, that is, when T+φT + \varphi is consistent and complete. For T=PAT = \mathsf{PA}, Rosser's theorem says that no consistent T+φT + \varphi is complete — so S(PA)S(\mathsf{PA}) has no isolated points. By Brouwer's characterisation (1910), a non-empty compact metrisable totally disconnected space without isolated points is homeomorphic to the Cantor set. Incompleteness, topologically: the completions of PA\mathsf{PA} form a Cantor set, and its Lindenbaum algebra is the countable atomless Boolean algebra. (Compare point-set topology.)

Computation— Incompleteness as a shadow of undecidability

From the computer scientist's side, a recursively axiomatised theory is a program that enumerates theorems. If it were complete and consistent, it would decide every sentence — and so (by Fact A) would decide the halting problem. Chaitin (1974) gave a quantitative version: for each consistent recursively axiomatised TT extending Q\mathsf{Q} there is a constant LL such that TT proves no sentence of the form "the Kolmogorov complexity of the string ss exceeds LL", although all but finitely many strings have complexity above LL. The proof is a formalised Berry paradox: a short program that searches TT's theorems for such a statement would itself describe ss in fewer than LL bits.

Number theory— Unprovable Diophantine equations

The MRDP theorem (Matiyasevich 1970, completing work of Davis, Putnam and Julia Robinson) says that every computably enumerable set A⊆NA \subseteq \N is Diophantine: there is a polynomial p(a,x1,…,xk)p(a, x_1, \dots, x_k) with integer coefficients such that a∈Aa \in A if and only if p(a,xˉ)=0p(a, \bar x) = 0 has a solution in natural numbers. Taking AA to be the c.e. set of codes of theorems of TT, one obtains, for each consistent recursively axiomatised T⊇QT \supseteq \mathsf{Q}, a specific polynomial equation with no solution in N\N such that TT cannot prove that it has none. Hilbert's tenth problem — an algorithm deciding solvability of Diophantine equations — is unsolvable for the same reason.

Combinatorics— Natural independence

Ramsey's theorem says that for all n,k,mn, k, m there is an NN such that every colouring of the nn-element subsets of {0,…,N−1}\{0, \dots, N - 1\} with kk colours has a homogeneous set of size mm. Paris and Harrington (1977) added one condition — the homogeneous set HH must be relatively large, ∣H∣≥min⁡H|H| \ge \min H — and showed that the resulting statement, a Π2\Pi_2 sentence of arithmetic easily proved from the infinite Ramsey theorem, is unprovable in PA\mathsf{PA}; indeed it implies ConPA\mathrm{Con}_{\mathsf{PA}} over PA\mathsf{PA}. The function giving the least NN grows faster than every function PA\mathsf{PA} proves total.

Category theory— Diagonal arguments as fixed points

Lawvere's theorem holds in any cartesian closed category: if e:A→BAe : A \to B^A is point-surjective, every endomorphism of BB has a fixed point. Cantor, Russell, Tarski, Gödel and Turing are all instances (Lawvere 1969; Yanofsky 2003 surveys them). Read contrapositively, it says that a "truth-value object" with a fixed-point-free endomorphism such as negation cannot be the target of a universal family — which is the categorical heart of Tarski's theorem. See categorical logic.

Logic— Provability logic

Treat □\square as a modal operator. Over PA\mathsf{PA} the derivability conditions and Löb's theorem become the axioms of the modal logic GL\mathsf{GL}: □(p→q)→(□p→□q)\square(p \to q) \to (\square p \to \square q) and □(□p→p)→□p\square(\square p \to p) \to \square p, with necessitation. Solovay (1976) proved that GL\mathsf{GL} is exactly the set of modal principles that PA\mathsf{PA} proves about its own provability predicate under all arithmetical interpretations. The second incompleteness theorem is the GL\mathsf{GL}-theorem ¬□⊥→¬□¬□⊥\neg\square\bot \to \neg\square\neg\square\bot.

History & global context

History and context

  • Hilbert's programme took shape in the 1920s, with Paul Bernays, Wilhelm Ackermann and John von Neumann working on finitary consistency proofs.
  • Kurt Gödel, then in Vienna, announced the first theorem at a conference in Königsberg in September 1930 and published both theorems in 1931 ("Über formal unentscheidbare Sätze der Principia Mathematica und verwandter Systeme I"). Von Neumann, on hearing the first theorem, independently found the second, but Gödel had already obtained it.
  • Emil Post had reached related ideas in the early 1920s but did not publish them at the time; he later gave an account of this anticipation.
  • Alfred Tarski proved the undefinability of truth in his 1933 monograph on the concept of truth (in Polish; German translation 1935).
  • J. Barkley Rosser (1936) weakened ω\omega-consistency to consistency. Alonzo Church and Alan Turing (1936) proved the undecidability of first-order logic, and Turing's halting problem gave incompleteness a computational form.
  • Gerhard Gentzen (1936) proved the consistency of PA\mathsf{PA} by transfinite induction up to ε0\varepsilon_0. Hilbert and Bernays (1939) and Löb (1955) isolated the derivability conditions.
  • Tarski, Mostowski and Raphael Robinson (1953) developed essential undecidability, with Q\mathsf{Q} as a finitely axiomatised base. Yuri Matiyasevich (1970), building on Martin Davis, Hilary Putnam and Julia Robinson, settled Hilbert's tenth problem; Jeff Paris and Leo Harrington (1977) found the first natural mathematical statement independent of PA\mathsf{PA}.
Further reading

Further reading

  • Peter Smith, An Introduction to Gödel's Theorems (2007; 2nd edition 2013) — the best first course, with full proofs of Facts A–C.
  • George S. Boolos, John P. Burgess and Richard C. Jeffrey, Computability and Logic (5th edition, 2007) — the computability route and the representability theorem.
  • Herbert B. Enderton, A Mathematical Introduction to Logic (1972; 2nd edition 2001), chapter 3.
  • Raymond M. Smullyan, Gödel's Incompleteness Theorems (1992) — the abstract diagonal framework used in the Lean file.
  • George Boolos, The Logic of Provability (1993) — derivability conditions, Löb's theorem and Solovay's theorem.
  • Torkel Franzén, Gödel's Theorem: An Incomplete Guide to Its Use and Abuse (2005) — what the theorems do not say.
  • Petr Hájek and Pavel Pudlák, Metamathematics of First-Order Arithmetic (1993) — the research-level treatment.
  • Kurt Gödel's 1931 paper, in English in Jean van Heijenoort (ed.), From Frege to Gödel (1967).