Incorrectly rewriting an infinite product for $\pi$ I am writing a program to calculate approximations to $\pi$ from (a slight reformulation of) John Wallis' formula: $\frac{\pi}{4} = \frac{2\cdot4\cdot4\cdot6\cdot6\cdot8\cdot8\cdots}{3\cdot3\cdot5\cdot5\cdot7\cdot7\cdots}$ and I've done the following:
$$\pi = 4\cdot\frac{2\cdot4\cdot4\cdot6\cdot6\cdot8\cdot8\cdots}{3\cdot3\cdot5\cdot5\cdot7\cdot7\cdots}$$
$$\pi = 8\cdot\frac{4\cdot4\cdot6\cdot6\cdot8\cdot8\cdots}{3\cdot3\cdot5\cdot5\cdot7\cdot7\cdots}$$
$$\pi = 8\cdot\left(\frac{4^2}{3^2}\right)\left(\frac{6^2}{5^2}\right)\left(\frac{8^2}{7^2}\right)\cdots$$
$$\pi=8\cdot\prod_{i=2}^{\infty}\left(\frac{2i}{2i-1}\right)^2$$
I have done what I think is correct, simple transformations of the original products. However the product diverges, and this reformulation is wrong. Why?
 A: Note that the limit of an infinite product can be defined via an infinite sum:
$$\prod_{i=1}^\infty a_i:=\exp \sum_{i=1}^\infty \log a_i.$$ And what you are doing in your first step is rearranging the sum in question: the transformation
$$\frac{\color{red}2}{\color{blue}3}\cdot\frac{\color{purple}4}{\color{green}3}\cdots \quad\to\quad \color{red}2\cdot\frac {\color{purple}4}{\color{blue}3}\cdot\frac 4{\color{green}3} \cdots$$
is equivalent to the rearrangement
$$\color{red}{\log 2}-\color{blue}{\log 3}+\color{purple}{\log 4}-\color{green}{\log 3}+\cdots\quad\to\quad \color{red}{\log 2}+\color{purple}{\log 4}-\color{blue}{\log 3}+\log 4-\color{green}{\log 3}+\cdots.$$
But rearranging infinite sums is not always allowed and can change the limit arbitrarily (or even make it diverge) which is explained in this question. This is known as Riemann's rearrangement theorem. It is not hard to see that your corresponding sum is not absolutely convergent, hence the theorem applies.
A: As M. Winter said, you have an issue with rearranging infinite products. The original version of the Wallis product is:
$\prod \frac{4n^2}{4n^2-1}$
This product converges iff 
$\sum\log\left(\frac{4n^2}{4n^2-1}\right)$
converges. In your formulation, you are looking at the product
$\prod \frac{4n^2}{(2n-1)^2}$
which converges iff 
$\sum\log\left(\frac{4n^2}{(2n-1)^2}\right)$
converges. 
If you check wolfram I think you'll find the first sum converges while the second doesn't.
This is how you can tell if your rearrangement is causing you trouble.
A: Elaborating on @M. Winter's answer, we can look at the convergence of the series $\sum_{i=1}^{+\infty}\ln(a_i)$. The figure below shows the partial sums: $$\begin{aligned}&\ln(2)-\ln(3)+\ln(4)-\ln(3)+\ldots
\\
&\ldots+\ln(2n)-\ln(2n+1)+\ln(2n+2)-\ln(2n+1)
\end{aligned}$$
Clearly, this curve has $2$ main sections: an upper curve and a lower curve. The upper curve is formed of the partial sums with an odd number of terms, while the lower curve has an even number of terms.
It's possible for lower curve to converge, since $\ln(2n)\sim\ln(2n+1)\sim\ln(2n+2)$. Hence, $\ln(2n)-\ln(2n+1)\sim0$ and $\ln(2n+2)-\ln(2n+1)\sim0$. The even and odd terms pair up, with the sum of them approaching $0$. It's necessary for a series' terms to approach $0$ for the series to be convergent. The dotted blue line in the figure shows $y=\ln(\pi/4)\approx-0.24$.
However, the upper curve can't be convergent because $\ln(2n),\ln(2n+1),\ln(2n+2)$ all approach $+\infty$. Hence, the partial sums have an arbitrarily large last term. The divergent upper curve appears to be asymptotic to $\ln(2n)-1.627\,858$ (which in turn is $\sim\ln(n)$). The partial sum of the first $10^8+1$ terms is $17.485\,969\,138\,141\,7$ which is approximately $\ln[2\cdot(10^8+1)]-1.627\,858$.
In essence, the limit inferior of the sequence of partial sums exists, but the limit superior does not. This explains why the series won't necessarily converge if its terms are rearranged. In fact, it's equivalent to the fact that a rearrangement of the original product could give you terms greater than $1$.  

The figure was generated in GeoGebra with the codes:
n=slider[1,500]
list1=Sequence[{(4j - 3, ln(2j)), (4j - 2, -ln(2j + 1)), (4j - 1, ln(2 (j + 1))), (4j, -ln(2j + 1))}, j, 1, n]
list2=Join[Sequence[Element[list1, i], i, 1, n]]
list3=Sequence[(i, Sum[Sequence[y(Element[list2, j]), j, 1, i]]), i, 1, n]

