# Evaluating the Definite Integral $\int_{0}^{1}\frac{2 \sin \pi x \cos \pi x}{1+x^2}dx$

How can I find this integral $$I=\int_{0}^{1}\frac{2 \sin \pi x \cos \pi x}{1+x^2}dx$$

Any trick that could compute the definite integral is acceptable. However, it will be more challenging to find a primitive.

Any hint or help is appreciated.

My Work

I just wrote the integral as

$$I=\int_{0}^{1}\frac{\sin 2 \pi x}{1+x^2}dx$$

Then, I decided to introduce

$$J(\alpha)=\int_{0}^{1}\frac{\sin \alpha x}{1+x^2}dx$$

and solve a more general problem. Hence, we would have $I=J(2\pi)$ as a special result. But I don't know how to go further. I tried integration by parts and substitutions but to no avail!

• Why do you think that this has a "simple" form solution? – Mark Viola Dec 19 '15 at 21:42
• @Dr.MV: Maybe the primitive be complicated, But I feel that there should be a trick to just evaluate the definite integral without computing the primitive. Anyway, I have no satisfactory reasons for a simple solution to exist! At least, I want to know how it can be obtained! :) – H. R. Dec 19 '15 at 21:47
• Have you tried differentiating under the integral sign? – Zain Patel Dec 19 '15 at 22:40
• @ZainPatel: mmmm, Nope! :) – H. R. Dec 19 '15 at 22:41

We need

$$I = \int_0^1 \dfrac{\sin(2\pi x)}{1+x^2}dx = \sum_{k=0}^{\infty} (-1)^k \int_0^1 x^{2k}\sin(2\pi x)dx$$

We have

\begin{align} I_{k} & = \int_0^1 x^{2k}\sin(2\pi x) dx \\ &= -\dfrac1{2\pi} \int_0^1 x^{2k} d\left(\cos(2\pi x)\right) \\ &= -\dfrac1{2\pi}\left(1-2k\int_0^1 x^{2k-1}\cos(2\pi x)dx\right)\\ & = -\dfrac1{2\pi} \left(1-\dfrac{k}{\pi}\int_0^1x^{2k-1}d\left(\sin(2\pi x)\right)\right) \\ &= -\dfrac1{2\pi}\left(1+\dfrac{k(2k-1)}{\pi}I_{k-1}\right) \end{align} Hence, we obtain $$I = \sum_{k=0}^{\infty} (-1)^k I_k$$ where $I_k$ satisfies the recurrence $$I_k = -\dfrac1{2\pi}\left(1+\dfrac{k(2k-1)}{\pi}I_{k-1}\right)$$ with $I_0 = 0$.

Note for @ClaudeLeibovici: I just made sure that this is due to catastrophic cancellation in finite precision. You might already be familiar with this, but still. Below is the results I obtain using an adaptive Gaussian quadrature for $I_k$ accurate up to $14$ digits on a $64$ bit machine and using the recurrence done on a $64$ bit machine. One always needs to be careful evaluating even a simple recurrence as I have written here. The recurrence arising out of this question goes into my teaching list when I discuss evaluating recurrences in class the next time :-).

The C++ code evaluating the recurrence is shown below.

#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<vector>

double PI   =   3.141592653589793238;

int main(int argc, char* argv[]) {
int n   =   atoi(argv[1]);
std::vector<double> I;
I.push_back(0.0);
for (int k=1; k<=n; ++k) {
double temp =   -0.5/PI*(1.0+k*(2.0*k-1.0)/PI*I[k-1]);
I.push_back(temp);
}
for (int j=0; j<=n; ++j) {
std::cout << "Term " << j << " is: " << std::setprecision(15) << I[j] << "\n";
}
double S    =   0.0;
for (int j=0; j<=n; j+=2) {
S+=I[j];
}
for (int j=1; j<=n; j+=2) {
S-=I[j];
}
std::cout << "\nThe integral is: " << S << "\n";
}

• I was going to write this myself! :) Can we solve the recurrence relation? :) – H. R. Dec 20 '15 at 10:46
• I dont know where I may have a mistake but, using the formula, the $I_k$ are just exploding : $I_{30}\approx -6.82906\times 10^{18}$, $I_{31}\approx 6.54218\times 10^{20}$, $I_{32}\approx -6.68165\times 10^{22}$, $I_{99}\approx 1.15444\times 10^{197}$, $I_{100}\approx -1.16384\times 10^{200}$. – Claude Leibovici Dec 20 '15 at 12:31
• @ClaudeLeibovici This is due to round off. Try Wolfram Alpha instead. I ran into the same issue :-) – Adhvaitha Dec 20 '15 at 15:55
• @H.R. There is no simple solution to the recurrence. Further, care needs to be taken while evaluating the recurrence. – Adhvaitha Dec 20 '15 at 15:56
• @H.R. It is indeed due to round off. See my updated answer. – Adhvaitha Dec 20 '15 at 17:44

