Sage returns negative value for the integral of a positive function x*cos(x^3) on (0,0.5), if I use abs(cos(x^3))*x, then it gets it correct?
> It may be "branch cut strangeness", but if so it is very strange. The
> integrand is clearly well-behaved, and the integral,
> while in terms of the incomplete gamma function, seems to be off the usual
> branch cut (negative real axis).
Try domain:complex before calling integrate; that changes the result to
what I think is expected.
I guess (emphasis on guess) that the problem originates not from
gamma_incomplete itself but from terms of the form (-1)^(1/n) which are
the result of simplifying or evaluating gamma_incomplete. Sorry I can't
be more helpful.
> (%i3) domain:complex;
>
> (%o3) complex
> (%i4) integrate(x*cos(x^3),x,0,1/2);
>
> (%o4)
> gamma_incomplete(2/3,%i/8)/6+gamma_incomplete(2/3,-%i/8)/6-gamma(2/3)/3
Hmm. I get a different result. I am using the current Git version.
domain : complex;
integrate (x*cos(x^3), x, 0, 1/2);
=>
%i*gamma_incomplete(2/3,%i/8)/(4*sqrt(3))
-gamma_incomplete(2/3,%i/8)/12-%i*gamma_incomplete(2/3,-%i/8)/(4*sqrt(3))
-gamma_incomplete(2/3,-%i/8)/12+gamma(2/3)/6
expand (float (%));
=> .1247560409610377
That's gratifying, but the problem, as I'm sure you know, is that the
user won't know they have to change a global variable.
I don't know how to get sage to understand "domain : complex" so I tried with assume and here is what happened. Does it make sense?
Yes, it does. Our assumptions go through Maxima, and apparently assuming a variable is complex does the job.sage: a = integrate(x*cos(x^3),(x,0,0.5)).n()sage: assume(x,'complex')sage: b = integrate(x*cos(x^3),(x,0,0.5)).n()sage: assumptions()[x is complex]