Ayberk Tosun, 13 September 2023

\begin{code}

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

open import MLTT.Spartan hiding (𝟚)
open import MLTT.List hiding ([_])
open import UF.PropTrunc
open import UF.FunExt
open import UF.Size

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

\end{code}

Importation of foundational UF stuff.

\begin{code}

open import Slice.Family
open import UF.SubtypeClassifier
open import UF.Logic

open AllCombinators pt fe
open PropositionalTruncation pt

\end{code}

Importations of other locale theory modules.

\begin{code}

open import Locales.Clopen                      pt fe sr
open import Locales.Compactness.Definition      pt fe
open import Locales.Frame                       pt fe
open import Locales.GaloisConnection            pt fe
open import Locales.WayBelowRelation.Definition pt fe
open import Locales.WellInside                  pt fe sr

open Locale

\end{code}

Definition of regularity of a frame.

\begin{code}

is-regularβ‚€ : (F : Frame 𝓀 π“₯ 𝓦) β†’ (𝓀 βŠ” π“₯ βŠ” 𝓦 ⁺) Μ‡
is-regularβ‚€ {𝓀 = 𝓀} {π“₯} {𝓦} F =
 let
  open Joins (Ξ» U V β†’ U ≀[ poset-of F ] V)

  P : Fam 𝓦 ⟨ F ⟩ β†’ 𝓀 βŠ” π“₯ βŠ” 𝓦 ⁺ Μ‡
  P ℬ = Ξ  U κž‰ ⟨ F ⟩ ,
         Ξ£ J κž‰ Fam 𝓦 (index ℬ) ,
            (U is-lub-of ⁅ ℬ [ j ] ∣ j Ξ΅ J ⁆) holds
          Γ— (Ξ  i κž‰ index J , (ℬ [ J [ i ] ] β‹œ[ F ] U) holds)
 in
  Ξ£ ℬ κž‰ Fam 𝓦 ⟨ F ⟩ , P ℬ

\end{code}

\begin{code}

is-regular : (F : Frame 𝓀 π“₯ 𝓦) β†’ Ξ© (𝓀 βŠ” π“₯ βŠ” 𝓦 ⁺)
is-regular {𝓀 = 𝓀} {π“₯} {𝓦} F = βˆ₯ is-regularβ‚€ F βˆ₯Ξ©

\end{code}

\begin{code}

is-regular-basis : (F : Frame 𝓀 π“₯ 𝓦)
                 β†’ (ℬ : Fam 𝓦 ⟨ F ⟩) β†’ (Ξ² : is-basis-for F ℬ) β†’ Ξ© (𝓀 βŠ” 𝓦)
is-regular-basis F ℬ Ξ² =
 β±― U κž‰ ⟨ F ⟩ , let π’₯ = pr₁ (Ξ² U) in β±― j κž‰ (index π’₯) , ℬ [ π’₯ [ j ] ] β‹œ[ F ] U

\end{code}

\begin{code}

𝟎-is-well-inside-anything : (F : Frame 𝓀 π“₯ 𝓦) (U : ⟨ F ⟩)
                          β†’ (𝟎[ F ] β‹œ[ F ] U) holds
𝟎-is-well-inside-anything F U =
 ↑↑-is-upwards-closed F ∣ 𝟎-is-clopen F ∣ (𝟎-is-bottom F U)

well-inside-is-join-stable : (F : Frame 𝓀 π“₯ 𝓦) {U₁ Uβ‚‚ V : ⟨ F ⟩}
                           β†’ (U₁ β‹œ[ F ] V) holds
                           β†’ (Uβ‚‚ β‹œ[ F ] V) holds
                           β†’ ((U₁ ∨[ F ] Uβ‚‚) β‹œ[ F ] V) holds
