UVA CS 655 - Lecture 6: Lambda Calculus

Unformatted text preview:

PowerPoint PresentationLanguage Complexity and Brain Cell DecayComplexity in Scheme-calculusMystery Function (Teaser)Evaluation RulesIdentity ()Defining Substitution ( )Slide 9Reduction (Uninteresting Rules)-Reduction (the source of all computation)Recall Apply in SchemeSome Simple FunctionsEvaluating Lambda ExpressionsExampleAlyssa P. Hacker’s AnswerBen Bitdiddle’s AnswerBe Very Afraid!Take on Faith (for now)Who needs primitives?EvaluationSlide 22CouplingTuplingPrimitivesWhat are numbers?Adding for Post-DocsCountingArithmeticFactorialSummaryChargeLecture 6: Lambda CalculusDavid Evanshttp://www.cs.virginia.edu/~evansCS655: Programming LanguagesUniversity of VirginiaComputer ScienceGod created the integers – all else is the result of man.Leopold KroneckerGod created application – all else is the result of man.Alonzo Church (not really)6 Feb 2001 CS 655: Lecture 6 2Language Complexity and Brain Cell DecayYears Spent in SchoolLanguage Complexity (Number of Morphemes)0 5 10 15 20 25English(OED: 500,000 words)C++(680 pages)Scheme (50 pages)??? (.5 page)6 Feb 2001 CS 655: Lecture 6 3Complexity in Scheme•Special Forms–if, cond, define, etc.•Primitives–Numbers (infinitely many)–Booleans: #t, #f–Functions (+, -, and, or, etc.)•Evaluation Complexity–Environments (more than ½ of our interpreter)Can we get rid of all this and still have a useful language?If we have lazy evaluation,(and don’t care about abstraction) we don’t need these.Hard to get rid of?6 Feb 2001 CS 655: Lecture 6 4-calculusAlonzo Church, 1940(LISP was developed from -calculus, not the other way round.)term = variable | term term | (term) |  variable . term6 Feb 2001 CS 655: Lecture 6 5Mystery Function (Teaser)p  xy.  pca.pca (x.x xy.x) x) y (p ((x.x xy.y) x) (x. z.z (xy.y) y)m  xy.  pca.pca (x.x xy.x) x) x.x (p y (m ((x.x xy.y) x) y))f  x.  pca.pca ((x.x  xy.x) x) (z.z ( xy.y) (x.x)) (m x (f ((x.x xy.y) x)))ifx = 01x * f (x – 1)6 Feb 2001 CS 655: Lecture 6 6Evaluation Rules-reduction (renaming) y. M  v. (M [y v])where v does not occur in M.-reduction (substitution) (x. M)N   M [ x N ] 6 Feb 2001 CS 655: Lecture 6 7Identity ()x  y if x and y are same nameM1 M2  N1 N2 if M1  N1  M2  N2(M)  (N) if M  Nx. M  y. N if x  y  M  N6 Feb 2001 CS 655: Lecture 6 8Defining Substitution ( ) x [x N]  Ny [x N]  y where x  yM1 M2 [x N]  M1 [x N] M2 [x N](x. M) [x N]  x. M6 Feb 2001 CS 655: Lecture 6 9Defining Substitution ( ) (y. M) [x N]  y. (M [x N])where x  y and y does not appear free in N or x does not appear free in M.(y. M) [x N]  z. (M [y z]) [x N]where x  y, z  x and z  y and z does not appear in M or N, x does occur free in M and y does occur free in N.6 Feb 2001 CS 655: Lecture 6 10Reduction (Uninteresting Rules) y. M  v. (M [y v])where v does not occur in M. M  M M  N  PM  PN M  N  MP  NP M  N  x. M  x. N M  N and N  P  M  P6 Feb 2001 CS 655: Lecture 6 11-Reduction (the source of all computation) (x. M)N  M [ x N ]6 Feb 2001 CS 655: Lecture 6 12Recall Apply in Scheme“To apply a procedure to a list of arguments, evaluate the procedure in a new environment that binds the formal parameters of the procedure to the arguments it is applied to.”•We’ve replaced environments with substitution.•We’ve replaced eval with reduction.6 Feb 2001 CS 655: Lecture 6 13Some Simple FunctionsI  x.xC  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= I6 Feb 2001 CS 655: Lecture 6 14Evaluating 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.6 Feb 2001 CS 655: Lecture 6 15Example f. (( x.f (xx)) ( x. f (xx)))6 Feb 2001 CS 655: Lecture 6 16Alyssa P. Hacker’s 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)) ...6 Feb 2001 CS 655: Lecture 6 17Ben Bitdiddle’s 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) ...6 Feb 2001 CS 655: Lecture 6 18Be Very Afraid!•Some -calculus terms can be -reduced forever!•The order in which you choose to do the reductions might change the result!6 Feb 2001 CS 655: Lecture 6 19Take on Faith (for now)•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 is there is one.–This is normal order reduction – corresponds to normal order (lazy) evaluation6 Feb 2001 CS 655: Lecture 6 20Who needs primitives?T   xy. x F  xy. y if  pca . pca6 Feb 2001 CS 655: Lecture 6 21EvaluationT  xy. x F  xy. y if  pca . 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   M6 Feb 2001 CS 655: Lecture 6 22Who needs primitives?and  xy. if x y For  xy. if x T y6 Feb 2001 CS 655: Lecture 6 23Coupling[M, N]  z.z M N first  p.p Tsecond  p.p Ffirst [M, N]=  p.p T (z.z M N)   (z.z M N) T = (z.z M N) xy. x   (xy. x) M N   M6 Feb 2001 CS 655: Lecture 6 24Tuplingn-tuple: [M] = M[M0,..., Mn-1, Mn] = [M0, [M1 ,..., [Mn-1, Mn ]... ]n-tuple direct: [M0,..., Mn-1, Mn] = z.z M0,..., Mn-1, MnPi,n = x.x Ui,nUi,n = x0... xn. xiWhat is P1,2?6 Feb 2001 CS 655: Lecture 6 25PrimitivesWhat about all those pesky numbers?6 Feb 2001 CS 655: Lecture 6 26What are numbers?•We need three (?)


View Full Document

UVA CS 655 - Lecture 6: Lambda Calculus

Download Lecture 6: Lambda Calculus
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 6: Lambda Calculus and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 6: Lambda Calculus 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?