--------------------------------------------------------------------------------
title:          Continuous maps of locales
author:         Ayberk Tosun
date-started:   2024-04-10
--------------------------------------------------------------------------------

Originally written as part of the `Locales.Frame` module on 2022-04-23.

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

\begin{code}[hide]

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

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

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

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

open AllCombinators pt fe

\end{code}

We work in a module parameterized by two locales `X` and `Y`.

\begin{code}

module ContinuousMaps (X : Locale ๐“ค ๐“ฅ ๐“ฆ) (Y : Locale ๐“ค' ๐“ฅ' ๐“ฆ) where

 open Locale
 open FrameHomomorphisms hiding (fun-syntax; fun)
 open FrameHomomorphisms (๐’ช Y) (๐’ช X) using (fun-syntax)

\end{code}

We denote the type of continuous maps by `X โ”€cโ†’ Y`.

\begin{code}

 _โ”€cโ†’_ : ๐“ค โŠ” ๐“ฅ โŠ” ๐“ฆ โบ โŠ” ๐“ค' ฬ‡
 _โ”€cโ†’_ = ๐’ช Y โ”€fโ†’ ๐’ช X

\end{code}

\begin{code}

 continuity-of : (f : _โ”€cโ†’_) โ†’ (S : Fam ๐“ฆ โŸจ ๐’ช Y โŸฉ)
               โ†’ f .prโ‚ (โ‹[ ๐’ช Y ] S) ๏ผ โ‹[ ๐’ช X ] โ… f .prโ‚ V โˆฃ V ฮต S โ†
 continuity-of f S = โ‹[ ๐’ช X ]-unique โ… f $ V โˆฃ V ฮต S โ† (f $ (โ‹[ ๐’ช Y ] S)) ((prโ‚‚ (prโ‚‚ (prโ‚‚ f)) S))
   where
    open Joins (ฮป x y โ†’ x โ‰ค[ poset-of (๐’ช X) ] y)

    infixr 25 _$_
    _$_ = prโ‚

\end{code}

\begin{code}

module ContinuousMapNotation (X : Locale ๐“ค ๐“ฅ ๐“ฆ) (Y : Locale ๐“ค' ๐“ฅ' ๐“ฆ) where

 infix  9 _โ‹†
 infixl 9 _โ‹†โˆ™_

 open Locale

 open ContinuousMaps
 open FrameHomomorphisms (๐’ช Y) (๐’ช X) using (fun-syntax; fun)
 open FrameHomomorphisms hiding (fun-syntax; fun)

\end{code}

We denote by `fโ‹†` the defining frame homomorphism of a continuous map `f`.

\begin{code}

 _โ‹† : (X โ”€cโ†’ Y) โ†’ ๐’ช Y โ”€fโ†’ ๐’ช X
 _โ‹† f = f

\end{code}

\begin{code}

 _โ‹†โˆ™_ : (X โ”€cโ†’ Y) โ†’ โŸจ ๐’ช Y โŸฉ โ†’ โŸจ ๐’ช X โŸฉ
 _โ‹†โˆ™_ f = fun (_โ‹† f)

\end{code}

\begin{code}

open ContinuousMaps using (_โ”€cโ†’_)
open Locale
open FrameHomomorphisms using (is-a-frame-homomorphism)

cont-comp : {๐“ค'' ๐“ฅ'' : Universe}
          โ†’ (X : Locale ๐“ค   ๐“ฅ   ๐“ฆ)
          โ†’ (Y : Locale ๐“ค'  ๐“ฅ'  ๐“ฆ)
          โ†’ (Z : Locale ๐“ค'' ๐“ฅ'' ๐“ฆ)
          โ†’ (Y โ”€cโ†’ Z) โ†’ (X โ”€cโ†’ Y) โ†’ X โ”€cโ†’ Z
