a call by need lambda calculus with scoped work
play

A Call-by-Need Lambda Calculus with Scoped Work Decorations David - PowerPoint PPT Presentation

A Call-by-Need Lambda Calculus with Scoped Work Decorations David Sabel and Manfred Schmidt-Schau Goethe University Frankfurt am Main, Germany ATPS 2016, Vienna, Austria 1 Motivation Reasoning on program transformations, like map f ( map g


  1. A Call-by-Need Lambda Calculus with Scoped Work Decorations David Sabel and Manfred Schmidt-Schauß Goethe University Frankfurt am Main, Germany ATPS 2016, Vienna, Austria 1

  2. Motivation Reasoning on program transformations, like map f ( map g xs ) → map ( λx.f ( g x )) xs Are transformations optimizations / improvements ? w.r.t. time consumption, i.e. the number of computation steps in a core language of Haskell : extended polymorphically typed lambda calculus with call-by-need evaluation 2/18

  3. Some Previous and Related Work [Moran & Sands, POPL’99]: Improvement theory in an untyped call-by-need lambda calculus counting based on an abstract machine semantics tick-algebra for modular reasoning on improvements no concrete technique for list induction proofs [Hackett & Hutton, ICFP’14]: Improvement for worker-wrapper-transformations based on Moran & Sands’ tick algebra argue for the requirement of a typed language [Schmidt-Schauß & S., PPDP’15, IFL’15]: Improvement in call-by-need lambda calculi: untyped LR , typed LRP counting essential reduction steps of a small-step semantics core language with seq -operator proving list-laws being improvements, using work-decorations 3/18

  4. Motivation: Equational Reasoning for List-Expressions Example: s 1 := letrec xs = 0 : xs in xs s 2 := letrec y =(( λx.x ) 0 ) , xs = y : y : xs in xs s 3 := letrec y =(( λx.x ) 0 ) , xs = y : (( λx.x ) y ) : xs in xs s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) Contextual equivalence: s ∼ c t iff ∀ contexts C : C [ s ] ↓ ⇐ ⇒ C [ t ] ↓ Prove s i ∼ c s j for all i, j ∈ { 1 , 2 , 3 , 4 } 4/18

  5. Motivation: Equational Reasoning for List-Expressions Example: s 1 := letrec xs = 0 : xs in xs s 2 := letrec y =(( λx.x ) 0 ) , xs = y : y : xs in xs s 3 := letrec y =(( λx.x ) 0 ) , xs = y : (( λx.x ) y ) : xs in xs s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) Contextual equivalence: s ∼ c t iff ∀ contexts C : C [ s ] ↓ ⇐ ⇒ C [ t ] ↓ Prove s i ∼ c s j for all i, j ∈ { 1 , 2 , 3 , 4 } For list-expressions r 1 , r 2 define: r 1 R r 2 iff r 1 ∼ c ( h 1 : t 1 ) , r 2 ∼ c ( h 2 : t 2 ) such that h 1 ∼ c h 2 and t 1 R t 2 Principle of co-induction: r 1 gfp( R ) r 2 = ⇒ r 1 ∼ c r 2 4/18

  6. Motivation: Equational Reasoning for List-Expressions Example: s 1 := letrec xs = 0 : xs in xs s 2 := letrec y =(( λx.x ) 0 ) , xs = y : y : xs in xs s 3 := letrec y =(( λx.x ) 0 ) , xs = y : (( λx.x ) y ) : xs in xs s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) Contextual equivalence: s ∼ c t iff ∀ contexts C : C [ s ] ↓ ⇐ ⇒ C [ t ] ↓ Prove s i ∼ c s j for all i, j ∈ { 1 , 2 , 3 , 4 } For list-expressions r 1 , r 2 define: r 1 R r 2 iff r 1 ∼ c ( h 1 : t 1 ) , r 2 ∼ c ( h 2 : t 2 ) such that h 1 ∼ c h 2 and t 1 R t 2 Principle of co-induction: r 1 gfp( R ) r 2 = ⇒ r 1 ∼ c r 2 4/18

  7. Motivation: Equational Reasoning for List-Expressions Example: s 1 ∼ c 0 : 0 : ( letrec xs = 0 : xs in xs ) s 2 := letrec y =(( λx.x ) 0 ) , xs = y : y : xs in xs s 3 := letrec y =(( λx.x ) 0 ) , xs = y : (( λx.x ) y ) : xs in xs s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) Contextual equivalence: s ∼ c t iff ∀ contexts C : C [ s ] ↓ ⇐ ⇒ C [ t ] ↓ Prove s i ∼ c s j for all i, j ∈ { 1 , 2 , 3 , 4 } For list-expressions r 1 , r 2 define: r 1 R r 2 iff r 1 ∼ c ( h 1 : t 1 ) , r 2 ∼ c ( h 2 : t 2 ) such that h 1 ∼ c h 2 and t 1 R t 2 Principle of co-induction: r 1 gfp( R ) r 2 = ⇒ r 1 ∼ c r 2 4/18

  8. Motivation: Equational Reasoning for List-Expressions Example: s 1 ∼ c 0 : 0 : ( letrec xs = 0 : xs in xs ) s 2 := letrec y =(( λx.x ) 0 ) , xs = y : y : xs in xs s 3 := letrec y =(( λx.x ) 0 ) , xs = y : (( λx.x ) y ) : xs in xs s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) Contextual equivalence: s ∼ c t iff ∀ contexts C : C [ s ] ↓ ⇐ ⇒ C [ t ] ↓ Prove s i ∼ c s j for all i, j ∈ { 1 , 2 , 3 , 4 } For list-expressions r 1 , r 2 define: r 1 R r 2 iff r 1 ∼ c ( h 1 : t 1 ) , r 2 ∼ c ( h 2 : t 2 ) such that h 1 ∼ c h 2 and t 1 R t 2 Principle of co-induction: r 1 gfp( R ) r 2 = ⇒ r 1 ∼ c r 2 4/18

  9. Motivation: Equational Reasoning for List-Expressions Example: s 1 ∼ c 0 : 0 : ( letrec xs = 0 : xs in xs ) s 2 ∼ c 0 : 0 : ( letrec xs = 0 : 0 : xs in xs ) s 3 := letrec y =(( λx.x ) 0 ) , xs = y : (( λx.x ) y ) : xs in xs s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) Contextual equivalence: s ∼ c t iff ∀ contexts C : C [ s ] ↓ ⇐ ⇒ C [ t ] ↓ Prove s i ∼ c s j for all i, j ∈ { 1 , 2 , 3 , 4 } For list-expressions r 1 , r 2 define: r 1 R r 2 iff r 1 ∼ c ( h 1 : t 1 ) , r 2 ∼ c ( h 2 : t 2 ) such that h 1 ∼ c h 2 and t 1 R t 2 Principle of co-induction: r 1 gfp( R ) r 2 = ⇒ r 1 ∼ c r 2 4/18

  10. Motivation: Equational Reasoning for List-Expressions Example: s 1 ∼ c 0 : 0 : ( letrec xs = 0 : xs in xs ) s 2 ∼ c 0 : 0 : ( letrec xs = 0 : 0 : xs in xs ) s 3 := letrec y =(( λx.x ) 0 ) , xs = y : (( λx.x ) y ) : xs in xs s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) Contextual equivalence: s ∼ c t iff ∀ contexts C : C [ s ] ↓ ⇐ ⇒ C [ t ] ↓ Prove s i ∼ c s j for all i, j ∈ { 1 , 2 , 3 , 4 } For list-expressions r 1 , r 2 define: r 1 R r 2 iff r 1 ∼ c ( h 1 : t 1 ) , r 2 ∼ c ( h 2 : t 2 ) such that h 1 ∼ c h 2 and t 1 R t 2 Principle of co-induction: r 1 gfp( R ) r 2 = ⇒ r 1 ∼ c r 2 4/18

  11. Motivation: Equational Reasoning for List-Expressions Example: s 1 ∼ c 0 : 0 : ( letrec xs = 0 : xs in xs ) s 2 ∼ c 0 : 0 : ( letrec xs = 0 : 0 : xs in xs ) s 3 ∼ c 0 : 0 : ( letrec xs = 0 : 0 : xs in xs ) s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) Contextual equivalence: s ∼ c t iff ∀ contexts C : C [ s ] ↓ ⇐ ⇒ C [ t ] ↓ Prove s i ∼ c s j for all i, j ∈ { 1 , 2 , 3 , 4 } For list-expressions r 1 , r 2 define: r 1 R r 2 iff r 1 ∼ c ( h 1 : t 1 ) , r 2 ∼ c ( h 2 : t 2 ) such that h 1 ∼ c h 2 and t 1 R t 2 Principle of co-induction: r 1 gfp( R ) r 2 = ⇒ r 1 ∼ c r 2 4/18

  12. Motivation: Equational Reasoning for List-Expressions Example: s 1 ∼ c 0 : 0 : ( letrec xs = 0 : xs in xs ) s 2 ∼ c 0 : 0 : ( letrec xs = 0 : 0 : xs in xs ) s 3 ∼ c 0 : 0 : ( letrec xs = 0 : 0 : xs in xs ) s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) Contextual equivalence: s ∼ c t iff ∀ contexts C : C [ s ] ↓ ⇐ ⇒ C [ t ] ↓ Prove s i ∼ c s j for all i, j ∈ { 1 , 2 , 3 , 4 } For list-expressions r 1 , r 2 define: r 1 R r 2 iff r 1 ∼ c ( h 1 : t 1 ) , r 2 ∼ c ( h 2 : t 2 ) such that h 1 ∼ c h 2 and t 1 R t 2 Principle of co-induction: r 1 gfp( R ) r 2 = ⇒ r 1 ∼ c r 2 4/18

  13. Motivation: Equational Reasoning for List-Expressions Example: s 1 ∼ c 0 : 0 : ( letrec xs = 0 : xs in xs ) s 2 ∼ c 0 : 0 : ( letrec xs = 0 : 0 : xs in xs ) s 3 ∼ c 0 : 0 : ( letrec xs = 0 : 0 : xs in xs ) s 4 ∼ c 0 : 0 : ( letrec xs = λy.y : ( xs y ) in ( xs 0 )) Contextual equivalence: s ∼ c t iff ∀ contexts C : C [ s ] ↓ ⇐ ⇒ C [ t ] ↓ Prove s i ∼ c s j for all i, j ∈ { 1 , 2 , 3 , 4 } For list-expressions r 1 , r 2 define: r 1 R r 2 iff r 1 ∼ c ( h 1 : t 1 ) , r 2 ∼ c ( h 2 : t 2 ) such that h 1 ∼ c h 2 and t 1 R t 2 Principle of co-induction: r 1 gfp( R ) r 2 = ⇒ r 1 ∼ c r 2 4/18

  14. Motivation: Equational Reasoning for List-Expressions Example: s 1 ∼ c 0 : 0 : ( letrec xs = 0 : xs in xs ) s 2 ∼ c 0 : 0 : ( letrec xs = 0 : 0 : xs in xs ) s 3 ∼ c 0 : 0 : ( letrec xs = 0 : 0 : xs in xs ) s 4 ∼ c 0 : 0 : ( letrec xs = λy.y : ( xs y ) in ( xs 0 )) further processing with the tails indeed shows s i ∼ c s j Contextual equivalence: s ∼ c t iff ∀ contexts C : C [ s ] ↓ ⇐ ⇒ C [ t ] ↓ Prove s i ∼ c s j for all i, j ∈ { 1 , 2 , 3 , 4 } For list-expressions r 1 , r 2 define: r 1 R r 2 iff r 1 ∼ c ( h 1 : t 1 ) , r 2 ∼ c ( h 2 : t 2 ) such that h 1 ∼ c h 2 and t 1 R t 2 Principle of co-induction: r 1 gfp( R ) r 2 = ⇒ r 1 ∼ c r 2 4/18

  15. Motivation: Reasoning Including Resources In [Schmidt-Schauß & S., IFL 2015]: analogous reasoning , but w.r.t. improvement and cost-equivalence Improvement and Cost-Equivalence Improvement : s � t iff s ∼ c t and ∀ closing contexts C : rln ( C [ s ]) ≤ rln ( C [ t ]) where rln ( · ) is the reduction length, counting essential reduction steps Cost-Equivalence : s ≈ t iff s � t and t � s 5/18

  16. Motivation: Reasoning including Resources Equational reasoning w.r.t. cost equivalence: s 1 := letrec xs = 0 : xs in xs s 2 := letrec y =(( λx.x ) 0 ) , xs = y : y : xs in xs s 3 := letrec y =(( λx.x ) 0 ) , xs = y : (( λx.x ) y ) : xs in xs s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) 6/18

  17. Motivation: Reasoning including Resources Equational reasoning w.r.t. cost equivalence: s 1 := letrec xs = 0 : xs in xs s 2 := letrec y =(( λx.x ) 0 ) , xs = y : y : xs in xs s 3 := letrec y =(( λx.x ) 0 ) , xs = y : (( λx.x ) y ) : xs in xs s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) 6/18

  18. Motivation: Reasoning including Resources Equational reasoning w.r.t. cost equivalence: s 1 ≈ 0 : 0 : ( letrec xs = 0 : xs in xs ) s 2 := letrec y =(( λx.x ) 0 ) , xs = y : y : xs in xs s 3 := letrec y =(( λx.x ) 0 ) , xs = y : (( λx.x ) y ) : xs in xs s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) 6/18

  19. Motivation: Reasoning including Resources Equational reasoning w.r.t. cost equivalence: s 1 ≈ 0 : 0 : ( letrec xs = 0 : xs in xs ) s 2 := letrec y =(( λx.x ) 0 ) , xs = y : y : xs in xs s 3 := letrec y =(( λx.x ) 0 ) , xs = y : (( λx.x ) y ) : xs in xs s 4 := letrec xs = λy.y : ( xs y ) in ( xs 0 ) 6/18

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