CSE321 Programming Languages Fixed Point Combinator POSTECH March
CSE-321 Programming Languages Fixed Point Combinator 박성우 POSTECH March 29, 2006
Values and Reductions : -reduction redex = reducible expression 2
Substitution Completed avoid variable captures 3
Outline • • • Abstract syntax of the -calculus V Operational semantics of the -calculus V Substitutions V Programming in the -calculus V Fixed point combinator – non-termination in the -calculus – recursive functions in the -calculus 4
Non-termination in -calculus 5
Recursive Functions in -calculus • Plan of attack 1. Assume a recursive function construct fun f x. e 2. Rewrite it as an expression in the -calculus i. e. , show that it is syntactic sugar. 6
Example: Factorial • Plan of attack 1. Assume a recursive function construct 2. Rewrite it as an expression in the -calculus i. e. , show that it is syntactic sugar. 7
fac to FAC 8
FAC produces a new function from f 9
KEY Observation on FAC new! 10
FAC improves the input function f : computes fac(0), fac(1), . . . , fac(k), fac(k + 1) 11
Special Case no matter what 12
Invariant: 13
FAC fac 14
Key Equation 15
What is f ? 16
17
(Earlier Slide) 18
19
20
Now we only need to solve: 21
Fixed Point • Fixed point of function f V such that V = f (V) • Ex. f (x) = 2 - x fixed point of f = 1 1 = f (1) 22
Now we only need to solve: Now we only need to find a fixed point of: 23
Magic Revealed • Fixed point combinator / Y combinator (call-by-value) • fix F returns a fixed point of F. 24
Magic Explained 25
Now we only need to solve: Now we only need to find a fixed point of: Now we only need to compute: 26
Answer 27
If you are a masochist, • See the course notes to learn how to derive the fixed point combinator! – There is a really crazy idea! 28
- Slides: 28