Pi equation with sequence
Recently in a class at school I was shown by my teacher that it is possible to show the value of pi using the formula
Pi = 2 * (2*2*4*4*6*6*8*8.....)/(1*3*3*5*5*7*7*9.......)Where the integers used on the numerator and the denominater have to be equal. The more integers you use, the more accurate the number gets. I was wondering if there was a mathematical formula for the sequence of 2,2,4,4,6,6,8,8.... and 1,3,3,5,5,7,7,9,9...... so that I could write a basic program to calculate the value of pi to a certain accuracy. Are there any formulas which allow for this?
3 Answers
$\begingroup$The formula you are using is $$A_n=2 \frac{\prod_{i=1}^n(2i)^2}{(2n+1)\prod_{i=1}^{n-1}(2i+1)^2}=2(2n+1)\frac{\prod_{i=1}^n(2i)^2}{\prod_{i=1}^{n}(2i+1)^2}$$ As said, this involves the gamma function and the result would approximate $\pi$ but very slowly.
Sooner or later, you will learn about series expansions and asymptotics. To give you an idea, for large values of $n$, you will have $$\frac{A_n}\pi=1-\frac{1}{4 n}+\frac{5}{32 n^2}-\frac{11}{128 n^3}+\frac{83}{2048 n^4}-\frac{143}{8192 n^5}+\frac{625}{65536 n^6}+O\left(\frac{1}{n^7}\right)$$ Using this expansion for $n=10000$, it would give $$\frac{A_n}\pi=\frac{104854978723830989224941697}{104857600000000000000000000}\approx 0.999975$$ I meka a table of the decimal value of $A_n$ as a function of $n$ $$\left( \begin{array}{cc} n & A_n \\ 1000 & 3.140807746 \\ 2000 & 3.141200077 \\ 3000 & 3.141330909 \\ 4000 & 3.141396335 \\ 5000 & 3.141435594 \\ 6000 & 3.141461768 \\ 7000 & 3.141480464 \\ 8000 & 3.141494486 \\ 9000 & 3.141505393 \\ 10000 & 3.141514119 \\ 11000 & 3.141521258 \\ 12000 & 3.141527207 \\ 13000 & 3.141532241 \\ 14000 & 3.141536556 \\ 15000 & 3.141540296 \\ 16000 & 3.141543568 \\ 17000 & 3.141546455 \\ 18000 & 3.141549022 \\ 19000 & 3.141551318 \\ 20000 & 3.141553385 \end{array} \right)$$
$\endgroup$ $\begingroup$There is probably a couple of ways to get the two sequences you mention as a formula. Though I don't think any are "nice".
One possibility is $a_n=(\left\lfloor{n/2}\right\rfloor+1)*2$ and $b_n=(\left\lceil{n/2}\right\rceil+1)*2+1$ assuming you start at $0$.
Though I would say if you want to write a program this is a probably not the best way to go. A for loop would probably be much easier.
double pi_acc(int n){
int i=0;
double mypi=2,a=2,b=1;
for(i=0;i<n;i++){ mypi*= (a/b); a+=( i & 0x01)*2; b+=( (i+1)&0x01)*2; }
return(mypi);
}All together though the biggest issue is that this particular product converges to $\pi$ incredibly slowly. Roughly 40000 terms gets you 5 significant digits.
$\endgroup$ $\begingroup$There is indeed a shortcut way to compute factorials faster than by doing all products explicitly: the Stirling approximation formula. See Wikipedia.
Very grossly speaking, it approximates $n!$ by $n^n$, which can be computed by logarithms, as $e^{n\log n}$. And $e$ can be raised to a larger power fast by iterative squarings ($2\log n$ multiplies instead of $n$).
Unfortunately, there is a "but": Stirling's formula requires... the knowledge of $\pi$.
$\endgroup$ 2