1 / 25

David Evans http://www.cs.virginia.edu/evans

Lecture 39: Lambda Calculus. David Evans http://www.cs.virginia.edu/evans. CS150: Computer Science University of Virginia Computer Science. Equivalent Computers. . z. z. z. z. z. z. z. term = variable | term term | ( term )

irish
Download Presentation

David Evans http://www.cs.virginia.edu/evans

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 39: Lambda Calculus David Evans http://www.cs.virginia.edu/evans CS150: Computer Science University of Virginia Computer Science

  2. Equivalent Computers ... z z z z z z z • term = variable • | term term • | (term) • |  variable .term ), X, L  ), #, R (, #, L 2: look for ( 1 Start (, X, R • y. M v. (M [yv]) • where v does not occur in M. • (x. M)N   M [ xN ] HALT #, 0, - #, 1, - Finite State Machine Lambda Calculus Turing Machine

  3. What is Calculus? • In High School: d/dxxn = nxn-1 [Power Rule] d/dx (f + g) = d/dx f + d/dx g [Sum Rule] Calculus is a branch of mathematics that deals with limits and the differentiation and integration of functions of one or more variables...

  4. Real Definition • A calculus is just a bunch of rules for manipulating symbols. • People can give meaning to those symbols, but that’s not part of the calculus. • Differential calculus is a bunch of rules for manipulating symbols. There is an interpretation of those symbols corresponds with physics, slopes, etc.

  5. Lambda Calculus • Rules for manipulating strings of symbols in the language: term = variable | term term | (term) |  variable .term • Humans can give meaning to those symbols in a way that corresponds to computations.

  6. Why? • Once we have precise and formal rules for manipulating symbols, we can use it to reason with. • Since we can interpret the symbols as representing computations, we can use it to reason about programs.

  7. Evaluation Rules -reduction (renaming) y. M v. (M [yv]) where v does not occur in M. -reduction (substitution) (x. M)N   M [ xN ] Note the syntax is different from Scheme: (x.M)N ((lambda (x) M) N)

  8. -Reduction (the source of all computation) (x. M)N  M [ xN ] Replace all x’s in M witn N

  9. Evaluating Lambda Expressions • redex: Term of the form (x. M)N Something that can be -reduced • An expression is in normal form if it contains no redexes (redices). • To evaluate a lambda expression, keep doing reductions until you get to normal form.

  10. Some Simple Functions I x.x Cxy.yx Abbreviation for x.(y. yx) CII = (x.(y. yx)) (x.x) (x.x)  (y. y (x.x))(x.x) x.x (x.x) x.x = I

  11. Example  f. (( x.f (xx))( x. f (xx)))

  12. Possible Answer ( f. (( x.f (xx))( x. f (xx)))) (z.z) (x.(z.z)(xx))( x. (z.z)(xx))  (z.z) ( x.(z.z)(xx)) ( x.(z.z)(xx))  (x.(z.z)(xx)) ( x.(z.z)(xx))  (z.z) ( x.(z.z)(xx)) ( x.(z.z)(xx))  (x.(z.z)(xx)) ( x.(z.z)(xx)) ...

  13. Alternate Answer ( f. (( x.f (xx))( x. f (xx)))) (z.z)  (x.(z.z)(xx))( x. (z.z)(xx))  (x.xx)(x.(z.z)(xx))  (x.xx)(x.xx)  (x.xx)(x.xx) ...

  14. Be Very Afraid! • Some -calculus terms can be -reduced forever! • The order in which you choose to do the reductions might change the result!

  15. Take on Faith (until CS655) • All ways of choosing reductions that reduce a lambda expression to normal form will produce the same normal form (but some might never produce a normal form). • If we always apply the outermost lambda first, we will find the normal form if there is one. • This is normal order reduction – corresponds to normal order (lazy) evaluation

  16. Universal Language • Is Lambda Calculus a universal language? • Can we compute any computable algorithm using Lambda Calculus? • To prove it isn’t: • Find some Turing Machine that cannot be simulated with Lambda Calculus • To prove it is: • Show you can simulate every Turing Machine using Lambda Calculus

  17. Simulating Every Turing Machine • A Universal Turing Machine can simulate every Turing Machine • So, to show Lambda Calculus can simulate every Turing Machine, all we need to do is show it can simulate a Universal Turing Machine

  18. Simulating Computation z z z z z z z z z z z z z z z z z z z z • Lambda expression corresponds to a computation: input on the tape is transformed into a lambda expression • Normal form is that value of that computation: output is the normal form • How do we simulate the FSM? ), X, L ), #, R (, #, L 2: look for ( 1 Start (, X, R HALT #, 0, - #, 1, - Finite State Machine

  19. Simulating Computation z z z z z z z z z z z z z z z z z z z z Read/Write Infinite Tape Mutable Lists Finite State Machine Numbers Processing Way to make decisions (if) Way to keep going ), X, L ), #, R (, #, L 2: look for ( 1 Start (, X, R HALT #, 0, - #, 1, - Finite State Machine

  20. Making “Primitives”from Only Glue ()

  21. In search of thetruth? • What does true mean? • True is something that when used as the first operand of if, makes the value of the if the value of its second operand: ifTMN M

  22. Don’t search for T, search for if T  x (y. x)  xy. x F  x ( y. y)) if pca . pca

  23. Finding the Truth T  x . (y. x) F  x . (y. y) if p . (c . (a . pca))) if T M N ((pca . pca) (xy. x)) M N  (ca . (x.(y. x)) ca)) M N   (x.(y. x))M N  (y. M ))N  M Is the if necessary?

  24. and and or? and x (y. ifxyF)) or x (y. ifxTy))

  25. Lambda Calculus is a Universal Computer? z z z z z z z z z z z z z z z z z z z z • Read/Write Infinite Tape Mutable Lists • Finite State Machine Numbers • Processing Way to make decisions (if) Way to keep going ), X, L ), #, R (, #, L 2: look for ( 1 Start (, X, R HALT #, 0, - #, 1, - Finite State Machine ...to be continued Wednesday...

More Related