cont-comp {๐“ฆ = ๐“ฆ} X Y Z โ„Š@(g , ฮฑโ‚ , ฮฑโ‚‚ , ฮฑโ‚ƒ) ๐’ป@(f , ฮฒโ‚ , ฮฒโ‚‚ , ฮฒโ‚ƒ) = h , โ€ 
 where
  open ContinuousMapNotation X Y using () renaming (_โ‹†โˆ™_ to _โ‹†โ‚โˆ™_)
  open ContinuousMapNotation Y Z using () renaming (_โ‹†โˆ™_ to _โ‹†โ‚‚โˆ™_)

  h : โŸจ ๐’ช Z โŸฉ โ†’ โŸจ ๐’ช X โŸฉ
  h W = ๐’ป โ‹†โ‚โˆ™ (โ„Š โ‹†โ‚‚โˆ™ W)

  โ€  : is-a-frame-homomorphism (๐’ช Z) (๐’ช X) h holds
  โ€  = โ€ โ‚ , โ€ โ‚‚ , โ€ โ‚ƒ
   where
    โ€ โ‚ : ๐’ป โ‹†โ‚โˆ™ (โ„Š โ‹†โ‚‚โˆ™ ๐Ÿ[ ๐’ช Z ]) ๏ผ ๐Ÿ[ ๐’ช X ]
    โ€ โ‚ = ๐’ป โ‹†โ‚โˆ™ (โ„Š โ‹†โ‚‚โˆ™ ๐Ÿ[ ๐’ช Z ])     ๏ผโŸจ โ…  โŸฉ
         ๐’ป โ‹†โ‚โˆ™ ๐Ÿ[ ๐’ช Y ]             ๏ผโŸจ โ…ก โŸฉ
         ๐Ÿ[ ๐’ช X ]                   โˆŽ
          where
           โ…  = ap (ฮป - โ†’ ๐’ป โ‹†โ‚โˆ™ -) ฮฑโ‚
           โ…ก = ฮฒโ‚

    โ€ โ‚‚ : (U V : โŸจ ๐’ช Z โŸฉ)
       โ†’ ๐’ป โ‹†โ‚โˆ™ (โ„Š โ‹†โ‚‚โˆ™ (U โˆง[ ๐’ช Z ] V))
       ๏ผ (๐’ป โ‹†โ‚โˆ™ (โ„Š โ‹†โ‚‚โˆ™ U)) โˆง[ ๐’ช X ] (๐’ป โ‹†โ‚โˆ™ (โ„Š โ‹†โ‚‚โˆ™ V))
    โ€ โ‚‚ U V = ๐’ป โ‹†โ‚โˆ™ (โ„Š โ‹†โ‚‚โˆ™ (U โˆง[ ๐’ช Z ] V))                   ๏ผโŸจ โ…  โŸฉ
             ๐’ป โ‹†โ‚โˆ™ ((โ„Š โ‹†โ‚‚โˆ™ U) โˆง[ ๐’ช Y ] (โ„Š โ‹†โ‚‚โˆ™ V))           ๏ผโŸจ โ…ก โŸฉ
             (๐’ป โ‹†โ‚โˆ™ (โ„Š โ‹†โ‚‚โˆ™ U)) โˆง[ ๐’ช X ] (๐’ป โ‹†โ‚โˆ™ (โ„Š โ‹†โ‚‚โˆ™ V))   โˆŽ
              where
               โ…  = ap (ฮป - โ†’ ๐’ป โ‹†โ‚โˆ™ -) (ฮฑโ‚‚ U V)
               โ…ก = ฮฒโ‚‚ (โ„Š โ‹†โ‚‚โˆ™ U) (โ„Š โ‹†โ‚‚โˆ™ V)

    open Joins (ฮป x y โ†’ x โ‰ค[ poset-of (๐’ช X) ] y)

    โ€ โ‚ƒ : (U : Fam ๐“ฆ โŸจ ๐’ช Z โŸฉ) โ†’ ((h (โ‹[ ๐’ช Z ] U)) is-lub-of โ… h x โˆฃ x ฮต U โ†) holds
    โ€ โ‚ƒ U = transport
            (ฮป - โ†’ (- is-lub-of โ… h x โˆฃ x ฮต U โ†) holds)
            (โ€ โ‚„ โปยน)
            (โ‹[ ๐’ช X ]-upper โ… h x โˆฃ x ฮต U โ† , โ‹[ ๐’ช X ]-least โ… h x โˆฃ x ฮต U โ†)
     where
      open PosetReasoning (poset-of (๐’ช X))

      โ€ โ‚„ : h (โ‹[ ๐’ช Z ] U) ๏ผ โ‹[ ๐’ช X ] โ… h x โˆฃ x ฮต U โ†
      โ€ โ‚„ = ๐’ป โ‹†โ‚โˆ™ (โ„Š โ‹†โ‚‚โˆ™ (โ‹[ ๐’ช Z ] U))              ๏ผโŸจ I  โŸฉ
           ๐’ป โ‹†โ‚โˆ™ (โ‹[ ๐’ช Y ] โ… โ„Š โ‹†โ‚‚โˆ™ x โˆฃ x ฮต U โ†)    ๏ผโŸจ II โŸฉ
           โ‹[ ๐’ช X ] โ… h x โˆฃ x ฮต U โ†                โˆŽ
            where
             I  = ap (ฮป - โ†’ ๐’ป โ‹†โ‚โˆ™ -) (โ‹[ ๐’ช Y ]-unique โ… โ„Š โ‹†โ‚‚โˆ™ x โˆฃ x ฮต U โ† _ (ฮฑโ‚ƒ _))
             II = โ‹[ ๐’ช X ]-unique โ… h x โˆฃ x ฮต U โ† _ (ฮฒโ‚ƒ _)

\end{code}