Ayberk Tosun, 21 August 2023

These used to live in the `CompactRegular` module which is now deprecated and
will be broken down into smaller modules.

\begin{code}[hide]

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

open import UF.PropTrunc
open import UF.FunExt
open import UF.Subsingletons
open import UF.Logic
open import MLTT.Spartan
open import UF.Size
open import UF.Base
open import UF.EquivalenceExamples using (Σ-assoc)

module Locales.SmallBasis (pt : propositional-truncations-exist)
                          (fe : Fun-Ext)
                          (sr : Set-Replacement pt) where

open import Locales.Frame       pt fe hiding (has-directed-basis₀)
open import Locales.Compactness.Definition pt fe
open import Locales.Spectrality.SpectralLocale pt fe
open import Slice.Family
open import UF.SubtypeClassifier
open import UF.ImageAndSurjection pt
open import UF.Equiv renaming (_■ to _𝒬ℰ𝒟)
open import MLTT.List using (List; map; _<$>_; []; _∷_)
open import UF.Univalence using (Univalence)
open import Locales.Spectrality.Properties pt fe

open PropositionalTruncation pt

open AllCombinators pt fe

open Locale

\end{code}

We start by defining the structure of having a basis. The superscript _ᴰ is our
notational convention for marking that we are working with the structural
version of a notion.

\begin{code}

basis-forᴰ : (F : Frame 𝓤 𝓥 𝓦)  Fam 𝓦  F   𝓤  𝓥  𝓦   ̇
basis-forᴰ {𝓦 = 𝓦} F (I , β) =
 (U :  F )  Σ J  Fam 𝓦 I , (U is-lub-of  β j  j ε J ) holds
  where
   open Joins  x y  x ≤[ poset-of F ] y)

basisᴰ : (F : Frame 𝓤 𝓥 𝓦)  𝓤  𝓥  𝓦   ̇
basisᴰ {𝓤} {𝓥} {𝓦} F = Σ   Fam 𝓦  F  , basis-forᴰ F 

\end{code}

We will often have to talk about "directed bases": bases in which the covering
families are directed.

\begin{code}

directed-basis-forᴰ : (F : Frame 𝓤 𝓥 𝓦)  Fam 𝓦  F   𝓤  𝓥  𝓦   ̇
directed-basis-forᴰ {𝓤} {𝓥} {𝓦} F @(I , β) =
 (U :  F ) 
  Σ J  Fam 𝓦 I ,
   (U is-lub-of  β j  j ε J   is-directed F  β j  j ε J ) holds
    where
     open Joins  x y  x ≤[ poset-of F ] y)

directed-basisᴰ : (F : Frame 𝓤 𝓥 𝓦)  𝓤  𝓥  𝓦   ̇
directed-basisᴰ {𝓤} {𝓥} {𝓦} F =
 Σ   Fam 𝓦  F  , directed-basis-forᴰ F 

directed-basis-is-basis : (F : Frame 𝓤 𝓥 𝓦) ( : Fam 𝓦  F )
                         directed-basis-forᴰ F 
                         basis-forᴰ F 
directed-basis-is-basis {_} {_} {𝓦} F  β U =  (β U)
 where
  open Joins  x y  x ≤[ poset-of F ] y)

   : Σ J  Fam 𝓦 (index ) ,
       (U is-lub-of   [ j ]  j ε J   is-directed F   [ j ]  j ε J )
        holds
     Σ J  Fam 𝓦 (index ) , (U is-lub-of   [ j ]  j ε J ) holds
   (J , c , _)= J , c

\end{code}

In `spectralₛᴰ`, we give the old definition of a spectral locale that bakes in
the small basis assumption. We use the `ₛ` subscript to differentiate it from
the new one.

\begin{code}

contains-top : (F : Frame 𝓤 𝓥 𝓦)  Fam 𝓦  F   Ω (𝓤  𝓥  𝓦)
contains-top F U = Ǝ t  index U , is-top F (U [ t ]) holds

closed-under-binary-meets : (F : Frame 𝓤 𝓥 𝓦)  Fam 𝓦  F   Ω (𝓤  𝓥  𝓦)
closed-under-binary-meets F 𝒮 =
  i  index 𝒮 ,  j  index 𝒮 ,
  Ǝ k  index 𝒮 , ((𝒮 [ k ]) is-glb-of (𝒮 [ i ] , 𝒮 [ j ])) holds
   where
    open Meets  x y  x ≤[ poset-of F ] y)

closed-under-finite-meets : (F : Frame 𝓤 𝓥 𝓦)  Fam 𝓦  F   Ω (𝓤  𝓥  𝓦)
closed-under-finite-meets F S = contains-top F S  closed-under-binary-meets F S

