-
-
Notifications
You must be signed in to change notification settings - Fork 656
Closed
Labels
Milestone
Description
Problem Description
A few things, so closely interrelated that it makes sense to collect them together:
IntegerVectors_nk
has no cardinality method, so it defaults to the slow method of iterating:IntegerVectors(200,5).cardinality()
takes something like a minute to compute70058751
.IntegerVectors_nk
has no unrank method: similarlyIntegerVectors(200,5).unrank(70000000)
takes a minute.IntegerVectors_n
andIntegerVectors_k
also have no unrank, making it slow.IntegerVectors_n
andIntegerVectors_k
always claim to beInfiniteEnumeratedSets
with cardinality+Infinity
. More appropriatelyIntegerVectors_n(0)
andIntegerVectors_k(0)
should be finite sets of cardinality1
, because they contain only the empty vector.IntegerVectors(k=0)[1]
loops forever, while it should just raiseIndexError
because the set has only one element.
Proposed Solution
- Compute cardinality by stars and bars. Then
IntegerVectors(200,5).cardinality()
will take something like a millisecond. - Use a fast method based on 1.
- Similar to the previous, but slightly more complicated. Still a fast
unrank
should be doable. - Both cases should give a
FiniteEnumeratedSets
with cardinality 1, if the parameter is zero. - This bug would be fixed by the solution to 3.
Alternatives Considered
For 5., a simpler fix (without doing 3. fully) would be just to check for the corner case.
Additional Information
1., 2. and 3. are efficiency issues, but 4. and 5. are in fact bugs.
IntegerVectors
has also other possible parameters, like max_slope
and min_slope
. This issue is not meant to change functionality in those cases (it would be more complicated), but only the base case with parameters n
and/or k
.
Related to item 1., a fast rank
was already implemented in #15609.
Is there an existing issue for this?
- I have searched the existing issues for a bug report that matches the one I want to file, without success.
mantepse and videlec