What is Viete's Formula?
In 1593 the French mathematician Francois Viete published the first known infinite product that expresses the constant pi in closed analytic form. It is built entirely from nested square roots of one half. This calculator evaluates that product up to a chosen number of terms and shows how quickly the value converges to \(3.14159265358979\). It is pure mathematics and gives the same answer anywhere in the world.
$$\frac{2}{\pi} = \sqrt{\tfrac12} \cdot \sqrt{\tfrac12 + \tfrac12\sqrt{\tfrac12}} \cdot \sqrt{\tfrac12 + \tfrac12\sqrt{\tfrac12 + \tfrac12\sqrt{\tfrac12}}} \cdots$$
How to use it
Enter a loop count (the number of product terms to evaluate, default 100) and pick how many display digits you want. Each extra term corresponds to doubling the number of sides of an inscribed regular polygon, going from a 4-gon up to a \(2^{(n+1)}\)-gon. Because this rebuild uses standard IEEE 754 double precision, pi is resolved to about 15 significant digits; the display-digits selector simply rounds the output to that many figures.
The formula explained
Start with \(s = 0\) and \(y = 1\). For each step \(k\), update \(s\) to the square root of \((1 + s) / 2\), then multiply that into the running product \(y\). Each factor equals \(\cos(\pi / 2^{(k+1)})\), and the product of these cosines tends to \(2/\pi\). Therefore pi is approximated by 2 divided by the running product \(y\). The estimate rises toward pi from below, gaining roughly one correct binary digit per term.
$$s_k=\sqrt{\tfrac{1+s_{k-1}}{2}},\quad y_k=\prod_{i=1}^{k}s_i,\quad \pi=\frac{2}{y_k}$$
Worked example
\(k=1\): \(s = \sqrt{0.5} = 0.70710678\), \(y = 0.70710678\), \(\pi \approx 2.82842712\). \(k=2\): \(s = 0.92387953\), \(y = 0.65328148\), \(\pi \approx 3.06146746\). \(k=3\): \(\pi \approx 3.12144515\). \(k=4\): \(\pi \approx 3.13654849\). By \(k=20\) the value already matches pi to 14 decimals, and any loop count of about 30 or more locks in \(3.14159265358979\) in double precision.
FAQ
Why does increasing display digits beyond 15 not help? Standard double-precision floating point only holds about 15 to 16 significant digits, so the underlying math cannot resolve more than that regardless of the selector.
Why does a tiny loop count give a poor estimate? The product converges geometrically; with only a handful of terms you are still approximating a low-sided polygon, so the value is noticeably below pi.
Does the result ever overshoot pi? No. Every factor is a cosine less than 1, so \(2/y\) always approaches pi from below as an under-estimate.