rtoy / maxima

A Clone of Maxima's repo
Other
0 stars 0 forks source link

wrong answer to a complex expression of real integral #3671

Open rtoy opened 3 months ago

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-08 11:08:28 Created by zmth on 2024-06-25 13:29:18 Original: https://sourceforge.net/p/maxima/bugs/4322


(assume_pos:true, file_output_append:true, ratprint:false, showtime:true,load(simplify_sum)
, simpsum:true,  load("lrats"),letrat:true,ratfac:true,algebraic:true,fpprintprec:4);

the expression -1/(y+1)/2+1/(1-%i)/(y+%i)/2+1/(1+%i)/(y-%i)/2 and y/(y+1)/(y^2+1) are equal:

ratsimp(-1/(y+1)/2+1/(1-%i)/(y+%i)/2+1/(1+%i)/(y-%i)/2-y/(y+1)/(y^2+1));   

gives 0.

[tot:-1/(y+1)/2+1/(1-%i)/(y+%i)/2+1/(1+%i)/(y-%i)/2,
toti:integrate(tot,y,0,tan(%pi/3)),
tt:ev(toti,numer)];

gives toti=-0.156 which is incorrect while ev(integrate(y/(y+1)/(y^2+1),y,0,tan(%pi/3)),numer); gives the correct 0.3676 which i also get by just filling in the limits of the analytic expression at y=tan(%pi/3) and subtracting evaluation at y=0 which is %pi/4 or

[ans1:-log(tan(%pi/3)+1)/2+log(tan(%pi/3)+%i)/(1-%i)/2+log(tan(%pi/3)-%i)/(1+%i)/2+%pi/4,
ans2:ev(realpart(ans1),numer)];

which also gives 0.3676 and also numerical It may be more direct to combine and rid the complex expression and use

[tt:integrate(-1/(y+1)/2+(y+1)/(y^2+1)/2,y),
ti:subst(y=tan(%pi/3),tt),
ev(ti,numer)];

which also gives 0.3676

rtoy commented 3 months ago

Imported from SourceForge on 2024-07-08 11:08:29 Created by rtoy on 2024-06-25 20:52:28 Original: https://sourceforge.net/p/maxima/bugs/4322/#6b40


Traced a few functions. When evaluating the definite integral, antideriv is called on the integrand which returns:

log(abs(y + %i))   log(abs(y - %i))   log(y + 1)
──────────────── + ──────────────── - ──────────
   2 (1 - %i)         2 (%i + 1)          2

But when doing integrate(tot,y), Maxima returns:

log(y + %i)   log(y - %i)   log(y + 1)
─────────── + ─────────── - ──────────
2 (1 - %i)    2 (%i + 1)        2

Note the lack of the abs function inside the log functions. This accounts for the difference. When we substitute the limits in the first result above, and call rectform, we get:

log(2)   log(sqrt(3) + 1)
────── - ────────────────
  2             2

which is approximately -0.15595.

But when substituting the limits for the second result above, and call rectform and expand, we get:

   log(sqrt(3) + 1)   log(2)   %pi
 - ──────────────── + ────── + ───
          2             2       6

which evaluates to 0.36764, which is the expected result.

For some reason, $logabs is set to true in $defint. But in defint, one call to antideriv explicitly sets $logabs to false. This path isn't taken in this particular integral though.

I'm not sure why we do this. integrate(1/x,x) returns just log(x) instead of log(abs(x)).