Skip to content

[Merged by Bors] - feat(SimpleGraph): sub-walks - #26655

Closed
Rida-Hamadani wants to merge 10 commits into
leanprover-community:masterfrom
Rida-Hamadani:subwalk
Closed

Rida-Hamadani wants to merge 10 commits into
leanprover-community:masterfrom
Rida-Hamadani:subwalk

Conversation

@Rida-Hamadani

@Rida-Hamadani Rida-Hamadani commented Jul 3, 2025 •

Copy link
Copy Markdown
Collaborator

defines (contiguous) subwalks and provides lemmas about them.

Co-authored-by: Kyle Miller [email protected]
Co-authored-by: Vlad Tsyrklevich [email protected]


Open in Gitpod

@github-actions github-actions Bot added the t-combinatorics Combinatorics label Jul 3, 2025
@github-actions

github-actions Bot commented Jul 3, 2025 •

Copy link
Copy Markdown

PR summary df7b8fa466

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ IsSubwalk
+ IsSubwalk.cons
+ IsSubwalk.trans
+ drop_support_eq_support_drop_min
+ drop_zero
+ infix_antisymm
+ infix_singleton_iff
+ isPath_of_isSubwalk
+ isSubwalk_antisymm
+ isSubwalk_cons
+ isSubwalk_iff_support_isInfix
+ isSubwalk_nil_iff
+ isSubwalk_of_append_left
+ isSubwalk_of_append_right
+ isSubwalk_rfl
+ isTrail_of_isSubwalk
+ length_le_of_isSubwalk
+ nil_isSubwalk
+ nil_isSubwalk_iff_exists
+ prefix_append_drop
+ singleton_infix_iff
+ singleton_infix_singleton_iff
+ support_append_eq_support_dropLast_append
+ take_support_eq_support_take_succ

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.


Increase in tech debt: (relative, absolute) = (1.00, 0.25)
Current number Change Type
4 1 large files

Current commit 141cf1ba15
Reference commit df7b8fa466

You can run this locally as

./scripts/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@kmill kmill left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent some time trying to prove this by induction, and got to here.

theorem isSubwalk_iff_support_isInfix {u₁ v₁ u₂ v₂ : V} (p : G.Walk u₁ v₁) (q : G.Walk u₂ v₂) :
    p.IsSubwalk q ↔ p.support <:+: q.support := by
  induction q with
  | nil =>
    cases p with
    | nil => simp [isSubwalk_nil_iff, eq_comm]
    | cons h p =>
      suffices ∀ (w) (hu : w = u₁) (hv : w = v₁), ¬cons h p = nil.copy hu hv by
        simp [isSubwalk_nil_iff, List.infix_singleton_iff, this]
      rintro _ rfl rfl
      simp
  | cons h q ih =>
    cases p with
    | nil =>
      simp only [support_nil, List.singleton_infix_iff] at ih
      simp [List.singleton_infix_iff, ← ih, nil_isSubwalk_cons_iff]
    | cons h p =>
      rw [support_cons] at ih
      rw [support_cons, support_cons, List.infix_cons_iff, ← ih]
      simp
      sorry

Maybe it's worth contributing these:

lemma List.singleton_infix_iff {α : Type*} (x : α) (xs : List α) :
    [x] <:+: xs ↔ x ∈ xs := by
  rw [List.mem_iff_append, List.IsInfix]
  congr! 4
  simp [eq_comm]

@[simp]
lemma List.singleton_infix_singleton_iff {α : Type*} {x y : α} :
    [x] <:+: [y] ↔ x = y := by
  constructor
  · rintro ⟨_ | _, bs, h⟩ <;> simp_all
  · rintro rfl; rfl

lemma List.infix_singleton_iff {α : Type*} (xs : List α) (x : α) :
    xs <:+: [x] ↔ xs = [] ∨ xs = [x] := by
  match xs with
  | [] => simp
  | [_] => simp [List.singleton_infix_singleton_iff]
  | _ :: _ :: _ =>
    constructor
    · rintro ⟨_ | _, _, h⟩ <;> simp at h
    · simp

