Brendan Hart 2019-2020

Addition by Tom de Jong in July 2024.

\begin{code}

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

open import MLTT.Spartan
open import UF.FunExt
open import UF.PropTrunc

module DomainTheory.Basics.Curry
        (pt : propositional-truncations-exist)
        (fe : βˆ€ {𝓀 π“₯} β†’ funext 𝓀 π“₯)
        (π“₯ : Universe)
       where

open PropositionalTruncation pt

open import DomainTheory.Basics.Dcpo pt fe π“₯
open import DomainTheory.Basics.Exponential pt fe π“₯
open import DomainTheory.Basics.Miscelanea pt fe π“₯
open import DomainTheory.Basics.Pointed pt fe π“₯
open import DomainTheory.Basics.Products pt fe
open import DomainTheory.Basics.ProductsContinuity pt fe π“₯
open import UF.Subsingletons
open import UF.Subsingletons-FunExt

open DcpoProductsGeneral π“₯

module _ (𝓓 : DCPO {𝓀} {𝓀'})
         (𝓔 : DCPO {𝓣} {𝓣'})
         (𝓕 : DCPO {𝓦} {𝓦'})
       where

 curryα΅ˆαΆœα΅–α΅’ : DCPO[ (𝓓 Γ—α΅ˆαΆœα΅–α΅’ 𝓔) , 𝓕 ] β†’ DCPO[ 𝓓 , 𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕 ]
 curryα΅ˆαΆœα΅–α΅’ (a , a-is-continuous) = f , f-is-continuous
  where
   f : ⟨ 𝓓 ⟩ β†’ ⟨ 𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕 ⟩
   f = continuousβ†’continuous-in-prβ‚‚ 𝓓 𝓔 𝓕 (a , a-is-continuous)

   f-is-continuous : (I : π“₯ Μ‡) (Ξ± : I β†’ ⟨ 𝓓 ⟩) (Ξ΄ : is-Directed 𝓓 Ξ±)
                   β†’ is-sup
                      (underlying-order (𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕))
                      (f (∐ 𝓓 Ξ΄))
                      (f ∘ α)
   f-is-continuous I Ξ± Ξ΄ = u , v
    where
     u : (i : I) β†’ ((f ∘ Ξ±) i) βŠ‘βŸ¨ 𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕 ⟩ (f (∐ 𝓓 Ξ΄))
     u i e = sup-is-upperbound
              (underlying-order 𝓕)
              (continuity-of-function 𝓓 𝓕 a-fixed-e I Ξ± Ξ΄)
              i
       where
         a-fixed-e : DCPO[ 𝓓 , 𝓕 ]
         a-fixed-e = continuousβ†’continuous-in-pr₁ 𝓓 𝓔 𝓕
                      (a , a-is-continuous)
                      e

     v : (u₁ : ⟨ 𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕 ⟩)
       β†’ ((i : I) β†’ f (Ξ± i) βŠ‘βŸ¨ 𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕 ⟩ u₁)
       β†’ f (∐ 𝓓 Ξ΄) βŠ‘βŸ¨ 𝓔 βŸΉα΅ˆαΆœα΅–α΅’ π“•Β βŸ© u₁
     v u₁ p e = e₃ (underlying-function 𝓔 𝓕 u₁ e) (Ξ» i β†’ p i e)
       where
         a-fixed-e : DCPO[ 𝓓 , 𝓕 ]
         a-fixed-e = continuousβ†’continuous-in-pr₁ 𝓓 𝓔 𝓕
                      (a , a-is-continuous)
                      e

         e₃ : (uβ‚‚ : ⟨ 𝓕 ⟩)
            β†’ ((i : I) β†’ (underlying-function 𝓓 𝓕 a-fixed-e) (Ξ± i) βŠ‘βŸ¨ 𝓕 ⟩ uβ‚‚)
            β†’ (underlying-function 𝓓 𝓕 a-fixed-e) (∐ 𝓓 Ξ΄) βŠ‘βŸ¨ 𝓕 ⟩ uβ‚‚
         e₃ =  sup-is-lowerbound-of-upperbounds
                (underlying-order 𝓕)
                (continuity-of-function 𝓓 𝓕 a-fixed-e I Ξ± Ξ΄)

 uncurryα΅ˆαΆœα΅–α΅’ : DCPO[ 𝓓 , 𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕 ] β†’ DCPO[ (𝓓 Γ—α΅ˆαΆœα΅–α΅’ 𝓔) , 𝓕 ]
 uncurryα΅ˆαΆœα΅–α΅’ 𝕗@(f , f-is-continuous) =
  g ,
  continuous-in-argumentsβ†’continuous 𝓓 𝓔 𝓕
   g
   𝓓→𝓕-is-continuous
   𝓔→𝓕-is-continuous
  where
   f-is-monotone : is-monotone 𝓓 (𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕) f
   f-is-monotone = monotone-if-continuous 𝓓 (𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕) 𝕗

   𝓓→𝓕-is-continuous : (e : ⟨ 𝓔 ⟩)
                      β†’ is-continuous 𝓓 𝓕 (Ξ» d β†’ underlying-function 𝓔 𝓕 (f d) e)
   𝓓→𝓕-is-continuous e I Ξ± Ξ΄ = u , v
    where
     u : is-upperbound
          (underlying-order 𝓕)
          (underlying-function 𝓔 𝓕 (f (∐ 𝓓 Ξ΄)) e)
          (pointwise-family 𝓔 𝓕 (f ∘ Ξ±) e)
     u i = f-is-monotone (Ξ± i) (∐ 𝓓 Ξ΄) (∐-is-upperbound 𝓓 Ξ΄ i) e
     v : (z : ⟨ 𝓕 ⟩)
       β†’ ((i : I) β†’ (underlying-function 𝓔 𝓕 ((f ∘ Ξ±) i) e) βŠ‘βŸ¨ 𝓕 ⟩ z)
       β†’ (underlying-function 𝓔 𝓕 (f (∐ 𝓓 Ξ΄)) e) βŠ‘βŸ¨ 𝓕 ⟩ z
     v z p = transport (Ξ» - β†’ - βŠ‘βŸ¨ 𝓕 ⟩ z) (ii ⁻¹) ∐-is-lowerbound
       where
         ⟨f∘α⟩i-is-directed : is-Directed (𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕) (f ∘ Ξ±)
         ⟨f∘α⟩i-is-directed = image-is-directed 𝓓 (𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕) {f}
                               f-is-monotone
                               {I}
                               {Ξ±}
                               Ξ΄

         ⟨f∘α⟩ie-is-directed : is-Directed 𝓕 (pointwise-family 𝓔 𝓕 (f ∘ Ξ±) e)
         ⟨f∘α⟩ie-is-directed = pointwise-family-is-directed 𝓔 𝓕
                                (f ∘ α)
                                ⟨f∘α⟩i-is-directed e

         ∐-is-lowerbound : (∐ 𝓕 ⟨f∘α⟩ie-is-directed) βŠ‘βŸ¨ 𝓕 ⟩ z
         ∐-is-lowerbound = ∐-is-lowerbound-of-upperbounds 𝓕
                            ⟨f∘α⟩ie-is-directed
                            z
                            p

         i : f (∐ 𝓓 Ξ΄) = ∐ (𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕) ⟨f∘α⟩i-is-directed
         i = continuous-∐-= 𝓓 (𝓔 βŸΉα΅ˆαΆœα΅–α΅’ 𝓕) (f , f-is-continuous) Ξ΄

         ii : underlying-function 𝓔 𝓕 (f (∐ 𝓓 Ξ΄)) e = ∐ 𝓕 ⟨f∘α⟩ie-is-directed
         ii = ap (Ξ» - β†’ underlying-function 𝓔 𝓕 - e) i

   𝓔→𝓕-is-continuous : (d : ⟨ 𝓓 ⟩)
                     β†’ is-continuous 𝓔 𝓕 (Ξ» e β†’ underlying-function 𝓔 𝓕 (f d) e)
   𝓔→𝓕-is-continuous d = continuity-of-function 𝓔 𝓕 (f d)

   g : ⟨ 𝓓 Γ—α΅ˆαΆœα΅–α΅’ 𝓔 ⟩ β†’ ⟨ 𝓕 ⟩
   g p = underlying-function 𝓔 𝓕 (f (pr₁ p)) (prβ‚‚ p)

module _ (𝓓 : DCPOβŠ₯ {𝓀} {𝓀'})
         (𝓔 : DCPOβŠ₯ {𝓣} {𝓣'})
         (𝓕 : DCPOβŠ₯ {𝓦} {𝓦'})
       where

 curryα΅ˆαΆœα΅–α΅’βŠ₯ : DCPOβŠ₯[ 𝓓 Γ—α΅ˆαΆœα΅–α΅’βŠ₯ 𝓔 , 𝓕 ] β†’ DCPOβŠ₯[ 𝓓 , 𝓔 βŸΉα΅ˆαΆœα΅–α΅’βŠ₯ 𝓕 ]
 curryα΅ˆαΆœα΅–α΅’βŠ₯ f = curryα΅ˆαΆœα΅–α΅’ (𝓓 ⁻) (𝓔 ⁻) ( 𝓕 ⁻) f

 uncurryα΅ˆαΆœα΅–α΅’βŠ₯ : DCPOβŠ₯[ 𝓓 , 𝓔 βŸΉα΅ˆαΆœα΅–α΅’βŠ₯ 𝓕 ] β†’ DCPOβŠ₯[ 𝓓 Γ—α΅ˆαΆœα΅–α΅’βŠ₯ 𝓔 , 𝓕 ]
 uncurryα΅ˆαΆœα΅–α΅’βŠ₯ f = uncurryα΅ˆαΆœα΅–α΅’ (𝓓 ⁻) (𝓔 ⁻) (𝓕 ⁻) f

module _ (𝓓 : DCPO {𝓀} {𝓀'})
         (𝓔 : DCPO {𝓣} {𝓣'})
       where

 eval : DCPO[ (𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔) Γ—α΅ˆαΆœα΅–α΅’ 𝓓 , 𝓔 ]
 eval = f , c
  where
   f : ⟨ (𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔) Γ—α΅ˆαΆœα΅–α΅’ 𝓓 ⟩ β†’ ⟨ 𝓔 ⟩
   f (g , d) = underlying-function 𝓓 𝓔 g d

   f-is-monotone : is-monotone ((𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔) Γ—α΅ˆαΆœα΅–α΅’ 𝓓) 𝓔 f
   f-is-monotone (g₁ , d₁) (gβ‚‚ , dβ‚‚) (g-βŠ‘ , d-βŠ‘) =
    f (g₁ , d₁) βŠ‘βŸ¨ 𝓔 ⟩[ monotone-if-continuous 𝓓 𝓔 g₁ d₁ dβ‚‚ d-βŠ‘ ]
    f (g₁ , dβ‚‚) βŠ‘βŸ¨ 𝓔 ⟩[ g-βŠ‘ dβ‚‚ ]
    f (gβ‚‚ , dβ‚‚) ∎⟨ 𝓔 ⟩

   c : is-continuous ((𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔) Γ—α΅ˆαΆœα΅–α΅’ 𝓓) 𝓔 f
   c = continuous-in-argumentsβ†’continuous (𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔) 𝓓 𝓔 f
        continuous₁
        continuousβ‚‚
    where
     continuous₁ : (e : ⟨ 𝓓 ⟩)
                 β†’ is-continuous (𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔) 𝓔 (Ξ» d β†’ f (d , e))
     continuous₁ d I Ξ± Ξ΄ = u , v
      where
       u : is-upperbound
            (underlying-order 𝓔)
            (f (∐ (𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔) {I} {Ξ±} Ξ΄ , d))
            (Ξ» z β†’ f (Ξ± z , d))
       u i = f-is-monotone
              (Ξ± i , d)
              (∐ (𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔) {I} {Ξ±} Ξ΄ , d)
              (∐-is-upperbound (𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔) {I} {Ξ±} Ξ΄ i , reflexivity 𝓓 d)

       v : (y : ⟨ 𝓔 ⟩)
         β†’ ((i : I) β†’ f (Ξ± i , d) βŠ‘βŸ¨ 𝓔 ⟩ y)
         β†’ f (∐ (𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔) {I} {Ξ±} Ξ΄ , d) βŠ‘βŸ¨ 𝓔 ⟩ y
       v y p = ∐-is-lowerbound-of-upperbounds 𝓔 isdir₁ y p
         where
          isdir₁ : is-Directed 𝓔 (pointwise-family 𝓓 𝓔 Ξ± d)
          isdir₁ = pointwise-family-is-directed 𝓓 𝓔 Ξ± Ξ΄ d

     continuousβ‚‚ : (d : ⟨ 𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔 ⟩) β†’ is-continuous 𝓓 𝓔 (Ξ» e β†’ f (d , e))
     continuousβ‚‚ g I Ξ± Ξ΄ = u , v
      where
       u : is-upperbound
            (underlying-order 𝓔)
            (f (g , ∐ 𝓓 Ξ΄))
            (Ξ» z β†’ f (g , Ξ± z))
       u i = f-is-monotone
              (g , Ξ± i)
              (g , ∐ 𝓓 Ξ΄)
              ((reflexivity (𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔) g) , (∐-is-upperbound 𝓓 Ξ΄ i))

       v : (y : ⟨ 𝓔 ⟩)
         β†’ ((i : I) β†’ f (g , Ξ± i) βŠ‘βŸ¨ 𝓔 ⟩ y)
         β†’ f (g , ∐ 𝓓 Ξ΄) βŠ‘βŸ¨ 𝓔 ⟩ y
       v y p = transport (Ξ» - β†’ - βŠ‘βŸ¨ 𝓔 ⟩ y) (e ⁻¹) q
        where
         e : f (g , ∐ 𝓓 Ξ΄)
           =  ∐ 𝓔 (image-is-directed 𝓓 𝓔 (monotone-if-continuous 𝓓 𝓔 g) Ξ΄)
         e = continuous-∐-= 𝓓 𝓔 g Ξ΄

         q : (∐ 𝓔 (image-is-directed 𝓓 𝓔 (monotone-if-continuous 𝓓 𝓔 g) Ξ΄))
           βŠ‘βŸ¨ 𝓔 ⟩ y
         q = ∐-is-lowerbound-of-upperbounds 𝓔
               (image-is-directed 𝓓 𝓔 (monotone-if-continuous 𝓓 𝓔 g) Ξ΄)
               y
               p

\end{code}

Added 3 July 2024 by Tom de Jong.

We introduce two abbreviations for readability.

\begin{code}

 private
  𝓔ᴰ = 𝓓 βŸΉα΅ˆαΆœα΅–α΅’ 𝓔
  ev = underlying-function (𝓔ᴰ Γ—α΅ˆαΆœα΅–α΅’ 𝓓) 𝓔 eval

 βŸΉα΅ˆαΆœα΅–α΅’-is-exponential : (𝓓' : DCPO {𝓦} {𝓦'})
                          (f : ⟨ 𝓓' Γ—α΅ˆαΆœα΅–α΅’ 𝓓 ⟩ β†’ ⟨ 𝓔 ⟩)
                        β†’ is-continuous (𝓓' Γ—α΅ˆαΆœα΅–α΅’ 𝓓) 𝓔 f
                        β†’ βˆƒ! fΜ… κž‰ (⟨ 𝓓' ⟩ β†’ ⟨ 𝓔ᴰ ⟩) ,
                                 is-continuous 𝓓' 𝓔ᴰ fΜ…
                               Γ— ev ∘ (Ξ» (d' , d) β†’ fΜ… d' , d) ∼ f
 βŸΉα΅ˆαΆœα΅–α΅’-is-exponential 𝓓' f cf =
  (fΜ… , fΜ…-is-continuous , ∼-refl) , fΜ…-is-unique
   where
    C : DCPO[ 𝓓' , 𝓔ᴰ ]
    C = curryα΅ˆαΆœα΅–α΅’ 𝓓' 𝓓 𝓔 (f , cf)
    fΜ… = pr₁ C
    fΜ…-is-continuous : is-continuous 𝓓' 𝓔ᴰ fΜ…
    fΜ…-is-continuous = prβ‚‚ C
    fΜ…-is-unique : is-central _ (fΜ… , fΜ…-is-continuous , ∼-refl)
    fΜ…-is-unique (g , g-cont , g-eq) =
     to-subtype-= (Ξ» h β†’ Γ—-is-prop
                          (being-continuous-is-prop 𝓓' 𝓔ᴰ h)
                          (Ξ -is-prop fe (Ξ» _ β†’ sethood 𝓔)))
                   (dfunext fe
                            (Ξ» d' β†’ to-continuous-function-= 𝓓 𝓔
                                     (Ξ» d β†’ g-eq (d' , d)) ⁻¹))

\end{code}

End of addition

\begin{code}

module _ (𝓓 : DCPOβŠ₯ {𝓀} {𝓀'})
         (𝓔 : DCPOβŠ₯ {𝓣} {𝓣'})
       where

 evalβŠ₯ : DCPOβŠ₯[ (𝓓 βŸΉα΅ˆαΆœα΅–α΅’βŠ₯ 𝓔) Γ—α΅ˆαΆœα΅–α΅’βŠ₯ 𝓓 , 𝓔 ]
 evalβŠ₯ = eval (𝓓 ⁻) (𝓔 ⁻)

\end{code}