Permutations

The Permutations module. Use Permutation? to get information about the Permutation class, and Permutations? to get information about the combinatorial class of permutations.

AUTHORS:

  • Mike Hansen
  • Dan Drake (2008-04-07): allow Permutation() to take lists of tuples
  • Sebastien Labbe (2009-03-17): added robinson_schensted_inverse
sage.combinat.permutation.Arrangements(mset, k)

An arrangement of mset is an ordered selection without repetitions and is represented by a list that contains only elements from mset, but maybe in a different order.

Arrangements returns the combinatorial class of arrangements of the multiset mset that contain k elements.

EXAMPLES:

sage: mset = [1,1,2,3,4,4,5]
sage: Arrangements(mset,2).list()
[[1, 1],
 [1, 2],
 [1, 3],
 [1, 4],
 [1, 5],
 [2, 1],
 [2, 3],
 [2, 4],
 [2, 5],
 [3, 1],
 [3, 2],
 [3, 4],
 [3, 5],
 [4, 1],
 [4, 2],
 [4, 3],
 [4, 4],
 [4, 5],
 [5, 1],
 [5, 2], 
 [5, 3],
 [5, 4]]
 sage: Arrangements(mset,2).cardinality()
 22
 sage: Arrangements( ["c","a","t"], 2 ).list()
 [['c', 'a'], ['c', 't'], ['a', 'c'], ['a', 't'], ['t', 'c'], ['t', 'a']]
 sage: Arrangements( ["c","a","t"], 3 ).list()
 [['c', 'a', 't'],
  ['c', 't', 'a'],
  ['a', 'c', 't'],
  ['a', 't', 'c'],
  ['t', 'c', 'a'],
  ['t', 'a', 'c']]
class sage.combinat.permutation.Arrangements_msetk(mset, k)
__repr__()

TESTS:

sage: repr(Arrangements([1,2,2],2))
'Arrangements of the multi-set [1, 2, 2] of length 2'
class sage.combinat.permutation.Arrangements_setk(s, k)
__repr__()

TESTS:

sage: repr(Arrangements([1,2,3],2))
'Arrangements of the set [1, 2, 3] of length 2'
sage.combinat.permutation.CyclicPermutations(mset)

Returns the combinatorial class of all cyclic permutations of mset in cycle notation. These are the same as necklaces.

EXAMPLES:

sage: CyclicPermutations(range(4)).list()
[[0, 1, 2, 3],
 [0, 1, 3, 2],
 [0, 2, 1, 3],
 [0, 2, 3, 1],
 [0, 3, 1, 2],
 [0, 3, 2, 1]]
sage: CyclicPermutations([1,1,1]).list()
[[1, 1, 1]]
sage.combinat.permutation.CyclicPermutationsOfPartition(partition)

Returns the combinatorial class of all combinations of cyclic permutations of each cell of the partition. This is the same as a Cartesian product of necklaces.

EXAMPLES:

sage: CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]).list()
[[[1, 2, 3, 4], [5, 6, 7]],
 [[1, 2, 4, 3], [5, 6, 7]],
 [[1, 3, 2, 4], [5, 6, 7]],
 [[1, 3, 4, 2], [5, 6, 7]],
 [[1, 4, 2, 3], [5, 6, 7]],
 [[1, 4, 3, 2], [5, 6, 7]],
 [[1, 2, 3, 4], [5, 7, 6]],
 [[1, 2, 4, 3], [5, 7, 6]],
 [[1, 3, 2, 4], [5, 7, 6]],
 [[1, 3, 4, 2], [5, 7, 6]],
 [[1, 4, 2, 3], [5, 7, 6]],
 [[1, 4, 3, 2], [5, 7, 6]]]
sage: CyclicPermutationsOfPartition([[1,2,3,4],[4,4,4]]).list()
[[[1, 2, 3, 4], [4, 4, 4]],
 [[1, 2, 4, 3], [4, 4, 4]],
 [[1, 3, 2, 4], [4, 4, 4]],
 [[1, 3, 4, 2], [4, 4, 4]],
 [[1, 4, 2, 3], [4, 4, 4]],
 [[1, 4, 3, 2], [4, 4, 4]]]
sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list()
[[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]]]
sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True)
[[[1, 2, 3], [4, 4, 4]],
 [[1, 3, 2], [4, 4, 4]],
 [[1, 2, 3], [4, 4, 4]],
 [[1, 3, 2], [4, 4, 4]]]
class sage.combinat.permutation.CyclicPermutationsOfPartition_partition(partition)
__init__(partition)

TESTS:

sage: CP = CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]])
sage: CP == loads(dumps(CP))
True
__iter__()

EXAMPLES:

sage: [ p for p in CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]) ] 
[[[1, 2, 3, 4], [5, 6, 7]],
 [[1, 2, 4, 3], [5, 6, 7]],
 [[1, 3, 2, 4], [5, 6, 7]],
 [[1, 3, 4, 2], [5, 6, 7]],
 [[1, 4, 2, 3], [5, 6, 7]],
 [[1, 4, 3, 2], [5, 6, 7]],
 [[1, 2, 3, 4], [5, 7, 6]],
 [[1, 2, 4, 3], [5, 7, 6]],
 [[1, 3, 2, 4], [5, 7, 6]],
 [[1, 3, 4, 2], [5, 7, 6]],
 [[1, 4, 2, 3], [5, 7, 6]],
 [[1, 4, 3, 2], [5, 7, 6]]]
__repr__()

TESTS:

sage: repr(CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]))
'Cyclic permutations of partition [[1, 2, 3, 4], [5, 6, 7]]'
iterator(distinct=False)

AUTHORS:

  • Robert Miller

EXAMPLES:

sage: CyclicPermutationsOfPartition([[1,2,3,4],[5,6,7]]).list() # indirect doctest
[[[1, 2, 3, 4], [5, 6, 7]],
 [[1, 2, 4, 3], [5, 6, 7]],
 [[1, 3, 2, 4], [5, 6, 7]],
 [[1, 3, 4, 2], [5, 6, 7]],
 [[1, 4, 2, 3], [5, 6, 7]],
 [[1, 4, 3, 2], [5, 6, 7]],
 [[1, 2, 3, 4], [5, 7, 6]],
 [[1, 2, 4, 3], [5, 7, 6]],
 [[1, 3, 2, 4], [5, 7, 6]],
 [[1, 3, 4, 2], [5, 7, 6]],
 [[1, 4, 2, 3], [5, 7, 6]],
 [[1, 4, 3, 2], [5, 7, 6]]]
sage: CyclicPermutationsOfPartition([[1,2,3,4],[4,4,4]]).list()
[[[1, 2, 3, 4], [4, 4, 4]],
 [[1, 2, 4, 3], [4, 4, 4]],
 [[1, 3, 2, 4], [4, 4, 4]],
 [[1, 3, 4, 2], [4, 4, 4]],
 [[1, 4, 2, 3], [4, 4, 4]],
 [[1, 4, 3, 2], [4, 4, 4]]]
sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list()
[[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]]]
sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True)
[[[1, 2, 3], [4, 4, 4]],
 [[1, 3, 2], [4, 4, 4]],
 [[1, 2, 3], [4, 4, 4]],
 [[1, 3, 2], [4, 4, 4]]]
list(distinct=False)

EXAMPLES:

sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list()
[[[1, 2, 3], [4, 4, 4]], [[1, 3, 2], [4, 4, 4]]]
sage: CyclicPermutationsOfPartition([[1,2,3],[4,4,4]]).list(distinct=True)
[[[1, 2, 3], [4, 4, 4]],
 [[1, 3, 2], [4, 4, 4]],
 [[1, 2, 3], [4, 4, 4]],
 [[1, 3, 2], [4, 4, 4]]]
class sage.combinat.permutation.CyclicPermutations_mset(mset)
__init__(mset)

TESTS:

sage: CP = CyclicPermutations(range(4))
sage: CP == loads(dumps(CP))
True
__iter__()

EXAMPLES:

sage: [ p for p in CyclicPermutations(range(4)) ]
[[0, 1, 2, 3],
 [0, 1, 3, 2],
 [0, 2, 1, 3],
 [0, 2, 3, 1],
 [0, 3, 1, 2],
 [0, 3, 2, 1]]
 sage: [ p for p in CyclicPermutations([1,1,1]) ]
 [[1, 1, 1]]
__repr__()

TESTS:

sage: repr(CyclicPermutations(range(4)))
'Cyclic permutations of [0, 1, 2, 3]'
iterator(distinct=False)

EXAMPLES:

sage: CyclicPermutations(range(4)).list() # indirect doctest
[[0, 1, 2, 3],
 [0, 1, 3, 2],
 [0, 2, 1, 3],
 [0, 2, 3, 1],
 [0, 3, 1, 2],
 [0, 3, 2, 1]]
 sage: CyclicPermutations([1,1,1]).list()
 [[1, 1, 1]]
 sage: CyclicPermutations([1,1,1]).list(distinct=True)
 [[1, 1, 1], [1, 1, 1]]
list(distinct=False)

EXAMPLES:

sage: CyclicPermutations(range(4)).list()
[[0, 1, 2, 3],
 [0, 1, 3, 2],
 [0, 2, 1, 3],
 [0, 2, 3, 1],
 [0, 3, 1, 2],
 [0, 3, 2, 1]]
class sage.combinat.permutation.PatternAvoider(n, patterns)
__init__(n, patterns)

EXAMPLES:

sage: from sage.combinat.permutation import PatternAvoider
sage: p = PatternAvoider(4, [[1,2,3]])
sage: loads(dumps(p))
<sage.combinat.permutation.PatternAvoider object at 0x...>
_rec(obj, state)

EXAMPLES:

sage: from sage.combinat.permutation import PatternAvoider
sage: p = PatternAvoider(4, [[1,2]])
sage: list(p._rec([1], 2))
[([2, 1], 3, False)]
sage.combinat.permutation.Permutation(l)

Converts l to a permutation.

INPUT:

  • an instance of Permutation_class,
  • list of integers, viewed as one-line permutation notation,
  • string, expressing the permutation in cycle notation,
  • list of tuples of integers, the permutation in cycle notation.
  • a PermutationGroupElement
  • a pair of two tableaux of the same shape, where the second one is standard. This uses the inverse of Robinson Schensted algorithm.

OUTPUT:

EXAMPLES:

sage: Permutation([2,1])
[2, 1]
sage: Permutation([2, 1, 4, 5, 3])
[2, 1, 4, 5, 3]
sage: Permutation('(1,2)')
[2, 1]
sage: Permutation('(1,2)(3,4,5)')
[2, 1, 4, 5, 3]
sage: Permutation( ((1,2),(3,4,5)) )
[2, 1, 4, 5, 3]
sage: Permutation( [(1,2),(3,4,5)] )
[2, 1, 4, 5, 3]
sage: Permutation( ((1,2)) )
[2, 1]
sage: Permutation( (1,2) )
[2, 1]
sage: Permutation( ((1,2),) )
[2, 1]
sage: p = Permutation((1, 2, 5)); p
[2, 5, 3, 4, 1]
sage: type(p)
<class 'sage.combinat.permutation.Permutation_class'>

Construction from a string in cycle notation

sage: p = Permutation( '(4,5)' ); p
[1, 2, 3, 5, 4]

The length of the permutation is the maximum integer appearing; add a 1-cycle to increase this:

sage: p2 = Permutation( '(4,5)(10)' ); p2
[1, 2, 3, 5, 4, 6, 7, 8, 9, 10]
sage: len(p); len(p2)
5
10

We construct a Permutation from a PermutationGroupElement:

sage: g = PermutationGroupElement([2,1,3])
sage: Permutation(g)
[2, 1, 3]

From a pair of tableaux of the same shape. This uses the inverse of Robinson Schensted algorithm:

sage: p = [[1, 4, 7], [2, 5], [3], [6]]
sage: q = [[1, 2, 5], [3, 6], [4], [7]]
sage: P = Tableau(p)
sage: Q = Tableau(q)
sage: Permutation( (p, q) )
[3, 6, 5, 2, 7, 4, 1]
sage: Permutation( [p, q] )
[3, 6, 5, 2, 7, 4, 1]
sage: Permutation( (P, Q) )
[3, 6, 5, 2, 7, 4, 1]
sage: Permutation( [P, Q] )
[3, 6, 5, 2, 7, 4, 1]

TESTS:

sage: Permutation([()])
[1]
sage: Permutation('()')
[1]
sage: Permutation(())
[1]

From a pair of empty tableaux

sage: Permutation( ([], []) )
[]
sage: Permutation( [[], []] )
[]
sage.combinat.permutation.PermutationOptions(**kwargs)

Sets the global options for elements of the permutation class. The defaults are for permutations to be displayed in list notation and the multiplication done from left to right (like in GAP).

display: ‘list’ - the permutations are displayed in list notation ‘cycle’ - the permutations are displayed in cycle notation ‘singleton’ - the permutations are displayed in cycle notation with singleton cycles shown as well.

mult: ‘l2r’ - the multiplication of permutations is done like composition of functions from left to right. That is, if we think of the permutations p1 and p2 as functions, then (p1*p2)(x) = p2(p1(x)). This is the default in multiplication in GAP. ‘r2l’ - the multiplication of permutations is done right to left so that (p1*p2)(x) = p1(p2(x))

If no parameters are set, then the function returns a copy of the options dictionary.

Note that these options have no effect on PermutationGroupElements.

EXAMPLES:

sage: p213 = Permutation([2,1,3])
sage: p312 = Permutation([3,1,2])
sage: PermutationOptions(mult='l2r', display='list')
sage: po = PermutationOptions()
sage: po['display']
'list'
sage: p213
[2, 1, 3]
sage: PermutationOptions(display='cycle')
sage: p213
(1,2)
sage: PermutationOptions(display='singleton')
sage: p213
(1,2)(3)
sage: PermutationOptions(display='list')
sage: po['mult']
'l2r'
sage: p213*p312
[1, 3, 2]
sage: PermutationOptions(mult='r2l')
sage: p213*p312
[3, 2, 1]
sage: PermutationOptions(mult='l2r')
class sage.combinat.permutation.Permutation_class(l)
__call__(i)

Returns the image of the integer i under this permutation.

EXAMPLES:

sage: p = Permutation([2, 1, 4, 5, 3])
sage: p(1)
2
sage: p = Permutation(((1,2),(4,3,5)))
sage: p(4)
3
sage: p(2)
1
sage: p = Permutation([5,2,1,6,3,7,4])
sage: map(p, range(1,8))
[5, 2, 1, 6, 3, 7, 4]

TESTS:

sage: p = Permutation([5,2,1,6,3,7,4])
sage: p(-1)
...
TypeError: i (= -1) must be between 1 and 7
sage: p(10)
...
TypeError: i (= 10) must be between 1 and 7
__hash__()

TESTS:

sage: d = {}
sage: p = Permutation([1,2,3])
sage: d[p] = 1
sage: d[p]
1
__mul__(rp)

TESTS:

sage: p213 = Permutation([2,1,3])
sage: p312 = Permutation([3,1,2])
sage: PermutationOptions(mult='l2r')
sage: p213*p312
[1, 3, 2]
sage: PermutationOptions(mult='r2l')
sage: p213*p312
[3, 2, 1]
sage: PermutationOptions(mult='l2r')
__repr__()

TESTS:

sage: PermutationOptions(display='list')
sage: p = Permutation([2,1,3])
sage: repr(p)
'[2, 1, 3]'
sage: PermutationOptions(display='cycle')
sage: repr(p)
'(1,2)'
sage: PermutationOptions(display='singleton')
sage: repr(p)
'(1,2)(3)'
sage: PermutationOptions(display='list')
__rmul__(lp)

TESTS:

sage: p213 = Permutation([2,1,3])
sage: p312 = Permutation([3,1,2])
sage: PermutationOptions(mult='l2r')
sage: p213*p312
[1, 3, 2]
sage: PermutationOptions(mult='r2l')
sage: p213*p312
[3, 2, 1]
sage: PermutationOptions(mult='l2r')
__str__()

TESTS:

sage: PermutationOptions(display='list')
sage: p = Permutation([2,1,3])
sage: str(p)
'[2, 1, 3]'
sage: PermutationOptions(display='cycle')
sage: str(p)
'(1,2)'
sage: PermutationOptions(display='singleton')
sage: str(p)
'(1,2)(3)'
sage: PermutationOptions(display='list')
_gap_(gap)

Returns a GAP version of this permutation.

EXAMPLES:

sage: gap(Permutation([1,2,3]))
()
sage: gap(Permutation((1,2,3)))
(1,2,3)
sage: type(_)
<class 'sage.interfaces.gap.GapElement'>
_icondition(i)

Returns a string which shows the relative positions of i-1,i,i+1 in self. Note that i corresponds to a 2 in the string.

Note

An imove can only be applied when the relative positions are one of ‘213’, ‘132’, ‘231’, or ‘312’. None is returned in the other cases to signal that an imove cannot be applied.

EXAMPLES:

sage: Permutation([2,1,3])._icondition(2)
('213', 1, 0, 2)
sage: Permutation([1,3,2])._icondition(2)
('132', 0, 2, 1)
sage: Permutation([2,3,1])._icondition(2)
('231', 2, 0, 1)
sage: Permutation([3,1,2])._icondition(2)
('312', 1, 2, 0)
sage: Permutation([1,2,3])._icondition(2)
(None, 0, 1, 2)
sage: Permutation([1,3,2,4])._icondition(3)
('213', 2, 1, 3)
sage: Permutation([2,1,3])._icondition(3)
...
ValueError: i (= 3) must be between 2 and n-1
_left_to_right_multiply_on_left(lp)

EXAMPLES:

sage: p = Permutation([2,1,3])
sage: q = Permutation([3,1,2])
sage: p._left_to_right_multiply_on_left(q)
[3, 2, 1]
sage: q._left_to_right_multiply_on_left(p)
[1, 3, 2]
_left_to_right_multiply_on_right(rp)

EXAMPLES:

sage: p = Permutation([2,1,3])
sage: q = Permutation([3,1,2])
sage: p._left_to_right_multiply_on_right(q)
[1, 3, 2]
sage: q._left_to_right_multiply_on_right(p)
[3, 2, 1]
action(a)

Returns the action of the permutation on a list.

EXAMPLES:

sage: p = Permutation([2,1,3])
sage: a = range(3)
sage: p.action(a)
[1, 0, 2]
sage: b = [1,2,3,4]
sage: p.action(b)
...
ValueError: len(a) must equal len(self)
avoids(patt)

