Ayberk Tosun, 30 June 2023

This module contains a definition of the Scott locale of a dcpo, using the
definition of dcpo from the `DomainTheory` development due to Tom de Jong.

\begin{code}[hide]

{-# OPTIONS --safe --without-K --lossy-unification #-}

open import MLTT.Spartan
open import Slice.Family
open import UF.FunExt
open import UF.Logic
open import UF.PropTrunc
open import UF.SubtypeClassifier
open import UF.Subsingletons
open import UF.Subsingletons-FunExt

\end{code}

We assume the existence of propositional truncations as well as function
extensionality.

\begin{code}

module Locales.ScottLocale.Definition (pt : propositional-truncations-exist)
                                      (fe : Fun-Ext)
                                      (π“₯  : Universe)                      where

open Universal fe
open Implication fe
open Existential pt
open Conjunction
open import Locales.Frame pt fe
open import DomainTheory.Basics.Dcpo pt fe π“₯ renaming (⟨_⟩ to ⟨_βŸ©βˆ™)
open import DomainTheory.Topology.ScottTopology pt fe π“₯

open PropositionalTruncation pt

\end{code}

We carry out the construction in the following submodule which is parametrised
by

  1. a dcpo `𝓓` whose (a) carrier set lives in universe `𝓀`, (b) whose relation
     lives in universe `𝓣`, and (c) whose directed joins are over families with
     index types living in universe `π“₯`.
  2. a universe `𝓦` where the Scott-open subsets are to live,
  3. an assumption that `𝓦` satisfies propositional extensionality.

\begin{code}

module DefnOfScottLocale (𝓓 : DCPO {𝓀} {𝓣}) (𝓦 : Universe) (pe : propext 𝓦) where

 open DefnOfScottTopology 𝓓 𝓦

\end{code}

`π’ͺβ‚›` is the type of 𝓦-Scott-opens over dcpo `𝓓`.

\begin{code}

 π’ͺβ‚›-equality : (π”˜ 𝔙 : π’ͺβ‚›) β†’ _βˆˆβ‚› π”˜ = _βˆˆβ‚› 𝔙 β†’ π”˜ = 𝔙
 π’ͺβ‚›-equality U V = to-subtype-= (holds-is-prop ∘ is-scott-open)

\end{code}

These are ordered by inclusion. The subscript `β‚›` in the symbol `βŠ†β‚›` is intended
be mnemonic for "Scott open".

\begin{code}

 _βŠ†β‚›_ : π’ͺβ‚› β†’ π’ͺβ‚› β†’ Ξ© (𝓀 βŠ” 𝓦)
 (U , _) βŠ†β‚› (V , _) = β±― x κž‰ ⟨ 𝓓 βŸ©βˆ™ , U x β‡’ V x

 βŠ†β‚›-is-reflexive : is-reflexive _βŠ†β‚›_ holds
 βŠ†β‚›-is-reflexive (U , Ξ΄) _ = id

 βŠ†β‚›-is-transitive : is-transitive _βŠ†β‚›_ holds
 βŠ†β‚›-is-transitive (U , Ξ΄) (V , Ο΅) (W , ΞΆ) p q x = q x ∘ p x

 βŠ†β‚›-is-antisymmetric : is-antisymmetric _βŠ†β‚›_
 βŠ†β‚›-is-antisymmetric {U} {V} p q =
  π’ͺβ‚›-equality
   U
   V
   (dfunext fe Ξ» x β†’ to-subtype-=
     (Ξ» _ β†’ being-prop-is-prop fe)
     (pe (holds-is-prop (x βˆˆβ‚› U)) (holds-is-prop (x βˆˆβ‚› V)) (p x) (q x)))

 βŠ†β‚›-is-partial-order : is-partial-order π’ͺβ‚› _βŠ†β‚›_
 βŠ†β‚›-is-partial-order = (βŠ†β‚›-is-reflexive , βŠ†β‚›-is-transitive) , βŠ†β‚›-is-antisymmetric

\end{code}

The top Scott open.

\begin{code}

 βŠ€β‚› : π’ͺβ‚›
 βŠ€β‚› = (Ξ» _ β†’ ⊀ {𝓦}) , Ο… , ΞΉ
  where
   Ο… : is-upwards-closed (Ξ» _ β†’ ⊀) holds
   Ο… _ _ _ _ = ⋆

   ΞΉ : is-inaccessible-by-directed-joins (Ξ» _ β†’ ⊀) holds
   ΞΉ (S , (∣i∣ , Ξ³)) ⋆ = βˆ₯βˆ₯-rec βˆƒ-is-prop † ∣i∣
    where
     † : index S β†’ βˆƒ _ κž‰ index S , ⊀ holds
     † i = ∣ i , ⋆ ∣

 βŠ€β‚›-is-top : (U : π’ͺβ‚›) β†’ (U βŠ†β‚› βŠ€β‚›) holds
 βŠ€β‚›-is-top U = Ξ» _ _ β†’ ⋆

\end{code}

The meet of two Scott opens.

\begin{code}

 _βˆ§β‚›_ : π’ͺβ‚› β†’ π’ͺβ‚› β†’ π’ͺβ‚›
 (U , (υ₁ , ι₁)) βˆ§β‚› (V , (Ο…β‚‚ , ΞΉβ‚‚)) = (Ξ» x β†’ U x ∧ V x) , Ο… , ΞΉ
  where
   Ο… : is-upwards-closed (Ξ» x β†’ U x ∧ V x) holds
   Ο… x y (p₁ , pβ‚‚) q = υ₁ x y p₁ q , Ο…β‚‚ x y pβ‚‚ q

   ΞΉ : is-inaccessible-by-directed-joins (Ξ» x β†’ U x ∧ V x) holds
   ΞΉ (S , Ξ΄) (p , q) = βˆ₯βˆ₯-recβ‚‚ βˆƒ-is-prop Ξ³ (ι₁ (S , Ξ΄) p) (ΞΉβ‚‚ (S , Ξ΄) q)
    where
     Ξ³ : Ξ£ i κž‰ index S , U (S [ i ]) holds
       β†’ Ξ£ j κž‰ index S , V (S [ j ]) holds
       β†’ βˆƒ k κž‰ index S , (U (S [ k ]) ∧ V (S [ k ])) holds
     Ξ³ (i , r₁) (j , rβ‚‚) = βˆ₯βˆ₯-rec βˆƒ-is-prop † (prβ‚‚ Ξ΄ i j)
      where
       † : Ξ£ kβ‚€ κž‰ index S ,
            ((S [ i ]) βŠ‘βŸ¨ 𝓓 βŸ©β‚š (S [ kβ‚€ ]) ∧ (S [ j ]) βŠ‘βŸ¨ 𝓓 βŸ©β‚š (S [ kβ‚€ ])) holds
         β†’ βˆƒ k κž‰ index S , (U (S [ k ]) ∧ V (S [ k ])) holds
       † (kβ‚€ , Ο† , ψ) =
        ∣ kβ‚€ , υ₁ (S [ i ]) (S [ kβ‚€ ]) r₁ Ο† , Ο…β‚‚ (S [ j ]) (S [ kβ‚€ ]) rβ‚‚ ψ ∣

 open Meets _βŠ†β‚›_

 βˆ§β‚›-is-meet : (U V : π’ͺβ‚›) β†’ ((U βˆ§β‚› V) is-glb-of ((U , V))) holds
 βˆ§β‚›-is-meet U V = † , ‑
  where
   † : ((U βˆ§β‚› V) is-a-lower-bound-of (U , V)) holds
   † = (Ξ» _ (p , _) β†’ p) , (Ξ» _ (_ , q) β†’ q)

   ‑ : ((W , _) : lower-bound (U , V)) β†’ (W βŠ†β‚› (U βˆ§β‚› V)) holds
   ‑ (W , p) x q = pr₁ p x q , prβ‚‚ p x q

\end{code}

The union of a 𝓦-family of Scott opens.

\begin{code}

 ⋁ₛ_ : Fam 𝓦 π’ͺβ‚› β†’ π’ͺβ‚›
 ⋁ₛ_ S = ⋃S , Ο… , ΞΉ
  where
   ⋃S : ⟨ 𝓓 βŸ©βˆ™ β†’ Ξ© 𝓦
   ⋃S = Ξ» x β†’ Ǝ i κž‰ index S , pr₁ (S [ i ]) x holds

   Ο… : is-upwards-closed ⋃S holds
   Ο… x y p q = βˆ₯βˆ₯-rec (holds-is-prop (⋃S y)) † p
    where
     † : Ξ£ i κž‰ index S , (S [ i ]) .pr₁ x holds β†’ ⋃S y holds
     † (i , r) = ∣ i , pr₁ (prβ‚‚ (S [ i ])) x y r q ∣

   ΞΉ : is-inaccessible-by-directed-joins ⋃S holds
   ΞΉ (T , Ξ΄) p = βˆ₯βˆ₯-rec βˆƒ-is-prop † p
    where
     † : Ξ£ i κž‰ index S , (S [ i ]) .pr₁ (⋁ (T , Ξ΄)) holds
       β†’ βˆƒ k κž‰ index T , ⋃S (T [ k ]) holds
     † (i , q) = βˆ₯βˆ₯-rec βˆƒ-is-prop ‑ (prβ‚‚ (prβ‚‚ (S [ i ])) (T , Ξ΄) q)
      where
       ‑ : (Ξ£ k κž‰ index T , (S [ i ]) .pr₁ (T [ k ]) holds)
         β†’ βˆƒ k κž‰ index T , ⋃S (T [ k ]) holds
       ‑ (k , r) = ∣ k , ∣ i , r ∣ ∣

 open Joins _βŠ†β‚›_

 ⋁ₛ-is-join : (S : Fam 𝓦 π’ͺβ‚›) β†’ ((⋁ₛ S) is-lub-of S) holds
 ⋁ₛ-is-join S = † , ‑
  where
   † : ((⋁ₛ S) is-an-upper-bound-of S) holds
   † i y p = ∣ i , p ∣

   ‑ : ((U , _) : upper-bound S) β†’ ((⋁ₛ S) βŠ†β‚› U) holds
   ‑ ((U , Ξ΄) , p) x q = βˆ₯βˆ₯-rec (holds-is-prop (U x) ) Ξ³ q
    where
     Ξ³ : Ξ£ i κž‰ index S , (S [ i ]) .pr₁ x holds
       β†’ U x holds
     Ξ³ (i , r) = p i x r

\end{code}

Distributivity is trivial as this is a lattice of subsets.

\begin{code}

 distributivityβ‚› : (U : π’ͺβ‚›) (S : Fam 𝓦 π’ͺβ‚›) β†’ U βˆ§β‚› (⋁ₛ S) = ⋁ₛ ⁅ U βˆ§β‚› V ∣ V Ξ΅ S ⁆
 distributivityβ‚› U S = βŠ†β‚›-is-antisymmetric † ‑
  where
   † : ((U βˆ§β‚› (⋁ₛ S)) βŠ†β‚› (⋁ₛ ⁅ U βˆ§β‚› V ∣ V Ξ΅ S ⁆)) holds
   † x (p , q) = βˆ₯βˆ₯-rec (holds-is-prop ((⋁ₛ ⁅ U βˆ§β‚› V ∣ V Ξ΅ S ⁆) .pr₁ x)) †₀ q
    where
     †₀ : Ξ£ i κž‰ index S , ((S [ i ]) .pr₁ x) holds
        β†’ (⋁ₛ ⁅ U βˆ§β‚› V ∣ V Ξ΅ S ⁆) .pr₁ x holds
     †₀ (i , r) = ∣ i , (p , r) ∣

   ‑ : ((⋁ₛ ⁅ U βˆ§β‚› V ∣ V Ξ΅ S ⁆) βŠ†β‚› (U βˆ§β‚› (⋁ₛ S))) holds
   ‑ x p = βˆ₯βˆ₯-rec (holds-is-prop ((U βˆ§β‚› (⋁ₛ S)) .pr₁ x)) ‑₀ p
    where
     ‑₀ : (Ξ£ i κž‰ index S , ((U βˆ§β‚› (S [ i ])) .pr₁ x holds))
        β†’ (U βˆ§β‚› (⋁ₛ S)) .pr₁ x holds
     ‑₀ (i , (q , r)) = q , ∣ i , r ∣

\end{code}

We now have everything we need to write down the Scott locale of `𝓓`.

\begin{code}

 π’ͺβ‚›-frame-structure : frame-structure (𝓀 βŠ” 𝓦) 𝓦 π’ͺβ‚›
 π’ͺβ‚›-frame-structure = (_βŠ†β‚›_ , βŠ€β‚› , _βˆ§β‚›_ , ⋁ₛ_) , βŠ†β‚›-is-partial-order
                    , βŠ€β‚›-is-top
                    , (Ξ» (U , V) β†’ βˆ§β‚›-is-meet U V)
                    , ⋁ₛ-is-join
                    , Ξ» (U , S) β†’ distributivityβ‚› U S

 ScottLocale : Locale (π“₯ ⁺ βŠ” 𝓀 βŠ” 𝓣 βŠ” 𝓦 ⁺) (𝓀 βŠ” 𝓦) 𝓦
 ScottLocale = record { ⟨_βŸ©β‚— = π’ͺβ‚› ; frame-str-of = π’ͺβ‚›-frame-structure }

\end{code}

For clarity, we define the special case of `ScottLocale` for the large and
locally small case.

\begin{code}

module DefnOfScottLocaleLocallySmallCase (𝓓  : DCPO {π“₯ ⁺} {π“₯})
                                         (pe : propext π“₯)        where


 open DefnOfScottLocale 𝓓 π“₯ pe

 ScottLocale' : Locale (π“₯ ⁺) (π“₯ ⁺) π“₯
 ScottLocale' = ScottLocale

\end{code}