realizability and parametricity in pure type systems
play

Realizability and parametricity in pure type systems Jean-Philippe - PowerPoint PPT Presentation

Realizability and parametricity in pure type systems Jean-Philippe Bernardy Chalmers university Marc Lasson Ecole Normale Sup erieure de Lyon February 15, 2011 1 / 41 Realizability and parametricity in pure type systems Marc


  1. System F System F The PTS F has the following specification S F = { ⋆, � } A F = { ( ⋆, � ) } R F = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) } 10 / 41 Realizability and parametricity in pure type systems Marc Lasson

  2. System F System F The PTS F has the following specification S F = { ⋆, � } A F = { ( ⋆, � ) } R F = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) } Only two kinds of product : Arrow type ( σ → τ ) : ( ⋆, ⋆, ⋆ ) Type quantification ( ∀ α, τ ): ( � , ⋆, ⋆ ) Γ ⊢ t : τ : ⋆ 10 / 41 Realizability and parametricity in pure type systems Marc Lasson

  3. System F System F The PTS F has the following specification S F = { ⋆, � } A F = { ( ⋆, � ) } R F = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) } Only two kinds of product : Arrow type ( σ → τ ) : ( ⋆, ⋆, ⋆ ) Type quantification ( ∀ α, τ ): ( � , ⋆, ⋆ ) Γ ⊢ t : τ : ⋆ Γ ⊢ σ : ⋆ Γ , x : σ ⊢ τ : ⋆ ( ⋆, ⋆, ⋆ ) ∈ R F Γ ⊢ ∀ x : σ.τ : ⋆ We can prove that Γ ⊢ τ : ⋆ and Γ ⊢ x : σ : ⋆ then x �∈ τ . Therefore ∀ x : σ.τ can always be written σ → τ . 10 / 41 Realizability and parametricity in pure type systems Marc Lasson

  4. System F System F The PTS F has the following specification S F = { ⋆, � } A F = { ( ⋆, � ) } R F = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) } Only two kinds of product : Arrow type ( σ → τ ) : ( ⋆, ⋆, ⋆ ) Type quantification ( ∀ α, τ ): ( � , ⋆, ⋆ ) Γ ⊢ t : τ : ⋆ Γ ⊢ σ : ⋆ Γ ⊢ τ : ⋆ ( ⋆, ⋆, ⋆ ) ∈ R F Γ ⊢ σ → τ : ⋆ We can prove that Γ ⊢ τ : ⋆ and Γ ⊢ x : σ : ⋆ then x �∈ τ . Therefore ∀ x : σ.τ can always be written σ → τ . 10 / 41 Realizability and parametricity in pure type systems Marc Lasson

  5. System F System F The PTS F has the following specification S F = { ⋆, � } A F = { ( ⋆, � ) } R F = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) } Only two kinds of product : Arrow type ( σ → τ ) : ( ⋆, ⋆, ⋆ ) Type quantification ( ∀ α, τ ): ( � , ⋆, ⋆ ) Γ ⊢ t : τ : ⋆ Γ ⊢ σ : ⋆ Γ ⊢ τ : ⋆ ( ⋆, ⋆, ⋆ ) ∈ R F Γ ⊢ σ → τ : ⋆ We can prove that Γ ⊢ τ : ⋆ and Γ ⊢ x : σ : ⋆ then x �∈ τ . Therefore ∀ x : σ.τ can always be written σ → τ . We can also prove that inhabitants of ⋆ are either : α , σ → τ or ∀ α : ⋆.τ . 10 / 41 Realizability and parametricity in pure type systems Marc Lasson

  6. System F – Examples Example Nat ≡ ∀ α : ⋆. ( α → α ) → ( α → α ) 0 ≡ λ ( α : ⋆ )( f : α → α )( x : α ) . x Succ ≡ λ ( n : Nat)( α : ⋆ )( f : α → α )( x : α ) . f ( n α f x ) 11 / 41 Realizability and parametricity in pure type systems Marc Lasson

  7. System F – Examples Example Nat ≡ ∀ α : ⋆. ( α → α ) → ( α → α ) 0 ≡ λ ( α : ⋆ )( f : α → α )( x : α ) . x Succ ≡ λ ( n : Nat)( α : ⋆ )( f : α → α )( x : α ) . f ( n α f x ) ⊢ Nat : ⋆ 11 / 41 Realizability and parametricity in pure type systems Marc Lasson

  8. System F – Examples Example Nat ≡ ∀ α : ⋆. ( α → α ) → ( α → α ) 0 ≡ λ ( α : ⋆ )( f : α → α )( x : α ) . x Succ ≡ λ ( n : Nat)( α : ⋆ )( f : α → α )( x : α ) . f ( n α f x ) ⊢ Nat : ⋆ ⊢ 0 : Nat 11 / 41 Realizability and parametricity in pure type systems Marc Lasson

  9. System F – Examples Example Nat ≡ ∀ α : ⋆. ( α → α ) → ( α → α ) 0 ≡ λ ( α : ⋆ )( f : α → α )( x : α ) . x Succ ≡ λ ( n : Nat)( α : ⋆ )( f : α → α )( x : α ) . f ( n α f x ) ⊢ Nat : ⋆ ⊢ 0 : Nat ⊢ Succ : Nat → Nat 11 / 41 Realizability and parametricity in pure type systems Marc Lasson

  10. Introduction 1 Building the logic 2 Parametricity and realizability in PTS’s 3 An application and an extension 4 12 / 41 Realizability and parametricity in pure type systems Marc Lasson

  11. From P to P 2 – From realizers to logic 13 / 41 Realizability and parametricity in pure type systems Marc Lasson

  12. From P to P 2 – From realizers to logic 13 / 41 Realizability and parametricity in pure type systems Marc Lasson

  13. From P to P 2 – Definitions Given a PTS P = ( S , A , R ), we define P 2 = ( S 2 , A 2 , R 2 ) by S 2 = S ∪ { ⌈ s ⌉ | s ∈ S} A 2 = A ∪ { ( ⌈ s 1 ⌉ , ⌈ s 2 ⌉ ) | ( s 1 , s 2 ) ∈ A} R 2 = R ∪ { ( ⌈ s 1 ⌉ , ⌈ s 2 ⌉ , ⌈ s 3 ⌉ ) , (s 1 , ⌈ s 3 ⌉ , ⌈ s 3 ⌉ ) | ( s 1 , s 2 , s 3 ) ∈ R} ∪ { (s 1 , ⌈ s 2 ⌉ , ⌈ s 2 ⌉ ) | ( s 1 , s 2 ) ∈ A} 14 / 41 Realizability and parametricity in pure type systems Marc Lasson

  14. From P to P 2 – Definitions Given a PTS P = ( S , A , R ), we define P 2 = ( S 2 , A 2 , R 2 ) by S 2 = S ∪ { ⌈ s ⌉ | s ∈ S} A 2 = A ∪ { ( ⌈ s 1 ⌉ , ⌈ s 2 ⌉ ) | ( s 1 , s 2 ) ∈ A} R 2 = R ∪ { ( ⌈ s 1 ⌉ , ⌈ s 2 ⌉ , ⌈ s 3 ⌉ ) , (s 1 , ⌈ s 3 ⌉ , ⌈ s 3 ⌉ ) | ( s 1 , s 2 , s 3 ) ∈ R} ∪ { (s 1 , ⌈ s 2 ⌉ , ⌈ s 2 ⌉ ) | ( s 1 , s 2 ) ∈ A} For each sort s we add a copy ⌈ s ⌉ , For each axiom ( s 1 , s 2 ) we add the axiom ( ⌈ s 1 ⌉ , ⌈ s 2 ⌉ ). Beside the original rules, we allow three new quantifications : We lift constructs of realizer at the level of the logic, 1 14 / 41 Realizability and parametricity in pure type systems Marc Lasson

  15. From P to P 2 – Definitions Given a PTS P = ( S , A , R ), we define P 2 = ( S 2 , A 2 , R 2 ) by S 2 = S ∪ { ⌈ s ⌉ | s ∈ S} A 2 = A ∪ { ( ⌈ s 1 ⌉ , ⌈ s 2 ⌉ ) | ( s 1 , s 2 ) ∈ A} R 2 = R ∪ { ( ⌈ s 1 ⌉ , ⌈ s 2 ⌉ , ⌈ s 3 ⌉ ) , (s 1 , ⌈ s 3 ⌉ , ⌈ s 3 ⌉ ) | ( s 1 , s 2 , s 3 ) ∈ R} ∪ { (s 1 , ⌈ s 2 ⌉ , ⌈ s 2 ⌉ ) | ( s 1 , s 2 ) ∈ A} For each sort s we add a copy ⌈ s ⌉ , For each axiom ( s 1 , s 2 ) we add the axiom ( ⌈ s 1 ⌉ , ⌈ s 2 ⌉ ). Beside the original rules, we allow three new quantifications : We lift constructs of realizer at the level of the logic, 1 We allow quantification over programs, 2 14 / 41 Realizability and parametricity in pure type systems Marc Lasson

  16. From P to P 2 – Definitions Given a PTS P = ( S , A , R ), we define P 2 = ( S 2 , A 2 , R 2 ) by S 2 = S ∪ { ⌈ s ⌉ | s ∈ S} A 2 = A ∪ { ( ⌈ s 1 ⌉ , ⌈ s 2 ⌉ ) | ( s 1 , s 2 ) ∈ A} R 2 = R ∪ { ( ⌈ s 1 ⌉ , ⌈ s 2 ⌉ , ⌈ s 3 ⌉ ) , (s 1 , ⌈ s 3 ⌉ , ⌈ s 3 ⌉ ) | ( s 1 , s 2 , s 3 ) ∈ R} ∪ { (s 1 , ⌈ s 2 ⌉ , ⌈ s 2 ⌉ ) | ( s 1 , s 2 ) ∈ A} For each sort s we add a copy ⌈ s ⌉ , For each axiom ( s 1 , s 2 ) we add the axiom ( ⌈ s 1 ⌉ , ⌈ s 2 ⌉ ). Beside the original rules, we allow three new quantifications : We lift constructs of realizer at the level of the logic, 1 We allow quantification over programs, 2 We allow the formation of predicates. 3 14 / 41 Realizability and parametricity in pure type systems Marc Lasson

  17. A bit of vocabulary a type inhabits an original sort s Γ ⊢ A : s a formula inhabits a lifted sort ⌈ s ⌉ Γ ⊢ A : ⌈ s ⌉ a program inhabits a type Γ ⊢ A : B : s a proof inhabits a formula Γ ⊢ A : B : ⌈ s ⌉ types & programs are first-level terms formulas & proofs are second-level terms 15 / 41 Realizability and parametricity in pure type systems Marc Lasson

  18. Second-order logic F 2 The PTS F 2 has the following specification: S 2 = { ⋆, � , ⌈ ⋆ ⌉ , ⌈ � ⌉ } F A 2 = { ( ⋆, � ) , ( ⌈ ⋆ ⌉ , ⌈ � ⌉ ) } F R 2 = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) , ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( ⌈ � ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) F ( ⋆, ⌈ � ⌉ , ⌈ � ⌉ ) , ( ⋆, ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( � , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) } . The logic F 2 is a second-order logic with higher-order typed individuals ( FA 2 with higher-order individuals). 16 / 41 Realizability and parametricity in pure type systems Marc Lasson

  19. Second-order logic F 2 The PTS F 2 has the following specification: S 2 = { ⋆, � , ⌈ ⋆ ⌉ , ⌈ � ⌉ } F A 2 = { ( ⋆, � ) , ( ⌈ ⋆ ⌉ , ⌈ � ⌉ ) } F R 2 = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) , ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( ⌈ � ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) F ( ⋆, ⌈ � ⌉ , ⌈ � ⌉ ) , ( ⋆, ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( � , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) } . The logic F 2 is a second-order logic with higher-order typed individuals ( FA 2 with higher-order individuals). ⌈ ⋆ ⌉ is the sort of formulas (like Prop in Coq). 16 / 41 Realizability and parametricity in pure type systems Marc Lasson

  20. Second-order logic F 2 The PTS F 2 has the following specification: S 2 = { ⋆, � , ⌈ ⋆ ⌉ , ⌈ � ⌉ } F A 2 = { ( ⋆, � ) , ( ⌈ ⋆ ⌉ , ⌈ � ⌉ ) } F R 2 = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) , ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( ⌈ � ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) F ( ⋆, ⌈ � ⌉ , ⌈ � ⌉ ) , ( ⋆, ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( � , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) } . The logic F 2 is a second-order logic with higher-order typed individuals ( FA 2 with higher-order individuals). ⌈ ⋆ ⌉ is the sort of formulas (like Prop in Coq). ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to build implication P → Q . 16 / 41 Realizability and parametricity in pure type systems Marc Lasson

  21. Second-order logic F 2 The PTS F 2 has the following specification: S 2 = { ⋆, � , ⌈ ⋆ ⌉ , ⌈ � ⌉ } F A 2 = { ( ⋆, � ) , ( ⌈ ⋆ ⌉ , ⌈ � ⌉ ) } F R 2 = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) , ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( ⌈ � ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) F ( ⋆, ⌈ � ⌉ , ⌈ � ⌉ ) , ( ⋆, ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( � , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) } . The logic F 2 is a second-order logic with higher-order typed individuals ( FA 2 with higher-order individuals). ⌈ ⋆ ⌉ is the sort of formulas (like Prop in Coq). ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to build implication P → Q . ( ⋆, ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to quantify over programs ∀ x : τ. P . 16 / 41 Realizability and parametricity in pure type systems Marc Lasson

  22. Second-order logic F 2 The PTS F 2 has the following specification: S 2 = { ⋆, � , ⌈ ⋆ ⌉ , ⌈ � ⌉ } F A 2 = { ( ⋆, � ) , ( ⌈ ⋆ ⌉ , ⌈ � ⌉ ) } F R 2 = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) , ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( ⌈ � ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) F ( ⋆, ⌈ � ⌉ , ⌈ � ⌉ ) , ( ⋆, ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( � , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) } . The logic F 2 is a second-order logic with higher-order typed individuals ( FA 2 with higher-order individuals). ⌈ ⋆ ⌉ is the sort of formulas (like Prop in Coq). ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to build implication P → Q . ( ⋆, ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to quantify over programs ∀ x : τ. P . ( � , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to quantify over types ∀ α. P . 16 / 41 Realizability and parametricity in pure type systems Marc Lasson

  23. Second-order logic F 2 The PTS F 2 has the following specification: S 2 = { ⋆, � , ⌈ ⋆ ⌉ , ⌈ � ⌉ } F A 2 = { ( ⋆, � ) , ( ⌈ ⋆ ⌉ , ⌈ � ⌉ ) } F R 2 = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) , ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( ⌈ � ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) F ( ⋆, ⌈ � ⌉ , ⌈ � ⌉ ) , ( ⋆, ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( � , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) } . The logic F 2 is a second-order logic with higher-order typed individuals ( FA 2 with higher-order individuals). ⌈ ⋆ ⌉ is the sort of formulas (like Prop in Coq). ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to build implication P → Q . ( ⋆, ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to quantify over programs ∀ x : τ. P . ( � , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to quantify over types ∀ α. P . ( ⋆, ⌈ � ⌉ , ⌈ � ⌉ ) is used to build signatures of predicates. They are all of the form τ 1 → · · · → τ n → ⌈ ⋆ ⌉ . 16 / 41 Realizability and parametricity in pure type systems Marc Lasson

  24. Second-order logic F 2 The PTS F 2 has the following specification: S 2 = { ⋆, � , ⌈ ⋆ ⌉ , ⌈ � ⌉ } F A 2 = { ( ⋆, � ) , ( ⌈ ⋆ ⌉ , ⌈ � ⌉ ) } F R 2 = { ( ⋆, ⋆, ⋆ ) , ( � , ⋆, ⋆ ) , ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( ⌈ � ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) F ( ⋆, ⌈ � ⌉ , ⌈ � ⌉ ) , ( ⋆, ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) , ( � , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) } . The logic F 2 is a second-order logic with higher-order typed individuals ( FA 2 with higher-order individuals). ⌈ ⋆ ⌉ is the sort of formulas (like Prop in Coq). ( ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to build implication P → Q . ( ⋆, ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to quantify over programs ∀ x : τ. P . ( � , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to quantify over types ∀ α. P . ( ⋆, ⌈ � ⌉ , ⌈ � ⌉ ) is used to build signatures of predicates. They are all of the form τ 1 → · · · → τ n → ⌈ ⋆ ⌉ . ( ⌈ � ⌉ , ⌈ ⋆ ⌉ , ⌈ ⋆ ⌉ ) allows to quantify over predicates ∀ X : τ 1 → · · · → τ n → ⌈ ⋆ ⌉ . P . 16 / 41 Realizability and parametricity in pure type systems Marc Lasson

  25. Second-order logic F 2 – A stratified presentation We can prove that F 2 is equivalent to this presentation: programs: t , t 1 , t 2 := | λ x : τ. t | Λ α.τ | ( t 1 t 2 ) | ( t τ ) x types: τ, σ := α | σ → τ | ∀ α.τ 17 / 41 Realizability and parametricity in pure type systems Marc Lasson

  26. Second-order logic F 2 – A stratified presentation We can prove that F 2 is equivalent to this presentation: programs: t , t 1 , t 2 := | λ x : τ. t | Λ α.τ | ( t 1 t 2 ) | ( t τ ) x types: τ, σ := α | σ → τ | ∀ α.τ formulas: P , Q := X t 1 ... t n | P → Q | ∀ α. P | ∀ x : τ. P | ∀ X : τ 1 → ... → τ n → Prop . P 17 / 41 Realizability and parametricity in pure type systems Marc Lasson

  27. Second-order logic F 2 – A stratified presentation We can prove that F 2 is equivalent to this presentation: programs: t , t 1 , t 2 := | λ x : τ. t | Λ α.τ | ( t 1 t 2 ) | ( t τ ) x types: τ, σ := α | σ → τ | ∀ α.τ formulas: P , Q := X t 1 ... t n | P → Q | ∀ α. P | ∀ x : τ. P | ∀ X : τ 1 → ... → τ n → Prop . P + a proof system 17 / 41 Realizability and parametricity in pure type systems Marc Lasson

  28. Second-order logic F 2 – A stratified presentation We can prove that F 2 is equivalent to this presentation: programs: t , t 1 , t 2 := | λ x : τ. t | Λ α.τ | ( t 1 t 2 ) | ( t τ ) x types: τ, σ := α | σ → τ | ∀ α.τ formulas: P , Q := X t 1 ... t n | P → Q | ∀ α. P | ∀ x : τ. P | ∀ X : τ 1 → ... → τ n → Prop . P + a proof system In the PTS presentation, proofs are represented by terms 17 / 41 Realizability and parametricity in pure type systems Marc Lasson

  29. Second-order logic: F 2 – Examples Here are some examples in F 2 . Truth: ⊤ ≡ ∀ X : ⌈ ⋆ ⌉ . X → X and is proved by λ X : ⌈ ⋆ ⌉ ( h : X ) . h 18 / 41 Realizability and parametricity in pure type systems Marc Lasson

  30. Second-order logic: F 2 – Examples Here are some examples in F 2 . Truth: ⊤ ≡ ∀ X : ⌈ ⋆ ⌉ . X → X and is proved by λ X : ⌈ ⋆ ⌉ ( h : X ) . h Leibniz equality: x = τ y ≡ ∀ X : τ → ⌈ ⋆ ⌉ . X x → X y 18 / 41 Realizability and parametricity in pure type systems Marc Lasson

  31. Second-order logic: F 2 – Examples Here are some examples in F 2 . Truth: ⊤ ≡ ∀ X : ⌈ ⋆ ⌉ . X → X and is proved by λ X : ⌈ ⋆ ⌉ ( h : X ) . h Leibniz equality: x = τ y ≡ ∀ X : τ → ⌈ ⋆ ⌉ . X x → X y ∀ ( α : ⋆ )( x : α ) . x = α x is proved by λ ( α : ⋆ )( x : α )( X : α → ⌈ ⋆ ⌉ )( h : X x ) . h 18 / 41 Realizability and parametricity in pure type systems Marc Lasson

  32. Second-order logic: F 2 – Examples Here are some examples in F 2 . Truth: ⊤ ≡ ∀ X : ⌈ ⋆ ⌉ . X → X and is proved by λ X : ⌈ ⋆ ⌉ ( h : X ) . h Leibniz equality: x = τ y ≡ ∀ X : τ → ⌈ ⋆ ⌉ . X x → X y ∀ ( α : ⋆ )( x : α ) . x = α x is proved by λ ( α : ⋆ )( x : α )( X : α → ⌈ ⋆ ⌉ )( h : X x ) . h The induction principle over Nat: N ≡ λ x : Nat . ∀ X : Nat → ⌈ ⋆ ⌉ . ( ∀ y : Nat . X y → X (Succ y )) → X 0 → X x 18 / 41 Realizability and parametricity in pure type systems Marc Lasson

  33. Lifting and projection Lifting ⌈·⌉ embeds the first level toward its copy. ⌈∀ α : ⋆.α → α ⌉ ≡ ∀ X : ⌈ ⋆ ⌉ . X → X ⌈ Nat ⌉ ≡ ∀ X : ⌈ ⋆ ⌉ . ( X → X ) → X → X 19 / 41 Realizability and parametricity in pure type systems Marc Lasson

  34. Lifting and projection Projection ⌊·⌋ collapses the second level toward the first level. ⌊ t 1 = τ t 2 ⌋ ≡ ⌊∀ X : τ → ⌈ ⋆ ⌉ . X t 1 → X t 2 ⌋ ≡ ∀ α : ⋆.α → α ⌊ N t ⌋ ≡ ⌊∀ X : Nat → ⌈ ⋆ ⌉ . ( ∀ y : Nat . X y → X (Succ y )) → X 0 → X t ⌋ ≡ ∀ α. ( α → α ) → α → α ≡ Nat 19 / 41 Realizability and parametricity in pure type systems Marc Lasson

  35. Lifting and projection – Lemmas 20 / 41 Realizability and parametricity in pure type systems Marc Lasson

  36. Lifting and projection – Lemmas Lifting preserves typing Γ ⊢ A : B : s ⇒ ⌈ Γ ⌉ ⊢ ⌈ A ⌉ : ⌈ B ⌉ : ⌈ s ⌉ 20 / 41 Realizability and parametricity in pure type systems Marc Lasson

  37. Lifting and projection – Lemmas Lifting preserves typing Γ ⊢ A : B : s ⇒ ⌈ Γ ⌉ ⊢ ⌈ A ⌉ : ⌈ B ⌉ : ⌈ s ⌉ Lifting preserves β -reduction A − → β B ⇒ ⌈ A ⌉− → β ⌈ B ⌉ 20 / 41 Realizability and parametricity in pure type systems Marc Lasson

  38. Lifting and projection – Lemmas Lifting preserves typing Γ ⊢ A : B : s ⇒ ⌈ Γ ⌉ ⊢ ⌈ A ⌉ : ⌈ B ⌉ : ⌈ s ⌉ Lifting preserves β -reduction A − → β B ⇒ ⌈ A ⌉− → β ⌈ B ⌉ Projection preserves typing Γ ⊢ A : B : ⌈ s ⌉ ⇒ ⌊ Γ ⌋ ⊢ ⌊ A ⌋ : ⌊ B ⌋ : s 20 / 41 Realizability and parametricity in pure type systems Marc Lasson

  39. Lifting and projection – Lemmas Lifting preserves typing Γ ⊢ A : B : s ⇒ ⌈ Γ ⌉ ⊢ ⌈ A ⌉ : ⌈ B ⌉ : ⌈ s ⌉ Lifting preserves β -reduction A − → β B ⇒ ⌈ A ⌉− → β ⌈ B ⌉ Projection preserves typing Γ ⊢ A : B : ⌈ s ⌉ ⇒ ⌊ Γ ⌋ ⊢ ⌊ A ⌋ : ⌊ B ⌋ : s Projection preserves or removes β -reduction If A − → β B , then either ⌊ A ⌋− → β ⌊ B ⌋ or ⌊ A ⌋ = ⌊ B ⌋ . 20 / 41 Realizability and parametricity in pure type systems Marc Lasson

  40. Lifting and projection – Lemmas Lifting preserves typing Γ ⊢ A : B : s ⇒ ⌈ Γ ⌉ ⊢ ⌈ A ⌉ : ⌈ B ⌉ : ⌈ s ⌉ Lifting preserves β -reduction A − → β B ⇒ ⌈ A ⌉− → β ⌈ B ⌉ Projection preserves typing Γ ⊢ A : B : ⌈ s ⌉ ⇒ ⌊ Γ ⌋ ⊢ ⌊ A ⌋ : ⌊ B ⌋ : s Projection preserves or removes β -reduction If A − → β B , then either ⌊ A ⌋− → β ⌊ B ⌋ or ⌊ A ⌋ = ⌊ B ⌋ . Projection is the left inverse of lifting ⌊⌈ A ⌉⌋ = A 20 / 41 Realizability and parametricity in pure type systems Marc Lasson

  41. Strong normalization Theorem (Normalization) If P is strongly normalizing, so is P 2 . 21 / 41 Realizability and parametricity in pure type systems Marc Lasson

  42. Strong normalization Theorem (Normalization) If P is strongly normalizing, so is P 2 . Proof sketch. If a term A is typable in P 2 and not normalizable, then : one of the first-level subterms of A is not normalizable, or the first-level term ⌊ A ⌋ is not normalizable. 21 / 41 Realizability and parametricity in pure type systems Marc Lasson

  43. Introduction 1 Building the logic 2 Parametricity and realizability in PTS’s 3 An application and an extension 4 22 / 41 Realizability and parametricity in pure type systems Marc Lasson

  44. Parametricity and realizability in PTS’s In the following sections, We are going to define a parametricity relation : ( A , B ) ∈ � C � ( we no longer use the notation A ∼ C B ) and a realizability relation : A � B . 23 / 41 Realizability and parametricity in pure type systems Marc Lasson

  45. Parametricity and realizability in PTS’s In the following sections, We are going to define a parametricity relation : ( A , B ) ∈ � C � ( we no longer use the notation A ∼ C B ) and a realizability relation : A � B . Formula Formula � �� � � �� � ( · , · ) ∈ � · � · � · ↑ ↑ ↑ ↑ ↑ Program / Program / Type Program / Formula 23 / 41 Realizability and parametricity in pure type systems Marc Lasson

  46. Parametricity and realizability in PTS’s In the following sections, We are going to define a parametricity relation : ( A , B ) ∈ � C � ( we no longer use the notation A ∼ C B ) and a realizability relation : A � B . Formula Formula � �� � � �� � ( · , · ) ∈ � · � · � · ↑ ↑ ↑ ↑ ↑ Program / Program / Type Program / Formula Type / Type / Sort Type / Lifted Sort 23 / 41 Realizability and parametricity in pure type systems Marc Lasson

  47. Parametricity in PTS’s We define at the same time : a ternary notation ( · , · ) ∈ � · � a unary notation � · � 24 / 41 Realizability and parametricity in pure type systems Marc Lasson

  48. Parametricity in PTS’s We define at the same time : a ternary notation ( · , · ) ∈ � · � a unary notation � · � We want to satisfy the abstraction theorem: 24 / 41 Realizability and parametricity in pure type systems Marc Lasson

  49. Parametricity in PTS’s We define at the same time : a ternary notation ( · , · ) ∈ � · � a unary notation � · � We want to satisfy the abstraction theorem: Theorem (abstraction) If Γ ⊢ A : B : s, then � Γ � ⊢ � A � : ( A , A ) ∈ � B � : ⌈ s ⌉ 24 / 41 Realizability and parametricity in pure type systems Marc Lasson

  50. Parametricity in PTS’s – Products, sorts and variables ( A 1 , A 2 ) ∈ � ∀ x : B . C � ≡ ∀ ( x 1 : B )( x 2 : B ) . ( x 1 , x 2 ) ∈ � B � → ( A 1 x 1 , A 2 x 2 ) ∈ � C � 25 / 41 Realizability and parametricity in pure type systems Marc Lasson

  51. Parametricity in PTS’s – Products, sorts and variables ( A 1 , A 2 ) ∈ � ∀ x : B . C � ≡ ∀ ( x 1 : B )( x 2 : B )( x R : ( x 1 , x 2 ) ∈ � B � ) . ( A 1 x 1 , A 2 x 2 ) ∈ � C � 25 / 41 Realizability and parametricity in pure type systems Marc Lasson

  52. Parametricity in PTS’s – Products, sorts and variables ( A 1 , A 2 ) ∈ � ∀ x : B . C � ≡ ∀ ( x 1 : B )( x 2 : B )( x R : ( x 1 , x 2 ) ∈ � B � ) . ( A 1 x 1 , A 2 x 2 ) ∈ � C � ( A 1 , A 2 ) ∈ � x � ≡ ( x R A 1 A 2 ) 25 / 41 Realizability and parametricity in pure type systems Marc Lasson

  53. Parametricity in PTS’s – Products, sorts and variables ( A 1 , A 2 ) ∈ � ∀ x : B . C � ≡ ∀ ( x 1 : B )( x 2 : B )( x R : ( x 1 , x 2 ) ∈ � B � ) . ( A 1 x 1 , A 2 x 2 ) ∈ � C � ( A 1 , A 2 ) ∈ � x � ≡ ( x R A 1 A 2 ) ( A 1 , A 2 ) ∈ � s � ≡ A 1 → A 2 → ⌈ s ⌉ 25 / 41 Realizability and parametricity in pure type systems Marc Lasson

  54. Parametricity in PTS’s – Example ( t 1 , t 2 ) ∈ � ∀ α : ⋆.α → α � ≡ ∀ ( α 1 : ⋆ )( α 2 : ⋆ )( α R : ( α 1 , α 2 ) ∈ � ⋆ � ) . ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � 26 / 41 Realizability and parametricity in pure type systems Marc Lasson

  55. Parametricity in PTS’s – Example ( t 1 , t 2 ) ∈ � ∀ α : ⋆.α → α � ≡ ∀ ( α 1 : ⋆ )( α 2 : ⋆ )( α R : ( α 1 , α 2 ) ∈ � ⋆ � ) . ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ( α 1 , α 2 ) ∈ � ⋆ � ≡ α 1 → α 2 → ⌈ ⋆ ⌉ 26 / 41 Realizability and parametricity in pure type systems Marc Lasson

  56. Parametricity in PTS’s – Example ( t 1 , t 2 ) ∈ � ∀ α : ⋆.α → α � ≡ ∀ ( α 1 : ⋆ )( α 2 : ⋆ )( α R : α 1 → α 2 → ⌈ ⋆ ⌉ ) . ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ( α 1 , α 2 ) ∈ � ⋆ � ≡ α 1 → α 2 → ⌈ ⋆ ⌉ 26 / 41 Realizability and parametricity in pure type systems Marc Lasson

  57. Parametricity in PTS’s – Example ( t 1 , t 2 ) ∈ � ∀ α : ⋆.α → α � ≡ ∀ ( α 1 : ⋆ )( α 2 : ⋆ )( α R : α 1 → α 2 → ⌈ ⋆ ⌉ ) . ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ( α 1 , α 2 ) ∈ � ⋆ � ≡ α 1 → α 2 → ⌈ ⋆ ⌉ ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ≡ 26 / 41 Realizability and parametricity in pure type systems Marc Lasson

  58. Parametricity in PTS’s – Example ( t 1 , t 2 ) ∈ � ∀ α : ⋆.α → α � ≡ ∀ ( α 1 : ⋆ )( α 2 : ⋆ )( α R : α 1 → α 2 → ⌈ ⋆ ⌉ ) . ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ( α 1 , α 2 ) ∈ � ⋆ � ≡ α 1 → α 2 → ⌈ ⋆ ⌉ ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ≡ ∀ ( x 1 : α )( x 2 : α ) . ( x 1 , x 2 ) ∈ � α � → ( t 1 α 1 x 1 , t 2 α 2 x 2 ) ∈ � α � 26 / 41 Realizability and parametricity in pure type systems Marc Lasson

  59. Parametricity in PTS’s – Example ( t 1 , t 2 ) ∈ � ∀ α : ⋆.α → α � ≡ ∀ ( α 1 : ⋆ )( α 2 : ⋆ )( α R : α 1 → α 2 → ⌈ ⋆ ⌉ ) . ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ( α 1 , α 2 ) ∈ � ⋆ � ≡ α 1 → α 2 → ⌈ ⋆ ⌉ ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ≡ ∀ ( x 1 : α )( x 2 : α ) . ( x 1 , x 2 ) ∈ � α � → ( t 1 α 1 x 1 , t 2 α 2 x 2 ) ∈ � α � ( A , B ) ∈ � α � ≡ α R A B 26 / 41 Realizability and parametricity in pure type systems Marc Lasson

  60. Parametricity in PTS’s – Example ( t 1 , t 2 ) ∈ � ∀ α : ⋆.α → α � ≡ ∀ ( α 1 : ⋆ )( α 2 : ⋆ )( α R : α 1 → α 2 → ⌈ ⋆ ⌉ ) . ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ( α 1 , α 2 ) ∈ � ⋆ � ≡ α 1 → α 2 → ⌈ ⋆ ⌉ ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ≡ ∀ ( x 1 : α )( x 2 : α ) . α R x 1 x 2 → α R ( t 1 α 1 x 1 ) ( t 2 α 2 x 2 ) ( A , B ) ∈ � α � ≡ α R A B 26 / 41 Realizability and parametricity in pure type systems Marc Lasson

  61. Parametricity in PTS’s – Example ( t 1 , t 2 ) ∈ � ∀ α : ⋆.α → α � ≡ ∀ ( α 1 : ⋆ )( α 2 : ⋆ )( α R : α 1 → α 2 → ⌈ ⋆ ⌉ ) . ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ( α 1 , α 2 ) ∈ � ⋆ � ≡ α 1 → α 2 → ⌈ ⋆ ⌉ ( t 1 α 1 , t 2 α 2 ) ∈ � α → α � ≡ ∀ ( x 1 : α )( x 2 : α ) . α R x 1 x 2 → α R ( t 1 α 1 x 1 ) ( t 2 α 2 x 2 ) ( A , B ) ∈ � α � ≡ α R A B Finally, ( t 1 , t 2 ) ∈ � ∀ α : ⋆.α → α � ≡ ∀ ( α 1 : ⋆ )( α 2 : ⋆ )( α R : α 1 → α 2 → ⌈ ⋆ ⌉ ) . ∀ ( x 1 : α 1 )( x 2 : α 2 ) .α R x 1 x 2 → α R ( t 1 α 1 x 1 ) ( t 2 α 2 x 2 ) 26 / 41 Realizability and parametricity in pure type systems Marc Lasson

  62. Parametricity in PTS’s Here is the transformation for the product: ( A 1 , A 2 ) ∈ � ∀ x : B . C � ≡ ∀ ( x 1 : B )( x 2 : B )( x R : ( x 1 , x 2 ) ∈ � B � ) . ( A 1 x 1 , A 2 x 2 ) ∈ � C � 27 / 41 Realizability and parametricity in pure type systems Marc Lasson

  63. Parametricity in PTS’s Here is the transformation for the product: ( A 1 , A 2 ) ∈ � ∀ x : B . C � ≡ ∀ ( x 1 : B )( x 2 : B )( x R : ( x 1 , x 2 ) ∈ � B � ) . ( A 1 x 1 , A 2 x 2 ) ∈ � C � If we have ⊢ ( λ x : B . A ) : ( ∀ x : B . C ), since we want to satisfy the abstraction theorem, we must take � λ x : B . A � ≡ λ ( x 1 : B )( x 2 : B )( x R : ( x 1 , x 2 ) ∈ � B � ) . � A � 27 / 41 Realizability and parametricity in pure type systems Marc Lasson

  64. Parametricity in PTS’s Here is the transformation for the product: ( A 1 , A 2 ) ∈ � ∀ x : B . C � ≡ ∀ ( x 1 : B )( x 2 : B )( x R : ( x 1 , x 2 ) ∈ � B � ) . ( A 1 x 1 , A 2 x 2 ) ∈ � C � If we have ⊢ ( λ x : B . A ) : ( ∀ x : B . C ), since we want to satisfy the abstraction theorem, we must take � λ x : B . A � ≡ λ ( x 1 : B )( x 2 : B )( x R : ( x 1 , x 2 ) ∈ � B � ) . � A � Symmetrically, we need to take � ( A B ) � ≡ ( � A � B B � B � ). 27 / 41 Realizability and parametricity in pure type systems Marc Lasson

  65. Parametricity in PTS’s – The whole definition Definition (parametricity) ( C 1 , C 2 ) ∈ � s � ( C 1 , C 2 ) ∈ � ∀ x : A . B � ( C 1 , C 2 ) ∈ � T � � x � � λ x : A . B � � A B � � T � 28 / 41 Realizability and parametricity in pure type systems Marc Lasson

  66. Parametricity in PTS’s – The whole definition Definition (parametricity) ( C 1 , C 2 ) ∈ � s � = C 1 → C 2 → ⌈ s ⌉ ( C 1 , C 2 ) ∈ � ∀ x : A . B � = ∀ ( x 1 : A )( x 2 : A )( x R : ( x 1 , x 2 ) ∈ � A � ) . ( C 1 x 1 , C 2 x 2 ) ∈ � B � ( C 1 , C 2 ) ∈ � T � = ( � T � C 1 C 2 ) otherwise � x � � λ x : A . B � � A B � � T � Theorem (abstraction) If Γ ⊢ A : B : s, then � Γ � ⊢ � A � : ( A , A ) ∈ � B � : ⌈ s ⌉ 28 / 41 Realizability and parametricity in pure type systems Marc Lasson

  67. Parametricity in PTS’s – The whole definition Definition (parametricity) ( C 1 , C 2 ) ∈ � s � = C 1 → C 2 → ⌈ s ⌉ ( C 1 , C 2 ) ∈ � ∀ x : A . B � = ∀ ( x 1 : A )( x 2 : A )( x R : ( x 1 , x 2 ) ∈ � A � ) . ( C 1 x 1 , C 2 x 2 ) ∈ � B � ( C 1 , C 2 ) ∈ � T � = ( � T � C 1 C 2 ) otherwise � x � = x R � λ x : A . B � = λ ( x 1 : A )( x 2 : A )( x R : ( x 1 , x 2 ) ∈ � A � ) . � B � � A B � = � A � B B � B � � T � = λ ( x 1 x 2 : T ) . ( x 1 , x 2 ) ∈ � T � otherwise Theorem (abstraction) If Γ ⊢ A : B : s, then � Γ � ⊢ � A � : ( A , A ) ∈ � B � : ⌈ s ⌉ 28 / 41 Realizability and parametricity in pure type systems Marc Lasson

  68. Parametricity in PTS’s – The n -ary version Definition (parametricity) C ∈ � s � n = C → ⌈ s ⌉ C ∈ � ∀ x : A . B � n = ∀ x : A . ∀ x R : x ∈ � A � n . z x ∈ � B � n C ∈ � T � n = � T � n C otherwise � x � n = x R � λ x : A . B � n = λ x : A . λ x R : x ∈ � A � n . � B � n � A B � n = � A � n B � B � n � T � n = λ z : T . C ∈ � T � n otherwise Theorem (abstraction) If Γ ⊢ A : B : s, then � Γ � n ⊢ � A � n : A ∈ � B � n : ⌈ s ⌉ 29 / 41 Realizability and parametricity in pure type systems Marc Lasson

  69. Realizability in second-order logic In traditional presentation of realizability: t � P → Q ≡ ∀ x , x � P → ( t x ) � Q 30 / 41 Realizability and parametricity in pure type systems Marc Lasson

  70. Realizability in second-order logic In traditional presentation of realizability: t � P → Q ≡ ∀ x , x � P → ( t x ) � Q t � ∀ x . P ≡ ∀ x , t � P 30 / 41 Realizability and parametricity in pure type systems Marc Lasson

  71. Realizability in second-order logic In traditional presentation of realizability: t � P → Q ≡ ∀ x , x � P → ( t x ) � Q t � ∀ x . P ≡ ∀ x , t � P There are two kinds of quantification: First-level quantification Second-level quantification 30 / 41 Realizability and parametricity in pure type systems Marc Lasson

  72. Realizability in second-order logic In traditional presentation of realizability: t � P → Q ≡ ∀ x , x � P → ( t x ) � Q t � ∀ x . P ≡ ∀ x , t � P There are two kinds of quantification: First-level quantification Second-level quantification 30 / 41 Realizability and parametricity in pure type systems Marc Lasson

  73. Realizability in second-order logic In traditional presentation of realizability: t � P → Q ≡ ∀ x , x � P → ( t x ) � Q t � ∀ x . P ≡ ∀ x , t � P There are two kinds of quantification: First-level quantification : uniform, Second-level quantification 30 / 41 Realizability and parametricity in pure type systems Marc Lasson

  74. Realizability in second-order logic In traditional presentation of realizability: t � P → Q ≡ ∀ x , x � P → ( t x ) � Q t � ∀ x . P ≡ ∀ x , t � P There are two kinds of quantification: First-level quantification : uniform, Second-level quantification 30 / 41 Realizability and parametricity in pure type systems Marc Lasson

  75. Realizability in second-order logic In traditional presentation of realizability: t � P → Q ≡ ∀ x , x � P → ( t x ) � Q t � ∀ x . P ≡ ∀ x , t � P There are two kinds of quantification: First-level quantification : uniform, Second-level quantification : things happen. 30 / 41 Realizability and parametricity in pure type systems Marc Lasson

Recommend


More recommend