From 5978697af0b924d2d2b6174975bf06f1830746f3 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 19 Jul 2019 14:09:46 -0400 Subject: [PATCH] eja: support conversion of naturally-represented elements into an EJA. This lets us convert e.g. a symmetric 3x3 matrix to an EJA element without having to mess with the basis/coordinates ourselves. --- mjo/eja/euclidean_jordan_algebra.py | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/mjo/eja/euclidean_jordan_algebra.py b/mjo/eja/euclidean_jordan_algebra.py index e30c341..b258398 100644 --- a/mjo/eja/euclidean_jordan_algebra.py +++ b/mjo/eja/euclidean_jordan_algebra.py @@ -160,6 +160,51 @@ class FiniteDimensionalEuclideanJordanAlgebra(FiniteDimensionalAlgebra): An element of a Euclidean Jordan algebra. """ + def __init__(self, A, elt=None): + """ + EXAMPLES: + + The identity in `S^n` is converted to the identity in the EJA:: + + sage: J = RealSymmetricSimpleEJA(3) + sage: I = identity_matrix(QQ,3) + sage: J(I) == J.one() + True + + This skew-symmetric matrix can't be represented in the EJA:: + + sage: J = RealSymmetricSimpleEJA(3) + sage: A = matrix(QQ,3, lambda i,j: i-j) + sage: J(A) + Traceback (most recent call last): + ... + ArithmeticError: vector is not in free module + + """ + # Goal: if we're given a matrix, and if it lives in our + # parent algebra's "natural ambient space," convert it + # into an algebra element. + # + # The catch is, we make a recursive call after converting + # the given matrix into a vector that lives in the algebra. + # This we need to try the parent class initializer first, + # to avoid recursing forever if we're given something that + # already fits into the algebra, but also happens to live + # in the parent's "natural ambient space" (this happens with + # vectors in R^n). + try: + FiniteDimensionalAlgebraElement.__init__(self, A, elt) + except ValueError: + natural_basis = A.natural_basis() + if elt in natural_basis[0].matrix_space(): + # Thanks for nothing! Matrix spaces aren't vector + # spaces in Sage, so we have to figure out its + # natural-basis coordinates ourselves. + V = VectorSpace(elt.base_ring(), elt.nrows()**2) + W = V.span( _mat2vec(s) for s in natural_basis ) + coords = W.coordinates(_mat2vec(elt)) + FiniteDimensionalAlgebraElement.__init__(self, A, coords) + def __pow__(self, n): """ Return ``self`` raised to the power ``n``. -- 2.44.2