strong normalization by hoas
play

Strong Normalization by HOAS Andrei Popescu Joint work with Elsa - PowerPoint PPT Presentation

Strong Normalization by HOAS Andrei Popescu Joint work with Elsa Gunter Simply-typed -calculus - Syntax First-order syntax (up to ): Curry-style: no type annotations Data variables x, y, z, data terms X,Y, Z, data abstractions A,


  1. Strong Normalization by HOAS Andrei Popescu Joint work with Elsa Gunter

  2. Simply-typed λ -calculus - Syntax First-order syntax (up to α ): • Curry-style: no type annotations • Data variables x, y, z, data terms X,Y, Z, data abstractions A, B X ::= x | App X Y | Lam A A ::= x . X • Type variables tx, ty, tz, type terms tX, tY, tZ, type abstractions tA, tB tX ::= tx | Arr tX tY

  3. β -reduction (of untyped λ -calculus) App (Lam (x . Y)) X ~~> Y [X / x] (Beta) Y ~~> Y’ ----------------------------------------(Xi) Lam (x . Y) ~~> Lam (x . Y’) X ~~> X’ --------------------------------(App-Left) App X Y ~~> App X’ Y

  4. Typing . Γ |- Y : tY -------------------------- [x fresh Γ ] -------------------------------[x fresh Γ ] Γ , x : tX |- x : tX (Asm) Γ , x : tX |- Y : tY (Weak) Γ , x : tX |- Y : tY ---------------------------------------------- [x fresh Γ ] Γ |- Lam (x . Y) : Arr tX tY (Arr-I) Γ |- Z : Arr tX tY Γ |- X : tX ------------------------------------------(Arr-E) Γ |- App Z X : tY

  5. Abstractions as functions • FOAS definition/construction: A = (x . X) • HOAS treatment: A _ Y = A applied to Y, defined to be X [Y / x] • May regard abstractions as forming a subspace of Term  Term • This view accommodates a certain way to represent inference relations

  6. HOAS representation of β -reduction App (Lam (x . Y)) X ~~> Y [X / x] (Beta-FOAS) App (Lam A) X ~~> A _ X (Beta-HOAS) Y ~~> Y’ --------------------------------------(Xi-FOAS) Lam (x . Y) ~~> Lam (x . Y’) ∀ X. A _ X ~~> A’ _ X ------------------------------(Xi-HOAS) Lam A ~~> Lam A’

  7. HOAS representation of typing ∀Γ - (typing) context, i.e., list of pairs (data variable, type term): x 1 : tX 1 , …, x n : tX n ∀∆ - HOAS context, i.e., list of pairs (data term, type term): X 1 : tX 1 , …, X n : tX n • Note: we close under substitution

  8. HOAS representation of typing Γ , x : tX |- Y : tZ ----------------------------------- [x fresh for Γ ] Γ |- Lam (x . Y) : Arr tX tZ (Arr-I-FOAS) ∀ X. ∆ , X : tX ||- A _ X : tZ -------------------------------------(Arr-I-HOAS) ∆ ||- Lam A : Arr tX tZ

  9. HOAS representation of typing . -------------------------- (Asm) ∆ , X : tX ||- X : tX ∆ ||- Y : tY ------------------------------(Weak) ∆ , X : tX ||- Y : tY ∆ ||- Z : Arr tX tY ∆ ||- X : tX -------------------------------------------(Arr-E) ∆ ||- App Z X : tY

  10. “Context-free” induction principle for typing If H : data-term → type-term → bool s.t.: ∀ X. H X tX ⇒ H (A _ X) tZ -----------------------------------------(ArrI-H) H (Lam A) (Arr tX tZ) etc., then ∀ X tX. [] ||- X : tX ⇒ H X tX (Higher degree of HOAS – not only bindings and substitution, but also inference contexts are pushed to the meta-level )

  11. Strong normalization • Termination: X is strongly terminating = all reduction sequences X ~~> X’ ~~> X’’ ~~> … are finite • If confluence holds, then strongly terminating means the existence of a unique normal form, hence the phrase strongly normalizating • The strong normalization property: ∀ X. X typable ⇒ X strongly normalizing (X ∈ SN)

  12. Proof of strong normalization Γ |- X : tX ⇒ X ∈ SN

  13. Proof of strong normalization Difficulty Γ |- X : tX ⇒ X ∈ SN

  14. Proof of strong normalization Difficulty Γ |- X : tX ⇒ X ∈ SN Solution: • Strengthen the rhs of the goal • Integrate contexts into the goal’s statement • Give an SN-semantic interpretation to the relation |- • Close everything under substitution in arbitrary environments

  15. FOAS proof • Define [ _ ] : Tterm  P (SN) – [ tX ] = SN – [ Arr tX tY ] = {Z. ∀ X ∈ [tX]. App Z X ∈ [tY] } • Define Γ |= X : tX to mean: ∀ ρ : Dvar  P (SN). ( ∀ (y : tY) ∈ Γ . ρ y ∈ [tY]) ⇒ ρ X ∈ [ ρ tX] • Prove, by rule induction Γ |- X : tX ⇒ Γ |= X : tX

  16. FOAS proof • Want: Γ , x : tX ||- Y : tY ------------------------------------------[x fresh Γ ] Γ ||- Lam (x . Y) : Arr tX tY Assume the upper side. Fix ρ . Assume Γ ||- ρ . Want ρ (Lam (x . Y)) ∈ [Arr tX tY], i.e., Lam (x . ρ [x  x] Y) ∈ [Arr tX tY]. Fix X ∈ [tX]. Want App (Lam (x . ρ [x  x] Y)) X ∈ [tY] Since x fresh Γ , have Γ , x : tX ||- ρ [x  ρ X] . With IH, have ρ [x  ρ X] Y ∈ [ tY ], i.e., ( ρ [x  x] Y) [X / x]) ∈ [ tY ].

  17. FOAS proof • Discovered: would suffice that: Y [X / x] ∈ [ tY ] ⇒ App (Lam (x . Y)) X ∈ [tY] • A stronger version of this follows by induction on the definition of [ _ ]

  18. HOAS proof = Still define [ _ ] : Tterm  P (SN) + No environments, no typing contexts, no semantic consequence relation Want: ∀ X. X ∈ [tX] ⇒ A _ X ∈ [tY] ---------------------------------------- Lam A ∈ [Arr tX tY] + Discovered immediately: would suffice that: A _ X ∈ [ tY ] ⇒ App (Lam A) X ∈ [tY] = Again, a stronger version of this follows by induction on the definition of [ _ ] - Only in empty contexts proved (but extension immediate)

Recommend


More recommend