--------------------------------------------------------------------------------
title:        Some properties of the terminal locale
author:       Ayberk Tosun
date-started: 2024-03-09
--------------------------------------------------------------------------------

We collect properties of the terminal locale in this module.

Some of the facts below can be derived from general theorems about Stone spaces,
since the terminal locale is a Stone space. At the moment of writing, however,
the machinery for Stone locales needs a bit refactoring so I'm writing these
easy facts directly.

TODO: Refactor the following as to derive them from more general theorems about
Stone spaces.

\begin{code}[hide]

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

open import MLTT.List hiding ([_])
open import MLTT.Spartan hiding (๐Ÿš; โ‚€; โ‚)
open import UF.FunExt
open import UF.PropTrunc
open import UF.Size

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

open import Locales.Clopen pt fe sr
open import Locales.Compactness.Definition pt fe
open import Locales.Frame pt fe
open import Locales.InitialFrame pt fe
open import Locales.Spectrality.SpectralityOfOmega pt fe sr
open import Locales.Stone pt fe sr
open import Locales.StoneImpliesSpectral pt fe sr
open import Locales.ZeroDimensionality pt fe sr
open import Slice.Family
open import UF.Equiv
open import UF.Logic
open import UF.Subsingletons
open import UF.Subsingletons-FunExt
open import UF.SubtypeClassifier

open AllCombinators pt fe
open Locale
open PropositionalTruncation pt hiding (_โˆจ_; โˆจ-elim)

module _ (pe : propext ๐“ค) where

 open Spectrality-of-๐ŸŽ ๐“ค pe

\end{code}

Every compact open of the initial frame is either `โŠค` or `โŠฅ`.

\begin{code}

 compact-opens-are-boolean : (P : ฮฉ ๐“ค)
                          โ†’ is-compact-open (๐ŸLoc pe) P holds
                          โ†’ (ฦŽ K ๊ž‰ ๐Ÿš ๐“ค , P ๏ผ โ„ฌ๐ŸŽ [ K ]) holds
 compact-opens-are-boolean P ฮบ =
  โˆฅโˆฅ-rec
   โˆƒ-is-prop
   ฮณ
   (ฮบ (๐’ฎโ†‘ P)
   (covers-of-directified-basis-are-directed (๐ŸŽ-๐”ฝ๐•ฃ๐•ž pe) โ„ฌ๐ŸŽ โ„ฌ๐ŸŽ-is-basis-for-๐ŸŽ P) cโ‚€)
   where
    S : Fam ๐“ค (๐Ÿš ๐“ค)
    S = prโ‚ (โ„ฌ๐ŸŽ-is-basis-for-๐ŸŽ P)

    c : P ๏ผ โ‹[ ๐’ช (๐ŸLoc pe) ] ๐’ฎโ†‘ P
    c = โ‹[ ๐’ช (๐ŸLoc pe) ]-unique (๐’ฎโ†‘ P) P (prโ‚‚ (โ„ฌ๐ŸŽโ†‘-is-basis P))

    cโ‚€ : (P โ‡’ โ‹[ ๐’ช (๐ŸLoc pe) ] ๐’ฎโ†‘ P) holds
    cโ‚€ = โ‡”-gives-โ‡’
          P
          (โ‹[ ๐’ช (๐ŸLoc pe) ] ๐’ฎโ†‘ P)
          (equal-โŠค-gives-holds _ (๏ผ-gives-โ‡” pe P (โ‹[ ๐’ช (๐ŸLoc pe) ] ๐’ฎโ†‘ P) c))

    open PosetReasoning (poset-of (๐ŸŽ-๐”ฝ๐•ฃ๐•ž pe))

    ฮณ : (ฮฃ bs ๊ž‰ List (P holds) , (P โ‡’ ๐’ฎโ†‘ P [ bs ]) holds)
      โ†’ (ฦŽ K ๊ž‰ ๐Ÿš ๐“ค , P ๏ผ โ„ฌ๐ŸŽ [ K ]) holds
    ฮณ ([]       , ฯ†) = โˆฃ inl โ‹† , fails-gives-equal-โŠฅ pe fe P โ€   โˆฃ
                        where
                         โ€  : ยฌ (P holds)
                         โ€  = ๐Ÿ˜-elim โˆ˜ (๐ŸŽ-is-bottom (๐’ช (๐ŸLoc pe)) โŠฅ) โˆ˜ ฯ†
    ฮณ ((p โˆท _) , ฯ†) = โˆฃ inr โ‹† ,  holds-gives-equal-โŠค pe fe P p โˆฃ

