@@ -7,9 +7,13 @@ description: |
77open import 1Lab.Path.Cartesian
88open import 1Lab.Reflection
99
10+ open import Cat.Functor.Equivalence.Path
11+ open import Cat.Instances.Shape.Parallel
12+ open import Cat.Functor.Equivalence
1013open import Cat.Instances.StrictCat
1114open import Cat.Functor.Properties
1215open import Cat.Functor.Base
16+ open import Cat.Univalent
1317open import Cat.Prelude
1418open import Cat.Strict
1519
@@ -145,6 +149,11 @@ Graph-hom-path {G = G} {H = H} p0 p1 =
145149instance
146150 Funlike-Graph-hom : Funlike (Graph-hom G H) ⌞ G ⌟ λ _ → ⌞ H ⌟
147151 Funlike-Graph-hom .Funlike._#_ = vertex
152+
153+ Graph-hom-id : {G : Graph o ℓ} → Graph-hom G G
154+ Graph-hom-id .vertex v = v
155+ Graph-hom-id .edge e = e
156+
148157```
149158-->
150159
@@ -155,30 +164,221 @@ Graphs : ∀ o ℓ → Precategory (lsuc (o ⊔ ℓ)) (o ⊔ ℓ)
155164Graphs o ℓ .Precategory.Ob = Graph o ℓ
156165Graphs o ℓ .Precategory.Hom = Graph-hom
157166Graphs o ℓ .Precategory.Hom-set _ _ = hlevel 2
158- Graphs o ℓ .Precategory.id .vertex v = v
159- Graphs o ℓ .Precategory.id .edge e = e
167+ Graphs o ℓ .Precategory.id = Graph-hom-id
160168Graphs o ℓ .Precategory._∘_ f g .vertex v = f .vertex (g .vertex v)
161169Graphs o ℓ .Precategory._∘_ f g .edge e = f .edge (g .edge e)
162170Graphs o ℓ .Precategory.idr _ = Graph-hom-path (λ _ → refl) (λ _ → refl)
163171Graphs o ℓ .Precategory.idl _ = Graph-hom-path (λ _ → refl) (λ _ → refl)
164172Graphs o ℓ .Precategory.assoc _ _ _ = Graph-hom-path (λ _ → refl) (λ _ → refl)
173+ ```
174+ <!--
175+ ```agda
176+ open Functor
177+ open _=>_
178+ module _ {o ℓ : Level} where
179+ module Graphs = Cat.Reasoning (Graphs o ℓ)
180+
181+ graph-iso-is-ff : {x y : Graph o ℓ} (h : Graphs.Hom x y) → Graphs.is-invertible h → ∀ {x y} → is-equiv (h .edge {x} {y})
182+ graph-iso-is-ff {x} {y} h inv {s} {t} = is-iso→is-equiv (iso from ir il) where
183+ module h = Graphs.is-invertible inv
184+
185+ from : ∀ {s t} → y .Edge (h # s) (h # t) → x .Edge s t
186+ from e = subst₂ (x .Edge) (ap vertex h.invr # _) (ap vertex h.invr # _) (h.inv .edge e)
187+
188+ ir : is-right-inverse from (h .edge)
189+ ir e =
190+ let
191+ lemma = J₂
192+ (λ s'' t'' p q → ∀ e
193+ → h .edge (subst₂ (x .Edge) p q e)
194+ ≡ subst₂ (y .Edge) (ap# h p) (ap# h q) (h .edge e))
195+ (λ e → ap (h .edge) (transport-refl _) ∙ sym (transport-refl _))
196+ in lemma _ _ (h.inv .edge e)
197+ ·· ap₂ (λ p q → subst₂ (y .Edge) {b' = h .vertex t} p q (h .edge (h.inv .edge e))) prop! prop!
198+ ·· from-pathp (λ i → h.invl i .edge e)
199+
200+ il : is-left-inverse from (h .edge)
201+ il e = from-pathp λ i → h.invr i .edge e
202+
203+ Graph-path
204+ : ∀ {x y : Graph o ℓ}
205+ → (p : x .Vertex ≡ y .Vertex)
206+ → (PathP (λ i → p i → p i → Type ℓ) (x .Edge) (y .Edge))
207+ → x ≡ y
208+ Graph-path {x = x} {y} p q i .Vertex = p i
209+ Graph-path {x = x} {y} p q i .Edge = q i
210+ Graph-path {x = x} {y} p q i .Vertex-is-set = is-prop→pathp
211+ (λ i → is-hlevel-is-prop {A = p i} 2) (x .Vertex-is-set) (y .Vertex-is-set) i
212+ Graph-path {x = x} {y} p q i .Edge-is-set {s} {t} =
213+ is-prop→pathp
214+ (λ i → Π-is-hlevel 1 λ x → Π-is-hlevel 1 λ y → is-hlevel-is-prop {A = q i x y} 2)
215+ (λ a b → x .Edge-is-set {a} {b}) (λ a b → y .Edge-is-set {a} {b}) i s t
216+
217+ graph-path : ∀ {x y : Graph o ℓ} (h : x Graphs.≅ y) → x ≡ y
218+ graph-path {x = x} {y = y} h = Graph-path (ua v) (λ i → E i ) module graph-path where
219+ module h = Graphs._≅_ h
220+ v : ⌞ x ⌟ ≃ ⌞ y ⌟
221+ v = record
222+ { fst = h.to .vertex
223+ ; snd = is-iso→is-equiv (iso (h.from .vertex) (happly (ap vertex h.invl)) (happly (ap vertex h.invr)))
224+ }
225+
226+ E : (i : I) → ua v i → ua v i → Type ℓ
227+ E i s t = Glue (y .Edge (unglue s) (unglue t)) (λ where
228+ (i = i0) → x .Edge s t , _ , graph-iso-is-ff h.to (Graphs.iso→invertible h)
229+ (i = i1) → y .Edge s t , _ , id-equiv)
230+ ```
231+ -->
232+
233+ In particular, $\Graphs$ is a [[ univalent category]] .
234+
235+ ``` agda
236+ Graphs-is-category : is-category (Graphs o ℓ)
237+ Graphs-is-category .to-path = graph-path
238+ Graphs-is-category .to-path-over {a} {b} p = Graphs.≅-pathp _ _ $ Graph-hom-pathp pv pe where
239+ open graph-path p
240+
241+ pv : (h : I → a .Vertex) → PathP (λ i → ua v i) (h i0) (h.to .vertex (h i1))
242+ pv h i = ua-glue v i (λ { (i = i0) → h i }) (inS (h.to .vertex (h i)))
165243
166- module Graphs {o} {ℓ} = Cat.Reasoning (Graphs o ℓ)
244+ pe : {x y : I → a .Vertex} (e : ∀ i → a .Edge (x i) (y i))
245+ → PathP (λ i → graph-path p i .Edge (pv x i) (pv y i)) (e i0) (h.to .edge (e i1))
246+ pe {x} {y} e i = attach (∂ i) (λ { (i = i0) → _ ; (i = i1) → _ }) (inS (h.to .edge (e i)))
167247```
168248
249+ ## Graphs as presheaves
250+
251+ A graph $(V, E)$ may equivalently be seen as a diagram
252+
253+ ~~~ {.quiver}
254+ \begin{tikzcd}
255+ V & E & V
256+ \arrow["{\mathrm{src}}"', from=1-2, to=1-1]
257+ \arrow["{\mathrm{dst}}", from=1-2, to=1-3]
258+ \end{tikzcd}
259+ ~~~
260+
261+ of sets.
262+
263+ That is, a graph $G$^[ whose edges and vertices live in the same
264+ universe] is the same as functor from the [[ walking parallel arrows]]
265+ category to $\Sets$. Furthermore, presheaves and functors to $\Sets$ are
266+ equivalent as this category is self-dual.
267+
169268<!--
170269```agda
171- open Functor
270+ graph→presheaf : Functor (Graphs o ℓ) (PSh (o ⊔ ℓ) ·⇇·)
271+ graph→presheaf .F₀ G =
272+ Fork {a = el! $ Σ[ s ∈ G .Vertex ] Σ[ t ∈ G .Vertex ] G .Edge s t }
273+ {el! $ Lift ℓ ⌞ G ⌟}
274+ (lift ⊙ fst)
275+ (lift ⊙ fst ⊙ snd)
276+ graph→presheaf .F₁ f =
277+ Fork-nt {u = λ (s , t , e) → f .vertex s , f .vertex t , f .edge e }
278+ {v = λ { (lift v) → lift (f # v) } } refl refl
279+ graph→presheaf .F-id = Nat-path λ { true → refl ; false → refl }
280+ graph→presheaf .F-∘ G H = Nat-path λ { true → refl ; false → refl }
281+
282+ g→p-is-ff : is-fully-faithful graph→presheaf
283+ g→p-is-ff {x = x} {y = y} = is-iso→is-equiv (iso from ir il) where
284+ from : graph→presheaf # x => graph→presheaf # y → Graph-hom x y
285+ from h .vertex v = h .η true (lift v) .lower
286+ from h .edge e =
287+ let
288+ (s' , t' , e') = h .η false (_ , _ , e)
289+ ps = ap lower (sym (h .is-natural false true false $ₚ (_ , _ , e)))
290+ pt = ap lower (sym (h .is-natural false true true $ₚ (_ , _ , e)))
291+ in subst₂ (y .Edge) ps pt e'
292+
293+ ir : is-right-inverse from (graph→presheaf .F₁)
294+ ir h = ext λ where
295+ true x → refl
296+ false (s , t , e) →
297+ let
298+ ps = ap lower (h .is-natural false true false $ₚ (s , t , e))
299+ pt = ap lower (h .is-natural false true true $ₚ (s , t , e))
300+ s' , t' , e' = h .η false (_ , _ , e)
301+ in Σ-pathp ps (Σ-pathp pt λ i → coe1→i (λ j → y .Edge (ps j) (pt j)) i e')
302+
303+ il : is-left-inverse from (graph→presheaf .F₁)
304+ il h = Graph-hom-path (λ _ → refl) (λ e → transport-refl _)
305+
306+ private module _ {ℓ : Level} where
307+
308+ presheaf→graph : ⌞ PSh ℓ ·⇇· ⌟ → Graph ℓ ℓ
309+ presheaf→graph F = g
310+ where module F = Functor F
311+ g : Graph ℓ ℓ
312+ g .Vertex = ⌞ F # true ⌟
313+ g .Edge s d = Σ[ e ∈ ∣ F.₀ false ∣ ] F.₁ false e ≡ s × F.₁ true e ≡ d
314+ g .Vertex-is-set = hlevel 2
315+ g .Edge-is-set = hlevel 2
316+
317+ open is-precat-iso
318+ open is-iso
319+ g→p-is-iso : is-precat-iso (graph→presheaf {ℓ} {ℓ})
320+ g→p-is-iso .has-is-ff = g→p-is-ff
321+ g→p-is-iso .has-is-iso = is-iso→is-equiv F₀-iso where
322+ F₀-iso : is-iso (graph→presheaf .F₀)
323+ F₀-iso .inv = presheaf→graph
324+ F₀-iso .rinv F = Functor-path
325+ (λ { false → n-ua (Iso→Equiv (
326+ (λ (_ , _ , x , _ , _) → x) , iso
327+ (λ s → _ , _ , s , refl , refl)
328+ (λ _ → refl)
329+ (λ (_ , _ , s , p , q) i → p i , q i , s
330+ , (λ j → p (i ∧ j)) , (λ j → q (i ∧ j)))))
331+ ; true → n-ua (lower
332+ , (is-iso→is-equiv (iso lift (λ _ → refl) (λ _ → refl))))
333+ })
334+ λ { {false} {false} e → ua→ λ _ → path→ua-pathp _ (sym (F .F-id {false} # _))
335+ ; {false} {true} false → ua→ λ (_ , _ , s , p , q) → path→ua-pathp _ (sym p)
336+ ; {false} {true} true → ua→ λ (_ , _ , s , p , q) → path→ua-pathp _ (sym q)
337+ ; {true} {true} e → ua→ λ _ → path→ua-pathp _ (sym (F .F-id {true} # _)) }
338+ F₀-iso .linv G = let
339+ eqv : Lift ℓ ⌞ G ⌟ ≃ ⌞ G ⌟
340+ eqv = Lift-≃
341+
342+ ΣE = Σ[ s ∈ G ] Σ[ t ∈ G ] G .Edge s t
343+
344+ E' : Lift ℓ ⌞ G ⌟ → Lift ℓ ⌞ G ⌟ → Type _
345+ E' x y = Σ[ (s , t , e) ∈ ΣE ] (lift s ≡ x × lift t ≡ y)
346+
347+ from : (u v : ⌞ G ⌟) → E' (lift u) (lift v) → G .Edge u v
348+ from u v ((u' , v' , e) , p , q) = subst₂ (G .Edge) (ap lower p) (ap lower q) e
349+
350+ frome : (u v : ⌞ G ⌟) → is-iso (from u v)
351+ frome u v = iso (λ e → ((_ , _ , e) , refl , refl)) (λ x → transport-refl _)
352+ (λ ((u' , v' , e) , p , q) i →
353+ ( p (~ i) .lower , q (~ i) .lower
354+ , coe0→i (λ i → G .Edge (p i .lower) (q i .lower)) (~ i) e )
355+ , (λ j → p (~ i ∨ j))
356+ , (λ j → q (~ i ∨ j)))
357+ in Graph-path (ua eqv) λ i x y → Glue (G .Edge (ua-unglue eqv i x)
358+ (ua-unglue eqv i y)) λ where
359+ (i = i0) → E' x y , from (x .lower) (y .lower) , is-iso→is-equiv (frome _ _)
360+ (i = i1) → G .Edge x y , _ , id-equiv
172361```
173362-->
174363
175- :::{.definition #underlying-graph alias="underlying-graph-functor"}
364+ Thus, $\Graphs$ are presheaves and are thereby a [[ topos]] .
365+
366+ ``` agda
367+ graphs-are-presheaves : Equivalence (Graphs ℓ ℓ) (PSh ℓ ·⇇·)
368+ graphs-are-presheaves = eqv where
369+ open Equivalence
370+ eqv : Equivalence (Graphs ℓ ℓ) (PSh ℓ ·⇇·)
371+ eqv .To = graph→presheaf
372+ eqv .To-equiv = is-precat-iso→is-equivalence g→p-is-iso
373+ ```
374+
375+ ## The underlying graph of a strict category {defines="underlying-graph underlying-graph-functor"}
376+
176377Note that every [[ strict category]] has an underlying graph, where
177378the vertices are given by objects, and edges by morphisms. Moreover,
178379functors between strict categories give rise to graph homomorphisms
179380between underlying graphs. This gives rise to a functor from the
180381[[ category of strict categories]] to the category of graphs.
181- :::
182382
183383``` agda
184384Strict-cats↪Graphs : Functor (Strict-cats o ℓ) (Graphs o ℓ)
0 commit comments