Ticket #780 (assigned defect)

Opened 1 year ago

Last modified 1 month ago

calculus integration failing due to maxima interacting when it shouldn't

Reported by: was Assigned to: gfurnish (accepted)
Priority: major Milestone: sage-3.4
Component: calculus Keywords:
Cc:

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|
> 
> }}}
> 

Change History

10/01/2007 07:12:48 PM changed 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).

12/12/2007 01:26:00 AM changed by mabshoff

  • milestone changed from sage-wishlist to sage-2.9.

02/21/2008 09:54:41 PM changed by AlexGhitza

03/16/2008 01:11:42 PM changed by gfurnish

  • owner changed from was to gfurnish.
  • status changed from new to assigned.

03/16/2008 02:04:35 PM changed 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.

11/27/2008 12:33:40 AM changed 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.