4
$\begingroup$

After having read the answers to calculating $\pi$ manually, I realised that the two fast methods (Ramanujan and Gauss–Legendre) used $\sqrt{2}$. So, I wondered how to calculate $\sqrt{2}$ manually in an accurate fashion (i.e., how to approximate its value easily).

$\endgroup$
  • 1
    $\begingroup$ Check this page [Wikipedia, Square root of 2 -- Computation algorithms]. $\endgroup$ – Clement C. Mar 15 '15 at 21:54
  • 1
    $\begingroup$ More generally, see this wikipedia page for how to approximate any square root. You can use Newton's method for how to approximate roots of real-valued function (so in this case you can use it for the roots of $x^2-2$). $\endgroup$ – user26486 Mar 15 '15 at 21:56
  • $\begingroup$ Do you know by any chance how many digits of root 2 that we need for accuracy in order to get the 707 digits of pi using Ramanujan's formula? $\endgroup$ – Neil Mar 16 '15 at 11:10
11
$\begingroup$

One really easy way of approximating square roots surprisingly accurately was actually developed by the Babylonians.

First they made a guess at the square root of a number $N$--let this guess be denoted by $r_1$. Noting that $$ r_1\cdot\left(\frac{N}{r_1}\right)=N, $$ they concluded that the actual square root must be somewhere between $r_1$ and $N/r_1$. Thus, their next guess for the square root, $r_2$, was the average of these two numbers: $$ r_2 = \frac{1}{2}\left(r_1+\frac{N}{r_1}\right). $$ Continuing in this way, in general, once we have reached the $n$th approximation to the square root of $N$, we find the $(n+1)$st using $$ r_{n+1}=\frac{1}{2}\left(r_n+\frac{N}{r_n}\right). $$ All that you really need to do is make a moderately decent guess of the square root of a number and then apply this method two or three times and you should have quite a good approximation.

For $\sqrt{2}$, simply using a guess of $1$ and applying this method three times (the algebra involved is remarkably simple) yields an approximation of $$ \frac{577}{408}\approx \color{red}{1.41421}\color{blue}{568627}, $$ whereas $$ \sqrt{2}\approx \color{red}{1.41421}\color{green}{356237}. $$ That's quite a good approximation using an easy and quick manual method.

$\endgroup$
  • 5
    $\begingroup$ This is surprisingly the exact recursion that results from applying Newton's method. So any method that is better than this would have to be better than Newton's method. $\endgroup$ – DanielV Mar 15 '15 at 22:18
3
$\begingroup$

I think crash's post's method is the best, but if you don't want to do a lot of long divisions, then here is an alternative method for the lazy.

Suppose you want to compute $\sqrt{2}$ to $k$ decimal places. That is, you want to find $x$ in:

$$x \cdot 10^{-k} \approx \sqrt{2}$$ $$x^2 \approx 2 \cdot 10^{2k}$$

This allows you to find $x$ using a binary search: doing approximately $\log(k)$ multiplications of a $k$ digit number (and computing the average of the upper and lower bound, just adding and dividing by $2$ is easy by hand).

And the accuracy of this result guaranteed by construction. Suppose you want to calculate $\sqrt{2}$ to $8$ decimal places:

$$x^2 = 2 \cdot 10^{16}$$

$$\begin{array} {c|ccc} \text{Step} & \text{LowerBound} & \text{UpperBound} &\text{MidPoint} \\ 1 & 100000000 & 1000000000 & 550000000 \\ 2 & 100000000 & 549999999 & 324999999 \\ 3 & 100000000 & 324999998 & 212499999 \\ 4 & 100000000 & 212499998 & 156249999 \\ 5 & 100000000 & 156249998 & 128124999 \\ 6 & 128125000 & 156249998 & 142187499 \\ 7 & 128125000 & 142187498 & 135156249 \\ 8 & 135156250 & 142187498 & 138671874 \\ 9 & 138671875 & 142187498 & 140429686 \\ 10 & 140429687 & 142187498 & 141308592 \\ 11 & 141308593 & 142187498 & 141748045 \\ 12 & 141308593 & 141748044 & 141528318 \\ 13 & 141308593 & 141528317 & 141418455 \\ 14 & 141418456 & 141528317 & 141473386 \\ 15 & 141418456 & 141473385 & 141445920 \\ 16 & 141418456 & 141445919 & 141432187 \\ 17 & 141418456 & 141432186 & 141425321 \\ 18 & 141418456 & 141425320 & 141421888 \\ 19 & 141418456 & 141421887 & 141420171 \\ 20 & 141420172 & 141421887 & 141421029 \\ 21 & 141421030 & 141421887 & 141421458 \\ 22 & 141421030 & 141421457 & 141421243 \\ 23 & 141421244 & 141421457 & 141421350 \\ 24 & 141421351 & 141421457 & 141421404 \\ 25 & 141421351 & 141421403 & 141421377 \\ 26 & 141421351 & 141421376 & 141421363 \\ 27 & 141421351 & 141421362 & 141421356 \\ 28 & 141421357 & 141421362 & 141421359 \\ 29 & 141421357 & 141421358 & 141421357 \\ \end{array}$$

