from sage.categories.magmatic_algebras import MagmaticAlgebras
from sage.combinat.free_module import CombinatorialFreeModule
from sage.matrix.constructor import matrix
+from sage.matrix.matrix_space import MatrixSpace
from sage.misc.cachefunc import cached_method
from sage.misc.prandom import choice
from sage.misc.table import table
-from sage.modules.free_module import VectorSpace
+from sage.modules.free_module import FreeModule, VectorSpace
from sage.rings.integer_ring import ZZ
from sage.rings.number_field.number_field import QuadraticField
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
determinant).
"""
z = self._a_regular_element()
- V = self.vector_space()
- V1 = V.span_of_basis( (z**k).to_vector() for k in range(self.rank()) )
+ # Don't use the parent vector space directly here in case this
+ # happens to be a subalgebra. In that case, we would be e.g.
+ # two-dimensional but span_of_basis() would expect three
+ # coordinates.
+ V = VectorSpace(self.base_ring(), self.vector_space().dimension())
+ basis = [ (z**k).to_vector() for k in range(self.rank()) ]
+ V1 = V.span_of_basis( basis )
b = (V1.basis() + V1.complement().basis())
return V.span_of_basis(b)
# have multivatiate polynomial entries.
names = tuple('X' + str(i) for i in range(1,n+1))
R = PolynomialRing(self.base_ring(), names)
- V = self.vector_space().change_ring(R)
+
+ # Using change_ring() on the parent's vector space doesn't work
+ # here because, in a subalgebra, that vector space has a basis
+ # and change_ring() tries to bring the basis along with it. And
+ # that doesn't work unless the new ring is a PID, which it usually
+ # won't be.
+ V = FreeModule(R,n)
# Now let x = (X1,X2,...,Xn) be the vector whose entries are
# indeterminates...
return x.trace_inner_product(y)
+ def is_trivial(self):
+ """
+ Return whether or not this algebra is trivial.
+
+ A trivial algebra contains only the zero element.
+
+ SETUP::
+
+ sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
+
+ EXAMPLES::
+
+ sage: J = ComplexHermitianEJA(3)
+ sage: J.is_trivial()
+ False
+ sage: A = J.zero().subalgebra_generated_by()
+ sage: A.is_trivial()
+ True
+
+ """
+ return self.dimension() == 0
+
+
def multiplication_table(self):
"""
Return a visual representation of this algebra's multiplication
"""
if self._natural_basis is None:
- return tuple( b.to_vector().column() for b in self.basis() )
+ M = self.natural_basis_space()
+ return tuple( M(b.to_vector()) for b in self.basis() )
else:
return self._natural_basis
+ def natural_basis_space(self):
+ """
+ Return the matrix space in which this algebra's natural basis
+ elements live.
+ """
+ if self._natural_basis is None or len(self._natural_basis) == 0:
+ return MatrixSpace(self.base_ring(), self.dimension(), 1)
+ else:
+ return self._natural_basis[0].matrix_space()
+
+
@cached_method
def one(self):
"""
return self.linear_combination(zip(self.gens(), coeffs))
+ def random_element(self):
+ # Temporary workaround for https://trac.sagemath.org/ticket/28327
+ if self.is_trivial():
+ return self.zero()
+ else:
+ s = super(FiniteDimensionalEuclideanJordanAlgebra, self)
+ return s.random_element()
+
+
def rank(self):
"""
Return the rank of this EJA.
sage: RealCartesianProductEJA(3, prefix='r').gens()
(r0, r1, r2)
+ Our inner product satisfies the Jordan axiom::
+
+ sage: set_random_seed()
+ sage: n = ZZ.random_element(1,5)
+ sage: J = RealCartesianProductEJA(n)
+ sage: x = J.random_element()
+ sage: y = J.random_element()
+ sage: z = J.random_element()
+ sage: (x*y).inner_product(z) == y.inner_product(x*z)
+ True
+
"""
def __init__(self, n, field=QQ, **kwargs):
V = VectorSpace(field, n)
-def _real_symmetric_basis(n, field=QQ):
+def _real_symmetric_basis(n, field):
"""
Return a basis for the space of real symmetric n-by-n matrices.
+
+ SETUP::
+
+ sage: from mjo.eja.eja_algebra import _real_symmetric_basis
+
+ TESTS::
+
+ sage: set_random_seed()
+ sage: n = ZZ.random_element(1,5)
+ sage: B = _real_symmetric_basis(n, QQbar)
+ sage: all( M.is_symmetric() for M in B)
+ True
+
"""
# The basis of symmetric matrices, as matrices, in their R^(n-by-n)
# coordinates.
return tuple(S)
-def _complex_hermitian_basis(n, field=QQ):
+def _complex_hermitian_basis(n, field):
"""
Returns a basis for the space of complex Hermitian n-by-n matrices.
return tuple(S)
-def _quaternion_hermitian_basis(n, field=QQ):
+def _quaternion_hermitian_basis(n, field):
"""
Returns a basis for the space of quaternion Hermitian n-by-n matrices.
sage: RealSymmetricEJA(3, prefix='q').gens()
(q0, q1, q2, q3, q4, q5)
+ Our inner product satisfies the Jordan axiom::
+
+ sage: set_random_seed()
+ sage: n = ZZ.random_element(1,5)
+ sage: J = RealSymmetricEJA(n)
+ sage: x = J.random_element()
+ sage: y = J.random_element()
+ sage: z = J.random_element()
+ sage: (x*y).inner_product(z) == y.inner_product(x*z)
+ True
+
"""
def __init__(self, n, field=QQ, **kwargs):
- S = _real_symmetric_basis(n, field=field)
+ S = _real_symmetric_basis(n, field)
Qs = _multiplication_table_from_matrix_basis(S)
fdeja = super(RealSymmetricEJA, self)
sage: ComplexHermitianEJA(2, prefix='z').gens()
(z0, z1, z2, z3)
+ Our inner product satisfies the Jordan axiom::
+
+ sage: set_random_seed()
+ sage: n = ZZ.random_element(1,5)
+ sage: J = ComplexHermitianEJA(n)
+ sage: x = J.random_element()
+ sage: y = J.random_element()
+ sage: z = J.random_element()
+ sage: (x*y).inner_product(z) == y.inner_product(x*z)
+ True
+
"""
def __init__(self, n, field=QQ, **kwargs):
- S = _complex_hermitian_basis(n)
+ S = _complex_hermitian_basis(n, field)
Qs = _multiplication_table_from_matrix_basis(S)
fdeja = super(ComplexHermitianEJA, self)
sage: QuaternionHermitianEJA(2, prefix='a').gens()
(a0, a1, a2, a3, a4, a5)
+ Our inner product satisfies the Jordan axiom::
+
+ sage: set_random_seed()
+ sage: n = ZZ.random_element(1,5)
+ sage: J = QuaternionHermitianEJA(n)
+ sage: x = J.random_element()
+ sage: y = J.random_element()
+ sage: z = J.random_element()
+ sage: (x*y).inner_product(z) == y.inner_product(x*z)
+ True
+
"""
def __init__(self, n, field=QQ, **kwargs):
- S = _quaternion_hermitian_basis(n)
+ S = _quaternion_hermitian_basis(n, field)
Qs = _multiplication_table_from_matrix_basis(S)
fdeja = super(QuaternionHermitianEJA, self)
sage: JordanSpinEJA(2, prefix='B').gens()
(B0, B1)
+ Our inner product satisfies the Jordan axiom::
+
+ sage: set_random_seed()
+ sage: n = ZZ.random_element(1,5)
+ sage: J = JordanSpinEJA(n)
+ sage: x = J.random_element()
+ sage: y = J.random_element()
+ sage: z = J.random_element()
+ sage: (x*y).inner_product(z) == y.inner_product(x*z)
+ True
+
"""
def __init__(self, n, field=QQ, **kwargs):
V = VectorSpace(field, n)