feat(Data): interleaving lists#1853
Conversation
Define interleaving of lists, both as an operation and as a relation. This will be used to define interleaving polynomials, which in turn are a central concept in the line of work that earned June Huh his 2022 Fields medal.
|
"Interleaves two lists Obviously this choice is somewhat arbitrary. But I have to say this is counter to what I would expect - intuitively I expect to start with |
|
I would support both the upstreams you mention by the way - indeed, this is a great reason to do them! Would you be willing to prepare them as PRs? |
|
https://www.symmetricfunctions.com/realRootedInterlacing.htm Is this a good source for the concept you're referring to? |
This is the convention that the literature around real-rooted polynomials uses (assuming the lists are sorted decreasingly). This is motivated by the idea that
Certainly a great reference! This is the personal website of @PerAlexandersson, whose repo I am upstreaming this from. |
|
I have opened #1854 for |
|
It looks a bit like what you have as "interleave" is called "interlace" there, unless I'm mistaken. I think for batteries the interleaving list operation should not be defined with reference to this theory in particular. I would strongly prefer, I think, a definition like this: Now, I can also see the argument for: I think this might be more similar to your definition, though you seem to want to take one element in the cons, nil (or nil, cons using your argument order) case. This last definition is the same as yours with the argument order reversed - but it has the advantage that it doesn't need a termination hint. I might characterise these as: "take from the first list, then take from the second list, then repeat - if you ever can't take from one, return the other" Alternatively I can see the argument for your argument order if "l₁.interleave l₂" is taken to mean "interleave So: at minimum, change your definition to
I think there's not a common consensus which one of these is right but I don't think yours is the one most people would intuitively reach for. |
|
Do you understand why the build fails? It looks like a pre-existing issue surfacing now because I modified the file |
|
@YaelDillies Ah - the Qq dependency will need some discussion I think. |
Yes - you have changed the first line of it, removing "-- deprecated_module: ignore", which causes that warning to no longer be ignored. But that was deliberate on the part of the PR that wrote that line: reinstate it and the warning will not cause the build to fail. |
|
Mathlib CI status (docs):
|
I am sitting with @PerAlexandersson right now and he confirms that the naming in the literature is a mess. Different experts in the area use both names for different things, and even the same expert will not use the two names consistently. We get to set a consistent naming convention here. |
Yes, this is indeed how the name is supposed to be read.
I do not care what |
Understood. I think the examples of I think this has the behaviour that you want while I think giving the more sensible outputs in your "junk values" range. What do you think? |
|
I personally want to define interlacing so that Theorem 7.2 in This book chapter is true. The empty list should interlace lists of length 0 and 1. I agree that the definition is not totally intuitive, unless you have this background. |
|
That makes sense to me. I just want to characterise interlacing in a way that fits your usage but which is also suitable for wider consumers. |
|
@wrenna-robson Yes, of course. I discussed with @YaelDillies about this a bit. So, Wagner defines two properties he calls interleaves and alternates, see my references. This is essentially splitting into two cases: both list have same length, and one list has one more element compared to the other. These two separate concepts could be useful, but for questions about polynomials with only real roots, the 'either-or' is a useful concept as well. Now, the literature here is very inconsistent and interlaces and interleaves are somewhat synonyms, but for some authors they mean slightly different things. The way I'd implement it, would be to have three named concepts:
The first two concepts are natural from computer-science perspective, while the third is natural in the world of real-rooted polynomials. All three concepts are useful, its only the naming that's the issue IMHO. |
|
Well, interleave above should, ideally, create a list which is the interleaving of two lists. The predicate should also exist (or instead of?) |
|
Mathlib CI status (docs):
|
|
The operation is useful for the characterisation and also to show that interleaving lists are sorted |
|
Mathlib CI status (docs):
|
|
After discussion with @fgdorais, we'd quite like you to take a discussion of "interleave" to Zulip - we would like to understand what other consumers of this function might want. I can see various options being sensible. |
| namespace List | ||
| variable {α : Type u} {r s : α → α → Prop} {l l₁ l₂ : List α} {a b c : α} | ||
|
|
||
| /-- Interleaves two lists `l₁` and `l₂`, starting with an element of `l₂`. |
There was a problem hiding this comment.
I would have expected it to start with the first list!
|
Mathlib CI status (docs):
|
Define interleaving of lists, both as an operation and as a relation.
This will be used to define interleaving polynomials, which in turn are a central concept in the line of work that earned June Huh his 2022 Fields medal.
Zulip
Originally PRed as leanprover-community/mathlib4#39870 but moved to batteries at the request of @ocfnash.
There are two pain points compared to the mathlib version:
@[mk_iff]attribute, meaning that I had to writeinterleaves_iffby hand.existsAndEqsimproc, meaning two subproofs became annoying to write.Both of these depend minimally on mathlib, so we could consider upstreaming them.