relating system f and 2 a case study in coq abella and
play

Relating System F and 2: A Case Study in Coq, Abella and Beluga - PowerPoint PPT Presentation

Relating System F and 2: A Case Study in Coq, Abella and Beluga Jonas Kaiser Brigitte Pientka Gert Smolka FSCD 2017, Oxford September 4, 2017 saarland university computer science saarland System F [Girard 72] / PTLC [Reynolds 74]


  1. Relating System F and λ 2: A Case Study in Coq, Abella and Beluga Jonas Kaiser Brigitte Pientka Gert Smolka FSCD 2017, Oxford September 4, 2017 saarland university computer science

  2. saarland System F [Girard ’72] / PTLC [Reynolds ’74] university computer science Some History Developed in the context of proof theory and polymorphism. Commonly phrased as a two-sorted system: Types & Terms We consider F as presented in [Harper ’13] . ◮ Explicitly scopes type variables. Meanwhile . . . Study of CC led to single-sorted Pure Type Systems (PTS): ◮ The λ -cube of [Barendregt ’91] . System F appears as the corner λ 2. Goal: Transport of Results F � λ 2 bidirectional reduction of typing Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 2 / 25

  3. saarland Related Work university computer science The reduction result is partially discussed in [Geuvers ’93] . ◮ Primarily argues the forward preservation of typing. ◮ The syntactic correspondence is left implicit. Coq formalisation of the full reduction in [K/Tebbi/Smolka ’17] . ◮ Pairs of translation functions establish the syntactic correspondence. ◮ Requires involved cancellation laws. ◮ Proofs based on an extension of context morphism lemmas [Goguen/McKinna ’97, Adams ’06] . Goal of this work: Correspondence Proof as benchmark for reasoning about syntax and contextual information . Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 3 / 25

  4. saarland Syntactic Variants F and λ 2 university computer science Two-sorted non-uniform syntax: Ty F A , B ::= X | A → B | ∀ X . A Tm F s , t ::= x | s t | λ x : A . s | s A | Λ X . s Type Formation ∆ ⊢ A ty Typing ∆; Γ ⊢ s : F A Single-sorted uniform PTS syntax: Tm λ a , b ::= x | ∗ | � | a b | λ x : a . b | Π x : a . b Typing Ψ ⊢ a : 2 b Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 4 / 25

  5. saarland Syntactic Correspondence university computer science Ty F Tm λ Θ ⊢ A ∼ a well-formed types propositions 1) injective 2) functional 3) L-total & preserving Tm F 4) R-total & preserving well-typed terms proofs Θ; Σ ⊢ s ≈ b Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 5 / 25

  6. saarland Syntactic Correspondence – Two Complications university computer science 1 Non-uniform vs. uniform: A → B ? Π x : a . b ∀ X . B 2 Open terms & contextual assumptions about ◮ well-formedness : in X → X , is X in scope? ◮ typing : in a b , is b a proof or proposition? ◮ related variables : in the variable case, does Θ ⊢ X ∼ x hold? Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 6 / 25

  7. saarland The Reduction Proof: F � λ 2 university computer science Assume we are given syntactic relations ∼ and ≈ which are both: 1 functional 2 injective 3 left-total and judgement preserving on suitable fragment 4 right-total and judgement preserving on suitable fragment Theorem (Reduction F � λ 2) ⊢ A ty ⇐ ⇒ ∃ a . ⊢ A ∼ a ∧ ⊢ a : 2 ∗ ⊢ s : F A ⇐ ⇒ ∃ ba . ⊢ s ≈ b ∧ ⊢ A ∼ a ∧ ⊢ b : 2 a ∧ ⊢ a : 2 ∗ Theorem (Reduction λ 2 � F) ⊢ a : 2 ∗ ⇐ ⇒ ∃ A . ⊢ A ∼ a ∧ ⊢ A ty ⊢ b : 2 a ∧ ⊢ a : 2 ∗ ⇐ ⇒ ∃ sA . ⊢ s ≈ b ∧ ⊢ A ∼ a ∧ ⊢ s : F A Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 7 / 25

  8. saarland Formalising the Proof university computer science We consider three approaches: Coq first-order de Bruijn, par. substitutions, invariants Abella HOAS, ∇ -quantification, relational proof search HOAS, 1 st -class contexts, context schemas Beluga Topics of Interest Representation of syntax and judgements. Management of local variable binding. Tracking of contextual information. Technicalities: Usability / Libraries / Tool Support Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 8 / 25

  9. saarland university computer science – Coq – first-order de Bruijn, parallel substitutions, invariants Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 9 / 25

  10. saarland Coq – Representation university computer science Syntax: first-order de Bruijn A , B ::= n ty | A → B | ∀ . A n ∈ N s , t ::= n tm | s t | λ A . s | s A | Λ . s Typing contexts: ∆ : N – excl. upper bound for free type variables Γ : list Ty F – dangling indices reference by position Judgements as inductive predicates, e.g.: _; _ ⊢ _ : F _ : N → list Ty F → Tm F → Ty F → Prop Parallel substitutions from Autosubst library [Schäfer/Tebbi/Smolka ’15] : σ : N → T ( ∀ . A )[ σ ] = ∀ . A [ ⇑ σ ] ⇑ σ := 0 ty · ( σ ◦ ↑ ) Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 10 / 25

  11. saarland Coq – Relating Indices university computer science Relating open terms requires explicit tracking of related indices: R , S : list ( N × N ) Traversal of binders requires context adjustments: R ⇑ ⊢ B ∼ b R ext ⊢ A ∼ a R ⊢ A ∼ a R ⊢ A → B ∼ Π a . b R ⊢ ∀ . A ∼ Π ∗ . a R ext := (0 , 0) :: map ( ↑ × ↑ ) R R ⇑ := map (id × ↑ ) R R ⇑ ; S ext ⊢ s ≈ b R ⊢ A ∼ a R ; S ⊢ λ A . s ≈ λ a . b Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 11 / 25

  12. saarland Coq – Custom Invariants university computer science Left-Totality and Preservation of Type Formation of ∼ 1 Define Invariant: R ∆ − → Ψ := ∀ x < ∆ . ∃ y . ( x , y ) ∈ R ∧ ( y : 2 ∗ ) ∈ λ Ψ 2 Prove Extension Laws: → Ψ ⇒ ∆ R ⇑ R ∆ − − → Ψ , a – ext. with new term variable → Ψ ⇒ ∆ + 1 R ext R ∆ − − → Ψ , ∗ – ext. with new type variable 3 Prove by induction on ∆ ⊢ A ty : R ∆ ⊢ A ty ⇒ ∀ R , Ψ . ∆ − → Ψ ⇒ ∃ a . R ⊢ A ∼ a ∧ Ψ ⊢ a : 2 ∗ 4 Repeat for remaining three preservation results. Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 12 / 25

  13. saarland university computer science – Abella – HOAS, ∇ -quantification, relational proof search Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 13 / 25

  14. saarland Abella [Miller, Chaudhuri et al. ’14] university computer science Two-level logic: Specification Level: λ Prolog, HOAS, logic predicates, proof search λ _ . _ : Ty F → (Tm F → Tm F ) → Tm F Π_ . _ : Tm λ → (Tm λ → Tm λ ) → Tm λ _ : F _ : Tm F → Ty F → o + λ Prolog rules _ ≈ _ : Tm F → Tm λ → o + λ Prolog rules Reasoning Level: G – intuitionistic, predicative, STT, ∇ -quantification n 1 , n 2 , . . . – nominals represent free variables ∇ x . ∇ y . x � = y – theorem of G { L ⊢ J } – logical embedding Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 14 / 25

  15. saarland Abella – Logical Embedding university computer science { _ ⊢ _ } : [ o ] → o → Prop { L ⊢ J } holds in G iff J has a λ Prolog-derivation from hypotheses L . Mobility of binders, consider: Π x y . x ∼ y = ◮ s � x � ≈ b � y � Λ . s ≈ λ ∗ . b { L ⊢ Π x y . x ∼ y = ◮ s � x � ≈ b � y �} � ∇ x , y . { L , x ∼ y ⊢ s � x � ≈ b � y �} � { L , n 1 ∼ n 2 ⊢ s � n 1 � ≈ b � n 2 �} { L ⊢ A ∼ a } { L , n 1 ∼ n 2 ⊢ s � n 1 � ≈ b � n 2 �} inst & cut { L ⊢ s � A � ≈ b � a �} Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 15 / 25

  16. saarland Abella – Context Management university computer science Contexts L : [ o ] are lists of arbitrary logical predicate instances. The embedding has a backchaining rule: J ∈ L ⇒ { L ⊢ J } We want typing/relational contexts that only contain information about variables, i.e. nominals . ⇒ inductive G -predicates: Define C ≈ : [ o ] → Prop by C ≈ ( • ); ∇ x y , C ≈ ( L , x ∼ y ) := C ≈ ( L ); ∇ x y , C ≈ ( L , x ≈ y ) := C ≈ ( L ) . 1 Avoid spurious instances of backchaining. 2 Constrains L to exactly track related variables. 3 Forces L to be injective, functional & range-disjoint. Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 16 / 25

  17. saarland Abella – Relating Contexts university computer science Left-Totality and Preservation of Type Formation of ∼ 1 Define a compound inductive predicate C R : C R ( L F | L ≈ | L 2 ) x , y fresh for L F , L ≈ , L 2 C R ( • | • | • ) C R ( L F , x ty | L ≈ , x ∼ y | L 2 , y : 2 ∗ ) { L F ⊢ A ty } { L ≈ ⊢ A ∼ a } { L 2 ⊢ a : 2 ∗} C R ( L F | L ≈ | L 2 ) x , y fresh for L F , L ≈ , L 2 , A , a C R ( L F , x : F A | L ≈ , x ≈ y | L 2 , y : 2 a ) 2 Prove extraction laws that yield connected assumptions: x ty ∈ L F ⇒ C R ( L F | L ≈ | L 2 ) ⇒ . . . 3 Prove by induction on { L F ⊢ A ty } : { L F ⊢ A ty } ⇒ ∀ L ≈ L 2 . C R ( L F | L ≈ | L 2 ) ⇒ ∃ a . { L ≈ ⊢ A ∼ a } ∧ { L 2 ⊢ a : 2 ∗} Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 17 / 25

  18. saarland university computer science – Beluga – HOAS, 1 st -class contexts, context schemas Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 18 / 25

  19. saarland Beluga – Contextual Objects university computer science Objects K (types, terms, derivations) paired with 1 st -class context Γ: [Γ ⊢ K ] No concept of free variable : ◮ In Coq: 0 ⊢ 0 ty → 0 ty ty ⇒ ⊥ provable. ◮ In Abella: {• ⊢ n 0 → n 0 ty } ⇒ ⊥ provable. ◮ In Beluga [ • ⊢ x → x ty ] syntactically ill-formed since x / ∈ • . Jonas Kaiser F and λ 2 – A Case Study September 4, 2017 19 / 25

Recommend


More recommend