Given a high precision real number, how should I go about guessing an algebraic integer that it's close to?


Of course, this is extremely poorly defined -- every real number is close to a rational number, of course! But I'd like to keep both the coefficients and the degree relatively small. Obviously we can make tradeoffs between how much we dislike large coefficents and how much we dislike large degrees.


But that aside, I don't even know how you'd start. Any ideas?


**Background**: this comes out of the project that prompted Noah's [recent question](https://mathoverflow.net/questions/2396/solving-polynomial-equations-when-you-know-in-which-number-field-the-solutions-li) on solving large systems of quadratics. We're trying to find subfactors inside their graph planar algebras. We've found that solving quadratics numerically, approximating the solutions by algebraic integers, and then checking that these are actually exact solutions is very effective. So far, we've been making use of Mathematica's "[RootApproximant](http://reference.wolfram.com/mathematica/ref/RootApproximant.html)" function which does exactly what I ask here, but it's an impenetrable black box, like everything out of Wolfram.



How should I approximate real numbers by algebraic ones?
The Lenstra-Lenstra-Lovasz lattice basis reduction algorithm is what you need. Suppose that your real number is a and you want a quadratic equation with as small coefficients as possible, of which a is nearly a root. Then calculate 1,a,a^2 (to some precision), find a nontrivial integer relation between them, and use the LLL algorithm to find a much better one from the first one. Exactly this example is discussed in the Wikipedia entry on the LLL algorithm, applied to the Golden Section number. And there is a big literature on the algorithm and its many applications. (For higher degree, calculate 1,a,a^2,...,a^n).


