Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|cite|improve this question
Some irrational numbers are easier to compute than other irrational numbers. Do you really want to talk about all irrational numbers, or just certain types of them (like the roots of polynomials, for example?) – Thomas Andrews Apr 23 '12 at 14:50
There are a few methods: find an approximate sequence, use continued fraction expansion. And after that you need to program the algorithm in a good programming language. I think that the easiest one for this purpose is Pari/GP, which will give you the result for free. – Beni Bogosel Apr 23 '12 at 14:50
Non-trancendental numbers. – Guru Prasad Apr 23 '12 at 14:50
@GuruPrasad: i.e. roots of polynomials. – Beni Bogosel Apr 23 '12 at 14:53
@BeniBogosel: Can you explain how to do using continued fraction expansion? I'm at a loss here. – Guru Prasad Apr 23 '12 at 14:53
up vote 1 down vote accepted

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:


If you like programming I suggest trying to solve some of the Project Euler problems.

share|cite|improve this answer
Actually, I think this probably is for a Project Euler problem. Not sure I can blame anyone for looking this one up though. Most computer languages don't do that kind of precision normally. It took quite a while to find an algorithm just about made for a computer. – Mike Apr 23 '12 at 18:00

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.

share|cite|improve this answer
I think you approach and Beni's can be combined nicely: use the continued fraction to yield a starting point, and then polish with Newton-Raphson. – J. M. Apr 28 '12 at 16:02

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



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$$

share|cite|improve this answer

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.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.