Goal Game Plan Partially-Ordered

Goal Game Plan Partially-Ordered

2/2/2013 Goal • Many problems in programming languages can be formulated as the solution of a set of mutually recursive equations: D: set, f,g:DxD D x = f(x,y) y = g(x,y) •Examples – Parsing: first/follow sets in LL(k) parsing – PL semantics Solving fixpoint equations – Dataflow analysis • General questions – What assumptions on D, f, and g are sufficient to ensure that such a system of equations has a solution? – If system has multiple solutions, which solution do we really want? – How do we compute that solution? •Keywords: – Assumptions on D: partially-ordered set (poset), semi-lattice, lattice, complete lattice,… – Assumptions on functions f,g: monotonic, continuous, extensive,…. – Solutions: fixpoint, least fixpoint, greatest fixpoint,.. Game plan Partially-ordered set • Set D with a binary relation < that is • Finite partially-ordered set with least element: D – reflexive: x < x … • Function f: DD – anti-symmetric: x < y and y < x x=y 3 • Monotonic function f: DD – transitive: x < y and y < z x < z • Fixpoints of monotonic function f:DD • Example: set of integers ordered 2 – Least fixpoint by standard < relation 1 • Solving equation x = f(x) – poset generalizes this – Least solution is least fixpoint of f 0 • Generalization to case when D has a greatest • Graphical representation of poset: element T – Graph in which nodes are elements of -1 – Least and greatest solutions to equation x = f(x) D and relation < is shown by arrows -2 • Generalization of systems of equations – Usually we omit transitive arrows to simplify picture • Semi-lattices and lattices -3 • Not a poset: – D = {a,b}, {a < a, b < b, a < b, b < a} .. 1 2/2/2013 Another example of poset Finite poset with least element • Powerset of any set {a,b,c} • Poset in which – set is finite 12 ordered by set – there is a least element that is containment is a poset below all other elements in 6 {a,b} {a,c} {b,c} poset • In example shown to •Examples: 4 – Set of primes ordered by the left, poset elements natural ordering is a poset but 3 is not finite are {}, {a}, {a,b},{a,b,c}, {a} {b} {c} – Factors of 12 ordered by 2 etc. natural ordering on integers is a finite poset with least – x < y if x is a subset of y 1 { } element – Powerset example from previous slide is a finite poset with least element ({ }) Domain Functions on domains • Since “finite partially-ordered set with a • If D is a domain, f:DD least element” is a mouthful, we will just – a function maps each element of D to some abbreviate it to “domain”. element of D itself • Later, we will generalize the term “domain” • Examples: for D = powerset of {a,b,c} to include other posets of interest to us in – f(x) = x U {a} the context of dataflow analysis. • so f maps { } to {a}, {b} to {a,b} etc. – g(x) = x – {a} – h(x) = {a} - x 2 2/2/2013 Monotonic functions Examples • Function f: DD where D is a domain is • Domain D is powerset of {a,b,c} monotonic if • Monotonic functions: (x in D) –x <y f(x) < f(y) –x { } (why?) –x x U {a} • Common confusion: people think f is monotonic –x x – {a} if x < f(x). This is a different property called • Not monotonic: extensivity. –x {a} – x • Intuition: • Why? Because { } is mapped to {a} and {a} is mapped to { }. – think of f as an electrical circuit mapping input to • Extensivity output –x x U {a} is extensive and monotonic – f is monotonic if increasing the input voltage causes –x x – {a} is not extensive but monotonic the output voltage to increase or stay the same • Exercise: define a function on D that is extensive but not – f is extensive if the output voltage is greater than or monotonic equal to the input voltage Fixpoint of f:DD Fixpoint theorem(I) • Suppose f: D D. A value x is a fixpoint of • If D is a domain, is its least element, and f if f(x) = x. That is, f maps x to itself. f:DD is monotonic, then f has a least fixpoint that is the largest element in the sequence • Examples: D is powerset of {a,b,c} (chain) – Identity function: xx , f(), f(f()), f(f(f())),…. • Every point in domain is a fixpoint of this function • Examples: for D = power-set of {a,b,c}, so is { } –x x U {a} – Identity function: sequence is { }, { }, { }… so least • {a}, {a,b}, {a,c}, {a,b,c} are all fixpoints fixpoint is { }, which is correct. –x {a} – x –x x U {a}: sequence is { }, {a},{a},{a},… so least • no fixpoints fixpoint is {a} which is correct 3 2/2/2013 Proof of fixpoint theorem Solving equations • Largest element of chain is a fixpoint: • If D is a domain and f:DD is monotonic, – <f (by definition of ) –f() < f(f()) (from previous fact and monotonicity of f) then the equation x = f(x) has a least –f(f()) < f(f(f())) (same argument) solution given by the largest element in the we have a chain , f(), f(f()), f(f(f())),… – since the set D is finite, this chain cannot grow arbitrarily, so it has some sequence , f(), f(f()), f(f(f())), … largest element that f maps to itself. Therefore, we have constructed a fixpoint of f. • This is the least fixpoint • Proof: follows trivially from fixpoint – let p be any other fixpoint of f theorem – < p (from definition of ) –So f() < f(p) = p (monotonicity of f) – similarly f(f()) < p etc. – therefore all elements of chain are < p, so largest element of chain must be < p – therefore largest element of chain is the least fixpoint of f. Easy generalization Another result • Proof goes through • If D is a domain with a greatest element T even if D is not a and f:DD is monotonic, then the finite set but only …….. …….. equation x = f(x) has a greatest solution has finite height given by the smallest element in the – no infinite chains descending sequence T, f(T), f(f(T)), f(f(f(T))), … • Proof: left to reader 4 2/2/2013 Functions with multiple arguments Fixpoint theorem(II) • If D is a domain, a function f(x,y):DxDD • If D is a domain and f,g:DxDD are that takes two arguments is said to be monotonic, the following system of monotonic if it is monotonic in each simultaneous equations has a least argument when the other argument is held solution computed in the obvious way. constant. x = f(x,y) • Intuition: y = g(x,y) – electrical circuit has two inputs • You can easily generalize this to more – if you increase voltage on any one input than two equations and to the case when keeping voltage on other input fixed, the D has a greatest element T. output voltage stays the same or increases Computing the least solution for a system of equations Work-list based algorithm • Consider • Obvious point: it is not necessary to reevaluate a function if its inputs have not changed x = f(x,y,z) • Worklist based algorithm: y = g(x,y,z) – initialize worklist with all equations – initialize solution vector S to all z = h(x,y,z) – while worklist not empty do • get equation from worklist • Obvious iterative strategy: evaluate all • evaluate rhs of equation with current solution vector values and update entry corresponding to lhs variable in solution vector equations at every step (Jacobi iteration) • put all equations that use this variable in their RHS on worklist f(,,) • You can show that this algorithm will compute the least solution to the system of equations , g(,,) , ….. h(,, • General approach is called round-robin scheduling of equations 5 2/2/2013 Upper and lower bounds Example of lattice • If (D, ·) is po set and S µ D, l 2D is a lower bound of S if • Powerset of finite set is classical {a,b,c} –8x 2S. l ·x – Example: lower bounds of {c,d} are d and f example of a lattice • In general, a given S may have many lower bounds. a • Greatest lower bound (glb) of S: greatest element of D • Meet is set intersection that is a lower bound of S b c – Caveat: glb may not always exist • Join is set union {a,b} {a,c} {b,c} – Example: lower bounds of {b,c} are d,e,f but there is no glb • If for every pair of elements x,y 2 D glb({x,y}) exists, we d e • If you “flip” this lattice over, you can define a function called meet (Æ:D£ D ! D) – x Æ y = glb({x,y}) get another lattice – Idempotent: x Æ x = x f – Commutative: x Æ y = y Æ x – least element is {a,b,c} {a} {b} {c} – Associative: x Æ(y Æz) = (x Æy) Æz • Analogous notions: upper bounds, least upper bounds, – set union is meet join (Ç) – set intersection is join • Meet semilattice: – partially ordered set in which every pair of elements has a { } glb • Examples of posets that are not • Join semilattice lattices – analogous notion • Lattice: both a meet and join semilattice – see previous slide Fixpoint equations in lattices Summary • Solving systems of simultaneous equations in • If (D,·, Æ, Ç) is a finite lattice, it has a least which the underlying structure is a partially and greatest element. ordered set with various properties is basic to many problems in PL • Meet and join functions are monotonic – usually referred to as “fixpoint equations” • Therefore, if (D,·,Æ,Ç) is a finite lattice, • Given fairly reasonable conditions on the rhs functions and the partially ordered set, there are fixpoint theorem (II) applies even if some guaranteed to be solutions to such equations, and of the functions f,g etc.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us