\end{code}

Every compact open of the initial frame is a decidable proposition.

\begin{code}

 compact-implies-boolean : (P : ฮฉ ๐“ค)
                         โ†’ is-compact-open (๐ŸLoc pe) P holds
                         โ†’ is-decidable (P holds)
 compact-implies-boolean P ฮบ =
  โˆฅโˆฅ-rec
   (decidability-of-prop-is-prop fe (holds-is-prop P))
   ฮณ
   (compact-opens-are-boolean P ฮบ)
   where
    ฮณ : ฮฃ b ๊ž‰ ๐Ÿš ๐“ค , P ๏ผ โ„ฌ๐ŸŽ [ b ] โ†’ is-decidable (P holds)
    ฮณ (inl p , q) = inr (equal-โŠฅ-gives-fails P q)
    ฮณ (inr _ , p) = inl (equal-โŠค-gives-holds P p)

\end{code}

The bottom proposition `โŠฅ` is obviously the same thing as the empty join, but
this fact is not a definitional equality.

\begin{code}

 ๐ŸŽ-is-โŠฅ : โŠฅ ๏ผ ๐ŸŽ[ ๐’ช (๐ŸLoc pe) ]
 ๐ŸŽ-is-โŠฅ = โ‡”-gives-๏ผ
           pe
           โŠฅ
           ๐ŸŽ[ ๐’ช (๐ŸLoc pe) ]
           (holds-gives-equal-โŠค pe fe _ ((ฮป ()) , ๐ŸŽ-is-bottom (๐’ช (๐ŸLoc pe)) โŠฅ))

\end{code}

Added on 2024-05-28.

The following is probably written down somewhere else, but this is the right
place for it.

\begin{code}

 binary-join-is-disjunction : (P Q : โŸจ ๐’ช (๐ŸLoc pe) โŸฉ)
                            โ†’ P โˆจ[ ๐ŸŽ-๐”ฝ๐•ฃ๐•ž pe ] Q ๏ผ P โˆจ Q
 binary-join-is-disjunction P Q =
  โ‹[ ๐ŸŽ-๐”ฝ๐•ฃ๐•ž pe ]-unique โ… P , Q โ† (P โˆจ Q) (ฯ… , ฯ†) โปยน
   where
    open Joins (ฮป x y โ†’ x โ‰ค[ poset-of (๐ŸŽ-๐”ฝ๐•ฃ๐•ž pe) ] y)

    ฯ… : ((P โˆจ Q) is-an-upper-bound-of โ… P , Q โ†) holds
    ฯ… โ‚€ p = โˆฃ inl p โˆฃ
    ฯ… โ‚ q = โˆฃ inr q โˆฃ

    ฯ† : ((R , _) : upper-bound โ… P , Q โ†) โ†’ ((P โˆจ Q) โ‡’ R) holds
    ฯ† (R , ฯˆ) = โˆจ-elim P Q R (ฯˆ (inl โ‹†)) (ฯˆ (inr โ‹†))

\end{code}

End of addition

Every compact open of the initial frame is a clopen i.e. is a complemented
proposition.

\begin{code}

 compact-implies-clopen : (P : ฮฉ ๐“ค)
                        โ†’ (is-compact-open (๐ŸLoc pe) P
                        โ‡’ is-clopen (๐’ช (๐ŸLoc pe)) P) holds
 compact-implies-clopen P ฮบ = cases โ€  โ€ก (compact-implies-boolean P ฮบ)
  where
   โ€  : P holds โ†’ is-clopen (๐’ช (๐ŸLoc pe)) P holds
   โ€  p = transport
          (ฮป - โ†’ is-clopen (๐’ช (๐ŸLoc pe)) - holds)
          (holds-gives-equal-โŠค pe fe P p โปยน)
          (๐Ÿ-is-clopen (๐ŸŽ-๐”ฝ๐•ฃ๐•ž pe))

   โ€ก : ยฌ (P holds) โ†’ is-clopen (๐’ช (๐ŸLoc pe)) P holds
   โ€ก ฮฝ = transport
          (ฮป - โ†’ is-clopen (๐’ช (๐ŸLoc pe)) - holds)
          q
          (๐ŸŽ-is-clopen (๐ŸŽ-๐”ฝ๐•ฃ๐•ž pe))
    where
     โ…  = ๐ŸŽ-is-โŠฅ โปยน
     โ…ก = fails-gives-equal-โŠฅ pe fe P ฮฝ โปยน

     q : ๐ŸŽ[ ๐’ช (๐ŸLoc pe) ] ๏ผ P
     q = ๐ŸŽ[ ๐’ช (๐ŸLoc pe) ] ๏ผโŸจ โ…  โŸฉ โŠฅ ๏ผโŸจ โ…ก โŸฉ P โˆŽ

