# How should I approximate real numbers by algebraic ones?

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 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" function which does exactly what I ask here, but it's an impenetrable black box, like everything out of Wolfram.

• Do you mean algebraic integers or algebraic numbers? Oct 27, 2009 at 20:57
• I know this question seems long dead, but it seems to me that there is an issue here regarding algebraic integers vs algebraic numbers. For example the suggestion to use pari's "algdep" function below will only (at least if applied naively) find an algebraic number of smallish height close to the given number, not an algebraic integer. Feb 19, 2010 at 20:29
• – Stef
Sep 16, 2022 at 16:36