Tom de Jong, January 2020.
December 2021: Added material on semidirected and subsingleton suprema.
June 2022: Refactored and moved some material around to/from other files.
A collection of various useful definitions and facts on directed complete posets
and Scott continuous maps between them.
Table of contents
 * Lemmas for establishing Scott continuity of maps between dcpos.
 * Continuity of basic functions (constant functions, identity, composition).
 * Definitions of isomorphisms of dcpos, continuous retracts and
   embedding-projection pairs.
 * Defining local smallness for dcpos and showing it is preserved by continuous
   retracts.
 * Lemmas involving (joins of) cofinal directed families.
 * Reindexing directed families.
 * Suprema of ฯ-chains (added 23 June 2024).
 * Subdcpo induced by a subset/property (added 18th Feb 2024 by Martin Escardo).
\begin{code}
{-# OPTIONS --safe --without-K #-}
open import MLTT.Spartan
open import UF.FunExt
open import UF.PropTrunc
module DomainTheory.Basics.Miscelanea
        (pt : propositional-truncations-exist)
        (fe : Fun-Ext)
        (๐ฅ : Universe)
       where
private
 fe' : FunExt
 fe' _ _ = fe
open PropositionalTruncation pt
open import UF.Base
open import UF.Equiv
open import UF.Equiv-FunExt
open import UF.EquivalenceExamples
open import UF.Size hiding (is-small ; is-locally-small)
open import UF.Subsingletons
open import UF.Subsingletons-FunExt
open import UF.UniverseEmbedding
open import DomainTheory.Basics.Dcpo pt fe ๐ฅ
\end{code}
Some preliminary basic lemmas.
\begin{code}
โ-is-monotone : (๐ : DCPO {๐ค} {๐ฃ}) {I : ๐ฅ ฬ } {ฮฑ ฮฒ : I โ โจ ๐ โฉ}
                (ฮด : is-Directed ๐ ฮฑ) (ฮต : is-Directed ๐ ฮฒ)
              โ ((i : I) โ ฮฑ i โโจ ๐ โฉ ฮฒ i)
              โ โ ๐ ฮด โโจ ๐ โฉ โ ๐ ฮต
โ-is-monotone ๐ {I} {ฮฑ} {ฮฒ} ฮด ฮต l = โ-is-lowerbound-of-upperbounds ๐ ฮด (โ ๐ ฮต) ฮณ
 where
  ฮณ : (i : I) โ ฮฑ i โโจ ๐ โฉ โ ๐ ฮต
  ฮณ i = ฮฑ i   โโจ ๐ โฉ[ l i ]
        ฮฒ i   โโจ ๐ โฉ[ โ-is-upperbound ๐ ฮต i ]
        โ ๐ ฮต โโจ ๐ โฉ
โ-independent-of-directedness-witness : (๐ : DCPO {๐ค} {๐ฃ})
                                        {I : ๐ฅ ฬ } {ฮฑ : I โ โจ ๐ โฉ}
                                        (ฮด ฮต : is-Directed ๐ ฮฑ)
                                      โ โ ๐ ฮด ๏ผ โ ๐ ฮต
โ-independent-of-directedness-witness ๐ {I} {ฮฑ} ฮด ฮต = ap (โ ๐) p
 where
  p : ฮด ๏ผ ฮต
  p = being-directed-is-prop (underlying-order ๐) ฮฑ ฮด ฮต
โ-family-๏ผ : (๐ : DCPO {๐ค} {๐ฃ}) {I : ๐ฅ ฬ } {ฮฑ ฮฒ : I โ โจ ๐ โฉ}
             (p : ฮฑ ๏ผ ฮฒ) (ฮด : is-Directed ๐ ฮฑ)
           โ โ ๐ {I} {ฮฑ} ฮด ๏ผ โ ๐ {I} {ฮฒ} (transport (is-Directed ๐) p ฮด)
โ-family-๏ผ ๐ {I} {ฮฑ} {ฮฑ} refl ฮด = refl
โ-family-๏ผ' : (๐ : DCPO {๐ค} {๐ฃ}) {I : ๐ฅ ฬ } {ฮฑ ฮฒ : I โ โจ ๐ โฉ}
              (h : ฮฑ โผ ฮฒ) (ฮด : is-Directed ๐ ฮฑ) (ฮต : is-Directed ๐ ฮฒ)
            โ โ ๐ {I} {ฮฑ} ฮด ๏ผ โ ๐ {I} {ฮฒ} ฮต
โ-family-๏ผ' ๐ {I} {ฮฑ} {ฮฒ} h ฮด ฮต =
 โ-family-๏ผ ๐ (dfunext fe h) ฮด โ โ-independent-of-directedness-witness ๐ _ ฮต
to-continuous-function-๏ผ : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                           {f g : DCPO[ ๐ , ๐ ]}
                         โ [ ๐ , ๐ ]โจ f โฉ โผ [ ๐ , ๐ ]โจ g โฉ
                         โ f ๏ผ g
to-continuous-function-๏ผ ๐ ๐ h =
 to-subtype-๏ผ (being-continuous-is-prop ๐ ๐) (dfunext fe h)
๏ผ-to-โ : (๐ : DCPO {๐ค} {๐ฃ}) {x y : โจ ๐ โฉ} โ x ๏ผ y โ x โโจ ๐ โฉ y
๏ผ-to-โ ๐ {x} {x} refl = reflexivity ๐ x
๏ผ-to-โ : (๐ : DCPO {๐ค} {๐ฃ}) {x y : โจ ๐ โฉ} โ y ๏ผ x โ x โโจ ๐ โฉ y
๏ผ-to-โ ๐ p = ๏ผ-to-โ ๐ (p โปยน)
is-monotone : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
            โ (โจ ๐ โฉ โ โจ ๐ โฉ) โ ๐ค โ ๐ฃ โ ๐ฃ' ฬ
is-monotone ๐ ๐ f = (x y : โจ ๐ โฉ) โ x โโจ ๐ โฉ y โ f x โโจ ๐ โฉ f y
is-inflationary : (๐ : DCPO {๐ค} {๐ฃ})
                โ (โจ ๐ โฉ โ โจ ๐ โฉ) โ ๐ค โ ๐ฃ ฬ
is-inflationary ๐ f = (x : โจ ๐ โฉ) โ x โโจ ๐ โฉ f x
\end{code}
Lemmas for establishing Scott continuity of maps between dcpos.
\begin{code}
image-is-directed : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                    {f : โจ ๐ โฉ โ โจ ๐ โฉ}
                  โ is-monotone ๐ ๐ f
                  โ {I : ๐ฅ ฬ }
                  โ {ฮฑ : I โ โจ ๐ โฉ}
                  โ is-Directed ๐ ฮฑ
                  โ is-Directed ๐ (f โ ฮฑ)
image-is-directed ๐ ๐ {f} m {I} {ฮฑ} ฮด =
 inhabited-if-Directed ๐ ฮฑ ฮด , ฮณ
  where
   ฮณ : is-semidirected (underlying-order ๐) (f โ ฮฑ)
   ฮณ i j = โฅโฅ-functor (ฮป (k , u , v) โ k , m (ฮฑ i) (ฮฑ k) u , m (ฮฑ j) (ฮฑ k) v)
                      (semidirected-if-Directed ๐ ฮฑ ฮด i j)
continuity-criterion : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                       (f : โจ ๐ โฉ โ โจ ๐ โฉ)
                     โ (m : is-monotone ๐ ๐ f)
                     โ ((I : ๐ฅ ฬ )
                        (ฮฑ : I โ โจ ๐ โฉ)
                        (ฮด : is-Directed ๐ ฮฑ)
                     โ f (โ ๐ ฮด) โโจ ๐ โฉ โ ๐ (image-is-directed ๐ ๐ m ฮด))
                     โ is-continuous ๐ ๐ f
continuity-criterion ๐ ๐ f m e I ฮฑ ฮด = ub , lb-of-ubs
 where
  ub : (i : I) โ f (ฮฑ i) โโจ ๐ โฉ f (โ ๐ ฮด)
  ub i = m (ฮฑ i) (โ ๐ ฮด) (โ-is-upperbound ๐ ฮด i)
  ฮต : is-Directed ๐ (f โ ฮฑ)
  ฮต = image-is-directed ๐ ๐ m ฮด
  lb-of-ubs : is-lowerbound-of-upperbounds (underlying-order ๐)
              (f (โ ๐ ฮด)) (f โ ฮฑ)
  lb-of-ubs y u = f (โ ๐ ฮด) โโจ ๐ โฉ[ e I ฮฑ ฮด  ]
                  โ ๐ ฮต     โโจ ๐ โฉ[ โ-is-lowerbound-of-upperbounds ๐ ฮต y u ]
                  y         โโจ ๐ โฉ
continuity-criterion' : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                        (f : โจ ๐ โฉ โ โจ ๐ โฉ)
                      โ (m : is-monotone ๐ ๐ f)
                      โ ((I : ๐ฅ ฬ )
                         (ฮฑ : I โ โจ ๐ โฉ)
                         (ฮด : is-Directed ๐ ฮฑ)
                      โ is-lowerbound-of-upperbounds (underlying-order ๐)
                                                     (f (โ ๐ ฮด)) (f โ ฮฑ))
                      โ is-continuous ๐ ๐ f
continuity-criterion' ๐ ๐ f m lb I ฮฑ ฮด = ub , lb I ฮฑ ฮด
 where
  ub : (i : I) โ f (ฮฑ i) โโจ ๐ โฉ f (โ ๐ ฮด)
  ub i = m (ฮฑ i) (โ ๐ ฮด) (โ-is-upperbound ๐ ฮด i)
monotone-if-continuous : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                         (f : DCPO[ ๐ , ๐ ])
                       โ is-monotone ๐ ๐ [ ๐ , ๐ ]โจ f โฉ
monotone-if-continuous ๐ ๐ (f , cts) x y l = ฮณ
  where
   ฮฑ : ๐ {๐ฅ} + ๐ {๐ฅ} โ โจ ๐ โฉ
   ฮฑ (inl *) = x
   ฮฑ (inr *) = y
   ฮด : is-Directed ๐ ฮฑ
   ฮด = (โฃ inl โ โฃ , ฮต)
    where
     ฮต : (i j : ๐ + ๐) โ โ k ๊ ๐ + ๐ , ฮฑ i โโจ ๐ โฉ ฮฑ k ร ฮฑ j โโจ ๐ โฉ ฮฑ k
     ฮต (inl โ) (inl โ) = โฃ inr โ , l , l โฃ
     ฮต (inl โ) (inr โ) = โฃ inr โ , l , reflexivity ๐ y โฃ
     ฮต (inr โ) (inl โ) = โฃ inr โ , reflexivity ๐ y , l โฃ
     ฮต (inr โ) (inr โ) = โฃ inr โ , reflexivity ๐ y , reflexivity ๐ y โฃ
   a : y ๏ผ โ ๐ ฮด
   a = antisymmetry ๐ y (โ ๐ ฮด)
           (โ-is-upperbound ๐ ฮด (inr โ))
           (โ-is-lowerbound-of-upperbounds ๐ ฮด y h)
    where
     h : (i : ๐ + ๐) โ ฮฑ i โโจ ๐ โฉ y
     h (inl โ) = l
     h (inr โ) = reflexivity ๐ y
   b : is-sup (underlying-order ๐) (f y) (f โ ฮฑ)
   b = transport (ฮป - โ is-sup (underlying-order ๐) - (f โ ฮฑ)) (ap f (a โปยน))
       (cts (๐ + ๐) ฮฑ ฮด)
   ฮณ : f x โโจ ๐ โฉ f y
   ฮณ = sup-is-upperbound (underlying-order ๐) b (inl โ)
image-is-directed' : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                     (f : DCPO[ ๐ , ๐ ]) {I : ๐ฅ ฬ } {ฮฑ : I โ โจ ๐ โฉ}
                   โ is-Directed ๐ ฮฑ
                   โ is-Directed ๐ ([ ๐ , ๐ ]โจ f โฉ โ ฮฑ)
image-is-directed' ๐ ๐ f {I} {ฮฑ} ฮด = image-is-directed ๐ ๐ m ฮด
 where
  m : is-monotone ๐ ๐ [ ๐ , ๐ ]โจ f โฉ
  m = monotone-if-continuous ๐ ๐ f
continuous-โ-โ : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                 (f : DCPO[ ๐ , ๐ ]) {I : ๐ฅ ฬ } {ฮฑ : I โ โจ ๐ โฉ}
                 (ฮด : is-Directed ๐ ฮฑ)
               โ [ ๐ , ๐ ]โจ f โฉ (โ ๐ ฮด) โโจ ๐ โฉ โ ๐ (image-is-directed' ๐ ๐ f ฮด)
continuous-โ-โ ๐ ๐ (f , c) {I} {ฮฑ} ฮด =
 sup-is-lowerbound-of-upperbounds (underlying-order ๐) (c I ฮฑ ฮด) (โ ๐ ฮต) u
  where
   ฮต : is-Directed ๐ (f โ ฮฑ)
   ฮต = image-is-directed' ๐ ๐ (f , c) ฮด
   u : is-upperbound (underlying-order ๐) (โ ๐ ฮต) (f โ ฮฑ)
   u = โ-is-upperbound ๐ ฮต
continuous-โ-โ : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                 (f : DCPO[ ๐ , ๐ ]) {I : ๐ฅ ฬ } {ฮฑ : I โ โจ ๐ โฉ}
                 (ฮด : is-Directed ๐ ฮฑ)
               โ โ ๐ (image-is-directed' ๐ ๐ f ฮด) โโจ ๐ โฉ [ ๐ , ๐ ]โจ f โฉ (โ ๐ ฮด)
continuous-โ-โ ๐ ๐ (f , c) {I} {ฮฑ} ฮด =
 โ-is-lowerbound-of-upperbounds ๐ ฮต (f (โ ๐ ฮด)) u
  where
   ฮต : is-Directed ๐ (f โ ฮฑ)
   ฮต = image-is-directed' ๐ ๐ (f , c) ฮด
   u : (i : I) โ f (ฮฑ i) โโจ ๐ โฉ f (โ ๐ ฮด)
   u i = sup-is-upperbound (underlying-order ๐) (c I ฮฑ ฮด) i
continuous-โ-๏ผ : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                 (f : DCPO[ ๐ , ๐ ]) {I : ๐ฅ ฬ } {ฮฑ : I โ โจ ๐ โฉ}
                 (ฮด : is-Directed ๐ ฮฑ)
               โ [ ๐ , ๐ ]โจ f โฉ (โ ๐ ฮด) ๏ผ โ ๐ (image-is-directed' ๐ ๐ f ฮด)
continuous-โ-๏ผ ๐ ๐ (f , c) {I} {ฮฑ} ฮด =
 antisymmetry ๐ (f (โ ๐ ฮด)) (โ ๐ ฮต) a b
  where
   ฮต : is-Directed ๐ (f โ ฮฑ)
   ฮต = image-is-directed' ๐ ๐ (f , c) ฮด
   a : f (โ ๐ ฮด) โโจ ๐ โฉ โ ๐ ฮต
   a = continuous-โ-โ ๐ ๐ (f , c) ฮด
   b : โ ๐ ฮต โโจ ๐ โฉ f (โ ๐ ฮด)
   b = continuous-โ-โ ๐ ๐ (f , c) ฮด
\end{code}
Continuity of basic functions (constant functions, identity, composition).
\begin{code}
constant-functions-are-continuous : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                                    {e : โจ ๐ โฉ} โ is-continuous ๐ ๐ (ฮป d โ e)
constant-functions-are-continuous ๐ ๐ {e} I ฮฑ ฮด = u , v
 where
  u : (i : I) โ e โโจ ๐ โฉ e
  u i = reflexivity ๐ e
  v : (y : โจ ๐ โฉ) โ ((i : I) โ e โโจ ๐ โฉ y) โ e โโจ ๐ โฉ y
  v y l  = โฅโฅ-rec (prop-valuedness ๐ e y) l (inhabited-if-Directed ๐ ฮฑ ฮด)
id-is-monotone : (๐ : DCPO {๐ค} {๐ฃ}) โ is-monotone ๐ ๐ id
id-is-monotone ๐ x y l = l
id-is-inflationary : (๐ : DCPO {๐ค} {๐ฃ}) โ is-inflationary ๐ id
id-is-inflationary = reflexivity
id-is-continuous : (๐ : DCPO {๐ค} {๐ฃ}) โ is-continuous ๐ ๐ id
id-is-continuous ๐ = continuity-criterion ๐ ๐ id (id-is-monotone ๐) ฮณ
 where
  ฮณ : (I : ๐ฅ ฬ )(ฮฑ : I โ โจ ๐ โฉ) (ฮด : is-Directed ๐ ฮฑ)
    โ โ ๐ ฮด โโจ ๐ โฉ โ ๐ (image-is-directed ๐ ๐ (ฮป x y l โ l) ฮด)
  ฮณ I ฮฑ ฮด = ๏ผ-to-โ ๐ (โ-independent-of-directedness-witness ๐
             ฮด (image-is-directed ๐ ๐ (ฮป x y l โ l) ฮด))
โ-is-monotone : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'}) (๐' : DCPO {๐ฆ} {๐ฆ'})
                  (f : โจ ๐ โฉ โ โจ ๐ โฉ) (g : โจ ๐ โฉ โ โจ ๐' โฉ)
                โ is-monotone ๐ ๐ f
                โ is-monotone ๐ ๐' g
                โ is-monotone ๐ ๐' (g โ f)
โ-is-monotone ๐ ๐ ๐' f g mf mg x y l = mg (f x) (f y) (mf x y l)
โ-is-inflationary : (๐ : DCPO {๐ค} {๐ฃ})
                  (f g : โจ ๐ โฉ โ โจ ๐ โฉ)
                โ is-inflationary ๐ f
                โ is-inflationary ๐ g
                โ is-inflationary ๐ (g โ f)
โ-is-inflationary ๐ f g if ig x = transitivity ๐ x (f x) (g (f x)) (if x) (ig (f x))
โ-is-continuous : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'}) (๐' : DCPO {๐ฆ} {๐ฆ'})
                  (f : โจ ๐ โฉ โ โจ ๐ โฉ) (g : โจ ๐ โฉ โ โจ ๐' โฉ)
                โ is-continuous ๐ ๐ f
                โ is-continuous ๐ ๐' g
                โ is-continuous ๐ ๐' (g โ f)
โ-is-continuous ๐ ๐ ๐' f g cf cg = continuity-criterion ๐ ๐' (g โ f) m ฯ
 where
  mf : is-monotone ๐ ๐ f
  mf = monotone-if-continuous ๐ ๐ (f , cf)
  mg : is-monotone ๐ ๐' g
  mg = monotone-if-continuous ๐ ๐' (g , cg)
  m : is-monotone ๐ ๐' (g โ f)
  m = โ-is-monotone ๐ ๐ ๐' f g mf mg
  ฯ : (I : ๐ฅ ฬ )(ฮฑ : I โ โจ ๐ โฉ) (ฮด : is-Directed ๐ ฮฑ)
    โ g (f (โ ๐ ฮด)) โโจ ๐' โฉ โ ๐' (image-is-directed ๐ ๐' m ฮด)
  ฯ I ฮฑ ฮด = g (f (โ ๐ ฮด)) โโจ ๐' โฉ[ lโ ]
            g (โ ๐ ฮตf)    โโจ ๐' โฉ[ lโ ]
            โ ๐' ฮตg       โโจ ๐' โฉ[ lโ ]
            โ ๐' ฮต        โโจ ๐' โฉ
   where
    ฮต : is-Directed ๐' (g โ f โ ฮฑ)
    ฮต = image-is-directed ๐ ๐' m ฮด
    ฮตf : is-Directed ๐ (f โ ฮฑ)
    ฮตf = image-is-directed' ๐ ๐ (f , cf) ฮด
    ฮตg : is-Directed ๐' (g โ f โ ฮฑ)
    ฮตg = image-is-directed' ๐ ๐' (g , cg) ฮตf
    lโ = mg (f (โ ๐ ฮด)) (โ ๐ ฮตf) h
     where
      h : f (โ ๐ ฮด) โโจ ๐ โฉ โ ๐ ฮตf
      h = continuous-โ-โ ๐ ๐ (f , cf) ฮด
    lโ = continuous-โ-โ ๐ ๐' (g , cg) ฮตf
    lโ = ๏ผ-to-โ ๐' (โ-independent-of-directedness-witness ๐' ฮตg ฮต)
โ-is-continuousโ : {๐ฆโ ๐ฃโ ๐ฆโ ๐ฃโ ๐ฆโ ๐ฃโ ๐ฆโ ๐ฃโ : Universe}
                   (๐โ : DCPO {๐ฆโ} {๐ฃโ}) (๐โ : DCPO {๐ฆโ} {๐ฃโ})
                   (๐โ : DCPO {๐ฆโ} {๐ฃโ}) (๐โ : DCPO {๐ฆโ} {๐ฃโ})
                   (f : โจ ๐โ โฉ โ โจ ๐โ โฉ) (g : โจ ๐โ โฉ โ โจ ๐โ โฉ)
                   (h : โจ ๐โ โฉ โ โจ ๐โ โฉ)
                 โ is-continuous ๐โ ๐โ f
                 โ is-continuous ๐โ ๐โ g
                 โ is-continuous ๐โ ๐โ h
                 โ is-continuous ๐โ ๐โ (h โ g โ f)
โ-is-continuousโ ๐โ ๐โ ๐โ ๐โ f g h cf cg ch =
 โ-is-continuous ๐โ ๐โ ๐โ f (h โ g) cf
                 (โ-is-continuous ๐โ ๐โ ๐โ g h cg ch)
DCPO-โ : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'}) (๐' : DCPO {๐ฆ} {๐ฆ'})
       โ DCPO[ ๐ , ๐ ] โ DCPO[ ๐ , ๐' ] โ DCPO[ ๐ , ๐' ]
DCPO-โ ๐ ๐ ๐' (f , cf) (g , cg) = (g โ f) , (โ-is-continuous ๐ ๐ ๐' f g cf cg)
DCPO-โโ : {๐ฆโ ๐ฃโ ๐ฆโ ๐ฃโ ๐ฆโ ๐ฃโ ๐ฆโ ๐ฃโ : Universe}
          (๐โ : DCPO {๐ฆโ} {๐ฃโ}) (๐โ : DCPO {๐ฆโ} {๐ฃโ})
          (๐โ : DCPO {๐ฆโ} {๐ฃโ}) (๐โ : DCPO {๐ฆโ} {๐ฃโ})
          (f : DCPO[ ๐โ , ๐โ ]) (g : DCPO[ ๐โ , ๐โ ]) (h : DCPO[ ๐โ , ๐โ ])
        โ DCPO[ ๐โ , ๐โ ]
DCPO-โโ ๐โ ๐โ ๐โ ๐โ f g h = DCPO-โ ๐โ ๐โ ๐โ f (DCPO-โ ๐โ ๐โ ๐โ g h)
\end{code}
Defining isomorphisms of (pointed) dcpos.
\begin{code}
_โแตแถแตแต_ : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'}) โ ๐ฅ โบ โ ๐ค โ ๐ฃ โ ๐ค' โ ๐ฃ' ฬ
๐ โแตแถแตแต ๐ = ฮฃ f ๊ (โจ ๐ โฉ โ โจ ๐ โฉ) , ฮฃ g ๊ (โจ ๐ โฉ โ โจ ๐ โฉ) ,
                ((d : โจ ๐ โฉ) โ g (f d) ๏ผ d)
              ร ((e : โจ ๐ โฉ) โ f (g e) ๏ผ e)
              ร is-continuous ๐ ๐ f
              ร is-continuous ๐ ๐ g
โแตแถแตแต-inv : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
          โ ๐ โแตแถแตแต ๐
          โ ๐ โแตแถแตแต ๐
โแตแถแตแต-inv ๐ ๐ (f , g , s , r , cf , cg) = (g , f , r , s , cg , cf)
\end{code}
Added 20-25 March 2025 by Tom de Jong, following a discussion with Martin Escardo.
For use with the structure identity principle (SIP) it's convenient to know that
the type of dcpo isomorphisms is equivalent to the type order-equivs of order
preserving and reflecting equivalences.
\begin{code}
is-order-reflecting : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                    โ (โจ ๐ โฉ โ โจ ๐ โฉ)
                    โ ๐ค โ ๐ฃ โ ๐ฃ' ฬ
is-order-reflecting ๐ ๐ f = (x x' : โจ ๐ โฉ) โ f x โโจ ๐ โฉ f x' โ x โโจ ๐ โฉ x'
is-order-equiv : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
               โ (โจ ๐ โฉ โ โจ ๐ โฉ)
               โ ๐ค โ ๐ค' โ ๐ฃ โ ๐ฃ' ฬ
is-order-equiv ๐ ๐ f = is-equiv f ร is-monotone ๐ ๐ f ร is-order-reflecting ๐ ๐ f
being-order-equiv-is-prop : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                            (f : โจ ๐ โฉ โ โจ ๐ โฉ)
                          โ is-prop (is-order-equiv ๐ ๐ f)
being-order-equiv-is-prop ๐ ๐ f =
 รโ-is-prop (being-equiv-is-prop fe' f)
            (ฮ โ-is-prop fe ฮป x x' _ โ prop-valuedness ๐ (f x) (f x'))
            (ฮ โ-is-prop fe ฮป x x' _ โ prop-valuedness ๐ x x')
order-equivs : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'}) โ ๐ค โ ๐ฃ โ ๐ค' โ ๐ฃ' ฬ
order-equivs ๐ ๐ = ฮฃ f ๊ (โจ ๐ โฉ โ โจ ๐ โฉ) , is-order-equiv ๐ ๐ f
\end{code}
To relate order equivalences to isomorphisms of dcpos we will need the following
three basic observations.
\begin{code}
inverse-of-order-equiv-is-order-equiv : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                                      โ (f : โจ ๐ โฉ โ โจ ๐ โฉ)
                                      โ (๐@(e , _) : is-order-equiv ๐ ๐ f)
                                      โ is-order-equiv ๐ ๐ (inverse f e)
inverse-of-order-equiv-is-order-equiv ๐ ๐ f
 (f-equiv , f-monotone , f-order-reflecting) = I , II , III
 where
  g : โจ ๐ โฉ โ โจ ๐ โฉ
  g = inverse f f-equiv
  I : is-equiv g
  I = inverses-are-equivs f f-equiv
  II : is-monotone ๐ ๐ g
  II y y' l =
   f-order-reflecting (g y) (g y')
                      (transportโ (underlying-order ๐)
                                  ((inverses-are-sections f f-equiv y) โปยน)
                                  ((inverses-are-sections f f-equiv y') โปยน)
                                  l)
  III : is-order-reflecting ๐ ๐ g
  III y y' l =
   transportโ (underlying-order ๐)
              (inverses-are-sections f f-equiv y)
              (inverses-are-sections f f-equiv y')
              (f-monotone (g y) (g y') l)
monotone-map-with-monotone-inverse-is-order-reflecting
 : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
   (f : โจ ๐ โฉ โ โจ ๐ โฉ) (e : is-equiv f)
 โ is-monotone ๐ ๐ f
 โ is-monotone ๐ ๐ (inverse f e)
 โ is-order-reflecting ๐ ๐ f
monotone-map-with-monotone-inverse-is-order-reflecting
 ๐ ๐ f e f-monotone f-inv-monotone x x' l =
  transportโ (underlying-order ๐)
             (inverses-are-retractions f e x)
             (inverses-are-retractions f e x')
             (f-inv-monotone (f x) (f x') l)
order-equivs-are-continuous : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                            โ (f : โจ ๐ โฉ โ โจ ๐ โฉ)
                            โ is-order-equiv ๐ ๐ f
                            โ is-continuous ๐ ๐ f
order-equivs-are-continuous ๐ ๐ f ๐@(f-equiv , f-monotone , f-order-reflecting) =
 continuity-criterion ๐ ๐ f f-monotone cont-condition
  where
   g : โจ ๐ โฉ โ โจ ๐ โฉ
   g = inverse f f-equiv
   g-order-reflecting : is-order-reflecting ๐ ๐ g
   g-order-reflecting = prโ (prโ (inverse-of-order-equiv-is-order-equiv ๐ ๐ f ๐))
   cont-condition : (I : ๐ฅ ฬ ) (ฮฑ : I โ โจ ๐ โฉ) (ฮด : is-Directed ๐ ฮฑ)
                  โ f (โ ๐ ฮด) โโจ ๐ โฉ โ ๐ (image-is-directed ๐ ๐ f-monotone ฮด)
   cont-condition I ฮฑ ฮด =
    g-order-reflecting (f (โ ๐ ฮด))
                       (โ ๐ ฮต)
                       (transportโปยน (ฮป - โ - โโจ ๐ โฉ g (โ ๐ ฮต))
                                    (inverses-are-retractions f f-equiv (โ ๐ ฮด))
                                    ineq)
    where
     ฮต : is-Directed ๐ (f โ ฮฑ)
     ฮต = image-is-directed ๐ ๐ f-monotone ฮด
     ineq : โ ๐ ฮด โโจ ๐ โฉ g (โ ๐ ฮต)
     ineq = โ-is-lowerbound-of-upperbounds ๐ ฮด (g (โ ๐ ฮต)) ub
      where
       ub : (i : I) โ ฮฑ i โโจ ๐ โฉ g (โ ๐ ฮต)
       ub i = f-order-reflecting (ฮฑ i) (g (โ ๐ ฮต))
               (transportโปยน (ฮป - โ f (ฮฑ i) โโจ ๐ โฉ -)
                            (inverses-are-sections f f-equiv (โ ๐ ฮต))
                            (โ-is-upperbound ๐ ฮต i))
\end{code}
We are now ready to show that the identity type between two dcpos ๐ and ๐ is
equivalent to type of isomorphisms between ๐ and ๐.
\begin{code}
open import UF.Univalence
characterization-of-DCPO-๏ผ : Univalence
                            โ (๐ ๐ : DCPO {๐ค} {๐ฃ}) โ (๐ ๏ผ ๐) โ ๐ โแตแถแตแต ๐
characterization-of-DCPO-๏ผ {๐ค} {๐ฃ} ua ๐ ๐ =
 (๐ ๏ผ ๐)                                                            โโจ I โฉ
 (ฮฃ f ๊ (โจ ๐ โฉ โ โจ ๐ โฉ)
   , is-equiv f ร ((x x' : โจ ๐ โฉ) โ x โโจ ๐ โฉ x' ๏ผ f x โโจ ๐ โฉ f x')) โโจ II โฉ
 (ฮฃ f ๊ (โจ ๐ โฉ โ โจ ๐ โฉ) , is-order-equiv ๐ ๐ f)                      โโจ III โฉ
 (ฮฃ f ๊ (โจ ๐ โฉ โ โจ ๐ โฉ) , ฮฃ e ๊ is-equiv f
                        , is-continuous ๐ ๐ f
                        ร is-continuous ๐ ๐ (inverse f e))           โโจ IV โฉ
 ๐ โแตแถแตแต ๐                                                           โ 
  where
   I = characterization-of-M-๏ผ' ua ๐ ๐
    where
     open import UF.SIP-Examples
     open generalized-metric-space
           (๐ฃ ฬ  )
           (ฮป (D : ๐ค ฬ  ) (_โ_ : D โ D โ ๐ฃ ฬ  ) โ dcpo-axioms _โ_)
           (ฮป D โ dcpo-axioms-is-prop)
   II =
    ฮฃ-cong
     (ฮป f โ logically-equivalent-props-are-equivalent
             (ร-is-prop (being-equiv-is-prop fe' f)
                        (ฮ โ-is-prop fe
                          (ฮป x x' โ identifications-with-props-are-props
                                     (univalence-gives-propext (ua ๐ฃ))
                                     fe
                                     (f x โโจ ๐ โฉ f x')
                                     (prop-valuedness ๐ (f x) (f x'))
                                     (x โโจ ๐ โฉ x'))))
             (being-order-equiv-is-prop ๐ ๐ f)
             (ฮป (e , p) โ e ,
                          (ฮป x x' โ Idtofun (p x x')) ,
                          (ฮป x x' โ Idtofunโปยน (p x x')))
             (ฮป (e , m , r) โ e ,
                              (ฮป x x' โ univalence-gives-propext
                                         (ua ๐ฃ)
                                         (prop-valuedness ๐ x x')
                                         (prop-valuedness ๐ (f x) (f x'))
                                         (m x x')
                                         (r x x'))))
   III =
    ฮฃ-cong
     (ฮป f โ logically-equivalent-props-are-equivalent
             (being-order-equiv-is-prop ๐ ๐ f)
             (ฮฃ-is-prop
               (being-equiv-is-prop fe' f)
               (ฮป e โ ร-is-prop
                       (being-continuous-is-prop ๐ ๐ f)
                       (being-continuous-is-prop ๐ ๐ (inverse f e))))
             (ฮป (e , m , r) โ e ,
                              order-equivs-are-continuous ๐ ๐ f (e , m , r) ,
                              order-equivs-are-continuous ๐ ๐
                               (inverse f e)
                               (inverse-of-order-equiv-is-order-equiv ๐ ๐ f
                                 (e , m , r)))
             (ฮป (e , f-cont , f-inv-cont) โ
               e ,
               monotone-if-continuous ๐ ๐ (f , f-cont) ,
               monotone-map-with-monotone-inverse-is-order-reflecting ๐ ๐ f e
                (monotone-if-continuous ๐ ๐ (f , f-cont))
                (monotone-if-continuous ๐ ๐ (inverse f e , f-inv-cont))))
   IV = ฮฃ-cong (ฮป f โ ฮฃ-change-of-variable _ โ ฯ f โ (โโ-is-equiv (ฯ f))
                      โ ฮฃ-change-of-variable _ โ ฮฃ-assoc โโปยน (โโโปยน-is-equiv ฮฃ-assoc)
                      โ ฮฃ-assoc
                      โ ฮฃ-assoc)
    where
     ฯ : (f : โจ ๐ โฉ โ โจ ๐ โฉ) โ is-equiv f โ qinv f
     ฯ f = is-equiv-โ-qinv fe f (sethood ๐)
\end{code}
End of addition.
We now define embedding-projection pairs.
\begin{code}
is-deflation : (๐ : DCPO {๐ค} {๐ฃ}) โ DCPO[ ๐ , ๐ ] โ ๐ค โ ๐ฃ ฬ
is-deflation ๐ f = (x : โจ ๐ โฉ) โ [ ๐ , ๐ ]โจ f โฉ x โโจ ๐ โฉ x
is-continuous-retract : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                      โ DCPO[ ๐ , ๐ ]
                      โ DCPO[ ๐ , ๐ ]
                      โ ๐ค ฬ
is-continuous-retract ๐ ๐ (ฯ , _) (ฯ , _) = (x : โจ ๐ โฉ) โ ฯ (ฯ x) ๏ผ x
is-embedding-projection-pair : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                             โ DCPO[ ๐ , ๐ ]
                             โ DCPO[ ๐ , ๐ ]
                             โ ๐ค โ ๐ค' โ ๐ฃ' ฬ
is-embedding-projection-pair ๐ ๐ ๐ค@(s , cs) ๐ฃ@(r , cr) =
   is-continuous-retract ๐ ๐ ๐ค ๐ฃ
 ร is-deflation ๐ (s โ r , โ-is-continuous ๐ ๐ ๐ r s cr cs)
record _continuous-retract-of_
        (๐ : DCPO {๐ค} {๐ฃ})
        (๐ : DCPO {๐ค'} {๐ฃ'}) : ๐ฅ โบ โ ๐ค โ ๐ฃ โ ๐ค' โ ๐ฃ' ฬ where
  field
   s : โจ ๐ โฉ โ โจ ๐ โฉ
   r : โจ ๐ โฉ โ โจ ๐ โฉ
   s-section-of-r : r โ s โผ id
   s-is-continuous : is-continuous ๐ ๐ s
   r-is-continuous : is-continuous ๐ ๐ r
  ๐ค : DCPO[ ๐ , ๐ ]
  ๐ค = s , s-is-continuous
  ๐ฃ : DCPO[ ๐ , ๐ ]
  ๐ฃ = r , r-is-continuous
โแตแถแตแต-to-continuous-retract : (๐ : DCPO {๐ค} {๐ฃ})
                              (๐ : DCPO {๐ค'} {๐ฃ'})
                            โ ๐ โแตแถแตแต ๐
                            โ ๐ continuous-retract-of ๐
โแตแถแตแต-to-continuous-retract ๐ ๐ (f , g , s , r , cf , cg) =
 record
  { s = f
  ; r = g
  ; s-section-of-r = s
  ; s-is-continuous = cf
  ; r-is-continuous = cg
 }
is-embedding-projection : (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
                        โ DCPO[ ๐ , ๐ ]
                        โ DCPO[ ๐ , ๐ ]
                        โ ๐ค โ ๐ค' โ ๐ฃ' ฬ
is-embedding-projection ๐ ๐ ฮต ฯ =
 is-continuous-retract ๐ ๐ ฮต ฯ ร is-deflation ๐ (DCPO-โ ๐ ๐ ๐ ฯ ฮต)
record embedding-projection-pair-between
        (๐ : DCPO {๐ค} {๐ฃ})
        (๐ : DCPO {๐ค'} {๐ฃ'}) : ๐ฅ โบ โ ๐ค โ ๐ฃ โ ๐ค' โ ๐ฃ' ฬ where
  field
   e : โจ ๐ โฉ โ โจ ๐ โฉ
   p : โจ ๐ โฉ โ โจ ๐ โฉ
   e-section-of-p : p โ e โผ id
   e-p-deflation : (y : โจ ๐ โฉ) โ e (p y) โโจ ๐ โฉ y
   e-is-continuous : is-continuous ๐ ๐ e
   p-is-continuous : is-continuous ๐ ๐ p
  ๐ : DCPO[ ๐ , ๐ ]
  ๐ = e , e-is-continuous
  ๐ก : DCPO[ ๐ , ๐ ]
  ๐ก = p , p-is-continuous
โแตแถแตแต-to-embedding-projection-pair : (๐ : DCPO {๐ค} {๐ฃ})
                                     (๐ : DCPO {๐ค'} {๐ฃ'})
                                   โ ๐ โแตแถแตแต ๐
                                   โ embedding-projection-pair-between ๐ ๐
โแตแถแตแต-to-embedding-projection-pair ๐ ๐ (f , g , s , r , cf , cg) =
 record
  { e = f
  ; p = g
  ; e-section-of-p = s
  ; e-p-deflation = ฮป y โ ๏ผ-to-โ ๐ (r y)
  ; e-is-continuous = cf
  ; p-is-continuous = cg
 }
\end{code}
Many examples of dcpos conveniently happen to be locally small.
We present and prove the equivalence of three definitions:
- our main one, is-locally-small, which uses a record so that we have convenient
  helper functions;
- a second one, is-locally-small-ฮฃ, which is like the above but uses a ฮฃ-type
  rather than a record;
- a third one, is-locally-small', which arguably looks more like the familiar
  categorical notion of a locally small category.
To prove their equivalence, we prove a general lemma on small-valued binary
relations.
\begin{code}
is-small : (X : ๐ค ฬ ) โ ๐ฅ โบ โ ๐ค ฬ
is-small X = X is ๐ฅ small
small-binary-relation-equivalence : {X : ๐ค ฬ } {Y : ๐ฆ ฬ } {R : X โ Y โ ๐ฃ ฬ }
                                  โ ((x : X) (y : Y) โ is-small (R x y))
                                  โ (ฮฃ Rโ ๊ (X โ Y โ ๐ฅ ฬ ) ,
                                      ((x : X) (y : Y) โ Rโ x y โ R x y))
small-binary-relation-equivalence {๐ค} {๐ฆ} {๐ฃ} {X} {Y} {R} =
 ((x : X) (y : Y)    โ is-small (R x y))                            โโจ I   โฉ
 ((((x , y) : X ร Y) โ is-small (R x y)))                           โโจ II  โฉ
 (ฮฃ R' ๊ (X ร Y โ ๐ฅ ฬ ) , (((x , y) : X ร Y) โ R' (x , y) โ R x y)) โโจ III โฉ
 (ฮฃ R' ๊ (X ร Y โ ๐ฅ ฬ ) , ((x : X) (y : Y) โ R' (x , y) โ R x y))   โโจ IV  โฉ
 (ฮฃ Rโ ๊ (X โ Y โ ๐ฅ ฬ ) , ((x : X) (y : Y) โ Rโ x y โ R x y))       โ 
  where
   ฯ : {๐ค ๐ฅ ๐ฆ : Universe}
       {X : ๐ค ฬ } {Y : X โ ๐ฅ ฬ } {Z : (ฮฃ x ๊ X , Y x) โ ๐ฆ ฬ }
     โ ฮ  Z โ (ฮ  x ๊ X , ฮ  y ๊ Y x , Z (x , y))
   ฯ = curry-uncurry fe'
   I   = โ-sym ฯ
   II  = ฮ ฮฃ-distr-โ
   III = ฮฃ-cong (ฮป R โ ฯ)
   IV  = ฮฃ-change-of-variable (ฮป R' โ (x : X) (y : Y) โ R' x y โ R x y)
          โ ฯ โ (โโ-is-equiv ฯ)
module _
        (๐ : DCPO {๐ค} {๐ฃ})
       where
 record is-locally-small : ๐ฅ โบ โ ๐ค โ ๐ฃ ฬ where
  field
   _โโ_ : โจ ๐ โฉ โ โจ ๐ โฉ โ ๐ฅ ฬ
   โโ-โ-โ : {x y : โจ ๐ โฉ} โ x โโ y โ x โโจ ๐ โฉ y
  โโ-to-โ : {x y : โจ ๐ โฉ} โ x โโ y โ x โโจ ๐ โฉ y
  โโ-to-โ = โ โโ-โ-โ โ
  โ-to-โโ : {x y : โจ ๐ โฉ} โ x โโจ ๐ โฉ y โ x โโ y
  โ-to-โโ = โ โโ-โ-โ โโปยน
  โโ-is-prop-valued : (x y : โจ ๐ โฉ) โ is-prop (x โโ y)
  โโ-is-prop-valued x y = equiv-to-prop โโ-โ-โ (prop-valuedness ๐ x y)
  transitivityโ : (x : โจ ๐ โฉ) {y z : โจ ๐ โฉ}
                โ x โโ y โ y โโ z โ x โโ z
  transitivityโ x {y} {z} u v = โ โโ-โ-โ โโปยน
                                 (transitivity ๐ x y z
                                               (โ โโ-โ-โ โ u)
                                               (โ โโ-โ-โ โ v))
  syntax transitivityโ x u v = x โโ[ u ] v
  infixr 0 transitivityโ
  reflexivityโ : (x : โจ ๐ โฉ) โ x โโ x
  reflexivityโ x = โ โโ-โ-โ โโปยน (reflexivity ๐ x)
  syntax reflexivityโ x = x โโ
  infix 1 reflexivityโ
\end{code}
This ends our helper function for the record and we proceed by giving the
alternative definitions of local smallness and proving their equivalence.
\begin{code}
 is-locally-small-ฮฃ : ๐ฅ โบ โ ๐ค โ ๐ฃ ฬ
 is-locally-small-ฮฃ =
   ฮฃ _โโ_ ๊ (โจ ๐ โฉ โ โจ ๐ โฉ โ ๐ฅ ฬ ) , ((x y : โจ ๐ โฉ) โ (x โโ y) โ (x โโจ ๐ โฉ y))
 is-locally-small-record-equivalence : is-locally-small โ is-locally-small-ฮฃ
 is-locally-small-record-equivalence = qinveq f (g , (ฮป _ โ refl) , (ฮป _ โ refl))
  where
   f : is-locally-small โ is-locally-small-ฮฃ
   f ls = _โโ_ , (ฮป x y โ โโ-โ-โ)
    where
     open is-locally-small ls
   g : is-locally-small-ฮฃ โ is-locally-small
   g ls = record { _โโ_ = prโ ls ; โโ-โ-โ = (ฮป {x} {y} โ prโ ls x y)}
 is-locally-small' : ๐ฅ โบ โ ๐ค โ ๐ฃ ฬ
 is-locally-small' = (x y : โจ ๐ โฉ) โ is-small (x โโจ ๐ โฉ y)
 local-smallness-equivalent-definitions : is-locally-small โ is-locally-small'
 local-smallness-equivalent-definitions =
  is-locally-small-record-equivalence โ โ-sym (small-binary-relation-equivalence)
 being-locally-small'-is-prop : PropExt โ is-prop is-locally-small'
 being-locally-small'-is-prop pe =
  ฮ โ-is-prop fe (ฮป x y โ prop-being-small-is-prop pe fe'
                          (x โโจ ๐ โฉ y) (prop-valuedness ๐ x y))
 being-locally-small-is-prop : PropExt โ is-prop is-locally-small
 being-locally-small-is-prop pe =
  equiv-to-prop local-smallness-equivalent-definitions
                (being-locally-small'-is-prop pe)
\end{code}
Being locally small is preserved by continuous retracts.
\begin{code}
local-smallness-preserved-by-continuous-retract :
   (๐ : DCPO {๐ค} {๐ฃ}) (๐ : DCPO {๐ค'} {๐ฃ'})
 โ ๐ continuous-retract-of ๐
 โ is-locally-small ๐
 โ is-locally-small ๐
local-smallness-preserved-by-continuous-retract ๐ ๐ ฯ ls =
 โ local-smallness-equivalent-definitions ๐ โโปยน ฮณ
  where
   open _continuous-retract-of_ ฯ
   open is-locally-small ls
   ฮณ : is-locally-small' ๐
   ฮณ x y = (s x โโ s y , g)
    where
     g : (s x โโ s y) โ (x โโจ ๐ โฉ y)
     g = logically-equivalent-props-are-equivalent
          (equiv-to-prop โโ-โ-โ
            (prop-valuedness ๐ (s x) (s y)))
          (prop-valuedness ๐ x y)
          โฆ
โโฆ โฆ
โโฆ
      where
       โฆ
โโฆ : (s x โโ s y) โ (x โโจ ๐ โฉ y)
       โฆ
โโฆ l = x      โโจ ๐ โฉ[ โฆ
1โฆ ]
              r (s x) โโจ ๐ โฉ[ โฆ
2โฆ ]
              r (s y) โโจ ๐ โฉ[ โฆ
3โฆ ]
              y       โโจ ๐ โฉ
        where
         โฆ
1โฆ = ๏ผ-to-โ ๐ (s-section-of-r x)
         โฆ
2โฆ = monotone-if-continuous ๐ ๐ ๐ฃ (s x) (s y) (โโ-to-โ l)
         โฆ
3โฆ = ๏ผ-to-โ ๐ (s-section-of-r y)
       โฆ
โโฆ : (x โโจ ๐ โฉ y) โ (s x โโ s y)
       โฆ
โโฆ l = โ-to-โโ (monotone-if-continuous ๐ ๐ ๐ค x y l)
\end{code}
Moving on from local smallness, we present a few useful lemmas on cofinality and
(joins of) directed families.
\begin{code}
semidirected-if-bicofinal : (๐ : DCPO {๐ค} {๐ฃ}) {I J : ๐ฆ ฬ }
                            (ฮฑ : I โ โจ ๐ โฉ) (ฮฒ : J โ โจ ๐ โฉ)
                          โ ((i : I) โ โ j ๊ J , ฮฑ i โโจ ๐ โฉ ฮฒ j)
                          โ ((j : J) โ โ i ๊ I , ฮฒ j โโจ ๐ โฉ ฮฑ i)
                          โ is-semidirected (underlying-order ๐) ฮฑ
                          โ is-semidirected (underlying-order ๐) ฮฒ
semidirected-if-bicofinal ๐ {I} {J} ฮฑ ฮฒ ฮฑ-cofinal-in-ฮฒ ฮฒ-cofinal-in-ฮฑ ฯ jโ jโ =
 โฅโฅ-recโ โ-is-prop f (ฮฒ-cofinal-in-ฮฑ jโ) (ฮฒ-cofinal-in-ฮฑ jโ)
  where
   f : (ฮฃ iโ ๊ I , ฮฒ jโ โโจ ๐ โฉ ฮฑ iโ)
     โ (ฮฃ iโ ๊ I , ฮฒ jโ โโจ ๐ โฉ ฮฑ iโ)
     โ โ j ๊ J , (ฮฒ jโ โโจ ๐ โฉ ฮฒ j) ร (ฮฒ jโ โโจ ๐ โฉ ฮฒ j)
   f (iโ , uโ) (iโ , uโ) = โฅโฅ-rec โ-is-prop g (ฯ iโ iโ)
    where
     g : (ฮฃ i ๊ I , (ฮฑ iโ โโจ ๐ โฉ ฮฑ i) ร (ฮฑ iโ โโจ ๐ โฉ ฮฑ i))
       โ (โ j ๊ J , (ฮฒ jโ โโจ ๐ โฉ ฮฒ j) ร (ฮฒ jโ โโจ ๐ โฉ ฮฒ j))
     g (i , vโ , vโ) = โฅโฅ-functor h (ฮฑ-cofinal-in-ฮฒ i)
      where
       h : (ฮฃ j ๊ J , ฮฑ i โโจ ๐ โฉ ฮฒ j)
         โ (ฮฃ j ๊ J , (ฮฒ jโ โโจ ๐ โฉ ฮฒ j) ร (ฮฒ jโ โโจ ๐ โฉ ฮฒ j))
       h (j , w) = (j , (ฮฒ jโ โโจ ๐ โฉ[ uโ ]
                         ฮฑ iโ โโจ ๐ โฉ[ vโ ]
                         ฮฑ i  โโจ ๐ โฉ[ w ]
                         ฮฒ j  โโจ ๐ โฉ)
                      , (ฮฒ jโ โโจ ๐ โฉ[ uโ ]
                         ฮฑ iโ โโจ ๐ โฉ[ vโ ]
                         ฮฑ i  โโจ ๐ โฉ[ w ]
                         ฮฒ j  โโจ ๐ โฉ))
directed-if-bicofinal : (๐ : DCPO {๐ค} {๐ฃ}) {I J : ๐ฆ ฬ }
                        {ฮฑ : I โ โจ ๐ โฉ} {ฮฒ : J โ โจ ๐ โฉ}
                      โ ((i : I) โ โ j ๊ J , ฮฑ i โโจ ๐ โฉ ฮฒ j)
                      โ ((j : J) โ โ i ๊ I , ฮฒ j โโจ ๐ โฉ ฮฑ i)
                      โ is-Directed ๐ ฮฑ
                      โ is-Directed ๐ ฮฒ
directed-if-bicofinal ๐ {I} {J} {ฮฑ} {ฮฒ} ฮบโ ฮบโ ฮด =
 (ฮณ , semidirected-if-bicofinal ๐ ฮฑ ฮฒ ฮบโ ฮบโ (semidirected-if-Directed ๐ ฮฑ ฮด))
  where
   ฮณ : โฅ J โฅ
   ฮณ = โฅโฅ-rec โฅโฅ-is-prop ฯ (inhabited-if-Directed ๐ ฮฑ ฮด)
    where
     ฯ : I โ โฅ J โฅ
     ฯ i = โฅโฅ-functor prโ (ฮบโ i)
โ-โ-if-cofinal : (๐ : DCPO {๐ค} {๐ฃ}) {I J : ๐ฅ ฬ }
                 {ฮฑ : I โ โจ ๐ โฉ} {ฮฒ : J โ โจ ๐ โฉ}
               โ ((i : I) โ โ j ๊ J , ฮฑ i โโจ ๐ โฉ ฮฒ j)
               โ (ฮด : is-Directed ๐ ฮฑ)
               โ (ฮต : is-Directed ๐ ฮฒ)
               โ โ ๐ ฮด โโจ ๐ โฉ โ ๐ ฮต
โ-โ-if-cofinal ๐ {I} {J} {ฮฑ} {ฮฒ} ฮฑ-cofinal-in-ฮฒ ฮด ฮต =
 โ-is-lowerbound-of-upperbounds ๐ ฮด (โ ๐ ฮต) ฮณ
  where
   ฮณ : (i : I) โ ฮฑ i โโจ ๐ โฉ โ ๐ ฮต
   ฮณ i = โฅโฅ-rec (prop-valuedness ๐ (ฮฑ i) (โ ๐ ฮต)) ฯ (ฮฑ-cofinal-in-ฮฒ i)
    where
     ฯ : (ฮฃ j ๊ J , ฮฑ i โโจ ๐ โฉ ฮฒ j)
       โ ฮฑ i โโจ ๐ โฉ โ ๐ ฮต
     ฯ (j , u) = ฮฑ i   โโจ ๐ โฉ[ u ]
                 ฮฒ j   โโจ ๐ โฉ[ โ-is-upperbound ๐ ฮต j ]
                 โ ๐ ฮต โโจ ๐ โฉ
โ-๏ผ-if-bicofinal : (๐ : DCPO {๐ค} {๐ฃ}) {I J : ๐ฅ ฬ }
                   {ฮฑ : I โ โจ ๐ โฉ} {ฮฒ : J โ โจ ๐ โฉ}
                 โ ((i : I) โ โ j ๊ J , ฮฑ i โโจ ๐ โฉ ฮฒ j)
                 โ ((j : J) โ โ i ๊ I , ฮฒ j โโจ ๐ โฉ ฮฑ i)
                 โ (ฮด : is-Directed ๐ ฮฑ)
                 โ (ฮต : is-Directed ๐ ฮฒ)
                 โ โ ๐ ฮด ๏ผ โ ๐ ฮต
โ-๏ผ-if-bicofinal ๐ ฮบโ ฮบโ ฮด ฮต =
 antisymmetry ๐ (โ ๐ ฮด) (โ ๐ ฮต) (โ-โ-if-cofinal ๐ ฮบโ ฮด ฮต)
                                (โ-โ-if-cofinal ๐ ฮบโ ฮต ฮด)
\end{code}
Finally, we sometimes wish to reindex a directed family by another equivalent
type. The resulting family is of course directed again and has the same
supremum, which is what we prove here.
\begin{code}
module _
        (๐ : DCPO {๐ค} {๐ฃ})
        {I : ๐ฆ ฬ } {J : ๐ฆ' ฬ }
        (ฯ : I โ J)
        (ฮฑ : I โ โจ ๐ โฉ)
       where
 reindexed-family : J โ โจ ๐ โฉ
 reindexed-family = ฮฑ โ โ ฯ โโปยน
 reindexed-family-is-directed : is-Directed ๐ ฮฑ
                              โ is-Directed ๐ reindexed-family
 reindexed-family-is-directed ฮด = J-inh , ฮฒ-semidirected
  where
   J-inh : โฅ J โฅ
   J-inh = โฅโฅ-functor โ ฯ โ (inhabited-if-Directed ๐ ฮฑ ฮด)
   ฮฒ : J โ โจ ๐ โฉ
   ฮฒ = reindexed-family
   ฮฒ-semidirected : is-semidirected (underlying-order ๐) ฮฒ
   ฮฒ-semidirected jโ jโ =
    โฅโฅ-functor r (semidirected-if-Directed ๐ ฮฑ ฮด (โ ฯ โโปยน jโ) (โ ฯ โโปยน jโ))
     where
      r : (ฮฃ i ๊ I , (ฮฒ jโ โโจ ๐ โฉ ฮฑ i) ร (ฮฒ jโ โโจ ๐ โฉ ฮฑ i))
        โ (ฮฃ j ๊ J , (ฮฒ jโ โโจ ๐ โฉ ฮฒ j) ร (ฮฒ jโ โโจ ๐ โฉ ฮฒ j))
      r (i , lโ , lโ) = (โ ฯ โ i
                        , (ฮฒ jโ                    โโจ ๐ โฉ[ lโ ]
                           ฮฑ i                     โโจ ๐ โฉ[ k ]
                           (ฮฑ โ โ ฯ โโปยน โ โ ฯ โ) i โโจ ๐ โฉ)
                        , (ฮฒ jโ                    โโจ ๐ โฉ[ lโ ]
                           ฮฑ i                     โโจ ๐ โฉ[ k ]
                           (ฮฑ โ โ ฯ โโปยน โ โ ฯ โ) i โโจ ๐ โฉ))
       where
        k = ๏ผ-to-โ ๐
             (ap ฮฑ (inverses-are-retractions โ ฯ โ (โโ-is-equiv ฯ) i))
 reindexed-family-sup : (x : โจ ๐ โฉ)
                      โ is-sup (underlying-order ๐) x ฮฑ
                      โ is-sup (underlying-order ๐) x (reindexed-family)
 reindexed-family-sup x x-is-sup = ub , lb-of-ubs
  where
   ฮฒ : J โ โจ ๐ โฉ
   ฮฒ = reindexed-family
   ub : is-upperbound (underlying-order ๐) x ฮฒ
   ub i = sup-is-upperbound (underlying-order ๐) x-is-sup (โ ฯ โโปยน i)
   lb-of-ubs : is-lowerbound-of-upperbounds (underlying-order ๐) x ฮฒ
   lb-of-ubs y y-is-ub = sup-is-lowerbound-of-upperbounds (underlying-order ๐)
                          x-is-sup y lemma
    where
     lemma : is-upperbound (underlying-order ๐) y ฮฑ
     lemma i = ฮฑ i         โโจ ๐ โฉ[ โฆ
1โฆ ]
               ฮฒ (โ ฯ โ i) โโจ ๐ โฉ[ โฆ
2โฆ ]
               y           โโจ ๐ โฉ
      where
       โฆ
1โฆ = ๏ผ-to-โ ๐
             (ap ฮฑ (inverses-are-retractions โ ฯ โ (โโ-is-equiv ฯ) i))
       โฆ
2โฆ = y-is-ub (โ ฯ โ i)
module _
        (๐ : DCPO {๐ค} {๐ฃ})
        {I : ๐ฆ ฬ } {J : ๐ฆ' ฬ }
        (ฯ : I โ J)
        (ฮฑ : I โ โจ ๐ โฉ)
       where
 sup-reindexed-family : (x : โจ ๐ โฉ)
                      โ is-sup (underlying-order ๐) x (reindexed-family ๐ ฯ ฮฑ)
                      โ is-sup (underlying-order ๐) x ฮฑ
 sup-reindexed-family x x-is-sup =
  transport (is-sup (underlying-order ๐) x) (dfunext fe h)
            (reindexed-family-sup ๐ (โ-sym ฯ) ฮฒ x x-is-sup)
   where
    ฮฒ = reindexed-family ๐ ฯ ฮฑ
    h : reindexed-family ๐ (โ-sym ฯ) ฮฒ โผ ฮฑ
    h i = (ฮฑ โ โ ฯ โโปยน โ โ โ-sym ฯ โโปยน) i ๏ผโจ eโ โฉ
          (ฮฑ โ โ ฯ โโปยน โ โ ฯ โ) i         ๏ผโจ eโ โฉ
          ฮฑ i                             โ
     where
      eโ = ap (ฮป - โ (ฮฑ โ โ ฯ โโปยน โ -) i)
              (inversion-involutive โ ฯ โ (โโ-is-equiv ฯ))
      eโ = ap ฮฑ (inverses-are-retractions' ฯ i)
\end{code}
Added 23 June 2024.
All dcpos (regardless of the universe level for index families) are ฯ-complete.
\begin{code}
dcpos-are-ฯ-complete : (๐ : DCPO {๐ค} {๐ฃ})
                     โ is-ฯ-complete (underlying-order ๐)
dcpos-are-ฯ-complete ๐ ฮฑ ฮฑ-is-ฯ-chain = s , s-is-sup
 where
  โ' : ๐ฅ ฬ
  โ' = Lift ๐ฅ โ
  ฯ : โ โ Lift ๐ฅ โ
  ฯ = โ-Lift ๐ฅ โ
  ฮด : is-Directed ๐ (reindexed-family ๐ (โ-Lift ๐ฅ โ) ฮฑ)
  ฮด = reindexed-family-is-directed ๐ ฯ ฮฑ (ฯ-chains-are-Directed ๐ ฮฑ ฮฑ-is-ฯ-chain)
  s : โจ ๐ โฉ
  s = โ ๐ ฮด
  s-is-sup : is-sup (underlying-order ๐) s ฮฑ
  s-is-sup = sup-reindexed-family ๐ ฯ ฮฑ s (โ-is-sup ๐ ฮด)
\end{code}
Added 18th Feb 2024 by Martin Escardo. Subdcpo induced by a subset /
property.
\begin{code}
is-closed-under-directed-sups : (๐ : DCPO {๐ค} {๐ฃ})
                              โ (โจ ๐ โฉ โ ๐ฆ ฬ )
                              โ ๐ฅ โบ โ ๐ค โ ๐ฃ โ ๐ฆ ฬ
is-closed-under-directed-sups {๐ค} {๐ฃ} ๐ P =
    {I : ๐ฅ ฬ } (ฮฑ : I โ โจ ๐ โฉ) (ฮด : is-Directed ๐ ฮฑ)
  โ ((i : I) โ P (ฮฑ i))
  โ P (โ ๐ ฮด)
open import UF.Sets-Properties
module _
         (๐ : DCPO {๐ค} {๐ฃ})
         (P : โจ ๐ โฉ โ ๐ฆ ฬ )
         (P-is-prop-valued : (x : โจ ๐ โฉ) โ is-prop (P x))
         (P-is-closed-under-directed-sups : is-closed-under-directed-sups ๐ P)
       where
 subdcpo : DCPO {๐ค โ ๐ฆ} {๐ฃ}
 subdcpo =
  (ฮฃ x ๊ โจ ๐ โฉ , P x) ,
  (ฮป (x , _) (y , _) โ x โโจ ๐ โฉ y) ,
  (subsets-of-sets-are-sets โจ ๐ โฉ P (sethood ๐) (P-is-prop-valued _) ,
   (ฮป _ _ โ prop-valuedness ๐ _ _) ,
   (ฮป _ โ reflexivity ๐ _) ,
   (ฮป (x , _) (y , _) (z , _) โ transitivity ๐ x y z) ,
   (ฮป (x , _) (y , _) l m โ to-subtype-๏ผ
                             P-is-prop-valued
                             (antisymmetry ๐ x y l m))) ,
  (ฮป I ฮฑ ฮด โ (โ ๐ {I} {prโ โ ฮฑ} ฮด ,
              P-is-closed-under-directed-sups (prโ โ ฮฑ) ฮด (prโ โ ฮฑ)) ,
             โ-is-upperbound ๐ ฮด ,
             (ฮป (x , _) โ โ-is-lowerbound-of-upperbounds ๐ ฮด x))
 subdcpo-inclusion : โจ subdcpo โฉ โ โจ ๐ โฉ
 subdcpo-inclusion = prโ
 subdcpo-satisfies-property : (ฯ : โจ subdcpo โฉ) โ P (subdcpo-inclusion ฯ)
 subdcpo-satisfies-property = prโ
open import UF.SubtypeClassifier
is-closed-under-directed-supsโ : (๐ : DCPO {๐ค} {๐ฃ})
                               โ (โจ ๐ โฉ โ ฮฉ ๐ฆ)
                               โ ฮฉ (๐ฅ โบ โ ๐ค โ ๐ฃ โ ๐ฆ)
is-closed-under-directed-supsโ {๐ค} {๐ฃ} ๐ P =
 is-closed-under-directed-sups ๐ (ฮป x โ P x holds) ,
 implicit-ฮ -is-prop fe (ฮป I โ ฮ โ-is-prop fe (ฮป ฮฑ ฮด c โ holds-is-prop (P (โ ๐ ฮด))))
module _
        (๐ : DCPO {๐ค} {๐ฃ})
        (P : โจ ๐ โฉ โ ฮฉ ๐ฆ)
        (P-is-closed-under-directed-supsโ : is-closed-under-directed-supsโ ๐ P holds)
       where
 subdcpoโ : DCPO {๐ค โ ๐ฆ} {๐ฃ}
 subdcpoโ = subdcpo ๐
            (ฮป x โ P x holds)
            (ฮป x โ holds-is-prop (P x))
            P-is-closed-under-directed-supsโ
\end{code}