1 / 33

David Evans cs.virginia/~evans

Lecture 10: Fixed Points ad Infinitum. M.C. Escher, Moebius Ants. David Evans http://www.cs.virginia.edu/~evans. CS655: Programming Languages University of Virginia Computer Science. Goal: Understand the Least Fixed Point Theorem.

mimir
Télécharger la présentation

David Evans cs.virginia/~evans

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 10: Fixed Points ad Infinitum M.C. Escher, Moebius Ants David Evans http://www.cs.virginia.edu/~evans CS655: Programming Languages University of Virginia Computer Science

  2. Goal: Understand theLeast Fixed Point Theorem If D is a pointed complete partial order, then a continuous functionf: D  D has a least fixed point (fixDf) defined by D{ (fnD ) | n 0 } University of Virginia CS 655

  3. Last Time • A domain is a structured set of values • A function domain is constructed from two primitive domains, D1 D2 by associating an element of D2 with each element of D1. • A fixed point of a function f: D1 D2 is an element d D such that f d = d. University of Virginia CS 655

  4. Last Time, cont. • Any recursive definition can be encoded with a (non-recursive) generating function by abstracting out the thing that is defined. • A fixed point of a generating function is a solution of its associated recursive definition. University of Virginia CS 655

  5. a a • a b and b a imply a = b • a b and b c imply a c Last Time, cont. • (D, ) is a partial order if is: • reflexive: • transitive: • anti-symmetric: • (D, ) is a pointed partial order if it has a bottom element u D such that ud for all elements d D. University of Virginia CS 655

  6. Ordered Product Domains If <D, D > and <E, E > is are POs, <Dx E, Dx E > is a partial order, ordered by: <d1, e1>Dx E <d2, e2> if d1 D d2and e1 Ee2 University of Virginia CS 655

  7. <1, 73> <3, 3> <0, 2> <2, 0> <0, 1> <1, 0> <0, 0> Ordered Product Example • What is << Nat,  >x < Nat,  >>? (Hasse diagram) University of Virginia CS 655

  8. Ordered Function Domains If <D, D > and <E, E > is are POs, <D E, D E > is a partial order, ordered by: f D  E f1DE f2 if for all d D,(f1 d)E (f2 d) University of Virginia CS 655

  9. Ordered Function Example < Bool,  > = { false, true } false  true true  false What is << Bool,  > < Bool,  >>? <{false, true}, {true, true}> <{false, false}, {true, true}> <{false, true}, {true, false}> <{false, false}, {true, false}> University of Virginia CS 655

  10. T-Shirt Exercise • What is the order of the domain: <<Bool,  >x < Bool,  > < Bool,  >> (includes xor, and, or, implies, ...) University of Virginia CS 655

  11. The Domain Nat 2 0 3 4 ... 1 Nat University of Virginia CS 655

  12. Ordered Function Bottom • What is the bottom of <Nat, > <Nat, > ? { <0, >, <1, >, <2, >, ... } = { <x, > } = { } If a function map has no entry for x, it maps x to . University of Virginia CS 655

  13. Least Upper Bounds • The least upper bound of a subset X of a domain D is the weakest element of X that is at least as strong as every other element of X. l  X = D X if for everyx  X, x l and for everym  X such thatx m x  X, l m University of Virginia CS 655

  14. Least Upper Bounds in Nat { 0, 2, 4, 6, ... } = any element of { 0, 2, 4, 6, ... } Nat {Nat, 3, 17} = 3 or 17 Nat 2 0 3 4 ... 1 Nat University of Virginia CS 655

  15. Complete Partial Orders • A partial order D iscomplete if every chain in D has a least upper bound in D. • Any upward chain through a Hasse diagram converges to a limit • All finite partial orders are complete • Most sensible partial orders (including Nat) are complete (see Gifford’s notes for some incomplete POs.) University of Virginia CS 655

  16. Monotonic Functions • f D  E is monotonic if d1 Dd2 implies (fd1)E (fd2). • Is not over << Bool,  > < Bool,  >> monotonic? • Is { <x, x * 2>} over << Nat,  > < Nat,  >> monotonic? • What functions are monotonic over NatNat? University of Virginia CS 655

  17. Continuous Functions • f D  E is continuous if, for all chains C in D, f applied to the least element of the chain over D is the least element of (fc) for cC over E. • Continuity is like monotonicity, but it works for limits of infinite chains also. • If the CPO is finite, monotonicity implies continuity. • Continuity always implies monotonicity University of Virginia CS 655

  18. Monotonic/Continuous Functions in Domain Nat 2 0 3 4 ... 1 Nat What is a monotonic function in Nat? What is a continuous function in Nat? University of Virginia CS 655

  19. Least Fixed Point Theorem • If D is a pointed complete partial order, then a continuous function f: D  D has a least fixed point (fixDf) defined by D{ (fnD ) | n 0 } The least upper bound of applying f any number of times, starting with D. University of Virginia CS 655

  20. Sanity Check In g:(Nat  Nat)  (Nat  Nat) =  f. n. if (n = 0) then 1 else (n * ( f (n - 1))) What is (fixNat  Natg)? University of Virginia CS 655

  21. Sanity Check g:(Nat Nat)  (Nat Nat) =  f. n. if (n = 0) then 1 else (n * ( f (n - 1))) What is (fixNat Natg)? University of Virginia CS 655

  22. What is the bottom of Nat Nat? { <x, > | x Nat} University of Virginia CS 655

  23. What is (g { <x, > | x Nat})? g =  f. n. if (n = 0) then 1 else (n * ( f (n - 1))) g { <x, > | x Nat} = {<0, 1>, <x, > | x > 0 and x Nat } University of Virginia CS 655

  24. What is (g (g { <x, > | x Nat}))? g =  f. n. if (n = 0) then 1 else (n * ( f (n - 1))) g { <0, 1>, <x, > | x > 0 and x Nat } = { <0, 1>, <1, 1>, <x, > | x > 1 and x Nat } University of Virginia CS 655

  25. What is LUB (gn{ <x, > | x Nat}))? g =  f. n. if (n = 0) then 1 else (n * ( f (n - 1))) g { <0, 1>, <x, > | x > 0 and x Nat } = { <0, 1>, <1, 1>, <2, 2>, <3, 6>, ...} = {<x, x!> | x Nat } University of Virginia CS 655

  26. Getting to the  of things • Think of bottom as the element with the least information, or the “worst” possible approximation. • To find the least fixed point in a function domain, start with the bottom of the function domain and iterate... University of Virginia CS 655

  27. Fixed Point Theorem • Do all -calculus terms have a fixed point? • (Smullyan: Is there a Sage bird?) University of Virginia CS 655

  28. Finding the Sage Bird •  F ,  X such thatFX = X • Proof: LetW =  x.F(xx) andX = WW. X = WW = ( x.F(xx))W   F (WW) = FX University of Virginia CS 655

  29. 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). (PS1, 1e) University of Virginia CS 655

  30. Still Uncomfortable? University of Virginia CS 655

  31. 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 University of Virginia CS 655

  32. 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 leftmost first finds the normal form if there is one. • Proof by trust the theory people, but don’t become one. University of Virginia CS 655

  33. Charge • PS2 is due Thursday • Domains are like types in programming languages, we will see them again soon... • Next time: Intro to Language Design University of Virginia CS 655

More Related