def __init__(self, domain, prefix): """ EXAMPLES:: sage: G = WeylGroup(['B',3]) sage: TestSuite(G).run() sage: cm = CartanMatrix([[2,-5,0],[-2,2,-1],[0,-1,2]]) sage: W = WeylGroup(cm) sage: TestSuite(W).run() # long time """ self._domain = domain if self.cartan_type().is_affine(): category = AffineWeylGroups() elif self.cartan_type().is_finite(): category = FiniteWeylGroups() else: category = WeylGroups() if self.cartan_type().is_irreducible(): category = category.Irreducible() self.n = domain.dimension() # Really needed? self._prefix = prefix # FinitelyGeneratedMatrixGroup_gap takes plain matrices as input gens_matrix = [self.morphism_matrix(self.domain().simple_reflection(i)) for i in self.index_set()] from sage.libs.all import libgap libgap_group = libgap.Group(gens_matrix) degree = ZZ(self.domain().dimension()) ring = self.domain().base_ring() FinitelyGeneratedMatrixGroup_gap.__init__( self, degree, ring, libgap_group, category=category)
def __setstate__(self, state): """ Restore from old pickle. EXAMPLES:: sage: from sage.groups.matrix_gps.pickling_overrides import LegacyMatrixGroup sage: state = dict() sage: state['_MatrixGroup_gap__n'] = 2 sage: state['_MatrixGroup_gap__R'] = GF(3) sage: state['_gensG'] = [ matrix(GF(3), [[1,2],[0,1]]) ] sage: M = LegacyMatrixGroup.__new__(LegacyMatrixGroup) sage: M.__setstate__(state) sage: M Matrix group over Finite Field of size 3 with 1 generators ( [1 2] [0 1] ) """ matrix_gens = state['_gensG'] ring = state['_MatrixGroup_gap__R'] degree = state['_MatrixGroup_gap__n'] from sage.libs.all import libgap libgap_group = libgap.Group(libgap(matrix_gens)) self.__init__(degree, ring, libgap_group)
def word_problem(self, gens=None): r""" Solve the word problem. This method writes the group element as a product of the elements of the list ``gens``, or the standard generators of the parent of self if ``gens`` is None. INPUT: - ``gens`` -- a list/tuple/iterable of elements (or objects that can be converted to group elements), or ``None`` (default). By default, the generators of the parent group are used. OUTPUT: A factorization object that contains information about the order of factors and the exponents. A ``ValueError`` is raised if the group element cannot be written as a word in ``gens``. ALGORITHM: Use GAP, which has optimized algorithms for solving the word problem (the GAP functions ``EpimorphismFromFreeGroup`` and ``PreImagesRepresentative``). EXAMPLE:: sage: G = GL(2,5); G General Linear Group of degree 2 over Finite Field of size 5 sage: G.gens() ( [2 0] [4 1] [0 1], [4 0] ) sage: G(1).word_problem([G.gen(0)]) 1 sage: type(_) <class 'sage.structure.factorization.Factorization'> sage: g = G([0,4,1,4]) sage: g.word_problem() ([4 1] [4 0])^-1 Next we construct a more complicated element of the group from the generators:: sage: s,t = G.0, G.1 sage: a = (s * t * s); b = a.word_problem(); b ([2 0] [0 1]) * ([4 1] [4 0]) * ([2 0] [0 1]) sage: flatten(b) [ [2 0] [4 1] [2 0] [0 1], 1, [4 0], 1, [0 1], 1 ] sage: b.prod() == a True We solve the word problem using some different generators:: sage: s = G([2,0,0,1]); t = G([1,1,0,1]); u = G([0,-1,1,0]) sage: a.word_problem([s,t,u]) ([2 0] [0 1])^-1 * ([1 1] [0 1])^-1 * ([0 4] [1 0]) * ([2 0] [0 1])^-1 We try some elements that don't actually generate the group:: sage: a.word_problem([t,u]) Traceback (most recent call last): ... ValueError: word problem has no solution AUTHORS: - David Joyner and William Stein - David Loeffler (2010): fixed some bugs - Volker Braun (2013): LibGAP """ from sage.libs.gap.libgap import libgap G = self.parent() if gens: gen = lambda i: gens[i] H = libgap.Group([G(x).gap() for x in gens]) else: gen = G.gen H = G.gap() hom = H.EpimorphismFromFreeGroup() preimg = hom.PreImagesRepresentative(self.gap()) if preimg.is_bool(): assert preimg == libgap.eval('fail') raise ValueError('word problem has no solution') result = [] n = preimg.NumberSyllables().sage() exponent_syllable = libgap.eval('ExponentSyllable') generator_syllable = libgap.eval('GeneratorSyllable') for i in range(n): exponent = exponent_syllable(preimg, i + 1).sage() generator = gen(generator_syllable(preimg, i + 1).sage() - 1) result.append((generator, exponent)) from sage.structure.factorization import Factorization result = Factorization(result) result._set_cr(True) return result