Skip to content

Commit

Permalink
Finite Limits for PERs
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulc29 committed Jun 25, 2024
1 parent 827bf93 commit 41d4f18
Show file tree
Hide file tree
Showing 6 changed files with 395 additions and 177 deletions.
70 changes: 17 additions & 53 deletions src/Realizability/Assembly/LocallyCartesianClosed.agda
Original file line number Diff line number Diff line change
Expand Up @@ -270,63 +270,27 @@ module _ {X Y : Type ℓ} {asmX : Assembly X} {asmY : Assembly Y} (f : AssemblyM
(sym (λ*ComputationRule realizer a))
(isTrackedH v (pr₂ ⨾ a) pr₂a⊩v .snd (x , sym (isFiberOfY x v fx≡gv)) (pr₁ ⨾ a) pr₁a⊩x) }))

opaque
unfolding pullback
unfolding answer
unfolding answerMap
answerEq : answer ⊚ m ≡ (reindexFunctor ASM PullbacksASM f ⟅ sliceob g ⟆) .S-arr
answerEq =
AssemblyMorphism≡ _ _
(funExt
λ { q@(x , v , fx≡gv)
m .map (answerMap q)
≡⟨ refl ⟩
m .map (h .map v .fst .snd .fst (x , sym (isFiberOfY x v fx≡gv)))
≡⟨ h .map v .fst .snd .snd (x , sym (isFiberOfY x v fx≡gv)) ⟩
x
∎ })

opaque
unfolding pullback
reindex⊣Π[_] : reindexFunctor ASM PullbacksASM f ⊣ Π[_]
Iso.fun (_⊣_.adjIso reindex⊣Π[_] {sliceob {V , asmV} g} {sliceob {P , asmP} m}) (slicehom h hComm) = slicehom (ForwardIso.answer g m h hComm) (ForwardIso.answerEq g m h hComm)
Iso.inv (_⊣_.adjIso reindex⊣Π[_] {sliceob {V , asmV} g} {sliceob {P , asmP} m}) (slicehom h hComm) =
slicehom answer (AssemblyMorphism≡ _ _ (funExt λ { (x , v , fx≡gv) answerEq x v fx≡gv })) where
Π[f]m : AssemblyMorphism (S-ob (Π[_] ⟅ sliceob m ⟆) .snd) asmY
Π[f]m = (Π[_] ⟅ sliceob m ⟆) .S-arr

Q : ASM .Category.ob
Q = (reindexFunctor ASM PullbacksASM f ⟅ sliceob g ⟆) .S-ob

typeQ : Type ℓ
typeQ = Q .fst

asmQ : Assembly typeQ
asmQ = Q .snd

isFiberOfY : (x : X) (v : V) f .map x ≡ g .map v h .map v .fst .fst ≡ f .map x
isFiberOfY x v fx≡gv =
h .map v .fst .fst
≡[ i ]⟨ hComm i .map v ⟩
g .map v
≡⟨ sym fx≡gv ⟩
f .map x

answerMap : typeQ P
answerMap (x , v , fx≡gv) =
h .map v .fst .snd .fst
(x ,
sym (isFiberOfY x v fx≡gv))

answerEq : (x : X) (v : V) (fx≡gv : f .map x ≡ g .map v) m .map (answerMap (x , v , fx≡gv)) ≡ x
answerEq x v fx≡gv =
m .map (answerMap (x , v , fx≡gv))
≡⟨ refl ⟩
m .map (h .map v .fst .snd .fst (x , sym (isFiberOfY x v fx≡gv)))
≡⟨ h .map v .fst .snd .snd (x , sym (isFiberOfY x v fx≡gv)) ⟩
x

answer : AssemblyMorphism asmQ asmP
AssemblyMorphism.map answer = answerMap
AssemblyMorphism.tracker answer =
do
(h~ , isTrackedH) h .tracker
let
realizer : Term as 1
realizer = ` pr₂ ̇ (` h~ ̇ (` pr₂ ̇ # zero)) ̇ (` pr₁ ̇ # zero)
return
(λ* realizer ,
(λ { q@(x , v , fx≡gv) a (pr₁a⊩x , pr₂a⊩v)
subst
(λ r' r' ⊩[ asmP ] (answerMap (x , v , fx≡gv)))
(sym (λ*ComputationRule realizer a))
(isTrackedH v (pr₂ ⨾ a) pr₂a⊩v .snd (x , sym (isFiberOfY x v fx≡gv)) (pr₁ ⨾ a) pr₁a⊩x) }))
Iso.inv (_⊣_.adjIso reindex⊣Π[_] {sliceob {V , asmV} g} {sliceob {P , asmP} m}) (slicehom h hComm) = slicehom (BackwardIso.answer g m h hComm) (BackwardIso.answerEq g m h hComm)
Iso.rightInv (_⊣_.adjIso reindex⊣Π[_] {sliceob {V , asmV} g} {sliceob {P , asmP} m}) (slicehom h hComm) =
SliceHom-≡-intro'
ASM
Expand Down
2 changes: 2 additions & 0 deletions src/Realizability/Modest/UniformFamily.agda
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,7 @@ Categoryᴰ.⋆Assocᴰ UNIMOD
ΣPathPProp (λ comp isSetAssemblyMorphism asmXᴰ asmW _ _) (Category.⋆Assoc ASM fᵈ gᵈ hᵈ )
Categoryᴰ.isSetHomᴰ UNIMOD = isSetΣ (isSetAssemblyMorphism _ _) (λ f isProp→isSet (isSetAssemblyMorphism _ _ _ _))

open Categoryᴰ UNIMOD

UniformFamily : {X : Type ℓ} (asmX : Assembly X) Type (ℓ-suc ℓ)
UniformFamily {X} asmX = UNIMOD .Categoryᴰ.ob[_] (X , asmX)
196 changes: 196 additions & 0 deletions src/Realizability/PERs/BinProducts.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
open import Realizability.ApplicativeStructure
open import Realizability.CombinatoryAlgebra
open import Realizability.PropResizing
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Structure using (⟨_⟩; str)
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Powerset
open import Cubical.Functions.FunExtEquiv
open import Cubical.Relation.Binary
open import Cubical.Data.Sigma
open import Cubical.Data.FinData
open import Cubical.Data.Unit
open import Cubical.Reflection.RecordEquiv
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.Categories.Category
open import Cubical.Categories.Limits.BinProduct
open import Utils.SQElim as SQElim

module Realizability.PERs.BinProducts
{ℓ} {A : Type ℓ} (ca : CombinatoryAlgebra A) where

open import Realizability.PERs.PER ca
open CombinatoryAlgebra ca
open Combinators ca renaming (i to Id; ia≡a to Ida≡a)
open PER
open Category PERCat

module _ (R S : PER) where
binProdObPER : PER
PER.relation binProdObPER =
(λ a b (pr₁ ⨾ a) ~[ R ] (pr₁ ⨾ b) × (pr₂ ⨾ a) ~[ S ] (pr₂ ⨾ b)) , λ a b isProp× (isProp~ (pr₁ ⨾ a) R (pr₁ ⨾ b)) (isProp~ (pr₂ ⨾ a) S (pr₂ ⨾ b))
fst (isPER binProdObPER) a b (pr₁a~[R]pr₁b , pr₂a~[S]pr₂b) =
(isSymmetric R (pr₁ ⨾ a) (pr₁ ⨾ b) pr₁a~[R]pr₁b) , (isSymmetric S (pr₂ ⨾ a) (pr₂ ⨾ b) pr₂a~[S]pr₂b)
snd (isPER binProdObPER) a b c (pr₁a~[R]pr₁b , pr₂a~[S]pr₂b) (pr₁b~[R]pr₁c , pr₂b~[S]pr₂c) =
(isTransitive R (pr₁ ⨾ a) (pr₁ ⨾ b) (pr₁ ⨾ c) pr₁a~[R]pr₁b pr₁b~[R]pr₁c) , (isTransitive S (pr₂ ⨾ a) (pr₂ ⨾ b) (pr₂ ⨾ c) pr₂a~[S]pr₂b pr₂b~[S]pr₂c)

isTrackerPr₁ : isTracker binProdObPER R pr₁
isTrackerPr₁ = λ r r' (pr₁r~[R]pr₁r' , pr₂r~[S]pr₂r') pr₁r~[R]pr₁r'

binProdPr₁Tracker : perTracker binProdObPER R
binProdPr₁Tracker = pr₁ , isTrackerPr₁

binProdPr₁PER : perMorphism binProdObPER R
binProdPr₁PER = [ binProdPr₁Tracker ]

isTrackerPr₂ : isTracker binProdObPER S pr₂
isTrackerPr₂ = λ { r r' (pr₁r~[R]pr₁r' , pr₂r~[S]pr₂r') pr₂r~[S]pr₂r' }

binProdPr₂Tracker : perTracker binProdObPER S
binProdPr₂Tracker = pr₂ , isTrackerPr₂

binProdPr₂PER : perMorphism binProdObPER S
binProdPr₂PER = [ binProdPr₂Tracker ]

binProdUnivPropPER :
(T : PER)
(f : perMorphism T R)
(g : perMorphism T S)
∃![ ! ∈ perMorphism T binProdObPER ] ((composePerMorphism T binProdObPER R ! binProdPr₁PER ≡ f) × (composePerMorphism T binProdObPER S ! binProdPr₂PER ≡ g))
binProdUnivPropPER T f g =
inhProp→isContr
map
(isPropMapType f g) where

mapEqProj1 : ! f' Type _
mapEqProj1 ! f' = composePerMorphism T binProdObPER R ! binProdPr₁PER ≡ f'

mapEqProj2 : ! g' Type _
mapEqProj2 ! g' = composePerMorphism T binProdObPER S ! binProdPr₂PER ≡ g'

mapEqs : ! f' g' Type _
mapEqs ! f' g' = (composePerMorphism T binProdObPER R ! binProdPr₁PER ≡ f') × (composePerMorphism T binProdObPER S ! binProdPr₂PER ≡ g')

isPropMapEqs : ! f' g' isProp (mapEqs ! f' g')
isPropMapEqs ! f' g' = isProp× (squash/ _ _) (squash/ _ _)

mapType : f' g' Type _
mapType f' g' = Σ[ ! ∈ perMorphism T binProdObPER ] (mapEqs ! f' g')

mapRealizer : a b Term as 1
mapRealizer a b = ` pair ̇ (` a ̇ # zero) ̇ (` b ̇ # zero)

isSetMapType : f' g' isSet (mapType f' g')
isSetMapType f' g' = isSetΣ squash/ (λ ! isSet× (isProp→isSet (squash/ _ _)) (isProp→isSet (squash/ _ _)))

isPropMapType : f' g' isProp (mapType f' g')
isPropMapType f' g' (! , !⋆π₁≡f , !⋆π₂≡g) (!' , !'⋆π₁≡f , !'⋆π₂≡g) =
Σ≡Prop
(λ ! isPropMapEqs ! f' g')
(SQ.elimProp4
{P = motive}
isPropMotive
goal
f' g' ! !'
!⋆π₁≡f
!⋆π₂≡g
!'⋆π₁≡f
!'⋆π₂≡g) where

motive : f' g' ! !' Type _
motive f' g' ! !' = (!proj1 : mapEqProj1 ! f') (!proj2 : mapEqProj2 ! g') (!'proj1 : mapEqProj1 !' f') (!'proj2 : mapEqProj2 !' g') ! ≡ !'

isPropMotive : f' g' ! !' isProp (motive f' g' ! !')
isPropMotive f' g' ! !' =
isPropΠ4 λ _ _ _ _ squash/ _ _

goal : f' g' ! !' motive [ f' ] [ g' ] [ ! ] [ !' ]
goal (f , f⊩f) (g , g⊩g) (a , a⊩!) (b , b⊩!') !proj1 !proj2 !'proj1 !'proj2 =
eq/ _ _
λ r r~r
let
pr₁Equiv : (pr₁ ⨾ (a ⨾ r)) ~[ R ] (pr₁ ⨾ (b ⨾ r))
pr₁Equiv =
isTransitive
R (pr₁ ⨾ (a ⨾ r)) (f ⨾ r) (pr₁ ⨾ (b ⨾ r))
(subst (_~[ R ] (f ⨾ r)) (λ*ComputationRule (` pr₁ ̇ (` a ̇ # zero)) r) (!proj1Equiv r r~r))
(isSymmetric R (pr₁ ⨾ (b ⨾ r)) (f ⨾ r) (subst (_~[ R ] (f ⨾ r)) (λ*ComputationRule (` pr₁ ̇ (` b ̇ # zero)) r) (!'proj1Equiv r r~r)))

pr₂Equiv : (pr₂ ⨾ (a ⨾ r)) ~[ S ] (pr₂ ⨾ (b ⨾ r))
pr₂Equiv =
isTransitive
S (pr₂ ⨾ (a ⨾ r)) (g ⨾ r) (pr₂ ⨾ (b ⨾ r))
(subst (_~[ S ] (g ⨾ r)) (λ*ComputationRule (` pr₂ ̇ (` a ̇ # zero)) r) (!proj2Equiv r r~r))
(isSymmetric S (pr₂ ⨾ (b ⨾ r)) (g ⨾ r) (subst (_~[ S ] (g ⨾ r)) (λ*ComputationRule (` pr₂ ̇ (` b ̇ # zero)) r) (!'proj2Equiv r r~r)))
in
pr₁Equiv ,
pr₂Equiv where
!proj1Equiv : isEquivTracker T R (composePerTracker T binProdObPER R (a , a⊩!) binProdPr₁Tracker) (f , f⊩f)
!proj1Equiv = effectiveIsEquivTracker T R _ _ !proj1

!proj2Equiv : isEquivTracker T S (composePerTracker T binProdObPER S (a , a⊩!) binProdPr₂Tracker) (g , g⊩g)
!proj2Equiv = effectiveIsEquivTracker T S _ _ !proj2

!'proj1Equiv : isEquivTracker T R (composePerTracker T binProdObPER R (b , b⊩!') binProdPr₁Tracker) (f , f⊩f)
!'proj1Equiv = effectiveIsEquivTracker T R _ _ !'proj1

!'proj2Equiv : isEquivTracker T S (composePerTracker T binProdObPER S (b , b⊩!') binProdPr₂Tracker) (g , g⊩g)
!'proj2Equiv = effectiveIsEquivTracker T S _ _ !'proj2

coreMap : a b mapType [ a ] [ b ]
coreMap (a , a⊩f) (b , b⊩g) =
[ (λ* (mapRealizer a b)) ,
(λ r r' r~r'
subst2
(λ abr abr' abr ~[ binProdObPER ] abr')
(sym (λ*ComputationRule (mapRealizer a b) r))
(sym (λ*ComputationRule (mapRealizer a b) r'))
(subst2
(λ ar ar' ar ~[ R ] ar')
(sym (pr₁pxy≡x _ _))
(sym (pr₁pxy≡x _ _))
(a⊩f r r' r~r') ,
subst2
(λ br br' br ~[ S ] br')
(sym (pr₂pxy≡y _ _))
(sym (pr₂pxy≡y _ _))
(b⊩g r r' r~r'))) ] ,
eq/ _ _
(λ r r~r
subst
(_~[ R ] (a ⨾ r))
(sym
(λ*ComputationRule (` pr₁ ̇ (` λ* (mapRealizer a b) ̇ # zero)) r ∙
cong (pr₁ ⨾_) (λ*ComputationRule (mapRealizer a b) r)))
(subst (_~[ R ] (a ⨾ r)) (sym (pr₁pxy≡x _ _)) (a⊩f r r r~r))) ,
eq/ _ _
λ r r~r
subst
(_~[ S ] (b ⨾ r))
(sym
(λ*ComputationRule (` pr₂ ̇ (` λ* (mapRealizer a b) ̇ # zero)) r ∙
cong (pr₂ ⨾_) (λ*ComputationRule (mapRealizer a b) r) ∙
pr₂pxy≡y _ _))
(b⊩g r r r~r)

map : mapType f g
map =
SQ.elimProp2
{P = mapType}
isPropMapType
coreMap
f g

BinProductPER : (R S : PER) BinProduct PERCat R S
BinProduct.binProdOb (BinProductPER R S) = binProdObPER R S
BinProduct.binProdPr₁ (BinProductPER R S) = binProdPr₁PER R S
BinProduct.binProdPr₂ (BinProductPER R S) = binProdPr₂PER R S
BinProduct.univProp (BinProductPER R S) {T} f g = binProdUnivPropPER R S T f g

BinProductsPER : BinProducts PERCat
BinProductsPER R S = BinProductPER R S
Loading

0 comments on commit 41d4f18

Please sign in to comment.