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
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
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
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
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 5 λ -Terms and λ -Trees T V ::= ( variable ) T T | ( application ) λ V . T | ( abstraction )
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
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
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
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
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 10 repeat let repeat = λ x . x : repeat x λ x in repeat : @ x x
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
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
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
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
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
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
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 17 repeat 3 @ 3 let repeat = λ x . x : repeat x λ x in repeat 3 : @ x x
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
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
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 20 → β : 3 @ 3 let repeat = λ x . x : repeat x in 3: repeat 3 λ x : @ x x
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
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
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
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 24 ։ ▽ , β ։ : 3 : 3:3: ... 3 : . . 3 .
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 25 և և ▽ let rec = 3: rec in rec : 3
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 26 → ▽ : let rec = 3: rec in 3: rec 3 : 3
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 27 → ▽ : 3 : let rec = 3: rec in 3:3: rec 3 : 3
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 28 repeat 3 @ 3 λ x : @ x x
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 29 repeat 3 @ λ x 3 @ : 3 @ x λ x ։ ։ ▽ λ x x : : @ x @ x x . . . x
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
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
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 32 repeat λ x : @ x x
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 33 repeat λ x : @ x λ x ։ ։ ▽ λ x x : : @ x @ x x . . . x
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 34 repeat λ x : λ x @ x λ x : ։ β ։ ։ ▽ ։ λ x x : : x : @ . x . . x @ x x . . . x
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 35 repeat λ x : λ x λ x @ x λ x : ։ β ։ ։ ▽ ։ և և ▽ λ x x : : x : : @ . x . . x x @ x x . . . x
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
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 37 Operational equivalence I Used here: = ∞ ։ ▽ ) ∗ ▽ , β = ( և և ▽ ∪ և և β ∪ ։ ։ β ∪ ։ as notion of operational equivalence.
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
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 39 replicate – generalised β -reduction λ n λ x : @ x @ x − 1 n
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
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 41 Generalised β -Reduction @ @ r λ x s @ λ y x λ z @ z y
Avoiding Repetitive Reduction Patterns in λ letrec Rochel, Grabmayer 42 Generalised β -Reduction @ @ r λ x s @ λ y x λ z @ z y
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
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
Recommend
More recommend