4. Curry-Howard
Draft
The rules of proof are the rules of typing
Set two tables from the last two parts side by side. Section 2.2 typed the lambda calculus with three rules: a variable has the type its context lists, an abstraction \(\lambda x{:}A.\, M\) has a function type \(A \to B\), and an application hands a function its argument. Section 3.2 proved implications by three kinds of step in natural deduction: use an assumption, introduce \(A \to B\) by discharging the assumption \(A\), eliminate it by modus ponens. They are the same three rules. A proposition is a type, and a proof of it is a program of that type; and because the tables match rule for rule, simplifying a proof is running it: to remove a detour, an introduction that is at once eliminated (Section 3.3), is to take one step of reduction (Section 1.1). This identification is the Curry-Howard correspondence.
For the series this is the hinge. It closes the first of five steps, turning a proof into a concrete object: once a proof is a program term, checking a proof reduces to computing its type, which is the job of the kernel in Section 6. The match would be mere notation if it stopped at the static rules, yet it goes deeper: simplifying a proof is running the program, which is why a constructive proof of existence carries a computable witness while a classical proof by contradiction need not. Lean keeps the typing match intact and, for propositions, sets execution aside by treating all proofs of a given proposition as interchangeable.
Here is one object, a proof that \(p \land q\) implies \(q \land p\), in three notations.
object p ∧ q → q ∧ p, proved once and written three times
proof [p ∧ q]ʰ [p ∧ q]ʰ
―――――――― ∧E₂ ―――――――― ∧E₁
q p
――――――――――――――――――――――――― ∧I the rule in use
q ∧ p
――――――――――――――――――――――――― →Iʰ
p ∧ q → q ∧ p
term λh:p ∧ q. ⟨π₂ h, π₁ h⟩ the rule in use writes ⟨ , ⟩
Lean theorem and_swap (p q : Prop) : p ∧ q → q ∧ p :=
fun h => ⟨h.2, h.1⟩
or, as a tactic script after by: intro h; constructor; · exact h.2; · exact h.1
rule in a term in Lean as a tactic
∧I ⟨M, N⟩ ⟨a, b⟩ constructor one of 12 rows; this proof uses 5 of them
∧I as a rule of natural deduction: from A and B infer A ∧ B. As a typing rule: from Γ ⊢ M : A and
Γ ⊢ N : B infer Γ ⊢ ⟨M, N⟩ : A ∧ B. Here A is q and B is p.
6 rule applications, 6 nodes of the term, one for each. Lean 4.35.0 accepts the term and the script,
and prints both as fun p q h => ⟨h.right, h.left⟩.
(the live figure needs JavaScript; it loads no data)
Every rule of the proof is one constructor of the term and one piece of the Lean source, at the same place: the tree, the term and the declaration are one object, and the dictionary under them only renames its parts. The tree of Section 3.1 wrote its atoms \(P, Q, R\), and the trees of Section 3 number the assumptions that a rule discharges; here the atoms are \(p, q, r\), as in the Lean source beside them, and every assumption has a name, because the name is a variable: an assumption that a rule discharges is a variable that a \(\lambda\) binds.
Seeing one proof written three ways is suggestive, yet a proof checker needs a two-way guarantee: every well-typed term must represent a valid proof (so type-checking is sound), and every valid proof must be representable as a well-typed term (so nothing provable is lost). Erase the terms from a typing derivation and a natural-deduction proof remains; assign variable names to the open assumptions of a proof and a typed lambda term emerges.
Theorem 4.1.1 (the correspondence for implication). Take the formulas built from atoms by \(\to\) alone, and read each also as a simple type (Definition 2.2.1). (i) If \(x_1 : A_1, \dots, x_n : A_n \vdash M : A\) is derived by the rules of Definition 2.2.2, then erasing the terms leaves a derivation of \(A\) from the assumptions \(A_1, \dots, A_n\) in natural deduction: (var) becomes the use of an assumption, (abs) the introduction of \(\to\), and (app) its elimination. (ii) Conversely, every derivation of \(A\) from \(A_1, \dots, A_n\) by the rules for implication becomes, once each assumption is named by a variable, a derivation of \(x_1 : A_1, \dots, x_n : A_n \vdash M : A\) for some term \(M\): an introduction binds the variable of the assumption it discharges, and an elimination is an application.M. H. B. Sørensen and P. Urzyczyn, "Lectures on the Curry-Howard Isomorphism" (lecture notes, 1998), Proposition 4.2.1, for natural deduction written with contexts. The rules for implication alone are those of the implication fragment of intuitionistic logic (Section 3.6).
Proof. Each direction is an induction on the derivation, one case to a rule. ∎
The paper that gave the correspondence its present form does not argue for it at greater length.
Clearly the axioms and rules of inference 1.1-1.3 of P(⊃) correspond exactly to the rules 2.1-2.3 of term formation. A construction of Γ → β is clearly also a construction of Γ, α → β (thinning); similarly for a permutation of Γ; and the contraction (from Γ, α, α → β infer Γ, α → β) corresponds to replacing two distinct variables of type α by one variable of type α in the corresponding construction. Hence:
THEOREM 1. Given any derivation of Γ → β in P(⊃) we can find a construction of Γ → β and conversely.
—W. A. Howard, "The formulae-as-types notion of construction" (1980). In J. P. Seldin and J. R. Hindley (eds.), To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, Academic Press, pp. 479–490; the passage is the whole of the third of its thirteen sections, p. 481. P(⊃) is the logic of implication alone, written with sequents: ⊃ is implication, and Γ → β says that β follows from the assumptions Γ. Rules 1.1 to 1.3 are the axiom α → α and the two rules of implication; rules 2.1 to 2.3 form variables, abstractions and applications; a construction of a sequent is a term of type β whose free variables have types that occur in Γ. The print sets the contraction as an inference figure, written out here in words.
The paper is a set of notes that went round as photocopies from 1969 and were printed in 1980. The question came from Kreisel, who wanted a mathematical notion of what Brouwer called a construction (Section 4.4), and the notes name two debts. One is to Curry, who had observed that the types of the basic combinators, a few closed terms from which the others are built by application, are axioms of the logic of implication: the term \(\mathsf{K} = \lambda x\,y.\, x\) of Section 1.4 has the type \(A \to B \to A\), the first axiom of a Hilbert system (Section 3.1), and modus ponens is application. The other is to Tait, and Section 4.3 takes it up. In the same years N. G. de Bruijn found the idea independently and made it the working principle of a proof checker, Automath; Section 4.8 returns to him.The two debts: Howard, pp. 479–480, citing Curry's book of 1958 with R. Feys; that book, by J. P. Seldin's account, also notes that a typing deduction with its terms removed is a deduction in the implication fragment of intuitionistic logic ("The logic of Curry and Church", draft of 2008, Section 2.6). Kreisel's question, the summer of 1966 as the date of the idea, the handwritten notes of January 1969, and the judgment that de Bruijn "discovered the idea of derivations as terms, and the accompanying idea of formulae-as-types, on his own" are from a letter of Howard's that P. Wadler published in 2014 ("Howard on Curry-Howard"); by the same letter the name formulae-as-types is Kreisel's. De Bruijn designed Automath in 1967 and 1968 (F. Dechesne and R. Nederpelt, "N.G. de Bruijn (1918-2012) and his road to Automath, the earliest proof checker", The Mathematical Intelligencer 34(4), 2012, pp. 4–11).
Whether the two translations in Theorem 4.1.1 are exact inverses determines how much information a proof term must record.
Remark 4.1.2 (in what sense an isomorphism). The correspondence is often called the Curry-Howard isomorphism, with two qualifications. First, the bijection is exact only when discharged assumptions carry explicit labels. Both \(\lambda x{:}p.\,\lambda y{:}p.\, x\) and \(\lambda x{:}p.\,\lambda y{:}p.\, y\) inhabit the type \(p \to p \to p\), and erasing their variables collapses both derivations into the same unlabeled tree of formulas; they differ in which of the two outer →I steps discharges the leaf \(p\), and variable names record that choice unambiguously. A lambda term is a proof with every assumption named and nothing left implicit, which is why Lean stores the term rather than a bare tree of formulas. Second, the name covers a family of correspondences pairing one typed calculus with each logic: just as implicational logic matches simple types, second-order logic matches the polymorphic types of System F (Section 2.5) and predicate logic matches the dependent types of Section 5.Sørensen and Urzyczyn, Remark 4.2.2, for the two terms, and the first paragraph of their preface for the family.
Theorem 4.1.1 covers implication alone, whereas the proof in the figure already pairs hypotheses with a conjunction.
The dictionary
Implication is one row of a table. Each further connective of Section 3.2 adds a row, and on the side of programs every row is a familiar way of building data and of using it.
One dictionary, two columnsa row to a notion; left, as natural deduction names it; right, as the lambda calculus names it
- what is stated
a proposition A statement that it makes sense to try to prove: p ∧ q → q ∧ p.
4.1a type What a program is promised to return. In Lean a proposition is a type in the universe Prop, and data lives in Type.
- what settles it
a proof A tree of rule applications that ends in the proposition.
4.1a program of that type A term with one constructor for each rule of the tree: fun h => ⟨h.2, h.1⟩.
- what is supposed
an assumption Used above, and discharged below by the rule that introduces an implication.
4.1a variable Free where it is used, and bound by the λ that stands for that rule. The name of the assumption is the variable.
- if, then
an implication Introduced by proving B from the assumption A, and used by modus ponens.
4.2a function Built by abstraction, used by application. In Lean p → q is the function type itself.
- and, or, false
conjunction, disjunction, falsity Each with its introduction rules and one way of being used. Falsity has no introduction.
4.2pairs, tagged unions, the empty type The introductions are the constructors: a pair, a value tagged left or right, nothing at all. In Lean: And, Or, False, and for data Prod, Sum, Empty.
- there is
an existence statement Proved constructively by giving a witness and a proof that it is one.
4.5a dependent pair The witness with its proof. In Lean the pair can be projected when it is data (Subtype, Sigma); a proof of ∃ shows its witness only to another proof.
- a roundabout step
a detour An introduction followed at once by the elimination of the same connective: a lemma proved and at once used.
4.3a redex A constructor met by its destructor: a function applied, a pair projected. Removing the detour is one step of reduction.
- what is left
a normal proof No detour is left. If it has no open assumption, it ends in an introduction.
4.3a value The program has returned: a function, a pair, a tagged value. Normalization is evaluation.
- a classical law
Peirce's law ((A → B) → A) → A holds classically and has no proof in the rows above. In Lean it is a theorem that rests on axioms.
4.6callcc: a jump An operator that hands its argument the rest of the computation as a value. Calling that value throws away whatever was waiting.
green: the row that makes the dictionary more than a renaming; removing a detour is one step of running the program
Definition 4.2.1 (terms for conjunction, disjunction and falsity). Extend the types by \(A \land B\), \(A \lor B\) and \(\bot\), and the terms and rules of Definition 2.2.2 by
\[\frac{\Gamma \vdash M : A \qquad \Gamma \vdash N : B}{\Gamma \vdash \langle M, N \rangle : A \land B} \qquad \frac{\Gamma \vdash M : A \land B}{\Gamma \vdash \pi_1 M : A} \qquad \frac{\Gamma \vdash M : A \land B}{\Gamma \vdash \pi_2 M : B}\] \[\frac{\Gamma \vdash M : A}{\Gamma \vdash \mathsf{inl}\,M : A \lor B} \qquad \frac{\Gamma \vdash M : B}{\Gamma \vdash \mathsf{inr}\,M : A \lor B} \qquad \frac{\Gamma \vdash M : \bot}{\Gamma \vdash \mathsf{abort}\,M : C}\] \[\frac{\Gamma \vdash M : A \lor B \qquad \Gamma,\, x : A \vdash N : C \qquad \Gamma,\, y : B \vdash P : C}{\Gamma \vdash \mathsf{case}\;M\;\mathsf{of}\;\mathsf{inl}\,x \Rightarrow N \mid \mathsf{inr}\,y \Rightarrow P \;:\; C}\]With the terms erased these are the introduction and elimination rules of \(\land\), \(\lor\) and \(\bot\) in Section 3.2, and Theorem 4.1.1 extends to them case by case. Negation has no rules of its own: \(\lnot A\) is \(A \to \bot\).
On the programming side, these three additions are ordinary data types: pairs (\(A \land B\)), tagged unions whose values carry a left or right tag (\(A \lor B\), a sum type), and an uninhabited type (\(\bot\)), out of which a function may promise any return type \(C\) because no input of type \(\bot\) can ever be supplied to call it. In every row of the dictionary, introduction rules construct values of the type and elimination rules destruct or consume them.
Even a statement that looks purely logical, such as Section 3.6's intuitionistic theorem \(\lnot\lnot(p \lor \lnot p)\) that the excluded middle cannot be refuted, translates under the dictionary into an executable higher-order callback program.
Example 4.2.2 (a proof that is a program). Unfolding \(\lnot A\) as \(A \to \bot\) turns \(\lnot\lnot(p \lor \lnot p)\) into the function type \(((p \lor (p \to \bot)) \to \bot) \to \bot\), inhabited by the closed term
\[\lambda h.\;\, h\,\bigl(\mathsf{inr}\,(\lambda a.\; h\,(\mathsf{inl}\,a))\bigr).\]Given \(a : p\), calling \(h\,(\mathsf{inl}\,a)\) produces \(\bot\), so the inner function \(\lambda a.\; h\,(\mathsf{inl}\,a)\) has type \(p \to \bot\) (that is, \(\lnot p\)); wrapping that function in \(\mathsf{inr}\) builds a value of \(p \lor \lnot p\), and passing it to \(h\) yields \(\bot\) again. Operationally, the program receives an adversary \(h\) claiming to refute \(p \lor \lnot p\), and immediately calls \(h\) on the right branch ("not \(p\)"). As evidence for \(\lnot p\), it hands \(h\) a callback: if \(h\) ever tests that callback by supplying a proof \(a\) of \(p\), the callback wraps \(a\) in the left branch ("\(p\)") and calls \(h\) a second time. Either way, \(h\) is handed a value of the exact sum type it claimed was empty. The derivation uses nine steps, three of them variable lookups (Section 3.6 counted the other six), and requires no classical axiom, in Lean or here (Section 4.6 returns to this callback). ◁
Twice that term assumes a hypothesis and derives \(\bot\), which looks superficially like proof by contradiction, yet no classical rule appears anywhere in it.
Remark 4.2.3 (proving a negation is not proof by contradiction). Because \(\lnot A\) is simply an abbreviation for the function type \(A \to \bot\), proving \(\lnot A\) by assuming \(A\) and deriving \(\bot\) is just writing a \(\lambda\)-abstraction: it is the ordinary introduction rule for \(\to\), and completely constructive. What has no term in Definition 4.2.1 is the converse step from \(\lnot\lnot A\) (that is, \((A \to \bot) \to \bot\)) to \(A\), which tries to manufacture a value of \(A\) merely from knowing that \(A \to \bot\) leads to \(\bot\). That step, along with \(A \lor \lnot A\) and Peirce's law (Section 4.6), is what separates classical from intuitionistic logic in Section 3.6.
In Lean's core library the rows stand twice, once in Prop, the universe of propositions, and once in Type, where data lives; all but implication, the function type itself, are declarations.
| logic | Lean, a proposition | Lean, data |
|---|---|---|
| \(A \to B\) | p → q, the function type |
α → β |
| \(A \land B\) | And p q: And.intro, .left, .right |
Prod α β: Prod.mk, .fst, .snd |
| \(A \lor B\) | Or p q: Or.inl, Or.inr, Or.elim |
Sum α β: Sum.inl, Sum.inr, Sum.elim |
| \(\bot\) | False: False.elim |
Empty: Empty.elim |
| \(\top\) | True: True.intro |
Unit: () |
| \(\lnot A\) | Not p, defined as p → False |
|
| \(\exists x.\, A(x)\) | Exists p: Exists.intro, Exists.elim |
Subtype p, Sigma β |
/--
`And a b`, or `a ∧ b`, is the conjunction of propositions. It can be
constructed and destructed like a pair: if `ha : a` and `hb : b` then
`⟨ha, hb⟩ : a ∧ b`, and if `h : a ∧ b` then `h.left : a` and `h.right : b`.
-/
@[pp_using_anonymous_constructor]
structure And (a b : Prop) : Prop where
/-- `And.intro : a → b → a ∧ b` is the constructor for the And operation. -/
intro ::
/-- Extract the left conjunct from a conjunction. `h : a ∧ b` then
`h.left`, also notated as `h.1`, is a proof of `a`. -/
left : a
/-- Extract the right conjunct from a conjunction. `h : a ∧ b` then
`h.right`, also notated as `h.2`, is a proof of `b`. -/
right : b
And is a structure with two fields, and Prod, the type of pairs of data, is declared shortly before it in the same file, with the same shape.
Definition 4.2.1 stops short of the quantifiers. Howard's notes go on to them: a proof of \(\forall x.\, A(x)\) is a function whose result type depends on its argument, and a proof of \(\exists x.\, A(x)\) is a pair whose second type depends on its first component.The second of the paper's two parts treats arithmetic. P. Wadler, "Propositions as types" (author's version of 29 November 2014; the journal version appeared in Communications of the ACM in 2015), p. 4: "Howard proposes that the predicate quantifiers ∀ and ∃ corresponds to new types that we now call dependent types." Types that mention values are the subject of Section 5; Section 4.5 needs only the pair.
Matching each logical connective with a static data type is only half the correspondence; the deeper half shows that simplifying a proof by removing detours is literally running the program.
Simplifying a proof is running it
Section 3 took a proof of \(r\) from \(p\), \(p \to q\) and \(q \to r\) that goes by way of a pair, and removed its detours one at a time. Here is the same proof with its term beside it, and two engines at work on them, neither told what the other does.
object a proof seen in Section 3: r from p, p → q and q → r, through the lemma p ∧ (p → q) → r
proof the conclusion first, premises indented under it rule
r →E
p ∧ (p → q) → r the detour: introduced here, eliminated above →I, discharges [p ∧ (p → q)]
r →E
hqr:q → r
q →E
p → q ∧E₂
[p ∧ (p → q)]
p ∧E₁
[p ∧ (p → q)]
p ∧ (p → q) ∧I
hp:p
hpq:p → q
term a line to a state: the step before it, the term, its size in nodes
(λh:p ∧ (p → q). hqr (π₂ h (π₁ h))) ⟨hp, hpq⟩ 12 the redex: λ applied
beta → hqr (π₂ ⟨hp, hpq⟩ (π₁ ⟨hp, hpq⟩)) 11 Lean #reduce comes this far, as a proof
proj → hqr (hpq (π₁ ⟨hp, hpq⟩)) 8
proj → hqr (hpq hp) 5 Lean #reduce comes this far, as data
Two engines, one for proofs and one for terms, take the same 3 steps and agree at each of the 4 states:
removing the detour →I then →E is the step beta, ∧I then ∧E the step proj. Other runs, by size: swap of a
pair 10 → 9 → 6 → 3; a lemma used twice 10 → 11; swap of a case 10 → 7 → 2; a case, then a projection
9 → 10 → 7 → 4; after ex falso 3 → 2.
(the live figure needs JavaScript; it loads no data)
The two engines stay in lockstep at every state because they perform the exact same rewrite. In term notation, a logical detour is a constructor immediately met by its matching destructor: a \(\lambda\)-abstraction applied to an argument, a pair hit by a projection, or an injection inspected by case. Section 1 called such a subterm a redex. Proving a lemma and immediately applying it is defining a function and immediately calling it; removing the detour is one evaluation step, and reaching a detour-free proof means the program has finished computing a value. Making that match precise across all connectives adds projection and case-split reduction rules alongside β-reduction.
Definition 4.3.1 (reduction). The terms of Definition 4.2.1 reduce by the beta rule of Section 1.1 and by one rule for each of the other connectives:
\[\begin{aligned} (\lambda x{:}A.\, M)\,N &\;\to\; M[x := N] \\ \pi_1 \langle M, N \rangle \;\to\; M, \qquad \pi_2 \langle M, N \rangle &\;\to\; N \\ \mathsf{case}\;(\mathsf{inl}\,M)\;\mathsf{of}\;\mathsf{inl}\,x \Rightarrow N \mid \mathsf{inr}\,y \Rightarrow P &\;\to\; N[x := M] \end{aligned}\]and the mirror image of the last for \(\mathsf{inr}\). A term to which no rule applies, anywhere inside it, is normal. Under Theorem 4.1.1 the redexes of a term are the detours of its proof, at the same places, and a step of reduction is the conversion of Section 3.3 that removes the detour.For proofs with \(\lor\) and \(\bot\) two further conversions are needed before a normal proof has the subformula property of Section 3.3: an elimination that follows a case analysis moves into its two branches, and one that follows an \(\mathsf{abort}\) is absorbed by it. The page's engines apply them. They are not among Lean's rules of computation.
If reducing is running, a normal term is a result, and the question is what a result can be.
Proposition 4.3.2 (a closed normal proof ends in an introduction). Let \(M\) be a closed normal term of the calculus of Definition 4.2.1 that has a type, that is, a proof with no open assumption and no detour. Then \(M\) is an abstraction, a pair or an injection, according as its type is an implication, a conjunction or a disjunction. No closed normal term has the type \(\bot\), or an atom.
The idea of the proof. Proceed by induction on the size of \(M\). Because \(M\) is closed, it cannot be a bare variable. Suppose \(M\) were an elimination destructing a principal subterm \(N\) (the function in an application, the pair inside a projection, or the scrutinee of case or abort). Being a subterm of \(M\), \(N\) would itself be a smaller closed normal typed term, so by the induction hypothesis \(N\) would have to end in an introduction matching its type. Placing \(M\)'s destructor directly around \(N\)'s constructor would make \(M\) a redex, contradicting that \(M\) is normal (or, if \(M\) is abort \(N\), would require an introduction of type \(\bot\), which does not exist). Thus \(M\) must be an introduction; and because neither \(\bot\) nor an atom has an introduction rule, no closed normal term can inhabit either type.
Add the normalization theorem (Section 3.3; for terms, the strong normalization of Section 2.4 extended to these types) and the proposition becomes a statement about running programs. Every closed term of type \(A \lor B\) computes to \(\mathsf{inl}\,M\) or to \(\mathsf{inr}\,M\), so from a proof of \(A \lor B\) a proof of \(A\) or a proof of \(B\) can be computed, and no computation ends in a proof of \(\bot\). These are the disjunction property and the consistency of intuitionistic logic (Corollary 3.3.4), read off terms; the first fails for classical logic, which proves \(p \lor \lnot p\) without proving either side. A normal proof is a value, and normalization is evaluation.Howard's Theorems 3 and 4: every closed irreducible term of a conjunctive type is a pair, and of a disjunctive type an injection. As logicians state it: "Every closed derivation in intuitionistic logic can be reduced to a derivation using an introduction rule in the last step" (P. Schroeder-Heister, "Proof-Theoretic Semantics", Stanford Encyclopedia of Philosophy, revision of 18 August 2023, Section 1.3). The disjunction property of intuitionistic propositional logic was observed by Gödel in 1932 (J. Moschovakis, "Intuitionistic Logic", Stanford Encyclopedia of Philosophy, revision of 16 December 2022, Section 4.2).
A step need not make the proof smaller. Where a lemma is used twice, removing the one detour copies the proof of the lemma, and the whole grows from 10 rules to 11; iterated, this is the growth that Section 3.4 measures on proofs and Section 2.4 on terms.
Howard's notes credit half of their motivation to "W. Tait's discovery of the close correspondence between cut elimination and reduction of λ-terms", and a survey of the subject places it deepest of three levels: propositions as types, proofs as programs, and then "for each way to simplify a proof there is a corresponding way to evaluate a program", which makes the whole "not merely a shallow bijection between propositions and types, but a true isomorphism preserving the deep structure of proofs and programs, simplification and evaluation".Howard, pp. 479–480, citing a paper of Tait's of 1965; Wadler, "Propositions as types", p. 1.
Lean can be asked to take the same steps. Read as data, with a pair type where the proof has a conjunction, the term of the figure reduces all the way. Read as a proof, it is the term that Section 3.7 put to the same command, which took one step there and stopped at the projections.
section
variable (p q r : Type) (hqr : q → r) (hp : p) (hpq : p → q)
#reduce (fun (h : p × (p → q)) => hqr (h.2 h.1)) (hp, hpq)
end
section
variable (p q r : Prop) (hqr : q → r) (hp : p) (hpq : p → q)
example : (fun (h : p ∧ (p → q)) => hqr (h.2 h.1)) ⟨hp, hpq⟩ = hqr (hpq hp) := rfl
end
hqr (hpq hp)
The stop of Section 3.7 is not a failure: #reduce looks inside a proof only when told to, and it never unfolds a theorem of the library, as the projections of a conjunction are. Lean's kernel never needs the remaining steps: the last line is accepted, and it would be accepted for any two proofs of r, because in Lean two proofs of one proposition are equal by definition, before any step is taken. Section 4.8 is about that decision.
In Proposition 4.3.2, the fact that a finished proof of \(A \lor B\) exhibits a proof of one side appeared as a theorem about one formal calculus; constructive mathematicians reached the same demand decades earlier by asking what a proof of a statement must be in the first place.
What a proof is
Theorem 4.1.1 says that a proof can be written as a program. An older and stronger reading says that this is what a proof is, and that the dictionary of Section 4.2 is not a translation of the connectives but their definition. Lean's core library takes it at its word.
Definition 4.4.1 (the explanation by proofs). What counts as a proof of a compound proposition is explained by what counts as a proof of its parts:
- a proof of \(A \land B\) is a proof of \(A\) together with a proof of \(B\);
- a proof of \(A \lor B\) is a proof of \(A\) or a proof of \(B\), together with the information which of the two it is;
- a proof of \(A \to B\) is a construction that turns any proof of \(A\) into a proof of \(B\);
- \(\bot\) has no proof, and a proof of \(\lnot A\) is a construction that turns any proof of \(A\) into a proof of \(\bot\);
- a proof of \(\forall x.\, A(x)\) is a construction that turns any element \(d\) of the domain into a proof of \(A(d)\);
- a proof of \(\exists x.\, A(x)\) is an element \(d\) of the domain together with a proof of \(A(d)\).The six clauses usually quoted are those of Troelstra and van Dalen, Constructivism in Mathematics (1988), p. 9, as given in M. van Atten, "The Development of Intuitionistic Logic", Stanford Encyclopedia of Philosophy (revision of 4 May 2022), Section 1.1; they are restated here. The name is Troelstra's, of 1977, and its K first stood for Kreisel (Section 1.2 of the entry, which prefers "explanation" to the usual "interpretation", a word that has come to mean the translation of one formal theory into another).
The clauses are named after Brouwer, Heyting and Kolmogorov, BHK for short. They say not when a proposition is true but what one must have in hand to assert it, and that changes what some assertions cost. To assert \(A \lor \lnot A\) one must have a proof of \(A\) or a refutation of it, so the excluded middle, asserted of every \(A\), is the claim that every problem can be decided. Brouwer's refusal of it in 1908 rests on that reading: the question of its validity was for him the question whether unsolvable mathematical problems are possible, as The painted rock tells in his own words. For finite systems he granted the principle, and added a footnote that a series on proof checkers should not pass over: there the investigation "can always be done by a machine or by a trained animal".L. E. J. Brouwer, "De onbetrouwbaarheid der logische principes", Tijdschrift voor Wijsbegeerte 2 (1908), pp. 152–158, at p. 156 and its footnote 10, in the translation of M. van Atten and G. Sundholm (arXiv:1511.01113, 2015), p. 29.
Brouwer rejected the notion of a proposition as something true or false and did not say what should replace it. Heyting did, in a lecture at Königsberg in September 1930.
We here distinguish between propositions [Aussagen] and assertions [Sätze]. An assertion is the affirmation of a proposition. A mathematical proposition expresses a certain expectation. For example, the proposition, “Euler’s constant \(C\) is rational”, expresses the expectation that we could find two integers \(a\) and \(b\) such that \(C = a / b\). Perhaps the word “intention”, coined by the phenomenologists, expresses even better what is meant here … The affirmation of a proposition means the fulfillment of an intention.
—A. Heyting, lecture at Königsberg, September 1930, printed in Erkenntnis 2 (1931). P. 113 of the printed lecture (pp. 106–115), in the translation printed in Benacerraf and Putnam (1983), pp. 58–59, as quoted in van Atten's entry, Section 5.1; the elision is the entry's. That Brouwer left the notion of proposition unreplaced is P. Martin-Löf's remark ("On the meanings of the logical constants and the justifications of the logical laws", Nordic Journal of Philosophical Logic 1(1), 1996, p. 33).
A proposition is something to be fulfilled, and to assert it is to have fulfilled it: in Lean's notation, a type p : Prop and a term h : p. Two years later Kolmogorov read the calculus of intuitionistic logic as a logic of problems and their solutions; among his examples of a problem is that of finding whole numbers with \(x^n + y^n = z^n\) and \(n > 2\). The clause for implication, the one with no counterpart in a truth table, was fixed by Heyting in a letter of October 1930: \(a \to b\) should refer to a proof procedure, "I possess a construction that derives from every proof of \(a\) a proof of \(b\)".A. Kolmogoroff, "Zur Deutung der intuitionistischen Logik", Mathematische Zeitschrift 35 (1932), pp. 58–65, as reported in van Atten's entry, Section 5.3; the example is quoted in A. Rodin, "Kolmogorov's calculus of problems and its legacy" (PhilSci-Archive 22316, 2023), p. 6. Heyting's letter to Freudenthal of 25 October 1930 is quoted in van Atten's translation in the entry, Section 5.1.
Could a program check a proof against these clauses? Not as they stand.
Remark 4.4.2 (an explanation, not a definition). The BHK clauses do not reduce proof to a simpler primitive. "Construction" is left informal, and the clauses for \(\to\) and \(\forall\) are circular: verifying semantically that a procedure \(F\) turns every possible proof of \(A\) into a proof of \(B\) would require surveying the open-ended totality of all proofs of \(A\), including proofs that might themselves invoke \(A \to B\). As a standard textbook objects, "the definition of a proof uses quantifiers twice (for ⇒ and ∀)", and the domain of inputs to an implication proof is hardly well understood. Howard hit this circle when formalizing what counts as a construction for \(A \to B\), and broke it the same way a proof checker does: instead of testing \(F\) on every hypothetical proof of \(A\), \(F\) "is assigned the type phi according to the way F is built up". Static type-checking replaces an impossible check over infinitely many inputs with a finite syntactic inspection of one term.J.-Y. Girard, Y. Lafont and P. Taylor, Proofs and Types (1989), Section 1.2.2, p. 6, and Howard's letter of 2014. One way of making the clauses exact for arithmetic is Kleene's realizability of 1945, in which a number that codes a program stands in the place of a proof; Martin-Löf (1996, p. 34) calls it "a nonstandard, or nonintended, interpretation of intuitionistic logic and arithmetic".
Whatever one makes of the explanation as philosophy, in Lean it is the letter of the definitions. Implication is not a connective with rules of its own: p → q is the type of the functions from proofs of p to proofs of q. The core library declares False as an inductive type with no constructor and defines Not a as a → False. Whoever checks what a Lean theorem says is reading these clauses. The last of the six makes a promise that can be tested.
Existence with a witness
Above every number there is a prime. By the last clause of Definition 4.4.1 a proof of that is, for each \(n\), a prime above \(n\) together with the proof that it is one; so a proof for all \(n\), read as a program, takes a number and returns a larger prime. The development of Euclid's theorem that runs through this series states the theorem three times, and a kernel can be asked to reduce all three.
terms "above n there is a prime": three terms of the running example at n = 5, each brought to weak head
normal form (→) by the kernel of this page; then its witness is run
the function nextPrime 5 : { p // 5 < p ∧ Prime p }
→ ⟨search Prime (factorial 5 + 1) (5 + 1), ⋯⟩ → 7 in 2,261 steps
its search is k prime? 6: no 7: yes
the proof exists_prime_gt 5 : ∃ p, 5 < p ∧ Prime p
→ ⟨minFac (factorial 5 + 1), ⋯⟩ → 11 in 15,514 steps
its search does d divide 121? ten tests from d = 2; the last, d = 11: yes
the kernel hands no number out of a proof (invalid projection): the witness is run by itself
the proof by exists_prime_gt_by_contradiction 5 : ∃ p, 5 < p ∧ Prime p
contradiction → Or.rec ⋯ ⋯ (Classical.em (∃ p, 5 < p ∧ Prime p))
stops after 54 steps at the axiom Classical.choice: no witness
other n the function reaches a prime at every n from 0 to 30; the proof's witness, minFac (n! + 1), stays within
the budget of 100,000 steps up to n = 6 (64,755); at n = 7 it takes 1,047,496 to reach 71 (counted once,
outside the page)
axioms under the three: none, none, 3; Lean 4.35.0 reports the same
(the live figure needs JavaScript; it loads a kernel of about 0.2 MB and 0.9 MB of exported declarations, and
checks the 397 declarations before it runs anything)
Only the data-level function nextPrime evaluates directly to a number inside Lean: it returns a subtype pair of a natural number and a proof, computing the number by testing candidates upward from \(n + 1\). That bounded search always terminates because it recurses on an explicit fuel counter; Euclid's argument supplies the proof that a prime appears before the fuel of \(n! + 1\) steps runs out. Neither proof of the Prop statement ∃ p, n < p ∧ Prime p allows a program to project out its number. Even so, inspecting the two proof terms from outside by reducing each to weak head normal form (unfolding definitions until the outermost constructor appears) exposes a sharp divide: the constructive proof exists_prime_gt reveals an explicit witness term, the least prime factor of \(n! + 1\), whereas the classical proof by contradiction halts at a non-computational axiom with no witness in sight.
def search (P : Nat → Prop) [DecidablePred P] : Nat → Nat → Nat
| 0, k => k
| fuel + 1, k => if P k then k else search P fuel (k + 1)
-- ...
theorem exists_prime_gt (n : Nat) : ∃ p, n < p ∧ Prime p :=
have hp : Prime (minFac (factorial n + 1)) := minFac_prime (two_le_factorial_succ n)
⟨minFac (factorial n + 1),
lt_of_prime_of_dvd hp (minFac_dvd _ (two_le_factorial_succ n)),
hp⟩
-- ...
def nextPrime (n : Nat) : { p // n < p ∧ Prime p } :=
⟨search Prime (factorial n + 1) (n + 1),
le_search (factorial n + 1) (n + 1),
have h₂ := two_le_factorial_succ n
have hp : Prime (minFac (factorial n + 1)) := minFac_prime h₂
search_spec (factorial n + 1) (n + 1) (minFac (factorial n + 1))
(lt_of_prime_of_dvd hp (minFac_dvd _ h₂))
(Nat.le_trans (le_of_dvd (Nat.succ_pos _) (minFac_dvd _ h₂)) (Nat.le_add_right _ _))
hp⟩
Both exists_prime_gt and nextPrime build a pair in angle brackets wrapping Euclid's argument, and their types differ only in writing ∃ p, … versus { p // … }. Constructed identically, they differ solely in whether callers may project the witness out into ordinary data or may only unpack it temporarily while proving another proposition whose conclusion no longer mentions the witness.
Definition 4.5.1 (weak and strong existence). A proof of \(\exists x.\, A(x)\) is introduced as a pair \(\langle t, M \rangle\) of a term \(t\) and a proof \(M\) of \(A(t)\). Existence is weak if such a proof can be used in one way only: from a proof of \(\exists x.\, A(x)\) and a proof of \(\forall x.\,(A(x) \to B)\), where \(x\) does not occur in \(B\), conclude \(B\); the detour is removed by handing \(t\) and \(M\) to the second proof. It is strong if there are also two projections: for a proof \(F\) of \(\exists x.\, A(x)\), \(\pi_1 F\) is the witness and \(\pi_2 F\) a proof of \(A(\pi_1 F)\).
The names and the distinction are Howard's, and he pinpointed why strong existence steps beyond ordinary first-order logic: in \(\pi_2 F : A(\pi_1 F)\), the formula \(A(\pi_1 F)\) plugs in a projection of a proof object \(F\), which, in his words, "takes us outside the formalism" of first-order arithmetic (where formulas plug in numeric terms only) into dependent types that can mention proofs (Section 5.2). Lean provides both forms in separate universes. Its ∃ (Exists in Prop) is weak existence, unpackable only when proving another proposition; its strong forms live in Type as Subtype ({ p // … }, pairing a value with a proof) and Sigma (pairing a value with dependent data). Sections 5.8 and 6.5 examine the boundary between them.
Even under weak existence, where no projection inside the language extracts the witness, does normalizing a constructive proof still exhibit one? In constructive arithmetic it does.
Theorem 4.5.2 (the witness is in the normal form). (i) In Heyting arithmetic, which has the axioms of Peano arithmetic (Section 3.5) and intuitionistic logic, formulated with typed terms for implication, conjunction, the universal quantifier and weak existence: every term reduces to a normal term, and a closed normal term whose type is a closed formula \(\exists y.\, A(y)\) is an introduction \(\langle \bar n, M \rangle\), a numeral with a closed normal proof of \(A(\bar n)\). (ii) Heyting arithmetic has the existence property: if \(\exists x.\, A(x)\) is a closed theorem, then \(A(t)\) is a theorem for some closed term \(t\).(i): Howard, Theorems 6 and 7 and Section 12, pp. 488–489, with normalization by the method of Tait of 1967, the reducibility of Section 2.4: "from an irreducible construction of → ∃yα(y) we get a numeral n and an irreducible construction of → α(n)". (ii): Kleene, 1945 and 1952, as stated in Moschovakis's entry, Section 4.2.
Part (i) extends Proposition 4.3.2 to quantifiers and arithmetic: normalizing a closed proof exposes a concrete numeral in its first slot, readable from outside the formal system even though weak existence provides no internal projection term. Theorem 4.5.2 is proved for Heyting arithmetic rather than for Lean's full type theory, so the figure tests Lean's exported terms directly by running them.
Example 4.5.3 (the prime above 5). All three declarations, elaborated by Lean 4.35.0 and exported together with their dependencies, are applied to \(n = 5\) and reduced inside the page by its JavaScript kernel (a separate implementation of Lean's checker in another language, written with the reference at hand) under a budget of 100,000 uncached kernel steps per run. For the subtype function, nextPrime 5 reduces to a pair whose first component, search Prime (factorial 5 + 1) (5 + 1), evaluates to the numeral 7 in 2,261 steps after testing 6 and 7, and across every \(n\) up to 30 the function stays at or below 16,443 steps. For the constructive proof, reducing exists_prime_gt 5 to weak head normal form yields ⟨minFac (factorial 5 + 1), ⋯⟩. If asked to project a Nat out of that proof term, the kernel refuses because exists_prime_gt 5 inhabits Prop; extracted from outside and run on its own, the witness minFac (factorial 5 + 1) evaluates in 15,514 steps to 11, the least prime factor of \(5! + 1 = 121\) (whereas nextPrime 5 found 7, the first prime above 5). That constructive witness stays within the 100,000-step budget up to \(n = 6\) (64,755 steps, finding 7 as the least factor of 721), and at \(n = 7\) takes 1,047,496 steps (counted outside the page) to reach 71. For the classical proof by contradiction, reduction halts after 54 steps at the axiom Classical.choice. ◁
That third declaration formalizes the textbook indirect proof of Euclid's theorem.
theorem exists_prime_gt_by_contradiction (n : Nat) : ∃ p, n < p ∧ Prime p :=
(Classical.em (∃ p, n < p ∧ Prime p)).elim id fun hnone =>
have ⟨p, hp, hdvd⟩ := exists_prime_factor (factorial n + 1) (two_le_factorial_succ n)
have hle : p ≤ n := Nat.le_of_not_lt fun hlt => hnone ⟨p, hlt, hp⟩
absurd hdvd (not_dvd_succ_of_dvd hp.1 (dvd_factorial (Nat.le_of_succ_le hp.1) hle))
Its first step asks the excluded middle whether a prime above \(n\) exists, and takes the two cases. A case analysis reduces when the thing analyzed becomes one of the two injections, and this one never does: in Lean's core library the excluded middle is a theorem derived from the axiom of choice (Section 7.3), and an axiom is a constant with a type and no rule of computation. Proposition 4.3.2 no longer holds: with a constant that has no rule, a closed normal term can be an elimination that waits on the constant forever. The proof is not thereby wrong, or empty: Section 4.6 says what it does lack.
Classical proofs compute by jumping
The proof by contradiction stopped at a classical law, and for those the dictionary has no term. For atoms \(A\) and \(B\) no closed term of Definition 4.2.1 has the type of Peirce's law, \(((A \to B) \to A) \to A\), which holds classically (Section 3.6); Howard's notes already remark that normalization shows it underivable. For two decades the correspondence stopped there, at constructive logic. Then a type was found for an operator that programmers already had.
source peirce = λf. callcc (λk. f k) its type: ((α → β) → α) → α, Peirce's law
10 * peirce (λk. 1 + k 2) the program, of type Nat
machine after 35 of 37 transitions: the jump
control the value 2, being returned
stack 1 + [·] thrown away by the jump
10 * [·] put back: the stack that κ1 holds
captured κ1 = 10 * [·], kept by callcc at transition 17
κ1 is applied to 2: what was waiting is dropped, the kept stack returns, the answer is 20
runs program transitions capture at jump at answer
10 * peirce (λk. 1 + k 2) 37 17 35 20
10 * peirce (λk. 3) 26 17 none 30
the excluded middle, by cases 35 6 24 107
1 + dne (λk. k 41) 31 17 29 42
1 + control (λk. 10) 15 12 none 10
(λc. c (λx. 5)) (callcc (λk. k)) 24 8 16 5
The two uses of peirce have one type and differ in what they do: one returns, one jumps.
Lean 4.35.0 has no callcc. There Peirce's law is a theorem, and
'peirce' depends on axioms: [propext, Classical.choice, Quot.sound]
(the live figure needs JavaScript; it loads no data)
When callcc runs at a point where the surrounding program expects a result of type \(A\), it snapshots the entire waiting computation (such as 10 * [·] in the figure) and hands that snapshot to its argument as a first-class escape function \(k\). If \(k\) is never called, evaluation returns normally; if \(k\) is later called with a value \(a : A\) deep inside another subexpression (such as 1 + k 2), the local work waiting there (1 + [·]) is discarded and execution jumps straight back to the saved snapshot 10 * [·] with \(a\). Because calling \(k(a)\) aborts its immediate surroundings without returning to them, \(k(a)\) can stand wherever any return type \(B\) is expected, giving \(k\) the type \(A \to B\) and callcc the exact type of Peirce's law, \(((A \to B) \to A) \to A\). Making "the rest of the computation" into a concrete object requires fixing an evaluation order and maintaining an explicit call stack.
Definition 4.6.1 (continuation, callcc). Run a program call by value (an argument is evaluated before the function is applied to it) on a machine that keeps, beside the term under evaluation, a stack of frames: what waits for the value of that term, the nearest first. That stack is the continuation of the term. Add to the calculus of Definition 4.2.1 a constant \(\mathsf{callcc}\) (for call-with-current-continuation, an operator of the programming language Scheme), and let the machine make of any stack \(S\) a value \(\kappa_S\), with two transitions. Capture: to evaluate \(\mathsf{callcc}\,V\) on the stack \(S\), apply \(V\) to \(\kappa_S\) on \(S\). Jump: to apply \(\kappa_S\) to a value \(W\) on any stack \(S^{\prime}\), discard \(S^{\prime}\) and return \(W\) to \(S\). The constant is typed by Peirce's law,
\[\mathsf{callcc} : ((A \to B) \to A) \to A ,\]in which the argument of type \(A \to B\) is the continuation: it expects an \(A\) and never returns, so any \(B\) will do.
Attaching a stack machine to an operator would be ad hoc unless typed classical proofs actually evaluate without getting stuck or looping forever; Griffin proved in 1990 that they do.
Theorem 4.6.2 (Griffin, 1990). Take the simply typed calculus with a type \(\bot\), evaluated call by value, and add operators typed as follows: \(\mathsf{abort}\,M : A\) for \(M : \bot\); \(\mathcal{C}(M) : A\) for \(M : \lnot\lnot A\); \(\mathsf{callcc}\,M : A\) for \(M : (A \to B) \to A\). (i) The typed terms correspond to the proofs of classical implicational logic in natural deduction, the three operators to ex falso (from \(\bot\), anything), double-negation elimination and Peirce's law. (ii) Every evaluation of a typed term built with \(\mathsf{abort}\) and \(\mathcal{C}\) is finite. (iii) The continuation-passing transform, which removes \(\mathcal{C}\) by giving every function the rest of the computation as one more argument, turns a classical proof of \(A\) into an intuitionistic proof of \(\lnot\lnot A^{\ast}\), for a translation \(A^{\ast}\) of \(A\).T. G. Griffin, "A formulae-as-types notion of control", Conference Record of the Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, 1990, pp. 47–58 (the author's copy): Sections 3 and 5 for (i); Section 7 for (ii), its Theorem 9, where a typed program \(M\) is run inside \(\mathcal{C}(\lambda k.\, k\,M)\), so that the rule for \(\mathcal{C}\) respects the types, and the question is reduced to the strong normalization of simply typed terms (Theorem 2.4.1 here); Theorems 5 and 6 for (iii): a term of type \(A\) is sent to one of type \((A^{\ast} \to o) \to o\), where \(o\) is a fixed type, \(t^{\ast} = t\) for an atom and \((A \to B)^{\ast} = A^{\ast} \to (B^{\ast} \to o) \to o\), and \(o\) is then taken to be \(\bot\). The paper writes K for \(\mathsf{callcc}\) and gives it the rule that a program \(E[\mathsf{K}(M)]\) continues as \(E[M\,(\lambda z.\,\mathsf{abort}\,(E[z]))]\), where \(E\) is the context that waits for the value: the stack of the definition. It adds that an operator computationally equivalent to K is defined from \(\mathcal{C}\), as \(\mathcal{C}(\lambda k.\, k\,(M\,k))\), and it treats call by name as well, with another translation. \(\mathcal{C}\) is the operator of Felleisen and his coauthors. That the transform of (iii) corresponds to the double-negation translations of Kolmogorov and Gödel was noted by C. Murthy (Wadler, p. 4).
Part (iii) is a double-negation translation like the one of Section 3.6, found a second time from the side of programs: a compiler's way of doing without jumps is a logician's way of doing without the excluded middle. The paper is also plain about what a classical type no longer promises.
The types of “classical programs” cannot be given the same operational interpretation as the types of “constructive programs.” A program M corresponding to a constructive proof of α → β takes inputs of type α to outputs of type β. This is no longer the case with classical programs since the evaluation of an expression need not return to the point of its evaluation but may “jump” to some other evaluation context. In the type system presented here, the distinction between a “returning expression” and a “jumping expression” cannot be made by inspecting an expression’s type. Thus, if M is a classical program of type α → β and N is a classical program of type α, we know only that if the application of M to N returns to the current control context, then it will return with a (classical) value of type β. Note that the evaluation of either M, N, or the application of M to N could result in a jump.
—Timothy G. Griffin, "A formulae-as-types notion of control" (1990). Section 3, p. 6 of the author's copy. An earlier section adds that once two parts of an application can each jump, "the result of MN will depend on which term is evaluated first": the calculus comes with a fixed order of evaluation, which is why it is run here on a machine and not by free reduction.
Writing peirce for λf. callcc (λk. f k), the two expressions 10 * peirce (λk. 1 + k 2) and 10 * peirce (λk. 3) share the same type Nat and return 20 and 30: the first invokes k 2 to abort 1 + [·] before the addition runs, and its type gives no sign that it jumped. Even the excluded middle \(A \lor \lnot A\) becomes a backtracking program, \(\mathsf{callcc}\,(\lambda k.\; \mathsf{inr}\,(\lambda a.\; k\,(\mathsf{inl}\,a)))\). Asked for \(A \lor \lnot A\), it initially bluffs by returning the right branch \(\mathsf{inr}(\dots)\) ("not \(A\)"), carrying a trapdoor function of type \(A \to \bot\); if the surrounding computation never constructs an \(a : A\), the bluff stands, and if the caller later produces a proof \(a : A\) and feeds it to the trapdoor, \(k\,(\mathsf{inl}\,a)\) rewinds the stack back to the original split and returns the left branch \(\mathsf{inl}\,a\) ("\(A\), witnessed by \(a\)") instead. Placed beside Example 4.2.2, it is the exact same term with the captured continuation \(k\) replacing the explicit refutation argument \(h\).
On the side of logic the same fact was known for arithmetic, and it answers what Section 4.5 left open for Euclid's statement.
Theorem 4.6.3 (what classical arithmetic computes). Let \(A(x, y)\) be a quantifier-free formula of arithmetic. If Peano arithmetic proves \(\forall x\, \exists y\, A(x, y)\), then so does Heyting arithmetic. The two theories have the same provably recursive functions, the computable functions that they prove total.Moschovakis's entry, Section 4.2, where the same is said for every \(A\) that Heyting arithmetic proves decidable. For Euclid's statement in particular, P. Dybjer and E. Palmgren name Friedman's translation as the way to turn a classical proof into an intuitionistic one ("Intuitionistic Type Theory", Stanford Encyclopedia of Philosophy, revision of 23 September 2024, Section 2.5).
Euclid's theorem has that exact \(\forall n\,\exists p\) shape with a decidable matrix in place of a quantifier-free one. Consequently, a classical arithmetic proof by contradiction is not computationally vacuous: metatheorems such as continuation-passing or Friedman's translation can transform the whole classical derivation into a constructive one, whose witness function is computable in Gödel's T (Theorem 2.5.3). What Section 4.5's exists_prime_gt_by_contradiction lacks is narrower: as written in Lean, the raw proof term itself does not reduce to a witness, because Lean includes no jump operator like \(\mathsf{callcc}\) and instead derives Peirce's law and indirect proof from non-computational axioms, whereas \(\lnot\lnot(p \lor \lnot p)\) needed none (Section 3.7).
theorem peirce (p q : Prop) : ((p → q) → p) → p :=
fun f => Classical.byContradiction
(fun (k : ¬p) => k (f (fun a => False.elim (k a))))
#print axioms peirce
'peirce' depends on axioms: [propext, Classical.choice, Quot.sound]
The term of peirce has the shape of the program in the figure, with Classical.byContradiction where the machine captured its stack. It type-checks, and it runs nowhere: a jump is what a rule of computation for the classical axioms would be, and Lean's axioms have none. What they are, and what each costs, is the subject of Section 7.
Two kinds of rule are now in play: those that compute, and axioms, which only have a type.
Meaning by rules of proof
What gives the rules their authority? The question is practical in Lean, which is handed the introductions of a new type and makes its elimination from them (Section 3.7 and Section 5.6). Natural deduction suggested an answer, to its inventor first: they need none from outside, because they say what the connectives mean. "The introductions represent, as it were, the ‘definitions’ of the symbols concerned," Gentzen wrote in 1935, "and the eliminations are no more, in the final analysis, than the consequences of these definitions."In M. E. Szabo's translation (The Collected Papers of Gerhard Gentzen, 1969, p. 80), as quoted in Schroeder-Heister's entry, Section 2.2.1. His example, in the sentences that follow, is implication.
An example may make clear what is meant: the formula A ⊃ B could be introduced when there was a derivation of B from the assumption formula A. If one then wants to use it again by eliminating the sign ⊃ (it can of course also be used to form longer formulas, such as (A ⊃ B) ∨ C, by or-introduction), one can do so precisely by concluding B at once from a proved A, for A ⊃ B records the existence of a derivation of B from A. Note well: no reference need be made here to a "contentual sense" of the sign ⊃.
—Gerhard Gentzen, "Untersuchungen über das logische Schließen" (1935), translated here from the German. Mathematische Zeitschrift 39, pp. 176–210, at p. 189 (part II, 5.13). It follows the remark on introductions directly. The highlighted sentences read, in the original: so kann man das gerade in der Weise tun, daß man aus einem bewiesenen \(\mathfrak{A}\) sofort \(\mathfrak{B}\) schließt, denn \(\mathfrak{A} \supset \mathfrak{B}\) dokumentiert ja das Bestehen einer Herleitung von \(\mathfrak{B}\) aus \(\mathfrak{A}\). Wohlgemerkt: Es braucht hierbei nicht auf einen „inhaltlichen Sinn“ des Zeichens \(\supset\) Bezug genommen zu werden.
This is Heyting's clause for implication (Section 4.4), reached from the calculus, with no appeal to a construction in anyone's mind. What makes "the consequences of these definitions" exact is the reduction of Section 4.3. An elimination applied to an introduction gives back what the introduction was given, a function its body and a pair its components, and no more. Prawitz made that the test of a pair of rules in 1965, as an inversion principle: the proofs of the premises of an elimination already contain a proof of its conclusion whenever the major premise has just been introduced.D. Prawitz, Natural Deduction (1965), p. 33, as quoted in Schroeder-Heister's entry, Section 2.2.1, which also describes tonk; that the connective is Prior's is from the paper of Kürbis cited below. Rules that fail the test define nothing.
Example 4.7.1 (tonk). Give a connective the introduction rule of disjunction, from \(A\) infer \(A\ \mathsf{tonk}\ B\), and an elimination rule of conjunction, from \(A\ \mathsf{tonk}\ B\) infer \(B\). Every \(B\) now follows from every \(A\). As terms, the introduction is a left injection and the elimination a second projection, and the detour \(\pi_2\,(\mathsf{inl}\,M)\) has nothing to reduce to: no proof of \(B\) was ever put in. With \(M = \lambda x{:}p.\, x\) this is a closed normal term of any type, \(\bot\) included, that is not an introduction. Proposition 4.3.2 fails, and the logic is inconsistent, for one reason: the connective has no reduction rule, hence no program. The connective is Prior's. ◁
The test became a definition of what a proof is. A closed proof that ends in an introduction, a canonical one, is valid if its immediate subproofs are; any other closed proof is valid if it reduces to a valid canonical proof; a proof with open assumptions is valid if all its closed instances are, with valid closed proofs put for the assumptions. This is the reducibility of Section 2.4, by which typed terms were shown to halt, read as a definition of meaning, and the encyclopedia's account gives the descent: the notion was "originally used to prove strong normalization". Dummett built a theory of meaning on it. Its "fundamental assumption" is that whoever has a valid argument for a compound statement can find one that ends with an introduction for its main connective. For closed proofs in pure logic that is Proposition 4.3.2 with normalization, a theorem; as a thesis about all of mathematics it is an assumption, and its price is that the logic so justified is the intuitionistic one.Schroeder-Heister's entry, Section 2.2.2 for validity (developed by Prawitz from 1971 on, out of the notion Tait used in 1967), Section 1.3 for the fundamental assumption, which it calls "a typical example of a philosophical re-interpretation of a technical proof-theoretic result", and Section 1.2 for classical logic, which in natural deduction "is only available by means of some rule of indirect proof". Dummett's wording, from The Logical Basis of Metaphysics (1991), p. 254, is quoted in N. Kürbis, "How fundamental is the fundamental assumption?", Teorema 31(2), 2012, pp. 5–19.
Martin-Löf, from whose type theory the logic of Lean descends (Section 5), put the position most compactly in lectures of 1983. To know a proposition is to know what counts as a direct proof of it, one that ends in an introduction; any other proof is a method that yields a direct one; and the reductions are what tie the two together.
In the course of my semantical explanation of the elimination rule for implication, I have performed certain transformations which are very much like an implication reduction in the sense of Prawitz. Indeed, I have explained the semantical role of this syntactical transformation. The place where it belongs in the meaning theory is precisely in the semantical explanation, or justification, of the elimination rule for implication. Similarly, the reduction rules for the other logical constants serve to explain the elimination rules associated with those constants. The key to seeing the relationship between the reduction rules and the semantical explanations of the elimination rules is this: to verify a proposition by putting a proof of yours that it is true into practice corresponds to reducing a natural deduction to introductory form and deleting the last inference. This takes for granted, as is in fact the case, that an introduction is an inference in which you conclude, from the possession of a verification of a proposition, that you know how to verify it.
—Per Martin-Löf, "On the meanings of the logical constants and the justifications of the logical laws" (1996). Nordic Journal of Philosophical Logic 1(1), pp. 11–60, the third of three lectures given in Siena in April 1983, p. 47. The sentence before the quotation paraphrases his "Truth of a proposition, evidence of a judgement, validity of a proof", Synthese 73 (1987), p. 413: "an indirect proof of a proposition is a method of proving it directly".
Both traditions answer a single question: what does someone possess by knowing a theorem? Along the constructive line from Heyting to Martin-Löf, knowing a theorem means possessing a method that reduces to a direct, canonical proof; for a classical mathematician, knowing a theorem means knowing an objective truth, with inference rules serving merely as instruments to establish it. Machine-checked mathematics poses that contrast sharply, because the proof checker itself guarantees only the most austere fact of all: some well-typed term inhabiting the target type was exhibited (Section 6). Mechanically, Lean's inductive types turn Gentzen's insight into an algorithm, generating each type's eliminator and computation rules directly from its constructors (Section 5.6), while Section 14 examines what a kernel verdict still leaves unsaid. Where Lean draws the line between constructive programs and classical proofs shows clearly in a short file.
In Lean
Lean keeps the first two levels of the correspondence to the letter. A proposition is a type, in a universe of its own; a proof is a term; and theorem is def. Here is the theorem of Section 4.1 in term mode and in tactic mode, with the program of the same shape, in a file that imports nothing.
theorem and_swap (p q : Prop) : p ∧ q → q ∧ p :=
fun h => ⟨h.2, h.1⟩
theorem and_swap' (p q : Prop) : p ∧ q → q ∧ p := by
intro h
constructor
· exact h.2
· exact h.1
def swap (α β : Type) : α × β → β × α :=
fun x => (x.2, x.1)
#check Prop
#print and_swap
#print and_swap'
#print swap
Prop : Type
theorem and_swap : ∀ (p q : Prop), p ∧ q → q ∧ p :=
fun p q h => ⟨h.right, h.left⟩
theorem and_swap' : ∀ (p q : Prop), p ∧ q → q ∧ p :=
fun p q h => ⟨h.right, h.left⟩
def swap : (α β : Type) → α × β → β × α :=
fun α β x => (x.snd, x.fst)
Lean 4.35.0 prints one term for the two theorems: tactics are a way of writing it (Section 10), and what the kernel receives is the function. The program swap has the shape of the proof, with Prod in Type where the proof has And in Prop. The next lines, in the same file after a blank line, show what theorem adds to def, and where proofs and programs part.
theorem five : Nat := 5
example : and_swap = and_swap' := rfl
example (p : Prop) (h₁ h₂ : p) : h₁ = h₂ := rfl
example : swap Nat Nat = fun x => x := rfl
CurryHoward.lean:18:0: error: type of theorem `five` is not a proposition
Nat
CurryHoward.lean:22:39: error: Type mismatch
rfl
has type
?m.4 = ?m.4
but is expected to have type
swap Nat Nat = fun x => x
The sole typing requirement that theorem adds beyond def is that the declared type must live in Prop; the elaborator checks this first (Section 9), and the kernel enforces it again when handed a raw declaration: (kernel) type of theorem 'asThm' is not a proposition. Next, Lean silently accepts both and_swap = and_swap' and h₁ = h₂ by rfl: even two completely arbitrary hypotheses h₁ and h₂ of a proposition p are definitionally equal. For data in Type, by contrast, Lean rightly rejects swap Nat Nat = fun x => x, because swapping a pair of numbers is not the identity function. Treating all proofs of a proposition as definitionally equal is called proof irrelevance, and it is where Lean deliberately sets the third level of Curry-Howard aside: when mathematical objects carry embedded proofs (such as a bounded number paired with a proof of k < n, or a real logarithm taking a proof of x > 0), two values should not differ merely because their attached inequality proofs were written differently. De Bruijn proposed this rule under that name for Automath in 1974.
This is a feature we might add to our languages if we are interested in classical mathematics only. The classical mathematician would find it even hard to understand what its counterpart "proof relevance" is. We give an example. If x is a real number, then P(x) stands for "proof of x > 0". Now we define "log" (the logarithm) in the context [x : real][y : P(x)], and if we want to talk about log 3 we have to write log(3,p), where p is some proof for 3 > 0. Now the p is relevant, and we have some trouble in saying that log(3,p) does not depend on p. This can be done by means of the general axioms for book equality, with the effect that in this case log(3,p1) and log(3,p2) are book-equal if both p1 and p2 are proofs 3 > 0.
Some time and some annoyance can be saved if we extend the language by proclaiming that proofs of one and the same proposition are always definitionally equal. This extra rule was called "proof irrelevance" in de Bruijn (1974b). We of course do not want to have the similar feature for type.
—N. G. de Bruijn, "A survey of the project AUTOMATH" (1980). Typescript AUT 072 of the Automath Archive, printed in the volume for Curry of 1980; the passage is the whole of its Section 24, p. 24. Book equality is equality as a proposition that one proves; definitional equality is the one a checker decides by computing (Section 5.4). An earlier section gives a reason for keeping a sort of propositions apart from the sort of types at all: a form of the double-negation axiom, written for types, would be a choice operator, and "if we want to do classical logic and do not want to accept the axiom of choice, we need some distinction" (Section 15).
Lean adopts proof irrelevance for Prop while keeping Type proof-relevant, just as de Bruijn's closing sentence asks, and pays the unavoidable logical price: once every two proofs of a proposition are definitionally equal, no function can be allowed to extract ordinary data from a proof in Prop. If an operation witness could extract the number from a proof of ∃ n : Nat, True, then since ⟨0, True.intro⟩ and ⟨1, True.intro⟩ are two proofs of the same proposition and hence definitionally equal, applying witness to both would make 0 definitionally equal to 1, collapsing the logic. Lean's core library states this consequence directly where it declares Exists.
/--
Existential quantification. If `p : α → Prop` is a predicate, then `∃ x : α, p x`
asserts that there is some `x` of type `α` such that `p x` holds.
-- ...
Because Lean has proof irrelevance, any two proofs of an existential are
definitionally equal. One consequence of this is that it is impossible to recover the
witness of an existential from the mere fact of its existence.
-- ...
-/
inductive Exists {α : Sort u} (p : α → Prop) : Prop where
/-- Existential introduction. If `a : α` and `h : p a`,
then `⟨a, h⟩` is a proof that `∃ x : α, p x`. -/
| intro (w : α) (h : p w) : Exists p
Three lines added at the end of the Euclid development, after open Euclid, put two of the questions of Section 4.5 to Lean itself, which answers after the file's own four lines on axioms.
#reduce (nextPrime 5).val
example : (nextPrime 5).val = 7 := rfl
def witness : Nat := (exists_prime_gt 5).1
7
Euclid.lean:243:21: error(lean.projNonPropFromProp): Invalid projection: Cannot project a value of non-propositional type
Nat
from the expression
exists_prime_gt 5
which has propositional type
∃ p, 5 < p ∧ Prime p
The function runs, and the kernel accepts by rfl that its value at 5 is 7. The proof hands nothing out. Nor does Lean show the witness inside it: #reduce (proofs := true) exists_prime_gt 5 answers exists_prime_gt 5, since that command unfolds no theorem (Section 3.7). The weak head normal forms of the two proofs in Section 4.5 are the page's kernel's, not Lean's printing.
Lean's own tutorial offers its readers two ways to take all this. On the constructive view a proposition specifies the data that proves it, and a term is that data. "Those not inclined to this ideology can view it, rather, as a simple coding trick": to each proposition a type that is empty if the proposition is false and has one element if it is true. Proof irrelevance is the second view built into the kernel, under which proofs "carry no information beyond the fact that p is true".Theorem Proving in Lean 4, chapter 3, "Propositions and Proofs", Section 3.1, as served on 1 December 2026. On either view the term is there: it is what the kernel checks, and where the statement is a function into a subtype, it is what runs.
A proposition is a type, a proof is a program of that type, and removing a detour from the proof is one step of running the program. Lean keeps the first two to the letter and sets the third aside for propositions: its kernel checks that the term has the type, and counts any two proofs of one proposition as equal without running either.
Two rows of the dictionary were borrowed in this part and not explained: for all and exists, where a type mentions a value. Euclid's statement needs both, and how a type comes to mention a value is the question of Section 5.