Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'u/mantepse/make_linearextensions_an_iterator' of git://…
Browse files Browse the repository at this point in the history
…trac.sagemath.org/sage into t/25865/fast_iterator_for_set_partitions_with_given_block_sizes
  • Loading branch information
mantepse committed Jul 17, 2018
2 parents 84ba2c8 + f1705d8 commit 0765e7f
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 181 deletions.
4 changes: 2 additions & 2 deletions src/sage/combinat/interval_posets.py
Expand Up @@ -1920,8 +1920,8 @@ def linear_extensions(self):
sage: list(ip.linear_extensions())
[[3, 1, 2], [1, 3, 2]]
sage: ip = TamariIntervalPoset(4,[(1,2),(2,3),(4,3)])
sage: list(ip.linear_extensions())
[[4, 1, 2, 3], [1, 4, 2, 3], [1, 2, 4, 3]]
sage: sorted(ip.linear_extensions())
[[1, 2, 4, 3], [1, 4, 2, 3], [4, 1, 2, 3]]
"""
for ext in self._poset.linear_extensions():
yield Permutation(ext)
Expand Down
43 changes: 22 additions & 21 deletions src/sage/combinat/permutation.py
Expand Up @@ -3972,7 +3972,7 @@ def right_permutohedron_interval(self, other):
ValueError: len([2, 4, 1, 3]) and len([2, 1, 4, 5, 3]) must be equal
"""
P = Permutations()
return [P(p) for p in self.right_permutohedron_interval_iterator(other)]
return sorted(P(p) for p in self.right_permutohedron_interval_iterator(other))

