Mercurial > hg > Members > kono > Proof > category
annotate src/monoid-monad.agda @ 1046:60b24b3dc0c6
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 10 Apr 2021 11:39:46 +0900 |
parents | 40c39d3e6a75 |
children | 5620d4a85069 |
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 |
144 | 114 |
170
721cf9d9f5e3
use functional extensionality in library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
169
diff
changeset
|
115 -- Multi Arguments Functional Extensionality |
721cf9d9f5e3
use functional extensionality in library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
169
diff
changeset
|
116 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
|
117 (∀ x y z → f x y z ≡ g x y z ) → ( f ≡ g ) |
971 | 118 extensionality30 eq = extensionality A ( λ x → extensionality A ( λ y → extensionality A (eq x y) ) ) |
144 | 119 |
783 | 120 Lemma-MM9 : (λ(x : Carrier M) → ( ε M ∙ x )) ≡ ( λ(x : Carrier M) → x ) |
971 | 121 Lemma-MM9 = extensionality A Lemma-MM34 |
144 | 122 |
783 | 123 Lemma-MM10 : ( λ x → (x ∙ ε M)) ≡ ( λ x → x ) |
971 | 124 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
|
125 |
783 | 126 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
|
127 Lemma-MM11 = extensionality30 Lemma-MM36 |
145 | 128 |
773 | 129 MonoidMonad : Monad A |
141 | 130 MonoidMonad = record { |
773 | 131 T = T |
132 ; η = η | |
133 ; μ = μ | |
134 ; isMonad = record { | |
148
6e80e1aaa8b9
no yellow on monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
135 unity1 = Lemma-MM3 ; |
141 | 136 unity2 = Lemma-MM4 ; |
148
6e80e1aaa8b9
no yellow on monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
137 assoc = Lemma-MM5 |
141 | 138 } |
139 } where | |
147 | 140 Lemma-MM3 : {a : Obj A} → A [ A [ TMap μ a o TMap η ( FObj T a ) ] ≈ Id {_} {_} {_} {A} (FObj T a) ] |
971 | 141 Lemma-MM3 {a} = let open ≈-Reasoning (A) renaming ( _o_ to _*_ ) hiding (_∙_) in |
141 | 142 begin |
143 TMap μ a o TMap η ( FObj T a ) | |
144 ≈⟨⟩ | |
783 | 145 ( λ x → ε M ∙ (proj₁ x) , proj₂ x ) |
149 | 146 ≈⟨ cong ( λ f → ( λ x → ( ( f (proj₁ x) ) , proj₂ x ))) ( Lemma-MM9 ) ⟩ |
147 | 147 ( λ (x : FObj T a) → (proj₁ x) , proj₂ x ) |
144 | 148 ≈⟨⟩ |
141 | 149 ( λ x → x ) |
150 ≈⟨⟩ | |
151 Id {_} {_} {_} {A} (FObj T a) | |
152 ∎ | |
153 Lemma-MM4 : {a : Obj A} → A [ A [ TMap μ a o (FMap T (TMap η a ))] ≈ Id {_} {_} {_} {A} (FObj T a) ] | |
971 | 154 Lemma-MM4 {a} = let open ≈-Reasoning (A) renaming ( _o_ to _*_ ) hiding (_∙_) in |
144 | 155 begin |
156 TMap μ a o (FMap T (TMap η a )) | |
157 ≈⟨⟩ | |
783 | 158 ( λ x → ( proj₁ x ∙ (ε M) , proj₂ x )) |
149 | 159 ≈⟨ cong ( λ f → ( λ x → ( f (proj₁ x) ) , proj₂ x )) ( Lemma-MM10 ) ⟩ |
144 | 160 ( λ x → (proj₁ x) , proj₂ x ) |
161 ≈⟨⟩ | |
162 ( λ x → x ) | |
163 ≈⟨⟩ | |
164 Id {_} {_} {_} {A} (FObj T a) | |
165 ∎ | |
141 | 166 Lemma-MM5 : {a : Obj A} → A [ A [ TMap μ a o TMap μ ( FObj T a ) ] ≈ A [ TMap μ a o FMap T (TMap μ a) ] ] |
971 | 167 Lemma-MM5 {a} = let open ≈-Reasoning (A) renaming ( _o_ to _*_ ) hiding (_∙_) in |
144 | 168 begin |
169 TMap μ a o TMap μ ( FObj T a ) | |
170 ≈⟨⟩ | |
783 | 171 ( λ x → (proj₁ x) ∙ (proj₁ (proj₂ x)) ∙ (proj₁ (proj₂ (proj₂ x))) , proj₂ (proj₂ (proj₂ x))) |
149 | 172 ≈⟨ 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
|
173 (( 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
|
174 )) Lemma-MM11 ⟩ |
783 | 175 ( λ x → ( proj₁ x) ∙(( proj₁ (proj₂ x)) ∙ (proj₁ (proj₂ (proj₂ x)))) , proj₂ (proj₂ (proj₂ x))) |
144 | 176 ≈⟨⟩ |
177 TMap μ a o FMap T (TMap μ a) | |
178 ∎ | |
141 | 179 |
180 | |
300 | 181 F : (m : Carrier M) → { a b : Obj A } → ( f : a → b ) → Hom A a ( FObj T b ) |
182 F m {a} {b} f = λ (x : a ) → ( m , ( f x) ) | |
141 | 183 |
151 | 184 postulate m m' : Carrier M |
185 postulate a b c' : Obj A | |
300 | 186 postulate f : b → c' |
187 postulate g : a → b | |
151 | 188 |
153 | 189 Lemma-MM12 = Monad.join MonoidMonad (F m f) (F m' g) |
151 | 190 |
773 | 191 open import kleisli {_} {_} {_} {A} {T} {η} {μ} {Monad.isMonad MonoidMonad} |
151 | 192 |
202
58ee98bbb333
remove an extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
193 -- nat-ε TMap = λ a₁ → record { KMap = λ x → x } |
58ee98bbb333
remove an extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
194 -- nat-η TMap = λ a₁ → _,_ (ε, M) |
58ee98bbb333
remove an extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
195 -- U_T Functor Kleisli A |
58ee98bbb333
remove an extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
196 -- 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
|
197 -- F_T Functor A Kleisli |
58ee98bbb333
remove an extensionality
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
170
diff
changeset
|
198 -- F_T FObj = λ a₁ → a₁ FMap = λ {a₁} {b₁} f₁ → record { KMap = λ x → ε M , f₁ x } |