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
Partitions parts_in vs WeightedIntegerVectors #31319
Comments
Author: Tom Grubb |
comment:2
Thanks for opening this ticket and suggesting an approach. |
This comment has been minimized.
This comment has been minimized.
New commits:
|
Changed author from Tom Grubb to Frédéric Chapoton, Tom Grubb |
Branch: u/chapoton/31319 |
Commit: |
comment:6
You can make this even faster by using the from sage.combinat.integer_vector_weighted import iterator_fast
sorted_parts = sorted(parts, reverse=True)
for vec in iterator_fast(n, sorted_parts):
yield sum([pi] * multi for pi, multi in zip(sorted_parts, vec), [] This should be the fastest way to do things. This probably can be easily modified to work for k-regular/restricted partitions as well, but that can be a separate ticket. |
Branch pushed to git repo; I updated commit sha1. New commits:
|
comment:8
Thanks, Travis. I made the suggested changes. |
comment:9
Thank you. LGTM. |
Reviewer: Travis Scrimshaw |
Changed branch from u/chapoton/31319 to |
Creating the integer partitions of an integer
N
with parts restricted to a listL
takes much longer than creating the weighted integer vectors ofN
with weights inL
. In principle one should be able to translate between these two constructions, so perhaps it would be better to computePartitions(N, parts_in=L)
by callingWeightedIntegerVectors(N, L)
and then transferring the results accordingly? Below are two examples where this manifests.This code sees how far Sage can compute in 100 seconds with respect to both functions:
The result of the first block is 321269, whereas the second is 41686 (for me).
Another example: this code computes the Frobenius number of
[1000, 1001]
(https://en.wikipedia.org/wiki/Coin_problem) by starting at the naive upper bound and working downwards:The first code block runs in 0.83 seconds whereas the second takes 249.96 seconds to evaluate (for me).
A very basic attempt at a fix for this would be something like
Of course this would have to be adapted into the Partitions class, but it seems like that should be no issue as long as the
parts_in
flag is taken into account. Even this crude fix gives me much better performance on the two tasks above.CC: @slel @videlec @seblabbe
Component: number theory
Keywords: Partitions
Author: Frédéric Chapoton, Tom Grubb
Branch/Commit:
ea494b1
Reviewer: Travis Scrimshaw
Issue created by migration from https://trac.sagemath.org/ticket/31319
The text was updated successfully, but these errors were encountered: