h5i

Appendix A

Proof that Proofs Are Terms

Chapter 4 claimed that every proof in second-order propositional logic can be turned into a term that the kernel accepts (Theorem 4.1). This appendix makes the statement precise and proves it in full. The proof is short once the right bookkeeping is in place: it is an induction on the derivation of the logical judgment, and each case is one row of the table in Chapter 4 read from left to right.

The idea

A derivation in the logic is a tree of rule applications. The translation in Chapter 4 pairs each logical rule with a typing rule. So the natural plan is: walk the derivation from the leaves up, and at each node build the typing derivation that the paired typing rule gives. A hypothesis becomes a variable lookup, an implication introduction becomes a λ\lambda, an implication elimination becomes an application, and the two quantifier rules become a λ\lambda over Sort 0\Sort{0} and an application to a type.

Two details need care, and both are about contexts.

  • The logical rules do not say which proposition variables are in scope. The typing side needs to know, because a proposition variable PP is only usable after the assumption P:Sort 0P : \Sort{0} is in the context. The precise statement therefore carries an explicit list Θ\Theta of proposition variables.
  • The typing rules extend contexts on the right, but the translation Δ∗\Delta^\ast of Chapter 4 puts all proposition variables before all hypotheses. The proof is easier if any interleaving is allowed, so we prove the theorem for every context that represents the logical judgment, in a sense defined below.

The precise statement

Theorem 4.1 leaves implicit which proposition variables are in scope. For the proof we make them explicit and write

Θ;Δ⊢φ,\Theta; \Delta \vdash \varphi,

where Θ\Theta is a list of distinct proposition variables, and every proposition variable free in Δ\Delta or in φ\varphi belongs to Θ\Theta. With this bookkeeping the rules of Chapter 4 read as follows.

φ∈ΔΘ;Δ⊢φ;(Hyp)Θ;Δ,φ⊢ψΘ;Δ⊢φ→ψ;(→-intro)Θ;Δ⊢φ→ψΘ;Δ⊢φΘ;Δ⊢ψ;(→-elim)\dfrac{\varphi \in \Delta}{\Theta; \Delta \vdash \varphi}\rulename{Hyp} \qquad \dfrac{\Theta; \Delta, \varphi \vdash \psi}{\Theta; \Delta \vdash \varphi \to \psi}\rulename{$\to$-intro} \qquad \dfrac{\Theta; \Delta \vdash \varphi \to \psi \qquad \Theta; \Delta \vdash \varphi}{\Theta; \Delta \vdash \psi}\rulename{$\to$-elim}
Θ,P;Δ⊢φP∉ΘΘ;Δ⊢∀P. φ;(∀-intro)Θ;Δ⊢∀P. φFV(ψ)⊆ΘΘ;Δ⊢φ[P↦ψ];(∀-elim)\dfrac{\Theta, P; \Delta \vdash \varphi \qquad P \notin \Theta}{\Theta; \Delta \vdash \forall P.\,\varphi}\rulename{$\forall$-intro} \qquad \dfrac{\Theta; \Delta \vdash \forall P.\,\varphi \qquad \FV(\psi) \subseteq \Theta}{\Theta; \Delta \vdash \subst{\varphi}{P}{\psi}}\rulename{$\forall$-elim}

The side condition P∉FV(Δ)P \notin \FV(\Delta) of Chapter 4 is now implied by P∉ΘP \notin \Theta: every proposition variable free in Δ\Delta is in Θ\Theta, and PP is not. Formulas are taken up to α\alpha-equivalence, so a bound PP can always be renamed to satisfy the side condition. As in Chapter 4, φ∗→ψ∗\varphi^\ast \to \psi^\ast stands for Π(x:φ∗). ψ∗\tPi{x}{\varphi^\ast}{\psi^\ast} with xx fresh.

The context Δ∗\Delta^\ast of Chapter 4 lists the proposition variables first and the hypotheses after them. The proof has to extend contexts on the right, so it is convenient to allow any order.

Definition A.1 (Representation). A context Γ\Gamma represents (Θ;Δ)(\Theta; \Delta) if ⊢Γ;ok\ctxok{\Gamma} and Γ\Gamma consists of one assumption P:Sort 0P : \Sort{0} for each P∈ΘP \in \Theta and one assumption h:χ∗h : \chi^\ast for each χ∈Δ\chi \in \Delta, in some order.

Theorem A.2 (Theorem 4.1, precise form). If Θ;Δ⊢φ\Theta; \Delta \vdash \varphi and Γ\Gamma represents (Θ;Δ)(\Theta; \Delta), then Γ⊢t:φ∗\Gamma \vdash t : \varphi^\ast for some term tt.