spectralₛᴰ : Locale 𝓤 𝓥 𝓦  𝓤  𝓥  𝓦   ̇
spectralₛᴰ {_} {_} {𝓦} X =
  Σ   Fam 𝓦  𝒪 X  ,
     is-directed-basis (𝒪 X) 
   × consists-of-compact-opens X  holds
   × closed-under-finite-meets (𝒪 X)  holds

\end{code}

The previous definition of spectrality was the truncation of `spectralₛᴰ`:

\begin{code}

is-spectralₛ : Locale 𝓤 𝓥 𝓦  Ω (𝓤  𝓥  𝓦 )
is-spectralₛ X =  spectralₛᴰ X ∥Ω

\end{code}

Compact opens are basic:

\begin{code}

is-basic : (X : Locale 𝓤 𝓥 𝓦)   𝒪 X   directed-basisᴰ (𝒪 X)  Ω (𝓤  𝓦)
is-basic X U ( , β) = U ∈image ( [_]) , ∃-is-prop

compact-opens-are-basic : (X : Locale 𝓤 𝓥 𝓦)
                         (b : directed-basisᴰ (𝒪 X))
                         (K :  𝒪 X )
                         is-compact-open X K holds
                         is-basic X K b holds
compact-opens-are-basic {_} {_} {𝓦} X ( , β) K κ =  (β K)
 where
  open Joins  x y  x ≤[ poset-of (𝒪 X) ] y)

   : (Σ 𝒥  Fam 𝓦 (index ) , (K is-lub-of   [ j ]  j ε 𝒥   is-directed (𝒪 X)   [ j ]  j ε 𝒥 ) holds)
     is-basic X K ( , β) holds
   (𝒥 , c , d) =
   ∥∥-rec (holds-is-prop (is-basic X K ( , β)))  (κ   [ j ]  j ε 𝒥  d q)
    where
     q : (K ≤[ poset-of (𝒪 X) ] (⋁[ 𝒪 X ]   [ j ]  j ε 𝒥 )) holds
     q = reflexivity+ (poset-of (𝒪 X)) (⋁[ 𝒪 X ]-unique   [ j ]  j ε 𝒥  K c)

      : Σ j  index 𝒥 , (K ≤[ poset-of (𝒪 X) ]  [ 𝒥 [ j ] ]) holds
        is-basic X K ( , β) holds
      (j , φ) =  𝒥 [ j ] , ≤-is-antisymmetric (poset-of (𝒪 X)) ψ φ 
      where
       open PosetReasoning (poset-of (𝒪 X))

        = ⋁[ 𝒪 X ]-upper   [ j ]  j ε 𝒥  j
        = reflexivity+ (poset-of (𝒪 X)) ((⋁[ 𝒪 X ]-unique   [ j ]  j ε 𝒥  K c) ⁻¹)

       ψ : ( [ 𝒥 [ j ] ] ≤[ poset-of (𝒪 X) ] K) holds
       ψ =  [ 𝒥 [ j ] ] ≤⟨   ⋁[ 𝒪 X ]   [ j ]  j ε 𝒥  ≤⟨   K 

\end{code}

One of the things that we show in this module is that this truncation was
unnecessary as the basis is unique in the presence of a small basis.

We now define the following crucial predicate expressing what it means for the
type of compact opens of a locale to be small:

\begin{code}

has-small-𝒦 : Locale 𝓤 𝓥 𝓦  𝓤  𝓥  𝓦   ̇
has-small-𝒦 {_} {_} {𝓦} X = 𝒦 X is 𝓦 small

\end{code}

\begin{code}

basis-is-unique : (X : Locale 𝓤 𝓥 𝓦)
                 (( , _) : directed-basisᴰ (𝒪 X))
                 consists-of-compact-opens X  holds
                 image (ℬ-compact X [_])  image ( [_])
basis-is-unique X ( , b) κ =
 r , (s , s-is-section-of-r) , s , r-is-retract-of-s
  where
   r : image (ℬ-compact X [_])  image ( [_])
   r (K , p) = K , K-is-basic
    where
     K-is-compact : is-compact-open X K holds
     K-is-compact = ∥∥-rec (holds-is-prop (is-compact-open X K))  p
      where
        : Σ  x  ℬ-compact X [ x ]  K)  is-compact-open X K holds
        ((K′ , κ′) , q) = transport  -  is-compact-open X - holds) q κ′

     K-is-basic : K ∈image ( [_])
     K-is-basic =
      ∥∥-rec ∃-is-prop  (compact-opens-are-basic X ( , b) K K-is-compact)
       where
         : Σ i  index  ,  [ i ]  K   j  index  ,  [ j ]  K
         (i , p) =  i , p 

   s : image ( [_])  image (ℬ-compact X [_])
   s (K , p) = K , ∥∥-rec ∃-is-prop  p
    where
      : Σ i  index  ,  [ i ]  K   (K′ , _)  index (ℬ-compact X) , K′  K
      (i , q) =  ( [ i ] , κ i) , q 

   s-is-section-of-r : r  s  id
   s-is-section-of-r (U , p) = to-subtype-=  _  ∃-is-prop) refl

   r-is-retract-of-s : s  r  id
   r-is-retract-of-s (K , p) = to-subtype-=  _  ∃-is-prop) refl

\end{code}

Having a directed basis is a proposition under certain favourable conditions.

\begin{code}

basic-iso-to-𝒦 : (X : Locale 𝓤 𝓥 𝓦)
                (( , b) : directed-basisᴰ (𝒪 X))
                consists-of-compact-opens X  holds
                image ( [_])  𝒦 X
basic-iso-to-𝒦 X ( , β) κ =
 image ( [_])             ≃⟨  
 image (ℬ-compact X [_])   ≃⟨  
 𝒦 X                       𝒬ℰ𝒟
  where
    : image ( [_])  image (ℬ-compact X [_])
    = ≃-sym (basis-is-unique X ( , β) κ)

    : image (ℬ-compact X [_])  𝒦 X
    = s , (r , ψ) , (r , ϑ)
    where
     s : image (ℬ-compact X [_])  𝒦 X
     s (K , c) = K , ∥∥-rec (holds-is-prop (is-compact-open X K))  c
      where
        : Σ i  index (ℬ-compact X) , ℬ-compact X [ i ]  K
          is-compact-open X K holds
        ((K′ , φ) , p) = transport  -  is-compact-open X - holds) p φ

     r : 𝒦 X  image (ℬ-compact X [_])
     r (K , p) = K ,  (K , p) , refl 

     ψ : s  r  id
     ψ (K , p) = to-subtype-= (holds-is-prop  is-compact-open X) refl

     ϑ : (r  s)  id
     ϑ (K , p) = to-subtype-=  _  ∃-is-prop) refl

\end{code}

\begin{code}

local-smallness : (X : Locale 𝓤 𝓦 𝓦)
                  𝒪 X  is-locally 𝓦 small
local-smallness {𝓤} {𝓦} X = 
 where
  _≡ₓ_ :  𝒪 X    𝒪 X   Ω 𝓦
  U ≡ₓ V = (U ≤[ poset-of (𝒪 X) ] V)  (V ≤[ poset-of (𝒪 X) ] U)

   :  𝒪 X  is-locally 𝓦 small
   U V = (U ≡ₓ V) holds , e
   where
    e : (U ≡ₓ V) holds  (U  V)
    e = logically-equivalent-props-are-equivalent
         (holds-is-prop (U ≡ₓ V))
         carrier-of-[ poset-of (𝒪 X) ]-is-set
          (p , q)  ≤-is-antisymmetric (poset-of (𝒪 X)) p q)
         λ p  (reflexivity+ (poset-of (𝒪 X)) p) , reflexivity+ (poset-of (𝒪 X)) (p ⁻¹)

\end{code}

\begin{code}

basic-is-small : (X : Locale 𝓤 𝓥 𝓦)
                (( , b) : directed-basisᴰ (𝒪 X))
                 𝒪 X  is-locally 𝓦 small
                (image ( [_])) is 𝓦 small
basic-is-small X ( , b) ψ =
 sr ( [_]) (index  , ≃-refl (index )) ψ carrier-of-[ poset-of (𝒪 X) ]-is-set

\end{code}

\begin{code}

𝒦-is-small : (X : Locale 𝓤 𝓥 𝓦)
            (( , b) : directed-basisᴰ (𝒪 X))
            consists-of-compact-opens X  holds
             𝒪 X  is-locally 𝓦 small
            (𝒦 X) is 𝓦 small
𝒦-is-small {𝓤} {𝓥} {𝓦} X ( , b) κ ψ = B₀ , e
 where
  σ : image ( [_]) is 𝓦 small
  σ = basic-is-small X ( , b) ψ

  B₀ : 𝓦  ̇
  B₀ = pr₁ σ

   = pr₂ σ
   = basic-iso-to-𝒦 X ( , b) κ

  e : B₀  𝒦 X
  e = B₀ ≃⟨   image ( [_]) ≃⟨   𝒦 X 𝒬ℰ𝒟

\end{code}

\begin{code}

spectral-and-small-𝒦-gives-basis : (X : Locale 𝓤 𝓦 𝓦)
                                  is-spectral X holds
                                  𝒦 X is 𝓦 small
                                  basisᴰ (𝒪 X)
