cse-321 programming languages fixed point combinator
DESCRIPTION
CSE-321 Programming Languages Fixed Point Combinator. 박성우. POSTECH March 29, 2006. : -reduction. redex = reducible expression. Values and Reductions. Substitution Completed. avoid variable captures. Outline. Abstract syntax of the -calculus V - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/1.jpg)
CSE-321 Programming Languages
Fixed Point Combinator
POSTECH
March 29, 2006
박성우
![Page 2: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/2.jpg)
2
Values and Reductions
redex = reducible expression
: -reduction
![Page 3: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/3.jpg)
3
Substitution Completed
avoid variable captures
![Page 4: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/4.jpg)
4
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
![Page 5: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/5.jpg)
5
Non-termination in -calculus
![Page 6: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/6.jpg)
6
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 -calculusi.e., show that it is syntactic sugar.
![Page 7: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/7.jpg)
7
• Plan of attack
1. Assume a recursive function construct
2. Rewrite it as an expression in the -calculusi.e., show that it is syntactic sugar.
Example: Factorial
![Page 8: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/8.jpg)
8
fac to FAC
![Page 9: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/9.jpg)
9
FAC produces a new function from f
![Page 10: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/10.jpg)
10
KEY Observation on FAC
new!
![Page 11: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/11.jpg)
11
FAC improves the input function f
:computes fac(0), fac(1), ..., fac(k)
:computes fac(0), fac(1), ..., fac(k), fac(k + 1)
![Page 12: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/12.jpg)
12
Special Case
no matter what
![Page 13: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/13.jpg)
13
Invariant:
![Page 14: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/14.jpg)
14
FAC fac
![Page 15: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/15.jpg)
15
Key Equation
![Page 16: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/16.jpg)
16
What is f ?
![Page 17: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/17.jpg)
17
![Page 18: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/18.jpg)
18
(Earlier Slide)
![Page 19: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/19.jpg)
19
![Page 20: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/20.jpg)
20
![Page 21: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/21.jpg)
21
Now we only need to solve:
![Page 22: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/22.jpg)
22
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)
![Page 23: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/23.jpg)
23
Now we only need to solve:
Now we only need to find a fixed point of:
![Page 24: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/24.jpg)
24
Magic Revealed• Fixed point combinator / Y combinator
(call-by-value)
• fix F returns a fixed point of F.
![Page 25: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/25.jpg)
25
Magic Explained
![Page 26: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/26.jpg)
26
Now we only need to solve:
Now we only need to find a fixed point of:
Now we only need to compute:
![Page 27: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/27.jpg)
27
Answer
![Page 28: CSE-321 Programming Languages Fixed Point Combinator](https://reader036.vdocuments.site/reader036/viewer/2022062422/5681350c550346895d9c5f89/html5/thumbnails/28.jpg)
28
If you are a masochist,• See the course notes to learn
how to derive the fixed point combinator!– There is a really crazy idea!