Class 33: Making Recursion M.C. Escher, Ascending and Descending

Slides:



Advertisements
Similar presentations
David Evans cs302: Theory of Computation University of Virginia Computer Science Lecture 17: ProvingUndecidability.
Advertisements

David Evans CS200: Computer Science University of Virginia Computer Science Class 30: Models of Computation.
Class 39: Universality cs1120 Fall 2009 David Evans University of Virginia.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 39: Lambda Calculus.
1 Section 14.1 Computability Some problems cannot be solved by any machine/algorithm. To prove such statements we need to effectively describe all possible.
Computability and Complexity 5-1 Classifying Problems Computability and Complexity Andrei Bulatov.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 40: Computing with Glue and Photons.
Prof. Busch - LSU1 Decidable Languages. Prof. Busch - LSU2 Recall that: A language is Turing-Acceptable if there is a Turing machine that accepts Also.
Courtesy Costas Busch - RPI1 A Universal Turing Machine.
Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing.
David Evans cs302: Theory of Computation University of Virginia Computer Science Lecture 2: Modeling Computers.
Class 19: Undecidability in Theory and Practice David Evans cs302: Theory of Computation University of Virginia Computer.
1 Reducibility. 2 Problem is reduced to problem If we can solve problem then we can solve problem.
Theory of Computing Lecture 19 MAS 714 Hartmut Klauck.
David Evans CS200: Computer Science University of Virginia Computer Science Class 31: Universal Turing Machines.
Lecture 20: λ Calculus λ Calculus & Computability Yan Huang Dept. of Comp. Sci. University of Virginia.
Class 37: Computability in Theory and Practice cs1120 Fall 2011 David Evans 21 November 2011 cs1120 Fall 2011 David Evans 21 November 2011.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 15-1 Mälardalen University 2012.
Week 10Complexity of Algorithms1 Hard Computational Problems Some computational problems are hard Despite a numerous attempts we do not know any efficient.
David Evans CS200: Computer Science University of Virginia Computer Science Class 38: Fixed Points and Biological Computing.
Lecture 8: The Meaning of Life, Searching for Truth and The Stuff Primitives are Made Of (and a smattering of Quantum Physics) David Evans
A Universal Turing Machine
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 36: Modeling Computing.
1 Turing’s Thesis. 2 Turing’s thesis: Any computation carried out by mechanical means can be performed by a Turing Machine (1930)
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Sections 7.1, 7.2 Sections 7.1, 7.2 Functions and Domain.
Strings Basic data type in computational biology A string is an ordered succession of characters or symbols from a finite set called an alphabet Sequence.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
David Evans CS150: Computer Science University of Virginia Computer Science Class 32: Computability in Theory and Practice.
The Church-Turing Thesis Chapter Are We Done? FSM  PDA  Turing machine Is this the end of the line? There are still problems we cannot solve:
Recursively Enumerable and Recursive Languages. Definition: A language is recursively enumerable if some Turing machine accepts it.
MA/CSSE 474 Theory of Computation Universal Turing Machine Church-Turing Thesis Delayed due dates for HWs See updated schedule page. No class meeting.
1 A Universal Turing Machine. 2 Turing Machines are “hardwired” they execute only one program A limitation of Turing Machines: Real Computers are re-programmable.
The Acceptance Problem for TMs
A Universal Turing Machine
Lecture 6: Lambda Calculus
Recursively Enumerable and Recursive Languages
Class 27: Universal Turing Machines CS150: Computer Science
Class 30: Models of Computation CS200: Computer Science
CSCI 2670 Introduction to Theory of Computing
CSCI 2670 Introduction to Theory of Computing
Lecture 37: A Universal Computer
Lambda Calculus Revisited
CS154, Lecture 7: Turing Machines.
Decidable Languages Costas Busch - LSU.
Class 36: The Meaning of Truth CS200: Computer Science
Decidability and Undecidability
Lecture 22: P = NP? CS200: Computer Science University of Virginia
Computability and Complexity
Class 37: Making Lists, Numbers and Recursion from Glue Alone
Proposed in Turing’s 1936 paper
Formal Languages, Automata and Models of Computation
Recall last lecture and Nondeterministic TMs
Class 24: Computability Halting Problems Hockey Team Logo
CS21 Decidability and Tractability
Class 31: Universal Turing Machines CS200: Computer Science
Lecture 10: Fixed Points ad Infinitum M.C. Escher, Moebius Ants
Class 34: Models of Computation CS200: Computer Science
Class 33: Learning to Count CS200: Computer Science
CSE S. Tanimoto Lambda Calculus
Class 26: Modeling Computing CS150: Computer Science
Lecture 14: Mocking Mockingbirds
Lecture 15: Crazy Eddie and the Fixed Points Background
Instructor: Aaron Roth
Computability and Undecidability
The Church-Turing Thesis and Turing-completeness
Lecture 23: Computability CS200: Computer Science
Presentation transcript:

