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