An easy way to calc PI with powers of 2 and square roots

79 Views Asked by At

I don't know if this algorithm is know, but I think it's an easy way to calc $\pi$ more quickly than others. The reason of this, it's because when I search for computing algorithms, I only find stochastic methods, or difficult methods to implement, or methods that consume too much time. Let me explain this simple method.

We know the exact value of $\cos(\frac{\pi}{4})$ and $\sin(\frac{\pi}{4})$, it's $\frac{\sqrt{2}}{2}$.

But, what's the value of $\cos(\frac{\pi}{2^n})$ with $n\gt2$? We can use the middle angle formules: $\cos(\frac{\alpha}{2})=\sqrt{\frac{1+\cos(\alpha)}{2}}$ and $\sin(\frac{\alpha}{2})=\sqrt{\frac{1-\cos(\alpha)}{2}}= \sqrt{\frac{1-\sqrt{1-\sin^2(\alpha)}}{2}}$. We are going to use the sine formule only.

For $\frac{\pi}{8}$ we have: $$\sin(\frac{\pi}{8})= \sqrt{\frac{1-\sqrt{1-\frac{1}{2}}}{2}}= \frac{1}{2}\sqrt{2-\sqrt{2}}$$

For $\frac{\pi}{16}$ we have: $$\sin(\frac{\pi}{16})= ...= \frac{1}{2}\sqrt{2-\sqrt{2+\sqrt{2}}}$$

For $\frac{\pi}{32}$ we have: $$\sin(\frac{\pi}{32})= ...= \frac{1}{2}\sqrt{2-\sqrt{2+\sqrt{2+\sqrt{2}}}}$$

You can continue if you want, and you are going to obtain a collection of nested roots in function of the power of 2. We can conclude that:

$$\sin(\frac{\pi}{2^n})= ...= \frac{1}{2}\sqrt{2-\sqrt{2+\sqrt{2+\sqrt{2... (n-2)_{nested roots}}}}}$$

We are using now the limit of the function $f(x) = \frac{sin(x)}{x}$ when x goes to 0.

$$\lim_{x \to 0} \frac{sin(x)}{x} = 1$$

If we substitute $\sin(\frac{\pi}{2^n})$ in the equation before, changing $x$ for $\frac{\pi}{2^n}$, and $x \to 0$ for $n \to \infty$, we obtain:

$$\lim_{n \to \infty} \frac{sin(\frac{\pi}{2^n})}{\frac{\pi}{2^n}} = 1$$

Where we can conclude that

$$\pi= \lim_{n \to \infty} 2^n sin(\frac{\pi}{2^n}) = \lim_{n \to \infty} \frac{2^n}{2}\sqrt{2-\sqrt{2+\sqrt{2+\sqrt{2... (n-2)_{nested roots}}}}}$$

A simple calculation with n = 14, it give to us 8 exact decimals:

$$\frac{16384 \sqrt{2-\sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2+\sqrt{2}}}}}}}}}}}}}}{2} =3.1415926...$$

I hope you understand it.