\end{code}

Every decidable proposition of `ฮฉ` is a compact open of the initial frame.

\begin{code}

 decidable-implies-compact : (P : ฮฉ ๐“ค)
                           โ†’ is-decidable (P holds)
                           โ†’ is-compact-open (๐ŸLoc pe) P holds
 decidable-implies-compact P (inl p) = transport
                                        (ฮป - โ†’ is-compact-open (๐ŸLoc pe) - holds)
                                        (holds-gives-equal-โŠค pe fe P p โปยน)
                                        (๐ŸŽFrm-is-compact ๐“ค pe)
 decidable-implies-compact P (inr ฮฝ) =
  transport (ฮป - โ†’ is-compact-open (๐ŸLoc pe) - holds) โ€  (๐ŸŽ-is-compact (๐ŸLoc pe))
   where
    โ…  = ๐ŸŽ-is-โŠฅ โปยน
    โ…ก = fails-gives-equal-โŠฅ pe fe P ฮฝ โปยน

    โ€  : ๐ŸŽ[ ๐’ช (๐ŸLoc pe) ] ๏ผ P
    โ€  = ๐ŸŽ[ ๐’ช (๐ŸLoc pe) ] ๏ผโŸจ โ…  โŸฉ โŠฅ ๏ผโŸจ โ…ก โŸฉ P โˆŽ

\end{code}

Every clopen of the terminal locale is a compact open.

\begin{code}

 clopen-implies-compact : (P : ฮฉ ๐“ค)
                        โ†’ (is-clopen (๐’ช (๐ŸLoc pe)) P โ‡’ is-compact-open (๐ŸLoc pe) P)
                           holds
 clopen-implies-compact P ๐”  =
  clopens-are-compact-in-compact-locales (๐ŸLoc pe) (๐ŸŽFrm-is-compact ๐“ค pe) P ๐” 

\end{code}

The type of compact opens of the terminal locale is equivalent to its type of
clopens.

\begin{code}

 clopen-equiv-compact : ๐’ฆ (๐ŸLoc pe) โ‰ƒ ๐’ž (๐ŸLoc pe)
 clopen-equiv-compact = g , (h ,  โ€ ) , h , โ€ก
  where
   g : ๐’ฆ (๐ŸLoc pe) โ†’ ๐’ž (๐ŸLoc pe)
   g (K , ฮบ) = K , compact-implies-clopen K ฮบ

   h : ๐’ž (๐ŸLoc pe) โ†’ ๐’ฆ (๐ŸLoc pe)
   h (K , ๐” ) = K , clopen-implies-compact K ๐” 

   โ€  : (g โˆ˜ h) โˆผ id
   โ€  U = to-subtype-๏ผ (holds-is-prop โˆ˜ is-clopen (๐’ช (๐ŸLoc pe))) refl

   โ€ก : (h โˆ˜ g) โˆผ id
   โ€ก U = to-subtype-๏ผ (holds-is-prop โˆ˜ is-compact-open (๐ŸLoc pe)) refl

\end{code}

The type of clopens of the terminal locale is equivalent to the type of
decidable propositions

