module Order.DCPO.Free where
private variable
: Level
o o' ℓ : Type ℓ
A B C
open is-directed-family
open Lub
open Functor
open _=>_
open _⊣_
Free DCPOs🔗
The discrete poset on a set is a DCPO. To see this, note that every semi-directed family in a discrete poset is constant. Furthermore, is directed, so it is merely inhabited.
: ∀ {ℓ} {A : Set ℓ} → is-dcpo (Disc A)
Disc-is-dcpo {A = A} .is-dcpo.directed-lubs {Ix = Ix} f dir =
Disc-is-dcpo (dir .elt)
const-inhabited-fam→lub disc-fam-const where
: ∀ i j → f i ≡ f j
disc-fam-const = case dir .semidirected i j of λ k p q → p ∙ sym q
disc-fam-const i j
: (A : Set ℓ) → DCPO ℓ ℓ
Disc-dcpo = Disc A , Disc-is-dcpo Disc-dcpo A
This extends to a functor from to the category of DCPOs.
: ∀ {ℓ} → Functor (Sets ℓ) (DCPOs ℓ ℓ)
Free-DCPO .F₀ = Disc-dcpo
Free-DCPO .F₁ f =
Free-DCPO λ s dir x x-lub →
to-scott-directed f
const-inhabited-fam→is-lub(λ ix → ap f (disc-is-lub→const x-lub ix))
(dir .elt)
.F-id = trivial!
Free-DCPO .F-∘ _ _ = trivial! Free-DCPO
Furthermore, this functor is left adjoint to the forgetful functor to
: ∀ {ℓ} → Free-DCPO {ℓ} ⊣ DCPOs↪Sets
Free-DCPO⊣Forget-DCPO .unit .η _ x = x
Free-DCPO⊣Forget-DCPO .unit .is-natural _ _ _ = refl
Free-DCPO⊣Forget-DCPO .counit .η D =
Free-DCPO⊣Forget-DCPO (λ x → x) λ s dir x x-lub → λ where
to-scott-directed .is-lub.fam≤lub i → ≤-refl' (disc-is-lub→const x-lub i)
.is-lub.least y le →
∥-∥-rec ≤-thin(λ i →
x =˘⟨ disc-is-lub→const x-lub i ⟩
s i ≤⟨ le i ⟩)
y ≤∎(dir .elt)
where open DCPO D
.counit .is-natural x y f = trivial!
Free-DCPO⊣Forget-DCPO .zig = trivial!
Free-DCPO⊣Forget-DCPO .zag = refl Free-DCPO⊣Forget-DCPO
Free pointed DCPOs🔗
The purpose of this section is to establish that the free pointed DCPO on a set is given by its partial elements We have already constructed the order we will use, the information ordering, and established some of its basic order-theoretic properties, so that we immediately get a poset of partial elements:
: (A : Set ℓ) → Poset ℓ ℓ
Parts .Poset.Ob = ↯ ∣ A ∣
Parts A .Poset._≤_ = _⊑_
Parts A .Poset.≤-thin = hlevel 1
Parts A .Poset.≤-refl = ⊑-refl
Parts A .Poset.≤-trans = ⊑-trans
Parts A .Poset.≤-antisym = ⊑-antisym Parts A
Unfortunately, the hardest two parts of the construction remain:
We must show that has least upper bounds for all semidirected families, i.e., that it is actually a DCPO;
We must show that this construction is actually free, meaning that every map to a pointed DCPO extends uniquely to a strictly Scott-continuous
We will proceed in this order.
Directed joins of partial elements🔗
⊑-lub: {Ix : Type ℓ} ⦃ _ : H-Level A 2 ⦄ (s : Ix → ↯ A)
→ (semi : ∀ i j → ∃[ k ∈ Ix ] (s i ⊑ s k × s j ⊑ s k))
→ ↯ A
Suppose that is a semidirected family of partial elements — which, recall, means that for each we can merely find satisfying and We decree that the join is defined whenever there exists such that is defined.
{Ix = Ix} s dir .def = elΩ (Σ[ i ∈ Ix ] ⌞ s i ⌟) ⊑-lub
Next, we need to construct an element of under the assumption that there exists such an The obvious move is to use the value itself. However, we only merely have such an and we’re not mapping into a proposition — we’re mapping into a set. But that’s not a major impediment: we’re allowed to make this choice, as long as we show that the function is constant.
{Ix = Ix} s dir .elt =
⊑-lub (hlevel 2) (λ (ix , def) → s ix .elt def) (λ p q i →
□-rec-set .elt $
is-const p q i (λ i → is-const p q i .def .is-tr) (p .snd) (q .snd) i)
is-prop→pathp where abstract
So imagine that we have two indices with and both defined. We must show that Since is semidirected, and we’re showing a proposition, we may assume that there is some satisfying and We then compute:
is-const: ∀ (p q : Σ[ i ∈ Ix ] ⌞ s i ⌟)
→ s (p .fst) ≡ s (q .fst)
(i , si) (j , sj) = ∥-∥-out! do
is-const (k , p , q) ← dir i j
(λ _ → sj) (λ _ → si) λ si sj →
pure $ part-ext .elt _ ≡˘⟨ p .refines si ⟩
s i .elt _ ≡⟨ ↯-indep (s k) ⟩
s k .elt _ ≡⟨ q .refines sj ⟩
s k .elt _ ∎ s j
After having constructed the element, we’re still left with proving that this is actually a least upper bound. This turns out to be pretty straightforward, so we present the solution without further comments:
module
_ {Ix : Type ℓ} ⦃ set : H-Level A 2 ⦄ {s : Ix → ↯ A}
{dir : ∀ i j → ∃[ k ∈ Ix ] (s i ⊑ s k × s j ⊑ s k)}
where
: ∀ i → s i ⊑ ⊑-lub s dir
⊑-lub-le .implies si = inc (i , si)
⊑-lub-le i .refines si = refl
⊑-lub-le i
⊑-lub-least: ∀ x → (∀ i → s i ⊑ x) → ⊑-lub s dir ⊑ x
.implies = rec! λ i si → le i .implies si
⊑-lub-least x le .refines = elim! λ i si → le i .refines si ⊑-lub-least x le
open is-dcpo
open is-lub
open Bottom
open Lub
: ∀ {A : Set ℓ} → is-dcpo (Parts A)
Parts-is-dcpo {A = A} .directed-lubs s dir .lub =
Parts-is-dcpo (dir .semidirected)
⊑-lub s {A = A} .directed-lubs s dir .has-lub .fam≤lub = ⊑-lub-le
Parts-is-dcpo {A = A} .directed-lubs s dir .has-lub .least = ⊑-lub-least
Parts-is-dcpo
: (A : Set ℓ) → DCPO ℓ ℓ
Parts-dcpo = Parts A , Parts-is-dcpo Parts-dcpo A
Furthermore, it’s a pointed DCPO, since we additionally have a bottom element.
: ∀ {A : Set ℓ} → is-pointed-dcpo (Parts-dcpo A)
Parts-is-pointed-dcpo .bot = never
Parts-is-pointed-dcpo .has-bottom _ = never-⊑
Parts-is-pointed-dcpo
: ∀ (A : Set ℓ) → Pointed-dcpo ℓ ℓ
Parts-pointed-dcpo = Parts-dcpo A , Parts-is-pointed-dcpo Parts-pointed-dcpo A
Finally, we note that the functorial action of the partiality monad preserves these directed joins. Since it’s valued in strict Scott-continuous maps, this action extends to a proper functor from the category to the category of pointed dcpos.
part-map-lub: {Ix : Type ℓ} {A : Set o} {B : Set o'} {s : Ix → ↯ ∣ A ∣}
→ {dir : ∀ i j → ∃[ k ∈ Ix ] (s i ⊑ s k × s j ⊑ s k)}
→ (f : ∣ A ∣ → ∣ B ∣)
→ is-lub (Parts B) (part-map f ⊙ s) (part-map f (⊑-lub s dir))
.fam≤lub i = part-map-⊑ (⊑-lub-le i)
part-map-lub f .least y le .implies = rec! λ i si → le i .implies si
part-map-lub f {B = B} f .least y le .refines = elim! λ i si → le i .refines si
part-map-lub
: Functor (Sets ℓ) (Pointed-DCPOs ℓ ℓ)
Free-Pointed-dcpo .F₀ A = Parts-pointed-dcpo A
Free-Pointed-dcpo .F₁ {x = A} f = to-strict-scott-bottom
Free-Pointed-dcpo (part-map f) (part-map-⊑)
(λ _ _ → part-map-lub {A = A} f)
(λ _ → part-map-never)
.F-id = ext (part-map-id $_)
Free-Pointed-dcpo .F-∘ f g = ext (part-map-∘ f g $_) Free-Pointed-dcpo
module _ (D : Pointed-dcpo o ℓ) where
open Pointed-dcpo D
The universal property🔗
It remains to show that this functor is actually a left
adjoint. We have already constructed the adjunction unit: it is the
map always
which embeds
into
We turn to defining the counit. Since every pointed dcpo admits joins
indexed by propositions, given a
we can define
to be the join
: ↯ Ob → Ob
part-counit = ⋃-prop (x .elt ⊙ lower) def-prop where abstract
part-counit x : is-prop (Lift o ⌞ x ⌟)
def-prop = hlevel 1 def-prop
We can characterise the behaviour of this definition as though it were defined by cases: if is defined, then this simply yields its value. And if is undefined, then this is the bottom element.
: (x : ↯ Ob) (p : ⌞ x ⌟) → part-counit x ≡ x .elt p
part-counit-elt = ≤-antisym
part-counit-elt x p (⋃-prop-least _ _ _ λ (lift p') → ≤-refl' (↯-indep x))
(⋃-prop-le _ _ (lift p))
: (x : ↯ Ob) → (⌞ x ⌟ → ⊥) → part-counit x ≡ bottom
part-counit-¬elt = ≤-antisym
part-counit-¬elt x ¬def (⋃-prop-least _ _ _ (λ p → absurd (¬def (lower p))))
(bottom≤x _)
The following three properties are fundamental: the counit
- preserves the information order; and
- preserves directed joins; and
- preserves the bottom element.
: ∀ {x y} → x ⊑ y → part-counit x ≤ part-counit y
part-counit-⊑
part-counit-lub: ∀ {Ix} s (sdir : is-semidirected-family (Parts set) {Ix} s)
→ is-lub poset (part-counit ⊙ s) (part-counit (⊑-lub s sdir))
: ∀ x → part-counit never ≤ x part-counit-never
The proofs here are simply calculations. We leave them for the curious reader.
{x = x} {y = y} p = ⋃-prop-least _ _ (part-counit y) λ (lift i) →
part-counit-⊑ .elt i =˘⟨ p .refines i ⟩
x .elt (p .implies i) ≤⟨ ⋃-prop-le _ _ (lift (p .implies i)) ⟩
y (y .elt ⊙ lower) _ ≤∎
⋃-prop
.is-lub.fam≤lub i =
part-counit-lub s sdir _ _ _ λ (lift p) →
⋃-prop-least _ _ (lift (inc (i , p)))
⋃-prop-le {Ix = Ix} s sdir .is-lub.least y le = ⋃-prop-least _ _ _ $
part-counit-lub λ (lift p) → □-elim (λ p → ≤-thin {x = ⊑-lub s sdir .elt p}) (λ (i , si) →
.elt si ≤⟨ ⋃-prop-le _ _ (lift si) ⟩
s i _ _ ≤⟨ le i ⟩
⋃-prop ) p
y ≤∎
= ⋃-prop-least _ _ x (λ ()) part-counit-never x
We can tie this all together to obtain the desired adjunction.
Free-Pointed-dcpo⊣Forget-Pointed-dcpo: ∀ {ℓ} → Free-Pointed-dcpo {ℓ} ⊣ Pointed-DCPOs↪Sets
.unit .η A x = always x
Free-Pointed-dcpo⊣Forget-Pointed-dcpo .unit .is-natural x y f = ext λ _ →
Free-Pointed-dcpo⊣Forget-Pointed-dcpo (always-natural f)
sym
.counit .η D = to-strict-scott-bottom
Free-Pointed-dcpo⊣Forget-Pointed-dcpo (part-counit D)
(part-counit-⊑ D)
(λ s dir → part-counit-lub D s (dir .semidirected))
(part-counit-never D)
.counit .is-natural D E f = ext λ x →
Free-Pointed-dcpo⊣Forget-Pointed-dcpo .pres-⋃-prop f _ _ _
sym $ Strict-scott
.zig {A} = ext λ x → part-ext
Free-Pointed-dcpo⊣Forget-Pointed-dcpo (A?.⋃-prop-least _ _ x (λ p → always-⊒ (lower p , refl)) .implies)
(λ p → A?.⋃-prop-le _ _ (lift p) .implies tt)
(λ p q →
(A?.⋃-prop-least _ _ x (λ p → always-⊒ (lower p , refl)) .refines p)
sym )
∙ ↯-indep xwhere module A? = Pointed-dcpo (Parts-pointed-dcpo A)
.zag {B} = ext λ x →
Free-Pointed-dcpo⊣Forget-Pointed-dcpo (λ _ _ → refl) (B.⋃-prop-lub _ _ ) (lift tt)
sym $ lub-of-const-fam where module B = Pointed-dcpo B