annotate free-monoid.agda @ 160:c9f29b84ca2f

hmmm
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 19 Aug 2013 04:49:07 +0900
parents 0be3e0a49cca
children ffeb33698173
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
155
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
1 -- {-# OPTIONS --universe-polymorphism #-}
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
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 module free-monoid { c c₁ c₂ ℓ : Level } where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 open import Category.Sets
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 open import Category.Cat
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import HomReasoning
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import cat-utility
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import Relation.Binary.Core
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 open import Relation.Binary.PropositionalEquality
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 infixr 40 _::_
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
17 data List (A : Set c ) : Set c where
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 [] : List A
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 _::_ : A -> List A -> List A
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 infixl 30 _++_
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
23 _++_ : {A : Set c } -> List A -> List A -> List A
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 [] ++ ys = ys
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 (x :: xs) ++ ys = x :: (xs ++ ys)
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 ≡-cong = Relation.Binary.PropositionalEquality.cong
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
29 list-id-l : { A : Set c } -> { x : List A } -> [] ++ x ≡ x
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
30 list-id-l {_} {_} = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
31 list-id-r : { A : Set c } -> { x : List A } -> x ++ [] ≡ x
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
32 list-id-r {_} {[]} = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
33 list-id-r {A} {x :: xs} = ≡-cong ( \y -> x :: y ) ( list-id-r {A} {xs} )
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
34 list-assoc : {A : Set c} -> { xs ys zs : List A } ->
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
35 ( xs ++ ( ys ++ zs ) ) ≡ ( ( xs ++ ys ) ++ zs )
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
36 list-assoc {_} {[]} {_} {_} = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
37 list-assoc {A} {x :: xs} {ys} {zs} = ≡-cong ( \y -> x :: y )
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
38 ( list-assoc {A} {xs} {ys} {zs} )
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
39 list-o-resp-≈ : {A : Set c} -> {f g : List A } → {h i : List A } →
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
40 f ≡ g → h ≡ i → (h ++ f) ≡ (i ++ g)
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
41 list-o-resp-≈ {A} refl refl = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
42 list-isEquivalence : {A : Set c} -> IsEquivalence {_} {_} {List A } _≡_
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
43 list-isEquivalence {A} = -- this is the same function as A's equivalence but has different types
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
44 record { refl = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
45 ; sym = sym
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
46 ; trans = trans
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
47 }
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 open import Algebra.FunctionProperties using (Op₁; Op₂)
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
50 open import Algebra.Structures
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
51 open import Data.Product
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 record ≡-Monoid : Set (suc c) where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 infixl 7 _∙_
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 field
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 Carrier : Set c
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 _∙_ : Op₂ Carrier
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 ε : Carrier
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 isMonoid : IsMonoid _≡_ _∙_ ε
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 open ≡-Monoid
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 record Monomorph ( a b : ≡-Monoid ) : Set (suc c) where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 field
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 morph : Carrier a -> Carrier b
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 identity : morph (ε a) ≡ ε b
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 mdistr : ∀{x y} -> morph ( _∙_ a x y ) ≡ ( _∙_ b (morph x ) (morph y) )
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 open Monomorph
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
155
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
72 _+_ : { a b c : ≡-Monoid } -> Monomorph b c -> Monomorph a b -> Monomorph a c
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
73 _+_ {a} {b} {c} f g = record {
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 morph = \x -> morph f ( morph g x ) ;
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 identity = identity1 ;
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 mdistr = mdistr1
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 } where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 identity1 : morph f ( morph g (ε a) ) ≡ ε c
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 -- morph f (ε b) = ε c , morph g (ε a) ) ≡ ε b
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 -- morph f morph g (ε a) ) ≡ morph f (ε b) = ε c
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 identity1 = trans ( ≡-cong (morph f ) ( identity g ) ) ( identity f )
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 mdistr1 : ∀{x y} -> morph f ( morph g ( _∙_ a x y )) ≡ ( _∙_ c (morph f (morph g x )) (morph f (morph g y) ) )
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 -- ∀{x y} -> morph f ( morph g ( _∙_ a x y )) ≡ morph f ( ( _∙_ c (morph g x )) (morph g y) )
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 -- ∀{x y} -> morph f ( ( _∙_ c (morph g x )) (morph g y) ) ≡ ( _∙_ c (morph f (morph g x )) (morph f (morph g y) ) )
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 mdistr1 = trans (≡-cong (morph f ) ( mdistr g) ) ( mdistr f )
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
155
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
87 M-id : { a : ≡-Monoid } -> Monomorph a a
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
88 M-id = record { morph = \x -> x ; identity = refl ; mdistr = refl }
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89
155
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
90 _==_ : { a b : ≡-Monoid } -> Monomorph a b -> Monomorph a b -> Set c
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
91 _==_ f g = morph f ≡ morph g
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
92
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
93 isMonoidCategory : IsCategory ≡-Monoid Monomorph _==_ _+_ (M-id)
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
94 isMonoidCategory = record { isEquivalence = isEquivalence1
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
95 ; identityL = refl
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
96 ; identityR = refl
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
97 ; associative = refl
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
98 ; o-resp-≈ = \{a} {b} {c} {f} {g} {h} {i} -> o-resp-≈ {a} {b} {c} {f} {g} {h} {i}
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
99 }
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
100 where
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
101 o-resp-≈ : {a b c : ≡-Monoid } {f g : Monomorph a b } → {h i : Monomorph b c } →
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
102 f == g → h == i → (h + f) == (i + g)
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
103 o-resp-≈ {A} refl refl = refl
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
104 isEquivalence1 : { a b : ≡-Monoid } -> IsEquivalence {_} {_} {Monomorph a b} _==_
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
105 isEquivalence1 = -- this is the same function as A's equivalence but has different types
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
106 record { refl = refl
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
107 ; sym = sym
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
108 ; trans = trans
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
109 }
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
110 MonoidCategory : Category _ _ _
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
111 MonoidCategory =
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
112 record { Obj = ≡-Monoid
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
113 ; Hom = Monomorph
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
114 ; _o_ = _+_
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
115 ; _≈_ = _==_
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
116 ; Id = M-id
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
117 ; isCategory = isMonoidCategory
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
118 }
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
121 A = Sets {c}
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
122 B = MonoidCategory
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
124 open Functor
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
126 U : Functor B A
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
127 U = record {
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
128 FObj = \m -> Carrier m ;
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
129 FMap = \f -> morph f ;
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
130 isFunctor = record {
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
131 ≈-cong = \x -> x
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
132 ; identity = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
133 ; distr = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
134 }
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
135 }
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
137 -- FObj
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
138
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
139 list : (a : Set c) -> ≡-Monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
140 list a = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
141 Carrier = List a
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
142 ; _∙_ = _++_
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
143 ; ε = []
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
144 ; isMonoid = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
145 identity = ( ( \x -> list-id-l {a} ) , ( \x -> list-id-r {a} ) ) ;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
146 isSemigroup = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
147 assoc = \x -> \y -> \z -> sym ( list-assoc {a} {x} {y} {z} )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
148 ; isEquivalence = list-isEquivalence
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
149 ; ∙-cong = \x -> \y -> list-o-resp-≈ y x
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
150 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
151 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
152 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
153
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
154 Generator : Obj A -> Obj B
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
155 Generator s = list s
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
156
157
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
157 -- η
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
158
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
159 postulate eta : (a : Obj A) → Hom A a ( FObj U (Generator a) )
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
160
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
161 -- solution
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
162
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
163 open UniversalMapping
158
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
164
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
165 FreeMonoidUniveralMapping : UniversalMapping A B U Generator eta
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
166 FreeMonoidUniveralMapping =
157
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
167 record {
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
168 _* = \{a b} -> \f -> solution a b f ;
157
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
169 isUniversalMapping = record {
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
170 universalMapping = \{a b f} -> universalMapping {a} {b} {f} ;
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
171 uniquness = \{a b f} -> uniquness {a} {b} {f}
157
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
172 }
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
173 } where
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
174 Φ : {a : Obj A } {b : Obj B} { f : Hom A a (FObj U b) } → List a -> Carrier b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
175 Φ {a} {b} {f} [] = ε b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
176 Φ {a} {b} {f} ( x :: xs ) = _∙_ b ( f x ) (Φ {a} {b} {f} xs )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
177 lemma-fm-1 : {a : Obj A } {b : Obj B} { f : Hom A a (FObj U b) } →
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
178 (x y : Carrier (Generator a)) → Φ {a} {b} {f} ((Generator a ∙ x) y) ≡ (b ∙ Φ {a} {b} {f} x) (Φ {a} {b} {f} y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
179 lemma-fm-1 {a} {b} {f} [] y = sym (proj₁ ( IsMonoid.identity ( isMonoid b) ) (Φ {a} {b} {f} y))
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
180 lemma-fm-1 {a} {b} {f} (x :: xs) y = let open ≡-Reasoning in
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
181 sym ( begin
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
182 _∙_ b (Φ {a} {b} {f} (x :: xs)) (Φ {a} {b} {f} y)
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
183 ≡⟨⟩
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
184 _∙_ b ( _∙_ b (f x) (Φ {a} {b} {f} xs)) (Φ {a} {b} {f} y)
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
185 ≡⟨ ( IsMonoid.assoc ( isMonoid b )) _ _ _ ⟩
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
186 _∙_ b (f x) ( _∙_ b (Φ {a} {b} {f} xs) (Φ {a} {b} {f} y) )
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
187 ≡⟨ sym ( (IsMonoid.∙-cong (isMonoid b)) refl (lemma-fm-1 {a} {b} {f} xs y )) ⟩
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
188 _∙_ b (f x) ( Φ {a} {b} {f} ( xs ++ y ) )
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
189 ≡⟨⟩
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
190 Φ {a} {b} {f} ( x :: ( xs ++ y ) )
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
191 ≡⟨⟩
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
192 Φ {a} {b} {f} ( (x :: xs) ++ y )
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
193 ≡⟨⟩
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
194 Φ {a} {b} {f} ((Generator a ∙ x :: xs) y)
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
195 ∎ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
196 solution : (a : Obj A ) (b : Obj B) ( f : Hom A a (FObj U b) ) → Hom B (Generator a ) b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
197 solution a b f = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
198 morph = \(l : List a) -> Φ l ;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
199 identity = refl ;
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
200 mdistr = \{x y} -> lemma-fm-1 {a} {b} {f} x y
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
201 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
202 universalMapping : {a : Obj A } {b : Obj B} { f : Hom A a (FObj U b) } → FMap U ( solution a b f ) o eta a ≡ f
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
203 universalMapping {a} {b} {f} = let open ≡-Reasoning in
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
204 begin
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
205 FMap U ( solution a b f ) o eta a
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
206 ≡⟨ {!!} ⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
207 f
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
208
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
209 uniquness : {a : Obj A } {b : Obj B} { f : Hom A a (FObj U b) } →
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
210 { g : Hom B (Generator a) b } → (FMap U g) o (eta a ) ≡ f → B [ solution a b f ≈ g ]
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
211 uniquness = {!!}
157
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
212