First of all, let me excuse myself by saying that I'm a physicist, so I tend to manipulate things a bit thoughtlessly and hope for the best. Still, while manipulating some expressions today I found something that surprised me, and I would like to understand why I get the following weird contradiction, and how can I be aware of when problems like this might arise. So, consider the following integral, which has some poles in the contour but which I will deal with by taking the principal value:
$$ \int_{0}^{\infty}dp\,dq\,dr\,\left[\frac{1}{(e^p-e^q)(e^p-e^r)} + \frac{1}{(e^q-e^p)(e^q-e^r)} + \frac{1}{(e^r-e^p)(e^r-e^q)} \right] ~ . $$
I solved it first by "brute force", meaning I changed variables in the second and third terms to write them as the first one, and then I did the following, solving for $F(p)$ in the principal value sense:
$$ 3 \int_{0}^{\infty} dp \, F(p)^2 ~ , \qquad F(p)\equiv \int_{0}^{\infty} \frac{dq}{(e^q-e^p)} = - e^{-p} \left[ p + \log \left( 1 - e^{-p} \right) \right] ~ . $$
I don't really care about the final value of the integral, it just seems that it is nonzero because we are integrating the square of a nonzero function. The point is that if you are smart enough, you can simplify in the first expression by realizing that:
$$ \frac{1}{(e^p-e^q)(e^p-e^r)} + \frac{1}{(e^q-e^p)(e^q-e^r)} + \frac{1}{(e^r-e^p)(e^r-e^q)} = 0 ~ , $$
and then the integral should be just zero! Clearly, in the previous manipulation I'm doing something which is not allowed, because in the end, when combining the three terms, the original integral has no poles (it is just the integral of zero), and therefore even the idea of doing it in the principal value sense is not needed.
I would like to understand what is wrong in this example, but also the broader picture of when the kind of manipulations I did are allowed. The previous question is just a toy model I cooked up to understand more complicated integrals, in which I start with things that don't have poles but I don't know how to integrate, then I manipulate them to be able to integrate them analytically but introducing spurious poles in the middle, and finally I get some result which, when compared to the original numerical result for the integral, does not match. Thanks in advance!