X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=mjo%2Feja%2Feja_algebra.py;h=da008d0cf70249de27ac1a52b1d53ae4be9ef4f2;hb=843814d06f42e6a97e31079173266fa6165e8c6a;hp=799490044dbb4d0834577f435afd2dbc89429baf;hpb=78bee5c30c1cd2828d9834fc7d652db21331d4fe;p=sage.d.git diff --git a/mjo/eja/eja_algebra.py b/mjo/eja/eja_algebra.py index 7994900..da008d0 100644 --- a/mjo/eja/eja_algebra.py +++ b/mjo/eja/eja_algebra.py @@ -64,8 +64,7 @@ from itertools import repeat from sage.algebras.quatalg.quaternion_algebra import QuaternionAlgebra from sage.categories.magmatic_algebras import MagmaticAlgebras from sage.categories.sets_cat import cartesian_product -from sage.combinat.free_module import (CombinatorialFreeModule, - CombinatorialFreeModule_CartesianProduct) +from sage.combinat.free_module import CombinatorialFreeModule from sage.matrix.constructor import matrix from sage.matrix.matrix_space import MatrixSpace from sage.misc.cachefunc import cached_method @@ -1837,18 +1836,13 @@ class MatrixEJA: True """ - Xu = cls.real_unembed(X) - Yu = cls.real_unembed(Y) - tr = (Xu*Yu).trace() - - try: - # Works in QQ, AA, RDF, et cetera. - 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] + # This does in fact compute the real part of the trace. + # If we compute the trace of e.g. a complex matrix M, + # then we do so by adding up its diagonal entries -- + # call them z_1 through z_n. The real embedding of z_1 + # will be a 2-by-2 REAL matrix [a, b; -b, a] whose trace + # as a REAL matrix will be 2*a = 2*Re(z_1). And so forth. + return (X*Y).trace()/cls.dimension_over_reals() class RealMatrixEJA(MatrixEJA): @@ -3480,17 +3474,15 @@ class RationalBasisCartesianProductEJA(CartesianProductEJA, RationalBasisEJA.CartesianProduct = RationalBasisCartesianProductEJA -random_eja = ConcreteEJA.random_instance - -# def random_eja(*args, **kwargs): -# J1 = ConcreteEJA.random_instance(*args, **kwargs) - -# # This might make Cartesian products appear roughly as often as -# # any other ConcreteEJA. -# if ZZ.random_element(len(ConcreteEJA.__subclasses__()) + 1) == 0: -# # Use random_eja() again so we can get more than two factors. -# J2 = random_eja(*args, **kwargs) -# J = cartesian_product([J1,J2]) -# return J -# else: -# return J1 +def random_eja(*args, **kwargs): + J1 = ConcreteEJA.random_instance(*args, **kwargs) + + # This might make Cartesian products appear roughly as often as + # any other ConcreteEJA. + if ZZ.random_element(len(ConcreteEJA.__subclasses__()) + 1) == 0: + # Use random_eja() again so we can get more than two factors. + J2 = random_eja(*args, **kwargs) + J = cartesian_product([J1,J2]) + return J + else: + return J1