@@ -5,22 +5,24 @@ module Categories.Category.Instance.Nat where
5
5
6
6
open import Level
7
7
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 )
9
9
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; <_,_>)
11
12
open import Data.Sum using (inj₁; inj₂; [_,_]′)
12
13
open import Data.Sum.Properties
13
14
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_ )
16
17
18
+ open import Categories.Category.Cartesian using (Cartesian)
17
19
open import Categories.Category.Cartesian.Bundle using (CartesianCategory)
18
20
open import Categories.Category.Cocartesian using (Cocartesian)
19
21
open import Categories.Category.Cocartesian.Bundle using (CocartesianCategory)
20
22
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 )
22
24
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 )
24
26
open import Categories.Object.Product
25
27
26
28
Nat : Category 0ℓ 0ℓ 0ℓ
@@ -60,7 +62,7 @@ Coprod m n = record
60
62
uniq : {o : ℕ} {h : Fin (m + n) → Fin o} {f : Fin m → Fin o} {g : Fin n → Fin o} →
61
63
h ∘′ inject+ n ≗ f → h ∘′ raise m ≗ g → (λ z → [ f , g ]′ (splitAt m z)) ≗ h
62
64
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) ⟩
64
66
[ h ∘′ inject+ n , h ∘′ raise m ]′ (splitAt m w) ≡˘⟨ [,]-∘-distr h (splitAt m w) ⟩
65
67
h ([ inject+ n , raise m ]′ (splitAt m w)) ≡⟨ cong h (join-splitAt m n w) ⟩
66
68
h w ∎
@@ -77,6 +79,36 @@ Nat-Cocartesian = record
77
79
; coproducts = record { coproduct = λ {m} {n} → Coprod m n }
78
80
}
79
81
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
+
80
112
-- And Natop is what is used a lot, so record some things here too
81
113
Natop : Category 0ℓ 0ℓ 0ℓ
82
114
Natop = Category.op Nat
@@ -89,3 +121,12 @@ Natop-Cartesian = record
89
121
{ U = Natop
90
122
; cartesian = Cocartesian⇒coCartesian Nat Nat-Cocartesian
91
123
}
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