--------------------------------------------------------------------------------
title:          Lattice homomorphism given by a spectral map
author:         Ayberk Tosun
date-started:   2024-03-03
date-completed: 2024-03-04
--------------------------------------------------------------------------------

Any spectral map `f : X β†’ Y` of spectral locales gives a lattice homomorphism
`𝒦(Y) β†’ 𝒦(X)`. We prove this fact in this module.

\begin{code}

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

open import MLTT.Spartan
open import UF.FunExt
open import UF.Logic
open import UF.PropTrunc
open import UF.Size
open import UF.SubtypeClassifier
open import UF.UA-FunExt
open import UF.Univalence

module Locales.Spectrality.SpectralMapToLatticeHomomorphism
        (ua : Univalence)
        (pt : propositional-truncations-exist)
        (sr : Set-Replacement pt)
       where

fe : Fun-Ext
fe {𝓀} {π“₯} = univalence-gives-funext' 𝓀 π“₯ (ua 𝓀) (ua (𝓀 βŠ” π“₯))

open import Locales.Compactness.Definition pt fe
open import Locales.ContinuousMap.Definition pt fe
open import Locales.ContinuousMap.FrameHomomorphism-Definition pt fe
open import Locales.ContinuousMap.FrameHomomorphism-Properties pt fe
open import Locales.DistributiveLattice.Homomorphism fe pt
open import Locales.Frame pt fe
open import Locales.SmallBasis pt fe sr
open import Locales.Spectrality.LatticeOfCompactOpens ua pt sr
open import Locales.Spectrality.SpectralLocale pt fe
open import Locales.Spectrality.SpectralMap pt fe

open AllCombinators pt fe
open ContinuousMaps
open FrameHomomorphismProperties
open FrameHomomorphisms
open Locale
open PropositionalTruncation pt

\end{code}

We fix large and locally small locales `X` and `Y` which we assume to be
spectral. We also fix a spectral map `f : X β†’ Y`.

\begin{code}

module FunctorialAction
        (X  : Locale (𝓀 ⁺) 𝓀 𝓀)
        (Y  : Locale (𝓀 ⁺) 𝓀 𝓀)
        (σ₁ : is-spectral-with-small-basis ua X holds)
        (Οƒβ‚‚ : is-spectral-with-small-basis ua Y holds)
        (f  : X ─cβ†’ Y)
        (𝕀  : is-spectral-map Y X f holds)
       where

\end{code}

We denote by `𝒦⦅X⦆` and `𝒦⦅Y⦆` the distributive lattices of compact opens of
locales `X` and `Y` respectively.

\begin{code}

 open ContinuousMapNotation X Y
 open 𝒦-Lattice X σ₁ renaming (πŸβ‚– to πŸβ‚–-X;
                               𝟏-is-compact to 𝟏-X-is-compact)
 open 𝒦-Lattice Y Οƒβ‚‚ renaming (πŸβ‚– to πŸβ‚–-Y;
                               𝒦⦅X⦆ to 𝒦⦅Y⦆;
                               𝟏-is-compact to 𝟏-Y-is-compact)
 open OperationsOnCompactOpens X (pr₁ σ₁) renaming (_βˆ¨β‚–_ to _βˆ¨β‚‚_; _βˆ§β‚–_ to _βˆ§β‚‚_)
 open OperationsOnCompactOpens Y (pr₁ Οƒβ‚‚) renaming (_βˆ¨β‚–_ to _βˆ¨β‚_; _βˆ§β‚–_ to _βˆ§β‚_)

\end{code}

We denote by `𝒦-mapβ‚€` the underlying function of the lattice homomorphism
between the lattices of compact opens.

\begin{code}

 𝒦-mapβ‚€ : 𝒦 Y β†’ 𝒦 X
 𝒦-mapβ‚€ (K , ΞΊ) = f β‹†βˆ™ K , 𝕀 K ΞΊ

\end{code}

The proof that this is a lattice homomorphism is easy.