David Evans http://www.cs.virginia.edu/evans Class 33: Making Recursion M.C. Escher, Ascending and Descending also known as f. (( x.f (xx)) ( x. f (xx)) CS200: Computer Science University of Virginia Computer Science David Evans http://www.cs.virginia.edu/evans

Menu Recap: Proving Lambda Calculus is Universal How to make recursive definitions without define Fixed points 16 April 2003 CS 200 Spring 2003

Lambda Calculus Review term ::= variable |term term | (term)|  variable . term Parens are just for grouping, not like in Scheme -reduction (renaming) y. M  v. (M [y v]) where v does not occur in M. -reduction (substitution) (x. M)N   M [ x N ] ( f. (( x.f (xx)) ( x. f (xx)))) (z.z) 16 April 2003 CS 200 Spring 2003

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 16 April 2003 CS 200 Spring 2003

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 1 2: look for ( Start (, X, R HALT #, 1, - #, 0, - Finite State Machine 16 April 2003 CS 200 Spring 2003

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 ), X, L ), #, R (, #, L 1 2: look for ( Read/Write Infinite Tape Mutable Lists Finite State Machine Numbers to keep track of state Processing Way of making decisions (if) Way to keep going Start (, X, R HALT #, 1, - #, 0, - Finite State Machine We have this, but we cheated using  to make recursive definitions! 16 April 2003 CS 200 Spring 2003

Alyssa 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))  ... 16 April 2003 CS 200 Spring 2003

Recursive Definitions Which of these make you uncomfortable? x = 1 + x x = 4 – x x = 9 / x x = x x = 1 / (16x3) No solutions over integers 1 integer solution, x = 2 2 integer solutions, x = 3, x = -3 Infinitely many integer solutions No integer solutions, two rational solutions (1/2 and –1/2), four complex solutions (1/2, -1/2, i/2, -i/2) 16 April 2003 CS 200 Spring 2003

f  x. sub 4 x Equations  Functions Find an x such that (f x) = x. Same as solve for x. sub  x . y. if (zero? y) x (sub (pred x) (pred y)) 16 April 2003 CS 200 Spring 2003

What’s a function? f  x. sub 4 x f: Nat  Nat { <0, 4>, <1, 3>, <2, 2>, <3, 1>, <4, 0>, <5, ???>, ... } 16 April 2003 CS 200 Spring 2003

Domains Set: unordered collection of values Nat = { 0, 2, 1, 4, 3, 6, 5, 8, 7, ... } Domains: like a set, but has structure Nat = { 0, 1, 2, 3, 4, 5, 6, 7, 8, ... } where 0 is the least element, and there is an order of the elements. 16 April 2003 CS 200 Spring 2003

Making Domains Primitive domains can be combined to make new domains Product domain: D1 x D2 Pairs of values Nat x Nat = { (tupleNat,Nat 0 0), (tupleNat,Nat 0 1), (tupleNat,Nat 1 0), (tupleNat,Nat 1 1), (tupleNat,Nat 0 2), ... } 16 April 2003 CS 200 Spring 2003

Functions A set of input-output pairs The inputs (Di) and outputs (Do) are elements of a domain The function is an element of the domain Di  Do. It is a (completely defined) function if and only if for every element d  Di, the set of input-output pairs has one member whose first member matches d. 16 April 2003 CS 200 Spring 2003

Functions? f: Nat  Nat  z. subNat  Nat 4 z f: Nat  Int  z. subNat  Int 4 z f: Nat  Nat  z. addNat  Nat z 1 Not a function since there is no value in output domain for z > 4. 16 April 2003 CS 200 Spring 2003

Functions f: (Nat  Nat)   n. add 1 ( f n)) f: (Nat  Nat)   n. f (add 1 n)) No solutions (over natural numbers) – would require x = 1 + x. Infinitely many solutions – e.g., f(x) = x. 3 { <0, 3>, <1, 3>, <2, 3>, ... } 16 April 2003 CS 200 Spring 2003

Fixed Points A fixed point of a function f: (D  D) is an element d D such that (f d) = d. Examples: f: Nat  Int  z. sub 4 z f: Nat  Nat  z. mul 2 z f: Nat  Nat  z.z 2 infinitely many 16 April 2003 CS 200 Spring 2003

Generating Functions f: (Nat  Nat)   n. (add 1 ( f n)) Any recursive definition can be encoded with a (non-recursive) generating function f: (Nat  Nat)   n. (add 1 ( f n))  g: (Nat  Nat)  (Nat  Nat)   f.  n. (add 1 ( f n)) Solution to a recursive definition is a fixed point of its associated generating function 16 April 2003 CS 200 Spring 2003

