X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Feja%2Feja_element.py;h=9044860b8b8674c4110bde49edc2d46e9c999bfa;hb=667e0df9c07589c03616ad8cf42eebe5c86de50b;hp=42e5782c4539c97fcd71805b50c81cd4a96877a5;hpb=3baadd6fb5c765caab2bd57d1d6ed764b03d53b3;p=sage.d.git diff --git a/mjo/eja/eja_element.py b/mjo/eja/eja_element.py index 42e5782..9044860 100644 --- a/mjo/eja/eja_element.py +++ b/mjo/eja/eja_element.py @@ -1107,14 +1107,35 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement): [0 0 0 0 0 0 1 0] [0 0 0 0 0 0 0 1] + This also works in Cartesian product algebras:: + + sage: J1 = HadamardEJA(1) + sage: J2 = RealSymmetricEJA(2) + sage: J = cartesian_product([J1,J2]) + sage: x = sum(J.gens()) + sage: x.to_matrix()[0] + [1] + sage: x.to_matrix()[1] + [ 1 0.7071067811865475?] + [0.7071067811865475? 1] + """ B = self.parent().matrix_basis() W = self.parent().matrix_space() - # 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()) ) + if self.parent()._matrix_basis_is_cartesian: + # Aaaaand linear combinations don't work in Cartesian + # product spaces, even though they provide a method + # with that name. + 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()) + 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()) ) @@ -1615,38 +1636,3 @@ class FiniteDimensionalEJAElement(IndexedFreeModuleElement): """ return self.trace_inner_product(self).sqrt() - - - -class CartesianProductEJAElement(FiniteDimensionalEJAElement): - - def to_matrix(self): - r""" - SETUP:: - - sage: from mjo.eja.eja_algebra import (HadamardEJA, - ....: RealSymmetricEJA) - - EXAMPLES:: - - sage: J1 = HadamardEJA(1) - sage: J2 = RealSymmetricEJA(2) - sage: J = cartesian_product([J1,J2]) - sage: x = sum(J.gens()) - sage: x.to_matrix()[0] - [1] - sage: x.to_matrix()[1] - [ 1 0.7071067811865475?] - [0.7071067811865475? 1] - - """ - 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. - 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())