From 8df2d11483a77663ead561b3ebf1b0147fb5285e Mon Sep 17 00:00:00 2001 From: Max New <maxsnew@gmail.com> Date: Wed, 31 May 2023 18:46:02 -0400 Subject: [PATCH] ev ctxts all done except for substId/substAssoc and the computation stuff --- .../Abstract/TermModel/Convenient.agda | 9 ++-- .../Abstract/TermModel/Convenient/Linear.agda | 32 +++++++++++++++ .../TermModel/Convenient/Semantics.agda | 41 ++++++++++--------- 3 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient/Linear.agda diff --git a/formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient.agda b/formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient.agda index d67ca5a..5be8841 100644 --- a/formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient.agda +++ b/formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient.agda @@ -18,8 +18,7 @@ open import Cubical.Categories.Limits.BinProduct.More open import Cubical.Categories.Limits.BinCoproduct open import Cubical.Categories.Monad.Base open import Cubical.Categories.Exponentials - -open import Semantics.Abstract.TermModel.Strength +open import Cubical.Categories.Monad.Strength.Cartesian private variable @@ -33,20 +32,20 @@ open IsMonad record Model â„“ â„“' : Type (â„“-suc (â„“-max â„“ â„“')) where field - -- A cartesian closed category + -- a bicartesian closed category cat : Category â„“ â„“' term : Terminal cat binProd : BinProducts cat exponentials : Exponentials cat binProd binCoprod : BinCoproducts cat + -- with a strong monad monad : Monad cat - strength : Strength cat binProd monad + strength : Strength binProd monad -- TODO: rename Notation and make similar modules for terminal, coprod open Notation cat binProd public open ExpNotation cat binProd exponentials public - open StrengthNotation cat binProd monad strength public 🙠= term .fst diff --git a/formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient/Linear.agda b/formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient/Linear.agda new file mode 100644 index 0000000..942529e --- /dev/null +++ b/formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient/Linear.agda @@ -0,0 +1,32 @@ +{-# OPTIONS --lossy-unification #-} +module Semantics.Abstract.TermModel.Convenient.Linear where + +open import Cubical.Foundations.Prelude +open import Cubical.Categories.Category +open import Cubical.Categories.Functor +open import Cubical.Categories.Monad.Strength.Cartesian +open import Cubical.Categories.Monad.Kleisli +open import Cubical.Categories.DistributiveLaw.ComonadOverMonad.BiKleisli.Base +open import Cubical.Categories.DistributiveLaw.ComonadOverMonad.BiKleisli.Morphism +open import Cubical.Categories.Comonad.Instances.Environment + +open import Semantics.Abstract.TermModel.Convenient + +private + variable + â„“ â„“' : Level + +module StrengthNotation (𓜠: Model â„“ â„“') where + open Model 𓜠+ open Category cat + Linear : ∀ (Γ : ob) → Category _ _ + Linear Γ = BiKleisli (Env Γ (binProd Γ)) monad (strength-law binProd monad strength Γ) + + ClosedLinear : Category _ _ + ClosedLinear = Kleisli monad + + wkClosed : ∀ Γ → Functor ClosedLinear (Linear Γ) + wkClosed = wkF binProd monad strength + + _^* : ∀ {Δ Γ}(γ : Hom[ Δ , Γ ]) → Functor (Linear Γ) (Linear Δ) + γ ^* = change-of-comonad (change-of-base _ _ strength γ) diff --git a/formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient/Semantics.agda b/formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient/Semantics.agda index 9a0eb56..cd5d6ed 100644 --- a/formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient/Semantics.agda +++ b/formalizations/guarded-cubical/Semantics/Abstract/TermModel/Convenient/Semantics.agda @@ -16,13 +16,14 @@ open import Cubical.Categories.Limits.Terminal open import Cubical.Categories.Limits.BinProduct open import Cubical.Categories.Limits.BinCoproduct open import Cubical.Categories.Monad.Base +open import Cubical.Categories.Comonad.Instances.Environment open import Cubical.Categories.Exponentials open import Cubical.Data.List hiding ([_]) -open import Semantics.Abstract.TermModel.Strength open import Syntax.Types open import Syntax.Terms open import Semantics.Abstract.TermModel.Convenient +open import Semantics.Abstract.TermModel.Convenient.Linear private variable @@ -48,6 +49,8 @@ module _ (𓜠: Model â„“ â„“') where module 𓜠= Model 𓜠module T = IsMonad (ð“œ.monad .snd) ⇒F = ExponentialF ð“œ.cat ð“œ.binProd ð“œ.exponentials + open StrengthNotation 𓜠+ ⟦_⟧ty : Ty → ð“œ.cat .ob ⟦ nat ⟧ty = ð“œ.nat ⟦ dyn ⟧ty = ð“œ.dyn @@ -57,16 +60,15 @@ module _ (𓜠: Model â„“ â„“') where ⟦_⟧p : S ⊑ R → ð“œ.cat [ ⟦ R ⟧ty , ð“œ.T ⟅ ⟦ S ⟧ty ⟆ ] ⟦_⟧p' : S ⊑ R → ð“œ.cat [ ð“œ.T ⟅ ⟦ R ⟧ty ⟆ , ð“œ.T ⟅ ⟦ S ⟧ty ⟆ ] - ⟦ nat ⟧e = ð“œ.cat .id ⟦ dyn ⟧e = ð“œ.cat .id -- The most annoying one because it's not from bifunctoriality, more like separate functoriality -- λ f . λ x . x' <- p x; -- y' <- app(f,x'); -- η (e y') - ⟦ c ⇀ d ⟧e = ð“œ.lda ((ð“œ.ret ∘⟨ ð“œ.cat ⟩ ⟦ d ⟧e) ð“œ.∘k - (ð“œ.app' (ð“œ.π₠∘⟨ ð“œ.cat ⟩ ð“œ.Ï€â‚) ð“œ.π₂ ð“œ.∘sk - (⟦ c ⟧p ∘⟨ ð“œ.cat ⟩ ð“œ.π₂))) + ⟦ c ⇀ d ⟧e = ð“œ.lda ((ð“œ.ret ∘⟨ ð“œ.cat ⟩ ⟦ d ⟧e) ∘⟨ ClosedLinear ⟩ + ð“œ.app ∘⟨ Linear _ ⟩ + wkClosed _ ⟪ ⟦ c ⟧p ⟫) ⟦ inj-nat ⟧e = ð“œ.inj ∘⟨ ð“œ.cat ⟩ ð“œ.σ1 ⟦ inj-arr c ⟧e = ð“œ.inj ∘⟨ ð“œ.cat ⟩ ð“œ.σ2 ∘⟨ ð“œ.cat ⟩ ⟦ c ⟧e @@ -74,8 +76,8 @@ module _ (𓜠: Model â„“ â„“') where ⟦ dyn ⟧p = ð“œ.ret -- = η ∘ (⟦ c ⟧e ⇒ ⟦ d ⟧p') ⟦ c ⇀ d ⟧p = ð“œ.ret ∘⟨ ð“œ.cat ⟩ ⇒F ⟪ ⟦ c ⟧e , ⟦ d ⟧p' ⟫ - ⟦ inj-nat ⟧p = (ð“œ.ret ð“œ.|| ð“œ.℧) ð“œ.∘k ð“œ.prj - ⟦ inj-arr c ⟧p = (ð“œ.℧ ð“œ.|| ⟦ c ⟧p) ð“œ.∘k ð“œ.prj + ⟦ inj-nat ⟧p = (ð“œ.ret ð“œ.|| ð“œ.℧) ∘⟨ ClosedLinear ⟩ ð“œ.prj + ⟦ inj-arr c ⟧p = (ð“œ.℧ ð“œ.|| ⟦ c ⟧p) ∘⟨ ClosedLinear ⟩ ð“œ.prj ⟦ c ⟧p' = T.bind .N-ob _ ⟦ c ⟧p @@ -88,7 +90,7 @@ module _ (𓜠: Model â„“ â„“') where ⟦_⟧S : Subst Δ Γ → ð“œ.cat [ ⟦ Δ ⟧ctx , ⟦ Γ ⟧ctx ] ⟦_⟧V : Val Γ S → ð“œ.cat [ ⟦ Γ ⟧ctx , ⟦ S ⟧ty ] - ⟦_⟧E : EvCtx Γ R S → ð“œ.cat [ ⟦ Γ ⟧ctx ð“œ.× ⟦ R ⟧ty , ð“œ.T ⟅ ⟦ S ⟧ty ⟆ ] + ⟦_⟧E : EvCtx Γ R S → Linear ⟦ Γ ⟧ctx [ ⟦ R ⟧ty , ⟦ S ⟧ty ] ⟦_⟧C : Comp Γ S → ð“œ.cat [ ⟦ Γ ⟧ctx , ð“œ.T ⟅ ⟦ S ⟧ty ⟆ ] ⟦ ids ⟧S = ð“œ.cat .id @@ -116,21 +118,20 @@ module _ (𓜠: Model â„“ â„“') where ⟦ up S⊑T ⟧V = ⟦ S⊑T .ty-prec ⟧e ∘⟨ ð“œ.cat ⟩ ð“œ.π₂ ⟦ isSetVal V V' p q i j ⟧V = ð“œ.cat .isSetHom ⟦ V ⟧V ⟦ V' ⟧V (cong ⟦_⟧V p) (cong ⟦_⟧V q) i j - -- | TODO: potential for generalization - -- | This is a general construction of a category from a strong monad, the "simple Kleisli slice" - ⟦ ∙E ⟧E = ð“œ.ret ∘⟨ ð“œ.cat ⟩ ð“œ.π₂ - ⟦ E ∘E F ⟧E = {!!} - ⟦ ∘IdL i ⟧E = {!!} - ⟦ ∘IdR i ⟧E = {!!} - ⟦ ∘Assoc i ⟧E = {!!} - ⟦ E [ γ ]e ⟧E = {!!} + ⟦ ∙E ⟧E = Linear _ .id + ⟦ E ∘E F ⟧E = ⟦ E ⟧E ∘⟨ Linear _ ⟩ ⟦ F ⟧E + ⟦ ∘IdL {E = E} i ⟧E = Linear _ .⋆IdR ⟦ E ⟧E i + ⟦ ∘IdR {E = E} i ⟧E = Linear _ .⋆IdL ⟦ E ⟧E i + ⟦ ∘Assoc {E = E}{F = F}{F' = F'} i ⟧E = Linear _ .⋆Assoc ⟦ F' ⟧E ⟦ F ⟧E ⟦ E ⟧E i + ⟦ E [ γ ]e ⟧E = (⟦ γ ⟧S ^*) ⟪ ⟦ E ⟧E ⟫ + -- TODO: upstream, show change-of-comonad is functorial in the morphism of distributive laws ⟦ substId i ⟧E = {!!} ⟦ substAssoc i ⟧E = {!!} - ⟦ ∙substDist i ⟧E = {!!} - ⟦ ∘substDist i ⟧E = {!!} - ⟦ bind x ⟧E = {!!} + ⟦ ∙substDist {γ = γ} i ⟧E = (⟦ γ ⟧S ^*) .F-id i + ⟦ ∘substDist {E = E}{F = F}{γ = γ} i ⟧E = (⟦ γ ⟧S ^*) .F-seq ⟦ F ⟧E ⟦ E ⟧E i + ⟦ bind M ⟧E = ⟦ M ⟧C ⟦ ret-η i ⟧E = {!!} - ⟦ dn S⊑T ⟧E = ⟦ S⊑T .ty-prec ⟧p ∘⟨ ð“œ.cat ⟩ ð“œ.π₂ + ⟦ dn S⊑T ⟧E = wkClosed ð“œ.🙠⟪ ⟦ S⊑T .ty-prec ⟧p ⟫ ⟦ isSetEvCtx E F p q i j ⟧E = ð“œ.cat .isSetHom ⟦ E ⟧E ⟦ F ⟧E (cong ⟦_⟧E p) (cong ⟦_⟧E q) i j ⟦_⟧C = {!!} -- GitLab