def __iter__(self): """ TESTS:: sage: [ p for p in OrderedSetPartitions([1,2,3,4], [2,1,1]) ] [[{1, 2}, {3}, {4}], [{1, 2}, {4}, {3}], [{1, 3}, {2}, {4}], [{1, 4}, {2}, {3}], [{1, 3}, {4}, {2}], [{1, 4}, {3}, {2}], [{2, 3}, {1}, {4}], [{2, 4}, {1}, {3}], [{3, 4}, {1}, {2}], [{2, 3}, {4}, {1}], [{2, 4}, {3}, {1}], [{3, 4}, {2}, {1}]] sage: len(OrderedSetPartitions([1,2,3,4], [1,1,1,1])) 24 sage: [ x for x in OrderedSetPartitions([1,4,7], [3]) ] [[{1, 4, 7}]] sage: [ x for x in OrderedSetPartitions([1,4,7], [1,2]) ] [[{1}, {4, 7}], [{4}, {1, 7}], [{7}, {1, 4}]] sage: [ p for p in OrderedSetPartitions([], []) ] [[]] 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] l = len(self.c) dcomp = [-1] + comp.descents(final_descent=True) p = [] for j in range(l): p += [j + 1] * comp[j] from sage.combinat.permutation import Permutations_mset for x in Permutations_mset(p): 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)])
def __iter__(self): """ TESTS:: sage: [ p for p in OrderedSetPartitions([1,2,3,4], [2,1,1]) ] [[{1, 2}, {3}, {4}], [{1, 2}, {4}, {3}], [{1, 3}, {2}, {4}], [{1, 4}, {2}, {3}], [{1, 3}, {4}, {2}], [{1, 4}, {3}, {2}], [{2, 3}, {1}, {4}], [{2, 4}, {1}, {3}], [{3, 4}, {1}, {2}], [{2, 3}, {4}, {1}], [{2, 4}, {3}, {1}], [{3, 4}, {2}, {1}]] sage: len(OrderedSetPartitions([1,2,3,4], [1,1,1,1])) 24 sage: [ x for x in OrderedSetPartitions([1,4,7], [3]) ] [[{1, 4, 7}]] sage: [ x for x in OrderedSetPartitions([1,4,7], [1,2]) ] [[{1}, {4, 7}], [{4}, {1, 7}], [{7}, {1, 4}]] sage: [ p for p in OrderedSetPartitions([], []) ] [[]] 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] l = len(self.c) dcomp = [-1] + comp.descents(final_descent=True) p = [] for j in range(l): p += [j + 1] * comp[j] from sage.combinat.permutation import Permutations_mset for x in Permutations_mset(p): 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)])
def spin_rec(t, nexts, current, part, weight, length): """ Routine used for constructing the spin polynomial. INPUT: - ``weight`` -- list of non-negative integers - ``length`` -- the length of the ribbons we're tiling with - ``t`` -- the variable EXAMPLES:: sage: from sage.combinat.ribbon_tableau import spin_rec sage: sp = SkewPartition sage: t = ZZ['t'].gen() sage: spin_rec(t, [], [[[], [3, 3]]], sp([[2, 2, 2], []]), [2], 3) [t^4] sage: spin_rec(t, [[0], [t^4]], [[[2, 1, 1, 1, 1], [0, 3]], [[2, 2, 2], [3, 0]]], sp([[2, 2, 2, 2, 1], []]), [2, 1], 3) [t^5] sage: spin_rec(t, [], [[[], [3, 3, 0]]], sp([[3, 3], []]), [2], 3) [t^2] sage: spin_rec(t, [[t^4], [t^3], [t^2]], [[[2, 2, 2], [0, 0, 3]], [[3, 2, 1], [0, 3, 0]], [[3, 3], [3, 0, 0]]], sp([[3, 3, 3], []]), [2, 1], 3) [t^6 + t^4 + t^2] sage: spin_rec(t, [[t^5], [t^4], [t^6 + t^4 + t^2]], [[[2, 2, 2, 2, 1], [0, 0, 3]], [[3, 3, 1, 1, 1], [0, 3, 0]], [[3, 3, 3], [3, 0, 0]]], sp([[3, 3, 3, 2, 1], []]), [2, 1, 1], 3) [2*t^7 + 2*t^5 + t^3] """ if not current: return [parent(t).zero()] tmp = [] partp = part[0].conjugate() ell = len(partp) #compute the contribution of the ribbons added at #the current node for val in current: perms = val[1] perm = [ partp[i] + ell - (i + 1) - perms[i] for i in reversed(range(ell)) ] perm = to_standard(perm) tmp.append(weight[-1] * (length - 1) - perm.number_of_inversions()) if nexts: return [ sum( sum(t**tval * nval for nval in nexts[i]) for i, tval in enumerate(tmp)) ] else: return [sum(t**val for val in tmp)]
def spin_rec(t, nexts, current, part, weight, length): """ Routine used for constructing the spin polynomial. INPUT: - ``weight`` -- list of non-negative integers - ``length`` -- the length of the ribbons we're tiling with - ``t`` -- the variable EXAMPLES:: sage: from sage.combinat.ribbon_tableau import spin_rec sage: sp = SkewPartition sage: t = ZZ['t'].gen() sage: spin_rec(t, [], [[[], [3, 3]]], sp([[2, 2, 2], []]), [2], 3) [t^4] sage: spin_rec(t, [[0], [t^4]], [[[2, 1, 1, 1, 1], [0, 3]], [[2, 2, 2], [3, 0]]], sp([[2, 2, 2, 2, 1], []]), [2, 1], 3) [t^5] sage: spin_rec(t, [], [[[], [3, 3, 0]]], sp([[3, 3], []]), [2], 3) [t^2] sage: spin_rec(t, [[t^4], [t^3], [t^2]], [[[2, 2, 2], [0, 0, 3]], [[3, 2, 1], [0, 3, 0]], [[3, 3], [3, 0, 0]]], sp([[3, 3, 3], []]), [2, 1], 3) [t^6 + t^4 + t^2] sage: spin_rec(t, [[t^5], [t^4], [t^6 + t^4 + t^2]], [[[2, 2, 2, 2, 1], [0, 0, 3]], [[3, 3, 1, 1, 1], [0, 3, 0]], [[3, 3, 3], [3, 0, 0]]], sp([[3, 3, 3, 2, 1], []]), [2, 1, 1], 3) [2*t^7 + 2*t^5 + t^3] """ if not current: return [parent(t).zero()] tmp = [] partp = part[0].conjugate() ell = len(partp) #compute the contribution of the ribbons added at #the current node for val in current: perms = val[1] perm = [partp[i] + ell - (i + 1) - perms[i] for i in reversed(range(ell))] perm = to_standard(perm) tmp.append( weight[-1]*(length-1) - perm.number_of_inversions() ) if nexts: return [ sum(sum(t**tval * nval for nval in nexts[i]) for i, tval in enumerate(tmp)) ] else: return [ sum(t**val for val in tmp) ]