spectral-and-small-𝒦-gives-basis {𝓤} {𝓦} X 𝕤 (𝒦₀ , e) = (𝒦₀ , α) , β
 where
  open Joins  x y  x ≤[ poset-of (𝒪 X) ] y)
  open PosetReasoning (poset-of (𝒪 X))

  sec : 𝒦₀  𝒦 X
  sec = pr₁ e

  ret : 𝒦 X  𝒦₀
  ret = pr₁ (pr₁ (pr₂ e))

  α : 𝒦₀   𝒪 X 
  α = pr₁  sec

  β : basis-forᴰ (𝒪 X) (𝒦₀ , α)
  β U = 𝒥 ,  , 
   where
    𝒥 : Fam 𝓦 𝒦₀
    𝒥 = (Σ k  𝒦₀ , (α k ≤[ poset-of (𝒪 X) ] U) holds) , pr₁

     : (U is-an-upper-bound-of  α j  j ε 𝒥 ) holds
     = pr₂

     : ((u , _) : upper-bound  α j  j ε 𝒥 )  (U ≤[ poset-of (𝒪 X) ] u) holds
     (V , ψ) = spectral-yoneda X 𝕤 U V λ { (K , p)   K p}
     where
       : (K :  𝒪 X )
         (is-compact-open X K  K ≤[ poset-of (𝒪 X) ] U  K ≤[ poset-of (𝒪 X) ] V) holds
       K κ p = K ≤⟨ c₀  ⋁[ 𝒪 X ]  α j  j ε 𝒥  ≤⟨ ⋁[ 𝒪 X ]-least  α j  j ε 𝒥  (V ,  i  ψ i))  V 
       where
        iₖ : 𝒦₀
        iₖ = ret (K , κ)

        tmp : sec (ret (K , κ))  (K , κ)
        tmp = pr₂ (pr₁ (pr₂ e)) (K , κ)

        ϑ : (α iₖ ≤[ poset-of (𝒪 X) ] U) holds
        ϑ = α iₖ                    =⟨ refl ⟩ₚ
            pr₁ (sec (ret (K , κ))) =⟨ ap pr₁ tmp ⟩ₚ
            K                       ≤⟨ p 
            U                       

        c₀ : (K ≤[ poset-of (𝒪 X) ] (⋁[ 𝒪 X ]  α j  j ε 𝒥 )) holds
        c₀ = K                       =⟨ pr₁ (from-Σ-= tmp) ⁻¹ ⟩ₚ
             pr₁ (sec (ret (K , κ))) =⟨ refl ⟩ₚ
             α iₖ                    ≤⟨ ⋁[ 𝒪 X ]-upper  α j  j ε 𝒥  (iₖ , ϑ) 
             ⋁[ 𝒪 X ] (fmap-syntax  j  α j) 𝒥) 


\end{code}

\begin{code}

spectral-and-small-𝒦-gives-directed-basis : (X : Locale 𝓤 𝓦 𝓦)
                                           is-spectral X holds
                                           𝒦 X is 𝓦 small
                                           directed-basisᴰ (𝒪 X)
spectral-and-small-𝒦-gives-directed-basis {_} {𝓦} X σ 𝕤 =
 ℬ↑ , ℬ↑-is-directed-basis-for-X
  where
   basis-X : basisᴰ (𝒪 X)
   basis-X = spectral-and-small-𝒦-gives-basis X σ 𝕤

    : Fam 𝓦  𝒪 X 
    = pr₁ basis-X

   β : basis-forᴰ (𝒪 X) 
   β = pr₂ basis-X

   ℬ↑ : Fam 𝓦  𝒪 X 
   ℬ↑ = directify (𝒪 X) 

   β↑ : basis-forᴰ (𝒪 X) ℬ↑
   β↑ = directified-basis-is-basis (𝒪 X)  β

   ℬ↑-is-directed-basis-for-X : directed-basis-forᴰ (𝒪 X) ℬ↑
   ℬ↑-is-directed-basis-for-X U = pr₁ Σ-assoc (β↑ U , d)
    where
     𝒥 : Fam 𝓦 (index ℬ↑)
     𝒥 = pr₁ (β↑ U)

     d : is-directed (𝒪 X)  ℬ↑ [ j ]  j ε 𝒥  holds
     d = covers-of-directified-basis-are-directed (𝒪 X)  β U

\end{code}

\begin{code}

spectralᴰ : Locale 𝓤 𝓥 𝓦  (𝓤  𝓥  𝓦 ) ̇
spectralᴰ {𝓤 = 𝓤} {𝓥} {𝓦} X =
 Σ   Fam 𝓦  𝒪 X  , directed-basis-forᴰ (𝒪 X) 
                     × consists-of-compact-opens X  holds
                     × closed-under-finite-meets (𝒪 X)  holds

basisₛ : (X : Locale 𝓤 𝓥 𝓦)  spectralᴰ X  Fam 𝓦  𝒪 X 
basisₛ {𝓤} {𝓥} {𝓦} X = pr₁

basisₛ-is-basis : (X : Locale 𝓤 𝓥 𝓦) (σᴰ : spectralᴰ X)
                 basis-forᴰ (𝒪 X) (basisₛ X σᴰ)
