]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_algebra.py
eja: use the basis space ring instead of the element's during construction.
[sage.d.git] / mjo / eja / eja_algebra.py
index 42b2474d6971d81c8a1fcda67b079892a3e8af25..1f6112ca188124b114da9892d6a8aed283681161 100644 (file)
@@ -135,13 +135,17 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
             return self.zero()
 
         natural_basis = self.natural_basis()
-        if elt not in natural_basis[0].matrix_space():
+        basis_space = natural_basis[0].matrix_space()
+        if elt not in basis_space:
             raise ValueError("not a naturally-represented algebra element")
 
-        # Thanks for nothing! Matrix spaces aren't vector
-        # spaces in Sage, so we have to figure out its
-        # natural-basis coordinates ourselves.
-        V = VectorSpace(elt.base_ring(), elt.nrows()*elt.ncols())
+        # Thanks for nothing! Matrix spaces aren't vector spaces in
+        # Sage, so we have to figure out its natural-basis coordinates
+        # ourselves. We use the basis space's ring instead of the
+        # element's ring because the basis space might be an algebraic
+        # closure whereas the base ring of the 3-by-3 identity matrix
+        # could be QQ instead of QQbar.
+        V = VectorSpace(basis_space.base_ring(), elt.nrows()*elt.ncols())
         W = V.span_of_basis( _mat2vec(s) for s in natural_basis )
         coords =  W.coordinate_vector(_mat2vec(elt))
         return self.from_vector(coords)
@@ -722,6 +726,17 @@ class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra):
         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)
@@ -786,9 +801,22 @@ def random_eja():
 
 
 
-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.
@@ -805,7 +833,7 @@ def _real_symmetric_basis(n, field=QQ):
     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.
 
@@ -846,7 +874,7 @@ def _complex_hermitian_basis(n, field=QQ):
     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.
 
@@ -1213,9 +1241,20 @@ class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra):
         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)
@@ -1271,9 +1310,20 @@ class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra):
         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)
@@ -1337,9 +1387,20 @@ class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra):
         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)
@@ -1399,6 +1460,17 @@ class JordanSpinEJA(FiniteDimensionalEuclideanJordanAlgebra):
         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)