Algorithm Search⌘K

Theoremcore

Curry-Howard correspondence

Also called propositions as types, proofs as programs.

Simple types are the formulas of intuitionistic implicational logic, typed lambda terms are its natural deduction proofs, and beta reduction is the removal of detours from proofs.

The Curry-Howard correspondence says that a type is a logical formula and a program of that type is a proof of the formula. In its first and most precise form, the types of the simply typed lambda calculus are the formulas of intuitionistic logic with implication only, the typed terms are exactly the natural deduction proofs, and one step of beta reduction is one step of the normalization of proofs. Curry saw the match for combinators in the 1930s and 1950s, and Howard stated it for natural deduction in 1969. It is the reason that a type checker can be a proof checker.

Statement

Fix a set of atoms p,q,…p, q, \dots. Formulas, which are also types, are A::=p∣A→AA ::= p \mid A \to A. Natural deduction for intuitionistic implicational logic, NJ(→\to), proves judgments Γ⊢A\Gamma \vdash A, where Γ\Gamma lists labelled hypotheses x1:A1,…,xk:Akx_1{:}A_1, \dots, x_k{:}A_k. It has three rules: a hypothesis (Ax), implication introduction (→\toI), which discharges a hypothesis, and implication elimination (→\toE), which is modus ponens. A detour is a (→\toI) whose conclusion is at once the major premise of a (→\toE). Prawitz's reduction of a detour replaces each use of the discharged hypothesis by the proof of the minor premise. A derivation is normal if it has no detour. The terms are the Church-style terms xx, λx:A. t\lambda x{:}A.\,t and t ut\,u, typed by T-Var, T-Abs and T-App.

Theorem (Curry-Howard).

  1. Erasure. If Γ⊢t:A\Gamma \vdash t : A, then removing the terms from the typing derivation gives an NJ(→\to) derivation of Γ⊢A\Gamma \vdash A.
  2. Bijection. For each Γ\Gamma and AA, erasure is a bijection between the terms tt with Γ⊢t:A\Gamma \vdash t : A (up to renaming of bound variables) and the NJ(→\to) derivations of Γ⊢A\Gamma \vdash A (up to renaming of discharged labels). T-Var, T-Abs and T-App match (Ax), (→\toI) and (→\toE).
  3. Reduction. A beta-redex in tt is a detour in its derivation, and the beta step (λx:B. s) u→[x:=u] s(\lambda x{:}B.\,s)\,u \to [x := u]\,s is the reduction of that detour. So tt is beta-normal if and only if its derivation is normal.
  4. Normalization. Every sequence of detour reductions of an NJ(→\to) derivation is finite, and it ends in a normal derivation of the same judgment.

Corollary. A formula AA is provable in NJ(→\to) if and only if the type AA has a closed term.

Natural deduction normalization is the natural deduction form of Gentzen's cut elimination: a detour is a cut, an introduction followed at once by an elimination of the same connective.

In plain words

Read a type as a claim. The type "from A to B" is the claim "if A then B". A program of that type is a method that turns any evidence for A into evidence for B, and that is what a proof of "if A then B" is. Writing a function is proving an "if" claim; calling a function is using one. A program that builds a function only to call it at once is a proof with a pointless detour: it proves a general rule and then applies it once. Running that call is cutting out the detour. Because typed programs in this calculus always finish, every proof can be made direct. The match is with constructive logic, where a proof must give a method. Some classical laws, such as Peirce's law, have no program.

Proof

The proof file has the full proof of parts 1 to 3, and of part 4 from strong normalization of the STLC, which it cites.

  • Erasure is an induction on the typing derivation: each typing rule, with the terms removed, is a rule of NJ(→\to).
  • Bijection. Church-style terms have unique typing derivations, so erasure is a function. Its inverse reads a term off a derivation: a hypothesis labelled xx gives the variable xx, (→\toI) discharging x:Ax{:}A gives λx:A. ⋅\lambda x{:}A.\,\cdot, and (→\toE) gives application. Two inductions show the maps are inverse.
  • Reduction. A redex (λx:B. s) u(\lambda x{:}B.\,s)\,u is typed by T-App above T-Abs, which erases to a detour. The substitution lemma builds the typing of [x:=u] s[x := u]\,s by putting a copy of the derivation of uu at each occurrence of xx. That is exactly Prawitz's reduction.
  • Normalization. By part 3, detour reductions of a derivation are beta steps of its term. The STLC is strongly normalizing (Tait 1967; the proof is on the reducibility method page), so every such sequence is finite.