basisₛ-is-basis X σᴰ = directed-basis-is-basis (𝒪 X) (basisₛ X σᴰ) (pr₁ (pr₂ σᴰ))

cover-indexₛ : (X : Locale 𝓤 𝓥 𝓦) (σᴰ : spectralᴰ X)
              let
                 = basisₛ X σᴰ
               in
                 𝒪 X   Fam 𝓦 (index )
cover-indexₛ X σᴰ U = pr₁ (basisₛ-is-basis X σᴰ U)

covering-familyₛ : (X : Locale 𝓤 𝓥 𝓦) (σᴰ : spectralᴰ X)
                  let
                     = basisₛ X σᴰ
                   in
                     𝒪 X   Fam 𝓦  𝒪 X 
covering-familyₛ X σᴰ U =  basisₛ X σᴰ [ j ]  j ε cover-indexₛ X σᴰ U 

basisₛ-covers-are-directed : (X : Locale 𝓤 𝓥 𝓦) (σᴰ : spectralᴰ X) (U :  𝒪 X )
                            let
                               = basisₛ X σᴰ
                              𝒥 = cover-indexₛ X σᴰ U
                             in
                              is-directed (𝒪 X)   [ j ]  j ε 𝒥  holds
basisₛ-covers-are-directed X σᴰ U = pr₂ (pr₂ (pr₁ (pr₂ σᴰ) U))

basisₛ-covers-do-cover : (X : Locale 𝓤 𝓥 𝓦) (σᴰ : spectralᴰ X) (U :  𝒪 X )
                        let
                           = basisₛ X σᴰ
                          𝒥 = cover-indexₛ X σᴰ U
                          open Joins  U V  U ≤[ poset-of (𝒪 X) ] V)
                         in
                          (U is-lub-of   [ j ]  j ε 𝒥 ) holds
basisₛ-covers-do-cover X σᴰ U = pr₁ (pr₂ (pr₁ (pr₂ σᴰ) U))

basisₛ-covers-do-cover-eq : (X : Locale 𝓤 𝓥 𝓦) (σᴰ : spectralᴰ X) (U :  𝒪 X )
                           let
                              = basisₛ X σᴰ
                             𝒥 = cover-indexₛ X σᴰ U
                             open Joins  U V  U ≤[ poset-of (𝒪 X) ] V)
                            in
                             U  ⋁[ 𝒪 X ]   [ j ]  j ε 𝒥 
basisₛ-covers-do-cover-eq X σᴰ U =
 ⋁[ 𝒪 X ]-unique   [ j ]  j ε 𝒥  U c
  where
   open Joins  U V  U ≤[ poset-of (𝒪 X) ] V)

    = basisₛ X σᴰ
   𝒥 = cover-indexₛ X σᴰ U

   c : (U is-lub-of   [ j ]  j ε 𝒥 ) holds
   c = basisₛ-covers-do-cover X σᴰ U


basisₛ-is-directed-basis : (X : Locale 𝓤 𝓥 𝓦) (σᴰ : spectralᴰ X)
                          directed-basis-forᴰ (𝒪 X) (basisₛ X σᴰ)
basisₛ-is-directed-basis X σᴰ U = cover-indexₛ X σᴰ U
                                , basisₛ-covers-do-cover X σᴰ U
                                , (basisₛ-covers-are-directed X σᴰ U)
                                 where
                                   = basisₛ X σᴰ

basisₛ-contains-top : (X : Locale 𝓤 𝓥 𝓦) (σᴰ : spectralᴰ X)
                     contains-top (𝒪 X) (basisₛ X σᴰ) holds
basisₛ-contains-top X σᴰ = pr₁ (pr₂ (pr₂ (pr₂ σᴰ)))

basisₛ-consists-of-compact-opens : (X : Locale 𝓤 𝓥 𝓦) (σᴰ : spectralᴰ X)
                                  consists-of-compact-opens X (basisₛ X σᴰ) holds
basisₛ-consists-of-compact-opens X σᴰ = pr₁ (pr₂ (pr₂ σᴰ))

basisₛ-closed-under-∧ : (X : Locale 𝓤 𝓥 𝓦) (σᴰ : spectralᴰ X)
                       closed-under-binary-meets (𝒪 X) (basisₛ X σᴰ) holds
basisₛ-closed-under-∧ X σᴰ = pr₂ (pr₂ (pr₂ (pr₂ σᴰ)))

spectralᴰ-implies-basisᴰ : (X : Locale 𝓤 𝓥 𝓦)  spectralᴰ X  basisᴰ (𝒪 X)
spectralᴰ-implies-basisᴰ X σᴰ = basisₛ X σᴰ , basisₛ-is-basis X σᴰ

spectralᴰ-implies-directed-basisᴰ : (X : Locale 𝓤 𝓥 𝓦)
                                   spectralᴰ X  directed-basisᴰ (𝒪 X)