well-inside-is-join-stable F {U₁} {Uβ‚‚} {V} =
 βˆ₯βˆ₯-recβ‚‚ (holds-is-prop ((U₁ ∨[ F ] Uβ‚‚) β‹œ[ F ] V)) Ξ³
  where
   open PosetReasoning (poset-of F)

   Ξ³ : U₁ β‹œβ‚€[ F ] V β†’ Uβ‚‚ β‹œβ‚€[ F ] V β†’ ((U₁ ∨[ F ] Uβ‚‚) β‹œ[ F ] V) holds
   Ξ³ (W₁ , c₁ , d₁) (Wβ‚‚ , cβ‚‚ , dβ‚‚) = ∣ (W₁ ∧[ F ] Wβ‚‚) , c , d ∣
    where
     Ξ΄ : (W₁ ∧[ F ] Wβ‚‚) ∧[ F ] Uβ‚‚ = 𝟎[ F ]
     Ξ΄ = (W₁ ∧[ F ] Wβ‚‚) ∧[ F ] Uβ‚‚  =⟨ (∧[ F ]-is-associative W₁ Wβ‚‚ Uβ‚‚) ⁻¹ ⟩
         W₁ ∧[ F ] (Wβ‚‚ ∧[ F ] Uβ‚‚)  =⟨ †                                   ⟩
         W₁ ∧[ F ] (Uβ‚‚ ∧[ F ] Wβ‚‚)  =⟨ ap (Ξ» - β†’ meet-of F W₁ -) cβ‚‚        ⟩
         W₁ ∧[ F ] 𝟎[ F ]          =⟨ 𝟎-right-annihilator-for-∧ F W₁      ⟩
         𝟎[ F ]                    ∎
          where
           † = ap (Ξ» - β†’ W₁ ∧[ F ] -) (∧[ F ]-is-commutative Wβ‚‚ Uβ‚‚)

     Ξ΅ : ((W₁ ∧[ F ] Wβ‚‚) ∧[ F ] U₁) = 𝟎[ F ]
     Ξ΅ = (W₁ ∧[ F ] Wβ‚‚) ∧[ F ] U₁  =⟨ †                                   ⟩
         (Wβ‚‚ ∧[ F ] W₁) ∧[ F ] U₁  =⟨ (∧[ F ]-is-associative Wβ‚‚ W₁ U₁) ⁻¹ ⟩
         Wβ‚‚ ∧[ F ] (W₁ ∧[ F ] U₁)  =⟨ ‑                                   ⟩
         Wβ‚‚ ∧[ F ] (U₁ ∧[ F ] W₁)  =⟨ ap (Ξ» - β†’ Wβ‚‚ ∧[ F ] -) c₁           ⟩
         Wβ‚‚ ∧[ F ] 𝟎[ F ]          =⟨ 𝟎-right-annihilator-for-∧ F Wβ‚‚      ⟩
         𝟎[ F ]                    ∎
          where
           † = ap (Ξ» - β†’ - ∧[ F ] U₁) (∧[ F ]-is-commutative W₁ Wβ‚‚)
           ‑ = ap (Ξ» - β†’ Wβ‚‚ ∧[ F ] -) (∧[ F ]-is-commutative W₁ U₁)

     c : ((U₁ ∨[ F ] Uβ‚‚) ∧[ F ] (W₁ ∧[ F ] Wβ‚‚)) = 𝟎[ F ]
     c = (U₁ ∨[ F ] Uβ‚‚) ∧[ F ] (W₁ ∧[ F ] Wβ‚‚)                          =⟨ i    ⟩
         (W₁ ∧[ F ] Wβ‚‚) ∧[ F ] (U₁ ∨[ F ] Uβ‚‚)                          =⟨ ii   ⟩
         ((W₁ ∧[ F ] Wβ‚‚) ∧[ F ] U₁) ∨[ F ] ((W₁ ∧[ F ] Wβ‚‚) ∧[ F ] Uβ‚‚)  =⟨ iii  ⟩
         ((W₁ ∧[ F ] Wβ‚‚) ∧[ F ] U₁) ∨[ F ] 𝟎[ F ]                      =⟨ iv   ⟩
         (W₁ ∧[ F ] Wβ‚‚) ∧[ F ] U₁                                      =⟨ Ξ΅    ⟩
         𝟎[ F ]                                                        ∎
          where
           i   = ∧[ F ]-is-commutative (U₁ ∨[ F ] Uβ‚‚) (W₁ ∧[ F ] Wβ‚‚)
           ii  = binary-distributivity F (W₁ ∧[ F ] Wβ‚‚) U₁ Uβ‚‚
           iii = ap (Ξ» - β†’ ((W₁ ∧[ F ] Wβ‚‚) ∧[ F ] U₁) ∨[ F ] -) Ξ΄
           iv  = 𝟎-left-unit-of-∨ F ((W₁ ∧[ F ] Wβ‚‚) ∧[ F ] U₁)

     d : V ∨[ F ] (W₁ ∧[ F ] Wβ‚‚) = 𝟏[ F ]
     d = V ∨[ F ] (W₁ ∧[ F ] Wβ‚‚)            =⟨ i   ⟩
         (V ∨[ F ] W₁) ∧[ F ] (V ∨[ F ] Wβ‚‚) =⟨ ii  ⟩
         𝟏[ F ] ∧[ F ] (V ∨[ F ] Wβ‚‚)        =⟨ iii ⟩
         𝟏[ F ] ∧[ F ] 𝟏[ F ]               =⟨ iv  ⟩
         𝟏[ F ] ∎
          where
           i   = binary-distributivity-op F V W₁ Wβ‚‚
           ii  = ap (Ξ» - β†’ - ∧[ F ] (V ∨[ F ] Wβ‚‚)) d₁
           iii = ap (Ξ» - β†’ 𝟏[ F ] ∧[ F ] -) dβ‚‚
           iv  = 𝟏-right-unit-of-∧ F 𝟏[ F ]


