--------------------------------------------------------------------------------
title:          Properties of frame homomorphisms
author:         Ayberk Tosun
date-started:   2024-04-10
dates-updated:  [2024-05-06]
--------------------------------------------------------------------------------

Originally written as part of the `Locales.Frame` module on 2021-03-09.

Factored out from the `Locales.Frame` module on 2024-04-10.

\begin{code}[hide]

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

open import MLTT.Spartan hiding (𝟚; β‚€; ₁)
open import UF.Base
open import UF.FunExt
open import UF.PropTrunc

module Locales.ContinuousMap.FrameHomomorphism-Properties
        (pt : propositional-truncations-exist)
        (fe : Fun-Ext)
       where

open import Locales.ContinuousMap.FrameHomomorphism-Definition pt fe
open import Locales.Frame pt fe
open import Slice.Family
open import UF.Logic
open import UF.Subsingletons
open import UF.SubtypeClassifier

open AllCombinators pt fe

\end{code}

We work in a module parameterized by two frames.

\begin{code}

module FrameHomomorphismProperties (F : Frame 𝓀 π“₯ 𝓦) (G : Frame 𝓀' π“₯' 𝓦) where

 open FrameHomomorphisms using (_─fβ†’_)
 open FrameHomomorphisms F G hiding (_─fβ†’_)

\end{code}

The following lemma says that if the underlying functions of two frame
homomorphisms are extensionally equal, then the frame homomorphisms are equal.

\begin{code}

 to-frame-homomorphism-= : (h₁ hβ‚‚  : F ─fβ†’ G)
                         β†’ ((x : ⟨ F ⟩) β†’ h₁ .pr₁ x = hβ‚‚ .pr₁ x)
                         β†’ h₁ = hβ‚‚
 to-frame-homomorphism-= h₁ hβ‚‚ ψ = to-subtype-= † (dfunext fe ψ)
  where
   † : (f : ⟨ F ⟩ β†’ ⟨ G ⟩) β†’ is-prop (is-a-frame-homomorphism f holds)
   † f = holds-is-prop (is-a-frame-homomorphism f)

\end{code}

\begin{code}

 frame-morphisms-are-monotonic : (h : ⟨ F ⟩ β†’ ⟨ G ⟩)
                               β†’ is-a-frame-homomorphism h holds
                               β†’ is-monotonic (poset-of F) (poset-of G) h holds
 frame-morphisms-are-monotonic f (_ , ψ , _) (x , y) p =
  f x              β‰€βŸ¨ β…  ⟩
  f (x ∧[ F ] y)   β‰€βŸ¨ β…‘ ⟩
  f x ∧[ G ] f y   β‰€βŸ¨ β…’ ⟩
  f y              β– 
   where
    open PosetReasoning (poset-of G)

    β…  = reflexivity+ (poset-of G) (ap f (connecting-lemma₁ F p))
    β…‘ = reflexivity+ (poset-of G) (ψ x y)
    β…’ = ∧[ G ]-lowerβ‚‚ (f x) (f y)

\end{code}

\begin{code}

 monotone-map-of : (F ─fβ†’ G) β†’ poset-of F ─mβ†’ poset-of G
 monotone-map-of h = fun h , †
  where
   † : is-monotonic (poset-of F) (poset-of G) (pr₁ h) holds
   † = frame-morphisms-are-monotonic (pr₁ h) (prβ‚‚ h)

\end{code}

\begin{code}

 meet-preserving-implies-monotone : (h : ⟨ F ⟩ β†’ ⟨ G ⟩)
                                  β†’ preserves-binary-meets h holds
                                  β†’ is-monotonic (poset-of F) (poset-of G) h holds
 meet-preserving-implies-monotone h ΞΌ (x , y) p =
  h x              =⟨ i   βŸ©β‚š
  h (x ∧[ F ] y)   =⟨ ii  βŸ©β‚š
  h x ∧[ G ] h y   β‰€βŸ¨ iii ⟩
  h y              β– 
   where
    open PosetReasoning (poset-of G)

    i   = ap h (connecting-lemma₁ F p)
    ii  = ΞΌ x y
    iii = ∧[ G ]-lowerβ‚‚ (h x) (h y)

\end{code}

\begin{code}

 frame-homomorphisms-preserve-bottom : (h : F ─fβ†’ G)
                                     β†’ h .pr₁ 𝟎[ F ] = 𝟎[ G ]
 frame-homomorphisms-preserve-bottom 𝒽@(h , _ , _ , Ξ³) =
  only-𝟎-is-below-𝟎 G (𝒽 .pr₁ 𝟎[ F ]) †
   where
    † : (h 𝟎[ F ] ≀[ poset-of G ] 𝟎[ G ]) holds
    † = prβ‚‚ (Ξ³ (βˆ… _)) ((⋁[ G ] βˆ… 𝓦) , Ξ» ())

\end{code}

\begin{code}

 frame-homomorphisms-preserve-binary-joins : (h : F ─fβ†’ G)
                                           β†’ (x y : ⟨ F ⟩)
                                           β†’ h .pr₁ (x ∨[ F ] y)
                                           = (h .pr₁ x) ∨[ G ] (h .pr₁ y)
 frame-homomorphisms-preserve-binary-joins 𝒽@(h , _ , _ , Ξ³) x y =
  ⋁[ G ]-unique ⁅ h x , h y ⁆ (h (x ∨[ F ] y)) († , ‑)
   where
    open Joins (Ξ» x y β†’ x ≀[ poset-of G ] y)

    † : (h (x ∨[ F ] y) is-an-upper-bound-of ⁅ h x , h y ⁆) holds
    † (inl ⋆) = pr₁ (Ξ³ ⁅ x , y ⁆) (inl ⋆)
    † (inr ⋆) = pr₁ (Ξ³ ⁅ x , y ⁆) (inr ⋆)

    ‑ : ((u , _) : upper-bound ⁅ h x , h y ⁆)
      β†’ (h (x ∨[ F ] y) ≀[ poset-of G ] u) holds
    ‑ (u , p) = prβ‚‚ (Ξ³ ⁅ x , y ⁆) (u , q)
     where
      q : (u is-an-upper-bound-of ⁅ h z ∣ z Ξ΅ ⁅ x , y ⁆ ⁆) holds
      q (inl ⋆) = p (inl ⋆)
      q (inr ⋆) = p (inr ⋆)

\end{code}

Added on 2024-05-06.

\begin{code}

sections-are-order-embeddings : (P : Poset 𝓀 π“₯) (Q : Poset 𝓀' π“₯')
                              β†’ (s : ∣ P βˆ£β‚š β†’ ∣ Q βˆ£β‚š)
                              β†’ (r : ∣ Q βˆ£β‚š β†’ ∣ P βˆ£β‚š )
                              β†’ is-monotonic Q P r holds
                              β†’ r ∘ s ∼ id
                              β†’ {x y : ∣ P βˆ£β‚š}
                              β†’ (s x ≀[ Q ] s y β‡’ x ≀[ P ] y) holds
sections-are-order-embeddings P Q s r 𝓂 Ο† {x} {y} p =
 transportβ‚‚ (Ξ» x y β†’ (x ≀[ P ] y) holds) (Ο† x) (Ο† y) †
  where
   † : (r (s x) ≀[ P ] r (s y)) holds
   † = 𝓂 (s x , s y) p

\end{code}