Summary: integrate(abs(sin(x)),x) and integrate(abs(cos(x)),x) are computed incorrectly. integrate(abs(sin(x)),x,0,2*%pi) causes crashes, and integrate(abs(cos(x)),x,0,2*%pi) returns nonsense.
In more detail: Maxima 5.28.0 (SBCL/OSX 10.6.8 - downloaded from SF version), Maxima 5.26.0 (ECL 11.1 / Sage), Maxima 5.29.1 (ECL 12.12 and CLISP) all compute integrate(abs(sin(x)),x) and integrate(abs(cos(x)),x) incorrectly.
On Maxima 5.26.0 integrate(abs(sin(x)),x,0,2*%pi) returns the unevaluated integral, on Maxima 5.29.1 it causes segfaults, on Maxima 5.28.0 one gets "Control stack exhausted (no more space for function call frames)."
On Maxima 5.28.0 integrate(abs(cos(x)),x,0,2*%pi) returns 0, after a long wait and many messages "log: encountered log(0)."
See more details on http://trac.sagemath.org/sage_trac/ticket/13364 (this is where we stumbled upon this problem).
Rupert Swarbrick
2012-12-17
Confusingly, on my machine, both the current git version and 2.28.0 give noun forms:
rupert@skate /s/n/maxima> ./maxima-local Maxima 5.28.0_130_g925e3f2_dirty http://maxima.sourceforge.net using Lisp SBCL 1.0.57.0.debian Distributed under the GNU Public License. See the file COPYING. Dedicated to the memory of William Schelter. The function bug_report() provides bug reporting information. (%i1) integrate(abs(sin(x)),x,0,2*%pi); 2 %pi / [ (%o1) I abs(sin(x)) dx ] / 0 (%i2) integrate(abs(cos(x)),x,0,2*%pi); 2 %pi / [ (%o2) I abs(cos(x)) dx ] / 0 (%i3) rupert@skate /s/n/maxima> maxima Maxima 5.28.0 http://maxima.sourceforge.net using Lisp GNU Common Lisp (GCL) GCL 2.6.7 (a.k.a. GCL) Distributed under the GNU Public License. See the file COPYING. Dedicated to the memory of William Schelter. The function bug_report() provides bug reporting information. (%i1) integrate(abs(cos(x)),x,0,2*%pi); 2 %pi / [ (%o1) I abs(cos(x)) dx ] / 0 (%i2) integrate(abs(sin(x)),x,0,2*%pi); 2 %pi / [ (%o2) I abs(sin(x)) dx ] / 0
Dima Pasechnik
2012-12-17
one needs to explicitly
load(abs_integrate);
Rupert Swarbrick
2012-12-17
Some more poking shows that, with abs(sin(x)), everything dies because Maxima is trying to find the limit of some truly hideous expression, returned by
(ANTIDERIV '((MABS SIMP) ((%SIN SIMP) $X)))
namely:
4*((signum(1/(cos(x)+1))*signum(sin(x))*log(abs(sin(x)/(cos(x)+1)+%i)) +signum(1/(cos(x)+1))*signum(sin(x))*log(abs(sin(x)/(cos(x)+1)-%i)) -signum(1/(cos(x)+1))*signum(sin(x))*log(2*sin(x)^2/(cos(x)+1)^2+2) +signum(1/(cos(x)+1))*signum(sin(x)) *(log(2)-2*sin(x)*atan(sin(x)/(cos(x)+1))/(cos(x)+1))) /4 +abs(sin(x))*(atan(sin(x)/(cos(x)+1))/2 +sin(x)/((cos(x)+1)*(2*sin(x)^2/(cos(x)+1)^2+2))) /abs(cos(x)+1))
It looks plausibly correct when you check it between, say, 0.1 and
0.5, but then when you plot it you see that it's not even continuous!
(I think that at every point it is continuous, the function is smooth
and its derivative is probably equal to abs(sin(x)), but that's not
particularly helpful!)
A picture: [-img src=antideriv.png alt=graph of antiderivative: missing =-]
Dima Pasechnik
2012-12-17
It is slightly better with abs(cos(x))
(%i7) integrate(abs(cos(x)),x);
log: encountered log(0).
[..]
(%o7) 2((1/2-sin(x)/((cos(x)+1)(sin(x)^2/(cos(x)+1)^2+1)))
signum(sin(x)/(cos(x)+1)-1)
+1)signum(sin(x)/(cos(x)+1)+1)
Plotting this function shows a jump discontinuity at %pi, and maxima computes the limit at %pi wrongly (it claims both left and right limits to be 0), while the left must be 3, and the right must be -1, according to the plot. So it seems to be a bug in the limit computation.
Rupert Swarbrick
2012-12-17
In the abs(sin(x)) case, I hunted a bit further. Basically, Maxima is failing to compute some slightly unpleasant looking limit, and seemingly hanging somewhere in the gruntz1 routine. I managed to trim the testcase a little and
u: log(abs(%i*cos(x)+%i)/abs(cos(x)+1))$ v: abs(sin(x))*atan(sin(x)/(cos(x)+1))$ limit([u,v], x, 2*%pi); => [0, 0] limit(u+v, x, 2*%pi); => Hangs...
Rupert Swarbrick
2012-12-17
And a bit further... We're dying in a call to $taylor. A related call that blows the stack is
taylor (abs(sin(x))*atan(sin(x)/(cos(x)+1)), x, 0, 0);
Removing abs(sin(x))
stops things going haywire.
Barton Willis
2012-12-17
Using GCL and Clozure CL, I'm unable to reproduce segfaults or crashes. Maybe these errors have something to do with ECL.
In neighborhoods of zero, integrate(abs(sin(x)),x) and integrate(abs(cos(x)),x) are both correct. Unfortunately these antiderivaties are not valid on the reals. Maxima incorrectly assumes that these antiderivaties are valid on larger sets, and thus it incorrectly computes some definite integrals.
Most all of this happens outside of the abs_integrate code. Maxima makes some fairly dubious substitutions, and the abs_integrate code (as far as I can tell) correctly integrates an expression that is mostly rational, but involves some absolute values.
Rupert Swarbrick
2012-12-17
Barton: That's surprising. I only have git master compiled with sbcl, but on ECL with 5.28.0, I get:
rupert@skate ~> maxima Maxima 5.28.0 http://maxima.sourceforge.net using Lisp GNU Common Lisp (GCL) GCL 2.6.7 (a.k.a. GCL) Distributed under the GNU Public License. See the file COPYING. Dedicated to the memory of William Schelter. The function bug_report() provides bug reporting information. (%i1) load("abs_integrate"); (%o1) /usr/share/maxima/5.28.0/share/contrib/integration/abs_integrate.mac (%i2) integrate (abs(sin(x)), x, 0, 2*%pi); Maxima encountered a Lisp error: Error in MACSYMA-TOP-LEVEL [or a callee]: Bind stack overflow. Automatically continuing. To enable the Lisp debugger set *debugger-hook* to nil. (%i3)
which seems to be what the bug reporter described. As far as I can tell, it's to do with Taylor going off the deep end on the expression in my previous note. I plan to trace and debug it further this evening, but I'd be very surprised if the behaviour varied between lisps.
Robert Dodier
2012-12-17
Diff:
--- old +++ new @@ -1,10 +1,8 @@ -Summary: integrate(abs(sin(x)),x) and integrate(abs(cos(x)),x) are computed incorrectly. integrate(abs(sin(x)),x,0,2*%pi) causes crashes, and integrate(abs(cos(x)),x,0,2*%pi) returns nonsense. +Summary: integrate(abs(sin(x)),x) and integrate(abs(cos(x)),x) are computed incorrectly. integrate(abs(sin(x)),x,0,2\*%pi) causes crashes, and integrate(abs(cos(x)),x,0,2\*%pi) returns nonsense. In more detail: Maxima 5.28.0 (SBCL/OSX 10.6.8 - downloaded from SF version), Maxima 5.26.0 (ECL 11.1 / Sage), Maxima 5.29.1 (ECL 12.12 and CLISP) all compute integrate(abs(sin(x)),x) and integrate(abs(cos(x)),x) incorrectly. -On Maxima 5.26.0 integrate(abs(sin(x)),x,0,2*%pi) returns the unevaluated integral, on Maxima 5.29.1 it causes segfaults, on Maxima 5.28.0 one gets "Control stack exhausted (no more space for function call frames)." -On Maxima 5.28.0 integrate(abs(cos(x)),x,0,2*%pi) returns 0, after a long wait and many messages "log: encountered log(0)." +On Maxima 5.26.0 integrate(abs(sin(x)),x,0,2\*%pi) returns the unevaluated integral, on Maxima 5.29.1 it causes segfaults, on Maxima 5.28.0 one gets "Control stack exhausted (no more space for function call frames)." +On Maxima 5.28.0 integrate(abs(cos(x)),x,0,2\*%pi) returns 0, after a long wait and many messages "log: encountered log(0)." See more details on http://trac.sagemath.org/sage_trac/ticket/13364 (this is where we stumbled upon this problem). - -
Robert Dodier
2012-12-17
Fix up formatting: throw in backslashes to make literal asterisks.