# Using an integral to generate rational approximations of $\pi$

Let $$f(r)=\int_0^1\frac{x^r(1-x)^r}{1+x^2}dx.$$ One surprising fact is that $$f(4)=\frac{22}{7}-\pi.$$ This got me thinking. Surely, it can't be a coincidence that a fairly accurate rational approximation for $$\pi$$ shows up in this way, right? Well, this is what I've found so far: $$\boxed{f(0)=\frac{\pi}{4}≈0.785}$$ $$\boxed{f(4)=\frac{22}{7}-\pi≈0.001}$$ $$\boxed{f(8)=4\pi-\frac{188684}{15015}≈3.64×10^{-6}}$$ $$\boxed{f(12)=\frac{431302721}{8580495}-16\pi≈1.18×10^{-8}}$$ $$\boxed{f(16)=64\pi-\frac{5930158704872}{29494189725}≈4.00×10^{-11}}$$ Let $$k\in\{0,1,2,\ldots\}.$$ It seems to me that $$f(4k)=4^{k-1}((-1)^k\pi+(-1)^{k+1}R_k),$$ where $$R_k$$ is some rational approximation of $$\pi.$$ We have: $$\boxed{R_0=0}$$ $$\boxed{R_1=\frac{22}{7}}$$ $$\boxed{R_2=\frac{188684}{15015×4}}$$ $$\boxed{R_3=\frac{431302721}{8580495×16}}$$ $$\boxed{R_4=\frac{5930158704872}{29494189725×64}}$$ I have three conjectures at this point: $$\textbf{C1:}\lim_{r\to\infty}f(r)=0.$$ $$\textbf{C2:}\forall k\in\{0,1,2,\ldots\},f(4k)=4^{k-1}((-1)^k\pi+(-1)^{k+1}R_k),R_k\in\mathbb{Q}.$$ $$\textbf{C3:}\lim_{k\to\infty}R_k=\pi.$$ Clearly, $$(\textbf{C1}\wedge\textbf{C2})\implies\textbf{C3}.$$ How do we go about proving these conjectures? It seems like $$\textbf{C2}$$ is the toughest of the three. $$\textbf{C1}$$ makes intuitive sense as the integrand is a decreasing function of $$r.$$

• +1; C1 follows immediately from the dominated convergence theorem Mar 26, 2023 at 13:37
• @CalvinKhor, oh, cool. Also, $(\textbf{C1}\wedge\textbf{C2})$ does imply $\textbf{C3},$ right? Mar 26, 2023 at 13:55
• Yes, that's right. I think this is answered by en.wikipedia.org/wiki/Proof_that_22/7_exceeds_π#Extensions which I found here math.stackexchange.com/questions/2488985/…; see also math.stackexchange.com/questions/1654104/… Mar 26, 2023 at 14:34
• By the way, these approximations of $\pi$ are not very good, except for $R_1$. $R_1$ gives three-digit accuracy with a one-digit denominator. $R_4$ gives eleven digits with a $13$-digit denominator. You can do better with $3141592653589/1000000000000$. And much better with convergents of the continued fraction for $\pi$. Mar 27, 2023 at 5:29
• Relevant link: jstor.org/stable/27642693. Mar 27, 2023 at 20:03

As mentioned in comments, C1 follows immediately from the dominated convergence theorem, and as you said, proving C2 proves C3.

For C2, one can check the proof of Wikipedia. It is stated that \begin{align} \frac1{2^{2n-2}} \int_0^1\frac{x^{4n}(1-x)^{4n}}{1+x^2}\,dx = \sum_{j=0}^{2n-1}\frac{(-1)^j}{2^{2n-j-2}(8n-j-1)\binom{8n-j-2}{4n+j}} +(-1)^n\left(\pi-4\sum_{j=0}^{3n-1}\frac{(-1)^j}{2j+1}\right) \end{align} from which we infer that $$R_k = 4\sum_{j=0}^{3k-1} \frac{(-1)^j}{2j+1} - \sum_{j=0}^{2k-1}\frac{(-1)^{k+j}}{2^{2k-j-2}(8k-j-1)\binom{8k-j-2}{4k+j}}$$ is a finite sum of rationals, hence rational.

