From 7af3a2ff120fbf6824f891093398bbe96b55e9c5 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 3 Dec 2020 17:18:27 -0500 Subject: [PATCH] eja: fix recently broken doctests. --- mjo/eja/eja_algebra.py | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 5dee5d0..52e27de 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -1523,15 +1523,29 @@ class MatrixEuclideanJordanAlgebra: This gives the same answer as it would if we computed the trace from the unembedded (original) matrices:: + sage: set_random_seed() + sage: J = RealSymmetricEJA.random_instance() + sage: x,y = J.random_elements(2) + sage: Xe = x.to_matrix() + sage: Ye = y.to_matrix() + sage: X = J.real_unembed(Xe) + sage: Y = J.real_unembed(Ye) + sage: expected = (X*Y).trace() + sage: actual = J.trace_inner_product(Xe,Ye) + sage: actual == expected + True + + :: + sage: set_random_seed() sage: J = ComplexHermitianEJA.random_instance() sage: x,y = J.random_elements(2) sage: Xe = x.to_matrix() sage: Ye = y.to_matrix() - sage: X = ComplexHermitianEJA.real_unembed(Xe) - sage: Y = ComplexHermitianEJA.real_unembed(Ye) + sage: X = J.real_unembed(Xe) + sage: Y = J.real_unembed(Ye) sage: expected = (X*Y).trace().real() - sage: actual = ComplexHermitianEJA.trace_inner_product(Xe,Ye) + sage: actual = J.trace_inner_product(Xe,Ye) sage: actual == expected True @@ -1542,10 +1556,10 @@ class MatrixEuclideanJordanAlgebra: sage: x,y = J.random_elements(2) sage: Xe = x.to_matrix() sage: Ye = y.to_matrix() - sage: X = QuaternionHermitianEJA.real_unembed(Xe) - sage: Y = QuaternionHermitianEJA.real_unembed(Ye) + sage: X = J.real_unembed(Xe) + sage: Y = J.real_unembed(Ye) sage: expected = (X*Y).trace().coefficient_tuple()[0] - sage: actual = QuaternionHermitianEJA.trace_inner_product(Xe,Ye) + sage: actual = J.trace_inner_product(Xe,Ye) sage: actual == expected True @@ -1556,12 +1570,12 @@ class MatrixEuclideanJordanAlgebra: try: # Works in QQ, AA, RDF, et cetera. - return tr.real() / cls.dimension_over_reals() + return tr.real() except AttributeError: # A quaternion doesn't have a real() method, but does # have coefficient_tuple() method that returns the # coefficients of 1, i, j, and k -- in that order. - return tr.coefficient_tuple()[0] / cls.dimension_over_reals() + return tr.coefficient_tuple()[0] class RealMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra): @@ -1803,11 +1817,19 @@ class ComplexMatrixEuclideanJordanAlgebra(MatrixEuclideanJordanAlgebra): field = M.base_ring() R = PolynomialRing(field, 'z') z = R.gen() + + # Sage doesn't know how to adjoin the complex "i" (the root of + # x^2 + 1) to a field in a general way. Here, we just enumerate + # all of the cases that I have cared to support so far. if field is AA: # Sage doesn't know how to embed AA into QQbar, i.e. how # to adjoin sqrt(-1) to AA. F = QQbar + elif not field.is_exact(): + # RDF or RR + F = field.complex_field() else: + # Works for QQ and... maybe some other fields. F = field.extension(z**2 + 1, 'I', embedding=CLF(-1).sqrt()) i = F.gen() -- 2.44.2