Mercurial > hg > Members > kono > Proof > category
annotate monoid-monad.agda @ 150:5dc6f3f43507
clean up
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 15 Aug 2013 12:32:48 +0900 |
parents | 2f68a9e0167b |
children | 3bd5109c83f3 |
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 |
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
|
27 postulate Mono : ≡-Monoid 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
|
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 { |
149 | 36 FObj = λ a → (Carrier Mono) × a |
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} → |
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
|
45 Sets [ f ≈ g ] → Sets [ map (λ (x : Carrier Mono) → x) f ≈ map (λ (x : Carrier Mono) → 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} → |
51 A [ A [ FMap T f o (λ x → ε Mono , x) ] ≈ | |
52 A [ (λ x → ε Mono , x) o f ] ] | |
53 Lemma-MM1 {a} {b} {f} = let open ≈-Reasoning A renaming ( _o_ to _*_ ) in | |
139 | 54 begin |
144 | 55 FMap T f o (λ x → ε Mono , x) |
139 | 56 ≈⟨⟩ |
57 (λ x → ε Mono , x) o f | |
58 ∎ | |
59 | |
150 | 60 -- η : a → (ε,a) |
149 | 61 η : NTrans A A identityFunctor T |
139 | 62 η = record { |
149 | 63 TMap = λ a → λ(x : a) → ( ε Mono , x ) ; |
139 | 64 isNTrans = record { |
149 | 65 commute = Lemma-MM1 |
139 | 66 } |
67 } | |
68 | |
150 | 69 -- μ : (m,(m',a)) → (m*m,a) |
139 | 70 |
149 | 71 muMap : (a : Obj A ) → FObj T ( FObj T a ) → Σ (Carrier Mono) (λ x → a ) |
139 | 72 muMap a ( m , ( m' , x ) ) = ( _∙_ Mono m m' , x ) |
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 | |
149 | 97 Lemma-MM34 : ∀{ x : Carrier Mono } → ( (Mono ∙ ε Mono) x ≡ x ) |
147 | 98 Lemma-MM34 {x} = (( proj₁ ( IsMonoid.identity ( isMonoid Mono )) ) 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 |
149 | 100 Lemma-MM35 : ∀{ x : Carrier Mono } → ((Mono ∙ x) (ε Mono)) ≡ 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
|
101 Lemma-MM35 {x} = ( proj₂ ( IsMonoid.identity ( isMonoid Mono )) ) x |
141 | 102 |
149 | 103 Lemma-MM36 : ∀{ x y z : Carrier Mono } → ((Mono ∙ (Mono ∙ x) y) z) ≡ (_∙_ Mono x (_∙_ Mono 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
|
104 Lemma-MM36 {x} {y} {z} = ( IsMonoid.assoc ( isMonoid Mono )) x y z |
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 |
150 | 106 -- Functional Extensionarity Axiom (We cannot prove this in Agda / Coq, just assumming ) |
149 | 107 postulate Extensionarity : {f g : Carrier Mono → Carrier Mono } → (∀ {x} → (f x ≡ g x)) → ( f ≡ g ) |
144 | 108 |
149 | 109 postulate Extensionarity3 : {f g : Carrier Mono → Carrier Mono → Carrier Mono → Carrier Mono } → |
110 (∀{x y z} → f x y z ≡ g x y z ) → ( f ≡ g ) | |
144 | 111 |
149 | 112 Lemma-MM9 : ( λ(x : Carrier Mono) → ( Mono ∙ ε Mono ) x ) ≡ ( λ(x : Carrier Mono) → x ) |
113 Lemma-MM9 = Extensionarity Lemma-MM34 | |
144 | 114 |
149 | 115 Lemma-MM10 : ( λ x → ((Mono ∙ x) (ε Mono))) ≡ ( λ x → x ) |
116 Lemma-MM10 = Extensionarity 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
|
117 |
149 | 118 Lemma-MM11 : (λ x y z → ((Mono ∙ (Mono ∙ x) y) z)) ≡ (λ x y z → ( _∙_ Mono x (_∙_ Mono y z ) )) |
119 Lemma-MM11 = Extensionarity3 Lemma-MM36 | |
145 | 120 |
149 | 121 MonoidMonad : Monad A T η μ |
141 | 122 MonoidMonad = record { |
123 isMonad = record { | |
148
6e80e1aaa8b9
no yellow on monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
124 unity1 = Lemma-MM3 ; |
141 | 125 unity2 = Lemma-MM4 ; |
148
6e80e1aaa8b9
no yellow on monoid monad
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
147
diff
changeset
|
126 assoc = Lemma-MM5 |
141 | 127 } |
128 } where | |
147 | 129 Lemma-MM3 : {a : Obj A} → A [ A [ TMap μ a o TMap η ( FObj T a ) ] ≈ Id {_} {_} {_} {A} (FObj T a) ] |
149 | 130 Lemma-MM3 {a} = let open ≈-Reasoning (A) renaming ( _o_ to _*_ ) in |
141 | 131 begin |
132 TMap μ a o TMap η ( FObj T a ) | |
133 ≈⟨⟩ | |
134 ( λ x → ((Mono ∙ ε Mono) (proj₁ x) , proj₂ x )) | |
149 | 135 ≈⟨ cong ( λ f → ( λ x → ( ( f (proj₁ x) ) , proj₂ x ))) ( Lemma-MM9 ) ⟩ |
147 | 136 ( λ (x : FObj T a) → (proj₁ x) , proj₂ x ) |
144 | 137 ≈⟨⟩ |
141 | 138 ( λ x → x ) |
139 ≈⟨⟩ | |
140 Id {_} {_} {_} {A} (FObj T a) | |
141 ∎ | |
142 Lemma-MM4 : {a : Obj A} → A [ A [ TMap μ a o (FMap T (TMap η a ))] ≈ Id {_} {_} {_} {A} (FObj T a) ] | |
149 | 143 Lemma-MM4 {a} = let open ≈-Reasoning (A) renaming ( _o_ to _*_ ) in |
144 | 144 begin |
145 TMap μ a o (FMap T (TMap η a )) | |
146 ≈⟨⟩ | |
147 ( λ x → (Mono ∙ proj₁ x) (ε Mono) , proj₂ x ) | |
149 | 148 ≈⟨ cong ( λ f → ( λ x → ( f (proj₁ x) ) , proj₂ x )) ( Lemma-MM10 ) ⟩ |
144 | 149 ( λ x → (proj₁ x) , proj₂ x ) |
150 ≈⟨⟩ | |
151 ( λ x → x ) | |
152 ≈⟨⟩ | |
153 Id {_} {_} {_} {A} (FObj T a) | |
154 ∎ | |
141 | 155 Lemma-MM5 : {a : Obj A} → A [ A [ TMap μ a o TMap μ ( FObj T a ) ] ≈ A [ TMap μ a o FMap T (TMap μ a) ] ] |
149 | 156 Lemma-MM5 {a} = let open ≈-Reasoning (A) renaming ( _o_ to _*_ ) in |
144 | 157 begin |
158 TMap μ a o TMap μ ( FObj T a ) | |
159 ≈⟨⟩ | |
160 ( λ x → (Mono ∙ (Mono ∙ proj₁ x) (proj₁ (proj₂ x))) (proj₁ (proj₂ (proj₂ x))) , proj₂ (proj₂ (proj₂ x))) | |
149 | 161 ≈⟨ 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
|
162 (( 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
|
163 )) Lemma-MM11 ⟩ |
144 | 164 ( λ x → (Mono ∙ proj₁ x) ((Mono ∙ proj₁ (proj₂ x)) (proj₁ (proj₂ (proj₂ x)))) , proj₂ (proj₂ (proj₂ x))) |
165 ≈⟨⟩ | |
166 TMap μ a o FMap T (TMap μ a) | |
167 ∎ | |
141 | 168 |
169 | |
170 |