Skip to content

Commit

Permalink
Trac #16646: Ordered Set Partitions of size 42
Browse files Browse the repository at this point in the history
I had the pleasure to remark that to generate '''ordered set partitions
of size 42''' one has to use Word... and for some obscure reason...
{{{
sage: type(Word(Permutations(range(3,52)).first()))
<class 'sage.combinat.words.word.InfiniteWord_iter_with_caching'>
sage: type(Word(range(3,52)))
<class 'sage.combinat.words.word.FiniteWord_list'>
}}}
from a permutation of size 42 (>39), the word associated is an infinite
word...

(NOTE: This ticket fix `set_partition_ordered` not `Words`!!)

URL: http://trac.sagemath.org/16646
Reported by: elixyre
Ticket author(s): Jean-Baptiste Priez
Reviewer(s): Frédéric Chapoton
  • Loading branch information
Release Manager authored and vbraun committed Jul 20, 2014
2 parents 62aeb71 + bf0a71c commit 1f73f9f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/sage/combinat/set_partition_ordered.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
from sage.combinat.combinatorial_map import combinatorial_map
from sage.combinat.combinat import stirling_number2
from sage.combinat.composition import Composition, Compositions
from sage.combinat.words.word import Word
import sage.combinat.permutation as permutation
from functools import reduce


class OrderedSetPartition(ClonableArray):
"""
An ordered partition of a set.
Expand Down Expand Up @@ -561,6 +561,14 @@ def __iter__(self):
sage: [ p for p in OrderedSetPartitions([1], [1]) ]
[[{1}]]
Let us check that it works for large size (:trac:`16646`)::
sage: OrderedSetPartitions(42).first()
[{1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12},
{13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23},
{24}, {25}, {26}, {27}, {28}, {29}, {30}, {31}, {32}, {33}, {34},
{35}, {36}, {37}, {38}, {39}, {40}, {41}, {42}]
"""
comp = self.c
lset = [x for x in self._set]
Expand All @@ -569,16 +577,18 @@ def __iter__(self):

p = []
for j in range(l):
p += [j+1]*comp[j]
p += [j + 1] * comp[j]

for x in permutation.Permutations(p):
res = Word(x).standard_permutation().inverse()
res = [lset[x-1] for x in res]
yield self.element_class( self, [ Set( res[dcomp[i]+1:dcomp[i+1]+1] ) for i in range(l)] )
res = permutation.to_standard(x).inverse()
res = [lset[x - 1] for x in res]
yield self.element_class(self, [Set(res[dcomp[i]+1:dcomp[i+1]+1])
for i in range(l)])

##########################################################
# Deprecations


class SplitNK(OrderedSetPartitions_scomp):
def __setstate__(self, state):
r"""
Expand Down

0 comments on commit 1f73f9f

Please sign in to comment.