-
-
Notifications
You must be signed in to change notification settings - Fork 632
Add Curiel–Genitrini unranking algorithm #40318
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
base: develop
Are you sure you want to change the base?
Conversation
…sequential_form, sequential_to_canonical_form
…sion wasn't update)
src/sage/combinat/set_partition.py
Outdated
@@ -13,6 +13,9 @@ | |||
- Martin Rubey (2017-10-10): Cleanup, add crossings and nestings, add | |||
random generation. | |||
|
|||
- Anciaux Hugo, Rachid Bouhmad, Elhadj Alseiny Diallo, Do Truong Thinh Truong ( Algorithms Design : Amaury Curiel, Genitrini Antoine ). |
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.
tout le monde sous la forme "prénom nom" SVP
Documentation preview for this PR (built with commit 02a47cc; changes) is ready! 🎉 |
src/sage/combinat/set_partition.py
Outdated
sage: from sage.combinat.set_partition import compare_subsets | ||
sage: compare_subsets([1, 3], [1, 3, 4]) | ||
True | ||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
- But `{1, 4}` is not less than `{1, 3, 4}`: | ||
|
||
:: | ||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
TESTS: | ||
|
||
:: | ||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
sage: from sage.combinat.set_partition import compare_subsets | ||
sage: compare_subsets([2,5], [2,5]) | ||
True | ||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
sage: from sage.combinat.set_partition import compare_subsets | ||
sage: compare_subsets([],[]) | ||
True | ||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
sage: from sage.combinat.set_partition import compare_subsets | ||
sage: compare_subsets([], [1]) | ||
True | ||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
sage: compare_subsets([1], []) | ||
False | ||
|
||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
sage: from sage.combinat.set_partition import compare_subsets | ||
sage: compare_subsets([1, 2], [3, 4]) | ||
True | ||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
sage: compare_subsets([4,5], [2,3]) | ||
False | ||
|
||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
sage: from sage.combinat.set_partition import compare_subsets | ||
sage: compare_subsets([1], [1,2]) | ||
True | ||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
sage: compare_subsets([1,2], [1]) | ||
False | ||
|
||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
sage: from sage.combinat.set_partition import compare_subsets | ||
sage: compare_subsets([1,3,5], [1,3]) | ||
False | ||
sage: from sage.combinat.set_partition import compare_subsets |
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.
sage: from sage.combinat.set_partition import compare_subsets |
src/sage/combinat/set_partition.py
Outdated
sage: from sage.combinat.set_partition import compare_subsets | ||
sage: compare_subsets([1, 3], [1, 3, 5]) | ||
True | ||
|
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.
src/sage/combinat/set_partition.py
Outdated
|
||
:: | ||
|
||
sage: from sage.combinat.set_partition import SetPartition, compare_set_partitions |
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.
sage: from sage.combinat.set_partition import SetPartition, compare_set_partitions |
src/sage/combinat/set_partition.py
Outdated
|
||
UNIT TESTS: | ||
|
||
:: |
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.
UNIT TESTS: | |
:: |
src/sage/combinat/set_partition.py
Outdated
Compare a sequence of set partitions to ensure each partition is less than or equal to the next: | ||
|
||
:: | ||
|
||
sage: from sage.combinat.set_partition import SetPartitions, compare_set_partitions |
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.
Compare a sequence of set partitions to ensure each partition is less than or equal to the next: | |
:: | |
sage: from sage.combinat.set_partition import SetPartitions, compare_set_partitions | |
Compare a sequence of set partitions to ensure each partition is less than or equal to the next:: | |
sage: from sage.combinat.set_partition import compare_set_partitions |
src/sage/combinat/set_partition.py
Outdated
|
||
:: |
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.
:: |
src/sage/combinat/set_partition.py
Outdated
: | ||
sage: from sage.combinat.set_partition import SetPartition, compare_set_partitions |
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.
: | |
sage: from sage.combinat.set_partition import SetPartition, compare_set_partitions |
src/sage/combinat/set_partition.py
Outdated
We create a list of set partitions of the set {1, 2, 3, 4, 5} into 3 parts, sort them, and check that each partition is lexicographically less than or equal to the next. This confirms that `compare_set_partitions` correctly identifies the lexicographic ordering among a sorted list of set partitions: | ||
|
||
:: | ||
|
||
sage: from sage.combinat.set_partition import SetPartitions, compare_set_partitions |
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.
We create a list of set partitions of the set {1, 2, 3, 4, 5} into 3 parts, sort them, and check that each partition is lexicographically less than or equal to the next. This confirms that `compare_set_partitions` correctly identifies the lexicographic ordering among a sorted list of set partitions: | |
:: | |
sage: from sage.combinat.set_partition import SetPartitions, compare_set_partitions | |
We create a list of set partitions of the set {1, 2, 3, 4, 5} | |
into 3 parts, sort them, and check that each partition is | |
lexicographically less than or equal to the next. This | |
confirms that `compare_set_partitions` correctly identifies the | |
lexicographic ordering among a sorted list of set partitions:: |
src/sage/combinat/set_partition.py
Outdated
sage: j = SetPartition([ [1] ]) | ||
sage: compare_set_partitions(i, j) | ||
True | ||
|
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.
src/sage/combinat/set_partition.py
Outdated
|
||
UNITS TESTS: | ||
|
||
assert unranking(0, 0, 0) == [[]] | ||
|
||
assert unranking(1, 1, 0) == [[1]] | ||
|
||
assert unranking(3, 1, 0) == [[1, 2, 3]] | ||
|
||
assert unranking(3, 3, 0) == [[1], [2], [3]] | ||
|
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.
UNITS TESTS: | |
assert unranking(0, 0, 0) == [[]] | |
assert unranking(1, 1, 0) == [[1]] | |
assert unranking(3, 1, 0) == [[1, 2, 3]] | |
assert unranking(3, 3, 0) == [[1], [2], [3]] | |
sage: unranking(0, 0, 0) == [[]] | |
True | |
sage: unranking(1, 1, 0) == [[1]] | |
True | |
sage: unranking(3, 1, 0) == [[1, 2, 3]] | |
True | |
sage: unranking(3, 3, 0) == [[1], [2], [3]] | |
True |
Why do you introduce |
This function was part of the project. Since it has potential future use, I decided to keep it rather than remove it. |
Did you intend to close the pull request ? If not, you can re-open. |
Thanks for the help. I'll do this |
Co-authored-by: Martin Rubey <axiomize@yahoo.de>
from collections import defaultdict | ||
|
||
@cached_method | ||
def stilde(n: int, k: int, d: int) -> int: |
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.
you need to add the import of ZZ on top of the file ; note also that your type annotations are not correct, as sage Integers are not Python ints.
Commits:
-Add the function "compare_subsets"
-Add the function "compare_set_partitions"
-Add Curiel-Genitrini unranking algorithm
This PR introduces the unranking algorithm for lexicographic order.