-
Notifications
You must be signed in to change notification settings - Fork 299
/
hamiltonian2.lean
1377 lines (1217 loc) · 50 KB
/
hamiltonian2.lean
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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import combinatorics.simple_graph.matching
import combinatorics.simple_graph.connectivity
import combinatorics.simple_graph.coloring
import combinatorics.simple_graph.metric
noncomputable theory
namespace simple_graph
universes u
variables {V : Type u} {G : simple_graph V}
theorem disjoint_iff (G G' : simple_graph V) :
disjoint G G' ↔ ∀ v w, G.adj v w → G'.adj v w → false :=
begin
split,
{ intros hd v w h h',
exact hd inf_le_left inf_le_right ⟨h, h'⟩, },
{ intros h H hH hH' v w hvw,
exact h _ _ (hH hvw) (hH' hvw), }
end
/-- A recursor that is kinder to `v` in `G.walk u v`. -/
@[elab_as_eliminator]
protected def walk.rec' {v : V} {motive : Π (u : V), G.walk u v → Sort*}
(hnil : motive v walk.nil)
(hcons : Π {u w : V} (h : G.adj u w) (p : G.walk w v), motive w p → motive u (walk.cons h p)) :
Π {u : V} (p : G.walk u v), motive u p
| _ walk.nil := hnil
| _ (walk.cons h p) := hcons h p (walk.rec' p)
using_well_founded {rel_tac := λ _ _, `[exact ⟨_, measure_wf (λ x, x.snd.length)⟩]}
lemma walk.drop_until_eq_of_length_eq [decidable_eq V]
{u v w : V} (p : G.walk u v) (hw : w ∈ p.support)
(h : (p.drop_until w hw).length = p.length) :
∃ (h : w = u), (p.drop_until w hw).copy h rfl = p :=
begin
have := congr_arg walk.length (walk.take_spec p hw),
rw [walk.length_append, h, add_left_eq_self] at this,
cases walk.eq_of_length_eq_zero this,
refine ⟨rfl, _⟩,
have key := walk.take_spec p hw,
rw [walk.length_eq_zero_iff] at this,
rw [this, walk.nil_append] at key,
exact key,
end
lemma walk.bypass_eq_of_length_le [decidable_eq V]
{u v : V} (p : G.walk u v) (h : p.length ≤ p.bypass.length) :
p.bypass = p :=
begin
induction p with a b c d he p ih,
{ simp only [walk.bypass], },
{ simp only [walk.bypass],
split_ifs with hb,
{ exfalso,
simp only [hb, walk.bypass, walk.length_cons, dif_pos] at h,
have := h.trans ((walk.length_drop_until_le p.bypass hb).trans (walk.length_bypass_le p)),
exact nat.not_succ_le_self _ this, },
{ simp only [hb, walk.bypass, walk.length_cons, not_false_iff, dif_neg, add_le_add_iff_right] at h,
simp [ih h], } }
end
protected
lemma reachable.exists_path_of_dist {u v : V} (hr : G.reachable u v) :
∃ (p : G.walk u v), p.is_path ∧ p.length = G.dist u v :=
begin
classical,
obtain ⟨p, h⟩ := hr.exists_walk_of_dist,
refine ⟨p, _, h⟩,
have : p.bypass = p,
{ have := calc p.length = G.dist u v : h
... ≤ p.bypass.length : dist_le p.bypass,
exact walk.bypass_eq_of_length_le p this },
rw [← this],
apply walk.bypass_is_path,
end
lemma dist_eq_one_of_adj {u v : V} (h : G.adj u v) :
G.dist u v = 1 :=
begin
apply le_antisymm (dist_le h.to_walk),
obtain (hd | hd) := eq_or_ne (G.dist u v) 0,
{ rw hd,
rw [h.reachable.dist_eq_zero_iff] at hd,
cases hd,
cases h.ne rfl },
{ rw [← nat.one_le_iff_ne_zero] at hd,
exact hd, },
end
protected
lemma reachable.dist_triangle {u v w : V} (huv : G.reachable u v) (hvw : G.reachable v w) :
G.dist u w ≤ G.dist u v + G.dist v w :=
begin
obtain ⟨p, hp⟩ := huv.exists_walk_of_dist,
obtain ⟨q, hq⟩ := hvw.exists_walk_of_dist,
rw [← hp, ← hq, ← walk.length_append],
apply dist_le,
end
/-- The vertices in the same connected component. -/
def connected_component.supp (c : G.connected_component) : set V :=
{v | G.connected_component_mk v = c}
@[simp] lemma connected_component.mem_supp {v : V} {c : G.connected_component} :
v ∈ c.supp ↔ G.connected_component_mk v = c := iff.rfl
/-- The graph consisting of all the edges in the connected component for `c`. -/
def connected_component.induce (c : G.connected_component) : simple_graph V :=
(G.induce c.supp).spanning_coe
@[simp] lemma connected_component.induce_adj_left (c : G.connected_component) {v w : V} :
c.induce.adj v w ↔ G.connected_component_mk v = c ∧ G.adj v w :=
begin
simp only [connected_component.induce, map_adj, comap_adj, function.embedding.coe_subtype,
set_coe.exists, connected_component.mem_supp, subtype.coe_mk, exists_prop],
split,
{ rintro ⟨a, hrab, b, rfl, hab, rfl, rfl⟩,
exact ⟨hrab, hab⟩, },
{ rintro ⟨hc, hvw⟩,
refine ⟨v, hc, w, _, hvw, rfl, rfl⟩,
rw [← hc, connected_component.eq],
exact hvw.symm.reachable, }
end
lemma connected_component.induce_le (c : G.connected_component) : c.induce ≤ G :=
spanning_coe_induce_le _ _
lemma connected_component.mem_supp_of_adj (c : G.connected_component) {v w : V}
(hvw : c.induce.adj v w) : v ∈ c.supp :=
begin
simp only [connected_component.induce_adj_left] at hvw,
simpa using hvw.1,
end
lemma connected_component.not_adj_of_not_mem_supp (c : G.connected_component) {v w : V}
(hv : ¬ v ∈ c.supp) : ¬ c.induce.adj v w :=
mt (c.mem_supp_of_adj) hv
-- Note: it might not be that `c.induce.support.nonempty` since the connected component
-- might have just a single vertex.
lemma connected_component.induce_support_le (c : G.connected_component) :
c.induce.support ≤ c.supp :=
begin
rintro v ⟨w, hvw⟩,
exact c.mem_supp_of_adj hvw,
end
lemma connected_component.induce.mem_of_reachable (c : G.connected_component)
{v w : V} (hv : v ∈ c.induce.support) (hvw : G.adj v w) :
w ∈ c.induce.support :=
begin
refine connected_component.ind (λ u hv, _) c hv,
simp only [mem_support, connected_component.induce_adj_left, connected_component.eq,
exists_and_distrib_left] at hv ⊢,
exact ⟨hvw.symm.reachable.trans hv.1, ⟨v, hvw.symm⟩⟩,
end
/-- A graph is a *matching* if every vertex has at most one neighbor. -/
def is_matching (G : simple_graph V) : Prop := ∀ v, (G.neighbor_set v).subsingleton
/-- A graph is a *perfect matching* if every vertex has exactly one neighbor. -/
def is_perfect_matching (G : simple_graph V) : Prop := ∀ v, ∃! w, G.adj v w
section matchings
variables {G}
namespace is_matching
lemma adj_unique (hm : G.is_matching) {v w w' : V} (h : G.adj v w) (h' : G.adj v w') : w = w' :=
hm v h h'
end is_matching
namespace is_perfect_matching
variables (hp : G.is_perfect_matching)
/-- The unique vertex incident to `v` in the perfect matching. -/
protected def other (v : V) : V := (hp v).some
lemma adj_other (v : V) : G.adj v (hp.other v) := (hp v).some_spec.1
lemma other_unique {v w : V} (ha : G.adj v w) : w = hp.other v := (hp v).some_spec.2 w ha
lemma adj_iff_eq {v w : V} : G.adj v w ↔ w = hp.other v :=
⟨hp.other_unique, by { rintro rfl, exact hp.adj_other v }⟩
lemma other_involutive : function.involutive hp.other :=
λ v, (hp.other_unique (hp.adj_other v).symm).symm
@[simp] lemma other_other (v : V) : hp.other (hp.other v) = v :=
hp.other_involutive v
lemma neighbor_set_eq (v : V) : G.neighbor_set v = {hp.other v} :=
by { ext w, simp [hp.adj_iff_eq] }
def locally_finite (hp : G.is_perfect_matching) : G.locally_finite :=
λ v, by { rw [hp.neighbor_set_eq], exact unique.fintype }
protected
lemma is_matching (hp : G.is_perfect_matching) : G.is_matching :=
begin
intro v,
rw [set.subsingleton_iff_singleton],
apply hp.neighbor_set_eq,
simp [hp.adj_other],
end
lemma support_eq_univ (hp : G.is_perfect_matching) : G.support = set.univ :=
begin
ext v,
simp [mem_support],
existsi hp.other v,
apply adj_other,
end
end is_perfect_matching
lemma is_perfect_matching_iff :
G.is_perfect_matching ↔ G.is_matching ∧ G.support = set.univ :=
begin
split,
{ intro hp,
exact ⟨hp.is_matching, hp.support_eq_univ⟩, },
{ rintro ⟨hm, hs⟩,
intro v,
have := set.ext_iff.mp hs v,
simp only [set.mem_univ, iff_true] at this,
obtain ⟨w, hvw⟩ := this,
refine ⟨w, hvw, _⟩,
intros w' hvw',
exact hm.adj_unique hvw' hvw, }
end
lemma is_perfect_matching_iff_forall_degree [G.locally_finite] :
G.is_perfect_matching ↔ ∀ (v : V), G.degree v = 1 :=
begin
rw [is_perfect_matching],
refine forall_congr (λ v, _),
simp_rw [degree, finset.card_eq_one, finset.singleton_iff_unique_mem, mem_neighbor_finset],
end
lemma is_perfect_matching_iff_one_regular [G.locally_finite] :
G.is_perfect_matching ↔ G.is_regular_of_degree 1 :=
by rw [is_perfect_matching_iff_forall_degree, is_regular_of_degree]
end matchings
theorem neighbor_set_sup {G H : simple_graph V} {v : V} :
(G ⊔ H).neighbor_set v = G.neighbor_set v ∪ H.neighbor_set v :=
by { ext w, simp }
theorem neighbor_set_inf {G H : simple_graph V} {v : V} :
(G ⊓ H).neighbor_set v = G.neighbor_set v ∩ H.neighbor_set v :=
by { ext w, simp }
theorem neighbor_finset_sup {G H : simple_graph V} {v : V} [decidable_eq V]
[fintype ((G ⊔ H).neighbor_set v)] [fintype (G.neighbor_set v)] [fintype (H.neighbor_set v)] :
(G ⊔ H).neighbor_finset v = G.neighbor_finset v ∪ H.neighbor_finset v :=
by { ext w, simp }
noncomputable
instance (G H : simple_graph V) {v : V} [fintype (G.neighbor_set v)] [fintype (H.neighbor_set v)] :
fintype ((G ⊔ H).neighbor_set v) :=
by { rw [neighbor_set_sup], exact fintype.of_finite ↥(neighbor_set G v ∪ neighbor_set H v) }
lemma disjoint_neighbor_set_of_disjoint {G H : simple_graph V} (hd : disjoint G H) {v : V} :
disjoint (G.neighbor_set v) (H.neighbor_set v) :=
begin
rw [set.disjoint_iff],
rintro w ⟨hg, hh⟩,
exfalso,
rw [disjoint_iff] at hd,
exact hd _ _ hg hh,
end
lemma disj_union_regular {G H : simple_graph V} [G.locally_finite] [H.locally_finite]
(hd : disjoint G H)
{m n : ℕ}
(hg : G.is_regular_of_degree m) (hh : H.is_regular_of_degree n) :
(G ⊔ H).is_regular_of_degree (m + n) :=
begin
intro v,
specialize hg v,
specialize hh v,
classical,
rw [degree, neighbor_finset_sup, finset.card_union_eq, ← degree, ← degree, hg, hh],
apply set.disjoint_to_finset.mpr,
apply disjoint_neighbor_set_of_disjoint hd,
end
lemma disj_union_perfect_matchings {G H : simple_graph V} [G.locally_finite] [H.locally_finite]
(hd : disjoint G H)
(hg : G.is_perfect_matching) (hh : H.is_perfect_matching) :
(G ⊔ H).is_regular_of_degree 2 :=
begin
rw [is_perfect_matching_iff_one_regular] at hg hh,
exact disj_union_regular hd hg hh,
end
lemma disj_union_three_perfect_matchings {G₁ G₂ G₃ : simple_graph V}
[G₁.locally_finite] [G₂.locally_finite] [G₃.locally_finite]
(hd₁₂ : disjoint G₁ G₂) (hd₁₃ : disjoint G₁ G₃) (hd₂₃ : disjoint G₂ G₃)
(hg₁ : G₁.is_perfect_matching) (hg₂ : G₂.is_perfect_matching) (hg₃ : G₃.is_perfect_matching) :
(G₁ ⊔ G₂ ⊔ G₃).is_regular_of_degree 3 :=
begin
rw [is_perfect_matching_iff_one_regular] at hg₃,
have := disj_union_perfect_matchings hd₁₂ hg₁ hg₂,
refine disj_union_regular _ this hg₃,
rw disjoint_sup_left,
split; assumption,
end
/--
Given disjoint perfect matchings and a connected component, we can flip those edges of `m`
to those of `m'` in the connected component.
-/
lemma flip_part_of_disjoint
{m m' : simple_graph V} (hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
(hd : disjoint m m')
(c : (m ⊔ m').connected_component) :
(m ∆ c.induce).is_perfect_matching :=
begin
intro v,
by_cases hv : v ∈ c.supp,
{ simp only [connected_component.mem_supp] at hv,
refine ⟨hm'.other v, _, _⟩,
{ simp only [symm_diff_def, sup_adj, sdiff_adj],
right,
split,
{ simp only [hv, connected_component.induce_adj_left, eq_self_iff_true, sup_adj, true_and],
right,
exact hm'.adj_other _, },
{ intro h,
have := hm'.adj_other v,
exact hd inf_le_left inf_le_right ⟨h, this⟩, }, },
{ intro w,
simp only [symm_diff_def, sup_adj, sdiff_adj, connected_component.induce_adj_left, not_and],
simp only [hv, eq_self_iff_true, forall_true_left, true_and],
simp only [not_or_distrib, ←and_assoc, and_not_self, false_and, false_or, and_imp],
simp only [or_imp_distrib, not_true, is_empty.forall_iff,
implies_true_iff, true_and] {contextual := tt},
intros hv hv',
exact hm'.other_unique hv, } },
{ refine ⟨hm.other v, _, _⟩,
{ simp only [symm_diff_def, hm.adj_other, sup_adj, sdiff_adj, true_and,
not_true, and_false, or_false],
intro h,
exact hv (c.mem_supp_of_adj h), },
{ intro w,
simp only [symm_diff_def, sup_adj, sdiff_adj],
simp only [c.not_adj_of_not_mem_supp hv, not_false_iff, and_true, false_and, or_false],
exact hm.other_unique, } }
end
lemma flip_part_of_disjoint_le
{m m' : simple_graph V}
(c : (m ⊔ m').connected_component) :
m ∆ c.induce ≤ m ⊔ m' :=
begin
intros v w,
simp only [symm_diff_def, sup_adj, sdiff_adj, connected_component.induce_adj_left, not_and,
not_or_distrib],
rintro (⟨h, _⟩ | ⟨⟨_, h⟩, _⟩),
{ exact or.inl h },
{ exact h }
end
/-- The predicate that every pair of distinct perfect matchings is disjoint. -/
def perfect_matchings_disjoint (G : simple_graph V) : Prop :=
∀ {m m' : simple_graph V}, m ≤ G → m' ≤ G →
m.is_perfect_matching → m'.is_perfect_matching → m ≠ m' → disjoint m m'
namespace perfect_matchings_disjoint
lemma ne_symm_diff (hpmd : G.perfect_matchings_disjoint)
{m m' : simple_graph V} (hm : m ≤ G) (hm' : m' ≤ G)
(hpm : m.is_perfect_matching) (hpm' : m'.is_perfect_matching) (hne : m ≠ m') (v : V) :
m ≠ m ∆ ((m ⊔ m').connected_component_mk v).induce :=
begin
intro h,
have hv := congr_fun (congr_fun (congr_arg simple_graph.adj h) v) (hpm.other v),
simp only [hpm.adj_other v, eq_true_eq_id, id.def] at hv,
simp only [symm_diff_def, hpm.adj_other v, sup_adj, sdiff_adj,
connected_component.induce_adj_left, connected_component.eq,
true_or, and_true, true_and, not_true, and_false, or_false] at hv,
exact hv reachable.rfl,
end
/-- The union of two distinct perfect matchings in a graph with the property that all perfect
matchings are disjoint is connected. -/
theorem disj_union_connected (hpmd : G.perfect_matchings_disjoint)
{m m' : simple_graph V} (hm : m ≤ G) (hm' : m' ≤ G)
(hpm : m.is_perfect_matching) (hpm' : m'.is_perfect_matching) (hne : m ≠ m') :
(m ⊔ m').connected :=
begin
haveI hnonempty : nonempty V,
{ by_contra h,
rw [not_nonempty_iff] at h,
apply hne,
ext v w,
exact h.elim v },
rw [connected_iff],
refine ⟨_, hnonempty⟩,
by_contra,
simp only [preconnected, not_forall] at h,
obtain ⟨v, v', h⟩ := h,
have hdisj := hpmd hm hm' hpm hpm' hne,
let c := (m ⊔ m').connected_component_mk v,
have hperf := flip_part_of_disjoint hpm hpm' hdisj c,
have hsup_le : m ⊔ m' ≤ G := sup_le hm hm',
have : m ≠ m ∆ c.induce := ne_symm_diff @hpmd hm hm' hpm hpm' hne v,
have := hpmd hm (le_trans (flip_part_of_disjoint_le c) hsup_le) hpm hperf this,
have h1 : m \ c.induce ≤ m,
{ intros v w,
simp only [sdiff_adj, implies_true_iff] {contextual := tt}, },
have h2 : m \ c.induce ≤ m ∆ c.induce,
{ intros v w,
simp only [symm_diff_def, sdiff_adj, connected_component.induce_adj_left,
connected_component.eq, sup_adj, not_and, and_imp],
simp { contextual := tt}, },
have h3 : (m \ c.induce).adj v' (hpm.other v'),
{ simp only [hpm.adj_other v', sdiff_adj, connected_component.induce_adj_left,
connected_component.eq, sup_adj, true_or, and_true, true_and],
contrapose! h,
exact h.symm, },
exact this h1 h2 h3,
end
end perfect_matchings_disjoint
section colorings
/-! ### Colorings and matchings
In this section we prove that the union of two perfect matchings is two-colorable (i.e., bipartite).
-/
def connected_component.out (c : G.connected_component) : V := c.out
lemma connected_component.out_eq (c : G.connected_component) :
G.connected_component_mk c.out = c := quot.out_eq _
lemma reachable_out_connected_component_mk (G : simple_graph V) (v : V) :
G.reachable (G.connected_component_mk v).out v :=
begin
rw [← connected_component.eq, connected_component.out_eq],
end
/-- The distance from a vertex to an arbitrary basepoint in its connected component. -/
def basepoint_dist (G : simple_graph V) (v : V) : ℕ :=
G.dist v (G.connected_component_mk v).out
def basepoint_mod2dist (G : simple_graph V) (v : V) : bool := even (G.basepoint_dist v)
/-- A walk whose edges alternate between two graphs. A `p : alt_graph G G' s e v w` is
a walk where if `s` is true it starts incident to `G` and if `e` is true ends incident to `G'`.
This way if the inner bools match up they can be appended. -/
inductive alt_walk (G G' : simple_graph V) : bool → bool → V → V → Type u
| nil (b : bool) (v : V) : alt_walk b b v v
| cons1 (e : bool) (u v w : V) (h : G.adj u v) (p : alt_walk ff e v w) : alt_walk tt e u w
| cons2 (e : bool) (u v w : V) (h : G'.adj u v) (p : alt_walk tt e v w) : alt_walk ff e u w
/-- Converts an alternating walk to a walk on `G ⊔ G'`. -/
def alt_walk.to_walk {G G' : simple_graph V} :
Π {s e : bool} {u v : V}, alt_walk G G' s e u v → (G ⊔ G').walk u v
| _ _ _ _ (alt_walk.nil _ _) := walk.nil
| _ _ _ _ (alt_walk.cons1 _ _ _ _ h p) := walk.cons (or.inl h) (alt_walk.to_walk p)
| _ _ _ _ (alt_walk.cons2 _ _ _ _ h p) := walk.cons (or.inr h) (alt_walk.to_walk p)
def alt_walk.append {G G' : simple_graph V} :
Π {s e e' : bool} {u v w : V},
alt_walk G G' s e u v → alt_walk G G' e e' v w → alt_walk G G' s e' u w
| _ _ _ _ _ _ (alt_walk.nil _ _) q := q
| _ _ _ _ _ _ (alt_walk.cons1 _ _ _ _ h p) q :=
alt_walk.cons1 _ _ _ _ h (alt_walk.append p q)
| _ _ _ _ _ _ (alt_walk.cons2 _ _ _ _ h p) q :=
alt_walk.cons2 _ _ _ _ h (alt_walk.append p q)
lemma alt_walk.to_walk_append {G G' : simple_graph V}
{s e e' : bool} {u v w : V}
(p : alt_walk G G' s e u v) (q : alt_walk G G' e e' v w) :
(p.append q).to_walk = p.to_walk.append q.to_walk :=
by induction p; simp! [*]
/-- The concatenation of the reverse of the first walk with the second walk. -/
protected def alt_walk.reverse_aux {G G' : simple_graph V} :
Π {s e e' : bool} {u v w : V},
alt_walk G G' s e u v → alt_walk G G' (!s) e' u w → alt_walk G G' (!e) e' v w
| _ _ _ _ _ _ (alt_walk.nil _ _) q := q
| _ _ _ _ _ _ (alt_walk.cons1 _ _ _ _ h p) q :=
alt_walk.reverse_aux p (alt_walk.cons1 _ _ _ _ h.symm q)
| _ _ _ _ _ _ (alt_walk.cons2 _ _ _ _ h p) q :=
alt_walk.reverse_aux p (alt_walk.cons2 _ _ _ _ h.symm q)
/-- The walk in reverse. -/
def alt_walk.reverse {G G' : simple_graph V} {u v : V} {s e : bool}
(p : alt_walk G G' s e u v) : alt_walk G G' (!e) (!s) v u := p.reverse_aux (alt_walk.nil _ _)
lemma alt_walk.reverse_aux_to_walk {G G' : simple_graph V}
{s e e' : bool} {u v w : V}
(p : alt_walk G G' s e u v) (q : alt_walk G G' (!s) e' u w) :
(alt_walk.reverse_aux p q).to_walk = walk.reverse_aux p.to_walk q.to_walk :=
begin
induction p generalizing q,
refl,
simp! [p_ih], refl,
simp! [p_ih], refl,
end
lemma alt_walk.to_walk_reverse {G G' : simple_graph V} {u v : V} {s e : bool}
(p : alt_walk G G' s e u v) :
p.reverse.to_walk = p.to_walk.reverse :=
begin
rw [alt_walk.reverse, alt_walk.reverse_aux_to_walk],
refl,
end
/-- Since we're keeping track of incidences, we can tell whether the length of
an alternating walk is even. -/
theorem even_alt_walk_length {G G' : simple_graph V} {s e : bool} {u v : V}
(p : alt_walk G G' s e u v) : even p.to_walk.length ↔ s = e :=
begin
induction p,
{ simp [alt_walk.to_walk], },
{ simp only [alt_walk.to_walk, nat.even_add_one, p_ih, walk.length_cons],
cases p_e; simp, },
{ simp only [alt_walk.to_walk, nat.even_add_one, p_ih, walk.length_cons],
cases p_e; simp, },
end
/-- Whether the walk is nil or whose first edge is in G. -/
def walk.starts_with_fst {G G' : simple_graph V} :
Π {u v : V}, (G ⊔ G').walk u v → Prop
| _ _ walk.nil := tt
| _ _ (walk.cons' u v w h p) := G.adj u v
/-- Whether the walk is nil or whose first edge is in G'. -/
def walk.starts_with_snd {G G' : simple_graph V} :
Π {u v : V}, (G ⊔ G').walk u v → Prop
| _ _ walk.nil := tt
| _ _ (walk.cons' u v w h p) := G'.adj u v
lemma walk.starts_with_fst_or_snd
{G G' : simple_graph V}
{u v : V} (p : (G ⊔ G').walk u v) :
p.starts_with_fst ∨ p.starts_with_snd :=
begin
cases p;
simp [walk.starts_with_fst, walk.starts_with_snd],
assumption,
end
/-- A boolean-controlled version of `walk.starts_with_fst` and `walk.starts_with_end`. -/
def walk.starts_with_opt {G G' : simple_graph V}
{u v : V} (p : (G ⊔ G').walk u v) (b : bool) : Prop :=
if b then walk.starts_with_fst p else walk.starts_with_snd p
lemma walk.starts_with_opt_append_of_ne_nil
{G G' : simple_graph V}
{u v w : V} (p : (G ⊔ G').walk u v) (q : (G ⊔ G').walk v w) (b : bool)
(hne : p.length ≠ 0) :
(p.append q).starts_with_opt b ↔ p.starts_with_opt b :=
begin
cases p,
{ exfalso, simpa using hne, },
{ simp! [walk.starts_with_opt], }
end
lemma walk.start_with_opt_tail
{m m' : simple_graph V}
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
{u w v : V} (huv : (m ⊔ m').adj u v) (p : (m ⊔ m').walk v w)
(hp : (walk.cons huv p).is_path)
(s : bool)
(hs : (walk.cons huv p).starts_with_opt s) :
p.starts_with_opt (!s) :=
begin
cases p,
{ simp! [walk.starts_with_opt], },
{ simp only [walk.cons_is_path_iff, not_or_distrib, walk.support_cons, list.mem_cons_iff] at hp,
simp! [walk.starts_with_opt],
simp! [walk.starts_with_opt] at hs,
cases s,
{ simp only [coe_sort_ff, is_empty.forall_iff, if_true],
simp only [coe_sort_ff, if_false] at hs,
cases p_h,
{ assumption },
{ exfalso,
cases hm'.is_matching.adj_unique hs.symm p_h,
simpa using hp, } },
{ simp only [coe_sort_tt, forall_true_left, if_false],
simp only [coe_sort_tt, if_true] at hs,
cases p_h,
{ exfalso,
cases hm.is_matching.adj_unique hs.symm p_h,
simpa using hp, },
{ assumption } } }
end
/-- Given a path in the sup of two perfect matchings, convert it into an alternating walk. -/
def walk.matchings_lift_alt_walk_of_path {m m' : simple_graph V}
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching) :
Π {u v : V} (p : (m ⊔ m').walk u v) (hp : p.is_path)
(s : bool) (hs : p.starts_with_opt s),
Σ (e : bool), alt_walk m m' s e u v
| _ _ walk.nil _ s _ := ⟨s, alt_walk.nil _ _⟩
| _ _ (walk.cons' u v w huv p) hp tt hs :=
let r := walk.matchings_lift_alt_walk_of_path p
(by { rw [walk.cons_is_path_iff] at hp, exact hp.1 })
ff (walk.start_with_opt_tail hm hm' huv p hp tt hs)
in ⟨r.1, alt_walk.cons1 _ _ _ _ hs r.2⟩
| _ _ (walk.cons' u v w huv p) hp ff hs :=
let r := walk.matchings_lift_alt_walk_of_path p
(by { rw [walk.cons_is_path_iff] at hp, exact hp.1 })
tt (walk.start_with_opt_tail hm hm' huv p hp ff hs)
in ⟨r.1, alt_walk.cons2 _ _ _ _
begin simpa [walk.starts_with_opt, walk.starts_with_snd] using hs end r.2⟩
theorem walk.matchings_lift_alt_walk_of_path_to_walk {m m' : simple_graph V}
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
{u v : V} (p : (m ⊔ m').walk u v) (hp : p.is_path)
(s : bool) (hs : p.starts_with_opt s) :
(p.matchings_lift_alt_walk_of_path hm hm' hp s hs).2.to_walk = p :=
begin
induction p with _ u v w huv p ih generalizing s,
{ simp! },
{ have := walk.start_with_opt_tail hm hm' huv p hp s hs,
rw [walk.cons_is_path_iff] at hp,
have := ih hp.1 (!s) this,
cases s; simp! [*], },
end
theorem walk.reverse_starts_with_opt_fst {m m' : simple_graph V}
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
{u v : V} (p : (m ⊔ m').walk u v) (hp : p.is_path)
(s : bool) (hs : p.starts_with_opt s) :
p.reverse.starts_with_opt (!(p.matchings_lift_alt_walk_of_path hm hm' hp s hs).1) :=
begin
induction p generalizing s,
{ simp! [walk.starts_with_opt], },
{ simp only [walk.reverse_cons],
by_cases hne : p_p.length = 0,
{ cases p_p, cases s; simp! [walk.starts_with_opt]; simp! [walk.starts_with_opt] at hs,
exact hs.symm, exact hs.symm,
exfalso, simpa using hne, },
rw [walk.starts_with_opt_append_of_ne_nil], swap, simp [hne],
cases s; rw [walk.matchings_lift_alt_walk_of_path],
dsimp, apply p_ih,
dsimp, apply p_ih, }
end
theorem walk.matchings_paths_unique_of_starts_with {m m' : simple_graph V}
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
{u v : V} (p q : (m ⊔ m').walk u v) (hp : p.is_path) (hq : q.is_path)
(s : bool) (hsp : p.starts_with_opt s) (hsq : q.starts_with_opt s) :
p = q :=
begin
induction p generalizing q s,
{ rw [walk.is_path_iff_eq_nil] at hq,
exact hq.symm, },
{ have keyp := walk.start_with_opt_tail hm hm' p_h p_p hp _ hsp,
cases q,
{ rw [walk.is_path_iff_eq_nil] at hp,
exact hp },
{ have keyq := walk.start_with_opt_tail hm hm' q_h q_p hq _ hsq,
simp only [walk.cons_is_path_iff] at hp hq,
have : p_v = q_v,
{ cases s; simp [walk.starts_with_opt, walk.starts_with_fst, walk.starts_with_snd] at hsp hsq,
exact hm'.is_matching.adj_unique hsp hsq,
exact hm.is_matching.adj_unique hsp hsq, },
cases this,
simp,
exact p_ih hp.1 q_p (!s) hq.1 keyp keyq, } }
end
/-| _ _ (walk.nil) _ := ⟨tt, alt_walk.nil tt _⟩
-- Since nil can't really decide what the endpoint bools should be, we need another base case:
| _ _ (walk.cons' u v _ h walk.nil) _ :=
if ha : m.adj u v then
⟨tt, ff, alt_walk.cons1 _ _ _ _ ha (alt_walk.nil _ _)⟩
else
have ha : m'.adj u v := by simpa [ha] using h,
⟨ff, tt, alt_walk.cons2 _ _ _ _ ha (alt_walk.nil _ _)⟩
| _ _ (walk.cons' u v w h p) hp :=
let r := walk.matchings_lift_alt_walk_of_path p
(by { rw [walk.cons_is_path_iff] at hp, exact hp.1 }) in
match r with
| ⟨tt, e, r'⟩ :=
have ha : m'.adj u v := by { },
sorry
| ⟨ff, e, r'⟩ := sorry-/
/--
Main idea of proof: given two paths between the same vertices, they're either the same
or they start and end in different matchings.
-/
lemma parity_path_sup_matchings (m m' : simple_graph V)
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
{v w : V} (p q : (m ⊔ m').walk v w) (hp : p.is_path) (hq : q.is_path) :
even p.length ↔ even q.length :=
begin
classical,
have Pstartfst : p.starts_with_opt p.starts_with_fst,
{ cases p.starts_with_fst_or_snd with hpfst hpfst;
simp [hpfst, walk.starts_with_opt, em'], },
cases hP : p.matchings_lift_alt_walk_of_path hm hm' hp p.starts_with_fst Pstartfst with Pe P,
have Qstartfst : q.starts_with_opt q.starts_with_fst,
{ cases q.starts_with_fst_or_snd with hpfst hpfst;
simp [hpfst, walk.starts_with_opt, em'], },
cases hQ : q.matchings_lift_alt_walk_of_path hm hm' hq q.starts_with_fst Qstartfst with Qe Q,
obtain (h | h) := eq_or_ne p.starts_with_fst q.starts_with_fst,
{ rw walk.matchings_paths_unique_of_starts_with hm hm' _ _ hp hq p.starts_with_fst Pstartfst,
rw [h], exact Qstartfst, },
have Pre : p.reverse.starts_with_opt (!Pe),
{ convert (walk.reverse_starts_with_opt_fst hm hm' p hp _ Pstartfst),
rw hP, },
have Qre : q.reverse.starts_with_opt (!Qe),
{ convert (walk.reverse_starts_with_opt_fst hm hm' q hq _ Qstartfst),
rw hQ, },
obtain (rfl | hPQ) := eq_or_ne Pe Qe,
{ have := walk.matchings_paths_unique_of_starts_with hm hm' p.reverse q.reverse
hp.reverse hq.reverse
_ Pre Qre,
apply_fun walk.length at this,
simp only [walk.length_reverse] at this,
rw [this], },
{ have hPlen : P.to_walk.length = p.length,
{ have := congr_arg walk.length
(walk.matchings_lift_alt_walk_of_path_to_walk hm hm' p hp _ Pstartfst),
rw [hP] at this,
exact this, },
have hQlen : Q.to_walk.length = q.length,
{ have := congr_arg walk.length
(walk.matchings_lift_alt_walk_of_path_to_walk hm hm' q hq _ Qstartfst),
rw [hQ] at this,
exact this, },
rw [← hPlen, ← hQlen, even_alt_walk_length, even_alt_walk_length],
simp [not_iff] at h,
cases Pe; cases Qe; simp at hPQ; try { exact false.elim hPQ }; simp [h.symm], },
end
lemma parity_path_sup_matchings_dist (m m' : simple_graph V)
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
{v w : V} (p : (m ⊔ m').walk v w) (hp : p.is_path) :
even p.length ↔ even ((m ⊔ m').dist v w) :=
begin
obtain ⟨q, hq, hd⟩ := p.reachable.exists_path_of_dist,
rw [← hd],
apply parity_path_sup_matchings _ _ hm hm' _ _ hp hq,
end
/-
lemma even_length_loop_sup_matchings (m m' : simple_graph V)
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
{v : V} (p : (m ⊔ m').walk v v) : even p.length :=
begin
induction hn : p.length using nat.strong_induction_on with n ih generalizing p,
by_cases hc : p.is_cycle,
{ sorry
},
cases p with _ _ w _ hvw p,
{ cases hn, exact even_zero, },
{ simp only [walk.cons_is_cycle_iff, not_and, not_not] at hc,
}
end
-/
/-lemma even_length_loop_sup_matchings (m m' : simple_graph V)
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
{v : V} (p : (m ⊔ m').walk v v) : even p.length :=
begin
induction hn : p.length using nat.strong_induction_on with n ih generalizing p,
by_cases hc : p.is_cycle,
{ sorry
},
{ rw [← hn],
cases p,
{ simp only [walk.length_nil, even_zero], },
--simp only [walk.length_cons] at hn,
simp only [walk.cons_is_cycle_iff, not_and, not_not] at hc,
by_cases hpp : p_p.is_path,
{ specialize hc hpp,
},
},
end-/
lemma even_basepoint_dist_sup_matchings (m m' : simple_graph V)
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
{v w : V} (hvw : (m ⊔ m').adj v w) :
even ((m ⊔ m').basepoint_dist v) ↔ ¬even ((m ⊔ m').basepoint_dist w) :=
begin
classical,
let c := (m ⊔ m').connected_component_mk v,
have : c = (m ⊔ m').connected_component_mk w,
{ exact connected_component.sound hvw.reachable, },
have hvr : (m ⊔ m').reachable v c.out := (reachable_out_connected_component_mk (m ⊔ m') v).symm,
have hwr : (m ⊔ m').reachable w c.out := hvw.reachable.symm.trans hvr,
obtain ⟨p, hp, hpw⟩ := hvr.exists_path_of_dist,
obtain ⟨q, hq, hqw⟩ := hwr.exists_path_of_dist,
simp only [basepoint_dist, ← this, ← hpw, ← hqw],
have htri2 := reachable.dist_triangle hvw.symm.reachable hvr,
simp [hvw, hvw.symm, dist_eq_one_of_adj] at htri2,
clear hvr hwr this,
by_cases hq' : (walk.cons hvw q).is_path,
{ rw parity_path_sup_matchings m m' hm hm' _ _ hp hq',
simp only [nat.even_add_one, walk.length_cons], },
{ simp only [walk.cons_is_path_iff, not_and, not_not, hq, true_implies_iff] at hq',
induction q using simple_graph.walk.rec',
{ exfalso, simp at hq', simp [hq'] at hvw, exact hvw, },
{ simp only [walk.support_cons, list.mem_cons_iff] at hq',
obtain (rfl | hq') := hq',
{ cases hvw.ne rfl, },
{ simp [← hpw, ← hqw] at htri2,
simp only [add_comm, add_le_add_iff_left] at htri2,
have := walk.length_drop_until_le _ hq',
have := (this.trans htri2).trans hpw.le,
have := le_antisymm this (dist_le _),
rw [hpw, ← this] at htri2,
obtain ⟨rfl, hq'⟩ := walk.drop_until_eq_of_length_eq _ hq'
(le_antisymm (walk.length_drop_until_le _ hq') htri2),
simp only [walk.copy_rfl_rfl] at hq',
rw [hq', ← hpw] at this,
simp [this, nat.even_add_one], } } },
end
/-
lemma even_basepoint_dist_sup_matchings (m m' : simple_graph V)
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
{v w : V} (hvw : (m ⊔ m').adj v w) :
even ((m ⊔ m').basepoint_dist v) ↔ ¬even ((m ⊔ m').basepoint_dist w) :=
begin
have : (m ⊔ m').connected_component_mk v = (m ⊔ m').connected_component_mk w,
{ exact connected_component.sound hvw.reachable, },
simp only [basepoint_dist, this],
obtain ⟨pw, hpw⟩ := (reachable_out_connected_component_mk (m ⊔ m') w).exists_walk_of_dist,
have h := (reachable_out_connected_component_mk (m ⊔ m') w).trans hvw.symm.reachable,
obtain ⟨pv, hpv⟩ := h.exists_walk_of_dist,
rw [← hpw, ← hpv],
have : even (walk.cons hvw.symm (pv.reverse.append pw)).length :=
even_length_loop_sup_matchings m m' hm hm' _,
simp only [nat.even_add, not_iff, walk.length_cons, walk.length_append, walk.length_reverse,
nat.not_even_one, iff_false] at this,
simp [← this],
end
-/
lemma basepoint_mod2dist_sup_matchings (m m' : simple_graph V)
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching)
{v w : V} (hvw : (m ⊔ m').adj v w) :
(m ⊔ m').basepoint_mod2dist v ≠ ((m ⊔ m').basepoint_mod2dist w) :=
begin
simp only [basepoint_mod2dist, even_basepoint_dist_sup_matchings m m' hm hm' hvw,
bool.to_bool_not, ne.def, bool.bnot_not_eq],
end
/-- The union of two perfect matchings is a bipartite graph. -/
def mod2dist_coloring (m m' : simple_graph V)
(hm : m.is_perfect_matching) (hm' : m'.is_perfect_matching) :
(m ⊔ m').coloring bool :=
coloring.mk (m ⊔ m').basepoint_mod2dist
begin
intros v w hvw,
exact basepoint_mod2dist_sup_matchings m m' hm hm' hvw,
end
end colorings
section two_coloring
/-! ### 2-regular two-colorable graphs
In this section, we show that a 2-regular two-colorable connected graph is an even-length cycle,
in that there is an enumeration of its vertices by `fin (2 * k)`.
-/
/--
Given that `G.adj u v`, get the other vertex adjacent to `v`.
-/
def two_regular_other [decidable_eq V]
(G : simple_graph V) [G.locally_finite] (h : G.is_regular_of_degree 2)
{u v : V} (huv : G.adj u v) : V :=
(G.neighbor_finset v).choose (λ w, w ≠ u)
begin
specialize h v,
rw [degree, finset.card_eq_two] at h,
obtain ⟨w, w', h⟩ := h,
obtain (rfl | hne) := eq_or_ne u w,
{ use w',
rw [h.2], simp,
simp only [h.1.symm, finset.mem_attach, ne.def, not_false_iff, true_and,
subtype.forall, mem_neighbor_finset], },
{ use w,
rw [h.2],
simp [hne.symm, h.1.symm, imp_false],
rw [adj_comm, ← mem_neighbor_finset, h.2] at huv,
simp [hne] at huv,
exact huv.symm, }
end
lemma two_regular_other_adj [decidable_eq V]
(G : simple_graph V) [G.locally_finite] (h : G.is_regular_of_degree 2)
{u v : V} (huv : G.adj u v) : G.adj v (G.two_regular_other h huv) :=
begin
simp [two_regular_other],
rw [← mem_neighbor_finset],
apply finset.choose_mem,
end
lemma two_regular_other_ne [decidable_eq V]
(G : simple_graph V) [G.locally_finite] (h : G.is_regular_of_degree 2)
{u v : V} (huv : G.adj u v) : G.two_regular_other h huv ≠ u :=
begin
simp [two_regular_other],
generalize_proofs hp,
exact finset.choose_property _ _ hp,
end
def follow_cycle' [decidable_eq V]
(G : simple_graph V) [G.locally_finite] (h : G.is_regular_of_degree 2) :
Π {u v : V} (huv : G.adj u v), ℕ → V
| u v huv 0 := u
| u v huv 1 := v
| u v huv (n + 1) := follow_cycle' (G.two_regular_other_adj h huv) n
lemma follow_cycle'_adj_succ [decidable_eq V]
(G : simple_graph V) [G.locally_finite] (h : G.is_regular_of_degree 2)
{u v : V} (huv : G.adj u v) (n : ℕ) :
G.adj (G.follow_cycle' h huv n) (G.follow_cycle' h huv (n + 1)) :=
begin
cases n,
{ exact huv },
induction n generalizing u v,
{ apply two_regular_other_adj, },
{ simp [follow_cycle'],
simp [follow_cycle'] at n_ih,
apply n_ih,
apply G.two_regular_other_adj, }
end
def follow_cycle [decidable_eq V]
(G : simple_graph V) [G.locally_finite] (h : G.is_regular_of_degree 2)
{u v : V} (huv : G.adj u v) : ℤ → V
| (int.of_nat n) := G.follow_cycle' h huv n
| -[1+ n] := G.follow_cycle' h huv.symm (n + 2)
lemma follow_cycle_coe [decidable_eq V]
(G : simple_graph V) [G.locally_finite] (h : G.is_regular_of_degree 2)
{u v : V} (huv : G.adj u v) (n : ℕ) :
G.follow_cycle h huv n = G.follow_cycle' h huv n := rfl
lemma follow_cycle_zero [decidable_eq V]
(G : simple_graph V) [G.locally_finite] (h : G.is_regular_of_degree 2)
{u v : V} (huv : G.adj u v) :
G.follow_cycle h huv 0 = u := rfl
lemma follow_cycle_one [decidable_eq V]
(G : simple_graph V) [G.locally_finite] (h : G.is_regular_of_degree 2)
{u v : V} (huv : G.adj u v) :
G.follow_cycle h huv 1 = v := rfl
lemma follow_cycle_neg_coe [decidable_eq V]
(G : simple_graph V) [G.locally_finite] (h : G.is_regular_of_degree 2)
{u v : V} (huv : G.adj u v) (n : ℕ) :
G.follow_cycle h huv (- n) = G.follow_cycle' h (G.two_regular_other_adj h huv.symm) n :=
begin
cases n,
{ simp [follow_cycle_zero, follow_cycle'], },
{ simp [],
rw [add_comm, ← neg_add, ← int.coe_nat_one, ← int.coe_nat_add, ← int.neg_succ_of_nat_coe],
rw [follow_cycle],
simp [follow_cycle'], }
end
/-- Key basic property of `G.follow_cycle`.
This is showing that `ℤ` as a line has a graph homomorphism to `G`. -/
lemma follow_cycle_adj_succ [decidable_eq V]
(G : simple_graph V) [G.locally_finite] (h : G.is_regular_of_degree 2)
{u v : V} (huv : G.adj u v) (n : ℤ) :
G.adj (G.follow_cycle h huv n) (G.follow_cycle h huv (n + 1)) :=
begin
obtain ⟨n, rfl | rfl⟩ := int.eq_coe_or_neg n,
{ rw [int.coe_nat_add_one_out, follow_cycle_coe, follow_cycle_coe],
apply follow_cycle'_adj_succ, },
{ cases n,
{ simp [follow_cycle_zero, follow_cycle_one, huv], },
{ rw [follow_cycle_neg_coe],
simp only [neg_add_cancel_comm, nat.cast_succ, neg_add_rev, follow_cycle_neg_coe],
rw [adj_comm],
apply follow_cycle'_adj_succ, } },
end