turnstile travelogue

Structural Normalization (1: STLC to Sequent Calculus)

{Previously: Part 0}

What I'm calling structural normalization -- a normalization procedure for simply-typed lambda calculus derived from concepts from structural proof theory -- can be achieved as a round trip with four stops.

  1. STLC -> intuitionistic sequent calculus (LJ)
  2. Cut elimination for LJ (to LJ-)
  3. LJ- to canonical forms STLC (CF)
  4. Home again: transliteration of canonical forms (CF) back to STLC

However, our actual itinerary is going to involve a backroad from 1 to 3. Instead of proving Cut Elimination as a translation from LJ into LJ-, we'll proof Cut Admissibility for LJ-, which allows us to go directly from STLC to LJ-, applying Cut Admissibility along the way. This lets us avoid defining two separate sequent calculi.

(Revised) Itinerary

The purpose of this blog post series is to describe a mechanized development I recently carried out of the following translations, which constitute my itinerary for the series:

  1. STLC -> LJ-, assuming Cut Admissibility for LJ-
  2. Cut Admissibility for LJ-
  3. LJ- to CF
  4. CF to STLC

In this post, I will cover step 1. (Note that steps 1 and 2 are somewhat out of order, but I think step 2 is a little more motivated once we have step 1 in place, and anyway it's the least "novel" in terms of things that have been well-documented and mechanized already.)

STLC

I will define STLC as the collection of proof terms for the following system of propositional natural deduction, defining the judgment ΓA true.

Γ,x:A trueA true(x)Γ,x:A trueB trueΓAB true(λx.)ΓAB trueΓA trueΓB true(app)

Note that if we were to think of as logical implication, spell the (x) rule as hypx, the (λx.) rule as I (implication introduction), and the app rule as E (implication elimination), we would have a natural deduction calculus for what Prawitz calls "minimal logic" (propositional logic with implication as its sole connective).

Example 1. λx.x as a derivation of AA true:

x:A trueA true(x)·AA true(λx.)

Example 2. (λx.x)y as a derivation of y:BtrueB true:

y:Btrue,x:B trueB true(x)y:BtrueBB true(λx.)y:BtrueBtrue(y)y:BtrueBtrue(app)

LJ-

I will define LJ- as the calculus defining the judgment ΓA with the following inference rules, in which p denotes an atomic proposition.

Γ,x:pp(idpx)Γ,x:ABΓAB(Rx)Γ,ABAΓ,AB,BCΓ,ABC(L)

STLC -> LJ-

We want to prove the following theorem:

Theorem: STLC -> LJ-. For all STLC terms M deriving ΓA true, there exists a derivation of ΓA (where just strips off the "true"s).

The computational content of this theorem will be a translation of STLC terms to LJ- derivations.

Proof: by induction on the structure of M.

STLC introduction rules (in the minimal fragment, just λ) correspond quite directly to LJ- right rules for the same connective:

  1. Case M=λx.N : ΓAB true, where N : Γ,x:AtrueB true.

Need to show ΓAB.

However, the "elimination rules" don't map nicely onto the LJ- left rules:

  1. Case M=app(F,N) : ΓB true, where F : ΓAB true and N : ΓA true.

Need to show: ΓB.

Now we will construct a derivation of the goal with an extra premise of AB:

𝒟NΓ,ABAΓ,AB,BBΓ,ABB(L)

Finally, by putting together 𝒟F and , we'd like to conclude by some principle {???}1 our goal ΓB.

We're missing two pieces, which turn out to be key metatheorems for LJ-:

We'll talk about the proofs of these later but leave them as holes for now.

Finally we have the variable case:

  1. Case M=(x) : Γ,x:AtrueA true.

Need to show: Γ,AA.

The goal follows by Identity Admissibility (same as {???}0 in the previous case).

Mechanization

I mechanized the above development (and the rest of the series outlined in the itinerary) in Twelf. Because I'm interested in the computational content of these proofs, I wanted to mechanize them so I could run them as programs. I chose Twelf for the same reasons Frank outlines in his paper "Structural Cut Elimination" (whose title inspires mine):

Most proofs require tedious data structures (such as multi-sets) and use complex termination measures. They also involve global conditions on occurrences of parameters in sequent derivations. In this paper we present new proofs of cut elimination [in LF/Elf]. Multi-sets are avoided altogether in these proofs, and termination measures are replaced by three nested structural inductions. Parameters are treated as variables bound in derivations, thus naturally capturing occurrence conditions.

Unfortunately, development on Twelf has mostly ceased, and most modern proof assistants still don't offer this same convenience. But, happily, you can still install and run Twelf today, even in your browser.

What follows is my Twelf code implementing the STLC -> LJ- proof (view it in the online webserver!). This post is getting long enough to risk not getting finished before I need to get up and do something else, so for now I will just leave the code here sans explanation, perhaps discussing its details and the results of running it in the next installment.

var-to-hyp : tm A -> left A -> type.
%mode var-to-hyp +Tm -Left.

nd-to-sc : tm A -> right A -> type.
%mode nd-to-sc +X1 -X2.

% variable case as a block
%block var-conc 
: some {A:tp} {RA:left A -> right A}
  block {x:tm A} {h:left A} {d:var-to-hyp x h}
  {thm : nd-to-sc x (RA h)}.


nd-to-sc/lam
  : nd-to-sc (lam ([x:tm A] M x : tm B))
    (arr-R ([h:left A] D h))
   <- ({h : left A} 
          identity A h
          (RA h : right A))
   <- ({x:tm A} {h:left A}
          var-to-hyp x h
       -> nd-to-sc x (RA h)
       -> nd-to-sc (M x) (D h)).

nd-to-sc/app
  : nd-to-sc
    (app (Fn : tm (arr A B))
         (Arg : tm A) 
      : tm B)
    (DB : right B)
   <- nd-to-sc Fn (Dfn : right (arr A B))
   <- nd-to-sc Arg (Darg : right A)
   <- ({h:left (arr A B)}
        {x:left B} identity B x (DidB h x : right B))
   <- ca (arr A B) Dfn
      % left (arr A B) -> right B
      ([h:left (arr A B)]
       arr-L
          (DidB h)
          (Darg)
          h)
      DB.

%worlds (var-conc) (nd-to-sc _ _).
%total D (nd-to-sc D _).