convert real number to radicals

algorithm, language-agnostic, math

Solution

No need for continued fractions; just calculate the square-root of all "small" values of `b` (up to whatever value you feel is still "small" enough), remove everything before the decimal point, and sort/store them all (along with the `b` that generated it).

Then when you need to approximate a real number, find the radical whose decimal-portion is closet to the real number's decimal-portion. This gives you `b` - choosing the correct `a` is then a simple matter of subtraction.

Problem

Suppose I have a real number. I want to approximate it with something of the form a+sqrt(b) for integers a and b. But I don't know the values of a and b. Of course I would prefer to get a good approximation with small values of a and b. Let's leave it undefined for now what is meant by "good" and "small". Any sensible definitions of those terms will do. Is there a sane way to find them? Something like the continued fraction algorithm for finding fractional approximations of decimals. For more on the fractions problem, see here. EDIT: To clarify, it is an arbitrary real number. All I have are a bunch of its digits. So depending on how good of an approximation we want, a and b might or might not exist. Brute force is naturally not a particularly good algorithm. The best I can think of would be to start adding integers to my real, squaring the result, and seeing if I come close to an integer. Pretty much brute force, and not a particularly good algorithm. But if nothing better exists, that would itself be interesting to know. EDIT: Obviously b has to be zero or positive. But a could be any integer.

Original source

Related problems