in lambda calculus with letrec
play

in Lambda Calculus with letrec (Work In Progress) Jan Rochel and - PowerPoint PPT Presentation

Avoiding Repetitive Reduction Patterns in letrec Rochel, Grabmayer 1 Avoiding Repetitive Reduction Patterns in Lambda Calculus with letrec (Work In Progress) Jan Rochel and Clemens Grabmayer Dept. of Computer Science, and Dept. of


  1. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 1 Avoiding Repetitive Reduction Patterns in Lambda Calculus with letrec (Work In Progress) Jan Rochel and Clemens Grabmayer Dept. of Computer Science, and Dept. of Philosophy NWO-project Realising Optimal Sharing Utrecht University TERMGRAPH 2011 Saarbrücken, April 2 nd

  2. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 2 In this talk We report on: ◮ an optimising transformation for λ -calculus with letrec ◮ by which i.p. the cyclic passing on of unchanged arguments during evaluation can often be prevented

  3. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 3 In this talk We report on: ◮ an optimising transformation for λ -calculus with letrec ◮ by which i.p. the cyclic passing on of unchanged arguments during evaluation can often be prevented Examples: ◮ Haskell functions repeat , replicate , ++ , map , until ◮ a specification of the Thue–Morse sequence

  4. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 4 In this talk We report on: ◮ an optimising transformation for λ -calculus with letrec ◮ by which i.p. the cyclic passing on of unchanged arguments during evaluation can often be prevented Examples: ◮ Haskell functions repeat , replicate , ++ , map , until ◮ a specification of the Thue–Morse sequence Concepts used: ◮ visible/concealed redexes ◮ generalised β -reduction ◮ domination in digraphs ◮ static analysis of cyclically reappearing redexes

  5. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 5 λ -Terms and λ -Trees T V ::= ( variable ) T T | ( application ) λ V . T | ( abstraction )

  6. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 6 λ -Terms and λ -Trees T V ::= ( variable ) T T | ( application ) λ V . T | ( abstraction ) @ λ x 3 ( λ x . g ( f x )) 3 @ @ g f x

  7. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 7 β -Reduction ( λ x . M ) N M [ x := N ] → β @ λ x 3 @ ( λ x . g ( f x )) 3 g ( f 3 ) → β → β @ g @ @ 3 g f f x

  8. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 8 letrec -Terms and λ -Graphs T V ::= ( variable ) T T | ( application ) λ V . T | ( abstraction ) f ( T ,..., T ) | ( primitive functions ) let Defs in T | ( letrec ) Defs v 1 = T ... v n = T ::= ( equations ) ( v 1 ,..., v n distinct variables ) let repeat = λ x . x : repeat x in repeat

  9. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 9 letrec -Terms and λ -Graphs T V ::= ( variable ) T T | ( application ) λ V . T | ( abstraction ) f ( T ,..., T ) | ( primitive functions ) let Defs in T | ( letrec ) Defs v 1 = T ... v n = T ::= ( equations ) ( v 1 ,..., v n distinct variables ) let repeat = λ x . x : repeat x λ x in repeat : @ x x

  10. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 10 repeat let repeat = λ x . x : repeat x λ x in repeat : @ x x

  11. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 11 repeat λ x : @ x let repeat = λ x . x : repeat x λ x → ▽ x in repeat : λ x @ x : x @ x x

  12. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 12 repeat λ x : @ x λ x x let repeat = λ x . x : repeat x λ x : in repeat ։ ▽ : @ x @ x x x λ x : @ x x

  13. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 13 repeat λ x : let repeat = λ x . x : repeat x @ λ x x in repeat ։ ։ ▽ λ x : x : @ x x @ x . . . x

  14. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 14 Visible and concealed redexes @ 3 λ x @ @ g @ λ y x y Common practice in existing compilers: ◮ Exhaustive reduction of visible redexes

  15. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 15 Visible and concealed redexes @ 3 @ 3 λ x @ → β λ x @ @ g @ @ g λ y x x y Common practice in existing compilers: ◮ Exhaustive reduction of visible redexes

  16. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 16 Visible and concealed redexes @ 3 3 λ x @ → β @ @ g @ g λ y x x y Common practice in existing compilers: ◮ Exhaustive reduction of visible redexes ◮ This is in general not possible for concealed redexes

  17. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 17 repeat 3 @ 3 let repeat = λ x . x : repeat x λ x in repeat 3 : @ x x

  18. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 18 → ▽ @ λ x 3 : @ let repeat = λ x . x : repeat x x in ( λ x . x : repeat x ) 3 x λ x : @ x x

  19. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 19 @ λ x 3 : @ let repeat = λ x . x : repeat x x in ( λ x . x : repeat x ) 3 x λ x : @ x x

  20. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 20 → β : 3 @ 3 let repeat = λ x . x : repeat x in 3: repeat 3 λ x : @ x x

  21. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 21 → ▽ : 3 @ λ x 3 : let repeat = λ x . x : repeat x @ x in 3: ( λ x . x : repeat x ) 3 x λ x : @ x x

  22. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 22 : 3 @ λ x 3 : let repeat = λ x . x : repeat x @ x in 3: ( λ x . x : repeat x ) 3 x λ x : @ x x

  23. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 23 → β : 3 : 3 @ let repeat = λ x . x : repeat x 3 in 3:3: repeat 3 λ x : @ x x

  24. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 24 ։ ▽ , β ։ : 3 : 3:3: ... 3 : . . 3 .

  25. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 25 և և ▽ let rec = 3: rec in rec : 3

  26. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 26 → ▽ : let rec = 3: rec in 3: rec 3 : 3

  27. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 27 → ▽ : 3 : let rec = 3: rec in 3:3: rec 3 : 3

  28. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 28 repeat 3 @ 3 λ x : @ x x

  29. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 29 repeat 3 @ λ x 3 @ : 3 @ x λ x ։ ։ ▽ λ x x : : @ x @ x x . . . x

  30. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 30 repeat 3 @ λ x 3 @ : : 3 @ x 3 : λ x ։ β ։ ։ ▽ ։ 3 : λ x x : . . : 3 . @ x @ x x . . . x

  31. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 31 repeat 3 @ λ x 3 @ : : 3 @ x 3 : λ x ։ β ։ ։ ▽ ։ և և ▽ : 3 : λ x x : 3 . . : 3 . @ x @ x x . . . x

  32. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 32 repeat λ x : @ x x

  33. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 33 repeat λ x : @ x λ x ։ ։ ▽ λ x x : : @ x @ x x . . . x

  34. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 34 repeat λ x : λ x @ x λ x : ։ β ։ ։ ▽ ։ λ x x : : x : @ . x . . x @ x x . . . x

  35. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 35 repeat λ x : λ x λ x @ x λ x : ։ β ։ ։ ▽ ։ և և ▽ λ x x : : x : : @ . x . . x x @ x x . . . x

  36. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 36 Optimising repeat let repeat = λ x . x : repeat x in repeat λ x λ x = ∞ ▽ , β : : @ x x x let repeat = λ x . let xs = x : xs in xs in repeat

  37. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 37 Operational equivalence I Used here: = ∞ ։ ▽ ) ∗ ▽ , β = ( և և ▽ ∪ և և β ∪ ։ ։ β ∪ ։ as notion of operational equivalence.

  38. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 38 replicate replicate 0 x = [ ] replicate n x = x : replicate ( n − 1 ) x replicate n x = let rec 0 = [ ] rec n = x : rec ( n − 1 ) in rec n

  39. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 39 replicate – generalised β -reduction λ n λ x : @ x @ x − 1 n

  40. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 40 replicate – generalised β -reduction λ n λ x : @ x λ n @ x λ x λ n : − ։ ։ ▽ λ x n 1 @ x : @ x @ − x @ x 1 n . . . − 1 n

  41. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 41 Generalised β -Reduction @ @ r λ x s @ λ y x λ z @ z y

  42. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 42 Generalised β -Reduction @ @ r λ x s @ λ y x λ z @ z y

  43. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 43 Generalised β -Reduction @ @ @ r λ x @ s r λ y @ → β s λ y λ z x λ z @ @ z y z y

  44. Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 44 Generalised β -Reduction @ @ @ r λ x @ s r λ y @ → β s λ y λ z x λ z @ @ z y z y

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