module Order.DCPO where
Directed-complete partial ordersπ
Let be a partial order. A family of elements is a semi-directed family if for every there merely exists some such and A semidirected family is a directed family when is merely inhabited.
module _ {o β} (P : Poset o β) where open Order.Reasoning P is-semidirected-family : β {Ix : Type o} β (Ix β Ob) β Type _ is-semidirected-family {Ix = Ix} f = β i j β β[ k β Ix ] (f i β€ f k Γ f j β€ f k) record is-directed-family {Ix : Type o} (f : Ix β Ob) : Type (o β β) where no-eta-equality field elt : β₯ Ix β₯ semidirected : is-semidirected-family f
Note that any family whose indexing type is a proposition is automatically semi-directed:
prop-indexedβsemidirected : β {Ix : Type o} β (s : Ix β Ob) β is-prop Ix β is-semidirected-family s prop-indexedβsemidirected s prop i j = inc (i , β€-refl , β€-refl' (ap s (prop j i)))
The poset is a directed-complete partial order, or DCPO, if it has least upper bounds of all directed families.
record is-dcpo : Type (lsuc o β β) where no-eta-equality field directed-lubs : β {Ix : Type o} (f : Ix β Ob) β is-directed-family f β Lub P f module β {Ix : Type o} (f : Ix β Ob) (dir : is-directed-family f) = Lub (directed-lubs f dir) open β using () renaming (lub to β; famβ€lub to famβ€β; least to β-least) public
Since least upper bounds are unique when they exist, being a DCPO is a property of a poset, and not structure on that poset.
Scott-continuous functionsπ
Let and be a pair of posets. A monotone map is called Scott-continuous when it preserves all directed lubs.
module _ {P Q : Poset o β} where private module P = Poset P module Q = Poset Q open is-directed-family open Total-hom
is-scott-continuous : (f : Posets.Hom P Q) β Type _ is-scott-continuous f = β {Ix} (s : Ix β P.Ob) (fam : is-directed-family P s) β β x β is-lub P s x β is-lub Q (f .hom β s) (f .hom x) is-scott-continuous-is-prop : β (f : Posets.Hom P Q) β is-prop (is-scott-continuous f) is-scott-continuous-is-prop _ = hlevel 1
If is a DCPO, then any function which preserves directed lubs is automatically a monotone map, and, consequently, Scott-continuous.
To see this, suppose weβre given with The family that sends to and to is directed: is inhabited, and is a least upper bound for arbitrary values of the family. Since preserves lubs, we have
opaque dcpo+scottβmonotone : is-dcpo P β (f : P.Ob β Q.Ob) β (β {Ix} (s : Ix β Poset.Ob P) (fam : is-directed-family P s) β β x β is-lub P s x β is-lub Q (f β s) (f x)) β β {x y} β x P.β€ y β f x Q.β€ f y dcpo+scottβmonotone is-dcpo f scott {x} {y} p = fs-lub .is-lub.famβ€lub (lift true) where s : Lift o Bool β P.Ob s (lift b) = if b then x else y sxβ€sfalse : β b β s b P.β€ s (lift false) sxβ€sfalse (lift true) = p sxβ€sfalse (lift false) = P.β€-refl s-directed : is-directed-family P s s-directed .elt = inc (lift true) s-directed .semidirected i j = inc (lift false , sxβ€sfalse _ , sxβ€sfalse _) s-lub : is-lub P s y s-lub .is-lub.famβ€lub = sxβ€sfalse s-lub .is-lub.least z lt = lt (lift false) fs-lub : is-lub Q (f β s) (f y) fs-lub = scott s s-directed y s-lub
Moreover, if is an arbitrary monotone map, and is a directed family, then is still a directed family.
monotoneβdirected : β {Ix : Type o} β {s : Ix β P.Ob} β (f : Posets.Hom P Q) β is-directed-family P s β is-directed-family Q (f .hom β s) monotoneβdirected f dir .elt = dir .elt monotoneβdirected f dir .is-directed-family.semidirected i j = β₯-β₯-map (Ξ£-mapβ (Γ-map (f .pres-β€) (f .pres-β€))) (dir .semidirected i j)
The identity function is Scott-continuous.
scott-id : β {P : Poset o β} β is-scott-continuous (Posets.id {x = P}) scott-id s fam x lub = lub
Scott-continuous functions are closed under composition.
scott-β : β {P Q R : Poset o β} β (f : Posets.Hom Q R) (g : Posets.Hom P Q) β is-scott-continuous f β is-scott-continuous g β is-scott-continuous (f Posets.β g) scott-β f g f-scott g-scott s dir x lub = f-scott (g .hom β s) (monotoneβdirected g dir) (g .hom x) (g-scott s dir x lub)
The category of DCPOsπ
DCPOs form a subcategory of the category of posets. Furthermore, since being a DCPO is a property, identity of DCPOs is determined by identity of their underlying posets: thus, the category of DCPOs is univalent.
DCPOs-subcat : β (o β : Level) β Subcat (Posets o β) (lsuc o β β) (lsuc o β β) DCPOs-subcat o β .Subcat.is-ob = is-dcpo DCPOs-subcat o β .Subcat.is-hom f _ _ = is-scott-continuous f DCPOs-subcat o β .Subcat.is-hom-prop f _ _ = is-scott-continuous-is-prop f DCPOs-subcat o β .Subcat.is-hom-id _ = scott-id DCPOs-subcat o β .Subcat.is-hom-β {f = f} {g = g} = scott-β f g DCPOs : β (o β : Level) β Precategory (lsuc (o β β)) (lsuc o β β) DCPOs o β = Subcategory (DCPOs-subcat o β) DCPOs-is-category : β {o β} β is-category (DCPOs o β) DCPOs-is-category = subcat-is-category Posets-is-category (Ξ» _ β hlevel 1)
module DCPOs {o β : Level} = Cat.Reasoning (DCPOs o β) DCPO : (o β : Level) β Type _ DCPO o β = DCPOs.Ob {o} {β} DCPOsβͺPosets : β {o β} β Functor (DCPOs o β) (Posets o β) DCPOsβͺPosets = Forget-subcat DCPOsβͺSets : β {o β} β Functor (DCPOs o β) (Sets o) DCPOsβͺSets = PosetsβͺSets Fβ DCPOsβͺPosets
Reasoning with DCPOsπ
The following pair of modules re-exports facts about the underlying posets (resp. monotone maps) of DCPOs (resp. Scott-continuous functions). They also prove a plethora of small lemmas that are useful in formalisation but not for informal reading.
These proofs are all quite straightforward, so we omit them.
module DCPO {o β} (D : DCPO o β) where poset : Poset o β poset = D .fst open Order.Reasoning (D .fst) public set : Set o set = el β D β Ob-is-set has-dcpo : is-dcpo poset has-dcpo = D .snd open is-dcpo (D .snd) public β-pointwise : β {Ix} {s s' : Ix β Ob} β {fam : is-directed-family poset s} {fam' : is-directed-family poset s'} β (β ix β s ix β€ s' ix) β β s fam β€ β s' fam' β-pointwise p = β.least _ _ (β _ _) Ξ» ix β β€-trans (p ix) (β.famβ€lub _ _ ix) module Scott {o β} {D E : DCPO o β} (f : DCPOs.Hom D E) where private module D = DCPO D module E = DCPO E mono : Posets.Hom D.poset E.poset mono = Subcat-hom.hom f monotone : β {x y} β x D.β€ y β f # x E.β€ f # y monotone = mono .pres-β€ opaque pres-directed-lub : β {Ix} (s : Ix β D.Ob) β is-directed-family D.poset s β β x β is-lub (D .fst) s x β is-lub (E .fst) (apply f β s) (f # x) pres-directed-lub = Subcat-hom.witness f directed : β {Ix} {s : Ix β D.Ob} β is-directed-family D.poset s β is-directed-family E.poset (apply f β s) directed dir = monotoneβdirected (Subcat-hom.hom f) dir pres-β : β {Ix} (s : Ix β D.Ob) β (dir : is-directed-family D.poset s) β f # (D.β s dir) β‘ E.β (apply f β s) (directed dir) pres-β s dir = E.β€-antisym (is-lub.least (pres-directed-lub s dir (D.β s dir) (D.β.has-lub s dir)) (E.β (apply f β s) (directed dir)) (E.β.famβ€lub (apply f β s) (directed dir))) (E.β.least (apply f β s) (directed dir) (apply f (D.β s dir)) Ξ» i β monotone (D.β.famβ€lub s dir i))
module _ {o β} {D E : DCPO o β} where private module D = DCPO D module E = DCPO E open is-directed-family open Total-hom
We also provide a couple methods for constructing Scott-continuous maps. First, we note that if a function is monotonic and commutes with some chosen assignment of least upper bounds, then it is Scott-continuous.
to-scott : (f : D.Ob β E.Ob) β (β {x y} β x D.β€ y β f x E.β€ f y) β (β {Ix} (s : Ix β D.Ob) β (dir : is-directed-family D.poset s) β is-lub E.poset (f β s) (f (D.β s dir))) β DCPOs.Hom D E to-scott f monotone pres-β = sub-hom fα΅ pres-lub where fα΅ : Monotone D.poset E.poset fα΅ .hom = f fα΅ .pres-β€ = monotone pres-lub : β {Ix} (s : Ix β D.Ob) β (dir : is-directed-family D.poset s) β β x β is-lub D.poset s x β is-lub E.poset (f β s) (f x) pres-lub s dir x x-lub .is-lub.famβ€lub i = monotone (is-lub.famβ€lub x-lub i) pres-lub s dir x x-lub .is-lub.least y le = f x E.β€β¨ monotone (is-lub.least x-lub _ (D.β.famβ€lub s dir)) β©E.β€ f (D.β s dir) E.=β¨ lub-unique (pres-β s dir) (E.β.has-lub (f β s) (monotoneβdirected fα΅ dir)) β©E.= E.β (f β s) _ E.β€β¨ E.β.least _ _ y le β©E.β€ y E.β€β
Furthermore, if preserves arbitrary least upper bounds, then it is monotone, and thus Scott-continuous.
to-scott-directed : (f : D.Ob β E.Ob) β (β {Ix} (s : Ix β D.Ob) β (dir : is-directed-family D.poset s) β β x β is-lub D.poset s x β is-lub E.poset (f β s) (f x)) β DCPOs.Hom D E to-scott-directed f pres .Subcat-hom.hom .hom = f to-scott-directed f pres .Subcat-hom.hom .pres-β€ = dcpo+scottβmonotone D.has-dcpo f pres to-scott-directed f pres .Subcat-hom.witness = pres