Theorem 4.1 is the special case Γ=Δ∗\Gamma = \Delta^\ast. When Θ\Theta lists the free proposition variables, the context Δ∗\Delta^\ast contains exactly the required assumptions; it is well formed by Lemma A.3 below together with the rule C-Ext, since each hypothesis type χ∗\chi^\ast is a proposition once the proposition variables are in scope.

Facts about the translation

The translation φ↦φ∗\varphi \mapsto \varphi^\ast commutes with substitution:

(φ[P↦ψ])∗=φ∗[P↦ψ∗].(\subst{\varphi}{P}{\psi})^\ast = \subst{\varphi^\ast}{P}{\psi^\ast}.

This is a routine induction on φ\varphi: both sides replace the free occurrences of PP by ψ∗\psi^\ast, and the translation does nothing to a proposition variable except keep its name. The ∀\forall-elim case of the main proof depends on this equation.

The next lemma is the one place where the universe structure of Chapter 13 enters. It says that every translated formula is a proposition, that is, has type Sort 0\Sort{0}. Without it, the typing rule T-Lam could not be applied to a hypothesis, and the ∀\forall-elim case could not instantiate a quantifier with an arbitrary formula.

Lemma A.3 (Formulas are propositions). If ⊢Γ;ok\ctxok{\Gamma} and (P:Sort 0)∈Γ(P : \Sort{0}) \in \Gamma for every P∈FV(φ)P \in \FV(\varphi), then Γ⊢φ∗:Sort 0\Gamma \vdash \varphi^\ast : \Sort{0}.

By induction on φ\varphi.

For a proposition variable PP, the assumption gives (P:Sort 0)∈Γ(P : \Sort{0}) \in \Gamma, so Γ⊢P:Sort 0\Gamma \vdash P : \Sort{0} by T-Var.

For φ→ψ\varphi \to \psi, the induction hypothesis gives Γ⊢φ∗:Sort 0\Gamma \vdash \varphi^\ast : \Sort{0}, so Γ,x:φ∗\Gamma, x : \varphi^\ast is well formed by C-Ext for a fresh xx. The induction hypothesis for ψ\psi in that extended context gives Γ,x:φ∗⊢ψ∗:Sort 0\Gamma, x : \varphi^\ast \vdash \psi^\ast : \Sort{0}, and T-Pi gives Γ⊢Π(x:φ∗). ψ∗:Sort imax(0,0)=Sort 0\Gamma \vdash \tPi{x}{\varphi^\ast}{\psi^\ast} : \Sort{\imax(0, 0)} = \Sort{0}.

For ∀Q. χ\forall Q.\,\chi, rename QQ so that Q∉dom(Γ)Q \notin \dom(\Gamma). T-Sort gives Γ⊢Sort 0:Sort 1\Gamma \vdash \Sort{0} : \Sort{1}, so Γ,Q:Sort 0\Gamma, Q : \Sort{0} is well formed by C-Ext. The induction hypothesis for χ\chi in that context gives Γ,Q:Sort 0⊢χ∗:Sort 0\Gamma, Q : \Sort{0} \vdash \chi^\ast : \Sort{0}, and T-Pi gives Γ⊢Π(Q:Sort 0). χ∗:Sort imax(1,0)=Sort 0\Gamma \vdash \tPi{Q}{\Sort{0}}{\chi^\ast} : \Sort{\imax(1, 0)} = \Sort{0}.

The proof

We prove Theorem A.2 by induction on the derivation of Θ;Δ⊢φ\Theta; \Delta \vdash \varphi, for all representing contexts Γ\Gamma at once. Each case builds the typing derivation shown in the right column of the table in Chapter 4.

Hypothesis. The rule concludes Θ;Δ⊢φ\Theta; \Delta \vdash \varphi from φ∈Δ\varphi \in \Delta. Since Γ\Gamma represents (Θ;Δ)(\Theta; \Delta), it contains an assumption h:φ∗h : \varphi^\ast, so Γ⊢h:φ∗\Gamma \vdash h : \varphi^\ast by T-Var.

→\to-intro. The premise is Θ;Δ,φ⊢ψ\Theta; \Delta, \varphi \vdash \psi and the conclusion is Θ;Δ⊢φ→ψ\Theta; \Delta \vdash \varphi \to \psi. By Lemma A.3, Γ⊢φ∗:Sort 0\Gamma \vdash \varphi^\ast : \Sort{0}. For a fresh hh, the context Γ,h:φ∗\Gamma, h : \varphi^\ast is therefore well formed by C-Ext, and it represents (Θ;Δ,φ)(\Theta; \Delta, \varphi). The induction hypothesis, applied to the premise and this context, gives Γ,h:φ∗⊢t:ψ∗\Gamma, h : \varphi^\ast \vdash t : \psi^\ast for some tt, and T-Lam gives

Γ⊢λ(h:φ∗). t:Π(h:φ∗). ψ∗.\Gamma \vdash \tLam{h}{\varphi^\ast}{t} : \tPi{h}{\varphi^\ast}{\psi^\ast}.

This type is φ∗→ψ∗\varphi^\ast \to \psi^\ast: the free variables of ψ∗\psi^\ast are proposition variables, and hh is not one of them, so hh does not occur in ψ∗\psi^\ast and the Π\Pi is non-dependent.

→\to-elim. The premises are Θ;Δ⊢φ→ψ\Theta; \Delta \vdash \varphi \to \psi and Θ;Δ⊢φ\Theta; \Delta \vdash \varphi. The induction hypotheses give Γ⊢f:Π(x:φ∗). ψ∗\Gamma \vdash f : \tPi{x}{\varphi^\ast}{\psi^\ast} with x∉FV(ψ∗)x \notin \FV(\psi^\ast), and Γ⊢a:φ∗\Gamma \vdash a : \varphi^\ast. T-App gives Γ⊢f  a:ψ∗[x↦a]\Gamma \vdash f\;a : \subst{\psi^\ast}{x}{a}, and since xx does not occur in ψ∗\psi^\ast the substitution does nothing: ψ∗[x↦a]=ψ∗\subst{\psi^\ast}{x}{a} = \psi^\ast.

∀\forall-intro. The premise is Θ,P;Δ⊢φ\Theta, P; \Delta \vdash \varphi with P∉ΘP \notin \Theta, and the conclusion is Θ;Δ⊢∀P. φ\Theta; \Delta \vdash \forall P.\,\varphi. Renaming PP if necessary, assume P∉dom(Γ)P \notin \dom(\Gamma); a routine induction shows that renaming a variable of Θ\Theta to a fresh one preserves derivations. By T-Sort and C-Ext, Γ,P:Sort 0\Gamma, P : \Sort{0} is well formed, and it represents (Θ,P;Δ)(\Theta, P; \Delta). The induction hypothesis gives Γ,P:Sort 0⊢t:φ∗\Gamma, P : \Sort{0} \vdash t : \varphi^\ast, and T-Lam gives

Γ⊢λ(P:Sort 0). t:Π(P:Sort 0). φ∗,\Gamma \vdash \tLam{P}{\Sort{0}}{t} : \tPi{P}{\Sort{0}}{\varphi^\ast},

which is the translation of ∀P. φ\forall P.\,\varphi.

∀\forall-elim. The premise is Θ;Δ⊢∀P. φ\Theta; \Delta \vdash \forall P.\,\varphi with FV(ψ)⊆Θ\FV(\psi) \subseteq \Theta, and the conclusion is Θ;Δ⊢φ[P↦ψ]\Theta; \Delta \vdash \subst{\varphi}{P}{\psi}. The induction hypothesis gives Γ⊢f:Π(P:Sort 0). φ∗\Gamma \vdash f : \tPi{P}{\Sort{0}}{\varphi^\ast}. Since every proposition variable of ψ\psi is in Θ\Theta and hence has an assumption Q:Sort 0Q : \Sort{0} in Γ\Gamma, Lemma A.3 gives Γ⊢ψ∗:Sort 0\Gamma \vdash \psi^\ast : \Sort{0}. T-App gives

Γ⊢f  ψ∗:φ∗[P↦ψ∗]=(φ[P↦ψ])∗,\Gamma \vdash f\;\psi^\ast : \subst{\varphi^\ast}{P}{\psi^\ast} = (\subst{\varphi}{P}{\psi})^\ast,

where the last step is the substitution equation from the previous section.

Every rule of the logic has been covered, so the theorem holds for every derivation.

The proof never needs T-Conv. Every typing derivation it builds compares types only syntactically, up to the names of bound variables. Conversion becomes necessary only when the logic is extended with computation, as the inductive types of Part II do.

What to remember

  • The precise form of the theorem carries an explicit list Θ\Theta of proposition variables, and proves the claim for every context that represents (Θ;Δ)(\Theta; \Delta), in any order.
  • Every translated formula lives in Sort 0\Sort{0} (Lemma A.3). This uses impredicativity in the ∀\forall case, and it is what lets ∀\forall-elim instantiate a quantifier with any formula.
  • The proof is an induction on the derivation; each logical rule maps to exactly one typing rule: Hyp to T-Var, the two introductions to T-Lam, the two eliminations to T-App.
  • T-Conv is never used, because the logic has no computation.