Ask Your Question

# 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)


leads to

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

## 1 Answer

Sort by » oldest newest most voted

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

## Comments

Ticket #30063, which upgrades to Maxima 5.44.0 and thus fixes this behaviour, was merged in Sage 9.2.beta10. Ticket #30353, which adds a test to Sage so that this problem never comes back, was merged in Sage 9.2.beta11. Any later version of Sage, in particular Sage 9.2 or any later version, is free from this bug. This answer by @tmonteil should be the accepted answer rather than mine.

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2020-08-13 18:13:05 +0200

Seen: 136 times

Last updated: Aug 14 '20