from sage.modules.with_basis.indexed_element import IndexedFreeModuleElement
from mjo.eja.eja_operator import FiniteDimensionalEJAOperator
-from mjo.eja.eja_utils import _mat2vec, _scale
+from mjo.eja.eja_utils import _scale
+
class FiniteDimensionalEJAElement(IndexedFreeModuleElement):
"""
B = self.parent().matrix_basis()
W = self.parent().matrix_space()
- if hasattr(W, 'cartesian_factors'):
- # Aaaaand linear combinations don't work in Cartesian
- # 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 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
- # don't have a from_vector() method.
- return W.linear_combination( zip(B, self.to_vector()) )
+ # This is just a manual "from_vector()", but of course
+ # matrix spaces aren't vector spaces in sage, so they
+ # don't have a from_vector() method.
+ return W.linear_combination( zip(B, self.to_vector()) )
"""
return self.trace_inner_product(self).sqrt()
+
+
+class CartesianProductEJAElement(FiniteDimensionalEJAElement):
+ def det(self):
+ r"""
+ Compute the determinant of this product-element using the
+ determianants of its factors.
+
+ This result Follows from the spectral decomposition of (say)
+ the pair `(x,y)` in terms of the Jordan frame `\left\{ (c_1,
+ 0),(c_2, 0),...,(0,d_1),(0,d_2),... \right\}.
+ """
+ from sage.misc.misc_c import prod
+ return prod( f.det() for f in self.cartesian_factors() )
+
+ def to_matrix(self):
+ # An override is necessary to call our custom _scale().
+ B = self.parent().matrix_basis()
+ W = self.parent().matrix_space()
+
+ # Aaaaand linear combinations don't work in Cartesian
+ # 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 W.sum( _scale(b, alpha) for (b,alpha) in pairs )