Opened 7 years ago

Closed 5 years ago

Last modified 5 years ago

#780 closed defect (fixed)

[with patch, positive review] calculus integration failing due to maxima interacting when it shouldn't

Reported by: was Owned by: AlexGhitza
Priority: major Milestone: sage-4.1.2
Component: calculus Keywords:
Cc: jason Merged in: Sage 4.1.2.alpha4
Authors: Alex Ghitza, Burcin Erocal Reviewers: Karl-Dieter Crisman
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

Hi,

This is a quick and possibly not so useful answer. 
(1) I think you're running into a bug in Maxima (hence Sage) below, since
your assumption should be passed through.  It's pretty hard for us Sage
developers to fix bugs in Maxima, unfortunately.   Nonetheless, we are
very thankful for the bug report.

(2) Possibly doing the following workaround would be OK for you, i.e.,
just compute the definite integral you want by computing an antiderivative
and use the fundamental theorem of calculus:

sage: x,y=var('x,y')
sage: f = log(x^2+y^2)
sage: integrate(f,x)
x*log(y^2 + x^2) - 2*(x - atan(x/y)*y)
sage: g = integrate(f,x)
sage: h = g(x=1.) - g(x=0.0001415); h    # this is what you want.
1.00000000000000*log(y^2 + 1.00000000000000) - 0.0001415000000000000000*log(y^2 + 0.000000020022250000000000000000) - 2*(1.00000000000000 - atan(1.00000000000000/y)*y) + 2*(0.0001415000000000000000 - atan(0.0001415000000000000000/y)*y)
sage: h(y=5)
3.231596665591034

On 10/1/07, Eliz <elyip@comcast.net> wrote:
> 
> Attached is the 'edit' view of my worksheet.  When I changed the lower
> bound of the definite integral from 0.0001415 to  0.0001414, we got
> into trouble.
> 
> Elizabeth
> ------------------------------------------------------------------------------------------------------------
> integration_exercise
> system:sage
> 
> {{{id=0|
> x,y=var('x,y')
> f=log(x^2+y^2)
> integrate(f,x)
> ///
> x*log(y^2 + x^2) - 2*(x - atan(x/y)*y)
> }}}
> 
> {{{id=11|
> assume(y^2>1)
> integrate(f,x,0.0001415,1.)
> ///
> 1.00000000000000*log(1.00000000000000*y^2 + 1.00000000000000) -
> 0.0001415000000000000000*log(1.00000000000000*y^2 +
> 0.000000020022250000000000000000) +
> 2.00000000000000*atan(1.00000000000000/y)*y -
> 2.00000000000000*atan(0.0001415000000000000000/y)*y - 1.99971700000000
> }}}
> 
> {{{id=16|
> assume(y^2<1)
> integrate(f,x,0.0001415,1.)
> ///
> 1.00000000000000*log(1.00000000000000*y^2 + 1.00000000000000) -
> 0.0001415000000000000000*log(1.00000000000000*y^2 +
> 0.000000020022250000000000000000) +
> 2.00000000000000*atan(1.00000000000000/y)*y -
> 2.00000000000000*atan(0.0001415000000000000000/y)*y - 1.99971700000000
> }}}
> 
> {{{id=17|
> assume(y^2==1)
> integrate(f,x,0.0001415,1.)
> ///
> 1.00000000000000*log(1.00000000000000*y^2 + 1.00000000000000) -
> 0.0001415000000000000000*log(1.00000000000000*y^2 +
> 0.000000020022250000000000000000) +
> 2.00000000000000*atan(1.00000000000000/y)*y -
> 2.00000000000000*atan(0.0001415000000000000000/y)*y - 1.99971700000000
> }}}
> 
> {{{id=19|
> assume(y^2>1)
> integrate(f,x,0.0001414,1.)
> ///
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/home/yip/sage_notebook/worksheets/admin/10/code/47.py", line
> 5, in <module>
>     exec
> compile(ur'integrate(f,x,RealNumber(\u00270.0001414\u0027),RealNumber(\u00271.\u0027))'
> + '\n', '', 'single')
>   File "/local/sage-2.8.5.1/data/extcode/sage/", line 1, in <module>
> 
>   File "/local/sage-2.8.5.1/local/lib/python2.5/site-packages/sage/
> calculus/functional.py", line 175, in integral
>     return f.integral(*args, **kwds)
>   File "/local/sage-2.8.5.1/local/lib/python2.5/site-packages/sage/
> calculus/calculus.py", line 1652, in integral
>     return self.parent()(self._maxima_().integrate(v, a, b))
>   File "/local/sage-2.8.5.1/local/lib/python2.5/site-packages/sage/
> interfaces/maxima.py", line 1391, in integral
>     return I(var, min, max)
>   File "/local/sage-2.8.5.1/local/lib/python2.5/site-packages/sage/
> interfaces/expect.py", line 884, in __call__
>     return self._obj.parent().function_call(self._name, [self._obj] +
> list(args))
>   File "/local/sage-2.8.5.1/local/lib/python2.5/site-packages/sage/
> interfaces/expect.py", line 831, in function_call
>     return self.new("%s(%s)"%(function, ",".join([s.name() for s in
> args])))
>   File "/local/sage-2.8.5.1/local/lib/python2.5/site-packages/sage/
> interfaces/expect.py", line 733, in new
>     return self(code)
>   File "/local/sage-2.8.5.1/local/lib/python2.5/site-packages/sage/
> interfaces/maxima.py", line 376, in __call__
>     return Expect.__call__(self, x)
>   File "/local/sage-2.8.5.1/local/lib/python2.5/site-packages/sage/
> interfaces/expect.py", line 678, in __call__
>     return cls(self, x)
>   File "/local/sage-2.8.5.1/local/lib/python2.5/site-packages/sage/
> interfaces/expect.py", line 919, in __init__
>     raise TypeError, x
> TypeError: Computation failed since Maxima requested additional
> constraints (use assume):
> Is  (y-1)*(y+1)  positive, negative, or zero?
> }}}
> 
> {{{id=20|
> 
> }}}
> 

