Running integral twice breaks pexpect to maxima?

68 views
Skip to first unread message

Jan Groenewald

unread,
Mar 1, 2013, 2:39:13 AM3/1/13
to sage-...@googlegroups.com
Sage 5.7 on Ubuntu 12.04.2

sage:  integral(e^(-abs(x))/cosh(x),x,-infinity,infinity)                                                                                                                                                   
2*log(2)
sage: integral(e^(-abs(x))/cosh(x),x,-infinity,infinity)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
...
<snip>

...
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/interfaces/maxima_lib.pyc in sr_integral(self, *args)
    737 # in pexpect interface, one looks for this - e.g. integrate(1/x^3,x,-1,3) gives a principal value
    738 #            if "divergent" in s or 'Principal Value' in s:
--> 739                 raise ValueError, "Integral is divergent."
    740             elif "Is" in s: # Maxima asked for a condition
    741                 j = s.find('Is ')

ValueError: Integral is divergent.
sage:


It runs fine in maxima repeatedly...

0 jan@muizenberg:/var/autofs/misc/home/jan$sage --maxima
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/sb-bsd-sockets.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/sockets.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/defsystem.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/cmp.fas"
Maxima 5.29.1 http://maxima.sourceforge.net
using Lisp ECL 12.12.1
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)  integral(e^(-abs(x))/cosh(x),x,-infinity,infinity);   
                              1
(%o1)         integral(---------------, x, - infinity, infinity)
                        abs(x)
                       e       cosh(x)
(%i2)  integral(e^(-abs(x))/cosh(x),x,-infinity,infinity);
                              1
(%o2)         integral(---------------, x, - infinity, infinity)
                        abs(x)
                       e       cosh(x)
(%i3)


Regards,
Jan
--
  .~.
  /V\     Jan Groenewald
 /( )\    www.aims.ac.za
 ^^-^^

Jan Groenewald

unread,
Mar 1, 2013, 4:26:29 AM3/1/13
to sage-...@googlegroups.com
Hi

The maxima part should probably be:

0 jan@muizenberg:/srv/local/Disk_Space/sage-5.7$ maxima # system maxima 5.24

Maxima 5.24.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) defint(exp(-abs(x))/cosh(x),x,minf,inf);
(%o1)                              2 log(2)
(%i2) defint(exp(-abs(x))/cosh(x),x,minf,inf);
(%o2)                              2 log(2)


Or the maxima from sage

(%i2) 0 jan@muizenberg:/srv/local/Disk_Space/sage-5.7$sage --maxima # sage maxima 5.29.1

;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/sb-bsd-sockets.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/sockets.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/defsystem.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/cmp.fas"
Maxima 5.29.1 http://maxima.sourceforge.net
using Lisp ECL 12.12.1
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) defint(exp(-abs(x))/cosh(x),x,minf,inf);
(%o1)                              2 log(2)
(%i2) defint(exp(-abs(x))/cosh(x),x,minf,inf);
(%o2)                              2 log(2)
(%i3)

Both seem to work fine.

Regards,
Jan

Christian Nassau

unread,
Mar 1, 2013, 4:48:05 AM3/1/13
to sage-...@googlegroups.com
Looks like the comment sign in line 738 is the culprit: the code raises an unconditional exception since the "if" has been commented out.  If true you could just remove the "#", see if it works, create a patch and open a ticket for this.

I wonder why it works the first time, though...

Cheers,
Christian
--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To post to this group, send email to sage-...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jan Groenewald

unread,
Mar 1, 2013, 5:14:07 AM3/1/13
to sage-...@googlegroups.com
Hi

If you look a few lines before, the if statement is there; so I don't think it is that.

        try:
            return max_to_sr(maxima_eval(([max_integrate],[sr_to_max(SR(a)) for a in args])))
        except RuntimeError, error:
            s = str(error)
            if "Divergent" in s or "divergent" in s:

# in pexpect interface, one looks for this - e.g. integrate(1/x^3,x,-1,3) gives a principal value
#            if "divergent" in s or 'Principal Value' in s:
                raise ValueError, "Integral is divergent."
            elif "Is" in s: # Maxima asked for a condition
                j = s.find('Is ')
                s = s[j:]
                k = s.find(' ',4)
                raise ValueError, "Computation failed since Maxima requested additional constraints; using the 'assume' command before integral evaluation *may* help (example of legal syntax is 'assume(" + s[4:k] +">0)', see `assume?` for more details)\n" + s
            else:
                raise error