Example fact: (Nat  Nat)  n. if (= n 0) 1 (mul n (fact (sub n 1))) gfact: (Nat  Nat)  (Nat  Nat)  f.n. if (= n 0) 1 (mul (n (f (sub n 1))) 16 April 2003 CS 200 Spring 2003

gfact I gfact (z.z)  n. if (= n 0) 1 (mul (n ((z.z) (sub n 1))) gfact: (Nat  Nat)  (Nat  Nat)  f.n. if (= n 0) 1 (mul (n (f (sub n 1))) gfact (z.z)  n. if (= n 0) 1 (mul (n ((z.z) (sub n 1))) What is (gfact I) 5? 16 April 2003 CS 200 Spring 2003

gfact fact gfact fact  n. if (= n 0) 1 (mul n (fact (sub n 1))) gfact: (Nat  Nat)  (Nat  Nat)  f.n. if (= n 0) 1 (mul (n (f (sub n 1))) fact : (Nat  Nat)  n. if (= n 0) 1 (mul (n (fact (sub n 1))) gfact fact gfact fact  n. if (= n 0) 1 (mul n (fact (sub n 1)))  fact fact is a fixed point of gfact 16 April 2003 CS 200 Spring 2003

Unsettling Questions Is the factorial function the only fixed point of gfact? Given an arbitrary function, how does one find a fixed point? If there is more than one fixed point, how do you know which is the right one? 16 April 2003 CS 200 Spring 2003

Iterative Fixed Point Technique To find a fixed point of g: D  D Start with some element d D Calculate g(d), g(g(d)), g(g(g(d))), ... until you get g(g(v)) = v then v is a fixed point. 16 April 2003 CS 200 Spring 2003

Where to start? If you start with   D you get the least fixed point (which is the “best” one)  (pronounced “bottom”) is the element of D such that for any element d D,  d. means “has less information than” or “is weaker than” Not all domains have a . 16 April 2003 CS 200 Spring 2003

Pointed Partial Order A partial order (D, ) is pointed if it has a bottom element u  D such that u d for all elements d  D. Bottom of (Nat, <=)? Bottom of (Nat, =)? Bottom of (Int, <=)? Bottom of ({Nat}, <=)? Not a pointed partial order Not a pointed partial order {} 16 April 2003 CS 200 Spring 2003

Getting to the  of things Think of bottom as the element with the least information, or the “worst” possible approximation. Bottom of Nat  Nat is a function that is undefined for all inputs. That is, the function with the graph {}. To find the least fixed point in a function domain, start with the function whose graph is {} and iterate. 16 April 2003 CS 200 Spring 2003

Least Fixed Point of gfact gfact: (Nat  Nat)  (Nat  Nat)   f. n. if (= n 0) 1 mul n ( f (sub n 1))) gfactn (function with graph {}) = fact as n approaches infinity. 16 April 2003 CS 200 Spring 2003

Fixed Point Theorem Do all -calculus terms have a fixed point? 16 April 2003 CS 200 Spring 2003

Fixed Point Theorem  F ,  X  such that FX = X Proof: Let W =  x.F(xx) and X = WW. X = WW = ( x.F(xx))W   F (WW) = FX 16 April 2003 CS 200 Spring 2003

Why of Y? Y is  f. WW: Y calculates a fixed point of any lambda term! Y   f. ( x.f (xx)) ( x. f (xx)) Y calculates a fixed point of any lambda term! Hence: we don’t need define to do recursion! Works in Scheme too - check the “lecture” from the Adventure Game 16 April 2003 CS 200 Spring 2003

Fixed Point The fixed point of our Turing Machine simulator on some input is the result of running the TM on that input. If there is no fixed point, the TM doesn’t halt! fixed-point TM input   result of running TM on input 16 April 2003 CS 200 Spring 2003

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 ), X, L ), #, R Read/Write Infinite Tape Mutable Lists Finite State Machine Numbers to keep track of state Processing Way of making decisions (if) Way to keep going (, #, L 1 2: look for ( Start (, X, R HALT #, 1, - #, 0, - Finite State Machine 16 April 2003 CS 200 Spring 2003

Mystery 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))) 16 April 2003 CS 200 Spring 2003

QED Lambda calculus is a Universal Programming language All you need is beta-reduction and you can compute anything Integers, booleans, if, while, +, *, =, <, classes, define, inheritance, etc. are for wimps! Real programmers only use  and beta-reduction. 16 April 2003 CS 200 Spring 2003

Charge Friday: chance to ask questions before Exam 2 is handed out Email questions before if you want to make sure they are covered Today’s lecture is not covered by Exam 2 Office hours this week: Wednesday, after class - 3:45 Thursday 10am-10:45am; 4-5pm. 16 April 2003 CS 200 Spring 2003