MathLabs

Foundations of mathematics

Gödel's incompleteness theorems

Any formal system strong enough to describe arithmetic contains true statements it cannot prove, and cannot prove its own consistency — a fundamental limit discovered in 1931 that reshaped logic, computability, and the philosophy of mathematics.

IntuitionA sentence that talks about itself

Consider the sentence: "This sentence cannot be proved." If it could be proved, it would be false (since it says it can't be), which is bad for a proof system that only proves true things. So it must be unprovable — but then what it says is true. We have found a true statement that cannot be proved. This is not a cheap trick with words; Kurt Gödel showed in 1931 how to build an honest, purely arithmetical sentence with exactly this behaviour inside any sufficiently powerful formal system.

SchoolA formal system is a game with fixed rules

Think of a formal system like chess: a fixed starting position (axioms), fixed rules for moving pieces (rules of inference), and a match is "won" when you reach a legal position (a proved theorem). The rules don't know anything about the real world — a computer could check every move mechanically, without understanding what a proof means. Gödel's discovery is about exactly this: no matter how you fix the axioms and rules for arithmetic, some true facts about numbers will never be reachable as a "legal position" in the game.

UndergraduateTruth vs provability, and Gödel numbering

Definition: Consistency and completeness

A formal system FF is consistent if there is no statement φ\varphi for which FF proves both φ\varphi and ¬φ\neg\varphi (written F⊢φF \vdash \varphi and F⊢¬φF \vdash \neg\varphi). It is complete if for every sentence φ\varphi in its language, either F⊢φF \vdash \varphi or F⊢¬φF \vdash \neg\varphi. And FF is effectively axiomatized if a computer can decide whether a given text is a valid proof in FF.

How can a formula about numbers talk about proofs? By Gödel numbering: assign a unique natural number ⌜φ⌝\ulcorner\varphi\urcorner to every symbol, formula φ\varphi, and sequence of formulas (just as a computer stores every file as a number). Checking whether a sequence of formulas is a valid proof is a mechanical calculation on those numbers, so "the number pp encodes a proof of the formula with code nn" is an ordinary arithmetic relation PrfF(p,n)\mathrm{Prf}_F(p, n) using only ++, ×\times, and quantifiers. Provability in FF becomes the arithmetic formula ProvF(n):=∃p PrfF(p,n)\mathrm{Prov}_F(n) := \exists p\,\mathrm{Prf}_F(p, n).

⌜φ⌝=2a13a2⋯pkak\ulcorner\varphi\urcorner = 2^{a_1} 3^{a_2} \cdots p_k^{a_k}

Read a formula φ\varphi as a finite string of symbols, and let a1,a2,…,aka_1, a_2, \dots, a_k be the numeric codes of those symbols in order (say, a fixed lookup table assigns each symbol of the language a small number). The code of the whole formula, ⌜φ⌝\ulcorner\varphi\urcorner, is then the single number above: the exponent on the ii-th prime p1,p2,…,pkp_1, p_2, \dots, p_k (i.e. 2,3,5,…2, 3, 5, \dots) records the code of the ii-th symbol. Because every natural number factors into primes in exactly one way, this number can always be decoded back into the original string — coding formulas as numbers loses no information, exactly like a computer storing a text file as a sequence of bytes.

T⊢G↔¬ProvT(⌜G⌝)T \vdash G \leftrightarrow \neg\mathrm{Prov}_T(\ulcorner G\urcorner)

The equation above, T⊢G↔¬ProvT(⌜G⌝)T \vdash G \leftrightarrow \neg\mathrm{Prov}_T(\ulcorner G\urcorner), is the general shape of every diagonal (fixed-point) sentence: for a theory TT, it produces a sentence GG that is provably equivalent to the claim "I, GG, am not provable in TT." This is not a trick specific to Gödel's example — the same recipe builds a self-referential sentence for any property expressible in arithmetic, which is exactly why the loop drawn below has no dependency it cannot close: the arrow leaving GG always finds its way back to GG.

A network graph showing a directed loop between a self-referential sentence and the arithmetic statement asserting its own provability, illustrating the self-reference at the heart of Gödel's diagonal construction.
A dependency loop: the sentence GFG_F refers to its own provability. Node "GFG_F" points to node "ProvF(⌜GF⌝)\mathrm{Prov}_F(\ulcorner G_F\urcorner)" (its provability statement), which points right back to GFG_F — the same closed loop that Gödel numbering makes possible inside pure arithmetic.

Let FF be a consistent, effectively axiomatized formal system capable of expressing elementary arithmetic. Then there is a sentence GFG_F in the language of FF that is true in the standard natural numbers N\mathbb{N}, yet F⊬GFF \nvdash G_F (and if FF is ω\omega-consistent, also F⊬¬GFF \nvdash \neg G_F). In particular, FF is incomplete.

Why is it true?

By the diagonal lemma (a formal cousin of Cantor's diagonal argument), arithmetic can construct a sentence GFG_F satisfying F⊢GF↔¬ProvF(⌜GF⌝)F \vdash G_F \leftrightarrow \neg\mathrm{Prov}_F(\ulcorner G_F\urcorner) — a sentence asserting its own unprovability in FF. If F⊢GFF \vdash G_F, then ProvF(⌜GF⌝)\mathrm{Prov}_F(\ulcorner G_F\urcorner) holds, so F⊢¬GFF \vdash \neg G_F, contradicting consistency. Hence F⊬GFF \nvdash G_F — which is exactly what GFG_F claims, making GFG_F true in N\mathbb{N}. (Rosser later removed the ω\omega-consistency hypothesis.)

Proof

Step 1 (arithmetization of syntax). Fix a computable coding scheme assigning to every symbol, formula, and finite sequence of formulas of FF's language a unique natural number, its Gödel number. Because FF is effectively axiomatized, the relation PrfF(p,n)\mathrm{Prf}_F(p, n) — "pp is the code of a proof of the formula with code nn" — is expressible by an arithmetic formula using only ++, ×\times, and quantifiers, since checking a proof line by line is a finite mechanical procedure. Define ProvF(n):=∃p PrfF(p,n)\mathrm{Prov}_F(n) := \exists p\, \mathrm{Prf}_F(p, n).

Step 2 (the diagonal lemma). For any arithmetic formula ψ(x)\psi(x) with one free variable, the diagonal lemma produces a sentence DD such that F⊢D↔ψ(⌜D⌝)F \vdash D \leftrightarrow \psi(\ulcorner D \urcorner) — DD asserts of its own code that ψ(x)\psi(x) holds of it. Apply this to ψ(x):=¬ProvF(x)\psi(x) := \neg\mathrm{Prov}_F(x): we obtain a sentence GFG_F with F⊢GF↔¬ProvF(⌜GF⌝)F \vdash G_F \leftrightarrow \neg\mathrm{Prov}_F(\ulcorner G_F \urcorner). Informally, GFG_F says "I am not provable in FF."

Step 3 (F⊬GFF \nvdash G_F). Suppose toward contradiction that F⊢GFF \vdash G_F. Since FF is effectively axiomatized, this proof itself has a code p0p_0, so PrfF(p0,⌜GF⌝)\mathrm{Prf}_F(p_0, \ulcorner G_F \urcorner) is true, hence F⊢ProvF(⌜GF⌝)F \vdash \mathrm{Prov}_F(\ulcorner G_F \urcorner) (provable arithmetic facts about concrete numbers are themselves provable in FF). But the diagonal equivalence together with F⊢GFF \vdash G_F gives F⊢¬ProvF(⌜GF⌝)F \vdash \neg \mathrm{Prov}_F(\ulcorner G_F \urcorner). So FF proves both a statement and its negation, contradicting consistency. Hence F⊬GFF \nvdash G_F.

Step 4 (GFG_F is true, and — assuming ω\omega-consistency — F⊬¬GFF \nvdash \neg G_F). Since F⊬GFF \nvdash G_F, no number codes a proof of GFG_F, so ¬ProvF(⌜GF⌝)\neg\mathrm{Prov}_F(\ulcorner G_F \urcorner) holds in N\mathbb{N}; by the diagonal equivalence this is exactly what GFG_F asserts, so GFG_F is true. If FF also proved the negation of GFG_F, i.e. F⊢¬GFF \vdash \neg G_F, then combining this with the diagonal equivalence would give F⊢ProvF(⌜GF⌝)F \vdash \mathrm{Prov}_F(\ulcorner G_F \urcorner) — "some pp codes a proof of GFG_F" — without that ever being witnessed by an actual proof, exactly the situation ω\omega-consistency rules out. So under ω\omega-consistency F⊬¬GFF \nvdash \neg G_F as well, and FF is incomplete.

Let FF be a consistent, effectively axiomatized formal system extending Peano arithmetic (or strong enough to formalize its own proof predicate), and let Con(F):=¬ProvF(⌜0=1⌝)\mathrm{Con}(F) := \neg\mathrm{Prov}_F(\ulcorner 0 = 1\urcorner) be the arithmetic sentence expressing that FF is consistent. Then F⊬Con(F)F \nvdash \mathrm{Con}(F).

Why is it true?

The proof of the first theorem — "if FF is consistent, then FF does not prove GFG_F" — can itself be formalized inside FF, yielding F⊢Con(F)→GFF \vdash \mathrm{Con}(F) \to G_F. If FF could prove Con(F)\mathrm{Con}(F), modus ponens would give F⊢GFF \vdash G_F, contradicting the first theorem.

Proof

Step 1 (the provability predicate is formalizable, not just definable). Because ProvF\mathrm{Prov}_F is built from the mechanical, checkable relation PrfF(p,n)\mathrm{Prf}_F(p,n), three "derivability conditions" are themselves provable inside FF (this is where the argument needs FF to extend Peano arithmetic, not just be consistent): (P1P_1) if FF proves φ\varphi then FF proves ProvF(⌜φ⌝)\mathrm{Prov}_F(\ulcorner\varphi\urcorner); (P2P_2) FF proves ProvF(⌜φ→ψ⌝)→(ProvF(⌜φ⌝)→ProvF(⌜ψ⌝))\mathrm{Prov}_F(\ulcorner\varphi\to\psi\urcorner) \to (\mathrm{Prov}_F(\ulcorner\varphi\urcorner)\to\mathrm{Prov}_F(\ulcorner\psi\urcorner)); (P3P_3) FF proves ProvF(⌜φ⌝)→ProvF(⌜ProvF(⌜φ⌝)⌝)\mathrm{Prov}_F(\ulcorner\varphi\urcorner) \to \mathrm{Prov}_F(\ulcorner\mathrm{Prov}_F(\ulcorner\varphi\urcorner)\urcorner).

Step 2 (formalizing Theorem 1's own argument). By the diagonal equivalence, F⊢¬GF→ProvF(⌜GF⌝)F \vdash \neg G_F \to \mathrm{Prov}_F(\ulcorner G_F \urcorner). The informal argument of Theorem 1 — "if GFG_F were provable, its own proof would witness ProvF(⌜GF⌝)\mathrm{Prov}_F(\ulcorner G_F\urcorner), and the diagonal equivalence would then hand us a proof of ¬GF\neg G_F too" — uses nothing beyond mechanical symbol manipulation covered by (P1P_1)–(P3P_3), so it can be mirrored step by step as a formal deduction inside FF itself, yielding F⊢ProvF(⌜GF⌝)→ProvF(⌜¬GF⌝)F \vdash \mathrm{Prov}_F(\ulcorner G_F \urcorner) \to \mathrm{Prov}_F(\ulcorner \neg G_F \urcorner). Since proving both GFG_F and its negation lets FF derive 0=10 = 1 by ex falso quodlibet, this gives F⊢ProvF(⌜GF⌝)→¬Con(F)F \vdash \mathrm{Prov}_F(\ulcorner G_F \urcorner) \to \neg\mathrm{Con}(F), i.e. F⊢Con(F)→GFF \vdash \mathrm{Con}(F) \to G_F.

Step 3 (conclusion). Suppose toward contradiction that F⊢Con(F)F \vdash \mathrm{Con}(F). Combined with F⊢Con(F)→GFF \vdash \mathrm{Con}(F) \to G_F via modus ponens, FF would prove GFG_F. But Theorem 1 already showed F⊬GFF \nvdash G_F for consistent FF — a contradiction. Hence FF cannot prove Con(F)\mathrm{Con}(F), exactly as claimed.

In the 1920s David Hilbert proposed Hilbert's program: axiomatize all of mathematics and then prove, using only simple finitary reasoning about symbols, that the axioms are consistent and complete. Gödel's two theorems showed this cannot be done as stated: Peano arithmetic cannot even prove its own consistency, let alone that of set theory, without using principles stronger than the ones being checked.

For any first-order theory TT and sentence φ\varphi, T⊢φT \vdash \varphi if and only if φ\varphi is true in every model of TT (T⊨φT \models \varphi).

Why is it true?

Proved by Gödel in 1929 (his doctoral thesis), this says the inference rules of first-order logic are complete: they miss no logical consequence. Incompleteness (1931) does not contradict this: GFG_F is unprovable because FF has non-standard models in which GFG_F is false, even though GFG_F is true in the intended model N\mathbb{N}.

Proof

Step 1 (soundness — the easy direction, T⊢φT \vdash \varphi implies T⊨φT \models \varphi). Argue by induction on the length of a formal proof of φ\varphi from TT. Every axiom of TT is true in any model MM of TT by definition; every purely logical axiom (e.g. φ→(ψ→φ)\varphi \to (\psi \to \varphi)) is valid, true under every interpretation whatsoever. And each inference rule preserves truth in MM: for modus ponens, if M⊨θM \models \theta and M⊨θ→φM \models \theta \to \varphi then automatically M⊨φM \models \varphi. So every line of the proof is true in MM, and in particular the last line, φ\varphi, is; since MM was an arbitrary model of TT, T⊨φT \models \varphi.

Step 2 (completeness — the hard direction, by contraposition: T⊬φT \nvdash \varphi implies T⊭φT \not\models \varphi). Suppose T⊬φT \nvdash \varphi. Then the set T∪{¬φ}T \cup \{\neg\varphi\} is consistent (if it proved a contradiction, TT would prove φ\varphi by reductio). Using Henkin's method, extend it to a maximal consistent set Σ\Sigma with witnesses: whenever ∃x ψ(x)\exists x\, \psi(x) is in Σ\Sigma, some constant cc is added with ψ(c)\psi(c) also in Σ\Sigma. Build the term model MΣM_\Sigma whose elements are closed terms of the extended language identified up to provable equality in Σ\Sigma, with relations and functions interpreted directly from Σ\Sigma. A term-length induction (the "truth lemma") then shows MΣ⊨θ  ⟺  θ∈ΣM_\Sigma \models \theta \iff \theta \in \Sigma for every sentence θ\theta.

Step 3 (assembling the model, and conclusion). Since ¬φ∈Σ\neg\varphi \in \Sigma, the truth lemma gives MΣ⊨¬φM_\Sigma \models \neg\varphi, and since every axiom of TT lies in Σ\Sigma, also MΣ⊨TM_\Sigma \models T. So MΣM_\Sigma is an actual model of TT in which φ\varphi fails, i.e. T⊭φT \not\models \varphi. This proves the contrapositive of Step 2, and combined with Step 1, T⊢φT \vdash \varphi exactly when T⊨φT \models \varphi — this is Gödel's 1929 doctoral thesis result, later streamlined by Leon Henkin (1949) into the term-model construction used here.

AdvancedIncompleteness, the halting problem, and undecidable problems

There is no algorithm (Turing machine) HH that takes the code of an arbitrary program PP and input xx and always halts with the correct answer to whether P(x)P(x) eventually halts.

Why is it true?

Suppose H(P,x)H(P, x) decided halting. Build a machine D(P)D(P) that runs H(P,P)H(P, P) and then loops forever if HH says "halts", and halts if HH says "loops". Feeding DD its own code: D(D)D(D) halts iff H(D,D)H(D, D) says it loops — a contradiction. This is the exact computational twin of Gödel's diagonal sentence.

Proof

Step 1 (assume a halting decider exists). Suppose toward contradiction that there is an algorithm HH such that H(P,x)H(P, x) always terminates and correctly outputs "halts" if the program with code PP halts on input xx, and "loops" otherwise.

Step 2 (build a diagonal machine from HH). Define a new algorithm D(P)D(P) that, on input a program code PP, first computes H(P,P)H(P, P) — running HH with PP fed in as both the program and the input. If H(P,P)H(P, P) says "halts", then DD deliberately enters an infinite loop; if H(P,P)H(P, P) says "loops", then DD halts immediately (say, by returning 00).

Step 3 (feed DD its own code). Since DD is itself an algorithm, it has a code, and nothing stops us from running DD on that very code: consider D(D)D(D). Two cases, both impossible: if D(D)D(D) halts, then by construction this happens exactly when H(D,D)H(D, D) said "loops" — meaning HH incorrectly reported that DD on DD does not halt, even though it just did. If instead D(D)D(D) runs forever, this happens exactly when H(D,D)H(D, D) said "halts" — meaning HH incorrectly reported that it halts, even though it loops forever.

Step 4 (conclusion). Either way HH gives a wrong answer on the input (D,D)(D, D), contradicting the assumption that HH is always correct. So no such algorithm HH can exist: the halting problem is undecidable.

The halting problem immediately implies the first incompleteness theorem: if a sound, effectively axiomatized system FF were complete for arithmetic, we could decide whether P(x)P(x) halts simply by enumerating all proofs in FF until we find either a proof that P(x)P(x) halts or a proof that it does not. And undecidability reaches into ordinary number theory: Hilbert's tenth problem (`hilbert-tenth-problem`), which asked for an algorithm to decide whether a polynomial equation with integer coefficients has an integer solution, was shown to have no such algorithm by Davis, Putnam, Robinson, and Matiyasevich (1970). Consequently, in any consistent system FF, there is a specific Diophantine equation with no integer solution whose unsolvability FF cannot prove.

UndergraduateReal-World Applications and Worked Examples

Gödel and Turing's limits are not just philosophical curiosities: they set hard boundaries on what software tools can ever promise. Every "prove my program has no bugs" static analyzer, every fully automatic theorem prover, and every antivirus scanner that claims to detect all malicious behavior runs directly into these theorems — some questions about programs are simply not decidable by any algorithm, no matter how much computing power or cleverness is thrown at them. The two examples below make this concrete: one shows the numbering machinery at the heart of the proof in miniature, the other shows a genuine software-engineering task that inherits undecidability directly from the halting problem.

Example

Fix a toy lookup table for a tiny logical alphabet: ¬↦1\neg \mapsto 1, ∃↦3\exists \mapsto 3, x↦4x \mapsto 4. Using the Gödel numbering formula, compute the code ⌜¬∃x⌝\ulcorner \neg \exists x \urcorner of the three-symbol string "¬∃x\neg \exists x".

Solution

Step 1 (read off the symbol codes in order). The string "¬∃x\neg \exists x" has three symbols in this order: ¬\neg, ∃\exists, xx. Looking them up in the table gives the code sequence a1=1a_1 = 1, a2=3a_2 = 3, a3=4a_3 = 4.

Step 2 (apply the numbering formula). With k=3k = 3 symbols, the formula is ⌜¬∃x⌝=2a1⋅3a2⋅5a3=21⋅33⋅54\ulcorner \neg \exists x \urcorner = 2^{a_1} \cdot 3^{a_2} \cdot 5^{a_3} = 2^{1} \cdot 3^{3} \cdot 5^{4}, using the first three primes 2,3,52, 3, 5 as the bases.

Step 3 (compute each prime power). 21=22^{1} = 2, 33=273^{3} = 27, and 54=6255^{4} = 625.

Step 4 (multiply). ⌜¬∃x⌝=2×27×625=33,750\ulcorner \neg \exists x \urcorner = 2 \times 27 \times 625 = 33{,}750. Because 33,75033{,}750 factors uniquely as 21⋅33⋅542^1 \cdot 3^3 \cdot 5^4, anyone holding this single number can recover the exponents 1,3,41, 3, 4 and hence read back the exact original string "¬∃x\neg \exists x" — no information was lost in the encoding.

Example

A static-analysis team wants to add a feature ZZ to their tool: given the source code of any function ff in their language, Z(f)Z(f) always terminates and correctly reports whether there is some input on which ff throws a null-pointer exception. Show that no such ZZ can exist, by reducing the halting problem to it.

Solution

Step 1 (reduce halting to null-pointer detection). Assume toward contradiction that ZZ exists. Given an arbitrary program PP and input xx — an instance of the halting problem — build a new function fP,xf_{P,x} (with no input of its own) as follows: fP,xf_{P,x} first simulates PP running on xx step by step, using no null pointers anywhere in that simulation code.

Step 2 (attach the observable signal). Immediately after the simulation of P(x)P(x) finishes — which only happens if P(x)P(x) halts — fP,xf_{P,x} executes one further line that deliberately dereferences a null pointer, throwing the exception. If the simulation of P(x)P(x) never finishes, this line is never reached and no exception is ever thrown.

Step 3 (the reduction is exact). By construction, fP,xf_{P,x} throws a null-pointer exception on some input if and only if P(x)P(x) halts: the "some input" is irrelevant here since fP,xf_{P,x} ignores its argument, but the tool's decision about fP,xf_{P,x} exactly answers the halting question for (P,x)(P, x).

Step 4 (contradiction). Running the assumed decider as Z(fP,x)Z(f_{P,x}) would then decide, for arbitrary PP and xx, whether P(x)P(x) halts — but the theorem above shows no algorithm can do that. So the static-analysis feature ZZ cannot exist for arbitrary programs, no matter how sophisticated the analysis.

ResearchNatural independent statements and the continuum hypothesis

Gödel's sentence GFG_F looks artificial — it was engineered to talk about its own proof. Does incompleteness ever hit questions mathematicians were already asking? Yes. The most famous example is Cantor's continuum hypothesis (`continuum-hypothesis`): is there any set whose size lies strictly between that of N\mathbb{N} and that of R\mathbb{R}? Gödel (1940) proved that ZFC set theory cannot disprove it (by building the constructible universe LL), and Paul Cohen (1963) invented forcing to prove that ZFC cannot prove it either. In arithmetic itself, the Paris–Harrington theorem (1977) and Goodstein's theorem (1944, proved independent by Kirby–Paris in 1982) are genuine combinatorial facts about finite numbers that are true in N\mathbb{N} yet unprovable in Peano arithmetic.

Why does Gödel's first incompleteness theorem not apply to Presburger arithmetic (the first-order theory of N\mathbb{N} with addition ++ only, without multiplication ×\times)?

What does Gödel's second incompleteness theorem say about a consistent, effectively axiomatized system FF extending Peano arithmetic?

Gödel proved a completeness theorem in 1929 and an incompleteness theorem in 1931. Why do they not contradict each other?

If a sound, effectively axiomatized formal system FF were complete for arithmetic, what would that imply for the halting problem?

References

  1. Kurt Gödel (ed. Jean van Heijenoort) (1967). On formally undecidable propositions of Principia Mathematica and related systems I (1931), in From Frege to Gödel · DOI:10.1007/BF01700692
  2. Peter Smith (2013). An Introduction to Gödel's Theorems · DOI:10.1017/cbo9780511800962
  3. Torkel Franzén (2005). Gödel's Theorem: An Incomplete Guide to Its Use and Abuse