Lecture 14: Progress & Preservation w/ State

September 10

Progress, Take 1

If (S,e) : τ, then either e is a value or (S,e) -> (S',e).

Note, this doesn't work right off the bat, because we can't really induct on the thing we want. So we "explode" the lemma based on the one rule for (S,e):&tau:
    [Σ]S:Σ   [Σ]e:τ
    --------------------- t-state
    (S,e) : τ
    

Progress, Take 2

If [Σ]S:Σ and [Σ]e:τ, then either e is a value or (S,e) -> (S',e).

Modifying old cases

Now we can proceed by induction over the derivation of [Σ]e:τ. we'll do two representative cases of the old proof, it really doesn't change at all.

Case t-lam (e = λx:τ1.e, and τ = τ2)

    x:τ1 |- [Σ]e:τ2
    ----------------------- t-lam
    [&Sigma](λx:τ1.e) : τ1 -> τ2
    
Proof is immediate, λx:τ1.e is a value by rule.

Case t-app (e = e1(e2))

    [Σ]e1:τ' -> τ 
    [Σ]e2:τ'
    ----------------------- t-app
    [&Sigma] e1(e2) : τ
    

By the induction hypothesis, either e1 steps or is a value

Subcase (S,e1) -> (S',e'1) - we are done, because (S,e1(e2)) -> (S',e'1(e2)) by rule.

Subcase e1 value - by the induction hypothesis, either e2 steps or is a value.

Sub-subcase (S,e2) -> (S',e'2) - we are done, because (S,e1(e2)) -> (S',e1(e'2)) by rule.

Sub-subcase e2 value - by canonical forms on the facts [Σ]e1:τ' -> τ and e1 value, we know e1 = λx:τ.e0.
We know (S,(λx:τ.e0)(e2)) -> (S,[e2/x]e0), by rule (because e2 value) so we are done.

Canonical Forms

Our canonical forms lemmas change somewhat, and we need a new canonical forms lemma.

Store domain Lemma

We also need a lemma - which we can prove by induction on the store typing rules - that says that locations in a store type are in a store!

If 1]S : Σ2 and l is in the domain of Σ, then l is in the domain of S.

New cases

We have four new cases we need to deal with (recall the rules from the previous lecture):

Case (e = l, τ = τ' ref)

    Σ(l) = τ'
    -------------------------------------- t-loc
    [Σ]l : τ' ref
    

We are done: l value by rule.

Case (e = ref e', τ = τ' ref)

    [Σ]e' : τ'
    -------------------------------------- t-ref
    [Σ]ref e' : τ' ref
    

By the induction hypothesis, e' steps or is a value

Subcase (S,e') -> (S',e") - we are done, because (S,ref e') -> (S',ref e") by rule.

Subcase e' value - we are done, because we can come with l fresh and then (S, ref e') -> ((S,l=e'), l) by rule.

Note: this doesn't really follow the pattern of previous cases, because we reduced the subterm to a value but didn't rely on canonical forms.

Preservation

If

then

The interesting thing here are the lemmas we need:

Monotonicity

If Γ |- [Σ] e : τ and Σ' extends Σ, then Γ |- [Σ'] e : τ.

If 1] S : Σ2 and Σ' extends Σ1, then Γ |- [Σ'] S : Σ2.

This proof is pretty boring, the interesting cases are the variable rule t-var or t-assume and the location typing case t-loc. Monotonicity is one of these "big lemmas" like inversion or canonical forms, but it only shows up when our state is more interesting than just a single expression e

Substitution

If Γ, x:τ1 |- [Σ] e2 : τ2 and [Σ] e11, then Γ |- [Σ] [e1/x]e2 : τ2.

Old cases

Case e-appabs (e = λx:τ1.e1)e2, and e' = [e2/x]e1)

    e2 value
    -------------------------------------- e-appabs
    (S, (λx:τ.e1)e2) -> (S, [e2/x]e1)
    
By assumption, [Σ](λx:τ.e1)e2 : τ.
To show: [Σ] [e2/x]e1 : τ. (everything else is obvious)
By inversion, [Σ] λx:τ1.e1 : τ' -> &tau and [Σ]e2 : τ'.
By inversion, τ' -> τ = τ1 -> τ2 and x : τ1 |- [Σ]e1 : τ2. Therefore, τ' = τ1 and τ = τ2.
By substitution, we have [Σ][e2/x]e1 : τ2, which is what we needed to show.
$LastChangedDate: 2008-11-10 11:52:21 -0500 (Mon, 10 Nov 2008) $
$Author: rjsimmon $
$Rev: 1029 $