The following arctan formula for $\pi$ is quite well known $$\frac{\pi}{4} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \cdots\tag{1}$$ and bears the name of Madhava-Gregory-Leibniz series after its discoverers. The formula has an easy proof via integration. While reading a paper by Ranjan Roy titled "The Discovery of the Series Formula for $\pi$ by Leibniz, Gregory and Nilakantha" I was surprised to find that error in approximation via $n$ terms of series $(1)$ can be expressed in terms of a continued fraction studied by both Rogers and Ramanujan.
Let $$f(x) = \cfrac{1}{x +\cfrac{1^{2}}{x +\cfrac{2^{2}}{x +\cfrac{3^{2}}{x + \cdots}}}}\tag{2}$$ for $x > 0$ and let $n$ be a positive integer. Let us define $S_{n}$ by $$S_{n} = \sum_{i = 1}^{n}(-1)^{i - 1}\cdot\frac{1}{2i - 1}$$ so that $S_{n}$ is the $n^{\text{th}}$ partial sum of series $(1)$. Then we have the formula $$\frac{\pi}{4} = S_{n} + (-1)^{n}\cdot\frac{f(2n)}{2}\tag{3}$$ The formula above is so marvelous that first 2-3 convergents of the continued fraction $(2)$ are sufficient to give a very good approximation of $\pi$ for small values of $n$. For example if $n = 4$ so that $$S_{4} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} = \frac{2}{3} + \frac{2}{35} = \frac{76}{105}$$ and taking 3rd convergent of $f(8)$ we see that $$f(8) \approx \cfrac{1}{8 +\cfrac{1^{2}}{8 +\cfrac{2^{2}}{8}}} = \frac{17}{138}$$ and hence $$\frac{\pi}{4} = S_{4} + \frac{f(8)}{2} \approx \frac{76}{105} + \frac{17}{276} = 0.78540372670807$$ which is greater than $\pi/4$ by approximately $5.5 \times 10^{-6}$ so that the approximation is really great.
I would like to know the proof of identity $(3)$. Any reference for the proof would also be helpful.
Update: Sorry people! I found the answer myself when I used the information in related link about the continued fraction $f(x)$. See my answer below.
On the other hand I would be more than happy if we can obtain a proof of $(3)$ without using Rogers proof mentioned in my answer. Perhaps there was some simpler proof available with Nilkantha.