Example: a detour. The term (λf:p→p. f) (λx:p. x)(\lambda f{:}p{\to}p.\ f)\ (\lambda x{:}p.\ x) has type p→pp \to p. Its derivation first proves the general rule (p→p)→(p→p)(p \to p) \to (p \to p) by (→\toI), then applies it to the proof λx.x\lambda x.x of p→pp \to p by (→\toE). One beta step gives λx:p. x\lambda x{:}p.\ x, the direct proof by one (→\toI) over one hypothesis.

Example: Peirce's law has no proof. Let p≠qp \neq q. A closed normal term of type ((p→q)→p)→p((p \to q) \to p) \to p must be λf. N\lambda f.\,N with N:pN : p. An atom-typed normal term is a variable applied to arguments, and the only variable is ff, so N=f MN = f\,M with M:p→qM : p \to q. A head form with head ff has type (p→q)→p(p \to q) \to p or pp, so M=λx. PM = \lambda x.\,P with P:qP : q. Now the head of PP is ff or xx, and neither can produce qq. So there is no normal term, and by normalization no term at all. A depth-bounded search for long normal forms, run as a script, confirms this. The same search finds exactly one normal inhabitant of p→q→pp \to q \to p, namely λx.λy. x\lambda x.\lambda y.\,x (the combinator KK), and exactly one of (p→q→r)→(p→q)→p→r(p \to q \to r) \to (p \to q) \to p \to r, namely λx.λy.λz. x z (y z)\lambda x.\lambda y.\lambda z.\ x\,z\,(y\,z) (the combinator SS). Peirce's law holds in classical logic, so the correspondence is with intuitionistic logic.

Consequences

The theorem extends connective by connective. Each extension has the same three parts: formulas as types, proofs as terms, normalization as evaluation.

  • Products, sums and the empty type. Pairs A×BA \times B are conjunction, with pairing as ∧\wedgeI and projections as ∧\wedgeE. Tagged unions A+BA + B are disjunction, with case as ∨\veeE. The empty type is falsity ⊥\bot, and ¬A\neg A is A→⊥A \to \bot.
  • Hilbert systems and combinators. The types of K:A→B→AK : A \to B \to A and S:(A→B→C)→(A→B)→A→CS : (A \to B \to C) \to (A \to B) \to A \to C are the two axiom schemes of the Hilbert system for implication, and application is modus ponens. This was Curry's observation (combinatory logic). The translation of lambda terms to combinators is the deduction theorem.
  • Second-order logic. System F is second-order intuitionistic propositional logic: ∀α.A\forall\alpha.A is quantification over propositions. Normalization of System F implies the consistency of second-order arithmetic, so by Gödel's second incompleteness theorem Girard's normalization proof cannot be formalized inside second-order arithmetic.
  • Predicate logic. Dependent types are predicate logic: a dependent function type Πx:A. B(x)\Pi x{:}A.\,B(x) is ∀x. B(x)\forall x.\,B(x), and a dependent pair type is ∃\exists. Automath (de Bruijn, 1968), Martin-Löf type theory, Coq, Agda and Lean rest on this.
  • Classical logic. Griffin (1990) showed that call/cc can be given the type ((A→B)→A)→A((A \to B) \to A) \to A, which is Peirce's law, and the control operator CC the type ¬¬A→A\neg\neg A \to A. Classical proofs are programs with control effects. The double-negation translations of classical logic into intuitionistic logic are CPS translations.
  • Linear logic. Girard's linear logic corresponds to linear types, where each hypothesis is used exactly once.
  • Complexity. Provability in intuitionistic implicational logic is the inhabitation problem for simple types, which is PSPACE-complete (Statman 1979). Type checking a proof term is proof checking, which takes linear time for this calculus.

