#11590: Integrating the sgn() function can produce incorrect results
------------------------+---------------------------------------------------
Reporter: mjo | Owner: burcin
Type: defect | Status: new
Priority: major | Milestone:
Component: calculus | Keywords:
Work_issues: | Upstream: Reported upstream. Developers
acknowledge bug.
Reviewer: | Author:
Merged: | Dependencies:
------------------------+---------------------------------------------------
Comment(by mjo):
Sorry, I should have been more clear: I did try everything you suggested.
Replacing `$INTEGRATE` with `%INTEGRATE` causes the same test failures in
maxima_lib.py that I got when I swapped out the whole thing for string
substitution. It does fix this ''particular'' answer, though.
Here's a session with just the abs_integrate patch applied, maxima-5.26. I
left the error at the top intact, for whatever reason it doesn't work at
all until after I've integrated something.
{{{
sage: from sage.libs.ecl import *
sage:
I1=EclObject("#$integrate(x*signum(x^2-1/4),x,-1,0);$").cadr().cdr().car()
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
/home/mjo/src/sage-5.0.beta1/devel/sage-devel/<ipython console> in
<module>()
/home/mjo/src/sage-5.0.beta1/local/lib/python2.7/site-
packages/sage/libs/ecl.so in sage.libs.ecl.EclObject.cadr
(sage/libs/ecl.c:5528)()
TypeError: cadr can only be applied to a cons
sage: integrate(x*sgn(x^2-1/4),x,-1,0)
1/2
sage:
I1=EclObject("#$integrate(x*signum(x^2-1/4),x,-1,0);$").cadr().cdr().car()
sage:
I2=EclObject("#$'integrate(x*signum(x^2-1/4),x,-1,0);$").cadr().cdr().car()
sage: I1
<ECL: (($INTEGRATE)
((MTIMES) $X
((%SIGNUM) ((MPLUS) ((MEXPT) $X 2) ((MMINUS) ((MQUOTIENT) 1 4)))))
$X ((MMINUS) 1) 0)>
sage: I2
<ECL: ((%INTEGRATE)
((MTIMES) $X
((%SIGNUM) ((MPLUS) ((MEXPT) $X 2) ((MMINUS) ((MQUOTIENT) 1 4)))))
$X ((MMINUS) 1) 0)>
sage: EclObject(["meval*",["quote", I1]]).eval()
<ECL: ((RAT SIMP) 1 2)>
sage: EclObject(["meval*",["quote", I2]]).eval()
<ECL: ((RAT SIMP) -1 4)>
sage: EclObject(["meval",["quote", I1]]).eval()
<ECL: ((RAT SIMP) 1 2)>
sage: EclObject(["meval",["quote", I2]]).eval()
<ECL: ((RAT SIMP) -1 4)>
}}}
And here's a session with `$INTEGRATE` switched to `%INTEGRATE`:
{{{
sage: from sage.libs.ecl import *
sage:
I1=EclObject("#$integrate(x*signum(x^2-1/4),x,-1,0);$").cadr().cdr().car()
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)
/home/mjo/src/sage-5.0.beta1/devel/sage-devel/<ipython console> in
<module>()
/home/mjo/src/sage-5.0.beta1/local/lib/python2.7/site-
packages/sage/libs/ecl.so in sage.libs.ecl.EclObject.cadr
(sage/libs/ecl.c:5528)()
TypeError: cadr can only be applied to a cons
sage: integrate(x*sgn(x^2-1/4),x,-1,0)
-1/4
sage:
I1=EclObject("#$integrate(x*signum(x^2-1/4),x,-1,0);$").cadr().cdr().car()
sage:
I2=EclObject("#$'integrate(x*signum(x^2-1/4),x,-1,0);$").cadr().cdr().car()
sage: I1
<ECL: (($INTEGRATE)
((MTIMES) $X
((%SIGNUM) ((MPLUS) ((MEXPT) $X 2) ((MMINUS) ((MQUOTIENT) 1 4)))))
$X ((MMINUS) 1) 0)>
sage: I2
<ECL: ((%INTEGRATE)
((MTIMES) $X
((%SIGNUM) ((MPLUS) ((MEXPT) $X 2) ((MMINUS) ((MQUOTIENT) 1 4)))))
$X ((MMINUS) 1) 0)>
sage: EclObject(["meval*",["quote", I1]]).eval()
<ECL: ((RAT SIMP) 1 2)>
sage: EclObject(["meval*",["quote", I2]]).eval()
<ECL: ((RAT SIMP) -1 4)>
sage: EclObject(["meval",["quote", I1]]).eval()
<ECL: ((RAT SIMP) 1 2)>
sage: EclObject(["meval",["quote", I2]]).eval()
<ECL: ((RAT SIMP) -1 4)>
}}}
The same thing, except the original integration actually works. Problem
is, other tests start to fail with `%INTEGRATE`. Here's an example:
{{{
$ sage -t sage/interfaces/maxima_lib.py
sage -t "devel/sage-devel/sage/interfaces/maxima_lib.py"
**********************************************************************
File "/home/mjo/src/sage-5.0.beta1/devel/sage-
devel/sage/interfaces/maxima_lib.py", line 661:
sage: integral(x^n,x)
Expected:
Traceback (most recent call last):
...
ValueError: Computation failed since Maxima requested additional
constraints; using the 'assume' command before integral evaluation
*may* help (example of legal syntax is 'assume(n+1>0)',
see `assume?` for more details)
Is n+1 zero or nonzero?
Got:
x^(n + 1)/(n + 1)
**********************************************************************
File "/home/mjo/src/sage-5.0.beta1/devel/sage-
devel/sage/interfaces/maxima_lib.py", line 685:
sage: integrate(sgn(x) - sgn(1-x), x)
Expected:
abs(x - 1) + abs(x)
Got:
(x - 1)*sgn(x - 1) + x*sgn(x)
**********************************************************************
File "/home/mjo/src/sage-5.0.beta1/devel/sage-
devel/sage/interfaces/maxima_lib.py", line 700:
sage: integrate(cos(x + abs(x)), x)
Expected:
1/4*(sgn(x) + 1)*sin(2*x) - 1/2*x*sgn(x) + 1/2*x
Got:
-1/4*(2*x - sin(2*x))*sgn(x) + 1/2*x + 1/4*sin(2*x)
**********************************************************************
File "/home/mjo/src/sage-5.0.beta1/devel/sage-
devel/sage/interfaces/maxima_lib.py", line 711:
sage: integral(abs(cos(x))*sin(x),(x,pi/2,pi))
Expected:
1/2
Got:
-1/2
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11590#comment:11>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.