directification-preserves-regularity : (F : Frame 𝓀 π“₯ 𝓦)
                                     β†’ (ℬ : Fam 𝓦 ⟨ F ⟩)
                                     β†’ (Ξ² : is-basis-for F ℬ)
                                     β†’ is-regular-basis F ℬ Ξ² holds
                                     β†’ let
                                        ℬ↑ = directify F ℬ
                                        β↑ = directified-basis-is-basis F ℬ Ξ²
                                       in
                                        is-regular-basis F ℬ↑ β↑ holds
directification-preserves-regularity F ℬ Ξ² r U = Ξ³
 where
  ℬ↑ = directify F ℬ
  β↑ = directified-basis-is-basis F ℬ Ξ²

  π’₯  = pr₁ (Ξ² U)
  π’₯↑ = pr₁ (β↑ U)

  Ξ³ : (β±― js κž‰ index π’₯↑ , ℬ↑ [ π’₯↑ [ js ] ] β‹œ[ F ] U) holds
  γ []       = 𝟎-is-well-inside-anything F U
  γ (j ∷ js) = well-inside-is-join-stable F (r U j) (γ js)

β‰ͺ-implies-β‹œ-in-regular-frames : (F : Frame 𝓀 π“₯ 𝓦)
                              β†’ (is-regular F) holds
                              β†’ (U V : ⟨ F ⟩)
                              β†’ (U β‰ͺ[ F ] V β‡’ U β‹œ[ F ] V) holds
β‰ͺ-implies-β‹œ-in-regular-frames {𝓦 = 𝓦} F r U V =
 βˆ₯βˆ₯-rec (holds-is-prop (U β‰ͺ[ F ] V β‡’ U β‹œ[ F ] V)) Ξ³ r
  where
   Ξ³ : is-regularβ‚€ F β†’ (U β‰ͺ[ F ] V β‡’ U β‹œ[ F ] V) holds
   Ξ³ (ℬ , Ξ΄) ΞΊ = βˆ₯βˆ₯-rec (holds-is-prop (U β‹œ[ F ] V)) ΞΆ (ΞΊ S Ξ΅ c)
    where
     ℬ↑ : Fam 𝓦 ⟨ F ⟩
     ℬ↑ = directify F ℬ

     Ξ² : is-basis-for F ℬ
     Ξ² U = pr₁ (Ξ΄ U) , pr₁ (prβ‚‚ (Ξ΄ U))

     β↑ : is-basis-for F ℬ↑
     β↑ = directified-basis-is-basis F ℬ Ξ²

     ρ : is-regular-basis F ℬ Ξ² holds
     ρ U = prβ‚‚ (prβ‚‚ (Ξ΄ U))

     ρ↑ : is-regular-basis F ℬ↑ β↑ holds
     ρ↑ =  directification-preserves-regularity F ℬ Ξ² ρ

     π’₯ : Fam 𝓦 (index ℬ↑)
     π’₯ = pr₁ (β↑ V)

     S : Fam 𝓦 ⟨ F ⟩
     S = ⁅ ℬ↑ [ i ] ∣ i Ξ΅ π’₯ ⁆

     Ξ΅ : is-directed F S holds
     Ξ΅ = covers-of-directified-basis-are-directed F ℬ Ξ² V

     c : (V ≀[ poset-of F ] (⋁[ F ] S)) holds
     c = reflexivity+ (poset-of F) (⋁[ F ]-unique S V (prβ‚‚ (β↑ V)))

     ΞΆ : Ξ£ k κž‰ index S , (U ≀[ poset-of F ] (S [ k ])) holds β†’ (U β‹œ[ F ] V) holds
     ΞΆ (k , q) = ↓↓-is-downwards-closed F (ρ↑ V k) q

\end{code}

\begin{code}

compacts-are-clopen-in-regular-frames : (X : Locale 𝓀 π“₯ 𝓦)
                                      β†’ is-regular (π’ͺ X) holds
                                      β†’ (β±― U κž‰ ⟨ π’ͺ X ⟩ ,
                                          is-compact-open X U β‡’ is-clopen (π’ͺ X) U) holds
compacts-are-clopen-in-regular-frames X r U =
 well-inside-itself-implies-clopen X U ∘ β‰ͺ-implies-β‹œ-in-regular-frames (π’ͺ X) r U U

\end{code}