return A.element_class(A, self.vector()*(self.matrix()**(n-1)))
+ def span_of_powers(self):
+ """
+ Return the vector space spanned by successive powers of
+ this element.
+ """
+ # The dimension of the subalgebra can't be greater than
+ # the big algebra, so just put everything into a list
+ # and let span() get rid of the excess.
+ V = self.vector().parent()
+ return V.span( (self**d).vector() for d in xrange(V.dimension()) )
+
+
def degree(self):
"""
Compute the degree of this element the straightforward way
2
"""
- d = 0
- V = self.vector().parent()
- vectors = [(self**d).vector()]
- while V.span(vectors).dimension() > d:
- d += 1
- vectors.append((self**d).vector())
- return d
+ return self.span_of_powers().dimension()
+
def minimal_polynomial(self):
return self.matrix().minimal_polynomial()