Given that the other answers (at time of writing) somehow do not seem to answer the question, the only point of this answer is to have a copy of Wikipedia's proof on this website as well. (Apparently the page was nominated for deletion before...) Here it is -

For all integers $$k ≥ 0$$ and $$\ell ≥ 2$$ we have \begin{align} x^k(1-x)^\ell&=(1-2x+x^2)x^k(1-x)^{\ell-2}\\ &=(1+x^2)\,x^k(1-x)^{\ell-2}-2x^{k+1}(1-x)^{\ell-2}. \end{align}

Applying this formula recursively $$2n$$ times yields $$x^{4n}(1-x)^{4n} =\left(1+x^2\right)\sum_{j=0}^{2n-1}(-2)^jx^{4n+j}(1-x)^{4n-2(j+1)}+(-2)^{2n}x^{6n}.$$ Furthermore,

\begin{align} x^{6n}-(-1)^{3n} &=\sum_{j=1}^{3n}(-1)^{3n-j}x^{2j}-\sum_{j=0}^{3n-1}(-1)^{3n-j}x^{2j}\\ &=\sum_{j=0}^{3n-1}\left((-1)^{3n-(j+1)} x^{2(j+1)}-(-1)^{3n-j}x^{2j}\right)\\ &=-(1+x^2)\sum_{j=0}^{3n-1} (-1)^{3n-j}x^{2j}, \end{align}

where the first equality holds, because the terms for $$1 ≤ j ≤ 3n – 1$$ cancel, and the second equality arises from the index shift $$j → j + 1$$ in the first sum.

Application of these two results gives

\begin{align}\frac{x^{4n}(1-x)^{4n}}{2^{2n-2}(1+x^2)} =\sum_{j=0}^{2n-1} & \frac{(-1)^j}{2^{2n-j-2}}x^{4n+j}(1-x)^{4n-2j-2}\\ & {} -4\sum_{j=0}^{3n-1}(-1)^{3n-j}x^{2j}+(-1)^{3n}\frac4{1+x^2}.\tag{1} \end{align}

For integers $$k, \ell ≥ 0$$, using integration by parts $$\ell$$ times, we obtain

\begin{align} \int_0^1x^k(1-x)^\ell\,dx &=\frac \ell{k+1}\int_0^1x^{k+1}(1-x)^{\ell-1}\,dx\\ &\,\,\,\vdots\\ &=\frac \ell{k+1} \frac{\ell-1}{k+2}\cdots\frac1{k+\ell}\int_0^1x^{k+\ell}\,dx\\ &=\frac{1}{(k+\ell+1)\binom{k+\ell}{k}}.\tag{2} \end{align}

Setting $$k = \ell = 4n$$, we obtain

$$\int_0^1 x^{4n} (1-x)^{4n}\,dx = \frac{1}{(8n+1)\binom{8n}{4n}}.$$

Integrating equation (1) from 0 to 1 using equation (2) and $$\arctan(1) = \frac{π}4$$, we get the claimed equation involving $$\pi$$.

• Hey Calvin, excellent work as always. Can you make any similar progress on the "typo" integral $$g(p)=\int_0^1\frac{x^p(1-x^p)}{1+x^2}\mathrm dx$$ As mentioned in my answer? It also appears to have the property that $g(4n)$ is always rational. Jun 15, 2023 at 16:49
• @K.defaoite well, I tried at the time your answer was posted. Perhaps it is worth a new question? Jun 15, 2023 at 23:29
• @K.defaoite I see you have asked the question and gotten a nice answer :) Jun 16, 2023 at 15:46

The integral can be evaluated with Laplaces method when $$r\to\infty$$. From the link, one has that an integral on the form according to below with a minimum of $$p(x)$$ at $$x=a$$ to leading order is given by

$$\int_a^b \exp(-rp(x))q(x)dx \sim \frac{Q}{\mu} \Gamma\left(\frac{\lambda}{\mu}\right) \frac{e^{-rp(a)}}{(Pr)^{\lambda/\mu}}, \quad r\to \infty$$

where the constants are found from the Taylor expansions of $$p(x)$$ and $$q(x)$$ around $$x=a$$ respectively. In this case, one has

$$f(r) = \int_0^1 \frac{x^r(1-x)^r}{1+x^2} dx=\int_0^1 \exp\left(-rp(x) \right) q(x)dx$$

with $$p(x) = -\ln(x(1-x))$$ and $$q(x) = (1+x^2)^{-1}$$. With a minimum at $$x = 1/2$$ one has that around $$x=1/2$$,

$$p(x) = \ln(4)+4\left(x-\frac{1}{2}\right)^2 +...$$ $$q(x) = \frac{4}{5}-\frac{16}{25}\left(x-\frac{1}{2}\right)+...$$

Splitting the integral into two parts, the first from $$0$$ to $$1/2$$ and the second from $$1/2$$ to $$1$$, one has that

$$\int_{1/2}^1 \exp\left(-rp(x) \right) q(x)dx \sim \frac{4^{-r}}{5}\sqrt{\frac{\pi}{r}}$$

and letting $$x\to x+1/2$$ gives similarly that the integral from $$0$$ to $$1/2$$ is the same as the one above. Hence, to leading order, one has

$$f(r) = \int_0^1 \frac{x^r(1-x)^r}{1+x^2} dx \sim \frac{2\cdot4^{-r}}{5}\sqrt{\frac{\pi}{r}}, \quad r \to \infty$$

Now, e.g. looking at $$f(4k)$$ with $$k=8$$ gives that $$f(4k) = 6.712\cdot 10^{-21}$$ whereas the asymptotic expression gives $$f(4k) \sim \frac{4^{-4k}}{5} \sqrt{\frac{\pi}{k}} = 6.794\cdot 10^{-21}$$.

If it is possible to get $$\textbf{C}_2$$ or $$\textbf{C}_3$$ from here, I'm not sure. I mean, you could take your assumption from $$\textbf{C}_2$$ and plug in the asymptotic expression, which would give $$R_k \sim \pi +(-1)^{k-1}\frac{4^{-5k+1}}{5} \sqrt{\frac{\pi}{k}}$$ but I don't really think it makes much sense that way.

• Thanks, Axel. This integral and it's variants seems to have some sort of weird link with $\pi$ and $\ln(2).$ Curious. Mar 27, 2023 at 20:02
• You had a more than great idea ! Mar 28, 2023 at 2:40
• In hindsight, maybe I should’ve posted the result only as a comment as the result fails to answer most of the question. Calvins answer looks very nice though! Mar 28, 2023 at 5:48
• @AxelT well personally I am very happy for your answer to take the space it does, for it gives an asymptotic for the opaque formula in my answer (which I again stress I did not find myself; thanks Wikipedia) Mar 28, 2023 at 9:44
• @aqualubix See my answer here. The "weird link" can be explained via partial fractions. The expression is of the form $f(x) + ( a + bx) / (1+x^2)$, where $f(x)$ is a polynomial with rational coefficients, and $a, b$ are rational numbers. Integrating these terms then yields a rational number, $\pi$, and $\log 2$ (with relevant rational coefficients). Jun 16, 2023 at 0:36

$$f(r)=\int_0^1\frac{x^r(1-x)^r}{1+x^2}dx$$ $$f(r)=\sqrt{\pi }\,\,\frac{ \Gamma (r+1)}{2^{2 r+1}\,\,\Gamma \left(r+\frac{3}{2}\right)}\, _3F_2\left(1,\frac{r+1}{2},\frac{r+2}{2};r+1,\frac{2r+3}{ 2};-1\right)$$ In terms of summation $$f(r)=\Gamma (r+1)\sum_{n=0}^\infty(-1)^n\,\frac{\Gamma (2 n+r+1)}{\Gamma (2 (n+r+1))}$$ which will converge very fast since $$a_n=\frac{\Gamma (2 n+r+1)}{\Gamma (2 (n+r+1))}\quad \implies \quad \log\left(\frac{a_{n+1}}{a_n}\right)=-\frac{r+1}{n}+\frac{(r+1) (3 r+4)}{4 n^2}+O\left(\frac{1}{n^3}\right)$$

As you noticed, if $$r=4k$$, we obtained what you observed and conjectured.

Computing up to $$r=100$$ $$\log(f(r))=a + b\,r$$ with $$R^2=0.9999985$$ $$\begin{array}{|llll} \hline \text{} & \text{Estimate} & \text{Std Error} & \text{Confidence Interval} \\ a & -2.14647 & 0.04008 & \{-2.22601,-2.06693\} \\ b & -5.55932 & 0.00069 & \{-5.56069,-5.55795\} \\ \end{array}$$

Edit

@AxelT approach is very appealing and could be extended a little bit.

Writing $$q(x)=\sum_{n=0}^m a_n\,\left(x-\frac{1}{2}\right)^n$$ $$I_n=\int_{0}^1 \exp\left(-r\,p(x) \right) \left(x-\frac{1}{2}\right)^n\,dx$$ $$I_n=2^{-(n+2 r+1)} r^{-\frac{n+1}{2}} \left(\Gamma \left(\frac{n+1}{2}\right)-\Gamma \left(\frac{n+1}{2},r\right)\right)$$ $$I_n \sim \frac 1{2^{n+2 r+1} }\left(r^{-\frac{n+1}{2}} \Gamma \left(\frac{n+1}{2}\right) -\frac{e^{-r} (n+2 r-1)}{2 r^2}\right)$$

With $$m=2$$ $$f(r)\sim\frac 1{2^r}\left(\frac{2}{5} \sqrt{\frac{\pi}{r}}-\frac{4}{25 r}-\frac{\sqrt{\pi }}{125 r^{3/2}}-e^{-r}\frac{ 28 r-26}{125 r^2}\right)=g(r)$$ which is a decent approximation even for small values of $$r$$ $$\left( \begin{array}{ccc} r & \log(g(r)) & \log(f(r)) \\ 1 & -2.02322 & -2.02517 \\ 2 & -3.66861 & -3.63135 \\ 3 & -5.20670 & -5.17007 \\ 4 & -6.71015 & -6.67309 \\ 5 & -8.19183 & -8.15398 \\ 6 & -9.65820 & -9.61981 \\ 7 & -11.1133 & -11.0747 \\ 8 & -12.5599 & -12.5213 \\ 9 & -13.9998 & -13.9615 \\ 10 & -15.4344 & -15.3963 \\ \end{array} \right)$$

• Thanks for your very informative answer, Claude. However, I will be unaccepting your answer as I want people to be encouraged to prove that $R_k\in\mathbb{Q}.$ Either way, great answer. Mar 27, 2023 at 20:07

Lazy way to prove C1, C2, C3, without evaluating $$R_k$$:

We have an isomorphism of fields: $$\mathbb{Q}[i]\to\mathbb{Q}[x]/(1+x^2),$$ identifying $$i\mapsto x$$.

Thus to find the remainder left after dividing a polynomial $$p$$ by $$1+x^2$$, we may simply evaluate $$p(i)=a+bi$$ (with $$a,b\in\mathbb{Q}$$) and take $$a+bx$$ as the remainder.

