Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#2520 abs_integrate fails on abs(sin(x)) and abs(cos(x))

None
open
nobody
5
2014-12-15
2012-12-17
Dima Pasechnik
No

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

Related

Bugs: #2520

Discussion

<< < 1 2 (Page 2 of 2)
  • Barton Willis
    Barton Willis
    2012-12-17

    $ ./maxima-local
    Maxima 5.28post http://maxima.sourceforge.net
    using Lisp Clozure Common Lisp Version 1.8-r15286M (WindowsX8664)
    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) c:/maxima-clean/share/contrib/integration/abs_integrate.mac
    (%i2) integrate (abs(sin(x)), x, 0, 2*%pi);

    --> hostile abort. maybe I didn't try this case with Clozure. With GCL, the result is a noun form.

    --Barton


    From: Rupert Swarbrick [rswarbrick@users.sf.net]
    Sent: Monday, December 17, 2012 15:16
    To: [maxima:bugs]
    Subject: [maxima:bugs] #2520 abs_integrate fails on abs(sin(x)) and abs(cos(x))

    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.


    [bugs:#2520]http://sourceforge.net/p/maxima/bugs/2520/ abs_integrate fails on abs(sin(x)) and abs(cos(x))

    Status: open
    Labels: abs_integrate
    Created: Mon Dec 17, 2012 10:22 AM UTC by Dima Pasechnik
    Last Updated: Mon Dec 17, 2012 08:50 PM UTC
    Owner: nobody

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


    Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/maxima/bugs/2520/

    To unsubscribe from further messages, please visit https://sourceforge.net/auth/prefs/

     

    Related

    Bugs: #2520

  • Assuming that the Taylor example I found is the root of this error, I carried on hunting. A simpler example again that causes the same error is

    taylor (cos(x)*sin(x)/abs(sin(x)), x, 0, 0);
    

    If you trace taylor2 beforehand, you'll see an infinite recursion. What causes it is that you get calls of the form

            5: (TAYLOR2
                ((MTIMES) ((RAT SIMP) 1 1)
                 ((MTIMES SIMP) ((%COS SIMP) $X) ((%SIN SIMP) $X)
                  ((MEXPT SIMP) ((MABS SIMP) ((%SIN SIMP) $X)) -1))
                 ((MEXPT) $X 1)))
    

    to evaluate this, you end up calling

                      10: (TAYLOR2 ((MABS SIMP) ((%SIN SIMP) $X)))
    

    and, unfortunately, this falls through to the bottom of the cond in taylor2, which looks like

    (t (let ((exact-poly () ))  ; Taylor series aren't exact
          (taylor2 (diff-expand e tlist))))
    

    DIFF-EXPAND, when called on this abs form, returns

                             ((MPLUS)
                              ((MTIMES) ((RAT SIMP) 1 1)
                               ((MTIMES SIMP) ((%COS SIMP) $X) ((%SIN SIMP) $X)
                                ((MEXPT SIMP) ((MABS SIMP) ((%SIN SIMP) $X))
                                 -1))
                               ((MEXPT) $X 1))
                              0)
    

    and we recurse. Bleugh.

     
  • Continuing the detective work, write f(x) for abs(sin(x)). The unhelpful result from DIFF-EXPAND is because it is trying to evaluate "f(0) + f'(0) + ..." (up to order one in this case) and calls EVAL-DERIV to actually evaluate the derivative it gets. This is of the form

    at(cos(x)*sin(x)/abs(sin(x)),x = 0)
    

    and EVAL-DERIV returns cos(x)*sin(x)/abs(sin(x)) rather than throwing an error because of the division by zero. As such, the result from DIFF-EXPAND actually has f'(x) rather than f'(0).

     
  • The attached patch fixes the stack overflow bug. The test for %derivative seems a bit hacky, but I'm not sure how to do better. Ideas, anyone?

    The only unexpected failure in the resulting testsuite run is a numerical error in rtest_gamma, but I'm pretty certain that's not my fault :-)

    With this patch, the sin integral returns a noun form. Not ideal, but better than crashing Maxima! The cos integral still returns the wrong answer, but that was tickling a different bug.

    Comments? (Which I'll read tomorrow. It's midnight and I've still got to cycle home!)

     
    • Dima Pasechnik
      Dima Pasechnik
      2012-12-18

      deleted a meaningless comment.

       
      Last edit: Dima Pasechnik 2012-12-18
  • Robert Dodier
    Robert Dodier
    2012-12-18

    Rupert, thanks for working on this problem. Looks like your analysis is right on the mark. Please keep up the good work.

    There has to be a way to express the fact that there is no Taylor expansion for some functions (e.g. absolute value). The most useful behavior for EVAL-DERIV is to throw something to indicate the derivative doesn't exist at the specified point. Returning a noun expression suggests that the derivative exists but EVAL-DERIV wasn't able to calculate it.

    Likewise the Maxima function 'taylor' would be more useful if it could indicate that the Taylor expansion doesn't exist. As it stands, there is no documented way for 'taylor' to express that. Maybe that is the first thing to work on: what should be the behavior of 'taylor' when there is no such Taylor expansion?

     
    • I'm not sure what you mean here. At the moment, $taylor throws an error (see tay-err), which is caught by $limit (yielding a noun form for the limit). Since there's not really a way to throw and catch errors in the maxima language, what else could happen?

       
<< < 1 2 (Page 2 of 2)