Attachments (1)

trac_780-maxima_integral.patch (1.2 KB) - added by burcin 5 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 7 years ago by was

The solution might be to make the pexpect interface interaction with maxima even more sophisticated or -- even better -- replicate the whole bug directly in maxima and report it to the maxima list (I'm too lazy to do so right now).

comment:2 Changed 7 years ago by mabshoff

  • Milestone changed from sage-wishlist to sage-2.9

comment:3 Changed 6 years ago by AlexGhitza

comment:4 Changed 6 years ago by gfurnish

  • Owner changed from was to gfurnish
  • Status changed from new to assigned

comment:5 Changed 6 years ago by was

Somebody on the maxima list responded:

Date: 2008-02-22 06:16
Sender: rtoy
Logged In: YES 
user_id=28849
Originator: NO

Note that is((y-1)*(y+1)>0) returns unknown.  If you say assume(y>1),
integrate doesn't ask about that anymore. But it still asks about
y^2+x^2+2*x+1.  It should know that x > 0 and y > 0 here.

comment:6 Changed 6 years ago by tjlahey

I've noticed this many times when running my integration tests. Axiom handles these kinds of integrals by returning multiple solutions. Maxima could do the same and that's what I think is the best solution.

One possible solution on the Sage side would be to add optional parameters to answer the questions. So, the first time one tries the integral, you get the trackback so you re-run the integration with an added parameter to answer the question (or series of questions for problems with several branches).

Since the questions are yes/no based, another option arises, that is more difficult to implement but better for the user. This would be to have an option for Sage to build up the branches by re-running the integration answering the questions automatically and noting the solution and the question+answer.

Both of these Sage solutions require improvements to the pexpect interface which are likely non-trivial.

comment:7 Changed 6 years ago by jason

  • Cc jason added

comment:8 Changed 5 years ago by kcrisman

It should be pointed out that:

  1. Changing the left endpoint from 0.0001415 to 0.0001414 caused the error in this case. Mysteriously, doing the endpoint 0.0001415 in maxima_console() still has two questions for you, but Sage nonetheless answers it!
  1. assume((y-1)*(y+1)>0) or whatever doesn't work - and even if it did, Maxima does have an actual bug in not recognizing that x is positive from the integral we wanted to calculate. So a question-and-answer framework, while definitely helpful, wouldn't solve this particular issue.

comment:9 Changed 5 years ago by AlexGhitza

Note that the Maxima bug seems to have been fixed, see

https://sourceforge.net/tracker/?func=detail&atid=104933&aid=1899352&group_id=4933

comment:10 Changed 5 years ago by AlexGhitza

  • Owner changed from gfurnish to AlexGhitza
  • Status changed from assigned to new

This is fixed by the spkg and patch at #6699. I will put up a patch with a doctest verifying this when #6699 gets merged.

Changed 5 years ago by burcin

comment:11 Changed 5 years ago by burcin

  • Authors set to Alex Ghitza, Burcin Erocal
  • Summary changed from calculus integration failing due to maxima interacting when it shouldn't to [with patch, needs review] calculus integration failing due to maxima interacting when it shouldn't

attachment:trac_780-maxima_integral.patch adds doctests to show that this is fixed.

Alex, many thanks for your work on updating maxima. I'm trying to get as many symbolics/calculus tickets closed as possible for this release now.

comment:12 Changed 5 years ago by kcrisman

  • Reviewers set to Karl-Dieter Crisman
  • Summary changed from [with patch, needs review] calculus integration failing due to maxima interacting when it shouldn't to [with patch, positive review] calculus integration failing due to maxima interacting when it shouldn't

All tests passed!

Yes, also thanks! Incidentally, I would be happy to help with updating Maxima as needed, now that I've read the spkg documentation in the developer's guide, because there are always new improvements.

comment:13 Changed 5 years ago by mvngu

  • Merged in set to Sage 4.1.2.alpha3
  • Resolution set to fixed
  • Status changed from new to closed

comment:14 Changed 5 years ago by mvngu

  • Merged in changed from Sage 4.1.2.alpha3 to Sage 4.1.2.alpha4

There is no 4.1.2.alpha3. Sage 4.1.2.alpha3 was William Stein's release for working on making the notebook a standalone package.

Note: See TracTickets for help on using tickets.