In particular $$x^{4k}(1-x)^{4k}$$ evaluated at $$i$$ is just $$((1-i)^4)^k=(-4)^k$$. Thus $$\frac{x^{4k}(1-x)^{4k}}{1+x^2} = p(x)+\frac{(-4)^k}{1+x^2},$$ where $$p(x)\in \mathbb{Q}[x]$$.

Thus $$\int_0^1 \frac{x^{4k}(1-x)^{4k}}{1+x^2} dx = \int_0^1 p(x) dx +\int_0^1 \frac{(-4)^k}{1+x^2} dx$$ $$=R_k'+(-1)^k 4^{k-1}\pi,$$ with $$R_k'\in \mathbb{Q}$$.

This is just C2 with $$R_k=(-4)^{1-k} R_k'$$.

For C1 just note that $${\rm sup}_{x\in [0,1]}\{x(1-x)\}=\frac14$$ and $${\rm inf}_{x\in [0,1]}\{1+x^2\}=1$$, so $$0\leq \int_0^1 \frac{x^{r}(1-x)^{r}}{1+x^2} dx \leq \frac1{4^r}.$$

C3 follows immediately.

Recurrence

Define $$\newcommand{\rmod}[1]{\quad\left(\text{mod}\ \ {#1}\right)} f(n)=\int_0^1\frac{x^n(1-x)^n}{1+x^2}\,\mathrm{d}x\tag1$$ We would like to find a recurrence relation for $$f(n)$$. To do this, we will find $$a,b,c$$ so that $$ax^2(1-x)^2+bx(1-x)+c\equiv0\rmod{1+x^2}\tag2$$ Using $$\{1,x\}$$ as a basis for $$\left.\mathbb{R}[x]\middle/\left(1+x^2\right)\right.$$, \begin{align} 1&\equiv1&\rmod{1+x^2}\tag{3a}\\ x(1-x)&\equiv1+x&\rmod{1+x^2}\tag{3b}\\ x^2(1-x)^2&\equiv2x&\rmod{1+x^2}\tag{3c} \end{align} Working from $$(3)$$, we can see that $$x^2(1-x)^2-2x(1-x)+2\equiv0\rmod{1+x^2}\tag4$$ Noting that $$\left(u^2-2u+2\right)\left(u^2+2u+2\right)=u^4+4$$ and setting $$u=x(1-x)$$, multiply $$(4)$$ by $$x^2(1-x)^2+2x(1-x)+2$$ to get $$x^4(1-x)^4+4\equiv0\rmod{1+x^2}\tag5$$ In fact, $$x^4(1-x)^4+4 =\left(x^6-4x^5+5x^4-4x^2+4\right)\left(1+x^2\right)\tag6$$ Thus, using the Beta Function Integral, we get \begin{align} \hspace{-24pt}f(n+4)+4f(n) &=\int_0^1x^n(1-x)^n\frac{x^4(1-x)^4+4}{1+x^2}\mathrm{d}x\tag{7a}\\ &=\int_0^1x^n(1-x)^n\left(x^6-4x^5+5x^4-4x^2+4\right)\mathrm{d}x\tag{7b}\\ &=\frac1{n+1}\left(\frac1{\binom{2n+7}{n+1}}-\frac4{\binom{2n+6}{n+1}}+\frac5{\binom{2n+5}{n+1}}-\frac4{\binom{2n+3}{n+1}}+\frac4{\binom{2n+1}{n+1}}\right)\tag{7c}\\[6pt] &\in\mathbb{Q}\tag{7d} \end{align} Since $$f(0)=\frac\pi4$$, we get that $$f(4n)\equiv(-4)^n\frac\pi4\rmod{\mathbb{Q}}\tag8$$ Furthermore, since $$x(1-x)\le\frac14$$, we get that $$f(4n)\le\frac1{256^n}\tag9$$

Conjectures

The conjectures in the question can be verified using $$(8)$$ and $$(9)$$.

$$\textbf{C1}$$ follows directly from $$(9)$$.

$$\textbf{C2}$$ follows from $$(8)$$, which says that $$\frac{f(4n)}{4^{n-1}}=(-1)^n\pi+(-1)^{n-1}R_n$$, for some $$R_n\in\mathbb{Q}$$.

$$\textbf{C3}$$ follows from $$\textbf{C2}$$ and $$(9)$$: $$|\pi-R_n|=\frac{f(n)}{4^{n-1}}\le\frac4{1024^n}$$

Computation of the Integral

We can use $$\text{(7c)}$$ to compute $$f(4n)$$. $$\begin{array}{r|l} n&f(4n)&\approx f(4n)&\approx\frac1{256^n}\\\hline 0&\frac\pi4&0.7853981634&1.0000000000\\ 1&\frac{22}7-\pi&0.0012644893&0.0039062500\\ 2&4\pi-\frac{188684}{15015}&3.6479922066\times10^{-6}&1.5258789063\times10^{-5}\\ 3&\frac{431302721}{8580495}-16\pi&1.1814790762\times10^{-8}&5.9604644775\times10^{-8}\\ 4&64\pi-\frac{5930158704872}{29494189725}&4.0282588889\times10^{-11}&2.3283064365\times10^{-10}\\ 5&\frac{26856502742629699}{33393321606645}-256\pi&1.4141199610\times10^{-13}&9.0949470177\times10^{-13}\\ 6&1024\pi-\frac{423877461668007447086}{131762096268962445}&5.0587290930\times10^{-16}&3.5527136788\times10^{-15} \end{array}$$

Some thoughts.

$$f(p)=\int_0^1 \frac{x^p(1-x)^p}{1+x^2}\mathrm dx$$

Now, recall that $$\pi=4\int_0^1 \frac{1}{1+x^2}\mathrm dx$$

So $$f(4k)-4^{k-1}(-1)^{k}\pi \\ =\int_0^1 \frac{x^{4k}(1-x)^{4k}}{1+x^2}\mathrm dx~+(-1)^{k+1}4^k\int_0^1\frac{1}{1+x^2}\mathrm dx \\ =\int_0^1 \frac{x^{4k}(1-x)^{4k}+(-1)^{k+1}4^k}{1+x^2}\mathrm dx$$

Maybe there is some way to show that this is rational?

Another interesting finding - I accidentally typed $$(1-x^{4k})$$ instead of $$(1-x)^{4k}$$ when trying to evaluate $$f(4k)$$, but strangely "typo" integral,

$$g(p)=\int_0^1\frac{x^p(1-x^p)}{1+x^2}\mathrm dx$$

Seems to have the strange property that $$g(4k)\in\mathbb Q$$ when $$k\in\mathbb N$$. For example, Mathematica is telling me that $$g(4\cdot 1)=\frac{2}{35} \\ g(4\cdot 2)=\frac{196}{6~435} \\ g(4\cdot 3)=\frac{208~786}{10~140~585} \\ g(4\cdot 4)=\frac{489~772~744}{31~556~720~475} \\ \text{etc}.$$

There must be something deeper going on.

• "There must be something deeper going on." My thoughts exactly. This link might be of interest to you: jstor.org/stable/27642693. The links given in the comments above led me to look up "Dalzell integrals", which eventually led me to this link. Mar 27, 2023 at 20:01
• @aqualubix Thanks for the link. Did you find anything on the typo integral? Mar 28, 2023 at 9:47
• Not really, even Wolfram Alpha didn't return anything. Mar 29, 2023 at 6:21
• FYI See tkf's solution above to see how to extend my ideas to this problem for a similarly quick solution. The key is to get the remainder when $f(x)$ is divided by $1+x^2$, which can be done via Remainder Factor Theorem. Jun 25, 2023 at 15:13