diff --git a/src/sage/combinat/interval_posets.py b/src/sage/combinat/interval_posets.py index 73dd24a78e2..db19ef281a8 100644 --- a/src/sage/combinat/interval_posets.py +++ b/src/sage/combinat/interval_posets.py @@ -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) diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index 7290a0013d7..cac67c5eddf 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -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""" @@ -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]] :: @@ -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]] :: @@ -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))) ) @@ -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)] @@ -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], @@ -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], @@ -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 diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index 42017c6457a..64902208f41 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -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 @@ -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)): diff --git a/src/sage/combinat/ribbon_shaped_tableau.py b/src/sage/combinat/ribbon_shaped_tableau.py index dd783f5128a..eb74994dbe4 100644 --- a/src/sage/combinat/ribbon_shaped_tableau.py +++ b/src/sage/combinat/ribbon_shaped_tableau.py @@ -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: @@ -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 """ @@ -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) diff --git a/src/sage/combinat/skew_tableau.py b/src/sage/combinat/skew_tableau.py index d26493fa036..a56b6734d7b 100644 --- a/src/sage/combinat/skew_tableau.py +++ b/src/sage/combinat/skew_tableau.py @@ -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): @@ -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: @@ -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): @@ -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]]] diff --git a/src/sage/combinat/tableau.py b/src/sage/combinat/tableau.py index d5f24b8b5f0..1acd9591a16 100644 --- a/src/sage/combinat/tableau.py +++ b/src/sage/combinat/tableau.py @@ -6689,7 +6689,7 @@ class RowStandardTableaux(Tableaux): - with a partition argument, the class of all standard tableaux of that shape - A row standard tableau is a tableaux that contains each of the + A row standard tableau is a tableau that contains each of the entries from `1` to `n` exactly once and is increasing along rows. All classes of row standard tableaux are iterable. @@ -6701,20 +6701,20 @@ class RowStandardTableaux(Tableaux): sage: ST.first() [[1, 2, 3]] sage: ST.last() - [[1], [2], [3]] + [[3], [1], [2]] sage: ST.cardinality() 10 - sage: ST.list() + sage: sorted(ST, key=lambda t: t.shape(), reverse=True) [[[1, 2, 3]], [[2, 3], [1]], - [[1, 3], [2]], [[1, 2], [3]], + [[1, 3], [2]], [[3], [2], [1]], [[2], [3], [1]], - [[3], [1], [2]], - [[2], [1], [3]], [[1], [3], [2]], - [[1], [2], [3]]] + [[1], [2], [3]], + [[2], [1], [3]], + [[3], [1], [2]]] .. SEEALSO:: @@ -6732,18 +6732,18 @@ class RowStandardTableaux(Tableaux): sage: ST = RowStandardTableaux([2,2]); ST Row standard tableaux of shape [2, 2] sage: ST.first() - [[3, 4], [1, 2]] + [[2, 4], [1, 3]] sage: ST.last() - [[1, 2], [3, 4]] + [[2, 3], [1, 4]] sage: ST.cardinality() 6 - sage: ST.list() - [[[3, 4], [1, 2]], - [[2, 4], [1, 3]], - [[2, 3], [1, 4]], - [[1, 4], [2, 3]], + sage: sorted(ST) + [[[1, 2], [3, 4]], [[1, 3], [2, 4]], - [[1, 2], [3, 4]]] + [[1, 4], [2, 3]], + [[2, 3], [1, 4]], + [[2, 4], [1, 3]], + [[3, 4], [1, 2]]] sage: RowStandardTableau([[3,4,5],[1,2]]).residue_sequence(3).standard_tableaux() Standard tableaux with 3-residue sequence (2,0,0,1,2) and multicharge (0) """ @@ -6874,17 +6874,17 @@ class RowStandardTableaux_size(RowStandardTableaux, DisjointUnionEnumeratedSets) [[[1]]] sage: [ t for t in RowStandardTableaux(2) ] [[[1, 2]], [[2], [1]], [[1], [2]]] - sage: RowStandardTableaux(3)[:] + sage: list(RowStandardTableaux(3)) [[[1, 2, 3]], [[2, 3], [1]], - [[1, 3], [2]], [[1, 2], [3]], + [[1, 3], [2]], [[3], [2], [1]], [[2], [3], [1]], - [[3], [1], [2]], - [[2], [1], [3]], [[1], [3], [2]], - [[1], [2], [3]]] + [[1], [2], [3]], + [[2], [1], [3]], + [[3], [1], [2]]] TESTS:: @@ -7013,24 +7013,24 @@ def __iter__(self): EXAMPLES:: - sage: [t for t in RowStandardTableaux([2,2])] - [[[3, 4], [1, 2]], - [[2, 4], [1, 3]], - [[2, 3], [1, 4]], - [[1, 4], [2, 3]], + sage: sorted(RowStandardTableaux([2,2])) + [[[1, 2], [3, 4]], [[1, 3], [2, 4]], - [[1, 2], [3, 4]]] - sage: [t for t in RowStandardTableaux([3,2])] - [[[3, 4, 5], [1, 2]], - [[2, 4, 5], [1, 3]], - [[2, 3, 5], [1, 4]], - [[2, 3, 4], [1, 5]], - [[1, 4, 5], [2, 3]], - [[1, 3, 5], [2, 4]], - [[1, 3, 4], [2, 5]], - [[1, 2, 5], [3, 4]], + [[1, 4], [2, 3]], + [[2, 3], [1, 4]], + [[2, 4], [1, 3]], + [[3, 4], [1, 2]]] + sage: sorted(RowStandardTableaux([3,2])) + [[[1, 2, 3], [4, 5]], [[1, 2, 4], [3, 5]], - [[1, 2, 3], [4, 5]]] + [[1, 2, 5], [3, 4]], + [[1, 3, 4], [2, 5]], + [[1, 3, 5], [2, 4]], + [[1, 4, 5], [2, 3]], + [[2, 3, 4], [1, 5]], + [[2, 3, 5], [1, 4]], + [[2, 4, 5], [1, 3]], + [[3, 4, 5], [1, 2]]] sage: st = RowStandardTableaux([2,1]) sage: st[0].parent() is st True @@ -7043,9 +7043,15 @@ def __iter__(self): for row in self.shape: relations += [(m+i,m+i+1) for i in range(row-1)] m += row - +# print("iterating through %s"%self.shape) + P = Poset((range(1,self.shape.size()+1), relations)) + L = P.linear_extensions() +# print("covers: %s"%P.cover_relations()) +# print("exts: %s"%[e for e in L]) +# print("ext2: %s"%[e for e in L]) # now run through the linear extensions and return the corresponding tableau - for lin in Poset((range(1,self.shape.size()+1), relations)).linear_extensions(): + for lin in L: +# print("l-ext %s"%lin) linear_tab = list(permutation.Permutation(lin).inverse()) tab = [linear_tab[partial_sums[i]:partial_sums[i+1]] for i in range(len(self.shape))] diff --git a/src/sage/combinat/tableau_tuple.py b/src/sage/combinat/tableau_tuple.py index 939da06cb74..42631852eeb 100644 --- a/src/sage/combinat/tableau_tuple.py +++ b/src/sage/combinat/tableau_tuple.py @@ -2716,19 +2716,19 @@ class RowStandardTableauTuples(TableauTuples): Row standard tableau tuples of shape ([2], [1, 1]) sage: tabs.cardinality() 12 - sage: tabs[:] - [([[3, 4]], [[2], [1]]), - ([[2, 4]], [[3], [1]]), - ([[2, 3]], [[4], [1]]), - ([[3, 4]], [[1], [2]]), - ([[2, 4]], [[1], [3]]), - ([[2, 3]], [[1], [4]]), - ([[1, 4]], [[3], [2]]), + sage: sorted(tabs) + [([[1, 2]], [[3], [4]]), + ([[1, 2]], [[4], [3]]), + ([[1, 3]], [[2], [4]]), ([[1, 3]], [[4], [2]]), ([[1, 4]], [[2], [3]]), - ([[1, 3]], [[2], [4]]), - ([[1, 2]], [[4], [3]]), - ([[1, 2]], [[3], [4]])] + ([[1, 4]], [[3], [2]]), + ([[2, 3]], [[1], [4]]), + ([[2, 3]], [[4], [1]]), + ([[2, 4]], [[1], [3]]), + ([[2, 4]], [[3], [1]]), + ([[3, 4]], [[1], [2]]), + ([[3, 4]], [[2], [1]])] sage: tabs = RowStandardTableauTuples(level=3); tabs Row standard tableau tuples of level 3 @@ -2880,14 +2880,14 @@ def __getitem__(self, r): sage: RowStandardTableauTuples()[10:20] [([[2, 3], [1]]), - ([[1, 3], [2]]), ([[1, 2], [3]]), + ([[1, 3], [2]]), ([[3], [2], [1]]), ([[2], [3], [1]]), - ([[3], [1], [2]]), - ([[2], [1], [3]]), ([[1], [3], [2]]), ([[1], [2], [3]]), + ([[2], [1], [3]]), + ([[3], [1], [2]]), ([[1, 2]], [])] .. TODO:: @@ -3415,44 +3415,44 @@ def __iter__(self): EXAMPLES:: - sage: RowStandardTableauTuples([[1],[1],[1]]).list() - [([[3]], [[2]], [[1]]), + sage: sorted(RowStandardTableauTuples([[1],[1],[1]])) + [([[1]], [[2]], [[3]]), + ([[1]], [[3]], [[2]]), + ([[2]], [[1]], [[3]]), ([[2]], [[3]], [[1]]), ([[3]], [[1]], [[2]]), - ([[2]], [[1]], [[3]]), - ([[1]], [[3]], [[2]]), - ([[1]], [[2]], [[3]])] - sage: RowStandardTableauTuples([[2,1],[2]]).list() - [([[4, 5], [3]], [[1, 2]]), - ([[3, 5], [4]], [[1, 2]]), - ([[3, 4], [5]], [[1, 2]]), - ([[4, 5], [2]], [[1, 3]]), - ([[3, 5], [2]], [[1, 4]]), - ([[3, 4], [2]], [[1, 5]]), - ([[2, 5], [4]], [[1, 3]]), + ([[3]], [[2]], [[1]])] + sage: sorted(RowStandardTableauTuples([[2,1],[2]])) + [([[1, 2], [3]], [[4, 5]]), + ([[1, 2], [4]], [[3, 5]]), + ([[1, 2], [5]], [[3, 4]]), + ([[1, 3], [2]], [[4, 5]]), + ([[1, 3], [4]], [[2, 5]]), + ([[1, 3], [5]], [[2, 4]]), + ([[1, 4], [2]], [[3, 5]]), + ([[1, 4], [3]], [[2, 5]]), + ([[1, 4], [5]], [[2, 3]]), + ([[1, 5], [2]], [[3, 4]]), + ([[1, 5], [3]], [[2, 4]]), + ([[1, 5], [4]], [[2, 3]]), + ([[2, 3], [1]], [[4, 5]]), + ([[2, 3], [4]], [[1, 5]]), + ([[2, 3], [5]], [[1, 4]]), + ([[2, 4], [1]], [[3, 5]]), + ([[2, 4], [3]], [[1, 5]]), ([[2, 4], [5]], [[1, 3]]), + ([[2, 5], [1]], [[3, 4]]), ([[2, 5], [3]], [[1, 4]]), - ([[2, 4], [3]], [[1, 5]]), - ([[2, 3], [5]], [[1, 4]]), - ([[2, 3], [4]], [[1, 5]]), - ([[4, 5], [1]], [[2, 3]]), - ([[3, 5], [1]], [[2, 4]]), + ([[2, 5], [4]], [[1, 3]]), ([[3, 4], [1]], [[2, 5]]), - ([[2, 5], [1]], [[3, 4]]), - ([[2, 4], [1]], [[3, 5]]), - ([[2, 3], [1]], [[4, 5]]), - ([[1, 5], [4]], [[2, 3]]), - ([[1, 4], [5]], [[2, 3]]), - ([[1, 5], [3]], [[2, 4]]), - ([[1, 4], [3]], [[2, 5]]), - ([[1, 3], [5]], [[2, 4]]), - ([[1, 3], [4]], [[2, 5]]), - ([[1, 5], [2]], [[3, 4]]), - ([[1, 4], [2]], [[3, 5]]), - ([[1, 3], [2]], [[4, 5]]), - ([[1, 2], [5]], [[3, 4]]), - ([[1, 2], [4]], [[3, 5]]), - ([[1, 2], [3]], [[4, 5]])] + ([[3, 4], [2]], [[1, 5]]), + ([[3, 4], [5]], [[1, 2]]), + ([[3, 5], [1]], [[2, 4]]), + ([[3, 5], [2]], [[1, 4]]), + ([[3, 5], [4]], [[1, 2]]), + ([[4, 5], [1]], [[2, 3]]), + ([[4, 5], [2]], [[1, 3]]), + ([[4, 5], [3]], [[1, 2]])] TESTS:: @@ -3530,7 +3530,7 @@ def an_element(self): EXAMPLES:: sage: RowStandardTableauTuples([[2],[2,1]]).an_element() - ([[2, 4]], [[3, 5], [1]]) + ([[4, 5]], [[1, 3], [2]]) sage: RowStandardTableauTuples([[10],[],[]]).an_element() ([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [], []) """ diff --git a/src/sage/graphs/linearextensions.py b/src/sage/graphs/linearextensions.py index 0c0177bc0f7..026277bd22b 100644 --- a/src/sage/graphs/linearextensions.py +++ b/src/sage/graphs/linearextensions.py @@ -22,7 +22,7 @@ sage: D = DiGraph({ 0:[1,2], 1:[3], 2:[3,4] }) sage: D.is_directed_acyclic() True - sage: LinearExtensions(D).list() + sage: sorted(LinearExtensions(D)) [[0, 1, 2, 3, 4], [0, 1, 2, 4, 3], [0, 2, 1, 3, 4], @@ -35,7 +35,7 @@ We can also get at the linear extensions directly from the graph. From the graph, the linear extensions are known as topological sorts :: - sage: D.topological_sort_generator() + sage: sorted(D.topological_sort_generator()) [[0, 1, 2, 3, 4], [0, 1, 2, 4, 3], [0, 2, 1, 3, 4], @@ -80,10 +80,14 @@ def __init__(self, dag): True """ + self.dag = dag + self._name = "Linear extensions of %s"%dag + + def _prepare(self): ################ #Precomputation# ################ - dag_copy = copy(dag) + dag_copy = copy(self.dag) le = [] a = [] b = [] @@ -114,13 +118,9 @@ def __init__(self, dag): self.le = le self.a = a self.b = b - self.dag = dag self.mrb = 0 self.mra = 0 self.is_plus = True - self.linear_extensions = None - self._name = "Linear extensions of %s"%dag - def switch(self, i): """ @@ -353,13 +353,14 @@ def __iter__(self): sage: from sage.graphs.linearextensions import LinearExtensions sage: D = DiGraph({ 0:[1,2], 1:[3], 2:[3,4] }) - sage: LinearExtensions(D).list() + sage: sorted(LinearExtensions(D)) [[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]] """ + self._prepare() yield self.le[:] for e in self.generate_linear_extensions(self.max_pair): yield e