Switching the sum and integral So I was calculating $\psi\left(\frac{1}{3}\right)$, I started with
$$\psi(s+1)=-\gamma+\sum_{n=1}^{\infty}\frac{1}{n}-\frac{1}{n+s}$$
putting $s=-\frac{2}{3}$ and do a variable shift,
$$\psi\left(\frac{1}{3}\right)=-\gamma+\sum_{n=0}^{\infty}\frac{1}{n+1}-\frac{3}{3n+1}$$
$$=-\gamma+\sum_{n=0}^{\infty}\left(\int_0^{1} x^n dx-\int_0^1 3x^{3n}dx\right)$$
If I switch the sum and integral
$$-\gamma+\int_0^{1}\left(\frac{1}{1-x}-\frac{3}{1-x^3}\right)dx$$
I got $-\gamma-\frac{\pi}{2\sqrt{3}}-\frac{\log(3)}{2}$. Which is not the correct answer. why? I checked on wolfram alpha and I did calculate the integral right. I used the same method to calculate $\psi\left(\frac{1}{2}\right)$ and got $-\gamma-\log(2)$ which is also incorrect. So I guess it is the summation and integration switching that is invalid. Can someone explain why is that?
 A: You can not swap the summation and integration anytime.
For example, we know that
$$
\int_{0}^{2\pi} \sin(x+n)\ \mathrm{d}x =0
$$
Consider the infinite sum over it,
$$
\sum_{n=0}^{\infty }\int_{0}^{2\pi} \sin(x+n) \ \mathrm{d}x = 0
$$
But if you switch the order of integration and summation, you'll find
$$
\int_{0}^{2\pi} \left(\sum_{n=0}^{\infty}\sin(x+n)\right)\ \mathrm{d}x= ?
$$
The series $\displaystyle{\sum_{n=0}^{\infty}\sin(x+n)}$ doesn't converge for any value of $x$. The result is meaningless.
So when do summations and integrals switch orders?

In fact, if the summation $\sum_{n}u_{n}(x)$ converges absolutely, and each of these terms is continuous, then
$$
\sum_{n} \int_{a}^{b} u_{n}(x) \ \mathrm{d}x = \int_{a}^{b} \sum_{n}u_{n}(x) \ \mathrm{d}x
$$

Back to your question, You will find that neither series converges:
$$
\sum_{n=0}^{\infty}\frac{1}{n+1}\to \infty,\quad \sum_{n=0}^{\infty}\frac{3}{3n+1}\to \infty
$$
A: To interchange integral and sum, some assumptions are needed.  The standard assumptions are that either the integrands should be non-negative, or the $L^1$ norms of the integrands should be summable. Neither condition is met
in this case.
