I don't think that in this case there would be a performance penality, the computation of the eigenvalues itself is not affected. Regardless, I think that in general, a high level convenience method should be optimized for reliability, not for performance. In fact, removing the optimization we could avoid the universe computation in eigenvalues = Sequence(res), which might be just as expensive.
Of course, if I know that the eigenvalues will be rational, it would be good to be able to tell the method that. I am a bit unsure how difficult that would be. I am guessing that the default ring cannot be the base ring, because that would break existing code, right?
Apart from that, I just found another snippet of the documentation, which says:
The eigenvalues are elements of ``QQbar``, so they really represent
exact roots of polynomials, not just approximations.
Here is what I would like to change:
diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx
index 63102fb380b..0b3d2040e80 100644
--- a/src/sage/matrix/matrix2.pyx
+++ b/src/sage/matrix/matrix2.pyx
@@ -7297,7 +7297,7 @@ cdef class Matrix(Matrix1):
res = []
for f, e in self.charpoly().change_ring(K).factor():
if f.degree() == 1:
- res.extend([-f.constant_coefficient()]*e)
+ res.extend([A(-f.constant_coefficient())]*e)
else:
for r, ee in f.change_ring(A).roots():
res.extend([r]*(e*ee))