-
Notifications
You must be signed in to change notification settings - Fork 182
feat(Data): Results about RelatesInSteps with bounds on the reachable set #779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
crei
wants to merge
10
commits into
leanprover:main
Choose a base branch
from
crei:relates_in_steps_bounded
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+172
−20
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cce51a6
Results about reachability with repeated visits.
crei c462faa
Use isChain.
crei dea453a
Merge remote-tracking branch 'origin/main' into relates_in_steps_bounded
crei 877f6d5
Extract a lemma and clean up.
crei ba0c2b5
Undo some golfing.
crei cd5c63f
Undo some more golfing.
crei c4c92c1
Extract results related to List.isChain into their own file.
crei 9ec5246
Merge remote-tracking branch 'origin/main' into relates_in_steps_bounded
crei af70d3b
Minor tweaks.
crei f03aca6
Remove simp.
crei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /- | ||
| Copyright (c) 2026 Christian Reitwiessner. All rights reserved. | ||
| Released under Apache 2.0 license as described in the file LICENSE. | ||
| Authors: Christian Reitwiessner | ||
| -/ | ||
|
|
||
| module | ||
|
|
||
| public import Cslib.Init | ||
| public import Mathlib.Data.List.Chain | ||
| public import Mathlib.Data.List.Nodup | ||
|
|
||
| /-! # Chains with a designated start and end | ||
|
|
||
| This file defines `List.IsChainFromTo`, a variant of `List.IsChain` that also fixes the first and | ||
| last element of the chain. | ||
|
|
||
| The lemma `List.IsChainFromTo.exists_length_lt_of_not_nodup` shows that a chain with duplicates can | ||
| always be shortened. | ||
| -/ | ||
|
|
||
| @[expose] public section | ||
|
|
||
| variable {α : Type*} {r : α → α → Prop} {chain : List α} {a b : α} | ||
|
|
||
| /-- A "chain from to" is a list of elements where adjacent elements relate to each other | ||
| (cf. `List.IsChain`) and start and end with specific elements. -/ | ||
| structure List.IsChainFromTo {α : Type*} (r : α → α → Prop) (chain : List α) (a b : α) : Prop where | ||
| isChain : chain.IsChain r | ||
| ne_nil : chain ≠ [] | ||
| head_eq : chain.head ne_nil = a | ||
| getLast_eq : chain.getLast ne_nil = b | ||
|
|
||
| /-- Restatement of `head_eq`, but tagged with grind. -/ | ||
| @[grind →] | ||
| lemma List.IsChainFromTo_head_eq (hc : chain.IsChainFromTo r a b) : | ||
| chain.head hc.ne_nil = a := | ||
| hc.head_eq | ||
|
|
||
| /-- Restatement of `getLast_eq`, but tagged with grind. -/ | ||
| @[grind →] | ||
| lemma List.IsChainFromTo_getLast_eq (hc : chain.IsChainFromTo r a b) : | ||
| chain.getLast hc.ne_nil = b := | ||
| hc.getLast_eq | ||
|
|
||
| @[simp, grind ←] | ||
| lemma List.IsChainFromTo.singleton {a : α} : List.IsChainFromTo r [a] a a := | ||
| ⟨List.IsChain.singleton a, by simp, rfl, rfl⟩ | ||
|
|
||
| /-- If there is an `r`-chain from `a` to `b` with duplicates, then there is a shorter `r`-chain | ||
| from `a` to `b` (the one that skips the part between the duplicates). | ||
| Note that applying this method iteratively does not necessarily lead to the shortest `r`-chain | ||
| from `a` to `b`, since we always keep the initial and final segment. -/ | ||
| lemma List.IsChainFromTo.exists_length_lt_of_not_nodup | ||
| (hc : chain.IsChainFromTo r a b) | ||
| (h_dup : ¬ chain.Nodup) : | ||
| ∃ chain' : List α, chain'.IsChainFromTo r a b ∧ chain'.length < chain.length := by | ||
| rw [nodup_iff_getElem?_ne_getElem?] at h_dup | ||
| push Not at h_dup | ||
| obtain ⟨i, j, h_ij, h_lt, h_eq⟩ := h_dup | ||
| use chain.take i ++ chain.drop j | ||
| refine ⟨⟨?_, by simp; omega, by grind, by grind⟩, by grind⟩ | ||
| · refine (hc.isChain.take _).append (hc.isChain.drop _) ?_ | ||
| intro x hx y hy | ||
| rw [List.head?_drop] at hy | ||
| have := hc.isChain.getElem (i := i - 1) (by omega) | ||
| grind |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I think the last part of the statement would have been clearer if you explicitly require the set being finite for the cardinality comparison. But that's just me and I don't insist on it.
More seriously, it seems to me that the real mathematical content of this theorem is that there is a shortest path from
atobin which there is no duplication of elements. I think you should try to phrase and prove that theorem in terms ofList.IsChainand then derive this theorem as a corollary.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both versions (with finiteness and Finset.card / just .encard) have their advantages and disadvantages. I like the current version better because it can be used both for finite and infinite sets and is "sharp" in both versions.
About the "IsChain-only" theorem: I guess I wanted to limit myself to results that directly relate to RelatesInSteps, but you are right, this is the cleaner approach, I'll try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if it makes sense to introduce a structure here:
Additionally, this is now much more general and should probably move to mathlib (I'm a bit surprised that it is not there yet, but maybe I didn't find it) - should I just create a new file for that? Plus, this is probably relevant for the emerging graph theory section as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our usual procedure for Mathlib upstreaming is to leave them in the same file as any other proof, sometimes leaving a comment or in a section if it's several proofs. (If a comment is prefaced with
TODOan issue will automatically open with that as its title)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think
List.IsChainFromTois a good idea. I like putting the new definitions and theorems aboutListin a new file underCslib/Foundations/Data/List/. The file can be removed after the mathlib upstreaming happens. Personally I find this approach more modular.