Menu

#4522 in definite integrals each log(expr) is erroneously evaluated as log(abs(expr))

None
closed
nobody
None
5
2025-04-14
2025-03-15
Max
No

Please compare the results of

expr: -1/17*sqrt(-52/17*I + 47/17)/(2*x - sqrt(4*I + 1) - 1);
q : integrate(expr, x);
subst(x=1,q) - subst(x=0,q);

and

integrate(expr, x, 0, 1);

They are

(sqrt(47/17-(52*I)/17)*log((-sqrt(4*I+1))-1))/34 -(sqrt(47/17-(52*I)/17)*log(1-sqrt(4*I+1)))/34

-(sqrt(47/17-(52*I)/17)*(log(abs(sqrt(4*I+1)-1))/2 -log(sqrt(4*I+1)+1)/2))/17

Apparently, the first is correct, while the second is not. Please see comparison with how other CAS handle this integral at https://ask.sagemath.org/question/78955/

Discussion

  • Barton Willis

    Barton Willis - 2025-03-17

    Here is a putative fix:

    (defun antideriv (a ivar)
    "Either return an explicit antiderivative (not an integral 
    nounform) of 'a' with respect to 'ivar' or return nil"
      (let ((limitp nil)
            (ans nil)
            ($logabs nil)
            (generate-atan2 nil))
        (setq ans (sinint a ivar))
        (if (among '%integrate ans) nil (simplify ans))))
    

    The only real change is to set the option variable logabs to nil, but I also inserted a docstring and reformatted the code.

    This change causes five testsuite failures--I'm working through these changes now.

     
  • Barton Willis

    Barton Willis - 2025-03-17

    With this proposed fix, one of the five regressions is rtest15, test 210. This test is

    ratsimp(ev(logcontract((integrate(1/(x^8-1),x,0,1/2))),algebraic) + 
    (sqrt(2)*log((2^(3/2)+5)/(2^(3/2)-5)/-1)
          +2*sqrt(2)*atan((sqrt(2)+2)/2)
          +2*sqrt(2)*atan((sqrt(2)-2)/2)+log(9)
          +4*atan(1/2))
     /16);
    0;
    

    The correct numerical value of integrate(1/(x^8-1),x,0,1/2) is about -0.500217463872434252. With my fix, I get

    (%i9) ratsimp(ev(logcontract((integrate(1/(x^8-1),x,0,1/2))),algebraic));
    
    (%o9) -((sqrt(2)*log((2^(3/2)+5)/(2^(3/2)-5))
     +2^(3/2)*atan((sqrt(2)+2)/2)+2^(3/2)*atan((sqrt(2)-2)/2)+log(9)+4*atan(1/2)
     -sqrt(2)*%i*%pi)
     /16)
    (%i10) expand(float(%));
    
    (%o10) -0.5002174638724343
    

    So I might claim success. But sans the call to logcontract, I get

    (%i11) integrate(1/(x^8-1),x,0,1/2);
    
    (%o11) (sqrt(2)*(-log(2^(3/2)+5)+log(2^(3/2)-5)-2*atan((sqrt(2)+2)/2)
                                    -2*atan((sqrt(2)-2)/2)+%i*%pi)
     -2*log(3)-4*atan(1/2)+2*%i*%pi)
     /16
     -(%i*%pi)/8
    (%i12) expand(float(%));
    
    (%o12) 0.5553603672697958*%i-0.5002174638724343
    

    And this is wrong. With Maxima 5.47, with or without the "extra" call to logcontract, the answer is correct.

    Generally, I think it's best when tests have a no or minimal amount of calls to simplification functions on result.

     
  • Barton Willis

    Barton Willis - 2025-03-17

    Another testsuite failure is rtestint test 86. This test is

    ratsimp(integrate(1/(x^2-3),x,0,1) - sqrt(3)*log(2-sqrt(3))/6);
    

    With my proposed fix, the result is

    (%i34) integrate(1/(x^2-3),x,0,1);
    
    (%o34) log(sqrt(3)-2)/(2*sqrt(3))-(%i*%pi)/(2*sqrt(3))
    (%i35) expand(float(%));
    
    (%o35) -0.3801729981504731
    

    So the result is correct, but not manifestly real.

    Another failure is rtest_sqrt test 299. This test is

    integrate(sqrt(t)*(t+1)^(1/2),t,0,1);
     (-log(sqrt(2)+1)+log(1-sqrt(2))+3*2^(3/2))/8-(%i*%pi)/8$
    

    With the proposed fix, the result is

    (%i5) integrate(sqrt(t)*(t+1)^(1/2),t,0,1);
    
    (%o5) -(log(sqrt(2)+1)/8)+log(sqrt(2)-1)/8+3/2^(3/2)
    (%i6) float(%);
    
    (%o6) 0.8403167750249352
    

    This is correct, and better than the result from Maxima 5.47.

     
  • Barton Willis

    Barton Willis - 2025-04-14
    • status: open --> closed
     
  • Barton Willis

    Barton Willis - 2025-04-14

    Fixed by Commit [6f1fe7]. Thanks for this bug report. Closing this ticket.

     

    Related

    Commit: [6f1fe7]


Log in to post a comment.

MongoDB Logo MongoDB