]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_algebra.py
eja: switch HadamardEJA to the new constructor.
[sage.d.git] / mjo / eja / eja_algebra.py
index 44d83147bbeceb4acae52d573749545dec3c4b99..4609ca2a4df7a4ff762e3eef00435a70b85e8cbb 100644 (file)
@@ -1040,7 +1040,7 @@ class RationalBasisEuclideanJordanAlgebraNg(FiniteDimensionalEuclideanJordanAlge
         n = len(basis)
         vector_basis = basis
 
-        from sage.matrix.matrix import is_Matrix
+        from sage.structure.element import is_Matrix
         basis_is_matrices = False
 
         degree = 0
@@ -1054,18 +1054,22 @@ class RationalBasisEuclideanJordanAlgebraNg(FiniteDimensionalEuclideanJordanAlge
 
         V = VectorSpace(field, degree)
 
-        self._deorthonormalization_matrix = matrix.identity(field,n)
+        # Compute this from "Q" (obtained from Gram-Schmidt) below as
+        # R = Q.solve_right(A), where the rows of "Q" are the
+        # orthonormalized vector_basis and and the rows of "A" are the
+        # original vector_basis.
+        self._deorthonormalization_matrix = None
+
         if orthonormalize:
-            A = matrix(field, vector_basis)
-            # uh oh, this is only the "usual" inner product
-            Q,R = A.gram_schmidt(orthonormal=True)
-            self._deorthonormalization_matrix = R.inverse().transpose()
-            vector_basis = Q.rows()
+            from mjo.eja.eja_utils import gram_schmidt
+            vector_basis = gram_schmidt(vector_basis, inner_product)
             W = V.span_of_basis( vector_basis )
             if basis_is_matrices:
                 from mjo.eja.eja_utils import _vec2mat
                 basis = tuple( map(_vec2mat,vector_basis) )
 
+        W = V.span_of_basis( vector_basis )
+
         mult_table = [ [0 for i in range(n)] for j in range(n) ]
         ip_table = [ [0 for i in range(n)] for j in range(n) ]
 
@@ -1086,12 +1090,14 @@ class RationalBasisEuclideanJordanAlgebraNg(FiniteDimensionalEuclideanJordanAlge
         if basis_is_matrices:
             for m in basis:
                 m.set_immutable()
+        else:
+            basis = tuple( x.column() for x in basis )
 
         super().__init__(field,
                          mult_table,
                          prefix,
                          category,
-                         basis,
+                         basis, # matrix basis
                          check_field,
                          check_axioms)
 
@@ -2109,7 +2115,7 @@ class QuaternionHermitianEJA(QuaternionMatrixEuclideanJordanAlgebra,
         return cls(n, field, **kwargs)
 
 
-class HadamardEJA(RationalBasisEuclideanJordanAlgebra,
+class HadamardEJA(RationalBasisEuclideanJordanAlgebraNg,
                   ConcreteEuclideanJordanAlgebra):
     """
     Return the Euclidean Jordan Algebra corresponding to the set
@@ -2152,22 +2158,17 @@ class HadamardEJA(RationalBasisEuclideanJordanAlgebra,
     """
     def __init__(self, n, field=AA, **kwargs):
         V = VectorSpace(field, n)
-        mult_table = [ [ V.gen(i)*(i == j) for j in range(n) ]
-                       for i in range(n) ]
+        basis = V.basis()
 
-        # Inner products are real numbers and not algebra
-        # elements, so once we turn the algebra element
-        # into a vector in inner_product(), we never go
-        # back. As a result -- contrary to what we do with
-        # self._multiplication_table -- we store the inner
-        # product table as a plain old matrix and not as
-        # an algebra operator.
-        ip_table = matrix.identity(field,n)
-        self._inner_product_matrix = ip_table
+        def jordan_product(x,y):
+            return V([ xi*yi for (xi,yi) in zip(x,y) ])
+        def inner_product(x,y):
+            return x.inner_product(y)
 
         super(HadamardEJA, self).__init__(field,
-                                          mult_table,
-                                          check_axioms=False,
+                                          basis,
+                                          jordan_product,
+                                          inner_product,
                                           **kwargs)
         self.rank.set_cache(n)