Lecture 15: Crazy Eddie and the Fixed Points Background

Slides:



Advertisements
Similar presentations
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 39: Lambda Calculus.
Advertisements

School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 3 LECTURE: LAMBDA CALCULUS PRACTICAL/TUTORIAL: (i) Do exercises given out.
Lecture 20: λ Calculus λ Calculus & Computability Yan Huang Dept. of Comp. Sci. University of Virginia.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
David Evans CS150: Computer Science University of Virginia Computer Science Lecture 36: Modeling Computing.
David Evans Class 15: P vs. NP (Smiley Puzzles and Curing Cancer) CS150: Computer Science University of Virginia Computer.
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.
1 Interactive Computer Theorem Proving CS294-9 October 19, 2006 Adam Chlipala UC Berkeley Lecture 9: Beyond Primitive Recursion.
P2 Chapter 8 CIE Centre A-level Pure Maths © Adam Gibson.
(Thunking about Thunks)
CSE332: Data Abstractions Lecture 7: AVL Trees
The foundation of calculus
Lecture 4: Metacircles Eval Apply David Evans
Evaluating Limits Analytically
Unit – 3 :LAMBDA CALCULUS AND FUNCTIONAL PROGRAMMING
Lecture 6: Lambda Calculus
Decrease-and-Conquer Approach
Lecture 2: Schreme David Evans
Class 27: Universal Turing Machines CS150: Computer Science
Class 30: Models of Computation CS200: Computer Science
Limits and Continuity The student will learn about: limits,
Lecture 37: A Universal Computer
Lambda Calculus Revisited
Review Calculus.
Class 19: Think Globally, Mutate Locally CS150: Computer Science
Discrete Structure II: Introduction
NP-Completeness Yin Tat Lee
ASU 101: The ASU Experience Computer Science Perspective
Lecture 21: Inheritance CS200: Computer Science University of Virginia
Turnstile Streaming Algorithms Might as Well Be Linear Sketches
Information Security CS 526
Lecture 11: All Sorts CS200: Computer Science University of Virginia
Class 36: The Meaning of Truth CS200: Computer Science
This Lecture Substitution model
CSCE 489- Problem Solving Programming Strategies Spring 2018
CSE373: Data Structures & Algorithms Lecture 5: AVL Trees
CS 188: Artificial Intelligence Fall 2007
Lecture 21: Crosscutting Aspect-Oriented Programming Background
Lecture 10: The Return of Paco Background just got here last week
CS21 Decidability and Tractability
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
Guest Lecture by David Johnston
What LIMIT Means Given a function: f(x) = 3x – 5 Describe its parts.
Class 33: Making Recursion M.C. Escher, Ascending and Descending
Reasoning About DrScheme Programs in ACL2
Information Security CS 526
Lecture 10: Using Object-Oriented Languages
Recursion Great fleas have little fleas upon their backs to bite 'em, And little fleas have lesser fleas, and so ad infinitum. And the great fleas themselves,
Class 24: Computability Halting Problems Hockey Team Logo
Programming Languages and Compilers (CS 421)
NP-Completeness Yin Tat Lee
Lecture 19: Proof-Carrying Code Background just got here last week
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
This Lecture Substitution model
Class 33: Learning to Count CS200: Computer Science
David Evans Lecture 19: ||ism I don’t think we have found the right programming concepts for parallel computers yet.
Plan to Do Student Speeches
Lecture 12: Minding your Ps & Qs:
Class 26: Modeling Computing CS150: Computer Science
Lecture 5: DES Use and Analysis Background just got here last week
Lecture 14: Mocking Mockingbirds
CS 611: Lecture 10 More Lambda Calculus September 20, 1999
This Lecture Substitution model
Information Security CS 526
Induction: One Step At A Time
Group 4: Song Li, Ying Lu, Hexin Wang, and Michael Walker May 1, 2000
Lecture 23: Computability CS200: Computer Science
Presentation transcript:

David Evans http://www.cs.virginia.edu/~evans Lecture 15: Crazy Eddie and the Fixed Points Background just got here last week finished degree at MIT week before Philosophy of advising students don’t come to grad school to implement someone else’s idea can get paid more to do that in industry learn to be a researcher important part of that is deciding what problems and ideas are worth spending time on grad students should have their own project looking for students who can come up with their own ideas for research will take good students interested in things I’m interested in – systems, programming languages & compilers, security rest of talk – give you a flavor of the kinds of things I am interested in meant to give you ideas (hopefully even inspiration!) but not meant to suggest what you should work on CS655: Programming Languages University of Virginia Computer Science David Evans http://www.cs.virginia.edu/~evans

University of Virginia CS 655 Menu Billy Bob and the Beta Reducers Survey Results Fixed Points 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 -term Evaluation Y   f. (( x.f (xx)) ( x. f (xx))) What is (Y I)? Recall I = z.z Evaluation rule: -reduction (substitution) (x. M)N   M [ x := N] Substitute N for x in M. 15 May 2019 University of Virginia CS 655

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))   ... 15 May 2019 University of Virginia CS 655

Ben 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)   ... 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 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 May 2019 University of Virginia CS 655