@vlad902

vlad902 commented Jul 3, 2025

Copy link
Copy Markdown
Collaborator

This is what I had worked up locally: vlad902@4767466

Note that the proof of equivalence isSubwalk_iff_append_append is much shorter, not sure if that's because of the direction I chose to prove it in. Please take any parts of it that you find useful.

@Rida-Hamadani
Rida-Hamadani requested a review from kmill July 5, 2025 09:30

@jt496 jt496 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks great to me! My only real question is would it be better to call this IsInfixwalk (or maybe just Infixwalk) so it aligns with the naming in List
and makes it easer to introduce not-necessarily-contiguous subwalks at a later date if we want them.

(I've been playing around with something like this based on List.Sublist https://github.com/jt496/mathlib4/blob/walks/Mathlib/Combinatorics/SimpleGraph/Subwalk.lean)

Comment thread Mathlib/Data/List/Infix.lean Resolved
@Rida-Hamadani
Rida-Hamadani removed the request for review from kmill July 23, 2025 17:36

@b-mehta b-mehta left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thanks!

@b-mehta

b-mehta commented Aug 18, 2025

Copy link
Copy Markdown
Contributor

bors merge

@ghost ghost added the ready-to-merge This PR has been sent to bors. label Aug 18, 2025
mathlib-bors Bot pushed a commit that referenced this pull request Aug 19, 2025
defines (contiguous) subwalks and provides lemmas about them.

Co-authored-by: Kyle Miller <[email protected]>
Co-authored-by: Vlad Tsyrklevich <[email protected]>
@mathlib-bors

mathlib-bors Bot commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

Build failed (retrying...):

@bryangingechen

bryangingechen commented Aug 19, 2025 •

Copy link
Copy Markdown
Contributor

Please merge master, fix the linter warning about a file being too long, and then re-bors, thanks!

bors r-
bors d+

@mathlib-bors

mathlib-bors Bot commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

✌️ Rida-Hamadani can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@mathlib-bors

mathlib-bors Bot commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

Canceled.

@ghost ghost added delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). and removed ready-to-merge This PR has been sent to bors. labels Aug 19, 2025
@ghost ghost removed the delegated This pull request has been delegated to the PR author (or occasionally another non-maintainer). label Aug 19, 2025
@Rida-Hamadani

Copy link
Copy Markdown
Collaborator Author

bors r+

mathlib-bors Bot pushed a commit that referenced this pull request Aug 19, 2025
defines (contiguous) subwalks and provides lemmas about them.

Co-authored-by: Kyle Miller <[email protected]>
Co-authored-by: Vlad Tsyrklevich <[email protected]>
@mathlib-bors

mathlib-bors Bot commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title feat(SimpleGraph): sub-walks [Merged by Bors] - feat(SimpleGraph): sub-walks Aug 19, 2025
@mathlib-bors mathlib-bors Bot closed this Aug 19, 2025
pfaffelh pushed a commit to pfaffelh/mathlib4 that referenced this pull request Aug 20, 2025
defines (contiguous) subwalks and provides lemmas about them.

Co-authored-by: Kyle Miller <[email protected]>
Co-authored-by: Vlad Tsyrklevich <[email protected]>
Paul-Lez pushed a commit to Paul-Lez/mathlib4 that referenced this pull request Aug 23, 2025
defines (contiguous) subwalks and provides lemmas about them.

Co-authored-by: Kyle Miller <[email protected]>
Co-authored-by: Vlad Tsyrklevich <[email protected]>
pechersky pushed a commit to pechersky/mathlib4 that referenced this pull request Aug 25, 2025
defines (contiguous) subwalks and provides lemmas about them.

Co-authored-by: Kyle Miller <[email protected]>
Co-authored-by: Vlad Tsyrklevich <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-combinatorics Combinatorics

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants