code
stringlengths
17
6.64M
class AlgebraMorphism(ModuleMorphismByLinearity): '\n An algebra morphism of the Askey-Wilson algebra defined by\n the images of the generators.\n ' def __init__(self, domain, on_generators, position=0, codomain=None, category=None): '\n Given a map on the multiplicative basis of a free algebra, this method\n returns the algebra morphism that is the linear extension of its image\n on generators.\n\n INPUT:\n\n - ``domain`` -- an Askey-Wilson algebra\n - ``on_generators`` -- a list of length 6 corresponding to\n the images of the generators\n - ``codomain`` -- (optional) the codomain\n - ``position`` -- (default: 0) integer\n - ``category`` -- (optional) category\n\n OUTPUT:\n\n - module morphism\n\n EXAMPLES::\n\n sage: AW = algebras.AskeyWilson(QQ)\n sage: sigma = AW.sigma()\n sage: TestSuite(sigma).run()\n ' if (category is None): category = Algebras(Rings().Commutative()).WithBasis() self._on_generators = tuple(on_generators) ModuleMorphismByLinearity.__init__(self, domain=domain, codomain=codomain, position=position, category=category) def __eq__(self, other): '\n Check equality.\n\n EXAMPLES::\n\n sage: from sage.algebras.askey_wilson import AlgebraMorphism\n sage: AW = algebras.AskeyWilson(QQ)\n sage: rho = AW.rho()\n sage: sigma = AW.sigma()\n sage: id = AlgebraMorphism(AW, AW.gens(), codomain=AW)\n sage: sigma * sigma == id\n True\n sage: id == rho * rho * rho\n True\n ' return ((self.__class__ is other.__class__) and (self.parent() == other.parent()) and (self._zero == other._zero) and (self._on_generators == other._on_generators) and (self._position == other._position) and (self._is_module_with_basis_over_same_base_ring == other._is_module_with_basis_over_same_base_ring)) def _on_basis(self, c): '\n Computes the image of this morphism on the basis element\n indexed by ``c``.\n\n INPUT:\n\n - ``c`` -- a tuple of length 6\n\n OUTPUT:\n\n - element of the codomain\n\n EXAMPLES::\n\n sage: AW = algebras.AskeyWilson(QQ)\n sage: AW.inject_variables()\n Defining A, B, C, a, b, g\n sage: rho = AW.rho()\n sage: sigma = AW.sigma()\n sage: rho._on_basis((2,1,1,2,0,5))\n q^2*A*B^2*C*a^5*b^2 + (q^-3-q)*B^3*a^5*b^2 - (q^-2-1)*B^2*a^5*b^3\n - (q^-3-q^5)*B*C^2*a^5*b^2 + (q^-2-q^2)*B*C*a^5*b^2*g\n + (q^-2-2*q^2+q^6)*A*C*a^5*b^2 - (q^-1-q-q^3+q^5)*C*a^6*b^2\n\n sage: sigma._on_basis((2,1,1,2,0,5))\n -q^9*A^2*B^3*b^2*g^5 + (q^2-q^10-q^14)*A*B^2*C*b^2*g^5\n - (q^3-q^7-q^9)*A*B^2*b^2*g^6\n - (2*q-q^5-3*q^9+q^13+q^17)*A^2*B*b^2*g^5\n + (1-q^6-q^8+q^14)*A*B*a*b^2*g^5 + (q^-3-q-q^5+q^9)*B^3*b^2*g^5\n - (q^-2-1-q^6+q^8)*B^2*b^3*g^5 + (q^5-q^13)*B*C^2*b^2*g^5\n - (q^2+q^6-2*q^10)*B*C*b^2*g^6 + (q^3-q^7)*B*b^2*g^7\n + (q^-6-4*q^2+2*q^6+2*q^10-q^18)*A*C*b^2*g^5\n - (q^-3+q^-1-3*q-2*q^3+q^5+2*q^7+2*q^9-2*q^11+q^15-q^17)*A*b^2*g^6\n - (q^-3-2*q-q^3+q^5+q^7+q^9-q^13)*C*a*b^2*g^5\n + (q^-2-1-q^2-q^4+2*q^6+2*q^8-2*q^10)*a*b^2*g^6\n + (q^-7-3*q^-3+2*q+2*q^5-3*q^9+q^13)*B*b^2*g^5\n - (q^-6-q^-4-2*q^-2+2+2*q^6-2*q^8-q^10+q^12)*b^3*g^5\n\n sage: rho(B*A)\n q^2*B*C - (q^-1-q^3)*A + (1-q^2)*a\n sage: rho(A*B)\n B*C\n sage: rho(A*B*C)\n A*B*C + (q^-3-q)*B^2 - (q^-2-1)*B*b - (q^-3-q)*C^2 + (q^-2-1)*C*g\n sage: rho(B*C*A)\n A*B*C - (q^-3-q)*A^2 + (q^-2-1)*A*a + (q^-3-q)*B^2 - (q^-2-1)*B*b\n sage: rho(C*A*B)\n A*B*C\n\n sage: rho(C^2*a*b^6*g^2)\n A^2*a^2*b*g^6\n\n sage: sigma(C^2)\n q^4*A^2*B^2 + (q^3+q^7)*A*B*C - (q^2+q^4)*A*B*g\n - (q^4-q^8)*A^2 + (q^5-q^7)*A*a + (1-q^4)*B^2\n - (q-q^3)*B*b + q^4*C^2 - 2*q^3*C*g + q^2*g^2\n sage: sigma(A*B)\n q^2*A*B - (q^-1-q^3)*C + (1-q^2)*g\n sage: sigma(C + 3*g*A*B)\n 3*q^2*A*B*g - q*A*B - (3*q^-1-3*q^3)*C*g\n + (3-3*q^2)*g^2 - q^2*C + q*g\n ' return self.codomain().prod(((self._on_generators[i] ** exp) for (i, exp) in enumerate(c))) def _composition_(self, right, homset): '\n Return the composition of ``self`` and ``right`` in ``homset``.\n\n EXAMPLES::\n\n sage: AW = algebras.AskeyWilson(QQ)\n sage: rho = AW.rho()\n sage: sigma = AW.sigma()\n sage: s2 = sigma * sigma\n sage: s2._on_generators\n (A, B, C, a, b, g)\n sage: sr = sigma * rho\n sage: sr._on_generators\n (C, B, -q*B*C - q^2*A + q*a, g, b, a)\n sage: rs = rho * sigma\n sage: rs._on_generators\n (A, -q*A*B - q^2*C + q*g, B, a, g, b)\n ' if isinstance(right, AlgebraMorphism): cat = homset.homset_category() return AlgebraMorphism(homset.domain(), [right(g) for g in self._on_generators], codomain=homset.codomain(), category=cat) return super()._composition_(right, homset)
class AssociatedGradedAlgebra(CombinatorialFreeModule): "\n The associated graded algebra/module `\\operatorname{gr} A`\n of a filtered algebra/module with basis `A`.\n\n Let `A` be a filtered module over a commutative ring `R`.\n Let `(F_i)_{i \\in I}` be the filtration of `A`, with `I` being\n a totally ordered set. Define\n\n .. MATH::\n\n G_i = F_i / \\sum_{j < i} F_j\n\n for every `i \\in I`, and then\n\n .. MATH::\n\n \\operatorname{gr} A = \\bigoplus_{i \\in I} G_i.\n\n There are canonical projections `p_i : F_i \\to G_i` for\n every `i \\in I`. Moreover `\\operatorname{gr} A` is naturally a\n graded `R`-module with `G_i` being the `i`-th graded component.\n This graded `R`-module is known as the *associated graded module*\n (or, for short, just *graded module*) of `A`.\n\n Now, assume that `A` (endowed with the filtration\n `(F_i)_{i \\in I}`) is not just a filtered `R`-module, but also\n a filtered `R`-algebra.\n Let `u \\in G_i` and `v \\in G_j`, and let `u' \\in F_i` and\n `v' \\in F_j` be lifts of `u` and `v`, respectively (so that\n `u = p_i(u')` and `v = p_j(v')`). Then, we define a\n multiplication `*` on `\\operatorname{gr} A` (not to be mistaken\n for the multiplication of the original algebra `A`) by\n\n .. MATH::\n\n u * v = p_{i+j} (u' v').\n\n The *associated graded algebra* (or, for short, just\n *graded algebra*) of `A` is the graded algebra\n `\\operatorname{gr} A` (endowed with this multiplication).\n\n Now, assume that `A` is a filtered `R`-algebra with basis.\n Let `(b_x)_{x \\in X}` be the basis of `A`,\n and consider the partition `X = \\bigsqcup_{i \\in I} X_i` of\n the set `X`, which is part of the data of a filtered\n algebra with basis. We know (see\n :class:`~sage.categories.filtered_modules_with_basis.FilteredModulesWithBasis`)\n that `A` (being a filtered `R`-module with basis) is canonically\n (when the basis is considered to be part of the data)\n isomorphic to `\\operatorname{gr} A` as an `R`-module. Therefore\n the `k`-th graded component `G_k` can be identified with\n the span of `(b_x)_{x \\in X_k}`, or equivalently the\n `k`-th homogeneous component of `A`. Suppose\n that `u' v' = \\sum_{k \\leq i+j} m_k` where `m_k \\in G_k` (which\n has been identified with the `k`-th homogeneous component of `A`).\n Then `u * v = m_{i+j}`. We also note that the choice of\n identification of `G_k` with the `k`-th homogeneous component\n of `A` depends on the given basis.\n\n The basis `(b_x)_{x \\in X}` of `A` gives rise to a basis\n of `\\operatorname{gr} A`. This latter basis is still indexed\n by the elements of `X`, and consists of the images of the\n `b_x` under the `R`-module isomorphism from `A` to\n `\\operatorname{gr} A`. It makes `\\operatorname{gr} A` into\n a graded `R`-algebra with basis.\n\n In this class, the `R`-module isomorphism from `A` to\n `\\operatorname{gr} A` is implemented as\n :meth:`to_graded_conversion` and also as the default\n conversion from `A` to `\\operatorname{gr} A`. Its\n inverse map is implemented as\n :meth:`from_graded_conversion`.\n The projection `p_i : F_i \\to G_i` is implemented as\n :meth:`projection` ``(i)``.\n\n INPUT:\n\n - ``A`` -- a filtered module (or algebra) with basis\n\n OUTPUT:\n\n The associated graded module of `A`, if `A` is just a filtered\n `R`-module.\n The associated graded algebra of `A`, if `A` is a filtered\n `R`-algebra.\n\n EXAMPLES:\n\n Associated graded module of a filtered module::\n\n sage: A = Modules(QQ).WithBasis().Filtered().example()\n sage: grA = A.graded_algebra()\n sage: grA.category()\n Category of graded vector spaces with basis over Rational Field\n sage: x = A.basis()[Partition([3,2,1])]\n sage: grA(x)\n Bbar[[3, 2, 1]]\n\n Associated graded algebra of a filtered algebra::\n\n sage: A = Algebras(QQ).WithBasis().Filtered().example()\n sage: grA = A.graded_algebra()\n sage: grA.category()\n Category of graded algebras with basis over Rational Field\n sage: x,y,z = [grA.algebra_generators()[s] for s in ['x','y','z']]\n sage: x\n bar(U['x'])\n sage: y * x + z\n bar(U['x']*U['y']) + bar(U['z'])\n sage: A(y) * A(x) + A(z)\n U['x']*U['y']\n\n We note that the conversion between ``A`` and ``grA`` is\n the canonical ``QQ``-module isomorphism stemming from the\n fact that the underlying ``QQ``-modules of ``A`` and\n ``grA`` are isomorphic::\n\n sage: grA(A.an_element())\n bar(U['x']^2*U['y']^2*U['z']^3) + 2*bar(U['x']) + 3*bar(U['y']) + bar(1)\n sage: elt = A.an_element() + A.algebra_generators()['x'] + 2\n sage: grelt = grA(elt); grelt\n bar(U['x']^2*U['y']^2*U['z']^3) + 3*bar(U['x']) + 3*bar(U['y']) + 3*bar(1)\n sage: A(grelt) == elt\n True\n\n .. TODO::\n\n The algebra ``A`` must currently be an instance of (a subclass of)\n :class:`CombinatorialFreeModule`. This should work with any\n filtered algebra with a basis.\n\n .. TODO::\n\n Implement a version of associated graded algebra for\n filtered algebras without a distinguished basis.\n\n REFERENCES:\n\n - :wikipedia:`Filtered_algebra#Associated_graded_algebra`\n " def __init__(self, A, category=None): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: A = Algebras(QQ).WithBasis().Filtered().example()\n sage: grA = A.graded_algebra()\n sage: TestSuite(grA).run(elements=[prod(grA.algebra_generators())])\n ' if (A not in ModulesWithBasis(A.base_ring().category()).Filtered()): raise ValueError('the base algebra must be filtered and with basis') self._A = A base_ring = A.base_ring() base_one = base_ring.one() category = A.category().Graded().or_subcategory(category) try: opts = copy(A.print_options()) if ((not opts['prefix']) and (not opts['bracket'])): opts['bracket'] = '(' opts['prefix'] = (opts['prefix'] + 'bar') except AttributeError: opts = {'prefix': 'Abar'} CombinatorialFreeModule.__init__(self, base_ring, A.basis().keys(), category=category, **opts) phi = self.module_morphism(diagonal=(lambda x: base_one), codomain=A) self._A.register_conversion(phi) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: A = Algebras(QQ).WithBasis().Filtered().example()\n sage: A.graded_algebra()\n Graded Algebra of An example of a filtered algebra with basis:\n the universal enveloping algebra of Lie algebra of RR^3\n with cross product over Rational Field\n ' from sage.categories.algebras_with_basis import AlgebrasWithBasis if (self in AlgebrasWithBasis): return 'Graded Algebra of {}'.format(self._A) return 'Graded Module of {}'.format(self._A) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: A = Algebras(QQ).WithBasis().Filtered().example()\n sage: latex(A.graded_algebra())\n \\operatorname{gr} ...\n ' from sage.misc.latex import latex return ('\\operatorname{gr} ' + latex(self._A)) def _element_constructor_(self, x): "\n Construct an element of ``self`` from ``x``.\n\n If ``self`` `= \\operatorname{gr} A` for a filtered algebra\n `A` with basis, and if ``x`` is an element of `A`, then\n this returns the image of `x` under the canonical `R`-module\n isomorphism `A \\to \\operatorname{gr} A`. (In this case,\n this is equivalent to calling\n ``self.to_graded_conversion()(x)``.)\n\n EXAMPLES::\n\n sage: A = Algebras(QQ).WithBasis().Filtered().example()\n sage: grA = A.graded_algebra()\n sage: grA(A.an_element())\n bar(U['x']^2*U['y']^2*U['z']^3)\n + 2*bar(U['x']) + 3*bar(U['y']) + bar(1)\n sage: grA(A.an_element() + A.algebra_generators()['x'] + 2)\n bar(U['x']^2*U['y']^2*U['z']^3)\n + 3*bar(U['x']) + 3*bar(U['y']) + 3*bar(1)\n " if isinstance(x, CombinatorialFreeModule.Element): if (x.parent() is self._A): return self._from_dict(dict(x)) return super()._element_constructor_(x) def gen(self, *args, **kwds): "\n Return a generator of ``self``.\n\n EXAMPLES::\n\n sage: A = Algebras(QQ).WithBasis().Filtered().example()\n sage: grA = A.graded_algebra()\n sage: grA.gen('x')\n bar(U['x'])\n " try: x = self._A.gen(*args, **kwds) except AttributeError: x = self._A.algebra_generators()[args[0]] return self(x) @cached_method def algebra_generators(self): "\n Return the algebra generators of ``self``.\n\n This assumes that the algebra generators of `A` provided by\n its ``algebra_generators`` method are homogeneous.\n\n EXAMPLES::\n\n sage: A = Algebras(QQ).WithBasis().Filtered().example()\n sage: grA = A.graded_algebra()\n sage: grA.algebra_generators()\n Finite family {'x': bar(U['x']), 'y': bar(U['y']), 'z': bar(U['z'])}\n " G = self._A.algebra_generators() return Family(G.keys(), (lambda x: self(G[x])), name='generator') def degree_on_basis(self, x): '\n Return the degree of the basis element indexed by ``x``.\n\n EXAMPLES::\n\n sage: A = Algebras(QQ).WithBasis().Filtered().example()\n sage: grA = A.graded_algebra()\n sage: all(A.degree_on_basis(x) == grA.degree_on_basis(x)\n ....: for g in grA.algebra_generators() for x in g.support())\n True\n ' return self._A.degree_on_basis(x) @cached_method def one_basis(self): '\n Return the basis index of the element `1` of\n `\\operatorname{gr} A`.\n\n This assumes that the unity `1` of `A` belongs to `F_0`.\n\n EXAMPLES::\n\n sage: A = Algebras(QQ).WithBasis().Filtered().example()\n sage: grA = A.graded_algebra()\n sage: grA.one_basis()\n 1\n ' return self._A.one_basis() def product_on_basis(self, x, y): "\n Return the product on basis elements given by the\n indices ``x`` and ``y``.\n\n EXAMPLES::\n\n sage: A = Algebras(QQ).WithBasis().Filtered().example()\n sage: grA = A.graded_algebra()\n sage: G = grA.algebra_generators()\n sage: x,y,z = G['x'], G['y'], G['z']\n sage: x * y # indirect doctest\n bar(U['x']*U['y'])\n sage: y * x\n bar(U['x']*U['y'])\n sage: z * y * x\n bar(U['x']*U['y']*U['z'])\n " ret = self._A.product_on_basis(x, y) deg = (self._A.degree_on_basis(x) + self._A.degree_on_basis(y)) return self.sum_of_terms([(i, c) for (i, c) in ret if (self._A.degree_on_basis(i) == deg)], distinct=True)
class CellularBasis(CombinatorialFreeModule): '\n The cellular basis of a cellular algebra, in the sense of\n Graham and Lehrer [GrLe1996]_.\n\n INPUT:\n\n - ``A`` -- the cellular algebra\n\n EXAMPLES:\n\n We compute a cellular basis and do some basic computations::\n\n sage: S = SymmetricGroupAlgebra(QQ, 3)\n sage: C = S.cellular_basis()\n sage: C\n Cellular basis of Symmetric group algebra of order 3\n over Rational Field\n sage: len(C.basis())\n 6\n sage: len(S.basis())\n 6\n sage: a,b,c,d,e,f = C.basis()\n sage: f\n C([3], [[1, 2, 3]], [[1, 2, 3]])\n sage: c\n C([2, 1], [[1, 3], [2]], [[1, 2], [3]])\n sage: d\n C([2, 1], [[1, 2], [3]], [[1, 3], [2]])\n sage: f * f\n C([3], [[1, 2, 3]], [[1, 2, 3]])\n sage: f * c\n 0\n sage: d * c\n C([2, 1], [[1, 2], [3]], [[1, 2], [3]])\n sage: c * d\n C([2, 1], [[1, 3], [2]], [[1, 3], [2]])\n sage: S(f)\n 1/6*[1, 2, 3] + 1/6*[1, 3, 2] + 1/6*[2, 1, 3] + 1/6*[2, 3, 1]\n + 1/6*[3, 1, 2] + 1/6*[3, 2, 1]\n sage: S(d)\n 1/4*[1, 3, 2] - 1/4*[2, 3, 1] + 1/4*[3, 1, 2] - 1/4*[3, 2, 1]\n sage: B = list(S.basis())\n sage: B[2]\n [2, 1, 3]\n sage: C(B[2])\n -C([1, 1, 1], [[1], [2], [3]], [[1], [2], [3]])\n + C([2, 1], [[1, 2], [3]], [[1, 2], [3]])\n - C([2, 1], [[1, 3], [2]], [[1, 3], [2]])\n + C([3], [[1, 2, 3]], [[1, 2, 3]])\n ' def __init__(self, A, to_algebra=None, from_algebra=None, **kwargs): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: S = SymmetricGroupAlgebra(QQ, 3)\n sage: C = S.cellular_basis()\n sage: TestSuite(C).run()\n ' self._algebra = A I = [(la, s, t) for la in A.cell_poset() for s in A.cell_module_indices(la) for t in A.cell_module_indices(la)] prefix = kwargs.pop('prefix', 'C') cat = Algebras(A.category().base_ring()).FiniteDimensional().WithBasis().Cellular() CombinatorialFreeModule.__init__(self, A.base_ring(), I, prefix=prefix, bracket=False, category=cat, **kwargs) if (from_algebra is None): from_algebra = A._to_cellular_element if (to_algebra is None): to_algebra = A._from_cellular_index if (from_algebra is not NotImplemented): to_cellular = A.module_morphism(from_algebra, codomain=self, category=cat) if (to_algebra is NotImplemented): from_cellular = (~ to_cellular) else: from_cellular = self.module_morphism(to_algebra, codomain=A, category=cat) if (from_algebra is NotImplemented): to_cellular = (~ from_cellular) to_cellular.register_as_coercion() from_cellular.register_as_coercion() def _repr_(self): '\n String representation of ``self``.\n\n EXAMPLES::\n\n sage: S = SymmetricGroupAlgebra(QQ, 3)\n sage: S.cellular_basis()\n Cellular basis of Symmetric group algebra of order 3 over Rational Field\n ' return 'Cellular basis of {}'.format(self._algebra) def _latex_term(self, x): "\n Return a latex representation of the term indexed by ``x``.\n\n EXAMPLES::\n\n sage: S = SymmetricGroupAlgebra(QQ, 3)\n sage: C = S.cellular_basis()\n sage: s = Tableau([[1,2],[3]])\n sage: C._latex_term((Partition([2,1]), s, s))\n 'C^{...}_{\\\\left(...\\\\right)}'\n " from sage.misc.latex import latex la = x[0] m = (x[1], x[2]) sla = latex(la) if (sla.find('\\text{\\textt') != (- 1)): sla = str(la) sm = latex(m) if (sm.find('\\text{\\textt') != (- 1)): sm = str(m) return ('C^{%s}_{%s}' % (sla, sm)) def cellular_basis_of(self): '\n Return the defining algebra of ``self``.\n\n EXAMPLES::\n\n sage: S = SymmetricGroupAlgebra(QQ, 3)\n sage: C = S.cellular_basis()\n sage: C.cellular_basis_of() is S\n True\n ' return self._algebra def cell_poset(self): '\n Return the cell poset of ``self``.\n\n EXAMPLES::\n\n sage: S = SymmetricGroupAlgebra(QQ, 3)\n sage: C = S.cellular_basis()\n sage: C.cell_poset()\n Finite poset containing 3 elements\n ' return self._algebra.cell_poset() def cell_module_indices(self, la): '\n Return the indices of the cell module of ``self``\n indexed by ``la`` .\n\n This is the finite set `M(\\lambda)`.\n\n EXAMPLES::\n\n sage: S = SymmetricGroupAlgebra(QQ, 3)\n sage: C = S.cellular_basis()\n sage: C.cell_module_indices([2,1])\n Standard tableaux of shape [2, 1]\n ' return self._algebra.cell_module_indices(la) def cellular_basis(self): '\n Return the cellular basis of ``self``, which is ``self``.\n\n EXAMPLES::\n\n sage: S = SymmetricGroupAlgebra(QQ, 3)\n sage: C = S.cellular_basis()\n sage: C.cellular_basis() is C\n True\n ' return self @cached_method def one(self): '\n Return the element `1` in ``self``.\n\n EXAMPLES::\n\n sage: S = SymmetricGroupAlgebra(QQ, 3)\n sage: C = S.cellular_basis()\n sage: C.one()\n C([1, 1, 1], [[1], [2], [3]], [[1], [2], [3]])\n + C([2, 1], [[1, 2], [3]], [[1, 2], [3]])\n + C([2, 1], [[1, 3], [2]], [[1, 3], [2]])\n + C([3], [[1, 2, 3]], [[1, 2, 3]])\n ' return self(self._algebra.one()) @cached_method def product_on_basis(self, x, y): '\n Return the product of basis indices by ``x`` and ``y``.\n\n EXAMPLES::\n\n sage: S = SymmetricGroupAlgebra(QQ, 3)\n sage: C = S.cellular_basis()\n sage: la = Partition([2,1])\n sage: s = StandardTableau([[1,2],[3]])\n sage: t = StandardTableau([[1,3],[2]])\n sage: C.product_on_basis((la, s, t), (la, s, t))\n 0\n ' A = self._algebra return self((A(self.monomial(x)) * A(self.monomial(y))))
class CliffordAlgebraIndices(UniqueRepresentation, Parent): '\n A facade parent for the indices of Clifford algebra.\n Users should not create instances of this class directly.\n ' def __init__(self, Qdim): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices\n sage: idx = CliffordAlgebraIndices(7)\n sage: idx._nbits\n 7\n sage: idx._cardinality\n 128\n sage: i = idx.an_element(); i\n 1111\n sage: type(i)\n <class 'sage.data_structures.bitset.FrozenBitset'>\n " self._nbits = Qdim self._cardinality = (2 ** Qdim) category = FiniteEnumeratedSets().Facade() Parent.__init__(self, category=category, facade=True) def _element_constructor_(self, x): '\n Construct an element of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices\n sage: idx = CliffordAlgebraIndices(7)\n sage: idx([1,3,6])\n 0101001\n sage: for i in range(7): print(idx(i))\n 1\n 01\n 001\n 0001\n 00001\n 000001\n 0000001\n ' if isinstance(x, (list, tuple, set, frozenset)): if (len(x) > self._nbits): raise ValueError(f'x={x!r} is too long') return FrozenBitset(x) if isinstance(x, int): return FrozenBitset((x,)) def __call__(self, el): '\n EXAMPLES::\n\n sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices\n sage: idx = CliffordAlgebraIndices(7)\n sage: idx([1,3,6])\n 0101001\n sage: E = ExteriorAlgebra(QQ, 7)\n sage: B = E.basis()\n ' if (not isinstance(el, Element)): return self._element_constructor_(el) else: return Parent.__call__(self, el) def cardinality(self): '\n Return the cardinality of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices\n sage: idx = CliffordAlgebraIndices(7)\n sage: idx.cardinality() == 2^7\n True\n sage: len(idx) == 2^7\n True\n ' return self._cardinality __len__ = cardinality def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices\n sage: CliffordAlgebraIndices(7)\n Subsets of {0,1,...,6}\n sage: CliffordAlgebraIndices(0)\n Subsets of {}\n sage: CliffordAlgebraIndices(1)\n Subsets of {0}\n sage: CliffordAlgebraIndices(2)\n Subsets of {0,1}\n ' if (self._nbits == 0): return 'Subsets of {}' if (self._nbits == 1): return 'Subsets of {0}' if (self._nbits == 2): return 'Subsets of {0,1}' return f'Subsets of {{0,1,...,{(self._nbits - 1)}}}' def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices\n sage: latex(CliffordAlgebraIndices(7))\n \\mathcal{P}({0,1,\\ldots,6})\n sage: latex(CliffordAlgebraIndices(0))\n \\mathcal{P}(\\emptyset)\n sage: latex(CliffordAlgebraIndices(1))\n \\mathcal{P}({0})\n sage: latex(CliffordAlgebraIndices(2))\n \\mathcal{P}({0,1})\n ' if (self._nbits == 0): return '\\mathcal{P}(\\emptyset)' if (self._nbits == 1): return '\\mathcal{P}({0})' if (self._nbits == 2): return '\\mathcal{P}({0,1})' return f'\mathcal{{P}}({{0,1,\ldots,{(self._nbits - 1)}}})' def __iter__(self): '\n Iterate over ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices\n sage: idx = CliffordAlgebraIndices(3)\n sage: for i in idx:\n ....: print(i)\n 0\n 1\n 01\n 001\n 11\n 101\n 011\n 111\n ' import itertools n = self._nbits (yield FrozenBitset()) k = 1 while (k <= n): for C in itertools.combinations(range(n), k): (yield FrozenBitset(C)) k += 1 def __contains__(self, elt): "\n Check containment of ``elt`` in ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices\n sage: idx = CliffordAlgebraIndices(3)\n sage: int(8) in idx # representing the set {4}\n False\n sage: int(5) in idx # representing the set {1,3}\n True\n sage: FrozenBitset('1') in idx\n True\n sage: FrozenBitset('000001') in idx\n False\n " if isinstance(elt, int): return ((elt < self._cardinality) and (elt >= 0)) if (not isinstance(elt, FrozenBitset)): return False return (elt.capacity() <= self._nbits) def _an_element_(self): '\n Return an element of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.clifford_algebra import CliffordAlgebraIndices\n sage: idx = CliffordAlgebraIndices(0)\n sage: idx._an_element_()\n 0\n sage: idx = CliffordAlgebraIndices(1)\n sage: idx._an_element_()\n 1\n sage: idx = CliffordAlgebraIndices(2)\n sage: idx._an_element_()\n 01\n sage: idx = CliffordAlgebraIndices(3)\n sage: idx._an_element_()\n 11\n ' if (not self._nbits): return FrozenBitset() from sage.combinat.subset import SubsetsSorted X = SubsetsSorted(range(self._nbits)) return FrozenBitset(X.an_element())
class CliffordAlgebra(CombinatorialFreeModule): "\n The Clifford algebra of a quadratic form.\n\n Let `Q : V \\to \\mathbf{k}` denote a quadratic form on a vector space `V`\n over a field `\\mathbf{k}`. The Clifford algebra `Cl(V, Q)` is defined as\n `T(V) / I_Q` where `T(V)` is the tensor algebra of `V` and `I_Q` is the\n two-sided ideal generated by all elements of the form `v \\otimes v - Q(v)`\n for all `v \\in V`.\n\n We abuse notation to denote the projection of a pure tensor\n `x_1 \\otimes x_2 \\otimes \\cdots \\otimes x_m \\in T(V)` onto\n `T(V) / I_Q = Cl(V, Q)` by `x_1 \\wedge x_2 \\wedge \\cdots \\wedge x_m`.\n This is motivated by the fact that `Cl(V, Q)` is the exterior algebra\n `\\wedge V` when `Q = 0` (one can also think of a Clifford algebra as\n a quantization of the exterior algebra). See :class:`ExteriorAlgebra`\n for the concept of an exterior algebra.\n\n From the definition, a basis of `Cl(V, Q)` is given by monomials of\n the form\n\n .. MATH::\n\n \\{ e_{i_1} \\wedge \\cdots \\wedge e_{i_k} \\mid 1 \\leq i_1 < \\cdots <\n i_k \\leq n \\},\n\n where `n = \\dim(V)` and where `\\{ e_1, e_2, \\cdots, e_n \\}` is any\n fixed basis of `V`. Hence\n\n .. MATH::\n\n \\dim(Cl(V, Q)) = \\sum_{k=0}^n \\binom{n}{k} = 2^n.\n\n .. NOTE::\n\n The algebra `Cl(V, Q)` is a `\\ZZ / 2\\ZZ`-graded algebra, but not\n (in general) `\\ZZ`-graded (in a reasonable way).\n\n This construction satisfies the following universal property. Let\n `i : V \\to Cl(V, Q)` denote the natural inclusion (which is an\n embedding). Then for every associative `\\mathbf{k}`-algebra `A`\n and any `\\mathbf{k}`-linear map `j : V \\to A` satisfying\n\n .. MATH::\n\n j(v)^2 = Q(v) \\cdot 1_A\n\n for all `v \\in V`, there exists a unique `\\mathbf{k}`-algebra\n homomorphism `f : Cl(V, Q) \\to A` such that `f \\circ i = j`.\n This property determines the Clifford algebra uniquely up to\n canonical isomorphism. The inclusion `i` is commonly used to\n identify `V` with a vector subspace of `Cl(V)`.\n\n The Clifford algebra `Cl(V, Q)` is a `\\ZZ_2`-graded algebra\n (where `\\ZZ_2 = \\ZZ / 2 \\ZZ`); this grading is determined by\n placing all elements of `V` in degree `1`. It is also an\n `\\NN`-filtered algebra, with the filtration too being defined\n by placing all elements of `V` in degree `1`. The :meth:`degree` gives\n the `\\NN`-*filtration* degree, and to get the super degree use instead\n :meth:`~sage.categories.super_modules.SuperModules.ElementMethods.is_even_odd`.\n\n The Clifford algebra also can be considered as a covariant functor\n from the category of vector spaces equipped with quadratic forms\n to the category of algebras. In fact, if `(V, Q)` and `(W, R)`\n are two vector spaces endowed with quadratic forms, and if\n `g : W \\to V` is a linear map preserving the quadratic form,\n then we can define an algebra morphism\n `Cl(g) : Cl(W, R) \\to Cl(V, Q)` by requiring that it send every\n `w \\in W` to `g(w) \\in V`. Since the quadratic form `R` on `W`\n is uniquely determined by the quadratic form `Q` on `V` (due to\n the assumption that `g` preserves the quadratic form), this fact\n can be rewritten as follows: If `(V, Q)` is a vector space with a\n quadratic form, and `W` is another vector space, and\n `\\phi : W \\to V` is any linear map, then we obtain an algebra\n morphism `Cl(\\phi) : Cl(W, \\phi(Q)) \\to Cl(V, Q)` where\n `\\phi(Q) = \\phi^T \\cdot Q \\cdot \\phi` (we consider `\\phi` as a\n matrix) is the quadratic form `Q` pulled back to `W`. In fact, the\n map `\\phi` preserves the quadratic form because of\n\n .. MATH::\n\n \\phi(Q)(x) = x^T \\cdot \\phi^T \\cdot Q \\cdot \\phi \\cdot x\n = (\\phi \\cdot x)^T \\cdot Q \\cdot (\\phi \\cdot x) = Q(\\phi(x)).\n\n Hence we have `\\phi(w)^2 = Q(\\phi(w)) = \\phi(Q)(w)` for all `w \\in W`.\n\n REFERENCES:\n\n - :wikipedia:`Clifford_algebra`\n\n INPUT:\n\n - ``Q`` -- a quadratic form\n - ``names`` -- (default: ``'e'``) the generator names\n\n EXAMPLES:\n\n To create a Clifford algebra, all one needs to do is specify a\n quadratic form::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl = CliffordAlgebra(Q)\n sage: Cl\n The Clifford algebra of the Quadratic form in 3 variables\n over Integer Ring with coefficients:\n [ 1 2 3 ]\n [ * 4 5 ]\n [ * * 6 ]\n\n We can also explicitly name the generators. In this example, the\n Clifford algebra we construct is an exterior algebra (since we\n choose the quadratic form to be zero)::\n\n sage: Q = QuadraticForm(ZZ, 4, [0]*10)\n sage: Cl.<a,b,c,d> = CliffordAlgebra(Q)\n sage: a*d\n a*d\n sage: d*c*b*a + a + 4*b*c\n a*b*c*d + 4*b*c + a\n " @staticmethod def __classcall_private__(cls, Q, names=None): "\n Normalize arguments to ensure a unique representation.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl1.<e0,e1,e2> = CliffordAlgebra(Q)\n sage: Cl2 = CliffordAlgebra(Q)\n sage: Cl3 = CliffordAlgebra(Q, ['e0','e1','e2'])\n sage: Cl1 is Cl2 and Cl2 is Cl3\n True\n " if (not isinstance(Q, QuadraticForm)): raise ValueError('{} is not a quadratic form'.format(Q)) if (names is None): names = 'e' names = tuple(names) if (len(names) != Q.dim()): if (len(names) == 1): names = tuple(('{}{}'.format(names[0], i) for i in range(Q.dim()))) else: raise ValueError('the number of variables does not match the number of generators') return super().__classcall__(cls, Q, names) def __init__(self, Q, names, category=None): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl = CliffordAlgebra(Q)\n sage: Cl.category()\n Category of finite dimensional super algebras with basis over\n (euclidean domains and infinite enumerated sets and metric spaces)\n sage: TestSuite(Cl).run()\n\n TESTS:\n\n We check that the basis elements are indeed indexed by\n *strictly increasing* tuples::\n\n sage: Q = QuadraticForm(ZZ, 9)\n sage: Cl = CliffordAlgebra(Q)\n sage: ba = Cl.basis().keys()\n sage: all(FrozenBitset(format(i,'b')[::-1]) in ba for i in range(2**9))\n True\n " self._quadratic_form = Q R = Q.base_ring() category = AlgebrasWithBasis(R.category()).Super().Filtered().FiniteDimensional().or_subcategory(category) indices = CliffordAlgebraIndices(Q.dim()) CombinatorialFreeModule.__init__(self, R, indices, category=category, sorting_key=tuple) self._assign_names(names) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: CliffordAlgebra(Q)\n The Clifford algebra of the Quadratic form in 3 variables\n over Integer Ring with coefficients:\n [ 1 2 3 ]\n [ * 4 5 ]\n [ * * 6 ]\n ' return 'The Clifford algebra of the {}'.format(self._quadratic_form) def _repr_term(self, m): "\n Return a string representation of the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl._repr_term((0,2))\n 'x*z'\n sage: Cl._repr_term(FrozenBitset('101'))\n 'x*z'\n sage: Cl._repr_term(())\n '1'\n sage: Cl._repr_term((1,))\n 'y'\n " if (not m): return '1' term = '' for i in m: if term: term += '*' term += self.variable_names()[i] return term def _latex_term(self, m): "\n Return a `\\LaTeX` representation of the basis element indexed\n by ``m``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl._latex_term((0,2))\n ' x z'\n " if (not m): return '1' term = '' for i in m: term += (' ' + self.latex_variable_names()[i]) return term def _coerce_map_from_(self, V): "\n Return if there is a coerce map from ``V`` into ``self``.\n\n The things which coerce into ``self`` are:\n\n - Clifford algebras with the same generator names and an equal\n quadratic form over a ring which coerces into the base\n ring of ``self``.\n - The underlying free module of ``self``.\n - The base ring of ``self``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Qp = QuadraticForm(QQ, 3, [1,2,3,4,5,6])\n sage: Cl = CliffordAlgebra(Q)\n sage: Clp = CliffordAlgebra(Qp)\n sage: Cl.has_coerce_map_from(Clp)\n False\n sage: Clp.has_coerce_map_from(Cl)\n True\n\n Check that we preserve the multiplicative structure::\n\n sage: all(Clp(b)*Clp(b) == Clp(b*b) for b in Cl.basis())\n True\n\n Check from the underlying free module::\n\n sage: M = ZZ^3\n sage: Mp = QQ^3\n sage: Cl.has_coerce_map_from(M)\n True\n sage: Cl.has_coerce_map_from(Mp)\n False\n sage: Clp.has_coerce_map_from(M)\n True\n sage: Clp.has_coerce_map_from(Mp)\n True\n\n Names matter::\n\n sage: Cln = CliffordAlgebra(Q, names=['x','y','z'])\n sage: Cln.has_coerce_map_from(Cl)\n False\n sage: Cl.has_coerce_map_from(Cln)\n False\n\n Non-injective homomorphisms of base rings don't cause zero\n values in the coordinate dictionary (this had to be manually\n ensured)::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Qp = QuadraticForm(Integers(3), 3, [1,2,3,4,5,6])\n sage: Cl = CliffordAlgebra(Q)\n sage: Clp = CliffordAlgebra(Qp)\n sage: a = Cl.basis()[(1,2)]\n sage: a\n e1*e2\n sage: Clp(a) # so far so good\n e1*e2\n sage: Clp(3*a) # but now\n 0\n sage: Clp(3*a) == 0\n True\n sage: b = Cl.basis()[(0,2)]\n sage: Clp(3*a-4*b)\n 2*e0*e2\n " if isinstance(V, CliffordAlgebra): Q = self._quadratic_form try: return ((V.variable_names() == self.variable_names()) and (V._quadratic_form.change_ring(self.base_ring()) == Q)) except (TypeError, AttributeError): return False if self.free_module().has_coerce_map_from(V): return True return super()._coerce_map_from_(V) def _element_constructor_(self, x): "\n Construct an element of ``self`` from ``x``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Qp = QuadraticForm(QQ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Clp = CliffordAlgebra(Qp, names=['x','y','z'])\n sage: M = ZZ^3\n sage: Mp = QQ^3\n sage: Cl(2/3)\n Traceback (most recent call last):\n ...\n TypeError: do not know how to make x=2/3 an element of self\n sage: Clp(2/3)\n 2/3\n sage: Clp(x)\n x\n sage: M = ZZ^3\n sage: Clp( M((1,-3,2)) )\n x - 3*y + 2*z\n\n Zero coordinates are handled appropriately::\n\n sage: Q3 = QuadraticForm(Integers(3), 3, [1,2,3,4,5,6])\n sage: Cl3 = CliffordAlgebra(Q3, names='xyz') # different syntax for a change\n sage: Cl3( M((1,-3,2)) )\n x + 2*z\n " if (x in self.free_module()): R = self.base_ring() if (x.parent().base_ring() is R): return self.element_class(self, {FrozenBitset((i,)): c for (i, c) in x.items()}) return self.element_class(self, {FrozenBitset((i,)): R(c) for (i, c) in x.items() if (R(c) != R.zero())}) if (isinstance(x, CliffordAlgebraElement) and self.has_coerce_map_from(x.parent())): R = self.base_ring() return self.element_class(self, {i: R(c) for (i, c) in x if (R(c) != R.zero())}) if isinstance(x, tuple): R = self.base_ring() return self.element_class(self, {FrozenBitset((i,)): R.one() for i in x}) try: return super()._element_constructor_(x) except TypeError: raise TypeError(f'do not know how to make x={x!r} an element of self') def _basis_index_function(self, x): '\n Given an integer indexing the basis, return the correct\n bitset.\n\n For backwards compatibility, tuples are also accepted.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl = CliffordAlgebra(Q)\n sage: Cl._basis_index_function(7)\n 111\n sage: Cl._basis_index_function(5)\n 101\n sage: Cl._basis_index_function(4)\n 001\n\n sage: Cl._basis_index_function((0, 1, 2))\n 111\n sage: Cl._basis_index_function((0, 2))\n 101\n sage: Cl._basis_index_function((2,))\n 001\n ' Q = self._quadratic_form format_style = f'0{Q.dim()}b' if isinstance(x, tuple): return FrozenBitset(x, capacity=Q.dim()) return FrozenBitset(format(x, format_style)[::(- 1)], capacity=Q.dim()) def gen(self, i): '\n Return the ``i``-th standard generator of the algebra ``self``.\n\n This is the ``i``-th basis vector of the vector space on which\n the quadratic form defining ``self`` is defined, regarded as an\n element of ``self``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: [Cl.gen(i) for i in range(3)]\n [x, y, z]\n ' return self._from_dict({FrozenBitset((i,)): self.base_ring().one()}, remove_zeros=False) def algebra_generators(self): "\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.algebra_generators()\n Finite family {'x': x, 'y': y, 'z': z}\n " d = {x: self.gen(i) for (i, x) in enumerate(self.variable_names())} return Family(self.variable_names(), (lambda x: d[x])) def gens(self): '\n Return the generators of ``self`` (as an algebra).\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.gens()\n (x, y, z)\n ' return tuple(self.algebra_generators()) @cached_method def ngens(self): '\n Return the number of algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.ngens()\n 3\n ' return self._quadratic_form.dim() @cached_method def one_basis(self): '\n Return the basis index of the element ``1``. The element ``1``\n is indexed by the emptyset, which is represented by the\n :class:`sage.data_structures.bitset.Bitset` ``0``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.one_basis()\n 0\n ' return FrozenBitset() def is_commutative(self): '\n Check if ``self`` is a commutative algebra.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.is_commutative()\n False\n ' return (self._quadratic_form.dim() < 2) def quadratic_form(self): '\n Return the quadratic form of ``self``.\n\n This is the quadratic form used to define ``self``. The\n quadratic form on ``self`` is yet to be implemented.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.quadratic_form()\n Quadratic form in 3 variables over Integer Ring with coefficients:\n [ 1 2 3 ]\n [ * 4 5 ]\n [ * * 6 ]\n ' return self._quadratic_form def degree_on_basis(self, m): '\n Return the degree of the monomial indexed by ``m``.\n\n We are considering the Clifford algebra to be `\\NN`-filtered,\n and the degree of the monomial ``m`` is the length of ``m``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.degree_on_basis((0,))\n 1\n sage: Cl.degree_on_basis((0,1))\n 2\n ' return ZZ(len(m)) def graded_algebra(self): '\n Return the associated graded algebra of ``self``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.graded_algebra()\n The exterior algebra of rank 3 over Integer Ring\n ' return ExteriorAlgebra(self.base_ring(), self.variable_names()) @cached_method def free_module(self): '\n Return the underlying free module `V` of ``self``.\n\n This is the free module on which the quadratic form that was\n used to construct ``self`` is defined.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.free_module()\n Ambient free module of rank 3 over the principal ideal domain Integer Ring\n ' return FreeModule(self.base_ring(), self._quadratic_form.dim()) def dimension(self): '\n Return the rank of ``self`` as a free module.\n\n Let `V` be a free `R`-module of rank `n`; then, `Cl(V, Q)` is a\n free `R`-module of rank `2^n`.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.dimension()\n 8\n ' return (ZZ(2) ** self._quadratic_form.dim()) def pseudoscalar(self): '\n Return the unit pseudoscalar of ``self``.\n\n Given the basis `e_1, e_2, \\ldots, e_n` of the underlying\n `R`-module, the unit pseudoscalar is defined as\n `e_1 \\cdot e_2 \\cdots e_n`.\n\n This depends on the choice of basis.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.pseudoscalar()\n x*y*z\n\n sage: Q = QuadraticForm(ZZ, 0, [])\n sage: Cl = CliffordAlgebra(Q)\n sage: Cl.pseudoscalar()\n 1\n\n REFERENCES:\n\n - :wikipedia:`Classification_of_Clifford_algebras#Unit_pseudoscalar`\n ' d = self._quadratic_form.dim() return self.element_class(self, {tuple(range(d)): self.base_ring().one()}) def lift_module_morphism(self, m, names=None): "\n Lift the matrix ``m`` to an algebra morphism of Clifford algebras.\n\n Given a linear map `m : W \\to V` (here represented by a matrix\n acting on column vectors), this method returns the algebra\n morphism `Cl(m) : Cl(W, m(Q)) \\to Cl(V, Q)`, where `Cl(V, Q)`\n is the Clifford algebra ``self`` and where `m(Q)` is the pullback\n of the quadratic form `Q` to `W`. See the documentation\n of :class:`CliffordAlgebra` for how this pullback and the\n morphism `Cl(m)` are defined.\n\n .. NOTE::\n\n This is a map into ``self``.\n\n INPUT:\n\n - ``m`` -- a matrix\n - ``names`` -- (default: ``'e'``) the names of the generators of the\n Clifford algebra of the domain of (the map represented by) ``m``\n\n OUTPUT:\n\n The algebra morphism `Cl(m)` from `Cl(W, m(Q))` to ``self``.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: m = matrix([[1,-1,-1],[0,1,-1],[1,1,1]])\n sage: phi = Cl.lift_module_morphism(m, 'abc')\n sage: phi\n Generic morphism:\n From: The Clifford algebra of the Quadratic form in 3 variables over Integer Ring with coefficients:\n [ 10 17 3 ]\n [ * 11 0 ]\n [ * * 5 ]\n To: The Clifford algebra of the Quadratic form in 3 variables over Integer Ring with coefficients:\n [ 1 2 3 ]\n [ * 4 5 ]\n [ * * 6 ]\n sage: a,b,c = phi.domain().gens()\n sage: phi(a)\n x + z\n sage: phi(b)\n -x + y + z\n sage: phi(c)\n -x - y + z\n sage: phi(a + 3*b)\n -2*x + 3*y + 4*z\n sage: phi(a) + 3*phi(b)\n -2*x + 3*y + 4*z\n sage: phi(a*b)\n x*y + 2*x*z - y*z + 7\n sage: phi(b*a)\n -x*y - 2*x*z + y*z + 10\n sage: phi(a*b + c)\n x*y + 2*x*z - y*z - x - y + z + 7\n sage: phi(a*b) + phi(c)\n x*y + 2*x*z - y*z - x - y + z + 7\n\n We check that the map is an algebra morphism::\n\n sage: phi(a)*phi(b)\n x*y + 2*x*z - y*z + 7\n sage: phi(a*b)\n x*y + 2*x*z - y*z + 7\n sage: phi(a*a)\n 10\n sage: phi(a)*phi(a)\n 10\n sage: phi(b*a)\n -x*y - 2*x*z + y*z + 10\n sage: phi(b) * phi(a)\n -x*y - 2*x*z + y*z + 10\n sage: phi((a + b)*(a + c)) == phi(a + b) * phi(a + c)\n True\n\n We can also lift arbitrary linear maps::\n\n sage: m = matrix([[1,1],[0,1],[1,1]])\n sage: phi = Cl.lift_module_morphism(m, 'ab')\n sage: a,b = phi.domain().gens()\n sage: phi(a)\n x + z\n sage: phi(b)\n x + y + z\n sage: phi(a*b)\n x*y - y*z + 15\n sage: phi(a)*phi(b)\n x*y - y*z + 15\n sage: phi(b*a)\n -x*y + y*z + 12\n sage: phi(b)*phi(a)\n -x*y + y*z + 12\n\n sage: m = matrix([[1,1,1,2], [0,1,1,1], [0,1,1,1]])\n sage: phi = Cl.lift_module_morphism(m, 'abcd')\n sage: a,b,c,d = phi.domain().gens()\n sage: phi(a)\n x\n sage: phi(b)\n x + y + z\n sage: phi(c)\n x + y + z\n sage: phi(d)\n 2*x + y + z\n sage: phi(a*b*c + d*a)\n -x*y - x*z + 21*x + 7\n sage: phi(a*b*c*d)\n 21*x*y + 21*x*z + 42\n\n TESTS:\n\n Check that the resulting morphism knows it is for\n finite-dimensional algebras (:trac:`25339`)::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: m = matrix([[1,-1,-1],[0,1,-1],[1,1,1]])\n sage: phi = Cl.lift_module_morphism(m, 'abc')\n sage: phi.category_for()\n Category of finite dimensional super algebras with basis over\n (euclidean domains and infinite enumerated sets and metric spaces)\n sage: phi.matrix()\n [ 1 0 0 0 7 -3 -7 0]\n [ 0 1 -1 -1 0 0 0 -17]\n [ 0 0 1 -1 0 0 0 -4]\n [ 0 1 1 1 0 0 0 3]\n [ 0 0 0 0 1 -1 2 0]\n [ 0 0 0 0 2 2 0 0]\n [ 0 0 0 0 -1 1 2 0]\n [ 0 0 0 0 0 0 0 4]\n " Q = self._quadratic_form(m) if ((Q == self._quadratic_form) and (names is None)): Cl = self else: Cl = CliffordAlgebra(Q, names) n = self._quadratic_form.dim() f = (lambda x: self.prod((self._from_dict({FrozenBitset((j,)): m[(j, i)] for j in range(n)}, remove_zeros=True) for i in x))) cat = AlgebrasWithBasis(self.category().base_ring()).Super().FiniteDimensional() return Cl.module_morphism(on_basis=f, codomain=self, category=cat) def lift_isometry(self, m, names=None): "\n Lift an invertible isometry ``m`` of the quadratic form of\n ``self`` to a Clifford algebra morphism.\n\n Given an invertible linear map `m : V \\to W` (here represented by\n a matrix acting on column vectors), this method returns the\n algebra morphism `Cl(m)` from `Cl(V, Q)` to `Cl(W, m^{-1}(Q))`,\n where `Cl(V, Q)` is the Clifford algebra ``self`` and where\n `m^{-1}(Q)` is the pullback of the quadratic form `Q` to `W` along\n the inverse map `m^{-1} : W \\to V`. See the documentation of\n :class:`CliffordAlgebra` for how this pullback and the morphism\n `Cl(m)` are defined.\n\n INPUT:\n\n - ``m`` -- an isometry of the quadratic form of ``self``\n - ``names`` -- (default: ``'e'``) the names of the generators of\n the Clifford algebra of the codomain of (the map represented by)\n ``m``\n\n OUTPUT:\n\n The algebra morphism `Cl(m)` from ``self`` to `Cl(W, m^{-1}(Q))`.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: m = matrix([[1,1,2],[0,1,1],[0,0,1]])\n sage: phi = Cl.lift_isometry(m, 'abc')\n sage: phi(x)\n a\n sage: phi(y)\n a + b\n sage: phi(x*y)\n a*b + 1\n sage: phi(x) * phi(y)\n a*b + 1\n sage: phi(z*y)\n a*b - a*c - b*c\n sage: phi(z) * phi(y)\n a*b - a*c - b*c\n sage: phi(x + z) * phi(y + z) == phi((x + z) * (y + z))\n True\n\n TESTS:\n\n Check that the resulting morphism knows it is for\n finite-dimensional algebras (:trac:`25339`)::\n\n sage: Q = QuadraticForm(ZZ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: m = matrix([[1,1,2],[0,1,1],[0,0,1]])\n sage: phi = Cl.lift_isometry(m, 'abc')\n sage: phi.category_for()\n Category of finite dimensional super algebras with basis over\n (euclidean domains and infinite enumerated sets and metric spaces)\n sage: phi.matrix()\n [ 1 0 0 0 1 2 5 0]\n [ 0 1 1 2 0 0 0 5]\n [ 0 0 1 1 0 0 0 -1]\n [ 0 0 0 1 0 0 0 1]\n [ 0 0 0 0 1 1 -1 0]\n [ 0 0 0 0 0 1 1 0]\n [ 0 0 0 0 0 0 1 0]\n [ 0 0 0 0 0 0 0 1]\n " MS = m.parent() if (not m.is_invertible()): raise ValueError('{} is not invertible') Q = self._quadratic_form(MS(m.inverse())) if ((Q == self._quadratic_form) and (names is None)): Cl = self else: if (names is None): names = 'e' Cl = CliffordAlgebra(Q, names) n = Q.dim() f = (lambda x: Cl.prod((Cl._from_dict({FrozenBitset((j,)): m[(j, i)] for j in range(n)}, remove_zeros=True) for i in x))) cat = AlgebrasWithBasis(self.category().base_ring()).Super().FiniteDimensional() return self.module_morphism(on_basis=f, codomain=Cl, category=cat) @cached_method def center_basis(self): '\n Return a list of elements which correspond to a basis for the center\n of ``self``.\n\n This assumes that the ground ring can be used to compute the\n kernel of a matrix.\n\n .. SEEALSO::\n\n :meth:`supercenter_basis`,\n http://math.stackexchange.com/questions/129183/center-of-clifford-algebra-depending-on-the-parity-of-dim-v\n\n .. TODO::\n\n Deprecate this in favor of a method called `center()` once\n subalgebras are properly implemented in Sage.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(QQ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Z = Cl.center_basis(); Z\n (1, -2/5*x*y*z + x - 3/5*y + 2/5*z)\n sage: all(z*b - b*z == 0 for z in Z for b in Cl.basis())\n True\n\n sage: Q = QuadraticForm(QQ, 3, [1,-2,-3, 4, 2, 1])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Z = Cl.center_basis(); Z\n (1, -x*y*z + x + 3/2*y - z)\n sage: all(z*b - b*z == 0 for z in Z for b in Cl.basis())\n True\n\n sage: Q = QuadraticForm(QQ, 2, [1,-2,-3])\n sage: Cl.<x,y> = CliffordAlgebra(Q)\n sage: Cl.center_basis()\n (1,)\n\n sage: Q = QuadraticForm(QQ, 2, [-1,1,-3])\n sage: Cl.<x,y> = CliffordAlgebra(Q)\n sage: Cl.center_basis()\n (1,)\n\n A degenerate case::\n\n sage: Q = QuadraticForm(QQ, 3, [4,4,-4,1,-2,1])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.center_basis()\n (1, x*y*z + x - 2*y - 2*z, x*y + x*z - 2*y*z)\n\n The most degenerate case (the exterior algebra)::\n\n sage: Q = QuadraticForm(QQ, 3)\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.center_basis()\n (1, x*y, x*z, y*z, x*y*z)\n ' R = self.base_ring() B = self.basis() K = list(B.keys()) k = len(K) d = {} for (a, i) in enumerate(K): Bi = B[i] for (b, j) in enumerate(K): Bj = B[j] for (m, c) in ((Bi * Bj) - (Bj * Bi)): d[(a, (K.index(m) + (k * b)))] = c m = Matrix(R, d, nrows=k, ncols=(k * k), sparse=True) from_vector = (lambda x: self.sum_of_terms(((K[i], c) for (i, c) in x.items()), distinct=True)) return tuple(map(from_vector, m.kernel().basis())) @cached_method def supercenter_basis(self): '\n Return a list of elements which correspond to a basis for the\n supercenter of ``self``.\n\n This assumes that the ground ring can be used to compute the\n kernel of a matrix.\n\n .. SEEALSO::\n\n :meth:`center_basis`,\n http://math.stackexchange.com/questions/129183/center-of-clifford-algebra-depending-on-the-parity-of-dim-v\n\n .. TODO::\n\n Deprecate this in favor of a method called `supercenter()` once\n subalgebras are properly implemented in Sage.\n\n EXAMPLES::\n\n sage: Q = QuadraticForm(QQ, 3, [1,2,3,4,5,6])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: SZ = Cl.supercenter_basis(); SZ\n (1,)\n sage: all(z.supercommutator(b) == 0 for z in SZ for b in Cl.basis())\n True\n\n sage: Q = QuadraticForm(QQ, 3, [1,-2,-3, 4, 2, 1])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.supercenter_basis()\n (1,)\n\n sage: Q = QuadraticForm(QQ, 2, [1,-2,-3])\n sage: Cl.<x,y> = CliffordAlgebra(Q)\n sage: Cl.supercenter_basis()\n (1,)\n\n sage: Q = QuadraticForm(QQ, 2, [-1,1,-3])\n sage: Cl.<x,y> = CliffordAlgebra(Q)\n sage: Cl.supercenter_basis()\n (1,)\n\n Singular vectors of a quadratic form generate in the supercenter::\n\n sage: Q = QuadraticForm(QQ, 3, [1/2,-2,4,256/249,3,-185/8])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.supercenter_basis()\n (1, x + 249/322*y + 22/161*z)\n\n sage: Q = QuadraticForm(QQ, 3, [4,4,-4,1,-2,1])\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.supercenter_basis()\n (1, x + 2*z, y + z, x*y + x*z - 2*y*z)\n\n The most degenerate case::\n\n sage: Q = QuadraticForm(QQ, 3)\n sage: Cl.<x,y,z> = CliffordAlgebra(Q)\n sage: Cl.supercenter_basis()\n (1, x, y, z, x*y, x*z, y*z, x*y*z)\n ' R = self.base_ring() B = self.basis() K = list(B.keys()) k = len(K) d = {} for (a, i) in enumerate(K): Bi = B[i] for (b, j) in enumerate(K): Bj = B[j] if ((len(i) % 2) and (len(j) % 2)): supercommutator = ((Bi * Bj) + (Bj * Bi)) else: supercommutator = ((Bi * Bj) - (Bj * Bi)) for (m, c) in supercommutator: d[(a, (K.index(m) + (k * b)))] = c m = Matrix(R, d, nrows=k, ncols=(k * k), sparse=True) from_vector = (lambda x: self.sum_of_terms(((K[i], c) for (i, c) in x.items()), distinct=True)) return tuple(map(from_vector, m.kernel().basis())) Element = CliffordAlgebraElement
class ExteriorAlgebra(CliffordAlgebra): '\n An exterior algebra of a free module over a commutative ring.\n\n Let `V` be a module over a commutative ring `R`. The exterior algebra\n (or Grassmann algebra) `\\Lambda(V)` of `V` is defined as the quotient\n of the tensor algebra `T(V)` of `V` modulo the two-sided ideal\n generated by all tensors of the form `x \\otimes x` with `x \\in V`. The\n multiplication on `\\Lambda(V)` is denoted by `\\wedge` (so\n `v_1 \\wedge v_2 \\wedge \\cdots \\wedge v_n` is the projection of\n `v_1 \\otimes v_2 \\otimes \\cdots \\otimes v_n` onto `\\Lambda(V)`) and\n called the "exterior product" or "wedge product".\n\n If `V` is a rank-`n` free `R`-module with a basis\n `\\{e_1, \\ldots, e_n\\}`, then `\\Lambda(V)` is the `R`-algebra\n noncommutatively generated by the `n` generators `e_1, \\ldots, e_n`\n subject to the relations `e_i^2 = 0` for all `i`, and\n `e_i e_j = - e_j e_i` for all `i < j`. As an `R`-module,\n `\\Lambda(V)` then has a basis `(\\bigwedge_{i \\in I} e_i)` with `I`\n ranging over the subsets of `\\{1, 2, \\ldots, n\\}` (where\n `\\bigwedge_{i \\in I} e_i` is the wedge product of `e_i` for `i`\n running through all elements of `I` from smallest to largest), and\n hence is free of rank `2^n`.\n\n The exterior algebra of an `R`-module `V` can also be realized\n as the Clifford algebra of `V` for the quadratic form `Q` given by\n `Q(v) = 0` for all vectors `v \\in V`. See :class:`CliffordAlgebra`\n for the notion of a Clifford algebra.\n\n The exterior algebra of an `R`-module `V` is a connected `\\ZZ`-graded\n Hopf superalgebra. It is commutative in the super sense (i.e., the\n odd elements anticommute and square to `0`).\n\n This class implements the exterior algebra `\\Lambda(R^n)` for\n `n` a nonnegative integer.\n\n INPUT:\n\n - ``R`` -- the base ring, *or* the free module whose exterior algebra\n is to be computed\n\n - ``names`` -- a list of strings to name the generators of the\n exterior algebra; this list can either have one entry only (in which\n case the generators will be called ``e + \'0\'``, ``e + \'1\'``, ...,\n ``e + \'n-1\'``, with ``e`` being said entry), or have ``n`` entries\n (in which case these entries will be used directly as names for the\n generators)\n\n - ``n`` -- the number of generators, i.e., the rank of the free\n module whose exterior algebra is to be computed (this doesn\'t have\n to be provided if it can be inferred from the rest of the input)\n\n REFERENCES:\n\n - :wikipedia:`Exterior_algebra`\n ' @staticmethod def __classcall_private__(cls, R, names=None, n=None): "\n Normalize arguments to ensure a unique representation.\n\n EXAMPLES::\n\n sage: E1.<e0,e1,e2> = ExteriorAlgebra(QQ)\n sage: E2 = ExteriorAlgebra(QQ, 3)\n sage: E3 = ExteriorAlgebra(QQ, ['e0','e1','e2'])\n sage: E1 is E2 and E2 is E3\n True\n " if (names is None): names = 'e' elif (names in ZZ): n = names names = 'e' if isinstance(R, FreeModule_generic): if ((n is not None) and (n != R.dimension())): raise ValueError('the number of variables does not match the dimension') n = R.dimension() R = R.base_ring() names = tuple(names) if ((n is not None) and (len(names) != n)): if (len(names) == 1): names = tuple(('{}{}'.format(names[0], i) for i in range(n))) else: raise ValueError('the number of variables does not match the number of generators') return super().__classcall__(cls, R, names) def __init__(self, R, names): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E.category()\n Category of finite dimensional supercommutative supercocommutative\n super Hopf algebras with basis over Rational Field\n sage: TestSuite(E).run()\n\n sage: TestSuite(ExteriorAlgebra(GF(3), ['a', 'b'])).run()\n " cat = HopfAlgebrasWithBasis(R).FiniteDimensional().Supercommutative().Supercocommutative() CliffordAlgebra.__init__(self, QuadraticForm(R, len(names)), names, category=cat) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: ExteriorAlgebra(QQ, 3)\n The exterior algebra of rank 3 over Rational Field\n ' return 'The exterior algebra of rank {} over {}'.format(self.ngens(), self.base_ring()) def _repr_term(self, m): "\n Return a string representation of the basis element indexed by\n ``m``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E._repr_term((0,1,2))\n 'x*y*z'\n sage: y*x + x*z\n -x*y + x*z\n " if (len(m) == 0): return '1' term = '' for i in m: if (len(term) != 0): term += '*' term += self.variable_names()[i] return term def _ascii_art_term(self, m): '\n Return ascii art for the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E._ascii_art_term((0,1,2))\n x/\\y/\\z\n sage: ascii_art(y*x + 2*x*z)\n -x/\\y + 2*x/\\z\n ' if (len(m) == 0): return ascii_art('1') wedge = '/\\' return ascii_art(*[repr(self.basis()[FrozenBitset((i,))]) for i in m], sep=wedge) def _unicode_art_term(self, m): '\n Return unicode art for the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E._unicode_art_term((0,1,2))\n x∧y∧z\n sage: unicode_art(y*x + x*z)\n -x∧y + x∧z\n ' if (len(m) == 0): return unicode_art('1') wedge = unicodedata.lookup('LOGICAL AND') return unicode_art(*[self.variable_names()[i] for i in m], sep=wedge) def _latex_term(self, m): "\n Return a `\\LaTeX` representation of the basis element indexed\n by ``m``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E._latex_term((0,1,2))\n ' x \\\\wedge y \\\\wedge z'\n sage: E.<x0,x1,x2> = ExteriorAlgebra(QQ)\n sage: E._latex_term((0,1,2))\n ' x_{0} \\\\wedge x_{1} \\\\wedge x_{2}'\n sage: E._latex_term(())\n '1'\n sage: E._latex_term((0,))\n ' x_{0}'\n " if (len(m) == 0): return '1' term = '' for i in m: if (len(term) != 0): term += ' \\wedge' term += (' ' + self.latex_variable_names()[i]) return term def lift_morphism(self, phi, names=None): "\n Lift the matrix ``m`` to an algebra morphism of exterior algebras.\n\n Given a linear map `\\phi : V \\to W` (here represented by a matrix\n acting on column vectors over the base ring of `V`), this method\n returns the algebra morphism\n `\\Lambda(\\phi) : \\Lambda(V) \\to \\Lambda(W)`. This morphism is defined\n on generators `v_i \\in \\Lambda(V)` by `v_i \\mapsto \\phi(v_i)`.\n\n .. NOTE::\n\n This is the map going out of ``self`` as opposed to\n :meth:`~sage.algebras.clifford_algebra.CliffordAlgebraElement.lift_module_morphism()`\n for general Clifford algebras.\n\n INPUT:\n\n - ``phi`` -- a linear map `\\phi` from `V` to `W`, encoded as a\n matrix\n - ``names`` -- (default: ``'e'``) the names of the generators of\n the Clifford algebra of the domain of (the map represented by)\n ``phi``\n\n OUTPUT:\n\n The algebra morphism `\\Lambda(\\phi)` from ``self`` to `\\Lambda(W)`.\n\n EXAMPLES::\n\n sage: E.<x,y> = ExteriorAlgebra(QQ)\n sage: phi = matrix([[0,1],[1,1],[1,2]]); phi\n [0 1]\n [1 1]\n [1 2]\n sage: L = E.lift_morphism(phi, ['a','b','c']); L\n Generic morphism:\n From: The exterior algebra of rank 2 over Rational Field\n To: The exterior algebra of rank 3 over Rational Field\n sage: L(x)\n b + c\n sage: L(y)\n a + b + 2*c\n sage: L.on_basis()((1,))\n a + b + 2*c\n sage: p = L(E.one()); p\n 1\n sage: p.parent()\n The exterior algebra of rank 3 over Rational Field\n sage: L(x*y)\n -a*b - a*c + b*c\n sage: L(x)*L(y)\n -a*b - a*c + b*c\n sage: L(x + y)\n a + 2*b + 3*c\n sage: L(x) + L(y)\n a + 2*b + 3*c\n sage: L(1/2*x + 2)\n 1/2*b + 1/2*c + 2\n sage: L(E(3))\n 3\n\n sage: psi = matrix([[1, -3/2]]); psi\n [ 1 -3/2]\n sage: Lp = E.lift_morphism(psi, ['a']); Lp\n Generic morphism:\n From: The exterior algebra of rank 2 over Rational Field\n To: The exterior algebra of rank 1 over Rational Field\n sage: Lp(x)\n a\n sage: Lp(y)\n -3/2*a\n sage: Lp(x + 2*y + 3)\n -2*a + 3\n\n TESTS:\n\n Check that the resulting morphism knows it is for\n finite-dimensional algebras (:trac:`25339`)::\n\n sage: E = ExteriorAlgebra(ZZ, 'e', 3)\n sage: T = jordan_block(0, 2).block_sum(jordan_block(0, 1))\n sage: phi = E.lift_morphism(T)\n sage: phi.category_for()\n Category of finite dimensional super algebras with basis over Integer Ring\n sage: phi.matrix()\n [1 0 0 0 0 0 0 0]\n [0 0 1 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n " n = phi.nrows() R = self.base_ring() E = ExteriorAlgebra(R, names, n) f = (lambda x: E.prod((E._from_dict({FrozenBitset((j,)): phi[(j, i)] for j in range(n)}, remove_zeros=True) for i in x))) cat = AlgebrasWithBasis(R).Super().FiniteDimensional() return self.module_morphism(on_basis=f, codomain=E, category=cat) def volume_form(self): '\n Return the volume form of ``self``.\n\n Given the basis `e_1, e_2, \\ldots, e_n` of the underlying\n `R`-module, the volume form is defined as `e_1 \\wedge e_2\n \\wedge \\cdots \\wedge e_n`.\n\n This depends on the choice of basis.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E.volume_form()\n x*y*z\n ' d = self._quadratic_form.dim() return self.element_class(self, {tuple(range(d)): self.base_ring().one()}) def boundary(self, s_coeff): '\n Return the boundary operator `\\partial` defined by the structure\n coefficients ``s_coeff`` of a Lie algebra.\n\n For more on the boundary operator, see\n :class:`ExteriorAlgebraBoundary`.\n\n INPUT:\n\n - ``s_coeff`` -- a dictionary whose keys are in `I \\times I`, where\n `I` is the index set of the underlying vector space `V`, and whose\n values can be coerced into 1-forms (degree 1 elements) in ``E``\n (usually, these values will just be elements of `V`)\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E.boundary({(0,1): z, (1,2): x, (2,0): y})\n Boundary endomorphism of The exterior algebra of rank 3 over Rational Field\n ' return ExteriorAlgebraBoundary(self, s_coeff) def coboundary(self, s_coeff): '\n Return the coboundary operator `d` defined by the structure\n coefficients ``s_coeff`` of a Lie algebra.\n\n For more on the coboundary operator, see\n :class:`ExteriorAlgebraCoboundary`.\n\n INPUT:\n\n - ``s_coeff`` -- a dictionary whose keys are in `I \\times I`, where\n `I` is the index set of the underlying vector space `V`, and whose\n values can be coerced into 1-forms (degree 1 elements) in ``E``\n (usually, these values will just be elements of `V`)\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E.coboundary({(0,1): z, (1,2): x, (2,0): y})\n Coboundary endomorphism of The exterior algebra of rank 3 over Rational Field\n ' return ExteriorAlgebraCoboundary(self, s_coeff) def degree_on_basis(self, m): '\n Return the degree of the monomial indexed by ``m``.\n\n The degree of ``m`` in the `\\ZZ`-grading of ``self`` is defined\n to be the length of ``m``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E.degree_on_basis(())\n 0\n sage: E.degree_on_basis((0,))\n 1\n sage: E.degree_on_basis((0,1))\n 2\n ' return ZZ(len(m)) def coproduct_on_basis(self, a): '\n Return the coproduct on the basis element indexed by ``a``.\n\n The coproduct is defined by\n\n .. MATH::\n\n \\Delta(e_{i_1} \\wedge \\cdots \\wedge e_{i_m}) = \\sum_{k=0}^m\n \\sum_{\\sigma \\in Ush_{k,m-k}} (-1)^{\\sigma}\n (e_{i_{\\sigma(1)}} \\wedge \\cdots \\wedge e_{i_{\\sigma(k)}}) \\otimes\n (e_{i_{\\sigma(k+1)}} \\wedge \\cdots \\wedge e_{i_{\\sigma(m)}}),\n\n where `Ush_{k,m-k}` denotes the set of all `(k,m-k)`-unshuffles\n (i.e., permutations in `S_m` which are increasing on the interval\n `\\{1, 2, \\ldots, k\\}` and on the interval\n `\\{k+1, k+2, \\ldots, k+m\\}`).\n\n .. WARNING::\n\n This coproduct is a homomorphism of superalgebras, not a\n homomorphism of algebras!\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E.coproduct_on_basis((0,))\n 1 # x + x # 1\n sage: E.coproduct_on_basis((0,1))\n 1 # x*y + x # y - y # x + x*y # 1\n sage: E.coproduct_on_basis((0,1,2))\n 1 # x*y*z + x # y*z - y # x*z + x*y # z\n + z # x*y - x*z # y + y*z # x + x*y*z # 1\n\n ' from sage.combinat.combinat import unshuffle_iterator one = self.base_ring().one() L = unshuffle_iterator(tuple(a), one) return self.tensor_square()._from_dict({tuple(((FrozenBitset(e) if e else FrozenBitset()) for e in t)): c for (t, c) in L if c}, coerce=False, remove_zeros=False) def antipode_on_basis(self, m): '\n Return the antipode on the basis element indexed by ``m``.\n\n Given a basis element `\\omega`, the antipode is defined by\n `S(\\omega) = (-1)^{\\deg(\\omega)} \\omega`.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E.antipode_on_basis(())\n 1\n sage: E.antipode_on_basis((1,))\n -y\n sage: E.antipode_on_basis((1,2))\n y*z\n ' return self.term(m, ((- self.base_ring().one()) ** len(m))) def counit(self, x): '\n Return the counit of ``x``.\n\n The counit of an element `\\omega` of the exterior algebra\n is its constant coefficient.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: elt = x*y - 2*x + 3\n sage: E.counit(elt)\n 3\n ' return x.constant_coefficient() def interior_product_on_basis(self, a, b): "\n Return the interior product `\\iota_b a` of ``a`` with respect to\n ``b``.\n\n See :meth:`~sage.algebras.clifford_algebra.CliffordAlgebra.Element.interior_product`\n for more information.\n\n In this method, ``a`` and ``b`` are supposed to be\n basis elements (see\n :meth:`~sage.algebras.clifford_algebra.CliffordAlgebra.Element.interior_product`\n for a method that computes interior product of arbitrary\n elements), and to be input as their keys.\n\n This depends on the choice of basis of the vector space\n whose exterior algebra is ``self``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: k = list(E.basis().keys())\n sage: E.interior_product_on_basis(k[1], k[1])\n 1\n sage: E.interior_product_on_basis(k[5], k[1])\n z\n sage: E.interior_product_on_basis(k[2], k[5])\n 0\n sage: E.interior_product_on_basis(k[5], k[2])\n 0\n sage: E.interior_product_on_basis(k[7], k[5])\n -y\n\n Check :trac:`34694`::\n\n sage: # needs sage.symbolic\n sage: E = ExteriorAlgebra(SR,'e',3)\n sage: E.inject_variables()\n Defining e0, e1, e2\n sage: a = (e0*e1).interior_product(e0)\n sage: a * e0\n -e0*e1\n " sgn = True t = list(a) for i in b: if (i not in t): return self.zero() if (t.index(i) % 2): sgn = (not sgn) t.remove(i) R = self.base_ring() if (not t): t = None return self.term(FrozenBitset(t), (R.one() if sgn else (- R.one()))) def lifted_bilinear_form(self, M): '\n Return the bilinear form on the exterior algebra ``self``\n `= \\Lambda(V)` which is obtained by lifting the bilinear\n form `f` on `V` given by the matrix ``M``.\n\n Let `V` be a module over a commutative ring `R`, and let\n `f : V \\times V \\to R` be a bilinear form on `V`. Then,\n a bilinear form `\\Lambda(f) : \\Lambda(V) \\times\n \\Lambda(V) \\to R` on `\\Lambda(V)` can be canonically\n defined as follows: For every `n \\in \\NN`, `m \\in \\NN`,\n `v_1, v_2, \\ldots, v_n, w_1, w_2, \\ldots, w_m \\in V`,\n we define\n\n .. MATH::\n\n \\Lambda(f)\n ( v_1 \\wedge v_2 \\wedge \\cdots \\wedge v_n ,\n w_1 \\wedge w_2 \\wedge \\cdots \\wedge w_m )\n := \\begin{cases}\n 0, &\\mbox{if } n \\neq m ; \\\\\n \\det G, & \\mbox{if } n = m \\end{cases} ,\n\n where `G` is the `n \\times m`-matrix whose\n `(i, j)`-th entry is `f(v_i, w_j)`. This bilinear form\n `\\Lambda(f)` is known as the bilinear form on\n `\\Lambda(V)` obtained by lifting the bilinear form `f`.\n Its restriction to the `1`-st homogeneous component\n `V` of `\\Lambda(V)` is `f`.\n\n The bilinear form `\\Lambda(f)` is symmetric if `f` is.\n\n INPUT:\n\n - ``M`` -- a matrix over the same base ring as ``self``,\n whose `(i, j)`-th entry is `f(e_i, e_j)`, where\n `(e_1, e_2, \\ldots, e_N)` is the standard basis of the\n module `V` for which ``self`` `= \\Lambda(V)` (so that\n `N = \\dim(V)`), and where `f` is the bilinear form\n which is to be lifted.\n\n OUTPUT:\n\n A bivariate function which takes two elements `p` and\n `q` of ``self`` to `\\Lambda(f)(p, q)`.\n\n .. NOTE::\n\n This takes a bilinear form on `V` as matrix, and\n returns a bilinear form on ``self`` as a function in\n two arguments. We do not return the bilinear form as\n a matrix since this matrix can be huge and one often\n needs just a particular value.\n\n .. TODO::\n\n Implement a class for bilinear forms and rewrite this\n method to use that class.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: M = Matrix(QQ, [[1, 2, 3], [2, 3, 4], [3, 4, 5]])\n sage: Eform = E.lifted_bilinear_form(M)\n sage: Eform\n Bilinear Form from The exterior algebra of rank 3 over Rational\n Field (+) The exterior algebra of rank 3 over Rational Field to\n Rational Field\n sage: Eform(x*y, y*z)\n -1\n sage: Eform(x*y, y)\n 0\n sage: Eform(x*(y+z), y*z)\n -3\n sage: Eform(x*(y+z), y*(z+x))\n 0\n sage: N = Matrix(QQ, [[3, 1, 7], [2, 0, 4], [-1, -3, -1]])\n sage: N.determinant()\n -8\n sage: Eform = E.lifted_bilinear_form(N)\n sage: Eform(x, E.one())\n 0\n sage: Eform(x, x*z*y)\n 0\n sage: Eform(E.one(), E.one())\n 1\n sage: Eform(E.zero(), E.one())\n 0\n sage: Eform(x, y)\n 1\n sage: Eform(z, y)\n -3\n sage: Eform(x*z, y*z)\n 20\n sage: Eform(x+x*y+x*y*z, z+z*y+z*y*x)\n 11\n\n TESTS:\n\n Exterior algebra over a zero space (a border case)::\n\n sage: E = ExteriorAlgebra(QQ, 0)\n sage: M = Matrix(QQ, [])\n sage: Eform = E.lifted_bilinear_form(M)\n sage: Eform(E.one(), E.one())\n 1\n sage: Eform(E.zero(), E.one())\n 0\n\n .. TODO::\n\n Another way to compute this bilinear form seems to be to\n map `x` and `y` to the appropriate Clifford algebra and\n there compute `x^t y`, then send the result back to the\n exterior algebra and return its constant coefficient. Or\n something like this. Once the maps to the Clifford and\n back are implemented, check if this is faster.\n ' R = self.base_ring() def lifted_form(x, y): result = R.zero() for (mx, cx) in x: for (my, cy) in y: n = len(mx) m = len(my) if (m != n): continue matrix_list = [M[(i, j)] for i in mx for j in my] MA = MatrixArgs(R, n, matrix_list) del matrix_list result += ((cx * cy) * MA.matrix(False).determinant()) return result from sage.categories.cartesian_product import cartesian_product return PoorManMap(lifted_form, domain=cartesian_product([self, self]), codomain=self.base_ring(), name='Bilinear Form') def _ideal_class_(self, n=0): "\n Return the class that is used to implement ideals of ``self``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: type(E.ideal(x*y - z))\n <class 'sage.algebras.clifford_algebra.ExteriorAlgebraIdeal'>\n\n TESTS::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: E._ideal_class_()\n <class 'sage.algebras.clifford_algebra.ExteriorAlgebraIdeal'>\n " return ExteriorAlgebraIdeal Element = ExteriorAlgebraElement
class ExteriorAlgebraDifferential(ModuleMorphismByLinearity, UniqueRepresentation, metaclass=InheritComparisonClasscallMetaclass): '\n Internal class to store the data of a boundary or coboundary of\n an exterior algebra `\\Lambda(L)` defined by the structure\n coefficients of a Lie algebra `L`.\n\n See :class:`ExteriorAlgebraBoundary` and\n :class:`ExteriorAlgebraCoboundary` for the actual classes, which\n inherit from this.\n\n .. WARNING::\n\n This is not a general class for differentials on the exterior\n algebra.\n ' @staticmethod def __classcall__(cls, E, s_coeff): '\n Standardize the structure coefficients to ensure a unique\n representation.\n\n EXAMPLES::\n\n sage: from sage.algebras.clifford_algebra import ExteriorAlgebraDifferential\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: par1 = ExteriorAlgebraDifferential(E, {(0,1): z, (1,2): x, (2,0): y})\n sage: par2 = ExteriorAlgebraDifferential(E, {(0,1): z, (1,2): x, (0,2): -y})\n sage: par3 = ExteriorAlgebraDifferential(E, {(1,0): {2:-1}, (1,2): {0:1}, (2,0):{1:1}})\n sage: par1 is par2\n True\n sage: par1 is par3\n True\n sage: par2 is par3\n True\n\n sage: par4 = ExteriorAlgebraDifferential(E, {})\n sage: par5 = ExteriorAlgebraDifferential(E, {(1,0): 0, (1,2): {}, (0,2): E.zero()})\n sage: par6 = ExteriorAlgebraDifferential(E, {(1,0): 0, (1,2): 0, (0,2): 0})\n sage: par4 is par5 and par5 is par6\n True\n ' d = {} for (k, v) in dict(s_coeff).items(): if (not v): continue if isinstance(v, dict): R = E.base_ring() v = E._from_dict({FrozenBitset((i,)): R(c) for (i, c) in v.items()}) else: v = E(v) if (v.list() and (v.degree() != 1)): raise ValueError('elements must be degree 1') if (k[0] < k[1]): d[tuple(k)] = v else: d[(k[1], k[0])] = (- v) from sage.sets.family import Family return super().__classcall__(cls, E, Family(d)) def __init__(self, E, s_coeff): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: par = E.boundary({(0,1): z, (1,2):x, (2,0):y})\n\n We skip the pickling test as there is an infinite recursion when\n doing equality checks::\n\n sage: TestSuite(par).run(skip="_test_pickling")\n\n Check that it knows it is a finite-dimensional algebra\n morphism (:trac:`25339`):;\n\n sage: par.category_for()\n Category of finite dimensional algebras with basis over Rational Field\n sage: par.matrix()\n [ 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 1 0]\n [ 0 0 0 0 0 -1 0 0]\n [ 0 0 0 0 1 0 0 0]\n [ 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0]\n ' self._s_coeff = s_coeff cat = AlgebrasWithBasis(E.base_ring()).FiniteDimensional() ModuleMorphismByLinearity.__init__(self, domain=E, codomain=E, category=cat) def homology(self, deg=None, **kwds): '\n Return the homology determined by ``self``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: par = E.boundary({(0,1): z, (1,2): x, (2,0): y})\n sage: par.homology()\n {0: Vector space of dimension 1 over Rational Field,\n 1: Vector space of dimension 0 over Rational Field,\n 2: Vector space of dimension 0 over Rational Field,\n 3: Vector space of dimension 1 over Rational Field}\n sage: d = E.coboundary({(0,1): z, (1,2): x, (2,0): y})\n sage: d.homology()\n {0: Vector space of dimension 1 over Rational Field,\n 1: Vector space of dimension 0 over Rational Field,\n 2: Vector space of dimension 0 over Rational Field,\n 3: Vector space of dimension 1 over Rational Field}\n ' return self.chain_complex().homology(deg, **kwds)
class ExteriorAlgebraBoundary(ExteriorAlgebraDifferential): '\n The boundary `\\partial` of an exterior algebra `\\Lambda(L)` defined\n by the structure coefficients of `L`.\n\n Let `L` be a Lie algebra. We give the exterior algebra\n `E = \\Lambda(L)` a chain complex structure by considering a\n differential `\\partial : \\Lambda^{k+1}(L) \\to \\Lambda^k(L)` defined by\n\n .. MATH::\n\n \\partial(x_1 \\wedge x_2 \\wedge \\cdots \\wedge x_{k+1})\n = \\sum_{i < j} (-1)^{i+j+1}\n [x_i, x_j] \\wedge x_1 \\wedge \\cdots \\wedge \\hat{x}_i \\wedge \\cdots\n \\wedge \\hat{x}_j \\wedge \\cdots \\wedge x_{k+1}\n\n where `\\hat{x}_i` denotes a missing index. The corresponding homology is\n the Lie algebra homology.\n\n INPUT:\n\n - ``E`` -- an exterior algebra of a vector space `L`\n - ``s_coeff`` -- a dictionary whose keys are in `I \\times I`, where\n `I` is the index set of the basis of the vector space `L`, and whose\n values can be coerced into 1-forms (degree 1 elements) in ``E``;\n this dictionary will be used to define the Lie algebra structure\n on `L` (indeed, the `i`-th coordinate of the Lie bracket of the\n `j`-th and `k`-th basis vectors of `L` for `j < k` is set to be\n the value at the key `(j, k)` if this key appears in ``s_coeff``,\n or otherwise the negated of the value at the key `(k, j)`)\n\n .. WARNING::\n\n The values of ``s_coeff`` are supposed to be coercible into\n 1-forms in ``E``; but they can also be dictionaries themselves\n (in which case they are interpreted as giving the coordinates of\n vectors in ``L``). In the interest of speed, these dictionaries\n are not sanitized or checked.\n\n .. WARNING::\n\n For any two distinct elements `i` and `j` of `I`, the dictionary\n ``s_coeff`` must have only one of the pairs `(i, j)` and\n `(j, i)` as a key. This is not checked.\n\n EXAMPLES:\n\n We consider the differential given by Lie algebra given by the cross\n product `\\times` of `\\RR^3`::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: par = E.boundary({(0,1): z, (1,2): x, (2,0): y})\n sage: par(x)\n 0\n sage: par(x*y)\n z\n sage: par(x*y*z)\n 0\n sage: par(x+y-y*z+x*y)\n -x + z\n sage: par(E.zero())\n 0\n\n We check that `\\partial \\circ \\partial = 0`::\n\n sage: p2 = par * par\n sage: all(p2(b) == 0 for b in E.basis())\n True\n\n Another example: the Lie algebra `\\mathfrak{sl}_2`, which has a\n basis `e,f,h` satisfying `[h,e] = 2e`, `[h,f] = -2f`, and `[e,f] = h`::\n\n sage: E.<e,f,h> = ExteriorAlgebra(QQ)\n sage: par = E.boundary({(0,1): h, (2,1): -2*f, (2,0): 2*e})\n sage: par(E.zero())\n 0\n sage: par(e)\n 0\n sage: par(e*f)\n h\n sage: par(f*h)\n 2*f\n sage: par(h*f)\n -2*f\n sage: C = par.chain_complex(); C\n Chain complex with at most 4 nonzero terms over Rational Field\n sage: ascii_art(C)\n [ 0 -2 0] [0]\n [ 0 0 2] [0]\n [0 0 0] [ 1 0 0] [0]\n 0 <-- C_0 <-------- C_1 <----------- C_2 <---- C_3 <-- 0\n sage: C.homology()\n {0: Vector space of dimension 1 over Rational Field,\n 1: Vector space of dimension 0 over Rational Field,\n 2: Vector space of dimension 0 over Rational Field,\n 3: Vector space of dimension 1 over Rational Field}\n\n Over the integers::\n\n sage: C = par.chain_complex(R=ZZ); C\n Chain complex with at most 4 nonzero terms over Integer Ring\n sage: ascii_art(C)\n [ 0 -2 0] [0]\n [ 0 0 2] [0]\n [0 0 0] [ 1 0 0] [0]\n 0 <-- C_0 <-------- C_1 <----------- C_2 <---- C_3 <-- 0\n sage: C.homology()\n {0: Z, 1: C2 x C2, 2: 0, 3: Z}\n\n REFERENCES:\n\n - :wikipedia:`Exterior_algebra#Lie_algebra_homology`\n ' def _repr_type(self): "\n TESTS::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: par = E.boundary({(0,1): z, (1,2): x, (2,0): y})\n sage: par._repr_type()\n 'Boundary'\n " return 'Boundary' def _on_basis(self, m): '\n Return the differential on the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: par = E.boundary({(0,1): z, (1,2): x, (2,0): y})\n sage: par._on_basis(FrozenBitset())\n 0\n sage: par._on_basis((0,))\n 0\n sage: par._on_basis((0,1))\n z\n sage: par._on_basis((0,2))\n -y\n sage: par._on_basis((0,1,2))\n 0\n ' from itertools import combinations E = self.domain() sc = self._s_coeff keys = sc.keys() s = E.zero() for (b, (i, j)) in enumerate(combinations(m, 2)): if ((i, j) not in keys): continue t = Bitset(m) t.discard(i) t.discard(j) s += (sc[(i, j)] * E.term(FrozenBitset(t), ((- 1) ** b))) return s @cached_method def chain_complex(self, R=None): '\n Return the chain complex over ``R`` determined by ``self``.\n\n INPUT:\n\n - ``R`` -- the base ring; the default is the base ring of\n the exterior algebra\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: par = E.boundary({(0,1): z, (1,2): x, (2,0): y})\n sage: C = par.chain_complex(); C\n Chain complex with at most 4 nonzero terms over Rational Field\n sage: ascii_art(C)\n [ 0 0 1] [0]\n [ 0 -1 0] [0]\n [0 0 0] [ 1 0 0] [0]\n 0 <-- C_0 <-------- C_1 <----------- C_2 <---- C_3 <-- 0\n\n TESTS:\n\n This still works in degree `1`::\n\n sage: E.<x> = ExteriorAlgebra(QQ)\n sage: par = E.boundary({})\n sage: C = par.chain_complex(); C\n Chain complex with at most 2 nonzero terms over Rational Field\n sage: ascii_art(C)\n [0]\n 0 <-- C_0 <---- C_1 <-- 0\n\n Also in degree `0`::\n\n sage: E = ExteriorAlgebra(QQ, 0)\n sage: par = E.boundary({})\n sage: C = par.chain_complex(); C\n Chain complex with at most 1 nonzero terms over Rational Field\n sage: ascii_art(C)\n 0 <-- C_0 <-- 0\n ' from sage.homology.chain_complex import ChainComplex from sage.matrix.constructor import Matrix E = self.domain() n = E.ngens() if (R is None): R = E.base_ring() if (n == 0): return ChainComplex({1: Matrix(R, [[]])}, degree=(- 1)) basis_by_deg = {deg: [] for deg in range((n + 1))} for b in E.basis().keys(): basis_by_deg[len(b)].append(b) data = {} prev_basis = basis_by_deg[0] for deg in range(1, (n + 1)): basis = sorted(basis_by_deg[deg]) mat = [] for b in basis: ret = self._on_basis(b) mat.append([ret.coefficient(p) for p in prev_basis]) data[deg] = Matrix(mat).transpose().change_ring(R) prev_basis = basis return ChainComplex(data, degree=(- 1))
class ExteriorAlgebraCoboundary(ExteriorAlgebraDifferential): '\n The coboundary `d` of an exterior algebra `\\Lambda(L)` defined\n by the structure coefficients of a Lie algebra `L`.\n\n Let `L` be a Lie algebra. We endow its exterior algebra\n `E = \\Lambda(L)` with a cochain complex structure by considering a\n differential `d : \\Lambda^k(L) \\to \\Lambda^{k+1}(L)` defined by\n\n .. MATH::\n\n d x_i = \\sum_{j < k} s_{jk}^i x_j x_k,\n\n where `(x_1, x_2, \\ldots, x_n)` is a basis of `L`, and where\n `s_{jk}^i` is the `x_i`-coordinate of the Lie bracket `[x_j, x_k]`.\n\n The corresponding cohomology is the Lie algebra cohomology of `L`.\n\n This can also be thought of as the exterior derivative, in which case\n the resulting cohomology is the de Rham cohomology of a manifold whose\n exterior algebra of differential forms is ``E``.\n\n INPUT:\n\n - ``E`` -- an exterior algebra of a vector space `L`\n - ``s_coeff`` -- a dictionary whose keys are in `I \\times I`, where\n `I` is the index set of the basis of the vector space `L`, and whose\n values can be coerced into 1-forms (degree 1 elements) in ``E``;\n this dictionary will be used to define the Lie algebra structure\n on `L` (indeed, the `i`-th coordinate of the Lie bracket of the\n `j`-th and `k`-th basis vectors of `L` for `j < k` is set to be\n the value at the key `(j, k)` if this key appears in ``s_coeff``,\n or otherwise the negated of the value at the key `(k, j)`)\n\n .. WARNING::\n\n For any two distinct elements `i` and `j` of `I`, the dictionary\n ``s_coeff`` must have only one of the pairs `(i, j)` and\n `(j, i)` as a key. This is not checked.\n\n EXAMPLES:\n\n We consider the differential coming from the Lie algebra given by the\n cross product `\\times` of `\\RR^3`::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: d = E.coboundary({(0,1): z, (1,2): x, (0, 2): -y})\n sage: d(x)\n y*z\n sage: d(y)\n -x*z\n sage: d(x+y-y*z)\n -x*z + y*z\n sage: d(x*y)\n 0\n sage: d(E.one())\n 0\n sage: d(E.zero())\n 0\n\n We check that `d \\circ d = 0`::\n\n sage: d2 = d * d\n sage: all(d2(b) == 0 for b in E.basis())\n True\n\n Another example: the Lie algebra `\\mathfrak{sl}_2`, which has a\n basis `e,f,h` satisfying `[h,e] = 2e`, `[h,f] = -2f`, and `[e,f] = h`::\n\n sage: E.<e,f,h> = ExteriorAlgebra(QQ)\n sage: d = E.coboundary({(0,1): h, (2,1): -2*f, (2,0): 2*e})\n sage: d(E.zero())\n 0\n sage: d(e)\n -2*e*h\n sage: d(f)\n 2*f*h\n sage: d(h)\n e*f\n sage: d(e*f)\n 0\n sage: d(f*h)\n 0\n sage: d(e*h)\n 0\n sage: C = d.chain_complex(); C\n Chain complex with at most 4 nonzero terms over Rational Field\n sage: ascii_art(C)\n [ 0 0 1] [0]\n [-2 0 0] [0]\n [0 0 0] [ 0 2 0] [0]\n 0 <-- C_3 <-------- C_2 <----------- C_1 <---- C_0 <-- 0\n sage: C.homology()\n {0: Vector space of dimension 1 over Rational Field,\n 1: Vector space of dimension 0 over Rational Field,\n 2: Vector space of dimension 0 over Rational Field,\n 3: Vector space of dimension 1 over Rational Field}\n\n Over the integers::\n\n sage: C = d.chain_complex(R=ZZ); C\n Chain complex with at most 4 nonzero terms over Integer Ring\n sage: ascii_art(C)\n [ 0 0 1] [0]\n [-2 0 0] [0]\n [0 0 0] [ 0 2 0] [0]\n 0 <-- C_3 <-------- C_2 <----------- C_1 <---- C_0 <-- 0\n sage: C.homology()\n {0: Z, 1: 0, 2: C2 x C2, 3: Z}\n\n REFERENCES:\n\n - :wikipedia:`Exterior_algebra#Differential_geometry`\n ' def __init__(self, E, s_coeff): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: d = E.coboundary({(0,1): z, (1,2):x, (2,0):y})\n sage: TestSuite(d).run() # known bug - morphisms are properly in a category\n ' self._cos_coeff = {} zero = E.zero() B = E.basis() for (k, v) in dict(s_coeff).items(): if (k[0] > k[1]): k = sorted(k) v = (- v) k = B[FrozenBitset(k)] for (m, c) in v: self._cos_coeff[m] = (self._cos_coeff.get(m, zero) + (c * k)) ExteriorAlgebraDifferential.__init__(self, E, s_coeff) def _repr_type(self): "\n TESTS::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: d = E.coboundary({(0,1): z, (1,2): x, (2,0): y})\n sage: d._repr_type()\n 'Coboundary'\n " return 'Coboundary' def _on_basis(self, m): '\n Return the differential on the basis element indexed by ``m``.\n\n EXAMPLES:\n\n The vector space `\\RR^3` made into a Lie algebra using the\n cross product::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: d = E.coboundary({(0,1): z, (1,2): x, (0,2): -y})\n sage: d._on_basis(())\n 0\n sage: d._on_basis((0,))\n y*z\n sage: d._on_basis((1,))\n -x*z\n sage: d._on_basis((2,))\n x*y\n sage: d._on_basis((0,1))\n 0\n sage: d._on_basis((0,2))\n 0\n sage: d._on_basis((0,1,2))\n 0\n ' E = self.domain() cc = self._cos_coeff tot = E.zero() for (sgn, i) in enumerate(m): k = FrozenBitset((i,)) if (k in cc): below = tuple([j for j in m if (j < i)]) above = tuple([j for j in m if (j > i)]) if (not below): below = E.one() else: below = E.monomial(FrozenBitset(below)) if (not above): above = E.one() else: above = E.monomial(FrozenBitset(above)) tot += (((((- 1) ** sgn) * below) * cc[k]) * above) return tot @cached_method def chain_complex(self, R=None): '\n Return the chain complex over ``R`` determined by ``self``.\n\n INPUT:\n\n - ``R`` -- the base ring; the default is the base ring of\n the exterior algebra\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: d = E.coboundary({(0,1): z, (1,2): x, (2,0): y})\n sage: C = d.chain_complex(); C\n Chain complex with at most 4 nonzero terms over Rational Field\n sage: ascii_art(C)\n [ 0 0 1] [0]\n [ 0 -1 0] [0]\n [0 0 0] [ 1 0 0] [0]\n 0 <-- C_3 <-------- C_2 <----------- C_1 <---- C_0 <-- 0\n\n TESTS:\n\n This still works in degree `1`::\n\n sage: E.<x> = ExteriorAlgebra(QQ)\n sage: d = E.coboundary({})\n sage: C = d.chain_complex(); C\n Chain complex with at most 2 nonzero terms over Rational Field\n sage: ascii_art(C)\n [0]\n 0 <-- C_1 <---- C_0 <-- 0\n\n Also in degree `0`::\n\n sage: E = ExteriorAlgebra(QQ, 0)\n sage: d = E.coboundary({})\n sage: C = d.chain_complex(); C\n Chain complex with at most 1 nonzero terms over Rational Field\n sage: ascii_art(C)\n 0 <-- C_0 <-- 0\n ' from sage.homology.chain_complex import ChainComplex from sage.matrix.constructor import Matrix E = self.domain() n = E.ngens() if (R is None): R = E.base_ring() if (n == 0): return ChainComplex({(- 1): Matrix(R, [[]])}, degree=1) basis_by_deg = {deg: [] for deg in range((n + 1))} for b in E.basis().keys(): basis_by_deg[len(b)].append(b) data = {} basis = basis_by_deg[0] for deg in range(n): next_basis = sorted(basis_by_deg[(deg + 1)]) mat = [] for b in basis: ret = self._on_basis(b) try: mat.append([ret.coefficient(p) for p in next_basis]) except AttributeError: mat.append(([E.base_ring()(ret)] * len(next_basis))) data[deg] = Matrix(mat).transpose().change_ring(R) basis = next_basis return ChainComplex(data, degree=1)
@richcmp_method class ExteriorAlgebraIdeal(Ideal_nc): '\n An ideal of the exterior algebra.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: I = E.ideal(x*y); I\n Twosided Ideal (x*y) of The exterior algebra of rank 3 over Rational Field\n\n We can also use it to build a quotient::\n\n sage: Q = E.quotient(I); Q\n Quotient of The exterior algebra of rank 3 over Rational Field by the ideal (x*y)\n sage: Q.inject_variables()\n Defining xbar, ybar, zbar\n sage: xbar * ybar\n 0\n ' def __init__(self, ring, gens, coerce=True, side='twosided'): '\n Initialize ``self``.\n\n EXAMPLES:\n\n We skip the category test because the ideals are not a proper\n element class of the monoid of all ideals::\n\n sage: E.<y, x> = ExteriorAlgebra(QQ)\n sage: I = E.ideal([x*y - x, x*y - 1])\n sage: TestSuite(I).run(skip="_test_category")\n\n sage: I = E.ideal([x*y - 3, 0, 2*3])\n sage: TestSuite(I).run(skip="_test_category")\n\n sage: I = E.ideal([])\n sage: TestSuite(I).run(skip="_test_category")\n ' self._groebner_strategy = None self._reduced = False self._homogeneous = all((x.is_super_homogeneous() for x in gens if x)) if self._homogeneous: side = 'twosided' Ideal_nc.__init__(self, ring, gens, coerce, side) def reduce(self, f): '\n Reduce ``f`` modulo ``self``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: I = E.ideal(x*y);\n sage: I.reduce(x*y + x*y*z + z)\n z\n sage: I.reduce(x*y + x + y)\n x + y\n sage: I.reduce(x*y + x*y*z)\n 0\n\n sage: E.<a,b,c,d> = ExteriorAlgebra(QQ)\n sage: I = E.ideal([a+b*c])\n sage: I.reduce(I.gen(0) * d)\n 0\n ' if (self._groebner_strategy is None): self.groebner_basis() R = self.ring() return self._groebner_strategy.reduce(R(f)) def _contains_(self, f): '\n Return ``True`` if ``f`` is in this ideal,\n ``False`` otherwise.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: I = E.ideal([x, x*y*z + 2*x*z + 3*y*z], side="left")\n sage: I.groebner_basis()\n (x, y*z)\n sage: x in I\n True\n sage: y*z in I\n True\n sage: x + 3*y*z in I\n True\n sage: x + 3*y in I\n False\n sage: x*y in I\n True\n sage: x + x*y + y*z + x*z in I\n True\n\n .. NOTE::\n\n Requires computation of a Groebner basis, which can be a very\n expensive operation.\n ' return (not self.reduce(f)) def __richcmp__(self, other, op): '\n Compare ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: I = E.ideal([x, x*y*z + 2*x*z + 3*y*z])\n sage: I == I\n True\n sage: Ip = E.ideal([x, y*z])\n sage: Ip == I\n True\n sage: Ip <= I\n True\n sage: Ip < I\n False\n sage: Ip >= I\n True\n sage: Ip > I\n False\n sage: E.ideal([x]) < I\n True\n sage: E.ideal([x]) <= I\n True\n sage: I <= E.ideal([x])\n False\n\n sage: E.<a,b,c,d> = ExteriorAlgebra(QQ)\n sage: p = a + b*c\n sage: IT = E.ideal([p], side="twosided")\n sage: IR = E.ideal([p], side="right")\n sage: IL = E.ideal([p], side="left")\n sage: IR == IL\n False\n sage: IR <= IL\n False\n sage: IR >= IL\n False\n sage: IL.reduce(p * d)\n 2*a*d\n sage: IR.reduce(d * p)\n -2*a*d\n\n sage: IR <= IT\n True\n sage: IL <= IT\n True\n sage: IT <= IL\n False\n sage: IT <= IR\n False\n ' if (not isinstance(other, ExteriorAlgebraIdeal)): if (op == op_EQ): return False if (op == op_NE): return True return NotImplemented if (self is other): return rich_to_bool(op, 0) if (op == op_GE): return other.__richcmp__(self, op_LE) elif (op == op_GT): return other.__richcmp__(self, op_LT) s_gens = {g for g in self.gens() if g} o_gens = {g for g in other.gens() if g} if (self.side() != other.side()): if (other.side() == 'right'): X = {(t * f) for t in self.ring().basis() for f in s_gens} s_gens.update(X) elif (other.side() == 'left'): X = {(f * t) for t in self.ring().basis() for f in s_gens} s_gens.update(X) if (set(s_gens) == set(o_gens)): return rich_to_bool(op, 0) contained = all(((f in other) for f in s_gens)) if (op == op_LE): return contained if ((op == op_NE) and (not contained)): return True if (self.side() != other.side()): if (self.side() == 'right'): X = {(t * f) for t in self.ring().basis() for f in o_gens} s_gens.update(X) elif (self.side() == 'left'): X = {(f * t) for t in self.ring().basis() for f in o_gens} s_gens.update(X) contains = all(((f in self) for f in o_gens)) if (op == op_EQ): return (contained and contains) if (op == op_NE): return (not (contained and contains)) return (contained and (not contains)) def __mul__(self, other): '\n Return the product of ``self`` with ``other``.\n\n .. WARNING::\n\n If ``self`` is a right ideal and ``other`` is a left ideal,\n this returns a submodule rather than an ideal.\n\n EXAMPLES::\n\n sage: E.<a,b,c,d> = ExteriorAlgebra(QQ)\n\n sage: I = E.ideal([a + 1], side="left")\n sage: J = I * I; J\n Left Ideal (2*a + 1, a, b, c, d, a*b, a*c, a*d, 2*a*b*c + b*c, 2*a*b*d + b*d,\n 2*a*c*d + c*d, a*b*c, a*b*d, a*c*d, b*c*d, a*b*c*d)\n of The exterior algebra of rank 4 over Rational Field\n sage: J.groebner_basis()\n (1,)\n sage: I.gen(0)^2\n 2*a + 1\n\n sage: J = E.ideal([b+c])\n sage: I * J\n Twosided Ideal (a*b + a*c + b + c) of The exterior algebra of rank 4 over Rational Field\n sage: J * I\n Left Ideal (-a*b - a*c + b + c) of The exterior algebra of rank 4 over Rational Field\n\n sage: K = J * I\n sage: K\n Left Ideal (-a*b - a*c + b + c) of The exterior algebra of rank 4 over Rational Field\n sage: E.ideal([J.gen(0) * d * I.gen(0)], side="left") <= K\n True\n\n sage: J = E.ideal([b + c*d], side="right")\n sage: I * J\n Twosided Ideal (a*c*d + a*b + c*d + b) of The exterior algebra of rank 4 over Rational Field\n sage: X = J * I; X\n Free module generated by {0, 1, 2, 3, 4, 5, 6, 7} over Rational Field\n sage: [X.lift(b) for b in X.basis()]\n [c*d + b, -a*c*d + a*b, b*c, b*d, a*b*c, a*b*d, b*c*d, a*b*c*d]\n sage: p = X.lift(X.basis()[0])\n sage: p\n c*d + b\n sage: a * p # not a left ideal\n a*c*d + a*b\n\n sage: I = E.ideal([a + 1], side="right")\n sage: E.ideal([1]) * I\n Twosided Ideal (a + 1) of The exterior algebra of rank 4 over Rational Field\n sage: I * E.ideal([1])\n Right Ideal (a + 1) of The exterior algebra of rank 4 over Rational Field\n ' if ((not isinstance(other, ExteriorAlgebraIdeal)) or (self.ring() != other.ring())): return super().__mul__(other) if (self._homogeneous or other._homogeneous or ((self.side() == 'left') and (other.side() == 'right'))): gens = ((x * y) for x in self.gens() for y in other.gens()) else: gens = (((x * t) * y) for t in self.ring().basis() for x in self.gens() for y in other.gens()) gens = [z for z in gens if z] if ((self.side() == 'right') and (other.side() == 'left')): return self.ring().submodule(gens) if ((self.side() == 'left') or (self.side() == 'twosided')): if ((other.side() == 'right') or (other.side() == 'twosided')): return self.ring().ideal(gens, side='twosided') return self.ring().ideal(gens, side='left') return self.ring().ideal(gens, side='right') def groebner_basis(self, term_order=None, reduced=True): '\n Return the (reduced) Gröbner basis of ``self``.\n\n INPUT:\n\n - ``term_order`` -- the term order used to compute the Gröbner basis;\n must be one of the following:\n\n * ``"neglex"`` -- (default) negative (read right-to-left) lex order\n * ``"degrevlex"`` -- degree reverse lex order\n * ``"deglex"`` -- degree lex order\n\n - ``reduced`` -- (default: ``True``) whether or not to return the\n reduced Gröbner basis\n\n EXAMPLES:\n\n We compute an example::\n\n sage: E.<a,b,c,d,e> = ExteriorAlgebra(QQ)\n sage: rels = [c*d*e - b*d*e + b*c*e - b*c*d,\n ....: c*d*e - a*d*e + a*c*e - a*c*d,\n ....: b*d*e - a*d*e + a*b*e - a*b*d,\n ....: b*c*e - a*c*e + a*b*e - a*b*c,\n ....: b*c*d - a*c*d + a*b*d - a*b*c]\n sage: I = E.ideal(rels)\n sage: I.groebner_basis()\n (-a*b*c + a*b*d - a*c*d + b*c*d,\n -a*b*c + a*b*e - a*c*e + b*c*e,\n -a*b*d + a*b*e - a*d*e + b*d*e,\n -a*c*d + a*c*e - a*d*e + c*d*e)\n\n With different term orders::\n\n sage: I.groebner_basis("degrevlex")\n (b*c*d - b*c*e + b*d*e - c*d*e,\n a*c*d - a*c*e + a*d*e - c*d*e,\n a*b*d - a*b*e + a*d*e - b*d*e,\n a*b*c - a*b*e + a*c*e - b*c*e)\n\n sage: I.groebner_basis("deglex")\n (-a*b*c + a*b*d - a*c*d + b*c*d,\n -a*b*c + a*b*e - a*c*e + b*c*e,\n -a*b*d + a*b*e - a*d*e + b*d*e,\n -a*c*d + a*c*e - a*d*e + c*d*e)\n\n The example above was computed first using M2, which agrees with\n the ``"degrevlex"`` ordering::\n\n E = QQ[a..e, SkewCommutative => true]\n I = ideal( c*d*e - b*d*e + b*c*e - b*c*d,\n c*d*e - a*d*e + a*c*e - a*c*d,\n b*d*e - a*d*e + a*b*e - a*b*d,\n b*c*e - a*c*e + a*b*e - a*b*c,\n b*c*d - a*c*d + a*b*d - a*b*c)\n groebnerBasis(I)\n\n returns:\n o3 = | bcd-bce+bde-cde acd-ace+ade-cde abd-abe+ade-bde abc-abe+ace-bce |\n\n By default, the Gröbner basis is reduced, but we can get non-reduced\n Gröber bases (which are not unique)::\n\n sage: E.<x,y,z> = ExteriorAlgebra(QQ)\n sage: I = E.ideal([x+y*z])\n sage: I.groebner_basis(reduced=False)\n (x*y, x*z, y*z + x, x*y*z)\n sage: I.groebner_basis(reduced=True)\n (x*y, x*z, y*z + x)\n\n However, if we have already computed a reduced Gröbner basis (with\n a given term order), then we return that::\n\n sage: I = E.ideal([x+y*z]) # A fresh ideal\n sage: I.groebner_basis()\n (x*y, x*z, y*z + x)\n sage: I.groebner_basis(reduced=False)\n (x*y, x*z, y*z + x)\n\n TESTS::\n\n sage: E.<a,b,c,d,e> = ExteriorAlgebra(ZZ)\n sage: I = E.ideal([a+1, b*c+d])\n sage: I.groebner_basis()\n Traceback (most recent call last):\n ...\n NotImplementedError: only implemented over fields\n ' if (self.ring().base_ring() not in Fields()): raise NotImplementedError('only implemented over fields') if (term_order is None): if (self._groebner_strategy is not None): strategy = type(self._groebner_strategy) else: from sage.algebras.exterior_algebra_groebner import GroebnerStrategyNegLex as strategy elif (term_order == 'neglex'): from sage.algebras.exterior_algebra_groebner import GroebnerStrategyNegLex as strategy elif (term_order == 'degrevlex'): from sage.algebras.exterior_algebra_groebner import GroebnerStrategyDegRevLex as strategy elif (term_order == 'deglex'): from sage.algebras.exterior_algebra_groebner import GroebnerStrategyDegLex as strategy else: raise ValueError('invalid term order') if isinstance(self._groebner_strategy, strategy): if (self._reduced or (not reduced)): return self._groebner_strategy.groebner_basis self._reduced = reduced self._groebner_strategy.reduce_computed_gb() return self._groebner_strategy.groebner_basis self._groebner_strategy = strategy(self) self._groebner_strategy.compute_groebner(reduced=reduced) self._reduced = reduced return self._groebner_strategy.groebner_basis
def sorting_keys(element): '\n Auxiliary function to sort the elements of a basis of a Cohomology group.\n\n It is needed to ensure that elements of a cohomology group are represented\n in a consistent way.\n\n INPUT:\n\n - ``element`` - A CohomologyClass\n\n OUTPUT:\n\n Its coordinates in the corresponding ``cohomology_raw`` quotient vector space\n\n EXAMPLES::\n\n sage: from sage.algebras.commutative_dga import sorting_keys\n sage: A.<e1,e2,e3,e4,e5> = GradedCommutativeAlgebra(QQ)\n sage: B = A.cdg_algebra({e5:e1*e2+e3*e4})\n sage: B.inject_variables()\n Defining e1, e2, e3, e4, e5\n sage: C = B.cohomology(3)\n sage: [sorting_keys(el) for el in C.basis().keys()]\n [[1, 0, 0, 0, 0],\n [0, 1, 0, 0, 0],\n [0, 0, 1, 0, 0],\n [0, 0, 0, 1, 0],\n [0, 0, 0, 0, 1]]\n ' x = element._x P = x.parent() CR = P.cohomology_raw(x.degree()) V = CR.V() return list(CR(V(x.basis_coefficients())))
class Differential(UniqueRepresentation, Morphism, metaclass=InheritComparisonClasscallMetaclass): "\n Differential of a commutative graded algebra.\n\n INPUT:\n\n - ``A`` -- algebra where the differential is defined\n - ``im_gens`` -- tuple containing the image of each generator\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1, 1, 2, 3))\n sage: B = A.cdg_algebra({x: x*y, y: -x*y , z: t})\n sage: B\n Commutative Differential Graded Algebra with generators ('x', 'y', 'z', 't')\n in degrees (1, 1, 2, 3) over Rational Field with differential:\n x --> x*y\n y --> -x*y\n z --> t\n t --> 0\n sage: B.differential()(x)\n x*y\n " @staticmethod def __classcall__(cls, A, im_gens): "\n Normalize input to ensure a unique representation.\n\n TESTS::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1, 1, 2, 3))\n sage: d1 = A.cdg_algebra({x: x*y, y: -x*y, z: t}).differential()\n sage: d2 = A.cdg_algebra({x: x*y, z: t, y: -x*y, t: 0}).differential()\n sage: d1 is d2\n True\n\n Check that :trac:`34818` is solved::\n\n sage: A.<a,b,x,u> = GradedCommutativeAlgebra(QQ,degrees=(2,2,3,3))\n sage: A = A.quotient(A.ideal([a*u,b*u,x*u]))\n sage: A.cdg_algebra({x:a*b,a:u})\n Commutative Differential Graded Algebra with generators ('a', 'b', 'x', 'u')\n in degrees (2, 2, 3, 3) with relations [a*u, b*u, x*u] over Rational Field\n with differential:\n a --> u\n b --> 0\n x --> a*b\n u --> 0\n sage: A.cdg_algebra({x:a*b,a:u,u:a^2})\n Traceback (most recent call last):\n ...\n ValueError: the differential does not preserve the ideal\n " if isinstance(im_gens, (list, tuple)): im_gens = {A.gen(i): A(x) for (i, x) in enumerate(im_gens)} else: im_gens = {A(a): A(im_gens[a]) for a in im_gens} I = A.defining_ideal() def image_monomial(exponent): i = 0 cexp = list(exponent) ell = len(cexp) while (i < ell): if (not cexp[i]): i += 1 continue a = A.gen(i) try: da = im_gens[a] except KeyError: da = A.zero() cexp[i] -= 1 b = A.prod(((A.gen(j) ** cexp[j]) for j in range(len(cexp)))) db = image_monomial(cexp) im = ((da * b) + ((((- 1) ** A._degrees[i]) * a) * db)) return A(im) return A.zero() for g in I.gens(): d = g.dict() res = A.sum(((d[ex] * image_monomial(ex)) for ex in d)) if (not res.is_zero()): raise ValueError('the differential does not preserve the ideal') for i in im_gens: x = im_gens[i] if ((not x.is_zero()) and ((not x.is_homogeneous()) or (total_degree(x.degree()) != (total_degree(i.degree()) + 1)))): raise ValueError('the given dictionary does not determine a degree 1 map') im_gens = tuple((im_gens.get(x, A.zero()) for x in A.gens())) return super().__classcall__(cls, A, im_gens) def __init__(self, A, im_gens): '\n Initialize ``self``.\n\n INPUT:\n\n - ``A`` -- algebra where the differential is defined\n\n - ``im_gens`` -- tuple containing the image of each generator\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ)\n sage: B = A.cdg_algebra({x: x*y, y: x*y, z: z*t, t: t*z})\n sage: [B.cohomology(i).dimension() for i in range(6)]\n [1, 2, 1, 0, 0, 0]\n sage: d = B.differential()\n\n We skip the category test because homsets/morphisms aren\'t\n proper parents/elements yet::\n\n sage: TestSuite(d).run(skip="_test_category")\n\n An error is raised if the differential `d` does not have\n degree 1 or if `d \\circ d` is not zero::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3))\n sage: A.cdg_algebra({a:b, b:c})\n Traceback (most recent call last):\n ...\n ValueError: the given dictionary does not determine a valid differential\n ' self._dic_ = {A.gen(i): x for (i, x) in enumerate(im_gens)} Morphism.__init__(self, Hom(A, A, category=Modules(A.base_ring()))) for i in A.gens(): if (not self(self(i)).is_zero()): raise ValueError('the given dictionary does not determine a valid differential') def _call_(self, x): '\n Apply the differential to ``x``.\n\n INPUT:\n\n - ``x`` -- an element of the domain of this differential\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ)\n sage: B = A.cdg_algebra({x: x*y, y: x*y, z: z*t, t: t*z})\n sage: D = B.differential()\n sage: D(x*t+1/2*t*x*y) # indirect doctest\n -1/2*x*y*z*t + x*y*t + x*z*t\n\n Test positive characteristic::\n\n sage: A.<x,y> = GradedCommutativeAlgebra(GF(17), degrees=(2, 3))\n sage: B = A.cdg_algebra(differential={x:y})\n sage: B.differential()(x^17)\n 0\n ' if x.is_zero(): return self.codomain().zero() res = self.codomain().zero() dic = x.dict() for key in dic: keyl = list(key) coef = dic[key] idx = 0 while keyl: exp = keyl.pop(0) if (exp > 0): v1 = ((exp * self._dic_[x.parent().gen(idx)]) * (x.parent().gen(idx) ** (exp - 1))) v2 = prod(((x.parent().gen(((i + idx) + 1)) ** keyl[i]) for i in range(len(keyl)))) res += ((coef * v1) * v2) coef *= (((- 1) ** total_degree(x.parent()._degrees[idx])) * (x.parent().gen(idx) ** exp)) idx += 1 return res def _repr_defn(self): '\n Return a string showing where ``self`` sends each generator.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ)\n sage: B = A.cdg_algebra({x: x*y, y: x*y, z: z*t, t: t*z})\n sage: D = B.differential()\n sage: print(D._repr_defn())\n x --> x*y\n y --> x*y\n z --> z*t\n t --> -z*t\n ' return '\n'.join((f'{i} --> {self(i)}' for i in self.domain().gens())) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ)\n sage: D = A.differential({x: x*y, y: x*y, z: z*t, t: t*z})\n sage: D\n Differential of Graded Commutative Algebra with generators ('x', 'y', 'z', 't') in degrees (1, 1, 1, 1) over Rational Field\n Defn: x --> x*y\n y --> x*y\n z --> z*t\n t --> -z*t\n " if (self.domain() is None): return 'Defunct morphism' s = 'Differential of {}'.format(self.domain()._base_repr()) s += ('\n Defn: ' + '\n '.join(self._repr_defn().split('\n'))) return s @cached_method def differential_matrix(self, n): '\n The matrix that gives the differential in degree ``n``.\n\n INPUT:\n\n - ``n`` -- degree\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(GF(5), degrees=(2, 2, 3, 4))\n sage: d = A.differential({t: x*z, x: z, y: z})\n sage: d.differential_matrix(4)\n [2 0]\n [1 1]\n [0 2]\n [1 0]\n sage: A.inject_variables()\n Defining x, y, z, t\n sage: d(t)\n x*z\n sage: d(y^2)\n 2*y*z\n sage: d(x*y)\n x*z + y*z\n sage: d(x^2)\n 2*x*z\n ' A = self.domain() dom = A.basis(n) cod = A.basis((n + 1)) cokeys = [next(iter(a.lift().dict().keys())) for a in cod] m = matrix(A.base_ring(), len(dom), len(cod)) for (i, domi) in enumerate(dom): im = self(domi) dic = im.lift().dict() for j in dic.keys(): k = cokeys.index(j) m[(i, k)] = dic[j] m.set_immutable() return m def coboundaries(self, n): '\n The ``n``-th coboundary group of the algebra.\n\n This is a vector space over the base field `F`, and it is\n returned as a subspace of the vector space `F^d`, where the\n ``n``-th homogeneous component has dimension `d`.\n\n INPUT:\n\n - ``n`` -- degree\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1, 1, 2))\n sage: d = A.differential({z: x*z})\n sage: d.coboundaries(2)\n Vector space of degree 2 and dimension 0 over Rational Field\n Basis matrix:\n []\n sage: d.coboundaries(3)\n Vector space of degree 2 and dimension 1 over Rational Field\n Basis matrix:\n [1 0]\n sage: d.coboundaries(1)\n Vector space of degree 2 and dimension 0 over Rational Field\n Basis matrix:\n []\n\n ' A = self.domain() F = A.base_ring() if (n == 0): return VectorSpace(F, 0) if (n == 1): V0 = VectorSpace(F, len(A.basis(1))) return V0.subspace([]) M = self.differential_matrix((n - 1)) V0 = VectorSpace(F, M.nrows()) V1 = VectorSpace(F, M.ncols()) mor = V0.Hom(V1)(M) return mor.image() def cocycles(self, n): '\n The ``n``-th cocycle group of the algebra.\n\n This is a vector space over the base field `F`, and it is\n returned as a subspace of the vector space `F^d`, where the\n ``n``-th homogeneous component has dimension `d`.\n\n INPUT:\n\n - ``n`` -- degree\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1, 1, 2))\n sage: d = A.differential({z: x*z})\n sage: d.cocycles(2)\n Vector space of degree 2 and dimension 1 over Rational Field\n Basis matrix:\n [1 0]\n ' A = self.domain() F = A.base_ring() if (n == 0): return VectorSpace(F, 1) M = self.differential_matrix(n) V0 = VectorSpace(F, M.nrows()) V1 = VectorSpace(F, M.ncols()) mor = V0.Hom(V1)(M) return mor.kernel() def cohomology_raw(self, n): '\n The ``n``-th cohomology group of ``self``.\n\n This is a vector space over the base ring, and it is returned\n as the quotient cocycles/coboundaries.\n\n INPUT:\n\n - ``n`` -- degree\n\n .. SEEALSO::\n\n :meth:`cohomology`\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3, 4))\n sage: d = A.differential({t: x*z, x: z, y: z})\n sage: d.cohomology_raw(4)\n Vector space quotient V/W of dimension 2 over Rational Field where\n V: Vector space of degree 4 and dimension 2 over Rational Field\n Basis matrix:\n [ 1 0 0 -2]\n [ 0 1 -1/2 -1]\n W: Vector space of degree 4 and dimension 0 over Rational Field\n Basis matrix:\n []\n\n Compare to :meth:`cohomology`::\n\n sage: d.cohomology(4)\n Free module generated by {[x^2 - 2*t], [x*y - 1/2*y^2 - t]} over Rational Field\n ' return self.cocycles(n).quotient(self.coboundaries(n)) def cohomology(self, n): '\n The ``n``-th cohomology group of ``self``.\n\n This is a vector space over the base ring, defined as the\n quotient cocycles/coboundaries. The elements of the quotient\n are lifted to the vector space of cocycles, and this is\n described in terms of those lifts.\n\n INPUT:\n\n - ``n`` -- degree\n\n .. SEEALSO::\n\n :meth:`cohomology_raw`\n\n EXAMPLES::\n\n sage: A.<a,b,c,d,e> = GradedCommutativeAlgebra(QQ, degrees=(1, 1, 1, 1, 1))\n sage: d = A.differential({d: a*b, e: b*c})\n sage: d.cohomology(2)\n Free module generated by {[a*c], [a*d], [b*d], [c*d - a*e], [b*e], [c*e]} over Rational Field\n\n Compare to :meth:`cohomology_raw`::\n\n sage: d.cohomology_raw(2)\n Vector space quotient V/W of dimension 6 over Rational Field where\n V: Vector space of degree 10 and dimension 8 over Rational Field\n Basis matrix:\n [ 1 0 0 0 0 0 0 0 0 0]\n [ 0 1 0 0 0 0 0 0 0 0]\n [ 0 0 1 0 0 0 0 0 0 0]\n [ 0 0 0 1 0 0 0 0 0 0]\n [ 0 0 0 0 1 0 0 0 0 0]\n [ 0 0 0 0 0 1 -1 0 0 0]\n [ 0 0 0 0 0 0 0 1 0 0]\n [ 0 0 0 0 0 0 0 0 1 0]\n W: Vector space of degree 10 and dimension 2 over Rational Field\n Basis matrix:\n [1 0 0 0 0 0 0 0 0 0]\n [0 0 1 0 0 0 0 0 0 0]\n ' H = self.cohomology_raw(n) H_basis_raw = (H.lift(H.basis()[i]) for i in range(H.dimension())) A = self.domain() B = A.basis(n) H_basis = (sum(((c * b) for (c, b) in zip(coeffs, B))) for coeffs in H_basis_raw) H_basis_brackets = [CohomologyClass(b, A) for b in H_basis] return CombinatorialFreeModule(A.base_ring(), H_basis_brackets, sorting_key=sorting_keys, monomial_reverse=True) homology = cohomology def _is_nonzero(self): '\n Return ``True`` iff this morphism is nonzero.\n\n This is used by the :meth:`Morphism.__bool__` method, which\n in turn is used by the :func:`TestSuite` test\n ``_test_nonzero_equal``.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1, 1, 2, 3))\n sage: B = A.cdg_algebra({x: x*y, y: -x*y , z: t})\n sage: B.differential()._is_nonzero()\n True\n sage: bool(B.differential())\n True\n sage: C = A.cdg_algebra({x: 0, y: 0, z: 0})\n sage: C.differential()._is_nonzero()\n False\n sage: bool(C.differential())\n False\n ' return any(self._dic_.values())
class Differential_multigraded(Differential): '\n Differential of a commutative multi-graded algebra.\n ' def __init__(self, A, im_gens): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1, 0), (0, 1), (0, 2)))\n sage: d = A.differential({a: c})\n\n We skip the category test because homsets/morphisms aren\'t\n proper parents/elements yet::\n\n sage: TestSuite(d).run(skip="_test_category")\n ' Differential.__init__(self, A, im_gens) diff_deg = [] for x in A.gens(): y = self(x) if (y != 0): diff_deg.append((y.degree() - x.degree())) if (len(set(diff_deg)) > 1): raise ValueError('the differential does not have a well-defined degree') self._degree_of_differential = diff_deg[0] @cached_method def differential_matrix_multigraded(self, n, total=False): '\n The matrix that gives the differential in degree ``n``.\n\n .. TODO::\n\n Rename this to ``differential_matrix`` once inheritance,\n overriding, and cached methods work together better. See\n :trac:`17201`.\n\n INPUT:\n\n - ``n`` -- degree\n - ``total`` -- (default: ``False``) if ``True``,\n return the matrix corresponding to total degree ``n``\n\n If ``n`` is an integer rather than a multi-index, then the\n total degree is used in that case as well.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1, 0), (0, 1), (0, 2)))\n sage: d = A.differential({a: c})\n sage: d.differential_matrix_multigraded((1, 0))\n [1]\n sage: d.differential_matrix_multigraded(1, total=True)\n [0 1]\n [0 0]\n sage: d.differential_matrix_multigraded((1, 0), total=True)\n [0 1]\n [0 0]\n sage: d.differential_matrix_multigraded(1)\n [0 1]\n [0 0]\n ' if (total or (n in ZZ)): return Differential.differential_matrix(self, total_degree(n)) A = self.domain() G = AdditiveAbelianGroup(([0] * A._grading_rank)) n = G(vector(n)) dom = A.basis(n) cod = A.basis((n + self._degree_of_differential)) cokeys = [next(iter(a.lift().dict().keys())) for a in cod] m = matrix(self.base_ring(), len(dom), len(cod)) for (i, domi) in enumerate(dom): im = self(domi) dic = im.lift().dict() for j in dic.keys(): k = cokeys.index(j) m[(i, k)] = dic[j] m.set_immutable() return m def coboundaries(self, n, total=False): '\n The ``n``-th coboundary group of the algebra.\n\n This is a vector space over the base field `F`, and it is\n returned as a subspace of the vector space `F^d`, where the\n ``n``-th homogeneous component has dimension `d`.\n\n INPUT:\n\n - ``n`` -- degree\n - ``total`` (default ``False``) -- if ``True``, return the\n coboundaries in total degree ``n``\n\n If ``n`` is an integer rather than a multi-index, then the\n total degree is used in that case as well.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1, 0), (0, 1), (0, 2)))\n sage: d = A.differential({a: c})\n sage: d.coboundaries((0, 2))\n Vector space of degree 1 and dimension 1 over Rational Field\n Basis matrix:\n [1]\n sage: d.coboundaries(2)\n Vector space of degree 2 and dimension 1 over Rational Field\n Basis matrix:\n [0 1]\n ' if (total or (n in ZZ)): return Differential.coboundaries(self, total_degree(n)) A = self.domain() G = AdditiveAbelianGroup(([0] * A._grading_rank)) n = G(vector(n)) F = A.base_ring() if (total_degree(n) == 0): return VectorSpace(F, 0) if (total_degree(n) == 1): return VectorSpace(F, 0) M = self.differential_matrix_multigraded((n - self._degree_of_differential)) V0 = VectorSpace(F, M.nrows()) V1 = VectorSpace(F, M.ncols()) mor = V0.Hom(V1)(M) return mor.image() def cocycles(self, n, total=False): '\n The ``n``-th cocycle group of the algebra.\n\n This is a vector space over the base field `F`, and it is\n returned as a subspace of the vector space `F^d`, where the\n ``n``-th homogeneous component has dimension `d`.\n\n INPUT:\n\n - ``n`` -- degree\n - ``total`` -- (default: ``False``) if ``True``, return the\n cocycles in total degree ``n``\n\n If ``n`` is an integer rather than a multi-index, then the\n total degree is used in that case as well.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1, 0), (0, 1), (0, 2)))\n sage: d = A.differential({a: c})\n sage: d.cocycles((0, 1))\n Vector space of degree 1 and dimension 1 over Rational Field\n Basis matrix:\n [1]\n sage: d.cocycles((0, 1), total=True)\n Vector space of degree 2 and dimension 1 over Rational Field\n Basis matrix:\n [0 1]\n ' if (total or (n in ZZ)): return Differential.cocycles(self, total_degree(n)) A = self.domain() G = AdditiveAbelianGroup(([0] * A._grading_rank)) n = G(vector(n)) F = A.base_ring() if (total_degree(n) == 0): return VectorSpace(F, 1) M = self.differential_matrix_multigraded(n) V0 = VectorSpace(F, M.nrows()) V1 = VectorSpace(F, M.ncols()) mor = V0.Hom(V1)(M) return mor.kernel() def cohomology_raw(self, n, total=False): '\n The ``n``-th cohomology group of the algebra.\n\n This is a vector space over the base ring, and it is returned\n as the quotient cocycles/coboundaries.\n\n INPUT:\n\n - ``n`` -- degree\n - ``total`` -- (default: ``False``) if ``True``, return the\n cohomology in total degree ``n``\n\n If ``n`` is an integer rather than a multi-index, then the\n total degree is used in that case as well.\n\n .. SEEALSO::\n\n :meth:`cohomology`\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1, 0), (0, 1), (0, 2)))\n sage: d = A.differential({a: c})\n sage: d.cohomology_raw((0, 2))\n Vector space quotient V/W of dimension 0 over Rational Field where\n V: Vector space of degree 1 and dimension 1 over Rational Field\n Basis matrix:\n [1]\n W: Vector space of degree 1 and dimension 1 over Rational Field\n Basis matrix:\n [1]\n\n sage: d.cohomology_raw(1)\n Vector space quotient V/W of dimension 1 over Rational Field where\n V: Vector space of degree 2 and dimension 1 over Rational Field\n Basis matrix:\n [0 1]\n W: Vector space of degree 2 and dimension 0 over Rational Field\n Basis matrix:\n []\n ' return self.cocycles(n, total).quotient(self.coboundaries(n, total)) def cohomology(self, n, total=False): '\n The ``n``-th cohomology group of the algebra.\n\n This is a vector space over the base ring, defined as the\n quotient cocycles/coboundaries. The elements of the quotient\n are lifted to the vector space of cocycles, and this is\n described in terms of those lifts.\n\n INPUT:\n\n - ``n`` -- degree\n - ``total`` -- (default: ``False``) if ``True``, return the\n cohomology in total degree ``n``\n\n If ``n`` is an integer rather than a multi-index, then the\n total degree is used in that case as well.\n\n .. SEEALSO::\n\n :meth:`cohomology_raw`\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1, 0), (0, 1), (0, 2)))\n sage: d = A.differential({a: c})\n sage: d.cohomology((0, 2))\n Free module generated by {} over Rational Field\n\n sage: d.cohomology(1)\n Free module generated by {[b]} over Rational Field\n ' H = self.cohomology_raw(n, total) H_basis_raw = (H.lift(H.basis()[i]) for i in range(H.dimension())) A = self.domain() B = A.basis(n, total) H_basis = (sum(((c * b) for (c, b) in zip(coeffs, B))) for coeffs in H_basis_raw) H_basis_brackets = [CohomologyClass(b, A) for b in H_basis] return CombinatorialFreeModule(A.base_ring(), H_basis_brackets, sorting_key=sorting_keys, monomial_reverse=True) homology = cohomology
class GCAlgebra(UniqueRepresentation, QuotientRing_nc): '\n A graded commutative algebra.\n\n INPUT:\n\n - ``base`` -- the base field\n\n - ``names`` -- (optional) names of the generators: a list of\n strings or a single string with the names separated by\n commas. If not specified, the generators are named "x0", "x1",\n ...\n\n - ``degrees`` -- (optional) a tuple or list specifying the degrees\n of the generators; if omitted, each generator is given degree\n 1, and if both ``names`` and ``degrees`` are omitted, an error is\n raised.\n\n - ``R`` (optional, default None) -- the ring over which the\n algebra is defined: if this is specified, the algebra is defined\n to be ``R/I``.\n\n - ``I`` (optional, default None) -- an ideal in ``R``. It is\n should include, among other relations, the squares of the\n generators of odd degree\n\n As described in the module-level documentation, these are graded\n algebras for which oddly graded elements anticommute and evenly\n graded elements commute.\n\n The arguments ``R`` and ``I`` are primarily for use by the\n :meth:`quotient` method.\n\n These algebras should be graded over the integers; multi-graded\n algebras should be constructed using\n :class:`GCAlgebra_multigraded` instead.\n\n EXAMPLES::\n\n sage: A.<a,b> = GradedCommutativeAlgebra(QQ, degrees = (2, 3))\n sage: a.degree()\n 2\n sage: B = A.quotient(A.ideal(a**2*b))\n sage: B\n Graded Commutative Algebra with generators (\'a\', \'b\') in degrees (2, 3)\n with relations [a^2*b] over Rational Field\n sage: A.basis(7)\n [a^2*b]\n sage: B.basis(7)\n []\n\n Note that the function :func:`GradedCommutativeAlgebra` can also be used to\n construct these algebras.\n ' @staticmethod def __classcall__(cls, base, names=None, degrees=None, R=None, I=None, category=None): "\n Normalize the input for the :meth:`__init__` method and the\n unique representation.\n\n INPUT:\n\n - ``base`` -- the base ring of the algebra\n\n - ``names`` -- the names of the variables; by default, set to ``x1``,\n ``x2``, etc.\n\n - ``degrees`` -- the degrees of the generators; by default, set to 1\n\n - ``R`` -- an underlying `g`-algebra; only meant to be used by the\n quotient method\n\n - ``I`` -- a two-sided ideal in ``R``, with the desired relations;\n Only meant to be used by the quotient method\n\n TESTS::\n\n sage: A1 = GradedCommutativeAlgebra(GF(2), 'x,y', (3, 6))\n sage: A2 = GradedCommutativeAlgebra(GF(2), ['x', 'y'], [3, 6])\n sage: A1 is A2\n True\n\n Testing the single generator case (:trac:`25276`)::\n\n sage: A3.<z> = GradedCommutativeAlgebra(QQ)\n sage: z**2 == 0\n True\n sage: A4.<z> = GradedCommutativeAlgebra(QQ, degrees=[4])\n sage: z**2 == 0\n False\n sage: A5.<z> = GradedCommutativeAlgebra(GF(2))\n sage: z**2 == 0\n False\n " if (names is None): if (degrees is None): raise ValueError('you must specify names or degrees') n = len(degrees) names = tuple((f'x{i}' for i in range(n))) elif isinstance(names, str): names = tuple(names.split(',')) n = len(names) else: n = len(names) names = tuple(names) if (degrees is None): degrees = tuple(([1] * n)) else: if degrees: try: rank = len(list(degrees[0])) G = AdditiveAbelianGroup(([0] * rank)) degrees = [G(vector(d)) for d in degrees] except TypeError: pass degrees = tuple(degrees) if ((not R) or (not I)): if (n > 1): F = FreeAlgebra(base, n, names) else: F = PolynomialRing(base, n, names) gens = F.gens() rels = {} tot_degs = [total_degree(d) for d in degrees] for i in range((len(gens) - 1)): for j in range((i + 1), len(gens)): rels[(gens[j] * gens[i])] = ((((- 1) ** (tot_degs[i] * tot_degs[j])) * gens[i]) * gens[j]) if (n > 1): R = F.g_algebra(rels, order=TermOrder('wdegrevlex', tot_degs)) else: R = F.quotient(rels) if (base.characteristic() == 2): I = R.ideal(0, side='twosided') else: I = R.ideal([(R.gen(i) ** 2) for i in range(n) if is_odd(tot_degs[i])], side='twosided') return super().__classcall__(cls, base=base, names=names, degrees=degrees, R=R, I=I, category=category) def __init__(self, base, R=None, I=None, names=None, degrees=None, category=None): "\n Initialize ``self``.\n\n INPUT:\n\n - ``base`` -- the base field\n\n - ``R`` -- (optional) the ring over which the algebra is defined\n\n - ``I`` -- (optional) an ideal over the corresponding `g`-algebra;\n it is meant to include, among other relations, the squares of the\n generators of odd degree\n\n - ``names`` -- (optional) the names of the generators; if omitted,\n this uses the names ``x0``, ``x1``, ...\n\n - ``degrees`` -- (optional) the degrees of the generators; if\n omitted, they are given degree 1\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ)\n sage: TestSuite(A).run()\n sage: A = GradedCommutativeAlgebra(QQ, ('x','y','z'), [2,3,4])\n sage: TestSuite(A).run()\n sage: A = GradedCommutativeAlgebra(QQ, ('x','y','z','t'), [1,2,3,4])\n sage: TestSuite(A).run()\n " self._degrees = tuple(degrees) category = Algebras(R.base_ring()).Graded().or_subcategory(category) QuotientRing_nc.__init__(self, R, I, names, category=category) def _repr_(self): "\n Print representation.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=[1, 2, 3, 4])\n sage: A\n Graded Commutative Algebra with generators ('x', 'y', 'z', 't') in degrees (1, 2, 3, 4) over Rational Field\n sage: A.quotient(A.ideal(3*x*t - 2*y*z))\n Graded Commutative Algebra with generators ('x', 'y', 'z', 't') in degrees (1, 2, 3, 4) with relations [-2*y*z + 3*x*t] over Rational Field\n " s = 'Graded Commutative Algebra with generators {} in degrees {}'.format(self._names, self._degrees) I = self.defining_ideal() R = self.cover_ring() degrees = self._degrees if (self.base().characteristic() != 2): squares = [(R.gen(i) ** 2) for i in range(len(degrees)) if is_odd(degrees[i])] else: squares = [R.zero()] relns = [g for g in I.gens() if (g not in squares)] if relns: s += ' with relations {}'.format(relns) return (s + ' over {}'.format(self.base_ring())) _base_repr = _repr_ @cached_method def _basis_for_free_alg(self, n): '\n Basis of the associated free commutative DGA in degree ``n``.\n\n That is, ignore the relations when computing the basis:\n compute the basis of the free commutative DGA with generators\n in degrees given by ``self._degrees``.\n\n INPUT:\n\n - ``n`` -- integer\n\n OUTPUT:\n\n Tuple of basis elements in degree ``n``, as tuples of exponents.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3))\n sage: A._basis_for_free_alg(3)\n [(0, 0, 1), (1, 1, 0)]\n sage: B = A.quotient(A.ideal(a*b, b**2+a*c))\n sage: B._basis_for_free_alg(3)\n [(0, 0, 1), (1, 1, 0)]\n\n sage: GradedCommutativeAlgebra(QQ, degrees=(1,1))._basis_for_free_alg(3)\n []\n sage: GradedCommutativeAlgebra(GF(2), degrees=(1,1))._basis_for_free_alg(3)\n [(0, 3), (1, 2), (2, 1), (3, 0)]\n\n sage: A = GradedCommutativeAlgebra(GF(2), degrees=(4,8,12))\n sage: A._basis_for_free_alg(399)\n []\n ' if (n == 0): return (((0,) * len(self._degrees)),) if (self.base_ring().characteristic() == 2): return [tuple(_) for _ in WeightedIntegerVectors(n, self._degrees)] even_degrees = [] odd_degrees = [] for a in self._degrees: if is_even(a): even_degrees.append(a) else: odd_degrees.append(a) if (not even_degrees): return [tuple(_) for _ in exterior_algebra_basis(n, tuple(odd_degrees))] if (not odd_degrees): return [tuple(_) for _ in WeightedIntegerVectors(n, tuple(even_degrees))] result = [] for dim in range((n + 1)): if (dim == 0): even_result = [([0] * len(even_degrees))] else: even_result = WeightedIntegerVectors(dim, tuple(even_degrees)) for even_mono in even_result: deg = (n - dim) odd_result = exterior_algebra_basis(deg, tuple(odd_degrees)) for odd_mono in odd_result: temp_even = list(even_mono) temp_odd = list(odd_mono) mono = [] for a in self._degrees: if is_even(a): mono.append(temp_even.pop(0)) else: mono.append(temp_odd.pop(0)) result.append(tuple(mono)) return result def basis(self, n): '\n Return a basis of the ``n``-th homogeneous component of ``self``.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1, 2, 2, 3))\n sage: A.basis(2)\n [y, z]\n sage: A.basis(3)\n [x*y, x*z, t]\n sage: A.basis(4)\n [y^2, y*z, z^2, x*t]\n sage: A.basis(5)\n [x*y^2, x*y*z, x*z^2, y*t, z*t]\n sage: A.basis(6)\n [y^3, y^2*z, y*z^2, z^3, x*y*t, x*z*t]\n ' free_basis = self._basis_for_free_alg(n) fb_reversed_entries = [list(reversed(e)) for e in free_basis] fb_reversed_entries.sort() free_basis = (tuple(reversed(e)) for e in fb_reversed_entries) basis = [] for v in free_basis: el = prod([(self.gen(i) ** v[i]) for i in range(len(v))]) di = el.dict() if (len(di) == 1): (k,) = di.keys() if (tuple(k) == v): basis.append(el) return basis def quotient(self, I, check=True): "\n Create the quotient of this algebra by a two-sided ideal ``I``.\n\n INPUT:\n\n - ``I`` -- a two-sided homogeneous ideal of this algebra\n\n - ``check`` -- (default: ``True``) if ``True``, check whether\n ``I`` is generated by homogeneous elements\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(GF(5), degrees=(2, 2, 3, 4))\n sage: I = A.ideal([x*t+z^2, x*y - t])\n sage: B = A.quotient(I); B\n Graded Commutative Algebra with generators ('x', 'y', 'z', 't')\n in degrees (2, 2, 3, 4) with relations [x*t, x*y - t]\n over Finite Field of size 5\n sage: B(x*t)\n 0\n sage: B(x*y)\n t\n sage: A.basis(7)\n [x^2*z, x*y*z, y^2*z, z*t]\n sage: B.basis(7)\n [x^2*z, y^2*z, z*t]\n " if (check and any(((not i.is_homogeneous()) for i in I.gens()))): raise ValueError('the ideal must be homogeneous') NCR = self.cover_ring() gens1 = list(self.defining_ideal().gens()) gens2 = [i.lift() for i in I.gens()] gens = [g for g in (gens1 + gens2) if (g != NCR.zero())] J = NCR.ideal(gens, side='twosided') return GCAlgebra(self.base_ring(), self._names, self._degrees, NCR, J) def _coerce_map_from_(self, other): '\n Return ``True`` if there is a coercion map from ``R`` to ``self``.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2))\n sage: B = A.cdg_algebra({y:x*y, x: x*y})\n sage: A._coerce_map_from_(B)\n True\n sage: B._coerce_map_from_(A)\n True\n sage: B._coerce_map_from_(QQ)\n True\n sage: B._coerce_map_from_(GF(3))\n False\n ' if isinstance(other, GCAlgebra): if ((self._names != other._names) or (self._degrees != other._degrees)): return False if (set(self.defining_ideal().gens()) != set(other.defining_ideal().gens())): return False return self.cover_ring().has_coerce_map_from(other.cover_ring()) return super()._coerce_map_from_(other) def _element_constructor_(self, x, coerce=True): '\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3, 4))\n sage: A({(1,3,0,1): 2, (2,2,1,2): 3})\n 3*x^2*y^2*z*t^2 + 2*x*y^3*t\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(GF(5))\n sage: A({(1,3,0,1): 2, (2,2,1,2): 3})\n 0\n\n TESTS::\n\n sage: B = A.cdg_algebra({})\n sage: B(x, coerce=False)\n x\n ' if isinstance(x, QuotientRingElement): if (x.parent() is self): return x x = x.lift() if isinstance(x, dict): res = self.zero() for i in x.keys(): mon = prod(((self.gen(j) ** i[j]) for j in range(len(i)))) res += (x[i] * mon) return res if coerce: R = self.cover_ring() x = R(x) if isinstance(x, sage.interfaces.abc.SingularElement): x = self.element_class(self, x.sage_poly(self.cover_ring())) return x return self.element_class(self, x) def _Hom_(self, B, category): "\n Return the homset from ``self`` to ``B`` in the category ``category``.\n\n INPUT:\n\n - ``B`` -- a graded commutative algebra\n - ``category`` -- a subcategory of graded algebras or ``None``\n\n EXAMPLES::\n\n sage: A.<x,y> = GradedCommutativeAlgebra(QQ)\n sage: B.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3))\n sage: C.<d> = GradedCommutativeAlgebra(GF(17))\n sage: Hom(A,A)\n Set of Homomorphisms\n from Graded Commutative Algebra with generators ('x', 'y')\n in degrees (1, 1) over Rational Field\n to Graded Commutative Algebra with generators ('x', 'y')\n in degrees (1, 1) over Rational Field\n sage: Hom(A,B)\n Set of Homomorphisms\n from Graded Commutative Algebra with generators ('x', 'y')\n in degrees (1, 1) over Rational Field\n to Graded Commutative Algebra with generators ('a', 'b', 'c')\n in degrees (1, 2, 3) over Rational Field\n sage: Hom(A,C)\n Traceback (most recent call last):\n ...\n NotImplementedError: homomorphisms of graded commutative algebras\n have only been implemented when the base rings are the same\n " R = self.base_ring() if (R != B.base_ring()): raise NotImplementedError('homomorphisms of graded commutative algebras have only been implemented when the base rings are the same') cat = Algebras(R).Graded() if ((category is not None) and (not category.is_subcategory(cat))): raise TypeError('{} is not a subcategory of graded algebras'.format(category)) return GCAlgebraHomset(self, B, category=category) def differential(self, diff): "\n Construct a differential on ``self``.\n\n INPUT:\n\n - ``diff`` -- a dictionary defining a differential\n\n The keys of the dictionary are generators of the algebra, and\n the associated values are their targets under the\n differential. Any generators which are not specified are\n assumed to have zero differential.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1, 1, 2))\n sage: A.differential({y:x*y, x: x*y})\n Differential of Graded Commutative Algebra with generators ('x', 'y', 'z')\n in degrees (1, 1, 2) over Rational Field\n Defn: x --> x*y\n y --> x*y\n z --> 0\n sage: B.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1, 2, 2))\n sage: d = B.differential({b:a*c, c:a*c})\n sage: d(b*c)\n a*b*c + a*c^2\n " return Differential(self, diff) def cdg_algebra(self, differential): "\n Construct a differential graded commutative algebra from ``self``\n by specifying a differential.\n\n INPUT:\n\n - ``differential`` -- a dictionary defining a differential or\n a map defining a valid differential\n\n The keys of the dictionary are generators of the algebra, and\n the associated values are their targets under the\n differential. Any generators which are not specified are\n assumed to have zero differential. Alternatively, the\n differential can be defined using the :meth:`differential`\n method; see below for an example.\n\n .. SEEALSO::\n\n :meth:`differential`\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1, 1, 1))\n sage: B = A.cdg_algebra({a: b*c, b: a*c})\n sage: B\n Commutative Differential Graded Algebra with generators ('a', 'b', 'c')\n in degrees (1, 1, 1) over Rational Field with differential:\n a --> b*c\n b --> a*c\n c --> 0\n\n Note that ``differential`` can also be a map::\n\n sage: d = A.differential({a: b*c, b: a*c})\n sage: d\n Differential of Graded Commutative Algebra with generators ('a', 'b', 'c')\n in degrees (1, 1, 1) over Rational Field\n Defn: a --> b*c\n b --> a*c\n c --> 0\n sage: A.cdg_algebra(d) is B\n True\n " return DifferentialGCAlgebra(self, differential) class Element(QuotientRingElement): '\n An element of a graded commutative algebra.\n ' def __init__(self, A, rep): '\n Initialize ``self``.\n\n INPUT:\n\n - ``parent`` -- the graded commutative algebra in which\n this element lies, viewed as a quotient `R / I`\n\n - ``rep`` -- a representative of the element in `R`; this is used\n as the internal representation of the element\n\n EXAMPLES::\n\n sage: B.<x,y> = GradedCommutativeAlgebra(QQ, degrees=(2, 2))\n sage: a = B({(1,1): -3, (2,5): 1/2})\n sage: a\n 1/2*x^2*y^5 - 3*x*y\n sage: TestSuite(a).run()\n\n sage: b = x^2*y^3+2\n sage: b\n x^2*y^3 + 2\n ' QuotientRingElement.__init__(self, A, rep) def degree(self, total=False): '\n The degree of this element.\n\n If the element is not homogeneous, this returns the\n maximum of the degrees of its monomials.\n\n INPUT:\n\n - ``total`` -- ignored, present for compatibility with the\n multi-graded case\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1, 2, 3, 3))\n sage: el = z*t+2*x*y-y^2*z\n sage: el.degree()\n 7\n sage: el.monomials()\n [y^2*z, z*t, x*y]\n sage: [i.degree() for i in el.monomials()]\n [7, 6, 3]\n\n sage: A(0).degree()\n Traceback (most recent call last):\n ...\n ValueError: the zero element does not have a well-defined degree\n ' if self.is_zero(): raise ValueError('the zero element does not have a well-defined degree') exps = self.lift().dict().keys() degrees = self.parent()._degrees n = self.parent().ngens() l = [sum(((e[i] * degrees[i]) for i in range(n))) for e in exps] return max(l) def is_homogeneous(self, total=False): "\n Return ``True`` if ``self`` is homogeneous and ``False`` otherwise.\n\n INPUT:\n\n - ``total`` -- boolean (default ``False``); only used in the\n multi-graded case, in which case if ``True``, check to see\n if ``self`` is homogeneous with respect to total degree\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1, 2, 3, 3))\n sage: el = z*t + 2*x*y - y^2*z\n sage: el.degree()\n 7\n sage: el.monomials()\n [y^2*z, z*t, x*y]\n sage: [i.degree() for i in el.monomials()]\n [7, 6, 3]\n sage: el.is_homogeneous()\n False\n sage: em = y^3 - 5*z*t + 3/2*x*y*t\n sage: em.is_homogeneous()\n True\n sage: em.monomials()\n [y^3, x*y*t, z*t]\n sage: [i.degree() for i in em.monomials()]\n [6, 6, 6]\n\n The element 0 is homogeneous, even though it doesn't have\n a well-defined degree::\n\n sage: A(0).is_homogeneous()\n True\n\n A multi-graded example::\n\n sage: B.<c,d> = GradedCommutativeAlgebra(QQ, degrees=((2, 0), (0, 4)))\n sage: (c^2 - 1/2 * d).is_homogeneous()\n False\n sage: (c^2 - 1/2 * d).is_homogeneous(total=True)\n True\n " degree = None for m in self.monomials(): if (degree is None): degree = m.degree(total) elif (degree != m.degree(total)): return False return True def homogeneous_parts(self): '\n Return the homogeneous parts of the element. The result is given as\n a dictionary indexed by degree.\n\n\n EXAMPLES::\n\n sage: A.<e1,e2,e3,e4,e5> = GradedCommutativeAlgebra(QQ)\n sage: a = e1*e3*e5-3*e2*e3*e5 + e1*e2 -2*e3 + e5\n sage: a.homogeneous_parts()\n {1: -2*e3 + e5, 2: e1*e2, 3: e1*e3*e5 - 3*e2*e3*e5}\n ' dic = self.dict() terms = [self.parent()({t: dic[t]}) for t in dic.keys()] res = {} for term in terms: deg = term.degree() if (deg in res): res[deg] += term else: res[deg] = term return {i: res[i] for i in sorted(res.keys())} def dict(self): '\n A dictionary that determines the element.\n\n The keys of this dictionary are the tuples of exponents of each\n monomial, and the values are the corresponding coefficients.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1, 2, 2, 3))\n sage: dic = (x*y - 5*y*z + 7*x*y^2*z^3*t).dict()\n sage: sorted(dic.items())\n [((0, 1, 1, 0), -5), ((1, 1, 0, 0), 1), ((1, 2, 3, 1), 7)]\n ' return self.lift().dict() def basis_coefficients(self, total=False): '\n Return the coefficients of this homogeneous element with\n respect to the basis in its degree.\n\n For example, if this is the sum of the 0th and 2nd basis\n elements, return the list ``[1, 0, 1]``.\n\n Raise an error if the element is not homogeneous.\n\n INPUT:\n\n - ``total`` -- boolean (default ``False``); this\n is only used in the multi-graded case, in which case if\n ``True``, it returns the coefficients with respect to\n the basis for the total degree of this element\n\n OUTPUT:\n\n A list of elements of the base field.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1, 2, 2, 3))\n sage: A.basis(3)\n [x*y, x*z, t]\n sage: (t + 3*x*y).basis_coefficients()\n [3, 0, 1]\n sage: (t + x).basis_coefficients()\n Traceback (most recent call last):\n ...\n ValueError: this element is not homogeneous\n\n sage: B.<c,d> = GradedCommutativeAlgebra(QQ, degrees=((2,0), (0,4)))\n sage: B.basis(4)\n [c^2, d]\n sage: (c^2 - 1/2 * d).basis_coefficients(total=True)\n [1, -1/2]\n sage: (c^2 - 1/2 * d).basis_coefficients()\n Traceback (most recent call last):\n ...\n ValueError: this element is not homogeneous\n ' if (not self.is_homogeneous(total)): raise ValueError('this element is not homogeneous') basis = self.parent().basis(self.degree(total)) lift = self.lift() return [lift.monomial_coefficient(x.lift()) for x in basis]
class GCAlgebra_multigraded(GCAlgebra): "\n A multi-graded commutative algebra.\n\n INPUT:\n\n - ``base`` -- the base field\n\n - ``degrees`` -- a tuple or list specifying the degrees of the\n generators\n\n - ``names`` -- (optional) names of the generators: a list of\n strings or a single string with the names separated by\n commas; if not specified, the generators are named ``x0``,\n ``x1``, ...\n\n - ``R`` -- (optional) the ring over which the algebra is defined\n\n - ``I`` -- (optional) an ideal in ``R``; it should include, among\n other relations, the squares of the generators of odd degree\n\n When defining such an algebra, each entry of ``degrees`` should be\n a list, tuple, or element of an additive (free) abelian\n group. Regardless of how the user specifies the degrees, Sage\n converts them to group elements.\n\n The arguments ``R`` and ``I`` are primarily for use by the\n :meth:`GCAlgebra.quotient` method.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0,1), (1,1)))\n sage: A\n Graded Commutative Algebra with generators ('a', 'b', 'c')\n in degrees ((1, 0), (0, 1), (1, 1)) over Rational Field\n sage: a**2\n 0\n sage: c.degree(total=True)\n 2\n sage: c**2\n c^2\n sage: c.degree()\n (1, 1)\n\n Although the degree of ``c`` was defined using a Python tuple, it\n is returned as an element of an additive abelian group, and so it\n can be manipulated via arithmetic operations::\n\n sage: type(c.degree())\n <class 'sage.groups.additive_abelian.additive_abelian_group.AdditiveAbelianGroup_fixed_gens_with_category.element_class'>\n sage: 2 * c.degree()\n (2, 2)\n sage: (a*b).degree() == a.degree() + b.degree()\n True\n\n The :meth:`basis` method and the :meth:`Element.degree` method both accept\n the boolean keyword ``total``. If ``True``, use the total degree::\n\n sage: A.basis(2, total=True)\n [a*b, c]\n sage: c.degree(total=True)\n 2\n " def __init__(self, base, degrees, names=None, R=None, I=None, category=None): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0,1), (1,1)))\n sage: TestSuite(A).run()\n sage: B.<w> = GradedCommutativeAlgebra(GF(2), degrees=((3,2),))\n sage: TestSuite(B).run(skip=['_test_construction'])\n sage: C = GradedCommutativeAlgebra(GF(7), degrees=((3,2),))\n sage: TestSuite(C).run()\n " total_degs = [total_degree(d) for d in degrees] GCAlgebra.__init__(self, base, R=R, I=I, names=names, degrees=total_degs, category=category) self._degrees_multi = degrees self._grading_rank = len(list(degrees[0])) def _repr_(self): "\n Print representation.\n\n EXAMPLES::\n\n sage: GradedCommutativeAlgebra(QQ, degrees=((1,0,0), (0,0,1), (1,1,1)))\n Graded Commutative Algebra with generators ('x0', 'x1', 'x2') in degrees ((1, 0, 0), (0, 0, 1), (1, 1, 1)) over Rational Field\n " s = GCAlgebra._repr_(self) old = '{}'.format(self._degrees) new = '{}'.format(self._degrees_multi) return s.replace(old, new) _base_repr = _repr_ def quotient(self, I, check=True): "\n Create the quotient of this algebra by a two-sided ideal ``I``.\n\n INPUT:\n\n - ``I`` -- a two-sided homogeneous ideal of this algebra\n\n - ``check`` -- (default: ``True``) if ``True``, check whether\n ``I`` is generated by homogeneous elements\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(GF(5), degrees=(2, 2, 3, 4))\n sage: I = A.ideal([x*t+z^2, x*y - t])\n sage: B = A.quotient(I)\n sage: B\n Graded Commutative Algebra with generators ('x', 'y', 'z', 't')\n in degrees (2, 2, 3, 4) with relations [x*t, x*y - t]\n over Finite Field of size 5\n sage: B(x*t)\n 0\n sage: B(x*y)\n t\n sage: A.basis(7)\n [x^2*z, x*y*z, y^2*z, z*t]\n sage: B.basis(7)\n [x^2*z, y^2*z, z*t]\n " if (check and any(((not i.is_homogeneous()) for i in I.gens()))): raise ValueError('the ideal must be homogeneous') NCR = self.cover_ring() gens1 = list(self.defining_ideal().gens()) gens2 = [i.lift() for i in I.gens()] gens = [g for g in (gens1 + gens2) if (g != NCR.zero())] J = NCR.ideal(gens, side='twosided') return GCAlgebra_multigraded(self.base_ring(), self._names, self._degrees_multi, NCR, J) def _coerce_map_from_(self, other): '\n Return ``True`` if there is a coercion map from ``R`` to ``self``.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))\n sage: B = A.cdg_algebra({a: c})\n sage: B._coerce_map_from_(A)\n True\n sage: B._coerce_map_from_(QQ)\n True\n sage: B._coerce_map_from_(GF(3))\n False\n ' if isinstance(other, GCAlgebra_multigraded): if (self._degrees_multi != other._degrees_multi): return False elif isinstance(other, GCAlgebra): return False return super()._coerce_map_from_(other) def basis(self, n, total=False): "\n Basis in degree ``n``.\n\n - ``n`` -- degree or integer\n - ``total`` (optional, default False) -- if True, return the\n basis in total degree ``n``.\n\n If ``n`` is an integer rather than a multi-index, then the\n total degree is used in that case as well.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(GF(2), degrees=((1,0), (0,1), (1,1)))\n sage: A.basis((1,1))\n [a*b, c]\n sage: A.basis(2, total=True)\n [a^2, a*b, b^2, c]\n\n Since 2 is a not a multi-index, we don't need to specify ``total=True``::\n\n sage: A.basis(2)\n [a^2, a*b, b^2, c]\n\n If ``total==True``, then ``n`` can still be a tuple, list,\n etc., and its total degree is used instead::\n\n sage: A.basis((1,1), total=True)\n [a^2, a*b, b^2, c]\n " tot_basis = GCAlgebra.basis(self, total_degree(n)) if (total or (n in ZZ)): return tot_basis G = AdditiveAbelianGroup(([0] * self._grading_rank)) n = G(vector(n)) return [b for b in tot_basis if (b.degree() == n)] def differential(self, diff): "\n Construct a differential on ``self``.\n\n INPUT:\n\n - ``diff`` -- a dictionary defining a differential\n\n The keys of the dictionary are generators of the algebra, and\n the associated values are their targets under the\n differential. Any generators which are not specified are\n assumed to have zero differential.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))\n sage: A.differential({a: c})\n Differential of Graded Commutative Algebra with generators ('a', 'b', 'c')\n in degrees ((1, 0), (0, 1), (0, 2)) over Rational Field\n Defn: a --> c\n b --> 0\n c --> 0\n " return Differential_multigraded(self, diff) def cdg_algebra(self, differential): "\n Construct a differential graded commutative algebra from ``self``\n by specifying a differential.\n\n INPUT:\n\n - ``differential`` -- a dictionary defining a differential or\n a map defining a valid differential\n\n The keys of the dictionary are generators of the algebra, and\n the associated values are their targets under the\n differential. Any generators which are not specified are\n assumed to have zero differential. Alternatively, the\n differential can be defined using the :meth:`differential`\n method; see below for an example.\n\n .. SEEALSO::\n\n :meth:`differential`\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))\n sage: A.cdg_algebra({a: c})\n Commutative Differential Graded Algebra with generators ('a', 'b', 'c')\n in degrees ((1, 0), (0, 1), (0, 2)) over Rational Field with differential:\n a --> c\n b --> 0\n c --> 0\n sage: d = A.differential({a: c})\n sage: A.cdg_algebra(d)\n Commutative Differential Graded Algebra with generators ('a', 'b', 'c')\n in degrees ((1, 0), (0, 1), (0, 2)) over Rational Field with differential:\n a --> c\n b --> 0\n c --> 0\n " return DifferentialGCAlgebra_multigraded(self, differential) class Element(GCAlgebra.Element): def degree(self, total=False): '\n Return the degree of this element.\n\n INPUT:\n\n - ``total`` -- if ``True``, return the total degree, an\n integer; otherwise, return the degree as an element of\n an additive free abelian group\n\n If not requesting the total degree, raise an error if the\n element is not homogeneous.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(GF(2),\n ....: degrees=((1,0), (0,1), (1,1)))\n sage: (a**2*b).degree()\n (2, 1)\n sage: (a**2*b).degree(total=True)\n 3\n sage: (a**2*b + c).degree()\n Traceback (most recent call last):\n ...\n ValueError: this element is not homogeneous\n sage: (a**2*b + c).degree(total=True)\n 3\n sage: A(0).degree()\n Traceback (most recent call last):\n ...\n ValueError: the zero element does not have a well-defined degree\n ' if total: return GCAlgebra.Element.degree(self) if self.is_zero(): raise ValueError('the zero element does not have a well-defined degree') degrees = self.parent()._degrees_multi n = self.parent().ngens() exps = self.lift().dict().keys() l = [sum(((exp[i] * degrees[i]) for i in range(n))) for exp in exps] if (len(set(l)) == 1): return l[0] raise ValueError('this element is not homogeneous')
class DifferentialGCAlgebra(GCAlgebra): "\n A commutative differential graded algebra.\n\n INPUT:\n\n - ``A`` -- a graded commutative algebra; that is, an instance\n of :class:`GCAlgebra`\n\n - ``differential`` -- a differential\n\n As described in the module-level documentation, these are graded\n algebras for which oddly graded elements anticommute and evenly\n graded elements commute, and on which there is a graded\n differential of degree 1.\n\n These algebras should be graded over the integers; multi-graded\n algebras should be constructed using\n :class:`DifferentialGCAlgebra_multigraded` instead.\n\n Note that a natural way to construct these is to use the\n :func:`GradedCommutativeAlgebra` function and the\n :meth:`GCAlgebra.cdg_algebra` method.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3, 3))\n sage: A.cdg_algebra({z: x*y})\n Commutative Differential Graded Algebra with generators ('x', 'y', 'z', 't')\n in degrees (2, 2, 3, 3) over Rational Field with differential:\n x --> 0\n y --> 0\n z --> x*y\n t --> 0\n\n Alternatively, starting with :func:`GradedCommutativeAlgebra`::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3, 3))\n sage: A.cdg_algebra(differential={z: x*y})\n Commutative Differential Graded Algebra with generators ('x', 'y', 'z', 't')\n in degrees (2, 2, 3, 3) over Rational Field with differential:\n x --> 0\n y --> 0\n z --> x*y\n t --> 0\n\n See the function :func:`GradedCommutativeAlgebra` for more examples.\n " @staticmethod def __classcall__(cls, A, differential): '\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1,1,1))\n sage: D1 = A.cdg_algebra({a: b*c, b: a*c})\n sage: D2 = A.cdg_algebra(D1.differential())\n sage: D1 is D2\n True\n sage: from sage.algebras.commutative_dga import DifferentialGCAlgebra\n sage: D1 is DifferentialGCAlgebra(A, {a: b*c, b: a*c, c: 0})\n True\n ' if (not isinstance(differential, Differential)): differential = A.differential(differential) elif (differential.parent() != A): differential = Differential(A, differential._dic_) return super(GCAlgebra, cls).__classcall__(cls, A, differential) def __init__(self, A, differential): '\n Initialize ``self``\n\n INPUT:\n\n - ``A`` -- a graded commutative algebra\n\n - ``differential`` -- a differential\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3, 3))\n sage: D = A.cdg_algebra({z: x*y})\n sage: TestSuite(D).run()\n\n The degree of the differential must be 1::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1,1,1))\n sage: A.cdg_algebra({a: a*b*c})\n Traceback (most recent call last):\n ...\n ValueError: the given dictionary does not determine a degree 1 map\n\n The differential composed with itself must be zero::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3))\n sage: A.cdg_algebra({a:b, b:c})\n Traceback (most recent call last):\n ...\n ValueError: the given dictionary does not determine a valid differential\n ' cat = (Algebras(A.base()).Graded() & ChainComplexes(A.base())) GCAlgebra.__init__(self, A.base(), names=A._names, degrees=A._degrees, R=A.cover_ring(), I=A.defining_ideal(), category=cat) self._differential = Differential(self, differential._dic_) self._minimalmodels = {} self._numerical_invariants = {} def cdg_algebra(self, differential): "\n Construct a differential graded commutative algebra from the underlying\n graded commutative algebra by specifying a differential. This may be used\n to get a new differential over the same algebra structure.\n\n INPUT:\n\n - ``differential`` -- a dictionary defining a differential or\n a map defining a valid differential\n\n The keys of the dictionary are generators of the algebra, and\n the associated values are their targets under the\n differential. Any generators which are not specified are\n assumed to have zero differential. Alternatively, the\n differential can be defined using the :meth:`differential`\n method; see below for an example.\n\n .. SEEALSO::\n\n :meth:`differential`\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(GF(5), degrees=(2, 3, 2, 4))\n sage: B = A.quotient(A.ideal(x^3-z*t))\n sage: C = B.cdg_algebra({y:t})\n sage: C\n Commutative Differential Graded Algebra with generators ('x', 'y', 'z', 't')\n in degrees (2, 3, 2, 4) with relations [x^3 - z*t]\n over Finite Field of size 5 with differential:\n x --> 0\n y --> t\n z --> 0\n t --> 0\n sage: C.cdg_algebra({})\n Commutative Differential Graded Algebra with generators ('x', 'y', 'z', 't')\n in degrees (2, 3, 2, 4) with relations [x^3 - z*t]\n over Finite Field of size 5 with differential:\n x --> 0\n y --> 0\n z --> 0\n t --> 0\n\n " return self.graded_commutative_algebra().cdg_algebra(differential) def graded_commutative_algebra(self): '\n Return the base graded commutative algebra of ``self``.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3, 3))\n sage: D = A.cdg_algebra({z: x*y})\n sage: D.graded_commutative_algebra() == A\n True\n ' return GCAlgebra(self.base(), names=self._names, degrees=self._degrees, R=self.cover_ring(), I=self.defining_ideal()) def _base_repr(self): '\n Return the base string representation of ``self``.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=[1, 2, 3, 4])\n sage: A.cdg_algebra({x:y, z:t})._base_repr()\n "Commutative Differential Graded Algebra with generators (\'x\', \'y\', \'z\', \'t\') in degrees (1, 2, 3, 4) over Rational Field"\n ' return GCAlgebra._repr_(self).replace('Graded Commutative', 'Commutative Differential Graded') def _repr_(self): "\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=[1, 2, 3, 4])\n sage: A.cdg_algebra({x:y, z:t})\n Commutative Differential Graded Algebra with generators ('x', 'y', 'z', 't') in degrees (1, 2, 3, 4) over Rational Field with differential:\n x --> y\n y --> 0\n z --> t\n t --> 0\n " d = self._differential._repr_defn().replace('\n', '\n ') return (self._base_repr() + f''' with differential: {d}''') def quotient(self, I, check=True): '\n Create the quotient of this algebra by a two-sided ideal ``I``.\n\n INPUT:\n\n - ``I`` -- a two-sided homogeneous ideal of this algebra\n\n - ``check`` -- (default: ``True``) if ``True``, check whether\n ``I`` is generated by homogeneous elements\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2))\n sage: B = A.cdg_algebra({y:x*y, z:x*z})\n sage: B.inject_variables()\n Defining x, y, z\n sage: I = B.ideal([y*z])\n sage: C = B.quotient(I)\n sage: (y*z).differential()\n 2*x*y*z\n sage: C((y*z).differential())\n 0\n sage: C(y*z)\n 0\n\n It is checked that the differential maps the ideal into itself, to make\n sure that the quotient inherits a differential structure::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,2))\n sage: B = A.cdg_algebra({x:y})\n sage: B.quotient(B.ideal(y*x))\n Traceback (most recent call last):\n ...\n ValueError: the differential does not preserve the ideal\n sage: B.quotient(B.ideal(x))\n Traceback (most recent call last):\n ...\n ValueError: the differential does not preserve the ideal\n ' J = self.ideal(I) AQ = GCAlgebra.quotient(self, J, check) for g in I.gens(): if (not AQ(g.differential()).is_zero()): raise ValueError('the differential does not preserve the ideal') dic = {AQ(a): AQ(a.differential()) for a in self.gens()} return AQ.cdg_algebra(dic) def differential(self, x=None): "\n The differential of ``self``.\n\n This returns a map, and so it may be evaluated on elements of\n this algebra.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2))\n sage: B = A.cdg_algebra({y:x*y, x: y*x})\n sage: d = B.differential(); d\n Differential of Commutative Differential Graded Algebra\n with generators ('x', 'y', 'z') in degrees (1, 1, 2) over Rational Field\n Defn: x --> -x*y\n y --> x*y\n z --> 0\n sage: d(y)\n x*y\n " return self._differential def coboundaries(self, n): '\n The ``n``-th coboundary group of the algebra.\n\n This is a vector space over the base field `F`, and it is\n returned as a subspace of the vector space `F^d`, where the\n ``n``-th homogeneous component has dimension `d`.\n\n INPUT:\n\n - ``n`` -- degree\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2))\n sage: B = A.cdg_algebra(differential={z: x*z})\n sage: B.coboundaries(2)\n Vector space of degree 2 and dimension 0 over Rational Field\n Basis matrix:\n []\n sage: B.coboundaries(3)\n Vector space of degree 2 and dimension 1 over Rational Field\n Basis matrix:\n [1 0]\n sage: B.basis(3)\n [x*z, y*z]\n ' return self._differential.coboundaries(n) def cocycles(self, n): '\n The ``n``-th cocycle group of the algebra.\n\n This is a vector space over the base field `F`, and it is\n returned as a subspace of the vector space `F^d`, where the\n ``n``-th homogeneous component has dimension `d`.\n\n INPUT:\n\n - ``n`` -- degree\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2))\n sage: B = A.cdg_algebra(differential={z: x*z})\n sage: B.cocycles(2)\n Vector space of degree 2 and dimension 1 over Rational Field\n Basis matrix:\n [1 0]\n sage: B.basis(2)\n [x*y, z]\n ' return self._differential.cocycles(n) def cohomology_raw(self, n): '\n The ``n``-th cohomology group of ``self``.\n\n This is a vector space over the base ring, and it is returned\n as the quotient cocycles/coboundaries.\n\n INPUT:\n\n - ``n`` -- degree\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees = (2,2,3,4))\n sage: B = A.cdg_algebra({t: x*z, x: z, y: z})\n sage: B.cohomology_raw(4)\n Vector space quotient V/W of dimension 2 over Rational Field where\n V: Vector space of degree 4 and dimension 2 over Rational Field\n Basis matrix:\n [ 1 0 0 -2]\n [ 0 1 -1/2 -1]\n W: Vector space of degree 4 and dimension 0 over Rational Field\n Basis matrix:\n []\n\n Compare to :meth:`cohomology`::\n\n sage: B.cohomology(4)\n Free module generated by {[x^2 - 2*t], [x*y - 1/2*y^2 - t]} over Rational Field\n ' return self._differential.cohomology_raw(n) def cohomology(self, n): '\n The ``n``-th cohomology group of ``self``.\n\n This is a vector space over the base ring, defined as the\n quotient cocycles/coboundaries. The elements of the quotient\n are lifted to the vector space of cocycles, and this is\n described in terms of those lifts.\n\n INPUT:\n\n - ``n`` -- degree\n\n EXAMPLES::\n\n sage: A.<a,b,c,d,e> = GradedCommutativeAlgebra(QQ, degrees=(1,1,1,1,1))\n sage: B = A.cdg_algebra({d: a*b, e: b*c})\n sage: B.cohomology(2)\n Free module generated by {[a*c], [a*d], [b*d], [c*d - a*e], [b*e], [c*e]}\n over Rational Field\n\n Compare to :meth:`cohomology_raw`::\n\n sage: B.cohomology_raw(2)\n Vector space quotient V/W of dimension 6 over Rational Field where\n V: Vector space of degree 10 and dimension 8 over Rational Field\n Basis matrix:\n [ 1 0 0 0 0 0 0 0 0 0]\n [ 0 1 0 0 0 0 0 0 0 0]\n [ 0 0 1 0 0 0 0 0 0 0]\n [ 0 0 0 1 0 0 0 0 0 0]\n [ 0 0 0 0 1 0 0 0 0 0]\n [ 0 0 0 0 0 1 -1 0 0 0]\n [ 0 0 0 0 0 0 0 1 0 0]\n [ 0 0 0 0 0 0 0 0 1 0]\n W: Vector space of degree 10 and dimension 2 over Rational Field\n Basis matrix:\n [1 0 0 0 0 0 0 0 0 0]\n [0 0 1 0 0 0 0 0 0 0]\n\n TESTS:\n\n Check that the issue discovered in :trac:`28155` is solved::\n\n sage: A.<e1,e2,e3,e4,e5> = GradedCommutativeAlgebra(QQ)\n sage: B = A.cdg_algebra({e5:e1*e2+e3*e4})\n sage: B.cohomology(3) is B.cohomology(3)\n True\n ' return self._differential.cohomology(n) homology = cohomology def cohomology_generators(self, max_degree): "\n Return lifts of algebra generators for cohomology in degrees at\n most ``max_degree``.\n\n INPUT:\n\n - ``max_degree`` -- integer\n\n OUTPUT:\n\n A dictionary keyed by degree, where the corresponding\n value is a list of cohomology generators in that degree.\n Actually, the elements are lifts of cohomology generators,\n which means that they lie in this differential graded\n algebra. It also means that they are only well-defined up to\n cohomology, not on the nose.\n\n ALGORITHM:\n\n Reduce a basis of the `n`'th cohomology modulo all the degree `n`\n products of the lower degree cohomologies.\n\n EXAMPLES::\n\n sage: A.<a,x,y> = GradedCommutativeAlgebra(QQ, degrees=(1,2,2))\n sage: B = A.cdg_algebra(differential={y: a*x})\n sage: B.cohomology_generators(3)\n {1: [a], 2: [x], 3: [a*y]}\n\n The previous example has infinitely generated cohomology:\n `a y^n` is a cohomology generator for each `n`::\n\n sage: B.cohomology_generators(10)\n {1: [a], 2: [x], 3: [a*y], 5: [a*y^2], 7: [a*y^3], 9: [a*y^4]}\n\n In contrast, the corresponding algebra in characteristic `p`\n has finitely generated cohomology::\n\n sage: A3.<a,x,y> = GradedCommutativeAlgebra(GF(3), degrees=(1,2,2))\n sage: B3 = A3.cdg_algebra(differential={y: a*x})\n sage: B3.cohomology_generators(16)\n {1: [a], 2: [x], 3: [a*y], 5: [a*y^2], 6: [y^3]}\n\n This method works with both singly graded and multi-graded algebras::\n\n sage: Cs.<a,b,c,d> = GradedCommutativeAlgebra(GF(2), degrees=(1,2,2,3))\n sage: Ds = Cs.cdg_algebra({a:c, b:d})\n sage: Ds.cohomology_generators(10)\n {2: [a^2], 4: [b^2]}\n\n sage: Cm.<a,b,c,d> = GradedCommutativeAlgebra(GF(2),\n ....: degrees=((1,0), (1,1),\n ....: (0,2), (0,3)))\n sage: Dm = Cm.cdg_algebra({a:c, b:d})\n sage: Dm.cohomology_generators(10)\n {2: [a^2], 4: [b^2]}\n\n TESTS:\n\n Test that coboundaries do not appear as cohomology generators::\n\n sage: X.<x,y> = GradedCommutativeAlgebra(QQ, degrees=(1,2))\n sage: acyclic = X.cdg_algebra({x: y})\n sage: acyclic.cohomology_generators(3)\n {}\n\n Test that redundant generators are eliminated::\n\n sage: A.<e1,e2,e3,e4> = GradedCommutativeAlgebra(QQ)\n sage: d = A.differential({e1:e4*e3,e2:e4*e3})\n sage: B = A.cdg_algebra(d)\n sage: B.cohomology_generators(3)\n {1: [e1 - e2, e3, e4], 2: [e1*e3, e1*e4]}\n\n " if (not ((max_degree in ZZ) and (max_degree > 0))): raise ValueError('the given maximal degree must be a positive integer') def vector_to_element(v, deg): '\n If an element of this algebra in degree ``deg`` is represented\n by a raw vector ``v``, convert it back to an element of the\n algebra again.\n ' return sum(((c * b) for (c, b) in zip(v, self.basis(deg)))) if (max_degree == 1): cohom1 = self.cohomology(1).basis().keys() if (not cohom1): return {} return {1: [g.representative() for g in cohom1]} smaller_degree = {i: [g.representative() for g in self.cohomology(i).basis().keys()] for i in range(1, max_degree)} already_generated = [] for i in range(1, max_degree): already_generated += [(a * b) for a in smaller_degree[i] for b in smaller_degree[(max_degree - i)]] CR = self.cohomology_raw(max_degree) V = CR.V() S = CR.submodule([CR(V(g.basis_coefficients(total=True))) for g in already_generated if (not g.is_zero())]) Q = CR.quotient(S) res = self.cohomology_generators((max_degree - 1)) if Q.basis(): res[max_degree] = [vector_to_element(CR.lift(Q.lift(g)), max_degree) for g in Q.basis()] return res def minimal_model(self, i=3, max_iterations=3, partial_result=False): "\n Try to compute a map from a ``i``-minimal gcda that is a\n ``i``-quasi-isomorphism to self.\n\n INPUT:\n\n - ``i`` -- integer (default: `3`); degree to which the result is\n required to induce an isomorphism in cohomology, and the domain is\n required to be minimal.\n\n - ``max_iterations`` -- integer (default: `3`); the number of\n iterations of the method at each degree. If the algorithm does not\n finish in this many iterations at each degree, an error is raised,\n or the partial result computed up to that point is returned, deppending\n on the ``partial_result`` flag.\n\n - ``partial_result`` -- boolean (default: ``False``); wether to return\n the partial result if the ``max_iterations`` limit is reached.\n\n OUTPUT:\n\n A morphism from a minimal Sullivan (up to degree ``i``) CDGA's to self,\n that induces an isomorphism in cohomology up to degree ``i``, and a\n monomorphism in degree ``i+1``.\n\n EXAMPLES::\n\n sage: S.<x, y, z> = GradedCommutativeAlgebra(QQ, degrees = (1, 1, 2))\n sage: d = S.differential({x:x*y, y:x*y})\n sage: R = S.cdg_algebra(d)\n sage: p = R.minimal_model()\n sage: T = p.domain()\n sage: p\n Commutative Differential Graded Algebra morphism:\n From: Commutative Differential Graded Algebra\n with generators ('x1_0', 'x2_0') in degrees (1, 2)\n over Rational Field with differential:\n x1_0 --> 0\n x2_0 --> 0\n To: Commutative Differential Graded Algebra\n with generators ('x', 'y', 'z') in degrees (1, 1, 2)\n over Rational Field with differential:\n x --> x*y\n y --> x*y\n z --> 0\n Defn: (x1_0, x2_0) --> (x - y, z)\n sage: R.cohomology(1)\n Free module generated by {[x - y]} over Rational Field\n sage: T.cohomology(1)\n Free module generated by {[x1_0]} over Rational Field\n sage: [p(g.representative()) for g in T.cohomology(1).basis().keys()]\n [x - y]\n sage: R.cohomology(2)\n Free module generated by {[z]} over Rational Field\n sage: T.cohomology(2)\n Free module generated by {[x2_0]} over Rational Field\n sage: [p(g.representative()) for g in T.cohomology(2).basis().keys()]\n [z]\n\n\n\n sage: A.<e1, e2, e3, e4, e5, e6, e7> = GradedCommutativeAlgebra(QQ)\n sage: d = A.differential({e1:e1*e7, e2:e2*e7, e3:-e3*e7, e4:-e4*e7})\n sage: B = A.cdg_algebra(d)\n sage: phi = B.minimal_model(i=3)\n sage: M = phi.domain()\n sage: M\n Commutative Differential Graded Algebra with generators\n ('x1_0', 'x1_1', 'x1_2', 'x2_0', 'x2_1', 'x2_2', 'x2_3',\n 'y3_0', 'y3_1', 'y3_2', 'y3_3', 'y3_4', 'y3_5', 'y3_6', 'y3_7', 'y3_8')\n in degrees (1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3)\n over Rational Field with differential:\n x1_0 --> 0\n x1_1 --> 0\n x1_2 --> 0\n x2_0 --> 0\n x2_1 --> 0\n x2_2 --> 0\n x2_3 --> 0\n y3_0 --> x2_0^2\n y3_1 --> x2_0*x2_1\n y3_2 --> x2_1^2\n y3_3 --> x2_0*x2_2\n y3_4 --> x2_1*x2_2 + x2_0*x2_3\n y3_5 --> x2_2^2\n y3_6 --> x2_1*x2_3\n y3_7 --> x2_2*x2_3\n y3_8 --> x2_3^2\n\n sage: phi\n Commutative Differential Graded Algebra morphism:\n From: Commutative Differential Graded Algebra with generators\n ('x1_0', 'x1_1', 'x1_2', 'x2_0', 'x2_1', 'x2_2', 'x2_3',\n 'y3_0', 'y3_1', 'y3_2', 'y3_3', 'y3_4', 'y3_5', 'y3_6', 'y3_7', 'y3_8')\n in degrees (1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3)\n over Rational Field with differential:\n x1_0 --> 0\n x1_1 --> 0\n x1_2 --> 0\n x2_0 --> 0\n x2_1 --> 0\n x2_2 --> 0\n x2_3 --> 0\n y3_0 --> x2_0^2\n y3_1 --> x2_0*x2_1\n y3_2 --> x2_1^2\n y3_3 --> x2_0*x2_2\n y3_4 --> x2_1*x2_2 + x2_0*x2_3\n y3_5 --> x2_2^2\n y3_6 --> x2_1*x2_3\n y3_7 --> x2_2*x2_3\n y3_8 --> x2_3^2\n To: Commutative Differential Graded Algebra with generators\n ('e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7')\n in degrees (1, 1, 1, 1, 1, 1, 1) over Rational Field with differential:\n e1 --> e1*e7\n e2 --> e2*e7\n e3 --> -e3*e7\n e4 --> -e4*e7\n e5 --> 0\n e6 --> 0\n e7 --> 0\n Defn: (x1_0, x1_1, x1_2, x2_0, x2_1, x2_2, x2_3,\n y3_0, y3_1, y3_2, y3_3, y3_4, y3_5, y3_6, y3_7, y3_8)\n --> (e5, e6, e7, e1*e3, e2*e3, e1*e4, e2*e4, 0, 0, 0, 0, 0, 0, 0, 0, 0)\n sage: [B.cohomology(i).dimension() for i in [1..3]]\n [3, 7, 13]\n sage: [M.cohomology(i).dimension() for i in [1..3]]\n [3, 7, 13]\n\n ALGORITHM:\n\n We follow the algorithm described in [Man2019]_. It consists in\n constructing the minimal Sullivan algebra ``S`` by iteratively adding\n generators to it. Start with one closed generator of degree 1 for each\n element in the basis of the first cohomology of the algebra. Then\n proceed degree by degree. At each degree `d`, we keep adding generators\n of degree `d-1` whose differential kills the elements in the kernel of\n the map `H^d(S)\\to H^d(self)`. Once this map is made injective, we add\n the needed closed generators in degree `d` to make it surjective.\n\n .. WARNING::\n\n The method is not granted to finish (it can't, since the minimal\n model could be infinitely generated in some degrees).\n The parameter ``max_iterations`` controls how many iterations of\n the method are attempted at each degree. In case they are not\n enough, an exception is raised. If you think that the result will\n be finitely generated, you can try to run it again with a higher\n value for ``max_iterations``.\n\n .. SEEALSO::\n\n :wikipedia:`Rational_homotopy_theory#Sullivan_algebras`\n\n TESTS::\n\n sage: A.<x, y, z, t> = GradedCommutativeAlgebra(QQ,degrees = (1, 2, 3, 3))\n sage: d = A.differential({x:y})\n sage: B = A.cdg_algebra(d)\n sage: B.minimal_model(i=3)\n Commutative Differential Graded Algebra morphism:\n From: Commutative Differential Graded Algebra with generators ('x3_0', 'x3_1') in degrees (3, 3) over Rational Field with differential:\n x3_0 --> 0\n x3_1 --> 0\n To: Commutative Differential Graded Algebra with generators ('x', 'y', 'z', 't') in degrees (1, 2, 3, 3) over Rational Field with differential:\n x --> y\n y --> 0\n z --> 0\n t --> 0\n Defn: (x3_0, x3_1) --> (z, t)\n\n ::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ)\n sage: I = A.ideal([a*b-a*c+b*c])\n sage: B = A.quotient(I)\n sage: S = B.cdg_algebra({})\n sage: S.minimal_model()\n Traceback (most recent call last):\n ...\n ValueError: could not cover all relations in max iterations in degree 2\n sage: S.minimal_model(partial_result=True)\n Commutative Differential Graded Algebra morphism:\n From: Commutative Differential Graded Algebra with generators\n ('x1_0', 'x1_1', 'x1_2', 'y1_0', 'y1_1', 'y1_2') in degrees (1, 1, 1, 1, 1, 1)\n over Rational Field with differential:\n x1_0 --> 0\n x1_1 --> 0\n x1_2 --> 0\n y1_0 --> x1_0*x1_1 - x1_0*x1_2 + x1_1*x1_2\n y1_1 --> x1_0*y1_0 - x1_2*y1_0\n y1_2 --> x1_1*y1_0 - x1_2*y1_0\n To: Commutative Differential Graded Algebra with generators ('a', 'b', 'c')\n in degrees (1, 1, 1) with relations [a*b - a*c + b*c] over Rational Field with differential:\n a --> 0\n b --> 0\n c --> 0\n Defn: (x1_0, x1_1, x1_2, y1_0, y1_1, y1_2) --> (a, b, c, 0, 0, 0)\n\n REFERENCES:\n\n - [Fel2001]_\n\n - [Man2019]_\n\n " max_degree = int(i) if (max_degree < 1): raise ValueError('the degree must be a positive integer') if ((max_iterations not in ZZ) or (max_iterations < 1)): raise ValueError('max_iterations must be a positive integer') if (max_degree in self._minimalmodels): return self._minimalmodels[max_degree] from copy import copy def extend(phi, ndegrees, ndifs, nimags, nnames): '\n Extend phi to a new algebra with new generators, labeled by nnames\n ' B = phi.domain() names = [str(g) for g in B.gens()] degrees = [g.degree() for g in B.gens()] A = GradedCommutativeAlgebra(B.base_ring(), names=(names + nnames), degrees=(degrees + ndegrees)) h = B.hom(A.gens()[:B.ngens()], check=False) d = B.differential() diff = {h(g): h(d(g)) for g in B.gens()} cndifs = copy(ndifs) for g in A.gens()[B.ngens():]: diff[g] = h(cndifs.pop(0)) NB = A.cdg_algebra(diff) return NB.hom(([phi(g) for g in B.gens()] + nimags), check=False) def extendx(phi, degree): B = phi.domain() imagesbcohom = [phi(g.representative()) for g in B.cohomology(degree).basis().keys()] CS = self.cohomology_raw(degree) VS = CS.V() CB = B.cohomology_raw(degree) imagesphico = [] for g in imagesbcohom: if g.is_zero(): imagesphico.append(CS.zero()) else: imagesphico.append(CS(VS(g.basis_coefficients()))) phico = CB.hom(imagesphico, codomain=CS) QI = CS.quotient(phico.image()) self._numerical_invariants[degree] = [QI.dimension()] if (QI.dimension() > 0): nnames = [f'x{degree}_{j}' for j in range(QI.dimension())] nbasis = [] bbasis = self.basis(degree) for v in QI.basis(): vl = CS.lift(QI.lift(v)) g = sum(((bbasis[j] * vl[j]) for j in range(len(bbasis)))) nbasis.append(g) nimags = nbasis ndegrees = [degree for _ in nbasis] return extend(phi, ndegrees, [B.zero() for _ in nimags], nimags, nnames) return phi def extendy(phi, degree): nnamesy = 0 for iteration in range(max_iterations): B = phi.domain() imagesbcohom = [phi(g.representative()) for g in B.cohomology(degree).basis().keys()] CS = self.cohomology_raw(degree) VS = CS.V() CB = B.cohomology_raw(degree) imagesphico = [] for g in imagesbcohom: if g.is_zero(): imagesphico.append(CS.zero()) else: imagesphico.append(CS(VS(g.basis_coefficients()))) phico = CB.hom(imagesphico, codomain=CS) K = phico.kernel() self._numerical_invariants[(degree - 1)].append(K.dimension()) if (K.dimension() == 0): return phi if (iteration == (max_iterations - 1)): return (phi,) ndifs = [CB.lift(g) for g in K.basis()] basisdegree = B.basis(degree) ndifs = [sum(((basisdegree[j] * g[j]) for j in range(len(basisdegree)))) for g in ndifs] MS = self.differential().differential_matrix((degree - 1)) nimags = [] for g in ndifs: if phi(g).is_zero(): nimags.append(vector((MS.nrows() * [0]))) else: nimags.append(MS.solve_left(vector(phi(g).basis_coefficients()))) nimags = [sum(((self.basis((degree - 1))[j] * g[j]) for j in range(len(self.basis((degree - 1)))))) for g in nimags] ndegrees = [(degree - 1) for g in nimags] nnames = ['y{}_{}'.format((degree - 1), (j + nnamesy)) for j in range(len(nimags))] nnamesy += len(nimags) phi = extend(phi, ndegrees, ndifs, nimags, nnames) if (not self._minimalmodels): degnzero = 1 while (self.cohomology(degnzero).dimension() == 0): self._numerical_invariants[degnzero] = [0] degnzero += 1 if (degnzero > max_degree): raise ValueError('cohomology is trivial up to max_degree') gens = [g.representative() for g in self.cohomology(degnzero).basis().keys()] self._numerical_invariants[degnzero] = [len(gens)] names = ['x{}_{}'.format(degnzero, j) for j in range(len(gens))] A = GradedCommutativeAlgebra(self.base_ring(), names, degrees=[degnzero for _ in names]) B = A.cdg_algebra(A.differential({})) phi = B.hom(gens) phiext = extendy(phi, (degnzero + 1)) if isinstance(phiext, tuple): if (not partial_result): raise ValueError('could not cover all relations in max iterations in degree {}'.format((degnzero + 1))) return phiext[0] phi = phiext self._minimalmodels[degnzero] = phi else: degnzero = max(self._minimalmodels) phi = self._minimalmodels[degnzero] for degree in range((degnzero + 1), (max_degree + 1)): phi = extendx(phi, degree) phiext = extendy(phi, (degree + 1)) if isinstance(phiext, tuple): if partial_result: return phiext[0] else: raise ValueError('could not cover all relations in max iterations in degree {}'.format((degree + 1))) phi = phiext self._minimalmodels[degree] = phi return phi def cohomology_algebra(self, max_degree=3): "\n Compute a CDGA with trivial differential, that is isomorphic to the cohomology of\n self up to``max_degree``\n\n INPUT:\n\n - ``max_degree`` -- integer (default: `3`); degree to which the result is required to\n be isomorphic to self's cohomology.\n\n EXAMPLES::\n\n sage: A.<e1, e2, e3, e4, e5, e6, e7> = GradedCommutativeAlgebra(QQ)\n sage: d = A.differential({e1:-e1*e6, e2:-e2*e6, e3:-e3*e6, e4:-e5*e6, e5:e4*e6})\n sage: B = A.cdg_algebra(d)\n sage: M = B.cohomology_algebra()\n sage: M\n Commutative Differential Graded Algebra with generators ('x0', 'x1', 'x2')\n in degrees (1, 1, 2) over Rational Field with differential:\n x0 --> 0\n x1 --> 0\n x2 --> 0\n sage: M.cohomology(1)\n Free module generated by {[x0], [x1]} over Rational Field\n sage: B.cohomology(1)\n Free module generated by {[e6], [e7]} over Rational Field\n sage: M.cohomology(2)\n Free module generated by {[x0*x1], [x2]} over Rational Field\n sage: B.cohomology(2)\n Free module generated by {[e4*e5], [e6*e7]} over Rational Field\n sage: M.cohomology(3)\n Free module generated by {[x0*x2], [x1*x2]} over Rational Field\n sage: B.cohomology(3)\n Free module generated by {[e4*e5*e6], [e4*e5*e7]} over Rational Field\n " cohomgens = self.cohomology_generators(max_degree) if (not cohomgens): raise ValueError('cohomology ring has no generators') chgens = [] degrees = [] for d in cohomgens: for g in cohomgens[d]: degrees.append(d) chgens.append(g) A = GradedCommutativeAlgebra(self.base_ring(), [f'x{i}' for i in range(len(chgens))], degrees) rels = [] for d in range(1, (max_degree + 1)): B1 = A.basis(d) V2 = self.cohomology_raw(d) images = [] for g in B1: ig = g._im_gens_(self, chgens) if ig.is_zero(): images.append(V2.zero()) else: images.append(V2(V2.V()(ig.basis_coefficients()))) V1 = (self.base_ring() ** len(B1)) h = V1.hom(images, codomain=V2) K = h.kernel() for g in K.basis(): newrel = sum(((g[i] * B1[i]) for i in range(len(B1)))) rels.append(newrel) return A.quotient(A.ideal(rels)).cdg_algebra({}) def numerical_invariants(self, max_degree=3, max_iterations=3): "\n Return the numerical invariants of the algebra, up to degree ``d``. The\n numerical invariants reflect the number of generators added at each step\n of the construction of the minimal model.\n\n The numerical invariants are the dimensions of the subsequent Hirsch\n extensions used at each degree to compute the minimal model.\n\n INPUT:\n\n - ``max_degree`` -- integer (default: `3`); the degree up to which the\n numerical invariants are computed\n\n - ``max_iterations`` -- integer (default: `3`); the maximum number of iterations\n used to compute the minimal model, if it is not already cached\n\n EXAMPLES::\n\n sage: A.<e1, e2, e3> = GradedCommutativeAlgebra(QQ)\n sage: B = A.cdg_algebra({e3 : e1*e2})\n sage: B.minimal_model(4)\n Commutative Differential Graded Algebra morphism:\n From: Commutative Differential Graded Algebra with\n generators ('x1_0', 'x1_1', 'y1_0') in degrees (1, 1, 1)\n over Rational Field with differential:\n x1_0 --> 0\n x1_1 --> 0\n y1_0 --> x1_0*x1_1\n To: Commutative Differential Graded Algebra with\n generators ('e1', 'e2', 'e3') in degrees (1, 1, 1)\n over Rational Field with differential:\n e1 --> 0\n e2 --> 0\n e3 --> e1*e2\n Defn: (x1_0, x1_1, y1_0) --> (e1, e2, e3)\n sage: B.numerical_invariants(2)\n {1: [2, 1, 0], 2: [0, 0]}\n\n ALGORITHM:\n\n The numerical invariants are stored as the minimal model is constructed.\n\n .. WARNING::\n\n The method is not granted to finish (it can't, since the minimal\n model could be infinitely generated in some degrees).\n The parameter ``max_iterations`` controls how many iterations of\n the method are attempted at each degree. In case they are not\n enough, an exception is raised. If you think that the result will\n be finitely generated, you can try to run it again with a higher\n value for ``max_iterations``.\n\n REFERENCES:\n\n For a precise definition and properties, see [Man2019]_ .\n\n " self.minimal_model(max_degree, max_iterations) return {i: self._numerical_invariants[i] for i in range(1, (max_degree + 1))} def is_formal(self, i, max_iterations=3): "\n Check if the algebra is ``i``-formal. That is, if it is ``i``-quasi-isomorphic\n to its cohomology algebra.\n\n INPUT:\n\n - ``i`` -- integer; the degree up to which the formality is checked\n\n - ``max_iterations`` -- integer (default: `3`); the maximum number of\n iterations used in the computation of the minimal model\n\n .. WARNING::\n\n The method is not granted to finish (it can't, since the minimal\n model could be infinitely generated in some degrees).\n The parameter ``max_iterations`` controls how many iterations of\n the method are attempted at each degree. In case they are not\n enough, an exception is raised. If you think that the result will\n be finitely generated, you can try to run it again with a higher\n value for ``max_iterations``.\n\n Moreover, the method uses criteria that are often enough to conclude\n that the algebra is either formal or non-formal. However, it could\n happen that the used criteria can not determine the formality. In\n that case, an error is raised.\n\n EXAMPLES::\n\n sage: A.<e1, e2, e3, e4, e5> = GradedCommutativeAlgebra(QQ)\n sage: B = A.cdg_algebra({e5: e1*e2 + e3*e4})\n sage: B.is_formal(1)\n True\n sage: B.is_formal(2)\n False\n\n ALGORITHM:\n\n Apply the criteria in [Man2019]_ . Both the `i`-minimal model of the\n algebra and its cohomology algebra are computed. If the numerical\n invariants are different, the algebra is not `i`-formal.\n\n If the numerical invariants match, the `\\psi` condition is checked.\n " phi = self.minimal_model(i, max_iterations) M = phi.domain() H = M.cohomology_algebra((i + 1)) try: H.minimal_model(i, max_iterations) except ValueError: return False N1 = self.numerical_invariants(i, max_iterations) N2 = H.numerical_invariants(i, max_iterations) if any(((N1[n] != N2[n]) for n in range(1, (i + 1)))): return False subsdict = {y.lift(): 0 for y in M.gens() if (not y.differential().is_zero())} tocheck = [M(g.differential().lift().subs(subsdict)) for g in M.gens()] if all((c.is_coboundary() for c in tocheck)): return True raise NotImplementedError('the implemented criteria cannot determine formality') class Element(GCAlgebra.Element): def differential(self): '\n The differential on this element.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(2, 2, 3, 4))\n sage: B = A.cdg_algebra({t: x*z, x: z, y: z})\n sage: B.inject_variables()\n Defining x, y, z, t\n sage: x.differential()\n z\n sage: (-1/2 * x^2 + t).differential()\n 0\n ' return self.parent().differential()(self) def is_coboundary(self): '\n Return ``True`` if ``self`` is a coboundary and ``False``\n otherwise.\n\n This raises an error if the element is not homogeneous.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1,2,2))\n sage: B = A.cdg_algebra(differential={b: a*c})\n sage: x,y,z = B.gens()\n sage: x.is_coboundary()\n False\n sage: (x*z).is_coboundary()\n True\n sage: (x*z + x*y).is_coboundary()\n False\n sage: (x*z + y**2).is_coboundary()\n Traceback (most recent call last):\n ...\n ValueError: this element is not homogeneous\n ' if (not self.is_homogeneous()): raise ValueError('this element is not homogeneous') if self.is_zero(): return True v = vector(self.basis_coefficients()) return (v in self.parent().coboundaries(self.degree())) def is_cohomologous_to(self, other): '\n Return ``True`` if ``self`` is cohomologous to ``other``\n and ``False`` otherwise.\n\n INPUT:\n\n - ``other`` -- another element of this algebra\n\n EXAMPLES::\n\n sage: A.<a,b,c,d> = GradedCommutativeAlgebra(QQ, degrees=(1,1,1,1))\n sage: B = A.cdg_algebra(differential={a: b*c-c*d})\n sage: w, x, y, z = B.gens()\n sage: (x*y).is_cohomologous_to(y*z)\n True\n sage: (x*y).is_cohomologous_to(x*z)\n False\n sage: (x*y).is_cohomologous_to(x*y)\n True\n\n Two elements whose difference is not homogeneous are\n cohomologous if and only if they are both coboundaries::\n\n sage: w.is_cohomologous_to(y*z)\n False\n sage: (x*y-y*z).is_cohomologous_to(x*y*z)\n True\n sage: (x*y*z).is_cohomologous_to(0) # make sure 0 works\n True\n ' if other.is_zero(): return self.is_coboundary() if ((not isinstance(other, DifferentialGCAlgebra.Element)) or (self.parent() is not other.parent())): raise ValueError(f'the element {other} does not lie in this DGA') if (self - other).is_homogeneous(): return (self - other).is_coboundary() return (self.is_coboundary() and other.is_coboundary()) def cohomology_class(self): '\n Return the cohomology class of a homogeneous cycle, as an element\n of the corresponding cohomology group.\n\n EXAMPLES::\n\n sage: A.<e1,e2,e3,e4,e5> = GradedCommutativeAlgebra(QQ)\n sage: B = A.cdg_algebra({e5: e1*e2+e3*e4})\n sage: B.inject_variables()\n Defining e1, e2, e3, e4, e5\n sage: a = e1*e3*e5 - 3*e2*e3*e5\n sage: a.cohomology_class()\n B[[e1*e3*e5]] - 3*B[[e2*e3*e5]]\n\n TESTS::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1, 2, 3))\n sage: B = A.cdg_algebra({a: b})\n sage: B.inject_variables()\n Defining a, b, c\n sage: b.cohomology_class()\n 0\n sage: b.cohomology_class().parent()\n Free module generated by {} over Rational Field\n\n Check that the issue detected in :trac:`28155` is solved::\n\n sage: A.<e1,e2,e3,e4,e5> = GradedCommutativeAlgebra(QQ)\n sage: B = A.cdg_algebra({e5: e1*e2+e3*e4})\n sage: B.inject_variables()\n Defining e1, e2, e3, e4, e5\n sage: a = e1*e3*e5 - 3*e2*e3*e5\n sage: ca = a.cohomology_class()\n sage: C = B.cohomology(3)\n sage: ca in C\n True\n ' if (not self.is_homogeneous()): raise ValueError('the element is not homogeneous') if (not self.differential().is_zero()): raise ValueError('the element is not closed') d = self.degree() C = self.parent().cohomology(d) CR = self.parent().cohomology_raw(d) V = CR.V() cohomcoefs = CR(V(self.basis_coefficients())) return C.sum(((a * b) for (a, b) in zip(cohomcoefs, C.basis().values()))) def _cohomology_class_dict(self): '\n Return the dictionary that represents the cohomology class of\n the cycle expressed in terms of the cohomology generators.\n\n This can be used to map the cycle to the cohomology algebra.\n\n EXAMPLES::\n\n sage: A.<e1,e2,e3,e4,e5> = GradedCommutativeAlgebra(QQ)\n sage: B = A.cdg_algebra({e5: e1*e2+e3*e4})\n sage: a = B(e1*e3*e5-3*e2*e3*e5)\n sage: a._cohomology_class_dict()\n {(0, 0, 0, 0, 0, 0, 1, 0, 0): -3, (0, 0, 0, 0, 0, 1, 0, 0, 0): 1}\n sage: H = B.cohomology_algebra(3)\n sage: H(a._cohomology_class_dict())\n x5 - 3*x6\n sage: B.cohomology_generators(3)\n {1: [e1, e2, e3, e4],\n 3: [e1*e2*e5 - e3*e4*e5, e1*e3*e5, e2*e3*e5, e1*e4*e5, e2*e4*e5]}\n sage: [H(g._cohomology_class_dict()) for g in flatten(B.cohomology_generators(3).values())]\n [x0, x1, x2, x3, x4, x5, x6, x7, x8]\n ' from sage.misc.flatten import flatten if (not self.differential().is_zero()): raise ValueError('the element is not closed') if (not self.is_homogeneous()): res = {} for d in self.homogeneous_parts().values(): res.update(d._cohomology_class_dict()) return res d = self.degree() gens = flatten(self.parent().cohomology_generators(d).values()) ebasis = exterior_algebra_basis(d, tuple((g.degree() for g in gens))) gensd = [prod([(gens[i] ** b[i]) for i in range(len(b))]) for b in ebasis] m = matrix([g.cohomology_class()._vector_() for g in gensd]) coeffs = m.solve_left(self.cohomology_class()._vector_()) return {tuple(ebasis[i]): coeffs[i] for i in range(len(ebasis)) if coeffs[i]}
class DifferentialGCAlgebra_multigraded(DifferentialGCAlgebra, GCAlgebra_multigraded): '\n A commutative differential multi-graded algebras.\n\n INPUT:\n\n - ``A`` -- a commutative multi-graded algebra\n\n - ``differential`` -- a differential\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))\n sage: B = A.cdg_algebra(differential={a: c})\n sage: B.basis((1,0))\n [a]\n sage: B.basis(1, total=True)\n [a, b]\n sage: B.cohomology((1, 0))\n Free module generated by {} over Rational Field\n sage: B.cohomology(1, total=True)\n Free module generated by {[b]} over Rational Field\n ' def __init__(self, A, differential): '\n Initialize ``self``.\n\n INPUT:\n\n - ``A`` -- a multi-graded commutative algebra\n - ``differential`` -- a differential\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))\n sage: B = A.cdg_algebra(differential={a: c})\n\n Trying to define a differential which is not multi-graded::\n\n sage: A.<t,x,y,z> = GradedCommutativeAlgebra(QQ, degrees=((1,0),(1,0),(2,0),(0,2)))\n sage: B = A.cdg_algebra(differential={x:y}) # good\n sage: B = A.cdg_algebra(differential={t:z}) # good\n sage: B = A.cdg_algebra(differential={x:y, t:z}) # bad\n Traceback (most recent call last):\n ...\n ValueError: the differential does not have a well-defined degree\n ' cat = (Algebras(A.base()).Graded() & ChainComplexes(A.base())) GCAlgebra_multigraded.__init__(self, A.base(), names=A._names, degrees=A._degrees_multi, R=A.cover_ring(), I=A.defining_ideal(), category=cat) self._differential = Differential_multigraded(self, differential._dic_) def _base_repr(self): '\n Return the base string representation of ``self``.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))\n sage: A.cdg_algebra(differential={a: c})._base_repr()\n "Commutative Differential Graded Algebra with generators (\'a\', \'b\', \'c\') in degrees ((1, 0), (0, 1), (0, 2)) over Rational Field"\n ' s = DifferentialGCAlgebra._base_repr(self) old = '{}'.format(self._degrees) new = '{}'.format(self._degrees_multi) return s.replace(old, new) def coboundaries(self, n, total=False): '\n The ``n``-th coboundary group of the algebra.\n\n This is a vector space over the base field `F`, and it is\n returned as a subspace of the vector space `F^d`, where the\n ``n``-th homogeneous component has dimension `d`.\n\n INPUT:\n\n - ``n`` -- degree\n - ``total`` (default ``False``) -- if ``True``, return the\n coboundaries in total degree ``n``\n\n If ``n`` is an integer rather than a multi-index, then the\n total degree is used in that case as well.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))\n sage: B = A.cdg_algebra(differential={a: c})\n sage: B.coboundaries((0,2))\n Vector space of degree 1 and dimension 1 over Rational Field\n Basis matrix:\n [1]\n sage: B.coboundaries(2)\n Vector space of degree 2 and dimension 1 over Rational Field\n Basis matrix:\n [0 1]\n ' return self._differential.coboundaries(n, total) def cocycles(self, n, total=False): '\n The ``n``-th cocycle group of the algebra.\n\n This is a vector space over the base field `F`, and it is\n returned as a subspace of the vector space `F^d`, where the\n ``n``-th homogeneous component has dimension `d`.\n\n INPUT:\n\n - ``n`` -- degree\n - ``total`` -- (default: ``False``) if ``True``, return the\n cocycles in total degree ``n``\n\n If ``n`` is an integer rather than a multi-index, then the\n total degree is used in that case as well.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))\n sage: B = A.cdg_algebra(differential={a: c})\n sage: B.cocycles((0,1))\n Vector space of degree 1 and dimension 1 over Rational Field\n Basis matrix:\n [1]\n sage: B.cocycles((0,1), total=True)\n Vector space of degree 2 and dimension 1 over Rational Field\n Basis matrix:\n [0 1]\n ' return self._differential.cocycles(n, total) def cohomology_raw(self, n, total=False): '\n The ``n``-th cohomology group of the algebra.\n\n This is a vector space over the base ring, and it is returned\n as the quotient cocycles/coboundaries.\n\n Compare to :meth:`cohomology`.\n\n INPUT:\n\n - ``n`` -- degree\n - ``total`` -- (default: ``False``) if ``True``, return the\n cohomology in total degree ``n``\n\n If ``n`` is an integer rather than a multi-index, then the\n total degree is used in that case as well.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))\n sage: B = A.cdg_algebra(differential={a: c})\n sage: B.cohomology_raw((0,2))\n Vector space quotient V/W of dimension 0 over Rational Field where\n V: Vector space of degree 1 and dimension 1 over Rational Field\n Basis matrix:\n [1]\n W: Vector space of degree 1 and dimension 1 over Rational Field\n Basis matrix:\n [1]\n\n sage: B.cohomology_raw(1)\n Vector space quotient V/W of dimension 1 over Rational Field where\n V: Vector space of degree 2 and dimension 1 over Rational Field\n Basis matrix:\n [0 1]\n W: Vector space of degree 2 and dimension 0 over Rational Field\n Basis matrix:\n []\n ' return self._differential.cohomology_raw(n, total) def cohomology(self, n, total=False): '\n The ``n``-th cohomology group of the algebra.\n\n This is a vector space over the base ring, defined as the\n quotient cocycles/coboundaries. The elements of the quotient\n are lifted to the vector space of cocycles, and this is\n described in terms of those lifts.\n\n Compare to :meth:`cohomology_raw`.\n\n INPUT:\n\n - ``n`` -- degree\n - ``total`` -- (default: ``False``) if ``True``, return the\n cohomology in total degree ``n``\n\n If ``n`` is an integer rather than a multi-index, then the\n total degree is used in that case as well.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0, 1), (0,2)))\n sage: B = A.cdg_algebra(differential={a: c})\n sage: B.cohomology((0,2))\n Free module generated by {} over Rational Field\n\n sage: B.cohomology(1)\n Free module generated by {[b]} over Rational Field\n ' return self._differential.cohomology(n, total) homology = cohomology class Element(GCAlgebra_multigraded.Element, DifferentialGCAlgebra.Element): '\n Element class of a commutative differential multi-graded algebra.\n '
def GradedCommutativeAlgebra(ring, names=None, degrees=None, max_degree=None, **kwargs): '\n A graded commutative algebra.\n\n INPUT:\n\n There are two ways to call this. The first way defines a free\n graded commutative algebra:\n\n - ``ring`` -- the base field over which to work\n\n - ``names`` -- names of the generators. You may also use Sage\'s\n ``A.<x,y,...> = ...`` syntax to define the names. If no names\n are specified, the generators are named ``x0``, ``x1``, ...\n\n - ``degrees`` -- degrees of the generators; if this is omitted,\n the degree of each generator is 1, and if both ``names`` and\n ``degrees`` are omitted, an error is raised\n\n - ``max_degree`` -- the maximal degree of the graded algebra. If omitted,\n no maximal degree is assumed and an instance of :class:`GCAlgebra` is\n returned. Otherwise, an instance of\n :class:`sage.algebras.commutative_graded_algebra.GradedCommutativeAlgebraWithMaxDeg`\n is created.\n\n Once such an algebra has been defined, one can use its associated\n methods to take a quotient, impose a differential, etc. See the\n examples below.\n\n The second way takes a graded commutative algebra and imposes\n relations:\n\n - ``ring`` -- a graded commutative algebra\n\n - ``relations`` -- a list or tuple of elements of ``ring``\n\n EXAMPLES:\n\n Defining a graded commutative algebra::\n\n sage: GradedCommutativeAlgebra(QQ, \'x, y, z\')\n Graded Commutative Algebra with generators (\'x\', \'y\', \'z\')\n in degrees (1, 1, 1) over Rational Field\n sage: GradedCommutativeAlgebra(QQ, degrees=(2, 3, 4))\n Graded Commutative Algebra with generators (\'x0\', \'x1\', \'x2\')\n in degrees (2, 3, 4) over Rational Field\n\n As usual in Sage, the ``A.<...>`` notation defines both the\n algebra and the generator names::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1, 1, 2))\n sage: x^2\n 0\n sage: y*x # Odd classes anticommute.\n -x*y\n sage: z*y # z is central since it is in degree 2.\n y*z\n sage: (x*y*z**3).degree()\n 8\n sage: A.basis(3) # basis of homogeneous degree 3 elements\n [x*z, y*z]\n\n Defining a quotient::\n\n sage: I = A.ideal(x*z)\n sage: AQ = A.quotient(I); AQ\n Graded Commutative Algebra with generators (\'x\', \'y\', \'z\')\n in degrees (1, 1, 2) with relations [x*z] over Rational Field\n sage: AQ.basis(3)\n [y*z]\n\n Note that ``AQ`` has no specified differential. This is reflected in\n its print representation: ``AQ`` is described as a "graded commutative\n algebra" -- the word "differential" is missing. Also, it has no\n default ``differential``::\n\n sage: AQ.differential()\n Traceback (most recent call last):\n ...\n TypeError: ...differential() missing 1 required positional argument:\n \'diff\'\n\n Now we add a differential to ``AQ``::\n\n sage: B = AQ.cdg_algebra({z: y*z}); B\n Commutative Differential Graded Algebra with generators (\'x\', \'y\', \'z\')\n in degrees (1, 1, 2) with relations [x*z] over Rational Field with differential:\n x --> 0\n y --> 0\n z --> y*z\n sage: B.differential()\n Differential of Commutative Differential Graded Algebra with generators\n (\'x\', \'y\', \'z\') in degrees (1, 1, 2) with relations [x*z] over Rational Field\n Defn: x --> 0\n y --> 0\n z --> y*z\n sage: B.cohomology(1)\n Free module generated by {[x], [y]} over Rational Field\n sage: B.cohomology(2)\n Free module generated by {[x*y]} over Rational Field\n\n We compute algebra generators for cohomology in a range of\n degrees. This cohomology algebra appears to be finitely\n generated::\n\n sage: B.cohomology_generators(15)\n {1: [x, y]}\n\n We can construct multi-graded rings as well. We work in characteristic 2\n for a change, so the algebras here are honestly commutative::\n\n sage: C.<a,b,c,d> = GradedCommutativeAlgebra(GF(2),\n ....: degrees=((1,0), (1,1), (0,2), (0,3)))\n sage: D = C.cdg_algebra(differential={a: c, b: d}); D\n Commutative Differential Graded Algebra with generators (\'a\', \'b\', \'c\', \'d\')\n in degrees ((1, 0), (1, 1), (0, 2), (0, 3)) over Finite Field of size 2\n with differential:\n a --> c\n b --> d\n c --> 0\n d --> 0\n\n We can examine ``D`` using both total degrees and multidegrees.\n Use tuples, lists, vectors, or elements of additive\n abelian groups to specify degrees::\n\n sage: D.basis(3) # basis in total degree 3\n [a^3, a*b, a*c, d]\n sage: D.basis((1,2)) # basis in degree (1,2)\n [a*c]\n sage: D.basis([1,2])\n [a*c]\n sage: D.basis(vector([1,2]))\n [a*c]\n sage: G = AdditiveAbelianGroup([0,0]); G\n Additive abelian group isomorphic to Z + Z\n sage: D.basis(G(vector([1,2])))\n [a*c]\n\n At this point, ``a``, for example, is an element of ``C``. We can\n redefine it so that it is instead an element of ``D`` in several\n ways, for instance using :meth:`gens` method::\n\n sage: a, b, c, d = D.gens()\n sage: a.differential()\n c\n\n Or the :meth:`inject_variables` method::\n\n sage: D.inject_variables()\n Defining a, b, c, d\n sage: (a*b).differential()\n b*c + a*d\n sage: (a*b*c**2).degree()\n (2, 5)\n\n Degrees are returned as elements of additive abelian groups::\n\n sage: (a*b*c**2).degree() in G\n True\n\n sage: (a*b*c**2).degree(total=True) # total degree\n 7\n sage: D.cohomology(4)\n Free module generated by {[a^4], [b^2]} over Finite Field of size 2\n sage: D.cohomology((2,2))\n Free module generated by {[b^2]} over Finite Field of size 2\n\n Graded algebra with maximal degree::\n\n sage: A.<p,e> = GradedCommutativeAlgebra(QQ, degrees=(4,2), max_degree=6); A\n Graded commutative algebra with generators (\'p\', \'e\') in degrees (4, 2)\n with maximal degree 6\n sage: p^2\n 0\n\n TESTS:\n\n We need to specify either name or degrees::\n\n sage: GradedCommutativeAlgebra(QQ)\n Traceback (most recent call last):\n ...\n ValueError: you must specify names or degrees\n ' if max_degree: from .finite_gca import FiniteGCAlgebra return FiniteGCAlgebra(ring, names=names, degrees=degrees, max_degree=max_degree, **kwargs) multi = False if degrees: try: for d in degrees: list(d) multi = True except TypeError: pass if multi: return GCAlgebra_multigraded(ring, names=names, degrees=degrees) return GCAlgebra(ring, names=names, degrees=degrees)
class GCAlgebraMorphism(RingHomomorphism_im_gens): "\n Create a morphism between two :class:`graded commutative algebras <GCAlgebra>`.\n\n INPUT:\n\n - ``parent`` -- the parent homset\n\n - ``im_gens`` -- the images, in the codomain, of the generators of\n the domain\n\n - ``check`` -- boolean (default: ``True``); check whether the\n proposed map is actually an algebra map; if the domain and\n codomain have differentials, also check that the map respects\n those.\n\n EXAMPLES::\n\n sage: A.<x,y> = GradedCommutativeAlgebra(QQ)\n sage: H = Hom(A,A)\n sage: f = H([y,x])\n sage: f\n Graded Commutative Algebra endomorphism of Graded Commutative Algebra\n with generators ('x', 'y') in degrees (1, 1) over Rational Field\n Defn: (x, y) --> (y, x)\n sage: f(x*y)\n -x*y\n " def __init__(self, parent, im_gens, check=True): '\n TESTS:\n\n The entries in ``im_gens`` must lie in the codomain::\n\n sage: A.<x,y> = GradedCommutativeAlgebra(QQ, degrees=(1,2))\n sage: B.<a,b> = GradedCommutativeAlgebra(QQ, degrees=(1,2))\n sage: H = Hom(A,A)\n sage: H([x,b])\n Traceback (most recent call last):\n ...\n ValueError: not all elements of im_gens are in the codomain\n\n Note that morphisms do not need to respect the grading;\n whether they do can be tested with the method\n :meth:`is_graded`::\n\n sage: A.<x,y> = GradedCommutativeAlgebra(QQ, degrees=(1,2))\n sage: H = Hom(A,A)\n sage: f = H([x,x])\n sage: f\n Graded Commutative Algebra endomorphism of Graded Commutative Algebra\n with generators (\'x\', \'y\') in degrees (1, 2) over Rational Field\n Defn: (x, y) --> (x, x)\n sage: f.is_graded()\n False\n sage: TestSuite(f).run(skip="_test_category")\n\n Since `x^2=0` but `y^2 \\neq 0`, the following does not define a valid morphism::\n\n sage: H([y,y])\n Traceback (most recent call last):\n ...\n ValueError: the proposed morphism does not respect the relations\n\n This is okay in characteristic two since then `x^2 \\neq 0`::\n\n sage: A2.<x,y> = GradedCommutativeAlgebra(GF(2), degrees=(1,2))\n sage: H2 = Hom(A2,A2)\n sage: H2([y,y])\n Graded Commutative Algebra endomorphism of Graded Commutative Algebra\n with generators (\'x\', \'y\') in degrees (1, 2) over Finite Field of size 2\n Defn: (x, y) --> (y, y)\n\n The "nc-relations" `a*b = -b*a`, for `a` and `b` in odd\n degree, are checked first, and we can see this when using more\n generators::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2))\n sage: Hom(A,A)([x,z,z])\n Traceback (most recent call last):\n ...\n ValueError: the proposed morphism does not respect the nc-relations\n\n Other relations::\n\n sage: B.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,1))\n sage: D = B.quotient(B.ideal(x*y))\n sage: H = Hom(D,D)\n sage: D.inject_variables()\n Defining x, y, z\n sage: H([x,z,z])\n Traceback (most recent call last):\n ...\n ValueError: the proposed morphism does not respect the relations\n\n The morphisms must respect the differentials, when present::\n\n sage: B.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,1))\n sage: C = B.cdg_algebra({z: x*y})\n sage: C.inject_variables()\n Defining x, y, z\n sage: H = Hom(C,C)\n sage: H([x,z,z])\n Traceback (most recent call last):\n ...\n ValueError: the proposed morphism does not respect the differentials\n\n In the case of only one generator, the cover ring is a polynomial ring,\n hence the noncommutativity relations should not be checked::\n\n sage: A.<e1> = GradedCommutativeAlgebra(QQ)\n sage: A.cover_ring()\n Multivariate Polynomial Ring in e1 over Rational Field\n sage: A.hom([2*e1])\n Graded Commutative Algebra endomorphism of Graded Commutative Algebra\n with generators (\'e1\',) in degrees (1,) over Rational Field\n Defn: (e1,) --> (2*e1,)\n\n ' domain = parent.domain() codomain = parent.codomain() RingHomomorphism_im_gens.__init__(self, parent=parent, im_gens=im_gens, check=False) self._im_gens = tuple(im_gens) if check: if any(((x not in codomain) for x in im_gens)): raise ValueError('not all elements of im_gens are in the codomain') R = domain.cover_ring() from_R = dict(zip(R.gens(), im_gens)) if hasattr(R, 'free_algebra'): from_free = dict(zip(R.free_algebra().gens(), im_gens)) for left in R.relations(): zero = (left.subs(from_free) - R.relations()[left].subs(from_R)) if zero: raise ValueError('the proposed morphism does not respect the nc-relations') for g in domain.defining_ideal().gens(): zero = g.subs(from_R) if zero: raise ValueError('the proposed morphism does not respect the relations') if (isinstance(domain, DifferentialGCAlgebra) and isinstance(codomain, DifferentialGCAlgebra)): dom_diff = domain.differential() cod_diff = codomain.differential() if any(((cod_diff(self(g)) != self(dom_diff(g))) for g in domain.gens())): raise ValueError('the proposed morphism does not respect the differentials') def _call_(self, x): '\n Evaluate this morphism on ``x``.\n\n INPUT:\n\n - ``x`` -- an element of the domain\n\n EXAMPLES::\n\n sage: A.<x,y> = GradedCommutativeAlgebra(GF(2))\n sage: H = Hom(A,A)\n sage: g = H([y,y])\n sage: g(x)\n y\n sage: g(x*y)\n y^2\n\n sage: B.<x,y,z> = GradedCommutativeAlgebra(QQ)\n sage: H = Hom(B,B)\n sage: f = H([y,x,x])\n sage: f(x)\n y\n sage: f(3*x*y)\n -3*x*y\n sage: f(y*z)\n 0\n sage: f(1)\n 1\n ' codomain = self.codomain() result = codomain.zero() for (mono, coeff) in x.dict().items(): term = prod([(gen ** y) for (y, gen) in zip(mono, self.im_gens())], codomain.one()) result += (coeff * term) return result def is_graded(self, total=False): '\n Return ``True`` if this morphism is graded.\n\n That is, return ``True`` if `f(x)` is zero, or if `f(x)` is\n homogeneous and has the same degree as `x`, for each generator\n `x`.\n\n INPUT:\n\n - ``total`` (optional, default ``False``) -- if ``True``, use\n the total degree to determine whether the morphism is graded\n (relevant only in the multigraded case)\n\n EXAMPLES::\n\n sage: C.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1,1,2))\n sage: H = Hom(C,C)\n sage: H([a, b, a*b + 2*a]).is_graded()\n False\n sage: H([a, b, a*b]).is_graded()\n True\n\n sage: A.<w,x> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (1,0)))\n sage: B.<y,z> = GradedCommutativeAlgebra(QQ, degrees=((1,0), (0,1)))\n sage: H = Hom(A,B)\n sage: H([y,0]).is_graded()\n True\n sage: H([z,z]).is_graded()\n False\n sage: H([z,z]).is_graded(total=True)\n True\n ' return all((((not y) or (y.is_homogeneous() and (x.degree(total=total) == y.degree(total=total)))) for (x, y) in zip(self.domain().gens(), self.im_gens()))) def _repr_type(self): "\n EXAMPLES::\n\n sage: B.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1,1))\n sage: C = B.cdg_algebra({z: x*y})\n sage: Hom(B,B)([z,y,x])._repr_type()\n 'Graded Commutative Algebra'\n sage: C.inject_variables()\n Defining x, y, z\n sage: Hom(C,C)([x,0,0])._repr_type()\n 'Commutative Differential Graded Algebra'\n " if (isinstance(self.domain(), DifferentialGCAlgebra) and isinstance(self.codomain(), DifferentialGCAlgebra)): return 'Commutative Differential Graded Algebra' return 'Graded Commutative Algebra' def _repr_defn(self): "\n EXAMPLES::\n\n sage: A.<x,y> = GradedCommutativeAlgebra(QQ)\n sage: Hom(A,A)([y,x])._repr_defn()\n '(x, y) --> (y, x)'\n " gens = self.domain().gens() return '{} --> {}'.format(gens, self._im_gens)
class GCAlgebraHomset(RingHomset_generic): "\n Set of morphisms between two graded commutative algebras.\n\n .. NOTE::\n\n Homsets (and thus morphisms) have only been implemented when\n the base fields are the same for the domain and codomain.\n\n EXAMPLES::\n\n sage: A.<x,y> = GradedCommutativeAlgebra(QQ, degrees=(1,2))\n sage: H = Hom(A,A)\n sage: H([x,y]) == H.identity()\n True\n sage: H([x,x]) == H.identity()\n False\n\n sage: A.<w,x> = GradedCommutativeAlgebra(QQ, degrees=(1,2))\n sage: B.<y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1))\n sage: H = Hom(A,B)\n sage: H([y,0])\n Graded Commutative Algebra morphism:\n From: Graded Commutative Algebra with generators ('w', 'x')\n in degrees (1, 2) over Rational Field\n To: Graded Commutative Algebra with generators ('y', 'z')\n in degrees (1, 1) over Rational Field\n Defn: (w, x) --> (y, 0)\n sage: H([y,y*z])\n Graded Commutative Algebra morphism:\n From: Graded Commutative Algebra with generators ('w', 'x')\n in degrees (1, 2) over Rational Field\n To: Graded Commutative Algebra with generators ('y', 'z')\n in degrees (1, 1) over Rational Field\n Defn: (w, x) --> (y, y*z)\n " @cached_method def zero(self): '\n Construct the "zero" morphism of this homset: the map sending each\n generator to zero.\n\n EXAMPLES::\n\n sage: A.<x,y> = GradedCommutativeAlgebra(QQ, degrees=(1,2))\n sage: B.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(1,1,1))\n sage: zero = Hom(A,B).zero()\n sage: zero(x) == zero(y) == 0\n True\n ' return GCAlgebraMorphism(self, ([self.codomain().zero()] * self.domain().ngens())) @cached_method def identity(self): '\n Construct the identity morphism of this homset.\n\n EXAMPLES::\n\n sage: A.<x,y> = GradedCommutativeAlgebra(QQ, degrees=(1,2))\n sage: H = Hom(A,A)\n sage: H([x,y]) == H.identity()\n True\n sage: H([x,x]) == H.identity()\n False\n ' if (self.domain() != self.codomain()): raise TypeError('identity map is only defined for endomorphism sets') return GCAlgebraMorphism(self, self.domain().gens()) def __call__(self, im_gens, check=True): "\n Create a homomorphism.\n\n INPUT:\n\n - ``im_gens`` -- the images of the generators of the domain\n\n EXAMPLES::\n\n sage: A.<w,x> = GradedCommutativeAlgebra(QQ, degrees=(1,2))\n sage: B.<y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,1))\n sage: H = Hom(A,B)\n sage: H([y,0])\n Graded Commutative Algebra morphism:\n From: Graded Commutative Algebra with generators ('w', 'x') in degrees (1, 2) over Rational Field\n To: Graded Commutative Algebra with generators ('y', 'z') in degrees (1, 1) over Rational Field\n Defn: (w, x) --> (y, 0)\n sage: H([y,y*z])\n Graded Commutative Algebra morphism:\n From: Graded Commutative Algebra with generators ('w', 'x') in degrees (1, 2) over Rational Field\n To: Graded Commutative Algebra with generators ('y', 'z') in degrees (1, 1) over Rational Field\n Defn: (w, x) --> (y, y*z)\n " from sage.categories.map import Map if isinstance(im_gens, Map): return self._coerce_impl(im_gens) return GCAlgebraMorphism(self, im_gens, check=check)
class CohomologyClass(SageObject, CachedRepresentation): "\n A class for representing cohomology classes.\n\n This just has ``_repr_`` and ``_latex_`` methods which put\n brackets around the object's name.\n\n EXAMPLES::\n\n sage: from sage.algebras.commutative_dga import CohomologyClass\n sage: CohomologyClass(3)\n [3]\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(2,2,3,3))\n sage: CohomologyClass(x^2 + 2*y*z, A)\n [2*y*z + x^2]\n\n TESTS:\n\n In order for the cache to not confuse objects with the same representation,\n we can pass the parent of the representative as a parameter::\n\n sage: A.<e1,e2,e3,e4,e5,e6> = GradedCommutativeAlgebra(QQ)\n sage: B1 = A.cdg_algebra({e5:e1*e2,e6:e3*e4})\n sage: B2 = A.cdg_algebra({e5:e1*e2,e6:e1*e2+e3*e4})\n sage: B1.minimal_model()\n Commutative Differential Graded Algebra morphism:\n From: Commutative Differential Graded Algebra with generators ('x1_0', 'x1_1', 'x1_2', 'x1_3', 'y1_0', 'y1_1') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential:\n x1_0 --> 0\n x1_1 --> 0\n x1_2 --> 0\n x1_3 --> 0\n y1_0 --> x1_0*x1_1\n y1_1 --> x1_2*x1_3\n To: Commutative Differential Graded Algebra with generators ('e1', 'e2', 'e3', 'e4', 'e5', 'e6') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential:\n e1 --> 0\n e2 --> 0\n e3 --> 0\n e4 --> 0\n e5 --> e1*e2\n e6 --> e3*e4\n Defn: (x1_0, x1_1, x1_2, x1_3, y1_0, y1_1) --> (e1, e2, e3, e4, e5, e6)\n sage: B2.minimal_model()\n Commutative Differential Graded Algebra morphism:\n From: Commutative Differential Graded Algebra with generators ('x1_0', 'x1_1', 'x1_2', 'x1_3', 'y1_0', 'y1_1') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential:\n x1_0 --> 0\n x1_1 --> 0\n x1_2 --> 0\n x1_3 --> 0\n y1_0 --> x1_0*x1_1\n y1_1 --> x1_2*x1_3\n To: Commutative Differential Graded Algebra with generators ('e1', 'e2', 'e3', 'e4', 'e5', 'e6') in degrees (1, 1, 1, 1, 1, 1) over Rational Field with differential:\n e1 --> 0\n e2 --> 0\n e3 --> 0\n e4 --> 0\n e5 --> e1*e2\n e6 --> e1*e2 + e3*e4\n Defn: (x1_0, x1_1, x1_2, x1_3, y1_0, y1_1) --> (e1, e2, e3, e4, e5, -e5 + e6)\n\n " def __init__(self, x, cdga=None): '\n EXAMPLES::\n\n sage: from sage.algebras.commutative_dga import CohomologyClass\n sage: CohomologyClass(x - 2) # needs sage.symbolic\n [x - 2]\n ' self._x = x self._cdga = cdga def __hash__(self): '\n TESTS::\n\n sage: from sage.algebras.commutative_dga import CohomologyClass\n sage: hash(CohomologyClass(sin)) == hash(sin) # needs sage.symbolic\n True\n ' return hash(self._x) def _repr_(self): '\n EXAMPLES::\n\n sage: from sage.algebras.commutative_dga import CohomologyClass\n sage: CohomologyClass(sin) # needs sage.symbolic\n [sin]\n ' return '[{}]'.format(self._x) def _latex_(self): '\n EXAMPLES::\n\n sage: from sage.algebras.commutative_dga import CohomologyClass\n sage: latex(CohomologyClass(sin)) # needs sage.symbolic\n \\left[ \\sin \\right]\n sage: latex(CohomologyClass(x^2)) # needs sage.symbolic\n \\left[ x^{2} \\right]\n ' from sage.misc.latex import latex return '\\left[ {} \\right]'.format(latex(self._x)) def representative(self): '\n Return the representative of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.commutative_dga import CohomologyClass\n sage: x = CohomologyClass(sin) # needs sage.symbolic\n sage: x.representative() == sin # needs sage.symbolic\n True\n ' return self._x
@cached_function def exterior_algebra_basis(n, degrees): "\n Basis of an exterior algebra in degree ``n``, where the\n generators are in degrees ``degrees``.\n\n INPUT:\n\n - ``n`` - integer\n - ``degrees`` - iterable of integers\n\n Return list of lists, each list representing exponents for the\n corresponding generators. (So each list consists of 0's and 1's.)\n\n EXAMPLES::\n\n sage: from sage.algebras.commutative_dga import exterior_algebra_basis\n sage: exterior_algebra_basis(1, (1,3,1))\n [[0, 0, 1], [1, 0, 0]]\n sage: exterior_algebra_basis(4, (1,3,1))\n [[0, 1, 1], [1, 1, 0]]\n sage: exterior_algebra_basis(10, (1,5,1,1))\n []\n " if (n == 0): return [[0 for _ in degrees]] if (len(degrees) == 1): if (degrees[0] == n): return [[1]] return [] if (not degrees): return [] if (min(degrees) > n): return [] if (sum(degrees) < n): return [] if (sum(degrees) == n): return [[1 for _ in degrees]] i = (len(degrees) // 2) res = [] for j in range((n + 1)): v1 = exterior_algebra_basis(j, degrees[:i]) v2 = exterior_algebra_basis((n - j), degrees[i:]) res += [(l1 + l2) for l1 in v1 for l2 in v2] res.sort() return res
def total_degree(deg): '\n Total degree of ``deg``.\n\n INPUT:\n\n - ``deg`` -- an element of a free abelian group.\n\n In fact, ``deg`` could be an integer, a Python int, a list, a\n tuple, a vector, etc. This function returns the sum of the\n components of ``deg``.\n\n EXAMPLES::\n\n sage: from sage.algebras.commutative_dga import total_degree\n sage: total_degree(12)\n 12\n sage: total_degree(range(5))\n 10\n sage: total_degree(vector(range(5)))\n 10\n sage: G = AdditiveAbelianGroup((0,0))\n sage: x = G.gen(0); y = G.gen(1)\n sage: 3*x+4*y\n (3, 4)\n sage: total_degree(3*x+4*y)\n 7\n ' if (deg in ZZ): return deg return sum(deg)
class DownUpAlgebra(CombinatorialFreeModule): "\n The down-up algebra.\n\n Let `R` be a commutative ring, and let `\\alpha, \\beta, \\gamma \\in R`.\n The *down-up algebra* is the associative unital algebra\n `DU(\\alpha, \\beta, \\gamma)` generated by `d, u` with relations\n\n .. MATH::\n\n \\begin{aligned}\n d^2u & = \\alpha dud + \\beta ud^2 + \\gamma d,\n \\\\ du^2 & = \\alpha udu + \\beta u^2d + \\gamma u.\n \\end{aligned}\n\n The down-up algebra has a PBW-type basis given by\n\n .. MATH::\n\n \\{ u^i (du)^j d^k \\mid i,j,k \\in \\ZZ_{\\geq 0} \\}.\n\n This algebra originates in the study of posets. For a poset `P`,\n we define operators acting on `R[P]` by\n\n .. MATH::\n\n d(y) = \\sum_x x \\qquad\\qquad u(y) = \\sum_z z,\n\n where `y` covers `x` and `z` covers `y`. For `r`-differential posets\n we have `du - ud = r 1`, and thus it affords a representation of a\n :class:`Weyl algebra <sage.algebras.weyl_algebra.DifferentialWeylAlgebra>`.\n This Weyl algebra is obtained as the quotient of `DU(0, 1, 2r)` by the\n ideal generated by `du - ud - r`. For a `(q, r)`-differential poset,\n we have the `d` and `u` operators satisfying\n\n .. MATH::\n\n \\begin{aligned}\n d^2u & = q(q+1) dud - q^3 ud^2 + r d,\n \\\\ du^2 & = q(q+1) udu - q^3 u^2d + r u,\n \\end{aligned}\n\n or `\\alpha = q(q+1)`, `\\beta = -q^3`, and `\\gamma = r`. Specializing\n `q = -1` recovers the `r`-differential poset relation.\n\n Two other noteworthy quotients are:\n\n - the `q`-Weyl algebra from `DU(0, q^2, q+1)` by the ideal generated by\n `du - qud - 1`, and\n - the quantum plane `R_q[d, u]`, where `du = qud`, from `DU(2q, -q^2, 0)`\n by the ideal generated by `du - qud`.\n\n EXAMPLES:\n\n We begin by constructing the down-up algebra and perform some\n basic computations::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: d, u = DU.gens()\n sage: d * u\n (d*u)\n sage: u * d\n u*d\n sage: d^2 * u\n b*u*d^2 + a*(d*u)*d + g*d\n sage: d * u^2\n b*u^2*d + a*u*(d*u) + g*u\n\n We verify some examples of Proposition 3.5 in [BR1998]_, which states\n that the 0-th degree part is commutative::\n\n sage: DU0 = [u^i * (d*u)^j * d^i for i,j in\n ....: cartesian_product([range(3), range(3)])]\n sage: all(x.degree() == 0 for x in DU0)\n True\n sage: all(x * y == y * x for x, y in cartesian_product([DU0, DU0]))\n True\n\n We verify that `DU(2, -1, \\gamma)` can be described as the universal\n enveloping algebra of the 3-dimensional Lie algebra spanned by `x,y,z`\n satisfying `z = [x, y]`, `[x, z] = \\gamma x`, and `[z, y] = \\gamma y`::\n\n sage: R.<g> = QQ[]\n sage: L = LieAlgebra(R, {('x','y'): {'z': 1}, ('x','z'): {'x': g}, ('z','y'): {'y': g}},\n ....: names='x,y,z')\n sage: x, y, z = L.basis()\n sage: (L[x, y], L[x, z], L[z, y])\n (z, g*x, g*y)\n sage: x, y, z = L.pbw_basis().gens()\n sage: x^2*y - 2*x*y*x + y*x^2 == g*x\n True\n sage: x*y^2 - 2*y*x*y + y^2*x == g*y\n True\n sage: DU = algebras.DownUp(2, -1, g)\n sage: d, u = DU.gens()\n sage: d^2*u - 2*d*u*d + u*d^2 == g*d\n True\n sage: d*u^2 - 2*u*d*u + u^2*d == g*u\n True\n\n Young's lattice is known to be a differential poset. Thus we can\n construct a representation of `DU(0, 1, 2)` on this poset (which\n gives a proof that Fomin's :class:`growth diagrams <GrowthDiagram>`\n are equivalent to edge local rules or shadow lines construction\n for :func:`RSK`)::\n\n sage: DU = algebras.DownUp(0, 1, 2)\n sage: d, u = DU.gens()\n sage: d^2*u == 0*d*u*d + 1*u*d*d + 2*d\n True\n sage: d*u^2 == 0*u*d*u + 1*u*u*d + 2*u\n True\n\n sage: YL = CombinatorialFreeModule(DU.base_ring(), Partitions())\n sage: def d_action(la):\n ....: return YL.sum_of_monomials(la.remove_cell(*c) for c in la.removable_cells())\n sage: def u_action(la):\n ....: return YL.sum_of_monomials(la.add_cell(*c) for c in la.addable_cells())\n sage: D = YL.module_morphism(on_basis=d_action, codomain=YL)\n sage: U = YL.module_morphism(on_basis=u_action, codomain=YL)\n sage: for la in PartitionsInBox(5, 5):\n ....: b = YL.basis()[la]\n ....: assert (D*D*U)(b) == 0*(D*U*D)(b) + 1*(U*D*D)(b) + 2*D(b)\n ....: assert (D*U*U)(b) == 0*(U*D*U)(la) + 1*(U*U*D)(b) + 2*U(b)\n ....: assert (D*U)(b) == (U*D)(b) + b # the Weyl algebra relation\n\n .. TODO::\n\n Implement the homogenized version.\n\n REFERENCES:\n\n - [BR1998]_\n - [CM2000]_\n " @staticmethod def __classcall_private__(cls, alpha, beta, gamma, base_ring=None): '\n Standardize input to ensure a unique representation.\n\n TESTS::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU1 = algebras.DownUp(a, 1, g)\n sage: DU2 = algebras.DownUp(a, R.one(), g)\n sage: DU3 = algebras.DownUp(a, 1, g, R)\n sage: DU1 is DU2 and DU2 is DU3\n True\n ' if (base_ring is None): from sage.structure.element import get_coercion_model base_ring = get_coercion_model().common_parent(alpha, beta, gamma) if (base_ring not in Rings().Commutative()): raise TypeError('base ring must be a commutative ring') alpha = base_ring(alpha) beta = base_ring(beta) gamma = base_ring(gamma) return super().__classcall__(cls, alpha, beta, gamma, base_ring=base_ring) def __init__(self, alpha, beta, gamma, base_ring): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: d, u = DU.gens()\n sage: elts = [d, u, d^2, u^2, d*u, u*d]\n sage: TestSuite(DU).run(elements=elts)\n sage: elts += [d*(d*u)*u]\n sage: TestSuite(DU).run(elements=elts) # long time\n ' self._alpha = alpha self._beta = beta self._gamma = gamma cat = Algebras(base_ring).WithBasis().Graded() if self._beta: from sage.categories.domains import Domains cat &= Domains() indices = cartesian_product(([NonNegativeIntegers()] * 3)) CombinatorialFreeModule.__init__(self, base_ring, indices, category=cat, sorting_reverse=True) self._assign_names(['d', 'u']) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: DU = algebras.DownUp(1, 2, 3)\n sage: DU\n Down-Up algebra with parameters (1, 2, 3) over Integer Ring\n ' return 'Down-Up algebra with parameters ({}, {}, {}) over {}'.format(self._alpha, self._beta, self._gamma, self.base_ring()) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: latex(DU)\n \\mathcal{DU}(a,b,g)\n ' return ('\\mathcal{DU}(%s,%s,%s)' % (self._alpha, self._beta, self._gamma)) def _repr_term(self, m): "\n Return a string representation of the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: I = DU.indices()\n sage: DU._repr_term(I([1,0,5]))\n 'u*d^5'\n sage: DU._repr_term(I([6,3,1]))\n 'u^6*(d*u)^3*d'\n sage: DU._repr_term(I([0,1,2]))\n '(d*u)*d^2'\n sage: DU._repr_term(I([0,0,0]))\n '1'\n " if (not any(m)): return '1' ret = '' for (i, s) in enumerate(['u', '(d*u)', 'd']): if (not m[i]): continue if ret: ret += '*' if (m[i] == 1): ret += s else: ret += f'{s}^{m[i]}' return ret def _latex_term(self, m): "\n Return a latex representation for the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: I = DU.indices()\n sage: DU._latex_term(I([1,0,5]))\n 'ud^{5}'\n sage: DU._latex_term(I([6,3,1]))\n 'u^{6}(du)^{3}d'\n sage: DU._latex_term(I([0,1,2]))\n '(du)d^{2}'\n sage: DU._latex_term(I([0,0,0]))\n '1'\n " if all(((val == 0) for val in m)): return '1' ret = '' for (i, s) in enumerate(['u', '(du)', 'd']): if (not m[i]): continue if (m[i] == 1): ret += s else: ret += f'{s}^{{{m[i]}}}' return ret @cached_method def algebra_generators(self): "\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: DU = algebras.DownUp(2, 3, 4)\n sage: dict(DU.algebra_generators())\n {'d': d, 'u': u}\n " u = self.monomial(self._indices([1, 0, 0])) d = self.monomial(self._indices([0, 0, 1])) return Family({'d': d, 'u': u}) @cached_method def gens(self): '\n Return the generators of ``self``.\n\n EXAMPLES::\n\n sage: DU = algebras.DownUp(2, 3, 4)\n sage: DU.gens()\n (d, u)\n ' G = self.algebra_generators() return (G['d'], G['u']) @cached_method def one_basis(self): '\n Return the index of the basis element of `1`.\n\n EXAMPLES::\n\n sage: DU = algebras.DownUp(2, 3, 4)\n sage: DU.one_basis()\n (0, 0, 0)\n ' return self._indices([0, 0, 0]) def product_on_basis(self, m1, m2): '\n Return the product of the basis elements indexed by ``m1`` and ``m2``.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: I = DU.indices()\n sage: DU.product_on_basis(I([2,0,0]), I([4,0,0]))\n u^6\n sage: DU.product_on_basis(I([2,0,0]), I([0,4,0]))\n u^2*(d*u)^4\n sage: DU.product_on_basis(I([2,0,0]), I([0,0,4]))\n u^2*d^4\n sage: DU.product_on_basis(I([0,2,0]), I([0,4,0]))\n (d*u)^6\n sage: DU.product_on_basis(I([0,2,0]), I([0,0,4]))\n (d*u)^2*d^4\n sage: DU.product_on_basis(I([0,0,2]), I([0,0,4]))\n d^6\n sage: DU.product_on_basis(I([5,3,1]), I([1,0,4]))\n u^5*(d*u)^4*d^4\n\n sage: DU.product_on_basis(I([0,1,0]), I([1,0,0]))\n b*u^2*d + a*u*(d*u) + g*u\n sage: DU.product_on_basis(I([0,0,2]), I([1,0,0]))\n b*u*d^2 + a*(d*u)*d + g*d\n sage: DU.product_on_basis(I([0,0,1]), I([2,0,0]))\n b*u^2*d + a*u*(d*u) + g*u\n sage: DU.product_on_basis(I([0,0,1]), I([0,1,0]))\n b*u*d^2 + a*(d*u)*d + g*d\n\n sage: DU.product_on_basis(I([0,1,0]), I([3,0,0]))\n (a^2*b+b^2)*u^4*d + (a^3+2*a*b)*u^3*(d*u) + (a^2*g+a*g+b*g+g)*u^3\n sage: DU.product_on_basis(I([1,1,3]), I([0,1,1]))\n (a^2*b^2+b^3)*u^3*d^6 + (a^3*b+a*b^2)*u^2*(d*u)*d^5 + (a^2*b*g+b^2*g)*u^2*d^5\n + (a^3+2*a*b)*u*(d*u)^2*d^4 + (a^2*g+a*g+b*g+g)*u*(d*u)*d^4\n ' if (not any(m1)): return self.monomial(m2) if (not any(m2)): return self.monomial(m1) (u1, du1, d1) = m1 (u2, du2, d2) = m2 I = self._indices if (not d1): if (not u2): return self.monomial(I([u1, (du1 + du2), d2])) if (not du1): return self.monomial(I([(u1 + u2), du2, d2])) lhs = self.monomial(I([u1, (du1 - 1), 0])) mid = self._from_dict({I([1, 1, 0]): self._alpha, I([2, 0, 1]): self._beta, I([1, 0, 0]): self._gamma}) rhs = self.monomial(I([(u2 - 1), du2, d2])) elif (not u2): if (not du2): return self.monomial(I([u1, du1, (d1 + d2)])) lhs = self.monomial(I([u1, du1, (d1 - 1)])) mid = self._from_dict({I([0, 1, 1]): self._alpha, I([1, 0, 2]): self._beta, I([0, 0, 1]): self._gamma}) rhs = self.monomial(I([0, (du2 - 1), d2])) elif (u2 > 1): lhs = self.monomial(I([u1, du1, (d1 - 1)])) mid = self._from_dict({I([1, 1, 0]): self._alpha, I([2, 0, 1]): self._beta, I([1, 0, 0]): self._gamma}) rhs = self.monomial(I([(u2 - 2), du2, d2])) elif (u2 == 1): if (d1 == 1): return self.monomial(I([u1, ((du1 + du2) + 1), d2])) lhs = self.monomial(I([u1, du1, (d1 - 2)])) mid = self._from_dict({I([0, 1, 1]): self._alpha, I([1, 0, 2]): self._beta, I([0, 0, 1]): self._gamma}) rhs = self.monomial(I([0, du2, d2])) if (lhs == self.one()): if (rhs == self.one()): return mid return (mid * rhs) if (rhs == self.one()): return (lhs * mid) return ((lhs * mid) * rhs) def degree_on_basis(self, m): '\n Return the degree of the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: I = DU.indices()\n sage: DU.degree_on_basis(I([0, 3, 2]))\n -2\n sage: DU.degree_on_basis(I([2, 3, 0]))\n 2\n sage: DU.degree_on_basis(I([2, 0, 3]))\n -1\n sage: DU.degree_on_basis(I([3, 10, 3]))\n 0\n ' return (m[0] - m[2]) def verma_module(self, la): '\n Return the :class:`Verma module\n <sage.algebras.down_up_algebra.VermaModule>`\n `V(\\lambda)` of ``self``.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: DU.verma_module(5)\n Verma module of weight 5 of Down-Up algebra with parameters (a, b, g)\n over Multivariate Polynomial Ring in a, b, g over Rational Field\n ' return VermaModule(self, la)
class VermaModule(CombinatorialFreeModule): "\n The Verma module `V(\\lambda)` of a down-up algebra.\n\n The Verma module `V(\\lambda)` for the down-up algebra generated\n by `d, u` is the span of `\\{v_n \\mid n \\in \\ZZ_{\\geq 0} \\}`\n satisfying the relations\n\n .. MATH::\n\n d \\cdot v_n = \\lambda_{n-1} v_{n-1}, \\qquad\\qquad\n u \\cdot v_n = v_{n+1},\n\n where `\\lambda_n = \\alpha \\lambda_{n-1} + \\beta \\lambda_{n-2} + \\gamma`\n and we set `\\lambda_0 = \\lambda` and `\\lambda_{-1} = 0`.\n\n By Proposition 2.4 in [BR1998]_, `V(\\lambda)` is simple if and\n only if `\\lambda_n \\neq 0` for all `n \\geq 0`. Moreover, a maximal\n submodule is spanned by `\\{ v_n \\mid n > m \\}`, where `m` is the\n minimal index such that `\\lambda_m = 0`. Moreover, this is unique\n unless `\\gamma = \\lambda = 0`.\n\n EXAMPLES::\n\n sage: R.<a,b> = QQ[]\n sage: DU = algebras.DownUp(0, b, 1)\n sage: d, u = DU.gens()\n sage: V = DU.verma_module(a)\n sage: list(V.weights()[:6])\n [a, 1, a*b + 1, b + 1, a*b^2 + b + 1, b^2 + b + 1]\n sage: v = V.basis()\n sage: d^2 * v[2]\n a*v[0]\n sage: d * (d * v[2])\n a*v[0]\n\n The weight is computed by looking at the scalars associated to the\n action of `du` and `ud`::\n\n sage: d*u * v[3]\n (b+1)*v[3]\n sage: u*d * v[3]\n (a*b+1)*v[3]\n sage: v[3].weight()\n (b + 1, a*b + 1)\n\n An `U(\\mathfrak{sl}_2)` example::\n\n sage: DU = algebras.DownUp(2, -1, -2)\n sage: d, u = DU.gens()\n sage: V = DU.verma_module(5)\n sage: list(V.weights()[:10])\n [5, 8, 9, 8, 5, 0, -7, -16, -27, -40]\n sage: v6 = V.basis()[6]\n sage: d * v6\n 0\n sage: [V.basis()[i].weight() for i in range(6)]\n [(5, 0), (8, 5), (9, 8), (8, 9), (5, 8), (0, 5)]\n\n Note that these are the same `\\mathfrak{sl}_2` weights from the usual\n construction of the irreducible representation `V(5)` (but they are\n different as `\\mathfrak{gl}_2` weights)::\n\n sage: B = crystals.Tableaux(['A',1], shape=[5]) # needs sage.graphs\n sage: [b.weight() for b in B] # needs sage.graphs\n [(5, 0), (4, 1), (3, 2), (2, 3), (1, 4), (0, 5)]\n\n An example with periodic weights (see Theorem 2.13 of [BR1998]_)::\n\n sage: # needs sage.rings.number_field\n sage: k.<z6> = CyclotomicField(6)\n sage: al = z6 + 1\n sage: (al - 1)^6 == 1\n True\n sage: DU = algebras.DownUp(al, 1-al, 0)\n sage: V = DU.verma_module(5)\n sage: list(V.weights()[:8])\n [5, 5*z6 + 5, 10*z6, 10*z6 - 5, 5*z6 - 5, 0, 5, 5*z6 + 5]\n " @staticmethod def __classcall_private__(cls, DU, la): '\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: from sage.algebras.down_up_algebra import VermaModule\n sage: VermaModule(DU, 5) is VermaModule(DU, R(5))\n True\n sage: VermaModule(DU, 1/a)\n Traceback (most recent call last):\n ...\n TypeError: fraction must have unit denominator\n ' R = DU.base_ring() la = R(la) return super().__classcall__(cls, DU, la) def __init__(self, DU, la): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: V = DU.verma_module(5)\n sage: TestSuite(V).run()\n sage: V = DU.verma_module(0)\n sage: TestSuite(V).run()\n\n sage: DU = algebras.DownUp(a, 0, g)\n sage: V = DU.verma_module(5)\n sage: TestSuite(V).run()\n sage: V = DU.verma_module(0)\n sage: TestSuite(V).run()\n\n sage: DU = algebras.DownUp(a, 1-a, 0)\n sage: V = DU.verma_module(5)\n sage: TestSuite(V).run()\n sage: V = DU.verma_module(0)\n sage: TestSuite(V).run()\n ' self._DU = DU R = DU.base_ring() def _la_iter(): m2 = la (yield la) m2 = R.zero() m1 = la while True: cur = (((DU._alpha * m1) + (DU._beta * m2)) + DU._gamma) (yield cur) m2 = m1 m1 = cur self._weights = lazy_list(_la_iter()) cat = Modules(R).WithBasis() CombinatorialFreeModule.__init__(self, R, NonNegativeIntegers(), prefix='v', category=cat) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: DU = algebras.DownUp(1, 2, 3)\n sage: DU.verma_module(5)\n Verma module of weight 5 of Down-Up algebra with parameters (1, 2, 3) over Integer Ring\n ' return f'Verma module of weight {self._weights[0]} of {self._DU}' def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: DU = algebras.DownUp(1, 2, 3)\n sage: latex(DU.verma_module(5))\n V\\left(5\\right)\n ' return f'''V\left({self._weights[0]} ight)''' def highest_weight_vector(self): '\n Return the highest weight vector of ``self`` that generates\n ``self`` as a down-up module.\n\n EXAMPLES::\n\n sage: DU = algebras.DownUp(1, 2, 3)\n sage: V = DU.verma_module(5)\n sage: V.highest_weight_vector()\n v[0]\n ' return self.basis()[0] def weights(self): '\n Return the sequence of weights `(\\lambda_n)_{n=0}^{\\infty}`.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: V = DU.verma_module(5)\n sage: V.weights()\n lazy list [5, 5*a + g, 5*a^2 + a*g + 5*b + g, ...]\n\n sage: V = DU.verma_module(0)\n sage: DU = algebras.DownUp(a, 1-a, 0)\n sage: V = DU.verma_module(0)\n sage: V.weights()\n lazy list [0, 0, 0, ...]\n\n We reproduce the Fibonacci numbers example from [BR1998]_::\n\n sage: R.<la> = QQ[]\n sage: DU = algebras.DownUp(1, 1, 0, R)\n sage: V = DU.verma_module(la)\n sage: list(V.weights()[:11])\n [la, la, 2*la, 3*la, 5*la, 8*la, 13*la, 21*la, 34*la, 55*la, 89*la]\n ' return self._weights def _action_on_basis(self, m, n): '\n Return the action of a basis element of the down-up algebra indexed\n by ``m`` on the basis element of ``self`` indexed by ``n``.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(0, b, 1)\n sage: I = DU.indices()\n sage: V = DU.verma_module(1)\n sage: V.weights()\n lazy list [1, 1, b + 1, ...]\n sage: V._action_on_basis(I([0,0,1]), 0)\n 0\n sage: V._action_on_basis(I([0,1,0]), 0)\n v[0]\n sage: V._action_on_basis(I([1,0,0]), 0)\n v[1]\n\n sage: V._action_on_basis(I([0,0,1]), 3)\n (b+1)*v[2]\n sage: V._action_on_basis(I([0,1,0]), 3)\n (b+1)*v[3]\n sage: V._action_on_basis(I([1,0,0]), 3)\n v[4]\n\n sage: V._action_on_basis(I([0,0,3]), 3)\n (b+1)*v[0]\n sage: V._action_on_basis(I([1,2,1]), 3)\n (b^3+3*b^2+3*b+1)*v[3]\n\n sage: V = DU.verma_module(0)\n sage: V._action_on_basis(I([0,0,1]), 1)\n 0\n ' if (m[2] > n): return self.zero() np = (n - m[2]) coeff = (prod(self._weights[np:n]) * (self._weights[np] ** m[1])) return self.term(((n - m[2]) + m[0]), coeff) class Element(CombinatorialFreeModule.Element): '\n An element of a Verma module of a down-up algebra.\n ' def _acted_upon_(self, scalar, self_on_left): "\n Return the action of ``scalar`` (an element of the base ring or\n the defining down-up algebra) on ``self``.\n\n EXAMPLES::\n\n sage: R.<a,b> = QQ[]\n sage: DU = algebras.DownUp(0, b, 1)\n sage: d, u = DU.gens()\n sage: V = DU.verma_module(a)\n sage: it = iter(DU.basis())\n sage: scalars = [next(it) for _ in range(10)]; scalars\n [1, u, (d*u), d, u^2, u*(d*u), u*d, (d*u)^2, (d*u)*d, d^2]\n sage: vecs = [V.basis()[0], V.basis()[1], V.basis()[6]]\n sage: all((x * y) * v == x * (y * v)\n ....: for x in scalars for y in scalars for v in vecs)\n True\n sage: 5 * V.basis()[3]\n 5*v[3]\n sage: V.basis()[0] * d\n Traceback (most recent call last):\n ...\n TypeError: unsupported operand parent(s) for *:\n 'Verma module of weight a of Down-Up algebra ...'\n and 'Down-Up algebra ...'\n " ret = super()._acted_upon_(scalar, self_on_left) if (ret is not None): return ret P = self.parent() try: scalar = P._DU(scalar) except (TypeError, ValueError): return None if self_on_left: return None return P.linear_combination(((P._action_on_basis(m, n), (mc * nc)) for (m, mc) in scalar._monomial_coefficients.items() for (n, nc) in self._monomial_coefficients.items())) def is_weight_vector(self): '\n Return if ``self`` is a weight vector.\n\n EXAMPLES::\n\n sage: DU = algebras.DownUp(2, -1, -2)\n sage: V = DU.verma_module(5)\n sage: V.zero().is_weight_vector()\n False\n sage: B = V.basis()\n sage: [B[i].weight() for i in range(6)]\n [(5, 0), (8, 5), (9, 8), (8, 9), (5, 8), (0, 5)]\n sage: B[5].is_weight_vector()\n True\n sage: v = B[0] + B[1]\n sage: v.is_weight_vector()\n False\n\n sage: DU = algebras.DownUp(2, -1, 0)\n sage: V = DU.verma_module(0)\n sage: B = V.basis()\n sage: v = sum(i*B[i] for i in range(1,5))\n sage: v.is_weight_vector()\n True\n ' if (not self): return False P = self.parent() R = P.base_ring() weights = P._weights def get_wt(n): if (not n): return (R(P._weights[0]), R.zero()) return (R(P._weights[n]), R(P._weights[(n - 1)])) it = iter(self._monomial_coefficients) wt = get_wt(next(it)) return all(((get_wt(n) == wt) for n in it)) def weight(self): '\n Return the weight of ``self``.\n\n For `v_n`, this is the vector with the pair\n `(\\lambda_n, \\lambda_{n-1})`.\n\n EXAMPLES::\n\n sage: R.<a,b,g> = QQ[]\n sage: DU = algebras.DownUp(a, b, g)\n sage: V = DU.verma_module(5)\n sage: B = V.basis()\n sage: B[0].weight()\n (5, 0)\n sage: B[1].weight()\n (5*a + g, 5)\n sage: B[2].weight()\n (5*a^2 + a*g + 5*b + g, 5*a + g)\n\n sage: V.zero().weight()\n Traceback (most recent call last):\n ...\n ValueError: the zero element does not have well-defined weight\n sage: (B[0] + B[1]).weight()\n Traceback (most recent call last):\n ...\n ValueError: not a weight vector\n ' if (not self): raise ValueError('the zero element does not have well-defined weight') if (not self.is_weight_vector()): raise ValueError('not a weight vector') P = self.parent() R = P.base_ring() V = FreeModule(R, 2) weights = P._weights it = iter(self._monomial_coefficients) n = next(it) if (not n): return V([P._weights[0], R.zero()]) return V([P._weights[n], P._weights[(n - 1)]])
class FiniteDimensionalAlgebra(UniqueRepresentation, Algebra): "\n Create a finite-dimensional `k`-algebra from a multiplication table.\n\n INPUT:\n\n - ``k`` -- a field\n\n - ``table`` -- a list of matrices\n\n - ``names`` -- (default: ``'e'``) string; names for the basis\n elements\n\n - ``assume_associative`` -- (default: ``False``) boolean; if\n ``True``, then the category is set to ``category.Associative()``\n and methods requiring associativity assume this\n\n - ``category`` -- (default:\n ``MagmaticAlgebras(k).FiniteDimensional().WithBasis()``)\n the category to which this algebra belongs\n\n The list ``table`` must have the following form: there exists a\n finite-dimensional `k`-algebra of degree `n` with basis\n `(e_1, \\ldots, e_n)` such that the `i`-th element of ``table`` is the\n matrix of right multiplication by `e_i` with respect to the basis\n `(e_1, \\ldots, e_n)`.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])]); A\n Finite-dimensional algebra of degree 2 over Finite Field of size 3\n sage: TestSuite(A).run()\n\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,0]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,0,0], [0,0,0], [0,0,1]])])\n sage: B\n Finite-dimensional algebra of degree 3 over Rational Field\n\n TESTS::\n\n sage: A.category()\n Category of finite dimensional magmatic algebras with basis\n over Finite Field of size 3\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])],\n ....: assume_associative=True)\n sage: A.category()\n Category of finite dimensional associative algebras with basis\n over Finite Field of size 3\n " @staticmethod def __classcall_private__(cls, k, table, names='e', assume_associative=False, category=None): "\n Normalize input.\n\n TESTS::\n\n sage: table = [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])]\n sage: A1 = FiniteDimensionalAlgebra(GF(3), table)\n sage: A2 = FiniteDimensionalAlgebra(GF(3), table, names='e')\n sage: A3 = FiniteDimensionalAlgebra(GF(3), table, names=['e0', 'e1'])\n sage: A1 is A2 and A2 is A3\n True\n\n The ``assume_associative`` keyword is built into the category::\n\n sage: from sage.categories.magmatic_algebras import MagmaticAlgebras\n sage: cat = MagmaticAlgebras(GF(3)).FiniteDimensional().WithBasis()\n sage: A1 = FiniteDimensionalAlgebra(GF(3), table,\n ....: category=cat.Associative())\n sage: A2 = FiniteDimensionalAlgebra(GF(3), table, assume_associative=True)\n sage: A1 is A2\n True\n\n Uniqueness depends on the category::\n\n sage: cat = Algebras(GF(3)).FiniteDimensional().WithBasis()\n sage: A1 = FiniteDimensionalAlgebra(GF(3), table)\n sage: A2 = FiniteDimensionalAlgebra(GF(3), table, category=cat)\n sage: A1 == A2\n False\n sage: A1 is A2\n False\n\n Checking that equality is still as expected::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), table)\n sage: B = FiniteDimensionalAlgebra(GF(5), [Matrix([0])])\n sage: A == A\n True\n sage: B == B\n True\n sage: A == B\n False\n sage: A != A\n False\n sage: B != B\n False\n sage: A != B\n True\n " n = len(table) table = [b.base_extend(k) for b in table] for b in table: b.set_immutable() if (not (is_Matrix(b) and (b.dimensions() == (n, n)))): raise ValueError('input is not a multiplication table') table = tuple(table) cat = MagmaticAlgebras(k).FiniteDimensional().WithBasis() cat = cat.or_subcategory(category) if assume_associative: cat = cat.Associative() names = normalize_names(n, names) return super().__classcall__(cls, k, table, names, category=cat) def __init__(self, k, table, names='e', category=None): "\n TESTS::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [])\n sage: A\n Finite-dimensional algebra of degree 0 over Rational Field\n sage: type(A)\n <class 'sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra.FiniteDimensionalAlgebra_with_category'>\n sage: TestSuite(A).run()\n\n sage: B = FiniteDimensionalAlgebra(GF(7), [Matrix([1])])\n sage: B\n Finite-dimensional algebra of degree 1 over Finite Field of size 7\n sage: TestSuite(B).run()\n\n sage: C = FiniteDimensionalAlgebra(CC, [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])])\n sage: C\n Finite-dimensional algebra of degree 2 over Complex Field with 53 bits of precision\n sage: TestSuite(C).run()\n\n sage: FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]])])\n Traceback (most recent call last):\n ...\n ValueError: input is not a multiplication table\n\n sage: D.<a,b> = FiniteDimensionalAlgebra(RR, [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [-1, 0]])])\n sage: D.gens()\n (a, b)\n\n sage: E = FiniteDimensionalAlgebra(QQ, [Matrix([0])])\n sage: E.gens()\n (e,)\n " self._table = table self._assume_associative = ('Associative' in category.axioms()) Algebra.__init__(self, base_ring=k, names=names, category=category) def _repr_(self): "\n Return a string representation of ``self``.\n\n TESTS::\n\n sage: FiniteDimensionalAlgebra(RR, [Matrix([1])])._repr_()\n 'Finite-dimensional algebra of degree 1 over Real Field with 53 bits of precision'\n " return 'Finite-dimensional algebra of degree {} over {}'.format(self.degree(), self.base_ring()) def _coerce_map_from_(self, S): '\n TESTS::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: A.has_coerce_map_from(ZZ)\n True\n sage: A.has_coerce_map_from(GF(3))\n True\n sage: A.has_coerce_map_from(GF(5))\n False\n sage: A.has_coerce_map_from(QQ)\n False\n ' return ((S == self) or (self.base_ring().has_coerce_map_from(S) and self.is_unitary())) Element = FiniteDimensionalAlgebraElement def _element_constructor_(self, x): '\n TESTS::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([0])])\n sage: a = A(0)\n sage: a.parent()\n Finite-dimensional algebra of degree 1 over Rational Field\n sage: A(1)\n Traceback (most recent call last):\n ...\n TypeError: algebra is not unitary\n\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,0]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,0,0], [0,0,0], [0,0,1]])])\n sage: B(17)\n 17*e0 + 17*e2\n ' return self.element_class(self, x) from_base_ring = _element_constructor_ def _Hom_(self, B, category): '\n Construct a homset of ``self`` and ``B``.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([1])])\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])])\n sage: A._Hom_(B, A.category())\n Set of Homomorphisms\n from Finite-dimensional algebra of degree 1 over Rational Field\n to Finite-dimensional algebra of degree 2 over Rational Field\n ' cat = MagmaticAlgebras(self.base_ring()).FiniteDimensional().WithBasis() if category.is_subcategory(cat): from sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra_morphism import FiniteDimensionalAlgebraHomset return FiniteDimensionalAlgebraHomset(self, B, category=category) return super()._Hom_(B, category) def ngens(self): '\n Return the number of generators of ``self``, i.e., the degree\n of ``self`` over its base field.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: A.ngens()\n 2\n ' return len(self._table) degree = ngens @cached_method def gen(self, i): '\n Return the `i`-th basis element of ``self``.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: A.gen(0)\n e0\n ' return self.element_class(self, [(j == i) for j in range(self.ngens())]) @cached_method def basis(self): '\n Return a list of the basis elements of ``self``.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: A.basis()\n Family (e0, e1)\n ' from sage.sets.family import Family return Family(self.gens()) def __iter__(self): "\n Iterates over the elements of ``self``.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: list(A)\n [0, e0, 2*e0, e1, e0 + e1, 2*e0 + e1, 2*e1, e0 + 2*e1, 2*e0 + 2*e1]\n\n This is used in the :class:`Testsuite`'s when ``self`` is\n finite.\n " if (not self.is_finite()): raise NotImplementedError('object does not support iteration') V = self.zero().vector().parent() for v in V: (yield self(v)) def _ideal_class_(self, n=0): "\n Return the ideal class of ``self`` (that is, the class that\n all ideals of ``self`` inherit from).\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: A._ideal_class_()\n <class 'sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra_ideal.FiniteDimensionalAlgebraIdeal'>\n " return FiniteDimensionalAlgebraIdeal def table(self): '\n Return the multiplication table of ``self``, as a list of\n matrices for right multiplication by the basis elements.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: A.table()\n (\n [1 0] [0 1]\n [0 1], [0 0]\n )\n ' return self._table @cached_method def left_table(self): '\n Return the list of matrices for left multiplication by the\n basis elements.\n\n EXAMPLES::\n\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0], [0,1]]),\n ....: Matrix([[0,1], [-1,0]])])\n sage: T = B.left_table(); T\n (\n [1 0] [ 0 1]\n [0 1], [-1 0]\n )\n\n We check immutability::\n\n sage: T[0] = "vandalized by h4xx0r"\n Traceback (most recent call last):\n ...\n TypeError: \'tuple\' object does not support item assignment\n sage: T[1][0] = [13, 37]\n Traceback (most recent call last):\n ...\n ValueError: matrix is immutable; please change a copy instead\n (i.e., use copy(M) to change a copy of M).\n ' B = self.table() n = self.degree() table = [Matrix([B[j][i] for j in range(n)]) for i in range(n)] for b in table: b.set_immutable() return tuple(table) def base_extend(self, F): '\n Return ``self`` base changed to the field ``F``.\n\n EXAMPLES::\n\n sage: C = FiniteDimensionalAlgebra(GF(2), [Matrix([1])])\n sage: k.<y> = GF(4) # needs sage.rings.finite_rings\n sage: C.base_extend(k) # needs sage.rings.finite_rings\n Finite-dimensional algebra of degree 1 over Finite Field in y of size 2^2\n ' return FiniteDimensionalAlgebra(F, self.table()) def cardinality(self): '\n Return the cardinality of ``self``.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(7), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [2, 3]])])\n sage: A.cardinality()\n 49\n\n sage: B = FiniteDimensionalAlgebra(RR, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [2, 3]])])\n sage: B.cardinality()\n +Infinity\n\n sage: C = FiniteDimensionalAlgebra(RR, [])\n sage: C.cardinality()\n 1\n ' n = self.degree() return (ZZ.one() if (not n) else (self.base_ring().cardinality() ** n)) def ideal(self, gens=None, given_by_matrix=False, side=None): '\n Return the right ideal of ``self`` generated by ``gens``.\n\n INPUT:\n\n - ``A`` -- a :class:`FiniteDimensionalAlgebra`\n\n - ``gens`` -- (default: None) - either an element of ``A`` or a\n list of elements of ``A``, given as vectors, matrices, or\n FiniteDimensionalAlgebraElements. If ``given_by_matrix`` is\n ``True``, then ``gens`` should instead be a matrix whose rows\n form a basis of an ideal of ``A``.\n\n - ``given_by_matrix`` -- boolean (default: ``False``) - if\n ``True``, no checking is done\n\n - ``side`` -- ignored but necessary for coercions\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: A.ideal(A([1,1]))\n Ideal (e0 + e1) of\n Finite-dimensional algebra of degree 2 over Finite Field of size 3\n ' return self._ideal_class_()(self, gens=gens, given_by_matrix=given_by_matrix) @cached_method def is_associative(self): '\n Return ``True`` if ``self`` is associative.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0], [0,1]]),\n ....: Matrix([[0,1], [-1,0]])])\n sage: A.is_associative()\n True\n\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,1]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,0,1], [0,0,0], [1,0,0]])])\n sage: B.is_associative()\n False\n\n sage: e = B.basis()\n sage: (e[1]*e[2])*e[2]==e[1]*(e[2]*e[2])\n False\n ' B = self.table() n = self.degree() for i in range(n): for j in range(n): eiej = B[j][i] if ((B[i] * B[j]) != sum(((eiej[k] * B[k]) for k in range(n)))): return False return True @cached_method def is_commutative(self): '\n Return ``True`` if ``self`` is commutative.\n\n EXAMPLES::\n\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,0]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,0,0], [0,0,0], [0,0,1]])])\n sage: B.is_commutative()\n True\n\n sage: C = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,0,0], [0,1,0], [0,0,1]])])\n sage: C.is_commutative()\n False\n ' B = self.table() for i in range(self.degree()): for j in range(i): if (B[j][i] != B[i][j]): return False return True def is_finite(self): '\n Return ``True`` if the cardinality of ``self`` is finite.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(7), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [2, 3]])])\n sage: A.is_finite()\n True\n\n sage: B = FiniteDimensionalAlgebra(RR, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [2, 3]])])\n sage: B.is_finite()\n False\n\n sage: C = FiniteDimensionalAlgebra(RR, [])\n sage: C.is_finite()\n True\n ' return ((self.degree() == 0) or self.base_ring().is_finite()) @cached_method def is_unitary(self): '\n Return ``True`` if ``self`` has a two-sided multiplicative\n identity element.\n\n .. WARNING::\n\n This uses linear algebra; thus expect wrong results when\n the base ring is not a field.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [])\n sage: A.is_unitary()\n True\n\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0], [0,1]]),\n ....: Matrix([[0,1], [-1,0]])])\n sage: B.is_unitary()\n True\n\n sage: C = FiniteDimensionalAlgebra(QQ, [Matrix([[0,0], [0,0]]),\n ....: Matrix([[0,0], [0,0]])])\n sage: C.is_unitary()\n False\n\n sage: D = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0], [0,1]]),\n ....: Matrix([[1,0], [0,1]])])\n sage: D.is_unitary()\n False\n\n sage: E = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0],[1,0]]),\n ....: Matrix([[0,1],[0,1]])])\n sage: E.is_unitary()\n False\n\n sage: F = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,1]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,0,1], [0,0,0], [1,0,0]])])\n sage: F.is_unitary()\n True\n\n sage: G = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,1]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,1,0], [0,0,0], [1,0,0]])])\n sage: G.is_unitary() # Unique right identity, but no left identity.\n False\n ' n = self.degree() k = self.base_ring() if (n == 0): self._one = matrix(k, 1, n) return True B1 = reduce((lambda x, y: x.augment(y)), self._table, Matrix(k, n, 0)) B2 = reduce((lambda x, y: x.augment(y)), self.left_table(), Matrix(k, n, 0)) kone = k.one() kzero = k.zero() v = matrix(k, 1, (n ** 2), (((n - 1) * ([kone] + (n * [kzero]))) + [kone])) try: sol1 = B1.solve_left(v) sol2 = B2.solve_left(v) except ValueError: return False assert (sol1 == sol2) self._one = sol1 return True def is_zero(self): '\n Return ``True`` if ``self`` is the zero ring.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [])\n sage: A.is_zero()\n True\n\n sage: B = FiniteDimensionalAlgebra(GF(7), [Matrix([0])])\n sage: B.is_zero()\n False\n ' return (self.degree() == 0) def one(self): '\n Return the multiplicative identity element of ``self``, if it\n exists.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [])\n sage: A.one()\n 0\n\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0], [0,1]]),\n ....: Matrix([[0,1], [-1,0]])])\n sage: B.one()\n e0\n\n sage: C = FiniteDimensionalAlgebra(QQ, [Matrix([[0,0], [0,0]]),\n ....: Matrix([[0,0], [0,0]])])\n sage: C.one()\n Traceback (most recent call last):\n ...\n TypeError: algebra is not unitary\n\n sage: D = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,1]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,0,1], [0,0,0], [1,0,0]])])\n sage: D.one()\n e0\n\n sage: E = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,1]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,1,0], [0,0,0], [1,0,0]])])\n sage: E.one()\n Traceback (most recent call last):\n ...\n TypeError: algebra is not unitary\n ' if (not self.is_unitary()): raise TypeError('algebra is not unitary') else: return self(self._one) def random_element(self, *args, **kwargs): '\n Return a random element of ``self``.\n\n Optional input parameters are propagated to the ``random_element``\n method of the underlying :class:`VectorSpace`.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: A.random_element() # random\n e0 + 2*e1\n\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,0]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,0,0], [0,0,0], [0,0,1]])])\n sage: B.random_element(num_bound=1000) # random\n 215/981*e0 + 709/953*e1 + 931/264*e2\n ' return self(self.zero().vector().parent().random_element(*args, **kwargs)) def _is_valid_homomorphism_(self, other, im_gens, base_map=None): '\n TESTS::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([1])])\n sage: Hom(A, B)(Matrix([[1], [0]]))\n Morphism from Finite-dimensional algebra of degree 2 over Rational Field\n to Finite-dimensional algebra of degree 1 over Rational Field given by matrix\n [1]\n [0]\n sage: Hom(B, A)(Matrix([[1, 0]]))\n Morphism from Finite-dimensional algebra of degree 1 over Rational Field\n to Finite-dimensional algebra of degree 2 over Rational Field given by matrix\n [1 0]\n sage: H = Hom(A, A)\n sage: H(Matrix.identity(QQ, 2))\n Morphism from Finite-dimensional algebra of degree 2 over Rational Field\n to Finite-dimensional algebra of degree 2 over Rational Field given by matrix\n [1 0]\n [0 1]\n sage: H(Matrix([[1, 0], [0, 0]]))\n Morphism from Finite-dimensional algebra of degree 2 over Rational Field\n to Finite-dimensional algebra of degree 2 over Rational Field given by matrix\n [1 0]\n [0 0]\n sage: H(Matrix([[1, 0], [1, 1]]))\n Traceback (most recent call last):\n ...\n ValueError: relations do not all (canonically) map to 0\n under map determined by images of generators\n sage: Hom(B, B)(Matrix([[2]]))\n Traceback (most recent call last):\n ...\n ValueError: relations do not all (canonically) map to 0\n under map determined by images of generators\n ' assert (len(im_gens) == self.degree()) if (base_map is None): base_map = (lambda x: x) B = self.table() for (i, gi) in enumerate(im_gens): for (j, gj) in enumerate(im_gens): eiej = B[j][i] if (sum([(other(im_gens[k]) * base_map(v)) for (k, v) in enumerate(eiej)]) != (other(gi) * other(gj))): return False return True def quotient_map(self, ideal): '\n Return the quotient of ``self`` by ``ideal``.\n\n INPUT:\n\n - ``ideal`` -- a :class:`FiniteDimensionalAlgebraIdeal`\n\n OUTPUT:\n\n - :class:`~sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra_morphism.FiniteDimensionalAlgebraMorphism`;\n the quotient homomorphism\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: q0 = A.quotient_map(A.zero_ideal()); q0\n Morphism\n from Finite-dimensional algebra of degree 2 over Finite Field of size 3\n to Finite-dimensional algebra of degree 2 over Finite Field of size 3\n given by matrix\n [1 0]\n [0 1]\n sage: q1 = A.quotient_map(A.ideal(A.gen(1))); q1\n Morphism\n from Finite-dimensional algebra of degree 2 over Finite Field of size 3\n to Finite-dimensional algebra of degree 1 over Finite Field of size 3\n given by matrix\n [1]\n [0]\n ' k = self.base_ring() f = ideal.basis_matrix().transpose().kernel().basis_matrix().echelon_form().transpose() pivots = f.pivot_rows() table = [] for p in pivots: v = matrix(k, 1, self.degree()) v[(0, p)] = 1 v = self.element_class(self, v) table.append(f.solve_right((v.matrix() * f))) B = FiniteDimensionalAlgebra(k, table) return self.hom(f, codomain=B, check=False) def maximal_ideal(self): '\n Compute the maximal ideal of the local algebra ``self``.\n\n .. NOTE::\n\n ``self`` must be unitary, commutative, associative and local\n (have a unique maximal ideal).\n\n OUTPUT:\n\n - :class:`~sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra_ideal.FiniteDimensionalAlgebraIdeal`;\n the unique maximal ideal of ``self``. If ``self`` is not a local\n algebra, a :class:`ValueError` is raised.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: A.maximal_ideal() # needs sage.rings.finite_rings\n Ideal (0, e1) of\n Finite-dimensional algebra of degree 2 over Finite Field of size 3\n\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,0]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,0,0], [0,0,0], [0,0,1]])])\n sage: B.maximal_ideal() # needs sage.libs.pari\n Traceback (most recent call last):\n ...\n ValueError: algebra is not local\n ' if (self.degree() == 0): raise ValueError('the zero algebra is not local') if (not (self.is_unitary() and self.is_commutative() and (self._assume_associative or self.is_associative()))): raise TypeError('algebra must be unitary, commutative and associative') gens = [] for x in self.gens(): f = x.characteristic_polynomial().factor() if (len(f) != 1): raise ValueError('algebra is not local') if (f[0][1] > 1): gens.append(f[0][0](x)) return FiniteDimensionalAlgebraIdeal(self, gens) def primary_decomposition(self): '\n Return the primary decomposition of ``self``.\n\n .. NOTE::\n\n ``self`` must be unitary, commutative and associative.\n\n OUTPUT:\n\n - a list consisting of the quotient maps ``self`` -> `A`,\n with `A` running through the primary factors of ``self``\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: A.primary_decomposition() # needs sage.rings.finite_rings\n [Morphism\n from Finite-dimensional algebra of degree 2 over Finite Field of size 3\n to Finite-dimensional algebra of degree 2 over Finite Field of size 3\n given by matrix [1 0]\n [0 1]]\n\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,0]]),\n ....: Matrix([[0,1,0], [0,0,0], [0,0,0]]),\n ....: Matrix([[0,0,0], [0,0,0], [0,0,1]])])\n sage: B.primary_decomposition() # needs sage.libs.pari\n [Morphism\n from Finite-dimensional algebra of degree 3 over Rational Field\n to Finite-dimensional algebra of degree 1 over Rational Field\n given by matrix [0]\n [0]\n [1],\n Morphism\n from Finite-dimensional algebra of degree 3 over Rational Field\n to Finite-dimensional algebra of degree 2 over Rational Field\n given by matrix [1 0]\n [0 1]\n [0 0]]\n ' k = self.base_ring() n = self.degree() if (n == 0): return [] if (not (self.is_unitary() and self.is_commutative() and (self._assume_associative or self.is_associative()))): raise TypeError('algebra must be unitary, commutative and associative') components = [Matrix.identity(k, n)] for b in self.table(): components_new = [] for c in components: b_c = c.solve_left((c * b)) fact = b_c.characteristic_polynomial().factor() if (len(fact) == 1): components_new.append(c) else: for f in fact: (h, a) = f e = (h(b_c) ** a) ker_e = e.kernel().basis_matrix() components_new.append((ker_e * c)) components = components_new quotients = [] for i in range(len(components)): I = Matrix(k, 0, n) for (j, c) in enumerate(components): if (j != i): I = I.stack(c) quotients.append(self.quotient_map(self.ideal(I, given_by_matrix=True))) return quotients def maximal_ideals(self): '\n Return a list consisting of all maximal ideals of ``self``.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: A.maximal_ideals() # needs sage.rings.finite_rings\n [Ideal (e1) of Finite-dimensional algebra of degree 2 over Finite Field of size 3]\n\n sage: B = FiniteDimensionalAlgebra(QQ, [])\n sage: B.maximal_ideals()\n []\n ' P = self.primary_decomposition() return [f.inverse_image(f.codomain().maximal_ideal()) for f in P]
class FiniteDimensionalAlgebraIdeal(Ideal_generic): '\n An ideal of a :class:`FiniteDimensionalAlgebra`.\n\n INPUT:\n\n - ``A`` -- a finite-dimensional algebra\n - ``gens`` -- the generators of this ideal\n - ``given_by_matrix`` -- (default: ``False``) whether the basis matrix is\n given by ``gens``\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])])\n sage: A.ideal(A([0,1]))\n Ideal (e1) of Finite-dimensional algebra of degree 2 over Finite Field of size 3\n ' def __init__(self, A, gens=None, given_by_matrix=False): '\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])])\n sage: I = A.ideal(A([0,1]))\n sage: TestSuite(I).run(skip="_test_category") # Currently ideals are not using the category framework\n ' k = A.base_ring() n = A.degree() if given_by_matrix: self._basis_matrix = gens gens = gens.rows() elif (gens is None): self._basis_matrix = Matrix(k, 0, n) elif isinstance(gens, (list, tuple)): B = [FiniteDimensionalAlgebraIdeal(A, x).basis_matrix() for x in gens] B = reduce((lambda x, y: x.stack(y)), B, Matrix(k, 0, n)) self._basis_matrix = B.echelon_form().image().basis_matrix() elif is_Matrix(gens): gens = FiniteDimensionalAlgebraElement(A, gens) elif isinstance(gens, FiniteDimensionalAlgebraElement): gens = gens.vector() B = Matrix([(gens * b).list() for b in A.table()]) self._basis_matrix = B.echelon_form().image().basis_matrix() Ideal_generic.__init__(self, A, gens) def _richcmp_(self, other, op): '\n Comparisons\n\n TESTS::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])])\n sage: I = A.ideal(A([1,1]))\n sage: J = A.ideal(A([0,1]))\n sage: I == J\n False\n sage: I == I\n True\n sage: I == I + J\n True\n\n sage: A2 = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])])\n sage: A is A2\n True\n sage: A == A2\n True\n sage: I2 = A.ideal(A([1,1]))\n sage: I == I2\n True\n\n sage: I != J, I != I, I != I+J\n (True, False, False)\n sage: I <= J, I <= I, I <= I+J\n (False, True, True)\n sage: I < J, I < I, I < I+J\n (False, False, False)\n sage: I >= J, I >= I, I >= I+J\n (True, True, True)\n sage: I > J, I > I, I > I+J\n (True, False, False)\n\n sage: I = A.ideal(A([1,1]))\n sage: J = A.ideal(A([0,1]))\n sage: I != J\n True\n sage: I != I\n False\n sage: I != I + J\n False\n ' if (self.basis_matrix() == other.basis_matrix()): return ((op == op_EQ) or (op == op_LE) or (op == op_GE)) elif (op == op_EQ): return False elif (op == op_NE): return True if ((op == op_LE) or (op == op_LT)): return self.vector_space().is_subspace(other.vector_space()) elif ((op == op_GE) or (op == op_GT)): return other.vector_space().is_subspace(self.vector_space()) def __contains__(self, elt): '\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])])\n sage: J = A.ideal(A([0,1]))\n sage: A([0,1]) in J\n True\n sage: A([1,0]) in J\n False\n ' if (self.ring() is not parent(elt)): return False return (elt.vector() in self.vector_space()) def basis_matrix(self): '\n Return the echelonized matrix whose rows form a basis of ``self``.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])])\n sage: I = A.ideal(A([1,1]))\n sage: I.basis_matrix()\n [1 0]\n [0 1]\n ' return self._basis_matrix @cached_method def vector_space(self): '\n Return ``self`` as a vector space.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1, 0], [0, 1]]), Matrix([[0, 1], [0, 0]])])\n sage: I = A.ideal(A([1,1]))\n sage: I.vector_space()\n Vector space of degree 2 and dimension 2 over Finite Field of size 3\n Basis matrix:\n [1 0]\n [0 1]\n ' return self.basis_matrix().image()
class FiniteDimensionalAlgebraMorphism(RingHomomorphism_im_gens): '\n Create a morphism between two :class:`finite-dimensional algebras <FiniteDimensionalAlgebra>`.\n\n INPUT:\n\n - ``parent`` -- the parent homset\n\n - ``f`` -- matrix of the underlying `k`-linear map\n\n - ``unitary`` -- boolean (default: ``True``); if ``True`` and ``check``\n is also ``True``, raise a :class:`ValueError` unless ``A`` and ``B`` are\n unitary and ``f`` respects unit elements\n\n - ``check`` -- boolean (default: ``True``); check whether the given\n `k`-linear map really defines a (not necessarily unitary)\n `k`-algebra homomorphism\n\n The algebras ``A`` and ``B`` must be defined over the same base field.\n\n EXAMPLES::\n\n sage: from sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra_morphism import FiniteDimensionalAlgebraMorphism\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([1])])\n sage: H = Hom(A, B)\n sage: f = H(Matrix([[1], [0]]))\n sage: f.domain() is A\n True\n sage: f.codomain() is B\n True\n sage: f(A.basis()[0])\n e\n sage: f(A.basis()[1])\n 0\n\n .. TODO:: An example illustrating unitary flag.\n ' def __init__(self, parent, f, check=True, unitary=True): '\n TESTS::\n\n sage: from sage.algebras.finite_dimensional_algebras.finite_dimensional_algebra_morphism import FiniteDimensionalAlgebraMorphism\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([1])])\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: H = Hom(A, B)\n sage: phi = FiniteDimensionalAlgebraMorphism(H, Matrix([[1, 0]]))\n sage: TestSuite(phi).run(skip="_test_category")\n ' A = parent.domain() B = parent.codomain() RingHomomorphism_im_gens.__init__(self, parent=parent, im_gens=f.rows(), check=check) self._matrix = f if (unitary and check and ((not A.is_unitary()) or (not B.is_unitary()) or (self(A.one()) != B.one()))): raise ValueError('homomorphism does not respect unit elements') def _repr_(self): "\n TESTS::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: I = A.maximal_ideal() # needs sage.libs.pari\n sage: q = A.quotient_map(I) # needs sage.libs.pari\n sage: q._repr_() # needs sage.libs.pari\n 'Morphism from Finite-dimensional algebra of degree 2 over Rational Field to Finite-dimensional algebra of degree 1 over Rational Field given by matrix\\n[1]\\n[0]'\n " return 'Morphism from {} to {} given by matrix\n{}'.format(self.domain(), self.codomain(), self._matrix) def __call__(self, x): '\n TESTS::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: I = A.maximal_ideal() # needs sage.libs.pari\n sage: q = A.quotient_map(I) # needs sage.libs.pari\n sage: q(0) == 0 and q(1) == 1 # needs sage.libs.pari\n True\n ' x = self.domain()(x) B = self.codomain() return B.element_class(B, (x.vector() * self._matrix)) def __eq__(self, other): '\n Check equality.\n\n TESTS::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([1])])\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: H = Hom(A, B)\n sage: phi = H(Matrix([[1, 0]]))\n sage: psi = H(Matrix([[1, 0]]))\n sage: phi == psi\n True\n sage: phi == H.zero()\n False\n ' return (isinstance(other, FiniteDimensionalAlgebraMorphism) and (self.parent() == other.parent()) and (self._matrix == other._matrix)) def __ne__(self, other): '\n Check not equals.\n\n TESTS::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([1])])\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: H = Hom(A, B)\n sage: phi = H(Matrix([[1, 0]]))\n sage: psi = H(Matrix([[1, 0]]))\n sage: phi != psi\n False\n sage: phi != H.zero()\n True\n ' return (not (self == other)) def matrix(self): '\n Return the matrix of ``self``.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([1])])\n sage: M = Matrix([[1], [0]])\n sage: H = Hom(A, B)\n sage: f = H(M)\n sage: f.matrix() == M\n True\n ' return self._matrix def inverse_image(self, I): '\n Return the inverse image of ``I`` under ``self``.\n\n INPUT:\n\n - ``I`` -- ``FiniteDimensionalAlgebraIdeal``, an ideal of ``self.codomain()``\n\n OUTPUT:\n\n :class:`FiniteDimensionalAlgebraIdeal`, the inverse image of `I` under ``self``.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: I = A.maximal_ideal() # needs sage.libs.pari\n sage: q = A.quotient_map(I) # needs sage.libs.pari\n sage: B = q.codomain() # needs sage.libs.pari\n sage: q.inverse_image(B.zero_ideal()) == I # needs sage.libs.pari\n True\n ' coker_I = I.basis_matrix().transpose().kernel().basis_matrix().transpose() return self.domain().ideal((self._matrix * coker_I).kernel().basis_matrix(), given_by_matrix=True)
class FiniteDimensionalAlgebraHomset(RingHomset_generic): '\n Set of morphisms between two finite-dimensional algebras.\n ' @cached_method def zero(self): '\n Construct the zero morphism of ``self``.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([1])])\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: H = Hom(A, B)\n sage: H.zero()\n Morphism from Finite-dimensional algebra of degree 1 over Rational Field to\n Finite-dimensional algebra of degree 2 over Rational Field given by matrix\n [0 0]\n ' from sage.matrix.constructor import matrix return FiniteDimensionalAlgebraMorphism(self, matrix.zero(self.domain().ngens(), self.codomain().ngens()), False, False) def __call__(self, f, check=True, unitary=True): '\n Construct a homomorphism.\n\n .. TODO::\n\n Implement taking generator images and converting them to a matrix.\n\n EXAMPLES::\n\n sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([1])])\n sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1, 0], [0, 1]]),\n ....: Matrix([[0, 1], [0, 0]])])\n sage: H = Hom(A, B)\n sage: H(Matrix([[1, 0]]))\n Morphism from Finite-dimensional algebra of degree 1 over Rational Field to\n Finite-dimensional algebra of degree 2 over Rational Field given by matrix\n [1 0]\n ' if isinstance(f, FiniteDimensionalAlgebraMorphism): if (f.parent() is self): return f if (f.parent() == self): return FiniteDimensionalAlgebraMorphism(self, f._matrix, check, unitary) elif is_Matrix(f): return FiniteDimensionalAlgebraMorphism(self, f, check, unitary) try: from sage.matrix.constructor import Matrix return FiniteDimensionalAlgebraMorphism(self, Matrix(f), check, unitary) except Exception: return RingHomset_generic.__call__(self, f, check)
class FiniteGCAlgebra(CombinatorialFreeModule, Algebra): '\n Finite dimensional graded commutative algebras.\n\n A finite dimensional graded commutative algebra `A` is an integer-graded\n algebra satisfying the super-algebra relation w.r.t. the degree modulo 2.\n More precisely, `A` has a graded ring structure\n\n .. MATH::\n\n A = \\bigoplus_{i=0}^n A_i,\n\n where `n \\in \\NN` is the finite maximal degree, and the multiplication\n satisfies\n\n .. MATH::\n\n A_i \\cdot A_j \\subset \\begin{cases}A_{i+j} & \\text{if $i+j\\leq n$}, \\\\\n 0 & \\text{if $i+j > n$},\\end{cases}\n\n as well as the super-algebra relation\n\n .. MATH::\n\n x y = (-1)^{ij} y x\n\n for all homogeneous elements `x \\in A_i` and `y \\in A_j`.\n\n Such an algebra is multiplicatively generated by a set of single monomials\n `\\{ x_1, \\ldots, x_k \\}`, where each `x_i` is given a certain degree\n `\\mathrm{deg}(x_i)`. To that end, this algebra can be given a vector\n space basis, and the basis vectors are of the form `x_1^{w_1} \\cdots x_n^{\n w_k}`, where `\\sum_{i=1}^k \\mathrm{deg}(x_i) \\, w_i \\leq n` and\n\n .. MATH::\n\n w_i \\in \\begin{cases} \\ZZ_2 & \\text{if $\\mathrm{deg}(x_i)$ is odd}, \\\\\n \\NN & \\text{if $\\mathrm{deg}(x_i)$ is even}. \\end{cases}\n\n Typical examples of finite dimensional graded commutative algebras are\n cohomology rings over finite dimensional CW-complexes.\n\n INPUT:\n\n - ``base`` -- the base field\n - ``names`` -- (optional) names of the generators: a list of\n strings or a single string with the names separated by\n commas. If not specified, the generators are named "x0", "x1",...\n - ``degrees`` -- (optional) a tuple or list specifying the degrees\n of the generators; if omitted, each generator is given degree\n 1, and if both ``names`` and ``degrees`` are omitted, an error is\n raised.\n - ``max_degree`` -- the maximal degree of the graded algebra.\n - ``mul_symbol`` -- (optional) symbol used for multiplication. If omitted,\n the string "*" is used.\n - ``mul_latex_symbol`` -- (optional) latex symbol used for multiplication.\n If omitted, the empty string is used.\n\n EXAMPLES::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1,2,2,3), max_degree=6)\n sage: A\n Graded commutative algebra with generators (\'x\', \'y\', \'z\', \'t\')\n in degrees (1, 2, 2, 3) with maximal degree 6\n sage: t*x + x*t\n 0\n sage: x^2\n 0\n sage: x*t^2\n 0\n sage: x*y^2 + z*t\n x*y^2 + z*t\n\n The generators can be returned with :meth:`algebra_generators`::\n\n sage: F = A.algebra_generators(); F\n Family (x, y, z, t)\n sage: [g.degree() for g in F]\n [1, 2, 2, 3]\n\n We can also return the basis::\n\n sage: list(A.basis())\n [1, x, z, y, t, x*z, x*y, x*t, z^2, y*z, y^2, z*t, y*t, x*z^2, x*y*z, x*y^2]\n\n Depending on the context, the multiplication can be given a different\n symbol::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1,2,6,6), max_degree=10,\n ....: mul_symbol=\'⌣\',\n ....: mul_latex_symbol=r\'\\smile\')\n sage: x*y^2 + x*t\n x⌣y^2 + x⌣t\n sage: latex(x*y^2 - z*x)\n x\\smile y^{2} - x\\smile z\n\n .. NOTE::\n\n Notice, when the argument ``max_degree`` in the global namespace is\n omitted, an instance of the class\n :class:`sage.algebras.commutative_dga.GCAlgebra` is created instead::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, degrees=(1,2,6,6))\n sage: type(A)\n <class \'sage.algebras.commutative_dga.GCAlgebra_with_category\'>\n\n ' @staticmethod def __classcall_private__(cls, base, names=None, degrees=None, max_degree=None, category=None, **kwargs): "\n Normalize the input for the :meth:`__init__` method and the\n unique representation.\n\n INPUT:\n\n - ``base`` -- the base ring of the algebra\n - ``max_degree`` -- the maximal degree of the algebra\n - ``names`` -- the names of the variables; by default, set to ``x1``,\n ``x2``, etc.\n - ``degrees`` -- the degrees of the generators; by default, set to 1\n\n TESTS::\n\n sage: A1 = GradedCommutativeAlgebra(GF(2), 'x,y', (3, 6), max_degree=12)\n sage: A2 = GradedCommutativeAlgebra(GF(2), ['x', 'y'], [3, 6], max_degree=12)\n sage: A1 is A2\n True\n\n " if (max_degree is None): raise TypeError('max_degree must be specified') if (names is None): if (degrees is None): raise ValueError('You must specify names or degrees') else: n = len(degrees) names = tuple(('x{}'.format(i) for i in range(n))) elif isinstance(names, str): names = tuple(names.split(',')) n = len(names) else: n = len(names) names = tuple(names) if (degrees is None): degrees = tuple([1 for _ in range(n)]) else: degrees = tuple(degrees) return super().__classcall__(cls, base=base, names=names, degrees=degrees, max_degree=max_degree, category=category, **kwargs) def __init__(self, base, names, degrees, max_degree, category=None, **kwargs): "\n Construct a commutative graded algebra with finite degree.\n\n TESTS::\n\n sage: A.<x,y,z,t> = GradedCommutativeAlgebra(QQ, max_degree=6)\n sage: TestSuite(A).run()\n sage: A = GradedCommutativeAlgebra(QQ, ('x','y','z'), [2,3,4], max_degree=8)\n sage: TestSuite(A).run()\n sage: A = GradedCommutativeAlgebra(QQ, ('x','y','z','t'), [1,2,3,4], max_degree=10)\n sage: TestSuite(A).run()\n\n " from sage.arith.misc import gcd if (max_degree not in ZZ): raise TypeError('max_degree must be an integer') if (max_degree < max(degrees)): raise ValueError(f'max_degree must not deceed {max(degrees)}') self._names = names self.__ngens = len(self._names) self._degrees = degrees self._max_deg = max_degree self._weighted_vectors = WeightedIntegerVectors(degrees) self._mul_symbol = kwargs.pop('mul_symbol', '*') self._mul_latex_symbol = kwargs.pop('mul_latex_symbol', '') step = gcd(degrees) universe = DisjointUnionEnumeratedSets((self._weighted_vectors.subset(k) for k in range(0, max_degree, step))) base_cat = Algebras(base).WithBasis().Super().Supercommutative().FiniteDimensional() category = base_cat.or_subcategory(category, join=True) indices = ConditionSet(universe, self._valid_index) sorting_key = self._weighted_vectors.grading CombinatorialFreeModule.__init__(self, base, indices, sorting_key=sorting_key, category=category) def _valid_index(self, w): '\n Return whether ``w`` is a valid index; no multiple powers in odd\n degrees.\n\n TESTS::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=8)\n sage: w1 = A._weighted_vectors([1,2,1])\n sage: w2 = A._weighted_vectors([1,2,2])\n sage: A._valid_index(w1)\n True\n sage: A._valid_index(w2)\n False\n\n ' return (not any(((i > 1) for (i, d) in zip(w, self._degrees) if is_odd(d)))) def _repr_(self): '\n Return the string representation of ``self``.\n\n TESTS::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=8)\n sage: A._repr_()\n "Graded commutative algebra with generators (\'x\', \'y\', \'z\') in degrees (1, 2, 3) with maximal degree 8"\n sage: A # indirect doctest\n Graded commutative algebra with generators (\'x\', \'y\', \'z\') in degrees (1, 2, 3) with maximal degree 8\n\n ' desc = f'Graded commutative algebra with generators {self._names} in ' desc += f'degrees {self._degrees} with maximal degree {self._max_deg}' return desc def ngens(self): '\n Return the number of generators of ``self``.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)\n sage: A.ngens()\n 3\n\n ' return self.__ngens @cached_method def product_on_basis(self, w1, w2): '\n Return the product of two indices within the algebra.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)\n sage: z*x\n x*z\n sage: x^3\n 0\n sage: 5*z + 4*z*x\n 5*z + 4*x*z\n\n ::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=5)\n sage: 2*x*y\n 2*x*y\n sage: x^2\n 0\n sage: x*z\n x*z\n sage: z*x\n -x*z\n sage: x*y*z\n 0\n\n TESTS::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)\n sage: weighted_vectors = A._weighted_vectors\n sage: w1 = A._weighted_vectors([1,0,1])\n sage: w2 = A._weighted_vectors([0,0,0])\n sage: A.product_on_basis(w1, w2)\n x*z\n\n ::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=5)\n sage: weighted_vectors = A._weighted_vectors\n sage: w1 = A._weighted_vectors([1,0,0])\n sage: w2 = A._weighted_vectors([0,0,1])\n sage: A.product_on_basis(w1, w2)\n x*z\n sage: A.product_on_basis(w2, w1)\n -x*z\n\n ::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=10)\n sage: weighted_vectors = A._weighted_vectors\n sage: w1 = A._weighted_vectors([1,1,0])\n sage: w2 = A._weighted_vectors([0,1,1])\n sage: A.product_on_basis(w1, w2)\n x*y^2*z\n sage: A.product_on_basis(w2, w1)\n -x*y^2*z\n\n ' grading = self._weighted_vectors.grading deg_left = grading(w1) deg_right = grading(w2) deg_tot = (deg_left + deg_right) if (deg_tot > self._max_deg): return self.zero() w_tot = self._weighted_vectors([sum(w) for w in zip(w1, w2)]) if (not self._valid_index(w_tot)): return self.zero() n = self.__ngens c = 0 for (p, i, d) in zip(reversed(range(n)), reversed(w1), reversed(self._degrees)): if (is_even(d) or (i == 0)): continue for (q, j, b) in zip(range(n), w2, self._degrees): if (q == p): break if ((j == 0) or is_even(b)): continue c += 1 return (((- 1) ** c) * self.monomial(w_tot)) def degree_on_basis(self, i): '\n Return the degree of a homogeneous element with index `i`.\n\n EXAMPLES::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(2,4,6), max_degree=7)\n sage: a.degree()\n 2\n sage: (2*a*b).degree()\n 6\n sage: (a+b).degree()\n Traceback (most recent call last):\n ...\n ValueError: element is not homogeneous\n\n TESTS::\n\n sage: A.<a,b,c> = GradedCommutativeAlgebra(QQ, degrees=(2,4,6), max_degree=7)\n sage: weighted_vectors = A._weighted_vectors\n sage: i = A._weighted_vectors([1,1,0])\n sage: A.degree_on_basis(i)\n 6\n\n ' return self._weighted_vectors.grading(i) def _repr_term(self, w): "\n Return the string representation of basis with index ``w``.\n\n TESTS::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=8)\n sage: w = A._weighted_vectors([1,2,1])\n sage: A._repr_term(w)\n 'x*y^2*z'\n sage: x*y^2*z # indirect doctest\n x*y^2*z\n\n ::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=8, mul_symbol='⌣')\n sage: w = A._weighted_vectors([1,2,1])\n sage: A._repr_term(w)\n 'x⌣y^2⌣z'\n sage: x*y^2*z # indirect doctest\n x⌣y^2⌣z\n\n " if (sum(w) == 0): return '1' terms = [] for i in range(len(w)): if (w[i] == 0): continue elif (w[i] == 1): terms.append(self._names[i]) else: terms.append((self._names[i] + f'^{w[i]}')) return self._mul_symbol.join(terms) def _latex_term(self, w): "\n Return the LaTeX representation of basis with index ``w``.\n\n TESTS::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=8)\n sage: w = A._weighted_vectors([1,2,1])\n sage: A._latex_term(w)\n 'x y^{2} z'\n sage: latex(x*y^2*z) # indirect doctest\n x y^{2} z\n\n ::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=8, mul_latex_symbol=r'\\smile')\n sage: A._latex_term(w)\n 'x\\\\smile y^{2}\\\\smile z'\n sage: latex(x*y^2*z) # indirect doctest\n x\\smile y^{2}\\smile z\n\n " if (sum(w) == 0): return '1' terms = [] for i in range(len(w)): if (w[i] == 0): continue elif (w[i] == 1): terms.append(self._names[i]) else: terms.append((((self._names[i] + '^{') + str(w[i])) + '}')) latex_mul = (self._mul_latex_symbol + ' ') return latex_mul.join(terms) def algebra_generators(self): '\n Return the generators of ``self`` as a\n :class:`sage.sets.family.TrivialFamily`.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)\n sage: A.algebra_generators()\n Family (x, y, z)\n\n ' from sage.sets.family import Family return Family(self.gens()) @cached_method def one_basis(self): '\n Return the index of the one element of ``self``.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)\n sage: ind = A.one_basis(); ind\n [0, 0, 0]\n sage: A.monomial(ind)\n 1\n sage: A.one() # indirect doctest\n 1\n\n ' n = len(self._degrees) return self._weighted_vectors([0 for _ in range(n)]) def gens(self) -> tuple: '\n Return the generators of ``self`` as a tuple.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)\n sage: A.gens()\n (x, y, z)\n ' n = len(self._degrees) zero = [0 for _ in range(n)] indices = [] for k in range(n): ind = list(zero) ind[k] = 1 indices.append(self._weighted_vectors(ind)) return tuple([self.monomial(ind) for ind in indices]) @cached_method def gen(self, i): '\n Return the `i`-th generator of ``self``.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(4,8,2), max_degree=10)\n sage: A.gen(0)\n x\n sage: A.gen(1)\n y\n sage: A.gen(2)\n z\n\n ' return self.gens()[i] def maximal_degree(self): '\n Return the maximal degree of ``self``.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = GradedCommutativeAlgebra(QQ, degrees=(1,2,3), max_degree=8)\n sage: A.maximal_degree()\n 8\n\n ' return self._max_deg max_degree = maximal_degree
class FreeAlgebraFactory(UniqueFactory): '\n A constructor of free algebras.\n\n See :mod:`~sage.algebras.free_algebra` for examples and corner cases.\n\n EXAMPLES::\n\n sage: FreeAlgebra(GF(5),3,\'x\')\n Free Algebra on 3 generators (x0, x1, x2) over Finite Field of size 5\n sage: F.<x,y,z> = FreeAlgebra(GF(5),3)\n sage: (x+y+z)^2\n x^2 + x*y + x*z + y*x + y^2 + y*z + z*x + z*y + z^2\n sage: FreeAlgebra(GF(5),3, \'xx, zba, Y\')\n Free Algebra on 3 generators (xx, zba, Y) over Finite Field of size 5\n sage: FreeAlgebra(GF(5),3, \'abc\')\n Free Algebra on 3 generators (a, b, c) over Finite Field of size 5\n sage: FreeAlgebra(GF(5),1, \'z\')\n Free Algebra on 1 generators (z,) over Finite Field of size 5\n sage: FreeAlgebra(GF(5),1, [\'alpha\'])\n Free Algebra on 1 generators (alpha,) over Finite Field of size 5\n sage: FreeAlgebra(FreeAlgebra(ZZ,1,\'a\'), 2, \'x\')\n Free Algebra on 2 generators (x0, x1) over\n Free Algebra on 1 generators (a,) over Integer Ring\n\n Free algebras are globally unique::\n\n sage: F = FreeAlgebra(ZZ,3,\'x,y,z\')\n sage: G = FreeAlgebra(ZZ,3,\'x,y,z\')\n sage: F is G\n True\n sage: F.<x,y,z> = FreeAlgebra(GF(5),3) # indirect doctest\n sage: F is loads(dumps(F))\n True\n sage: F is FreeAlgebra(GF(5),[\'x\',\'y\',\'z\'])\n True\n sage: copy(F) is F is loads(dumps(F))\n True\n sage: TestSuite(F).run()\n\n By :trac:`7797`, we provide a different implementation of free\n algebras, based on Singular\'s "letterplace rings". Our letterplace\n wrapper allows for choosing positive integral degree weights for the\n generators of the free algebra. However, only (weighted) homogeneous\n elements are supported. Of course, isomorphic algebras in different\n implementations are not identical::\n\n sage: # needs sage.libs.singular\n sage: G = FreeAlgebra(GF(5),[\'x\',\'y\',\'z\'], implementation=\'letterplace\')\n sage: F == G\n False\n sage: G is FreeAlgebra(GF(5),[\'x\',\'y\',\'z\'], implementation=\'letterplace\')\n True\n sage: copy(G) is G is loads(dumps(G))\n True\n sage: TestSuite(G).run()\n\n ::\n\n sage: # needs sage.libs.singular\n sage: H = FreeAlgebra(GF(5), [\'x\',\'y\',\'z\'], implementation=\'letterplace\',\n ....: degrees=[1,2,3])\n sage: F != H != G\n True\n sage: H is FreeAlgebra(GF(5),[\'x\',\'y\',\'z\'], implementation=\'letterplace\',\n ....: degrees=[1,2,3])\n True\n sage: copy(H) is H is loads(dumps(H))\n True\n sage: TestSuite(H).run()\n\n Free algebras commute with their base ring.\n ::\n\n sage: K.<a,b> = FreeAlgebra(QQ,2)\n sage: K.is_commutative()\n False\n sage: L.<c> = FreeAlgebra(K,1)\n sage: L.is_commutative()\n False\n sage: s = a*b^2 * c^3; s\n a*b^2*c^3\n sage: parent(s)\n Free Algebra on 1 generators (c,) over\n Free Algebra on 2 generators (a, b) over Rational Field\n sage: c^3 * a * b^2\n a*b^2*c^3\n ' def create_key(self, base_ring, arg1=None, arg2=None, sparse=None, order=None, names=None, name=None, implementation=None, degrees=None): "\n Create the key under which a free algebra is stored.\n\n TESTS::\n\n sage: FreeAlgebra.create_key(GF(5),['x','y','z'])\n (Finite Field of size 5, ('x', 'y', 'z'))\n sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3)\n (Finite Field of size 5, ('x', 'y', 'z'))\n sage: FreeAlgebra.create_key(GF(5),3,'xyz')\n (Finite Field of size 5, ('x', 'y', 'z'))\n\n sage: # needs sage.libs.singular\n sage: FreeAlgebra.create_key(GF(5),['x','y','z'],\n ....: implementation='letterplace')\n (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,)\n sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3,\n ....: implementation='letterplace')\n (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,)\n sage: FreeAlgebra.create_key(GF(5),3,'xyz',\n ....: implementation='letterplace')\n (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,)\n sage: FreeAlgebra.create_key(GF(5),3,'xyz',\n ....: implementation='letterplace', degrees=[1,2,3])\n ((1, 2, 3), Multivariate Polynomial Ring in x, y, z, x_ over Finite Field of size 5)\n\n " if ((arg1 is None) and (arg2 is None) and (names is None)): if (degrees is None): return (base_ring,) return (tuple(degrees), base_ring) if (implementation == 'letterplace'): if (order is None): order = ('degrevlex' if (degrees is None) else 'deglex') args = [arg for arg in (arg1, arg2) if (arg is not None)] kwds = {'sparse': sparse, 'order': order, 'implementation': 'singular'} if (name is not None): kwds['name'] = name if (names is not None): kwds['names'] = names PolRing = PolynomialRing(base_ring, *args, **kwds) if (degrees is None): return (PolRing,) from sage.rings.polynomial.term_order import TermOrder T = TermOrder(PolRing.term_order(), (PolRing.ngens() + 1)) varnames = list(PolRing.variable_names()) newname = 'x' while (newname in varnames): newname += '_' varnames.append(newname) R = PolynomialRing(PolRing.base(), varnames, sparse=sparse, order=T) return (tuple(degrees), R) from sage.rings.integer import Integer if isinstance(arg1, (Integer, int)): (arg1, arg2) = (arg2, arg1) if (names is not None): arg1 = names elif (name is not None): arg1 = name if (arg2 is None): arg2 = len(arg1) names = normalize_names(arg2, arg1) return (base_ring, names) def create_object(self, version, key): "\n Construct the free algebra that belongs to a unique key.\n\n NOTE:\n\n Of course, that method should not be called directly,\n since it does not use the cache of free algebras.\n\n TESTS::\n\n sage: FreeAlgebra.create_object('4.7.1', (QQ['x','y'],))\n Free Associative Unital Algebra on 2 generators (x, y) over Rational Field\n sage: FreeAlgebra.create_object('4.7.1', (QQ['x','y'],)) is FreeAlgebra(QQ,['x','y'])\n False\n " if (len(key) == 1): from sage.algebras.letterplace.free_algebra_letterplace import FreeAlgebra_letterplace return FreeAlgebra_letterplace(key[0]) if isinstance(key[0], tuple): from sage.algebras.letterplace.free_algebra_letterplace import FreeAlgebra_letterplace return FreeAlgebra_letterplace(key[1], degrees=key[0]) return FreeAlgebra_generic(key[0], len(key[1]), key[1])
def is_FreeAlgebra(x) -> bool: "\n Return True if x is a free algebra; otherwise, return False.\n\n EXAMPLES::\n\n sage: from sage.algebras.free_algebra import is_FreeAlgebra\n sage: is_FreeAlgebra(5)\n False\n sage: is_FreeAlgebra(ZZ)\n False\n sage: is_FreeAlgebra(FreeAlgebra(ZZ,100,'x'))\n True\n sage: is_FreeAlgebra(FreeAlgebra(ZZ,10,'x',implementation='letterplace'))\n True\n sage: is_FreeAlgebra(FreeAlgebra(ZZ,10,'x',implementation='letterplace',\n ....: degrees=list(range(1,11))))\n True\n " return isinstance(x, (FreeAlgebra_generic, FreeAlgebra_letterplace))
class FreeAlgebra_generic(CombinatorialFreeModule, Algebra): "\n The free algebra on `n` generators over a base ring.\n\n INPUT:\n\n - ``R`` -- a ring\n - ``n`` -- an integer\n - ``names`` -- the generator names\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ, 3); F\n Free Algebra on 3 generators (x, y, z) over Rational Field\n sage: mul(F.gens())\n x*y*z\n sage: mul([ F.gen(i%3) for i in range(12) ])\n x*y*z*x*y*z*x*y*z*x*y*z\n sage: mul([ F.gen(i%3) for i in range(12) ]) + mul([ F.gen(i%2) for i in range(12) ])\n x*y*x*y*x*y*x*y*x*y*x*y + x*y*z*x*y*z*x*y*z*x*y*z\n sage: (2 + x*z + x^2)^2 + (x - y)^2\n 4 + 5*x^2 - x*y + 4*x*z - y*x + y^2 + x^4 + x^3*z + x*z*x^2 + x*z*x*z\n\n TESTS:\n\n Free algebras commute with their base ring::\n\n sage: K.<a,b> = FreeAlgebra(QQ)\n sage: K.is_commutative()\n False\n sage: L.<c,d> = FreeAlgebra(K)\n sage: L.is_commutative()\n False\n sage: s = a*b^2 * c^3; s\n a*b^2*c^3\n sage: parent(s)\n Free Algebra on 2 generators (c, d) over Free Algebra on 2 generators (a, b) over Rational Field\n sage: c^3 * a * b^2\n a*b^2*c^3\n\n Two free algebras are considered the same if they have the same\n base ring, number of generators and variable names, and the same\n implementation::\n\n sage: F = FreeAlgebra(QQ,3,'x')\n sage: F == FreeAlgebra(QQ,3,'x')\n True\n sage: F is FreeAlgebra(QQ,3,'x')\n True\n sage: F == FreeAlgebra(ZZ,3,'x')\n False\n sage: F == FreeAlgebra(QQ,4,'x')\n False\n sage: F == FreeAlgebra(QQ,3,'y')\n False\n\n Note that since :trac:`7797` there is a different\n implementation of free algebras. Two corresponding free\n algebras in different implementations are not equal, but there\n is a coercion.\n " Element = FreeAlgebraElement def __init__(self, R, n, names): "\n The free algebra on `n` generators over a base ring.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ, 3); F # indirect doctest\n Free Algebra on 3 generators (x, y, z) over Rational Field\n\n TESTS:\n\n Note that the following is *not* the recommended way to create\n a free algebra::\n\n sage: from sage.algebras.free_algebra import FreeAlgebra_generic\n sage: FreeAlgebra_generic(ZZ, 3, 'abc')\n Free Algebra on 3 generators (a, b, c) over Integer Ring\n " if (R not in Rings()): raise TypeError('argument R must be a ring') self.__ngens = n indices = FreeMonoid(n, names=names) cat = AlgebrasWithBasis(R) CombinatorialFreeModule.__init__(self, R, indices, prefix='F', category=cat) self._assign_names(indices.variable_names()) def one_basis(self): "\n Return the index of the basis element `1`.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(QQ, 2, 'x,y')\n sage: F.one_basis()\n 1\n sage: F.one_basis().parent()\n Free monoid on 2 generators (x, y)\n " return self._indices.one() def is_field(self, proof=True) -> bool: "\n Return ``True`` if this Free Algebra is a field.\n\n This happens only if the\n base ring is a field and there are no generators\n\n EXAMPLES::\n\n sage: A = FreeAlgebra(QQ,0,'')\n sage: A.is_field()\n True\n sage: A = FreeAlgebra(QQ,1,'x')\n sage: A.is_field()\n False\n " if (self.__ngens == 0): return self.base_ring().is_field(proof) return False def is_commutative(self) -> bool: '\n Return ``True`` if this free algebra is commutative.\n\n EXAMPLES::\n\n sage: R.<x> = FreeAlgebra(QQ,1)\n sage: R.is_commutative()\n True\n sage: R.<x,y> = FreeAlgebra(QQ,2)\n sage: R.is_commutative()\n False\n ' return ((self.__ngens <= 1) and self.base_ring().is_commutative()) def _repr_(self) -> str: "\n Text representation of this free algebra.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(QQ,3,'x')\n sage: F # indirect doctest\n Free Algebra on 3 generators (x0, x1, x2) over Rational Field\n sage: F.rename('QQ<<x0,x1,x2>>')\n sage: F #indirect doctest\n QQ<<x0,x1,x2>>\n sage: FreeAlgebra(ZZ,1,['a'])\n Free Algebra on 1 generators (a,) over Integer Ring\n " return 'Free Algebra on {} generators {} over {}'.format(self.__ngens, self.gens(), self.base_ring()) def _latex_(self) -> str: "\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(QQ,3,'x')\n sage: latex(F)\n \\Bold{Q}\\langle x_{0}, x_{1}, x_{2}\\rangle\n sage: F = FreeAlgebra(ZZ['q'], 3, 'a,b,c')\n sage: latex(F)\n \\Bold{Z}[q]\\langle a, b, c\\rangle\n " from sage.misc.latex import latex return '{}\\langle {}\\rangle'.format(latex(self.base_ring()), ', '.join(self.latex_variable_names())) def _element_constructor_(self, x): "\n Convert ``x`` into ``self``.\n\n EXAMPLES::\n\n sage: R.<x,y> = FreeAlgebra(QQ,2)\n sage: R(3) # indirect doctest\n 3\n\n TESTS::\n\n sage: # needs sage.libs.singular\n sage: F.<x,y,z> = FreeAlgebra(GF(5),3)\n sage: L.<x,y,z> = FreeAlgebra(ZZ,3,implementation='letterplace')\n sage: F(x) # indirect doctest\n x\n sage: F.1*L.2\n y*z\n sage: (F.1*L.2).parent() is F\n True\n\n ::\n\n sage: # needs sage.libs.singular sage.rings.finite_rings\n sage: K.<z> = GF(25)\n sage: F.<a,b,c> = FreeAlgebra(K,3)\n sage: L.<a,b,c> = FreeAlgebra(K,3, implementation='letterplace')\n sage: F.1 + (z+1)*L.2\n b + (z+1)*c\n\n Check that :trac:`15169` is fixed::\n\n sage: A.<x> = FreeAlgebra(CC)\n sage: A(2)\n 2.00000000000000\n\n We check that the string coercions work correctly over\n inexact fields::\n\n sage: F.<x,y> = FreeAlgebra(CC)\n sage: F('2')\n 2.00000000000000\n sage: F('x')\n 1.00000000000000*x\n\n Check that it also converts factorizations::\n\n sage: f = Factorization([(x,2),(y,3)]); f\n 1.00000000000000*x^2 * 1.00000000000000*y^3\n sage: F(f)\n 1.00000000000000*x^2*y^3\n " if isinstance(x, FreeAlgebraElement): P = x.parent() if (P is self): return x if (P is not self.base_ring()): return self.element_class(self, x) elif hasattr(x, 'letterplace_polynomial'): P = x.parent() if self.has_coerce_map_from(P): ngens = P.ngens() M = self._indices def exp_to_monomial(T): out = [] for i in range(len(T)): if T[i]: out.append(((i % ngens), T[i])) return M(out) return self.element_class(self, {exp_to_monomial(T): c for (T, c) in x.letterplace_polynomial().dict().items()}) if isinstance(x, str): from sage.misc.sage_eval import sage_eval G = self.gens() d = {str(v): G[i] for (i, v) in enumerate(self.variable_names())} return self(sage_eval(x, locals=d)) R = self.base_ring() if (isinstance(x, FreeMonoidElement) and (x.parent() is self._indices)): return self.element_class(self, {x: R.one()}) if (isinstance(x, PBWBasisOfFreeAlgebra.Element) and self.has_coerce_map_from(x.parent()._alg)): return self(x.parent().expansion(x)) from sage.structure.factorization import Factorization if isinstance(x, Factorization): return self.prod(((f ** i) for (f, i) in x)) x = R(x) if (x == 0): return self.element_class(self, {}) return self.element_class(self, {self.one_basis(): x}) def _coerce_map_from_(self, R): "\n Return ``True`` if there is a coercion from ``R`` into ``self`` and\n ``False`` otherwise. The things that coerce into ``self`` are:\n\n - This free algebra.\n\n - Anything with a coercion into ``self.monoid()``.\n\n - Free algebras in the same variables over a base with a coercion\n map into ``self.base_ring()``.\n\n - The underlying monoid.\n\n - The PBW basis of ``self``.\n\n - Anything with a coercion into ``self.base_ring()``.\n\n TESTS::\n\n sage: F = FreeAlgebra(ZZ, 3, 'x,y,z')\n sage: G = FreeAlgebra(QQ, 3, 'x,y,z')\n sage: H = FreeAlgebra(ZZ, 1, 'y')\n sage: F._coerce_map_from_(G)\n False\n sage: G._coerce_map_from_(F)\n True\n sage: F._coerce_map_from_(H)\n False\n sage: F._coerce_map_from_(QQ)\n False\n sage: G._coerce_map_from_(QQ)\n True\n sage: F._coerce_map_from_(G.monoid())\n True\n sage: F._coerce_map_from_(F.pbw_basis())\n True\n sage: F.has_coerce_map_from(PolynomialRing(ZZ, 3, 'x,y,z'))\n False\n\n sage: # needs sage.rings.finite_rings\n sage: K.<z> = GF(25)\n sage: F.<a,b,c> = FreeAlgebra(K,3)\n sage: F._coerce_map_from_(ZZ)\n True\n sage: F._coerce_map_from_(QQ)\n False\n sage: F._coerce_map_from_(F.monoid())\n True\n sage: F._coerce_map_from_(F.pbw_basis())\n True\n sage: G = FreeAlgebra(ZZ, 3, 'a,b,c')\n sage: F._coerce_map_from_(G)\n True\n sage: G._coerce_map_from_(F)\n False\n sage: L.<a,b,c> = FreeAlgebra(K,3, implementation='letterplace') # needs sage.libs.singular\n sage: F.1 + (z+1) * L.2 # needs sage.libs.singular\n b + (z+1)*c\n " if self._indices.has_coerce_map_from(R): return True if is_FreeAlgebra(R): if (R.variable_names() == self.variable_names()): return self.base_ring().has_coerce_map_from(R.base_ring()) if isinstance(R, PBWBasisOfFreeAlgebra): return self.has_coerce_map_from(R._alg) return self.base_ring().has_coerce_map_from(R) def gen(self, i): "\n The ``i``-th generator of the algebra.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(ZZ,3,'x,y,z')\n sage: F.gen(0)\n x\n " if ((i < 0) or (not (i < self.__ngens))): raise IndexError('argument i (= {}) must be between 0 and {}'.format(i, (self.__ngens - 1))) R = self.base_ring() F = self._indices return self.element_class(self, {F.gen(i): R.one()}) @cached_method def algebra_generators(self): "\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(ZZ,3,'x,y,z')\n sage: F.algebra_generators()\n Finite family {'x': x, 'y': y, 'z': z}\n " ret = {} for i in range(self.__ngens): x = self.gen(i) ret[str(x)] = x from sage.sets.family import Family return Family(self.variable_names(), (lambda i: ret[i])) @cached_method def gens(self): "\n Return the generators of ``self``.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(ZZ,3,'x,y,z')\n sage: F.gens()\n (x, y, z)\n " return tuple((self.gen(i) for i in range(self.__ngens))) def product_on_basis(self, x, y): "\n Return the product of the basis elements indexed by ``x`` and ``y``.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(ZZ,3,'x,y,z')\n sage: I = F.basis().keys()\n sage: x,y,z = I.gens()\n sage: F.product_on_basis(x*y, z*y)\n x*y*z*y\n " return self.monomial((x * y)) def quotient(self, mons, mats=None, names=None, **args): "\n Return a quotient algebra.\n\n The quotient algebra is defined via the action of a free algebra\n `A` on a (finitely generated) free module. The input for the quotient\n algebra is a list of monomials (in the underlying monoid for `A`)\n which form a free basis for the module of `A`, and a list of\n matrices, which give the action of the free generators of `A` on this\n monomial basis.\n\n EXAMPLES:\n\n Here is the quaternion algebra defined in terms of three generators::\n\n sage: n = 3\n sage: A = FreeAlgebra(QQ,n,'i')\n sage: F = A.monoid()\n sage: i, j, k = F.gens()\n sage: mons = [ F(1), i, j, k ]\n sage: M = MatrixSpace(QQ,4)\n sage: mats = [M([0,1,0,0, -1,0,0,0, 0,0,0,-1, 0,0,1,0]),\n ....: M([0,0,1,0, 0,0,0,1, -1,0,0,0, 0,-1,0,0]),\n ....: M([0,0,0,1, 0,0,-1,0, 0,1,0,0, -1,0,0,0]) ]\n sage: H.<i,j,k> = A.quotient(mons, mats); H\n Free algebra quotient on 3 generators ('i', 'j', 'k') and dimension 4\n over Rational Field\n " if (mats is None): return super().quotient(mons, names) from . import free_algebra_quotient return free_algebra_quotient.FreeAlgebraQuotient(self, mons, mats, names) quo = quotient def ngens(self): "\n The number of generators of the algebra.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(ZZ,3,'x,y,z')\n sage: F.ngens()\n 3\n " return self.__ngens def monoid(self): "\n The free monoid of generators of the algebra.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(ZZ,3,'x,y,z')\n sage: F.monoid()\n Free monoid on 3 generators (x, y, z)\n " return self._indices def g_algebra(self, relations, names=None, order='degrevlex', check=True): "\n The `G`-Algebra derived from this algebra by relations.\n\n By default is assumed, that two variables commute.\n\n .. TODO::\n\n - Coercion doesn't work yet, there is some cheating about assumptions\n - The optional argument ``check`` controls checking the degeneracy\n conditions. Furthermore, the default values interfere with\n non-degeneracy conditions.\n\n EXAMPLES::\n\n sage: # needs sage.libs.singular\n sage: A.<x,y,z> = FreeAlgebra(QQ,3)\n sage: G = A.g_algebra({y*x: -x*y})\n sage: (x,y,z) = G.gens()\n sage: x*y\n x*y\n sage: y*x\n -x*y\n sage: z*x\n x*z\n sage: (x,y,z) = A.gens()\n sage: G = A.g_algebra({y*x: -x*y + 1})\n sage: (x,y,z) = G.gens()\n sage: y*x\n -x*y + 1\n sage: (x,y,z) = A.gens()\n sage: G = A.g_algebra({y*x: -x*y + z})\n sage: (x,y,z) = G.gens()\n sage: y*x\n -x*y + z\n\n TESTS::\n\n sage: S = FractionField(QQ['t'])\n sage: t = S.gen()\n sage: F.<x,y> = FreeAlgebra(S)\n sage: K = F.g_algebra({y*x:-x*y+1+y})\n sage: x,y = K.gens()\n sage: 1+t*y*x\n (-t)*x*y + t*y + (t + 1)\n " from sage.matrix.constructor import Matrix base_ring = self.base_ring() polynomial_ring = PolynomialRing(base_ring, self.gens()) n = self.__ngens cmat = Matrix(base_ring, n) dmat = Matrix(polynomial_ring, n) for i in range(n): for j in range((i + 1), n): cmat[(i, j)] = 1 for (to_commute, commuted) in relations.items(): assert isinstance(to_commute, FreeAlgebraElement), to_commute assert isinstance(commuted, FreeAlgebraElement), commuted ((v1, e1), (v2, e2)) = next(iter(to_commute))[0] assert (e1 == 1) assert (e2 == 1) assert (v1 > v2) c_coef = None d_poly = None reverse_monomial = (v2 * v1) for (m, c) in commuted: if (m == reverse_monomial): c_coef = c d_poly = (commuted - (c * self.monomial(m))) break assert (c_coef is not None), m v2_ind = self.gens().index(v2) v1_ind = self.gens().index(v1) cmat[(v2_ind, v1_ind)] = c_coef if d_poly: dmat[(v2_ind, v1_ind)] = polynomial_ring(d_poly) from sage.rings.polynomial.plural import g_Algebra return g_Algebra(base_ring, cmat, dmat, names=(names or self.variable_names()), order=order, check=check) def poincare_birkhoff_witt_basis(self): '\n Return the Poincaré-Birkhoff-Witt (PBW) basis of ``self``.\n\n EXAMPLES::\n\n sage: F.<x,y> = FreeAlgebra(QQ, 2)\n sage: F.poincare_birkhoff_witt_basis()\n The Poincare-Birkhoff-Witt basis of Free Algebra on 2 generators (x, y) over Rational Field\n ' return PBWBasisOfFreeAlgebra(self) pbw_basis = poincare_birkhoff_witt_basis def pbw_element(self, elt): '\n Return the element ``elt`` in the Poincaré-Birkhoff-Witt basis.\n\n EXAMPLES::\n\n sage: F.<x,y> = FreeAlgebra(QQ, 2)\n sage: F.pbw_element(x*y - y*x + 2)\n 2*PBW[1] + PBW[x*y]\n sage: F.pbw_element(F.one())\n PBW[1]\n sage: F.pbw_element(x*y*x + x^3*y)\n PBW[x*y]*PBW[x] + PBW[y]*PBW[x]^2 + PBW[x^3*y]\n + 3*PBW[x^2*y]*PBW[x] + 3*PBW[x*y]*PBW[x]^2 + PBW[y]*PBW[x]^3\n ' PBW = self.pbw_basis() if (elt == self.zero()): return PBW.zero() l = {} while elt: lst = list(elt) support = [i[0].to_word() for i in lst] min_elt = support[0] for word in support[1:(len(support) - 1)]: if min_elt.lex_less(word): min_elt = word coeff = lst[support.index(min_elt)][1] min_elt = min_elt.to_monoid_element() l[min_elt] = (l.get(min_elt, 0) + coeff) elt = (elt - (coeff * self.lie_polynomial(min_elt))) return PBW.sum_of_terms([(k, v) for (k, v) in l.items() if (v != 0)], distinct=True) def lie_polynomial(self, w): "\n Return the Lie polynomial associated to the Lyndon word ``w``. If\n ``w`` is not Lyndon, then return the product of Lie polynomials of\n the Lyndon factorization of ``w``.\n\n Given a Lyndon word `w`, the Lie polynomial `L_w` is defined\n recursively by `L_w = [L_u, L_v]`, where `w = uv` is the\n :meth:`standard factorization\n <sage.combinat.words.finite_word.FiniteWord_class.standard_factorization>`\n of `w`, and `L_w = w` when `w` is a single letter.\n\n INPUT:\n\n - ``w`` -- a word or an element of the free monoid\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(QQ, 3, 'x,y,z')\n sage: M.<x,y,z> = FreeMonoid(3)\n sage: F.lie_polynomial(x*y)\n x*y - y*x\n sage: F.lie_polynomial(y*x)\n y*x\n sage: F.lie_polynomial(x^2*y*x)\n x^2*y*x - 2*x*y*x^2 + y*x^3\n sage: F.lie_polynomial(y*z*x*z*x*z)\n y*z*x*z*x*z - y*z*x*z^2*x - y*z^2*x^2*z + y*z^2*x*z*x\n - z*y*x*z*x*z + z*y*x*z^2*x + z*y*z*x^2*z - z*y*z*x*z*x\n\n TESTS:\n\n We test some corner cases and alternative inputs::\n\n sage: F = FreeAlgebra(QQ, 3, 'x,y,z')\n sage: M.<x,y,z> = FreeMonoid(3)\n sage: F.lie_polynomial(Word('xy'))\n x*y - y*x\n sage: F.lie_polynomial('xy')\n x*y - y*x\n sage: F.lie_polynomial(M.one())\n 1\n sage: F.lie_polynomial(Word([]))\n 1\n sage: F.lie_polynomial('')\n 1\n\n We check that :trac:`22251` is fixed::\n\n sage: F.lie_polynomial(x*y*z)\n x*y*z - x*z*y - y*z*x + z*y*x\n " if (not w): return self.one() M = self._indices if (len(w) == 1): return self(M(w)) ret = self.one() for factor in Word(w).lyndon_factorization(): if (len(factor) == 1): ret = (ret * self(M(factor))) continue (x, y) = factor.standard_factorization() x = self.lie_polynomial(M(x)) y = self.lie_polynomial(M(y)) ret = (ret * ((x * y) - (y * x))) return ret
class PBWBasisOfFreeAlgebra(CombinatorialFreeModule): "\n The Poincaré-Birkhoff-Witt basis of the free algebra.\n\n EXAMPLES::\n\n sage: F.<x,y> = FreeAlgebra(QQ, 2)\n sage: PBW = F.pbw_basis()\n sage: px, py = PBW.gens()\n sage: px * py\n PBW[x*y] + PBW[y]*PBW[x]\n sage: py * px\n PBW[y]*PBW[x]\n sage: px * py^3 * px - 2*px * py\n -2*PBW[x*y] - 2*PBW[y]*PBW[x] + PBW[x*y^3]*PBW[x]\n + 3*PBW[y]*PBW[x*y^2]*PBW[x] + 3*PBW[y]^2*PBW[x*y]*PBW[x]\n + PBW[y]^3*PBW[x]^2\n\n We can convert between the two bases::\n\n sage: p = PBW(x*y - y*x + 2); p\n 2*PBW[1] + PBW[x*y]\n sage: F(p)\n 2 + x*y - y*x\n sage: f = F.pbw_element(x*y*x + x^3*y + x + 3)\n sage: F(PBW(f)) == f\n True\n sage: p = px*py + py^4*px^2\n sage: F(p)\n x*y + y^4*x^2\n sage: PBW(F(p)) == p\n True\n\n Note that multiplication in the PBW basis agrees with multiplication\n as monomials::\n\n sage: F(px * py^3 * px - 2*px * py) == x*y^3*x - 2*x*y\n True\n\n We verify Examples 1 and 2 in [MR1989]_::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: PBW = F.pbw_basis()\n sage: PBW(x*y*z)\n PBW[x*y*z] + PBW[x*z*y] + PBW[y]*PBW[x*z] + PBW[y*z]*PBW[x]\n + PBW[z]*PBW[x*y] + PBW[z]*PBW[y]*PBW[x]\n sage: PBW(x*y*y*x)\n PBW[x*y^2]*PBW[x] + 2*PBW[y]*PBW[x*y]*PBW[x] + PBW[y]^2*PBW[x]^2\n\n TESTS:\n\n Check that going between the two bases is the identity::\n\n sage: F = FreeAlgebra(QQ, 2, 'x,y')\n sage: PBW = F.pbw_basis()\n sage: M = F.monoid()\n sage: L = [j.to_monoid_element() for i in range(6) for j in Words('xy', i)]\n sage: all(PBW(F(PBW(m))) == PBW(m) for m in L)\n True\n sage: all(F(PBW(F(m))) == F(m) for m in L)\n True\n " @staticmethod def __classcall_private__(cls, R, n=None, names=None): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: from sage.algebras.free_algebra import PBWBasisOfFreeAlgebra\n sage: PBW1 = FreeAlgebra(QQ, 2, 'x,y').pbw_basis()\n sage: PBW2.<x,y> = PBWBasisOfFreeAlgebra(QQ)\n sage: PBW3 = PBWBasisOfFreeAlgebra(QQ, 2, ['x','y'])\n sage: PBW1 is PBW2 and PBW2 is PBW3\n True\n " if ((n is None) and (names is None)): if (not isinstance(R, FreeAlgebra_generic)): raise ValueError('{} is not a free algebra'.format(R)) alg = R else: if (n is None): n = len(names) alg = FreeAlgebra(R, n, names) return super().__classcall__(cls, alg) def __init__(self, alg): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: PBW = FreeAlgebra(QQ, 2, 'x,y').pbw_basis()\n sage: TestSuite(PBW).run()\n " R = alg.base_ring() self._alg = alg category = AlgebrasWithBasis(R) CombinatorialFreeModule.__init__(self, R, alg.monoid(), prefix='PBW', category=category) self._assign_names(alg.variable_names()) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: FreeAlgebra(QQ, 2, 'x,y').pbw_basis()\n The Poincare-Birkhoff-Witt basis of Free Algebra on 2 generators (x, y) over Rational Field\n " return 'The Poincare-Birkhoff-Witt basis of {}'.format(self._alg) def _repr_term(self, w): "\n Return a representation of term indexed by ``w``.\n\n EXAMPLES::\n\n sage: PBW = FreeAlgebra(QQ, 2, 'x,y').pbw_basis()\n sage: x,y = PBW.gens()\n sage: x*y # indirect doctest\n PBW[x*y] + PBW[y]*PBW[x]\n sage: y*x\n PBW[y]*PBW[x]\n sage: x^3\n PBW[x]^3\n sage: PBW.one()\n PBW[1]\n sage: 3*PBW.one()\n 3*PBW[1]\n " if (len(w) == 0): return super()._repr_term(w) ret = '' p = 1 cur = None for x in w.to_word().lyndon_factorization(): if (x == cur): p += 1 else: if (len(ret) != 0): if (p != 1): ret += '^{}'.format(p) ret += '*' ret += super()._repr_term(x.to_monoid_element()) cur = x p = 1 if (p != 1): ret += '^{}'.format(p) return ret def _element_constructor_(self, x): '\n Convert ``x`` into ``self``.\n\n EXAMPLES::\n\n sage: F.<x,y> = FreeAlgebra(QQ, 2)\n sage: R = F.pbw_basis()\n sage: R(3)\n 3*PBW[1]\n sage: R(x*y)\n PBW[x*y] + PBW[y]*PBW[x]\n ' if isinstance(x, FreeAlgebraElement): return self._alg.pbw_element(self._alg(x)) return CombinatorialFreeModule._element_constructor_(self, x) def _coerce_map_from_(self, R): "\n Return ``True`` if there is a coercion from ``R`` into ``self`` and\n ``False`` otherwise. The things that coerce into ``self`` are:\n\n - Anything that coerces into the associated free algebra of ``self``\n\n TESTS::\n\n sage: F = FreeAlgebra(ZZ, 3, 'x,y,z').pbw_basis()\n sage: G = FreeAlgebra(QQ, 3, 'x,y,z').pbw_basis()\n sage: H = FreeAlgebra(ZZ, 1, 'y').pbw_basis()\n sage: F._coerce_map_from_(G)\n False\n sage: G._coerce_map_from_(F)\n True\n sage: F._coerce_map_from_(H)\n False\n sage: F._coerce_map_from_(QQ)\n False\n sage: G._coerce_map_from_(QQ)\n True\n sage: F._coerce_map_from_(G._alg.monoid())\n True\n sage: F.has_coerce_map_from(PolynomialRing(ZZ, 3, 'x,y,z'))\n False\n sage: F.has_coerce_map_from(FreeAlgebra(ZZ, 3, 'x,y,z'))\n True\n " return self._alg.has_coerce_map_from(R) def one_basis(self): "\n Return the index of the basis element for `1`.\n\n EXAMPLES::\n\n sage: PBW = FreeAlgebra(QQ, 2, 'x,y').pbw_basis()\n sage: PBW.one_basis()\n 1\n sage: PBW.one_basis().parent()\n Free monoid on 2 generators (x, y)\n " return self._indices.one() def algebra_generators(self): "\n Return the generators of ``self`` as an algebra.\n\n EXAMPLES::\n\n sage: PBW = FreeAlgebra(QQ, 2, 'x,y').pbw_basis()\n sage: gens = PBW.algebra_generators(); gens\n (PBW[x], PBW[y])\n sage: all(g.parent() is PBW for g in gens)\n True\n " return tuple((self.monomial(x) for x in self._indices.gens())) gens = algebra_generators def gen(self, i): "\n Return the ``i``-th generator of ``self``.\n\n EXAMPLES::\n\n sage: PBW = FreeAlgebra(QQ, 2, 'x,y').pbw_basis()\n sage: PBW.gen(0)\n PBW[x]\n sage: PBW.gen(1)\n PBW[y]\n " return self.algebra_generators()[i] def free_algebra(self): "\n Return the associated free algebra of ``self``.\n\n EXAMPLES::\n\n sage: PBW = FreeAlgebra(QQ, 2, 'x,y').pbw_basis()\n sage: PBW.free_algebra()\n Free Algebra on 2 generators (x, y) over Rational Field\n " return self._alg def product(self, u, v): "\n Return the product of two elements ``u`` and ``v``.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(QQ, 2, 'x,y')\n sage: PBW = F.pbw_basis()\n sage: x, y = PBW.gens()\n sage: PBW.product(x, y)\n PBW[x*y] + PBW[y]*PBW[x]\n sage: PBW.product(y, x)\n PBW[y]*PBW[x]\n sage: PBW.product(y^2*x, x*y*x)\n PBW[y]^2*PBW[x^2*y]*PBW[x] + 2*PBW[y]^2*PBW[x*y]*PBW[x]^2 + PBW[y]^3*PBW[x]^3\n\n TESTS:\n\n Check that multiplication agrees with the multiplication in the\n free algebra::\n\n sage: F = FreeAlgebra(QQ, 2, 'x,y')\n sage: PBW = F.pbw_basis()\n sage: x, y = PBW.gens()\n sage: F(x*y)\n x*y\n sage: F(x*y*x)\n x*y*x\n sage: PBW(F(x)*F(y)*F(x)) == x*y*x\n True\n " return self((self.expansion(u) * self.expansion(v))) def expansion(self, t): "\n Return the expansion of the element ``t`` of the Poincaré-Birkhoff-Witt\n basis in the monomials of the free algebra.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(QQ, 2, 'x,y')\n sage: PBW = F.pbw_basis()\n sage: x,y = F.monoid().gens()\n sage: PBW.expansion(PBW(x*y))\n x*y - y*x\n sage: PBW.expansion(PBW.one())\n 1\n sage: PBW.expansion(PBW(x*y*x) + 2*PBW(x) + 3)\n 3 + 2*x + x*y*x - y*x^2\n\n TESTS:\n\n Check that we have the correct parent::\n\n sage: PBW.expansion(PBW(x*y)).parent() is F\n True\n sage: PBW.expansion(PBW.one()).parent() is F\n True\n " return sum([(i[1] * self._alg.lie_polynomial(i[0])) for i in list(t)], self._alg.zero()) class Element(CombinatorialFreeModule.Element): def expand(self): "\n Expand ``self`` in the monomials of the free algebra.\n\n EXAMPLES::\n\n sage: F = FreeAlgebra(QQ, 2, 'x,y')\n sage: PBW = F.pbw_basis()\n sage: x,y = F.monoid().gens()\n sage: f = PBW(x^2*y) + PBW(x) + PBW(y^4*x)\n sage: f.expand()\n x + x^2*y - 2*x*y*x + y*x^2 + y^4*x\n " return self.parent().expansion(self)
class FreeAlgebraElement(IndexedFreeModuleElement, AlgebraElement): '\n A free algebra element.\n\n TESTS:\n\n The ordering is inherited from ``IndexedFreeModuleElement``::\n\n sage: R.<x,y> = FreeAlgebra(QQ,2)\n sage: x < y\n True\n sage: x * y < y * x\n True\n sage: y * x < x * y\n False\n ' def __init__(self, A, x): '\n Create the element ``x`` of the FreeAlgebra ``A``.\n\n TESTS::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ, 3)\n sage: elt = x^3 * y - z^2*x\n sage: TestSuite(elt).run()\n ' if isinstance(x, FreeAlgebraElement): x = x._monomial_coefficients R = A.base_ring() if isinstance(x, AlgebraElement): x = {A.monoid()(1): R(x)} elif isinstance(x, FreeMonoidElement): x = {x: R(1)} elif True: x = {A.monoid()(e1): R(e2) for (e1, e2) in x.items()} else: raise TypeError('argument x (= {}) is of the wrong type'.format(x)) IndexedFreeModuleElement.__init__(self, A, x) def _repr_(self): "\n Return string representation of self.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = FreeAlgebra(ZZ,3)\n sage: repr(-x+3*y*z) # indirect doctest\n '-x + 3*y*z'\n\n Github issue :trac:`11068` enables the use of local variable names::\n\n sage: from sage.structure.parent_gens import localvars\n sage: with localvars(A, ['a','b','c']):\n ....: print(-x+3*y*z)\n -a + 3*b*c\n\n " v = sorted(self._monomial_coefficients.items()) P = self.parent() M = P.monoid() from sage.structure.parent_gens import localvars with localvars(M, P.variable_names(), normalize=False): x = repr_lincomb(v, strip_one=True) return x def _latex_(self): "\n Return latex representation of self.\n\n EXAMPLES::\n\n sage: A.<x,y,z>=FreeAlgebra(ZZ,3)\n sage: latex(-x+3*y^20*z) # indirect doctest\n -x + 3 y^{20}z\n sage: alpha,beta,gamma=FreeAlgebra(ZZ,3,'alpha,beta,gamma').gens()\n sage: latex(alpha-beta)\n \\alpha - \\beta\n " v = sorted(self._monomial_coefficients.items()) return repr_lincomb(v, strip_one=True, is_latex=True) def __call__(self, *x, **kwds): '\n EXAMPLES::\n\n sage: A.<x,y,z>=FreeAlgebra(ZZ,3)\n sage: (x+3*y).subs(x=1,y=2,z=14)\n 7\n sage: (2*x+y).subs({x:1,y:z})\n 2 + z\n sage: f=x+3*y+z\n sage: f(1,2,1/2)\n 15/2\n sage: f(1,2)\n Traceback (most recent call last):\n ...\n ValueError: must specify as many values as generators in parent\n\n AUTHORS:\n\n - Joel B. Mohler (2007-10-27)\n ' if (kwds and x): raise ValueError('must not specify both a keyword and positional argument') if kwds: p = self.parent() def extract_from(kwds, g): for x in g: try: return kwds[x] except KeyError: pass return None x = [extract_from(kwds, (p.gen(i), p.variable_name(i))) for i in range(p.ngens())] elif isinstance(x[0], tuple): x = x[0] if (len(x) != self.parent().ngens()): raise ValueError('must specify as many values as generators in parent') result = None for (m, c) in self._monomial_coefficients.items(): if (result is None): result = (c * m(x)) else: result += (c * m(x)) if (result is None): return self.parent().zero() return result def _mul_(self, y): '\n Return the product of ``self`` and ``y`` (another free algebra\n element with the same parent).\n\n EXAMPLES::\n\n sage: A.<x,y,z> = FreeAlgebra(ZZ,3)\n sage: (x+y+x*y)*(x+y+1)\n x + y + x^2 + 2*x*y + y*x + y^2 + x*y*x + x*y^2\n ' A = self.parent() z_elt = {} for (mx, cx) in self: for (my, cy) in y: key = (mx * my) if (key in z_elt): z_elt[key] += (cx * cy) else: z_elt[key] = (cx * cy) if (not z_elt[key]): del z_elt[key] return A._from_dict(z_elt) def _acted_upon_(self, scalar, self_on_left=False): '\n Return the action of a scalar on ``self``.\n\n EXAMPLES::\n\n sage: R.<x,y> = FreeAlgebra(QQ,2)\n sage: f = Factorization([(x,2),(y,3)]); f\n x^2 * y^3\n sage: x * f\n x^3 * y^3\n sage: f * x\n x^2 * y^3 * x\n ' from sage.structure.factorization import Factorization if isinstance(scalar, Factorization): if self_on_left: return (Factorization([(self, 1)]) * scalar) return (scalar * Factorization([(self, 1)])) return super()._acted_upon_(scalar, self_on_left) def variables(self): '\n Return the variables used in ``self``.\n\n EXAMPLES::\n\n sage: A.<x,y,z> = FreeAlgebra(ZZ,3)\n sage: elt = x + x*y + x^3*y\n sage: elt.variables()\n [x, y]\n sage: elt = x + x^2 - x^4\n sage: elt.variables()\n [x]\n sage: elt = x + z*y + z*x\n sage: elt.variables()\n [x, y, z]\n ' v = set() for s in self._monomial_coefficients: for (var, _) in s: v.add(var) A = self.parent() return sorted(map(A, v)) def to_pbw_basis(self): '\n Return ``self`` in the Poincaré-Birkhoff-Witt (PBW) basis.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(ZZ, 3)\n sage: p = x^2*y + 3*y*x + 2\n sage: p.to_pbw_basis()\n 2*PBW[1] + 3*PBW[y]*PBW[x] + PBW[x^2*y]\n + 2*PBW[x*y]*PBW[x] + PBW[y]*PBW[x]^2\n ' return self.parent().pbw_element(self)
class FreeAlgebraQuotient(UniqueRepresentation, Algebra): @staticmethod def __classcall__(cls, A, mons, mats, names): '\n Used to support unique representation.\n\n EXAMPLES::\n\n sage: H = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0] # indirect doctest\n sage: H1 = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0]\n sage: H is H1\n True\n ' new_mats = [] for M in mats: M = M.parent()(M) M.set_immutable() new_mats.append(M) return super().__classcall__(cls, A, tuple(mons), tuple(new_mats), tuple(names)) Element = FreeAlgebraQuotientElement def __init__(self, A, mons, mats, names): "\n Return a quotient algebra defined via the action of a free algebra\n A on a (finitely generated) free module.\n\n The input for the quotient algebra is a list of monomials (in\n the underlying monoid for A) which form a free basis for the\n module of A, and a list of matrices, which give the action of\n the free generators of A on this monomial basis.\n\n EXAMPLES:\n\n Quaternion algebra defined in terms of three generators::\n\n sage: n = 3\n sage: A = FreeAlgebra(QQ,n,'i')\n sage: F = A.monoid()\n sage: i, j, k = F.gens()\n sage: mons = [F(1), i, j, k]\n sage: M = MatrixSpace(QQ,4)\n sage: mats = [M([0,1,0,0, -1,0,0,0, 0,0,0,-1, 0,0,1,0]),\n ....: M([0,0,1,0, 0,0,0,1, -1,0,0,0, 0,-1,0,0]),\n ....: M([0,0,0,1, 0,0,-1,0, 0,1,0,0, -1,0,0,0]) ]\n sage: H3.<i,j,k> = FreeAlgebraQuotient(A,mons,mats)\n sage: x = 1 + i + j + k\n sage: x\n 1 + i + j + k\n sage: x**128\n -170141183460469231731687303715884105728\n + 170141183460469231731687303715884105728*i\n + 170141183460469231731687303715884105728*j\n + 170141183460469231731687303715884105728*k\n\n Same algebra defined in terms of two generators, with some penalty\n on already slow arithmetic.\n\n ::\n\n sage: n = 2\n sage: A = FreeAlgebra(QQ,n,'x')\n sage: F = A.monoid()\n sage: i, j = F.gens()\n sage: mons = [ F(1), i, j, i*j ]\n sage: r = len(mons)\n sage: M = MatrixSpace(QQ,r)\n sage: mats = [M([0,1,0,0, -1,0,0,0, 0,0,0,-1, 0,0,1,0]),\n ....: M([0,0,1,0, 0,0,0,1, -1,0,0,0, 0,-1,0,0]) ]\n sage: H2.<i,j> = A.quotient(mons,mats)\n sage: k = i*j\n sage: x = 1 + i + j + k\n sage: x\n 1 + i + j + i*j\n sage: x**128\n -170141183460469231731687303715884105728\n + 170141183460469231731687303715884105728*i\n + 170141183460469231731687303715884105728*j\n + 170141183460469231731687303715884105728*i*j\n\n TESTS::\n\n sage: TestSuite(H2).run()\n\n " if (not is_FreeAlgebra(A)): raise TypeError('argument A must be an algebra') R = A.base_ring() n = A.ngens() assert (n == len(mats)) self.__free_algebra = A self.__ngens = n self.__dim = len(mons) self.__module = FreeModule(R, self.__dim) self.__matrix_action = mats self.__monomial_basis = mons Algebra.__init__(self, R, names, normalize=True) def _element_constructor_(self, x): '\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: H(i) is i\n True\n sage: a = H._element_constructor_(1); a\n 1\n sage: a in H\n True\n sage: a = H._element_constructor_([1,2,3,4]); a\n 1 + 2*i + 3*j + 4*k\n ' return self.element_class(self, x) def _coerce_map_from_(self, S): '\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: H._coerce_map_from_(H)\n True\n sage: H._coerce_map_from_(QQ)\n True\n sage: H._coerce_map_from_(GF(7))\n False\n ' return ((S == self) or self.__free_algebra.has_coerce_map_from(S)) def _repr_(self): '\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: H._repr_()\n "Free algebra quotient on 3 generators (\'i\', \'j\', \'k\') and dimension 4 over Rational Field"\n ' R = self.base_ring() n = self.__ngens r = self.__module.dimension() x = self.variable_names() return ('Free algebra quotient on %s generators %s and dimension %s over %s' % (n, x, r, R)) def gen(self, i): '\n The i-th generator of the algebra.\n\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: H.gen(0)\n i\n sage: H.gen(2)\n k\n\n An :class:`IndexError` is raised if an invalid generator is requested::\n\n sage: H.gen(3)\n Traceback (most recent call last):\n ...\n IndexError: argument i (= 3) must be between 0 and 2\n\n Negative indexing into the generators is not supported::\n\n sage: H.gen(-1)\n Traceback (most recent call last):\n ...\n IndexError: argument i (= -1) must be between 0 and 2\n ' n = self.__ngens if ((i < 0) or (not (i < n))): raise IndexError(('argument i (= %s) must be between 0 and %s' % (i, (n - 1)))) R = self.base_ring() F = self.__free_algebra.monoid() return self.element_class(self, {F.gen(i): R.one()}) def ngens(self): '\n The number of generators of the algebra.\n\n EXAMPLES::\n\n sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].ngens()\n 3\n ' return self.__ngens def dimension(self): '\n The rank of the algebra (as a free module).\n\n EXAMPLES::\n\n sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].dimension()\n 4\n ' return self.__dim def matrix_action(self): '\n EXAMPLES::\n\n sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].matrix_action()\n (\n [ 0 1 0 0] [ 0 0 1 0] [ 0 0 0 1]\n [-1 0 0 0] [ 0 0 0 1] [ 0 0 -1 0]\n [ 0 0 0 -1] [-1 0 0 0] [ 0 1 0 0]\n [ 0 0 1 0], [ 0 -1 0 0], [-1 0 0 0]\n )\n ' return self.__matrix_action def monomial_basis(self): '\n The free monoid of generators of the algebra as elements of a free\n monoid.\n\n EXAMPLES::\n\n sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].monomial_basis()\n (1, i0, i1, i2)\n ' return self.__monomial_basis def rank(self): '\n The rank of the algebra (as a free module).\n\n EXAMPLES::\n\n sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].rank()\n 4\n ' return self.__dim def module(self): "\n The free module of the algebra.\n\n EXAMPLES::\n\n sage: H = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0]; H\n Free algebra quotient on 3 generators ('i', 'j', 'k') and dimension 4 over Rational Field\n sage: H.module()\n Vector space of dimension 4 over Rational Field\n " return self.__module def monoid(self): '\n The free monoid of generators of the algebra.\n\n EXAMPLES::\n\n sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].monoid()\n Free monoid on 3 generators (i0, i1, i2)\n ' return self.__free_algebra.monoid() def free_algebra(self): '\n The free algebra generating the algebra.\n\n EXAMPLES::\n\n sage: sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)[0].free_algebra()\n Free Algebra on 3 generators (i0, i1, i2) over Rational Field\n ' return self.__free_algebra
def hamilton_quatalg(R): "\n Hamilton quaternion algebra over the commutative ring R,\n constructed as a free algebra quotient.\n\n INPUT:\n\n - R -- a commutative ring\n\n OUTPUT:\n\n - Q -- quaternion algebra\n - gens -- generators for Q\n\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(ZZ)\n sage: H\n Free algebra quotient on 3 generators ('i', 'j', 'k') and dimension 4\n over Integer Ring\n sage: i^2\n -1\n sage: i in H\n True\n\n Note that there is another vastly more efficient models for\n quaternion algebras in Sage; the one here is mainly for testing\n purposes::\n\n sage: R.<i,j,k> = QuaternionAlgebra(QQ,-1,-1) # much fast than the above\n " n = 3 from sage.algebras.free_algebra import FreeAlgebra from sage.matrix.matrix_space import MatrixSpace A = FreeAlgebra(R, n, 'i') F = A.monoid() (i, j, k) = F.gens() mons = [F(1), i, j, k] M = MatrixSpace(R, 4) mats = [M([0, 1, 0, 0, (- 1), 0, 0, 0, 0, 0, 0, (- 1), 0, 0, 1, 0]), M([0, 0, 1, 0, 0, 0, 0, 1, (- 1), 0, 0, 0, 0, (- 1), 0, 0]), M([0, 0, 0, 1, 0, 0, (- 1), 0, 0, 1, 0, 0, (- 1), 0, 0, 0])] H3 = FreeAlgebraQuotient(A, mons, mats, names=('i', 'j', 'k')) return (H3, H3.gens())
def is_FreeAlgebraQuotientElement(x): '\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: sage.algebras.free_algebra_quotient_element.is_FreeAlgebraQuotientElement(i)\n True\n\n Of course this is testing the data type::\n\n sage: sage.algebras.free_algebra_quotient_element.is_FreeAlgebraQuotientElement(1)\n False\n sage: sage.algebras.free_algebra_quotient_element.is_FreeAlgebraQuotientElement(H(1))\n True\n ' return isinstance(x, FreeAlgebraQuotientElement)
class FreeAlgebraQuotientElement(AlgebraElement): def __init__(self, A, x): '\n Create the element x of the FreeAlgebraQuotient A.\n\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(ZZ)\n sage: sage.algebras.free_algebra_quotient.FreeAlgebraQuotientElement(H, i)\n i\n sage: a = sage.algebras.free_algebra_quotient.FreeAlgebraQuotientElement(H, 1); a\n 1\n sage: a in H\n True\n\n TESTS::\n\n sage: TestSuite(i).run()\n ' AlgebraElement.__init__(self, A) Q = self.parent() if (isinstance(x, FreeAlgebraQuotientElement) and (x.parent() == Q)): self.__vector = Q.module()(x.vector()) return if isinstance(x, (Integer, int)): self.__vector = (Q.module().gen(0) * x) return elif (isinstance(x, FreeModuleElement) and (x.parent() is Q.module())): self.__vector = x return elif (isinstance(x, FreeModuleElement) and (x.parent() == A.module())): self.__vector = x return R = A.base_ring() M = A.module() F = A.monoid() B = A.monomial_basis() if isinstance(x, (Integer, int)): self.__vector = (x * M.gen(0)) elif (isinstance(x, RingElement) and (not isinstance(x, AlgebraElement)) and (x in R)): self.__vector = (x * M.gen(0)) elif (isinstance(x, FreeMonoidElement) and (x.parent() is F)): if (x in B): self.__vector = M.gen(B.index(x)) else: raise AttributeError(('argument x (= %s) is not in monomial basis' % x)) elif (isinstance(x, list) and (len(x) == A.dimension())): try: self.__vector = M(x) except TypeError: raise TypeError(('argument x (= %s) is of the wrong type' % x)) elif (isinstance(x, FreeAlgebraElement) and (x.parent() is A.free_algebra())): self.__vector = M(0) for (m, c) in x._FreeAlgebraElement__monomial_coefficients.items(): self.__vector += (c * M.gen(B.index(m))) elif isinstance(x, dict): self.__vector = M(0) for (m, c) in x.items(): self.__vector += (c * M.gen(B.index(m))) elif (isinstance(x, AlgebraElement) and (x.parent().ambient_algebra() is A)): self.__vector = x.ambient_algebra_element().vector() else: raise TypeError(('argument x (= %s) is of the wrong type' % x)) def _repr_(self): "\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(ZZ)\n sage: i._repr_()\n 'i'\n " Q = self.parent() M = Q.monoid() with localvars(M, Q.variable_names()): cffs = list(self.__vector) mons = Q.monomial_basis() return repr_lincomb(zip(mons, cffs), strip_one=True) def _latex_(self): "\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: ((2/3)*i - j)._latex_()\n '\\frac{2}{3} i - j'\n " Q = self.parent() M = Q.monoid() with localvars(M, Q.variable_names()): cffs = tuple(self.__vector) mons = Q.monomial_basis() return repr_lincomb(zip(mons, cffs), is_latex=True, strip_one=True) def vector(self): '\n Return underlying vector representation of this element.\n\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: ((2/3)*i - j).vector()\n (0, 2/3, -1, 0)\n ' return self.__vector def _richcmp_(self, right, op): '\n Compare two quotient algebra elements; done by comparing the\n underlying vector representatives.\n\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: i > j\n True\n sage: i == i\n True\n sage: i == 1\n False\n sage: i + j == j + i\n True\n ' return richcmp(self.vector(), right.vector(), op) def __neg__(self): '\n Return negative of self.\n\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: -i\n -i\n sage: -(2/3*i - 3/7*j + k)\n -2/3*i + 3/7*j - k\n ' y = self.parent()(0) y.__vector = (- self.__vector) return y def _add_(self, y): '\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: 2/3*i + 4*j + k\n 2/3*i + 4*j + k\n ' A = self.parent() z = A(0) z.__vector = (self.__vector + y.__vector) return z def _sub_(self, y): '\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: 2/3*i - 4*j\n 2/3*i - 4*j\n sage: a = 2/3*i - 4*j; a\n 2/3*i - 4*j\n sage: a - a\n 0\n ' A = self.parent() z = A(0) z.__vector = (self.__vector - y.__vector) return z def _mul_(self, y): '\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: a = (5 + 2*i - 3/5*j + 17*k); a*(a+10)\n -5459/25 + 40*i - 12*j + 340*k\n\n Double check that the above is actually right::\n\n sage: R.<i,j,k> = QuaternionAlgebra(QQ,-1,-1)\n sage: a = (5 + 2*i - 3/5*j + 17*k); a*(a+10)\n -5459/25 + 40*i - 12*j + 340*k\n ' A = self.parent() def monomial_product(X, w, m): mats = X._FreeAlgebraQuotient__matrix_action for (j, k) in m._element_list: M = mats[int(j)] for _ in range(k): w *= M return w u = self.__vector.__copy__() v = y.__vector z = A(0) B = A.monomial_basis() for i in range(A.dimension()): c = v[i] if (c != 0): z.__vector += monomial_product(A, (c * u), B[i]) return z def _rmul_(self, c): '\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: 3 * (-1+i-2*j+k)\n -3 + 3*i - 6*j + 3*k\n sage: (-1+i-2*j+k)._rmul_(3)\n -3 + 3*i - 6*j + 3*k\n ' return self.parent([(c * a) for a in self.__vector]) def _lmul_(self, c): '\n EXAMPLES::\n\n sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(QQ)\n sage: (-1+i-2*j+k) * 3\n -3 + 3*i - 6*j + 3*k\n sage: (-1+i-2*j+k)._lmul_(3)\n -3 + 3*i - 6*j + 3*k\n ' return self.parent([(a * c) for a in self.__vector])
class FreeZinbielAlgebra(CombinatorialFreeModule): "\n The free Zinbiel algebra on `n` generators.\n\n Let `R` be a ring. A *Zinbiel algebra* is a non-associative\n algebra with multiplication `\\circ` that satisfies\n\n .. MATH::\n\n (a \\circ b) \\circ c = a \\circ (b \\circ c) + a \\circ (c \\circ b).\n\n Zinbiel algebras were first introduced by Loday (see [Lod1995]_ and\n [LV2012]_) as the Koszul dual to Leibniz algebras (hence the name\n coined by Lemaire).\n\n By default, the convention above is used. The opposite product,\n which satisfy the opposite axiom, can be used instead by setting\n the ``side`` parameter to ``'>'`` instead of the default value ``'<'``.\n\n Zinbiel algebras are divided power algebras, in that for\n\n .. MATH::\n\n x^{\\circ n} = \\bigl(x \\circ (x \\circ \\cdots \\circ( x \\circ x) \\cdots\n ) \\bigr)\n\n we have\n\n .. MATH::\n\n x^{\\circ m} \\circ x^{\\circ n} = \\binom{n+m-1}{m} x^{n+m}\n\n and\n\n .. MATH::\n\n \\underbrace{\\bigl( ( x \\circ \\cdots \\circ x \\circ (x \\circ x) \\cdots\n ) \\bigr)}_{n+1 \\text{ times}} = n! x^n.\n\n .. NOTE::\n\n This implies that Zinbiel algebras are not power associative.\n\n To every Zinbiel algebra, we can construct a corresponding commutative\n associative algebra by using the symmetrized product:\n\n .. MATH::\n\n a * b = a \\circ b + b \\circ a.\n\n The free Zinbiel algebra on `n` generators is isomorphic as `R`-modules\n to the reduced tensor algebra `\\bar{T}(R^n)` with the product\n\n .. MATH::\n\n (x_0 x_1 \\cdots x_p) \\circ (x_{p+1} x_{p+2} \\cdots x_{p+q})\n = \\sum_{\\sigma \\in S_{p,q}} x_0 (x_{\\sigma(1)} x_{\\sigma(2)}\n \\cdots x_{\\sigma(p+q)},\n\n where `S_{p,q}` is the set of `(p,q)`-shuffles.\n\n The free Zinbiel algebra is free as a divided power algebra. Moreover,\n the corresponding commutative algebra is isomorphic to the (non-unital)\n shuffle algebra.\n\n INPUT:\n\n - ``R`` -- a ring\n - ``n`` -- (optional) the number of generators\n - ``names`` -- the generator names\n\n .. WARNING::\n\n Currently the basis is indexed by all finite words over the variables,\n including the empty word. This is a slight abuse as it is supposed\n to be indexed by all non-empty words.\n\n EXAMPLES:\n\n We create the free Zinbiel algebra and check the defining relation::\n\n sage: Z.<x,y,z> = algebras.FreeZinbiel(QQ)\n sage: (x*y)*z\n Z[xyz] + Z[xzy]\n sage: x*(y*z) + x*(z*y)\n Z[xyz] + Z[xzy]\n\n We see that the Zinbiel algebra is not associative, not even\n power associative::\n\n sage: x*(y*z)\n Z[xyz]\n sage: x*(x*x)\n Z[xxx]\n sage: (x*x)*x\n 2*Z[xxx]\n\n We verify that it is a divided power algebra::\n\n sage: (x*(x*x)) * (x*(x*(x*x)))\n 15*Z[xxxxxxx]\n sage: binomial(3+4-1,4)\n 15\n sage: (x*(x*(x*x))) * (x*(x*x))\n 20*Z[xxxxxxx]\n sage: binomial(3+4-1,3)\n 20\n sage: ((x*x)*x)*x\n 6*Z[xxxx]\n sage: (((x*x)*x)*x)*x\n 24*Z[xxxxx]\n\n A few tests with the opposite convention for the product::\n\n sage: Z.<x,y,z> = algebras.FreeZinbiel(QQ, side='>')\n sage: (x*y)*z\n Z[xyz]\n sage: x*(y*z)\n Z[xyz] + Z[yxz]\n\n TESTS::\n\n sage: Z.<x,y,z> = algebras.FreeZinbiel(QQ)\n sage: Z.basis().keys()\n Finite words over {'x', 'y', 'z'}\n\n sage: A = algebras.FreeZinbiel(QQ,'z2,z3')\n sage: x, y = A.gens()\n sage: x*y\n Z[z2,z3]\n\n REFERENCES:\n\n - :wikipedia:`Zinbiel_algebra`\n\n - [Lod1995]_\n\n - [LV2012]_\n " @staticmethod def __classcall_private__(cls, R, n=None, names=None, prefix=None, side=None): "\n Standardize input to ensure a unique representation.\n\n TESTS::\n\n sage: Z1.<x,y,z> = algebras.FreeZinbiel(QQ)\n sage: Z2.<x,y,z> = algebras.FreeZinbiel(QQ, 3)\n sage: Z3 = algebras.FreeZinbiel(QQ, 3, 'x,y,z')\n sage: Z4.<x,y,z> = algebras.FreeZinbiel(QQ, 'x,y,z')\n sage: Z1 is Z2 and Z1 is Z3 and Z1 is Z4\n True\n\n sage: algebras.FreeZinbiel(QQ, ['x', 'y'])\n Free Zinbiel algebra on generators (Z[x], Z[y]) over Rational Field\n sage: algebras.FreeZinbiel(QQ, ('x', 'y'))\n Free Zinbiel algebra on generators (Z[x], Z[y]) over Rational Field\n\n sage: Z = algebras.FreeZinbiel(QQ, ZZ)\n " if isinstance(n, (list, tuple)): names = n n = len(names) elif isinstance(n, str): names = n.split(',') n = len(names) elif isinstance(names, str): names = names.split(',') elif (n is None): n = len(names) if (R not in Rings()): raise TypeError('argument R must be a ring') if (prefix is None): prefix = 'Z' if (side is None): side = '<' if (side not in ['<', '>']): raise ValueError("side must be either '<' or '>'") if (names is None): return super().__classcall__(cls, R, n, None, prefix, side) return super().__classcall__(cls, R, n, tuple(names), prefix, side) def __init__(self, R, n, names, prefix, side): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: Z.<x,y,z> = algebras.FreeZinbiel(QQ)\n sage: TestSuite(Z).run()\n\n sage: Z = algebras.FreeZinbiel(QQ, ZZ)\n sage: G = Z.algebra_generators()\n sage: TestSuite(Z).run(elements=[Z.an_element(), G[1], G[1]*G[2]*G[0]])\n\n TESTS::\n\n sage: Z.<x,y,z> = algebras.FreeZinbiel(5)\n Traceback (most recent call last):\n ...\n TypeError: argument R must be a ring\n\n sage: algebras.FreeZinbiel(QQ, ['x', 'y'], prefix='f')\n Free Zinbiel algebra on generators (f[x], f[y]) over Rational Field\n " if (R not in Rings()): raise TypeError('argument R must be a ring') if (names is None): indices = Words(Alphabet(n), infinite=False) self._n = None else: indices = Words(Alphabet(n, names=names), infinite=False) self._n = n self._side = side if (side == '<'): self.product_on_basis = self.product_on_basis_left else: self.product_on_basis = self.product_on_basis_right cat = MagmaticAlgebras(R).WithBasis().Graded() cat &= CoalgebrasWithBasis(R) CombinatorialFreeModule.__init__(self, R, indices, prefix=prefix, category=cat) if (self._n is not None): self._assign_names(names) def _repr_term(self, t): "\n Return a string representation of the basis element indexed by ``t``.\n\n EXAMPLES::\n\n sage: Z.<x,y,z> = algebras.FreeZinbiel(QQ)\n sage: Z._repr_term(Z._indices('xyzxxy'))\n 'Z[xyzxxy]'\n " return '{!s}[{!s}]'.format(self._print_options['prefix'], repr(t)[6:]) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: Z.<x,y> = algebras.FreeZinbiel(QQ)\n sage: Z\n Free Zinbiel algebra on generators (Z[x], Z[y]) over Rational Field\n\n sage: Z = algebras.FreeZinbiel(QQ, ZZ)\n sage: Z\n Free Zinbiel algebra on generators indexed by Integer Ring over Rational Field\n ' if (self._n is None): return 'Free Zinbiel algebra on generators indexed by {} over {}'.format(self._indices.alphabet(), self.base_ring()) return 'Free Zinbiel algebra on generators {} over {}'.format(self.gens(), self.base_ring()) def side(self): "\n Return the choice of side for the product.\n\n This is either ``'<'`` or ``'>'``.\n\n EXAMPLES::\n\n sage: Z.<x,y,z> = algebras.FreeZinbiel(QQ)\n sage: Z.side()\n '<'\n " return self._side @cached_method def algebra_generators(self): '\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: Z.<x,y,z> = algebras.FreeZinbiel(QQ)\n sage: list(Z.algebra_generators())\n [Z[x], Z[y], Z[z]]\n ' if (self._n is None): A = self._indices.alphabet() else: A = self.variable_names() return Family(A, (lambda g: self.monomial(self._indices([g])))) def change_ring(self, R): "\n Return the free Zinbiel algebra in the same variables over ``R``.\n\n INPUT:\n\n - ``R`` -- a ring\n\n The same side convention is used for the product.\n\n EXAMPLES::\n\n sage: A = algebras.FreeZinbiel(ZZ, 'f,g,h')\n sage: A.change_ring(QQ)\n Free Zinbiel algebra on generators (Z[f], Z[g], Z[h])\n over Rational Field\n " A = self.variable_names() return FreeZinbielAlgebra(R, n=len(A), names=A, side=self._side) @cached_method def gens(self): '\n Return the generators of ``self``.\n\n EXAMPLES::\n\n sage: Z.<x,y,z> = algebras.FreeZinbiel(QQ)\n sage: Z.gens()\n (Z[x], Z[y], Z[z])\n ' if (self._n is None): return self.algebra_generators() return tuple(self.algebra_generators()) def degree_on_basis(self, t): "\n Return the degree of a word in the free Zinbiel algebra.\n\n This is the length.\n\n EXAMPLES::\n\n sage: A = algebras.FreeZinbiel(QQ, 'x,y')\n sage: W = A.basis().keys()\n sage: A.degree_on_basis(W('xy'))\n 2\n " return len(t) def product_on_basis_left(self, x, y): "\n Return the product < of the basis elements indexed by ``x`` and ``y``.\n\n This is one half of the shuffle product, where the first letter\n comes from the first letter of the first argument.\n\n INPUT:\n\n - ``x``, ``y`` -- two words\n\n EXAMPLES::\n\n sage: Z.<x,y,z> = algebras.FreeZinbiel(QQ)\n sage: (x*y)*z # indirect doctest\n Z[xyz] + Z[xzy]\n\n TESTS::\n\n sage: Z.<x,y> = algebras.FreeZinbiel(QQ)\n sage: Z.product_on_basis(Word(), Word('y'))\n Z[y]\n " if (not x): return self.monomial(y) x0 = self._indices([x[0]]) return self.sum_of_monomials(((x0 + sh) for sh in x[1:].shuffle(y))) def product_on_basis_right(self, x, y): "\n Return the product > of the basis elements indexed by ``x`` and ``y``.\n\n This is one half of the shuffle product, where the last letter\n comes from the last letter of the second argument.\n\n INPUT:\n\n - ``x``, ``y`` -- two words\n\n EXAMPLES::\n\n sage: Z.<x,y,z> = algebras.FreeZinbiel(QQ, side='>')\n sage: (x*y)*z # indirect doctest\n Z[xyz]\n\n TESTS::\n\n sage: Z.<x,y> = algebras.FreeZinbiel(QQ, side='>')\n sage: Z.product_on_basis(Word('x'), Word())\n Z[x]\n " if (not y): return self.monomial(x) yf = self._indices([y[(- 1)]]) return self.sum_of_monomials(((sh + yf) for sh in x.shuffle(y[:(- 1)]))) def coproduct_on_basis(self, w): "\n Return the coproduct of the element of the basis indexed by\n the word ``w``.\n\n The coproduct is given by deconcatenation.\n\n INPUT:\n\n - ``w`` -- a word\n\n EXAMPLES::\n\n sage: F = algebras.FreeZinbiel(QQ,['a','b'])\n sage: F.coproduct_on_basis(Word('a'))\n Z[] # Z[a] + Z[a] # Z[]\n sage: F.coproduct_on_basis(Word('aba'))\n Z[] # Z[aba] + Z[a] # Z[ba] + Z[ab] # Z[a] + Z[aba] # Z[]\n sage: F.coproduct_on_basis(Word())\n Z[] # Z[]\n\n TESTS::\n\n sage: F = algebras.FreeZinbiel(QQ,['a','b'])\n sage: S = F.an_element(); S\n Z[] + 2*Z[a] + 3*Z[b] + Z[bab]\n sage: F.coproduct(S)\n Z[] # Z[] + 2*Z[] # Z[a] + 3*Z[] # Z[b] + Z[] # Z[bab] +\n 2*Z[a] # Z[] + 3*Z[b] # Z[] + Z[b] # Z[ab] + Z[ba] # Z[b] +\n Z[bab] # Z[]\n " TS = self.tensor_square() return TS.sum_of_monomials(((w[:i], w[i:]) for i in range((len(w) + 1)))) def counit(self, S): "\n Return the counit of ``S``.\n\n EXAMPLES::\n\n sage: F = algebras.FreeZinbiel(QQ,['a','b'])\n sage: S = F.an_element(); S\n Z[] + 2*Z[a] + 3*Z[b] + Z[bab]\n sage: F.counit(S)\n 1\n " W = self.basis().keys() return S.coefficient(W()) def _element_constructor_(self, x): "\n Convert ``x`` into ``self``.\n\n EXAMPLES::\n\n sage: R = algebras.FreeZinbiel(QQ, 'x,y')\n sage: x, y = R.gens()\n sage: R(x)\n Z[x]\n sage: R(x+4*y)\n Z[x] + 4*Z[y]\n\n sage: W = R.basis().keys()\n sage: R(W('x'))\n Z[x]\n sage: D = algebras.FreeZinbiel(ZZ, 'x,y')\n sage: X, Y = D.gens()\n sage: R(X-Y).parent()\n Free Zinbiel algebra on generators (Z[x], Z[y]) over Rational Field\n\n TESTS::\n\n sage: R.<x,y> = algebras.FreeZinbiel(QQ)\n sage: S.<z> = algebras.FreeZinbiel(GF(3))\n sage: R(z)\n Traceback (most recent call last):\n ...\n TypeError: not able to convert this to this algebra\n " if (x in self.basis().keys()): return self.monomial(x) try: P = x.parent() except AttributeError: raise TypeError('not able to convert this to this algebra') if (isinstance(P, FreeZinbielAlgebra) and self._coerce_map_from_(P)): if (self._side == P._side): return self.element_class(self, x.monomial_coefficients(copy=False)) else: dic = x.monomial_coefficients(copy=False) return self.element_class(self, {w.reversal(): cf for (w, cf) in dic.items()}) else: raise TypeError('not able to convert this to this algebra') def _coerce_map_from_(self, R): "\n Return ``True`` if there is a coercion from ``R`` into ``self``\n and ``False`` otherwise.\n\n The things that coerce into ``self`` are\n\n - free Zinbiel algebras whose set `E` of labels is\n a subset of the corresponding self of ``set`, and whose base\n ring has a coercion map into ``self.base_ring()``\n\n EXAMPLES::\n\n sage: F = algebras.FreeZinbiel(GF(7), 'x,y,z'); F\n Free Zinbiel algebra on generators (Z[x], Z[y], Z[z])\n over Finite Field of size 7\n\n Elements of the free Zinbiel algebra canonically coerce in::\n\n sage: x, y, z = F.gens()\n sage: F.coerce(x+y) == x+y\n True\n\n The free Zinbiel algebra over `\\ZZ` on `x, y, z` coerces in, since\n `\\ZZ` coerces to `\\GF{7}`::\n\n sage: G = algebras.FreeZinbiel(ZZ, 'x,y,z')\n sage: Gx,Gy,Gz = G.gens()\n sage: z = F.coerce(Gx+Gy); z\n Z[x] + Z[y]\n sage: z.parent() is F\n True\n\n However, `\\GF{7}` does not coerce to `\\ZZ`, so the free Zinbiel\n algebra over `\\GF{7}` does not coerce to the one over `\\ZZ`::\n\n sage: G.coerce(y)\n Traceback (most recent call last):\n ...\n TypeError: no canonical coercion from Free Zinbiel algebra on\n generators (Z[x], Z[y], Z[z]) over Finite Field of size 7 to\n Free Zinbiel algebra on generators (Z[x], Z[y], Z[z])\n over Integer Ring\n\n TESTS::\n\n sage: F = algebras.FreeZinbiel(ZZ, 'x,y,z')\n sage: G = algebras.FreeZinbiel(QQ, 'x,y,z')\n sage: H = algebras.FreeZinbiel(ZZ, 'y')\n sage: F._coerce_map_from_(G)\n False\n sage: G._coerce_map_from_(F)\n True\n sage: F._coerce_map_from_(H)\n True\n sage: F._coerce_map_from_(QQ) is None\n True\n sage: G._coerce_map_from_(QQ) is None\n True\n sage: F.has_coerce_map_from(PolynomialRing(ZZ, 3, 'x,y,z'))\n False\n\n sage: I = algebras.FreeZinbiel(ZZ, ZZ)\n sage: F._coerce_map_from_(I)\n False\n sage: I._coerce_map_from_(F)\n False\n " if isinstance(R, FreeZinbielAlgebra): if ((self._n is None) or (R._n is None)): return False return (all(((x in self.variable_names()) for x in R.variable_names())) and self.base_ring().has_coerce_map_from(R.base_ring())) return super()._coerce_map_from_(R) def construction(self): "\n Return a pair ``(F, R)``, where ``F`` is a :class:`ZinbielFunctor`\n and ``R`` is a ring, such that ``F(R)`` returns ``self``.\n\n EXAMPLES::\n\n sage: P = algebras.FreeZinbiel(ZZ, 'x,y')\n sage: x,y = P.gens()\n sage: F, R = P.construction()\n sage: F\n Zinbiel[x,y]\n sage: R\n Integer Ring\n sage: F(ZZ) is P\n True\n sage: F(QQ)\n Free Zinbiel algebra on generators (Z[x], Z[y]) over Rational Field\n " if (self._n is None): A = self._indices.alphabet() else: A = self.variable_names() return (ZinbielFunctor(A, side=self._side), self.base_ring())
class ZinbielFunctor(ConstructionFunctor): "\n A constructor for free Zinbiel algebras.\n\n EXAMPLES::\n\n sage: P = algebras.FreeZinbiel(ZZ, 'x,y')\n sage: x,y = P.gens()\n sage: F = P.construction()[0]; F\n Zinbiel[x,y]\n\n sage: A = GF(5)['a,b']\n sage: a, b = A.gens()\n sage: F(A)\n Free Zinbiel algebra on generators (Z[x], Z[y])\n over Multivariate Polynomial Ring in a, b over Finite Field of size 5\n\n sage: f = A.hom([a+b,a-b],A)\n sage: F(f)\n Generic endomorphism of Free Zinbiel algebra on generators (Z[x], Z[y])\n over Multivariate Polynomial Ring in a, b over Finite Field of size 5\n\n sage: F(f)(a * F(A)(x))\n (a+b)*Z[x]\n " rank = 9 def __init__(self, variables, side): "\n EXAMPLES::\n\n sage: functor = sage.algebras.free_zinbiel_algebra.ZinbielFunctor\n sage: F = functor(['x','y'], '<'); F\n Zinbiel[x,y]\n sage: F(ZZ)\n Free Zinbiel algebra on generators (Z[x], Z[y]) over Integer Ring\n " Functor.__init__(self, Rings(), Magmas()) self.vars = variables self._side = side self._finite_vars = bool((isinstance(variables, (list, tuple)) or (variables in Sets().Finite()))) def _apply_functor(self, R): "\n Apply the functor to an object of ``self``'s domain.\n\n EXAMPLES::\n\n sage: R = algebras.FreeZinbiel(ZZ, 'x,y,z')\n sage: F = R.construction()[0]; F\n Zinbiel[x,y,z]\n sage: type(F)\n <class 'sage.algebras.free_zinbiel_algebra.ZinbielFunctor'>\n sage: F(ZZ) # indirect doctest\n Free Zinbiel algebra on generators (Z[x], Z[y], Z[z])\n over Integer Ring\n\n sage: R = algebras.FreeZinbiel(QQ, ZZ)\n sage: F = R.construction()[0]; F\n Zinbiel[Integer Ring]\n sage: F(ZZ) # indirect doctest\n Free Zinbiel algebra on generators indexed by Integer Ring over Integer Ring\n " if self._finite_vars: return FreeZinbielAlgebra(R, len(self.vars), self.vars, side=self._side) return FreeZinbielAlgebra(R, self.vars, side=self._side) def _apply_functor_to_morphism(self, f): "\n Apply the functor ``self`` to the ring morphism `f`.\n\n TESTS::\n\n sage: R = algebras.FreeZinbiel(ZZ, 'x').construction()[0]\n sage: R(ZZ.hom(GF(3))) # indirect doctest\n Generic morphism:\n From: Free Zinbiel algebra on generators (Z[x],)\n over Integer Ring\n To: Free Zinbiel algebra on generators (Z[x],)\n over Finite Field of size 3\n " dom = self(f.domain()) codom = self(f.codomain()) def action(x): return codom._from_dict({a: f(b) for (a, b) in x.monomial_coefficients(copy=False).items()}) return dom.module_morphism(function=action, codomain=codom) def __eq__(self, other): "\n EXAMPLES::\n\n sage: F = algebras.FreeZinbiel(ZZ, 'x,y,z').construction()[0]\n sage: G = algebras.FreeZinbiel(QQ, 'x,y,z').construction()[0]\n sage: F == G\n True\n sage: G == loads(dumps(G))\n True\n sage: G = algebras.FreeZinbiel(QQ, 'x,y').construction()[0]\n sage: F == G\n False\n " if (not isinstance(other, ZinbielFunctor)): return False return ((self.vars == other.vars) and (self._side == other._side)) def __hash__(self): "\n Return the hash of ``self``.\n\n EXAMPLES::\n\n sage: F = algebras.FreeZinbiel(ZZ, 'x,y,z').construction()[0]\n sage: G = algebras.FreeZinbiel(QQ, 'x,y,z').construction()[0]\n sage: hash(F) == hash(G)\n True\n " return hash(repr(self)) def __mul__(self, other): "\n If two Zinbiel functors are given in a row, form a single\n Zinbiel functor with all of the variables.\n\n EXAMPLES::\n\n sage: from sage.algebras.free_zinbiel_algebra import ZinbielFunctor as functor\n sage: F = functor(['x','y'], '<')\n sage: G = functor(['t'], '<')\n sage: G * F\n Zinbiel[x,y,t]\n\n With an infinite generating set::\n\n sage: H = functor(ZZ, '<')\n sage: H * G\n Traceback (most recent call last):\n ...\n CoercionException: Unable to determine overlap for infinite sets\n sage: G * H\n Traceback (most recent call last):\n ...\n CoercionException: Unable to determine overlap for infinite sets\n " if isinstance(other, IdentityConstructionFunctor): return self if isinstance(other, ZinbielFunctor): if (self._side != other._side): raise CoercionException('detection of distinct sides') if ((not self._finite_vars) or (not other._finite_vars)): raise CoercionException('Unable to determine overlap for infinite sets') if set(self.vars).intersection(other.vars): raise CoercionException(('Overlapping variables (%s,%s)' % (self.vars, other.vars))) return ZinbielFunctor((other.vars + self.vars), self._side) elif (isinstance(other, CompositeConstructionFunctor) and isinstance(other.all[(- 1)], ZinbielFunctor)): return CompositeConstructionFunctor(other.all[:(- 1)], (self * other.all[(- 1)])) else: return CompositeConstructionFunctor(other, self) def merge(self, other): "\n Merge ``self`` with another construction functor, or return ``None``.\n\n EXAMPLES::\n\n sage: functor = sage.algebras.free_zinbiel_algebra.ZinbielFunctor\n sage: F = functor(['x','y'], '<')\n sage: G = functor(['t'], '<')\n sage: F.merge(G)\n Zinbiel[x,y,t]\n sage: F.merge(F)\n Zinbiel[x,y]\n\n With an infinite generating set::\n\n sage: H = functor(ZZ, '<')\n sage: H.merge(H) is H\n True\n sage: H.merge(F) is None\n True\n sage: F.merge(H) is None\n True\n\n Now some actual use cases::\n\n sage: R = algebras.FreeZinbiel(ZZ, 'x,y,z')\n sage: x,y,z = R.gens()\n sage: 1/2 * x\n 1/2*Z[x]\n sage: parent(1/2 * x)\n Free Zinbiel algebra on generators (Z[x], Z[y], Z[z])\n over Rational Field\n\n sage: S = algebras.FreeZinbiel(QQ, 'z,t')\n sage: z,t = S.gens()\n sage: x * t\n Z[xt]\n sage: parent(x * t)\n Free Zinbiel algebra on generators (Z[z], Z[t], Z[x], Z[y])\n over Rational Field\n\n TESTS:\n\n Using the other side convention::\n\n sage: F = functor(['x','y'], '>')\n sage: G = functor(['t'], '>')\n sage: H = functor(['t'], '<')\n sage: F.merge(G)\n Zinbiel[x,y,t]\n sage: F.merge(H)\n Traceback (most recent call last):\n ...\n TypeError: cannot merge free Zinbiel algebras with distinct sides\n " if isinstance(other, ZinbielFunctor): if (self._side != other._side): raise TypeError('cannot merge free Zinbiel algebras with distinct sides') if (self.vars == other.vars): return self def check(x): return (isinstance(x, (list, tuple)) or (x in Sets().Finite())) if ((not check(self.vars)) or (not check(other.vars))): return None ret = list(self.vars) cur_vars = set(ret) for v in other.vars: if (v not in cur_vars): ret.append(v) return ZinbielFunctor(ret, self._side) else: return None def _repr_(self): "\n TESTS::\n\n sage: algebras.FreeZinbiel(QQ,'x,y,z,t').construction()[0]\n Zinbiel[x,y,z,t]\n\n sage: algebras.FreeZinbiel(QQ, ZZ).construction()[0]\n Zinbiel[Integer Ring]\n " if self._finite_vars: return ('Zinbiel[%s]' % ','.join(self.vars)) return 'Zinbiel[{}]'.format(self.vars)
class FMatrix(SageObject): '\n An F-matrix for a :class:`FusionRing`.\n\n INPUT:\n\n - ``FR`` -- a :class:`FusionRing`\n - ``fusion_label`` -- (optional) a string used to label basis elements\n of the :class:`FusionRing` associated to ``self``\n (see :meth:`FusionRing.fusion_labels`)\n - ``var_prefix`` -- (optional) a string indicating the desired prefix\n for variables denoting F-symbols to be solved\n - ``inject_variables`` -- (default: ``False``) a boolean indicating\n whether to inject variables (:class:`FusionRing` basis element\n labels and F-symbols) into the global namespace\n\n The :class:`FusionRing` or Verlinde algebra is the\n Grothendieck ring of a modular tensor category [BaKi2001]_.\n Such categories arise in conformal field theory or in the\n representation theories of affine Lie algebras, or\n quantum groups at roots of unity. They have applications\n to low dimensional topology and knot theory, to conformal\n field theory and to topological quantum computing. The\n :class:`FusionRing` captures much information about a fusion\n category, but to complete the picture, the F-matrices or\n 6j-symbols are needed. For example these are required in\n order to construct braid group representations. This\n can be done using the :class:`FusionRing` method\n :meth:`FusionRing.get_braid_generators`, which uses\n the F-matrix.\n\n We only undertake to compute the F-matrix if the\n :class:`FusionRing` is *multiplicity free* meaning that\n the Fusion coefficients `N^{ij}_k` are bounded\n by 1. For Cartan Types `X_r` and level `k`,\n the multiplicity-free cases are given by the\n following table.\n\n +------------------------+----------+\n | Cartan Type | `k` |\n +========================+==========+\n | `A_1` | any |\n +------------------------+----------+\n | `A_r, r\\geq 2` | `\\leq 2` |\n +------------------------+----------+\n | `B_r, r\\geq 2` | `\\leq 2` |\n +------------------------+----------+\n | `C_2` | `\\leq 2` |\n +------------------------+----------+\n | `C_r, r\\geq 3` | `\\leq 1` |\n +------------------------+----------+\n | `D_r, r\\geq 4` | `\\leq 2` |\n +------------------------+----------+\n | `G_2, F_4, E_6, E_7` | `\\leq 2` |\n +------------------------+----------+\n | `E_8` | `\\leq 3` |\n +------------------------+----------+\n\n Beyond this limitation, computation of the F-matrix\n can involve very large systems of equations. A\n rule of thumb is that this code can compute the\n F-matrix for systems with `\\leq 14` simple objects\n (primary fields) on a machine with 16 GB of memory.\n (Larger examples can be quite time consuming.)\n\n The :class:`FusionRing` and its methods capture much\n of the structure of the underlying tensor category.\n But an important aspect that is not encoded in the\n fusion ring is the associator, which is a homomorphism\n `(A\\otimes B)\\otimes C\\to A\\otimes(B\\otimes C)` that\n requires an additional tool, the F-matrix or 6j-symbol.\n To specify this, we fix a simple object `D`\n and represent the transformation\n\n .. MATH::\n\n \\text{Hom}(D, (A\\otimes B)\\otimes C)\n \\to \\text{Hom}(D, A\\otimes(B\\otimes C))\n\n by a matrix `F^{ABC}_D`. This depends on a pair of\n additional simple objects `X` and `Y`. Indeed, we can\n get a basis for `\\text{Hom}(D, (A\\otimes B)\\otimes C)`\n indexed by simple objects `X` in which the corresponding\n homomorphism factors through `X\\otimes C`, and similarly\n `\\text{Hom}(D, A\\otimes(B\\otimes C))` has a basis indexed\n by `Y`, in which the basis vector factors through `A\\otimes Y`.\n\n See [TTWL2009]_ for an introduction to this topic,\n [EGNO2015]_ Section 4.9 for a precise mathematical\n definition, and [Bond2007]_ Section 2.5 and [Ab2022]_ for discussions\n of how to compute the F-matrix. In addition to\n [Bond2007]_, worked out F-matrices may be found in\n [RoStWa2009]_ and [CHW2015]_.\n\n The F-matrix is only determined up to a *gauge*. This\n is a family of embeddings `C \\to A\\otimes B` for\n simple objects `A, B, C` such that `\\text{Hom}(C, A\\otimes B)`\n is nonzero. Changing the gauge changes the F-matrix though\n not in a very essential way. By varying the gauge it is\n possible to make the F-matrices unitary, or it is possible\n to make them cyclotomic.\n\n Due to the large number of equations we may fail to find a\n Groebner basis if there are too many variables.\n\n EXAMPLES::\n\n sage: I = FusionRing("E8", 2, conjugate=True)\n sage: I.fusion_labels(["i0", "p", "s"], inject_variables=True)\n sage: f = I.get_fmatrix(inject_variables=True); f\n creating variables fx1..fx14\n Defining fx0, fx1, fx2, fx3, fx4, fx5, fx6, fx7, fx8, fx9, fx10, fx11, fx12, fx13\n F-Matrix factory for The Fusion Ring of Type E8 and level 2 with Integer Ring coefficients\n\n We have injected two sets of variables to the global namespace.\n We created three variables ``i0, p, s`` to represent the\n primary fields (simple elements) of the :class:`FusionRing`. Creating\n the :class:`FMatrix` factory also created variables\n ``fx1, fx2, ..., fx14`` in order to solve the hexagon and pentagon\n equations describing the F-matrix. Since we called :class:`FMatrix`\n with the parameter ``inject_variables=True``, these have been injected\n into the global namespace. This is not necessary for the code to work\n but if you want to run the code experimentally you may want access\n to these variables.\n\n EXAMPLES::\n\n sage: f.fmatrix(s, s, s, s)\n [fx10 fx11]\n [fx12 fx13]\n\n The F-matrix has not been computed at this stage, so\n the F-matrix `F^{sss}_s` is filled with variables\n ``fx10``, ``fx11``, ``fx12``, ``fx13``. The task is\n to solve for these.\n\n As explained above The F-matrix `(F^{ABC}_D)_{X, Y}`\n two other variables `X` and `Y`. We have methods to\n tell us (depending on `A, B, C, D`) what the possibilities\n for these are. In this example with `A=B=C=D=s`\n both `X` and `Y` are allowed to be `i_0` or `s`.\n\n ::\n\n sage: f.f_from(s, s, s, s), f.f_to(s, s, s, s)\n ([i0, p], [i0, p])\n\n The last two statments show that the possible values of\n `X` and `Y` when `A = B = C = D = s` are `i_0` and `p`.\n\n The F-matrix is computed by solving the so-called\n pentagon and hexagon equations. The *pentagon equations*\n reflect the Mac Lane pentagon axiom in the definition\n of a monoidal category. The hexagon relations\n reflect the axioms of a *braided monoidal category*,\n which are constraints on both the F-matrix and on\n the R-matrix. Optionally, orthogonality constraints\n may be imposed to obtain an orthogonal F-matrix.\n\n ::\n\n sage: sorted(f.get_defining_equations("pentagons"))[1:3]\n [fx9*fx12 - fx2*fx13, fx4*fx11 - fx2*fx13]\n sage: sorted(f.get_defining_equations("hexagons"))[1:3]\n [fx6 - 1, fx2 + 1]\n sage: sorted(f.get_orthogonality_constraints())[1:3]\n [fx10*fx11 + fx12*fx13, fx10*fx11 + fx12*fx13]\n\n There are two methods available to compute an F-matrix.\n The first, :meth:`find_cyclotomic_solution` uses only\n the pentagon and hexagon relations. The second,\n :meth:`find_orthogonal_solution` uses additionally\n the orthogonality relations. There are some differences\n that should be kept in mind.\n\n :meth:`find_cyclotomic_solution` currently works only with\n smaller examples. For example the :class:`FusionRing` for `G_2`\n at level 2 is too large. When it is available, this method\n produces an F-matrix whose entries are in the same\n cyclotomic field as the underlying :class:`FusionRing`. ::\n\n sage: f.find_cyclotomic_solution()\n Setting up hexagons and pentagons...\n Finding a Groebner basis...\n Solving...\n Fixing the gauge...\n adding equation... fx1 - 1\n adding equation... fx11 - 1\n Done!\n\n We now have access to the values of the F-matrix using\n the methods :meth:`fmatrix` and :meth:`fmat`::\n\n sage: f.fmatrix(s, s, s, s)\n [(-1/2*zeta128^48 + 1/2*zeta128^16) 1]\n [ 1/2 (1/2*zeta128^48 - 1/2*zeta128^16)]\n sage: f.fmat(s, s, s, s, p, p)\n (1/2*zeta128^48 - 1/2*zeta128^16)\n\n :meth:`find_orthogonal_solution` is much more powerful\n and is capable of handling large cases, sometimes\n quickly but sometimes (in larger cases) after hours of\n computation. Its F-matrices are not always in the\n cyclotomic field that is the base ring of the underlying\n :class:`FusionRing`, but sometimes in an extension field adjoining\n some square roots. When this happens, the :class:`FusionRing` is\n modified, adding an attribute ``_basecoer`` that is\n a coercion from the cyclotomic field to the field\n containing the F-matrix. The field containing the F-matrix\n is available through :meth:`field`. ::\n\n sage: f = FusionRing("B3", 2).get_fmatrix()\n sage: f.find_orthogonal_solution(verbose=False, checkpoint=True) # not tested (~100 s)\n sage: all(v in CyclotomicField(56) for v in f.get_fvars().values()) # not tested\n True\n\n sage: f = FusionRing("G2", 2).get_fmatrix()\n sage: f.find_orthogonal_solution(verbose=False) # long time (~11 s)\n sage: f.field() # long time\n Algebraic Field\n ' def __init__(self, fusion_ring, fusion_label='f', var_prefix='fx', inject_variables=False): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: f = FusionRing("B3", 2).get_fmatrix()\n sage: TestSuite(f).run(skip="_test_pickling")\n ' self._FR = fusion_ring if (inject_variables and (self._FR._fusion_labels is None)): self._FR.fusion_labels(fusion_label, inject_variables=True) if (not self._FR.is_multiplicity_free()): raise NotImplementedError('FMatrix is only available for multiplicity free FusionRings') n_vars = self.findcases() self._poly_ring = PolynomialRing(self._FR.field(), n_vars, var_prefix) if inject_variables: print(('creating variables %s%s..%s%s' % (var_prefix, 1, var_prefix, n_vars))) self._poly_ring.inject_variables(get_main_globals()) (self._idx_to_sextuple, self._fvars) = self.findcases(output=True) self._field = self._FR.field() r = self._field.defining_polynomial().roots(ring=QQbar, multiplicities=False)[0] self._qqbar_embedding = self._field.hom([r], QQbar) self._chkpt_status = (- 1) self.mp_thresh = 10000 self.pool = None def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: FusionRing("B2", 1).get_fmatrix()\n F-Matrix factory for The Fusion Ring of Type B2 and level 1 with Integer Ring coefficients\n ' return ('F-Matrix factory for %s' % self._FR) def clear_equations(self): '\n Clear the list of equations to be solved.\n\n EXAMPLES::\n\n sage: f = FusionRing("E6", 1).get_fmatrix()\n sage: f.get_defining_equations(\'hexagons\', output=False)\n sage: len(f.ideal_basis)\n 6\n sage: f.clear_equations()\n sage: len(f.ideal_basis) == 0\n True\n ' self.ideal_basis = [] def clear_vars(self): '\n Reset the F-symbols.\n\n EXAMPLES::\n\n sage: f = FusionRing("C4", 1).get_fmatrix()\n sage: fvars = f.get_fvars()\n sage: some_key = sorted(fvars)[0]\n sage: fvars[some_key]\n fx0\n sage: fvars[some_key] = 1\n sage: f.get_fvars()[some_key]\n 1\n sage: f.clear_vars()\n sage: f.get_fvars()[some_key]\n fx0\n ' self._fvars = {t: self._poly_ring.gen(idx) for (idx, t) in self._idx_to_sextuple.items()} self._solved = ([False] * self._poly_ring.ngens()) def _reset_solver_state(self): '\n Reset solver state and clear relevant cache.\n\n Used to ensure state variables are the same for each\n orthogonal solver run.\n\n EXAMPLES::\n\n sage: f = FusionRing("G2", 1).get_fmatrix()\n sage: f._reset_solver_state()\n sage: K = f.field()\n sage: len(f._nnz.nonzero_positions())\n 1\n sage: f.find_orthogonal_solution(verbose=False)\n sage: K == f.field()\n False\n sage: f._reset_solver_state()\n sage: K == f.field()\n True\n sage: f.FR()._basecoer is None\n True\n sage: f._poly_ring.base_ring() == K\n True\n sage: sum(f._solved) == 0\n True\n sage: len(f.ideal_basis) == 0\n True\n sage: for k, v in f._ks.items():\n ....: k\n sage: len(f._nnz.nonzero_positions()) == 1\n True\n sage: all(len(x.q_dimension.cache) == 0 for x in f.FR().basis())\n True\n sage: len(f.FR().r_matrix.cache) == 0\n True\n sage: len(f.FR().s_ij.cache) == 0\n True\n ' self._FR._basecoer = None self._field = self._FR.field() self._non_cyc_roots = [] self._poly_ring = self._poly_ring.change_ring(self._field) self._chkpt_status = (- 1) self.clear_vars() self.clear_equations() n = self._poly_ring.ngens() self._var_degs = ([0] * n) self._kp = {} self._ks = KSHandler(n, self._field) self._singles = self.get_fvars_by_size(1, indices=True) self._nnz = self._get_known_nonz() [x.q_dimension.clear_cache() for x in self._FR.basis()] self._FR.r_matrix.clear_cache() self._FR.s_ij.clear_cache() def fmat(self, a, b, c, d, x, y, data=True): '\n Return the F-Matrix coefficient `(F^{a, b, c}_d)_{x, y}`.\n\n EXAMPLES::\n\n sage: fr = FusionRing("G2", 1, fusion_labels=("i0", "t"), inject_variables=True)\n sage: f = fr.get_fmatrix()\n sage: [f.fmat(t, t, t, t, x, y) for x in fr.basis() for y in fr.basis()]\n [fx1, fx2, fx3, fx4]\n sage: f.find_cyclotomic_solution(output=True)\n Setting up hexagons and pentagons...\n Finding a Groebner basis...\n Solving...\n Fixing the gauge...\n adding equation... fx2 - 1\n Done!\n {(t, t, t, i0, t, t): 1,\n (t, t, t, t, i0, i0): (-zeta60^14 + zeta60^6 + zeta60^4 - 1),\n (t, t, t, t, i0, t): 1,\n (t, t, t, t, t, i0): (-zeta60^14 + zeta60^6 + zeta60^4 - 1),\n (t, t, t, t, t, t): (zeta60^14 - zeta60^6 - zeta60^4 + 1)}\n sage: [f.fmat(t, t, t, t, x, y) for x in f._FR.basis() for y in f._FR.basis()]\n [(-zeta60^14 + zeta60^6 + zeta60^4 - 1),\n 1,\n (-zeta60^14 + zeta60^6 + zeta60^4 - 1),\n (zeta60^14 - zeta60^6 - zeta60^4 + 1)]\n ' if ((self._FR.Nk_ij(a, b, x) == 0) or (self._FR.Nk_ij(x, c, d) == 0) or (self._FR.Nk_ij(b, c, y) == 0) or (self._FR.Nk_ij(a, y, d) == 0)): return 0 if (a == self._FR.one()): if ((x == b) and (y == d)): return 1 else: return 0 if (b == self._FR.one()): if ((x == a) and (y == c)): return 1 else: return 0 if (c == self._FR.one()): if ((x == d) and (y == b)): return 1 else: return 0 if data: try: return self._fvars[(a, b, c, d, x, y)] except KeyError: return 0 else: return (a, b, c, d, x, y) def fmatrix(self, a, b, c, d): '\n Return the F-Matrix `F^{a, b, c}_d`.\n\n INPUT:\n\n - ``a, b, c, d`` -- basis elements of the associated :class:`FusionRing`\n\n EXAMPLES::\n\n sage: fr = FusionRing("A1", 2, fusion_labels="c", inject_variables=True)\n sage: f = fr.get_fmatrix(new=True)\n sage: f.fmatrix(c1, c1, c1, c1)\n [fx0 fx1]\n [fx2 fx3]\n sage: f.find_cyclotomic_solution(verbose=False);\n adding equation... fx4 - 1\n adding equation... fx10 - 1\n sage: f.f_from(c1, c1, c1, c1)\n [c0, c2]\n sage: f.f_to(c1, c1, c1, c1)\n [c0, c2]\n sage: f.fmatrix(c1, c1, c1, c1)\n [ (1/2*zeta32^12 - 1/2*zeta32^4) (-1/2*zeta32^12 + 1/2*zeta32^4)]\n [ (1/2*zeta32^12 - 1/2*zeta32^4) (1/2*zeta32^12 - 1/2*zeta32^4)]\n ' X = self.f_from(a, b, c, d) Y = self.f_to(a, b, c, d) return matrix([[self.fmat(a, b, c, d, x, y) for y in Y] for x in X]) def field(self): '\n Return the base field containing the F-symbols.\n\n When ``self`` is initialized, the field is set to be the\n cyclotomic field of the :class:`FusionRing` associated\n to ``self``.\n\n The field may change after running :meth:`find_orthogonal_solution`.\n At that point, this method could return the\n associated :class:`FusionRing`\'s cyclotomic field, an\n appropriate :func:`NumberField` that was computed on the fly\n by the F-matrix solver, or the :class:`QQbar<AlgebraicField>`.\n\n Depending on the ``CartanType`` of ``self``, the solver may need\n to compute an extension field containing certain square roots that\n do not belong to the associated :class:`FusionRing`\'s cyclotomic field.\n\n In certain cases we revert to :class:`QQbar<AlgebraicField>` because\n the extension field computation does not seem to terminate. See\n :meth:`attempt_number_field_computation` for more details.\n\n The method :meth:`get_non_cyclotomic_roots` returns a list of\n roots defining the extension of the :class:`FusionRing`\'s\n cyclotomic field needed to contain all F-symbols.\n\n EXAMPLES::\n\n sage: f = FusionRing("G2", 1).get_fmatrix()\n sage: f.field()\n Cyclotomic Field of order 60 and degree 16\n sage: f.find_orthogonal_solution(verbose=False)\n sage: f.field()\n Number Field in a with defining polynomial y^32 - ... - 22*y^2 + 1\n sage: phi = f.get_qqbar_embedding()\n sage: [phi(r).n() for r in f.get_non_cyclotomic_roots()]\n [-0.786151377757423 - 8.92806368517581e-31*I]\n\n .. NOTE::\n\n Consider using ``self.field().optimized_representation()`` to\n obtain an equivalent :func:`NumberField` with a defining\n polynomial with smaller coefficients, for a more efficient\n element representation.\n ' return self._field def FR(self): '\n Return the :class:`FusionRing` associated to ``self``.\n\n EXAMPLES::\n\n sage: f = FusionRing("D3", 1).get_fmatrix()\n sage: f.FR()\n The Fusion Ring of Type D3 and level 1 with Integer Ring coefficients\n ' return self._FR def findcases(self, output=False): '\n Return unknown F-matrix entries.\n\n If run with ``output=True``,\n this returns two dictionaries; otherwise it just returns the\n number of unknown values.\n\n EXAMPLES::\n\n sage: f = FusionRing("G2", 1, fusion_labels=("i0", "t")).get_fmatrix()\n sage: f.findcases()\n 5\n sage: f.findcases(output=True)\n ({0: (t, t, t, i0, t, t),\n 1: (t, t, t, t, i0, i0),\n 2: (t, t, t, t, i0, t),\n 3: (t, t, t, t, t, i0),\n 4: (t, t, t, t, t, t)},\n {(t, t, t, i0, t, t): fx0,\n (t, t, t, t, i0, i0): fx1,\n (t, t, t, t, i0, t): fx2,\n (t, t, t, t, t, i0): fx3,\n (t, t, t, t, t, t): fx4})\n ' i = 0 if output: idx_map = {} ret = {} id_anyon = self._FR.one() for (a, b, c, d) in product(self._FR.basis(), repeat=4): if ((a == id_anyon) or (b == id_anyon) or (c == id_anyon)): continue for x in self.f_from(a, b, c, d): for y in self.f_to(a, b, c, d): if output: v = self._poly_ring.gen(i) ret[(a, b, c, d, x, y)] = v idx_map[i] = (a, b, c, d, x, y) i += 1 if output: return (idx_map, ret) else: return i def f_from(self, a, b, c, d): '\n Return the possible `x` such that there are morphisms\n `d \\to x \\otimes c \\to (a \\otimes b) \\otimes c`.\n\n INPUT:\n\n - ``a, b, c, d`` -- basis elements of the associated :class:`FusionRing`\n\n EXAMPLES::\n\n sage: fr = FusionRing("A1", 3, fusion_labels="a", inject_variables=True)\n sage: f = fr.get_fmatrix()\n sage: f.fmatrix(a1, a1, a2, a2)\n [fx6 fx7]\n [fx8 fx9]\n sage: f.f_from(a1, a1, a2, a2)\n [a0, a2]\n sage: f.f_to(a1, a1, a2, a2)\n [a1, a3]\n ' return [x for x in self._FR.basis() if ((self._FR.Nk_ij(a, b, x) != 0) and (self._FR.Nk_ij(x, c, d) != 0))] def f_to(self, a, b, c, d): '\n Return the possible `y` such that there are morphisms\n `d \\to a \\otimes y \\to a \\otimes (b \\otimes c)`.\n\n INPUT:\n\n - ``a, b, c, d`` -- basis elements of the associated :class:`FusionRing`\n\n EXAMPLES::\n\n sage: b22 = FusionRing("B2", 2)\n sage: b22.fusion_labels("b", inject_variables=True)\n sage: B = b22.get_fmatrix()\n sage: B.fmatrix(b2, b4, b2, b4)\n [fx266 fx267 fx268]\n [fx269 fx270 fx271]\n [fx272 fx273 fx274]\n sage: B.f_from(b2, b4, b2, b4)\n [b1, b3, b5]\n sage: B.f_to(b2, b4, b2, b4)\n [b1, b3, b5]\n ' return [y for y in self._FR.basis() if ((self._FR.Nk_ij(b, c, y) != 0) and (self._FR.Nk_ij(a, y, d) != 0))] def get_fvars(self): '\n Return a dictionary of F-symbols.\n\n The keys are sextuples `(a, b, c, d, x, y)` of basis elements of\n ``self.FR()`` and the values are the corresponding F-symbols\n `(F^{a, b, c}_d)_{xy}`.\n\n These values reflect the current state of a solver\'s computation.\n\n EXAMPLES::\n\n sage: f = FusionRing("A2", 1).get_fmatrix(inject_variables=True)\n creating variables fx1..fx8\n Defining fx0, fx1, fx2, fx3, fx4, fx5, fx6, fx7\n sage: f.get_fvars()[(f1, f1, f1, f0, f2, f2)]\n fx0\n sage: f.find_orthogonal_solution(verbose=False)\n sage: f.get_fvars()[(f1, f1, f1, f0, f2, f2)]\n 1\n ' return self._fvars def get_poly_ring(self): '\n Return the polynomial ring whose generators denote the desired F-symbols.\n\n EXAMPLES::\n\n sage: f = FusionRing("B6", 1).get_fmatrix()\n sage: f.get_poly_ring()\n Multivariate Polynomial Ring in fx0, ..., fx13 over\n Cyclotomic Field of order 96 and degree 32\n ' return self._poly_ring def get_non_cyclotomic_roots(self): '\n Return a list of roots that define the extension of the associated\n :class:`FusionRing`\'s base\n :class:`Cyclotomic field<sage.rings.number_field.number_field.CyclotomicFieldFactory>`,\n containing all the F-symbols.\n\n OUTPUT:\n\n The list of non-cyclotomic roots is given as a list of elements of the\n field returned by :meth:`field()`.\n\n If ``self.field() == self.FR().field()`` then this method\n returns an empty list.\n\n EXAMPLES::\n\n sage: f = FusionRing("E6", 1).get_fmatrix()\n sage: f.find_orthogonal_solution(verbose=False)\n sage: f.field() == f.FR().field()\n True\n sage: f.get_non_cyclotomic_roots()\n []\n sage: f = FusionRing("G2", 1).get_fmatrix()\n sage: f.find_orthogonal_solution(verbose=False)\n sage: f.field() == f.FR().field()\n False\n sage: phi = f.get_qqbar_embedding()\n sage: [phi(r).n() for r in f.get_non_cyclotomic_roots()]\n [-0.786151377757423 - 8.92806368517581e-31*I]\n\n When ``self.field()`` is a ``NumberField``, one may use\n :meth:`get_qqbar_embedding` to embed the resulting values into\n :class:`QQbar<AlgebraicField>`.\n ' return sorted(set(self._non_cyc_roots)) def get_qqbar_embedding(self): '\n Return an embedding from the base field containing F-symbols (the\n associated :class:`FusionRing`\'s\n :class:`Cyclotomic field<sage.rings.number_field.number_field.CyclotomicFieldFactory>`,\n a :func:`NumberField`, or :class:`QQbar<AlgebraicField>`) into\n :class:`QQbar<AlgebraicField>`.\n\n This embedding is useful for getting a better sense for the\n F-symbols, particularly when they are computed as elements of a\n :func:`NumberField`. See also :meth:`get_non_cyclotomic_roots`.\n\n EXAMPLES::\n\n sage: fr = FusionRing("G2", 1)\n sage: f = fr.get_fmatrix(fusion_label="g", inject_variables=True, new=True)\n creating variables fx1..fx5\n Defining fx0, fx1, fx2, fx3, fx4\n sage: f.find_orthogonal_solution()\n Computing F-symbols for The Fusion Ring of Type G2 and level 1 with Integer Ring coefficients with 5 variables...\n Set up 10 hex and orthogonality constraints...\n Partitioned 10 equations into 2 components of size:\n [4, 1]\n Elimination epoch completed... 0 eqns remain in ideal basis\n Hex elim step solved for 4 / 5 variables\n Set up 0 reduced pentagons...\n Pent elim step solved for 4 / 5 variables\n Partitioned 0 equations into 0 components of size:\n []\n Partitioned 1 equations into 1 components of size:\n [1]\n Computing appropriate NumberField...\n sage: phi = f.get_qqbar_embedding()\n sage: phi(f.fmat(g1, g1, g1, g1, g1, g1)).n()\n -0.618033988749895 + 1.46674215951686e-29*I\n ' return self._qqbar_embedding def get_coerce_map_from_fr_cyclotomic_field(self): '\n Return a coercion map from the associated :class:`FusionRing`\'s\n cyclotomic field into the base field containing all F-symbols\n (this could be the :class:`FusionRing`\'s\n :class:`Cyclotomic field<sage.rings.number_field.number_field.CyclotomicFieldFactory>`,\n a :func:`NumberField`, or :class:`QQbar<AlgebraicField>`).\n\n EXAMPLES::\n\n sage: f = FusionRing("G2", 1).get_fmatrix()\n sage: f.find_orthogonal_solution(verbose=False)\n sage: f.FR().field()\n Cyclotomic Field of order 60 and degree 16\n sage: f.field()\n Number Field in a with defining polynomial y^32 - ... - 22*y^2 + 1\n sage: phi = f.get_coerce_map_from_fr_cyclotomic_field()\n sage: phi.domain() == f.FR().field()\n True\n sage: phi.codomain() == f.field()\n True\n\n When F-symbols are computed as elements of the associated\n :class:`FusionRing`\'s base\n :class:`Cyclotomic field<sage.rings.number_field.number_field.CyclotomicFieldFactory>`,\n we have ``self.field() == self.FR().field()`` and this\n returns the identity map on ``self.field()``. ::\n\n sage: f = FusionRing("A2", 1).get_fmatrix()\n sage: f.find_orthogonal_solution(verbose=False)\n sage: phi = f.get_coerce_map_from_fr_cyclotomic_field()\n sage: f.field()\n Cyclotomic Field of order 48 and degree 16\n sage: f.field() == f.FR().field()\n True\n sage: phi.domain() == f.field()\n True\n sage: phi.is_identity()\n True\n ' try: return self._coerce_map_from_cyc_field except AttributeError: F = self._FR.field() return F.hom([F.gen()], F) def get_fvars_in_alg_field(self): '\n Return F-symbols as elements of the :class:`QQbar<AlgebraicField>`.\n\n This method uses the embedding defined by\n :meth:`get_qqbar_embedding` to coerce\n F-symbols into :class:`QQbar<AlgebraicField>`.\n\n EXAMPLES::\n\n sage: fr = FusionRing("G2", 1)\n sage: f = fr.get_fmatrix(fusion_label="g", inject_variables=True, new=True)\n creating variables fx1..fx5\n Defining fx0, fx1, fx2, fx3, fx4\n sage: f.find_orthogonal_solution(verbose=False)\n sage: f.field()\n Number Field in a with defining polynomial y^32 - ... - 22*y^2 + 1\n sage: f.get_fvars_in_alg_field()\n {(g1, g1, g1, g0, g1, g1): 1,\n (g1, g1, g1, g1, g0, g0): 0.61803399? + 0.?e-8*I,\n (g1, g1, g1, g1, g0, g1): -0.7861514? + 0.?e-8*I,\n (g1, g1, g1, g1, g1, g0): -0.7861514? + 0.?e-8*I,\n (g1, g1, g1, g1, g1, g1): -0.61803399? + 0.?e-8*I}\n ' return {sextuple: self._qqbar_embedding(fvar) for (sextuple, fvar) in self._fvars.items()} def get_radical_expression(self): '\n Return a radical expression of F-symbols.\n\n EXAMPLES::\n\n sage: f = FusionRing("G2", 1).get_fmatrix()\n sage: f.FR().fusion_labels("g", inject_variables=True)\n sage: f.find_orthogonal_solution(verbose=False)\n sage: radical_fvars = f.get_radical_expression() # long time (~1.5s)\n sage: radical_fvars[g1, g1, g1, g1, g1, g0] # long time\n -sqrt(1/2*sqrt(5) - 1/2)\n ' return {sextuple: val.radical_expression() for (sextuple, val) in self.get_fvars_in_alg_field().items()} def _get_known_vals(self): '\n Construct a dictionary of ``idx``, ``known_val`` pairs used for\n substituting into remaining equations.\n\n EXAMPLES::\n\n sage: f = FusionRing("D4", 1).get_fmatrix()\n sage: f._reset_solver_state()\n sage: len(f._get_known_vals()) == 0\n True\n sage: f.find_orthogonal_solution(verbose=False)\n sage: len(f._get_known_vals()) == f._poly_ring.ngens()\n True\n ' return {i: self._fvars[s] for (i, s) in self._idx_to_sextuple.items() if self._solved[i]} def _get_known_nonz(self): '\n Construct an :class:`ETuple` indicating positions of\n known nonzero variables.\n\n .. NOTE::\n\n MUST be called after ``self._ks = _get_known_sq()``.\n This method is called by the constructor of ``self``.\n\n EXAMPLES::\n\n sage: f = FusionRing("D5", 1).get_fmatrix() # indirect doctest\n sage: f._reset_solver_state()\n sage: f._nnz\n (100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,\n 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100)\n ' nonz = {idx: 100 for idx in self._singles} for (idx, v) in self._ks.items(): nonz[idx] = 100 return ETuple(nonz, self._poly_ring.ngens()) def largest_fmat_size(self): '\n Get the size of the largest F-matrix `F^{abc}_d`.\n\n EXAMPLES::\n\n sage: f = FusionRing("B3", 2).get_fmatrix()\n sage: f.largest_fmat_size()\n 4\n ' return max((self.fmatrix(*tup).nrows() for tup in product(self._FR.basis(), repeat=4))) def get_fvars_by_size(self, n, indices=False): '\n Return the set of F-symbols that are entries of an `n \\times n` matrix\n `F^{a, b, c}_d`.\n\n INPUT:\n\n - `n` -- a positive integer\n - ``indices`` -- boolean (default: ``False``)\n\n If ``indices`` is ``False`` (default),\n this method returns a set of sextuples `(a, b, c, d, x, y)` identifying\n the corresponding F-symbol. Each sextuple is a key in the\n dictionary returned by :meth:`get_fvars`.\n\n Otherwise the method returns a list of integer indices that\n internally identify the F-symbols. The ``indices=True`` option is\n meant for internal use.\n\n EXAMPLES::\n\n sage: f = FusionRing("A2", 2).get_fmatrix(inject_variables=True)\n creating variables fx1..fx287\n Defining fx0, ..., fx286\n sage: f.largest_fmat_size()\n 2\n sage: f.get_fvars_by_size(2)\n {(f2, f2, f2, f4, f1, f1),\n (f2, f2, f2, f4, f1, f5),\n ...\n (f4, f4, f4, f4, f4, f0),\n (f4, f4, f4, f4, f4, f4)}\n ' var_set = set() one = self._FR.one() for (a, b, c, d) in product(self._FR.basis(), repeat=4): X = self.f_from(a, b, c, d) Y = self.f_to(a, b, c, d) if ((len(X) == n) and (len(Y) == n)): for x in X: for y in Y: trivial = ((a == one) and (x == b) and (y == d)) trivial |= ((b == one) and (x == a) and (y == c)) trivial |= ((c == one) and (x == d) and (y == b)) if (not trivial): var_set.add((a, b, c, d, x, y)) if indices: sext_to_idx = {v: k for (k, v) in self._idx_to_sextuple.items()} return {sext_to_idx[fx] for fx in var_set} return var_set def save_fvars(self, filename): '\n Save computed F-symbols for later use.\n\n INPUT:\n\n - ``filename`` -- a string specifying the name of the pickle file\n to be used\n\n The current directory is used unless an absolute path to a file in\n a different directory is provided.\n\n .. NOTE::\n\n This method should only be used *after* successfully running one\n of the solvers, e.g. :meth:`find_cyclotomic_solution` or\n :meth:`find_orthogonal_solution`.\n\n When used in conjunction with :meth:`load_fvars`, this method may\n be used to restore state of an :class:`FMatrix` object at the end\n of a successful F-matrix solver run.\n\n EXAMPLES::\n\n sage: f = FusionRing("A2", 1).get_fmatrix(new=True)\n sage: f.find_orthogonal_solution(verbose=False)\n sage: fvars = f.get_fvars()\n sage: K = f.field()\n sage: filename = f.get_fr_str() + "_solver_results.pickle"\n sage: f.save_fvars(filename)\n sage: del f\n sage: f2 = FusionRing("A2", 1).get_fmatrix(new=True)\n sage: f2.load_fvars(filename)\n sage: fvars == f2.get_fvars()\n True\n sage: K == f2.field()\n True\n sage: os.remove(filename)\n ' final_state = [self._fvars, self._non_cyc_roots, self.get_coerce_map_from_fr_cyclotomic_field(), self._qqbar_embedding] with open(filename, 'wb') as f: pickle.dump(final_state, f) def load_fvars(self, filename): '\n Load previously computed F-symbols from a pickle file.\n\n See :meth:`save_fvars` for more information.\n\n EXAMPLES::\n\n sage: f = FusionRing("A2", 1).get_fmatrix(new=True)\n sage: f.find_orthogonal_solution(verbose=False)\n sage: fvars = f.get_fvars()\n sage: K = f.field()\n sage: filename = f.get_fr_str() + "_solver_results.pickle"\n sage: f.save_fvars(filename)\n sage: del f\n sage: f2 = FusionRing("A2", 1).get_fmatrix(new=True)\n sage: f2.load_fvars(filename)\n sage: fvars == f2.get_fvars()\n True\n sage: K == f2.field()\n True\n sage: os.remove(filename)\n\n .. NOTE::\n\n :meth:`save_fvars`. This method does not work with intermediate\n checkpoint pickles; it only works with pickles containing *all*\n F-symbols, i.e. those created by :meth:`save_fvars` and by\n specifying an optional ``save_results`` parameter for\n :meth:`find_orthogonal_solution`.\n ' with open(filename, 'rb') as f: (self._fvars, self._non_cyc_roots, self._coerce_map_from_cyc_field, self._qqbar_embedding) = pickle.load(f) self._chkpt_status = 7 self._solved = [True for v in self._fvars] self._field = self._qqbar_embedding.domain() def get_fr_str(self): '\n Auto-generate an identifying key for saving results.\n\n EXAMPLES::\n\n sage: f = FusionRing("B3", 1).get_fmatrix()\n sage: f.get_fr_str()\n \'B31\'\n ' ct = self._FR.cartan_type() return ((ct.letter + str(ct.n)) + str(self._FR.fusion_level())) def _checkpoint(self, do_chkpt, status, verbose=True): '\n Pickle current solver state.\n\n EXAMPLES::\n\n sage: f = FusionRing("A1", 3).get_fmatrix(new=True)\n sage: f._reset_solver_state()\n sage: f.get_orthogonality_constraints(output=False)\n sage: f.get_defining_equations(\'hexagons\', output=False)\n sage: f.ideal_basis = f._par_graph_gb(verbose=False)\n sage: from sage.algebras.fusion_rings.poly_tup_engine import poly_tup_sortkey, poly_to_tup\n sage: f.ideal_basis.sort(key=poly_tup_sortkey)\n sage: from sage.algebras.fusion_rings.shm_managers import FvarsHandler\n sage: n = f._poly_ring.ngens()\n sage: f._fvars = FvarsHandler(n, f._field, f._idx_to_sextuple, init_data=f._fvars)\n sage: f._triangular_elim(verbose=False)\n sage: f._update_reduction_params()\n sage: f._checkpoint(do_chkpt=True, status=2)\n Checkpoint 2 reached!\n sage: del f\n sage: f = FusionRing("A1", 3).get_fmatrix(new=True)\n sage: f.find_orthogonal_solution(warm_start="fmatrix_solver_checkpoint_A13.pickle")\n Computing F-symbols for The Fusion Ring of Type A1 and level 3 with Integer Ring coefficients with 71 variables...\n Set up 121 reduced pentagons...\n Elimination epoch completed... 18 eqns remain in ideal basis\n Elimination epoch completed... 5 eqns remain in ideal basis\n Pent elim step solved for 64 / 71 variables\n Partitioned 5 equations into 1 components of size:\n [4]\n Elimination epoch completed... 0 eqns remain in ideal basis\n Partitioned 6 equations into 6 components of size:\n [1, 1, 1, 1, 1, 1]\n Computing appropriate NumberField...\n sage: f._chkpt_status == 7\n True\n sage: sum(f._solved) == f._poly_ring.ngens()\n True\n sage: os.remove("fmatrix_solver_checkpoint_A13.pickle")\n sage: f = FusionRing("A1", 2).get_fmatrix(new=True)\n sage: f._reset_solver_state()\n sage: f.get_orthogonality_constraints(output=False)\n sage: f.get_defining_equations(\'hexagons\', output=False)\n sage: f.ideal_basis = f._par_graph_gb(verbose=False)\n sage: from sage.algebras.fusion_rings.poly_tup_engine import poly_tup_sortkey\n sage: f.ideal_basis.sort(key=poly_tup_sortkey)\n sage: from sage.algebras.fusion_rings.shm_managers import FvarsHandler\n sage: n = f._poly_ring.ngens()\n sage: f._fvars = FvarsHandler(n, f._field, f._idx_to_sextuple, init_data=f._fvars)\n sage: f._triangular_elim(verbose=False)\n sage: f._update_reduction_params()\n sage: f.get_defining_equations(\'pentagons\', output=False)\n sage: f.ideal_basis.sort(key=poly_tup_sortkey)\n sage: f._triangular_elim(verbose=False)\n sage: f._checkpoint(do_chkpt=True, status=4)\n Checkpoint 4 reached!\n sage: del f\n sage: f = FusionRing("A1", 2).get_fmatrix(new=True)\n sage: f.find_orthogonal_solution(warm_start="fmatrix_solver_checkpoint_A12.pickle")\n Computing F-symbols for The Fusion Ring of Type A1 and level 2 with Integer Ring coefficients with 14 variables...\n Partitioned 0 equations into 0 components of size:\n []\n Partitioned 2 equations into 2 components of size:\n [1, 1]\n sage: f._chkpt_status == 7\n True\n sage: sum(f._solved) == f._poly_ring.ngens()\n True\n sage: os.remove("fmatrix_solver_checkpoint_A12.pickle")\n ' if (not do_chkpt): return filename = (('fmatrix_solver_checkpoint_' + self.get_fr_str()) + '.pickle') with open(filename, 'wb') as f: pickle.dump([self._fvars, list(self._solved), self._ks, self.ideal_basis, status], f) if verbose: print(f'Checkpoint {status} reached!') def _restore_state(self, filename): '\n Load solver state from file. Use this method both for warm-starting\n :meth:`find_orthogonal_solution` and to load pickled results.\n\n EXAMPLES::\n\n sage: f = FusionRing("A1", 2).get_fmatrix(new=True)\n sage: f._reset_solver_state()\n sage: f.get_orthogonality_constraints(output=False)\n sage: f.get_defining_equations(\'hexagons\', output=False)\n sage: f.ideal_basis = f._par_graph_gb(verbose=False)\n sage: from sage.algebras.fusion_rings.poly_tup_engine import poly_tup_sortkey, poly_to_tup\n sage: f.ideal_basis.sort(key=poly_tup_sortkey)\n sage: from sage.algebras.fusion_rings.shm_managers import FvarsHandler\n sage: n = f._poly_ring.ngens()\n sage: f._fvars = FvarsHandler(n, f._field, f._idx_to_sextuple, init_data=f._fvars)\n sage: f._triangular_elim(verbose=False)\n sage: f._update_reduction_params()\n sage: fvars = f._fvars\n sage: ib = f.ideal_basis\n sage: solved = f._solved\n sage: ks = f._ks\n sage: status = f._chkpt_status\n sage: f._checkpoint(do_chkpt=True, status=2)\n Checkpoint 2 reached!\n sage: del f\n sage: f = FusionRing("A1", 2).get_fmatrix(new=True)\n sage: f._reset_solver_state()\n sage: f._restore_state("fmatrix_solver_checkpoint_A12.pickle")\n sage: for sextuple, fvar in fvars.items():\n ....: assert fvar == f._fvars[sextuple]\n ....:\n sage: ib == f.ideal_basis\n True\n sage: ks == f._ks\n True\n sage: solved == f._solved\n True\n sage: 2 == f._chkpt_status\n True\n sage: os.remove("fmatrix_solver_checkpoint_A12.pickle")\n\n TESTS::\n\n sage: f = FusionRing("A1", 3).get_fmatrix(new=True)\n sage: f.find_orthogonal_solution(save_results="test.pickle", verbose=False) # long time\n sage: del f\n sage: f = FusionRing("A1", 3).get_fmatrix(new=True)\n sage: f.find_orthogonal_solution(warm_start="test.pickle") # long time\n sage: f._chkpt_status == 7 # long time\n True\n sage: os.remove("test.pickle") # long time\n ' with open(filename, 'rb') as f: state = pickle.load(f) if (len(state) == 4): self.load_fvars(filename) self._chkpt_status = 7 return (self._fvars, self._solved, self._ks, self.ideal_basis, self._chkpt_status) = state self._update_reduction_params() def start_worker_pool(self, processes=None): '\n Initialize a ``multiprocessing`` worker pool for parallel processing,\n which may be used e.g. to set up defining equations using\n :meth:`get_defining_equations`.\n\n This method sets ``self``\'s ``pool`` attribute. The worker\n pool may be used time and again. Upon initialization, each process\n in the pool attaches to the necessary shared memory resources.\n\n When you are done using the worker pool, use\n :meth:`shutdown_worker_pool` to close the pool and properly dispose\n of shared memory resources.\n\n INPUT:\n\n - ``processes`` -- an integer indicating the number of workers\n in the pool; if left unspecified, the number of workers is\n equals the number of processors available\n\n OUTPUT:\n\n This method returns a boolean indicating whether a worker pool\n was successfully initialized.\n\n EXAMPLES::\n\n sage: f = FusionRing("G2", 1).get_fmatrix(new=True)\n sage: f.start_worker_pool()\n sage: he = f.get_defining_equations(\'hexagons\')\n sage: sorted(he)\n [fx0 - 1,\n fx2*fx3 + (zeta60^14 + zeta60^12 - zeta60^6 - zeta60^4 + 1)*fx4^2 + (zeta60^6)*fx4,\n fx1*fx3 + (zeta60^14 + zeta60^12 - zeta60^6 - zeta60^4 + 1)*fx3*fx4 + (zeta60^14 - zeta60^4)*fx3,\n fx1*fx2 + (zeta60^14 + zeta60^12 - zeta60^6 - zeta60^4 + 1)*fx2*fx4 + (zeta60^14 - zeta60^4)*fx2,\n fx1^2 + (zeta60^14 + zeta60^12 - zeta60^6 - zeta60^4 + 1)*fx2*fx3 + (-zeta60^12)*fx1]\n sage: pe = f.get_defining_equations(\'pentagons\')\n sage: f.shutdown_worker_pool()\n\n .. WARNING::\n\n This method is needed to initialize the worker pool using the\n necessary shared memory resources. Simply using the\n ``multiprocessing.Pool`` constructor will not work with our\n class methods.\n\n .. WARNING::\n\n Failure to call :meth:`shutdown_worker_pool` may result in a memory\n leak, since shared memory resources outlive the process that created\n them.\n ' try: set_start_method('fork') except RuntimeError: pass if (not hasattr(self, '_nnz')): self._reset_solver_state() n_proc = (cpu_count() if (processes is None) else processes) self._pid_list = shared_memory.ShareableList(([0] * (n_proc + 1))) pids_name = self._pid_list.shm.name self._solved = shared_memory.ShareableList(self._solved) s_name = self._solved.shm.name self._var_degs = shared_memory.ShareableList(self._var_degs) vd_name = self._var_degs.shm.name n = self._poly_ring.ngens() self._ks = KSHandler(n, self._field, use_mp=True, init_data=self._ks) ks_names = self._ks.shm.name self._shared_fvars = FvarsHandler(n, self._field, self._idx_to_sextuple, use_mp=n_proc, pids_name=pids_name, init_data=self._fvars) fvar_names = self._shared_fvars.shm.name args = (id(self), s_name, vd_name, ks_names, fvar_names, n_proc, pids_name) def init(fmats_id, solved_name, vd_name, ks_names, fvar_names, n_proc, pids_name): '\n Connect worker process to shared memory resources\n ' fmats_obj = cast(fmats_id, py_object).value fmats_obj._solved = shared_memory.ShareableList(name=solved_name) fmats_obj._var_degs = shared_memory.ShareableList(name=vd_name) n = fmats_obj._poly_ring.ngens() K = fmats_obj._field fmats_obj._fvars = FvarsHandler(n, K, fmats_obj._idx_to_sextuple, name=fvar_names, use_mp=n_proc, pids_name=pids_name) fmats_obj._ks = KSHandler(n, K, name=ks_names, use_mp=True) self.pool = Pool(processes=n_proc, initializer=init, initargs=args) self._pid_list[0] = getpid() for (i, p) in enumerate(self.pool._pool): self._pid_list[(i + 1)] = p.pid def shutdown_worker_pool(self): '\n Shutdown the given worker pool and dispose of shared memory resources\n created when the pool was set up using :meth:`start_worker_pool`.\n\n .. WARNING::\n\n Failure to call this method after using :meth:`start_worker_pool`\n to create a process pool may result in a memory\n leak, since shared memory resources outlive the process that\n created them.\n\n EXAMPLES::\n\n sage: f = FusionRing("A1", 3).get_fmatrix(new=True)\n sage: f.start_worker_pool()\n sage: he = f.get_defining_equations(\'hexagons\')\n sage: f.shutdown_worker_pool()\n ' if (self.pool is not None): self.pool.close() self.pool = None self._solved.shm.unlink() self._var_degs.shm.unlink() self._ks.shm.unlink() self._shared_fvars.shm.unlink() self._pid_list.shm.unlink() del self.__dict__['_shared_fvars'] def _map_triv_reduce(self, mapper, input_iter, worker_pool=None, chunksize=None, mp_thresh=None): '\n Apply the given mapper to each element of the given input iterable and\n return the results (with no duplicates) in a list.\n\n INPUT:\n\n - ``mapper`` -- string specifying the name of a function defined in\n the ``fast_parallel_fmats_methods`` module\n\n .. NOTE::\n\n If ``worker_pool`` is not provided, function maps and reduces on a\n single process.\n If ``worker_pool`` is provided, the function attempts to determine\n whether it should use multiprocessing based on the length of the\n input iterable. If it can\'t determine the length of the input\n iterable then it uses multiprocessing with the default chunksize of\n `1` unless a chunksize is provided.\n\n EXAMPLES::\n\n sage: f = FusionRing("A1", 2).get_fmatrix()\n sage: f._reset_solver_state()\n sage: len(f._map_triv_reduce(\'get_reduced_hexagons\', [(0, 1, False)]))\n 11\n sage: f.start_worker_pool()\n sage: mp_params = [(i, f.pool._processes, True) for i in range(f.pool._processes)]\n sage: len(f._map_triv_reduce(\'get_reduced_pentagons\', mp_params, worker_pool=f.pool, chunksize=1, mp_thresh=0))\n 33\n sage: f.shutdown_worker_pool()\n ' if (mp_thresh is None): mp_thresh = self.mp_thresh if (worker_pool is not None): try: n = len(input_iter) except (TypeError, ValueError, AttributeError): n = (mp_thresh + 1) if (chunksize is None): chunksize = ((n // (worker_pool._processes ** 2)) + 1) no_mp = ((worker_pool is None) or (n < mp_thresh)) input_iter = zip_longest([], input_iter, fillvalue=(mapper, id(self))) if no_mp: mapped = map(executor, input_iter) else: mapped = worker_pool.imap_unordered(executor, input_iter, chunksize=chunksize) results = set() for child_eqns in mapped: if (child_eqns is not None): results.update(child_eqns) results = list(results) return results def get_orthogonality_constraints(self, output=True): '\n Get equations imposed on the F-matrix by orthogonality.\n\n INPUT:\n\n - ``output`` -- a boolean\n\n OUTPUT:\n\n If ``output=True``, orthogonality constraints are returned as\n polynomial objects.\n\n Otherwise, the constraints are appended to ``self.ideal_basis``.\n They are stored in the internal tuple representation. The\n ``output=False`` option is meant mostly for internal use by the\n F-matrix solver.\n\n EXAMPLES::\n\n sage: f = FusionRing("B4", 1).get_fmatrix()\n sage: f.get_orthogonality_constraints()\n [fx0^2 - 1,\n fx1^2 - 1,\n fx2^2 - 1,\n fx3^2 - 1,\n fx4^2 - 1,\n fx5^2 - 1,\n fx6^2 - 1,\n fx7^2 - 1,\n fx8^2 - 1,\n fx9^2 - 1,\n fx10^2 + fx12^2 - 1,\n fx10*fx11 + fx12*fx13,\n fx10*fx11 + fx12*fx13,\n fx11^2 + fx13^2 - 1]\n ' eqns = [] for tup in product(self._FR.basis(), repeat=4): mat = self.fmatrix(*tup) eqns.extend(((mat.T * mat) - matrix.identity(mat.nrows())).coefficients()) if output: return eqns self.ideal_basis.extend([poly_to_tup(eq) for eq in eqns]) def get_defining_equations(self, option, output=True): '\n Get the equations defining the ideal generated by the hexagon or\n pentagon relations.\n\n INPUT:\n\n - ``option`` -- a string determining equations to be set up:\n\n * ``\'hexagons\'`` - get equations imposed on the F-matrix by\n the hexagon relations in the definition of a braided category\n\n * ``\'pentagons\'`` - get equations imposed on the F-matrix by\n the pentagon relations in the definition of a monoidal category\n\n - ``output`` -- (default: ``True``) a boolean indicating whether\n results should be returned, where the equations will be polynomials.\n Otherwise, the constraints are appended to ``self.ideal_basis``.\n Constraints are stored in the internal tuple representation. The\n ``output=False`` option is meant only for internal use by the\n F-matrix solver. When computing the hexagon equations with the\n ``output=False`` option, the initial state of the F-symbols is used.\n\n .. NOTE::\n\n To set up the defining equations using parallel processing,\n use :meth:`start_worker_pool` to initialize multiple processes\n *before* calling this method.\n\n EXAMPLES::\n\n sage: f = FusionRing("B2", 1).get_fmatrix()\n sage: sorted(f.get_defining_equations(\'hexagons\'))\n [fx7 + 1,\n fx6 - 1,\n fx2 + 1,\n fx0 - 1,\n fx11*fx12 + (-zeta32^8)*fx13^2 + (zeta32^12)*fx13,\n fx10*fx12 + (-zeta32^8)*fx12*fx13 + (zeta32^4)*fx12,\n fx10*fx11 + (-zeta32^8)*fx11*fx13 + (zeta32^4)*fx11,\n fx10^2 + (-zeta32^8)*fx11*fx12 + (-zeta32^12)*fx10,\n fx4*fx9 + fx7,\n fx3*fx8 - fx6,\n fx1*fx5 + fx2]\n sage: pe = f.get_defining_equations(\'pentagons\')\n sage: len(pe)\n 33\n ' if (not hasattr(self, '_nnz')): self._reset_solver_state() n_proc = (self.pool._processes if (self.pool is not None) else 1) params = [(child_id, n_proc, output) for child_id in range(n_proc)] eqns = self._map_triv_reduce(('get_reduced_' + option), params, worker_pool=self.pool, chunksize=1, mp_thresh=0) if output: F = self._field for (i, eq_tup) in enumerate(eqns): eqns[i] = _unflatten_coeffs(F, eq_tup) return [self._tup_to_fpoly(p) for p in eqns] self.ideal_basis.extend(eqns) def _tup_to_fpoly(self, eq_tup): '\n Assemble a polynomial object from its tuple representation.\n\n .. WARNING::\n\n This method avoids implicit casting when constructing a\n polynomial object, and may therefore lead to SEGFAULTs.\n It is meant for internal use by the F-matrix solver.\n\n This method is a left inverse of\n :meth:`sage.algebras.fusion_rings.poly_tup_engine.poly_to_tup`.\n\n EXAMPLES::\n\n sage: f = FusionRing("C3", 1).get_fmatrix()\n sage: f.start_worker_pool()\n sage: he = f.get_defining_equations(\'hexagons\')\n sage: from sage.algebras.fusion_rings.poly_tup_engine import poly_to_tup\n sage: all(f._tup_to_fpoly(poly_to_tup(h)) for h in he)\n True\n sage: f.shutdown_worker_pool()\n ' return _tup_to_poly(eq_tup, parent=self._poly_ring) def _update_reduction_params(self, eqns=None): '\n Update reduction parameters that are solver state attributes.\n\n EXAMPLES::\n\n sage: f = FusionRing("A1", 3).get_fmatrix()\n sage: f._reset_solver_state()\n sage: f.get_orthogonality_constraints(output=False)\n sage: f.start_worker_pool()\n sage: f.get_defining_equations(\'hexagons\', output=False)\n sage: f.ideal_basis = f._par_graph_gb(verbose=False)\n sage: from sage.algebras.fusion_rings.poly_tup_engine import poly_tup_sortkey, poly_to_tup\n sage: f.ideal_basis.sort(key=poly_tup_sortkey)\n sage: f.mp_thresh = 0\n sage: f._fvars = f._shared_fvars\n sage: f._triangular_elim(verbose=False) # indirect doctest\n sage: f.ideal_basis\n []\n sage: f.shutdown_worker_pool()\n ' if (eqns is None): eqns = self.ideal_basis self._ks.update(eqns) for (i, d) in enumerate(get_variables_degrees(eqns, self._poly_ring.ngens())): self._var_degs[i] = d self._nnz = self._get_known_nonz() self._kp = compute_known_powers(self._var_degs, self._get_known_vals(), self._field.one()) def _triangular_elim(self, eqns=None, verbose=True): '\n Perform triangular elimination of linear terms in two-term equations\n until no such terms exist.\n\n .. NOTE::\n\n For optimal usage of triangular elimination, pass in a\n *sorted* list of equations.\n\n EXAMPLES::\n\n sage: f = FusionRing("D3", 1).get_fmatrix()\n sage: f.get_defining_equations(\'hexagons\', output=False)\n sage: f.get_orthogonality_constraints(output=False)\n sage: gb = f._par_graph_gb(verbose=False)\n sage: from sage.algebras.fusion_rings.poly_tup_engine import poly_tup_sortkey, poly_to_tup\n sage: f.ideal_basis = sorted(gb, key=poly_tup_sortkey)\n sage: from sage.algebras.fusion_rings.shm_managers import FvarsHandler\n sage: n = f._poly_ring.ngens()\n sage: f._fvars = FvarsHandler(n, f._field, f._idx_to_sextuple, init_data=f._fvars)\n sage: f._triangular_elim()\n Elimination epoch completed... 0 eqns remain in ideal basis\n sage: f.ideal_basis\n []\n ' if (eqns is None): eqns = self.ideal_basis while True: linear_terms_exist = _solve_for_linear_terms(self, eqns) if (not linear_terms_exist): break _backward_subs(self) self._update_reduction_params(eqns=eqns) if ((self.pool is not None) and (len(eqns) > self.mp_thresh)): n = self.pool._processes chunks = [[] for i in range(n)] for (i, eq_tup) in enumerate(eqns): chunks[(i % n)].append(eq_tup) eqns = chunks else: eqns = [eqns] eqns = self._map_triv_reduce('update_reduce', eqns, worker_pool=self.pool, mp_thresh=0) eqns.sort(key=poly_tup_sortkey) if verbose: print('Elimination epoch completed... {} eqns remain in ideal basis'.format(len(eqns))) self.ideal_basis = eqns def equations_graph(self, eqns=None): '\n Construct a graph corresponding to the given equations.\n\n Every node corresponds to a variable and nodes are connected when\n the corresponding variables appear together in an equation.\n\n INPUT:\n\n - ``eqns`` -- a list of polynomials\n\n Each polynomial is either an object in the ring returned by\n :meth:`get_poly_ring` or it is a tuple of pairs representing\n a polynomial using the internal representation.\n\n If no list of equations is passed, the graph is built from the\n polynomials in ``self.ideal_basis``. In this case the method assumes\n the internal representation of a polynomial as a tuple of pairs is\n used.\n\n This method is crucial to :meth:`find_orthogonal_solution`. The\n hexagon equations, obtained using :meth:`get_defining_equations`,\n define a disconnected graph that breaks up into many small components.\n The :meth:`find_orthogonal_solution` solver exploits this when\n undertaking a Groebner basis computation.\n\n OUTPUT:\n\n A ``Graph`` object. If a list of polynomial objects was given,\n the set of nodes in the output graph is the subset polynomial\n ring generators appearing in the equations.\n\n If the internal representation was used, the set of nodes is\n the subset of indices corresponding to polynomial ring generators.\n This option is meant for internal use by the F-matrix solver.\n\n EXAMPLES::\n\n sage: f = FusionRing("A3", 1).get_fmatrix()\n sage: f.get_poly_ring().ngens()\n 27\n sage: he = f.get_defining_equations(\'hexagons\')\n sage: graph = f.equations_graph(he)\n sage: graph.connected_components_sizes()\n [6, 3, 3, 3, 3, 3, 3, 1, 1, 1]\n ' if (eqns is None): eqns = self.ideal_basis G = Graph() if (not eqns): return G if isinstance(eqns[0], tuple): G.add_vertices([x for eq_tup in eqns for x in variables(eq_tup)]) else: G.add_vertices([x for eq in eqns for x in eq.variables()]) for eq in eqns: if isinstance(eq, tuple): s = list(variables(eq)) else: s = list(eq.variables()) for x in s: for y in s: if (y != x): G.add_edge(x, y) return G def _partition_eqns(self, eqns=None, verbose=True): '\n Partition equations corresponding to edges in a disconnected graph.\n\n OUTPUT:\n\n This method returns a dictionary of (c, e) pairs, where\n c is a tuple denoting a connected component in the graph produced\n by calling :meth:`equations_graph` with the given ``eqns`` and\n e is a list of all equations with variables in c.\n\n EXAMPLES::\n\n sage: f = FusionRing("C2", 1).get_fmatrix()\n sage: f.get_defining_equations(\'hexagons\', output=False)\n sage: partition = f._partition_eqns()\n Partitioned 11 equations into 5 components of size:\n [4, 3, 3, 3, 1]\n sage: from sage.algebras.fusion_rings.poly_tup_engine import variables\n sage: for c, e in partition.items():\n ....: assert set(v for eq_tup in e for v in variables(eq_tup)) == set(c)\n sage: vars_in_partition = set()\n sage: eqns_in_partition = set()\n sage: for c, e in partition.items():\n ....: vars_in_partition.update(c)\n ....: eqns_in_partition.update(e)\n sage: vars_in_partition == set(v for eq_tup in f.ideal_basis for v in variables(eq_tup))\n True\n sage: eqns_in_partition == set(f.ideal_basis)\n True\n sage: from itertools import product\n sage: for e1, e2 in product(partition.values(), repeat=2):\n ....: assert e1 == e2 or set(e1).isdisjoint(set(e2))\n ' if (eqns is None): eqns = self.ideal_basis graph = self.equations_graph(eqns) partition = {tuple(c): [] for c in graph.connected_components(sort=True)} for eq_tup in eqns: partition[tuple(graph.connected_component_containing_vertex(variables(eq_tup)[0], sort=True))].append(eq_tup) if verbose: print('Partitioned {} equations into {} components of size:'.format(len(eqns), graph.connected_components_number())) print(graph.connected_components_sizes()) return partition def _par_graph_gb(self, eqns=None, term_order='degrevlex', largest_comp=45, verbose=True): '\n Compute a Groebner basis for a list of equations partitioned\n according to their corresponding graph.\n\n .. NOTE::\n\n If the graph has more than 50 components, this method computes the\n Groebner basis in parallel when a ``worker_pool`` is provided.\n\n This method will refuse to find a Groebner basis for a component\n of size larger than 60, since such a calculation does not seem to\n terminate.\n\n EXAMPLES::\n\n sage: f = FusionRing("F4", 1).get_fmatrix()\n sage: f._reset_solver_state()\n sage: f.get_orthogonality_constraints(output=False)\n sage: f.start_worker_pool()\n sage: f.get_defining_equations(\'hexagons\', output=False)\n sage: gb = f._par_graph_gb()\n Partitioned 10 equations into 2 components of size:\n [4, 1]\n sage: from sage.algebras.fusion_rings.poly_tup_engine import _unflatten_coeffs\n sage: ret = [f._tup_to_fpoly(_unflatten_coeffs(f.field(), t)) for t in gb]\n sage: ret.sort(); ret\n [fx4 + (-zeta80^24 + zeta80^16),\n fx2 - fx3,\n fx1 + (zeta80^24 - zeta80^16),\n fx0 - 1,\n fx3^2 + (zeta80^24 - zeta80^16)]\n sage: f.shutdown_worker_pool()\n ' if (eqns is None): eqns = self.ideal_basis small_comps = [] temp_eqns = [] for (comp, comp_eqns) in self._partition_eqns(eqns=eqns, verbose=verbose).items(): if (len(comp) > largest_comp): temp_eqns.extend(comp_eqns) else: small_comps.append(comp_eqns) input_iter = zip_longest(small_comps, [], fillvalue=term_order) small_comp_gb = self._map_triv_reduce('compute_gb', input_iter, worker_pool=self.pool, chunksize=1, mp_thresh=50) ret = (small_comp_gb + temp_eqns) return ret def _get_component_variety(self, var, eqns): '\n Translate equations in each connected component to smaller polynomial\n rings so we can call built-in variety method.\n\n INPUT:\n\n - ``var`` -- a list of variable indices\n - ``eqns`` -- a list of polynomial equations in the internal\n tuple of pairs representation\n\n EXAMPLES::\n\n sage: f = FusionRing("G2", 2).get_fmatrix(new=True)\n sage: f.start_worker_pool()\n sage: f.get_defining_equations(\'hexagons\', output=False) # long time\n sage: f.shutdown_worker_pool()\n sage: partition = f._partition_eqns() # long time\n Partitioned 327 equations into 35 components of size:\n [27, 27, 27, 24, 24, 16, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,\n 9, 9, 6, 6, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1]\n sage: c = (216, 292, 319)\n sage: from sage.algebras.fusion_rings.poly_tup_engine import poly_to_tup\n sage: eqns = partition[c] + [poly_to_tup(f._poly_ring.gen(216)-1)] # long time\n sage: f._get_component_variety(c, eqns) # long time\n [{216: -1, 292: -1, 319: 1}]\n ' R = PolynomialRing(self._FR.field(), len(var), 'a', order='lex') idx_map = {old: new for (new, old) in enumerate(sorted(var))} nvars = len(var) eqns = [_unflatten_coeffs(self._field, eq_tup) for eq_tup in eqns] polys = [_tup_to_poly(resize(eq_tup, idx_map, nvars), parent=R) for eq_tup in eqns] var_in_R = Ideal(sorted(polys)).variety(ring=AA) inv_idx_map = {v: k for (k, v) in idx_map.items()} return [{inv_idx_map[i]: value for (i, (key, value)) in enumerate(sorted(soln.items()))} for soln in var_in_R] def attempt_number_field_computation(self): '\n Based on the ``CartanType`` of ``self`` and data\n known on March 17, 2021, determine whether to attempt\n to find a :func:`NumberField` containing all the F-symbols.\n\n This method is used by :meth:`find_orthogonal_solution`\n to determine a field containing all F-symbols.\n See :meth:`field` and :meth:`get_non_cyclotomic_roots`.\n\n For certain :class:`fusion rings <FusionRing>`, the number field\n computation does not terminate in reasonable time.\n In these cases, we report F-symbols as elements\n of the :class:`QQbar<AlgebraicField>`.\n\n EXAMPLES::\n\n sage: f = FusionRing("F4", 2).get_fmatrix()\n sage: f.attempt_number_field_computation()\n False\n sage: f = FusionRing("G2", 1).get_fmatrix()\n sage: f.attempt_number_field_computation()\n True\n\n .. NOTE::\n\n In certain cases, F-symbols are found in the associated\n :class:`FusionRing`\'s cyclotomic field and a\n :func:`NumberField` computation is not needed. In these\n cases this method returns ``True`` but the\n :meth:`find_orthogonal_solution` solver does *not*\n undertake a :func:`NumberField` computation.\n ' ct = self._FR.cartan_type() k = self._FR._k if (ct.letter == 'A'): if ((ct.n == 1) and (k >= 9) and (k % 2)): return False if (ct.letter == 'C'): if ((ct.n >= 9) and (ct.n % 2) and (k == 1)): return False if (ct.letter == 'E'): if ((ct.n < 8) and (k == 2)): return False if ((ct.n == 8) and (k == 3)): return False if ((ct.letter == 'F') and (k == 2)): return False if ((ct.letter == 'G') and (k == 2)): return False return True def _get_explicit_solution(self, eqns=None, verbose=True): '\n Construct an explicit solution of ``self``.\n\n When this method is called, the solution is already found in\n terms of Groeber basis. A few degrees of freedom remain.\n By specializing the free variables and back substituting, a\n solution in the base field is now obtained.\n\n EXAMPLES::\n\n sage: f = FusionRing("A1", 3).get_fmatrix() # indirect doctest\n sage: f.find_orthogonal_solution() # long time\n Computing F-symbols for The Fusion Ring of Type A1 and level 3 with Integer Ring coefficients with 71 variables...\n Set up 134 hex and orthogonality constraints...\n Partitioned 134 equations into 17 components of size:\n [12, 12, 6, 6, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1]\n Elimination epoch completed... 10 eqns remain in ideal basis\n Elimination epoch completed... 0 eqns remain in ideal basis\n Hex elim step solved for 51 / 71 variables\n Set up 121 reduced pentagons...\n Elimination epoch completed... 18 eqns remain in ideal basis\n Elimination epoch completed... 5 eqns remain in ideal basis\n Pent elim step solved for 64 / 71 variables\n Partitioned 5 equations into 1 components of size:\n [4]\n Elimination epoch completed... 0 eqns remain in ideal basis\n Partitioned 6 equations into 6 components of size:\n [1, 1, 1, 1, 1, 1]\n Computing appropriate NumberField...\n ' if (eqns is None): eqns = self.ideal_basis if (self._chkpt_status < 5): n = self._poly_ring.ngens() one = self._field.one() for (fx, rhs) in self._ks.items(): if (not self._solved[fx]): lt = (ETuple({fx: 2}, n), one) eqns.append((lt, (ETuple({}, n), (- rhs)))) eqns_partition = self._partition_eqns(verbose=verbose) F = self._field R = F['x'] numeric_fvars = {} non_cyclotomic_roots = [] must_change_base_field = False phi = F.hom([F.gen()], F) for (comp, part) in eqns_partition.items(): if ((len(comp) == 1) and (len(part) == 1)): univ_poly = tup_to_univ_poly(part[0], R) roots = univ_poly.roots(multiplicities=False) if roots: numeric_fvars[comp[0]] = roots[0] else: roots = univ_poly.roots(ring=AA, multiplicities=False) if (not roots): roots = univ_poly.roots(ring=QQbar, multiplicities=False) non_cyclotomic_roots.append((comp[0], roots[0])) must_change_base_field = True else: sols = self._get_component_variety(comp, part) for (fx, rhs) in sols[0].items(): non_cyclotomic_roots.append((fx, rhs)) must_change_base_field = True if must_change_base_field: if self.attempt_number_field_computation(): if verbose: print('Computing appropriate NumberField...') roots = ([self._FR.field().gen()] + [r[1] for r in non_cyclotomic_roots]) (self._field, bf_elts, self._qqbar_embedding) = number_field_elements_from_algebraics(roots, minimal=True) else: self._field = QQbar bf_elts = [self._qqbar_embedding(F.gen())] bf_elts += [rhs for (fx, rhs) in non_cyclotomic_roots] self._qqbar_embedding = (lambda x: x) self._non_cyc_roots = bf_elts[1:] cyc_gen_as_bf_elt = bf_elts.pop(0) phi = self._FR.field().hom([cyc_gen_as_bf_elt], self._field) self._coerce_map_from_cyc_field = phi numeric_fvars = {k: phi(v) for (k, v) in numeric_fvars.items()} for (i, elt) in enumerate(bf_elts): numeric_fvars[non_cyclotomic_roots[i][0]] = elt self._poly_ring = self._poly_ring.change_ring(self._field) for fx in numeric_fvars: self._solved[fx] = True nvars = self._poly_ring.ngens() assert (sum(self._solved) == nvars), 'Some F-symbols are still missing...{}'.format([self._poly_ring.gen(fx) for fx in range(nvars) if (not self._solved[fx])]) self._fvars = {sextuple: apply_coeff_map(rhs, phi) for (sextuple, rhs) in self._fvars.items()} for (fx, rhs) in numeric_fvars.items(): self._fvars[self._idx_to_sextuple[fx]] = ((ETuple({}, nvars), rhs),) _backward_subs(self, flatten=False) self._fvars = {sextuple: constant_coeff(rhs, self._field) for (sextuple, rhs) in self._fvars.items()} self._FR._field = self.field() self._FR._basecoer = self.get_coerce_map_from_fr_cyclotomic_field() if self._FR._basecoer: self._FR.r_matrix.clear_cache() def find_orthogonal_solution(self, checkpoint=False, save_results='', warm_start='', use_mp=True, verbose=True): '\n Solve the the hexagon and pentagon relations, along with\n orthogonality constraints, to evaluate an orthogonal F-matrix.\n\n INPUT:\n\n - ``checkpoint`` -- (default: ``False``) a boolean indicating whether\n the computation should be checkpointed. Depending on the associated\n ``CartanType``, the computation may take hours to complete. For\n large examples, checkpoints are recommended. This method supports\n "warm" starting, so the calculation may be resumed from a checkpoint,\n using the ``warm_start`` option.\n\n Checkpoints store necessary state in the pickle file\n ``"fmatrix_solver_checkpoint_" + key + ".pickle"``, where ``key``\n is the result of :meth:`get_fr_str`.\n\n Checkpoint pickles are automatically deleted when the solver exits\n a successful run.\n\n - ``save_results`` -- (optional) a string indicating the name of a\n pickle file in which to store calculated F-symbols for later use.\n\n If ``save_results`` is not provided (default), F-matrix results\n are not stored to file.\n\n The F-symbols may be saved to file after running the solver using\n :meth:`save_fvars`.\n\n - ``warm_start`` -- (optional) a string indicating the name of a pickle\n file containing checkpointed solver state. This file must have been\n produced by a previous call to the solver using the ``checkpoint``\n option.\n\n If no file name is provided, the calculation begins from scratch.\n\n - ``use_mp`` -- (default: ``True``) a boolean indicating whether to use\n multiprocessing to speed up calculation. The default value\n ``True`` is highly recommended, since parallel processing yields\n results much more quickly.\n\n - ``verbose`` -- (default: ``True``) a boolean indicating whether the\n solver should print out intermediate progress reports.\n\n OUTPUT:\n\n This method returns ``None``. If the solver runs successfully, the\n results may be accessed through various methods, such as\n :meth:`get_fvars`, :meth:`fmatrix`, :meth:`fmat`, etc.\n\n EXAMPLES::\n\n sage: f = FusionRing("B5", 1).get_fmatrix(fusion_label="b", inject_variables=True)\n creating variables fx1..fx14\n Defining fx0, fx1, fx2, fx3, fx4, fx5, fx6, fx7, fx8, fx9, fx10, fx11, fx12, fx13\n sage: f.find_orthogonal_solution()\n Computing F-symbols for The Fusion Ring of Type B5 and level 1 with Integer Ring coefficients with 14 variables...\n Set up 25 hex and orthogonality constraints...\n Partitioned 25 equations into 5 components of size:\n [4, 3, 3, 3, 1]\n Elimination epoch completed... 0 eqns remain in ideal basis\n Hex elim step solved for 10 / 14 variables\n Set up 7 reduced pentagons...\n Elimination epoch completed... 0 eqns remain in ideal basis\n Pent elim step solved for 12 / 14 variables\n Partitioned 0 equations into 0 components of size:\n []\n Partitioned 2 equations into 2 components of size:\n [1, 1]\n sage: f.fmatrix(b2, b2, b2, b2)\n [ 1/2*zeta80^30 - 1/2*zeta80^10 -1/2*zeta80^30 + 1/2*zeta80^10]\n [ 1/2*zeta80^30 - 1/2*zeta80^10 1/2*zeta80^30 - 1/2*zeta80^10]\n sage: f.fmat(b2, b2, b2, b2, b0, b1)\n -1/2*zeta80^30 + 1/2*zeta80^10\n\n Every F-matrix `F^{a, b, c}_d` is orthogonal and in many cases real.\n We may use :meth:`fmats_are_orthogonal` and :meth:`fvars_are_real`\n to obtain correctness certificates.\n\n EXAMPLES::\n\n sage: f.fmats_are_orthogonal()\n True\n\n In any case, the F-symbols are obtained as elements of the associated\n :class:`FusionRing`\'s\n :class:`Cyclotomic field<sage.rings.number_field.number_field.CyclotomicFieldFactory>`,\n a computed :func:`NumberField`, or :class:`QQbar<AlgebraicField>`.\n Currently, the field containing the F-symbols is determined based\n on the ``CartanType`` associated to ``self``.\n\n .. SEEALSO::\n\n :meth:`attempt_number_field_computation`\n ' if (self._poly_ring.ngens() == 0): return self._reset_solver_state() if warm_start: self._restore_state(warm_start) if (self._chkpt_status > 5): return if use_mp: self.start_worker_pool() if verbose: print('Computing F-symbols for {} with {} variables...'.format(self._FR, self._poly_ring.ngens())) if (self._chkpt_status < 1): self.get_orthogonality_constraints(output=False) self.get_defining_equations('hexagons', output=False) if verbose: print('Set up {} hex and orthogonality constraints...'.format(len(self.ideal_basis))) if use_mp: self._fvars = self._shared_fvars else: n = self._poly_ring.ngens() self._fvars = FvarsHandler(n, self._field, self._idx_to_sextuple, init_data=self._fvars) self._checkpoint(checkpoint, 1, verbose=verbose) if (self._chkpt_status < 2): self.ideal_basis = self._par_graph_gb(verbose=verbose) self.ideal_basis.sort(key=poly_tup_sortkey) self._triangular_elim(verbose=verbose) if verbose: print('Hex elim step solved for {} / {} variables'.format(sum(self._solved), len(self._poly_ring.gens()))) self._checkpoint(checkpoint, 2, verbose=verbose) if (self._chkpt_status < 3): self.get_defining_equations('pentagons', output=False) if verbose: print('Set up {} reduced pentagons...'.format(len(self.ideal_basis))) self._checkpoint(checkpoint, 3, verbose=verbose) if (self._chkpt_status < 4): self.ideal_basis.sort(key=poly_tup_sortkey) self._triangular_elim(verbose=verbose) if verbose: print('Pent elim step solved for {} / {} variables'.format(sum(self._solved), len(self._poly_ring.gens()))) self._checkpoint(checkpoint, 4, verbose=verbose) if (self._chkpt_status < 5): self.ideal_basis = self._par_graph_gb(term_order='lex', verbose=verbose) self.ideal_basis.sort(key=poly_tup_sortkey) self._triangular_elim(verbose=verbose) self._checkpoint(checkpoint, 5, verbose=verbose) self.shutdown_worker_pool() self._get_explicit_solution(verbose=verbose) self._chkpt_status = 7 self.clear_equations() if checkpoint: remove((('fmatrix_solver_checkpoint_' + self.get_fr_str()) + '.pickle')) if save_results: self.save_fvars(save_results) def _fix_gauge(self, algorithm=''): '\n Fix the gauge by forcing F-symbols not already fixed to equal `1`.\n\n .. NOTE::\n\n This method should be used *after* adding hexagon and pentagon\n equations to ``self.ideal_basis``.\n\n EXAMPLES::\n\n sage: f = FusionRing("A3", 1).get_fmatrix()\n sage: f._reset_solver_state() # long time\n sage: f._var_to_sextuple = {f._poly_ring.gen(i): s for i, s in f._idx_to_sextuple.items()} # long time\n sage: eqns = f.get_defining_equations("hexagons")+f.get_defining_equations("pentagons") # long time\n sage: f.ideal_basis = set(Ideal(eqns).groebner_basis()) # long time\n sage: _, _ = f._substitute_degree_one() # long time\n sage: f._fix_gauge() # long time\n adding equation... fx1 - 1\n adding equation... fx18 - 1\n adding equation... fx21 - 1\n ' while (not all(self._solved)): for (i, var) in enumerate(self._poly_ring.gens()): if (not self._solved[i]): break self.ideal_basis.add((var - 1)) print('adding equation...', (var - 1)) self.ideal_basis = set(Ideal(list(self.ideal_basis)).groebner_basis(algorithm=algorithm)) self._substitute_degree_one() self._update_equations() def _substitute_degree_one(self, eqns=None): '\n Substitute known value from linear univariate polynomial and\n solve, following [Bond2007]_ p.37, for two-term linear equation\n for one of the variables. See also [Ab2022]_.\n\n EXAMPLES::\n\n sage: fr = FusionRing("D3", 1)\n sage: f = fr.get_fmatrix(inject_variables=True, new=True)\n creating variables fx1..fx27\n Defining fx0, ..., fx26\n sage: f._reset_solver_state()\n sage: f._var_to_sextuple = {f._poly_ring.gen(i): s for i, s in f._idx_to_sextuple.items()}\n sage: f.ideal_basis = [fx0 - 8, fx4**2 - 3, fx4 + fx10 + 3, fx4 + fx9]\n sage: _, _ = f._substitute_degree_one()\n sage: f._fvars[f._var_to_sextuple[fx0]]\n 8\n sage: f._fvars[f._var_to_sextuple[fx4]]\n -fx9\n ' if (eqns is None): eqns = self.ideal_basis new_knowns = set() useless = set() for eq in eqns: if ((eq.degree() == 1) and (sum(eq.degrees()) <= 2) and (eq.lm() not in self._solved)): self._fvars[self._var_to_sextuple[eq.lm()]] = ((- sum(((c * m) for (c, m) in zip(eq.coefficients()[1:], eq.monomials()[1:])))) / eq.lc()) new_knowns.add(eq.lm()) useless.add(eq) for (idx, fx) in enumerate(self._poly_ring.gens()): if (fx in new_knowns): self._solved[idx] = fx for (sextuple, rhs) in self._fvars.items(): d = {var: self._fvars[self._var_to_sextuple[var]] for var in rhs.variables() if (var in self._solved)} if d: self._fvars[sextuple] = rhs.subs(d) return (new_knowns, useless) def _update_equations(self): '\n Perform backward substitution on equations in ``self.ideal_basis``.\n\n EXAMPLES::\n\n sage: fr = FusionRing("D3", 1)\n sage: f = fr.get_fmatrix(inject_variables=True, new=True)\n creating variables fx1..fx27\n Defining fx0, ..., fx26\n sage: f._reset_solver_state()\n sage: f._var_to_sextuple = {f._poly_ring.gen(i): s for i, s in f._idx_to_sextuple.items()}\n sage: f.ideal_basis = [fx0 - 8, fx4 + fx9, fx4**2 + fx3 - fx9**2]\n sage: _, _ = f._substitute_degree_one()\n sage: f._update_equations()\n sage: f.ideal_basis\n {fx3}\n ' special_values = {known: self._fvars[self._var_to_sextuple[known]] for known in self._solved if known} self.ideal_basis = {eq.subs(special_values) for eq in self.ideal_basis} self.ideal_basis.discard(0) def find_cyclotomic_solution(self, equations=None, algorithm='', verbose=True, output=False): '\n Solve the hexagon and pentagon relations to evaluate the F-matrix.\n\n This method (omitting the orthogonality constraints) produces\n output in the cyclotomic field, but it is very limited in the size\n of examples it can handle: for example, `G_2` at level 2 is\n too large for this method. You may use :meth:`find_orthogonal_solution`\n to solve much larger examples.\n\n INPUT:\n\n - ``equations`` -- (optional) a set of equations to be\n solved; defaults to the hexagon and pentagon equations\n - ``algorithm`` -- (optional) algorithm to compute Groebner Basis\n - ``output`` -- (default: ``False``) output a dictionary of\n F-matrix values; this may be useful to see but may be omitted\n since this information will be available afterwards via the\n :meth:`fmatrix` and :meth:`fmat` methods.\n\n EXAMPLES::\n\n sage: fr = FusionRing("A2", 1, fusion_labels="a", inject_variables=True)\n sage: f = fr.get_fmatrix(inject_variables=True)\n creating variables fx1..fx8\n Defining fx0, fx1, fx2, fx3, fx4, fx5, fx6, fx7\n sage: f.find_cyclotomic_solution(output=True)\n Setting up hexagons and pentagons...\n Finding a Groebner basis...\n Solving...\n Fixing the gauge...\n adding equation... fx4 - 1\n Done!\n {(a2, a2, a2, a0, a1, a1): 1,\n (a2, a2, a1, a2, a1, a0): 1,\n (a2, a1, a2, a2, a0, a0): 1,\n (a2, a1, a1, a1, a0, a2): 1,\n (a1, a2, a2, a2, a0, a1): 1,\n (a1, a2, a1, a1, a0, a0): 1,\n (a1, a1, a2, a1, a2, a0): 1,\n (a1, a1, a1, a0, a2, a2): 1}\n\n After you successfully run :meth:`find_cyclotomic_solution` you may\n check the correctness of the F-matrix by running\n :meth:`get_defining_equations` with ``option=\'hexagons\'`` and\n ``option=\'pentagons\'``. These should return empty lists\n of equations.\n\n EXAMPLES::\n\n sage: f.get_defining_equations("hexagons")\n []\n sage: f.get_defining_equations("pentagons")\n []\n ' if (self._poly_ring.ngens() == 0): return self._reset_solver_state() self._var_to_sextuple = {self._poly_ring.gen(i): s for (i, s) in self._idx_to_sextuple.items()} if (equations is None): if verbose: print('Setting up hexagons and pentagons...') equations = (self.get_defining_equations('hexagons') + self.get_defining_equations('pentagons')) if verbose: print('Finding a Groebner basis...') self.ideal_basis = set(Ideal(equations).groebner_basis(algorithm=algorithm)) if verbose: print('Solving...') self._substitute_degree_one() if verbose: print('Fixing the gauge...') self._fix_gauge(algorithm=algorithm) if verbose: print('Done!') if output: return self._fvars def fmats_are_orthogonal(self): '\n Verify that all F-matrices are orthogonal.\n\n This method should always return ``True`` when called after running\n :meth:`find_orthogonal_solution`.\n\n EXAMPLES::\n\n sage: f = FusionRing("D4", 1).get_fmatrix()\n sage: f.find_orthogonal_solution(verbose=False)\n sage: f.fmats_are_orthogonal()\n True\n ' is_orthog = [] for (a, b, c, d) in product(self._FR.basis(), repeat=4): mat = self.fmatrix(a, b, c, d) is_orthog.append(((mat.T * mat) == matrix.identity(mat.nrows()))) return all(is_orthog) def fvars_are_real(self): '\n Test whether all F-symbols are real.\n\n EXAMPLES::\n\n sage: f = FusionRing("A1", 3).get_fmatrix()\n sage: f.find_orthogonal_solution(verbose=False) # long time\n sage: f.fvars_are_real() # not tested (cypari issue in doctesting framework)\n True\n ' try: for (k, v) in self._fvars.items(): AA(self._qqbar_embedding(v)) except ValueError: print('the F-symbol {} (key {}) has a nonzero imaginary part'.format(v, k)) return False return True def certify_pentagons(self, use_mp=True, verbose=False): '\n Obtain a certificate of satisfaction for the pentagon equations,\n up to floating-point error.\n\n This method converts the computed F-symbols (available through\n :meth:`get_fvars`) to native Python floats and then checks whether\n the pentagon equations are satisfied using floating point arithmetic.\n\n When ``self.FR().basis()`` has many elements, verifying satisfaction\n of the pentagon relations exactly using :meth:`get_defining_equations`\n with ``option="pentagons"`` may take a long time. This method is\n faster, but it cannot provide mathematical guarantees.\n\n EXAMPLES::\n\n sage: f = FusionRing("C3", 1).get_fmatrix()\n sage: f.find_orthogonal_solution() # long time\n Computing F-symbols for The Fusion Ring of Type C3 and level 1 with Integer Ring coefficients with 71 variables...\n Set up 134 hex and orthogonality constraints...\n Partitioned 134 equations into 17 components of size:\n [12, 12, 6, 6, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1]\n Elimination epoch completed... 10 eqns remain in ideal basis\n Elimination epoch completed... 0 eqns remain in ideal basis\n Hex elim step solved for 51 / 71 variables\n Set up 121 reduced pentagons...\n Elimination epoch completed... 18 eqns remain in ideal basis\n Elimination epoch completed... 5 eqns remain in ideal basis\n Pent elim step solved for 64 / 71 variables\n Partitioned 5 equations into 1 components of size:\n [4]\n Elimination epoch completed... 0 eqns remain in ideal basis\n Partitioned 6 equations into 6 components of size:\n [1, 1, 1, 1, 1, 1]\n Computing appropriate NumberField...\n sage: f.certify_pentagons() is None # not tested (long time ~1.5s, cypari issue in doctesting framework)\n True\n ' fvars_copy = deepcopy(self._fvars) self._fvars = {sextuple: float(rhs) for (sextuple, rhs) in self.get_fvars_in_alg_field().items()} if use_mp: pool = Pool() else: pool = None n_proc = (pool._processes if (pool is not None) else 1) params = [(child_id, n_proc, verbose) for child_id in range(n_proc)] pe = self._map_triv_reduce('pent_verify', params, worker_pool=pool, chunksize=1, mp_thresh=0) if np.all(np.isclose(np.array(pe), 0, atol=1e-07)): if verbose: print('Found valid F-symbols for {}'.format(self._FR)) pe = None elif verbose: print('Something went wrong. Pentagons remain.') self._fvars = fvars_copy return pe
class FusionDouble(CombinatorialFreeModule): '\n The fusion ring corresponding to the Drinfeld double of a finite group.\n\n This is the fusion ring of the modular tensor category of modules\n over the Drinfeld double of a finite group. Usage is similar\n to :class:`FusionRing`; we refer the reader to that class for more\n information.\n\n INPUT:\n\n - ``G`` -- a finite group\n - ``prefix`` -- (default: ``\'s\'``) a prefix for the names of simple objects\n - ``inject_varables`` -- (optional) set to ``True`` to create variables\n for the simple objects\n\n REFERENCES:\n\n - [BaKi2001]_ Chapter 3\n - [Mas1995]_\n - [CHW2015]_\n - [Goff1999]_\n\n EXAMPLES::\n\n sage: G = DihedralGroup(5)\n sage: H = FusionDouble(G, inject_variables=True)\n sage: H.basis()\n Finite family {0: s0, 1: s1, 2: s2, 3: s3, 4: s4, 5: s5, 6: s6, 7: s7, 8: s8,\n 9: s9, 10: s10, 11: s11, 12: s12, 13: s13, 14: s14, 15: s15}\n sage: for x in H.basis():\n ....: print ("%s : %s"%(x,x^2))\n ....:\n s0 : s0\n s1 : s0\n s2 : s0 + s1 + s3\n s3 : s0 + s1 + s2\n s4 : s0 + s2 + s3 + s6 + s7 + s8 + s9 + s10 + s11 + s12 + s13 + s14 + s15\n s5 : s0 + s2 + s3 + s6 + s7 + s8 + s9 + s10 + s11 + s12 + s13 + s14 + s15\n s6 : s0 + s1 + s11\n s7 : s0 + s1 + s13\n s8 : s0 + s1 + s15\n s9 : s0 + s1 + s12\n s10 : s0 + s1 + s14\n s11 : s0 + s1 + s6\n s12 : s0 + s1 + s9\n s13 : s0 + s1 + s7\n s14 : s0 + s1 + s10\n s15 : s0 + s1 + s8\n sage: s4*s5\n s1 + s2 + s3 + s6 + s7 + s8 + s9 + s10 + s11 + s12 + s13 + s14 + s15\n sage: s4.ribbon()\n 1\n sage: s5.ribbon()\n -1\n sage: s8.ribbon()\n zeta5^3\n\n If the fusion double is multiplicity-free, meaning that the fusion\n coefficients `N_k^{ij}` are bounded by `1`, then the F-matrix may be\n computed, by solving the pentagon and hexagon relations as described\n in [Bond2007]_ and [Ab2022]_, just as for :class:`FusionRing`.\n There is a caveat here, since even if the fusion rules are multiplicity-free,\n if there are too many F-matrix values to compute, even if many of them are\n zero, in the current implementation singular cannot create enough variables.\n At least, this code can compute the F-matrix for the Fusion Double of the\n symmetric group `S_3`, duplicating the result of [CHW2015]_.\n\n ::\n\n sage: G1 = SymmetricGroup(3)\n sage: H1 = FusionDouble(G1, prefix="u", inject_variables=True)\n sage: F = H1.get_fmatrix()\n\n The above commands create the F-matrix. You can compute all of the\n F-matrices with the command::\n\n sage: H1.find_orthogonal_solution() # not tested (10-15 minutes)\n\n Individual F-matrices may be computed thus::\n\n sage: F.fmatrix(u3, u3, u3, u4) # not tested\n\n See :class:`FMatrix` for more information.\n\n Unfortunately beyond `S_3` the number of simple objects is seemingly\n impractical. Although the :class:`FusionDouble` class and its methods\n work well for groups of moderate size, the :class:`FMatrix` may not be\n computable. For the dihedral group of order 8, there are already 22\n simple objects, and the F-matrix seems out of reach. The actual limitation\n is that singular will not create a polynomial ring in more than\n `2^{15}-1 = 32767` symbols, and there are more than this many F-matrix\n values to be computed for the dihedral group of order 8, so in the\n current implementation, this FusionRing is out of reach.\n\n It is an open problem to classify the finite groups whose fusion doubles\n are multiplicity-free. Abelian groups, dihedral groups, dicyclic groups,\n and all groups of order 16 are multiplicity-free. On the other hand, for\n groups of order 32, some are multiplicity-free and others are not.\n These can all be constructed using :class:`SmallPermutationGroup`.\n\n EXAMPLES::\n\n sage: G = SmallPermutationGroup(16,9)\n sage: F = FusionDouble(G, prefix="b",inject_variables=True)\n sage: b13^2 # long time (4s)\n b0 + b2 + b4 + b15 + b16 + b17 + b18 + b24 + b26 + b27\n\n ' @staticmethod def __classcall_private__(cls, G, prefix='s', inject_variables=False): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: H1 = FusionDouble(DihedralGroup(6), inject_variables=True)\n sage: H2 = FusionDouble(DihedralGroup(6), prefix='s')\n sage: H1 is H2\n True\n " F = super().__classcall__(cls, G=G, prefix=prefix) if inject_variables: F.inject_variables() return F def __init__(self, G, prefix='s'): "\n EXAMPLES::\n\n sage: H = FusionDouble(DihedralGroup(6))\n sage: TestSuite(H).run()\n sage: H = FusionDouble(DihedralGroup(7))\n sage: TestSuite(H).run() # long time\n\n sage: F = FusionDouble(CyclicPermutationGroup(2))\n sage: [F._repr_term(t) for t in F._names]\n ['s0', 's1', 's2', 's3']\n sage: F = FusionDouble(CyclicPermutationGroup(2))\n sage: [F._latex_term(t) for t in F._names]\n ['s_{0}', 's_{1}', 's_{2}', 's_{3}']\n\n sage: FusionDouble(SymmetricGroup(4)).get_order()\n [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n " self._G = G self._names = {} self._elt = {} self._chi = {} count = ZZ.zero() for g in G.conjugacy_classes_representatives(): for chi in G.centralizer(g).irreducible_characters(): self._names[count] = ('%s%s' % (prefix, count)) self._elt[count] = g self._chi[count] = chi count += ZZ.one() self._cyclotomic_order = G.exponent() self._basecoer = None self._fusion_labels = None self._field = None cat = AlgebrasWithBasis(ZZ) CombinatorialFreeModule.__init__(self, ZZ, list(self._names), prefix=prefix, bracket=False, category=cat) def _repr_(self): '\n EXAMPLES::\n\n sage: FusionDouble(SymmetricGroup(3))\n The Fusion Ring of the Drinfeld Double of Symmetric group of\n order 3! as a permutation group\n ' return ('The Fusion Ring of the Drinfeld Double of %s' % self._G) def inject_variables(self): '\n Create variables for the simple objects in the global name space.\n\n EXAMPLES::\n\n sage: F = FusionDouble(DiCyclicGroup(3), prefix="d")\n sage: F.inject_variables()\n sage: d0 + d1 + d5\n d0 + d1 + d5\n ' for (i, name) in self._names.items(): inject_variable(name, self.monomial(i)) @cached_method def _char_cache(self, i, g): '\n Return ``self._chi[i](g)``, cached here for speed.\n\n TESTS::\n\n sage: D = FusionDouble(SymmetricGroup(4))\n\n sage: all(D._char_cache(b.support_of_term(), b.g()) == b.char()(b.g())\n ....: for b in D.basis())\n True\n ' return self._chi[i](g) @cached_method def s_ij(self, i, j, unitary=False, base_coercion=True): '\n Return the element of the S-matrix of this fusion ring\n corresponding to the given elements.\n\n Without the unitary option set true, this is the unnormalized S-matrix\n entry, denoted `\\tilde{s}_{ij}`, in [BaKi2001]_ Chapter 3. The\n normalized S-matrix entries are denoted `s_{ij}`.\n\n INPUT:\n\n - ``i``, ``j``, -- a pair of basis elements\n - ``unitary`` -- (default: ``False``) set to ``True`` to obtain\n the unitary S-matrix\n\n EXAMPLES::\n\n sage: D = FusionDouble(SymmetricGroup(3), prefix="t", inject_variables=True)\n sage: [D.s_ij(t2, x) for x in D.basis()]\n [2, 2, 4, 0, 0, -2, -2, -2]\n sage: [D.s_ij(t2, x, unitary=True) for x in D.basis()]\n [1/3, 1/3, 2/3, 0, 0, -1/3, -1/3, -1/3]\n ' sum_val = ZZ.zero() G = self._G [i] = list(i._monomial_coefficients) [j] = list(j._monomial_coefficients) a = self._elt[i] b = self._elt[j] for g in G: gi = g.inverse() conj = ((g * b) * gi) if ((a * conj) == (conj * a)): sum_val += (self._char_cache(i, conj) * self._char_cache(j, ((gi * a) * g))) if unitary: coef = (1 / (G.centralizer(a).order() * G.centralizer(b).order())) else: coef = (G.order() / (G.centralizer(a).order() * G.centralizer(b).order())) ret = (coef * sum_val) if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) def s_ijconj(self, i, j, unitary=False, base_coercion=True): '\n Return the conjugate of the element of the S-matrix given by\n ``self.s_ij(elt_i, elt_j, base_coercion=base_coercion)``.\n\n .. SEEALSO::\n\n :meth:`s_ij`\n\n EXAMPLES::\n\n sage: P=FusionDouble(CyclicPermutationGroup(3),prefix="p",inject_variables=True)\n sage: P.s_ij(p1,p3)\n zeta3\n sage: P.s_ijconj(p1,p3)\n -zeta3 - 1\n ' return self.s_ij(i, j, unitary=unitary, base_coercion=base_coercion).conjugate() def s_matrix(self, unitary=False, base_coercion=True): '\n Return the S-matrix of this fusion ring.\n\n OPTIONAL:\n\n - ``unitary`` -- (default: ``False``) set to ``True`` to obtain\n the unitary S-matrix\n\n Without the ``unitary`` parameter, this is the matrix denoted\n `\\widetilde{s}` in [BaKi2001]_.\n\n EXAMPLES::\n\n sage: FusionDouble(SymmetricGroup(3)).s_matrix()\n [ 1 1 2 3 3 2 2 2]\n [ 1 1 2 -3 -3 2 2 2]\n [ 2 2 4 0 0 -2 -2 -2]\n [ 3 -3 0 3 -3 0 0 0]\n [ 3 -3 0 -3 3 0 0 0]\n [ 2 2 -2 0 0 4 -2 -2]\n [ 2 2 -2 0 0 -2 -2 4]\n [ 2 2 -2 0 0 -2 4 -2]\n sage: FusionDouble(SymmetricGroup(3)).s_matrix(unitary=True)\n [ 1/6 1/6 1/3 1/2 1/2 1/3 1/3 1/3]\n [ 1/6 1/6 1/3 -1/2 -1/2 1/3 1/3 1/3]\n [ 1/3 1/3 2/3 0 0 -1/3 -1/3 -1/3]\n [ 1/2 -1/2 0 1/2 -1/2 0 0 0]\n [ 1/2 -1/2 0 -1/2 1/2 0 0 0]\n [ 1/3 1/3 -1/3 0 0 2/3 -1/3 -1/3]\n [ 1/3 1/3 -1/3 0 0 -1/3 -1/3 2/3]\n [ 1/3 1/3 -1/3 0 0 -1/3 2/3 -1/3]\n\n ' b = self.basis() S = matrix([[self.s_ij(b[x], b[y], unitary=unitary, base_coercion=base_coercion) for x in self.get_order()] for y in self.get_order()]) return S @cached_method def N_ijk(self, i, j, k): '\n The symmetric invariant of three simple objects.\n\n This is the dimension of\n\n .. MATH::\n\n Hom(i \\otimes j \\otimes k, s_0),\n\n where `s_0` is the unit element (assuming ``prefix=\'s\'``).\n Method of computation is through the Verlinde formula,\n deducing the values from the known values of the S-matrix.\n\n EXAMPLES::\n\n sage: A = FusionDouble(AlternatingGroup(4),prefix="a",inject_variables=True)\n sage: [A.N_ijk(a10,a11,x) for x in A.basis()]\n [0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0]\n\n TESTS::\n\n sage: F = FusionDouble(SymmetricGroup(4))\n sage: from itertools import product\n sage: B = list(F.basis())\n sage: all(F.N_ijk(i,j,k).parent() is ZZ\n ....: for i, j, k in product(B[::6], repeat=3))\n True\n ' sz = self.one() return ZZ(sum(((((self.s_ij(i, r, unitary=True) * self.s_ij(j, r, unitary=True)) * self.s_ij(k, r, unitary=True)) / self.s_ij(sz, r, unitary=True)) for r in self.basis()))) @cached_method def Nk_ij(self, i, j, k, use_characters=False): '\n Return the fusion coefficient `N^k_{ij}`.\n\n INPUT:\n\n - ``i``, ``j``, ``k`` -- basis elements\n - ``use_characters`` -- (default: ``False``) see the algorithm\n description below\n\n ALGORITHM:\n\n If ``use_characters=False``, then this is computed using\n the Verlinde formula:\n\n .. MATH::\n\n N^k_{ij} = \\sum_l \\frac{s(i, \\ell)\\, s(j, \\ell)\\,\n \\overline{s(k, \\ell)}}{s(I, \\ell)}.\n\n Otherwise we use a character theoretic method to compute the fusion\n coefficient `N_{ij}^k` as follows. Each simple object, for example\n `i` corresponds to a conjugacy class `\\mathcal{C}_i` of the underlying\n group `G`, and an irreducible character `\\chi_i` of the centralizer\n `C(g_i)` of a fixed representative `g_i` of `\\mathcal{C}_i`. In addition\n to the fixed representative `g_k` of the class `\\mathcal{C}_i`\n and `\\mathcal{C}_j`, the formula will make use of variable elements\n `h_i` and `h_j` that are subject to the condition `h_i h_j = g_k`.\n See [GoMa2010]_ equation (7).\n\n .. MATH::\n\n \\frac{|\\mathcal{C}_k|}{|G|}\n \\sum_{\\substack{h_i\\in\\mathcal{C}_i \\\\ h_j\\in\\mathcal{C}_j \\\\ h_ih_j=g_k}}\n \\lvert C(h_i)\\cap C(h_j) \\rvert \\,\n \\langle \\chi_i^{(h_i)} \\chi_j^{(h_j)}, \\chi_k \\rangle_{C(h_i)\\cap C(h_j)},\n\n where `\\chi_i^{(h_i)}` is the character `\\chi_i` of `C(g_i)`\n conjugated to a character of `C(h_i)`, when `h_i` is a conjugate\n of the fixed representative `g_i`. More exactly, there exists `r_i`\n such that `r_i g_i r_i^{-1} = h_i`, and then `\\chi_i^{(h_i)}(x) =\n \\chi_i(r_i^{-1}xr_i)`, and this definition does not depend on the\n choice of `r_i`.\n\n .. NOTE::\n\n This should be functionally equivalent, and testing shows\n that it is, but it is slower.\n\n EXAMPLES::\n\n sage: A = FusionDouble(AlternatingGroup(4),prefix="aa",inject_variables=True)\n sage: [A.Nk_ij(aa8,aa10,x) for x in A.basis()]\n [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 1]\n\n sage: B = FusionDouble(CyclicPermutationGroup(2))\n sage: all(B.Nk_ij(x,y,z,use_characters=True) == B.Nk_ij(x,y,z)\n ....: for x in B.basis() for y in B.basis() for z in B.basis())\n True\n ' if (not use_characters): return self.N_ijk(i, j, self.dual(k)) G = self._G I = G.conjugacy_class(i.g()) J = G.conjugacy_class(j.g()) IJ = {(I_elem * J_elem) for I_elem in I for J_elem in J} if (k.g() not in IJ): return ZZ.zero() K = G.conjugacy_class(k.g()) CI = G.centralizer(i.g()) CJ = G.centralizer(j.g()) CK = G.centralizer(k.g()) c = (K.cardinality() / G.order()) summands = [(I_elem, J_elem) for I_elem in I for J_elem in J if ((I_elem * J_elem) == k.g())] res = ZZ.zero() ichar = i.char() jchar = j.char() kchar = k.char() for p in summands: (I_elem, J_elem) = p for g in G: ginv = g.inverse() if (((ginv * i.g()) * g) == I_elem): i_twist = g if (((ginv * j.g()) * g) == J_elem): j_twist = g A = Set((((i_twist.inverse() * zi) * i_twist) for zi in CI)) B = Set((((j_twist.inverse() * zj) * j_twist) for zj in CJ)) inner_summands = A.intersection(B).intersection(Set(CK)) i_twist_inv = i_twist.inverse() j_twist_inv = j_twist.inverse() res += sum((((ichar(((i_twist * x) * i_twist_inv)) * jchar(((j_twist * x) * j_twist_inv))) * kchar(x).conjugate()) for x in inner_summands)) return (c * res) @cached_method def field(self): '\n Returns a cyclotomic field large enough to contain the values\n of R-matrices and twists that can arise for this fusion ring.\n\n EXAMPLES::\n\n sage: FusionDouble(SymmetricGroup(3)).field()\n Cyclotomic Field of order 24 and degree 8\n ' return CyclotomicField((4 * self._cyclotomic_order)) def fvars_field(self): '\n Return a field containing the ``CyclotomicField`` computed by\n :meth:`field` as well as all the F-symbols of the associated\n ``FMatrix`` factory object.\n\n This method is only available if ``self`` is multiplicity-free.\n\n EXAMPLES::\n\n sage: FusionDouble(SymmetricGroup(3)).fvars_field()\n Cyclotomic Field of order 24 and degree 8\n ' if self.is_multiplicity_free(verbose=False): return self.get_fmatrix().field() raise NotImplementedError('method is only available for multiplicity free fusion rings') def root_of_unity(self, r, base_coercion=True): '\n Return `e^{i\\pi r}` as an element of ``self.field()`` if possible.\n\n INPUT:\n\n - ``r`` -- a rational number\n\n EXAMPLES::\n\n sage: H = FusionDouble(DihedralGroup(6))\n sage: H.field()\n Cyclotomic Field of order 24 and degree 8\n sage: for n in [1..7]:\n ....: try:\n ....: print (n,H.root_of_unity(2/n))\n ....: except ValueError as err:\n ....: print (n,err)\n ....:\n 1 1\n 2 -1\n 3 zeta24^4 - 1\n 4 zeta24^6\n 5 not a root of unity in the field\n 6 zeta24^4\n 7 not a root of unity in the field\n ' n = ((2 * r) * self._cyclotomic_order) if (n not in ZZ): raise ValueError('not a root of unity in the field') ret = (self.field().gen() ** n) if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) @cached_method def r_matrix(self, i, j, k, base_coercion=True): '\n Return the R-matrix entry corresponding to the subobject ``k``\n in the tensor product of ``i`` with ``j``. This method is only\n correct if the fusion coefficient ``N_{ij}^k\\leq 1``. See the\n :class:`FusionRing` method for more information, including\n the reason for this caveat, and the algorithm.\n\n EXAMPLES::\n\n sage: C = FusionDouble(SymmetricGroup(3),prefix="c",inject_variables=True)\n sage: c4*c5\n c3 + c4\n sage: [C.r_matrix(c4,c5,k) for k in [c3,c4]]\n [-zeta24^6, 1]\n sage: c6^2\n c0 + c1 + c6\n sage: [C.r_matrix(c6,c6,k) for k in [c0,c1,c6]]\n [zeta3, -zeta3, -zeta3 - 1]\n ' if (self.Nk_ij(i, j, k) == 0): return (self.field().zero() if ((not base_coercion) or (self._basecoer is None)) else self.fvars_field().zero()) if (i != j): ret = self.root_of_unity((((k.twist() - i.twist()) - j.twist()) / 2)) else: i0 = self.one() B = self.basis() ret = (sum((((((((((y.ribbon() ** 2) / (i.ribbon() * (x.ribbon() ** 2))) * self.s_ij(i0, y)) * self.s_ij(i, z)) * self.s_ijconj(x, z)) * self.s_ijconj(k, x)) * self.s_ijconj(y, z)) / self.s_ij(i0, z)) for x in B for y in B for z in B)) / (self.total_q_order() ** 4)) if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) def global_q_dimension(self, base_coercion=True): '\n Return the global quantum dimension, which is the sum of the squares of the\n quantum dimensions of the simple objects.\n For the Drinfeld double, it is the square of the order of the underlying quantum group.\n\n EXAMPLES::\n\n sage: G = SymmetricGroup(4)\n sage: H = FusionDouble(G)\n sage: H.global_q_dimension()\n 576\n sage: sum(x.q_dimension()^2 for x in H.basis())\n 576\n ' ret = (self._G.order() ** 2) if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) def total_q_order(self, base_coercion=True): '\n Return the positive square root of :meth:`self.global_q_dimension()\n <global_q_dimension>` as an element of :meth:`self.field() <field>`.\n\n For the Drinfeld double of a finite group `G`, this equals the\n cardinality of `G`. This is also equal to `\\sum d_i^2 \\theta_i^{\\pm 1}`,\n where `i` runs through the simple objects, `d_i` is the quantum\n dimension, and `\\theta_i` is the twist. This sum with `\\theta_i` is\n denoted `p_-` in [BaKi2001]_ Chapter 3.\n\n EXAMPLES::\n\n sage: FusionDouble(DihedralGroup(7)).total_q_order()\n 14\n ' ret = self._G.order() if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) D_minus = D_plus = total_q_order def is_multiplicity_free(self, verbose=False): '\n Return ``True`` if all fusion coefficients are at most 1.\n\n EXAMPLES::\n\n sage: FusionDouble(SymmetricGroup(3)).is_multiplicity_free()\n True\n sage: FusionDouble(SymmetricGroup(4)).is_multiplicity_free()\n False\n\n sage: FusionDouble(SymmetricGroup(3)).is_multiplicity_free(True)\n Checking multiplicity freeness\n True\n sage: FusionDouble(SymmetricGroup(4)).is_multiplicity_free(True)\n Checking multiplicity freeness\n N(s2,s13,s13) = 2\n False\n ' if verbose: print('Checking multiplicity freeness') from itertools import product for (i, j, k) in product(self.basis(), repeat=3): if (self.N_ijk(i, j, k) > 1): print(('N(%s,%s,%s) = %s' % (i, j, k, self.N_ijk(i, j, k)))) return False return True return all(((self.N_ijk(i, j, k) <= 1) for i in self.basis() for j in self.basis() for k in self.basis())) @cached_method def one_basis(self): '\n The unit element of the ring, which is the first basis element.\n\n EXAMPLES::\n\n sage: FusionDouble(CyclicPermutationGroup(2), prefix="h").one()\n h0\n ' return ZZ.zero() @cached_method def dual(self, i): '\n Return the dual object ``i^\\ast`` to ``i``.\n\n The dual is also available as an element method of ``i``.\n\n EXAMPLES::\n\n sage: K = FusionDouble(CyclicPermutationGroup(3),prefix="k")\n sage: [(x,K.dual(x)) for x in K.basis()]\n [(k0, k0),\n (k1, k2),\n (k2, k1),\n (k3, k6),\n (k4, k8),\n (k5, k7),\n (k6, k3),\n (k7, k5),\n (k8, k4)]\n sage: all(K.dual(x)==x.dual() for x in K.basis())\n True\n ' sz = self.one() for j in self.basis(): if (self.N_ijk(i, j, sz) > 0): return j def product_on_basis(self, a, b): '\n Return the product of two basis elements corresponding to keys `a` and `b`.\n\n INPUT:\n\n - ``a`, ``b`` -- keys for the dictionary ``self._names`` representing simple objects\n\n EXAMPLES::\n\n sage: Q=FusionDouble(SymmetricGroup(3),prefix="q",inject_variables=True)\n sage: q3*q4\n q1 + q2 + q5 + q6 + q7\n sage: Q._names\n {0: \'q0\', 1: \'q1\', 2: \'q2\', 3: \'q3\', 4: \'q4\', 5: \'q5\', 6: \'q6\', 7: \'q7\'}\n sage: Q.product_on_basis(3,4)\n q1 + q2 + q5 + q6 + q7\n ' d = {k.support_of_term(): val for k in self.basis() if (val := self.N_ijk(self.monomial(a), self.monomial(b), self.dual(k)))} return self._from_dict(d, remove_zeros=False) def group(self): '\n Return the underlying group.\n\n EXAMPLES::\n\n sage: FusionDouble(DiCyclicGroup(4)).group()\n Dicyclic group of order 16 as a permutation group\n ' return self._G def get_fmatrix(self, *args, **kwargs): '\n Construct an :class:`FMatrix` factory to solve the pentagon and\n hexagon relations and organize the resulting F-symbols.\n\n EXAMPLES::\n\n sage: f = FusionDouble(SymmetricGroup(3)).get_fmatrix(); f\n F-Matrix factory for The Fusion Ring of the Drinfeld Double of\n Symmetric group of order 3! as a permutation group\n ' if ((not hasattr(self, 'fmats')) or kwargs.get('new', False)): kwargs.pop('new', None) from sage.algebras.fusion_rings.f_matrix import FMatrix self.fmats = FMatrix(self, *args, **kwargs) return self.fmats class Element(CombinatorialFreeModule.Element): def is_simple_object(self): '\n Determine whether ``self`` is a simple object (basis element) of the fusion ring.\n\n EXAMPLES::\n\n sage: H = FusionDouble(CyclicPermutationGroup(2), prefix="g", inject_variables=True)\n sage: [x.is_simple_object() for x in [g0, g1, g0+g1]]\n [True, True, False]\n ' return (len(self._monomial_coefficients) == 1) def g(self): '\n The data determining a simple object consists of a conjugacy\n class representative `g` and an irreducible character `\\chi` of\n the centralizer of `g`.\n\n Returns the conjugacy class representative of the underlying\n group corresponding to a simple object. See also :meth:`char`.\n\n EXAMPLES::\n\n sage: G = QuaternionGroup()\n sage: H = FusionDouble(G, prefix="e", inject_variables=True)\n sage: e10.g()\n (1,3)(2,4)(5,7)(6,8)\n sage: e10.char()\n Character of Subgroup generated by [(1,2,3,4)(5,6,7,8), (1,5,3,7)(2,8,4,6)]\n of (Quaternion group of order 8 as a permutation group)\n ' return self.parent()._elt[self.support_of_term()] def char(self): '\n Return the character `\\chi` corresponding to ``self``.\n\n The data determining a simple object consists of a conjugacy\n class representative `g` and an irreducible character `\\chi` of\n the centralizer of `g`.\n\n .. SEEALSO:: :meth:`g`\n\n EXAMPLES::\n\n sage: G = DihedralGroup(5)\n sage: H = FusionDouble(G, prefix="f", inject_variables=True)\n sage: f10.g()\n (1,2,3,4,5)\n sage: f10.char()\n Character of Subgroup generated by [(1,2,3,4,5)] of\n (Dihedral group of order 10 as a permutation group)\n ' return self.parent()._chi[self.support_of_term()] def ribbon(self, base_coercion=True): '\n The twist or ribbon of the simple object.\n\n EXAMPLES::\n\n sage: H = FusionDouble(CyclicPermutationGroup(3))\n sage: [i.ribbon() for i in H.basis()]\n [1, 1, 1, 1, zeta3, -zeta3 - 1, 1, -zeta3 - 1, zeta3]\n ' i = self.support_of_term() P = self.parent() ret = (P._char_cache(i, self.g()) / P._char_cache(i, P._G.one())) if ((not base_coercion) or (P._basecoer is None)): return ret return self.parent()._basecoer(ret) def twist(self, reduced=True): '\n Return a rational number `h` such that `\\theta = e^{i \\pi h}`\n is the twist of ``self``.\n\n The quantity `e^{i \\pi h}` is also available using :meth:`ribbon`.\n\n This method is only available for simple objects.\n\n EXAMPLES::\n\n sage: Q=FusionDouble(CyclicPermutationGroup(3))\n sage: [x.twist() for x in Q.basis()]\n [0, 0, 0, 0, 2/3, 4/3, 0, 4/3, 2/3]\n sage: [x.ribbon() for x in Q.basis()]\n [1, 1, 1, 1, zeta3, -zeta3 - 1, 1, -zeta3 - 1, zeta3]\n\n TESTS::\n\n sage: H = FusionDouble(AlternatingGroup(4))\n sage: sum(H.basis()).twist()\n Traceback (most recent call last):\n ...\n ValueError: quantum twist is only available for simple objects\n ' if (not self.is_simple_object()): raise ValueError('quantum twist is only available for simple objects') P = self.parent() zeta = P.field().gen() rib = self.ribbon() norm = (2 * P._cyclotomic_order) for k in range((4 * P._cyclotomic_order)): if ((zeta ** k) == rib): return (k / norm) def dual(self): '\n Return the dual of ``self``.\n\n This method is only available for simple objects.\n\n EXAMPLES::\n\n sage: G = CyclicPermutationGroup(4)\n sage: H = FusionDouble(G, prefix="j")\n sage: [x for x in H.basis() if x == x.dual()]\n [j0, j1, j8, j9]\n\n TESTS::\n\n sage: H = FusionDouble(AlternatingGroup(4))\n sage: sum(H.basis()).dual()\n Traceback (most recent call last):\n ...\n ValueError: dual is only available for simple objects\n ' if (not self.is_simple_object()): raise ValueError('dual is only available for simple objects') return self.parent().dual(self) @cached_method def q_dimension(self, base_coercion=True): '\n Return the q-dimension of ``self``.\n\n This method is only available for simple objects.\n\n EXAMPLES::\n\n sage: G = AlternatingGroup(4)\n sage: H = FusionDouble(G)\n sage: [x.q_dimension() for x in H.basis()]\n [1, 1, 1, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4]\n sage: sum(x.q_dimension()^2 for x in H.basis()) == G.order()^2\n True\n\n TESTS::\n\n sage: H = FusionDouble(AlternatingGroup(4))\n sage: sum(H.basis()).q_dimension()\n Traceback (most recent call last):\n ...\n ValueError: quantum dimension is only available for simple objects\n ' if (not self.is_simple_object()): raise ValueError('quantum dimension is only available for simple objects') return self.parent().s_ij(self, self.parent().one())
class FusionRing(WeylCharacterRing): '\n Return the Fusion Ring (Verlinde Algebra) of level ``k``.\n\n INPUT:\n\n - ``ct`` -- the Cartan type of a simple (finite-dimensional) Lie algebra\n - ``k`` -- a nonnegative integer\n - ``conjugate`` -- (default ``False``) set ``True`` to obtain\n the complex conjugate ring\n - ``cyclotomic_order`` -- (default computed depending on ``ct`` and ``k``)\n - ``fusion_labels`` -- (default None) either a tuple of strings to use as labels of the\n basis of simple objects, or a string from which the labels will be\n constructed\n - ``inject_variables`` -- (default ``False``): use with ``fusion_labels``.\n If ``inject_variables`` is ``True``, the fusion labels will be variables\n that can be accessed from the command line\n\n The cyclotomic order is an integer `N` such that all computations\n will return elements of the cyclotomic field of `N`-th roots of unity.\n Normally you will never need to change this but consider changing it\n if :meth:`root_of_unity` raises a :class:`ValueError`.\n\n This algebra has a basis (sometimes called *primary fields* but here\n called *simple objects*) indexed by the weights of level `\\leq k`.\n These arise as the fusion algebras of Wess-Zumino-Witten (WZW) conformal\n field theories, or as Grothendieck groups of tilting modules for quantum\n groups at roots of unity. The :class:`FusionRing` class is implemented as\n a variant of the :class:`WeylCharacterRing`.\n\n REFERENCES:\n\n - [BaKi2001]_ Chapter 3\n - [DFMS1996]_ Chapter 16\n - [EGNO2015]_ Chapter 8\n - [Feingold2004]_\n - [Fuchs1994]_\n - [Row2006]_\n - [Walton1990]_\n - [Wan2010]_\n\n EXAMPLES::\n\n sage: A22 = FusionRing("A2", 2)\n sage: [f1, f2] = A22.fundamental_weights()\n sage: M = [A22(x) for x in [0*f1, 2*f1, 2*f2, f1+f2, f2, f1]]\n sage: [M[3] * x for x in M]\n [A22(1,1),\n A22(0,1),\n A22(1,0),\n A22(0,0) + A22(1,1),\n A22(0,1) + A22(2,0),\n A22(1,0) + A22(0,2)]\n\n You may assign your own labels to the basis elements. In the next\n example, we create the `SO(5)` fusion ring of level `2`, check the\n weights of the basis elements, then assign new labels to them while\n injecting them into the global namespace::\n\n sage: B22 = FusionRing("B2", 2)\n sage: b = [B22(x) for x in B22.get_order()]; b\n [B22(0,0), B22(1,0), B22(0,1), B22(2,0), B22(1,1), B22(0,2)]\n sage: [x.weight() for x in b]\n [(0, 0), (1, 0), (1/2, 1/2), (2, 0), (3/2, 1/2), (1, 1)]\n sage: B22.fusion_labels([\'I0\', \'Y1\', \'X\', \'Z\', \'Xp\', \'Y2\'], inject_variables=True)\n sage: b = [B22(x) for x in B22.get_order()]; b\n [I0, Y1, X, Z, Xp, Y2]\n sage: [(x, x.weight()) for x in b]\n [(I0, (0, 0)),\n (Y1, (1, 0)),\n (X, (1/2, 1/2)),\n (Z, (2, 0)),\n (Xp, (3/2, 1/2)),\n (Y2, (1, 1))]\n sage: X * Y1\n X + Xp\n sage: Z * Z\n I0\n\n A fixed order of the basis keys is available with :meth:`get_order`.\n This is the order used by methods such as :meth:`s_matrix`. You may\n use :meth:`CombinatorialFreeModule.set_order` to reorder the basis::\n\n sage: B22.set_order([x.weight() for x in [I0, Y1, Y2, X, Xp, Z]])\n sage: [B22(x) for x in B22.get_order()]\n [I0, Y1, Y2, X, Xp, Z]\n\n To reset the labels, you may run :meth:`fusion_labels` with no parameter::\n\n sage: B22.fusion_labels()\n sage: [B22(x) for x in B22.get_order()]\n [B22(0,0), B22(1,0), B22(0,2), B22(0,1), B22(1,1), B22(2,0)]\n\n To reset the order to the default, simply set it to the list of basis\n element keys::\n\n sage: B22.set_order(B22.basis().keys().list())\n sage: [B22(x) for x in B22.get_order()]\n [B22(0,0), B22(1,0), B22(0,1), B22(2,0), B22(1,1), B22(0,2)]\n\n The fusion ring has a number of methods that reflect its role\n as the Grothendieck ring of a *modular tensor category* (MTC). These\n include twist methods :meth:`Element.twist` and :meth:`Element.ribbon`\n for its elements related to the ribbon structure, and the\n S-matrix :meth:`s_ij`.\n\n There are two natural normalizations of the S-matrix. Both\n are explained in Chapter 3 of [BaKi2001]_. The one that is computed\n by the method :meth:`s_matrix`, or whose individual entries\n are computed by :meth:`s_ij` is denoted `\\tilde{s}` in\n [BaKi2001]_. It is not unitary.\n\n The unitary S-matrix is `s=D^{-1/2}\\tilde{s}` where\n\n .. MATH::\n\n D = \\sum_V d_i(V)^2.\n\n The sum is over all simple objects `V` with\n `d_i(V)` the *quantum dimension*. We will call quantity `D`\n the *global quantum dimension* and `\\sqrt{D}` the\n *total quantum order*. They are computed by :meth:`global_q_dimension`\n and :meth:`total_q_order`. The unitary S-matrix `s` may be obtained\n using :meth:`s_matrix` with the option ``unitary=True``.\n\n Let us check the Verlinde formula, which is [DFMS1996]_ (16.3). This\n famous identity states that\n\n .. MATH::\n\n N^k_{ij} = \\sum_l \\frac{s(i, \\ell)\\, s(j, \\ell)\\, \\overline{s(k, \\ell)}}{s(I, \\ell)},\n\n where `N^k_{ij}` are the fusion coefficients, i.e. the structure\n constants of the fusion ring, and ``I`` is the unit object.\n The S-matrix has the property that if `i*` denotes the dual\n object of `i`, implemented in Sage as ``i.dual()``, then\n\n .. MATH::\n\n s(i*, j) = s(i, j*) = \\overline{s(i, j)}.\n\n This is equation (16.5) in [DFMS1996]_. Thus with `N_{ijk}=N^{k*}_{ij}`\n the Verlinde formula is equivalent to\n\n .. MATH::\n\n N_{ijk} = \\sum_l \\frac{s(i, \\ell)\\, s(j, \\ell)\\, s(k, \\ell)}{s(I, \\ell)},\n\n In this formula `s` is the normalized unitary S-matrix\n denoted `s` in [BaKi2001]_. We may define a function that\n corresponds to the right-hand side, except using\n `\\tilde{s}` instead of `s`::\n\n sage: def V(i, j, k):\n ....: R = i.parent()\n ....: return sum(R.s_ij(i, l) * R.s_ij(j, l) * R.s_ij(k, l) / R.s_ij(R.one(), l)\n ....: for l in R.basis())\n\n This does not produce ``self.N_ijk(i, j, k)`` exactly, because of the\n missing normalization factor. The following code to check the\n Verlinde formula takes this into account::\n\n sage: def test_verlinde(R):\n ....: b0 = R.one()\n ....: c = R.global_q_dimension()\n ....: return all(V(i, j, k) == c * R.N_ijk(i, j, k) for i in R.basis()\n ....: for j in R.basis() for k in R.basis())\n\n Every fusion ring should pass this test::\n\n sage: test_verlinde(FusionRing("A2", 1))\n True\n sage: test_verlinde(FusionRing("B4", 2)) # long time (.56s)\n True\n\n As an exercise, the reader may verify the examples in\n Section 5.3 of [RoStWa2009]_. Here we check the example\n of the Ising modular tensor category, which is related\n to the Belavin, Polyakov, Zamolodchikov minimal model `M(4, 3)`\n or to an `E_8` coset model. See [DFMS1996]_ Sections 7.4.2 and 18.4.1.\n [RoStWa2009]_ Example 5.3.4 tells us how to\n construct it as the conjugate of the `E_8` level 2\n :class:`FusionRing`::\n\n sage: I = FusionRing("E8", 2, conjugate=True)\n sage: I.fusion_labels(["i0", "p", "s"], inject_variables=True)\n sage: b = I.basis().list(); b\n [i0, p, s]\n sage: Matrix([[x*y for x in b] for y in b]) # long time (.93s)\n [ i0 p s]\n [ p i0 s]\n [ s s i0 + p]\n sage: [x.twist() for x in b]\n [0, 1, 1/8]\n sage: [x.ribbon() for x in b]\n [1, -1, zeta128^8]\n sage: [I.r_matrix(i, j, k) for (i, j, k) in [(s, s, i0), (p, p, i0), (p, s, s), (s, p, s), (s, s, p)]]\n [-zeta128^56, -1, -zeta128^32, -zeta128^32, zeta128^24]\n sage: I.r_matrix(s, s, i0) == I.root_of_unity(-1/8)\n True\n sage: I.global_q_dimension()\n 4\n sage: I.total_q_order()\n 2\n sage: [x.q_dimension()^2 for x in b]\n [1, 1, 2]\n sage: I.s_matrix()\n [ 1 1 -zeta128^48 + zeta128^16]\n [ 1 1 zeta128^48 - zeta128^16]\n [-zeta128^48 + zeta128^16 zeta128^48 - zeta128^16 0]\n sage: I.s_matrix().apply_map(lambda x:x^2)\n [1 1 2]\n [1 1 2]\n [2 2 0]\n\n The term *modular tensor category* refers to the fact that associated\n with the category there is a projective representation of the modular\n group `SL(2, \\ZZ)`. We recall that this group is generated by\n\n .. MATH::\n\n S = \\begin{pmatrix} & -1\\\\1\\end{pmatrix}, \\qquad\n T = \\begin{pmatrix} 1 & 1\\\\ &1 \\end{pmatrix}\n\n subject to the relations `(ST)^3 = S^2`, `S^2T = TS^2`, and `S^4 = I`.\n Let `s` be the normalized S-matrix, and\n `t` the diagonal matrix whose entries are the twists of the simple\n objects. Let `s` the unitary S-matrix and `t` the matrix of twists,\n and `C` the conjugation matrix :meth:`conj_matrix`. Let\n\n .. MATH::\n\n D_+ = \\sum_i d_i^2 \\theta_i, \\qquad D_- = d_i^2 \\theta_i^{-1},\n\n where `d_i` and `\\theta_i` are the quantum dimensions and twists of the\n simple objects. Let `c` be the Virasoro central charge, a rational number\n that is computed in :meth:`virasoro_central_charge`. It is known that\n\n .. MATH::\n\n \\sqrt{\\frac{D_+}{D_-}} = e^{i\\pi c/4}.\n\n It is proved in [BaKi2001]_ Equation (3.1.17) that\n\n .. MATH::\n\n (st)^3 = e^{i\\pi c/4} s^2, \\qquad\n s^2 = C, \\qquad C^2 = 1, \\qquad Ct = tC.\n\n Therefore `S \\mapsto s, T \\mapsto t` is a projective representation\n of `SL(2, \\ZZ)`. Let us confirm these identities for the Fibonacci MTC\n ``FusionRing("G2", 1)``::\n\n sage: R = FusionRing("G2", 1)\n sage: S = R.s_matrix(unitary=True)\n sage: T = R.twists_matrix()\n sage: C = R.conj_matrix()\n sage: c = R.virasoro_central_charge(); c\n 14/5\n sage: (S*T)^3 == R.root_of_unity(c/4) * S^2\n True\n sage: S^2 == C\n True\n sage: C*T == T*C\n True\n ' @staticmethod def __classcall__(cls, ct, k, base_ring=ZZ, prefix=None, style='coroots', conjugate=False, cyclotomic_order=None, fusion_labels=None, inject_variables=False): '\n Normalize input to ensure a unique representation.\n\n TESTS::\n\n sage: F1 = FusionRing(\'B3\', 2)\n sage: F2 = FusionRing(CartanType(\'B3\'), QQ(2), ZZ)\n sage: F3 = FusionRing(CartanType(\'B3\'), int(2), style="coroots")\n sage: F1 is F2 and F2 is F3\n True\n\n sage: A23 = FusionRing(\'A2\', 3)\n sage: TestSuite(A23).run()\n\n sage: B22 = FusionRing(\'B2\', 2)\n sage: TestSuite(B22).run()\n\n sage: C31 = FusionRing(\'C3\', 1)\n sage: TestSuite(C31).run()\n\n sage: D41 = FusionRing(\'D4\', 1)\n sage: TestSuite(D41).run()\n\n sage: G22 = FusionRing(\'G2\', 2)\n sage: TestSuite(G22).run()\n\n sage: F41 = FusionRing(\'F4\', 1)\n sage: TestSuite(F41).run()\n\n sage: E61 = FusionRing(\'E6\', 1)\n sage: TestSuite(E61).run()\n\n sage: E71 = FusionRing(\'E7\', 1)\n sage: TestSuite(E71).run()\n\n sage: E81 = FusionRing(\'E8\', 1)\n sage: TestSuite(E81).run()\n ' return super().__classcall__(cls, ct, base_ring=base_ring, prefix=prefix, style=style, k=k, conjugate=conjugate, cyclotomic_order=cyclotomic_order, fusion_labels=fusion_labels, inject_variables=inject_variables) def _test_verlinde(self, **options): '\n Check the Verlinde formula for this :class:`FusionRing` instance.\n\n EXAMPLES::\n\n sage: G22 = FusionRing("G2", 2)\n sage: G22._test_verlinde()\n ' tester = self._tester(**options) c = self.global_q_dimension() i0 = self.one() from sage.misc.misc import some_tuples B = self.basis() for (x, y, z) in some_tuples(B, 3, tester._max_runs): v = sum(((((self.s_ij(x, w) * self.s_ij(y, w)) * self.s_ij(z, w)) / self.s_ij(i0, w)) for w in B)) tester.assertEqual(v, (c * self.N_ijk(x, y, z))) def _test_total_q_order(self, **options): '\n Check that the total quantum order is real and positive.\n\n The total quantum order is the positive square root\n of the global quantum dimension. This indirectly test the\n Virasoro central charge.\n\n EXAMPLES::\n\n sage: G22 = FusionRing("G2", 2)\n sage: G22._test_total_q_order()\n ' tester = self._tester(**options) tqo = self.total_q_order(base_coercion=False) tester.assertTrue(tqo.is_real_positive()) tester.assertEqual((tqo ** 2), self.global_q_dimension(base_coercion=False)) def test_braid_representation(self, max_strands=6, anyon=None): '\n Check that we can compute valid braid group representations.\n\n INPUT:\n\n - ``max_strands`` -- (default: 6): maximum number of braid group strands\n - ``anyon`` -- (optional) run this test on this particular simple object\n\n Create a braid group representation using :meth:`get_braid_generators`\n and confirms the braid relations. This test indirectly partially\n verifies the correctness of the orthogonal F-matrix solver. If the\n code were incorrect the method would not be deterministic because the\n fusing anyon is chosen randomly. (A different choice is made for each\n number of strands tested.) However the doctest is deterministic since\n it will always return ``True``. If the anyon parameter is omitted,\n a random anyon is tested for each number of strands up to ``max_strands``.\n\n EXAMPLES::\n\n sage: A21 = FusionRing("A2", 1)\n sage: A21.test_braid_representation(max_strands=4)\n True\n sage: F41 = FusionRing("F4", 1) # long time\n sage: F41.test_braid_representation() # long time\n True\n ' if (not self.is_multiplicity_free()): raise NotImplementedError('only implemented for multiplicity free fusion rings') b = self.basis() results = [] for n_strands in range(3, (max_strands + 1)): if (anyon is not None): a = anyon else: while True: a = b.random_element() if (a != self.one()): break pow = (a ** n_strands) d = pow.monomials()[0] for (k, v) in pow.monomial_coefficients().items(): if (v > 1): d = self(k) break (comp_basis, sig) = self.get_braid_generators(a, d, n_strands, verbose=False) results.append((len(comp_basis) > 0)) results.append(self.gens_satisfy_braid_gp_rels(sig)) return all(results) def fusion_labels(self, labels=None, inject_variables=False): '\n Set the labels of the basis.\n\n INPUT:\n\n - ``labels`` -- (default: ``None``) a list of strings or string\n - ``inject_variables`` -- (default: ``False``) if ``True``, then\n inject the variable names into the global namespace; note that\n this could override objects already defined\n\n If ``labels`` is a list, the length of the list must equal the\n number of basis elements. These become the names of\n the basis elements.\n\n If ``labels`` is a string, this is treated as a prefix and a\n list of names is generated.\n\n If ``labels`` is ``None``, then this resets the labels to the default.\n\n EXAMPLES::\n\n sage: A13 = FusionRing("A1", 3)\n sage: A13.fusion_labels("x")\n sage: fb = list(A13.basis()); fb\n [x0, x1, x2, x3]\n sage: Matrix([[x*y for y in A13.basis()] for x in A13.basis()])\n [ x0 x1 x2 x3]\n [ x1 x0 + x2 x1 + x3 x2]\n [ x2 x1 + x3 x0 + x2 x1]\n [ x3 x2 x1 x0]\n\n We give an example where the variables are injected into the\n global namespace::\n\n sage: A13.fusion_labels("y", inject_variables=True)\n sage: y0\n y0\n sage: y0.parent() is A13\n True\n\n We reset the labels to the default::\n\n sage: A13.fusion_labels()\n sage: fb\n [A13(0), A13(1), A13(2), A13(3)]\n sage: y0\n A13(0)\n ' if (labels is None): self._fusion_labels = None return B = self.basis() if isinstance(labels, str): labels = [(labels + str(k)) for k in range(len(B))] elif (len(labels) != len(B)): raise ValueError('invalid data') d = {} ac = self.simple_coroots() for (j, b) in enumerate(self.get_order()): t = tuple([b.inner_product(x) for x in ac]) d[t] = labels[j] if inject_variables: inject_variable(labels[j], B[b]) self._fusion_labels = d @cached_method def field(self): '\n Return a cyclotomic field large enough to\n contain the `2 \\ell`-th roots of unity, as well as\n all the S-matrix entries.\n\n EXAMPLES::\n\n sage: FusionRing("A2", 2).field()\n Cyclotomic Field of order 60 and degree 16\n sage: FusionRing("B2", 2).field()\n Cyclotomic Field of order 40 and degree 16\n ' return CyclotomicField((4 * self._cyclotomic_order)) def fvars_field(self): '\n Return a field containing the ``CyclotomicField`` computed by\n :meth:`field` as well as all the F-symbols of the associated\n ``FMatrix`` factory object.\n\n This method is only available if ``self`` is multiplicity-free.\n\n OUTPUT:\n\n Depending on the ``CartanType`` associated to ``self`` and whether\n a call to an F-matrix solver has been made, this method\n will return the same field as :meth:`field`, a :func:`NumberField`,\n or the :class:`QQbar<AlgebraicField>`.\n See :meth:`FMatrix.attempt_number_field_computation` for more details.\n\n Before running an F-matrix solver, the output of this method matches\n that of :meth:`field`. However, the output may change upon successfully\n computing F-symbols. Requesting braid generators triggers a call to\n :meth:`FMatrix.find_orthogonal_solution`, so the output of this method\n may change after such a computation.\n\n By default, the output of methods like :meth:`r_matrix`,\n :meth:`s_matrix`, :meth:`twists_matrix`, etc. will lie in the\n ``fvars_field``, unless the ``base_coercion`` option is set to\n ``False``.\n\n This method does not trigger a solver run.\n\n EXAMPLES::\n\n sage: A13 = FusionRing("A1", 3, fusion_labels="a", inject_variables=True)\n sage: A13.fvars_field()\n Cyclotomic Field of order 40 and degree 16\n sage: A13.field()\n Cyclotomic Field of order 40 and degree 16\n sage: a2**4\n 2*a0 + 3*a2\n sage: comp_basis, sig = A13.get_braid_generators(a2, a2, 3, verbose=False) # long time (<3s)\n sage: A13.fvars_field() # long time\n Number Field in a with defining polynomial y^32 - ... - 500*y^2 + 25\n sage: a2.q_dimension().parent() # long time\n Number Field in a with defining polynomial y^32 - ... - 500*y^2 + 25\n sage: A13.field()\n Cyclotomic Field of order 40 and degree 16\n\n In some cases, the :meth:`NumberField.optimized_representation()\n <sage.rings.number_field.number_field.NumberField_absolute.optimized_representation>`\n may be used to obtain a better defining polynomial for the\n computed :func:`NumberField`.\n ' if self.is_multiplicity_free(): return self.get_fmatrix().field() raise NotImplementedError('method is only available for multiplicity free fusion rings') def root_of_unity(self, r, base_coercion=True): '\n Return `e^{i\\pi r}` as an element of ``self.field()`` if possible.\n\n INPUT:\n\n - ``r`` -- a rational number\n\n EXAMPLES::\n\n sage: A11 = FusionRing("A1", 1)\n sage: A11.field()\n Cyclotomic Field of order 24 and degree 8\n sage: for n in [1..7]:\n ....: try:\n ....: print(n, A11.root_of_unity(2/n))\n ....: except ValueError as err:\n ....: print(n, err)\n 1 1\n 2 -1\n 3 zeta24^4 - 1\n 4 zeta24^6\n 5 not a root of unity in the field\n 6 zeta24^4\n 7 not a root of unity in the field\n ' n = ((2 * r) * self._cyclotomic_order) if (n not in ZZ): raise ValueError('not a root of unity in the field') ret = (self.field().gen() ** n) if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) def get_order(self): '\n Return the weights of the basis vectors in a fixed order.\n\n You may change the order of the basis using :meth:`CombinatorialFreeModule.set_order`\n\n EXAMPLES::\n\n sage: A15 = FusionRing("A1", 5)\n sage: w = A15.get_order(); w\n [(0, 0), (1/2, -1/2), (1, -1), (3/2, -3/2), (2, -2), (5/2, -5/2)]\n sage: A15.set_order([w[k] for k in [0, 4, 1, 3, 5, 2]])\n sage: [A15(x) for x in A15.get_order()]\n [A15(0), A15(4), A15(1), A15(3), A15(5), A15(2)]\n\n .. WARNING::\n\n This duplicates :meth:`get_order` from\n :class:`CombinatorialFreeModule` except the result\n is *not* cached. Caching of\n :meth:`CombinatorialFreeModule.get_order` causes inconsistent\n results after calling :meth:`CombinatorialFreeModule.set_order`.\n\n ' if (self._order is None): self.set_order(self.basis().keys().list()) return self._order def some_elements(self): "\n Return some elements of ``self``.\n\n EXAMPLES::\n\n sage: D41 = FusionRing('D4', 1)\n sage: D41.some_elements()\n [D41(1,0,0,0), D41(0,0,1,0), D41(0,0,0,1)]\n " return [self.monomial(x) for x in self.fundamental_weights() if (self.level(x) <= self._k)] def fusion_level(self): "\n Return the level `k` of ``self``.\n\n EXAMPLES::\n\n sage: B22 = FusionRing('B2', 2)\n sage: B22.fusion_level()\n 2\n " return self._k def fusion_l(self): "\n Return the product `\\ell = m_g(k + h^\\vee)`, where `m_g` denotes the\n square of the ratio of the lengths of long to short roots of\n the underlying Lie algebra, `k` denotes the level of the FusionRing,\n and `h^\\vee` denotes the dual Coxeter number of the underlying Lie\n algebra.\n\n This value is used to define the associated root `2\\ell`-th\n of unity `q = e^{i\\pi/\\ell}`.\n\n EXAMPLES::\n\n sage: B22 = FusionRing('B2', 2)\n sage: B22.fusion_l()\n 10\n sage: D52 = FusionRing('D5', 2)\n sage: D52.fusion_l()\n 10\n " return self._l def virasoro_central_charge(self): '\n Return the Virasoro central charge of the WZW conformal\n field theory associated with the Fusion Ring.\n\n If `\\mathfrak{g}` is the corresponding semisimple Lie algebra, this is\n\n .. MATH::\n\n \\frac{k\\dim\\mathfrak{g}}{k+h^\\vee},\n\n where `k` is the level and `h^\\vee` is the dual Coxeter number.\n See [DFMS1996]_ Equation (15.61).\n\n Let `d_i` and `\\theta_i` be the quantum dimensions and\n twists of the simple objects. By Proposition 2.3 in [RoStWa2009]_,\n there exists a rational number `c` such that\n `D_+ / \\sqrt{D} = e^{i\\pi c/4}`, where `D_+ = \\sum d_i^2 \\theta_i`\n is computed in :meth:`D_plus` and `D = \\sum d_i^2 > 0` is computed\n by :meth:`global_q_dimension`. Squaring this identity and\n remembering that `D_+ D_- = D` gives\n\n .. MATH::\n\n D_+ / D_- = e^{i\\pi c/2}.\n\n EXAMPLES::\n\n sage: R = FusionRing("A1", 2)\n sage: c = R.virasoro_central_charge(); c\n 3/2\n sage: Dp = R.D_plus(); Dp\n 2*zeta32^6\n sage: Dm = R.D_minus(); Dm\n -2*zeta32^10\n sage: Dp / Dm == R.root_of_unity(c/2)\n True\n ' dim_g = (len(self.space().roots()) + self.cartan_type().rank()) return (((self._conj * self._k) * dim_g) / (self._k + self._h_check)) def conj_matrix(self): '\n Return the conjugation matrix, which is the permutation matrix\n for the conjugation (dual) operation on basis elements.\n\n EXAMPLES::\n\n sage: FusionRing("A2", 1).conj_matrix()\n [1 0 0]\n [0 0 1]\n [0 1 0]\n ' b = self.basis().list() return matrix(ZZ, [[(i == j.dual()) for i in b] for j in b]) def twists_matrix(self): '\n Return a diagonal matrix describing the twist corresponding to\n each simple object in the ``FusionRing``.\n\n EXAMPLES::\n\n sage: B21=FusionRing("B2", 1)\n sage: [x.twist() for x in B21.basis().list()]\n [0, 1, 5/8]\n sage: [B21.root_of_unity(x.twist()) for x in B21.basis().list()]\n [1, -1, zeta32^10]\n sage: B21.twists_matrix()\n [ 1 0 0]\n [ 0 -1 0]\n [ 0 0 zeta32^10]\n ' B = self.basis() return diagonal_matrix((B[x].ribbon() for x in self.get_order())) @cached_method def N_ijk(self, elt_i, elt_j, elt_k): '\n Return the symmetric fusion coefficient `N_{ijk}`.\n\n INPUT:\n\n - ``elt_i``, ``elt_j``, ``elt_k`` -- elements of the fusion basis\n\n This is the same as `N_{ij}^{k\\ast}`, where `N_{ij}^k` are\n the structure coefficients of the ring (see :meth:`Nk_ij`),\n and `k\\ast`` denotes the dual element. The coefficient `N_{ijk}`\n is unchanged under permutations of the three basis vectors.\n\n EXAMPLES::\n\n sage: G23 = FusionRing("G2", 3)\n sage: G23.fusion_labels("g")\n sage: b = G23.basis().list(); b\n [g0, g1, g2, g3, g4, g5]\n sage: [(x, y, z) for x in b for y in b for z in b if G23.N_ijk(x, y, z) > 1]\n [(g3, g3, g3), (g3, g3, g4), (g3, g4, g3), (g4, g3, g3)]\n sage: all(G23.N_ijk(x, y, z)==G23.N_ijk(y, z, x) for x in b for y in b for z in b)\n True\n sage: all(G23.N_ijk(x, y, z)==G23.N_ijk(y, x, z) for x in b for y in b for z in b)\n True\n ' return (elt_i * elt_j).monomial_coefficients().get(elt_k.dual().weight(), 0) @cached_method def Nk_ij(self, elt_i, elt_j, elt_k): '\n Return the fusion coefficient `N^k_{ij}`.\n\n These are the structure coefficients of the fusion ring, so\n\n .. MATH::\n\n i * j = \\sum_{k} N_{ij}^k k.\n\n EXAMPLES::\n\n sage: A22 = FusionRing("A2", 2)\n sage: b = A22.basis().list()\n sage: all(x*y == sum(A22.Nk_ij(x, y, k)*k for k in b) for x in b for y in b)\n True\n ' return (elt_i * elt_j).monomial_coefficients(copy=False).get(elt_k.weight(), 0) @cached_method def s_ij(self, elt_i, elt_j, base_coercion=True): '\n Return the element of the S-matrix of this fusion ring corresponding to\n the given elements.\n\n This is the unnormalized S-matrix, denoted `\\tilde{s}_{ij}`\n in [BaKi2001]_ . To obtain the normalized S-matrix, divide by\n :meth:`global_q_dimension()` or use :meth:`S_matrix()` with\n the option ``unitary=True``.\n\n This is computed using the formula\n\n .. MATH::\n\n s_{i, j} = \\frac{1}{\\theta_i\\theta_j} \\sum_k N_{ik}^j d_k \\theta_k,\n\n where `\\theta_k` is the twist and `d_k` is the quantum\n dimension. See [Row2006]_ Equation (2.2) or [EGNO2015]_\n Proposition 8.13.8.\n\n INPUT:\n\n - ``elt_i``, ``elt_j`` -- elements of the fusion basis\n\n EXAMPLES::\n\n sage: G21 = FusionRing("G2", 1)\n sage: b = G21.basis()\n sage: [G21.s_ij(x, y) for x in b for y in b]\n [1, -zeta60^14 + zeta60^6 + zeta60^4, -zeta60^14 + zeta60^6 + zeta60^4, -1]\n ' ijtwist = (elt_i.twist() + elt_j.twist()) ret = sum((((k.q_dimension(base_coercion=False) * self.Nk_ij(elt_i, k, elt_j)) * self.root_of_unity((k.twist() - ijtwist), base_coercion=False)) for k in self.basis())) if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) def s_ijconj(self, elt_i, elt_j, base_coercion=True): '\n Return the conjugate of the element of the S-matrix given by\n ``self.s_ij(elt_i, elt_j, base_coercion=base_coercion)``.\n\n See :meth:`s_ij`.\n\n EXAMPLES::\n\n sage: G21 = FusionRing("G2", 1)\n sage: b = G21.basis()\n sage: [G21.s_ijconj(x, y) for x in b for y in b]\n [1, -zeta60^14 + zeta60^6 + zeta60^4, -zeta60^14 + zeta60^6 + zeta60^4, -1]\n\n This method works with all possible types of fields returned by\n ``self.fmats.field()``.\n\n TESTS::\n\n sage: E62 = FusionRing("E6", 2)\n sage: E62.fusion_labels("e", inject_variables=True)\n sage: E62.s_ij(e8, e1).conjugate() == E62.s_ijconj(e8, e1)\n True\n sage: F41 = FusionRing("F4", 1)\n sage: fmats = F41.get_fmatrix()\n sage: fmats.find_orthogonal_solution(verbose=False)\n sage: b = F41.basis()\n sage: all(F41.s_ijconj(x, y) == F41._basecoer(F41.s_ij(x, y, base_coercion=False).conjugate()) for x in b for y in b)\n True\n sage: G22 = FusionRing("G2", 2)\n sage: fmats = G22.get_fmatrix()\n sage: fmats.find_orthogonal_solution(verbose=False) # long time (~11 s)\n sage: b = G22.basis() # long time\n sage: all(G22.s_ijconj(x, y) == fmats.field()(G22.s_ij(x, y, base_coercion=False).conjugate()) for x in b for y in b) # long time\n True\n ' ret = self.s_ij(elt_i, elt_j, base_coercion=False).conjugate() if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) def s_matrix(self, unitary=False, base_coercion=True): '\n Return the S-matrix of this fusion ring.\n\n OPTIONAL:\n\n - ``unitary`` -- (default: ``False``) set to ``True`` to obtain\n the unitary S-matrix\n\n Without the ``unitary`` parameter, this is the matrix denoted\n `\\widetilde{s}` in [BaKi2001]_.\n\n EXAMPLES::\n\n sage: D91 = FusionRing("D9", 1)\n sage: D91.s_matrix()\n [ 1 1 1 1]\n [ 1 1 -1 -1]\n [ 1 -1 -zeta136^34 zeta136^34]\n [ 1 -1 zeta136^34 -zeta136^34]\n sage: S = D91.s_matrix(unitary=True); S\n [ 1/2 1/2 1/2 1/2]\n [ 1/2 1/2 -1/2 -1/2]\n [ 1/2 -1/2 -1/2*zeta136^34 1/2*zeta136^34]\n [ 1/2 -1/2 1/2*zeta136^34 -1/2*zeta136^34]\n sage: S*S.conjugate()\n [1 0 0 0]\n [0 1 0 0]\n [0 0 1 0]\n [0 0 0 1]\n ' b = self.basis() S = matrix([[self.s_ij(b[x], b[y], base_coercion=base_coercion) for x in self.get_order()] for y in self.get_order()]) if unitary: return (S / self.total_q_order(base_coercion=base_coercion)) return S @cached_method def r_matrix(self, i, j, k, base_coercion=True): '\n Return the R-matrix entry corresponding to the subobject ``k``\n in the tensor product of ``i`` with ``j``.\n\n .. WARNING::\n\n This method only gives complete information when `N_{ij}^k = 1`\n (an important special case). Tables of MTC including R-matrices\n may be found in Section 5.3 of [RoStWa2009]_ and in [Bond2007]_.\n\n The R-matrix is a homomorphism `i \\otimes j \\rightarrow j \\otimes i`.\n This may be hard to describe since the object `i \\otimes j`\n may be reducible. However if `k` is a simple subobject of\n `i \\otimes j` it is also a subobject of `j \\otimes i`. If we fix\n embeddings `k \\rightarrow i \\otimes j`, `k \\rightarrow j \\otimes i`\n we may ask for the scalar automorphism of `k` induced by the\n R-matrix. This method computes that scalar. It is possible to\n adjust the set of embeddings `k \\rightarrow i \\otimes j` (called\n a *gauge*) so that this scalar equals\n\n .. MATH::\n\n \\pm \\sqrt{\\frac{ \\theta_k }{ \\theta_i \\theta_j }}.\n\n If `i \\neq j`, the gauge may be used to control the sign of\n the square root. But if `i = j` then we must be careful\n about the sign. These cases are computed by a formula\n of [BDGRTW2019]_, Proposition 2.3.\n\n EXAMPLES::\n\n sage: I = FusionRing("E8", 2, conjugate=True) # Ising MTC\n sage: I.fusion_labels(["i0", "p", "s"], inject_variables=True)\n sage: I.r_matrix(s, s, i0) == I.root_of_unity(-1/8)\n True\n sage: I.r_matrix(p, p, i0)\n -1\n sage: I.r_matrix(p, s, s) == I.root_of_unity(-1/2)\n True\n sage: I.r_matrix(s, p, s) == I.root_of_unity(-1/2)\n True\n sage: I.r_matrix(s, s, p) == I.root_of_unity(3/8)\n True\n ' if (self.Nk_ij(i, j, k) == 0): return (self.field().zero() if ((not base_coercion) or (self._basecoer is None)) else self.fvars_field().zero()) if (i != j): ret = self.root_of_unity((((k.twist(reduced=False) - i.twist(reduced=False)) - j.twist(reduced=False)) / 2), base_coercion=False) else: i0 = self.one() B = self.basis() ret = (sum((((((((((y.ribbon(base_coercion=False) ** 2) / (i.ribbon(base_coercion=False) * (x.ribbon(base_coercion=False) ** 2))) * self.s_ij(i0, y, base_coercion=False)) * self.s_ij(i, z, base_coercion=False)) * self.s_ijconj(x, z, base_coercion=False)) * self.s_ijconj(k, x, base_coercion=False)) * self.s_ijconj(y, z, base_coercion=False)) / self.s_ij(i0, z, base_coercion=False)) for x in B for y in B for z in B)) / (self.total_q_order(base_coercion=False) ** 4)) if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) def global_q_dimension(self, base_coercion=True): '\n Return `\\sum d_i^2`, where the sum is over all simple objects\n and `d_i` is the quantum dimension.\n\n The global `q`-dimension is a positive real number.\n\n EXAMPLES::\n\n sage: FusionRing("E6", 1).global_q_dimension()\n 3\n ' ret = sum(((x.q_dimension(base_coercion=False) ** 2) for x in self.basis())) if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) def total_q_order(self, base_coercion=True): '\n Return the positive square root of :meth:`self.global_q_dimension()\n <global_q_dimension>` as an element of :meth:`self.field() <field>`.\n\n This is implemented as `D_{+}e^{-i\\pi c/4}`, where `D_+` is\n :meth:`D_plus()` and `c` is :meth:`virasoro_central_charge()`.\n\n EXAMPLES::\n\n sage: F = FusionRing("G2", 1)\n sage: tqo=F.total_q_order(); tqo\n zeta60^15 - zeta60^11 - zeta60^9 + 2*zeta60^3 + zeta60\n sage: tqo.is_real_positive()\n True\n sage: tqo^2 == F.global_q_dimension()\n True\n ' c = self.virasoro_central_charge() ret = (self.D_plus(base_coercion=False) * self.root_of_unity(((- c) / 4), base_coercion=False)) if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) def D_plus(self, base_coercion=True): '\n Return `\\sum d_i^2\\theta_i` where `i` runs through the simple objects,\n `d_i` is the quantum dimension and `\\theta_i` is the twist.\n\n This is denoted `p_+` in [BaKi2001]_ Chapter 3.\n\n EXAMPLES::\n\n sage: B31 = FusionRing("B3", 1)\n sage: Dp = B31.D_plus(); Dp\n 2*zeta48^13 - 2*zeta48^5\n sage: Dm = B31.D_minus(); Dm\n -2*zeta48^3\n sage: Dp*Dm == B31.global_q_dimension()\n True\n sage: c = B31.virasoro_central_charge(); c\n 7/2\n sage: Dp/Dm == B31.root_of_unity(c/2)\n True\n ' ret = sum((((x.q_dimension(base_coercion=False) ** 2) * x.ribbon(base_coercion=False)) for x in self.basis())) if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) def D_minus(self, base_coercion=True): '\n Return `\\sum d_i^2\\theta_i^{-1}` where `i` runs through the simple\n objects, `d_i` is the quantum dimension and `\\theta_i` is the twist.\n\n This is denoted `p_-` in [BaKi2001]_ Chapter 3.\n\n EXAMPLES::\n\n sage: E83 = FusionRing("E8", 3, conjugate=True)\n sage: [Dp, Dm] = [E83.D_plus(), E83.D_minus()]\n sage: Dp*Dm == E83.global_q_dimension()\n True\n sage: c = E83.virasoro_central_charge(); c\n -248/11\n sage: Dp*Dm == E83.global_q_dimension()\n True\n ' ret = sum((((x.q_dimension(base_coercion=False) ** 2) / x.ribbon(base_coercion=False)) for x in self.basis())) if ((not base_coercion) or (self._basecoer is None)): return ret return self._basecoer(ret) def is_multiplicity_free(self): '\n Return ``True`` if the fusion multiplicities\n :meth:`Nk_ij` are bounded by 1.\n\n The :class:`FMatrix` is available only for multiplicity free\n instances of :class:`FusionRing`.\n\n EXAMPLES::\n\n sage: [FusionRing(ct, k).is_multiplicity_free() for ct in ("A1", "A2", "B2", "C3") for k in (1, 2, 3)]\n [True, True, True, True, True, False, True, True, False, True, False, False]\n ' ct = self.cartan_type() k = self.fusion_level() if (ct.letter == 'A'): if (ct.n == 1): return True return (k <= 2) if (ct.letter in ['B', 'D', 'F', 'G']): return (k <= 2) if (ct.letter == 'C'): if (ct.n == 2): return (k <= 2) return (k == 1) if (ct.letter == 'E'): if (ct.n == 8): return (k <= 3) return (k <= 2) def get_computational_basis(self, a, b, n_strands): '\n Return the so-called computational basis for `\\text{Hom}(b, a^n)`.\n\n INPUT:\n\n - ``a`` -- a basis element\n - ``b`` -- another basis element\n - ``n_strands`` -- the number of strands for a braid group\n\n Let `n=` ``n_strands`` and let `k` be the greatest integer `\\leq n/2`.\n The braid group acts on `\\text{Hom}(b, a^n)`. This action\n is computed in :meth:`get_braid_generators`. This method\n returns the computational basis in the form of a list of\n fusion trees. Each tree is represented by an `(n-2)`-tuple\n\n .. MATH::\n\n (m_1, \\ldots, m_k, l_1, \\ldots, l_{k-2})\n\n such that each `m_j` is an irreducible constituent in `a \\otimes a`\n and\n\n .. MATH::\n\n \\begin{array}{l}\n b \\in l_{k-2} \\otimes m_{k}, \\\\\n l_{k-2} \\in l_{k-3} \\otimes m_{k-1}, \\\\\n \\cdots, \\\\\n l_2 \\in l_1 \\otimes m_3, \\\\\n l_1 \\in m_1 \\otimes m_2,\n \\end{array}\n\n where `z \\in x \\otimes y` means `N_{xy}^z \\neq 0`.\n\n As a computational device when ``n_strands`` is odd, we pad the\n vector `(m_1, \\ldots, m_k)` with an additional `m_{k+1}` equal to `a`.\n However, this `m_{k+1}` does *not* appear in the output of this method.\n\n The following example appears in Section 3.1 of [CW2015]_.\n\n EXAMPLES::\n\n sage: A14 = FusionRing("A1", 4)\n sage: A14.get_order()\n [(0, 0), (1/2, -1/2), (1, -1), (3/2, -3/2), (2, -2)]\n sage: A14.fusion_labels(["zero", "one", "two", "three", "four"], inject_variables=True)\n sage: [A14(x) for x in A14.get_order()]\n [zero, one, two, three, four]\n sage: A14.get_computational_basis(one, two, 4)\n [(two, two), (two, zero), (zero, two)]\n ' def _get_trees(fr, top_row, root): if (len(top_row) == 2): (m1, m2) = top_row return ([[]] if fr.Nk_ij(m1, m2, root) else []) else: (m1, m2) = top_row[:2] return [(l, *b) for l in fr.basis() for b in _get_trees(fr, ([l] + top_row[2:]), root) if fr.Nk_ij(m1, m2, l)] comp_basis = [] for top in product((a * a).monomials(), repeat=(n_strands // 2)): top_row = (list(top) + ([a] * (n_strands % 2))) comp_basis.extend(((*top, *levels) for levels in _get_trees(self, top_row, b))) return comp_basis def get_fmatrix(self, *args, **kwargs): '\n Construct an :class:`FMatrix` factory to solve the pentagon relations\n and organize the resulting F-symbols.\n\n EXAMPLES::\n\n sage: A15 = FusionRing("A1", 5)\n sage: A15.get_fmatrix()\n F-Matrix factory for The Fusion Ring of Type A1 and level 5 with Integer Ring coefficients\n ' if ((not hasattr(self, 'fmats')) or kwargs.get('new', False)): kwargs.pop('new', None) from sage.algebras.fusion_rings.f_matrix import FMatrix self.fmats = FMatrix(self, *args, **kwargs) return self.fmats def _emap(self, mapper, input_args, worker_pool=None): '\n Apply the given mapper to each element of the given input iterable\n and return the results (with no duplicates) in a list.\n\n INPUT:\n\n - ``mapper`` -- a string specifying the name of a function defined\n in the ``fast_parallel_fusion_ring_braid_repn`` module\n - ``input_args`` -- a tuple of arguments to be passed to mapper\n\n This method applies the mapper in parallel if a ``worker_pool``\n is provided.\n\n .. NOTE::\n\n If ``worker_pool`` is not provided, function maps and reduces on\n a single process. If ``worker_pool`` is provided, the function\n attempts to determine whether it should use multiprocessing\n based on the length of the input iterable. If it cannot determine\n the length of the input iterable then it uses multiprocessing\n with the default chunksize of `1` if chunksize is not\n explicitly provided.\n\n EXAMPLES::\n\n sage: FR = FusionRing("A1", 4)\n sage: FR.fusion_labels([\'idd\', \'one\', \'two\', \'three\', \'four\'], inject_variables=True)\n sage: fmats = FR.get_fmatrix()\n sage: fmats.find_orthogonal_solution(verbose=False) # long time\n sage: len(FR._emap(\'sig_2k\', (1, one, one, 5))) # long time\n 13\n sage: FR = FusionRing("A1", 2)\n sage: FR.fusion_labels("a", inject_variables=True)\n sage: fmats = FR.get_fmatrix()\n sage: fmats.find_orthogonal_solution(verbose=False)\n sage: len(FR._emap(\'odd_one_out\', (a1, a1, 7)))\n 16\n ' n_proc = (worker_pool._processes if (worker_pool is not None) else 1) input_iter = [(child_id, n_proc, input_args) for child_id in range(n_proc)] no_mp = (worker_pool is None) input_iter = zip_longest([], input_iter, fillvalue=(mapper, id(self))) results = [] if no_mp: mapped = map(executor, input_iter) else: mapped = worker_pool.imap_unordered(executor, input_iter, chunksize=1) for worker_results in mapped: results.extend(worker_results) return results def get_braid_generators(self, fusing_anyon, total_charge_anyon, n_strands, checkpoint=False, save_results='', warm_start='', use_mp=True, verbose=True): '\n Compute generators of the Artin braid group on ``n_strands`` strands.\n\n If `a = ` ``fusing_anyon`` and `b = ` ``total_charge_anyon``\n the generators are endomorphisms of `\\text{Hom}(b, a^n)`.\n\n INPUT:\n\n - ``fusing_anyon`` -- a basis element of ``self``\n - ``total_charge_anyon`` -- a basis element of ``self``\n - ``n_strands`` -- a positive integer greater than 2\n - ``checkpoint`` -- (default: ``False``) a boolean indicating\n whether the F-matrix solver should pickle checkpoints\n - ``save_results`` -- (optional) a string indicating the name of\n a file in which to pickle computed F-symbols for later use\n - ``warm_start`` -- (optional) a string indicating the name of a\n pickled checkpoint file to "warm" start the F-matrix solver.\n The pickle may be a checkpoint generated by the solver, or\n a file containing solver results. If all F-symbols are known,\n we don\'t run the solver again.\n - ``use_mp`` -- (default: ``True``) a boolean indicating whether\n to use multiprocessing to speed up the computation; this is\n highly recommended.\n - ``verbose`` -- (default: ``True``) boolean indicating whether\n to be verbose with the computation\n\n For more information on the optional parameters, see\n :meth:`FMatrix.find_orthogonal_solution`.\n\n Given a simple object in the fusion category, here called\n ``fusing_anyon`` allowing the universal R-matrix to act on adjacent\n pairs in the fusion of ``n_strands`` copies of ``fusing_anyon``\n produces an action of the braid group. This representation can\n be decomposed over another anyon, here called ``total_charge_anyon``.\n See [CHW2015]_.\n\n OUTPUT:\n\n The method outputs a pair of data ``(comp_basis, sig)`` where\n ``comp_basis`` is a list of basis elements of the braid group\n module, parametrized by a list of fusion ring elements describing\n a fusion tree. For example with 5 strands the fusion tree\n is as follows. See :meth:`get_computational_basis`\n for more information.\n\n .. IMAGE:: ../../../media/fusiontree.png\n :scale: 45\n :align: center\n\n ``sig`` is a list of braid group generators as matrices. In\n some cases these will be represented as sparse matrices.\n\n In the following example we compute a 5-dimensional braid group\n representation on 5 strands associated to the spin representation\n in the modular tensor category `SU(2)_4 \\cong SO(3)_2`.\n\n EXAMPLES::\n\n sage: A14 = FusionRing("A1", 4)\n sage: A14.get_order()\n [(0, 0), (1/2, -1/2), (1, -1), (3/2, -3/2), (2, -2)]\n sage: A14.fusion_labels(["one", "two", "three", "four", "five"], inject_variables=True)\n sage: [A14(x) for x in A14.get_order()]\n [one, two, three, four, five]\n sage: two ** 5\n 5*two + 4*four\n sage: comp_basis, sig = A14.get_braid_generators(two, two, 5, verbose=False) # long time\n sage: A14.gens_satisfy_braid_gp_rels(sig) # long time\n True\n sage: len(comp_basis) == 5 # long time\n True\n ' if (n_strands < 3): raise ValueError('the number of strands must be an integer at least 3') self.get_fmatrix() if (self.fmats._chkpt_status < 7): self.fmats.find_orthogonal_solution(checkpoint=checkpoint, save_results=save_results, warm_start=warm_start, use_mp=use_mp, verbose=verbose) try: set_start_method('fork') except RuntimeError: pass pool = (Pool() if (use_mp and (self.fvars_field() != QQbar)) else None) (a, b) = (fusing_anyon, total_charge_anyon) comp_basis = self.get_computational_basis(a, b, n_strands) d = len(comp_basis) if verbose: print('Computing an {}-dimensional representation of the Artin braid group on {} strands...'.format(d, n_strands)) gens = {((2 * i) + 1): diagonal_matrix((self.r_matrix(a, a, c[i]) for c in comp_basis)) for i in range((n_strands // 2))} for k in range(1, (n_strands // 2)): entries = self._emap('sig_2k', (k, a, b, n_strands), pool) _unflatten_entries(self, entries) gens[(2 * k)] = matrix(dict(entries)) if (n_strands % 2): entries = self._emap('odd_one_out', (a, b, n_strands), pool) _unflatten_entries(self, entries) gens[(n_strands - 1)] = matrix(dict(entries)) return (comp_basis, [gens[k] for k in sorted(gens)]) def gens_satisfy_braid_gp_rels(self, sig): '\n Return ``True`` if the matrices in the list ``sig`` satisfy\n the braid relations.\n\n This if `n` is the cardinality of ``sig``, this\n confirms that these matrices define a representation of\n the Artin braid group on `n+1` strands. Tests correctness of\n :meth:`get_braid_generators`.\n\n EXAMPLES::\n\n sage: F41 = FusionRing("F4", 1, fusion_labels="f", inject_variables=True)\n sage: f1*f1\n f0 + f1\n sage: comp, sig = F41.get_braid_generators(f1, f0, 4, verbose=False)\n sage: F41.gens_satisfy_braid_gp_rels(sig)\n True\n ' n = len(sig) braid_rels = all(((((sig[i] * sig[(i + 1)]) * sig[i]) == ((sig[(i + 1)] * sig[i]) * sig[(i + 1)])) for i in range((n - 1)))) far_comm = all((((sig[i] * sig[j]) == (sig[j] * sig[i])) for (i, j) in product(range(n), repeat=2) if ((abs((i - j)) > 1) and (i > j)))) singular = any((s.is_singular() for s in sig)) return (braid_rels and far_comm and (not singular)) class Element(WeylCharacterRing.Element): '\n A class for FusionRing elements.\n ' def is_simple_object(self): '\n Determine whether ``self`` is a simple object of the fusion ring.\n\n EXAMPLES::\n\n sage: A22 = FusionRing("A2", 2)\n sage: x = A22(1, 0); x\n A22(1,0)\n sage: x.is_simple_object()\n True\n sage: x^2\n A22(0,1) + A22(2,0)\n sage: (x^2).is_simple_object()\n False\n ' return ((self.parent()._k is not None) and (len(self._monomial_coefficients) == 1)) def weight(self): '\n Return the parametrizing dominant weight in the level `k` alcove.\n\n This method is only available for basis elements.\n\n EXAMPLES::\n\n sage: A21 = FusionRing("A2", 1)\n sage: [x.weight() for x in A21.basis().list()]\n [(0, 0, 0), (2/3, -1/3, -1/3), (1/3, 1/3, -2/3)]\n ' if (len(self._monomial_coefficients) != 1): raise ValueError('fusion weight is valid for basis elements only') return next(iter(self._monomial_coefficients)) def twist(self, reduced=True): '\n Return a rational number `h` such that `\\theta = e^{i \\pi h}`\n is the twist of ``self``. The quantity `e^{i \\pi h}` is\n also available using :meth:`ribbon`.\n\n This method is only available for simple objects. If\n `\\lambda` is the weight of the object, then\n `h = \\langle \\lambda, \\lambda+2\\rho \\rangle`, where\n `\\rho` is half the sum of the positive roots.\n As in [Row2006]_, this requires normalizing\n the invariant bilinear form so that\n `\\langle \\alpha, \\alpha \\rangle = 2` for short roots.\n\n INPUT:\n\n - ``reduced`` -- (default: ``True``) boolean; if ``True``\n then return the twist reduced modulo 2\n\n EXAMPLES::\n\n sage: G21 = FusionRing("G2", 1)\n sage: [x.twist() for x in G21.basis()]\n [0, 4/5]\n sage: [G21.root_of_unity(x.twist()) for x in G21.basis()]\n [1, zeta60^14 - zeta60^4]\n sage: zeta60 = G21.field().gen()\n sage: zeta60^((4/5)*(60/2))\n zeta60^14 - zeta60^4\n\n sage: F42 = FusionRing("F4", 2)\n sage: [x.twist() for x in F42.basis()]\n [0, 18/11, 2/11, 12/11, 4/11]\n\n sage: E62 = FusionRing("E6", 2)\n sage: [x.twist() for x in E62.basis()]\n [0, 26/21, 12/7, 8/21, 8/21, 26/21, 2/3, 4/7, 2/3]\n ' if (not self.is_simple_object()): raise ValueError('quantum twist is only available for simple objects of a FusionRing') P = self.parent() rho = P.space().rho() lam = next(iter(self._monomial_coefficients)) inner = lam.inner_product((lam + (2 * rho))) twist = (((P._conj * P._nf) * inner) / P.fusion_l()) if reduced: f = twist.floor() twist -= f return (twist + (f % 2)) return twist def ribbon(self, base_coercion=True): '\n Return the twist or ribbon element of ``self``.\n\n If `h` is the rational number modulo 2 produced by\n ``self.twist()``, this method produces `e^{i\\pi h}`.\n\n .. SEEALSO::\n\n An additive version of this is available as :meth:`twist`.\n\n EXAMPLES::\n\n sage: F = FusionRing("A1", 3)\n sage: [x.twist() for x in F.basis()]\n [0, 3/10, 4/5, 3/2]\n sage: [x.ribbon(base_coercion=False) for x in F.basis()]\n [1, zeta40^6, zeta40^12 - zeta40^8 + zeta40^4 - 1, -zeta40^10]\n sage: [F.root_of_unity(x, base_coercion=False) for x in [0, 3/10, 4/5, 3/2]]\n [1, zeta40^6, zeta40^12 - zeta40^8 + zeta40^4 - 1, -zeta40^10]\n ' ret = self.parent().root_of_unity(self.twist(), base_coercion=False) if ((not base_coercion) or (self.parent()._basecoer is None)): return ret return self.parent()._basecoer(ret) @cached_method def q_dimension(self, base_coercion=True): '\n Return the quantum dimension as an element of the cyclotomic\n field of the `2\\ell`-th roots of unity, where `l = m (k+h^\\vee)`\n with `m=1, 2, 3` depending on whether type is simply, doubly or\n triply laced, `k` is the level and `h^\\vee` is the dual\n Coxeter number.\n\n EXAMPLES::\n\n sage: B22 = FusionRing("B2", 2)\n sage: [(b.q_dimension())^2 for b in B22.basis()]\n [1, 4, 5, 1, 5, 4]\n ' if (not self.is_simple_object()): raise ValueError('quantum dimension is only available for simple objects of a FusionRing') P = self.parent() lam = self.weight() space = P.space() rho = space.rho() powers = {} for alpha in space.positive_roots(): val = alpha.inner_product((lam + rho)) if (val in powers): powers[val] += 1 else: powers[val] = 1 val = alpha.inner_product(rho) if (val in powers): powers[val] -= 1 else: powers[val] = (- 1) R = ZZ['q'] q = R.gen() expr = R.fraction_field().one() for val in powers: exp = powers[val] if (exp > 0): expr *= (q_int((P._nf * val), q) ** exp) elif (exp < 0): expr /= (q_int((P._nf * val), q) ** (- exp)) expr = R(expr) expr = (expr.substitute(q=(q ** 4)) / (q ** (2 * expr.degree()))) zet = (P.field().gen() ** (P._cyclotomic_order / P._l)) ret = expr.substitute(q=zet) if ((not base_coercion) or (self.parent()._basecoer is None)): return ret return self.parent()._basecoer(ret)
def GroupAlgebra(G, R=IntegerRing()): "\n Return the group algebra of `G` over `R`.\n\n INPUT:\n\n - `G` -- a group\n - `R` -- (default: `\\ZZ`) a ring\n\n EXAMPLES:\n\n The *group algebra* `A=RG` is the space of formal linear\n combinations of elements of `G` with coefficients in `R`::\n\n sage: G = DihedralGroup(3)\n sage: R = QQ\n sage: A = GroupAlgebra(G, R); A\n Algebra of Dihedral group of order 6 as a permutation group over Rational Field\n sage: a = A.an_element(); a\n () + (1,2) + 3*(1,2,3) + 2*(1,3,2)\n\n This space is endowed with an algebra structure, obtained by extending\n by bilinearity the multiplication of `G` to a multiplication on `RG`::\n\n sage: A in Algebras\n True\n sage: a * a\n 14*() + 5*(2,3) + 2*(1,2) + 10*(1,2,3) + 13*(1,3,2) + 5*(1,3)\n\n :func:`GroupAlgebra` is just a short hand for a more general\n construction that covers, e.g., monoid algebras, additive group\n algebras and so on::\n\n sage: G.algebra(QQ)\n Algebra of Dihedral group of order 6 as a permutation group over Rational Field\n\n sage: GroupAlgebra(G,QQ) is G.algebra(QQ)\n True\n\n sage: M = Monoids().example(); M\n An example of a monoid:\n the free monoid generated by ('a', 'b', 'c', 'd')\n sage: M.algebra(QQ)\n Algebra of An example of a monoid: the free monoid generated by ('a', 'b', 'c', 'd')\n over Rational Field\n\n See the documentation of :mod:`sage.categories.algebra_functor`\n for details.\n\n TESTS::\n\n sage: GroupAlgebra(1)\n Traceback (most recent call last):\n ...\n ValueError: 1 is not a magma or additive magma\n\n sage: GroupAlgebra(GL(3, GF(7)))\n Algebra of General Linear Group of degree 3 over Finite Field of size 7\n over Integer Ring\n sage: GroupAlgebra(GL(3, GF(7)), QQ)\n Algebra of General Linear Group of degree 3 over Finite Field of size 7\n over Rational Field\n " if (not ((G in Magmas()) or (G in AdditiveMagmas()))): raise ValueError(('%s is not a magma or additive magma' % G)) if (R not in Rings()): raise ValueError(('%s is not a ring' % R)) return G.algebra(R)
class GroupAlgebra_class(CombinatorialFreeModule): def _coerce_map_from_(self, S): "\n Return a coercion from `S` or ``None``.\n\n INPUT:\n\n - ``S`` -- a parent\n\n Let us write ``self`` as `R[G]`. This method handles\n the case where `S` is another group/monoid/...-algebra\n `R'[H]`, with R coercing into `R'` and `H` coercing\n into `G`. In that case it returns the naturally\n induced coercion between `R'[H]` and `R[G]`. Otherwise\n it returns ``None``.\n\n EXAMPLES::\n\n sage: A = GroupAlgebra(SymmetricGroup(4), QQ)\n sage: B = GroupAlgebra(SymmetricGroup(3), ZZ)\n sage: A.has_coerce_map_from(B)\n True\n sage: B.has_coerce_map_from(A)\n False\n sage: A.has_coerce_map_from(ZZ)\n True\n sage: A.has_coerce_map_from(CC)\n False\n sage: A.has_coerce_map_from(SymmetricGroup(5))\n False\n sage: A.has_coerce_map_from(SymmetricGroup(2))\n True\n\n\n sage: H = CyclicPermutationGroup(3)\n sage: G = DihedralGroup(3)\n\n sage: QH = H.algebra(QQ)\n sage: ZH = H.algebra(ZZ)\n sage: QG = G.algebra(QQ)\n sage: ZG = G.algebra(ZZ)\n sage: ZG.coerce_map_from(H)\n Composite map:\n From: Cyclic group of order 3 as a permutation group\n To: Algebra of Dihedral group of order 6 as a permutation group over Integer Ring\n Defn: Coercion map:\n From: Cyclic group of order 3 as a permutation group\n To: Dihedral group of order 6 as a permutation group\n then\n Coercion map:\n From: Dihedral group of order 6 as a permutation group\n To: Algebra of Dihedral group of order 6 as a permutation group over Integer Ring\n sage: QG.coerce_map_from(ZG)\n Generic morphism:\n From: Algebra of Dihedral group of order 6 as a permutation group over Integer Ring\n To: Algebra of Dihedral group of order 6 as a permutation group over Rational Field\n sage: QG.coerce_map_from(QH)\n Generic morphism:\n From: Algebra of Cyclic group of order 3 as a permutation group over Rational Field\n To: Algebra of Dihedral group of order 6 as a permutation group over Rational Field\n sage: QG.coerce_map_from(ZH)\n Generic morphism:\n From: Algebra of Cyclic group of order 3 as a permutation group over Integer Ring\n To: Algebra of Dihedral group of order 6 as a permutation group over Rational Field\n\n sage: H = PermutationGroup([ [(1,2), (3,4)], [(5,6,7),(12,14,18)] ])\n sage: kH = H.algebra(GF(2))\n sage: [a, b] = kH.gens()\n sage: x = kH(a) + kH(b) + kH.one(); print(x)\n () + (5,6,7)(12,14,18) + (1,2)(3,4)\n sage: x*x #checks :trac:34292\n (5,7,6)(12,18,14)\n\n As expected, there is no coercion when restricting the\n field::\n\n sage: ZG.coerce_map_from(QG)\n\n There is no coercion for additive groups since ``+`` could mean\n both the action (i.e., the group operation) or adding a term::\n\n sage: G = groups.misc.AdditiveCyclic(3)\n sage: ZG = G.algebra(ZZ, category=AdditiveMagmas())\n sage: ZG.has_coerce_map_from(G)\n False\n " G = self.basis().keys() K = self.base_ring() G_coercion = G.coerce_map_from(S) if (G_coercion is not None): from sage.categories.groups import Groups if (not self.category().is_subcategory(Groups().Algebras(K))): return None if (S is G): return True return (self.coerce_map_from(G) * G_coercion) if (S in Sets.Algebras): S_K = S.base_ring() S_G = S.basis().keys() hom_K = K.coerce_map_from(S_K) hom_G = G.coerce_map_from(S_G) if ((hom_K is not None) and (hom_G is not None)): return SetMorphism(S.Hom(self, category=(self.category() | S.category())), (lambda x: self.sum_of_terms(((hom_G(g), hom_K(c)) for (g, c) in x))))
def transpose_cmp(x, y): '\n Compare partitions ``x`` and ``y`` in transpose dominance order.\n\n We say partitions `\\mu` and `\\lambda` satisfy `\\mu \\prec \\lambda`\n in transpose dominance order if for all `i \\geq 1` we have:\n\n .. MATH::\n\n l_1 + 2 l_2 + \\cdots + (i-1) l_{i-1} + i(l_i + l_{i+1} + \\cdots) \\leq\n m_1 + 2 m_2 + \\cdots + (i-1) m_{i-1} + i(m_i + m_{i+1} + \\cdots),\n\n where `l_k` denotes the number of appearances of `k` in\n `\\lambda`, and `m_k` denotes the number of appearances of `k`\n in `\\mu`.\n\n Equivalently, `\\mu \\prec \\lambda` if the conjugate of the\n partition `\\mu` dominates the conjugate of the partition\n `\\lambda`.\n\n Since this is a partial ordering, we fallback to lex ordering\n `\\mu <_L \\lambda` if we cannot compare in the transpose order.\n\n EXAMPLES::\n\n sage: from sage.algebras.hall_algebra import transpose_cmp\n sage: transpose_cmp(Partition([4,3,1]), Partition([3,2,2,1]))\n -1\n sage: transpose_cmp(Partition([2,2,1]), Partition([3,2]))\n 1\n sage: transpose_cmp(Partition([4,1,1]), Partition([4,1,1]))\n 0\n ' if (x == y): return 0 xexp = x.to_exp() yexp = y.to_exp() n = min(len(xexp), len(yexp)) def check(m, l): s1 = 0 s2 = 0 for i in range(n): s1 += sum(l[i:]) s2 += sum(m[i:]) if (s1 > s2): return False return (sum(l) <= sum(m)) if check(xexp, yexp): return 1 if check(yexp, xexp): return (- 1) if (x < y): return (- 1) return 1
class HallAlgebra(CombinatorialFreeModule): "\n The (classical) Hall algebra.\n\n The *(classical) Hall algebra* over a commutative ring `R` with a\n parameter `q \\in R` is defined to be the free `R`-module with\n basis `(I_\\lambda)`, where `\\lambda` runs over all integer\n partitions. The algebra structure is given by a product defined by\n\n .. MATH::\n\n I_\\mu \\cdot I_\\lambda = \\sum_\\nu P^{\\nu}_{\\mu, \\lambda}(q) I_\\nu,\n\n where `P^{\\nu}_{\\mu, \\lambda}` is a Hall polynomial (see\n :func:`~sage.combinat.hall_polynomial.hall_polynomial`). The\n unity of this algebra is `I_{\\emptyset}`.\n\n The (classical) Hall algebra is also known as the Hall-Steinitz\n algebra.\n\n We can define an `R`-algebra isomorphism `\\Phi` from the\n `R`-algebra of symmetric functions (see\n :class:`~sage.combinat.sf.sf.SymmetricFunctions`) to the\n (classical) Hall algebra by sending the `r`-th elementary\n symmetric function `e_r` to `q^{r(r-1)/2} I_{(1^r)}` for every\n positive integer `r`. This isomorphism used to transport the\n Hopf algebra structure from the `R`-algebra of symmetric functions\n to the Hall algebra, thus making the latter a connected graded\n Hopf algebra. If `\\lambda` is a partition, then the preimage\n of the basis element `I_{\\lambda}` under this isomorphism is\n `q^{n(\\lambda)} P_{\\lambda}(x; q^{-1})`, where `P_{\\lambda}` denotes\n the `\\lambda`-th Hall-Littlewood `P`-function, and where\n `n(\\lambda) = \\sum_i (i - 1) \\lambda_i`.\n\n See section 2.3 in [Sch2006]_, and sections II.2 and III.3\n in [Mac1995]_ (where our `I_{\\lambda}` is called `u_{\\lambda}`).\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: H = HallAlgebra(R, q)\n sage: H[2,1]*H[1,1]\n H[3, 2] + (q+1)*H[3, 1, 1] + (q^2+q)*H[2, 2, 1] + (q^4+q^3+q^2)*H[2, 1, 1, 1]\n sage: H[2]*H[2,1]\n H[4, 1] + q*H[3, 2] + (q^2-1)*H[3, 1, 1] + (q^3+q^2)*H[2, 2, 1]\n sage: H[3]*H[1,1]\n H[4, 1] + q^2*H[3, 1, 1]\n sage: H[3]*H[2,1]\n H[5, 1] + q*H[4, 2] + (q^2-1)*H[4, 1, 1] + q^3*H[3, 2, 1]\n\n We can rewrite the Hall algebra in terms of monomials of\n the elements `I_{(1^r)}`::\n\n sage: I = H.monomial_basis()\n sage: H(I[2,1,1])\n H[3, 1] + (q+1)*H[2, 2] + (2*q^2+2*q+1)*H[2, 1, 1]\n + (q^5+2*q^4+3*q^3+3*q^2+2*q+1)*H[1, 1, 1, 1]\n sage: I(H[2,1,1])\n I[3, 1] + (-q^3-q^2-q-1)*I[4]\n\n The isomorphism between the Hall algebra and the symmetric\n functions described above is implemented as a coercion::\n\n sage: R = PolynomialRing(ZZ, 'q').fraction_field()\n sage: q = R.gen()\n sage: H = HallAlgebra(R, q)\n sage: e = SymmetricFunctions(R).e()\n sage: e(H[1,1,1])\n 1/q^3*e[3]\n\n We can also do computations with any special value of ``q``,\n such as `0` or `1` or (most commonly) a prime power. Here\n is an example using a prime::\n\n sage: H = HallAlgebra(ZZ, 2)\n sage: H[2,1]*H[1,1]\n H[3, 2] + 3*H[3, 1, 1] + 6*H[2, 2, 1] + 28*H[2, 1, 1, 1]\n sage: H[3,1]*H[2]\n H[5, 1] + H[4, 2] + 6*H[3, 3] + 3*H[4, 1, 1] + 8*H[3, 2, 1]\n sage: H[2,1,1]*H[3,1]\n H[5, 2, 1] + 2*H[4, 3, 1] + 6*H[4, 2, 2] + 7*H[5, 1, 1, 1]\n + 19*H[4, 2, 1, 1] + 24*H[3, 3, 1, 1] + 48*H[3, 2, 2, 1]\n + 105*H[4, 1, 1, 1, 1] + 224*H[3, 2, 1, 1, 1]\n sage: I = H.monomial_basis()\n sage: H(I[2,1,1])\n H[3, 1] + 3*H[2, 2] + 13*H[2, 1, 1] + 105*H[1, 1, 1, 1]\n sage: I(H[2,1,1])\n I[3, 1] - 15*I[4]\n\n If `q` is set to `1`, the coercion to the symmetric functions\n sends `I_{\\lambda}` to `m_{\\lambda}`::\n\n sage: H = HallAlgebra(QQ, 1)\n sage: H[2,1] * H[2,1]\n H[4, 2] + 2*H[3, 3] + 2*H[4, 1, 1] + 2*H[3, 2, 1] + 6*H[2, 2, 2] + 4*H[2, 2, 1, 1]\n sage: m = SymmetricFunctions(QQ).m()\n sage: m[2,1] * m[2,1]\n 4*m[2, 2, 1, 1] + 6*m[2, 2, 2] + 2*m[3, 2, 1] + 2*m[3, 3] + 2*m[4, 1, 1] + m[4, 2]\n sage: m(H[3,1])\n m[3, 1]\n\n We can set `q` to `0` (but should keep in mind that we don't get\n the Schur functions this way)::\n\n sage: H = HallAlgebra(QQ, 0)\n sage: H[2,1] * H[2,1]\n H[4, 2] + H[3, 3] + H[4, 1, 1] - H[3, 2, 1] - H[3, 1, 1, 1]\n\n TESTS:\n\n The coefficients are actually Laurent polynomials in general, so we don't\n have to work over the fraction field of `\\ZZ[q]`. This didn't work before\n :trac:`15345`::\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: H = HallAlgebra(R, q)\n sage: I = H.monomial_basis()\n sage: hi = H(I[2,1]); hi\n H[2, 1] + (1+q+q^2)*H[1, 1, 1]\n sage: hi.parent() is H\n True\n sage: h22 = H[2]*H[2]; h22\n H[4] - (1-q)*H[3, 1] + (q+q^2)*H[2, 2]\n sage: h22.parent() is H\n True\n sage: e = SymmetricFunctions(R).e()\n sage: e(H[1,1,1])\n (q^-3)*e[3]\n " def __init__(self, base_ring, q, prefix='H'): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: H = HallAlgebra(R, q)\n sage: TestSuite(H).run()\n sage: R = PolynomialRing(ZZ, 'q').fraction_field()\n sage: q = R.gen()\n sage: H = HallAlgebra(R, q)\n sage: TestSuite(H).run() # long time\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: H = HallAlgebra(R, q)\n sage: TestSuite(H).run() # long time\n " self._q = q try: q_inverse = (q ** (- 1)) if (q_inverse not in base_ring): hopf_structure = False else: hopf_structure = True except Exception: hopf_structure = False if hopf_structure: category = HopfAlgebrasWithBasis(base_ring) else: category = AlgebrasWithBasis(base_ring) CombinatorialFreeModule.__init__(self, base_ring, Partitions(), prefix=prefix, bracket=False, sorting_key=cmp_to_key(transpose_cmp), category=category) I = self.monomial_basis() M = I.module_morphism(I._to_natural_on_basis, codomain=self, triangular='upper', unitriangular=True, inverse_on_support=(lambda x: x.conjugate()), invertible=True) M.register_as_coercion() (~ M).register_as_coercion() def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: HallAlgebra(R, q)\n Hall algebra with q=q over Univariate Polynomial Ring in q over Integer Ring\n ' return 'Hall algebra with q={} over {}'.format(self._q, self.base_ring()) def one_basis(self): '\n Return the index of the basis element `1`.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: H = HallAlgebra(R, q)\n sage: H.one_basis()\n []\n ' return Partition([]) def product_on_basis(self, mu, la): '\n Return the product of the two basis elements indexed by ``mu``\n and ``la``.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: H = HallAlgebra(R, q)\n sage: H.product_on_basis(Partition([1,1]), Partition([1]))\n H[2, 1] + (q^2+q+1)*H[1, 1, 1]\n sage: H.product_on_basis(Partition([2,1]), Partition([1,1]))\n H[3, 2] + (q+1)*H[3, 1, 1] + (q^2+q)*H[2, 2, 1] + (q^4+q^3+q^2)*H[2, 1, 1, 1]\n sage: H.product_on_basis(Partition([3,2]), Partition([2,1]))\n H[5, 3] + (q+1)*H[4, 4] + q*H[5, 2, 1] + (2*q^2-1)*H[4, 3, 1]\n + (q^3+q^2)*H[4, 2, 2] + (q^4+q^3)*H[3, 3, 2]\n + (q^4-q^2)*H[4, 2, 1, 1] + (q^5+q^4-q^3-q^2)*H[3, 3, 1, 1]\n + (q^6+q^5)*H[3, 2, 2, 1]\n sage: H.product_on_basis(Partition([3,1,1]), Partition([2,1]))\n H[5, 2, 1] + q*H[4, 3, 1] + (q^2-1)*H[4, 2, 2]\n + (q^3+q^2)*H[3, 3, 2] + (q^2+q+1)*H[5, 1, 1, 1]\n + (2*q^3+q^2-q-1)*H[4, 2, 1, 1] + (q^4+2*q^3+q^2)*H[3, 3, 1, 1]\n + (q^5+q^4)*H[3, 2, 2, 1] + (q^6+q^5+q^4-q^2-q-1)*H[4, 1, 1, 1, 1]\n + (q^7+q^6+q^5)*H[3, 2, 1, 1, 1]\n ' if (len(mu) == 0): return self.monomial(la) if (len(la) == 0): return self.monomial(mu) if all(((x == 1) for x in la)): return self.sum_of_terms([(p, hall_polynomial(p, mu, la, self._q)) for p in Partitions((sum(mu) + len(la)))], distinct=True) I = HallAlgebraMonomials(self.base_ring(), self._q) mu = self.monomial(mu) la = self.monomial(la) return self((I(mu) * I(la))) def coproduct_on_basis(self, la): "\n Return the coproduct of the basis element indexed by ``la``.\n\n EXAMPLES::\n\n sage: R = PolynomialRing(ZZ, 'q').fraction_field()\n sage: q = R.gen()\n sage: H = HallAlgebra(R, q)\n sage: H.coproduct_on_basis(Partition([1,1]))\n H[] # H[1, 1] + 1/q*H[1] # H[1] + H[1, 1] # H[]\n sage: H.coproduct_on_basis(Partition([2]))\n H[] # H[2] + ((q-1)/q)*H[1] # H[1] + H[2] # H[]\n sage: H.coproduct_on_basis(Partition([2,1]))\n H[] # H[2, 1] + ((q^2-1)/q^2)*H[1] # H[1, 1] + 1/q*H[1] # H[2]\n + ((q^2-1)/q^2)*H[1, 1] # H[1] + 1/q*H[2] # H[1] + H[2, 1] # H[]\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: H = HallAlgebra(R, q)\n sage: H.coproduct_on_basis(Partition([2]))\n H[] # H[2] - (q^-1-1)*H[1] # H[1] + H[2] # H[]\n sage: H.coproduct_on_basis(Partition([2,1]))\n H[] # H[2, 1] - (q^-2-1)*H[1] # H[1, 1] + (q^-1)*H[1] # H[2]\n - (q^-2-1)*H[1, 1] # H[1] + (q^-1)*H[2] # H[1] + H[2, 1] # H[]\n " S = self.tensor_square() if all(((x == 1) for x in la)): n = len(la) return S.sum_of_terms([((Partition(([1] * r)), Partition(([1] * (n - r)))), (self._q ** ((- r) * (n - r)))) for r in range((n + 1))], distinct=True) I = HallAlgebraMonomials(self.base_ring(), self._q) la = self.monomial(la) return S(I(la).coproduct()) def antipode_on_basis(self, la): "\n Return the antipode of the basis element indexed by ``la``.\n\n EXAMPLES::\n\n sage: R = PolynomialRing(ZZ, 'q').fraction_field()\n sage: q = R.gen()\n sage: H = HallAlgebra(R, q)\n sage: H.antipode_on_basis(Partition([1,1]))\n 1/q*H[2] + 1/q*H[1, 1]\n sage: H.antipode_on_basis(Partition([2]))\n -1/q*H[2] + ((q^2-1)/q)*H[1, 1]\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: H = HallAlgebra(R, q)\n sage: H.antipode_on_basis(Partition([1,1]))\n (q^-1)*H[2] + (q^-1)*H[1, 1]\n sage: H.antipode_on_basis(Partition([2]))\n -(q^-1)*H[2] - (q^-1-q)*H[1, 1]\n " if all(((x == 1) for x in la)): r = len(la) q = (((- 1) ** r) * (self._q ** ((- (r * (r - 1))) // 2))) return self._from_dict({p: q for p in Partitions(r)}) I = HallAlgebraMonomials(self.base_ring(), self._q) return self(I(self.monomial(la)).antipode()) def counit(self, x): "\n Return the counit of the element ``x``.\n\n EXAMPLES::\n\n sage: R = PolynomialRing(ZZ, 'q').fraction_field()\n sage: q = R.gen()\n sage: H = HallAlgebra(R, q)\n sage: H.counit(H.an_element())\n 2\n " return x.coefficient(self.one_basis()) def monomial_basis(self): '\n Return the basis of the Hall algebra given by monomials in the\n `I_{(1^r)}`.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: H = HallAlgebra(R, q)\n sage: H.monomial_basis()\n Hall algebra with q=q over Univariate Polynomial Ring in q over\n Integer Ring in the monomial basis\n ' return HallAlgebraMonomials(self.base_ring(), self._q) def __getitem__(self, la): '\n Return the basis element indexed by ``la``.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: H = HallAlgebra(R, q)\n sage: H[[]]\n H[]\n sage: H[2]\n H[2]\n sage: H[[2]]\n H[2]\n sage: H[2,1]\n H[2, 1]\n sage: H[Partition([2,1])]\n H[2, 1]\n sage: H[(2,1)]\n H[2, 1]\n ' if (la in ZZ): return self.monomial(Partition([la])) return self.monomial(Partition(la)) class Element(CombinatorialFreeModule.Element): def scalar(self, y): '\n Return the scalar product of ``self`` and ``y``.\n\n The scalar product is given by\n\n .. MATH::\n\n (I_{\\lambda}, I_{\\mu}) = \\delta_{\\lambda,\\mu}\n \\frac{1}{a_{\\lambda}},\n\n where `a_{\\lambda}` is given by\n\n .. MATH::\n\n a_{\\lambda} = q^{|\\lambda| + 2 n(\\lambda)} \\prod_k\n \\prod_{i=1}^{l_k} (1 - q^{-i})\n\n where `n(\\lambda) = \\sum_i (i - 1) \\lambda_i` and\n `\\lambda = (1^{l_1}, 2^{l_2}, \\ldots, m^{l_m})`.\n\n Note that `a_{\\lambda}` can be interpreted as the number\n of automorphisms of a certain object in a category\n corresponding to `\\lambda`. See Lemma 2.8 in [Sch2006]_\n for details.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: H = HallAlgebra(R, q)\n sage: H[1].scalar(H[1])\n 1/(q - 1)\n sage: H[2].scalar(H[2])\n 1/(q^2 - q)\n sage: H[2,1].scalar(H[2,1])\n 1/(q^5 - 2*q^4 + q^3)\n sage: H[1,1,1,1].scalar(H[1,1,1,1])\n 1/(q^16 - q^15 - q^14 + 2*q^11 - q^8 - q^7 + q^6)\n sage: H.an_element().scalar(H.an_element())\n (4*q^2 + 9)/(q^2 - q)\n ' q = self.parent()._q f = (lambda la: (~ ((q ** (sum(la) + (2 * la.weighted_size()))) * prod((prod(((1 - (q ** (- i))) for i in range(1, (k + 1)))) for k in la.to_exp()))))) y = self.parent()(y) ret = q.parent().zero() for (mx, cx) in self: cy = y.coefficient(mx) if (cy != 0): ret += ((cx * cy) * f(mx)) return ret
class HallAlgebraMonomials(CombinatorialFreeModule): "\n The classical Hall algebra given in terms of monomials in the\n `I_{(1^r)}`.\n\n We first associate a monomial `I_{(1^{r_1})} I_{(1^{r_2})} \\cdots\n I_{(1^{r_k})}` with the composition `(r_1, r_2, \\ldots, r_k)`. However\n since `I_{(1^r)}` commutes with `I_{(1^s)}`, the basis is indexed\n by partitions.\n\n EXAMPLES:\n\n We use the fraction field of `\\ZZ[q]` for our initial example::\n\n sage: R = PolynomialRing(ZZ, 'q').fraction_field()\n sage: q = R.gen()\n sage: H = HallAlgebra(R, q)\n sage: I = H.monomial_basis()\n\n We check that the basis conversions are mutually inverse::\n\n sage: all(H(I(H[p])) == H[p] for i in range(7) for p in Partitions(i))\n True\n sage: all(I(H(I[p])) == I[p] for i in range(7) for p in Partitions(i))\n True\n\n Since Laurent polynomials are sufficient, we run the same check with\n the Laurent polynomial ring `\\ZZ[q, q^{-1}]`::\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: H = HallAlgebra(R, q)\n sage: I = H.monomial_basis()\n sage: all(H(I(H[p])) == H[p] for i in range(6) for p in Partitions(i)) # long time\n True\n sage: all(I(H(I[p])) == I[p] for i in range(6) for p in Partitions(i)) # long time\n True\n\n We can also convert to the symmetric functions. The natural basis\n corresponds to the Hall-Littlewood basis (up to a renormalization and\n an inversion of the `q` parameter), and this basis corresponds\n to the elementary basis (up to a renormalization)::\n\n sage: Sym = SymmetricFunctions(R)\n sage: e = Sym.e()\n sage: e(I[2,1])\n (q^-1)*e[2, 1]\n sage: e(I[4,2,2,1])\n (q^-8)*e[4, 2, 2, 1]\n sage: HLP = Sym.hall_littlewood(q).P()\n sage: H(I[2,1])\n H[2, 1] + (1+q+q^2)*H[1, 1, 1]\n sage: HLP(e[2,1])\n (1+q+q^2)*HLP[1, 1, 1] + HLP[2, 1]\n sage: all( e(H[lam]) == q**-sum([i * x for i, x in enumerate(lam)])\n ....: * e(HLP[lam]).map_coefficients(lambda p: p(q**(-1)))\n ....: for lam in Partitions(4) )\n True\n\n We can also do computations using a prime power::\n\n sage: H = HallAlgebra(ZZ, 3)\n sage: I = H.monomial_basis()\n sage: i_elt = I[2,1]*I[1,1]; i_elt\n I[2, 1, 1, 1]\n sage: H(i_elt)\n H[4, 1] + 7*H[3, 2] + 37*H[3, 1, 1] + 136*H[2, 2, 1]\n + 1495*H[2, 1, 1, 1] + 62920*H[1, 1, 1, 1, 1]\n " def __init__(self, base_ring, q, prefix='I'): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: TestSuite(I).run()\n sage: R = PolynomialRing(ZZ, 'q').fraction_field()\n sage: q = R.gen()\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: TestSuite(I).run()\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: TestSuite(I).run()\n " self._q = q try: q_inverse = (q ** (- 1)) if (q_inverse not in base_ring): hopf_structure = False else: hopf_structure = True except Exception: hopf_structure = False if hopf_structure: category = HopfAlgebrasWithBasis(base_ring) else: category = AlgebrasWithBasis(base_ring) CombinatorialFreeModule.__init__(self, base_ring, Partitions(), prefix=prefix, bracket=False, category=category) if hopf_structure: e = SymmetricFunctions(base_ring).e() f = (lambda la: (q ** sum(((- ((r * (r - 1)) // 2)) for r in la)))) M = self.module_morphism(diagonal=f, codomain=e) M.register_as_coercion() (~ M).register_as_coercion() @cached_method def _to_natural_on_basis(self, a): '\n Return the basis element indexed by ``a`` converted into\n the partition basis.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: I._to_natural_on_basis(Partition([3]))\n H[1, 1, 1]\n sage: I._to_natural_on_basis(Partition([2,1,1]))\n H[3, 1] + (q+1)*H[2, 2] + (2*q^2+2*q+1)*H[2, 1, 1]\n + (q^5+2*q^4+3*q^3+3*q^2+2*q+1)*H[1, 1, 1, 1]\n ' H = HallAlgebra(self.base_ring(), self._q) return reduce((lambda cur, r: (cur * H.monomial(Partition(([1] * r))))), a, H.one()) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: HallAlgebra(R, q).monomial_basis()\n Hall algebra with q=q over Univariate Polynomial Ring in q over\n Integer Ring in the monomial basis\n ' return 'Hall algebra with q={} over {} in the monomial basis'.format(self._q, self.base_ring()) def one_basis(self): '\n Return the index of the basis element `1`.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: I.one_basis()\n []\n ' return Partition([]) def product_on_basis(self, a, b): '\n Return the product of the two basis elements indexed by ``a``\n and ``b``.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: I.product_on_basis(Partition([4,2,1]), Partition([3,2,1]))\n I[4, 3, 2, 2, 1, 1]\n ' return self.monomial(Partition(sorted((list(a) + list(b)), reverse=True))) def coproduct_on_basis(self, a): "\n Return the coproduct of the basis element indexed by ``a``.\n\n EXAMPLES::\n\n sage: R = PolynomialRing(ZZ, 'q').fraction_field()\n sage: q = R.gen()\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: I.coproduct_on_basis(Partition([1]))\n I[] # I[1] + I[1] # I[]\n sage: I.coproduct_on_basis(Partition([2]))\n I[] # I[2] + 1/q*I[1] # I[1] + I[2] # I[]\n sage: I.coproduct_on_basis(Partition([2,1]))\n I[] # I[2, 1] + 1/q*I[1] # I[1, 1] + I[1] # I[2]\n + 1/q*I[1, 1] # I[1] + I[2] # I[1] + I[2, 1] # I[]\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: I.coproduct_on_basis(Partition([2,1]))\n I[] # I[2, 1] + (q^-1)*I[1] # I[1, 1] + I[1] # I[2]\n + (q^-1)*I[1, 1] # I[1] + I[2] # I[1] + I[2, 1] # I[]\n " S = self.tensor_square() return S.prod((S.sum_of_terms([((Partition([r]), Partition([(n - r)])), (self._q ** ((- r) * (n - r)))) for r in range((n + 1))], distinct=True) for n in a)) def antipode_on_basis(self, a): "\n Return the antipode of the basis element indexed by ``a``.\n\n EXAMPLES::\n\n sage: R = PolynomialRing(ZZ, 'q').fraction_field()\n sage: q = R.gen()\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: I.antipode_on_basis(Partition([1]))\n -I[1]\n sage: I.antipode_on_basis(Partition([2]))\n 1/q*I[1, 1] - I[2]\n sage: I.antipode_on_basis(Partition([2,1]))\n -1/q*I[1, 1, 1] + I[2, 1]\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: I.antipode_on_basis(Partition([2,1]))\n -(q^-1)*I[1, 1, 1] + I[2, 1]\n " H = HallAlgebra(self.base_ring(), self._q) cur = self.one() for r in a: q = (((- 1) ** r) * (self._q ** ((- (r * (r - 1))) // 2))) cur *= self(H._from_dict({p: q for p in Partitions(r)})) return cur def counit(self, x): "\n Return the counit of the element ``x``.\n\n EXAMPLES::\n\n sage: R = PolynomialRing(ZZ, 'q').fraction_field()\n sage: q = R.gen()\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: I.counit(I.an_element())\n 2\n " return x.coefficient(self.one_basis()) def __getitem__(self, a): '\n Return the basis element indexed by ``a``.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: I[3,1,1] + 3*I[1,1]\n 3*I[1, 1] + I[3, 1, 1]\n sage: I[Partition([3,2,2])]\n I[3, 2, 2]\n sage: I[2]\n I[2]\n sage: I[[2]]\n I[2]\n sage: I[[]]\n I[]\n ' if (a in ZZ): return self.monomial(Partition([a])) return self.monomial(Partition(a)) class Element(CombinatorialFreeModule.Element): def scalar(self, y): '\n Return the scalar product of ``self`` and ``y``.\n\n The scalar product is computed by converting into the\n natural basis.\n\n EXAMPLES::\n\n sage: R.<q> = ZZ[]\n sage: I = HallAlgebra(R, q).monomial_basis()\n sage: I[1].scalar(I[1])\n 1/(q - 1)\n sage: I[2].scalar(I[2])\n 1/(q^4 - q^3 - q^2 + q)\n sage: I[2,1].scalar(I[2,1])\n (2*q + 1)/(q^6 - 2*q^5 + 2*q^3 - q^2)\n sage: I[1,1,1,1].scalar(I[1,1,1,1])\n 24/(q^4 - 4*q^3 + 6*q^2 - 4*q + 1)\n sage: I.an_element().scalar(I.an_element())\n (4*q^4 - 4*q^2 + 9)/(q^4 - q^3 - q^2 + q)\n ' H = HallAlgebra(self.parent().base_ring(), self.parent()._q) return H(self).scalar(H(y))
class _Basis(CombinatorialFreeModule, BindableClass): '\n Abstract base class for bases of the Ariki-Koike algebra.\n ' def __init__(self, algebra, prefix='AK'): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(2, 3).LT()\n sage: TestSuite(LT).run()\n ' self._r = algebra._r self._n = algebra._n self._q = algebra._q self._u = algebra._u self._zero_tuple = tuple(([0] * self._n)) self._Pn = Permutations(self._n) self._one_perm = self._Pn.one() C = cartesian_product(([range(self._r)] * self._n)) indices = cartesian_product([C, self._Pn]) CombinatorialFreeModule.__init__(self, algebra.base_ring(), indices, prefix=prefix, category=algebra._BasesCategory()) @cached_method def one_basis(self): '\n Return the index of the basis element of `1`.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(5, 3).LT()\n sage: LT.one_basis()\n ((0, 0, 0), [1, 2, 3])\n\n sage: T = algebras.ArikiKoike(5, 3).T()\n sage: T.one_basis()\n ((0, 0, 0), [1, 2, 3])\n ' return (self._zero_tuple, self._one_perm)
class ArikiKoikeAlgebra(Parent, UniqueRepresentation): '\n The Ariki-Koike algebra `H_{r,n}(q, u)`.\n\n Let `R` be an unital integral domain.\n Let `q, u_0, \\ldots, u_{r-1} \\in R` such that `q^{-1} \\in R`.\n The *Ariki-Koike algebra* is the unital associative algebra\n `H_{r,n}(q, u)` generated by `T_0, \\ldots, T_{n-1}` that satisfies\n the following relations:\n\n .. MATH::\n\n \\begin{aligned}\n \\prod_{i=0}^{r-1} (T_0 - u_i) & = 0, \\\\\n T_i^2 & = (q - 1) T_i + q && \\text{for } 1 \\leq i < n, \\\\\n T_0 T_1 T_0 T_1 & = T_1 T_0 T_1 T_0, \\\\\n T_i T_j & = T_j T_i && \\text{if } |i - j| \\geq 2, \\\\\n T_i T_{i+1} T_i & = T_{i+1} T_i T_{i+1} && \\text{for } 1 \\leq i < n.\n \\end{aligned}\n\n The parameter `q` is called the *Hecke parameter* and the parameters\n `u_0, \\ldots, u_{r-1}` are called the *cyclotomic parameters*.\n Thus, the Ariki-Koike algebra is a deformation of the group algebra of the\n complex reflection group `G(r, 1, n) = \\ZZ / r\\ZZ \\wr \\mathfrak{S}_n`.\n\n Next, we define *Jucys-Murphy elements*\n\n .. MATH::\n\n L_i = q^{-i+1} T_{i-1} \\cdots T_1 T_0 T_1 \\cdots T_{i-1}\n\n for `1 \\leq i \\leq n`.\n\n .. NOTE::\n\n These element differ by a power of `q` from the corresponding\n elements in [AK1994]_. However, these elements are more commonly\n used because they lead to nicer representation theoretic formulas.\n\n Ariki and Koike [AK1994]_ showed that `H_{r,n}(q, u)` is a free\n `R`-module with a basis given by\n\n .. MATH::\n\n \\{ L_1^{c_i} \\cdots L_n^{c_n} T_w \\mid w \\in S_n, 0 \\leq c_i < r \\}.\n\n In particular, we have `\\dim H_{r,n}(q,u) = r^n n! = |G(r, 1, n)|`.\n Moreover, we have `L_i L_j = L_i L_j` for all `1 \\leq i, j \\leq n`.\n\n The Ariki-Koike algebra `H_{r,n}(q, u)` can be considered as a quotient\n of the group algebra of the braid group for `G(r, 1, n)` by the ideal\n generated by `\\prod_{i=0}^{r-1} (T_0 - u_i)` and `(T_i - q)(T_i + 1)`.\n Furthermore, `H_{r,n}(q, u)` can be constructed as a quotient of the\n extended affine Hecke algebra of type `A_{n-1}^{(1)}` by\n `\\prod_{i=0}^{r-1} (X_1 - u_i)`.\n\n Since the Ariki-Koike algebra is a quotient of the group\n algebra of the braid group of `G(r, 1, n)`, we can recover\n the group algebra of `G(r, 1, n)` as follows. Consider\n `u = (1, \\zeta_r, \\ldots, \\zeta_r^{r-1})`, where `\\zeta_r`\n is a primitive `r`-th root of unity, then we have\n\n .. MATH::\n\n R G(r, 1, n) = H_{r,n}(1, u).\n\n INPUT:\n\n - ``r`` -- the maximum power of `L_i`\n - ``n`` -- the rank `S_n`\n - ``q`` -- (optional) an invertible element in a commutative ring;\n the default is `q \\in R[q,q^{-1}]`, where `R` is the ring containing\n the variables ``u``\n - ``u`` -- (optional) the variables `u_1, \\ldots, u_r`; the\n default is the generators of `\\ZZ[u_1, \\ldots, u_r]`\n - ``R`` -- (optional) a commutative ring containing ``q`` and ``u``;\n the default is the parent of `q` and `u_1, \\ldots, u_r`\n\n EXAMPLES:\n\n We start by constructing an Ariki-Koike algebra where the\n values `q, u` are generic and do some computations::\n\n sage: H = algebras.ArikiKoike(3, 4)\n\n Next, we do some computations using the `LT` basis::\n\n sage: LT = H.LT()\n sage: LT.inject_variables()\n Defining L1, L2, L3, L4, T1, T2, T3\n sage: T1 * T2 * T1 * T2\n q*T[2,1] - (1-q)*T[2,1,2]\n sage: T1 * L1 * T2 * L3 * T1 * T2\n -(q-q^2)*L2*L3*T[2] + q*L1*L2*T[2,1] - (1-q)*L1*L2*T[2,1,2]\n sage: L1^3\n u0*u1*u2 + ((-u0*u1-u0*u2-u1*u2))*L1 + ((u0+u1+u2))*L1^2\n sage: L3 * L2 * L1\n L1*L2*L3\n sage: u = LT.u()\n sage: q = LT.q()\n sage: (q + 2*u[0]) * (T1 * T2) * L3\n (-2*u0+(2*u0-1)*q+q^2)*L3*T[1] + (-2*u0+(2*u0-1)*q+q^2)*L2*T[2]\n + (2*u0+q)*L1*T[1,2]\n\n We check the defining relations::\n\n sage: prod(L1 - val for val in u) == H.zero()\n True\n sage: L1 * T1 * L1 * T1 == T1 * L1 * T1 * L1\n True\n sage: T1 * T2 * T1 == T2 * T1 * T2\n True\n sage: T2 * T3 * T2 == T3 * T2 * T3\n True\n sage: L2 == q^-1 * T1 * L1 * T1\n True\n sage: L3 == q^-2 * T2 * T1 * L1 * T1 * T2\n True\n\n We construct an Ariki-Koike algebra with `u = (1, \\zeta_3, \\zeta_3^2)`,\n where `\\zeta_3` is a primitive third root of unity::\n\n sage: # needs sage.rings.number_field\n sage: F = CyclotomicField(3)\n sage: zeta3 = F.gen()\n sage: R.<q> = LaurentPolynomialRing(F)\n sage: H = algebras.ArikiKoike(3, 4, q=q, u=[1, zeta3, zeta3^2], R=R)\n sage: H.LT().inject_variables()\n Defining L1, L2, L3, L4, T1, T2, T3\n sage: L1^3\n 1\n sage: L2^3\n 1 - (q^-1-1)*T[1] - (q^-1-1)*L1*L2^2*T[1] - (q^-1-1)*L1^2*L2*T[1]\n\n Next, we additionally take `q = 1` to obtain the group algebra\n of `G(r, 1, n)`::\n\n sage: # needs sage.rings.number_field\n sage: F = CyclotomicField(3)\n sage: zeta3 = F.gen()\n sage: H = algebras.ArikiKoike(3, 4, q=1, u=[1, zeta3, zeta3^2], R=F)\n sage: LT = H.LT()\n sage: LT.inject_variables()\n Defining L1, L2, L3, L4, T1, T2, T3\n sage: A = ColoredPermutations(3, 4).algebra(F)\n sage: s1, s2, s3, s0 = list(A.algebra_generators())\n sage: all(L^3 == LT.one() for L in LT.L())\n True\n sage: J = [s0, s3*s0*s3, s2*s3*s0*s3*s2, s1*s2*s3*s0*s3*s2*s1]\n sage: all(Ji^3 == A.one() for Ji in J)\n True\n ' @staticmethod def __classcall_private__(cls, r, n, q=None, u=None, R=None): "\n Standardize input to ensure a unique representation.\n\n TESTS::\n\n sage: H1 = algebras.ArikiKoike(4, 3)\n sage: S = PolynomialRing(ZZ, 'u', 4)\n sage: R.<q> = LaurentPolynomialRing(S)\n sage: H2 = algebras.ArikiKoike(4, 3, q=q)\n sage: H3 = algebras.ArikiKoike(4, 3, q, S.gens(), R)\n sage: H1 is H2\n True\n sage: H2 is H3\n True\n " if (u is None): if (q is not None): R = q.parent() if (R is None): R = PolynomialRing(ZZ, 'u', r) u = R.gens() if (q is None): R = LaurentPolynomialRing(R, 'q') q = R.gen() else: u = PolynomialRing(ZZ, 'u', r).gens() if (q is None): q = 'q' else: if (not isinstance(u, (list, tuple))): u = ([u] * r) if (R is None): from sage.structure.element import get_coercion_model cm = get_coercion_model() if (q is None): R = cm.common_parent(*[val.parent() for val in u]) R = LaurentPolynomialRing(R, 'q') q = R.gen() else: R = cm.common_parent(q.parent(), *[val.parent() for val in u]) elif (q is None): q = 'q' u = [R(val) for val in u] if (R not in Rings().Commutative()): raise TypeError('base ring must be a commutative ring') q = R(q) u = tuple(u) return super().__classcall__(cls, r, n, q, u, R) def __init__(self, r, n, q, u, R): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(5, 3)\n sage: TestSuite(H).run()\n sage: H = algebras.ArikiKoike(1, 4)\n sage: TestSuite(H).run()\n sage: H = algebras.ArikiKoike(2, 3)\n sage: TestSuite(H).run()\n sage: H = algebras.ArikiKoike(3, 4)\n sage: TestSuite(H).run() # long time\n ' self._r = r self._n = n self._q = q self._u = u self._category = Algebras(R).FiniteDimensional().WithBasis() Parent.__init__(self, base=R, category=self._category.WithRealizations()) T = self.T() LT = self.LT() T.module_morphism(LT._from_T_basis, codomain=LT).register_as_coercion() LT.module_morphism(T._from_LT_basis, codomain=T).register_as_coercion() def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: algebras.ArikiKoike(5, 2)\n Ariki-Koike algebra of rank 5 and order 2\n with q=q and u=(u0, u1, u2, u3, u4)\n over Univariate Laurent Polynomial Ring in q\n over Multivariate Polynomial Ring in u0, u1, u2, u3, u4\n over Integer Ring\n ' return 'Ariki-Koike algebra of rank {} and order {} with q={} and u={} over {}'.format(self._r, self._n, self._q, self._u, self.base_ring()) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(5, 2)\n sage: latex(H)\n \\mathcal{H}_{5,2}(q)\n ' return ('\\mathcal{H}_{%s,%s}(%s)' % (self._r, self._n, self._q)) def hecke_parameter(self): '\n Return the Hecke parameter `q` of ``self``.\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(5, 3)\n sage: H.hecke_parameter()\n q\n ' return self._q q = hecke_parameter def cyclotomic_parameters(self): '\n Return the cyclotomic parameters `u` of ``self``.\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(5, 3)\n sage: H.cyclotomic_parameters()\n (u0, u1, u2, u3, u4)\n ' return self._u u = cyclotomic_parameters def a_realization(self): '\n Return a realization of ``self``.\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(5, 2)\n sage: H.a_realization()\n Ariki-Koike algebra of rank 5 and order 2\n with q=q and u=(u0, u1, u2, u3, u4) ... in the LT-basis\n ' return self.LT() class _BasesCategory(Category_realization_of_parent): '\n The category of bases of a Ariki-Koike algebra.\n ' def __init__(self, base): '\n Initialize ``self``.\n\n INPUT:\n\n - ``base`` -- a Ariki-Koike algebra\n\n TESTS::\n\n sage: H = algebras.ArikiKoike(5, 2)\n sage: bases = H._BasesCategory()\n sage: H.T() in bases\n True\n ' Category_realization_of_parent.__init__(self, base) def super_categories(self): '\n The super categories of ``self``.\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(5, 2)\n sage: bases = H._BasesCategory()\n sage: bases.super_categories()\n [Category of realizations of Ariki-Koike algebra of rank 5 and order 2\n with q=q and u=(u0, u1, u2, u3, u4) over ...,\n Category of finite dimensional algebras with basis over ...]\n\n ' return [Realizations(self.base()), self.base()._category] def _repr_(self): '\n Return the representation of ``self``.\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(5, 2)\n sage: H._BasesCategory()\n Category of bases of Ariki-Koike algebra of rank 5 and order 2\n with q=q and u=(u0, u1, u2, u3, u4) over ...\n ' return ('Category of bases of %s' % self.base()) class ParentMethods(): '\n This class collects code common to all the various bases. In most\n cases, these are just default implementations that will get\n specialized in a basis.\n ' def _repr_(self): '\n Text representation of this basis of Iwahori-Hecke algebra.\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(5, 2)\n sage: H.T()\n Ariki-Koike algebra of rank 5 and order 2\n with q=q and u=(u0, u1, u2, u3, u4) ... in the T-basis\n sage: H.LT()\n Ariki-Koike algebra of rank 5 and order 2\n with q=q and u=(u0, u1, u2, u3, u4) ... in the LT-basis\n ' return ('%s in the %s-basis' % (self.realization_of(), self._realization_name())) def hecke_parameter(self): '\n Return the Hecke parameter `q` of ``self``.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(5, 3).LT()\n sage: LT.hecke_parameter()\n q\n ' return self._q q = hecke_parameter def cyclotomic_parameters(self): '\n Return the cyclotomic parameters `u` of ``self``.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(5, 3).LT()\n sage: LT.cyclotomic_parameters()\n (u0, u1, u2, u3, u4)\n ' return self._u u = cyclotomic_parameters @cached_method def gens(self): '\n Return the generators of ``self``.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(5, 3).LT()\n sage: LT.gens()\n (L1, L2, L3, T[1], T[2])\n ' return tuple(self.algebra_generators()) def dimension(self): '\n Return the dimension of ``self``.\n\n The dimension of `H_{r,n}(q, u)` is `r^n n!`.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(8, 3).LT()\n sage: LT.dimension()\n 3072\n sage: LT = algebras.ArikiKoike(6, 3).LT()\n sage: LT.dimension()\n 1296\n sage: LT = algebras.ArikiKoike(3, 5).LT()\n sage: LT.dimension()\n 29160\n ' from sage.arith.misc import factorial return ((self._r ** self._n) * factorial(self._n)) def some_elements(self): '\n Return a list of elements of ``self``.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(4, 3).LT()\n sage: LT.some_elements()\n [1 + 2*T[2] + 3*T[1] + T[2,1],\n L1, L2, L3, T[1], T[2], L1^2, L2^2]\n ' G = self.algebra_generators() elts = ([self.an_element()] + list(G)) elts += [(self.L(1) ** 2)] if (self._n > 1): elts += [(self.L(2) ** (self._r // 2))] return elts class LT(_Basis): '\n The basis of the Ariki-Koike algebra given by monomials of the\n form `L T`, where `L` is product of Jucys-Murphy elements and\n `T` is a product of `\\{ T_i | 0 < i < n \\}`.\n\n This was the basis defined in [AK1994]_ except using the\n renormalized Jucys-Murphy elements.\n ' def __init__(self, algebra): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(5, 3).LT()\n sage: TestSuite(LT).run()\n sage: LT = algebras.ArikiKoike(1, 4).LT()\n sage: TestSuite(LT).run()\n sage: LT = algebras.ArikiKoike(2, 3).LT()\n sage: TestSuite(LT).run()\n sage: LT = algebras.ArikiKoike(3, 4).LT()\n sage: TestSuite(LT).run() # long time\n ' _Basis.__init__(self, algebra, prefix='LT') self._assign_names(self.algebra_generators().keys()) def _repr_term(self, m): "\n Return a string representation of the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(4, 3).LT()\n sage: LT._repr_term( ((1, 0, 2), Permutation([3,2,1])) )\n 'L1*L3^2*T[2,1,2]'\n " gen_str = (lambda e: ('' if (e == 1) else ('^%s' % e))) lhs = '*'.join(((('L%s' % (j + 1)) + gen_str(i)) for (j, i) in enumerate(m[0]) if (i > 0))) redword = m[1].reduced_word() if (not redword): if (not lhs): return '1' return lhs rhs = 'T[{}]'.format(','.join((str(i) for i in redword))) if (not lhs): return rhs return ((lhs + '*') + rhs) def _latex_term(self, m): "\n Return a latex representation for the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(4, 3).LT()\n sage: LT._latex_term( ((1, 0, 2), Permutation([3,2,1])) )\n 'L_{1} L_{3}^{2} T_{2} T_{1} T_{2}'\n " gen_str = (lambda e: ('' if (e == 1) else ('^{%s}' % e))) lhs = ' '.join(((('L_{%s}' % (j + 1)) + gen_str(i)) for (j, i) in enumerate(m[0]) if (i > 0))) redword = m[1].reduced_word() if (not redword): if (not lhs): return '1' return lhs return ((lhs + ' ') + ' '.join((('T_{%d}' % i) for i in redword))) def _from_T_basis(self, t): '\n Return the image of the `T` basis element indexed\n by ``t`` in ``self``.\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(3, 3)\n sage: LT = H.LT()\n sage: T = H.T()\n sage: all(LT(Li) == LT.L(i+1) for i,Li in enumerate(T.L()))\n True\n sage: all(LT(Ti) == LT.T(i) for i,Ti in enumerate(T.T()))\n True\n sage: all(LT(T(b)) == b for b in LT.basis()) # long time\n True\n\n sage: H = algebras.ArikiKoike(1, 3)\n sage: LT = H.LT()\n sage: T = H.T()\n sage: all(LT(Li) == LT.L(i+1) for i,Li in enumerate(T.L()))\n True\n sage: all(LT(T(b)) == b for b in LT.basis()) # indirect doctest\n True\n ' ret = self.one() T = list(self._zero_tuple) one = self.base_ring().one() for (i, k) in enumerate(t[0]): if (k == 0): continue perm = self._Pn.prod((self._Pn.simple_reflection(j) for j in range(1, (i + 1)))) ret = (ret * self._from_dict({(self._zero_tuple, perm): one}, remove_zeros=False, coerce=False)) T[0] = k ret = (ret * self._from_dict({(tuple(T), self._one_perm): one}, remove_zeros=False, coerce=False)) return (ret * self._from_dict({(self._zero_tuple, t[1]): one}, remove_zeros=False, coerce=False)) @cached_method def algebra_generators(self): "\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(5, 3).LT()\n sage: dict(LT.algebra_generators())\n {'L1': L1, 'L2': L2, 'L3': L3, 'T1': T[1], 'T2': T[2]}\n\n sage: LT = algebras.ArikiKoike(1, 4).LT()\n sage: dict(LT.algebra_generators())\n {'T1': T[1], 'T2': T[2], 'T3': T[3]}\n " d = {} if (self._r != 1): for i in range(self._n): r = list(self._zero_tuple) r[i] = 1 d[('L%s' % (i + 1))] = self.monomial((tuple(r), self._one_perm)) G = self._Pn.group_generators() for i in range(1, self._n): d[('T%s' % i)] = self.monomial((self._zero_tuple, G[i])) return Family(sorted(d), (lambda i: d[i])) def T(self, i=None): '\n Return the generator(s) `T_i` of ``self``.\n\n INPUT:\n\n - ``i`` -- (default: ``None``) the generator `T_i` or\n if ``None``, then the list of all generators `T_i`\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(8, 3).LT()\n sage: LT.T(1)\n T[1]\n sage: LT.T()\n [L1, T[1], T[2]]\n sage: LT.T(0)\n L1\n ' G = self.algebra_generators() if (i is None): return ([G['L1']] + [G[('T%s' % j)] for j in range(1, self._n)]) if (i == 0): return G['L1'] return G[('T%s' % i)] def L(self, i=None): '\n Return the generator(s) `L_i`.\n\n INPUT:\n\n - ``i`` -- (default: ``None``) the generator `L_i` or\n if ``None``, then the list of all generators `L_i`\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(8, 3).LT()\n sage: LT.L(2)\n L2\n sage: LT.L()\n [L1, L2, L3]\n\n sage: LT = algebras.ArikiKoike(1, 3).LT()\n sage: LT.L(2)\n u + (-u*q^-1+u)*T[1]\n sage: LT.L()\n [u,\n u + (-u*q^-1+u)*T[1],\n u + (-u*q^-1+u)*T[2] + (-u*q^-2+u*q^-1)*T[2,1,2]]\n ' G = self.algebra_generators() if (i is None): if (self._r == 1): return [self._Li_power(j, 1) for j in range(1, (self._n + 1))] return [G[('L%s' % j)] for j in range(1, (self._n + 1))] if (self._r == 1): return self._Li_power(i, 1) return G[('L%s' % i)] @cached_method def product_on_basis(self, m1, m2): '\n Return the product of the basis elements indexed\n by ``m1`` and ``m2``.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(6, 3).LT()\n sage: m = ((1, 0, 2), Permutations(3)([2,1,3]))\n sage: LT.product_on_basis(m, m)\n q*L1*L2*L3^4\n\n sage: LT = algebras.ArikiKoike(4, 3).LT()\n sage: L1,L2,L3,T1,T2 = LT.algebra_generators()\n sage: L1 * T1 * L1^2 * T1\n q*L1*L2^2 + (1-q)*L1^2*L2*T[1]\n sage: L1^2 * T1 * L1^2 * T1\n q*L1^2*L2^2 + (1-q)*L1^3*L2*T[1]\n sage: L1^3 * T1 * L1^2 * T1\n (-u0*u1*u2*u3+u0*u1*u2*u3*q)*L2*T[1]\n + ((u0*u1*u2+u0*u1*u3+u0*u2*u3+u1*u2*u3)+(-u0*u1*u2-u0*u1*u3-u0*u2*u3-u1*u2*u3)*q)*L1*L2*T[1]\n + ((-u0*u1-u0*u2-u1*u2-u0*u3-u1*u3-u2*u3)+(u0*u1+u0*u2+u1*u2+u0*u3+u1*u3+u2*u3)*q)*L1^2*L2*T[1]\n + ((u0+u1+u2+u3)+(-u0-u1-u2-u3)*q)*L1^3*L2*T[1] + q*L1^3*L2^2\n\n sage: L1^2 * T1 * L1^3 * T1\n (-u0*u1*u2*u3+u0*u1*u2*u3*q)*L2*T[1]\n + ((u0*u1*u2+u0*u1*u3+u0*u2*u3+u1*u2*u3)+(-u0*u1*u2-u0*u1*u3-u0*u2*u3-u1*u2*u3)*q)*L1*L2*T[1]\n + ((-u0*u1-u0*u2-u1*u2-u0*u3-u1*u3-u2*u3)+(u0*u1+u0*u2+u1*u2+u0*u3+u1*u3+u2*u3)*q)*L1^2*L2*T[1]\n + q*L1^2*L2^3\n + ((u0+u1+u2+u3)+(-u0-u1-u2-u3)*q)*L1^3*L2*T[1]\n + (1-q)*L1^3*L2^2*T[1]\n\n sage: L1^2 * T1*T2*T1 * L2 * L3 * T2\n (q-2*q^2+q^3)*L1^2*L2*L3 - (1-2*q+2*q^2-q^3)*L1^2*L2*L3*T[2]\n - (q-q^2)*L1^3*L3*T[1] + (1-2*q+q^2)*L1^3*L3*T[1,2]\n + q*L1^3*L2*T[2,1] - (1-q)*L1^3*L2*T[2,1,2]\n\n sage: LT = algebras.ArikiKoike(2, 3).LT()\n sage: L3 = LT.L(3)\n sage: x = LT.an_element()\n sage: (x * L3) * L3 == x * (L3 * L3)\n True\n ' (L1, T1) = m1 (L2, T2) = m2 if (sum(L2) == 0): return self._from_dict(self._product_LTwTv(L1, T1, T2), remove_zeros=False, coerce=False) if (T1 == self._one_perm): Lbig = list(self._zero_tuple) Lsmall = list(self._zero_tuple) for i in range(self._n): s = (L1[i] + L2[i]) if (s < self._r): Lsmall[i] = s else: Lbig[i] = s if (tuple(Lbig) == self._zero_tuple): return self.monomial((tuple(Lsmall), T2)) return ((self.monomial((tuple(Lsmall), self._one_perm)) * prod((self._Li_power((i + 1), Lbig[i]) for i in reversed(range(self._n)) if (Lbig[i] > 0)))) * self.monomial((self._zero_tuple, T2))) return ((self.monomial((L1, self._one_perm)) * self._product_Tw_L(T1, L2)) * self.monomial((self._zero_tuple, T2))) def _product_LTwTv(self, L, w, v): '\n Return the product `L * T_w * Tv` as a linear combinations of\n terms of the form `L*T_x`.\n\n The main point of this method is that it computes the product\n `L T_w T_v` and returns it as a linear combination of standard\n basis elements. That is, terms of the form `L T_x`. The monomial\n ``L`` does not play a role in this calculation and, instead, it\n is kept as a place holder for this "L-component" of the product.\n\n For this calculation the most important point is that\n\n .. MATH::\n\n T_i T_v = \\begin{cases}\n T_{s_i v}, & \\text{if } \\ell(s_iv) > \\ell(v),\\\\\n q T_{s_i v} + (q-1)T_v, & \\text{if } \\ell(s_iv) < \\ell(v).\n \\end{cases}\n\n This observation is used to rewrite the product `L T_w T_v`\n as a linear combination of standard basis elements.\n\n .. WARNING::\n\n This method is not intended to be called directly and, instead,\n is used by :meth:`product_on_basis`.\n\n INPUT:\n\n - ``L`` -- an `n`-tuple\n - ``w`` -- the permutation ``w``\n - ``v`` -- the permutation ``v``\n\n OUTPUT:\n\n The corresponding element represented as a ``dict``.\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(5, 4).LT()\n sage: P4 = Permutations(4)\n sage: H._from_dict( H._product_LTwTv((0, 3, 2, 4), P4([1,3,2,4]), P4([1,3,2,4])) )\n q*L2^3*L3^2*L4^4 - (1-q)*L2^3*L3^2*L4^4*T[2]\n sage: H._from_dict( H._product_LTwTv((0, 3, 2, 4), P4([1,3,2,4]), P4([1,3,4,2])) )\n q*L2^3*L3^2*L4^4*T[3] - (1-q)*L2^3*L3^2*L4^4*T[2,3]\n sage: H._from_dict( H._product_LTwTv((0, 3, 2, 4), P4([1,4,3,2]), P4([1,4,3,2])) )\n q^3*L2^3*L3^2*L4^4 - (q^2-q^3)*L2^3*L3^2*L4^4*T[3]\n - (q^2-q^3)*L2^3*L3^2*L4^4*T[2]\n + (q-2*q^2+q^3)*L2^3*L3^2*L4^4*T[2,3]\n + (q-2*q^2+q^3)*L2^3*L3^2*L4^4*T[3,2]\n - (1-2*q+2*q^2-q^3)*L2^3*L3^2*L4^4*T[3,2,3]\n ' ret = {v: self.base_ring().one()} qm1 = (self._q - self.base_ring().one()) for i in reversed(w.reduced_word()): temp = {} for p in ret: c = ret[p] pi = p.apply_simple_reflection(i, side='left') if p.has_descent(i, side='left'): iaxpy(1, {p: (c * qm1), pi: (c * self._q)}, temp) else: iaxpy(1, {pi: c}, temp) ret = temp return {(L, p): ret[p] for p in ret} def _product_Tw_L(self, w, L): '\n Given a permutation ``w`` and a monomial ``L`` return the product\n `T_w L` as a linear combination of terms of the form `L_v T_v`.\n\n To do this we write `w = s_{i_1} \\cdots s_{i_k}` and then push each\n `T_{i_a}` past `L` using Lemma 3.2 of [MM1998]_ (cf. Lemma 3.3 and\n Proposition 3.4 of [AK1994]_), which says\n\n .. MATH::\n\n T_i L_i^a L_{i+1}^b = L_i^b L_{i+1}^a T_i + \\begin{cases}\n (1-q) sum_{k=0}^{a-1} L_i^{a+k} L_{i+1}^{b-k}, &\\text{if } a \\leq b,\\\\\n (q-1) sum_{k=0}^{b-1} L_i^{b+k} L_{i+1}^{a-k}, &\\text{if } a \\geq b.\n \\end{cases}\n\n Of course, `T_i` commutes with `L_k`, for `k \\neq i,i+1`.\n\n This method is not intended to be called directly and, instead,\n is used by :meth:`product_on_basis`.\n\n INPUT:\n\n - ``w`` -- a permutation\n - ``L`` -- a tuple `(a_1, \\ldots, a_n)`\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(5, 4).LT()\n sage: P4 = Permutations(4)\n sage: H._product_Tw_L(P4([1,3,2,4]), (0,2,2,0))\n L2^2*L3^2*T[2]\n sage: H._product_Tw_L(P4([1,3,2,4]), (0,1,3,0))\n -(1-q)*L2*L3^3 - (1-q)*L2^2*L3^2 + L2^3*L3*T[2]\n sage: H._product_Tw_L(P4([1,3,2,4]), (0,3,1,0))\n (1-q)*L2*L3^3 + L2*L3^3*T[2] + (1-q)*L2^2*L3^2\n sage: H._product_Tw_L(P4([1,3,2,4]), (2,3,1,3))\n (1-q)*L1^2*L2*L3^3*L4^3 + L1^2*L2*L3^3*L4^3*T[2] + (1-q)*L1^2*L2^2*L3^2*L4^3\n ' wL = {(L, self._one_perm): self.base_ring().one()} q = self._q one = q.parent().one() for i in w.reduced_word()[::(- 1)]: iL = {} for lv in wL: c = wL[lv] L = list(lv[0]) v = lv[1] (a, b) = (L[(i - 1)], L[i]) (L[(i - 1)], L[i]) = (L[i], L[(i - 1)]) iaxpy(c, self._product_LTwTv(tuple(L), self._Pn.simple_reflections()[i], v), iL) if (a < b): Ls = [list(L) for k in range((b - a))] for k in range((b - a)): Ls[k][(i - 1)] = (a + k) Ls[k][i] = (b - k) c *= (q - one) iaxpy(1, {(tuple(l), v): c for l in Ls}, iL) elif (a > b): Ls = [list(L) for k in range((a - b))] for k in range((a - b)): Ls[k][(i - 1)] = (b + k) Ls[k][i] = (a - k) c *= (one - q) iaxpy(1, {(tuple(l), v): c for l in Ls}, iL) wL = iL return self._from_dict(wL, remove_zeros=False, coerce=False) @cached_method def _Li_power(self, i, m): "\n Return `L_i^m`, where `m \\geq 0`.\n\n To compute `L_i^m` we use Corollary 3.4 of [MM1998]_ which says that\n\n .. MATH::\n\n L_i^m = q^{-1} T_{i-1} L_{i-1}^m T_{i-1}\n + (1 - q^{-1}) \\sum_{c=1}^{m-1} L_i^c L_{i-1}^{m-c} T_{i-1}.\n\n .. WARNING::\n\n This function is used internally by the multiplication and\n may return elements that are not in the basis. However\n these will be eventually resolved after the product has\n been computed. ::\n\n sage: H = algebras.ArikiKoike(3, 2).LT()\n sage: L2 = H.L(2)\n sage: H._Li_power(2, 4)\n ((u0^2*u1*u2+u0*u1^2*u2+u0*u1*u2^2)) + ...\n - (q^-1-1)*L1*L2^3*T[1] ...\n - (q^-1-1)*L1^3*L2*T[1]\n sage: H._Li_power(2, 4) == L2^4\n False\n sage: L2 * H._Li_power(2, 4) == L2^5\n True\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(3, 3).LT()\n sage: for i in range(1,4):\n ....: for m in range(4):\n ....: print('L_{}^{} = {}'.format(i,m,H._Li_power(i,m)))\n L_1^0 = 1\n L_1^1 = L1\n L_1^2 = L1^2\n L_1^3 = u0*u1*u2 + ((-u0*u1-u0*u2-u1*u2))*L1 + ((u0+u1+u2))*L1^2\n L_2^0 = 1\n L_2^1 = L2\n L_2^2 = L2^2\n L_2^3 = u0*u1*u2 + (-u0*u1*u2*q^-1+u0*u1*u2)*T[1]\n + ((-u0*u1-u0*u2-u1*u2))*L2 + ((u0+u1+u2))*L2^2\n + ((u0+u1+u2)*q^-1+(-u0-u1-u2))*L1*L2*T[1]\n - (q^-1-1)*L1*L2^2*T[1] - (q^-1-1)*L1^2*L2*T[1]\n L_3^0 = 1\n L_3^1 = L3\n L_3^2 = L3^2\n L_3^3 = u0*u1*u2 + (-u0*u1*u2*q^-1+u0*u1*u2)*T[2]\n + (-u0*u1*u2*q^-2+u0*u1*u2*q^-1)*T[2,1,2]\n + ((-u0*u1-u0*u2-u1*u2))*L3 + ((u0+u1+u2))*L3^2\n + ((u0+u1+u2)*q^-1+(-u0-u1-u2))*L2*L3*T[2]\n - (q^-1-1)*L2*L3^2*T[2] - (q^-1-1)*L2^2*L3*T[2]\n + ((u0+u1+u2)*q^-2+(-2*u0-2*u1-2*u2)*q^-1+(u0+u1+u2))*L1*L3*T[1,2]\n + ((u0+u1+u2)*q^-2+(-u0-u1-u2)*q^-1)*L1*L3*T[2,1,2]\n - (q^-2-2*q^-1+1)*L1*L3^2*T[1,2] - (q^-2-q^-1)*L1*L3^2*T[2,1,2]\n - (q^-2-2*q^-1+1)*L1*L2*L3*T[1,2] - (q^-2-2*q^-1+1)*L1^2*L3*T[1,2]\n - (q^-2-q^-1)*L1^2*L3*T[2,1,2]\n " def Ltuple(a, b): return tuple([(b if (j == i) else (a if (j == (i - 1)) else 0)) for j in range(1, (self._n + 1))]) if (m < self._r): return self.monomial((Ltuple(0, m), self._one_perm)) if (i > 1): si = self._Pn.simple_reflections()[(i - 1)] qsum = (self.base_ring().one() - (self._q ** (- 1))) return (self.sum_of_terms((((Ltuple(c, (m - c)), si), qsum) for c in range(1, m))) + ((((self._q ** (- 1)) * self.T((i - 1))) * self._Li_power((i - 1), m)) * self.T((i - 1)))) if (m > self._r): return (self.monomial((Ltuple(0, 1), self._one_perm)) * self._Li_power(i, (m - 1))) z = PolynomialRing(self.base_ring(), 'DUMMY').gen() p = list(prod(((z - val) for val in self._u))) p.pop() zero = self.base_ring().zero() return self._from_dict({(Ltuple(0, exp), self._one_perm): (- coeff) for (exp, coeff) in enumerate(p) if (coeff != zero)}, remove_zeros=False, coerce=False) @cached_method def inverse_T(self, i): '\n Return the inverse of the generator `T_i`.\n\n From the quadratic relation, we have\n\n .. MATH::\n\n T_i^{-1} = q^{-1} T_i + (q^{-1} - 1).\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(3, 4).LT()\n sage: [LT.inverse_T(i) for i in range(1, 4)]\n [(q^-1-1) + (q^-1)*T[1],\n (q^-1-1) + (q^-1)*T[2],\n (q^-1-1) + (q^-1)*T[3]]\n\n TESTS::\n\n sage: LT = algebras.ArikiKoike(4, 4).LT()\n sage: all(LT.inverse_T(i) * LT.T(i) == LT.one() for i in range(1, 4))\n True\n sage: all(LT.T(i) * LT.inverse_T(i) == LT.one() for i in range(1, 4))\n True\n ' c = ((~ self._q) - self.base_ring().one()) m = self.T(i).leading_support() return self._from_dict({m: (~ self._q), self.one_basis(): c}) class Element(CombinatorialFreeModule.Element): def __invert__(self): '\n Return the inverse if ``self`` is a basis element.\n\n EXAMPLES::\n\n sage: LT = algebras.ArikiKoike(3, 4).LT()\n sage: t = LT.T(1) * LT.T(2) * LT.T(3); t\n T[1,2,3]\n sage: t.inverse() # indirect doctest\n (q^-3-3*q^-2+3*q^-1-1) + (q^-3-2*q^-2+q^-1)*T[3]\n + (q^-3-2*q^-2+q^-1)*T[2] + (q^-3-q^-2)*T[3,2]\n + (q^-3-2*q^-2+q^-1)*T[1] + (q^-3-q^-2)*T[1,3]\n + (q^-3-q^-2)*T[2,1] + (q^-3)*T[3,2,1]\n ' if (len(self) != 1): raise NotImplementedError('inverse only implemented for monomials') (l, w) = self.support_of_term() if (sum(l) != 0): raise NotImplementedError('inverse only implemented for monomials in T variables') H = self.parent() return ((~ self[(l, w)]) * H.prod((H.inverse_T(i) for i in reversed(w.reduced_word())))) class T(_Basis): '\n The basis of the Ariki-Koike algebra given by monomials of the\n generators `\\{ T_i | 0 \\leq i < n \\}`.\n\n We use the choice of reduced expression given by [BM1997]_:\n\n .. MATH::\n\n T_{1,a_1} \\cdots T_{n,a_n} T_w,\n\n where `T_{i,k} = T_{i-1} \\cdots T_2 T_1 T_0^k` (note that\n `T_{1,k} = T_0^k`) and `w` is a reduced expression of an\n element in `\\mathfrak{S}_n`.\n ' def __init__(self, algebra): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: T = algebras.ArikiKoike(5, 3).T()\n sage: TestSuite(T).run()\n sage: T = algebras.ArikiKoike(1, 4).T()\n sage: TestSuite(T).run()\n sage: T = algebras.ArikiKoike(2, 3).T()\n sage: TestSuite(T).run()\n sage: T = algebras.ArikiKoike(3, 4).T()\n sage: TestSuite(T).run() # long time\n ' _Basis.__init__(self, algebra, prefix='T') self._assign_names([('T%s' % i) for i in range(self._n)]) def _repr_term(self, t): "\n Return a string representation of the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: T = algebras.ArikiKoike(4, 3).T()\n sage: T._repr_term( ((1,0,2), Permutation([3,2,1])) )\n 'T[0,2,1,0,0,2,1,2]'\n " redword = [] for (i, k) in enumerate(t[0]): if (k == 0): continue redword += (list(reversed(range(1, (i + 1)))) + ([0] * k)) redword += t[1].reduced_word() if (len(redword) == 0): return '1' return (self._print_options['prefix'] + ('[%s]' % ','.join((('%d' % i) for i in redword)))) def _latex_term(self, t): "\n Return a latex representation for the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: T = algebras.ArikiKoike(4, 3).T()\n sage: T._latex_term( ((1,0,2), Permutation([3,2,1])) )\n 'T_{0}T_{1}T_{0}T_{0}T_{2}T_{1}T_{2}'\n " redword = [] for (i, k) in enumerate(t[0]): if (k == 0): continue redword += (list(reversed(range(1, i))) + ([0] * k)) redword += t[1].reduced_word() if (len(redword) == 0): return '1' return ''.join((('%s_{%d}' % (self._print_options['prefix'], i)) for i in redword)) def _from_LT_basis(self, m): '\n Return the image of the `LT` basis element indexed\n by ``m`` in ``self``.\n\n EXAMPLES::\n\n sage: H = algebras.ArikiKoike(4, 2)\n sage: LT = H.LT()\n sage: T = H.T()\n sage: all(T(Li) == T.L(i+1) for i,Li in enumerate(LT.L()))\n True\n sage: all(T(Ti) == T.T(i) for i,Ti in enumerate(LT.T()))\n True\n\n Check that the products of elements agrees::\n\n sage: type_A_words = [p.reduced_word() for p in Permutations(H._n)]\n sage: def from_reduced_word(B, w):\n ....: t = B.T()\n ....: return B.prod(t[i] for i in w)\n sage: all(T(from_reduced_word(LT, w)) == from_reduced_word(T, w)\n ....: for w in type_A_words)\n True\n\n Check that the composition of the morphisms is the identity::\n\n sage: all(T(LT(b)) == b for b in T.basis()) # indirect doctest\n True\n ' ret = self.prod(((self.L((i + 1)) ** k) for (i, k) in enumerate(m[0]))) return (ret * self.monomial((self._zero_tuple, m[1]))) @cached_method def algebra_generators(self): '\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: T = algebras.ArikiKoike(5, 3).T()\n sage: dict(T.algebra_generators())\n {0: T[0], 1: T[1], 2: T[2]}\n\n sage: T = algebras.ArikiKoike(1, 4).T()\n sage: dict(T.algebra_generators())\n {1: T[1], 2: T[2], 3: T[3]}\n ' start = (1 if (self._r == 1) else 0) return Family(list(range(start, self._n)), self.T) def T(self, i=None): '\n Return the generator(s) `T_i` of ``self``.\n\n INPUT:\n\n - ``i`` -- (default: ``None``) the generator `T_i` or if ``None``,\n then the list of all generators `T_i`\n\n EXAMPLES::\n\n sage: T = algebras.ArikiKoike(8, 3).T()\n sage: T.T(1)\n T[1]\n sage: T.T()\n [T[0], T[1], T[2]]\n\n sage: T = algebras.ArikiKoike(1, 4).T()\n ' if (i is None): return [self.T(j) for j in range(self._n)] if (i == 0): return self.monomial((((1,) + self._zero_tuple[1:]), self._one_perm)) s = self._Pn.simple_reflections() return self.monomial((self._zero_tuple, s[i])) @cached_method def L(self, i=None): '\n Return the Jucys-Murphy element(s) `L_i`.\n\n The Jucys-Murphy element `L_i` is defined as\n\n .. MATH::\n\n L_i = q^{-i+1} T_{i-1} \\cdots T_1 T_0 T_1 \\cdots T_{i-1}\n = q^{-1} T_{i-1} L_{i-1} T_{i-1}.\n\n INPUT:\n\n - ``i`` -- (default: ``None``) the Jucys-Murphy element `L_i`\n or if ``None``, then the list of all `L_i`\n\n EXAMPLES::\n\n sage: T = algebras.ArikiKoike(8, 3).T()\n sage: T.L(2)\n (q^-1)*T[1,0,1]\n sage: T.L()\n [T[0], (q^-1)*T[1,0,1], (q^-2)*T[2,1,0,1,2]]\n\n sage: T0,T1,T2 = T.T()\n sage: q = T.q()\n sage: T.L(1) == T0\n True\n sage: T.L(2) == q^-1 * T1*T0*T1\n True\n sage: T.L(3) == q^-2 * T2*T1*T0*T1*T2\n True\n\n sage: T = algebras.ArikiKoike(1, 3).T()\n sage: T.L(2)\n u + (-u*q^-1+u)*T[1]\n sage: T.L()\n [u,\n u + (-u*q^-1+u)*T[1],\n u + (-u*q^-1+u)*T[2] + (-u*q^-2+u*q^-1)*T[2,1,2]]\n\n TESTS:\n\n Check that the Jucys-Murphy elements form a commutative\n subring::\n\n sage: T = algebras.ArikiKoike(8, 4).T()\n sage: L = T.L()\n sage: all(x*y == y*x for x in L for y in L)\n True\n\n sage: T = algebras.ArikiKoike(2, 3).T()\n sage: L = T.L()\n sage: all(x*y == y*x for x in L for y in L)\n True\n\n sage: T = algebras.ArikiKoike(1, 4).T()\n sage: L = T.L()\n sage: all(x*y == y*x for x in L for y in L)\n True\n ' if (i is None): return [self.L(j) for j in range(1, (self._n + 1))] if (i == 1): if (self._r == 1): return self.from_base_ring(self._u[0]) else: return self.T(0) T = self.T() return ((((self._q ** (- 1)) * T[(i - 1)]) * self.L((i - 1))) * T[(i - 1)]) @cached_method def product_on_basis(self, m1, m2): '\n Return the product of the basis elements indexed\n by ``m1`` and ``m2``.\n\n EXAMPLES::\n\n sage: T = algebras.ArikiKoike(2, 3).T()\n sage: T0, T1, T2 = T.T()\n sage: T.product_on_basis(T0.leading_support(), T1.leading_support())\n T[0,1]\n sage: T1 * T2\n T[1,2]\n sage: T2 * T1\n T[2,1]\n sage: T2 * (T2 * T1 * T0)\n -(1-q)*T[2,1,0] + q*T[1,0]\n sage: (T1 * T0 * T1 * T0) * T0\n (-u0*u1)*T[1,0,1] + ((u0+u1))*T[0,1,0,1]\n sage: (T0 * T1 * T0 * T1) * (T0 * T1)\n (-u0*u1*q)*T[1,0] + (u0*u1-u0*u1*q)*T[1,0,1]\n + ((u0+u1)*q)*T[0,1,0] + ((-u0-u1)+(u0+u1)*q)*T[0,1,0,1]\n sage: T1 * (T0 * T2 * T1 * T0)\n T[1,0,2,1,0]\n sage: (T1 * T2) * (T2 * T1 * T0)\n -(1-q)*T[2,1,0,2] - (q-q^2)*T[1,0] + q^2*T[0]\n sage: (T2*T1*T2) * (T2*T1*T0*T1*T2)\n -(q-q^2)*T[2,1,0,1,2] + (1-2*q+q^2)*T[2,1,0,2,1,2]\n - (q-q^2)*T[1,0,2,1,2] + q^2*T[0,2,1,2]\n\n We check some relations::\n\n sage: T0 * T1 * T0 * T1 == T1 * T0 * T1 * T0\n True\n sage: T1 * T2 * T1 == T2 * T1 * T2\n True\n sage: (T1 * T0) * T0 == T1 * (T0 * T0)\n True\n sage: (T.L(1) * T.L(2)) * T.L(2) - T.L(1) * (T.L(2) * T.L(2))\n 0\n sage: (T.L(2) * T.L(3)) * T.L(3) - T.L(2) * (T.L(3) * T.L(3))\n 0\n\n TESTS::\n\n sage: T = algebras.ArikiKoike(2, 3).T()\n sage: T0, T1, T2 = T.T()\n sage: (T1 * T0 * T1) * (T0 * T0)\n (-u0*u1)*T[1,0,1] + ((u0+u1))*T[0,1,0,1]\n sage: T1 * T.L(3) * T2 * T1 * T0 - T1 * (T.L(3) * T2 * T1 * T0)\n 0\n\n sage: T = algebras.ArikiKoike(3, 3).T()\n sage: x = T.T(0) * T.T(1)\n sage: (x*x)*x == x*(x*x)\n True\n\n sage: T = algebras.ArikiKoike(3, 4).T()\n sage: L1 = T.L(1)\n sage: L2 = T.L(2)\n sage: (L2 * L1^2) * L2 == L2 * (L1^2 * L2)\n True\n sage: T1 = T.T(1)\n sage: (T1 * L1^2) * T1 * L1 * L1 == (T1 * L1^2) * T1 * L1^2\n True\n ' (t1, s1) = m1 (t2, s2) = m2 one = self.base_ring().one() q = self._q qm1 = (q - one) if (s1 == self._one_perm): if (t1 == self._zero_tuple): return self._from_dict({m2: one}, remove_zeros=False) if (t2 == self._zero_tuple): return self._from_dict({(t1, s2): one}, remove_zeros=False) k1 = max((k for (k, a) in enumerate(t1) if (a != 0))) k2 = min((k for (k, a) in enumerate(t2) if (a != 0))) if (k1 < k2): T = list(t1) for k in range(k2, len(t2)): T[k] = t2[k] return self._from_dict({(tuple(T), s2): one}, remove_zeros=False) M = self._product_TT(k1, t1[k1], k2, t2[k2]) t1 = list(t1) t2 = list(t2) t1[k1] = 0 t2[k2] = 0 L = self._from_dict({(tuple(t1), self._one_perm): one}, remove_zeros=False) R = self._from_dict({(tuple(t2), s2): one}, remove_zeros=False) return ((L * M) * R) tprod = [([(k, a) for (k, a) in enumerate(t2) if (a != 0)], {s2: one})] for i in reversed(s1.reduced_word()): new_t = [] for index in range(len(tprod)): j = i (T, sprod) = tprod[index] absorbed = False for ind in range(len(T)): (k, a) = T[ind] if (j < k): j += 1 elif (j == k): absorbed = True new_t.append((list(T), {s: (q * sprod[s]) for s in sprod})) new_t[(- 1)][0][ind] = ((k - 1), a) for s in sprod: sprod[s] *= qm1 break elif (j == (k + 1)): absorbed = True T[ind] = ((k + 1), a) break if absorbed: continue temp = {} for p in sprod: c = sprod[p] pj = p.apply_simple_reflection(j, side='left') if p.has_descent(j, side='left'): iaxpy(1, {p: (c * qm1), pj: (c * self._q)}, temp) else: iaxpy(1, {pj: c}, temp) tprod[index] = (T, temp) tprod.extend(new_t) def compute(T, sprod): if (not T): return self._from_dict({(t1, s): sprod[s] for s in sprod}, remove_zeros=False, coerce=False) s_elt = self._from_dict({(self._zero_tuple, s): sprod[s] for s in sprod}, remove_zeros=False, coerce=False) cur = list(t1) product = [cur] if (t1 != self._zero_tuple): K = max((k for (k, a) in enumerate(t1) if (a != 0))) else: K = (- 1) T.reverse() while T: (k, a) = T.pop() if (k > K): cur[k] = a else: cur = list(self._zero_tuple) cur[k] = a product.append(cur) K = k return (self.prod((self._from_dict({(tuple(p), self._one_perm): one}, remove_zeros=False, coerce=False) for p in product)) * s_elt) return self.sum((compute(T, sprod) for (T, sprod) in tprod)) @lazy_attribute def _T0_polynomial(self): '\n Return `p` such that `T0^{r-1} - p = \\prod_{i=0}^{r-1} (T_0 - u_i)`.\n\n OUTPUT:\n\n A ``dict`` representing the polynomial `p`.\n\n EXAMPLES::\n\n sage: T = algebras.ArikiKoike(4, 2).T()\n sage: T._T0_polynomial\n ((u0 + u1 + u2 + u3))*DUMMY^3\n + ((-u0*u1 - u0*u2 - u1*u2 - u0*u3 - u1*u3 - u2*u3))*DUMMY^2\n + ((u0*u1*u2 + u0*u1*u3 + u0*u2*u3 + u1*u2*u3))*DUMMY\n - u0*u1*u2*u3\n ' z = PolynomialRing(self.base_ring(), 'DUMMY').gen() return (- prod(((z - val) for val in self._u)).truncate(self._r)) def _reduced_T0_power(self, exp): '\n Return the element `T_0` to the power ``exp`` in terms\n of `T_0^k` for `k < r`.\n\n EXAMPLES::\n\n sage: T = algebras.ArikiKoike(2, 3).T()\n sage: T._reduced_T0_power(1)\n 1\n sage: T._reduced_T0_power(2)\n ((u0 + u1))*DUMMY - u0*u1\n sage: T._reduced_T0_power(3)\n ((u0^2 + u0*u1 + u1^2))*DUMMY + (-u0^2*u1 - u0*u1^2)\n sage: T._reduced_T0_power(4)\n ((u0^3 + u0^2*u1 + u0*u1^2 + u1^3))*DUMMY\n + (-u0^3*u1 - u0^2*u1^2 - u0*u1^3)\n sage: T._reduced_T0_power(5)\n ((u0^4 + u0^3*u1 + u0^2*u1^2 + u0*u1^3 + u1^4))*DUMMY\n + (-u0^4*u1 - u0^3*u1^2 - u0^2*u1^3 - u0*u1^4)\n ' if (exp < self._r): return self.base_ring().one() PR = self._T0_polynomial.parent() z = PR.gen() cur = (z ** exp) while (cur.degree() >= self._r): cur = (PR.sum((((coeff * self._T0_polynomial) * (z ** e)) for (e, coeff) in enumerate(cur.list()[self._r:]))) + cur.truncate(self._r)) return cur @cached_method def _product_TT(self, kp, a, k, b): "\n Return the product `T_{k',a} T_{k,b}` with `k' \\geq k` in terms\n of the basis elements of ``self``.\n\n From Lemma 2.3 of [BM1997]_, we have\n\n .. MATH::\n\n T_{k',a} T_{k,b} = T_{k-1,b} T_{k',a} T_1\n + (q - 1) \\sum_{i=1}^b T_{k-1,a+b-i} T_{k',i}\n - T_{k-1,i} T_{k',a+b-i}.\n\n INPUT:\n\n - ``kp``, ``k`` -- 0-based indices\n - ``a``, ``b`` -- the exponents of the `T_0` generator\n\n EXAMPLES::\n\n sage: T = algebras.ArikiKoike(4, 3).T()\n sage: T._product_TT(1, 0, 0, 1)\n T[1,0]\n sage: T._product_TT(1, 1, 0, 1)\n T[1,0,0]\n sage: T._product_TT(1, 2, 0, 1)\n T[1,0,0,0]\n sage: T._product_TT(1, 3, 0, 1)\n (-u0*u1*u2*u3)*T[1]\n + ((u0*u1*u2+u0*u1*u3+u0*u2*u3+u1*u2*u3))*T[1,0]\n + ((-u0*u1-u0*u2-u1*u2-u0*u3-u1*u3-u2*u3))*T[1,0,0]\n + ((u0+u1+u2+u3))*T[1,0,0,0]\n sage: T._product_TT(1, 2, 0, 2)\n (-u0*u1*u2*u3)*T[1]\n + ((u0*u1*u2+u0*u1*u3+u0*u2*u3+u1*u2*u3))*T[1,0]\n + ((-u0*u1-u0*u2-u1*u2-u0*u3-u1*u3-u2*u3))*T[1,0,0]\n + ((u0+u1+u2+u3))*T[1,0,0,0]\n sage: T._product_TT(2, 1, 0, 3)\n (-u0*u1*u2*u3)*T[2,1]\n + ((u0*u1*u2+u0*u1*u3+u0*u2*u3+u1*u2*u3))*T[2,1,0]\n + ((-u0*u1-u0*u2-u1*u2-u0*u3-u1*u3-u2*u3))*T[2,1,0,0]\n + ((u0+u1+u2+u3))*T[2,1,0,0,0]\n\n TESTS::\n\n sage: H = algebras.ArikiKoike(3, 4)\n sage: T = H.T()\n sage: T._product_TT(1, 2, 1, 2)\n (-u0*u1*u2+u0*u1*u2*q)*T[1,0]\n + (u0*u1*u2-u0*u1*u2*q)*T[0,1]\n + ((u0+u1+u2)+(-u0-u1-u2)*q)*T[0,1,0,0]\n + ((-u0-u1-u2)+(u0+u1+u2)*q)*T[0,0,1,0]\n + T[0,0,1,0,0,1]\n sage: T._product_TT(2,2,2,2)\n (-u0*u1*u2+u0*u1*u2*q)*T[2,1,0,2]\n + (u0*u1*u2-u0*u1*u2*q)*T[1,0,2,1]\n + ((u0+u1+u2)+(-u0-u1-u2)*q)*T[1,0,2,1,0,0]\n + ((-u0-u1-u2)+(u0+u1+u2)*q)*T[1,0,0,2,1,0]\n + T[1,0,0,2,1,0,0,1]\n sage: T._product_TT(3,2,3,2)\n (-u0*u1*u2+u0*u1*u2*q)*T[3,2,1,0,3,2]\n + (u0*u1*u2-u0*u1*u2*q)*T[2,1,0,3,2,1]\n + ((u0+u1+u2)+(-u0-u1-u2)*q)*T[2,1,0,3,2,1,0,0]\n + ((-u0-u1-u2)+(u0+u1+u2)*q)*T[2,1,0,0,3,2,1,0]\n + T[2,1,0,0,3,2,1,0,0,1]\n " one = self.base_ring().one() if (k == 0): if ((a + b) < self._r): T = list(self._zero_tuple) T[kp] = (a + b) return self._from_dict({(tuple(T), self._one_perm): one}, remove_zeros=False, coerce=False) def key(exp): if ((exp > 0) or (kp == 0)): T = list(self._zero_tuple) T[kp] = exp return (tuple(T), self._one_perm) perm = self._Pn.one() for j in range(1, (kp + 1)): perm = perm.apply_simple_reflection_left(j) return (self._zero_tuple, perm) p = self._reduced_T0_power((a + b)) zero = self.base_ring().zero() return self._from_dict({key(exp): coeff for (exp, coeff) in enumerate(p) if (coeff != zero)}, remove_zeros=False, coerce=False) assert (kp >= k) s1 = self._Pn.simple_reflection(1) qm1 = (self._q - one) T = list(self._zero_tuple) T[(k - 1)] = b T[kp] = a ret = {(tuple(T), s1): one} zero = self.base_ring().zero() def T_index(exp, ind, i, indp): T = list(self._zero_tuple) T[ind] = exp T[indp] = i return tuple(T) for i in range(1, (b + 1)): if (((a + b) - i) == i): continue if (((a + b) - i) < self._r): T[(k - 1)] = ((a + b) - i) T[kp] = i m = (tuple(T), self._one_perm) T[(k - 1)] = i T[kp] = ((a + b) - i) mp = (tuple(T), self._one_perm) iaxpy(1, {m: qm1, mp: (- qm1)}, ret) else: p = self._reduced_T0_power(((a + b) - i)) temp = {(T_index(exp, (k - 1), i, kp), self._one_perm): (qm1 * coeff) for (exp, coeff) in enumerate(p) if (coeff != zero)} if ((p[0] != zero) and (k > 1)): perm = self._Pn.one() for j in range(2, (k + 1)): perm = perm.apply_simple_reflection_left(j) tind = T_index(0, (k - 1), i, kp) temp[(tind, perm)] = temp[(tind, self._one_perm)] del temp[(tind, self._one_perm)] iaxpy(1, temp, ret) temp = {(T_index(exp, kp, i, (k - 1)), self._one_perm): ((- qm1) * coeff) for (exp, coeff) in enumerate(p) if (coeff != zero)} if (p[0] != zero): perm = self._Pn.one() for j in range(1, (kp + 1)): perm = perm.apply_simple_reflection_left(j) tind = T_index(0, kp, i, (k - 1)) temp[(tind, perm)] = temp[(tind, self._one_perm)] del temp[(tind, self._one_perm)] iaxpy(1, temp, ret) return self._from_dict(ret, remove_zeros=False)
class CubicHeckeElement(CombinatorialFreeModule.Element): "\n An element of a :class:`CubicHeckeAlgebra`.\n\n For more information see :class:`CubicHeckeAlgebra`.\n\n EXAMPLES::\n\n sage: CHA3s = algebras.CubicHecke('s1, s2'); CHA3s.an_element()\n (-w)*s1*s2^-1 + v*s1 + u*s2 + ((-v*w+u)/w)\n sage: CHA3.<c1, c2> = algebras.CubicHecke(3)\n sage: c1**3*~c2\n u*w*c1^-1*c2^-1 + (u^2-v)*c1*c2^-1 + (-u*v+w)*c2^-1\n " def __invert__(self): '\n Return inverse of ``self`` (if possible).\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: ele1 = CHA3((1,-2,1)); ele1\n c0*c1^-1*c0\n sage: ~ele1 # indirect doctest\n c0^-1*c1*c0^-1\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: x = CHA2.an_element(); x\n v*c + ((-v*w+u)/w)\n sage: ~x\n Traceback (most recent call last):\n ...\n ValueError: cannot invert self (= v*c + ((-v*w+u)/w))\n ' self_Tietze = self.Tietze() if (self_Tietze is None): return super().__invert__() inverse_Tietze = () len_self = len(self_Tietze) inverse_Tietze = tuple([((- 1) * self_Tietze[((len_self - i) - 1)]) for i in range(len_self)]) P = self.parent() return P(inverse_Tietze) def Tietze(self): '\n Return the Tietze presentation of ``self`` if ``self`` belongs to the\n basis of its parent and ``None`` otherwise.\n\n OUTPUT:\n\n A tuple representing the pre image braid of ``self`` if ``self`` is a\n monomial from the basis ``None`` else-wise\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: ele = CHA3.an_element(); ele\n (-w)*c0*c1^-1 + v*c0 + u*c1 + ((-v*w+u)/w)\n sage: ele.Tietze() is None\n True\n sage: [CHA3(sp).Tietze() for sp in ele.support()]\n [(), (1,), (1, -2), (2,)]\n ' vecd = self._monomial_coefficients if (len(vecd) != 1): return None (ind, coeff) = next(iter(vecd.items())) if coeff.is_one(): return ind.Tietze() def max_len(self): '\n Return the maximum of the length of Tietze expressions among the\n support of ``self``.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: ele = CHA3.an_element(); ele\n (-w)*c0*c1^-1 + v*c0 + u*c1 + ((-v*w+u)/w)\n sage: ele.max_len()\n 2\n ' return max((len(bas_ele.Tietze()) for bas_ele in self.support())) def braid_group_algebra_pre_image(self): '\n Return a pre image of ``self`` in the group algebra of the braid group\n (with respect to the basis given by Ivan Marin).\n\n OUTPUT:\n\n The pre image of ``self`` as instance of the element class of the group\n algebra of the BraidGroup\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: ele = CHA3.an_element(); ele\n (-w)*c0*c1^-1 + v*c0 + u*c1 + ((-v*w+u)/w)\n sage: b_ele = ele.braid_group_algebra_pre_image(); b_ele\n ((-v*w+u)/w) + v*c0 + u*c1 + (-w)*c0*c1^-1\n sage: ele in CHA3\n True\n sage: b_ele in CHA3\n False\n sage: b_ele in CHA3.braid_group_algebra()\n True\n ' ch_algebra = self.parent() braid_group_algebra = ch_algebra.braid_group_algebra() braid_group = ch_algebra.braid_group() def phi(bas_ele): return braid_group_algebra(braid_group(bas_ele)) return ch_algebra._apply_module_morphism(self, phi, codomain=braid_group_algebra) def cubic_braid_group_algebra_pre_image(self): '\n Return a pre image of ``self`` in the group algebra of the cubic braid\n group.\n\n OUTPUT:\n\n The pre image of ``self`` as instance of the element class of the group\n algebra of the :class:`CubicBraidGroup`.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: ele = CHA3.an_element(); ele\n (-w)*c0*c1^-1 + v*c0 + u*c1 + ((-v*w+u)/w)\n sage: cb_ele = ele.cubic_braid_group_algebra_pre_image(); cb_ele\n (-w)*c0*c1^-1 + v*c0 + u*c1 + ((-v*w+u)/w)\n sage: ele in CHA3\n True\n sage: cb_ele in CHA3\n False\n sage: cb_ele in CHA3.cubic_braid_group_algebra()\n True\n ' ch_algebra = self.parent() cbraid_group_algebra = ch_algebra.cubic_braid_group_algebra() cbraid_group = ch_algebra.cubic_braid_group() def phi(bas_ele): return cbraid_group_algebra(cbraid_group(bas_ele)) return ch_algebra._apply_module_morphism(self, phi, codomain=cbraid_group_algebra) @cached_method def matrix(self, subdivide=False, representation_type=None, original=False): "\n Return certain types of matrix representations of ``self``.\n\n The absolutely irreducible representations of the cubic Hecke algebra\n are constructed using the ``GAP3`` interface and the ``CHEVIE`` package\n if ``GAP3`` and ``CHEVIE`` are installed on the system. Furthermore,\n the representations given on `Ivan Marin's homepage\n <http://www.lamfa.u-picardie.fr/marin/representationH4-en.html>`__\n are used:\n\n INPUT:\n\n - ``subdivide`` -- boolean (default: ``False``): this boolean is passed\n to the block_matrix function\n - ``representation_type`` -- instance of enum :class:`RepresentationType`;\n this can be obtained by the attribute :attr:`CubicHeckeAlgebra.repr_type`\n of ``self``; the following values are possible:\n\n - ``RegularLeft`` -- (regular left repr. from the above URL)\n - ``RegularRight`` -- (regular right repr. from the above URL)\n - ``SplitIrredChevie`` -- (split irred. repr. via CHEVIE)\n - ``SplitIrredMarin`` -- (split irred. repr. from the above URL)\n - default: ``SplitIrredChevie`` taken if GAP3 and CHEVIE are installed\n on the system, otherwise the default will be ``SplitIrredMarin``\n\n - ``original`` -- boolean (default: ``False``): if set to true the base\n ring of the matrix will be the generic base_ring resp. generic extension\n ring (for the split versions) of the parent of ``self``\n\n OUTPUT:\n\n An instance of :class:`~sage.algebras.hecke_algebras.cubic_hecke_matrix_rep.CubicHeckeMatrixRep`,\n which is inherited from :class:`~sage.matrix.matrix_generic_dense.Matrix_generic_dense`.\n In the case of the irreducible representations the matrix is given as a\n block matrix. Each single irreducible can be obtained as item indexed by\n the members of the enum :class:`AbsIrreducibeRep` available via\n :attr:`CubicHeckeAlgebra.irred_repr`.\n For details type: ``CubicHeckeAlgebra.irred_repr?``.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: CHA3.inject_variables()\n Defining c0, c1\n sage: c0m = c0.matrix()\n sage: c0m[CHA3.irred_repr.W3_111]\n [ -b - a + u 0 0]\n [(-2*a + u)*b - 2*a^2 + 2*u*a - v b 0]\n [ b 1 a]\n\n using the the ``representation_type`` option::\n\n sage: CHA3.<c0, c1> = algebras.CubicHecke(3) # optional gap3\n sage: chevie = CHA3.repr_type.SplitIrredChevie # optional gap3\n sage: c0m_ch = c0.matrix(representation_type=chevie) # optional gap3\n sage: c0m_ch[CHA3.irred_repr.W3_011] # optional gap3\n [ b 0]\n [ -b -b - a + u]\n sage: c0m[CHA3.irred_repr.W3_011]\n [ b 0]\n [a^2 - u*a + v -b - a + u]\n\n using the the ``original`` option::\n\n sage: c0mo = c0.matrix(original=True)\n sage: c0mo_ch = c0.matrix(representation_type=chevie, original=True) # optional gap3\n sage: c0mo[CHA3.irred_repr.W3_011]\n [ b 0]\n [b*c c]\n sage: c0mo_ch[CHA3.irred_repr.W3_011] # optional gap3\n [ b 0]\n [-b c]\n\n specialized matrices::\n\n sage: t = (3,7,11)\n sage: CHA4 = algebras.CubicHecke(4, cubic_equation_roots=t) # optional database_cubic_hecke\n sage: e = CHA4.an_element(); e # optional database_cubic_hecke\n -231*c0*c1^-1 + 131*c0*c2^-1 + 21*c2*c1 - 1440/11\n sage: em = e.matrix() # optional database_cubic_hecke\n sage: em.base_ring() # optional database_cubic_hecke\n Splitting Algebra of T^2 + T + 1 with roots [E3, -E3 - 1]\n over Integer Ring localized at (3, 7, 11)\n sage: em.dimensions() # optional database_cubic_hecke\n (108, 108)\n sage: em_irr24 = em[23] # optional database_cubic_hecke\n sage: em_irr24.dimensions() # optional database_cubic_hecke\n (9, 9)\n sage: em_irr24[3,2] # optional database_cubic_hecke\n -131*E3 - 393/7\n sage: emg = e.matrix(representation_type=chevie) # optional gap3 database_cubic_hecke\n sage: emg_irr24 = emg[23] # optional gap3 database_cubic_hecke\n sage: emg_irr24[3,2] # optional gap3 database_cubic_hecke\n -131*E3 - 393/7\n " parent = self.parent() MS = CubicHeckeMatrixSpace(parent, representation_type=representation_type, subdivide=subdivide, original=original) return MS(self) def revert_garside(self): '\n Return the image of ``self`` under the Garside involution.\n\n .. SEEALSO::\n\n :meth:`CubicHeckeAlgebra.garside_involution`\n\n EXAMPLES::\n\n sage: roots = (E(3), ~E(3), 1)\n sage: CHA3.<c1, c2> = algebras.CubicHecke(3, cubic_equation_roots=roots)\n sage: e = CHA3.an_element(); e\n -c1*c2^-1\n sage: _.revert_garside()\n -c2*c1^-1\n sage: _.revert_garside()\n -c1*c2^-1\n ' return self.parent().garside_involution(self) def revert_mirror(self): '\n Return the image of ``self`` under the mirror isomorphism.\n\n .. SEEALSO::\n\n :meth:`CubicHeckeAlgebra.mirror_isomorphism`\n\n EXAMPLES::\n\n sage: CHA3.<c1, c2> = algebras.CubicHecke(3)\n sage: e = CHA3.an_element()\n sage: e.revert_mirror()\n -1/w*c0^-1*c1 + u/w*c0^-1 + v/w*c1^-1 + ((v*w-u)/w)\n sage: _.revert_mirror() == e\n True\n ' return self.parent().mirror_isomorphism(self) def revert_orientation(self): '\n Return the image of ``self`` under the anti involution reverting the\n orientation of braids.\n\n .. SEEALSO::\n\n :meth:`CubicHeckeAlgebra.orientation_antiinvolution`\n\n EXAMPLES::\n\n sage: CHA3.<c1, c2> = algebras.CubicHecke(3)\n sage: e = CHA3.an_element()\n sage: e.revert_orientation()\n (-w)*c2^-1*c1 + v*c1 + u*c2 + ((-v*w+u)/w)\n sage: _.revert_orientation() == e\n True\n ' return self.parent().orientation_antiinvolution(self) def formal_markov_trace(self, extended=False, field_embedding=False): '\n Return a formal expression which can be specialized to Markov traces\n which factor through the cubic Hecke algebra.\n\n This covers Markov traces corresponding to the\n\n - HOMFLY-PT polynomial,\n - Kauffman polynomial,\n - Links-Gould polynomial.\n\n These expressions are elements of a sub-module of the module of linear\n forms on ``self`` the base ring of which is an extension of the\n generic base ring of ``self`` by an additional variable ``s``\n representing the writhe factor. All variables of this base ring\n extension are invertible.\n\n A Markov trace is a family of class functions `tr_n` on the family\n of braid groups `B_n` into some commutative ring `R` depending on\n a unit `s \\in R` such that for all `b \\in B_n` the following two\n conditions are satisfied (see [Kau1991]_, section 7):\n\n .. MATH::\n\n \\begin{array}{lll}\n tr_{n+1}(b g_n) & = & s tr_n(b), \\\\\n tr_{n+1}(b g^{-1}_n) & = & s^{-1} tr_n(b).\n \\end{array}\n\n The unit `s` is often called the writhe factor and corresponds to the\n additional variable mentioned above.\n\n .. NOTE::\n\n Currently it is not known if all linear forms of this sub-module\n belong to a Markov trace, i.e. can be extended to the full tower\n of cubic Hecke algebras. Anyway, at least the four basis elements\n (``U1``, ``U2``, ``U3`` and ``K4``) can be reconstructed form\n the HOMFLY-PT and Kauffman polynomial.\n\n INPUT:\n\n - ``extended`` -- boolean (default: ``False``); if set to ``True`` the\n base ring of the Markov trace module is constructed as an extension\n of generic extension ring of ``self``; per default it is constructed\n upon the generic base ring\n - ``field_embedding`` -- boolean (default: ``False``); if set to ``True``\n the base ring of the module is the smallest field containing the\n generic extension ring of ``self``; ignored if ``extended=False``\n\n EXAMPLES::\n\n sage: from sage.knots.knotinfo import KnotInfo\n sage: CHA2 = algebras.CubicHecke(2)\n sage: K3_1 = KnotInfo.K3_1\n sage: b3_1 = CHA2(K3_1.braid())\n sage: mt3_1 = b3_1.formal_markov_trace(); mt3_1\n ((u^2*s^2-v*s^2+u*w)/s)*B[U1] + (-u*v+w)*B[U2]\n sage: mt3_1.parent()\n Free module generated by {U1, U2}\n over Multivariate Polynomial Ring in u, v, w, s\n over Integer Ring localized at (s, w, v, u)\n\n sage: f = b3_1.formal_markov_trace(extended=True); f\n (a^2*b*c*s^-1+a*b^2*c*s^-1+a*b*c^2*s^-1+a^2*s+a*b*s+b^2*s+a*c*s+b*c*s+c^2*s)*B[U1]\n + (-a^2*b-a*b^2-a^2*c+(-2)*a*b*c-b^2*c-a*c^2-b*c^2)*B[U2]\n sage: f.parent().base_ring()\n Multivariate Laurent Polynomial Ring in a, b, c, s\n over Splitting Algebra of x^2 + x + 1 with roots [e3, -e3 - 1]\n over Integer Ring\n\n sage: f = b3_1.formal_markov_trace(extended=True, field_embedding=True); f\n ((a^2*b*c+a*b^2*c+a*b*c^2+a^2*s^2+a*b*s^2+b^2*s^2+a*c*s^2+b*c*s^2+c^2*s^2)/s)*B[U1]\n + (-a^2*b-a*b^2-a^2*c-2*a*b*c-b^2*c-a*c^2-b*c^2)*B[U2]\n sage: f.parent().base_ring()\n Fraction Field of Multivariate Polynomial Ring in a, b, c, s\n over Cyclotomic Field of order 3 and degree 2\n\n Obtaining the well known link invariants from it::\n\n sage: MT = mt3_1.base_ring()\n sage: sup = mt3_1.support()\n sage: u, v, w, s = mt3_1.base_ring().gens()\n sage: LK3_1 = mt3_1*s**-3 # since the writhe of K3_1 is 3\n sage: f = MT.specialize_homfly()\n sage: g = sum(f(LK3_1.coefficient(b)) * b.regular_homfly_polynomial() for b in sup); g\n L^-2*M^2 - 2*L^-2 - L^-4\n sage: g == K3_1.link().homfly_polynomial()\n True\n\n sage: f = MT.specialize_kauffman()\n sage: g = sum(f(LK3_1.coefficient(b)) * b.regular_kauffman_polynomial() for b in sup); g\n a^-2*z^2 - 2*a^-2 + a^-3*z + a^-4*z^2 - a^-4 + a^-5*z\n sage: g == K3_1.kauffman_polynomial()\n True\n\n sage: f = MT.specialize_links_gould()\n sage: g = sum(f(LK3_1.coefficient(b)) * b.links_gould_polynomial() for b in sup); g\n -t0^2*t1 - t0*t1^2 + t0^2 + 2*t0*t1 + t1^2 - t0 - t1 + 1\n sage: g == K3_1.link().links_gould_polynomial()\n True\n ' cha = self.parent() vs = self.to_vector() mtcf = cha._markov_trace_coeffs() M = cha._markov_trace_module(extended=extended, field_embedding=field_embedding) if (M != mtcf[0].parent()): if field_embedding: MI = cha._markov_trace_module(extended=extended, field_embedding=False) RI = MI.base_ring() mtcf = [MI.from_vector(cf.to_vector()) for cf in mtcf] vs = vs.change_ring(RI) mtcf = [M.from_vector(cf.to_vector()) for cf in mtcf] R = M.base_ring() return M.linear_combination(((mtcf[i], R(val)) for (i, val) in vs.iteritems()))
class CubicHeckeAlgebra(CombinatorialFreeModule): "\n Return the Cubic-Hecke algebra with respect to the Artin braid group on\n `n` strands.\n\n This is a quotient of the group algebra of the Artin braid group, such that\n the images `s_i` (`1 \\leq i < n`) of the braid generators satisfy a cubic\n equation (see :mod:`~sage.algebras.hecke_algebras.cubic_hecke_algebra`\n for more information, in a session type\n ``sage.algebras.hecke_algebras.cubic_hecke_algebra?``):\n\n .. MATH::\n\n s_i^3 = u s_i^2 - v s_i + w.\n\n The base ring of this algebra can be specified by giving optional keywords\n described below. If no keywords are given, the base ring will be a\n :class:`CubicHeckeRingOfDefinition`, which is constructed as the\n polynomial ring in `u, v, w` over the integers localized at `w`.\n This ring will be called the *ring of definition* or sometimes for short\n *generic base ring*. However note, that in this context the word *generic*\n should not remind in a generic point of the corresponding scheme.\n\n In addition to the base ring, another ring containing the roots (`a`, `b`\n and `c`) of the cubic equation will be needed to handle the split\n irreducible representations. This ring will be called the *extension ring*.\n Generically, the extension ring will be a\n :class:`~sage.algebras.hecke_algebras.cubic_hecke_base_ring.CubicHeckeExtensionRing`,\n which is constructed as the Laurent polynomial ring in `a, b` and `c` over\n the integers adjoined with a primitive third root of unity. A special form\n of this *generic extension ring* is constructed as a\n :class:`~sage.algebras.splitting_algebra.SplittingAlgebra` for the roots of\n the cubic equation and a primitive third root of unity over the ring of\n definition. This ring will be called the *default extension ring*.\n\n This class uses a static and a dynamic data library. The first one is defined\n as instance of :class:`~sage.databases.cubic_hecke_db.CubicHeckeDataBase`\n and contains the complete basis for the algebras with less than 5 strands\n and various types of representation matrices of the generators. These data\n have been calculated by `Ivan Marin <http://www.lamfa.u-picardie.fr/marin/anglais.html>`__\n and have been imported from his corresponding\n `web page <http://www.lamfa.u-picardie.fr/marin/representationH4-en.html>`__.\n\n Note that just the data for the cubic Hecke algebras on less than four\n strands is available in Sage by default. To deal with four strands and\n more you need to install the optional package\n `database_cubic_hecke <https://pypi.org/project/database-cubic-hecke/>`__\n by typing\n\n - ``sage -i database_cubic_hecke`` (first time installation) or\n - ``sage -f database_cubic_hecke`` (reinstallation) respective\n - ``sage -i -c database_cubic_hecke`` (for running all test in concern)\n - ``sage -f -c database_cubic_hecke``\n\n This will add a `Python wrapper <https://github.com/soehms/database_cubic_hecke#readme>`__\n around Ivan Marin's data to the Sage library. For more installation hints\n see the documentation of this wrapper.\n\n Furthermore, representation matrices can be obtained from the ``CHEVIE``\n package of ``GAP3`` via the ``GAP3`` interface if ``GAP3`` is installed\n inside Sage. For more information on how to obtain representation matrices\n to elements of this class, see the documentation of the element class\n :class:`~sage.algebras.hecke_algebras.cubic_hecke_algebra.CubicHeckeElement`\n or its method\n :meth:`~sage.algebras.hecke_algebras.cubic_hecke_algebra.CubicHeckeElement.matrix`:\n\n ``algebras.CubicHecke.Element?`` or ``algebras.CubicHecke.Element.matrix?``\n\n The second library is created as instance of\n :class:`~sage.databases.cubic_hecke_db.CubicHeckeFileCache` and used while\n working with the class to achieve a better performance. This file cache\n contains images of braids and representation matrices of basis elements\n from former calculations. A refresh of the file cache can be done using\n the :meth:`reset_filecache`.\n\n INPUT:\n\n - ``names`` -- string containing the names of the generators as images of\n the braid group generators\n - ``cubic_equation_parameters`` -- tuple ``(u, v, w)`` of three elements\n in an integral domain used as coefficients in the cubic equation. If this\n argument is given the base ring will be set to the common parent of\n ``u, v, w``. In addition a conversion map from the generic base ring is\n supplied. This keyword can also be used to change the variable names of\n the generic base ring (see example 3 below)\n - ``cubic_equation_roots`` -- tuple ``(a, b, c)`` of three elements in an\n integral domain which stand for the roots of the cubic equation. If this\n argument is given the extension ring will be set to the common parent of\n ``a, b, c``. In addition a conversion map from the generic extension ring\n and the generic base ring is supplied. This keyword can also be used to\n change the variable names of the generic extension ring (see example 3\n below)\n\n EXAMPLES:\n\n Cubic Hecke algebra over the ring of definition::\n\n sage: CHA3 = algebras.CubicHecke('s1, s2'); CHA3\n Cubic Hecke algebra on 3 strands over Multivariate Polynomial Ring\n in u, v, w\n over Integer Ring localized at (w,)\n with cubic equation: h^3 - u*h^2 + v*h - w = 0\n sage: CHA3.gens()\n (s1, s2)\n sage: GER = CHA3.extension_ring(generic=True); GER\n Multivariate Laurent Polynomial Ring in a, b, c\n over Splitting Algebra of x^2 + x + 1\n with roots [e3, -e3 - 1] over Integer Ring\n sage: ER = CHA3.extension_ring(); ER\n Splitting Algebra of T^2 + T + 1 with roots [E3, -E3 - 1]\n over Splitting Algebra of h^3 - u*h^2 + v*h - w\n with roots [a, b, -b - a + u]\n over Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n\n Element construction::\n\n sage: ele = CHA3.an_element(); ele\n (-w)*s1*s2^-1 + v*s1 + u*s2 + ((-v*w+u)/w)\n sage: ele2 = ele**2; ele2\n w^2*(s1^-1*s2)^2 + (-u*w^2)*s1^-1*s2*s1^-1 + (-v*w)*s2*s1^-1*s2\n + (-v*w^2)*s1^-1*s2^-1 + u*w*s1*s2*s1^-1*s2 + (-u*w)*s1^-1*s2*s1\n + (-u*v*w+2*v*w-2*u)*s1*s2^-1 + u*v*w*s2*s1^-1 + u*v*s2*s1 + v^2*w*s1^-1\n + (-u^2*w)*s1*s2*s1^-1 + ((u*v^2*w-2*v^2*w-u*w^2+2*u*v)/w)*s1\n + u*v*s1*s2 + (u^2*w+v^2*w)*s2^-1 + ((u^3*w-2*u*v*w+2*u^2)/w)*s2\n + ((-u^2*v*w^2-v^3*w^2+v^2*w^2-2*u*v*w+u^2)/w^2)\n sage: B3 = CHA3.braid_group()\n sage: braid = B3((2,-1, 2, 1)); braid\n s2*s1^-1*s2*s1\n sage: ele3 = CHA3(braid); ele3\n s1*s2*s1^-1*s2 + u*s1^-1*s2*s1 + (-v)*s1*s2^-1 + v*s2^-1*s1 + (-u)*s1*s2*s1^-1\n sage: ele3t = CHA3((2,-1, 2, 1))\n sage: ele3 == ele3t\n True\n sage: CHA4 = algebras.CubicHecke(4) # optional database_cubic_hecke\n sage: ele4 = CHA4(ele3); ele4 # optional database_cubic_hecke\n c0*c1*c0^-1*c1 + u*c0^-1*c1*c0 + (-v)*c0*c1^-1 + v*c1^-1*c0 + (-u)*c0*c1*c0^-1\n\n Cubic Hecke algebra over the ring of definition using different variable\n names::\n\n sage: algebras.CubicHecke(3, cubic_equation_parameters='u, v, w', cubic_equation_roots='p, q, r')\n Cubic Hecke algebra on 3 strands over Multivariate Polynomial Ring\n in u, v, w\n over Integer Ring localized at (w,)\n with cubic equation: h^3 - u*h^2 + v*h - w = 0\n sage: _.extension_ring()\n Splitting Algebra of T^2 + T + 1 with roots [E3, -E3 - 1]\n over Splitting Algebra of h^3 - u*h^2 + v*h - w\n with roots [p, q, -q - p + u]\n over Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n\n Cubic Hecke algebra over a special base ring with respect to a special\n cubic equation::\n\n sage: algebras.CubicHecke('s1, s2', cubic_equation_parameters=(QQ(1),3,1))\n Cubic Hecke algebra on 3 strands over Rational Field\n with cubic equation: h^3 - h^2 + 3*h - 1 = 0\n sage: CHA3 = _\n sage: ER = CHA3.extension_ring(); ER\n Number Field in T with defining polynomial T^12 + 4*T^11 + 51*T^10\n + 154*T^9 + 855*T^8 + 1880*T^7 + 5805*T^6 + 8798*T^5 + 15312*T^4\n + 14212*T^3 + 13224*T^2 + 5776*T + 1444\n sage: CHA3.cubic_equation_roots()[0]\n -4321/1337904*T^11 - 4181/445968*T^10 - 4064/27873*T^9 - 51725/167238*T^8\n - 2693189/1337904*T^7 - 1272907/445968*T^6 - 704251/74328*T^5\n - 591488/83619*T^4 - 642145/83619*T^3 + 252521/111492*T^2 + 45685/5868*T\n + 55187/17604\n\n sage: F = GF(25,'u')\n sage: algebras.CubicHecke('s1, s2', cubic_equation_parameters=(F(1), F.gen(), F(3)))\n Cubic Hecke algebra on 3 strands over Finite Field in u of size 5^2\n with cubic equation: h^3 + 4*h^2 + u*h + 2 = 0\n sage: CHA3 = _\n sage: ER = CHA3.extension_ring(); ER\n Finite Field in S of size 5^4\n sage: CHA3.cubic_equation_roots()\n [2*S^3 + 2*S^2 + 2*S + 1, 2*S^3 + 3*S^2 + 3*S + 2, S^3 + 3]\n\n\n Cubic Hecke algebra over a special extension ring with respect to special\n roots of the cubic equation::\n\n sage: UCF = UniversalCyclotomicField()\n sage: e3=UCF.gen(3); e5=UCF.gen(5)\n sage: algebras.CubicHecke('s1, s2', cubic_equation_roots=(1, e5, e3))\n Cubic Hecke algebra on 3 strands over Universal Cyclotomic Field\n with cubic equation:\n h^3 + (-E(15) - E(15)^4 - E(15)^7 + E(15)^8)*h^2 + (-E(15)^2 - E(15)^8\n - E(15)^11 - E(15)^13 - E(15)^14)*h - E(15)^8 = 0\n\n TESTS::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: TestSuite(CHA3).run()\n\n Note, that the ``TestSuite`` run on the cubic Hecke algebra on four strands\n would take up to half an hour if the file cache is empty. A repetition takes\n less than half a minute.\n " Element = CubicHeckeElement repr_type = RepresentationType irred_repr = AbsIrreducibeRep @staticmethod def __classcall_private__(cls, n=None, names='c', cubic_equation_parameters=None, cubic_equation_roots=None): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2, 'd', cubic_equation_roots=(3,5,7)); CHA2\n Cubic Hecke algebra on 2 strands\n over Integer Ring localized at (3, 5, 7)\n with cubic equation:\n h^3 - 15*h^2 + 71*h - 105 = 0\n sage: CHA2.inject_variables()\n Defining d\n sage: CHA3 = algebras.CubicHecke(3, cubic_equation_parameters=(3,5,7)); CHA3\n Cubic Hecke algebra on 3 strands\n over Integer Ring localized at (7,)\n with cubic equation:\n h^3 - 3*h^2 + 5*h - 7 = 0\n sage: CHA3.cubic_equation_roots()\n [a, b, -b - a + 3]\n " if (n is not None): try: n = (ZZ(n) - 1) except TypeError: names = n n = None if (n is None): if (type(names) is str): n = len(names.split(',')) else: names = list(names) n = len(names) from sage.structure.category_object import normalize_names names = tuple(normalize_names(n, names)) return super().__classcall__(cls, names, cubic_equation_parameters=cubic_equation_parameters, cubic_equation_roots=cubic_equation_roots) def __init__(self, names, cubic_equation_parameters=None, cubic_equation_roots=None): "\n Initialize ``self``.\n\n TESTS::\n\n sage: CHA2 = algebras.CubicHecke(2, 'd', cubic_equation_roots=(3,5,7))\n sage: TestSuite(CHA2).run()\n sage: CHA2 = algebras.CubicHecke(2, cubic_equation_parameters=(3,5,7))\n sage: TestSuite(CHA2).run()\n " self._cubic_braid_group = CubicBraidGroup(names) self._braid_group = self._cubic_braid_group.braid_group() n = len(self._cubic_braid_group.gens()) self._nstrands = (n + 1) self._dim_irr_rep = sum([irr.dimension() for irr in AbsIrreducibeRep if (irr.number_gens() == n)]) from sage.databases.cubic_hecke_db import CubicHeckeDataBase, CubicHeckeFileCache self._database = CubicHeckeDataBase() self._filecache = CubicHeckeFileCache(self._nstrands) ring_of_definition_names = ('u', 'v', 'w') if (cubic_equation_parameters is not None): if isinstance(cubic_equation_parameters, str): ring_of_definition_names = tuple(cubic_equation_parameters.split(',')) if (len(ring_of_definition_names) != 3): raise ValueError('cubic_equation_parameters must consist of exactly 3 elements') cubic_equation_parameters = None else: if isinstance(cubic_equation_parameters, list): cubic_equation_parameters = tuple(cubic_equation_parameters) if (not isinstance(cubic_equation_parameters, tuple)): raise TypeError('cubic_equation_parameters must be a tuple or list') if (len(cubic_equation_parameters) != 3): raise ValueError('cubic_equation_parameters must consist of exactly 3 elements') generic_extension_ring_names = ('a', 'b', 'c') if (cubic_equation_roots is not None): if isinstance(cubic_equation_roots, str): generic_extension_ring_names = tuple(cubic_equation_roots.split(',')) if (len(generic_extension_ring_names) != 3): raise ValueError('cubic_equation_roots must consist of exactly 3 elements') cubic_equation_roots = None else: if isinstance(cubic_equation_roots, list): cubic_equation_roots = tuple(cubic_equation_roots) if (not isinstance(cubic_equation_roots, tuple)): raise TypeError('cubic_equation_roots must be a tuple or list') if (len(cubic_equation_roots) != 3): raise ValueError('cubic_equation_roots must consist of exactly 3 elements') if (len(set((ring_of_definition_names + generic_extension_ring_names))) < 6): raise ValueError(('there is an overlap of names between cubic equation parameters (%s) and cubic equation roots (%s)' % (ring_of_definition_names, generic_extension_ring_names))) ring_of_definition = CubicHeckeRingOfDefinition(names=ring_of_definition_names) (u, v, w) = ring_of_definition.gens() generic_extension_ring = ring_of_definition.extension_ring(names=generic_extension_ring_names) (a, b, c) = generic_extension_ring.gens() self._ring_of_definition = ring_of_definition self._generic_extension_ring = generic_extension_ring self._generic_cubic_equation_parameters = [u, v, w] self._generic_cubic_equation_roots = [a, b, c] if ((cubic_equation_parameters is None) and (cubic_equation_roots is not None)): (pa, pb, pc) = cubic_equation_roots cubic_equation_parameters = [((pa + pb) + pc), (((pa * pb) + (pb * pc)) + (pa * pc)), ((pa * pb) * pc)] verbose(('cubic_equation_parameters %s set according to cubic_equation_roots %s' % (cubic_equation_parameters, cubic_equation_roots)), level=2) if (cubic_equation_parameters is not None): base_ring = ring_of_definition.create_specialization(cubic_equation_parameters) cubic_equation_parameters = [base_ring(para) for para in cubic_equation_parameters] verbose(('base_ring %s set according to cubic_equation_parameters %s' % (base_ring, cubic_equation_parameters)), level=2) else: base_ring = self._ring_of_definition cubic_equation_parameters = self._generic_cubic_equation_parameters verbose(('base_ring %s and cubic_equation_parameters %s defined' % (base_ring, cubic_equation_parameters)), level=2) (pu, pv, pw) = cubic_equation_parameters pol_bas_ring = base_ring['h'] cubic_equation = pol_bas_ring([(- pw), pv, (- pu), 1]) verbose(('cubic_equation %s defined' % cubic_equation), level=2) if (base_ring != ring_of_definition): if (cubic_equation_roots is None): ext_ring_names = list(generic_extension_ring_names) cubic_equation_roots = solve_with_extension(cubic_equation, ext_ring_names, var='S', flatten=True) if (cubic_equation_roots is not None): extension_ring = generic_extension_ring.create_specialization(cubic_equation_roots) cubic_equation_roots = [extension_ring(root) for root in cubic_equation_roots] verbose(('extension_ring %s set according to cubic_equation_roots %s' % (base_ring, cubic_equation_roots)), level=2) else: extension_ring = generic_extension_ring.as_splitting_algebra() cubic_equation_roots = [extension_ring(a), extension_ring(b), extension_ring(c)] verbose(('cubic roots %s and extension ring %s defined' % (cubic_equation_roots, extension_ring)), level=2) (pa, pb, pc) = cubic_equation_roots if (base_ring == extension_ring): val_a = cubic_equation.substitute(h=pa) val_b = cubic_equation.substitute(h=pb) val_c = cubic_equation.substitute(h=pc) if ((val_a != 0) or (val_b != 0) or (val_c != 0)): raise ValueError('cubic equation does not vanish on cubic equation roots') im_base_gens = [((pa + pb) + pc), (((pa * pb) + (pa * pc)) + (pb * pc)), ((pa * pb) * pc)] base_ring_embedding = extension_ring.coerce_map_from(base_ring) def check_base_ring_embedding(base_ring_embedding): if (base_ring_embedding is None): return False try: ipu = base_ring_embedding(pu) ipv = base_ring_embedding(pv) ipw = base_ring_embedding(pw) if ([ipu, ipv, ipw] != im_base_gens): return False except (TypeError, ValueError): return False return True if check_base_ring_embedding(base_ring_embedding): verbose('base_ring_embedding defined via coercion', level=2) else: base_ring_embedding = extension_ring.convert_map_from(base_ring) if check_base_ring_embedding(base_ring_embedding): verbose('base_ring_embedding defined via conversion', level=2) else: try: if (base_ring.gens() == cubic_equation_parameters): base_ring_embedding = base_ring.hom(im_base_gens, codomain=extension_ring) except (TypeError, ValueError): base_ring_embedding = None if (base_ring_embedding is None): warn('Warning: no base_ring_embedding found') self._extension_ring = extension_ring self._base_ring_embedding = base_ring_embedding self._ring_of_definition_map = base_ring.convert_map_from(ring_of_definition) self._generic_extension_ring_map = extension_ring.convert_map_from(generic_extension_ring) self._cubic_equation_parameters = cubic_equation_parameters self._cubic_equation_roots = cubic_equation_roots from sage.algebras.group_algebra import GroupAlgebra self._cubic_braid_group_algebra = GroupAlgebra(self._cubic_braid_group, R=base_ring) self._braid_group_algebra = GroupAlgebra(self._braid_group, R=base_ring) db = self._database ns = min(self._nstrands, 4) self._basis_static = db.read(db.section.basis, nstrands=ns) if self._cubic_braid_group.is_finite(): from sage.categories.finite_dimensional_algebras_with_basis import FiniteDimensionalAlgebrasWithBasis category = FiniteDimensionalAlgebrasWithBasis(base_ring) else: from sage.categories.algebras_with_basis import AlgebrasWithBasis category = AlgebrasWithBasis(base_ring) CombinatorialFreeModule.__init__(self, base_ring, self._cubic_braid_group, prefix='', names=names, bracket=False, category=category) self._cubic_hecke_subalgebra = None self._mirror_image = None self._is_mirror = False self._base_ring_mirror = None self._gens_reg_repres_matrix = {} self._init_basis_extension() return def _repr_(self): '\n Return a string representation\n\n OUTPUT:\n\n String describing ``self``\n\n TESTS::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: CHA3 # indirect doctest\n Cubic Hecke algebra on 3 strands\n over Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n with cubic equation: h^3 - u*h^2 + v*h - w = 0\n ' s = 'Cubic Hecke algebra on %s strands over %s with cubic equation: %s = 0' return (s % (self._nstrands, self.base_ring(), self.cubic_equation())) def _element_constructor_(self, x): '\n Extensions to the element constructor of class :class:`CombinatorialFreeModule`.\n\n New functionalities are:\n\n - constructing element from a braid (group homomorphism)\n - constructing element from a braid giving in Tietze form\n - constructing element from an element of the braid group algebra\n (algebra homomorphism)\n - constructing element from an element of the cubic braid group\n algebra (module homomorphism)\n - constructing element from an element of an other cubic Hecke\n algebra over an other base ring or with less strands\n - constructing element from an element of the mirror image of\n ``self`` (see method mirror_image)\n\n INPUT:\n\n - ``x`` -- can be one of the following:\n\n * an instance of the element class of ``self`` (but possible\n to a different parent)\n * an instance of the element class of the braid group\n * an instance of the element class of the braid group algebra\n over the base ring of ``self``\n * an instance of the element class of the cubic braid group\n * an instance of the element class of the cubic braid group\n algebra over the base ring of ``self``\n * an instance of the element class of the mirror image of\n ``self``\n * a tuple representing a braid in Tietze form\n * any other object which works for the element constructor\n of :class:`CombinatorialFreeModule`\n\n EXAMPLES::\n\n sage: B2 = BraidGroup(2)\n sage: b, = B2.gens()\n sage: b2 = b**2\n sage: CB2 = CubicBraidGroup(2)\n sage: cb, = CB2.gens()\n sage: cb2 = cb**2\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2(b2)\n w*c^-1 + u*c + (-v)\n sage: CHA2(cb2)\n c^-1\n sage: CHA3 = algebras.CubicHecke(3)\n sage: B3 = CHA3.braid_group()\n sage: CB3 = CHA3.cubic_braid_group()\n sage: CB3GA = CHA3.cubic_braid_group_algebra()\n sage: braid = B3((1,2,2,-1,2,1,1,-1)); braid\n c0*c1^2*c0^-1*c1*c0\n sage: img_braid = CHA3(braid); img_braid\n u*w*(c0^-1*c1)^2 + u*v*c0*c1^-1*c0 + (-u^2*w)*c0^-1*c1*c0^-1\n + (-u*v)*c1*c0^-1*c1 + (-u*v*w+w^2)*c0^-1*c1^-1 + u^2*c0*c1*c0^-1*c1\n + (-u^2*v+u*w)*c0*c1^-1 + u^2*v*c1*c0^-1 + (u^2-v)*c1*c0\n + (-u^3)*c0*c1*c0^-1 + (u*v^2-v*w)*c1^-1\n sage: cbraid = CB3(braid); cbraid\n c0*c1^2*c0^-1*c1*c0\n sage: img_cbraid = CHA3(cbraid); img_cbraid\n c0^-1*c1^-1\n sage: img_cbraid_back = img_cbraid.cubic_braid_group_algebra_pre_image()\n sage: img_cbraid_back in CB3GA\n True\n sage: img_cbraid_back == CB3GA(cbraid)\n True\n ' braid_grp = self.braid_group() braid_grp_alg = self.braid_group_algebra() braid_img = self._braid_image cbraid_grp = self.cubic_braid_group() cbraid_grp_alg = self.cubic_braid_group_algebra() cbraid_img = self._cubic_braid_image base_ring = self.base_ring() ngens = self.ngens() params = self.cubic_equation_parameters() xb = x if (type(x) in (tuple, list)): x = tuple(x) result = self._tietze_to_finite_sub_basis_monomial(x) if (result is not None): verbose(('end from tuple %s: %s' % (x, result)), level=2) return result try: xb = braid_grp(x) except (TypeError, ValueError, NotImplementedError): pass if isinstance(xb, CubicHeckeElement): other_cha = xb.parent() other_base_ring = other_cha.base_ring() other_ngens = other_cha.ngens() other_params = other_cha.cubic_equation_parameters() if (other_base_ring != base_ring): if (other_ngens == ngens): xbv = xb.to_vector() img_xbv = vector([self.base_ring()(cf) for cf in xbv]) return self.from_vector(img_xbv) elif (other_ngens < ngens): sub_alg = self.cubic_hecke_subalgebra((other_ngens + 1)) return self(sub_alg(xb)) elif ((other_ngens < ngens) and (other_params == params)): cbraid_preimg = xb.cubic_braid_group_algebra_pre_image() other_cbga = other_cha.cubic_braid_group_algebra() def fc(ele): return cbraid_img(cbraid_grp(ele)) result = other_cbga._apply_module_morphism(cbraid_preimg, fc, codomain=self) verbose(('end from smaller cubic Hecke algebra %s: %s' % (xb, result)), level=2) return result elif (other_cha == self._mirror_image): result = other_cha.mirror_isomorphism(xb) verbose(('end from mirror image %s: %s' % (xb, result)), level=2) return result if (isinstance(xb, braid_grp_alg.element_class) and (xb in braid_grp_alg)): def fb(ele): return braid_img(ele) result = braid_grp_alg._apply_module_morphism(xb, fb, codomain=self) verbose(('end from braid_group algebra %s: %s' % (xb, result)), level=2) return result from sage.groups.braid import Braid if (isinstance(xb, Braid) and (xb.strands() == self._nstrands)): result = braid_img(xb) verbose(('end from braid_group %s: %s' % (xb, result)), level=2) return result if (isinstance(xb, cbraid_grp_alg.element_class) and (xb in cbraid_grp_alg)): result = cbraid_grp_alg._apply_module_morphism(xb, cbraid_img, codomain=self) verbose(('end from cubic braid_group algebra %s: %s' % (xb, result)), level=2) return result from sage.groups.cubic_braid import CubicBraidElement if (isinstance(xb, CubicBraidElement) and (xb.parent().strands() == self._nstrands)): result = cbraid_img(xb) verbose(('end from cubic braid_group %s: %s' % (xb, result)), level=2) return result result = CombinatorialFreeModule._element_constructor_(self, x) verbose(('end (default) %s: %s' % (xb, result)), level=2) return result def get_order(self): '\n Return an ordering of the basis of ``self``.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: len(CHA3.get_order())\n 24\n ' if (self._nstrands < 5): return self._order sub_alg = self.cubic_hecke_subalgebra() former_len_sub = len(sub_alg._order) sub_order = sub_alg.get_order() if (former_len_sub == len(sub_order)): if (len(self._order) == (former_len_sub + len(self._basis_extension))): return self._order cbg = self.cubic_braid_group() sub_order = [cbg(cb) for cb in sub_order] self._order = (sub_order + [cbg(tup) for tup in self._basis_extension]) return self._order def _order_key(self, x): "\n Return a key for `x` compatible with the term order.\n\n INPUT:\n\n - ``x`` -- indices of the basis of ``self``\n\n EXAMPLES::\n\n sage: A = CombinatorialFreeModule(QQ, ['x','y','a','b'])\n sage: A.set_order(['x', 'y', 'a', 'b'])\n sage: A._order_key('x')\n 0\n sage: A._order_key('y')\n 1\n sage: A._order_key('a')\n 2\n " try: return self._rank_basis(x) except AttributeError: from sage.combinat.ranker import rank_from_list self._rank_basis = rank_from_list(self._order) return self._rank_basis(x) def _dense_free_module(self, base_ring=None): '\n Return a dense free module with the same dimension as ``self``.\n\n This overwrites the corresponding method of :class:`CombinatorialFreeModule`.\n The only difference is, that the dimension is not the dimension of\n ``self`` but the dimension of the sub-module generated by the dynamically\n growing basis given by the :meth:`get_order`. In particular there is\n no difference if the number of strands is less than 5.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2._dense_free_module()\n Ambient free module of rank 3\n over the integral domain Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n ' if (base_ring is None): base_ring = self.base_ring() from sage.modules.free_module import FreeModule return FreeModule(base_ring, len(self.get_order())) def ngens(self): '\n The number of generators of the algebra.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2.ngens()\n 1\n ' return (self._nstrands - 1) def algebra_generators(self): '\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2.algebra_generators()\n Finite family {c: c}\n ' from sage.sets.family import Family return Family(self._cubic_braid_group.gens(), self.monomial) def gens(self): '\n Return the generators of ``self``.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2.gens()\n (c,)\n ' return tuple(self.algebra_generators()) def gen(self, i): '\n The ``i``-th generator of the algebra.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2.gen(0)\n c\n ' return self.gens()[i] def one_basis(self): '\n Return the index of the basis element for the identity element\n in the cubic braid group.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2.one_basis()\n 1\n ' return self.cubic_braid_group().one() def _an_element_(self): '\n Overwrite the original method from :mod:`~sage.combinat.free_module`\n to obtain a more interesting element for ``TestSuite``.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2.an_element() # indirect doctest\n v*c + ((-v*w+u)/w)\n ' n = (self.ngens() + 1) base_ring = self.base_ring() (u, v, w) = (base_ring(para) for para in self._cubic_equation_parameters) const = (((u * (~ w)) - v) * self.one()) gens = self.gens() first_gens = [gen for gen in gens if (gens.index(gen) < 3)] if (n == 2): (c1,) = first_gens return (const + (v * c1)) elif (n == 3): (c1, c2) = first_gens return (((const + (v * c1)) - ((w * c1) * (~ c2))) + (u * c2)) else: (c1, c2, c3) = first_gens return (((const + ((v * c1) * (~ c3))) - ((w * c1) * (~ c2))) + ((u * c3) * c2)) @cached_method def chevie(self): '\n Return the ``GAP3``-``CHEVIE`` realization of the corresponding\n cyclotomic Hecke algebra in the finite-dimensional case.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3) # optional gap3\n sage: CHA3.chevie() # optional gap3\n Hecke(G4,[[a,b,c]])\n ' from sage.combinat.root_system.reflection_group_real import is_chevie_available if (not is_chevie_available()): raise NotImplementedError('this functionality needs GAP3 with package CHEVIE') n = self._nstrands if (n == 3): st_number = 4 elif (n == 4): st_number = 25 elif (n == 5): st_number = 32 else: raise NotImplementedError("CHEVIE version doesn't exist for this cubic Hecke algebra") gap3_function_str = 'function(st_number, na, nb,nc)\n local a, b, c, # embedded Indeterminates\n ReflGroup, # Reflection group\n HeckeAlg; # Hecke algebra\n\n a := Mvp(na); b := Mvp(nb); c := Mvp(nc);\n ReflGroup := ComplexReflectionGroup(st_number);\n HeckeAlg := Hecke(ReflGroup, [[a, b, c]] );\n return HeckeAlg;\n end;' from sage.interfaces.gap3 import gap3 gap3_function = gap3(gap3_function_str) (na, nb, nc) = (('"%s"' % indet) for indet in self.extension_ring(generic=True).variable_names()) return gap3_function(st_number, na, nb, nc) @cached_method def product_on_basis(self, g1, g2): '\n Return product on basis elements indexed by ``g1`` and ``g2``.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: g = CHA3.basis().keys().an_element(); g\n c0*c1\n sage: CHA3.product_on_basis(g, ~g)\n 1\n sage: CHA3.product_on_basis(g, g)\n w*c0^-1*c1*c0 + (-v)*c1*c0 + u*c0*c1*c0\n ' if (g1 == g1.parent().one()): return self.monomial(g2) if (g2 == g2.parent().one()): return self.monomial(g1) g1 = self.monomial(g1) g2 = self.monomial(g2) result = None g1_Tietze = g1.Tietze() g2_Tietze = g2.Tietze() verbose(('Tietze established (%s, %s)' % (g1_Tietze, g2_Tietze)), level=2) braid_group = self.braid_group() braid_product = braid_group((g1_Tietze + g2_Tietze)) result = self._braid_image(braid_product) return result def _basis_tietze(self): '\n Return the complete finite sub basis as list of Tietze tuples\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2._basis_tietze()\n [[], [1], [-1]]\n ' if (self._nstrands > 4): self_sub = self.cubic_hecke_subalgebra() result_list = (self_sub._basis_tietze() + self._basis_extension) else: result_list = self._basis_static return result_list def _tietze_to_finite_sub_basis_monomial(self, tietze_tup): '\n Return the monomial corresponding to a Tietze tuple\n if it is in the finite sub basis, otherwise return ``None``.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2._tietze_to_finite_sub_basis_monomial([-1])\n c^-1\n sage: CHA2._tietze_to_finite_sub_basis_monomial([-2]) is None\n True\n ' tietze_list = list(tietze_tup) in_basis = False if (tietze_list in self._basis_tietze()): in_basis = True elif (self._nstrands > 4): fsb_dict = self._finite_sub_basis_tuples if (tietze_list in list(fsb_dict.values())): in_basis = True elif (self.cubic_hecke_subalgebra()._tietze_to_finite_sub_basis_monomial(tietze_tup) is not None): in_basis = True if in_basis: B = self.basis() cb = self.cubic_braid_group()(tietze_tup) return B[cb] return None @cached_method def _create_matrix_list_for_one(self, representation_type): '\n Return the matrix list for the given representation type\n for ``self.one()``.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2._create_matrix_list_for_one(CHA2.repr_type.SplitIrredMarin)\n [[1], [1], [1]]\n sage: CHA2._create_matrix_list_for_one(CHA2.repr_type.RegularLeft)\n [\n [1 0 0]\n [0 1 0]\n [0 0 1]\n ]\n ' n = self._nstrands if representation_type.is_split(): gen_base_ring = self.extension_ring(generic=True) rep_ind = [rep.internal_index() for rep in AbsIrreducibeRep if (rep.number_gens() == (n - 1))] rep_dim = [rep.dimension() for rep in AbsIrreducibeRep if (rep.number_gens() == (n - 1))] dim_sort = [rep_dim[rep_ind.index(i)] for i in range(len(rep_ind))] matrix_list = [MatrixSpace(gen_base_ring, dim_sort[i]).one() for i in range(len(rep_ind))] else: gen_base_ring = self.base_ring(generic=True) matrix_list = [MatrixSpace(gen_base_ring, self.dimension()).one()] return matrix_list @cached_method def _fetch_matrix_list_from_chevie(self, number): '\n This method reads irreducible representation of the cubic Hecke algebra\n via the *GAP3* interface from *CHEVIE*.\n\n INPUT:\n\n - ``number`` -- integer; number of the representation according to\n *CHEVIE*\n\n OUTPUT:\n\n A list of representing matrices over the generic extension ring, one\n matrix for each generators.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3) # optional gap3\n sage: CHA3._fetch_matrix_list_from_chevie(5) # optional gap3\n [\n [ a 0] [c c]\n [-a c], [0 a]\n ]\n ' GER = self.extension_ring(generic=True) gap3_result = self.chevie().Representations(number) from sage.matrix.constructor import matrix matrix_list_gens = [matrix(GER, mat_gap) for mat_gap in gap3_result] for m in matrix_list_gens: m.set_immutable() return matrix_list_gens def _test_ring_constructions(self, **options): '\n Method called by :class:`TestSuite`.\n\n The following is checked:\n\n - construction of base_ring and extension ring\n - construction of maps between generic base and extension ring and\n the user defined rings\n - application of the ring homomorphisms\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2, cubic_equation_roots=(3,7,11))\n sage: CHA2._test_ring_constructions()\n ' br = self.base_ring() er = self.extension_ring() (A, B, C) = self.cubic_equation_roots() (a, b, c) = self.cubic_equation_roots(generic=True) (U, V, W) = self.cubic_equation_parameters() (u, v, w) = self.cubic_equation_parameters(generic=True) eleB = ((U * V) - (W ** 2)) eleBgen = ((u * v) - (w ** 2)) eleE = ((A * B) - (C ** 2)) eleEgen = ((a * b) - (c ** 2)) mbr = self._ring_of_definition_map mer = self._generic_extension_ring_map bri = self._base_ring_embedding eleBgenEmb = 0 eleEgenEmb = 0 eleBembE = 0 try: eleBgenEmb = br(eleBgen) except (TypeError, ValueError, NotImplementedError): verbose('generic base ring map not registered') try: eleBgenEmb = mbr(eleBgen) except (TypeError, ValueError, NotImplementedError): raise RuntimeError(('fatal: generic base ring map %s does not work' % mbr)) try: eleEgenEmb = er(eleEgen) except (TypeError, ValueError, NotImplementedError): verbose('generic extension ring map not registered') try: eleEgenEmb = mer(eleEgen) except (TypeError, ValueError, NotImplementedError): raise RuntimeError(('fatal: generic extension ring map %s does not work' % mer)) try: eleBembE = er(eleB) except (TypeError, ValueError, NotImplementedError): verbose('base ring embedding map not registered') try: eleBembE = bri(eleB) except (TypeError, ValueError, NotImplementedError): raise RuntimeError(('fatal: base ring embedding %s does not work' % bri)) test_eleBgenEmb = self._tester(**options) test_eleBgenEmb.assertEqual(eleBgenEmb, eleB) test_eleEgenEmb = self._tester(**options) test_eleEgenEmb.assertEqual(eleEgenEmb, eleE) test_eleBembE = self._tester(**options) test_eleBembE.assertEqual(eleBembE, eleB) def _test_matrix_constructions(self, **options): '\n Test that the matrix constructions are valid.\n\n The following is checked:\n\n - construction of matrices of the following types:\n\n * ``RepresentationType.SplitIrredChevie``\n * ``RepresentationType.SplitIrredMarin``\n * ``RepresentationType.RegularLeft``\n\n - multiplication of matrices and compare with the matrix of the\n corresponding product of elements\n - construction of maps between generic base and extension ring and\n the user defined rings\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2, cubic_equation_roots=(3,7,11))\n sage: CHA2._test_matrix_constructions()\n ' if (self.ngens() > 4): return gens = self.gens() b1 = gens[0] b2 = self.an_element() b12 = (b1 * b2) verbose(('b12 %s' % b12)) def check_matrix(representation_type): m1 = b1.matrix(representation_type=representation_type) m2 = b2.matrix(representation_type=representation_type) m12mult = (m1 * m2) m12mat = b12.matrix(representation_type=representation_type) test_matrix = self._tester(**options) test_matrix.assertEqual(m12mult, m12mat) from sage.combinat.root_system.reflection_group_real import is_chevie_available if is_chevie_available(): check_matrix(RepresentationType.SplitIrredChevie) if (self.ngens() < 3): check_matrix(RepresentationType.SplitIrredMarin) elif (self.ngens() < 4): check_matrix(RepresentationType.SplitIrredMarin) if (self.ngens() < 3): check_matrix(RepresentationType.RegularLeft) return def _init_basis_extension(self): '\n Return the extension of the basis for more than 4 strands hold\n in file cache.\n\n The basis elements from the file are added to the elements of\n the Marin basis.\n\n EXAMPLES::\n\n sage: # optional - database_cubic_hecke\n sage: CHA5 = algebras.CubicHecke(5)\n sage: fc = CHA5._filecache\n sage: be = fc.section.basis_extensions\n sage: CHA5.reset_filecache(be)\n sage: fc.read(be)\n [[4], [-4]]\n sage: ele = CHA5.an_element()\n sage: CHA5.inject_variables()\n Defining c0, c1, c2, c3\n sage: ele2 = ele * c3\n sage: bex = fc.read(be)\n sage: bex.sort(); bex\n [[-4], [1, -3, 4], [1, -2, 4], [3, 2, 4], [4]]\n ' self._basis_extension = [] tietze_list = self._basis_tietze() cbg = self._cubic_braid_group self._finite_sub_basis_tuples = {} order_list = [cbg(tup) for tup in tietze_list] self._order = order_list verbose(('finite sub basis length: %s' % len(order_list)), level=2) if (self._nstrands < 5): return fc = self._filecache former_bas_ext = fc.read(fc.section.basis_extensions) cub_braid_group = self.cubic_braid_group() if (not former_bas_ext): gens = cub_braid_group.gens() last_gen = gens[(len(gens) - 1)] self._cubic_braid_image(last_gen, check=False) self._cubic_braid_image((~ last_gen), check=False) self._filecache.update_basis_extensions(self._basis_extension) return for bas_Tietze in former_bas_ext: cub_braid = cub_braid_group(bas_Tietze) self._cubic_braid_image(cub_braid, check=False) verbose(('finite sub basis (extended) length: %s' % len(self.get_order())), level=2) self._filecache.update_basis_extensions(self._basis_extension) return def _braid_image_from_filecache(self, braid): '\n Return the image of the given braid in ``self`` from file cache (if\n contained).\n\n INPUT:\n\n - ``braid`` -- braid as instance of the braid group of ``self``\n\n OUTPUT:\n\n Image of braid as element of ``self``. ``None`` if the product has\n not been stored.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: b1, b2 = CHA3.braid_group().gens(); br = ~b2*b1*~b2\n sage: CHA3._braid_image_from_filecache(br)\n 1/w*c0*c1*c0^-1*c1 + v/w*c1^-1*c0 + ((-u)/w)*c0*c1*c0^-1\n sage: F = CHA3.base_ring().fraction_field()\n sage: par = tuple([F(p) for p in CHA3.cubic_equation_parameters()])\n sage: CHA3F = algebras.CubicHecke(3, cubic_equation_parameters=par)\n sage: CHA3F._braid_image_from_filecache(br)\n 1/w*c0*c1*c0^-1*c1 + v/w*c1^-1*c0 + ((-u)/w)*c0*c1*c0^-1\n sage: section = CHA3.filecache_section().braid_images\n sage: CHA3.reset_filecache(section)\n sage: CHA3._braid_image_from_filecache(br)\n ' base_ring = self.base_ring() gen_base_ring = self.base_ring(generic=True) result_vect = self._filecache.read_braid_image(braid.Tietze(), gen_base_ring) if (result_vect is not None): if (gen_base_ring != base_ring): base_map = self._ring_of_definition_map result_vect = vector(base_ring, [base_map(cf) for cf in result_vect]) return self.from_vector(result_vect) return None def _braid_image_to_filecache(self, braid_tietze, braid_image_vect): '\n Write the given braid image of to file cache.\n\n INPUT:\n\n - ``braid_tietze`` -- braid in Tietze form\n - ``braid_image_vect`` -- image of the given braid in ``self`` in vector\n representation\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: br, = CHA2.braid_group().gens(); br2 = br**2\n sage: section = CHA2.filecache_section().braid_images\n sage: CHA2.is_filecache_empty(section) # note: 2-strand images are not automatically cached in file system\n True\n sage: CHA2._braid_image_to_filecache(br2.Tietze(), CHA2(br2).to_vector())\n sage: CHA2._braid_image_from_filecache(br2)\n w*c^-1 + u*c + (-v)\n sage: CHA2.reset_filecache(CHA2.filecache_section().braid_images)\n sage: CHA2._braid_image_from_filecache(br2) == None\n True\n ' if (self.base_ring() != self.base_ring(generic=True)): return self._filecache.write_braid_image(braid_tietze, braid_image_vect) return @cached_method def _braid_image(self, braid): '\n Return the image of the given braid in ``self``.\n\n INPUT:\n\n - ``braid`` -- :class:`~sage.groups.braid.Braid` whose image\n in ``self`` should be calculated\n\n OUTPUT:\n\n An instance of the element class of ``self``.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: br, = CHA2.braid_group().gens(); br2 = br**2\n sage: CHA2._braid_image(br2)\n w*c^-1 + u*c + (-v)\n ' (coeffs, braids) = self._reduce_all_gen_powers(braid.Tietze()) result = self.zero() for i in range(len(coeffs)): braid_image = self._braid_image_from_reduced_powers(braids[i]) result += (coeffs[i] * braid_image) return result @cached_method def _braid_image_from_reduced_powers(self, braid_tietze): '\n Return the image of a braid in ``self`` assuming that no successive\n repetitions occur in the Tietze form of the braid.\n\n INPUT:\n\n - ``braid_tietze`` -- tuple representing the Braid whose image in\n ``self`` should be computed; it is assumed that no successive\n repetitions occur among the entries (i.e. ``(1, 1)`` is not allowed\n but ``(1, -2, 1)`` is)\n\n OUTPUT:\n\n The image of the braid as an element of ``self``.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: CHA3._braid_image_from_reduced_powers((1, -2, 1))\n c0*c1^-1*c0\n sage: CHA3._braid_image_from_reduced_powers((1, -2, 1, 2))\n w*c0^-1*c1*c0^-1 + (-v)*c1*c0^-1 + u*c0*c1*c0^-1\n ' n = self.ngens() braid_list = list(braid_tietze) len_braid = len(braid_list) if (n == 1): if (len_braid == 0): return self.one() k = (braid_tietze[0] * len_braid) result_vect = self._reduce_gen_power(k) result = self.from_vector(result_vect) return result (result, word_decomposition) = self._braid_image_from_former_calculations(braid_tietze) if (word_decomposition is None): return result if ((n > 3) and ((n in braid_tietze) or ((- n) in braid_tietze))): return self._braid_image_by_basis_extension(braid_tietze) (word_left, word_result, word_right) = word_decomposition result_vect = None if (word_left is not None): vect = result.to_vector() braid_preimage = tuple(word_result) result_vect = self._mult_by_regular_rep(vect, tuple(word_left), RepresentationType.RegularLeft, braid_preimage) if (word_right is not None): if (result_vect is not None): vect = result_vect braid_preimage = tuple((word_left + word_result)) else: vect = result.to_vector() braid_preimage = tuple(word_result) result_vect = self._mult_by_regular_rep(vect, tuple(word_right), RepresentationType.RegularRight, braid_preimage) result = self.from_vector(result_vect) return result def _braid_image_from_former_calculations(self, braid_tietze): '\n Return the image of a braid in ``self`` as far as this can be done by\n use of former calculations and is sure not to go into an endless\n recursion, that is\n\n - using the cubic Hecke sub-algebra on one strand less\n - using the file cache.\n\n If the image can not be calculated from former registered results this\n method returns None. Therefore, it is just intended to be used as as\n step in the complete calculation.\n\n INPUT:\n\n - ``braid_tietze`` -- tuple representing the braid whose image in\n ``self`` should be computed; he generator exponents in the braid\n word are assumed to be ``1`` or ``-1``\n\n OUTPUT:\n\n A pair (image, basis_factors) where result is an element of ``self``\n representing the image of the input if calculation was possible and\n ``None`` else-wise. If ``image == None`` the output basis_factors is\n given as a list of basis element whose product equals the input.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: CHA3._braid_image_from_former_calculations((1, -2, 1))\n (c0*c1^-1*c0, None)\n sage: CHA3._braid_image_from_former_calculations((1, -2, 1, 2))\n (c0*c1^-1*c0, ([], [1, -2, 1], [2]))\n ' braid_list = list(braid_tietze) len_braid = len(braid_list) result = None n = self.ngens() result = self._tietze_to_finite_sub_basis_monomial(braid_tietze) if (result is not None): return (result, None) sub_alg = self.cubic_hecke_subalgebra() if ((n not in braid_list) and ((- n) not in braid_list)): result = self(sub_alg(braid_tietze)) verbose(('end (%s): %s in smaller algebra' % (braid_list, result)), level=2) return (result, None) braid_group = self.braid_group() braid = braid_group(braid_tietze) result = self._braid_image_from_filecache(braid) if (result is not None): verbose(('end from file cache (%s)' % list(braid_tietze)), level=2) return (result, None) braid_list_red_left = [braid_tietze[j] for j in range(1, len_braid)] braid_list_red_right = [braid_tietze[j] for j in range((len_braid - 1))] (result_left, word_decomp_left) = self._braid_image_from_former_calculations(tuple(braid_list_red_left)) (result_right, word_decomp_right) = self._braid_image_from_former_calculations(tuple(braid_list_red_right)) if (word_decomp_left is None): return (result_left, ([braid_tietze[0]], braid_list_red_left, [])) if (word_decomp_right is None): return (result_right, ([], braid_list_red_right, [braid_tietze[(len_braid - 1)]])) (word_decomp_left_left, word_decomp_left_result, word_decomp_left_right) = word_decomp_left (word_decomp_right_left, word_decomp_right_result, word_decomp_right_right) = word_decomp_right if (len(word_decomp_left_result) >= len(word_decomp_right_result)): return (result_left, (([braid_tietze[0]] + word_decomp_left_left), word_decomp_left_result, word_decomp_left_right)) return (result_right, (word_decomp_right_left, word_decomp_right_result, (word_decomp_right_right + [braid_tietze[(len_braid - 1)]]))) @cached_method def _braid_image_by_basis_extension(self, braid_tietze): "\n Return the given braid as a new basis element of ``self`` expanding the\n incomplete order (which is just a part of the whole basis) in the case\n of more than 4 strands.\n\n INPUT:\n\n - ``braid_tietze`` -- tuple representing the braid whose image in\n ``self`` should be computed; he generator exponents in the braid\n word are assumed to be ``1`` or ``-1``\n\n OUTPUT:\n\n An instance of the element class of ``self``.\n\n EXAMPLES::\n\n sage: # optional - database_cubic_hecke\n sage: CHA5 = algebras.CubicHecke(5)\n sage: be = CHA5.filecache_section().basis_extensions\n sage: CHA5.reset_filecache(be)\n sage: CHA5._basis_extension\n [[4], [-4]]\n sage: CHA5._braid_image_by_basis_extension((4,1))\n c3*c0\n sage: CHA5._basis_extension\n [[4], [-4], [4, 1]]\n\n case where the braid already has a corresponding basis element::\n\n sage: CHA5._braid_image_by_basis_extension((1,)) # optional - database_cubic_hecke\n c0\n sage: CHA5._basis_extension # optional - database_cubic_hecke\n [[4], [-4], [4, 1]]\n\n case where the braid doesn't have corresponding basis element but depends\n on them::\n\n sage: CHA5._braid_image_by_basis_extension((1,1)) # optional - database_cubic_hecke\n Traceback (most recent call last):\n ...\n NotImplementedError: no algorithm available to calculate braid image of (1, 1)\n " cubic_braid = self._cubic_braid_group(braid_tietze) tup = self._cubic_braid_basis_tuple(cubic_braid) if (tup is not None): bgrp = self.braid_group() if (bgrp(braid_tietze) != bgrp(tup)): raise NotImplementedError(('no algorithm available to calculate braid image of %s' % str(braid_tietze))) B = self.basis() verbose(('braid-image %s in Basis' % str(braid_tietze)), level=2) return self.monomial(B[cubic_braid]) return self._cubic_braid_append_to_basis(cubic_braid) @cached_method def _reduce_all_gen_powers(self, braid_tietze): '\n Return a linear combination of braids that have no higher powers in the\n braid generators having the same image in ``self`` than the given braid.\n\n This linear combination is returned as a pair of lists of braids and\n corresponding coefficients.\n\n INPUT:\n\n - ``braid_tietze`` -- tuple representing the braid whose powers should\n be reduced given in Tietze form\n\n OUTPUT:\n\n A pair of two lists: ``coeffs``, ``braids``. The fist one contains the\n coefficients corresponding to the braids in Tietze form from the second\n list of braids.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: CHA3._reduce_all_gen_powers((1, 1, -2, -2))\n ([u*v/w, (-v)/w, (-v^2)/w, (-u^2)/w, u/w, u*v/w, -u, 1, v],\n [(), (2,), (-2,), (1,), (1, 2), (1, -2), (-1,), (-1, 2), (-1, -2)])\n ' braid_list = list(braid_tietze) len_braid = len(braid_list) power = 0 pos = 0 for i in range((len_braid - 1)): if (braid_list[i] != braid_list[(i + 1)]): continue pos = i for power in range(1, ((len_braid - pos) + 1)): if ((pos + power) == len_braid): break if (braid_list[pos] != braid_list[(pos + power)]): break break if (power == 0): verbose(('end (%s) no powers' % braid_list), level=2) return ([self.base_ring().one()], [braid_tietze]) val = braid_list[pos] if (val > 0): gen_ind = val exp = power else: gen_ind = (- val) exp = (- power) braid_list_start = [braid_list[i] for i in range(pos)] braid_list_end = [braid_list[i] for i in range((pos + power), len_braid)] tuple_one = tuple((braid_list_start + braid_list_end)) tuple_gen = tuple(((braid_list_start + [gen_ind]) + braid_list_end)) tuple_gen_inv = tuple(((braid_list_start + [(- gen_ind)]) + braid_list_end)) braid_group = self.braid_group() braid_one = braid_group(tuple_one) braid_gen = braid_group(tuple_gen) braid_gen_inv = braid_group(tuple_gen_inv) (one_coeffs, one_braids) = self._reduce_all_gen_powers(braid_one.Tietze()) (gen_coeffs, gen_braids) = self._reduce_all_gen_powers(braid_gen.Tietze()) (gen_inv_coeffs, gen_inv_braids) = self._reduce_all_gen_powers(braid_gen_inv.Tietze()) (cf_one, cf_gen, cf_gen_inv) = self._reduce_gen_power(exp) one_coeffs = [(cf * cf_one) for cf in one_coeffs] gen_coeffs = [(cf * cf_gen) for cf in gen_coeffs] gen_inv_coeffs = [(cf * cf_gen_inv) for cf in gen_inv_coeffs] return (((one_coeffs + gen_coeffs) + gen_inv_coeffs), ((one_braids + gen_braids) + gen_inv_braids)) @cached_method def _reduce_gen_power(self, k): '\n Return the `k`-th power on an arbitrary generator,\n for example `c_0^k`.\n\n INPUT:\n\n - ``k`` -- integer giving the power\n\n OUTPUT:\n\n A list ``[coeff_one, coeff_gen, coeff_gen_inverse]`` of the three\n coefficients of the generators power in the span of the generator.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2._reduce_gen_power(5)\n (-u^3*v + 2*u*v^2 + u^2*w - 2*v*w, u^4 - 3*u^2*v\n + v^2 + 2*u*w, u^3*w - 2*u*v*w + w^2)\n ' n = self.ngens() if (n > 1): sub_alg = self.cubic_hecke_subalgebra() return sub_alg._reduce_gen_power(k) if (k == 0): result_ele = self.one() result = result_ele.to_vector() elif (abs(k) == 1): result_ele = self._tietze_to_finite_sub_basis_monomial((k,)) result = result_ele.to_vector() else: if (k < 0): right_vect = self._reduce_gen_power((k + 1)) genTietze = ((- 1),) else: right_vect = self._reduce_gen_power((k - 1)) genTietze = (1,) result = self._mult_by_regular_rep(right_vect, genTietze, RepresentationType.RegularLeft) return result @cached_method def _mult_by_regular_rep(self, vect, gen_tuple, representation_type, braid_preimage=None): '\n Return the product of an`element of ``self`` given as a coefficient\n vector with a sequence (tuple) of generators (that is a braid word)\n using regular representation matrices.\n\n The multiplication will be performed form left or right according\n to the given ``representation_type``.\n\n INPUT:\n\n - ``vect`` -- element of ``self`` in vector form (obtained by\n :meth:`to_vector`)\n - ``gen_tuple`` -- list of generators (that is a braid in Tietze form)\n which operates on ``vect``\n - ``representation_type`` -- instance of :class:`RepresentationType`\n (one of `RegularLeft` or `RegularRight`)\n - ``braid_preimage`` -- (optional) a word representing a braid whose\n image is vect (if it exist). This is used to record intermediate\n results to the dynamic library\n\n OUTPUT:\n\n The coefficient vector resulting after applying the multiplication of all\n matrices corresponding to the generators from gen_tuple.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: CHA3.inject_variables()\n Defining c0, c1\n sage: repr_type = CHA3.repr_type.RegularRight\n sage: CHA3._mult_by_regular_rep(c0.to_vector(), (1, -2, -2), repr_type)\n (u*v/w, (-u^2)/w, -u, (-v)/w, (-v^2)/w, u/w, u*v/w, 1, v,\n 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)\n ' verbose(('multiply %s (pre-image %s) by %s using %s' % (vect, braid_preimage, gen_tuple, representation_type)), level=2) m = len(gen_tuple) braid_list = None if braid_preimage: braid_list = list(braid_preimage) result = vect for i in range(m): verbose(('multiply image of %s with position %s' % (braid_list, i)), level=2) if (representation_type == RepresentationType.RegularLeft): gen_ind = gen_tuple[((m - i) - 1)] if braid_list: braid_list = ([gen_ind] + braid_list) else: gen_ind = gen_tuple[i] if braid_list: braid_list = (braid_list + [gen_ind]) if ((gen_ind, representation_type) in list(self._gens_reg_repres_matrix.keys())): mat = self._gens_reg_repres_matrix[(gen_ind, representation_type)] else: if (gen_ind > 0): gen = self.gen((gen_ind - 1)) mat = gen.matrix(representation_type=representation_type) else: gen = (self.gen(((- gen_ind) - 1)) ** (- 1)) mat = gen.matrix(representation_type=representation_type) self._gens_reg_repres_matrix[(gen_ind, representation_type)] = mat result = (mat * result) if braid_list: verbose(('save image of %s to file cache' % braid_list), level=2) self._braid_image_to_filecache(tuple(braid_list), result) verbose(('multiply %s by %s using %s result %s' % (vect, gen_tuple, representation_type, result)), level=2) return result def _cubic_braid_append_to_basis(self, cubic_braid): '\n Append the given cubic braid to the finite sub basis which is used for\n calculation of products and representation matrices.\n\n This only makes sense if the ``cubic_braid`` is not in this finite\n sub-basis, before. This can happen if the number of strands is more\n than 4.\n\n INPUT:\n\n - ``cubic_braid`` -- :class:`~sage.groups.cubic_braid.CubicBraid`\n whose image in ``self`` should be appended\n\n OUTPUT:\n\n The new monomial of ``self``.\n\n EXAMPLES::\n\n sage: # optional - database_cubic_hecke\n sage: CHA5 = algebras.CubicHecke(5)\n sage: be = CHA5.filecache_section().basis_extensions\n sage: CHA5.reset_filecache(be)\n sage: CHA5._basis_extension\n [[4], [-4]]\n sage: CBG = CHA5.cubic_braid_group()\n sage: CHA5._cubic_braid_append_to_basis(CBG((4,1)))\n c3*c0\n sage: CHA5._basis_extension\n [[4], [-4], [4, 1]]\n\n ' cbTietze = list(cubic_braid.Tietze()) order = self.get_order() next_index = len(order) self._basis_extension.append(cbTietze) try: self._rank_basis.update({cubic_braid: next_index}) except AttributeError: pass order.append(cubic_braid) monomial = self.monomial(cubic_braid) self._finite_sub_basis_tuples.update({cubic_braid: cbTietze}) verbose(('registering new basis element: %s (par %s ind %s)' % (cubic_braid, cubic_braid.parent(), next_index)), level=2) self._filecache.update_basis_extensions(self._basis_extension) return monomial def _cubic_braid_basis_tuple(self, cubic_braid): '\n Return the Tietze tuple that represents the given cubic_braid in the\n basis of ``self``.\n\n In the case ``self`` has more than 4 strands it may happen that the\n given cubic braid is not contained in the finite subbasis, so far.\n In this case it is automatically added to it.\n\n INPUT:\n\n - ``cubic_braid`` -- :class:`~sage.groups.cubic_braid.CubicBraid`\n\n OUTPUT:\n\n A tuple from the basis representing the cubic braid.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CBG = CHA2.cubic_braid_group()\n sage: CHA2._cubic_braid_basis_tuple(CBG((1, 1)))\n (-1,)\n ' tietze_list = self._basis_tietze() cubic_braid_tietze = cubic_braid.Tietze() if (list(cubic_braid_tietze) in tietze_list): verbose(('cubic_braid_tietze: %s in basis' % str(cubic_braid_tietze)), level=2) return cubic_braid_tietze elif (cubic_braid in self._finite_sub_basis_tuples.keys()): verbose(('cubic_braid: %s in finite_sub_basis' % cubic_braid), level=2) return self._finite_sub_basis_tuples[cubic_braid] for tup in tietze_list: cb_tup = self.cubic_braid_group()(tup) if (cubic_braid == cb_tup): self._finite_sub_basis_tuples.update({cb_tup: tup}) verbose(('cubic_braid: %s added to finite_sub_basis with tuple %s' % (cubic_braid, tup)), level=2) return tuple(tup) return None def _cubic_braid_image(self, cubic_braid, check=True): '\n Return the given cubic braid as monomial of ``self``, that is the image\n under the map onto the basis.\n\n If the number of strands is larger than 4, the corresponding basis\n element may not be contained in the order of ``self``. In this\n case it will be appended here.\n\n INPUT:\n\n - ``cubic_braid`` -- :class:`~sage.groups.cubic_braid.CubicBraid`\n whose image in ``self`` should be returned\n - ``check`` -- boolean (default: ``True``); check if the given cubic\n braid is already registered in the finite sub basis; if set to\n ``False`` duplicate entries can occur\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CBG = CHA2.cubic_braid_group()\n sage: CHA2._cubic_braid_image(CBG((1,1)))\n c^-1\n ' if check: tup = self._cubic_braid_basis_tuple(cubic_braid) if (tup is not None): return self._tietze_to_finite_sub_basis_monomial(tup) return self._cubic_braid_append_to_basis(cubic_braid) def _extend_braid_automorphism(self, element, braid_automorphism): '\n Return the image of element under the extension of the given braid group\n automorphism to ``self``. It is assumed that the given\n ``braid_automorphism`` factors through ``self``.\n\n INPUT:\n\n - ``element`` -- an element class of ``self``\n - ``braid_automorphism`` -- braid group automorphism factoring through\n ``self``\n\n OUTPUT:\n\n Element class of ``self`` representing the image of element\n under the extension of the given braid group automorphism.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: br, = CHA2.gens()\n sage: CHA2.mirror_isomorphism(br) # indirect doctest\n c^-1\n ' result = self.zero() for braid in element.support(): autom_braid = braid_automorphism(braid) img_braid = self._braid_image_from_reduced_powers(autom_braid.Tietze()) result += (element[braid] * img_braid) return result def _markov_trace_module(self, extended=False, field_embedding=False): '\n Return the module that contains the formal Markov trace as elements.\n\n INPUT:\n\n - ``extended`` -- boolean (default: ``False``); if set to ``True`` the\n base ring of the module is the Markov trace version of the generic\n extension ring of ``self``.\n\n - ``field_embedding`` -- boolean (default: ``False``); if set to ``True`\n the base ring of the module is the smallest field containing the\n generic extension ring of ``self``. The keyword is meaningless if\n ``extended=False``.\n\n OUTPUT:\n\n A :class:`~sage.combinat.free_module.CombinatorialFreeModule`.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2._markov_trace_module()\n Free module generated by {U1, U2}\n over Multivariate Polynomial Ring in u, v, w, s\n over Integer Ring localized at (s, w, v, u)\n\n sage: CHA2._markov_trace_module(extended=True)\n Free module generated by {U1, U2}\n over Multivariate Laurent Polynomial Ring in a, b, c, s\n over Splitting Algebra of x^2 + x + 1 with roots [e3, -e3 - 1]\n over Integer Ring\n\n sage: CHA2._markov_trace_module(extended=True, field_embedding=True)\n Free module generated by {U1, U2}\n over Fraction Field of Multivariate Polynomial Ring in a, b, c, s\n over Cyclotomic Field of order 3 and degree 2\n ' from sage.modules.free_module import FreeModule from sage.databases.cubic_hecke_db import MarkovTraceModuleBasis basis = [b for b in MarkovTraceModuleBasis if (b.strands() <= self._nstrands)] BRM = self.base_ring(generic=True).markov_trace_version() if extended: BRM = BRM.extension_ring() if field_embedding: emb = BRM.field_embedding() BRM = emb.codomain() return FreeModule(BRM, basis) @cached_method def _markov_trace_coeffs(self): '\n Return a list of formal Markov traces of the basis elements of ``self``.\n\n OUTPUT:\n\n A list of elements of the Markov trace module (over the Markov trace\n version of the generic base ring). Each entry of the list corresponds\n to the according basis element of ``self``.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2._markov_trace_coeffs()\n [B[U2], s*B[U1], 1/s*B[U1]]\n sage: M = _[0].parent(); M\n Free module generated by {U1, U2}\n over Multivariate Polynomial Ring in u, v, w, s\n over Integer Ring localized at (s, w, v, u)\n ' M = self._markov_trace_module() Mbas = M.basis().keys() db = self._database sec = db.section.markov_tr_cfs cfs = db.read(sec, variables=M.base_ring().gens(), nstrands=self._nstrands) d = self.dimension() return [sum(((cfs[bas_ele][i] * M(bas_ele)) for bas_ele in Mbas)) for i in range(d)] def filecache_section(self): "\n Return the ``enum`` to select a section in the file cache.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: list(CHA2.filecache_section())\n [<section.matrix_representations: 'matrix_representations'>,\n <section.braid_images: 'braid_images'>,\n <section.basis_extensions: 'basis_extensions'>,\n <section.markov_trace: 'markov_trace'>]\n " return self._filecache.section def is_filecache_empty(self, section=None): '\n Return ``True`` if the file cache of the given ``section`` is empty.\n If no ``section`` is given the answer is given for the complete\n file cache.\n\n INPUT:\n\n - ``section`` -- (default: all sections) an element of enum\n :class:`~sage.databases.cubic_hecke_db.CubicHeckeFileCache.section`\n that can be selected using :meth:`filecache_section`\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2.is_filecache_empty()\n False\n ' return self._filecache.is_empty(section=section) def reset_filecache(self, section=None, commit=True): '\n Reset the file cache of the given ``section`` resp. the complete\n file cache if no ``section`` is given.\n\n INPUT:\n\n - ``section`` -- (default: all sections) an element of enum\n :class:`~sage.databases.cubic_hecke_db.CubicHeckeFileCache.section`\n that can be selected using :meth:`filecache_section`\n - ``commit`` -- boolean (default: ``True``); if set to ``False`` the\n reset is not written to the filesystem\n\n EXAMPLES::\n\n sage: # optional - database_cubic_hecke\n sage: CHA5 = algebras.CubicHecke(5)\n sage: be = CHA5.filecache_section().basis_extensions\n sage: CHA5.is_filecache_empty(be)\n False\n sage: CHA5.reset_filecache(be)\n sage: CHA5.is_filecache_empty(be)\n True\n ' fc = self._filecache if (section == fc.section.basis_extensions): if (self._nstrands < 5): raise ValueError('not allowed for less than 5 strand') fc.reset_library(section=section) if (section == fc.section.basis_extensions): self._init_basis_extension() if commit: fc.write(section=section) def strands(self): '\n Return the number of strands of the braid group whose group algebra\n image is ``self``.\n\n EXAMPLES::\n\n sage: CHA4 = algebras.CubicHecke(2)\n sage: CHA4.strands()\n 2\n ' return self._nstrands def garside_involution(self, element): '\n Return the image of the given element of ``self`` under the extension of\n the Garside involution of braids to ``self``.\n\n This method may be invoked by the ``revert_garside`` method of the\n element class of ``self``, alternatively.\n\n INPUT:\n\n - ``element`` -- instance of the element class of ``self``\n\n OUTPUT:\n\n Instance of the element class of ``self`` representing the image of\n ``element`` under the extension of the Garside involution to ``self``.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: ele = CHA3.an_element()\n sage: ele_gar = CHA3.garside_involution(ele); ele_gar\n (-w)*c1*c0^-1 + u*c0 + v*c1 + ((-v*w+u)/w)\n sage: ele == CHA3.garside_involution(ele_gar)\n True\n ' braid_group = self.braid_group() reverse_gens = list(braid_group.gens()) reverse_gens.reverse() brgrp_garside_involution = braid_group.hom(reverse_gens, check=False) return self._extend_braid_automorphism(element, brgrp_garside_involution) def orientation_antiinvolution(self, element): '\n Return the image of the given element of ``self`` under the extension of\n the orientation anti involution of braids to ``self``. The orientation\n anti involution of a braid is given by reversing the order of generators\n in the braid word.\n\n This method may be invoked by the ``revert_orientation`` method of the\n element class of ``self``, alternatively.\n\n INPUT:\n\n - ``element`` -- instance of the element class of ``self``\n\n OUTPUT:\n\n Instance of the element class of ``self`` representing the image of\n ``element`` under the extension of the orientation reversing braid\n involution to ``self``.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: ele = CHA3.an_element()\n sage: ele_ori = CHA3.orientation_antiinvolution(ele); ele_ori\n (-w)*c1^-1*c0 + v*c0 + u*c1 + ((-v*w+u)/w)\n sage: ele == CHA3.orientation_antiinvolution(ele_ori)\n True\n ' braid_group = self.braid_group() def brgrp_orientation_antiinvolution(braid): braid_list = list(braid.Tietze()) braid_list.reverse() return braid_group(tuple(braid_list)) return self._extend_braid_automorphism(element, brgrp_orientation_antiinvolution) def mirror_isomorphism(self, element): '\n Return the image of the given element of ``self`` under the extension\n of the mirror involution of braids to ``self``. The mirror involution\n of a braid is given by inverting all generators in the braid word. It\n does not factor through ``self`` over the base ring but it factors\n through ``self`` considered as a `\\ZZ`-module relative to the mirror\n automorphism of the generic base ring. Considering ``self`` as algebra\n over its base ring this involution defines an isomorphism of ``self``\n onto a different cubic Hecke algebra with a different cubic equation.\n This is defined over a different base (and extension) ring than\n ``self``. It can be obtained by the method ``mirror_image`` or as\n parent of the output of this method.\n\n This method may be invoked by the ``CubicHeckeElelemnt.revert_mirror``\n method of the element class of ``self``, alternatively.\n\n INPUT:\n\n - ``element`` -- instance of the element class of ``self``\n\n OUTPUT:\n\n Instance of the element class of the mirror image of ``self``\n representing the image of element under the extension of the braid\n mirror involution to ``self``.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: ele = CHA3.an_element()\n sage: ele_mirr = CHA3.mirror_isomorphism(ele); ele_mirr\n -1/w*c0^-1*c1 + u/w*c0^-1 + v/w*c1^-1 + ((v*w-u)/w)\n sage: ele_mirr2 = ele.revert_mirror() # indirect doctest\n sage: ele_mirr == ele_mirr2\n True\n sage: par_mirr = ele_mirr.parent()\n sage: par_mirr == CHA3\n False\n sage: par_mirr == CHA3.mirror_image()\n True\n sage: ele == par_mirr.mirror_isomorphism(ele_mirr)\n True\n ' mirror_image = self.mirror_image() braid_group = self.braid_group() mirror_involution = braid_group.hom([(~ g) for g in braid_group.gens()], check=False) base_ring_mirror = self._base_ring_mirror element_vec = vector([base_ring_mirror(cf) for cf in list(element.to_vector())]) element_mirr = mirror_image.from_vector(element_vec) return mirror_image._extend_braid_automorphism(element_mirr, mirror_involution) def cubic_equation(self, var='h', as_coefficients=False, generic=False): '\n Return the cubic equation attached to ``self``.\n\n INPUT:\n\n - ``var`` -- string (default ``h``) setting the indeterminate of the\n equation\n - ``as_coefficients`` -- boolean (default: ``False``); if set to ``True``\n the list of coefficients is returned\n - ``generic`` -- boolean (default: ``False``); if set to ``True`` the\n cubic equation will be given over the generic base ring\n\n OUTPUT:\n\n A polynomial over the base ring (resp. generic base ring if ``generic``\n is set to True). In case ``as_coefficients`` is set to ``True`` a list\n of them is returned.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2, cubic_equation_roots=(E(3), ~E(3), 1))\n sage: CHA2.cubic_equation()\n h^3 - 1\n sage: CHA2.cubic_equation(generic=True)\n h^3 - u*h^2 + v*h - w\n sage: CHA2.cubic_equation(as_coefficients=True, generic=True)\n [-w, v, -u, 1]\n sage: CHA2.cubic_equation(as_coefficients=True)\n [-1, 0, 0, 1]\n ' BaseRing = self.base_ring(generic=generic) if generic: (u, v, w) = BaseRing.gens() else: (u, v, w) = self._cubic_equation_parameters cf = [(- w), v, (- u), 1] if as_coefficients: return cf from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing P = PolynomialRing(BaseRing, var) return P(cf) def cubic_equation_roots(self, generic=False): '\n Return the roots of the underlying cubic equation.\n\n INPUT:\n\n - ``generic`` -- boolean (default: ``False``); if set to ``True`` the\n roots are returned as elements of the generic extension ring\n\n OUTPUT:\n\n A triple consisting of the roots.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2, cubic_equation_roots=(3, 4, 5))\n sage: CHA2.cubic_equation()\n h^3 - 12*h^2 + 47*h - 60\n sage: CHA2.cubic_equation_roots()\n [3, 4, 5]\n sage: CHA2.cubic_equation_roots(generic=True)\n [a, b, c]\n ' if generic: return self._generic_cubic_equation_roots else: return self._cubic_equation_roots def cubic_equation_parameters(self, generic=False): '\n Return the coefficients of the underlying cubic equation.\n\n INPUT:\n\n - ``generic`` -- boolean (default: ``False``); if set to ``True`` the\n coefficients are returned as elements of the generic base ring\n\n OUTPUT:\n\n A tripple consisting of the coefficients.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2, cubic_equation_roots=(3, 4, 5))\n sage: CHA2.cubic_equation()\n h^3 - 12*h^2 + 47*h - 60\n sage: CHA2.cubic_equation_parameters()\n [12, 47, 60]\n sage: CHA2.cubic_equation_parameters(generic=True)\n [u, v, w]\n ' if generic: return self._generic_cubic_equation_parameters else: return self._cubic_equation_parameters def base_ring(self, generic=False): '\n Return the base ring of ``self``.\n\n INPUT:\n\n - ``generic`` -- boolean (default: ``False``); if ``True`` the ring\n of definition (here often called the generic base ring) is returned\n\n EXAMMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2, cubic_equation_roots=(3, 4, 5))\n sage: CHA2.base_ring()\n Integer Ring localized at (2, 3, 5)\n sage: CHA2.base_ring(generic=True)\n Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n ' if generic: return self._ring_of_definition else: return super().base_ring() def extension_ring(self, generic=False): '\n Return the extension ring of ``self``.\n\n This is an extension of its base ring containing the roots\n of the cubic equation.\n\n INPUT:\n\n - ``generic`` -- boolean (default: ``False``); if ``True`` the\n extension ring of definition (here often called the generic\n extension ring) is returned\n\n EXAMMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2, cubic_equation_roots=(3, 4, 5))\n sage: CHA2.extension_ring()\n Splitting Algebra of T^2 + T + 1 with roots [E3, -E3 - 1]\n over Integer Ring localized at (2, 3, 5)\n sage: CHA2.extension_ring(generic=True)\n Multivariate Laurent Polynomial Ring in a, b, c\n over Splitting Algebra of x^2 + x + 1\n with roots [e3, -e3 - 1] over Integer Ring\n ' if generic: return self._generic_extension_ring else: return self._extension_ring def cyclotomic_generator(self, generic=False): '\n Return the third root of unity as element of the extension ring.\n\n The only thing where this is needed is in the nine dimensional\n irreducible representations of the cubic Hecke algebra on four strands\n (see the examples of :meth:`CubicHeckeElement.matrix` for instance).\n\n INPUT:\n\n - ``generic`` -- boolean (default: ``False``); if ``True`` the\n cyclotomic generator is returned as an element extension ring of\n definition\n\n EXAMMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2, cubic_equation_roots=(3, 4, 5))\n sage: CHA2.cyclotomic_generator()\n E3\n sage: CHA2.cyclotomic_generator(generic=True)\n e3\n ' e3gen = self.extension_ring(generic=True).cyclotomic_generator() if generic: return e3gen else: return self._generic_extension_ring_map(e3gen) def braid_group(self): '\n Return the braid group attached to ``self``.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2.braid_group()\n Braid group on 2 strands\n ' return self._braid_group def cubic_braid_group(self): '\n Return the cubic braid group attached to ``self``.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2.cubic_braid_group()\n Cubic Braid group on 2 strands\n ' return self._cubic_braid_group def braid_group_algebra(self): '\n Return the group algebra of braid group attached to ``self`` over the\n base ring of ``self``.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2.braid_group_algebra()\n Algebra of Braid group on 2 strands\n over Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n ' return self._braid_group_algebra def cubic_braid_group_algebra(self): '\n Return the group algebra of cubic braid group attached to ``self`` over\n the base ring of ``self``.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: CHA2.cubic_braid_group_algebra()\n Algebra of Cubic Braid group on 2 strands\n over Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n ' return self._cubic_braid_group_algebra def cubic_hecke_subalgebra(self, nstrands=None): '\n Return a :class:`CubicHeckeAlgebra` that realizes a sub-algebra\n of ``self`` on the first ``n_strands`` strands.\n\n INPUT:\n\n - ``nstrands`` -- integer at least 1 and at most :meth:`strands` giving\n the number of strands for the subgroup; the default is one strand\n less than ``self`` has\n\n OUTPUT:\n\n An instance of this class realizing the sub-algebra.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3, cubic_equation_roots=(3, 4, 5))\n sage: CHA3.cubic_hecke_subalgebra()\n Cubic Hecke algebra on 2 strands\n over Integer Ring localized at (2, 3, 5)\n with cubic equation: h^3 - 12*h^2 + 47*h - 60 = 0\n ' if (nstrands is None): nstrands = (self._nstrands - 1) n = self._nstrands nstrands = ZZ(nstrands) if ((nstrands >= n) or (nstrands <= 0)): raise ValueError(('nstrands must be positive and less than %s' % self._nstrands)) names = self.variable_names() if ((nstrands == (self._nstrands - 1)) and (self._cubic_hecke_subalgebra is not None)): return self._cubic_hecke_subalgebra names_red = names[:(nstrands - 1)] if (self.base_ring() == self.base_ring(generic=True)): SubHeckeAlg = CubicHeckeAlgebra(names=names_red) else: SubHeckeAlg = CubicHeckeAlgebra(names=names_red, cubic_equation_parameters=tuple(self._cubic_equation_parameters), cubic_equation_roots=tuple(self._cubic_equation_roots)) if (nstrands == (self._nstrands - 1)): self._cubic_hecke_subalgebra = SubHeckeAlg return SubHeckeAlg def mirror_image(self): '\n Return a copy of ``self`` with the mirrored cubic equation, that is:\n the cubic equation has the inverse roots to the roots with respect\n to ``self``.\n\n This is needed since the mirror involution of the braid group does\n not factor through ``self`` (considered as an algebra over the base\n ring, just considered as `\\ZZ`-algebra). Therefore, the mirror\n involution of an element of ``self`` belongs to ``mirror_image``.\n\n OUTPUT:\n\n A cubic Hecke algebra over the same base and extension ring,\n but whose cubic equation is transformed by the mirror involution\n applied to its coefficients and roots.\n\n EXAMPLES::\n\n sage: CHA2 = algebras.CubicHecke(2)\n sage: ce = CHA2.cubic_equation(); ce\n h^3 - u*h^2 + v*h - w\n sage: CHA2m = CHA2.mirror_image()\n sage: cem = CHA2m.cubic_equation(); cem\n h^3 + ((-v)/w)*h^2 + u/w*h + (-1)/w\n sage: mi = CHA2.base_ring().mirror_involution(); mi\n Ring endomorphism of Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n Defn: u |--> v/w\n v |--> u/w\n w |--> 1/w\n sage: cem == cem.parent()([mi(cf) for cf in ce.coefficients()])\n True\n\n Note that both cubic Hecke algebras have the same ring of definition\n and identical generic cubic equation::\n\n sage: cemg = CHA2m.cubic_equation(generic=True)\n sage: CHA2.cubic_equation(generic=True) == cemg\n True\n sage: CHA2.cubic_equation() == cemg\n True\n sage: a, b, c = CHA2.cubic_equation_roots()\n sage: CHA2m.cubic_equation_roots(generic=True) == [a, b, c]\n True\n sage: CHA2m.cubic_equation_roots()\n [((-1)/(-w))*a^2 + (u/(-w))*a + (-v)/(-w),\n ((1/(-w))*a)*b + (1/(-w))*a^2 + ((-u)/(-w))*a,\n (((-1)/(-w))*a)*b]\n sage: ai, bi, ci = _\n sage: ai == ~a, bi == ~b, ci == ~c\n (True, True, True)\n sage: CHA2.extension_ring(generic=True).mirror_involution()\n Ring endomorphism of Multivariate Laurent Polynomial Ring in a, b, c\n over Splitting Algebra of x^2 + x + 1\n with roots [e3, -e3 - 1] over Integer Ring\n Defn: a |--> a^-1\n b |--> b^-1\n c |--> c^-1\n with map of base ring\n\n The mirror image can not be obtained for specialized cubic Hecke\n algebras if the specialization does not factor through the mirror\n involution on the ring if definition::\n\n sage: CHA2s = algebras.CubicHecke(2, cubic_equation_roots=(3, 4, 5))\n sage: CHA2s\n Cubic Hecke algebra on 2 strands\n over Integer Ring localized at (2, 3, 5)\n with cubic equation: h^3 - 12*h^2 + 47*h - 60 = 0\n\n In the next example it is not clear what the mirror image of ``7``\n should be::\n\n sage: CHA2s.mirror_image()\n Traceback (most recent call last):\n ...\n RuntimeError: base ring Integer Ring localized at (2, 3, 5)\n does not factor through mirror involution\n ' base_ring = self.base_ring() base_gen = self.base_ring(generic=True) base_gen_mirror = base_gen.mirror_involution() base_ring_mirror = self._base_ring_mirror cepg = self.cubic_equation_parameters(generic=True) cerg = self.cubic_equation_roots(generic=True) if (not base_ring_mirror): mirr_paras_gen = [base_gen_mirror(par) for par in cepg] mirr_paras = [base_ring(mirr_para) for mirr_para in mirr_paras_gen] try: base_ring_mirror = base_ring.hom(mirr_paras) except (TypeError, ValueError, NotImplementedError): raise RuntimeError(('base ring %s does not factor through mirror involution' % base_ring)) mirr_paras_back = [base_ring_mirror(mirr_para) for mirr_para in mirr_paras] if (mirr_paras_back != self.cubic_equation_parameters()): raise RuntimeError(('base ring %s does not factor through mirror involution' % base_ring)) self._base_ring_mirror = base_ring_mirror mirror_image = self._mirror_image if (mirror_image is None): extension_ring = self.extension_ring() extension_gen = self.extension_ring(generic=True) extension_gen_mirror = extension_gen.mirror_involution() mirr_paras_gen = [base_gen_mirror(par) for par in cepg] mirr_roots_gen = [extension_gen_mirror(root) for root in cerg] mirr_paras = tuple([base_ring(par) for par in mirr_paras_gen]) mirr_roots = tuple([extension_ring(root) for root in mirr_roots_gen]) n = self._nstrands mirror_image = CubicHeckeAlgebra(n, cubic_equation_parameters=mirr_paras, cubic_equation_roots=mirr_roots) mirror_image._mirror_image = self mirror_image._base_ring_mirror = base_ring_mirror mirror_image._ring_of_definition._mirror_ = base_gen_mirror mirror_image._is_mirror = True self._mirror_image = mirror_image return mirror_image def schur_elements(self, generic=False): '\n Return the list of Schur elements of ``self`` as elements\n of the extension ring of ``self``.\n\n .. NOTE::\n\n This method needs ``GAP3`` installed with package ``CHEVIE``.\n\n INPUT:\n\n - ``generic`` -- boolean (default: ``False``); if ``True``,\n the element is returned as element of the generic\n extension ring\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3) # optional gap3\n sage: sch_eles = CHA3.schur_elements() # optional gap3\n sage: sch_eles[6] # optional gap3\n (u^3*w + v^3 - 6*u*v*w + 8*w^2)/w^2\n ' gap3_result = self.chevie().SchurElements() GER = self.extension_ring(generic=True) generic_result = [GER(s) for s in gap3_result] if generic: return list(generic_result) else: ER = self.extension_ring() return [ER(s) for s in generic_result] def schur_element(self, item, generic=False): '\n Return a single Schur element of ``self`` as elements\n of the extension ring of ``self``.\n\n .. NOTE::\n\n This method needs ``GAP3`` installed with package ``CHEVIE``.\n\n INPUT:\n\n - ``item`` -- an element of :class:`AbsIrreducibeRep` to give\n the irreducible representation of ``self`` to which the Schur\n element should be returned\n - ``generic`` -- boolean (default: ``False``); if ``True``,\n the element is returned as element of the generic\n extension ring\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3) # optional gap3\n sage: CHA3.schur_element(CHA3.irred_repr.W3_111) # optional gap3\n (u^3*w + v^3 - 6*u*v*w + 8*w^2)/w^2\n ' if (not isinstance(item, AbsIrreducibeRep)): raise ValueError(('item must be an instance of %s' % AbsIrreducibeRep)) return self.schur_elements(generic=generic)[item.gap_index()] def characters(self, irr=None, original=True): '\n Return the irreducible characters of ``self``.\n\n By default the values are given in the generic extension ring.\n Setting the keyword ``original`` to ``False`` you can obtain\n the values in the (non generic) extension ring (compare the\n same keyword for :meth:`CubicHeckeElement.matrix`).\n\n INPUT:\n\n - ``irr`` -- (optional) instance of :class:`AbsIrreducibeRep`\n selecting the irreducible representation corresponding to the\n character; if not given a list of all characters is returned\n - ``original`` -- (default: ``True``) see description above\n\n OUTPUT:\n\n Function or list of Functions from the element class of ``self`` to\n the (generic or non generic) extension ring depending on the given\n keyword arguments.\n\n EXAMPLES::\n\n sage: CHA3 = algebras.CubicHecke(3)\n sage: ch = CHA3.characters()\n sage: e = CHA3.an_element()\n sage: ch[0](e)\n a^2*b + a^2*c + a^2 - b*c + b^-1*c^-1 + a^-1*c^-1 + a^-1*b^-1\n sage: _.parent()\n Multivariate Laurent Polynomial Ring in a, b, c\n over Splitting Algebra of x^2 + x + 1 with roots [e3, -e3 - 1]\n over Integer Ring\n sage: ch_w3_100 = CHA3.characters(irr=CHA3.irred_repr.W3_100)\n sage: ch_w3_100(e) == ch[0](e)\n True\n sage: ch_x = CHA3.characters(original=False)\n sage: ch_x[0](e)\n (u + v)*a + (-v*w - w^2 + u)/w\n sage: _.parent()\n Splitting Algebra of T^2 + T + 1 with roots [E3, -E3 - 1]\n over Splitting Algebra of h^3 - u*h^2 + v*h - w\n with roots [a, b, -b - a + u]\n over Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n ' def char_function(ele): if isinstance(ele, self.element_class): m = ele.matrix(original=original) return m[irr].trace() if irr: return char_function irrs = [irr for irr in self.irred_repr if (irr.number_gens() == (self._nstrands - 1))] return [self.characters(irrs[i], original=original) for i in range(len(irrs))]
def normalize_names_markov(names, markov_trace_version): "\n Return a tuple of strings of variable names of length 3 resp. 4 (if\n ``markov_trace_version`` is ``True``) according to the given input names.\n\n INPUT:\n\n - ``names`` -- passed to :func:`~sage.structure.category_object.normalize_names`\n - ``markov_trace_version`` -- boolean; if set to ``True`` four names are\n expected the last of which corresponds to the writhe factor of the\n Markov trace\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: chbr.normalize_names_markov('a, b, c', False)\n ('a', 'b', 'c')\n sage: chbr.normalize_names_markov(('u', 'v', 'w', 's'), False)\n ('u', 'v', 'w')\n " if markov_trace_version: names = normalize_names(4, names) else: if isinstance(names, tuple): names = list(names) if (isinstance(names, list) and (len(names) > 3)): names = normalize_names(3, names[0:3]) else: names = normalize_names(3, names) return names
def register_ring_hom(ring_hom): '\n Register the given ring homomorphism as conversion map.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: BR.create_specialization([E(5), E(7), E(3)]) # indirect doctest\n Universal Cyclotomic Field\n sage: _.convert_map_from(BR)\n Ring morphism:\n From: Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n To: Universal Cyclotomic Field\n Defn: u |--> E(5)\n v |--> E(7)\n w |--> E(3)\n ' domain = ring_hom.domain() codomain = ring_hom.codomain() conversion_cached = codomain._is_conversion_cached(domain) if conversion_cached: test_map = codomain.convert_map_from(domain) try: if (test_map != ring_hom): verbose(('\nConversion:\n%s\n already exists and is different from:\n%s\n' % (test_map, ring_hom))) except TypeError: verbose(('\n Conversion:\n%s\n already exists and is not comparable to:\n%s\n' % (test_map, ring_hom))) else: try: codomain.register_conversion(ring_hom) except ValueError: verbose(('\nthe map:\n%s\ncannot be registerd as conversion\n' % ring_hom)) return
class GaloisGroupAction(Action): '\n Action on a multivariate polynomial ring by permuting the generators.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: from operator import mul\n sage: R.<x, y, z> = ZZ[]\n sage: G = SymmetricGroup(3)\n sage: p = 5*x*y + 3*z**2\n sage: R._unset_coercions_used()\n sage: R.register_action(chbr.GaloisGroupAction(G, R, op=mul))\n sage: s = G([2,3,1])\n sage: s*p\n 3*x^2 + 5*y*z\n ' def _act_(self, perm, pol): '\n Application of the action.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: from operator import mul\n sage: R.<x, y> = QQ[]\n sage: G = SymmetricGroup(2)\n sage: A = chbr.GaloisGroupAction(G, R, op=mul)\n sage: p = ~5*x*y**2 + 3*x**2\n sage: s = G([2,1])\n sage: A._act_(s, p)\n 1/5*x^2*y + 3*y^2\n ' if (not self.is_left()): (perm, pol) = (pol, perm) pol_dict = {} for (key, value) in pol.dict().items(): newkey = ([0] * len(key)) for (pos, k) in enumerate(key): newkey[(perm((pos + 1)) - 1)] = k pol_dict[tuple(newkey)] = value return self.domain()(pol_dict)
class CubicHeckeExtensionRing(LaurentPolynomialRing_mpair): "\n The generic splitting algebra for the irreducible representations of\n the cubic Hecke algebra.\n\n This ring must contain three invertible indeterminates (representing\n the roots of the cubic equation) together with a third root of unity\n (needed for the 18-dimensional irreducibles of the cubic Hecke algebra\n on 4 strands).\n\n Therefore this ring is constructed as a multivariate Laurent polynomial\n ring in three indeterminates over a polynomial quotient ring over the\n integers with respect to the minimal polynomial of a third root of unity.\n\n The polynomial quotient ring is constructed as instance of\n :class:`SplittingAlgebra`.\n\n INPUT:\n\n - ``names`` -- (default: ``'u,v,w'``) string containing the names of the\n indeterminates separated by ``,`` or a triple of strings each of which\n are the names of one of the three indeterminates\n - ``order`` -- string (default: ``'degrevlex'``); the term order; see also\n :class:`~sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_mpair`\n - ``ring_of_definition`` -- (optional) a :class:`CubicHeckeRingOfDefinition`\n to specify the generic cubic Hecke base ring over which ``self`` may be\n realized as splitting ring via the ``as_splitting_algebra`` method\n - ``third_unity_root_name`` -- string (default: ``'e3'``); for setting the\n name of the third root if unity of ``self``\n - ``markov_trace_version`` -- boolean (default: ``False``) if this is\n set to ``True`` then ``self`` contains one invertible indeterminate in\n addition which is meant to represent the writhe factor of a Markov trace\n on the cubic Hecke algebra and which default name is ``s``\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: chbr.CubicHeckeExtensionRing('a, b, c')\n Multivariate Laurent Polynomial Ring in a, b, c\n over Splitting Algebra of x^2 + x + 1\n with roots [e3, -e3 - 1]\n over Integer Ring\n sage: _.an_element()\n b^2*c^-1 + e3*a\n " def __init__(self, names, order='degrevlex', ring_of_definition=None, third_unity_root_name='e3', markov_trace_version=False): "\n Initialize ``self``.\n\n TESTS::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('a, b, c')\n sage: TestSuite(ER).run()\n " self._ring_of_definition = None self._splitting_algebra = None if (ring_of_definition is not None): if (not isinstance(ring_of_definition, CubicHeckeRingOfDefinition)): raise TypeError('generic base ring must be an instance of CubicHeckeRingOfDefinition') self._ring_of_definition = ring_of_definition base_ring = SplittingAlgebra(cyclotomic_polynomial(3), [third_unity_root_name]) self._names = normalize_names_markov(names, markov_trace_version) self._order = order pol_ring = PolynomialRing(base_ring, names=self._names, order=self._order, implementation=None) LaurentPolynomialRing_mpair.__init__(self, pol_ring) from sage.groups.perm_gps.permgroup_named import SymmetricGroup from operator import mul self._galois_group = SymmetricGroup(3) galois_group_action = GaloisGroupAction(self._galois_group, self, op=mul) self._unset_coercions_used() self.register_action(galois_group_action) self._mirror = None return def construction(self): "\n Return ``None`` since this construction is not functorial.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('a, b, c')\n sage: ER._test_category() # indirect doctest\n " return None def __reduce__(self): "\n Used in pickling.\n\n TESTS::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('a, b, c')\n sage: loads(dumps(ER)) == ER\n True\n " return (CubicHeckeExtensionRing, (self._names, self._order, self._ring_of_definition)) def _element_constructor_(self, x, mon=None): '\n Inherited element constructor overloaded to allow construction from\n ``GAP3`` ``MVP`` expressions.\n\n EXAMPLES::\n\n sage: # optional - gap3\n sage: CHA3 = algebras.CubicHecke(3)\n sage: GER = CHA3.extension_ring(generic=True)\n sage: sch7 = CHA3.chevie().SchurElements()[7]\n sage: GER(sch7)\n a*b*c^-2 + a^2*b^-1*c^-1 + a^-1*b^2*c^-1 + 2\n + a*b^-2*c + a^-2*b*c + a^-1*b^-1*c^2\n sage: rep4_gap3 = CHA3.chevie().Representations(4)\n sage: matrix(GER, rep4_gap3[1])\n [ b 0]\n [-b c]\n ' from sage.interfaces.gap3 import GAP3Element if isinstance(x, GAP3Element): return self._convert_from_gap3_mvp(x) return super()._element_constructor_(x, mon=mon) def _coerce_map_from_(self, R): '\n The rings that canonically coerce to ``self`` ar the ones from\n inheritence and the base ring of definition of the cubic Hecke algebra.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: ER = BR.extension_ring()\n sage: ER(BR.an_element())\n a*b + a*c + b*c + a*b^-1*c^-1 + 2*c^-1 + a^-1*b*c^-1 + 2*b^-1\n + 2*a^-1 + a^-1*b^-1*c\n sage: MBR = chbr.CubicHeckeRingOfDefinition(markov_trace_version=True)\n sage: MER = MBR.extension_ring()\n sage: MER(MBR.an_element())\n a*b*s^-1 + a*c*s^-1 + b*c*s^-1 + a*b^-1*c^-1 + 2*c^-1\n + a^-1*b*c^-1 + 2*b^-1 + 2*a^-1 + a^-1*b^-1*c\n ' if isinstance(R, CubicHeckeRingOfDefinition): markov = R.markov_trace_version() (a, b, c, *rem) = self.gens() iu = ((a + b) + c) iv = (((a * b) + (a * c)) + (b * c)) iw = ((a * b) * c) im_gens = [iu, iv, iw] if markov: if self.markov_trace_version(): im_gens += rem embedding_into_extension_ring = R.hom(im_gens, check=False) else: embedding_into_extension_ring = R.hom(im_gens) return embedding_into_extension_ring return super()._coerce_map_from_(R) def hom(self, im_gens, codomain=None, check=True, base_map=None): "\n Return a homomorphism of ``self``.\n\n INPUT:\n\n - ``im_gens`` -- tuple for the image of the generators of ``self``\n - ``codomain`` -- (optional) the codomain of the homomorphism\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('a, b, c')\n sage: UCF = UniversalCyclotomicField()\n sage: map = ER.hom((UCF.gen(3),) + (UCF(3),UCF(4),UCF(5)))\n sage: ER.an_element()\n b^2*c^-1 + e3*a\n sage: map(_)\n -1/5*E(3) - 16/5*E(3)^2\n " gens = self.gens() num_gens = len(gens) if (not isinstance(im_gens, (list, tuple))): im_gens = [im_gens] if (len(im_gens) == (num_gens + 1)): (e3, *im_remain) = im_gens hom_cycl_gen = self.base_ring().hom([e3], codomain=e3.parent(), check=check, base_map=base_map) verbose(('hom_cycl_gen %s' % hom_cycl_gen), level=2) return super().hom(im_remain, codomain=codomain, check=check, base_map=hom_cycl_gen) else: if (base_map is None): raise ValueError(('number of images must be four (inculding a third root of unity at first position) or a base_map (on %s) must be given' % self.base_ring())) return super().hom(im_gens, codomain=codomain, check=check, base_map=base_map) def _an_element_(self): "\n Return an element of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('x, y, z')\n sage: ER.an_element() # indirect doctest\n y^2*z^-1 + e3*x\n sage: MER = chbr.CubicHeckeExtensionRing('x, y, z, s', markov_trace_version=True)\n sage: MER.an_element() # indirect doctest\n y^2*z^-1 + e3*x*s^-1\n " (a, b, c, *rem) = self.gens() e3 = self.cyclotomic_generator() s = self.one() if rem: s = rem[0] return (((b ** 2) / c) + ((a * e3) / s)) def _is_markov_trace_version(self): "\n Return whether ``self`` is the version containing the writhe parameter\n ``s`` for the Markov trace.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('a, b, c')\n sage: ER._is_markov_trace_version()\n False\n sage: MER = chbr.CubicHeckeExtensionRing('a, b, c, s', markov_trace_version=True)\n sage: MER._is_markov_trace_version()\n True\n " return (len(self.gens()) == 4) def _convert_from_gap3_mvp(self, mvp_expression): "\n Convert a string produced via ``GAP3`` interface and containing Jean\n Michel's ``MVP`` (multivariate polynomials) to an element of ``self``.\n\n INPUT:\n\n - ``string`` -- string produced via GAP3 interface and containing\n Jean Michel's ``MVP`` (multivariate polynomials)\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('a, b, c')\n sage: gap3_string = '2+a^-2bc+a^-1b^-1c^2+a^-1b^2c^-1+ab^-2E3c'\n sage: ER._convert_from_gap3_mvp(gap3_string)\n a^-1*b^2*c^-1 + 2 + e3*a*b^-2*c + a^-2*b*c + a^-1*b^-1*c^2\n " E3 = self.cyclotomic_generator() (a, b, c, *rem) = self.gens() (na, nb, nc) = self.variable_names() lc = {na: a, nb: b, nc: c, 'e': E3} var_names = list(lc.keys()) from sage.repl.preparse import implicit_mul string = str(mvp_expression) string = string.replace('E3', 'e') for i in var_names: for j in var_names: string = string.replace(('%s%s' % (i, j)), ('%s*%s' % (i, j))) sage_expression = implicit_mul(string) from sage.misc.sage_eval import sage_eval return sage_eval(sage_expression, locals=lc) def cyclotomic_generator(self): "\n Return the third root of unity as generator of the base ring\n of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('a, b, c')\n sage: ER.cyclotomic_generator()\n e3\n sage: _**3 == 1\n True\n " return self(self.base_ring().gen()) def conjugation(self): "\n Return an involution that performs *complex conjugation* with respect\n to base ring considered as order in the complex field.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('x, y, z')\n sage: conj = ER.conjugation()\n sage: conj(ER.an_element())\n y^2*z^-1 + (-e3 - 1)*x\n sage: MER = chbr.CubicHeckeExtensionRing('x, y, z, s', markov_trace_version=True)\n sage: conj = MER.conjugation()\n sage: conj(MER.an_element())\n y^2*z^-1 + (-e3 - 1)*x*s^-1\n " e3 = self.cyclotomic_generator() return self.hom(tuple(([(e3 ** 2)] + list(self.gens())))) def cubic_equation_galois_group(self): "\n Return the Galois group of the cubic equation, which is the permutation\n group on the three generators together with its action on ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('a, b, c')\n sage: G = ER.cubic_equation_galois_group()\n sage: t = ER.an_element()\n sage: [(g ,g*t) for g in G]\n [((), b^2*c^-1 + e3*a),\n ((1,3,2), a^2*b^-1 + e3*c),\n ((1,2,3), e3*b + a^-1*c^2),\n ((2,3), e3*a + b^-1*c^2),\n ((1,3), a^-1*b^2 + e3*c),\n ((1,2), a^2*c^-1 + e3*b)]\n " return self._galois_group def mirror_involution(self): "\n Return the involution of ``self`` corresponding to the involution of\n the cubic Hecke algebra (with the same name).\n\n This means that it maps the generators of ``self`` to their inverses.\n\n .. NOTE::\n\n The mirror involution of the braid group does not factor through the\n cubic Hecke algebra over its base ring, but it does if it is\n considered as `\\ZZ`-algebra. The base ring elements are transformed\n by this automorphism.\n\n OUTPUT:\n\n The involution as automorphism of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('p, q, r')\n sage: ER.mirror_involution()\n Ring endomorphism of Multivariate Laurent Polynomial Ring in p, q, r\n over Splitting Algebra of x^2 + x + 1\n with roots [e3, -e3 - 1]\n over Integer Ring\n Defn: p |--> p^-1\n q |--> q^-1\n r |--> r^-1\n with map of base ring\n sage: _(ER.an_element())\n e3*p^-1 + q^-2*r\n\n sage: MER = chbr.CubicHeckeExtensionRing('p, q, r, s', markov_trace_version=True)\n sage: MER.mirror_involution()\n Ring endomorphism of Multivariate Laurent Polynomial Ring in p, q, r, s\n over Splitting Algebra of x^2 + x + 1\n with roots [e3, -e3 - 1] over Integer Ring\n Defn: p |--> p^-1\n q |--> q^-1\n r |--> r^-1\n s |--> s^-1\n with map of base ring\n sage: _(MER.an_element())\n e3*p^-1*s + q^-2*r\n " if (self._mirror is None): e3 = self.base_ring().gen() if self._is_markov_trace_version(): (a, b, c, s) = self.gens() self._mirror = self.hom([e3, (~ a), (~ b), (~ c), (~ s)]) else: (a, b, c) = self.gens() self._mirror = self.hom([e3, (~ a), (~ b), (~ c)]) return self._mirror def create_specialization(self, im_cubic_equation_roots, im_writhe_parameter=None, var='T', third_unity_root_name='E3'): "\n Return an appropriate ring containing the elements from the list\n ``im_cubic_equation_roots`` defining a conversion map from self mapping\n the cubic equation roots of ``self`` to ``im_cubic_equation_roots``.\n\n INPUT:\n\n - ``im_cubic_equation_roots`` -- list or tuple of three ring elements\n such that there exists a ring homomorphism from the corresponding\n elements of ``self`` to them\n\n OUTPUT:\n\n A common parent containing the elements of ``im_cubic_equation_roots``\n together with their inverses.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('a, b, c')\n sage: t = ER.an_element(); t\n b^2*c^-1 + e3*a\n sage: Sp1 = ER.create_specialization([E(5), E(7), E(3)]); Sp1\n Universal Cyclotomic Field\n sage: Sp1(t)\n -E(105)^11 - E(105)^16 - E(105)^26 - E(105)^37 - E(105)^41\n - E(105)^58 - E(105)^71 - E(105)^79 - E(105)^86 - E(105)^101\n sage: MER = chbr.CubicHeckeExtensionRing('a, b, c, s', markov_trace_version=True)\n sage: MER.create_specialization([E(5), E(7), E(3)], im_writhe_parameter=E(4))\n Universal Cyclotomic Field\n sage: a, b, c, s = MER.gens()\n sage: Sp1(MER(t)/s)\n E(420) + E(420)^29 + E(420)^89 + E(420)^149 + E(420)^169 + E(420)^209\n + E(420)^253 + E(420)^269 + E(420)^337 + E(420)^389\n\n sage: Z3 = CyclotomicField(3); E3=Z3.gen()\n sage: Sp2 = ER.create_specialization([E3, E3**2, Z3(1)])\n sage: Sp2(t)\n -1\n sage: MER.create_specialization([E3, E3**2, 1], im_writhe_parameter=2)\n Cyclotomic Field of order 3 and degree 2\n sage: Sp2(MER(t)*s)\n -2\n\n sage: Sp3 = ER.create_specialization([5, 7, 11])\n sage: Sp3(t)\n 5*E3 + 49/11\n " if isinstance(im_cubic_equation_roots, tuple): im_cubic_equation_roots = list(im_cubic_equation_roots) if (not isinstance(im_cubic_equation_roots, list)): raise TypeError('cubic_equation_roots must be a list of three elements') if (len(im_cubic_equation_roots) != 3): raise ValueError('there must be exactly three cubic_equation_roots') gens = self.gens() num_gens = len(gens) if im_writhe_parameter: if (num_gens < 4): raise ValueError('im_writhe_parameter only possible for Markov-trace extension') im_gens = (im_cubic_equation_roots + [im_writhe_parameter]) (a, b, c, s) = im_gens else: if (num_gens == 4): raise ValueError('im_writhe_parameter must be given for Markov-trace extension') im_gens = im_cubic_equation_roots (a, b, c) = im_gens image_ring = get_coercion_model().common_parent(*im_gens) try: image_ring = image_ring.localization(tuple(im_gens)) except ValueError: pass im_gens = [image_ring(root) for root in im_gens] verbose(('common parent of roots and inverses: %s' % image_ring), level=2) image_ring_base = image_ring.base_ring() image_ring_map = None verbose(('first choice: image_ring %s, image_ring_base %s' % (image_ring, image_ring_base)), level=2) E3 = None cp3 = cyclotomic_polynomial(3, var=var).change_ring(image_ring) cyclotomic_roots = solve_with_extension(cp3, [third_unity_root_name], var=var, flatten=True, warning=False) if (len(cyclotomic_roots) > 0): E3 = cyclotomic_roots[0] verbose(('thrird root of unity %s found in %s' % (E3, E3.parent())), level=2) if (E3 is None): raise RuntimeError('cannot find a ring containing a third root of unity for the this choice of cubic roots!') hom_gens = ([E3] + im_gens) verbose(('hom_gens %s' % hom_gens), level=2) image_ring = get_coercion_model().common_parent(*hom_gens) verbose(('common parent of roots and third root: %s' % image_ring), level=2) hom_gens = [image_ring(gen) for gen in hom_gens] image_ring_base = image_ring.base_ring() verbose(('second choice: image_ring %s, image_ring_base %s' % (image_ring, image_ring_base)), level=2) try: image_ring_map = self.hom(hom_gens, codomain=image_ring) except (ValueError, NotImplementedError): image_ring_map = self.hom(hom_gens, codomain=image_ring, check=False) verbose('check failed for embedding as ring morphism') verbose(('specializing map defined %s' % image_ring_map), level=2) register_ring_hom(image_ring_map) return image_ring def as_splitting_algebra(self): '\n Return ``self`` as a :class:`SplittingAlgebra`; that is as an\n extension ring of the corresponding cubic Hecke algebra base ring\n (``self._ring_of_definition``, as a :class:`CubicHeckeRingOfDefinition`)\n splitting its cubic equation into linear factors, such that the roots\n are images of the generators of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: GBR = chbr.CubicHeckeRingOfDefinition()\n sage: GER = GBR.extension_ring()\n sage: ER = GER.as_splitting_algebra(); ER\n Splitting Algebra of T^2 + T + 1 with roots [E3, -E3 - 1]\n over Splitting Algebra of h^3 - u*h^2 + v*h - w\n with roots [a, b, -b - a + u]\n over Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n sage: ER(GER.an_element())\n a*E3 + ((u/(-w))*a^2 + ((u^2 - v)/w)*a)*b + a - u\n sage: ER(GBR.an_element())\n (u^2 + v*w)/w\n\n sage: MBR = chbr.CubicHeckeRingOfDefinition(markov_trace_version=True)\n sage: MER = MBR.extension_ring()\n sage: ES = MER.as_splitting_algebra(); ES\n Splitting Algebra of T^2 + T + 1 with roots [E3, -E3 - 1]\n over Splitting Algebra of h^3 - u*h^2 + v*h - w\n with roots [a, b, -b - a + u]\n over Multivariate Polynomial Ring in u, v, w, s\n over Integer Ring localized at (s, w, v, u)\n sage: ES(MER.an_element())\n (((-1)/(-s))*a)*E3 + ((u/(-w))*a^2 + ((u^2 - v)/w)*a)*b + a - u\n sage: ES(MBR.an_element())\n (u^2*s + v*w)/(w*s)\n ' if (self._splitting_algebra is not None): verbose('End (short)', level=2) return self._splitting_algebra if (self._ring_of_definition is None): verbose('constructing generic base ring', level=2) self._ring_of_definition = CubicHeckeRingOfDefinition() markov = self._is_markov_trace_version() BR = self._ring_of_definition root_names = list(self._names) var_s = None if markov: var_s = root_names.pop() (a, b, c, s) = self.gens() else: (a, b, c) = self.gens() root_names.pop() FSR = SplittingAlgebra(BR.cubic_equation(), root_names, warning=False) splitting_roots = FSR.splitting_roots() verbose(('splitting roots %s' % splitting_roots), level=2) (A, B, C) = splitting_roots e3 = self.cyclotomic_generator() if var_s: fsr_s = FSR.scalar_base_ring().gens_dict()[var_s] S = self.create_specialization([A, B, C], im_writhe_parameter=fsr_s) map_back = S.hom([e3, b, a, ((a + b) + c), (((a * b) + (a * c)) + (b * c)), ((a * b) * c), s], check=False) else: S = self.create_specialization([A, B, C]) map_back = S.hom([e3, b, a, ((a + b) + c), (((a * b) + (a * c)) + (b * c)), ((a * b) * c)]) self.register_coercion(map_back) self._splitting_algebra = S return self._splitting_algebra def field_embedding(self, characteristic=0): '\n Return a field embedding of ``self``.\n\n INPUT:\n\n - ``characteristic`` -- integer (default: ``0``); the characteristic\n of the field\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: ER = BR.extension_ring()\n sage: ER.field_embedding()\n Ring morphism:\n From: Multivariate Laurent Polynomial Ring in a, b, c\n over Splitting Algebra of x^2 + x + 1\n with roots [e3, -e3 - 1]\n over Integer Ring\n To: Fraction Field of Multivariate Polynomial Ring in a, b, c\n over Cyclotomic Field of order 3 and degree 2\n Defn: a |--> a\n b |--> b\n c |--> c\n with map of base ring\n\n sage: ER.field_embedding(characteristic=5)\n Ring morphism:\n From: Multivariate Laurent Polynomial Ring in a, b, c\n over Splitting Algebra of x^2 + x + 1\n with roots [e3, -e3 - 1]\n over Integer Ring\n To: Fraction Field of Multivariate Polynomial Ring in a, b, c\n over Finite Field in a of size 5^2\n Defn: a |--> a\n b |--> b\n c |--> c\n with map of base ring\n\n sage: MER = ER.markov_trace_version()\n sage: MER.field_embedding()\n Ring morphism:\n From: Multivariate Laurent Polynomial Ring in a, b, c, s\n over Splitting Algebra of x^2 + x + 1\n with roots [e3, -e3 - 1]\n over Integer Ring\n To: Fraction Field of Multivariate Polynomial Ring in a, b, c, s\n over Cyclotomic Field of order 3 and degree 2\n Defn: a |--> a\n b |--> b\n c |--> c\n s |--> s\n with map of base ring\n ' if (characteristic == 0): from sage.rings.number_field.number_field import CyclotomicField C3 = CyclotomicField(3) E3 = C3.gen() else: if (not ZZ(characteristic).is_prime()): raise ValueError('characteristic must be a prime integer') from sage.rings.finite_rings.finite_field_constructor import GF from sage.misc.functional import cyclotomic_polynomial G = GF(characteristic) c3 = cyclotomic_polynomial(3).change_ring(G) C3 = c3.splitting_field('a') E3 = c3.change_ring(C3).roots()[0][0] B = self.base_ring() embBase = B.hom((E3,)) if (not C3.has_coerce_map_from(B)): C3._unset_coercions_used() C3.register_coercion(embBase) P = C3[self.variable_names()] F = P.fraction_field() emb = self.hom(((F(E3),) + F.gens())) F = emb.codomain() if (not F.has_coerce_map_from(self)): F._unset_coercions_used() F.register_coercion(emb) return emb def markov_trace_version(self): "\n Return the Markov trace version of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: ER = chbr.CubicHeckeExtensionRing('a, b, c')\n sage: ER.markov_trace_version()\n Multivariate Laurent Polynomial Ring in a, b, c, s\n over Splitting Algebra of x^2 + x + 1\n with roots [e3, -e3 - 1] over Integer Ring\n " if self._is_markov_trace_version(): return self names = (self.variable_names() + ('s',)) return self.__class__(names=names, order=self._order, markov_trace_version=True)
class CubicHeckeRingOfDefinition(Localization): "\n The *ring of definition* of the cubic Hecke algebra.\n\n It contains one invertible indeterminate (representing the product of the\n roots of the cubic equation) and two non invertible indeterminates.\n\n .. NOTE::\n\n We follow a suggestion by Ivan Marin in the name *ring of definition*.\n We avoid alternative names like *generic* or *universal* base ring\n as these have some issues. The first option could be misleading\n in view of the term *generic point* used in algebraic geometry, which\n would mean the function field in ``u, v, w``, here.\n\n The second option is problematic since the base ring itself is not a\n universal object. Rather, the universal object is the cubic Hecke algebra\n considered as a `\\ZZ`-algebra including ``u, v, w`` as pairwise commuting\n indeterminates. From this point of view the base ring appears to be a\n subalgebra of this universal object generated by ``u, v, w``.\n\n INPUT:\n\n - ``names`` -- (default: ``'u,v,w'``) string containing the names of the\n indeterminates separated by ``,`` or a triple of strings each of which\n are the names of one of the three indeterminates\n - ``order`` -- string (default: ``'degrevlex'``); the term order; see also\n :class:`~sage.rings.polynomial.laurent_polynomial_ring.LaurentPolynomialRing_mpair`\n - ``ring_of_definition`` -- (optional) a :class:`CubicHeckeRingOfDefinition`\n to specify the generic cubic Hecke base ring over which ``self`` may be\n realized as splitting ring via the ``as_splitting_algebra`` method\n - ``markov_trace_version`` -- boolean (default: ``False``) if this is\n set to ``True`` then ``self`` contains one invertible indeterminate in\n addition which is meant to represent the writhe factor of a Markov trace\n on the cubic Hecke algebra and which default name is ``s``\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: u, v, w = BR.gens()\n sage: ele = 3*u*v-5*w**(-2)\n sage: ER = BR.extension_ring()\n sage: ER(ele)\n 3*a^2*b + 3*a*b^2 + 3*a^2*c + 9*a*b*c + 3*b^2*c\n + 3*a*c^2 + 3*b*c^2 + (-5)*a^-2*b^-2*c^-2\n sage: phi1 = BR.hom( [4,3,1/1] )\n sage: phi1(ele)\n 31\n\n sage: LL.<t> = LaurentPolynomialRing(ZZ)\n sage: phi2=BR.hom( [LL(4),LL(3),t] )\n sage: phi2(ele)\n -5*t^-2 + 36\n\n sage: BR.create_specialization( [E(5), E(7), E(3)] )\n Universal Cyclotomic Field\n sage: _(ele)\n -3*E(105) - 5*E(105)^2 - 5*E(105)^8 - 5*E(105)^11 - 5*E(105)^17\n - 5*E(105)^23 - 5*E(105)^26 - 5*E(105)^29 - 5*E(105)^32 - 5*E(105)^38\n - 5*E(105)^41 - 5*E(105)^44 - 5*E(105)^47 - 5*E(105)^53 - 5*E(105)^59\n - 5*E(105)^62 - 5*E(105)^68 - 8*E(105)^71 - 5*E(105)^74 - 5*E(105)^83\n - 5*E(105)^86 - 5*E(105)^89 - 5*E(105)^92 - 5*E(105)^101 - 5*E(105)^104\n " def __init__(self, names=('u', 'v', 'w', 's'), order='degrevlex', markov_trace_version=False): '\n Initialize ``self``.\n\n TESTS::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: TestSuite(BR).run()\n ' names = normalize_names_markov(names, markov_trace_version) if (len(names) == 4): invertible_names = names else: invertible_names = names[2] self._order = order base_ring = PolynomialRing(ZZ, names, order=order) Localization.__init__(self, base_ring, invertible_names) self._mirror = None return def _defining_names(self): '\n Return the generators of ``self`` as the defining names.\n\n This method is cached in the parent class.\n This causes trouble if a second instance of ``self`` is used for another\n cubic Hecke algebra in the same session. To avoid this it is overloaded\n without ``cached_method`` decorator.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: BR._defining_names()\n (u, v, w)\n ' return self.gens() def _an_element_(self): '\n Return an element of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: BR.an_element() # indirect doctest\n (u^2 + v*w)/w\n sage: MBR = chbr.CubicHeckeRingOfDefinition(markov_trace_version=True)\n sage: MBR.an_element() # indirect doctest\n (u^2*s + v*w)/(w*s)\n ' (u, v, w, *rem) = self.gens() s = self.one() if rem: s = rem[0] return (((u ** 2) / w) + (v / s)) def _is_markov_trace_version(self): '\n Return whether ``self`` is the version containing the writhe parameter\n ``s`` for the Markov trace.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: BR._is_markov_trace_version()\n False\n sage: MBR = chbr.CubicHeckeRingOfDefinition(markov_trace_version=True)\n sage: MBR._is_markov_trace_version()\n True\n ' return (len(self.gens()) == 4) def cubic_equation(self, var='h', as_coefficients=False): "\n Return the cubic equation over which the cubic Hecke algebra is defined.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: BR.cubic_equation()\n h^3 - u*h^2 + v*h - w\n sage: BR.cubic_equation(var='t')\n t^3 - u*t^2 + v*t - w\n sage: BR.cubic_equation(as_coefficients=True)\n [-w, v, -u, 1]\n " (u, v, w, *rem) = self.gens() cf = [(- w), v, (- u), 1] if as_coefficients: return cf P = PolynomialRing(self, var) return P(cf) def mirror_involution(self): '\n Return the involution of ``self`` corresponding to the involution of the\n cubic Hecke algebra (with the same name).\n\n This means that it maps the last generator of ``self`` to its inverse\n and both others to their product with the image of the former.\n\n From the cubic equation for a braid generator `\\beta_i`:\n\n .. MATH::\n\n \\beta_i^3 - u \\beta_i^2 + v\\beta_i -w = 0.\n\n One deduces the following cubic equation for `\\beta_i^{-1}`:\n\n .. MATH::\n\n \\beta_i^{-3} -\\frac{v}{w} \\beta_i^{-2} + \\frac{u}{w}\\beta_i^{-1}\n - \\frac{1}{w} = 0.\n\n .. NOTE::\n\n The mirror involution of the braid group does not factor through\n the cubic Hecke algebra over its base ring, but it does if it is\n considered as `\\ZZ`-algebra. The base ring elements are transformed\n by this automorphism.\n\n OUTPUT:\n\n The involution as automorphism of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: BR.mirror_involution()\n Ring endomorphism of Multivariate Polynomial Ring in u, v, w\n over Integer Ring localized at (w,)\n Defn: u |--> v/w\n v |--> u/w\n w |--> 1/w\n sage: _(BR.an_element())\n (v^2 + u)/w\n\n sage: MBR = chbr.CubicHeckeRingOfDefinition(markov_trace_version=True)\n sage: MBR.mirror_involution()\n Ring endomorphism of Multivariate Polynomial Ring in u, v, w, s\n over Integer Ring localized at (s, w, v, u)\n Defn: u |--> v/w\n v |--> u/w\n w |--> 1/w\n s |--> 1/s\n sage: _(MBR.an_element())\n (v^2 + u*s)/w\n ' if (self._mirror is None): if self._is_markov_trace_version(): (u, v, w, s) = self.gens() self._mirror = self.hom([(v / w), (u / w), (~ w), (~ s)]) else: (u, v, w) = self.gens() self._mirror = self.hom([(v / w), (u / w), (~ w)]) return self._mirror def create_specialization(self, im_cubic_equation_parameters, im_writhe_parameter=None): '\n Return an appropriate Ring containing the elements from the list\n ``im_cubic_equation_parameters`` having a conversion map from ``self``\n mapping the cubic equation parameters of ``self`` to\n ``im_cubic_equation_parameters``.\n\n INPUT:\n\n - ``im_cubic_equation_parameters`` -- list or tuple of three ring\n elements such that there exists a ring homomorphism from the\n corresponding elements of ``self`` to them\n\n OUTPUT:\n\n A common parent containing the elements of ``im_cubic_equation_parameters``\n together with an inverse of the third element.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: t = BR.an_element(); t\n (u^2 + v*w)/w\n sage: Sp1 = BR.create_specialization([E(5), E(7), E(3)]); Sp1\n Universal Cyclotomic Field\n sage: Sp1(t)\n E(105) + E(105)^8 + E(105)^29 - E(105)^37 + E(105)^43 - E(105)^52\n + E(105)^64 - E(105)^67 + E(105)^71 - E(105)^82 + E(105)^92\n - E(105)^97\n\n sage: MBR = chbr.CubicHeckeRingOfDefinition(markov_trace_version=True)\n sage: MBR.create_specialization([E(5), E(7), E(3)], im_writhe_parameter=E(4))\n Universal Cyclotomic Field\n sage: u, v, w, s = MBR.gens()\n sage: Sp1(MBR(t)/s)\n E(420)^13 - E(420)^53 + E(420)^73 - E(420)^109 - E(420)^137\n - E(420)^221 + E(420)^253 - E(420)^277 + E(420)^313 - E(420)^361\n + E(420)^373 - E(420)^389\n\n sage: Z3 = CyclotomicField(3); E3=Z3.gen()\n sage: Sp2 = BR.create_specialization([E3, E3**2, 1]); Sp2\n Cyclotomic Field of order 3 and degree 2\n sage: Sp2(t)\n -2*zeta3 - 2\n sage: MBR.create_specialization([E3, E3**2, 1], im_writhe_parameter=2)\n Cyclotomic Field of order 3 and degree 2\n sage: Sp2(MBR(t)/s)\n -zeta3 - 1\n\n sage: Sp3 = BR.create_specialization([5, 7, 11]); Sp3\n Integer Ring localized at (11,)\n sage: Sp3(t)\n 102/11\n ' if isinstance(im_cubic_equation_parameters, tuple): im_cubic_equation_parameters = list(im_cubic_equation_parameters) if (not isinstance(im_cubic_equation_parameters, list)): raise TypeError('cubic_equation_parameters must be a list of three elements') if (len(im_cubic_equation_parameters) != 3): raise ValueError('there must be exactly three cubic_equation_parameters') gens = self.gens() num_gens = len(gens) if im_writhe_parameter: if (num_gens < 4): raise ValueError('im_writhe_parameter only possible for Markov-trace extension') im_gens = (im_cubic_equation_parameters + [im_writhe_parameter]) (u, v, w, s) = im_gens else: if (num_gens == 4): raise ValueError('im_writhe_parameter must be given for Markov-trace extension') im_gens = im_cubic_equation_parameters (u, v, w) = im_gens image_ring = None image_ring_map = None image_ring_base = w.parent() if ((image_ring_base is self) and (im_gens == gens)): return self image_ring = get_coercion_model().common_parent(*im_gens) try: image_ring = image_ring.localization(w) except ValueError: pass im_gens = [image_ring(para) for para in im_gens] verbose(('common parent of parameters and inverses: %s' % image_ring), level=2) try: image_ring_map = self.hom(im_gens, codomain=image_ring) except ValueError: image_ring_map = self.hom(im_gens, codomain=image_ring, check=False) verbose('Warning: check failed for embedding as ring morphism') register_ring_hom(image_ring_map) return image_ring @cached_method def extension_ring(self, names=('a', 'b', 'c', 's')): '\n Return the generic extension ring attached to ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: BR = chbr.CubicHeckeRingOfDefinition()\n sage: BR.extension_ring()\n Multivariate Laurent Polynomial Ring in a, b, c\n over Splitting Algebra of x^2 + x + 1\n with roots [e3, -e3 - 1]\n over Integer Ring\n ' markov = self._is_markov_trace_version() return CubicHeckeExtensionRing(names, ring_of_definition=self, markov_trace_version=markov) def markov_trace_version(self): '\n Return the extension of the ring of definition needed to treat the\n formal Markov traces.\n\n This appends an additional variable ``s`` to measure the writhe\n of knots and makes ``u`` and ``v`` invertible.\n\n EXAMPLES::\n\n sage: from sage.algebras.hecke_algebras import cubic_hecke_base_ring as chbr\n sage: GBR = chbr.CubicHeckeRingOfDefinition()\n sage: GBR.markov_trace_version()\n Multivariate Polynomial Ring in u, v, w, s\n over Integer Ring localized at (s, w, v, u)\n ' if self._is_markov_trace_version(): return self names = (self.base_ring().variable_names() + ('s',)) return self.__class__(names=names, order=self._order, markov_trace_version=True) def specialize_homfly(self): '\n Return a map to the two variable Laurent polynomial ring that is\n the parent of the HOMFLY-PT polynomial.\n\n EXAMPLES::\n\n sage: from sage.knots.knotinfo import KnotInfo\n sage: CHA2 = algebras.CubicHecke(2)\n sage: K5_1 = KnotInfo.K5_1.link()\n sage: br = CHA2(K5_1.braid())\n sage: mt = br.formal_markov_trace()\n sage: MT = mt.base_ring()\n sage: f = MT.specialize_homfly(); f\n Composite map:\n From: Multivariate Polynomial Ring in u, v, w, s over Integer Ring\n localized at (s, w, v, u)\n To: Multivariate Laurent Polynomial Ring in L, M over Integer Ring\n Defn: Ring morphism:\n From: Multivariate Polynomial Ring in u, v, w, s\n over Integer Ring localized at (s, w, v, u)\n To: Multivariate Polynomial Ring in L, M\n over Integer Ring localized at (M, M - 1, L)\n Defn: u |--> -M + 1\n v |--> -M + 1\n w |--> 1\n s |--> L\n then\n Conversion map:\n From: Multivariate Polynomial Ring in L, M\n over Integer Ring localized at (M, M - 1, L)\n To: Multivariate Laurent Polynomial Ring in L, M\n over Integer Ring\n sage: sup = mt.support()\n sage: h1 = sum(f(mt.coefficient(b)) * b.regular_homfly_polynomial() for b in sup)\n sage: L, M = f.codomain().gens()\n sage: h2 = K5_1.homfly_polynomial()\n sage: h1*L**(-5) == h2 # since the writhe of K5_1 is 5\n True\n ' if (not self._is_markov_trace_version()): raise ValueError('Functionality available for Markov trace version, only') from sage.knots.link import Link H = Link([]).homfly_polynomial().parent() (L, M) = H.gens() HL = H.localization((1 - M)) u = HL((1 - M)) phi = self.hom((u, u, HL.one(), HL(L))) inc = H.convert_map_from(HL) return (inc * phi) def specialize_kauffman(self): '\n Return a map to the two variable Laurent polynomial ring that is\n the parent of the Kauffman polynomial.\n\n EXAMPLES::\n\n sage: from sage.knots.knotinfo import KnotInfo\n sage: CHA2 = algebras.CubicHecke(2)\n sage: K5_1 = KnotInfo.K5_1.link()\n sage: br = CHA2(K5_1.braid())\n sage: mt = br.formal_markov_trace()\n sage: MT = mt.base_ring()\n sage: f = MT.specialize_kauffman(); f\n Composite map:\n From: Multivariate Polynomial Ring in u, v, w, s over Integer Ring\n localized at (s, w, v, u)\n To: Multivariate Laurent Polynomial Ring in a, z over Integer Ring\n Defn: Ring morphism:\n From: Multivariate Polynomial Ring in u, v, w, s\n over Integer Ring localized at (s, w, v, u)\n To: Multivariate Polynomial Ring in a, z\n over Integer Ring localized at (z, a, a + z, a*z + 1)\n Defn: u |--> (a*z + 1)/a\n v |--> (a + z)/a\n w |--> 1/a\n s |--> a\n then\n Conversion map:\n From: Multivariate Polynomial Ring in a, z over Integer Ring\n localized at (z, a, a + z, a*z + 1)\n To: Multivariate Laurent Polynomial Ring in a, z\n over Integer Ring\n sage: sup = mt.support()\n sage: k1 = sum(f(mt.coefficient(b)) * b.regular_kauffman_polynomial() for b in sup)\n sage: a, z = f.codomain().gens()\n sage: k2 = KnotInfo.K5_1.kauffman_polynomial()\n sage: k1*a**(-5) == k2 # since the writhe of K5_1 is 5\n True\n ' if (not self._is_markov_trace_version()): raise ValueError('Functionality available for Markov trace version, only') from sage.knots.knotinfo import KnotInfo K = KnotInfo.L2a1_1.kauffman_polynomial().parent() (a, z) = K.gens() ku = ((z * a) + 1) kv = (z + a) KL = K.localization((ku, kv)) u = KL((ku / a)) v = KL((kv / a)) phi = self.hom((u, v, KL((~ a)), KL(a))) inc = K.convert_map_from(KL) return (inc * phi) def specialize_links_gould(self): '\n Return a map to the two variable Laurent polynomial ring that is\n the parent of the Links-Gould polynomial.\n\n EXAMPLES::\n\n sage: from sage.knots.knotinfo import KnotInfo\n sage: CHA2 = algebras.CubicHecke(2)\n sage: K5_1 = KnotInfo.K5_1.link()\n sage: br = CHA2(K5_1.braid())\n sage: mt = br.formal_markov_trace()\n sage: MT = mt.base_ring()\n sage: f = MT.specialize_links_gould(); f\n Composite map:\n From: Multivariate Polynomial Ring in u, v, w, s over Integer Ring\n localized at (s, w, v, u)\n To: Multivariate Laurent Polynomial Ring in t0, t1 over Integer Ring\n Defn: Ring morphism:\n From: Multivariate Polynomial Ring in u, v, w, s\n over Integer Ring localized at (s, w, v, u)\n To: Multivariate Polynomial Ring in t0, t1 over Integer Ring\n localized at (t1, t0, t0 + t1 - 1, t0*t1 - t0 - t1)\n Defn: u |--> t0 + t1 - 1\n v |--> t0*t1 - t0 - t1\n w |--> -t0*t1\n s |--> 1\n then\n Conversion map:\n From: Multivariate Polynomial Ring in t0, t1 over Integer Ring\n localized at (t1, t0, t0 + t1 - 1, t0*t1 - t0 - t1)\n To: Multivariate Laurent Polynomial Ring in t0, t1 over Integer Ring\n sage: sup = mt.support()\n sage: sum(f(mt.coefficient(b)) * b.links_gould_polynomial() for b in sup)\n -t0^4*t1 - t0^3*t1^2 - t0^2*t1^3 - t0*t1^4 + t0^4 + 2*t0^3*t1 + 2*t0^2*t1^2\n + 2*t0*t1^3 + t1^4 - t0^3 - 2*t0^2*t1 - 2*t0*t1^2 - t1^3 + t0^2 + 2*t0*t1\n + t1^2 - t0 - t1 + 1\n ' if (not self._is_markov_trace_version()): raise ValueError('Functionality available for Markov trace version, only') from sage.rings.polynomial.laurent_polynomial_ring import LaurentPolynomialRing L = LaurentPolynomialRing(ZZ, 't0, t1') (t0, t1) = L.gens() lu = ((t0 + t1) - 1) lv = (((t0 * t1) - t0) - t1) lw = ((- t0) * t1) LL = L.localization((lu, lv)) u = LL(lu) v = LL(lv) w = LL(lw) phi = self.hom((u, v, w, LL.one())) inc = L.convert_map_from(LL) return (inc * phi)
class GenSign(Enum): '\n Enum class to select the braid generators sign.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: chmr.GenSign.pos\n <GenSign.pos: 1>\n sage: chmr.GenSign.neg\n <GenSign.neg: -1>\n ' pos = 1 neg = (- 1)
class RepresentationType(Enum): "\n Enum class to select a representation type for the cubic Hecke algebra.\n\n - ``RegularLeft`` -- left regular representations\n - ``RegularRight`` -- right regular representations\n - ``SplitIrredMarin`` -- split irreducible representations obtained from\n Ivan Marin's data\n - ``SplitIrredChevie`` -- the split irreducible representations obtained\n from CHEVIE via the ``GAP3`` interface\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: chmr.RepresentationType.RegularLeft.is_regular()\n True\n " def is_split(self): '\n Return ``True`` if this representation type is absolutely split,\n ``False`` else-wise.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: chevie = chmr.RepresentationType.SplitIrredChevie\n sage: chevie.is_split()\n True\n ' return self.value['split'] def is_regular(self): '\n Return ``True`` if this representation type is regular, ``False``\n else-wise.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: reg_left = chmr.RepresentationType.RegularLeft\n sage: reg_left.is_regular()\n True\n ' return self.value['regular'] def data_section(self): "\n Return the name of the data file. For more information see\n :class:`~sage.databases.cubic_hecke_db.CubicHeckeDataBase`.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: reg_left = chmr.RepresentationType.RegularLeft\n sage: reg_left.data_section()\n <CubicHeckeDataSection.regular_left: 'regular_left'>\n " return self.value['data'] def number_of_representations(self, nstrands): '\n Return the number of representations existing to that type.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: chmr.RepresentationType.SplitIrredChevie.number_of_representations(4)\n 24\n sage: chmr.RepresentationType.SplitIrredMarin.number_of_representations(4)\n 24\n ' if (self.value['data'] is None): if ((nstrands < 1) or (nstrands > 5)): raise ValueError('nstrands must be between 1 and 5') elif ((nstrands < 1) or (nstrands > 4)): raise ValueError('nstrands must be between 1 and 4') return self.value['num_rep'][(nstrands - 1)] RegularLeft = {'split': False, 'regular': True, 'data': sc.regular_left, 'num_rep': [1, 1, 1, 1]} RegularRight = {'split': False, 'regular': True, 'data': sc.regular_right, 'num_rep': [1, 1, 1, 1]} SplitIrredMarin = {'split': True, 'regular': False, 'data': sc.split_irred, 'num_rep': [1, 3, 7, 24]} SplitIrredChevie = {'split': True, 'regular': False, 'data': None, 'num_rep': [1, 3, 7, 24, 30]}
class AbsIrreducibeRep(Enum): "\n Enum class to select an absolutely irreducible representation for the cubic\n Hecke algebra (``CHAn``) on `n`-strands.\n\n The names are build as follows: Take the determinant of one of the\n generators of the ``CHAn``. This is a monomial in the generic extension\n ring (``GER``) of ``CHA``, say ``a^ib^jc^k`` where ``a, b`` and ``c`` are\n the generators of ``GER``. This does not depend on the choice of the\n generator of ``CHA``, since these are conjugated to each other. This\n monomial might be looked as the weight of the representation. Therefore we\n use it as a name:\n\n ``Wn_ijk``\n\n The only ambiguity among the available irreducible representations occurs for the two nine-dimensional modules, which\n are conjugated to each other and distinguished by these names:\n\n ``W4_333`` and ``W4_333bar``\n\n Examples of names:\n\n - ``W2_100`` -- one dimensional representation of the cubic Hecke algebra on 2 strands corresponding to the first root\n of the cubic equation\n - ``W3_111`` -- three dimensional irreducible representation of the cubic Hecke algebra on 3 strands\n - ``W4_242`` -- eight dimensional irreducible representation of the cubic Hecke algebra on 4 strands having the second\n root of the cubic equation as weight of dimension 4\n\n Alternative names are taken from [MW2012]_ and can be shown by\n :meth:`alternative_name`.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: [irr.name for irr in chmr.AbsIrreducibeRep]\n ['W2_100', 'W2_001', 'W2_010', 'W3_100', 'W3_001', 'W3_010', 'W3_011', 'W3_110',\n 'W3_101', 'W3_111', 'W4_100', 'W4_001', 'W4_010', 'W4_011', 'W4_110', 'W4_101',\n 'W4_111', 'W4_120', 'W4_201', 'W4_012', 'W4_102', 'W4_210', 'W4_021', 'W4_213',\n 'W4_132', 'W4_321', 'W4_231', 'W4_123', 'W4_312', 'W4_422', 'W4_224', 'W4_242',\n 'W4_333', 'W4_333bar', 'W5_100', 'W5_001', 'W5_010', 'W5_013', 'W5_130', 'W5_301',\n 'W5_031', 'W5_103', 'W5_310', 'W5_203', 'W5_032', 'W5_320', 'W5_230', 'W5_023',\n 'W5_302', 'W5_033', 'W5_330', 'W5_303', 'W5_163', 'W5_631', 'W5_316', 'W5_136',\n 'W5_613', 'W5_361', 'W5_366', 'W5_663', 'W5_636', 'W5_933', 'W5_339', 'W5_393']\n\n REFERENCES:\n\n - [MW2012]_\n " def alternative_name(self): "\n Return the name of the split irreducible representation for cubic Hecke\n algebras for up to four strands as given in [MW2012]_.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: chmr.AbsIrreducibeRep.W3_011.alternative_name()\n 'Tbc'\n " return self.value['alt_name'] def dimension(self): '\n Return the dimension of the representation.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: chmr.AbsIrreducibeRep.W3_111.dimension()\n 3\n ' return self.value['dim'] def number_gens(self): '\n Return the number of generators of the underlying cubic Hecke algebra.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: chmr.AbsIrreducibeRep.W3_001.number_gens()\n 2\n sage: chmr.AbsIrreducibeRep.W4_001.number_gens()\n 3\n ' return self.value['ngens'] def length_orbit(self): '\n Return the length of the orbit of this representation under the action\n of the Galois group of the cubic equation.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: chmr.AbsIrreducibeRep.W3_001.length_orbit()\n 3\n sage: chmr.AbsIrreducibeRep.W3_111.length_orbit()\n 1\n ' return self.value['len_orbit'] def gap_index(self): '\n Return the array index of this representation for the access\n to the ``GAP3`` package ``CHEVIE``.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: chmr.AbsIrreducibeRep.W3_111.gap_index()\n 6\n ' return self.value['gap_ind'] def internal_index(self): '\n Return the array index of this representation for the internal access.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: chmr.AbsIrreducibeRep.W3_111.internal_index()\n 6\n ' return self.value['intern_ind'] W2_100 = {'alt_name': 'Sa', 'dim': 1, 'ngens': 1, 'len_orbit': 3, 'gap_ind': 0, 'intern_ind': 0} W2_001 = {'alt_name': 'Sc', 'dim': 1, 'ngens': 1, 'len_orbit': 3, 'gap_ind': 1, 'intern_ind': 1} W2_010 = {'alt_name': 'Sb', 'dim': 1, 'ngens': 1, 'len_orbit': 3, 'gap_ind': 2, 'intern_ind': 2} W3_100 = {'alt_name': 'Sa', 'dim': 1, 'ngens': 2, 'len_orbit': 3, 'gap_ind': 0, 'intern_ind': 0} W3_001 = {'alt_name': 'Sc', 'dim': 1, 'ngens': 2, 'len_orbit': 3, 'gap_ind': 1, 'intern_ind': 1} W3_010 = {'alt_name': 'Sb', 'dim': 1, 'ngens': 2, 'len_orbit': 3, 'gap_ind': 2, 'intern_ind': 2} W3_011 = {'alt_name': 'Tbc', 'dim': 2, 'ngens': 2, 'len_orbit': 3, 'gap_ind': 3, 'intern_ind': 3} W3_110 = {'alt_name': 'Tab', 'dim': 2, 'ngens': 2, 'len_orbit': 3, 'gap_ind': 4, 'intern_ind': 4} W3_101 = {'alt_name': 'Tac', 'dim': 2, 'ngens': 2, 'len_orbit': 3, 'gap_ind': 5, 'intern_ind': 5} W3_111 = {'alt_name': 'V', 'dim': 3, 'ngens': 2, 'len_orbit': 1, 'gap_ind': 6, 'intern_ind': 6} W4_100 = {'alt_name': 'Sa', 'dim': 1, 'ngens': 3, 'len_orbit': 3, 'gap_ind': 0, 'intern_ind': 0} W4_001 = {'alt_name': 'Sc', 'dim': 1, 'ngens': 3, 'len_orbit': 3, 'gap_ind': 1, 'intern_ind': 1} W4_010 = {'alt_name': 'Sb', 'dim': 1, 'ngens': 3, 'len_orbit': 3, 'gap_ind': 2, 'intern_ind': 2} W4_011 = {'alt_name': 'Tbc', 'dim': 2, 'ngens': 3, 'len_orbit': 3, 'gap_ind': 3, 'intern_ind': 3} W4_110 = {'alt_name': 'Tab', 'dim': 2, 'ngens': 3, 'len_orbit': 3, 'gap_ind': 4, 'intern_ind': 4} W4_101 = {'alt_name': 'Tac', 'dim': 2, 'ngens': 3, 'len_orbit': 3, 'gap_ind': 5, 'intern_ind': 5} W4_111 = {'alt_name': 'V', 'dim': 3, 'ngens': 3, 'len_orbit': 1, 'gap_ind': 6, 'intern_ind': 6} W4_120 = {'alt_name': 'Uba', 'dim': 3, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 7, 'intern_ind': 7} W4_201 = {'alt_name': 'Uac', 'dim': 3, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 8, 'intern_ind': 8} W4_012 = {'alt_name': 'Ucb', 'dim': 3, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 9, 'intern_ind': 9} W4_102 = {'alt_name': 'Uca', 'dim': 3, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 10, 'intern_ind': 10} W4_210 = {'alt_name': 'Uab', 'dim': 3, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 11, 'intern_ind': 11} W4_021 = {'alt_name': 'Ubc', 'dim': 3, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 12, 'intern_ind': 12} W4_213 = {'alt_name': 'Vcab', 'dim': 6, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 13, 'intern_ind': 13} W4_132 = {'alt_name': 'Vbca', 'dim': 6, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 14, 'intern_ind': 14} W4_321 = {'alt_name': 'Vabc', 'dim': 6, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 15, 'intern_ind': 15} W4_231 = {'alt_name': 'Vbac', 'dim': 6, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 16, 'intern_ind': 16} W4_123 = {'alt_name': 'Vcba', 'dim': 6, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 17, 'intern_ind': 17} W4_312 = {'alt_name': 'Vacb', 'dim': 6, 'ngens': 3, 'len_orbit': 6, 'gap_ind': 18, 'intern_ind': 18} W4_422 = {'alt_name': 'Wa', 'dim': 8, 'ngens': 3, 'len_orbit': 3, 'gap_ind': 19, 'intern_ind': 19} W4_224 = {'alt_name': 'Wc', 'dim': 8, 'ngens': 3, 'len_orbit': 3, 'gap_ind': 20, 'intern_ind': 20} W4_242 = {'alt_name': 'Wb', 'dim': 8, 'ngens': 3, 'len_orbit': 3, 'gap_ind': 21, 'intern_ind': 21} W4_333 = {'alt_name': 'X', 'dim': 9, 'ngens': 3, 'len_orbit': 2, 'gap_ind': 22, 'intern_ind': 22} W4_333bar = {'alt_name': 'Xbar', 'dim': 9, 'ngens': 3, 'len_orbit': 2, 'gap_ind': 23, 'intern_ind': 23} W5_100 = {'alt_name': None, 'dim': 1, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 0, 'intern_ind': 0} W5_001 = {'alt_name': None, 'dim': 1, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 1, 'intern_ind': 1} W5_010 = {'alt_name': None, 'dim': 1, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 2, 'intern_ind': 2} W5_013 = {'alt_name': None, 'dim': 4, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 3, 'intern_ind': 3} W5_130 = {'alt_name': None, 'dim': 4, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 4, 'intern_ind': 4} W5_301 = {'alt_name': None, 'dim': 4, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 5, 'intern_ind': 5} W5_031 = {'alt_name': None, 'dim': 4, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 6, 'intern_ind': 6} W5_103 = {'alt_name': None, 'dim': 4, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 7, 'intern_ind': 7} W5_310 = {'alt_name': None, 'dim': 4, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 8, 'intern_ind': 8} W5_203 = {'alt_name': None, 'dim': 5, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 9, 'intern_ind': 9} W5_032 = {'alt_name': None, 'dim': 5, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 10, 'intern_ind': 10} W5_320 = {'alt_name': None, 'dim': 5, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 11, 'intern_ind': 11} W5_230 = {'alt_name': None, 'dim': 5, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 12, 'intern_ind': 12} W5_023 = {'alt_name': None, 'dim': 5, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 13, 'intern_ind': 13} W5_302 = {'alt_name': None, 'dim': 5, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 14, 'intern_ind': 14} W5_033 = {'alt_name': None, 'dim': 6, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 15, 'intern_ind': 15} W5_330 = {'alt_name': None, 'dim': 6, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 16, 'intern_ind': 16} W5_303 = {'alt_name': None, 'dim': 6, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 17, 'intern_ind': 17} W5_163 = {'alt_name': None, 'dim': 10, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 18, 'intern_ind': 18} W5_631 = {'alt_name': None, 'dim': 10, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 19, 'intern_ind': 19} W5_316 = {'alt_name': None, 'dim': 10, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 20, 'intern_ind': 20} W5_136 = {'alt_name': None, 'dim': 10, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 21, 'intern_ind': 21} W5_613 = {'alt_name': None, 'dim': 10, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 22, 'intern_ind': 22} W5_361 = {'alt_name': None, 'dim': 10, 'ngens': 4, 'len_orbit': 6, 'gap_ind': 23, 'intern_ind': 23} W5_366 = {'alt_name': None, 'dim': 15, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 24, 'intern_ind': 24} W5_663 = {'alt_name': None, 'dim': 15, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 26, 'intern_ind': 25} W5_636 = {'alt_name': None, 'dim': 15, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 27, 'intern_ind': 26} W5_933 = {'alt_name': None, 'dim': 15, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 25, 'intern_ind': 27} W5_339 = {'alt_name': None, 'dim': 15, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 28, 'intern_ind': 28} W5_393 = {'alt_name': None, 'dim': 15, 'ngens': 4, 'len_orbit': 3, 'gap_ind': 29, 'intern_ind': 29}
class CubicHeckeMatrixRep(Matrix_generic_dense): "\n Class to supervise the diagonal block matrix structure arising from\n cubic Hecke algebra-representations.\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: MS = chmr.CubicHeckeMatrixSpace(CHA2)\n sage: m1 = MS(c1); m1\n [ a 0 0]\n [ 0 b 0]\n [ 0 0 -b - a + u]\n sage: type(m1)\n <class 'sage.algebras.hecke_algebras.cubic_hecke_matrix_rep.CubicHeckeMatrixSpace_with_category.element_class'>\n sage: m1.block_diagonal_list()\n [[a], [b], [-b - a + u]]\n\n sage: MSo = chmr.CubicHeckeMatrixSpace(CHA2, original=True)\n sage: MSo(c1)\n [a 0 0]\n [0 b 0]\n [0 0 c]\n\n sage: reg_left = chmr.RepresentationType.RegularLeft\n sage: MSreg = chmr.CubicHeckeMatrixSpace(CHA2, representation_type=reg_left)\n sage: MSreg(c1)\n [ 0 -v 1]\n [ 1 u 0]\n [ 0 w 0]\n sage: len(_.block_diagonal_list())\n 1\n\n TESTS:\n\n The minpoly does not work over more generic rings::\n\n sage: TestSuite(m1).run(skip='_test_minpoly')\n " @cached_method def _get_block(self, ind): '\n Return the ``ind``-th sub-matrix block of ``self`` considered\n as block diagonal matrix.\n\n INPUT:\n\n - ``ind`` -- integer specifying the list index according to\n :meth:`internal_index` respectively :meth:`gap_index`\n\n OUTPUT:\n\n An instance of :class:`Matrix_generic_dense` representing\n the specified block of ``self``.\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: c1.matrix()._get_block(0) # indirect doctest\n [a]\n ' representation_type = self.parent()._representation_type if (not representation_type.is_split()): return matrix(self) n = self.parent()._cubic_hecke_algebra.ngens() s = sum((irr_rep.dimension() for irr_rep in AbsIrreducibeRep if ((irr_rep.number_gens() == n) and (irr_rep.internal_index() < ind)))) for irr_rep in AbsIrreducibeRep: if ((irr_rep.number_gens() == n) and (irr_rep.internal_index() == ind)): d = irr_rep.dimension() return matrix(self.submatrix(s, s, d, d)) raise ValueError('no irreducible representation for this index') @cached_method def _irr_to_ind(self, irr): '\n Return the index if the given split irreducible representation\n of ``self``.\n\n INPUT:\n\n - ``irr`` -- an instance of :class:`AbsIrreducibeRep` specifying an\n absolute irreducible representation of the cubic Hecke algebra\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: m1 = c1.matrix()\n sage: m1._irr_to_ind(CHA2.irred_repr.W2_001)\n 1\n sage: m1._irr_to_ind(CHA2.irred_repr.W3_001)\n Traceback (most recent call last):\n ...\n TypeError: representation must have 1 generators\n ' representation_type = self.parent()._representation_type if (not representation_type.is_split()): raise TypeError('representation type is non split') ch_algebra = self.parent()._cubic_hecke_algebra if (ch_algebra.strands() != (irr.number_gens() + 1)): raise TypeError(('representation must have %s generators' % (ch_algebra.strands() - 1))) ind = irr.gap_index() if (representation_type == RepresentationType.SplitIrredMarin): ind = irr.internal_index() return ind @cached_method def __getitem__(self, item): '\n Return the sub-matrix block of ``self`` considered as block diagonal\n matrix specified by `item`.\n\n Overloading builtin-method to select a list-item.\n\n INPUT:\n\n - ``item`` -- an :class:`AbsIrreducibeRep` specifying an\n absolute irreducible representation of the cubic Hecke algebra;\n alternatively, it can be specified by list index\n (see :meth:`internal_index` repectively :meth:`gap_index`)\n\n OUTPUT:\n\n An instance of :class:`Matrix_generic_dense` representing\n the specified block of ``self``.\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: m1 = c1.matrix()\n sage: m1[0] # indirect doctest\n [a]\n sage: m1[CHA2.irred_repr.W2_001] # indirect doctest\n [b]\n ' if isinstance(item, AbsIrreducibeRep): return self._get_block(self._irr_to_ind(item)) elif isinstance(item, (Integer, int)): return self._get_block(item) return super().__getitem__(item) @cached_method def block_diagonal_list(self): '\n Return the list of sub-matrix blocks of ``self`` considered\n as block diagonal matrix.\n\n OUTPUT:\n\n A list of instances of :class:`Matrix_generic_dense` each of\n which represents a diagonal block of ``self``.\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: c1.matrix().block_diagonal_list()\n [[a], [b], [-b - a + u]]\n ' representation_type = self.parent()._representation_type n = self.parent()._cubic_hecke_algebra.strands() m = representation_type.number_of_representations(n) return [self._get_block(i) for i in range(m)] @cached_method def reduce_to_irr_block(self, irr): '\n Return a copy of ``self`` with zeroes outside the block corresponding to\n ``irr`` but the block according to the input identical to that of ``self``.\n\n INPUT:\n\n - ``irr`` -- an :class:`AbsIrreducibeRep` specifying an\n absolute irreducible representation of the cubic Hecke algebra;\n alternatively, it can be specified by list index (see\n :meth:`internal_index` respectively :meth:`gap_index`)\n\n OUTPUT:\n\n An instance of :class:`Matrix_generic_dense` with exactly one non zero block\n according to ``irr``.\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: m1 = c1.matrix()\n sage: m1.reduce_to_irr_block(0)\n [a 0 0]\n [0 0 0]\n [0 0 0]\n sage: m1.reduce_to_irr_block(CHA2.irred_repr.W2_001)\n [0 0 0]\n [0 b 0]\n [0 0 0]\n ' if isinstance(irr, AbsIrreducibeRep): ind = self._irr_to_ind(irr) else: ind = Integer(irr) from copy import copy mat_list = copy(self.parent().zero().block_diagonal_list()) mat_list[ind] = self[ind] return block_diagonal_matrix(mat_list, subdivide=self.parent()._subdivide, sparse=True)
class CubicHeckeMatrixSpace(MatrixSpace): '\n The matrix space of cubic Hecke algebra representations.\n\n INPUT:\n\n - ``cubic_hecke_algebra`` -- (optional)\n :class:`~sage.algebras.hecke_algebras.cubic_hecke_algebra.CubicHeckeAlgebra`\n must be given if ``element`` fails to be an instance of its element class\n - ``representation_type`` -- (default: ``RepresentationType.SplitIrredChevie``)\n :class:`RepresentationType` specifying the type of the representation\n - ``subdivide`` -- boolean (default: ``False``); whether or not to subdivide\n the resulting matrices\n\n - ``original`` -- boolean (default: ``False``) if ``True``, the matrix\n will have coefficients in the generic base / extension ring\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: c1.matrix() # indirect doctest\n [ a 0 0]\n [ 0 b 0]\n [ 0 0 -b - a + u]\n sage: c1.matrix(original=True)\n [a 0 0]\n [0 b 0]\n [0 0 c]\n sage: c1.matrix(representation_type = CHA2.repr_type.RegularLeft) # indirect doctest\n [ 0 -v 1]\n [ 1 u 0]\n [ 0 w 0]\n ' @staticmethod def __classcall_private__(cls, cubic_hecke_algebra, representation_type=None, subdivide=False, original=False): '\n Normalize the arguments to call the ``__init__`` constructor.\n\n See the documentation in ``__init__``.\n\n TESTS::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: MS = chmr.CubicHeckeMatrixSpace(CHA2)\n sage: MS2 = chmr.CubicHeckeMatrixSpace(CHA2, representation_type=CHA2.repr_type.SplitIrredMarin, subdivide=False)\n sage: MS is MS2\n True\n ' from sage.algebras.hecke_algebras.cubic_hecke_algebra import CubicHeckeAlgebra if (not isinstance(cubic_hecke_algebra, CubicHeckeAlgebra)): raise TypeError('cubic_hecke_algebra must be an instance of CubicHeckeAlgebra') if (representation_type is None): representation_type = RepresentationType.SplitIrredMarin if (representation_type == RepresentationType.SplitIrredChevie): from sage.combinat.root_system.reflection_group_real import is_chevie_available if (not is_chevie_available()): raise ValueError('CHEVIE is not available') base_ring = cubic_hecke_algebra.base_ring(generic=original) dimension = cubic_hecke_algebra.dimension() if representation_type.is_split(): dimension = cubic_hecke_algebra._dim_irr_rep base_ring = cubic_hecke_algebra.extension_ring(generic=original) return super(MatrixSpace, cls).__classcall__(cls, base_ring, int(dimension), cubic_hecke_algebra=cubic_hecke_algebra, representation_type=representation_type, subdivide=subdivide) def __init__(self, base_ring, dimension, cubic_hecke_algebra, representation_type, subdivide): "\n Initialize ``self``.\n\n TESTS::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: CHA3.<c1, c2> = algebras.CubicHecke(3)\n sage: MS = chmr.CubicHeckeMatrixSpace(CHA3, original=True)\n\n The minpoly does not work over more generic rings::\n\n sage: TestSuite(MS).run(skip='_test_elements') # long time\n " from sage.algebras.hecke_algebras.cubic_hecke_algebra import CubicHeckeAlgebra if (not isinstance(cubic_hecke_algebra, CubicHeckeAlgebra)): raise TypeError('cubic_hecke_algebra must be an instance of CubicHeckeAlgebra') self._cubic_hecke_algebra = cubic_hecke_algebra self._representation_type = representation_type self._subdivide = subdivide original_base_ring = cubic_hecke_algebra.base_ring(generic=True) if representation_type.is_split(): original_base_ring = cubic_hecke_algebra.extension_ring(generic=True) specialize = cubic_hecke_algebra._generic_extension_ring_map else: specialize = cubic_hecke_algebra._ring_of_definition_map verbose(('original_base_ring %s base_ring %s' % (original_base_ring, base_ring)), level=2) self._original_base_ring = original_base_ring self._specialize = specialize super().__init__(base_ring, dimension, dimension, sparse=True, implementation=CubicHeckeMatrixRep) def construction(self): '\n Return ``None`` since this construction is not functorial.\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: MS = c1.matrix().parent()\n sage: MS._test_category() # indirect doctest\n ' return None def __reduce__(self): '\n Used for pickling.\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: MS = c1.matrix().parent()\n sage: loads(dumps(MS)) == MS # indirect doctest\n True\n ' original = (self.base_ring() == self._original_base_ring) return (CubicHeckeMatrixSpace, (self._cubic_hecke_algebra, self._representation_type, self._subdivide, original)) def _element_constructor_(self, x): '\n INPUT:\n\n - ``x`` -- an element of a\n :class:`~sage.algebras.hecke_algebras.cubic_hecke_algebra.CubicHeckeAlgebra`\n or an element whose parent is a :class:`MatrixSpace`\n\n EXAMLPES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: CHA3.<c1, c2> = algebras.CubicHecke(3)\n sage: MS = chmr.CubicHeckeMatrixSpace(CHA3, original=True)\n sage: m1 = MS._element_constructor_(c1)\n sage: isinstance(m1, MS.element_class)\n True\n sage: isinstance(MS._element_constructor_(m1), MS.element_class)\n True\n\n sage: m = matrix(MS.base_ring(), 12, 12, lambda i, j: 1)\n sage: MS._element_constructor_(m)\n Traceback (most recent call last):\n ...\n TypeError: incompatible block structure\n ' ch_algebra = self._cubic_hecke_algebra ele_parent = x.parent() ori_base_ring = self._original_base_ring if isinstance(ele_parent, MatrixSpace): (d1, d2) = x.dimensions() if ((d1 != self.ncols()) or (d2 != self.nrows())): raise ValueError('incompatible dimensions!') if (ele_parent.base_ring() == ori_base_ring): x = self._specialize_matrix(x) elif (ele_parent.base_ring() != self.base_ring()): raise ValueError('incompatible base ring!') x_in_self = self.element_class(self, x) matrix_list = x_in_self.block_diagonal_list() matrix = block_diagonal_matrix(matrix_list, subdivide=self._subdivide, sparse=True) if (matrix != x): raise TypeError('incompatible block structure') return self.element_class(self, matrix) if (ele_parent == ch_algebra): mat = ch_algebra._apply_module_morphism(x, self._image_on_basis) return self(mat) raise TypeError('element must be an instance of CubicHeckeElement or a matrix') @cached_method def __call__(self, entries=None, coerce=True, copy=None): '\n Construct an element of ``self``.\n\n This method needs to be overloaded here since\n :class:`MatrixSpace` has an own implementation of it.\n\n EXAMLPES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: MS = chmr.CubicHeckeMatrixSpace(CHA2)\n sage: MS(c1)\n [ a 0 0]\n [ 0 b 0]\n [ 0 0 -b - a + u]\n ' from sage.algebras.hecke_algebras.cubic_hecke_algebra import CubicHeckeAlgebra if (entries is None): return super().__call__(entries=entries, coerce=coerce, copy=copy) if (not hasattr(entries, 'parent')): return super().__call__(entries=entries, coerce=coerce, copy=copy) ele_parent = entries.parent() if (not isinstance(ele_parent, (CubicHeckeAlgebra, MatrixSpace))): return super().__call__(entries=entries, coerce=coerce, copy=copy) return self._element_constructor_(entries) @cached_method def _specialize_matrix(self, mat): '\n Return the given matrix specializing the original coefficients\n from data import to the base ring of ``self``.\n\n INPUT:\n\n - ``mat`` -- matrix over the original base ring\n\n OUTPUT:\n\n ``mat`` over the base ring of ``self``\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: MS = chmr.CubicHeckeMatrixSpace(CHA2)\n sage: B = MS._original_base_ring\n sage: a, b, c = B.gens()\n sage: mat = matrix(B, [[a, b], [0, c]])\n sage: MS._specialize_matrix(mat)\n [ a b]\n [ 0 -b - a + u]\n ' base_ring = self.base_ring() original_base_ring = self._original_base_ring specialize = self._specialize if (base_ring == original_base_ring): return mat mat_dict = {k: specialize(original_base_ring(v)) for (k, v) in mat.dict().items()} return matrix(base_ring, mat_dict) @cached_method def _image_on_gen(self, gen_ind): '\n Return the matrix list corresponding to the generator given by\n ``(gen_ind,)`` in Tietze form under the representation_type of\n ``self`` from the data-file or via the ``GAP3`` interface\n\n INPUT:\n\n - ``gen_ind`` -- integer; index of a generator of the cubic Hecke\n algebra attached to ``self + 1``; negative values correspond to\n the according inverses\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: CHA3.<c1, c2> = algebras.CubicHecke(3)\n sage: MS = chmr.CubicHeckeMatrixSpace(CHA3)\n sage: MS._image_on_gen(1)\n [\n [ b 0] [ a 0] [ a 0]\n [a], [c], [b], [b*c c], [a*b b], [a*c c],\n <BLANKLINE>\n [ c 0 0]\n [b^2 + a*c b 0]\n [ b 1 a]\n ]\n\n sage: CHA2 = CHA3.cubic_hecke_subalgebra()\n sage: MSreg = chmr.CubicHeckeMatrixSpace(CHA2, representation_type=CHA2.repr_type.RegularRight)\n sage: MSreg._image_on_gen(-1)\n [\n [ 0 1 (-u)/w]\n [ 0 0 1/w]\n [ 1 0 v/w]\n ]\n ' representation_type = self._representation_type original_base_ring = self._original_base_ring ch_algebra = self._cubic_hecke_algebra n = ch_algebra.strands() def invert_gen(matr): '\n Return the inverse matrix of generators.\n ' cfs = ch_algebra.cubic_equation(as_coefficients=True, generic=True) fac = ((- 1) / cfs[0]) (cf0, cf1, cf2, cf3) = (original_base_ring((cf * fac)) for cf in cfs) matri = (cf1 * matr.parent().one()) matri += (cf2 * matr) matri += (cf3 * (matr ** 2)) (d1, d2) = matr.dimensions() matrI = matrix(original_base_ring, d1, d2, (lambda i, j: original_base_ring(matri[(i, j)]))) return matrI if (n == 2): if representation_type.is_split(): (a, b, c) = original_base_ring.gens() matrix_list = [matrix(1, 1, [a]), matrix(1, 1, [b]), matrix(1, 1, [c])] if (gen_ind < 0): matrix_list = [invert_gen(mat) for mat in matrix_list] return matrix_list num_rep = representation_type.number_of_representations(n) if (representation_type == RepresentationType.SplitIrredChevie): rep_list = [ch_algebra._fetch_matrix_list_from_chevie((i + 1)) for i in range(num_rep)] if (gen_ind > 0): matrix_list = [rep[(gen_ind - 1)] for rep in rep_list] else: matrix_list = [invert_gen(rep[((- gen_ind) - 1)]) for rep in rep_list] else: database = ch_algebra._database matrix_list = database.read_matrix_representation(representation_type, gen_ind, n, original_base_ring) return matrix_list @cached_method def _image_on_basis(self, basis_element): '\n Return the image of the given basis element of the cubic Hecke algebra\n in ``self``.\n\n INPUT:\n\n - ``basis_element`` -- a\n :class:`~sage.algebras.hecke_algebras.cubic_hecke_algebra.CubicHeckeElement`\n that is a monomial\n\n EXAMPLES::\n\n sage: import sage.algebras.hecke_algebras.cubic_hecke_matrix_rep as chmr\n sage: CHA3.<c1, c2> = algebras.CubicHecke(3)\n sage: MS = chmr.CubicHeckeMatrixSpace(CHA3, original=True)\n sage: MS._image_on_basis(c1)\n [ a 0 0 0 0 0 0 0 0 0 0 0]\n [ 0 c 0 0 0 0 0 0 0 0 0 0]\n [ 0 0 b 0 0 0 0 0 0 0 0 0]\n [ 0 0 0 b 0 0 0 0 0 0 0 0]\n [ 0 0 0 b*c c 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 a 0 0 0 0 0 0]\n [ 0 0 0 0 0 a*b b 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 a 0 0 0 0]\n [ 0 0 0 0 0 0 0 a*c c 0 0 0]\n [ 0 0 0 0 0 0 0 0 0 c 0 0]\n [ 0 0 0 0 0 0 0 0 0 b^2 + a*c b 0]\n [ 0 0 0 0 0 0 0 0 0 b 1 a]\n ' representation_type = self._representation_type ch_algebra = self._cubic_hecke_algebra filecache = ch_algebra._filecache original_base_ring = self._original_base_ring ele_Tietze = basis_element.Tietze() matrix_list = filecache.read_matrix_representation(representation_type, ele_Tietze, original_base_ring) if (matrix_list is None): verbose(('not in memory %s (Tietze %s)' % (basis_element, ele_Tietze)), level=2) if (len(ele_Tietze) == 0): matrix_list = ch_algebra._create_matrix_list_for_one(representation_type) else: for gen_ind in ele_Tietze: gen_matrix_list = self._image_on_gen(gen_ind) if (matrix_list is None): matrix_list = list(gen_matrix_list) else: for i in range(len(matrix_list)): matrix_list[i] *= gen_matrix_list[i] filecache.write_matrix_representation(representation_type, ele_Tietze, matrix_list) verbose(('%s saved to memory' % basis_element), level=2) mat = block_diagonal_matrix(matrix_list, subdivide=self._subdivide, sparse=True) return self._specialize_matrix(mat) @cached_method def zero(self): '\n Return the zero element of ``self``.\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: m1 = c1.matrix()\n sage: m1rl = c1.matrix(representation_type = CHA2.repr_type.RegularLeft)\n sage: z = m1.parent().zero()\n sage: zrl = m1rl.parent().zero()\n sage: matrix(z) == matrix(zrl), z.is_zero(), zrl.is_zero()\n (True, True, True)\n sage: z.block_diagonal_list()\n [[0], [0], [0]]\n sage: zrl.block_diagonal_list()\n [\n [0 0 0]\n [0 0 0]\n [0 0 0]\n ]\n ' z = self.element_class(self, super().zero()) z._cubic_hecke_element = self._cubic_hecke_algebra.zero() z.set_immutable() return z @cached_method def one(self): '\n Return the one element of ``self``.\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2)\n sage: m1 = c1.matrix()\n sage: m1rl = c1.matrix(representation_type = CHA2.repr_type.RegularLeft)\n sage: o = m1.parent().one()\n sage: orl = m1rl.parent().one()\n sage: matrix(o) == matrix(orl), o.is_one(), orl.is_one()\n (True, True, True)\n sage: o.block_diagonal_list()\n [[1], [1], [1]]\n sage: orl.block_diagonal_list()\n [\n [1 0 0]\n [0 1 0]\n [0 0 1]\n ]\n ' o = self.element_class(self, super().one()) o._cubic_hecke_element = self._cubic_hecke_algebra.one() o.set_immutable() return o @cached_method def _an_element_(self): '\n Return an element of ``self``.\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2, cubic_equation_roots=(2, 3, 5))\n sage: c1.matrix()\n [2 0 0]\n [0 3 0]\n [0 0 5]\n sage: _.parent()._an_element_()\n [ 94/3 0 0]\n [ 0 187/3 0]\n [ 0 0 373/3]\n ' x = self._cubic_hecke_algebra.an_element() return self(x) @cached_method def some_elements(self): '\n Return a generator of elements of ``self``.\n\n EXAMPLES::\n\n sage: CHA2.<c1> = algebras.CubicHecke(2, cubic_equation_roots=(2, 3, 5))\n sage: M = c1.matrix(); M\n [2 0 0]\n [0 3 0]\n [0 0 5]\n sage: MS = M.parent()\n sage: MS.some_elements()\n (\n [ 94/3 0 0]\n [ 0 187/3 0]\n [ 0 0 373/3]\n )\n sage: MS.some_elements() == tuple(MS(x) for x in CHA2.some_elements())\n True\n ' return tuple([self(x) for x in self._cubic_hecke_algebra.some_elements()])
def normalized_laurent_polynomial(R, p): '\n Return a normalized version of the (Laurent polynomial) ``p`` in the\n ring ``R``.\n\n Various ring operations in ``sage`` return an element of the field of\n fractions of the parent ring even though the element is "known" to belong to\n the base ring. This function is a hack to recover from this. This occurs\n somewhat haphazardly with Laurent polynomial rings::\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: [type(c) for c in (q**-1).coefficients()]\n [<class \'sage.rings.integer.Integer\'>]\n\n It also happens in any ring when dividing by units::\n\n sage: type(3/1)\n <class \'sage.rings.rational.Rational\'>\n sage: type(-1/-1)\n <class \'sage.rings.rational.Rational\'>\n\n This function is a variation on a suggested workaround of Nils Bruin.\n\n EXAMPLES::\n\n sage: from sage.algebras.iwahori_hecke_algebra import normalized_laurent_polynomial\n sage: type(normalized_laurent_polynomial(ZZ, 3/1))\n <class \'sage.rings.integer.Integer\'>\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: [type(c) for c in normalized_laurent_polynomial(R, q**-1).coefficients()]\n [<class \'sage.rings.integer.Integer\'>]\n sage: R.<u,v> = LaurentPolynomialRing(ZZ,2)\n sage: p = normalized_laurent_polynomial(R, 2*u**-1*v**-1 + u*v)\n sage: ui = normalized_laurent_polynomial(R, u^-1)\n sage: vi = normalized_laurent_polynomial(R, v^-1)\n sage: p(ui, vi)\n 2*u*v + u^-1*v^-1\n sage: q = u+v+ui\n sage: q(ui, vi)\n u + v^-1 + u^-1\n ' try: return R({k: R._base(c) for (k, c) in p.dict().items()}) except (AttributeError, TypeError): return R(p)
def index_cmp(x, y): "\n Compare two term indices ``x`` and ``y`` by Bruhat order, then by word\n length, and then by the generic comparison.\n\n EXAMPLES::\n\n sage: from sage.algebras.iwahori_hecke_algebra import index_cmp\n sage: W = WeylGroup(['A',2,1])\n sage: x = W.from_reduced_word([0,1])\n sage: y = W.from_reduced_word([0,2,1])\n sage: x.bruhat_le(y)\n True\n sage: index_cmp(x, y)\n 1\n " if (x.bruhat_le(y) or (x.length() < y.length())): return 1 if (y.bruhat_le(x) or (x.length() > y.length())): return (- 1) if (x < y): return (- 1) if (x > y): return 1 return 0
class IwahoriHeckeAlgebra(Parent, UniqueRepresentation): '\n The Iwahori-Hecke algebra of the Coxeter group ``W``\n with the specified parameters.\n\n INPUT:\n\n - ``W`` -- a Coxeter group or Cartan type\n - ``q1`` -- a parameter\n\n OPTIONAL ARGUMENTS:\n\n - ``q2`` -- (default ``-1``) another parameter\n - ``base_ring`` -- (default ``q1.parent()``) a ring containing ``q1``\n and ``q2``\n\n The Iwahori-Hecke algebra [Iwa1964]_ is a deformation of the group algebra of\n a Weyl group or, more generally, a Coxeter group. These algebras are\n defined by generators and relations and they depend on a deformation\n parameter `q`. Taking `q = 1`, as in the following example, gives a ring\n isomorphic to the group algebra of the corresponding Coxeter group.\n\n Let `(W, S)` be a Coxeter system and let `R` be a commutative ring\n containing elements `q_1` and `q_2`. Then the *Iwahori-Hecke algebra*\n `H = H_{q_1,q_2}(W,S)` of `(W,S)` with parameters `q_1` and `q_2` is the\n unital associative algebra with generators `\\{T_s \\mid s\\in S\\}` and\n relations:\n\n .. MATH::\n\n \\begin{aligned}\n (T_s - q_1)(T_s - q_2) &= 0\\\\\n T_r T_s T_r \\cdots &= T_s T_r T_s \\cdots,\n \\end{aligned}\n\n where the number of terms on either side of the second relations (the braid\n relations) is the order of `rs` in the Coxeter group `W`, for `r,s \\in S`.\n\n Iwahori-Hecke algebras are fundamental in many areas of mathematics,\n ranging from the representation theory of Lie groups and quantum groups,\n to knot theory and statistical mechanics. For more information see,\n for example, [KL1979]_, [HKP2010]_, [Jon1987]_ and\n :wikipedia:`Iwahori-Hecke_algebra`.\n\n .. RUBRIC:: Bases\n\n A reduced expression for an element `w \\in W` is any minimal length\n word `w = s_1 \\cdots s_k`, with `s_i \\in S`. If `w = s_1 \\cdots s_k` is a\n reduced expression for `w` then Matsumoto\'s Monoid Lemma implies that\n `T_w = T_{s_1} \\cdots T_{s_k}` depends on `w` and not on the choice of\n reduced expressions. Moreover, `\\{ T_w \\mid w\\in W \\}` is a basis for the\n Iwahori-Hecke algebra `H` and\n\n .. MATH::\n\n T_s T_w = \\begin{cases}\n T_{sw}, & \\text{if } \\ell(sw) = \\ell(w)+1,\\\\\n (q_1+q_2)T_w -q_1q_2 T_{sw}, & \\text{if } \\ell(sw) = \\ell(w)-1.\n \\end{cases}\n\n The `T`-basis of `H` is implemented for any choice of parameters\n ``q_1`` and ``q_2``::\n\n sage: R.<u,v> = LaurentPolynomialRing(ZZ,2)\n sage: H = IwahoriHeckeAlgebra(\'A3\', u,v)\n sage: T = H.T()\n sage: T[1]\n T[1]\n sage: T[1,2,1] + T[2]\n T[1,2,1] + T[2]\n sage: T[1] * T[1,2,1]\n (u+v)*T[1,2,1] + (-u*v)*T[2,1]\n sage: T[1]^-1\n (-u^-1*v^-1)*T[1] + (v^-1+u^-1)\n\n Working over the Laurent polynomial ring `Z[q^{\\pm 1/2}]` Kazhdan and\n Lusztig proved that there exist two distinguished bases\n `\\{ C^{\\prime}_w \\mid w \\in W \\}` and `\\{ C_w \\mid w \\in W \\}` of `H`\n which are uniquely determined by the properties that they are invariant\n under the bar involution on `H` and have triangular transitions matrices\n with polynomial entries of a certain form with the `T`-basis;\n see [KL1979]_ for a precise statement.\n\n It turns out that the Kazhdan-Lusztig bases can be defined (by\n specialization) in `H` whenever `-q_1 q_2` is a square in the base ring.\n The Kazhdan-Lusztig bases are implemented inside `H` whenever `-q_1 q_2`\n has a square root::\n\n sage: H = IwahoriHeckeAlgebra(\'A3\', u^2, -v^2)\n sage: T = H.T(); Cp = H.Cp(); C = H.C()\n sage: T(Cp[1])\n (u^-1*v^-1)*T[1] + (u^-1*v)\n sage: T(C[1])\n (u^-1*v^-1)*T[1] + (-u*v^-1)\n sage: Cp(C[1])\n Cp[1] + (-u*v^-1-u^-1*v)\n sage: elt = Cp[2]*Cp[3]+C[1]; elt\n Cp[2,3] + Cp[1] + (-u*v^-1-u^-1*v)\n sage: c = C(elt); c\n C[2,3] + C[1] + (u*v^-1+u^-1*v)*C[3] + (u*v^-1+u^-1*v)*C[2] + (u^2*v^-2+2+u^-2*v^2)\n sage: t = T(c); t\n (u^-2*v^-2)*T[2,3] + (u^-1*v^-1)*T[1] + (u^-2)*T[3] + (u^-2)*T[2] + (-u*v^-1+u^-2*v^2)\n sage: Cp(t)\n Cp[2,3] + Cp[1] + (-u*v^-1-u^-1*v)\n sage: Cp(c)\n Cp[2,3] + Cp[1] + (-u*v^-1-u^-1*v)\n\n The conversions to and from the Kazhdan-Lusztig bases are done behind the\n scenes whenever the Kazhdan-Lusztig bases are well-defined. Once a suitable\n Iwahori-Hecke algebra is defined they will work without further\n intervention.\n\n For example, with the "standard parameters", so that\n `(T_r-q^2)(T_r+1) = 0`::\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: H = IwahoriHeckeAlgebra(\'A3\', q^2)\n sage: T=H.T(); Cp=H.Cp(); C=H.C()\n sage: C(T[1])\n q*C[1] + q^2\n sage: elt = Cp(T[1,2,1]); elt\n q^3*Cp[1,2,1] - q^2*Cp[2,1] - q^2*Cp[1,2] + q*Cp[1] + q*Cp[2] - 1\n sage: C(elt)\n q^3*C[1,2,1] + q^4*C[2,1] + q^4*C[1,2] + q^5*C[1] + q^5*C[2] + q^6\n\n With the "normalized presentation", so that `(T_r-q)(T_r+q^{-1}) = 0`::\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: H = IwahoriHeckeAlgebra(\'A3\', q, -q^-1)\n sage: T=H.T(); Cp=H.Cp(); C=H.C()\n sage: C(T[1])\n C[1] + q\n sage: elt = Cp(T[1,2,1]); elt\n Cp[1,2,1] - (q^-1)*Cp[2,1] - (q^-1)*Cp[1,2] + (q^-2)*Cp[1] + (q^-2)*Cp[2] - (q^-3)\n sage: C(elt)\n C[1,2,1] + q*C[2,1] + q*C[1,2] + q^2*C[1] + q^2*C[2] + q^3\n\n In the group algebra, so that `(T_r-1)(T_r+1) = 0`::\n\n sage: H = IwahoriHeckeAlgebra(\'A3\', 1)\n sage: T=H.T(); Cp=H.Cp(); C=H.C()\n sage: C(T[1])\n C[1] + 1\n sage: Cp(T[1,2,1])\n Cp[1,2,1] - Cp[2,1] - Cp[1,2] + Cp[1] + Cp[2] - 1\n sage: C(_)\n C[1,2,1] + C[2,1] + C[1,2] + C[1] + C[2] + 1\n\n On the other hand, if the Kazhdan-Lusztig bases are not well-defined (when\n `-q_1 q_2` is not a square), attempting to use the Kazhdan-Lusztig bases\n triggers an error::\n\n sage: R.<q>=LaurentPolynomialRing(ZZ)\n sage: H = IwahoriHeckeAlgebra(\'A3\', q)\n sage: C=H.C()\n Traceback (most recent call last):\n ...\n ValueError: The Kazhdan_Lusztig bases are defined only when -q_1*q_2 is a square\n\n We give an example in affine type::\n\n sage: R.<v> = LaurentPolynomialRing(ZZ)\n sage: H = IwahoriHeckeAlgebra([\'A\',2,1], v^2)\n sage: T=H.T(); Cp=H.Cp(); C=H.C()\n sage: C(T[1,0,2])\n v^3*C[1,0,2] + v^4*C[1,0] + v^4*C[0,2] + v^4*C[1,2]\n + v^5*C[0] + v^5*C[2] + v^5*C[1] + v^6\n sage: Cp(T[1,0,2])\n v^3*Cp[1,0,2] - v^2*Cp[1,0] - v^2*Cp[0,2] - v^2*Cp[1,2]\n + v*Cp[0] + v*Cp[2] + v*Cp[1] - 1\n sage: T(C[1,0,2])\n (v^-3)*T[1,0,2] - (v^-1)*T[1,0] - (v^-1)*T[0,2] - (v^-1)*T[1,2]\n + v*T[0] + v*T[2] + v*T[1] - v^3\n sage: T(Cp[1,0,2])\n (v^-3)*T[1,0,2] + (v^-3)*T[1,0] + (v^-3)*T[0,2] + (v^-3)*T[1,2]\n + (v^-3)*T[0] + (v^-3)*T[2] + (v^-3)*T[1] + (v^-3)\n\n EXAMPLES:\n\n We start by creating a Iwahori-Hecke algebra together with the three bases\n for these algebras that are currently supported::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, \'v\')\n sage: H = IwahoriHeckeAlgebra(\'A3\', v**2)\n sage: T = H.T()\n sage: C = H.C()\n sage: Cp = H.Cp()\n\n It is also possible to define these three bases quickly using\n the :meth:`inject_shorthands` method.\n\n Next we create our generators for the `T`-basis and do some basic\n computations and conversions between the bases::\n\n sage: T1,T2,T3 = T.algebra_generators()\n sage: T1 == T[1]\n True\n sage: T1*T2 == T[1,2]\n True\n sage: T1 + T2\n T[1] + T[2]\n sage: T1*T1\n -(1-v^2)*T[1] + v^2\n sage: (T1 + T2)*T3 + T1*T1 - (v + v^-1)*T2\n T[3,1] + T[2,3] - (1-v^2)*T[1] - (v^-1+v)*T[2] + v^2\n sage: Cp(T1)\n v*Cp[1] - 1\n sage: Cp((v^1 - 1)*T1*T2 - T3)\n -(v^2-v^3)*Cp[1,2] + (v-v^2)*Cp[1] - v*Cp[3] + (v-v^2)*Cp[2] + v\n sage: C(T1)\n v*C[1] + v^2\n sage: p = C(T2*T3 - v*T1); p\n v^2*C[2,3] - v^2*C[1] + v^3*C[3] + v^3*C[2] - (v^3-v^4)\n sage: Cp(p)\n v^2*Cp[2,3] - v^2*Cp[1] - v*Cp[3] - v*Cp[2] + (1+v)\n sage: Cp(T2*T3 - v*T1)\n v^2*Cp[2,3] - v^2*Cp[1] - v*Cp[3] - v*Cp[2] + (1+v)\n\n In addition to explicitly creating generators, we have two shortcuts to\n basis elements. The first is by using elements of the underlying Coxeter\n group, the other is by using reduced words::\n\n sage: s1,s2,s3 = H.coxeter_group().gens()\n sage: T[s1*s2*s1*s3] == T[1,2,1,3]\n True\n sage: T[1,2,1,3] == T1*T2*T1*T3\n True\n\n TESTS:\n\n We check the defining properties of the bases::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, \'v\')\n sage: H = IwahoriHeckeAlgebra(\'A3\', v**2)\n sage: W = H.coxeter_group()\n sage: T = H.T()\n sage: C = H.C()\n sage: Cp = H.Cp()\n sage: T(Cp[1])\n (v^-1)*T[1] + (v^-1)\n sage: T(C[1])\n (v^-1)*T[1] - v\n sage: C(Cp[1])\n C[1] + (v^-1+v)\n sage: Cp(C[1])\n Cp[1] - (v^-1+v)\n sage: all(C[x] == C[x].bar() for x in W) # long time\n True\n sage: all(Cp[x] == Cp[x].bar() for x in W) # long time\n True\n sage: all(T(C[x]).bar() == T(C[x]) for x in W) # long time\n True\n sage: all(T(Cp[x]).bar() == T(Cp[x]) for x in W) # long time\n True\n sage: KL = KazhdanLusztigPolynomial(W, v)\n sage: term = lambda x,y: (-1)^y.length() * v^(-2*y.length()) * KL.P(y, x).substitute(v=v^-2)*T[y]\n sage: all(T(C[x]) == (-v)^x.length()*sum(term(x,y) for y in W) for x in W) # long time\n True\n sage: all(T(Cp[x]) == v^-x.length()*sum(KL.P(y,x).substitute(v=v^2)*T[y] for y in W) for x in W) # long time\n True\n\n We check conversion between the bases for type `B_2` as well as some of\n the defining properties::\n\n sage: H = IwahoriHeckeAlgebra([\'B\',2], v**2)\n sage: W = H.coxeter_group()\n sage: T = H.T()\n sage: C = H.C()\n sage: Cp = H.Cp()\n sage: all(T[x] == T(C(T[x])) for x in W) # long time\n True\n sage: all(T[x] == T(Cp(T[x])) for x in W) # long time\n True\n sage: all(C[x] == C(T(C[x])) for x in W) # long time\n True\n sage: all(C[x] == C(Cp(C[x])) for x in W) # long time\n True\n sage: all(Cp[x] == Cp(T(Cp[x])) for x in W) # long time\n True\n sage: all(Cp[x] == Cp(C(Cp[x])) for x in W) # long time\n True\n sage: all(T(C[x]).bar() == T(C[x]) for x in W) # long time\n True\n sage: all(T(Cp[x]).bar() == T(Cp[x]) for x in W) # long time\n True\n sage: KL = KazhdanLusztigPolynomial(W, v)\n sage: term = lambda x,y: (-1)^y.length() * v^(-2*y.length()) * KL.P(y, x).substitute(v=v^-2)*T[y]\n sage: all(T(C[x]) == (-v)^x.length()*sum(term(x,y) for y in W) for x in W) # long time\n True\n sage: all(T(Cp[x]) == v^-x.length()*sum(KL.P(y,x).substitute(v=v^2)*T[y] for y in W) for x in W) # long time\n True\n\n .. TODO::\n\n Implement multi-parameter Iwahori-Hecke algebras together with their\n Kazhdan-Lusztig bases. That is, Iwahori-Hecke algebras with (possibly)\n different parameters for each conjugacy class of simple reflections\n in the underlying Coxeter group.\n\n .. TODO::\n\n When given "generic parameters" we should return the generic\n Iwahori-Hecke algebra with these parameters and allow the user to\n work inside this algebra rather than doing calculations behind the\n scenes in a copy of the generic Iwahori-Hecke algebra. The main\n problem is that it is not clear how to recognise when the\n parameters are "generic".\n ' @staticmethod def __classcall_private__(cls, W, q1, q2=(- 1), base_ring=None): '\n TESTS::\n\n sage: H = IwahoriHeckeAlgebra("A2", 1)\n sage: W = CoxeterGroup("A2")\n sage: H.coxeter_group() == W\n True\n sage: H.cartan_type() == CartanType("A2")\n True\n sage: H._q2 == -1\n True\n sage: H2 = IwahoriHeckeAlgebra(W, QQ(1), base_ring=ZZ)\n sage: H is H2\n True\n ' if (W not in CoxeterGroups()): W = CoxeterGroup(W) if (base_ring is None): base_ring = q1.parent() else: q1 = base_ring(q1) q2 = base_ring(q2) return super().__classcall__(cls, W, q1, q2, base_ring) def __init__(self, W, q1, q2, base_ring): '\n Initialize and return the two parameter Iwahori-Hecke algebra ``self``.\n\n EXAMPLES::\n\n sage: R.<q1,q2> = QQ[]\n sage: H = IwahoriHeckeAlgebra("A2", q1, q2=q2, base_ring=Frac(R))\n sage: TestSuite(H).run()\n ' self._W = W self._coxeter_type = W.coxeter_type() self._q1 = q1 self._q2 = q2 self._q_sum = (q1 + q2) self._q_prod = ((- q1) * q2) (is_Square, root) = is_square(self._q_prod, root=True) if is_Square: self._root = root self._generic_iwahori_hecke_algebra = IwahoriHeckeAlgebra_nonstandard(W) self._shorthands = ['C', 'Cp', 'T'] else: self._root = None self._shorthands = ['T'] try: base_ring((base_ring.one() / 2)) self._shorthands.extend(['A', 'B']) except (TypeError, ZeroDivisionError): pass if W.is_finite(): self._category = FiniteDimensionalAlgebrasWithBasis(base_ring) else: self._category = AlgebrasWithBasis(base_ring) Parent.__init__(self, base=base_ring, category=self._category.WithRealizations()) self._is_generic = False try: self._inverse_base_ring_generators = {g: (self.base_ring()(g) ** (- 1)) for g in self.base_ring().variable_names()} except TypeError: self._inverse_base_ring_generators = {} def _repr_(self): '\n EXAMPLES::\n\n sage: R.<q1,q2> = QQ[]\n sage: IwahoriHeckeAlgebra("A2", q1**2, q2**2, base_ring=Frac(R))\n Iwahori-Hecke algebra of type A2 in q1^2,q2^2 over Fraction Field of Multivariate Polynomial Ring in q1, q2 over Rational Field\n ' try: ct = self._coxeter_type._repr_(compact=True) except TypeError: ct = repr(self._coxeter_type) return 'Iwahori-Hecke algebra of type {} in {},{} over {}'.format(ct, self._q1, self._q2, self.base_ring()) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: R.<q1,q2> = QQ[]\n sage: H = IwahoriHeckeAlgebra("A2", q1**2, q2**2, base_ring=Frac(R))\n sage: latex(H)\n \\mathcal{H}_{q_{1}^{2},q_{2}^{2}}\\left(A_{2},\n \\mathrm{Frac}(\\Bold{Q}[q_{1}, q_{2}])\\right)\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: H = IwahoriHeckeAlgebra("A2", q)\n sage: latex(H)\n \\mathcal{H}_{q,-1}\\left(A_{2}, \\Bold{Z}[q^{\\pm 1}]\\right)\n ' from sage.misc.latex import latex return '\\mathcal{{H}}_{{{},{}}}\\left({}, {}\\right)'.format(latex(self._q1), latex(self._q2), latex(self._coxeter_type), latex(self.base_ring())) def _bar_on_coefficients(self, c): '\n Given a Laurent polynomial ``c`` return the Laurent polynomial obtained\n by applying the (generic) bar involution to ``c`` .\n\n This is the ring homomorphism of Laurent polynomials in\n `\\ZZ[u,u^{-1},v,v^{-1}]` which sends `u` to `u^{-1}` and `v`\n to `v^{-1}`.\n\n EXAMPLES::\n\n sage: R.<q>=LaurentPolynomialRing(ZZ)\n sage: H = IwahoriHeckeAlgebra("A3",q^2)\n sage: H._bar_on_coefficients(q)\n q^-1\n ' return normalized_laurent_polynomial(self._base, c).substitute(**self._inverse_base_ring_generators) def coxeter_type(self): '\n Return the Coxeter type of ``self``.\n\n EXAMPLES::\n\n sage: IwahoriHeckeAlgebra("D4", 1).coxeter_type()\n Coxeter type of [\'D\', 4]\n ' return self._coxeter_type def cartan_type(self): '\n Return the Cartan type of ``self``.\n\n EXAMPLES::\n\n sage: IwahoriHeckeAlgebra("D4", 1).cartan_type()\n [\'D\', 4]\n ' try: return self._coxeter_type.cartan_type() except AttributeError: return None def coxeter_group(self): '\n Return the Coxeter group of ``self``.\n\n EXAMPLES::\n\n sage: IwahoriHeckeAlgebra("B2", 1).coxeter_group()\n Finite Coxeter group over Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095? with Coxeter matrix:\n [1 4]\n [4 1]\n ' return self._W def a_realization(self): '\n Return a particular realization of ``self`` (the `T`-basis).\n\n EXAMPLES::\n\n sage: H = IwahoriHeckeAlgebra("B2", 1)\n sage: H.a_realization()\n Iwahori-Hecke algebra of type B2 in 1,-1 over Integer Ring in the T-basis\n ' return self.T() def q1(self): '\n Return the parameter `q_1` of ``self``.\n\n EXAMPLES::\n\n sage: H = IwahoriHeckeAlgebra("B2", 1)\n sage: H.q1()\n 1\n ' return self._q1 def q2(self): '\n Return the parameter `q_2` of ``self``.\n\n EXAMPLES::\n\n sage: H = IwahoriHeckeAlgebra("B2", 1)\n sage: H.q2()\n -1\n ' return self._q2 class _BasesCategory(Category_realization_of_parent): '\n The category of bases of a Iwahori-Hecke algebra.\n ' def __init__(self, base): '\n Initialize the bases of a Iwahori-Hecke algebra.\n\n INPUT:\n\n - ``base`` -- a Iwahori-Hecke algebra\n\n TESTS::\n\n sage: H = IwahoriHeckeAlgebra("B2", 1)\n sage: bases = H._BasesCategory()\n sage: H.T() in bases\n True\n ' Category_realization_of_parent.__init__(self, base) def super_categories(self): '\n The super categories of ``self``.\n\n EXAMPLES::\n\n sage: H = IwahoriHeckeAlgebra("B2", 1)\n sage: bases = H._BasesCategory()\n sage: bases.super_categories()\n [Category of realizations of Iwahori-Hecke algebra of type B2 in 1,-1 over Integer Ring,\n Category of finite dimensional algebras with basis over Integer Ring]\n ' return [Realizations(self.base()), self.base()._category] def _repr_(self): '\n Return the representation of ``self``.\n\n EXAMPLES::\n\n sage: H = IwahoriHeckeAlgebra("B2", 1)\n sage: H._BasesCategory()\n Category of bases of Iwahori-Hecke algebra of type B2 in 1,-1 over Integer Ring\n ' return ('Category of bases of %s' % self.base()) class ParentMethods(): '\n This class collects code common to all the various bases. In most\n cases, these are just default implementations that will get\n specialized in a basis.\n ' def _repr_(self): '\n Text representation of this basis of Iwahori-Hecke algebra.\n\n EXAMPLES::\n\n sage: H = IwahoriHeckeAlgebra("B2", 1)\n sage: H.T()\n Iwahori-Hecke algebra of type B2 in 1,-1 over Integer Ring in the T-basis\n sage: H.C()\n Iwahori-Hecke algebra of type B2 in 1,-1 over Integer Ring in the C-basis\n sage: H.Cp()\n Iwahori-Hecke algebra of type B2 in 1,-1 over Integer Ring in the Cp-basis\n ' return ('%s in the %s-basis' % (self.realization_of(), self._basis_name)) def __getitem__(self, i): '\n Return the basis element indexed by ``i``.\n\n INPUT:\n\n - ``i`` -- either an element of the Coxeter group or a\n reduced word\n\n .. WARNING::\n\n If `i`` is not a reduced expression then the basis element\n indexed by the corresponding element of the algebra is\n returned rather than the corresponding product of the\n generators::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, \'v\')\n sage: T = IwahoriHeckeAlgebra(\'A3\', v**2).T()\n sage: T[1,1] == T[1] * T[1]\n False\n\n EXAMPLES::\n\n sage: H = IwahoriHeckeAlgebra("B2", 1)\n sage: T = H.T()\n sage: G = H.coxeter_group()\n sage: T[G.one()]\n 1\n sage: T[G.simple_reflection(1)]\n T[1]\n sage: T[G.from_reduced_word([1,2,1])]\n T[1,2,1]\n sage: T[[]]\n 1\n sage: T[1]\n T[1]\n sage: T[1,2,1]\n T[1,2,1]\n ' W = self.realization_of().coxeter_group() if (i in ZZ): return self(W.simple_reflection(i)) if (i in W): return self(i) if (i == []): return self.one() return self(W.from_reduced_word(i)) def is_field(self, proof=True): '\n Return whether this Iwahori-Hecke algebra is a field.\n\n EXAMPLES::\n\n sage: T = IwahoriHeckeAlgebra("B2", 1).T()\n sage: T.is_field()\n False\n ' return False def is_commutative(self): '\n Return whether this Iwahori-Hecke algebra is commutative.\n\n EXAMPLES::\n\n sage: T = IwahoriHeckeAlgebra("B2", 1).T()\n sage: T.is_commutative()\n False\n ' return (self.base_ring().is_commutative() and self.realization_of().coxeter_group().is_commutative()) @cached_method def one_basis(self): '\n Return the identity element in the Weyl group, as per\n ``AlgebrasWithBasis.ParentMethods.one_basis``.\n\n EXAMPLES::\n\n sage: H = IwahoriHeckeAlgebra("B2", 1)\n sage: H.T().one_basis()\n [1 0]\n [0 1]\n ' return self.realization_of().coxeter_group().one() def index_set(self): '\n Return the index set of ``self``.\n\n EXAMPLES::\n\n sage: IwahoriHeckeAlgebra("B2", 1).T().index_set()\n (1, 2)\n ' return self.realization_of().coxeter_group().index_set() @cached_method def algebra_generators(self): '\n Return the generators.\n\n They do not have order two but satisfy a quadratic relation.\n They coincide with the simple reflections in the Coxeter group\n when `q_1 = 1` and `q_2 = -1`. In this special case,\n the Iwahori-Hecke algebra is identified with the group algebra\n of the Coxeter group.\n\n EXAMPLES:\n\n In the standard basis::\n\n sage: R.<q> = QQ[]\n sage: H = IwahoriHeckeAlgebra("A3", q).T()\n sage: T = H.algebra_generators(); T\n Finite family {1: T[1], 2: T[2], 3: T[3]}\n sage: T.list()\n [T[1], T[2], T[3]]\n sage: [T[i] for i in [1,2,3]]\n [T[1], T[2], T[3]]\n sage: T1,T2,T3 = H.algebra_generators()\n sage: T1\n T[1]\n sage: H = IwahoriHeckeAlgebra([\'A\',2,1], q).T()\n sage: T = H.algebra_generators(); T\n Finite family {0: T[0], 1: T[1], 2: T[2]}\n sage: T.list()\n [T[0], T[1], T[2]]\n sage: [T[i] for i in [0,1,2]]\n [T[0], T[1], T[2]]\n sage: [T0, T1, T2] = H.algebra_generators()\n sage: T0\n T[0]\n\n In the Kazhdan-Lusztig basis::\n\n sage: R = LaurentPolynomialRing(QQ, \'v\')\n sage: v = R.gen(0)\n sage: H = IwahoriHeckeAlgebra(\'A5\', v**2)\n sage: C = H.C()\n sage: C.algebra_generators()\n Finite family {1: C[1], 2: C[2], 3: C[3], 4: C[4], 5: C[5]}\n sage: C.algebra_generators().list()\n [C[1], C[2], C[3], C[4], C[5]]\n ' return self.basis().keys().simple_reflections().map(self.monomial) def algebra_generator(self, i): '\n Return the `i`-th generator of ``self``.\n\n EXAMPLES:\n\n In the standard basis::\n\n sage: R.<q>=QQ[]\n sage: H = IwahoriHeckeAlgebra("A3", q).T()\n sage: [H.algebra_generator(i) for i in H.index_set()]\n [T[1], T[2], T[3]]\n\n In the Kazhdan-Lusztig basis::\n\n sage: R = LaurentPolynomialRing(QQ, \'v\')\n sage: v = R.gen(0)\n sage: H = IwahoriHeckeAlgebra(\'A5\', v**2)\n sage: C = H.C()\n sage: [C.algebra_generator(i) for i in H.coxeter_group().index_set()]\n [C[1], C[2], C[3], C[4], C[5]]\n ' return self.algebra_generators()[i] @abstract_method(optional=True) def bar_on_basis(self, w): "\n Return the bar involution on the basis element of ``self``\n indexed by ``w``.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: W = H.coxeter_group()\n sage: s1,s2,s3 = W.simple_reflections()\n sage: Cp = H.Cp()\n sage: Cp.bar_on_basis(s1*s2*s1*s3)\n Cp[1,2,3,1]\n " @abstract_method(optional=True) def hash_involution_on_basis(self, w): "\n Return the bar involution on the basis element of ``self``\n indexed by ``w``.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: W = H.coxeter_group()\n sage: s1,s2,s3 = W.simple_reflections()\n sage: Cp = H.Cp()\n sage: C = H.C()\n sage: C(Cp.hash_involution_on_basis(s1*s2*s1*s3))\n C[1,2,3,1]\n " class ElementMethods(): def bar(self): "\n Return the bar involution of ``self``.\n\n The bar involution `\\overline{\\phantom{x}}` is an antilinear\n `\\ZZ`-algebra involution defined by the identity on `\\ZZ`,\n sending `q^{1/2} \\mapsto q^{-1/2}`, and `\\overline{T_w} =\n T_{w^{-1}}^{-1}`.\n\n REFERENCES:\n\n - :wikipedia:`Iwahori-Hecke_algebra#Canonical_basis`\n\n EXAMPLES:\n\n We first test on a single generator::\n\n sage: R.<q> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', q)\n sage: T = H.T()\n sage: T1,T2,T3 = T.algebra_generators()\n sage: T1.bar()\n (q^-1)*T[1] + (q^-1-1)\n sage: T1.bar().bar() == T1\n True\n\n Next on a multiple of generators::\n\n sage: b = (T1*T2*T1).bar(); b\n (q^-3)*T[1,2,1] + (q^-3-q^-2)*T[2,1] + (q^-3-q^-2)*T[1,2]\n + (q^-3-2*q^-2+q^-1)*T[1] + (q^-3-2*q^-2+q^-1)*T[2]\n + (q^-3-2*q^-2+2*q^-1-1)\n sage: b.bar() == T1*T2*T1\n True\n\n A sum::\n\n sage: s = T1 + T2\n sage: b = s.bar(); b\n (q^-1)*T[1] + (q^-1)*T[2] + (2*q^-1-2)\n sage: b.bar() == s\n True\n\n A more complicated example::\n\n sage: p = T1*T2 + (1-q+q^-1)*T3 - q^3*T1*T3\n sage: p.bar()\n -(q^-5)*T[3,1] + (q^-2)*T[1,2]\n - (q^-5-q^-4-q^-2+q^-1)*T[1]\n - (q^-5-q^-4+q^-2-q^-1-1)*T[3]\n + (q^-2-q^-1)*T[2]\n - (q^-5-2*q^-4+q^-3-1+q)\n sage: p.bar().bar() == p\n True\n\n This also works for arbitrary ``q1`` and ``q2``::\n\n sage: R.<q1,q2> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', q1, q2=-q2)\n sage: T = H.T()\n sage: T1,T2,T3 = T.algebra_generators()\n sage: p = T1*T3 + T2\n sage: p.bar()\n (q1^-2*q2^-2)*T[3,1]\n + (-q1^-1*q2^-2+q1^-2*q2^-1)*T[1]\n + (-q1^-1*q2^-2+q1^-2*q2^-1)*T[3]\n + (q1^-1*q2^-1)*T[2]\n + (-q2^-1+q1^-1+q2^-2-2*q1^-1*q2^-1+q1^-2)\n sage: p.bar().bar() == p\n True\n\n Next we have an example in the `C` basis::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: C = H.C()\n sage: p = C[1]*C[3] + C[2]\n sage: p.bar()\n C[3,1] + C[2]\n sage: p.bar().bar() == p\n True\n\n For the `C^{\\prime}` basis as well::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: Cp = H.Cp()\n sage: p = Cp[1]*Cp[3] + Cp[2]\n sage: p.bar()\n Cp[3,1] + Cp[2]\n\n TESTS:\n\n We check that doing the computations explicitly in the `T`\n basis gives the same results and with bar invariant\n coefficients::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: Cp = H.Cp()\n sage: T = H.T()\n sage: Cp(T(Cp[1,2,1])) == Cp[1,2,1]\n True\n sage: p = 4*Cp[1]*Cp[3] + (v^2 + v^-2 - 2)*Cp[2]\n sage: Cp(T(p).bar()) == p\n True\n " B = self.parent() if (B.bar_on_basis is NotImplemented): T = B.realization_of().T() return B(T(self).bar()) H = B.realization_of() return sum(((H._bar_on_coefficients(c) * B.bar_on_basis(w)) for (w, c) in self)) def hash_involution(self): "\n Return the hash involution of ``self``.\n\n The hash involution `\\alpha` is a `\\ZZ`-algebra\n involution of the Iwahori-Hecke algebra determined by\n `q^{1/2} \\mapsto q^{-1/2}`, and `T_w \\mapsto\n (-q_1 q_2)^{-\\ell(w)} T_w`, for `w` an element of the\n corresponding Coxeter group.\n\n This map is defined in [KL1979]_ and it is used to\n change between the `C` and `C^{\\prime}` bases because\n `\\alpha(C_w) = (-1)^{\\ell(w)} C_w'`.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: T = H.T()\n sage: T1,T2,T3 = T.algebra_generators()\n sage: elt = T1.hash_involution(); elt\n -(v^-2)*T[1]\n sage: elt.hash_involution()\n T[1]\n sage: elt = T1*T2 + (v^3 - v^-1 + 2)*T3*T1*T2*T3\n sage: elt.hash_involution()\n (v^-11+2*v^-8-v^-7)*T[1,2,3,2] + (v^-4)*T[1,2]\n sage: elt.hash_involution().hash_involution() == elt\n True\n\n With the Kazhdan-Lusztig `C^{\\prime}` basis::\n\n sage: Cp = H.Cp()\n sage: p = Cp[1]*Cp[3] + Cp[2]\n sage: q = p.hash_involution(); q\n Cp[3,1] - (v^-1+v)*Cp[1] - (v^-1+v)*Cp[3] - Cp[2] + (v^-2+v^-1+2+v+v^2)\n sage: q.hash_involution() == p\n True\n\n With the Kazhdan-Lusztig `C` basis::\n\n sage: C = H.C()\n sage: p = C[1]*C[3] + C[2]\n sage: q = p.hash_involution(); q\n C[3,1] + (v^-1+v)*C[1] + (v^-1+v)*C[3] - C[2] + (v^-2-v^-1+2-v+v^2)\n sage: q.hash_involution() == p\n True\n " basis = self.parent() if (basis.hash_involution_on_basis is NotImplemented): T = basis.realization_of().T() return basis(T(self).hash_involution()) H = basis.realization_of() return basis(sum(((H._bar_on_coefficients(c) * basis.hash_involution_on_basis(w)) for (w, c) in self))) def goldman_involution(self): "\n Return the Goldman involution of ``self``.\n\n The Goldman involution is the algebra involution of the\n Iwahori-Hecke algebra determined by\n\n .. MATH::\n\n T_w \\mapsto (-q_1 q_2)^{\\ell(w)} T_{w^{-1}}^{-1},\n\n where `w` is\n an element of the corresponding Coxeter group. The main point\n here is that `q_1 q_2 T_s^{-1} = -T_s + q_1 + q_2`, for\n each simple reflection `s`.\n\n This map is defined in [Iwa1964]_. The *alternating Hecke algebra*\n is the fixed-point subalgebra the Iwahori-Hecke algebra under\n this involution.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: T = H.T()\n sage: T[1].goldman_involution()\n -T[1] - (1-v^2)\n sage: T[2].goldman_involution()\n -T[2] - (1-v^2)\n sage: T[1,2].goldman_involution()\n T[1,2] + (1-v^2)*T[1] + (1-v^2)*T[2] + (1-2*v^2+v^4)\n sage: elt=T[1,2]+ v*T[1]\n sage: elt.goldman_involution()\n T[1,2] + (1-v-v^2)*T[1] + (1-v^2)*T[2] + (1-v-2*v^2+v^3+v^4)\n sage: elt.goldman_involution().goldman_involution() == elt\n True\n sage: H.A()(elt).goldman_involution()==elt.goldman_involution()\n True\n\n With different parameters::\n\n sage: H = IwahoriHeckeAlgebra('A3', q1=v, q2=-v^-1)\n sage: T = H.T()\n sage: T[1].goldman_involution()\n -T[1] - (v^-1-v)\n sage: T[2].goldman_involution()\n -T[2] - (v^-1-v)\n sage: T[1,2].goldman_involution()\n T[1,2] + (v^-1-v)*T[1] + (v^-1-v)*T[2] + (v^-2-2+v^2)\n sage: elt=T[1,2]+ v*T[1]\n sage: elt.goldman_involution()\n T[1,2] + (v^-1-2*v)*T[1] + (v^-1-v)*T[2] + (v^-2-3+2*v^2)\n sage: elt.goldman_involution().goldman_involution() == elt\n True\n sage: H.A()(elt).goldman_involution()==elt.goldman_involution()\n True\n\n With the `A` basis::\n\n sage: A = H.A()\n sage: p = A[1,3] + A[2]\n sage: q = p.goldman_involution(); q\n A[3,1] - A[2]\n sage: q.goldman_involution() == p\n True\n\n TESTS::\n\n sage: all(h.goldman_involution().goldman_involution() == h for h in T.basis()) # long time\n True\n " basis = self.parent() if hasattr(basis, 'goldman_involution_on_basis'): return basis.sum(((c * basis.goldman_involution_on_basis(w)) for (w, c) in self)) T = basis.realization_of().T() return basis(T(self).goldman_involution()) def specialize_to(self, new_hecke, num_vars=2): '\n Return the element in the Iwahori-Hecke algebra ``new_hecke``\n with respect to the same basis which is obtained from ``self``\n by specializing the generic parameters in this algebra to the\n parameters of ``new_hecke``.\n\n INPUT:\n\n - ``new_hecke`` -- the Hecke algebra in specialized parameters\n - ``num_vars`` -- the number of variables to specialize\n\n .. WARNING::\n\n This is not always defined. In particular, the number of\n generators must match ``num_vars``\n\n EXAMPLES::\n\n sage: R.<a,b> = LaurentPolynomialRing(ZZ)\n sage: H = IwahoriHeckeAlgebra("A3", a^2, -b^2)\n sage: T = H.T()\n sage: elt = T[1,2,1] + 3*T[1] - a*b*T[3]\n sage: S.<q> = LaurentPolynomialRing(ZZ)\n sage: HS = IwahoriHeckeAlgebra("A3", q^2, -1)\n sage: selt = elt.specialize_to(HS); selt\n T[1,2,1] + 3*T[1] + q^2*T[3]\n sage: GA = IwahoriHeckeAlgebra("A3", 1, -1)\n sage: elt.specialize_to(GA)\n T[1,2,1] + 3*T[1] + T[3]\n\n We need to specify that we are only specializing\n one argument::\n\n sage: selt.specialize_to(GA)\n Traceback (most recent call last):\n ...\n TypeError: Wrong number of arguments\n sage: selt.specialize_to(GA, 1)\n T[1,2,1] + 3*T[1] + T[3]\n ' q1 = new_hecke._q1 q2 = new_hecke._q2 new_basis = getattr(new_hecke, self.parent()._basis_name)() if (num_vars == 2): args = (q1, q2) elif (num_vars == 1): args = (q1,) else: return new_basis._from_dict({w: new_hecke._base(c) for (w, c) in self}) return new_basis._from_dict({w: new_hecke._base(c(args)) for (w, c) in self}) class _Basis(CombinatorialFreeModule, BindableClass): '\n Technical methods (i.e., not mathematical) that are inherited by each\n basis of the algebra. These methods cannot be defined in the category.\n ' def __init__(self, algebra, prefix=None): '\n Initialises a basis class for the Iwahori-Hecke algebra ``algebra``.\n Optionally, a ``prefix`` can be set which is used when printing the\n basis elements. The prefix defaults to ``self._basis-name``, which\n is the name of the basis class.\n\n EXAMPLES::\n\n sage: H = IwahoriHeckeAlgebra("G2",1)\n sage: t = H.T(prefix="t")\n sage: t[1]\n t[1]\n ' if (prefix is None): self._prefix = self._basis_name else: self._prefix = prefix CombinatorialFreeModule.__init__(self, algebra.base_ring(), algebra._W, category=algebra._BasesCategory(), sorting_key=sorting_key, prefix=self._prefix) _basis_name = None def _repr_term(self, t): '\n Return the string representation of the term indexed by ``t``.\n\n EXAMPLES::\n\n sage: R.<q> = QQ[]\n sage: H = IwahoriHeckeAlgebra("A3", q)\n sage: W = H.coxeter_group()\n sage: H.T()._repr_term(W.from_reduced_word([1,2,3]))\n \'T[1,2,3]\'\n ' redword = t.reduced_word() if (not redword): return '1' return (self._print_options['prefix'] + ('[%s]' % ','.join((('%d' % i) for i in redword)))) def _latex_term(self, t): '\n Return latex for the term indexed by ``t``.\n\n EXAMPLES::\n\n sage: R.<v> = QQ[]\n sage: H = IwahoriHeckeAlgebra("A3", q1=v**2, q2=-1)\n sage: W = H.coxeter_group()\n sage: H.T()._latex_term(W.from_reduced_word([1,2,3]))\n \'T_{1}T_{2}T_{3}\'\n ' redword = t.reduced_word() if (not redword): return '1' return ''.join((('%s_{%d}' % (self._print_options['prefix'], i)) for i in redword)) def product_on_basis(self, w1, w2): "\n Return the product of the two basis elements indexed by ``w1`` and\n ``w2``.\n\n The computation is actually done by converting to the\n `T`-basis, multiplying and then converting back.\n\n EXAMPLES::\n\n sage: R = LaurentPolynomialRing(QQ, 'v')\n sage: v = R.gen(0)\n sage: H = IwahoriHeckeAlgebra('A2', v**2)\n sage: s1,s2 = H.coxeter_group().simple_reflections()\n sage: [H.Cp().product_on_basis(s1,x) for x in [s1,s2]]\n [(v^-1+v)*Cp[1], Cp[1,2]]\n sage: [H.C().product_on_basis(s1,x) for x in [s1,s2]]\n [-(v^-1+v)*C[1], C[1,2]]\n " return self((self.to_T_basis(w1) * self.to_T_basis(w2))) class T(_Basis): '\n The standard basis of Iwahori-Hecke algebra.\n\n For every simple reflection `s_i` of the Coxeter group, there is a\n corresponding generator `T_i` of Iwahori-Hecke algebra. These\n are subject to the relations:\n\n .. MATH::\n\n (T_i - q_1) (T_i - q_2) = 0\n\n together with the braid relations:\n\n .. MATH::\n\n T_i T_j T_i \\cdots = T_j T_i T_j \\cdots,\n\n where the number of terms on each of the two sides is the order of\n `s_i s_j` in the Coxeter group.\n\n Weyl group elements form a basis of Iwahori-Hecke algebra `H`\n with the property that if `w_1` and `w_2` are Coxeter group elements\n such that `\\ell(w_1 w_2) = \\ell(w_1) + \\ell(w_2)` then\n `T_{w_1 w_2} = T_{w_1} T_{w_2}`.\n\n With the default value `q_2 = -1` and with `q_1 = q` the\n generating relation may be written\n `T_i^2 = (q-1) \\cdot T_i + q \\cdot 1` as in [Iwa1964]_.\n\n EXAMPLES::\n\n sage: H = IwahoriHeckeAlgebra("A3", 1)\n sage: T = H.T()\n sage: T1,T2,T3 = T.algebra_generators()\n sage: T1*T2*T3*T1*T2*T1 == T3*T2*T1*T3*T2*T3\n True\n sage: w0 = T(H.coxeter_group().long_element())\n sage: w0\n T[1,2,3,1,2,1]\n sage: T = H.T(prefix="s")\n sage: T.an_element()\n s[1,2,3] + 2*s[1] + 3*s[2] + 1\n\n TESTS::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, \'v\')\n sage: H = IwahoriHeckeAlgebra(\'A3\', v**2)\n sage: W = H.coxeter_group()\n sage: T = H.T()\n sage: C = H.C()\n sage: Cp = H.Cp()\n sage: all(T(C(T[x])) == T[x] for x in W) # long time\n True\n sage: all(T(Cp(T[x])) == T[x] for x in W) # long time\n True\n\n We check a property of the bar involution and `R`-polynomials::\n\n sage: KL = KazhdanLusztigPolynomial(W, v)\n sage: all(T[x].bar() == sum(v^(-2*y.length()) * KL.R(y, x).substitute(v=v^-2) * T[y] for y in W) for x in W) # long time\n True\n ' _basis_name = 'T' def inverse_generator(self, i): '\n Return the inverse of the `i`-th generator, if it exists.\n\n This method is only available if the Iwahori-Hecke algebra\n parameters ``q1`` and ``q2`` are both invertible. In this case,\n the algebra generators are also invertible and this method\n returns the inverse of ``self.algebra_generator(i)``.\n\n EXAMPLES::\n\n sage: P.<q1, q2>=QQ[]\n sage: F = Frac(P)\n sage: H = IwahoriHeckeAlgebra("A2", q1, q2=q2, base_ring=F).T()\n sage: H.base_ring()\n Fraction Field of Multivariate Polynomial Ring in q1, q2 over Rational Field\n sage: H.inverse_generator(1)\n -1/(q1*q2)*T[1] + ((q1+q2)/(q1*q2))\n sage: H = IwahoriHeckeAlgebra("A2", q1, base_ring=F).T()\n sage: H.inverse_generator(2)\n -(1/(-q1))*T[2] + ((q1-1)/(-q1))\n sage: P1.<r1, r2> = LaurentPolynomialRing(QQ)\n sage: H1 = IwahoriHeckeAlgebra("B2", r1, q2=r2, base_ring=P1).T()\n sage: H1.base_ring()\n Multivariate Laurent Polynomial Ring in r1, r2 over Rational Field\n sage: H1.inverse_generator(2)\n (-r1^-1*r2^-1)*T[2] + (r2^-1+r1^-1)\n sage: H2 = IwahoriHeckeAlgebra("C2", r1, base_ring=P1).T()\n sage: H2.inverse_generator(2)\n (r1^-1)*T[2] + (-1+r1^-1)\n ' A = self.realization_of() try: i1 = normalized_laurent_polynomial(A._base, (A._q1 ** (- 1))) i2 = normalized_laurent_polynomial(A._base, (A._q2 ** (- 1))) except Exception: raise ValueError(('%s and %s must be invertible' % (A._q1, A._q2))) return ((((- i1) * i2) * self.algebra_generator(i)) + (i1 + i2)) @cached_method def inverse_generators(self): '\n Return the inverses of all the generators, if they exist.\n\n This method is only available if ``q1`` and ``q2`` are invertible.\n In that case, the algebra generators are also invertible.\n\n EXAMPLES::\n\n sage: P.<q> = PolynomialRing(QQ)\n sage: F = Frac(P)\n sage: H = IwahoriHeckeAlgebra("A2", q, base_ring=F).T()\n sage: T1,T2 = H.algebra_generators()\n sage: U1,U2 = H.inverse_generators()\n sage: U1*T1,T1*U1\n (1, 1)\n sage: P1.<q> = LaurentPolynomialRing(QQ)\n sage: H1 = IwahoriHeckeAlgebra("A2", q, base_ring=P1).T(prefix="V")\n sage: V1,V2 = H1.algebra_generators()\n sage: W1,W2 = H1.inverse_generators()\n sage: [W1,W2]\n [(q^-1)*V[1] + (q^-1-1), (q^-1)*V[2] + (q^-1-1)]\n sage: V1*W1, W2*V2\n (1, 1)\n ' return Family(self.index_set(), self.inverse_generator) def product_on_basis(self, w1, w2): '\n Return `T_{w_1} T_{w_2}`, where `w_1` and `w_2` are words in the\n Coxeter group.\n\n EXAMPLES::\n\n sage: R.<q> = QQ[]; H = IwahoriHeckeAlgebra("A2", q)\n sage: T = H.T()\n sage: s1,s2 = H.coxeter_group().simple_reflections()\n sage: [T.product_on_basis(s1,x) for x in [s1,s2]]\n [(q-1)*T[1] + q, T[1,2]]\n ' result = self.monomial(w1) for i in w2.reduced_word(): result = self.product_by_generator(result, i) return result def product_by_generator_on_basis(self, w, i, side='right'): '\n Return the product `T_w T_i` (resp. `T_i T_w`) if ``side`` is\n ``\'right\'`` (resp. ``\'left\'``).\n\n If the quadratic relation is `(T_i-u)(T_i-v) = 0`, then we have\n\n .. MATH::\n\n T_w T_i = \\begin{cases}\n T_{ws_i} & \\text{if } \\ell(ws_i) = \\ell(w) + 1, \\\\\n (u+v) T_{ws_i} - uv T_w & \\text{if } \\ell(w s_i) = \\ell(w)-1.\n \\end{cases}\n\n The left action is similar.\n\n INPUT:\n\n - ``w`` -- an element of the Coxeter group\n - ``i`` -- an element of the index set\n - ``side`` -- ``\'right\'`` (default) or ``\'left\'``\n\n EXAMPLES::\n\n sage: R.<q> = QQ[]; H = IwahoriHeckeAlgebra("A2", q)\n sage: T = H.T()\n sage: s1,s2 = H.coxeter_group().simple_reflections()\n sage: [T.product_by_generator_on_basis(w, 1) for w in [s1,s2,s1*s2]]\n [(q-1)*T[1] + q, T[2,1], T[1,2,1]]\n sage: [T.product_by_generator_on_basis(w, 1, side="left") for w in [s1,s2,s1*s2]]\n [(q-1)*T[1] + q, T[1,2], (q-1)*T[1,2] + q*T[2]]\n ' wi = w.apply_simple_reflection(i, side=side) A = self.realization_of() if w.has_descent(i, side=side): return self.sum_of_terms(((w, A._q_sum), (wi, A._q_prod)), distinct=True) else: return self.monomial(wi) def product_by_generator(self, x, i, side='right'): '\n Return `T_i \\cdot x`, where `T_i` is the `i`-th generator. This is\n coded individually for use in ``x._mul_()``.\n\n EXAMPLES::\n\n sage: R.<q> = QQ[]; H = IwahoriHeckeAlgebra("A2", q).T()\n sage: T1, T2 = H.algebra_generators()\n sage: [H.product_by_generator(x, 1) for x in [T1,T2]]\n [(q-1)*T[1] + q, T[2,1]]\n sage: [H.product_by_generator(x, 1, side = "left") for x in [T1,T2]]\n [(q-1)*T[1] + q, T[1,2]]\n ' return self.linear_combination(((self.product_by_generator_on_basis(w, i, side), c) for (w, c) in x)) def to_C_basis(self, w): "\n Return `T_w` as a linear combination of `C`-basis elements.\n\n EXAMPLES::\n\n sage: R = LaurentPolynomialRing(QQ, 'v')\n sage: v = R.gen(0)\n sage: H = IwahoriHeckeAlgebra('A2', v**2)\n sage: s1,s2 = H.coxeter_group().simple_reflections()\n sage: T = H.T()\n sage: C = H.C()\n sage: T.to_C_basis(s1)\n v*T[1] + v^2\n sage: C(T(s1))\n v*C[1] + v^2\n sage: C(v^-1*T(s1) - v)\n C[1]\n sage: C(T(s1*s2)+T(s1)+T(s2)+1)\n v^2*C[1,2] + (v+v^3)*C[1] + (v+v^3)*C[2] + (1+2*v^2+v^4)\n sage: C(T(s1*s2*s1))\n v^3*C[1,2,1] + v^4*C[2,1] + v^4*C[1,2] + v^5*C[1] + v^5*C[2] + v^6\n " H = self.realization_of() generic_T = H._generic_iwahori_hecke_algebra.T() return generic_T.to_C_basis(w).specialize_to(H) def to_Cp_basis(self, w): "\n Return `T_w` as a linear combination of `C^{\\prime}`-basis\n elements.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A2', v**2)\n sage: s1,s2 = H.coxeter_group().simple_reflections()\n sage: T = H.T()\n sage: Cp = H.Cp()\n sage: T.to_Cp_basis(s1)\n v*Cp[1] - 1\n sage: Cp(T(s1))\n v*Cp[1] - 1\n sage: Cp(T(s1)+1)\n v*Cp[1]\n sage: Cp(T(s1*s2)+T(s1)+T(s2)+1)\n v^2*Cp[1,2]\n sage: Cp(T(s1*s2*s1))\n v^3*Cp[1,2,1] - v^2*Cp[2,1] - v^2*Cp[1,2] + v*Cp[1] + v*Cp[2] - 1\n " H = self.realization_of() generic_T = H._generic_iwahori_hecke_algebra.T() return generic_T.to_Cp_basis(w).specialize_to(H) def bar_on_basis(self, w): "\n Return the bar involution of `T_w`, which is `T^{-1}_{w^-1}`.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: W = H.coxeter_group()\n sage: s1,s2,s3 = W.simple_reflections()\n sage: T = H.T()\n sage: b = T.bar_on_basis(s1*s2*s3); b\n (v^-6)*T[1,2,3] + (v^-6-v^-4)*T[3,1]\n + (v^-6-v^-4)*T[1,2] + (v^-6-v^-4)*T[2,3]\n + (v^-6-2*v^-4+v^-2)*T[1] + (v^-6-2*v^-4+v^-2)*T[3]\n + (v^-6-2*v^-4+v^-2)*T[2] + (v^-6-3*v^-4+3*v^-2-1)\n sage: b.bar()\n T[1,2,3]\n " return self.monomial(w.inverse()).inverse() def hash_involution_on_basis(self, w): "\n Return the hash involution on the basis element ``self[w]``.\n\n The hash involution `\\alpha` is a `\\ZZ`-algebra\n involution of the Iwahori-Hecke algebra determined by\n `q^{1/2} \\mapsto q^{-1/2}`, and `T_w \\mapsto\n (-q_1 q_2)^{-\\ell(w)} T_w`, for `w` an element of the\n corresponding Coxeter group.\n\n This map is defined in [KL1979]_ and it is used to change between\n the `C` and `C^{\\prime}` bases because\n `\\alpha(C_w) = (-1)^{\\ell(w)}C^{\\prime}_w`.\n\n This function is not intended to be called directly. Instead, use\n :meth:`hash_involution`.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, 'v')\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: T=H.T()\n sage: s=H.coxeter_group().simple_reflection(1)\n sage: T.hash_involution_on_basis(s)\n -(v^-2)*T[1]\n sage: T[s].hash_involution()\n -(v^-2)*T[1]\n sage: h = T[1]*T[2] + (v^3 - v^-1 + 2)*T[3,1,2,3]\n sage: h.hash_involution()\n (v^-11+2*v^-8-v^-7)*T[1,2,3,2] + (v^-4)*T[1,2]\n sage: h.hash_involution().hash_involution() == h\n True\n " H = self.realization_of() return (((- H._q_prod) ** (- w.length())) * self.monomial(w)) def goldman_involution_on_basis(self, w): "\n Return the Goldman involution to the basis element\n indexed by ``w``.\n\n The goldman involution is the algebra involution of the\n Iwahori-Hecke algebra determined by\n\n .. MATH::\n\n T_w \\mapsto (-q_1 q_2)^{\\ell(w)} T_{w^{-1}}^{-1},\n\n where `w` is an element of the corresponding Coxeter group.\n\n This map is defined in [Iwa1964]_ and it is used to define the\n alternating subalgebra of the Iwahori-Hecke algebra, which is the\n fixed-point subalgebra of the Goldman involution.\n\n This function is not intended to be called directly. Instead, use\n :meth:`goldman_involution`.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, 'v')\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: T=H.T()\n sage: s=H.coxeter_group().simple_reflection(1)\n sage: T.goldman_involution_on_basis(s)\n -T[1] - (1-v^2)\n sage: T[s].goldman_involution()\n -T[1] - (1-v^2)\n sage: h = T[1]*T[2] + (v^3 - v^-1 + 2)*T[3,1,2,3]\n sage: h.goldman_involution()\n -(v^-1-2-v^3)*T[1,2,3,2]\n - (v^-1-2-v+2*v^2-v^3+v^5)*T[3,1,2]\n - (v^-1-2-v+2*v^2-v^3+v^5)*T[1,2,3]\n - (v^-1-2-v+2*v^2-v^3+v^5)*T[2,3,2]\n - (v^-1-2-2*v+4*v^2-2*v^4+2*v^5-v^7)*T[3,1]\n - (v^-1-3-2*v+4*v^2-2*v^4+2*v^5-v^7)*T[1,2]\n - (v^-1-2-2*v+4*v^2-2*v^4+2*v^5-v^7)*T[3,2]\n - (v^-1-2-2*v+4*v^2-2*v^4+2*v^5-v^7)*T[2,3]\n - (v^-1-3-2*v+5*v^2+v^3-4*v^4+v^5+2*v^6-2*v^7+v^9)*T[1]\n - (v^-1-2-3*v+6*v^2+2*v^3-6*v^4+2*v^5+2*v^6-3*v^7+v^9)*T[3]\n - (v^-1-3-3*v+7*v^2+2*v^3-6*v^4+2*v^5+2*v^6-3*v^7+v^9)*T[2]\n - (v^-1-3-3*v+8*v^2+3*v^3-9*v^4+6*v^6-3*v^7-2*v^8+3*v^9-v^11)\n sage: h.goldman_involution().goldman_involution() == h\n True\n " H = self.realization_of() return (((- H._q_prod) ** w.length()) * self.monomial(w.inverse()).inverse()) class Element(CombinatorialFreeModule.Element): '\n A class for elements of an Iwahori-Hecke algebra in the `T` basis.\n\n TESTS::\n\n sage: R.<q> = QQ[]\n sage: H = IwahoriHeckeAlgebra("B3",q).T()\n sage: T1,T2,T3 = H.algebra_generators()\n sage: T1+2*T2*T3\n 2*T[2,3] + T[1]\n sage: T1*T1\n (q-1)*T[1] + q\n\n sage: R.<q1,q2> = QQ[]\n sage: H = IwahoriHeckeAlgebra("A2", q1, q2=q2).T(prefix="x")\n sage: sum(H.algebra_generators())^2\n x[2,1] + x[1,2] + (q1+q2)*x[1] + (q1+q2)*x[2] + (-2*q1*q2)\n\n sage: H = IwahoriHeckeAlgebra("A2", q1, q2=q2).T(prefix="t")\n sage: t1,t2 = H.algebra_generators()\n sage: (t1-t2)^3\n (q1^2-q1*q2+q2^2)*t[1] + (-q1^2+q1*q2-q2^2)*t[2]\n\n sage: R.<q> = QQ[]\n sage: H = IwahoriHeckeAlgebra("G2", q).T()\n sage: [T1, T2] = H.algebra_generators()\n sage: T1*T2*T1*T2*T1*T2 == T2*T1*T2*T1*T2*T1\n True\n sage: T1*T2*T1 == T2*T1*T2\n False\n\n sage: H = IwahoriHeckeAlgebra("A2", 1).T()\n sage: [T1,T2] = H.algebra_generators()\n sage: T1+T2\n T[1] + T[2]\n\n sage: -(T1+T2)\n -T[1] - T[2]\n sage: 1-T1\n -T[1] + 1\n\n sage: T1.parent()\n Iwahori-Hecke algebra of type A2 in 1,-1 over Integer Ring in the T-basis\n ' def __invert__(self): '\n Return the inverse if ``self`` is a basis element.\n\n An element is a basis element if it is `T_w` where `w` is in\n the Weyl group. The base ring must be a field or Laurent\n polynomial ring. Other elements of the ring have inverses but\n the inverse method is only implemented for the basis elements.\n\n EXAMPLES::\n\n sage: R.<q> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra("A2", q).T()\n sage: [T1,T2] = H.algebra_generators()\n sage: x = (T1*T2).inverse(); x # indirect doctest\n (q^-2)*T[2,1] + (q^-2-q^-1)*T[1] + (q^-2-q^-1)*T[2] + (q^-2-2*q^-1+1)\n sage: x*T1*T2\n 1\n\n TESTS:\n\n We check some alternative forms of input for inverting\n an element::\n\n sage: R.<q> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra("A2", q).T()\n sage: T1,T2 = H.algebra_generators()\n sage: ~(T1*T2)\n (q^-2)*T[2,1] + (q^-2-q^-1)*T[1] + (q^-2-q^-1)*T[2] + (q^-2-2*q^-1+1)\n sage: (T1*T2)^(-1)\n (q^-2)*T[2,1] + (q^-2-q^-1)*T[1] + (q^-2-q^-1)*T[2] + (q^-2-2*q^-1+1)\n ' if (len(self) != 1): raise NotImplementedError(('inverse only implemented for basis elements (monomials in the generators)' % self)) H = self.parent() w = self.support_of_term() return H.prod((H.inverse_generator(i) for i in reversed(w.reduced_word()))) standard = T class _KLHeckeBasis(_Basis): '\n Abstract class for the common methods for the Kazhdan-Lusztig `C` and\n `C^{\\prime}` bases.\n ' def __init__(self, IHAlgebra, prefix=None): "\n Initialize the Kazhdan-Lusztig basis of the Iwahori-Hecke\n algebra ``IHAlgebra``.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: Cp = H.Cp()\n sage: C = H.C()\n " if (IHAlgebra._root is None): raise ValueError('The Kazhdan_Lusztig bases are defined only when -q_1*q_2 is a square') if IHAlgebra._is_generic: klbasis = IwahoriHeckeAlgebra_nonstandard._KLHeckeBasis else: klbasis = IwahoriHeckeAlgebra._KLHeckeBasis super(klbasis, self).__init__(IHAlgebra, prefix) self.module_morphism(self.to_T_basis, codomain=IHAlgebra.T(), category=self.category()).register_as_coercion() T = IHAlgebra.T() T.module_morphism(getattr(T, 'to_{}_basis'.format(self._basis_name)), codomain=self, category=self.category()).register_as_coercion() def bar_on_basis(self, w): "\n Return the bar involution on the Kazhdan-Lusztig basis element\n indexed by ``w``. By definition, all Kazhdan-Lusztig basis elements\n are fixed by the bar involution.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: W = H.coxeter_group()\n sage: s1,s2,s3 = W.simple_reflections()\n sage: Cp = H.Cp()\n sage: Cp.bar_on_basis(s1*s2*s1*s3)\n Cp[1,2,3,1]\n " return self.monomial(w) def to_T_basis(self, w): '\n Return the Kazhdan-Lusztig basis element ``self[w]`` as a linear\n combination of ``T``-basis elements.\n\n EXAMPLES::\n\n sage: H=IwahoriHeckeAlgebra("A3",1); Cp=H.Cp(); C=H.C()\n sage: s=H.coxeter_group().simple_reflection(1)\n sage: C.to_T_basis(s)\n T[1] - 1\n sage: Cp.to_T_basis(s)\n T[1] + 1\n ' H = self.realization_of() generic_KL = getattr(H._generic_iwahori_hecke_algebra, self._basis_name)() return generic_KL.to_T_basis(w).specialize_to(H) class Cp(_KLHeckeBasis): '\n The `C^{\\prime}` Kazhdan-Lusztig basis of Iwahori-Hecke algebra.\n\n Assuming the standard quadratic relations of `(T_r-q)(T_r+1)=0`, for\n every element `w` in the Coxeter group, there is a unique element\n `C^{\\prime}_w` in the Iwahori-Hecke algebra which is uniquely determined\n by the two properties:\n\n .. MATH::\n\n \\begin{aligned}\n \\overline{ C^{\\prime}_w } &= C^{\\prime}_w, \\\\\n C^{\\prime}_w &= q^{-\\ell(w)/2}\n \\sum_{v \\leq w} P_{v,w}(q) T_v,\n \\end{aligned}\n\n where `\\leq` is the Bruhat order on the underlying Coxeter group and\n `P_{v,w}(q) \\in \\ZZ[q,q^{-1}]` are polynomials in `\\ZZ[q]` such that\n `P_{w,w}(q) = 1` and if `v < w` then `\\deg P_{v,w}(q) \\leq\n \\frac{1}{2}(\\ell(w)-\\ell(v)-1)`.\n\n More generally, if the quadratic relations are of the form\n (T_s-q_1)(T_s-q_2)=0` and `\\sqrt{-q_1q_2}` exists then, for a simple\n reflection `s`, the corresponding Kazhdan-Lusztig basis element is:\n\n .. MATH::\n\n C^{\\prime}_s = (-q_1 q_2)^{-1/2} (T_s + 1).\n\n See [KL1979]_ for more details.\n\n If the optional ``coxeter3`` package is available and the\n Iwahori--Hecke algebra was initialized in the "standard" presentation\n where `\\{q_1,q_2\\} = \\{v^2,1\\}` as sets or the "normalized"\n presentation where `\\{q_1,q_2\\} = \\{v,-v^{-1}\\}` as sets, the function\n :func:`product_on_basis` in this class computes products in the\n `C^{\\prime}`-basis directly in the basis itself, using ``coxeter3`` to\n calculate certain `\\mu`-coefficients quickly. If the above conditions\n are not all met, the function computes such products indirectly, by\n converting elements to the `T`-basis, computing products there, and\n converting back. The indirect method can be prohibitively slow for\n more complex calculations; the direct method is faster.\n\n EXAMPLES::\n\n sage: R = LaurentPolynomialRing(QQ, \'v\')\n sage: v = R.gen(0)\n sage: H = IwahoriHeckeAlgebra(\'A5\', v**2)\n sage: W = H.coxeter_group()\n sage: s1,s2,s3,s4,s5 = W.simple_reflections()\n sage: T = H.T()\n sage: Cp = H.Cp()\n sage: T(s1)**2\n -(1-v^2)*T[1] + v^2\n sage: T(Cp(s1))\n (v^-1)*T[1] + (v^-1)\n sage: T(Cp(s1)*Cp(s2)*Cp(s1))\n (v^-3)*T[1,2,1] + (v^-3)*T[2,1] + (v^-3)*T[1,2]\n + (v^-3+v^-1)*T[1] + (v^-3)*T[2] + (v^-3+v^-1)\n\n ::\n\n sage: R = LaurentPolynomialRing(QQ, \'v\')\n sage: v = R.gen(0)\n sage: H = IwahoriHeckeAlgebra(\'A3\', v**2)\n sage: W = H.coxeter_group()\n sage: s1,s2,s3 = W.simple_reflections()\n sage: Cp = H.Cp()\n sage: Cp(s1*s2*s1)\n Cp[1,2,1]\n sage: Cp(s1)**2\n (v^-1+v)*Cp[1]\n sage: Cp(s1)*Cp(s2)*Cp(s1)\n Cp[1,2,1] + Cp[1]\n sage: Cp(s1)*Cp(s2)*Cp(s3)*Cp(s1)*Cp(s2) # long time\n Cp[1,2,3,1,2] + Cp[1,2,1] + Cp[3,1,2]\n\n In the following product computations, whether ``coxeter3`` is\n installed makes a big difference: without ``coxeter3`` the product in\n type `H_4` takes about 5 seconds to compute and the product in type\n `A_9` seems infeasible, while with ``coxeter3`` both the computations\n are instant::\n\n sage: H = IwahoriHeckeAlgebra(\'H4\', v**2) # optional - coxeter3\n sage: Cp = H.Cp() # optional - coxeter3\n sage: Cp[3,4,3]*Cp[3,4,3,4]*Cp[1,2,3,4] # optional - coxeter3\n (v^-2+2+v^2)*Cp[3,4,3,4,1,2,3,4,2]\n + (v^-2+2+v^2)*Cp[3,4,3,4,3,1,2]\n + (v^-3+3*v^-1+3*v+v^3)*Cp[3,4,3,4,3,1]\n + (v^-1+v)*Cp[3,4,1,2,3,4]\n + (v^-1+v)*Cp[3,4,1,2]\n\n sage: H = IwahoriHeckeAlgebra(\'A9\', v**2) # optional - coxeter3\n sage: Cp = H.Cp() # optional - coxeter3\n sage: Cp[1,2,1,8,9,8]*Cp[1,2,3,7,8,9] # optional - coxeter3\n (v^-2+2+v^2)*Cp[7,8,9,7,8,7,1,2,3,1]\n + (v^-2+2+v^2)*Cp[8,9,8,7,1,2,3,1]\n + (v^-3+3*v^-1+3*v+v^3)*Cp[8,9,8,1,2,3,1]\n\n To use ``coxeter3`` for product computations most efficiently, we\n recommend creating the Iwahori-Hecke algebra from a Coxeter group\n implemented with ``coxeter3`` to avoid unnecessary conversions, as in\n the following example with the same product computed in the last one::\n\n sage: # optional - coxeter3\n sage: R = LaurentPolynomialRing(QQ, \'v\')\n sage: v = R.gen(0)\n sage: W = CoxeterGroup(\'A9\', implementation=\'coxeter3\')\n sage: H = IwahoriHeckeAlgebra(W, v**2)\n sage: Cp = H.Cp()\n sage: Cp[1,2,1,8,9,8]*Cp[1,2,3,7,8,9]\n (v^-2+2+v^2)*Cp[1,2,1,3,7,8,7,9,8,7]\n + (v^-2+2+v^2)*Cp[1,2,1,3,8,9,8,7]\n + (v^-3+3*v^-1+3*v+v^3)*Cp[1,2,1,3,8,9,8]\n\n TESTS::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, \'v\')\n sage: H = IwahoriHeckeAlgebra(\'A3\', v**2)\n sage: W = H.coxeter_group()\n sage: T = H.T()\n sage: C = H.C()\n sage: Cp = H.Cp()\n sage: all(Cp(T(Cp[x])) == Cp[x] for x in W) # long time\n True\n sage: all(Cp(C(Cp[x])) == Cp[x] for x in W) # long time\n True\n ' _basis_name = 'Cp' def __init__(self, IHAlgebra, prefix=None): "\n TESTS::\n\n sage: # optional - coxeter3\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: W = CoxeterGroup('A3', implementation='coxeter3')\n sage: H = IwahoriHeckeAlgebra(W, v**2)\n sage: Cp = H.Cp()\n sage: Cp._delta == v + ~v\n True\n sage: Cp._W_Coxeter3 == H._W\n True\n sage: H = IwahoriHeckeAlgebra(W, QQ(1))\n sage: Cp = H.Cp()\n sage: Cp._W_Coxeter3 is None\n True\n " super().__init__(IHAlgebra, prefix) self._W_Coxeter3 = None v = IHAlgebra.base_ring().gen(0) parameters = {IHAlgebra.q1(), IHAlgebra.q2()} if ((v == IHAlgebra.base_ring().one()) or ((parameters != {(v ** 2), (- 1)}) and (parameters != {v, ((- 1) / v)}))): return try: from sage.libs.coxeter3.coxeter_group import CoxeterGroup as Coxeter3Group except ImportError: return self._delta = (v + (~ v)) if isinstance(IHAlgebra._W, Coxeter3Group): self._W_Coxeter3 = IHAlgebra._W else: self._W_Coxeter3 = CoxeterGroup(IHAlgebra._W.coxeter_type(), implementation='coxeter3') def hash_involution_on_basis(self, w): "\n Return the effect of applying the hash involution to the basis\n element ``self[w]``.\n\n This function is not intended to be called directly. Instead, use\n :meth:`hash_involution`.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, 'v')\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: Cp=H.Cp()\n sage: s=H.coxeter_group().simple_reflection(1)\n sage: Cp.hash_involution_on_basis(s)\n -Cp[1] + (v^-1+v)\n sage: Cp[s].hash_involution()\n -Cp[1] + (v^-1+v)\n " return (((- 1) ** w.length()) * self(self.realization_of().C().monomial(w))) def product_on_basis(self, w1, w2): '\n Return the expansion of `C^{\\prime}_{w_1} \\cdot C^{\\prime}_{w_2}`\n in the `C^{\\prime}`-basis.\n\n If ``coxeter3`` is installed and the Iwahori--Hecke algebra is in\n the standard or normalized presentation, the product is computed\n directly using the method described in ALGORITHM. If not, the\n product is computed indirectly by converting the factors to the\n `T`-basis, computing the product there, and converting back.\n\n The following formulas for products of the forms `C^{\\prime}_s\n \\cdot C^{\\prime}_w` and `C^{\\prime}_w \\cdot C^{\\prime}_s`, where\n `s` is a generator of the Coxeter group and `w` an arbitrary\n element, are key to the direct computation method. The formulas are\n valid for both the standard and normalized presentation of the\n Hecke algebra.\n\n .. MATH::\n\n C^{\\prime}_s \\cdot C^{\\prime}_w = \\begin{cases}\n (q+q^{-1})C^{\\prime}_{w}, & \\text{if } \\ell(sw) = \\ell(w)-1,\\\\\n C^{\\prime}_{sw}+\\sum_{v\\leq w, sv \\leq v} \\mu(v,w)C^{\\prime}_v,\n & \\text{if } \\ell(sw) = \\ell(w)+1.\n \\end{cases}\n\n \\qquad\\qquad\n\n C^{\\prime}_w \\cdot C^{\\prime}_s = \\begin{cases}\n (q+q^{-1})C^{\\prime}_{w}, & \\text{if } \\ell(ws) = \\ell(w)-1,\\\\\n C^{\\prime}_{ws}+\\sum_{v\\leq w, vs \\leq v} \\mu(v,w)C^{\\prime}_v,\n & \\text{if } \\ell(ws) = \\ell(w)+1.\n \\end{cases}\n\n In the above, `\\leq` is the Bruhat order on the Coxeter group and\n `\\mu(v,w)` is the "leading coefficient of Kazhdan-Lusztig\n polynomials"; see [KL1979]_ and [Lus2013]_ for more details. The\n method designates the computation of the `\\mu`-coefficients to\n Sage\'s interface to Fokko du Cloux\'s ``coxeter3`` package, which is\n why the method requires the creation of the Coxeter group using the\n ``\'coxeter3\'`` implementation.\n\n ALGORITHM:\n\n The direct algorithm for computing `C^{\\prime}_x \\cdot\n C^{\\prime}_y` runs in two steps as follows.\n\n If `\\ell(x) \\leq \\ell(y)`, we first decompose `C^{\\prime}_x` into\n a polynomial in the generators `C^{\\prime}_s (s\\in S)` and then\n multiply that polynomial with `C^{\\prime}_y`. If `\\ell(x) >\n \\ell(y)`, we decompose `C^{\\prime}_y` into a polynomial in\n `C^{\\prime}_s (s\\in S)` and multiply that polynomial with\n `C^{\\prime}_x`. The second step (multiplication) is done by\n repeatedly applying the formulas displayed earlier directly. The\n first step (decomposition) is done by induction on the Bruhat order\n as follows: for every element `u\\in W` with length `\\ell(u)>1`,\n pick a left descent `s` of `u` and write `u=sw` (so `w=su`), then\n note that\n\n .. MATH::\n\n C^{\\prime}_u = C^{\\prime}_s \\cdot C^{\\prime}_{w}\n - \\sum_{v \\le u; sv < v} \\mu(v,w) C^{\\prime}_v\n\n by the earlier formulas, where the element `w` and all elements\n `v`\'s on the right side are lower than `u` in the Bruhat order;\n this allows us to finish the computation by decomposing the lower\n order terms `C^{\\prime}_w` and each `C^{\\prime}_v`. For example,\n for `u=121, s=1, w=21` in type `A_3` we have `C^{\\prime}_{121} =\n C^{\\prime}_1 C^{\\prime}_{21} - C^{\\prime}_1`, where the lower\n order term `C^{\\prime}_{21}` further decomposes into `C^{\\prime}_2\n C^{\\prime}_1`, therefore\n\n .. MATH::\n\n C^{\\prime}_{121} = C^{\\prime}_1 C^{\\prime}_2 C^{\\prime}_1\n - C^{\\prime}_1.\n\n We note that the base cases `\\ell(x)=1` or `\\ell(x)=0` of the above\n induction occur when `x` is itself a Coxeter generator `s` or the\n group identity, respectively. The decomposition is trivial in these\n cases (we have `C^{\\prime}_x=C^{\\prime}_s` or `C^{\\prime}_x=1`, the\n unit of the Hecke algebra).\n\n EXAMPLES::\n\n sage: # optional - coxeter3\n sage: R.<v> = LaurentPolynomialRing(ZZ, \'v\')\n sage: W = CoxeterGroup(\'A3\', implementation=\'coxeter3\')\n sage: H = IwahoriHeckeAlgebra(W, v**2); Cp=H.Cp()\n sage: Cp.product_on_basis(W([1,2,1]), W([3,1]))\n (v^-1+v)*Cp[1,2,1,3]\n sage: Cp.product_on_basis(W([1,2,1]), W([3,1,2]))\n (v^-1+v)*Cp[1,2,1,3,2] + (v^-1+v)*Cp[1,2,1]\n ' if (self._W_Coxeter3 is None): return super().product_on_basis(w1, w2) if (self._W_Coxeter3 != self.realization_of()._W): w1 = self._W_Coxeter3.from_reduced_word(w1.reduced_word()) w2 = self._W_Coxeter3.from_reduced_word(w2.reduced_word()) if (len(w1) <= len(w2)): side = 'left' gen_expression = self._decompose_into_generators(w1) other_element = self.monomial(w2) else: side = 'right' gen_expression = self._decompose_into_generators(w2) other_element = self.monomial(w1) result = self.zero() for (p, coeff) in gen_expression.items(): summand = (coeff * other_element) if (side == 'right'): for s in p: summand = self._product_with_generator(s, summand, side) else: for s in reversed(p): summand = self._product_with_generator(s, summand, side) result += summand if (self._W_Coxeter3 != self.realization_of()._W): _W = self.realization_of()._W result = self._from_dict({_W.from_reduced_word(w.reduced_word()): c for (w, c) in result}, remove_zeros=False) return result def _product_with_generator_on_basis(self, s, w, side='left'): "\n Compute the product of `C^{\\prime}_s` and `C^{\\prime}_w`, putting\n `C^{\\prime}_s` on the given ``side``.\n\n INPUT:\n\n - ``s`` -- integer in ``self.index_set()``\n - ``w`` -- a word in ``self.coxeter_group()``\n - ``side`` -- string; ``'left'`` or ``'right'``\n\n EXAMPLES::\n\n sage: # optional - coxeter3\n sage: R.<v> = LaurentPolynomialRing(ZZ, 'v')\n sage: W = CoxeterGroup('A3', implementation='coxeter3')\n sage: H = IwahoriHeckeAlgebra(W, v**2); Cp = H.Cp()\n sage: Cp._product_with_generator_on_basis(1, W([2,1]), 'left')\n Cp[1,2,1] + Cp[1]\n sage: Cp._product_with_generator_on_basis(1, W([2,1]), 'right')\n (v^-1+v)*Cp[2,1]\n sage: Cp._product_with_generator_on_basis(2, W([1,3,2,1,3]), 'right')\n Cp[1,2,1,3,2,1] + Cp[1,2,3,2] + Cp[1,3,2,1]\n " if w.has_descent(s, side=side): return self._from_dict({w: self._delta}, remove_zeros=False) element = {} between = self._W_Coxeter3.bruhat_interval([], w) R = self.base_ring() for x in between: x_elt = self._W_Coxeter3(x) if x_elt.has_descent(s, side=side): coeff = R(x.mu_coefficient(w)) if coeff: element[x_elt] = coeff longer_word = ((self._W_Coxeter3([s]) * w) if (side == 'left') else (w * self._W_Coxeter3([s]))) element[longer_word] = R.one() return self._from_dict(element, remove_zeros=False) def _product_with_generator(self, s, x, side='left'): "\n Compute the product of `C^{\\prime}_s` with any linear\n combination of `C^{\\prime}`-basis elements.\n\n INPUT:\n\n - ``s`` -- integer in ``self.index_set()``\n - ``x`` -- any element of ``self``\n - ``side`` -- string; ``'left'`` or ``'right'``\n\n EXAMPLES::\n\n sage: # optional - coxeter3\n sage: R.<v> = LaurentPolynomialRing(ZZ, 'v')\n sage: W = CoxeterGroup('A3', implementation='coxeter3')\n sage: H = IwahoriHeckeAlgebra(W, v**2); Cp = H.Cp()\n sage: Cp._product_with_generator(1, Cp[1]+Cp[2], 'left')\n Cp[1,2] + (v^-1+v)*Cp[1]\n sage: Cp._product_with_generator(1, Cp[1]+Cp[2], 'right')\n Cp[2,1] + (v^-1+v)*Cp[1]\n " return self.linear_combination(((self._product_with_generator_on_basis(s, w, side), coeff) for (w, coeff) in x)) def _decompose_into_generators(self, u): "\n Decompose `C^{\\prime}_u` into a polynomial in the KL generators\n `C^{\\prime}_s`; see the ALGORITHM section of\n :func:`product_on_basis`.\n\n OUTPUT:\n\n A dictionary keyed by tuples with integer values. Each entry\n represents a term, where the tuple represents a monomial term\n in the KL generators and the value represents the coefficient\n of that term. For example, an item `(1,2): 3` stands for\n `3 \\cdot C^{\\prime}_1 C^{\\prime}_2`.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(ZZ, 'v') # optional - coxeter3\n sage: W = CoxeterGroup('A3', implementation='coxeter3') # optional - coxeter3\n sage: H = IwahoriHeckeAlgebra(W, v**2); Cp=H.Cp() # optional - coxeter3\n\n When `u` is itself a generator `s`, the decomposition is trivial::\n\n sage: Cp._decompose_into_generators(W([1])) # optional - coxeter3\n {(1,): 1}\n\n Another example, where `C^{\\prime}_u` happens to be a monomial\n (e.g., `C'_{21} = C'_2 C'_1`)::\n\n sage: Cp._decompose_into_generators(W([2,1])) # optional - coxeter3\n {(2, 1): 1}\n\n In more general situations the sum is a polynomial (e.g.,\n `C'_{121} = C'_1 C'_2 C'_1 - C'_1)`::\n\n sage: Cp._decompose_into_generators(W([1,2,1])) # optional - coxeter3\n {(1,): -1, (1, 2, 1): 1}\n sage: Cp._decompose_into_generators(W([1,2,3,1,2])) # optional - coxeter3\n {(1,): 1, (1, 2, 1): -1, (1, 2, 1, 3, 2): 1, (1, 3, 2): -1}\n\n TESTS::\n\n sage: Cp._decompose_into_generators(W([])) # optional - coxeter3\n {(): 1}\n " if (not len(u)): return {(): 1} if (len(u) == 1): return {(u[0],): 1} s = u[0] w = u[1:] sum_term = {} between = self._W_Coxeter3.bruhat_interval([], w) R = self.base_ring() for v in between: v_elt = self._W_Coxeter3(v) if v_elt.has_left_descent(s): coeff = R(v.mu_coefficient(w)) if coeff: sum_term[v_elt] = coeff result = {((s,) + gens): coeff for (gens, coeff) in self._decompose_into_generators(w).items()} zero = R.zero() for (z, c1) in sum_term.items(): for (gens, c2) in self._decompose_into_generators(z).items(): result[gens] = (result.get(gens, zero) - (c1 * c2)) return result C_prime = Cp class C(_KLHeckeBasis): "\n The Kazhdan-Lusztig `C`-basis of Iwahori-Hecke algebra.\n\n Assuming the standard quadratic relations of `(T_r-q)(T_r+1)=0`, for\n every element `w` in the Coxeter group, there is a unique element\n `C_w` in the Iwahori-Hecke algebra which is uniquely determined\n by the two properties:\n\n .. MATH::\n\n \\begin{aligned}\n \\overline{C_w} &= C_w \\\\\n C_w &= (-1)^{\\ell(w)} q^{\\ell(w)/2}\n \\sum_{v \\leq w} (-q)^{-\\ell(v)}\\overline{P_{v,w}(q)} T_v\n \\end{aligned}\n\n where `\\leq` is the Bruhat order on the underlying Coxeter group and\n `P_{v,w}(q)\\in\\ZZ[q,q^{-1}]` are polynomials in `\\ZZ[q]` such that\n `P_{w,w}(q) = 1` and if `v < w` then\n `\\deg P_{v,w}(q) \\leq \\frac{1}{2}(\\ell(w) - \\ell(v) - 1)`.\n This is related to the `C^{\\prime}` Kazhdan-Lusztig basis by `C_i =\n -\\alpha(C_i^{\\prime})` where `\\alpha` is the `\\ZZ`-linear Hecke\n involution defined by `q^{1/2} \\mapsto q^{-1/2}` and `\\alpha(T_i) =\n -(q_1 q_2)^{-1/2} T_i`.\n\n More generally, if the quadratic relations are of the form\n (T_s-q_1)(T_s-q_2)=0` and `\\sqrt{-q_1q_2}` exists then, for a simple\n reflection `s`, the corresponding Kazhdan-Lusztig basis element is:\n\n .. MATH::\n\n C_s = (-q_1 q_2)^{1/2} (1 - (-q_1 q_2)^{-1/2} T_s).\n\n See [KL1979]_ for more details.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A5', v**2)\n sage: W = H.coxeter_group()\n sage: s1,s2,s3,s4,s5 = W.simple_reflections()\n sage: T = H.T()\n sage: C = H.C()\n sage: T(s1)**2\n -(1-v^2)*T[1] + v^2\n sage: T(C(s1))\n (v^-1)*T[1] - v\n sage: T(C(s1)*C(s2)*C(s1))\n (v^-3)*T[1,2,1] - (v^-1)*T[2,1] - (v^-1)*T[1,2]\n + (v^-1+v)*T[1] + v*T[2] - (v+v^3)\n\n ::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: W = H.coxeter_group()\n sage: s1,s2,s3 = W.simple_reflections()\n sage: C = H.C()\n sage: C(s1*s2*s1)\n C[1,2,1]\n sage: C(s1)**2\n -(v^-1+v)*C[1]\n sage: C(s1)*C(s2)*C(s1)\n C[1,2,1] + C[1]\n\n TESTS::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, 'v')\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: W = H.coxeter_group()\n sage: T = H.T()\n sage: C = H.C()\n sage: Cp = H.Cp()\n sage: all(C(T(C[x])) == C[x] for x in W) # long time\n True\n sage: all(C(Cp(C[x])) == C[x] for x in W) # long time\n True\n\n Check the defining property between `C` and `C^{\\prime}`::\n\n sage: T(C[1])\n (v^-1)*T[1] - v\n sage: -T(Cp[1]).hash_involution()\n (v^-1)*T[1] - v\n sage: T(Cp[1] + Cp[2]).hash_involution()\n -(v^-1)*T[1] - (v^-1)*T[2] + 2*v\n sage: -T(C[1] + C[2])\n -(v^-1)*T[1] - (v^-1)*T[2] + 2*v\n sage: Cp(-C[1].hash_involution())\n Cp[1]\n sage: Cp(-C[1,2,3].hash_involution())\n Cp[1,2,3]\n sage: Cp(C[1,2,1,3].hash_involution())\n Cp[1,2,3,1]\n sage: all(C((-1)**x.length()*Cp[x].hash_involution()) == C[x] for x in W) # long time\n True\n " _basis_name = 'C' def hash_involution_on_basis(self, w): "\n Return the effect of applying the hash involution to the basis\n element ``self[w]``.\n\n This function is not intended to be called directly. Instead, use\n :meth:`hash_involution`.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, 'v')\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: C=H.C()\n sage: s=H.coxeter_group().simple_reflection(1)\n sage: C.hash_involution_on_basis(s)\n -C[1] - (v^-1+v)\n sage: C[s].hash_involution()\n -C[1] - (v^-1+v)\n " return (((- 1) ** w.length()) * self(self.realization_of().Cp().monomial(w))) class A(_Basis): "\n The `A`-basis of an Iwahori-Hecke algebra.\n\n The `A`-basis of the Iwahori-Hecke algebra is the simplest basis\n that is invariant under the Goldman involution `\\#`, up to sign.\n For `w` in the underlying Coxeter group define:\n\n .. MATH::\n\n A_w = T_w + (-1)^{\\ell(w)}T_w^{\\#}\n = T_w + (-1)^{\\ell(w)}T_{w^{-1}}^{-1}\n\n This gives a basis of the Iwahori-Hecke algebra whenever 2 is a unit\n in the base ring. The `A`-basis induces a `\\ZZ / 2\\ZZ`-grading\n on the Iwahori-Hecke algebra.\n\n The `A`-basis is a basis only when `2` is invertible. An error\n is raised whenever `2` is not a unit in the base ring.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, 'v')\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: A=H.A(); T=H.T()\n sage: T(A[1])\n T[1] + (1/2-1/2*v^2)\n sage: T(A[1,2])\n T[1,2] + (1/2-1/2*v^2)*T[1] + (1/2-1/2*v^2)*T[2] + (1/2-v^2+1/2*v^4)\n sage: A[1]*A[2]\n A[1,2] - (1/4-1/2*v^2+1/4*v^4)\n\n TESTS::\n\n sage: R.<v> = LaurentPolynomialRing(GF(2), 'v')\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: H.A()\n Traceback (most recent call last):\n ...\n TypeError: the A-basis is defined only when 2 is invertible\n " _basis_name = 'A' def __init__(self, IHAlgebra, prefix=None): "\n Initialize the `A`-basis of the Iwahori-Hecke algebra ``IHAlgebra``.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: A = H.A()\n " R = IHAlgebra.base_ring() try: R((R.one() / 2)) except (TypeError, ZeroDivisionError): raise TypeError('the A-basis is defined only when 2 is invertible') super().__init__(IHAlgebra, prefix) from_A_to_T = self.module_morphism(self.to_T_basis, codomain=IHAlgebra.T(), triangular='lower', key=sorting_key, category=self.category()) from_A_to_T.register_as_coercion() from_T_to_A = (~ from_A_to_T) from_T_to_A.register_as_coercion() def to_T_basis(self, w): "\n Return the `A`-basis element ``self[w]`` as a linear\n combination of `T`-basis elements.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2); A=H.A(); T=H.T()\n sage: s=H.coxeter_group().simple_reflection(1)\n sage: A.to_T_basis(s)\n T[1] + (1/2-1/2*v^2)\n sage: T(A[1,2])\n T[1,2] + (1/2-1/2*v^2)*T[1] + (1/2-1/2*v^2)*T[2] + (1/2-v^2+1/2*v^4)\n sage: A(T[1,2])\n A[1,2] - (1/2-1/2*v^2)*A[1] - (1/2-1/2*v^2)*A[2]\n " T = self.realization_of().T() return ((T.monomial(w) + (((- 1) ** w.length()) * T.goldman_involution_on_basis(w))) / 2) def goldman_involution_on_basis(self, w): "\n Return the effect of applying the Goldman involution to the basis\n element ``self[w]``.\n\n This function is not intended to be called directly. Instead, use\n :meth:`goldman_involution`.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, 'v')\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: A=H.A()\n sage: s=H.coxeter_group().simple_reflection(1)\n sage: A.goldman_involution_on_basis(s)\n -A[1]\n sage: A[1,2].goldman_involution()\n A[1,2]\n " return (((- 1) ** w.length()) * self.monomial(w)) class B(_Basis): "\n The `B`-basis of an Iwahori-Hecke algebra.\n\n The `B`-basis is the unique basis of the Iwahori-Hecke algebra that\n is invariant under the Goldman involution, up to sign, and invariant\n under the Kazhdan-Lusztig bar involution. In the generic case, the\n `B`-basis becomes the group basis of the group algebra of the Coxeter\n group the `B`-basis upon setting the Hecke parameters equal to `1`.\n If `w` is an element of the corresponding Coxeter group then\n the `B`-basis element `B_w` is uniquely determined by the conditions\n that `B_w^{\\#} = (-1)^{\\ell(w)} B_w`, where `\\#` is the\n :meth:`Goldman involution <goldman_involution>` and\n\n .. MATH::\n\n B_w = T_w + \\sum_{v<w}b_{vw}(q) T_v\n\n where `b_{vw}(q) \\neq 0` only if `v < w` in the Bruhat order and\n `\\ell(v) \\not\\equiv \\ell(w) \\pmod 2`.\n\n This gives a basis of the Iwahori-Hecke algebra whenever `2` is a\n unit in the base ring. The `B`-basis induces a `\\ZZ / 2 \\ZZ`-grading\n on the Iwahori-Hecke algebra. The `B`-basis elements are also\n invariant under the Kazhdan-Lusztig bar involution and hence\n are related to the Kazhdan-Lusztig bases.\n\n The `B`-basis is a basis only when `2` is invertible. An error\n is raised whenever `2` is not a unit in the base ring.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, 'v')\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: A=H.A(); T=H.T(); Cp=H.Cp()\n sage: T(A[1])\n T[1] + (1/2-1/2*v^2)\n sage: T(A[1,2])\n T[1,2] + (1/2-1/2*v^2)*T[1] + (1/2-1/2*v^2)*T[2] + (1/2-v^2+1/2*v^4)\n sage: A[1]*A[2]\n A[1,2] - (1/4-1/2*v^2+1/4*v^4)\n sage: Cp(A[1]*A[2])\n v^2*Cp[1,2] - (1/2*v+1/2*v^3)*Cp[1] - (1/2*v+1/2*v^3)*Cp[2]\n + (1/4+1/2*v^2+1/4*v^4)\n sage: Cp(A[1])\n v*Cp[1] - (1/2+1/2*v^2)\n sage: Cp(A[1,2])\n v^2*Cp[1,2] - (1/2*v+1/2*v^3)*Cp[1]\n - (1/2*v+1/2*v^3)*Cp[2] + (1/2+1/2*v^4)\n sage: Cp(A[1,2,1])\n v^3*Cp[1,2,1] - (1/2*v^2+1/2*v^4)*Cp[2,1]\n - (1/2*v^2+1/2*v^4)*Cp[1,2] + (1/2*v+1/2*v^5)*Cp[1]\n + (1/2*v+1/2*v^5)*Cp[2] - (1/2+1/2*v^6)\n\n TESTS::\n\n sage: R.<v> = LaurentPolynomialRing(ZZ, 'v')\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: H.B()\n Traceback (most recent call last):\n ...\n TypeError: the B-basis is defined only when 2 is invertible\n " _basis_name = 'B' def __init__(self, IHAlgebra, prefix=None): "\n Initialize the `B`-basis of the Iwahori-Hecke algebra ``IHAlgebra``.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: B = H.B()\n " R = IHAlgebra.base_ring() try: R((R.one() / 2)) except (TypeError, ZeroDivisionError): raise TypeError('the B-basis is defined only when 2 is invertible') super().__init__(IHAlgebra, prefix) from_B_to_T = self.module_morphism(self.to_T_basis, codomain=IHAlgebra.T(), triangular='lower', key=sorting_key, category=self.category()) from_B_to_T.register_as_coercion() from_T_to_B = (~ from_B_to_T) from_T_to_B.register_as_coercion() @cached_method def to_T_basis(self, w): "\n Return the `B`-basis element ``self[w]`` as a linear\n combination of `T`-basis elements.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ)\n sage: H = IwahoriHeckeAlgebra('A3', v**2); B=H.B(); T=H.T()\n sage: s=H.coxeter_group().simple_reflection(1)\n sage: B.to_T_basis(s)\n T[1] + (1/2-1/2*v^2)\n sage: T(B[1,2])\n T[1,2] + (1/2-1/2*v^2)*T[1] + (1/2-1/2*v^2)*T[2]\n sage: B(T[1,2])\n B[1,2] - (1/2-1/2*v^2)*B[1] - (1/2-1/2*v^2)*B[2] + (1/2-v^2+1/2*v^4)\n " T = self.realization_of().T() Bw = T(self.realization_of().A()[w]) odd = [v for v in Bw.support() if ((v != w) and (not ((v.length() - w.length()) % 2)))] return (Bw - T.sum(((Bw.coefficient(v) * self.to_T_basis(v)) for v in odd))) def goldman_involution_on_basis(self, w): "\n Return the Goldman involution to the basis element\n indexed by ``w``.\n\n This function is not intended to be called directly. Instead, use\n :meth:`goldman_involution`.\n\n EXAMPLES::\n\n sage: R.<v> = LaurentPolynomialRing(QQ, 'v')\n sage: H = IwahoriHeckeAlgebra('A3', v**2)\n sage: B=H.B()\n sage: s=H.coxeter_group().simple_reflection(1)\n sage: B.goldman_involution_on_basis(s)\n -B[1]\n sage: B[1,2].goldman_involution()\n B[1,2]\n " return (((- 1) ** w.length()) * self.monomial(w))
class IwahoriHeckeAlgebra_nonstandard(IwahoriHeckeAlgebra): '\n This is a class which is used behind the scenes by\n :class:`IwahoriHeckeAlgebra` to compute the Kazhdan-Lusztig bases. It is\n not meant to be used directly. It implements the slightly idiosyncratic\n (but convenient) Iwahori-Hecke algebra with two parameters which is\n defined over the Laurent polynomial ring `\\ZZ[u,u^{-1},v,v^{-1}]` in\n two variables and has quadratic relations:\n\n .. MATH::\n\n (T_r - u)(T_r + v^2/u) = 0.\n\n The point of these relations is that the product of the two parameters is\n `v^2` which is a square in `\\ZZ[u,u^{-1},v,v^{-1}]`. Consequently, the\n Kazhdan-Lusztig bases are defined for this algebra.\n\n More generally, if we have a Iwahori-Hecke algebra with two parameters\n which has quadratic relations of the form:\n\n .. MATH::\n\n (T_r - q_1)(T_r - q_2) = 0\n\n where `-q_1 q_2` is a square then the Kazhdan-Lusztig bases are\n well-defined for this algebra. Moreover, these bases be computed by\n specialization from the generic Iwahori-Hecke algebra using the\n specialization which sends `u \\mapsto q_1` and `v \\mapsto \\sqrt{-q_1 q_2}`,\n so that `v^2 / u \\mapsto -q_2`.\n\n For example, if `q_1 = q = Q^2` and `q_2 = -1` then `u \\mapsto q` and\n `v \\mapsto \\sqrt{q} = Q`; this is the standard presentation of the\n Iwahori-Hecke algebra with `(T_r - q)(T_r + 1) = 0`. On the other hand,\n when `q_1 = q` and `q_2 = -q^{-1}` then `u \\mapsto q` and `v \\mapsto 1`.\n This is the normalized presentation with `(T_r - v)(T_r + v^{-1}) = 0`.\n\n .. WARNING::\n\n This class uses non-standard parameters for the Iwahori-Hecke algebra\n and are related to the standard parameters by an outer automorphism\n that is non-trivial on the `T`-basis.\n ' @staticmethod def __classcall_private__(cls, W): '\n TESTS::\n\n sage: H1 = sage.algebras.iwahori_hecke_algebra.IwahoriHeckeAlgebra_nonstandard("A2")\n sage: W = CoxeterGroup("A2")\n sage: H2 = sage.algebras.iwahori_hecke_algebra.IwahoriHeckeAlgebra_nonstandard(W)\n sage: H1 is H2\n True\n ' if (W not in CoxeterGroups()): W = CoxeterGroup(W) return super().__classcall__(cls, W) def __init__(self, W): '\n EXAMPLES::\n\n sage: H = sage.algebras.iwahori_hecke_algebra.IwahoriHeckeAlgebra_nonstandard("A2")\n sage: TestSuite(H).run()\n ' self._W = W self._coxeter_type = W.coxeter_type() base_ring = LaurentPolynomialRing(ZZ, 'u,v') (u, v) = base_ring.gens() self._q1 = u self._q2 = normalized_laurent_polynomial(base_ring, ((- (v ** 2)) * (u ** (- 1)))) self._root = v self._q_sum = normalized_laurent_polynomial(base_ring, (self._q1 + self._q2)) self._q_prod = normalized_laurent_polynomial(base_ring, ((- self._q1) * self._q2)) self.u_inv = normalized_laurent_polynomial(base_ring, (u ** (- 1))) self.v_inv = normalized_laurent_polynomial(base_ring, (v ** (- 1))) self._shorthands = ['C', 'Cp', 'T'] if W.is_finite(): self._category = FiniteDimensionalAlgebrasWithBasis(base_ring) else: self._category = AlgebrasWithBasis(base_ring) Parent.__init__(self, base=base_ring, category=self._category.WithRealizations()) self._is_generic = True def _repr_(self): '\n EXAMPLES::\n\n sage: sage.algebras.iwahori_hecke_algebra.IwahoriHeckeAlgebra_nonstandard("A2")\n A generic Iwahori-Hecke algebra of type A2 in u,-u^-1*v^2 over\n Multivariate Laurent Polynomial Ring in u, v over Integer Ring\n ' try: ct = self._coxeter_type._repr_(compact=True) except TypeError: ct = repr(self._coxeter_type) return 'A generic Iwahori-Hecke algebra of type {} in {},{} over {}'.format(ct, self._q1, self._q2, self.base_ring()) def _bar_on_coefficients(self, c): '\n Given a Laurent polynomial ``c`` return the Laurent polynomial obtained\n by applying the (generic) bar involution to ``c`` .\n\n This is the ring homomorphism of Laurent polynomials in\n `\\ZZ[u,u^{-1},v,v^{-1}]` which sends `u` to `u^{-1}` and `v`\n to `v^{-1}`.\n\n EXAMPLES::\n\n sage: R.<q>=LaurentPolynomialRing(ZZ)\n sage: H=IwahoriHeckeAlgebra("A3",q^2)\n sage: GH=H._generic_iwahori_hecke_algebra\n sage: GH._bar_on_coefficients(GH.u_inv)\n u\n sage: GH._bar_on_coefficients(GH.v_inv)\n v\n ' return normalized_laurent_polynomial(self._base, c)(self.u_inv, self.v_inv) class _BasesCategory(IwahoriHeckeAlgebra._BasesCategory): '\n Category of bases for a generic Iwahori-Hecke algebra.\n ' def super_categories(self): '\n The super categories of ``self``.\n\n EXAMPLES::\n\n sage: H = sage.algebras.iwahori_hecke_algebra.IwahoriHeckeAlgebra_nonstandard("B2")\n sage: H._BasesCategory().super_categories()\n [Category of bases of A generic Iwahori-Hecke algebra of type B2 in u,-u^-1*v^2 over\n Multivariate Laurent Polynomial Ring in u, v over Integer Ring]\n ' return [IwahoriHeckeAlgebra._BasesCategory(self.base())] class ElementMethods(): def specialize_to(self, new_hecke): '\n Return the element in the Iwahori-Hecke algebra ``new_hecke``\n with respect to the same basis which is obtained from ``self``\n by specializing the generic parameters in this algebra to the\n parameters of ``new_hecke``.\n\n The generic Iwahori-Hecke algebra is defined over\n `\\ZZ[u^\\pm, v^\\pm]` and has parameters ``u`` and\n ``-v^2/u``. The specialization map sends ``u`` to\n ``new_hecke._q1`` and ``v`` to ``new_hecke._root`` which is\n thesquare root of ``-new_hecke._q1*new_hecke._q2``, so\n `-v^2/u` is sent to ``new_hecke._q2``.\n\n This function is not intended to be called directly. Rather it\n is called behind the scenes to convert between the\n Kazhdan-Lusztig and standard bases of the Iwahori-Hecke\n algebras.\n\n EXAMPLES::\n\n sage: R.<a,b>=LaurentPolynomialRing(ZZ,2)\n sage: H=IwahoriHeckeAlgebra("A3",a^2,-b^2)\n sage: GH=H._generic_iwahori_hecke_algebra\n sage: GH.T()(GH.C()[1])\n (v^-1)*T[1] + (-u*v^-1)\n sage: ( GH.T()(GH.C()[1]) ).specialize_to(H)\n (a^-1*b^-1)*T[1] + (-a*b^-1)\n sage: GH.C()( GH.T()[1] )\n v*C[1] + u\n sage: GH.C()( GH.T()[1] ).specialize_to(H)\n a*b*C[1] + a^2\n sage: H.C()( H.T()[1] )\n a*b*C[1] + a^2\n ' hecke = self.parent().realization_of() q1 = new_hecke._q1 root = new_hecke._root def new_coeff(c): return new_hecke._base(normalized_laurent_polynomial(hecke._base, c)(q1, root)) new_basis = getattr(new_hecke, self.parent()._basis_name)() return new_basis._from_dict({w: new_coeff(c) for (w, c) in self}) class T(IwahoriHeckeAlgebra.T): '\n The `T`-basis for the generic Iwahori-Hecke algebra.\n ' @cached_method def to_Cp_basis(self, w): '\n Return `T_w` as a linear combination of `C^{\\prime}`-basis\n elements.\n\n EXAMPLES::\n\n sage: H = sage.algebras.iwahori_hecke_algebra.IwahoriHeckeAlgebra_nonstandard("A2")\n sage: s1,s2 = H.coxeter_group().simple_reflections()\n sage: T = H.T()\n sage: Cp = H.Cp()\n sage: T.to_Cp_basis(s1)\n v*Cp[1] + (-u^-1*v^2)\n sage: Cp(T(s1))\n v*Cp[1] + (-u^-1*v^2)\n sage: Cp(T(s1)+1)\n v*Cp[1] + (-u^-1*v^2+1)\n sage: Cp(T(s1*s2)+T(s1)+T(s2)+1)\n v^2*Cp[1,2] + (-u^-1*v^3+v)*Cp[1] + (-u^-1*v^3+v)*Cp[2]\n + (u^-2*v^4-2*u^-1*v^2+1)\n sage: Cp(T(s1*s2*s1))\n v^3*Cp[1,2,1] + (-u^-1*v^4)*Cp[2,1] + (-u^-1*v^4)*Cp[1,2]\n + (u^-2*v^5)*Cp[1] + (u^-2*v^5)*Cp[2] + (-u^-3*v^6)\n ' A = self.realization_of() Cp = A.Cp() if (w == A._W.one()): return Cp.one() T0 = self.zero() inp = self.monomial(w) result = Cp.zero() while (inp != T0): (x, c) = inp.trailing_item(key=sorting_key) inp = (inp - ((c * (A._root ** x.length())) * Cp.to_T_basis(x))) result = (result + ((c * (A._root ** x.length())) * Cp.monomial(x))) return result @cached_method def to_C_basis(self, w): '\n Return `T_w` as a linear combination of `C`-basis elements.\n\n To compute this we piggy back off the `C^{\\prime}`-basis\n conversion using the observation that the hash involution sends\n `T_w` to `(-q_1 q_1)^{\\ell(w)} T_w` and `C_w` to\n `(-1)^{\\ell(w)} C^{\\prime}_w`. Therefore, if\n\n .. MATH::\n\n T_w = \\sum_v a_{vw} C^{\\prime}_v\n\n then\n\n .. MATH::\n\n T_w = (-q_1 q_2)^{\\ell(w)} \\Big( \\sum_v a_{vw} C^{\\prime}_v\n \\Big)^\\#\n = \\sum_v (-1)^{\\ell(v)} \\overline{a_{vw}} C_v\n\n Note that we cannot just apply :meth:`hash_involution` here because\n this involution always returns the answer with respect to the\n same basis.\n\n EXAMPLES::\n\n sage: H = sage.algebras.iwahori_hecke_algebra.IwahoriHeckeAlgebra_nonstandard("A2")\n sage: s1,s2 = H.coxeter_group().simple_reflections()\n sage: T = H.T()\n sage: C = H.C()\n sage: T.to_C_basis(s1)\n v*T[1] + u\n sage: C(T(s1))\n v*C[1] + u\n sage: C(T( C[1] ))\n C[1]\n sage: C(T(s1*s2)+T(s1)+T(s2)+1)\n v^2*C[1,2] + (u*v+v)*C[1] + (u*v+v)*C[2] + (u^2+2*u+1)\n sage: C(T(s1*s2*s1))\n v^3*C[1,2,1] + u*v^2*C[2,1] + u*v^2*C[1,2] + u^2*v*C[1] + u^2*v*C[2] + u^3\n ' H = self.realization_of() q_w = ((- H._q_prod) ** w.length()) return self.sum_of_terms(((v, ((((- 1) ** v.length()) * q_w) * H._bar_on_coefficients(c))) for (v, c) in self.to_Cp_basis(w))) class Cp(IwahoriHeckeAlgebra.Cp): '\n The Kazhdan-Lusztig `C^{\\prime}`-basis for the generic Iwahori-Hecke\n algebra.\n ' @cached_method def to_T_basis(self, w): '\n Return `C^{\\prime}_w` as a linear combination of `T`-basis\n elements.\n\n EXAMPLES::\n\n sage: H = sage.algebras.iwahori_hecke_algebra.IwahoriHeckeAlgebra_nonstandard("A3")\n sage: s1,s2,s3 = H.coxeter_group().simple_reflections()\n sage: T = H.T()\n sage: Cp = H.Cp()\n sage: Cp.to_T_basis(s1)\n (v^-1)*T[1] + (u^-1*v)\n sage: Cp.to_T_basis(s1*s2)\n (v^-2)*T[1,2] + (u^-1)*T[1] + (u^-1)*T[2] + (u^-2*v^2)\n sage: Cp.to_T_basis(s1*s2*s1)\n (v^-3)*T[1,2,1] + (u^-1*v^-1)*T[2,1] + (u^-1*v^-1)*T[1,2]\n + (u^-2*v)*T[1] + (u^-2*v)*T[2] + (u^-3*v^3)\n sage: T(Cp(s1*s2*s1))\n (v^-3)*T[1,2,1] + (u^-1*v^-1)*T[2,1] + (u^-1*v^-1)*T[1,2]\n + (u^-2*v)*T[1] + (u^-2*v)*T[2] + (u^-3*v^3)\n sage: T(Cp(s2*s1*s3*s2))\n (v^-4)*T[2,3,1,2] + (u^-1*v^-2)*T[2,3,1] + (u^-1*v^-2)*T[1,2,1]\n + (u^-1*v^-2)*T[3,1,2] + (u^-1*v^-2)*T[2,3,2] + (u^-2)*T[2,1]\n + (u^-2)*T[3,1] + (u^-2)*T[1,2] + (u^-2)*T[3,2]\n + (u^-2)*T[2,3] + (u^-3*v^2)*T[1] + (u^-3*v^2)*T[3]\n + (u^-1+u^-3*v^2)*T[2] + (u^-2*v^2+u^-4*v^4)\n ' A = self.realization_of() T = A.T() Ts = T.algebra_generators() if (w == A._W.one()): return T.one() s = w.first_descent() ws = w.apply_simple_reflection(s) cpw_s = ((self.to_T_basis(ws) * A.v_inv) * (Ts[s] - (A._q2 * T.one()))) i = 1 def key_func(x): return sorting_key(x.leading_support()) while (i < len(cpw_s)): (x, c) = sorted(cpw_s.terms(), key=key_func)[i].leading_item() mu = normalized_laurent_polynomial(A._base, c)[(0, (- x.length()))] if (mu != 0): cpw_s -= (mu * self.to_T_basis(x)) else: i += 1 return cpw_s C_prime = Cp class C(IwahoriHeckeAlgebra.C): '\n The Kazhdan-Lusztig `C`-basis for the generic Iwahori-Hecke algebra.\n ' @cached_method def to_T_basis(self, w): '\n Return `C_w` as a linear combination of `T`-basis elements.\n\n EXAMPLES::\n\n sage: H = sage.algebras.iwahori_hecke_algebra.IwahoriHeckeAlgebra_nonstandard("A3")\n sage: s1,s2,s3 = H.coxeter_group().simple_reflections()\n sage: T = H.T()\n sage: C = H.C()\n sage: C.to_T_basis(s1)\n (v^-1)*T[1] + (-u*v^-1)\n sage: C.to_T_basis(s1*s2)\n (v^-2)*T[1,2] + (-u*v^-2)*T[1] + (-u*v^-2)*T[2] + (u^2*v^-2)\n sage: C.to_T_basis(s1*s2*s1)\n (v^-3)*T[1,2,1] + (-u*v^-3)*T[2,1] + (-u*v^-3)*T[1,2]\n + (u^2*v^-3)*T[1] + (u^2*v^-3)*T[2] + (-u^3*v^-3)\n sage: T(C(s1*s2*s1))\n (v^-3)*T[1,2,1] + (-u*v^-3)*T[2,1] + (-u*v^-3)*T[1,2]\n + (u^2*v^-3)*T[1] + (u^2*v^-3)*T[2] + (-u^3*v^-3)\n sage: T(C(s2*s1*s3*s2))\n (v^-4)*T[2,3,1,2] + (-u*v^-4)*T[2,3,1] + (-u*v^-4)*T[1,2,1]\n + (-u*v^-4)*T[3,1,2] + (-u*v^-4)*T[2,3,2] + (u^2*v^-4)*T[2,1]\n + (u^2*v^-4)*T[3,1] + (u^2*v^-4)*T[1,2] + (u^2*v^-4)*T[3,2]\n + (u^2*v^-4)*T[2,3] + (-u^3*v^-4)*T[1] + (-u^3*v^-4)*T[3]\n + (-u^3*v^-4-u*v^-2)*T[2] + (u^4*v^-4+u^2*v^-2)\n ' return (((- 1) ** w.length()) * self.realization_of().Cp().to_T_basis(w).hash_involution())
class JordanAlgebra(UniqueRepresentation, Parent): "\n A Jordan algebra.\n\n A *Jordan algebra* is a magmatic algebra (over a commutative ring\n `R`) whose multiplication satisfies the following axioms:\n\n - `xy = yx`, and\n - `(xy)(xx) = x(y(xx))` (the Jordan identity).\n\n See [Ja1971]_, [Ch2012]_, and [McC1978]_, for example.\n\n These axioms imply that a Jordan algebra is power-associative and the\n following generalization of Jordan's identity holds [Al1947]_:\n `(x^m y) x^n = x^m (y x^n)` for all `m, n \\in \\ZZ_{>0}`.\n\n Let `A` be an associative algebra over a ring `R` in which `2` is\n invertible. We construct a Jordan algebra `A^+` with ground set `A`\n by defining the multiplication as\n\n .. MATH::\n\n x \\circ y = \\frac{xy + yx}{2}.\n\n Often the multiplication is written as `x \\circ y` to avoid confusion\n with the product in the associative algebra `A`. We note that if `A` is\n commutative then this reduces to the usual multiplication in `A`.\n\n Jordan algebras constructed in this fashion, or their subalgebras,\n are called *special*. All other Jordan algebras are called *exceptional*.\n\n Jordan algebras can also be constructed from a module `M` over `R` with\n a symmetric bilinear form `(\\cdot, \\cdot) : M \\times M \\to R`.\n We begin with the module `M^* = R \\oplus M` and define multiplication\n in `M^*` by\n\n .. MATH::\n\n (\\alpha + x) \\circ (\\beta + y) =\n \\underbrace{\\alpha \\beta + (x,y)}_{\\in R}\n + \\underbrace{\\beta x + \\alpha y}_{\\in M},\n\n where `\\alpha, \\beta \\in R` and `x,y \\in M`.\n\n INPUT:\n\n Can be either an associative algebra `A` or a symmetric bilinear\n form given as a matrix (possibly followed by, or preceded by, a base\n ring argument).\n\n EXAMPLES:\n\n We let the base algebra `A` be the free algebra on 3 generators::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F); J\n Jordan algebra of Free Algebra on 3 generators (x, y, z) over Rational Field\n sage: a,b,c = map(J, F.gens())\n sage: a*b\n 1/2*x*y + 1/2*y*x\n sage: b*a\n 1/2*x*y + 1/2*y*x\n\n Jordan algebras are typically non-associative::\n\n sage: (a*b)*c\n 1/4*x*y*z + 1/4*y*x*z + 1/4*z*x*y + 1/4*z*y*x\n sage: a*(b*c)\n 1/4*x*y*z + 1/4*x*z*y + 1/4*y*z*x + 1/4*z*y*x\n\n We check the Jordan identity::\n\n sage: (a*b)*(a*a) == a*(b*(a*a))\n True\n sage: x = a + c\n sage: y = b - 2*a\n sage: (x*y)*(x*x) == x*(y*(x*x))\n True\n\n Next we construct a Jordan algebra from a symmetric bilinear form::\n\n sage: m = matrix([[-2,3],[3,4]])\n sage: J.<a,b,c> = JordanAlgebra(m); J\n Jordan algebra over Integer Ring given by the symmetric bilinear form:\n [-2 3]\n [ 3 4]\n sage: a\n 1 + (0, 0)\n sage: b\n 0 + (1, 0)\n sage: x = 3*a - 2*b + c; x\n 3 + (-2, 1)\n\n We again show that Jordan algebras are usually non-associative::\n\n sage: (x*b)*b\n -6 + (7, 0)\n sage: x*(b*b)\n -6 + (4, -2)\n\n We verify the Jordan identity::\n\n sage: y = -a + 4*b - c\n sage: (x*y)*(x*x) == x*(y*(x*x))\n True\n\n The base ring, while normally inferred from the matrix, can also\n be explicitly specified::\n\n sage: J.<a,b,c> = JordanAlgebra(m, QQ); J\n Jordan algebra over Rational Field given by the symmetric bilinear form:\n [-2 3]\n [ 3 4]\n sage: J.<a,b,c> = JordanAlgebra(QQ, m); J # either order work\n Jordan algebra over Rational Field given by the symmetric bilinear form:\n [-2 3]\n [ 3 4]\n\n REFERENCES:\n\n - :wikipedia:`Jordan_algebra`\n - [Ja1971]_\n - [Ch2012]_\n - [McC1978]_\n - [Al1947]_\n " @staticmethod def __classcall_private__(self, arg0, arg1=None, names=None): "\n Choose the correct parent based upon input.\n\n TESTS:\n\n We check arguments with passing in an associative algebra::\n\n sage: cat = Algebras(QQ).WithBasis().FiniteDimensional()\n sage: C = CombinatorialFreeModule(QQ, ['x','y','z'], category=cat)\n sage: J1 = JordanAlgebra(C, names=['a','b','c'])\n sage: J2.<a,b,c> = JordanAlgebra(C)\n sage: J1 is J2\n True\n\n We check with passing in a symmetric bilinear form::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J1 = JordanAlgebra(m)\n sage: J2 = JordanAlgebra(QQ, m)\n sage: J3 = JordanAlgebra(m, QQ)\n sage: J1 is J2\n False\n sage: J2 is J3\n True\n sage: J4 = JordanAlgebra(ZZ, m)\n sage: J1 is J4\n True\n sage: m = matrix(QQ, [[0,1],[1,1]])\n sage: J1 = JordanAlgebra(m)\n sage: J1 is J2\n True\n " if (names is not None): if isinstance(names, str): names = names.split(',') names = tuple(names) if (arg1 is None): if (not is_Matrix(arg0)): from sage.algebras.octonion_algebra import OctonionAlgebra if isinstance(arg0, OctonionAlgebra): return ExceptionalJordanAlgebra(arg0) if (arg0.base_ring().characteristic() == 2): raise ValueError('the base ring cannot have characteristic 2') return SpecialJordanAlgebra(arg0, names) (arg0, arg1) = (arg0.base_ring(), arg0) elif is_Matrix(arg0): (arg0, arg1) = (arg1, arg0) if (not arg1.is_symmetric()): raise ValueError('the bilinear form is not symmetric') arg1 = arg1.change_ring(arg0) arg1.set_immutable() return JordanAlgebraSymmetricBilinear(arg0, arg1, names=names) def _test_jordan_relations(self, **options): '\n Test the Jordan algebra relations.\n\n The Jordan algebra relations are\n\n - `xy = yx`, and\n - `(xy)(xx) = x(y(xx))` (the Jordan identity).\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(GF(7), 1, 3, 4)\n sage: J = JordanAlgebra(O)\n sage: J._test_jordan_relations()\n ' tester = self._tester(**options) S = tester.some_elements() from sage.misc.misc import some_tuples for (x, y) in some_tuples(S, 2, tester._max_runs): tester.assertEqual((x * y), (y * x)) tester.assertEqual(((x * y) * (x * x)), (x * (y * (x * x))))
class SpecialJordanAlgebra(JordanAlgebra): '\n A (special) Jordan algebra `A^+` from an associative algebra `A`.\n ' def __init__(self, A, names=None): '\n Initialize ``self``.\n\n TESTS::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: TestSuite(J).run()\n sage: J.category()\n Category of commutative unital algebras with basis over Rational Field\n ' R = A.base_ring() C = MagmaticAlgebras(R) if (A not in C.Associative()): raise ValueError('A is not an associative algebra') self._A = A cat = C.Commutative() if (A in C.Unital()): cat = cat.Unital() if (A in C.WithBasis()): cat = cat.WithBasis() if (A in C.FiniteDimensional()): cat = cat.FiniteDimensional() Parent.__init__(self, base=R, names=names, category=cat) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: JordanAlgebra(F)\n Jordan algebra of Free Algebra on 3 generators (x, y, z) over Rational Field\n ' return 'Jordan algebra of {}'.format(self._A) def _element_constructor_(self, x): '\n Construct an element of ``self`` from ``x``.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: J(5)\n 5\n sage: elt = J(x + 2*x*y); elt\n x + 2*x*y\n sage: elt.parent() is J\n True\n ' return self.element_class(self, self._A(x)) def _an_element_(self): '\n Return an element of ``self``.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: J.an_element()\n 2 + 2*x + 3*y\n ' return self.element_class(self, self._A.an_element()) @cached_method def basis(self): '\n Return the basis of ``self``.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: J.basis()\n Lazy family (Term map(i))_{i in Free monoid on 3 generators (x, y, z)}\n ' B = self._A.basis() return Family(B.keys(), (lambda x: self.element_class(self, B[x])), name='Term map') algebra_generators = basis def gens(self): "\n Return the generators of ``self``.\n\n EXAMPLES::\n\n sage: cat = Algebras(QQ).WithBasis().FiniteDimensional()\n sage: C = CombinatorialFreeModule(QQ, ['x','y','z'], category=cat)\n sage: J = JordanAlgebra(C)\n sage: J.gens()\n (B['x'], B['y'], B['z'])\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: J.gens()\n Traceback (most recent call last):\n ...\n NotImplementedError: infinite set\n " return tuple(self.algebra_generators()) @cached_method def zero(self): '\n Return the element `0`.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: J.zero()\n 0\n ' return self.element_class(self, self._A.zero()) @cached_method def one(self): '\n Return the element `1` if it exists.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: J.one()\n 1\n ' return self.element_class(self, self._A.one()) class Element(AlgebraElement): '\n An element of a special Jordan algebra.\n ' def __init__(self, parent, x): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: TestSuite(a + 2*b - c).run()\n ' self._x = x AlgebraElement.__init__(self, parent) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: a + 2*b - c\n x + 2*y - z\n ' return repr(self._x) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: F.<x0,x1,x2> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: latex(a + 2*b - c)\n x_{0} + 2 x_{1} - x_{2}\n ' from sage.misc.latex import latex return latex(self._x) def __bool__(self) -> bool: '\n Return if ``self`` is non-zero.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: bool(a + 2*b - c)\n True\n ' return bool(self._x) def __eq__(self, other): '\n Check equality.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: elt = a + 2*b - c\n sage: elt == elt\n True\n sage: elt == x\n False\n sage: elt == 2*b\n False\n ' if (not isinstance(other, SpecialJordanAlgebra.Element)): return False if (other.parent() != self.parent()): return False return (self._x == other._x) def __ne__(self, other): '\n Check inequality.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: elt = a + 2*b - c\n sage: elt != elt\n False\n sage: elt != x\n True\n sage: elt != 2*b\n True\n ' return (not (self == other)) def _add_(self, other): '\n Add ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: a + 2*b\n x + 2*y\n ' return self.__class__(self.parent(), (self._x + other._x)) def _neg_(self): '\n Negate ``self``.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: -(a + 2*b)\n -x - 2*y\n ' return self.__class__(self.parent(), (- self._x)) def _sub_(self, other): '\n Subtract ``other`` from ``self``.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: a - 2*b\n x - 2*y\n ' return self.__class__(self.parent(), (self._x - other._x)) def _mul_(self, other): '\n Multiply ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: (a + 2*b) * (c - b)\n -1/2*x*y + 1/2*x*z - 1/2*y*x - 2*y^2 + y*z + 1/2*z*x + z*y\n\n sage: F.<x,y,z> = FreeAlgebra(GF(3))\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: (a + 2*b) * (c - b)\n x*y + 2*x*z + y*x + y^2 + y*z + 2*z*x + z*y\n ' x = self._x y = other._x R = self.parent().base_ring() return self.__class__(self.parent(), (((x * y) + (y * x)) * (~ R(2)))) def _lmul_(self, other): '\n Multiply ``self`` by the scalar ``other`` on the left.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: (a + b) * 2\n 2*x + 2*y\n ' return self.__class__(self.parent(), (self._x * other)) def _rmul_(self, other): '\n Multiply ``self`` and the scalar ``other`` by the right\n action.\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: 2 * (a + b)\n 2*x + 2*y\n ' return self.__class__(self.parent(), (other * self._x)) def monomial_coefficients(self, copy=True): '\n Return a dictionary whose keys are indices of basis elements in\n the support of ``self`` and whose values are the corresponding\n coefficients.\n\n INPUT:\n\n - ``copy`` -- (default: ``True``) if ``self`` is internally\n represented by a dictionary ``d``, then make a copy of ``d``;\n if ``False``, then this can cause undesired behavior by\n mutating ``d``\n\n EXAMPLES::\n\n sage: F.<x,y,z> = FreeAlgebra(QQ)\n sage: J = JordanAlgebra(F)\n sage: a,b,c = map(J, F.gens())\n sage: elt = a + 2*b - c\n sage: elt.monomial_coefficients()\n {x: 1, y: 2, z: -1}\n ' return self._x.monomial_coefficients(copy)
class JordanAlgebraSymmetricBilinear(JordanAlgebra): '\n A Jordan algebra given by a symmetric bilinear form `m`.\n ' def __init__(self, R, form, names=None): '\n Initialize ``self``.\n\n TESTS::\n\n sage: m = matrix([[-2,3],[3,4]])\n sage: J = JordanAlgebra(m)\n sage: TestSuite(J).run()\n ' self._form = form self._M = FreeModule(R, form.ncols()) cat = MagmaticAlgebras(R).Commutative().Unital().FiniteDimensional().WithBasis() Parent.__init__(self, base=R, names=names, category=cat) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: m = matrix([[-2,3],[3,4]])\n sage: JordanAlgebra(m)\n Jordan algebra over Integer Ring given by the symmetric bilinear form:\n [-2 3]\n [ 3 4]\n ' return 'Jordan algebra over {} given by the symmetric bilinear form:\n{}'.format(self.base_ring(), self._form) def _element_constructor_(self, *args): '\n Construct an element of ``self`` from ``s``.\n\n Here ``s`` can be a pair of an element of `R` and an\n element of `M`, or an element of `R`, or an element of\n `M`, or an element of a(nother) Jordan algebra given\n by a symmetric bilinear form.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J = JordanAlgebra(m)\n sage: J(2)\n 2 + (0, 0)\n sage: J((-4, (2, 5)))\n -4 + (2, 5)\n sage: J((-4, (ZZ^2)((2, 5))))\n -4 + (2, 5)\n sage: J(2, (-2, 3))\n 2 + (-2, 3)\n sage: J(2, (ZZ^2)((-2, 3)))\n 2 + (-2, 3)\n sage: J(-1, 1, 0)\n -1 + (1, 0)\n sage: J((ZZ^2)((1, 3)))\n 0 + (1, 3)\n\n sage: m = matrix([[2]])\n sage: J = JordanAlgebra(m)\n sage: J(2)\n 2 + (0)\n sage: J((-4, (2,)))\n -4 + (2)\n sage: J(2, (-2,))\n 2 + (-2)\n sage: J(-1, 1)\n -1 + (1)\n sage: J((ZZ^1)((3,)))\n 0 + (3)\n\n sage: m = Matrix(QQ, [])\n sage: J = JordanAlgebra(m)\n sage: J(2)\n 2 + ()\n sage: J((-4, ()))\n -4 + ()\n sage: J(2, ())\n 2 + ()\n sage: J(-1)\n -1 + ()\n sage: J((ZZ^0)(()))\n 0 + ()\n ' R = self.base_ring() if (len(args) == 1): s = args[0] if isinstance(s, JordanAlgebraSymmetricBilinear.Element): if (s.parent() is self): return s return self.element_class(self, R(s._s), self._M(s._v)) if isinstance(s, (list, tuple)): if (len(s) != 2): raise ValueError('must be length 2') return self.element_class(self, R(s[0]), self._M(s[1])) if (s in self._M): return self.element_class(self, R.zero(), self._M(s)) return self.element_class(self, R(s), self._M.zero()) if ((len(args) == 2) and (isinstance(args[1], (list, tuple)) or (args[1] in self._M))): return self.element_class(self, R(args[0]), self._M(args[1])) if (len(args) == (self._form.ncols() + 1)): return self.element_class(self, R(args[0]), self._M(args[1:])) raise ValueError('unable to construct an element from the given data') def _coerce_map_from_base_ring(self): '\n Return a coercion map from the base ring of ``self``.\n\n TESTS::\n\n sage: J = JordanAlgebra(Matrix([[0, 1], [1, 1]]))\n sage: J._coerce_map_from_base_ring()\n Conversion map:\n From: Integer Ring\n To: Jordan algebra over Integer Ring given by the symmetric bilinear form:\n [0 1]\n [1 1]\n sage: J.coerce_map_from(ZZ)\n Coercion map:\n From: Integer Ring\n To: Jordan algebra over Integer Ring given by the symmetric bilinear form:\n [0 1]\n [1 1]\n ' return self._generic_coerce_map(self.base_ring()) @cached_method def basis(self): '\n Return a basis of ``self``.\n\n The basis returned begins with the unity of `R` and continues with\n the standard basis of `M`.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J = JordanAlgebra(m)\n sage: J.basis()\n Family (1 + (0, 0), 0 + (1, 0), 0 + (0, 1))\n ' R = self.base_ring() ret = (self.element_class(self, R.one(), self._M.zero()),) ret += tuple((self.element_class(self, R.zero(), x) for x in self._M.basis())) return Family(ret) algebra_generators = basis def gens(self): '\n Return the generators of ``self``.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J = JordanAlgebra(m)\n sage: J.gens()\n (1 + (0, 0), 0 + (1, 0), 0 + (0, 1))\n ' return tuple(self.algebra_generators()) @cached_method def zero(self): '\n Return the element 0.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J = JordanAlgebra(m)\n sage: J.zero()\n 0 + (0, 0)\n ' return self.element_class(self, self.base_ring().zero(), self._M.zero()) @cached_method def one(self): '\n Return the element 1 if it exists.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J = JordanAlgebra(m)\n sage: J.one()\n 1 + (0, 0)\n ' return self.element_class(self, self.base_ring().one(), self._M.zero()) class Element(AlgebraElement): '\n An element of a Jordan algebra defined by a symmetric bilinear form.\n ' def __init__(self, parent, s, v): '\n Initialize ``self``.\n\n TESTS::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: TestSuite(a + 2*b - c).run()\n ' self._s = s self._v = v AlgebraElement.__init__(self, parent) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: a + 2*b - c\n 1 + (2, -1)\n ' return '{} + {}'.format(self._s, self._v) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: latex(a + 2*b - c)\n 1 + \\left(2,\\,-1\\right)\n ' from sage.misc.latex import latex return '{} + {}'.format(latex(self._s), latex(self._v)) def __bool__(self) -> bool: '\n Return if ``self`` is non-zero.\n\n TESTS::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: bool(1)\n True\n sage: bool(b)\n True\n sage: bool(a + 2*b - c)\n True\n ' return (bool(self._s) or bool(self._v)) def __eq__(self, other): '\n Check equality.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: x = 4*a - b + 3*c\n sage: x == J((4, (-1, 3)))\n True\n sage: a == x\n False\n\n sage: m = matrix([[-2,3],[3,4]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: 4*a - b + 3*c == x\n False\n ' if (not isinstance(other, JordanAlgebraSymmetricBilinear.Element)): return False if (other.parent() != self.parent()): return False return ((self._s == other._s) and (self._v == other._v)) def __ne__(self, other): '\n Check inequality.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: x = 4*a - b + 3*c\n sage: x != J((4, (-1, 3)))\n False\n sage: a != x\n True\n\n sage: m = matrix([[-2,3],[3,4]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: 4*a - b + 3*c != x\n True\n ' return (not (self == other)) def _add_(self, other): '\n Add ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: a + b\n 1 + (1, 0)\n sage: b + c\n 0 + (1, 1)\n ' return self.__class__(self.parent(), (self._s + other._s), (self._v + other._v)) def _neg_(self): '\n Negate ``self``.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: -(a + b - 2*c)\n -1 + (-1, 2)\n ' return self.__class__(self.parent(), (- self._s), (- self._v)) def _sub_(self, other): '\n Subtract ``other`` from ``self``.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: a - b\n 1 + (-1, 0)\n sage: b - c\n 0 + (1, -1)\n ' return self.__class__(self.parent(), (self._s - other._s), (self._v - other._v)) def _mul_(self, other): '\n Multiply ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: (4*a - b + 3*c)*(2*a + 2*b - c)\n 12 + (6, 2)\n\n sage: m = matrix([[-2,3],[3,4]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: (4*a - b + 3*c)*(2*a + 2*b - c)\n 21 + (6, 2)\n ' P = self.parent() return self.__class__(P, ((self._s * other._s) + ((self._v * P._form) * other._v.column())[0]), ((other._s * self._v) + (self._s * other._v))) def _lmul_(self, other): '\n Multiply ``self`` by the scalar ``other`` on the left.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: (a + b - c) * 2\n 2 + (2, -2)\n ' return self.__class__(self.parent(), (self._s * other), (self._v * other)) def _rmul_(self, other): '\n Multiply ``self`` with the scalar ``other`` by the right\n action.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: 2 * (a + b - c)\n 2 + (2, -2)\n ' return self.__class__(self.parent(), (other * self._s), (other * self._v)) def monomial_coefficients(self, copy=True): '\n Return a dictionary whose keys are indices of basis elements in\n the support of ``self`` and whose values are the corresponding\n coefficients.\n\n INPUT:\n\n - ``copy`` -- ignored\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: elt = a + 2*b - c\n sage: elt.monomial_coefficients()\n {0: 1, 1: 2, 2: -1}\n ' d = {0: self._s} for (i, c) in enumerate(self._v): d[(i + 1)] = c return d def trace(self): '\n Return the trace of ``self``.\n\n The trace of an element `\\alpha + x \\in M^*` is given by\n `t(\\alpha + x) = 2 \\alpha`.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: x = 4*a - b + 3*c\n sage: x.trace()\n 8\n ' return (2 * self._s) def norm(self): '\n Return the norm of ``self``.\n\n The norm of an element `\\alpha + x \\in M^*` is given by\n `n(\\alpha + x) = \\alpha^2 - (x, x)`.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: x = 4*a - b + 3*c; x\n 4 + (-1, 3)\n sage: x.norm()\n 13\n ' return ((self._s * self._s) - ((self._v * self.parent()._form) * self._v.column())[0]) def bar(self): '\n Return the result of the bar involution of ``self``.\n\n The bar involution `\\bar{\\cdot}` is the `R`-linear\n endomorphism of `M^*` defined by `\\bar{1} = 1` and\n `\\bar{x} = -x` for `x \\in M`.\n\n EXAMPLES::\n\n sage: m = matrix([[0,1],[1,1]])\n sage: J.<a,b,c> = JordanAlgebra(m)\n sage: x = 4*a - b + 3*c\n sage: x.bar()\n 4 + (1, -3)\n\n We check that it is an algebra morphism::\n\n sage: y = 2*a + 2*b - c\n sage: x.bar() * y.bar() == (x*y).bar()\n True\n ' return self.__class__(self.parent(), self._s, (- self._v))
class ExceptionalJordanAlgebra(JordanAlgebra): "\n The exceptional `27` dimensional Jordan algebra as self-adjoint\n `3 \\times 3` matrix over an octonion algebra.\n\n Let `\\mathbf{O}` be the :class:`OctonionAlgebra` over a commutative\n ring `R` of characteristic not equal to `2`. The *exceptional Jordan\n algebra* `\\mathfrak{h}_3(\\mathbf{O})` is a `27` dimensional free\n `R`-module spanned by the matrices\n\n .. MATH::\n\n \\begin{bmatrix}\n \\alpha & x & y \\\\\n x^* & \\beta & z \\\\\n y^* & z^* & \\gamma\n \\end{bmatrix}\n\n for `\\alpha, \\beta, \\gamma \\in R` and `x, y, z \\in \\mathbf{O}`,\n with multiplication given by the usual symmetrizer operation\n `X \\circ Y = \\frac{1}{2}(XY + YX)`.\n\n These are also known as *Albert algebras* due to the work of\n Abraham Adrian Albert on these algebras over `\\RR`.\n\n EXAMPLES:\n\n We construct an exceptional Jordan algebra over `\\QQ` and perform\n some basic computations::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: gens = J.gens()\n sage: gens[1]\n [0 0 0]\n [0 1 0]\n [0 0 0]\n sage: gens[3]\n [0 1 0]\n [1 0 0]\n [0 0 0]\n sage: gens[1] * gens[3]\n [ 0 1/2 0]\n [1/2 0 0]\n [ 0 0 0]\n\n The Lie algebra of derivations of the exceptional Jordan algebra\n is isomorphic to the simple Lie algebra of type `F_4`. We verify\n that we the derivation module has the correct dimension::\n\n sage: len(J.derivations_basis()) # long time\n 52\n sage: LieAlgebra(QQ, cartan_type='F4').dimension()\n 52\n\n REFERENCES:\n\n - :wikipedia:`Albert_algebra`\n - :wikipedia:`Jordan_algebra#Examples`\n - :wikipedia:`Hurwitz's_theorem_(composition_algebras)#Applications_to_Jordan_algebras`\n - `<https://math.ucr.edu/home/baez/octonions/octonions.pdf>`_\n " def __init__(self, O): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: TestSuite(J).run() # long time\n\n sage: O = OctonionAlgebra(QQ, 1, -2, 9)\n sage: J = JordanAlgebra(O)\n sage: TestSuite(J).run() # long time\n\n sage: R.<x, y> = GF(11)[]\n sage: O = OctonionAlgebra(R, 1, x + y, 9)\n sage: J = JordanAlgebra(O)\n sage: TestSuite(J).run() # long time\n\n sage: O = OctonionAlgebra(ZZ)\n sage: J = JordanAlgebra(O)\n Traceback (most recent call last):\n ...\n ValueError: 2 must be invertible\n ' self._O = O R = O.base_ring() if (not R(2).is_unit()): raise ValueError('2 must be invertible') self._half = R(2).inverse_of_unit() from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing Onames = list(O.variable_names()) Onames.extend(((Onames[3] + Onames[i]) for i in range(3))) self._repr_poly_ring = PolynomialRing(R, Onames) cat = MagmaticAlgebras(R).Unital().FiniteDimensional().WithBasis() Parent.__init__(self, base=R, category=cat) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: JordanAlgebra(O)\n Exceptional Jordan algebra constructed from Octonion algebra\n over Rational Field\n ' return 'Exceptional Jordan algebra constructed from {}'.format(self._O) def _element_constructor_(self, x): '\n Construct an element of ``self`` from ``s``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: J(2)\n [2 0 0]\n [0 2 0]\n [0 0 2]\n sage: J([2, 3, 0, -1, O.basis()[3], 2])\n [ 2 -1 k]\n [-1 3 2]\n [-k 2 0]\n ' R = self.base_ring() try: x = R(x) zero = self._O.zero() return self.element_class(self, [x, x, x, zero, zero, zero]) except (ValueError, TypeError): pass x = list(x) if (len(x) != 6): raise ValueError('invalid data to construct an element') R = self.base_ring() for i in range(3): x[i] = R(x[i]) x[(3 + i)] = self._O(x[(3 + i)]) return self.element_class(self, x) def _test_multiplication_self_adjoint(self, **options): '\n Test that `(XY + YX) / 2` is self-adjoint.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(GF(7), 1, 3, 4)\n sage: J = JordanAlgebra(O)\n sage: J._test_multiplication_self_adjoint()\n ' tester = self._tester(**options) S = tester.some_elements() data_pairs = [(0, 0), (1, 1), (2, 2), (0, 1), (0, 2), (1, 2)] zerO = self._O.zero() from sage.misc.misc import some_tuples for (x, y) in some_tuples(S, 2, tester._max_runs): SD = x._data OD = y._data X = [[SD[0], SD[3], SD[4]], [SD[3].conjugate(), SD[1], SD[5]], [SD[4].conjugate(), SD[5].conjugate(), SD[2]]] Y = [[OD[0], OD[3], OD[4]], [OD[3].conjugate(), OD[1], OD[5]], [OD[4].conjugate(), OD[5].conjugate(), OD[2]]] for (r, c) in data_pairs: if (r != c): val = (sum((((X[r][i] * Y[i][c]) + (Y[r][i] * X[i][c])) for i in range(3))) * self._half) val_opp = (sum((((X[c][i] * Y[i][r]) + (Y[c][i] * X[i][r])) for i in range(3))) * self._half) tester.assertEqual(val, val_opp.conjugate()) else: val = (sum((((X[r][i] * Y[i][c]) + (Y[r][i] * X[i][c])) for i in range(3))) * self._half) tester.assertEqual(val.imag_part(), zerO) @cached_method def basis(self): '\n Return a basis of ``self``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: B = J.basis()\n sage: B[::6]\n ([1 0 0]\n [0 0 0]\n [0 0 0],\n [ 0 k 0]\n [-k 0 0]\n [ 0 0 0],\n [ 0 0 i]\n [ 0 0 0]\n [-i 0 0],\n [ 0 0 lk]\n [ 0 0 0]\n [-lk 0 0],\n [ 0 0 0]\n [ 0 0 li]\n [ 0 -li 0])\n sage: len(B)\n 27\n ' import itertools R = self.base_ring() OB = self._O.basis() base = (([R.zero()] * 3) + ([self._O.zero()] * 3)) ret = [] for i in range(3): temp = list(base) temp[i] = R.one() ret.append(self.element_class(self, temp)) for i in range(3): for b in OB: temp = list(base) temp[(3 + i)] = b ret.append(self.element_class(self, temp)) return Family(ret) algebra_generators = basis def gens(self): '\n Return the generators of ``self``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: G = J.gens()\n sage: G[0]\n [1 0 0]\n [0 0 0]\n [0 0 0]\n sage: G[5]\n [ 0 j 0]\n [-j 0 0]\n [ 0 0 0]\n sage: G[22]\n [ 0 0 0]\n [ 0 0 k]\n [ 0 -k 0]\n ' return tuple(self.algebra_generators()) @cached_method def zero(self): '\n Return the additive identity.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: J.zero()\n [0 0 0]\n [0 0 0]\n [0 0 0]\n ' Rz = self.base_ring().zero() Oz = self._O.zero() return self.element_class(self, (Rz, Rz, Rz, Oz, Oz, Oz)) @cached_method def one(self): '\n Return multiplicative identity.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: J.one()\n [1 0 0]\n [0 1 0]\n [0 0 1]\n sage: all(J.one() * b == b for b in J.basis())\n True\n ' one = self.base_ring().one() zero = self._O.zero() return self.element_class(self, (one, one, one, zero, zero, zero)) def some_elements(self): '\n Return some elements of ``self``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: J.some_elements()\n [[6/5 0 0]\n [ 0 6/5 0]\n [ 0 0 6/5],\n [1 0 0]\n [0 1 0]\n [0 0 1],\n [0 0 0]\n [0 0 0]\n [0 0 0],\n [0 0 0]\n [0 1 0]\n [0 0 0],\n [ 0 j 0]\n [-j 0 0]\n [ 0 0 0],\n [ 0 0 lj]\n [ 0 0 0]\n [-lj 0 0],\n [ 0 0 0]\n [ 0 1 1/2*lj]\n [ 0 -1/2*lj 0],\n [ 1 0 j + 2*li]\n [ 0 1 0]\n [-j - 2*li 0 1],\n [ 1 j + lk l]\n [-j - lk 0 i + lj]\n [ -l -i - lj 0],\n [ 1 3/2*l 2*k]\n [-3/2*l 0 5/2*j]\n [ -2*k -5/2*j 0]]\n\n sage: O = OctonionAlgebra(GF(3))\n sage: J = JordanAlgebra(O)\n sage: J.some_elements()\n [[-1 0 0]\n [ 0 -1 0]\n [ 0 0 -1],\n [1 0 0]\n [0 1 0]\n [0 0 1],\n [0 0 0]\n [0 0 0]\n [0 0 0],\n [0 0 0]\n [0 1 0]\n [0 0 0],\n [ 0 j 0]\n [-j 0 0]\n [ 0 0 0],\n [ 0 0 lj]\n [ 0 0 0]\n [-lj 0 0],\n [ 0 0 0]\n [ 0 1 -lj]\n [ 0 lj 0],\n [ 1 0 j - li]\n [ 0 1 0]\n [-j + li 0 1],\n [ 1 j + lk l]\n [-j - lk 0 i + lj]\n [ -l -i - lj 0],\n [ 1 0 -k]\n [ 0 0 j]\n [ k -j 0]]\n ' B = self.basis() S = [self.an_element(), self.one(), self.zero(), B[1], B[5], B[17], (B[1] + (self._half * B[25])), ((self.one() + B[13]) + (2 * B[16]))] S.append(sum(B[::5])) S.append(sum((((self._half * ind) * b) for (ind, b) in enumerate(B[::7], start=2)))) return S class Element(AlgebraElement): '\n An element of an exceptional Jordan algebra.\n ' def __init__(self, parent, data): '\n Initialize ``self``.\n\n TESTS::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: elt = sum(J.basis())\n sage: TestSuite(elt).run()\n ' self._data = tuple(data) AlgebraElement.__init__(self, parent) def _to_print_matrix(self): '\n Return ``self`` as a matrix for printing.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: elt = J([2, 3, 0, -1 + O.basis()[2], O.basis()[3], -O.basis()[5] + 5*O.basis()[7]])\n sage: elt._to_print_matrix()\n [ 2 j - 1 k]\n [ -j - 1 3 -li + 5*lk]\n [ -k li - 5*lk 0]\n ' PR = self.parent()._repr_poly_ring gens = ([PR.one()] + list(PR.gens())) data = [PR(self._data[i]) for i in range(3)] data.extend((PR.sum(((c * g) for (c, g) in zip(self._data[(3 + i)].vector(), gens))) for i in range(3))) for i in range(1, 8): gens[i] = (- gens[i]) data.extend((PR.sum(((c * g) for (c, g) in zip(self._data[(3 + i)].vector(), gens))) for i in range(3))) return matrix(PR, [[data[0], data[3], data[4]], [data[6], data[1], data[5]], [data[7], data[8], data[2]]]) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: J.an_element()\n [6/5 0 0]\n [ 0 6/5 0]\n [ 0 0 6/5]\n ' return repr(self._to_print_matrix()) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: latex(J.an_element())\n \\left(\\begin{array}{rrr}\n \\frac{6}{5} & 0 & 0 \\\\\n 0 & \\frac{6}{5} & 0 \\\\\n 0 & 0 & \\frac{6}{5}\n \\end{array}\\right)\n ' from sage.misc.latex import latex return latex(self._to_print_matrix()) def _ascii_art_(self): '\n Return an ascii art representation of ``self``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: ascii_art(J.an_element())\n [6/5 0 0]\n [ 0 6/5 0]\n [ 0 0 6/5]\n ' from sage.typeset.ascii_art import ascii_art return ascii_art(self._to_print_matrix()) def _unicode_art_(self): '\n Return a unicode art representation of ``self``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: unicode_art(J.an_element())\n ⎛6/5 0 0⎞\n ⎜ 0 6/5 0⎟\n ⎝ 0 0 6/5⎠\n ' from sage.typeset.unicode_art import unicode_art return unicode_art(self._to_print_matrix()) def __bool__(self) -> bool: '\n Return if ``self`` is non-zero.\n\n TESTS::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: all(bool(b) for b in J.basis())\n True\n sage: bool(J.zero())\n False\n ' return any((d for d in self._data)) def _richcmp_(self, other, op): '\n Rich comparison of ``self`` with ``other`` by ``op``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: x = sum(J.basis()[::6])\n sage: y = sum(J.basis()[::5])\n sage: x == x\n True\n sage: x == y\n False\n sage: x < y\n True\n sage: x != J.zero()\n True\n ' return richcmp(self._data, other._data, op) def _add_(self, other): '\n Add ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: x = sum(J.basis()[::6])\n sage: y = sum(J.basis()[::5])\n sage: x + x\n [ 2 2*k 2*i + 2*lk]\n [ -2*k 0 2*li]\n [-2*i - 2*lk -2*li 0]\n sage: x + y\n [ 2 j + k + lk i + l + lk]\n [ -j - k - lk 0 i + li + lj]\n [ -i - l - lk -i - li - lj 0]\n ' return self.__class__(self.parent(), [(a + b) for (a, b) in zip(self._data, other._data)]) def _neg_(self): '\n Negate ``self``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: x = sum(J.basis()[::6])\n sage: -x\n [ -1 -k -i - lk]\n [ k 0 -li]\n [ i + lk li 0]\n ' return self.__class__(self.parent(), [(- c) for c in self._data]) def _sub_(self, other): '\n Subtract ``other`` from ``self``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: x = sum(J.basis()[::6])\n sage: y = sum(J.basis()[::5])\n sage: x - x\n [0 0 0]\n [0 0 0]\n [0 0 0]\n sage: x - y\n [ 0 -j + k - lk i - l + lk]\n [ j - k + lk 0 -i + li - lj]\n [ -i + l - lk i - li + lj 0]\n ' return self.__class__(self.parent(), [(a - b) for (a, b) in zip(self._data, other._data)]) def _mul_(self, other): '\n Multiply ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: x = sum(J.basis()[::7])\n sage: y = sum(J.basis()[::11])\n sage: x * y\n [ 1 -1/2*j + 1/2*l + 1/2 1/2*k + 1/2*lk + 1/2]\n [ 1/2*j - 1/2*l + 1/2 0 -1/2*l]\n [-1/2*k - 1/2*lk + 1/2 1/2*l 0]\n ' P = self.parent() SD = self._data OD = other._data X = [[SD[0], SD[3], SD[4]], [SD[3].conjugate(), SD[1], SD[5]], [SD[4].conjugate(), SD[5].conjugate(), SD[2]]] Y = [[OD[0], OD[3], OD[4]], [OD[3].conjugate(), OD[1], OD[5]], [OD[4].conjugate(), OD[5].conjugate(), OD[2]]] ret = [(((X[0][0] * Y[0][0]) + (X[0][1] * Y[1][0]).real_part()) + (X[0][2] * Y[2][0]).real_part()), (((X[1][1] * Y[1][1]) + (X[1][0] * Y[0][1]).real_part()) + (X[1][2] * Y[2][1]).real_part()), (((X[2][2] * Y[2][2]) + (X[2][0] * Y[0][2]).real_part()) + (X[2][1] * Y[1][2]).real_part())] ret += [(sum((((X[r][i] * Y[i][c]) + (Y[r][i] * X[i][c])) for i in range(3))) * P._half) for (r, c) in [(0, 1), (0, 2), (1, 2)]] return self.__class__(P, ret) def _lmul_(self, other): '\n Multiply ``self`` by the scalar ``other`` on the left.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: elt = sum(2 * b for b in J.basis()[::6]); elt\n [ 2 2*k 2*i + 2*lk]\n [ -2*k 0 2*li]\n [-2*i - 2*lk -2*li 0]\n sage: elt * 2\n [ 4 4*k 4*i + 4*lk]\n [ -4*k 0 4*li]\n [-4*i - 4*lk -4*li 0]\n ' return self.__class__(self.parent(), [(c * other) for c in self._data]) def _rmul_(self, other): '\n Multiply ``self`` with the scalar ``other`` by the right\n action.\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: elt = sum(b * 2 for b in J.basis()[::6]); elt\n [ 2 2*k 2*i + 2*lk]\n [ -2*k 0 2*li]\n [-2*i - 2*lk -2*li 0]\n sage: (1/2) * elt\n [ 1 k i + lk]\n [ -k 0 li]\n [-i - lk -li 0]\n ' return self.__class__(self.parent(), [(other * c) for c in self._data]) def monomial_coefficients(self, copy=True): '\n Return a dictionary whose keys are indices of basis elements in\n the support of ``self`` and whose values are the corresponding\n coefficients.\n\n INPUT:\n\n - ``copy`` -- ignored\n\n EXAMPLES::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: elt = sum(~QQ(ind) * b for ind, b in enumerate(J.basis()[::6], start=1)); elt\n [ 1 1/2*k 1/3*i + 1/4*lk]\n [ -1/2*k 0 1/5*li]\n [-1/3*i - 1/4*lk -1/5*li 0]\n sage: elt.monomial_coefficients()\n {0: 1, 6: 1/2, 12: 1/3, 18: 1/4, 24: 1/5}\n\n TESTS::\n\n sage: O = OctonionAlgebra(QQ)\n sage: J = JordanAlgebra(O)\n sage: all(b.monomial_coefficients() == {i: 1} for i,b in enumerate(J.basis()))\n True\n ' ret = {} for i in range(3): if self._data[i]: ret[i] = self._data[i] mc = self._data[(3 + i)].monomial_coefficients() for (k, coeff) in mc.items(): ret[((3 + (i * 8)) + k)] = coeff return ret
class AbelianLieAlgebra(LieAlgebraWithStructureCoefficients): '\n An abelian Lie algebra.\n\n A Lie algebra `\\mathfrak{g}` is abelian if `[x, y] = 0` for all\n `x, y \\in \\mathfrak{g}`.\n\n EXAMPLES::\n\n sage: L.<x, y> = LieAlgebra(QQ, abelian=True)\n sage: L.bracket(x, y)\n 0\n ' @staticmethod def __classcall_private__(cls, R, names=None, index_set=None, category=None, **kwds): "\n Normalize input to ensure a unique representation.\n\n TESTS::\n\n sage: L1 = LieAlgebra(QQ, 'x,y', {})\n sage: L2.<x, y> = LieAlgebra(QQ, abelian=True)\n sage: L1 is L2\n True\n " (names, index_set) = standardize_names_index_set(names, index_set) if (index_set.cardinality() == infinity): return InfiniteDimensionalAbelianLieAlgebra(R, index_set, **kwds) return super().__classcall__(cls, R, names, index_set, category=category, **kwds) def __init__(self, R, names, index_set, category, **kwds): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, 3, 'x', abelian=True)\n sage: TestSuite(L).run()\n " cat = LieAlgebras(R).FiniteDimensional().WithBasis().Nilpotent() category = cat.or_subcategory(category) LieAlgebraWithStructureCoefficients.__init__(self, R, Family({}), names, index_set, category, **kwds) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: LieAlgebra(QQ, 3, 'x', abelian=True)\n Abelian Lie algebra on 3 generators (x0, x1, x2) over Rational Field\n " gens = self.lie_algebra_generators() if (gens.cardinality() == 1): return 'Abelian Lie algebra on generator {} over {}'.format(tuple(gens)[0], self.base_ring()) return 'Abelian Lie algebra on {} generators {} over {}'.format(gens.cardinality(), tuple(gens), self.base_ring()) def _construct_UEA(self): "\n Construct the universal enveloping algebra of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, 3, 'x', abelian=True)\n sage: L._construct_UEA()\n Multivariate Polynomial Ring in x0, x1, x2 over Rational Field\n " return PolynomialRing(self.base_ring(), self.variable_names()) def is_abelian(self): "\n Return ``True`` since ``self`` is an abelian Lie algebra.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, 3, 'x', abelian=True)\n sage: L.is_abelian()\n True\n " return True is_nilpotent = is_solvable = is_abelian class Element(LieAlgebraWithStructureCoefficients.Element): def _bracket_(self, y): '\n Return the Lie bracket ``[self, y]``.\n\n EXAMPLES::\n\n sage: L.<x, y> = LieAlgebra(QQ, abelian=True)\n sage: L.bracket(x, y)\n 0\n ' return self.parent().zero()
class InfiniteDimensionalAbelianLieAlgebra(InfinitelyGeneratedLieAlgebra, IndexedGenerators): '\n An infinite dimensional abelian Lie algebra.\n\n A Lie algebra `\\mathfrak{g}` is abelian if `[x, y] = 0` for all\n `x, y \\in \\mathfrak{g}`.\n ' def __init__(self, R, index_set, prefix='L', **kwds): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, index_set=ZZ, abelian=True)\n sage: TestSuite(L).run()\n ' cat = LieAlgebras(R).WithBasis() InfinitelyGeneratedLieAlgebra.__init__(self, R, category=cat) IndexedGenerators.__init__(self, index_set, prefix=prefix, **kwds) def dimension(self): '\n Return the dimension of ``self``, which is `\\infty`.\n\n EXAMPLES::\n\n sage: L = lie_algebras.abelian(QQ, index_set=ZZ)\n sage: L.dimension()\n +Infinity\n ' return infinity def is_abelian(self): '\n Return ``True`` since ``self`` is an abelian Lie algebra.\n\n EXAMPLES::\n\n sage: L = lie_algebras.abelian(QQ, index_set=ZZ)\n sage: L.is_abelian()\n True\n ' return True is_nilpotent = is_solvable = is_abelian _repr_term = IndexedGenerators._repr_generator _latex_term = IndexedGenerators._latex_generator class Element(LieAlgebraElement): def _bracket_(self, other): '\n Return the Lie bracket ``[self, y]``.\n\n EXAMPLES::\n\n sage: L = lie_algebras.abelian(QQ, index_set=ZZ)\n sage: B = L.basis()\n sage: l1 = B[1]\n sage: l5 = B[5]\n sage: l1.bracket(l5)\n 0\n ' return self.parent().zero()
class AffineLieAlgebra(FinitelyGeneratedLieAlgebra): '\n An (untwisted) affine Lie algebra.\n\n Note that the derived subalgebra of the Kac-Moody algebra is the\n affine Lie algebra.\n\n INPUT:\n\n Can be one of the following:\n\n - a base ring and an affine Cartan type: constructs the affine\n (Kac-Moody) Lie algebra of the classical Lie algebra in the\n bracket representation over the base ring\n\n - a classical Lie algebra: constructs the corresponding affine\n (Kac-Moody) Lie algebra\n\n There is the optional argument ``kac_moody``, which can be set\n to ``False`` to obtain the affine Lie algebra instead of the affine\n Kac-Moody algebra.\n\n .. SEEALSO::\n\n - :class:`UntwistedAffineLieAlgebra`\n - :class:`TwistedAffineLieAlgebra`\n\n REFERENCES:\n\n - [Ka1990]_\n ' @staticmethod def __classcall_private__(cls, arg0, cartan_type=None, kac_moody=True): "\n Parse input to ensure a unique representation.\n\n INPUT:\n\n - ``arg0`` -- a simple Lie algebra or a base ring\n - ``cartan_type`` -- a Cartan type\n\n EXAMPLES::\n\n sage: L1 = lie_algebras.Affine(QQ, ['A', 4, 1])\n sage: cl = lie_algebras.sl(QQ, 5)\n sage: L2 = lie_algebras.Affine(cl)\n sage: L1 is L2\n True\n sage: cl.affine() is L1\n True\n\n sage: L1 = LieAlgebra(QQ, cartan_type=['A', 5, 2])\n sage: L2 = lie_algebras.Affine(QQ, ['A', 5, 2])\n sage: L1 is L2\n True\n " if isinstance(arg0, LieAlgebra): ct = arg0.cartan_type() if (not ct.is_finite()): raise ValueError('the base Lie algebra is not simple') cartan_type = ct.affine() g = arg0 else: cartan_type = CartanType(cartan_type) if (not cartan_type.is_affine()): raise ValueError('the Cartan type must be affine') if cartan_type.is_untwisted_affine(): g = LieAlgebra(arg0, cartan_type=cartan_type.classical()) if cartan_type.is_untwisted_affine(): return UntwistedAffineLieAlgebra(g, kac_moody=kac_moody) return TwistedAffineLieAlgebra(arg0, cartan_type, kac_moody=kac_moody) def __init__(self, g, cartan_type, names, kac_moody): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: asl = lie_algebras.Affine(QQ, ['D', 4, 1])\n sage: TestSuite(asl).run()\n " self._g = g self._cartan_type = cartan_type if kac_moody: names += ['d'] self._kac_moody = kac_moody names = tuple(names) self._ordered_indices = names R = g.base_ring() cat = KacMoodyAlgebras(R).WithBasis() if (not self._cartan_type.is_untwisted_affine()): cat = cat.Subobjects() FinitelyGeneratedLieAlgebra.__init__(self, R, names, names, category=cat) @cached_method def basis(self): "\n Return the basis of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['D', 4, 1])\n sage: B = g.basis()\n sage: al = RootSystem(['D',4]).root_lattice().simple_roots()\n sage: B[al[1]+al[2]+al[4],4]\n (E[alpha[1] + alpha[2] + alpha[4]])#t^4\n sage: B[-al[1]-2*al[2]-al[3]-al[4],2]\n (E[-alpha[1] - 2*alpha[2] - alpha[3] - alpha[4]])#t^2\n sage: B[al[4],-2]\n (E[alpha[4]])#t^-2\n sage: B['c']\n c\n sage: B['d']\n d\n\n sage: g = LieAlgebra(QQ, cartan_type=['D', 4, 2], kac_moody=False)\n sage: B = g.basis()\n sage: it = iter(B)\n sage: [next(it) for _ in range(3)]\n [c, (E[alpha[1]])#t^0, (E[alpha[2]])#t^0]\n sage: B['c']\n c\n sage: B['d']\n 0\n " if self._cartan_type.is_untwisted_affine(): K = cartesian_product([self._g.basis().keys(), ZZ]) else: K = TwistedAffineIndices(self._cartan_type) from sage.sets.finite_enumerated_set import FiniteEnumeratedSet c = FiniteEnumeratedSet(['c']) if self._kac_moody: d = FiniteEnumeratedSet(['d']) keys = DisjointUnionEnumeratedSets([c, d, K]) else: keys = DisjointUnionEnumeratedSets([c, K]) return Family(keys, self.monomial) def _element_constructor_(self, x): "\n Construct an element of ``self`` from ``x``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['A',1])\n sage: A = g.affine()\n sage: D = A.derived_subalgebra()\n sage: A(D.an_element())\n (E[alpha[1]] + h1 + E[-alpha[1]])#t^0\n + (E[-alpha[1]])#t^1 + (E[alpha[1]])#t^-1 + c\n sage: A(g.an_element())\n (E[alpha[1]] + h1 + E[-alpha[1]])#t^0\n " P = parent(x) if (P is self.derived_subalgebra()): return self.element_class(self, x.t_dict(), x.c_coefficient(), x.d_coefficient()) if (P == self._g): zero = self.base_ring().zero() return self.element_class(self, {0: x}, zero, zero) return super()._element_constructor_(x) def _coerce_map_from_(self, R): "\n Return the coerce map from ``R`` to ``self`` or ``True`` if\n a coerce map exists.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['G',2])\n sage: A = g.affine()\n sage: A.has_coerce_map_from(g)\n True\n sage: D = A.derived_subalgebra()\n sage: A.has_coerce_map_from(D)\n True\n " if ((R is self.derived_subalgebra()) or (R is self._g)): return True return super()._coerce_map_from_(R) def derived_series(self): "\n Return the derived series of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['B',3,1])\n sage: g.derived_series()\n [Affine Kac-Moody algebra of ['B', 3] in the Chevalley basis,\n Affine Lie algebra of ['B', 3] in the Chevalley basis]\n sage: g.lower_central_series()\n [Affine Kac-Moody algebra of ['B', 3] in the Chevalley basis,\n Affine Lie algebra of ['B', 3] in the Chevalley basis]\n\n sage: D = g.derived_subalgebra()\n sage: D.derived_series()\n [Affine Lie algebra of ['B', 3] in the Chevalley basis]\n " if self._kac_moody: return [self, self.derived_subalgebra()] return [self] lower_central_series = derived_series def is_nilpotent(self): "\n Return ``False`` as ``self`` is semisimple.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['B',3,1])\n sage: g.is_nilpotent()\n False\n sage: g.is_solvable()\n False\n " return False is_solvable = is_nilpotent def cartan_type(self): "\n Return the Cartan type of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['C',3,1])\n sage: g.cartan_type()\n ['C', 3, 1]\n " return self._cartan_type def classical(self): "\n Return the classical Lie algebra of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['F',4,1])\n sage: g.classical()\n Lie algebra of ['F', 4] in the Chevalley basis\n\n sage: so5 = lie_algebras.so(QQ, 5, 'matrix')\n sage: A = so5.affine()\n sage: A.classical() == so5\n True\n " return self._g @cached_method def zero(self): "\n Return the element `0`.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['F',4,1])\n sage: g.zero()\n 0\n " zero = self.base_ring().zero() return self.element_class(self, {}, zero, zero) @cached_method def c(self): "\n Return the canonical central element `c` of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['A',3,1])\n sage: g.c()\n c\n " R = self.base_ring() return self.element_class(self, {}, R.one(), R.zero()) @cached_method def d(self): "\n Return the canonical derivation `d` of ``self``.\n\n If ``self`` is the affine Lie algebra, then this returns `0`.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['A',3,1])\n sage: g.d()\n d\n sage: D = g.derived_subalgebra()\n sage: D.d()\n 0\n " if (not self._kac_moody): return self.zero() R = self.base_ring() return self.element_class(self, {}, R.zero(), R.one()) @cached_method def lie_algebra_generators(self): "\n Return the Lie algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['A',1,1])\n sage: list(g.lie_algebra_generators())\n [(E[alpha[1]])#t^0,\n (E[-alpha[1]])#t^0,\n (h1)#t^0,\n (E[-alpha[1]])#t^1,\n (E[alpha[1]])#t^-1,\n c,\n d]\n\n sage: L = LieAlgebra(QQ, cartan_type=['A',5,2])\n sage: list(L.lie_algebra_generators())\n [(E[alpha[1]])#t^0,\n (E[alpha[2]])#t^0,\n (E[alpha[3]])#t^0,\n (E[-alpha[1]])#t^0,\n (E[-alpha[2]])#t^0,\n (E[-alpha[3]])#t^0,\n (h1)#t^0,\n (h2)#t^0,\n (h3)#t^0,\n (E[-alpha[1] - 2*alpha[2] - alpha[3]])#t^1,\n (E[alpha[1] + 2*alpha[2] + alpha[3]])#t^-1,\n c,\n d]\n " zero = self.base_ring().zero() d = {} if self._kac_moody: d['d'] = self.d() d['c'] = self.c() try: finite_gens = dict(self._g.lie_algebra_generators(True)) except TypeError: finite_gens = dict(self._g.lie_algebra_generators()) for (k, g) in finite_gens.items(): d[k] = self.element_class(self, {0: g}, zero, zero) if self._cartan_type.is_untwisted_affine(): d['e0'] = self.element_class(self, {1: self._g.highest_root_basis_elt(False)}, zero, zero) d['f0'] = self.element_class(self, {(- 1): self._g.highest_root_basis_elt(True)}, zero, zero) elif (self._cartan_type.type() != 'BC'): a = self._cartan_type.a() Q = self._g._Q theta = Q._from_dict({i: a[i] for i in Q.index_set()}, remove_zeros=False) d['e0'] = self.element_class(self, {1: self._g.basis()[(- theta)]}, zero, zero) d['f0'] = self.element_class(self, {(- 1): self._g.basis()[theta]}, zero, zero) else: n = self._g.cartan_type().rank() a = self._cartan_type.a() Q = self._g._Q theta = Q._from_dict({i: ZZ(2) for i in Q.index_set()}, remove_zeros=False) d[f'e{n}'] = self.element_class(self, {1: self._g1.basis()[(- theta)]}, zero, zero) d[f'f{n}'] = self.element_class(self, {(- 1): self._g1.basis()[theta]}, zero, zero) return Family(self.variable_names(), d.__getitem__) def e(self, i=None): "\n Return the generators `e` of ``self``.\n\n INPUT:\n\n - ``i`` -- (optional) if specified, return just the\n generator `e_i`\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['B', 3, 1])\n sage: list(g.e())\n [(E[-alpha[1] - 2*alpha[2] - 2*alpha[3]])#t^1,\n (E[alpha[1]])#t^0, (E[alpha[2]])#t^0, (E[alpha[3]])#t^0]\n sage: g.e(2)\n (E[alpha[2]])#t^0\n " gens = self.lie_algebra_generators() if (i is None): I = self._cartan_type.index_set() d = {j: gens[f'e{j}'] for j in I} return Family(I, d.__getitem__) return gens[f'e{i}'] def f(self, i=None): "\n Return the generators `f` of ``self``.\n\n INPUT:\n\n - ``i`` -- (optional) if specified, return just the\n generator `f_i`\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['A', 5, 2])\n sage: list(g.f())\n [(E[alpha[1] + 2*alpha[2] + alpha[3]])#t^-1,\n (E[-alpha[1]])#t^0, (E[-alpha[2]])#t^0, (E[-alpha[3]])#t^0]\n sage: g.f(2)\n (E[-alpha[2]])#t^0\n " gens = self.lie_algebra_generators() if (i is None): I = self._cartan_type.index_set() d = {j: gens[f'f{j}'] for j in I} return Family(I, d.__getitem__) return gens[f'f{i}'] def monomial(self, m): "\n Construct the monomial indexed by ``m``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['B',4,1])\n sage: al = RootSystem(['B',4]).root_lattice().simple_roots()\n sage: g.monomial((al[1]+al[2]+al[3],4))\n (E[alpha[1] + alpha[2] + alpha[3]])#t^4\n sage: g.monomial((-al[1]-al[2]-2*al[3]-2*al[4],2))\n (E[-alpha[1] - alpha[2] - 2*alpha[3] - 2*alpha[4]])#t^2\n sage: g.monomial((al[4],-2))\n (E[alpha[4]])#t^-2\n sage: g.monomial('c')\n c\n sage: g.monomial('d')\n d\n " if (m == 'c'): return self.c() if (m == 'd'): return self.d() G = self._g.basis() zero = self.base_ring().zero() return self.element_class(self, {m[1]: G[m[0]]}, zero, zero)
class UntwistedAffineLieAlgebra(AffineLieAlgebra): "\n An untwisted affine Lie algebra.\n\n Let `R` be a ring. Given a finite-dimensional simple Lie algebra\n `\\mathfrak{g}` over `R`, the affine Lie algebra\n `\\widehat{\\mathfrak{g}}^{\\prime}` associated to `\\mathfrak{g}` is\n defined as\n\n .. MATH::\n\n \\widehat{\\mathfrak{g}}' = \\bigl( \\mathfrak{g} \\otimes\n R[t, t^{-1}] \\bigr) \\oplus R c,\n\n where `c` is the canonical central element and `R[t, t^{-1}]` is the\n Laurent polynomial ring over `R`. The Lie bracket is defined as\n\n .. MATH::\n\n [x \\otimes t^m + \\lambda c, y \\otimes t^n + \\mu c] =\n [x, y] \\otimes t^{m+n} + m \\delta_{m,-n} ( x | y ) c,\n\n where `( x | y )` is the Killing form on `\\mathfrak{g}`.\n\n There is a canonical derivation `d` on `\\widehat{\\mathfrak{g}}'`\n that is defined by\n\n .. MATH::\n\n d(x \\otimes t^m + \\lambda c) = a \\otimes m t^m,\n\n or equivalently by `d = t \\frac{d}{dt}`.\n\n The affine Kac-Moody algebra `\\widehat{\\mathfrak{g}}` is formed by\n adjoining the derivation `d` such that\n\n .. MATH::\n\n \\widehat{\\mathfrak{g}} = \\bigl( \\mathfrak{g} \\otimes R[t,t^{-1}]\n \\bigr) \\oplus R c \\oplus R d.\n\n Specifically, the bracket on `\\widehat{\\mathfrak{g}}` is defined as\n\n .. MATH::\n\n [t^m \\otimes x \\oplus \\lambda c \\oplus \\mu d, t^n \\otimes y \\oplus\n \\lambda_1 c \\oplus \\mu_1 d] = \\bigl( t^{m+n} [x,y] + \\mu n t^n \\otimes\n y - \\mu_1 m t^m \\otimes x\\bigr) \\oplus m \\delta_{m,-n} (x|y) c .\n\n EXAMPLES:\n\n We begin by constructing an affine Kac-Moody algebra of type `G_2^{(1)}`\n from the classical Lie algebra of type `G_2`::\n\n sage: g = LieAlgebra(QQ, cartan_type=['G',2])\n sage: A = g.affine()\n sage: A\n Affine Kac-Moody algebra of ['G', 2] in the Chevalley basis\n\n Next, we construct the generators and perform some computations::\n\n sage: A.inject_variables()\n Defining e1, e2, f1, f2, h1, h2, e0, f0, c, d\n sage: e1.bracket(f1)\n (h1)#t^0\n sage: e0.bracket(f0)\n (-h1 - 2*h2)#t^0 + 8*c\n sage: e0.bracket(f1)\n 0\n sage: A[d, f0]\n (-E[3*alpha[1] + 2*alpha[2]])#t^-1\n sage: A([[e0, e2], [[[e1, e2], [e0, [e1, e2]]], e1]])\n (-6*E[-3*alpha[1] - alpha[2]])#t^2\n sage: f0.bracket(f1)\n 0\n sage: f0.bracket(f2)\n (E[3*alpha[1] + alpha[2]])#t^-1\n sage: A[h1+3*h2, A[[[f0, f2], f1], [f1,f2]] + f1] - f1\n (2*E[alpha[1]])#t^-1\n\n We can construct its derived subalgebra, the affine Lie algebra\n of type `G_2^{(1)}`. In this case, there is no canonical derivation,\n so the generator `d` is `0`::\n\n sage: D = A.derived_subalgebra()\n sage: D.d()\n 0\n " def __init__(self, g, kac_moody): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: asl = lie_algebras.Affine(QQ, ['A',4,1])\n sage: TestSuite(asl).run()\n " cartan_type = g.cartan_type().affine() names = (list(g.variable_names()) + ['e0', 'f0', 'c']) super().__init__(g, cartan_type, names, kac_moody) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['D',4,1])\n sage: g\n Affine Kac-Moody algebra of ['D', 4] in the Chevalley basis\n sage: g.derived_subalgebra()\n Affine Lie algebra of ['D', 4] in the Chevalley basis\n " base = 'Affine ' rep = repr(self._g) if self._kac_moody: old_len = len(rep) rep = rep.replace('Lie', 'Kac-Moody') if (len(rep) == old_len): base += 'Kac-Moody ' return (base + rep) def derived_subalgebra(self): "\n Return the derived subalgebra of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['B',3,1])\n sage: g\n Affine Kac-Moody algebra of ['B', 3] in the Chevalley basis\n sage: D = g.derived_subalgebra(); D\n Affine Lie algebra of ['B', 3] in the Chevalley basis\n sage: D.derived_subalgebra() == D\n True\n " if self._kac_moody: return UntwistedAffineLieAlgebra(self._g, kac_moody=False) return self Element = UntwistedAffineLieAlgebraElement
class TwistedAffineLieAlgebra(AffineLieAlgebra): '\n A twisted affine Lie algebra.\n\n A twisted affine Lie algebra is an affine Lie algebra for\n type `X_N^{(r)}` with `r > 1`. We realize this inside an\n untwisted affine Kac--Moody Lie algebra following Chapter 8\n of [Ka1990]_.\n\n Let `\\overline{\\mathfrak{g}}` be the classical Lie algebra by\n taking the index set `I \\setminus \\{\\epsilon\\}`, where\n `\\epsilon = 0` unless `\\epsilon = n` for `X_N^{(r)} = A_{2n}^{(2)}`,\n for the twisted affine Lie algebra `\\widetilde{\\mathfrak{g}}`.\n Let `\\mathfrak{g}` be the basic Lie algebra of type `X_N`.\n We realize `\\overline{\\mathfrak{g}}` as the fixed-point subalgebra\n `\\mathfrak{g}^{(0)}` of `\\mathfrak{g}` under the order `r` diagram\n automorphism `\\mu`. This naturally acts on the `\\zeta_r` (a primitive\n `r`-th root of unity) eigenspace `\\mathfrak{g}^{(1)}` of `\\mu`,\n which is the highest weight representation corresponding to\n the small adjoint (where the weight spaces are the short roots\n of `\\overline{\\mathfrak{g}}`). The *twisted affine (Kac-Moody)\n Lie algebra* `\\widehat{\\mathfrak{g}}` is constructed as the\n subalgebra of `X_N^{(1)}` given by\n\n .. MATH::\n\n \\sum_{i \\in \\ZZ} \\mathfrak{g}^{(i \\mod 2)} \\otimes t^i\n \\oplus R c \\oplus R d,\n\n where `R` is the base ring.\n\n We encode our basis by using the classical Lie algebra except\n for type `A_{2n}^{(2)}`. For type `A_{2n}^{(2)}`, the fixed-point\n algebra `\\mathfrak{g}^{(0)}` is of type `B_n` using the index set\n `\\{0, \\ldots, n-1\\}`. For `\\mathfrak{g}^{(1)}`, we identify the\n weights in this representation with the roots of type `B_n` and\n the double all of its short roots.\n ' def __init__(self, R, cartan_type, kac_moody): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.Affine(QQ, ['A', 5, 2])\n sage: TestSuite(g).run()\n\n sage: g = lie_algebras.Affine(QQ, ['D', 4, 2])\n sage: TestSuite(g).run()\n\n sage: g = lie_algebras.Affine(QQ, ['D', 5, 2])\n sage: TestSuite(g).run()\n\n sage: g = lie_algebras.Affine(QQ, ['A', 6, 2])\n sage: TestSuite(g).run()\n\n sage: g = lie_algebras.Affine(QQ, ['A', 2, 2])\n sage: TestSuite(g).run()\n\n sage: g = lie_algebras.Affine(QQ, ['E', 6, 2])\n sage: TestSuite(g).run() # long time\n\n sage: g = lie_algebras.Affine(QQ, ['D', 4, 3])\n sage: TestSuite(g).run() # long time\n " if (cartan_type.type() == 'BC'): classical = cartan_type.classical().dual() n = classical.rank() classical = classical.relabel({(n - i): i for i in range(n)}) else: classical = cartan_type.classical() g = LieAlgebra(R, cartan_type=classical) n = classical.rank() names = [('e%s' % i) for i in range(1, (n + 1))] names.extend((('f%s' % i) for i in range(1, (n + 1)))) if (cartan_type.type() == 'BC'): names.extend((('h%s' % i) for i in range(n))) else: names.extend((('h%s' % i) for i in range(1, (n + 1)))) names += ['e0', 'f0', 'c'] super().__init__(g, cartan_type, names, kac_moody) basic_ct = cartan_type.basic_untwisted() if (cartan_type.dual().type() == 'B'): ep = [(i, (i + 1)) for i in range(1, n)] ep.extend((((i + 1), i) for i in range(n, ((2 * n) - 1)))) elif (cartan_type.dual().type() == 'F'): ep = [(1, 3), (3, 4), (5, 4), (6, 5), (4, 2)] elif (cartan_type.dual().type() == 'G'): ep = [(1, 2), (3, 2), (4, 2)] else: ep = basic_ct.dynkin_diagram().to_undirected().edges(labels=False, sort=False) if (self._cartan_type.dual().type() == 'G'): from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing RP = PolynomialRing(R, 'x') Rext = RP.quotient(((RP.gen(0) ** 3) - 1)) self._basic = LieAlgebra(Rext, cartan_type=basic_ct, epsilon=ep) else: self._basic = LieAlgebra(R, cartan_type=basic_ct, epsilon=ep) self._ambient = self._basic.affine(kac_moody=self._kac_moody) basic_ct = self._basic.cartan_type() if (self._cartan_type.dual().type() == 'G'): gens = basic_ct.dynkin_diagram().automorphism_group().gens() auto = (gens[0] * gens[1]) else: auto = basic_ct.dynkin_diagram().automorphism_group().gen(0) basic_Q = basic_ct.root_system().root_lattice() basic_p_roots = basic_Q.positive_roots() visited = set() orbits = [] for al in basic_p_roots: if (al in visited): continue visited.add(al) O = [al] cur = basic_Q._from_dict({auto(i): c for (i, c) in al}, remove_zeros=False) while (cur != al): O.append(cur) visited.add(cur) cur = basic_Q._from_dict({auto(i): c for (i, c) in cur}, remove_zeros=False) orbits.append(O) finite_ct = self._g.cartan_type() Q = finite_ct.root_system().root_lattice() I = finite_ct.index_set() a = finite_ct.symmetrizer() ord = auto.order() if (self._cartan_type.dual().type() == 'F'): reindex = {2: 4, 4: 3, 3: 2, 1: 1} def build_root(O): return Q._from_dict({reindex[i]: ((c * (ord // a[reindex[i]])) / len(O)) for (i, c) in sum(O) if (i in reindex)}, remove_zeros=False) elif (self._cartan_type.type() == 'BC'): reindex = {(n - i): i for i in range(finite_ct.rank())} def build_root(O): return Q._from_dict({reindex[i]: (c * (ord // len(O))) for (i, c) in sum(O) if (i in reindex)}, remove_zeros=False) else: def build_root(O): return Q._from_dict({i: ((c * (ord // a[i])) / len(O)) for (i, c) in sum(O) if (i in I)}, remove_zeros=False) self._root_mapping = {build_root(O): O for O in orbits} for r in list(self._root_mapping.keys()): self._root_mapping[(- r)] = [(- s) for s in self._root_mapping[r]] if (self._cartan_type.type() == 'BC'): assert ({r for r in self._root_mapping if (len(self._root_mapping[r]) > 1)} == set(Q.roots())) if (self._cartan_type.rank() == 2): assert ({(r / 2) for r in self._root_mapping if (len(self._root_mapping[r]) == 1)} == set(Q.roots())) else: assert ({(r / 2) for r in self._root_mapping if (len(self._root_mapping[r]) == 1)} == set(Q.short_roots())) from sage.combinat.free_module import CombinatorialFreeModule X = sorted(self._root_mapping, key=str) self._g1 = CombinatorialFreeModule(R, X, prefix='E') else: assert (set(self._root_mapping) == set(Q.roots())) al = Q.simple_roots() ac = Q.simple_coroots() for i in I: self._root_mapping[ac[i]] = [r.associated_coroot() for r in self._root_mapping[al[i]]] self._inverse_root_map = {O[0]: r for (r, O) in self._root_mapping.items()} def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['D', 4, 2])\n sage: g\n Twisted affine Kac-Moody algebra of type ['C', 3, 1]^* over Rational Field\n sage: g.derived_subalgebra()\n Twisted affine Lie algebra of type ['C', 3, 1]^* over Rational Field\n " rep = 'Twisted affine ' rep += ('Kac-Moody ' if self._kac_moody else 'Lie ') rep += f'algebra of type {self._cartan_type} over {self.base_ring()}' return rep def _test_classical_subalgebra(self, **options): "\n Test the Chevalley basis properties for the classical subalgebra\n of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 5, 2])\n sage: L._test_classical_subalgebra()\n sage: L = LieAlgebra(QQ, cartan_type=['D', 4, 2])\n sage: L._test_classical_subalgebra()\n " tester = self._tester(**options) B = self.basis() roots = set(self._g._Q.roots()) ac = list(self._g._Q.simple_coroots()) from sage.misc.misc import some_tuples for (r, s) in some_tuples(roots, 2, tester._max_runs): ret = B[(r, 0)].bracket(B[(s, 0)]) if ((r + s) in roots): tester.assertEqual(list(ret.support()), [((r + s), 0)], f'obtained [{r}, {s}] == {ret}') elif (r == (- s)): supp = {(ac, 0) for ac in r.associated_coroot().monomials()} tester.assertEqual(set(ret.support()), supp, f'obtained [{r}, {s}] == {ret}') else: tester.assertEqual(ret, self.zero(), f'nonzero for [{r}, {s}]') def derived_subalgebra(self): "\n Return the derived subalgebra of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['A', 5, 2])\n sage: g\n Twisted affine Kac-Moody algebra of type ['B', 3, 1]^* over Rational Field\n sage: D = g.derived_subalgebra(); D\n Twisted affine Lie algebra of type ['B', 3, 1]^* over Rational Field\n sage: D.derived_subalgebra() == D\n True\n " if self._kac_moody: return TwistedAffineLieAlgebra(self.base_ring(), self._cartan_type, kac_moody=False) return self def ambient(self): "\n Return the ambient untwisted affine Lie algebra of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['A', 5, 2])\n sage: g.ambient()\n Affine Kac-Moody algebra of ['A', 5] in the Chevalley basis\n " return self._ambient def retract(self, x): "\n Retract the element ``x`` from the ambient untwisted affine Lie\n algebra into ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['A', 5, 2])\n sage: it = iter(g.basis())\n sage: elts = [next(it) for _ in range(20)]\n sage: elts\n [c,\n d,\n (E[alpha[1]])#t^0,\n (E[alpha[2]])#t^0,\n (E[alpha[3]])#t^0,\n (E[alpha[1] + alpha[2]])#t^0,\n (E[alpha[2] + alpha[3]])#t^0,\n (E[2*alpha[2] + alpha[3]])#t^0,\n (E[alpha[1] + alpha[2] + alpha[3]])#t^0,\n (E[2*alpha[1] + 2*alpha[2] + alpha[3]])#t^0,\n (E[alpha[1] + 2*alpha[2] + alpha[3]])#t^0,\n (E[-alpha[1]])#t^0,\n (E[-alpha[2]])#t^0,\n (E[-alpha[3]])#t^0,\n (E[-alpha[1] - alpha[2]])#t^0,\n (E[-alpha[2] - alpha[3]])#t^0,\n (E[-2*alpha[2] - alpha[3]])#t^0,\n (E[-alpha[1] - alpha[2] - alpha[3]])#t^0,\n (E[-2*alpha[1] - 2*alpha[2] - alpha[3]])#t^0,\n (E[-alpha[1] - 2*alpha[2] - alpha[3]])#t^0]\n sage: all(g.retract(g.to_ambient(x)) == x for x in elts)\n True\n " t_dict = x.t_dict() c_coeff = x.c_coefficient() d_coeff = x.d_coefficient() if (self._cartan_type.dual().type() == 'G'): R = self.base_ring() for i in t_dict: t_dict[i] = self._g._from_dict({self._inverse_root_map[r]: R(c.lift()) for (r, c) in t_dict[i] if (r in self._inverse_root_map)}, remove_zeros=False) elif (self._cartan_type.type() == 'BC'): for i in t_dict: if (i % 2): t_dict[i] = self._g1._from_dict({self._inverse_root_map[r]: c for (r, c) in t_dict[i] if (r in self._inverse_root_map)}, remove_zeros=False) else: t_dict[i] = self._g._from_dict({self._inverse_root_map[r]: c for (r, c) in t_dict[i] if (r in self._inverse_root_map)}, remove_zeros=False) else: for i in t_dict: t_dict[i] = self._g._from_dict({self._inverse_root_map[r]: c for (r, c) in t_dict[i] if (r in self._inverse_root_map)}, remove_zeros=False) return self.element_class(self, t_dict, c_coeff, d_coeff) @lazy_attribute def to_ambient(self): "\n Lift the element ``x`` from the ambient untwisted affine Lie\n algebra into ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['A', 5, 2])\n sage: g.to_ambient\n Generic morphism:\n From: Twisted affine Kac-Moody algebra of type ['B', 3, 1]^* over Rational Field\n To: Affine Kac-Moody algebra of ['A', 5] in the Chevalley basis\n " one = self.base_ring().one() if (self._cartan_type.type() == 'BC'): mone = (- one) def basis_map(r): O = self._root_mapping[r] return self._basic._from_dict({O[0]: one, O[1]: (mone ** (1 + O[1].height()))}, remove_zeros=False) else: def basis_map(r): return self._basic._from_dict({s: one for s in self._root_mapping[r]}, remove_zeros=False) if (self._cartan_type.dual().type() == 'G'): zeta3 = self._basic.base_ring().gen() def basis_alt(r): return self._basic._from_dict({s: (zeta3 ** ind) for (ind, s) in enumerate(self._root_mapping[r])}, remove_zeros=False) elif (self._cartan_type.type() == 'BC'): def basis_alt(r): O = self._root_mapping[r] if (len(O) == 1): return self._basic.monomial(O[0]) return self._basic._from_dict({O[0]: one, O[1]: (mone ** O[1].height())}, remove_zeros=False) else: mone = (- one) def basis_alt(r): return self._basic._from_dict({s: (mone ** ind) for (ind, s) in enumerate(self._root_mapping[r])}, remove_zeros=False) def lift_map(elt): t_dict = elt.t_dict() c_coeff = elt.c_coefficient() d_coeff = elt.d_coefficient() for i in t_dict: if (i % 2): t_dict[i] = self._basic.linear_combination(((basis_alt(r), c) for (r, c) in t_dict[i])) else: t_dict[i] = self._basic.linear_combination(((basis_map(r), c) for (r, c) in t_dict[i])) return self._ambient.element_class(self._ambient, t_dict, c_coeff, d_coeff) return self.module_morphism(function=lift_map, codomain=self._ambient) class Element(UntwistedAffineLieAlgebraElement): def _bracket_(self, y): "\n Return the Lie bracket ``[self, y]``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['D', 5, 2])\n sage: e0, e1, e2, e3, e4 = g.e()\n sage: f0, f1, f2, f3, f4 = g.f()\n sage: B = g.basis()\n sage: Q = g.classical().cartan_type().root_system().root_lattice()\n sage: h1, h2, h3, h4 = [B[ac, 0] for ac in Q.simple_coroots()]\n sage: e1._bracket_(e2)\n (-E[alpha[1] + alpha[2]])#t^0\n sage: e1._bracket_(e3)\n 0\n sage: e0._bracket_(e1)\n (-E[-alpha[2] - alpha[3] - alpha[4]])#t^1\n sage: e0._bracket_(e2)\n 0\n sage: f1._bracket_(f2)\n (E[-alpha[1] - alpha[2]])#t^0\n sage: f1._bracket_(f3)\n 0\n sage: f0._bracket_(f1)\n (E[alpha[2] + alpha[3] + alpha[4]])#t^-1\n sage: f0._bracket_(f2)\n 0\n sage: g[f0, e0]\n (2*h1 + 2*h2 + 2*h3 + h4)#t^0 + -32*c\n sage: g([f1, [e1, e2]])\n (E[alpha[2]])#t^0\n sage: g[h1, e0]\n (-E[-alpha[1] - alpha[2] - alpha[3] - alpha[4]])#t^1\n sage: g[h2, f0]\n 0\n " P = parent(self) ax = P.to_ambient(self) ay = P.to_ambient(y) return P.retract(ax.bracket(ay))
class TwistedAffineIndices(UniqueRepresentation, Set_generic): "\n The indices for the basis of a twisted affine Lie algebra.\n\n INPUT:\n\n - ``cartan_type`` -- the Cartan type of twisted affine type Lie algebra\n\n EXAMPLES::\n\n sage: from sage.algebras.lie_algebras.affine_lie_algebra import TwistedAffineIndices\n sage: I = TwistedAffineIndices(['A', 3, 2])\n sage: it = iter(I)\n sage: [next(it) for _ in range(20)]\n [(alpha[1], 0), (alpha[2], 0), (alpha[1] + alpha[2], 0),\n (2*alpha[1] + alpha[2], 0), (-alpha[1], 0), (-alpha[2], 0),\n (-alpha[1] - alpha[2], 0), (-2*alpha[1] - alpha[2], 0),\n (alphacheck[1], 0), (alphacheck[2], 0), (alpha[1], 1),\n (alpha[1] + alpha[2], 1), (-alpha[1], 1), (-alpha[1] - alpha[2], 1),\n (alphacheck[1], 1), (alpha[1], -1), (alpha[1] + alpha[2], -1),\n (-alpha[1], -1), (-alpha[1] - alpha[2], -1), (alphacheck[1], -1)]\n\n sage: I = TwistedAffineIndices(['A', 4, 2])\n sage: it = iter(I)\n sage: [next(it) for _ in range(20)]\n [(alpha[0], 0), (alpha[1], 0), (alpha[0] + alpha[1], 0),\n (2*alpha[0] + alpha[1], 0), (-alpha[0], 0), (-alpha[1], 0),\n (-alpha[0] - alpha[1], 0), (-2*alpha[0] - alpha[1], 0),\n (alphacheck[0], 0), (alphacheck[1], 0), (alpha[0], 1), (alpha[1], 1),\n (alpha[0] + alpha[1], 1), (2*alpha[0] + alpha[1], 1), (-alpha[0], 1),\n (-alpha[1], 1), (-alpha[0] - alpha[1], 1), (-2*alpha[0] - alpha[1], 1),\n (2*alpha[0], 1), (2*alpha[0] + 2*alpha[1], 1)]\n\n sage: I = TwistedAffineIndices(['A', 2, 2])\n sage: it = iter(I)\n sage: [next(it) for _ in range(10)]\n [(alpha[0], 0), (-alpha[0], 0), (alphacheck[0], 0), (alpha[0], 1),\n (-alpha[0], 1), (2*alpha[0], 1), (-2*alpha[0], 1),\n (alphacheck[0], 1), (alpha[0], -1), (-alpha[0], -1)]\n " @staticmethod def __classcall_private__(cls, cartan_type): "\n Normalize input to ensure a unique representation.\n\n sage: from sage.algebras.lie_algebras.affine_lie_algebra import TwistedAffineIndices\n sage: I1 = TwistedAffineIndices(CartanType(['C', 4, 1]).dual())\n sage: I2 = TwistedAffineIndices(['D', 5, 2])\n sage: I1 is I2\n True\n sage: I = TwistedAffineIndices(['C', 4, 1])\n Traceback (most recent call last):\n ...\n ValueError: the Cartan type must be a twisted affine type\n " cartan_type = CartanType(cartan_type) if ((not cartan_type.is_affine()) or cartan_type.is_untwisted_affine()): raise ValueError('the Cartan type must be a twisted affine type') return super().__classcall__(cls, cartan_type) def __init__(self, cartan_type): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.lie_algebras.affine_lie_algebra import TwistedAffineIndices\n sage: I = TwistedAffineIndices(['D', 4, 2])\n sage: TestSuite(I).run()\n " self._cartan_type = cartan_type if (cartan_type.type() == 'BC'): finite_ct = cartan_type.classical().dual() n = finite_ct.rank() Q = finite_ct.relabel({(n - i): i for i in range(n)}).root_system().root_lattice() self._roots = tuple(Q.roots()) self._ac = tuple(Q.simple_coroots()) CP = cartesian_product(([range(3)] * n)) if (cartan_type.rank() == 2): self._short_roots = (self._roots + tuple(((2 * r) for r in Q.roots()))) else: self._short_roots = (self._roots + tuple(((2 * r) for r in Q.short_roots()))) self._short_roots += self._ac facade = cartesian_product([self._short_roots, ZZ]) else: Q = cartan_type.classical().root_system().root_lattice() self._roots = tuple(Q.roots()) self._ac = tuple(Q.simple_coroots()) self._short_roots = tuple(Q.short_roots()) ac = Q.simple_coroots() self._short_roots += tuple([ac[i] for i in Q.index_set() if Q.simple_root(i).is_short_root()]) facade = cartesian_product([(self._roots + self._ac), ZZ]) from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets super().__init__(facade=facade, category=InfiniteEnumeratedSets()) def __contains__(self, x): "\n Return if ``x`` is contained in ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.lie_algebras.affine_lie_algebra import TwistedAffineIndices\n sage: I = TwistedAffineIndices(['D', 4, 2])\n sage: Q = RootSystem(['B', 3]).root_lattice()\n sage: all((r, 4) in I for r in Q.roots())\n True\n sage: all((r, 3) in I for r in Q.short_roots())\n True\n sage: all((r, 3) not in I for r in Q.long_roots())\n True\n sage: list(I.an_element()) in I # lists are not included\n False\n sage: (5, Q) in I\n False\n sage: (5, 5) in I\n False\n sage: (Q.simple_root(1), Q.simple_root(1)) in I\n False\n sage: (Q.simple_coroot(2), 1) in I\n False\n sage: (Q.simple_coroot(3), 1) in I\n True\n " if (x not in self._facade_for[0]): return False x = self._facade_for[0](x) return (((x[1] % 2) == 0) or (x[0] in self._short_roots)) def __iter__(self): "\n Iterate over ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.lie_algebras.affine_lie_algebra import TwistedAffineIndices\n sage: I = TwistedAffineIndices(['D', 3, 2])\n sage: it = iter(I)\n sage: [next(it) for _ in range(22)]\n [(alpha[1], 0), (alpha[2], 0), (alpha[1] + 2*alpha[2], 0), (alpha[1] + alpha[2], 0),\n (-alpha[1], 0), (-alpha[2], 0), (-alpha[1] - 2*alpha[2], 0), (-alpha[1] - alpha[2], 0),\n (alphacheck[1], 0), (alphacheck[2], 0), (alpha[2], 1), (alpha[1] + alpha[2], 1),\n (-alpha[2], 1), (-alpha[1] - alpha[2], 1), (alphacheck[2], 1), (alpha[2], -1),\n (alpha[1] + alpha[2], -1), (-alpha[2], -1), (-alpha[1] - alpha[2], -1),\n (alphacheck[2], -1), (alpha[1], 2), (alpha[2], 2)]\n " if (self._cartan_type.type() == 'BC'): finite_ct = self._cartan_type.classical().dual() n = finite_ct.rank() finite_ct = finite_ct.relabel({(n - i): i for i in range(n)}) else: finite_ct = self._cartan_type.classical() Q = finite_ct.root_system().root_lattice() P = self._facade_for[0] for i in ZZ: if (i % 2): for r in self._short_roots: (yield P((r, i))) else: for r in self._roots: (yield P((r, i))) for r in self._ac: (yield P((r, i)))
def bch_iterator(X=None, Y=None): "\n A generator function which returns successive terms of the\n Baker-Campbell-Hausdorff formula.\n\n INPUT:\n\n - ``X`` -- (optional) an element of a Lie algebra\n - ``Y`` -- (optional) an element of a Lie algebra\n\n The BCH formula is an expression for `\\log(\\exp(X)\\exp(Y))` as a sum of Lie\n brackets of ``X`` and ``Y`` with rational coefficients. In arbitrary Lie\n algebras, the infinite sum is only guaranteed to converge for ``X`` and\n ``Y`` close to zero.\n\n If the elements ``X`` and ``Y`` are not given, then the iterator will\n return successive terms of the abstract BCH formula, i.e., the BCH formula\n for the generators of the free Lie algebra on 2 generators.\n\n If the Lie algebra containing ``X`` and ``Y`` is not nilpotent, the\n iterator will output infinitely many elements. If the Lie algebra is\n nilpotent, the number of elements outputted is equal to the nilpotency step.\n\n EXAMPLES:\n\n The terms of the abstract BCH formula up to fifth order brackets::\n\n sage: from sage.algebras.lie_algebras.bch import bch_iterator\n sage: bch = bch_iterator()\n sage: next(bch)\n X + Y\n sage: next(bch)\n 1/2*[X, Y]\n sage: next(bch)\n 1/12*[X, [X, Y]] + 1/12*[[X, Y], Y]\n sage: next(bch)\n 1/24*[X, [[X, Y], Y]]\n sage: next(bch)\n -1/720*[X, [X, [X, [X, Y]]]] + 1/180*[X, [X, [[X, Y], Y]]]\n + 1/360*[[X, [X, Y]], [X, Y]] + 1/180*[X, [[[X, Y], Y], Y]]\n + 1/120*[[X, Y], [[X, Y], Y]] - 1/720*[[[[X, Y], Y], Y], Y]\n\n For nilpotent Lie algebras the BCH formula only has finitely many terms::\n\n sage: L = LieAlgebra(QQ, 2, step=3)\n sage: L.inject_variables()\n Defining X_1, X_2, X_12, X_112, X_122\n sage: [Z for Z in bch_iterator(X_1, X_2)]\n [X_1 + X_2, 1/2*X_12, 1/12*X_112 + 1/12*X_122]\n sage: [Z for Z in bch_iterator(X_1 + X_2, X_12)]\n [X_1 + X_2 + X_12, 1/2*X_112 - 1/2*X_122, 0]\n\n The elements ``X`` and ``Y`` don't need to be elements of the same Lie\n algebra if there is a coercion from one to the other::\n\n sage: L = LieAlgebra(QQ, 3, step=2)\n sage: L.inject_variables()\n Defining X_1, X_2, X_3, X_12, X_13, X_23\n sage: S = L.subalgebra(X_1, X_2)\n sage: bch1 = [Z for Z in bch_iterator(S(X_1), S(X_2))]; bch1\n [X_1 + X_2, 1/2*X_12]\n sage: bch1[0].parent() == S\n True\n sage: bch2 = [Z for Z in bch_iterator(S(X_1), X_3)]; bch2\n [X_1 + X_3, 1/2*X_13]\n sage: bch2[0].parent() == L\n True\n\n The BCH formula requires a coercion from the rationals::\n\n sage: L.<X,Y,Z> = LieAlgebra(ZZ, 2, step=2)\n sage: bch = bch_iterator(X, Y); next(bch)\n Traceback (most recent call last):\n ...\n TypeError: the BCH formula is not well defined since Integer Ring has no coercion from Rational Field\n\n TESTS:\n\n Compare to the BCH formula up to degree 5 given by wikipedia::\n\n sage: from sage.algebras.lie_algebras.bch import bch_iterator\n sage: bch = bch_iterator()\n sage: L.<X,Y> = LieAlgebra(QQ)\n sage: L = L.Lyndon()\n sage: computed_BCH = L.sum(next(bch) for k in range(5))\n sage: wikiBCH = X + Y + 1/2*L[X,Y] + 1/12*(L[X,[X,Y]] + L[Y,[Y,X]])\n sage: wikiBCH += -1/24*L[Y,[X,[X,Y]]]\n sage: wikiBCH += -1/720*(L[Y,[Y,[Y,[Y,X]]]] + L[X,[X,[X,[X,Y]]]])\n sage: wikiBCH += 1/360*(L[X,[Y,[Y,[Y,X]]]] + L[Y,[X,[X,[X,Y]]]])\n sage: wikiBCH += 1/120*(L[Y,[X,[Y,[X,Y]]]] + L[X,[Y,[X,[Y,X]]]])\n sage: computed_BCH == wikiBCH\n True\n\n ALGORITHM:\n\n The BCH formula `\\log(\\exp(X)\\exp(Y)) = \\sum_k Z_k` is computed starting\n from `Z_1 = X + Y`, by the recursion\n\n .. MATH::\n\n (m+1)Z_{m+1} = \\frac{1}{2}[X - Y, Z_m]\n + \\sum_{2\\leq 2p \\leq m}\\frac{B_{2p}}{(2p)!}\\sum_{k_1+\\cdots+k_{2p}=m}\n [Z_{k_1}, [\\cdots [Z_{k_{2p}}, X + Y]\\cdots],\n\n where `B_{2p}` are the Bernoulli numbers, see Lemma 2.15.3. in [Var1984]_.\n\n .. WARNING::\n\n The time needed to compute each successive term increases exponentially.\n For example on one machine iterating through `Z_{11},...,Z_{18}` for a\n free Lie algebra, computing each successive term took 4-5 times longer,\n going from 0.1s for `Z_{11}` to 21 minutes for `Z_{18}`.\n " if ((X is None) or (Y is None)): L = LieAlgebra(QQ, ['X', 'Y']).Lyndon() (X, Y) = L.lie_algebra_generators() else: (X, Y) = canonical_coercion(X, Y) L = X.parent() R = L.base_ring() if (not R.has_coerce_map_from(QQ)): raise TypeError(('the BCH formula is not well defined since %s has no coercion from %s' % (R, QQ))) xdif = (X - Y) Z = [0, (X + Y)] m = 1 (yield Z[1]) while True: m += 1 if ((L in LieAlgebras.Nilpotent) and (m > L.step())): return Zm = ((~ QQ((2 * m))) * xdif.bracket(Z[(- 1)])) for p in range(1, (((m - 1) // 2) + 1)): partitions = IntegerListsLex((m - 1), length=(2 * p), min_part=1) coeff = (bernoulli((2 * p)) / QQ((m * factorial((2 * p))))) for kvec in partitions: W = Z[1] for k in kvec: W = Z[k].bracket(W) Zm += (coeff * W) Z.append(Zm) (yield Zm)
class ClassicalMatrixLieAlgebra(MatrixLieAlgebraFromAssociative): "\n A classical Lie algebra represented using matrices.\n\n This means a classical Lie algebra given as a Lie\n algebra of matrices, with commutator as Lie bracket.\n\n INPUT:\n\n - ``R`` -- the base ring\n - ``ct`` -- the finite Cartan type\n\n EXAMPLES::\n\n sage: lie_algebras.ClassicalMatrix(QQ, ['A', 4])\n Special linear Lie algebra of rank 5 over Rational Field\n sage: lie_algebras.ClassicalMatrix(QQ, CartanType(['B',4]))\n Special orthogonal Lie algebra of rank 9 over Rational Field\n sage: lie_algebras.ClassicalMatrix(QQ, 'C4')\n Symplectic Lie algebra of rank 8 over Rational Field\n sage: lie_algebras.ClassicalMatrix(QQ, cartan_type=['D',4])\n Special orthogonal Lie algebra of rank 8 over Rational Field\n " @staticmethod def __classcall_private__(cls, R, cartan_type): "\n Return the correct parent based on input.\n\n EXAMPLES::\n\n sage: lie_algebras.ClassicalMatrix(QQ, ['A', 4])\n Special linear Lie algebra of rank 5 over Rational Field\n sage: lie_algebras.ClassicalMatrix(QQ, CartanType(['B',4]))\n Special orthogonal Lie algebra of rank 9 over Rational Field\n sage: lie_algebras.ClassicalMatrix(QQ, 'C4')\n Symplectic Lie algebra of rank 8 over Rational Field\n sage: lie_algebras.ClassicalMatrix(QQ, cartan_type=['D',4])\n Special orthogonal Lie algebra of rank 8 over Rational Field\n " if isinstance(cartan_type, (CartanMatrix, DynkinDiagram_class)): cartan_type = cartan_type.cartan_type() else: cartan_type = CartanType(cartan_type) if (not cartan_type.is_finite()): raise ValueError('only for finite types') if (cartan_type.type() == 'A'): return sl(R, (cartan_type.rank() + 1)) if (cartan_type.type() == 'B'): return so(R, ((2 * cartan_type.rank()) + 1)) if (cartan_type.type() == 'C'): return sp(R, (2 * cartan_type.rank())) if (cartan_type.type() == 'D'): return so(R, (2 * cartan_type.rank())) if (cartan_type.type() == 'E'): if (cartan_type.rank() == 6): return e6(R) if (cartan_type.rank() == 7): return e7(R) if (cartan_type.rank() == 8): return e8(R) if ((cartan_type.type() == 'F') and (cartan_type.rank() == 4)): return f4(R) if ((cartan_type.type() == 'G') and (cartan_type.rank() == 2)): return g2(R) raise ValueError('invalid Cartan type') def __init__(self, R, ct, e, f, h, sparse=True): "\n Initialize ``self``.\n\n INPUT:\n\n - ``R`` -- the base ring\n - ``ct`` -- the Cartan type\n - ``e`` -- the `e` generators\n - ``f`` -- the `f` generators\n - ``h`` -- the `h` generators\n - ``sparse`` -- boolean (default: ``True``); use the sparse vectors\n for the basis computation\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 3, representation='matrix')\n sage: TestSuite(g).run()\n\n TESTS:\n\n Check that :trac:`23266` is fixed::\n\n sage: sl2 = lie_algebras.sl(QQ, 2, 'matrix')\n sage: isinstance(sl2.indices(), FiniteEnumeratedSet)\n True\n\n Check that elements are hashable (see :trac:`28961`)::\n\n sage: sl2 = lie_algebras.sl(QQ, 2, 'matrix')\n sage: e,f,h = list(sl2.basis())\n sage: len(set([e, e+f]))\n 2\n " n = len(e) I = ct.index_set() names = [('e%s' % i) for i in I] names += [('f%s' % i) for i in I] names += [('h%s' % i) for i in I] category = LieAlgebras(R).FiniteDimensional().WithBasis() from sage.sets.finite_enumerated_set import FiniteEnumeratedSet index_set = FiniteEnumeratedSet(names) MatrixLieAlgebraFromAssociative.__init__(self, e[0].parent(), gens=tuple(((e + f) + h)), names=tuple(names), index_set=index_set, category=category) self._cartan_type = ct self._sparse = sparse gens = tuple(self.gens()) self._e = Family({i: gens[c] for (c, i) in enumerate(I)}) self._f = Family({i: gens[(n + c)] for (c, i) in enumerate(I)}) self._h = Family({i: gens[((2 * n) + c)] for (c, i) in enumerate(I)}) def e(self, i): "\n Return the generator `e_i`.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 3, representation='matrix')\n sage: g.e(2)\n [0 0 0]\n [0 0 1]\n [0 0 0]\n " return self._e[i] def f(self, i): "\n Return the generator `f_i`.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 3, representation='matrix')\n sage: g.f(2)\n [0 0 0]\n [0 0 0]\n [0 1 0]\n " return self._f[i] def h(self, i): "\n Return the generator `h_i`.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 3, representation='matrix')\n sage: g.h(2)\n [ 0 0 0]\n [ 0 1 0]\n [ 0 0 -1]\n " return self._h[i] @cached_method def index_set(self): "\n Return the index_set of ``self``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 3, representation='matrix')\n sage: g.index_set()\n (1, 2)\n " return self._cartan_type.index_set() def cartan_type(self): "\n Return the Cartan type of ``self``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 3, representation='matrix')\n sage: g.cartan_type()\n ['A', 2]\n " return self._cartan_type def epsilon(self, i, h): "\n Return the action of the functional\n `\\varepsilon_i \\colon \\mathfrak{h} \\to R`, where `R` is the base\n ring of ``self``, on the element ``h``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 3, representation='matrix')\n sage: g.epsilon(1, g.h(1))\n 1\n sage: g.epsilon(2, g.h(1))\n -1\n sage: g.epsilon(3, g.h(1))\n 0\n " return h[((i - 1), (i - 1))] @abstract_method(optional=True) def simple_root(self, i, h): "\n Return the action of the simple root\n `\\alpha_i \\colon \\mathfrak{h} \\to R`, where `R` is the base\n ring of ``self``, on the element ``h``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 3, representation='matrix')\n sage: g.simple_root(1, g.h(1))\n 2\n sage: g.simple_root(1, g.h(2))\n -1\n " def highest_root_basis_elt(self, pos=True): "\n Return the basis element corresponding to the highest root `\\theta`.\n If ``pos`` is ``True``, then returns `e_{\\theta}`, otherwise it\n returns `f_{\\theta}`.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 3, representation='matrix')\n sage: g.highest_root_basis_elt()\n [0 0 1]\n [0 0 0]\n [0 0 0]\n " RL = self._cartan_type.root_system().root_lattice() coroots = RL.simple_coroots() theta = RL.highest_root() (i, w) = theta.to_simple_root(True) r = RL.simple_root(i) if pos: gens = self._e else: gens = self._f cur = gens[i] for j in reversed(w): for _ in range((- r.scalar(coroots[j]))): cur = self.bracket(gens[j], cur) r = r.reflection(coroots[j], True) return cur @cached_method def basis(self): "\n Return a basis of ``self``.\n\n EXAMPLES::\n\n sage: M = LieAlgebra(ZZ, cartan_type=['A',2], representation='matrix')\n sage: list(M.basis())\n [\n [ 1 0 0] [0 1 0] [0 0 1] [0 0 0] [ 0 0 0] [0 0 0] [0 0 0]\n [ 0 0 0] [0 0 0] [0 0 0] [1 0 0] [ 0 1 0] [0 0 1] [0 0 0]\n [ 0 0 -1], [0 0 0], [0 0 0], [0 0 0], [ 0 0 -1], [0 0 0], [1 0 0],\n <BLANKLINE>\n [0 0 0]\n [0 0 0]\n [0 1 0]\n ]\n\n Sparse version::\n\n sage: e6 = LieAlgebra(QQ, cartan_type=['E',6], representation='matrix')\n sage: len(e6.basis()) # long time\n 78\n " from sage.matrix.constructor import matrix R = self.base_ring() basis_pivots = set() gens = list(self.lie_algebra_generators()) added = gens m = self._assoc.ncols() adim = self._assoc.dimension() cur_mat = matrix(R, 0, adim, sparse=self._sparse) def set_row(mat, row, val): for (k, v) in val.dict().items(): (a, b) = k mat[(row, ((a * m) + b))] = v def build_assoc(row): ret = {} for (i, v) in row.dict().items(): ret[((i // m), (i % m))] = v return self._assoc(ret) while added: if self._sparse: mat = {} count = 0 for x in added: set_row(mat, count, x.value) count += 1 for y in gens: ret = x.bracket(y) if ret: set_row(mat, count, ret.value) count += 1 mat = matrix(R, count, adim, mat, sparse=True) else: mat = [] for x in added: mat.append(x.value.list()) for y in gens: ret = x.bracket(y) if ret: mat.append(ret.value.list()) mat = matrix(R, mat) cur_mat = cur_mat.stack(mat) cur_mat.echelonize() pivots = cur_mat.pivots() added = [] if (len(pivots) != len(basis_pivots)): for (i, p) in enumerate(pivots): if (p in basis_pivots): continue basis_pivots.add(p) if self._sparse: added.append(self.element_class(self, build_assoc(cur_mat[i]))) else: added.append(self.element_class(self, self._assoc(cur_mat[i].list()))) cur_mat = cur_mat.submatrix(nrows=len(pivots)) if self._sparse: basis = [self.element_class(self, build_assoc(cur_mat[i])) for i in range(cur_mat.rank())] else: basis = [self.element_class(self, self._assoc(cur_mat[i].list())) for i in range(cur_mat.rank())] return Family(basis) def affine(self, kac_moody=True): "\n Return the affine (Kac-Moody) Lie algebra of ``self``.\n\n EXAMPLES::\n\n sage: so5 = lie_algebras.so(QQ, 5, 'matrix')\n sage: so5\n Special orthogonal Lie algebra of rank 5 over Rational Field\n sage: so5.affine()\n Affine Special orthogonal Kac-Moody algebra of rank 5 over Rational Field\n sage: so5.affine(False)\n Affine Special orthogonal Lie algebra of rank 5 over Rational Field\n " from sage.algebras.lie_algebras.affine_lie_algebra import AffineLieAlgebra return AffineLieAlgebra(self, kac_moody=kac_moody)
class gl(MatrixLieAlgebraFromAssociative): '\n The matrix Lie algebra `\\mathfrak{gl}_n`.\n\n The Lie algebra `\\mathfrak{gl}_n` which consists of all `n \\times n`\n matrices.\n\n INPUT:\n\n - ``R`` -- the base ring\n - ``n`` -- the size of the matrix\n ' def __init__(self, R, n): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.gl(QQ, 4)\n sage: TestSuite(g).run()\n\n TESTS:\n\n Check that :trac:`23266` is fixed::\n\n sage: gl2 = lie_algebras.gl(QQ, 2)\n sage: isinstance(gl2.basis().keys(), FiniteEnumeratedSet)\n True\n sage: Ugl2 = gl2.pbw_basis()\n sage: prod(Ugl2.gens())\n PBW['E_0_0']*PBW['E_0_1']*PBW['E_1_0']*PBW['E_1_1']\n " MS = MatrixSpace(R, n, sparse=True) one = R.one() names = [] gens = [] for i in range(n): for j in range(n): names.append('E_{0}_{1}'.format(i, j)) mat = MS({(i, j): one}) mat.set_immutable() gens.append(mat) self._n = n category = LieAlgebras(R).FiniteDimensional().WithBasis() from sage.sets.finite_enumerated_set import FiniteEnumeratedSet index_set = FiniteEnumeratedSet(names) MatrixLieAlgebraFromAssociative.__init__(self, MS, tuple(gens), names=tuple(names), index_set=index_set, category=category) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: lie_algebras.gl(QQ, 4)\n General linear Lie algebra of rank 4 over Rational Field\n ' return 'General linear Lie algebra of rank {} over {}'.format(self._n, self.base_ring()) def killing_form(self, x, y): '\n Return the Killing form on ``x`` and ``y``.\n\n The Killing form on `\\mathfrak{gl}_n` is:\n\n .. MATH::\n\n \\langle x \\mid y \\rangle = 2n \\mathrm{tr}(xy) - 2 \\mathrm{tr}(x)\n \\mathrm{tr}(y).\n\n EXAMPLES::\n\n sage: g = lie_algebras.gl(QQ, 4)\n sage: x = g.an_element()\n sage: y = g.gens()[1]\n sage: g.killing_form(x, y)\n 8\n ' return (((2 * self._n) * (x.value * y.value).trace()) - ((2 * x.value.trace()) * y.value.trace())) @cached_method def basis(self): '\n Return the basis of ``self``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.gl(QQ, 2)\n sage: tuple(g.basis())\n (\n [1 0] [0 1] [0 0] [0 0]\n [0 0], [0 0], [1 0], [0 1]\n )\n ' G = self.gens() return Family(self._indices, (lambda i: G[self._indices.index(i)])) def monomial(self, i): "\n Return the basis element indexed by ``i``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: gl4 = lie_algebras.gl(QQ, 4)\n sage: gl4.monomial('E_2_1')\n [0 0 0 0]\n [0 0 0 0]\n [0 1 0 0]\n [0 0 0 0]\n sage: gl4.monomial((2,1))\n [0 0 0 0]\n [0 0 0 0]\n [0 1 0 0]\n [0 0 0 0]\n " if isinstance(i, tuple): return self.basis()['E_{}_{}'.format(*i)] return self.basis()[i] class Element(MatrixLieAlgebraFromAssociative.Element): def monomial_coefficients(self, copy=True): "\n Return the monomial coefficients of ``self``.\n\n EXAMPLES::\n\n sage: gl4 = lie_algebras.gl(QQ, 4)\n sage: x = gl4.monomial('E_2_1') + 3*gl4.monomial('E_0_3')\n sage: x.monomial_coefficients()\n {'E_0_3': 3, 'E_2_1': 1}\n " d = {} for k in self.value.nonzero_positions(): d['E_{}_{}'.format(*k)] = self.value[k] return d
class sl(ClassicalMatrixLieAlgebra): '\n The matrix Lie algebra `\\mathfrak{sl}_n`.\n\n The Lie algebra `\\mathfrak{sl}_n`, which consists of all `n \\times n`\n matrices with trace 0. This is the Lie algebra of type `A_{n-1}`.\n ' def __init__(self, R, n): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 5, representation='matrix')\n sage: TestSuite(g).run()\n " MS = MatrixSpace(R, n, sparse=True) one = R.one() e = [MS({(i, (i + 1)): one}) for i in range((n - 1))] f = [MS({((i + 1), i): one}) for i in range((n - 1))] h = [MS({(i, i): one, ((i + 1), (i + 1)): (- one)}) for i in range((n - 1))] self._n = n ClassicalMatrixLieAlgebra.__init__(self, R, CartanType(['A', (n - 1)]), e, f, h) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: lie_algebras.sl(QQ, 5, representation='matrix')\n Special linear Lie algebra of rank 5 over Rational Field\n " return 'Special linear Lie algebra of rank {} over {}'.format(self._n, self.base_ring()) def killing_form(self, x, y): "\n Return the Killing form on ``x`` and ``y``.\n\n The Killing form on `\\mathfrak{sl}_n` is:\n\n .. MATH::\n\n \\langle x \\mid y \\rangle = 2n \\mathrm{tr}(xy).\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 5, representation='matrix')\n sage: x = g.an_element()\n sage: y = g.lie_algebra_generators()['e1']\n sage: g.killing_form(x, y)\n 10\n " return ((2 * self._n) * (x.value * y.value).trace()) def simple_root(self, i, h): "\n Return the action of the simple root\n `\\alpha_i \\colon \\mathfrak{h} \\to R`, where `R` is the base\n ring of ``self``, on the element ``j``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sl(QQ, 5, representation='matrix')\n sage: matrix([[g.simple_root(i, g.h(j)) for i in g.index_set()] for j in g.index_set()])\n [ 2 -1 0 0]\n [-1 2 -1 0]\n [ 0 -1 2 -1]\n [ 0 0 -1 2]\n " i = self.index_set().index(i) return (h[(i, i)] - h[((i + 1), (i + 1))])
class so(ClassicalMatrixLieAlgebra): '\n The matrix Lie algebra `\\mathfrak{so}_n`.\n\n The Lie algebra `\\mathfrak{so}_n`, which is isomorphic to the\n Lie algebra of all anti-symmetric `n \\times n` matrices.\n The implementation here uses a different bilinear form and follows\n the description in Chapter 8 of [HK2002]_. More precisely, this\n is the set of matrices:\n\n .. MATH::\n\n \\begin{pmatrix}\n A & B \\\\\n C & D\n \\end{pmatrix}\n\n such that `A^t = -D`, `B^t = -B`, `C^t = -C` for `n` even and\n\n .. MATH::\n\n \\begin{pmatrix}\n A & B & a \\\\\n C & D & b \\\\\n c & d & 0\n \\end{pmatrix}\n\n such that `A^t = -D`, `B^t = -B`, `C^t = -C`, `a^t = -d`,\n and `b^t = -c` for `n` odd.\n\n This is the Lie algebra of type `B_{(n-1)/2}` or `D_{n/2}` if `n`\n is odd or even respectively.\n ' def __init__(self, R, n): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.so(QQ, 8, representation='matrix')\n sage: TestSuite(g).run()\n sage: g = lie_algebras.so(QQ, 9, representation='matrix')\n sage: TestSuite(g).run()\n " MS = MatrixSpace(R, n) one = R.one() self._n = n if ((n % 2) == 0): m = ((n // 2) - 1) n -= 1 e = [MS({((m - 1), n): one, (m, (n - 1)): (- one)})] f = [MS({(n, (m - 1)): one, ((n - 1), m): (- one)})] h = [MS({((m - 1), (m - 1)): one, (m, m): one, ((n - 1), (n - 1)): (- one), (n, n): (- one)})] m += 1 ct = CartanType(['D', m]) else: m = (((n - 1) // 2) - 1) n -= 1 e = [MS({(m, n): 2, (n, (n - 1)): (- 2)})] f = [MS({(n, m): one, ((n - 1), n): (- one)})] h = [MS({(m, m): 2, ((n - 1), (n - 1)): (- 2)})] m += 1 ct = CartanType(['B', m]) e = ([MS({(i, (i + 1)): one, (((m + i) + 1), (m + i)): (- one)}) for i in range((m - 1))] + e) f = ([MS({((i + 1), i): one, ((m + i), ((m + i) + 1)): (- one)}) for i in range((m - 1))] + f) h = ([MS({(i, i): one, ((i + 1), (i + 1)): (- one), ((m + i), (m + i)): (- one), (((m + i) + 1), ((m + i) + 1)): one}) for i in range((m - 1))] + h) ClassicalMatrixLieAlgebra.__init__(self, R, ct, e, f, h) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: LieAlgebra(QQ, cartan_type=['B', 4], representation='matrix')\n Special orthogonal Lie algebra of rank 9 over Rational Field\n sage: LieAlgebra(QQ, cartan_type=['D', 4], representation='matrix')\n Special orthogonal Lie algebra of rank 8 over Rational Field\n " return 'Special orthogonal Lie algebra of rank {} over {}'.format(self._n, self.base_ring()) def killing_form(self, x, y): "\n Return the Killing form on ``x`` and ``y``.\n\n The Killing form on `\\mathfrak{so}_n` is:\n\n .. MATH::\n\n \\langle x \\mid y \\rangle = (n - 2) \\mathrm{tr}(xy).\n\n EXAMPLES::\n\n sage: g = lie_algebras.so(QQ, 8, representation='matrix')\n sage: x = g.an_element()\n sage: y = g.lie_algebra_generators()['e1']\n sage: g.killing_form(x, y)\n 12\n sage: g = lie_algebras.so(QQ, 9, representation='matrix')\n sage: x = g.an_element()\n sage: y = g.lie_algebra_generators()['e1']\n sage: g.killing_form(x, y)\n 14\n " return ((self._n - 2) * (x.value * y.value).trace()) def simple_root(self, i, h): "\n Return the action of the simple root\n `\\alpha_i \\colon \\mathfrak{h} \\to R`, where `R` is the base\n ring of ``self``, on the element ``j``.\n\n EXAMPLES:\n\n The even or type `D` case::\n\n sage: g = lie_algebras.so(QQ, 8, representation='matrix')\n sage: matrix([[g.simple_root(i, g.h(j)) for i in g.index_set()] for j in g.index_set()])\n [ 2 -1 0 0]\n [-1 2 -1 -1]\n [ 0 -1 2 0]\n [ 0 -1 0 2]\n\n The odd or type `B` case::\n\n sage: g = lie_algebras.so(QQ, 9, representation='matrix')\n sage: matrix([[g.simple_root(i, g.h(j)) for i in g.index_set()] for j in g.index_set()])\n [ 2 -1 0 0]\n [-1 2 -1 0]\n [ 0 -1 2 -1]\n [ 0 0 -2 2]\n " i = self.index_set().index(i) if (i == (len(self.index_set()) - 1)): if ((self._n % 2) == 0): return (h[((i - 1), (i - 1))] + h[(i, i)]) return h[(i, i)] return (h[(i, i)] - h[((i + 1), (i + 1))])
class sp(ClassicalMatrixLieAlgebra): '\n The matrix Lie algebra `\\mathfrak{sp}_n`.\n\n The Lie algebra `\\mathfrak{sp}_{2k}`, which consists of all\n `2k \\times 2k` matrices `X` that satisfy the equation:\n\n .. MATH::\n\n X^T M - M X = 0\n\n where\n\n .. MATH::\n\n M = \\begin{pmatrix}\n 0 & I_k \\\\\n -I_k & 0\n \\end{pmatrix}.\n\n This is the Lie algebra of type `C_k`.\n ' def __init__(self, R, n): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sp(QQ, 8, representation='matrix')\n sage: TestSuite(g).run()\n " MS = MatrixSpace(R, n, sparse=True) one = R.one() self._n = n n = (n // 2) e = [MS({(i, (i + 1)): one, (((n + i) + 1), (n + i)): (- one)}) for i in range((n - 1))] e.append(MS({((n - 1), ((2 * n) - 1)): one})) f = [MS({((i + 1), i): one, ((n + i), ((n + i) + 1)): (- one)}) for i in range((n - 1))] f.append(MS({(((2 * n) - 1), (n - 1)): one})) h = [MS({(i, i): one, ((i + 1), (i + 1)): (- one), ((n + i), (n + i)): (- one), (((n + i) + 1), ((n + i) + 1)): one}) for i in range((n - 1))] h.append(MS({((n - 1), (n - 1)): one, (((2 * n) - 1), ((2 * n) - 1)): (- one)})) ClassicalMatrixLieAlgebra.__init__(self, R, CartanType(['C', n]), e, f, h) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: lie_algebras.sp(QQ, 8, representation='matrix')\n Symplectic Lie algebra of rank 8 over Rational Field\n " return 'Symplectic Lie algebra of rank {} over {}'.format(self._n, self.base_ring()) def killing_form(self, x, y): "\n Return the Killing form on ``x`` and ``y``.\n\n The Killing form on `\\mathfrak{sp}_n` is:\n\n .. MATH::\n\n \\langle x \\mid y \\rangle = (2n + 2) \\mathrm{tr}(xy).\n\n EXAMPLES::\n\n sage: g = lie_algebras.sp(QQ, 8, representation='matrix')\n sage: x = g.an_element()\n sage: y = g.lie_algebra_generators()['e1']\n sage: g.killing_form(x, y)\n 36\n " return (((2 * self._n) + 2) * (x.value * y.value).trace()) def simple_root(self, i, h): "\n Return the action of the simple root\n `\\alpha_i \\colon \\mathfrak{h} \\to R`, where `R` is the base\n ring of ``self``, on the element ``j``.\n\n EXAMPLES::\n\n sage: g = lie_algebras.sp(QQ, 8, representation='matrix')\n sage: matrix([[g.simple_root(i, g.h(j)) for i in g.index_set()] for j in g.index_set()])\n [ 2 -1 0 0]\n [-1 2 -1 0]\n [ 0 -1 2 -2]\n [ 0 0 -1 2]\n " i = self.index_set().index(i) if (i == ((self._n / 2) - 1)): return (2 * h[(i, i)]) return (h[(i, i)] - h[((i + 1), (i + 1))])
class ExceptionalMatrixLieAlgebra(ClassicalMatrixLieAlgebra): '\n A matrix Lie algebra of exceptional type.\n ' def __init__(self, R, cartan_type, e, f, h=None, sparse=False): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['E',6], representation='matrix')\n sage: all(g.h(i) == g.e(i).bracket(g.f(i)) for i in range(1,7))\n True\n " if (h is None): h = [((e[i] * f[i]) - (f[i] * e[i])) for i in range(len(e))] ClassicalMatrixLieAlgebra.__init__(self, R, cartan_type, e, f, h, sparse=sparse) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: LieAlgebra(QQ, cartan_type=['G',2], representation='matrix')\n Simple matrix Lie algebra of type ['G', 2] over Rational Field\n " return 'Simple matrix Lie algebra of type {} over {}'.format(self.cartan_type(), self.base_ring())
class e6(ExceptionalMatrixLieAlgebra): '\n The matrix Lie algebra `\\mathfrak{e}_6`.\n\n The simple Lie algebra `\\mathfrak{e}_6` of type `E_6`. The matrix\n representation is given following [HRT2000]_.\n ' def __init__(self, R): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['E',6], representation='matrix')\n sage: TestSuite(g).run() # long time\n " MS = MatrixSpace(R, 27, sparse=True) one = R.one() coords = [[(0, 1), (10, 12), (13, 15), (16, 17), (18, 19), (20, 21)], [(3, 4), (5, 6), (7, 9), (18, 20), (19, 21), (22, 23)], [(1, 2), (8, 10), (11, 13), (14, 16), (19, 22), (21, 23)], [(2, 3), (6, 8), (9, 11), (16, 18), (17, 19), (23, 24)], [(3, 5), (4, 6), (11, 14), (13, 16), (15, 17), (24, 25)], [(5, 7), (6, 9), (8, 11), (10, 13), (12, 15), (25, 26)]] e = [MS({c: one for c in coord}) for coord in coords] f = [MS({(c[1], c[0]): one for c in coord}) for coord in coords] ExceptionalMatrixLieAlgebra.__init__(self, R, CartanType(['E', 6]), e, f)
class e7(ExceptionalMatrixLieAlgebra): '\n The matrix Lie algebra `\\mathfrak{e}_7`.\n\n The simple Lie algebra `\\mathfrak{e}_7` of type `E_7`. The matrix\n representation is given following [HRT2000]_.\n ' def __init__(self, R): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['E', 7], representation='matrix')\n sage: g\n Simple matrix Lie algebra of type ['E', 7] over Rational Field\n\n sage: len(g.basis()) # long time\n 133\n sage: TestSuite(g).run() # long time\n " MS = MatrixSpace(R, 56, sparse=True) one = R.one() coords = [[(6, 7), (8, 9), (10, 11), (12, 14), (15, 17), (18, 21), (34, 37), (38, 40), (41, 43), (44, 45), (46, 47), (48, 49)], [(4, 5), (6, 8), (7, 9), (19, 22), (23, 25), (26, 28), (27, 29), (30, 32), (33, 36), (46, 48), (47, 49), (50, 51)], [(4, 6), (5, 8), (11, 13), (14, 16), (17, 20), (21, 24), (31, 34), (35, 38), (39, 41), (42, 44), (47, 50), (49, 51)], [(3, 4), (8, 10), (9, 11), (16, 19), (20, 23), (24, 27), (28, 31), (32, 35), (36, 39), (44, 46), (45, 47), (51, 52)], [(2, 3), (10, 12), (11, 14), (13, 16), (23, 26), (25, 28), (27, 30), (29, 32), (39, 42), (41, 44), (43, 45), (52, 53)], [(1, 2), (12, 15), (14, 17), (16, 20), (19, 23), (22, 25), (30, 33), (32, 36), (35, 39), (38, 41), (40, 43), (53, 54)], [(0, 1), (15, 18), (17, 21), (20, 24), (23, 27), (25, 29), (26, 30), (28, 32), (31, 35), (34, 38), (37, 40), (54, 55)]] e = [MS({c: one for c in coord}) for coord in coords] f = [MS({(c[1], c[0]): one for c in coord}) for coord in coords] ExceptionalMatrixLieAlgebra.__init__(self, R, CartanType(['E', 7]), e, f)
class e8(ExceptionalMatrixLieAlgebra): '\n The matrix Lie algebra `\\mathfrak{e}_8`.\n\n The simple Lie algebra `\\mathfrak{e}_8` of type `E_8` built from the\n adjoint representation in the Chevalley basis.\n ' def __init__(self, R): '\n Initialize ``self``.\n\n TESTS::\n\n sage: g = LieAlgebra(QQ, cartan_type=[\'E\', 8], representation=\'matrix\') # long time\n sage: g # long time\n Simple matrix Lie algebra of type [\'E\', 8] over Rational Field\n\n We skip the not implemented methods test as it takes too much time::\n\n sage: TestSuite(g).run(skip="_test_not_implemented_methods") # long time\n ' ct = CartanType(['E', 8]) g = LieAlgebraChevalleyBasis(R, ct) e = [ge.adjoint_matrix(sparse=True) for ge in g.e()] f = [gf.adjoint_matrix(sparse=True) for gf in g.f()] ExceptionalMatrixLieAlgebra.__init__(self, R, ct, e, f) @cached_method def basis(self): "\n Return a basis of ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['E', 8], representation='matrix') # long time\n sage: len(g.basis()) # long time\n 248\n " g = LieAlgebraChevalleyBasis(self.base_ring(), self.cartan_type()) return Family([ge.adjoint_matrix(sparse=True) for ge in g.basis()])
class f4(ExceptionalMatrixLieAlgebra): '\n The matrix Lie algebra `\\mathfrak{f}_4`.\n\n The simple Lie algebra `\\mathfrak{f}_f` of type `F_4`. The matrix\n representation is given following [HRT2000]_ but indexed in the\n reversed order (i.e., interchange 1 with 4 and 2 with 3).\n ' def __init__(self, R): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['F',4], representation='matrix')\n sage: TestSuite(g).run() # long time\n " MS = MatrixSpace(R, 26, sparse=True) one = R.one() coords = [[(0, 1), (5, 7), (6, 9), (8, 11), (10, 12), (10, 13), (12, 14), (15, 16), (17, 18), (19, 20), (24, 25)], [(1, 2), (3, 5), (4, 6), (8, 10), (11, 12), (11, 13), (13, 15), (14, 16), (18, 21), (20, 22), (23, 24)], [(2, 3), (6, 8), (9, 11), (15, 17), (16, 18), (22, 23)], [(3, 4), (5, 6), (7, 9), (17, 19), (18, 20), (21, 22)]] e = [MS({c: one for c in coord}) for coord in coords] e[0][(10, 12)] = (2 * one) e[1][(11, 13)] = (2 * one) coords = [[(1, 0), (7, 5), (9, 6), (11, 8), (12, 10), (14, 12), (14, 13), (16, 15), (18, 17), (20, 19), (25, 24)], [(2, 1), (5, 3), (6, 4), (10, 8), (13, 11), (15, 12), (15, 13), (16, 14), (21, 18), (22, 20), (24, 23)], [(3, 2), (8, 6), (11, 9), (17, 15), (18, 16), (23, 22)], [(4, 3), (6, 5), (9, 7), (19, 17), (20, 18), (22, 21)]] f = [MS({c: one for c in coord}) for coord in coords] f[0][(14, 12)] = (2 * one) f[1][(15, 13)] = (2 * one) e.reverse() f.reverse() ExceptionalMatrixLieAlgebra.__init__(self, R, CartanType(['F', 4]), e, f)
class g2(ExceptionalMatrixLieAlgebra): '\n The matrix Lie algebra `\\mathfrak{g}_2`.\n\n The simple Lie algebra `\\mathfrak{g}_2` of type `G_2`. The matrix\n representation is given following [HRT2000]_.\n ' def __init__(self, R): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['G',2], representation='matrix')\n sage: TestSuite(g).run()\n " MS = MatrixSpace(R, 7, sparse=True) one = R.one() e = [MS({(0, 1): one, (2, 3): (2 * one), (3, 4): one, (5, 6): one}), MS({(1, 2): one, (4, 5): one})] f = [MS({(1, 0): one, (3, 2): one, (4, 3): (2 * one), (6, 5): one}), MS({(2, 1): one, (5, 4): one})] h = [MS({(0, 0): one, (1, 1): (- one), (2, 2): (2 * one), (4, 4): ((- 2) * one), (5, 5): one, (6, 6): (- one)}), MS({(1, 1): one, (2, 2): (- one), (4, 4): one, (5, 5): (- one)})] ExceptionalMatrixLieAlgebra.__init__(self, R, CartanType(['G', 2]), e, f, h)
class MatrixCompactRealForm(FinitelyGeneratedLieAlgebra): '\n The compact real form of a matrix Lie algebra.\n\n Let `L` be a classical (i.e., type `ABCD`) Lie algebra over `\\RR`\n given as matrices that is invariant under matrix transpose (i.e.,\n `X^T \\in L` for all `X \\in L`). Then we can perform the\n *Cartan decomposition* of `L` by `L = K \\oplus S`, where `K`\n (resp. `S`) is the set of skew-symmetric (resp. symmetric) matrices\n in `L`. Then the Lie algebra `U = K \\oplus i S` is an `\\RR`-subspace\n of the complexification of `L` that is closed under commutators and\n has skew-hermitian matrices. Hence, the Killing form is negative\n definitive (i.e., `U` is a compact Lie algebra), and thus `U` is\n the complex real form of the complexification of `L`.\n\n EXAMPLES::\n\n sage: U = LieAlgebra(QQ, cartan_type=[\'A\',1], representation="compact real")\n sage: list(U.basis())\n [\n [ 0 1] [ i 0] [0 i]\n [-1 0], [ 0 -i], [i 0]\n ]\n sage: U.killing_form_matrix()\n [-8 0 0]\n [ 0 -8 0]\n [ 0 0 -8]\n\n Computations are only (currently) possible if this is defined\n over a field::\n\n sage: U = LieAlgebra(ZZ, cartan_type=[\'A\',1], representation="compact real")\n sage: list(U.basis())\n Traceback (most recent call last):\n ...\n TypeError: no conversion of this rational to integer\n ' def __init__(self, R, cartan_type): '\n Initialize ``self``.\n\n TESTS::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'A\',2], representation="compact real")\n sage: TestSuite(L).run()\n ' if (not cartan_type.is_finite()): raise ValueError('the Cartan type must be finite type') self._classical = ClassicalMatrixLieAlgebra(R, cartan_type) self._MS = self._classical._assoc dim = self._classical.dimension() from sage.sets.finite_enumerated_set import FiniteEnumeratedSet index_set = FiniteEnumeratedSet(range(dim)) names = tuple([('CR%s' % s) for s in range(dim)]) category = LieAlgebras(R).FiniteDimensional().WithBasis() FinitelyGeneratedLieAlgebra.__init__(self, R, names=names, index_set=index_set, category=category) @cached_method def basis(self): '\n Compute a basis of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'B\',2], representation="compact real")\n sage: list(L.basis())\n [\n [ 0 1 0 0 0] [ 0 0 0 1 0] [ 0 0 0 0 1] [ 0 0 0 0 0]\n [-1 0 0 0 0] [ 0 0 -1 0 0] [ 0 0 0 0 0] [ 0 0 0 0 1]\n [ 0 0 0 1 0] [ 0 1 0 0 0] [ 0 0 0 0 1] [ 0 0 0 0 0]\n [ 0 0 -1 0 0] [-1 0 0 0 0] [ 0 0 0 0 0] [ 0 0 0 0 1]\n [ 0 0 0 0 0], [ 0 0 0 0 0], [-1 0 -1 0 0], [ 0 -1 0 -1 0],\n <BLANKLINE>\n [ i 0 0 0 0] [ 0 i 0 0 0] [ 0 0 0 i 0] [ 0 0 0 0 i]\n [ 0 0 0 0 0] [ i 0 0 0 0] [ 0 0 -i 0 0] [ 0 0 0 0 0]\n [ 0 0 -i 0 0] [ 0 0 0 -i 0] [ 0 -i 0 0 0] [ 0 0 0 0 -i]\n [ 0 0 0 0 0] [ 0 0 -i 0 0] [ i 0 0 0 0] [ 0 0 0 0 0]\n [ 0 0 0 0 0], [ 0 0 0 0 0], [ 0 0 0 0 0], [ i 0 -i 0 0],\n <BLANKLINE>\n [ 0 0 0 0 0] [ 0 0 0 0 0]\n [ 0 i 0 0 0] [ 0 0 0 0 i]\n [ 0 0 0 0 0] [ 0 0 0 0 0]\n [ 0 0 0 -i 0] [ 0 0 0 0 -i]\n [ 0 0 0 0 0], [ 0 i 0 -i 0]\n ]\n ' from sage.matrix.constructor import matrix zero = self._MS.zero() basis = self._classical.basis() R = self.base_ring() mat = matrix(R, [((b.value - b.value.transpose()) / 2).list() for b in basis], sparse=self._MS.is_sparse()) mat.echelonize() ret = [self.element_class(self, self._MS(mat[i].list()), zero) for i in range(mat.rank())] mat = matrix(R, [((b.value + b.value.transpose()) / 2).list() for b in basis], sparse=self._MS.is_sparse()) mat.echelonize() ret += [self.element_class(self, zero, self._MS(mat[i].list())) for i in range(mat.rank())] return Family(ret) @cached_method def zero(self): '\n Return the element `0`.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'D\',4], representation="compact real")\n sage: L.zero()\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0]\n ' return self.element_class(self, self._MS.zero(), self._MS.zero()) def monomial(self, i): '\n Return the monomial indexed by ``i``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'A\',3], representation="compact real")\n sage: L.monomial(0)\n [ 0 1 0 0]\n [-1 0 0 0]\n [ 0 0 0 0]\n [ 0 0 0 0]\n ' return self.basis()[i] def term(self, i, c=None): '\n Return the term indexed by ``i`` with coefficient ``c``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'C\',3], representation="compact real")\n sage: L.term(4, 7/2)\n [ 0 0 0 0 0 7/2]\n [ 0 0 0 0 0 0]\n [ 0 0 0 7/2 0 0]\n [ 0 0 -7/2 0 0 0]\n [ 0 0 0 0 0 0]\n [-7/2 0 0 0 0 0]\n ' if (c is None): c = self.base_ring().one() else: c = self.base_ring()(c) return (c * self.basis()[i]) def _repr_option(self, key): '\n Metadata about the :meth:`_repr_` output.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'A\',1], representation="compact real")\n sage: L._repr_option("element_ascii_art")\n True\n ' if (key == 'element_ascii_art'): return True return FinitelyGeneratedLieAlgebra._repr_option(self, key) class Element(Element): '\n An element of a matrix Lie algebra in its compact real form.\n ' def __init__(self, parent, real, imag): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'D\',4], representation="compact real")\n sage: TestSuite(L.an_element()).run()\n ' Element.__init__(self, parent) self._real = real self._imag = imag self._real.set_immutable() self._imag.set_immutable() self._mc = None def _combined_matrix(self): '\n Return a single matrix representative of ``self``.\n\n .. NOTE::\n\n The resulting base ring is `R[i]`, where `R` is the\n base ring of the Lie algebra.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'A\',2], representation="compact real")\n sage: x = L.sum((i+1)/7*b for i,b in enumerate(L.basis()))\n sage: M = x._combined_matrix()\n sage: M\n [ 4/7*i 5/7*i + 1/7 6/7*i + 2/7]\n [5/7*i - 1/7 i 8/7*i + 3/7]\n [6/7*i - 2/7 8/7*i - 3/7 -11/7*i]\n sage: M.parent()\n Full MatrixSpace of 3 by 3 sparse matrices over\n Univariate Polynomial Ring in i over Rational Field\n ' from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing MS = self.parent()._MS R = PolynomialRing(MS.base_ring(), 'i') return (self._real + (R.gen() * self._imag)) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'B\',2], representation="compact real")\n sage: L.sum((i+1)/7*b for i,b in enumerate(L.basis()))\n [ 5/7*i 6/7*i + 1/7 0 i + 2/7 8/7*i + 3/7]\n [ 6/7*i - 1/7 9/7*i -i - 2/7 0 10/7*i + 4/7]\n [ 0 -i + 2/7 -5/7*i -6/7*i + 1/7 -8/7*i + 3/7]\n [ i - 2/7 0 -6/7*i - 1/7 -9/7*i -10/7*i + 4/7]\n [ 8/7*i - 3/7 10/7*i - 4/7 -8/7*i - 3/7 -10/7*i - 4/7 0]\n ' return repr(self._combined_matrix()) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'B\',2], representation="compact real")\n sage: x = L.sum((i+1)/7*b for i,b in enumerate(L.basis()))\n sage: latex(x)\n \\left(\\begin{array}{rrrrr}\n \\frac{5}{7} i & \\frac{6}{7} i + \\frac{1}{7} & 0 & i + \\frac{2}{7} & \\frac{8}{7} i + \\frac{3}{7} \\\\\n \\frac{6}{7} i - \\frac{1}{7} & \\frac{9}{7} i & -i - \\frac{2}{7} & 0 & \\frac{10}{7} i + \\frac{4}{7} \\\\\n 0 & -i + \\frac{2}{7} & -\\frac{5}{7} i & -\\frac{6}{7} i + \\frac{1}{7} & -\\frac{8}{7} i + \\frac{3}{7} \\\\\n i - \\frac{2}{7} & 0 & -\\frac{6}{7} i - \\frac{1}{7} & -\\frac{9}{7} i & -\\frac{10}{7} i + \\frac{4}{7} \\\\\n \\frac{8}{7} i - \\frac{3}{7} & \\frac{10}{7} i - \\frac{4}{7} & -\\frac{8}{7} i - \\frac{3}{7} & -\\frac{10}{7} i - \\frac{4}{7} & 0\n \\end{array}\\right)\n ' from sage.misc.latex import latex return latex(self._combined_matrix()) def _ascii_art_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'A\',2], representation="compact real")\n sage: x = L.sum((i+1)/7*b for i,b in enumerate(L.basis()))\n sage: ascii_art(x)\n [ 4/7*i 5/7*i + 1/7 6/7*i + 2/7]\n [5/7*i - 1/7 i 8/7*i + 3/7]\n [6/7*i - 2/7 8/7*i - 3/7 -11/7*i]\n ' from sage.typeset.ascii_art import ascii_art return ascii_art(self._combined_matrix()) def _unicode_art_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'A\',2], representation="compact real")\n sage: x = L.sum((i+1)/7*b for i,b in enumerate(L.basis()))\n sage: unicode_art(x)\n ⎛ 4/7*i 5/7*i + 1/7 6/7*i + 2/7⎞\n ⎜5/7*i - 1/7 i 8/7*i + 3/7⎟\n ⎝6/7*i - 2/7 8/7*i - 3/7 -11/7*i⎠\n ' from sage.typeset.unicode_art import unicode_art return unicode_art(self._combined_matrix()) def __bool__(self) -> bool: '\n Return if ``self`` is nonzero.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'C\',3], representation="compact real")\n sage: all(b for b in L.basis() if b != 0)\n True\n sage: bool(L.zero())\n False\n ' return (bool(self._real) or bool(self._imag)) def __hash__(self): '\n Return the hash of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'A\',2], representation="compact real")\n sage: x = L.an_element()\n sage: hash(x) == hash((x._real, x._imag))\n True\n ' return hash((self._real, self._imag)) def _richcmp_(self, other, op): '\n Return the richcmp of ``self`` and ``other`` by ``op``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'A\',1], representation="compact real")\n sage: sorted(L.basis())\n [\n [0 i] [ i 0] [ 0 1]\n [i 0], [ 0 -i], [-1 0]\n ]\n ' return richcmp((self._real, self._imag), (other._real, other._imag), op) def _add_(self, other): '\n Add ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'C\',2], representation="compact real")\n sage: B = L.basis()\n sage: B[0] + B[6]\n [ 0 1 i 0]\n [-1 0 0 0]\n [ i 0 0 1]\n [ 0 0 -1 0]\n sage: L.sum(B)\n [ i i + 1 i + 1 i + 1]\n [ i - 1 i i + 1 i + 1]\n [ i - 1 i - 1 -i -i + 1]\n [ i - 1 i - 1 -i - 1 -i]\n ' P = self.parent() return P.element_class(P, (self._real + other._real), (self._imag + other._imag)) def _sub_(self, other): '\n Subtract ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'C\',2], representation="compact real")\n sage: B = L.basis()\n sage: B[0] - B[6]\n [ 0 1 -i 0]\n [-1 0 0 0]\n [-i 0 0 1]\n [ 0 0 -1 0]\n sage: all(b - b == L.zero() for b in B)\n True\n ' P = self.parent() return P.element_class(P, (self._real - other._real), (self._imag - other._imag)) def _neg_(self): '\n Negate ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'C\',2], representation="compact real")\n sage: B = L.basis()\n sage: -(B[0] + B[6])\n [ 0 -1 -i 0]\n [ 1 0 0 0]\n [-i 0 0 -1]\n [ 0 0 1 0]\n sage: all(-(-b) == b for b in B)\n True\n ' P = self.parent() return P.element_class(P, (- self._real), (- self._imag)) def _bracket_(self, other): '\n Return the Lie bracket of ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'A\',1], representation="compact real")\n sage: B = L.basis()\n sage: list(B)\n [\n [ 0 1] [ i 0] [0 i]\n [-1 0], [ 0 -i], [i 0]\n ]\n sage: [b._bracket_(bp) for b in B for bp in B]\n [\n [0 0] [ 0 -2*i] [ 2*i 0] [ 0 2*i] [0 0] [ 0 -2]\n [0 0], [-2*i 0], [ 0 -2*i], [2*i 0], [0 0], [ 2 0],\n <BLANKLINE>\n [-2*i 0] [ 0 2] [0 0]\n [ 0 2*i], [-2 0], [0 0]\n ]\n ' (A, B) = (self._real, self._imag) (X, Y) = (other._real, other._imag) P = self.parent() return P.element_class(P, ((((A * X) - (X * A)) - (B * Y)) + (Y * B)), ((((A * Y) - (Y * A)) + (B * X)) - (X * B))) def _acted_upon_(self, x, self_on_left): '\n Return the action of ``x`` on ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'D\',4], representation="compact real")\n sage: B = L.basis()\n sage: (3/5) * B[21]\n [ 0 0 0 0 0 0 0 0]\n [ 0 0 0 3/5*i 0 0 0 0]\n [ 0 0 0 0 0 0 0 0]\n [ 0 3/5*i 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 -3/5*i]\n [ 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 -3/5*i 0 0]\n sage: B[7] * 7\n [ 0 0 0 0 0 0 0 0]\n [ 0 0 0 7 0 0 0 0]\n [ 0 0 0 0 0 0 0 0]\n [ 0 -7 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 0 0 7]\n [ 0 0 0 0 0 0 0 0]\n [ 0 0 0 0 0 -7 0 0]\n ' P = self.parent() return P.element_class(P, (x * self._real), (x * self._imag)) def monomial_coefficients(self, copy=False): '\n Return the monomial coefficients of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=[\'C\',3], representation="compact real")\n sage: B = L.basis()\n sage: x = L.sum(i*B[i] for i in range(len(B)))\n sage: x.monomial_coefficients() == {i: i for i in range(1,len(B))}\n True\n ' if (self._mc is None): P = self.parent() B = [(b._real.list() + b._imag.list()) for b in P.basis()] B.append((self._real.list() + self._imag.list())) R = self.base_ring() F = FreeModule(R, len(B[0])) dep = list(F.linear_dependence([F(b) for b in B])[0]) last = dep.pop() self._mc = {i: R(((- val) / last)) for (i, val) in enumerate(dep) if (val != 0)} if copy: return dict(self._mc) return self._mc
class LieAlgebraChevalleyBasis(LieAlgebraWithStructureCoefficients): '\n A simple finite dimensional Lie algebra in the Chevalley basis.\n\n Let `L` be a simple (complex) Lie algebra with roots `\\Phi`, then the\n Chevalley basis is given by `e_{\\alpha}` for all `\\alpha \\in \\Phi` and\n `h_{\\alpha_i} := h_i` where `\\alpha_i` is a simple root subject. These\n generators are subject to the relations:\n\n .. MATH::\n\n \\begin{aligned}\n [h_i, h_j] & = 0,\n \\\\ [h_i, e_{\\beta}] & = A_{\\alpha_i, \\beta} e_{\\beta},\n \\\\ [e_{\\beta}, e_{-\\beta}] & = \\sum_i A_{\\beta, \\alpha_i} h_i,\n \\\\ [e_{\\beta}, e_{\\gamma}] & = \\begin{cases}\n N_{\\beta,\\gamma} e_{\\beta + \\gamma} & \\beta + \\gamma \\in \\Phi, \\\\\n 0 & \\text{otherwise,} \\end{cases}\n \\end{aligned}\n\n where `A_{\\alpha, \\beta} = \\frac{2 (\\alpha, \\beta)}{(\\alpha, \\alpha)}`\n and `N_{\\alpha, \\beta}` is the maximum such that\n `\\alpha - N_{\\alpha, \\beta} \\beta \\in \\Phi`.\n\n For computing the signs of the coefficients, see Section 3 of [CMT2003]_.\n\n .. SEEALSO::\n\n For simply-laced types, an alternative construction using an asymmetry\n function is given by :class:`LieAlgebraChevalleyBasis_simply_laced`.\n ' @staticmethod def __classcall_private__(cls, R, cartan_type, epsilon=None): "\n Normalize ``self`` to ensure a unique representation.\n\n TESTS::\n\n sage: L1 = LieAlgebra(QQ, cartan_type=['A', 2])\n sage: L2 = LieAlgebra(QQ, cartan_type=CartanType(['A', 2]))\n sage: L3 = LieAlgebra(QQ, cartan_type=CartanMatrix(['A', 2]))\n sage: L1 is L2 and L2 is L3\n True\n\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2], epsilon=[(1,2)])\n sage: type(L)\n <class '...LieAlgebraChevalleyBasis_simply_laced_with_category'>\n sage: L = LieAlgebra(QQ, cartan_type=['A', 1], epsilon=[])\n sage: type(L)\n <class '...LieAlgebraChevalleyBasis_simply_laced_with_category'>\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2], epsilon=[(2,3)])\n Traceback (most recent call last):\n ...\n ValueError: not a valid Dynkin orientation\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2], epsilon=[(1,2), (2,1)])\n Traceback (most recent call last):\n ...\n ValueError: not a valid Dynkin orientation\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2], epsilon=[(1,2), (1,1)])\n Traceback (most recent call last):\n ...\n ValueError: not a valid Dynkin orientation\n sage: L = LieAlgebra(QQ, cartan_type=['A', 1], epsilon=[(1,1)])\n Traceback (most recent call last):\n ...\n ValueError: not a valid Dynkin orientation\n " if isinstance(cartan_type, (CartanMatrix, DynkinDiagram_class)): cartan_type = cartan_type.cartan_type() else: cartan_type = CartanType(cartan_type) if (epsilon is not None): if (not cartan_type.is_simply_laced()): raise ValueError('the Cartan type must be simply-laced with an asymmetry function') epsilon = frozenset([tuple(p) for p in epsilon]) if (cartan_type.rank() == 1): if epsilon: raise ValueError('not a valid Dynkin orientation') else: from sage.graphs.graph import Graph G = Graph(epsilon, multiedges=True, loops=True, format='list_of_edges') if (G.has_multiple_edges() or G.has_loops() or (cartan_type.dynkin_diagram().to_undirected() != G.to_simple())): raise ValueError('not a valid Dynkin orientation') return LieAlgebraChevalleyBasis_simply_laced(R, cartan_type, epsilon) return super().__classcall__(cls, R, cartan_type) def __init__(self, R, cartan_type): "\n Initialize ``self``.\n\n TESTS::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A',2])\n sage: TestSuite(L).run() # long time\n " self._cartan_type = cartan_type self._Q = cartan_type.root_system().root_lattice() p_roots = list(self._Q.positive_roots_by_height()) n_roots = [(- x) for x in p_roots] self._p_roots_index = OrderedDict(((al, i) for (i, al) in enumerate(p_roots))) alphacheck = self._Q.simple_coroots() s_coeffs = self._construct_struct_coeffs(R, p_roots) for k in list(s_coeffs): (a, b) = k if (self._basis_key(a) > self._basis_key(b)): s_coeffs[(b, a)] = [(index, (- v)) for (index, v) in s_coeffs[k].items()] del s_coeffs[k] else: s_coeffs[k] = s_coeffs[k].items() I = self._cartan_type.index_set() names = ['e{}'.format(i) for i in I] names += ['f{}'.format(i) for i in I] names += ['h{}'.format(i) for i in I] category = TriangularKacMoodyAlgebras(R).FiniteDimensional() index_set = ((p_roots + list(alphacheck)) + n_roots) self._cartan_indices = range(len(p_roots), (len(p_roots) + len(alphacheck))) names = tuple(names) from sage.sets.finite_enumerated_set import FiniteEnumeratedSet index_set = FiniteEnumeratedSet(index_set) LieAlgebraWithStructureCoefficients.__init__(self, R, s_coeffs, names, index_set, category, prefix='E', bracket='[', sorting_key=self._basis_key) def _construct_struct_coeffs(self, R, p_roots): "\n Construct the structure coefficients of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A',1], epsilon=[])\n sage: sorted(L._construct_struct_coeffs(QQ, list(L._Q.positive_roots())).items(), key=str)\n [((alpha[1], -alpha[1]), {alphacheck[1]: 1}),\n ((alpha[1], alphacheck[1]), {alpha[1]: -2}),\n ((alphacheck[1], -alpha[1]), {-alpha[1]: -2})]\n " alphacheck = self._Q.simple_coroots() roots = frozenset(self._Q.roots()) one = R.one() sp_sign = {} for (i, a) in enumerate(p_roots): for b in p_roots[(i + 1):]: if ((a + b) not in p_roots): continue (x, y) = (a + b).extraspecial_pair() if ((x, y) == (a, b)): if ((x, y) not in sp_sign): if ((sum(x.coefficients()) == sum(y.coefficients())) and (str(x) > str(y))): (y, x) = (x, y) sp_sign[(x, y)] = (- one) sp_sign[(y, x)] = one continue if ((b - x) in roots): t1 = ((((b - x).norm_squared() / b.norm_squared()) * sp_sign[(x, (b - x))]) * sp_sign[(a, (y - a))]) else: t1 = 0 if ((a - x) in roots): t2 = ((((a - x).norm_squared() / a.norm_squared()) * sp_sign[(x, (a - x))]) * sp_sign[(b, (y - b))]) else: t2 = 0 if ((t1 - t2) > 0): sp_sign[(a, b)] = (- one) elif ((t2 - t1) > 0): sp_sign[(a, b)] = one sp_sign[(b, a)] = (- sp_sign[(a, b)]) def e_coeff(r, s): p = 1 while ((r - (p * s)) in roots): p += 1 return p s_coeffs = {} for (i, r) in enumerate(p_roots): for ac in alphacheck: c = r.scalar(ac) if (c == 0): continue s_coeffs[(r, ac)] = {r: (- c)} s_coeffs[(ac, (- r))] = {(- r): (- c)} s_coeffs[(r, (- r))] = {alphacheck[j]: c for (j, c) in r.associated_coroot()} for (j, s) in enumerate(p_roots[(i + 1):], start=(i + 1)): if ((s - r) in p_roots): c = e_coeff(r, (- s)) (a, b) = ((s - r), r) if (self._p_roots_index[a] > self._p_roots_index[b]): c *= (- sp_sign[(b, a)]) else: c *= sp_sign[(a, b)] s_coeffs[((- r), s)] = {a: (- c)} s_coeffs[(r, (- s))] = {(- a): c} a = (r + s) if (a in p_roots): c = (e_coeff(r, s) * sp_sign[(r, s)]) s_coeffs[(r, s)] = {a: c} s_coeffs[((- r), (- s))] = {(- a): (- c)} return s_coeffs def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: LieAlgebra(QQ, cartan_type=['A', 2])\n Lie algebra of ['A', 2] in the Chevalley basis\n " return 'Lie algebra of {} in the Chevalley basis'.format(self._cartan_type) def _test_structure_coeffs(self, **options): "\n Check the structure coefficients against the GAP implementation.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(ZZ, cartan_type=['G',2])\n sage: L._test_structure_coeffs()\n " tester = self._tester(**options) ct = self.cartan_type() from sage.libs.gap.libgap import libgap L = libgap.SimpleLieAlgebra(ct.letter, ct.n, libgap(self.base_ring())) (pos_B, neg_B, _) = libgap.ChevalleyBasis(L) gap_p_roots = libgap.PositiveRoots(libgap.RootSystem(L)).sage() p_roots = list(self._Q.positive_roots_by_height()) WL = ct.root_system().weight_lattice() La = WL.fundamental_weights() convert = {WL(root): root for root in p_roots} index = {convert[sum(((c * La[(j + 1)]) for (j, c) in enumerate(rt)))]: i for (i, rt) in enumerate(gap_p_roots)} basis = self.basis() roots = frozenset(p_roots) for (i, x) in enumerate(p_roots): for y in p_roots[(i + 1):]: if ((x + y) in roots): c = basis[x].bracket(basis[y]).leading_coefficient() (a, b) = (x + y).extraspecial_pair() if ((x, y) == (a, b)): tester.assertEqual((pos_B[index[x]] * pos_B[index[y]]), (c * pos_B[index[(x + y)]]), 'extra special pair differ for [{}, {}]'.format(x, y)) else: tester.assertEqual((pos_B[index[x]] * pos_B[index[y]]), (c * pos_B[index[(x + y)]]), 'incorrect structure coefficient for [{}, {}]'.format(x, y)) if ((x - y) in roots): c = basis[x].bracket(basis[(- y)]).leading_coefficient() tester.assertEqual((pos_B[index[x]] * neg_B[index[y]]), (c * neg_B[index[(x - y)]]), 'incorrect structure coefficient for [{}, {}]'.format(x, y)) def _repr_generator(self, m): "\n Return a string representation of the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2])\n sage: K = L.basis().keys()\n sage: L._repr_generator(K[0])\n 'E[alpha[2]]'\n sage: L._repr_generator(K[4])\n 'h2'\n " if (m in self._Q.simple_coroots()): return 'h{}'.format(m.support()[0]) return IndexedGenerators._repr_generator(self, m) def _latex_generator(self, m): "\n Return a latex representation of the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2])\n sage: K = L.basis().keys()\n sage: L._latex_generator(K[0])\n 'E_{\\\\alpha_{2}}'\n sage: L._latex_generator(K[4])\n 'h_{2}'\n " if (m in self._Q.simple_coroots()): return 'h_{{{}}}'.format(m.support()[0]) return IndexedGenerators._latex_generator(self, m) def _basis_key(self, x): "\n Compare two basis element indices. We order the basis elements by\n positive roots, coroots, and negative roots and then according to\n height.\n\n OUTPUT:\n\n If ``x == y``, return 0. If ``x < y``, return -1. Else return 1.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['B', 2])\n sage: K = L.basis().keys()\n sage: S = sorted(K, key=L._basis_key); S\n [alpha[2],\n alpha[1],\n alpha[1] + alpha[2],\n alpha[1] + 2*alpha[2],\n alphacheck[1],\n alphacheck[2],\n -alpha[2],\n -alpha[1],\n -alpha[1] - alpha[2],\n -alpha[1] - 2*alpha[2]]\n sage: S == K\n False\n " if (x in self._p_roots_index): return self._p_roots_index[x] if ((- x) in self._p_roots_index): return ((len(self._p_roots_index) + self._cartan_type.rank()) + self._p_roots_index[(- x)]) alphacheck = list(self._Q.simple_coroots()) try: return (len(self._p_roots_index) + alphacheck.index(x)) except ValueError: raise KeyError(x) def degree_on_basis(self, m): "\n Return the degree of the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['G', 2])\n sage: [L.degree_on_basis(m) for m in L.basis().keys()]\n [alpha[2], alpha[1], alpha[1] + alpha[2],\n 2*alpha[1] + alpha[2], 3*alpha[1] + alpha[2],\n 3*alpha[1] + 2*alpha[2],\n 0, 0,\n -alpha[2], -alpha[1], -alpha[1] - alpha[2],\n -2*alpha[1] - alpha[2], -3*alpha[1] - alpha[2],\n -3*alpha[1] - 2*alpha[2]]\n " if (m.parent() is self._Q): return m return self._Q.zero() def _negative_half_index_set(self): '\n Return the index set of the basis for the negative half of ``self``.\n\n EXAMPLES::\n\n sage: L = lie_algebras.sp(QQ, 4)\n sage: L._negative_half_index_set()\n [-alpha[2], -alpha[1], -alpha[1] - alpha[2],\n -2*alpha[1] - alpha[2]]\n ' return [(- x) for x in self._p_roots_index] def _weight_action(self, m, wt): '\n Return the action of the basis element indexed by ``m`` on ``wt``.\n\n INPUT:\n\n - ``m`` -- an index of a basis element of the Cartan subalgebra\n - ``wt`` -- a weight\n\n EXAMPLES::\n\n sage: L = lie_algebras.sp(QQ, 6)\n sage: La = L.cartan_type().root_system().ambient_space().fundamental_weights()\n sage: mu = La[1] - 3/5*La[2]\n sage: ac = L.cartan_type().root_system().coroot_lattice().simple_roots()\n sage: L._weight_action(ac[1], mu)\n 1\n sage: L._weight_action(ac[2], mu)\n -3/5\n sage: L._weight_action(ac[3], mu)\n 0\n ' ac = self._cartan_type.root_system().root_lattice().simple_coroots() aci = dict(ac.inverse_family()) if (m not in aci): raise ValueError('not an element in the Cartan subalgebra') R = self.base_ring() alc = wt.parent().simple_coroots() return R(wt.scalar(alc[aci[m]])) def affine(self, kac_moody=True): "\n Return the affine Lie algebra of ``self``.\n\n EXAMPLES::\n\n sage: sp6 = lie_algebras.sp(QQ, 6)\n sage: sp6\n Lie algebra of ['C', 3] in the Chevalley basis\n sage: sp6.affine()\n Affine Kac-Moody algebra of ['C', 3] in the Chevalley basis\n\n sage: L = LieAlgebra(QQ, cartan_type=['A',3], epsilon=[(1,2),(3,2)])\n sage: L.affine(False)\n Affine Lie algebra of ['A', 3] in the Chevalley basis\n sage: L.affine(True)\n Affine Kac-Moody algebra of ['A', 3] in the Chevalley basis\n " from sage.algebras.lie_algebras.affine_lie_algebra import AffineLieAlgebra return AffineLieAlgebra(self, kac_moody=kac_moody) @cached_method def indices_to_positive_roots_map(self): "\n Return the map from indices to positive roots.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2])\n sage: L.indices_to_positive_roots_map()\n {1: alpha[1], 2: alpha[2], 3: alpha[1] + alpha[2]}\n " return {(i + 1): r for (i, r) in enumerate(self._Q.positive_roots())} @cached_method def lie_algebra_generators(self, str_keys=False): "\n Return the Chevalley Lie algebra generators of ``self``.\n\n INPUT:\n\n - ``str_keys`` -- (default: ``False``) set to ``True`` to have the\n indices indexed by strings instead of simple (co)roots\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 1])\n sage: L.lie_algebra_generators()\n Finite family {alpha[1]: E[alpha[1]], -alpha[1]: E[-alpha[1]], alphacheck[1]: h1}\n sage: L.lie_algebra_generators(True)\n Finite family {'e1': E[alpha[1]], 'f1': E[-alpha[1]], 'h1': h1}\n " index_set = self._cartan_type.index_set() alpha = self._Q.simple_roots() alphacheck = self._Q.simple_coroots() B = self.basis() ret = {} if str_keys: for i in index_set: al = alpha[i] ret['e{}'.format(i)] = B[al] ret['f{}'.format(i)] = B[(- al)] ret['h{}'.format(i)] = B[alphacheck[i]] keys = ((['e{}'.format(i) for i in index_set] + ['f{}'.format(i) for i in index_set]) + ['h{}'.format(i) for i in index_set]) else: for i in index_set: al = alpha[i] ret[al] = B[al] ret[(- al)] = B[(- al)] ret[alphacheck[i]] = B[alphacheck[i]] keys = (([alpha[i] for i in index_set] + [(- alpha[i]) for i in index_set]) + [alphacheck[i] for i in index_set]) return Family(keys, ret.__getitem__) @cached_method def _part_generators(self, positive=False): "\n Return the Lie algebra generators for the positive or\n negative half of ``self``.\n\n INPUT:\n\n - ``positive`` -- boolean (default: ``False``); if ``True``\n then return positive part generators, otherwise the return\n the negative part generators\n\n OUTPUT:\n\n A :func:`~sage.sets.family.Family` whose keys are the\n index set of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['G', 2])\n sage: list(L._part_generators(True))\n [E[alpha[1]],\n E[alpha[2]]]\n " I = self._cartan_type.index_set() al = self._Q.simple_roots() G = self.lie_algebra_generators() if positive: d = {i: G[al[i]] for i in I} else: d = {i: G[(- al[i])] for i in I} return Family(I, d.__getitem__) @cached_method def gens(self): "\n Return the generators of ``self`` in the order of `e_i`, `f_i`,\n and `h_i`.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2])\n sage: L.gens()\n (E[alpha[1]], E[alpha[2]], E[-alpha[1]], E[-alpha[2]], h1, h2)\n " index_set = self._cartan_type.index_set() alpha = self._Q.simple_roots() alphacheck = self._Q.simple_coroots() B = self.basis() ret = [] for i in index_set: ret.append(B[alpha[i]]) for i in index_set: ret.append(B[(- alpha[i])]) for i in index_set: ret.append(B[alphacheck[i]]) return tuple(ret) def highest_root_basis_elt(self, pos=True): "\n Return the basis element corresponding to the highest root `\\theta`.\n\n INPUT:\n\n - ``pos`` -- (default: ``True``) if ``True``, then return\n `e_{\\theta}`, otherwise return `f_{\\theta}`\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2])\n sage: L.highest_root_basis_elt()\n E[alpha[1] + alpha[2]]\n sage: L.highest_root_basis_elt(False)\n E[-alpha[1] - alpha[2]]\n " theta = self._Q.highest_root() B = self.basis() if pos: return B[theta] return B[(- theta)] @cached_method def killing_form_matrix(self): "\n Return the matrix of the Killing form of ``self``.\n\n The rows and the columns of this matrix are indexed by the\n elements of the basis of ``self`` (in the order provided by\n :meth:`basis`).\n\n EXAMPLES::\n\n sage: g = LieAlgebra(QQ, cartan_type=['A', 2])\n sage: g.killing_form_matrix()\n [ 0 0 0 0 0 6 0 0]\n [ 0 0 0 0 0 0 6 0]\n [ 0 0 0 0 0 0 0 6]\n [ 0 0 0 12 -6 0 0 0]\n [ 0 0 0 -6 12 0 0 0]\n [ 6 0 0 0 0 0 0 0]\n [ 0 6 0 0 0 0 0 0]\n [ 0 0 6 0 0 0 0 0]\n " B = self.basis() Q = self._Q from sage.matrix.constructor import matrix ret = matrix.zero(self.base_ring(), self._M.rank()) keys = list(B.keys()) for (i, a) in enumerate(keys): for (j, b) in enumerate(keys[i:], start=i): if (((a in Q) != (b in Q)) or ((a in Q) and (a + b))): continue temp = self.killing_matrix(B[a], B[b]).trace() ret[(i, j)] = temp ret[(j, i)] = temp ret.set_immutable() return ret def killing_form(self, x, y): "\n Return the Killing form on ``x`` and ``y``, where ``x``\n and ``y`` are two elements of ``self``.\n\n The Killing form is defined as\n\n .. MATH::\n\n \\langle x \\mid y \\rangle\n = \\operatorname{tr}\\left( \\operatorname{ad}_x\n \\circ \\operatorname{ad}_y \\right).\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2])\n sage: L.killing_form(L.an_element(), L.an_element())\n 36\n sage: B = L.basis()\n sage: matrix([[L.killing_form(a, b) for a in B] for b in B])\n [ 0 0 0 0 0 6 0 0]\n [ 0 0 0 0 0 0 6 0]\n [ 0 0 0 0 0 0 0 6]\n [ 0 0 0 12 -6 0 0 0]\n [ 0 0 0 -6 12 0 0 0]\n [ 6 0 0 0 0 0 0 0]\n [ 0 6 0 0 0 0 0 0]\n [ 0 0 6 0 0 0 0 0]\n " return ((x.value * self.killing_form_matrix()) * y.value)
class LieAlgebraChevalleyBasis_simply_laced(LieAlgebraChevalleyBasis): "\n A finite dimensional simply-laced Lie algebra in the Chevalley basis\n with structure coefficients given by an orientation of the Dynkin\n diagram.\n\n We follow Chapter 7.7 of [Ka1990]_, where the structure coefficients\n are given by an :meth:`asymmetry function <asymmetry_function>` defined by\n `\\varepsilon(\\alpha_i, \\alpha_j) = -1` if there is an arrow `i \\to j` in\n the Dynkin quiver (an orientation of the Dynkin diagram). However we twist\n `E_{\\alpha}` by `\\mathrm{sign}(\\alpha)` so that `F_i = E_{-\\alpha_i}`\n rather than its negative.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2], epsilon=[(2, 1)])\n sage: L.e(1).bracket(L.e(2))\n E[alpha[1] + alpha[2]]\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2], epsilon=[(1, 2)])\n sage: L.e(1).bracket(L.e(2))\n -E[alpha[1] + alpha[2]]\n " def __init__(self, R, cartan_type, epsilon): "\n Initialize ``self``.\n\n TESTS::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A', 2], epsilon=[(2,1)])\n sage: TestSuite(L).run(elements=list(L.basis()))\n sage: L = LieAlgebra(QQ, cartan_type=['D', 4], epsilon=[(2,1), (3,2), (4,2)])\n sage: TestSuite(L).run(elements=list(L.basis())) # long time\n " self._epsilon = epsilon super().__init__(R, cartan_type) def _construct_struct_coeffs(self, R, p_roots): "\n Construct the structure coefficients of ``self``.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A',1], epsilon=[])\n sage: sorted(L._construct_struct_coeffs(QQ, list(L._Q.positive_roots())).items(), key=str)\n [((alpha[1], -alpha[1]), {alphacheck[1]: 1}),\n ((alpha[1], alphacheck[1]), {alpha[1]: -2}),\n ((alphacheck[1], -alpha[1]), {-alpha[1]: -2})]\n " p_roots_set = set(p_roots) alphacheck = self._Q.simple_coroots() s_coeffs = {} for (i, r) in enumerate(p_roots): for ac in alphacheck: c = r.scalar(ac) if (c == 0): continue s_coeffs[(r, ac)] = {r: (- c)} s_coeffs[(ac, (- r))] = {(- r): (- c)} s_coeffs[(r, (- r))] = {alphacheck[j]: c for (j, c) in r.associated_coroot()} for (j, s) in enumerate(p_roots[(i + 1):], start=(i + 1)): if ((r + s) in p_roots_set): coeff = R.prod(((((- 1) ** (ca * cb)) if (((ii, jj) in self._epsilon) or (ii == jj)) else 1) for (ii, ca) in r._monomial_coefficients.items() for (jj, cb) in s._monomial_coefficients.items())) s_coeffs[(r, s)] = {(r + s): coeff} ht = (sum(r.coefficients()) + sum(s.coefficients())) s_coeffs[((- r), (- s))] = {((- r) - s): (- coeff)} if (((r - s) in p_roots_set) or ((s - r) in p_roots_set)): coeff = R.prod(((((- 1) ** (ca * cb)) if (((ii, jj) in self._epsilon) or (ii == jj)) else 1) for (ii, ca) in r._monomial_coefficients.items() for (jj, cb) in s._monomial_coefficients.items())) if ((r - s) in p_roots_set): s_coeffs[(r, (- s))] = {(r - s): (- coeff)} s_coeffs[((- r), s)] = {(s - r): coeff} else: s_coeffs[(r, (- s))] = {(r - s): coeff} s_coeffs[((- r), s)] = {(s - r): (- coeff)} return s_coeffs def asymmetry_function(self): "\n Return the asymmetry function of ``self``.\n\n An *asymmetry function* is a function `\\varepsilon : Q \\times Q\n \\to \\{1, -1\\}` that satisfies the following properties:\n\n 1. `\\varepsilon(\\alpha, \\alpha) = (-1)^{(\\alpha|\\alpha)/2}`\n 2. bimultiplicativity `\\varepsilon(alpha + \\alpha', \\beta) =\n \\varepsilon(\\alpha, \\beta) \\varepsilon(\\alpha', \\beta)` and\n `\\varepsilon(alpha, \\beta + \\beta') =\n \\varepsilon(\\alpha, \\beta) \\varepsilon(\\alpha', \\beta)`,\n\n where `(\\alpha | \\beta)` is the symmetric bilinear form on `Q` given\n by the Cartan matrix. Some consequences of these properties are that\n `\\varepsilon(\\alpha, 0) = \\varepsilon(0, \\beta) = 1` and\n `varepsilon(\\alpha, \\beta) \\varepsilon(\\beta, \\alpha) =\n (-1)^{(\\alpha|\\beta)}`.\n\n OUTPUT:\n\n The asymmetry function as a ``dict`` consisting of pairs of all of\n the roots of `Q` and `0`.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(QQ, cartan_type=['A',2], epsilon=[(2,1)])\n sage: ep = L.asymmetry_function()\n sage: al = L.cartan_type().root_system().root_lattice().simple_roots()\n sage: ep[al[1], al[2]]\n 1\n sage: ep[al[2],al[1]]\n -1\n\n sage: L = LieAlgebra(QQ, cartan_type=['A',2], epsilon=[(1,2)])\n sage: ep = L.asymmetry_function()\n sage: al = L.cartan_type().root_system().root_lattice().simple_roots()\n sage: ep[al[1], al[2]]\n -1\n sage: ep[al[2],al[1]]\n 1\n " roots = set(self._Q.roots()) al = self._Q.simple_roots() ep = {(r, r): ((- 1) ** (r.scalar(r.associated_coroot()) // 2)) for r in roots} next_level = set() for i in self._Q.index_set(): ep[(al[i], self._Q.zero())] = 1 ep[((- al[i]), self._Q.zero())] = 1 for j in self._Q.index_set(): if ((i == j) or ((i, j) in self._epsilon)): ep[(al[i], al[j])] = (- 1) else: ep[(al[i], al[j])] = 1 next_level.add((al[i], al[j])) ep[(al[i], (- al[j]))] = ep[(al[i], al[j])] next_level.add((al[i], (- al[j]))) ep[((- al[i]), al[j])] = ep[(al[i], al[j])] next_level.add(((- al[i]), al[j])) ep[((- al[i]), (- al[j]))] = ep[(al[i], al[j])] next_level.add(((- al[i]), (- al[j]))) while next_level: cur = next_level next_level = set() for (r, s) in cur: for a in al: prev = r temp = (r + a) while ((temp in roots) or (temp == 0)): if ((temp, s) in ep): break next_level.add((temp, s)) ep[(temp, s)] = (ep[(prev, s)] * ep[(a, s)]) prev = temp temp += a prev = r temp = (r - a) while ((temp in roots) or (temp == 0)): if ((temp, s) in ep): break next_level.add((temp, s)) ep[(temp, s)] = (ep[(prev, s)] * ep[((- a), s)]) prev = temp temp -= a prev = s temp = (s + a) while ((temp in roots) or (temp == 0)): if ((r, temp) in ep): break next_level.add((r, temp)) ep[(r, temp)] = (ep[(r, prev)] * ep[(r, a)]) prev = temp temp += a prev = s temp = (s - a) while ((temp in roots) or (temp == 0)): if ((r, temp) in ep): break next_level.add((r, temp)) ep[(r, temp)] = (ep[(r, prev)] * ep[(r, (- a))]) prev = temp temp -= a return ep def _test_structure_coeffs(self, **options): "\n Check the structure coefficients using the :meth:`asymmetry_function`.\n\n EXAMPLES::\n\n sage: L = LieAlgebra(ZZ, cartan_type=['A',4], epsilon=[(1,2), (3,2), (3,4)])\n sage: L._test_structure_coeffs()\n " tester = self._tester(**options) ep = self.asymmetry_function() roots = set(self._Q.roots()) p_roots = set(self._Q.positive_roots()) B = self.basis() for r in roots: for s in roots: if ((r + s) not in roots): continue x = B[r].bracket(B[s]) tester.assertEqual(list(x.support()), [(r + s)], f'[{r}, {s}] = {x} is not a root vector') sign = (1 if ((r in p_roots) == (s in p_roots)) else (- 1)) if ((r + s) not in p_roots): sign = (- sign) tester.assertEqual(x[(r + s)], (sign * ep[(r, s)]), f'[{r}, {s}] = {x[(r + s)]} != {(sign * ep[(r, s)])}')
def three_dimensional(R, a, b, c, d, names=['X', 'Y', 'Z']): "\n The 3-dimensional Lie algebra over a given commutative ring `R`\n with basis `\\{X, Y, Z\\}` subject to the relations:\n\n .. MATH::\n\n [X, Y] = aZ + dY, \\quad [Y, Z] = bX, \\quad [Z, X] = cY + dZ\n\n where `a,b,c,d \\in R`.\n\n This is always a well-defined 3-dimensional Lie algebra, as can\n be easily proven by computation.\n\n EXAMPLES::\n\n sage: L = lie_algebras.three_dimensional(QQ, 4, 1, -1, 2)\n sage: L.structure_coefficients()\n Finite family {('X', 'Y'): 2*Y + 4*Z, ('X', 'Z'): Y - 2*Z, ('Y', 'Z'): X}\n sage: TestSuite(L).run()\n sage: L = lie_algebras.three_dimensional(QQ, 1, 0, 0, 0)\n sage: L.structure_coefficients()\n Finite family {('X', 'Y'): Z}\n sage: L = lie_algebras.three_dimensional(QQ, 0, 0, -1, -1)\n sage: L.structure_coefficients()\n Finite family {('X', 'Y'): -Y, ('X', 'Z'): Y + Z}\n sage: L = lie_algebras.three_dimensional(QQ, 0, 1, 0, 0)\n sage: L.structure_coefficients()\n Finite family {('Y', 'Z'): X}\n sage: lie_algebras.three_dimensional(QQ, 0, 0, 0, 0)\n Abelian Lie algebra on 3 generators (X, Y, Z) over Rational Field\n sage: Q.<a,b,c,d> = PolynomialRing(QQ)\n sage: L = lie_algebras.three_dimensional(Q, a, b, c, d)\n sage: L.structure_coefficients()\n Finite family {('X', 'Y'): d*Y + a*Z, ('X', 'Z'): (-c)*Y + (-d)*Z, ('Y', 'Z'): b*X}\n sage: TestSuite(L).run()\n " if isinstance(names, str): names = names.split(',') X = names[0] Y = names[1] Z = names[2] from sage.algebras.lie_algebras.structure_coefficients import LieAlgebraWithStructureCoefficients s_coeff = {(X, Y): {Z: a, Y: d}, (Y, Z): {X: b}, (Z, X): {Y: c, Z: d}} return LieAlgebraWithStructureCoefficients(R, s_coeff, tuple(names))
def cross_product(R, names=['X', 'Y', 'Z']): "\n The Lie algebra of `\\RR^3` defined by the usual cross product\n `\\times`.\n\n EXAMPLES::\n\n sage: L = lie_algebras.cross_product(QQ)\n sage: L.structure_coefficients()\n Finite family {('X', 'Y'): Z, ('X', 'Z'): -Y, ('Y', 'Z'): X}\n sage: TestSuite(L).run()\n " L = three_dimensional(R, 1, 1, 1, 0, names=names) L.rename('Lie algebra of RR^3 under cross product over {}'.format(R)) return L
def three_dimensional_by_rank(R, n, a=None, names=['X', 'Y', 'Z']): "\n Return a 3-dimensional Lie algebra of rank ``n``, where `0 \\leq n \\leq 3`.\n\n Here, the *rank* of a Lie algebra `L` is defined as the dimension\n of its derived subalgebra `[L, L]`. (We are assuming that `R` is\n a field of characteristic `0`; otherwise the Lie algebras\n constructed by this function are still well-defined but no longer\n might have the correct ranks.) This is not to be confused with\n the other standard definition of a rank (namely, as the\n dimension of a Cartan subalgebra, when `L` is semisimple).\n\n INPUT:\n\n - ``R`` -- the base ring\n - ``n`` -- the rank\n - ``a`` -- the deformation parameter (used for `n = 2`); this should\n be a nonzero element of `R` in order for the resulting Lie\n algebra to actually have the right rank(?)\n - ``names`` -- (optional) the generator names\n\n EXAMPLES::\n\n sage: lie_algebras.three_dimensional_by_rank(QQ, 0)\n Abelian Lie algebra on 3 generators (X, Y, Z) over Rational Field\n sage: L = lie_algebras.three_dimensional_by_rank(QQ, 1)\n sage: L.structure_coefficients()\n Finite family {('Y', 'Z'): X}\n sage: L = lie_algebras.three_dimensional_by_rank(QQ, 2, 4)\n sage: L.structure_coefficients()\n Finite family {('X', 'Y'): Y, ('X', 'Z'): Y + Z}\n sage: L = lie_algebras.three_dimensional_by_rank(QQ, 2, 0)\n sage: L.structure_coefficients()\n Finite family {('X', 'Y'): Y}\n sage: lie_algebras.three_dimensional_by_rank(QQ, 3)\n sl2 over Rational Field\n " if isinstance(names, str): names = names.split(',') names = tuple(names) if (n == 0): from sage.algebras.lie_algebras.abelian import AbelianLieAlgebra return AbelianLieAlgebra(R, names=names) if (n == 1): L = three_dimensional(R, 0, 1, 0, 0, names=names) L.rename('Lie algebra of 3x3 strictly upper triangular matrices over {}'.format(R)) return L if (n == 2): if (a is None): raise ValueError("The parameter 'a' must be specified") X = names[0] Y = names[1] Z = names[2] from sage.algebras.lie_algebras.structure_coefficients import LieAlgebraWithStructureCoefficients if (a == 0): s_coeff = {(X, Y): {Y: R.one()}, (X, Z): {Y: R(a)}} L = LieAlgebraWithStructureCoefficients(R, s_coeff, tuple(names)) L.rename('Degenerate Lie algebra of dimension 3 and rank 2 over {}'.format(R)) else: s_coeff = {(X, Y): {Y: R.one()}, (X, Z): {Y: R.one(), Z: R.one()}} L = LieAlgebraWithStructureCoefficients(R, s_coeff, tuple(names)) L.rename('Lie algebra of dimension 3 and rank 2 with parameter {} over {}'.format(a, R)) return L if (n == 3): from sage.algebras.lie_algebras.structure_coefficients import LieAlgebraWithStructureCoefficients E = names[0] F = names[1] H = names[2] s_coeff = {(E, F): {H: R.one()}, (H, E): {E: R(2)}, (H, F): {F: R((- 2))}} L = LieAlgebraWithStructureCoefficients(R, s_coeff, tuple(names)) L.rename('sl2 over {}'.format(R)) return L raise ValueError('Invalid rank')
def affine_transformations_line(R, names=['X', 'Y'], representation='bracket'): '\n The Lie algebra of affine transformations of the line.\n\n EXAMPLES::\n\n sage: L = lie_algebras.affine_transformations_line(QQ)\n sage: L.structure_coefficients()\n Finite family {(\'X\', \'Y\'): Y}\n sage: X, Y = L.lie_algebra_generators()\n sage: L[X, Y] == Y\n True\n sage: TestSuite(L).run()\n sage: L = lie_algebras.affine_transformations_line(QQ, representation="matrix")\n sage: X, Y = L.lie_algebra_generators()\n sage: L[X, Y] == Y\n True\n sage: TestSuite(L).run()\n ' if isinstance(names, str): names = names.split(',') names = tuple(names) if (representation == 'matrix'): from sage.matrix.matrix_space import MatrixSpace MS = MatrixSpace(R, 2, sparse=True) one = R.one() gens = tuple((MS({(0, i): one}) for i in range(2))) from sage.algebras.lie_algebras.lie_algebra import LieAlgebraFromAssociative return LieAlgebraFromAssociative(MS, gens, names=names) X = names[0] Y = names[1] from sage.algebras.lie_algebras.structure_coefficients import LieAlgebraWithStructureCoefficients s_coeff = {(X, Y): {Y: R.one()}} L = LieAlgebraWithStructureCoefficients(R, s_coeff, names=names) L.rename('Lie algebra of affine transformations of a line over {}'.format(R)) return L
def abelian(R, names=None, index_set=None): "\n Return the abelian Lie algebra generated by ``names``.\n\n EXAMPLES::\n\n sage: lie_algebras.abelian(QQ, 'x, y, z')\n Abelian Lie algebra on 3 generators (x, y, z) over Rational Field\n " if isinstance(names, str): names = names.split(',') elif isinstance(names, (list, tuple)): names = tuple(names) elif (names is not None): if (index_set is not None): raise ValueError('invalid generator names') index_set = names names = None from sage.rings.infinity import infinity if ((index_set is not None) and (not isinstance(index_set, (list, tuple))) and (index_set.cardinality() == infinity)): from sage.algebras.lie_algebras.abelian import InfiniteDimensionalAbelianLieAlgebra return InfiniteDimensionalAbelianLieAlgebra(R, index_set=index_set) from sage.algebras.lie_algebras.abelian import AbelianLieAlgebra return AbelianLieAlgebra(R, names=names, index_set=index_set)
def Heisenberg(R, n, representation='structure'): '\n Return the rank ``n`` Heisenberg algebra in the given representation.\n\n INPUT:\n\n - ``R`` -- the base ring\n - ``n`` -- the rank (a nonnegative integer or infinity)\n - ``representation`` -- (default: "structure") can be one of the following:\n\n - ``"structure"`` -- using structure coefficients\n - ``"matrix"`` -- using matrices\n\n EXAMPLES::\n\n sage: lie_algebras.Heisenberg(QQ, 3)\n Heisenberg algebra of rank 3 over Rational Field\n ' from sage.rings.infinity import infinity if (n == infinity): from sage.algebras.lie_algebras.heisenberg import InfiniteHeisenbergAlgebra return InfiniteHeisenbergAlgebra(R) if (representation == 'matrix'): from sage.algebras.lie_algebras.heisenberg import HeisenbergAlgebra_matrix return HeisenbergAlgebra_matrix(R, n) from sage.algebras.lie_algebras.heisenberg import HeisenbergAlgebra return HeisenbergAlgebra(R, n)
def regular_vector_fields(R): '\n Return the Lie algebra of regular vector fields on `\\CC^{\\times}`.\n\n This is also known as the Witt (Lie) algebra.\n\n .. SEEALSO::\n\n :class:`~sage.algebras.lie_algebras.virasoro.LieAlgebraRegularVectorFields`\n\n EXAMPLES::\n\n sage: lie_algebras.regular_vector_fields(QQ)\n The Lie algebra of regular vector fields over Rational Field\n ' from sage.algebras.lie_algebras.virasoro import LieAlgebraRegularVectorFields return LieAlgebraRegularVectorFields(R)
def pwitt(R, p): '\n Return the `p`-Witt Lie algebra over `R`.\n\n INPUT:\n\n - ``R`` -- the base ring\n - ``p`` -- a positive integer that is `0` in ``R``\n\n EXAMPLES::\n\n sage: lie_algebras.pwitt(GF(5), 5)\n The 5-Witt Lie algebra over Finite Field of size 5\n ' from sage.algebras.lie_algebras.virasoro import WittLieAlgebra_charp return WittLieAlgebra_charp(R, p)