Opened 7 years ago

Closed 6 years ago

#14209 closed defect (fixed)

Extra assumption kept by Maxima

Reported by: pipedream Owned by: burcin
Priority: major Milestone: sage-6.3
Component: calculus Keywords: maxima ecl
Cc: Merged in:
Authors: Karl-Dieter Crisman Reviewers: Travis Scrimshaw, Peter Bruin
Report Upstream: Fixed upstream, in a later stable release. Work issues:
Branch: 999e21f (Commits) Commit: 999e21f109dd9741693987a91728129955c50056
Dependencies: #13973, #13712, #11984, #15386 Stopgaps:

Description (last modified by kcrisman)

From: https://groups.google.com/forum/?fromgroups=#!topic/sage-devel/jIjYSSCPrrY

Initial symptom:
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)

A closer look:

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)

Change History (25)

comment:1 in reply to: ↑ description Changed 7 years ago by pipedream

  • Description modified (diff)

Replying to pipedream:

From: https://groups.google.com/forum/?fromgroups=#!topic/sage-devel/jIjYSSCPrrY

Initial symptom: 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)

A closer look: 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)

comment:2 Changed 7 years ago by kcrisman

  • Component changed from PLEASE CHANGE to calculus
  • Description modified (diff)
  • Owner changed from tbd to burcin

comment:3 Changed 7 years ago by nbruin

Just a couple of notes:

  • we patch maxima to throw an error rather than print "Principal Value".
  • internally, maxima has a flag that gets set if Principal Value has already been printed, to prevent it from being printed repeatedly.
  • this flag also gets used to suppress the "Principal Value" warning in certain cases where their integration code apparently knows it's safe to take a principal value.
  • so we don't throw an error if maxima wouldn't print the warning.

It would seem something about this setting gets messed up. My guess it's the way maxima deals internally with the doubly infinite integral:

sage: integrate(exp(-abs(x))/cosh(x),x,-oo,0)
log(2)
sage: integrate(exp(-abs(x))/cosh(x),x,0,oo)
log(2)
sage: integrate(exp(-abs(x))/cosh(x),x,-oo,0)
log(2)
sage: integrate(exp(-abs(x))/cosh(x),x,0,oo)
log(2)
sage: integrate(exp(-abs(x))/cosh(x),x,-oo,oo)
2*log(2)
sage: integrate(exp(-abs(x))/cosh(x),x,0,oo)
log(2)
sage: integrate(exp(-abs(x))/cosh(x),x,-oo,0)
ValueError: Integral is divergent.
sage: integrate(exp(-abs(x))/cosh(x),x,0,oo)
log(2)

At this point it can hardly be anything in the way we translate things for maxima. It's got to be in the internals in maxima. They may have changed something internally in maxima that doesn't jive well with our patch (see maxima_lib.py):

ecl_eval('(defun principal nil (cond ($noprincipal (diverg)) ((not pcprntd) (merror "Divergent Integral"))))')

For instance, in sage 4.7.1, which uses maxima 5.23.2, this problem does not arise.

In fact, when you look at the message that is returned, it's:

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

which is the error message that gets generated by diverg. So it seems the second time around, this code is executed with $noprincipal set.

BEWARE: both noprincipal and pcprntd are "special" variables, which means they are dynamically scoped. That's different from what you're probably used to.

Furthermore, the definition of diverg is:

(defun diverg nil
  (cond (*nodiverg (throw 'divergent 'divergent))
	(t (merror (intl:gettext "defint: integral is divergent.")))))

which shows the behaviour can be influenced by yet another special variable, *nodiverg. In defint.lisp this really gets used: they sometimes prefer a condition thrown that they catch rather than generate an merror. If you compare the defint.lisp between 5.26.0 and 5.29.1 (sage 5.0 uses the former and does not have this problem. sage 5.7 uses the latter), you'll find some changes that look like they might change behaviour around such constructs, but I wasn't able to detect a smoking gun. And of course the problem may lie in a different file and/or a bug in how the new ECL handles dynamic variables (which is unlikely and would be disconcerting, because they form a basic component of CL)

Last edited 7 years ago by nbruin (previous) (diff)

