Squaring in the subalgebra should be the same thing as
squaring in the superalgebra::
+ sage: set_random_seed()
sage: J = eja_ln(5)
sage: x = J.random_element()
sage: u = x.subalgebra_generated_by().random_element()
def mat2vec(m):
return vector(field, m.list())
+ def vec2mat(v):
+ return matrix(field, dimension, v.list())
+
W = V.span( mat2vec(s) for s in S )
+ # Taking the span above reorders our basis (thanks, jerk!) so we
+ # need to put our "matrix basis" in the same order as the
+ # (reordered) vector basis.
+ S = [ vec2mat(b) for b in W.basis() ]
+
for s in S:
# Brute force the multiplication-by-s matrix by looping
# through all elements of the basis and doing the computation