{-# OPTIONS --cubical --safe #-}

module CoverFormsNucleus where

open import Basis          hiding (A) renaming (squash to squashβ€²)
open import Poset
open import Frame
open import Cover
open import Nucleus           using    (isNuclear; Nucleus; 𝔣𝔦𝔡; idem)
open import Cubical.Data.Bool using    (Bool; true; false)
open import FormalTopology    renaming (pos to posβ€²)

We use a module that takes some formal topology F as a parameter to reduce parameter-passing.

module NucleusFrom (β„± : FormalTopology β„“β‚€ β„“β‚€) where

We refer to the underlying poset of F as P and the frame of downwards-closed subsets of P as P↓.

  private
    P       = posβ€² β„±
    P↓      = DCFrame P
    _βŠ‘_     = Ξ» (x y : stage β„±) β†’ x βŠ‘[ P ] y

  open CoverFromFormalTopology β„± public

Now, we define the covering nucleus which we denote by 𝕛. At its heart, this is nothing but the map U ↦ - ◁ U.

  𝕛 : ∣ P↓ ∣F β†’ ∣ P↓ ∣F
  𝕛 (U , U-down) = (Ξ» - β†’ U β–· -) , Uβ–·-dc
    where
      -- This is not propositional unless we force it to be using the HIT definition!
      _β–·_ : 𝒫 ∣ P βˆ£β‚š β†’ 𝒫 ∣ P βˆ£β‚š
      U β–· a = a ◁ U , squash

      Uβ–·-dc : [ isDownwardsClosed P (Ξ» - β†’ (- ◁ U) , squash) ]
      Uβ–·-dc a aβ‚€ aΞ΅U₁ aβ‚€βŠ‘a = ◁-lem₁ U-down aβ‚€βŠ‘a aΞ΅U₁

  𝕛-nuclear : isNuclear P↓ 𝕛
  𝕛-nuclear = Nβ‚€ , N₁ , Nβ‚‚
    where
      -- We reason by antisymmetry and prove in (d) 𝕛 (aβ‚€ βŠ“ a₁) βŠ‘ (𝕛 aβ‚€) βŠ“ (𝕛 a₁) and
      -- in (u) (𝕛 aβ‚€) βŠ“ (𝕛 a₁) βŠ‘ 𝕛 (aβ‚€ βŠ“ a₁).
      Nβ‚€ : (π”˜ 𝔙 : ∣ P↓ ∣F) β†’ 𝕛 (π”˜ βŠ“[ P↓ ] 𝔙) ≑ (𝕛 π”˜) βŠ“[ P↓ ] (𝕛 𝔙)
      Nβ‚€ π•Œ@(U , U-down) 𝕍@(V , V-down) =
        βŠ‘[ pos P↓ ]-antisym (𝕛 (π•Œ βŠ“[ P↓ ] 𝕍)) (𝕛 π•Œ βŠ“[ P↓ ] 𝕛 𝕍) down up
        where
          down : [ (𝕛 (π•Œ βŠ“[ P↓ ] 𝕍)) βŠ‘[ pos P↓ ] (𝕛 π•Œ βŠ“[ P↓ ] 𝕛 𝕍) ]
          down a p = (◁-lemβ‚„ (U ∩ V) U (Ξ» { u (u∈U , u∈V) β†’ dir u∈U }) a p)
                   , (◁-lemβ‚„ (U ∩ V) V (Ξ» { u (u∈U , u∈V) β†’ dir u∈V }) a p)

          up : [ (𝕛 π•Œ βŠ“[ P↓ ] 𝕛 𝕍) βŠ‘[ pos P↓ ] 𝕛 (π•Œ βŠ“[ P↓ ] 𝕍) ]
          up a (a◁U , a◁V) = ◁-lem₃ V U V-down U-down (βŠ‘[ P ]-refl a) a◁V a◁U

      N₁ : (π”˜ : ∣ P↓ ∣F) β†’ [ π”˜ βŠ‘[ pos P↓ ] (𝕛 π”˜) ]
      N₁ _ aβ‚€ a∈U = dir a∈U

      Nβ‚‚ : (π”˜ : ∣ P↓ ∣F) β†’ [ Ο€β‚€ (𝕛 (𝕛 π”˜)) βŠ† Ο€β‚€ (𝕛 π”˜) ]
      Nβ‚‚ π”˜@(U , _) = ◁-lemβ‚„ (Ο€β‚€ (𝕛 π”˜)) U (Ξ» _ q β†’ q)

We denote by L the frame of fixed points for 𝕛.

  L : Frame (β„“-suc β„“β‚€) β„“β‚€ β„“β‚€
  L = 𝔣𝔦𝔡 P↓ (𝕛 , 𝕛-nuclear)

The following is a just a piece of convenient notation for projecting out the underlying set of a downwards-closed subset equipped with the information that it is a fixed point for 𝕛.

  β¦…_⦆ : ∣ L ∣F β†’ 𝒫 ∣ P βˆ£β‚š
  β¦… ((U , _) , _) ⦆ = U

Given some x in F, we define a map taking x to its downwards-closure.

  ↓-clos : stage β„± β†’ ∣ P↓ ∣F
  ↓-clos x = x↓ , down-DC
    where
      x↓ = Ξ» y β†’ y βŠ‘[ P ] x
      down-DC : [ isDownwardsClosed P x↓ ]
      down-DC z y zβŠ‘x yβŠ‘z = βŠ‘[ P ]-trans y z x yβŠ‘z zβŠ‘x

  x◁x↓ : (x : stage β„±) β†’ x ◁ (Ξ» - β†’ - βŠ‘[ P ] x)
  x◁x↓ x = dir (βŠ‘[ P ]-refl x)

By composing this with the covering nucleus, we define a map e from F to P↓.

  e : ∣ P βˆ£β‚š β†’ ∣ P↓ ∣F
  e z = (Ξ» a β†’ (a ◁ (Ο€β‚€ (↓-clos z))) , squash) , NTS
    where
      NTS : [ isDownwardsClosed P (Ξ» a β†’ (a ◁ (Ξ» - β†’ - βŠ‘[ P ] z)) , squash) ]
      NTS _ _ x y = ◁-lem₁ (Ξ» _ _ xβŠ‘y yβŠ‘z β†’ βŠ‘[ P ]-trans _ _ z yβŠ‘z xβŠ‘y) y x

We can further refine the codomain of e to L. In other words, we can prove that j (e x) = e x for every x. We call the version e with the refined codomain Ξ·.

  fixing : (x : ∣ P βˆ£β‚š) β†’ 𝕛 (e x) ≑ e x
  fixing x = βŠ‘[ pos P↓ ]-antisym (𝕛 (e x)) (e x) down up
    where
      down : βˆ€ y β†’ [ Ο€β‚€ (𝕛 (e x)) y ] β†’ [ Ο€β‚€ (e x) y ]
      down = ◁-lemβ‚„ (Ο€β‚€ (e x)) (Ο€β‚€ (↓-clos x)) (Ξ» _ q β†’ q)

      up : [ e x βŠ‘[ pos P↓ ] 𝕛 (e x) ]
      up = Ο€β‚€ (π₁ 𝕛-nuclear) (e x)

  Ξ· : stage β„± β†’ ∣ L ∣F
  Ξ· x = e x , fixing x

Furthermore, Ξ· is a monotonic map.

  Ξ·m : P ─mβ†’ pos L
  Ξ·m = Ξ· , Ξ·-mono
    where
      Ξ·-mono : isMonotonic P (pos L) Ξ·
      Ξ·-mono x y xβŠ‘y = ◁-lemβ‚„ (Ο€β‚€ (↓-clos x)) (Ο€β‚€ (↓-clos y)) NTS
        where
          NTS : (u : ∣ P βˆ£β‚š) β†’ [ u ∈ Ο€β‚€ (↓-clos x) ] β†’ u ◁ Ο€β‚€ (↓-clos y)
          NTS _ p = ◁-lem₁ (π₁ (↓-clos y)) p (dir xβŠ‘y)