]> gitweb.michael.orlitzky.com - sage.d.git/blobdiff - mjo/eja/eja_algebra.py
eja: define the trace of an element in a trivial algebra.
[sage.d.git] / mjo / eja / eja_algebra.py
index 7a65fabdcfcd4adf9c2369dd7d64da50e17b1bd3..725cd7132343ee6f3ba5769d8053aaff32501560 100644 (file)
@@ -251,7 +251,10 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
         """
         (A_of_x, x, xr, detA) = self._charpoly_matrix_system()
         R = A_of_x.base_ring()
-        if i >= self.rank():
+
+        if i == self.rank():
+            return R.one()
+        if i > self.rank():
             # Guaranteed by theory
             return R.zero()
 
@@ -378,8 +381,8 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
         r = self.rank()
         n = self.dimension()
 
-        # The list of coefficient polynomials a_1, a_2, ..., a_n.
-        a = [ self._charpoly_coeff(i) for i in range(n) ]
+        # The list of coefficient polynomials a_0, a_1, a_2, ..., a_n.
+        a = [ self._charpoly_coeff(i) for i in range(r+1) ]
 
         # We go to a bit of trouble here to reorder the
         # indeterminates, so that it's easier to evaluate the
@@ -391,17 +394,6 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
         S = PolynomialRing(S, R.variable_names())
         t = S(t)
 
-        # Note: all entries past the rth should be zero. The
-        # coefficient of the highest power (x^r) is 1, but it doesn't
-        # appear in the solution vector which contains coefficients
-        # for the other powers (to make them sum to x^r).
-        if (r < n):
-            a[r] = 1 # corresponds to x^r
-        else:
-            # When the rank is equal to the dimension, trying to
-            # assign a[r] goes out-of-bounds.
-            a.append(1) # corresponds to x^r
-
         return sum( a[k]*(t**k) for k in xrange(len(a)) )
 
 
@@ -449,9 +441,6 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
             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
@@ -625,14 +614,6 @@ 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 random_elements(self, count):
         """
         Return ``count`` random elements as a tuple.
@@ -697,11 +678,15 @@ class FiniteDimensionalEuclideanJordanAlgebra(CombinatorialFreeModule):
         TESTS:
 
         Ensure that every EJA that we know how to construct has a
-        positive integer rank::
+        positive integer rank, unless the algebra is trivial in
+        which case its rank will be zero::
 
             sage: set_random_seed()
-            sage: r = random_eja().rank()
-            sage: r in ZZ and r > 0
+            sage: J = random_eja()
+            sage: r = J.rank()
+            sage: r in ZZ
+            True
+            sage: r > 0 or (r == 0 and J.is_trivial())
             True
 
         """
@@ -852,7 +837,7 @@ class RealCartesianProductEJA(FiniteDimensionalEuclideanJordanAlgebra,
         return x.to_vector().inner_product(y.to_vector())
 
 
-def random_eja():
+def random_eja(field=QQ):
     """
     Return a "random" finite-dimensional Euclidean Jordan Algebra.
 
@@ -889,7 +874,7 @@ def random_eja():
 
     """
     classname = choice(KnownRankEJA.__subclasses__())
-    return classname.random_instance()
+    return classname.random_instance(field=field)