comment:4 follow-up: Changed 7 years ago by nbruin

I don't think it has anything to do with principal or with diverg. I think there is an assumption on x that sticks around so that abs(x) gets simplified to x. Of course, integrate(exp(-abs(x))/cosh(x),x,-oo,oo) really is divergent. Evidence:

sage: maxima_calculus.eval("facts()")
'[kind(sinh,one_to_one),kind(log,one_to_one),kind(tanh,one_to_one),kind(log,increasing)]'
sage: integrate(exp(-abs(x))/cosh(x),x,-oo,oo)
2*log(2)
sage: maxima_calculus.eval("facts()")
'[kind(sinh,one_to_one),kind(log,one_to_one),kind(tanh,one_to_one),kind(log,increasing),x>0]'

Indeed, if we subsequently do

sage: maxima_calculus.eval("forget(x>0)")
'[x>0]'
sage: integrate(exp(-abs(x))/cosh(x),x,-oo,oo)
2*log(2)

we see the damage is undone (and redone with the second line of course).

The fact that we have a problem here and maxima itself doesn't seem to have a problem suggests that we are handling contexts differently from what maxima is doing. See maxima's documentation.

maxima's defint.lisp contains plenty of assume commands, but very little seems to have changed in how they're used. I don't know where the change comes from.

comment:5 in reply to: ↑ 4 Changed 7 years ago by kcrisman

sage: maxima_calculus.eval("facts()")
'[kind(sinh,one_to_one),kind(log,one_to_one),kind(tanh,one_to_one),kind(log,increasing)]'
sage: integrate(exp(-abs(x))/cosh(x),x,-oo,oo)
2*log(2)
sage: maxima_calculus.eval("facts()")
'[kind(sinh,one_to_one),kind(log,one_to_one),kind(tanh,one_to_one),kind(log,increasing),x>0]'

Yeah, that sounds like a bug or something. Huh.

comment:6 Changed 7 years ago by nbruin

  • Report Upstream changed from N/A to Reported upstream. No feedback yet.

Cool. It's not our fault. It's an error in abs_integrate.mac, which we load:

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) load(abs_integrate);
defint(exp(-abs(x))/cosh(x),x,minf,inf);
defint(exp(-abs(x))/cosh(x),x,minf,inf);
(%o1) /usr/local/sage/5.7/local/share/maxima/5.29.1/share/contrib/integration/\
abs_integrate.mac
(%i2) (%o2)                              2 log(2)
(%i3) 
defint: integral is divergent.
 -- an error. To debug this try: debugmode(true);

This is now maxima #2557.

comment:7 Changed 7 years ago by kcrisman

There has been a fair amount of activity on this, see the thread starting here on the Maxima list.

comment:8 Changed 7 years ago by kcrisman

  • Report Upstream changed from Reported upstream. No feedback yet. to Reported upstream. Developers acknowledge bug.
  • Summary changed from Interface to maxima / ecl broken to Extra assumption kept by Maxima

comment:9 Changed 7 years ago by robert_dodier

comment:10 Changed 7 years ago by kcrisman

  • Report Upstream changed from Reported upstream. Developers acknowledge bug. to Fixed upstream, in a later stable release.

This will be in the upcoming 5.30. Needs patch to verify at that time.

comment:11 Changed 7 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:12 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:13 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:14 Changed 6 years ago by pbruin

  • Dependencies set to #13973

This is indeed fixed upstream and after #13973 we get

sage: sage: integral(e^(-abs(x))/cosh(x),x,-infinity,infinity)           
2*log(2)
sage: sage: integral(e^(-abs(x))/cosh(x),x,-infinity,infinity)
2*log(2)

comment:15 Changed 6 years ago by kcrisman

  • Authors set to Karl-Dieter Crisman
  • Branch set to u/kcrisman/14209_doc_fix_twoints
  • Commit set to 54d060972983ad223c7b7f572ffad308b8b4dc56
  • Dependencies changed from #13973 to #13973, #13712, #11984, #15386
  • Status changed from new to needs_review

Again, my apologies for all the dependencies, not knowing how to do this so it doesn't depend on previous stuff - I'm still in the hg queue mode.