spectralᴰ-implies-directed-basisᴰ X σᴰ =
 basisₛ X σᴰ , basisₛ-is-directed-basis X σᴰ

\end{code}

Spectrality structure gives `is-spectral`.

\begin{code}

spectralᴰ-gives-spectrality : (X : Locale 𝓤 𝓥 𝓦)
                             spectralᴰ X
                             is-spectral X holds
spectralᴰ-gives-spectrality X σᴰ = ⦅𝟏⦆ , ⦅𝟐⦆
 where
    = basisₛ X σᴰ
  β↑ = basisₛ-is-directed-basis X σᴰ

   : (Σ iₜ  index  , is-top (𝒪 X) ( [ iₜ ]) holds)  is-compact X holds
   (iₜ , φ) =
   transport
     -  is-compact-open X - holds)
    (𝟏-is-unique (𝒪 X) ( [ iₜ ]) φ)
    (basisₛ-consists-of-compact-opens X σᴰ iₜ)

  κ : is-compact X holds
  κ = ∥∥-rec (holds-is-prop (is-compact X))  (basisₛ-contains-top X σᴰ)

  𝕔 : compacts-of-[ X ]-are-closed-under-binary-meets holds
  𝕔 K₁ K₂ κ₁ κ₂ = ∥∥-rec₂
                   (holds-is-prop (is-compact-open X (K₁ ∧[ 𝒪 X ] K₂)))
                   
                   K₁-is-basic
                   K₂-is-basic
   where
    K₁-is-basic : is-basic X K₁ ( , β↑) holds
    K₁-is-basic = compact-opens-are-basic X ( , β↑) K₁ κ₁

    K₂-is-basic : is-basic X K₂ ( , β↑) holds
    K₂-is-basic = compact-opens-are-basic X ( , β↑) K₂ κ₂

     : Σ i₁  index  ,  [ i₁ ]  K₁
       Σ i₂  index  ,  [ i₂ ]  K₂
       is-compact-open X (K₁ ∧[ 𝒪 X ] K₂) holds
     (i₁ , p₁) (i₂ , p₂) =
     transport  -  is-compact-open X - holds) (p ⁻¹) 
      where
       p : K₁ ∧[ 𝒪 X ] K₂   [ i₁ ] ∧[ 𝒪 X ]  [ i₂ ]
       p = K₁ ∧[ 𝒪 X ] K₂             =⟨  
            [ i₁ ] ∧[ 𝒪 X ] K₂       =⟨  
            [ i₁ ] ∧[ 𝒪 X ]  [ i₂ ] 
            where
              = ap  -  - ∧[ 𝒪 X ] K₂) (p₁ ⁻¹)
              = ap  -  _ ∧[ 𝒪 X ] -) (p₂ ⁻¹)

       open Meets  U V  U ≤[ poset-of (𝒪 X) ] V)

        : (Σ i₃  index  , ((( [ i₃ ]) is-glb-of (( [ i₁ ]) , ( [ i₂ ]))) holds))
          is-compact-open X ( [ i₁ ] ∧[ 𝒪 X ]  [ i₂ ]) holds
        (i₃ , φ) =
        transport
          -  is-compact-open X - holds)
         q
         (basisₛ-consists-of-compact-opens X σᴰ i₃)
          where
           q :  [ i₃ ]   [ i₁ ] ∧[ 𝒪 X ]  [ i₂ ]
           q = ∧[ 𝒪 X ]-unique φ

        : is-compact-open X ( [ i₁ ] ∧[ 𝒪 X ]  [ i₂ ]) holds
        = ∥∥-rec
            (holds-is-prop (is-compact-open X ( [ i₁ ] ∧[ 𝒪 X ]  [ i₂ ])))
            
            (basisₛ-closed-under-∧ X σᴰ i₁ i₂)

  ⦅𝟏⦆ : compacts-of-[ X ]-are-closed-under-finite-meets holds
  ⦅𝟏⦆ = κ , 𝕔

  ⦅𝟐⦆ : (U :  𝒪 X )  has-a-directed-cover-of-compact-opens X U holds
  ⦅𝟐⦆ U =    [ j ]  j ε cover-indexₛ X σᴰ U  , ϑ , d , c 
   where
    ϑ : consists-of-compact-opens X   [ j ]  j ε cover-indexₛ X σᴰ U  holds
    ϑ i = basisₛ-consists-of-compact-opens X σᴰ (cover-indexₛ X σᴰ U [ i ])

    d : is-directed (𝒪 X)   [ j ]  j ε cover-indexₛ X σᴰ U  holds
    d = basisₛ-covers-are-directed X σᴰ U

    c : U  ⋁[ 𝒪 X ]   [ j ]  j ε cover-indexₛ X σᴰ U 
    c = ⋁[ 𝒪 X ]-unique
           [ j ]  j ε cover-indexₛ X σᴰ U 
         U
         (basisₛ-covers-do-cover X σᴰ U)