Tightness

  • Only intuitionistic logic. Peirce's law, the excluded middle A∨¬AA \vee \neg A and double negation elimination ¬¬A→A\neg\neg A \to A are classical tautologies with no closed term in the pure typed lambda calculus. Adding them needs control operators, as above.
  • Termination is needed for consistency. If the language has general recursion, for example fix:(A→A)→A\mathsf{fix} : (A \to A) \to A, then fix (λx:A. x)\mathsf{fix}\ (\lambda x{:}A.\ x) has every type AA, including ⊥\bot. The logic becomes inconsistent. This is why proof assistants require every function to terminate, and why ML or Haskell types are not sound as a logic.
  • The bijection needs Church style and labelled hypotheses. In Curry style, one untyped term such as λx. x\lambda x.\,x is the image of a derivation of p→pp \to p and of a derivation of (q→q)→q→q(q \to q) \to q \to q. If hypotheses are not labelled, the two terms λx.λy. x\lambda x.\lambda y.\,x and λx.λy. y\lambda x.\lambda y.\,y of type p→p→pp \to p \to p give the same unlabelled proof tree, although they are different programs.
  • Proofs are finer than provability. All the closed terms of type (p→p)→p→p(p \to p) \to p \to p prove the same formula, but they are the Church numerals 0,1,2,…0, 1, 2, \dots, an infinite set of different programs. The correspondence keeps the structure of proofs, not only provability.
Proof: The Curry-Howard correspondence between the simply typed lambda calculus and implicational natural deductionfull

This file proves parts 1 to 3 of the statement in full. Part 4 uses strong normalization of the simply typed lambda calculus, which is proved on the reducibility method page and in Girard, Lafont and Taylor, Proofs and Types, Chapter 6. Given that theorem, part 4 is proved here in full.

Setting

Formulas and types. Fix a set of atoms p,q,…p, q, \dots. Formulas, which are also the types, are A::=p∣A→AA ::= p \mid A \to A.

Natural deduction NJ(→\to). A derivation has open hypotheses, each with a label. We write Γ⊢A\Gamma \vdash A where Γ=x1:A1,…,xk:Ak\Gamma = x_1{:}A_1, \dots, x_k{:}A_k lists the labels of the open hypotheses with their formulas; the labels are distinct, and two labels may carry the same formula. The rules are:

  • (Ax) If x:A∈Γx{:}A \in \Gamma, then Γ⊢A\Gamma \vdash A by the hypothesis xx.
  • (→\toI) From a derivation of Γ,x:A⊢B\Gamma, x{:}A \vdash B, infer Γ⊢A→B\Gamma \vdash A \to B and discharge the hypotheses labelled xx.
  • (→\toE) From derivations of Γ⊢A→B\Gamma \vdash A \to B and Γ⊢A\Gamma \vdash A, infer Γ⊢B\Gamma \vdash B.

Two derivations are the same if they differ only in the names of discharged labels.

Terms. The Church-style terms are t::=x∣λx:A. t∣t tt ::= x \mid \lambda x{:}A.\,t \mid t\,t, up to renaming of bound variables, with the typing rules T-Var, T-Abs and T-App of the simply typed lambda calculus.

Detours. A detour in a derivation is an application of (→\toI) whose conclusion A→BA \to B is at once the major premise of (→\toE). Its reduction (Prawitz) takes the subderivation DD of Γ,x:A⊢B\Gamma, x{:}A \vdash B and the subderivation EE of Γ⊢A\Gamma \vdash A, and replaces each use of the hypothesis xx in DD by a copy of EE. The result is a derivation of Γ⊢B\Gamma \vdash B. A derivation is normal if it has no detour.

Part 1: erasure

Claim. If Γ⊢t:A\Gamma \vdash t : A, then the derivation of the typing judgment, with each term removed, is an NJ(→\to) derivation of Γ⊢A\Gamma \vdash A.

Proof. By induction on the typing derivation. T-Var with x:A∈Γx{:}A \in \Gamma becomes (Ax) with hypothesis xx. T-Abs, from Γ,x:A⊢t:B\Gamma, x{:}A \vdash t : B to Γ⊢λx:A. t:A→B\Gamma \vdash \lambda x{:}A.\,t : A \to B, becomes (→\toI) on the erased premise, discharging xx. T-App becomes (→\toE) on the two erased premises. Each rule has the same premises and conclusion once terms are removed, so the result is a derivation. □\square

Write ∣D∣\lvert \mathcal{D} \rvert for this erasure of a typing derivation D\mathcal{D}.

Part 2: the bijection

Claim. For each Γ\Gamma and AA, the map t↦∣Dt∣t \mapsto \lvert \mathcal{D}_t \rvert, where Dt\mathcal{D}_t is the typing derivation of Γ⊢t:A\Gamma \vdash t : A, is a bijection from the terms tt with Γ⊢t:A\Gamma \vdash t : A to the NJ(→\to) derivations of Γ⊢A\Gamma \vdash A.