$29$ $8$-digit multiplications for $8$ decimal places of accuracy (and a lot of even that was redundant).

$\endgroup$
  • $\begingroup$ Hm, can you explain how you did it? $\endgroup$ – Mageek Mar 16 '15 at 18:53
  • $\begingroup$ @Mageek Do you know what a binary search is? Like if I say "I'm thinking of a number between 1 and 100" and you guess 50 and I say "too low" so now you know between 50 and 100 so you guess 75, keep going, that is a binary search. $\endgroup$ – DanielV Mar 16 '15 at 18:58
  • $\begingroup$ @Mageek This example is much less efficient than crash's, it is just an alternative that is easy to understand. $\endgroup$ – DanielV Mar 16 '15 at 19:00
3
$\begingroup$

you can use the formula $$\frac{a_{n+1}}{b_{n+1}}=\frac{a_n^2+2b_n^2}{2a_nb_n}$$ if we take an initial value of $\sqrt{2}$ as $\frac{3}{2}$

now the new value will become $$\frac{a}{b}=\frac{3^2+2*2^2}{2*2*3}=\frac{17}{12}$$

the new value of $a=17$ and $b=12$

and then continue

$\endgroup$
  • $\begingroup$ The identity you start with is not true. For example, taking $a=b=1$ it claims that $\frac11 = \frac32$ which is blatantly false. $\endgroup$ – Henning Makholm Mar 16 '15 at 12:51
  • $\begingroup$ @HenningMakholm $$\frac{1^2+2*1^2}{2*1*1}=\frac{3}{2}$$ and the next $$\frac{3^2+2*2^2}{2*3*2}=\frac{17}{12}$$ and then $$\frac{17^2+2*12^2}{2*17*12}=\frac{577}{408}$$ if you need more accuracy, continue $\endgroup$ – E.H.E Mar 16 '15 at 12:57
  • $\begingroup$ Yes, that evaluates to $\frac32$ but $\frac32$ is not the same as $\frac11$, so your claim $\frac ab=\frac{a^2+2b^2}{2ab}$ is false. Do you have any values of $a$ and $b$ that it holds for? $\endgroup$ – Henning Makholm Mar 16 '15 at 13:01
  • $\begingroup$ ok, I understood what do you mean.The formula should be written $$\frac{a_{n+1}}{b_{n+1}}=\frac{a_n^2+2b_n^2}{2a_nb_n}$$ $\endgroup$ – E.H.E Mar 16 '15 at 13:05
  • $\begingroup$ @HenningMakholm now ,Is it ok? $\endgroup$ – E.H.E Mar 16 '15 at 13:09
1
$\begingroup$

Another technique might be to use the Taylor series $$(1+x)^{1/2} = 1+ \frac 12 x - \frac 18 x^2 + \frac{1}{16} x^3 - \frac{5}{128} x^4 +\cdots.$$

The coefficients of this series are $\frac{(-1)^k }{k!} \left(\frac12\right) \left(-\frac12\right)\left(-\frac32\right)\cdots\left(\frac32 - k\right)$. You can plug in $x=1$ so that the series evaluates to $\sqrt2$, but the series converges faster if you start with a rational approximation of $\sqrt2$ and use the Taylor series to compute a correction factor, for example $\sqrt 2 = 1.4 \cdot \left(1 + \frac{1}{49}\right)^{1/2}.$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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