]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_algebra.py
eja: add is_trivial() method and special cases for trivial algebras.
[sage.d.git] / mjo / eja / eja_algebra.py
index 580c923c37a7c00ed492272161eec70ced95c2de..832e7a19d5857fcd429a11b8693565aa781ba617 100644 (file)
@@ -404,6 +404,29 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
         return x.trace_inner_product(y)
 
 
+    def is_trivial(self):
+        """
+        Return whether or not this algebra is trivial.
+
+        A trivial algebra contains only the zero element.
+
+        SETUP::
+
+            sage: from mjo.eja.eja_algebra import ComplexHermitianEJA
+
+        EXAMPLES::
+
+            sage: J = ComplexHermitianEJA(3)
+            sage: J.is_trivial()
+            False
+            sage: A = J.zero().subalgebra_generated_by()
+            sage: A.is_trivial()
+            True
+
+        """
+        return self.dimension() == 0
+
+
     def multiplication_table(self):
         """
         Return a visual representation of this algebra's multiplication
@@ -546,6 +569,15 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
         return self.linear_combination(zip(self.gens(), coeffs))
 
 
+    def random_element(self):
+        # Temporary workaround for https://trac.sagemath.org/ticket/28327
+        if self.is_trivial():
+            return self.zero()
+        else:
+            s = super(FiniteDimensionalEuclideanJordanAlgebra, self)
+            return s.random_element()
+
+
     def rank(self):
         """
         Return the rank of this EJA.