Let's try your last idea and start with : $$J(\alpha):=\int_{0}^{1}\frac{\sin \alpha x}{1+x^2}dx$$

Then $\;\displaystyle J''(\alpha)=-\int_{0}^{1}\frac{x^2\;\sin \alpha x}{1+x^2}dx\;$ and we obtain this ODE : $$J(\alpha)-J''(\alpha)=\frac {1-\cos(\alpha)}{\alpha}$$ The solution of the homogeneous ODE is simply $\;J(x)=ae^x+be^{-x}$.

Let's use variation of constant and start with $J(x)=a(x)e^x$ then : \begin{align} J(x)&=a(x)e^x\\ J'(x)&=(a'(x)+a(x))e^x\\ J''(x)&=(a''(x)+2a'(x)+a(x))e^x\\ J(x)-J''(x)&=-(a''(x)+2a'(x))e^x=\frac {1-\cos(x)}{x}\\ \end{align} For $b(x):=-a'(x)\,$ we have

\begin{align} b'(x)+2b(x)&=\frac {1-\cos(x)}{x}e^{-x}\\ \end{align}

For $b(x):=c(x)e^{-2x}\,$ this becomes for $\operatorname{Ei}$ the exponential integral :

\begin{align} c'(x)&=\frac {1-\cos(x)}{x}e^{x}\\ c(x)&=\int\frac {e^{x}}x\,dx-\int\frac {e^{x+ix}+e^{x-ix}}{2\,x}\,dx\\ c(x)&=C+\operatorname{Ei}(x)-\frac 12\operatorname{Ei}((1+i)x)-\frac 12\operatorname{Ei}((1-i)x)\\ \end{align}

Coming back to $a(x)$ :

\begin{align} a'(x)&=-\left(C+\operatorname{Ei}(x)-\frac 12\operatorname{Ei}((1+i)x)-\frac 12\operatorname{Ei}((1-i)x)\right)e^{-2\,x}\\ \end{align}

Now $\ \displaystyle \int \operatorname{Ei}(u\,x)e^{-vx}\,dx=\frac 1v\left(\operatorname{Ei}((u-v)x)-e^{-vx}\operatorname{Ei}(u x)\right)\;$ from Wolfram functions so that for $\,v=2$ and $u=1,1+i,1-i$ : $$a(x)=D-\frac 12\left(C_1\,e^{-2x}+\operatorname{Ei}(-x)-e^{-2x}\operatorname{Ei}(x)\\-\frac 12\left(\operatorname{Ei}((-1+i)x)-e^{-2x}\operatorname{Ei}((1+i)x)+\operatorname{Ei}((-1-i)x)-e^{-2x}\operatorname{Ei}((1-i)x)\right)\right)$$

Multiplying by $e^x$ we get the general formula for $J(x)$ : $$J(x)=De^x+D_1\,e^{-x}-\frac {e^x\operatorname{Ei}(-x)-e^{-x}\operatorname{Ei}(x)}2\\+\frac {e^x\operatorname{Ei}((-1+i)x)-e^{- x}\operatorname{Ei}((1+i)x)+e^x\operatorname{Ei}((-1-i)x)-e^{-x}\operatorname{Ei}((1-i)x)}4$$ (of course getting this with alpha is faster!)

Now we have to find $J(2\pi)$ knowing that $J(0)=0$ (I'll let you try too!).

• (+1), Nice Job! And also hard! :) I think that we don't really need the homogeneous solution! Do we? :) – H. R. Dec 19 '15 at 23:10
• Thanks @H.R.! Concerning the exponentials I am not sure (I don't exclude say a $\sinh(2\pi)$ at this point...) Btw if you have mathematica (I don't) could you try a FullSimplify for $x=2\pi$ on this. – Raymond Manzoni Dec 19 '15 at 23:14
• They have to be fixed from your condition (here $J(0)=0$ and something else ($J'(0)$ or $J(\infty)$ or whatever). Well the $a,b$ were different constants then...! :-) – Raymond Manzoni Dec 19 '15 at 23:18
• @H.R. Yes we could but I fear that it will be more complicated than doing the same thing on your initial integrand (I mean that integrating something like $\sin(2\pi x)x^{2n}$ may be simpler... I was unable to find something simple related to $\;\operatorname{Ei}(2\pi)$ or $\;\operatorname{Ei}(2\pi(1\pm i))$ ('symmetrized' combined with exp. like at the end or not) so no sure that much will get out of all this sorry... – Raymond Manzoni Dec 19 '15 at 23:54
• @H.R. Good question! (the answer would require to read a whole book about symbolic integration again... :-) with Mma's special additions). Anyway the result is the same with nothing special at value $x=1$ (no closed form seem to be known for $\;\operatorname{Ei}(2\pi)$ or for other real values other than $0$). – Raymond Manzoni Dec 20 '15 at 0:25

I don't think you will get a simple answer judging by Mathematica's output:

Integrate[2 Sin[Pi x] Cos[Pi x]/(1 + x^2), {x, 0, 1}]

produces

Cosh[\[Pi]] (CosIntegral[(-2 + 2 I) \[Pi]] - 2 CosIntegral[2 I \[Pi]] + CosIntegral[(2 + 2 I) \[Pi]]) Sinh[\[Pi]] + 1/2 Cosh[2 \[Pi]] (2 SinhIntegral[2 \[Pi]] + I (SinIntegral[(-2 + 2 I) \[Pi]] + SinIntegral[(2 + 2 I) \[Pi]]))

Numerically,

NIntegrate[2 Sin[Pi x] Cos[Pi x]/(1 + x^2), {x, 0, 1}]

produces

0.0926961.

• Thanks. :) I know it is hard. That's why I am putting it here. Humans do better than machines! :) Please use MathJax for formatting equations! :) – H. R. Dec 19 '15 at 21:13

Let us consider $$I=\int \frac{\sin(2 \pi x)}{1+x^2} \,dx$$ Now, since $$\frac{1}{1+x^2}=\frac i 2\left( \frac{1}{x+i}-\frac{1}{x-i} \right)$$ hence $$I=\frac i 2\left(\int \frac{\sin(2 \pi x)}{x+i} \,dx-\int \frac{\sin(2 \pi x)}{x-i} \,dx\right)$$ Now, considering the first integral, writing $2\pi x=2\pi(x+i)-2i\pi$ and expanding $\sin(a-b)$ ,$$\sin(2 \pi x)=\cosh (2\pi ) \sin (2 \pi (x+i))- i \sinh (2\pi) \cos (2 \pi (x+i))$$ Now, change variable $2\pi(x+i)=t$ to make $$\int \frac{\sin(2 \pi x)}{x+i} \,dx=\cosh(2\pi)\int \frac{\sin(t)}{t} \,dt-i \sinh(2\pi)\int \frac{\cos(t)}{t} \,dt$$ and using $$\int \frac{\sin(t)}{t} \,dt=\text{Si}(t)\quad , \quad \int \frac{\cos(t)}{t} \,dt=\text{Ci}(t)$$ Doing almost the same for the second integral, recombining and back to $x$ $$2I=\sinh (2 \pi ) (\text{Ci}(2 \pi (i-x))+\text{Ci}(2 \pi (i+x)))+i \cosh (2 \pi ) (\text{Si}(2 \pi (i+x))+\text{Si}(2 \pi (i- x))$$ from which you get E.tsukerman's result.

Edit

Using the same approach for $$J=\int\frac{\sin (\alpha x)}{1+x^2}\,dx$$ $$2J=\sinh (\alpha ) (\text{Ci}(\alpha(i-x) )+\text{Ci}(\alpha(i+x) ))+i \cosh (\alpha ) (\text{Si}(\alpha(i+x) )+\text{Si}( \alpha(i-x ))$$

Edit

Concerning the numerical value, it is awful (just as already said by other participants).

For $x=1$, the value is $\approx -0.077380457987+420.572696077718 i$

For $x=0$, the value is $\approx -0.170076586683+420.572696077718 i$

Edit

For the antiderivative, doing the same, it would have been faster to compute $$K=\int \frac{e^{i ax}}{1+x^2} \,dx=\frac i 2 \left( e^a \,\text{Ei}(a(ix-1))-e^{-a}\, \text{Ei}(a(i x+1))\right)$$

• +1: I don't have much hope for a simple solution here. Cheers anyway! – Raymond Manzoni Dec 20 '15 at 9:00
• @RaymondManzoni. This is simple, no ? Cheers. – Claude Leibovici Dec 20 '15 at 9:01
• well for $x=1$ you still have $\operatorname{Ci}(2\pi(i+1))$ to evaluate : not much simpler than the initial integral I fear... – Raymond Manzoni Dec 20 '15 at 9:04
• @RaymondManzoni. I totally agree with you concerning the problem of the evaluation. I just tried to show that the antiderivative problem was workable. – Claude Leibovici Dec 20 '15 at 9:06
• @H.R. This was done using pen and paper !! Cheers :-) – Claude Leibovici Dec 20 '15 at 12:24