def permutohedron_join(self, other, side="right"):
r"""
Expand Down Expand Up @@ -5185,7 +5185,7 @@ class Permutations(UniqueRepresentation, Parent):
sage: p = Permutations(descents=([1], 4)); p
Standard permutations of 4 with descents [1]
sage: p.list()
sage: sorted(p)
[[1, 3, 2, 4], [1, 4, 2, 3], [2, 3, 1, 4], [2, 4, 1, 3], [3, 4, 1, 2]]
::
Expand All @@ -5206,14 +5206,14 @@ class Permutations(UniqueRepresentation, Parent):
sage: p = Permutations(recoils_finer=[2,1]); p
Standard permutations whose recoils composition is finer than [2, 1]
sage: p.list()
sage: sorted(p)
[[1, 2, 3], [1, 3, 2], [3, 1, 2]]
::
sage: p = Permutations(recoils_fatter=[2,1]); p
Standard permutations whose recoils composition is fatter than [2, 1]
sage: p.list()
sage: sorted(p)
[[1, 3, 2], [3, 1, 2], [3, 2, 1]]
::
Expand Down Expand Up @@ -7364,22 +7364,22 @@ def __iter__(self):
EXAMPLES::
sage: Permutations(descents=([2,0],5)).list()
sage: sorted(Permutations(descents=([2,0],5)))
[[2, 1, 4, 3, 5],
[2, 1, 5, 3, 4],
[3, 1, 4, 2, 5],
[3, 1, 5, 2, 4],
[4, 1, 3, 2, 5],
[5, 1, 3, 2, 4],
[4, 1, 5, 2, 3],
[5, 1, 4, 2, 3],
[3, 2, 4, 1, 5],
[3, 2, 5, 1, 4],
[4, 1, 3, 2, 5],
[4, 1, 5, 2, 3],
[4, 2, 3, 1, 5],
[5, 2, 3, 1, 4],
[4, 2, 5, 1, 3],
[5, 2, 4, 1, 3],
[4, 3, 5, 1, 2],
[5, 1, 3, 2, 4],
[5, 1, 4, 2, 3],
[5, 2, 3, 1, 4],
[5, 2, 4, 1, 3],
[5, 3, 4, 1, 2]]
"""
return iter( descents_composition_list(Composition(descents=(self.d,self.n))) )
Expand All @@ -7392,23 +7392,24 @@ def descents_composition_list(dc):
EXAMPLES::
sage: import sage.combinat.permutation as permutation
sage: permutation.descents_composition_list([1,2,2])
sage: sorted(permutation.descents_composition_list([1,2,2]))
[[2, 1, 4, 3, 5],
[2, 1, 5, 3, 4],
[3, 1, 4, 2, 5],
[3, 1, 5, 2, 4],
[4, 1, 3, 2, 5],
[5, 1, 3, 2, 4],
[4, 1, 5, 2, 3],
[5, 1, 4, 2, 3],
[3, 2, 4, 1, 5],
[3, 2, 5, 1, 4],
[4, 1, 3, 2, 5],
[4, 1, 5, 2, 3],
[4, 2, 3, 1, 5],
[5, 2, 3, 1, 4],
[4, 2, 5, 1, 3],
[5, 2, 4, 1, 3],
[4, 3, 5, 1, 2],
[5, 1, 3, 2, 4],
[5, 1, 4, 2, 3],
[5, 2, 3, 1, 4],
[5, 2, 4, 1, 3],
[5, 3, 4, 1, 2]]
"""
return [p.inverse() for p in StandardPermutations_recoils(dc)]

Expand Down Expand Up @@ -7503,7 +7504,7 @@ def __iter__(self):
EXAMPLES::
sage: Permutations(recoils_finer=[2,2]).list()
sage: sorted(Permutations(recoils_finer=[2,2]))
[[1, 2, 3, 4],
[1, 3, 2, 4],
[1, 3, 4, 2],
Expand Down Expand Up @@ -7570,7 +7571,7 @@ def __iter__(self):
EXAMPLES::
sage: Permutations(recoils_fatter=[2,2]).list()
sage: sorted(Permutations(recoils_fatter=[2,2]))
[[1, 3, 2, 4],
[1, 3, 4, 2],
[1, 4, 3, 2],
Expand Down Expand Up @@ -7644,7 +7645,7 @@ def __iter__(self):
EXAMPLES::
sage: Permutations(recoils=[2,2]).list()
sage: sorted(Permutations(recoils=[2,2]))
[[1, 3, 2, 4], [1, 3, 4, 2], [3, 1, 2, 4], [3, 1, 4, 2], [3, 4, 1, 2]]
"""
recoils = self.recoils
Expand Down
15 changes: 8 additions & 7 deletions src/sage/combinat/posets/linear_extensions.py
Expand Up @@ -268,7 +268,7 @@ def tau(self, i):
[1, 2, 3, 4]
sage: l.tau(1)
[2, 1, 3, 4]
sage: for p in L:
sage: for p in sorted(L):
....: for i in range(1,4):
....: print("{} {} {}".format(i, p, p.tau(i)))
1 [1, 2, 3, 4] [2, 1, 3, 4]
Expand Down Expand Up @@ -423,7 +423,7 @@ class LinearExtensionsOfPoset(UniqueRepresentation, Parent):
The set of all linear extensions of Finite poset containing 4 elements with distinguished linear extension
sage: L.cardinality()
5
sage: L.list()
sage: sorted(L)
[[1, 2, 3, 4], [1, 2, 4, 3], [1, 4, 2, 3], [2, 1, 3, 4], [2, 1, 4, 3]]
sage: L.an_element()
[1, 2, 3, 4]
Expand Down Expand Up @@ -601,7 +601,7 @@ def __iter__(self):
sage: rels = [[1,3],[1,4],[2,3]]
sage: P = Poset((elms, rels), linear_extension=True)
sage: L = P.linear_extensions()
sage: list(L)
sage: sorted(L)
[[1, 2, 3, 4], [1, 2, 4, 3], [1, 4, 2, 3], [2, 1, 3, 4], [2, 1, 4, 3]]
"""
vertex_to_element = self._poset._vertex_to_element
Expand Down Expand Up @@ -717,18 +717,19 @@ def markov_chain_digraph(self, action = 'promotion', labeling = 'identity'):
sage: G = L.markov_chain_digraph(labeling = 'source'); G
Looped multi-digraph on 5 vertices
"""
d = dict([x,dict([y,[]] for y in self)] for x in self)
L = sorted(self.list())
d = dict([x,dict([y,[]] for y in L)] for x in L)
if action == 'promotion':
R = list(range(self.poset().cardinality()))
else:
R = list(range(self.poset().cardinality() - 1))
if labeling == 'source':
for x in self:
for x in L:
for i in R:
child = getattr(x, action)(i+1)
d[x][child]+=[self.poset().unwrap(x[i])]
else:
for x in self:
for x in L:
for i in R:
child = getattr(x, action)(i+1)
d[x][child]+=[i+1]
Expand Down Expand Up @@ -789,7 +790,7 @@ def markov_chain_transition_matrix(self, action = 'promotion', labeling = 'ident
"""
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.matrix.constructor import matrix
L = self.list()
L = sorted(self.list())
n = self.poset().cardinality()
R = PolynomialRing(QQ, 'x', n)
x = [R.gen(i) for i in range(n)]
Expand Down
14 changes: 7 additions & 7 deletions src/sage/combinat/posets/posets.py
Expand Up @@ -1573,7 +1573,7 @@ def linear_extensions(self, facade=False):
[1, 2, 3, 4, 6, 12]
sage: L.cardinality()
5
sage: L.list()
sage: sorted(L)
[[1, 2, 3, 4, 6, 12],
[1, 2, 3, 6, 4, 12],
[1, 2, 4, 3, 6, 12],
Expand All @@ -1597,7 +1597,7 @@ def linear_extensions(self, facade=False):
In Sage <= 4.8, this function used to return a plain list
of lists. To recover the previous functionality, please use::
sage: L = list(P.linear_extensions(facade=True)); L
sage: L = sorted(P.linear_extensions(facade=True)); L
[[1, 2, 3, 4, 6, 12],
[1, 2, 3, 6, 4, 12],
[1, 2, 4, 3, 6, 12],
Expand All @@ -1611,7 +1611,7 @@ def linear_extensions(self, facade=False):
TESTS::
sage: D = Poset({ 0:[1,2], 1:[3], 2:[3,4] })
sage: list(D.linear_extensions())
sage: sorted(D.linear_extensions())
[[0, 1, 2, 3, 4], [0, 1, 2, 4, 3], [0, 2, 1, 3, 4], [0, 2, 1, 4, 3], [0, 2, 4, 1, 3]]
"""
Expand Down Expand Up @@ -1642,7 +1642,7 @@ def is_linear_extension(self, l):
[1, 2, 4, 3, 6, 12],
[1, 3, 2, 4, 6, 12],
[1, 3, 2, 6, 4, 12]]
sage: list(P.linear_extensions())
sage: sorted(P.linear_extensions())
[[1, 2, 3, 4, 6, 12],
[1, 2, 3, 6, 4, 12],
[1, 2, 4, 3, 6, 12],
Expand Down Expand Up @@ -6061,8 +6061,8 @@ def linear_extensions_graph(self):
sage: N = Poset({1: [3, 4], 2: [4]})
sage: G = N.linear_extensions_graph(); G
Graph on 5 vertices
sage: G.neighbors(N.linear_extension([1,2,3,4]))
[[2, 1, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4]]
sage: sorted(G.neighbors(N.linear_extension([1,2,3,4])))
[[1, 2, 4, 3], [1, 3, 2, 4], [2, 1, 3, 4]]
sage: chevron = Poset({1: [2, 6], 2: [3], 4: [3, 5], 6: [5]})
sage: G = chevron.linear_extensions_graph(); G
Expand All @@ -6082,7 +6082,7 @@ def linear_extensions_graph(self):
"""
from sage.graphs.graph import Graph
# Direct implementation, no optimizations
L = self.linear_extensions()
L = sorted(self.linear_extensions())
G = Graph()
G.add_vertices(L)
for i in range(len(L)):
Expand Down
23 changes: 12 additions & 11 deletions src/sage/combinat/ribbon_shaped_tableau.py
Expand Up @@ -290,7 +290,7 @@ def __iter__(self):
[[None, 1], [2, 3]],
[[1], [2], [3]],
[[1, 2, 3, 4]],
[[None, None, 3], [1, 2, 4]]]
[[None, None, 2], [1, 3, 4]]]
"""
from sage.combinat.partition import _Partitions
for p in _Partitions:
Expand Down Expand Up @@ -363,12 +363,12 @@ class StandardRibbonShapedTableaux_shape(StandardRibbonShapedTableaux):
[[None, 1, 2], [3, 4]]
sage: StandardRibbonShapedTableaux([2,2]).cardinality()
5
sage: StandardRibbonShapedTableaux([2,2]).list()
[[[None, 2, 4], [1, 3]],
[[None, 2, 3], [1, 4]],
[[None, 1, 4], [2, 3]],
sage: sorted(StandardRibbonShapedTableaux([2,2]))
[[[None, 1, 2], [3, 4]],
[[None, 1, 3], [2, 4]],
[[None, 1, 2], [3, 4]]]
[[None, 1, 4], [2, 3]],
[[None, 2, 3], [1, 4]],
[[None, 2, 4], [1, 3]]]
sage: StandardRibbonShapedTableaux([3,2,2]).cardinality()
155
"""
Expand Down Expand Up @@ -433,12 +433,13 @@ def __iter__(self):
EXAMPLES::
sage: [t for t in StandardRibbonShapedTableaux([2,2])]
[[[None, 2, 4], [1, 3]],
[[None, 2, 3], [1, 4]],
[[None, 1, 4], [2, 3]],
sage: sorted(StandardRibbonShapedTableaux([2,2]))
[[[None, 1, 2], [3, 4]],
[[None, 1, 3], [2, 4]],
[[None, 1, 2], [3, 4]]]
[[None, 1, 4], [2, 3]],
[[None, 2, 3], [1, 4]],
[[None, 2, 4], [1, 3]]]
"""
for p in descents_composition_list(self.shape):
yield self.from_permutation(p)
Expand Down
23 changes: 12 additions & 11 deletions src/sage/combinat/skew_tableau.py
Expand Up @@ -1748,15 +1748,16 @@ class StandardSkewTableaux(SkewTableaux):
::
sage: StandardSkewTableaux([[3, 2, 1], [1, 1]]).list()
sage: sorted(StandardSkewTableaux([[3, 2, 1], [1, 1]]))
[[[None, 1, 2], [None, 3], [4]],
[[None, 1, 2], [None, 4], [3]],
[[None, 1, 3], [None, 2], [4]],
[[None, 1, 4], [None, 2], [3]],
[[None, 1, 3], [None, 4], [2]],
[[None, 1, 4], [None, 2], [3]],
[[None, 1, 4], [None, 3], [2]],
[[None, 2, 3], [None, 4], [1]],
[[None, 2, 4], [None, 3], [1]]]
"""
@staticmethod
def __classcall_private__(cls, skp=None):
Expand Down Expand Up @@ -1833,7 +1834,7 @@ def __iter__(self):
[[1]],
[[1, 2]], [[1], [2]], [[None, 1], [2]], [[None, 2], [1]],
[[1, 2, 3]], [[1, 2], [3]], [[1, 3], [2]],
[[None, 1, 2], [3]]]
[[None, 1, 3], [2]]]
"""
n = 0
while True:
Expand Down Expand Up @@ -1897,16 +1898,16 @@ def __iter__(self):
sage: StandardSkewTableaux(3).list()
[[[1, 2, 3]],
[[1, 2], [3]], [[1, 3], [2]],
[[None, 1, 2], [3]], [[None, 1, 3], [2]],
[[None, 1, 3], [2]], [[None, 1, 2], [3]],
[[None, 2, 3], [1]],
[[None, 1], [2, 3]], [[None, 2], [1, 3]],
[[None, None, 1], [2, 3]], [[None, None, 2], [1, 3]], [[None, None, 3], [1, 2]],
[[None, None, 1], [2, 3]], [[None, None, 3], [1, 2]], [[None, None, 2], [1, 3]],
[[1], [2], [3]],
[[None, 1], [None, 2], [3]], [[None, 1], [None, 3], [2]], [[None, 2], [None, 3], [1]],
[[None, 1], [2], [3]], [[None, 2], [1], [3]], [[None, 3], [1], [2]],
[[None, 1], [None, 3], [2]], [[None, 1], [None, 2], [3]], [[None, 2], [None, 3], [1]],
[[None, 1], [2], [3]], [[None, 3], [1], [2]], [[None, 2], [1], [3]],
[[None, None, 1], [None, 2], [3]], [[None, None, 1], [None, 3], [2]],
[[None, None, 2], [None, 1], [3]], [[None, None, 3], [None, 1], [2]],
[[None, None, 2], [None, 3], [1]], [[None, None, 3], [None, 2], [1]]]
[[None, None, 2], [None, 3], [1]], [[None, None, 3], [None, 2], [1]],
[[None, None, 3], [None, 1], [2]], [[None, None, 2], [None, 1], [3]]]
"""
for skp in SkewPartitions(self.n):
for sst in StandardSkewTableaux_shape(skp):
Expand Down Expand Up @@ -1986,12 +1987,12 @@ def __iter__(self):
EXAMPLES::
sage: [st for st in StandardSkewTableaux([[3, 2, 1], [1, 1]])]
sage: sorted(StandardSkewTableaux([[3, 2, 1], [1, 1]]))
[[[None, 1, 2], [None, 3], [4]],
[[None, 1, 2], [None, 4], [3]],
[[None, 1, 3], [None, 2], [4]],
[[None, 1, 4], [None, 2], [3]],
[[None, 1, 3], [None, 4], [2]],
[[None, 1, 4], [None, 2], [3]],
[[None, 1, 4], [None, 3], [2]],
[[None, 2, 3], [None, 4], [1]],
[[None, 2, 4], [None, 3], [1]]]
Expand Down

0 comments on commit 0765e7f

Please sign in to comment.