2018-02-02 14:33:54 +00:00
|
|
|
|
{-# OPTIONS --cubical --allow-unsolved-metas #-}
|
2018-01-08 21:48:59 +00:00
|
|
|
|
module Cat.Categories.Rel where
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
2018-01-30 10:19:48 +00:00
|
|
|
|
open import Cubical
|
2017-11-10 15:00:00 +00:00
|
|
|
|
open import Cubical.GradLemma
|
|
|
|
|
open import Agda.Primitive
|
2018-01-08 21:48:59 +00:00
|
|
|
|
open import Data.Product renaming (proj₁ to fst ; proj₂ to snd)
|
|
|
|
|
open import Function
|
|
|
|
|
import Cubical.FromStdLib
|
|
|
|
|
|
|
|
|
|
open import Cat.Category
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
-- Subsets are predicates over some type.
|
|
|
|
|
Subset : {ℓ : Level} → ( A : Set ℓ ) → Set (ℓ ⊔ lsuc lzero)
|
|
|
|
|
Subset A = A → Set
|
|
|
|
|
-- Subset : {ℓ ℓ' : Level} → ( A : Set ℓ ) → Set (ℓ ⊔ lsuc ℓ')
|
|
|
|
|
-- Subset {ℓ' = ℓ'} A = A → Set ℓ'
|
|
|
|
|
-- {a ∈ A | P a}
|
|
|
|
|
|
|
|
|
|
-- subset-syntax : {ℓ ℓ' : Level} → (A : Set ℓ) → (P : A → Set ℓ') → ( a : A ) → Set ℓ'
|
|
|
|
|
-- subset-syntax A P a = P a
|
|
|
|
|
-- infix 2 subset-syntax
|
|
|
|
|
|
|
|
|
|
-- syntax subset P a = << a ∈ A >>>
|
|
|
|
|
-- syntax subset P = ⦃ a ∈ A | P a ⦄
|
|
|
|
|
-- syntax subset-syntax A (λ a → B) = ⟨ a foo A ∣ B ⟩
|
|
|
|
|
|
2017-11-15 20:59:00 +00:00
|
|
|
|
-- Membership is (dependent) function applicatiom.
|
2017-11-10 15:00:00 +00:00
|
|
|
|
_∈_ : {ℓ : Level} {A : Set ℓ} → A → Subset A → Set
|
|
|
|
|
s ∈ S = S s
|
|
|
|
|
|
|
|
|
|
infixl 45 _∈_
|
|
|
|
|
|
|
|
|
|
-- The diagnoal of a set is a synonym for equality.
|
|
|
|
|
Diag : ∀ S → Subset (S × S)
|
2017-11-15 20:59:00 +00:00
|
|
|
|
Diag S (x , y) = x ≡ y
|
2017-11-10 15:00:00 +00:00
|
|
|
|
-- Diag S = subset (S × S) (λ {(p , q) → p ≡ q})
|
|
|
|
|
-- Diag S = ⟨ ? foo ? ∣ ? ⟩
|
|
|
|
|
-- Diag S (s₀ , s₁) = ⦃ (s₀ , s₁) ∈ S | s₀ ≡ s₁ ⦄
|
|
|
|
|
|
|
|
|
|
module _ {A B : Set} {S : Subset (A × B)} (ab : A × B) where
|
|
|
|
|
private
|
|
|
|
|
a : A
|
|
|
|
|
a = fst ab
|
|
|
|
|
b : B
|
|
|
|
|
b = snd ab
|
|
|
|
|
|
|
|
|
|
module _ where
|
|
|
|
|
private
|
|
|
|
|
forwards : ((a , b) ∈ S)
|
|
|
|
|
→ (Σ[ a' ∈ A ] (a , a') ∈ Diag A × (a' , b) ∈ S)
|
|
|
|
|
forwards ab∈S = a , (refl , ab∈S)
|
|
|
|
|
|
|
|
|
|
backwards : (Σ[ a' ∈ A ] (a , a') ∈ Diag A × (a' , b) ∈ S)
|
|
|
|
|
→ (a , b) ∈ S
|
|
|
|
|
backwards (a' , (a=a' , a'b∈S)) = subst (sym a=a') a'b∈S
|
|
|
|
|
|
2017-11-15 19:45:35 +00:00
|
|
|
|
fwd-bwd : (x : (a , b) ∈ S) → (backwards ∘ forwards) x ≡ x
|
2017-11-10 15:00:00 +00:00
|
|
|
|
-- isbijective x = pathJ (λ y x₁ → (backwards ∘ forwards) x ≡ x) {!!} {!!} {!!}
|
2017-11-15 19:45:35 +00:00
|
|
|
|
fwd-bwd x = pathJprop (λ y _ → y) x
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
2017-11-15 19:45:35 +00:00
|
|
|
|
bwd-fwd : (x : Σ[ a' ∈ A ] (a , a') ∈ Diag A × (a' , b) ∈ S)
|
2017-11-10 15:00:00 +00:00
|
|
|
|
→ (forwards ∘ backwards) x ≡ x
|
2017-11-15 19:45:35 +00:00
|
|
|
|
-- bwd-fwd (y , a≡y , z) = ?
|
|
|
|
|
bwd-fwd (a' , a≡y , z) = pathJ lem0 lem1 a' a≡y z
|
|
|
|
|
where
|
|
|
|
|
lem0 = (λ a'' a≡a'' → ∀ a''b∈S → (forwards ∘ backwards) (a'' , a≡a'' , a''b∈S) ≡ (a'' , a≡a'' , a''b∈S))
|
|
|
|
|
lem1 = (λ z₁ → cong (\ z → a , refl , z) (pathJprop (\ y _ → y) z₁))
|
|
|
|
|
|
2017-11-10 15:00:00 +00:00
|
|
|
|
isequiv : isEquiv
|
|
|
|
|
(Σ[ a' ∈ A ] (a , a') ∈ Diag A × (a' , b) ∈ S)
|
|
|
|
|
((a , b) ∈ S)
|
|
|
|
|
backwards
|
2017-11-15 19:45:35 +00:00
|
|
|
|
isequiv y = gradLemma backwards forwards fwd-bwd bwd-fwd y
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
equi : (Σ[ a' ∈ A ] (a , a') ∈ Diag A × (a' , b) ∈ S)
|
|
|
|
|
≃ (a , b) ∈ S
|
2018-01-08 21:48:59 +00:00
|
|
|
|
equi = backwards Cubical.FromStdLib., isequiv
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
ident-l : (Σ[ a' ∈ A ] (a , a') ∈ Diag A × (a' , b) ∈ S)
|
|
|
|
|
≡ (a , b) ∈ S
|
|
|
|
|
ident-l = equivToPath equi
|
|
|
|
|
|
|
|
|
|
module _ where
|
|
|
|
|
private
|
|
|
|
|
forwards : ((a , b) ∈ S)
|
|
|
|
|
→ (Σ[ b' ∈ B ] (a , b') ∈ S × (b' , b) ∈ Diag B)
|
|
|
|
|
forwards proof = b , (proof , refl)
|
|
|
|
|
|
|
|
|
|
backwards : (Σ[ b' ∈ B ] (a , b') ∈ S × (b' , b) ∈ Diag B)
|
|
|
|
|
→ (a , b) ∈ S
|
|
|
|
|
backwards (b' , (ab'∈S , b'=b)) = subst b'=b ab'∈S
|
|
|
|
|
|
2017-11-15 19:45:35 +00:00
|
|
|
|
bwd-fwd : (x : (a , b) ∈ S) → (backwards ∘ forwards) x ≡ x
|
|
|
|
|
bwd-fwd x = pathJprop (λ y _ → y) x
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
fwd-bwd : (x : Σ[ b' ∈ B ] (a , b') ∈ S × (b' , b) ∈ Diag B)
|
|
|
|
|
→ (forwards ∘ backwards) x ≡ x
|
2017-11-15 19:45:35 +00:00
|
|
|
|
fwd-bwd (b' , (ab'∈S , b'≡b)) = pathJ lem0 lem1 b' (sym b'≡b) ab'∈S
|
|
|
|
|
where
|
|
|
|
|
lem0 = (λ b'' b≡b'' → (ab''∈S : (a , b'') ∈ S) → (forwards ∘ backwards) (b'' , ab''∈S , sym b≡b'') ≡ (b'' , ab''∈S , sym b≡b''))
|
|
|
|
|
lem1 = (λ ab''∈S → cong (λ φ → b , φ , refl) (pathJprop (λ y _ → y) ab''∈S))
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
isequiv : isEquiv
|
|
|
|
|
(Σ[ b' ∈ B ] (a , b') ∈ S × (b' , b) ∈ Diag B)
|
|
|
|
|
((a , b) ∈ S)
|
|
|
|
|
backwards
|
2017-11-15 19:45:35 +00:00
|
|
|
|
isequiv ab∈S = gradLemma backwards forwards bwd-fwd fwd-bwd ab∈S
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
equi : (Σ[ b' ∈ B ] (a , b') ∈ S × (b' , b) ∈ Diag B)
|
|
|
|
|
≃ ab ∈ S
|
2018-01-08 21:48:59 +00:00
|
|
|
|
equi = backwards Cubical.FromStdLib., isequiv
|
2017-11-10 15:00:00 +00:00
|
|
|
|
|
|
|
|
|
ident-r : (Σ[ b' ∈ B ] (a , b') ∈ S × (b' , b) ∈ Diag B)
|
|
|
|
|
≡ ab ∈ S
|
|
|
|
|
ident-r = equivToPath equi
|
|
|
|
|
|
2017-11-15 20:49:50 +00:00
|
|
|
|
module _ {A B C D : Set} {S : Subset (A × B)} {R : Subset (B × C)} {Q : Subset (C × D)} (ad : A × D) where
|
|
|
|
|
private
|
|
|
|
|
a : A
|
|
|
|
|
a = fst ad
|
|
|
|
|
d : D
|
|
|
|
|
d = snd ad
|
|
|
|
|
|
|
|
|
|
Q⊕⟨R⊕S⟩ : Set
|
|
|
|
|
Q⊕⟨R⊕S⟩ = Σ[ c ∈ C ] (Σ[ b ∈ B ] (a , b) ∈ S × (b , c) ∈ R) × (c , d) ∈ Q
|
|
|
|
|
⟨Q⊕R⟩⊕S : Set
|
|
|
|
|
⟨Q⊕R⟩⊕S = Σ[ b ∈ B ] (a , b) ∈ S × (Σ[ c ∈ C ] (b , c) ∈ R × (c , d) ∈ Q)
|
|
|
|
|
|
|
|
|
|
fwd : Q⊕⟨R⊕S⟩ → ⟨Q⊕R⟩⊕S
|
|
|
|
|
fwd (c , (b , (ab∈S , bc∈R)) , cd∈Q) = b , (ab∈S , (c , (bc∈R , cd∈Q)))
|
|
|
|
|
|
|
|
|
|
bwd : ⟨Q⊕R⟩⊕S → Q⊕⟨R⊕S⟩
|
|
|
|
|
bwd (b , (ab∈S , (c , (bc∈R , cd∈Q)))) = c , (b , ab∈S , bc∈R) , cd∈Q
|
|
|
|
|
|
|
|
|
|
fwd-bwd : (x : ⟨Q⊕R⟩⊕S) → (fwd ∘ bwd) x ≡ x
|
|
|
|
|
fwd-bwd x = refl
|
|
|
|
|
|
|
|
|
|
bwd-fwd : (x : Q⊕⟨R⊕S⟩) → (bwd ∘ fwd) x ≡ x
|
|
|
|
|
bwd-fwd x = refl
|
|
|
|
|
|
|
|
|
|
isequiv : isEquiv
|
|
|
|
|
(Σ[ c ∈ C ] (Σ[ b ∈ B ] (a , b) ∈ S × (b , c) ∈ R) × (c , d) ∈ Q)
|
|
|
|
|
(Σ[ b ∈ B ] (a , b) ∈ S × (Σ[ c ∈ C ] (b , c) ∈ R × (c , d) ∈ Q))
|
|
|
|
|
fwd
|
|
|
|
|
isequiv = gradLemma fwd bwd fwd-bwd bwd-fwd
|
|
|
|
|
|
|
|
|
|
equi : (Σ[ c ∈ C ] (Σ[ b ∈ B ] (a , b) ∈ S × (b , c) ∈ R) × (c , d) ∈ Q)
|
|
|
|
|
≃ (Σ[ b ∈ B ] (a , b) ∈ S × (Σ[ c ∈ C ] (b , c) ∈ R × (c , d) ∈ Q))
|
2018-01-08 21:48:59 +00:00
|
|
|
|
equi = fwd Cubical.FromStdLib., isequiv
|
2017-11-15 20:49:50 +00:00
|
|
|
|
|
2018-02-23 11:43:49 +00:00
|
|
|
|
-- isAssociativec : Q + (R + S) ≡ (Q + R) + S
|
|
|
|
|
is-isAssociative : (Σ[ c ∈ C ] (Σ[ b ∈ B ] (a , b) ∈ S × (b , c) ∈ R) × (c , d) ∈ Q)
|
2017-11-15 20:49:50 +00:00
|
|
|
|
≡ (Σ[ b ∈ B ] (a , b) ∈ S × (Σ[ c ∈ C ] (b , c) ∈ R × (c , d) ∈ Q))
|
2018-02-23 11:43:49 +00:00
|
|
|
|
is-isAssociative = equivToPath equi
|
2017-11-15 20:49:50 +00:00
|
|
|
|
|
2018-02-05 10:43:38 +00:00
|
|
|
|
RawRel : RawCategory (lsuc lzero) (lsuc lzero)
|
|
|
|
|
RawRel = record
|
2017-11-10 15:00:00 +00:00
|
|
|
|
{ Object = Set
|
|
|
|
|
; Arrow = λ S R → Subset (S × R)
|
|
|
|
|
; 𝟙 = λ {S} → Diag S
|
2018-01-30 18:19:16 +00:00
|
|
|
|
; _∘_ = λ {A B C} S R → λ {( a , c ) → Σ[ b ∈ B ] ( (a , b) ∈ R × (b , c) ∈ S )}
|
2018-02-05 10:43:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RawIsCategoryRel : IsCategory RawRel
|
|
|
|
|
RawIsCategoryRel = record
|
2018-02-23 11:43:49 +00:00
|
|
|
|
{ isAssociative = funExt is-isAssociative
|
2018-02-05 10:43:38 +00:00
|
|
|
|
; ident = funExt ident-l , funExt ident-r
|
2018-02-06 09:34:43 +00:00
|
|
|
|
; arrowIsSet = {!!}
|
2018-02-05 10:43:38 +00:00
|
|
|
|
; univalent = {!!}
|
2017-11-10 15:00:00 +00:00
|
|
|
|
}
|