Proof. First, the map is well defined: by the inversion lemma for T-Var, T-Abs and T-App (one rule per form of term, and in T-App the type of the argument is fixed by uniqueness of types), each typable Church term has exactly one typing derivation Dt\mathcal{D}_t.

Define the inverse tm\mathrm{tm} on derivations by induction:

  • tm\mathrm{tm} of the hypothesis xx is the variable xx.
  • tm\mathrm{tm} of (→\toI) discharging x:Ax{:}A above a derivation DD is λx:A. tm(D)\lambda x{:}A.\,\mathrm{tm}(D).
  • tm\mathrm{tm} of (→\toE) with premises D1D_1 and D2D_2 is tm(D1) tm(D2)\mathrm{tm}(D_1)\,\mathrm{tm}(D_2).

By induction on DD, Γ⊢tm(D):A\Gamma \vdash \mathrm{tm}(D) : A, because each clause is the matching typing rule. By induction on DD, ∣Dtm(D)∣=D\lvert \mathcal{D}_{\mathrm{tm}(D)} \rvert = D: each clause makes a term whose last typing rule erases to the last rule of DD, and the subterms come from the subderivations. By induction on tt, tm(∣Dt∣)=t\mathrm{tm}(\lvert \mathcal{D}_t \rvert) = t, for the same reason. Renaming a discharged label on one side is renaming a bound variable on the other, so the two notions of sameness match. □\square

Part 3: beta reduction is detour reduction

Claim. Let Γ⊢t:A\Gamma \vdash t : A. Then tt has a beta-redex if and only if ∣Dt∣\lvert \mathcal{D}_t \rvert has a detour. Contracting a redex (λx:B. s) u(\lambda x{:}B.\,s)\,u in tt gives the term whose derivation is the reduction of the matching detour. So tt is beta-normal if and only if its derivation is normal.

Proof. A subterm (λx:B. s) u(\lambda x{:}B.\,s)\,u is typed by T-App whose first premise is T-Abs, and this erases to (→\toE) whose major premise is (→\toI): a detour. Conversely, by Part 2, a detour is the image of a T-App whose function premise ends in T-Abs, and a term typed that way is a redex. So redexes and detours are in one-to-one correspondence, by position.

Let S\mathcal{S} be the derivation of Γ,x:B⊢s:C\Gamma, x{:}B \vdash s : C and U\mathcal{U} that of Γ⊢u:B\Gamma \vdash u : B. The substitution lemma (proved in full for this calculus on the type soundness page) builds the derivation of Γ⊢[x:=u] s:C\Gamma \vdash [x := u]\,s : C by induction on ss: at each occurrence of the variable xx it puts a copy of U\mathcal{U}, weakened by the bound variables of ss above that occurrence, and it keeps every other rule. After erasure this is exactly Prawitz's reduction: each use of the hypothesis xx in ∣S∣\lvert \mathcal{S} \rvert is replaced by a copy of ∣U∣\lvert \mathcal{U} \rvert. The context of the whole term is unchanged, because a redex inside tt sits under the same rules before and after the step. □\square

Part 4: normalization

Claim. Every NJ(→\to) derivation reduces, by any sequence of detour reductions, in finitely many steps, to a normal derivation of the same sequent.

Proof. Let DD be a derivation of Γ⊢A\Gamma \vdash A, and t=tm(D)t = \mathrm{tm}(D). By Part 3, a sequence of detour reductions from DD is the image of a sequence of beta steps from tt, of the same length. By strong normalization of the simply typed lambda calculus (Tait 1967), every such sequence from tt is finite. When no step is possible, the term is beta-normal, and by Part 3 the derivation is normal. Each step keeps the sequent, by Part 3 and preservation. □\square

Corollary: Peirce's law has no proof

Claim. For distinct atoms pp and qq, there is no closed term of type ((p→q)→p)→p((p \to q) \to p) \to p, so the formula has no NJ(→\to) proof.

