Mercurial > hg > Members > kono > Proof > category
annotate src/monoid-monad.agda @ 971:9746e93a8c31
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 27 Feb 2021 12:15:28 +0900 |
parents | ac53803b3b2a |
children | 40c39d3e6a75 |
rev | line source |
---|---|
129 | 1 open import Category -- https://github.com/konn/category-agda |
130 | 2 open import Algebra |
129 | 3 open import Level |
149 | 4 open import Category.Sets |
5 module monoid-monad {c : Level} where | |
130 | 6 |
142 | 7 open import Algebra.Structures |
971 | 8 open import HomReasoning |
129 | 9 open import cat-utility |
10 open import Category.Cat | |
138 | 11 open import Data.Product |
12 open import Relation.Binary.Core | |
13 open import Relation.Binary | |
131 | 14 |
146
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
15 -- open Monoid |
971 | 16 -- open import Algebra.FunctionProperties using (Op₁; Op₂) |
146
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
17 |
781 | 18 open import Relation.Binary.PropositionalEquality hiding ( [_] ; sym ) |
19 | |
146
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
20 |
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
21 record ≡-Monoid c : Set (suc c) where |
783 | 22 infixl 7 _*_ |
146
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
23 field |
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
24 Carrier : Set c |
783 | 25 _*_ : Op₂ Carrier |
301 | 26 ε : Carrier -- id in Monoid |
783 | 27 isMonoid : IsMonoid _≡_ _*_ ε |
146
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
28 |
151 | 29 postulate M : ≡-Monoid c |
146
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
30 open ≡-Monoid |
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
31 |
783 | 32 infixl 7 _∙_ |
33 | |
34 _∙_ : ( m m' : Carrier M ) → Carrier M | |
35 _∙_ m m' = _*_ M m m' | |
36 | |
149 | 37 A = Sets {c} |
138 | 38 |
139 | 39 -- T : A → (M x A) |
134 | 40 |
149 | 41 T : Functor A A |
138 | 42 T = record { |
151 | 43 FObj = λ a → (Carrier M) × a |
783 | 44 ; FMap = λ f p → (proj₁ p , f (proj₂ p )) |
138 | 45 ; isFunctor = record { |
46 identity = IsEquivalence.refl (IsCategory.isEquivalence ( Category.isCategory Sets )) | |
47 ; distr = (IsEquivalence.refl (IsCategory.isEquivalence ( Category.isCategory Sets ))) | |
48 ; ≈-cong = cong1 | |
49 } | |
50 } where | |
139 | 51 cong1 : {ℓ′ : Level} → {a b : Set ℓ′} { f g : Hom (Sets {ℓ′}) a b} → |
151 | 52 Sets [ f ≈ g ] → Sets [ map (λ (x : Carrier M) → x) f ≈ map (λ (x : Carrier M) → x) g ] |
138 | 53 cong1 _≡_.refl = _≡_.refl |
129 | 54 |
144 | 55 open Functor |
56 | |
149 | 57 Lemma-MM1 : {a b : Obj A} {f : Hom A a b} → |
151 | 58 A [ A [ FMap T f o (λ x → ε M , x) ] ≈ |
59 A [ (λ x → ε M , x) o f ] ] | |
149 | 60 Lemma-MM1 {a} {b} {f} = let open ≈-Reasoning A renaming ( _o_ to _*_ ) in |
139 | 61 begin |
151 | 62 FMap T f o (λ x → ε M , x) |
139 | 63 ≈⟨⟩ |
151 | 64 (λ x → ε M , x) o f |
139 | 65 ∎ |
66 | |
150 | 67 -- η : a → (ε,a) |
149 | 68 η : NTrans A A identityFunctor T |
139 | 69 η = record { |
151 | 70 TMap = λ a → λ(x : a) → ( ε M , x ) ; |
139 | 71 isNTrans = record { |
149 | 72 commute = Lemma-MM1 |
139 | 73 } |
74 } | |
75 | |
150 | 76 -- μ : (m,(m',a)) → (m*m,a) |
139 | 77 |
151 | 78 muMap : (a : Obj A ) → FObj T ( FObj T a ) → Σ (Carrier M) (λ x → a ) |
783 | 79 muMap a ( m , ( m' , x ) ) = ( m ∙ m' , x ) |
139 | 80 |
149 | 81 Lemma-MM2 : {a b : Obj A} {f : Hom A a b} → |
82 A [ A [ FMap T f o (λ x → muMap a x) ] ≈ | |
83 A [ (λ x → muMap b x) o FMap (T ○ T) f ] ] | |
84 Lemma-MM2 {a} {b} {f} = let open ≈-Reasoning A renaming ( _o_ to _*_ ) in | |
139 | 85 begin |
86 FMap T f o (λ x → muMap a x) | |
87 ≈⟨⟩ | |
88 (λ x → muMap b x) o FMap (T ○ T) f | |
89 ∎ | |
90 | |
149 | 91 μ : NTrans A A ( T ○ T ) T |
139 | 92 μ = record { |
149 | 93 TMap = λ a → λ x → muMap a x ; |
139 | 94 isNTrans = record { |
149 | 95 commute = λ{a} {b} {f} → Lemma-MM2 {a} {b} {f} |
139 | 96 } |
97 } | |
141 | 98 |
99 open NTrans | |
100 | |
144 | 101 Lemma-MM33 : {a : Level} {b : Level} {A : Set a} {B : A → Set b} {x : Σ A B } → (((proj₁ x) , proj₂ x ) ≡ x ) |
142 | 102 Lemma-MM33 = _≡_.refl |
103 | |
783 | 104 Lemma-MM34 : ∀( x : Carrier M ) → ε M ∙ x ≡ x |
169
44bf6e78f891
builtin extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
105 Lemma-MM34 x = (( proj₁ ( IsMonoid.identity ( isMonoid M )) ) x ) |
146
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
106 |
783 | 107 Lemma-MM35 : ∀( x : Carrier M ) → x ∙ ε M ≡ x |
169
44bf6e78f891
builtin extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
108 Lemma-MM35 x = ( proj₂ ( IsMonoid.identity ( isMonoid M )) ) x |
141 | 109 |
783 | 110 Lemma-MM36 : ∀( x y z : Carrier M ) → (x ∙ y) ∙ z ≡ x ∙ (y ∙ z ) |
170
721cf9d9f5e3
use functional extensionality in library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
169
diff
changeset
|
111 Lemma-MM36 x y z = ( IsMonoid.assoc ( isMonoid M )) x y z |
146
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
112 |
169
44bf6e78f891
builtin extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
168
diff
changeset
|
113 import Relation.Binary.PropositionalEquality |
170
721cf9d9f5e3
use functional extensionality in library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
169
diff
changeset
|
114 -- postulate extensionality : { a b : Obj A } {f g : Hom A a b } → Relation.Binary.PropositionalEquality.Extensionality c c |
971 | 115 -- postulate extensionality : Axiom.Extensionality.Propositional.Extensionality c c |
116 | |
117 import Axiom.Extensionality.Propositional | |
118 postulate extensionality : { c₁ c₂ ℓ : Level} ( A : Category c₁ c₂ ℓ ) → Axiom.Extensionality.Propositional.Extensionality c₂ c₂ | |
144 | 119 |
170
721cf9d9f5e3
use functional extensionality in library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
169
diff
changeset
|
120 -- Multi Arguments Functional Extensionality |
721cf9d9f5e3
use functional extensionality in library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
169
diff
changeset
|
121 extensionality30 : {f g : Carrier M → Carrier M → Carrier M → Carrier M } → |
721cf9d9f5e3
use functional extensionality in library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
169
diff
changeset
|
122 (∀ x y z → f x y z ≡ g x y z ) → ( f ≡ g ) |
971 | 123 extensionality30 eq = extensionality A ( λ x → extensionality A ( λ y → extensionality A (eq x y) ) ) |
144 | 124 |
783 | 125 Lemma-MM9 : (λ(x : Carrier M) → ( ε M ∙ x )) ≡ ( λ(x : Carrier M) → x ) |
971 | 126 Lemma-MM9 = extensionality A Lemma-MM34 |
144 | 127 |
783 | 128 Lemma-MM10 : ( λ x → (x ∙ ε M)) ≡ ( λ x → x ) |
971 | 129 Lemma-MM10 = extensionality A Lemma-MM35 |
146
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
130 |
783 | 131 Lemma-MM11 : (λ x y z → ((x ∙ y ) ∙ z)) ≡ (λ x y z → ( x ∙ (y ∙ z ) )) |
170
721cf9d9f5e3
use functional extensionality in library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
169
diff
changeset
|
132 Lemma-MM11 = extensionality30 Lemma-MM36 |
145 | 133 |
773 | 134 MonoidMonad : Monad A |
141 | 135 MonoidMonad = record { |
773 | 136 T = T |
137 ; η = η | |
138 ; μ = μ | |
139 ; isMonad = record { | |
148
6e80e1aaa8b9
no yellow on monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
140 unity1 = Lemma-MM3 ; |
141 | 141 unity2 = Lemma-MM4 ; |
148
6e80e1aaa8b9
no yellow on monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
142 assoc = Lemma-MM5 |
141 | 143 } |
144 } where | |
147 | 145 Lemma-MM3 : {a : Obj A} → A [ A [ TMap μ a o TMap η ( FObj T a ) ] ≈ Id {_} {_} {_} {A} (FObj T a) ] |
971 | 146 Lemma-MM3 {a} = let open ≈-Reasoning (A) renaming ( _o_ to _*_ ) hiding (_∙_) in |
141 | 147 begin |
148 TMap μ a o TMap η ( FObj T a ) | |
149 ≈⟨⟩ | |
783 | 150 ( λ x → ε M ∙ (proj₁ x) , proj₂ x ) |
149 | 151 ≈⟨ cong ( λ f → ( λ x → ( ( f (proj₁ x) ) , proj₂ x ))) ( Lemma-MM9 ) ⟩ |
147 | 152 ( λ (x : FObj T a) → (proj₁ x) , proj₂ x ) |
144 | 153 ≈⟨⟩ |
141 | 154 ( λ x → x ) |
155 ≈⟨⟩ | |
156 Id {_} {_} {_} {A} (FObj T a) | |
157 ∎ | |
158 Lemma-MM4 : {a : Obj A} → A [ A [ TMap μ a o (FMap T (TMap η a ))] ≈ Id {_} {_} {_} {A} (FObj T a) ] | |
971 | 159 Lemma-MM4 {a} = let open ≈-Reasoning (A) renaming ( _o_ to _*_ ) hiding (_∙_) in |
144 | 160 begin |
161 TMap μ a o (FMap T (TMap η a )) | |
162 ≈⟨⟩ | |
783 | 163 ( λ x → ( proj₁ x ∙ (ε M) , proj₂ x )) |
149 | 164 ≈⟨ cong ( λ f → ( λ x → ( f (proj₁ x) ) , proj₂ x )) ( Lemma-MM10 ) ⟩ |
144 | 165 ( λ x → (proj₁ x) , proj₂ x ) |
166 ≈⟨⟩ | |
167 ( λ x → x ) | |
168 ≈⟨⟩ | |
169 Id {_} {_} {_} {A} (FObj T a) | |
170 ∎ | |
141 | 171 Lemma-MM5 : {a : Obj A} → A [ A [ TMap μ a o TMap μ ( FObj T a ) ] ≈ A [ TMap μ a o FMap T (TMap μ a) ] ] |
971 | 172 Lemma-MM5 {a} = let open ≈-Reasoning (A) renaming ( _o_ to _*_ ) hiding (_∙_) in |
144 | 173 begin |
174 TMap μ a o TMap μ ( FObj T a ) | |
175 ≈⟨⟩ | |
783 | 176 ( λ x → (proj₁ x) ∙ (proj₁ (proj₂ x)) ∙ (proj₁ (proj₂ (proj₂ x))) , proj₂ (proj₂ (proj₂ x))) |
149 | 177 ≈⟨ cong ( λ f → ( λ x → |
146
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
178 (( f ( proj₁ x ) ((proj₁ (proj₂ x))) ((proj₁ (proj₂ (proj₂ x))) )) , proj₂ (proj₂ (proj₂ x)) ) |
945f26ed12d5
assuing ∀{x : Carrier Mono } {f g : Carrier Mono -> Carrier Mono } -> (f x ≡ g x) -> ( f ≡ g )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
145
diff
changeset
|
179 )) Lemma-MM11 ⟩ |
783 | 180 ( λ x → ( proj₁ x) ∙(( proj₁ (proj₂ x)) ∙ (proj₁ (proj₂ (proj₂ x)))) , proj₂ (proj₂ (proj₂ x))) |
144 | 181 ≈⟨⟩ |
182 TMap μ a o FMap T (TMap μ a) | |
183 ∎ | |
141 | 184 |
185 | |
300 | 186 F : (m : Carrier M) → { a b : Obj A } → ( f : a → b ) → Hom A a ( FObj T b ) |
187 F m {a} {b} f = λ (x : a ) → ( m , ( f x) ) | |
141 | 188 |
151 | 189 postulate m m' : Carrier M |
190 postulate a b c' : Obj A | |
300 | 191 postulate f : b → c' |
192 postulate g : a → b | |
151 | 193 |
153 | 194 Lemma-MM12 = Monad.join MonoidMonad (F m f) (F m' g) |
151 | 195 |
773 | 196 open import kleisli {_} {_} {_} {A} {T} {η} {μ} {Monad.isMonad MonoidMonad} |
151 | 197 |
202
58ee98bbb333
remove an extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
198 -- nat-ε TMap = λ a₁ → record { KMap = λ x → x } |
58ee98bbb333
remove an extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
199 -- nat-η TMap = λ a₁ → _,_ (ε, M) |
58ee98bbb333
remove an extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
200 -- U_T Functor Kleisli A |
58ee98bbb333
remove an extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
201 -- U_T FObj = λ B → Σ (Carrier M) (λ x → B) FMap = λ {a₁} {b₁} f₁ x → ( proj₁ x ∙ (proj₁ (KMap f₁ (proj₂ x))) , proj₂ (KMap f₁ (proj₂ x)) |
58ee98bbb333
remove an extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
202 -- F_T Functor A Kleisli |
58ee98bbb333
remove an extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
203 -- F_T FObj = λ a₁ → a₁ FMap = λ {a₁} {b₁} f₁ → record { KMap = λ x → ε M , f₁ x } |