# Stack overflow during symbolic manipulations I'm trying to evaluate this cursed integral (finite for $0 < a < 1$):

$$\int_0^1 \frac{x}{\log{\left(ax+(1-x)^2\right)}}{\rm d}x$$

using Sagemath 9.0 and 9.1:

sage: a = var('a')
sage: assume(a>0)
sage: assume(a<1)
sage: f = integrate(x*log(1/(a*x+(1-x)^2)), x, 0, 1)


RuntimeError: ECL says: C-STACK overflow at size 1048576. Stack can probably be resized. Proceed with caution.


Sympy gives a result even without the assumptions (which is odd by itself):

sage: f = integrate(x*log(1/(a*x+(1-x)*(1-x))), x, 0, 1, algorithm='sympy')


$$\frac{1}{4} {\left(a^{2} + \sqrt{{\left(a - 4\right)} a} {\left(a - 2\right)} - 4 a + 2\right)} \log\left(\frac{a^{2} + \sqrt{{\left(a - 4\right)} a} {\left(a - 2\right)} - 4 a + 4}{2 {\left(a - 2\right)}} + 1\right) - \frac{1}{4} {\left(a^{2} + \sqrt{{\left(a - 4\right)} a} {\left(a - 2\right)} - 4 a + 2\right)} \log\left(\frac{a^{2} + \sqrt{{\left(a - 4\right)} a} {\left(a - 2\right)} - 4 a + 4}{2 {\left(a - 2\right)}}\right) + \frac{1}{4} {\left(a^{2} - \sqrt{{\left(a - 4\right)} a} {\left(a - 2\right)} - 4 a + 2\right)} \log\left(\frac{a^{2} - \sqrt{{\left(a - 4\right)} a} {\left(a - 2\right)} - 4 a + 4}{2 {\left(a - 2\right)}} + 1\right) - \frac{1}{4} {\left(a^{2} - \sqrt{{\left(a - 4\right)} a} {\left(a - 2\right)} - 4 a + 2\right)} \log\left(\frac{a^{2} - \sqrt{{\left(a - 4\right)} a} {\left(a - 2\right)} - 4 a + 4}{2 {\left(a - 2\right)}}\right) - \frac{1}{2} a + \frac{1}{2} \log\left(\frac{1}{a}\right) + \frac{3}{2}$$

But then problems continue:

sage: f.simplify_full()

RuntimeError: ECL says: C-STACK overflow at size 1048576. Stack can probably be resized. Proceed with caution.


But:

sage: f.expand().simplify_full()


$$-\frac{1}{2} {\left(2 \pi - {\left(\pi - \arctan\left(\frac{\sqrt{-a + 4}}{\sqrt{a}}\right) + \arctan\left(\frac{\sqrt{a} \sqrt{-a + 4}}{a - 2}\right)\right)} a - 2 \arctan\left(\frac{\sqrt{-a + 4}}{\sqrt{a}}\right) + 2 \arctan\left(\frac{\sqrt{a} \sqrt{-a + 4}}{a - 2}\right)\right)} \sqrt{a} \sqrt{-a + 4} + \frac{1}{4} {\left(a^{2} - 4 a\right)} \log\left(a\right) - \frac{1}{2} a + \frac{3}{2}$$ If I want to find the limit when $a\to 0$:

sage: f.limit(a=0)

RuntimeError: ECL says: C-STACK overflow at size 1048576. Stack can probably be resized. Proceed with caution.


and once again

 sage: f.limit(a=0, algorithm="sympy")


$$-i \pi + \frac{3}{2}$$

Which is only true for $a<0$.

I previously found this strange bug a while ago (fixed upstream, still present in Sagemath 9.1), this makes me think the assumption assume(a>0) is the root of it all, unfortunately it cannot be skipped to evaluate the integral properly.

Do you know when the updated version of Maxima will be included with Sagemath?
Do you think all these issues are linked to this old ticket or should it be investigated independently?

edit retag close merge delete

Sort by » oldest newest most voted

The upgrade to the latest Maxima version is tracked (help welcome) at:

It seems it won't make it into Sage 9.2. So hopefully it will be part of Sage 9.3.

more

1

This ticket is now ready for review, so if it is reviewed quickly, it could enter Sage 9.2 (i updated the milestone).

Thanks for reporting, this is clrealy a bug, it is now trac ticket 30353. The latest Maxima release fixes it, so, when trac ticket 30063 will be merged, you will get:

sage: a = var('a')
sage: assume(a>0)
sage: assume(a<1)
sage: f = integrate(x*log(1/(a*x+(1-x)^2)), x, 0, 1)
sage: f
1/4*a^2*log(a) + 1/2*sqrt(-a^2 + 4*a)*a*arctan(sqrt(-a^2 + 4*a)*(a - 2)/(a^2 - 4*a)) - 1/2*sqrt(-a^2 + 4*a)*a*arctan(sqrt(-a^2 + 4*a)/(a - 4)) - a*log(a) - sqrt(-a^2 + 4*a)*arctan(sqrt(-a^2 + 4*a)*(a - 2)/(a^2 - 4*a)) + sqrt(-a^2 + 4*a)*arctan(sqrt(-a^2 + 4*a)/(a - 4)) - 1/2*a + 3/2
sage: f = integrate(x*log(1/(a*x+(1-x)*(1-x))), x, 0, 1, algorithm='sympy')
sage: f.simplify_full()
1/4*(a^2 - 4*a + 2)*log(1/2*a + 1/2*sqrt(a^2 - 4*a)) - 1/4*(a^2 - 4*a + 2)*log(1/2*a + 1/2*sqrt(a^2 - 4*a) - 1) + 1/4*(a^2 - 4*a + 2)*log(1/2*a - 1/2*sqrt(a^2 - 4*a)) - 1/4*(a^2 - 4*a + 2)*log(1/2*a - 1/2*sqrt(a^2 - 4*a) - 1) + 1/4*sqrt(a^2 - 4*a)*((a - 2)*log(1/2*a + 1/2*sqrt(a^2 - 4*a)) - (a - 2)*log(1/2*a + 1/2*sqrt(a^2 - 4*a) - 1) - (a - 2)*log(1/2*a - 1/2*sqrt(a^2 - 4*a)) + (a - 2)*log(1/2*a - 1/2*sqrt(a^2 - 4*a) - 1)) - 1/2*a - 1/2*log(a) + 3/2
sage: f.limit(a=0)
-I*pi + 3/2

more