church-turing thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · exercise: translate boolean...

13

Upload: others

Post on 27-Aug-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and
Page 2: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

Church-Turing Thesis

Page 3: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

Church-Turing Thesis

Page 4: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

Exercise: Implement f_and, f_or

Motivation: Encoding values with functions

t = lambda a: lambda b: af = lambda a: lambda b: b

def py_pred(p): return p(True)(False)

def f_not(p): """ >>> py_pred(f_not(t)) False >>> py_pred(f_not(f)) True """ return lambda a: lambda b: p(b)(a)

f_and = lambda p1: lambda p2:f_or = lambda p1: lambda p2:

p1(p2)(f)p1(t)(p2)

Page 5: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

A Cleaner Syntax

Page 6: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

Basic Functions

Exercise:

Confirm that K I is equivalent to CI

Write down CC_I

, also write it in terms of K and I

Evaluate (K K) (K K)

http://www.chenyang.co/lambda

Page 7: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

Currying

What does pi_1 and pi_2 remind you of?

Page 8: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

Exercise:

Translate boolean operators into lambda notation

Write an if-function using lambda notation

True and False

f_not = lambda p: lambda a: lambda b: p(b)(a) f_and = lambda p1: lambda p2: p1(p2)(false)f_or = lambda p1: lambda p2: p1(true)(p2)

true = lambda a: lambda b: afalse = lambda a: lambda b: b

Page 9: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

Zero, One, Two, ...

Exercise:

Implement add, mul, power

Suppose we have an operator pred that returns the predecessor of a number, implement subtraction using pred

Implement pred (Challenging)

Page 10: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

Recursion!

fac = lambda n: 1 if n == 0 else n * fac(n-1)

F = lambda fac: lambda n: 1 if n == 0 else n * fac(n-1)

F(fac) = fac <- fac is the fixed point of F

Page 11: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

Fixed Points

Page 12: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

PuzzleWhat is X? (There are 26 Ls)

Hint: A fixed point combinator has the form YF=F(YF)

Page 13: Church-Turing Thesiscs61a/sp15/assets/slides/... · 2015. 6. 14. · Exercise: Translate boolean operators into lambda notation Write an if-function using lambda notation True and

Conclusion + Acknowledgements

Everything + more:http://xuanji.appspot.com/isicp/lambda.htmlLambda interpreter:https://github.com/tarao/LambdaJS