reduction strategies for cbn and cbv
play

Reduction strategies for CBN and CBV Structural operational style - PowerPoint PPT Presentation

Reduction strategies for CBN and CBV Structural operational style and Felleisen style Bas Broere April 24th 2018 Bas Broere Reduction strategies for CBN and CBV 1/22 Introduction Disclaimer I have (almost) no experience in functional


  1. Features/limitations of SOS in CBV We cannot reduce under λ -abstractions (weak reduction). So this is NOT a thing: M → M ′ λ x . M → λ x . M ′ Bas Broere — Reduction strategies for CBN and CBV 9/22

  2. Features/limitations of SOS in CBV We cannot reduce under λ -abstractions (weak reduction). So this is NOT a thing: M → M ′ λ x . M → λ x . M ′ We need to reduce N to a value if we want to evaluate ( λ x . M ) N (call-by-value). So also this is NOT a thing: ( λ x . M )( N P ) → M [ x := N P ] Bas Broere — Reduction strategies for CBN and CBV 9/22

  3. Features/limitations of SOS in CBV We cannot reduce under λ -abstractions (weak reduction). So this is NOT a thing: M → M ′ λ x . M → λ x . M ′ We need to reduce N to a value if we want to evaluate ( λ x . M ) N (call-by-value). So also this is NOT a thing: ( λ x . M )( N P ) → M [ x := N P ] In the application M N , we need to reduce M to a value first (left-to-right), because: N → N ′ v N → v N ′ (app-r) . Bas Broere — Reduction strategies for CBN and CBV 9/22

  4. Features/limitations of SOS in CBV We cannot reduce under λ -abstractions (weak reduction). So this is NOT a thing: M → M ′ λ x . M → λ x . M ′ We need to reduce N to a value if we want to evaluate ( λ x . M ) N (call-by-value). So also this is NOT a thing: ( λ x . M )( N P ) → M [ x := N P ] In the application M N , we need to reduce M to a value first (left-to-right), because: N → N ′ v N → v N ′ (app-r) . It is deterministic, i.e. for every M there is at most one M ′ s.t. M → M ′ . Bas Broere — Reduction strategies for CBN and CBV 9/22

  5. Multiple reductions When making a reduction sequence we have 3 possibilities: Bas Broere — Reduction strategies for CBN and CBV 10/22

  6. Multiple reductions When making a reduction sequence we have 3 possibilities: 1 The reductions end in a value (termination): M → M 1 → M 2 → . . . → v . Example: ( λ x .λ y . y x ) (( λ x . x )1) ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) → ( λ y . y 1) ( λ x . x ) → ( λ x . x ) 1 → 1 Bas Broere — Reduction strategies for CBN and CBV 10/22

  7. Multiple reductions When making a reduction sequence we have 3 possibilities: 1 The reductions end in a value (termination): M → M 1 → M 2 → . . . → v . Example: ( λ x .λ y . y x ) (( λ x . x )1) ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) → ( λ y . y 1) ( λ x . x ) → ( λ x . x ) 1 → 1 2 The reduction never ends (divergence): M → M 1 → M 2 → . . . → M n → . . . . Example: Bas Broere — Reduction strategies for CBN and CBV 10/22

  8. Multiple reductions When making a reduction sequence we have 3 possibilities: 1 The reductions end in a value (termination): M → M 1 → M 2 → . . . → v . Example: ( λ x .λ y . y x ) (( λ x . x )1) ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) → ( λ y . y 1) ( λ x . x ) → ( λ x . x ) 1 → 1 2 The reduction never ends (divergence): M → M 1 → M 2 → . . . → M n → . . . . Example: ω ω , where ω = λ x . x x . Bas Broere — Reduction strategies for CBN and CBV 10/22

  9. Multiple reductions When making a reduction sequence we have 3 possibilities: 1 The reductions end in a value (termination): M → M 1 → M 2 → . . . → v . Example: ( λ x .λ y . y x ) (( λ x . x )1) ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) → ( λ y . y 1) ( λ x . x ) → ( λ x . x ) 1 → 1 2 The reduction never ends (divergence): M → M 1 → M 2 → . . . → M n → . . . . Example: ω ω , where ω = λ x . x x . 3 Error: M → M 1 → M 2 → . . . → M n �→ , where M n is not a value, but also does not reduce. Example: Bas Broere — Reduction strategies for CBN and CBV 10/22

  10. Multiple reductions When making a reduction sequence we have 3 possibilities: 1 The reductions end in a value (termination): M → M 1 → M 2 → . . . → v . Example: ( λ x .λ y . y x ) (( λ x . x )1) ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) → ( λ y . y 1) ( λ x . x ) → ( λ x . x ) 1 → 1 2 The reduction never ends (divergence): M → M 1 → M 2 → . . . → M n → . . . . Example: ω ω , where ω = λ x . x x . 3 Error: M → M 1 → M 2 → . . . → M n �→ , where M n is not a value, but also does not reduce. Example: ω 2 → 2 2 �→ . Bas Broere — Reduction strategies for CBN and CBV 10/22

  11. Reduction strategies for CBV Reduction contexts (felleisen style) Head reductions: ( λ x . M ) v → ǫ M [ x := v ] ( β v ) Bas Broere — Reduction strategies for CBN and CBV 11/22

  12. Reduction strategies for CBV Reduction contexts (felleisen style) Head reductions: ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , with E ::= [ ] | E b | v E terms with a hole [ ] in it. Bas Broere — Reduction strategies for CBN and CBV 11/22

  13. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) Bas Broere — Reduction strategies for CBN and CBV 12/22

  14. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) Bas Broere — Reduction strategies for CBN and CBV 12/22

  15. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) Bas Broere — Reduction strategies for CBN and CBV 12/22

  16. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) Bas Broere — Reduction strategies for CBN and CBV 12/22

  17. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) Bas Broere — Reduction strategies for CBN and CBV 12/22

  18. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) E = [ ] ( λ x . x ) Bas Broere — Reduction strategies for CBN and CBV 12/22

  19. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) E = [ ] ( λ x . x ) → ( λ y . y 1) ( λ x . x ) Bas Broere — Reduction strategies for CBN and CBV 12/22

  20. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) E = [ ] ( λ x . x ) → ( λ y . y 1) ( λ x . x ) Bas Broere — Reduction strategies for CBN and CBV 12/22

  21. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) E = [ ] ( λ x . x ) → ( λ y . y 1) ( λ x . x ) E = [ ] Bas Broere — Reduction strategies for CBN and CBV 12/22

  22. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) E = [ ] ( λ x . x ) → ( λ y . y 1) ( λ x . x ) E = [ ] → ( λ x . x ) 1 Bas Broere — Reduction strategies for CBN and CBV 12/22

  23. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) E = [ ] ( λ x . x ) → ( λ y . y 1) ( λ x . x ) E = [ ] → ( λ x . x ) 1 E = [ ] Bas Broere — Reduction strategies for CBN and CBV 12/22

  24. Example Reduction contexts (Felleisen style) ( λ x . M ) v → ǫ M [ x := v ] ( β v ) M → ǫ M ′ E [ M ] → E [ M ′ ] (context) , E ::= [ ] | E b | v E Same example as before: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) E = ( λ x .λ y . x y ) [ ] ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) E = [ ] ( λ x . x ) → ( λ y . y 1) ( λ x . x ) E = [ ] → ( λ x . x ) 1 E = [ ] → 1 Bas Broere — Reduction strategies for CBN and CBV 12/22

  25. Equivalence SOS and Felleisen Remember the earlier example: ( λ x . x ) 1 → 1 ( λ x .λ y . y x ) (( λ x . x ) 1) → ( λ x .λ y . y x ) 1 ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) This corresponds to the context: Bas Broere — Reduction strategies for CBN and CBV 13/22

  26. Equivalence SOS and Felleisen Remember the earlier example: ( λ x . x ) 1 → 1 ( λ x .λ y . y x ) (( λ x . x ) 1) → ( λ x .λ y . y x ) 1 ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) This corresponds to the context: E = Bas Broere — Reduction strategies for CBN and CBV 13/22

  27. Equivalence SOS and Felleisen Remember the earlier example: ( λ x . x ) 1 → 1 ( λ x .λ y . y x ) (( λ x . x ) 1) → ( λ x .λ y . y x ) 1 ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) This corresponds to the context: E = (( λ x .λ y . y x ) [ ]) ( λ x . x ) with head reduction ( λ x . x ) 1 → ǫ 1. Bas Broere — Reduction strategies for CBN and CBV 13/22

  28. Equivalence SOS and Felleisen Remember the earlier example: ( λ x . x ) 1 → 1 ( λ x .λ y . y x ) (( λ x . x ) 1) → ( λ x .λ y . y x ) 1 ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ x . x ) → ( λ x .λ y . y x ) 1 ( λ x . x ) This corresponds to the context: E = (( λ x .λ y . y x ) [ ]) ( λ x . x ) with head reduction ( λ x . x ) 1 → ǫ 1. Equivalence SOS and Felleisen approach are one-to-one! Bas Broere — Reduction strategies for CBN and CBV 13/22

  29. Result From this equivalence, it follow that Felleisen style also has the previously discussed properties: Left-to-right, Call-by-value, Weak reduction, Deterministic*. Bas Broere — Reduction strategies for CBN and CBV 14/22

  30. Result From this equivalence, it follow that Felleisen style also has the previously discussed properties: Left-to-right, Call-by-value, Weak reduction, Deterministic*. *: The determinism is also a consequence of the following theorem: Unique decomposition theorem For all terms M , there exists at most one reduction context E and one term N , s.t. M = E [ N ] and N can reduce by head-reduction. Bas Broere — Reduction strategies for CBN and CBV 14/22

  31. Result From this equivalence, it follow that Felleisen style also has the previously discussed properties: Left-to-right, Call-by-value, Weak reduction, Deterministic*. *: The determinism is also a consequence of the following theorem: Unique decomposition theorem For all terms M , there exists at most one reduction context E and one term N , s.t. M = E [ N ] and N can reduce by head-reduction. Proof: Induction on the terms. Bas Broere — Reduction strategies for CBN and CBV 14/22

  32. Reduction strategies for CBN Call-by-name The arguments to a function are not evaluated before the function is called (perform β -reduction asap). Bas Broere — Reduction strategies for CBN and CBV 15/22

  33. Reduction strategies for CBN Call-by-name The arguments to a function are not evaluated before the function is called (perform β -reduction asap). Structural operation style (SOS) M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) M N → M ′ N (app-l) Bas Broere — Reduction strategies for CBN and CBV 15/22

  34. Reduction strategies for CBN Call-by-name The arguments to a function are not evaluated before the function is called (perform β -reduction asap). Structural operation style (SOS) M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) M N → M ′ N (app-l) Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , with E ::= [ ] | E M Bas Broere — Reduction strategies for CBN and CBV 15/22

  35. Reduction strategies for CBN Call-by-name The arguments to a function are not evaluated before the function is called (perform β -reduction asap). Structural operation style (SOS) M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) M N → M ′ N (app-l) Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , with E ::= [ ] | E M , so E ::= [ ] M 1 . . . M n . Bas Broere — Reduction strategies for CBN and CBV 15/22

  36. Examples Structural operation style (SOS) M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) M N → M ′ N (app-l) The same example once again, in SOS-style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) Bas Broere — Reduction strategies for CBN and CBV 16/22

  37. Examples Structural operation style (SOS) M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) M N → M ′ N (app-l) The same example once again, in SOS-style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) Bas Broere — Reduction strategies for CBN and CBV 16/22

  38. Examples Structural operation style (SOS) M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) M N → M ′ N (app-l) The same example once again, in SOS-style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) Bas Broere — Reduction strategies for CBN and CBV 16/22

  39. Examples Structural operation style (SOS) M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) M N → M ′ N (app-l) The same example once again, in SOS-style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) Bas Broere — Reduction strategies for CBN and CBV 16/22

  40. Examples Structural operation style (SOS) M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) M N → M ′ N (app-l) The same example once again, in SOS-style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) → ( λ z . z ) (( λ x . x ) 1) Bas Broere — Reduction strategies for CBN and CBV 16/22

  41. Examples Structural operation style (SOS) M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) M N → M ′ N (app-l) The same example once again, in SOS-style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) → ( λ z . z ) (( λ x . x ) 1) → ( λ x . x ) 1 Bas Broere — Reduction strategies for CBN and CBV 16/22

  42. Examples Structural operation style (SOS) M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) M N → M ′ N (app-l) The same example once again, in SOS-style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) → ( λ z . z ) (( λ x . x ) 1) → ( λ x . x ) 1 → 1 . Bas Broere — Reduction strategies for CBN and CBV 16/22

  43. Examples Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , E ::= [ ] | E M . And in Felleisen style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) E = [ ] ( λ x . x ) Bas Broere — Reduction strategies for CBN and CBV 17/22

  44. Examples Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , E ::= [ ] | E M . And in Felleisen style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) E = [ ] ( λ x . x ) Bas Broere — Reduction strategies for CBN and CBV 17/22

  45. Examples Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , E ::= [ ] | E M . And in Felleisen style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) E = [ ] ( λ z . z ) Bas Broere — Reduction strategies for CBN and CBV 17/22

  46. Examples Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , E ::= [ ] | E M . And in Felleisen style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) E = [ ] ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) Bas Broere — Reduction strategies for CBN and CBV 17/22

  47. Examples Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , E ::= [ ] | E M . And in Felleisen style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) E = [ ] ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) Bas Broere — Reduction strategies for CBN and CBV 17/22

  48. Examples Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , E ::= [ ] | E M . And in Felleisen style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) E = [ ] ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) E = [ ] Bas Broere — Reduction strategies for CBN and CBV 17/22

  49. Examples Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , E ::= [ ] | E M . And in Felleisen style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) E = [ ] ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) E = [ ] → ( λ z . z ) (( λ x . x ) 1) Bas Broere — Reduction strategies for CBN and CBV 17/22

  50. Examples Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , E ::= [ ] | E M . And in Felleisen style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) E = [ ] ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) E = [ ] → ( λ z . z ) (( λ x . x ) 1) E = [ ] Bas Broere — Reduction strategies for CBN and CBV 17/22

  51. Examples Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , E ::= [ ] | E M . And in Felleisen style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) E = [ ] ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) E = [ ] → ( λ z . z ) (( λ x . x ) 1) E = [ ] → ( λ x . x ) 1 Bas Broere — Reduction strategies for CBN and CBV 17/22

  52. Examples Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , E ::= [ ] | E M . And in Felleisen style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) E = [ ] ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) E = [ ] → ( λ z . z ) (( λ x . x ) 1) E = [ ] → ( λ x . x ) 1 E = [ ] Bas Broere — Reduction strategies for CBN and CBV 17/22

  53. Examples Felleisen style M → M ′ ( λ x . M ) N → M [ x := N ] ( β n ) E [ M ] → E [ M ′ ](context) , E ::= [ ] | E M . And in Felleisen style: ( λ x .λ y . y x ) (( λ x . x ) 1) ( λ z . z ) E = [ ] ( λ z . z ) → ( λ y . y (( λ x . x ) 1)) ( λ z . z ) E = [ ] → ( λ z . z ) (( λ x . x ) 1) E = [ ] → ( λ x . x ) 1 E = [ ] → 1 . Bas Broere — Reduction strategies for CBN and CBV 17/22

  54. CBV vs CBN Some examples: Termination: Bas Broere — Reduction strategies for CBN and CBV 18/22

  55. CBV vs CBN Some examples: Termination: CBN: ( λ x . 1) ( ω ω ) → Bas Broere — Reduction strategies for CBN and CBV 18/22

  56. CBV vs CBN Some examples: Termination: CBN: ( λ x . 1) ( ω ω ) → 1; Bas Broere — Reduction strategies for CBN and CBV 18/22

  57. CBV vs CBN Some examples: Termination: CBN: ( λ x . 1) ( ω ω ) → 1; CBV: ( λ x . 1) ( ω ω ) → Bas Broere — Reduction strategies for CBN and CBV 18/22

  58. CBV vs CBN Some examples: Termination: CBN: ( λ x . 1) ( ω ω ) → 1; CBV: ( λ x . 1) ( ω ω ) → ( λ x . 1) ( ω ω ) → . . . Bas Broere — Reduction strategies for CBN and CBV 18/22

  59. CBV vs CBN Some examples: Termination: CBN: ( λ x . 1) ( ω ω ) → 1; CBV: ( λ x . 1) ( ω ω ) → ( λ x . 1) ( ω ω ) → . . . In general: Termination in CBV implies termination in CBN, but not the other way around. Bas Broere — Reduction strategies for CBN and CBV 18/22

  60. CBV vs CBN Some examples: Termination: CBN: ( λ x . 1) ( ω ω ) → 1; CBV: ( λ x . 1) ( ω ω ) → ( λ x . 1) ( ω ω ) → . . . In general: Termination in CBV implies termination in CBN, but not the other way around. Efficiency: Bas Broere — Reduction strategies for CBN and CBV 18/22

  61. CBV vs CBN Some examples: Termination: CBN: ( λ x . 1) ( ω ω ) → 1; CBV: ( λ x . 1) ( ω ω ) → ( λ x . 1) ( ω ω ) → . . . In general: Termination in CBV implies termination in CBN, but not the other way around. Efficiency: ( λ x . x + x ) M : Bas Broere — Reduction strategies for CBN and CBV 18/22

  62. CBV vs CBN Some examples: Termination: CBN: ( λ x . 1) ( ω ω ) → 1; CBV: ( λ x . 1) ( ω ω ) → ( λ x . 1) ( ω ω ) → . . . In general: Termination in CBV implies termination in CBN, but not the other way around. Efficiency: ( λ x . x + x ) M : CBV evaluates M once, CBN twice; Bas Broere — Reduction strategies for CBN and CBV 18/22

  63. CBV vs CBN Some examples: Termination: CBN: ( λ x . 1) ( ω ω ) → 1; CBV: ( λ x . 1) ( ω ω ) → ( λ x . 1) ( ω ω ) → . . . In general: Termination in CBV implies termination in CBN, but not the other way around. Efficiency: ( λ x . x + x ) M : CBV evaluates M once, CBN twice; ( λ x . 1) M : Bas Broere — Reduction strategies for CBN and CBV 18/22

  64. CBV vs CBN Some examples: Termination: CBN: ( λ x . 1) ( ω ω ) → 1; CBV: ( λ x . 1) ( ω ω ) → ( λ x . 1) ( ω ω ) → . . . In general: Termination in CBV implies termination in CBN, but not the other way around. Efficiency: ( λ x . x + x ) M : CBV evaluates M once, CBN twice; ( λ x . 1) M : CBV evaluates M once, CBN not at all. Bas Broere — Reduction strategies for CBN and CBV 18/22

  65. CBN in CBV language Bas Broere — Reduction strategies for CBN and CBV 19/22

  66. CBN in CBV language Introduce functions λ x . M to delay computation of M (thunks). Bas Broere — Reduction strategies for CBN and CBV 19/22

  67. CBN in CBV language Introduce functions λ x . M to delay computation of M (thunks). 1 � x � = x () (application); Bas Broere — Reduction strategies for CBN and CBV 19/22

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