Skip to content

Commit 4326d0d

Browse files
author
Release Manager
committed
gh-38795: switch to nauty for generating posets
as there is now a direct method in `nauty` and we have added the interface previously ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #38795 Reported by: Frédéric Chapoton Reviewer(s): David Coudert, Frédéric Chapoton, Martin Rubey
2 parents 17791d4 + 17f72fa commit 4326d0d

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

build/pkgs/configure/checksums.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
tarball=configure-VERSION.tar.gz
2-
sha1=140d921780212198287a0d626b8c9655d4408f7a
3-
sha256=4f82ec8bdb67c4dffd43daddd5160e8f9c624f6a5cf16c4128bfab2e5ddca459
2+
sha1=2b8c8181575563ae16afca012c2188b31f3e8bb7
3+
sha256=77d20639b03b1c125d6ccf88ebb2cb0202b32059dff4bf38ca05db229913f639
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2b4fe39e420df022d34a67fbc820252618e15f83
1+
a1d9c1e13576bf777e95ba50d51d81ee09d2a0c9

src/sage/combinat/posets/posets.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8884,11 +8884,11 @@ class FinitePosets_n(UniqueRepresentation, Parent):
88848884
sage: P.cardinality()
88858885
5
88868886
sage: for p in P: print(p.cover_relations())
8887-
[]
8888-
[[1, 2]]
8887+
[[1, 2], [0, 2]]
88898888
[[0, 1], [0, 2]]
8889+
[[0, 2]]
88908890
[[0, 1], [1, 2]]
8891-
[[1, 2], [0, 2]]
8891+
[]
88928892
"""
88938893

88948894
def __init__(self, n) -> None:
@@ -8930,27 +8930,40 @@ def __contains__(self, P) -> bool:
89308930
return P in FinitePosets() and P.cardinality() == self._n
89318931

89328932
def __iter__(self):
8933-
"""
8933+
r"""
89348934
Return an iterator of representatives of the isomorphism classes
89358935
of finite posets of a given size.
89368936
89378937
.. NOTE::
89388938
8939-
This uses the DiGraph iterator as a backend to construct
8940-
transitively-reduced, acyclic digraphs.
8939+
If the size `n\leq 16`, this uses an iterator from
8940+
``nauty`` as a backend to construct only transitively-reduced,
8941+
acyclic digraphs. Otherwise it uses a slow naive iterator,
8942+
as the ``nauty`` iterator is not available.
89418943
89428944
EXAMPLES::
89438945
89448946
sage: P = Posets(2)
89458947
sage: list(P)
89468948
[Finite poset containing 2 elements, Finite poset containing 2 elements]
8949+
8950+
TESTS::
8951+
8952+
sage: it = iter(Posets(17))
8953+
sage: next(it)
8954+
Finite poset containing 17 elements
89478955
"""
8948-
from sage.graphs.digraph_generators import DiGraphGenerators
8949-
for dig in DiGraphGenerators()(self._n, is_poset):
8956+
if self._n <= 16:
8957+
it = digraphs.nauty_posetg(f"{self._n} o")
8958+
else:
8959+
it = digraphs(self._n, is_poset)
8960+
8961+
for dig in it:
89508962
# We need to relabel the digraph since range(self._n) must be a linear
89518963
# extension. Too bad we need to compute this again. TODO: Fix this.
8952-
label_dict = dict(zip(dig.topological_sort(), range(dig.order())))
8953-
yield FinitePoset(dig.relabel(label_dict, inplace=False))
8964+
label_dict = dict(zip(dig.topological_sort(), range(self._n)))
8965+
dig.relabel(label_dict, inplace=True)
8966+
yield FinitePoset(dig)
89548967

89558968
def cardinality(self, from_iterator=False):
89568969
r"""

src/sage/combinat/tutorial.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -844,15 +844,15 @@
844844
845845
Partial orders on a set of `8` elements, up to isomorphism::
846846
847-
sage: C = Posets(8); C
848-
Posets containing 8 elements
847+
sage: C = Posets(7); C
848+
Posets containing 7 elements
849849
sage: C.cardinality()
850-
16999
850+
2045
851851
852852
::
853853
854854
sage: C.unrank(20).plot()
855-
Graphics object consisting of 20 graphics primitives
855+
Graphics object consisting of ... graphics primitives
856856
857857
.. image:: ../../media/a_poset.png
858858

src/sage/databases/findstat.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4002,16 +4002,17 @@ def _finite_lattices(n):
40024002
TESTS::
40034003
40044004
sage: from sage.databases.findstat import _finite_lattices
4005-
sage: [L.cover_relations() for L in _finite_lattices(4)]
4006-
[[['bottom', 0], ['bottom', 1], [0, 'top'], [1, 'top']],
4007-
[['bottom', 0], [0, 1], [1, 'top']]]
4005+
sage: sorted((L.cover_relations() for L in _finite_lattices(4)),
4006+
....: key=len)
4007+
[[['bottom', 0], [0, 1], [1, 'top']],
4008+
[['bottom', 0], ['bottom', 1], [0, 'top'], [1, 'top']]]
40084009
"""
40094010
if n <= 2:
40104011
for P in Posets(n):
40114012
if P.is_lattice():
40124013
yield LatticePoset(P)
40134014
else:
4014-
for P in Posets(n-2):
4015+
for P in Posets(n - 2):
40154016
Q = P.with_bounds()
40164017
if Q.is_lattice():
40174018
yield LatticePoset(Q)

0 commit comments

Comments
 (0)