Returns True if the permutation avoid the pattern patt and False otherwise.

EXAMPLES:

sage: Permutation([6,2,5,4,3,1]).avoids([4,2,3,1])
False
sage: Permutation([6,1,2,5,4,3]).avoids([4,2,3,1])
True
sage: Permutation([6,1,2,5,4,3]).avoids([3,4,1,2])
True
bruhat_greater()

Returns the combinatorial class of permutations greater than or equal to p in the Bruhat order.

EXAMPLES:

sage: Permutation([4,1,2,3]).bruhat_greater().list()
[[4, 1, 2, 3],
 [4, 1, 3, 2],
 [4, 2, 1, 3],
 [4, 2, 3, 1],
 [4, 3, 1, 2],
 [4, 3, 2, 1]]
bruhat_inversions()

Returns the list of inversions of p such that the application of this inversion to p decrements its number of inversions.

Equivalently, it returns the list of pairs (i,j), i < j such that p[i] < p[j] and such that there exists no k between i and j satisfying p[i] < p[k].

EXAMPLES:

sage: Permutation([5,2,3,4,1]).bruhat_inversions()
[[0, 1], [0, 2], [0, 3], [1, 4], [2, 4], [3, 4]]
sage: Permutation([6,1,4,5,2,3]).bruhat_inversions()
[[0, 1], [0, 2], [0, 3], [2, 4], [2, 5], [3, 4], [3, 5]]
bruhat_inversions_iterator()

Returns the iterator for the inversions of p such that the application of this inversion to p decrements its number of inversions.

EXAMPLES:

sage: list(Permutation([5,2,3,4,1]).bruhat_inversions_iterator())
[[0, 1], [0, 2], [0, 3], [1, 4], [2, 4], [3, 4]]
sage: list(Permutation([6,1,4,5,2,3]).bruhat_inversions_iterator())
[[0, 1], [0, 2], [0, 3], [2, 4], [2, 5], [3, 4], [3, 5]]
bruhat_lequal(p2)

Returns True if self is less than p2 in the Bruhat order.

EXAMPLES:

sage: Permutation([2,4,3,1]).bruhat_lequal(Permutation([3,4,2,1])) 
True
bruhat_pred()

Returns a list of the permutations strictly smaller than p in the Bruhat order such that there is no permutation between one of those and p.

EXAMPLES:

sage: Permutation([6,1,4,5,2,3]).bruhat_pred()
[[1, 6, 4, 5, 2, 3],
 [4, 1, 6, 5, 2, 3],
 [5, 1, 4, 6, 2, 3],
 [6, 1, 2, 5, 4, 3],
 [6, 1, 3, 5, 2, 4],
 [6, 1, 4, 2, 5, 3],
 [6, 1, 4, 3, 2, 5]]
bruhat_pred_iterator()

An iterator for the permutations strictly smaller than p in the Bruhat order such that there is no permutation between one of those and p.

EXAMPLES:

sage: [x for x in Permutation([6,1,4,5,2,3]).bruhat_pred_iterator()]
[[1, 6, 4, 5, 2, 3],
 [4, 1, 6, 5, 2, 3],
 [5, 1, 4, 6, 2, 3],
 [6, 1, 2, 5, 4, 3],
 [6, 1, 3, 5, 2, 4],
 [6, 1, 4, 2, 5, 3],
 [6, 1, 4, 3, 2, 5]]
bruhat_smaller()

Returns a the combinatorial class of permutations smaller than or equal to p in the Bruhat order.

EXAMPLES:

sage: Permutation([4,1,2,3]).bruhat_smaller().list()
[[1, 2, 3, 4],
 [1, 2, 4, 3],
 [1, 3, 2, 4],
 [1, 4, 2, 3],
 [2, 1, 3, 4],
 [2, 1, 4, 3],
 [3, 1, 2, 4],
 [4, 1, 2, 3]]
bruhat_succ()

Returns a list of the permutations strictly greater than p in the Bruhat order such that there is no permutation between one of those and p.

EXAMPLES:

sage: Permutation([6,1,4,5,2,3]).bruhat_succ()
[[6, 4, 1, 5, 2, 3],
 [6, 2, 4, 5, 1, 3],
 [6, 1, 5, 4, 2, 3],
 [6, 1, 4, 5, 3, 2]]
bruhat_succ_iterator()

An iterator for the permutations that are strictly greater than p in the Bruhat order such that there is no permutation between one of those and p.

EXAMPLES:

sage: [x for x in Permutation([6,1,4,5,2,3]).bruhat_succ_iterator()]
[[6, 4, 1, 5, 2, 3],
 [6, 2, 4, 5, 1, 3],
 [6, 1, 5, 4, 2, 3],
 [6, 1, 4, 5, 3, 2]]
complement()

Returns the complement of the permutation which is obtained by replacing each value x in the list with n - x + 1.

EXAMPLES:

sage: Permutation([1,2,3]).complement()
[3, 2, 1]
sage: Permutation([1, 3, 2]).complement()
[3, 1, 2]
cycle_string(singletons=False)

Returns a string of the permutation in cycle notation.

If singletons=True, it includes 1-cycles in the string.

EXAMPLES:

sage: Permutation([1,2,3]).cycle_string()
'()'
sage: Permutation([2,1,3]).cycle_string()
'(1,2)'
sage: Permutation([2,3,1]).cycle_string()
'(1,2,3)'
sage: Permutation([2,1,3]).cycle_string(singletons=True)
'(1,2)(3)'
cycle_type()

Returns a partition of len(p) corresponding to the cycle type of p. This is a non-increasing sequence of the cycle lengths of p.

EXAMPLES:

sage: Permutation([3,1,2,4]).cycle_type()
[3, 1]
descent_polynomial()

Returns the descent polynomial of the permutation p.

The descent polynomial of p is the product of all the z[p[i]] where i ranges over the descents of p.

REFERENCES:

  • Garsia and Stanton 1984

EXAMPLES:

sage: Permutation([2,1,3]).descent_polynomial()
z1
sage: Permutation([4,3,2,1]).descent_polynomial()
z1*z2^2*z3^3
descents(final_descent=False)

Returns the list of the descents of the permutation p.

A descent of a permutation is an integer i such that p[i] > p[i+1]. With the final_descent option, the last position of a non empty permutation is also considered as a descent.

EXAMPLES:

sage: Permutation([1,4,3,2]).descents()
[1, 2]
sage: Permutation([1,4,3,2]).descents(final_descent=True)
[1, 2, 3]
descents_composition()

Returns the composition corresponding to the descents of the permutation.

EXAMPLES:

sage: Permutation([1,3,2,4]).descents_composition()
[2, 2]
dict()

Returns a dictionary corresponding to the permutation.

EXAMPLES:

sage: p = Permutation([2,1,3])
sage: d = p.dict()
sage: d[1]
2
sage: d[2]
1
sage: d[3]
3
fixed_points()

Returns a list of the fixed points of the permutation p.

EXAMPLES:

sage: Permutation([1,3,2,4]).fixed_points()
[1, 4]
sage: Permutation([1,2,3,4]).fixed_points()
[1, 2, 3, 4]
has_pattern(patt)

Returns the boolean answering the question ‘Is patt a pattern appearing in permutation p?’

EXAMPLES:

sage: Permutation([3,5,1,4,6,2]).has_pattern([1,3,2])
True
idescents(final_descent=False)

Returns a list of the idescents of self, that is the list of the descents of self’s inverse.

With the final_descent option, the last position of a non empty permutation is also considered as a descent.

EXAMPLES:

sage: Permutation([1,4,3,2]).idescents()
[1, 2]
sage: Permutation([1,4,3,2]).idescents(final_descent=True)
[1, 2, 3]
idescents_signature(final_descent=False)

Each position in self is mapped to -1 if it is an idescent and 1 if it is not an idescent.

EXAMPLES:

sage: Permutation([1,4,3,2]).idescents()
[1, 2]
sage: Permutation([1,4,3,2]).idescents_signature()
[1, -1, -1, 1]
imajor_index(final_descent=False)

Returns the inverse major index of the permutation self, which is the major index of the inverse of self.

The major index is the sum of the descents of p. Since our permutation indices are 0-based, we need to add one the number of descents.

EXAMPLES:

sage: Permutation([2,1,3]).imajor_index()
1
sage: Permutation([3,4,1,2]).imajor_index()
2
sage: Permutation([4,3,2,1]).imajor_index()
6
inverse()

Returns the inverse of a permutation

EXAMPLES:

sage: Permutation([3,8,5,10,9,4,6,1,7,2]).inverse()
[8, 10, 1, 6, 3, 7, 9, 2, 5, 4]
sage: Permutation([2, 4, 1, 5, 3]).inverse()
[3, 1, 5, 2, 4]
inversions()

Returns a list of the inversions of permutation p.

EXAMPLES:

sage: Permutation([3,2,4,1,5]).inversions()
[[0, 1], [0, 3], [1, 3], [2, 3]]
is_even()

Returns True if the permutation p is even and false otherwise.

EXAMPLES:

sage: Permutation([1,2,3]).is_even()
True
sage: Permutation([2,1,3]).is_even()
False
ishift(i)

Returns an the i-shift of self. If an i-shift of self can’t be performed, then None is returned.

