Expression simplification in sympy -- symbolic integration

305 Views Asked by At

I am trying to integrate $$p_1=\int_0^1\int_z^1\int_y^1\frac{6x^2}{(x+y)(x+y+z)}\,\mathrm{d}x\,\mathrm{d}y\,\mathrm{d}z$$ which arose in connection with an earlier question.

When I plug it into sympy, I get back a hot mess of unevaluated double integrals. Since I think (though I may be wrong) that the integral is elementary, I've been playing around with it. Finally, I tried to compute the innermost integral indefinitely with

simplify(integrate(6*x**2/((x+y)*(x+y+z)), x))

which gives $$\frac{6 \left(x z + y^{2} \log{\left (\frac{x \left(2 y^{2} + 2 y z + z^{2}\right) + 2 y^{3} + 2 y^{2} z + y z^{2}}{2 y^{2} + 2 y z + z^{2}} \right )} - \left(y + z\right)^{2} \log{\left (\frac{x \left(2 y^{2} + 2 y z + z^{2}\right) + 2 y^{3} + 3 y^{2} z + y z^{2} + z \left(y + z\right)^{2}}{2 y^{2} + 2 y z + z^{2}} \right )}\right)}{z}$$

No wonder it can't do the integration! However, the first logarithm simplifies to $\log(x+y)$ and the second to $\log(x+y+z)$. If I ask sympy to simplify these expressions, it has no difficulty.

So, if it were really import to compute this integral exactly, the only way I can see is to write the antiderivative as a function:

def f(x): 
    return 6*(x*z + y**2*log(x+y) - (y + z)**2*log(x+y+z))/z

evaluate $f(1)-f(y)$ in sympy, integrate the result with respect to $y$, and go through the same procedure again.

Is there a better way?


In answer to Eric's comment, at the end I had, among other things, $$\int\frac{-2\log(z+1)+2\log2}z\, \mathrm{d}z$$ for which sympy gave me

2*log(2)*log(z) + 2*polylog(2, z*exp_polar(I*pi))

I take the second term to be a polylogarithm $$2\operatorname{Li}_2(e^{i\pi}z)= 2\operatorname{Li}_2(-z)= 2\sum_{n=1}^\infty\frac{(-z)^n}{n^2}$$ but of course, the first term will blow up at $z=0$. It seemed to me that everything else would be integrable with no difficulty. I must have made a mistake somewhere, but it's hard to find.

I tried it again and it gave me NAN. I made a lot of manual adjustments along the way, and I might have made a mistake, but I don't think so.