# Interesting integrals

Consider the integral $I=\int_0^\infty\frac{\sin(x)}{e^x-1}dx$

We can approximate it with a Riemann sum in J:

   (%~+/@(1&o.%-&1@:^)@(%~}.@i.@*&30))1e5
1.07667

Using Euler’s formula, $$\sin(x)=(e^{ix}-e^{-ix})/2i$$, and the geometric series $\frac1{1/r-1}=r+r^2+r^3+\ldots$ for $$r=e^{-x}$$, we get $I=\sum_{n=1}^\infty\int_0^\infty\frac1{2i}\left(e^{(i-n)x}-e^{(-i-n)x}\right)dx=\frac1{2i}\sum_{n=1}^\infty\left(\frac1{-i+n}+\frac1{-i-n}\right)$

We can also combine both fractions to get $$1/(n^2+1)$$.

   %&0j2+/0j_1(++&:%-)}.i.1e6
1.07667
+/%>:*:}.i.1e6
1.07667

Using the series $\pi\cot(\pi z)=\sum_{n=-\infty}^\infty\frac1{z+n}$ we then get $$I=(-\pi i\cot(-\pi i)-1)/2$$, or $$(\pi\coth(\pi)-1)/2$$, or $I=\frac\pi2\frac{e^\pi+e^{-\pi}}{e^\pi-e^{-\pi}}-\frac12$

   -:<:(*%@o.~&3)o.0j_1
1.07667
-:<:o.%7&o.o.1
1.07667
-:<:o.((+%-)&^-)o.1
1.07667

A more constructive way to view the integral is to start with $$\int_0^\infty e^{-x}dx=1$$ and scaling the $$x$$-axis by a factor $$n$$ to get $\int_0^\infty e^{-nx}dx=\frac1n$ We can then differentiate both sides $$k$$ times with respect to $$n$$ and rearrange: $\int_0^\infty\frac1{k!}x^ke^{-nx}dx=\frac1{n^{k+1}}$

Because of the Taylor series of $$\sin$$ and the geometric series we used, $$I$$ is then a double sum over positive $$n$$ and positive odd $$k$$, with alternating signs. Summing over $$k$$ first, we recover the values $$1/(n^2+1)$$ we found earlier. If we instead sum over all $$n$$ first and then sum over $$k$$, we get an alternating sum of values of the Riemann zeta function $I=\zeta(2)-\zeta(4)+\zeta(6)-\zeta(8)+\ldots$

The sum doesn’t converge, because we weren’t justified in exchanging the limits.

   zeta =: +/@((1+i.1e6)&^@-)
-/zeta 2*1+i.20
0.576673
-/zeta 2*1+i.21
1.57667

The Cesàro sum is defined as the average of the partial sums and converges slowly to $$I$$. Because $$\zeta(2k)-1\downarrow 0$$, its alternating sum does converge quickly, but we have to add $$\frac12$$.

   (+/%#)-/\zeta 2*1+i.50
1.07781
reducedzeta =: +/@((2+i.1e6)&^@-)
0.5+-/reducedzeta 2*1+i.8
1.07667

Finally, summing over all $$k,n$$ in no particular order:

   +/,((]_1&^@>:)*(^_2&*))"0/~1+i.998
0.575673
+/,((]_1&^@>:)*(^_2&*))"0/~1+i.999
1.57567