CS 641 Lecture -*- Outline -*- * Complete Partial Orders and the Fixed Point Theorem ** Motivation: problems with recursive definitions (Schmidt 3.3, 6.0) Convenient to describe functions using recursion. both in denotational descriptions and in languages themselves e.g., q: Nat -> Nat_{\bot} q(x) = (x equals zero) -> one [] q(x plus one) Are such definitions well-defined? e.g., f1(x) = if (x equals zero) then one else \bot f2(x) = if (x equals zero) then one else two f3(x) = one and infinitely many others! e.g., example which has no solution? exactly one solution? Recursive domain equations have similar problems: e.g., Alist = Unit + (A x Alist) worse: D = B + (D -> D) has cardinality problems in set theroy We'll look for a category in which such equations have a cannonical solution (that matches our operational ideas) ** cpos and continuous functions *** Posets (partially ordered sets) and monotone functions D, R_D, where R_D is reflexive, transitive, and anti-symmetric e.g., subset ordering on {a,b,c} arrows are monotonic functions **** pointed posets \bot_D is the least element of D if it exists written \bot if D understood e.g., empty set in {a,b,c} ordered by subset arrows are monotonic functions or strict monotonic functions **** lattices have lub and glbs of finite sets of elements ***** join a join b (|_|) (lub) is element of D (if exists) such that a R_D (a join b) and b R_D (a join b) if d in d is an upper bound on a and b, then (a join b) R_D d ***** meet a meet b (|-|) (glb) is dual of join ***** complete lattices have lub and glb or arbitrary subsets **** chains are totally ordered subsets chain is family of elements that have consistent info e.g., sequence of approximations chains either finite or infinite, but non-empty **** directed (or filtered) sets: finite subsets have upper bounds (M subsetof D) is directed iff each finite subset u of M has an upper bound x in M. non-empty (since empty set is a subset) every chain is a directed set, but not conversely can check that pairs of elements have upper bounds. *** cpos (complete partial orders, w-complete partial orders, w-CPOs, domains) Schmidt: a cpo is a partial order such that every chain has a lub Gunter: a cpo is a poset such that each directed subset has a lub exercise: show that these are equivalent conditions **** arrows: continuous functions = monotone functions that preserve lubs of directed sets i.e., colimits f is continuous iff f is monotone and for all directed X in A, f(lub(X)) = lub(F(X)) extension of order to arrows, f,g:D -> E f <= g iff for all x, f(x) <= g(x) **** pointed (strict) cpo = cpo with a least element strict functions, f(\bot) = \bot **** examples a finite poset is a cpo e.g., 1 = {\bot} T = {\bot, true, false} powerset of X ordered by set inclusion lub is union flat pointed cpo, e.g., Nat_{\bot} partial functions between X and Y, ordered by set inclusion (on graphs) functions f:D ->E are continuous if f is monotone, D finite e.g., monotone f: T -> E is continuous. **** counterexamples set with infinite ascending chain e.g., Nat in usual order Rationals in usual order function f: Nat^{\top} -> {\bot,\top} such that f(i) = \bot and f(\top) = \top is monotone but not continuous. ** ccc of cpos *** {\bot} is terminal *** products of cpos if D and E are cpos, so is DxE, ordered pointwise (d,e) <= (d',e') iff d <= d' and e <= e' lemma (exchange): if M and N are directed and f: MxN -> D is monotone then lub_{x in M}(lub_{y in N}(f(x,y))) = lub_{y in N}(lub_{x in M}(f(x,y))) *** exponentials of cpos (hom-sets) [D -> E] = {f: D->E | f is continuous} lemma: this is a poset in the point-wise order. i.e., f <= g iff for all x in D, f(x) <= g(x) lemma: let M = F_{\alpha} be a directed set in [D -> E]. Then (lub(M))d = lub(F_{\alpha}(d)) theorem: cpos and continuous functions form a ccc with terminal object {\bot}. ** fixed point theorem def: if D is a pointed CPO and f: D->D is continuous, fix(f) = lub(f^n(\bot_D)). theorem: if D is a pointed CPO and f: D->D is continuous, then it has a least fixed point fix(f) in D. i.e., fix(f) = f(fix(f)) and fix(f) <= x for any x in D such that x = f(x) Pf: \bot_D is a fixed point of f. f^n(\bot) <= f^{n+1}(\bot), because f is monotonic. check the second property, noting that x is an upper bound. *** applications **** semantics of while loops given by fixed point of: F(f)(s) = s if [[B]]s = false f([[C]]s) if [[B]]s = true claim: F is continuous Pf: F: (States -> States) -> (States -> States) let M subsetof (States -> States) be directed check def. of continuous. **** factorial function (Schmidt 6.1) fact(n) = equals(n,zero) -> 1 [] else times(n,fact(minus(n,one))) Gunter regards fact as a partial function from Nat to Nat, Schmidt regards this as a total function from Nat to Nat_{\bot}. associated functional: F(fact)(n) = equals(n,zero) -> 1 [] else times(n,fact(minus(n,one))) what is \bot of [Nat -> Nat]? empty set (\x.\bot_{Nat_{\bot}}) F^1(\bot) is {(0,1)} F^n(\bot) is {(0,1),(1,1), ...(n-1,(n-1)!)} lub(F^n) = the factorial function *** categorical treatment (omit) let C be a category let R: C -> C be an endofunctor recall: functor is map on objects and arrows def: category (R : C) of R-algebras an R-algebra is a pair (A,a), where a: RA -> A is an arrow of C. a homomorphism between R-algebras (A,a) and (B,b) is an arrow f:A -> B of C such that a;f = Rf;b def: an fixed point of (R : C) is an object (A,a) such that a is an isomorphism def: a least-fixed point of (R : C) is an initial object of (R : C). why is an initial object a fixed point? if (A,a) is initial, then (RA,Ra) is an object of (R : A), so have unique arrow f:(A,a) -> (RA,Ra) stack above square on top of square with A in lower right. e.g., let [Nat -> Nat] be the w-CPO of partial function s from Nat to Nat. let C = [Nat -> Nat] as a category (by m: f -> g iff f <= g). use F as above from the factorial example as endofunctor (def above gives map on objects of [Nat -> Nat], for arrows m:f -> g, F(m): F(f) -> f(g) is uniquely defined.) can show only F-algebra is (factorial,id) *** uniformity (alternative to operational justification) (condition on fixed points that does not mention "least") lemma: composition is continuous def: a fixed point operator F is a class of continuous functions F_D: [D -> D] -> D such that for each cpo D and continuous f: D -> D, F_D(f) = f(F_D(f)). def: a fixed point operator F is uniform if, for all f: D -> D, for all g: E -> E, for all strict continuous h: D -> E, such that f;h = h;g, h(F_D(f)) = F_E(g). theorem: fix is the unique uniform fixed point operator. Pf: show fix has the required property (i.e. that it's continuous and uniform) for uniquieness, let E = {x in D | x <= fix(f)} in def of uniformity.