University of Virginia CS 655 Survey Results Only 2 really conclusive results: Less Readings (6 way too much, 15 too much, 4 just right) More Pizza (1 for, none against) 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Survey Results Lectures majority too fast, but not overwhelming Programming 12 just right, 9 not enough, 1 too much Topics 6 fewer topics/more depth, 10 more topics/less depth, 2 fewer topics/less depth, 2 more topics/more depth (5 write in like current mix) Grading 13 prefer unbounded, 8 prefer traditional, 4 don’t care 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Elevator Speeches 15 May 2019 University of Virginia CS 655

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) 15 May 2019 University of Virginia CS 655

More interesting for functions Functions are just sets of input/output pairs. f: (Nat  Nat) =  n. (1 + ( f n)) f: (Nat  Nat) =  n. ( f (1 + n)) No solutions (over natural numbers) – would require x = 1 + x. Infinitely many solutions – e.g., f(x) = 3. 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Generating Functions Any recursive definition can be encoded with a (non-recursive) generating function f: (Nat  Nat) =  n. (1 + ( f n))  g: (Nat  Nat)  (Nat  Nat) =  f.  n. (1 + ( f n)) 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Fixed Points A fixed point of a function f: (D  D) is an element d D such that (f d) = d. Solution to a recursive definition is a fixed point of its associated generating function. 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Example fact: (Nat  Nat) =  n. if (n = 0) then 1 else (n * ( fact (n - 1))) gfact: (Nat  Nat)  (Nat  Nat) =  f. n. if (n = 0) then 1 else (n * ( f (n - 1))) 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 (gfact I) (gfact (z.z)) = n. if (n = 0) then 1 else (n * ((z.z) (n - 1))) Function that returns 1 for 0, 0 for 1, 2 for 2, ..., n * n-1 for n ~= 0. 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 (gfact factorial) (gfact factorial) = n. if (n = 0) then 1 else (n * (factorial (n - 1))) = factorial factorial is a fixed point of gfact 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Unsettling Questions Is a 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? 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 An odd example odds = { 1 }  { x + 2 | x  odds } godds = ({Nat}  {Nat}) =  s. { 1 }  { x + 2 | x  s} godds ({}) = {1} godds (godds ({}) ) = godds{1} = {1 , 3} goddsn ({}) = {1, 3, ..., (n * 2) + 1} OOPS - this is broken 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Oddities of Odds What is a fixed point of godds? All odd numbers: { 1, 3, 5, ... } What about: { 0, 1, 2, 3, 4, ... } ? What about: { 1, 3, 4, 5, 6, 7, ... } ? godds has infinitely many fixed points, the set of all odd numbers is the least fixed point. OOPS - this is broken 15 May 2019 University of Virginia CS 655

Iterative Fixed Point Technique 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. 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 . 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Partial Order A partial order is a pair (D, ) of a domain D and a relation that is for all a, b, c  D reflexive transitive and anti-symmetric a a a b and b c imply a c a b and b a imply a = b 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Partial Orders? (Nat, <=) (Nat, =) ({ burger, fries, coke }, yummier) where burger yummier fries, burger yummier coke, fries yummier coke ({ burger, fries, beer }, yummier) where burger yummier fries, fries yummier beer, beer yummier burger 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 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 {} 15 May 2019 University of Virginia CS 655

Partial Order of Functions ((D, D)  (E, E), DE) is a partial order using: f DE g if for all d  D, (f d) E (g d). double: Nat  Nat = n. if (n = 0) then 0 else (2 + (double (n – 1)) Is double fact under (Nat, <=)? No, (double 1) is not <= (fact 1) 15 May 2019 University of Virginia CS 655

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. 15 May 2019 University of Virginia CS 655

Least Fixed Point of gfact gfact: (Nat  Nat)  (Nat  Nat) =  f. n. if (n = 0) then 1 else (n * ( f (n - 1))) (gfactn (function with graph {})) = fact as n approaches infinity. 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Fixed Point Theorem Do all -calculus terms have a fixed point?  F ,  X  such that FX = X Proof: Let W =  x.F(xx) and X = WW. X = WW = ( x.F(xx))W   F (WW) = FX 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Why of Y? Y is  f. WW: Y   f. (( x.f (xx)) ( x. f (xx))) Y calculates a fixed point (but not necessarily the least fixed point) of any lambda term! If you’re not convinced, try calculating ((Y fact) n). 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Still Uncomfortable? 15 May 2019 University of Virginia CS 655

Remember the problem reducing Y Different reduction orders produce different results Reduction may never terminate Normal Form means no more ß-reductions can be done There are no subterms of the form (x. M)N Not all -terms can be written in normal form 15 May 2019 University of Virginia CS 655

Church-Rosser Theorem If a -term has a normal form, any reduction sequence that produces a normal form always the same normal form Computation is deterministic Some orders of evaluation might not terminate though Evaluating left-to-right finds the normal form if there is one. Proof by lack of space/time. 15 May 2019 University of Virginia CS 655

University of Virginia CS 655 Charge Next time: pragmatic issues of functional programming Rewrite rules Type inference Depositions due today, will be sent to opposing attorneys (including my comments if any) by Thursday PS3 is harder than PS2 15 May 2019 University of Virginia CS 655