Skip to content

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

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from

Conversation

hugo-a-04
Copy link

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.

@@ -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 ).
Copy link
Contributor

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

Copy link

github-actions bot commented Jun 27, 2025

Documentation preview for this PR (built with commit 02a47cc; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

- But `{1, 4}` is not less than `{1, 3, 4}`:

::
sage: from sage.combinat.set_partition import compare_subsets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

TESTS:

::
sage: from sage.combinat.set_partition import compare_subsets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

sage: from sage.combinat.set_partition import compare_subsets
sage: compare_subsets([],[])
True
sage: from sage.combinat.set_partition import compare_subsets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

sage: from sage.combinat.set_partition import compare_subsets
sage: compare_subsets([], [1])
True
sage: from sage.combinat.set_partition import compare_subsets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

sage: compare_subsets([1], [])
False

sage: from sage.combinat.set_partition import compare_subsets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

sage: compare_subsets([4,5], [2,3])
False

sage: from sage.combinat.set_partition import compare_subsets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

sage: compare_subsets([1,2], [1])
False

sage: from sage.combinat.set_partition import compare_subsets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import compare_subsets

sage: from sage.combinat.set_partition import compare_subsets
sage: compare_subsets([1, 3], [1, 3, 5])
True

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change


::

sage: from sage.combinat.set_partition import SetPartition, compare_set_partitions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sage: from sage.combinat.set_partition import SetPartition, compare_set_partitions

Comment on lines 3475 to 3478

UNIT TESTS:

::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
UNIT TESTS:
::

Comment on lines 3439 to 3443
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines 3448 to 3449

::
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
::

Comment on lines 3457 to 3458
:
sage: from sage.combinat.set_partition import SetPartition, compare_set_partitions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
:
sage: from sage.combinat.set_partition import SetPartition, compare_set_partitions

Comment on lines 3466 to 3470
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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::

sage: j = SetPartition([ [1] ])
sage: compare_set_partitions(i, j)
True

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Comment on lines 3554 to 3564

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]]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@mantepse
Copy link
Contributor

Why do you introduce compare_subsets, it is not used anywhere except in the tests, is it?

@hugo-a-04
Copy link
Author

Why do you introduce compare_subsets, it is not used anywhere except in the tests, is it?

This function was part of the project. Since it has potential future use, I decided to keep it rather than remove it.

@fchapoton
Copy link
Contributor

Did you intend to close the pull request ? If not, you can re-open.

@hugo-a-04
Copy link
Author

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:
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants