Constructor for permutations

This module contains the generic constructor to build element of the symmetric groups (or more general permutation groups) called PermutationGroupElement. These objects have a more group theoretic flavor than the more combinatorial Permutation.

sage.groups.perm_gps.constructor.PermutationGroupElement(g, parent=None, check=True)[source]

Build a permutation from g.

INPUT:

  • g – either

    • a list of images

    • a tuple describing a single cycle

    • a list of tuples describing the cycle decomposition

    • a string describing the cycle decomposition

  • parent – (optional) an ambient permutation group for the result; it is mandatory if you want a permutation on a domain different from \(\{1, \ldots, n\}\)

  • check – boolean (default: True); whether additional check are performed. Setting it to False is likely to result in faster code.

EXAMPLES:

Initialization as a list of images:

sage: p = PermutationGroupElement([1,4,2,3])
sage: p
(2,4,3)
sage: p.parent()
Symmetric group of order 4! as a permutation group
>>> from sage.all import *
>>> p = PermutationGroupElement([Integer(1),Integer(4),Integer(2),Integer(3)])
>>> p
(2,4,3)
>>> p.parent()
Symmetric group of order 4! as a permutation group

Initialization as a list of cycles:

sage: p = PermutationGroupElement([(3,5),(4,6,9)])
sage: p
(3,5)(4,6,9)
sage: p.parent()
Symmetric group of order 9! as a permutation group
>>> from sage.all import *
>>> p = PermutationGroupElement([(Integer(3),Integer(5)),(Integer(4),Integer(6),Integer(9))])
>>> p
(3,5)(4,6,9)
>>> p.parent()
Symmetric group of order 9! as a permutation group

Initialization as a string representing a cycle decomposition:

sage: p = PermutationGroupElement('(2,4)(3,5)')
sage: p
(2,4)(3,5)
sage: p.parent()
Symmetric group of order 5! as a permutation group
>>> from sage.all import *
>>> p = PermutationGroupElement('(2,4)(3,5)')
>>> p
(2,4)(3,5)
>>> p.parent()
Symmetric group of order 5! as a permutation group

By default the constructor assumes that the domain is \(\{1, \dots, n\}\) but it can be set to anything via its second parent argument:

sage: S = SymmetricGroup(['a', 'b', 'c', 'd', 'e'])
sage: PermutationGroupElement(['e', 'c', 'b', 'a', 'd'], S)
('a','e','d')('b','c')
sage: PermutationGroupElement(('a', 'b', 'c'), S)
('a','b','c')
sage: PermutationGroupElement([('a', 'c'), ('b', 'e')], S)
('a','c')('b','e')
sage: PermutationGroupElement("('a','b','e')('c','d')", S)
('a','b','e')('c','d')
>>> from sage.all import *
>>> S = SymmetricGroup(['a', 'b', 'c', 'd', 'e'])
>>> PermutationGroupElement(['e', 'c', 'b', 'a', 'd'], S)
('a','e','d')('b','c')
>>> PermutationGroupElement(('a', 'b', 'c'), S)
('a','b','c')
>>> PermutationGroupElement([('a', 'c'), ('b', 'e')], S)
('a','c')('b','e')
>>> PermutationGroupElement("('a','b','e')('c','d')", S)
('a','b','e')('c','d')

But in this situation, you might want to use the more direct:

sage: S(['e', 'c', 'b', 'a', 'd'])
('a','e','d')('b','c')
sage: S(('a', 'b', 'c'))
('a','b','c')
sage: S([('a', 'c'), ('b', 'e')])
('a','c')('b','e')
sage: S("('a','b','e')('c','d')")
('a','b','e')('c','d')
>>> from sage.all import *
>>> S(['e', 'c', 'b', 'a', 'd'])
('a','e','d')('b','c')
>>> S(('a', 'b', 'c'))
('a','b','c')
>>> S([('a', 'c'), ('b', 'e')])
('a','c')('b','e')
>>> S("('a','b','e')('c','d')")
('a','b','e')('c','d')
sage.groups.perm_gps.constructor.standardize_generator(g, convert_dict=None, as_cycles=False)[source]

Standardize the input for permutation group elements to a list or a list of tuples.

This was factored out of the PermutationGroupElement.__init__ since PermutationGroup_generic.__init__ needs to do the same computation in order to compute the domain of a group when it’s not explicitly specified.

INPUT:

  • g – a list, tuple, string, GapElement, PermutationGroupElement, or Permutation

  • convert_dict – (optional) a dictionary used to convert the points to a number compatible with GAP

  • as_cycles – boolean (default: False); whether the output should be as cycles or in one-line notation

OUTPUT: the permutation in as a list in one-line notation or a list of cycles as tuples

EXAMPLES:

sage: from sage.groups.perm_gps.constructor import standardize_generator
sage: standardize_generator('(1,2)')
[2, 1]