\begin{code}

 𝒦-mapβ‚€-preserves-𝟎 : 𝒦-mapβ‚€ πŸŽβ‚–[ Y  ] = πŸŽβ‚–[ X ]
 𝒦-mapβ‚€-preserves-𝟎 =
  to-𝒦-=
   X
   (𝕀 𝟎[ π’ͺ Y ] (𝟎-is-compact Y))
   (𝟎-is-compact X)
   (frame-homomorphisms-preserve-bottom (π’ͺ Y) (π’ͺ X) f)

 𝒦-mapβ‚€-preserves-𝟏 : 𝒦-mapβ‚€ πŸβ‚–-Y = πŸβ‚–-X
 𝒦-mapβ‚€-preserves-𝟏 =
  to-𝒦-=
   X
   (𝕀 𝟏[ π’ͺ Y ] 𝟏-Y-is-compact)
   𝟏-X-is-compact
   (frame-homomorphisms-preserve-top (π’ͺ Y) (π’ͺ X) f)

 𝒦-mapβ‚€-preserves-∨ : (K₁ Kβ‚‚ : 𝒦 Y) β†’ 𝒦-mapβ‚€ (K₁ βˆ¨β‚ Kβ‚‚) = 𝒦-mapβ‚€ K₁ βˆ¨β‚‚ 𝒦-mapβ‚€ Kβ‚‚
 𝒦-mapβ‚€-preserves-∨ π”Žβ‚@(K₁ , κ₁) π”Žβ‚‚@(Kβ‚‚ , ΞΊβ‚‚) =
  to-𝒦-= X (𝕀 (K₁ ∨[ π’ͺ Y ] Kβ‚‚) ΞΊ) ΞΊβ€² †
   where
    ΞΊ : is-compact-open Y (K₁ ∨[ π’ͺ Y ] Kβ‚‚) holds
    ΞΊ = compact-opens-are-closed-under-∨ Y K₁ Kβ‚‚ κ₁ ΞΊβ‚‚

    ΞΊβ€² : is-compact-open X (f β‹†βˆ™ K₁ ∨[ π’ͺ X ] f β‹†βˆ™ Kβ‚‚) holds
    ΞΊβ€² = compact-opens-are-closed-under-∨ X (f β‹†βˆ™ K₁) (f β‹†βˆ™ Kβ‚‚) (𝕀 K₁ κ₁) (𝕀 Kβ‚‚ ΞΊβ‚‚)

    † : f β‹†βˆ™ (K₁ ∨[ π’ͺ Y ] Kβ‚‚) = f β‹†βˆ™ K₁ ∨[ π’ͺ X ] f β‹†βˆ™ Kβ‚‚
    † = frame-homomorphisms-preserve-binary-joins (π’ͺ Y) (π’ͺ X) f K₁ Kβ‚‚

 𝒦-mapβ‚€-preserves-∧ : (K₁ Kβ‚‚ : 𝒦 Y) β†’ 𝒦-mapβ‚€ (K₁ βˆ§β‚ Kβ‚‚) = 𝒦-mapβ‚€ K₁ βˆ§β‚‚ 𝒦-mapβ‚€ Kβ‚‚
 𝒦-mapβ‚€-preserves-∧ (K₁ , κ₁) (Kβ‚‚ , ΞΊβ‚‚) =
  to-𝒦-= X (𝕀 (K₁ ∧[ π’ͺ Y ] Kβ‚‚) ΞΊ) ΞΊβ€² †
   where
    ΞΊ : is-compact-open Y (K₁ ∧[ π’ͺ Y ] Kβ‚‚) holds
    ΞΊ = binary-coherence Y (ssb-implies-spectral ua Y Οƒβ‚‚) K₁ Kβ‚‚ κ₁ ΞΊβ‚‚

    ΞΊβ€² : is-compact-open X (f β‹†βˆ™ K₁ ∧[ π’ͺ X ] f β‹†βˆ™ Kβ‚‚) holds
    ΞΊβ€² = binary-coherence
          X
          (ssb-implies-spectral ua X σ₁)
          (f β‹†βˆ™ K₁)
          (f β‹†βˆ™ Kβ‚‚)
          (𝕀 K₁ κ₁)
          (𝕀 Kβ‚‚ ΞΊβ‚‚)

    † : f β‹†βˆ™ (K₁ ∧[ π’ͺ Y ] Kβ‚‚) = f β‹†βˆ™ K₁ ∧[ π’ͺ X ] f β‹†βˆ™ Kβ‚‚
    † = frame-homomorphisms-preserve-meets (π’ͺ Y) (π’ͺ X) f K₁ Kβ‚‚

 𝒦-mapβ‚€-is-lattice-homomorphism : is-homomorphismᡈ 𝒦⦅Y⦆ 𝒦⦅X⦆ 𝒦-mapβ‚€ holds
 𝒦-mapβ‚€-is-lattice-homomorphism = 𝒦-mapβ‚€-preserves-𝟏
                                , 𝒦-mapβ‚€-preserves-∧
                                , 𝒦-mapβ‚€-preserves-𝟎
                                , 𝒦-mapβ‚€-preserves-∨

\end{code}

We package `𝒦-mapβ‚€` together with the proof that it is a lattice homomorphism
and call this `𝒦-map`.

\begin{code}

 𝒦-map : Homomorphismᡈᡣ 𝒦⦅Y⦆ 𝒦⦅X⦆
 𝒦-map = record
          { h                 = 𝒦-mapβ‚€
          ; h-is-homomorphism = 𝒦-mapβ‚€-is-lattice-homomorphism
          }

\end{code}

Finally, we put everything together to define a function `to-𝒦-map` that maps a
spectral map `f : X β†’ Y` of spectral locales to a homomorphism `𝒦 Y β†’ 𝒦 X` of
distributive lattices.

\begin{code}

module _ (X  : Locale (𝓀 ⁺) 𝓀 𝓀)
         (Y  : Locale (𝓀 ⁺) 𝓀 𝓀)
         (σ₁ : is-spectral-with-small-basis ua X holds)
         (Οƒβ‚‚ : is-spectral-with-small-basis ua Y holds) where

 open FunctorialAction X Y σ₁ Οƒβ‚‚
 open 𝒦-Lattice X σ₁ renaming (πŸβ‚– to πŸβ‚–-X;
                               𝟏-is-compact to 𝟏-X-is-compact)
 open 𝒦-Lattice Y Οƒβ‚‚ renaming (πŸβ‚– to πŸβ‚–-Y; 𝒦⦅X⦆ to 𝒦⦅Y⦆;
                               𝟏-is-compact to 𝟏-Y-is-compact)

 to-𝒦-map : (X ─sβ†’ Y) β†’ 𝒦⦅Y⦆ ─dβ†’ 𝒦⦅X⦆
 to-𝒦-map (f , 𝕀) = 𝒦-map f 𝕀

\end{code}