Regards,
Jan


On 1 March 2013 09:39, Jan Groenewald <j...@aims.ac.za> wrote:

Christian Nassau

unread,
Mar 1, 2013, 5:19:46 AM3/1/13
to sage-...@googlegroups.com
On 03/01/2013 11:14 AM, Jan Groenewald wrote:
> Hi
>
> If you look a few lines before, the if statement is there; so I don't
> think it is that.

You're right, of course... I should go back to sleep.

Sorry for the noise,
C.

Jan Groenewald

unread,
Mar 1, 2013, 5:34:31 AM3/1/13
to sage-...@googlegroups.com
Something is weird there though. The way I see it looking for "Principal Value" is commented out.
Sage only looks for [Dd]ivergent.So when maxima gives this:

0 jan@muizenberg:/var/autofs/misc/home/jan$sage --maxima
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/sb-bsd-sockets.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/sockets.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/defsystem.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/cmp.fas"
Maxima 5.29.1 http://maxima.sourceforge.net
using Lisp ECL 12.12.1
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) defint(1/x^3,x,-1,3);
Principal Value
                                       4
(%o1)                                  -
                                       9

Sage should not be finding "Divergent" string and returning divergent (but Sage does).

sage: integrate(1/x^3,x,-1,3)
...
ValueError: Integral is divergent.


Regards,
Jan



--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscribe@googlegroups.com.

To post to this group, send email to sage-...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Christian Nassau

unread,
Mar 1, 2013, 6:06:53 AM3/1/13
to sage-...@googlegroups.com
On 03/01/2013 11:34 AM, Jan Groenewald wrote:
Something is weird there though. The way I see it looking for "Principal Value" is commented out.
Sage only looks for [Dd]ivergent.So when maxima gives this:

0 jan@muizenberg:/var/autofs/misc/home/jan$sage --maxima
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/sb-bsd-sockets.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/sockets.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/defsystem.fas"
;;; Loading #P"/usr/lib/sagemath/local/lib/ecl/cmp.fas"
Maxima 5.29.1 http://maxima.sourceforge.net
using Lisp ECL 12.12.1
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) defint(1/x^3,x,-1,3);
Principal Value
                                       4
(%o1)                                  -
                                       9

Sage should not be finding "Divergent" string and returning divergent (but Sage does).

Well in my test the second call to maxima_eval returns the error

   ECL says: Error executing code in Maxima: defint: integral is divergent.

That explains the Sage error message but is also way out of my area of expertise...

Cheers,
Christian

Jan Groenewald

unread,
Mar 1, 2013, 7:52:12 AM3/1/13
to sage-...@googlegroups.com
This reproduces the error:

sage: from sage.interfaces.maxima_lib import sr_to_max            
sage: sr_to_max(integral(e^(-abs(x))/cosh(x),x,-infinity,infinity))
<ECL: ((MTIMES) ((%LOG) 2) 2)>
sage: sr_to_max(integral(e^(-abs(x))/cosh(x),x,-infinity,infinity))

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.

To post to this group, send email to sage-...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

kcrisman

unread,
Mar 1, 2013, 8:54:50 AM3/1/13
to sage-...@googlegroups.com


On Friday, March 1, 2013 7:52:12 AM UTC-5, Jan Groenewald wrote:
This reproduces the error:

sage: from sage.interfaces.maxima_lib import sr_to_max            
sage: sr_to_max(integral(e^(-abs(x))/cosh(x),x,-infinity,infinity))
<ECL: ((MTIMES) ((%LOG) 2) 2)>
sage: sr_to_max(integral(e^(-abs(x))/cosh(x),x,-infinity,infinity))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)




Jan, can you open a ticket for this?  I may have time to look into it this weekend.  It does seem quite odd; maybe there is something we are not parsing as output.

That said, the relevant Maxima command wouldn't be defint - I believe we just use "integrate(...,x,a,b)", though perhaps internally in Maxima that calls defint, I wouldn't be surprised.  But that could be our problem, too.

- kcrisman 

Jan Groenewald

unread,
Mar 1, 2013, 9:17:24 AM3/1/13
to sage-...@googlegroups.com
Maxima does call defint if you specify limits.