sage: p = PermutationGroupElement([(1,2)])
sage: standardize_generator(p)
[2, 1]
sage: standardize_generator(p._gap_())
[2, 1]
sage: standardize_generator((1,2))
[2, 1]
sage: standardize_generator([(1,2)])
[2, 1]

sage: standardize_generator(p, as_cycles=True)
[(1, 2)]
sage: standardize_generator(p._gap_(), as_cycles=True)
[(1, 2)]
sage: standardize_generator((1,2), as_cycles=True)
[(1, 2)]
sage: standardize_generator([(1,2)], as_cycles=True)
[(1, 2)]

sage: standardize_generator(Permutation([2,1,3]))
[2, 1, 3]
sage: standardize_generator(Permutation([2,1,3]), as_cycles=True)
[(1, 2), (3,)]
>>> from sage.all import *
>>> from sage.groups.perm_gps.constructor import standardize_generator
>>> standardize_generator('(1,2)')
[2, 1]

>>> p = PermutationGroupElement([(Integer(1),Integer(2))])
>>> standardize_generator(p)
[2, 1]
>>> standardize_generator(p._gap_())
[2, 1]
>>> standardize_generator((Integer(1),Integer(2)))
[2, 1]
>>> standardize_generator([(Integer(1),Integer(2))])
[2, 1]

>>> standardize_generator(p, as_cycles=True)
[(1, 2)]
>>> standardize_generator(p._gap_(), as_cycles=True)
[(1, 2)]
>>> standardize_generator((Integer(1),Integer(2)), as_cycles=True)
[(1, 2)]
>>> standardize_generator([(Integer(1),Integer(2))], as_cycles=True)
[(1, 2)]

>>> standardize_generator(Permutation([Integer(2),Integer(1),Integer(3)]))
[2, 1, 3]
>>> standardize_generator(Permutation([Integer(2),Integer(1),Integer(3)]), as_cycles=True)
[(1, 2), (3,)]

sage: d = {'a': 1, 'b': 2}
sage: p = SymmetricGroup(['a', 'b']).gen(0); p
('a','b')
sage: standardize_generator(p, convert_dict=d)
[2, 1]
sage: standardize_generator(p._gap_(), convert_dict=d)
[2, 1]
sage: standardize_generator(('a','b'), convert_dict=d)
[2, 1]
sage: standardize_generator([('a','b')], convert_dict=d)
[2, 1]

sage: standardize_generator(p, convert_dict=d, as_cycles=True)
[(1, 2)]
sage: standardize_generator(p._gap_(), convert_dict=d, as_cycles=True)
[(1, 2)]
sage: standardize_generator(('a','b'), convert_dict=d, as_cycles=True)
[(1, 2)]
sage: standardize_generator([('a','b')], convert_dict=d, as_cycles=True)
[(1, 2)]
>>> from sage.all import *
>>> d = {'a': Integer(1), 'b': Integer(2)}
>>> p = SymmetricGroup(['a', 'b']).gen(Integer(0)); p
('a','b')
>>> standardize_generator(p, convert_dict=d)
[2, 1]
>>> standardize_generator(p._gap_(), convert_dict=d)
[2, 1]
>>> standardize_generator(('a','b'), convert_dict=d)
[2, 1]
>>> standardize_generator([('a','b')], convert_dict=d)
[2, 1]

>>> standardize_generator(p, convert_dict=d, as_cycles=True)
[(1, 2)]
>>> standardize_generator(p._gap_(), convert_dict=d, as_cycles=True)
[(1, 2)]
>>> standardize_generator(('a','b'), convert_dict=d, as_cycles=True)
[(1, 2)]
>>> standardize_generator([('a','b')], convert_dict=d, as_cycles=True)
[(1, 2)]
sage.groups.perm_gps.constructor.string_to_tuples(g)[source]

EXAMPLES:

sage: from sage.groups.perm_gps.constructor import string_to_tuples
sage: string_to_tuples('(1,2,3)')
[(1, 2, 3)]
sage: string_to_tuples('(1,2,3)(4,5)')
[(1, 2, 3), (4, 5)]
sage: string_to_tuples(' (1,2, 3) (4,5)')
[(1, 2, 3), (4, 5)]
sage: string_to_tuples('(1,2)(3)')
[(1, 2), (3,)]
>>> from sage.all import *
>>> from sage.groups.perm_gps.constructor import string_to_tuples
>>> string_to_tuples('(1,2,3)')
[(1, 2, 3)]
>>> string_to_tuples('(1,2,3)(4,5)')
[(1, 2, 3), (4, 5)]
>>> string_to_tuples(' (1,2, 3) (4,5)')
[(1, 2, 3), (4, 5)]
>>> string_to_tuples('(1,2)(3)')
[(1, 2), (3,)]