# Find root approximants for low-precision numbers

I want to be able to find low-complexity algebraic approximants to decimal numbers. For example, 1.41 can be approximated as a solution to the polynomial x^2==2. There is a Mathematica function RootApproximant that seems like it should be able to do this approximation. However, I can't get it to work. RootApproximant[N[Sqrt[2]] returns $\sqrt{2}$ correctly, but RootApproximant[1.41] doesn't - it prefers to approximate it as 141/100.

Presumably I need to tell it to lower the accuracy it's aiming for. There is an option called "DegreeCost" that can be passed, but I can't work out how to use that to achieve my goal.

-
Note that RootApproximant[1.4142, 7] is Sqrt[2] –  belisarius Mar 25 at 12:49
How about changing the precision of the input: RootApproximant[1.413] –  Simon Woods Mar 25 at 12:54

Though RootApproximant is doing the right thing for $1.41$, if you persist to get some polynomial what about adding some random precision. Try this!

TrickApprox[loPric_?NumericQ, degree_?IntegerQ, degreeCost_: 2] := Module[{val},
val = ToExpression@(ToString@loPric <>ToString@FromDigits@RandomInteger[{0, 4}, 8]);
RootApproximant[val, degree, Method -> {"DegreeCost" -> degreeCost}]
]


Now test it for a cubic polynomial.

TrickApprox[1.41, 3]


Root[-5765 + 7694 #1 - 2705 #1^2 + 104 #1^3 &, 1]

N[%, 3]


1.41

If you increase the DegreeCost using the third argument RootApproximant` will try not to include higher degree terms in the approximation.

-