annotate src/list-monoid-cat.agda @ 1124:f683d96fbc93 default tip

safe fix done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 07 Jul 2024 22:28:50 +0900
parents 5620d4a85069
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1115
5620d4a85069 safe rewriting nearly finished
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 949
diff changeset
1 {-# OPTIONS --cubical-compatible --safe #-}
5620d4a85069 safe rewriting nearly finished
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 949
diff changeset
2
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 open import Category -- https://github.com/konn/category-agda
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 open import Level
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import HomReasoning
1115
5620d4a85069 safe rewriting nearly finished
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 949
diff changeset
6 open import Definitions
1124
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
7 open import Relation.Binary
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
8
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9
168
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
10 module list-monoid-cat (c : Level ) where
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 infixr 40 _::_
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 data List (A : Set ) : Set where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 [] : List A
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
15 _::_ : A → List A → List A
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 infixl 30 _++_
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
19 _++_ : {A : Set } → List A → List A → List A
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 [] ++ ys = ys
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 (x :: xs) ++ ys = x :: (xs ++ ys)
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 data ListObj : Set where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 * : ListObj
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 open import Relation.Binary.Core
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 open import Relation.Binary.PropositionalEquality
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 ≡-cong = Relation.Binary.PropositionalEquality.cong
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
31 isListCategory : (A : Set) → IsCategory ListObj (λ a b → List A) _≡_ _++_ []
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 isListCategory A = record { isEquivalence = isEquivalence1 {A}
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 ; identityL = list-id-l
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 ; identityR = list-id-r
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 ; o-resp-≈ = o-resp-≈ {A}
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
36 ; associative = λ {a} {b} {c} {d} {x} {y} {z} → list-assoc {A} {x} {y} {z}
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 }
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 where
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
39 list-id-l : { A : Set } → { x : List A } → [] ++ x ≡ x
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 list-id-l {_} {_} = refl
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
41 list-id-r : { A : Set } → { x : List A } → x ++ [] ≡ x
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 list-id-r {_} {[]} = refl
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
43 list-id-r {A} {x :: xs} = ≡-cong ( λ y → x :: y ) ( list-id-r {A} {xs} )
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
44 list-assoc : {A : Set} → { xs ys zs : List A } →
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 ( xs ++ ( ys ++ zs ) ) ≡ ( ( xs ++ ys ) ++ zs )
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 list-assoc {_} {[]} {_} {_} = refl
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
47 list-assoc {A} {x :: xs} {ys} {zs} = ≡-cong ( λ y → x :: y )
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 ( list-assoc {A} {xs} {ys} {zs} )
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
49 o-resp-≈ : {A : Set} → {f g : List A } → {h i : List A } →
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 f ≡ g → h ≡ i → (h ++ f) ≡ (i ++ g)
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 o-resp-≈ {A} refl refl = refl
1124
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
52 isEquivalence1 : {A : Set} → IsEquivalence {_} {_} {List A } _≡_
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
53 isEquivalence1 {A} = -- this is the same function as A's equivalence but has different types
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
54 record { refl = refl
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
55 ; sym = sym
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
56 ; trans = trans
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
57 }
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
58 ListCategory : (A : Set) → Category _ _ _
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 ListCategory A =
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 record { Obj = ListObj
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
61 ; Hom = λ a b → List A
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 ; _o_ = _++_
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 ; _≈_ = _≡_
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 ; Id = []
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 ; isCategory = ( isListCategory A )
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 }
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 open import Algebra.Structures
1115
5620d4a85069 safe rewriting nearly finished
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 949
diff changeset
69 -- open import Algebra.FunctionProperties using (Op₁; Op₂)
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 data MonoidObj : Set c where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 ! : MonoidObj
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 record ≡-Monoid c : Set (suc c) where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 infixl 7 _∙_
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 field
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 Carrier : Set c
1115
5620d4a85069 safe rewriting nearly finished
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 949
diff changeset
78 _∙_ : Carrier → Carrier → Carrier
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 ε : Carrier
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 isMonoid : IsMonoid _≡_ _∙_ ε
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 open ≡-Monoid
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 open import Data.Product
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
85 isMonoidCategory : (M : ≡-Monoid c) → IsCategory MonoidObj (λ a b → Carrier M ) _≡_ (_∙_ M) (ε M)
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 isMonoidCategory M = record { isEquivalence = isEquivalence1 {M}
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
87 ; identityL = λ {_} {_} {x} → (( proj₁ ( IsMonoid.identity ( isMonoid M )) ) x )
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
88 ; identityR = λ {_} {_} {x} → (( proj₂ ( IsMonoid.identity ( isMonoid M )) ) x )
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
89 ; associative = λ {a} {b} {c} {d} {x} {y} {z} → sym ( (IsMonoid.assoc ( isMonoid M )) x y z )
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 ; o-resp-≈ = o-resp-≈ {M}
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 }
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 where
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
93 o-resp-≈ : {M : ≡-Monoid c} → {f g : Carrier M } → {h i : Carrier M } →
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 f ≡ g → h ≡ i → (_∙_ M h f) ≡ (_∙_ M i g)
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 o-resp-≈ {A} refl refl = refl
1124
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
96 isEquivalence1 : {M : ≡-Monoid c} → IsEquivalence {_} {_} {Carrier M } _≡_
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
97 isEquivalence1 {A} = -- this is the same function as A's equivalence but has different types
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
98 record { refl = refl
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
99 ; sym = sym
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
100 ; trans = trans
f683d96fbc93 safe fix done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 1115
diff changeset
101 }
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
102 MonoidCategory : (M : ≡-Monoid c) → Category _ _ _
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 MonoidCategory M =
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 record { Obj = MonoidObj
300
d6a6dd305da2 arrow and lambda fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 168
diff changeset
105 ; Hom = λ a b → Carrier M
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 ; _o_ = _∙_ M
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 ; _≈_ = _≡_
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 ; Id = ε M
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 ; isCategory = ( isMonoidCategory M )
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 }
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111