Last 10 new commits:

741e9a4Trac 13973: fix integration doctest with changed output
0b4b0d0Trac 13973: use "domain: real" for example with integral
13d48c2Trac 13973: fix doctests with changed floating point format/precision
a130eedTrac 13973: realpart should be real_part
3d927bfMerge remote-tracking branch 'trac/u/pbruin/13973-maxima_update' into ticket/13712
c715aabMerge branch 'public/ticket/inf_sum_doctest-13712' of git://trac.sagemath.org/sage into ticket/11894-maxima_sum_zero_division
1dd0f05Trac 11894: add doctest for error detection in Maxima sum
0ede45cMerge branch 'u/pbruin/11894-maxima_sum_zero_division' of trac.sagemath.org:sage into maxima_upgrade
b6657b9Trac #15386 - document that Maxima 5.33 fixes this limit
54d0609Trac #14209 - verify Maxima fix for doing improper integral twice

comment:16 Changed 6 years ago by kcrisman

Just commit 54d0609 matters.

comment:17 Changed 6 years ago by tscrim

  • Reviewers set to Travis Scrimshaw
  • Status changed from needs_review to positive_review

LGTM (as well :p)

comment:18 Changed 6 years ago by pbruin

  • Status changed from positive_review to needs_work

Doctests fail on my system:

sage -t --long src/sage/symbolic/integration/integral.py
**********************************************************************
File "src/sage/symbolic/integration/integral.py", line 684, in sage.symbolic.int
egration.integral.integrate
Failed example:
    integral(e^(-abs(x))/cosh(x),x,-infinity,infinity)
Exception raised:
    Traceback (most recent call last):
    ...
    ValueError: Integral is divergent.
**********************************************************************
File "src/sage/symbolic/integration/integral.py", line 686, in sage.symbolic.int
egration.integral.integrate
Failed example:
    integral(e^(-abs(x))/cosh(x),x,-infinity,infinity)
Exception raised:
    Traceback (most recent call last):
    ...
    ValueError: Integral is divergent.
**********************************************************************

There is no error when running the example directly from the Sage prompt. Maybe a bad assumption made elsewhere in integral.py is creeping in? [Edit: it seems to be caused by "assume(x>0)" a few lines above.]

Last edited 6 years ago by pbruin (previous) (diff)

comment:19 follow-up: Changed 6 years ago by pbruin

Integrating over x in R after assuming x > 0 is problematic in Maxima:

$ sage --maxima
...
(%i1) load(abs_integrate)$

(%i2) defint(exp(-abs(x))/cosh(x),x,minf,inf);
(%o2)                              2 log(2)
(%i3) assume(x>0);
(%o3)                               [x > 0]
(%i4) defint(exp(-abs(x))/cosh(x),x,minf,inf);

defint: integral is divergent.
 -- an error. To debug this try: debugmode(true);

The easiest solution is to put forget(x > 0) at the end of the doctest with assume(x > 0).

comment:20 in reply to: ↑ 19 Changed 6 years ago by kcrisman

The easiest solution is to put forget(x > 0) at the end of the doctest with assume(x > 0).

Sorry, I didn't run tests because it worked in my local Sage, as you say. Certainly if we assumed this above we should forget it - preferably immediately after the assumption - that is the usual practice here.

Anyway, I'll update this momentarily.

comment:21 Changed 6 years ago by git

  • Commit changed from 54d060972983ad223c7b7f572ffad308b8b4dc56 to 999e21f109dd9741693987a91728129955c50056

Branch pushed to git repo; I updated commit sha1. New commits:

999e21fTrac #14209 - Forget assumptions from earlier doctest

comment:22 Changed 6 years ago by kcrisman

  • Reviewers changed from Travis Scrimshaw to Travis Scrimshaw, Peter Bruin
  • Status changed from needs_work to needs_review

comment:23 Changed 6 years ago by pbruin

  • Status changed from needs_review to positive_review

comment:24 Changed 6 years ago by kcrisman

Thanks.

comment:25 Changed 6 years ago by vbraun

  • Branch changed from u/kcrisman/14209_doc_fix_twoints to 999e21f109dd9741693987a91728129955c50056
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.