Chapter 3 presented eight typing rules as rules of logic. To make that claim precise, this chapter chooses a particular logic, translates its formulas into types, and shows that every proof in the logic becomes a term accepted by the kernel. It then explains why the kernel also needs consistency to be trustworthy.
A logic to compare against
The logic has formulas built from proposition variables P,Q,… by implication and by quantification over propositions:
φ,ψ::=P∣φ→ψ∣∀P.φ
This is second-order propositional logic: "second-order" because ∀ ranges over propositions rather than over individuals. It is small, but far from trivial. Conjunction, disjunction, negation, and falsity can all be defined inside it, for example ⊥=∀P.P and φ∧ψ=∀R.(φ→ψ→R)→R.
Proofs in this logic are natural-deduction derivations of judgments Δ⊢φ, where Δ is a list of hypotheses. The rules are the ones in the left column of Figure 4.1 below: use a hypothesis, introduce and eliminate implication, introduce and eliminate the quantifier.
Translating formulas into types
Each formula translates to a type, written φ∗:
P∗=P,(φ→ψ)∗=φ∗→ψ∗,(∀P.φ)∗=Π(P:Sort0).φ∗.
A proposition variable becomes a type variable, implication becomes the function type, and quantification over propositions becomes a Π-type over Sort0.
A list of hypotheses translates to a context. Besides one assumption hi:φi∗ per hypothesis, the context must declare the proposition variables that occur anywhere in the judgment:
where P1,…,Pk are the proposition variables free in Δ or in the conclusion φ of the judgment Δ⊢φ being translated, and h1,…,hn are fresh names. The conclusion must be included because a variable may occur only there, as P does in ⋅⊢P→P.
Figure 4.1 places each logical rule next to the typing rule that implements it. The premises that merely check that a type is well formed are omitted.
Figure 4.1. Natural deduction (middle column) and the typing rules that implement it (right column). In each row, Δ∗ is the context for the conclusion.
Erasing the terms from the right column gives the middle column exactly. Two details deserve comment.
In the ∀-intro row, the logic's side condition P∈/FV(Δ) guarantees that no hypothesis mentions P, so the typing rule may add P:Sort0after the hypotheses without breaking the dependency order of the context.
In the ∀-elim row, the premise ψ∗:Sort0 holds for every formula ψ, even one that contains ∀, because T-Pi places every translated formula in Sort0. (The imax in T-Pi is responsible: Π(P:Sort0).φ∗ lands in Sortimax(1,0)=Sort0.) So a universal statement can be instantiated with any formula, as it can in the logic. Chapter 13 returns to this point, which is called impredicativity.
Proofs are terms
Theorem 4.1 (Proofs are terms). If Δ⊢φ is provable in the logic, then Δ∗⊢t:φ∗ for some term t.
Figure 4.1 turns each step of a logical proof into a step of a typing derivation, so every proof becomes a term by induction on the proof. Appendix A states the theorem with the scoping of proposition variables made explicit and gives the full proof.
The theorem says that the type checker can check every proof of the logic. For the kernel to be trustworthy, we also need the opposite guarantee: it must not accept a term for a proposition that the logic refutes.
Consistency
Define ⊥=∀P.P, "everything holds". No proof of ⊥ exists in the logic: if each proposition variable is read as true or false, every rule preserves truth under every reading, but ∀P.P is false under the reading that makes some P false.
The type theory should agree. That is, no closed term should have the type
⊥∗=Π(P:Sort0).P.
A closed term t of this type would be a disaster: for every proposition C:Sort0, the application tC would have type C, so every proposition would be provable and the kernel would be worthless.
Definition 4.2 (Consistency). A type system is consistent if no closed term has type Π(P:Sort0).P.
Consistency is the property that every design decision in this book must preserve. In particular, a design for universes is acceptable only if the system remains consistent; Chapter 13 shows a natural-looking design that fails this test, and Chapter 14 states consistency for our system as Theorem 14.5.
Exercises
Translate the formula ∀P.∀Q.(P→Q)→P→Q to a type, and write the proof term that Figure 4.1 produces for the natural-deduction proof "assume P→Q and P; apply the first to the second".
Solution
The type is Π(P:Sort0).Π(Q:Sort0).(P→Q)→P→Q. Two ∀-intros give two outer λs over Sort0, two →-intros give λ(f:P→Q) and λ(p:P), and →-elim gives the body fp:
λ(P:Sort0).λ(Q:Sort0).λ(f:P→Q).λ(p:P).fp.
Show that from t:Π(P:Sort0).P one can build a term of type Π(P:Sort0).Π(Q:Sort0).P→Q, "every proposition implies every other".
Solution
λ(P:Sort0).λ(Q:Sort0).λ(p:P).tQ. The hypothesis p is ignored and tQ:Q by T-App. This is the sense in which a proof of ⊥∗ proves everything.
What to remember
Second-order propositional logic translates into the type theory: → becomes the function type, ∀P becomes Π(P:Sort0), hypotheses become context entries.
Theorem 4.1: every proof in the logic becomes a well-typed term. The translation is rule by rule (Figure 4.1).
The kernel is trustworthy only if it is consistent: no closed term of type Π(P:Sort0).P.
Impredicativity, via imax, is what lets a universal statement be instantiated by any formula, including itself.