I have a matrix in GAP, and I want its real valued eigenvalues. (Or rational approximations of them, of course.) As far as I can tell Eigenvalues(Rationals,A) only gives me the rational eigenvalues. This seems like a silly question but I couldn't find documentation for this anywhere.
2026-03-27 17:33:16.1774632796
On
Real valued eigenvalues in GAP?
626 Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
There are 2 best solutions below
3
On
It's definitely not something GAP will excel at; since good algorithms for eigenvalue computation do not use the characteristic polynomial, but rather decompositions (QR, LR, ...).
Here's an example of how to do it with the current features of GAP:
gap> m := [[2,1],[1,1]];
[ [ 2, 1 ], [ 1, 1 ] ]
gap> Eigenvalues(Rationals,m); # are the rational roots?
[ ]
gap> Eigenvalues(CyclotomicField(5),m);
[ -E(5)-2*E(5)^2-2*E(5)^3-E(5)^4, -2*E(5)-E(5)^2-E(5)^3-2*E(5)^4 ]
gap> CharacteristicPolynomial(m);
x_1^2-3*x_1+1
gap> c := CoefficientsOfUnivariatePolynomial(last);
[ 1, -3, 1 ]
gap> RootsFloat(List(c,Float));
[ 0.381966, 2.61803 ]
You may also use high-precision packages within GAP, if the package "Float" is installed (this comes precompiled in some GAP distributions):
gap> LoadPackage("float");
true
gap> SetFloats(MPFR,1000); # 1000 bits
gap> MPFR.constants.VIEW_DIG := 100;; # show 100 digits
gap> RootsFloat(List(c,Float));
[ .3819660112501051517954131656343618822796908201942371378645513772947395371810975502927927958106088625e0,
.2618033988749894848204586834365638117720309179805762862135448622705260462818902449707207204189391137e1 ]
Note that complex roots can also be computed by Float; in fact, they are what RootsFloat returns by default when the Float package is loaded:
gap> m := PermutationMat((1,2,3,4,5,6,7,8,9,10),10);
[ [ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ],
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ], [ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ]
gap> Eigenvalues(CyclotomicField(5),m);
[ 1, -1, E(5), E(5)^2, E(5)^3, E(5)^4, -E(5)^4, -E(5)^3, -E(5)^2, -E(5) ]
gap> c := CoefficientsOfUnivariatePolynomial(CharacteristicPolynomial(m));
[ -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
gap> RootsFloat(List(c,Float));
[ .809017e0+.587785e0ⅈ, -.809017e0+.587785e0ⅈ, -.309017e0-.951057e0ⅈ, .809017e0-.587785e0ⅈ,
.309017e0+.951057e0ⅈ, -.1e1, .309017e0-.951057e0ⅈ, .1e1, -.309017e0+.951057e0ⅈ,
-.809017e0-.587785e0ⅈ ]
GAP does not have the real numbers (or approximate real numbers) as a data type, so it cannot factor polynomials over the reals.
In some cases, working over a suitable cyclotomic field or a formal algebraic extension might help.
What I would try is to first calculate the
CharacteristicPolynomialof the matrix in question, and then factor it over the rationals, this will give you an idea what field extension is needed.