\begin{code}

 clopen-equiv-decidable : ๐’ž (๐ŸLoc pe) โ‰ƒ (ฮฃ P ๊ž‰ ฮฉ ๐“ค , is-decidable (P holds))
 clopen-equiv-decidable = g , (h , โ€ก) , h , โ€ 
  where
   g : ๐’ž (๐ŸLoc pe) โ†’ ฮฃ P ๊ž‰ ฮฉ ๐“ค , is-decidable (P holds)
   g (K , ๐” ) = K , compact-implies-boolean K (clopen-implies-compact K ๐” )

   h : (ฮฃ P ๊ž‰ ฮฉ ๐“ค , is-decidable (P holds)) โ†’ ๐’ž (๐ŸLoc pe)
   h (K , ฮบ) = K , compact-implies-clopen K (decidable-implies-compact K ฮบ)

   โ€  : (h โˆ˜ g) โˆผ id
   โ€  U =
    to-subtype-๏ผ (holds-is-prop โˆ˜ is-clopen (๐’ช (๐ŸLoc pe))) refl

   โ€ก : (g โˆ˜ h) โˆผ id
   โ€ก (P , _) =
    to-subtype-๏ผ (ฮป Q โ†’ decidability-of-prop-is-prop fe (holds-is-prop Q)) refl

\end{code}

Added on 2024-08-05.

\begin{code}

 โ„ฌ๐ŸŽ-consists-of-clopens : consists-of-clopens (๐’ช (๐ŸLoc pe)) โ„ฌ๐ŸŽ holds
 โ„ฌ๐ŸŽ-consists-of-clopens (inl โ‹†) =
  transport (ฮป - โ†’ is-clopen (๐’ช (๐ŸLoc pe)) - holds) (p โปยน) โ€ 
   where
    p : โŠฅ ๏ผ ๐ŸŽ[ ๐’ช (๐ŸLoc pe) ]
    p = ๐ŸŽ-is-โŠฅ

    โ€  : is-clopen (๐’ช (๐ŸLoc pe)) ๐ŸŽ[ ๐’ช (๐ŸLoc pe) ] holds
    โ€  = ๐ŸŽ-is-clopen (๐’ช (๐ŸLoc pe))
 โ„ฌ๐ŸŽ-consists-of-clopens (inr โ‹†) =
  ๐Ÿ-is-clopen (๐’ช (๐ŸLoc pe))

 โ„ฌ๐ŸŽโ†‘-consists-of-clopens : consists-of-clopens (๐’ช (๐ŸLoc pe)) โ„ฌ๐ŸŽโ†‘ holds
 โ„ฌ๐ŸŽโ†‘-consists-of-clopens []       = ๐ŸŽ-is-clopen (๐’ช (๐ŸLoc pe))
 โ„ฌ๐ŸŽโ†‘-consists-of-clopens (i โˆท is) =
  clopens-are-closed-under-โˆจ (๐’ช (๐ŸLoc pe)) (โ„ฌ๐ŸŽ [ i ]) (โ„ฌ๐ŸŽโ†‘ [ is ]) โ€  โ€ก
   where
    โ€  : is-clopen (๐’ช (๐ŸLoc pe)) (โ„ฌ๐ŸŽ [ i ]) holds
    โ€  = โ„ฌ๐ŸŽ-consists-of-clopens i

    โ€ก : is-clopen (๐’ช (๐ŸLoc pe)) (โ„ฌ๐ŸŽโ†‘ [ is ]) holds
    โ€ก = โ„ฌ๐ŸŽโ†‘-consists-of-clopens is

 ๐Ÿ-zero-dimensionalแดฐ : zero-dimensionalแดฐ (๐’ช (๐ŸLoc pe))
 ๐Ÿ-zero-dimensionalแดฐ = โ„ฌ๐ŸŽโ†‘
                     , prโ‚‚ (โ„ฌ๐ŸŽโ†‘-directed-basisแดฐ ๐“ค pe)
                     , โ„ฌ๐ŸŽโ†‘-consists-of-clopens

\end{code}

Added on 2024-08-10.

\begin{code}

 ๐Ÿ-stoneแดฐ : stoneแดฐ (๐ŸLoc pe)
 ๐Ÿ-stoneแดฐ = ๐ŸŽFrm-is-compact ๐“ค pe , ๐Ÿ-zero-dimensionalแดฐ

 ๐Ÿ-is-stone : is-stone (๐ŸLoc pe) holds
 ๐Ÿ-is-stone = ๐ŸŽFrm-is-compact ๐“ค pe
            , โˆฃ ๐Ÿ-zero-dimensionalแดฐ โˆฃ

\end{code}