module Order.Directed where

Directed sets🔗

A poset is upwards directed if it is merely inhabited and every pair of elements merely has a (not necessarily least) upper bound.

record is-upwards-directed {o ℓ} (P : Poset o ℓ) : Type (o ⊔ ℓ) where
  no-eta-equality
  open Poset P
  field
    inhabited : ∥ Ob ∥
    upper-bound : ∀ x y → ∃[ z ∈ Ob ] (x ≤ z × y ≤ z)

If is upwards directed, then there merely exists an upper bound of every finite subset of

  fin-upper-bound
    : ∀ {n}
    → (xᵢ : Fin n → Ob)
    → ∃[ y ∈ Ob ] (∀ ix → xᵢ ix ≤ y)
  fin-upper-bound {zero} xᵢ = do
    y ← inhabited
    inc (y , (λ ()))
  fin-upper-bound {suc n} xᵢ = do
    (y , xᵢ≤y) ← fin-upper-bound (xᵢ ⊙ fsuc)
    (ub , x₀≤ub , y≤ub) ← upper-bound (xᵢ 0) y
    pure (ub , fin-cons x₀≤ub λ ix → ≤-trans (xᵢ≤y ix) y≤ub)

Every join semilattice is upwards directed.

is-join-slat→is-upwards-directed
  : ∀ {o ℓ} {L : Poset o ℓ}
  → is-join-semilattice L
  → is-upwards-directed L
{-# INLINE is-join-slat→is-upwards-directed #-}
is-join-slat→is-upwards-directed {L = L} L-slat = record
  { inhabited = inc bot
  ; upper-bound = λ x y → inc (x ∪ y , l≤∪ , r≤∪)
  }
  where
    open Poset L
    open is-join-semilattice L-slat

Dually, a poset is downwards directed if it is merely inhabited and every pair of elements merely has a (not necessarily least) lower bound.

record is-downwards-directed {o ℓ} (P : Poset o ℓ) : Type (o ⊔ ℓ) where
  no-eta-equality
  open Poset P
  field
    inhabited : ∥ Ob ∥
    lower-bound : ∀ x y → ∃[ z ∈ Ob ] (z ≤ x × z ≤ y)

If is downward directed, then every finite subset has a (not necessarily greatest) lower bound.

  fin-lower-bound
    : ∀ {n}
    → (xᵢ : Fin n → Ob)
    → ∃[ y ∈ Ob ] (∀ ix → y ≤ xᵢ ix)
The proof is formally dual to the upwards directed case, so we omit it.
  fin-lower-bound {zero} xᵢ = do
    y ← inhabited
    inc (y , (λ ()))
  fin-lower-bound {suc n} xᵢ = do
    (y , y≤xᵢ) ← fin-lower-bound (xᵢ ⊙ fsuc)
    (lb , lb≤x₀ , lb≤y) ← lower-bound (xᵢ 0) y
    pure (lb , fin-cons lb≤x₀ λ ix → ≤-trans lb≤y (y≤xᵢ ix))

Every meet semilattice is downwards directed.

is-meet-slat→is-downwards-directed
  : ∀ {o ℓ} {L : Poset o ℓ}
  → is-meet-semilattice L
  → is-downwards-directed L
{-# INLINE is-meet-slat→is-downwards-directed #-}
is-meet-slat→is-downwards-directed {L = L} L-slat = record
  { inhabited = inc top
  ; lower-bound = λ x y → inc (x ∩ y , ∩≤l , ∩≤r)
  }
  where
    open Poset L
    open is-meet-semilattice L-slat