return self.zero()
natural_basis = self.natural_basis()
- if elt not in natural_basis[0].matrix_space():
+ basis_space = natural_basis[0].matrix_space()
+ if elt not in basis_space:
raise ValueError("not a naturally-represented algebra element")
- # 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()*elt.ncols())
+ # Thanks for nothing! Matrix spaces aren't vector spaces in
+ # Sage, so we have to figure out its natural-basis coordinates
+ # ourselves. We use the basis space's ring instead of the
+ # element's ring because the basis space might be an algebraic
+ # closure whereas the base ring of the 3-by-3 identity matrix
+ # could be QQ instead of QQbar.
+ V = VectorSpace(basis_space.base_ring(), elt.nrows()*elt.ncols())
W = V.span_of_basis( _mat2vec(s) for s in natural_basis )
coords = W.coordinate_vector(_mat2vec(elt))
return self.from_vector(coords)