/
walks-directed-graphs.lagda.md
789 lines (681 loc) · 28.8 KB
/
walks-directed-graphs.lagda.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
# Walks in directed graphs
```agda
module graph-theory.walks-directed-graphs where
```
<details><summary>Imports</summary>
```agda
open import elementary-number-theory.natural-numbers
open import foundation.action-on-identifications-functions
open import foundation.cartesian-product-types
open import foundation.commuting-squares-of-maps
open import foundation.contractible-types
open import foundation.coproduct-types
open import foundation.dependent-pair-types
open import foundation.equivalences
open import foundation.function-types
open import foundation.functoriality-cartesian-product-types
open import foundation.functoriality-dependent-pair-types
open import foundation.homotopies
open import foundation.identity-types
open import foundation.injective-maps
open import foundation.negated-equality
open import foundation.raising-universe-levels
open import foundation.transport-along-identifications
open import foundation.universe-levels
open import graph-theory.directed-graphs
open import graph-theory.equivalences-directed-graphs
open import graph-theory.morphisms-directed-graphs
```
</details>
## Idea
A **walk** in a [directed graph](graph-theory.directed-graphs.md) from a vertex
`x` to a vertex `y` is a [list](lists.lists.md) of edges that connect `x` to
`y`. Since every journey begins with a single step, we define the `cons`
operation on walks in directed graphs with an edge from the source in the first
argument, and a walk to the target in the second argument.
## Definitions
### The type of walks from `x` to `y` in `G`
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
data walk-Directed-Graph :
(x y : vertex-Directed-Graph G) → UU (l1 ⊔ l2)
where
refl-walk-Directed-Graph :
{x : vertex-Directed-Graph G} → walk-Directed-Graph x x
cons-walk-Directed-Graph :
{x y z : vertex-Directed-Graph G} →
edge-Directed-Graph G x y →
walk-Directed-Graph y z → walk-Directed-Graph x z
unit-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} (e : edge-Directed-Graph G x y) →
walk-Directed-Graph x y
unit-walk-Directed-Graph e =
cons-walk-Directed-Graph e refl-walk-Directed-Graph
snoc-walk-Directed-Graph :
{x y z : vertex-Directed-Graph G} →
walk-Directed-Graph x y →
edge-Directed-Graph G y z → walk-Directed-Graph x z
snoc-walk-Directed-Graph refl-walk-Directed-Graph e =
unit-walk-Directed-Graph e
snoc-walk-Directed-Graph (cons-walk-Directed-Graph f w) e =
cons-walk-Directed-Graph f (snoc-walk-Directed-Graph w e)
```
### The type of walks in a directed graph, defined dually
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
data walk-Directed-Graph' :
(x y : vertex-Directed-Graph G) → UU (l1 ⊔ l2)
where
refl-walk-Directed-Graph' :
{x : vertex-Directed-Graph G} → walk-Directed-Graph' x x
snoc-walk-Directed-Graph' :
{x y z : vertex-Directed-Graph G} →
walk-Directed-Graph' x y → edge-Directed-Graph G y z →
walk-Directed-Graph' x z
unit-walk-Directed-Graph' :
{x y : vertex-Directed-Graph G} →
edge-Directed-Graph G x y → walk-Directed-Graph' x y
unit-walk-Directed-Graph' e =
snoc-walk-Directed-Graph' refl-walk-Directed-Graph' e
cons-walk-Directed-Graph' :
{x y z : vertex-Directed-Graph G} →
edge-Directed-Graph G x y → walk-Directed-Graph' y z →
walk-Directed-Graph' x z
cons-walk-Directed-Graph' e refl-walk-Directed-Graph' =
unit-walk-Directed-Graph' e
cons-walk-Directed-Graph' e (snoc-walk-Directed-Graph' w f) =
snoc-walk-Directed-Graph' (cons-walk-Directed-Graph' e w) f
```
### The length of a walk in `G`
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
length-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} →
walk-Directed-Graph G x y → ℕ
length-walk-Directed-Graph refl-walk-Directed-Graph = 0
length-walk-Directed-Graph (cons-walk-Directed-Graph x w) =
succ-ℕ (length-walk-Directed-Graph w)
```
### The type of walks of length `n` from `x` to `y` in `G`
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
walk-of-length-Directed-Graph :
ℕ → (x y : vertex-Directed-Graph G) → UU (l1 ⊔ l2)
walk-of-length-Directed-Graph zero-ℕ x y = raise l2 (y = x)
walk-of-length-Directed-Graph (succ-ℕ n) x y =
Σ ( vertex-Directed-Graph G)
( λ z → edge-Directed-Graph G x z × walk-of-length-Directed-Graph n z y)
map-compute-total-walk-of-length-Directed-Graph :
(x y : vertex-Directed-Graph G) →
Σ ℕ (λ n → walk-of-length-Directed-Graph n x y) → walk-Directed-Graph G x y
map-compute-total-walk-of-length-Directed-Graph
x .x (zero-ℕ , map-raise refl) =
refl-walk-Directed-Graph
map-compute-total-walk-of-length-Directed-Graph x y (succ-ℕ n , z , e , w) =
cons-walk-Directed-Graph e
( map-compute-total-walk-of-length-Directed-Graph z y (n , w))
map-inv-compute-total-walk-of-length-Directed-Graph :
(x y : vertex-Directed-Graph G) →
walk-Directed-Graph G x y → Σ ℕ (λ n → walk-of-length-Directed-Graph n x y)
map-inv-compute-total-walk-of-length-Directed-Graph
x .x refl-walk-Directed-Graph =
(0 , map-raise refl)
map-inv-compute-total-walk-of-length-Directed-Graph x y
( cons-walk-Directed-Graph {y = z} e w) =
map-Σ
( λ n → walk-of-length-Directed-Graph n x y)
( succ-ℕ)
( λ k u → (z , e , u))
( map-inv-compute-total-walk-of-length-Directed-Graph z y w)
is-section-map-inv-compute-total-walk-of-length-Directed-Graph :
(x y : vertex-Directed-Graph G) →
( map-compute-total-walk-of-length-Directed-Graph x y ∘
map-inv-compute-total-walk-of-length-Directed-Graph x y) ~ id
is-section-map-inv-compute-total-walk-of-length-Directed-Graph
x .x refl-walk-Directed-Graph = refl
is-section-map-inv-compute-total-walk-of-length-Directed-Graph
x y (cons-walk-Directed-Graph {y = z} e w) =
ap
( cons-walk-Directed-Graph e)
( is-section-map-inv-compute-total-walk-of-length-Directed-Graph z y w)
is-retraction-map-inv-compute-total-walk-of-length-Directed-Graph :
(x y : vertex-Directed-Graph G) →
( map-inv-compute-total-walk-of-length-Directed-Graph x y ∘
map-compute-total-walk-of-length-Directed-Graph x y) ~ id
is-retraction-map-inv-compute-total-walk-of-length-Directed-Graph
x .x (zero-ℕ , map-raise refl) =
refl
is-retraction-map-inv-compute-total-walk-of-length-Directed-Graph
x y (succ-ℕ n , (z , e , w)) =
ap
( map-Σ
( λ n → walk-of-length-Directed-Graph n x y)
( succ-ℕ)
( λ k u → (z , e , u)))
( is-retraction-map-inv-compute-total-walk-of-length-Directed-Graph z y
( n , w))
is-equiv-map-compute-total-walk-of-length-Directed-Graph :
(x y : vertex-Directed-Graph G) →
is-equiv (map-compute-total-walk-of-length-Directed-Graph x y)
is-equiv-map-compute-total-walk-of-length-Directed-Graph x y =
is-equiv-is-invertible
( map-inv-compute-total-walk-of-length-Directed-Graph x y)
( is-section-map-inv-compute-total-walk-of-length-Directed-Graph x y)
( is-retraction-map-inv-compute-total-walk-of-length-Directed-Graph x y)
compute-total-walk-of-length-Directed-Graph :
(x y : vertex-Directed-Graph G) →
Σ ℕ (λ n → walk-of-length-Directed-Graph n x y) ≃ walk-Directed-Graph G x y
pr1 (compute-total-walk-of-length-Directed-Graph x y) =
map-compute-total-walk-of-length-Directed-Graph x y
pr2 (compute-total-walk-of-length-Directed-Graph x y) =
is-equiv-map-compute-total-walk-of-length-Directed-Graph x y
```
### Concatenation of walks
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
concat-walk-Directed-Graph :
{x y z : vertex-Directed-Graph G} →
walk-Directed-Graph G x y → walk-Directed-Graph G y z →
walk-Directed-Graph G x z
concat-walk-Directed-Graph refl-walk-Directed-Graph v = v
concat-walk-Directed-Graph (cons-walk-Directed-Graph e u) v =
cons-walk-Directed-Graph e (concat-walk-Directed-Graph u v)
```
## Properties
### The two dual definitions of walks are equivalent
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
map-compute-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} →
walk-Directed-Graph G x y → walk-Directed-Graph' G x y
map-compute-walk-Directed-Graph refl-walk-Directed-Graph =
refl-walk-Directed-Graph'
map-compute-walk-Directed-Graph (cons-walk-Directed-Graph e w) =
cons-walk-Directed-Graph' G e (map-compute-walk-Directed-Graph w)
compute-snoc-map-compute-walk-Directed-Graph :
{x y z : vertex-Directed-Graph G}
(w : walk-Directed-Graph G x y) (e : edge-Directed-Graph G y z) →
map-compute-walk-Directed-Graph (snoc-walk-Directed-Graph G w e) =
snoc-walk-Directed-Graph' (map-compute-walk-Directed-Graph w) e
compute-snoc-map-compute-walk-Directed-Graph refl-walk-Directed-Graph e =
refl
compute-snoc-map-compute-walk-Directed-Graph
( cons-walk-Directed-Graph f w)
( e) =
ap
( cons-walk-Directed-Graph' G f)
( compute-snoc-map-compute-walk-Directed-Graph w e)
map-inv-compute-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} →
walk-Directed-Graph' G x y → walk-Directed-Graph G x y
map-inv-compute-walk-Directed-Graph refl-walk-Directed-Graph' =
refl-walk-Directed-Graph
map-inv-compute-walk-Directed-Graph (snoc-walk-Directed-Graph' w e) =
snoc-walk-Directed-Graph G (map-inv-compute-walk-Directed-Graph w) e
compute-cons-map-inv-compute-walk-Directed-Graph :
{x y z : vertex-Directed-Graph G}
(e : edge-Directed-Graph G x y) (w : walk-Directed-Graph' G y z) →
map-inv-compute-walk-Directed-Graph (cons-walk-Directed-Graph' G e w) =
cons-walk-Directed-Graph e (map-inv-compute-walk-Directed-Graph w)
compute-cons-map-inv-compute-walk-Directed-Graph e refl-walk-Directed-Graph' =
refl
compute-cons-map-inv-compute-walk-Directed-Graph e
( snoc-walk-Directed-Graph' w f) =
ap
( λ v → snoc-walk-Directed-Graph G v f)
( compute-cons-map-inv-compute-walk-Directed-Graph e w)
is-section-map-inv-compute-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} →
( map-compute-walk-Directed-Graph {x} {y} ∘
map-inv-compute-walk-Directed-Graph {x} {y}) ~ id
is-section-map-inv-compute-walk-Directed-Graph refl-walk-Directed-Graph' =
refl
is-section-map-inv-compute-walk-Directed-Graph
( snoc-walk-Directed-Graph' w e) =
( compute-snoc-map-compute-walk-Directed-Graph
( map-inv-compute-walk-Directed-Graph w)
( e)) ∙
( ap
( λ v → snoc-walk-Directed-Graph' v e)
( is-section-map-inv-compute-walk-Directed-Graph w))
is-retraction-map-inv-compute-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} →
( map-inv-compute-walk-Directed-Graph {x} {y} ∘
map-compute-walk-Directed-Graph {x} {y}) ~ id
is-retraction-map-inv-compute-walk-Directed-Graph refl-walk-Directed-Graph =
refl
is-retraction-map-inv-compute-walk-Directed-Graph
( cons-walk-Directed-Graph e w) =
( compute-cons-map-inv-compute-walk-Directed-Graph e
( map-compute-walk-Directed-Graph w)) ∙
( ap
( cons-walk-Directed-Graph e)
( is-retraction-map-inv-compute-walk-Directed-Graph w))
is-equiv-map-compute-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} →
is-equiv (map-compute-walk-Directed-Graph {x} {y})
is-equiv-map-compute-walk-Directed-Graph =
is-equiv-is-invertible
map-inv-compute-walk-Directed-Graph
is-section-map-inv-compute-walk-Directed-Graph
is-retraction-map-inv-compute-walk-Directed-Graph
compute-walk-Directed-Graph :
(x y : vertex-Directed-Graph G) →
walk-Directed-Graph G x y ≃ walk-Directed-Graph' G x y
pr1 (compute-walk-Directed-Graph x y) = map-compute-walk-Directed-Graph
pr2 (compute-walk-Directed-Graph x y) =
is-equiv-map-compute-walk-Directed-Graph
```
### The type of walks from `x` to `y` is a coproduct
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
coproduct-walk-Directed-Graph : (x y : vertex-Directed-Graph G) → UU (l1 ⊔ l2)
coproduct-walk-Directed-Graph x y =
(y = x) +
Σ ( vertex-Directed-Graph G)
( λ z → edge-Directed-Graph G x z × walk-Directed-Graph G z y)
map-compute-coproduct-walk-Directed-Graph :
(x y : vertex-Directed-Graph G) →
walk-Directed-Graph G x y → coproduct-walk-Directed-Graph x y
map-compute-coproduct-walk-Directed-Graph x .x refl-walk-Directed-Graph =
inl refl
map-compute-coproduct-walk-Directed-Graph x y
( cons-walk-Directed-Graph {a} {b} {c} e w) =
inr (b , e , w)
map-inv-compute-coproduct-walk-Directed-Graph :
(x y : vertex-Directed-Graph G) →
coproduct-walk-Directed-Graph x y → walk-Directed-Graph G x y
map-inv-compute-coproduct-walk-Directed-Graph x .x (inl refl) =
refl-walk-Directed-Graph
map-inv-compute-coproduct-walk-Directed-Graph x y (inr (z , e , w)) =
cons-walk-Directed-Graph e w
is-section-map-inv-compute-coproduct-walk-Directed-Graph :
(x y : vertex-Directed-Graph G) →
( map-compute-coproduct-walk-Directed-Graph x y ∘
map-inv-compute-coproduct-walk-Directed-Graph x y) ~ id
is-section-map-inv-compute-coproduct-walk-Directed-Graph x .x (inl refl) =
refl
is-section-map-inv-compute-coproduct-walk-Directed-Graph x y
( inr (z , e , w)) =
refl
is-retraction-map-inv-compute-coproduct-walk-Directed-Graph :
(x y : vertex-Directed-Graph G) →
( map-inv-compute-coproduct-walk-Directed-Graph x y ∘
map-compute-coproduct-walk-Directed-Graph x y) ~ id
is-retraction-map-inv-compute-coproduct-walk-Directed-Graph x .x
refl-walk-Directed-Graph =
refl
is-retraction-map-inv-compute-coproduct-walk-Directed-Graph x y
( cons-walk-Directed-Graph e w) =
refl
is-equiv-map-compute-coproduct-walk-Directed-Graph :
(x y : vertex-Directed-Graph G) →
is-equiv (map-compute-coproduct-walk-Directed-Graph x y)
is-equiv-map-compute-coproduct-walk-Directed-Graph x y =
is-equiv-is-invertible
( map-inv-compute-coproduct-walk-Directed-Graph x y)
( is-section-map-inv-compute-coproduct-walk-Directed-Graph x y)
( is-retraction-map-inv-compute-coproduct-walk-Directed-Graph x y)
compute-coproduct-walk-Directed-Graph :
(x y : vertex-Directed-Graph G) →
walk-Directed-Graph G x y ≃ coproduct-walk-Directed-Graph x y
pr1 (compute-coproduct-walk-Directed-Graph x y) =
map-compute-coproduct-walk-Directed-Graph x y
pr2 (compute-coproduct-walk-Directed-Graph x y) =
is-equiv-map-compute-coproduct-walk-Directed-Graph x y
```
### Walks of length `0` are identifications
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2) (x : vertex-Directed-Graph G)
where
is-contr-total-walk-of-length-zero-Directed-Graph :
is-contr
( Σ ( vertex-Directed-Graph G)
( λ y → walk-of-length-Directed-Graph G 0 x y))
is-contr-total-walk-of-length-zero-Directed-Graph =
is-contr-equiv'
( Σ (vertex-Directed-Graph G) (λ y → y = x))
( equiv-tot (λ y → compute-raise l2 (y = x)))
( is-contr-total-path' x)
```
### `cons-walk e w ≠ refl-walk`
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2) (x : vertex-Directed-Graph G)
where
neq-cons-refl-walk-Directed-Graph :
(y : vertex-Directed-Graph G) (e : edge-Directed-Graph G x y) →
(w : walk-Directed-Graph G y x) →
cons-walk-Directed-Graph e w ≠ refl-walk-Directed-Graph
neq-cons-refl-walk-Directed-Graph y e w ()
```
### If `cons-walk e w = cons-walk e' w'`, then `(y , e) = (y' , e')`
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2) (x : vertex-Directed-Graph G)
where
eq-direct-successor-eq-cons-walk-Directed-Graph :
{y y' z : vertex-Directed-Graph G}
(e : edge-Directed-Graph G x y) (e' : edge-Directed-Graph G x y')
(w : walk-Directed-Graph G y z) (w' : walk-Directed-Graph G y' z) →
cons-walk-Directed-Graph e w = cons-walk-Directed-Graph e' w' →
(y , e) = (y' , e')
eq-direct-successor-eq-cons-walk-Directed-Graph {y} {.y} {z} e .e w .w refl =
refl
```
### Vertices on a walk
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
is-vertex-on-walk-Directed-Graph :
{x y : vertex-Directed-Graph G}
(w : walk-Directed-Graph G x y) (v : vertex-Directed-Graph G) → UU l1
is-vertex-on-walk-Directed-Graph {x} refl-walk-Directed-Graph v = v = x
is-vertex-on-walk-Directed-Graph {x} (cons-walk-Directed-Graph e w) v =
( v = x) +
( is-vertex-on-walk-Directed-Graph w v)
vertex-on-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} (w : walk-Directed-Graph G x y) → UU l1
vertex-on-walk-Directed-Graph w =
Σ (vertex-Directed-Graph G) (is-vertex-on-walk-Directed-Graph w)
vertex-vertex-on-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} (w : walk-Directed-Graph G x y) →
vertex-on-walk-Directed-Graph w → vertex-Directed-Graph G
vertex-vertex-on-walk-Directed-Graph w = pr1
```
### Edges on a walk
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
data is-edge-on-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} (w : walk-Directed-Graph G x y)
{u v : vertex-Directed-Graph G} → edge-Directed-Graph G u v → UU (l1 ⊔ l2)
where
edge-is-edge-on-walk-Directed-Graph :
{x y z : vertex-Directed-Graph G} (e : edge-Directed-Graph G x y)
(w : walk-Directed-Graph G y z) →
is-edge-on-walk-Directed-Graph (cons-walk-Directed-Graph e w) e
cons-is-edge-on-walk-Directed-Graph :
{x y z : vertex-Directed-Graph G} (e : edge-Directed-Graph G x y)
(w : walk-Directed-Graph G y z) →
{u v : vertex-Directed-Graph G} (f : edge-Directed-Graph G u v) →
is-edge-on-walk-Directed-Graph w f →
is-edge-on-walk-Directed-Graph (cons-walk-Directed-Graph e w) f
edge-on-walk-Directed-Graph :
{x y : vertex-Directed-Graph G}
(w : walk-Directed-Graph G x y) → UU (l1 ⊔ l2)
edge-on-walk-Directed-Graph w =
Σ ( total-edge-Directed-Graph G)
( λ e →
is-edge-on-walk-Directed-Graph w (edge-total-edge-Directed-Graph G e))
module _
{x y : vertex-Directed-Graph G}
(w : walk-Directed-Graph G x y)
(e : edge-on-walk-Directed-Graph w)
where
total-edge-edge-on-walk-Directed-Graph : total-edge-Directed-Graph G
total-edge-edge-on-walk-Directed-Graph = pr1 e
source-edge-on-walk-Directed-Graph : vertex-Directed-Graph G
source-edge-on-walk-Directed-Graph =
source-total-edge-Directed-Graph G total-edge-edge-on-walk-Directed-Graph
target-edge-on-walk-Directed-Graph : vertex-Directed-Graph G
target-edge-on-walk-Directed-Graph =
target-total-edge-Directed-Graph G total-edge-edge-on-walk-Directed-Graph
edge-edge-on-walk-Directed-Graph :
edge-Directed-Graph G
source-edge-on-walk-Directed-Graph
target-edge-on-walk-Directed-Graph
edge-edge-on-walk-Directed-Graph =
edge-total-edge-Directed-Graph G total-edge-edge-on-walk-Directed-Graph
is-edge-on-walk-edge-on-walk-Directed-Graph :
is-edge-on-walk-Directed-Graph w edge-edge-on-walk-Directed-Graph
is-edge-on-walk-edge-on-walk-Directed-Graph = pr2 e
```
### The action on walks of graph homomorphisms
```agda
walk-hom-Directed-Graph :
{l1 l2 l3 l4 : Level} (G : Directed-Graph l1 l2) (H : Directed-Graph l3 l4)
(f : hom-Directed-Graph G H) {x y : vertex-Directed-Graph G} →
walk-Directed-Graph G x y →
walk-Directed-Graph H
( vertex-hom-Directed-Graph G H f x)
( vertex-hom-Directed-Graph G H f y)
walk-hom-Directed-Graph G H f refl-walk-Directed-Graph =
refl-walk-Directed-Graph
walk-hom-Directed-Graph G H f (cons-walk-Directed-Graph e w) =
cons-walk-Directed-Graph
( edge-hom-Directed-Graph G H f e)
( walk-hom-Directed-Graph G H f w)
```
### The action on walks of length `n` of graph homomorphisms
```agda
module _
{l1 l2 l3 l4 : Level} (G : Directed-Graph l1 l2) (H : Directed-Graph l3 l4)
(f : hom-Directed-Graph G H)
where
walk-of-length-hom-Directed-Graph :
(n : ℕ) {x y : vertex-Directed-Graph G} →
walk-of-length-Directed-Graph G n x y →
walk-of-length-Directed-Graph H n
( vertex-hom-Directed-Graph G H f x)
( vertex-hom-Directed-Graph G H f y)
walk-of-length-hom-Directed-Graph zero-ℕ {x} {y} (map-raise p) =
map-raise (ap (vertex-hom-Directed-Graph G H f) p)
walk-of-length-hom-Directed-Graph (succ-ℕ n) =
map-Σ
( λ z →
( edge-Directed-Graph H (vertex-hom-Directed-Graph G H f _) z) ×
( walk-of-length-Directed-Graph H n z
( vertex-hom-Directed-Graph G H f _)))
( vertex-hom-Directed-Graph G H f)
( λ z →
map-prod
( edge-hom-Directed-Graph G H f)
( walk-of-length-hom-Directed-Graph n))
square-compute-total-walk-of-length-hom-Directed-Graph :
(x y : vertex-Directed-Graph G) →
coherence-square-maps
( tot (λ n → walk-of-length-hom-Directed-Graph n {x} {y}))
( map-compute-total-walk-of-length-Directed-Graph G x y)
( map-compute-total-walk-of-length-Directed-Graph H
( vertex-hom-Directed-Graph G H f x)
( vertex-hom-Directed-Graph G H f y))
( walk-hom-Directed-Graph G H f {x} {y})
square-compute-total-walk-of-length-hom-Directed-Graph
x .x (zero-ℕ , map-raise refl) = refl
square-compute-total-walk-of-length-hom-Directed-Graph
x y (succ-ℕ n , z , e , w) =
ap
( cons-walk-Directed-Graph (edge-hom-Directed-Graph G H f e))
( square-compute-total-walk-of-length-hom-Directed-Graph z y (n , w))
```
### The action on walks of length `n` of equivalences of graphs
```agda
equiv-walk-of-length-equiv-Directed-Graph :
{l1 l2 l3 l4 : Level} (G : Directed-Graph l1 l2) (H : Directed-Graph l3 l4)
(f : equiv-Directed-Graph G H) (n : ℕ) {x y : vertex-Directed-Graph G} →
walk-of-length-Directed-Graph G n x y ≃
walk-of-length-Directed-Graph H n
( vertex-equiv-Directed-Graph G H f x)
( vertex-equiv-Directed-Graph G H f y)
equiv-walk-of-length-equiv-Directed-Graph G H f zero-ℕ =
equiv-raise _ _
( equiv-ap (equiv-vertex-equiv-Directed-Graph G H f) _ _)
equiv-walk-of-length-equiv-Directed-Graph G H f (succ-ℕ n) =
equiv-Σ
( λ z →
( edge-Directed-Graph H (vertex-equiv-Directed-Graph G H f _) z) ×
( walk-of-length-Directed-Graph H n z
( vertex-equiv-Directed-Graph G H f _)))
( equiv-vertex-equiv-Directed-Graph G H f)
( λ z →
equiv-prod
( equiv-edge-equiv-Directed-Graph G H f _ _)
( equiv-walk-of-length-equiv-Directed-Graph G H f n))
```
### The action of equivalences on walks
```agda
module _
{l1 l2 l3 l4 : Level} (G : Directed-Graph l1 l2) (H : Directed-Graph l3 l4)
(e : equiv-Directed-Graph G H)
where
walk-equiv-Directed-Graph :
{x y : vertex-Directed-Graph G} →
walk-Directed-Graph G x y →
walk-Directed-Graph H
( vertex-equiv-Directed-Graph G H e x)
( vertex-equiv-Directed-Graph G H e y)
walk-equiv-Directed-Graph =
walk-hom-Directed-Graph G H (hom-equiv-Directed-Graph G H e)
square-compute-total-walk-of-length-equiv-Directed-Graph :
(x y : vertex-Directed-Graph G) →
coherence-square-maps
( tot
( λ n →
map-equiv
( equiv-walk-of-length-equiv-Directed-Graph G H e n {x} {y})))
( map-compute-total-walk-of-length-Directed-Graph G x y)
( map-compute-total-walk-of-length-Directed-Graph H
( vertex-equiv-Directed-Graph G H e x)
( vertex-equiv-Directed-Graph G H e y))
( walk-equiv-Directed-Graph {x} {y})
square-compute-total-walk-of-length-equiv-Directed-Graph
x .x (zero-ℕ , map-raise refl) = refl
square-compute-total-walk-of-length-equiv-Directed-Graph
x y (succ-ℕ n , z , f , w) =
ap
( cons-walk-Directed-Graph (edge-equiv-Directed-Graph G H e x z f))
( square-compute-total-walk-of-length-equiv-Directed-Graph z y (n , w))
is-equiv-walk-equiv-Directed-Graph :
{x y : vertex-Directed-Graph G} →
is-equiv (walk-equiv-Directed-Graph {x} {y})
is-equiv-walk-equiv-Directed-Graph {x} {y} =
is-equiv-right-is-equiv-left-square
( map-equiv
( equiv-tot
( λ n → equiv-walk-of-length-equiv-Directed-Graph G H e n {x} {y})))
( walk-equiv-Directed-Graph {x} {y})
( map-compute-total-walk-of-length-Directed-Graph G x y)
( map-compute-total-walk-of-length-Directed-Graph H
( vertex-equiv-Directed-Graph G H e x)
( vertex-equiv-Directed-Graph G H e y))
( inv-htpy
( square-compute-total-walk-of-length-equiv-Directed-Graph x y))
( is-equiv-map-compute-total-walk-of-length-Directed-Graph G x y)
( is-equiv-map-compute-total-walk-of-length-Directed-Graph H
( vertex-equiv-Directed-Graph G H e x)
( vertex-equiv-Directed-Graph G H e y))
( is-equiv-map-equiv
( equiv-tot
( λ n → equiv-walk-of-length-equiv-Directed-Graph G H e n)))
equiv-walk-equiv-Directed-Graph :
{x y : vertex-Directed-Graph G} →
walk-Directed-Graph G x y ≃
walk-Directed-Graph H
( vertex-equiv-Directed-Graph G H e x)
( vertex-equiv-Directed-Graph G H e y)
pr1 (equiv-walk-equiv-Directed-Graph {x} {y}) =
walk-equiv-Directed-Graph
pr2 (equiv-walk-equiv-Directed-Graph {x} {y}) =
is-equiv-walk-equiv-Directed-Graph
```
### If `concat-walk-Directed-Graph u v = refl-walk-Directed-Graph` then both `u` and `v` are `refl-walk-Directed-Graph`
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
eq-is-refl-concat-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} →
(u : walk-Directed-Graph G x y) (v : walk-Directed-Graph G y x) →
( concat-walk-Directed-Graph G u v = refl-walk-Directed-Graph) →
x = y
eq-is-refl-concat-walk-Directed-Graph
refl-walk-Directed-Graph .refl-walk-Directed-Graph refl =
refl
is-refl-left-is-refl-concat-walk-Directed-Graph :
{x y : vertex-Directed-Graph G}
(u : walk-Directed-Graph G x y) (v : walk-Directed-Graph G y x) →
(p : concat-walk-Directed-Graph G u v = refl-walk-Directed-Graph) →
tr
( walk-Directed-Graph G x)
( eq-is-refl-concat-walk-Directed-Graph u v p)
( refl-walk-Directed-Graph) = u
is-refl-left-is-refl-concat-walk-Directed-Graph
refl-walk-Directed-Graph .refl-walk-Directed-Graph refl =
refl
is-refl-right-is-refl-concat-walk-Directed-Graph :
{x y : vertex-Directed-Graph G}
(u : walk-Directed-Graph G x y) (v : walk-Directed-Graph G y x) →
(p : concat-walk-Directed-Graph G u v = refl-walk-Directed-Graph) →
tr
( walk-Directed-Graph G y)
( inv (eq-is-refl-concat-walk-Directed-Graph u v p))
( refl-walk-Directed-Graph) = v
is-refl-right-is-refl-concat-walk-Directed-Graph
refl-walk-Directed-Graph .refl-walk-Directed-Graph refl =
refl
```
### The function `unit-walk` is injective
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
is-injective-unit-walk-Directed-Graph :
{x y : vertex-Directed-Graph G} →
is-injective (unit-walk-Directed-Graph G {x} {y})
is-injective-unit-walk-Directed-Graph refl = refl
```
### The last edge on a walk
```agda
module _
{l1 l2 : Level} (G : Directed-Graph l1 l2)
where
last-stage-walk-Directed-Graph :
{x y z : vertex-Directed-Graph G} (e : edge-Directed-Graph G x y) →
walk-Directed-Graph G y z →
Σ (vertex-Directed-Graph G) (λ u → edge-Directed-Graph G u z)
last-stage-walk-Directed-Graph e refl-walk-Directed-Graph = (_ , e)
last-stage-walk-Directed-Graph e (cons-walk-Directed-Graph f w) =
last-stage-walk-Directed-Graph f w
vertex-last-stage-walk-Directed-Graph :
{x y z : vertex-Directed-Graph G} (e : edge-Directed-Graph G x y) →
walk-Directed-Graph G y z → vertex-Directed-Graph G
vertex-last-stage-walk-Directed-Graph e w =
pr1 (last-stage-walk-Directed-Graph e w)
edge-last-stage-walk-Directed-Graph :
{x y z : vertex-Directed-Graph G} (e : edge-Directed-Graph G x y) →
(w : walk-Directed-Graph G y z) →
edge-Directed-Graph G (vertex-last-stage-walk-Directed-Graph e w) z
edge-last-stage-walk-Directed-Graph e w =
pr2 (last-stage-walk-Directed-Graph e w)
walk-last-stage-walk-Directed-Graph :
{x y z : vertex-Directed-Graph G} (e : edge-Directed-Graph G x y) →
(w : walk-Directed-Graph G y z) →
walk-Directed-Graph G x (vertex-last-stage-walk-Directed-Graph e w)
walk-last-stage-walk-Directed-Graph e refl-walk-Directed-Graph =
refl-walk-Directed-Graph
walk-last-stage-walk-Directed-Graph e (cons-walk-Directed-Graph f w) =
cons-walk-Directed-Graph e (walk-last-stage-walk-Directed-Graph f w)
```
## External links
- [Path](https://www.wikidata.org/entity/Q917421) on Wikidata
- [Path (graph theory)](<https://en.wikipedia.org/wiki/Path_(graph_theory)>) at
Wikipedia
- [Walk](https://mathworld.wolfram.com/Walk.html) at Wolfram Mathworld