One-Slide Summary • The lambda calculus is a universal, fundamental model of computation. You can view it as “the essence of A Universal Language A Universal Language Scheme”. It contains terms and rules describing variables, function abstraction, and function application. • There are two key reduction rules in the lambda calculus. Alpha reduction allows you to rename variables uniformly. Beta reduction is the essence of computation: in beta reduction, a function evaluation is equivalent to replacing all instances of the formal parameter in the function body with the actual argument. • It is possible to encode programming concepts, such as true, false, if, numbers, plus, etc., in the lambda calculus. #2 Final Project Presentations -calculus Alonzo Church, 1940 • December 6 th , 3:30-4:45 (LISP was developed from -calculus, – Optional: Game Theory, OLS 011 not the other way round.) • December 6 th , 5:00pm+ term = variable – Optional: OLS 009 • Attending is worth extra credit. | term term – And you'll see the fun projects of your fellow | variable . term students. • You must request to give a presentation. • Requests are due Dec 04. #4 What is Calculus? Surprise Liberal Arts Trivia • This branch of mathematics involving • In High School: symbolic expressions manipulated according d/dx x n = nx n-1 [Power Rule] to fixed rules takes its name from the d/dx (f + g) = d/dx f + d/dx g [Sum Rule] diminutive form of calx/calcis, the latin word for rock or limestone. The diminutive word Calculus is a branch of mathematics thus means “pebble”: in ancient times that deals with limits and the pebbles were placed in sand and used for differentiation and integration of counting using techniques akin to those of the functions of one or more variables... abacus. #5 #6
Real Definition Lambda Calculus • A calculus is just a bunch of rules for • Rules for manipulating strings of manipulating symbols. symbols in the language: • People can give meaning to those term = variable symbols, but that’s not part of the | term term calculus. | variable . term • Differential calculus is a bunch of rules • Humans can give meaning to those for manipulating symbols. There is an symbols in a way that corresponds to interpretation of those symbols computations. corresponds with physics, slopes, etc. #7 #8 Why? Evaluation Rules • Once we have precise and formal rules -reduction (renaming) for manipulating symbols, we can reason y . M v . ( M [each y replaced by v ]) with those symbols and rules. where v does not occur in M . • Since we can interpret the symbols as representing computations, we can use this system to reason about programs. -reduction (substitution) • (It will provide additional evidence that ( x . M ) N M [each x replaced by N ] Scheme and Turing machines have equivalent computational power.) We'll see examples in a bit! #9 #10 Equivalent Computers? Liberal Arts Trivia: Music • This music genre originated in Jamaica in the ... z z z z z z z term = variable 1950s and was the precursor to reggae. It | term term combines elements of Caribbean mento and | ( term ) | variable . term calypso with American jazz and rhythm and ), X, L ), #, R (, #, L 2: blues. It is characterized by a walking bass 1 look for ( Start (, X, R y . M v . ( M [ y → v ]) line accented with rhythms on the offbeat. In HAL T #, 0, - #, 1, - where v does not occur in M . the 1980s it experience a third wave revival Finite State Machine ( x . M ) N M [ x → N ] and is often associated with punk and brass Lambda Calculus instruments. Turing Machine
Liberal Arts Trivia: Geography Lambda Examples • Identity Function • This baltic country borders Romania, Serbia, – Identity = lambda x : x Macedonia, Greece, Turkey and the Black – identity = x. x Sea. It was at one point ruled by the • Square Function Ottomans, but is now a member of the EU and – Square = lambda x : x * x NATO. Sofia, the capital and largest city, is one of the oldest cities in Europe and can be – square = x. (x * x) traced back some 7000 years. The traditional • Add Function cuisine of this country features rich salads at – add = lambda x, y : x + y every meal, as well as native pastries such as – add = lambda x : lambda y : x + y the banitsa . – add = x. y. (x + y) - Reduction - Reduction Examples (the source of all computation) • Square Function Recall: ( x . M ) N M [ x → N ] – square = x. (x * x) ( x . M ) N M [ x → N ] – ( x. (x * x)) 5 – ( x. (x * x)) 5 (x * x)[x → 5] Replace all x ’s in M – ( x. (x * x)) 5 (x * x)[x → 5] (5 * 5) with N’s • Add Function – add = x. y. (x + y) Note the syntax is different from Python: ( x . M ) N === (lambda x: M)(N) – ( x. y. (x + y)) 3 ??? Get out some paper! – (( x. y. (x + y)) 2) 6 ??? - Reduction Examples Evaluating Lambda Expressions • Square Function Recall: ( x . M ) N M [ x → N ] • redex : Term of the form ( x . M ) N – square = x. (x * x) Something that can be - reduced – ( x. (x * x)) 5 – ( x. (x * x)) 5 (x * x)[x → 5] • An expression is in normal form if it contains no redexes ( redices ). – ( x. (x * x)) 5 (x * x)[x → 5] (5 * 5) • To evaluate a lambda expression, keep • Add Function doing reductions until you get to normal – add = x. y. (x + y) form . – ( x. y. (x + y)) 3 y. (3 + y) – (( x. y. (x + y)) 2) 6 ( y. (2 + y)) 6 (2 + 6)
Example Possible Answer ( f. (( x . f ( xx )) ( x. f ( xx )))) ( z.z ) f. (( x . f ( xx )) ( x. f ( 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 )) Do it on paper! ( z.z ) ( x. ( z.z )( xx )) ( x. ( z.z )( xx )) ( x. ( z.z )( xx )) ( x. ( z.z )( xx )) ... Alternate Answer Be Very Afraid! ( f. (( x . f ( xx )) ( x. f ( xx )))) ( z.z ) • Some -calculus terms can be -reduced forever! ( x . ( z.z )( xx )) ( x. ( z.z )( xx )) – Just like some computer programs, which can ( x . xx ) ( x. ( z.z )( xx )) evaluate forever ( x . xx ) ( x.xx ) • The order in which you choose to do the reductions might change the result! ( x . xx ) ( x.xx ) – Just like lazy evaluation vs. eager evaluation ... Liberal Arts Trivia: Liberal Arts Trivia: Biology Classics • The Temple of • These even-toed ungulate have one or two Artemis at Ephesus, distinctive fatty deposits on their backs. They the Statue of Zeus are native to the dry desert areas of Asia. at Olympus, and the They are domesticated to provide meat and Tomb of Maussollos milk, as well as to serve as beasts of burden. are three of the The US Army had an active cavalry corps Seven Wonders of based on these beasts in California in the 19 th the Ancient World . century, and they have been used in wars Name the other throughout Africa. four.
Universal Language Liberal Arts Trivia: British Lit • Is Lambda Calculus a universal language ? • This 1883 coming-of-age tale of “pirates and – Can we compute any computable algorithm buried gold” by Robert Louis Stevenson had a using Lambda Calculus? vast influence on the popular perception of • To prove it is not : pirates. Its legacies include treasure maps – Find some Turing Machine that cannot be with an “X”, the Black Spot, tropical islands, simulated with Lambda Calculus and one-legged seamen with parrots on their • To prove it is : shoulders. – Show you can simulate every Turing Machine – Name the book. using Lambda Calculus – Name the morally gray, parrot-holding mutineer. Simulating Every Universal Language Turing Machine • Is Lambda Calculus a universal language ? – Can we compute any computable algorithm • A Universal Turing Machine can simulate using Lambda Calculus? every Turing Machine • To prove it is not : – Find some Turing Machine that cannot be • So, to show Lambda Calculus can simulated with Lambda Calculus simulate every Turing Machine, all we • To prove it is : need to do is show it can simulate a – Show you can simulate every Turing Machine Universal Turing Machine! using Lambda Calculus Simulating Computation Simulating Computation z z z z z z z z z z z z z z z z z z z z 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: Read/Write Infinite Tape ), X, L ), X, L ), #, R ), #, R Mutable Lists (, #, L input on the tape is (, #, L 2: 2: 1 look 1 look for ( for ( Finite State Machine Start Start transformed into a lambda (, X, R (, X, R Numbers expression HAL HAL Processing T #, 0, - T #, 0, - #, 1, - #, 1, - Finite State Machine Finite State Machine Way to make decisions (if) • Normal form is that value of Way to keep going that computation: output is the normal form • How do we simulate the FSM?
Recommend
More recommend