annotate free-monoid.agda @ 162:18ab1be1ebb5

mapping done
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 19 Aug 2013 12:34:08 +0900
parents ffeb33698173
children bc47179e3c9c
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
162
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
3 -- Shinji KONO <kono@ie.u-ryukyu.ac.jp>
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
4
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 open import Category -- https://github.com/konn/category-agda
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 open import Level
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 module free-monoid { c c₁ c₂ ℓ : Level } where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 open import Category.Sets
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 open import Category.Cat
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 open import HomReasoning
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 open import cat-utility
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 open import Relation.Binary.Core
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 open import Relation.Binary.PropositionalEquality
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
162
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
16 -- from https://github.com/danr/Agda-projects/blob/master/Category-Theory/FreeMonoid.agda
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 infixr 40 _::_
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
19 data List (A : Set c ) : Set c where
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 [] : List A
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 _::_ : A -> List A -> List A
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 infixl 30 _++_
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
25 _++_ : {A : Set c } -> List A -> List A -> List A
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 [] ++ ys = ys
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 (x :: xs) ++ ys = x :: (xs ++ ys)
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 ≡-cong = Relation.Binary.PropositionalEquality.cong
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
31 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
32 list-id-l {_} {_} = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
33 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
34 list-id-r {_} {[]} = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
35 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
36 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
37 ( xs ++ ( ys ++ zs ) ) ≡ ( ( xs ++ ys ) ++ zs )
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
38 list-assoc {_} {[]} {_} {_} = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
39 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
40 ( list-assoc {A} {xs} {ys} {zs} )
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
41 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
42 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
43 list-o-resp-≈ {A} refl refl = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
44 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
45 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
46 record { refl = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
47 ; sym = sym
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
48 ; trans = trans
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
49 }
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 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
52 open import Algebra.Structures
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
53 open import Data.Product
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 record ≡-Monoid : Set (suc c) where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 infixl 7 _∙_
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 field
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 Carrier : Set c
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 _∙_ : Op₂ Carrier
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 ε : Carrier
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 isMonoid : IsMonoid _≡_ _∙_ ε
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 open ≡-Monoid
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 record Monomorph ( a b : ≡-Monoid ) : Set (suc c) where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 field
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 morph : Carrier a -> Carrier b
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 identity : morph (ε a) ≡ ε b
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 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
71
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 open Monomorph
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
155
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
74 _+_ : { 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
75 _+_ {a} {b} {c} f g = record {
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 morph = \x -> morph f ( morph g x ) ;
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 identity = identity1 ;
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 mdistr = mdistr1
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 } where
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 identity1 : morph f ( morph g (ε a) ) ≡ ε c
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 -- morph f (ε b) = ε c , morph g (ε a) ) ≡ ε b
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 -- morph f morph g (ε a) ) ≡ morph f (ε b) = ε c
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 identity1 = trans ( ≡-cong (morph f ) ( identity g ) ) ( identity f )
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 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
85 -- ∀{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
86 -- ∀{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
87 mdistr1 = trans (≡-cong (morph f ) ( mdistr g) ) ( mdistr f )
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
155
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
89 M-id : { a : ≡-Monoid } -> Monomorph a a
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
90 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
91
155
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
92 _==_ : { 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
93 _==_ f g = morph f ≡ morph g
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
94
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
95 isMonoidCategory : IsCategory ≡-Monoid Monomorph _==_ _+_ (M-id)
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
96 isMonoidCategory = record { isEquivalence = isEquivalence1
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
97 ; identityL = refl
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
98 ; identityR = refl
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
99 ; associative = refl
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
100 ; 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
101 }
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
102 where
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
103 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
104 f == g → h == i → (h + f) == (i + g)
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
105 o-resp-≈ {A} refl refl = refl
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
106 isEquivalence1 : { a b : ≡-Monoid } -> IsEquivalence {_} {_} {Monomorph a b} _==_
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
107 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
108 record { refl = refl
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
109 ; sym = sym
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
110 ; trans = trans
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
111 }
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
112 MonoidCategory : Category _ _ _
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
113 MonoidCategory =
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
114 record { Obj = ≡-Monoid
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
115 ; Hom = Monomorph
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
116 ; _o_ = _+_
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
117 ; _≈_ = _==_
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
118 ; Id = M-id
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
119 ; isCategory = isMonoidCategory
d9cbaa749be6 Monoids done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 154
diff changeset
120 }
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
122 A = Sets {c}
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
123 B = MonoidCategory
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
125 open Functor
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
127 U : Functor B A
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
128 U = record {
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
129 FObj = \m -> Carrier m ;
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
130 FMap = \f -> morph f ;
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
131 isFunctor = record {
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
132 ≈-cong = \x -> x
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
133 ; identity = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
134 ; distr = refl
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
135 }
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
136 }
154
744be443e232 on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137
156
b15c1435cfcc list is monoid now.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 155
diff changeset
138 -- FObj
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 -- solution
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
158
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
159 open UniversalMapping
158
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 157
diff changeset
160
161
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
161 Φ : {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: 160
diff changeset
162 Φ {a} {b} {f} [] = ε b
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
163 Φ {a} {b} {f} ( x :: xs ) = _∙_ b ( f x ) (Φ {a} {b} {f} xs )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
164
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
165 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: 160
diff changeset
166 solution a b f = record {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
167 morph = \(l : List a) -> Φ l ;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
168 identity = refl ;
162
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
169 mdistr = \{x y} -> mdistr1 x y
161
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
170 } where
162
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
171 _*_ : Carrier b -> Carrier b -> Carrier b
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
172 _*_ f g = _∙_ b f g
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
173 mdistr1 : (x y : Carrier (Generator a)) → Φ ((Generator a ∙ x) y) ≡ (b ∙ Φ x) (Φ y)
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
174 mdistr1 [] y = sym (proj₁ ( IsMonoid.identity ( isMonoid b) ) (Φ y))
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
175 mdistr1 (x :: xs) y = let open ≡-Reasoning in
161
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
176 sym ( begin
162
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
177 (Φ {a} {b} {f} (x :: xs)) * (Φ {a} {b} {f} y)
161
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
178 ≡⟨⟩
162
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
179 ((f x) * (Φ {a} {b} {f} xs)) * (Φ {a} {b} {f} y)
161
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
180 ≡⟨ ( IsMonoid.assoc ( isMonoid b )) _ _ _ ⟩
162
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
181 (f x) * ( (Φ {a} {b} {f} xs) * (Φ {a} {b} {f} y) )
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
182 ≡⟨ sym ( (IsMonoid.∙-cong (isMonoid b)) refl (mdistr1 xs y )) ⟩
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
183 (f x) * ( Φ {a} {b} {f} ( xs ++ y ) )
161
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
184 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
185 Φ {a} {b} {f} ( x :: ( xs ++ y ) )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
186 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
187 Φ {a} {b} {f} ( (x :: xs) ++ y )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
188 ≡⟨⟩
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
189 Φ {a} {b} {f} ((Generator a ∙ x :: xs) y)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
190 ∎ )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
191
162
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
192 eta : (a : Obj A) → Hom A a ( FObj U (Generator a) )
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
193 eta a = \( x : a ) -> x :: []
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
194
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
195 -- Functional Extensionarity Axiom (We cannot prove this in Agda / Coq, just assumming )
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
196 postulate Extensionarity : { a b : Obj A } {f g : Hom A a b } → (∀ {x} → (f x ≡ g x)) → ( f ≡ g )
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
197
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
198 FreeMonoidUniveralMapping : UniversalMapping A B U Generator eta
162
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
199 FreeMonoidUniveralMapping =
157
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
200 record {
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
201 _* = \{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
202 isUniversalMapping = record {
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
203 universalMapping = \{a b f} -> universalMapping {a} {b} {f} ;
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
204 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
205 }
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
206 } where
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
207 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
208 universalMapping {a} {b} {f} = let open ≡-Reasoning in
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
209 begin
160
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 159
diff changeset
210 FMap U ( solution a b f ) o eta a
161
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 160
diff changeset
211 ≡⟨⟩
162
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
212 ( λ (x : a ) → Φ {a} {b} {f} (eta a x) )
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
213 ≡⟨⟩
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
214 ( λ (x : a ) → Φ {a} {b} {f} ( x :: [] ) )
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
215 ≡⟨⟩
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
216 ( λ (x : a ) → _∙_ b ( f x ) (Φ {a} {b} {f} [] ) )
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
217 ≡⟨⟩
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
218 ( λ (x : a ) → _∙_ b ( f x ) ( ε b ) )
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
219 ≡⟨ ≡-cong ( \ g -> ( ( λ (x : a ) → g x ) )) (Extensionarity lemma-ext1) ⟩
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
220 ( λ (x : a ) → f x )
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
221 ≡⟨⟩
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
222 f
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
223 ∎ where
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
224 lemma-ext1 : ∀{ x : a } -> _∙_ b ( f x ) ( ε b ) ≡ f x
18ab1be1ebb5 mapping done
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 161
diff changeset
225 lemma-ext1 {x} = ( proj₂ ( IsMonoid.identity ( isMonoid b) ) ) (f x)
159
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 158
diff changeset
226 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
227 { 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
228 uniquness = {!!}
157
34a152235ddd solution of universal mapping for free monoid
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 156
diff changeset
229