Menu

#4322 wrong answer to a complex expression of real integral

None
pending
nobody
5
2024-06-26
2024-06-25
dan hayes
No
(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

Discussion

  • Barton Willis

    Barton Willis - 2024-06-25

    Here is, I think, the same bug you identified, but presented in a way that's easier for me to read:

    (%i1)   tot:-1/(y+1)/2+1/(1-%i)/(y+%i)/2+1/(1+%i)/(y-%i)/2$
    
    (%i2)   i1 : integrate(ratsimp(tot),y,0, sqrt(3));
    (%o2)   -(log(sqrt(3)+1)/2)+log(4)/4+%pi/6
    
    (%i3)   i2 :  integrate(tot,y,0,sqrt(3));
    (%o3)   -((log(sqrt(3)+1)-log(2))/2)
    
    (%i4)   float(i1-i2);
    (%o4)   0.5235987755982987
    

    Thanks for this bug report.

     
  • Raymond Toy

    Raymond Toy - 2024-06-25

    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)).

     

Log in to post a comment.