@@ -177,16 +177,21 @@ theorem adj_getVert_succ {u v} (w : G.Walk u v) {i : ℕ} (hi : i < w.length) :
177
177
· simp [getVert, hxy]
178
178
· exact ih (Nat.succ_lt_succ_iff.1 hi)
179
179
180
+ lemma getVert_cons_one {u v w} (q : G.Walk v w) (hadj : G.Adj u v) :
181
+ (q.cons hadj).getVert 1 = v := by
182
+ have : (q.cons hadj).getVert 1 = q.getVert 0 := rfl
183
+ simpa [getVert_zero] using this
184
+
180
185
@[simp]
181
- lemma cons_getVert_succ {u v w n} (p : G.Walk v w) (h : G.Adj u v) :
186
+ lemma getVert_cons_succ {u v w n} (p : G.Walk v w) (h : G.Adj u v) :
182
187
(p.cons h).getVert (n + 1 ) = p.getVert n := rfl
183
188
184
- lemma cons_getVert {u v w n} (p : G.Walk v w) (h : G.Adj u v) (hn : n ≠ 0 ) :
189
+ lemma getVert_cons {u v w n} (p : G.Walk v w) (h : G.Adj u v) (hn : n ≠ 0 ) :
185
190
(p.cons h).getVert n = p.getVert (n - 1 ) := by
186
191
obtain ⟨i, hi⟩ : ∃ (i : ℕ), i.succ = n := by
187
192
use n - 1 ; exact Nat.succ_pred_eq_of_ne_zero hn
188
193
rw [← hi]
189
- simp only [Nat.succ_eq_add_one, cons_getVert_succ , Nat.add_sub_cancel]
194
+ simp only [Nat.succ_eq_add_one, getVert_cons_succ , Nat.add_sub_cancel]
190
195
191
196
@[simp]
192
197
theorem cons_append {u v w x : V} (h : G.Adj u v) (p : G.Walk v w) (q : G.Walk w x) :
@@ -754,6 +759,9 @@ lemma nil_iff_support_eq {p : G.Walk v w} : p.Nil ↔ p.support = [v] := by
754
759
lemma nil_iff_length_eq {p : G.Walk v w} : p.Nil ↔ p.length = 0 := by
755
760
cases p <;> simp
756
761
762
+ lemma not_nil_iff_lt_length {p : G.Walk v w} : ¬ p.Nil ↔ 0 < p.length := by
763
+ cases p <;> simp
764
+
757
765
lemma not_nil_iff {p : G.Walk v w} :
758
766
¬ p.Nil ↔ ∃ (u : V) (h : G.Adj v u) (q : G.Walk u w), p = cons h q := by
759
767
cases p <;> simp [*]
@@ -778,61 +786,77 @@ lemma notNilRec_cons {motive : {u w : V} → (p : G.Walk u w) → ¬ p.Nil → S
778
786
motive (q.cons h) Walk.not_nil_cons) (h' : G.Adj u v) (q' : G.Walk v w) :
779
787
@Walk.notNilRec _ _ _ _ _ cons _ _ = cons h' q' := by rfl
780
788
781
- /-- The second vertex along a non-nil walk. -/
782
- def sndOfNotNil (p : G.Walk v w) (hp : ¬ p.Nil ) : V :=
783
- p.notNilRec (@ fun _ u _ _ _ => u) hp
789
+ @[simp] lemma adj_getVert_one {p : G.Walk v w} (hp : ¬ p.Nil) :
790
+ G.Adj v (p.getVert 1 ) := by
791
+ simpa using adj_getVert_succ p ( by simpa [not_nil_iff_lt_length] using hp : 0 < p.length)
784
792
785
- @[simp] lemma adj_sndOfNotNil {p : G.Walk v w} (hp : ¬ p.Nil) :
786
- G.Adj v (p.sndOfNotNil hp) :=
787
- p.notNilRec (fun h _ => h) hp
793
+ /-- The walk obtained by removing the first `n` darts of a walk. -/
794
+ def drop {u v : V} (p : G.Walk u v) (n : ℕ) : G.Walk (p.getVert n) v :=
795
+ match p, n with
796
+ | .nil, _ => .nil
797
+ | p, 0 => p.copy (getVert_zero p).symm rfl
798
+ | .cons h q, (n + 1 ) => (q.drop n).copy (getVert_cons_succ _ h).symm rfl
788
799
789
800
/-- The walk obtained by removing the first dart of a non-nil walk. -/
790
- def tail (p : G.Walk u v) (hp : ¬ p.Nil) : G.Walk (p.sndOfNotNil hp) v :=
791
- p.notNilRec (fun _ q => q) hp
801
+ def tail (p : G.Walk u v) : G.Walk (p.getVert 1 ) v := p.drop 1
802
+
803
+ @[simp]
804
+ lemma tail_cons_nil (h : G.Adj u v) : (Walk.cons h .nil).tail = .nil := by rfl
805
+
806
+ lemma tail_cons_eq (h : G.Adj u v) (p : G.Walk v w) :
807
+ (p.cons h).tail = p.copy (getVert_zero p).symm rfl := by
808
+ match p with
809
+ | .nil => rfl
810
+ | .cons h q => rfl
792
811
793
812
/-- The first dart of a walk. -/
794
813
@[simps]
795
814
def firstDart (p : G.Walk v w) (hp : ¬ p.Nil) : G.Dart where
796
815
fst := v
797
- snd := p.sndOfNotNil hp
798
- adj := p.adj_sndOfNotNil hp
816
+ snd := p.getVert 1
817
+ adj := p.adj_getVert_one hp
799
818
800
819
lemma edge_firstDart (p : G.Walk v w) (hp : ¬ p.Nil) :
801
- (p.firstDart hp).edge = s(v, p.sndOfNotNil hp ) := rfl
820
+ (p.firstDart hp).edge = s(v, p.getVert 1 ) := rfl
802
821
803
822
variable {x y : V} -- TODO: rename to u, v, w instead?
804
823
805
- @[simp] lemma cons_tail_eq (p : G.Walk x y) (hp : ¬ p.Nil) :
806
- cons (p.adj_sndOfNotNil hp) (p.tail hp) = p :=
807
- p.notNilRec (fun _ _ => rfl) hp
824
+ lemma cons_tail_eq (p : G.Walk x y) (hp : ¬ p.Nil) :
825
+ cons (p.adj_getVert_one hp) p.tail = p := by
826
+ cases p with
827
+ | nil => simp only [nil_nil, not_true_eq_false] at hp
828
+ | cons h q =>
829
+ simp only [getVert_cons_succ, tail_cons_eq, cons_copy, copy_rfl_rfl]
808
830
809
831
@[simp] lemma cons_support_tail (p : G.Walk x y) (hp : ¬p.Nil) :
810
- x :: ( p.tail hp) .support = p.support := by
811
- rw [← support_cons, cons_tail_eq]
832
+ x :: p.tail.support = p.support := by
833
+ rw [← support_cons, cons_tail_eq _ hp ]
812
834
813
835
@[simp] lemma length_tail_add_one {p : G.Walk x y} (hp : ¬ p.Nil) :
814
- ( p.tail hp) .length + 1 = p.length := by
815
- rw [← length_cons, cons_tail_eq]
836
+ p.tail.length + 1 = p.length := by
837
+ rw [← length_cons, cons_tail_eq _ hp ]
816
838
817
839
@[simp] lemma nil_copy {x' y' : V} {p : G.Walk x y} (hx : x = x') (hy : y = y') :
818
840
(p.copy hx hy).Nil = p.Nil := by
819
841
subst_vars; rfl
820
842
821
- @[simp] lemma support_tail (p : G.Walk v v) (hp) :
822
- ( p.tail hp) .support = p.support.tail := by
843
+ @[simp] lemma support_tail (p : G.Walk v v) (hp : ¬ p.Nil ) :
844
+ p.tail.support = p.support.tail := by
823
845
rw [← cons_support_tail p hp, List.tail_cons]
824
846
825
847
@[simp]
826
848
lemma tail_cons {t u v} (p : G.Walk u v) (h : G.Adj t u) :
827
- (p.cons h).tail not_nil_cons = p := by
828
- unfold Walk.tail; simp only [notNilRec_cons]
849
+ (p.cons h).tail = p.copy (getVert_zero p).symm rfl := by
850
+ match p with
851
+ | .nil => rfl
852
+ | .cons h q => rfl
829
853
830
- lemma tail_support_eq_support_tail (p : G.Walk u v) (hnp : ¬p.Nil) :
831
- ( p.tail hnp) .support = p.support.tail :=
832
- p.notNilRec ( by
833
- intro u v w huv q
834
- unfold Walk.tail
835
- simp only [notNilRec_cons, Walk. support_cons, List.tail_cons]) hnp
854
+ lemma support_tail_of_not_nil (p : G.Walk u v) (hnp : ¬p.Nil) :
855
+ p.tail.support = p.support.tail := by
856
+ match p with
857
+ | .nil => simp only [nil_nil, not_true_eq_false] at hnp
858
+ | .cons h q =>
859
+ simp only [tail_cons, getVert_cons_succ, support_copy, support_cons, List.tail_cons]
836
860
837
861
/-! ### Walk decompositions -/
838
862
@@ -1008,17 +1032,23 @@ theorem exists_boundary_dart {u v : V} (p : G.Walk u v) (S : Set V) (uS : u ∈
1008
1032
exact ⟨d, List.Mem.tail _ hd, hcd⟩
1009
1033
· exact ⟨⟨(x, y), a⟩, List.Mem.head _, uS, h⟩
1010
1034
1011
- lemma getVert_tail {u v n} (p : G.Walk u v) (hnp: ¬ p.Nil) :
1012
- (p.tail hnp).getVert n = p.getVert (n + 1 ) :=
1013
- p.notNilRec (fun _ _ ↦ by simp only [tail_cons, cons_getVert_succ]) hnp
1014
-
1015
- @[simp]
1016
- lemma cons_sndOfNotNil (q : G.Walk v w) (hadj : G.Adj u v) :
1017
- (q.cons hadj).sndOfNotNil not_nil_cons = v := by
1018
- unfold sndOfNotNil; simp only [notNilRec_cons]
1019
-
1020
- lemma getVert_one (p : G.Walk u v) (hnp : ¬ p.Nil) : p.getVert 1 = p.sndOfNotNil hnp :=
1021
- p.notNilRec (fun _ _ ↦ by simp only [cons_getVert_succ, getVert_zero, cons_sndOfNotNil]) hnp
1035
+ @[simp] lemma getVert_copy {u v w x : V} (p : G.Walk u v) (i : ℕ) (h : u = w) (h' : v = x) :
1036
+ (p.copy h h').getVert i = p.getVert i := by
1037
+ subst_vars
1038
+ match p, i with
1039
+ | .nil, _ =>
1040
+ rw [getVert_of_length_le _ (by simp only [length_nil, Nat.zero_le] : nil.length ≤ _)]
1041
+ rw [getVert_of_length_le _ (by simp only [length_copy, length_nil, Nat.zero_le])]
1042
+ | .cons hadj q, 0 => simp only [copy_rfl_rfl, getVert_zero]
1043
+ | .cons hadj q, (n + 1 ) => simp only [copy_cons, getVert_cons_succ]; rfl
1044
+
1045
+ @[simp] lemma getVert_tail {u v n} (p : G.Walk u v) (hnp: ¬ p.Nil) :
1046
+ p.tail.getVert n = p.getVert (n + 1 ) := by
1047
+ match p with
1048
+ | .nil => rfl
1049
+ | .cons h q =>
1050
+ simp only [getVert_cons_succ, tail_cons_eq, getVert_cons]
1051
+ exact getVert_copy q n (getVert_zero q).symm rfl
1022
1052
1023
1053
/-- Given a walk `w` and a node in the support, there exists a natural `n`, such that given node
1024
1054
is the `n`-th node (zero-indexed) in the walk. In addition, `n` is at most the length of the path.
@@ -1045,13 +1075,18 @@ theorem mem_support_iff_exists_getVert {u v w : V} {p : G.Walk v w} :
1045
1075
rw [@nil_iff_length_eq]
1046
1076
have : 1 ≤ p.length := by omega
1047
1077
exact Nat.not_eq_zero_of_lt this
1048
- rw [← tail_support_eq_support_tail _ hnp]
1078
+ rw [← support_tail_of_not_nil _ hnp]
1049
1079
rw [mem_support_iff_exists_getVert]
1050
1080
use n - 1
1051
- simp only [Nat.sub_le_iff_le_add, length_tail_add_one, getVert_tail]
1052
- have : n - 1 + 1 = n := by omega
1081
+ simp only [Nat.sub_le_iff_le_add]
1082
+ rw [getVert_tail _ hnp, length_tail_add_one hnp]
1083
+ have : (n - 1 + 1 ) = n:= by omega
1053
1084
rwa [this]
1054
1085
termination_by p.length
1086
+ decreasing_by
1087
+ · simp_wf
1088
+ rw [@Nat.lt_iff_add_one_le]
1089
+ rw [length_tail_add_one hnp]
1055
1090
1056
1091
end Walk
1057
1092
0 commit comments