How to compute the decimal digits of irrational number(non-transcendental) with an arbitrary precision?
eg. Expansion of $\sqrt{ 2}$ with a precision of 500.
How to compute the decimal digits of irrational number(non-transcendental) with an arbitrary precision?
eg. Expansion of $\sqrt{ 2}$ with a precision of 500.
In the case of $\sqrt a$, Newton's method converges very fast: $$ x_{n+1}=\frac12\big(x_n+\frac{a}{x_n}\big), \qquad x_0=a $$
It doubles the number of correct digits every iteration and so to get 500 digits you'd have to do around 10 iterations. However, note that you need arbitrary precision arithmetic, at least for division and addition.
Wikipedia lists several other methods.
An approach I really like for $\sqrt 2$ and $\sqrt 3$ is due to Apostol.
Note that
$$\sqrt 2 = \frac 7 5 \left(1- \frac 1 {50} \right)^{-1/2}$$
and that
$$\sqrt 3 = \frac {1732}{1000} \left(1- \frac {176} {3\,000\,000} \right)^{-1/2}$$
Using the Taylor series
$$\frac 1 {\sqrt{1-x}}=1+\frac 1 2 x+\frac 3 8 x^2+\frac 5 {16} x^3+\frac {35} {128} x^4+\frac {63} {256} x^5+\cdots$$
you can get great aproximations for such constants. Note how for $\sqrt 3$ you'll get a dramatic effect from the $3\,000\,000$ in the denominator. I think you can obtain the same with any $\sqrt r$, with a little bit of trickery, putting it as
$$\sqrt r= \frac {a}{b} \left(1- \frac {c} {d} \right)^{-1/2}$$
I'll try and find an analog for $\sqrt 5$.
For $\sqrt 5 $ you can go with
$$\sqrt 5 = \frac{{2236}}{{1000}}{\left( {1 - \frac{{304}}{{5000000}}} \right)^{ - 1/2}}$$
In general you need
$$d-c=a^2$$
$$d=rb^2$$
Just checked, and a $6^{th}$ degree polynomial gives 15 exact decimals (if more)
$$\sqrt 3 \approx 1.732050807568877$$
$$\sqrt 5 \approx 2.236067977499790$$
$$\sqrt 2 \approx 1.414213562373095$$
The solutions to Pell's equation can approximate $\sqrt{2}$ or in general any squarefree radical. It is known that Pell's equation has infinitely many solutions, and a recurrence form (you can find the recurrence here) of the solution can be found. As the solutions of $x^2−2y^2=1$ grow larger, the approximation is better. So you just iterate the recurrence until you have the desired precision. After that it remains to calculate the ratio $x/y$ with the $500$ digits precision you want.
In Pari-GP you can get the desired result like this:
? \p=501
? sqrt(2)
The answer is:
1.41421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993583141322266592750559275579995050115278206057147010955997160597027453459686201472851741864088919860955232923048430871432145083976260362799525140798968725339654633180882964062061525835239505474575028775996172983557522033753185701135437460340849884716038689997069900481503054402779031645424782306849293691862158057846311159666871301301561856898723724
If you like programming I suggest trying to solve some of the Project Euler problems.
Since you're interested in algebraic numbers -- i.e. irrational numbers that are not transcendental -- there are some basic methods.
First, given a complex number, you can always take it's real and imaginary parts to reduce it to a problem of real numbers.
Sturm's theorem is a general purpose way to locate the real roots of a real polynomial. You can do a binary search to narrow down the locations of the roots.
Once you have a sufficiently good approximation, Newton's algorithm is the standard way to produce more approximations of greater accuracy.
? \p=501
and then? sqrt(2)
– Beni Bogosel Apr 23 '12 at 14:58