An i-shift can be applied when i is not in between i-1 and i+1. The i-shift moves i to the other side, and leaves the relative positions of i-1 and i+1 in place.

EXAMPLES: Here, 2 is to the left of both 1 and 3. A 2-shift can be applied which moves the 2 to the right and leaves 1 and 3 in their same relative order.

sage: Permutation([2,1,3]).ishift(2)
[1, 3, 2]

Note that the movement is done in place:

sage: Permutation([2,4,1,3]).ishift(2)
[1, 4, 3, 2]

Since 2 is between 1 and 3 in [1,2,3], an 2-shift cannot be applied.

sage: Permutation([1,2,3]).ishift(2) 
[1, 2, 3]
iswitch(i)

Returns an the i-switch of self. If an i-switch of self can’t be performed, then self is returned.

An i-shift can be applied when i is not in between i-1 and i+1. The i-shift moves i to the other side, and switches the relative positions of i-1 and i+1 in place.

EXAMPLES: Here, 2 is to the left of both 1 and 3. A 2-switch can be applied which moves the 2 to the right and switches the relative order between 1 and 3.

sage: Permutation([2,1,3]).iswitch(2)
[3, 1, 2]

Note that the movement is done in place:

sage: Permutation([2,4,1,3]).iswitch(2)
[3, 4, 1, 2]

Since 2 is between 1 and 3 in [1,2,3], an 2-switch cannot be applied.

sage: Permutation([1,2,3]).iswitch(2) 
[1, 2, 3]
left_tableau()

Returns the right standard tableau after performing the RSK algorithm on self.

EXAMPLES:

sage: Permutation([1,4,3,2]).left_tableau()
[[1, 2], [3], [4]]
length()

Returns the length of a permutation p. The length is given by the number of inversions of p.

EXAMPLES:

sage: Permutation([5, 1, 3, 2, 4]).length()
5
longest_increasing_subsequence()

Returns a list of the longest increasing subsequences of the permutation p.

EXAMPLES:

sage: Permutation([2,3,4,1]).longest_increasing_subsequence()
[[2, 3, 4]]
major_index(final_descent=False)

Returns the major index of the permutation p.

The major index is the sum of the descents of p. Since our permutation indices are 0-based, we need to add one the number of descents.

EXAMPLES:

sage: Permutation([2,1,3]).major_index()
1
sage: Permutation([3,4,1,2]).major_index()
2
sage: Permutation([4,3,2,1]).major_index()
6
next()

Returns the permutation that follows p in lexicographic order. If p is the last permutation, then next returns false.

EXAMPLES:

sage: p = Permutation([1, 3, 2])
sage: p.next()
[2, 1, 3]
sage: p = Permutation([4,3,2,1])
sage: p.next()
False
number_of_descents(final_descent=False)

Returns the number of descents of the permutation p.

EXAMPLES:

sage: Permutation([1,4,3,2]).number_of_descents()
2
sage: Permutation([1,4,3,2]).number_of_descents(final_descent=True)
3
number_of_fixed_points()

Returns the number of fixed points of the permutation p.

EXAMPLES:

sage: Permutation([1,3,2,4]).number_of_fixed_points()
2
sage: Permutation([1,2,3,4]).number_of_fixed_points()
4
number_of_idescents(final_descent=False)

Returns the number of descents of the permutation p.

EXAMPLES:

sage: Permutation([1,4,3,2]).number_of_idescents()
2
sage: Permutation([1,4,3,2]).number_of_idescents(final_descent=True)
3
number_of_inversions()

Returns the number of inversions in the permutation p.

An inversion of a permutation is a pair of elements (p[i],p[j]) with i < j and p[i] > p[j].

REFERENCES:

EXAMPLES:

sage: Permutation([3,2,4,1,5]).number_of_inversions()
4
sage: Permutation([1, 2, 6, 4, 7, 3, 5]).number_of_inversions()
6
number_of_peaks()

Returns the number of peaks of the permutation p.

A peak of a permutation is an integer i such that p[i-1] < p[i] and p[i] > p[i+1].

EXAMPLES:

sage: Permutation([1,3,2,4,5]).number_of_peaks()
1
sage: Permutation([4,1,3,2,6,5]).number_of_peaks()
2
number_of_recoils()

Returns the number of recoils of the permutation p.

EXAMPLES:

sage: Permutation([1,4,3,2]).number_of_recoils()
2
number_of_saliances()

Returns the number of saliances of the permutation p.

EXAMPLES:

sage: Permutation([2,3,1,5,4]).number_of_saliances()
2
sage: Permutation([5,4,3,2,1]).number_of_saliances()
5
pattern_positions(patt)

Returns the list of positions where the pattern patt appears in p.

EXAMPLES:

sage: Permutation([3,5,1,4,6,2]).pattern_positions([1,3,2])
[[0, 1, 3], [2, 3, 5], [2, 4, 5]]
peaks()

Returns a list of the peaks of the permutation p.

A peak of a permutation is an integer i such that p[i-1] < p[i] and p[i] > p[i+1].

EXAMPLES:

sage: Permutation([1,3,2,4,5]).peaks()
[1]
sage: Permutation([4,1,3,2,6,5]).peaks()
[2, 4]
permutohedron_greater(side='right')

Returns a list of permutations greater than or equal to p in the permutohedron order.

By default, the computations are done in the right permutohedron. If you pass the option side=’left’, then they will be done in the left permutohedron.

EXAMPLES:

sage: Permutation([4,2,1,3]).permutohedron_greater()
[[4, 2, 1, 3], [4, 2, 3, 1], [4, 3, 2, 1]]
sage: Permutation([4,2,1,3]).permutohedron_greater(side='left')
[[4, 2, 1, 3], [4, 3, 1, 2], [4, 3, 2, 1]]
permutohedron_lequal(p2, side='right')

Returns True if self is less than p2 in the permutohedron order.

By default, the computations are done in the right permutohedron. If you pass the option side=’left’, then they will be done in the left permutohedron.

EXAMPLES:

sage: p = Permutation([3,2,1,4])
sage: p.permutohedron_lequal(Permutation([4,2,1,3]))
False
sage: p.permutohedron_lequal(Permutation([4,2,1,3]), side='left') 
True
permutohedron_pred(side='right')

Returns a list of the permutations strictly smaller than p in the permutohedron order such that there is no permutation between one of those and p.

By default, the computations are done in the right permutohedron. If you pass the option side=’left’, then they will be done in the left permutohedron.

EXAMPLES:

sage: p = Permutation([4,2,1,3])
sage: p.permutohedron_pred()            
[[2, 4, 1, 3], [4, 1, 2, 3]]
sage: p.permutohedron_pred(side='left')
[[4, 1, 2, 3], [3, 2, 1, 4]]
permutohedron_smaller(side='right')

Returns a list of permutations smaller than or equal to p in the permutohedron order.

By default, the computations are done in the right permutohedron. If you pass the option side=’left’, then they will be done in the left permutohedron.

EXAMPLES:

sage: Permutation([4,2,1,3]).permutohedron_smaller()
[[1, 2, 3, 4],
 [1, 2, 4, 3],
 [1, 4, 2, 3],
 [2, 1, 3, 4],
 [2, 1, 4, 3],
 [2, 4, 1, 3],
 [4, 1, 2, 3],
 [4, 2, 1, 3]]
sage: Permutation([4,2,1,3]).permutohedron_smaller(side='left')
[[1, 2, 3, 4],
 [1, 3, 2, 4],
 [2, 1, 3, 4],
 [2, 3, 1, 4],
 [3, 1, 2, 4],
 [3, 2, 1, 4],
 [4, 1, 2, 3],
 [4, 2, 1, 3]]
permutohedron_succ(side='right')

Returns a list of the permutations strictly greater than p in the permutohedron order such that there is no permutation between one of those and p.

By default, the computations are done in the right permutohedron. If you pass the option side=’left’, then they will be done in the left permutohedron.

EXAMPLES:

sage: p = Permutation([4,2,1,3])
sage: p.permutohedron_succ()
[[4, 2, 3, 1]]
sage: p.permutohedron_succ(side='left')
[[4, 3, 1, 2]]
prev()

Returns the permutation that comes directly before p in lexicographic order. If p is the first permutation, then it returns False.

EXAMPLES:

sage: p = Permutation([1,2,3])
sage: p.prev()
False
sage: p = Permutation([1,3,2])
sage: p.prev()
[1, 2, 3]
rank()

Returns the rank of a permutation in lexicographic ordering.

EXAMPLES:

sage: Permutation([1,2,3]).rank()
0
sage: Permutation([1, 2, 4, 6, 3, 5]).rank()
10
sage: perms = Permutations(6).list()
sage: [p.rank() for p in perms ] == range(factorial(6))
True
recoils()

Returns the list of the positions of the recoils of the permutation p.

A recoil of a permutation is an integer i such that i+1 is to the left of it.

EXAMPLES:

sage: Permutation([1,4,3,2]).recoils()
[2, 3]
recoils_composition()

Returns the composition corresponding to recoils of the permutation.

EXAMPLES:

sage: Permutation([1,3,2,4]).recoils_composition()
[3]
reduced_word()

Returns the reduced word of a permutation.

EXAMPLES:

sage: Permutation([3,5,4,6,2,1]).reduced_word()
[2, 1, 4, 3, 2, 4, 3, 5, 4, 5]
reduced_word_lexmin()

Returns a lexicographically minimal reduced word of a permutation.

