Coverage for local/lib/python2.7/site-packages/sage/groups/conjugacy_classes.py : 57%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*- r""" Conjugacy classes of groups
This module implements a wrapper of GAP's ``ConjugacyClass`` function.
There are two main classes, :class:`ConjugacyClass` and :class:`ConjugacyClassGAP`. All generic methods should go into :class:`ConjugacyClass`, whereas :class:`ConjugacyClassGAP` should only contain wrappers for GAP functions. :class:`ConjugacyClass` contains some fallback methods in case some group cannot be defined as a GAP object.
.. TODO::
- Implement a non-naive fallback method for computing all the elements of the conjugacy class when the group is not defined in GAP, as the one in Butler's paper. - Define a sage method for gap matrices so that groups of matrices can use the quicker GAP algorithm rather than the naive one.
EXAMPLES:
Conjugacy classes for groups of permutations::
sage: G = SymmetricGroup(4) sage: g = G((1,2,3,4)) sage: G.conjugacy_class(g) Conjugacy class of cycle type [4] in Symmetric group of order 4! as a permutation group
Conjugacy classes for groups of matrices::
sage: F = GF(5) sage: gens = [matrix(F,2,[1,2, -1, 1]), matrix(F,2, [1,1, 0,1])] sage: H = MatrixGroup(gens) sage: h = H(matrix(F,2,[1,2, -1, 1])) sage: H.conjugacy_class(h) Conjugacy class of [1 2] [4 1] in Matrix group over Finite Field of size 5 with 2 generators ( [1 2] [1 1] [4 1], [0 1] )
TESTS::
sage: G = SymmetricGroup(3) sage: g = G((1,2,3)) sage: C = ConjugacyClass(G,g) sage: TestSuite(C).run() """
#**************************************************************************** # Copyright (C) 2011 Javier López Peña <jlopez@ende.cc> # # Distributed under the terms of the GNU General Public License (GPL) # http://www.gnu.org/licenses/ #****************************************************************************
from sage.structure.parent import Parent from sage.misc.cachefunc import cached_method from sage.categories.enumerated_sets import EnumeratedSets from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
class ConjugacyClass(Parent): r""" Generic conjugacy classes for elements in a group.
This is the default fall-back implementation to be used whenever GAP cannot handle the group.
EXAMPLES::
sage: G = SymmetricGroup(4) sage: g = G((1,2,3,4)) sage: ConjugacyClass(G,g) Conjugacy class of (1,2,3,4) in Symmetric group of order 4! as a permutation group """ def __init__(self, group, element): r""" Generic conjugacy classes for elements in a group.
This is the default fall-back implementation to be used whenever GAP cannot handle the group.
EXAMPLES::
sage: G = SymmetricGroup(4) sage: g = G((1,2,3,4)) sage: ConjugacyClass(G,g) Conjugacy class of (1,2,3,4) in Symmetric group of order 4! as a permutation group sage: TestSuite(G).run() """ except (AttributeError, NotImplementedError): finite = False else: # If the group is not finite, then we do not know if we are finite or not
def _repr_(self): r""" EXAMPLES::
sage: G = SymmetricGroup(4) sage: g = G((1,2,3,4)) sage: C = ConjugacyClass(G,g) sage: C Conjugacy class of (1,2,3,4) in Symmetric group of order 4! as a permutation group """ self._parent)
def __eq__(self, other): r""" Equality of conjugacy classes is tested by comparing the underlying sets.
EXAMPLES::
sage: F = GF(5) sage: gens = [matrix(F,2,[1,2, -1, 1]), matrix(F,2, [1,1, 0,1])] sage: H = MatrixGroup(gens) sage: h = H(matrix(F,2,[1,2, -1, 1])) sage: h2 = H(matrix(F,2,[1,1, 0, 1])) sage: g = h2*h*h2^(-1) sage: C = ConjugacyClass(H,h) sage: D = ConjugacyClass(H,g) sage: C == D True """
def __ne__(self, other): """ Negation of equality.
EXAMPLES::
sage: F = GF(5) sage: gens = [matrix(F,2, [1,2,-1,1]), matrix(F,2, [1,1,0,1])] sage: H = MatrixGroup(gens) sage: h = H(matrix(F,2, [1,2,-1,1])) sage: h2 = H(matrix(F,2, [1,1,0,1])) sage: g = h2 * h * h2^(-1) sage: C = ConjugacyClass(H, h) sage: D = ConjugacyClass(H, g) sage: C != D False sage: C != ConjugacyClass(H, H(identity_matrix(F, 2))) True """
def __contains__(self, element): r""" Check if ``element`` belongs to the conjugacy class ``self``.
EXAMPLES::
sage: G = SymmetricGroup(4) sage: g = G((1,2,3,4)) sage: C = ConjugacyClass(G,g) sage: g in C True """
def __iter__(self): r""" Naive algorithm to give the elements of the conjugacy class.
.. TODO::
Implement a non-naive algorithm, cf. for instance G. Butler: "An Inductive Schema for Computing Conjugacy Classes in Permutation Groups", Math. of Comp. Vol. 62, No. 205 (1994)
EXAMPLES:
Groups of permutations::
sage: G = SymmetricGroup(3) sage: g = G((1,2)) sage: C = ConjugacyClass(G,g) sage: sorted(C) [(2,3), (1,2), (1,3)]
It works for infinite groups::
sage: a = matrix(ZZ,2,[1,1,0,1]) sage: b = matrix(ZZ,2,[1,0,1,1]) sage: G = MatrixGroup([a,b]) # takes 1s sage: a = G(a) sage: C = ConjugacyClass(G, a) sage: it = iter(C) sage: [next(it) for _ in range(5)] # random (nothing guarantees enumeration order) [ [1 1] [ 2 1] [ 0 1] [ 3 1] [ 3 4] [0 1], [-1 0], [-1 2], [-4 -1], [-1 -1] ]
We check that two matrices are in C::
sage: b = G(b) sage: m1 = b * a * ~b sage: m2 = ~b * a * b sage: any(x == m1 for x in C) True sage: any(x == m2 for x in C) True
""" lambda y: [c * y * c**-1 for c in gens], structure=None)
@cached_method def set(self): r""" Return the set of elements of the conjugacy class.
EXAMPLES:
Groups of permutations::
sage: G = SymmetricGroup(3) sage: g = G((1,2)) sage: C = ConjugacyClass(G,g) sage: S = [(2,3), (1,2), (1,3)] sage: C.set() == Set(G(x) for x in S) True
Groups of matrices over finite fields::
sage: F = GF(5) sage: gens = [matrix(F,2,[1,2, -1, 1]), matrix(F,2, [1,1, 0,1])] sage: H = MatrixGroup(gens) sage: h = H(matrix(F,2,[1,2, -1, 1])) sage: C = ConjugacyClass(H,h) sage: S = [[[3, 2], [2, 4]], [[0, 1], [2, 2]], [[3, 4], [1, 4]],\ [[0, 3], [4, 2]], [[1, 2], [4, 1]], [[2, 1], [2, 0]],\ [[4, 1], [4, 3]], [[4, 4], [1, 3]], [[2, 4], [3, 0]],\ [[1, 4], [2, 1]], [[3, 3], [3, 4]], [[2, 3], [4, 0]],\ [[0, 2], [1, 2]], [[1, 3], [1, 1]], [[4, 3], [3, 3]],\ [[4, 2], [2, 3]], [[0, 4], [3, 2]], [[1, 1], [3, 1]],\ [[2, 2], [1, 0]], [[3, 1], [4, 4]]] sage: C.set() == Set(H(x) for x in S) True
It is not implemented for infinite groups::
sage: a = matrix(ZZ,2,[1,1,0,1]) sage: b = matrix(ZZ,2,[1,0,1,1]) sage: G = MatrixGroup([a,b]) # takes 1s sage: g = G(a) sage: C = ConjugacyClass(G, g) sage: C.set() Traceback (most recent call last): ... NotImplementedError: Listing the elements of conjugacy classes is not implemented for infinite groups! Use the iter function instead. """ # return Set(self) creates an infinite loop in __contains__ else: "classes is not implemented for infinite groups! Use the " "iter function instead.")
def list(self): r""" Return a list with all the elements of ``self``.
EXAMPLES:
Groups of permutations::
sage: G = SymmetricGroup(3) sage: g = G((1,2,3)) sage: c = ConjugacyClass(G,g) sage: L = c.list() sage: Set(L) == Set([G((1,3,2)), G((1,2,3))]) True """ # return list(self) creates an infinite loop because list calls # __len__ which calls list... else: raise NotImplementedError("Listing the elements of conjugacy " "classes is not implemented for infinite groups! Use the " "iter function instead.")
def is_real(self): """ Check if ``self`` is real (closed for inverses).
EXAMPLES::
sage: G = SymmetricGroup(4) sage: g = G((1,2,3,4)) sage: c = ConjugacyClass(G,g) sage: c.is_real() True """
def is_rational(self): """ Check if ``self`` is rational (closed for powers).
EXAMPLES::
sage: G = SymmetricGroup(4) sage: g = G((1,2,3,4)) sage: c = ConjugacyClass(G,g) sage: c.is_rational() False """
def representative(self): """ Return a representative of ``self``.
EXAMPLES::
sage: G = SymmetricGroup(3) sage: g = G((1,2,3)) sage: C = ConjugacyClass(G,g) sage: C.representative() (1,2,3) """
an_element = representative
class ConjugacyClassGAP(ConjugacyClass): r""" Class for a conjugacy class for groups defined over GAP.
Intended for wrapping GAP methods on conjugacy classes.
INPUT:
- ``group`` -- the group in which the conjugacy class is taken
- ``element`` -- the element generating the conjugacy class
EXAMPLES::
sage: G = SymmetricGroup(4) sage: g = G((1,2,3,4)) sage: ConjugacyClassGAP(G,g) Conjugacy class of (1,2,3,4) in Symmetric group of order 4! as a permutation group """ def __init__(self, group, element): r""" Constructor for the class.
EXAMPLES:
Conjugacy classes for groups of permutations::
sage: G = SymmetricGroup(4) sage: g = G((1,2,3,4)) sage: ConjugacyClassGAP(G,g) Conjugacy class of (1,2,3,4) in Symmetric group of order 4! as a permutation group
Conjugacy classes for groups of matrices::
sage: F = GF(5) sage: gens = [matrix(F,2,[1,2, -1, 1]), matrix(F,2, [1,1, 0,1])] sage: H = MatrixGroup(gens) sage: h = H(matrix(F,2,[1,2, -1, 1])) sage: ConjugacyClassGAP(H,h) Conjugacy class of [1 2] [4 1] in Matrix group over Finite Field of size 5 with 2 generators ( [1 2] [1 1] [4 1], [0 1] ) """ # GAP interface except (AttributeError, TypeError): try: # LibGAP self._gap_group = group.gap() self._gap_representative = element.gap() except (AttributeError, TypeError): raise TypeError("The group %s cannot be defined as a GAP group" % group)
def _gap_(self): r""" Return the gap object corresponding to ``self``.
EXAMPLES::
sage: G = SymmetricGroup(3) sage: g = G((1,2,3)) sage: C = ConjugacyClassGAP(G,g) sage: C._gap_() ConjugacyClass( SymmetricGroup( [ 1 .. 3 ] ), (1,2,3) ) """
def cardinality(self): r""" Return the size of this conjugacy class.
EXAMPLES::
sage: W = WeylGroup(['C',6]) sage: cc = W.conjugacy_class(W.an_element()) sage: cc.cardinality() 3840 sage: type(cc.cardinality()) <type 'sage.rings.integer.Integer'> """
def __contains__(self, g): r""" Containment test.
Wraps ``IsConjugate`` from GAP.
TESTS::
sage: W = WeylGroup(['C',6]) sage: g0,g1,g2,g3,g4,g5 = W.gens() sage: cc = W.conjugacy_class(g0) sage: g0 in cc True sage: g1 in cc True sage: g2 in cc True sage: g3 in cc True sage: g4 in cc True sage: g5 in cc False
Only trivial cases are implemented for infinite groups::
sage: G = SL(2,ZZ) sage: m1 = G([[1,1],[0,1]]) sage: m2 = G([[1,0],[1,1]]) sage: m1 in G.conjugacy_class(m1) and m2 in G.conjugacy_class(m2) True sage: m2 in G.conjugacy_class(m1) Traceback (most recent call last): ... NotImplementedError: only implemented for finite groups """
except (AttributeError, NotImplementedError): finite = False
@cached_method def set(self): r""" Return a Sage ``Set`` with all the elements of the conjugacy class.
By default attempts to use GAP construction of the conjugacy class. If GAP method is not implemented for the given group, and the group is finite, falls back to a naive algorithm.
.. WARNING::
The naive algorithm can be really slow and memory intensive.
EXAMPLES:
Groups of permutations::
sage: G = SymmetricGroup(4) sage: g = G((1,2,3,4)) sage: C = ConjugacyClassGAP(G,g) sage: S = [(1,3,2,4), (1,4,3,2), (1,3,4,2), (1,2,3,4), (1,4,2,3), (1,2,4,3)] sage: C.set() == Set(G(x) for x in S) True
""" except NotImplementedError: # If GAP doesn't work, fall back to naive method return ConjugacyClass.set.f(self) # Need the f because the base-class method is also cached |