]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_algebra.py
eja: fix doctests for matrix basis functions.
[sage.d.git] / mjo / eja / eja_algebra.py
index 9b028809c6ca46efd13d974fd99b176d1761754e..47d247be636c01d59a06a4f48da4d56b63b0f508 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)
@@ -797,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.
@@ -816,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.
 
@@ -828,7 +845,8 @@ def _complex_hermitian_basis(n, field=QQ):
 
         sage: set_random_seed()
         sage: n = ZZ.random_element(1,5)
-        sage: all( M.is_symmetric() for M in _complex_hermitian_basis(n) )
+        sage: B = _complex_hermitian_basis(n, QQ)
+        sage: all( M.is_symmetric() for M in  B)
         True
 
     """
@@ -857,7 +875,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.
 
@@ -869,7 +887,8 @@ def _quaternion_hermitian_basis(n, field=QQ):
 
         sage: set_random_seed()
         sage: n = ZZ.random_element(1,5)
-        sage: all( M.is_symmetric() for M in _quaternion_hermitian_basis(n) )
+        sage: B = _quaternion_hermitian_basis(n, QQbar)
+        sage: all( M.is_symmetric() for M in B )
         True
 
     """
@@ -1237,7 +1256,7 @@ class RealSymmetricEJA(FiniteDimensionalEuclideanJordanAlgebra):
 
     """
     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)
@@ -1306,7 +1325,7 @@ class ComplexHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra):
 
     """
     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)
@@ -1383,7 +1402,7 @@ class QuaternionHermitianEJA(FiniteDimensionalEuclideanJordanAlgebra):
 
     """
     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)