code
stringlengths
17
6.64M
def _unpickle_generic_element(parent, data): "\n Used to unpickle an element of ``parent`` using ``data``.\n\n EXAMPLES::\n\n sage: Q = QuantumGroup(['D',4])\n sage: x = Q.an_element()\n sage: loads(dumps(x)) == x # indirect doctest\n True\n " F = libgap.eval('ElementsFamily')(libgap.eval('FamilyObj')(parent._libgap)) ret = [] one = parent._libgap_base.One() for i in range((len(data) // 2)): ret.append(libgap(data[(2 * i)])) ret.append((one * libgap(data[((2 * i) + 1)].subs(q=parent._libgap_q)))) return parent.element_class(parent, F.ObjByExtRep(ret))
class QuantumGroupRepresentation(CombinatorialFreeModule): '\n A representation of a quantum group whose basis is indexed\n by the corresponding (combinatorial) crystal.\n\n INPUT:\n\n - ``C`` -- the crystal corresponding to the representation\n - ``R`` -- the base ring\n - ``q`` -- (default: the generator of ``R``) the parameter `q`\n of the quantum group\n ' @staticmethod def __classcall__(cls, R, C, q=None): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation\n sage: C = crystals.Tableaux(['A',3], shape=[1,1])\n sage: R = ZZ['q'].fraction_field()\n sage: V1 = MinusculeRepresentation(R, C)\n sage: V2 = MinusculeRepresentation(R, C, R.gen())\n sage: V1 is V2\n True\n " if (q is None): q = R.gen() return super().__classcall__(cls, R, C, q) def __init__(self, R, C, q): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation\n sage: C = crystals.Tableaux(['A',3], shape=[1,1])\n sage: R = ZZ['q'].fraction_field()\n sage: V = MinusculeRepresentation(R, C)\n sage: TestSuite(V).run()\n " self._q = q self._d = C.cartan_type().symmetrizer() cat = QuantumGroupRepresentations(R).WithBasis() if (C in Crystals().Finite()): cat = cat.FiniteDimensional() CombinatorialFreeModule.__init__(self, R, C, category=cat) def cartan_type(self): "\n Return the Cartan type of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation\n sage: C = crystals.Tableaux(['C',3], shape=[1])\n sage: R = ZZ['q'].fraction_field()\n sage: V = AdjointRepresentation(R, C)\n sage: V.cartan_type()\n ['C', 3]\n " return self.basis().keys().cartan_type() def K_on_basis(self, i, b, power=1): "\n Return the action of `K_i` on the basis element indexed by ``b``\n to the power ``power``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n - ``b`` -- an element of basis keys\n - ``power`` -- (default: 1) the power of `K_i`\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation\n sage: C = crystals.Tableaux(['A',3], shape=[1,1])\n sage: R = ZZ['q'].fraction_field()\n sage: V = MinusculeRepresentation(R, C)\n sage: [[V.K_on_basis(i, b) for i in V.index_set()] for b in C]\n [[B[[[1], [2]]], q*B[[[1], [2]]], B[[[1], [2]]]],\n [q*B[[[1], [3]]], 1/q*B[[[1], [3]]], q*B[[[1], [3]]]],\n [1/q*B[[[2], [3]]], B[[[2], [3]]], q*B[[[2], [3]]]],\n [q*B[[[1], [4]]], B[[[1], [4]]], 1/q*B[[[1], [4]]]],\n [1/q*B[[[2], [4]]], q*B[[[2], [4]]], 1/q*B[[[2], [4]]]],\n [B[[[3], [4]]], 1/q*B[[[3], [4]]], B[[[3], [4]]]]]\n sage: [[V.K_on_basis(i, b, -1) for i in V.index_set()] for b in C]\n [[B[[[1], [2]]], 1/q*B[[[1], [2]]], B[[[1], [2]]]],\n [1/q*B[[[1], [3]]], q*B[[[1], [3]]], 1/q*B[[[1], [3]]]],\n [q*B[[[2], [3]]], B[[[2], [3]]], 1/q*B[[[2], [3]]]],\n [1/q*B[[[1], [4]]], B[[[1], [4]]], q*B[[[1], [4]]]],\n [q*B[[[2], [4]]], 1/q*B[[[2], [4]]], q*B[[[2], [4]]]],\n [B[[[3], [4]]], q*B[[[3], [4]]], B[[[3], [4]]]]]\n " WLR = self.basis().keys().weight_lattice_realization() alc = WLR.simple_coroots() return self.term(b, (self._q ** ((b.weight().scalar(alc[i]) * self._d[i]) * power)))
class CyclicRepresentation(QuantumGroupRepresentation): '\n A cyclic quantum group representation that is indexed by either a\n highest weight crystal or Kirillov-Reshetikhin crystal.\n\n The crystal ``C`` must either allow ``C.module_generator()``,\n otherwise it is assumed to be generated by ``C.module_generators[0]``.\n\n This is meant as an abstract base class for\n :class:`~sage.algebras.quantum_groups.representation.AdjointRepresentation`\n and\n :class:`~sage.algebras.quantum_groups.representation.MinusculeRepresentation`.\n ' def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation\n sage: C = crystals.Tableaux(['C',3], shape=[1])\n sage: R = ZZ['q'].fraction_field()\n sage: AdjointRepresentation(R, C)\n V((1, 0, 0))\n " try: mg = self.basis().keys().module_generator() except (TypeError, AttributeError): mg = self.basis().keys().module_generators[0] return 'V({})'.format(mg.weight()) def _latex_(self): "\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation\n sage: C = crystals.Tableaux(['G',2], shape=[1])\n sage: R = ZZ['q'].fraction_field()\n sage: V = AdjointRepresentation(R, C)\n sage: latex(V)\n V\\left( e_{0} - e_{2} \\right)\n\n sage: La = RootSystem(['E',7,1]).weight_space().fundamental_weights()\n sage: K = crystals.ProjectedLevelZeroLSPaths(La[1])\n sage: A = AdjointRepresentation(R, K)\n sage: latex(A)\n V\\left( -2 \\Lambda_{0} + \\Lambda_{1} \\right)\n " try: mg = self.basis().keys().module_generator() except (TypeError, AttributeError): mg = self.basis().keys().module_generators[0] from sage.misc.latex import latex return 'V\\left( {} \\right)'.format(latex(mg.weight())) @cached_method def module_generator(self): "\n Return the module generator of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation\n sage: C = crystals.Tableaux(['G',2], shape=[1,1])\n sage: R = ZZ['q'].fraction_field()\n sage: V = AdjointRepresentation(R, C)\n sage: V.module_generator()\n B[[[1], [2]]]\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2], 1,1)\n sage: A = AdjointRepresentation(R, K)\n sage: A.module_generator()\n B[[[1]]]\n " try: mg = self.basis().keys().module_generator() except (TypeError, AttributeError): mg = self.basis().keys().module_generators[0] return self.monomial(mg)
class AdjointRepresentation(CyclicRepresentation): "\n An (generalized) adjoint representation of a quantum group.\n\n We define an *(generalized) adjoint representation* `V` of a\n quantum group `U_q` to be a cyclic `U_q`-module with a weight\n space decomposition `V = \\bigoplus_{\\mu} V_{\\mu}` such that\n `\\dim V_{\\mu} \\leq 1` unless `\\mu = 0`. Moreover, we require\n that there exists a basis `\\{y_j | j \\in J\\}` for `V_0` such\n that `e_i y_j = 0` for all `j \\neq i \\in I`.\n\n For a base ring `R`, we construct an adjoint representation from\n its (combinatorial) crystal `B` by `V = R \\{v_b | b \\in B\\}` with\n\n .. MATH::\n\n \\begin{aligned}\n e_i v_b & = \\begin{cases}\n v_{e_i b} / [\\varphi_i(e_i b)]_{q_i},\n & \\text{if } \\operatorname{wt}(b) \\neq 0, \\\\\n v_{e_i b} + \\sum_{j \\neq i} [-A_{ij}]_{q_i} / [2]_{q_i} v_{y_j}\n & \\text{otherwise}\n \\end{cases} \\\\\n f_i v_b & = \\begin{cases}\n v_{f_i b} / [\\varepsilon_i(f_i b)]_{q_i},\n & \\text{if } \\operatorname{wt}(b) \\neq 0, \\\\\n v_{f_i b} + \\sum_{j \\neq i} [-A_{ij}]_{q_i} / [2]_{q_i} v_{y_j}\n & \\text{otherwise}\n \\end{cases} \\\\\n K_i v_b & = q^{\\langle h_i, \\operatorname{wt}(b) \\rangle} v_b,\n \\end{aligned}\n\n where `(A_{ij})_{i,j \\in I}` is the Cartan matrix, and we\n consider `v_0 := 0`.\n\n INPUT:\n\n - ``C`` -- the crystal corresponding to the representation\n - ``R`` -- the base ring\n - ``q`` -- (default: the generator of ``R``) the parameter `q`\n of the quantum group\n\n .. WARNING::\n\n This assumes that `q` is generic.\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation\n sage: R = ZZ['q'].fraction_field()\n sage: C = crystals.Tableaux(['D',4], shape=[1,1])\n sage: V = AdjointRepresentation(R, C)\n sage: V\n V((1, 1, 0, 0))\n sage: v = V.an_element(); v\n 2*B[[[1], [2]]] + 2*B[[[1], [3]]] + 3*B[[[2], [3]]]\n sage: v.e(2)\n 2*B[[[1], [2]]]\n sage: v.f(2)\n 2*B[[[1], [3]]]\n sage: v.f(4)\n 2*B[[[1], [-4]]] + 3*B[[[2], [-4]]]\n sage: v.K(3)\n 2*B[[[1], [2]]] + 2*q*B[[[1], [3]]] + 3*q*B[[[2], [3]]]\n sage: v.K(2,-2)\n 2/q^2*B[[[1], [2]]] + 2*q^2*B[[[1], [3]]] + 3*B[[[2], [3]]]\n\n sage: La = RootSystem(['F',4,1]).weight_space().fundamental_weights()\n sage: K = crystals.ProjectedLevelZeroLSPaths(La[4])\n sage: A = AdjointRepresentation(R, K)\n sage: A\n V(-Lambda[0] + Lambda[4])\n\n Sort the summands uniformly in Python 2 and Python 3::\n\n sage: A.print_options(sorting_key=lambda x: str(x))\n sage: v = A.an_element(); v\n 2*B[(-Lambda[0] + Lambda[3] - Lambda[4],)]\n + 2*B[(-Lambda[0] + Lambda[4],)]\n + 3*B[(Lambda[0] - Lambda[1] + Lambda[4],)]\n sage: v.e(0)\n 2*B[(Lambda[0] - Lambda[1] + Lambda[3] - Lambda[4],)]\n + 2*B[(Lambda[0] - Lambda[1] + Lambda[4],)]\n sage: v.f(0)\n 3*B[(-Lambda[0] + Lambda[4],)]\n\n REFERENCES:\n\n - [OS2018]_\n " def __init__(self, R, C, q): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation\n sage: C = crystals.Tableaux(['B',3], shape=[1,1])\n sage: R = ZZ['q'].fraction_field()\n sage: V = AdjointRepresentation(R, C)\n sage: TestSuite(V).run()\n\n sage: A = crystals.Tableaux(['A',2], shape=[2,1])\n sage: VA = AdjointRepresentation(R, A)\n sage: TestSuite(VA).run()\n\n sage: K1 = crystals.KirillovReshetikhin(['C',3,1], 1,1)\n sage: A1 = AdjointRepresentation(R, K1)\n sage: TestSuite(A1).run()\n sage: K2 = crystals.KirillovReshetikhin(['C',2,1], 1,2)\n sage: A2 = AdjointRepresentation(R, K2)\n sage: TestSuite(A2).run()\n " self._WLR_zero = C.weight_lattice_realization().zero() CyclicRepresentation.__init__(self, R, C, q) ct = C.cartan_type() if (ct.is_finite() and (ct.type() == 'A')): def test_zero(x): wt = x.weight() return all(((wt.scalar(ac) == 0) for ac in self._WLR_zero.parent().simple_coroots())) self._check_zero_wt = test_zero else: self._check_zero_wt = (lambda x: (x.weight() == self._WLR_zero)) @lazy_attribute def _zero_elts(self): "\n Find all of the elements of weight `0` in the basis keys.\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation\n sage: K = crystals.KirillovReshetikhin(['D',4,1], 2,1)\n sage: R = ZZ['q'].fraction_field()\n sage: V = AdjointRepresentation(R, K)\n sage: V._zero_elts\n {0: [], 1: [[2], [-2]], 2: [[3], [-3]],\n 3: [[4], [-4]], 4: [[-4], [4]]}\n " C = self.basis().keys() ret = {} for x in C: if self._check_zero_wt(x): for i in C.index_set(): if (x.epsilon(i) > 0): ret[i] = x break return ret def e_on_basis(self, i, b): "\n Return the action of `e_i` on the basis element indexed by ``b``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n - ``b`` -- an element of basis keys\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation\n sage: K = crystals.KirillovReshetikhin(['D',3,2], 1,1)\n sage: R = ZZ['q'].fraction_field()\n sage: V = AdjointRepresentation(R, K)\n sage: mg0 = K.module_generators[0]; mg0\n []\n sage: mg1 = K.module_generators[1]; mg1\n [[1]]\n sage: V.e_on_basis(0, mg0)\n ((q^2+1)/q)*B[[[-1]]]\n sage: V.e_on_basis(0, mg1)\n B[[]]\n sage: V.e_on_basis(1, mg0)\n 0\n sage: V.e_on_basis(1, mg1)\n 0\n sage: V.e_on_basis(2, mg0)\n 0\n sage: V.e_on_basis(2, mg1)\n 0\n\n sage: K = crystals.KirillovReshetikhin(['D',4,3], 1,1)\n sage: V = AdjointRepresentation(R, K)\n sage: V.e_on_basis(0, K.module_generator())\n B[[]] + (q/(q^2+1))*B[[[0]]]\n " C = self.basis().keys() x = b.e(i) if (x is None): return self.zero() I = {j: pos for (pos, j) in enumerate(C.index_set())} if self._check_zero_wt(x): A = C.cartan_type().cartan_matrix() return (self.monomial(x) + sum((self.term(self._zero_elts[j], (q_int((- A[(I[i], I[j])]), (self._q ** self._d[i])) / q_int(2, (self._q ** self._d[j])))) for j in C.index_set() if ((A[(I[i], I[j])] < 0) and (j in self._zero_elts))))) return self.term(x, q_int(x.phi(i), (self._q ** self._d[i]))) def f_on_basis(self, i, b): "\n Return the action of `f_i` on the basis element indexed by ``b``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n - ``b`` -- an element of basis keys\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import AdjointRepresentation\n sage: K = crystals.KirillovReshetikhin(['D',3,2], 1,1)\n sage: R = ZZ['q'].fraction_field()\n sage: V = AdjointRepresentation(R, K)\n sage: mg0 = K.module_generators[0]; mg0\n []\n sage: mg1 = K.module_generators[1]; mg1\n [[1]]\n sage: V.f_on_basis(0, mg0)\n ((q^2+1)/q)*B[[[1]]]\n sage: V.f_on_basis(0, mg1)\n 0\n sage: V.f_on_basis(1, mg0)\n 0\n sage: V.f_on_basis(1, mg1)\n B[[[2]]]\n sage: V.f_on_basis(2, mg0)\n 0\n sage: V.f_on_basis(2, mg1)\n 0\n\n sage: K = crystals.KirillovReshetikhin(['D',4,3], 1,1)\n sage: V = AdjointRepresentation(R, K)\n sage: lw = K.module_generator().to_lowest_weight([1,2])[0]\n sage: V.f_on_basis(0, lw)\n B[[]] + (q/(q^2+1))*B[[[0]]]\n " C = self.basis().keys() x = b.f(i) if (x is None): return self.zero() I = {j: pos for (pos, j) in enumerate(C.index_set())} if self._check_zero_wt(x): A = C.cartan_type().cartan_matrix() return (self.monomial(x) + sum((self.term(self._zero_elts[j], (q_int((- A[(I[i], I[j])]), (self._q ** self._d[i])) / q_int(2, (self._q ** self._d[j])))) for j in C.index_set() if ((A[(I[i], I[j])] < 0) and (j in self._zero_elts))))) return self.term(x, q_int(x.epsilon(i), (self._q ** self._d[i])))
class MinusculeRepresentation(CyclicRepresentation): "\n A minuscule representation of a quantum group.\n\n A quantum group representation `V` is *minuscule* if it is\n cyclic, there is a weight space decomposition\n `V = \\bigoplus_{\\mu} V_{\\mu}` with `\\dim V_{\\mu} \\leq 1`,\n and `e_i^2 V = 0` and `f_i^2 V = 0`.\n\n For a base ring `R`, we construct a minuscule representation from\n its (combinatorial) crystal `B` by `V = R \\{v_b | b \\in B\\}` with\n `e_i v_b = v_{e_i b}`, `f_i v_b = v_{f_i b}`, and\n `K_i v_b = q^{\\langle h_i, \\operatorname{wt}(b) \\rangle} v_b`,\n where we consider `v_0 := 0`.\n\n INPUT:\n\n - ``C`` -- the crystal corresponding to the representation\n - ``R`` -- the base ring\n - ``q`` -- (default: the generator of ``R``) the parameter `q`\n of the quantum group\n\n .. WARNING::\n\n This assumes that `q` is generic.\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation\n sage: R = ZZ['q'].fraction_field()\n sage: C = crystals.Tableaux(['B',3], shape=[1/2,1/2,1/2])\n sage: V = MinusculeRepresentation(R, C)\n sage: V\n V((1/2, 1/2, 1/2))\n sage: v = V.an_element(); v\n 2*B[[+++, []]] + 2*B[[++-, []]] + 3*B[[+-+, []]]\n sage: v.e(3)\n 2*B[[+++, []]]\n sage: v.f(1)\n 3*B[[-++, []]]\n sage: v.f(3)\n 2*B[[++-, []]] + 3*B[[+--, []]]\n sage: v.K(2)\n 2*B[[+++, []]] + 2*q^2*B[[++-, []]] + 3/q^2*B[[+-+, []]]\n sage: v.K(3, -2)\n 2/q^2*B[[+++, []]] + 2*q^2*B[[++-, []]] + 3/q^2*B[[+-+, []]]\n\n sage: K = crystals.KirillovReshetikhin(['D',4,2], 3,1)\n sage: A = MinusculeRepresentation(R, K)\n sage: A\n V(-Lambda[0] + Lambda[3])\n sage: v = A.an_element(); v\n 2*B[[+++, []]] + 2*B[[++-, []]] + 3*B[[+-+, []]]\n sage: v.f(0)\n 0\n sage: v.e(0)\n 2*B[[-++, []]] + 2*B[[-+-, []]] + 3*B[[--+, []]]\n\n REFERENCES:\n\n - [OS2018]_\n " def e_on_basis(self, i, b): "\n Return the action of `e_i` on the basis element indexed by ``b``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n - ``b`` -- an element of basis keys\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation\n sage: C = crystals.Tableaux(['A',3], shape=[1,1])\n sage: R = ZZ['q'].fraction_field()\n sage: V = MinusculeRepresentation(R, C)\n sage: lw = C.lowest_weight_vectors()[0]\n sage: V.e_on_basis(1, lw)\n 0\n sage: V.e_on_basis(2, lw)\n B[[[2], [4]]]\n sage: V.e_on_basis(3, lw)\n 0\n sage: hw = C.highest_weight_vectors()[0]\n sage: all(V.e_on_basis(i, hw) == V.zero() for i in V.index_set())\n True\n " x = b.e(i) if (x is None): return self.zero() return self.monomial(x) def f_on_basis(self, i, b): "\n Return the action of `f_i` on the basis element indexed by ``b``.\n\n INPUT:\n\n - ``i`` -- an element of the index set\n - ``b`` -- an element of basis keys\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_groups.representations import MinusculeRepresentation\n sage: C = crystals.Tableaux(['A',3], shape=[1,1])\n sage: R = ZZ['q'].fraction_field()\n sage: V = MinusculeRepresentation(R, C)\n sage: hw = C.highest_weight_vectors()[0]\n sage: V.f_on_basis(1, hw)\n 0\n sage: V.f_on_basis(2, hw)\n B[[[1], [3]]]\n sage: V.f_on_basis(3, hw)\n 0\n sage: lw = C.lowest_weight_vectors()[0]\n sage: all(V.f_on_basis(i, lw) == V.zero() for i in V.index_set())\n True\n " x = b.f(i) if (x is None): return self.zero() return self.monomial(x)
class QuantumMatrixCoordinateAlgebra_abstract(CombinatorialFreeModule): '\n Abstract base class for quantum coordinate algebras of a set\n of matrices.\n ' @staticmethod def __classcall__(cls, q=None, bar=None, R=None, **kwds): '\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: O1 = algebras.QuantumMatrixCoordinate(4)\n sage: O2 = algebras.QuantumMatrixCoordinate(4, 4, q=q)\n sage: O3 = algebras.QuantumMatrixCoordinate(4, R=ZZ)\n sage: O4 = algebras.QuantumMatrixCoordinate(4, R=R, q=q)\n sage: O1 is O2 and O2 is O3 and O3 is O4\n True\n sage: O5 = algebras.QuantumMatrixCoordinate(4, R=QQ)\n sage: O1 is O5\n False\n ' if (R is None): R = ZZ elif (q is not None): q = R(q) if (q is None): q = LaurentPolynomialRing(R, 'q').gen() return super().__classcall__(cls, q=q, bar=bar, R=q.parent(), **kwds) def __init__(self, gp_indices, n, q, bar, R, category, indices_key=None): '\n Initialize ``self``.\n\n TESTS::\n\n sage: O = algebras.QuantumMatrixCoordinate(3, 2)\n sage: TestSuite(O).run()\n ' self._n = n self._q = q if (bar is None): def bar(x): return x.subs(q=(~ self._q)) self._bar = bar if (indices_key is None): indices = IndexedFreeAbelianMonoid(gp_indices) else: indices = IndexedFreeAbelianMonoid(gp_indices, sorting_key=indices_key) CombinatorialFreeModule.__init__(self, R, indices, category=category) def _repr_term(self, m): "\n Return a string representation of the term indexed by ``m``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: I = O.indices()\n sage: x = I.an_element(); x\n F[(1, 1)]^2*F[(1, 2)]^2*F[(1, 3)]^3\n sage: O._repr_term(x)\n 'x[1,1]^2*x[1,2]^2*x[1,3]^3'\n sage: O._repr_term(I.one())\n '1'\n sage: O.q() * O.one()\n q\n " S = m._sorted_items() if (not S): return '1' def exp(e): return ('^{}'.format(e) if (e > 1) else '') return '*'.join(((('x[{},{}]'.format(*k) if (k != 'c') else 'c') + exp(e)) for (k, e) in m._sorted_items())) def _latex_term(self, m): "\n Return a latex representation of the term indexed by ``m``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: I = O.indices()\n sage: x = I.an_element(); x\n F[(1, 1)]^2*F[(1, 2)]^2*F[(1, 3)]^3\n sage: O._latex_term(x)\n 'x_{1,1}^{2} x_{1,2}^{2} x_{1,3}^{3}'\n sage: O._latex_term(I.one())\n '1'\n sage: latex(O.q() * O.one())\n q\n " S = m._sorted_items() if (not S): return '1' def exp(e): return ('^{{{}}}'.format(e) if (e > 1) else '') return ' '.join(((('x_{{{},{}}}'.format(*k) if (k != 'c') else 'c') + exp(e)) for (k, e) in m._sorted_items())) def n(self): '\n Return the value `n`.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: O.n()\n 4\n sage: O = algebras.QuantumMatrixCoordinate(4, 6)\n sage: O.n()\n 6\n ' return self._n def q(self): '\n Return the variable ``q``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: O.q()\n q\n sage: O.q().parent()\n Univariate Laurent Polynomial Ring in q over Integer Ring\n sage: O.q().parent() is O.base_ring()\n True\n ' return self._q @cached_method def one_basis(self): '\n Return the basis element indexing `1`.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: O.one_basis()\n 1\n sage: O.one()\n 1\n\n TESTS::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: O.one_basis() == O.indices().one()\n True\n ' return self._indices.one() @cached_method def gens(self): '\n Return the generators of ``self`` as a tuple.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(3)\n sage: O.gens()\n (x[1,1], x[1,2], x[1,3],\n x[2,1], x[2,2], x[2,3],\n x[3,1], x[3,2], x[3,3])\n ' return tuple(self.algebra_generators()) @cached_method def quantum_determinant(self): '\n Return the quantum determinant of ``self``.\n\n The quantum determinant is defined by\n\n .. MATH::\n\n \\det_q = \\sum_{\\sigma \\in S_n} (-q)^{\\ell(\\sigma)}\n x_{1, \\sigma(1)} x_{2, \\sigma(2)} \\cdots x_{n, \\sigma(n)}.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(2)\n sage: O.quantum_determinant()\n x[1,1]*x[2,2] - q*x[1,2]*x[2,1]\n\n We verify that the quantum determinant is central::\n\n sage: for n in range(2,5):\n ....: O = algebras.QuantumMatrixCoordinate(n)\n ....: qdet = O.quantum_determinant()\n ....: assert all(g * qdet == qdet * g for g in O.algebra_generators())\n\n We also verify that it is group-like::\n\n sage: for n in range(2,4):\n ....: O = algebras.QuantumMatrixCoordinate(n)\n ....: qdet = O.quantum_determinant()\n ....: assert qdet.coproduct() == tensor([qdet, qdet])\n ' if (hasattr(self, '_m') and (self._m != self._n)): raise ValueError('undefined for non-square quantum matrices') from sage.combinat.permutation import Permutations q = self._q return self._from_dict({self._indices({(i, p(i)): 1 for i in range(1, (self._n + 1))}): ((- q) ** p.length()) for p in Permutations(self._n)}) def product_on_basis(self, a, b): '\n Return the product of basis elements indexed by ``a`` and ``b``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: x = O.algebra_generators()\n sage: b = x[1,4] * x[2,1] * x[3,4] # indirect doctest\n sage: b * (b * b) == (b * b) * b\n True\n sage: p = prod(list(O.algebra_generators())[:10])\n sage: p * (p * p) == (p * p) * p # long time\n True\n sage: x = O.an_element()\n sage: y = x^2 + x[4,4] * x[3,3] * x[1,2]\n sage: z = x[2,2] * x[1,4] * x[3,4] * x[1,1]\n sage: x * (y * z) == (x * y) * z\n True\n ' al = a._sorted_items() bl = b._sorted_items() if (not al): return self.monomial(b) if (not bl): return self.monomial(a) if (al[(- 1)][0] < bl[0][0]): return self.monomial((a * b)) G = self._indices.monoid_generators() one = self.base_ring().one() q = self._q qi = (q ** (- 1)) monomial = b coeff = one for pos in range((len(al) - 1), (- 1), (- 1)): (ax, ae) = al[pos] for (bx, be) in bl: if (ax[0] < bx[0]): break elif (ax[0] == bx[0]): if (ax[1] > bx[1]): coeff *= (qi ** (ae * be)) else: break elif (ax[1] == bx[1]): coeff *= (qi ** (ae * be)) elif (ax[1] > bx[1]): m1 = ((G[bx] ** be) * G[ax]) m2 = (((G[bx] ** (be - 1)) * G[(bx[0], ax[1])]) * G[(ax[0], bx[1])]) ret = self._from_dict({m1: one, m2: ((q ** (1 - (2 * be))) - q)}) ml = monomial._sorted_items() index = ml.index((bx, be)) a_key = self._indices(dict(al[:pos])) bp_key = (self._indices(dict(ml[:index])) * (G[ax] ** (ae - 1))) return (((self.monomial(a_key) * self.monomial(bp_key)) * ret) * self.term(self._indices(dict(ml[(index + 1):])), coeff)) monomial *= (G[ax] ** ae) return self.term(monomial, coeff) @cached_method def _bar_on_basis(self, x): '\n Return the bar involution on the basis element indexed by ``x``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: O._bar_on_basis(O._indices.an_element())\n (q^-16)*x[1,1]^2*x[1,2]^2*x[1,3]^3\n ' ret = self.one() for (k, e) in reversed(x._sorted_items()): ret *= self.monomial(self._indices({k: e})) return ret def counit_on_basis(self, x): '\n Return the counit on the basis element indexed by ``x``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: G = O.algebra_generators()\n sage: I = [1,2,3,4]\n sage: matrix([[G[i,j].counit() for i in I] for j in I]) # indirect doctest\n [1 0 0 0]\n [0 1 0 0]\n [0 0 1 0]\n [0 0 0 1]\n ' if all((((t == 'c') or (t[0] == t[1])) for (t, e) in x._sorted_items())): return self.base_ring().one() else: return self.base_ring().zero() class Element(CombinatorialFreeModule.Element): '\n An element of a quantum matrix coordinate algebra.\n ' def bar(self): '\n Return the image of ``self`` under the bar involution.\n\n The bar involution is the `\\QQ`-algebra anti-automorphism\n defined by `x_{ij} \\mapsto x_{ji}` and `q \\mapsto q^{-1}`.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: x = O.an_element()\n sage: x.bar()\n 1 + 2*x[1,1] + (q^-16)*x[1,1]^2*x[1,2]^2*x[1,3]^3 + 3*x[1,2]\n sage: x = O.an_element() * O.algebra_generators()[2,4]; x\n x[1,1]^2*x[1,2]^2*x[1,3]^3*x[2,4] + 2*x[1,1]*x[2,4]\n + 3*x[1,2]*x[2,4] + x[2,4]\n sage: xb = x.bar(); xb\n (q^-16)*x[1,1]^2*x[1,2]^2*x[1,3]^3*x[2,4]\n + (q^-21-q^-15)*x[1,1]^2*x[1,2]^2*x[1,3]^2*x[1,4]*x[2,3]\n + (q^-22-q^-18)*x[1,1]^2*x[1,2]*x[1,3]^3*x[1,4]*x[2,2]\n + (q^-24-q^-20)*x[1,1]*x[1,2]^2*x[1,3]^3*x[1,4]*x[2,1]\n + 2*x[1,1]*x[2,4] + 3*x[1,2]*x[2,4]\n + (2*q^-1-2*q)*x[1,4]*x[2,1]\n + (3*q^-1-3*q)*x[1,4]*x[2,2] + x[2,4]\n sage: xb.bar() == x\n True\n ' P = self.parent() return P.sum(((P._bar(c) * P._bar_on_basis(m)) for (m, c) in self))
class QuantumMatrixCoordinateAlgebra(QuantumMatrixCoordinateAlgebra_abstract): '\n A quantum matrix coordinate algebra.\n\n Let `R` be a commutative ring. The quantum matrix coordinate algebra\n of `M(m, n)` is the associative algebra over `R[q, q^{-1}]`\n generated by `x_{ij}`, for `i = 1, 2, \\ldots, m`, `j = 1, 2, \\ldots, n`,\n and subject to the following relations:\n\n .. MATH::\n\n \\begin{array}{ll}\n x_{it} x_{ij} = q^{-1} x_{ij} x_{it} & \\text{if } j < t, \\\\\n x_{sj} x_{ij} = q^{-1} x_{ij} x_{sj} & \\text{if } i < s, \\\\\n x_{st} x_{ij} = x_{ij} x_{st} & \\text{if } i < s, j > t, \\\\\n x_{st} x_{ij} = x_{ij} x_{st} + (q^{-1} - q) x_{it} x_{sj}\n & \\text{if } i < s, j < t. \\\\\n \\end{array}\n\n The quantum matrix coordinate algebra is denoted by\n `\\mathcal{O}_q(M(m, n))`. For `m = n`, it is also a bialgebra given by\n\n .. MATH::\n\n \\Delta(x_{ij}) = \\sum_{k=1}^n x_{ik} \\otimes x_{kj},\n \\varepsilon(x_{ij}) = \\delta_{ij}.\n\n Moreover, there is a central group-like element called the\n *quantum determinant* that is defined by\n\n .. MATH::\n\n \\det_q = \\sum_{\\sigma \\in S_n} (-q)^{\\ell(\\sigma)}\n x_{1,\\sigma(1)} x_{2,\\sigma(2)} \\cdots x_{n,\\sigma(n)}.\n\n The quantum matrix coordinate algebra also has natural inclusions\n when restricting to submatrices. That is, let\n `I \\subseteq \\{1, 2, \\ldots, m\\}` and `J \\subseteq \\{1, 2, \\ldots, n\\}`.\n Then the subalgebra generated by `\\{ x_{ij} \\mid i \\in I, j \\in J \\}`\n is naturally isomorphic to `\\mathcal{O}_q(M(|I|, |J|))`.\n\n .. NOTE::\n\n The `q` considered here is `q^2` in some references, e.g., [ZZ2005]_.\n\n INPUT:\n\n - ``m`` -- the integer `m`\n - ``n`` -- the integer `n`\n - ``R`` -- (optional) the ring `R` if `q` is not specified\n (the default is `\\ZZ`); otherwise the ring containing `q`\n - ``q`` -- (optional) the variable `q`; the default is\n `q \\in R[q, q^{-1}]`\n - ``bar`` -- (optional) the involution on the base ring; the\n default is `q \\mapsto q^{-1}`\n\n EXAMPLES:\n\n We construct `\\mathcal{O}_q(M(2,3))` and the variables::\n\n sage: O = algebras.QuantumMatrixCoordinate(2,3)\n sage: O.inject_variables()\n Defining x11, x12, x13, x21, x22, x23\n\n We do some basic computations::\n\n sage: x21 * x11\n (q^-1)*x[1,1]*x[2,1]\n sage: x23 * x12 * x11\n (q^-1)*x[1,1]*x[1,2]*x[2,3] + (q^-2-1)*x[1,1]*x[1,3]*x[2,2]\n + (q^-3-q^-1)*x[1,2]*x[1,3]*x[2,1]\n\n We construct the maximal quantum minors::\n\n sage: q = O.q()\n sage: qm12 = x11*x22 - q*x12*x21\n sage: qm13 = x11*x23 - q*x13*x21\n sage: qm23 = x12*x23 - q*x13*x22\n\n However, unlike for the quantum determinant, they are not central::\n\n sage: all(qm12 * g == g * qm12 for g in O.algebra_generators())\n False\n sage: all(qm13 * g == g * qm13 for g in O.algebra_generators())\n False\n sage: all(qm23 * g == g * qm23 for g in O.algebra_generators())\n False\n\n REFERENCES:\n\n - [FRT1990]_\n - [ZZ2005]_\n ' @staticmethod def __classcall_private__(cls, m, n=None, q=None, bar=None, R=None): '\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: O1 = algebras.QuantumMatrixCoordinate(4)\n sage: O2 = algebras.QuantumMatrixCoordinate(4, 4, q=q)\n sage: O3 = algebras.QuantumMatrixCoordinate(4, R=ZZ)\n sage: O4 = algebras.QuantumMatrixCoordinate(4, R=R, q=q)\n sage: O1 is O2 and O2 is O3 and O3 is O4\n True\n sage: O5 = algebras.QuantumMatrixCoordinate(4, R=QQ)\n sage: O1 is O5\n False\n ' if (n is None): n = m return super().__classcall__(cls, m=m, n=n, q=q, bar=bar, R=R) def __init__(self, m, n, q, bar, R): "\n Initialize ``self``.\n\n TESTS::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: TestSuite(O).run()\n\n sage: O = algebras.QuantumMatrixCoordinate(10)\n sage: O.variable_names()\n ('x0101', ..., 'x1010')\n sage: O = algebras.QuantumMatrixCoordinate(11,3)\n sage: O.variable_names()\n ('x011', ..., 'x113')\n sage: O = algebras.QuantumMatrixCoordinate(3,11)\n sage: O.variable_names()\n ('x101', ..., 'x311')\n " gp_indices = [(i, j) for i in range(1, (m + 1)) for j in range(1, (n + 1))] if (m == n): cat = Bialgebras(R.category()).WithBasis() else: cat = Algebras(R.category()).WithBasis() self._m = m QuantumMatrixCoordinateAlgebra_abstract.__init__(self, gp_indices, n, q, bar, R, cat) mb = len(str(m)) nb = len(str(n)) base = 'x{{:0>{}}}{{:0>{}}}'.format(mb, nb) names = [base.format(*k) for k in gp_indices] self._assign_names(names) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: algebras.QuantumMatrixCoordinate(4)\n Quantized coordinate algebra of M(4, 4) with q=q over\n Univariate Laurent Polynomial Ring in q over Integer Ring\n\n sage: algebras.QuantumMatrixCoordinate(4, 2)\n Quantized coordinate algebra of M(4, 2) with q=q over\n Univariate Laurent Polynomial Ring in q over Integer Ring\n ' txt = 'Quantized coordinate algebra of M({}, {}) with q={} over {}' return txt.format(self._m, self._n, self._q, self.base_ring()) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: latex(O)\n \\mathcal{O}_{q}(M(4, 4))\n ' return ('\\mathcal{O}_{%s}(M(%s, %s))' % (self._q, self._m, self._n)) def m(self): '\n Return the value `m`.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4, 6)\n sage: O.m()\n 4\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: O.m()\n 4\n ' return self._m @cached_method def algebra_generators(self): '\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(2)\n sage: O.algebra_generators()\n Finite family {(1, 1): x[1,1], (1, 2): x[1,2], (2, 1): x[2,1], (2, 2): x[2,2]}\n ' l = [(i, j) for i in range(1, (self._m + 1)) for j in range(1, (self._n + 1))] G = self._indices.monoid_generators() one = self.base_ring().one() return Family(l, (lambda x: self.element_class(self, {G[x]: one}))) def coproduct_on_basis(self, x): '\n Return the coproduct on the basis element indexed by ``x``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumMatrixCoordinate(4)\n sage: x24 = O.algebra_generators()[2,4]\n sage: O.coproduct_on_basis(x24.leading_support())\n x[2,1] # x[1,4] + x[2,2] # x[2,4] + x[2,3] # x[3,4] + x[2,4] # x[4,4]\n\n TESTS:\n\n We check that it is an algebra morphism::\n\n sage: O = algebras.QuantumMatrixCoordinate(3)\n sage: G = O.algebra_generators()\n sage: all(x.coproduct() * y.coproduct() == (x * y).coproduct()\n ....: for x in G for y in G)\n True\n ' if (self._m != self._n): raise ValueError('undefined for non-square quantum matrices') T = self.tensor_square() I = self._indices.monoid_generators() return T.prod(((T.sum_of_monomials(((I[(t[0], k)], I[(k, t[1])]) for k in range(1, (self._n + 1)))) ** e) for (t, e) in x._sorted_items()))
class QuantumGL(QuantumMatrixCoordinateAlgebra_abstract): '\n Quantum coordinate algebra of `GL(n)`.\n\n The quantum coordinate algebra of `GL(n)`, or quantum `GL(n)`\n for short and denoted by `\\mathcal{O}_q(GL(n))`, is the quantum\n coordinate algebra of `M_R(n, n)` with the addition of the\n additional central group-like element `c` which satisfies\n `c d = d c = 1`, where `d` is the quantum determinant.\n\n Quantum `GL(n)` is a Hopf algebra where `\\varepsilon(c) = 1`\n and the antipode `S` is given by the (quantum) matrix inverse.\n That is to say, we have `S(c) = c^-1 = d` and\n\n .. MATH::\n\n S(x_{ij}) = c * (-q)^{i-j} * \\tilde{t}_{ji},\n\n where we have the quantum minor\n\n .. MATH::\n\n \\tilde{t}_{ij} = \\sum_{\\sigma} (-q)^{\\ell(\\sigma)}\n x_{1, \\sigma(1)} \\cdots x_{i-1, \\sigma(i-1)} x_{i+1, \\sigma(i+1)}\n \\cdots x_{n, \\sigma(n)}\n\n with the sum over permutations `\\sigma \\colon \\{1, \\ldots, i-1, i+1,\n \\ldots n\\} \\to \\{1, \\ldots, j-1, j+1, \\ldots, n\\}`.\n\n .. SEEALSO::\n\n :class:`QuantumMatrixCoordinateAlgebra`\n\n INPUT:\n\n - ``n`` -- the integer `n`\n - ``R`` -- (optional) the ring `R` if `q` is not specified\n (the default is `\\ZZ`); otherwise the ring containing `q`\n - ``q`` -- (optional) the variable `q`; the default is\n `q \\in R[q, q^{-1}]`\n - ``bar`` -- (optional) the involution on the base ring; the\n default is `q \\mapsto q^{-1}`\n\n EXAMPLES:\n\n We construct `\\mathcal{O}_q(GL(3))` and the variables::\n\n sage: O = algebras.QuantumGL(3)\n sage: O.inject_variables()\n Defining x11, x12, x13, x21, x22, x23, x31, x32, x33, c\n\n We do some basic computations::\n\n sage: x33 * x12\n x[1,2]*x[3,3] + (q^-1-q)*x[1,3]*x[3,2]\n sage: x23 * x12 * x11\n (q^-1)*x[1,1]*x[1,2]*x[2,3] + (q^-2-1)*x[1,1]*x[1,3]*x[2,2]\n + (q^-3-q^-1)*x[1,2]*x[1,3]*x[2,1]\n sage: c * O.quantum_determinant()\n 1\n\n We verify the quantum determinant is in the center and is group-like::\n\n sage: qdet = O.quantum_determinant()\n sage: all(qdet * g == g * qdet for g in O.algebra_generators())\n True\n sage: qdet.coproduct() == tensor([qdet, qdet])\n True\n\n We check that the inverse of the quantum determinant is also in\n the center and group-like::\n\n sage: all(c * g == g * c for g in O.algebra_generators())\n True\n sage: c.coproduct() == tensor([c, c])\n True\n\n Moreover, the antipode interchanges the quantum determinant and\n its inverse::\n\n sage: c.antipode() == qdet\n True\n sage: qdet.antipode() == c\n True\n\n REFERENCES:\n\n - [DD1991]_\n - [Kar1993]_\n ' @staticmethod def __classcall_private__(cls, n, q=None, bar=None, R=None): '\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: R.<q> = LaurentPolynomialRing(ZZ)\n sage: O1 = algebras.QuantumGL(4)\n sage: O2 = algebras.QuantumGL(4, R=ZZ)\n sage: O3 = algebras.QuantumGL(4, R=R, q=q)\n sage: O1 is O2 and O2 is O3\n True\n sage: O4 = algebras.QuantumGL(4, R=QQ)\n sage: O1 is O4\n False\n ' return super().__classcall__(cls, n=n, q=q, bar=bar, R=R) def __init__(self, n, q, bar, R): '\n Initialize ``self``.\n\n TESTS::\n\n sage: O = algebras.QuantumGL(2)\n sage: elts = list(O.algebra_generators())\n sage: elts += [O.quantum_determinant(), O.an_element()]\n sage: TestSuite(O).run(elements=elts) # long time\n ' gp_indices = [(i, j) for i in range(1, (n + 1)) for j in range(1, (n + 1))] gp_indices.append('c') cat = HopfAlgebras(R.category()).WithBasis() QuantumMatrixCoordinateAlgebra_abstract.__init__(self, gp_indices, n, q, bar, R, cat, indices_key=_generator_key) names = ['x{}{}'.format(*k) for k in gp_indices[:(- 1)]] names.append('c') self._assign_names(names) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: algebras.QuantumGL(4)\n Quantized coordinate algebra of GL(4) with q=q over\n Univariate Laurent Polynomial Ring in q over Integer Ring\n ' txt = 'Quantized coordinate algebra of GL({}) with q={} over {}' return txt.format(self._n, self._q, self.base_ring()) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumGL(4)\n sage: latex(O)\n \\mathcal{O}_{q}(GL(4))\n ' return ('\\mathcal{O}_{%s}(GL(%s))' % (self._q, self._n)) @cached_method def algebra_generators(self): "\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumGL(2)\n sage: O.algebra_generators()\n Finite family {(1, 1): x[1,1], (1, 2): x[1,2], (2, 1): x[2,1], (2, 2): x[2,2], 'c': c}\n " l = [(i, j) for i in range(1, (self._n + 1)) for j in range(1, (self._n + 1))] l.append('c') G = self._indices.monoid_generators() one = self.base_ring().one() return Family(l, (lambda x: self.element_class(self, {G[x]: one}))) @lazy_attribute def _qdet_cancel_monomial(self): '\n Return the trailing monomial of the quantum determinant.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumGL(2)\n sage: O._qdet_cancel_monomial\n F[(1, 1)]*F[(2, 2)]\n ' I = self._indices gens = I.monoid_generators() return I.prod((gens[(i, i)] for i in range(1, (self._n + 1)))) @lazy_attribute def _qdet_remaining(self): '\n Return the remaining terms when cancelling the leading term.\n\n Consider `d = m + L`, where `m` is the leading term of the\n quantum determinant `d`. Then we have `c d = cm + cL = 1`,\n which we rewrite as `cm = 1 - cL`. This lazy attribute\n is `1 - cL`.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumGL(2)\n sage: O._qdet_remaining\n 1 + q*c*x[1,2]*x[2,1]\n ' temp = (self.monomial(self._qdet_cancel_monomial) - self.quantum_determinant()) c = self._indices.monoid_generators()['c'] ret = {(c * mon): coeff for (mon, coeff) in temp} return (self._from_dict(ret, remove_zeros=False) + self.one()) def product_on_basis(self, a, b): '\n Return the product of basis elements indexed by ``a`` and ``b``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumGL(2)\n sage: I = O.indices().monoid_generators()\n sage: O.product_on_basis(I[1,1], I[2,2])\n x[1,1]*x[2,2]\n sage: O.product_on_basis(I[2,2], I[1,1])\n x[1,1]*x[2,2] + (q^-1-q)*x[1,2]*x[2,1]\n\n TESTS::\n\n sage: x11,x12,x21,x22,c = O.algebra_generators()\n sage: x11 * x22\n x[1,1]*x[2,2]\n sage: x22 * x12\n (q^-1)*x[1,2]*x[2,2]\n sage: x22 * x11\n x[1,1]*x[2,2] + (q^-1-q)*x[1,2]*x[2,1]\n sage: c * (x11 * O.quantum_determinant())\n x[1,1]\n ' I = self._indices c_exp = 0 if ('c' in a._monomial): da = dict(a._monomial) c_exp += da.pop('c') a = I(da) if ('c' in b._monomial): db = dict(b._monomial) c_exp += db.pop('c') b = I(db) p = super().product_on_basis(a, b) if (c_exp == 0): return p c = self._indices.monoid_generators()['c'] ret = {} other = self.zero() for (mon, coeff) in p: try: rem = self.monomial((mon // self._qdet_cancel_monomial)) L = (self.monomial(self._qdet_cancel_monomial) * rem) co = L[mon] del L._monomial_coefficients[mon] temp = ((self.term((c ** (c_exp - 1)), coeff) * self._qdet_remaining) * rem) if (L != self.zero()): temp -= (self.term((c ** c_exp), coeff) * L) for k in temp._monomial_coefficients: temp._monomial_coefficients[k] //= co other += temp except ValueError: ret[((c ** c_exp) * mon)] = coeff return (self._from_dict(ret, remove_zeros=False) + other) @cached_method def _antipode_on_generator(self, i, j): '\n Return the antipode on the generator indexed by ``(i, j)``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumGL(2)\n sage: [[O._antipode_on_generator(i, j) for i in [1,2]] for j in [1,2]]\n [[c*x[2,2], -q*c*x[2,1]],\n [-(q^-1)*c*x[1,2], c*x[1,1]]]\n ' from sage.combinat.permutation import Permutations q = self._q I = (list(range(1, j)) + list(range((j + 1), (self._n + 1)))) def lift(p): return [(val if (val < i) else (val + 1)) for val in p] gens = self.algebra_generators() t_tilde = self.sum((((((- q) ** p.length()) * gens['c']) * self.prod((gens[(I[k], val)] for (k, val) in enumerate(lift(p))))) for p in Permutations((self._n - 1)))) return (((- q) ** (i - j)) * t_tilde) def antipode_on_basis(self, x): "\n Return the antipode of the basis element indexed by ``x``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumGL(3)\n sage: x = O.indices().monoid_generators()\n sage: O.antipode_on_basis(x[1,2])\n -(q^-1)*c*x[1,2]*x[3,3] + c*x[1,3]*x[3,2]\n sage: O.antipode_on_basis(x[2,2])\n c*x[1,1]*x[3,3] - q*c*x[1,3]*x[3,1]\n sage: O.antipode_on_basis(x['c']) == O.quantum_determinant()\n True\n " ret = self.one() for (k, e) in reversed(x._sorted_items()): if (k == 'c'): ret *= (self.quantum_determinant() ** e) else: ret *= (self._antipode_on_generator(*k) ** e) return ret def coproduct_on_basis(self, x): "\n Return the coproduct on the basis element indexed by ``x``.\n\n EXAMPLES::\n\n sage: O = algebras.QuantumGL(3)\n sage: x = O.indices().monoid_generators()\n sage: O.coproduct_on_basis(x[1,2])\n x[1,1] # x[1,2] + x[1,2] # x[2,2] + x[1,3] # x[3,2]\n sage: O.coproduct_on_basis(x[2,2])\n x[2,1] # x[1,2] + x[2,2] # x[2,2] + x[2,3] # x[3,2]\n sage: O.coproduct_on_basis(x['c'])\n c # c\n " T = self.tensor_square() I = self._indices.monoid_generators() return T.prod((((T.sum_of_monomials(((I[(t[0], k)], I[(k, t[1])]) for k in range(1, (self._n + 1)))) ** e) if (t != 'c') else (T.monomial((I['c'], I['c'])) ** e)) for (t, e) in x._sorted_items()))
def _generator_key(t): "\n Helper function to make ``'c'`` less that all other indices for\n sorting the monomials in :class:`QuantumGL`.\n\n INPUT:\n\n a tuple (index, exponent)\n\n OUTPUT:\n\n a tuple made from the index only\n\n EXAMPLES::\n\n sage: from sage.algebras.quantum_matrix_coordinate_algebra import _generator_key as k\n sage: k(((1,2),1)) < k(('c',1))\n False\n sage: k(((1,2),1)) < k(((1,3),1))\n True\n sage: k(((1,2),1)) < k(((3,1),1))\n True\n sage: k(('c',2)) < k(((1,1),1))\n True\n " t = t[0] if isinstance(t, tuple): return t return ()
class QuaternionAlgebraFactory(UniqueFactory): "\n Construct a quaternion algebra.\n\n INPUT:\n\n There are three input formats:\n\n - ``QuaternionAlgebra(a, b)``, where `a` and `b` can be coerced to\n units in a common field `K` of characteristic different from 2.\n\n - ``QuaternionAlgebra(K, a, b)``, where `K` is a ring in which 2\n is a unit and `a` and `b` are units of `K`.\n\n - ``QuaternionAlgebra(D)``, where `D \\ge 1` is a squarefree\n integer. This constructs a quaternion algebra of discriminant\n `D` over `K = \\QQ`. Suitable nonzero rational numbers `a`, `b`\n as above are deduced from `D`.\n\n OUTPUT:\n\n The quaternion algebra `(a, b)_K` over `K` generated by `i`, `j`\n subject to `i^2 = a`, `j^2 = b`, and `ji = -ij`.\n\n EXAMPLES:\n\n ``QuaternionAlgebra(a, b)`` -- return the quaternion algebra\n `(a, b)_K`, where the base ring `K` is a suitably chosen field\n containing `a` and `b`::\n\n sage: QuaternionAlgebra(-2,-3)\n Quaternion Algebra (-2, -3) with base ring Rational Field\n sage: QuaternionAlgebra(GF(5)(2), GF(5)(3))\n Quaternion Algebra (2, 3) with base ring Finite Field of size 5\n sage: QuaternionAlgebra(2, GF(5)(3))\n Quaternion Algebra (2, 3) with base ring Finite Field of size 5\n sage: QuaternionAlgebra(QQ[sqrt(2)](-1), -5) # needs sage.symbolic\n Quaternion Algebra (-1, -5) with base ring Number Field in sqrt2\n with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095?\n sage: QuaternionAlgebra(sqrt(-1), sqrt(-3)) # needs sage.symbolic\n Quaternion Algebra (I, sqrt(-3)) with base ring Symbolic Ring\n sage: QuaternionAlgebra(1r,1)\n Quaternion Algebra (1, 1) with base ring Rational Field\n sage: A.<t> = ZZ[]\n sage: QuaternionAlgebra(-1, t)\n Quaternion Algebra (-1, t) with base ring\n Fraction Field of Univariate Polynomial Ring in t over Integer Ring\n\n Python ints and floats may be passed to the\n ``QuaternionAlgebra(a, b)`` constructor, as may all pairs of\n nonzero elements of a domain not of characteristic 2.\n\n The following tests address the issues raised in :trac:`10601`::\n\n sage: QuaternionAlgebra(1r,1)\n Quaternion Algebra (1, 1) with base ring Rational Field\n sage: QuaternionAlgebra(1,1.0r)\n Quaternion Algebra (1.00000000000000, 1.00000000000000) with base ring\n Real Field with 53 bits of precision\n sage: QuaternionAlgebra(0,0)\n Traceback (most recent call last):\n ...\n ValueError: defining elements of quaternion algebra (0, 0)\n are not invertible in Rational Field\n sage: QuaternionAlgebra(GF(2)(1),1)\n Traceback (most recent call last):\n ...\n ValueError: 2 is not invertible in Finite Field of size 2\n sage: a = PermutationGroupElement([1,2,3])\n sage: QuaternionAlgebra(a, a)\n Traceback (most recent call last):\n ...\n ValueError: a and b must be elements of a ring with characteristic not 2\n\n ``QuaternionAlgebra(K, a, b)`` -- return the quaternion algebra\n defined by `(a, b)` over the ring `K`::\n\n sage: QuaternionAlgebra(QQ, -7, -21)\n Quaternion Algebra (-7, -21) with base ring Rational Field\n sage: QuaternionAlgebra(QQ[sqrt(2)], -2,-3) # needs sage.symbolic\n Quaternion Algebra (-2, -3) with base ring Number Field in sqrt2\n with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095?\n\n ``QuaternionAlgebra(D)`` -- `D` is a squarefree integer; return a\n rational quaternion algebra of discriminant `D`::\n\n sage: QuaternionAlgebra(1)\n Quaternion Algebra (-1, 1) with base ring Rational Field\n sage: QuaternionAlgebra(2)\n Quaternion Algebra (-1, -1) with base ring Rational Field\n sage: QuaternionAlgebra(7)\n Quaternion Algebra (-1, -7) with base ring Rational Field\n sage: QuaternionAlgebra(2*3*5*7)\n Quaternion Algebra (-22, 210) with base ring Rational Field\n\n If the coefficients `a` and `b` in the definition of the quaternion\n algebra are not integral, then a slower generic type is used for\n arithmetic::\n\n sage: type(QuaternionAlgebra(-1,-3).0)\n <... 'sage.algebras.quatalg.quaternion_algebra_element.QuaternionAlgebraElement_rational_field'>\n sage: type(QuaternionAlgebra(-1,-3/2).0)\n <... 'sage.algebras.quatalg.quaternion_algebra_element.QuaternionAlgebraElement_generic'>\n\n Make sure caching is sane::\n\n sage: A = QuaternionAlgebra(2,3); A\n Quaternion Algebra (2, 3) with base ring Rational Field\n sage: B = QuaternionAlgebra(GF(5)(2),GF(5)(3)); B\n Quaternion Algebra (2, 3) with base ring Finite Field of size 5\n sage: A is QuaternionAlgebra(2,3)\n True\n sage: B is QuaternionAlgebra(GF(5)(2),GF(5)(3))\n True\n sage: Q = QuaternionAlgebra(2); Q\n Quaternion Algebra (-1, -1) with base ring Rational Field\n sage: Q is QuaternionAlgebra(QQ,-1,-1)\n True\n sage: Q is QuaternionAlgebra(-1,-1)\n True\n sage: Q.<ii,jj,kk> = QuaternionAlgebra(15); Q.variable_names()\n ('ii', 'jj', 'kk')\n sage: QuaternionAlgebra(15).variable_names()\n ('i', 'j', 'k')\n\n TESTS:\n\n Verify that bug found when working on :trac:`12006` involving coercing\n invariants into the base field is fixed::\n\n sage: Q = QuaternionAlgebra(-1,-1); Q\n Quaternion Algebra (-1, -1) with base ring Rational Field\n sage: parent(Q._a)\n Rational Field\n sage: parent(Q._b)\n Rational Field\n " def create_key(self, arg0, arg1=None, arg2=None, names='i,j,k'): "\n Create a key that uniquely determines a quaternion algebra.\n\n TESTS::\n\n sage: QuaternionAlgebra.create_key(-1,-1)\n (Rational Field, -1, -1, ('i', 'j', 'k'))\n " if ((arg1 is None) and (arg2 is None)): K = QQ D = Integer(arg0) (a, b) = hilbert_conductor_inverse(D) a = Rational(a) b = Rational(b) elif (arg2 is None): L = [] for a in [arg0, arg1]: if is_RingElement(a): L.append(a) elif isinstance(a, int): L.append(Integer(a)) elif isinstance(a, float): L.append(RR(a)) else: raise ValueError('a and b must be elements of a ring with characteristic not 2') v = Sequence(L) K = v.universe().fraction_field() a = K(v[0]) b = K(v[1]) else: K = arg0 a = K(arg1) b = K(arg2) if (not K(2).is_unit()): raise ValueError(('2 is not invertible in %s' % K)) if (not (a.is_unit() and b.is_unit())): raise ValueError(('defining elements of quaternion algebra (%s, %s) are not invertible in %s' % (a, b, K))) names = normalize_names(3, names) return (K, a, b, names) def create_object(self, version, key, **extra_args): '\n Create the object from the key (extra arguments are ignored). This is\n only called if the object was not found in the cache.\n\n TESTS::\n\n sage: QuaternionAlgebra.create_object("6.0", (QQ, -1, -1, (\'i\', \'j\', \'k\')))\n Quaternion Algebra (-1, -1) with base ring Rational Field\n\n ' (K, a, b, names) = key return QuaternionAlgebra_ab(K, a, b, names=names)
def is_QuaternionAlgebra(A): '\n Return ``True`` if ``A`` is of the QuaternionAlgebra data type.\n\n EXAMPLES::\n\n sage: sage.algebras.quatalg.quaternion_algebra.is_QuaternionAlgebra(QuaternionAlgebra(QQ,-1,-1))\n True\n sage: sage.algebras.quatalg.quaternion_algebra.is_QuaternionAlgebra(ZZ)\n False\n ' return isinstance(A, QuaternionAlgebra_abstract)
class QuaternionAlgebra_abstract(Algebra): def _repr_(self): "\n EXAMPLES::\n\n sage: sage.algebras.quatalg.quaternion_algebra.QuaternionAlgebra_abstract(QQ)._repr_()\n 'Quaternion Algebra with base ring Rational Field'\n " return ('Quaternion Algebra with base ring %s' % self.base_ring()) def ngens(self): '\n Return the number of generators of the quaternion algebra as a K-vector\n space, not including 1.\n\n This value is always 3: the algebra is spanned\n by the standard basis `1`, `i`, `j`, `k`.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(QQ,-5,-2)\n sage: Q.ngens()\n 3\n sage: Q.gens()\n [i, j, k]\n ' return 3 @cached_method def basis(self): "\n Return the fixed basis of ``self``, which is `1`, `i`, `j`, `k`, where\n `i`, `j`, `k` are the generators of ``self``.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(QQ,-5,-2)\n sage: Q.basis()\n (1, i, j, k)\n\n sage: Q.<xyz,abc,theta> = QuaternionAlgebra(GF(9,'a'),-5,-2)\n sage: Q.basis()\n (1, xyz, abc, theta)\n\n The basis is cached::\n\n sage: Q.basis() is Q.basis()\n True\n " (i, j, k) = self.gens() return (self.one(), i, j, k) @cached_method def inner_product_matrix(self): '\n Return the inner product matrix associated to ``self``.\n\n This is the\n Gram matrix of the reduced norm as a quadratic form on ``self``.\n The standard basis `1`, `i`, `j`, `k` is orthogonal, so this matrix\n is just the diagonal matrix with diagonal entries `2`, `2a`, `2b`,\n `2ab`.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-5,-19)\n sage: Q.inner_product_matrix()\n [ 2 0 0 0]\n [ 0 10 0 0]\n [ 0 0 38 0]\n [ 0 0 0 190]\n ' (a, b) = (self._a, self._b) M = diagonal_matrix(self.base_ring(), [2, ((- 2) * a), ((- 2) * b), ((2 * a) * b)]) M.set_immutable() return M def is_commutative(self) -> bool: '\n Return ``False`` always, since all quaternion algebras are\n noncommutative.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -3,-7)\n sage: Q.is_commutative()\n False\n ' return False def is_division_algebra(self) -> bool: '\n Return ``True`` if the quaternion algebra is a division algebra (i.e.\n every nonzero element in ``self`` is invertible), and ``False`` if the\n quaternion algebra is isomorphic to the 2x2 matrix algebra.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(QQ,-5,-2).is_division_algebra()\n True\n sage: QuaternionAlgebra(1).is_division_algebra()\n False\n sage: QuaternionAlgebra(2,9).is_division_algebra()\n False\n sage: QuaternionAlgebra(RR(2.),1).is_division_algebra()\n Traceback (most recent call last):\n ...\n NotImplementedError: base field must be rational numbers\n ' if (not is_RationalField(self.base_ring())): raise NotImplementedError('base field must be rational numbers') return (self.discriminant() != 1) def is_matrix_ring(self) -> bool: '\n Return ``True`` if the quaternion algebra is isomorphic to the 2x2\n matrix ring, and ``False`` if ``self`` is a division algebra (i.e.\n every nonzero element in ``self`` is invertible).\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(QQ,-5,-2).is_matrix_ring()\n False\n sage: QuaternionAlgebra(1).is_matrix_ring()\n True\n sage: QuaternionAlgebra(2,9).is_matrix_ring()\n True\n sage: QuaternionAlgebra(RR(2.),1).is_matrix_ring()\n Traceback (most recent call last):\n ...\n NotImplementedError: base field must be rational numbers\n\n ' if (not is_RationalField(self.base_ring())): raise NotImplementedError('base field must be rational numbers') return (self.discriminant() == 1) def is_exact(self) -> bool: '\n Return ``True`` if elements of this quaternion algebra are represented\n exactly, i.e. there is no precision loss when doing arithmetic. A\n quaternion algebra is exact if and only if its base field is\n exact.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -3, -7)\n sage: Q.is_exact()\n True\n sage: Q.<i,j,k> = QuaternionAlgebra(Qp(7), -3, -7)\n sage: Q.is_exact()\n False\n ' return self.base_ring().is_exact() def is_field(self, proof=True) -> bool: '\n Return ``False`` always, since all quaternion algebras are\n noncommutative and all fields are commutative.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -3, -7)\n sage: Q.is_field()\n False\n ' return False def is_finite(self) -> bool: '\n Return ``True`` if the quaternion algebra is finite as a set.\n\n Algorithm: A quaternion algebra is finite if and only if the\n base field is finite.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -3, -7)\n sage: Q.is_finite()\n False\n sage: Q.<i,j,k> = QuaternionAlgebra(GF(5), -3, -7)\n sage: Q.is_finite()\n True\n ' return self.base_ring().is_finite() def is_integral_domain(self, proof=True) -> bool: '\n Return ``False`` always, since all quaternion algebras are\n noncommutative and integral domains are commutative (in Sage).\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -3, -7)\n sage: Q.is_integral_domain()\n False\n ' return False def is_noetherian(self) -> bool: '\n Return ``True`` always, since any quaternion algebra is a noetherian\n ring (because it is a finitely generated module over a field).\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -3, -7)\n sage: Q.is_noetherian()\n True\n ' return True def order(self): '\n Return the number of elements of the quaternion algebra, or\n ``+Infinity`` if the algebra is not finite.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(QQ, -3, -7)\n sage: Q.order()\n +Infinity\n sage: Q.<i,j,k> = QuaternionAlgebra(GF(5), -3, -7)\n sage: Q.order()\n 625\n ' return (self.base_ring().order() ** 4) def random_element(self, *args, **kwds): '\n Return a random element of this quaternion algebra.\n\n The ``args`` and ``kwds`` are passed to the ``random_element`` method\n of the base ring.\n\n EXAMPLES::\n\n sage: g = QuaternionAlgebra(QQ[sqrt(2)], -3, 7).random_element() # needs sage.symbolic\n sage: g.parent() is QuaternionAlgebra(QQ[sqrt(2)], -3, 7) # needs sage.symbolic\n True\n sage: g = QuaternionAlgebra(-3, 19).random_element()\n sage: g.parent() is QuaternionAlgebra(-3, 19)\n True\n sage: g = QuaternionAlgebra(GF(17)(2), 3).random_element()\n sage: g.parent() is QuaternionAlgebra(GF(17)(2), 3)\n True\n\n Specify the numerator and denominator bounds::\n\n sage: g = QuaternionAlgebra(-3,19).random_element(10^6, 10^6)\n sage: for h in g:\n ....: assert h.numerator() in range(-10^6, 10^6 + 1)\n ....: assert h.denominator() in range(10^6 + 1)\n\n sage: g = QuaternionAlgebra(-3,19).random_element(5, 4)\n sage: for h in g:\n ....: assert h.numerator() in range(-5, 5 + 1)\n ....: assert h.denominator() in range(4 + 1)\n ' K = self.base_ring() return self([K.random_element(*args, **kwds) for _ in range(4)]) @cached_method def free_module(self): '\n Return the free module associated to ``self`` with inner\n product given by the reduced norm.\n\n EXAMPLES::\n\n sage: A.<t> = LaurentPolynomialRing(GF(3))\n sage: B = QuaternionAlgebra(A, -1, t)\n sage: B.free_module()\n Ambient free quadratic module of rank 4 over the principal ideal domain\n Univariate Laurent Polynomial Ring in t over Finite Field of size 3\n Inner product matrix:\n [2 0 0 0]\n [0 2 0 0]\n [0 0 t 0]\n [0 0 0 t]\n ' return FreeModule(self.base_ring(), 4, inner_product_matrix=self.inner_product_matrix()) def vector_space(self): '\n Alias for :meth:`free_module`.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-3,19).vector_space()\n Ambient quadratic space of dimension 4 over Rational Field\n Inner product matrix:\n [ 2 0 0 0]\n [ 0 6 0 0]\n [ 0 0 -38 0]\n [ 0 0 0 -114]\n ' return self.free_module()
class QuaternionAlgebra_ab(QuaternionAlgebra_abstract): "\n A quaternion algebra of the form `(a, b)_K`.\n\n See ``QuaternionAlgebra`` for many more examples.\n\n INPUT:\n\n - ``base_ring`` -- a commutative ring `K` in which 2 is invertible\n - ``a, b`` -- units of `K`\n - ``names`` -- string (optional, default 'i,j,k') names of the generators\n\n OUTPUT:\n\n The quaternion algebra `(a, b)` over `K` generated by `i` and `j`\n subject to `i^2 = a`, `j^2 = b`, and `ji = -ij`.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(QQ, -7, -21) # indirect doctest\n Quaternion Algebra (-7, -21) with base ring Rational Field\n " def __init__(self, base_ring, a, b, names='i,j,k'): "\n Create the quaternion algebra with `i^2 = a`, `j^2 = b`, and\n `ij = -ji = k`.\n\n TESTS:\n\n Test making quaternion elements (using the element constructor)::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(QQ,-1,-2)\n sage: a = Q(2/3); a\n 2/3\n sage: type(a)\n <... 'sage.algebras.quatalg.quaternion_algebra_element.QuaternionAlgebraElement_rational_field'>\n sage: Q(a)\n 2/3\n sage: Q([1,2,3,4])\n 1 + 2*i + 3*j + 4*k\n sage: Q((1,2,3,4))\n 1 + 2*i + 3*j + 4*k\n sage: Q(-3/5)\n -3/5\n\n sage: TestSuite(Q).run()\n\n The element 2 must be a unit in the base ring::\n\n sage: Q.<ii,jj,kk> = QuaternionAlgebra(ZZ,-5,-19)\n Traceback (most recent call last):\n ...\n ValueError: 2 is not invertible in Integer Ring\n " cat = Algebras(base_ring).Division().FiniteDimensional() Algebra.__init__(self, base_ring, names, category=cat) self._a = a self._b = b if (is_RationalField(base_ring) and (a.denominator() == 1 == b.denominator())): self.Element = QuaternionAlgebraElement_rational_field elif (isinstance(base_ring, NumberField) and (base_ring.degree() > 2) and base_ring.is_absolute() and (a.denominator() == 1 == b.denominator()) and base_ring.defining_polynomial().is_monic()): self.Element = QuaternionAlgebraElement_number_field else: self.Element = QuaternionAlgebraElement_generic self._populate_coercion_lists_(coerce_list=[base_ring]) self._gens = [self([0, 1, 0, 0]), self([0, 0, 1, 0]), self([0, 0, 0, 1])] @cached_method def maximal_order(self, take_shortcuts=True): '\n Return a maximal order in this quaternion algebra.\n\n The algorithm used is from [Voi2012]_.\n\n INPUT:\n\n - ``take_shortcuts`` -- (default: ``True``) if the discriminant is\n prime and the invariants of the algebra are of a nice form, use\n Proposition 5.2 of [Piz1980]_.\n\n OUTPUT:\n\n A maximal order in this quaternion algebra.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-1,-7).maximal_order()\n Order of Quaternion Algebra (-1, -7) with base ring Rational Field\n with basis (1/2 + 1/2*j, 1/2*i + 1/2*k, j, k)\n\n sage: QuaternionAlgebra(-1,-1).maximal_order().basis()\n (1/2 + 1/2*i + 1/2*j + 1/2*k, i, j, k)\n\n sage: QuaternionAlgebra(-1,-11).maximal_order().basis()\n (1/2 + 1/2*j, 1/2*i + 1/2*k, j, k)\n\n sage: QuaternionAlgebra(-1,-3).maximal_order().basis()\n (1/2 + 1/2*j, 1/2*i + 1/2*k, j, k)\n\n sage: QuaternionAlgebra(-3,-1).maximal_order().basis()\n (1/2 + 1/2*i, 1/2*j - 1/2*k, i, -k)\n\n sage: QuaternionAlgebra(-2,-5).maximal_order().basis()\n (1/2 + 1/2*j + 1/2*k, 1/4*i + 1/2*j + 1/4*k, j, k)\n\n sage: QuaternionAlgebra(-5,-2).maximal_order().basis()\n (1/2 + 1/2*i - 1/2*k, 1/2*i + 1/4*j - 1/4*k, i, -k)\n\n sage: QuaternionAlgebra(-17,-3).maximal_order().basis()\n (1/2 + 1/2*j, 1/2*i + 1/2*k, -1/3*j - 1/3*k, k)\n\n sage: QuaternionAlgebra(-3,-17).maximal_order().basis()\n (1/2 + 1/2*i, 1/2*j - 1/2*k, -1/3*i + 1/3*k, -k)\n\n sage: QuaternionAlgebra(-17*9,-3).maximal_order().basis()\n (1, 1/3*i, 1/6*i + 1/2*j, 1/2 + 1/3*j + 1/18*k)\n\n sage: QuaternionAlgebra(-2, -389).maximal_order().basis()\n (1/2 + 1/2*j + 1/2*k, 1/4*i + 1/2*j + 1/4*k, j, k)\n\n If you want bases containing 1, switch off ``take_shortcuts``::\n\n sage: QuaternionAlgebra(-3,-89).maximal_order(take_shortcuts=False)\n Order of Quaternion Algebra (-3, -89) with base ring Rational Field\n with basis (1, 1/2 + 1/2*i, j, 1/2 + 1/6*i + 1/2*j + 1/6*k)\n\n sage: QuaternionAlgebra(1,1).maximal_order(take_shortcuts=False) # Matrix ring\n Order of Quaternion Algebra (1, 1) with base ring Rational Field\n with basis (1, 1/2 + 1/2*i, j, 1/2*j + 1/2*k)\n\n sage: QuaternionAlgebra(-22,210).maximal_order(take_shortcuts=False)\n Order of Quaternion Algebra (-22, 210) with base ring Rational Field\n with basis (1, i, 1/2*i + 1/2*j, 1/2 + 17/22*i + 1/44*k)\n\n sage: for d in ( m for m in range(1, 750) if is_squarefree(m) ): # long time (3s)\n ....: A = QuaternionAlgebra(d)\n ....: R = A.maximal_order(take_shortcuts=False)\n ....: assert A.discriminant() == R.discriminant()\n\n We do not support number fields other than the rationals yet::\n\n sage: K = QuadraticField(5)\n sage: QuaternionAlgebra(K,-1,-1).maximal_order()\n Traceback (most recent call last):\n ...\n NotImplementedError: maximal order only implemented\n for rational quaternion algebras\n ' if (self.base_ring() != QQ): raise NotImplementedError('maximal order only implemented for rational quaternion algebras') d_A = self.discriminant() (a, b) = self.invariants() if (take_shortcuts and d_A.is_prime() and (a in ZZ) and (b in ZZ)): a = ZZ(a) b = ZZ(b) (i, j, k) = self.gens() if (((a != (- 1)) and (b == (- 1))) or (b == (- 2)) or ((a != (- 1)) and (a != (- 2)) and (((- a) % 8) != 1))): (a, b) = (b, a) (i, j) = (j, i) k = (i * j) basis = [] if ((a, b) == ((- 1), (- 1))): basis = [((((1 + i) + j) + k) / 2), i, j, k] elif ((a == (- 1)) and (- b).is_prime() and (((- b) % 4) == 3)): basis = [((1 + j) / 2), ((i + k) / 2), j, k] elif ((a == (- 2)) and (- b).is_prime() and (((- b) % 8) == 5)): basis = [(((1 + j) + k) / 2), (((i + (2 * j)) + k) / 4), j, k] elif ((- a).is_prime() and (- b).is_prime()): q = (- b) p = (- a) if (((q % 4) == 3) and (kronecker_symbol(p, q) == (- 1))): a = 0 while ((((a * a) * p) + 1) % q): a += 1 basis = [((1 + j) / 2), ((i + k) / 2), ((- (j + (a * k))) / q), k] if basis: return self.quaternion_order(basis) R = self.quaternion_order(([1] + self.gens())) d_R = R.discriminant() e_new_gens = [] for (p, _) in d_R.factor(): e = R.basis() while (self.quaternion_order(e).discriminant().valuation(p) > d_A.valuation(p)): f = normalize_basis_at_p(list(e), p) V = (self.base_ring() ** 4) A = matrix(self.base_ring(), 4, 4, [list(g) for g in e]) e_n = [] x_rows = A.solve_left(matrix([V(vec.coefficient_tuple()) for (vec, val) in f]), check=False).rows() denoms = [x.denominator() for x in x_rows] for i in range(4): vec = f[i][0] val = f[i][1] v = (val / 2).floor() e_n.append(((denoms[i] / (p ** v)) * vec)) lst = sorted(zip(e_n, [f[m][1].mod(2) for m in range(4)]), key=itemgetter(1)) e_n = list(next(zip(*lst))) if (p != 2): if (ZZ((e_n[1] ** 2)).valuation(p) != 0): if (ZZ((e_n[2] ** 2)).valuation(p) == 0): (e_n[1], e_n[2]) = (e_n[2], e_n[1]) else: (e_n[1], e_n[3]) = (e_n[3], e_n[1]) a = ZZ((e_n[1] ** 2)) b = ZZ((e_n[2] ** 2)) if (b.valuation(p) > 0): F = ZZ.quo(p) if F(a).is_square(): x = F(a).sqrt().lift() if (((x ** 2) - a).mod((p ** 2)) == 0): x = (x + p) g = (((1 / p) * (x - e_n[1])) * e_n[2]) e_n[2] = g e_n[3] = (e_n[1] * g) else: t = e_n[1].reduced_trace() a = (- e_n[1].reduced_norm()) b = ZZ((e_n[2] ** 2)) if (t.valuation(p) == 0): if (b.valuation(p) > 0): x = a if ((((x ** 2) - (t * x)) + a).mod((p ** 2)) == 0): x = (x + p) g = (((1 / p) * (x - e_n[1])) * e_n[2]) e_n[2] = g e_n[3] = (e_n[1] * g) else: (y, z, w) = maxord_solve_aux_eq(a, b, p) g = ((1 / p) * (((1 + (y * e_n[1])) + (z * e_n[2])) + ((w * e_n[1]) * e_n[2]))) h = (((z * b) * e_n[1]) - ((y * a) * e_n[2])) e_n[1:4] = [g, h, (g * h)] if ((((1 - (a * (y ** 2))) - (b * (z ** 2))) + ((a * b) * (w ** 2))).valuation(2) > 2): e_n = basis_for_quaternion_lattice((list(e) + e_n[1:]), reverse=True) e = e_n e_new_gens.extend(e[1:]) e_new = basis_for_quaternion_lattice((list(R.basis()) + e_new_gens), reverse=True) return self.quaternion_order(e_new) def invariants(self): '\n Return the structural invariants `a`, `b` of this quaternion\n algebra: ``self`` is generated by `i`, `j` subject to\n `i^2 = a`, `j^2 = b` and `ji = -ij`.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(15)\n sage: Q.invariants()\n (-3, 5)\n sage: i^2\n -3\n sage: j^2\n 5\n ' return (self._a, self._b) def __eq__(self, other): '\n Compare self and other.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-1,-7) == QuaternionAlgebra(-1,-7)\n True\n sage: QuaternionAlgebra(-1,-7) == QuaternionAlgebra(-1,-5)\n False\n ' if (not isinstance(other, QuaternionAlgebra_abstract)): return False return ((self.base_ring() == other.base_ring()) and ((self._a, self._b) == (other._a, other._b))) def __ne__(self, other): '\n Compare self and other.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-1,-7) != QuaternionAlgebra(-1,-7)\n False\n sage: QuaternionAlgebra(-1,-7) != QuaternionAlgebra(-1,-5)\n True\n ' return (not self.__eq__(other)) def __hash__(self): '\n Compute the hash of ``self``.\n\n EXAMPLES::\n\n sage: h1 = hash(QuaternionAlgebra(-1,-7))\n sage: h2 = hash(QuaternionAlgebra(-1,-7))\n sage: h3 = hash(QuaternionAlgebra(-1,-5))\n sage: h1 == h2 and h1 != h3\n True\n ' return hash((self.base_ring(), self._a, self._b)) def gen(self, i=0): '\n Return the `i^{th}` generator of ``self``.\n\n INPUT:\n\n - ``i`` - integer (optional, default 0)\n\n EXAMPLES::\n\n sage: Q.<ii,jj,kk> = QuaternionAlgebra(QQ,-1,-2); Q\n Quaternion Algebra (-1, -2) with base ring Rational Field\n sage: Q.gen(0)\n ii\n sage: Q.gen(1)\n jj\n sage: Q.gen(2)\n kk\n sage: Q.gens()\n [ii, jj, kk]\n ' return self._gens[i] def _repr_(self): "\n Print representation.\n\n TESTS::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(QQ,-5,-2)\n sage: type(Q)\n <class 'sage.algebras.quatalg.quaternion_algebra.QuaternionAlgebra_ab_with_category'>\n sage: Q._repr_()\n 'Quaternion Algebra (-5, -2) with base ring Rational Field'\n sage: Q\n Quaternion Algebra (-5, -2) with base ring Rational Field\n sage: print(Q)\n Quaternion Algebra (-5, -2) with base ring Rational Field\n sage: str(Q)\n 'Quaternion Algebra (-5, -2) with base ring Rational Field'\n " return ('Quaternion Algebra (%r, %r) with base ring %s' % (self._a, self._b, self.base_ring())) def inner_product_matrix(self): '\n Return the inner product matrix associated to ``self``, i.e. the\n Gram matrix of the reduced norm as a quadratic form on ``self``.\n The standard basis `1`, `i`, `j`, `k` is orthogonal, so this matrix\n is just the diagonal matrix with diagonal entries `1`, `a`, `b`, `ab`.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-5,-19)\n sage: Q.inner_product_matrix()\n [ 2 0 0 0]\n [ 0 10 0 0]\n [ 0 0 38 0]\n [ 0 0 0 190]\n\n sage: R.<a,b> = QQ[]; Q.<i,j,k> = QuaternionAlgebra(Frac(R),a,b)\n sage: Q.inner_product_matrix()\n [ 2 0 0 0]\n [ 0 -2*a 0 0]\n [ 0 0 -2*b 0]\n [ 0 0 0 2*a*b]\n ' (a, b) = (self._a, self._b) return diagonal_matrix(self.base_ring(), [2, ((- 2) * a), ((- 2) * b), ((2 * a) * b)]) @cached_method def discriminant(self): "\n Given a quaternion algebra `A` defined over a number field,\n return the discriminant of `A`, i.e. the\n product of the ramified primes of `A`.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(210,-22).discriminant()\n 210\n sage: QuaternionAlgebra(19).discriminant()\n 19\n\n sage: x = polygen(ZZ, 'x')\n sage: F.<a> = NumberField(x^2 - x - 1)\n sage: B.<i,j,k> = QuaternionAlgebra(F, 2*a, F(-1))\n sage: B.discriminant()\n Fractional ideal (2)\n\n sage: QuaternionAlgebra(QQ[sqrt(2)], 3, 19).discriminant() # needs sage.symbolic\n Fractional ideal (1)\n " if (not is_RationalField(self.base_ring())): try: F = self.base_ring() return F.hilbert_conductor(self._a, self._b) except NotImplementedError: raise ValueError('base field must be rational numbers or number field') else: return hilbert_conductor(self._a, self._b) def ramified_primes(self): '\n Return the primes that ramify in this quaternion algebra.\n\n Currently only implemented over the rational numbers.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(QQ, -1, -1).ramified_primes()\n [2]\n ' return [f[0] for f in factor(self.discriminant())] def _magma_init_(self, magma): "\n Return Magma version of this quaternion algebra.\n\n EXAMPLES::\n\n sage: Q = QuaternionAlgebra(-1,-1); Q\n Quaternion Algebra (-1, -1) with base ring Rational Field\n sage: Q._magma_init_(magma) # optional - magma\n 'QuaternionAlgebra(_sage_[...],-1/1,-1/1)'\n sage: A = magma(Q); A # optional - magma\n Quaternion Algebra with base ring Rational Field, defined by i^2 = -1, j^2 = -1\n sage: A.RamifiedPlaces() # optional - magma\n [\n Ideal of Integer Ring generated by 2\n ]\n\n A more complicated example involving a quaternion algebra over a number field::\n\n sage: K.<a> = QQ[sqrt(2)]; Q = QuaternionAlgebra(K,-1,a); Q # needs sage.symbolic\n Quaternion Algebra (-1, sqrt2) with base ring Number Field in sqrt2\n with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095?\n sage: magma(Q) # optional - magma, needs sage.symbolic\n Quaternion Algebra with base ring Number Field with defining polynomial\n x^2 - 2 over the Rational Field, defined by i^2 = -1, j^2 = sqrt2\n sage: Q._magma_init_(magma) # optional - magma, needs sage.symbolic\n 'QuaternionAlgebra(_sage_[...],(_sage_[...]![-1, 0]),(_sage_[...]![0, 1]))'\n " R = magma(self.base_ring()) return ('QuaternionAlgebra(%s,%s,%s)' % (R.name(), self._a._magma_init_(magma), self._b._magma_init_(magma))) def quaternion_order(self, basis, check=True): '\n Return the order of this quaternion order with given basis.\n\n INPUT:\n\n - ``basis`` - list of 4 elements of ``self``\n - ``check`` - bool (default: ``True``)\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-11,-1)\n sage: Q.quaternion_order([1,i,j,k])\n Order of Quaternion Algebra (-11, -1) with base ring Rational Field\n with basis (1, i, j, k)\n\n We test out ``check=False``::\n\n sage: Q.quaternion_order([1,i,j,k], check=False)\n Order of Quaternion Algebra (-11, -1) with base ring Rational Field\n with basis (1, i, j, k)\n sage: Q.quaternion_order([i,j,k], check=False)\n Order of Quaternion Algebra (-11, -1) with base ring Rational Field\n with basis (i, j, k)\n ' return QuaternionOrder(self, basis, check=check) def ideal(self, gens, left_order=None, right_order=None, check=True, **kwds): '\n Return the quaternion ideal with given gens over `\\ZZ`.\n\n Neither a left or right order structure need be specified.\n\n INPUT:\n\n - ``gens`` -- a list of elements of this quaternion order\n\n - ``check`` -- bool (default: ``True``)\n\n - ``left_order`` -- a quaternion order or ``None``\n\n - ``right_order`` -- a quaternion order or ``None``\n\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1)\n sage: R.ideal([2*a for a in R.basis()])\n Fractional ideal (2, 2*i, 2*j, 2*k)\n ' gens = [self(g) for g in gens] if (self.base_ring() == QQ): return QuaternionFractionalIdeal_rational(self, gens, left_order=left_order, right_order=right_order, check=check) else: raise NotImplementedError('ideal only implemented for quaternion algebras over QQ') @cached_method def modp_splitting_data(self, p): '\n Return mod `p` splitting data for this quaternion algebra at\n the unramified prime `p`.\n\n This is `2\\times 2`\n matrices `I`, `J`, `K` over the finite field `\\GF{p}` such that if\n the quaternion algebra has generators `i, j, k`, then `I^2 =\n i^2`, `J^2 = j^2`, `IJ=K` and `IJ=-JI`.\n\n .. NOTE::\n\n Currently only implemented when `p` is odd and the base\n ring is `\\QQ`.\n\n INPUT:\n\n - `p` -- unramified odd prime\n\n OUTPUT:\n\n - 2-tuple of matrices over finite field\n\n EXAMPLES::\n\n sage: Q = QuaternionAlgebra(-15, -19)\n sage: Q.modp_splitting_data(7)\n (\n [0 6] [6 1] [6 6]\n [1 0], [1 1], [6 1]\n )\n sage: Q.modp_splitting_data(next_prime(10^5))\n (\n [ 0 99988] [97311 4] [99999 59623]\n [ 1 0], [13334 2692], [97311 4]\n )\n sage: I,J,K = Q.modp_splitting_data(23)\n sage: I\n [0 8]\n [1 0]\n sage: I^2\n [8 0]\n [0 8]\n sage: J\n [19 2]\n [17 4]\n sage: J^2\n [4 0]\n [0 4]\n sage: I*J == -J*I\n True\n sage: I*J == K\n True\n\n The following is a good test because of the asserts in the code::\n\n sage: v = [Q.modp_splitting_data(p) for p in primes(20,1000)]\n\n Proper error handling::\n\n sage: Q.modp_splitting_data(5)\n Traceback (most recent call last):\n ...\n NotImplementedError: algorithm for computing local splittings\n not implemented in general (currently require the first invariant\n to be coprime to p)\n\n sage: Q.modp_splitting_data(2)\n Traceback (most recent call last):\n ...\n NotImplementedError: p must be odd\n ' if (self.base_ring() != QQ): raise NotImplementedError('must be rational quaternion algebra') p = ZZ(p) if (not p.is_prime()): raise ValueError(('p (=%s) must be prime' % p)) if (p == 2): raise NotImplementedError('p must be odd') if ((self.discriminant() % p) == 0): raise ValueError(('p (=%s) must be an unramified prime' % p)) (i, j, _) = self.gens() F = GF(p) i2 = F((i * i)) j2 = F((j * j)) M = MatrixSpace(F, 2) I = M([0, i2, 1, 0]) if (i2 == 0): raise NotImplementedError('algorithm for computing local splittings not implemented in general (currently require the first invariant to be coprime to p)') i2inv = (~ i2) a = None for b in F: if (not b): continue c = (j2 + ((i2inv * b) * b)) if c.is_square(): a = (- c.sqrt()) break if (a is None): for J in M: K = (I * J) if (((J * J) == j2) and (K == ((- J) * I))): return (I, J, K) J = M([a, b, ((j2 - (a * a)) / b), (- a)]) K = (I * J) assert (K == ((- J) * I)), "bug in that I,J don't skew commute" return (I, J, K) def modp_splitting_map(self, p): '\n Return Python map from the (`p`-integral) quaternion algebra to\n the set of `2\\times 2` matrices over `\\GF{p}`.\n\n INPUT:\n\n - `p` -- prime number\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-1, -7)\n sage: f = Q.modp_splitting_map(13)\n sage: a = 2+i-j+3*k; b = 7+2*i-4*j+k\n sage: f(a*b)\n [12 3]\n [10 5]\n sage: f(a)*f(b)\n [12 3]\n [10 5]\n ' (I, J, K) = self.modp_splitting_data(p) F = I.base_ring() def phi(q): v = [F(a) for a in q.coefficient_tuple()] return (((v[0] + (I * v[1])) + (J * v[2])) + (K * v[3])) return phi
def unpickle_QuaternionAlgebra_v0(*key): "\n The 0th version of pickling for quaternion algebras.\n\n EXAMPLES::\n\n sage: Q = QuaternionAlgebra(-5,-19)\n sage: t = (QQ, -5, -19, ('i', 'j', 'k'))\n sage: sage.algebras.quatalg.quaternion_algebra.unpickle_QuaternionAlgebra_v0(*t)\n Quaternion Algebra (-5, -19) with base ring Rational Field\n sage: loads(dumps(Q)) == Q\n True\n sage: loads(dumps(Q)) is Q\n True\n " return QuaternionAlgebra(*key)
class QuaternionOrder(Parent): "\n An order in a quaternion algebra.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-1,-7).maximal_order()\n Order of Quaternion Algebra (-1, -7) with base ring Rational Field with basis (1/2 + 1/2*j, 1/2*i + 1/2*k, j, k)\n sage: type(QuaternionAlgebra(-1,-7).maximal_order())\n <class 'sage.algebras.quatalg.quaternion_algebra.QuaternionOrder_with_category'>\n " def __init__(self, A, basis, check=True): "\n INPUT:\n\n - ``A`` - a quaternion algebra\n - ``basis`` - list of 4 integral quaternions in ``A``\n - ``check`` - whether to do type and other consistency checks\n\n .. WARNING::\n\n Currently most methods silently assume that the ``A.base_ring()``\n is ``QQ``.\n\n EXAMPLES::\n\n sage: A.<i,j,k> = QuaternionAlgebra(-3,-5)\n sage: sage.algebras.quatalg.quaternion_algebra.QuaternionOrder(A, [1,i,j,k])\n Order of Quaternion Algebra (-3, -5) with base ring Rational Field with basis (1, i, j, k)\n sage: R = sage.algebras.quatalg.quaternion_algebra.QuaternionOrder(A, [1,2*i,2*j,2*k]); R\n Order of Quaternion Algebra (-3, -5) with base ring Rational Field with basis (1, 2*i, 2*j, 2*k)\n sage: type(R)\n <class 'sage.algebras.quatalg.quaternion_algebra.QuaternionOrder_with_category'>\n\n Over QQ and number fields it is checked whether the given\n basis actually gives an order (as a module over the maximal order)::\n\n sage: A.<i,j,k> = QuaternionAlgebra(-1,-1)\n sage: A.quaternion_order([1,i,j,i-j])\n Traceback (most recent call last):\n ...\n ValueError: basis must have rank 4\n sage: A.quaternion_order([2,i,j,k])\n Traceback (most recent call last):\n ...\n ValueError: lattice must contain 1\n sage: A.quaternion_order([1,i/2,j/2,k/2])\n Traceback (most recent call last):\n ...\n ValueError: given lattice must be a ring\n\n sage: K = QuadraticField(10)\n sage: A.<i,j,k> = QuaternionAlgebra(K,-1,-1)\n sage: A.quaternion_order([1,i,j,k])\n Order of Quaternion Algebra (-1, -1) with base ring Number Field in a\n with defining polynomial x^2 - 10 with a = 3.162277660168380? with basis (1, i, j, k)\n sage: A.quaternion_order([1,i/2,j,k])\n Traceback (most recent call last):\n ...\n ValueError: given lattice must be a ring\n\n TESTS::\n\n sage: TestSuite(R).run()\n " if check: if (not isinstance(basis, (list, tuple))): raise TypeError('basis must be a list or tuple') if (len(basis) != 4): raise ValueError('basis must have length 4') basis = tuple([A(x) for x in basis]) V = (A.base_ring() ** 4) if (V.span([V(x.coefficient_tuple()) for x in basis]).dimension() != 4): raise ValueError('basis must have rank 4') if (A.base_ring() == QQ): M = matrix(QQ, 4, 4, [x.coefficient_tuple() for x in basis]) v = M.solve_left(V([1, 0, 0, 0])) if (v.denominator() != 1): raise ValueError('lattice must contain 1') M1 = basis_for_quaternion_lattice(basis, reverse=False) M2 = basis_for_quaternion_lattice((list(basis) + [(x * y) for x in basis for y in basis]), reverse=False) if (M1 != M2): raise ValueError('given lattice must be a ring') if (A.base_ring() != QQ): O = None try: O = A.base_ring().maximal_order() except AttributeError: pass if O: M = matrix(A.base_ring(), 4, 4, [x.coefficient_tuple() for x in basis]) v = M.solve_left(V([1, 0, 0, 0])) if any(((a not in O) for a in v)): raise ValueError('lattice must contain 1') Y = matrix(QQ, 16, 4, [(x * y).coefficient_tuple() for x in basis for y in basis]) X = M.solve_left(Y) if any(((a not in O) for x in X for a in x)): raise ValueError('given lattice must be a ring') self.__basis = tuple(basis) self.__quaternion_algebra = A Parent.__init__(self, base=ZZ, facade=(A,), category=Algebras(ZZ).Facade().FiniteDimensional()) def _element_constructor_(self, x): '\n Construct an element of this quaternion order from ``x``,\n or throw an error if ``x`` is not contained in the order.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-1,-19)\n sage: O = Q.quaternion_order([1,i,j,k])\n sage: O(1+i)\n 1 + i\n sage: O(1/2)\n Traceback (most recent call last):\n ...\n TypeError: 1/2 does not lie in Order of Quaternion Algebra (-1, -19)\n with base ring Rational Field with basis (1, i, j, k)\n\n TESTS:\n\n Test for :trac:`32364`::\n\n sage: 1/5 in O\n False\n sage: j/2 in O\n False\n\n ' y = self.quaternion_algebra()(x) if (y not in self.unit_ideal()): raise TypeError(f'{x!r} does not lie in {self!r}') return y def one(self): '\n Return the multiplicative unit of this quaternion order.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-1,-7).maximal_order().one()\n 1\n ' return self.quaternion_algebra().one() def gens(self): '\n Return generators for self.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-1,-7).maximal_order().gens()\n (1/2 + 1/2*j, 1/2*i + 1/2*k, j, k)\n ' return self.__basis def ngens(self): '\n Return the number of generators (which is 4).\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-1,-7).maximal_order().ngens()\n 4\n ' return 4 def gen(self, n): '\n Return the n-th generator.\n\n INPUT:\n\n - ``n`` - an integer between 0 and 3, inclusive.\n\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order(); R\n Order of Quaternion Algebra (-11, -1) with base ring Rational Field\n with basis (1/2 + 1/2*i, 1/2*j - 1/2*k, i, -k)\n sage: R.gen(0)\n 1/2 + 1/2*i\n sage: R.gen(1)\n 1/2*j - 1/2*k\n sage: R.gen(2)\n i\n sage: R.gen(3)\n -k\n ' return self.__basis[n] def __eq__(self, R): '\n Compare orders self and other.\n\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order()\n sage: R == R # indirect doctest\n True\n sage: R == QuaternionAlgebra(-1,-1).maximal_order()\n False\n sage: R == 5\n False\n sage: Q.<i,j,k> = QuaternionAlgebra(-1,-19)\n\n Orders can be equal even if they are defined by different\n bases (see :trac:`32245`)::\n\n sage: Q.quaternion_order([1,-i,k,j+i*7]) == Q.quaternion_order([1,i,j,k])\n True\n ' if (not isinstance(R, QuaternionOrder)): return False return ((self.__quaternion_algebra == R.__quaternion_algebra) and (self.unit_ideal() == R.unit_ideal())) def __ne__(self, other): '\n Compare orders self and other.\n\n Two orders are equal if they\n have the same basis and are in the same quaternion algebra.\n\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order()\n sage: R != R # indirect doctest\n False\n sage: R != QuaternionAlgebra(-1,-1).maximal_order()\n True\n ' return (not self.__eq__(other)) def __hash__(self): '\n Compute the hash of ``self``.\n\n EXAMPLES::\n\n sage: h1 = hash(QuaternionAlgebra(-1,-7).maximal_order())\n sage: h2 = hash(QuaternionAlgebra(-1,-7).maximal_order())\n sage: h3 = hash(QuaternionAlgebra(-1,-5).maximal_order())\n sage: h1 == h2 and h1 != h3\n True\n ' return hash((self.__quaternion_algebra, self.__basis)) def basis(self): '\n Return fix choice of basis for this quaternion order.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-11,-1).maximal_order().basis()\n (1/2 + 1/2*i, 1/2*j - 1/2*k, i, -k)\n ' return self.__basis def quaternion_algebra(self): '\n Return ambient quaternion algebra that contains this quaternion order.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-11,-1).maximal_order().quaternion_algebra()\n Quaternion Algebra (-11, -1) with base ring Rational Field\n ' return self.__quaternion_algebra def _repr_(self): "\n Return string representation of this order.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-11,-1).maximal_order()._repr_()\n 'Order of Quaternion Algebra (-11, -1) with base ring Rational Field with basis (1/2 + 1/2*i, 1/2*j - 1/2*k, i, -k)'\n sage: QuaternionAlgebra(-11,-1).maximal_order()\n Order of Quaternion Algebra (-11, -1) with base ring Rational Field with basis (1/2 + 1/2*i, 1/2*j - 1/2*k, i, -k)\n " return ('Order of %s with basis %s' % (self.quaternion_algebra(), self.basis())) def random_element(self, *args, **kwds): '\n Return a random element of this order.\n\n The args and kwds are passed to the random_element method of\n the integer ring, and we return an element of the form\n\n .. MATH::\n\n ae_1 + be_2 + ce_3 + de_4\n\n where `e_1`, ..., `e_4` are the basis of this order and `a`,\n `b`, `c`, `d` are random integers.\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-11,-1).maximal_order().random_element() # random\n -4 - 4*i + j - k\n sage: QuaternionAlgebra(-11,-1).maximal_order().random_element(-10,10) # random\n -9/2 - 7/2*i - 7/2*j - 3/2*k\n ' return sum(((ZZ.random_element(*args, **kwds) * b) for b in self.basis())) def intersection(self, other): '\n Return the intersection of this order with other.\n\n INPUT:\n\n - ``other`` - a quaternion order in the same ambient quaternion algebra\n\n OUTPUT: a quaternion order\n\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order()\n sage: R.intersection(R)\n Order of Quaternion Algebra (-11, -1) with base ring Rational Field\n with basis (1/2 + 1/2*i, i, 1/2*j + 1/2*k, k)\n\n We intersect various orders in the quaternion algebra ramified at 11::\n\n sage: B = BrandtModule(11,3)\n sage: R = B.maximal_order(); S = B.order_of_level_N()\n sage: R.intersection(S)\n Order of Quaternion Algebra (-1, -11) with base ring Rational Field\n with basis (1/2 + 1/2*j, 1/2*i + 5/2*k, j, 3*k)\n sage: R.intersection(S) == S\n True\n sage: B = BrandtModule(11,5)\n sage: T = B.order_of_level_N()\n sage: S.intersection(T)\n Order of Quaternion Algebra (-1, -11) with base ring Rational Field\n with basis (1/2 + 1/2*j, 1/2*i + 23/2*k, j, 15*k)\n ' if (not isinstance(other, QuaternionOrder)): raise TypeError('other must be a QuaternionOrder') A = self.quaternion_algebra() if (other.quaternion_algebra() != A): raise ValueError('self and other must be in the same ambient quaternion algebra') V = (A.base_ring() ** 4) B = V.span([V(list(g)) for g in self.basis()], ZZ) C = V.span([V(list(g)) for g in other.basis()], ZZ) return QuaternionOrder(A, [A(list(e)) for e in B.intersection(C).basis()]) @cached_method def free_module(self): '\n Return the free `\\ZZ`-module that corresponds to this order\n inside the vector space corresponding to the ambient\n quaternion algebra.\n\n OUTPUT:\n\n A free `\\ZZ`-module of rank 4.\n\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order()\n sage: R.basis()\n (1/2 + 1/2*i, 1/2*j - 1/2*k, i, -k)\n sage: R.free_module()\n Free module of degree 4 and rank 4 over Integer Ring\n Echelon basis matrix:\n [1/2 1/2 0 0]\n [ 0 1 0 0]\n [ 0 0 1/2 1/2]\n [ 0 0 0 1]\n ' V = (self.quaternion_algebra().base_ring() ** 4) return V.span([V(list(g)) for g in self.basis()], ZZ) def discriminant(self): "\n Return the discriminant of this order.\n\n This is defined as\n `\\sqrt{ det ( Tr(e_i \\bar{e}_j ) ) }`, where `\\{e_i\\}` is the\n basis of the order.\n\n OUTPUT: rational number\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-11,-1).maximal_order().discriminant()\n 11\n sage: S = BrandtModule(11,5).order_of_level_N()\n sage: S.discriminant()\n 55\n sage: type(S.discriminant())\n <... 'sage.rings.rational.Rational'>\n " L = [] for d in self.basis(): MM = [] for e in self.basis(): MM.append(d.pair(e)) L.append(MM) return MatrixSpace(QQ, 4, 4)(L).determinant().sqrt() def left_ideal(self, gens, check=True): '\n Return the ideal with given gens over `\\ZZ`.\n\n INPUT:\n\n - ``gens`` -- a list of elements of this quaternion order\n\n - ``check`` -- bool (default: ``True``)\n\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order()\n sage: R.left_ideal([2*a for a in R.basis()])\n Fractional ideal (1 + i, 2*i, j + k, 2*k)\n ' if (self.base_ring() == ZZ): return QuaternionFractionalIdeal_rational(self.quaternion_algebra(), gens, left_order=self, check=check) else: raise NotImplementedError('ideal only implemented for quaternion algebras over QQ') def right_ideal(self, gens, check=True): '\n Return the ideal with given gens over `\\ZZ`.\n\n INPUT:\n\n - ``gens`` -- a list of elements of this quaternion order\n\n - ``check`` -- bool (default: ``True``)\n\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order()\n sage: R.right_ideal([2*a for a in R.basis()])\n Fractional ideal (1 + i, 2*i, j + k, 2*k)\n ' if (self.base_ring() == ZZ): return QuaternionFractionalIdeal_rational(self.quaternion_algebra(), gens, right_order=self, check=check) else: raise NotImplementedError('ideal only implemented for quaternion algebras over QQ') @cached_method def unit_ideal(self): '\n Return the unit ideal in this quaternion order.\n\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order()\n sage: I = R.unit_ideal(); I\n Fractional ideal (1/2 + 1/2*i, 1/2*j - 1/2*k, i, -k)\n ' if (self.base_ring() == ZZ): return QuaternionFractionalIdeal_rational(self.quaternion_algebra(), self.basis(), left_order=self, right_order=self, check=False) else: raise NotImplementedError('ideal only implemented for quaternion algebras over QQ') def basis_matrix(self): '\n Return the basis matrix of this quaternion order, for the\n specific basis returned by :meth:`basis()`.\n\n OUTPUT: matrix over `\\QQ`\n\n EXAMPLES::\n\n sage: O = QuaternionAlgebra(-11,-1).maximal_order()\n sage: O.basis()\n (1/2 + 1/2*i, 1/2*j - 1/2*k, i, -k)\n sage: O.basis_matrix()\n [ 1/2 1/2 0 0]\n [ 0 0 1/2 -1/2]\n [ 0 1 0 0]\n [ 0 0 0 -1]\n\n Note that the returned matrix is *not* necessarily the same as\n the basis matrix of the :meth:`unit_ideal()`::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-1,-11)\n sage: O = Q.quaternion_order([j,i,-1,k])\n sage: O.basis_matrix()\n [ 0 0 1 0]\n [ 0 1 0 0]\n [-1 0 0 0]\n [ 0 0 0 1]\n sage: O.unit_ideal().basis_matrix()\n [1 0 0 0]\n [0 1 0 0]\n [0 0 1 0]\n [0 0 0 1]\n ' return matrix(QQ, map(list, self.__basis)) def __mul__(self, other): '\n Every order equals its own unit ideal. Overload ideal multiplication\n and scaling to orders.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-1,-11)\n sage: O = Q.maximal_order()\n sage: I = O*j; I\n Fractional ideal (-11/2 + 1/2*j, -11/2*i + 1/2*k, -11, -11*i)\n ' return (self.unit_ideal() * other) def __rmul__(self, other): return (other * self.unit_ideal()) def __add__(self, other): '\n Every order equals its own unit ideal. Overload ideal addition\n to orders.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-1,-11)\n sage: O = Q.maximal_order()\n sage: I = O + O*((j-3)/5); I\n Fractional ideal (1/10 + 3/10*j, 1/10*i + 3/10*k, j, k)\n ' return (self.unit_ideal() + other) def quadratic_form(self): '\n Return the normalized quadratic form associated to this quaternion order.\n\n OUTPUT: quadratic form\n\n EXAMPLES::\n\n sage: R = BrandtModule(11,13).order_of_level_N()\n sage: Q = R.quadratic_form(); Q\n Quadratic form in 4 variables over Rational Field with coefficients:\n [ 14 253 55 286 ]\n [ * 1455 506 3289 ]\n [ * * 55 572 ]\n [ * * * 1859 ]\n sage: Q.theta_series(10)\n 1 + 2*q + 2*q^4 + 4*q^6 + 4*q^8 + 2*q^9 + O(q^10)\n ' return self.unit_ideal().quadratic_form() def ternary_quadratic_form(self, include_basis=False): '\n Return the ternary quadratic form associated to this order.\n\n INPUT:\n\n - ``include_basis`` -- bool (default: False), if True also\n return a basis for the dimension 3 subspace `G`\n\n OUTPUT:\n\n - QuadraticForm\n\n - optional basis for dimension 3 subspace\n\n This function computes the positive definition quadratic form\n obtained by letting G be the trace zero subspace of `\\ZZ` +\n 2* ``self``, which has rank 3, and restricting the pairing\n :meth:`QuaternionAlgebraElement_abstract.pair`::\n\n (x,y) = (x.conjugate()*y).reduced_trace()\n\n to `G`.\n\n APPLICATIONS: Ternary quadratic forms associated to an order\n in a rational quaternion algebra are useful in computing with\n Gross points, in decided whether quaternion orders have\n embeddings from orders in quadratic imaginary fields, and in\n computing elements of the Kohnen plus subspace of modular\n forms of weight 3/2.\n\n EXAMPLES::\n\n sage: R = BrandtModule(11,13).order_of_level_N()\n sage: Q = R.ternary_quadratic_form(); Q\n Quadratic form in 3 variables over Rational Field with coefficients:\n [ 5820 1012 13156 ]\n [ * 55 1144 ]\n [ * * 7436 ]\n sage: factor(Q.disc())\n 2^4 * 11^2 * 13^2\n\n The following theta series is a modular form of weight 3/2 and level 4*11*13::\n\n sage: Q.theta_series(100)\n 1 + 2*q^23 + 2*q^55 + 2*q^56 + 2*q^75 + 4*q^92 + O(q^100)\n ' if (self.base_ring() != ZZ): raise NotImplementedError('ternary quadratic form of order only implemented for quaternion algebras over QQ') Q = self.quaternion_algebra() twoR = self.free_module().scale(2) Z = twoR.span([Q(1).coefficient_tuple()], ZZ) S = (twoR + Z) v = [b.reduced_trace() for b in Q.basis()] M = matrix(QQ, 4, 1, v) tr0 = M.kernel() G = tr0.intersection(S) B = [Q(a) for a in G.basis()] m = matrix(QQ, [[x.pair(y) for x in B] for y in B]) from sage.quadratic_forms.quadratic_form import QuadraticForm Q = QuadraticForm(m) if include_basis: return (Q, B) else: return Q
class QuaternionFractionalIdeal(Ideal_fractional): pass
class QuaternionFractionalIdeal_rational(QuaternionFractionalIdeal): '\n A fractional ideal in a rational quaternion algebra.\n\n INPUT:\n\n - ``left_order`` -- a quaternion order or ``None``\n\n - ``right_order`` -- a quaternion order or ``None``\n\n - ``basis`` -- tuple of length 4 of elements in of ambient\n quaternion algebra whose `\\ZZ`-span is an ideal\n\n - ``check`` -- bool (default: ``True``); if ``False``, do no type\n checking.\n ' def __init__(self, Q, basis, left_order=None, right_order=None, check=True): '\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order()\n sage: R.right_ideal(R.basis())\n Fractional ideal (1/2 + 1/2*i, i, 1/2*j + 1/2*k, k)\n sage: R.right_ideal(tuple(R.basis()), check=False)\n Fractional ideal (1/2 + 1/2*i, 1/2*j - 1/2*k, i, -k)\n\n TESTS::\n\n sage: QuaternionAlgebra(-11,-1).maximal_order().unit_ideal().gens()\n (1/2 + 1/2*i, 1/2*j - 1/2*k, i, -k)\n\n Check that :trac:`31582` is fixed::\n\n sage: BrandtModule(23).right_ideals()[0].parent()\n Monoid of ideals of Quaternion Algebra (-1, -23) with base ring Rational Field\n ' if check: if ((left_order is not None) and (not isinstance(left_order, QuaternionOrder))): raise TypeError('left_order must be a quaternion order or None') if ((right_order is not None) and (not isinstance(right_order, QuaternionOrder))): raise TypeError('right_order must be a quaternion order or None') if (not isinstance(basis, (list, tuple))): raise TypeError('basis must be a list or tuple') basis = tuple([Q(v) for v in (QQ ** 4).span([Q(v).coefficient_tuple() for v in basis], ZZ).basis()]) self.__left_order = left_order self.__right_order = right_order Ideal_fractional.__init__(self, Q, basis) def scale(self, alpha, left=False): '\n Scale the fractional ideal ``self`` by multiplying the basis\n by ``alpha``.\n\n INPUT:\n\n - `\\alpha` -- element of quaternion algebra\n\n - ``left`` -- bool (default: False); if true multiply\n `\\alpha` on the left, otherwise multiply `\\alpha` on the right\n\n OUTPUT:\n\n - a new fractional ideal\n\n EXAMPLES::\n\n sage: B = BrandtModule(5,37); I = B.right_ideals()[0]\n sage: i,j,k = B.quaternion_algebra().gens(); I\n Fractional ideal (2 + 2*j + 106*k, i + 2*j + 105*k, 4*j + 64*k, 148*k)\n sage: I.scale(i)\n Fractional ideal (2*i + 212*j - 2*k, -2 + 210*j - 2*k, 128*j - 4*k, 296*j)\n sage: I.scale(i, left=True)\n Fractional ideal (2*i - 212*j + 2*k, -2 - 210*j + 2*k, -128*j + 4*k, -296*j)\n sage: I.scale(i, left=False)\n Fractional ideal (2*i + 212*j - 2*k, -2 + 210*j - 2*k, 128*j - 4*k, 296*j)\n sage: i * I.gens()[0]\n 2*i - 212*j + 2*k\n sage: I.gens()[0] * i\n 2*i + 212*j - 2*k\n\n TESTS:\n\n Scaling by `1` should not change anything (see :trac:`32245`)::\n\n sage: I.scale(1) == I\n True\n\n Check that :trac:`32726` is fixed::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-1,-19)\n sage: I = Q.ideal([1,i,j,k])\n sage: _ = I.left_order(), I.right_order() # cache\n sage: span = lambda L: L.basis_matrix().row_module(ZZ)\n sage: for left in (True,False):\n ....: J = I.scale(1+i+j+k, left=left)\n ....: Ol, Or = J.left_order(), J.right_order()\n ....: [\n ....: span(Ol.unit_ideal() * J) <= span(J),\n ....: span(J * Or.unit_ideal()) <= span(J),\n ....: ]\n [True, True]\n [True, True]\n ' Q = self.quaternion_algebra() alpha = Q(alpha) if left: gens = [(alpha * b) for b in self.basis()] else: gens = [(b * alpha) for b in self.basis()] left_order = (self.__left_order if ((alpha in QQ) or (not left)) else None) right_order = (self.__right_order if ((alpha in QQ) or left) else None) return Q.ideal(gens, check=False, left_order=left_order, right_order=right_order) def quaternion_algebra(self): '\n Return the ambient quaternion algebra that contains this fractional ideal.\n\n OUTPUT: a quaternion algebra\n\n EXAMPLES::\n\n sage: I = BrandtModule(3,5).right_ideals()[1]; I\n Fractional ideal (2 + 6*j + 4*k, 2*i + 4*j + 34*k, 8*j + 32*k, 40*k)\n sage: I.quaternion_algebra()\n Quaternion Algebra (-1, -3) with base ring Rational Field\n ' return Ideal_fractional.ring(self) def _compute_order(self, side='left'): "\n Used internally to compute either the left or right order\n associated to an ideal in a quaternion algebra. If\n action='right', compute the left order, and if action='left'\n compute the right order.\n\n INPUT:\n\n - ``side`` -- 'left' or 'right'\n\n EXAMPLES::\n\n sage: R.<i,j,k> = QuaternionAlgebra(-1,-11)\n sage: I = R.ideal([2 + 2*j + 140*k, 2*i + 4*j + 150*k, 8*j + 104*k, 152*k])\n sage: Ol = I._compute_order('left'); Ol\n Order of Quaternion Algebra (-1, -11) with base ring Rational Field\n with basis (1/2 + 1/2*j + 35*k, 1/4*i + 1/2*j + 75/4*k, j + 32*k, 38*k)\n sage: Or = I._compute_order('right'); Or\n Order of Quaternion Algebra (-1, -11) with base ring Rational Field\n with basis (1/2 + 1/2*j + 16*k, 1/2*i + 11/2*k, j + 13*k, 19*k)\n sage: Ol.discriminant()\n 209\n sage: Or.discriminant()\n 209\n sage: I.left_order() == Ol\n True\n sage: I.right_order() == Or\n True\n\n ALGORITHM: Let `b_1, b_2, b_3, b_3` be a basis for this\n fractional ideal `I`, and assume we want to compute the left\n order of `I` in the quaternion algebra `Q`. Then\n multiplication by `b_i` on the right defines a map `B_i:Q \\to\n Q`. We have\n\n .. MATH::\n\n R = B_1^{-1}(I) \\cap B_2^{-1}(I) \\cap B_3^{-1}(I)\\cap B_4^{-1}(I).\n\n This is because\n\n .. MATH::\n\n B_n^{-1}(I) = \\{\\alpha \\in Q : \\alpha b_n \\in I \\},\n\n and\n\n .. MATH::\n\n R = \\{\\alpha \\in Q : \\alpha b_n \\in I, n=1,2,3,4\\}.\n " if (side == 'left'): action = 'right' elif (side == 'right'): action = 'left' else: raise ValueError("side must be 'left' or 'right'") Q = self.quaternion_algebra() if (Q.base_ring() != QQ): raise NotImplementedError('computation of left and right orders only implemented over QQ') M = [(~ b).matrix(action=action) for b in self.basis()] B = self.basis_matrix() invs = [(B * m) for m in M] ISB = [Q(v) for v in intersection_of_row_modules_over_ZZ(invs).row_module(ZZ).basis()] return Q.quaternion_order(ISB) def left_order(self): '\n Return the left order associated to this fractional ideal.\n\n OUTPUT: an order in a quaternion algebra\n\n EXAMPLES::\n\n sage: B = BrandtModule(11)\n sage: R = B.maximal_order()\n sage: I = R.unit_ideal()\n sage: I.left_order()\n Order of Quaternion Algebra (-1, -11) with base ring Rational Field\n with basis (1/2 + 1/2*j, 1/2*i + 1/2*k, j, k)\n\n We do a consistency check::\n\n sage: B = BrandtModule(11,19); R = B.right_ideals()\n sage: [r.left_order().discriminant() for r in R]\n [209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209]\n ' if (self.__left_order is None): self.__left_order = self._compute_order(side='left') return self.__left_order def right_order(self): '\n Return the right order associated to this fractional ideal.\n\n OUTPUT: an order in a quaternion algebra\n\n EXAMPLES::\n\n sage: I = BrandtModule(389).right_ideals()[1]; I\n Fractional ideal (2 + 6*j + 2*k, i + 2*j + k, 8*j, 8*k)\n sage: I.right_order()\n Order of Quaternion Algebra (-2, -389) with base ring Rational Field\n with basis (1/2 + 1/2*j + 1/2*k, 1/4*i + 1/2*j + 1/4*k, j, k)\n sage: I.left_order()\n Order of Quaternion Algebra (-2, -389) with base ring Rational Field\n with basis (1/2 + 1/2*j + 3/2*k, 1/8*i + 1/4*j + 9/8*k, j + k, 2*k)\n\n The following is a big consistency check. We take reps for\n all the right ideal classes of a certain order, take the\n corresponding left orders, then take ideals in the left orders\n and from those compute the right order again::\n\n sage: B = BrandtModule(11,19); R = B.right_ideals()\n sage: O = [r.left_order() for r in R]\n sage: J = [O[i].left_ideal(R[i].basis()) for i in range(len(R))]\n sage: len(set(J))\n 18\n sage: len(set([I.right_order() for I in J]))\n 1\n sage: J[0].right_order() == B.order_of_level_N()\n True\n ' if (self.__right_order is None): self.__right_order = self._compute_order(side='right') return self.__right_order def __repr__(self): "\n Return string representation of this quaternion fractional ideal.\n\n EXAMPLES::\n\n sage: I = BrandtModule(11).right_ideals()[1]\n sage: type(I)\n <class 'sage.algebras.quatalg.quaternion_algebra.QuaternionFractionalIdeal_rational'>\n sage: I.__repr__()\n 'Fractional ideal (2 + 6*j + 4*k, 2*i + 4*j + 2*k, 8*j, 8*k)'\n " return ('Fractional ideal %s' % (self.gens(),)) def quaternion_order(self): '\n Return the order for which this ideal is a left or right\n fractional ideal.\n\n If this ideal has both a left and right\n ideal structure, then the left order is returned. If it has\n neither structure, then an error is raised.\n\n OUTPUT: QuaternionOrder\n\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order()\n sage: R.unit_ideal().quaternion_order() is R\n doctest:...: DeprecationWarning: quaternion_order() is deprecated,\n please use left_order() or right_order()\n See https://github.com/sagemath/sage/issues/31583 for details.\n True\n ' from sage.misc.superseded import deprecation deprecation(31583, 'quaternion_order() is deprecated, please use left_order() or right_order()') try: return self.__quaternion_order except AttributeError: pass if (self.__left_order is not None): A = self.__left_order elif (self.__right_order is not None): A = self.__right_order else: raise RuntimeError('unable to determine quaternion order of ideal without known order') self.__quaternion_order = A return A def ring(self): '\n Return ring that this is a fractional ideal for.\n\n The :meth:`ring` method will be removed from this class in the\n future. Calling :meth:`ring` will then return the ambient\n quaternion algebra. This is consistent with the behaviour for\n number fields.\n\n EXAMPLES::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order()\n sage: R.unit_ideal().ring() is R\n doctest:...: DeprecationWarning: ring() will return the quaternion algebra in the future, please use left_order() or right_order()\n See https://github.com/sagemath/sage/issues/31583 for details.\n True\n ' from sage.misc.superseded import deprecation deprecation(31583, 'ring() will return the quaternion algebra in the future, please use left_order() or right_order()') if (self.__left_order is not None): return self.__left_order elif (self.__right_order is not None): return self.__right_order else: raise RuntimeError('unable to determine quaternion order of ideal without known order') def basis(self): '\n Return a basis for this fractional ideal.\n\n OUTPUT: tuple\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-11,-1).maximal_order().unit_ideal().basis()\n (1/2 + 1/2*i, 1/2*j - 1/2*k, i, -k)\n ' return self.gens() def _richcmp_(self, right, op): '\n Compare this fractional quaternion ideal to ``right``.\n\n EXAMPLES::\n\n sage: I = QuaternionAlgebra(-11, -1).maximal_order().unit_ideal()\n sage: I == I # indirect doctest\n True\n sage: I == 5\n False\n\n sage: J = QuaternionAlgebra(-7, -1).maximal_order().unit_ideal()\n sage: J == I\n False\n\n Ideals can be equal even if they are defined by different\n bases (see :trac:`32245`)::\n\n sage: I == I.scale(-1)\n True\n\n sage: I != I # indirect doctest\n False\n ' return self.basis_matrix()._richcmp_(right.basis_matrix(), op) def __hash__(self): '\n Return the hash of ``self``.\n\n EXAMPLES::\n\n sage: I = QuaternionAlgebra(-11,-1).maximal_order().unit_ideal()\n sage: hash(I) == hash(I)\n True\n\n TESTS::\n\n sage: R = QuaternionAlgebra(-11,-1).maximal_order()\n sage: H = hash(R.right_ideal(R.basis()))\n ' return hash(self.gens()) @cached_method def basis_matrix(self): '\n Return basis matrix `M` in Hermite normal form for self as a\n matrix with rational entries.\n\n If `Q` is the ambient quaternion algebra, then the `\\ZZ`-span of\n the rows of `M` viewed as linear combinations of Q.basis() =\n `[1,i,j,k]` is the fractional ideal self. Also,\n ``M * M.denominator()`` is an integer matrix in Hermite normal form.\n\n OUTPUT: matrix over `\\QQ`\n\n EXAMPLES::\n\n sage: QuaternionAlgebra(-11,-1).maximal_order().unit_ideal().basis_matrix()\n [1/2 1/2 0 0]\n [ 0 1 0 0]\n [ 0 0 1/2 1/2]\n [ 0 0 0 1]\n ' B = quaternion_algebra_cython.rational_matrix_from_rational_quaternions(self.gens()) (C, d) = B._clear_denom() return (C.hermite_form() / d) def theta_series_vector(self, B): '\n Return theta series coefficients of ``self``, as a vector\n of ``B`` integers.\n\n INPUT:\n\n - ``B`` -- positive integer\n\n OUTPUT:\n\n Vector over `\\ZZ` with ``B`` entries.\n\n EXAMPLES::\n\n sage: I = BrandtModule(37).right_ideals()[1]; I\n Fractional ideal (2 + 6*j + 2*k, i + 2*j + k, 8*j, 8*k)\n sage: I.theta_series_vector(5)\n (1, 0, 2, 2, 6)\n sage: I.theta_series_vector(10)\n (1, 0, 2, 2, 6, 4, 8, 6, 10, 10)\n sage: I.theta_series_vector(5)\n (1, 0, 2, 2, 6)\n ' B = Integer(B) try: if (len(self.__theta_series_vector) >= B): return self.__theta_series_vector[:B] except AttributeError: pass V = FreeModule(ZZ, B) Q = self.quadratic_form() v = V(Q.representation_number_list(B)) self.__theta_series_vector = v return v @cached_method def quadratic_form(self): '\n Return the normalized quadratic form associated to this quaternion ideal.\n\n OUTPUT: quadratic form\n\n EXAMPLES::\n\n sage: I = BrandtModule(11).right_ideals()[1]\n sage: Q = I.quadratic_form(); Q\n Quadratic form in 4 variables over Rational Field with coefficients:\n [ 18 22 33 22 ]\n [ * 7 22 11 ]\n [ * * 22 0 ]\n [ * * * 22 ]\n sage: Q.theta_series(10)\n 1 + 12*q^2 + 12*q^3 + 12*q^4 + 12*q^5 + 24*q^6 + 24*q^7 + 36*q^8 + 36*q^9 + O(q^10)\n sage: I.theta_series(10)\n 1 + 12*q^2 + 12*q^3 + 12*q^4 + 12*q^5 + 24*q^6 + 24*q^7 + 36*q^8 + 36*q^9 + O(q^10)\n ' from sage.quadratic_forms.quadratic_form import QuadraticForm gram_matrix = self.gram_matrix() (gram_matrix, _) = gram_matrix._clear_denom() g = gram_matrix.gcd() if (g != 1): gram_matrix = (gram_matrix / g) return QuadraticForm(gram_matrix) def theta_series(self, B, var='q'): "\n Return normalized theta series of ``self``, as a power series over\n `\\ZZ` in the variable ``var``, which is 'q' by default.\n\n The normalized theta series is by definition\n\n .. MATH::\n\n \\theta_I(q) = \\sum_{x \\in I} q^{\\frac{N(x)}{N(I)}}.\n\n INPUT:\n\n - ``B`` -- positive integer\n - ``var`` -- string (default: 'q')\n\n OUTPUT: power series\n\n EXAMPLES::\n\n sage: I = BrandtModule(11).right_ideals()[1]; I\n Fractional ideal (2 + 6*j + 4*k, 2*i + 4*j + 2*k, 8*j, 8*k)\n sage: I.norm()\n 32\n sage: I.theta_series(5)\n 1 + 12*q^2 + 12*q^3 + 12*q^4 + O(q^5)\n sage: I.theta_series(5,'T')\n 1 + 12*T^2 + 12*T^3 + 12*T^4 + O(T^5)\n sage: I.theta_series(3)\n 1 + 12*q^2 + O(q^3)\n " try: if (self.__theta_series.prec() >= B): if (var == self.__theta_series.variable()): return self.__theta_series.add_bigoh(B) else: p_ring = self._theta_series.parent().change_var(var) p_ring(self.__theta_series.list()[:(B + 1)]) except AttributeError: pass v = self.theta_series_vector(B) p_ring = PowerSeriesRing(ZZ, var) theta = p_ring(v.list()).add_bigoh(B) self.__theta_series = theta return theta @cached_method def gram_matrix(self): '\n Return the Gram matrix of this fractional ideal.\n\n OUTPUT: `4 \\times 4` matrix over `\\QQ`.\n\n EXAMPLES::\n\n sage: I = BrandtModule(3,5).right_ideals()[1]; I\n Fractional ideal (2 + 6*j + 4*k, 2*i + 4*j + 34*k, 8*j + 32*k, 40*k)\n sage: I.gram_matrix()\n [ 640 1920 2112 1920]\n [ 1920 14080 13440 16320]\n [ 2112 13440 13056 15360]\n [ 1920 16320 15360 19200]\n ' A = self.gens() two = QQ(2) m = [(two * a.pair(b)) for b in A for a in A] M44 = MatrixSpace(QQ, 4, 4) return M44(m, coerce=False) def norm(self): "\n Return the reduced norm of this fractional ideal.\n\n OUTPUT: rational number\n\n EXAMPLES::\n\n sage: M = BrandtModule(37)\n sage: C = M.right_ideals()\n sage: [I.norm() for I in C]\n [16, 32, 32]\n\n sage: # optional - magma\n sage: (a,b) = M.quaternion_algebra().invariants()\n sage: magma.eval('A<i,j,k> := QuaternionAlgebra<Rationals() | %s, %s>' % (a,b))\n ''\n sage: magma.eval('O := QuaternionOrder(%s)' % str(list(C[0].right_order().basis())))\n ''\n sage: [ magma('rideal<O | %s>' % str(list(I.basis()))).Norm() for I in C]\n [16, 32, 32]\n\n sage: A.<i,j,k> = QuaternionAlgebra(-1,-1)\n sage: R = A.ideal([i,j,k,1/2 + 1/2*i + 1/2*j + 1/2*k]) # this is actually an order, so has reduced norm 1\n sage: R.norm()\n 1\n sage: [ J.norm() for J in R.cyclic_right_subideals(3) ] # enumerate maximal right R-ideals of reduced norm 3, verify their norms\n [3, 3, 3, 3]\n " G = (self.gram_matrix() / QQ(2)) r = G.det().abs() assert r.is_square(), 'first is bad!' r = r.sqrt() R = (self.__left_order or self.__right_order or self.left_order()) r /= R.discriminant() assert r.is_square(), 'second is bad!' return r.sqrt() def conjugate(self): '\n Return the ideal with generators the conjugates of the generators for self.\n\n OUTPUT: a quaternionic fractional ideal\n\n EXAMPLES::\n\n sage: I = BrandtModule(3,5).right_ideals()[1]; I\n Fractional ideal (2 + 6*j + 4*k, 2*i + 4*j + 34*k, 8*j + 32*k, 40*k)\n sage: I.conjugate()\n Fractional ideal (2 + 2*j + 28*k, 2*i + 4*j + 34*k, 8*j + 32*k, 40*k)\n ' return self.quaternion_algebra().ideal([b.conjugate() for b in self.basis()], left_order=self.__right_order, right_order=self.__left_order) def __mul__(self, right): '\n Return the product of the fractional ideals ``self`` and ``right``.\n\n .. note::\n\n We do not keep track of left or right order structure.\n\n EXAMPLES::\n\n sage: I = BrandtModule(3,5).right_ideals()[1]; I\n Fractional ideal (2 + 6*j + 4*k, 2*i + 4*j + 34*k, 8*j + 32*k, 40*k)\n sage: I*I\n Fractional ideal (8 + 24*j + 16*k, 8*i + 16*j + 136*k, 32*j + 128*k, 160*k)\n sage: I*I.conjugate()\n Fractional ideal (16 + 16*j + 224*k, 8*i + 16*j + 136*k, 32*j + 128*k, 320*k)\n sage: I.multiply_by_conjugate(I)\n Fractional ideal (16 + 16*j + 224*k, 8*i + 16*j + 136*k, 32*j + 128*k, 320*k)\n ' if isinstance(right, QuaternionOrder): right = right.unit_ideal() if (not isinstance(right, QuaternionFractionalIdeal_rational)): return self.scale(right, left=False) gens = [(a * b) for a in self.basis() for b in right.basis()] basis = tuple(basis_for_quaternion_lattice(gens, reverse=False)) A = self.quaternion_algebra() return A.ideal(basis, check=False) def __add__(self, other): '\n Return the sum of the fractional ideals ``self`` and ``other``.\n\n EXAMPLES::\n\n sage: I = BrandtModule(11,5).right_ideals()[1]; I\n Fractional ideal (2 + 2*j + 20*k, 2*i + 4*j + 6*k, 8*j, 40*k)\n sage: J = BrandtModule(11,5).right_ideals()[2]; J\n Fractional ideal (2 + 6*j + 20*k, 2*i + 4*j + 26*k, 8*j, 40*k)\n sage: I + J\n Fractional ideal (2 + 2*j, 2*i + 6*k, 4*j, 20*k)\n ' if isinstance(other, QuaternionOrder): other = other.unit_ideal() if (not isinstance(other, QuaternionFractionalIdeal_rational)): raise TypeError('can only add quaternion ideals') return self.quaternion_algebra().ideal((self.basis() + other.basis())) def _acted_upon_(self, other, on_left): '\n Scale a quaternion ideal.\n\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-1,-419)\n sage: O = Q.maximal_order()\n sage: I = 7*O.unit_ideal() + O.unit_ideal()*(j-1); I\n Fractional ideal (1/2 + 13/2*j, 1/2*i + 13/2*k, 7*j, 7*k)\n\n TESTS::\n\n sage: (5+i-j)*I == I.scale(5+i-j, left=True)\n True\n sage: I*(5+i-j) == I.scale(5+i-j, left=False)\n True\n ' return self.scale(other, left=(not on_left)) @cached_method def free_module(self): '\n Return the underlying free `\\ZZ`-module corresponding to this ideal.\n\n OUTPUT:\n\n Free `\\ZZ`-module of rank 4 embedded in an ambient `\\QQ^4`.\n\n EXAMPLES::\n\n sage: X = BrandtModule(3,5).right_ideals()\n sage: X[0]\n Fractional ideal (2 + 2*j + 8*k, 2*i + 18*k, 4*j + 16*k, 20*k)\n sage: X[0].free_module()\n Free module of degree 4 and rank 4 over Integer Ring\n Echelon basis matrix:\n [ 2 0 2 8]\n [ 0 2 0 18]\n [ 0 0 4 16]\n [ 0 0 0 20]\n sage: X[0].scale(1/7).free_module()\n Free module of degree 4 and rank 4 over Integer Ring\n Echelon basis matrix:\n [ 2/7 0 2/7 8/7]\n [ 0 2/7 0 18/7]\n [ 0 0 4/7 16/7]\n [ 0 0 0 20/7]\n\n sage: QuaternionAlgebra(-11,-1).maximal_order().unit_ideal().basis_matrix()\n [1/2 1/2 0 0]\n [ 0 1 0 0]\n [ 0 0 1/2 1/2]\n [ 0 0 0 1]\n\n The free module method is also useful since it allows for checking if\n one ideal is contained in another, computing quotients `I/J`, etc.::\n\n sage: X = BrandtModule(3,17).right_ideals()\n sage: I = X[0].intersection(X[2]); I\n Fractional ideal (2 + 2*j + 164*k, 2*i + 4*j + 46*k, 16*j + 224*k, 272*k)\n sage: I.free_module().is_submodule(X[3].free_module())\n False\n sage: I.free_module().is_submodule(X[1].free_module())\n True\n sage: X[0].free_module() / I.free_module()\n Finitely generated module V/W over Integer Ring with invariants (4, 4)\n\n This shows that the issue at :trac:`6760` is fixed::\n\n sage: R.<i,j,k> = QuaternionAlgebra(-1, -13)\n sage: I = R.ideal([2+i, 3*i, 5*j, j+k]); I\n Fractional ideal (2 + i, 3*i, j + k, 5*k)\n sage: I.free_module()\n Free module of degree 4 and rank 4 over Integer Ring\n Echelon basis matrix:\n [2 1 0 0]\n [0 3 0 0]\n [0 0 1 1]\n [0 0 0 5]\n ' return self.basis_matrix().row_module(ZZ) def intersection(self, J): '\n Return the intersection of the ideals self and `J`.\n\n EXAMPLES::\n\n sage: X = BrandtModule(3,5).right_ideals()\n sage: I = X[0].intersection(X[1]); I\n Fractional ideal (2 + 6*j + 4*k, 2*i + 4*j + 34*k, 8*j + 32*k, 40*k)\n\n ' V = self.free_module().intersection(J.free_module()) (H, d) = V.basis_matrix()._clear_denom() A = self.quaternion_algebra() gens = quaternion_algebra_cython.rational_quaternions_from_integral_matrix_and_denom(A, H, d) return A.ideal(gens) def multiply_by_conjugate(self, J): '\n Return product of self and the conjugate Jbar of `J`.\n\n INPUT:\n\n - ``J`` -- a quaternion ideal.\n\n OUTPUT: a quaternionic fractional ideal.\n\n EXAMPLES::\n\n sage: R = BrandtModule(3,5).right_ideals()\n sage: R[0].multiply_by_conjugate(R[1])\n Fractional ideal (8 + 8*j + 112*k, 8*i + 16*j + 136*k, 32*j + 128*k, 160*k)\n sage: R[0]*R[1].conjugate()\n Fractional ideal (8 + 8*j + 112*k, 8*i + 16*j + 136*k, 32*j + 128*k, 160*k)\n ' Jbar = [b.conjugate() for b in J.basis()] gens = [(a * b) for a in self.basis() for b in Jbar] basis = tuple(basis_for_quaternion_lattice(gens, reverse=False)) R = self.quaternion_algebra() return R.ideal(basis, check=False) def is_equivalent(self, J, B=10) -> bool: '\n Return ``True`` if ``self`` and ``J`` are equivalent as right ideals.\n\n INPUT:\n\n - ``J`` -- a fractional quaternion ideal with same order as ``self``\n\n - ``B`` -- a bound to compute and compare theta series before\n doing the full equivalence test\n\n OUTPUT: bool\n\n EXAMPLES::\n\n sage: R = BrandtModule(3,5).right_ideals(); len(R)\n 2\n sage: R[0].is_equivalent(R[1])\n False\n sage: R[0].is_equivalent(R[0])\n True\n sage: OO = R[0].left_order()\n sage: S = OO.right_ideal([3*a for a in R[0].basis()])\n sage: R[0].is_equivalent(S)\n True\n ' if (not isinstance(self, QuaternionFractionalIdeal_rational)): return False if (self.right_order() != J.right_order()): raise ValueError('self and J must be right ideals') if ((B > 0) and (self.theta_series_vector(B) != J.theta_series_vector(B))): return False IJbar = self.multiply_by_conjugate(J) c = IJbar.theta_series_vector(2)[1] return (c != 0) def __contains__(self, x): '\n Return whether x is in self.\n\n EXAMPLES::\n\n sage: R.<i,j,k> = QuaternionAlgebra(-3, -13)\n sage: I = R.ideal([2+i, 3*i, 5*j, j+k])\n sage: 2+i in I\n True\n sage: 2+i+j+k in I\n True\n sage: 1+i in I\n False\n sage: 101*j + k in I\n True\n ' try: x = self.quaternion_algebra()(x) return (self.basis_matrix().transpose().solve_right(vector(x)) in (ZZ ** 4)) except (ValueError, TypeError): return False @cached_method def cyclic_right_subideals(self, p, alpha=None): "\n Let `I` = ``self``. This function returns the right subideals\n `J` of `I` such that `I/J` is an `\\GF{p}`-vector space of\n dimension 2.\n\n INPUT:\n\n - ``p`` -- prime number (see below)\n\n - ``alpha`` -- (default: ``None``) element of quaternion algebra,\n which can be used to parameterize the order of the\n ideals `J`. More precisely the `J`'s are the right annihilators\n of `(1,0) \\alpha^i` for `i=0,1,2,...,p`\n\n OUTPUT:\n\n - list of right ideals\n\n .. NOTE::\n\n Currently, `p` must satisfy a bunch of conditions, or a\n :class:`NotImplementedError` is raised. In particular, `p` must\n be odd and unramified in the quaternion algebra, must be\n coprime to the index of the right order in the maximal\n order, and also coprime to the normal of self. (The Brandt\n modules code has a more general algorithm in some cases.)\n\n EXAMPLES::\n\n sage: B = BrandtModule(2,37); I = B.right_ideals()[0]\n sage: I.cyclic_right_subideals(3)\n [Fractional ideal (2 + 2*i + 10*j + 90*k, 4*i + 4*j + 152*k, 12*j + 132*k, 444*k),\n Fractional ideal (2 + 2*i + 2*j + 150*k, 4*i + 8*j + 196*k, 12*j + 132*k, 444*k),\n Fractional ideal (2 + 2*i + 6*j + 194*k, 4*i + 8*j + 344*k, 12*j + 132*k, 444*k),\n Fractional ideal (2 + 2*i + 6*j + 46*k, 4*i + 4*j + 4*k, 12*j + 132*k, 444*k)]\n\n sage: B = BrandtModule(5,389); I = B.right_ideals()[0]\n sage: C = I.cyclic_right_subideals(3); C\n [Fractional ideal (2 + 10*j + 546*k, i + 6*j + 133*k, 12*j + 3456*k, 4668*k),\n Fractional ideal (2 + 2*j + 2910*k, i + 6*j + 3245*k, 12*j + 3456*k, 4668*k),\n Fractional ideal (2 + i + 2295*k, 3*i + 2*j + 3571*k, 4*j + 2708*k, 4668*k),\n Fractional ideal (2 + 2*i + 2*j + 4388*k, 3*i + 2*j + 2015*k, 4*j + 4264*k, 4668*k)]\n sage: [(I.free_module()/J.free_module()).invariants() for J in C]\n [(3, 3), (3, 3), (3, 3), (3, 3)]\n sage: I.scale(3).cyclic_right_subideals(3)\n [Fractional ideal (6 + 30*j + 1638*k, 3*i + 18*j + 399*k, 36*j + 10368*k, 14004*k),\n Fractional ideal (6 + 6*j + 8730*k, 3*i + 18*j + 9735*k, 36*j + 10368*k, 14004*k),\n Fractional ideal (6 + 3*i + 6885*k, 9*i + 6*j + 10713*k, 12*j + 8124*k, 14004*k),\n Fractional ideal (6 + 6*i + 6*j + 13164*k, 9*i + 6*j + 6045*k, 12*j + 12792*k, 14004*k)]\n sage: C = I.scale(1/9).cyclic_right_subideals(3); C\n [Fractional ideal (2/9 + 10/9*j + 182/3*k, 1/9*i + 2/3*j + 133/9*k, 4/3*j + 384*k, 1556/3*k),\n Fractional ideal (2/9 + 2/9*j + 970/3*k, 1/9*i + 2/3*j + 3245/9*k, 4/3*j + 384*k, 1556/3*k),\n Fractional ideal (2/9 + 1/9*i + 255*k, 1/3*i + 2/9*j + 3571/9*k, 4/9*j + 2708/9*k, 1556/3*k),\n Fractional ideal (2/9 + 2/9*i + 2/9*j + 4388/9*k, 1/3*i + 2/9*j + 2015/9*k, 4/9*j + 4264/9*k, 1556/3*k)]\n sage: [(I.scale(1/9).free_module()/J.free_module()).invariants() for J in C]\n [(3, 3), (3, 3), (3, 3), (3, 3)]\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-2,-5)\n sage: I = Q.ideal([Q(1),i,j,k])\n sage: I.cyclic_right_subideals(3)\n [Fractional ideal (1 + 2*j, i + k, 3*j, 3*k),\n Fractional ideal (1 + j, i + 2*k, 3*j, 3*k),\n Fractional ideal (1 + 2*i, 3*i, j + 2*k, 3*k),\n Fractional ideal (1 + i, 3*i, j + k, 3*k)]\n\n The general algorithm is not yet implemented here::\n\n sage: I.cyclic_right_subideals(3)[0].cyclic_right_subideals(3)\n Traceback (most recent call last):\n ...\n NotImplementedError: general algorithm not implemented\n (The given basis vectors must be linearly independent.)\n " R = self.right_order() Q = self.quaternion_algebra() f = Q.modp_splitting_map(p) if (alpha is not None): alpha = f(alpha) W = (GF(p) ** 4) try: A = W.span_of_basis([W(f(a).list()) for a in self.basis()]) scale = 1 IB = self.basis_matrix() except (ValueError, ZeroDivisionError): (B, d) = self.basis_matrix()._clear_denom() g = gcd(B.list()) IB = (B / g) scale = (g / d) try: A = W.span_of_basis([W(f(Q(a.list())).list()) for a in IB.rows()]) except (ValueError, ZeroDivisionError) as msg: raise NotImplementedError(('general algorithm not implemented (%s)' % msg)) Ai = (A.basis_matrix() ** (- 1)) AiB = (Ai.change_ring(QQ) * IB) (AiB, _) = AiB._clear_denom() pB = (p * IB) (pB, d) = pB._clear_denom() ans = [] Z = matrix(ZZ, 2, 4) P1 = P1List(p) if (alpha is None): lines = P1 else: x = alpha lines = [] for _ in range((p + 1)): lines.append(P1.normalize(x[(0, 0)], x[(0, 1)])) x *= alpha for (u, v) in lines: Z[(0, 1)] = (- v) Z[(0, 3)] = u Z[(1, 0)] = (- v) Z[(1, 2)] = u z = (Z * AiB) G = (d * z).stack(pB) H = G._hnf_pari(0, include_zero_rows=False) gens = tuple(quaternion_algebra_cython.rational_quaternions_from_integral_matrix_and_denom(Q, H, d)) if (scale != 1): gens = tuple([(scale * gg) for gg in gens]) J = R.right_ideal(gens, check=False) ans.append(J) return ans
def basis_for_quaternion_lattice(gens, reverse=None): '\n Return a basis for the `\\ZZ`-lattice in a quaternion algebra\n spanned by the given gens.\n\n INPUT:\n\n - ``gens`` -- list of elements of a single quaternion algebra\n\n - ``reverse`` -- when computing the HNF do it on the basis\n `(k,j,i,1)` instead of `(1,i,j,k)`; this ensures\n that if ``gens`` are the generators for an order,\n the first returned basis vector is 1\n\n EXAMPLES::\n\n sage: from sage.algebras.quatalg.quaternion_algebra import basis_for_quaternion_lattice\n sage: A.<i,j,k> = QuaternionAlgebra(-1,-7)\n sage: basis_for_quaternion_lattice([i+j, i-j, 2*k, A(1/3)])\n doctest:warning ... DeprecationWarning: ...\n [1/3, i + j, 2*j, 2*k]\n\n sage: basis_for_quaternion_lattice([A(1),i,j,k])\n [1, i, j, k]\n\n ' if (reverse is None): from sage.misc.superseded import deprecation deprecation(34880, 'The default value for the "reverse" argument to basis_for_quaternion_lattice() will change from False to True. Pass the argument explicitly to silence this warning.') reverse = False if (not gens): return [] (Z, d) = quaternion_algebra_cython.integral_matrix_and_denom_from_rational_quaternions(gens, reverse) H = Z._hnf_pari(0, include_zero_rows=False) A = gens[0].parent() return quaternion_algebra_cython.rational_quaternions_from_integral_matrix_and_denom(A, H, d, reverse)
def intersection_of_row_modules_over_ZZ(v): '\n Intersect the `\\ZZ`-modules with basis matrices the full rank `4 \\times 4`\n `\\QQ`-matrices in the list v.\n\n The returned intersection is\n represented by a `4 \\times 4` matrix over `\\QQ`. This can also be done\n using modules and intersection, but that would take over twice as long\n because of overhead, hence this function.\n\n EXAMPLES::\n\n sage: a = matrix(QQ,4,[-2, 0, 0, 0, 0, -1, -1, 1, 2, -1/2, 0, 0, 1, 1, -1, 0])\n sage: b = matrix(QQ,4,[0, -1/2, 0, -1/2, 2, 1/2, -1, -1/2, 1, 2, 1, -2, 0, -1/2, -2, 0])\n sage: c = matrix(QQ,4,[0, 1, 0, -1/2, 0, 0, 2, 2, 0, -1/2, 1/2, -1, 1, -1, -1/2, 0])\n sage: v = [a,b,c]\n sage: from sage.algebras.quatalg.quaternion_algebra import intersection_of_row_modules_over_ZZ\n sage: M = intersection_of_row_modules_over_ZZ(v); M\n [ 2 0 -1 -1]\n [ -4 1 1 -3]\n [ -3 19/2 -1 -4]\n [ 2 -3 -8 4]\n sage: M2 = a.row_module(ZZ).intersection(b.row_module(ZZ)).intersection(c.row_module(ZZ))\n sage: M.row_module(ZZ) == M2\n True\n ' if (len(v) <= 0): raise ValueError('v must have positive length') if (len(v) == 1): return v[0] elif (len(v) == 2): (a, b) = v (s, _) = a.stack(b)._clear_denom() s = s.transpose() K = s.right_kernel_matrix(algorithm='pari', basis='computed') n = a.nrows() return (K.matrix_from_columns(range(n)) * a) else: w = intersection_of_row_modules_over_ZZ(v[:2]) return intersection_of_row_modules_over_ZZ(([w] + v[2:]))
def normalize_basis_at_p(e, p, B=QuaternionAlgebraElement_abstract.pair): '\n Compute a (at ``p``) normalized basis from the given basis ``e``\n of a `\\ZZ`-module.\n\n The returned basis is (at ``p``) a `\\ZZ_p` basis for the same\n module, and has the property that with respect to it the quadratic\n form induced by the bilinear form B is represented as a orthogonal\n sum of atomic forms multiplied by p-powers.\n\n If `p \\neq 2` this means that the form is diagonal with respect to\n this basis.\n\n If `p = 2` there may be additional 2-dimensional subspaces on which\n the form is represented as `2^e (ax^2 + bxy + cx^2)` with\n `0 = v_2(b) = v_2(a) \\leq v_2(c)`.\n\n INPUT:\n\n - ``e`` -- list; basis of a `\\ZZ` module.\n WARNING: will be modified!\n\n - ``p`` -- prime for at which the basis should be normalized\n\n - ``B`` --\n (default: :meth:`QuaternionAlgebraElement_abstract.pair`)\n a bilinear form with respect to which to normalize\n\n OUTPUT:\n\n - A list containing two-element tuples: The first element of\n each tuple is a basis element, the second the valuation of\n the orthogonal summand to which it belongs. The list is sorted\n by ascending valuation.\n\n EXAMPLES::\n\n sage: from sage.algebras.quatalg.quaternion_algebra import normalize_basis_at_p\n sage: A.<i,j,k> = QuaternionAlgebra(-1, -1)\n sage: e = [A(1), i, j, k]\n sage: normalize_basis_at_p(e, 2)\n [(1, 0), (i, 0), (j, 0), (k, 0)]\n\n sage: A.<i,j,k> = QuaternionAlgebra(210)\n sage: e = [A(1), i, j, k]\n sage: normalize_basis_at_p(e, 2)\n [(1, 0), (i, 1), (j, 1), (k, 2)]\n\n sage: A.<i,j,k> = QuaternionAlgebra(286)\n sage: e = [A(1), k, 1/2*j + 1/2*k, 1/2 + 1/2*i + 1/2*k]\n sage: normalize_basis_at_p(e, 5)\n [(1, 0), (1/2*j + 1/2*k, 0), (-5/6*j + 1/6*k, 1), (1/2*i, 1)]\n\n sage: A.<i,j,k> = QuaternionAlgebra(-1,-7)\n sage: e = [A(1), k, j, 1/2 + 1/2*i + 1/2*j + 1/2*k]\n sage: normalize_basis_at_p(e, 2)\n [(1, 0), (1/2 + 1/2*i + 1/2*j + 1/2*k, 0), (-34/105*i - 463/735*j + 71/105*k, 1),\n (-34/105*i - 463/735*j + 71/105*k, 1)]\n ' N = len(e) if (N == 0): return [] else: (min_m, min_n, min_v) = (0, 0, infinity) for m in range(N): for n in range(m, N): v = B(e[m], e[n]).valuation(p) if ((v < min_v) or ((v == min_v) and (min_m != min_n) and (m == n))): (min_m, min_n, min_v) = (m, n, v) if ((min_m == min_n) or (p != 2)): if (min_m == min_n): f0 = e[min_m] else: f0 = (e[min_m] + e[min_n]) (e[0], e[min_m]) = (e[min_m], e[0]) c = B(f0, f0) for l in range(1, N): e[l] = (e[l] - ((B(e[l], f0) / c) * f0)) f = normalize_basis_at_p(e[1:], p) f.insert(0, (f0, (min_v - valuation(p, 2)))) return f else: if (B(e[min_m], e[min_m]).valuation(p) > B(e[min_n], e[min_n]).valuation(p)): (e[min_m], e[min_n]) = (e[min_n], e[min_m]) f0 = (((p ** min_v) / B(e[min_m], e[min_n])) * e[min_m]) f1 = e[min_n] if ((B(f0, f1).valuation(p) + 1) < B(f0, f0).valuation(p)): f0 += f1 f1 = f0 e[min_m] = e[0] e[min_n] = e[1] B00 = B(f0, f0) B11 = B(f1, f1) B01 = B(f0, f1) d = ((B00 * B11) - (B01 ** 2)) tu = [(((B01 * B(f1, e[l])) - (B11 * B(f0, e[l]))), ((B01 * B(f0, e[l])) - (B00 * B(f1, e[l])))) for l in range(2, N)] e[2:n] = [((e[l] + ((tu[(l - 2)][0] / d) * f0)) + ((tu[(l - 2)][1] / d) * f1)) for l in range(2, N)] f = normalize_basis_at_p(e[2:N], p) return ([(f0, min_v), (f1, min_v)] + f)
def maxord_solve_aux_eq(a, b, p): '\n Given ``a`` and ``b`` and an even prime ideal ``p`` find\n (y,z,w) with y a unit mod `p^{2e}` such that\n\n .. MATH::\n\n 1 - ay^2 - bz^2 + abw^2 \\equiv 0 mod p^{2e},\n\n where `e` is the ramification index of `p`.\n\n Currently only `p=2` is implemented by hardcoding solutions.\n\n INPUT:\n\n - ``a`` -- integer with `v_p(a) = 0`\n\n - ``b`` -- integer with `v_p(b) \\in \\{0,1\\}`\n\n - ``p`` -- even prime ideal (actually only ``p=ZZ(2)`` is implemented)\n\n OUTPUT:\n\n - A tuple `(y, z, w)`\n\n EXAMPLES::\n\n sage: from sage.algebras.quatalg.quaternion_algebra import maxord_solve_aux_eq\n sage: for a in [1,3]:\n ....: for b in [1,2,3]:\n ....: (y,z,w) = maxord_solve_aux_eq(a, b, 2)\n ....: assert mod(y, 4) == 1 or mod(y, 4) == 3\n ....: assert mod(1 - a*y^2 - b*z^2 + a*b*w^2, 4) == 0\n ' if (p != ZZ(2)): raise NotImplementedError('Algorithm only implemented over ZZ at the moment') v_a = a.valuation(p) v_b = b.valuation(p) if (v_a != 0): raise RuntimeError('a must have v_p(a)=0') if ((v_b != 0) and (v_b != 1)): raise RuntimeError('b must have v_p(b) in {0,1}') R = ZZ.quo(ZZ(4)) lut = {(R(1), R(1)): (1, 1, 1), (R(1), R(2)): (1, 0, 0), (R(1), R(3)): (1, 0, 0), (R(3), R(1)): (1, 1, 1), (R(3), R(2)): (1, 0, 1), (R(3), R(3)): (1, 1, 1)} return lut[(R(a), R(b))]
def unpickle_QuaternionAlgebra_v0(*key): "\n The 0th version of pickling for quaternion algebras.\n\n EXAMPLES::\n\n sage: t = (QQ, -5, -19, ('i', 'j', 'k'))\n sage: import sage.algebras.quaternion_algebra\n sage: sage.algebras.quaternion_algebra.unpickle_QuaternionAlgebra_v0(*t)\n Quaternion Algebra (-5, -19) with base ring Rational Field\n " from .quatalg.quaternion_algebra import QuaternionAlgebra return QuaternionAlgebra(*key)
def unpickle_QuaternionAlgebraElement_generic_v0(*args): '\n EXAMPLES::\n\n sage: K.<X> = QQ[]\n sage: Q.<i,j,k> = QuaternionAlgebra(Frac(K), -5,-19); z = 2/3 + i*X - X^2*j + X^3*k\n sage: f, t = z.__reduce__()\n sage: import sage.algebras.quaternion_algebra_element\n sage: sage.algebras.quaternion_algebra_element.unpickle_QuaternionAlgebraElement_generic_v0(*t)\n 2/3 + X*i + (-X^2)*j + X^3*k\n sage: sage.algebras.quaternion_algebra_element.unpickle_QuaternionAlgebraElement_generic_v0(*t) == z\n True\n ' return QuaternionAlgebraElement_generic(*args)
def unpickle_QuaternionAlgebraElement_rational_field_v0(*args): '\n EXAMPLES::\n\n sage: Q.<i,j,k> = QuaternionAlgebra(-5,-19); a = 2/3 + i*5/7 - j*2/5 +19/2\n sage: f, t = a.__reduce__()\n sage: import sage.algebras.quaternion_algebra_element\n sage: sage.algebras.quaternion_algebra_element.unpickle_QuaternionAlgebraElement_rational_field_v0(*t)\n 61/6 + 5/7*i - 2/5*j\n ' return QuaternionAlgebraElement_rational_field(*args)
def unpickle_QuaternionAlgebraElement_number_field_v0(*args): '\n EXAMPLES::\n\n sage: # needs sage.symbolic\n sage: K.<a> = QQ[2^(1/3)]; Q.<i,j,k> = QuaternionAlgebra(K, -3, a); z = i + j\n sage: f, t = z.__reduce__()\n sage: import sage.algebras.quaternion_algebra_element\n sage: sage.algebras.quaternion_algebra_element.unpickle_QuaternionAlgebraElement_number_field_v0(*t)\n i + j\n sage: sage.algebras.quaternion_algebra_element.unpickle_QuaternionAlgebraElement_number_field_v0(*t) == z\n True\n ' return QuaternionAlgebraElement_number_field(*args)
class RationalCherednikAlgebra(CombinatorialFreeModule): "\n A rational Cherednik algebra.\n\n Let `k` be a field. Let `W` be a complex reflection group acting on\n a vector space `\\mathfrak{h}` (over `k`). Let `\\mathfrak{h}^*` denote\n the corresponding dual vector space. Let `\\cdot` denote the\n natural action of `w` on `\\mathfrak{h}` and `\\mathfrak{h}^*`. Let\n `\\mathcal{S}` denote the set of reflections of `W` and `\\alpha_s`\n and `\\alpha_s^{\\vee}` are the associated root and coroot of `s`. Let\n `c = (c_s)_{s \\in W}` such that `c_s = c_{tst^{-1}}` for all `t \\in W`.\n\n The *rational Cherednik algebra* is the `k`-algebra\n `H_{c,t}(W) = T(\\mathfrak{h} \\oplus \\mathfrak{h}^*) \\otimes kW` with\n parameters `c, t \\in k` that is subject to the relations:\n\n .. MATH::\n\n \\begin{aligned}\n w \\alpha & = (w \\cdot \\alpha) w,\n \\\\ \\alpha^{\\vee} w & = w (w^{-1} \\cdot \\alpha^{\\vee}),\n \\\\ \\alpha \\alpha^{\\vee} & = \\alpha^{\\vee} \\alpha\n + t \\langle \\alpha^{\\vee}, \\alpha \\rangle\n + \\sum_{s \\in \\mathcal{S}} c_s \\frac{\\langle \\alpha^{\\vee},\n \\alpha_s \\rangle \\langle \\alpha^{\\vee}_s, \\alpha \\rangle}{\n \\langle \\alpha^{\\vee}, \\alpha \\rangle} s,\n \\end{aligned}\n\n where `w \\in W` and `\\alpha \\in \\mathfrak{h}` and\n `\\alpha^{\\vee} \\in \\mathfrak{h}^*`.\n\n INPUT:\n\n - ``ct`` -- a finite Cartan type\n - ``c`` -- the parameters `c_s` given as an element or a tuple, where\n the first entry is the one for the long roots and (for\n non-simply-laced types) the second is for the short roots\n - ``t`` -- the parameter `t`\n - ``base_ring`` -- (optional) the base ring\n - ``prefix`` -- (default: ``('a', 's', 'ac')``) the prefixes\n\n .. TODO::\n\n Implement a version for complex reflection groups.\n\n REFERENCES:\n\n - [GGOR2003]_\n - [EM2001]_\n " @staticmethod def __classcall_private__(cls, ct, c=1, t=None, base_ring=None, prefix=('a', 's', 'ac')): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: R1 = algebras.RationalCherednik(['B',2], 1, 1, QQ)\n sage: R2 = algebras.RationalCherednik(CartanType(['B',2]), [1,1], 1, QQ, ('a', 's', 'ac'))\n sage: R1 is R2\n True\n " ct = CartanType(ct) if (not ct.is_finite()): raise ValueError('the Cartan type must be finite') if (base_ring is None): if (t is None): base_ring = QQ else: base_ring = t.parent() if (t is None): t = base_ring.one() else: t = base_ring(t) if isinstance(c, (tuple, list)): if ct.is_simply_laced(): if (len(c) != 1): raise ValueError('1 parameter c_s must be given for simply-laced types') c = (base_ring(c[0]),) else: if (len(c) != 2): raise ValueError('2 parameters c_s must be given for non-simply-laced types') c = (base_ring(c[0]), base_ring(c[1])) else: c = base_ring(c) if ct.is_simply_laced(): c = (c,) else: c = (c, c) return super().__classcall__(cls, ct, c, t, base_ring, tuple(prefix)) def __init__(self, ct, c, t, base_ring, prefix): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: k = QQ['c,t']\n sage: R = algebras.RationalCherednik(['A',2], k.gen(0), k.gen(1))\n sage: TestSuite(R).run() # long time\n " self._c = c self._t = t self._cartan_type = ct self._weyl = RootSystem(ct).root_lattice().weyl_group(prefix=prefix[1]) self._hd = IndexedFreeAbelianMonoid(ct.index_set(), prefix=prefix[0], bracket=False) self._h = IndexedFreeAbelianMonoid(ct.index_set(), prefix=prefix[2], bracket=False) indices = DisjointUnionEnumeratedSets([self._hd, self._weyl, self._h]) CombinatorialFreeModule.__init__(self, base_ring, indices, category=Algebras(base_ring).WithBasis().Graded(), sorting_key=self._genkey) def _genkey(self, t): "\n Construct a key for comparison for a term indexed by ``t``.\n\n The key we create is the tuple in the following order:\n\n - overall degree\n - length of the Weyl group element\n - the Weyl group element\n - the element of `\\mathfrak{h}`\n - the element of `\\mathfrak{h}^*`\n\n EXAMPLES::\n\n sage: R = algebras.RationalCherednik(['A',2], 1, 1, QQ)\n sage: R.an_element()**2 # indirect doctest\n 9*ac1^2 + 10*I + 6*a1*ac1 + 6*s1 + 3/2*s2 + 3/2*s1*s2*s1 + a1^2\n " return (self.degree_on_basis(t), t[1].length(), t[1], str(t[0]), str(t[2])) @lazy_attribute def _reflections(self): "\n A dictionary of reflections to a pair of the associated root\n and coroot.\n\n EXAMPLES::\n\n sage: R = algebras.RationalCherednik(['B',2], [1,2], 1, QQ)\n sage: [R._reflections[k] for k in sorted(R._reflections, key=str)]\n [(alpha[1], alphacheck[1], 1),\n (alpha[1] + alpha[2], 2*alphacheck[1] + alphacheck[2], 2),\n (alpha[2], alphacheck[2], 2),\n (alpha[1] + 2*alpha[2], alphacheck[1] + alphacheck[2], 1)]\n " d = {} for r in RootSystem(self._cartan_type).root_lattice().positive_roots(): s = self._weyl.from_reduced_word(r.associated_reflection()) if r.is_short_root(): c = self._c[1] else: c = self._c[0] d[s] = (r, r.associated_coroot(), c) return d def _repr_(self) -> str: "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: RationalCherednikAlgebra(['A',4], 2, 1, QQ)\n Rational Cherednik Algebra of type ['A', 4] with c=2 and t=1\n over Rational Field\n sage: algebras.RationalCherednik(['B',2], [1,2], 1, QQ)\n Rational Cherednik Algebra of type ['B', 2] with c_L=1 and c_S=2\n and t=1 over Rational Field\n " ret = 'Rational Cherednik Algebra of type {} with '.format(self._cartan_type) if self._cartan_type.is_simply_laced(): ret += 'c={}'.format(self._c[0]) else: ret += 'c_L={} and c_S={}'.format(*self._c) return (ret + ' and t={} over {}'.format(self._t, self.base_ring())) def _repr_term(self, t): "\n Return a string representation of the term indexed by ``t``.\n\n EXAMPLES::\n\n sage: R = algebras.RationalCherednik(['A',2], 1, 1, QQ)\n sage: R.an_element() # indirect doctest\n 3*ac1 + 2*s1 + a1\n sage: R.one() # indirect doctest\n I\n " r = [] if (t[0] != self._hd.one()): r.append(t[0]) if (t[1] != self._weyl.one()): r.append(t[1]) if (t[2] != self._h.one()): r.append(t[2]) if (not r): return 'I' return '*'.join((repr(x) for x in r)) def algebra_generators(self): "\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: R = algebras.RationalCherednik(['A',2], 1, 1, QQ)\n sage: list(R.algebra_generators())\n [a1, a2, s1, s2, ac1, ac2]\n " keys = [('a' + str(i)) for i in self._cartan_type.index_set()] keys += [('s' + str(i)) for i in self._cartan_type.index_set()] keys += [('ac' + str(i)) for i in self._cartan_type.index_set()] def gen_map(k): if (k[0] == 's'): i = int(k[1:]) return self.monomial((self._hd.one(), self._weyl.group_generators()[i], self._h.one())) if (k[1] == 'c'): i = int(k[2:]) return self.monomial((self._hd.one(), self._weyl.one(), self._h.monoid_generators()[i])) i = int(k[1:]) return self.monomial((self._hd.monoid_generators()[i], self._weyl.one(), self._h.one())) return Family(keys, gen_map) @cached_method def one_basis(self): "\n Return the index of the element `1`.\n\n EXAMPLES::\n\n sage: R = algebras.RationalCherednik(['A',2], 1, 1, QQ)\n sage: R.one_basis()\n (1, 1, 1)\n " return (self._hd.one(), self._weyl.one(), self._h.one()) def product_on_basis(self, left, right): "\n Return ``left`` multiplied by ``right`` in ``self``.\n\n EXAMPLES::\n\n sage: R = algebras.RationalCherednik(['A',2], 1, 1, QQ)\n sage: a2 = R.algebra_generators()['a2']\n sage: ac1 = R.algebra_generators()['ac1']\n sage: a2 * ac1 # indirect doctest\n a2*ac1\n sage: ac1 * a2\n -I + a2*ac1 - s1 - s2 + 1/2*s1*s2*s1\n sage: x = R.an_element()\n sage: [y * x for y in R.some_elements()]\n [0,\n 3*ac1 + 2*s1 + a1,\n 9*ac1^2 + 10*I + 6*a1*ac1 + 6*s1 + 3/2*s2 + 3/2*s1*s2*s1 + a1^2,\n 3*a1*ac1 + 2*a1*s1 + a1^2,\n 3*a2*ac1 + 2*a2*s1 + a1*a2,\n 3*s1*ac1 + 2*I - a1*s1,\n 3*s2*ac1 + 2*s2*s1 + a1*s2 + a2*s2,\n 3*ac1^2 - 2*s1*ac1 + 2*I + a1*ac1 + 2*s1 + 1/2*s2 + 1/2*s1*s2*s1,\n 3*ac1*ac2 + 2*s1*ac1 + 2*s1*ac2 - I + a1*ac2 - s1 - s2 + 1/2*s1*s2*s1]\n sage: [x * y for y in R.some_elements()]\n [0,\n 3*ac1 + 2*s1 + a1,\n 9*ac1^2 + 10*I + 6*a1*ac1 + 6*s1 + 3/2*s2 + 3/2*s1*s2*s1 + a1^2,\n 6*I + 3*a1*ac1 + 6*s1 + 3/2*s2 + 3/2*s1*s2*s1 - 2*a1*s1 + a1^2,\n -3*I + 3*a2*ac1 - 3*s1 - 3*s2 + 3/2*s1*s2*s1 + 2*a1*s1 + 2*a2*s1 + a1*a2,\n -3*s1*ac1 + 2*I + a1*s1,\n 3*s2*ac1 + 3*s2*ac2 + 2*s1*s2 + a1*s2,\n 3*ac1^2 + 2*s1*ac1 + a1*ac1,\n 3*ac1*ac2 + 2*s1*ac2 + a1*ac2]\n " dl = dict(left[2]._monomial) dr = dict(right[0]._monomial) if ((not dl) and (not dr)): return self.monomial((left[0], (left[1] * right[1]), right[2])) R = self.base_ring() I = self._cartan_type.index_set() P = PolynomialRing(R, 'x', len(I)) G = P.gens() gens_dict = {a: G[i] for (i, a) in enumerate(I)} Q = RootSystem(self._cartan_type).root_lattice() alpha = Q.simple_roots() alphacheck = Q.simple_coroots() def commute_w_hd(w, al): ret = P.one() for k in al: x = sum(((c * gens_dict[i]) for (i, c) in alpha[k].weyl_action(w))) ret *= (x ** al[k]) ret = ret.dict() for k in ret: (yield (self._hd({I[i]: e for (i, e) in enumerate(k) if (e != 0)}), ret[k])) if (dl and dr): il = next(iter(dl.keys())) ir = next(iter(dr.keys())) terms = self._product_coroot_root(il, ir) dl[il] -= 1 if (dl[il] == 0): del dl[il] dr[ir] -= 1 if (dr[ir] == 0): del dr[ir] cur = self._from_dict({(hd, (s * right[1]), right[2]): (c * cc) for (s, c) in terms for (hd, cc) in commute_w_hd(s, dr)}) cur = (self.monomial((left[0], left[1], self._h(dl))) * cur) rem = self.monomial((left[0], left[1], self._h(dl))) rem = (rem * self.monomial((self._hd({ir: 1}), self._weyl.one(), self._h({il: 1})))) rem = (rem * self.monomial((self._hd(dr), right[1], right[2]))) return (cur + rem) if dl: ret = P.one() for k in dl: x = sum(((c * gens_dict[i]) for (i, c) in alphacheck[k].weyl_action(right[1].reduced_word(), inverse=True))) ret *= (x ** dl[k]) ret = ret.dict() w = (left[1] * right[1]) return self._from_dict({(left[0], w, (self._h({I[i]: e for (i, e) in enumerate(k) if (e != 0)}) * right[2])): ret[k] for k in ret}) w = (left[1] * right[1]) return self._from_dict({((left[0] * hd), w, right[2]): c for (hd, c) in commute_w_hd(left[1], dr)}) @cached_method def _product_coroot_root(self, i, j): "\n Return the product `\\alpha^{\\vee}_i \\alpha_j`.\n\n EXAMPLES::\n\n sage: k = QQ['c,t']\n sage: R = algebras.RationalCherednik(['A',3], k.gen(0), k.gen(1))\n sage: sorted(R._product_coroot_root(1, 1))\n [(s1, 2*c),\n (s1*s2*s1, 1/2*c),\n (s1*s2*s3*s2*s1, 1/2*c),\n (1, 2*t),\n (s3, 0),\n (s2, 1/2*c),\n (s2*s3*s2, 1/2*c)]\n\n sage: sorted(R._product_coroot_root(1, 2))\n [(s1, -c),\n (s1*s2*s1, 1/2*c),\n (s1*s2*s3*s2*s1, 0),\n (1, -t),\n (s3, 0),\n (s2, -c),\n (s2*s3*s2, -1/2*c)]\n\n sage: sorted(R._product_coroot_root(1, 3))\n [(s1, 0),\n (s1*s2*s1, -1/2*c),\n (s1*s2*s3*s2*s1, 1/2*c),\n (1, 0),\n (s3, 0),\n (s2, 1/2*c),\n (s2*s3*s2, -1/2*c)]\n " Q = RootSystem(self._cartan_type).root_lattice() ac = Q.simple_coroot(i) al = Q.simple_root(j) R = self.base_ring() terms = [(self._weyl.one(), (self._t * R(ac.scalar(al))))] for s in self._reflections: (pr, pc, c) = self._reflections[s] terms.append((s, (c * R(((ac.scalar(pr) * pc.scalar(al)) / pc.scalar(pr)))))) return tuple(terms) def degree_on_basis(self, m): "\n Return the degree on the monomial indexed by ``m``.\n\n EXAMPLES::\n\n sage: R = algebras.RationalCherednik(['A',2], 1, 1, QQ)\n sage: [R.degree_on_basis(g.leading_support())\n ....: for g in R.algebra_generators()]\n [1, 1, 0, 0, -1, -1]\n " return (m[0].length() - m[2].length()) @cached_method def trivial_idempotent(self): "\n Return the trivial idempotent of ``self``.\n\n Let `e = |W|^{-1} \\sum_{w \\in W} w` is the trivial idempotent.\n Thus `e^2 = e` and `eW = We`. The trivial idempotent is used\n in the construction of the spherical Cherednik algebra from\n the rational Cherednik algebra by `U_{c,t}(W) = e H_{c,t}(W) e`.\n\n EXAMPLES::\n\n sage: R = algebras.RationalCherednik(['A',2], 1, 1, QQ)\n sage: R.trivial_idempotent()\n 1/6*I + 1/6*s1 + 1/6*s2 + 1/6*s2*s1 + 1/6*s1*s2 + 1/6*s1*s2*s1\n " coeff = self.base_ring()((~ self._weyl.cardinality())) hd_one = self._hd.one() h_one = self._h.one() return self._from_dict({(hd_one, w, h_one): coeff for w in self._weyl}, remove_zeros=False) @cached_method def deformed_euler(self): "\n Return the element `eu_k`.\n\n EXAMPLES::\n\n sage: R = algebras.RationalCherednik(['A',2], 1, 1, QQ)\n sage: R.deformed_euler()\n 2*I + 2/3*a1*ac1 + 1/3*a1*ac2 + 1/3*a2*ac1 + 2/3*a2*ac2\n + s1 + s2 + s1*s2*s1\n " I = self._cartan_type.index_set() G = self.algebra_generators() cm = (~ CartanMatrix(self._cartan_type)) n = len(I) ac = [G[('ac' + str(i))] for i in I] la = [sum(((cm[(i, j)] * G[('a' + str(I[i]))]) for i in range(n))) for j in range(n)] return self.sum(((ac[i] * la[i]) for i in range(n))) @cached_method def an_element(self): "\n Return an element of ``self``.\n\n EXAMPLES::\n\n sage: R = algebras.RationalCherednik(['A',2], 1, 1, QQ)\n sage: R.an_element()\n 3*ac1 + 2*s1 + a1\n " G = self.algebra_generators() i = str(self._cartan_type.index_set()[0]) return ((G[('a' + i)] + (2 * G[('s' + i)])) + (3 * G[('ac' + i)])) def some_elements(self): "\n Return some elements of ``self``.\n\n EXAMPLES::\n\n sage: R = algebras.RationalCherednik(['A',2], 1, 1, QQ)\n sage: R.some_elements()\n [0, I, 3*ac1 + 2*s1 + a1, a1, a2, s1, s2, ac1, ac2]\n " ret = [self.zero(), self.one(), self.an_element()] ret += list(self.algebra_generators()) return ret
def _schur_I_nr_representatives(n, r): '\n Internal function called by :func:`schur_representation_indices`,\n which generates all weakly increasing tuples of length ``r`` in the\n alphabet ``1, 2, ..., n``.\n\n EXAMPLES::\n\n sage: from sage.algebras.schur_algebra import _schur_I_nr_representatives\n sage: _schur_I_nr_representatives(2, 4)\n ((1, 1, 1, 1), (1, 1, 1, 2), (1, 1, 2, 2), (1, 2, 2, 2), (2, 2, 2, 2))\n ' if (r == 0): return () index = [] element = [1] while element: if (element[(- 1)] > n): element.pop() if element: element[(- 1)] += 1 continue if (len(element) == r): index.append(tuple(element)) element[(- 1)] += 1 continue element.append(element[(- 1)]) return tuple(index)
def schur_representative_indices(n, r): '\n Return a set which functions as a basis of `S_K(n,r)`.\n\n More specifically, the basis for `S_K(n,r)` consists of\n equivalence classes of pairs of tuples of length ``r`` on the alphabet\n `\\{1, \\dots, n\\}`, where the equivalence relation is simultaneous\n permutation of the two tuples. We can therefore fix a\n representative for each equivalence class in which the entries of\n the first tuple weakly increase, and the entries of the second tuple\n whose corresponding values in the first tuple are equal, also\n weakly increase.\n\n EXAMPLES::\n\n sage: from sage.algebras.schur_algebra import schur_representative_indices\n sage: schur_representative_indices(2, 2)\n [((1, 1), (1, 1)), ((1, 1), (1, 2)),\n ((1, 1), (2, 2)), ((1, 2), (1, 1)),\n ((1, 2), (1, 2)), ((1, 2), (2, 1)),\n ((1, 2), (2, 2)), ((2, 2), (1, 1)),\n ((2, 2), (1, 2)), ((2, 2), (2, 2))]\n ' basis = [] I_nr_repr = _schur_I_nr_representatives(n, r) for e in I_nr_repr: j = 0 k = 0 I1 = [] l = len(e) while (k < l): if (e[k] != e[j]): I2 = [] if (j == 0): I1 = _schur_I_nr_representatives(n, k) else: I2 = _schur_I_nr_representatives(n, (k - j)) I = [] for m1 in range(len(I1)): for m2 in range(len(I2)): I.append((I1[m1] + I2[m2])) I1 = I j = k elif (k == (l - 1)): I2 = [] k += 1 if (j == 0): I1 = _schur_I_nr_representatives(n, k) else: I2 = _schur_I_nr_representatives(n, (k - j)) I = [] for m1 in range(len(I1)): for m2 in range(len(I2)): I.append((I1[m1] + I2[m2])) I1 = I else: k += 1 for v in I1: basis.append((tuple(e), tuple(v))) return basis
def schur_representative_from_index(i0, i1): '\n Simultaneously reorder a pair of tuples to obtain the equivalent\n element of the distinguished basis of the Schur algebra.\n\n .. SEEALSO::\n\n :func:`schur_representative_indices`\n\n INPUT:\n\n - A pair of tuples of length `r` with elements in `\\{1,\\dots,n\\}`\n\n OUTPUT:\n\n - The corresponding pair of tuples ordered correctly.\n\n EXAMPLES::\n\n sage: from sage.algebras.schur_algebra import schur_representative_from_index\n sage: schur_representative_from_index([2,1,2,2], [1,3,0,0])\n ((1, 2, 2, 2), (3, 0, 0, 1))\n ' w = [] for (i, val) in enumerate(i0): w.append((val, i1[i])) w.sort() i0 = [] i1 = [] for pair in w: i0.append(pair[0]) i1.append(pair[1]) return (tuple(i0), tuple(i1))
class SchurAlgebra(CombinatorialFreeModule): '\n A Schur algebra.\n\n Let `R` be a commutative ring, `n` be a positive integer, and `r`\n be a non-negative integer. Define `A_R(n,r)` to be the set of\n homogeneous polynomials of degree `r` in `n^2` variables `x_{ij}`.\n Therefore we can write `R[x_{ij}] = \\bigoplus_{r \\geq 0} A_R(n,r)`,\n and `R[x_{ij}]` is known to be a bialgebra with coproduct given by\n `\\Delta(x_{ij}) = \\sum_l x_{il} \\otimes x_{lj}` and counit\n `\\varepsilon(x_{ij}) = \\delta_{ij}`. Therefore `A_R(n,r)` is a\n subcoalgebra of `R[x_{ij}]`. The *Schur algebra* `S_R(n,r)` is the\n linear dual to `A_R(n,r)`, that is `S_R(n,r) := \\hom(A_R(n,r), R)`,\n and `S_R(n,r)` obtains its algebra structure naturally by dualizing\n the comultiplication of `A_R(n,r)`.\n\n Let `V = R^n`. One of the most important properties of the Schur\n algebra `S_R(n, r)` is that it is isomorphic to the endomorphisms\n of `V^{\\otimes r}` which commute with the natural action of `S_r`.\n\n EXAMPLES::\n\n sage: S = SchurAlgebra(ZZ, 2, 2); S\n Schur algebra (2, 2) over Integer Ring\n\n REFERENCES:\n\n - [Gr2007]_\n - :wikipedia:`Schur_algebra`\n ' def __init__(self, R, n, r): "\n Initialize ``self``.\n\n TESTS::\n\n sage: S = SchurAlgebra(ZZ, 2, 2)\n sage: TestSuite(S).run()\n\n ::\n\n sage: SchurAlgebra(ZZ, -2, 2)\n Traceback (most recent call last):\n ...\n ValueError: n (=-2) must be a positive integer\n sage: SchurAlgebra(ZZ, 2, -2)\n Traceback (most recent call last):\n ...\n ValueError: r (=-2) must be a non-negative integer\n sage: SchurAlgebra('niet', 2, 2)\n Traceback (most recent call last):\n ...\n ValueError: R (=niet) must be a commutative ring\n " if ((n not in ZZ) or (n <= 0)): raise ValueError('n (={}) must be a positive integer'.format(n)) if ((r not in ZZ) or (r < 0)): raise ValueError('r (={}) must be a non-negative integer'.format(r)) if (R not in Rings.Commutative()): raise ValueError('R (={}) must be a commutative ring'.format(R)) self._n = n self._r = r CombinatorialFreeModule.__init__(self, R, schur_representative_indices(n, r), prefix='S', bracket=False, category=AlgebrasWithBasis(R).FiniteDimensional()) def _repr_(self): '\n Return the string representation of ``self``.\n\n EXAMPLES::\n\n sage: SchurAlgebra(ZZ, 4, 4)\n Schur algebra (4, 4) over Integer Ring\n ' msg = 'Schur algebra ({}, {}) over {}' return msg.format(self._n, self._r, self.base_ring()) @cached_method def one(self): '\n Return the element `1` of ``self``.\n\n EXAMPLES::\n\n sage: S = SchurAlgebra(ZZ, 2, 2)\n sage: e = S.one(); e\n S((1, 1), (1, 1)) + S((1, 2), (1, 2)) + S((2, 2), (2, 2))\n\n sage: x = S.an_element()\n sage: x * e == x\n True\n sage: all(e * x == x for x in S.basis())\n True\n\n sage: S = SchurAlgebra(ZZ, 4, 4)\n sage: e = S.one()\n sage: x = S.an_element()\n sage: x * e == x\n True\n ' tt = IntegerListsLex(length=self._r, min_part=1, max_part=self._n, min_slope=0) words = [tuple(u) for u in tt] return self.sum((self._monomial((w, w)) for w in words)) def product_on_basis(self, e_ij, e_kl): '\n Return the product of basis elements.\n\n EXAMPLES::\n\n sage: S = SchurAlgebra(QQ, 2, 3)\n sage: B = S.basis()\n\n If we multiply two basis elements `x` and `y`, such that\n `x[1]` and `y[0]` are not permutations of each other, the\n result is zero::\n\n sage: S.product_on_basis(((1, 1, 1), (1, 1, 2)), ((1, 2, 2), (1, 1, 2)))\n 0\n\n If we multiply a basis element `x` by a basis element which\n consists of the same tuple repeated twice (on either side),\n the result is either zero (if the previous case applies) or `x`::\n\n sage: ww = B[((1, 2, 2), (1, 2, 2))]\n sage: x = B[((1, 2, 2), (1, 1, 2))]\n sage: ww * x\n S((1, 2, 2), (1, 1, 2))\n\n An arbitrary product, on the other hand, may have multiplicities::\n\n sage: x = B[((1, 1, 1), (1, 1, 2))]\n sage: y = B[((1, 1, 2), (1, 2, 2))]\n sage: x * y\n 2*S((1, 1, 1), (1, 2, 2))\n ' j = e_ij[1] i = e_ij[0] l = e_kl[1] l = sorted(l) e_pq = [] for v in self.basis().keys(): if ((v[0] == i) and (sorted(v[1]) == l)): e_pq.append(v) b = self.basis() product = self.zero() for e in e_pq: Z_ijklpq = self.base_ring().zero() for s in Permutations(list(j)): if ((schur_representative_from_index(e[0], s) == e_ij) and (schur_representative_from_index(s, e[1]) == e_kl)): Z_ijklpq += self.base_ring().one() product += (Z_ijklpq * b[e]) return product def dimension(self): '\n Return the dimension of ``self``.\n\n The dimension of the Schur algebra `S_R(n, r)` is\n\n .. MATH::\n\n \\dim S_R(n,r) = \\binom{n^2+r-1}{r}.\n\n EXAMPLES::\n\n sage: S = SchurAlgebra(QQ, 4, 2)\n sage: S.dimension()\n 136\n sage: S = SchurAlgebra(QQ, 2, 4)\n sage: S.dimension()\n 35\n ' return binomial((((self._n ** 2) + self._r) - 1), self._r)
class SchurTensorModule(CombinatorialFreeModule_Tensor): '\n The space `V^{\\otimes r}` where `V = R^n` equipped with a left action\n of the Schur algebra `S_R(n,r)` and a right action of the symmetric\n group `S_r`.\n\n Let `R` be a commutative ring and `V = R^n`. We consider the module\n `V^{\\otimes r}` equipped with a natural right action of the symmetric\n group `S_r` given by\n\n .. MATH::\n\n (v_1 \\otimes v_2 \\otimes \\cdots \\otimes v_n) \\sigma\n = v_{\\sigma(1)} \\otimes v_{\\sigma(2)} \\otimes \\cdots\n \\otimes v_{\\sigma(n)}.\n\n The Schur algebra `S_R(n,r)` is naturally isomorphic to the\n endomorphisms of `V^{\\otimes r}` which commutes with the `S_r` action.\n We get the natural left action of `S_R(n,r)` by this isomorphism.\n\n EXAMPLES::\n\n sage: T = SchurTensorModule(QQ, 2, 3); T\n The 3-fold tensor product of a free module of dimension 2\n over Rational Field\n sage: A = SchurAlgebra(QQ, 2, 3)\n sage: P = Permutations(3)\n sage: t = T.an_element(); t\n 2*B[1] # B[1] # B[1] + 2*B[1] # B[1] # B[2] + 3*B[1] # B[2] # B[1]\n sage: a = A.an_element(); a\n 2*S((1, 1, 1), (1, 1, 1)) + 2*S((1, 1, 1), (1, 1, 2))\n + 3*S((1, 1, 1), (1, 2, 2))\n sage: p = P.an_element(); p\n [3, 1, 2]\n sage: y = a * t; y\n 14*B[1] # B[1] # B[1]\n sage: y * p\n 14*B[1] # B[1] # B[1]\n sage: z = t * p; z\n 2*B[1] # B[1] # B[1] + 3*B[1] # B[1] # B[2] + 2*B[2] # B[1] # B[1]\n sage: a * z\n 14*B[1] # B[1] # B[1]\n\n We check the commuting action property::\n\n sage: all( (bA * bT) * p == bA * (bT * p)\n ....: for bT in T.basis() for bA in A.basis() for p in P)\n True\n ' def __init__(self, R, n, r): '\n Initialize ``self``.\n\n TESTS::\n\n sage: T = SchurTensorModule(QQ, 2, 3)\n sage: TestSuite(T).run()\n ' C = CombinatorialFreeModule(R, list(range(1, (n + 1)))) self._n = n self._r = r self._sga = SymmetricGroupAlgebra(R, r) self._schur = SchurAlgebra(R, n, r) cat = ModulesWithBasis(R).TensorProducts().FiniteDimensional() CombinatorialFreeModule_Tensor.__init__(self, tuple(([C] * r)), category=cat) g = self._schur.module_morphism(self._monomial_product, codomain=self) self._schur_action = self.module_morphism(g, codomain=self, position=1) def _repr_(self): '\n Return the string representation of ``self``.\n\n EXAMPLES::\n\n sage: SchurTensorModule(QQ, 2, 3)\n The 3-fold tensor product of a free module of dimension 2\n over Rational Field\n ' msg = 'The {}-fold tensor product of a free module of dimension {}' msg += ' over {}' return msg.format(self._r, self._n, self.base_ring()) def construction(self): '\n Return ``None``.\n\n There is no functorial construction for ``self``.\n\n EXAMPLES::\n\n sage: T = SchurTensorModule(QQ, 2, 3)\n sage: T.construction()\n ' return None def _monomial_product(self, xi, v): '\n Result of acting by the basis element ``xi`` of the corresponding\n Schur algebra on the basis element ``v`` of ``self``.\n\n EXAMPLES::\n\n sage: T = SchurTensorModule(QQ, 2, 3)\n sage: xi = T._schur.basis().keys()[4]; xi\n ((1, 1, 2), (1, 1, 1))\n sage: T._monomial_product(xi, (1, 1, 1))\n B[1] # B[1] # B[2] + B[1] # B[2] # B[1] + B[2] # B[1] # B[1]\n ' ret = [] for i in itertools.product(list(range(1, (self._n + 1))), repeat=self._r): if (schur_representative_from_index(i, v) == xi): ret.append(tuple(i)) return self.sum_of_monomials(ret) class Element(CombinatorialFreeModule_Tensor.Element): def _acted_upon_(self, elt, self_on_left=False): '\n Return the action of ``elt`` on ``self``.\n\n We add the *left* action of the Schur algebra, and the *right*\n actions of the symmetric group algebra and the symmetric group.\n\n EXAMPLES::\n\n sage: T = SchurTensorModule(QQ, 2, 4)\n sage: x = T.an_element()\n sage: A = SchurAlgebra(QQ, 2, 4)\n sage: y = A.an_element()\n sage: y * x\n 14*B[1] # B[1] # B[1] # B[1]\n sage: x * y\n Traceback (most recent call last):\n ...\n TypeError: unsupported operand parent(s) for *: ...\n\n ::\n\n sage: SGA = SymmetricGroupAlgebra(QQ, 4)\n sage: y = SGA.an_element()\n sage: x * y\n 14*B[1] # B[1] # B[1] # B[1] + 17*B[1] # B[1] # B[1] # B[2]\n + 7*B[1] # B[1] # B[2] # B[1] + 9*B[1] # B[2] # B[1] # B[1]\n + 2*B[2] # B[1] # B[1] # B[1]\n sage: y * x\n Traceback (most recent call last):\n ...\n TypeError: unsupported operand parent(s) for *: ...\n\n ::\n\n sage: S = Permutations(4)\n sage: y = S.an_element()\n sage: x * y\n 2*B[1] # B[1] # B[1] # B[1] + 3*B[1] # B[1] # B[1] # B[2]\n + 2*B[2] # B[1] # B[1] # B[1]\n ' P = self.parent() if self_on_left: if (elt in P._sga): return P.sum_of_terms(((tuple([m[(i - 1)] for i in me]), (c * ce)) for (m, c) in self for (me, ce) in elt)) if (elt in P._sga._indices): return P.sum_of_terms(((tuple([m[(i - 1)] for i in elt]), c) for (m, c) in self)) elif (elt in P._schur): return P._schur_action(elt, self) return super()._acted_upon_(elt, self_on_left)
def GL_irreducible_character(n, mu, KK): '\n Return the character of the irreducible module indexed by ``mu``\n of `GL(n)` over the field ``KK``.\n\n INPUT:\n\n - ``n`` -- a positive integer\n - ``mu`` -- a partition of at most ``n`` parts\n - ``KK`` -- a field\n\n OUTPUT:\n\n a symmetric function which should be interpreted in ``n``\n variables to be meaningful as a character\n\n EXAMPLES:\n\n Over `\\QQ`, the irreducible character for `\\mu` is the Schur\n function associated to `\\mu`, plus garbage terms (Schur\n functions associated to partitions with more than `n` parts)::\n\n sage: from sage.algebras.schur_algebra import GL_irreducible_character\n sage: sbasis = SymmetricFunctions(QQ).s()\n sage: z = GL_irreducible_character(2, [2], QQ)\n sage: sbasis(z)\n s[2]\n\n sage: z = GL_irreducible_character(4, [3, 2], QQ)\n sage: sbasis(z)\n -5*s[1, 1, 1, 1, 1] + s[3, 2]\n\n Over a Galois field, the irreducible character for `\\mu` will\n in general be smaller.\n\n In characteristic `p`, for a one-part partition `(r)`, where\n `r = a_0 + p a_1 + p^2 a_2 + \\dots`, the result is (see [Gr2007]_,\n after 5.5d) the product of `h[a_0], h[a_1]( pbasis[p]), h[a_2]\n ( pbasis[p^2]), \\dots,` which is consistent with the following ::\n\n sage: from sage.algebras.schur_algebra import GL_irreducible_character\n sage: GL_irreducible_character(2, [7], GF(3))\n m[4, 3] + m[6, 1] + m[7]\n ' mbasis = SymmetricFunctions(QQ).m() r = sum(mu) M = SchurTensorModule(KK, n, r) A = M._schur SGA = M._sga from sage.combinat.tableau import from_shape_and_word ST = from_shape_and_word(mu, list(range(1, (r + 1))), convention='English') ell = [(i + 1) for (i, l) in enumerate(mu) for dummy in range(l)] e = M.basis()[tuple(ell)] S = SGA._indices BracC = SGA._from_dict({S(x.tuple()): x.sign() for x in ST.column_stabilizer()}, remove_zeros=False) f = (e * BracC) carter_lusztig = [] for T in SemistandardTableaux(mu, max_entry=n): i = tuple(flatten(T)) schur_rep = schur_representative_from_index(i, tuple(ell)) y = (A.basis()[schur_rep] * e) carter_lusztig.append(y.to_vector()) contents = Partitions(r, max_length=n).list() graded_basis = [] JJ = [] for i in range(len(contents)): graded_basis.append([]) JJ.append([]) for T in SemistandardTableaux(mu, max_entry=n): i = tuple(flatten(T)) con = ([0] * n) for a in i: con[(a - 1)] += 1 try: P = Partition(con) P_index = contents.index(P) JJ[P_index].append(i) schur_rep = schur_representative_from_index(i, tuple(ell)) x = (A.basis()[schur_rep] * f) graded_basis[P_index].append(x.to_vector()) except ValueError: pass length = len(carter_lusztig) phi = mbasis.zero() for aa in range(len(contents)): mat = [] for kk in range(len(JJ[aa])): temp = [] for j in range(length): temp.append(graded_basis[aa][kk].inner_product(carter_lusztig[j])) mat.append(temp) angle = Matrix(mat) phi += ((len(JJ[aa]) - angle.nullity()) * mbasis(contents[aa])) return phi
class ShuffleAlgebra(CombinatorialFreeModule): "\n The shuffle algebra on some generators over a base ring.\n\n Shuffle algebras are commutative and associative algebras, with a\n basis indexed by words. The product of two words `w_1 \\cdot w_2` is given\n by the sum over the shuffle product of `w_1` and `w_2`.\n\n .. SEEALSO::\n\n For more on shuffle products, see\n :mod:`~sage.combinat.words.shuffle_product` and\n :meth:`~sage.combinat.words.finite_word.FiniteWord_class.shuffle()`.\n\n REFERENCES:\n\n - :wikipedia:`Shuffle algebra`\n\n INPUT:\n\n - ``R`` -- ring\n\n - ``names`` -- generator names (string or an alphabet)\n\n EXAMPLES::\n\n sage: F = ShuffleAlgebra(QQ, 'xyz'); F\n Shuffle Algebra on 3 generators ['x', 'y', 'z'] over Rational Field\n\n sage: mul(F.gens())\n B[xyz] + B[xzy] + B[yxz] + B[yzx] + B[zxy] + B[zyx]\n\n sage: mul([ F.gen(i) for i in range(2) ]) + mul([ F.gen(i+1) for i in range(2) ])\n B[xy] + B[yx] + B[yz] + B[zy]\n\n sage: S = ShuffleAlgebra(ZZ, 'abcabc'); S\n Shuffle Algebra on 3 generators ['a', 'b', 'c'] over Integer Ring\n sage: S.base_ring()\n Integer Ring\n\n sage: G = ShuffleAlgebra(S, 'mn'); G\n Shuffle Algebra on 2 generators ['m', 'n'] over Shuffle Algebra on 3 generators ['a', 'b', 'c'] over Integer Ring\n sage: G.base_ring()\n Shuffle Algebra on 3 generators ['a', 'b', 'c'] over Integer Ring\n\n Shuffle algebras commute with their base ring::\n\n sage: K = ShuffleAlgebra(QQ,'ab')\n sage: a,b = K.gens()\n sage: K.is_commutative()\n True\n sage: L = ShuffleAlgebra(K,'cd')\n sage: c,d = L.gens()\n sage: L.is_commutative()\n True\n sage: s = a*b^2 * c^3; s\n (12*B[abb]+12*B[bab]+12*B[bba])*B[ccc]\n sage: parent(s)\n Shuffle Algebra on 2 generators ['c', 'd'] over Shuffle Algebra on 2 generators ['a', 'b'] over Rational Field\n sage: c^3 * a * b^2\n (12*B[abb]+12*B[bab]+12*B[bba])*B[ccc]\n\n Shuffle algebras are commutative::\n\n sage: c^3 * b * a * b == c * a * c * b^2 * c\n True\n\n We can also manipulate elements in the basis and coerce elements from our\n base field::\n\n sage: F = ShuffleAlgebra(QQ, 'abc')\n sage: B = F.basis()\n sage: B[Word('bb')] * B[Word('ca')]\n B[bbca] + B[bcab] + B[bcba] + B[cabb]\n + B[cbab] + B[cbba]\n sage: 1 - B[Word('bb')] * B[Word('ca')] / 2\n B[] - 1/2*B[bbca] - 1/2*B[bcab] - 1/2*B[bcba]\n - 1/2*B[cabb] - 1/2*B[cbab] - 1/2*B[cbba]\n\n TESTS::\n\n sage: R = ShuffleAlgebra(QQ,'x')\n sage: R.is_commutative()\n True\n sage: R = ShuffleAlgebra(QQ,'xy')\n sage: R.is_commutative()\n True\n\n Check for a fix when using numbers as generators::\n\n sage: A = algebras.Shuffle(QQ,[0,1])\n sage: A_d = A.dual_pbw_basis()\n sage: W = A.basis().keys()\n sage: x = A(W([0,1,0]))\n sage: A_d(x)\n -2*S[001] + S[010]\n " @staticmethod def __classcall_private__(cls, R, names, prefix=None): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: F1 = ShuffleAlgebra(QQ, 'xyz')\n sage: F2 = ShuffleAlgebra(QQ, ['x','y','z'])\n sage: F3 = ShuffleAlgebra(QQ, Alphabet('xyz'))\n sage: F1 is F2 and F1 is F3\n True\n " if (prefix is None): prefix = 'B' return super().__classcall__(cls, R, Alphabet(names), prefix) def __init__(self, R, names, prefix): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: F = ShuffleAlgebra(QQ, 'xyz'); F\n Shuffle Algebra on 3 generators ['x', 'y', 'z'] over Rational Field\n sage: TestSuite(F).run() # long time\n\n TESTS::\n\n sage: ShuffleAlgebra(24, 'toto')\n Traceback (most recent call last):\n ...\n TypeError: argument R must be a ring\n\n sage: F = ShuffleAlgebra(QQ, 'xyz', prefix='f'); F\n Shuffle Algebra on 3 generators ['x', 'y', 'z'] over Rational Field\n sage: F.gens()\n Family (f[x], f[y], f[z])\n " if (R not in Rings()): raise TypeError('argument R must be a ring') self._alphabet = names self.__ngens = self._alphabet.cardinality() cat = GradedHopfAlgebrasWithBasis(R).Commutative().Connected() CombinatorialFreeModule.__init__(self, R, Words(names, infinite=False), latex_prefix='', prefix=prefix, category=cat) def variable_names(self): "\n Return the names of the variables.\n\n EXAMPLES::\n\n sage: R = ShuffleAlgebra(QQ,'xy')\n sage: R.variable_names()\n {'x', 'y'}\n " return self._alphabet def _repr_term(self, t): "\n Return a string representation of the basis element indexed by ``t``.\n\n EXAMPLES::\n\n sage: R = ShuffleAlgebra(QQ,'xyz')\n sage: R._repr_term(R._indices('xyzxxy'))\n 'B[xyzxxy]'\n " return '{!s}[{!s}]'.format(self._print_options['prefix'], repr(t)[6:]) def _repr_(self): "\n Text representation of this shuffle algebra.\n\n EXAMPLES::\n\n sage: F = ShuffleAlgebra(QQ,'xyz')\n sage: F # indirect doctest\n Shuffle Algebra on 3 generators ['x', 'y', 'z'] over Rational Field\n\n sage: ShuffleAlgebra(ZZ,'a')\n Shuffle Algebra on one generator ['a'] over Integer Ring\n " if (self.__ngens == 1): gen = 'one generator' else: gen = ('%s generators' % self.__ngens) return (('Shuffle Algebra on ' + gen) + (' %s over %s' % (self._alphabet.list(), self.base_ring()))) @cached_method def one_basis(self): "\n Return the empty word, which index of `1` of this algebra,\n as per :meth:`AlgebrasWithBasis.ParentMethods.one_basis`.\n\n EXAMPLES::\n\n sage: A = ShuffleAlgebra(QQ,'a')\n sage: A.one_basis()\n word:\n sage: A.one()\n B[]\n " return self.basis().keys()([]) def product_on_basis(self, w1, w2): '\n Return the product of basis elements ``w1`` and ``w2``, as per\n :meth:`AlgebrasWithBasis.ParentMethods.product_on_basis()`.\n\n INPUT:\n\n - ``w1``, ``w2`` -- Basis elements\n\n EXAMPLES::\n\n sage: A = ShuffleAlgebra(QQ,\'abc\')\n sage: W = A.basis().keys()\n sage: A.product_on_basis(W("acb"), W("cba"))\n B[acbacb] + B[acbcab] + 2*B[acbcba]\n + 2*B[accbab] + 4*B[accbba] + B[cabacb]\n + B[cabcab] + B[cabcba] + B[cacbab]\n + 2*B[cacbba] + 2*B[cbaacb] + B[cbacab]\n + B[cbacba]\n\n sage: (a,b,c) = A.algebra_generators()\n sage: a * (1-b)^2 * c\n 2*B[abbc] - 2*B[abc] + 2*B[abcb] + B[ac]\n - 2*B[acb] + 2*B[acbb] + 2*B[babc]\n - 2*B[bac] + 2*B[bacb] + 2*B[bbac]\n + 2*B[bbca] - 2*B[bca] + 2*B[bcab]\n + 2*B[bcba] + B[ca] - 2*B[cab] + 2*B[cabb]\n - 2*B[cba] + 2*B[cbab] + 2*B[cbba]\n ' return sum((self.basis()[u] for u in w1.shuffle(w2))) def antipode_on_basis(self, w): '\n Return the antipode on the basis element ``w``.\n\n EXAMPLES::\n\n sage: A = ShuffleAlgebra(QQ,\'abc\')\n sage: W = A.basis().keys()\n sage: A.antipode_on_basis(W("acb"))\n -B[bca]\n ' mone = (- self.base_ring().one()) return self.term(w.reversal(), (mone ** len(w))) def gen(self, i): "\n Return the ``i``-th generator of the algebra.\n\n INPUT:\n\n - ``i`` -- an integer\n\n EXAMPLES::\n\n sage: F = ShuffleAlgebra(ZZ,'xyz')\n sage: F.gen(0)\n B[x]\n\n sage: F.gen(4)\n Traceback (most recent call last):\n ...\n IndexError: argument i (= 4) 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)))) return self.algebra_generators()[i] def some_elements(self): "\n Return some typical elements.\n\n EXAMPLES::\n\n sage: F = ShuffleAlgebra(ZZ,'xyz')\n sage: F.some_elements()\n [0, B[], B[x], B[y], B[z], B[xz] + B[zx]]\n " gens = list(self.algebra_generators()) if gens: gens.append((gens[0] * gens[(- 1)])) return ([self.zero(), self.one()] + gens) 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 = ShuffleAlgebra(QQ,'ab')\n sage: F.coproduct_on_basis(Word('a'))\n B[] # B[a] + B[a] # B[]\n sage: F.coproduct_on_basis(Word('aba'))\n B[] # B[aba] + B[a] # B[ba]\n + B[ab] # B[a] + B[aba] # B[]\n sage: F.coproduct_on_basis(Word())\n B[] # B[]\n\n TESTS::\n\n sage: F = ShuffleAlgebra(QQ,'ab')\n sage: S = F.an_element(); S\n B[] + 2*B[a] + 3*B[b] + B[bab]\n sage: F.coproduct(S)\n B[] # B[] + 2*B[] # B[a]\n + 3*B[] # B[b] + B[] # B[bab]\n + 2*B[a] # B[] + 3*B[b] # B[]\n + B[b] # B[ab] + B[ba] # B[b]\n + B[bab] # B[]\n sage: F.coproduct(F.one())\n B[] # B[]\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 = ShuffleAlgebra(QQ,'ab')\n sage: S = F.an_element(); S\n B[] + 2*B[a] + 3*B[b] + B[bab]\n sage: F.counit(S)\n 1\n " W = self.basis().keys() return S.coefficient(W()) def degree_on_basis(self, w): "\n Return the degree of the element ``w``.\n\n EXAMPLES::\n\n sage: A = ShuffleAlgebra(QQ, 'ab')\n sage: [A.degree_on_basis(x.leading_support()) for x in A.some_elements() if x != 0]\n [0, 1, 1, 2]\n " return ZZ(len(w)) @cached_method def algebra_generators(self): "\n Return the generators of this algebra.\n\n EXAMPLES::\n\n sage: A = ShuffleAlgebra(ZZ,'fgh'); A\n Shuffle Algebra on 3 generators ['f', 'g', 'h'] over Integer Ring\n sage: A.algebra_generators()\n Family (B[f], B[g], B[h])\n\n sage: A = ShuffleAlgebra(QQ, ['x1','x2'])\n sage: A.algebra_generators()\n Family (B[x1], B[x2])\n\n TESTS::\n\n sage: A = ShuffleAlgebra(ZZ,[0,1])\n sage: A.algebra_generators()\n Family (B[0], B[1])\n " Words = self.basis().keys() return Family([self.monomial(Words([a])) for a in self._alphabet]) gens = algebra_generators def _element_constructor_(self, x): "\n Convert ``x`` into ``self``.\n\n EXAMPLES::\n\n sage: R = ShuffleAlgebra(QQ,'xy')\n sage: x, y = R.gens()\n sage: R(3)\n 3*B[]\n sage: R(x)\n B[x]\n sage: R('xyy')\n B[xyy]\n sage: R(Word('xyx'))\n B[xyx]\n " if isinstance(x, (str, FiniteWord_class)): W = self.basis().keys() return self.monomial(W(x)) P = x.parent() if isinstance(P, ShuffleAlgebra): if (P is self): return x if (not (P is self.base_ring())): return self.element_class(self, x.monomial_coefficients()) if isinstance(P, DualPBWBasis): return self(P.expansion(x)) if isinstance(x, str): from sage.misc.sage_eval import sage_eval return sage_eval(x, locals=self.gens_dict()) R = self.base_ring() x = R(x) if (x == 0): return self.element_class(self, {}) else: return self.from_base_ring_from_one_basis(x) 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 - Shuffle Algebras in the same variables over a base with a coercion\n map into ``self.base_ring()``.\n\n - Anything with a coercion into ``self.base_ring()``.\n\n EXAMPLES::\n\n sage: F = ShuffleAlgebra(GF(7), 'xyz'); F\n Shuffle Algebra on 3 generators ['x', 'y', 'z'] over Finite Field of size 7\n\n Elements of the shuffle algebra canonically coerce in::\n\n sage: x, y, z = F.gens()\n sage: F.coerce(x*y) # indirect doctest\n B[xy] + B[yx]\n\n Elements of the integers coerce in, since there is a coerce map\n from `\\ZZ` to GF(7)::\n\n sage: F.coerce(1) # indirect doctest\n B[]\n\n There is no coerce map from `\\QQ` to `\\GF{7}`::\n\n sage: F.coerce(2/3) # indirect doctest\n Traceback (most recent call last):\n ...\n TypeError: no canonical coercion from Rational Field to Shuffle Algebra on 3 generators ['x', 'y', 'z'] over Finite Field of size 7\n\n Elements of the base ring coerce in::\n\n sage: F.coerce(GF(7)(5))\n 5*B[]\n\n The shuffle algebra over `\\ZZ` on `x, y, z` coerces in, since\n `\\ZZ` coerces to `\\GF{7}`::\n\n sage: G = ShuffleAlgebra(ZZ,'xyz')\n sage: Gx,Gy,Gz = G.gens()\n sage: z = F.coerce(Gx**2 * Gy);z\n 2*B[xxy] + 2*B[xyx] + 2*B[yxx]\n sage: z.parent() is F\n True\n\n However, `\\GF{7}` does not coerce to `\\ZZ`, so the shuffle\n algebra over `\\GF{7}` does not coerce to the one over `\\ZZ`::\n\n sage: G.coerce(x^3*y)\n Traceback (most recent call last):\n ...\n TypeError: no canonical coercion from Shuffle Algebra on 3 generators\n ['x', 'y', 'z'] over Finite Field of size 7 to Shuffle Algebra on 3\n generators ['x', 'y', 'z'] over Integer Ring\n\n TESTS::\n\n sage: F = ShuffleAlgebra(ZZ, 'xyz')\n sage: G = ShuffleAlgebra(QQ, 'xyz')\n sage: H = ShuffleAlgebra(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 False\n sage: F._coerce_map_from_(QQ)\n False\n sage: G._coerce_map_from_(QQ)\n True\n sage: F.has_coerce_map_from(PolynomialRing(ZZ, 3, 'x,y,z'))\n False\n sage: F._coerce_map_from_(F.dual_pbw_basis())\n True\n " if isinstance(R, ShuffleAlgebra): if (R.variable_names() == self.variable_names()): if self.base_ring().has_coerce_map_from(R.base_ring()): return True else: return False if isinstance(R, DualPBWBasis): return self.has_coerce_map_from(R._alg) return self.base_ring().has_coerce_map_from(R) def dual_pbw_basis(self): "\n Return the dual PBW of ``self``.\n\n EXAMPLES::\n\n sage: A = ShuffleAlgebra(QQ, 'ab')\n sage: A.dual_pbw_basis()\n The dual Poincare-Birkhoff-Witt basis of Shuffle Algebra on 2 generators ['a', 'b'] over Rational Field\n " return DualPBWBasis(self.base_ring(), self._alphabet) def to_dual_pbw_element(self, w): "\n Return the element `w` of ``self`` expressed in the dual PBW basis.\n\n INPUT:\n\n - ``w`` -- an element of the shuffle algebra\n\n EXAMPLES::\n\n sage: A = ShuffleAlgebra(QQ, 'ab')\n sage: f = 2 * A(Word()) + A(Word('ab')); f\n 2*B[] + B[ab]\n sage: A.to_dual_pbw_element(f)\n 2*S[] + S[ab]\n sage: A.to_dual_pbw_element(A.one())\n S[]\n sage: S = A.dual_pbw_basis()\n sage: elt = S.expansion_on_basis(Word('abba')); elt\n 2*B[aabb] + B[abab] + B[abba]\n sage: A.to_dual_pbw_element(elt)\n S[abba]\n sage: A.to_dual_pbw_element(2*A(Word('aabb')) + A(Word('abab')))\n S[abab]\n sage: S.expansion(S('abab'))\n 2*B[aabb] + B[abab]\n " D = self.dual_pbw_basis() l = {} W = self.basis().keys() while (w != self.zero()): support = [W(i[0]) for i in list(w)] min_elt = W(support[0]) if (len(support) > 1): for word in support[1:(len(support) - 1)]: if min_elt.lex_less(word): min_elt = W(word) coeff = list(w)[support.index(min_elt)][1] l[min_elt] = (l.get(min_elt, 0) + coeff) w = (w - (coeff * D.expansion_on_basis(W(min_elt)))) return D.sum_of_terms(((m, c) for (m, c) in l.items() if (c != 0)))
class DualPBWBasis(CombinatorialFreeModule): "\n The basis dual to the Poincaré-Birkhoff-Witt basis of the free algebra.\n\n We recursively define the dual PBW basis as the basis of the\n shuffle algebra given by\n\n .. MATH::\n\n S_w = \\begin{cases}\n w & |w| = 1, \\\\\n x S_u & w = xu \\text{ and } w \\in \\mathrm{Lyn}(X), \\\\\n \\displaystyle \\frac{S_{\\ell_{i_1}}^{\\ast \\alpha_1} \\ast \\cdots\n \\ast S_{\\ell_{i_k}}^{\\ast \\alpha_k}}{\\alpha_1! \\cdots \\alpha_k!} &\n w = \\ell_{i_1}^{\\alpha_1} \\cdots \\ell_{i_k}^{\\alpha_k} \\text{ with }\n \\ell_1 > \\cdots > \\ell_k \\in \\mathrm{Lyn}(X).\n \\end{cases}\n\n where `S \\ast T` denotes the shuffle product of `S` and `T` and\n `\\mathrm{Lyn}(X)` is the set of Lyndon words in the alphabet `X`.\n\n The definition may be found in Theorem 5.3 of [Reu1993]_.\n\n INPUT:\n\n - ``R`` -- ring\n\n - ``names`` -- names of the generators (string or an alphabet)\n\n EXAMPLES::\n\n sage: S = ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n sage: S\n The dual Poincare-Birkhoff-Witt basis of Shuffle Algebra on 2 generators ['a', 'b'] over Rational Field\n sage: S.one()\n S[]\n sage: S.one_basis()\n word:\n sage: T = ShuffleAlgebra(QQ, 'abcd').dual_pbw_basis(); T\n The dual Poincare-Birkhoff-Witt basis of Shuffle Algebra on 4 generators ['a', 'b', 'c', 'd'] over Rational Field\n sage: T.algebra_generators()\n (S[a], S[b], S[c], S[d])\n\n TESTS:\n\n We check conversion between the bases::\n\n sage: A = ShuffleAlgebra(QQ, 'ab')\n sage: S = A.dual_pbw_basis()\n sage: W = Words('ab', 5)\n sage: all(S(A(S(w))) == S(w) for w in W)\n True\n sage: all(A(S(A(w))) == A(w) for w in W)\n True\n " @staticmethod def __classcall_private__(cls, R, names): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: from sage.algebras.shuffle_algebra import DualPBWBasis\n sage: D1 = DualPBWBasis(QQ, 'ab')\n sage: D2 = DualPBWBasis(QQ, Alphabet('ab'))\n sage: D1 is D2\n True\n " return super().__classcall__(cls, R, Alphabet(names)) def __init__(self, R, names): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: D = ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n sage: TestSuite(D).run() # long time\n " self._alphabet = names self._alg = ShuffleAlgebra(R, names) cat = GradedHopfAlgebrasWithBasis(R).Commutative().Connected() CombinatorialFreeModule.__init__(self, R, Words(names), prefix='S', category=cat) def _repr_term(self, t): "\n Return a string representation of the basis element indexed by ``t``.\n\n EXAMPLES::\n\n sage: R = ShuffleAlgebra(QQ,'xyz').dual_pbw_basis()\n sage: R._repr_term(R._indices('xyzxxy'))\n 'S[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: ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n The dual Poincare-Birkhoff-Witt basis of Shuffle Algebra on 2 generators ['a', 'b'] over Rational Field\n " return 'The dual Poincare-Birkhoff-Witt basis of {}'.format(self._alg) def _element_constructor_(self, x): "\n Construct an element of ``self`` from ``x``.\n\n EXAMPLES::\n\n sage: A = ShuffleAlgebra(QQ, 'ab')\n sage: S = A.dual_pbw_basis()\n sage: S('abaab')\n S[abaab]\n sage: S(Word('aba'))\n S[aba]\n sage: S(A('ab'))\n S[ab]\n " if isinstance(x, (str, FiniteWord_class)): W = self.basis().keys() x = W(x) elif isinstance(x.parent(), ShuffleAlgebra): return self._alg.to_dual_pbw_element(self._alg(x)) return super()._element_constructor_(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 shuffle algebra of ``self``\n\n TESTS::\n\n sage: F = ShuffleAlgebra(ZZ, 'xyz').dual_pbw_basis()\n sage: G = ShuffleAlgebra(QQ, 'xyz').dual_pbw_basis()\n sage: H = ShuffleAlgebra(ZZ, 'y').dual_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.has_coerce_map_from(PolynomialRing(ZZ, 3, 'x,y,z'))\n False\n sage: F._coerce_map_from_(F._alg)\n True\n " return self._alg.has_coerce_map_from(R) def one_basis(self): "\n Return the indexing element of the basis element `1`.\n\n EXAMPLES::\n\n sage: S = ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n sage: S.one_basis()\n word:\n " W = self.basis().keys() return W([]) def counit(self, S): "\n Return the counit of ``S``.\n\n EXAMPLES::\n\n sage: F = ShuffleAlgebra(QQ,'ab').dual_pbw_basis()\n sage: (3*F.gen(0)+5*F.gen(1)**2).counit()\n 0\n sage: (4*F.one()).counit()\n 4\n " W = self.basis().keys() return S.coefficient(W()) def algebra_generators(self): "\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: S = ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n sage: S.algebra_generators()\n (S[a], S[b])\n " W = self.basis().keys() return tuple((self.monomial(W([a])) for a in self._alphabet)) gens = algebra_generators def gen(self, i): "\n Return the ``i``-th generator of ``self``.\n\n EXAMPLES::\n\n sage: S = ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n sage: S.gen(0)\n S[a]\n sage: S.gen(1)\n S[b]\n " return self.algebra_generators()[i] def some_elements(self): "\n Return some typical elements.\n\n EXAMPLES::\n\n sage: F = ShuffleAlgebra(QQ,'xyz').dual_pbw_basis()\n sage: F.some_elements()\n [0, S[], S[x], S[y], S[z], S[zx]]\n " gens = list(self.algebra_generators()) if gens: gens.append((gens[0] * gens[(- 1)])) return ([self.zero(), self.one()] + gens) def shuffle_algebra(self): "\n Return the associated shuffle algebra of ``self``.\n\n EXAMPLES::\n\n sage: S = ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n sage: S.shuffle_algebra()\n Shuffle Algebra on 2 generators ['a', 'b'] 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: S = ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n sage: a,b = S.gens()\n sage: S.product(a, b)\n S[ba]\n sage: S.product(b, a)\n S[ba]\n sage: S.product(b^2*a, a*b*a)\n 36*S[bbbaaa]\n\n TESTS:\n\n Check that multiplication agrees with the multiplication in the\n shuffle algebra::\n\n sage: A = ShuffleAlgebra(QQ, 'ab')\n sage: S = A.dual_pbw_basis()\n sage: a,b = S.gens()\n sage: A(a*b)\n B[ab] + B[ba]\n sage: A(a*b*a)\n 2*B[aab] + 2*B[aba] + 2*B[baa]\n sage: S(A(a)*A(b)*A(a)) == a*b*a\n True\n " return self((self.expansion(u) * self.expansion(v))) def antipode(self, elt): "\n Return the antipode of the element ``elt``.\n\n EXAMPLES::\n\n sage: A = ShuffleAlgebra(QQ, 'ab')\n sage: S = A.dual_pbw_basis()\n sage: w = S('abaab').antipode(); w\n S[abaab] - 2*S[ababa] - S[baaba]\n + 3*S[babaa] - 6*S[bbaaa]\n sage: w.antipode()\n S[abaab]\n " return self(self.expansion(elt).antipode()) def coproduct(self, elt): "\n Return the coproduct of the element ``elt``.\n\n EXAMPLES::\n\n sage: A = ShuffleAlgebra(QQ, 'ab')\n sage: S = A.dual_pbw_basis()\n sage: S('ab').coproduct()\n S[] # S[ab] + S[a] # S[b]\n + S[ab] # S[]\n sage: S('ba').coproduct()\n S[] # S[ba] + S[a] # S[b]\n + S[b] # S[a] + S[ba] # S[]\n\n TESTS::\n\n sage: all(A.tensor_square()(S(x).coproduct()) == x.coproduct()\n ....: for x in A.some_elements())\n True\n sage: all(S.tensor_square()(A(x).coproduct()) == x.coproduct()\n ....: for x in S.some_elements())\n True\n " return self.tensor_square()(self.expansion(elt).coproduct()) def degree_on_basis(self, w): "\n Return the degree of the element ``w``.\n\n EXAMPLES::\n\n sage: S = ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n sage: [S.degree_on_basis(x.leading_support()) for x in S.some_elements() if x != 0]\n [0, 1, 1, 2]\n " return ZZ(len(w)) @lazy_attribute def expansion(self): "\n Return the morphism corresponding to the expansion into words of\n the shuffle algebra.\n\n EXAMPLES::\n\n sage: S = ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n sage: f = S('ab') + S('aba')\n sage: S.expansion(f)\n 2*B[aab] + B[ab] + B[aba]\n " return self.module_morphism(self.expansion_on_basis, codomain=self._alg) @cached_method def expansion_on_basis(self, w): "\n Return the expansion of `S_w` in words of the shuffle algebra.\n\n INPUT:\n\n - ``w`` -- a word\n\n EXAMPLES::\n\n sage: S = ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n sage: S.expansion_on_basis(Word())\n B[]\n sage: S.expansion_on_basis(Word()).parent()\n Shuffle Algebra on 2 generators ['a', 'b'] over Rational Field\n sage: S.expansion_on_basis(Word('abba'))\n 2*B[aabb] + B[abab] + B[abba]\n sage: S.expansion_on_basis(Word())\n B[]\n sage: S.expansion_on_basis(Word('abab'))\n 2*B[aabb] + B[abab]\n " from sage.arith.misc import factorial if (not w): return self._alg.one() if (len(w) == 1): return self._alg.monomial(w) if w.is_lyndon(): W = self.basis().keys() letter = W([w[0]]) expansion = self.expansion_on_basis(W(w[1:])) return self._alg.sum_of_terms((((letter * i), c) for (i, c) in expansion)) lf = w.lyndon_factorization() powers = {} for i in lf: powers[i] = (powers.get(i, 0) + 1) denom = prod((factorial(p) for p in powers.values())) result = self._alg.prod((self.expansion_on_basis(i) for i in lf)) return self._alg((result / denom)) class Element(CombinatorialFreeModule.Element): '\n An element in the dual PBW basis.\n ' def expand(self): "\n Expand ``self`` in words of the shuffle algebra.\n\n EXAMPLES::\n\n sage: S = ShuffleAlgebra(QQ, 'ab').dual_pbw_basis()\n sage: f = S('ab') + S('bab')\n sage: f.expand()\n B[ab] + 2*B[abb] + B[bab]\n " return self.parent().expansion(self)
class SplittingAlgebraElement(PolynomialQuotientRingElement): "\n Element class for :class:`SplittingAlgebra`.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: cp6 = cyclotomic_polynomial(6)\n sage: CR6.<e6> = SplittingAlgebra(cp6)\n sage: type(e6)\n <class 'sage.algebras.splitting_algebra.SplittingAlgebra_with_category.element_class'>\n\n sage: type(CR6(5))\n <class 'sage.algebras.splitting_algebra.SplittingAlgebra_with_category.element_class'>\n " def __invert__(self): '\n Return the inverse of ``self``.\n\n Support inversion of special elements attached to the construction\n of the parent and which are recorded in the list\n ``self.parent()._invertible_elements``.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: CR3.<e3> = SplittingAlgebra(cyclotomic_polynomial(3))\n sage: ~e3\n -e3 - 1\n sage: ~(e3 + 5)\n Traceback (most recent call last):\n ...\n NotImplementedError: The base ring (=Integer Ring) is not a field\n ' inv_elements = self.parent()._invertible_elements if (self in inv_elements): return inv_elements[self] return super().__invert__() def is_unit(self): '\n Return ``True`` if ``self`` is invertible.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: CR3.<e3> = SplittingAlgebra(cyclotomic_polynomial(3))\n sage: e3.is_unit()\n True\n ' inv_elements = self.parent()._invertible_elements if (self in inv_elements): return True return super().is_unit() def dict(self): '\n Return the dictionary of ``self`` according to its lift to the cover.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: CR3.<e3> = SplittingAlgebra(cyclotomic_polynomial(3))\n sage: (e3 + 42).dict()\n {0: 42, 1: 1}\n ' return self.lift().dict()
class SplittingAlgebra(PolynomialQuotientRing_domain): '\n For a given monic polynomial `p(t)` of degree `n` over a commutative\n ring `R`, the splitting algebra is the universal `R`-algebra in which\n `p(t)` has `n` roots, or, more precisely, over which `p(t)` factors,\n\n .. MATH::\n\n p(t) = (t - \\xi_1) \\cdots (t - \\xi_n).\n\n This class creates an algebra as extension over the base ring of a\n given polynomial `p` such that `p` splits into linear factors over\n that extension. It is assumed (and not checked in general) that the\n Galois group of `p` is the symmetric Group `S(n)`. The construction\n is recursive (following [LT2012]_, 1.3).\n\n INPUT:\n\n - ``monic_polynomial`` -- the monic polynomial which should be split\n - ``names`` -- names for the indeterminates to be adjoined to the\n base ring of ``monic_polynomial``\n - ``warning`` -- (default: ``True``) can be used (by setting to ``False``)\n to suppress a warning which will be thrown whenever it cannot be\n checked that the Galois group of ``monic_polynomial`` is maximal\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: Lc.<w> = LaurentPolynomialRing(ZZ)\n sage: PabLc.<u,v> = Lc[]; t = polygen(PabLc)\n sage: S.<x, y> = SplittingAlgebra(t^3 - u*t^2 + v*t - w)\n doctest:...: UserWarning: Assuming x^3 - u*x^2 + v*x - w to have maximal\n Galois group!\n\n sage: roots = S.splitting_roots(); roots\n [x, y, -y - x + u]\n sage: all(t^3 -u*t^2 +v*t -w == 0 for t in roots)\n True\n sage: xi = ~x; xi\n (w^-1)*x^2 + ((-w^-1)*u)*x + (w^-1)*v\n sage: ~xi == x\n True\n sage: ~y\n ((-w^-1)*x)*y + (-w^-1)*x^2 + ((w^-1)*u)*x\n sage: zi = ((w^-1)*x)*y; ~zi\n -y - x + u\n\n sage: cp3 = cyclotomic_polynomial(3).change_ring(GF(5))\n sage: CR3.<e3> = SplittingAlgebra(cp3)\n sage: CR3.is_field()\n True\n sage: CR3.cardinality()\n 25\n sage: F.<a> = cp3.splitting_field()\n sage: F.cardinality()\n 25\n sage: E3 = cp3.change_ring(F).roots()[0][0]; E3\n 3*a + 3\n sage: f = CR3.hom([E3]); f\n Ring morphism:\n From: Splitting Algebra of x^2 + x + 1\n with roots [e3, 4*e3 + 4]\n over Finite Field of size 5\n To: Finite Field in a of size 5^2\n Defn: e3 |--> 3*a + 3\n\n REFERENCES:\n\n - [EL2002]_\n - [Lak2010]_\n - [Tho2011]_\n - [LT2012]_\n ' Element = SplittingAlgebraElement def __init__(self, monic_polynomial, names='X', iterate=True, warning=True): '\n Python constructor.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: Lw.<w> = LaurentPolynomialRing(ZZ)\n sage: PuvLw.<u,v> = Lw[]; t = polygen(PuvLw)\n sage: S.<x, y> = SplittingAlgebra(t^3 - u*t^2 + v*t - w, warning=False)\n sage: TestSuite(S).run()\n ' base_ring = monic_polynomial.base_ring() if (not monic_polynomial.is_monic()): raise ValueError('given polynomial must be monic') deg = monic_polynomial.degree() from sage.structure.category_object import normalize_names self._root_names = normalize_names((deg - 1), names) root_names = list(self._root_names) verbose(('Create splitting algebra to base ring %s and polynomial %s (%s %s)' % (base_ring, monic_polynomial, iterate, warning))) self._defining_polynomial = monic_polynomial self._iterate = iterate try: if (not base_ring.is_integral_domain()): raise TypeError('base_ring must be an integral domain') except NotImplementedError: from sage.rings.ring import Ring if (not isinstance(base_ring, Ring)): raise TypeError('base_ring must be an instance of ring') if warning: warn(('Assuming %s to be an integral domain!' % base_ring)) if (deg < 1): raise ValueError('the degree of the polynomial must positive') self._splitting_roots = [] self._coefficients_list = [] self._invertible_elements = {} if isinstance(base_ring, SplittingAlgebra): self._invertible_elements = base_ring._invertible_elements root_name = root_names[0] p = monic_polynomial.change_variable_name(root_name) P = p.parent() self._set_modulus_irreducible_ = False try: if (not p.is_irreducible()): raise ValueError('monic_polynomial must be irreducible') except (NotImplementedError, AttributeError): self._set_modulus_irreducible_ = True if warning: warn(('Assuming %s to have maximal Galois group!' % monic_polynomial)) warning = False verbose(('P %s defined:' % P)) if ((deg > 2) and iterate): base_ring_step = SplittingAlgebra(monic_polynomial, tuple(root_names), iterate=False, warning=False) first_root = base_ring_step.gen() verbose(('base_ring_step %s defined:' % base_ring_step)) from copy import copy root_names_reduces = copy(root_names) root_names_reduces.remove(root_name) P = base_ring_step[root_names_reduces[0]] p = P(monic_polynomial.dict()) (q, _) = p.quo_rem((P.gen() - first_root)) verbose(('Invoking recursion with: %s' % (q,))) SplittingAlgebra.__init__(self, q, root_names_reduces, warning=False) splitting_roots = (base_ring_step._splitting_roots + self._splitting_roots) coefficients_list = (base_ring_step._coefficients_list + self._coefficients_list) verbose(('Adding roots: %s' % splitting_roots)) self._splitting_roots = splitting_roots self._coefficients_list = coefficients_list else: PolynomialQuotientRing_domain.__init__(self, P, p, root_name) first_root = self.gen() self._splitting_roots.append(first_root) self._coefficients_list = [monic_polynomial.coefficients(sparse=False)] if (not iterate): verbose(('pre ring defined splitting_roots: %s' % self._splitting_roots)) return verbose(('final ring defined splitting_roots: %s' % self._splitting_roots)) if (deg == 2): coefficients = monic_polynomial.coefficients(sparse=False) lin_coeff = coefficients[1] self._splitting_roots.append(((- lin_coeff) - first_root)) self._root_names = names self._splitting_roots = [self(root) for root in self._splitting_roots] verbose(('splitting_roots: %s embedded' % self._splitting_roots)) cf0_inv = None for cf in self._coefficients_list: cf0 = cf[0] try: cf0_inv = (~ cf[0]) cf0_inv = self(cf0_inv) verbose(('invertible coefficient: %s found' % cf0_inv)) break except NotImplementedError: verbose(('constant coefficient: %s not invertibe' % cf0)) if (cf0_inv is not None): deg_cf = (len(cf) - 1) pf = P(cf) for root in self._splitting_roots: check = self(pf) if (not check.is_zero()): continue root_inv = self.one() for pos in range((deg_cf - 1)): root_inv = ((((- 1) ** (pos + 1)) * cf[((deg_cf - pos) - 1)]) - (root_inv * root)) verbose(('inverse %s of root %s' % (root_inv, root))) root_inv = ((((- 1) ** deg_cf) * cf0_inv) * root_inv) self._invertible_elements.update({root: root_inv}) verbose(('adding inverse %s of root %s' % (root_inv, root))) invert_items = list(self._invertible_elements.items()) for (k, v) in invert_items: self._invertible_elements.update({v: k}) return def __reduce__(self): "\n Used in pickling.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: L.<t, u, v, w > = LaurentPolynomialRing(ZZ); x = polygen(L)\n sage: S = SplittingAlgebra(x^4 -t*x^3 - u*x^2 - v*x + w, ('X', 'Y', 'Z'), warning=False)\n sage: S.__reduce__()\n (<class 'sage.algebras.splitting_algebra.SplittingAlgebra_with_category'>,\n (x^4 - t*x^3 - u*x^2 - v*x + w, ('X', 'Y', 'Z'), True, False))\n sage: S.base_ring().__reduce__()\n (<class 'sage.algebras.splitting_algebra.SplittingAlgebra_with_category'>,\n (Y^3 + (X - t)*Y^2 + (X^2 - t*X - u)*Y + X^3 - t*X^2 - u*X - v,\n ('Y', 'Z'),\n False,\n False))\n\n sage: TestSuite(S).run()\n " defining_polynomial = self.defining_polynomial() definig_coefficients = self._coefficients_list[0] if (defining_polynomial.coefficients(sparse=False) != definig_coefficients): par_pol = self.cover_ring() defining_polynomial = par_pol(definig_coefficients) return (self.__class__, (defining_polynomial, self._root_names, self._iterate, False)) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: L.<u, v> = PolynomialRing(ZZ)\n sage: t = polygen(L)\n sage: Spl.<S, T> = SplittingAlgebra(t^3 - (u^2-v)*t^2 + (v+u)*t - 1)\n sage: Spl._repr_()\n 'Splitting Algebra of x^3 + (-u^2 + v)*x^2 + (u + v)*x - 1\n with roots [S, T, -T - S + u^2 - v]\n over Multivariate Polynomial Ring in u, v over Integer Ring'\n sage: Spl.base_ring() # indirect doctest\n Factorization Algebra of x^3 + (-u^2 + v)*x^2 + (u + v)*x - 1\n with roots [S] over Multivariate Polynomial Ring in u, v over Integer Ring\n " if self.is_completely_split(): return ('Splitting Algebra of %s with roots %s over %s' % (self.defining_polynomial(), self.splitting_roots(), self.scalar_base_ring())) else: return ('Factorization Algebra of %s with roots %s over %s' % (self.defining_polynomial(), self.splitting_roots(), self.scalar_base_ring())) def _first_ngens(self, n): '\n Used by the preparser for ``R.<x> = ...``.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: L.<u, v> = PolynomialRing(ZZ)\n sage: t = polygen(L)\n sage: S.<X, Y> = SplittingAlgebra(t^3 - (u^2-v)*t^2 + (v+u)*t - 1) # indirect doctest\n sage: X.parent()\n Splitting Algebra of x^3 + (-u^2 + v)*x^2 + (u + v)*x - 1\n with roots [X, Y, -Y - X + u^2 - v]\n over Multivariate Polynomial Ring in u, v over Integer Ring\n sage: S._first_ngens(4)\n (X, Y, u, v)\n ' srts = self.splitting_roots() k = (len(srts) - 1) gens = (srts[:k] + list(self.scalar_base_ring().gens())) return tuple(gens[:n]) def _element_constructor_(self, x): '\n Make sure ``x`` is a valid member of ``self``, and return the constructed element.\n\n TESTS::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: L.<u, v, w> = LaurentPolynomialRing(ZZ); x = polygen(L)\n sage: S.<X, Y> = SplittingAlgebra(x^3 - u*x^2 + v*x - w)\n sage: S(u + v)\n u + v\n sage: S(X*Y + X)\n X*Y + X\n sage: TestSuite(S).run() # indirect doctest\n ' if isinstance(x, SplittingAlgebraElement): return self(x.lift()) return super()._element_constructor_(x) def hom(self, im_gens, codomain=None, check=True, base_map=None): "\n This version keeps track with the special recursive structure\n of :class:`SplittingAlgebra`\n\n Type ``Ring.hom?`` to see the general documentation of this method.\n Here you see just special examples for the current class.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: L.<u, v, w> = LaurentPolynomialRing(ZZ); x = polygen(L)\n sage: S = SplittingAlgebra(x^3 - u*x^2 + v*x - w, ('X', 'Y'))\n sage: P.<x, y, z> = PolynomialRing(ZZ)\n sage: F = FractionField(P)\n sage: im_gens = [F(g) for g in [y, x, x + y + z, x*y+x*z+y*z, x*y*z]]\n sage: f = S.hom(im_gens)\n sage: f(u), f(v), f(w)\n (x + y + z, x*y + x*z + y*z, x*y*z)\n sage: roots = S.splitting_roots(); roots\n [X, Y, -Y - X + u]\n sage: [f(r) for r in roots]\n [x, y, z]\n " base_ring = self.base_ring() if (not isinstance(im_gens, (list, tuple))): im_gens = [im_gens] all_gens = self.gens_dict_recursive() if (len(im_gens) != len(all_gens)): return super().hom(im_gens, codomain=codomain, check=check, base_map=base_map) num_gens = len(self.gens()) im_gens_start = [img for img in im_gens if (im_gens.index(img) < num_gens)] im_gens_end = [img for img in im_gens if (im_gens.index(img) >= num_gens)] if (not im_gens_end): return super().hom(im_gens, codomain=codomain, check=check, base_map=base_map) verbose(('base %s im_gens_end %s codomain %s check %s base_map %s' % (base_ring, im_gens_end, codomain, check, base_map))) hom_on_base_recurs = base_ring.hom(im_gens_end, codomain=codomain, check=check, base_map=base_map) verbose(('hom_on_base_recurs %s' % hom_on_base_recurs)) cover_ring = self.cover_ring() hom_from_cover = cover_ring.hom(im_gens_start, codomain=codomain, check=check, base_map=hom_on_base_recurs) lift = self.lifting_map() return (hom_from_cover * lift) def is_completely_split(self): '\n Return True if the defining polynomial of ``self`` splits into linear factors over ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: L.<u, v, w > = LaurentPolynomialRing(ZZ); x = polygen(L)\n sage: S.<a,b> = SplittingAlgebra(x^3 - u*x^2 + v*x - w)\n sage: S.is_completely_split()\n True\n sage: S.base_ring().is_completely_split()\n False\n ' return (len(self.splitting_roots()) >= self.defining_polynomial().degree()) @cached_method def lifting_map(self): "\n Return a section map from ``self`` to the cover ring. It is implemented according\n to the same named method of :class:`~sage.rings.quotient_ring.QuotientRing_nc`.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: x = polygen(ZZ)\n sage: S = SplittingAlgebra(x^2+1, ('I',))\n sage: lift = S.lifting_map()\n sage: lift(5)\n 5\n sage: r1, r2 =S.splitting_roots()\n sage: lift(r1)\n I\n " from sage.rings.morphism import RingMap_lift return RingMap_lift(self, self.cover_ring()) def splitting_roots(self): "\n Return the roots of the split equation.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: x = polygen(ZZ)\n sage: S = SplittingAlgebra(x^2+1, ('I',))\n sage: S.splitting_roots()\n [I, -I]\n " return self._splitting_roots @cached_method def scalar_base_ring(self): "\n Return the ring of scalars of ``self`` (considered as an algebra)\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: L.<u, v, w > = LaurentPolynomialRing(ZZ)\n sage: x = polygen(L)\n sage: S = SplittingAlgebra(x^3 - u*x^2 + v*x - w, ('X', 'Y'))\n sage: S.base_ring()\n Factorization Algebra of x^3 - u*x^2 + v*x - w with roots [X]\n over Multivariate Laurent Polynomial Ring in u, v, w over Integer Ring\n sage: S.scalar_base_ring()\n Multivariate Laurent Polynomial Ring in u, v, w over Integer Ring\n " base_ring = self.base_ring() if isinstance(base_ring, SplittingAlgebra): if base_ring.is_completely_split(): return base_ring else: return base_ring.scalar_base_ring() return base_ring @cached_method def defining_polynomial(self): "\n Return the defining polynomial of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import SplittingAlgebra\n sage: L.<u, v, w > = LaurentPolynomialRing(ZZ)\n sage: x = polygen(L)\n sage: S = SplittingAlgebra(x^3 - u*x^2 + v*x - w, ('X', 'Y'))\n sage: S.defining_polynomial()\n x^3 - u*x^2 + v*x - w\n " base_ring = self.base_ring() if isinstance(base_ring, SplittingAlgebra): if base_ring.is_completely_split(): return self._defining_polynomial else: return base_ring.defining_polynomial() return self._defining_polynomial
def solve_with_extension(monic_polynomial, root_names=None, var='x', flatten=False, warning=True): "\n Return all roots of a monic polynomial in its base ring or in an appropriate\n extension ring, as far as possible.\n\n INPUT:\n\n - ``monic_polynomial`` -- the monic polynomial whose roots should be created\n - ``root_names`` -- names for the indeterminates needed to define the\n splitting algebra of the ``monic_polynomial`` (if necessary and possible)\n - ``var`` -- (default: ``'x'``) for the indeterminate needed to define the\n splitting field of the ``monic_polynomial`` (if necessary and possible)\n - ``flatten`` -- (default: ``True``) if ``True`` the roots will not be\n given as a list of pairs ``(root, multiplicity)`` but as a list of\n roots repeated according to their multiplicity\n - ``warning`` -- (default: ``True``) can be used (by setting to ``False``)\n to suppress a warning which will be thrown whenever it cannot be checked\n that the Galois group of ``monic_polynomial`` is maximal\n\n OUTPUT:\n\n List of tuples ``(root, multiplicity)`` respectively list of roots repeated\n according to their multiplicity if option ``flatten`` is ``True``.\n\n EXAMPLES::\n\n sage: from sage.algebras.splitting_algebra import solve_with_extension\n sage: t = polygen(ZZ)\n sage: p = t^2 -2*t +1\n sage: solve_with_extension(p, flatten=True )\n [1, 1]\n sage: solve_with_extension(p)\n [(1, 2)]\n\n sage: cp5 = cyclotomic_polynomial(5, var='T').change_ring(UniversalCyclotomicField())\n sage: solve_with_extension(cp5)\n [(E(5), 1), (E(5)^4, 1), (E(5)^2, 1), (E(5)^3, 1)]\n sage: _[0][0].parent()\n Universal Cyclotomic Field\n " def create_roots(monic_polynomial, warning=True): '\n This internal function creates all roots of a polynomial in an\n appropriate extension ring assuming that none of the roots is\n contained its base ring.\n\n It first tries to create the splitting field of the given polynomial.\n If this is not faithful the splitting algebra will be created.\n\n INPUT:\n\n - ``monic_polynomial`` -- the monic polynomial whose roots should\n be created\n - ``warning`` -- (default: ``True``) can be used (by setting to ``False``)\n to suppress a warning which will be thrown whenever it cannot be\n checked that the Galois group of ``monic_polynomial`` is maximal\n ' parent = monic_polynomial.parent() base_ring = parent.base_ring() try: (ext_field, embed) = monic_polynomial.splitting_field(var, map=True) if (embed.domain() != base_ring): raise NotImplementedError reset_coercion = False from sage.rings.number_field.number_field import NumberField_generic if isinstance(base_ring, NumberField_generic): reset_coercion = True elif (base_ring.is_finite() and (not base_ring.is_prime_field())): reset_coercion = True if reset_coercion: ext_field._unset_coercions_used() ext_field.register_coercion(embed) ext_field.register_conversion(embed) verbose(('splitting field %s defined' % ext_field)) pol_emb = monic_polynomial.change_ring(ext_field) roots = pol_emb.roots() except NotImplementedError: ext_ring = SplittingAlgebra(monic_polynomial, name_list, warning=warning) verbose(('splitting algebra %s defined' % ext_ring)) roots = [(r, 1) for r in ext_ring.splitting_roots()] return roots deg_pol = monic_polynomial.degree() if (not root_names): from sage.structure.category_object import normalize_names root_names = normalize_names((deg_pol - 1), 'r') name_list = list(root_names) root_list = [] try: root_list = monic_polynomial.roots() except (TypeError, ValueError, NotImplementedError): pass if (not root_list): verbose('no roots in base_ring') if (len(name_list) > (deg_pol - 1)): name_list = [name_list[i] for i in range((deg_pol - 1))] roots = create_roots(monic_polynomial, warning=warning) else: num_roots = sum((m for (r, m) in root_list)) if (num_roots < deg_pol): h = monic_polynomial.variables()[0] divisor = monic_polynomial.base_ring().one() for (r, m) in root_list: divisor *= ((h - r) ** m) (q, r) = monic_polynomial.quo_rem(divisor) if (len(name_list) > ((deg_pol - num_roots) - 1)): name_list = [name_list[i] for i in range(((deg_pol - num_roots) - 1))] verbose(('%d root found in base ring, now solving %s' % (num_roots, q))) missing_roots = create_roots(q, warning=True) roots = (root_list + missing_roots) else: roots = root_list verbose('all roots in base ring') if flatten: from sage.misc.flatten import flatten return flatten([([rt] * m) for (rt, m) in roots]) return roots
class SteenrodAlgebra_generic(CombinatorialFreeModule): "\n The mod `p` Steenrod algebra.\n\n Users should not call this, but use the function\n :func:`SteenrodAlgebra` instead. See that function for\n extensive documentation.\n\n EXAMPLES::\n\n sage: sage.algebras.steenrod.steenrod_algebra.SteenrodAlgebra_generic()\n mod 2 Steenrod algebra, milnor basis\n sage: sage.algebras.steenrod.steenrod_algebra.SteenrodAlgebra_generic(5)\n mod 5 Steenrod algebra, milnor basis\n sage: sage.algebras.steenrod.steenrod_algebra.SteenrodAlgebra_generic(5, 'adem')\n mod 5 Steenrod algebra, serre-cartan basis\n " @staticmethod def __classcall__(self, p=2, basis='milnor', **kwds): "\n This normalizes the basis name and the profile, to make unique\n representation work properly.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(basis='adem') is SteenrodAlgebra(basis='serre-cartan')\n True\n sage: SteenrodAlgebra(profile=[3,2,1,0]) is SteenrodAlgebra(profile=lambda n: max(4-n,0), truncation_type=0)\n True\n sage: SteenrodAlgebra(p=5) is SteenrodAlgebra(p=5, generic=True)\n True\n " from .steenrod_algebra_misc import get_basis_name, normalize_profile profile = kwds.get('profile', None) precision = kwds.get('precision', None) truncation_type = kwds.get('truncation_type', 'auto') generic = kwds.get('generic', 'auto') if (generic == 'auto'): std_generic = (p != 2) else: std_generic = generic if (p != 2): std_generic = True if (not ((std_generic is True) or (std_generic is False))): raise ValueError("option 'generic' is not a boolean") std_basis = get_basis_name(basis, p, generic=std_generic) (std_profile, std_type) = normalize_profile(profile, precision=precision, truncation_type=truncation_type, p=p, generic=std_generic) return super().__classcall__(self, p=p, basis=std_basis, profile=std_profile, truncation_type=std_type, generic=std_generic) def __init__(self, p=2, basis='milnor', **kwds): "\n INPUT:\n\n - ``p`` - positive prime integer (optional, default 2)\n - ``basis`` - string (optional, default = 'milnor')\n - ``profile`` - profile function (optional, default ``None``)\n - ``truncation_type`` - (optional, default 'auto')\n - ``precision`` - (optional, default ``None``)\n - ``generic`` - (optional, default 'auto')\n\n OUTPUT:\n\n mod `p` Steenrod algebra with basis, or a sub-Hopf\n algebra of the mod `p` Steenrod algebra defined by the given\n profile function.\n\n See :func:`SteenrodAlgebra` for full documentation.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra() # 2 is the default prime\n mod 2 Steenrod algebra, milnor basis\n sage: SteenrodAlgebra(5)\n mod 5 Steenrod algebra, milnor basis\n sage: SteenrodAlgebra(2, 'milnor').Sq(0,1)\n Sq(0,1)\n sage: SteenrodAlgebra(2, 'adem').Sq(0,1)\n Sq^2 Sq^1 + Sq^3\n\n TESTS::\n\n sage: TestSuite(SteenrodAlgebra()).run()\n sage: TestSuite(SteenrodAlgebra(profile=[4,3,2,2,1])).run()\n sage: TestSuite(SteenrodAlgebra(basis='adem')).run()\n sage: TestSuite(SteenrodAlgebra(basis='wall')).run()\n sage: TestSuite(SteenrodAlgebra(basis='arnonc')).run() # long time\n sage: TestSuite(SteenrodAlgebra(basis='woody')).run() # long time\n sage: A3 = SteenrodAlgebra(3)\n sage: A3.category()\n Category of supercocommutative super Hopf algebras\n with basis over Finite Field of size 3\n sage: TestSuite(A3).run() # long time\n sage: TestSuite(SteenrodAlgebra(basis='adem', p=3)).run()\n sage: TestSuite(SteenrodAlgebra(basis='pst_llex', p=7)).run() # long time\n sage: TestSuite(SteenrodAlgebra(basis='comm_deg', p=5)).run() # long time\n sage: TestSuite(SteenrodAlgebra(p=2, generic=True)).run() # long time\n\n Two Steenrod algebras are equal iff their associated primes,\n bases, and profile functions (if present) are equal. Because\n this class inherits from :class:`UniqueRepresentation`, this\n means that they are equal if and only they are identical: ``A\n == B`` is True if and only if ``A is B`` is ``True``::\n\n sage: A = SteenrodAlgebra(2)\n sage: B = SteenrodAlgebra(2, 'adem')\n sage: A == B\n False\n sage: C = SteenrodAlgebra(17)\n sage: A == C\n False\n\n sage: A1 = SteenrodAlgebra(2, profile=[2,1])\n sage: A1 == A\n False\n sage: A1 == SteenrodAlgebra(2, profile=[2,1,0])\n True\n sage: A1 == SteenrodAlgebra(2, profile=[2,1], basis='pst')\n False\n " from sage.arith.misc import is_prime from sage.categories.super_hopf_algebras_with_basis import SuperHopfAlgebrasWithBasis from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets from sage.rings.infinity import Infinity from sage.sets.set_from_iterator import EnumeratedSetFromIterator from functools import partial from .steenrod_algebra_bases import steenrod_algebra_basis from sage.rings.finite_rings.finite_field_constructor import GF profile = kwds.get('profile', None) truncation_type = kwds.get('truncation_type', 'auto') self._generic = kwds.get('generic') assert ((self._generic is True) or ((p == 2) and (self._generic is False))) if (not is_prime(p)): raise ValueError(('%s is not prime' % p)) self._prime = p base_ring = GF(p) self._profile = profile self._truncation_type = truncation_type if (((not self._generic) and (profile and (profile[0] < Infinity))) or (self._generic and (profile != ((), ())) and profile[0] and (profile[0][0] < Infinity)) or (truncation_type < Infinity)): if ((basis != 'milnor') and (basis.find('pst') == (- 1))): raise NotImplementedError('for sub-Hopf algebras of the Steenrod algebra, only the Milnor basis and the pst bases are implemented') self._basis_name = basis basis_category = (FiniteEnumeratedSets() if self.is_finite() else InfiniteEnumeratedSets()) basis_set = EnumeratedSetFromIterator(self._basis_key_iterator, category=basis_category, name=('basis key family of %s' % self), cache=False) self._basis_fcn = partial(steenrod_algebra_basis, p=p, basis=basis, profile=profile, truncation_type=truncation_type, generic=self._generic) cat = SuperHopfAlgebrasWithBasis(base_ring).Supercocommutative() CombinatorialFreeModule.__init__(self, base_ring, basis_set, prefix=self._basis_name, element_class=self.Element, category=cat, scalar_mult=' ') from sage.modules.fp_graded.steenrod.module import SteenrodFPModule, SteenrodFreeModule self._fp_graded_module_class = SteenrodFPModule self._free_graded_module_class = SteenrodFreeModule def _basis_key_iterator(self): '\n An iterator for the basis keys of the Steenrod algebra.\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra(3,basis=\'adem\')\n sage: for (idx,key) in zip((1,..,10),A._basis_key_iterator()):\n ....: print("> %2d %-20s %s" % (idx,key,A.monomial(key)))\n > 1 () 1\n > 2 (1,) beta\n > 3 (0, 1, 0) P^1\n > 4 (1, 1, 0) beta P^1\n > 5 (0, 1, 1) P^1 beta\n > 6 (1, 1, 1) beta P^1 beta\n > 7 (0, 2, 0) P^2\n > 8 (1, 2, 0) beta P^2\n > 9 (0, 2, 1) P^2 beta\n > 10 (1, 2, 1) beta P^2 beta\n ' from .steenrod_algebra_bases import steenrod_algebra_basis from sage.sets.integer_range import IntegerRange from sage.rings.integer import Integer from sage.rings.infinity import Infinity from functools import partial import itertools if self.is_finite(): maxdim = self.top_class().degree() Ir = IntegerRange(Integer(0), Integer((maxdim + 1))) else: Ir = IntegerRange(Integer(0), Infinity) basfnc = partial(steenrod_algebra_basis, p=self.prime(), basis=self._basis_name, profile=self._profile, truncation_type=self._truncation_type) return itertools.chain.from_iterable((basfnc(dim) for dim in Ir)) def prime(self): '\n The prime associated to self.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(p=2, profile=[1,1]).prime()\n 2\n sage: SteenrodAlgebra(p=7).prime()\n 7\n ' return self._prime def basis_name(self): "\n The basis name associated to self.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(p=2, profile=[1,1]).basis_name()\n 'milnor'\n sage: SteenrodAlgebra(basis='serre-cartan').basis_name()\n 'serre-cartan'\n sage: SteenrodAlgebra(basis='adem').basis_name()\n 'serre-cartan'\n " return self.prefix() def _has_nontrivial_profile(self): '\n True if the profile function for this algebra seems to be that\n for a proper sub-Hopf algebra of the Steenrod algebra.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra()._has_nontrivial_profile()\n False\n sage: SteenrodAlgebra(p=3)._has_nontrivial_profile()\n False\n sage: SteenrodAlgebra(profile=[3,2,1])._has_nontrivial_profile()\n True\n sage: SteenrodAlgebra(profile=([1], [2, 2]), p=3)._has_nontrivial_profile()\n True\n sage: SteenrodAlgebra(generic=True)._has_nontrivial_profile()\n False\n sage: SteenrodAlgebra(generic=True, profile=[[3,2,1], []])._has_nontrivial_profile()\n True\n\n Check that a bug in :trac:`11832` has been fixed::\n\n sage: P3 = SteenrodAlgebra(p=3, profile=(lambda n: Infinity, lambda n: 1))\n sage: P3._has_nontrivial_profile()\n True\n ' from sage.rings.infinity import Infinity profile = self._profile trunc = self._truncation_type if (not self._generic): return ((profile and (profile[0] < Infinity)) or (trunc < Infinity)) return (((profile != ((), ())) and ((profile[0] and (profile[0][0] < Infinity)) or (profile[1] and (min(profile[1]) == 1)))) or (trunc < Infinity)) def _repr_(self): "\n Printed representation of the Steenrod algebra.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(3)\n mod 3 Steenrod algebra, milnor basis\n sage: SteenrodAlgebra(2, basis='adem')\n mod 2 Steenrod algebra, serre-cartan basis\n sage: B = SteenrodAlgebra(2003) # needs sage.rings.finite_rings\n sage: B._repr_() # needs sage.rings.finite_rings\n 'mod 2003 Steenrod algebra, milnor basis'\n sage: SteenrodAlgebra(generic=True, basis='adem')\n generic mod 2 Steenrod algebra, serre-cartan basis\n\n sage: SteenrodAlgebra(profile=(3,2,1,0))\n sub-Hopf algebra of mod 2 Steenrod algebra, milnor basis, profile function [3, 2, 1]\n sage: SteenrodAlgebra(profile=lambda n: 4)\n sub-Hopf algebra of mod 2 Steenrod algebra, milnor basis, profile function [4, 4, 4, ..., 4, 4, +Infinity, +Infinity, +Infinity, ...]\n sage: SteenrodAlgebra(p=5, profile=(lambda n: 4, lambda n: 1))\n sub-Hopf algebra of mod 5 Steenrod algebra, milnor basis, profile function ([4, 4, 4, ..., 4, 4, +Infinity, +Infinity, +Infinity, ...], [1, 1, 1, ..., 1, 1, 2, 2, ...])\n " def abridge_list(l): '\n String rep for list ``l`` if ``l`` is short enough;\n otherwise print the first few terms and the last few\n terms, with an ellipsis in between.\n ' if (len(l) < 8): l_str = str(l) else: l_str = ((str(l[:3]).rstrip(']') + ', ..., ') + str(l[(- 2):]).lstrip('[')) return l_str from sage.rings.infinity import Infinity profile = self._profile trunc = self._truncation_type p = self.prime() genprefix = ('generic ' if ((p == 2) and self._generic) else '') if self._has_nontrivial_profile(): if (not self._generic): pro_str = abridge_list(list(profile)) if (trunc != 0): pro_str = (((pro_str.rstrip(']') + ', ') + str(([Infinity] * 3)).strip('[]')) + ', ...]') else: e_str = abridge_list(list(profile[0])) k_str = abridge_list(list(profile[1])) if (trunc != 0): e_str = (((e_str.rstrip(']') + ', ') + str(([Infinity] * 3)).strip('[]')) + ', ...]') k_str = (((k_str.rstrip(']') + ', ') + str(([2] * 2)).strip('[]')) + ', ...]') pro_str = ('(%s, %s)' % (e_str, k_str)) return ('sub-Hopf algebra of %smod %d Steenrod algebra, %s basis, profile function %s' % (genprefix, self.prime(), self._basis_name, pro_str)) return ('%smod %d Steenrod algebra, %s basis' % (genprefix, self.prime(), self._basis_name)) def _latex_(self): "\n LaTeX representation of the Steenrod algebra.\n\n EXAMPLES::\n\n sage: C = SteenrodAlgebra(3)\n sage: C\n mod 3 Steenrod algebra, milnor basis\n sage: C._latex_()\n '\\\\mathcal{A}_{3}'\n " return ('\\mathcal{A}_{%s}' % self.prime()) def _repr_term(self, t): "\n String representation of the monomial specified by the tuple ``t``.\n\n INPUT:\n\n - ``t`` - tuple, representing basis element in the current basis.\n\n OUTPUT: string\n\n This is tested in many places: any place elements are printed\n is essentially a doctest for this method. Also, each basis\n has its own method for printing monomials, and those are\n doctested individually. We give a few doctests here, in\n addition.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra()._repr_term((3,2))\n 'Sq(3,2)'\n sage: SteenrodAlgebra(p=7)._repr_term(((0,2), (3,2)))\n 'Q_0 Q_2 P(3,2)'\n sage: SteenrodAlgebra(basis='adem')._repr_term((14,2))\n 'Sq^14 Sq^2'\n sage: SteenrodAlgebra(basis='adem', p=3)._repr_term((1,3,0))\n 'beta P^3'\n sage: SteenrodAlgebra(basis='pst')._repr_term(((0,2), (1,3)))\n 'P^0_2 P^1_3'\n sage: SteenrodAlgebra(basis='arnon_a')._repr_term(((0,2), (1,3)))\n 'X^0_2 X^1_3'\n\n sage: A7 = SteenrodAlgebra(7)\n sage: x = A7.Q(0,3) * A7.P(2,2)\n sage: x._repr_()\n 'Q_0 Q_3 P(2,2)'\n sage: x\n Q_0 Q_3 P(2,2)\n sage: a = SteenrodAlgebra().Sq(0,0,2)\n sage: a\n Sq(0,0,2)\n sage: A2_adem = SteenrodAlgebra(2,'admissible')\n sage: A2_adem(a)\n Sq^8 Sq^4 Sq^2 + Sq^9 Sq^4 Sq^1 + Sq^10 Sq^3 Sq^1 +\n Sq^10 Sq^4 + Sq^11 Sq^2 Sq^1 + Sq^12 Sq^2 + Sq^13 Sq^1\n + Sq^14\n sage: SteenrodAlgebra(2, 'woodz')(a)\n Sq^6 Sq^7 Sq^1 + Sq^14 + Sq^4 Sq^7 Sq^3 + Sq^4 Sq^7\n Sq^2 Sq^1 + Sq^12 Sq^2 + Sq^8 Sq^6 + Sq^8 Sq^4 Sq^2\n sage: SteenrodAlgebra(2, 'arnonc')(a)\n Sq^4 Sq^2 Sq^8 + Sq^4 Sq^4 Sq^6 + Sq^4 Sq^6 Sq^4 +\n Sq^6 Sq^8 + Sq^8 Sq^4 Sq^2 + Sq^8 Sq^6\n sage: SteenrodAlgebra(2, 'pst_llex')(a)\n P^1_3\n sage: SteenrodAlgebra(2, 'comm_revz')(a)\n c_0,1 c_1,1 c_0,3 c_2,1 + c_0,2 c_0,3 c_2,1 + c_1,3\n sage: SteenrodAlgebra(2, generic=True, basis='pst').P(0,0,2)\n P^1_3\n " from .steenrod_algebra_misc import milnor_mono_to_string, serre_cartan_mono_to_string, wood_mono_to_string, wall_mono_to_string, wall_long_mono_to_string, arnonA_mono_to_string, arnonA_long_mono_to_string, pst_mono_to_string, comm_long_mono_to_string, comm_mono_to_string p = self.prime() basis = self.basis_name() if (basis == 'milnor'): s = milnor_mono_to_string(t, generic=self._generic) elif (basis == 'serre-cartan'): s = serre_cartan_mono_to_string(t, generic=self._generic) elif (basis.find('wood') >= 0): s = wood_mono_to_string(t) elif (basis == 'wall'): s = wall_mono_to_string(t) elif (basis == 'wall_long'): s = wall_long_mono_to_string(t) elif (basis == 'arnona'): s = arnonA_mono_to_string(t) elif (basis == 'arnona_long'): s = arnonA_long_mono_to_string(t) elif (basis == 'arnonc'): s = serre_cartan_mono_to_string(t, generic=self._generic) elif (basis.find('pst') >= 0): s = pst_mono_to_string(t, generic=self._generic) elif ((basis.find('comm') >= 0) and (basis.find('long') >= 0)): s = comm_long_mono_to_string(t, p, generic=self._generic) elif (basis.find('comm') >= 0): s = comm_mono_to_string(t, generic=self._generic) s = s.replace('{', '').replace('}', '') return s def _latex_term(self, t): "\n LaTeX representation of the monomial specified by the tuple ``t``.\n\n INPUT:\n\n - ``t`` - tuple, representing basis element in the current basis.\n\n OUTPUT: string\n\n The string depends on the basis over which the element is defined.\n\n EXAMPLES::\n\n sage: A7 = SteenrodAlgebra(7)\n sage: A7._latex_term(((0, 3), (2,2)))\n 'Q_{0} Q_{3} \\\\mathcal{P}(2,2)'\n sage: x = A7.Q(0,3) * A7.P(2,2)\n sage: x._latex_() # indirect doctest\n 'Q_{0} Q_{3} \\\\mathcal{P}(2,2)'\n sage: latex(x)\n Q_{0} Q_{3} \\mathcal{P}(2,2)\n sage: b = Sq(0,2)\n sage: b.change_basis('adem')._latex_()\n '\\\\text{Sq}^{4} \\\\text{Sq}^{2} + \\\\text{Sq}^{5} \\\\text{Sq}^{1} +\n \\\\text{Sq}^{6}'\n sage: b.change_basis('woody')._latex_()\n '\\\\text{Sq}^{2} \\\\text{Sq}^{3} \\\\text{Sq}^{1} + \\\\text{Sq}^{6} +\n \\\\text{Sq}^{4} \\\\text{Sq}^{2}'\n sage: SteenrodAlgebra(2, 'arnona')(b)._latex_()\n 'X^{1}_{1} X^{2}_{2} + X^{2}_{1}'\n sage: SteenrodAlgebra(p=3, basis='serre-cartan').Q(0)._latex_()\n '\\\\beta'\n sage: latex(Sq(2).change_basis('adem').coproduct())\n 1 \\otimes \\text{Sq}^{2} + \\text{Sq}^{1} \\otimes \\text{Sq}^{1} + \\text{Sq}^{2} \\otimes 1\n sage: latex(SteenrodAlgebra(basis='pst').P(0,0,2))\n P^{1}_{3}\n " import re s = self._repr_term(t) s = re.sub('\\^([0-9]*)', '^{\\1}', s) s = re.sub('_([0-9,]*)', '_{\\1}', s) s = s.replace('Sq', '\\text{Sq}') if (not (self.basis_name().find('pst') >= 0)): s = s.replace('P', '\\mathcal{P}') s = s.replace('beta', '\\beta') return s def profile(self, i, component=0): '\n Profile function for this algebra.\n\n INPUT:\n\n - `i` - integer\n - ``component`` - either 0 or 1, optional (default 0)\n\n OUTPUT: integer or `\\infty`\n\n See the documentation for\n :mod:`sage.algebras.steenrod.steenrod_algebra` and\n :func:`SteenrodAlgebra` for information on profile functions.\n\n This applies the profile function to the integer `i`. Thus\n when `p=2`, `i` must be a positive integer. When `p` is odd,\n there are two profile functions, `e` and `k` (in the notation\n of the aforementioned documentation), corresponding,\n respectively to ``component=0`` and ``component=1``. So when\n `p` is odd and ``component`` is 0, `i` must be positive, while\n when ``component`` is 1, `i` must be non-negative.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra().profile(3)\n +Infinity\n sage: SteenrodAlgebra(profile=[3,2,1]).profile(1)\n 3\n sage: SteenrodAlgebra(profile=[3,2,1]).profile(2)\n 2\n\n When the profile is specified by a list, the default behavior\n is to return zero values outside the range of the list. This\n can be overridden if the algebra is created with an infinite\n ``truncation_type``::\n\n sage: SteenrodAlgebra(profile=[3,2,1]).profile(9)\n 0\n sage: SteenrodAlgebra(profile=[3,2,1], truncation_type=Infinity).profile(9)\n +Infinity\n\n sage: B = SteenrodAlgebra(p=3, profile=(lambda n: n, lambda n: 1))\n sage: B.profile(3)\n 3\n sage: B.profile(3, component=1)\n 1\n\n sage: EA = SteenrodAlgebra(generic=True, profile=(lambda n: n, lambda n: 1))\n sage: EA.profile(4)\n 4\n sage: EA.profile(2, component=1)\n 1\n ' if (not self._generic): t = self._profile elif (component == 0): t = self._profile[0] else: t = self._profile[1] if ((not self._generic) or (component == 0)): if (i <= 0): return 0 try: return t[(i - 1)] except IndexError: return self._truncation_type else: if (i < 0): return 1 try: return t[i] except IndexError: if (self._truncation_type > 0): return 2 else: return 1 def homogeneous_component(self, n): "\n Return the nth homogeneous piece of the Steenrod algebra.\n\n INPUT:\n\n - `n` - integer\n\n OUTPUT:\n\n a vector space spanned by the basis for this algebra in dimension `n`\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra()\n sage: A.homogeneous_component(4)\n Vector space spanned by (Sq(1,1), Sq(4)) over Finite Field of size 2\n sage: SteenrodAlgebra(profile=[2,1,0]).homogeneous_component(4)\n Vector space spanned by (Sq(1,1),) over Finite Field of size 2\n\n The notation A[n] may also be used::\n\n sage: A[5]\n Vector space spanned by (Sq(2,1), Sq(5)) over Finite Field of size 2\n sage: SteenrodAlgebra(basis='wall')[4]\n Vector space spanned by (Q^1_0 Q^0_0, Q^2_2) over Finite Field of size 2\n sage: SteenrodAlgebra(p=5)[17]\n Vector space spanned by (Q_1 P(1), Q_0 P(2)) over Finite Field of size 5\n\n Note that A[n] is just a vector space, not a Hopf algebra, so\n its elements don't have products, coproducts, or antipodes\n defined on them. If you want to use operations like this on\n elements of some A[n], then convert them back to elements of A::\n\n sage: sorted(A[5].basis())\n [milnor[(2, 1)], milnor[(5,)]]\n sage: a = list(A[5].basis())[1]\n sage: a # not in A, doesn't print like an element of A\n milnor[(5,)]\n sage: A(a) # in A\n Sq(5)\n sage: A(a) * A(a)\n Sq(7,1)\n sage: a * A(a) # only need to convert one factor\n Sq(7,1)\n sage: a.antipode() # not defined\n Traceback (most recent call last):\n ...\n AttributeError: 'CombinatorialFreeModule_with_category.element_class' object has no attribute 'antipode'...\n sage: A(a).antipode() # convert to elt of A, then compute antipode\n Sq(2,1) + Sq(5)\n\n sage: G = SteenrodAlgebra(p=5, profile=[[2,1], [2,2,2]], basis='pst')\n\n TESTS:\n\n The following sort of thing is also tested by the function\n :func:`steenrod_basis_error_check\n <sage.algebras.steenrod.steenrod_algebra_bases.steenrod_basis_error_check>`::\n\n sage: H = SteenrodAlgebra(p=5, profile=[[2,1], [2,2,2]])\n sage: G = SteenrodAlgebra(p=5, profile=[[2,1], [2,2,2]], basis='pst')\n sage: max([H[n].dimension() - G[n].dimension() for n in range(100)])\n 0\n " from sage.rings.finite_rings.finite_field_constructor import GF basis = self._basis_fcn(n) M = CombinatorialFreeModule(GF(self.prime()), basis, element_class=self.Element, prefix=self._basis_name) M._name = ('Vector space spanned by %s' % (tuple((self.monomial(a) for a in basis)),)) return M __getitem__ = homogeneous_component def one_basis(self): '\n The index of the element 1 in the basis for the Steenrod algebra.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(p=2).one_basis()\n ()\n sage: SteenrodAlgebra(p=7).one_basis()\n ((), ())\n ' basis = self.basis_name() if ((basis == 'serre-cartan') or (basis == 'arnonc')): return (0,) if (not self._generic): return () return ((), ()) def product_on_basis(self, t1, t2): "\n The product of two basis elements of this algebra\n\n INPUT:\n\n - ``t1``, ``t2`` -- tuples, the indices of two basis elements of self\n\n OUTPUT:\n\n the product of the two corresponding basis elements,\n as an element of self\n\n ALGORITHM: If the two elements are represented in the Milnor\n basis, use Milnor multiplication as implemented in\n :mod:`sage.algebras.steenrod.steenrod_algebra_mult`. If the two\n elements are represented in the Serre-Cartan basis, then\n multiply them using Adem relations (also implemented in\n :mod:`sage.algebras.steenrod.steenrod_algebra_mult`). This\n provides a good way of checking work -- multiply Milnor\n elements, then convert them to Adem elements and multiply\n those, and see if the answers correspond.\n\n If the two elements are represented in some other basis, then\n convert them both to the Milnor basis and multiply.\n\n EXAMPLES::\n\n sage: Milnor = SteenrodAlgebra()\n sage: Milnor.product_on_basis((2,), (2,))\n Sq(1,1)\n sage: Adem = SteenrodAlgebra(basis='adem')\n sage: Adem.Sq(2) * Adem.Sq(2) # indirect doctest\n Sq^3 Sq^1\n\n When multiplying elements from different bases, the left-hand\n factor determines the form of the output::\n\n sage: Adem.Sq(2) * Milnor.Sq(2)\n Sq^3 Sq^1\n sage: Milnor.Sq(2) * Adem.Sq(2)\n Sq(1,1)\n\n TESTS::\n\n sage: all(Adem(Milnor.Sq(n) ** 3)._repr_() == (Adem.Sq(n) ** 3)._repr_() for n in range(10))\n True\n sage: Wall = SteenrodAlgebra(basis='wall')\n sage: Wall(Adem.Sq(4,4) * Milnor.Sq(4)) == Adem(Wall.Sq(4,4) * Milnor.Sq(4))\n True\n\n sage: A3 = SteenrodAlgebra(p=3, basis='adem')\n sage: M3 = SteenrodAlgebra(p=3, basis='milnor')\n sage: all(A3(M3.P(n) * M3.Q(0) * M3.P(n))._repr_() == (A3.P(n) * A3.Q(0) * A3.P(n))._repr_() for n in range(5))\n True\n\n sage: EA = SteenrodAlgebra(generic=True)\n sage: EA.product_on_basis(((1, 3), (2, 1)), ((2, ), (0, 0, 1)))\n Q_1 Q_2 Q_3 P(2,1,1)\n\n sage: EA2 = SteenrodAlgebra(basis='serre-cartan', generic=True)\n sage: EA2.product_on_basis((1, 2, 0, 1, 0), (1, 2, 0, 1, 0))\n beta P^4 P^2 beta + beta P^5 beta P^1\n " p = self.prime() basis = self.basis_name() if (basis == 'milnor'): if (not self._generic): from .steenrod_algebra_mult import milnor_multiplication d = milnor_multiplication(t1, t2) else: from .steenrod_algebra_mult import milnor_multiplication_odd d = milnor_multiplication_odd(t1, t2, p) return self._from_dict(d, coerce=True) elif (basis == 'serre-cartan'): from .steenrod_algebra_mult import make_mono_admissible if self._generic: if ((len(t1) % 2) == 0): t1 = (t1 + (0,)) if ((len(t2) % 2) == 0): t2 = (t2 + (0,)) if ((t1[(- 1)] + t2[0]) == 2): return self.zero() mono = ((t1[:(- 1)] + ((t1[(- 1)] + t2[0]),)) + t2[1:]) d = make_mono_admissible(mono, p, generic=self._generic) else: mono = (t1 + t2) while ((len(mono) > 1) and (mono[(- 1)] == 0)): mono = mono[:(- 1)] d = make_mono_admissible(mono, generic=self._generic) return self._from_dict(d, coerce=True) else: x = self({t1: 1}) y = self({t2: 1}) A = SteenrodAlgebra(basis='milnor', p=p, generic=self._generic) return self((A(x) * A(y))) def coproduct_on_basis(self, t, algorithm=None): "\n The coproduct of a basis element of this algebra\n\n INPUT:\n\n - ``t`` -- tuple, the index of a basis element of self\n\n - ``algorithm`` -- ``None`` or a string, either 'milnor' or\n 'serre-cartan' (or anything which will be converted to one\n of these by the function :func:`get_basis_name\n <sage.algebras.steenrod.steenrod_algebra_misc.get_basis_name>`.\n If ``None``, default to 'milnor' unless current basis is\n 'serre-cartan', in which case use 'serre-cartan'.\n\n ALGORITHM: The coproduct on a Milnor basis element `P(n_1,\n n_2, ...)` is `\\sum P(i_1, i_2, ...) \\otimes P(j_1, j_2,\n ...)`, summed over all `i_k + j_k = n_k` for each `k`. At odd\n primes, each element `Q_n` is primitive: its coproduct is `Q_n\n \\otimes 1 + 1 \\otimes Q_n`.\n\n One can deduce a coproduct formula for the Serre-Cartan basis\n from this: the coproduct on each `P^n` is `\\sum P^i \\otimes\n P^{n-i}` and at odd primes `\\beta` is primitive. Since the\n coproduct is an algebra map, one can then compute the\n coproduct on any Serre-Cartan basis element.\n\n Which of these methods is used is controlled by whether\n ``algorithm`` is 'milnor' or 'serre-cartan'.\n\n OUTPUT:\n\n the coproduct of the corresponding basis element,\n as an element of ``self`` tensor ``self``.\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra()\n sage: A.coproduct_on_basis((3,))\n 1 # Sq(3) + Sq(1) # Sq(2) + Sq(2) # Sq(1) + Sq(3) # 1\n\n TESTS::\n\n sage: all(A.coproduct_on_basis((n,1), algorithm='milnor') == A.coproduct_on_basis((n,1), algorithm='adem') for n in range(9)) # long time\n True\n sage: A7 = SteenrodAlgebra(p=7, basis='adem')\n sage: all(A7.coproduct_on_basis((0,n,1), algorithm='milnor') == A7.coproduct_on_basis((0,n,1), algorithm='adem') for n in range(9)) # long time\n True\n " def coprod_list(t): '\n if t = (n0, n1, ...), then return list of terms (i0, i1,\n ...) where ik <= nk for each k. From each such term, can\n recover the second factor in the coproduct.\n ' if (len(t) == 0): return [()] if (len(t) == 1): return [[a] for a in range((t[0] + 1))] ans = [] for i in range((t[0] + 1)): ans.extend([([i] + x) for x in coprod_list(t[1:])]) return ans from .steenrod_algebra_misc import get_basis_name p = self.prime() basis = self.basis_name() if (algorithm is None): if (basis == 'serre-cartan'): algorithm = 'serre-cartan' else: algorithm = 'milnor' else: algorithm = get_basis_name(algorithm, p, generic=self._generic) if (basis == algorithm): if (basis == 'milnor'): if (not self._generic): left = coprod_list(t) right = [[(x - y) for (x, y) in zip(t, m)] for m in left] old = list(left) left = [] for a in old: while (a and (a[(- 1)] == 0)): a = a[:(- 1)] left.append(tuple(a)) old = list(right) right = [] for a in old: while (a and (a[(- 1)] == 0)): a = a[:(- 1)] right.append(tuple(a)) tens = dict.fromkeys(zip(left, right), 1) return self.tensor_square()._from_dict(tens, coerce=True) else: from sage.combinat.permutation import Permutation from .steenrod_algebra_misc import convert_perm from sage.sets.set import Set left_p = coprod_list(t[1]) right_p = [[(x - y) for (x, y) in zip(t[1], m)] for m in left_p] old = list(left_p) left_p = [] for a in old: while (a and (a[(- 1)] == 0)): a = a[:(- 1)] left_p.append(tuple(a)) old = list(right_p) right_p = [] for a in old: while (a and (a[(- 1)] == 0)): a = a[:(- 1)] right_p.append(tuple(a)) all_q = Set(t[0]) tens_q = {} for a in all_q.subsets(): left_q = sorted(a) right_q = sorted((all_q - a)) sign = Permutation(convert_perm((left_q + right_q))).signature() tens_q[(tuple(left_q), tuple(right_q))] = sign tens = {} for (l, r) in zip(left_p, right_p): for q in tens_q: tens[((q[0], l), (q[1], r))] = tens_q[q] return self.tensor_square()._from_dict(tens, coerce=True) elif (basis == 'serre-cartan'): result = self.tensor_square().one() if (not self._generic): for n in t: s = self.tensor_square().zero() for i in range((n + 1)): s += tensor((self.Sq(i), self.Sq((n - i)))) result = (result * s) return result else: bockstein = True for n in t: if bockstein: if (n != 0): s = (tensor((self.Q(0), self.one())) + tensor((self.one(), self.Q(0)))) else: s = self.tensor_square().one() bockstein = False else: s = self.tensor_square().zero() for i in range((n + 1)): s += tensor((self.P(i), self.P((n - i)))) bockstein = True result = (result * s) return result else: A = SteenrodAlgebra(p=p, basis=algorithm, generic=self._generic) x = A(self._change_basis_on_basis(t, algorithm)).coproduct(algorithm=algorithm) result = [] for ((a, b), coeff) in x: result.append((tensor((A._change_basis_on_basis(a, basis), A._change_basis_on_basis(b, basis))), coeff)) return self.tensor_square().linear_combination(result) def coproduct(self, x, algorithm='milnor'): "\n Return the coproduct of an element ``x`` of this algebra.\n\n INPUT:\n\n - ``x`` -- element of ``self``\n\n - ``algorithm`` -- ``None`` or a string, either ``'milnor'`` or\n ``'serre-cartan'`` (or anything which will be converted to one\n of these by the function :func:`get_basis_name\n <sage.algebras.steenrod.steenrod_algebra_misc.get_basis_name>`.\n If ``None``, default to ``'serre-cartan'`` if current basis is\n ``'serre-cartan'``; otherwise use ``'milnor'``.\n\n This calls :meth:`coproduct_on_basis` on the summands of ``x``\n and extends linearly.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra().Sq(3).coproduct()\n 1 # Sq(3) + Sq(1) # Sq(2) + Sq(2) # Sq(1) + Sq(3) # 1\n\n The element `\\text{Sq}(0,1)` is primitive::\n\n sage: SteenrodAlgebra(basis='adem').Sq(0,1).coproduct()\n 1 # Sq^2 Sq^1 + 1 # Sq^3 + Sq^2 Sq^1 # 1 + Sq^3 # 1\n sage: SteenrodAlgebra(basis='pst').Sq(0,1).coproduct()\n 1 # P^0_2 + P^0_2 # 1\n\n sage: SteenrodAlgebra(p=3).P(4).coproduct()\n 1 # P(4) + P(1) # P(3) + P(2) # P(2) + P(3) # P(1) + P(4) # 1\n sage: SteenrodAlgebra(p=3).P(4).coproduct(algorithm='serre-cartan')\n 1 # P(4) + P(1) # P(3) + P(2) # P(2) + P(3) # P(1) + P(4) # 1\n sage: SteenrodAlgebra(p=3, basis='serre-cartan').P(4).coproduct()\n 1 # P^4 + P^1 # P^3 + P^2 # P^2 + P^3 # P^1 + P^4 # 1\n sage: SteenrodAlgebra(p=11, profile=((), (2,1,2))).Q(0,2).coproduct()\n 1 # Q_0 Q_2 + Q_0 # Q_2 + Q_0 Q_2 # 1 + 10*Q_2 # Q_0\n " def coprod(x): return self.coproduct_on_basis(x, algorithm) return Hom(self, tensor([self, self]), ModulesWithBasis(self.base_ring()))(on_basis=coprod)(x) def antipode_on_basis(self, t): "\n The antipode of a basis element of this algebra\n\n INPUT:\n\n - ``t`` -- tuple, the index of a basis element of ``self``\n\n OUTPUT:\n\n the antipode of the corresponding basis element,\n as an element of ``self``.\n\n ALGORITHM: according to a result of Milnor's, the antipode of\n `\\text{Sq}(n)` is the sum of all of the Milnor basis elements\n in dimension `n`. So: convert the element to the Serre-Cartan\n basis, thus writing it as a sum of products of elements\n `\\text{Sq}(n)`, and use Milnor's formula for the antipode of\n `\\text{Sq}(n)`, together with the fact that the antipode is an\n antihomomorphism: if we call the antipode `c`, then `c(ab) =\n c(b) c(a)`.\n\n At odd primes, a similar method is used: the antipode of\n `P(n)` is the sum of the Milnor P basis elements in dimension\n `n*2(p-1)`, multiplied by `(-1)^n`, and the antipode of `\\beta\n = Q_0` is `-Q_0`. So convert to the Serre-Cartan basis, as in\n the `p = 2` case. Note that in the odd prime case, there is a\n sign in the antihomomorphism formula:\n `c(ab) = (-1)^{\\deg a \\deg b} c(b) c(a)`.\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra()\n sage: A.antipode_on_basis((4,))\n Sq(1,1) + Sq(4)\n sage: A.Sq(4).antipode()\n Sq(1,1) + Sq(4)\n sage: Adem = SteenrodAlgebra(basis='adem')\n sage: Adem.Sq(4).antipode()\n Sq^3 Sq^1 + Sq^4\n sage: SteenrodAlgebra(basis='pst').Sq(3).antipode()\n P^0_1 P^1_1 + P^0_2\n sage: a = SteenrodAlgebra(basis='wall_long').Sq(10)\n sage: a.antipode()\n Sq^1 Sq^2 Sq^4 Sq^1 Sq^2 + Sq^2 Sq^4 Sq^1 Sq^2 Sq^1 + Sq^8 Sq^2\n sage: a.antipode().antipode() == a\n True\n\n sage: SteenrodAlgebra(p=3).P(6).antipode()\n P(2,1) + P(6)\n sage: SteenrodAlgebra(p=3).P(6).antipode().antipode()\n P(6)\n\n TESTS::\n\n sage: Milnor = SteenrodAlgebra()\n sage: all(x.antipode().antipode() == x for x in Milnor.basis(11)) # long time\n True\n sage: A5 = SteenrodAlgebra(p=5, basis='adem')\n sage: all(x.antipode().antipode() == x for x in A5.basis(25))\n True\n sage: H = SteenrodAlgebra(profile=[2,2,1])\n sage: H.Sq(1,2).antipode() in H\n True\n\n sage: Q = A5.Q\n sage: (Q(0) * Q(1)).antipode() == - Q(1).antipode() * Q(0).antipode()\n True\n " p = self.prime() if (self.basis_name() == 'serre-cartan'): antipode = self.one() if (not self._generic): for n in t: antipode = (self(sum(SteenrodAlgebra().basis(n))) * antipode) else: from sage.misc.functional import is_even for (index, n) in enumerate(t): if is_even(index): if (n != 0): antipode = (((- self.Q(0)) * antipode) * ((- 1) ** antipode.degree())) else: B = SteenrodAlgebra(p=p, generic=self._generic).basis(((n * 2) * (p - 1))) s = self(0) for b in B: if (len(b.leading_support()[0]) == 0): s += self(b) antipode = ((((- 1) ** n) * s) * antipode) return antipode return self(self._change_basis_on_basis(t, 'serre-cartan').antipode()) def counit_on_basis(self, t): '\n The counit sends all elements of positive degree to zero.\n\n INPUT:\n\n - ``t`` -- tuple, the index of a basis element of ``self``\n\n EXAMPLES::\n\n sage: A2 = SteenrodAlgebra(p=2)\n sage: A2.counit_on_basis(())\n 1\n sage: A2.counit_on_basis((0,0,1))\n 0\n sage: parent(A2.counit_on_basis((0,0,1)))\n Finite Field of size 2\n sage: A3 = SteenrodAlgebra(p=3)\n sage: A3.counit_on_basis(((1,2,3), (1,1,1)))\n 0\n sage: A3.counit_on_basis(((), ()))\n 1\n sage: A3.counit(A3.P(10,5))\n 0\n sage: A3.counit(A3.P(0))\n 1\n ' if ((t != ()) and (t != ((), ()))): return self.base_ring().zero() else: return self.base_ring().one() def _milnor_on_basis(self, t): "\n Convert the tuple ``t`` in the current basis to an element in the\n Milnor basis.\n\n INPUT:\n\n - ``t`` - tuple, representing basis element in the current basis.\n\n OUTPUT: element of the Steenrod algebra with the Milnor basis\n\n ALGORITHM: there is a simple conversion from each basis to the\n Milnor basis, so use that. In more detail:\n\n - If the current basis is the Milnor basis, just return the\n corresponding element.\n\n - If the current basis is the Serre-Cartan basis: when `p=2`,\n the element `\\text{Sq}^a` equals the Milnor element\n `\\text{Sq}(a)`; when `p` is odd, `\\mathcal{P}^a =\n \\mathcal{P}(a)` and `\\beta = Q_0`. Hence for any\n Serre-Cartan basis element, represent it in the\n Milnor basis by computing an appropriate product using\n Milnor multiplication.\n\n - The same goes for Arnon's C basis, since the elements are\n monomials in the Steenrod squares.\n\n - If the current basis is Wood's Y or Z bases, then each basis\n element is a monomial in the classes `w(m,k) =\n \\text{Sq}^{2^m (2^{k+1}-1)}`. So again, multiply the\n corresponding Milnor elements together.\n\n - The Wall basis: each basis element is a monomial in the\n elements `Q^m_k = Sq(2^k) Sq(2^{k+1}) ... Sq(2^m)`.\n\n - Arnon's A basis: each basis element is a monomial in the\n elements `X^m_k = Sq(2^m) ... Sq(2^{k+1}) Sq(2^k)`.\n\n - The `P^s_t` bases: when `p=2`, each basis element is a\n monomial in the elements `P^s_t`. When `p` is odd, each\n basis element is a product of elements `Q_i` and a monomial\n in the elements `(P^s_t)^n` where `0 < n < p`.\n\n - The commutator bases: when `p=2`, each basis element is a\n monomial in the iterated commutators `c_{i,j}`, defined by\n `c_{i,1} = \\text{Sq}(2^i)` and `c_{i,j} = [c_{i,j-1},\n \\text{Sq}(2^{i+j-1})]`. When `p` is odd, each basis element\n is a product of elements `Q_i` and a monomial in the\n elements `c_{i,j}^n` where `0 < n < p`, `c_{i,1} =\n P(p^i)` and `c_{i,j} = [P(p^{i+j-1}), c_{i,j-1}]`.\n\n EXAMPLES::\n\n sage: Adem = SteenrodAlgebra(basis='serre-cartan')\n sage: Adem._milnor_on_basis((2,1)) # Sq^2 Sq^1\n Sq(0,1) + Sq(3)\n sage: Pst = SteenrodAlgebra(basis='pst')\n sage: Pst._milnor_on_basis(((0,1), (1,1), (2,1)))\n Sq(7)\n " basis = self.basis_name() p = self.prime() A = SteenrodAlgebra(p=p, generic=self._generic) if (basis == 'milnor'): return A({t: 1}) ans = A(1) if ((not self._generic) and ((basis == 'serre-cartan') or (basis == 'arnonc'))): for j in t: ans = (ans * A.Sq(j)) elif (self._generic and (basis == 'serre-cartan')): bockstein = True for j in t: if bockstein: if (j != 0): ans = (ans * A.Q(0)) bockstein = False else: ans = (ans * A.P(j)) bockstein = True elif ((basis == 'woody') or (basis == 'woodz')): for (m, k) in t: ans = (ans * A.Sq(((2 ** m) * ((2 ** (k + 1)) - 1)))) elif (basis.find('wall') >= 0): for (m, k) in t: exponent = (2 ** k) ans = (ans * A.Sq(exponent)) for i in range((m - k)): exponent = (exponent * 2) ans = (ans * A.Sq(exponent)) elif (basis.find('pst') >= 0): if (not self._generic): for (i, j) in t: ans = (ans * A.pst(i, j)) else: if t[0]: ans = (ans * A.Q(*t[0])) for ((i, j), n) in t[1]: ans = (ans * (A.pst(i, j) ** n)) elif (basis.find('arnona') >= 0): for (m, k) in t: exponent = (2 ** k) X = A.Sq(exponent) for i in range((m - k)): exponent = (exponent * 2) X = (A.Sq(exponent) * X) ans = (ans * X) elif (basis.find('comm') >= 0): if (not self._generic): for (i, j) in t: comm = A.Sq((2 ** i)) for k in range(2, (j + 1)): y = A.Sq((2 ** ((i + k) - 1))) comm = ((comm * y) + (y * comm)) ans = (ans * comm) else: if t[0]: ans = (ans * A.Q(*t[0])) for ((i, j), n) in t[1]: comm = A.P((p ** i)) for k in range(2, (j + 1)): y = A.P((p ** ((i + k) - 1))) comm = ((y * comm) - (comm * y)) ans = (ans * (comm ** n)) return ans @lazy_attribute def milnor(self): "\n Convert an element of this algebra to the Milnor basis\n\n INPUT:\n\n - x -- an element of this algebra\n\n OUTPUT: x converted to the Milnor basis\n\n ALGORITHM: use the method ``_milnor_on_basis`` and linearity.\n\n EXAMPLES::\n\n sage: Adem = SteenrodAlgebra(basis='adem')\n sage: a = Adem.Sq(2) * Adem.Sq(1)\n sage: Adem.milnor(a)\n Sq(0,1) + Sq(3)\n " A = SteenrodAlgebra(p=self.prime(), basis='milnor', generic=self._generic) return self._module_morphism(self._milnor_on_basis, codomain=A) def _change_basis_on_basis(self, t, basis='milnor'): "\n Convert the tuple t to the named basis.\n\n INPUT:\n\n - ``t`` - tuple, representing basis element in the current basis.\n\n - ``basis`` - string, the basis to which to convert, optional\n (default 'milnor')\n\n OUTPUT: an element of the Steenrod algebra with basis ``basis``.\n\n ALGORITHM: it's straightforward to convert to the Milnor basis\n (using :meth:`milnor` or :meth:`_milnor_on_basis`), so it's\n straightforward to produce a matrix representing this\n conversion in any degree. The function\n :func:`convert_from_milnor_matrix\n <steenrod_algebra_bases.convert_from_milnor_matrix>` provides\n the inverse operation.\n\n So: convert from the current basis to the Milnor basis, then\n from the Milnor basis to the new basis.\n\n EXAMPLES::\n\n sage: Adem = SteenrodAlgebra(basis='adem')\n sage: a = Adem({(2,1): 1}); a\n Sq^2 Sq^1\n sage: a.change_basis('adem') # indirect doctest\n Sq^2 Sq^1\n sage: a.change_basis('milnor')\n Sq(0,1) + Sq(3)\n sage: a.change_basis('pst')\n P^0_1 P^1_1 + P^0_2\n sage: a.change_basis('milnor').change_basis('adem').change_basis('adem')\n Sq^2 Sq^1\n sage: a.change_basis('wall') == a.change_basis('woody')\n True\n\n TESTS::\n\n sage: a = sum(SteenrodAlgebra(basis='comm').basis(10))\n sage: a.change_basis('adem').change_basis('wall').change_basis('comm')._repr_() == a._repr_()\n True\n sage: a.change_basis('pst').change_basis('milnor').change_basis('comm')._repr_() == a._repr_()\n True\n sage: a.change_basis('woody').change_basis('arnona').change_basis('comm')._repr_() == a._repr_()\n True\n\n sage: b = sum(SteenrodAlgebra(p=3).basis(41))\n sage: b.change_basis('adem').change_basis('adem').change_basis('milnor')._repr_() == b._repr_()\n True\n\n sage: SteenrodAlgebra(generic=True).P(0,2).change_basis('serre-cartan')\n P^4 P^2 + P^5 P^1 + P^6\n " from sage.matrix.constructor import matrix from sage.rings.finite_rings.finite_field_constructor import GF from .steenrod_algebra_bases import steenrod_algebra_basis, convert_from_milnor_matrix from .steenrod_algebra_misc import get_basis_name basis = get_basis_name(basis, self.prime(), generic=self._generic) if (basis == self.basis_name()): return self({t: 1}) a = self._milnor_on_basis(t) if (basis == 'milnor'): return a d = a.monomial_coefficients() p = self.prime() deg = a.degree() A = SteenrodAlgebra(basis=basis, p=p, generic=self._generic) if (deg == 0): return A(a.leading_coefficient()) Bnew = steenrod_algebra_basis(deg, basis, p, generic=self._generic) Bmil = steenrod_algebra_basis(deg, 'milnor', p, generic=self._generic) v = [] for a in Bmil: v.append(d.get(a, 0)) out = (matrix(GF(p), 1, len(v), v) * convert_from_milnor_matrix(deg, basis, p, generic=self._generic)) new_d = dict(zip(Bnew, out[0])) return A(new_d) def _change_basis(self, x, basis='milnor'): "\n Convert an element of this algebra to the specified basis\n\n INPUT:\n\n - ``x`` - an element of this algebra.\n\n - ``basis`` - string, the basis to which to convert, optional\n (default 'milnor')\n\n OUTPUT: an element of the Steenrod algebra with basis ``basis``.\n\n ALGORITHM: use :meth:`_change_basis_on_basis` and linearity\n\n EXAMPLES::\n\n sage: Adem = SteenrodAlgebra(basis='adem')\n sage: a = Adem({(2,1): 1}); a\n Sq^2 Sq^1\n sage: a.change_basis('adem') # indirect doctest\n Sq^2 Sq^1\n sage: a.change_basis('milnor')\n Sq(0,1) + Sq(3)\n sage: a.change_basis('pst')\n P^0_1 P^1_1 + P^0_2\n " if (basis == 'milnor'): return x.milnor() A = SteenrodAlgebra(p=self.prime(), basis=basis, generic=self._generic) def change(y): return self._change_basis_on_basis(y, basis) f = self._module_morphism(change, codomain=A) return f(x) def degree_on_basis(self, t): "\n The degree of the monomial specified by the tuple ``t``.\n\n INPUT:\n\n - ``t`` - tuple, representing basis element in the current basis.\n\n OUTPUT: integer, the degree of the corresponding element.\n\n The degree of `\\text{Sq}(i_1,i_2,i_3,...)` is\n\n .. MATH::\n\n i_1 + 3i_2 + 7i_3 + ... + (2^k - 1) i_k + ....\n\n At an odd prime `p`, the degree of `Q_k` is `2p^k - 1` and the\n degree of `\\mathcal{P}(i_1, i_2, ...)` is\n\n .. MATH::\n\n \\sum_{k \\geq 0} 2(p^k - 1) i_k.\n\n ALGORITHM: Each basis element is represented in terms relevant\n to the particular basis: 'milnor' basis elements (at the prime\n 2) are given by tuples ``(a,b,c,...)`` corresponding to the\n element `\\text{Sq}(a,b,c,...)`, while 'pst' basis elements are\n given by tuples of pairs ``((a, b), (c, d), ...)``,\n corresponding to the product `P^a_b P^c_d ...`. The other\n bases have similar descriptions. The degree of each basis\n element is computed from this data, rather than converting the\n element to the Milnor basis, for example, and then computing\n the degree.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra().degree_on_basis((0,0,1))\n 7\n sage: Sq(7).degree()\n 7\n\n sage: A11 = SteenrodAlgebra(p=11)\n sage: A11.degree_on_basis(((), (1,1)))\n 260\n sage: A11.degree_on_basis(((2,), ()))\n 241\n " def p_degree(m, mult=1, prime=2): '\n For m=(n_1, n_2, n_3, ...), Sum_i (mult) * n_i * (p^i - 1)\n ' i = 0 deg = 0 for n in m: i += 1 deg += ((n * mult) * ((prime ** i) - 1)) return deg def q_degree(m, prime=3): '\n For m=(n_0, n_1, n_2, ...), Sum_i 2*p^(n_i) - 1\n ' deg = 0 for n in m: deg += ((2 * (prime ** n)) - 1) return deg p = self.prime() basis = self.basis_name() if (basis == 'milnor'): if (not self._generic): return p_degree(t) else: return (q_degree(t[0], prime=p) + p_degree(t[1], prime=p, mult=2)) if ((not self._generic) and ((basis == 'serre-cartan') or (basis == 'arnonc'))): return sum(t) if (self._generic and (basis == 'serre-cartan')): bockstein = True n = 0 for j in t: if bockstein: if (j != 0): n += 1 bockstein = False else: n += ((2 * j) * (p - 1)) bockstein = True return n if ((basis == 'woody') or (basis == 'woodz')): return sum((((2 ** m) * ((2 ** (k + 1)) - 1)) for (m, k) in t)) if ((basis.find('wall') >= 0) or (basis.find('arnona') >= 0)): return sum((((2 ** k) * ((2 ** ((m - k) + 1)) - 1)) for (m, k) in t)) if ((basis.find('pst') >= 0) or (basis.find('comm') >= 0)): if (not self._generic): return sum((((2 ** m) * ((2 ** k) - 1)) for (m, k) in t)) q_deg = q_degree(t[0], prime=p) p_deg = sum(((((2 * n) * (p ** s)) * ((p ** t) - 1)) for ((s, t), n) in t[1])) return (q_deg + p_deg) def _coerce_map_from_(self, S): '\n True if there is a coercion from ``S`` to ``self``, False otherwise.\n\n INPUT:\n\n - ``S`` - a Sage object.\n\n The algebras that coerce into the mod p Steenrod algebra are:\n\n - the mod p Steenrod algebra `A`\n - its sub-Hopf algebras\n - its homogeneous components\n - its base field `GF(p)`\n - `ZZ`\n\n Similarly, a sub-Hopf algebra `B` of `A` coerces into another\n sub-Hopf algebra `C` if and only if the profile function for\n `B` is less than or equal to that of `C`, pointwise.\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra()\n sage: A1 = SteenrodAlgebra(profile=[2,1])\n sage: A2 = SteenrodAlgebra(profile=[3,2,1])\n sage: B = SteenrodAlgebra(profile=[1,2,1])\n sage: A._coerce_map_from_(A1)\n True\n sage: A2._coerce_map_from_(A1)\n True\n sage: A1._coerce_map_from_(A)\n False\n sage: A1._coerce_map_from_(B)\n False\n sage: B._coerce_map_from_(A1)\n False\n\n sage: A._coerce_map_from_(A[12])\n True\n\n sage: EA = SteenrodAlgebra(generic=True)\n sage: A._coerce_map_from_(EA)\n False\n sage: EA._coerce_map_from_(A)\n False\n sage: EA._coerce_map_from_(EA)\n True\n\n sage: A3 = SteenrodAlgebra(p=3)\n sage: A31 = SteenrodAlgebra(p=3, profile=([1], [2, 2]))\n sage: B3 = SteenrodAlgebra(p=3, profile=([1, 2, 1], [1]))\n sage: A3._coerce_map_from_(A31)\n True\n sage: A31._coerce_map_from_(A3)\n False\n sage: A31._coerce_map_from_(B3)\n False\n sage: B3._coerce_map_from_(A31)\n False\n ' from sage.rings.integer_ring import ZZ from sage.rings.finite_rings.finite_field_constructor import GF from sage.rings.infinity import Infinity p = self.prime() if ((S == ZZ) or (S == GF(p))): return True if (isinstance(S, SteenrodAlgebra_generic) and (p == S.prime()) and (self._generic == S._generic)): if (not self._generic): self_prec = len(self._profile) S_prec = len(S._profile) return all(((self.profile(i) >= S.profile(i)) for i in range(1, (max(self_prec, S_prec) + 1)))) self_prec = len(self._profile[0]) S_prec = len(S._profile[0]) return (all(((self.profile(i) >= S.profile(i)) for i in range(1, (max(self_prec, S_prec) + 1)))) and all(((self.profile(i, 1) >= S.profile(i, 1)) for i in range(1, (max(self_prec, S_prec) + 1))))) if (isinstance(S, CombinatorialFreeModule) and (S.dimension() < Infinity) and (p == S.base_ring().characteristic())): from .steenrod_algebra_misc import get_basis_name try: get_basis_name(S.prefix(), S.base_ring().characteristic()) return True except ValueError: return False return False def _element_constructor_(self, x): '\n Try to turn ``x`` into an element of ``self``.\n\n INPUT:\n\n - ``x`` - an element of some Steenrod algebra or an element of\n `\\ZZ` or `\\GF{p}` or a dict\n\n OUTPUT: ``x`` as a member of ``self``.\n\n If ``x`` is a dict, then call :meth:`_from_dict` on it,\n coercing the coefficients into the base field. That is, treat\n it as having entries of the form ``tuple: coeff``, where\n ``tuple`` is a tuple representing a basis element and\n ``coeff`` is the coefficient of that element.\n\n EXAMPLES::\n\n sage: A1 = SteenrodAlgebra(profile=[2,1])\n sage: A1(Sq(2)) # indirect doctest\n Sq(2)\n sage: A1._element_constructor_(Sq(2))\n Sq(2)\n sage: A1(3) # map integer into A1\n 1\n sage: A1._element_constructor_(Sq(4)) # Sq(4) not in A1\n Traceback (most recent call last):\n ...\n ValueError: Element does not lie in this Steenrod algebra\n sage: A1({(2,): 1, (1,): 13})\n Sq(1) + Sq(2)\n ' from sage.rings.integer_ring import ZZ from sage.rings.finite_rings.finite_field_constructor import GF if ((x in GF(self.prime())) or (x in ZZ)): return self.from_base_ring_from_one_basis(x) if isinstance(x, dict): A = SteenrodAlgebra(p=self.prime(), basis=self.basis_name(), generic=self._generic) x = A._from_dict(x, coerce=True) if (x in self): if (x.basis_name() == self.basis_name()): if (x.parent() is self): return x return self._from_dict(x.monomial_coefficients(), coerce=True) else: a = x.milnor() if (self.basis_name() == 'milnor'): return a return a.change_basis(self.basis_name()) raise ValueError('Element does not lie in this Steenrod algebra') def __contains__(self, x): '\n True if self contains x.\n\n EXAMPLES::\n\n sage: Sq(3,1,1) in SteenrodAlgebra()\n True\n sage: Sq(3,1,1) in SteenrodAlgebra(p=5)\n False\n\n sage: A1 = SteenrodAlgebra(profile=[2,1])\n sage: Sq(3) in A1\n True\n sage: Sq(4) in A1\n False\n sage: Sq(0,2) in A1\n False\n\n sage: Sq(3) in SteenrodAlgebra(generic=True)\n False\n\n sage: A_3 = SteenrodAlgebra(p=3)\n sage: B_3 = SteenrodAlgebra(p=3, profile=([1], [2,2,1,1]))\n sage: A_3.P(2) in B_3\n True\n sage: A_3.P(3) in B_3\n False\n sage: A_3.Q(1) in B_3\n True\n sage: A_3.P(1) * A_3.Q(2) in B_3\n False\n ' from sage.rings.finite_rings.finite_field_constructor import GF p = self.prime() if (x in GF(p)): return True if (isinstance(x, self.Element) and (x.prime() == p)): try: if (x.parent()._generic != self._generic): return False except AttributeError: pass A = SteenrodAlgebra(p=p, basis=self.basis_name(), generic=self._generic) if self._has_nontrivial_profile(): return all((self._check_profile_on_basis(mono) for mono in A(x).support())) return True return False def basis(self, d=None): '\n Return basis for ``self``, either the whole basis or the basis in\n degree `d`.\n\n INPUT:\n\n - `d` -- integer or ``None``, optional (default ``None``)\n\n OUTPUT:\n\n If `d` is ``None``, then return a basis of the algebra.\n Otherwise, return the basis in degree `d`.\n\n EXAMPLES::\n\n sage: A3 = SteenrodAlgebra(3)\n sage: A3.basis(13)\n Family (Q_1 P(2), Q_0 P(3))\n sage: SteenrodAlgebra(2, \'adem\').basis(12)\n Family (Sq^12, Sq^11 Sq^1, Sq^9 Sq^2 Sq^1, Sq^8 Sq^3 Sq^1, Sq^10 Sq^2, Sq^9 Sq^3, Sq^8 Sq^4)\n\n sage: A = SteenrodAlgebra(profile=[1,2,1])\n sage: A.basis(2)\n Family ()\n sage: A.basis(3)\n Family (Sq(0,1),)\n sage: SteenrodAlgebra().basis(3)\n Family (Sq(0,1), Sq(3))\n sage: A_pst = SteenrodAlgebra(profile=[1,2,1], basis=\'pst\')\n sage: A_pst.basis(3)\n Family (P^0_2,)\n\n sage: A7 = SteenrodAlgebra(p=7)\n sage: B = SteenrodAlgebra(p=7, profile=([1,2,1], [1]))\n sage: A7.basis(84)\n Family (P(7),)\n sage: B.basis(84)\n Family ()\n sage: C = SteenrodAlgebra(p=7, profile=([1], [2,2]))\n sage: A7.Q(0,1) in C.basis(14)\n True\n sage: A7.Q(2) in A7.basis(97)\n True\n sage: A7.Q(2) in C.basis(97)\n False\n\n With no arguments, return the basis of the whole algebra.\n This does not print in a very helpful way, unfortunately::\n\n sage: A7.basis()\n Lazy family (Term map from basis key family of mod 7 Steenrod algebra, milnor basis\n to mod 7 Steenrod algebra, milnor basis(i))_{i in basis key family\n of mod 7 Steenrod algebra, milnor basis}\n sage: for (idx,a) in zip((1,..,9),A7.basis()):\n ....: print("{} {}".format(idx, a))\n 1 1\n 2 Q_0\n 3 P(1)\n 4 Q_1\n 5 Q_0 P(1)\n 6 Q_0 Q_1\n 7 P(2)\n 8 Q_1 P(1)\n 9 Q_0 P(2)\n sage: D = SteenrodAlgebra(p=3, profile=([1], [2,2]))\n sage: sorted(D.basis())\n [1, P(1), P(2), Q_0, Q_0 P(1), Q_0 P(2), Q_0 Q_1,\n Q_0 Q_1 P(1), Q_0 Q_1 P(2), Q_1, Q_1 P(1), Q_1 P(2)]\n ' from sage.sets.family import Family if (d is None): return Family(self._indices, self.monomial) else: return Family([self.monomial(tuple(a)) for a in self._basis_fcn(d)]) def _check_profile_on_basis(self, t): '\n True if the element specified by the tuple ``t`` is in this\n algebra.\n\n INPUT:\n\n - ``t`` - tuple of ...\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra(profile=[1,2,1])\n sage: A._check_profile_on_basis((0,0,1))\n True\n sage: A._check_profile_on_basis((0,0,2))\n False\n sage: A5 = SteenrodAlgebra(p=5, profile=([3,2,1], [2,2,2,2,2]))\n sage: A5._check_profile_on_basis(((), (1,5)))\n True\n sage: A5._check_profile_on_basis(((1,1,1), (1,5)))\n True\n sage: A5._check_profile_on_basis(((1,1,1), (1,5,5)))\n False\n ' if (self.basis_name() != 'milnor'): A = SteenrodAlgebra(p=self.prime(), profile=self._profile, truncation_type=self._truncation_type, generic=self._generic) return all((A._check_profile_on_basis(a[0]) for a in self._milnor_on_basis(t))) from sage.rings.infinity import Infinity p = self.prime() if (not self._has_nontrivial_profile()): return True if (not self._generic): return all((((self.profile((i + 1)) == Infinity) or (t[i] < (2 ** self.profile((i + 1))))) for i in range(len(t)))) if any(((self.profile(i, 1) != 2) for i in t[0])): return False return all((((self.profile((i + 1), 0) == Infinity) or (t[1][i] < (p ** self.profile((i + 1), 0)))) for i in range(len(t[1])))) def P(self, *nums): "\n The element `P(a, b, c, ...)`\n\n INPUT:\n\n - ``a, b, c, ...`` - non-negative integers\n\n OUTPUT:\n\n element of the Steenrod algebra given by the Milnor\n single basis element `P(a, b, c, ...)`\n\n Note that at the prime 2, this is the same element as\n `\\text{Sq}(a, b, c, ...)`.\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra(2)\n sage: A.P(5)\n Sq(5)\n sage: B = SteenrodAlgebra(3)\n sage: B.P(5,1,1)\n P(5,1,1)\n sage: B.P(1,1,-12,1)\n Traceback (most recent call last):\n ...\n TypeError: entries must be non-negative integers\n\n sage: SteenrodAlgebra(basis='serre-cartan').P(0,1)\n Sq^2 Sq^1 + Sq^3\n sage: SteenrodAlgebra(generic=True).P(2,0,1)\n P(2,0,1)\n " from sage.rings.integer import Integer if (self.basis_name() != 'milnor'): return self(SteenrodAlgebra(p=self.prime(), generic=self._generic).P(*nums)) while (nums and (nums[(- 1)] == 0)): nums = nums[:(- 1)] if ((len(nums) == 0) or ((len(nums) == 1) and (nums[0] == 0))): return self.one() for i in nums: try: assert (Integer(i) >= 0) except (TypeError, AssertionError): raise TypeError('entries must be non-negative integers') if (not self._generic): t = nums else: t = ((), nums) if self._check_profile_on_basis(t): A = SteenrodAlgebra_generic(p=self.prime(), generic=self._generic) a = A.monomial(t) return self(a) raise ValueError('Element not in this algebra') def Q_exp(self, *nums): '\n The element `Q_0^{e_0} Q_1^{e_1} ...` , given by\n specifying the exponents.\n\n INPUT:\n\n - ``e0, e1, ...`` - sequence of 0s and 1s\n\n OUTPUT: The element `Q_0^{e_0} Q_1^{e_1} ...`\n\n Note that at the prime 2, `Q_n` is the element\n `\\text{Sq}(0,0,...,1)` , where the 1 is in the\n `(n+1)^{st}` position.\n\n Compare this to the method :meth:`Q`, which defines a similar\n element, but by specifying the tuple of subscripts of terms\n with exponent 1.\n\n EXAMPLES::\n\n sage: A2 = SteenrodAlgebra(2)\n sage: A5 = SteenrodAlgebra(5)\n sage: A2.Q_exp(0,0,1,1,0)\n Sq(0,0,1,1)\n sage: A5.Q_exp(0,0,1,1,0)\n Q_2 Q_3\n sage: A5.Q(2,3)\n Q_2 Q_3\n sage: A5.Q_exp(0,0,1,1,0) == A5.Q(2,3)\n True\n sage: SteenrodAlgebra(2,generic=True).Q_exp(1,0,1)\n Q_0 Q_2\n ' if (not all(((x in (0, 1)) for x in nums))): raise ValueError((('The tuple %s should consist ' % (nums,)) + "only of 0's and 1's")) else: if (self.basis_name() != 'milnor'): return self(SteenrodAlgebra(p=self.prime(), generic=self._generic).Q_exp(*nums)) while (nums[(- 1)] == 0): nums = nums[:(- 1)] if (not self._generic): return self.P(*nums) else: mono = () index = 0 for e in nums: if (e == 1): mono = (mono + (index,)) index += 1 return self.Q(*mono) def Q(self, *nums): '\n The element `Q_{n0} Q_{n1} ...` , given by specifying the\n subscripts.\n\n INPUT:\n\n - ``n0, n1, ...`` - non-negative integers\n\n OUTPUT: The element `Q_{n0} Q_{n1} ...`\n\n Note that at the prime 2, `Q_n` is the element\n `\\text{Sq}(0,0,...,1)` , where the 1 is in the\n `(n+1)^{st}` position.\n\n Compare this to the method :meth:`Q_exp`, which defines a\n similar element, but by specifying the tuple of exponents.\n\n EXAMPLES::\n\n sage: A2 = SteenrodAlgebra(2)\n sage: A2.Q(2,3)\n Sq(0,0,1,1)\n sage: A5 = SteenrodAlgebra(5)\n sage: A5.Q(1,4)\n Q_1 Q_4\n sage: A5.Q(1,4) == A5.Q_exp(0,1,0,0,1)\n True\n sage: H = SteenrodAlgebra(p=5, profile=[[2,1], [2,2,2]])\n sage: H.Q(2)\n Q_2\n sage: H.Q(4)\n Traceback (most recent call last):\n ...\n ValueError: Element not in this algebra\n ' if (len(nums) != len(set(nums))): return self(0) else: if (self.basis_name() != 'milnor'): return self(SteenrodAlgebra(p=self.prime(), generic=self._generic).Q(*nums)) if (not self._generic): if (len(nums) == 0): return self.one() else: list = ((1 + max(nums)) * [0]) for i in nums: list[i] = 1 return self.Sq(*tuple(list)) else: answer = self.one() for i in nums: answer = (answer * self.monomial(((i,), ()))) t = answer.leading_support() if self._check_profile_on_basis(t): return answer raise ValueError('Element not in this algebra') def an_element(self): "\n An element of this Steenrod algebra.\n\n The element depends on\n the basis and whether there is a nontrivial profile function.\n (This is used by the automatic test suite, so having different\n elements in different bases may help in discovering bugs.)\n\n EXAMPLES::\n\n sage: SteenrodAlgebra().an_element()\n Sq(2,1)\n sage: SteenrodAlgebra(basis='adem').an_element()\n Sq^4 Sq^2 Sq^1\n sage: SteenrodAlgebra(p=5).an_element()\n 4 Q_1 Q_3 P(2,1)\n sage: SteenrodAlgebra(basis='pst').an_element()\n P^3_1\n sage: SteenrodAlgebra(basis='pst', profile=[3,2,1]).an_element()\n P^0_1\n " from sage.rings.finite_rings.finite_field_constructor import GF basis = self.basis_name() p = self.prime() if self._has_nontrivial_profile(): if self.ngens(): return self.gen(0) else: return self.one() if ((basis == 'milnor') and (not self._generic)): return self.monomial((2, 1)) if ((basis == 'milnor') and self._generic): return self.term(((1, 3), (2, 1)), GF(p)((p - 1))) if ((basis == 'serre-cartan') and (not self._generic)): return self.monomial((4, 2, 1)) if ((basis == 'serre-cartan') and self._generic): return self.term((1, p, 0, 1, 0), GF(p)((p - 1))) if ((basis == 'woody') or (basis == 'woodz')): return self._from_dict({((3, 0),): 1, ((1, 1), (1, 0)): 1}, coerce=True) if (basis.find('wall') >= 0): return self._from_dict({((1, 1), (1, 0)): 1, ((2, 2), (0, 0)): 1}, coerce=True) if (basis.find('arnona') >= 0): return self._from_dict({((3, 3),): 1, ((1, 1), (2, 1)): 1}, coerce=True) if (basis == 'arnonc'): return self._from_dict({(8,): 1, (4, 4): 1}, coerce=True) if (basis.find('pst') >= 0): if (not self._generic): return self.monomial(((3, 1),)) return self.term(((1,), (((1, 1), 2),)), GF(p)((p - 1))) if (basis.find('comm') >= 0): if (not self._generic): return self.monomial(((1, 2),)) return self.term(((), (((1, 2), 1),)), GF(p)((p - 1))) def pst(self, s, t): '\n The Margolis element `P^s_t`.\n\n INPUT:\n\n - ``s`` - non-negative integer\n\n - ``t`` - positive integer\n\n - ``p`` - positive prime number\n\n OUTPUT: element of the Steenrod algebra\n\n This returns the Margolis element `P^s_t` of the mod\n `p` Steenrod algebra: the element equal to\n `P(0,0,...,0,p^s)`, where the `p^s` is in position\n `t`.\n\n EXAMPLES::\n\n sage: A2 = SteenrodAlgebra(2)\n sage: A2.pst(3,5)\n Sq(0,0,0,0,8)\n sage: A2.pst(1,2) == Sq(4)*Sq(2) + Sq(2)*Sq(4)\n True\n sage: SteenrodAlgebra(5).pst(3,5)\n P(0,0,0,0,125)\n ' from sage.rings.integer import Integer if (self.basis_name() != 'milnor'): return self(SteenrodAlgebra(p=self.prime(), generic=self._generic).pst(s, t)) if ((not isinstance(s, (Integer, int))) and (s >= 0)): raise ValueError(('%s is not a non-negative integer' % s)) if ((not isinstance(t, (Integer, int))) and (t > 0)): raise ValueError(('%s is not a positive integer' % t)) nums = (((0,) * (t - 1)) + ((self.prime() ** s),)) return self.P(*nums) def ngens(self): "\n Number of generators of ``self``.\n\n OUTPUT: number or Infinity\n\n The Steenrod algebra is infinitely generated. A sub-Hopf\n algebra may be finitely or infinitely generated; in general,\n it is not clear what a minimal generating set is, nor the\n cardinality of that set. So: if the algebra is\n infinite-dimensional, this returns Infinity. If the algebra\n is finite-dimensional and is equal to one of the sub-Hopf\n algebras `A(n)`, then their minimal generating set is known,\n and this returns the cardinality of that set. Otherwise, any\n sub-Hopf algebra is (not necessarily minimally) generated by\n the `P^s_t`'s that it contains (along with the `Q_n`'s it\n contains, at odd primes), so this returns the number of\n `P^s_t`'s and `Q_n`'s in the algebra.\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra(3)\n sage: A.ngens()\n +Infinity\n sage: SteenrodAlgebra(profile=lambda n: n).ngens()\n +Infinity\n sage: SteenrodAlgebra(profile=[3,2,1]).ngens() # A(2)\n 3\n sage: SteenrodAlgebra(profile=[3,2,1], basis='pst').ngens()\n 3\n sage: SteenrodAlgebra(p=3, profile=[[3,2,1], [2,2,2,2]]).ngens() # A(3) at p=3\n 4\n sage: SteenrodAlgebra(profile=[1,2,1,1]).ngens()\n 5\n " from sage.rings.infinity import Infinity if (self._truncation_type == Infinity): return Infinity n = self.profile(1) p = self.prime() if ((not self._generic) and (self._profile == AA((n - 1), p=p)._profile)): return n if (self._generic and (self._profile == AA(n, p=p)._profile)): return (n + 1) if (not self._generic): return sum(self._profile) return (sum(self._profile[0]) + len([a for a in self._profile[1] if (a == 2)])) def gens(self): "\n Family of generators for this algebra.\n\n OUTPUT: family of elements of this algebra\n\n At the prime 2, the Steenrod algebra is generated by the\n elements `\\text{Sq}^{2^i}` for `i \\geq 0`. At odd primes, it\n is generated by the elements `Q_0` and `\\mathcal{P}^{p^i}` for\n `i \\geq 0`. So if this algebra is the entire Steenrod\n algebra, return an infinite family made up of these elements.\n\n For sub-Hopf algebras of the Steenrod algebra, it is not\n always clear what a minimal generating set is. The sub-Hopf\n algebra `A(n)` is minimally generated by the elements\n `\\text{Sq}^{2^i}` for `0 \\leq i \\leq n` at the prime 2. At\n odd primes, `A(n)` is minimally generated by `Q_0` along with\n `\\mathcal{P}^{p^i}` for `0 \\leq i \\leq n-1`. So if this\n algebra is `A(n)`, return the appropriate list of generators.\n\n For other sub-Hopf algebras: return a non-minimal generating\n set: the family of `P^s_t`'s and `Q_n`'s contained in the\n algebra.\n\n EXAMPLES::\n\n sage: A3 = SteenrodAlgebra(3, 'adem')\n sage: A3.gens()\n Lazy family (<bound method SteenrodAlgebra_generic.gen of mod 3 Steenrod algebra,\n serre-cartan basis>(i))_{i in Non negative integers}\n sage: A3.gens()[0]\n beta\n sage: A3.gens()[1]\n P^1\n sage: A3.gens()[2]\n P^3\n sage: SteenrodAlgebra(profile=[3,2,1]).gens()\n Family (Sq(1), Sq(2), Sq(4))\n\n In the following case, return a non-minimal generating set.\n (It is not minimal because `\\text{Sq}(0,0,1)` is the\n commutator of `\\text{Sq}(1)` and `\\text{Sq}(0,2)`.) ::\n\n sage: SteenrodAlgebra(profile=[1,2,1]).gens()\n Family (Sq(1), Sq(0,1), Sq(0,2), Sq(0,0,1))\n sage: SteenrodAlgebra(p=5, profile=[[2,1], [2,2,2]]).gens()\n Family (Q_0, P(1), P(5))\n sage: SteenrodAlgebra(profile=lambda n: n).gens()\n Lazy family (<bound method SteenrodAlgebra_generic.gen of sub-Hopf algebra\n of mod 2 Steenrod algebra, milnor basis, profile function [1, 2, 3, ...,\n 98, 99, +Infinity, +Infinity, +Infinity, ...]>(i))_{i in Non negative integers}\n\n You may also use ``algebra_generators`` instead of ``gens``::\n\n sage: SteenrodAlgebra(p=5, profile=[[2,1], [2,2,2]]).algebra_generators()\n Family (Q_0, P(1), P(5))\n " from sage.sets.family import Family from sage.sets.non_negative_integers import NonNegativeIntegers from sage.rings.infinity import Infinity n = self.ngens() if (n < Infinity): return Family([self.gen(i) for i in range(n)]) return Family(NonNegativeIntegers(), self.gen) algebra_generators = gens def gen(self, i=0): "\n The ith generator of this algebra.\n\n INPUT:\n\n - ``i`` - non-negative integer\n\n OUTPUT: the ith generator of this algebra\n\n For the full Steenrod algebra, the `i^{th}` generator is\n `\\text{Sq}(2^i)` at the prime 2; when `p` is odd, the 0th generator\n is `\\beta = Q(0)`, and for `i>0`, the `i^{th}` generator is\n `P(p^{i-1})`.\n\n For sub-Hopf algebras of the Steenrod algebra, it is not\n always clear what a minimal generating set is. The sub-Hopf\n algebra `A(n)` is minimally generated by the elements\n `\\text{Sq}^{2^i}` for `0 \\leq i \\leq n` at the prime 2. At\n odd primes, `A(n)` is minimally generated by `Q_0` along with\n `\\mathcal{P}^{p^i}` for `0 \\leq i \\leq n-1`. So if this\n algebra is `A(n)`, return the appropriate generator.\n\n For other sub-Hopf algebras: they are generated (but not\n necessarily minimally) by the `P^s_t`'s (and `Q_n`'s, if `p`\n is odd) that they contain. So order the `P^s_t`'s (and\n `Q_n`'s) in the algebra by degree and return the `i`-th one.\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra(2)\n sage: A.gen(4)\n Sq(16)\n sage: A.gen(200)\n Sq(1606938044258990275541962092341162602522202993782792835301376)\n sage: SteenrodAlgebra(2, basis='adem').gen(2)\n Sq^4\n sage: SteenrodAlgebra(2, basis='pst').gen(2)\n P^2_1\n sage: B = SteenrodAlgebra(5)\n sage: B.gen(0)\n Q_0\n sage: B.gen(2)\n P(5)\n\n sage: SteenrodAlgebra(profile=[2,1]).gen(1)\n Sq(2)\n sage: SteenrodAlgebra(profile=[1,2,1]).gen(1)\n Sq(0,1)\n sage: SteenrodAlgebra(profile=[1,2,1]).gen(5)\n Traceback (most recent call last):\n ...\n ValueError: This algebra only has 4 generators, so call gen(i) with 0 <= i < 4\n\n sage: D = SteenrodAlgebra(profile=lambda n: n)\n sage: [D.gen(n) for n in range(5)]\n [Sq(1), Sq(0,1), Sq(0,2), Sq(0,0,1), Sq(0,0,2)]\n sage: D3 = SteenrodAlgebra(p=3, profile=(lambda n: n, lambda n: 2))\n sage: [D3.gen(n) for n in range(9)]\n [Q_0, P(1), Q_1, P(0,1), Q_2, P(0,3), P(0,0,1), Q_3, P(0,0,3)]\n sage: D3 = SteenrodAlgebra(p=3, profile=(lambda n: n, lambda n: 1 if n<1 else 2))\n sage: [D3.gen(n) for n in range(9)]\n [P(1), Q_1, P(0,1), Q_2, P(0,3), P(0,0,1), Q_3, P(0,0,3), P(0,0,0,1)]\n sage: SteenrodAlgebra(p=5, profile=[[2,1], [2,2,2]], basis='pst').gen(2)\n P^1_1\n " from sage.rings.infinity import Infinity from sage.rings.integer import Integer p = self.prime() if ((not isinstance(i, (Integer, int))) and (i >= 0)): raise ValueError(('%s is not a non-negative integer' % i)) num = self.ngens() if (num < Infinity): if (i >= num): raise ValueError(('This algebra only has %s generators, so call gen(i) with 0 <= i < %s' % (num, num))) n = self.profile(1) if ((not self._generic) and (self._profile == AA((n - 1), p=p)._profile)): return self.pst(i, 1) if (self._generic and (self._profile == AA(n, p=p)._profile)): if (i == 0): return self.Q(0) return self.pst((i - 1), 1) idx = (- 1) if (not self._generic): last_t = len(self._profile) else: last_t = max(len(self._profile[0]), len(self._profile[1])) last_s = self.profile(last_t) for j in range(1, ((last_s + last_t) + 1)): if (self._generic and (self.profile((j - 1), 1) == 2)): guess = self.Q((j - 1)) idx += 1 if (idx == i): elt = guess break for t in range(1, (min(j, last_t) + 1)): s = (j - t) if (self.profile(t) > s): guess = self.pst(s, t) idx += 1 if (idx == i): elt = guess break return elt if (self.profile(1) == Infinity): if (not self._generic): return self.Sq((p ** i)) elif (self.profile(0, 1) == 2): if (i == 0): return self.Q(0) else: return self.P((p ** (i - 1))) idx = (- 1) tot = 1 found = False A = SteenrodAlgebra(p=p, generic=self._generic) while (not found): if self._generic: test = A.Q((tot - 1)) if (test in self): idx += 1 if (idx == i): break for t in range(1, (tot + 1)): s = (tot - t) test = A.pst(s, t) if (test in self): idx += 1 if (idx == i): found = True break tot += 1 return test def is_commutative(self): '\n True if ``self`` is graded commutative, as determined by the\n profile function. In particular, a sub-Hopf algebra of the\n mod 2 Steenrod algebra is commutative if and only if there is\n an integer `n>0` so that its profile function `e` satisfies\n\n - `e(i) = 0` for `i < n`,\n - `e(i) \\leq n` for `i \\geq n`.\n\n When `p` is odd, there must be an integer `n \\geq 0` so that\n the profile functions `e` and `k` satisfy\n\n - `e(i) = 0` for `i < n`,\n - `e(i) \\leq n` for `i \\geq n`.\n - `k(i) = 1` for `i < n`.\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra(p=3)\n sage: A.is_commutative()\n False\n sage: SteenrodAlgebra(profile=[2,1]).is_commutative()\n False\n sage: SteenrodAlgebra(profile=[0,2,2,1]).is_commutative()\n True\n\n Note that if the profile function is specified by a function,\n then by default it has infinite truncation type: the profile\n function is assumed to be infinite after the 100th term. ::\n\n sage: SteenrodAlgebra(profile=lambda n: 1).is_commutative()\n False\n sage: SteenrodAlgebra(profile=lambda n: 1, truncation_type=0).is_commutative()\n True\n\n sage: SteenrodAlgebra(p=5, profile=([0,2,2,1], [])).is_commutative()\n True\n sage: SteenrodAlgebra(p=5, profile=([0,2,2,1], [1,1,2])).is_commutative()\n True\n sage: SteenrodAlgebra(p=5, profile=([0,2,1], [1,2,2,2])).is_commutative()\n False\n ' if ((not self._has_nontrivial_profile()) or (self._truncation_type > 0)): return False if (not self._generic): n = max(self._profile) return all(((self.profile(i) == 0) for i in range(1, n))) n = max(self._profile[0]) return (all(((self.profile(i, 0) == 0) for i in range(1, n))) and all(((self.profile(i, 1) == 1) for i in range(n)))) def is_finite(self): '\n True if this algebra is finite-dimensional.\n\n Therefore true if the profile function is finite, and in\n particular the ``truncation_type`` must be finite.\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra(p=3)\n sage: A.is_finite()\n False\n sage: SteenrodAlgebra(profile=[3,2,1]).is_finite()\n True\n sage: SteenrodAlgebra(profile=lambda n: n).is_finite()\n False\n ' return (self._has_nontrivial_profile() and (self._truncation_type == 0)) def dimension(self): "\n The dimension of this algebra as a vector space over `\\GF{p}`.\n\n If the algebra is infinite, return ``+Infinity``. Otherwise,\n the profile function must be finite. In this case, at the\n prime 2, its dimension is `2^s`, where `s` is the sum of the\n entries in the profile function. At odd primes, the dimension\n is `p^s * 2^t` where `s` is the sum of the `e` component of\n the profile function and `t` is the number of 2's in the `k`\n component of the profile function.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(p=7).dimension()\n +Infinity\n sage: SteenrodAlgebra(profile=[3,2,1]).dimension()\n 64\n sage: SteenrodAlgebra(p=3, profile=([1,1], [])).dimension()\n 9\n sage: SteenrodAlgebra(p=5, profile=([1], [2,2])).dimension()\n 20\n " from sage.rings.infinity import Infinity if (not self.is_finite()): return Infinity p = self.prime() if (not self._generic): return (2 ** sum(self._profile)) return ((p ** sum(self._profile[0])) * (2 ** len([a for a in self._profile[1] if (a == 2)]))) @cached_method def top_class(self): "\n Highest dimensional basis element. This is only defined if the algebra is finite.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(2, profile=(3,2,1)).top_class()\n Sq(7,3,1)\n sage: SteenrodAlgebra(3, profile=((2,2,1),(1,2,2,2,2))).top_class()\n Q_1 Q_2 Q_3 Q_4 P(8,8,2)\n\n TESTS::\n\n sage: SteenrodAlgebra(2, profile=(3,2,1), basis='pst').top_class()\n P^0_1 P^0_2 P^1_1 P^0_3 P^1_2 P^2_1\n sage: SteenrodAlgebra(5, profile=((0,),(2,1,2,2))).top_class()\n Q_0 Q_2 Q_3\n sage: SteenrodAlgebra(5).top_class()\n Traceback (most recent call last):\n ...\n ValueError: the algebra is not finite dimensional\n\n Currently, we create the top class in the Milnor basis version and transform\n this result back into the requested basis. This approach is easy to implement\n but far from optimal for the 'pst' basis. Occasionally, it also gives an awkward\n leading coefficient::\n\n sage: SteenrodAlgebra(3, profile=((2,1),(1,2,2)), basis='pst').top_class()\n 2 Q_1 Q_2 (P^0_1)^2 (P^0_2)^2 (P^1_1)^2\n\n TESTS::\n\n sage: A=SteenrodAlgebra(2, profile=(3,2,1), basis='pst')\n sage: A.top_class().parent() is A\n True\n " if (not self.is_finite()): raise ValueError('the algebra is not finite dimensional') p = self.prime() AM = SteenrodAlgebra(basis='milnor', p=p, generic=self._generic) if (not self._generic): ans = AM.monomial(tuple((((1 << k) - 1) for k in self._profile))) else: (rp, ep) = self._profile e = [kk for kk in range(len(ep)) if (ep[kk] == 2)] r = [((p ** kk) - 1) for kk in rp] ans = AM.monomial((tuple(e), tuple(r))) return self(ans.change_basis(self.basis_name())) def order(self): '\n The order of this algebra.\n\n This is computed by computing its vector space dimension `d`\n and then returning `p^d`.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(p=7).order()\n +Infinity\n sage: SteenrodAlgebra(profile=[2,1]).dimension()\n 8\n sage: SteenrodAlgebra(profile=[2,1]).order()\n 256\n sage: SteenrodAlgebra(p=3, profile=([1], [])).dimension()\n 3\n sage: SteenrodAlgebra(p=3, profile=([1], [])).order()\n 27\n sage: SteenrodAlgebra(p=5, profile=([], [2, 2])).dimension()\n 4\n sage: SteenrodAlgebra(p=5, profile=([], [2, 2])).order() == 5**4\n True\n ' from sage.rings.infinity import Infinity if (not self.is_finite()): return Infinity return (self.prime() ** self.dimension()) def is_division_algebra(self): '\n The only way this algebra can be a division algebra is if it\n is the ground field `\\GF{p}`.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(11).is_division_algebra()\n False\n sage: SteenrodAlgebra(profile=lambda n: 0, truncation_type=0).is_division_algebra()\n True\n ' return self.is_field() def is_field(self, proof=True): '\n The only way this algebra can be a field is if it is the\n ground field `\\GF{p}`.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(11).is_field()\n False\n sage: SteenrodAlgebra(profile=lambda n: 0, truncation_type=0).is_field()\n True\n ' return (self.dimension() == 1) def is_integral_domain(self, proof=True): '\n The only way this algebra can be an integral domain is if it\n is the ground field `\\GF{p}`.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(11).is_integral_domain()\n False\n sage: SteenrodAlgebra(profile=lambda n: 0, truncation_type=0).is_integral_domain()\n True\n ' return self.is_field() def is_noetherian(self): '\n This algebra is noetherian if and only if it is finite.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(3).is_noetherian()\n False\n sage: SteenrodAlgebra(profile=[1,2,1]).is_noetherian()\n True\n sage: SteenrodAlgebra(profile=lambda n: n+2).is_noetherian()\n False\n ' return self.is_finite() def is_generic(self): '\n The algebra is generic if it is based on the odd-primary relations,\n i.e. if its dual is a quotient of\n\n .. MATH::\n\n A_* = \\GF{p} [\\xi_1, \\xi_2, \\xi_3, ...] \\otimes \\Lambda (\\tau_0, \\tau_1, ...)\n\n Sage also allows this for `p=2`. Only the usual Steenrod algebra at the prime `2` and\n its sub algebras are non-generic.\n\n EXAMPLES::\n\n sage: SteenrodAlgebra(3).is_generic()\n True\n sage: SteenrodAlgebra(2).is_generic()\n False\n sage: SteenrodAlgebra(2, generic=True).is_generic()\n True\n ' return self._generic class Element(CombinatorialFreeModule.Element): '\n Class for elements of the Steenrod algebra. Since the\n Steenrod algebra class is based on\n :class:`CombinatorialFreeModule\n <sage.combinat.free_module.CombinatorialFreeModule>`, this is\n based on :class:`IndexedFreeModuleElement\n <sage.modules.with_basis.indexed_element.IndexedFreeModuleElement>`.\n It has new methods reflecting its role, like :meth:`degree`\n for computing the degree of an element.\n\n EXAMPLES:\n\n Since this class inherits from\n :class:`IndexedFreeModuleElement\n <sage.modules.with_basis.indexed_element.IndexedFreeModuleElement>`,\n elements can be used as iterators, and there are other useful\n methods::\n\n sage: c = Sq(5).antipode(); c\n Sq(2,1) + Sq(5)\n sage: for mono, coeff in c: print((coeff, mono))\n (1, (5,))\n (1, (2, 1))\n sage: c.monomial_coefficients() == {(2, 1): 1, (5,): 1}\n True\n sage: sorted(c.monomials(), key=lambda x: tuple(x.support()))\n [Sq(2,1), Sq(5)]\n sage: sorted(c.support())\n [(2, 1), (5,)]\n\n See the documentation for this module (type\n ``sage.algebras.steenrod.steenrod_algebra?``) for more\n information about elements of the Steenrod algebra.\n ' def prime(self): "\n The prime associated to self.\n\n EXAMPLES::\n\n sage: a = SteenrodAlgebra().Sq(3,2,1)\n sage: a.prime()\n 2\n sage: a.change_basis('adem').prime()\n 2\n sage: b = SteenrodAlgebra(p=7).basis(36)[0]\n sage: b.prime()\n 7\n sage: SteenrodAlgebra(p=3, basis='adem').one().prime()\n 3\n " return self.base_ring().characteristic() def basis_name(self): "\n The basis name associated to self.\n\n EXAMPLES::\n\n sage: a = SteenrodAlgebra().Sq(3,2,1)\n sage: a.basis_name()\n 'milnor'\n sage: a.change_basis('adem').basis_name()\n 'serre-cartan'\n sage: a.change_basis('wood____y').basis_name()\n 'woody'\n sage: b = SteenrodAlgebra(p=7).basis(36)[0]\n sage: b.basis_name()\n 'milnor'\n sage: a.change_basis('adem').basis_name()\n 'serre-cartan'\n " return self.parent().prefix() def is_homogeneous(self): '\n Return True iff this element is homogeneous.\n\n EXAMPLES::\n\n sage: (Sq(0,0,1) + Sq(7)).is_homogeneous()\n True\n sage: (Sq(0,0,1) + Sq(2)).is_homogeneous()\n False\n ' monos = self.support() if (len(monos) <= 1): return True degree = None deg = self.parent().degree_on_basis for mono in monos: if (degree is None): degree = deg(mono) elif (deg(mono) != degree): return False return True def degree(self): "\n The degree of self.\n\n The degree of `\\text{Sq}(i_1,i_2,i_3,...)` is\n\n .. MATH::\n\n i_1 + 3i_2 + 7i_3 + ... + (2^k - 1) i_k + ....\n\n At an odd prime `p`, the degree of `Q_k` is `2p^k - 1` and the\n degree of `\\mathcal{P}(i_1, i_2, ...)` is\n\n .. MATH::\n\n \\sum_{k \\geq 0} 2(p^k - 1) i_k.\n\n ALGORITHM: If :meth:`is_homogeneous` returns True, call\n :meth:`SteenrodAlgebra_generic.degree_on_basis` on the leading\n summand.\n\n EXAMPLES::\n\n sage: Sq(0,0,1).degree()\n 7\n sage: (Sq(0,0,1) + Sq(7)).degree()\n 7\n sage: (Sq(0,0,1) + Sq(2)).degree()\n Traceback (most recent call last):\n ...\n ValueError: element is not homogeneous\n\n sage: A11 = SteenrodAlgebra(p=11)\n sage: A11.P(1).degree()\n 20\n sage: A11.P(1,1).degree()\n 260\n sage: A11.Q(2).degree()\n 241\n\n TESTS::\n\n sage: all(x.degree() == 10 for x in SteenrodAlgebra(basis='woody').basis(10))\n True\n sage: all(x.degree() == 11 for x in SteenrodAlgebra(basis='woodz').basis(11))\n True\n sage: all(x.degree() == x.milnor().degree() for x in SteenrodAlgebra(basis='wall').basis(11))\n True\n sage: a = SteenrodAlgebra(basis='pst').basis(10)[0]\n sage: a.degree() == a.change_basis('arnonc').degree()\n True\n sage: b = SteenrodAlgebra(basis='comm').basis(12)[1]\n sage: b.degree() == b.change_basis('adem').change_basis('arnona').degree()\n True\n sage: all(x.degree() == 9 for x in SteenrodAlgebra(basis='comm').basis(9))\n True\n sage: all(x.degree() == 8 for x in SteenrodAlgebra(basis='adem').basis(8))\n True\n sage: all(x.degree() == 7 for x in SteenrodAlgebra(basis='milnor').basis(7))\n True\n sage: all(x.degree() == 24 for x in SteenrodAlgebra(p=3).basis(24))\n True\n sage: all(x.degree() == 40 for x in SteenrodAlgebra(p=5, basis='serre-cartan').basis(40))\n True\n " if (len(self.support()) == 0): raise ValueError('the zero element does not have a well-defined degree') if (not self.is_homogeneous()): raise ValueError('element is not homogeneous') return self.parent().degree_on_basis(self.leading_support()) def milnor(self): "\n Return this element in the Milnor basis; that is, as an\n element of the appropriate Steenrod algebra.\n\n This just calls the method\n :meth:`SteenrodAlgebra_generic.milnor`.\n\n EXAMPLES::\n\n sage: Adem = SteenrodAlgebra(basis='adem')\n sage: a = Adem.basis(4)[1]; a\n Sq^3 Sq^1\n sage: a.milnor()\n Sq(1,1)\n " A = self.parent() return A.milnor(self) def change_basis(self, basis='milnor'): "\n Representation of element with respect to basis.\n\n INPUT:\n\n - ``basis`` - string, basis in which to work.\n\n OUTPUT: representation of self in given basis\n\n The choices for ``basis`` are:\n\n - 'milnor' for the Milnor basis.\n - 'serre-cartan', 'serre_cartan', 'sc', 'adem', 'admissible'\n for the Serre-Cartan basis.\n - 'wood_y' for Wood's Y basis.\n - 'wood_z' for Wood's Z basis.\n - 'wall' for Wall's basis.\n - 'wall_long' for Wall's basis, alternate representation\n - 'arnon_a' for Arnon's A basis.\n - 'arnon_a_long' for Arnon's A basis, alternate representation.\n - 'arnon_c' for Arnon's C basis.\n - 'pst', 'pst_rlex', 'pst_llex', 'pst_deg', 'pst_revz' for\n various `P^s_t`-bases.\n - 'comm', 'comm_rlex', 'comm_llex', 'comm_deg', 'comm_revz'\n for various commutator bases.\n - 'comm_long', 'comm_rlex_long', etc., for commutator bases,\n alternate representations.\n\n See documentation for this module (by browsing the\n reference manual or by typing\n ``sage.algebras.steenrod.steenrod_algebra?``) for\n descriptions of the different bases.\n\n EXAMPLES::\n\n sage: c = Sq(2) * Sq(1)\n sage: c.change_basis('milnor')\n Sq(0,1) + Sq(3)\n sage: c.change_basis('serre-cartan')\n Sq^2 Sq^1\n sage: d = Sq(0,0,1)\n sage: d.change_basis('arnonc')\n Sq^2 Sq^5 + Sq^4 Sq^2 Sq^1 + Sq^4 Sq^3 + Sq^7\n " A = self.parent() return A._change_basis(self, basis) def _basis_dictionary(self, basis): "\n Convert self to ``basis``, returning a dictionary of terms of\n the form (mono: coeff), where mono is a monomial in the given\n basis.\n\n INPUT:\n\n - ``basis`` - string, basis in which to work\n\n OUTPUT: dictionary\n\n This just calls :meth:`change_basis` to get an element of the\n Steenrod algebra with the new basis, and then calls\n :meth:`monomial_coefficients` on this element to produce its\n dictionary representation.\n\n EXAMPLES::\n\n sage: c = Sq(2) * Sq(1)\n sage: c._basis_dictionary('milnor') == {(0, 1): 1, (3,): 1}\n True\n sage: c\n Sq(0,1) + Sq(3)\n sage: c._basis_dictionary('serre-cartan')\n {(2, 1): 1}\n sage: c.change_basis('serre-cartan')\n Sq^2 Sq^1\n sage: d = Sq(0,0,1)\n sage: sorted(d._basis_dictionary('arnonc').items())\n [((2, 5), 1), ((4, 2, 1), 1), ((4, 3), 1), ((7,), 1)]\n sage: d.change_basis('arnonc')\n Sq^2 Sq^5 + Sq^4 Sq^2 Sq^1 + Sq^4 Sq^3 + Sq^7\n\n At odd primes::\n\n sage: e = 2 * SteenrodAlgebra(3).P(1,2)\n sage: e._basis_dictionary('milnor')\n {((), (1, 2)): 2}\n sage: e\n 2 P(1,2)\n sage: sorted(e._basis_dictionary('serre-cartan').items())\n [((0, 7, 0, 2, 0), 2), ((0, 8, 0, 1, 0), 2)]\n sage: e.change_basis('adem')\n 2 P^7 P^2 + 2 P^8 P^1\n " a = self.change_basis(basis) return a.monomial_coefficients() def coproduct(self, algorithm='milnor'): "\n The coproduct of this element.\n\n INPUT:\n\n - ``algorithm`` -- ``None`` or a string, either 'milnor' or\n 'serre-cartan' (or anything which will be converted to\n one of these by the function :func:`get_basis_name\n <sage.algebras.steenrod.steenrod_algebra_misc.get_basis_name>`).\n If ``None``, default to 'serre-cartan' if current basis is\n 'serre-cartan'; otherwise use 'milnor'.\n\n See :meth:`SteenrodAlgebra_generic.coproduct_on_basis` for\n more information on computing the coproduct.\n\n EXAMPLES::\n\n sage: a = Sq(2)\n sage: a.coproduct()\n 1 # Sq(2) + Sq(1) # Sq(1) + Sq(2) # 1\n sage: b = Sq(4)\n sage: (a*b).coproduct() == (a.coproduct()) * (b.coproduct())\n True\n\n sage: c = a.change_basis('adem'); c.coproduct(algorithm='milnor')\n 1 # Sq^2 + Sq^1 # Sq^1 + Sq^2 # 1\n sage: c = a.change_basis('adem'); c.coproduct(algorithm='adem')\n 1 # Sq^2 + Sq^1 # Sq^1 + Sq^2 # 1\n\n sage: d = a.change_basis('comm_long'); d.coproduct()\n 1 # s_2 + s_1 # s_1 + s_2 # 1\n\n sage: A7 = SteenrodAlgebra(p=7)\n sage: a = A7.Q(1) * A7.P(1); a\n Q_1 P(1)\n sage: a.coproduct()\n 1 # Q_1 P(1) + P(1) # Q_1 + Q_1 # P(1) + Q_1 P(1) # 1\n sage: a.coproduct(algorithm='adem')\n 1 # Q_1 P(1) + P(1) # Q_1 + Q_1 # P(1) + Q_1 P(1) # 1\n\n Once you have an element of the tensor product, you may\n want to extract the tensor factors of its summands. ::\n\n sage: b = Sq(2).coproduct()\n sage: b\n 1 # Sq(2) + Sq(1) # Sq(1) + Sq(2) # 1\n sage: supp = sorted(b.support()); supp\n [((), (2,)), ((1,), (1,)), ((2,), ())]\n sage: Sq(*supp[0][0])\n 1\n sage: Sq(*supp[0][1])\n Sq(2)\n sage: [(Sq(*x), Sq(*y)) for (x,y) in supp]\n [(1, Sq(2)), (Sq(1), Sq(1)), (Sq(2), 1)]\n\n The ``support`` of an element does not include the\n coefficients, so at odd primes it may be better to use\n ``monomial_coefficients``::\n\n sage: A3 = SteenrodAlgebra(p=3)\n sage: b = (A3.P(1)**2).coproduct()\n sage: b\n 2*1 # P(2) + 2*P(1) # P(1) + 2*P(2) # 1\n sage: sorted(b.support())\n [(((), ()), ((), (2,))), (((), (1,)), ((), (1,))), (((), (2,)), ((), ()))]\n sage: b.monomial_coefficients()\n {(((), ()), ((), (2,))): 2,\n (((), (1,)), ((), (1,))): 2,\n (((), (2,)), ((), ())): 2}\n sage: mc = b.monomial_coefficients()\n sage: sorted([(A3.monomial(x), A3.monomial(y), mc[x,y]) for (x,y) in mc])\n [(1, P(2), 2), (P(1), P(1), 2), (P(2), 1, 2)]\n " A = self.parent() return A.coproduct(self, algorithm=algorithm) def excess(self): '\n Excess of element.\n\n OUTPUT: ``excess`` - non-negative integer\n\n The excess of a Milnor basis element `\\text{Sq}(a,b,c,...)` is\n `a + b + c + \\cdots`. When `p` is odd, the excess of `Q_{0}^{e_0}\n Q_{1}^{e_1} \\cdots P(r_1, r_2, ...)` is `\\sum e_i + 2 \\sum r_i`.\n The excess of a linear combination of Milnor basis elements is\n the minimum of the excesses of those basis elements.\n\n See [Kr1971]_ for the proofs of these assertions.\n\n EXAMPLES::\n\n sage: a = Sq(1,2,3)\n sage: a.excess()\n 6\n sage: (Sq(0,0,1) + Sq(4,1) + Sq(7)).excess()\n 1\n sage: elt = Sq(0,0,1) + Sq(4,1) + Sq(7)\n sage: M = sorted(elt.monomials(), key=lambda x: tuple(x.support()))\n sage: [m.excess() for m in M]\n [1, 5, 7]\n sage: [m for m in M]\n [Sq(0,0,1), Sq(4,1), Sq(7)]\n sage: B = SteenrodAlgebra(7)\n sage: a = B.Q(1,2,5)\n sage: b = B.P(2,2,3)\n sage: a.excess()\n 3\n sage: b.excess()\n 14\n sage: (a + b).excess()\n 3\n sage: (a * b).excess()\n 17\n ' def excess_odd(mono): '\n Excess of mono, where mono has the form\n ((s0, s1, ...), (r1, r2, ...)).\n\n Return the length of the first component, since that\n is the number of factors, plus twice the sum of the\n terms in the second component.\n ' if (not mono): return 0 else: return (len(mono[0]) + (2 * sum(mono[1]))) a = self.milnor() if (not self.parent()._generic): excesses = [sum(mono) for mono in a.support()] else: excesses = [excess_odd(mono) for mono in a.support()] return min(excesses) def is_unit(self): '\n True if element has a nonzero scalar multiple of P(0) as a summand,\n False otherwise.\n\n EXAMPLES::\n\n sage: z = Sq(4,2) + Sq(7,1) + Sq(3,0,1)\n sage: z.is_unit()\n False\n sage: u = Sq(0) + Sq(3,1)\n sage: u == 1 + Sq(3,1)\n True\n sage: u.is_unit()\n True\n sage: A5 = SteenrodAlgebra(5)\n sage: v = A5.P(0)\n sage: (v + v + v).is_unit()\n True\n ' return (self.parent().one() in self.monomials()) def is_nilpotent(self): '\n True if element is not a unit, False otherwise.\n\n EXAMPLES::\n\n sage: z = Sq(4,2) + Sq(7,1) + Sq(3,0,1)\n sage: z.is_nilpotent()\n True\n sage: u = 1 + Sq(3,1)\n sage: u == 1 + Sq(3,1)\n True\n sage: u.is_nilpotent()\n False\n ' return (not self.is_unit()) def may_weight(self): "\n May's 'weight' of element.\n\n OUTPUT: ``weight`` - non-negative integer\n\n If we let `F_* (A)` be the May filtration of the Steenrod\n algebra, the weight of an element `x` is the integer `k` so\n that `x` is in `F_k(A)` and not in `F_{k+1}(A)`. According to\n Theorem 2.6 in May's thesis [May1964]_, the weight of a Milnor\n basis element is computed as follows: first, to compute the\n weight of `P(r_1,r_2, ...)`, write each `r_i` in base `p` as\n `r_i = \\sum_j p^j r_{ij}`. Then each nonzero binary digit\n `r_{ij}` contributes `i` to the weight: the weight is\n `\\sum_{i,j} i r_{ij}`. When `p` is odd, the weight of `Q_i` is\n `i+1`, so the weight of a product `Q_{i_1} Q_{i_2} ...` equals\n `(i_1+1) + (i_2+1) + ...`. Then the weight of `Q_{i_1} Q_{i_2}\n ...P(r_1,r_2, ...)` is the sum of `(i_1+1) + (i_2+1) + ...`\n and `\\sum_{i,j} i r_{ij}`.\n\n The weight of a sum of Milnor basis elements is the minimum of\n the weights of the summands.\n\n When `p=2`, we compute the weight on Milnor basis elements by\n adding up the terms in their 'height' - see\n :meth:`wall_height` for documentation. (When `p` is odd, the\n height of an element is not defined.)\n\n EXAMPLES::\n\n sage: Sq(0).may_weight()\n 0\n sage: a = Sq(4)\n sage: a.may_weight()\n 1\n sage: b = Sq(4)*Sq(8) + Sq(8)*Sq(4)\n sage: b.may_weight()\n 2\n sage: Sq(2,1,5).wall_height()\n [2, 3, 2, 1, 1]\n sage: Sq(2,1,5).may_weight()\n 9\n sage: A5 = SteenrodAlgebra(5)\n sage: a = A5.Q(1,2,4)\n sage: b = A5.P(1,2,1)\n sage: a.may_weight()\n 10\n sage: b.may_weight()\n 8\n sage: (a * b).may_weight()\n 18\n sage: A5.P(0,0,1).may_weight()\n 3\n " from sage.rings.infinity import Infinity from sage.rings.integer import Integer p = self.prime() generic = self.parent()._generic if (self == 0): return Infinity elif self.is_unit(): return 0 elif (not generic): wt = Infinity for mono in self.milnor().monomials(): wt = min(wt, sum(mono.wall_height())) return wt else: wt = Infinity for (mono1, mono2) in self.milnor().support(): P_wt = 0 index = 1 for n in mono2: P_wt += (index * sum(Integer(n).digits(p))) index += 1 wt = min(wt, ((sum(mono1) + len(mono1)) + P_wt)) return wt def is_decomposable(self): "\n Return True if element is decomposable, False otherwise.\n\n That is, if element is in the square of the augmentation ideal,\n return True; otherwise, return False.\n\n OUTPUT: boolean\n\n EXAMPLES::\n\n sage: a = Sq(6)\n sage: a.is_decomposable()\n True\n sage: for i in range(9):\n ....: if not Sq(i).is_decomposable():\n ....: print(Sq(i))\n 1\n Sq(1)\n Sq(2)\n Sq(4)\n Sq(8)\n sage: A3 = SteenrodAlgebra(p=3, basis='adem')\n sage: [A3.P(n) for n in range(30) if not A3.P(n).is_decomposable()]\n [1, P^1, P^3, P^9, P^27]\n\n TESTS:\n\n These all test changing bases and printing in various bases::\n\n sage: A = SteenrodAlgebra(basis='milnor')\n sage: [A.Sq(n) for n in range(9) if not A.Sq(n).is_decomposable()]\n [1, Sq(1), Sq(2), Sq(4), Sq(8)]\n sage: A = SteenrodAlgebra(basis='wall_long')\n sage: [A.Sq(n) for n in range(9) if not A.Sq(n).is_decomposable()]\n [1, Sq^1, Sq^2, Sq^4, Sq^8]\n sage: A = SteenrodAlgebra(basis='arnona_long')\n sage: [A.Sq(n) for n in range(9) if not A.Sq(n).is_decomposable()]\n [1, Sq^1, Sq^2, Sq^4, Sq^8]\n sage: A = SteenrodAlgebra(basis='woodz')\n sage: [A.Sq(n) for n in range(20) if not A.Sq(n).is_decomposable()] # long time\n [1, Sq^1, Sq^2, Sq^4, Sq^8, Sq^16]\n sage: A = SteenrodAlgebra(basis='comm_long')\n sage: [A.Sq(n) for n in range(25) if not A.Sq(n).is_decomposable()] # long time\n [1, s_1, s_2, s_4, s_8, s_16]\n " return (self.may_weight() > 1) def wall_height(self): "\n Wall's 'height' of element.\n\n OUTPUT: list of non-negative integers\n\n The height of an element of the mod 2 Steenrod algebra is a\n list of non-negative integers, defined as follows: if the\n element is a monomial in the generators `\\text{Sq}(2^i)`, then\n the `i^{th}` entry in the list is the number of times\n `\\text{Sq}(2^i)` appears. For an arbitrary element, write it\n as a sum of such monomials; then its height is the maximum,\n ordered right-lexicographically, of the heights of those\n monomials.\n\n When `p` is odd, the height of an element is not defined.\n\n According to Theorem 3 in [Wal1960]_, the height of the Milnor\n basis element `\\text{Sq}(r_1, r_2, ...)` is obtained as\n follows: write each `r_i` in binary as `r_i = \\sum_j 2^j\n r_{ij}`. Then each nonzero binary digit `r_{ij}` contributes 1\n to the `k^{th}` entry in the height, for `j \\leq k \\leq\n i+j-1`.\n\n EXAMPLES::\n\n sage: Sq(0).wall_height()\n []\n sage: a = Sq(4)\n sage: a.wall_height()\n [0, 0, 1]\n sage: b = Sq(4)*Sq(8) + Sq(8)*Sq(4)\n sage: b.wall_height()\n [0, 0, 1, 1]\n sage: Sq(0,0,3).wall_height()\n [1, 2, 2, 1]\n " from sage.rings.integer import Integer if self.parent()._generic: raise NotImplementedError('Wall height is not defined at odd primes') if ((self == 0) or (self == 1)): return [] result = [] deg = self.parent().degree_on_basis for r in self.milnor().support(): h = ([0] * (1 + deg(r))) i = 1 for x in r: if (x > 0): for j in range((1 + Integer(x).exact_log(2))): if (((2 ** j) & x) != 0): for k in range(j, (i + j)): h[k] += 1 i += 1 h.reverse() result = max(h, result) result.reverse() while (result and (result[(- 1)] == 0)): result = result[:(- 1)] return result def additive_order(self): '\n The additive order of any nonzero element of the mod p\n Steenrod algebra is p.\n\n OUTPUT: 1 (for the zero element) or p (for anything else)\n\n EXAMPLES::\n\n sage: z = Sq(4) + Sq(6) + 1\n sage: z.additive_order()\n 2\n sage: (Sq(3) + Sq(3)).additive_order()\n 1\n ' if (self == 0): return 1 return self.prime()
class SteenrodAlgebra_mod_two(SteenrodAlgebra_generic): '\n The mod 2 Steenrod algebra.\n\n Users should not call this, but use the function\n :func:`SteenrodAlgebra` instead. See that function for extensive\n documentation. (This differs from :class:`SteenrodAlgebra_generic`\n only in that it has a method :meth:`Sq` for defining elements.)\n ' def Sq(self, *nums): '\n Milnor element `\\text{Sq}(a,b,c,...)`.\n\n INPUT:\n\n - ``a, b, c, ...`` - non-negative integers\n\n OUTPUT: element of the Steenrod algebra\n\n This returns the Milnor basis element\n `\\text{Sq}(a, b, c, ...)`.\n\n EXAMPLES::\n\n sage: A = SteenrodAlgebra(2)\n sage: A.Sq(5)\n Sq(5)\n sage: A.Sq(5,0,2)\n Sq(5,0,2)\n\n Entries must be non-negative integers; otherwise, an error\n results.\n ' if (self.prime() == 2): return self.P(*nums) else: raise ValueError('Sq is only defined at the prime 2')
def SteenrodAlgebra(p=2, basis='milnor', generic='auto', **kwds): '\n The mod `p` Steenrod algebra\n\n INPUT:\n\n - ``p`` - positive prime integer (optional, default = 2)\n - ``basis`` - string (optional, default = \'milnor\')\n - ``profile`` - a profile function in form specified below (optional, default ``None``)\n - ``truncation_type`` - 0 or `\\infty` or \'auto\' (optional, default \'auto\')\n - ``precision`` - integer or ``None`` (optional, default ``None``)\n - ``generic`` - (optional, default \'auto\')\n\n OUTPUT:\n\n mod `p` Steenrod algebra or one of its sub-Hopf algebras,\n elements of which are printed using ``basis``\n\n See below for information about ``basis``, ``profile``, etc.\n\n EXAMPLES:\n\n Some properties of the Steenrod algebra are available::\n\n sage: A = SteenrodAlgebra(2)\n sage: A.order()\n +Infinity\n sage: A.is_finite()\n False\n sage: A.is_commutative()\n False\n sage: A.is_noetherian()\n False\n sage: A.is_integral_domain()\n False\n sage: A.is_field()\n False\n sage: A.is_division_algebra()\n False\n sage: A.category()\n Category of supercocommutative super Hopf algebras\n with basis over Finite Field of size 2\n\n There are methods for constructing elements of the Steenrod\n algebra::\n\n sage: A2 = SteenrodAlgebra(2); A2\n mod 2 Steenrod algebra, milnor basis\n sage: A2.Sq(1,2,6)\n Sq(1,2,6)\n sage: A2.Q(3,4) # product of Milnor primitives Q_3 and Q_4\n Sq(0,0,0,1,1)\n sage: A2.pst(2,3) # Margolis pst element\n Sq(0,0,4)\n sage: A5 = SteenrodAlgebra(5); A5\n mod 5 Steenrod algebra, milnor basis\n sage: A5.P(1,2,6)\n P(1,2,6)\n sage: A5.Q(3,4)\n Q_3 Q_4\n sage: A5.Q(3,4) * A5.P(1,2,6)\n Q_3 Q_4 P(1,2,6)\n sage: A5.pst(2,3)\n P(0,0,25)\n\n You can test whether elements are contained in the Steenrod\n algebra::\n\n sage: w = Sq(2) * Sq(4)\n sage: w in SteenrodAlgebra(2)\n True\n sage: w in SteenrodAlgebra(17)\n False\n\n .. rubric:: Different bases for the Steenrod algebra:\n\n There are two standard vector space bases for the mod `p` Steenrod\n algebra: the Milnor basis and the Serre-Cartan basis. When `p=2`,\n there are also several other, less well-known, bases. See the\n documentation for this module (type\n ``sage.algebras.steenrod.steenrod_algebra?``) and the function\n :func:`steenrod_algebra_basis\n <sage.algebras.steenrod.steenrod_algebra_bases.steenrod_algebra_basis_>`\n for full descriptions of each of the implemented bases.\n\n This module implements the following bases at all primes:\n\n - \'milnor\': Milnor basis.\n\n - \'serre-cartan\' or \'adem\' or \'admissible\': Serre-Cartan basis.\n\n - \'pst\', \'pst_rlex\', \'pst_llex\', \'pst_deg\', \'pst_revz\': various\n `P^s_t`-bases.\n\n - \'comm\', \'comm_rlex\', \'comm_llex\', \'comm_deg\', \'comm_revz\', or\n these with \'_long\' appended: various commutator bases.\n\n It implements the following bases when `p=2`:\n\n - \'wood_y\': Wood\'s Y basis.\n\n - \'wood_z\': Wood\'s Z basis.\n\n - \'wall\', \'wall_long\': Wall\'s basis.\n\n - \'arnon_a\', \'arnon_a_long\': Arnon\'s A basis.\n\n - \'arnon_c\': Arnon\'s C basis.\n\n When defining a Steenrod algebra, you can specify a basis. Then\n elements of that Steenrod algebra are printed in that basis::\n\n sage: adem = SteenrodAlgebra(2, \'adem\')\n sage: x = adem.Sq(2,1) # Sq(-) always means a Milnor basis element\n sage: x\n Sq^4 Sq^1 + Sq^5\n sage: y = Sq(0,1) # unadorned Sq defines elements w.r.t. Milnor basis\n sage: y\n Sq(0,1)\n sage: adem(y)\n Sq^2 Sq^1 + Sq^3\n sage: adem5 = SteenrodAlgebra(5, \'serre-cartan\')\n sage: adem5.P(0,2)\n P^10 P^2 + 4 P^11 P^1 + P^12\n\n If you add or multiply elements defined using different bases, the\n left-hand factor determines the form of the output::\n\n sage: SteenrodAlgebra(basis=\'adem\').Sq(3) + SteenrodAlgebra(basis=\'pst\').Sq(0,1)\n Sq^2 Sq^1\n sage: SteenrodAlgebra(basis=\'pst\').Sq(3) + SteenrodAlgebra(basis=\'milnor\').Sq(0,1)\n P^0_1 P^1_1 + P^0_2\n sage: SteenrodAlgebra(basis=\'milnor\').Sq(2) * SteenrodAlgebra(basis=\'arnonc\').Sq(2)\n Sq(1,1)\n\n You can get a list of basis elements in a given dimension::\n\n sage: A3 = SteenrodAlgebra(3, \'milnor\')\n sage: A3.basis(13)\n Family (Q_1 P(2), Q_0 P(3))\n\n Algebras defined over different bases are not equal::\n\n sage: SteenrodAlgebra(basis=\'milnor\') == SteenrodAlgebra(basis=\'pst\')\n False\n\n Bases have various synonyms, and in general Sage tries to figure\n out what basis you meant::\n\n sage: SteenrodAlgebra(basis=\'MiLNOr\')\n mod 2 Steenrod algebra, milnor basis\n sage: SteenrodAlgebra(basis=\'MiLNOr\') == SteenrodAlgebra(basis=\'milnor\')\n True\n sage: SteenrodAlgebra(basis=\'adem\')\n mod 2 Steenrod algebra, serre-cartan basis\n sage: SteenrodAlgebra(basis=\'adem\').basis_name()\n \'serre-cartan\'\n sage: SteenrodAlgebra(basis=\'wood---z---\').basis_name()\n \'woodz\'\n\n As noted above, several of the bases (\'arnon_a\', \'wall\', \'comm\')\n have alternate, sometimes longer, representations. These provide\n ways of expressing elements of the Steenrod algebra in terms of\n the `\\text{Sq}^{2^n}`.\n\n ::\n\n sage: A_long = SteenrodAlgebra(2, \'arnon_a_long\')\n sage: A_long(Sq(6))\n Sq^1 Sq^2 Sq^1 Sq^2 + Sq^2 Sq^4\n sage: SteenrodAlgebra(2, \'wall_long\')(Sq(6))\n Sq^2 Sq^1 Sq^2 Sq^1 + Sq^2 Sq^4\n sage: SteenrodAlgebra(2, \'comm_deg_long\')(Sq(6))\n s_1 s_2 s_12 + s_2 s_4\n\n .. rubric:: Sub-Hopf algebras of the Steenrod algebra:\n\n These are specified using the argument ``profile``, along with,\n optionally, ``truncation_type`` and ``precision``. The\n ``profile`` argument specifies the profile function for this\n algebra. Any sub-Hopf algebra of the Steenrod algebra is\n determined by its *profile function*. When `p=2`, this is a map `e`\n from the positive integers to the set of non-negative integers,\n plus `\\infty`, corresponding to the sub-Hopf algebra dual to this\n quotient of the dual Steenrod algebra:\n\n .. MATH::\n\n \\GF{2} [\\xi_1, \\xi_2, \\xi_3, ...] / (\\xi_1^{2^{e(1)}}, \\xi_2^{2^{e(2)}}, \\xi_3^{2^{e(3)}}, ...).\n\n The profile function `e` must satisfy the condition\n\n - `e(r) \\geq \\min( e(r-i) - i, e(i))` for all `0 < i < r`.\n\n This is specified via ``profile``, and optionally ``precision``\n and ``truncation_type``. First, ``profile`` must have one of the\n following forms:\n\n - a list or tuple, e.g., ``[3,2,1]``, corresponding to the\n function sending 1 to 3, 2 to 2, 3 to 1, and all other integers\n to the value of ``truncation_type``.\n - a function from positive integers to non-negative integers (and\n `\\infty`), e.g., ``lambda n: n+2``.\n - ``None`` or ``Infinity`` - use this for the profile function for\n the whole Steenrod algebra.\n\n In the first and third cases, ``precision`` is ignored. In the\n second case, this function is converted to a tuple of length one\n less than ``precision``, which has default value 100. The\n function is truncated at this point, and all remaining values are\n set to the value of ``truncation_type``.\n\n ``truncation_type`` may be 0, `\\infty`, or \'auto\'. If it\'s\n \'auto\', then it gets converted to 0 in the first case above (when\n ``profile`` is a list), and otherwise (when ``profile`` is a\n function, ``None``, or ``Infinity``) it gets converted to `\\infty`.\n\n For example, the sub-Hopf algebra `A(2)` has profile function\n ``[3,2,1,0,0,0,...]``, so it can be defined by any of the\n following::\n\n sage: A2 = SteenrodAlgebra(profile=[3,2,1])\n sage: B2 = SteenrodAlgebra(profile=[3,2,1,0,0]) # trailing 0\'s ignored\n sage: A2 == B2\n True\n sage: C2 = SteenrodAlgebra(profile=lambda n: max(4-n, 0), truncation_type=0)\n sage: A2 == C2\n True\n\n In the following case, the profile function is specified by a\n function and ``truncation_type`` isn\'t specified, so it defaults\n to `\\infty`; therefore this gives a different sub-Hopf algebra::\n\n sage: D2 = SteenrodAlgebra(profile=lambda n: max(4-n, 0))\n sage: A2 == D2\n False\n sage: D2.is_finite()\n False\n sage: E2 = SteenrodAlgebra(profile=lambda n: max(4-n, 0), truncation_type=Infinity)\n sage: D2 == E2\n True\n\n The argument ``precision`` only needs to be specified if the\n profile function is defined by a function and you want to control\n when the profile switches from the given function to the\n truncation type. For example::\n\n sage: D3 = SteenrodAlgebra(profile=lambda n: n, precision=3)\n sage: D3\n sub-Hopf algebra of mod 2 Steenrod algebra, milnor basis, profile function [1, 2, +Infinity, +Infinity, +Infinity, ...]\n sage: D4 = SteenrodAlgebra(profile=lambda n: n, precision=4); D4\n sub-Hopf algebra of mod 2 Steenrod algebra, milnor basis, profile function [1, 2, 3, +Infinity, +Infinity, +Infinity, ...]\n sage: D3 == D4\n False\n\n When `p` is odd, ``profile`` is a pair of functions `e` and `k`,\n corresponding to the quotient\n\n .. MATH::\n\n \\GF{p} [\\xi_1, \\xi_2, \\xi_3, ...] \\otimes \\Lambda (\\tau_0,\n \\tau_1, ...) / (\\xi_1^{p^{e_1}}, \\xi_2^{p^{e_2}}, ...;\n \\tau_0^{k_0}, \\tau_1^{k_1}, ...).\n\n Together, the functions `e` and `k` must satisfy the conditions\n\n - `e(r) \\geq \\min( e(r-i) - i, e(i))` for all `0 < i < r`,\n\n - if `k(i+j) = 1`, then either `e(i) \\leq j` or `k(j) = 1` for all `i\n \\geq 1`, `j \\geq 0`.\n\n Therefore ``profile`` must have one of the following forms:\n\n - a pair of lists or tuples, the second of which takes values in\n the set `\\{1,2\\}`, e.g., ``([3,2,1,1], [1,1,2,2,1])``.\n\n - a pair of functions, one from the positive integers to\n non-negative integers (and `\\infty`), one from the non-negative\n integers to the set `\\{1,2\\}`, e.g., ``(lambda n: n+2, lambda n:\n 1 if n<3 else 2)``.\n\n - ``None`` or ``Infinity`` - use this for the profile function for\n the whole Steenrod algebra.\n\n You can also mix and match the first two, passing a pair with\n first entry a list and second entry a function, for instance. The\n values of ``precision`` and ``truncation_type`` are determined by\n the first entry.\n\n More examples::\n\n sage: E = SteenrodAlgebra(profile=lambda n: 0 if n<3 else 3, truncation_type=0)\n sage: E.is_commutative()\n True\n\n sage: A2 = SteenrodAlgebra(profile=[3,2,1]) # the algebra A(2)\n sage: Sq(7,3,1) in A2\n True\n sage: Sq(8) in A2\n False\n sage: Sq(8) in SteenrodAlgebra().basis(8)\n True\n sage: Sq(8) in A2.basis(8)\n False\n sage: A2.basis(8)\n Family (Sq(1,0,1), Sq(2,2), Sq(5,1))\n\n sage: A5 = SteenrodAlgebra(p=5)\n sage: A51 = SteenrodAlgebra(p=5, profile=([1], [2,2]))\n sage: A5.Q(0,1) * A5.P(4) in A51\n True\n sage: A5.Q(2) in A51\n False\n sage: A5.P(5) in A51\n False\n\n For sub-Hopf algebras of the Steenrod algebra, only the Milnor\n basis or the various `P^s_t`-bases may be used. ::\n\n sage: SteenrodAlgebra(profile=[1,2,1,1], basis=\'adem\')\n Traceback (most recent call last):\n ...\n NotImplementedError: for sub-Hopf algebras of the Steenrod algebra, only the Milnor basis and the pst bases are implemented\n\n .. rubric:: The generic Steenrod algebra at the prime `2`:\n\n The structure formulas for the Steenrod algebra at odd primes `p` also make sense\n when `p` is set to `2`. We refer to the resulting algebra as the "generic Steenrod algebra" for\n the prime `2`. The dual Hopf algebra is given by\n\n .. MATH::\n\n A_* = \\GF{2} [\\xi_1, \\xi_2, \\xi_3, ...] \\otimes \\Lambda (\\tau_0, \\tau_1, ...)\n\n The degree of `\\xi_k` is `2^{k+1}-2` and the degree of `\\tau_k` is `2^{k+1}-1`.\n\n The generic Steenrod algebra is an associated graded algebra of the usual Steenrod algebra\n that is occasionally useful. Its cohomology, for example, is the `E_2`-term of a spectral sequence\n that computes the `E_2`-term of the Novikov spectral sequence. It can also be obtained as a\n specialisation of Voevodsky\'s "motivic Steenrod algebra": in the notation of [Voe2003]_, Remark 12.12,\n it corresponds to setting `\\rho = \\tau = 0`. The usual Steenrod algebra is given by `\\rho = 0`\n and `\\tau = 1`.\n\n In Sage this algebra is constructed using the \'generic\' keyword.\n\n Example::\n\n sage: EA = SteenrodAlgebra(p=2,generic=True) ; EA\n generic mod 2 Steenrod algebra, milnor basis\n sage: EA[8]\n Vector space spanned by (Q_0 Q_2, Q_0 Q_1 P(2), P(1,1), P(4))\n over Finite Field of size 2\n\n TESTS:\n\n Testing unique parents::\n\n sage: S0 = SteenrodAlgebra(2)\n sage: S1 = SteenrodAlgebra(2)\n sage: S0 is S1\n True\n sage: S2 = SteenrodAlgebra(2, basis=\'adem\')\n sage: S0 is S2\n False\n sage: S0 == S2\n False\n sage: A1 = SteenrodAlgebra(profile=[2,1])\n sage: B1 = SteenrodAlgebra(profile=[2,1,0,0])\n sage: A1 is B1\n True\n ' if (generic == 'auto'): generic = (p != 2) if (not generic): return SteenrodAlgebra_mod_two(p=2, basis=basis, **kwds) else: return SteenrodAlgebra_generic(p=p, basis=basis, generic=True, **kwds)
def AA(n=None, p=2): '\n This returns the Steenrod algebra `A` or its sub-Hopf algebra `A(n)`.\n\n INPUT:\n\n - `n` - non-negative integer, optional (default ``None``)\n - `p` - prime number, optional (default 2)\n\n OUTPUT:\n\n If `n` is ``None``, then return the full Steenrod algebra.\n Otherwise, return `A(n)`.\n\n When `p=2`, `A(n)` is the sub-Hopf algebra generated by the\n elements `\\text{Sq}^i` for `i \\leq 2^n`. Its profile function is\n `(n+1, n, n-1, ...)`. When `p` is odd, `A(n)` is the sub-Hopf\n algebra generated by the elements `Q_0` and `\\mathcal{P}^i` for `i\n \\leq p^{n-1}`. Its profile function is `e=(n, n-1, n-2, ...)`\n and `k=(2, 2, ..., 2)` (length `n+1`).\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra import AA as A\n sage: A()\n mod 2 Steenrod algebra, milnor basis\n sage: A(2)\n sub-Hopf algebra of mod 2 Steenrod algebra, milnor basis,\n profile function [3, 2, 1]\n sage: A(2, p=5)\n sub-Hopf algebra of mod 5 Steenrod algebra, milnor basis,\n profile function ([2, 1], [2, 2, 2])\n ' if (n is None): return SteenrodAlgebra(p=p) if (p == 2): return SteenrodAlgebra(p=p, profile=list(range((n + 1), 0, (- 1)))) return SteenrodAlgebra(p=p, profile=(list(range(n, 0, (- 1))), ([2] * (n + 1))))
def Sq(*nums): '\n Milnor element Sq(a,b,c,...).\n\n INPUT:\n\n - ``a, b, c, ...`` - non-negative integers\n\n OUTPUT: element of the Steenrod algebra\n\n This returns the Milnor basis element\n `\\text{Sq}(a, b, c, ...)`.\n\n EXAMPLES::\n\n sage: Sq(5)\n Sq(5)\n sage: Sq(5) + Sq(2,1) + Sq(5) # addition is mod 2:\n Sq(2,1)\n sage: (Sq(4,3) + Sq(7,2)).degree()\n 13\n\n Entries must be non-negative integers; otherwise, an error\n results.\n\n This function is a good way to define elements of the Steenrod\n algebra.\n ' return SteenrodAlgebra(p=2).Sq(*nums)
@cached_function def convert_to_milnor_matrix(n, basis, p=2, generic='auto'): "\n Change-of-basis matrix, 'basis' to Milnor, in dimension\n `n`, at the prime `p`.\n\n INPUT:\n\n - ``n`` -- non-negative integer, the dimension\n - ``basis`` -- string, the basis from which to convert\n - ``p`` -- positive prime number (optional, default 2)\n\n OUTPUT:\n\n ``matrix`` -- change-of-basis matrix, a square matrix over `\\GF{p}`\n\n EXAMPLES::\n\n sage: # needs sage.modules\n sage: from sage.algebras.steenrod.steenrod_algebra_bases import convert_to_milnor_matrix\n sage: convert_to_milnor_matrix(5, 'adem') # indirect doctest\n [0 1]\n [1 1]\n sage: convert_to_milnor_matrix(45, 'milnor')\n 111 x 111 dense matrix over Finite Field of size 2 (use the '.str()' method to see the entries)\n sage: convert_to_milnor_matrix(12, 'wall')\n [1 0 0 1 0 0 0]\n [1 1 0 0 0 1 0]\n [0 1 0 1 0 0 0]\n [0 0 0 1 0 0 0]\n [1 1 0 0 1 0 0]\n [0 0 1 1 1 0 1]\n [0 0 0 0 1 0 1]\n\n The function takes an optional argument, the prime `p` over\n which to work::\n\n sage: # needs sage.modules\n sage: convert_to_milnor_matrix(17, 'adem', 3)\n [0 0 1 1]\n [0 0 0 1]\n [1 1 1 1]\n [0 1 0 1]\n sage: convert_to_milnor_matrix(48, 'adem', 5)\n [0 1]\n [1 1]\n sage: convert_to_milnor_matrix(36, 'adem', 3)\n [0 0 1]\n [0 1 0]\n [1 2 0]\n " from sage.matrix.constructor import matrix from sage.rings.finite_rings.finite_field_constructor import GF from .steenrod_algebra import SteenrodAlgebra if (generic == 'auto'): generic = (p != 2) if (n == 0): return matrix(GF(p), 1, 1, [[1]]) milnor_base = steenrod_algebra_basis(n, 'milnor', p, generic=generic) rows = [] A = SteenrodAlgebra(basis=basis, p=p, generic=generic) for poly in A.basis(n): d = poly.milnor().monomial_coefficients() for v in milnor_base: entry = d.get(v, 0) rows = (rows + [entry]) d = len(milnor_base) return matrix(GF(p), d, d, rows)
def convert_from_milnor_matrix(n, basis, p=2, generic='auto'): "\n Change-of-basis matrix, Milnor to ``basis``, in dimension `n`.\n\n INPUT:\n\n - ``n`` -- non-negative integer, the dimension\n\n - ``basis`` -- string, the basis to which to convert\n\n - ``p`` -- positive prime number (optional, default 2)\n\n OUTPUT:\n\n ``matrix`` -- change-of-basis matrix, a square matrix over `\\GF{p}`\n\n .. note::\n\n This is called internally. It is not intended for casual\n users, so no error checking is made on the integer `n`, the\n basis name, or the prime.\n\n EXAMPLES::\n\n sage: # needs sage.modules\n sage: from sage.algebras.steenrod.steenrod_algebra_bases import convert_from_milnor_matrix, convert_to_milnor_matrix\n sage: convert_from_milnor_matrix(12, 'wall')\n [1 0 0 1 0 0 0]\n [0 0 1 1 0 0 0]\n [0 0 0 1 0 1 1]\n [0 0 0 1 0 0 0]\n [1 0 1 0 1 0 0]\n [1 1 1 0 0 0 0]\n [1 0 1 0 1 0 1]\n sage: convert_from_milnor_matrix(38, 'serre_cartan')\n 72 x 72 dense matrix over Finite Field of size 2 (use the '.str()' method to see the entries)\n sage: x = convert_to_milnor_matrix(20, 'wood_y')\n sage: y = convert_from_milnor_matrix(20, 'wood_y')\n sage: x*y\n [1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n [0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n [0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n [0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0]\n [0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0]\n [0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0]\n [0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0]\n [0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0]\n [0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0]\n [0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0]\n [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0]\n [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1]\n\n The function takes an optional argument, the prime `p` over\n which to work::\n\n sage: convert_from_milnor_matrix(17, 'adem', 3) # needs sage.modules\n [2 1 1 2]\n [0 2 0 1]\n [1 2 0 0]\n [0 1 0 0]\n " mat = convert_to_milnor_matrix(n, basis, p, generic) if (mat.nrows() != 0): return convert_to_milnor_matrix(n, basis, p, generic).inverse() else: return mat
@cached_function def steenrod_algebra_basis(n, basis='milnor', p=2, **kwds): "\n Basis for the Steenrod algebra in degree `n`.\n\n INPUT:\n\n - ``n`` -- non-negative integer\n - ``basis`` -- string, which basis to use (optional, default: ``'milnor'``)\n - ``p`` -- positive prime number (optional, default: 2)\n - ``profile`` -- profile function (optional, default: ``None``). This\n is just passed on to the functions :func:`milnor_basis` and\n :func:`pst_basis`.\n - ``truncation_type`` -- truncation type, either 0 or Infinity\n (optional, default Infinity if no profile function is specified,\n 0 otherwise). This is just passed on to the function\n :func:`milnor_basis`.\n - ``generic`` -- boolean (optional, default: ``None``)\n\n OUTPUT:\n\n Tuple of objects representing basis elements for the Steenrod algebra\n in dimension n.\n\n The choices for the string ``basis`` are as follows; see the\n documentation for :mod:`sage.algebras.steenrod.steenrod_algebra`\n for details on each basis:\n\n - ``'milnor'``: Milnor basis.\n - ``'serre-cartan'`` or ``'adem'`` or ``'admissible'``: Serre-Cartan basis.\n - ``'pst'``, ``'pst_rlex'``, ``'pst_llex'``, ``'pst_deg'``, ``'pst_revz'``:\n various `P^s_t`-bases.\n - ``'comm'``, ``'comm_rlex'``, ``'comm_llex'``, ``'comm_deg'``, ``'comm_revz'``, or\n any of these with ``'_long'`` appended: various commutator bases.\n\n The rest of these bases are only defined when `p=2`.\n\n - ``'wood_y'``: Wood's Y basis.\n - ``'wood_z'``: Wood's Z basis.\n - ``'wall'`` or ``'wall_long'``: Wall's basis.\n - ``'arnon_a'`` or ``'arnon_a_long'``: Arnon's A basis.\n - ``'arnon_c'``: Arnon's C basis.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_bases import steenrod_algebra_basis\n sage: steenrod_algebra_basis(7, 'milnor') # indirect doctest\n ((0, 0, 1), (1, 2), (4, 1), (7,))\n sage: steenrod_algebra_basis(5) # milnor basis is the default\n ((2, 1), (5,))\n\n Bases in negative dimensions are empty::\n\n sage: steenrod_algebra_basis(-2, 'wall')\n ()\n\n The third (optional) argument to 'steenrod_algebra_basis' is the\n prime p::\n\n sage: steenrod_algebra_basis(9, 'milnor', p=3)\n (((1,), (1,)), ((0,), (2,)))\n sage: steenrod_algebra_basis(9, 'milnor', 3)\n (((1,), (1,)), ((0,), (2,)))\n sage: steenrod_algebra_basis(17, 'milnor', 3)\n (((2,), ()), ((1,), (3,)), ((0,), (0, 1)), ((0,), (4,)))\n\n Other bases::\n\n sage: steenrod_algebra_basis(7, 'admissible')\n ((7,), (6, 1), (4, 2, 1), (5, 2))\n sage: steenrod_algebra_basis(13, 'admissible', p=3)\n ((1, 3, 0), (0, 3, 1))\n sage: steenrod_algebra_basis(5, 'wall')\n (((2, 2), (0, 0)), ((1, 1), (1, 0)))\n sage: steenrod_algebra_basis(5, 'wall_long')\n (((2, 2), (0, 0)), ((1, 1), (1, 0)))\n sage: steenrod_algebra_basis(5, 'pst-rlex')\n (((0, 1), (2, 1)), ((1, 1), (0, 2)))\n " from .steenrod_algebra_misc import get_basis_name try: if ((n < 0) or (int(n) != n)): return () except TypeError: return () generic = kwds.get('generic', (p != 2)) basis_name = get_basis_name(basis, p, generic=generic) if (basis_name.find('long') >= 0): basis_name = basis_name.rsplit('_', 1)[0] profile = kwds.get('profile', None) if ((profile is not None) and (profile != ()) and (profile != ((), ())) and (basis != 'milnor') and (basis.find('pst') == (- 1))): raise ValueError('Profile functions may only be used with the Milnor or pst bases') if (basis_name == 'milnor'): return milnor_basis(n, p, **kwds) elif (basis_name == 'serre-cartan'): return serre_cartan_basis(n, p, **kwds) elif (generic and ((basis_name.find('pst') >= 0) or (basis_name.find('comm') >= 0))): return atomic_basis_odd(n, basis_name, p, **kwds) elif ((not generic) and ((basis_name == 'woody') or (basis_name == 'woodz') or (basis_name == 'wall') or (basis_name == 'arnona') or (basis_name.find('pst') >= 0) or (basis_name.find('comm') >= 0))): return atomic_basis(n, basis_name, **kwds) elif ((not generic) and (basis == 'arnonc')): return arnonC_basis(n) else: raise ValueError(('Unknown basis: %s at the prime %s' % (basis, p)))
def restricted_partitions(n, l, no_repeats=False): "\n List of 'restricted' partitions of `n`: partitions with parts taken\n from list `l`.\n\n INPUT:\n\n - ``n`` -- non-negative integer\n - ``l`` -- list of positive integers\n - ``no_repeats`` -- boolean (optional, default: ``False``), if ``True``,\n only return partitions with no repeated parts\n\n OUTPUT: list of lists\n\n One could also use ``Partitions(n, parts_in=l)``, but this\n function may be faster. Also, while ``Partitions(n, parts_in=l,\n max_slope=-1)`` should in theory return the partitions of `n` with\n parts in ``l`` with no repetitions, the ``max_slope=-1`` argument\n is ignored, so it doesn't work. (At the moment, the\n ``no_repeats=True`` case is the only one used in the code.)\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_bases import restricted_partitions\n sage: restricted_partitions(10, [7,5,1])\n [[7, 1, 1, 1], [5, 5], [5, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]\n sage: restricted_partitions(10, [6,5,4,3,2,1], no_repeats=True)\n [[6, 4], [6, 3, 1], [5, 4, 1], [5, 3, 2], [4, 3, 2, 1]]\n sage: restricted_partitions(10, [6,4,2])\n [[6, 4], [6, 2, 2], [4, 4, 2], [4, 2, 2, 2], [2, 2, 2, 2, 2]]\n sage: restricted_partitions(10, [6,4,2], no_repeats=True)\n [[6, 4]]\n\n ``l`` may have repeated elements. If ``no_repeats`` is ``False``, this\n has no effect. If ``no_repeats`` is ``True``, and if the repeated\n elements appear consecutively in ``l``, then each element may be\n used only as many times as it appears in ``l``::\n\n sage: restricted_partitions(10, [6,4,2,2], no_repeats=True)\n [[6, 4], [6, 2, 2]]\n sage: restricted_partitions(10, [6,4,2,2,2], no_repeats=True)\n [[6, 4], [6, 2, 2], [4, 2, 2, 2]]\n\n (If the repeated elements don't appear consecutively, the results\n are likely meaningless, containing several partitions more than\n once, for example.)\n\n In the following examples, ``no_repeats`` is ``False``::\n\n sage: restricted_partitions(10, [6,4,2])\n [[6, 4], [6, 2, 2], [4, 4, 2], [4, 2, 2, 2], [2, 2, 2, 2, 2]]\n sage: restricted_partitions(10, [6,4,2,2,2])\n [[6, 4], [6, 2, 2], [4, 4, 2], [4, 2, 2, 2], [2, 2, 2, 2, 2]]\n sage: restricted_partitions(10, [6,4,4,4,2,2,2,2,2,2])\n [[6, 4], [6, 2, 2], [4, 4, 2], [4, 2, 2, 2], [2, 2, 2, 2, 2]]\n " if (n < 0): return [] elif (n == 0): return [[]] else: results = [] if no_repeats: index = 1 else: index = 0 old_i = 0 for i in l: if (old_i != i): for sigma in restricted_partitions((n - i), l[index:], no_repeats): results.append(([i] + sigma)) index += 1 old_i = i return results
def xi_degrees(n, p=2, reverse=True): "\n Decreasing list of degrees of the `\\xi_i`'s, starting in degree `n`.\n\n INPUT:\n\n - ``n`` -- integer\n - ``p`` -- prime number, optional (default: 2)\n - ``reverse`` -- bool, optional (default: ``True``)\n\n OUTPUT: ``list`` -- list of integers\n\n When `p=2`: decreasing list of the degrees of the `\\xi_i`'s with\n degree at most `n`.\n\n At odd primes: decreasing list of these degrees, each divided by\n `2(p-1)`.\n\n If ``reverse`` is ``False``, then return an increasing list rather\n than a decreasing one.\n\n EXAMPLES::\n\n sage: sage.algebras.steenrod.steenrod_algebra_bases.xi_degrees(17)\n [15, 7, 3, 1]\n sage: sage.algebras.steenrod.steenrod_algebra_bases.xi_degrees(17, reverse=False)\n [1, 3, 7, 15]\n sage: sage.algebras.steenrod.steenrod_algebra_bases.xi_degrees(17, p=3)\n [13, 4, 1]\n sage: sage.algebras.steenrod.steenrod_algebra_bases.xi_degrees(400, p=17)\n [307, 18, 1]\n " from sage.rings.integer import Integer if (n <= 0): return [] N = Integer(((n * (p - 1)) + 1)) l = [(((p ** d) - 1) // (p - 1)) for d in range(1, (N.exact_log(p) + 1))] if reverse: l.reverse() return l
def milnor_basis(n, p=2, **kwds): '\n Milnor basis in dimension `n` with profile function ``profile``.\n\n INPUT:\n\n - ``n`` -- non-negative integer\n\n - ``p`` -- positive prime number (optional, default 2)\n\n - ``profile`` - profile function (optional, default ``None``).\n Together with ``truncation_type``, specify the profile function\n to be used; ``None`` means the profile function for the entire\n Steenrod algebra. See\n :mod:`sage.algebras.steenrod.steenrod_algebra` and\n :func:`SteenrodAlgebra <sage.algebras.steenrod.steenrod_algebra.SteenrodAlgebra>`\n for information on profile functions.\n\n - ``truncation_type`` -- truncation type, either 0 or Infinity\n (optional, default Infinity if no profile function is specified,\n 0 otherwise)\n\n OUTPUT: tuple of mod `p` Milnor basis elements in dimension `n`\n\n At the prime 2, the Milnor basis consists of symbols of the form\n `\\text{Sq}(m_1, m_2, ..., m_t)`, where each\n `m_i` is a non-negative integer and if `t>1`, then\n `m_t \\neq 0`. At odd primes, it consists of symbols of the\n form `Q_{e_1} Q_{e_2} ... P(m_1, m_2, ..., m_t)`,\n where `0 \\leq e_1 < e_2 < ...`, each `m_i` is a\n non-negative integer, and if `t>1`, then\n `m_t \\neq 0`.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_bases import milnor_basis\n sage: milnor_basis(7)\n ((0, 0, 1), (1, 2), (4, 1), (7,))\n sage: milnor_basis(7, 2)\n ((0, 0, 1), (1, 2), (4, 1), (7,))\n sage: milnor_basis(4, 2)\n ((1, 1), (4,))\n sage: milnor_basis(4, 2, profile=[2,1])\n ((1, 1),)\n sage: milnor_basis(4, 2, profile=(), truncation_type=0)\n ()\n sage: milnor_basis(4, 2, profile=(), truncation_type=Infinity)\n ((1, 1), (4,))\n sage: milnor_basis(9, 3)\n (((1,), (1,)), ((0,), (2,)))\n sage: milnor_basis(17, 3)\n (((2,), ()), ((1,), (3,)), ((0,), (0, 1)), ((0,), (4,)))\n sage: milnor_basis(48, p=5)\n (((), (0, 1)), ((), (6,)))\n sage: len(milnor_basis(100,3))\n 13\n sage: len(milnor_basis(200,7))\n 0\n sage: len(milnor_basis(240,7))\n 3\n sage: len(milnor_basis(240,7, profile=((),()), truncation_type=Infinity))\n 3\n sage: len(milnor_basis(240,7, profile=((),()), truncation_type=0))\n 0\n ' generic = kwds.get('generic', (p != 2)) if (n == 0): if (not generic): return ((),) else: return (((), ()),) from sage.rings.infinity import Infinity from sage.combinat.integer_vector_weighted import WeightedIntegerVectors profile = kwds.get('profile', None) trunc = kwds.get('truncation_type', None) if (trunc is None): if (profile is not None): trunc = 0 else: trunc = Infinity result = [] if (not generic): for mono in WeightedIntegerVectors(n, xi_degrees(n, reverse=False)): exponents = list(mono) while (exponents and (exponents[(- 1)] == 0)): exponents.pop((- 1)) okay = True if ((profile is not None) and (len(profile) > 0)): for i in range(len(exponents)): if (((len(profile) > i) and (exponents[i] >= (2 ** profile[i]))) or ((len(profile) <= i) and (trunc < Infinity) and (exponents[i] >= (2 ** trunc)))): okay = False break else: okay = (trunc == Infinity) if okay: result.append(tuple(exponents)) else: for dim in range(((n // (2 * (p - 1))) + 1)): if (dim == 0): P_result = [[0]] else: P_result = [] for mono in WeightedIntegerVectors(dim, xi_degrees(dim, p=p, reverse=False)): p_mono = list(mono) while (p_mono and (p_mono[(- 1)] == 0)): p_mono.pop((- 1)) if p_mono: P_result.append(p_mono) for p_mono in P_result: deg = (n - ((2 * dim) * (p - 1))) q_degrees = ([(1 + ((2 * (p - 1)) * d)) for d in xi_degrees(int(((deg - 1) // (2 * (p - 1)))), p)] + [1]) q_degrees_decrease = q_degrees q_degrees.reverse() if ((deg % (2 * (p - 1))) <= len(q_degrees)): for sigma in restricted_partitions(deg, q_degrees_decrease, no_repeats=True): index = 0 q_mono = [] for q in q_degrees: if (q in sigma): q_mono.append(index) index += 1 okay = True if ((profile is not None) and ((len(profile[0]) > 0) or (len(profile[1]) > 0))): for i in q_mono: if (((len(profile[1]) > i) and (profile[1][i] == 1)) or ((len(profile[1]) <= i) and (trunc == 0))): okay = False break for i in range(len(p_mono)): if (okay and (((len(profile[0]) > i) and (p_mono[i] >= (p ** profile[0][i]))) or ((len(profile[0]) <= i) and (trunc < Infinity) and (p_mono[i] >= (p ** trunc))))): okay = False break else: okay = (trunc == Infinity) if okay: if (list(p_mono) == [0]): p_mono = [] result.append((tuple(q_mono), tuple(p_mono))) return tuple(result)
def serre_cartan_basis(n, p=2, bound=1, **kwds): "\n Serre-Cartan basis in dimension `n`.\n\n INPUT:\n\n - ``n`` -- non-negative integer\n - ``bound`` -- positive integer (optional)\n - ``prime`` -- positive prime number (optional, default 2)\n\n OUTPUT: tuple of mod `p` Serre-Cartan basis elements in dimension `n`\n\n The Serre-Cartan basis consists of 'admissible monomials in the\n Steenrod squares'. Thus at the prime 2, it consists of monomials\n `\\text{Sq}^{m_1} \\text{Sq}^{m_2} ... \\text{Sq}^{m_t}` with `m_i\n \\geq 2m_{i+1}` for each `i`. At odd primes, it consists of\n monomials `\\beta^{e_0} P^{s_1} \\beta^{e_1} P^{s_2} ... P^{s_k}\n \\beta^{e_k}` with each `e_i` either 0 or 1, `s_i \\geq p s_{i+1} +\n e_i` for all `i`, and `s_k \\geq 1`.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_bases import serre_cartan_basis\n sage: serre_cartan_basis(7)\n ((7,), (6, 1), (4, 2, 1), (5, 2))\n sage: serre_cartan_basis(13,3)\n ((1, 3, 0), (0, 3, 1))\n sage: serre_cartan_basis(50,5)\n ((1, 5, 0, 1, 1), (1, 6, 1))\n\n If optional argument ``bound`` is present, include only those monomials\n whose last term is at least ``bound`` (when `p=2`), or those for which\n `s_k - e_k \\geq bound` (when `p` is odd). ::\n\n sage: serre_cartan_basis(7, bound=2)\n ((7,), (5, 2))\n sage: serre_cartan_basis(13, 3, bound=3)\n ((1, 3, 0),)\n " generic = kwds.get('generic', (p != 2)) if (n == 0): return ((),) elif (not generic): result = [(n,)] for last in range(bound, (1 + (n // 3))): for vec in serre_cartan_basis((n - last), bound=(2 * last)): new = (vec + (last,)) result.append(new) else: if (((n % (2 * (p - 1))) == 0) and ((n // (2 * (p - 1))) >= bound)): result = [(0, int((n // (2 * (p - 1)))), 0)] elif (n == 1): result = [(1,)] else: result = [] for last in range(bound, (1 + (n // (2 * (p - 1))))): if ((n - ((2 * (p - 1)) * last)) > 0): for vec in serre_cartan_basis((n - ((2 * (p - 1)) * last)), p, (p * last), generic=generic): result.append((vec + (last, 0))) if (bound == 1): bound = 0 for last in range((bound + 1), (1 + (n // (2 * (p - 1))))): basis = serre_cartan_basis(((n - ((2 * (p - 1)) * last)) - 1), p, (p * last), generic=generic) for vec in basis: if (vec == ()): vec = (0,) new = (vec + (last, 1)) result.append(new) return tuple(result)
def atomic_basis(n, basis, **kwds): "\n Basis for dimension `n` made of elements in 'atomic' degrees:\n degrees of the form `2^i (2^j - 1)`.\n\n This works at the prime 2 only.\n\n INPUT:\n\n - ``n`` -- non-negative integer\n\n - ``basis`` -- string, the name of the basis\n\n - ``profile`` -- profile function (optional, default: ``None``).\n Together with ``truncation_type``, specify the profile function\n to be used; ``None`` means the profile function for the entire\n Steenrod algebra. See\n :mod:`sage.algebras.steenrod.steenrod_algebra` and\n :func:`SteenrodAlgebra` for information on profile functions.\n\n - ``truncation_type`` -- truncation type, either 0 or Infinity\n (optional, default Infinity if no profile function is specified,\n 0 otherwise).\n\n OUTPUT: tuple of basis elements in dimension `n`\n\n The atomic bases include Wood's Y and Z bases, Wall's basis,\n Arnon's A basis, the `P^s_t`-bases, and the commutator\n bases. (All of these bases are constructed similarly, hence their\n constructions have been consolidated into a single function. Also,\n see the documentation for :func:`steenrod_algebra_basis` for\n descriptions of them.) For `P^s_t`-bases, you may also specify a\n profile function and truncation type; profile functions are ignored\n for the other bases.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_bases import atomic_basis\n sage: atomic_basis(6,'woody')\n (((1, 0), (0, 1), (0, 0)), ((2, 0), (1, 0)), ((1, 1),))\n sage: atomic_basis(8,'woodz')\n (((2, 0), (0, 1), (0, 0)), ((0, 2), (0, 0)), ((1, 1), (1, 0)), ((3, 0),))\n sage: atomic_basis(6,'woodz') == atomic_basis(6, 'woody')\n True\n sage: atomic_basis(9,'woodz') == atomic_basis(9, 'woody')\n False\n\n Wall's basis::\n\n sage: atomic_basis(8,'wall')\n (((2, 2), (1, 0), (0, 0)), ((2, 0), (0, 0)), ((2, 1), (1, 1)), ((3, 3),))\n\n Arnon's A basis::\n\n sage: atomic_basis(7,'arnona')\n (((0, 0), (1, 1), (2, 2)), ((0, 0), (2, 1)), ((1, 0), (2, 2)), ((2, 0),))\n\n `P^s_t`-bases::\n\n sage: atomic_basis(7,'pst_rlex')\n (((0, 1), (1, 1), (2, 1)), ((0, 1), (1, 2)), ((2, 1), (0, 2)), ((0, 3),))\n sage: atomic_basis(7,'pst_llex')\n (((0, 1), (1, 1), (2, 1)), ((0, 1), (1, 2)), ((0, 2), (2, 1)), ((0, 3),))\n sage: atomic_basis(7,'pst_deg')\n (((0, 1), (1, 1), (2, 1)), ((0, 1), (1, 2)), ((0, 2), (2, 1)), ((0, 3),))\n sage: atomic_basis(7,'pst_revz')\n (((0, 1), (1, 1), (2, 1)), ((0, 1), (1, 2)), ((0, 2), (2, 1)), ((0, 3),))\n\n Commutator bases::\n\n sage: atomic_basis(7,'comm_rlex')\n (((0, 1), (1, 1), (2, 1)), ((0, 1), (1, 2)), ((2, 1), (0, 2)), ((0, 3),))\n sage: atomic_basis(7,'comm_llex')\n (((0, 1), (1, 1), (2, 1)), ((0, 1), (1, 2)), ((0, 2), (2, 1)), ((0, 3),))\n sage: atomic_basis(7,'comm_deg')\n (((0, 1), (1, 1), (2, 1)), ((0, 1), (1, 2)), ((0, 2), (2, 1)), ((0, 3),))\n sage: atomic_basis(7,'comm_revz')\n (((0, 1), (1, 1), (2, 1)), ((0, 1), (1, 2)), ((0, 2), (2, 1)), ((0, 3),))\n " def degree_dictionary(n, basis): '\n Dictionary of atomic degrees for basis up to degree `n`.\n\n The keys for the dictionary are the atomic degrees -- the numbers of\n the form `2^i (2^j - 1)` -- which are less than or equal to `n`. The value\n associated to such a degree depends on basis; it has the form\n `(s,t)`, where `(s,t)` is a pair of integers which indexes the\n corresponding element.\n ' dict = {} if (basis.find('wood') >= 0): k = 0 m = 0 deg = ((2 ** m) * ((2 ** (k + 1)) - 1)) while (deg <= n): dict[deg] = (m, k) if (m > 0): m = (m - 1) k = (k + 1) else: m = (k + 1) k = 0 deg = ((2 ** m) * ((2 ** (k + 1)) - 1)) elif ((basis.find('wall') >= 0) or (basis.find('arnon') >= 0)): k = 0 m = 0 deg = ((2 ** k) * ((2 ** ((m - k) + 1)) - 1)) while (deg <= n): dict[deg] = (m, k) if (k == 0): m = (m + 1) k = m else: k = (k - 1) deg = ((2 ** k) * ((2 ** ((m - k) + 1)) - 1)) elif ((basis.find('pst') >= 0) or (basis.find('comm') >= 0)): s = 0 t = 1 deg = ((2 ** s) * ((2 ** t) - 1)) while (deg <= n): if (basis.find('pst') >= 0): dict[deg] = (s, t) else: dict[deg] = (s, t) if (s == 0): s = t t = 1 else: s = (s - 1) t = (t + 1) deg = ((2 ** s) * ((2 ** t) - 1)) return dict def sorting_pair(s, t, basis): if ((basis.find('wood') >= 0) and (basis.find('z') >= 0)): return (((- s) - t), (- s)) elif ((basis.find('wood') >= 0) or (basis.find('wall') >= 0) or (basis.find('arnon') >= 0)): return ((- s), (- t)) elif (basis.find('rlex') >= 0): return (t, s) elif (basis.find('llex') >= 0): return (s, t) elif (basis.find('deg') >= 0): return ((s + t), t) elif (basis.find('revz') >= 0): return ((s + t), s) from sage.rings.infinity import Infinity profile = kwds.get('profile', None) trunc = kwds.get('truncation_type', None) if ((profile is not None) and (trunc is None)): trunc = 0 if (n == 0): return ((),) else: result = [] degrees_etc = degree_dictionary(n, basis) degrees = list(degrees_etc) for sigma in restricted_partitions(n, degrees, no_repeats=True): big_list = [degrees_etc[part] for part in sigma] big_list.sort(key=(lambda x: sorting_pair(x[0], x[1], basis))) if (basis.find('arnon') >= 0): big_list.reverse() okay = True if (basis.find('pst') >= 0): if ((profile is not None) and (len(profile) > 0)): for (s, t) in big_list: if (((len(profile) > (t - 1)) and (profile[(t - 1)] <= s)) or ((len(profile) <= (t - 1)) and (trunc < Infinity))): okay = False break if okay: result.append(tuple(big_list)) return tuple(result)
@cached_function def arnonC_basis(n, bound=1): "\n Arnon's C basis in dimension `n`.\n\n INPUT:\n\n - ``n`` -- non-negative integer\n\n - ``bound`` -- positive integer (optional)\n\n OUTPUT: tuple of basis elements in dimension `n`\n\n The elements of Arnon's C basis are monomials of the form\n `\\text{Sq}^{t_1} ... \\text{Sq}^{t_m}` where for each\n `i`, we have `t_i \\leq 2t_{i+1}` and\n `2^i | t_{m-i}`.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_bases import arnonC_basis\n sage: arnonC_basis(7)\n ((7,), (2, 5), (4, 3), (4, 2, 1))\n\n If optional argument ``bound`` is present, include only those monomials\n whose first term is at least as large as ``bound``::\n\n sage: arnonC_basis(7,3)\n ((7,), (4, 3), (4, 2, 1))\n " if (n == 0): return ((),) else: result = [(n,)] for first in range(bound, (1 + ((2 * n) // 3))): for vec in arnonC_basis((n - first), max((first // 2), 1)): if ((first % (2 ** len(vec))) == 0): result.append(((first,) + vec)) return tuple(result)
def atomic_basis_odd(n, basis, p, **kwds): "\n `P^s_t`-bases and commutator basis in dimension `n` at odd primes.\n\n This function is called ``atomic_basis_odd`` in analogy with\n :func:`atomic_basis`.\n\n INPUT:\n\n - ``n`` -- non-negative integer\n\n - ``basis`` -- string, the name of the basis\n\n - ``p`` -- positive prime number\n\n - ``profile`` -- profile function (optional, default: ``None``).\n Together with ``truncation_type``, specify the profile function\n to be used; ``None`` means the profile function for the entire\n Steenrod algebra. See\n :mod:`sage.algebras.steenrod.steenrod_algebra` and\n :func:`SteenrodAlgebra` for information on profile functions.\n\n - ``truncation_type`` -- truncation type, either 0 or Infinity\n (optional, default Infinity if no profile function is specified,\n 0 otherwise).\n\n OUTPUT: tuple of basis elements in dimension `n`\n\n The only possible difference in the implementations for `P^s_t`\n bases and commutator bases is that the former make sense, and\n require filtering, if there is a nontrivial profile function.\n This function is called by :func:`steenrod_algebra_basis`, and it\n will not be called for commutator bases if there is a profile\n function, so we treat the two bases exactly the same.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_bases import atomic_basis_odd\n sage: atomic_basis_odd(8, 'pst_rlex', 3)\n (((), (((0, 1), 2),)),)\n\n sage: atomic_basis_odd(18, 'pst_rlex', 3)\n (((0, 2), ()), ((0, 1), (((1, 1), 1),)))\n sage: atomic_basis_odd(18, 'pst_rlex', 3, profile=((), (2,2,2)))\n (((0, 2), ()),)\n " def sorting_pair(s, t, basis): if (basis.find('rlex') >= 0): return (t, s) elif (basis.find('llex') >= 0): return (s, t) elif (basis.find('deg') >= 0): return ((s + t), t) elif (basis.find('revz') >= 0): return ((s + t), s) generic = kwds.get('generic', (p != 2)) if (n == 0): if (not generic): return ((),) else: return (((), ()),) from sage.rings.integer import Integer from sage.rings.infinity import Infinity from sage.combinat.integer_vector_weighted import WeightedIntegerVectors profile = kwds.get('profile', None) trunc = kwds.get('truncation_type', 0) result = [] for dim in range(((n // ((2 * p) - 2)) + 1)): P_result = [] for v in WeightedIntegerVectors(dim, xi_degrees(dim, p=p, reverse=False)): mono = [] for (t, a) in enumerate(v): for (s, pow) in enumerate(Integer(a).digits(p)): if (pow > 0): mono.append(((s, (t + 1)), pow)) P_result.append(mono) for p_mono in P_result: p_mono.sort(key=(lambda x: sorting_pair(x[0][0], x[0][1], basis))) deg = (n - ((2 * dim) * (p - 1))) q_degrees = ([(1 + ((2 * (p - 1)) * d)) for d in xi_degrees(((deg - 1) // (2 * (p - 1))), p)] + [1]) q_degrees_decrease = q_degrees q_degrees.reverse() if ((deg % (2 * (p - 1))) <= len(q_degrees)): for sigma in restricted_partitions(deg, q_degrees_decrease, no_repeats=True): q_mono = [index for (index, q) in enumerate(q_degrees) if (q in sigma)] okay = True if ((profile is not None) and (profile != ((), ()))): for i in q_mono: if (((len(profile[1]) > i) and (profile[1][i] == 1)) or ((len(profile[1]) <= i) and (trunc == 0))): okay = False break for ((s, t), _) in p_mono: if (((len(profile[0]) > (t - 1)) and (profile[0][(t - 1)] <= s)) or ((len(profile[0]) <= (t - 1)) and (trunc < Infinity))): okay = False break if okay: if (list(p_mono) == [0]): p_mono = [] result.append((tuple(q_mono), tuple(p_mono))) return tuple(result)
def steenrod_basis_error_check(dim, p, **kwds): '\n This performs crude error checking.\n\n INPUT:\n\n - ``dim`` -- non-negative integer\n - ``p`` -- positive prime number\n\n OUTPUT: None\n\n This checks to see if the different bases have the same length, and\n if the change-of-basis matrices are invertible. If something goes\n wrong, an error message is printed.\n\n This function checks at the prime `p` as the dimension goes up\n from 0 to ``dim``.\n\n If you set the Sage verbosity level to a positive integer (using\n ``set_verbose(n)``), then some extra messages will be printed.\n\n EXAMPLES::\n\n sage: # long time\n sage: from sage.algebras.steenrod.steenrod_algebra_bases import steenrod_basis_error_check\n sage: steenrod_basis_error_check(15, 2)\n sage: steenrod_basis_error_check(15, 2, generic=True)\n sage: steenrod_basis_error_check(40, 3)\n sage: steenrod_basis_error_check(80, 5)\n ' from sage.misc.verbose import verbose generic = kwds.get('generic', (p != 2)) if (not generic): bases = ('adem', 'woody', 'woodz', 'wall', 'arnona', 'arnonc', 'pst_rlex', 'pst_llex', 'pst_deg', 'pst_revz', 'comm_rlex', 'comm_llex', 'comm_deg', 'comm_revz') else: bases = ('adem', 'pst_rlex', 'pst_llex', 'pst_deg', 'pst_revz', 'comm_rlex', 'comm_llex', 'comm_deg', 'comm_revz') for i in range(dim): if ((i % 5) == 0): verbose(('up to dimension %s' % i)) milnor_dim = len(steenrod_algebra_basis.f(i, 'milnor', p=p, generic=generic)) for B in bases: if (milnor_dim != len(steenrod_algebra_basis.f(i, B, p, generic=generic))): print('problem with milnor/{} in dimension {}'.format(B, i)) mat = convert_to_milnor_matrix.f(i, B, p, generic=generic) if ((mat.nrows() != 0) and (not mat.is_invertible())): print(('%s invertibility problem in dim %s at p=%s' % (B, i, p))) verbose('done checking, no profiles') bases = ('pst_rlex', 'pst_llex', 'pst_deg', 'pst_revz') if (not generic): profiles = [(4, 3, 2, 1), (2, 2, 3, 1, 1), (0, 0, 0, 2)] else: profiles = [((3, 2, 1), ()), ((), (2, 1, 2)), ((3, 2, 1), (2, 2, 2, 2))] for i in range(dim): if ((i % 5) == 0): verbose(('up to dimension %s' % i)) for pro in profiles: milnor_dim = len(steenrod_algebra_basis.f(i, 'milnor', p=p, profile=pro, generic=generic)) for B in bases: if (milnor_dim != len(steenrod_algebra_basis.f(i, B, p, profile=pro, generic=generic))): print(('problem with milnor/%s in dimension %s with profile %s' % (B, i, pro))) verbose('done checking with profiles')
def get_basis_name(basis, p, generic=None): "\n Return canonical basis named by string basis at the prime p.\n\n INPUT:\n\n - ``basis`` - string\n\n - ``p`` - positive prime number\n\n - ``generic`` - boolean, optional, default to 'None'\n\n OUTPUT:\n\n - ``basis_name`` - string\n\n Specify the names of the implemented bases. The input is\n converted to lower-case, then processed to return the canonical\n name for the basis.\n\n For the Milnor and Serre-Cartan bases, use the list of synonyms\n defined by the variables :data:`_steenrod_milnor_basis_names` and\n :data:`_steenrod_serre_cartan_basis_names`. Their canonical names\n are 'milnor' and 'serre-cartan', respectively.\n\n For the other bases, use pattern-matching rather than a list of\n synonyms:\n\n - Search for 'wood' and 'y' or 'wood' and 'z' to get the Wood\n bases. Canonical names 'woody', 'woodz'.\n\n - Search for 'arnon' and 'c' for the Arnon C basis. Canonical\n name: 'arnonc'.\n\n - Search for 'arnon' (and no 'c') for the Arnon A basis. Also see\n if 'long' is present, for the long form of the basis. Canonical\n names: 'arnona', 'arnona_long'.\n\n - Search for 'wall' for the Wall basis. Also see if 'long' is\n present. Canonical names: 'wall', 'wall_long'.\n\n - Search for 'pst' for P^s_t bases, then search for the order\n type: 'rlex', 'llex', 'deg', 'revz'. Canonical names:\n 'pst_rlex', 'pst_llex', 'pst_deg', 'pst_revz'.\n\n - For commutator types, search for 'comm', an order type, and also\n check to see if 'long' is present. Canonical names:\n 'comm_rlex', 'comm_llex', 'comm_deg', 'comm_revz',\n 'comm_rlex_long', 'comm_llex_long', 'comm_deg_long',\n 'comm_revz_long'.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import get_basis_name\n sage: get_basis_name('adem', 2)\n 'serre-cartan'\n sage: get_basis_name('milnor', 2)\n 'milnor'\n sage: get_basis_name('MiLNoR', 5)\n 'milnor'\n sage: get_basis_name('pst-llex', 2)\n 'pst_llex'\n sage: get_basis_name('wood_abcdedfg_y', 2)\n 'woody'\n sage: get_basis_name('wood', 2)\n Traceback (most recent call last):\n ...\n ValueError: wood is not a recognized basis at the prime 2\n sage: get_basis_name('arnon--hello--long', 2)\n 'arnona_long'\n sage: get_basis_name('arnona_long', p=5)\n Traceback (most recent call last):\n ...\n ValueError: arnona_long is not a recognized basis at the prime 5\n sage: get_basis_name('NOT_A_BASIS', 2)\n Traceback (most recent call last):\n ...\n ValueError: not_a_basis is not a recognized basis at the prime 2\n sage: get_basis_name('woody', 2, generic=True)\n Traceback (most recent call last):\n ...\n ValueError: woody is not a recognized basis for the generic Steenrod algebra at the prime 2\n " if (generic is None): generic = (p != 2) basis = basis.lower() if (basis in _steenrod_milnor_basis_names): result = 'milnor' elif (basis in _steenrod_serre_cartan_basis_names): result = 'serre-cartan' elif (basis.find('pst') >= 0): if (basis.find('rlex') >= 0): result = 'pst_rlex' elif (basis.find('llex') >= 0): result = 'pst_llex' elif (basis.find('deg') >= 0): result = 'pst_deg' elif (basis.find('revz') >= 0): result = 'pst_revz' else: result = 'pst_revz' elif (basis.find('comm') >= 0): if (basis.find('rlex') >= 0): result = 'comm_rlex' elif (basis.find('llex') >= 0): result = 'comm_llex' elif (basis.find('deg') >= 0): result = 'comm_deg' elif (basis.find('revz') >= 0): result = 'comm_revz' else: result = 'comm_revz' if (basis.find('long') >= 0): result = (result + '_long') elif ((not generic) and (basis.find('wood') >= 0)): if (basis.find('y') >= 0): result = 'woody' elif (basis.find('z') >= 0): result = 'woodz' else: raise ValueError(('%s is not a recognized basis at the prime %s' % (basis, p))) elif ((not generic) and (basis.find('arnon') >= 0)): if (basis.find('c') >= 0): result = 'arnonc' else: result = 'arnona' if (basis.find('long') >= 0): result = (result + '_long') elif ((not generic) and (basis.find('wall') >= 0)): result = 'wall' if (basis.find('long') >= 0): result = (result + '_long') else: gencase = (' for the generic Steenrod algebra' if ((p == 2) and generic) else '') raise ValueError(('%s is not a recognized basis%s at the prime %s' % (basis, gencase, p))) return result
def is_valid_profile(profile, truncation_type, p=2, generic=None): '\n True if ``profile``, together with ``truncation_type``, is a valid\n profile at the prime `p`.\n\n INPUT:\n\n - ``profile`` - when `p=2`, a tuple or list of numbers; when `p`\n is odd, a pair of such lists\n\n - ``truncation_type`` - either 0 or `\\infty`\n\n - `p` - prime number, optional, default 2\n\n - `generic` - boolean, optional, default None\n\n OUTPUT: True if the profile function is valid, False otherwise.\n\n See the documentation for :mod:`sage.algebras.steenrod.steenrod_algebra`\n for descriptions of profile functions and how they correspond to\n sub-Hopf algebras of the Steenrod algebra. Briefly: at the prime\n 2, a profile function `e` is valid if it satisfies the condition\n\n - `e(r) \\geq \\min( e(r-i) - i, e(i))` for all `0 < i < r`.\n\n At odd primes, a pair of profile functions `e` and `k` are valid\n if they satisfy\n\n - `e(r) \\geq \\min( e(r-i) - i, e(i))` for all `0 < i < r`.\n\n - if `k(i+j) = 1`, then either `e(i) \\leq j` or `k(j) = 1` for all\n `i \\geq 1`, `j \\geq 0`.\n\n In this function, profile functions are lists or tuples, and\n ``truncation_type`` is appended as the last element of the list\n `e` before testing.\n\n EXAMPLES:\n\n `p=2`::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import is_valid_profile\n sage: is_valid_profile([3,2,1], 0)\n True\n sage: is_valid_profile([3,2,1], Infinity)\n True\n sage: is_valid_profile([1,2,3], 0)\n False\n sage: is_valid_profile([6,2,0], Infinity)\n False\n sage: is_valid_profile([0,3], 0)\n False\n sage: is_valid_profile([0,0,4], 0)\n False\n sage: is_valid_profile([0,0,0,4,0], 0)\n True\n\n Odd primes::\n\n sage: is_valid_profile(([0,0,0], [2,1,1,1,2,2]), 0, p=3)\n True\n sage: is_valid_profile(([1], [2,2]), 0, p=3)\n True\n sage: is_valid_profile(([1], [2]), 0, p=7)\n False\n sage: is_valid_profile(([1,2,1], []), 0, p=7)\n True\n sage: is_valid_profile(([0,0,0], [2,1,1,1,2,2]), 0, p=2, generic=True)\n True\n ' from sage.rings.infinity import Infinity if (generic is None): generic = (p != 2) if (not generic): pro = (list(profile) + ([truncation_type] * len(profile))) r = 0 for pro_r in pro: r += 1 if (pro_r < Infinity): for i in range(1, r): if (pro_r < min((pro[((r - i) - 1)] - i), pro[(i - 1)])): return False else: e = (list(profile[0]) + ([truncation_type] * len(profile[0]))) k = list(profile[1]) if (not set(k).issubset({1, 2})): return False if (truncation_type > 0): k = (k + [2]) else: k = (k + ([1] * len(profile[0]))) if (len(k) > len(e)): e = (e + ([truncation_type] * (len(k) - len(e)))) r = 0 for e_r in e: r += 1 if (e_r < Infinity): for i in range(1, r): if (e_r < min((e[((r - i) - 1)] - i), e[(i - 1)])): return False r = (- 1) for k_r in k: r += 1 if (k_r == 1): for j in range(r): i = (r - j) if ((e[(i - 1)] > j) and (k[j] == 2)): return False return True
def normalize_profile(profile, precision=None, truncation_type='auto', p=2, generic=None): '\n Given a profile function and related data, return it in a standard form,\n suitable for hashing and caching as data defining a sub-Hopf\n algebra of the Steenrod algebra.\n\n INPUT:\n\n - ``profile`` - a profile function in form specified below\n - ``precision`` - integer or ``None``, optional, default ``None``\n - ``truncation_type`` - 0 or `\\infty` or \'auto\', optional, default \'auto\'\n - `p` - prime, optional, default 2\n - `generic` - boolean, optional, default ``None``\n\n OUTPUT:\n\n a triple ``profile, precision, truncation_type``, in\n standard form as described below.\n\n The "standard form" is as follows: ``profile`` should be a tuple\n of integers (or `\\infty`) with no trailing zeroes when `p=2`, or a\n pair of such when `p` is odd or `generic` is ``True``. ``precision``\n should be a positive integer. ``truncation_type`` should be 0 or `\\infty`.\n Furthermore, this must be a valid profile, as determined by the\n function :func:`is_valid_profile`. See also the documentation for\n the module :mod:`sage.algebras.steenrod.steenrod_algebra` for information\n about profile functions.\n\n For the inputs: when `p=2`, ``profile`` should be a valid profile\n function, and it may be entered in any of the following forms:\n\n - a list or tuple, e.g., ``[3,2,1,1]``\n - a function from positive integers to non-negative integers (and\n `\\infty`), e.g., ``lambda n: n+2``. This corresponds to the\n list ``[3, 4, 5, ...]``.\n - ``None`` or ``Infinity`` - use this for the profile function for\n the whole Steenrod algebra. This corresponds to the list\n ``[Infinity, Infinity, Infinity, ...]``\n\n To make this hashable, it gets turned into a tuple. In the first\n case it is clear how to do this; also in this case, ``precision``\n is set to be one more than the length of this tuple. In the\n second case, construct a tuple of length one less than\n ``precision`` (default value 100). In the last case, the empty\n tuple is returned and ``precision`` is set to 1.\n\n Once a sub-Hopf algebra of the Steenrod algebra has been defined\n using such a profile function, if the code requires any remaining\n terms (say, terms after the 100th), then they are given by\n ``truncation_type`` if that is 0 or `\\infty`. If\n ``truncation_type`` is \'auto\', then in the case of a tuple, it\n gets set to 0, while for the other cases it gets set to `\\infty`.\n\n See the examples below.\n\n When `p` is odd, ``profile`` is a pair of "functions", so it may\n have the following forms:\n\n - a pair of lists or tuples, the second of which takes values in\n the set `\\{1,2\\}`, e.g., ``([3,2,1,1], [1,1,2,2,1])``.\n\n - a pair of functions, one (called `e`) from positive integers to\n non-negative integers (and `\\infty`), one (called `k`) from\n non-negative integers to the set `\\{1,2\\}`, e.g.,\n ``(lambda n: n+2, lambda n: 1)``. This corresponds to the\n pair ``([3, 4, 5, ...], [1, 1, 1, ...])``.\n\n - ``None`` or ``Infinity`` - use this for the profile function for\n the whole Steenrod algebra. This corresponds to the pair\n ``([Infinity, Infinity, Infinity, ...], [2, 2, 2, ...])``.\n\n You can also mix and match the first two, passing a pair with\n first entry a list and second entry a function, for instance. The\n values of ``precision`` and ``truncation_type`` are determined by\n the first entry.\n\n EXAMPLES:\n\n `p=2`::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import normalize_profile\n sage: normalize_profile([1,2,1,0,0])\n ((1, 2, 1), 0)\n\n The full mod 2 Steenrod algebra::\n\n sage: normalize_profile(Infinity)\n ((), +Infinity)\n sage: normalize_profile(None)\n ((), +Infinity)\n sage: normalize_profile(lambda n: Infinity)\n ((), +Infinity)\n\n The ``precision`` argument has no effect when the first argument\n is a list or tuple::\n\n sage: normalize_profile([1,2,1,0,0], precision=12)\n ((1, 2, 1), 0)\n\n If the first argument is a function, then construct a list of\n length one less than ``precision``, by plugging in the numbers 1,\n 2, ..., ``precision`` - 1::\n\n sage: normalize_profile(lambda n: 4-n, precision=4)\n ((3, 2, 1), +Infinity)\n sage: normalize_profile(lambda n: 4-n, precision=4, truncation_type=0)\n ((3, 2, 1), 0)\n\n Negative numbers in profile functions are turned into zeroes::\n\n sage: normalize_profile(lambda n: 4-n, precision=6)\n ((3, 2, 1, 0, 0), +Infinity)\n\n If it doesn\'t give a valid profile, an error is raised::\n\n sage: normalize_profile(lambda n: 3, precision=4, truncation_type=0)\n Traceback (most recent call last):\n ...\n ValueError: Invalid profile\n sage: normalize_profile(lambda n: 3, precision=4, truncation_type = Infinity)\n ((3, 3, 3), +Infinity)\n\n When `p` is odd, the behavior is similar::\n\n sage: normalize_profile(([2,1], [2,2,2]), p=13)\n (((2, 1), (2, 2, 2)), 0)\n\n The full mod `p` Steenrod algebra::\n\n sage: normalize_profile(None, p=7)\n (((), ()), +Infinity)\n sage: normalize_profile(Infinity, p=11)\n (((), ()), +Infinity)\n sage: normalize_profile((lambda n: Infinity, lambda n: 2), p=17)\n (((), ()), +Infinity)\n\n Note that as at the prime 2, the ``precision`` argument has no\n effect on a list or tuple in either entry of ``profile``. If\n ``truncation_type`` is \'auto\', then it gets converted to either\n ``0`` or ``+Infinity`` depending on the *first* entry of\n ``profile``::\n\n sage: normalize_profile(([2,1], [2,2,2]), precision=84, p=13)\n (((2, 1), (2, 2, 2)), 0)\n sage: normalize_profile((lambda n: 0, lambda n: 2), precision=4, p=11)\n (((0, 0, 0), ()), +Infinity)\n sage: normalize_profile((lambda n: 0, (1,1,1,1,1,1,1)), precision=4, p=11)\n (((0, 0, 0), (1, 1, 1, 1, 1, 1, 1)), +Infinity)\n sage: normalize_profile(((4,3,2,1), lambda n: 2), precision=6, p=11)\n (((4, 3, 2, 1), (2, 2, 2, 2, 2)), 0)\n sage: normalize_profile(((4,3,2,1), lambda n: 1), precision=3, p=11, truncation_type=Infinity)\n (((4, 3, 2, 1), (1, 1)), +Infinity)\n\n As at the prime 2, negative numbers in the first component are\n converted to zeroes. Numbers in the second component must be\n either 1 and 2, or else an error is raised::\n\n sage: normalize_profile((lambda n: -n, lambda n: 1), precision=4, p=11)\n (((0, 0, 0), (1, 1, 1)), +Infinity)\n sage: normalize_profile([[0,0,0], [1,2,3,2,1]], p=11)\n Traceback (most recent call last):\n ...\n ValueError: Invalid profile\n ' from sage.rings.infinity import Infinity if (truncation_type == 'zero'): truncation_type = 0 if (truncation_type == 'infinity'): truncation_type = Infinity if (generic is None): generic = (p != 2) if (not generic): if ((profile is None) or (profile == Infinity)): new_profile = () truncation_type = Infinity elif isinstance(profile, (list, tuple)): if (truncation_type == 'auto'): truncation_type = 0 while (profile and (profile[(- 1)] == truncation_type)): profile = profile[:(- 1)] new_profile = tuple(profile) elif callable(profile): if (precision is None): precision = 100 if (truncation_type == 'auto'): truncation_type = Infinity new_profile = [max(0, profile(i)) for i in range(1, precision)] while (new_profile and (new_profile[(- 1)] == truncation_type)): del new_profile[(- 1)] new_profile = tuple(new_profile) if is_valid_profile(new_profile, truncation_type, p): return (new_profile, truncation_type) else: raise ValueError('Invalid profile') else: if ((profile is None) or (profile == Infinity)): new_profile = ((), ()) truncation_type = Infinity else: assert (isinstance(profile, (list, tuple)) and (len(profile) == 2)), 'Invalid form for profile' e = profile[0] k = profile[1] if isinstance(e, (list, tuple)): if (truncation_type == 'auto'): truncation_type = 0 while (e and (e[(- 1)] == truncation_type)): e = e[:(- 1)] e = tuple(e) elif callable(e): if (precision is None): e_precision = 100 else: e_precision = precision if (truncation_type == 'auto'): truncation_type = Infinity e = [max(0, e(i)) for i in range(1, e_precision)] while (e and (e[(- 1)] == truncation_type)): del e[(- 1)] e = tuple(e) if isinstance(k, (list, tuple)): k = tuple(k) elif callable(k): if (precision is None): k_precision = 100 else: k_precision = precision k = tuple([k(i) for i in range((k_precision - 1))]) if (truncation_type == 0): while (k and (k[(- 1)] == 1)): k = k[:(- 1)] else: while (k and (k[(- 1)] == 2)): k = k[:(- 1)] new_profile = (e, k) if is_valid_profile(new_profile, truncation_type, p, generic=True): return (new_profile, truncation_type) else: raise ValueError('Invalid profile')
def milnor_mono_to_string(mono, latex=False, generic=False): "\n String representation of element of the Milnor basis.\n\n This is used by the _repr_ and _latex_ methods.\n\n INPUT:\n\n - ``mono`` - if `generic=False`, tuple of non-negative integers (a,b,c,...);\n if `generic=True`, pair of tuples of non-negative integers ((e0, e1, e2,\n ...), (r1, r2, ...))\n\n - ``latex`` - boolean (optional, default False), if true, output\n LaTeX string\n\n - ``generic`` - whether to format generically, or for the prime 2 (default)\n\n OUTPUT: ``rep`` - string\n\n This returns a string like ``Sq(a,b,c,...)`` when `generic=False`, or a string\n like ``Q_e0 Q_e1 Q_e2 ... P(r1, r2, ...)`` when `generic=True`.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import milnor_mono_to_string\n sage: milnor_mono_to_string((1,2,3,4))\n 'Sq(1,2,3,4)'\n sage: milnor_mono_to_string((1,2,3,4),latex=True)\n '\\text{Sq}(1,2,3,4)'\n sage: milnor_mono_to_string(((1,0), (2,3,1)), generic=True)\n 'Q_{1} Q_{0} P(2,3,1)'\n sage: milnor_mono_to_string(((1,0), (2,3,1)), latex=True, generic=True)\n 'Q_{1} Q_{0} \\mathcal{P}(2,3,1)'\n\n The empty tuple represents the unit element::\n\n sage: milnor_mono_to_string(())\n '1'\n sage: milnor_mono_to_string((), generic=True)\n '1'\n " if latex: if (not generic): sq = '\\text{Sq}' P = '\\text{Sq}' else: P = '\\mathcal{P}' elif (not generic): sq = 'Sq' P = 'Sq' else: P = 'P' if ((mono == ()) or (mono == (0,)) or (generic and ((len(mono[0]) + len(mono[1])) == 0))): return '1' else: if (not generic): string = ((sq + '(') + str(mono[0])) for n in mono[1:]: string = ((string + ',') + str(n)) string = (string + ')') else: string = '' if (len(mono[0]) > 0): for e in mono[0]: string = (((string + 'Q_{') + str(e)) + '} ') if (len(mono[1]) > 0): string = (((string + P) + '(') + str(mono[1][0])) for n in mono[1][1:]: string = ((string + ',') + str(n)) string = (string + ')') return string.strip(' ')
def serre_cartan_mono_to_string(mono, latex=False, generic=False): "\n String representation of element of the Serre-Cartan basis.\n\n This is used by the _repr_ and _latex_ methods.\n\n INPUT:\n\n - ``mono`` - tuple of positive integers (a,b,c,...) when `generic=False`,\n or tuple (e0, n1, e1, n2, ...) when `generic=True`, where each ei is 0 or\n 1, and each ni is positive\n\n - ``latex`` - boolean (optional, default False), if true, output\n LaTeX string\n\n - ``generic`` - whether to format generically, or for the prime 2 (default)\n\n OUTPUT: ``rep`` - string\n\n This returns a string like ``Sq^{a} Sq^{b} Sq^{c} ...`` when\n `generic=False`, or a string like\n ``\\beta^{e0} P^{n1} \\beta^{e1} P^{n2} ...`` when `generic=True`.\n is odd.\n\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import serre_cartan_mono_to_string\n sage: serre_cartan_mono_to_string((1,2,3,4))\n 'Sq^{1} Sq^{2} Sq^{3} Sq^{4}'\n sage: serre_cartan_mono_to_string((1,2,3,4),latex=True)\n '\\\\text{Sq}^{1} \\\\text{Sq}^{2} \\\\text{Sq}^{3} \\\\text{Sq}^{4}'\n sage: serre_cartan_mono_to_string((0,5,1,1,0), generic=True)\n 'P^{5} beta P^{1}'\n sage: serre_cartan_mono_to_string((0,5,1,1,0), generic=True, latex=True)\n '\\\\mathcal{P}^{5} \\\\beta \\\\mathcal{P}^{1}'\n\n The empty tuple represents the unit element 1::\n\n sage: serre_cartan_mono_to_string(())\n '1'\n sage: serre_cartan_mono_to_string((), generic=True)\n '1'\n " if latex: if (not generic): sq = '\\text{Sq}' P = '\\text{Sq}' else: P = '\\mathcal{P}' elif (not generic): sq = 'Sq' P = 'Sq' else: P = 'P' if ((len(mono) == 0) or (mono == (0,))): return '1' else: if (not generic): string = '' for n in mono: string = ((((string + sq) + '^{') + str(n)) + '} ') else: string = '' index = 0 for n in mono: from sage.misc.functional import is_even if is_even(index): if (n == 1): if latex: string = (string + '\\beta ') else: string = (string + 'beta ') else: string = ((((string + P) + '^{') + str(n)) + '} ') index += 1 return string.strip(' ')
def wood_mono_to_string(mono, latex=False): "\n String representation of element of Wood's Y and Z bases.\n\n This is used by the _repr_ and _latex_ methods.\n\n INPUT:\n\n - ``mono`` - tuple of pairs of non-negative integers (s,t)\n\n - ``latex`` - boolean (optional, default False), if true, output\n LaTeX string\n\n OUTPUT:\n\n ``string`` - concatenation of strings of the form\n ``Sq^{2^s (2^{t+1}-1)}`` for each pair (s,t)\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import wood_mono_to_string\n sage: wood_mono_to_string(((1,2),(3,0)))\n 'Sq^{14} Sq^{8}'\n sage: wood_mono_to_string(((1,2),(3,0)),latex=True)\n '\\text{Sq}^{14} \\text{Sq}^{8}'\n\n The empty tuple represents the unit element::\n\n sage: wood_mono_to_string(())\n '1'\n " if latex: sq = '\\text{Sq}' else: sq = 'Sq' if (len(mono) == 0): return '1' else: string = '' for (s, t) in mono: string = ((((string + sq) + '^{') + str(((2 ** s) * ((2 ** (t + 1)) - 1)))) + '} ') return string.strip(' ')
def wall_mono_to_string(mono, latex=False): "\n String representation of element of Wall's basis.\n\n This is used by the _repr_ and _latex_ methods.\n\n INPUT:\n\n - ``mono`` - tuple of pairs of non-negative integers (m,k) with `m\n >= k`\n\n - ``latex`` - boolean (optional, default False), if true, output\n LaTeX string\n\n OUTPUT:\n\n ``string`` - concatenation of strings ``Q^{m}_{k}`` for each pair (m,k)\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import wall_mono_to_string\n sage: wall_mono_to_string(((1,2),(3,0)))\n 'Q^{1}_{2} Q^{3}_{0}'\n sage: wall_mono_to_string(((1,2),(3,0)),latex=True)\n 'Q^{1}_{2} Q^{3}_{0}'\n\n The empty tuple represents the unit element::\n\n sage: wall_mono_to_string(())\n '1'\n " if (len(mono) == 0): return '1' else: string = '' for (m, k) in mono: string = (((((string + 'Q^{') + str(m)) + '}_{') + str(k)) + '} ') return string.strip(' ')
def wall_long_mono_to_string(mono, latex=False): "\n Alternate string representation of element of Wall's basis.\n\n This is used by the _repr_ and _latex_ methods.\n\n INPUT:\n\n - ``mono`` - tuple of pairs of non-negative integers (m,k) with `m\n >= k`\n\n - ``latex`` - boolean (optional, default False), if true, output\n LaTeX string\n\n OUTPUT:\n\n ``string`` - concatenation of strings of the form ``Sq^(2^m)``\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import wall_long_mono_to_string\n sage: wall_long_mono_to_string(((1,2),(3,0)))\n 'Sq^{1} Sq^{2} Sq^{4} Sq^{8}'\n sage: wall_long_mono_to_string(((1,2),(3,0)),latex=True)\n '\\text{Sq}^{1} \\text{Sq}^{2} \\text{Sq}^{4} \\text{Sq}^{8}'\n\n The empty tuple represents the unit element::\n\n sage: wall_long_mono_to_string(())\n '1'\n " if latex: sq = '\\text{Sq}' else: sq = 'Sq' if (len(mono) == 0): return '1' else: string = '' for (m, k) in mono: for i in range(k, (m + 1)): string = ((((string + sq) + '^{') + str((2 ** i))) + '} ') return string.strip(' ')
def arnonA_mono_to_string(mono, latex=False, p=2): "\n String representation of element of Arnon's A basis.\n\n This is used by the _repr_ and _latex_ methods.\n\n INPUT:\n\n - ``mono`` - tuple of pairs of non-negative integers\n (m,k) with `m >= k`\n\n - ``latex`` - boolean (optional, default False), if true, output\n LaTeX string\n\n OUTPUT:\n\n ``string`` - concatenation of strings of the form ``X^{m}_{k}``\n for each pair (m,k)\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import arnonA_mono_to_string\n sage: arnonA_mono_to_string(((1,2),(3,0)))\n 'X^{1}_{2} X^{3}_{0}'\n sage: arnonA_mono_to_string(((1,2),(3,0)),latex=True)\n 'X^{1}_{2} X^{3}_{0}'\n\n The empty tuple represents the unit element::\n\n sage: arnonA_mono_to_string(())\n '1'\n " if (len(mono) == 0): return '1' else: string = '' for (m, k) in mono: string = (((((string + 'X^{') + str(m)) + '}_{') + str(k)) + '} ') return string.strip(' ')
def arnonA_long_mono_to_string(mono, latex=False, p=2): "\n Alternate string representation of element of Arnon's A basis.\n\n This is used by the _repr_ and _latex_ methods.\n\n INPUT:\n\n - ``mono`` - tuple of pairs of non-negative integers (m,k) with `m\n >= k`\n\n - ``latex`` - boolean (optional, default False), if true, output\n LaTeX string\n\n OUTPUT:\n\n ``string`` - concatenation of strings of the form ``Sq(2^m)``\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import arnonA_long_mono_to_string\n sage: arnonA_long_mono_to_string(((1,2),(3,0)))\n 'Sq^{8} Sq^{4} Sq^{2} Sq^{1}'\n sage: arnonA_long_mono_to_string(((1,2),(3,0)),latex=True)\n '\\text{Sq}^{8} \\text{Sq}^{4} \\text{Sq}^{2} \\text{Sq}^{1}'\n\n The empty tuple represents the unit element::\n\n sage: arnonA_long_mono_to_string(())\n '1'\n " if latex: sq = '\\text{Sq}' else: sq = 'Sq' if (len(mono) == 0): return '1' else: string = '' for (m, k) in mono: for i in range(m, (k - 1), (- 1)): string = ((((string + sq) + '^{') + str((2 ** i))) + '} ') return string.strip(' ')
def pst_mono_to_string(mono, latex=False, generic=False): "\n String representation of element of a `P^s_t`-basis.\n\n This is used by the _repr_ and _latex_ methods.\n\n INPUT:\n\n - ``mono`` - tuple of pairs of integers (s,t) with `s >= 0`, `t >\n 0`\n\n - ``latex`` - boolean (optional, default False), if true, output\n LaTeX string\n\n - ``generic`` - whether to format generically, or for the prime 2 (default)\n\n OUTPUT:\n\n ``string`` - concatenation of strings of the form ``P^{s}_{t}``\n for each pair (s,t)\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import pst_mono_to_string\n sage: pst_mono_to_string(((1,2),(0,3)), generic=False)\n 'P^{1}_{2} P^{0}_{3}'\n sage: pst_mono_to_string(((1,2),(0,3)),latex=True, generic=False)\n 'P^{1}_{2} P^{0}_{3}'\n sage: pst_mono_to_string(((1,4), (((1,2), 1),((0,3), 2))), generic=True)\n 'Q_{1} Q_{4} P^{1}_{2} (P^{0}_{3})^2'\n sage: pst_mono_to_string(((1,4), (((1,2), 1),((0,3), 2))), latex=True, generic=True)\n 'Q_{1} Q_{4} P^{1}_{2} (P^{0}_{3})^{2}'\n\n The empty tuple represents the unit element::\n\n sage: pst_mono_to_string(())\n '1'\n " if (len(mono) == 0): return '1' else: string = '' if (not generic): for (s, t) in mono: string = (((((string + 'P^{') + str(s)) + '}_{') + str(t)) + '} ') else: for e in mono[0]: string = (((string + 'Q_{') + str(e)) + '} ') for ((s, t), n) in mono[1]: if (n == 1): string = (((((string + 'P^{') + str(s)) + '}_{') + str(t)) + '} ') else: if latex: pow = ('{%s}' % n) else: pow = str(n) string = (((((((string + '(P^{') + str(s)) + '}_{') + str(t)) + '})^') + pow) + ' ') return string.strip(' ')
def comm_mono_to_string(mono, latex=False, generic=False): "\n String representation of element of a commutator basis.\n\n This is used by the _repr_ and _latex_ methods.\n\n INPUT:\n\n - ``mono`` - tuple of pairs of integers (s,t) with `s >= 0`, `t >\n 0`\n\n - ``latex`` - boolean (optional, default False), if true, output\n LaTeX string\n\n - ``generic`` - whether to format generically, or for the prime 2 (default)\n\n OUTPUT:\n\n ``string`` - concatenation of strings of the form ``c_{s,t}``\n for each pair (s,t)\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import comm_mono_to_string\n sage: comm_mono_to_string(((1,2),(0,3)), generic=False)\n 'c_{1,2} c_{0,3}'\n sage: comm_mono_to_string(((1,2),(0,3)), latex=True)\n 'c_{1,2} c_{0,3}'\n sage: comm_mono_to_string(((1, 4), (((1,2), 1),((0,3), 2))), generic=True)\n 'Q_{1} Q_{4} c_{1,2} c_{0,3}^2'\n sage: comm_mono_to_string(((1, 4), (((1,2), 1),((0,3), 2))), latex=True, generic=True)\n 'Q_{1} Q_{4} c_{1,2} c_{0,3}^{2}'\n\n The empty tuple represents the unit element::\n\n sage: comm_mono_to_string(())\n '1'\n " if (len(mono) == 0): return '1' else: string = '' if (not generic): for (s, t) in mono: string = (((((string + 'c_{') + str(s)) + ',') + str(t)) + '} ') else: for e in mono[0]: string = (((string + 'Q_{') + str(e)) + '} ') for ((s, t), n) in mono[1]: string = (((((string + 'c_{') + str(s)) + ',') + str(t)) + '}') if (n > 1): if latex: pow = ('^{%s}' % n) else: pow = ('^%s' % n) string = (string + pow) string = (string + ' ') return string.strip(' ')
def comm_long_mono_to_string(mono, p, latex=False, generic=False): "\n Alternate string representation of element of a commutator basis.\n\n Okay in low dimensions, but gets unwieldy as the dimension\n increases.\n\n INPUT:\n\n - ``mono`` - tuple of pairs of integers (s,t) with `s >= 0`, `t >\n 0`\n\n - ``latex`` - boolean (optional, default False), if true, output\n LaTeX string\n\n - ``generic`` - whether to format generically, or for the prime 2 (default)\n\n OUTPUT:\n\n ``string`` - concatenation of strings of the form ``s_{2^s... 2^(s+t-1)}``\n for each pair (s,t)\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_misc import comm_long_mono_to_string\n sage: comm_long_mono_to_string(((1,2),(0,3)), 2)\n 's_{24} s_{124}'\n sage: comm_long_mono_to_string(((1,2),(0,3)), 2, latex=True)\n 's_{24} s_{124}'\n sage: comm_long_mono_to_string(((1, 4), (((1,2), 1),((0,3), 2))), 5, generic=True)\n 'Q_{1} Q_{4} s_{5,25} s_{1,5,25}^2'\n sage: comm_long_mono_to_string(((1, 4), (((1,2), 1),((0,3), 2))), 3, latex=True, generic=True)\n 'Q_{1} Q_{4} s_{3,9} s_{1,3,9}^{2}'\n\n The empty tuple represents the unit element::\n\n sage: comm_long_mono_to_string((), p=2)\n '1'\n " if (len(mono) == 0): return '1' else: string = '' if (not generic): for (s, t) in mono: if ((s + t) > 4): comma = ',' else: comma = '' string = (string + 's_{') for i in range(t): string = ((string + str((2 ** (s + i)))) + comma) string = (string.strip(',') + '} ') else: for e in mono[0]: string = (((string + 'Q_{') + str(e)) + '} ') for ((s, t), n) in mono[1]: string = (string + 's_{') for i in range(t): string = ((string + str((p ** (s + i)))) + ',') string = (string.strip(',') + '}') if (n > 1): if latex: pow = ('^{%s}' % n) else: pow = ('^%s' % n) string = (string + pow) string = (string + ' ') return string.strip(' ')
def convert_perm(m): '\n Convert tuple m of non-negative integers to a permutation in\n one-line form.\n\n INPUT:\n\n - ``m`` - tuple of non-negative integers with no repetitions\n\n OUTPUT:\n\n ``list`` - conversion of ``m`` to a permutation of the set\n 1,2,...,len(m)\n\n If ``m=(3,7,4)``, then one can view ``m`` as representing the\n permutation of the set `(3,4,7)` sending 3 to 3, 4 to 7, and 7 to\n 4. This function converts ``m`` to the list ``[1,3,2]``, which\n represents essentially the same permutation, but of the set\n `(1,2,3)`. This list can then be passed to :func:`Permutation\n <sage.combinat.permutation.Permutation>`, and its signature can be\n computed.\n\n EXAMPLES::\n\n sage: sage.algebras.steenrod.steenrod_algebra_misc.convert_perm((3,7,4))\n [1, 3, 2]\n sage: sage.algebras.steenrod.steenrod_algebra_misc.convert_perm((5,0,6,3))\n [3, 1, 4, 2]\n ' m2 = sorted(m) return [(list(m2).index(x) + 1) for x in m]
def milnor_multiplication(r, s): "\n Product of Milnor basis elements r and s at the prime 2.\n\n INPUT:\n\n - r -- tuple of non-negative integers\n - s -- tuple of non-negative integers\n\n OUTPUT:\n\n Dictionary of terms of the form (tuple: coeff), where\n 'tuple' is a tuple of non-negative integers and 'coeff' is 1.\n\n This computes Milnor matrices for the product of `\\text{Sq}(r)`\n and `\\text{Sq}(s)`, computes their multinomial coefficients, and\n for each matrix whose coefficient is 1, add `\\text{Sq}(t)` to the\n output, where `t` is the tuple formed by the diagonals sums from\n the matrix.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_mult import milnor_multiplication\n sage: milnor_multiplication((2,), (1,)) == {(0, 1): 1, (3,): 1}\n True\n sage: sorted(milnor_multiplication((4,), (2,1)).items())\n [((0, 3), 1), ((2, 0, 1), 1), ((6, 1), 1)]\n sage: sorted(milnor_multiplication((2,4), (0,1)).items())\n [((2, 0, 0, 1), 1), ((2, 5), 1)]\n\n These examples correspond to the following product computations:\n\n .. MATH::\n\n \\text{Sq}(2) \\text{Sq}(1) = \\text{Sq}(0,1) + \\text{Sq}(3)\n\n \\text{Sq}(4) \\text{Sq}(2,1) = \\text{Sq}(6,1) + \\text{Sq}(0,3) + \\text{Sq}(2,0,1)\n\n \\text{Sq}(2,4) \\text{Sq}(0,1) = \\text{Sq}(2, 5) + \\text{Sq}(2, 0, 0, 1)\n\n This uses the same algorithm Monks does in his Maple package: see\n http://mathweb.scranton.edu/monks/software/Steenrod/steen.html.\n " result = {} rows = (len(r) + 1) cols = (len(s) + 1) diags = (len(r) + len(s)) M = list(range(rows)) for i in range(rows): M[i] = ([0] * cols) for j in range(1, cols): M[0][j] = s[(j - 1)] for i in range(1, rows): M[i][0] = r[(i - 1)] for j in range(1, cols): M[i][j] = 0 found = True while found: n = 1 okay = 1 diagonal = ([0] * diags) while ((n <= diags) and (okay is not None)): nth_diagonal = [M[i][(n - i)] for i in range(max(0, ((n - cols) + 1)), min((1 + n), rows))] okay = multinomial(nth_diagonal) diagonal[(n - 1)] = okay n = (n + 1) if (okay is not None): i = (diags - 1) while ((i >= 0) and (diagonal[i] == 0)): i = (i - 1) t = tuple(diagonal[:(i + 1)]) if (t in result): del result[t] else: result[t] = 1 found = False i = 1 while ((not found) and (i < rows)): sum = M[i][0] j = 1 while ((not found) and (j < cols)): if (sum >= (2 ** j)): temp_col_sum = 0 for k in range(i): temp_col_sum += M[k][j] if (temp_col_sum != 0): found = True for row in range(1, i): M[row][0] = r[(row - 1)] for col in range(1, cols): M[0][col] = (M[0][col] + M[row][col]) M[row][col] = 0 for col in range(1, j): M[0][col] = (M[0][col] + M[i][col]) M[i][col] = 0 M[0][j] = (M[0][j] - 1) M[i][j] = (M[i][j] + 1) M[i][0] = (sum - (2 ** j)) else: sum = (sum + (M[i][j] * (2 ** j))) else: sum = (sum + (M[i][j] * (2 ** j))) j = (j + 1) i = (i + 1) return result
def multinomial(list): '\n Multinomial coefficient of list, mod 2.\n\n INPUT:\n\n - list -- list of integers\n\n OUTPUT:\n\n None if the multinomial coefficient is 0, or sum of list if it is 1\n\n Given the input `[n_1, n_2, n_3, ...]`, this computes the\n multinomial coefficient `(n_1 + n_2 + n_3 + ...)! / (n_1! n_2!\n n_3! ...)`, mod 2. The method is roughly this: expand each\n `n_i` in binary. If there is a 1 in the same digit for any `n_i`\n and `n_j` with `i\\neq j`, then the coefficient is 0; otherwise, it\n is 1.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_mult import multinomial\n sage: multinomial([1,2,4])\n 7\n sage: multinomial([1,2,5])\n sage: multinomial([1,2,12,192,256])\n 463\n\n This function does not compute any factorials, so the following are\n actually reasonable to do::\n\n sage: multinomial([1,65536])\n 65537\n sage: multinomial([4,65535])\n sage: multinomial([32768,65536])\n 98304\n ' old_sum = list[0] okay = True i = 1 while (okay and (i < len(list))): j = 1 while (okay and (j <= min(old_sum, list[i]))): if ((j & old_sum) == j): okay = ((j & list[i]) == 0) j = (j << 1) old_sum = (old_sum + list[i]) i = (i + 1) if okay: return old_sum else: return None
def milnor_multiplication_odd(m1, m2, p): "\n Product of Milnor basis elements defined by m1 and m2 at the odd prime p.\n\n INPUT:\n\n - m1 - pair of tuples (e,r), where e is an increasing tuple of\n non-negative integers and r is a tuple of non-negative integers\n - m2 - pair of tuples (f,s), same format as m1\n - p -- odd prime number\n\n OUTPUT:\n\n Dictionary of terms of the form (tuple: coeff), where 'tuple' is\n a pair of tuples, as for r and s, and 'coeff' is an integer mod p.\n\n This computes the product of the Milnor basis elements\n `Q_{e_1} Q_{e_2} ... P(r_1, r_2, ...)` and\n `Q_{f_1} Q_{f_2} ... P(s_1, s_2, ...)`.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_mult import milnor_multiplication_odd\n sage: sorted(milnor_multiplication_odd(((0,2),(5,)), ((1,),(1,)), 5).items())\n [(((0, 1, 2), (0, 1)), 4), (((0, 1, 2), (6,)), 4)]\n sage: milnor_multiplication_odd(((0,2,4),()), ((1,3),()), 7)\n {((0, 1, 2, 3, 4), ()): 6}\n sage: milnor_multiplication_odd(((0,2,4),()), ((1,5),()), 7)\n {((0, 1, 2, 4, 5), ()): 1}\n sage: sorted(milnor_multiplication_odd(((),(6,)), ((),(2,)), 3).items())\n [(((), (0, 2)), 1), (((), (4, 1)), 1), (((), (8,)), 1)]\n\n These examples correspond to the following product computations:\n\n .. MATH::\n\n p=5: \\quad Q_0 Q_2 \\mathcal{P}(5) Q_1 \\mathcal{P}(1) = 4 Q_0 Q_1 Q_2 \\mathcal{P}(0,1) + 4 Q_0 Q_1 Q_2 \\mathcal{P}(6)\n\n p=7: \\quad (Q_0 Q_2 Q_4) (Q_1 Q_3) = 6 Q_0 Q_1 Q_2 Q_3 Q_4\n\n p=7: \\quad (Q_0 Q_2 Q_4) (Q_1 Q_5) = Q_0 Q_1 Q_2 Q_3 Q_5\n\n p=3: \\quad \\mathcal{P}(6) \\mathcal{P}(2) = \\mathcal{P}(0,2) + \\mathcal{P}(4,1) + \\mathcal{P}(8)\n\n The following used to fail until the trailing zeroes were\n eliminated in p_mono::\n\n sage: A = SteenrodAlgebra(3)\n sage: a = A.P(0,3); b = A.P(12); c = A.Q(1,2)\n sage: (a+b)*c == a*c + b*c\n True\n\n Test that the bug reported in :trac:`7212` has been fixed::\n\n sage: A.P(36,6)*A.P(27,9,81)\n 2 P(13,21,83) + P(14,24,82) + P(17,20,83) + P(25,18,83) + P(26,21,82) + P(36,15,80,1) + P(49,12,83) + 2 P(50,15,82) + 2 P(53,11,83) + 2 P(63,15,81)\n\n Associativity once failed because of a sign error::\n\n sage: a,b,c = A.Q_exp(0,1), A.P(3), A.Q_exp(1,1)\n sage: (a*b)*c == a*(b*c)\n True\n\n This uses the same algorithm Monks does in his Maple package to\n iterate through the possible matrices: see\n http://mathweb.scranton.edu/monks/software/Steenrod/steen.html.\n " from sage.rings.finite_rings.finite_field_constructor import GF F = GF(p) (f, s) = m2 answer = {m1: F(1)} for k in f: old_answer = answer answer = {} for mono in old_answer: if (k not in mono[0]): q_mono = set(mono[0]) if q_mono: ind = len(q_mono.intersection(range(k, (1 + max(q_mono))))) else: ind = 0 coeff = (((- 1) ** ind) * old_answer[mono]) lst = list(mono[0]) if (ind == 0): lst.append(k) else: lst.insert((- ind), k) q_mono = tuple(lst) p_mono = mono[1] answer[(q_mono, p_mono)] = F(coeff) for i in range(1, (1 + len(mono[1]))): if (((k + i) not in mono[0]) and ((p ** k) <= mono[1][(i - 1)])): q_mono = set(mono[0]) if q_mono: ind = len(q_mono.intersection(range((k + i), (1 + max(q_mono))))) else: ind = 0 coeff = (((- 1) ** ind) * old_answer[mono]) lst = list(mono[0]) if (ind == 0): lst.append((k + i)) else: lst.insert((- ind), (k + i)) q_mono = tuple(lst) p_mono = list(mono[1]) p_mono[(i - 1)] = (p_mono[(i - 1)] - (p ** k)) while (p_mono and (p_mono[(- 1)] == 0)): p_mono.pop() answer[(q_mono, tuple(p_mono))] = F(coeff) if (not s): result = answer else: result = {} for (e, r) in answer: old_coeff = answer[(e, r)] rows = (len(r) + 1) cols = (len(s) + 1) diags = (len(r) + len(s)) M = list(range(rows)) for i in range(rows): M[i] = ([0] * cols) for j in range(1, cols): M[0][j] = s[(j - 1)] for i in range(1, rows): M[i][0] = r[(i - 1)] for j in range(1, cols): M[i][j] = 0 found = True while found: n = 1 coeff = old_coeff diagonal = ([0] * diags) while ((n <= diags) and (coeff != 0)): nth_diagonal = [M[i][(n - i)] for i in range(max(0, ((n - cols) + 1)), min((1 + n), rows))] coeff = (coeff * multinomial_odd(nth_diagonal, p)) diagonal[(n - 1)] = sum(nth_diagonal) n = (n + 1) if (F(coeff) != 0): i = (diags - 1) while ((i >= 0) and (diagonal[i] == 0)): i = (i - 1) t = tuple(diagonal[:(i + 1)]) if ((e, t) in result): result[(e, t)] = F((coeff + result[(e, t)])) else: result[(e, t)] = F(coeff) found = False i = 1 while ((not found) and (i < rows)): temp_sum = M[i][0] j = 1 while ((not found) and (j < cols)): if (temp_sum >= (p ** j)): temp_col_sum = 0 for k in range(i): temp_col_sum += M[k][j] if (temp_col_sum != 0): found = True for row in range(1, i): M[row][0] = r[(row - 1)] for col in range(1, cols): M[0][col] = (M[0][col] + M[row][col]) M[row][col] = 0 for col in range(1, j): M[0][col] = (M[0][col] + M[i][col]) M[i][col] = 0 M[0][j] = (M[0][j] - 1) M[i][j] = (M[i][j] + 1) M[i][0] = (temp_sum - (p ** j)) else: temp_sum += (M[i][j] * (p ** j)) else: temp_sum += (M[i][j] * (p ** j)) j = (j + 1) i = (i + 1) return result
def multinomial_odd(list, p): "\n Multinomial coefficient of list, mod p.\n\n INPUT:\n\n - list -- list of integers\n - p -- a prime number\n\n OUTPUT:\n\n Associated multinomial coefficient, mod p\n\n Given the input `[n_1, n_2, n_3, ...]`, this computes the\n multinomial coefficient `(n_1 + n_2 + n_3 + ...)! / (n_1! n_2!\n n_3! ...)`, mod `p`. The method is this: expand each `n_i` in\n base `p`: `n_i = \\sum_j p^j n_{ij}`. Do the same for the sum of\n the `n_i`'s, which we call `m`: `m = \\sum_j p^j m_j`. Then the\n multinomial coefficient is congruent, mod `p`, to the product of\n the multinomial coefficients `m_j! / (n_{1j}! n_{2j}! ...)`.\n\n Furthermore, any multinomial coefficient `m! / (n_1! n_2! ...)`\n can be computed as a product of binomial coefficients: it equals\n\n .. MATH::\n\n \\binom{n_1}{n_1} \\binom{n_1 + n_2}{n_2} \\binom{n_1 + n_2 + n_3}{n_3} ...\n\n This is convenient because Sage's binomial function returns\n integers, not rational numbers (as would be produced just by\n dividing factorials).\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_mult import multinomial_odd\n sage: multinomial_odd([1,2,4], 2)\n 1\n sage: multinomial_odd([1,2,4], 7)\n 0\n sage: multinomial_odd([1,2,4], 11)\n 6\n sage: multinomial_odd([1,2,4], 101)\n 4\n sage: multinomial_odd([1,2,4], 107)\n 105\n " from sage.rings.finite_rings.finite_field_constructor import FiniteField as GF from sage.rings.integer import Integer from sage.arith.misc import binomial n = sum(list) answer = 1 F = GF(p) n_expansion = Integer(n).digits(p) list_expansion = [Integer(k).digits(p) for k in list] index = 0 while ((answer != 0) and (index < len(n_expansion))): multi = F(1) partial_sum = 0 for exp in list_expansion: if (index < len(exp)): partial_sum = (partial_sum + exp[index]) multi = F((multi * binomial(partial_sum, exp[index]))) answer = F((answer * multi)) index += 1 return answer
def binomial_mod2(n, k): '\n The binomial coefficient `\\binom{n}{k}`, computed mod 2.\n\n INPUT:\n\n - `n`, `k` - integers\n\n OUTPUT:\n\n `n` choose `k`, mod 2\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_mult import binomial_mod2\n sage: binomial_mod2(4,2)\n 0\n sage: binomial_mod2(5,4)\n 1\n sage: binomial_mod2(3 * 32768, 32768)\n 1\n sage: binomial_mod2(4 * 32768, 32768)\n 0\n ' if (n < k): return 0 elif (((n - k) & k) == 0): return 1 else: return 0
def binomial_modp(n, k, p): '\n The binomial coefficient `\\binom{n}{k}`, computed mod `p`.\n\n INPUT:\n\n - `n`, `k` - integers\n - `p` - prime number\n\n OUTPUT:\n\n `n` choose `k`, mod `p`\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_mult import binomial_modp\n sage: binomial_modp(5,2,3)\n 1\n sage: binomial_modp(6,2,11) # 6 choose 2 = 15\n 4\n ' if (n < k): return 0 return multinomial_odd([(n - k), k], p)
@cached_function def adem(a, b, c=0, p=2, generic=None): '\n The mod `p` Adem relations\n\n INPUT:\n\n - `a`, `b`, `c` (optional) - nonnegative integers, corresponding\n to either `P^a P^b` or (if `c` present) to `P^a \\beta^b P^c`\n - `p` - positive prime number (optional, default 2)\n - `generic` - whether to use the generic Steenrod algebra, (default: depends on prime)\n\n OUTPUT:\n\n a dictionary representing the mod `p` Adem relations\n applied to `P^a P^b` or (if `c` present) to `P^a \\beta^b P^c`.\n\n The mod `p` Adem relations for the mod `p` Steenrod algebra are as\n follows: if `p=2`, then if `a < 2b`,\n\n .. MATH::\n\n \\text{Sq}^a \\text{Sq}^b = \\sum_{j=0}^{a/2} \\binom{b-j-1}{a-2j} \\text{Sq}^{a+b-j} \\text{Sq}^j\n\n If `p` is odd, then if `a < pb`,\n\n .. MATH::\n\n P^a P^b = \\sum_{j=0}^{a/p} (-1)^{a+j} \\binom{(b-j)(p-1)-1}{a-pj} P^{a+b-j} P^j\n\n Also for `p` odd, if `a \\leq pb`,\n\n .. MATH::\n\n P^a \\beta P^b = \\sum_{j=0}^{a/p} (-1)^{a+j} \\binom{(b-j)(p-1)}{a-pj} \\beta P^{a+b-j} P^j\n + \\sum_{j=0}^{a/p} (-1)^{a+j-1} \\binom{(b-j)(p-1)-1}{a-pj-1} P^{a+b-j} \\beta P^j\n\n EXAMPLES:\n\n If two arguments (`a` and `b`) are given, then computations are\n done mod 2. If `a \\geq 2b`, then the dictionary {(a,b): 1} is\n returned. Otherwise, the right side of the mod 2 Adem relation\n for `\\text{Sq}^a \\text{Sq}^b` is returned. For example, since\n `\\text{Sq}^2 \\text{Sq}^2 = \\text{Sq}^3 \\text{Sq}^1`, we have::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_mult import adem\n sage: adem(2,2) # indirect doctest\n {(3, 1): 1}\n sage: adem(4,2)\n {(4, 2): 1}\n sage: adem(4,4) == {(6, 2): 1, (7, 1): 1}\n True\n\n If `p` is given and is odd, then with two inputs `a` and `b`, the\n Adem relation for `P^a P^b` is computed. With three inputs `a`,\n `b`, `c`, the Adem relation for `P^a \\beta^b P^c` is computed.\n In either case, the keys in the output are all tuples of odd length,\n with ``(i_1, i_2, ..., i_m)`` representing\n\n .. MATH::\n\n \\beta^{i_1} P^{i_2} \\beta^{i_3} P^{i_4} ... \\beta^{i_m}\n\n For instance::\n\n sage: adem(3,1, p=3)\n {(0, 3, 0, 1, 0): 1}\n sage: adem(3,0,1, p=3)\n {(0, 3, 0, 1, 0): 1}\n sage: adem(1,0,1, p=7)\n {(0, 2, 0): 2}\n sage: adem(1,1,1, p=5) == {(0, 2, 1): 1, (1, 2, 0): 1}\n True\n sage: adem(1,1,2, p=5) == {(0, 3, 1): 1, (1, 3, 0): 2}\n True\n ' if (generic is None): generic = (p != 2) if (not generic): if (b == 0): return {(a,): 1} elif (a == 0): return {(b,): 1} elif (a >= (2 * b)): return {(a, b): 1} result = {} for c in range((1 + (a // 2))): if (binomial_mod2(((b - c) - 1), (a - (2 * c))) == 1): if (c == 0): result[((a + b),)] = 1 else: result[(((a + b) - c), c)] = 1 return result if ((a == 0) and (b == 0)): return {(c,): 1} if (c == 0): bockstein = 0 A = a B = b else: A = a B = c bockstein = b if (A == 0): return {(bockstein, B, 0): 1} if (B == 0): return {(0, A, bockstein): 1} if (bockstein == 0): if (A >= (p * B)): return {(0, A, 0, B, 0): 1} result = {} for j in range((1 + (a // p))): coeff = (((- 1) ** (A + j)) * binomial_modp((((B - j) * (p - 1)) - 1), (A - (p * j)), p)) if ((coeff % p) != 0): if (j == 0): result[(0, (A + B), 0)] = coeff else: result[(0, ((A + B) - j), 0, j, 0)] = coeff else: if (A >= ((p * B) + 1)): return {(0, A, 1, B, 0): 1} result = {} for j in range((1 + (a // p))): coeff = (((- 1) ** (A + j)) * binomial_modp(((B - j) * (p - 1)), (A - (p * j)), p)) if ((coeff % p) != 0): if (j == 0): result[(1, (A + B), 0)] = coeff else: result[(1, ((A + B) - j), 0, j, 0)] = coeff for j in range((1 + ((a - 1) // p))): coeff = (((- 1) ** ((A + j) - 1)) * binomial_modp((((B - j) * (p - 1)) - 1), ((A - (p * j)) - 1), p)) if ((coeff % p) != 0): if (j == 0): result[(0, (A + B), 1)] = coeff else: result[(0, ((A + B) - j), 1, j, 0)] = coeff return result
@cached_function def make_mono_admissible(mono, p=2, generic=None): "\n Given a tuple ``mono``, view it as a product of Steenrod\n operations, and return a dictionary giving data equivalent to\n writing that product as a linear combination of admissible\n monomials.\n\n When `p=2`, the sequence (and hence the corresponding monomial)\n `(i_1, i_2, ...)` is admissible if `i_j \\geq 2 i_{j+1}` for all\n `j`.\n\n When `p` is odd, the sequence `(e_1, i_1, e_2, i_2, ...)` is\n admissible if `i_j \\geq e_{j+1} + p i_{j+1}` for all `j`.\n\n INPUT:\n\n - ``mono`` - a tuple of non-negative integers\n - `p` - prime number, optional (default 2)\n - `generic` - whether to use the generic Steenrod algebra, (default: depends on prime)\n\n OUTPUT:\n\n Dictionary of terms of the form (tuple: coeff), where\n 'tuple' is an admissible tuple of non-negative integers and\n 'coeff' is its coefficient. This corresponds to a linear\n combination of admissible monomials. When `p` is odd, each tuple\n must have an odd length: it should be of the form `(e_1, i_1, e_2,\n i_2, ..., e_k)` where each `e_j` is either 0 or 1 and each `i_j`\n is a positive integer: this corresponds to the admissible monomial\n\n .. MATH::\n\n \\beta^{e_1} \\mathcal{P}^{i_2} \\beta^{e_2} \\mathcal{P}^{i_2} ...\n \\mathcal{P}^{i_k} \\beta^{e_k}\n\n ALGORITHM:\n\n Given `(i_1, i_2, i_3, ...)`, apply the Adem relations to the first\n pair (or triple when `p` is odd) where the sequence is inadmissible,\n and then apply this function recursively to each of the resulting\n tuples `(i_1, ..., i_{j-1}, NEW, i_{j+2}, ...)`, keeping track of\n the coefficients.\n\n EXAMPLES::\n\n sage: from sage.algebras.steenrod.steenrod_algebra_mult import make_mono_admissible\n sage: make_mono_admissible((12,)) # already admissible, indirect doctest\n {(12,): 1}\n sage: make_mono_admissible((2,1)) # already admissible\n {(2, 1): 1}\n sage: make_mono_admissible((2,2))\n {(3, 1): 1}\n sage: make_mono_admissible((2, 2, 2))\n {(5, 1): 1}\n sage: make_mono_admissible((0, 2, 0, 1, 0), p=7)\n {(0, 3, 0): 3}\n\n Test the fix from :trac:`13796`::\n\n sage: SteenrodAlgebra(p=2, basis='adem').Q(2) * (Sq(6) * Sq(2)) # indirect doctest\n Sq^10 Sq^4 Sq^1 + Sq^10 Sq^5 + Sq^12 Sq^3 + Sq^13 Sq^2\n " from sage.rings.finite_rings.finite_field_constructor import GF if (generic is None): generic = (p != 2) F = GF(p) if (len(mono) == 1): return {mono: 1} if ((not generic) and (len(mono) == 2)): return adem(*mono, p=p, generic=generic) if (not generic): admissible = True for j in range((len(mono) - 1)): if (mono[j] < (2 * mono[(j + 1)])): admissible = False break if admissible: return {mono: 1} ans = {} y = adem(mono[j], mono[(j + 1)]) for x in y: new = ((mono[:j] + x) + mono[(j + 2):]) new = make_mono_admissible(new) for m in new: if (m in ans): ans[m] = (ans[m] + (y[x] * new[m])) if (F(ans[m]) == 0): del ans[m] else: ans[m] = (y[x] * new[m]) return ans admissible = True for j in range(1, (len(mono) - 2), 2): if (mono[j] < (mono[(j + 1)] + (p * mono[(j + 2)]))): admissible = False break if admissible: return {mono: 1} ans = {} y = adem(*mono[j:(j + 3)], p=p, generic=True) for x in y: new_x = list(x) new_x[0] = (mono[(j - 1)] + x[0]) if (len(mono) >= (j + 3)): new_x[(- 1)] = (mono[(j + 3)] + x[(- 1)]) if ((new_x[0] <= 1) and (new_x[(- 1)] <= 1)): new = ((mono[:(j - 1)] + tuple(new_x)) + mono[(j + 4):]) new = make_mono_admissible(new, p, generic=True) for m in new: if (m in ans): ans[m] = (ans[m] + (y[x] * new[m])) if (F(ans[m]) == 0): del ans[m] else: ans[m] = (y[x] * new[m]) return ans
class TensorAlgebra(CombinatorialFreeModule): "\n The tensor algebra `T(M)` of a module `M`.\n\n Let `\\{ b_i \\}_{i \\in I}` be a basis of the `R`-module `M`. Then the\n tensor algebra `T(M)` of `M` is an associative `R`-algebra, with a\n basis consisting of all tensors of the form\n `b_{i_1} \\otimes b_{i_2} \\otimes \\cdots \\otimes b_{i_n}` for\n nonnegative integers `n` and `n`-tuples\n `(i_1, i_2, \\ldots, i_n) \\in I^n`. The product of `T(M)` is given by\n\n .. MATH::\n\n (b_{i_1} \\otimes \\cdots \\otimes b_{i_m}) \\cdot (b_{j_1} \\otimes\n \\cdots \\otimes b_{j_n}) = b_{i_1} \\otimes \\cdots \\otimes b_{i_m}\n \\otimes b_{j_1} \\otimes \\cdots \\otimes b_{j_n}.\n\n As an algebra, it is generated by the basis vectors `b_i` of `M`. It\n is an `\\NN`-graded `R`-algebra, with the degree of each `b_i` being\n `1`.\n\n It also has a Hopf algebra structure: The comultiplication is the\n unique algebra morphism `\\delta : T(M) \\to T(M) \\otimes T(M)` defined\n by:\n\n .. MATH::\n\n \\delta(b_i) = b_i \\otimes 1 + 1 \\otimes b_i\n\n (where the `\\otimes` symbol here forms tensors in\n `T(M) \\otimes T(M)`, not inside `T(M)` itself). The counit is the\n unique algebra morphism `T(M) \\to R` sending each `b_i` to `0`. Its\n antipode `S` satisfies\n\n .. MATH::\n\n S(b_{i_1} \\otimes \\cdots \\otimes b_{i_m}) = (-1)^m (b_{i_m} \\otimes\n \\cdots \\otimes b_{i_1}).\n\n This is a connected graded cocommutative Hopf algebra.\n\n REFERENCES:\n\n - :wikipedia:`Tensor_algebra`\n\n .. SEEALSO::\n\n :class:`TensorAlgebra`\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: TA.dimension()\n +Infinity\n sage: TA.base_ring()\n Rational Field\n sage: TA.algebra_generators()\n Finite family {'a': B['a'], 'b': B['b'], 'c': B['c']}\n " def __init__(self, M, prefix='T', category=None, **options): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: TestSuite(TA).run()\n sage: m = SymmetricFunctions(QQ).m()\n sage: Tm = TensorAlgebra(m)\n sage: TestSuite(Tm).run()\n " self._base_module = M R = M.base_ring() category = GradedHopfAlgebrasWithBasis(R.category()).or_subcategory(category) CombinatorialFreeModule.__init__(self, R, IndexedFreeMonoid(M.indices()), prefix=prefix, category=category, **options) self._print_options['tensor_symbol'] = options.get('tensor_symbol', tensor.symbol) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TensorAlgebra(C)\n Tensor Algebra of Free module generated by {'a', 'b', 'c'} over Rational Field\n " return 'Tensor Algebra of {}'.format(self._base_module) def _repr_term(self, m): '\n Return a string of representation of the term indexed by ``m``.\n\n TESTS::\n\n sage: C = CombinatorialFreeModule(QQ, [\'a\',\'b\',\'c\'])\n sage: TA = TensorAlgebra(C)\n sage: s = TA([\'a\',\'b\',\'c\']).leading_support()\n sage: TA._repr_term(s)\n "B[\'a\'] # B[\'b\'] # B[\'c\']"\n sage: s = TA([\'a\']*3 + [\'b\']*2 + [\'a\',\'c\',\'b\']).leading_support()\n sage: TA._repr_term(s)\n "B[\'a\'] # B[\'a\'] # B[\'a\'] # B[\'b\'] # B[\'b\'] # B[\'a\'] # B[\'c\'] # B[\'b\']"\n\n sage: I = TA.indices()\n sage: TA._repr_term(I.one())\n \'1\'\n ' if (len(m) == 0): return '1' symb = self._print_options['tensor_symbol'] if (symb is None): symb = tensor.symbol return symb.join((self._base_module._repr_term(k) for (k, e) in m._monomial for i in range(e))) def _latex_term(self, m): "\n Return a latex representation of the term indexed by ``m``.\n\n TESTS::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: s = TA(['a','b','c']).leading_support()\n sage: TA._latex_term(s)\n 'B_{a} \\\\otimes B_{b} \\\\otimes B_{c}'\n\n sage: I = TA.indices()\n sage: TA._latex_term(I.one())\n '1'\n " if (len(m) == 0): return '1' symb = ' \\otimes ' return symb.join((self._base_module._latex_term(k) for (k, e) in m._monomial for i in range(e))) def _ascii_art_term(self, m): "\n Return an ascii art representation of the term indexed by ``m``.\n\n TESTS::\n\n sage: C = CombinatorialFreeModule(QQ, Partitions())\n sage: TA = TensorAlgebra(C)\n sage: s = TA([Partition([3,2,2,1]), Partition([3])]).leading_support()\n sage: TA._ascii_art_term(s)\n B # B\n *** ***\n **\n **\n *\n sage: s = TA([Partition([3,2,2,1])]*2 + [Partition([3])]*3 + [Partition([1])]*2).leading_support()\n sage: t = TA._ascii_art_term(s); t\n B # B # B # B # B # B # B\n *** *** *** *** *** * *\n ** **\n ** **\n * *\n sage: t._breakpoints\n [7, 14, 21, 28, 35, 40]\n\n sage: I = TA.indices()\n sage: TA._ascii_art_term(I.one())\n '1'\n " if (len(m) == 0): return '1' from sage.typeset.ascii_art import AsciiArt, ascii_art symb = self._print_options['tensor_symbol'] if (symb is None): symb = tensor.symbol M = self._base_module return ascii_art(*(M._ascii_art_term(k) for (k, e) in m._monomial for _ in range(e)), sep=AsciiArt([symb], breakpoints=[len(symb)])) def _element_constructor_(self, x): "\n Construct an element of ``self``.\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: TA(['a','b','c'])\n B['a'] # B['b'] # B['c']\n sage: TA(['a','b','b'])\n B['a'] # B['b'] # B['b']\n sage: TA(['a','b','c']) + TA(['a'])\n B['a'] + B['a'] # B['b'] # B['c']\n sage: TA(['a','b','c']) + TA(['a','b','a'])\n B['a'] # B['b'] # B['a'] + B['a'] # B['b'] # B['c']\n sage: TA(['a','b','c']) + TA(['a','b','c'])\n 2*B['a'] # B['b'] # B['c']\n sage: TA(C.an_element())\n 2*B['a'] + 2*B['b'] + 3*B['c']\n " FM = self._indices if isinstance(x, (list, tuple)): x = FM.prod((FM.gen(elt) for elt in x)) return self.monomial(x) if (x in FM._indices): return self.monomial(FM.gen(x)) if (x in self._base_module): return self.sum_of_terms(((FM.gen(k), v) for (k, v) in x)) return CombinatorialFreeModule._element_constructor_(self, x) def _tensor_constructor_(self, elts): "\n Construct an element of ``self`` that is the tensor product of\n the list of base module elements ``elts``.\n\n TESTS::\n\n sage: C = CombinatorialFreeModule(ZZ, ['a','b'])\n sage: TA = TensorAlgebra(C)\n sage: x = C.an_element(); x\n 2*B['a'] + 2*B['b']\n sage: TA._tensor_constructor_([x, x])\n 4*B['a'] # B['a'] + 4*B['a'] # B['b']\n + 4*B['b'] # B['a'] + 4*B['b'] # B['b']\n sage: y = C.monomial('b') + 3*C.monomial('a')\n sage: TA._tensor_constructor_([x, y])\n 6*B['a'] # B['a'] + 2*B['a'] # B['b'] + 6*B['b'] # B['a']\n + 2*B['b'] # B['b']\n sage: TA._tensor_constructor_([y]) == y\n True\n sage: TA._tensor_constructor_([x]) == x\n True\n sage: TA._tensor_constructor_([]) == TA.one()\n True\n " if (not elts): return self.one() zero = self.base_ring().zero() I = self._indices cur = {I.gen(k): v for (k, v) in elts[0]} for x in elts[1:]: next = {} for (k, v) in cur.items(): for (m, c) in x: i = (k * I.gen(m)) next[i] = (cur.get(i, zero) + (v * c)) cur = next return self._from_dict(cur) 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 with a coercion into ``self.base_ring()``.\n\n - Anything with a coercion into the base module of ``self``.\n\n - A tensor algebra whose base module has a coercion into the base\n module of ``self``.\n\n - A tensor module whose factors have a coercion into the base\n module of ``self``.\n\n TESTS::\n\n sage: C = CombinatorialFreeModule(ZZ, Set([1,2]))\n sage: TAC = TensorAlgebra(C)\n sage: TAC.has_coerce_map_from(ZZ)\n True\n sage: TAC(1) == TAC.one()\n True\n sage: TAC.has_coerce_map_from(C)\n True\n sage: c = C.monomial(2)\n sage: TAC(c)\n B[2]\n sage: d = C.monomial(1)\n sage: TAC(c) * TAC(d)\n B[2] # B[1]\n sage: TAC(c-d) * TAC(c+d)\n -B[1] # B[1] - B[1] # B[2] + B[2] # B[1] + B[2] # B[2]\n\n sage: TCC = tensor((C,C))\n sage: TAC.has_coerce_map_from(TCC)\n True\n sage: TAC(tensor([c, d]))\n B[2] # B[1]\n\n ::\n\n sage: D = CombinatorialFreeModule(ZZ, Set([2,4]))\n sage: TAD = TensorAlgebra(D)\n sage: f = C.module_morphism(on_basis=lambda x: D.monomial(2*x), codomain=D)\n sage: f.register_as_coercion()\n\n sage: TCD = tensor((C,D))\n sage: TAD.has_coerce_map_from(TCC)\n True\n sage: TAD.has_coerce_map_from(TCD)\n True\n sage: TAC.has_coerce_map_from(TCD)\n False\n sage: TAD.has_coerce_map_from(TAC)\n True\n sage: TAD(3 * TAC([1, 2, 2, 1, 1]))\n 3*B[2] # B[4] # B[4] # B[2] # B[2]\n ' self_base_ring = self.base_ring() if (self_base_ring == R): return BaseRingLift(Hom(self_base_ring, self)) if self_base_ring.has_coerce_map_from(R): return (BaseRingLift(Hom(self_base_ring, self)) * self_base_ring.coerce_map_from(R)) M = self._base_module if (R == M): return True if M.has_coerce_map_from(R): phi = M.coerce_map_from(R) return (self.coerce_map_from(M) * phi) if (isinstance(R, TensorAlgebra) and M.has_coerce_map_from(R._base_module)): RM = R._base_module phi = M.coerce_map_from(RM) return R.module_morphism((lambda m: self._tensor_constructor_([phi(RM.monomial(k)) for k in m.to_word_list()])), codomain=self) if ((R in Modules(self_base_ring).WithBasis().TensorProducts()) and isinstance(R, CombinatorialFreeModule_Tensor) and all((M.has_coerce_map_from(RM) for RM in R._sets))): modules = R._sets vector_map = [M.coerce_map_from(RM) for RM in R._sets] return R.module_morphism((lambda x: self._tensor_constructor_([vector_map[i](M.monomial(x[i])) for (i, M) in enumerate(modules)])), codomain=self) return super()._coerce_map_from_(R) def construction(self): "\n Return the functorial construction of ``self``.\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(ZZ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: f, M = TA.construction()\n sage: M == C\n True\n sage: f(M) == TA\n True\n " return (TensorAlgebraFunctor(self.category().base()), self._base_module) def degree_on_basis(self, m): "\n Return the degree of the simple tensor ``m``, which is its length\n (thought of as an element in the free monoid).\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: s = TA(['a','b','c']).leading_support(); s\n F['a']*F['b']*F['c']\n sage: TA.degree_on_basis(s)\n 3\n " return m.length() def base_module(self): "\n Return the base module of ``self``.\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: TA.base_module() is C\n True\n " return self._base_module @cached_method def one_basis(self): "\n Return the empty word, which indexes the `1` of this algebra.\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: TA.one_basis()\n 1\n sage: TA.one_basis().parent()\n Free monoid indexed by {'a', 'b', 'c'}\n sage: m = SymmetricFunctions(QQ).m()\n sage: Tm = TensorAlgebra(m)\n sage: Tm.one_basis()\n 1\n sage: Tm.one_basis().parent()\n Free monoid indexed by Partitions\n " return self._indices.one() @cached_method def algebra_generators(self): "\n Return the generators of this algebra.\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: TA.algebra_generators()\n Finite family {'a': B['a'], 'b': B['b'], 'c': B['c']}\n sage: m = SymmetricFunctions(QQ).m()\n sage: Tm = TensorAlgebra(m)\n sage: Tm.algebra_generators()\n Lazy family (generator(i))_{i in Partitions}\n " return Family(self._indices.indices(), (lambda i: self.monomial(self._indices.gen(i))), name='generator') gens = algebra_generators def product_on_basis(self, a, b): "\n Return the product of the basis elements indexed by ``a`` and\n ``b``, as per\n :meth:`AlgebrasWithBasis.ParentMethods.product_on_basis()`.\n\n INPUT:\n\n - ``a``, ``b`` -- basis indices\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: I = TA.indices()\n sage: g = I.gens()\n sage: TA.product_on_basis(g['a']*g['b'], g['a']*g['c'])\n B['a'] # B['b'] # B['a'] # B['c']\n " return self.monomial((a * b)) def counit(self, x): "\n Return the counit of ``x``.\n\n INPUT:\n\n - ``x`` -- an element of ``self``\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: x = TA(['a','b','c'])\n sage: TA.counit(x)\n 0\n sage: TA.counit(x + 3)\n 3\n " return x[self.one_basis()] def antipode_on_basis(self, m): "\n Return the antipode of the simple tensor indexed by ``m``.\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: TA = TensorAlgebra(C)\n sage: s = TA(['a','b','c']).leading_support()\n sage: TA.antipode_on_basis(s)\n -B['c'] # B['b'] # B['a']\n sage: t = TA(['a', 'b', 'b', 'b']).leading_support()\n sage: TA.antipode_on_basis(t)\n B['b'] # B['b'] # B['b'] # B['a']\n " m = self._indices(reversed(m._monomial)) R = self.base_ring() if ((len(m) % 2) == 1): return self.term(m, (- R.one())) else: return self.term(m, R.one()) def coproduct_on_basis(self, m): '\n Return the coproduct of the simple tensor indexed by ``m``.\n\n EXAMPLES::\n\n sage: C = CombinatorialFreeModule(QQ, [\'a\',\'b\',\'c\'])\n sage: TA = TensorAlgebra(C, tensor_symbol="(X)")\n sage: TA.coproduct_on_basis(TA.one_basis())\n 1 # 1\n sage: I = TA.indices()\n sage: ca = TA.coproduct_on_basis(I.gen(\'a\')); ca\n 1 # B[\'a\'] + B[\'a\'] # 1\n sage: s = TA([\'a\',\'b\',\'c\']).leading_support()\n sage: cp = TA.coproduct_on_basis(s); cp\n 1 # B[\'a\'](X)B[\'b\'](X)B[\'c\'] + B[\'a\'] # B[\'b\'](X)B[\'c\']\n + B[\'a\'](X)B[\'b\'] # B[\'c\'] + B[\'a\'](X)B[\'b\'](X)B[\'c\'] # 1\n + B[\'a\'](X)B[\'c\'] # B[\'b\'] + B[\'b\'] # B[\'a\'](X)B[\'c\']\n + B[\'b\'](X)B[\'c\'] # B[\'a\'] + B[\'c\'] # B[\'a\'](X)B[\'b\']\n\n We check that `\\Delta(a \\otimes b \\otimes c) =\n \\Delta(a) \\Delta(b) \\Delta(c)`::\n\n sage: cb = TA.coproduct_on_basis(I.gen(\'b\'))\n sage: cc = TA.coproduct_on_basis(I.gen(\'c\'))\n sage: cp == ca * cb * cc\n True\n ' S = self.tensor_square() if (len(m) == 0): return S.one() if (len(m) == 1): ob = self.one_basis() return S.sum_of_monomials([(m, ob), (ob, m)]) I = self._indices m_word = [k for (k, e) in m._monomial for dummy in range(e)] ob = self.one_basis() return S.prod((S.sum_of_monomials([(I.gen(x), ob), (ob, I.gen(x))]) for x in m_word))
class TensorAlgebraFunctor(ConstructionFunctor): '\n The tensor algebra functor.\n\n Let `R` be a unital ring. Let `V_R` and `A_R` be the categories of\n `R`-modules and `R`-algebras respectively. The functor\n `T : V_R \\to A_R` sends an `R`-module `M` to the tensor\n algebra `T(M)`. The functor `T` is left-adjoint to the forgetful\n functor `F : A_R \\to V_R`.\n\n INPUT:\n\n - ``base`` -- the base `R`\n ' rank = 20 def __init__(self, base): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.tensor_algebra import TensorAlgebraFunctor\n sage: F = TensorAlgebraFunctor(Rings())\n sage: TestSuite(F).run()\n ' ConstructionFunctor.__init__(self, Modules(base), Algebras(base)) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.tensor_algebra import TensorAlgebraFunctor\n sage: TensorAlgebraFunctor(Rings())\n Tensor algebra functor on modules over rings\n sage: TensorAlgebraFunctor(QQ)\n Tensor algebra functor on vector spaces over Rational Field\n ' return 'Tensor algebra functor on {}'.format(self.domain()._repr_object_names()) def _apply_functor(self, M): "\n Construct the tensor algebra `T(M)`.\n\n EXAMPLES::\n\n sage: from sage.algebras.tensor_algebra import TensorAlgebraFunctor\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: F = TensorAlgebraFunctor(QQ)\n sage: F._apply_functor(C)\n Tensor Algebra of Free module generated by {'a', 'b', 'c'} over Rational Field\n " if (M not in self.domain().WithBasis()): raise NotImplementedError('currently only for modules with basis') return TensorAlgebra(M) def _apply_functor_to_morphism(self, f): "\n Apply ``self`` to a morphism ``f`` in the domain of ``self``.\n\n EXAMPLES::\n\n sage: from sage.algebras.tensor_algebra import TensorAlgebraFunctor\n sage: C = CombinatorialFreeModule(QQ, ['a','b','c'])\n sage: D = CombinatorialFreeModule(QQ, ['x','y'])\n sage: on_basis = lambda m: C.term('a', 2) + C.monomial('b') if m == 'x' else sum(C.basis())\n sage: phi = D.module_morphism(on_basis, codomain=C); phi\n Generic morphism:\n From: Free module generated by {'x', 'y'} over Rational Field\n To: Free module generated by {'a', 'b', 'c'} over Rational Field\n sage: list(map(phi, D.basis()))\n [2*B['a'] + B['b'], B['a'] + B['b'] + B['c']]\n sage: F = TensorAlgebraFunctor(QQ)\n sage: Tphi = F._apply_functor_to_morphism(phi); Tphi\n Generic morphism:\n From: Tensor Algebra of Free module generated by {'x', 'y'} over Rational Field\n To: Tensor Algebra of Free module generated by {'a', 'b', 'c'} over Rational Field\n sage: G = F(D).algebra_generators()\n sage: list(map(Tphi, G))\n [2*B['a'] + B['b'], B['a'] + B['b'] + B['c']]\n sage: Tphi(sum(G))\n 3*B['a'] + 2*B['b'] + B['c']\n sage: Tphi(G['x'] * G['y'])\n 2*B['a'] # B['a'] + 2*B['a'] # B['b'] + 2*B['a'] # B['c']\n + B['b'] # B['a'] + B['b'] # B['b'] + B['b'] # B['c']\n " DB = f.domain() D = self(DB) C = self(f.codomain()) phi = (lambda m: C._tensor_constructor_([f(DB.monomial(k)) for k in m.to_word_list()])) return D.module_morphism(phi, codomain=C)
class BaseRingLift(Morphism): '\n Morphism `R \\to T(M)` which identifies the base ring `R` of a tensor\n algebra `T(M)` with the `0`-th graded part of `T(M)`.\n ' def _call_(self, x): '\n Construct the image of ``x``.\n\n TESTS::\n\n sage: C = CombinatorialFreeModule(QQ, Set([1,2]))\n sage: TA = TensorAlgebra(C)\n sage: TA(ZZ(2))\n 2\n ' T = self.codomain() R = T.base_ring() return T.term(T.indices().one(), R(x))
def repr_from_monomials(monomials, term_repr, use_latex=False): '\n Return a string representation of an element of a free module\n from the dictionary ``monomials``.\n\n INPUT:\n\n - ``monomials`` -- a list of pairs ``[m, c]`` where ``m`` is the index\n and ``c`` is the coefficient\n - ``term_repr`` -- a function which returns a string given an index\n (can be ``repr`` or ``latex``, for example)\n - ``use_latex`` -- (default: ``False``) if ``True`` then the output is\n in latex format\n\n EXAMPLES::\n\n sage: from sage.algebras.weyl_algebra import repr_from_monomials\n sage: R.<x,y,z> = QQ[]\n sage: d = [(z, 4/7), (y, sqrt(2)), (x, -5)] # needs sage.symbolic\n sage: repr_from_monomials(d, lambda m: repr(m)) # needs sage.symbolic\n \'4/7*z + sqrt(2)*y - 5*x\'\n sage: a = repr_from_monomials(d, lambda m: latex(m), True); a # needs sage.symbolic\n \\frac{4}{7} z + \\sqrt{2} y - 5 x\n sage: type(a) # needs sage.symbolic\n <class \'sage.misc.latex.LatexExpr\'>\n\n The zero element::\n\n sage: repr_from_monomials([], lambda m: repr(m))\n \'0\'\n sage: a = repr_from_monomials([], lambda m: latex(m), True); a\n 0\n sage: type(a)\n <class \'sage.misc.latex.LatexExpr\'>\n\n A "unity" element::\n\n sage: repr_from_monomials([(1, 1)], lambda m: repr(m))\n \'1\'\n sage: a = repr_from_monomials([(1, 1)], lambda m: latex(m), True); a\n 1\n sage: type(a)\n <class \'sage.misc.latex.LatexExpr\'>\n\n ::\n\n sage: repr_from_monomials([(1, -1)], lambda m: repr(m))\n \'-1\'\n sage: a = repr_from_monomials([(1, -1)], lambda m: latex(m), True); a\n -1\n sage: type(a)\n <class \'sage.misc.latex.LatexExpr\'>\n\n Leading minus signs are dealt with appropriately::\n\n sage: # needs sage.symbolic\n sage: d = [(z, -4/7), (y, -sqrt(2)), (x, -5)]\n sage: repr_from_monomials(d, lambda m: repr(m))\n \'-4/7*z - sqrt(2)*y - 5*x\'\n sage: a = repr_from_monomials(d, lambda m: latex(m), True); a\n -\\frac{4}{7} z - \\sqrt{2} y - 5 x\n sage: type(a)\n <class \'sage.misc.latex.LatexExpr\'>\n\n Indirect doctests using a class that uses this function::\n\n sage: R.<x,y> = QQ[]\n sage: A = CliffordAlgebra(QuadraticForm(R, 3, [x,0,-1,3,-4,5]))\n sage: a,b,c = A.gens()\n sage: a*b*c\n e0*e1*e2\n sage: b*c\n e1*e2\n sage: (a*a + 2)\n x + 2\n sage: c*(a*a + 2)*b\n (-x - 2)*e1*e2 - 4*x - 8\n sage: latex(c*(a*a + 2)*b)\n \\left( -x - 2 \\right) e_{1} e_{2} - 4 x - 8\n ' if (not monomials): if use_latex: return latex(0) else: return '0' ret = '' for (m, c) in monomials: term = term_repr(m) if use_latex: coeff = latex(c) else: coeff = repr(c) if ((not term) or (term == '1')): term = coeff elif (coeff == '-1'): term = ('-' + term) elif (coeff != '1'): atomic_repr = c.parent()._repr_option('element_is_atomic') if ((not atomic_repr) and ((coeff.find('+') != (- 1)) or (coeff.rfind('-') > 0))): if use_latex: term = ((('\\left(' + coeff) + '\\right) ') + term) elif (coeff not in ['', '-']): term = ((('(' + coeff) + ')*') + term) elif use_latex: term = ((coeff + ' ') + term) else: term = ((coeff + '*') + term) if ret: if (term[0] == '-'): ret += (' - ' + term[1:]) else: ret += (' + ' + term) else: ret = term return ret
def repr_factored(w, latex_output=False): "\n Return a string representation of ``w`` with the `dx_i` generators\n factored on the right.\n\n EXAMPLES::\n\n sage: from sage.algebras.weyl_algebra import repr_factored\n sage: R.<t> = QQ[]\n sage: D = DifferentialWeylAlgebra(R)\n sage: t, dt = D.gens()\n sage: x = dt^3*t^3 + dt^2*t^4\n sage: x\n t^3*dt^3 + t^4*dt^2 + 9*t^2*dt^2 + 8*t^3*dt + 18*t*dt + 12*t^2 + 6\n sage: print(repr_factored(x))\n (12*t^2 + 6) + (8*t^3 + 18*t)*dt + (t^4 + 9*t^2)*dt^2 + (t^3)*dt^3\n sage: repr_factored(x, True)\n (12 t^{2} + 6) + (8 t^{3} + 18 t) \\frac{\\partial}{\\partial t}\n + (t^{4} + 9 t^{2}) \\frac{\\partial^{2}}{\\partial t^{2}}\n + (t^{3}) \\frac{\\partial^{3}}{\\partial t^{3}}\n sage: repr_factored(D.zero())\n '0'\n\n With multiple variables::\n\n sage: R.<x,y,z> = QQ[]\n sage: D = DifferentialWeylAlgebra(R)\n sage: x, y, z, dx, dy, dz = D.gens()\n sage: elt = dx^3*x^3 + (y^3-z*x)*dx^3 + dy^3*x^3 + dx*dy*dz*x*y*z\n sage: elt\n x^3*dy^3 + x*y*z*dx*dy*dz + y^3*dx^3 + x^3*dx^3 - x*z*dx^3 + y*z*dy*dz\n + x*z*dx*dz + x*y*dx*dy + 9*x^2*dx^2 + z*dz + y*dy + 19*x*dx + 7\n sage: print(repr_factored(elt))\n (7) + (z)*dz + (y)*dy + (y*z)*dy*dz + (x^3)*dy^3 + (19*x)*dx\n + (x*z)*dx*dz + (x*y)*dx*dy + (x*y*z)*dx*dy*dz\n + (9*x^2)*dx^2 + (x^3 + y^3 - x*z)*dx^3\n sage: repr_factored(D.zero(), True)\n 0\n " f = w.factor_differentials() gens = w.parent().polynomial_ring().gens() if latex_output: def exp(e): return ('^{{{}}}'.format(e) if (e > 1) else '') def repr_dx(k): total = sum(k) if (total == 0): return '' denom = ' '.join(('\\partial {}{}'.format(latex(g), exp(e)) for (e, g) in zip(k, gens) if (e != 0))) return ''.join(' \\frac{{\\partial{}}}{{{}}}'.format(exp(total), denom)) repr_x = latex else: def exp(e): return ('^{}'.format(e) if (e > 1) else '') def repr_dx(k): return ''.join(('*d{}{}'.format(g, exp(e)) for (e, g) in zip(k, gens) if (e != 0))) repr_x = repr ret = ' + '.join(('({}){}'.format(repr_x(f[k]), repr_dx(k)) for k in sorted(f))) if (not ret): ret = '0' if latex_output: return LatexExpr(ret) return ret
class DifferentialWeylAlgebraElement(AlgebraElement): '\n An element in a differential Weyl algebra.\n ' def __init__(self, parent, monomials): '\n Initialize ``self``.\n\n TESTS::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: elt = ((x^3-z)*dx + dy)^2\n sage: TestSuite(elt).run()\n ' AlgebraElement.__init__(self, parent) self.__monomials = monomials def _repr_(self): '\n Return a string representation of ``self``.\n\n TESTS::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: ((x^3-z)*dx + dy)^2\n dy^2 + 2*x^3*dx*dy - 2*z*dx*dy + x^6*dx^2 - 2*x^3*z*dx^2\n + z^2*dx^2 + 3*x^5*dx - 3*x^2*z*dx\n ' if self.parent().options.factor_representation: return repr_factored(self, False) def term(m): ret = '' for (i, power) in enumerate((m[0] + m[1])): if (power == 0): continue name = self.parent().variable_names()[i] if ret: ret += '*' if (power == 1): ret += '{}'.format(name) else: ret += '{}^{}'.format(name, power) return ret return repr_from_monomials(self.list(), term) def _latex_(self): "\n Return a `\\LaTeX` representation of ``self``.\n\n TESTS::\n\n sage: R = PolynomialRing(QQ, 'x', 3)\n sage: W = DifferentialWeylAlgebra(R)\n sage: x0,x1,x2,dx0,dx1,dx2 = W.gens()\n sage: latex( ((x0^3-x2)*dx0 + dx1)^2 )\n \\frac{\\partial^{2}}{\\partial x_{1}^{2}}\n + 2 x_{0}^{3} \\frac{\\partial^{2}}{\\partial x_{0} \\partial x_{1}}\n - 2 x_{2} \\frac{\\partial^{2}}{\\partial x_{0} \\partial x_{1}}\n + x_{0}^{6} \\frac{\\partial^{2}}{\\partial x_{0}^{2}}\n - 2 x_{0}^{3} x_{2} \\frac{\\partial^{2}}{\\partial x_{0}^{2}}\n + x_{2}^{2} \\frac{\\partial^{2}}{\\partial x_{0}^{2}}\n + 3 x_{0}^{5} \\frac{\\partial}{\\partial x_{0}}\n - 3 x_{0}^{2} x_{2} \\frac{\\partial}{\\partial x_{0}}\n " if self.parent().options.factor_representation: return repr_factored(self, True) def exp(e): return ('^{{{}}}'.format(e) if (e > 1) else '') def term(m): R = self.parent()._poly_ring def half_term(mon, polynomial): total = sum(mon) if (total == 0): return '1' ret = ' '.join((('{}{}'.format(latex(R.gen(i)), exp(power)) if polynomial else '\\partial {}{}'.format(latex(R.gen(i)), exp(power))) for (i, power) in enumerate(mon) if (power > 0))) if (not polynomial): return '\\frac{{\\partial{}}}{{{}}}'.format(exp(total), ret) return ret p = half_term(m[0], True) d = half_term(m[1], False) if (p == '1'): return d elif (d == '1'): return p else: return ((p + ' ') + d) return repr_from_monomials(self.list(), term, True) def _richcmp_(self, other, op): '\n Rich comparison for equal parents.\n\n TESTS::\n\n sage: R.<x,y,z> = QQ[]\n sage: W = DifferentialWeylAlgebra(R)\n sage: dx,dy,dz = W.differentials()\n sage: dy*(x^3-y*z)*dx == -z*dx + x^3*dx*dy - y*z*dx*dy\n True\n sage: W.zero() == 0\n True\n sage: W.one() == 1\n True\n sage: x == 1\n False\n sage: x + 1 == 1\n False\n sage: W(x^3 - y*z) == x^3 - y*z\n True\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: dx != dy\n True\n sage: W.one() != 1\n False\n ' return richcmp(self.__monomials, other.__monomials, op) def __neg__(self): '\n Return the negative of ``self``.\n\n EXAMPLES::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: dy - (3*x - z)*dx\n dy + z*dx - 3*x*dx\n ' return self.__class__(self.parent(), {m: (- c) for (m, c) in self.__monomials.items()}) def _add_(self, other): '\n Return ``self`` added to ``other``.\n\n EXAMPLES::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: (dx*dy) + dz + x^3 - 2\n dx*dy + dz + x^3 - 2\n ' F = self.parent() return self.__class__(F, blas.add(self.__monomials, other.__monomials)) def _mul_(self, other): '\n Return ``self`` multiplied by ``other``.\n\n EXAMPLES::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: dx*(x*y + z)\n x*y*dx + z*dx + y\n sage: ((x^3-z)*dx + dy) * (dx*dz^2 - 10*x)\n dx*dy*dz^2 + x^3*dx^2*dz^2 - z*dx^2*dz^2 - 10*x*dy - 10*x^4*dx\n + 10*x*z*dx - 10*x^3 + 10*z\n ' add_tuples = (lambda x, y: tuple(((a + y[i]) for (i, a) in enumerate(x)))) d = {} n = self.parent()._n t = tuple(([0] * n)) zero = self.parent().base_ring().zero() for ml in self.__monomials: cl = self.__monomials[ml] for mr in other.__monomials: cr = other.__monomials[mr] cur = [((mr[0], t), (cl * cr))] for (i, p) in enumerate(ml[1]): for _ in range(p): next = [] for (m, c) in cur: diff = list(m[1]) diff[i] += 1 next.append(((m[0], tuple(diff)), c)) if (m[0][i] != 0): poly = list(m[0]) c *= poly[i] poly[i] -= 1 next.append(((tuple(poly), m[1]), c)) cur = next for (m, c) in cur: m = (add_tuples(ml[0], m[0]), add_tuples(mr[1], m[1])) d[m] = (d.get(m, zero) + c) if (d[m] == zero): del d[m] return self.__class__(self.parent(), d) def _rmul_(self, other): '\n Multiply ``self`` on the right side of ``other``.\n\n EXAMPLES::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: a = (x*y + z) * dx\n sage: 3/2 * a\n 3/2*x*y*dx + 3/2*z*dx\n ' if (other == 0): return self.parent().zero() M = self.__monomials return self.__class__(self.parent(), {t: (other * M[t]) for t in M}) def _lmul_(self, other): '\n Multiply ``self`` on the left side of ``other``.\n\n EXAMPLES::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: a = (x*y + z) * dx\n sage: a * 3/2\n 3/2*x*y*dx + 3/2*z*dx\n ' if (other == 0): return self.parent().zero() M = self.__monomials return self.__class__(self.parent(), {t: (M[t] * other) for t in M}) def monomial_coefficients(self, copy=True): '\n Return a dictionary which has the basis keys in the support\n of ``self`` as keys and their corresponding coefficients\n as values.\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: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: elt = (dy - (3*x - z)*dx)\n sage: sorted(elt.monomial_coefficients().items())\n [(((0, 0, 0), (0, 1, 0)), 1),\n (((0, 0, 1), (1, 0, 0)), 1),\n (((1, 0, 0), (1, 0, 0)), -3)]\n ' if copy: return dict(self.__monomials) return self.__monomials def __iter__(self): '\n Return an iterator of ``self``.\n\n This is the iterator of ``self.list()``.\n\n EXAMPLES::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: list(dy - (3*x - z)*dx)\n [(((0, 0, 0), (0, 1, 0)), 1),\n (((0, 0, 1), (1, 0, 0)), 1),\n (((1, 0, 0), (1, 0, 0)), -3)]\n ' return iter(self.list()) def list(self): '\n Return ``self`` as a list.\n\n This list consists of pairs `(m, c)`, where `m` is a pair of\n tuples indexing a basis element of ``self``, and `c` is the\n coordinate of ``self`` corresponding to this basis element.\n (Only nonzero coordinates are shown.)\n\n EXAMPLES::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: elt = dy - (3*x - z)*dx\n sage: elt.list()\n [(((0, 0, 0), (0, 1, 0)), 1),\n (((0, 0, 1), (1, 0, 0)), 1),\n (((1, 0, 0), (1, 0, 0)), -3)]\n ' return sorted(self.__monomials.items(), key=(lambda x: ((- sum(x[0][1])), x[0][1], (- sum(x[0][0])), x[0][0]))) def support(self): '\n Return the support of ``self``.\n\n EXAMPLES::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: elt = dy - (3*x - z)*dx + 1\n sage: sorted(elt.support())\n [((0, 0, 0), (0, 0, 0)),\n ((0, 0, 0), (0, 1, 0)),\n ((0, 0, 1), (1, 0, 0)),\n ((1, 0, 0), (1, 0, 0))]\n ' return list(self.__monomials) def __truediv__(self, x): '\n Division by coefficients.\n\n EXAMPLES::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: x / 2\n 1/2*x\n sage: W.<x,y,z> = DifferentialWeylAlgebra(ZZ)\n sage: a = 2*x + 4*y*z\n sage: a / 2\n 2*y*z + x\n ' F = self.parent() D = self.__monomials if F.base_ring().is_field(): x = F.base_ring()(x) x_inv = (x ** (- 1)) D = blas.linear_combination([(D, x_inv)]) return self.__class__(F, D) return self.__class__(F, {t: D[t]._divide_if_possible(x) for t in D}) def factor_differentials(self): '\n Return a dict representing ``self`` with the differentials\n factored out.\n\n EXAMPLES::\n\n sage: R.<t> = QQ[]\n sage: D = DifferentialWeylAlgebra(R)\n sage: t, dt = D.gens()\n sage: x = dt^3*t^3 + dt^2*t^4\n sage: x\n t^3*dt^3 + t^4*dt^2 + 9*t^2*dt^2 + 8*t^3*dt + 18*t*dt + 12*t^2 + 6\n sage: x.factor_differentials()\n {(0,): 12*t^2 + 6, (1,): 8*t^3 + 18*t, (2,): t^4 + 9*t^2, (3,): t^3}\n sage: D.zero().factor_differentials()\n {}\n\n sage: R.<x,y,z> = QQ[]\n sage: D = DifferentialWeylAlgebra(R)\n sage: x, y, z, dx, dy, dz = D.gens()\n sage: elt = dx^3*x^3 + (y^3-z*x)*dx^3 + dy^3*x^3 + dx*dy*dz*x*y*z\n sage: elt\n x^3*dy^3 + x*y*z*dx*dy*dz + y^3*dx^3 + x^3*dx^3 - x*z*dx^3 + y*z*dy*dz\n + x*z*dx*dz + x*y*dx*dy + 9*x^2*dx^2 + z*dz + y*dy + 19*x*dx + 7\n sage: elt.factor_differentials()\n {(0, 0, 0): 7,\n (0, 0, 1): z,\n (0, 1, 0): y,\n (0, 1, 1): y*z,\n (0, 3, 0): x^3,\n (1, 0, 0): 19*x,\n (1, 0, 1): x*z,\n (1, 1, 0): x*y,\n (1, 1, 1): x*y*z,\n (2, 0, 0): 9*x^2,\n (3, 0, 0): x^3 + y^3 - x*z}\n ' ret = {} DW = self.parent() P = DW.polynomial_ring() gens = P.gens() for (m, c) in self: (x, dx) = m if (dx not in ret): ret[dx] = P.zero() ret[dx] += (c * prod(((g ** e) for (e, g) in zip(x, gens)))) return ret def diff(self, p): '\n Apply this differential operator to a polynomial.\n\n INPUT:\n\n - ``p`` -- polynomial of the underlying polynomial ring\n\n OUTPUT:\n\n The result of the left action of the Weyl algebra on the polynomial\n ring via differentiation.\n\n EXAMPLES::\n\n sage: R.<x,y> = QQ[]\n sage: W = R.weyl_algebra()\n sage: dx, dy = W.differentials()\n sage: dx.diff(x^3)\n 3*x^2\n sage: (dx*dy).diff(W(x^3*y^3))\n 9*x^2*y^2\n sage: (x*dx + dy + 1).diff(x^4*y^4 + 1)\n 5*x^4*y^4 + 4*x^4*y^3 + 1\n ' return self.parent().diff_action(self, p)
class DifferentialWeylAlgebra(Algebra, UniqueRepresentation): "\n The differential Weyl algebra of a polynomial ring.\n\n Let `R` be a commutative ring. The (differential) Weyl algebra `W` is\n the algebra generated by `x_1, x_2, \\ldots x_n, \\partial_{x_1},\n \\partial_{x_2}, \\ldots, \\partial_{x_n}` subject to the relations:\n `[x_i, x_j] = 0`, `[\\partial_{x_i}, \\partial_{x_j}] = 0`, and\n `\\partial_{x_i} x_j = x_j \\partial_{x_i} + \\delta_{ij}`. Therefore\n `\\partial_{x_i}` is acting as the partial differential operator on `x_i`.\n\n The Weyl algebra can also be constructed as an iterated Ore extension\n of the polynomial ring `R[x_1, x_2, \\ldots, x_n]` by adding `x_i` at\n each step. It can also be seen as a quantization of the symmetric algebra\n `Sym(V)`, where `V` is a finite dimensional vector space over a field\n of characteristic zero, by using a modified Groenewold-Moyal\n product in the symmetric algebra.\n\n The Weyl algebra (even for `n = 1`) over a field of characteristic 0\n has many interesting properties.\n\n - It's a non-commutative domain.\n - It's a simple ring (but not in positive characteristic) that is not\n a matrix ring over a division ring.\n - It has no finite-dimensional representations.\n - It's a quotient of the universal enveloping algebra of the\n Heisenberg algebra `\\mathfrak{h}_n`.\n\n REFERENCES:\n\n - :wikipedia:`Weyl_algebra`\n\n INPUT:\n\n - ``R`` -- a (polynomial) ring\n - ``names`` -- (default: ``None``) if ``None`` and ``R`` is a\n polynomial ring, then the variable names correspond to\n those of ``R``; otherwise if ``names`` is specified, then ``R``\n is the base ring\n\n EXAMPLES:\n\n There are two ways to create a Weyl algebra, the first is from\n a polynomial ring::\n\n sage: R.<x,y,z> = QQ[]\n sage: W = DifferentialWeylAlgebra(R); W\n Differential Weyl algebra of polynomials in x, y, z over Rational Field\n\n We can call ``W.inject_variables()`` to give the polynomial ring\n variables, now as elements of ``W``, and the differentials::\n\n sage: W.inject_variables()\n Defining x, y, z, dx, dy, dz\n sage: (dx * dy * dz) * (x^2 * y * z + x * z * dy + 1)\n x*z*dx*dy^2*dz + z*dy^2*dz + x^2*y*z*dx*dy*dz + dx*dy*dz\n + x*dx*dy^2 + 2*x*y*z*dy*dz + dy^2 + x^2*z*dx*dz + x^2*y*dx*dy\n + 2*x*z*dz + 2*x*y*dy + x^2*dx + 2*x\n\n Or directly by specifying a base ring and variable names::\n\n sage: W.<a,b> = DifferentialWeylAlgebra(QQ); W\n Differential Weyl algebra of polynomials in a, b over Rational Field\n\n .. TODO::\n\n Implement the :meth:`graded_algebra` as a polynomial ring once\n they are considered to be graded rings (algebras).\n " @staticmethod def __classcall__(cls, R, names=None): "\n Normalize input to ensure a unique representation.\n\n EXAMPLES::\n\n sage: W1.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: W2 = DifferentialWeylAlgebra(QQ['x,y,z'])\n sage: W1 is W2\n True\n " if isinstance(R, (PolynomialRing_general, MPolynomialRing_base)): if (names is None): names = R.variable_names() R = R.base_ring() elif (names is None): raise ValueError('the names must be specified') elif (R not in Rings().Commutative()): raise TypeError('argument R must be a commutative ring') return super().__classcall__(cls, R, names) def __init__(self, R, names=None): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: R.<x,y,z> = QQ[]\n sage: W = DifferentialWeylAlgebra(R)\n sage: TestSuite(W).run()\n ' self._n = len(names) self._poly_ring = PolynomialRing(R, names) names = (names + tuple((('d' + n) for n in names))) if (len(names) != (self._n * 2)): raise ValueError("variable names cannot differ by a leading 'd'") if R.is_field(): cat = AlgebrasWithBasis(R).NoZeroDivisors().Super() else: cat = AlgebrasWithBasis(R).Super() Algebra.__init__(self, R, names, category=cat) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: R.<x,y,z> = QQ[]\n sage: DifferentialWeylAlgebra(R)\n Differential Weyl algebra of polynomials in x, y, z over Rational Field\n ' poly_gens = ', '.join((repr(x) for x in self.gens()[:self._n])) return 'Differential Weyl algebra of polynomials in {} over {}'.format(poly_gens, self.base_ring()) class options(GlobalOptions): '\n Sets the global options for elements of the differential Weyl\n algebra class. The default is to have the factored\n representations turned off.\n\n @OPTIONS@\n\n If no parameters are set, then the function returns a copy of the\n options dictionary.\n\n EXAMPLES::\n\n sage: R.<t> = QQ[]\n sage: D = DifferentialWeylAlgebra(R)\n sage: t,dt = D.gens()\n sage: x = dt^3*t^3 + dt^2*t^4\n sage: x\n t^3*dt^3 + t^4*dt^2 + 9*t^2*dt^2 + 8*t^3*dt + 18*t*dt + 12*t^2 + 6\n\n sage: D.options.factor_representation = True\n sage: x\n (12*t^2 + 6) + (8*t^3 + 18*t)*dt + (t^4 + 9*t^2)*dt^2 + (t^3)*dt^3\n\n sage: D.options._reset()\n ' NAME = 'DifferentialWeylAlgebra' module = 'sage.algebras.weyl_algebra' factor_representation = {'default': False, 'description': 'Controls whether to factor the differentials out or not in the output representations', 'checker': (lambda x: (x in [True, False]))} def _element_constructor_(self, x): '\n Construct an element of ``self`` from ``x``.\n\n EXAMPLES::\n\n sage: R.<x,y,z> = QQ[]\n sage: W = DifferentialWeylAlgebra(R)\n sage: a = W(2); a\n 2\n sage: a.parent() is W\n True\n sage: W(x^2 - y*z)\n -y*z + x^2\n ' t = tuple(([0] * self._n)) if (x in self.base_ring()): if (x == self.base_ring().zero()): return self.zero() return self.element_class(self, {(t, t): x}) if isinstance(x, DifferentialWeylAlgebraElement): R = self.base_ring() if (x.parent().base_ring() is R): return self.element_class(self, dict(x)) zero = R.zero() return self.element_class(self, {i: R(c) for (i, c) in x if (R(c) != zero)}) x = self._poly_ring(x) return self.element_class(self, {(tuple(m), t): c for (m, c) in x.dict().items()}) def _coerce_map_from_(self, R): "\n Return data which determines if there is a coercion map\n from ``R`` to ``self``.\n\n If such a map exists, the output could be a map, callable,\n or ``True``, which constructs a generic map. Otherwise the output\n must be ``False`` or ``None``.\n\n EXAMPLES::\n\n sage: R.<x,y,z> = QQ[]\n sage: W = DifferentialWeylAlgebra(R)\n sage: W._coerce_map_from_(R)\n True\n sage: W._coerce_map_from_(QQ)\n True\n sage: W._coerce_map_from_(ZZ['x'])\n True\n\n Order of the names matter::\n\n sage: Wp = DifferentialWeylAlgebra(QQ['x,z,y'])\n sage: W.has_coerce_map_from(Wp)\n False\n sage: Wp.has_coerce_map_from(W)\n False\n\n Zero coordinates are handled appropriately::\n\n sage: R.<x,y,z> = ZZ[]\n sage: W3 = DifferentialWeylAlgebra(GF(3)['x,y,z'])\n sage: W3.has_coerce_map_from(R)\n True\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(ZZ)\n sage: W3.has_coerce_map_from(W)\n True\n sage: W3(3*x + y)\n y\n " if self._poly_ring.has_coerce_map_from(R): return True if isinstance(R, DifferentialWeylAlgebra): return ((R.variable_names() == self.variable_names()) and self.base_ring().has_coerce_map_from(R.base_ring())) return super()._coerce_map_from_(R) def degree_on_basis(self, i): '\n Return the degree of the basis element indexed by ``i``.\n\n EXAMPLES::\n\n sage: W.<a,b> = DifferentialWeylAlgebra(QQ)\n sage: W.degree_on_basis( ((1, 3, 2), (0, 1, 3)) )\n 10\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: dx,dy,dz = W.differentials()\n sage: elt = y*dy - (3*x - z)*dx\n sage: elt.degree()\n 2\n ' return (sum(i[0]) + sum(i[1])) def polynomial_ring(self): '\n Return the associated polynomial ring of ``self``.\n\n EXAMPLES::\n\n sage: W.<a,b> = DifferentialWeylAlgebra(QQ)\n sage: W.polynomial_ring()\n Multivariate Polynomial Ring in a, b over Rational Field\n\n ::\n\n sage: R.<x,y,z> = QQ[]\n sage: W = DifferentialWeylAlgebra(R)\n sage: W.polynomial_ring() == R\n True\n ' return self._poly_ring @cached_method def basis(self): '\n Return a basis of ``self``.\n\n EXAMPLES::\n\n sage: W.<x,y> = DifferentialWeylAlgebra(QQ)\n sage: B = W.basis()\n sage: it = iter(B)\n sage: [next(it) for i in range(20)]\n [1, x, y, dx, dy, x^2, x*y, x*dx, x*dy, y^2, y*dx, y*dy,\n dx^2, dx*dy, dy^2, x^3, x^2*y, x^2*dx, x^2*dy, x*y^2]\n sage: dx, dy = W.differentials()\n sage: sorted((dx*x).monomials(), key=str)\n [1, x*dx]\n sage: B[(x*y).support()[0]]\n x*y\n sage: sorted((dx*x).monomial_coefficients().items())\n [(((0, 0), (0, 0)), 1), (((1, 0), (1, 0)), 1)]\n ' n = self._n from sage.combinat.integer_lists.nn import IntegerListsNN elt_map = (lambda u: (tuple(u[:n]), tuple(u[n:]))) I = IntegerListsNN(length=(2 * n), element_constructor=elt_map) one = self.base_ring().one() f = (lambda x: self.element_class(self, {(x[0], x[1]): one})) return Family(I, f, name='basis map') @cached_method def algebra_generators(self): "\n Return the algebra generators of ``self``.\n\n .. SEEALSO::\n\n :meth:`variables`, :meth:`differentials`\n\n EXAMPLES::\n\n sage: R.<x,y,z> = QQ[]\n sage: W = DifferentialWeylAlgebra(R)\n sage: W.algebra_generators()\n Finite family {'x': x, 'y': y, 'z': z, 'dx': dx, 'dy': dy, 'dz': dz}\n " d = {x: self.gen(i) for (i, x) in enumerate(self.variable_names())} return Family(self.variable_names(), (lambda x: d[x])) @cached_method def variables(self): "\n Return the variables of ``self``.\n\n .. SEEALSO::\n\n :meth:`algebra_generators`, :meth:`differentials`\n\n EXAMPLES::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: W.variables()\n Finite family {'x': x, 'y': y, 'z': z}\n " N = self.variable_names()[:self._n] d = {x: self.gen(i) for (i, x) in enumerate(N)} return Family(N, (lambda x: d[x])) @cached_method def differentials(self): "\n Return the differentials of ``self``.\n\n .. SEEALSO::\n\n :meth:`algebra_generators`, :meth:`variables`\n\n EXAMPLES::\n\n sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)\n sage: W.differentials()\n Finite family {'dx': dx, 'dy': dy, 'dz': dz}\n " N = self.variable_names()[self._n:] d = {x: self.gen((self._n + i)) for (i, x) in enumerate(N)} return Family(N, (lambda x: d[x])) def gen(self, i): '\n Return the ``i``-th generator of ``self``.\n\n .. SEEALSO::\n\n :meth:`algebra_generators`\n\n EXAMPLES::\n\n sage: R.<x,y,z> = QQ[]\n sage: W = DifferentialWeylAlgebra(R)\n sage: [W.gen(i) for i in range(6)]\n [x, y, z, dx, dy, dz]\n ' P = ([0] * self._n) D = ([0] * self._n) if (i < self._n): P[i] = 1 else: D[(i - self._n)] = 1 return self.element_class(self, {(tuple(P), tuple(D)): self.base_ring().one()}) def ngens(self): '\n Return the number of generators of ``self``.\n\n EXAMPLES::\n\n sage: R.<x,y,z> = QQ[]\n sage: W = DifferentialWeylAlgebra(R)\n sage: W.ngens()\n 6\n ' return (self._n * 2) @cached_method def one(self): '\n Return the multiplicative identity element `1`.\n\n EXAMPLES::\n\n sage: R.<x,y,z> = QQ[]\n sage: W = DifferentialWeylAlgebra(R)\n sage: W.one()\n 1\n ' t = tuple(([0] * self._n)) return self.element_class(self, {(t, t): self.base_ring().one()}) @cached_method def zero(self): '\n Return the additive identity element `0`.\n\n EXAMPLES::\n\n sage: R.<x,y,z> = QQ[]\n sage: W = DifferentialWeylAlgebra(R)\n sage: W.zero()\n 0\n ' return self.element_class(self, {}) @lazy_attribute def diff_action(self): '\n Left action of this Weyl algebra on the underlying polynomial ring by\n differentiation.\n\n EXAMPLES::\n\n sage: R.<x,y> = QQ[]\n sage: W = R.weyl_algebra()\n sage: dx, dy = W.differentials()\n sage: W.diff_action\n Left action by Differential Weyl algebra of polynomials in x, y\n over Rational Field on Multivariate Polynomial Ring in x, y over\n Rational Field\n sage: W.diff_action(dx^2 + dy + 1, x^3*y^3)\n x^3*y^3 + 3*x^3*y^2 + 6*x*y^3\n ' return DifferentialWeylAlgebraAction(self) Element = DifferentialWeylAlgebraElement
class DifferentialWeylAlgebraAction(Action): '\n Left action of a Weyl algebra on its underlying polynomial ring by\n differentiation.\n\n EXAMPLES::\n\n sage: R.<x,y> = QQ[]\n sage: W = R.weyl_algebra()\n sage: dx, dy = W.differentials()\n sage: W.diff_action\n Left action by Differential Weyl algebra of polynomials in x, y\n over Rational Field on Multivariate Polynomial Ring in x, y over\n Rational Field\n\n ::\n\n sage: g = dx^2 + x*dy\n sage: p = x^5 + x^3 + y^2*x^2 + 1\n sage: W.diff_action(g, p)\n 2*x^3*y + 20*x^3 + 2*y^2 + 6*x\n\n The action is a left action::\n\n sage: h = dx*x + x*y\n sage: W.diff_action(h, W.diff_action(g, p)) == W.diff_action(h*g, p)\n True\n\n The action endomorphism of a differential operator::\n\n sage: dg = W.diff_action(g); dg\n Action of dx^2 + x*dy on Multivariate Polynomial Ring in x, y over\n Rational Field under Left action by Differential Weyl algebra...\n sage: dg(p) == W.diff_action(g, p) == g.diff(p)\n True\n ' def __init__(self, G): '\n INPUT:\n\n - ``G`` -- Weyl algebra\n\n EXAMPLES::\n\n sage: from sage.algebras.weyl_algebra import DifferentialWeylAlgebraAction\n sage: W.<x,y> = DifferentialWeylAlgebra(QQ)\n sage: DifferentialWeylAlgebraAction(W)\n Left action by Differential Weyl algebra of polynomials in x, y\n over Rational Field on Multivariate Polynomial Ring in x, y over\n Rational Field\n ' super().__init__(G, G.polynomial_ring(), is_left=True) def _act_(self, g, x): '\n Apply a differential operator to a polynomial.\n\n EXAMPLES::\n\n sage: W.<x,y> = DifferentialWeylAlgebra(QQ)\n sage: dx, dy = W.differentials()\n sage: W.diff_action(dx^3 + dx, x^3*y^3 + x*y)\n 3*x^2*y^3 + 6*y^3 + y\n ' f = (g * x) D = {y: c for ((y, dy), c) in f.monomial_coefficients(copy=False).items() if all(((dyi == 0) for dyi in dy))} return self.right_domain()(D)
class Yangian(CombinatorialFreeModule): "\n The Yangian `Y(\\mathfrak{gl}_n)`.\n\n Let `A` be a commutative ring with unity. The *Yangian*\n `Y(\\mathfrak{gl}_n)`, associated with the Lie algebra `\\mathfrak{gl}_n`\n for `n \\geq 1`, is defined to be the unital associative algebra\n generated by `\\{t_{ij}^{(r)} \\mid 1 \\leq i,j \\leq n , r \\geq 1\\}`\n subject to the relations\n\n .. MATH::\n\n [t_{ij}^{(M+1)}, t_{k\\ell}^{(L)}] - [t_{ij}^{(M)}, t_{k\\ell}^{(L+1)}]\n = t_{kj}^{(M)} t_{i\\ell}^{(L)} - t_{kj}^{(L)} t_{i\\ell}^{(M)},\n\n where `L,M \\geq 0` and `t_{ij}^{(0)} = \\delta_{ij} \\cdot 1`. This\n system of quadratic relations is equivalent to the system of\n commutation relations\n\n .. MATH::\n\n [t_{ij}^{(r)}, t_{k\\ell}^{(s)}] =\n \\sum_{p=0}^{\\min\\{r,s\\}-1} \\bigl(t_{kj}^{(p)} t_{i\\ell}^{(r+s-1-p)}\n - t_{kj}^{(r+s-1-p)} t_{i\\ell}^{(p)} \\bigr),\n\n where `1 \\leq i,j,k,\\ell \\leq n` and `r,s \\geq 1`.\n\n Let `u` be a formal variable and, for\n `1 \\leq i,j \\leq n`, define\n\n .. MATH::\n\n t_{ij}(u) = \\delta_{ij} + \\sum_{r=1}^\\infty t_{ij}^{(r)} u^{-r}\n \\in Y(\\mathfrak{gl}_n)[\\![u^{-1}]\\!].\n\n Thus, we can write the defining relations as\n\n .. MATH::\n\n \\begin{aligned}\n (u - v)[t_{ij}(u), t_{k\\ell}(v)] & = t_{kj}(u) t_{i\\ell}(v)\n - t_{kj}(v) t_{i\\ell}(u).\n \\end{aligned}\n\n These series can be combined into a single matrix:\n\n .. MATH::\n\n T(u) := \\sum_{i,j=1}^n t_{ij}(u) \\otimes E_{ij} \\in Y(\\mathfrak{gl}_n)\n [\\![u^{-1}]\\!] \\otimes \\operatorname{End}(\\CC^n),\n\n where `E_{ij}` is the matrix with a `1` in the `(i,j)` position\n and zeros elsewhere.\n\n For `m \\geq 2`, define formal variables `u_1, \\ldots, u_m`.\n For any `1 \\leq k \\leq m`, set\n\n .. MATH::\n\n T_k(u_k) := \\sum_{i,j=1}^n t_{ij}(u_k) \\otimes (E_{ij})_k \\in\n Y(\\mathfrak{gl}_n)[\\![u_1^{-1},\\dots,u_m^{-1}]\\!] \\otimes\n \\operatorname{End}(\\CC^n)^{\\otimes m},\n\n where `(E_{ij})_k = 1^{\\otimes (k-1)} \\otimes E_{ij} \\otimes\n 1^{\\otimes (m-k)}`. If we consider `m = 2`, we can then also write\n the defining relations as\n\n .. MATH::\n\n R(u - v) T_1(u) T_2(v) = T_2(v) T_1(u) R(u - v),\n\n where `R(u) = 1 - Pu^{-1}` and `P` is the permutation operator that\n swaps the two factors. Moreover, we can write the Hopf algebra\n structure as\n\n .. MATH::\n\n \\Delta \\colon T(u) \\mapsto T_{[1]}(u) T_{[2]}(u),\n \\qquad\n S \\colon T(u) \\mapsto T^{-1}(u),\n \\qquad\n \\epsilon \\colon T(u) \\mapsto 1,\n\n where `T_{[a]} = \\sum_{i,j=1}^n (1^{\\otimes a-1} \\otimes t_{ij}(u)\n \\otimes 1^{2-a}) \\otimes (E_{ij})_1`.\n\n We can also impose two filtrations on `Y(\\mathfrak{gl}_n)`: the\n *natural* filtration `\\deg t_{ij}^{(r)} = r` and the *loop*\n filtration `\\deg t_{ij}^{(r)} = r - 1`. The natural filtration has\n a graded homomorphism with `U(\\mathfrak{gl}_n)` by\n `t_{ij}^{(r)} \\mapsto (E^r)_{ij}` and an associated graded algebra\n being polynomial algebra. Moreover, this shows a PBW theorem for\n the Yangian, that for any fixed order, we can write elements as\n unique linear combinations of ordered monomials using `t_{ij}^{(r)}`.\n For the loop filtration, the associated graded algebra is isomorphic\n (as Hopf algebras) to `U(\\mathfrak{gl}_n[z])` given by\n `\\overline{t}_{ij}^{(r)} \\mapsto E_{ij} x^{r-1}`, where\n `\\overline{t}_{ij}^{(r)}` is the image of `t_{ij}^{(r)}` in the\n `(r - 1)`-th component of `\\operatorname{gr}Y(\\mathfrak{gl}_n)`.\n\n INPUT:\n\n - ``base_ring`` -- the base ring\n - ``n`` -- the size `n`\n - ``level`` -- (optional) the level of the Yangian\n - ``variable_name`` -- (default: ``'t'``) the name of the variable\n - ``filtration`` -- (default: ``'loop'``) the filtration and can be\n one of the following:\n\n * ``'natural'`` -- the filtration is given by `\\deg t_{ij}^{(r)} = r`\n * ``'loop'`` -- the filtration is given by `\\deg t_{ij}^{(r)} = r - 1`\n\n .. TODO::\n\n Implement the antipode.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: t = Y.algebra_generators()\n sage: t[6,2,1] * t[2,3,2]\n -t(1)[2,2]*t(6)[3,1] + t(1)[3,1]*t(6)[2,2]\n + t(2)[3,2]*t(6)[2,1] - t(7)[3,1]\n sage: t[6,2,1] * t[3,1,4]\n t(1)[1,1]*t(7)[2,4] + t(1)[1,4]*t(6)[2,1] - t(1)[2,1]*t(6)[1,4]\n - t(1)[2,4]*t(7)[1,1] + t(2)[1,1]*t(6)[2,4] - t(2)[2,4]*t(6)[1,1]\n + t(3)[1,4]*t(6)[2,1] + t(6)[2,4] + t(8)[2,4]\n\n We check that the natural filtration has a homomorphism\n to `U(\\mathfrak{gl}_n)` as algebras::\n\n sage: Y = Yangian(QQ, 4, filtration='natural')\n sage: t = Y.algebra_generators()\n sage: gl4 = lie_algebras.gl(QQ, 4)\n sage: Ugl4 = gl4.pbw_basis()\n sage: E = matrix(Ugl4, 4, 4, Ugl4.gens())\n sage: Esq = E^2\n sage: t[2,1,3] * t[1,2,1]\n t(1)[2,1]*t(2)[1,3] - t(2)[2,3]\n sage: Esq[0,2] * E[1,0] == E[1,0] * Esq[0,2] - Esq[1,2]\n True\n\n sage: Em = [E^k for k in range(1,5)]\n sage: S = list(t.some_elements())[:30:3]\n sage: def convert(x):\n ....: return sum(c * prod(Em[t[0]-1][t[1]-1,t[2]-1] ** e\n ....: for t,e in m._sorted_items())\n ....: for m,c in x)\n sage: for x in S:\n ....: for y in S:\n ....: ret = x * y\n ....: rhs = convert(x) * convert(y)\n ....: assert rhs == convert(ret)\n ....: assert ret.maximal_degree() == rhs.maximal_degree()\n\n REFERENCES:\n\n - :wikipedia:`Yangian`\n - [MNO1994]_\n - [Mol2007]_\n " @staticmethod def __classcall_private__(cls, base_ring, n, level=None, variable_name='t', filtration='loop'): '\n Return the correct parent based upon input.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: Y2 = Yangian(QQ, 4)\n sage: Y is Y2\n True\n sage: YL = Yangian(QQ, 4, 3)\n sage: YL2 = Yangian(QQ, 4, 3)\n sage: YL is YL2\n True\n ' if (filtration not in ['natural', 'loop']): raise ValueError('invalid filtration') if (level is not None): return YangianLevel(base_ring, n, level, variable_name, filtration) return super().__classcall__(cls, base_ring, n, variable_name=variable_name, filtration=filtration) def __init__(self, base_ring, n, variable_name, filtration): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4, filtration=\'loop\')\n sage: TestSuite(Y).run(skip="_test_antipode") # Not implemented\n sage: Y = Yangian(QQ, 4, filtration=\'natural\')\n sage: G = Y.algebra_generators()\n sage: elts = [Y.one(), G[1,2,2], G[1,1,4], G[3,3,1], G[1,2,1]*G[2,1,4]]\n sage: TestSuite(Y).run(elements=elts) # long time\n ' self._n = n self._filtration = filtration category = HopfAlgebrasWithBasis(base_ring).Filtered() if (filtration == 'natural'): category = category.Connected() self._index_set = tuple(range(1, (n + 1))) indices = cartesian_product([PositiveIntegers(), self._index_set, self._index_set]) basis_keys = IndexedFreeAbelianMonoid(indices, bracket=False, prefix=variable_name) CombinatorialFreeModule.__init__(self, base_ring, basis_keys, sorting_key=Yangian._term_key, prefix=variable_name, category=category) def _repr_(self): "\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: Yangian(QQ, 4)\n Yangian of gl(4) in the loop filtration over Rational Field\n sage: Yangian(QQ, 4, filtration='natural')\n Yangian of gl(4) in the natural filtration over Rational Field\n " return 'Yangian of gl({}) in the {} filtration over {}'.format(self._n, self._filtration, self.base_ring()) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: latex(Yangian(QQ, 4))\n Y(\\mathfrak{gl}_{4}, \\Bold{Q})\n ' from sage.misc.latex import latex return 'Y(\\mathfrak{{gl}}_{{{}}}, {})'.format(self._n, latex(self.base_ring())) @staticmethod def _term_key(x): '\n Compute a key for ``x`` for comparisons.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: x = Y.gen(2, 1, 1).leading_support()\n sage: Yangian._term_key(x)\n (-1, [((2, 1, 1), 1)])\n ' return ((- len(x)), x._sorted_items()) def _repr_term(self, m): "\n Return a string representation of the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: I = Y._indices\n sage: Y._repr_term(I.gen((3,1,2))^2 * I.gen((4,3,1)))\n 't(3)[1,2]^2*t(4)[3,1]'\n sage: Y._repr_term(Y.one_basis())\n '1'\n " if (len(m) == 0): return '1' prefix = self.prefix() return '*'.join((((prefix + '({})[{},{}]'.format(r, i, j)) + ('^{}'.format(exp) if (exp > 1) else '')) for ((r, i, j), exp) in m._sorted_items())) def _latex_term(self, m): "\n Return a `\\LaTeX` representation of the basis element indexed\n by ``m``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: I = Y._indices\n sage: Y._latex_term(I.gen((3,1,2))^2 * I.gen((4,3,1)))\n '\\\\left(t^{(3)}_{1,2}\\\\right)^{2} t^{(4)}_{3,1}'\n sage: Y._latex_term(Y.one_basis())\n '1'\n " if (len(m) == 0): return '1' prefix = self.prefix() def term(r, i, j, exp): s = (prefix + '^{{({})}}_{{{},{}}}'.format(r, i, j)) if (exp == 1): return s return '\\left({}\\right)^{{{}}}'.format(s, exp) return ' '.join((term(r, i, j, exp) for ((r, i, j), exp) in m._sorted_items())) def _element_constructor_(self, x): "\n Construct an element of ``self`` from ``x``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: Yn = Yangian(QQ, 4, filtration='natural')\n sage: Yn(Y.an_element()) == Yn.an_element()\n True\n sage: Y(Yn.an_element()) == Y.an_element()\n True\n sage: Y6 = Yangian(QQ, 4, level=6, filtration='natural')\n sage: Y(Y6.an_element())\n t(1)[1,1]^2*t(1)[1,2]^2*t(1)[1,3]^3 + 2*t(1)[1,1] + 3*t(1)[1,2] + 1\n " if isinstance(x, CombinatorialFreeModule.Element): if (isinstance(x.parent(), Yangian) and (x.parent()._n <= self._n)): R = self.base_ring() return self._from_dict({i: R(c) for (i, c) in x}, coerce=False) return super()._element_constructor_(x) def gen(self, r, i=None, j=None): '\n Return the generator `t^{(r)}_{ij}` of ``self``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: Y.gen(2, 1, 3)\n t(2)[1,3]\n sage: Y.gen(12, 2, 1)\n t(12)[2,1]\n sage: Y.gen(0, 1, 1)\n 1\n sage: Y.gen(0, 1, 3)\n 0\n ' if ((i is None) and (j is None)): (r, i, j) = r if (r == 0): if (i == j): return self.one() return self.zero() m = self._indices.gen((r, i, j)) return self.element_class(self, {m: self.base_ring().one()}) @cached_method def algebra_generators(self): '\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: Y.algebra_generators()\n Lazy family (generator(i))_{i in The Cartesian product of\n (Positive integers, {1, 2, 3, 4}, {1, 2, 3, 4})}\n ' return Family(self._indices._indices, self.gen, name='generator') @cached_method def one_basis(self): '\n Return the basis index of the element `1`.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: Y.one_basis()\n 1\n ' return self._indices.one() def degree_on_basis(self, m): "\n Return the degree of the monomial index by ``m``.\n\n The degree of `t_{ij}^{(r)}` is equal to `r - 1` if ``filtration =\n 'loop'`` and is equal to `r` if ``filtration = 'natural'``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: Y.degree_on_basis(Y.gen(2,1,1).leading_support())\n 1\n sage: x = Y.gen(5,2,3)^4\n sage: Y.degree_on_basis(x.leading_support())\n 16\n sage: elt = Y.gen(10,3,1) * Y.gen(2,1,1) * Y.gen(1,2,4); elt\n t(1)[1,1]*t(1)[2,4]*t(10)[3,1] - t(1)[2,4]*t(1)[3,1]*t(10)[1,1]\n + t(1)[2,4]*t(2)[1,1]*t(10)[3,1] + t(1)[2,4]*t(10)[3,1]\n + t(1)[2,4]*t(11)[3,1]\n sage: for s in sorted(elt.support(), key=str): s, Y.degree_on_basis(s)\n (t(1, 1, 1)*t(1, 2, 4)*t(10, 3, 1), 9)\n (t(1, 2, 4)*t(1, 3, 1)*t(10, 1, 1), 9)\n (t(1, 2, 4)*t(10, 3, 1), 9)\n (t(1, 2, 4)*t(11, 3, 1), 10)\n (t(1, 2, 4)*t(2, 1, 1)*t(10, 3, 1), 10)\n\n sage: Y = Yangian(QQ, 4, filtration='natural')\n sage: Y.degree_on_basis(Y.gen(2,1,1).leading_support())\n 2\n sage: x = Y.gen(5,2,3)^4\n sage: Y.degree_on_basis(x.leading_support())\n 20\n sage: elt = Y.gen(10,3,1) * Y.gen(2,1,1) * Y.gen(1,2,4)\n sage: for s in sorted(elt.support(), key=str): s, Y.degree_on_basis(s)\n (t(1, 1, 1)*t(1, 2, 4)*t(10, 3, 1), 12)\n (t(1, 2, 4)*t(1, 3, 1)*t(10, 1, 1), 12)\n (t(1, 2, 4)*t(10, 3, 1), 11)\n (t(1, 2, 4)*t(11, 3, 1), 12)\n (t(1, 2, 4)*t(2, 1, 1)*t(10, 3, 1), 13)\n " if (self._filtration == 'natural'): return sum(((r[0][0] * r[1]) for r in m._monomial.items())) return sum(((max(0, (r[0][0] - 1)) * r[1]) for r in m._monomial.items())) def graded_algebra(self): "\n Return the associated graded algebra of ``self``.\n\n EXAMPLES::\n\n sage: Yangian(QQ, 4).graded_algebra()\n Graded Algebra of Yangian of gl(4) in the loop filtration over Rational Field\n sage: Yangian(QQ, 4, filtration='natural').graded_algebra()\n Graded Algebra of Yangian of gl(4) in the natural filtration over Rational Field\n " if (self._filtration == 'natural'): return GradedYangianNatural(self) return GradedYangianLoop(self) def dimension(self): '\n Return the dimension of ``self``, which is `\\infty`.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: Y.dimension()\n +Infinity\n ' return infinity @cached_method def product_on_basis(self, x, y): '\n Return the product of two monomials given by ``x`` and ``y``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: Y.gen(12, 2, 1) * Y.gen(2, 1, 1) # indirect doctest\n t(1)[1,1]*t(12)[2,1] - t(1)[2,1]*t(12)[1,1]\n + t(2)[1,1]*t(12)[2,1] + t(12)[2,1] + t(13)[2,1]\n ' if (len(x) == 0): return self.monomial(y) if (len(y) == 0): return self.monomial(x) if (x.trailing_support() <= y.leading_support()): return self.monomial((x * y)) if (len(x) != 1): I = self._indices cur = self.monomial(y) for (gen, exp) in reversed(x._sorted_items()): for _ in range(exp): cur = (self.monomial(I.gen(gen)) * cur) return cur if (len(y) == 1): return self.product_on_gens(tuple(x.support()[0]), tuple(y.support()[0])) I = self._indices cur = self.monomial(x) for (gen, exp) in y._sorted_items(): for _ in range(exp): cur = (cur * self.monomial(I.gen(gen))) return cur @cached_method def product_on_gens(self, a, b): '\n Return the product on two generators indexed by ``a`` and ``b``.\n\n We assume `(r, i, j) \\geq (s, k, \\ell)`, and we start with the basic\n relation:\n\n .. MATH::\n\n [t_{ij}^{(r)}, t_{k\\ell}^{(s)}] - [t_{ij}^{(r-1)}, t_{k\\ell}^{(s+1)}]\n = t_{kj}^{(r-1)} t_{i\\ell}^{(s)} - t_{kj}^{(s)} t_{i\\ell}^{(r-1)}.\n\n Solving for the first term and using induction we get:\n\n .. MATH::\n\n [t_{ij}^{(r)}, t_{k\\ell}^{(s)}] = \\sum_{a=1}^s \\left(\n t_{kj}^{(a-1)} t_{i\\ell}^{(r+s-a)} - t_{kj}^{(r+s-a)}\n t_{i\\ell}^{(a-1)} \\right).\n\n Next applying induction on this we get\n\n .. MATH::\n\n t_{ij}^{(r)} t_{k\\ell}^{(s)} = t_{k\\ell}^{(s)} t_{ij}^{(r)} +\n \\sum C_{abcd}^{m\\ell} t_{ab}^{(m)} t_{cd}^{(\\ell)}\n\n where `m + \\ell < r + s` and `t_{ab}^{(m)} < t_{cd}^{(\\ell)}`.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: Y.product_on_gens((2,1,1), (12,2,1))\n t(2)[1,1]*t(12)[2,1]\n sage: Y.gen(2, 1, 1) * Y.gen(12, 2, 1)\n t(2)[1,1]*t(12)[2,1]\n sage: Y.product_on_gens((12,2,1), (2,1,1))\n t(1)[1,1]*t(12)[2,1] - t(1)[2,1]*t(12)[1,1]\n + t(2)[1,1]*t(12)[2,1] + t(12)[2,1] + t(13)[2,1]\n sage: Y.gen(12, 2, 1) * Y.gen(2, 1, 1)\n t(1)[1,1]*t(12)[2,1] - t(1)[2,1]*t(12)[1,1]\n + t(2)[1,1]*t(12)[2,1] + t(12)[2,1] + t(13)[2,1]\n ' I = self._indices if (a <= b): return self.monomial((I.gen(a) * I.gen(b))) x1 = self.zero() if (b[1] == a[2]): x1 += self.monomial(I.gen((((a[0] + b[0]) - 1), a[1], b[2]))) if (a[1] == b[2]): x1 -= self.monomial(I.gen((((a[0] + b[0]) - 1), b[1], a[2]))) return ((self.monomial((I.gen(b) * I.gen(a))) + x1) + self.sum(((self.monomial((I.gen(((x - 1), b[1], a[2])) * I.gen((((a[0] + b[0]) - x), a[1], b[2])))) - self.product_on_gens((((a[0] + b[0]) - x), b[1], a[2]), ((x - 1), a[1], b[2]))) for x in range(2, (b[0] + 1))))) def coproduct_on_basis(self, m): '\n Return the coproduct on the basis element indexed by ``m``.\n\n The coproduct `\\Delta\\colon Y(\\mathfrak{gl}_n) \\longrightarrow\n Y(\\mathfrak{gl}_n) \\otimes Y(\\mathfrak{gl}_n)` is defined by\n\n .. MATH::\n\n \\Delta(t_{ij}(u)) = \\sum_{a=1}^n t_{ia}(u) \\otimes t_{aj}(u).\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: Y.gen(2,1,1).coproduct() # indirect doctest\n 1 # t(2)[1,1] + t(1)[1,1] # t(1)[1,1] + t(1)[1,2] # t(1)[2,1]\n + t(1)[1,3] # t(1)[3,1] + t(1)[1,4] # t(1)[4,1] + t(2)[1,1] # 1\n sage: Y.gen(2,3,1).coproduct()\n 1 # t(2)[3,1] + t(1)[3,1] # t(1)[1,1] + t(1)[3,2] # t(1)[2,1]\n + t(1)[3,3] # t(1)[3,1] + t(1)[3,4] # t(1)[4,1] + t(2)[3,1] # 1\n sage: Y.gen(2,2,3).coproduct()\n 1 # t(2)[2,3] + t(1)[2,1] # t(1)[1,3] + t(1)[2,2] # t(1)[2,3]\n + t(1)[2,3] # t(1)[3,3] + t(1)[2,4] # t(1)[4,3] + t(2)[2,3] # 1\n ' T = self.tensor_square() I = self._indices return T.prod((((T.monomial((I.one(), I.gen((a[0], a[1], a[2])))) + T.monomial((I.gen((a[0], a[1], a[2])), I.one()))) + T.sum_of_terms([((I.gen((s, a[1], k)), I.gen(((a[0] - s), k, a[2]))), 1) for k in range(1, (self._n + 1)) for s in range(1, a[0])])) for (a, exp) in m._sorted_items() for p in range(exp))) def counit_on_basis(self, m): '\n Return the counit on the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4)\n sage: Y.gen(2,3,1).counit() # indirect doctest\n 0\n sage: Y.gen(0,0,0).counit()\n 1\n ' if (len(m) == 0): return self.base_ring().one() return self.base_ring().zero()
class YangianLevel(Yangian): '\n The Yangian `Y_{\\ell}(\\mathfrak{gl_n})` of level `\\ell`.\n\n The Yangian of level `\\ell` is the quotient of the Yangian\n `Y(\\mathfrak{gl}_n)` by the two-sided ideal generated by `t_{ij}^{(r)}`\n for all `r > p` and all `i,j \\in \\{1, \\ldots, n\\}`.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4, 3)\n sage: elt = Y.gen(3,2,1) * Y.gen(1,1,3)\n sage: elt * Y.gen(1, 1, 2)\n t(1)[1,2]*t(1)[1,3]*t(3)[2,1] + t(1)[1,2]*t(3)[2,3]\n - t(1)[1,3]*t(3)[1,1] + t(1)[1,3]*t(3)[2,2] - t(3)[1,3]\n ' def __init__(self, base_ring, n, level, variable_name, filtration): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4, 3)\n sage: TestSuite(Y).run(skip="_test_antipode")\n ' self._level = level self._n = n self._filtration = filtration category = HopfAlgebrasWithBasis(base_ring).Filtered() self._index_set = tuple(range(1, (n + 1))) L = range(1, (self._level + 1)) indices = cartesian_product([L, self._index_set, self._index_set]) basis_keys = IndexedFreeAbelianMonoid(indices, bracket=False, prefix=variable_name) CombinatorialFreeModule.__init__(self, base_ring, basis_keys, prefix=variable_name, category=category) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: Yangian(QQ, 4, 3)\n Yangian of level 3 of gl(4) in the loop filtration over Rational Field\n ' return 'Yangian of level {} of gl({}) in the {} filtration over {}'.format(self._level, self._n, self._filtration, self.base_ring()) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: latex(Yangian(QQ, 4, level=5))\n Y_{5}(\\mathfrak{gl}_{4}, \\Bold{Q})\n ' from sage.misc.latex import latex return 'Y_{{{}}}(\\mathfrak{{gl}}_{{{}}}, {})'.format(self._level, self._n, latex(self.base_ring())) def _coerce_map_from_(self, R): "\n Return ``True`` or the coercion if there exists a coerce\n map from ``R``.\n\n EXAMPLES::\n\n sage: Y5 = Yangian(QQ, 7, level=5)\n sage: Y = Yangian(QQ, 3)\n sage: Y5._coerce_map_from_(Y)\n Generic morphism:\n From: Yangian of gl(3) in the loop filtration over Rational Field\n To: Yangian of level 5 of gl(7) in the loop filtration over Rational Field\n sage: phi = Y5.coerce_map_from(Y)\n sage: x = Y.gen(5,2,1) * Y.gen(4,3,2)\n sage: phi(x)\n -t(1)[2,2]*t(5)[3,1] + t(1)[3,1]*t(5)[2,2]\n - t(2)[2,1]*t(5)[3,2] + t(2)[3,2]*t(5)[2,1]\n - t(3)[2,2]*t(5)[3,1] + t(3)[3,1]*t(5)[2,2]\n + t(4)[3,2]*t(5)[2,1]\n\n sage: Y = Yangian(QQ, 10)\n sage: Y5.has_coerce_map_from(Y)\n False\n\n sage: Y10 = Yangian(QQ, 4, level=10)\n sage: phi = Y5.coerce_map_from(Y10); phi\n Generic morphism:\n From: Yangian of level 10 of gl(4) in the loop filtration over Rational Field\n To: Yangian of level 5 of gl(7) in the loop filtration over Rational Field\n sage: x = Y10.gen(5,2,1) * Y10.gen(4,3,2)\n sage: phi(x)\n -t(1)[2,2]*t(5)[3,1] + t(1)[3,1]*t(5)[2,2]\n - t(2)[2,1]*t(5)[3,2] + t(2)[3,2]*t(5)[2,1]\n - t(3)[2,2]*t(5)[3,1] + t(3)[3,1]*t(5)[2,2]\n + t(4)[3,2]*t(5)[2,1]\n\n sage: Y = Yangian(QQ, 3, filtration='natural')\n sage: Y5.has_coerce_map_from(Y)\n False\n " if (isinstance(R, Yangian) and (R._n <= self._n) and (R._filtration == self._filtration)): if (isinstance(R, YangianLevel) and (self._level > R._level)): return False on_gens = (lambda m: self.prod(((self.gen(*a) ** exp) for (a, exp) in m._sorted_items()))) return R.module_morphism(on_gens, codomain=self) return super()._coerce_map_from_(R) def level(self): '\n Return the level of ``self``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 3, 5)\n sage: Y.level()\n 5\n ' return self._level def defining_polynomial(self, i, j, u=None): '\n Return the defining polynomial of ``i`` and ``j``.\n\n The defining polynomial is given by:\n\n .. MATH::\n\n T_{ij}(u) = \\delta_{ij} u^{\\ell} + \\sum_{k=1}^{\\ell} t_{ij}^{(k)}\n u^{\\ell-k}.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 3, 5)\n sage: Y.defining_polynomial(3, 2)\n t(1)[3,2]*u^4 + t(2)[3,2]*u^3 + t(3)[3,2]*u^2 + t(4)[3,2]*u + t(5)[3,2]\n sage: Y.defining_polynomial(1, 1)\n u^5 + t(1)[1,1]*u^4 + t(2)[1,1]*u^3 + t(3)[1,1]*u^2 + t(4)[1,1]*u + t(5)[1,1]\n ' if (u is None): u = PolynomialRing(self.base_ring(), 'u').gen(0) ell = self._level return sum(((self.gen(k, i, j) * (u ** (ell - k))) for k in range((ell + 1)))) def quantum_determinant(self, u=None): '\n Return the quantum determinant of ``self``.\n\n The quantum determinant is defined by:\n\n .. MATH::\n\n \\operatorname{qdet}(u) = \\sum_{\\sigma \\in S_n} (-1)^{\\sigma}\n \\prod_{k=1}^n T_{\\sigma(k),k}(u - k + 1).\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 2, 2)\n sage: Y.quantum_determinant()\n u^4 + (-2 + t(1)[1,1] + t(1)[2,2])*u^3\n + (1 - t(1)[1,1] + t(1)[1,1]*t(1)[2,2] - t(1)[1,2]*t(1)[2,1]\n - 2*t(1)[2,2] + t(2)[1,1] + t(2)[2,2])*u^2\n + (-t(1)[1,1]*t(1)[2,2] + t(1)[1,1]*t(2)[2,2]\n + t(1)[1,2]*t(1)[2,1] - t(1)[1,2]*t(2)[2,1]\n - t(1)[2,1]*t(2)[1,2] + t(1)[2,2] + t(1)[2,2]*t(2)[1,1]\n - t(2)[1,1] - t(2)[2,2])*u\n - t(1)[1,1]*t(2)[2,2] + t(1)[1,2]*t(2)[2,1] + t(2)[1,1]*t(2)[2,2]\n - t(2)[1,2]*t(2)[2,1] + t(2)[2,2]\n ' if (u is None): u = PolynomialRing(self.base_ring(), 'u').gen(0) from sage.combinat.permutation import Permutations n = self._n return sum(((p.sign() * prod((self.defining_polynomial(p[k], (k + 1), (u - k)) for k in range(n)))) for p in Permutations(n))) def gen(self, r, i=None, j=None): '\n Return the generator `t^{(r)}_{ij}` of ``self``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4, 3)\n sage: Y.gen(2, 1, 3)\n t(2)[1,3]\n sage: Y.gen(12, 2, 1)\n 0\n sage: Y.gen(0, 1, 1)\n 1\n sage: Y.gen(0, 1, 3)\n 0\n ' if ((i is None) and (j is None)): (r, i, j) = r if (r > self._level): return self.zero() return Yangian.gen(self, r, i, j) @cached_method def gens(self): '\n Return the generators of ``self``.\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 2, 2)\n sage: Y.gens()\n (t(1)[1,1], t(2)[1,1], t(1)[1,2], t(2)[1,2], t(1)[2,1],\n t(2)[2,1], t(1)[2,2], t(2)[2,2])\n ' return tuple((self.gen(r, i, j) for i in range(1, (self._n + 1)) for j in range(1, (self._n + 1)) for r in range(1, (self._level + 1)))) @cached_method def product_on_gens(self, a, b): '\n Return the product on two generators indexed by ``a`` and ``b``.\n\n .. SEEALSO::\n\n :meth:`Yangian.product_on_gens()`\n\n EXAMPLES::\n\n sage: Y = Yangian(QQ, 4, 3)\n sage: Y.gen(1,2,2) * Y.gen(2,1,3) # indirect doctest\n t(1)[2,2]*t(2)[1,3]\n sage: Y.gen(1,2,1) * Y.gen(2,1,3) # indirect doctest\n t(1)[2,1]*t(2)[1,3]\n sage: Y.gen(3,2,1) * Y.gen(1,1,3) # indirect doctest\n t(1)[1,3]*t(3)[2,1] + t(3)[2,3]\n ' I = self._indices if (a <= b): return self.monomial((I.gen(a) * I.gen(b))) x1 = self.zero() if (((a[0] + b[0]) - 1) <= self._level): if (b[1] == a[2]): x1 += self.monomial(I.gen((((a[0] + b[0]) - 1), a[1], b[2]))) if (a[1] == b[2]): x1 -= self.monomial(I.gen((((a[0] + b[0]) - 1), b[1], a[2]))) return ((self.monomial((I.gen(b) * I.gen(a))) + x1) + self.sum(((self.monomial((I.gen(((x - 1), b[1], a[2])) * I.gen((((a[0] + b[0]) - x), a[1], b[2])))) - self.product_on_gens((((a[0] + b[0]) - x), b[1], a[2]), ((x - 1), a[1], b[2]))) for x in range(2, (b[0] + 1)) if (((a[0] + b[0]) - x) <= self._level))))
class GradedYangianBase(AssociatedGradedAlgebra): '\n Base class for graded algebras associated to a Yangian.\n ' def _repr_term(self, m): "\n Return a string representation of the monomial indexed by ``m``.\n\n EXAMPLES::\n\n sage: grY = Yangian(QQ, 4).graded_algebra()\n sage: I = grY._indices\n sage: grY._repr_term(I.gen((3,1,2))^2 * I.gen((4,3,1)))\n 'tbar(3)[1,2]^2*tbar(4)[3,1]'\n " if (len(m) == 0): return '1' prefix = self.prefix() return '*'.join((((prefix + '({})[{},{}]'.format(r, i, j)) + ('^{}'.format(exp) if (exp > 1) else '')) for ((r, i, j), exp) in m._sorted_items())) def _latex_term(self, m): "\n Return a latex representation of the monomial indexed by ``m``.\n\n EXAMPLES::\n\n sage: grY = Yangian(QQ, 4).graded_algebra()\n sage: I = grY._indices\n sage: grY._latex_term(I.gen((3,1,2))^2 * I.gen((4,3,1)))\n '\\\\left(\\\\overline{t}^{(3)}_{1,2}\\\\right)^{2} \\\\overline{t}^{(4)}_{3,1}'\n " if (len(m) == 0): return '1' prefix = '\\overline{{{}}}'.format(self._A.prefix()) def term(r, i, j, exp): s = (prefix + '^{{({})}}_{{{},{}}}'.format(r, i, j)) if (exp == 1): return s return '\\left({}\\right)^{{{}}}'.format(s, exp) return ' '.join((term(r, i, j, exp) for ((r, i, j), exp) in m._sorted_items()))
class GradedYangianNatural(GradedYangianBase): '\n The associated graded algebra corresponding to a Yangian\n `\\operatorname{gr} Y(\\mathfrak{gl}_n)` with the natural filtration\n of `\\deg t_{ij}^{(r)} = r`.\n\n INPUT:\n\n - ``Y`` -- a Yangian with the natural filtration\n ' def __init__(self, Y): "\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: grY = Yangian(QQ, 4, filtration='natural').graded_algebra()\n sage: TestSuite(grY).run(skip='_test_antipode')\n " if (Y._filtration != 'natural'): raise ValueError('the Yangian must have the natural filtration') cat = GradedHopfAlgebrasWithBasis(Y.base_ring()).Connected().Commutative() GradedYangianBase.__init__(self, Y, cat) 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: grY = Yangian(QQ, 4, filtration='natural').graded_algebra()\n sage: x = grY.gen(12, 2, 1) * grY.gen(2, 1, 1) # indirect doctest\n sage: x\n tbar(2)[1,1]*tbar(12)[2,1]\n sage: x == grY.gen(2, 1, 1) * grY.gen(12, 2, 1)\n True\n " return self.monomial((x * y))
class GradedYangianLoop(GradedYangianBase): '\n The associated graded algebra corresponding to a Yangian\n `\\operatorname{gr} Y(\\mathfrak{gl}_n)` with the filtration\n of `\\deg t_{ij}^{(r)} = r - 1`.\n\n Using this filtration for the Yangian, the associated graded algebra\n is isomorphic to `U(\\mathfrak{gl}_n[z])`, the universal enveloping\n algebra of the loop algebra of `\\mathfrak{gl}_n`.\n\n INPUT:\n\n - ``Y`` -- a Yangian with the loop filtration\n ' def __init__(self, Y): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: grY = Yangian(QQ, 4).graded_algebra()\n sage: g = grY.indices().gens()\n sage: x = grY(g[1,1,1] * g[1,1,2]^2 * g[1,1,3]^3 * g[3,1,1])\n sage: elts = [grY(g[1,1,1]), grY(g[2,1,1]), x]\n sage: TestSuite(grY).run(elements=elts) # long time\n ' if (Y._filtration != 'loop'): raise ValueError('the Yangian must have the loop filtration') cat = GradedHopfAlgebrasWithBasis(Y.base_ring()) GradedYangianBase.__init__(self, Y, cat) def antipode_on_basis(self, m): '\n Return the antipode on a basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: grY = Yangian(QQ, 4).graded_algebra()\n sage: grY.antipode_on_basis(grY.gen(2,1,1).leading_support())\n -tbar(2)[1,1]\n\n sage: x = grY.an_element(); x\n tbar(1)[1,1]*tbar(1)[1,2]^2*tbar(1)[1,3]^3*tbar(42)[1,1]\n sage: grY.antipode_on_basis(x.leading_support())\n -tbar(1)[1,1]*tbar(1)[1,2]^2*tbar(1)[1,3]^3*tbar(42)[1,1]\n - 2*tbar(1)[1,1]*tbar(1)[1,2]*tbar(1)[1,3]^3*tbar(42)[1,2]\n - 3*tbar(1)[1,1]*tbar(1)[1,2]^2*tbar(1)[1,3]^2*tbar(42)[1,3]\n + 5*tbar(1)[1,2]^2*tbar(1)[1,3]^3*tbar(42)[1,1]\n + 10*tbar(1)[1,2]*tbar(1)[1,3]^3*tbar(42)[1,2]\n + 15*tbar(1)[1,2]^2*tbar(1)[1,3]^2*tbar(42)[1,3]\n\n sage: g = grY.indices().gens()\n sage: x = grY(g[1,1,1] * g[1,1,2]^2 * g[1,1,3]^3 * g[3,1,1]); x\n tbar(1)[1,1]*tbar(1)[1,2]^2*tbar(1)[1,3]^3*tbar(3)[1,1]\n sage: grY.antipode_on_basis(x.leading_support())\n -tbar(1)[1,1]*tbar(1)[1,2]^2*tbar(1)[1,3]^3*tbar(3)[1,1]\n - 2*tbar(1)[1,1]*tbar(1)[1,2]*tbar(1)[1,3]^3*tbar(3)[1,2]\n - 3*tbar(1)[1,1]*tbar(1)[1,2]^2*tbar(1)[1,3]^2*tbar(3)[1,3]\n + 5*tbar(1)[1,2]^2*tbar(1)[1,3]^3*tbar(3)[1,1]\n + 10*tbar(1)[1,2]*tbar(1)[1,3]^3*tbar(3)[1,2]\n + 15*tbar(1)[1,2]^2*tbar(1)[1,3]^2*tbar(3)[1,3]\n ' return self.prod(((((- 1) ** exp) * self.monomial((a ** exp))) for (a, exp) in reversed(list(m)))) def coproduct_on_basis(self, m): '\n Return the coproduct on the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: grY = Yangian(QQ, 4).graded_algebra()\n sage: grY.coproduct_on_basis(grY.gen(2,1,1).leading_support())\n 1 # tbar(2)[1,1] + tbar(2)[1,1] # 1\n sage: grY.gen(2,3,1).coproduct()\n 1 # tbar(2)[3,1] + tbar(2)[3,1] # 1\n ' T = self.tensor_square() I = self._indices one = I.one() return T.prod((T.sum_of_monomials([(one, a), (a, one)]) for (a, exp) in m for p in range(exp))) def counit_on_basis(self, m): '\n Return the antipode on the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: grY = Yangian(QQ, 4).graded_algebra()\n sage: grY.counit_on_basis(grY.gen(2,3,1).leading_support())\n 0\n sage: grY.gen(0,0,0).counit()\n 1\n ' if (len(m) == 0): return self.base_ring().one() return self.base_ring().zero()
class YokonumaHeckeAlgebra(CombinatorialFreeModule): '\n The Yokonuma-Hecke algebra `Y_{d,n}(q)`.\n\n Let `R` be a commutative ring and `q` be a unit in `R`. The\n *Yokonuma-Hecke algebra* `Y_{d,n}(q)` is the associative, unital\n `R`-algebra generated by `t_1, t_2, \\ldots, t_n, g_1, g_2, \\ldots,\n g_{n-1}` and subject to the relations:\n\n - `g_i g_j = g_j g_i` for all `|i - j| > 1`,\n - `g_i g_{i+1} g_i = g_{i+1} g_i g_{i+1}`,\n - `t_i t_j = t_j t_i`,\n - `t_j g_i = g_i t_{j s_i}`, and\n - `t_j^d = 1`,\n\n where `s_i` is the simple transposition `(i, i+1)`, along with\n the quadratic relation\n\n .. MATH::\n\n g_i^2 = 1 + \\frac{(q - q^{-1})}{d} \\left( \\sum_{s=0}^{d-1}\n t_i^s t_{i+1}^{-s} \\right) g_i.\n\n Thus the Yokonuma-Hecke algebra can be considered a quotient of\n the framed braid group `(\\ZZ / d\\ZZ) \\wr B_n`, where `B_n` is the\n classical braid group on `n` strands, by the quadratic relations.\n Moreover, all of the algebra generators are invertible. In\n particular, we have\n\n .. MATH::\n\n g_i^{-1} = g_i - (q - q^{-1}) e_i.\n\n When we specialize `q = \\pm 1`, we obtain the group algebra of\n the complex reflection group `G(d, 1, n) = (\\ZZ / d\\ZZ) \\wr S_n`.\n Moreover for `d = 1`, the Yokonuma-Hecke algebra is equal to the\n :class:`Iwahori-Hecke <IwahoriHeckeAlgebra>` of type `A_{n-1}`.\n\n INPUT:\n\n - ``d`` -- the maximum power of `t`\n - ``n`` -- the number of generators\n - ``q`` -- (optional) an invertible element in a commutative ring;\n the default is `q \\in \\QQ[q,q^{-1}]`\n - ``R`` -- (optional) a commutative ring containing ``q``; the\n default is the parent of `q`\n\n EXAMPLES:\n\n We construct `Y_{4,3}` and do some computations::\n\n sage: Y = algebras.YokonumaHecke(4, 3)\n sage: g1, g2, t1, t2, t3 = Y.algebra_generators()\n sage: g1 * g2\n g[1,2]\n sage: t1 * g1\n t1*g[1]\n sage: g2 * t2\n t3*g[2]\n sage: g2 * t3\n t2*g[2]\n sage: (g2 + t1) * (g1 + t2*t3)\n g[2,1] + t2*t3*g[2] + t1*g[1] + t1*t2*t3\n sage: g1 * g1\n 1 - (1/4*q^-1-1/4*q)*g[1] - (1/4*q^-1-1/4*q)*t1*t2^3*g[1]\n - (1/4*q^-1-1/4*q)*t1^2*t2^2*g[1] - (1/4*q^-1-1/4*q)*t1^3*t2*g[1]\n sage: g2 * g1 * t1\n t3*g[2,1]\n\n We construct the elements `e_i` and show that they are idempotents::\n\n sage: e1 = Y.e(1); e1\n 1/4 + 1/4*t1*t2^3 + 1/4*t1^2*t2^2 + 1/4*t1^3*t2\n sage: e1 * e1 == e1\n True\n sage: e2 = Y.e(2); e2\n 1/4 + 1/4*t2*t3^3 + 1/4*t2^2*t3^2 + 1/4*t2^3*t3\n sage: e2 * e2 == e2\n True\n\n REFERENCES:\n\n - [CL2013]_\n\n - [CPdA2014]_\n\n - [ERH2015]_\n\n - [JPdA15]_\n ' @staticmethod def __classcall_private__(cls, d, n, q=None, R=None): "\n Standardize input to ensure a unique representation.\n\n TESTS::\n\n sage: Y1 = algebras.YokonumaHecke(5, 3)\n sage: q = LaurentPolynomialRing(QQ, 'q').gen()\n sage: Y2 = algebras.YokonumaHecke(5, 3, q)\n sage: Y3 = algebras.YokonumaHecke(5, 3, q, q.parent())\n sage: Y1 is Y2 and Y2 is Y3\n True\n " if (q is None): q = LaurentPolynomialRing(QQ, 'q').gen() if (R is None): R = q.parent() q = R(q) if (R not in Rings().Commutative()): raise TypeError('base ring must be a commutative ring') return super().__classcall__(cls, d, n, q, R) def __init__(self, d, n, q, R): '\n Initialize ``self``.\n\n EXAMPLES::\n\n sage: Y = algebras.YokonumaHecke(5, 3)\n sage: elts = Y.some_elements() + list(Y.algebra_generators())\n sage: TestSuite(Y).run(elements=elts)\n ' self._d = d self._n = n self._q = q self._Pn = Permutations(n) import itertools C = itertools.product(*([range(d)] * n)) indices = list(itertools.product(C, self._Pn)) cat = Algebras(R).WithBasis() CombinatorialFreeModule.__init__(self, R, indices, prefix='Y', category=cat) self._assign_names(self.algebra_generators().keys()) def _repr_(self): '\n Return a string representation of ``self``.\n\n EXAMPLES::\n\n sage: algebras.YokonumaHecke(5, 2)\n Yokonuma-Hecke algebra of rank 5 and order 2 with q=q\n over Univariate Laurent Polynomial Ring in q over Rational Field\n ' return 'Yokonuma-Hecke algebra of rank {} and order {} with q={} over {}'.format(self._d, self._n, self._q, self.base_ring()) def _latex_(self): '\n Return a latex representation of ``self``.\n\n EXAMPLES::\n\n sage: Y = algebras.YokonumaHecke(5, 2)\n sage: latex(Y)\n \\mathcal{Y}_{5,2}(q)\n ' return ('\\mathcal{Y}_{%s,%s}(%s)' % (self._d, self._n, self._q)) def _repr_term(self, m): "\n Return a string representation of the basis element indexed by ``m``.\n\n EXAMPLES::\n\n sage: Y = algebras.YokonumaHecke(4, 3)\n sage: Y._repr_term( ((1, 0, 2), Permutation([3,2,1])) )\n 't1*t3^2*g[2,1,2]'\n " gen_str = (lambda e: ('' if (e == 1) else ('^%s' % e))) lhs = '*'.join(((('t%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 = 'g[{}]'.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: Y = algebras.YokonumaHecke(4, 3)\n sage: Y._latex_term( ((1, 0, 2), Permutation([3,2,1])) )\n 't_{1} t_{3}^2 g_{2} g_{1} g_{2}'\n " gen_str = (lambda e: ('' if (e == 1) else ('^%s' % e))) lhs = ' '.join(((('t_{%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((('g_{%d}' % i) for i in redword))) @cached_method def algebra_generators(self): "\n Return the algebra generators of ``self``.\n\n EXAMPLES::\n\n sage: Y = algebras.YokonumaHecke(5, 3)\n sage: dict(Y.algebra_generators())\n {'g1': g[1], 'g2': g[2], 't1': t1, 't2': t2, 't3': t3}\n " one = self._Pn.one() zero = ([0] * self._n) d = {} for i in range(self._n): r = list(zero) r[i] = 1 d[('t%s' % (i + 1))] = self.monomial((tuple(r), one)) G = self._Pn.group_generators() for i in range(1, self._n): d[('g%s' % i)] = self.monomial((tuple(zero), G[i])) return Family(sorted(d), (lambda i: d[i])) @cached_method def gens(self): '\n Return the generators of ``self``.\n\n EXAMPLES::\n\n sage: Y = algebras.YokonumaHecke(5, 3)\n sage: Y.gens()\n (g[1], g[2], t1, t2, t3)\n ' return tuple(self.algebra_generators()) @cached_method def one_basis(self): '\n Return the index of the basis element of `1`.\n\n EXAMPLES::\n\n sage: Y = algebras.YokonumaHecke(5, 3)\n sage: Y.one_basis()\n ((0, 0, 0), [1, 2, 3])\n ' one = self._Pn.one() zero = ([0] * self._n) return (tuple(zero), one) @cached_method def e(self, i): '\n Return the element `e_i`.\n\n EXAMPLES::\n\n sage: Y = algebras.YokonumaHecke(4, 3)\n sage: Y.e(1)\n 1/4 + 1/4*t1*t2^3 + 1/4*t1^2*t2^2 + 1/4*t1^3*t2\n sage: Y.e(2)\n 1/4 + 1/4*t2*t3^3 + 1/4*t2^2*t3^2 + 1/4*t2^3*t3\n ' if ((i < 1) or (i >= self._n)): raise ValueError('invalid index') c = (~ self.base_ring()(self._d)) zero = ([0] * self._n) one = self._Pn.one() d = {} for s in range(self._d): r = list(zero) r[(i - 1)] = s if (s != 0): r[i] = (self._d - s) d[(tuple(r), one)] = c return self._from_dict(d, remove_zeros=False) def g(self, i=None): '\n Return the generator(s) `g_i`.\n\n INPUT:\n\n - ``i`` -- (default: ``None``) the generator `g_i` or if ``None``,\n then the list of all generators `g_i`\n\n EXAMPLES::\n\n sage: Y = algebras.YokonumaHecke(8, 3)\n sage: Y.g(1)\n g[1]\n sage: Y.g()\n [g[1], g[2]]\n ' G = self.algebra_generators() if (i is None): return [G[('g%s' % i)] for i in range(1, self._n)] return G[('g%s' % i)] def t(self, i=None): '\n Return the generator(s) `t_i`.\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: Y = algebras.YokonumaHecke(8, 3)\n sage: Y.t(2)\n t2\n sage: Y.t()\n [t1, t2, t3]\n ' G = self.algebra_generators() if (i is None): return [G[('t%s' % i)] for i in range(1, (self._n + 1))] return G[('t%s' % i)] 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: Y = algebras.YokonumaHecke(4, 3)\n sage: m = ((1, 0, 2), Permutations(3)([2,1,3]))\n sage: 4 * Y.product_on_basis(m, m)\n -(q^-1-q)*t2^2*g[1] + 4*t1*t2 - (q^-1-q)*t1*t2*g[1]\n - (q^-1-q)*t1^2*g[1] - (q^-1-q)*t1^3*t2^3*g[1]\n\n Check that we apply the permutation correctly on `t_i`::\n\n sage: Y = algebras.YokonumaHecke(4, 3)\n sage: g1, g2, t1, t2, t3 = Y.algebra_generators()\n sage: g21 = g2 * g1\n sage: g21 * t1\n t3*g[2,1]\n ' (t1, g1) = m1 (t2, g2) = m2 t = [((t1[i] + t2[g1.index((i + 1))]) % self._d) for i in range(self._n)] one = self._Pn.one() if (g1 == one): return self.monomial((tuple(t), g2)) ret = self.monomial((tuple(t), g1)) for i in g2.reduced_word(): ret = self.linear_combination(((self._product_by_basis_gen(m, i), c) for (m, c) in ret)) return ret def _product_by_basis_gen(self, m, i): '\n Return the product `t g_w g_i`.\n\n If the quadratic relation is `g_i^2 = 1 + (q + q^{-1})e_i g_i`,\n then we have\n\n .. MATH::\n\n g_w g_i = \\begin{cases}\n g_{ws_i} & \\text{if } \\ell(ws_i) = \\ell(w) + 1, \\\\\n g_{ws_i} - (q - q^{-1}) g_w e_i & \\text{if }\n \\ell(w s_i) = \\ell(w) - 1.\n \\end{cases}\n\n INPUT:\n\n - ``m`` -- a pair ``[t, w]``, where ``t`` encodes the monomial\n and ``w`` is an element of the permutation group\n - ``i`` -- an element of the index set\n\n EXAMPLES::\n\n sage: Y = algebras.YokonumaHecke(4, 3)\n sage: m = ((1, 0, 2), Permutations(3)([2,1,3]))\n sage: 4 * Y._product_by_basis_gen(m, 1)\n -(q^-1-q)*t2*t3^2*g[1] + 4*t1*t3^2 - (q^-1-q)*t1*t3^2*g[1]\n - (q^-1-q)*t1^2*t2^3*t3^2*g[1] - (q^-1-q)*t1^3*t2^2*t3^2*g[1]\n ' (t, w) = m wi = w.apply_simple_reflection(i, side='right') if (not w.has_descent(i, side='right')): return self.monomial((t, wi)) R = self.base_ring() c = ((self._q - (~ self._q)) * (~ R(self._d))) d = {(t, wi): R.one()} for s in range(self._d): r = list(t) r[(w[(i - 1)] - 1)] = ((r[(w[(i - 1)] - 1)] + s) % self._d) if (s != 0): r[(w[i] - 1)] = (((r[(w[i] - 1)] + self._d) - s) % self._d) d[(tuple(r), w)] = c return self._from_dict(d, remove_zeros=False) @cached_method def inverse_g(self, i): '\n Return the inverse of the generator `g_i`.\n\n From the quadratic relation, we have\n\n .. MATH::\n\n g_i^{-1} = g_i - (q - q^{-1}) e_i.\n\n EXAMPLES::\n\n sage: Y = algebras.YokonumaHecke(2, 4)\n sage: [2*Y.inverse_g(i) for i in range(1, 4)]\n [(q^-1+q) + 2*g[1] + (q^-1+q)*t1*t2,\n (q^-1+q) + 2*g[2] + (q^-1+q)*t2*t3,\n (q^-1+q) + 2*g[3] + (q^-1+q)*t3*t4]\n ' if ((i < 1) or (i >= self._n)): raise ValueError('invalid index') return (self.g(i) + (((~ self._q) + self._q) * self.e(i))) class Element(CombinatorialFreeModule.Element): def __invert__(self): '\n Return the inverse if ``self`` is a basis element.\n\n EXAMPLES::\n\n sage: Y = algebras.YokonumaHecke(3, 3)\n sage: t = prod(Y.t()); t\n t1*t2*t3\n sage: t.inverse() # indirect doctest\n t1^2*t2^2*t3^2\n sage: [3*~(t*g) for g in Y.g()]\n [(q^-1+q)*t2*t3^2 + (q^-1+q)*t1*t3^2\n + (q^-1+q)*t1^2*t2^2*t3^2 + 3*t1^2*t2^2*t3^2*g[1],\n (q^-1+q)*t1^2*t3 + (q^-1+q)*t1^2*t2\n + (q^-1+q)*t1^2*t2^2*t3^2 + 3*t1^2*t2^2*t3^2*g[2]]\n\n TESTS:\n\n Check that :trac:`26424` is fixed::\n\n sage: Y = algebras.YokonumaHecke(3, 3)\n sage: t = 3 * prod(Y.t())\n sage: ~t\n 1/3*t1^2*t2^2*t3^2\n\n sage: ~Y.zero()\n Traceback (most recent call last):\n ...\n ZeroDivisionError\n ' if (not self): raise ZeroDivisionError if (len(self) != 1): raise NotImplementedError(('inverse only implemented for basis elements (monomials in the generators)' % self)) H = self.parent() (t, w) = self.support_of_term() c = (~ self.coefficients()[0]) telt = H.monomial((tuple((((H._d - e) % H._d) for e in t)), H._Pn.one())) return ((c * telt) * H.prod((H.inverse_g(i) for i in reversed(w.reduced_word()))))
def quit_sage(verbose=True): '\n Does nothing. Code that needs cleanup should register its own\n handler using the atexit module.\n ' from sage.misc.superseded import deprecation deprecation(8784, 'quit_sage is deprecated and now does nothing; please simply delete it')
def sage_globals(): "\n Return the Sage namespace.\n\n EXAMPLES::\n\n sage: 'log' in sage_globals()\n True\n sage: 'MatrixSpace' in sage_globals()\n True\n sage: 'Permutations' in sage_globals()\n True\n sage: 'TheWholeUniverse' in sage_globals()\n False\n " return globals()
def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, use_digits=None, height_bound=None, proof=False): '\n Return an irreducible polynomial of degree at most `degree` which\n is approximately satisfied by the number `z`.\n\n You can specify the number of known bits or digits of `z` with\n ``known_bits=k`` or ``known_digits=k``. PARI is then told to\n compute the result using `0.8k` of these bits/digits. Or, you can\n specify the precision to use directly with ``use_bits=k`` or\n ``use_digits=k``. If none of these are specified, then the precision\n is taken from the input value.\n\n A height bound may be specified to indicate the maximum coefficient\n size of the returned polynomial; if a sufficiently small polynomial\n is not found, then ``None`` will be returned. If ``proof=True`` then\n the result is returned only if it can be proved correct (i.e. the\n only possible minimal polynomial satisfying the height bound, or no\n such polynomial exists). Otherwise a :class:`ValueError` is raised\n indicating that higher precision is required.\n\n ALGORITHM: Uses LLL for real/complex inputs, PARI C-library\n ``algdep`` command otherwise.\n\n Note that ``algebraic_dependency`` is a synonym for ``algdep``.\n\n INPUT:\n\n\n - ``z`` - real, complex, or `p`-adic number\n\n - ``degree`` - an integer\n\n - ``height_bound`` - an integer (default: ``None``) specifying the maximum\n coefficient size for the returned polynomial\n\n - ``proof`` - a boolean (default: ``False``), requires height_bound to be set\n\n\n EXAMPLES::\n\n sage: algdep(1.888888888888888, 1) # needs sage.libs.pari\n 9*x - 17\n sage: algdep(0.12121212121212, 1) # needs sage.libs.pari\n 33*x - 4\n sage: algdep(sqrt(2), 2) # needs sage.libs.pari sage.symbolic\n x^2 - 2\n\n This example involves a complex number::\n\n sage: z = (1/2) * (1 + RDF(sqrt(3)) * CC.0); z # needs sage.symbolic\n 0.500000000000000 + 0.866025403784439*I\n sage: algdep(z, 6) # needs sage.symbolic\n x^2 - x + 1\n\n This example involves a `p`-adic number::\n\n sage: K = Qp(3, print_mode=\'series\') # needs sage.rings.padics\n sage: a = K(7/19); a # needs sage.rings.padics\n 1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12 + 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20)\n sage: algdep(a, 1) # needs sage.rings.padics\n 19*x - 7\n\n These examples show the importance of proper precision control. We\n compute a 200-bit approximation to `sqrt(2)` which is wrong in the\n 33\'rd bit::\n\n sage: # needs sage.libs.pari sage.rings.real_mpfr\n sage: z = sqrt(RealField(200)(2)) + (1/2)^33\n sage: p = algdep(z, 4); p\n 227004321085*x^4 - 216947902586*x^3 - 99411220986*x^2 + 82234881648*x - 211871195088\n sage: factor(p)\n 227004321085*x^4 - 216947902586*x^3 - 99411220986*x^2 + 82234881648*x - 211871195088\n sage: algdep(z, 4, known_bits=32)\n x^2 - 2\n sage: algdep(z, 4, known_digits=10)\n x^2 - 2\n sage: algdep(z, 4, use_bits=25)\n x^2 - 2\n sage: algdep(z, 4, use_digits=8)\n x^2 - 2\n\n Using the ``height_bound`` and ``proof`` parameters, we can see that\n `pi` is not the root of an integer polynomial of degree at most 5\n and coefficients bounded above by 10::\n\n sage: algdep(pi.n(), 5, height_bound=10, proof=True) is None # needs sage.libs.pari sage.symbolic\n True\n\n For stronger results, we need more precision::\n\n sage: # needs sage.libs.pari sage.symbolic\n sage: algdep(pi.n(), 5, height_bound=100, proof=True) is None\n Traceback (most recent call last):\n ...\n ValueError: insufficient precision for non-existence proof\n sage: algdep(pi.n(200), 5, height_bound=100, proof=True) is None\n True\n sage: algdep(pi.n(), 10, height_bound=10, proof=True) is None\n Traceback (most recent call last):\n ...\n ValueError: insufficient precision for non-existence proof\n sage: algdep(pi.n(200), 10, height_bound=10, proof=True) is None\n True\n\n We can also use ``proof=True`` to get positive results::\n\n sage: # needs sage.libs.pari sage.symbolic\n sage: a = sqrt(2) + sqrt(3) + sqrt(5)\n sage: algdep(a.n(), 8, height_bound=1000, proof=True)\n Traceback (most recent call last):\n ...\n ValueError: insufficient precision for uniqueness proof\n sage: f = algdep(a.n(1000), 8, height_bound=1000, proof=True); f\n x^8 - 40*x^6 + 352*x^4 - 960*x^2 + 576\n sage: f(a).expand()\n 0\n\n TESTS::\n\n sage: algdep(complex("1+2j"), 4) # needs sage.libs.pari sage.rings.complex_double\n x^2 - 2*x + 5\n\n We get an irreducible polynomial even if PARI returns a reducible\n one::\n\n sage: z = CDF(1, RR(3).sqrt())/2 # needs sage.rings.complex_double\n sage: pari(z).algdep(5) # needs sage.libs.pari sage.rings.complex_double sage.symbolic\n x^5 + x^2\n sage: algdep(z, 5) # needs sage.libs.pari sage.rings.complex_double sage.symbolic\n x^2 - x + 1\n\n Check that cases where a constant polynomial might look better\n get handled correctly::\n\n sage: z = CC(-1)**(1/3) # needs sage.rings.real_mpfr\n sage: algdep(z, 1) # needs sage.libs.pari sage.symbolic\n x\n\n Tests with numpy and gmpy2 numbers::\n\n sage: from numpy import int8, float64 # needs numpy\n sage: algdep(float64(1.888888888888888), int8(1)) # needs numpy sage.libs.pari\n 9*x - 17\n sage: from gmpy2 import mpz, mpfr\n sage: algdep(mpfr(1.888888888888888), mpz(1)) # needs sage.libs.pari\n 9*x - 17\n ' if (proof and (not height_bound)): raise ValueError('height_bound must be given for proof=True') R = ZZ['x'] x = R.gen() z = py_scalar_to_element(z) if isinstance(z, Integer): if (height_bound and (abs(z) >= height_bound)): return None return (x - z) degree = ZZ(degree) if isinstance(z, Rational): if (height_bound and (max(abs(z.denominator()), abs(z.numerator())) >= height_bound)): return None return ((z.denominator() * x) - z.numerator()) if isinstance(z.parent(), (RealField, ComplexField)): log2_10 = math.log(10, 2) prec = (z.prec() - 6) if (known_digits is not None): known_bits = (known_digits * log2_10) if (known_bits is not None): use_bits = (known_bits * 0.8) if (use_digits is not None): use_bits = (use_digits * log2_10) if (use_bits is not None): prec = int(use_bits) is_complex = isinstance(z.parent(), ComplexField) n = (degree + 1) from sage.matrix.constructor import matrix M = matrix(ZZ, n, ((n + 1) + int(is_complex))) r = (ZZ.one() << prec) M[(0, 0)] = 1 M[(0, (- 1))] = r for k in range(1, (degree + 1)): M[(k, k)] = 1 r *= z if is_complex: M[(k, (- 1))] = r.real().round() M[(k, (- 2))] = r.imag().round() else: M[(k, (- 1))] = r.round() LLL = M.LLL(delta=0.75) coeffs = LLL[0][:n] if all(((c == 0) for c in coeffs[1:])): coeffs = LLL[1][:n] if height_bound: def norm(v): from sage.rings.real_mpfi import RIF return v.change_ring(RIF).norm() if (max((abs(a) for a in coeffs)) > height_bound): if proof: if (norm(LLL[0]) <= (((2 ** ((n - 1) / 2)) * n.sqrt()) * height_bound)): raise ValueError('insufficient precision for non-existence proof') return None elif (proof and (norm(LLL[1]) < ((2 ** ((n - 1) / 2)) * max(norm(LLL[0]), (n.sqrt() * height_bound))))): raise ValueError('insufficient precision for uniqueness proof') if (coeffs[degree] < 0): coeffs = (- coeffs) f = list(coeffs) elif (proof or height_bound): raise NotImplementedError('proof and height bound only implemented for real and complex numbers') else: from sage.libs.pari.all import pari y = pari(z) f = y.algdep(degree) factors = [p for (p, e) in R(f).factor()] return min(factors, key=(lambda f: abs(f(z))))
def bernoulli(n, algorithm='default', num_threads=1): '\n Return the n-th Bernoulli number, as a rational number.\n\n INPUT:\n\n - ``n`` - an integer\n - ``algorithm``:\n\n - ``\'default\'`` -- use \'flint\' for n <= 20000, then \'arb\' for n <= 300000\n and \'bernmm\' for larger values (this is just a heuristic, and not guaranteed\n to be optimal on all hardware)\n - ``\'arb\'`` -- use the arb library\n - ``\'flint\'`` -- use the FLINT library\n - ``\'pari\'`` -- use the PARI C library\n - ``\'gap\'`` -- use GAP\n - ``\'gp\'`` -- use PARI/GP interpreter\n - ``\'magma\'`` -- use MAGMA (optional)\n - ``\'bernmm\'`` -- use bernmm package (a multimodular algorithm)\n\n - ``num_threads`` - positive integer, number of\n threads to use (only used for bernmm algorithm)\n\n EXAMPLES::\n\n sage: bernoulli(12) # needs sage.libs.flint\n -691/2730\n sage: bernoulli(50) # needs sage.libs.flint\n 495057205241079648212477525/66\n\n We demonstrate each of the alternative algorithms::\n\n sage: bernoulli(12, algorithm=\'arb\') # needs sage.libs.flint\n -691/2730\n sage: bernoulli(12, algorithm=\'flint\') # needs sage.libs.flint\n -691/2730\n sage: bernoulli(12, algorithm=\'gap\') # needs sage.libs.gap\n -691/2730\n sage: bernoulli(12, algorithm=\'gp\') # needs sage.libs.pari\n -691/2730\n sage: bernoulli(12, algorithm=\'magma\') # optional - magma\n -691/2730\n sage: bernoulli(12, algorithm=\'pari\') # needs sage.libs.pari\n -691/2730\n sage: bernoulli(12, algorithm=\'bernmm\') # needs sage.libs.ntl\n -691/2730\n sage: bernoulli(12, algorithm=\'bernmm\', num_threads=4) # needs sage.libs.ntl\n -691/2730\n\n TESTS::\n\n sage: algs = [] # The imports below are so that "sage -fixdoctests --probe" does not remove\n sage: import sage.libs.arb; algs += [\'arb\'] # needs sage.libs.flint\n sage: import sage.libs.gap; algs += [\'gap\'] # needs sage.libs.gap\n sage: import sage.libs.pari; algs += [\'gp\', \'pari\'] # needs sage.libs.pari\n sage: import sage.libs.ntl; algs += [\'bernmm\'] # needs sage.libs.ntl\n sage: import sage.libs.flint; algs += [\'flint\'] # needs sage.libs.flint\n sage: test_list = [ZZ.random_element(2, 2255) for _ in range(500)]\n sage: vals = [[bernoulli(i, algorithm=j) for j in algs] for i in test_list] # long time (up to 21s on sage.math, 2011)\n sage: all(len(set(x)) == 1 for x in vals) # long time (depends on previous line)\n True\n sage: algs = []\n sage: import sage.libs.pari; algs += [\'gp\', \'pari\'] # needs sage.libs.pari\n sage: import sage.libs.ntl; algs += [\'bernmm\'] # needs sage.libs.ntl\n sage: test_list = [ZZ.random_element(2256, 5000) for _ in range(500)]\n sage: vals = [[bernoulli(i, algorithm=j) for j in algs] for i in test_list] # long time (up to 30s on sage.math, 2011)\n sage: all(len(set(x))==1 for x in vals) # long time (depends on previous line)\n True\n sage: from numpy import int8 # needs numpy\n sage: bernoulli(int8(12)) # needs numpy sage.libs.flint\n -691/2730\n sage: from gmpy2 import mpz\n sage: bernoulli(mpz(12)) # needs sage.libs.flint\n -691/2730\n\n AUTHOR:\n\n - David Joyner and William Stein\n ' n = ZZ(n) if (algorithm == 'default'): if (n <= 20000): algorithm = 'flint' elif (n <= 300000): algorithm = 'arb' else: algorithm = 'bernmm' if (algorithm == 'arb'): import sage.libs.arb.arith as arb_arith return arb_arith.bernoulli(n) elif (algorithm == 'flint'): if (n >= 100000): from warnings import warn warn('flint is known to not be accurate for large Bernoulli numbers') from sage.libs.flint.arith import bernoulli_number as flint_bernoulli return flint_bernoulli(n) elif ((algorithm == 'pari') or (algorithm == 'gp')): from sage.libs.pari.all import pari x = pari(n).bernfrac() return Rational(x) elif (algorithm == 'gap'): from sage.libs.gap.libgap import libgap x = libgap.Bernoulli(n).sage() return Rational(x) elif (algorithm == 'magma'): import sage.interfaces.magma x = sage.interfaces.magma.magma(('Bernoulli(%s)' % n)) return Rational(x) elif (algorithm == 'bernmm'): import sage.rings.bernmm return sage.rings.bernmm.bernmm_bern_rat(n, num_threads) else: raise ValueError('invalid choice of algorithm')
def factorial(n, algorithm='gmp'): "\n Compute the factorial of `n`, which is the product\n `1\\cdot 2\\cdot 3 \\cdots (n-1)\\cdot n`.\n\n INPUT:\n\n - ``n`` - an integer\n\n - ``algorithm`` - string (default: 'gmp'):\n\n - ``'gmp'`` - use the GMP C-library factorial function\n\n - ``'pari'`` - use PARI's factorial function\n\n OUTPUT: an integer\n\n EXAMPLES::\n\n sage: from sage.arith.misc import factorial\n sage: factorial(0)\n 1\n sage: factorial(4)\n 24\n sage: factorial(10)\n 3628800\n sage: factorial(1) == factorial(0)\n True\n sage: factorial(6) == 6*5*4*3*2\n True\n sage: factorial(1) == factorial(0)\n True\n sage: factorial(71) == 71* factorial(70)\n True\n sage: factorial(-32)\n Traceback (most recent call last):\n ...\n ValueError: factorial -- must be nonnegative\n\n Tests with numpy and gmpy2 numbers::\n\n sage: from numpy import int8 # needs numpy\n sage: factorial(int8(4)) # needs numpy\n 24\n sage: from gmpy2 import mpz\n sage: factorial(mpz(4))\n 24\n\n PERFORMANCE: This discussion is valid as of April 2006. All timings\n below are on a Pentium Core Duo 2Ghz MacBook Pro running Linux with\n a 2.6.16.1 kernel.\n\n - It takes less than a minute to compute the factorial of\n `10^7` using the GMP algorithm, and the factorial of\n `10^6` takes less than 4 seconds.\n\n - The GMP algorithm is faster and more memory efficient than the\n PARI algorithm. E.g., PARI computes `10^7` factorial in 100\n seconds on the core duo 2Ghz.\n\n - For comparison, computation in Magma `\\leq` 2.12-10 of\n `n!` is best done using ``*[1..n]``. It takes\n 113 seconds to compute the factorial of `10^7` and 6\n seconds to compute the factorial of `10^6`. Mathematica\n V5.2 compute the factorial of `10^7` in 136 seconds and the\n factorial of `10^6` in 7 seconds. (Mathematica is notably\n very efficient at memory usage when doing factorial\n calculations.)\n " if (n < 0): raise ValueError('factorial -- must be nonnegative') if (algorithm == 'gmp'): return ZZ(n).factorial() elif (algorithm == 'pari'): from sage.libs.pari.all import pari return pari.factorial(n) else: raise ValueError('unknown algorithm')
def is_prime(n) -> bool: "\n Determine whether `n` is a prime element of its parent ring.\n\n INPUT:\n\n - ``n`` -- the object for which to determine primality\n\n Exceptional special cases:\n\n - For integers, determine whether `n` is a *positive* prime.\n - For number fields except `\\QQ`, determine whether `n`\n is a prime element *of the maximal order*.\n\n ALGORITHM:\n\n For integers, this function uses a provable primality test\n or a strong pseudo-primality test depending on the global\n :mod:`arithmetic proof flag <sage.structure.proof.proof>`.\n\n .. SEEALSO::\n\n - :meth:`is_pseudoprime`\n - :meth:`sage.rings.integer.Integer.is_prime`\n\n EXAMPLES::\n\n sage: is_prime(389)\n True\n sage: is_prime(2000)\n False\n sage: is_prime(2)\n True\n sage: is_prime(-1)\n False\n sage: is_prime(1)\n False\n sage: is_prime(-2)\n False\n\n ::\n\n sage: a = 2**2048 + 981\n sage: is_prime(a) # not tested - takes ~ 1min\n sage: proof.arithmetic(False)\n sage: is_prime(a) # instantaneous! # needs sage.libs.pari\n True\n sage: proof.arithmetic(True)\n\n TESTS:\n\n Make sure the warning from :trac:`25046` works as intended::\n\n sage: is_prime(7/1)\n doctest:warning\n ...\n UserWarning: Testing primality in Rational Field, which is a field,\n hence the result will always be False. To test whether n is a prime\n integer, use is_prime(ZZ(n)) or ZZ(n).is_prime(). Using n.is_prime()\n instead will silence this warning.\n False\n sage: ZZ(7/1).is_prime()\n True\n sage: QQ(7/1).is_prime()\n False\n\n However, number fields redefine ``.is_prime()`` in an incompatible fashion\n (cf. :trac:`32340`) and we should not warn::\n\n sage: x = polygen(ZZ, 'x')\n sage: K.<i> = NumberField(x^2 + 1) # needs sage.rings.number_field\n sage: is_prime(1 + i) # needs sage.rings.number_field\n True\n " try: ret = n.is_prime() except (AttributeError, NotImplementedError): return ZZ(n).is_prime() R = n.parent() if R.is_field(): from sage.rings.number_field.number_field_base import NumberField if ((R is QQ) or (not isinstance(R, NumberField))): import warnings s = f'Testing primality in {R}, which is a field, hence the result will always be False. ' if (R is QQ): s += 'To test whether n is a prime integer, use is_prime(ZZ(n)) or ZZ(n).is_prime(). ' s += 'Using n.is_prime() instead will silence this warning.' warnings.warn(s) return ret
def is_pseudoprime(n): '\n Test whether ``n`` is a pseudo-prime\n\n The result is *NOT* proven correct - *this is a pseudo-primality test!*.\n\n INPUT:\n\n - ``n`` -- an integer\n\n .. note::\n\n We do not consider negatives of prime numbers as prime.\n\n EXAMPLES::\n\n sage: # needs sage.libs.pari\n sage: is_pseudoprime(389)\n True\n sage: is_pseudoprime(2000)\n False\n sage: is_pseudoprime(2)\n True\n sage: is_pseudoprime(-1)\n False\n sage: factor(-6)\n -1 * 2 * 3\n sage: is_pseudoprime(1)\n False\n sage: is_pseudoprime(-2)\n False\n ' return ZZ(n).is_pseudoprime()
def is_prime_power(n, get_data=False): '\n Test whether ``n`` is a positive power of a prime number\n\n This function simply calls the method :meth:`Integer.is_prime_power()\n <sage.rings.integer.Integer.is_prime_power>` of Integers.\n\n INPUT:\n\n - ``n`` -- an integer\n\n - ``get_data`` -- if set to ``True``, return a pair ``(p,k)`` such that\n this integer equals ``p^k`` instead of ``True`` or ``(self,0)`` instead of\n ``False``\n\n EXAMPLES::\n\n sage: # needs sage.libs.pari\n sage: is_prime_power(389)\n True\n sage: is_prime_power(2000)\n False\n sage: is_prime_power(2)\n True\n sage: is_prime_power(1024)\n True\n sage: is_prime_power(1024, get_data=True)\n (2, 10)\n\n The same results can be obtained with::\n\n sage: # needs sage.libs.pari\n sage: 389.is_prime_power()\n True\n sage: 2000.is_prime_power()\n False\n sage: 2.is_prime_power()\n True\n sage: 1024.is_prime_power()\n True\n sage: 1024.is_prime_power(get_data=True)\n (2, 10)\n\n TESTS::\n\n sage: # needs sage.libs.pari\n sage: is_prime_power(-1)\n False\n sage: is_prime_power(1)\n False\n sage: is_prime_power(QQ(997^100))\n True\n sage: is_prime_power(1/2197)\n Traceback (most recent call last):\n ...\n TypeError: no conversion of this rational to integer\n sage: is_prime_power("foo")\n Traceback (most recent call last):\n ...\n TypeError: unable to convert \'foo\' to an integer\n sage: from gmpy2 import mpz\n sage: is_prime_power(mpz(389))\n True\n sage: from numpy import int16 # needs numpy\n sage: is_prime_power(int16(389)) # needs numpy\n True\n ' return ZZ(n).is_prime_power(get_data=get_data)
def is_pseudoprime_power(n, get_data=False): '\n Test if ``n`` is a power of a pseudoprime.\n\n The result is *NOT* proven correct - *this IS a pseudo-primality test!*.\n Note that a prime power is a positive power of a prime number so that 1 is\n not a prime power.\n\n INPUT:\n\n - ``n`` - an integer\n\n - ``get_data`` - (boolean) instead of a boolean return a pair `(p,k)` so\n that ``n`` equals `p^k` and `p` is a pseudoprime or `(n,0)` otherwise.\n\n EXAMPLES::\n\n sage: # needs sage.libs.pari\n sage: is_pseudoprime_power(389)\n True\n sage: is_pseudoprime_power(2000)\n False\n sage: is_pseudoprime_power(2)\n True\n sage: is_pseudoprime_power(1024)\n True\n sage: is_pseudoprime_power(-1)\n False\n sage: is_pseudoprime_power(1)\n False\n sage: is_pseudoprime_power(997^100)\n True\n\n Use of the get_data keyword::\n\n sage: # needs sage.libs.pari\n sage: is_pseudoprime_power(3^1024, get_data=True)\n (3, 1024)\n sage: is_pseudoprime_power(2^256, get_data=True)\n (2, 256)\n sage: is_pseudoprime_power(31, get_data=True)\n (31, 1)\n sage: is_pseudoprime_power(15, get_data=True)\n (15, 0)\n\n Tests with numpy and gmpy2 numbers::\n\n sage: from numpy import int16 # needs numpy\n sage: is_pseudoprime_power(int16(1024)) # needs numpy sage.libs.pari\n True\n sage: from gmpy2 import mpz\n sage: is_pseudoprime_power(mpz(1024))\n True\n ' return ZZ(n).is_prime_power(proof=False, get_data=get_data)
def valuation(m, *args, **kwds): "\n Return the valuation of ``m``.\n\n This function simply calls the m.valuation() method.\n See the documentation of m.valuation() for a more precise description.\n\n Note that the use of this functions is discouraged as it is better to use\n m.valuation() directly.\n\n .. NOTE::\n\n This is not always a valuation in the mathematical sense.\n For more information see:\n sage.rings.finite_rings.integer_mod.IntegerMod_int.valuation\n\n EXAMPLES::\n\n sage: valuation(512,2)\n 9\n sage: valuation(1,2)\n 0\n sage: valuation(5/9, 3)\n -2\n\n Valuation of 0 is defined, but valuation with respect to 0 is not::\n\n sage: valuation(0,7)\n +Infinity\n sage: valuation(3,0)\n Traceback (most recent call last):\n ...\n ValueError: You can only compute the valuation with respect to a integer larger than 1.\n\n Here are some other examples::\n\n sage: valuation(100,10)\n 2\n sage: valuation(200,10)\n 2\n sage: valuation(243,3)\n 5\n sage: valuation(243*10007,3)\n 5\n sage: valuation(243*10007,10007)\n 1\n sage: y = QQ['y'].gen()\n sage: valuation(y^3, y)\n 3\n sage: x = QQ[['x']].gen()\n sage: valuation((x^3-x^2)/(x-4))\n 2\n sage: valuation(4r,2r)\n 2\n sage: valuation(1r,1r)\n Traceback (most recent call last):\n ...\n ValueError: You can only compute the valuation with respect to a integer larger than 1.\n sage: from numpy import int16 # needs numpy\n sage: valuation(int16(512), int16(2)) # needs numpy\n 9\n sage: from gmpy2 import mpz\n sage: valuation(mpz(512), mpz(2))\n 9\n " try: return m.valuation(*args, **kwds) except AttributeError: return ZZ(m).valuation(*args, **kwds)
def prime_powers(start, stop=None): '\n List of all positive primes powers between ``start`` and\n ``stop``-1, inclusive. If the second argument is omitted, returns\n the prime powers up to the first argument.\n\n INPUT:\n\n - ``start`` - an integer. If two inputs are given, a lower bound\n for the returned set of prime powers. If this is the only input,\n then it is an upper bound.\n\n - ``stop`` - an integer (default: ``None``). An upper bound for the\n returned set of prime powers.\n\n OUTPUT:\n\n The set of all prime powers between ``start`` and ``stop`` or, if\n only one argument is passed, the set of all prime powers between 1\n and ``start``. The number `n` is a prime power if `n=p^k`, where\n `p` is a prime number and `k` is a positive integer. Thus, `1` is\n not a prime power.\n\n EXAMPLES::\n\n sage: prime_powers(20) # needs sage.libs.pari\n [2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19]\n sage: len(prime_powers(1000)) # needs sage.libs.pari\n 193\n sage: len(prime_range(1000)) # needs sage.libs.pari\n 168\n\n sage: # needs sage.libs.pari\n sage: a = [z for z in range(95, 1234) if is_prime_power(z)]\n sage: b = prime_powers(95, 1234)\n sage: len(b)\n 194\n sage: len(a)\n 194\n sage: a[:10]\n [97, 101, 103, 107, 109, 113, 121, 125, 127, 128]\n sage: b[:10]\n [97, 101, 103, 107, 109, 113, 121, 125, 127, 128]\n sage: a == b\n True\n\n sage: prime_powers(100) == [i for i in range(100) if is_prime_power(i)] # needs sage.libs.pari\n True\n\n sage: prime_powers(10, 7)\n []\n sage: prime_powers(-5)\n []\n sage: prime_powers(-1, 3) # needs sage.libs.pari\n [2]\n\n TESTS:\n\n Check that output are always Sage integers (:trac:`922`)::\n\n sage: v = prime_powers(10) # needs sage.libs.pari\n sage: type(v[0]) # needs sage.libs.pari\n <class \'sage.rings.integer.Integer\'>\n\n sage: prime_powers(0, 1)\n []\n sage: prime_powers(2)\n []\n sage: prime_powers(3) # needs sage.libs.pari\n [2]\n\n sage: prime_powers("foo")\n Traceback (most recent call last):\n ...\n TypeError: unable to convert \'foo\' to an integer\n\n sage: prime_powers(6, "bar")\n Traceback (most recent call last):\n ...\n TypeError: unable to convert \'bar\' to an integer\n\n Check that long input are accepted (:trac:`17852`)::\n\n sage: prime_powers(6l) # needs sage.libs.pari\n [2, 3, 4, 5]\n sage: prime_powers(6l, 10l) # needs sage.libs.pari\n [7, 8, 9]\n\n Check numpy and gmpy2 support::\n\n sage: from numpy import int8 # needs numpy\n sage: prime_powers(int8(20)) # needs numpy sage.libs.pari\n [2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19]\n sage: from gmpy2 import mpz\n sage: prime_powers(mpz(20)) # needs sage.libs.pari\n [2, 3, 4, 5, 7, 8, 9, 11, 13, 16, 17, 19]\n ' start = ZZ(start) ZZ_2 = Integer(2) if (stop is None): stop = start start = ZZ_2 else: stop = ZZ(stop) if ((stop <= ZZ_2) or (start >= stop)): return [] output = [] for p in prime_range(stop): q = p while (q < start): q *= p while (q < stop): output.append(q) q *= p output.sort() return output