The bus to college is unreliable, and the first lecture tomorrow is at nine. Lying awake, you think it through:
The bus is cancelled. supposed
If the bus is cancelled, I walk. known
So I walk. from 2 and 1
If I walk, I miss the start of the lecture. known
So I miss the start of the lecture. from 4 and 3
So if the bus is cancelled,
I miss the start of the lecture. from 1–5; the supposition paid off
Look at line 1, and then at line 6. You haven’t found out whether the bus will be cancelled, and you can’t until the morning. You have found out what follows if it is, and line 6 says so without depending on line 1 at all. It is a rule, and you act on it: you set the alarm twenty minutes earlier.
That’s how people reason when they don’t know: suppose something, follow it to something you can check or act on, and keep the if when you’re done with the supposition. A doctor supposes an illness and looks for the symptom it would cause; an engineer supposes a bug and looks for the line it would have left in the log. A Hilbert proof has no line for “suppose”, so this most natural form of reasoning has no place in it at all.
Gerhard Gentzen made the same observation in 1934:1
The formalization of logical deduction, especially as it has been developed by Frege, Russell, and Hilbert, is rather far removed from the forms of deduction used in practice in mathematical proofs. Considerable formal advantages are achieved in return. In contrast, I intended first to set up a formal system which comes as close as possible to actual reasoning. The result was a “calculus of natural deduction”.
That calculus is the subject of this chapter.
3.1 Derivations in NJ
What is reasoning made of? Steps, each licensed by a logical rule. Line 3 of the argument about the bus takes one: from an if, and the thing it is conditional on, conclude the rest. We write a rule as a bar, as in Chapter 1: the premisses above it, the conclusion below, and the rule’s name on the right. Write for “the bus is cancelled”, for “I walk” and for “I miss the start of the lecture”. Line 3 is the first bar below; the second is the step from two facts to both of them at once.
The general rules put and for the particular claims.
Every connective gets two kinds of rule: one says how to prove a statement with that connective on the outside, and one says how to use such a statement once you have it:
to prove , prove both halves; to use it, take whichever half you need;
to prove , prove one side; to use it, handle both cases;
to prove , suppose , reach , and discharge the supposition; to use it, apply modus ponens;
nothing proves ; to use it, conclude anything at all.
So has rules of the second kind only. The first kind are called introduction rules and the second elimination rules, and the eliminations are, in a sense the end of the chapter makes more precise, consequences of the introductions: once you know how a statement is established, you know what may be got out of it.2 Figure 3.1 draws all of them, in two columns. These rules, with no axioms at all, make up the system called NJ. The N is for natürlich, natural; the J comes in Part 2.
Read one at a time, the rules of Figure 3.1 say these things in symbols. (E) is modus ponens, with the implication on the left, and (E) is proof by cases. (E) says that from an absurdity anything follows; no rule introduces , since there is no honest way to establish an absurdity.
The one subtlety is the square brackets. A formula in brackets above a column of dots is a supposition, and the rule discharges it: what was supposed above the bar is no longer assumed below it. To see what that means, take a proof you already know, that the square of an even number is even. Consider an arbitrary number , and suppose that it is even. Then for some , so , and is even. So if is even, then is even.
Now ask two questions of that last step.3 Is the supposition still needed? No: it has moved into the statement, which now holds of every , odd ones included. Is it wrong to keep it? No, but “ is even, provided is even” is the weaker claim the proof had reached one line earlier, before the supposition was paid off. A bar marked (I) is that last step, and the brackets are the provided crossed out.
How are the rules chained into proofs? Not as a list, the way a Hilbert proof is. To prove you prove and independently, each from what it needs, and a supposition made in one case of a proof by cases must not leak into the other. A list hides which lines rest on which; a tree shows it. So a proof here is a tree of formulas, held together by the rules: the conclusion of one bar becomes a premiss of the next, and the tree is read downwards:
the given facts and the suppositions sit at its leaves, at the top, written once each;
the thing proved is the single formula at the root;
the shape of the tree is the shape of the argument.
Here are lines 1 to 5 of the argument about the bus, with the supposition still in force:
Two bars, both (E). Three leaves: , which was supposed, and and , which were known. Nothing in the tree says which of the three was supposed and which was known, and the next step needs it to.
Line 6 pays off the supposition, and it is drawn as one more bar under the tree:
The new bar is (I): from a proof of that supposes , conclude and stop supposing. The square brackets round the leaf are a receipt. They say: this was supposed, and the bar marked 1 has paid for it. A leaf in brackets is discharged.
The two things known are open: they are not in brackets, no bar has paid for them, and the conclusion rests on them. So the tree establishes from and from nothing else. That’s exactly the rule the alarm clock was set by. Which leaves are open and which are discharged is what a tree’s conclusion rests on, and the brackets are where the tree keeps count.
Each rule joins trees already built into a bigger one. Draw each given tree as a triangle, its leaves along the top and its conclusion at the point, and the rules become pictures of trees being joined (Figure 3.2):
(E) and (I) set two trees side by side and draw one conclusion beneath them;
(I) takes a single tree, with or without among its leaves, and discharges every open in it; in the figure, a formula in brackets on a triangle’s top edge is one the new bar discharges;
(E) is the largest picture: a tree for , a tree from to and a tree from to combine into one tree for , discharging in the second and in the third.
Definition 3.1 (derivations). A derivation is a finite tree of formulas, drawn with its root at the bottom, in which some leaves are marked as discharged. Its conclusion is the formula at its root. The derivations are defined inductively:
(hypothesis) for every formula , the one-node tree is a derivation, with conclusion , and its leaf is not discharged;
(rule) suppose are derivations whose conclusions are, in order, the premisses of an instance of a rule in Figure 3.1 (for (I) and (E), the formulas under the dots). Then the tree that sets them side by side above a bar labelled with the rule, with the rule’s conclusion beneath it, is a derivation with that conclusion (Figure 3.2). In it,
an (I) bar concluding marks as discharged every leaf above it that is not discharged already,
an (E) bar on marks as discharged, in the same way, the leaves in its second premiss and the leaves in its third,
no other bar discharges anything;
nothing else is a derivation.
In words: a derivation is a tree built by the rules, and its brackets say which leaves a bar below has paid for. The definition is inductive, like that of the combinator terms, so it comes with a principle of proof. To show that every derivation has a property, it is enough to show it for the one-node trees, and to show that each rule, applied to derivations with the property, builds one with it. This is rule induction.
Negation needs no rules of its own. As in Chapter 2, abbreviates , so the rules for cover it: to prove , suppose and reach ; to use it, put it beside and get .
The numbers on the brackets and bars aren’t part of the definition, which says exactly which leaves each bar discharges and needs no labels. They appear in practice because a drawn tree may contain several discharging bars, and the reader has to see which receipt belongs to which.4
Example 3.2 (Baker: a double charge). Baker works on the payments service of an online shop, and at ten past ten a support ticket lands in her queue: a customer has been charged twice for one order. She doesn’t know why. She has two things to go on. The runbook says that when an attempt to charge a card times out, the app retries it, and that a retry goes to the card network as a fresh charge. The order record says the customer paid at nine fifty-two. So she reasons:
The first attempt timed out. supposed
If an attempt times out, the app retries it. runbook
So the app retried. from 2 and 1
If the app retries, the card is charged a second time. runbook
So the card was charged twice. from 4 and 3
So if the first attempt timed out,
the card was charged twice. from 1–5; the supposition paid off
She files line 6 in the runbook as a rule and goes to look for a timeout in the gateway’s log.
With for “the first attempt timed out”, for “the app retried” and for “the card was charged twice”, her reasoning is this tree:
It is a derivation. Each leaf is a one-node tree, by the first clause of Definition 3.1. The two (E) bars and the (I) bar come by the second, and the (I) bar marks the leaf as discharged.
What, then, does a derivation establish? Its conclusion, from the leaves it has not discharged. Those leaves get a name.
Definition 3.3 (open hypotheses). The open hypotheses of a derivation are the formulas at its leaves that are not marked as discharged. We write for the set of them.
Since derivations are defined inductively, the same set can be computed by recursion on the last rule:
where is the one subderivation of a one-premiss rule, , the two of a two-premiss rule, and , , those of (E), left to right. Only two lines take something away: the (I) and (E) lines, for the two rules that discharge.
Definition 3.4 (consequence). We write , and say that is derivable from in NJ, or an NJ-consequence of , when there is a derivation whose conclusion is and whose open hypotheses are among , . Such a derivation witnesses .
The tree of the bus and the lecture, with its discharge, witnesses , and the same tree without its last bar witnesses . The definition asks for a subset, not the whole of : a derivation may use fewer hypotheses than offers, but never more. The one-node tree has , so it witnesses as well as ; the is on offer and never used.
Example 3.5 (Baker, cont’d: the rule she filed). Compute the open hypotheses of Baker’s tree in Example 3.2, from the leaves down. The three leaves give , and , by the first line of Definition 3.3. The upper (E) bar takes the union of the last two, , and the lower one adds . The (I) bar takes away, leaving .
So the tree witnesses : the rule rests on the runbook and on nothing Baker supposed. Without its last bar, the tree witnesses .
Example 3.6 (). The smallest proof there is, . In the Hilbert system it takes five lines (Lemma 2.7), the first of which nobody would write unprompted:
| Line | Formula | Justification |
|---|---|---|
| no hypotheses | ||
| 1 | (II) | |
| 2 | (I) | |
| 3 | MP 1, 2 | |
| 4 | (I) | |
| 5 | MP 3, 4 |
In NJ it is one leaf and one bar:
The leaf has by the first line of Definition 3.3, and the bar takes away by its (I) line, leaving . So the tree witnesses : it depends on nothing at all. That’s what a theorem is.
Example 3.7 (commutativity of ). Swap the two halves of a conjunction. In the Hilbert system, from the hypothesis , it takes eight lines:
| Line | Formula | Justification |
|---|---|---|
| 1 | hypothesis | |
| 2 | (snd) | |
| 3 | MP 2, 1 | |
| 4 | (fst) | |
| 5 | MP 4, 1 | |
| 6 | (pair) | |
| 7 | MP 6, 3 | |
| 8 | MP 7, 5 |
In NJ, three bars, one for each step of the argument:
Both leaves are , so , and the tree witnesses . Now put one more bar under it, supposing and discharging it:
The supposition appears at two leaves, because it was used twice. The (I) line of Definition 3.3 removes both at once: , and the tree witnesses . The Hilbert system gets there from the eight lines only through the Deduction Theorem, which roughly triples them.
Example 3.8 (Baker, cont’d: proof by cases). At half past ten the app’s log says that the gateway answered the second attempt, and the entry is truncated: the answer was a decline or an approval, and the log doesn’t say which. The runbook says that an attempt the gateway has answered, either way, is written to the ledger. With for “the gateway declined”, for “the gateway approved”, and for “the attempt is in the ledger”:
This is proof by cases, (E), and here the bracket notation does something no other rule does: one bar discharges a different formula in each branch. : three things the log and the runbook said. The tree witnesses , and Baker goes to the ledger without ever learning which it was.
Each supposition is in force only in its own branch, under its own number, and the disjunction in the first premiss stays open.
The (I) line of Definition 3.3 removes from a set, and three things follow from reading it literally.
Multiple discharge. Every open leaf labelled goes at once. A supposition used three times sits at three leaves, and one bar discharges all three.
Vacuous discharge. When was never there, is just : the bar discharges nothing, and the tree is still a derivation.
Which bar takes a leaf. A leaf is discharged by the first bar below it, on its path to the root, that discharges its formula from the part of the tree the leaf stands in: an (I) bar whose antecedent it is, or an (E) bar whose second premiss it stands in and whose left side it is, or whose third premiss and right side. A bar further down finds that leaf already discharged, though it may still take other copies of the same formula.
An (E) bar does the same in each branch separately: leaves the second premiss and the third, and nothing in the first premiss is discharged.5
A discharge cannot be forgotten. The brackets record what Definition 3.3 computes: leave them off a leaf that a bar below it takes, and the result is not a different derivation with more open hypotheses but the same derivation drawn wrongly.
Example 3.9 (which bar takes the leaf?). Suppose and discharge it twice:
Both bars discharge , and there is one leaf to share between them. The (I) line of Definition 3.3 settles it. The bar marked 1 removes every open from , so when the bar marked 2 comes, no open is left: it discharges vacuously, and the leaf carries the number 1. The tree witnesses . A bar can be vacuous even though its formula stands at a leaf above it, because an earlier bar took that leaf.
Example 3.10 (vacuous discharge). A tree that looks as if it ought to be wrong:
The last bar concludes by (I). The rule asks only that the subtree above it conclude , which it does, and it discharges , of which there is no leaf. So this is a derivation, by a vacuous discharge, and its is still : it witnesses , which is right: to prove “if then ” it is enough to have .
A tree that is not a derivation has a bar whose premisses do not have the shape its rule requires: a bar labelled E under and , say, or I with one premiss. The definition refuses those by having no rule for them, and the clerk refuses them by failing to match a shape.
Example 3.11 (discharging in one branch). Two small trees. In the first, both cases suppose the same formula:
Each branch is a single leaf: the one-node tree is a tree from to , and once the bar discharges it, it leaves nothing open. The two suppositions are both , but they are discharged separately, one per branch, under the numbers 2 and 3, and the tree witnesses .
In the second, the same letter has two fates:
The second premiss is the leaf , discharged. The third premiss has to be a tree from to , and the one-node tree is one: it uses no , so discharge 2 is vacuous, and its leaf is not discharged, because the (E) line removes only from the second premiss. So , and the tree witnesses . That claim has a one-leaf derivation too; the point is the bookkeeping.
So one (E) bar can discharge properly in one branch and vacuously in the other, and a formula discharged in one branch may stand open in the other: brackets on one leaf say nothing about another.
Every tree can be checked in the same four steps, and none needs any understanding of what the letters mean.
Every bar has premisses of the shape its rule requires.
Every bracket carries a number, and the bar with that number is the first bar below the leaf, on its path to the root, that discharges its formula from the part of the tree the leaf stands in.
An (I) bar discharges every open copy of its formula above it, and every such copy carries its number; it is vacuous only if there is none. An (E) bar discharges the left side in its second premiss and the right side in its third, and nothing in its first.
The leaves left without brackets are the open hypotheses. The tree witnesses for every that contains them.
That’s the clerk’s job again, done on a tree instead of a list.
One last tree, to read aloud rather than check. It proves :
Suppose . Suppose as well , which is ; by modus ponens the two give . So the second supposition can’t stand: discharge it, concluding , which is . Now discharge the first: if , then . Nothing is left open, so the tree witnesses .
The converse, , has no derivation at all, though nothing in the rules looks as if it should forbid one. Exercise 3.8 proves this with the tools of §3.6. Yet if is read as true or false, is true either way. There is no conflict here: says what the rules derive, not what is true, and these are different questions. How they are related is the business of Part 2.
Remark (two trees that look alike).
The first is (I), since is : suppose , reach an absurdity, conclude that fails. The second is proof by contradiction as you were taught it: suppose the opposite, reach an absurdity, conclude the thing itself. It looks like the first with the moved, and it is not a rule of this chapter. Read with (I), its upper part proves , not , and nothing here gets from to (Exercise 3.8). Part 2 says what changes when you allow it.6
3.2 Equivalence with the Hilbert system
NJ has no axioms and nine rules; the Hilbert system HJ has nine schemas and one rule. Do they prove the same things? They do, and the way to see it is to read each axiom of HJ as a rule.
Take the schema (pair), : given , and then , you may have . An axiom is a one-line proof, so for every at all. The Deduction Theorem (Theorem 2.12) says that
where is short for . Apply it to the axiom, with for , and then once more:
The arrows have come out of the formula and gone above the line, among the hypotheses.
Now suppose both halves have been proved, and . By transitivity (Proposition 2.9) a hypothesis you can prove may be replaced by its proof. Splice each proof in for its hypothesis, and what is left is
The axiom has become a fact with two conditions: a rule, in the sense in which modus ponens is a rule, something you do rather than something you are told. Every schema can be read this way, and here is the whole list. It starts with the three facts that are not readings of axioms: reflexivity, modus ponens and the Deduction Theorem itself.
Proposition 3.12 (derived rules). For all sets of formulas and all formulas , , , in the Hilbert system:
if then ; (reflexivity)
if and then ; (modus ponens)
if then ; (the Deduction Theorem)
if and then ; (pair)
if then ; (fst)
if then ; (snd)
if then ; (left)
if then ; (right)
if , and , and , then ; (either)
if then ; (absurd)
if then ; (I)
if and then . (II)
Proof. Each item says that from Hilbert proofs of some formulas we can build a Hilbert proof of another. We give the building instructions, item by item.
Item 1. A hypothesis is a one-line proof of itself.
Item 2. Write the proof of , write the proof of below it, and add the line , by modus ponens on their two last lines.
Item 3. This is the Deduction Theorem (Theorem 2.12), read from left to right.
Items 4–8 and 10. These are built in the same way: write the given proof or proofs, then the axiom with the same name, then one modus ponens for each given proof. Item 5, for instance, follows the proof of with two lines:
Item 4 uses (pair), , and needs two modus ponens, one for each of its two given proofs. Items 6, 7, 8 and 10 use (snd), (left), (right) and (absurd), with one each.
Item 9. First turn the two branches into implications. By the Deduction Theorem, gives , and gives . Write these two proofs and the proof of , then the axiom
and use modus ponens three times, once for each of the three proofs.
Item 11. For the first half, write the proof of , then the axiom (I), , and use modus ponens once. For the second, write the two given proofs, then the axiom (II), , and use modus ponens twice.
□
Read for what they do to formulas, items 2 to 10 are the rules of NJ:
item 2 is (E), and item 3, the Deduction Theorem, is (I);
item 4 is (I), and items 5 and 6 are (E);
items 7 and 8 are (I), and item 9 is (E);
item 10 is (E).
Item 11 is the exception. It says that the axioms (I) and (II), read as rules, follow from modus ponens and the Deduction Theorem.
So in the Hilbert system the rules of NJ are theorems about proofs, each paid for with an axiom and, for the two that discharge, with the Deduction Theorem’s construction. In NJ they are the proofs. The proposition is half of the equivalence; the other half is to draw each axiom as a tree.
Lemma 3.13 (the axioms as trees). Every instance of each of the nine schemas of HJ has a derivation in NJ with no open hypotheses.
Proof. Every schema is an implication, and the recipe is the same each time: suppose the antecedents, reach the consequent with the rules, and discharge the suppositions in reverse order.
For (I), suppose and suppose . The conclusion is already there, since it was supposed. Discharge , then :
The bar marked 2 discharges , and there is no leaf anywhere in the tree. The definition permits this, since is just . To prove “if then ” it is enough to prove , and a supposition you never used can still be paid off. In the instance where is , the bar marked 2 takes the leaf, since it is the first bar below the leaf that discharges its formula, and the bar marked 1 is the vacuous one; either way .
For (II) there are three suppositions and three discharges, and this is the first tree in which the numbers earn their keep:
The supposition is used twice and discharged once, by the bar marked 3.
The other schemas follow the same recipe. Here are (pair), (snd) and (right):
The trees for (fst) and (left) are their mirror images, and (absurd) and (either) are Exercise 3.2.
One caution about the numbers. They assume that , and name different formulas. In an instance where two of them coincide, a leaf may belong to an earlier bar than its number says, since a leaf goes to the first bar below it that discharges its formula, but the open hypotheses are either way. □
Theorem 3.14 (equivalence with the Hilbert system). For every set of formulas and every formula built from letters and with , and ,
In words: the two systems prove the same things from the same hypotheses.
Proof. Each direction turns one kind of proof into the other. From right to left we go down a Hilbert proof one line at a time and build a tree for each line, as the proof of the Deduction Theorem built a new proof for each line. From left to right we take a tree apart at its last bar.
Right to left. Let be a Hilbert proof of from , so that is . For each from to , write for the claim . We prove for every by induction on , and the theorem is . So let , and suppose, as the induction hypothesis, that holds for every : a tree with open hypotheses in has already been built for each line above line . (When there are no lines above, and line 1 is a hypothesis or an axiom; the first two cases below use no earlier lines.) Line is justified in one of three ways.
A hypothesis. Then . The one-node tree has , which is a subset of .
An axiom. By Lemma 3.13, has a derivation with no open hypotheses, and is a subset of .
Modus ponens. Then there are earlier lines and such that is the formula . By the induction hypothesis both have trees with open hypotheses in . Put the two trees side by side and draw one (E) bar under them. The new tree concludes , and its open hypotheses are those of the two trees together, still in . In the bar notation of Chapter 1:
Left to right. Here we count bars. For each , write for the claim: whenever a derivation with bars has conclusion and open hypotheses , then . We prove for every by induction on . This is enough: if , some derivation of has open hypotheses , so , and monotonicity (Proposition 2.9) gives .
Base case, . A derivation with no bars is a single node , with , and because a hypothesis is a one-line proof.
Inductive step. Let , and suppose for every . Take a derivation with bars and look at its last bar. Each derivation standing above that bar has fewer than bars, so the induction hypothesis applies to it. There is one case for each rule.
(E). The derivations above the bar conclude and , with open hypotheses and , and the whole tree has . By the induction hypothesis and . Monotonicity puts both on the common set , and modus ponens finishes:
(I), (E), (I), (E). The same, with the item of Proposition 3.12 for the rule in place of modus ponens. For (I), for instance, and give by monotonicity and item 4.
(I). The derivation above the bar concludes with open hypotheses , and the whole tree concludes with open hypotheses . The set may or may not contain . Monotonicity puts in, whether or not it was there, and the Deduction Theorem takes it out again:
(E). The derivations above the bar conclude , and , with open hypotheses , and . The whole tree concludes , with open hypotheses
By the induction hypothesis and monotonicity, , and . Proof by cases, item 9 of Proposition 3.12, gives .
In every case the hypotheses on the left of are exactly the open hypotheses that Definition 3.3 computes: the brackets on a tree keep track of the turnstile. □
From here on we write , and would always do as well. Nothing proved about HJ has to be proved again, and nothing in this chapter will ever cite an axiom.
3.3 Folding up proofs
We now want to analyse proofs: to compare them, transform them, and ask when two of them are really the same. Trees are hard to hold in the head, and harder to compute with, so we fold them up into a notation, a single expression that records how the tree was built, rule by rule. Each derivation will be represented by a term.
A one-node derivation of is a hypothesis: give it a name, say , and write , read “ is a proof of ”. The name represents the derivation.
Every other derivation is built from smaller ones by a rule, so it is enough to say how each rule builds the term for the new tree from the terms for the trees it joins. Draw a derivation as a triangle, as in Figure 3.2, with its name inside and its conclusion at the point. We write when the term represents a derivation of , and an equation with on the left and a triangle on the right says that represents the derivation drawn in the triangle. If is a derivation of represented by , and a derivation of represented by , then (E) joins them into a derivation of , and it is represented by , the first applied to the second:
A proof of behaves like a function: give it a proof of , and it gives back a proof of .
The question is how to represent discharge, which (I) needs. That rule takes a derivation of , represented by , and discharges the hypotheses in it. Suppose those hypotheses are all named . The new derivation, extended by a bar that discharges them, is represented by :
The binds the name . Below the bar the supposition has been paid off, and outside the the name means nothing, just as a function’s parameter means nothing outside its body. So is the function that takes a proof of and returns the proof of that builds from it. The notation is older than this use of it, and the History at the end of the chapter says where it came from.
The term records the rule used at each bar, and the rules come in two kinds. An introduction rule builds a proof of a connective, and the term it gives is a constructor; an elimination rule takes such a proof apart to use it, and the term it gives is a destructor. So is the constructor for , and application is its destructor.
The other connectives follow the same pattern. (I) joins a derivation of , represented by , and a derivation of , represented by , into a derivation of , represented by the pair , so pairing is the constructor for ; (E) takes a half back out, with the destructors and :
We apologise for and , which look alike and mean different things: juxtaposition is application, and brackets with a comma make a pair. Both notations are standard, and we keep them.
A derivation that ends in (I) is represented by the term of its premiss, with a tag that says which side was proved; the tags and are the constructors for :
How is a proof by cases folded? As a pattern match:
case M:
Left x => P
Right y => Q
When turns out to be of some value, call that value and run ; if it turns out to be of some value, call that value and run . So the on runs with for , and never looks at .
In the triangles, the two branches are derivations and of the same formula , represented by and , and the suppositions they discharge are named and . Written with the branches between braces and a bar between them, the pattern match is the destructor for , and it represents the whole (E) derivation:
Each branch’s name is in force only in its own branch, as each case’s supposition is.
There is no introduction rule for , so it has no constructor: nothing builds a . Its destructor is , since if you ever have a you may conclude anything, which is what absurd :: Void -> a says:
In the language of constructors and destructors, the rules of NJ are precisely the rules of Figure 3.3. Write beside each formula the name of its proof, and collect the names in force at each point, with their formulas, into a list , the context; then says that is a proof of from the named hypotheses in . A tree whose every node is such a judgement is NJ in sequent style: the hypotheses available at each point are written at that point, rather than read off the leaves. A hypothesis becomes (var), which looks its name up in the context. Each introduction rule becomes the rule for its constructor and each elimination rule the rule for its destructor: (abs) is (I) and (app) is (E), and the rules below the dotted line, for pairs, tags, and , are those of the other connectives. This is the simply typed -calculus, and §3.4 says what it is good for.
Remark (product and sum types). Many books, and most writing about programming languages, write the type of pairs as , a product type, and the type of tagged values as , a sum type, with rules named (I), (E) and so on. These notes keep the logical signs throughout, since the types are the formulas. The History says where the other notation comes from.
Theorem 3.15 (Curry–Howard). Folding is a one-to-one correspondence between the derivations of NJ, with a name written on each hypothesis as in this section, and the typings by the rules of Figure 3.3.
(Erasure.) Take a typing of and delete every term, keeping the names on the hypotheses:
(var) becomes a hypothesis;
(app) an E bar;
(abs) an I bar discharging the hypotheses with the variable’s name;
each rule for , and the NJ rule of the same name.
The result is a derivation of whose open hypotheses are among the formulas declared in , a set we write .
(Decoration, the folding of this section.) Take a derivation of , with a name on each hypothesis, and write terms from the leaves down:
a variable at each leaf;
an application at each E;
a on the discharged name at each I;
the matching constructor or destructor at each other bar.
The result is a typing of for some term , with declaring the open hypotheses.
Each undoes the other. In one line: for some term if and only if .
Proof. Put Figure 3.3 beside Figure 3.1. Each typing rule is the NJ rule of the same name with a term written beside every formula: the premisses, the conclusion, and what each rule takes out of the context or out of are otherwise identical. Both constructions use this match, one rule at a time.
For (i) we go by induction on the number of rules in the typing. Look at its last rule. The typings above it have fewer rules, so by the induction hypothesis each erases to a derivation of its formula with open hypotheses among those declared in its context. Draw the matching NJ bar under these derivations. Where the typing rule removes from the context, as (abs) does, the NJ bar discharges the hypotheses named , so the open hypotheses of the new derivation are again among those declared.
For (ii) we go by induction on the number of bars in the derivation, in the same way: decorate the derivations above the last bar, which have fewer bars, and then write the term that the matching typing rule prescribes.
Each construction undoes the other. Decorating a derivation and then erasing the terms gives back the derivation, and erasing a typing and then decorating it gives back the typing: each rule of one system matches exactly one rule of the other, so at every step there is only one way to go.
The names are what make the match exact. (abs) discharges one variable, while (I), as Definition 3.3 computes it, discharges every open hypothesis with its formula. Once the names are rubbed out, two variables of the same type can become a single discharge: at type erases to the tree that supposes once and discharges it twice, and there the leaf belongs to the inner bar and the outer bar is vacuous. The last line of the theorem is not affected, since it says only that the open hypotheses are among . □
The case that matters is the , and it is easy to undersell: “proofs resemble programs” says far less than the theorem does. The theorem says that a derivation in NJ and a typing of a program with parameters, pairs, unions and case are the same tree with a column added; and that the rule which puts a parameter in scope and takes it out again is, column removed, the rule for supposing and discharging. Who saw this, and when, is told in the History, and is why the theorem carries two names.7
Example 3.16 (Baker, cont’d: the morning’s data). Baker’s morning had both. Her evidence that the first attempt had taken the money was an authorisation code and a capture id held together: a pair, which is what a settled charge is in the payments database, one record with two fields, either of which can be taken back out. The gateway’s answer to the second attempt was a value with a tag on it, Declined with a reason or Approved with a code, and to use it she had to branch on the tag. A tagged union is how a compiler makes it impossible to treat an answer as approved without looking at the tag.
Her proof by cases (Example 3.8) folds to a . Name the log’s answer , the two runbook rules and , and the two suppositions and :
Each branch ends in (E), the rule (app) of Figure 3.3, so it folds to an application, the destructor for . The (E) bar is the figure’s (E): it folds to the , the destructor for , which binds in its first branch and in its second, as the bar discharged in one and in the other. In the notation of the figure, with the context , the tree shows
3.4 Removing detours
For now we restrict attention to implication, whose terms are variables, applications and s. The other connectives, with their constructors and destructors, return in §3.5.
A proof takes a detour when it introduces a connective and at once eliminates it. The commonest is a lemma proved and used once. A derivation of from the supposition is closed by (I), giving , and at once applied by (E) to a derivation of :
Nothing is wrong with this proof, but it goes the long way round. The formula appears in the middle of the tree and nowhere else: it is neither the conclusion nor a hypothesis, but a lemma brought in for the occasion and dropped at once.
The detour is easy to straighten out. The derivation shows how to get from every proof of , and is one. So put a copy of in place of each leaf that the (I) bar was to discharge, and drop both bars:
Why straighten proofs at all? A proof with no detours uses no concepts other than those contained in its final result. For and this can be made exact: every formula in a proof without detours is a piece of its conclusion or of one of its open hypotheses. Now consider a proof of from no hypotheses at all. If it had no detours, every formula in it would be a piece of ; but has no pieces, so there would be nothing to build the proof from. Hence if every provable formula has a proof without detours, nothing proves .
The theorem to aim for, then, is that every formula provable in NJ has a proof without detours. A direct proof for NJ was published only some thirty years after the system was invented, and the History at the end of the chapter says why. We take a simpler route, through the folding of §3.3. The first step is to say exactly what happened when the detour above was removed; §3.5 does the same for every connective.
Fold the detour up. Let be the term of , with the name of the hypotheses that the (I) bar discharges, and let be the term of . The detour is then , a function applied to an argument. The straightened proof is with a copy of at each leaf named , so its term is with in place of each , which we write . Removing the detour is therefore the step
As a program this is familiar: to call a function, run its body with the argument in place of the parameter. What remains is to define precisely.
The first question is which occurrences of are replaced. The straightened tree is a composition: the hypotheses of that were open in , and closed only by the (I) bar, have each been replaced by a proof. A leaf that some bar inside discharges is not open in , and it stays where it is. On the term side, open hypotheses are free variables. A binds its parameter: the occurrences of in are bound, and an occurrence of a variable that no binds is free.
Definition 3.17 (free variables). The set of free variables of a term is defined by recursion on the shape of :
A term with no free variables is closed.
Only the third line does anything: a removes its own parameter from the set. That line has the shape of the (I) line of Definition 3.3, , with a variable in place of a formula: a closes its parameter as the (I) bar closes its hypothesis.
Substitution replaces the free occurrences of in by , and nothing else. So it must step around the s in , and that is where the care is needed.
Definition 3.18 (substitution). For terms and and a variable , the term , “ with for ”, is defined by recursion on the shape of , one line per form, except that the variable and abstraction cases each split in two, according to whether the variable met is the very one being replaced:
The first three lines replace the variable when you meet it and otherwise pass the substitution down. The fourth stops at a , because every inside it is bound and there is nothing to replace.
The side condition on the last line is the one subtlety. Pushing under a when is free in would turn that free into a bound one and change what means, so the definition declines. The remedy is to rename the of to a letter that occurs nowhere else, and then substitute. Rename first.8 Chapter 4 shows the same capture on the logic side, where it has been known for a century.
Renaming is harmless. Two terms that differ only in the names of their bound variables, like and , describe the same function, and we treat them as the same term. The renaming is called -conversion, and terms that differ by it are -equivalent. We never mark the step, since we take it only to keep variables apart.
The detour above sat at the root of its proof, but a detour can sit anywhere inside a proof, so the step must be allowed anywhere inside a term. That is the whole definition:
Definition 3.19 (-reduction). The one-step relation , “ reduces to ”, is given by the rule
together with a rule for each place a subterm can sit, which says that a step taken inside a term is a step of the term:
The first rule is the step itself, called , and is a redex: the term of a detour, with the term of the straightened proof on the right. To apply a function to an argument, substitute the argument for the parameter: that’s what a function call does, and it’s all a function call does. The other three rules say where a step may be taken, in the function, in the argument or under a , just as a detour may sit anywhere in a proof. This is the only reduction we use, so we call it -reduction and write with no subscript.9 Running means taking steps until there is none to take.
Example 3.20 (Baker, cont’d: the reply on the ticket). Baker’s morning has a detour of exactly this kind. At ten past ten she proved the rule by supposing and discharging (Example 3.5). At twenty to eleven, say, the gateway’s log gives her , a timeout at nine fifty-two, and she applies the rule to it:
An (I) met at once by (E): a detour, with the one-node tree as .
The reply she writes on the ticket does not mention the rule. It puts the log’s in place of the supposition, and the two bars go:
Both trees witness , but the second contains only facts about this charge, “no concepts other than those contained in its final result”. In terms, with and for the two runbook rules, for her supposition and for the log’s entry, the first tree is and the second is , one step later.
3.5 The simply typed -calculus
The detour of §3.4 was an (I) followed at once by (E). Every connective with an introduction rule has a detour of its own, and they can be described together. Call the premiss of an elimination rule that carries the connective being eliminated its major premiss, and the others minor: the major premiss is in (E), in (E1) and (E2), in (E), and in (E).
Definition 3.21 (maximal formula). A maximal formula in a derivation is an occurrence of a formula that is the conclusion of an introduction rule and, at once, the major premiss of an elimination rule. A derivation with no maximal formula is normal.
A maximal formula is a detour: a formula built only to be taken apart. By the folding of §3.3 it is a constructor met at once by its destructor. The detour of §3.4 is a maximal formula , and the other connectives have theirs.
A pair built by (I) and taken apart at once by (E1) keeps the proof of and throws away the proof of : becomes , and with (E2), becomes .
A tag put on by (I) and examined at once by (E) chooses the branch it names, and the proof inside the tag goes in for that branch’s supposition: a on becomes , and on it becomes .
Since has no introduction rule, it is never a maximal formula.
What does a derivation with no maximal formula fold up to? Call the part of a destructor that folds its major premiss its major part: the in , in , and , and the examined by . A maximal formula folds to a destructor whose major part is a constructor. In a normal derivation that never happens, and its term has a shape of its own.
Definition 3.22 (normal and neutral terms). The neutral and the normal terms are defined together. A term is neutral if it is one of:
a variable;
a destructor whose major part is neutral and whose other parts are normal, that is, , , , or , with neutral and and the branches normal.
A term is normal if it is one of:
a constructor, that is, , , or , whose parts are normal;
a neutral term.
A neutral term is a chain of destructors hanging off a variable, its head, and the head is free in it, since nothing in the chain binds it. On the proof side it is a hypothesis taken apart by eliminations, each working on what the one before produced. A normal term puts constructors on top of such chains: introductions near the root, building the conclusion, on eliminations that hang off hypotheses.
Lemma 3.23 (normal terms). Normal terms are the terms of normal derivations:
a term is normal exactly when no destructor in it has a constructor as its major part;
a derivation is normal exactly when the typed term it folds up to is normal.
Proof. We prove (i) in two halves and then deduce (ii).
Suppose first that is normal. By the definition, the parts of a normal term are normal; applying this to the parts, and to their parts, every subterm of is normal too. Now take a destructor in . It is normal and it is not a constructor, so it is neutral, and by the definition its major part is neutral. A neutral term is not a constructor, so no destructor in has a constructor as its major part.
For the converse, suppose that no destructor in has a constructor as its major part. We show that is normal, by induction on the size of , the number of symbols in it. The parts of are smaller, and no destructor in them has a constructor as its major part either, so by the induction hypothesis they are normal. Now look at the form of .
A variable. It is neutral, and so normal.
A constructor. Its parts are normal, so it is normal.
A destructor. Its major part is normal and, by the supposition, not a constructor, so it is neutral. Its other parts are normal. So the destructor is neutral, and therefore normal.
For (ii), fold the derivation up (Theorem 3.15). A constructor is the conclusion of an introduction rule, and a destructor is an elimination rule whose major premiss is its major part. So a maximal formula, the conclusion of an introduction that is at once the major premiss of an elimination, is exactly a destructor in the term whose major part is a constructor. By (i), the derivation has none exactly when its term is normal. □
So the proofs without detours that §3.4 asks for are exactly the derivations whose terms are normal, and what is wanted is a way to bring every term into that shape. A term that is not normal has a destructor meeting a constructor somewhere in it, and the list above says what each such meeting should become. Rewriting the meetings one at a time is reduction. To define it for the full calculus we first need free variables and substitution, as §3.4 had them for . Below, stands for one of , , , and , the forms with one part.
Definition 3.24 (free variables, all connectives). On the full calculus, is defined by recursion on the shape of :
and, for a ,
The new lines pass through the parts, and the line removes each branch’s variable from that branch, as the line removes the parameter from the body.
Definition 3.25 (substitution, all connectives). On the full calculus, is defined by recursion on the shape of :
and, for a whose branch variables and are neither nor free in ,
A branch variable that is or is free in is renamed first, as the parameter of a is; renaming a branch variable that is leaves nothing to replace in that branch, just as the sixth line leaves alone.
Definition 3.26 (-reduction, all connectives). On the full calculus the one-step relation is given by the rules of Figure 3.4, one for each constructor met by its destructor, together with a rule for each place a subterm can sit, which says that a step taken inside a part is a step of the whole: (), () and () of Definition 3.19, and one such rule for each part of each other form. There is no rule for , because has no constructor for it to meet. A term in which no step can be taken is in normal form.
Terms are written with as few brackets as the combinators of Chapter 1, by the same two conventions:
application groups to the left, so is ;
a reaches as far to the right as it can, so is , not .
Remark 3.27 (One input at a time). A term is a machine with a slot: put an argument in, and out comes the result, which may be another machine, waiting for the next argument. A makes a machine with one slot, so a function of two arguments is a function that returns a function: takes an and becomes with that in place, a machine waiting for a .
There are now two things a term can be: normal, which by Lemma 3.23 means that it folds up a normal derivation, and in normal form, which means that no step can be taken in it. The left-hand side of each rule of Figure 3.4 is a destructor whose major part is a constructor, so a normal term is in normal form. For typed terms the converse holds as well, and that is what the rules were made for: a typed term that has stopped running folds up a proof with no detours.
Proposition 3.28 (normal forms). A typed term is in normal form exactly when it is normal.
Proof. First, a normal term is in normal form. By Lemma 3.23, no destructor in it has a constructor as its major part. Every left-hand side in Figure 3.4 is such a destructor, so none occurs in the term, and no step can be taken in it.
Conversely, take a typed term in normal form, and a destructor in it. We show that its major part is not a constructor. The types decide what kind of constructor it could be, one destructor at a time.
An application. Its major part has an arrow type. The only constructor with an arrow type is a , and a there would make a redex.
A projection. Its major part has a type . The only constructor of that type is a pair, which would make a redex.
A . Its major part has a type . The only constructors of that type are the tags, which would make a redex.
An . Its major part has type , and no constructor has that type.
The term is in normal form, so it has no redex. So no destructor in it has a constructor as its major part, and by Lemma 3.23 the term is normal. □
Without the types the converse fails (Exercise 3.10).
So a typed term is in normal form exactly when the derivation it folds up is normal, and the question of §3.4, whether every proof can be straightened into one with no detours, is a question about running: does every typed term run to a normal form? That is termination, the subject of §3.6. Two questions about steps come first: does a step keep the type, and does the order of the steps matter?
Removing a detour restructures a proof without changing what it proves: the straightened derivation has the same conclusion, and its open hypotheses are among the old ones. On the terms, a step never changes the type. The property is called subject reduction, because the term is the subject of the judgement . It held for the combinators (Theorem 1.29), and it holds here for the whole calculus.
Theorem 3.29 (subject reduction). If and , then .
Proof sketch. The proof needs one fact about substitution first. Suppose and . Then : putting a term of type in place of a variable of type keeps the type. To see why, take the typing of and find each leaf where (var) gives . Replace each such leaf by a copy of the typing of . Every rule further down is still correctly applied, because a typing rule looks only at the types of its premisses, and those have not changed. The new tree types with in place of , at the same type . (On the proof side this is transitivity: a proof of spliced in for a hypothesis .)
With that fact in hand, we check each kind of step.
A step. The term was typed by (app) from and , and the first of these by (abs) from . The fact gives .
A projection. The term was typed from , which was typed from . So the result has type . The same holds for .
A on a tag. The term was typed from , so , and from for its first branch. The fact gives . A on is the same with the second branch.
A step inside a larger term. The subterm that steps keeps its type, by the cases above, so the lines of the typing that type it can be replaced by lines of the same type, and the rest of the typing is unchanged.
□
Example 3.30 (running typed terms). Take . Each line below names the rule of Figure 3.4 used, and the type is the same at every line, as subject reduction says.
A pair made and taken apart, after a function call:
all of type . On the proof side there are two maximal formulas: the proved by discharging and used at once, and the built by (I) and taken apart at once. Each step removes one, and what is left is the one-node derivation .
A function applied twice, with the identity as the function:
all of type , with .
A tag examined at once:
both of type , with .
Remark 3.31 (the order of the steps). A term may have several redexes, and then the order of the steps is a choice. Take , with and . It has two: the whole term, and the argument inside it. Take the whole term first, and the argument is copied before it is run, so it has to be run twice:
Take the argument first, and it is run once and then copied:
Three steps one way, two the other, and the same answer. It is the choice every language makes, whether an argument is evaluated before the call or only where it is used.
Could two orders ever give different answers? For the combinators the Church–Rosser theorem said no, and we took it on loan (Theorem 1.6). Here we prove it. Write when runs to in finitely many steps, perhaps none. Church–Rosser says that two runs from one term can always be brought back together:
Theorem 3.32 (Church–Rosser). If and , then there is a term such that and .
Proof. The proof has three stages. First we define a larger kind of step, which may contract several redexes at once. Second we show that two of these larger steps from one term can always be brought back together by one more large step on each side, closing a diamond. Third we fit such diamonds together, like tiles, to close every pair of runs.
Stage one: parallel steps. Say that reduces in parallel to , written , if comes from by contracting, all at once, some of the redexes already present in : all of them, some of them or none. In , for instance, a parallel step may contract the inner redex, giving ; or the outer one, giving ; or both, giving ; or neither. For the rules are
The third rule leaves an application as it is and works inside its two parts. The fourth contracts a redex, after working inside its two parts. The other forms get one rule like the third each, passing through their parts, and one like the fourth for each rule of Figure 3.4: when , and so on. Three facts about parallel steps are needed.
Parallel steps and runs. Every term reduces in parallel to itself, by contracting nothing. A single step is a parallel step that contracts one redex. And a parallel step is a run: if then . For the fourth rule, for instance, run to and to , which is possible by induction, and then take one step:
So a run is the same as a sequence of parallel steps.
Parallel steps and substitution. If and , then . In words, parallel steps taken inside a term and inside what is put into it can equally be taken after the substitution. This is proved by induction on the rules used for ; in the case of the fourth rule it also needs the fact that two substitutions can be done in either order, being when is neither nor free in .
Doing everything at once. Let the complete development of be the result of contracting every redex of at once:
and likewise for the other forms. The key fact is the triangle: if , then . Whichever redexes the parallel step to contracted, the ones it left can still be contracted, and contracting them reaches .
The triangle is proved by induction on the size of . If is a variable, and are that variable too. If is a , or an application whose function is not a , the parallel step and the complete development both work inside the parts, and the induction hypothesis for the parts gives the result. The case that carries the idea is a redex . The parallel step worked inside the parts, and , and by the induction hypothesis and . Then there are two possibilities.
The step contracted the redex. Then is , and fact (b) gives , which is .
The step left the redex. Then is , still a redex, and the fourth rule contracts it now: , which is .
The other forms are handled in the same way.
Stage two: the diamond. Suppose and . By the triangle, and . So two parallel steps from one term are brought back together by one parallel step on each side, and the meeting point is .
Stage three: tiling. Now let and . By fact (a) these runs are sequences of parallel steps, say steps to and steps to . Draw them as two edges of a grid, and fill the grid with diamonds, one square at a time, starting at :
Each square’s two upper edges are already drawn when we reach it, and they are two parallel steps from the square’s top corner; stage two supplies the two lower edges. After squares the grid is full. Its bottom corner has along one side and along the other, and by fact (a) again and . □
So a term has at most one normal form: the order of the steps can change whether it is reached, and what it costs, but not what it is.10
3.6 Normalisation
One theorem is left, and it is the one we were after. A typed term in normal form is the term of a proof without detours, and by Church–Rosser the normal form a term reaches does not depend on the order of the steps. What we do not yet know is whether every typed term reaches one. For the combinators it did: every typed program stopped. It does here too. Normalisation holds for the whole logic, but disjunction brings complications of its own, and a remark after the proof shows where, so we prove it for terms without only.11
Theorem 3.33 (normalisation). Every typed term runs to a normal form.
Proof for terms without . The idea is to attach to each term a measure that a well-chosen step always makes smaller. A measure that keeps getting smaller cannot do so for ever, so the run must stop.12
The measure. Give each type a degree, the height of its tree:
a letter and have degree 1;
and have degree one more than the larger of the degrees of and .
So has degree 2, and has degree 3. The degree of a redex is the degree of the type of the constructor in it:
the type of in ;
the type of in or .
By subject reduction a typed term stays typed as it runs, so these degrees stay defined. The measure of a term that is not in normal form is the pair , where is the largest degree of a redex in it and is the number of redexes of that degree.
The key observation. A step on a redex of degree creates new redexes only of degree less than . A new redex appears only where a constructor has come to stand under a destructor, and that can happen in two ways.
In a step , an occurrence of in that had a destructor applied to it (, or ) now has in its place. If is a or a pair, that is a new redex. Its constructor has the type of , and the degree of is less than that of .
The result of the step stands where the redex stood. If the result is a or a pair, and the redex had a destructor applied to it, as in or , that is a new redex. Its constructor has the type of the result in the case, and or in a projection: again of smaller degree than or .
Every other redex after the step was there before, though perhaps copied: a step makes one copy of , with all its redexes, for each occurrence of in .
The choice of step. Take a typed term with measure . Choose a redex of degree that contains no other redex of degree . One exists: if a redex of degree contains another, look at that one instead, and since the term is finite this stops. The choice matters because of copying. Had contained a second redex of degree in its argument, the step could have copied it, and the number of redexes of degree could have gone up.
Take the step on . Then:
itself is gone;
by the key observation, no new redex of degree or more has appeared;
the copies made of the argument of contain no redex of degree , because contained none.
So after the step there are two possibilities:
no redex of degree is left, and the measure is with , or the term is in normal form;
the largest degree is still , and the measure is .
Why the run stops. Compare measures as words are ordered in a dictionary: first by , and by only when the s are equal. Each chosen step makes the measure smaller in this order. When goes down, may go up, by any amount, but that does not matter, because has gone down. Now is a positive whole number, so it can go down only finitely many times; and while stays the same, goes down by one at each step, so that too can happen only finitely many times in a row. So after finitely many steps no redex is left, and the term is in normal form. □
It is an argument about the shapes of terms and nothing else: it counts redexes and watches the count go down.
Remark 3.34 (why disjunction fails). With the key observation fails. A step on a puts a branch where the stood, and the branch can have any type at all. Take , and write for , of type . The term
has one redex, the on a tag. Give a degree in the same way as . Then this redex has the degree of , which is 2, and its only step gives , a redex of degree 3, the degree of . The largest degree has gone up, and with a single redex there was no other step to choose. On the proof side, a meeting a is what Remark 3.36 calls a maximal segment, and the measure does not see it.
With normalisation in hand, every proof can be straightened.
Corollary 3.35 (normal derivations). Every derivation can be rewritten, by removing maximal formulas, into a normal derivation of the same formula whose open hypotheses are among those of the original.
Proof. Take a derivation of . We rewrite it in four moves.
Fold it into a typed term, by Curry–Howard: , where declares its open hypotheses.
Run to a normal form , by normalisation.
By subject reduction, has the same type in the same context: .
Unfold this typing into a derivation of . Its open hypotheses are among those that declares, which are the open hypotheses of the original.
The term is in normal form, so it is normal, and a normal term is the term of a normal derivation: the derivation it unfolds to is normal. □
By Church–Rosser, the normal derivation reached does not depend on the order in which the detours are removed.
Remark 3.36 (maximal segments). A normal derivation can still go the long way round when is involved. With , no step can be taken in
because meets a rather than a pair. Yet the formula is built by (I) in each branch, carried down through the (E) bar as its conclusion, and taken apart by (E1) below it: created by an introduction and eventually destroyed by an elimination, with no single occurrence of it maximal. A chain of occurrences of one formula of this kind, passed down through minor premisses of (E) from an introduction to the major premiss of an elimination, is a maximal segment, and a maximal formula is a maximal segment of length one; a conclusion of (E) taken apart by an elimination is a detour of the same sort.
Removing them takes further steps, the commuting conversions, which move the into the branches, as in
and similar ones for the other destructors and for . With them every derivation can be rewritten into one with no maximal segment, and every formula in such a derivation is a piece of its conclusion or of one of its open hypotheses, for all the connectives.13
We do without them: the proof of consistency (Theorem 3.38) goes through the shape of closed terms, and is enough for that.
Now watch normalisation pay off, in the argument that made us want it. A normal proof never invents material: for and , every formula in it is a piece of its conclusion or of one of its open hypotheses (with the same holds, after further rewriting steps). So to ask whether can be proved from nothing is to ask what a normal proof of from no open hypotheses could look like. Folded up, such a proof is a closed normal term, and there are very few of those, since a neutral term has a free variable at its head.
Lemma 3.37 (shape of closed normal forms). A closed typed term in normal form is a constructor. Consequently there is no closed term in normal form whose type is a letter , and none whose type is .
Proof. Take a closed typed term in normal form. It is normal, so it is a constructor or a neutral term. A neutral term has a free variable, its head; our term is closed, so it is not neutral, and it is therefore a constructor.
A constructor has type , or , according to the rule that introduces it, and none of these is a letter or . □
Theorem 3.38 (consistency). There is no closed term of type : . More generally, for every letter , .
Proof. Suppose, for a contradiction, that . Then:
So is a closed term in normal form of type , and the shape lemma says there is no such term. The argument for a letter is the same, with in place of . □
Read what we have shown. The logic of this chapter does not prove everything. It does not prove , and it does not prove any bare claim : whatever it proves has an arrow, an and or an or on the outside. So it proves things about how claims relate, and never a bare claim out of nothing.
The argument used nothing about what the letters mean, no table, no notion of a formula being the case. It’s an argument about the shapes of strings, and through programs it takes a page.
Ask whether arithmetic proves everything, rather than the bare connectives, and the question is much harder. It is the subject of Chapter 12, where the answer is of a different kind.
One more thing falls out of the shape lemma, and it’s worth having now.
Corollary 3.39 (disjunction property). If , then or .
Proof. Suppose . By Curry–Howard there is a closed term of type . By normalisation and subject reduction it runs to a closed term in normal form of the same type, and by the shape lemma that term is a constructor. The only constructors of type are the two tags, so it is one of:
with , and then ;
with , and then .
□
In this logic you can’t establish “ or ” without establishing one of them and saying which, because a proof of a disjunction is a value with a tag on it. A hypothesis may say “ or ” without saying which; a theorem cannot. Hold on to this. Part 2 has a use for it.
Finding a tree
Normalisation has a practical side, and it’s the one you’ll use most. Every derivable formula has a normal derivation, and a normal derivation has the shape of a normal term: introductions near the root, building the conclusion, sitting on chains of eliminations that hang off hypotheses and take them apart. So when you look for a tree, you need only look for one of that shape, and the shape tells you where to start: at the bottom, with the goal, working upwards. Take the currying formula of Exercise 3.5, .
The goal is an implication, and there’s one sensible way to prove an implication: suppose its antecedent and aim for its consequent. So the last bar is (I), and what’s left above it is a smaller problem:
The new goal is an implication too, and so is the one after it: two more bars, two more suppositions.
Now the goal is , a letter, and a letter has no introduction rule: there’s nothing left to build on the way up. So turn round and work downwards, from what you have. Of the three suppositions, only can produce an , by (E), and only if you can supply ; and (I) makes that from the other two:
Put this in the gap and the tree is finished: three introductions at the bottom, an elimination and the (I) it needed at the top, and no detour anywhere. The method, in four lines:
While the goal is , suppose and make the goal. While it is , make two goals of it. A goal is : suppose and aim for .
When the goal is a letter or , work down from what you have, taking it apart with elimination rules until the goal turns up. A usually comes from (E) on a negation you have.
If you have a disjunction, split on it with (E) early, and solve each case.
If you want a disjunction, use (I) last, once you know which side you can prove.
The fourth line is the one people break, and the disjunction property says why. Try to prove . After supposing , the goal is , and it is tempting to reach for (I1) at once and aim for :
and then you’re stuck, because nothing you have gives : it might be that holds. A proof of a disjunction has to say which side, and under the supposition you can’t say until you’ve split on it. Line 3 first: split on , and in each case you know which side to choose.
Programmers know the method as type-directed programming: the type says to write first, a value of type in hand says to write a , and what’s left is filling the holes.
It’s a guide, not an algorithm. A choice made early, which side of an or which hypothesis to apply, may have to be undone. When every attempt sticks, that’s a hint, not a proof, that there’s no tree; but the shape argument can turn the hint into a proof, and Exercise 3.8 does it for .14
3.7 Programs as proofs
With its steps, the simply typed -calculus is a programming language, a small one with its type checker built in: the rules of Figure 3.3 are the checker, and the steps of Figure 3.4 are the interpreter. Its programs are proofs, and each typed program proves the formula that is its type. Here are three, each a theorem given with the program that proves it.
Example 3.40 (swapping a pair). The program has type , so it proves that formula. In the context :
This is the tree we drew when learning to discharge (Example 3.7), with and for its and , and the two bracketed leaves are the two occurrences of in the body.
A variable used twice is a hypothesis discharged at two leaves;
a variable used once, at one;
a parameter never used at all, , which is , is the receipt for a debt of nothing.
Example 3.41 (contraposition). The program proves contraposition, . In the context , two uses of (app) give , and three uses of (abs) give the type claimed. Rub out the program before the last two uses of (abs), and what is left is modus tollens: from and , conclude .
Example 3.42 (swapping a union). The program has type , so it proves that formula, by cases. Rub out the program and what is left is an (E) bar with an (I) bar in each branch. The two branch variables and are its two discharged leaves and , each in scope only in its own branch.
Programs like these are ones you could have written without knowing what they proved:
a function that swaps a pair;
a function that composes a test with a function;
a function that swaps the tags on a union.
The types were there all along, as Curry–Howard says they must be.
Now take the three rules (var), (app) and (abs), rub out the programs, and read what is left.
A supposition in force may be written down.
From and , conclude .
If follows on the supposition , conclude and drop the supposition.
That is how you were taught to prove an implication, in the first mathematics lecture you attended. Every time the checker reads a definition f x = ..., that is what it checks.
Remark 3.43 (at work). None of this is a curiosity of logic books. The language ML, of 1978, is the typed -calculus with the types worked out by the compiler, offered with the promise that “well-typed programs cannot go wrong” (Milner, 1978). OCaml, F# and Haskell descend from it, and every lambda or closure in Java, C#, Swift, Rust or TypeScript is checked by rule (abs). The Glasgow Haskell compiler translates Haskell into a small typed -calculus of its own and can type-check that again after each optimisation, so that a compiler bug shows up as a type error.
On the logic side, the simply typed calculus is the logic of the HOL family of proof assistants (HOL4, HOL Light, Isabelle/HOL), and in Coq (now Rocq), Lean and Agda a proof is a typed -term, in a richer calculus than this one, checked by a small kernel with rules like (var), (app) and (abs). Between them they have checked the seL4 operating-system kernel (Klein et al., 2009), the CompCert C compiler (Leroy, 2009), the Four Colour Theorem (Gonthier, 2008) and the Kepler conjecture (Hales et al., 2017). In each the trusted part is a type checker, and whoever wants the theorem does the hard part, finding the term.
Consider these two programs. The first takes two arguments and returns the first:
renaming first if it is free in . The second takes three, and applies the first to the third and to what the second makes of the third:
What are their types? Fold each up as in §3.3, with the discharged hypotheses named for the parameters. The first is
where the bar marked 2 discharges nothing, since is never used. The second begins
where is used twice and discharged once, and two more (I) bars, discharging and then , end it at
So the types are and . Steps and types are both those of the combinators and , so we name the two terms after them:
Every combinator term is now a -term, and the two constants need no longer be taken as given. Exercise 3.4 checks the two typings again in the style of Figure 3.3.
Remark (looking back: the missing rule). Chapter 1’s checker had no rule for a name with a parameter. Rule (abs) is that rule. With it the compiler no longer has to compile anything to decide whether to say yes: it reads the definition as written. Adopting it types nothing new, as the next theorem shows.
Theorem 3.44 (translation into combinators). Every term built from variables by application and translates to a term built from , and variables by application, with no in it, such that:
has the same free variables as and does the same thing to every argument: if is then for every ;
has the types has: if then .
Conversely every combinator term is a -term, by the definitions of and above, with the same types.
Proof. The plan is to remove the s one at a time, innermost first. An innermost abstraction has no in its body , so it is enough to know how to remove a single from a body built by application alone. For such a body , define , “ abstracted over ”, by recursion on :
The result contains no and no . We check two things about it: it behaves as does, and it has the type has.
Behaviour. For every term ,
We prove this by induction on the size of , one case for each line of the definition.
If does not occur in : , and is , since there is no to replace.
If is : , and is .
If is : the step hands to both halves,
and by the induction hypothesis, applied to each half, this runs to , which is .
Type. If , then , the type that has. The same induction proves it.
If does not occur in : then without using , and , so .
If is : then is , and , as Chapter 1 showed.
If is , with and : by the induction hypothesis and . Then , at the type , gives .
The whole term. Now take an arbitrary term . Find an innermost abstraction in it, and replace it by . Repeat until no is left, and call the result . Each replacement keeps the free variables, since has those of ; it keeps the behaviour on arguments, by the first check; and it keeps the type, by the second, since a typing looks only at the types of the parts. So has the properties (i) and (ii). □
Remark (looking back: the Deduction Theorem as a compiler). You’ve seen the three lines of before.
The first writes a when the parameter is not used;
the second writes the identity for the parameter itself;
the third writes an to push the parameter through an application.
Those are, case for case, the three cases of the proof of the Deduction Theorem in Chapter 2, with the programs left on the lines:
an axiom or hypothesis weakened by (I);
the supposition itself, proved by the five-line proof of ;
a modus ponens distributed by (II).
That chapter said the proof was the compiler that turns your \ta -> into combinators. Here it is, three lines long.
Remark 3.45 (one theorem, twice). Rub the programs out of the translation and it is a theorem you have already seen. By Curry’s correspondence (Theorem 2.13) a typed combinator term is a Hilbert proof, and by Curry–Howard a typed -term is a derivation in NJ. The translation turns a derivation into a Hilbert proof of the same formula, and its converse, the definitions of and , turns a Hilbert proof into a derivation: and are the trees drawn for the schemas (I) and (II) in §3.2, folded up. So with the programs rubbed out, the theorem says that NJ and HJ prove the same formulas, which is the equivalence theorem of that section, and its proof is the proof given there.
3.8 Dropping the types
The typing rules pick out the terms that come from trees. Drop them and keep the steps, and any term built from the forms is a program, whether or not it comes from a tree. Here is the whole language at last.
Definition 3.46 (-terms). Fix a stock of variables . The terms are defined inductively:
every variable is a term;
if and are terms then is a term, the application of to ;
if is a variable and is a term then is a term, the abstraction of over , the function that takes and returns ;
if , , and are terms and and are variables, then , , , , , and are terms, the forms of the other connectives;
nothing else is a term.
In short,
Application groups to the left, as it did for the combinators, and a reaches as far to the right as it can, so is , not . We keep the ready-made integers and .
You’ve written the third form many times. It is \x -> M in Haskell, lambda x: M in Python and x => M in JavaScript;15 every def f(x): return M is one with a name attached. These terms, with the steps of §3.5 and no typing rules, are the untyped -calculus, the setting in which the was first studied.16
Every step of §3.5 still makes sense in it. What fails is the theorem about where runs end.
First, the Monster: the function that applies its argument to itself, applied to itself. In notation,
and each step gives back the term it started from. Nothing in the definition of -terms says what may be applied to what, and , which no typing accepts, is a term like any other. Self-application of this kind sank both of the logics these calculi were first built for, and in both the repair was the same: types.
Two runs of one term can still go apart, and the Church–Rosser theorem (Theorem 3.32) still brings them back together: its proof never looked at a type. So an untyped term, too, has at most one normal form.
Without types, though, the order can decide whether the end is reached at all. Put where it is thrown away, as in : the outer redex gives in one step, while a run that keeps choosing the redex inside never stops.
Fixing an order
Church–Rosser leaves the order free: every order that ends, ends at the same normal form. It does not say that every order ends, and is one that needn’t. So a language picks an order, by deleting or restricting rules. Lazy evaluation, or call by name, keeps and () and deletes () and (): an argument is run only where it is used.17 Eager evaluation, or call by value, keeps () and () and lets fire only when its argument is in normal form: an argument is run before the call. (Which of the two to try first is a further choice, and a language settles that too.) On , lazy gives in one step and eager runs for ever. Neither runs under a , and real languages don’t either, so a run can stop at a term with redexes still inside it, a value; a value need not be a normal form, and about values Church–Rosser says nothing.
The steps of Chapter 1 are steps, as §3.7 showed for and . The step is two steps on , and the step is three.
Remark (looking back: combinators). Everything Chapter 1 did with combinators carries over. A definition is the term with the name left off, and unfolding it is one step for each parameter; with the and steps above, all three kinds of step there are . The Church–Rosser theorem there is the combinator version of the one here, and was proved after it. And is the Monster, the program that runs for ever: combinator terms didn’t say what may be applied to what either, and the Monster’s story reads unchanged in the new grain.
The translation of Theorem 3.44 never looked at a type. Its three lines compile every untyped term built from variables by application and , the Monster included, into and , and the term compiled does the same thing to every argument.
Theorem 3.47 (Turing completeness). Every function a Turing machine computes is computed by a closed -term, and every function a closed -term computes is computed by a Turing machine.
Proof. Chapter 1 proved this for combinator terms (Theorem 1.19), and the translation of Theorem 3.44 converts each way without changing what is computed. □
That’s the order natural to these notes, which built the combinators first. History went the other way round, and the History at the end of the chapter tells it: one theorem, proved by three groups of people about three notations.
A term may not refer to itself, so recursion needs help. A recursive definition says that a function is one layer of work applied to the function itself, , which makes a fixed point of . Add to the combinators a constant with the single step , and is such a fixed point: it unfolds one layer of when it is needed, and no sooner.
Example 3.48 (factorial). Send something ordinary the whole way round: factorial, as you would write it on a whiteboard.
fact(n):
if n = 0 then return 1
else return n * fact(n - 1)
Four things in it are not in the combinator language: a parameter, a name that calls itself, a conditional, and arithmetic. Take them away one at a time. The parameter becomes a , which is what this section was for. Write , and for the test, the product and the predecessor, and use a boolean as its own conditional, so that “if then else ” is . Then
Nothing has really happened yet, because still occurs on the right-hand side. So make the recursive call a parameter too:
The term mentions nothing but its own two parameters: give it the function to call and a number, and it does one layer of the work. What we want is a term with , and is one, so define . One step shows how it runs:
and on the right ’s parameter is again: the recursive call, ready to unfold once more when it is needed and no sooner.18
The arithmetic was combinators already: the numerals, addition and multiplication were all built from and , and with more work so is the predecessor. We keep the three as names only to keep the term on the page.
One thing remains, the two s, and the translation removes them. Write for the body, so that , and read as the application . The line for an application splits it, the other two lines finish each half, and with written for ,
twenty-six symbols, with still free. Abstract out of that by the same three lines and every variable is gone:
There is not a variable, a parameter, a conditional or a recursive call anywhere in it, only , , three arithmetic constants and juxtaposition. Yet applied to runs to , by the and steps and the steps of the constants. A program you could have written in your first week sits on two constants in exactly this way, and so does every program you’ll ever compile.
Remark 3.49 (general recursion). Every language you use has recursion. Model it by a constant with the type for every and the step , as a recursive definition such as factorial needs. With it, has every type there is, and every letter included, so the consistency theorem fails; and it runs for ever, so normalisation fails with it. The two theorems go together, as they came together.
Read as a logic, a language with general recursion proves everything, and a type in such a language promises only what the program does if it returns. The price of factorial is the consistency of the logic. Every language you use pays it, and pays it knowingly: the loop is worth more to a programmer than consistency is. A programmer who wants both must say in the type where the recursion is allowed to go, and that takes a logic with more to say than this one.
The same price is why the checker’s yes, in the languages you use, means “safe” and never “correct”. The next chapter is about the gap between the two.
3.9 Fitch proofs (optional)
You’ve been drawing boxes all along, and they are a second notation for NJ. A proof can be written not as a tree but down the page, one line after another as a Hilbert proof is, with one addition:
a supposition opens a box;
every line inside the box is reasoned under it;
the box closes at the line that discharges it, which stands outside.
Drawn with the box as a vertical bar and the supposition underlined at its top, a proof of this kind is called a Fitch proof.19 The boxes in which the combinator typings were written are Fitch proofs with the programs on, each a single box because nothing there was ever discharged.
The two notations were invented separately, as the History at the end of the chapter tells, and Theorem 3.52 at the end of this section says that they agree.
A Fitch proof is a Hilbert proof that may open boxes inside its box, and it is an NJ derivation written down the page: a box is a subtree, and the nesting of boxes records what records.
Definition 3.50 (Fitch proof). A box has a head above a horizontal line and, below the line, a finite sequence of entries, each of which is one of:
a formula, called a line;
another box, called a subbox.
The head of the outermost box is a set of formulas. The head of a subbox is a single formula, its supposition, and its last entry is a line. The lines are numbered in one sequence down the page, whichever box they stand in, and a subbox is cited by the numbers – of its first and last lines:
| Line | Formula | Justification |
|---|---|---|
| 1 | reason | |
| i | reason | |
| j | reason | |
| n | reason |
A line or subbox is in scope at line if:
it comes before line , and
it is an entry of a box that contains line : the box that line stands in, or one around it.
So a subbox is in scope after it has closed, and the lines inside it are not.
Let be a set of formulas, the hypotheses. A Fitch proof of from is a box with head whose last entry is the line , and in which every line , in a subbox or not, is justified in one of the following ways, where “earlier” means “in scope at line ”:
(hyp) is a member of , or the supposition of a subbox that contains line ;
(E) there are earlier lines and such that is the formula ;
(I) is , and there is an earlier subbox with supposition whose last line is ;
(I) is , and and are earlier lines;
(E1, E2) some earlier line is , for some , or , for some ;
(I1, I2) is , and , or , is an earlier line;
(E) some earlier line is , and there are two earlier subboxes, one with supposition and one with supposition , each with last line ;
(E) is an earlier line.
Theorem 3.52 below shows that has a Fitch proof from exactly when , so no new symbol is needed.
Put this beside Definition 2.4. The outer box is the same box, with the hypotheses above the line and the lines below it. (hyp) is the hypothesis clause, with the supposition of every box around a line counted among that line’s hypotheses, and (E) is modus ponens, word for word. The axiom clause has gone: the rules that open subboxes do its work.
Everything new comes with the subbox, and so does the one restriction. A line inside a subbox was reasoned under its supposition, so once the subbox has closed, nothing outside it may cite that line. Only the subbox as a whole may be cited, and only by (I) and (E), the two rules that discharge.
Each line has a context: together with the suppositions of the subboxes that contain it. A line with context stands for the judgement . Read that way, each clause is one of the typing rules of Figure 3.3 with the terms deleted:
(hyp) is (var);
(E) is (app);
(I) is (abs), whose premiss is the last line of a subbox with supposition .
Example 3.51 (Baker, cont’d: her rule as a box). Baker’s rule once more, drawn earlier as a tree (Example 3.5) and now as a box:
| Line | Formula | Justification |
|---|---|---|
| 1 | (hyp) | |
| 2 | (hyp) | |
| 3 | (E) 2, 1 | |
| 4 | (hyp) | |
| 5 | (E) 4, 3 | |
| 6 | (I) 1–5 |
It is her six lines of Example 3.2 with the justifications formalised. Lines 2 and 4 stand inside the subbox and cite hypotheses from the head of the outer box, which is around them. Line 6 stands outside, and cites the subbox as a whole.
Trees and boxes are two notations for one system: they prove the same things from the same hypotheses, and they prove them by the same steps.
Theorem 3.52 (trees and boxes). For every set of formulas and every formula , the following are equivalent:
: some tree derivation has conclusion and all its open hypotheses in ;
has a Fitch proof from .
Moreover, the translations both ways go step by step:
each bar of a tree becomes a line justified by the same rule;
each line of a Fitch proof not justified by (hyp) becomes a bar of the same rule.
Proof. Each direction translates one notation into the other, bar for line.
Left to right. We show, by induction on the number of bars in a tree derivation with conclusion , that has a Fitch proof from every set that contains . One fact about Fitch proofs is used throughout. A Fitch proof from can be copied, with its lines renumbered, to each place where every member of is available, as a hypothesis or as the supposition of a box around that place. Each (hyp) line of the copy is still justified, and every other line cites only lines and subboxes of the copy, which are still in scope. Now look at the last bar of ; the trees above it have fewer bars, so the induction hypothesis applies to them.
No bar. is the one-node tree . Then , and the Fitch proof is the single line , by (hyp).
(E), (I), (E), (I), (E). The open hypotheses of each tree above the bar lie inside , so inside . By the induction hypothesis each premiss has a Fitch proof from . Copy these proofs, one after another, into a box with head , and add the conclusion as a new line, justified by the rule from the last lines of the copies.
(I). The tree above the bar, , concludes , and is . The bar removes from the open hypotheses, so . By the induction hypothesis has a Fitch proof from . In a box with head , open a subbox with supposition , copy that proof into it, close the subbox, and add the line , by (I).
(E). The same idea: first a Fitch proof of the disjunction from , then one subbox for each branch, with the branch’s supposition, and finally the conclusion, by (E).
Right to left. Take a Fitch proof from , and write for the context of line : the head of the outer box together with the suppositions of the subboxes around line . Going down the page, we build for each line a tree with conclusion and open hypotheses inside .
A (hyp) line. It gets the one-node tree , and .
Any other line. It cites earlier lines and subboxes, which already have trees. Put those trees above a bar for the rule that justifies line . Two facts about scope keep the open hypotheses inside . A line in scope at line stands in no box that does not also contain line , so . The last line of a subbox in scope at line , with supposition , has , and the bar removes again: for (I) from the one subbox, for (E) from each branch its own supposition.
The last line of the proof has context , so its tree witnesses .
Both constructions add one line for each bar, or one bar for each line, under the same rule, which is the last part of the theorem. □
Programs can be written in the boxes too, and then (abs) is a box inside a box. To type :
open an inner box whose declaration is ;
type the body inside it;
close the box.
The line after it, , is written outside the box, because outside the box is not in scope. A line may use a declaration from its own box or from each box around it, and nothing written inside a box that has been closed. That’s the scope rule of a programming language, and it is why proof assistants display proofs in this way.
For typing, though, these notes use the trees of Figure 3.3. In a box the context of a line is not written on the line: it has to be read off the boxes around it, and a term such as inside a box has a free variable whose declaration is somewhere above. In sequent style every judgement carries its whole context, and each step can be checked without looking anywhere else.
Trees, sequent-style trees and boxes are three notations for one object, and the theorem is the licence to move between them without comment. We draw trees when the shape of an argument is the point, and boxes when a proof is long and best read from top to bottom.
History
Three chapters have told this history in pieces, which is the right way to read it and the wrong way to remember it. It has nearly twenty people in it, Curry and Church twice each, doing the same things under different names. As one picture it’s a diamond, and it converges.
At the top is one book, read two ways. Hilbert read Principia and saw that a proof could be written down as a list and checked; so proof theory, the Deduction Theorem, and Gentzen’s rebuilding of the list as a tree. Schönfinkel, Curry and Church read it and saw mechanical instructions for rewriting formulas, above all for handling variables, and asked what a function does when it is applied; so the combinators, the , and, once Turing had asked the question in his own way, the theory of computation.
On the left edge the work was done in Göttingen. Gerhard Gentzen wrote his thesis, Untersuchungen über das logische Schließen (Gentzen, 1934), there in 1932–33, under Paul Bernays, who had been Hilbert’s collaborator on proof theory since 1917 and was writing the Grundlagen der Mathematik with him. In April 1933 Bernays was dismissed from the university under the new civil-service law, because he was a Jew; he left for Zürich the next year, and the thesis was examined by Hermann Weyl, who was himself about to leave. Gentzen had been set Hilbert’s task, to prove theorems about proofs, and the trees of NJ were built for it.
His main theorem, the Hauptsatz, says that detours can be removed, and the same introduction as the passage quoted at the start of the chapter puts it this way:20
The Hauptsatz says that every purely logical proof can be reduced to a definite, though not unique, normal form. Perhaps we may express the essential properties of such a normal proof by saying: it is not roundabout. No concepts enter into the proof other than those contained in its final result, and they are necessarily used in arriving at that result.
He could prove that every derivation can be made normal for NJ, but not for its classical version. To cover classical logic he invented a third presentation of the rules, the sequent calculus, and proved the Hauptsatz there. That proof covered the intuitionistic case as well, so he left the proof for NJ out of his thesis. In 2005 Jan von Plato found, among Bernays’s papers in Zürich, a handwritten version of the thesis that contains a detailed proof of normalisation for NJ, in the form that later became standard (von Plato, 2008): Gentzen had the proof and set it aside, since the sequent calculus handled classical and intuitionistic logic at once. The proof for NJ that everyone learned was published by Dag Prawitz in 1965, in the book that made natural deduction a subject again.
From 1935 Gentzen was Hilbert’s assistant, and in 1936 he proved the consistency of arithmetic, the result Chapter 12 comes back to. He went on writing to Bernays in Zürich for the rest of his life — drafts, the consistency proof, the ordinal that measures it — in letters that discuss nothing but mathematics, through the years in which he joined the SA and then the Party and in which Bernays could not have come back. The letters are in Menzler-Trott (2007), and I leave the reader to draw the conclusion.21
Natural deduction was invented twice in 1934. Stanisław Jaśkowski was in Warsaw, among Łukasiewicz’s students, and the complaint of Łukasiewicz’s seminar that Chapter 2’s History records, that a logic ought to let one suppose, was his starting point. He showed a system to the First Polish Mathematical Congress in 1927, though the published proceedings record the talk by title only, and printed it, in English, in the first volume of Studia Logica (Jaśkowski, 1934). Gentzen wrote his proofs as trees and Jaśkowski wrote his in boxes; Gentzen’s thesis appeared in the Mathematische Zeitschrift. The two men worked in different countries, wrote for different journals and moved in different circles, and were “never in contact with one another”, in the words of the standard history (Pelletier, 2000).
The war then scattered the Warsaw school, and Jaśkowski’s paper reached the wider world only afterwards, through textbooks. Quine’s Methods of Logic set out its proofs in a form close to his in 1950, and Fitch’s book of 1952, whose preface credits both Gentzen and Jaśkowski, made the boxes standard. By then Gentzen had been dead for seven years. So nobody chose between the tree and the box. Two people answered the same question separately, and Theorem 3.52 says that their answers agree.
On the right edge the combinators came first. Schönfinkel had them in 1924 (Schönfinkel, 1924), and Curry, finding them again in the 1920s, built a logic on them in his thesis of 1929 (Curry, 1930). In 1932 Alonzo Church, a Princeton mathematician not yet thirty, published a logic meant to carry the whole of mathematics, built, like Curry’s, from functions rather than from sets.22
Curry had done away with variables by building everything from constants. Church kept them, but only one kind: every variable in a formula had to be bound by a , and the free variable, the left dangling in , was to go. His paper calls this “the complete abandonment of the free variable”, and a page later it states the spirit in which the whole system was offered:23
We do not attach any character of uniqueness or absolute truth to any particular system of logic. The entities of formal logic are abstractions, invented because of their use in describing and systematizing facts of experience or observation …
Just as well he didn’t. In 1935 his own students, Kleene and Rosser, showed both his logic and Curry’s inconsistent (Kleene and Rosser, 1935), by the self-application of the Monster. The repair was the same in both cases: types. Curry gave his combinators types in 1934 (Curry, 1934), and Church gave his calculus types in 1940 (Church, 1940).
What survived of Church’s logic was the part that handled variables, the calculus of §3.5, and Church and his students went on to show that it could compute anything that can be computed at all. In 1936 Church proposed that “computable” should mean “definable by a -term”, and used that definition to show that no procedure decides whether two terms have the same normal form (Church, 1936b). A two-page note followed (Church, 1936a): no procedure decides which formulas of the logic with for all and there is are provable. That was the Entscheidungsproblem of Chapter 2’s History, answered. Turing, in Cambridge, had reached the same answer by way of his machines without knowing of Church’s. That September he arrived at Princeton to study with Church, and in 1937 he proved that his machines and Church’s terms compute the same functions (Turing, 1937a). Curry and his students showed the combinators equivalent to both.24
So the two edges first touch in 1936, at the dashed strut in the picture: a question asked on the left, by Hilbert and Ackermann, answered on the right, by Church and Turing. They meet at the bottom, when Curry noticed that the types of his combinators were Hilbert’s axioms, and Howard, thirty-five years later, that the typing rules for , pairs and unions were Gentzen’s, and that running was normalising. Below that is this course, which has walked the diamond backwards.
The correspondence came with two notations, because its two halves were worked out by different people. A type theorist writes for the type of pairs and for the type of tagged values, because a pair type has as many values as the product of the numbers of values of its halves, and a tagged type as many as their sum; hence product and sum types. A logician writes and , because those are the words. Nobody chose one notation for both, and most writing about programming languages uses the first; these notes use the second throughout, until Chapter 4 needs the type theorists’ letters for its quantifiers.
Four pairs of names are confused more often than not, and one sentence each will settle them.
Curry and Church. built two calculi for the same doomed logic, one with constants and one with ; one paradox broke both, and each repaired his own with types, Curry in 1934 and Church in 1940.
Church and Turing. gave two definitions of “computable” that are one theorem, and the thesis named after both is the claim that the theorem is about everything.25
Gentzen and Jaśkowski. invented “suppose” in the same year without knowing of each other, one as a tree and one as a box.
Curry and Howard. saw the two halves of one correspondence thirty-five years apart, Curry for the Hilbert system and the combinators, Howard for NJ and the -calculus — and Howard saw also that running was normalising, which Prawitz and Tait had just proved on the two sides, two years apart, with one proof.
Figure 3.5 collects the dates.
| Who | When | What |
|---|---|---|
| Frege | 1879 | proofs as gap-free chains; axioms (I), (II) |
| Whitehead & Russell | 1910–13 | the whole of mathematics, by rule |
| Hilbert & Bernays | 1922– | proofs as objects; proof theory |
| Schönfinkel | 1924 | and suffice |
| Hilbert & Ackermann | 1928 | the textbook; the Entscheidungsproblem |
| Herbrand | 1930 | the Deduction Theorem |
| Curry | 1930–34 | combinatory logic; the types of , |
| Church | 1932–36 | the -calculus; an unsolvable problem |
| Gentzen, Jaśkowski | 1934 | natural deduction; the Hauptsatz |
| Turing | 1936–37 | the machine; equivalence with |
| Church | 1940 | the simply typed -calculus |
| Curry & Feys | 1958 | types of combinators are axioms, in print |
| Prawitz; Tait | 1965; 1967 | normalisation, both sides |
| Howard | 1969 | the correspondence for and NJ |
Summary
NJ is ordinary reasoning written as rules: nine of them, for proving each connective and for using it, and no way to start except by supposing. Its derivations are trees, built by combining smaller trees, and a bracket round a leaf is a receipt for a supposition paid off. NJ proves exactly what the Hilbert system proves (Theorem 3.14): each rule is a fact about Hilbert proofs, and the whole cost of the Deduction Theorem is the cost of discharging.
Decorated with programs, a derivation is a typing in the simply typed -calculus (Theorem 3.15):
a hypothesis is a variable;
I is ;
E is application;
the other connectives are your data types, their introduction rules the constructors and their elimination rules the destructors.
The untyped calculus compiles to and by the theorem’s own construction and computes whatever a Turing machine computes.
Running a program is removing detours from a proof.
What the checker said survives the run (subject reduction);
every typed program stops (proved here by counting redexes, except for );
a normal derivation is what you look for when you look for one: introductions upwards from the goal, eliminations downwards from the hypotheses.
A stopped closed program is a constructor, so the logic proves no letter and no — the theorem Gentzen was hired to prove, by the route Howard noticed thirty-five years later — and a proof of or always says which.
Safe is not correct. Nothing we care about — a sorted list, a transitive order, a discount on every day of the sale — is proved from no hypotheses. By the consistency theorem, nothing with a bare claim at the top ever is. Such things are proved from a specification, a set of sentences about lists, orders or sales taken as hypotheses. And a specification says for all — every payment, not one customer’s; every day of the sale — which no formula of this chapter can say.
Exercises
Exercise 3.1. Give a derivation of each of the following, and say what it witnesses.
, that is, “ is not equivalent to its own negation”. (Harder.)
Then try each of , , and , and say where you get stuck. Keep the attempts: Section 3.6 explains why they stick, and Part 2 returns to all four.
Exercise 3.2. Draw derivations, in Gentzen’s notation, of the schemas (fst) , (either) and (absurd) with no open hypotheses, and compute for each by Definition 3.3. Then decorate the derivation of (either) with a program, and say which Haskell function it is.
Exercise 3.3. An online order is collected in store or delivered. A shop’s rules say that a collected order is marked complete, and that a delivered order is marked complete once the courier has confirmed it, which the courier has. Choose letters, draw the derivation that the order is marked complete, and compute its open hypotheses. Then give the program.
Exercise 3.4. Type and again, this time by (var), (app) and (abs) with the contexts written out, and confirm that the types are and , the ones Chapter 1 gave and . Then run and count the steps.
Exercise 3.5. Give derivations of and of , as trees, and then write the program each one is.
Exercise 3.6. Find a closed program of type , and give the derivation it is, a proof of .
Exercise 3.7. Find a closed program of type , and say which formula it proves.
Exercise 3.8. Try to find a closed program of type , for a letter . Say where every attempt sticks. Keep your attempt; Part 2 returns to this formula.
Exercise 3.9. The proof that NJ and the Hilbert system agree turns Chapter 2’s Hilbert proof of hypothetical syllogism, , into a derivation; decorated, it is the program with and written as -terms. That derivation has detours. Run the program to normal form and compare it with the composition function .
Exercise 3.10. Proposition 3.28 needs the types. Give a term in which no step can be taken but which is not normal, and say which typing rule it breaks. Then give one whose destructor is .
Exercise 3.11. Run the term for three steps. Then run , first blindly and then renaming the bound first, and say which answer is the one meant.
Exercise 3.12. Translate , the numeral , into combinators by the three lines of , innermost first, and check that the result applied to and runs to .
References
- Henk Barendregt. The impact of the lambda calculus in logic and computer science. Bulletin of Symbolic Logic, 3(2):181–215, 1997.
- Alonzo Church. A set of postulates for the foundation of logic. Annals of Mathematics, 33(2):346–366, 1932.
- Alonzo Church. A note on the Entscheidungsproblem. Journal of Symbolic Logic, 1(1):40–41, 1936a.
- Alonzo Church. An unsolvable problem of elementary number theory. American Journal of Mathematics, 58(2):345–363, 1936b.
- Alonzo Church. Review of A. M. Turing, On computable numbers, with an application to the Entscheidungsproblem. Journal of Symbolic Logic, 2(1):42–43, 1937.
- Alonzo Church. A formulation of the simple theory of types. Journal of Symbolic Logic, 5(2):56–68, 1940.
- Alonzo Church and J. Barkley Rosser. Some properties of conversion. Transactions of the American Mathematical Society, 39(3):472–482, 1936.
- Haskell B. Curry. Grundlagen der kombinatorischen Logik. American Journal of Mathematics, 52:509–536, 789–834, 1930.
- Haskell B. Curry. Functionality in combinatory logic. Proceedings of the National Academy of Sciences of the USA, 20(11):584–590, 1934.
- Frederic B. Fitch. Symbolic Logic: An Introduction. Ronald Press, New York, 1952.
- Robin O. Gandy. An early proof of normalization by A. M. Turing. In J. P. Seldin and J. R. Hindley, editors, To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, pages 453–455. Academic Press, London, 1980.
- Gerhard Gentzen. Untersuchungen über das logische Schließen I, II. Mathematische Zeitschrift, 39:176–210, 405–431, 1934. Appeared 1934–35; English translation in The Collected Papers of Gerhard Gentzen, ed. M. E. Szabo, North-Holland, 1969.
- Jean-Yves Girard, Yves Lafont, and Paul Taylor. Proofs and Types, volume 7 of Cambridge Tracts in Theoretical Computer Science. Cambridge University Press, 1989. Free online.
- Georges Gonthier. Formal proof—the four-color theorem. Notices of the American Mathematical Society, 55(11):1382–1393, 2008.
- Thomas Hales et al. A formal proof of the Kepler conjecture. Forum of Mathematics, Pi, 5:e2, 2017.
- William A. Howard. The formulae-as-types notion of construction. In J. P. Seldin and J. R. Hindley, editors, To H. B. Curry: Essays on Combinatory Logic, Lambda Calculus and Formalism, pages 479–490. Academic Press, London, 1980. Written in 1969.
- Stanisław Jaśkowski. On the rules of suppositions in formal logic. Studia Logica, 1:5–32, 1934.
- Stephen C. Kleene and J. Barkley Rosser. The inconsistency of certain formal logics. Annals of Mathematics, 36(3):630–636, 1935.
- Gerwin Klein et al. seL4: Formal verification of an OS kernel. In Proceedings of the 22nd ACM Symposium on Operating Systems Principles (SOSP), pages 207–220, 2009.
- Xavier Leroy. Formal verification of a realistic compiler. Communications of the ACM, 52(7):107–115, 2009.
- Paul Lorenzen. Einführung in die operative Logik und Mathematik. Springer, Berlin, 1955.
- John McCarthy. History of LISP. ACM SIGPLAN Notices, 13(8):217–223, 1978.
- Eckart Menzler-Trott. Logic’s Lost Genius: The Life of Gerhard Gentzen, volume 33 of History of Mathematics. American Mathematical Society and London Mathematical Society, 2007. Translated by Craig Smoryński and Edward Griffor.
- Robin Milner. A theory of type polymorphism in programming. Journal of Computer and System Sciences, 17(3):348–375, 1978.
- Francis Jeffry Pelletier. A history of natural deduction and elementary logic textbooks. In John Woods and Bryson Brown, editors, Logical Consequence: Rival Approaches, volume 1, pages 105–138. Hermes Science, Oxford, 2000.
- Dag Prawitz. Natural Deduction: A Proof-Theoretical Study. Almqvist & Wiksell, Stockholm, 1965.
- J. Barkley Rosser. Highlights of the history of the lambda-calculus. Annals of the History of Computing, 6(4):337–349, 1984.
- Moses Schönfinkel. Über die Bausteine der mathematischen Logik. Mathematische Annalen, 92:305–316, 1924.
- William W. Tait. Intensional interpretations of functionals of finite type I. Journal of Symbolic Logic, 32(2):198–212, 1967.
- Masako Takahashi. Parallel reductions in -calculus. Information and Computation, 118(1):120–127, 1995.
- Alan M. Turing. Computability and -definability. Journal of Symbolic Logic, 2(4):153–163, 1937a.
- Alan M. Turing. The -function in --conversion. Journal of Symbolic Logic, 2(4):164, 1937b.
- Dirk van Dalen. Logic and Structure. Springer, London, fifth edition, 2013.
- Jan von Plato. Gentzen’s proof of normalization for natural deduction. Bulletin of Symbolic Logic, 14(2):240–257, 2008.
Notes
Gentzen (1934, p. 68), in Szabo’s translation. Gentzen’s story is told at the end of the chapter, in the History. ↩
“The introductions represent, as it were, the ‘definitions’ of the symbols concerned, and the eliminations are no more, in the final analysis, than the consequences of these definitions” (Gentzen, 1934, p. 80). Lorenzen named this the inversion principle in 1955. ↩
They are van Dalen’s, who asks them of Euclid’s proof that the base angles of an isosceles triangle are equal (van Dalen, 2013, p. 30). ↩
The trees are Gentzen’s, root at the bottom, as he drew them and as no computer scientist draws any other tree. The square brackets round a discharged leaf are Prawitz’s, from the book (1965) that made natural deduction a subject again thirty years after Gentzen; Gentzen himself marked a discharged formula only with its number. ↩
Some books let a rule discharge a chosen subset of the open copies rather than all of them (van Dalen 2013, for one), or forbid discharging a formula that does not occur. Neither convention changes which consequences can be witnessed. ↩
Van Dalen calls this “a particular point which tends to confuse novices” (van Dalen, 2013, p. 33); his system has the second tree as a rule, and ours does not. ↩
Howard wrote his notes in 1969 and never submitted them; they went round as photocopies for eleven years and were printed in 1980 (Howard, 1980), in the same birthday volume for Curry in which Gandy printed Turing’s lost proof of normalisation. De Bruijn, in Eindhoven, found the same thing on his own at about the same time, building the checker of Exercise 2.4, and neither knew of the other. De Bruijn’s name is on nothing, which puts him in Schönfinkel’s company. Howard’s notes credit a talk of Tait’s in 1967 for the part of the correspondence that the next sections are about: that running a program is Gentzen’s normalisation. “Simply typed” is Church’s phrase from 1940, and the “simple” is the simple theory of types, Ramsey’s 1926 simplification of the ramified theory of Principia, in which a function’s type had recorded not only what it took and returned but at what stage it had been defined. It has nothing to do with difficulty. ↩
Getting this wrong is a rite of passage, and the first Lisp got it wrong. A function passed as an argument looked up its free variables where it was called rather than where it was written, so a variable of the caller could capture one of the function’s own. John McCarthy, its designer, later wrote: “I must confess that I regarded this difficulty as just a bug and expressed confidence that Steve Russell would soon fix it” (McCarthy, 1978). Lisps went on looking variables up that way for many years; Scheme, in 1975, was the first to do what the last line says by default. ↩
The letters are Church’s: for renaming, for the step. There is a third, , which says that and behave alike when is not free in ; we have no need of it. ↩
The theorem, for this calculus, is from 1936 (Church and Rosser, 1936). The proof by parallel steps is Tait’s and Martin-Löf’s, from about 1971; the complete development is Takahashi’s (Takahashi, 1995). ↩
Two proofs handle . Prawitz (1965) adds the commuting conversions described in Remark 3.36, which move a destructor into the branches of a , and counts maximal segments where the proof below counts maximal formulas; the counting argument then goes through. Tait (1967) defines, by induction on types, which terms are computable, shows that every computable term normalises, and shows that every typed term is computable. His method covers every connective at once and shows more: every order of steps reaches the normal form, not just a well-chosen one. Girard et al. (1989, chapters 6 and 10) give it. ↩
The argument that follows is Prawitz’s, for derivations (1965), and Girard et al. (1989, chapter 4) give it for and much as here. Turing had found it for terms in the early 1940s, in a note that was published only in 1980 (Gandy, 1980). ↩
The conversions, and this form of the normalisation theorem, are Prawitz’s (Prawitz, 1965). ↩
The advice to take formulas apart from the bottom upwards and then build the required ones, and its link with normalisation, are van Dalen’s (van Dalen, 2013, pp. 33, 36–37). ↩
Python’s
lambdacame from Church by way of Lisp. John McCarthy, designing Lisp in 1958, needed a notation for functions passed as arguments, and “it seemed natural to use the -notation of Church”, from Church’s little book of 1941. Twenty years later he added: “I didn’t understand the rest of his book, so I wasn’t tempted to try to implement his more general mechanism for defining functions” (McCarthy, 1978). In 2005 Python’s designer proposed takinglambdaout of the language, because “most Python users are unfamiliar with Lisp or Scheme, so the name is confusing”. It stayed. ↩Church used it in 1936 to exhibit a problem no procedure can settle (Church, 1936b), and gave it types in 1940. Why ? Whitehead and Russell had written the function with body as , with a hat; the story told by Church’s student Rosser is that a typesetter could not set the hat over the letter and moved it in front, where it became a capital lambda and then a small one (Rosser, 1984). Church himself, asked late in life, said the choice had been arbitrary. Barendregt tells both versions and believes neither entirely (Barendregt, 1997). The three forms are in Church (1940, §1), where he also proves that and are -terms. ↩
Haskell refines this to call by need, which runs a copied argument once and shares the result; the difference doesn’t matter here. ↩
In the untyped calculus need not be added: Curry’s satisfies by two steps, and Turing gave one of his own in 1937, , which does the same in a form that reduces to rather than merely to something equal to it (Turing, 1937b). Both are the Monster’s self-application put to work, which is why neither has a type (§3.6). ↩
After Frederic Fitch, at Yale, whose Symbolic Logic: An Introduction (1952) made the notation standard. His bars are Jaśkowski’s boxes with their right-hand sides rubbed out. Every proof assistant in use presents its proofs this way, with “suppose” as
introorassumeand the box as indentation, and so does the scope rule of every compiler: a parameter is in scope inside the function and not outside it. ↩Gentzen (1934, p. 69). His word is Umweg, a detour; Hauptsatz means the main theorem. ↩
Gentzen taught in Prague from 1943, was arrested there with the rest of the German faculty in May 1945, and died in the prison on 4 August 1945, of starvation; he is said to have gone on working, in his cell, on the consistency of analysis. ↩
Church was born in Washington in 1903 and spent almost his whole working life at two universities: Princeton, as student and then professor, until 1967, and then UCLA, where he taught until 1990, when he was eighty-seven. A childhood accident with an air gun had left him blind in one eye; his blackboard was nonetheless remembered as immaculate. He was exceedingly polite and exceedingly careful. He protected papers he valued with a coat of Duco cement, a clear household glue, and he read science-fiction magazines and wrote to their editors when they got something wrong. He was a founder of the Journal of Symbolic Logic in 1936 and edited its reviews until 1979, and he supervised thirty-one doctorates. Among them were Kleene, Rosser and Turing; Martin Davis; Michael Rabin and Dana Scott, who shared a Turing Award, a prize named after an earlier student of their supervisor; and Raymond Smullyan, of the mockingbirds, who had once performed in Chicago nightclubs as a stage magician called Five-Ace Merrill. ↩
Turing’s doctoral thesis was written under Church (1938), and Church’s two earlier students, Kleene and Rosser, had done most of the work of showing that the calculus could compute anything at all. Gödel, in Princeton at the time, was not persuaded that -definability captured “computable” until he read Turing’s paper, and then was. The name “Turing machine” is Church’s, from his review of Turing’s paper (Church, 1937); Turing had called them computing machines. ↩
Neither of them named it. Kleene called it “Church’s thesis” in 1952, and added Turing’s name in 1967. ↩