comparison CCCGraph.agda @ 911:b8c5f15ee561

small graph and small category on CCC to graph
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 02 May 2020 03:40:56 +0900
parents 8f41ad966eaa
children 635418b4b2f3
comparison
equal deleted inserted replaced
825:8f41ad966eaa 911:b8c5f15ee561
92 e4b = refl 92 e4b = refl
93 *-cong : {a b c : Obj Sets} {f f' : Hom Sets (a ∧ b) c} → 93 *-cong : {a b c : Obj Sets} {f f' : Hom Sets (a ∧ b) c} →
94 Sets [ f ≈ f' ] → Sets [ f * ≈ f' * ] 94 Sets [ f ≈ f' ] → Sets [ f * ≈ f' * ]
95 *-cong refl = refl 95 *-cong refl = refl
96 96
97 module ccc-from-graph where 97 open import graph
98 module ccc-from-graph {c₁ c₂ : Level} (G : Graph {c₁} {c₂} ) where
98 99
99 open import Relation.Binary.PropositionalEquality renaming ( cong to ≡-cong ) hiding ( [_] ) 100 open import Relation.Binary.PropositionalEquality renaming ( cong to ≡-cong ) hiding ( [_] )
100 open import graph
101 open graphtocat
102
103 open Graph 101 open Graph
104 102
105 data Objs (G : Graph {Level.zero} {Level.zero} ) : Set where -- formula 103 data Objs : Set c₁ where
106 atom : (vertex G) → Objs G 104 atom : (vertex G) → Objs
107 ⊤ : Objs G 105 ⊤ : Objs
108 _∧_ : Objs G → Objs G → Objs G 106 _∧_ : Objs → Objs → Objs
109 _<=_ : Objs G → Objs G → Objs G 107 _<=_ : Objs → Objs → Objs
110 108
111 data Arrow (G : Graph ) : Objs G → Objs G → Set where --- proof 109 data Arrows : (b c : Objs ) → Set ( c₁ ⊔ c₂ )
112 arrow : {a b : vertex G} → (edge G) a b → Arrow G (atom a) (atom b) 110 data Arrow : Objs → Objs → Set (c₁ ⊔ c₂) where --- case i
113 ○ : (a : Objs G ) → Arrow G a ⊤ 111 arrow : {a b : vertex G} → (edge G) a b → Arrow (atom a) (atom b)
114 π : {a b : Objs G } → Arrow G ( a ∧ b ) a 112 π : {a b : Objs } → Arrow ( a ∧ b ) a
115 π' : {a b : Objs G } → Arrow G ( a ∧ b ) b 113 π' : {a b : Objs } → Arrow ( a ∧ b ) b
116 ε : {a b : Objs G } → Arrow G ((a <= b) ∧ b ) a 114 ε : {a b : Objs } → Arrow ((a <= b) ∧ b ) a
117 <_,_> : {a b c : Objs G } → Arrow G c a → Arrow G c b → Arrow G c (a ∧ b) 115 _* : {a b c : Objs } → Arrows (c ∧ b ) a → Arrow c ( a <= b ) --- case v
118 _* : {a b c : Objs G } → Arrow G (c ∧ b ) a → Arrow G c ( a <= b ) 116
119 117 data Arrows where
120 data one {v : Level} {S : Set v} : Set v where 118 id : ( a : Objs ) → Arrows a a --- case i
121 elm : (x : S ) → one 119 ○ : ( a : Objs ) → Arrows a ⊤ --- case i
122 120 <_,_> : {a b c : Objs } → Arrows c a → Arrows c b → Arrows c (a ∧ b) -- case iii
123 iso→ : {v : Level} {S : Set v} → one → S 121 iv : {b c d : Objs } ( f : Arrow d c ) ( g : Arrows b d ) → Arrows b c -- cas iv
124 iso→ (elm x) = x 122
125 123 _・_ : {a b c : Objs } (f : Arrows b c ) → (g : Arrows a b) → Arrows a c
126 data iso← {v : Level} {S : Set v} : (one {v} {S} ) → S → Set v where 124 id a ・ g = g
127 elmeq : {x : S} → iso← ( elm x ) x 125 ○ a ・ g = ○ _
128 126 < f , g > ・ h = < f ・ h , g ・ h >
129 iso-left : {v : Level} {S : Set v} → (x : one {v} {S} ) → (a : S ) → iso← x a → iso→ x ≡ a 127 iv f g ・ h = iv f ( g ・ h )
130 iso-left (elm x) .x elmeq = refl 128
131 129 identityL : {A B : Objs} {f : Arrows A B} → (id B ・ f) ≡ f
132 iso-right : {v : Level} {S : Set v} → (x : one {v} {S} ) → iso← x ( iso→ x ) 130 identityL = refl
133 iso-right (elm x) = elmeq 131
134 132 identityR : {A B : Objs} {f : Arrows A B} → (f ・ id A) ≡ f
135 -- record one {v : Level} {S : Set v} : Set (suc v) where 133 identityR {a} {a} {id a} = refl
136 -- field 134 identityR {a} {⊤} {○ a} = refl
137 -- elm : S 135 identityR {a} {_} {< f , f₁ >} = cong₂ (λ j k → < j , k > ) identityR identityR
136 identityR {a} {b} {iv f g} = cong (λ k → iv f k ) identityR
137
138 assoc≡ : {a b c d : Objs} (f : Arrows c d) (g : Arrows b c) (h : Arrows a b) →
139 (f ・ (g ・ h)) ≡ ((f ・ g) ・ h)
140 assoc≡ (id a) g h = refl
141 assoc≡ (○ a) g h = refl
142 assoc≡ < f , f₁ > g h = cong₂ (λ j k → < j , k > ) (assoc≡ f g h) (assoc≡ f₁ g h)
143 assoc≡ (iv f f1) g h = cong (λ k → iv f k ) ( assoc≡ f1 g h )
144
145 -- positive intutionistic calculus
146 PL : Category c₁ (c₁ ⊔ c₂) (c₁ ⊔ c₂)
147 PL = record {
148 Obj = Objs;
149 Hom = λ a b → Arrows a b ;
150 _o_ = λ{a} {b} {c} x y → x ・ y ;
151 _≈_ = λ x y → x ≡ y ;
152 Id = λ{a} → id a ;
153 isCategory = record {
154 isEquivalence = record {refl = refl ; trans = trans ; sym = sym} ;
155 identityL = λ {a b f} → identityL {a} {b} {f} ;
156 identityR = λ {a b f} → identityR {a} {b} {f} ;
157 o-resp-≈ = λ {a b c f g h i} → o-resp-≈ {a} {b} {c} {f} {g} {h} {i} ;
158 associative = λ{a b c d f g h } → assoc≡ f g h
159 }
160 } where
161 o-resp-≈ : {A B C : Objs} {f g : Arrows A B} {h i : Arrows B C} →
162 f ≡ g → h ≡ i → (h ・ f) ≡ (i ・ g)
163 o-resp-≈ refl refl = refl
164
165 --------
138 -- 166 --
139 -- iso→ : {v : Level} {S : Set v} → one {v} {S} → One {Level.zero} → S 167 -- Functor from Positive Logic to Sets
140 -- iso→ x OneObj = one.elm x
141 -- iso← : {v : Level} {S : Set v} → one {v} {S} → S → One {Level.zero}
142 -- iso← x y = OneObj
143 -- 168 --
144 -- iso-left : {v : Level} {S : Set v} → (x : one {v} {S} ) → (a : S ) → iso→ x ( iso← x a ) ≡ a
145 -- iso-left x a = {!!}
146 --
147 -- iso-right : {v : Level} {S : Set v} → (x : one {v} {S} ) → iso← x ( iso→ x OneObj ) ≡ OneObj
148 -- iso-right x = refl
149
150 record one' {v : Level} {S : Set v} : Set (suc v) where
151 field
152 elm' : S
153 iso→' : One {Level.zero} → S
154 iso←' : S → One {Level.zero}
155 iso-left' : iso→' ( iso←' elm' ) ≡ elm'
156 iso-right' : iso←' ( iso→' OneObj ) ≡ OneObj
157
158 tmp : {v : Level} {S : Set v} → one {v} {S} → one' {v} {S}
159 tmp x = record {
160 elm' = iso→ x
161 ; iso→' = λ _ → iso→ x
162 ; iso←' = λ _ → OneObj
163 ; iso-left' = refl
164 ; iso-right' = refl
165 }
166
167
168
169 record SM {v : Level} : Set (suc v) where
170 field
171 graph : Graph {v} {v}
172 sobj : vertex graph → Set
173 smap : { a b : vertex graph } → edge graph a b → sobj a → sobj b
174
175 open SM
176
177 -- positive intutionistic calculus
178 PL : (G : SM) → Graph
179 PL G = record { vertex = Objs (graph G) ; edge = Arrow (graph G) }
180 DX : (G : SM) → Category Level.zero Level.zero Level.zero
181 DX G = GraphtoCat (PL G)
182 169
183 -- open import Category.Sets 170 -- open import Category.Sets
184 -- postulate extensionality : { c₁ c₂ ℓ : Level} ( A : Category c₁ c₂ ℓ ) → Relation.Binary.PropositionalEquality.Extensionality c₂ c₂ 171 -- postulate extensionality : { c₁ c₂ ℓ : Level} ( A : Category c₁ c₂ ℓ ) → Relation.Binary.PropositionalEquality.Extensionalit y c₂ c₂
185 172
186 fobj : {G : SM} ( a : Objs (graph G) ) → Set 173 C = graphtocat.Chain G
187 fobj {G} (atom x) = sobj G x 174
188 fobj {G} (a ∧ b) = (fobj {G} a ) /\ (fobj {G} b ) 175 tr : {a b : vertex G} → edge G a b → ((y : vertex G) → C y a) → (y : vertex G) → C y b
189 fobj {G} (a <= b) = fobj {G} b → fobj {G} a 176 tr f x y = graphtocat.next f (x y)
177
178 fobj : ( a : Objs ) → Set (c₁ ⊔ c₂ )
179 fobj (atom x) = ( y : vertex G ) → C y x
190 fobj ⊤ = One 180 fobj ⊤ = One
191 amap : {G : SM} { a b : Objs (graph G) } → Arrow (graph G) a b → fobj {G} a → fobj {G} b 181 fobj (a ∧ b) = ( fobj a /\ fobj b)
192 amap {G} (arrow x) = smap G x 182 fobj (a <= b) = fobj b → fobj a
193 amap (○ a) _ = OneObj 183
194 amap π ( x , _) = x 184 fmap : { a b : Objs } → Hom PL a b → fobj a → fobj b
195 amap π'( _ , x) = x 185 amap : { a b : Objs } → Arrow a b → fobj a → fobj b
196 amap ε ( f , x ) = f x 186 amap (arrow x) = tr x
197 amap < f , g > x = (amap f x , amap g x) 187 amap π ( x , y ) = x
198 amap (f *) x = λ y → amap f ( x , y ) 188 amap π' ( x , y ) = y
199 fmap : {G : SM} { a b : Objs (graph G) } → Hom (DX G) a b → fobj {G} a → fobj {G} b 189 amap ε (f , x ) = f x
200 fmap {G} {a} (id a) = λ z → z 190 amap (f *) x = λ y → fmap f ( x , y )
201 fmap {G} (next x f ) = Sets [ amap {G} x o fmap f ] 191 fmap (id a) x = x
202 192 fmap (○ a) x = OneObj
203 -- CS is a map from Positive logic to Sets 193 fmap < f , g > x = ( fmap f x , fmap g x )
204 -- Sets is CCC, so we have a cartesian closed category generated by a graph 194 fmap (iv x f) a = amap x ( fmap f a )
205 -- as a sub category of Sets 195
206 196 -- CS is a map from Positive logic to Sets
207 CS : (G : SM ) → Functor (DX G) (Sets {Level.zero}) 197 -- Sets is CCC, so we have a cartesian closed category generated by a graph
208 FObj (CS G) a = fobj a 198 -- as a sub category of Sets
209 FMap (CS G) {a} {b} f = fmap {G} {a} {b} f 199
210 isFunctor (CS G) = isf where 200 CS : Functor PL (Sets {c₁ ⊔ c₂ })
211 _++_ = Category._o_ (DX G) 201 FObj CS a = fobj a
212 ++idR = IsCategory.identityR ( Category.isCategory ( DX G ) ) 202 FMap CS {a} {b} f = fmap {a} {b} f
213 distr : {a b c : Obj (DX G)} { f : Hom (DX G) a b } { g : Hom (DX G) b c } → (z : fobj {G} a ) → fmap (g ++ f) z ≡ fmap g (fmap f z) 203 isFunctor CS = isf where
214 distr {a} {b} {c} {f} {next {b} {d} {c} x g} z = adistr (distr {a} {b} {d} {f} {g} z ) x where 204 _+_ = Category._o_ PL
215 adistr : fmap (g ++ f) z ≡ fmap g (fmap f z) → 205 ++idR = IsCategory.identityR ( Category.isCategory PL )
216 ( x : Arrow (graph G) d c ) → fmap ( next x (g ++ f) ) z ≡ fmap ( next x g ) (fmap f z ) 206 distr : {a b c : Obj PL} { f : Hom PL a b } { g : Hom PL b c } → (z : fobj a ) → fmap (g + f) z ≡ fmap g (fmap f z)
217 adistr eq x = cong ( λ k → amap x k ) eq 207 distr {a} {a₁} {a₁} {f} {id a₁} z = refl
218 distr {a} {b} {b} {f} {id b} z = refl 208 distr {a} {a₁} {⊤} {f} {○ a₁} z = refl
219 isf : IsFunctor (DX G) Sets fobj fmap 209 distr {a} {b} {c ∧ d} {f} {< g , g₁ >} z = cong₂ (λ j k → j , k ) (distr {a} {b} {c} {f} {g} z) (distr {a} {b} {d} {f} {g₁} z)
220 IsFunctor.identity isf = extensionality Sets ( λ x → refl ) 210 distr {a} {b} {c} {f} {iv {_} {_} {d} x g} z = adistr (distr {a} {b} {d} {f} {g} z) x where
221 IsFunctor.≈-cong isf refl = refl 211 adistr : fmap (g + f) z ≡ fmap g (fmap f z) →
222 IsFunctor.distr isf {a} {b} {c} {g} {f} = extensionality Sets ( λ z → distr {a} {b} {c} {g} {f} z ) 212 ( x : Arrow d c ) → fmap ( iv x (g + f) ) z ≡ fmap ( iv x g ) (fmap f z )
213 adistr eq x = cong ( λ k → amap x k ) eq
214 isf : IsFunctor PL Sets fobj fmap
215 IsFunctor.identity isf = extensionality Sets ( λ x → refl )
216 IsFunctor.≈-cong isf refl = refl
217 IsFunctor.distr isf {a} {b} {c} {g} {f} = extensionality Sets ( λ z → distr {a} {b} {c} {g} {f} z )
218
219
223 220
224 --- 221 ---
225 --- SubCategoy SC F A is a category with Obj = FObj F, Hom = FMap 222 --- SubCategoy SC F A is a category with Obj = FObj F, Hom = FMap
226 --- 223 ---
227 --- CCC ( SC (CS G)) Sets have to be proved 224 --- CCC ( SC (CS G)) Sets have to be proved
231 228
232 229
233 record CCCObj { c₁ c₂ ℓ : Level} : Set (suc (c₁ ⊔ c₂ ⊔ ℓ)) where 230 record CCCObj { c₁ c₂ ℓ : Level} : Set (suc (c₁ ⊔ c₂ ⊔ ℓ)) where
234 field 231 field
235 cat : Category c₁ c₂ ℓ 232 cat : Category c₁ c₂ ℓ
233 ≡←≈ : {a b : Obj cat } → { f g : Hom cat a b } → cat [ f ≈ g ] → f ≡ g
236 ccc : CCC cat 234 ccc : CCC cat
237 235
238 open CCCObj 236 open CCCObj
239 237
240 record CCCMap {c₁ c₂ ℓ : Level} (A B : CCCObj {c₁} {c₂} {ℓ} ) : Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where 238 record CCCMap {c₁ c₂ ℓ : Level} (A B : CCCObj {c₁} {c₂} {ℓ} ) : Set (suc (c₁ ⊔ c₂ ⊔ ℓ )) where
266 }} 264 }}
267 265
268 open import graph 266 open import graph
269 open Graph 267 open Graph
270 268
271 record GMap {v v' : Level} (x y : Graph {v} {v'} ) : Set (suc (v ⊔ v') ) where 269 record GMap {v v' : Level} (x y : Graph {v} {v'} ) : Set (v ⊔ v' ) where
272 field 270 field
273 vmap : vertex x → vertex y 271 vmap : vertex x → vertex y
274 emap : {a b : vertex x} → edge x a b → edge y (vmap a) (vmap b) 272 emap : {a b : vertex x} → edge x a b → edge y (vmap a) (vmap b)
275 273
276 open GMap 274 open GMap
286 _=m=_ {C = C} {D = D} F G = ∀{A B : vertex C} → (f : edge C A B) → [ D ] emap F f == emap G f 284 _=m=_ {C = C} {D = D} F G = ∀{A B : vertex C} → (f : edge C A B) → [ D ] emap F f == emap G f
287 285
288 _&_ : {v v' : Level} {x y z : Graph {v} {v'}} ( f : GMap y z ) ( g : GMap x y ) → GMap x z 286 _&_ : {v v' : Level} {x y z : Graph {v} {v'}} ( f : GMap y z ) ( g : GMap x y ) → GMap x z
289 f & g = record { vmap = λ x → vmap f ( vmap g x ) ; emap = λ x → emap f ( emap g x ) } 287 f & g = record { vmap = λ x → vmap f ( vmap g x ) ; emap = λ x → emap f ( emap g x ) }
290 288
291 Grp : {v v' : Level} → Category (suc (v ⊔ v')) (suc v ⊔ v') (suc ( v ⊔ v')) 289 Grph : {v v' : Level} → Category (suc (v ⊔ v')) (v ⊔ v') (suc ( v ⊔ v'))
292 Grp {v} {v'} = record { 290 Grph {v} {v'} = record {
293 Obj = Graph {v} {v'} 291 Obj = Graph {v} {v'}
294 ; Hom = GMap {v} {v'} 292 ; Hom = GMap {v} {v'}
295 ; _o_ = _&_ 293 ; _o_ = _&_
296 ; _≈_ = _=m=_ 294 ; _≈_ = _=m=_
297 ; Id = record { vmap = λ y → y ; emap = λ f → f } 295 ; Id = record { vmap = λ y → y ; emap = λ f → f }
338 g 336 g
339 ≈⟨ g=g' ⟩ 337 ≈⟨ g=g' ⟩
340 g' 338 g'
341 ∎ ) 339 ∎ )
342 340
343 fobj : {c₁ c₂ ℓ : Level} → Obj (Cart {c₁} {c₂} {ℓ} ) → Obj (Grp {c₁} {c₂}) 341 fobj : {c₁ c₂ ℓ : Level} → Obj (Cart {c₁} {c₂} {ℓ} ) → Obj (Grph {c₁} {c₂})
344 fobj a = record { vertex = Obj (cat a) ; edge = Hom (cat a) } 342 fobj a = record { vertex = Obj (cat a) ; edge = Hom (cat a) }
345 fmap : {c₁ c₂ ℓ : Level} → {a b : Obj (Cart {c₁} {c₂} {ℓ} ) } → Hom (Cart {c₁} {c₂} {ℓ} ) a b → Hom (Grp {c₁} {c₂}) ( fobj a ) ( fobj b ) 343 fmap : {c₁ c₂ ℓ : Level} → {a b : Obj (Cart {c₁} {c₂} {ℓ} ) } → Hom (Cart {c₁} {c₂} {ℓ} ) a b → Hom (Grph {c₁} {c₂}) ( fobj a ) ( fobj b )
346 fmap f = record { vmap = FObj (cmap f) ; emap = FMap (cmap f) } 344 fmap f = record { vmap = FObj (cmap f) ; emap = FMap (cmap f) }
347 345
348 UX : {c₁ c₂ ℓ : Level} → ( ≈-to-≡ : (A : Category c₁ c₂ ℓ ) → {a b : Obj A} → {f g : Hom A a b} → A [ f ≈ g ] → f ≡ g ) 346 UX : {c₁ c₂ ℓ : Level} → Functor (Cart {c₁} {c₂} {ℓ} ) (Grph {c₁} {c₂} )
349 → Functor (Cart {c₁} {c₂} {ℓ} ) (Grp {c₁} {c₂}) 347 FObj UX a = fobj a
350 FObj (UX {c₁} {c₂} {ℓ} ≈-to-≡ ) a = fobj a 348 FMap UX f = fmap f
351 FMap (UX ≈-to-≡) f = fmap f 349 isFunctor UX = isf where
352 isFunctor (UX {c₁} {c₂} {ℓ} ≈-to-≡) = isf where 350 isf : IsFunctor Cart Grph fobj fmap
353 -- if we don't need ≈-cong ( i.e. f ≈ g → UX f =m= UX g ), all lemmas are not necessary 351 IsFunctor.identity isf {a} {b} {f} e = mrefl refl
354 open import HomReasoning 352 IsFunctor.distr isf {a} {b} {c} f = mrefl refl
355 isf : IsFunctor (Cart {c₁} {c₂} {ℓ} ) (Grp {c₁} {c₂}) fobj fmap 353 IsFunctor.≈-cong isf {a} {b} {f} {g} f=g e = lemma ( (extensionality Sets ( λ z → lemma4 (
356 IsFunctor.identity isf {a} {b} {f} e = mrefl refl 354 ≃-cong (cat b) (f=g (id1 (cat a) z)) (IsFunctor.identity (Functor.isFunctor (cmap f))) (IsFunctor.identity (Functor.isFunctor (cmap g)))
357 IsFunctor.distr isf f = mrefl refl 355 )))) (f=g e) where
358 IsFunctor.≈-cong isf {a} {b} {f} {g} eq {x} {y} e = lemma (extensionality Sets ( λ z → lemma4 ( 356 lemma4 : {x y : vertex (fobj b) } → [_]_~_ (cat b) (id1 (cat b) x) (id1 (cat b) y) → x ≡ y
359 ≃-cong (cat b) (eq (id1 (cat a) z)) (IsFunctor.identity (Functor.isFunctor (cmap f))) (IsFunctor.identity (Functor.isFunctor (cmap g))) 357 lemma4 (refl eqv) = refl
360 ))) (eq e) where 358 lemma : vmap (fmap f) ≡ vmap (fmap g) → [ cat b ] FMap (cmap f) e ~ FMap (cmap g) e → [ fobj b ] emap (fmap f) e == emap (fmap g) e
361 lemma4 : {x y : vertex (fobj b) } → [_]_~_ (cat b) (id1 (cat b) x) (id1 (cat b) y) → x ≡ y 359 lemma refl (refl eqv) = mrefl (≡←≈ b eqv)
362 lemma4 (refl eqv) = refl 360
363 lemma : vmap (fmap f) ≡ vmap (fmap g) → [ cat b ] FMap (cmap f) e ~ FMap (cmap g) e → [ fobj b ] emap (fmap f) e == emap (fmap g) e 361
364 lemma refl (refl eqv) = mrefl ( ≈-to-≡ (cat b) eqv ) 362 open ccc-from-graph.Objs
365 363 open ccc-from-graph.Arrow
366 364 open ccc-from-graph.Arrows
367 --- 365 open graphtocat.Chain
368 --- open ccc-from-graph 366
369 --- 367 ccc-graph-univ : {c₁ : Level } → UniversalMapping (Grph {c₁} {c₁} ) (Cart {c₁} {c₁} {c₁} ) UX
370 --- sm : {v : Level } → Graph {v} → SM {v} 368 ccc-graph-univ {c₁} = record {
371 --- SM.graph (sm g) = g 369 F = λ g → csc g ;
372 --- SM.sobj (sm g) = {!!} 370 η = λ a → record { vmap = λ y → atom y ; emap = λ f x y → next f (x y) } ;
373 --- SM.smap (sm g) = {!!} 371 _* = {!!} ;
374 --- 372 isUniversalMapping = record {
375 --- HX : {v : Level } ( x : Obj (Grp {v}) ) → Obj (Grp {v}) 373 universalMapping = {!!} ;
376 --- HX {v} x = {!!} -- FObj UX ( record { cat = Sets {v} ; ccc = sets } ) 374 uniquness = {!!}
377 --- 375 }
378 --- 376 } where
379 --- 377 csc : Graph → Obj Cart
380 --- 378 csc g = record { cat = {!!} ; ccc = {!!} } where
379 open ccc-from-graph g
380