Skip to content

Commit

Permalink
Fix performance issues
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulc29 committed Jul 7, 2024
1 parent 0c8e626 commit 75c6f59
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 115 deletions.
99 changes: 15 additions & 84 deletions src/Realizability/Modest/GenericUniformFamily.agda
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ open import Realizability.Modest.Base ca
open import Realizability.Modest.UniformFamily ca
open import Realizability.Modest.CanonicalPER ca
open import Realizability.Modest.UnresizedGeneric ca
open import Realizability.Modest.SubquotientUniformFamily ca resizing
open import Realizability.PERs.PER ca
open import Realizability.PERs.ResizedPER ca resizing
open import Realizability.PERs.SubQuotient ca
Expand All @@ -46,100 +47,30 @@ open Contravariant UNIMOD
open UniformFamily
open DisplayedUFamMap

uniformFamilyCleavage : cleavage
uniformFamilyCleavage {X , asmX} {Y , asmY} f N =
N' , fᴰ , cartfᴰ where
N' : UniformFamily asmX
UniformFamily.carriers N' x = N .carriers (f .map x)
UniformFamily.assemblies N' x = N .assemblies (f .map x)
UniformFamily.isModestFamily N' x = N .isModestFamily (f .map x)

fᴰ : DisplayedUFamMap asmX asmY f N' N
DisplayedUFamMap.fibrewiseMap fᴰ x Nfx = Nfx
DisplayedUFamMap.isTracked fᴰ =
do
let
realizer : Term as 2
realizer = # zero
return
(λ*2 realizer ,
(λ x a a⊩x Nfx b b⊩Nfx
subst
(_⊩[ N .assemblies (f .map x) ] Nfx)
(sym (λ*2ComputationRule realizer a b))
b⊩Nfx))

opaque
unfolding isCartesian'
cart'fᴰ : isCartesian' f fᴰ
cart'fᴰ {Z , asmZ} {M} g hᴰ =
(! , !⋆fᴰ≡hᴰ) ,
λ { (!' , !'comm)
Σ≡Prop
(λ ! UNIMOD .Categoryᴰ.isSetHomᴰ _ _)
(DisplayedUFamMapPathP
_ _ _ _ _ _ _ _ _
λ z Mz
sym
(!' .fibrewiseMap z Mz
≡[ i ]⟨ !'comm i .fibrewiseMap z Mz ⟩
hᴰ .fibrewiseMap z Mz
∎)) } where
! : DisplayedUFamMap asmZ asmX g M N'
DisplayedUFamMap.fibrewiseMap ! z Mz = hᴰ .fibrewiseMap z Mz
DisplayedUFamMap.isTracked ! = hᴰ .isTracked

!⋆fᴰ≡hᴰ : composeDisplayedUFamMap asmZ asmX asmY g f M N' N ! fᴰ ≡ hᴰ
!⋆fᴰ≡hᴰ =
DisplayedUFamMapPathP
asmZ asmY _ _
M N
(composeDisplayedUFamMap asmZ asmX asmY g f M N' N ! fᴰ) hᴰ refl
λ z Mz refl

cartfᴰ : isCartesian f fᴰ
cartfᴰ = isCartesian'→isCartesian f fᴰ cart'fᴰ


∇PER = ∇ ⟅ ResizedPER , isSetResizedPER ⟆
asm∇PER = ∇PER .snd
private
∇PER = ∇ ⟅ ResizedPER , isSetResizedPER ⟆
asm∇PER = ∇PER .snd

genericUniformFamily : GenericObject UNIMOD
GenericObject.base genericUniformFamily = ∇PER
UniformFamily.carriers (GenericObject.displayed genericUniformFamily) per = subQuotient (enlargePER per)
UniformFamily.assemblies (GenericObject.displayed genericUniformFamily) per = subQuotientAssembly (enlargePER per)
UniformFamily.isModestFamily (GenericObject.displayed genericUniformFamily) per = isModestSubQuotientAssembly (enlargePER per)
GenericObject.displayed genericUniformFamily = subQuotientUniformFamily
GenericObject.isGeneric genericUniformFamily {X , asmX} M =
f , fᴰ , isCartesian'→isCartesian f fᴰ cart' where

f : AssemblyMorphism asmX asm∇PER
AssemblyMorphism.map f x = shrinkPER (canonicalPER (M .assemblies x) (M .isModestFamily x))
AssemblyMorphism.tracker f = return (k , (λ _ _ _ tt*))
f = classifyingMap M

subQuotientCod≡ : per subQuotient (enlargePER (shrinkPER per)) ≡ subQuotient per
subQuotientCod≡ per = cong subQuotient (enlargePER⋆shrinkPER≡id per)

fᴰ : DisplayedUFamMap asmX asm∇PER f M (genericUniformFamily .GenericObject.displayed)
DisplayedUFamMap.fibrewiseMap fᴰ x Mx =
subst
subQuotient
(sym
(enlargePER⋆shrinkPER≡id
(canonicalPER (M .assemblies x) (M .isModestFamily x))))
(Unresized.mainMap resizing asmX M x Mx)
DisplayedUFamMap.isTracked fᴰ =
do
return
(λ*2 (# one) ,
(λ x a a⊩x Mx b b⊩Mx
equivFun
(propTruncIdempotent≃ {!!})
(do
(r , r⊩mainMap) Unresized.isTrackedMainMap resizing asmX M
return {!!})))
opaque
unfolding Unresized.mainMap
fᴰ : DisplayedUFamMap asmX asm∇PER f M (genericUniformFamily .GenericObject.displayed)
fᴰ = classifyingMapᴰ M

opaque
unfolding isCartesian'
cart' : isCartesian' f fᴰ
cart' {Y , asmY} {N} g hᴰ = {!!}
cart' {Y , asmY} {N} g hᴰ =
(! , {!!}) , {!!} where
! : DisplayedUFamMap asmY asmX g N M
DisplayedUFamMap.fibrewiseMap ! y Ny = {!hᴰ .fibrewiseMap y Ny!}
DisplayedUFamMap.isTracked ! = {!!}

100 changes: 100 additions & 0 deletions src/Realizability/Modest/SubquotientUniformFamily.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Path
open import Cubical.Foundations.Structure using (⟨_⟩; str)
open import Cubical.Data.Sigma
open import Cubical.Data.FinData
open import Cubical.Data.Unit
open import Cubical.HITs.PropositionalTruncation as PT hiding (map)
open import Cubical.HITs.PropositionalTruncation.Monad
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.Reflection.RecordEquiv
open import Cubical.Categories.Category
open import Cubical.Categories.Displayed.Base
open import Cubical.Categories.Displayed.Reasoning
open import Cubical.Categories.Limits.Pullback
open import Cubical.Categories.Functor hiding (Id)
open import Cubical.Categories.Constructions.Slice
open import Categories.CartesianMorphism
open import Categories.GenericObject
open import Realizability.CombinatoryAlgebra
open import Realizability.ApplicativeStructure
open import Realizability.PropResizing

module Realizability.Modest.SubquotientUniformFamily {ℓ} {A : Type ℓ} (ca : CombinatoryAlgebra A) (resizing : hPropResizing ℓ) where

open import Realizability.Assembly.Base ca
open import Realizability.Assembly.Morphism ca
open import Realizability.Assembly.Terminal ca
open import Realizability.Assembly.SetsReflectiveSubcategory ca
open import Realizability.Modest.Base ca
open import Realizability.Modest.UniformFamily ca
open import Realizability.Modest.CanonicalPER ca
open import Realizability.Modest.UnresizedGeneric ca
open import Realizability.PERs.PER ca
open import Realizability.PERs.ResizedPER ca resizing
open import Realizability.PERs.SubQuotient ca

open Assembly
open CombinatoryAlgebra ca
open Realizability.CombinatoryAlgebra.Combinators ca renaming (i to Id; ia≡a to Ida≡a)
open Contravariant UNIMOD
open UniformFamily
open DisplayedUFamMap

private
∇PER = ∇ ⟅ ResizedPER , isSetResizedPER ⟆
asm∇PER = ∇PER .snd

-- G over ∇PER
subQuotientUniformFamily : UniformFamily asm∇PER
UniformFamily.carriers subQuotientUniformFamily per = subQuotient (enlargePER per)
UniformFamily.assemblies subQuotientUniformFamily per = subQuotientAssembly (enlargePER per)
UniformFamily.isModestFamily subQuotientUniformFamily per = isModestSubQuotientAssembly (enlargePER per)

-- For any uniform family M over X
-- there is a map to the canonical uniform family G over ∇PER
module _
{X : Type ℓ}
{asmX : Assembly X}
(M : UniformFamily asmX) where

classifyingMap : AssemblyMorphism asmX asm∇PER
AssemblyMorphism.map classifyingMap x = shrinkPER (canonicalPER (M .assemblies x) (M .isModestFamily x))
AssemblyMorphism.tracker classifyingMap = return (k , (λ _ _ _ tt*))

opaque
unfolding Unresized.mainMap
classifyingMapᴰ : DisplayedUFamMap asmX asm∇PER classifyingMap M subQuotientUniformFamily
DisplayedUFamMap.fibrewiseMap classifyingMapᴰ x Mx =
subst
subQuotient
(sym
(enlargePER⋆shrinkPER≡id
(canonicalPER (M .assemblies x) (M .isModestFamily x))))
(Unresized.mainMap resizing asmX M x Mx .fst)
DisplayedUFamMap.isTracked classifyingMapᴰ =
return
((λ*2 (# zero)) ,
(λ x a a⊩x Mx b b⊩Mx
-- Is there a way to do this that avoids transp ?
-- This really eats type-checking time
transp
(λ i
subQuotientRealizability
(enlargePER⋆shrinkPER≡id
(canonicalPER (M .assemblies x) (M .isModestFamily x)) (~ i))
(λ*2 (# zero) ⨾ a ⨾ b)
(subst-filler
subQuotient
(sym
(enlargePER⋆shrinkPER≡id
(canonicalPER (M .assemblies x) (M .isModestFamily x))))
(Unresized.mainMap resizing asmX M x Mx .fst) i)
⟩) i0 (Unresized.mainMap resizing asmX M x Mx .snd a a⊩x b b⊩Mx)))

100 changes: 100 additions & 0 deletions src/Realizability/Modest/UniformFamilyCleavage.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Path
open import Cubical.Foundations.Structure using (⟨_⟩; str)
open import Cubical.Data.Sigma
open import Cubical.Data.FinData
open import Cubical.Data.Unit
open import Cubical.HITs.PropositionalTruncation as PT hiding (map)
open import Cubical.HITs.PropositionalTruncation.Monad
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.Reflection.RecordEquiv
open import Cubical.Categories.Category
open import Cubical.Categories.Displayed.Base
open import Cubical.Categories.Displayed.Reasoning
open import Cubical.Categories.Limits.Pullback
open import Cubical.Categories.Functor hiding (Id)
open import Cubical.Categories.Constructions.Slice
open import Categories.CartesianMorphism
open import Categories.GenericObject
open import Realizability.CombinatoryAlgebra
open import Realizability.ApplicativeStructure
open import Realizability.PropResizing

module Realizability.Modest.UniformFamilyCleavage {ℓ} {A : Type ℓ} (ca : CombinatoryAlgebra A) where

open import Realizability.Assembly.Base ca
open import Realizability.Assembly.Morphism ca
open import Realizability.Assembly.Terminal ca
open import Realizability.Assembly.SetsReflectiveSubcategory ca
open import Realizability.Modest.Base ca
open import Realizability.Modest.UniformFamily ca
open import Realizability.Modest.CanonicalPER ca
open import Realizability.Modest.UnresizedGeneric ca
open import Realizability.PERs.PER ca
open import Realizability.PERs.SubQuotient ca

open Assembly
open CombinatoryAlgebra ca
open Realizability.CombinatoryAlgebra.Combinators ca renaming (i to Id; ia≡a to Ida≡a)
open Contravariant UNIMOD
open UniformFamily
open DisplayedUFamMap

uniformFamilyCleavage : cleavage
uniformFamilyCleavage {X , asmX} {Y , asmY} f N =
N' , fᴰ , cartfᴰ where
N' : UniformFamily asmX
UniformFamily.carriers N' x = N .carriers (f .map x)
UniformFamily.assemblies N' x = N .assemblies (f .map x)
UniformFamily.isModestFamily N' x = N .isModestFamily (f .map x)

fᴰ : DisplayedUFamMap asmX asmY f N' N
DisplayedUFamMap.fibrewiseMap fᴰ x Nfx = Nfx
DisplayedUFamMap.isTracked fᴰ =
do
let
realizer : Term as 2
realizer = # zero
return
(λ*2 realizer ,
(λ x a a⊩x Nfx b b⊩Nfx
subst
(_⊩[ N .assemblies (f .map x) ] Nfx)
(sym (λ*2ComputationRule realizer a b))
b⊩Nfx))

opaque
unfolding isCartesian'
cart'fᴰ : isCartesian' f fᴰ
cart'fᴰ {Z , asmZ} {M} g hᴰ =
(! , !⋆fᴰ≡hᴰ) ,
λ { (!' , !'comm)
Σ≡Prop
(λ ! UNIMOD .Categoryᴰ.isSetHomᴰ _ _)
(DisplayedUFamMapPathP
_ _ _ _ _ _ _ _ _
λ z Mz
sym
(!' .fibrewiseMap z Mz
≡[ i ]⟨ !'comm i .fibrewiseMap z Mz ⟩
hᴰ .fibrewiseMap z Mz
∎)) } where
! : DisplayedUFamMap asmZ asmX g M N'
DisplayedUFamMap.fibrewiseMap ! z Mz = hᴰ .fibrewiseMap z Mz
DisplayedUFamMap.isTracked ! = hᴰ .isTracked

!⋆fᴰ≡hᴰ : composeDisplayedUFamMap asmZ asmX asmY g f M N' N ! fᴰ ≡ hᴰ
!⋆fᴰ≡hᴰ =
DisplayedUFamMapPathP
asmZ asmY _ _
M N
(composeDisplayedUFamMap asmZ asmX asmY g f M N' N ! fᴰ) hᴰ refl
λ z Mz refl

cartfᴰ : isCartesian f fᴰ
cartfᴰ = isCartesian'→isCartesian f fᴰ cart'fᴰ
66 changes: 35 additions & 31 deletions src/Realizability/Modest/UnresizedGeneric.agda
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,40 @@ module Unresized
theCanonicalPER : x PER
theCanonicalPER x = canonicalPER (M . assemblies x) (M .isModestFamily x)

elimRealizerForMx : {x : X} {Mx : M .carriers x} Σ[ a ∈ A ] (a ⊩[ M .assemblies x ] Mx) subQuotient (canonicalPER (M .assemblies x) (M .isModestFamily x))
elimRealizerForMx {x} {Mx} (a , a⊩Mx) = [ a , (return (Mx , a⊩Mx , a⊩Mx)) ]

elimRealizerForMx2Constant : {x Mx} 2-Constant (elimRealizerForMx {x} {Mx})
elimRealizerForMx2Constant {x} {Mx} (a , a⊩Mx) (b , b⊩Mx) =
eq/
(a , (return (Mx , a⊩Mx , a⊩Mx)))
(b , return (Mx , b⊩Mx , b⊩Mx))
(return (Mx , a⊩Mx , b⊩Mx))
elimRealizerForMx : (x : X) (Mx : M .carriers x) Σ[ a ∈ A ] (a ⊩[ M .assemblies x ] Mx) subQuotient (canonicalPER (M .assemblies x) (M .isModestFamily x))
elimRealizerForMx x Mx (a , a⊩Mx) = [ a , (return (Mx , a⊩Mx , a⊩Mx)) ]

mainMap : (x : X) (Mx : M .carriers x) subQuotient (canonicalPER (M .assemblies x) (M .isModestFamily x))
mainMap x Mx =
PT.rec→Set
squash/
(elimRealizerForMx {x = x} {Mx = Mx})
(elimRealizerForMx2Constant {x = x} {Mx = Mx})
(M .assemblies x .⊩surjective Mx)

opaque
isTrackedMainMap : ∃[ r ∈ A ] ( (x : X) (a : A) a ⊩[ asmX ] x (Mx : M .carriers x) (b : A) b ⊩[ M .assemblies x ] Mx (r ⨾ a ⨾ b) ⊩[ subQuotientAssembly (theCanonicalPER x) ] (mainMap x Mx))
isTrackedMainMap =
return
((λ*2 (# zero)) ,
(λ x a a⊩x Mx b b⊩Mx
PT.elim
{P = λ MxRealizer (λ*2 (# zero) ⨾ a ⨾ b) ⊩[ subQuotientAssembly (theCanonicalPER x) ] (PT.rec→Set squash/ (elimRealizerForMx {x = x} {Mx = Mx}) (elimRealizerForMx2Constant {x = x} {Mx = Mx}) MxRealizer)}
(λ ⊩Mx subQuotientAssembly (theCanonicalPER x) .⊩isPropValued (λ*2 (# zero) ⨾ a ⨾ b) (rec→Set squash/ elimRealizerForMx elimRealizerForMx2Constant ⊩Mx))
(λ { (c , c⊩Mx)
subst
(_⊩[ subQuotientAssembly (theCanonicalPER x) ] (elimRealizerForMx (c , c⊩Mx)))
(sym (λ*2ComputationRule (# zero) a b))
(return (Mx , b⊩Mx , c⊩Mx))})
(M .assemblies x .⊩surjective Mx)))
elimRealizerForMx2Constant : x Mx 2-Constant (elimRealizerForMx x Mx)
elimRealizerForMx2Constant x Mx (a , a⊩Mx) (b , b⊩Mx) =
eq/
(a , (return (Mx , a⊩Mx , a⊩Mx)))
(b , return (Mx , b⊩Mx , b⊩Mx))
(return (Mx , a⊩Mx , b⊩Mx))

mainMapType : Type _
mainMapType =
(x : X) (Mx : M .carriers x)
Σ[ out ∈ (subQuotient (canonicalPER (M .assemblies x) (M .isModestFamily x))) ]
( (a : A) a ⊩[ asmX ] x (b : A) b ⊩[ M .assemblies x ] Mx (λ*2 (# zero) ⨾ a ⨾ b) ⊩[ subQuotientAssembly (theCanonicalPER x) ] out)

opaque
mainMap : mainMapType
mainMap x Mx =
PT.rec→Set
(isSetΣ
squash/
(λ out
isSetΠ3
λ a a⊩x b
isSet→
(isProp→isSet
(str
(subQuotientRealizability (theCanonicalPER x) (λ*2 (# zero) ⨾ a ⨾ b) out)))))
((λ { (c , c⊩Mx)
(elimRealizerForMx x Mx (c , c⊩Mx)) ,
(λ a a⊩x b b⊩Mx
subst (_⊩[ subQuotientAssembly (theCanonicalPER x) ] (elimRealizerForMx x Mx (c , c⊩Mx))) (sym (λ*2ComputationRule (# zero) a b)) (return (Mx , b⊩Mx , c⊩Mx))) }))
(λ { (a , a⊩Mx) (b , b⊩Mx)
Σ≡Prop (λ out isPropΠ4 λ a a⊩x b b⊩Mx str (subQuotientRealizability (theCanonicalPER x) (λ*2 (# zero) ⨾ a ⨾ b) out)) (elimRealizerForMx2Constant x Mx (a , a⊩Mx) (b , b⊩Mx)) })
(M .assemblies x .⊩surjective Mx)

0 comments on commit 75c6f59

Please sign in to comment.