This problem is inside the ECL call (maxima_ecal) in maxima_lib.py. I tried not sending the stdout to dev null, and in the same place setting debugmode=true, but then got dropped in a shell whose syntax I don't know at all.

Changes to get stdout and to turn on debugmode:
1 jan@tunis:/srv/local/Disk_Space/sage-5.7/devel/sage-maximabug/sage/interfaces$diff -ruN maxima_lib_orig.py maxima_lib.py
--- maxima_lib_orig.py    2013-03-01 16:01:14.000000000 +0200
+++ maxima_lib.py    2013-03-01 16:06:58.000000000 +0200
@@ -132,7 +132,8 @@
 ecl_eval(r"""(defparameter *dev-null* (make-two-way-stream
               (make-concatenated-stream) (make-broadcast-stream)))""")
 ecl_eval("(setf original-standard-output *standard-output*)")
-ecl_eval("(setf *standard-output* *dev-null*)")
+ecl_eval("#$debugmode(true)$")
+#ecl_eval("(setf *standard-output* *dev-null*)")
 #ecl_eval("(setf *error-output* *dev-null*)")
 
 ## Default options set in Maxima
1 jan@tunis:/srv/local/Disk_Space/sage-5.7/devel/sage-maximabug/sage/interfaces$mysage -b maximabug


That got me this far:
0 jan@tunis:/srv/local/Disk_Space/sage-5.7/devel/sage-maximabug/sage/interfaces$mysage
----------------------------------------------------------------------
| Sage Version 5.7, Release Date: 2013-02-19                         |
| Type "notebook()" for the browser-based notebook interface.        |
| Type "help()" for help.                                            |
----------------------------------------------------------------------

sage: from sage.interfaces.maxima_lib import sr_to_max            
Loading maxima-grobner $Revision: 1.6 $ $Date: 2009-06-02 07:49:49 $
sage: integral(e^(-abs(x))/cosh(x),x,-infinity,infinity)ax
2*log(2)
sage: integral(e^(-abs(x))/cosh(x),x,-infinity,infinity)
 -- an error.  Entering the Maxima debugger.
Enter ':h' for help.
(dbm:1) :h
Break commands start with ':'. Any unique substring may be used,
eg :r :re :res all work for :resume.

Command      Description
-----------  --------------------------------------
 :break      Set a breakpoint in the specified FUNCTION at the
             specified LINE offset from the beginning of the function.
             If FUNCTION is given as a string, then it is presumed to be
             a FILE and LINE is the offset from the beginning of the file.
 :bt         Print a backtrace of the stack frames
 :continue   Continue the computation.
 :delete     Delete all breakpoints, or if arguments are supplied delete the
             specified breakpoints
 :disable    Disable the specified breakpoints, or all if none are specified
 :enable     Enable the specified breakpoints, or all if none are specified
 :frame      With an argument print the selected stack frame.
             Otherwise the current frame.
 :help       Print help on a break command or with no arguments on
             all break commands
 :info       Print information about item
 :lisp       Evaluate the lisp form following on the line
 :lisp-quiet Evaluate the lisp form without printing a prompt
 :next       Like :step, except that subroutine calls are stepped over
 :quit       Quit this level
 :resume     Continue the computation.
 :step       Step program until it reaches a new source line
 :top        Throw to top level
 :_none      Undocumented


I've yet to dig into this. And here in Cape Town it is late Friday afternoon ;)

Regards,
Jan





--
You received this message because you are subscribed to the Google Groups "sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+...@googlegroups.com.
To post to this group, send email to sage-...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Nils Bruin

unread,
Mar 1, 2013, 3:24:09 PM3/1/13
to sage-devel
On Mar 1, 6:17 am, Jan Groenewald <j...@aims.ac.za> wrote:

> This problem is inside the ECL call (maxima_ecal) in maxima_lib.py. I tried
> not sending the stdout to dev null, and in the same place setting
> debugmode=true, but then got dropped in a shell whose syntax I don't know
> at all.

That's the ECL debugger. The stack trace you find there may well help
you to find where the problem is coming from. With things like

":lisp $noprincipal"

you may be able to investigate lisp variable values in the particular
frames. I've left some comments on the ticket that may be helpful in
tracking down the change that apparently happened somewhere between
maxima 2.26 and 2.29.1
Reply all
Reply to author
Forward
0 new messages