-
Notifications
You must be signed in to change notification settings - Fork 126
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
Weak compositions #3573
Weak compositions #3573
Conversation
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.
Thanks! I have some minor comments, but overall it looks great.
|
||
# I have no idea what to call these getter functions | ||
base(W::WeakCompositions) = W.n | ||
parts(W::WeakCompositions) = W.k |
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.
Do we even need these at all?
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.
Since the fields are called .n
and .k
, I prefer getter functions. I could of course also give the fields more meaningful names, but then I still would not know what to call them :)
src/Combinatorics/EnumerativeCombinatorics/weak_compositions.jl
Outdated
Show resolved
Hide resolved
253c5e4
to
a410ed7
Compare
@test !iszero(phi[0]) | ||
@test !iszero(phi[1]) | ||
@test !iszero(phi[0]) | ||
@test compose(map(dom_tot, 1), phi[0]) == compose(phi[1], map(cod_tot, 1)) | ||
|
||
phi = interp(H0[3]) | ||
dom_tot = domain(phi) | ||
cod_tot = codomain(phi) | ||
@test !iszero(phi[0]) | ||
@test !iszero(phi[0]) | ||
@test !iszero(phi[1]) |
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.
@HechtiDerLachs I made these adjustments to the tests: The order produced by weak_compositions
is the opposite of what MultiIndicesOfDegree
did and apparently this swaps the 2nd and 3rd generator of H0
in this test. I assume that this is still correct and the comment in line 195-196 suggests it's expected, but could you have a look whether this makes sense?
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 it's fine. Thanks for the work!
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #3573 +/- ##
==========================================
+ Coverage 81.72% 81.90% +0.17%
==========================================
Files 573 574 +1
Lines 77490 79272 +1782
==========================================
+ Hits 63332 64925 +1593
- Misses 14158 14347 +189
|
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.
Once @HechtiDerLachs has approved the changes to the DoubleAndHyperComplexes, I am happy with this change. Thanks @joschmitt for working on this.
Hechti is on holidays. We can wait with merging until he is back as far as I'm concerned. |
Design question: What should a function like I would have said 'error' because asking for the number of partitions of -1 does not make sense, but apparently so far we returned 0 and this is even tested. What do you think? @ulthiel @mjrodgers (or anybody else interested in combinatorics) |
0 is almost always better in my experience. There are often applications where we want to compute a sum of such numbers and take all of the ones that “don’t make sense” as 0. It’s a pain to have to catch errors to deal with this. |
0 probably: number_of_partitions(-1) is the cardinality of the set of partitions of -1, this set is empty, so its cardinality is 0. |
Question: What is the weak in weak compositions? Isn't this just compositions? Also I have https://github.com/ulthiel/Oscar.jl/blob/ut/compositions/experimental/JuLie/compositions.jl in which I have put quite some energy (but somehow lost track of opening a PR). |
0 is an allowed summand in weak compositions. |
Sounds reasonable, thank you. |
The parts in a weak composition are allowed to be 0, in a composition they have to be positive. |
Excellent. |
6066234
to
2575cfe
Compare
@test !iszero(phi[0]) | ||
@test !iszero(phi[1]) | ||
@test !iszero(phi[0]) | ||
@test compose(map(dom_tot, 1), phi[0]) == compose(phi[1], map(cod_tot, 1)) | ||
|
||
phi = interp(H0[3]) | ||
dom_tot = domain(phi) | ||
cod_tot = codomain(phi) | ||
@test !iszero(phi[0]) | ||
@test !iszero(phi[0]) | ||
@test !iszero(phi[1]) |
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 it's fine. Thanks for the work!
The booktests failed. I think this is already fixed by #3604, but restarting CI here to make sure. Once it is finished, I will go ahead and merge (unless there are any objections). |
Thanks. |
As remarked in the context of #3147 we have three (known) implementations of weak compositions of
n
intod
parts. (To my knowledge, a weak composition is a sequence ofd
non-negative integers that sum up ton
.)This pull request introduces a type
WeakComposition
analogously toPartition
and an iterator over all weak compositions ofn
intod
parts. There is not much more functionality for weak compositions so far because I personally am happy if I can iterate them.This unifies the mentioned three implementations:
weak_compositions
is removed/replacedmonomials_of_degree
-- the user shouldn't notice anythingMultiIndicesOfDegree
is removed. Warning:MultiIndicesOfDegree(d, n)
has to be replaced byweak_compositions(n, d)
!