\end{code}

\begin{code}

open import Locales.CompactRegular pt fe using (directify-preserves-closure-under-∧)

spectral-and-small-𝒦-implies-spectralᴰ : (X : Locale 𝓤 𝓥 𝓥)
                                        is-spectral X holds
                                        𝒦 X is 𝓥 small
                                        spectralᴰ X
spectral-and-small-𝒦-implies-spectralᴰ {𝓤} {𝓥} X σ 𝕤ₖ@(𝒦₀ , e) =
 pr₁ Σ-assoc (spectral-and-small-𝒦-gives-directed-basis X σ 𝕤ₖ , κ , μ↑)
  where
    : Fam 𝓥  𝒪 X 
    = pr₁ (spectral-and-small-𝒦-gives-basis X σ 𝕤ₖ)

   β : is-basis-for (𝒪 X) 
   β = pr₂ (spectral-and-small-𝒦-gives-basis X σ 𝕤ₖ)

   sec : 𝒦₀  𝒦 X
   sec = pr₁ e

   ret : 𝒦 X  𝒦₀
   ret = pr₁ (pr₁ (pr₂ e))


   q : (K :  𝒪 X ) (κ : is-compact-open X K holds)
      sec (ret (K , κ))  (K , κ)
   q K κ = pr₂ (pr₁ (pr₂ e)) (K , κ)

   q₀ : (K :  𝒪 X ) (κ : is-compact-open X K holds)
       pr₁ (sec (ret (K , κ)))  K
   q₀ K κ = pr₁ (from-Σ-= (q K κ))

   ℬ-consists-of-compact-opens : (i : index )
                                is-compact-open X ( [ i ]) holds
   ℬ-consists-of-compact-opens i = pr₂ (sec i)

   ℬ↑ : Fam 𝓥  𝒪 X 
   ℬ↑ = pr₁ (spectral-and-small-𝒦-gives-directed-basis X σ 𝕤ₖ)

   β↑ : directed-basis-forᴰ (𝒪 X) ℬ↑
   β↑ = pr₂ (spectral-and-small-𝒦-gives-directed-basis X σ 𝕤ₖ)

   κ : consists-of-compact-opens X ℬ↑ holds
   κ []       = 𝟎-is-compact X
   κ (i  is) = compact-opens-are-closed-under-∨
                 X
                 ( [ i ])
                 (ℬ↑ [ is ])
                 (ℬ-consists-of-compact-opens i)
                 (κ is)

   κ₁ : is-compact-open X 𝟏[ 𝒪 X ] holds
   κ₁ = spectral-implies-compact X σ

   τ↑ : contains-top (𝒪 X) ℬ↑ holds
   τ↑ =  (ret (𝟏[ 𝒪 X ] , κ₁)  []) ,  
    where
      : 𝟏[ 𝒪 X ]  ( [ ret (𝟏[ 𝒪 X ] , κ₁) ] ∨[ 𝒪 X ] 𝟎[ 𝒪 X ])
      = 𝟏[ 𝒪 X ]                                    =⟨ q₀ 𝟏[ 𝒪 X ] (pr₁ (pr₁ σ)) ⁻¹ 
          [ ret (𝟏[ 𝒪 X ] , κ₁) ]                   =⟨ 𝟎-left-unit-of-∨ (𝒪 X) ( [ ret (𝟏[ 𝒪 X ] , κ₁) ]) ⁻¹ 
          [ ret (𝟏[ 𝒪 X ] , κ₁) ] ∨[ 𝒪 X ] 𝟎[ 𝒪 X ] 

      : is-top (𝒪 X) ( [ ret (𝟏[ 𝒪 X ] , κ₁) ] ∨[ 𝒪 X ] 𝟎[ 𝒪 X ]) holds
      = transport  -  is-top (𝒪 X) - holds)  (𝟏-is-top (𝒪 X))

   μ : closed-under-binary-meets (𝒪 X)  holds
   μ i j =
     k , transport  -  (- is-glb-of ( [ i ] ,  [ j ])) holds)   
     where
      open Meets  x y  x ≤[ poset-of (𝒪 X) ] y)

      κᵢ : is-compact-open X ( [ i ]) holds
      κᵢ = ℬ-consists-of-compact-opens i

      κⱼ : is-compact-open X ( [ j ]) holds
      κⱼ = ℬ-consists-of-compact-opens j

      κ∧ : is-compact-open X ( [ i ] ∧[ 𝒪 X ]  [ j ]) holds
      κ∧ = binary-coherence X σ ( [ i ]) ( [ j ]) κᵢ κⱼ

      k : 𝒦₀
      k = ret (( [ i ] ∧[ 𝒪 X ]  [ j ]) , κ∧)

       : (( [ i ] ∧[ 𝒪 X ]  [ j ]) is-glb-of ( [ i ] ,  [ j ])) holds
       = (∧[ 𝒪 X ]-lower₁ ( [ i ]) ( [ j ]) , ∧[ 𝒪 X ]-lower₂ ( [ i ]) ( [ j ]))
        ,  (V , p)  ∧[ 𝒪 X ]-greatest ( [ i ]) ( [ j ]) _ (pr₁ p) (pr₂ p))


       :  [ i ] ∧[ 𝒪 X ]  [ j ]   [ k ]
       =  [ i ] ∧[ 𝒪 X ]  [ j ]                          =⟨     
          pr₁ (sec (ret (( [ i ] ∧[ 𝒪 X ]  [ j ]) , κ∧))) =⟨ refl 
           [ k ]                                           
           where
             = pr₁ (from-Σ-= (q ( [ i ] ∧[ 𝒪 X ]  [ j ]) κ∧ ⁻¹))

   μ↑ : closed-under-finite-meets (𝒪 X) ℬ↑ holds
   μ↑ = τ↑ , directify-preserves-closure-under-∧ (𝒪 X)  β μ

\end{code}

\begin{code}

spectralᴰ-implies-small-𝒦 : (X : Locale 𝓤 𝓥 𝓥)  spectralᴰ X  has-small-𝒦 X
spectralᴰ-implies-small-𝒦 {𝓤} {𝓥} X σᴰ = 𝒦-is-small X ( , β) κ ζ
 where
   : Fam 𝓥  𝒪 X 
   = basisₛ X σᴰ

  β : directed-basis-forᴰ (𝒪 X) 
  β = basisₛ-is-directed-basis X σᴰ

  κ : consists-of-compact-opens X  holds
  κ = basisₛ-consists-of-compact-opens X σᴰ

  ζ :  𝒪 X  is-locally 𝓥 small
  ζ = local-smallness X

\end{code}

\begin{code}

is-spectral-with-small-basis : (ua : Univalence) (X : Locale 𝓤 𝓥 𝓥)  Ω (𝓤  𝓥 )
is-spectral-with-small-basis {𝓤} {𝓥} ua X =
 is-spectral X  has-small-𝒦 X , being-small-is-prop ua (𝒦 X) 𝓥

\end{code}

\begin{code}

ssb-implies-spectral : (ua : Univalence) (X : Locale 𝓤 𝓥 𝓥)
                      is-spectral-with-small-basis ua X holds
                      is-spectral X holds
ssb-implies-spectral ua X (σ , _) = σ

smallness-of-𝒦 : (ua : Univalence) (X : Locale 𝓤 𝓥 𝓥)
                is-spectral-with-small-basis ua X holds
                𝒦 X is 𝓥 small
smallness-of-𝒦 ua X (_ , s) = s

ssb-implies-spectralᴰ : (ua : Univalence) (X : Locale 𝓤 𝓥 𝓥)
                       is-spectral-with-small-basis ua X holds
                       spectralᴰ X
ssb-implies-spectralᴰ ua X (σ , 𝕤) = spectral-and-small-𝒦-implies-spectralᴰ X σ 𝕤

spectralᴰ-implies-ssb : (ua : Univalence) (X : Locale 𝓤 𝓥 𝓥)
                       spectralᴰ X  is-spectral-with-small-basis ua X holds
spectralᴰ-implies-ssb ua X σᴰ =
 spectralᴰ-gives-spectrality X σᴰ ,  spectralᴰ-implies-small-𝒦 X σᴰ

\end{code}

\begin{code}

truncated-spectralᴰ-implies-spectral : (ua : Univalence) (X : Locale 𝓤 𝓥 𝓥)
                                       spectralᴰ X   is-spectral X holds
truncated-spectralᴰ-implies-spectral ua X p =
 ∥∥-rec (holds-is-prop (is-spectral X))  p
  where
    : spectralᴰ X  is-spectral X holds
    = pr₁  spectralᴰ-implies-ssb ua X

\end{code}

The split support result:

\begin{code}

truncated-spectralᴰ-implies-spectralᴰ : (ua : Univalence) (X : Locale 𝓤 𝓥 𝓥)
                                        spectralᴰ X   spectralᴰ X
truncated-spectralᴰ-implies-spectralᴰ {𝓤} {𝓥} ua X p =
 spectral-and-small-𝒦-implies-spectralᴰ
  X
  (truncated-spectralᴰ-implies-spectral ua X p)
  
   where
    φ : spectralᴰ X  𝒦 X is 𝓥 small
    φ σᴰ = 𝒦-is-small
            X
            (spectralᴰ-implies-directed-basisᴰ X σᴰ)
            (basisₛ-consists-of-compact-opens X σᴰ)
            (local-smallness X)

     : 𝒦 X is 𝓥 small
     = ∥∥-rec (being-small-is-prop ua (𝒦 X) 𝓥) φ p

\end{code}