Skip to content

Commit 2eda5e7

Browse files
committed
feat(SimpleGraph): Helper lemmas for Walk.take/drop (#25650)
Contributing helper lemmas I needed when formalizing Cayley graphs.
1 parent 71f3251 commit 2eda5e7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Mathlib/Combinatorics/SimpleGraph/Walk.lean

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,18 @@ def drop {u v : V} (p : G.Walk u v) (n : ℕ) : G.Walk (p.getVert n) v :=
901901
| p, 0 => p.copy (getVert_zero p).symm rfl
902902
| .cons _ q, (n + 1) => q.drop n
903903

904+
@[simp]
905+
lemma drop_length (p : G.Walk u v) (n : ℕ) : (p.drop n).length = p.length - n := by
906+
induction p generalizing n with
907+
| nil => simp [drop]
908+
| cons => cases n <;> simp_all [drop]
909+
910+
@[simp]
911+
lemma drop_getVert (p : G.Walk u v) (n m : ℕ) : (p.drop n).getVert m = p.getVert (n + m) := by
912+
induction p generalizing n with
913+
| nil => simp [drop]
914+
| cons => cases n <;> simp_all [drop, Nat.add_right_comm]
915+
904916
/-- The second vertex of a walk, or the only vertex in a nil walk. -/
905917
abbrev snd (p : G.Walk u v) : V := p.getVert 1
906918

@@ -918,6 +930,18 @@ def take {u v : V} (p : G.Walk u v) (n : ℕ) : G.Walk u (p.getVert n) :=
918930
| p, 0 => nil.copy rfl (getVert_zero p).symm
919931
| .cons h q, (n + 1) => .cons h (q.take n)
920932

933+
@[simp]
934+
lemma take_length (p : G.Walk u v) (n : ℕ) : (p.take n).length = n ⊓ p.length := by
935+
induction p generalizing n with
936+
| nil => simp [take]
937+
| cons => cases n <;> simp_all [take]
938+
939+
@[simp]
940+
lemma take_getVert (p : G.Walk u v) (n m : ℕ) : (p.take n).getVert m = p.getVert (n ⊓ m) := by
941+
induction p generalizing n m with
942+
| nil => simp [take]
943+
| cons => cases n <;> cases m <;> simp_all [take]
944+
921945
/-- The penultimate vertex of a walk, or the only vertex in a nil walk. -/
922946
abbrev penultimate (p : G.Walk u v) : V := p.getVert (p.length - 1)
923947

0 commit comments

Comments
 (0)