EXAMPLES:

sage: Permutation([3,4,2,1]).reduced_word_lexmin()
[1, 2, 1, 3, 2]
reduced_words()

Returns a list of the reduced words of the permutation p.

EXAMPLES:

sage: Permutation([2,1,3]).reduced_words()
[[1]]
sage: Permutation([3,1,2]).reduced_words()
[[2, 1]]
sage: Permutation([3,2,1]).reduced_words()
[[1, 2, 1], [2, 1, 2]]
sage: Permutation([3,2,4,1]).reduced_words()
[[1, 2, 3, 1], [1, 2, 1, 3], [2, 1, 2, 3]]
remove_extra_fixed_points()

Returns the permutation obtained by removing any fixed points at the end of self.

EXAMPLES:

sage: Permutation([2,1,3]).remove_extra_fixed_points()
[2, 1]
sage: Permutation([1,2,3,4]).remove_extra_fixed_points()
[1]
reverse()

Returns the permutation obtained by reversing the list.

EXAMPLES:

sage: Permutation([3,4,1,2]).reverse()
[2, 1, 4, 3]
sage: Permutation([1,2,3,4,5]).reverse()
[5, 4, 3, 2, 1]
right_tableau()

Returns the right standard tableau after performing the RSK algorithm on self.

EXAMPLES:

sage: Permutation([1,4,3,2]).right_tableau()
[[1, 2], [3], [4]]
robinson_schensted()

Returns the pair of standard tableau obtained by running the Robinson-Schensted Algorithm on self.

EXAMPLES:

sage: p = Permutation([6,2,3,1,7,5,4])
sage: p.robinson_schensted()
[[[1, 3, 4], [2, 5], [6, 7]], [[1, 3, 5], [2, 6], [4, 7]]]

TESTS:

The empty permutation:

sage: p = Permutation([])
sage: p.robinson_schensted()
[[], []]
runs()

Returns a list of the runs in the permutation p.

REFERENCES:

EXAMPLES:

sage: Permutation([1,2,3,4]).runs()
[[1, 2, 3, 4]]
sage: Permutation([4,3,2,1]).runs()
[[4], [3], [2], [1]]
sage: Permutation([2,4,1,3]).runs()
[[2, 4], [1, 3]]
saliances()

Returns a list of the saliances of the permutation p.

A saliance of a permutation p is an integer i such that p[i] > p[j] for all j > i.

EXAMPLES:

sage: Permutation([2,3,1,5,4]).saliances()
[3, 4]
sage: Permutation([5,4,3,2,1]).saliances()
[0, 1, 2, 3, 4]
signature(p)

Returns the signature of a permutation.

EXAMPLES:

sage: Permutation([4, 2, 3, 1, 5]).signature()
-1
to_cycles(singletons=True)

Returns the permutation p as a list of disjoint cycles.

EXAMPLES:

sage: Permutation([2,1,3,4]).to_cycles()
[(1, 2), (3,), (4,)]
sage: Permutation([2,1,3,4]).to_cycles(singletons=False)
[(1, 2)]
to_inversion_vector()

Returns the inversion vector of a permutation p.

If iv is the inversion vector, then iv[i] is the number of elements larger than i that appear to the left of i in the permutation.

EXAMPLES:

sage: Permutation([5,9,1,8,2,6,4,7,3]).to_inversion_vector()
[2, 3, 6, 4, 0, 2, 2, 1, 0]
sage: Permutation([8,7,2,1,9,4,6,5,10,3]).to_inversion_vector()
[3, 2, 7, 3, 4, 3, 1, 0, 0, 0]
sage: Permutation([3,2,4,1,5]).to_inversion_vector()
[3, 1, 0, 0, 0]
to_lehmer_cocode()

Returns the Lehmer cocode of p.

EXAMPLES:

sage: p = Permutation([2,1,3])
sage: p.to_lehmer_cocode()
[0, 1, 0]
sage: q = Permutation([3,1,2])
sage: q.to_lehmer_cocode()
[0, 1, 1]
to_lehmer_code()

Returns the Lehmer code of the permutation p.

EXAMPLES:

sage: p = Permutation([2,1,3])
sage: p.to_lehmer_code()
[1, 0, 0]
sage: q = Permutation([3,1,2])
sage: q.to_lehmer_code()
[2, 0, 0]
to_major_code(final_descent=False)

Returns the major code of the permutation p, which is defined as the list [m1-m2, m2-m3,..,mn] where mi := maj(pi) is the major indices of the permutation math obtained by erasing the letters smaller than math in p.

REFERENCES:

  • Carlitz, L. ‘q-Bernoulli and Eulerian Numbers’ Trans. Amer. Math. Soc. 76 (1954) 332-350 Skandera, M. ‘An Eulerian Partner for Inversions’, Sem. Lothar. Combin. 46 (2001) B46d.

EXAMPLES:

sage: Permutation([9,3,5,7,2,1,4,6,8]).to_major_code()
[5, 0, 1, 0, 1, 2, 0, 1, 0]
sage: Permutation([2,8,4,3,6,7,9,5,1]).to_major_code()
[8, 3, 3, 1, 4, 0, 1, 0, 0]
to_matrix()

Returns a matrix representing the permutation.

EXAMPLES:

sage: Permutation([1,2,3]).to_matrix()
[1 0 0]
[0 1 0]
[0 0 1]
sage: Permutation([1,3,2]).to_matrix()
[1 0 0]
[0 0 1]
[0 1 0]

Notice that matrix multiplication corresponds to permutation multiplication only when the permutation option mult=’r2l’

sage: PermutationOptions(mult='r2l')
sage: p = Permutation([2,1,3])
sage: q = Permutation([3,1,2])
sage: (p*q).to_matrix()
[0 0 1]
[0 1 0]
[1 0 0]
sage: p.to_matrix()*q.to_matrix()
[0 0 1]
[0 1 0]
[1 0 0]
sage: PermutationOptions(mult='l2r')
sage: (p*q).to_matrix()
[1 0 0]
[0 0 1]
[0 1 0]
to_permutation_group_element()

Returns a PermutationGroupElement equal to self.

EXAMPLES:

sage: Permutation([2,1,4,3]).to_permutation_group_element()
(1,2)(3,4)
sage: Permutation([1,2,3]).to_permutation_group_element()
()
to_tableau_by_shape(shape)

Returns a tableau of shape shape with the entries in self.

EXAMPLES:

sage: Permutation([3,4,1,2,5]).to_tableau_by_shape([3,2])
[[1, 2, 5], [3, 4]]
sage: Permutation([3,4,1,2,5]).to_tableau_by_shape([3,2]).to_permutation()
[3, 4, 1, 2, 5]
weak_excedences()

Returns all the numbers self[i] such that self[i] = i+1.

EXAMPLES:

sage: Permutation([1,4,3,2,5]).weak_excedences()
[1, 4, 3, 5]
sage.combinat.permutation.Permutations(n=None, k=None, **kwargs)

Returns a combinatorial class of permutations.

Permutations(n) returns the class of permutations of n, if n is an integer, list, set, or string.

Permutations(n, k) returns the class of permutations of n (where n is any of the above things) of length k; k must be an integer.

Valid keyword arguments are: ‘descents’, ‘bruhat_smaller’, ‘bruhat_greater’, ‘recoils_finer’, ‘recoils_fatter’, ‘recoils’, and ‘avoiding’. With the exception of ‘avoiding’, you cannot specify n or k along with a keyword.

Permutations(descents=list) returns the class of permutations with descents in the positions specified by ‘list’.

Permutations(bruhat_smaller,greater=p) returns the class of permutations smaller or greater, respectively, than the given permutation in Bruhat order.

Permutations(recoils=p) returns the class of permutations whose recoils composition is p.

Permutations(recoils_fatter,finer=p) returns the class of permutations whose recoils composition is fatter or finer, respectively, than the given permutation.

Permutations(n, avoiding=P) returns the class of permutations of n avoiding P. Here P may be a single permutation or a list of permutations; the returned class will avoid all patterns in P.

EXAMPLES:

sage: p = Permutations(3); p
Standard permutations of 3
sage: p.list()
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
sage: p = Permutations(3, 2); p
Permutations of {1,...,3} of length 2
sage: p.list()
[[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]
sage: p = Permutations(['c', 'a', 't']); p
Permutations of the set ['c', 'a', 't']
sage: p.list()
[['c', 'a', 't'],
 ['c', 't', 'a'],
 ['a', 'c', 't'],
 ['a', 't', 'c'],
 ['t', 'c', 'a'],
 ['t', 'a', 'c']]
sage: p = Permutations(['c', 'a', 't'], 2); p
Permutations of the set ['c', 'a', 't'] of length 2
sage: p.list()
[['c', 'a'], ['c', 't'], ['a', 'c'], ['a', 't'], ['t', 'c'], ['t', 'a']]
sage: p = Permutations([1,1,2]); p
Permutations of the multi-set [1, 1, 2]
sage: p.list()
[[1, 1, 2], [1, 2, 1], [2, 1, 1]]
sage: p = Permutations([1,1,2], 2); p
Permutations of the multi-set [1, 1, 2] of length 2
sage: p.list()
[[1, 1], [1, 2], [2, 1]]
sage: p = Permutations(descents=[1,3]); p
Standard permutations of 4 with descents [1, 3]
sage: p.list()
[[1, 3, 2, 4], [1, 4, 2, 3], [2, 3, 1, 4], [2, 4, 1, 3], [3, 4, 1, 2]]
sage: p = Permutations(bruhat_smaller=[1,3,2,4]); p
Standard permutations that are less than or equal to [1, 3, 2, 4] in the Bruhat order
sage: p.list()
[[1, 2, 3, 4], [1, 3, 2, 4]]
sage: p = Permutations(bruhat_greater=[4,2,3,1]); p
Standard permutations that are greater than or equal to [4, 2, 3, 1] in the Bruhat order
sage: p.list()
[[4, 2, 3, 1], [4, 3, 2, 1]]
sage: p = Permutations(recoils_finer=[2,1]); p
Standard permutations whose recoils composition is finer than [2, 1]
sage: p.list()
[[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()
[[1, 3, 2], [3, 1, 2], [3, 2, 1]]
sage: p = Permutations(recoils=[2,1]); p
Standard permutations whose recoils composition is [2, 1]
sage: p.list()
[[1, 3, 2], [3, 1, 2]]
sage: p = Permutations(4, avoiding=[1,3,2]); p
Standard permutations of 4 avoiding [1, 3, 2]
sage: p.list()
[[4, 1, 2, 3],
 [4, 2, 1, 3],
 [4, 2, 3, 1],
 [4, 3, 1, 2],
 [4, 3, 2, 1],
 [3, 4, 1, 2],
 [3, 4, 2, 1],
 [2, 3, 4, 1],
 [3, 2, 4, 1],
 [1, 2, 3, 4],
 [2, 1, 3, 4],
 [2, 3, 1, 4],
 [3, 1, 2, 4],
 [3, 2, 1, 4]]
sage: p = Permutations(5, avoiding=[[3,4,1,2], [4,2,3,1]]); p
Standard permutations of 5 avoiding [[3, 4, 1, 2], [4, 2, 3, 1]]
sage: p.cardinality()
88
sage: p.random_element()
[5, 1, 2, 4, 3]
class sage.combinat.permutation.Permutations_mset(mset)
__init__(mset)

TESTS:

sage: S = Permutations(['c','a','c'])
sage: S == loads(dumps(S))
True
__iter__()

Algorithm based on: http://marknelson.us/2002/03/01/next-permutation/

EXAMPLES:

sage: [ p for p in Permutations(['c','t','t'])] # indirect doctest
[['c', 't', 't'], ['t', 'c', 't'], ['t', 't', 'c']]
__repr__()

TESTS:

sage: repr(Permutations(['c','a','c']))
"Permutations of the multi-set ['c', 'a', 'c']"
cardinality()

EXAMPLES:

sage: Permutations([1,2,2]).cardinality()
3
class sage.combinat.permutation.Permutations_msetk(mset, k)
__contains__(x)

EXAMPLES:

sage: p = Permutations([1,2,2],2)
sage: [1,2,2] in p
False
sage: [2,2] in p
True
sage: [1,1] in p
False
sage: [2,1] in p
True
__init__(mset, k)

TESTS:

sage: P = Permutations([1,2,2],2)
sage: P == loads(dumps(P))
True
__repr__()

TESTS:

sage: repr(Permutations([1,2,2],2))
'Permutations of the multi-set [1, 2, 2] of length 2'
list()

EXAMPLES:

sage: Permutations([1,2,2],2).list()
[[1, 2], [2, 1], [2, 2]]
class sage.combinat.permutation.Permutations_nk(n, k)
__contains__(x)

EXAMPLES:

sage: [1,2] in Permutations(3,2)
True
sage: [1,1] in Permutations(3,2)
False
sage: [3,2,1] in Permutations(3,2)
False
sage: [3,1] in Permutations(3,2)
True
__init__(n, k)

TESTS:

sage: P = Permutations(3,2)
sage: P == loads(dumps(P))
True
__iter__()

EXAMPLES:

sage: [p for p in Permutations(3,2)]
[[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]
sage: [p for p in Permutations(3,0)]
[[]]
sage: [p for p in Permutations(3,4)]
[]
__repr__()

TESTS:

sage: repr(Permutations(3,2))
'Permutations of {1,...,3} of length 2'
cardinality()

EXAMPLES:

sage: Permutations(3,0).cardinality()
1
sage: Permutations(3,1).cardinality()
3
sage: Permutations(3,2).cardinality()
6
sage: Permutations(3,3).cardinality()
6
sage: Permutations(3,4).cardinality()
0
random_element()

EXAMPLES:

sage: Permutations(3,2).random_element()
[0, 1]
class sage.combinat.permutation.Permutations_set(s)
__init__(s)

TESTS:

sage: S = Permutations(['c','a','t'])
sage: S == loads(dumps(S))
True
__iter__()

Algorithm based on: http://marknelson.us/2002/03/01/next-permutation/

EXAMPLES:

sage: [ p for p in Permutations(['c','a','t'])] # indirect doctest
[['c', 'a', 't'],
 ['c', 't', 'a'],
 ['a', 'c', 't'],
 ['a', 't', 'c'],
 ['t', 'c', 'a'],
 ['t', 'a', 'c']]
__repr__()

TESTS:

sage: repr(Permutations(['c','a','t']))
"Permutations of the set ['c', 'a', 't']"
cardinality()

EXAMPLES:

sage: Permutations([1,2,3]).cardinality()
6
random_element()

EXAMPLES:

sage: Permutations([1,2,3]).random_element()
[1, 2, 3]
class sage.combinat.permutation.Permutations_setk(s, k)
__contains__(x)

EXAMPLES:

sage: p = Permutations([1,2,3],2)
sage: [1,2,3] in p
False
sage: [2,2] in p
False
sage: [1,3] in p
True
sage: [2,1] in p
True
__init__(s, k)

TESTS:

sage: P = Permutations([1,2,3],2)
sage: P == loads(dumps(P))
True
__iter__()

EXAMPLES:

sage: [i for i in Permutations([1,2,3],2)] # indirect doctest
[[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]
__repr__()

TESTS:

sage: repr(Permutations([1,2,3],2))
'Permutations of the set [1, 2, 3] of length 2'
random_element()

EXAMPLES:

sage: Permutations([1,2,3],2).random_element()
[1, 2]
class sage.combinat.permutation.StandardPermutations_all
__contains__(x)

TESTS:

sage: [] in Permutations()
True
sage: [1] in Permutations()
True
sage: [2] in Permutations()
False
sage: [1,2] in Permutations()
True
sage: [2,1] in Permutations()
True
sage: [1,2,2] in Permutations()
False
sage: [3,1,5,2] in Permutations()
False
sage: [3,4,1,5,2] in Permutations()
True
__init__()

TESTS:

sage: SP = Permutations()
sage: SP == loads(dumps(SP))
True
__repr__()

TESTS:

sage: repr(Permutations())
'Standard permutations'
_infinite_cclass_slice(n)

Needed by InfiniteAbstractCombinatorialClass to build __iter__.

TESTS:

sage: Permutations()._infinite_cclass_slice(4) == Permutations(4)
True
sage: it = iter(Permutations())    # indirect doctest
sage: [it.next() for i in range(10)]
[[], [1], [1, 2], [2, 1], [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
class sage.combinat.permutation.StandardPermutations_avoiding_12(n)
__init__(n)

TESTS:

sage: p = Permutations(3, avoiding=[1,2])
sage: p == loads(dumps(p))
True
__repr__()

TESTS:

sage: repr(Permutations(3, avoiding=[1,2]))
'Standard permutations of 3 avoiding [1, 2]'
list()

EXAMPLES:

sage: Permutations(3, avoiding=[1,2]).list()
[[3, 2, 1]]
class sage.combinat.permutation.StandardPermutations_avoiding_123(n)
__init__(n)

TESTS:

sage: p = Permutations(3, avoiding=[1, 2, 3])
sage: p == loads(dumps(p))
True
__iter__()

EXAMPLES:

sage: Permutations(3, avoiding=[1, 2, 3]).list() # indirect doctest
 [[1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
sage: Permutations(2, avoiding=[1, 2, 3]).list()
[[1, 2], [2, 1]]
sage: Permutations(3, avoiding=[1, 2, 3]).list()
[[1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
__repr__()

TESTS:

sage: repr(Permutations(3, avoiding=[1, 2, 3]))
'Standard permutations of 3 avoiding [1, 2, 3]'
cardinality()

EXAMPLES:

sage: Permutations(5, avoiding=[1, 2, 3]).cardinality()
42
sage: len( Permutations(5, avoiding=[1, 2, 3]).list() )
42
class sage.combinat.permutation.StandardPermutations_avoiding_132(n)
__init__(n)

TESTS:

sage: p = Permutations(3, avoiding=[1,3,2])
sage: p == loads(dumps(p))
True
__iter__()

EXAMPLES:

sage: Permutations(3, avoiding=[1,3,2]).list() # indirect doctest
[[1, 2, 3], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
sage: Permutations(4, avoiding=[1,3,2]).list()
[[4, 1, 2, 3],
 [4, 2, 1, 3],
 [4, 2, 3, 1],
 [4, 3, 1, 2],
 [4, 3, 2, 1],
 [3, 4, 1, 2],
 [3, 4, 2, 1],
 [2, 3, 4, 1],
 [3, 2, 4, 1],
 [1, 2, 3, 4],
 [2, 1, 3, 4],
 [2, 3, 1, 4],
 [3, 1, 2, 4],
 [3, 2, 1, 4]]
__repr__()

TESTS:

sage: repr(Permutations(3, avoiding=[1,3,2]))
'Standard permutations of 3 avoiding [1, 3, 2]'
cardinality()

EXAMPLES:

sage: Permutations(5, avoiding=[1, 3, 2]).cardinality()
42
sage: len( Permutations(5, avoiding=[1, 3, 2]).list() )
42
class sage.combinat.permutation.StandardPermutations_avoiding_21(n)
__init__(n)

TESTS:

sage: p = Permutations(3, avoiding=[2,1])
sage: p == loads(dumps(p))
True
__repr__()

TESTS:

sage: repr(Permutations(3, avoiding=[2,1]))
'Standard permutations of 3 avoiding [2, 1]'
list()

EXAMPLES:

sage: Permutations(3, avoiding=[2,1]).list()
[[1, 2, 3]]
class sage.combinat.permutation.StandardPermutations_avoiding_213(n)
__init__(n)

TESTS:

sage: p = Permutations(3, avoiding=[2, 1, 3])
sage: p == loads(dumps(p))
True
__iter__()

EXAMPLES:

sage: Permutations(3, avoiding=[2, 1, 3]).list()
[[1, 2, 3], [1, 3, 2], [3, 1, 2], [2, 3, 1], [3, 2, 1]]
__repr__()

TESTS:

sage: repr(Permutations(3, avoiding=[2, 1, 3]))
'Standard permutations of 3 avoiding [2, 1, 3]'
cardinality()

EXAMPLES:

sage: Permutations(5, avoiding=[2, 1, 3]).cardinality()
42
sage: len( Permutations(5, avoiding=[2, 1, 3]).list() )
42
class sage.combinat.permutation.StandardPermutations_avoiding_231(n)
__init__(n)

TESTS:

sage: p = Permutations(3, avoiding=[2, 3, 1])
sage: p == loads(dumps(p))
True
__iter__()

EXAMPLES:

sage: Permutations(3, avoiding=[2, 3, 1]).list()
[[3, 2, 1], [3, 1, 2], [1, 3, 2], [2, 1, 3], [1, 2, 3]]
__repr__()

TESTS:

sage: repr(Permutations(3, avoiding=[2, 3, 1]))
'Standard permutations of 3 avoiding [2, 3, 1]'
cardinality()

EXAMPLES:

sage: Permutations(5, avoiding=[2, 3, 1]).cardinality()
42
sage: len( Permutations(5, avoiding=[2, 3, 1]).list() )
42
class sage.combinat.permutation.StandardPermutations_avoiding_312(n)
__init__(n)

TESTS:

sage: p = Permutations(3, avoiding=[3, 1, 2])
sage: p == loads(dumps(p))
True
__iter__()

EXAMPLES:

sage: Permutations(3, avoiding=[3, 1, 2]).list()
[[3, 2, 1], [2, 3, 1], [2, 1, 3], [1, 3, 2], [1, 2, 3]]
__repr__()

TESTS:

sage: repr(Permutations(3, avoiding=[3, 1, 2]))
'Standard permutations of 3 avoiding [3, 1, 2]'
cardinality()

EXAMPLES:

sage: Permutations(5, avoiding=[3, 1, 2]).cardinality()
42
sage: len( Permutations(5, avoiding=[3, 1, 2]).list() )
42
class sage.combinat.permutation.StandardPermutations_avoiding_321(n)
__init__(n)

TESTS:

sage: p = Permutations(3, avoiding=[3, 2, 1])
sage: p == loads(dumps(p))
True
__iter__()

EXAMPLES:

sage: Permutations(3, avoiding=[3, 2, 1]).list() #indirect doctest
[[2, 3, 1], [3, 1, 2], [1, 3, 2], [2, 1, 3], [1, 2, 3]]
__repr__()

TESTS:

sage: repr(Permutations(3, avoiding=[3, 2, 1]))
'Standard permutations of 3 avoiding [3, 2, 1]'
cardinality()

EXAMPLES:

sage: Permutations(5, avoiding=[3, 2, 1]).cardinality()
42
sage: len( Permutations(5, avoiding=[3, 2, 1]).list() )
42
class sage.combinat.permutation.StandardPermutations_avoiding_generic(n, a)
__init__(n, a)

EXAMPLES:

sage: P = Permutations(3, avoiding=[[2, 1, 3],[1,2,3]])
sage: P == loads(dumps(P))
True
sage: type(P)
<class 'sage.combinat.permutation.StandardPermutations_avoiding_generic'>
__iter__()

EXAMPLES:

sage: Permutations(3, avoiding=[[2, 1, 3],[1,2,3]]).list()
[[1, 3, 2], [3, 1, 2], [2, 3, 1], [3, 2, 1]]
__repr__()

EXAMPLES:

sage: P = Permutations(3, avoiding=[[2, 1, 3],[1,2,3]])
sage: P.__repr__()
'Standard permutations of 3 avoiding [[2, 1, 3], [1, 2, 3]]'
class sage.combinat.permutation.StandardPermutations_bruhat_greater(p)
__init__(p)

TESTS:

sage: P = Permutations(bruhat_greater=[3,2,1])
sage: P == loads(dumps(P))
True
__repr__()

TESTS:

sage: repr(Permutations(bruhat_greater=[3,2,1]))
'Standard permutations that are greater than or equal to [3, 2, 1] in the Bruhat order'
list()

Returns a list of permutations greater than or equal to p in the Bruhat order.

EXAMPLES:

sage: Permutations(bruhat_greater=[4,1,2,3]).list()
[[4, 1, 2, 3],
 [4, 1, 3, 2],
 [4, 2, 1, 3],
 [4, 2, 3, 1],
 [4, 3, 1, 2],
 [4, 3, 2, 1]]
class sage.combinat.permutation.StandardPermutations_bruhat_smaller(p)
__init__(p)

TESTS:

sage: P = Permutations(bruhat_smaller=[3,2,1])
sage: P == loads(dumps(P))
True
__repr__()

TESTS:

sage: repr(Permutations(bruhat_smaller=[3,2,1]))
'Standard permutations that are less than or equal to [3, 2, 1] in the Bruhat order'
list()

Returns a list of permutations smaller than or equal to p in the Bruhat order.

EXAMPLES:

sage: Permutations(bruhat_smaller=[4,1,2,3]).list()
[[1, 2, 3, 4],
 [1, 2, 4, 3],
 [1, 3, 2, 4],
 [1, 4, 2, 3],
 [2, 1, 3, 4],
 [2, 1, 4, 3],
 [3, 1, 2, 4],
 [4, 1, 2, 3]]
class sage.combinat.permutation.StandardPermutations_descents(d, n)
__init__(d, n)

TESTS:

sage: P = Permutations(descents=([1,0,4,8],12))
sage: P == loads(dumps(P))
True
__repr__()

TESTS:

sage: repr(Permutations(descents=([1,0,4,8],12)))
'Standard permutations of 12 with descents [1, 0, 4, 8]'
first()

Returns the first permutation with descents d.

EXAMPLES:

sage: Permutations(descents=([1,0,4,8],12)).first()
[3, 2, 1, 4, 6, 5, 7, 8, 10, 9, 11, 12]
last()

Returns the last permutation with descents d.

EXAMPLES:

sage: Permutations(descents=([1,0,4,8],12)).last()
[12, 11, 8, 9, 10, 4, 5, 6, 7, 1, 2, 3]
list()

Returns a list of all the permutations that have the descents d.

EXAMPLES:

sage: Permutations(descents=([2,4,0],5)).list()
[[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, 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, 3, 4, 1, 2]]
object_class
alias of Permutation_class
class sage.combinat.permutation.StandardPermutations_n(n)
__contains__(x)

TESTS:

sage: [] in Permutations(0)
True
sage: [1,2] in Permutations(2)
True
sage: [1,2] in Permutations(3)
False
sage: [3,2,1] in Permutations(3)
True
__init__(n)

TESTS:

sage: SP = Permutations(3)
sage: SP == loads(dumps(SP))
True
__iter__()

EXAMPLES:

sage: [p for p in Permutations(0)] # indirect doctest
[[]]
sage: [p for p in Permutations(3)] # indirect doctest
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
__repr__()

TESTS:

sage: repr(Permutations(3))
'Standard permutations of 3'
cardinality()

EXAMPLES:

sage: Permutations(0).cardinality()
1
sage: Permutations(3).cardinality()
6
sage: Permutations(4).cardinality()
24
identity()

Returns the identity permutation of length n.

EXAMPLES:

sage: Permutations(4).identity()
[1, 2, 3, 4]
sage: Permutations(0).identity()
[]
random_element()

EXAMPLES:

sage: Permutations(4).random_element()
[1, 3, 2, 4]
rank(p)

EXAMPLES:

sage: SP3 = Permutations(3)
sage: map(SP3.rank, SP3)
[0, 1, 2, 3, 4, 5]
sage: SP0 = Permutations(0)
sage: map(SP0.rank, SP0)
[0]
unrank(r)

EXAMPLES:

sage: SP3 = Permutations(3)
sage: l = map(SP3.unrank, range(6))
sage: l == SP3.list()
True
sage: SP0 = Permutations(0)
sage: l = map(SP0.unrank, range(1))
sage: l == SP0.list()
True
class sage.combinat.permutation.StandardPermutations_recoils(recoils)
__init__(recoils)

TESTS:

sage: P = Permutations(recoils=[2,2])
sage: P == loads(dumps(P))
True
__repr__()

TESTS:

sage: repr(Permutations(recoils=[2,2]))
'Standard permutations whose recoils composition is [2, 2]'
list()

Returns a list of all of the permutations whose recoils composition is equal to recoils.

EXAMPLES:

sage: Permutations(recoils=[2,2]).list()
[[1, 3, 2, 4], [1, 3, 4, 2], [3, 1, 2, 4], [3, 1, 4, 2], [3, 4, 1, 2]]
object_class
alias of Permutation_class
class sage.combinat.permutation.StandardPermutations_recoilsfatter(recoils)
__init__(recoils)

TESTS:

sage: P = Permutations(recoils_fatter=[2,2])
sage: P == loads(dumps(P))
True
__repr__()

TESTS:

sage: repr(Permutations(recoils_fatter=[2,2]))
'Standard permutations whose recoils composition is fatter than [2, 2]'
list()

Returns a list of all of the permutations whose recoils composition is fatter than recoils.

EXAMPLES:

sage: Permutations(recoils_fatter=[2,2]).list()
[[1, 3, 2, 4],
 [1, 3, 4, 2],
 [1, 4, 3, 2],
 [3, 1, 2, 4],
 [3, 1, 4, 2],
 [3, 2, 1, 4],
 [3, 2, 4, 1],
 [3, 4, 1, 2],
 [3, 4, 2, 1],
 [4, 1, 3, 2],
 [4, 3, 1, 2],
 [4, 3, 2, 1]]
object_class
alias of Permutation_class
class sage.combinat.permutation.StandardPermutations_recoilsfiner(recoils)
__init__(recoils)

TESTS:

sage: P = Permutations(recoils_finer=[2,2])
sage: P == loads(dumps(P))
True
__repr__()

TESTS:

sage: repr(Permutations(recoils_finer=[2,2]))
'Standard permutations whose recoils composition is finer than [2, 2]'
list()

Returns a list of all of the permutations whose recoils composition is finer than recoils.

EXAMPLES:

sage: Permutations(recoils_finer=[2,2]).list()
[[1, 2, 3, 4],
 [1, 3, 2, 4],
 [1, 3, 4, 2],
 [3, 1, 2, 4],
 [3, 1, 4, 2],
 [3, 4, 1, 2]]
object_class
alias of Permutation_class
sage.combinat.permutation.bruhat_lequal(p1, p2)

Returns True if p1 is less than p2 in the Bruhat order.

Algorithm from mupad-combinat.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: permutation.bruhat_lequal([2,4,3,1],[3,4,2,1]) 
True
sage.combinat.permutation.descents_composition_first(dc)

Computes the smallest element of a descent class having a descent decomposition dc.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: permutation.descents_composition_first([1,1,3,4,3])
[3, 2, 1, 4, 6, 5, 7, 8, 10, 9, 11, 12]
sage.combinat.permutation.descents_composition_last(dc)

Returns the largest element of a descent class having a descent decomposition dc.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: permutation.descents_composition_last([1,1,3,4,3])
[12, 11, 8, 9, 10, 4, 5, 6, 7, 1, 2, 3]
sage.combinat.permutation.descents_composition_list(dc)

Returns a list of all the permutations that have a descent compositions dc.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: 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, 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, 3, 4, 1, 2]]
sage.combinat.permutation.from_cycles(n, cycles)

Returns the permutation corresponding to cycles.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: permutation.from_cycles(4, [[1,2]])
[2, 1, 3, 4]
sage.combinat.permutation.from_inversion_vector(iv)

Returns the permutation corresponding to inversion vector iv.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: permutation.from_inversion_vector([3,1,0,0,0])
[3, 2, 4, 1, 5]
sage: permutation.from_inversion_vector([2,3,6,4,0,2,2,1,0])
[5, 9, 1, 8, 2, 6, 4, 7, 3]
sage.combinat.permutation.from_lehmer_code(lehmer)

Returns the permutation with Lehmer code lehmer.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: Permutation([2,1,5,4,3]).to_lehmer_code()
[1, 0, 2, 1, 0]
sage: permutation.from_lehmer_code(_)  
[2, 1, 5, 4, 3]
sage.combinat.permutation.from_major_code(mc, final_descent=False)

Returns the permutation corresponding to major code mc.

REFERENCES:

  • Skandera, M. ‘An Eulerian Partner for Inversions’, Sem. Lothar. Combin. 46 (2001) B46d.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: permutation.from_major_code([5, 0, 1, 0, 1, 2, 0, 1, 0])
[9, 3, 5, 7, 2, 1, 4, 6, 8]
sage: permutation.from_major_code([8, 3, 3, 1, 4, 0, 1, 0, 0])
[2, 8, 4, 3, 6, 7, 9, 5, 1]
sage: Permutation([2,1,6,4,7,3,5]).to_major_code()
[3, 2, 0, 2, 2, 0, 0]
sage: permutation.from_major_code([3, 2, 0, 2, 2, 0, 0])
[2, 1, 6, 4, 7, 3, 5]
sage.combinat.permutation.from_permutation_group_element(pge)

Returns a Permutation give a PermutationGroupElement pge.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: pge = PermutationGroupElement([(1,2),(3,4)])
sage: permutation.from_permutation_group_element(pge)
[2, 1, 4, 3]
sage.combinat.permutation.from_rank(n, rank)

Returns the permutation with the specified lexicographic rank. The permutation is of the set [1,...,n].

The permutation is computed without iterating through all of the permutations with lower rank. This makes it efficient for large permutations.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: Permutation([3, 6, 5, 4, 2, 1]).rank()
359
sage: [permutation.from_rank(3, i) for i in range(6)]
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
sage: Permutations(6)[10]
[1, 2, 4, 6, 3, 5]
sage: permutation.from_rank(6,10)
[1, 2, 4, 6, 3, 5]
sage.combinat.permutation.from_reduced_word(rw)

Returns the permutation corresponding to the reduced word rw.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: permutation.from_reduced_word([3,2,3,1,2,3,1])
[3, 4, 2, 1]
sage: permutation.from_reduced_word([])
[]
sage.combinat.permutation.permutohedron_lequal(p1, p2, side='right')

Returns True if p1 is less than p2in the permutohedron order.

By default, the computations are done in the right permutohedron. If you pass the option side=’left’, then they will be done in the left permutohedron.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: permutation.permutohedron_lequal(Permutation([3,2,1,4]),Permutation([4,2,1,3]))
False
sage: permutation.permutohedron_lequal(Permutation([3,2,1,4]),Permutation([4,2,1,3]), side='left')
True
sage.combinat.permutation.robinson_schensted_inverse(p, q)

Returns the permutation corresponding to the pair of tableaux (p,q) using the inverse of Robinson-Schensted algorithm.

INPUT:

  • p, q: two tableaux of the same shape and where q is standard.

EXAMPLES:

sage: from sage.combinat.permutation import robinson_schensted_inverse
sage: t1 = Tableau([[1, 2, 5], [3], [4]])
sage: t2 = Tableau([[1, 2, 3], [4], [5]])
sage: robinson_schensted_inverse(t1, t2)
[1, 4, 5, 3, 2]
sage: robinson_schensted_inverse(t1, t1)
[1, 4, 3, 2, 5]
sage: robinson_schensted_inverse(t2, t2)
[1, 2, 5, 4, 3]
sage: robinson_schensted_inverse(t2, t1)
[1, 5, 4, 2, 3]

If the first tableau is semistandard:

sage: p = Tableau([[1,2,2]]); q = Tableau([[1,2,3]])
sage: robinson_schensted_inverse(p, q)
[1, 2, 2]
sage: _.robinson_schensted()
[[[1, 2, 2]], [[1, 2, 3]]]

Note that currently the constructor of Tableau accept as input lists that are not even tableaux but only filling of a partition diagram. This feature should not be used with robinson_schensted_inverse.

TESTS:

From empty tableaux:

sage: robinson_schensted_inverse(Tableau([]), Tableau([]))
[]

This function is the inverse of robinson_shensted:

sage: f = lambda p: robinson_schensted_inverse(*p.robinson_schensted())
sage: all(p == f(p) for n in range(7) for p in Permutations(n))
True

sage: n = ZZ.random_element(200)
sage: p = Permutations(n).random_element()
sage: is_fine = True if p == f(p) else p ; is_fine
True

Both tableaux must be of the same shape:

sage: robinson_schensted_inverse(Tableau([[1,2,3]]), Tableau([[1,2]]))
...
ValueError: p(=[[1, 2, 3]]) and q(=[[1, 2]]) must have the same shape

The second tableau must be standard:

sage: robinson_schensted_inverse(Tableau([[1,2,3]]), Tableau([[1,3,2]]))
...
ValueError: q(=[[1, 3, 2]]) must be standard
sage.combinat.permutation.to_standard(p)

Returns a standard permutation corresponding to the permutation p.

EXAMPLES:

sage: import sage.combinat.permutation as permutation
sage: permutation.to_standard([4,2,7])
[2, 1, 3]
sage: permutation.to_standard([1,2,3])
[1, 2, 3]

Previous topic

Partitions

Next topic

q-Analogues

This Page