a taste of linear logic for staged computation
play

A taste of linear logic for staged computation Hubert Godfroy - PowerPoint PPT Presentation

A taste of linear logic for staged computation Hubert Godfroy Jean-Yves Marion First GDRI-LL meeting 4 fvrier 2016 1/27 Plan Staged computation A correct system Sof modality Low level correspondence 2/27 Staged computation Paradigm


  1. A taste of linear logic for staged computation Hubert Godfroy Jean-Yves Marion First GDRI-LL meeting 4 février 2016 1/27

  2. Plan Staged computation A correct system Sof modality Low level correspondence 2/27

  3. Staged computation ◮ Paradigm where computation is split in stages ◮ Partial evaluation ◮ Run-time code generation ◮ Community uses tools like modal or temporal logic (MetaML) R. Davies and F. Pfenning. A modal analysis of staged computation. Principles of programming languages , 1996. R. Davies. A temporal-logic approach to binding-time analysis. Logic in Computer Science , pages 184–195, Jul 1996. 3/27

  4. Staged computation in everyday life ◮ Python ◮ Strings are frozen codes. ◮ eval launches execution of strings. ◮ Meta-OCaml ◮ � t � are frozen codes. ◮ pieces of unevaluated code can be inserted in frozen terms with ∼ . � f t 1 ∼ (( λx.x ) � t 2 � ) � → � f t 1 t 2 � 4/27

  5. Syntactic mark for value ◮ � t � is a value for any t . ◮ � ( λx.x ) t � and � t � are not β -equivalent... ◮ ...but computations are frozen. 5/27

  6. Syntactic mark for value ◮ � t � is a value for any t . ◮ � ( λx.x ) t � and � t � are not β -equivalent... ◮ ...but computations are frozen. � = β � ( λx.x ) t � � t � run run t 5/27

  7. Why is it important? ◮ Frozen codes are used to denote data like string. ◮ Patern matching on data. ◮ Confluence should be preserved 6/27

  8. Why is it important? ◮ Frozen codes are used to denote data like string. ◮ Patern matching on data. ◮ Confluence should be preserved Counter example match � ( λx.x )( λx.x ) � with App � → 1 | Lam � → 2 1 2 6/27

  9. Example: creation of data breaks confluence It should not exist a reifying operator returning the code (data) of a term. Otherwise... If θ were this operator θ (( λx.x ) t ) � ( λx.x ) t � � = β � t � Corollary θ is not expressible in λ -calculus. 7/27

  10. Frozen codes are mutable ◮ Substitution in frozen terms are allowed � t � [ x → t ′ ] = � t [ x → t ′ ] � 8/27

  11. Frozen codes are mutable ◮ Substitution in frozen terms are allowed � t � [ x → t ′ ] = � t [ x → t ′ ] � ◮ Put a frozen term into another let � x � = � t ′ � in � t � � t � [ x → t ′ ] � t [ x → t ′ ] � = → Subtly ◮ Same confluence issue than reification ◮ Cannot plug terms which are note data. ◮ If t → t ′ : ( λx. � x � ) t � t � � = � t ′ � 8/27

  12. Usages IRL ◮ Partial evaluation optimisations: n-ary function can be specialized by inspecting their code: pow is the power function. without specialization pow 2 = � λx.x × pow 1 � pow 2 = � λx.x × x × 1 � with specialization ◮ Dynamic code generation ◮ Code protection: ◮ if d = � � t 0 � is the encryption of � t 0 � and dec : � � t � � → � t � is the decrypting function, run ( dec d ) → t 0 ◮ Chained processus: t n = run ( dec � � t n − 1 � ) 9/27

  13. Plan Staged computation A correct system Sof modality Low level correspondence 10/27

  14. Modal Logic ◮ ∀ t, � t � is in NF (data). 11/27

  15. Modal Logic ◮ ∀ t, � t � is in NF (data). ◮ Meta-binder: let � x � = t ′ in t ◮ Meta-redex: ( let � x � = � t ′ � in t ) → t [ x/t ′ ] 11/27

  16. Modal Logic ◮ ∀ t, � t � is in NF (data). ◮ Meta-binder: let � x � = t ′ in t ◮ Meta-redex: ( let � x � = � t ′ � in t ) → t [ x/t ′ ] ◮ Typing rules: Box GVar Let Γ ⊢ t ′ : � A � ∆ � ⊢ t : A � x � : A ∈ Γ � x � : A, Γ ⊢ t : B Γ ⊢ let � x � = t ′ in t : B � ∆ � , Γ ⊢ � t � : � A Γ ⊢ x : A def where Γ = x i : A i , then � Γ � = � x i � : � A i . 11/27

  17. Linear Logic ◮ ∀ t, � t � is in NF (data). ◮ Meta-binder: let � x � = t ′ in t ◮ Meta-redex: ( let � x � = � t ′ � in t ) → t [ x/t ′ ] ◮ Typing rules: Promotion Dereliction Let Γ ⊢ t ′ : ! A � ∆ � ⊢ t : A � x � : A ∈ Γ � x � : A, Γ ⊢ t : B Γ ⊢ let � x � = t ′ in t : B � ∆ � , Γ ⊢ � t � : ! A Γ ⊢ x : A def where Γ = x i : A i , then � Γ � = � x i � : ! A i . 11/27

  18. Exemple ◮ Writing: ( let � x � = � t ′ � in � t � ) → � t [ x/t ′ ] � 12/27

  19. Exemple ◮ Writing: ( let � x � = � t ′ � in � t � ) → � t [ x/t ′ ] � Use this derivation (for t = x ): Dereliction Γ ′ , � x � : ! A ⊢ x : A · · · Promotion Γ ⊢ � t ′ � : ! A Γ, � x � : ! A ⊢ � x � : ! A Abstraction Γ ⊢ let � x � = � t ′ � in � x � : ! A 12/27

  20. Exemple ◮ Writing: ( let � x � = � t ′ � in � t � ) → � t [ x/t ′ ] � Use this derivation (for t = x ): Dereliction Γ ′ , � x � : ! A ⊢ x : A · · · Promotion Γ ⊢ � t ′ � : ! A Γ, � x � : ! A ⊢ � x � : ! A Abstraction Γ ⊢ let � x � = � t ′ � in � x � : ! A ◮ Execution: def = λx. let � y � = x in y run 12/27

  21. Exemple ◮ Writing: ( let � x � = � t ′ � in � t � ) → � t [ x/t ′ ] � Use this derivation (for t = x ): Dereliction Γ ′ , � x � : ! A ⊢ x : A · · · Promotion Γ ⊢ � t ′ � : ! A Γ, � x � : ! A ⊢ � x � : ! A Abstraction Γ ⊢ let � x � = � t ′ � in � x � : ! A ◮ Execution: def = λx. let � y � = x in y run Use this derivation: Var Γ, y : A ⊢ y : A Dereliction Γ, � y � : ! A ⊢ y : A Let Γ, x : ! A ⊢ let � y � = x in y : A Abstraction Γ ⊢ λx. let � y � = x in y : ! A → A 12/27

  22. Exemple ◮ Writing: ( let � x � = � t ′ � in � t � ) → � t [ x/t ′ ] � Use this derivation (for t = x ): Dereliction Γ ′ , � x � : ! A ⊢ x : A · · · Promotion Γ ⊢ � t ′ � : ! A Γ, � x � : ! A ⊢ � x � : ! A Abstraction Γ ⊢ let � x � = � t ′ � in � x � : ! A ◮ Execution: def = λx. let � y � = x in y run Use this derivation: Var Γ, y : A ⊢ y : A Dereliction Γ, � y � : ! A ⊢ y : A Let Γ, x : ! A ⊢ let � y � = x in y : A Abstraction Γ ⊢ λx. let � y � = x in y : ! A → A ⇒ Both use Dereliction . 12/27

  23. Exemple ◮ Writing: ( let � x � = � t ′ � in � t � ) → � t [ x/t ′ ] � Use this derivation (for t = x ): Dereliction Γ ′ , � x � : ! A ⊢ x : A · · · Promotion Γ ⊢ � t ′ � : ! A Γ, � x � : ! A ⊢ � x � : ! A Abstraction Γ ⊢ let � x � = � t ′ � in � x � : ! A ◮ Execution: def = λx. let � y � = x in y run Use this derivation: Var Γ, y : A ⊢ y : A Dereliction Γ, � y � : ! A ⊢ y : A Let Γ, x : ! A ⊢ let � y � = x in y : A Abstraction Γ ⊢ λx. let � y � = x in y : ! A → A ⇒ Both use Dereliction . Qestion What is the logical meaning of Dereliction in this system? 12/27

  24. Plan Staged computation A correct system Sof modality Low level correspondence 13/27

  25. Sof promotion Dereliction afer Promotion is used for writing, contrary to alone Dereliction used to execute data. 14/27

  26. Sof promotion Dereliction afer Promotion is used for writing, contrary to alone Dereliction used to execute data. Idea Compose Dereliction and Promotion ! SoftPromotion Γ ⊢ t : A � Γ � ⊢ � t � : ! A 14/27

  27. Sof promotion Dereliction afer Promotion is used for writing, contrary to alone Dereliction used to execute data. Idea Compose Dereliction and Promotion ! SoftPromotion Γ ⊢ t : A � Γ � ⊢ � t � : ! A Consequences ◮ No more Dereliction rule for writing ◮ Dereliction used only for execution of data ◮ Ex.: Var · · · Γ ′ , x : A ⊢ x : A SoftPromotion Γ ⊢ � t ′ � : ! A Γ, � x � : ! A ⊢ � x � : ! A Abstraction Γ ⊢ let � x � = � t ′ � in � x � : ! A 14/27

  28. Language behavior Abstraction Application Var Γ ⊢ t ′ : A Γ, x : A ⊢ t : B Γ ⊢ t : A → B Γ ⊢ t t ′ : B Γ, x : A ⊢ x : A Γ ⊢ λx.t : A → B Let SoftPromotion Dereliction Γ ⊢ t ′ : ! A Γ, � x � : ! A ⊢ t : B x i : A i ⊢ t : B Γ ⊢ let � x � = t ′ in t : B Γ, � x i � : ! A i ⊢ � t � : ! B Γ, � x � : ! A ⊢ x : A Abilities Properties inherited from languages inspired by modal logic. ◮ program generation (plug data into another) ◮ execution Properties ◮ Language is confluent ◮ Type system has subject reduction property 15/27

  29. Language behavior Abstraction Application Var Γ ⊢ t ′ : A Γ, x : A ⊢ t : B Γ ⊢ t : A → B Γ ⊢ t t ′ : B Γ, x : A ⊢ x : A Γ ⊢ λx.t : A → B Let SoftPromotion Dereliction Γ ⊢ t ′ : ! A Γ, � x � : ! A ⊢ t : B x i : A i ⊢ t : B Γ ⊢ let � x � = t ′ in t : B Γ, � x i � : ! A i ⊢ � t � : ! B Γ, � x � : ! A ⊢ x : A Abilities Properties inherited from languages inspired by modal logic. ◮ program generation (plug data into another) ◮ execution Properties ◮ Language is confluent ◮ Type system has subject reduction property Missing ◮ No reflexion possibilities ◮ No syntactic analysis of data 15/27

Recommend


More recommend