unnesting of copatterns
play

Unnesting of Copatterns RTA-TLCA, 15 July 2014 Anton Setzer - PowerPoint PPT Presentation

Unnesting of Copatterns RTA-TLCA, 15 July 2014 Anton Setzer Andreas Abel Brigitte Pientka David Thibodeau Swansea Gothenburg Montreal Montreal UK Sweden Canada Canada Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 1/ 30


  1. Unnesting of Copatterns RTA-TLCA, 15 July 2014 Anton Setzer Andreas Abel Brigitte Pientka David Thibodeau Swansea Gothenburg Montreal Montreal UK Sweden Canada Canada Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 1/ 30

  2. Pattern and Copattern Matching Unnesting of Copatterns/Patterns Proof of Conservatity and Preservation of SN/WN Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 2/ 30

  3. Pattern and Copattern Matching Pattern and Copattern Matching Unnesting of Copatterns/Patterns Proof of Conservatity and Preservation of SN/WN Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 3/ 30

  4. Pattern and Copattern Matching Natural Numbers Syntax for Algebraic Data Types in Paper Nat := µ X . � zero 1 | suc X � Introduction Rule (All constructors will have exactly one argument) zero : 1 → Nat suc : Nat → Nat Elimination Rule (Pattern Matching) pred : Nat → Nat pred (zero x ) = ? pred (suc n ) = ? Full recursion allowed (normalisation for individual terms see later) Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 4/ 30

  5. Pattern and Copattern Matching Nested Patterns and CC-Pattern-Sets pred : Nat → Nat pred (zero x ) = ? pred (suc n ) = ? Pattern matching on 1 (containing ()) yields the nested pattern pred : Nat → Nat pred (zero ()) = ? pred (suc n ) = ? which formally is the coverage complete ( cc ) pattern set pred : Nat → Nat ⊳ | ( · ⊢ pred (zero ()) : Nat) ( n : Nat ⊢ pred (suc n ) : Nat) Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 5/ 30

  6. Pattern and Copattern Matching Coverage Complete Rule Sets (CC-Rule Sets) After full pattern derived we fill in the “?” pred : Nat → Nat pred (zero ()) = zero () pred (suc n ) = n corresponds to the coverage complete ( cc ) rule set pred : Nat → Nat ⊳ | ( · ⊢ pred (zero ()) − → zero () : Nat) ( n : Nat ⊢ pred (suc n ) − → n : Nat) Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 6/ 30

  7. Pattern and Copattern Matching Stream Stream := ν X . { head : Nat , tail : X } (In paper called StrN) . tail . tail . tail s 2 s 3 s 1 · · · . head . head . head n 2 n 3 n 1 Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 7/ 30

  8. Pattern and Copattern Matching Stream Elimination Rule If s : Stream then s . head : Nat s . tail : Stream . head, . tail treated like application. Introduction Rule (Copattern Matching) inc : Nat → Stream inc n . head = n inc n . tail = inc ( n + 1) Informally inc n = n , n + 1 , n + 2 , . . . Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 8/ 30

  9. Pattern and Copattern Matching CC-Rule/Pattern Set inc : Nat → Stream inc n . head = n inc n . tail = inc ( n + 1) This corresponds to the cc-pattern-set inc : Nat → Stream ⊳ | ( n : Nat ⊢ inc n . head : Nat) ( n : Nat ⊢ inc n . tail : Stream) and cc-rule-set inc : Nat → Stream ⊳ | ( n : Nat ⊢ inc n . head − → n : Nat) ( n : Nat ⊢ inc n . tail − → inc ( n + 1) : Stream) Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 9/ 30

  10. Pattern and Copattern Matching cyc n Let N be fixed . For n we define a stream which is informally given as cyc n = n , n − 1 , n − 2 , . . . , 0 , N , N − 1 , N − 2 , . . . , 0 , N , N − 1 , . . . . tail . tail . tail . tail cyc cyc N cyc 0 N − 1 · · · . head . head . head N N − 1 0 Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 10/ 30

  11. Pattern and Copattern Matching Development of cyc (Paper contains rules for deriving cc-pattern/rule-sets .) The simplest pattern matching is by itself: cyc : Nat → Stream ⊳ | ( · ⊢ cyc : Nat → Stream) Copattern matching for functions is application : cyc : Nat → Stream ⊳ | ( n : Nat ⊢ cyc n : Stream) Copattern matching on Stream yields: cyc : Nat → Stream ⊳ | ( n : Nat ⊢ cyc n . head : Nat) ( n : Nat ⊢ cyc n . tail : Stream) Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 11/ 30

  12. Pattern and Copattern Matching Development of cyc (Cont.) Pattern matching on Nat yields: ( n : Nat ⊢ cyc n . head : Nat) cyc : Nat → Stream ⊳ | ( x : 1 ⊢ cyc (zero x ) . tail : Stream) ( n : Nat ⊢ cyc (suc n ) . tail : Stream) Pattern matching on 1 yields: ( n : Nat ⊢ cyc n . head : Nat) cyc : Nat → Stream ⊳ | ( · ⊢ cyc (zero ()) . tail : Stream) ( n : Nat ⊢ cyc (suc n ) . tail : Stream) By adding results we obtain a cc-rule-set: ( n : Nat ⊢ cyc n . head − → n :Nat) cyc : Nat → Stream ⊳ | ( · ⊢ cyc (zero ()) . tail − → cyc N :Stream) ( n : Nat ⊢ cyc (suc n ) . tail − → cyc n : Stream) Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 12/ 30

  13. Unnesting of Copatterns/Patterns Pattern and Copattern Matching Unnesting of Copatterns/Patterns Proof of Conservatity and Preservation of SN/WN Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 13/ 30

  14. Unnesting of Copatterns/Patterns Unnesting of cyc ( n : Nat ⊢ cyc n . head − → n :Nat) ( · ⊢ cyc (zero ()) . tail − → cyc N :Stream) cyc : Nat → Stream ⊳ | ( n : Nat ⊢ cyc (suc n ) . tail − → cyc n : Stream) We unnest the last step (pattern matching on 1 ) and delegate it to a new function g 2 ( n : Nat ⊢ cyc n . head − → n :Nat) cyc : Nat → Stream ⊳ | ( x : 1 ⊢ cyc (zero x ) . tail − → g 2 x :Stream) ( n : Nat ⊢ cyc (suc n ) . tail − → cyc n : Stream) g 2 : 1 → Stream ⊳ | ( · ⊢ g 2 () − → cyc N : Stream) Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 14/ 30

  15. Unnesting of Copatterns/Patterns Unnesting of cyc (Cont) ( n : Nat ⊢ cyc n . head − → n :Nat) cyc : Nat → Stream ⊳ | ( x : 1 ⊢ cyc (zero x ) . tail − → g 2 x :Stream) ( n : Nat ⊢ cyc (suc n ) . tail − → cyc n : Stream) g 2 : 1 → Stream ⊳ | ( · ⊢ g 2 () − → cyc N : Stream) Now we unnest pattern matching on x : Nat and delegate it to a new function g 1 : cyc : Nat → Stream ⊳ | ( n : Nat ⊢ cyc n . head − → n : Nat) ( n : Nat ⊢ cyc n . tail − → g 1 n : Stream) g 1 : Nat → Stream ⊳ | ( x : 1 ⊢ g 1 (zero x ) − → g 2 x : Stream) ( n : Nat ⊢ g 1 (suc n ) − → cyc n : Stream) g 2 : 1 → Stream ⊳ | ( · ⊢ g 2 () − → cyc N : Stream) Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 15/ 30

  16. Unnesting of Copatterns/Patterns Simple Pattern ◮ End result is simple pattern: ◮ There is at most one proper pattern/copattern step which is the last one. Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 16/ 30

  17. Proof of Conservatity and Preservation of SN/WN Pattern and Copattern Matching Unnesting of Copatterns/Patterns Proof of Conservatity and Preservation of SN/WN Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 17/ 30

  18. Proof of Conservatity and Preservation of SN/WN Programs Definition (a) A program P is given by constants with their types and a cc-rule-set for each constant (referring to terms in the same language). (b) A program P ′ extends P if the it contains all the constants of P with the same types (but not necessarily the same cc-rule-sets). Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 18/ 30

  19. Proof of Conservatity and Preservation of SN/WN Conservative Extensions, Preservation of SN, WN Definition Let P ′ be a program extending P . (a) P ′ is a conservative extension of P iff ∀ t , t ′ ∈ Term P . t − P t ′ ⇔ t − → ∗ → ∗ P ′ t ′ (b) P ′ preserves strong normalisation ( SN ) iff ∀ t ∈ Term P . t ∈ SN( P ) ⇔ t ∈ SN( P ′ ) (c) P ′ preserves weak normalisation ( WN ) iff ∀ t ∈ Term P . t ∈ WN( P ) ⇔ t ∈ WN( P ′ ) Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 19/ 30

  20. Proof of Conservatity and Preservation of SN/WN Conservative Extension P ′ P ′ P ′ · · · t n ∈ Term P′ t 1 ∈ Term P′ t 2 ∈ Term P′ P ′ P ′ t ′ ∈ Term P t ∈ Term P Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 20/ 30

  21. Proof of Conservatity and Preservation of SN/WN Conservative Extension P ′ P ′ P ′ · · · t n ∈ Term P′ t 1 ∈ Term P′ t 2 ∈ Term P′ P ′ P ′ t ′ ∈ Term P t ∈ Term P P P ∃ t ′ ∃ t ′ 2 ∈ Term P ∃ t ′ 1 ∈ Term P m ∈ Term P · · · P P P Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 20/ 30

  22. Proof of Conservatity and Preservation of SN/WN Preservation of ¬ SN t 1 ∈ Term P′ t 2 ∈ Term P′ t 3 ∈ Term P′ · · · t �∈ SN( P ′ ) Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 21/ 30

  23. Proof of Conservatity and Preservation of SN/WN Preservation of ¬ SN t 1 ∈ Term P′ t 2 ∈ Term P′ t 3 ∈ Term P′ · · · t �∈ SN( P ′ ) t �∈ SN( P ) ∃ t ′ ∃ t ′ ∃ t ′ 1 ∈ Term P 2 ∈ Term P 2 ∈ Term P · · · Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 21/ 30

  24. Proof of Conservatity and Preservation of SN/WN Main Theorem Theorem Let P be a program. There exist an extension of P which is ◮ conservative, ◮ preserves SN , ◮ preserves WN ◮ and has only simple patterns. Setzer, Abel, Pientka, Thibodeau Unnesting of Copatterns 22/ 30

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend