Skip to content

Commit 68c84fe

Browse files
Merge pull request #361 from Taneb/nasts-cartesian
Prove that Nat is cartesian and Natop is hence cocartesian
2 parents a109603 + 59b20fb commit 68c84fe

File tree

1 file changed

+48
-7
lines changed
  • src/Categories/Category/Instance

1 file changed

+48
-7
lines changed

src/Categories/Category/Instance/Nat.agda

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@ module Categories.Category.Instance.Nat where
55

66
open import Level
77

8-
open import Data.Fin.Base using (Fin; inject+; raise; splitAt; join)
8+
open import Data.Fin.Base using (Fin; inject+; raise; splitAt; join; remQuot; combine)
99
open import Data.Fin.Properties
10-
open import Data.Nat.Base using (ℕ; _+_)
10+
open import Data.Nat.Base using (ℕ; _+_; _*_)
11+
open import Data.Product using (proj₁; proj₂; uncurry; <_,_>)
1112
open import Data.Sum using (inj₁; inj₂; [_,_]′)
1213
open import Data.Sum.Properties
1314
open import Relation.Binary.PropositionalEquality
14-
using (_≗_; _≡_; refl; sym; trans; cong; module ≡-Reasoning; inspect; [_])
15-
open import Function using (id; _∘′_)
15+
using (_≗_; _≡_; refl; sym; trans; cong; cong₂; module ≡-Reasoning)
16+
open import Function using (id; _∘′_; case_return_of_)
1617

18+
open import Categories.Category.Cartesian using (Cartesian)
1719
open import Categories.Category.Cartesian.Bundle using (CartesianCategory)
1820
open import Categories.Category.Cocartesian using (Cocartesian)
1921
open import Categories.Category.Cocartesian.Bundle using (CocartesianCategory)
2022
open import Categories.Category.Core using (Category)
21-
open import Categories.Category.Duality using (Cocartesian⇒coCartesian)
23+
open import Categories.Category.Duality using (Cocartesian⇒coCartesian; coCartesian⇒Cocartesian)
2224
open import Categories.Object.Coproduct
23-
open import Categories.Object.Duality using (Coproduct⇒coProduct)
25+
open import Categories.Object.Duality using (Coproduct⇒coProduct; coProduct⇒Coproduct)
2426
open import Categories.Object.Product
2527

2628
Nat : Category 0ℓ 0ℓ 0ℓ
@@ -60,7 +62,7 @@ Coprod m n = record
6062
uniq : {o : ℕ} {h : Fin (m + n) Fin o} {f : Fin m Fin o} {g : Fin n Fin o}
6163
h ∘′ inject+ n ≗ f h ∘′ raise m ≗ g (λ z [ f , g ]′ (splitAt m z)) ≗ h
6264
uniq {_} {h} {f} {g} h≗f h≗g w = begin
63-
[ f , g ]′ (splitAt m w) ≡⟨ [,]-cong (λ x sym (h≗f x)) (λ x sym (h≗g x)) (splitAt m w) ⟩
65+
[ f , g ]′ (splitAt m w) ≡˘⟨ [,]-cong h≗f h≗g (splitAt m w) ⟩
6466
[ h ∘′ inject+ n , h ∘′ raise m ]′ (splitAt m w) ≡˘⟨ [,]-∘-distr h (splitAt m w) ⟩
6567
h ([ inject+ n , raise m ]′ (splitAt m w)) ≡⟨ cong h (join-splitAt m n w) ⟩
6668
h w ∎
@@ -77,6 +79,36 @@ Nat-Cocartesian = record
7779
; coproducts = record { coproduct = λ {m} {n} Coprod m n }
7880
}
7981

82+
Prod : (m n : ℕ) Product Nat m n
83+
Prod m n = record
84+
{ A×B = m * n
85+
; π₁ = proj₁ ∘′ remQuot n
86+
; π₂ = proj₂ ∘′ remQuot {m} n
87+
; ⟨_,_⟩ = λ l r z uncurry combine (< l , r > z)
88+
; project₁ = λ {_ f g} z cong proj₁ (remQuot-combine (f z) (g z))
89+
; project₂ = λ {_ f g} z cong proj₂ (remQuot-combine (f z) (g z))
90+
; unique = uniq
91+
}
92+
where
93+
open ≡-Reasoning
94+
uniq : {o : ℕ} {h : Fin o Fin (m * n)} {f : Fin o Fin m} {g : Fin o Fin n}
95+
proj₁ ∘′ remQuot n ∘′ h ≗ f proj₂ ∘′ remQuot {m} n ∘′ h ≗ g uncurry combine ∘′ < f , g > ≗ h
96+
uniq {_} {h} {f} {g} h≗f h≗g w = begin
97+
combine (f w) (g w) ≡˘⟨ cong₂ combine (h≗f w) (h≗g w) ⟩
98+
combine (proj₁ (remQuot {m} n (h w))) (proj₂ (remQuot {m} n (h w))) ≡⟨ combine-remQuot {m} n (h w) ⟩
99+
h w ∎
100+
101+
Nat-Cartesian : Cartesian Nat
102+
Nat-Cartesian = record
103+
{ terminal = record
104+
{ ⊤ = 1
105+
; ⊤-is-terminal = record
106+
{ !-unique = λ f x case f x return (Fin.zero ≡_) of λ { Fin.zero refl }
107+
}
108+
}
109+
; products = record {product = λ {m} {n} Prod m n }
110+
}
111+
80112
-- And Natop is what is used a lot, so record some things here too
81113
Natop : Category 0ℓ 0ℓ 0ℓ
82114
Natop = Category.op Nat
@@ -89,3 +121,12 @@ Natop-Cartesian = record
89121
{ U = Natop
90122
; cartesian = Cocartesian⇒coCartesian Nat Nat-Cocartesian
91123
}
124+
125+
Natop-Coprod : (m n : ℕ) Coproduct Natop m n
126+
Natop-Coprod m n = coProduct⇒Coproduct Natop (Prod m n)
127+
128+
Natop-Cocartesian : CocartesianCategory 0ℓ 0ℓ 0ℓ
129+
Natop-Cocartesian = record
130+
{ U = Natop
131+
; cocartesian = coCartesian⇒Cocartesian Natop Nat-Cartesian
132+
}

0 commit comments

Comments
 (0)