]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
eja: add is_trivial() method and special cases for trivial algebras.
authorMichael Orlitzky <michael@orlitzky.com>
Fri, 9 Aug 2019 19:22:14 +0000 (15:22 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Fri, 9 Aug 2019 19:22:14 +0000 (15:22 -0400)
mjo/eja/eja_algebra.py
mjo/eja/eja_element.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.
index 97c048dceb3e299e7a36ac1a15767ebb33af8fad..c47156d31e2c6989e1fe863091794520f395523c 100644 (file)
@@ -482,14 +482,20 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
             sage: J.one().is_invertible()
             True
 
-        The zero element is never invertible::
+        The zero element is never invertible in a non-trivial algebra::
 
             sage: set_random_seed()
             sage: J = random_eja()
-            sage: J.zero().is_invertible()
+            sage: (not J.is_trivial()) and J.zero().is_invertible()
             False
 
         """
+        if self.is_zero():
+            if self.parent().is_trivial():
+                return True
+            else:
+                return False
+
         # In fact, we only need to know if the constant term is non-zero,
         # so we can pass in the field's zero element instead.
         zero = self.base_ring().zero()
@@ -645,6 +651,11 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
             True
 
         """
+        if self.is_zero() and not self.parent().is_trivial():
+            # The minimal polynomial of zero in a nontrivial algebra
+            # is "t"; in a trivial algebra it's "1" by convention
+            # (it's an empty product).
+            return 1
         return self.subalgebra_generated_by().dimension()
 
 
@@ -723,6 +734,18 @@ class FiniteDimensionalEuclideanJordanAlgebraElement(IndexedFreeModuleElement):
             0
 
         """
+        if self.is_zero():
+            # We would generate a zero-dimensional subalgebra
+            # where the minimal polynomial would be constant.
+            # That might be correct, but only if *this* algebra
+            # is trivial too.
+            if not self.parent().is_trivial():
+                # Pretty sure we know what the minimal polynomial of
+                # the zero operator is going to be. This ensures
+                # consistency of e.g. the polynomial variable returned
+                # in the "normal" case without us having to think about it.
+                return self.operator().minimal_polynomial()
+
         A = self.subalgebra_generated_by()
         return A(self).operator().minimal_polynomial()