]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_element.py
eja: use the new deep change_ring() to clean things up.
[sage.d.git] / mjo / eja / eja_element.py
index b5f661bf037667d4d9210b6af65a3c1f95120732..81c2b54fca757f0696468b5c450a6dda674a0f7a 100644 (file)
@@ -4,7 +4,7 @@ from sage.modules.free_module import VectorSpace
 from sage.modules.with_basis.indexed_element import IndexedFreeModuleElement
 
 from mjo.eja.eja_operator import FiniteDimensionalEJAOperator
-from mjo.eja.eja_utils import _mat2vec
+from mjo.eja.eja_utils import _mat2vec, _scale
 
 class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
     """
@@ -664,7 +664,7 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
         element should always be in terms of minimal idempotents::
 
             sage: J = JordanSpinEJA(4)
-            sage: x = sum( i*J.gens()[i] for i in range(len(J.gens())) )
+            sage: x = sum( i*J.monomial(i) for i in range(len(J.gens())) )
             sage: x.is_regular()
             True
             sage: [ c.is_primitive_idempotent()
@@ -1125,14 +1125,13 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
         B = self.parent().matrix_basis()
         W = self.parent().matrix_space()
 
-        if self.parent()._matrix_basis_is_cartesian:
+        if hasattr(W, 'cartesian_factors'):
             # Aaaaand linear combinations don't work in Cartesian
-            # product spaces, even though they provide a method
-            # with that name.
+            # product spaces, even though they provide a method with
+            # that name. This is hidden behind an "if" because the
+            # _scale() function is slow.
             pairs = zip(B, self.to_vector())
-            return sum( ( W(tuple(alpha*b_i for b_i in b))
-                          for (b,alpha) in pairs ),
-                        W.zero())
+            return W.sum( _scale(b, alpha) for (b,alpha) in pairs )
         else:
             # This is just a manual "from_vector()", but of course
             # matrix spaces aren't vector spaces in sage, so they