Skip to content
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

Merged
merged 10 commits into from
Apr 15, 2024
Merged

Weak compositions #3573

merged 10 commits into from
Apr 15, 2024

Conversation

joschmitt
Copy link
Member

As remarked in the context of #3147 we have three (known) implementations of weak compositions of n into d parts. (To my knowledge, a weak composition is a sequence of d non-negative integers that sum up to n.)

This pull request introduces a type WeakComposition analogously to Partition and an iterator over all weak compositions of n into d 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:

  • The former non-exported weak_compositions is removed/replaced
  • The new iterator is used in monomials_of_degree -- the user shouldn't notice anything
  • The non-exported MultiIndicesOfDegree is removed. Warning: MultiIndicesOfDegree(d, n) has to be replaced by weak_compositions(n, d)!

Copy link
Member

@lgoettgens lgoettgens left a 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
Copy link
Member

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?

Copy link
Member Author

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/aliases.jl Outdated Show resolved Hide resolved
src/aliases.jl Outdated Show resolved Hide resolved
@joschmitt joschmitt marked this pull request as draft April 10, 2024 14:22
Comment on lines -207 to +214
@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])
Copy link
Member Author

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?

Copy link
Collaborator

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!

Copy link

codecov bot commented Apr 10, 2024

Codecov Report

Merging #3573 (2575cfe) into master (e143c8b) will increase coverage by 0.17%.
Report is 24 commits behind head on master.
The diff coverage is 92.98%.

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     
Files Coverage Δ
experimental/DoubleAndHyperComplexes/test/ext.jl 100.00% <100.00%> (ø)
src/Combinatorics/Compositions.jl 100.00% <ø> (ø)
...mbinatorics/EnumerativeCombinatorics/partitions.jl 97.61% <100.00%> (+0.01%) ⬆️
...rc/Combinatorics/EnumerativeCombinatorics/types.jl 100.00% <100.00%> (ø)
src/Combinatorics/OrderedMultiIndex.jl 97.95% <ø> (-0.51%) ⬇️
src/InvariantTheory/types.jl 100.00% <100.00%> (ø)
src/Modules/Iterators.jl 99.06% <100.00%> (ø)
src/Modules/ModulesGraded.jl 73.35% <100.00%> (-0.03%) ⬇️
src/InvariantTheory/iterators.jl 90.59% <87.50%> (-0.75%) ⬇️
...leAndHyperComplexes/src/Objects/total_complexes.jl 75.75% <50.00%> (ø)
... and 1 more

... and 48 files with indirect coverage changes

@joschmitt joschmitt marked this pull request as ready for review April 11, 2024 07:31
Copy link
Member

@lgoettgens lgoettgens left a 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.

@joschmitt
Copy link
Member Author

Hechti is on holidays. We can wait with merging until he is back as far as I'm concerned.

@joschmitt
Copy link
Member Author

Design question: What should a function like number_of_partitions or number_of_weak_compositions do for negative input: error or return 0?

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)

@mjrodgers
Copy link
Collaborator

Design question: What should a function like number_of_partitions or number_of_weak_compositions do for negative input: error or return 0?

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.

@ulthiel
Copy link
Contributor

ulthiel commented Apr 12, 2024

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.

@ulthiel
Copy link
Contributor

ulthiel commented Apr 12, 2024

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).

@lgoettgens
Copy link
Member

Question: What is the weak in weak compositions? Isn't this just compositions?

0 is an allowed summand in weak compositions.

@joschmitt
Copy link
Member Author

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.

Sounds reasonable, thank you.

@joschmitt
Copy link
Member Author

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).

The parts in a weak composition are allowed to be 0, in a composition they have to be positive.
I'm aware of the JuLie functionality for compositions and started working locally on moving it to OSCAR. This would then also make ascending compositions out of the ascending_partitions that still float around in experimental as discussed at some point. (No promise on when this will be done.)

@ulthiel
Copy link
Contributor

ulthiel commented Apr 12, 2024

Excellent.

Comment on lines -207 to +214
@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])
Copy link
Collaborator

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!

@lgoettgens lgoettgens closed this Apr 15, 2024
@lgoettgens lgoettgens reopened this Apr 15, 2024
@lgoettgens
Copy link
Member

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).

@lgoettgens lgoettgens enabled auto-merge (squash) April 15, 2024 09:59
@joschmitt
Copy link
Member Author

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.

@lgoettgens lgoettgens merged commit 3e92192 into oscar-system:master Apr 15, 2024
55 of 56 checks passed
@joschmitt joschmitt deleted the js/compositions branch April 15, 2024 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants