+ EXAMPLES::
+
+ sage: J1 = HadamardEJA(2)
+ sage: J2 = RealSymmetricEJA(3)
+ sage: J = DirectSumEJA(J1,J2)
+ sage: J.dimension()
+ 8
+ sage: J.rank()
+ 5
+ sage: J.matrix_space()
+ The Cartesian product of (Full MatrixSpace of 2 by 1 dense matrices
+ over Algebraic Real Field, Full MatrixSpace of 3 by 3 dense matrices
+ over Algebraic Real Field)
+
+ TESTS:
+
+ The external direct sum construction is only valid when the two factors
+ have the same base ring; an error is raised otherwise::
+
+ sage: set_random_seed()
+ sage: J1 = random_eja(field=AA)
+ sage: J2 = random_eja(field=QQ,orthonormalize=False)
+ sage: J = DirectSumEJA(J1,J2)
+ Traceback (most recent call last):
+ ...
+ ValueError: algebras must share the same base field
+
+ """
+ def __init__(self, J1, J2, **kwargs):
+ if J1.base_ring() != J2.base_ring():
+ raise ValueError("algebras must share the same base field")
+ field = J1.base_ring()
+
+ M = J1.matrix_space().cartesian_product(J2.matrix_space())
+ self._cartprod_algebra = J1.cartesian_product(J2)
+
+ self._matrix_basis = tuple( [M((a,0)) for a in J1.matrix_basis()] +
+ [M((0,b)) for b in J2.matrix_basis()] )
+
+ n = len(self._matrix_basis)
+ self._sets = None
+ CombinatorialFreeModule.__init__(
+ self,
+ field,
+ range(n),
+ category=self._cartprod_algebra.category(),
+ bracket=False,
+ **kwargs)
+ self.rank.set_cache(J1.rank() + J2.rank())
+
+
+
+ def product(self,x,y):
+ r"""
+ SETUP::
+
+ sage: from mjo.eja.eja_algebra import (JordanSpinEJA,
+ ....: ComplexHermitianEJA,
+ ....: DirectSumEJA)
+
+ TESTS::
+
+ sage: set_random_seed()
+ sage: J1 = JordanSpinEJA(3, field=QQ)
+ sage: J2 = ComplexHermitianEJA(2, field=QQ, orthonormalize=False)
+ sage: J = DirectSumEJA(J1,J2)
+ sage: J.random_element()*J.random_element() in J
+ True
+
+ """
+ xv = self._cartprod_algebra.from_vector(x.to_vector())
+ yv = self._cartprod_algebra.from_vector(y.to_vector())
+ return self.from_vector((xv*yv).to_vector())
+
+
+ def cartesian_factors(self):
+ r"""
+ Return the pair of this algebra's factors.
+
+ SETUP::
+
+ sage: from mjo.eja.eja_algebra import (HadamardEJA,
+ ....: JordanSpinEJA,
+ ....: DirectSumEJA)
+
+ EXAMPLES::
+
+ sage: J1 = HadamardEJA(2, field=QQ)
+ sage: J2 = JordanSpinEJA(3, field=QQ)
+ sage: J = DirectSumEJA(J1,J2)
+ sage: J.cartesian_factors()
+ (Euclidean Jordan algebra of dimension 2 over Rational Field,
+ Euclidean Jordan algebra of dimension 3 over Rational Field)
+
+ """
+ return self._cartprod_algebra.cartesian_factors()