"""
if self.is_zero():
- # We would generate a zero-dimensional subalgebra
- # where the minimal polynomial would be constant.
- # That might be correct, but only if *this* algebra
- # is trivial too.
- if not self.parent().is_trivial():
- # Pretty sure we know what the minimal polynomial of
- # the zero operator is going to be. This ensures
- # consistency of e.g. the polynomial variable returned
- # in the "normal" case without us having to think about it.
- return self.operator().minimal_polynomial()
-
+ # Pretty sure we know what the minimal polynomial of
+ # the zero operator is going to be. This ensures
+ # consistency of e.g. the polynomial variable returned
+ # in the "normal" case without us having to think about it.
+ return self.operator().minimal_polynomial()
+
+ # If we don't orthonormalize the subalgebra's basis, then the
+ # first two monomials in the subalgebra will be self^0 and
+ # self^1... assuming that self^1 is not a scalar multiple of
+ # self^0 (the unit element). We special case these to avoid
+ # having to solve a system to coerce self into the subalgebra.
A = self.subalgebra_generated_by(orthonormalize=False)
- return A(self).operator().minimal_polynomial()
+
+ if A.dimension() == 1:
+ # Does a solve to find the scalar multiple alpha such that
+ # alpha*unit = self. We have to do this because the basis
+ # for the subalgebra will be [ self^0 ], and not [ self^1 ]!
+ unit = self.parent().one()
+ alpha = self.to_vector() / unit.to_vector()
+ return (unit.operator()*alpha).minimal_polynomial()
+ else:
+ # If the dimension of the subalgebra is >= 2, then we just
+ # use the second basis element.
+ return A.monomial(1).operator().minimal_polynomial()