Proof. By Parts 2 and 4 it is enough to show that there is no closed beta-normal term tt of this type. A beta-normal term has the form λx1…xk. y N1⋯Nm\lambda x_1 \dots x_k.\ y\,N_1 \cdots N_m with k,m≥0k, m \geq 0, a variable yy at the head and beta-normal NiN_i, because a term that is not an abstraction is a variable applied to arguments (otherwise its leftmost head would be an abstraction applied to an argument, a redex).

  • tt is closed, so it is not of the form y N1⋯Nmy\,N_1 \cdots N_m with yy free. So t=λf:(p→q)→p. Nt = \lambda f{:}(p \to q) \to p.\ N with f:(p→q)→p⊢N:pf{:}(p \to q) \to p \vdash N : p.
  • NN has the atom type pp, so it is not an abstraction, and N=y N1⋯NmN = y\,N_1 \cdots N_m with y=fy = f, the only variable. The type (p→q)→p(p \to q) \to p ends in pp after one argument, so N=f MN = f\,M with f⊢M:p→qf \vdash M : p \to q.
  • MM is an abstraction or a head form. A head form has head ff, and its type is (p→q)→p(p \to q) \to p with no argument or pp with one argument. Neither is p→qp \to q. So M=λx:p. PM = \lambda x{:}p.\ P with f,x:p⊢P:qf, x{:}p \vdash P : q.
  • PP has the atom type qq, so it is a head form with head ff or xx. A head form with head ff has type (p→q)→p(p \to q) \to p or pp, and a head form with head xx has type pp. None is qq, because p≠qp \neq q.

So no normal term exists, and no term exists. □\square

The same argument with p=qp = q finds the term λf. f (λx. x)\lambda f.\ f\,(\lambda x.\ x), so the atoms must be distinct. A depth-bounded search over long normal forms, run as a script, finds no inhabitant of Peirce's law, one of p→q→pp \to q \to p, and one of the type of SS.

History

Curry noticed in 1934 that the types of the basic combinators are axioms of implicational logic, and Curry and Feys (1958) stated the match between combinator types and Hilbert-style proofs. Tait (1965) connected cut elimination with the normalization of typed terms. Prawitz (1965) proved normalization for natural deduction. Howard wrote "The formulae-as-types notion of construction" in 1969 and circulated it as a manuscript. It gave the match for natural deduction, extended it to first-order arithmetic with dependent types, and was published in 1980 in the Festschrift for Curry. De Bruijn's Automath (from 1968) used the same idea for computer-checked mathematics, and Martin-Löf (1971 onward) made it the base of a constructive type theory. Girard (1972) and Reynolds (1974) found System F, Girard from second-order logic. Lambek added the third side, cartesian closed categories. Wadler (2015) gives a survey.

References

  1. William A. Howard, The formulae-as-types notion of construction, in J. P. Seldin and J. R. Hindley (eds.), To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, Academic Press, 1980, pages 479 to 490 (manuscript of 1969), Sections 1 and 2 (implicational formulas as types, terms as constructions, and the match of normalization of terms with normalization of proofs)
  2. Philip Wadler, Propositions as types, Communications of the ACM 58(12), 2015, pages 75 to 84, the whole survey (history, the natural deduction and lambda calculus side by side, and the extensions to other logics)
  3. Jean-Yves Girard, Yves Lafont and Paul Taylor, Proofs and Types, Cambridge University Press, 1989, Chapter 2 (natural deduction), Chapter 3 (the Curry-Howard isomorphism), Chapter 4 (the normalization theorem), Chapter 6 (strong normalization), Chapter 11 (System F and second-order logic)
  4. Morten Heine Sorensen and Pawel Urzyczyn, Lectures on the Curry-Howard Isomorphism, Elsevier, 2006, Chapter 4 (the isomorphism for implicational logic), Chapter 5 (proofs as combinators, Hilbert systems), Chapter 6 (classical logic and control operators)
  5. Haskell B. Curry and Robert Feys, Combinatory Logic, Volume I, North-Holland, 1958, the chapter on functionality (the types of the basic combinators are the axioms of implicational logic)
  6. Dag Prawitz, Natural Deduction: A Proof-Theoretical Study, Almqvist and Wiksell, 1965, the normalization theorem for intuitionistic natural deduction and the reduction of detours
  7. Richard Statman, Intuitionistic propositional logic is polynomial-space complete, Theoretical Computer Science 9(1), 1979, pages 67 to 72, the main theorem (provability in intuitionistic implicational logic, and so inhabitation of simple types, is PSPACE-complete)
  8. Timothy G. Griffin, A formulae-as-types notion of control, POPL 1990, the typing of call/cc and the control operator C with classical tautologies such as double negation elimination

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of correctness
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/PHJYVS/text.yaml