a universal language a universal language
play

A Universal Language A Universal Language Scheme. It contains terms - PDF document

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


  1. 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 λ -calculus What is Calculus? Alonzo Church, 1940 • In High School: (LISP was developed from λ -calculus, d/dx x n = nx n-1 [Power Rule] not the other way round.) d/dx (f + g) = d/dx f + d/dx g [Sum Rule] term = variable | term term Calculus is a branch of mathematics that deals with limits and the differentiation | λ variable . term and integration of functions of one or more variables... #3 #4 Surprise Liberal Arts Trivia Real Definition • A calculus is just a bunch of rules for • This branch of mathematics involving symbolic manipulating symbols. expressions manipulated according to fixed • People can give meaning to those rules takes its name from the diminutive form symbols, but that’s not part of the of calx/calcis, the latin word for rock or calculus. limestone. The diminutive word thus means “pebble”: in ancient times pebbles were • Differential calculus is a bunch of rules placed in sand and used for counting using for manipulating symbols. There is an techniques akin to those of the abacus. interpretation of those symbols corresponds with physics, slopes, etc. #5 #6

  2. Why? Lambda Calculus • Rules for manipulating strings of • Once we have precise and formal rules for symbols in the language: manipulating symbols, we can reason with those symbols and rules. term = variable | term term • Since we can interpret the symbols as | λ variable . term representing computations, we can use this system to reason about programs. • Humans can give meaning to those symbols in a way that corresponds to • (It will provide additional evidence that computations. Scheme and Turing machines have equivalent computational power.) #7 #8 Equivalent Computers? Evaluation Rules α -reduction (renaming) ... z z z z z z z term = variable | term term λ y . M ⇒ α λ v . ( M [each y replaced by v ]) | ( term ) | λ variable . term where v does not occur in M . ), X, L ≡ ¬ ), #, R ¬ (, #, L 2: 1 look for ( Start (, X, R λ y . M ⇒ α λ v . ( M [ y → v ]) β -reduction (substitution) HAL T #, 0, - #, 1, - where v does not occur in M . Finite State Machine ( λ x . M ) N ⇒ β M [each x replaced by N ] ( λ x . M ) N ⇒ β M [ x → N ] Turing Machine Lambda Calculus We'll see examples in a bit! #9 Liberal Arts Trivia: Music Liberal Arts Trivia: Geography • This music genre originated in Jamaica in the • This baltic country borders Romania, Serbia, 1950s and was the precursor to reggae. It Macedonia, Greece, Turkey and the Black Sea. combines elements of Caribbean mento and It was at one point ruled by the Ottomans, but calypso with American jazz and rhythm and is now a member of the EU and NATO. Sofia, blues. It is characterized by a walking bass line the capital and largest city, is one of the accented with rhythms on the offbeat. In the oldest cities in Europe and can be traced back 1980s it experience a third wave revival and is some 7000 years. The traditional cuisine of this often associated with punk and brass country features rich salads at every meal, as instruments. well as native pastries such as the banitsa .

  3. β - Reduction Lambda Examples (the source of all computation) • Identity Function – (define identity (lambda (x) x)) ( λ x . M ) N ⇒ β M [ x → N ] – identity = λ x. x • Square Function Replace all x ’s in M – (define square (lambda (x) (* x x)) with N’s – square = λ x. (* x x) • Add Function Note the syntax is different from Scheme: – (define (add x y) (+ x y)) ( λ x . M ) N === ((lambda (x) M) N) – (define add (lambda (x) (lambda (y) (+ x y)))) – add = λ x. λ y. (+ x y) β - Reduction Examples β - Reduction Examples • Square Function • Square Function Recall: ( λ x . M ) N ⇒ β M [ x → N ] Recall: ( λ x . M ) N ⇒ β M [ x → N ] – square = λ x. (* x x) – square = λ x. (* x x) – (λ x. (* x x)) 5 – (λ x. (* x x)) 5 – (λ x. (* x x)) 5 ⇒ β (* x x)[x → 5] – (λ x. (* x x)) 5 ⇒ β (* x x)[x → 5] – (λ x. (* x x)) 5 ⇒ β (* x x)[x → 5] ⇒ β (* 5 5) – (λ x. (* x x)) 5 ⇒ β (* x x)[x → 5] ⇒ β (* 5 5) • Add Function • Add Function – add = λ x. λ y. (+ x y) – add = λ x. λ y. (+ x y) – (λ x. λ y. (+ x y)) 3 ⇒ β ??? – (λ x. λ y. (+ x y)) 3 ⇒ β λ y. (+ 3 y) Get out some paper! – ((λ x. λ y. (+ x y)) 2) 6 ⇒ β ??? – ((λ x. λ y. (+ x y)) 2) 6 ⇒ β (λ y. (+ 2 y)) 6 ⇒ β (+ 2 6) Evaluating Lambda Expressions Some Simple Functions • redex : Term of the form ( λ x . M ) N I ≡ λ x . x Something that can be β - reduced C ≡ λ xy . yx Abbreviation for λ x .( λ y . yx ) • An expression is in normal form if it CII = ( λ x .( λ y . yx )) ( λ x . x ) ( λ x . x ) contains no redexes ( redices ). → β ( λ y . y ( λ x . x )) ( λ x . x ) • To evaluate a lambda expression, keep doing reductions until you get to normal → β λ x . x ( λ x . x ) form . → β λ x . x = I

  4. 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 → β ( λ x . xx ) ( λ x. ( λ z.z )( xx )) • The order in which you choose to do the → β ( λ x . xx ) ( λ x.xx ) reductions might change the result! – Just like lazy evaluation vs. eager evaluation → β ( λ x . xx ) ( λ x.xx ) → β ... Liberal Arts Trivia: Liberal Arts Trivia: Biology Classics • The Temple of • These even-toed ungulate bear 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. They at Olympus, and the are domesticated to provide meat and milk, as Tomb of Maussollos well as to serve as beasts of burden. The US are three of the Army had an active cavalry corps based on Seven Wonders of these beasts in California in the 19 th century, the Ancient World . and they have been used in wars throughout Name the other Africa. four.

  5. Liberal Arts Trivia: British Lit Take on Faith (until Grad PL) • All ways of choosing reductions that reduce • This 1883 coming-of-age tale of “pirates and a lambda expression to normal form will buried gold” by Robert Louis Stevenson had a produce the same normal form (but some vast influence on the popular perception of might never produce a normal form). pirates. Its legacies include treasure maps with • If we always apply the outermost lambda an “X”, the Black Spot, tropical islands, and first , we will find the normal form if there one-legged seamen with parrots on their is one. shoulders. – This is normal order reduction – corresponds – Name the book. to normal order ( lazy ) evaluation – Name the morally gray, parrot-holding mutineer. Universal Language Universal Language • Is Lambda Calculus a universal language ? • Is Lambda Calculus a universal language ? – Can we compute any computable algorithm – Can we compute any computable algorithm using Lambda Calculus? using Lambda Calculus? • To prove it is not : • To prove it is not : – Find some Turing Machine that cannot be – Find some Turing Machine that cannot be simulated with Lambda Calculus simulated with Lambda Calculus • To prove it is : • To prove it is : – Show you can simulate every Turing Machine – Show you can simulate every Turing Machine using Lambda Calculus using Lambda Calculus Simulating Every Simulating Computation Turing Machine z z z z z z z z z z z z z z z z z z z z • A Universal Turing Machine can simulate • Lambda expression every Turing Machine corresponds to a computation: ), X, L ¬ ), #, R ¬ (, #, L input on the tape is 2: 1 look for ( Start transformed into a lambda (, X, R • So, to show Lambda Calculus can simulate expression HAL #, 1, - T #, 0, - every Turing Machine, all we need to do is Finite State Machine • Normal form is that value of show it can simulate a Universal Turing that computation: output is Machine! the normal form • How do we simulate the FSM?

Recommend


More recommend