Normal Form Bisimulation for Typed Calculi: Syntactic Minimal Invariance (Draft March 8, 2007) Soren B. Lassen Google, Inc.
[email protected]
Paul Blain Levy University of Birmingham, U.K.
[email protected]
This note uses the normal form bisimulation theory for recursively typed call-by-push-value (CBPV) [1] to prove a “syntactic minimal invariance” result. • SOREN: NEED TO CHANGE FUNCTION APPLICATION SYNTAX TO OPERAND-FIRST EVERYWHERE v c γΓ,U B = λx. return thunk(γΓ,B (x))
Given closed types A, B, we define the function types: def
c
v γA
v γΓ,1 = λh i.h i
def
B † = U B → B.
A† = A → F A, †
c
v v (x1 ) γΓ,A = λhx1 , x2 i. γΓ,A 1 ×A2 1 v to y1 . γΓ,A (x2 ) 2 to y2 . return hy1 , y2 i
†
c γB
and closed terms ` : A and ` : B . More generally, to deal with recursive types, we define in Figure , by structural induction on A and B, open terms: v Γ `c γΓ,A : A[Γ]† ,
v v γΓ,Σ = λ{hi, xi. γΓ,A (x) to y. return hi, yi}i∈I i i∈I Ai
c Γ `c γΓ,B : B[Γ]† .
v γΓ,X = force Xi i v v γΓ,RecX.A = recX. λfold x. γΓ,X:U (RecX.A)[Γ]† ,A (x) to y. return fold y
−−→ −−→ ~ : U A† , Y ~ : U B † (we take the liberty to use where Γ = X ~ and Y ~ as term identifiers in Γ, γ v , γ c and as type X Γ,B Γ,A ~ and B ~ are closed types; A and B identifiers in A and B); A ~ Y ~ `v A type, X, ~ Y ~ `c B type; and [Γ] are open types: X, ~ ~ B ~ ~ A denotes the type substitution [ /X , /Y ]. −v−→ −− v→ v v Proposition 1. γA[Γ] = γΓ,A [γA/X , γB/Y ] and −v−→ −− v→ c c = γΓ,B γB[Γ] [γA/X , γB/Y ].
c v γΓ,F A = λx. force x to y. γΓ,A (y) c v = λx. λy. γΓ,A (y) γΓ,A→B c to z. γΓ,B (thunk(force x(z))) c c γΓ,Π = λx. λ{i. γΓ,A (thunk(πi (force x)))}i∈I i i∈I v γΓ,Y = force Y i i v γΓ,RecY .B = recY . λx. fold c γΓ,Y :U (RecY .B)[Γ]† ,B (thunk(unfold(force x)))
Proof. By structural induction on A and B. So, for closed recursive types RecX.A, RecY .B, v
v γ v RecX.A = γX:(RecX.A),A [γRecX.A/X ], A[ /X ] v γ c RecY .B = γYv :(RecY .B),B [γRecY .B/Y ]. B[
v c Figure 1. Definitions of γΓ,A and γΓ,B
/Y ]
Observe that x : U B ` γUv B (x), nil
∗
return x‡ , nil
x : U F A ` γFc A (x), K
∗
force x, K ‡ 1
def
def
c v where x‡ = thunk(γB (x)) and K ‡ = to y. γA (y)::K, provided x is of type U B and K is from type F A. More generally: −−→ Lemma 2. If ~x : U B `v p(~x) : A and Γ | F A `k K : F C then
−−→ v (p(~x)), K Γ, ~x : U B ` γA
∗
return p(x~‡ ), K
−→ and, if Γ `v V : U B, ~x : U A | B `k q(~x; K) : D, and Γ | F C `k K : D, −→ c Γ, ~x : U A ` γB (V ), q(~x; K)
∗
force V, q(x~‡ ; K ‡ ).
Proof. By structural induction on p and q. Theorem 3 (Syntactic minimal invariance). For all closed value types A and closed computation types B, v `c γA h λz. return z : A† , c `c γB h λz. force z : B † .
Proof. The equations follow from v z : A `c γA (z) h return z : F A,
z : U B `c force z ‡ h force z : B, which we prove by the exhibiting the following normal form bisimulation R which relates −→ v (p(~x)), nil R p(~x), nil : F A ~x : U A ` γA −−→ ~y : U B, z : U B ` force z ‡ , q(~y ; nil) R force z, q(~y ; nil) : F C −→ −−→ whenever ~x : U A `v p(~x) : A and ~y : U B | B `k q(~y ; nil) : F C. By Lemma 2, R is a normal form bisimulation.
References [1] S. B. Lassen and P. B. Levy. Normal form bisimulation for typed calculi. Conference submission, 2007.
2
A
Proofs
Here are some of the cases in the proof of Lemma 2. Case A = A1 × A2 . Then there exist p1 , ~x1 , B~1 , p2 , ~x2 , and B~2 such that ~x = ~x1 , ~x2 , ~ ,B ~ , ~ =B B 1
2
p(~x) = hp1 (~x1 ), p2 (~x2 )i, −−→ ~xi : U B i `v pi (~xi ) : Ai , for i ∈ {1, 2}. We use the abbreviations M [V1 , V2 ] v γA (V ) to y . return hV1 , y2 i in the following calculation. 2 2 2 v γA (p(~x)), v γA , λhz1 , z2 i. M [z1 , z2 ], M [p1 (~x1 ), p2 (~x2 )], v (p1 (~x1 )), γA 1 ~ return p1 (x‡1 ), v γA (p2 (~x2 )), 2 ~ return p2 (x‡2 ), ~ ~ return hp1 (x‡1 ), p2 (x‡2 )i, return hp(x~‡ )i
def
=
v γA (V1 ) to y1 . N [y1 , V2 ] and N [V1 , V2 ] 1
K p(~x)::K hp1 (~x1 ), p2 (~x2 )i::K K to y1 . N [y1 , V2 ]::K
=
= ∗ ∗ ∗
by the I.H.
∗
to y1 . N [y1 , p2 (~x2 )]::K ~ to y2 . return hp1 (x‡1 ), y2 i::K ~ to y2 . return hp1 (x‡1 ), y2 i::K K K
def
∗
by the I.H.
=
−−→ Case A = Σi∈I Ai . Then there exist i ∈ I and p0 such that p(~x) = hi, p0 (~x)i and ~x : U B `v p0 (~x) : Ai . v (p(~x)), γA v γA , v λ{hi, xi. γA (x) to y. return hi, yi}i∈I , i v 0 γAi (p (~x)) to y. return hi, yi, v γA (p0 (~x)), i return p0 (x~‡ ), return hi, p0 (x~‡ )i, return p(x~‡ ),
K p(~x)::K hi, p0 (~x)i::K K to y. return hi, yi::K to y. return hi, yi::K K K
= ∗
∗
by the I.H.
=
→ ~ :− Case B = Πi∈I Bi . Then there exist i ∈ I and q 0 such that q(~x; K) = i::q 0 (~x; K) and X U A | Bi `k q 0 (~x; K) : F C. ∗ c (V ), q(~x; K) γB c λ{i. γΓ,Bi (thunk(πi (force V )))}i∈I , q(~x; K) = c 0 λ{i. γΓ,B (thunk(π (force V )))} , i::q (~ x ; K) i i∈I i c ∗ γΓ,B (thunk(πi (force V ))), q 0 (~x; K) by the I.H. i 0 ~‡ ∗ force thunk(πi (force V )), q (x ; K) πi (force V ), q 0 (x~‡ ; K) force V, i::q 0 (x~‡ ; K) = force V, q(x~‡ ; K)
→ ~ :− Case B = RecY .B0 . Then there exists q 0 such that q(~x; K) = unfold::q 0 (~x; K) and X U A | B 0 `k q 0 (~x; K) : F C, def
where B 0 = B0 [B/Y ]. Observe that c γB = recY . λx. fold γYc :U B † ,B0 (thunk(unfold(force x)))
3
c
† c and γYc :U B † ,B0 [thunk(γB )/Y ] = γB 0 and, if L is a stack from type B , c ,L γB
∗
c λx. fold γB 0 (thunk(unfold(force x))), L
c (V ), γB c , γB c λx. fold γB 0 (thunk(unfold(force x))), c fold γB 0 (thunk(unfold(force V ))), c fold γB 0 (thunk(unfold(force V ))), c γB 0 (thunk(unfold(force V ))),
force thunk(unfold(force V )), unfold(force V ), force V, force V,
4
q(~x; K) ∗ V ::q(~x; K) (1) V ::q(~x; K) q(~x; K) = unfold :: q 0 (~x; K) ∗ q 0 (~x; K) by the I.H. 0 ~‡ ‡ ∗ q (x ; K ) q 0 (x~‡ ; K ‡ ) unfold::q 0 (x~‡ ; K ‡ ) = q(x~‡ ; K ‡ )
(1)