Menu

#4125 incorrect integral for cosine when coefficient is zero, potentially

None
not-a-bug
nobody
integrate (157)
5
2025-10-20
2023-03-31
kcrisman
No
integrate(cos(2 * %pi * n * t), t, 0, 1);

yields

sin(2*%pi*n)/(2*%pi*n)

which clearly doesn't work if n is zero.

First reported at https://ask.sagemath.org/question/67139/why-does-this-non-zero-integral-evaluate-to-0/ and https://stackoverflow.com/questions/75869399/why-does-this-non-zero-integral-evaluate-to-0-in-sagemath

Discussion

  • kcrisman

    kcrisman - 2023-03-31

    For reference, the antiderivative is what is wrong:

    integrate(cos(2 * %pi * n * t),t);
    sin(2*%pi*n*t)/(2*%pi*n)
    
     
  • kcrisman

    kcrisman - 2023-03-31
     
  • Stavros Macrakis

    This isn't a bug. There is a removable singularity at n=0, and the limit gives the correct result:

    (%i1) integrate(cos(2*%pi*n*t),t,0,1);
                                     sin(2 %pi n)
    (%o1)                            ------------
                                       2 %pi n
    (%i2) limit(%,n,0);
    (%o2)                                  1
    (%i3) integrate(cos(2*%pi*0*t),t,0,1);
    (%o3)                                  1
    
     
  • Stavros Macrakis

    • labels: --> integrate
    • status: open --> not-a-bug
     
  • kcrisman

    kcrisman - 2023-03-31

    Probably debatable (the accumulation function when n=0 clearly doesn't have any singularities (discontinuities?), removable or otherwise), but here is the actual original report:

    declare(n, integer);
    integrate(cos(2 * %pi * n * t), t, 0, 1);
    

    This returns zero, and that certainly is a bug.

     

    Last edit: kcrisman 2023-03-31
    • Stavros Macrakis

      Agreed. Maxima should ask whether n is zero if n is declare integer. I've reopened the bug. Please be sure to include the full context in bug reports -- it's pretty important!

       

      Last edit: Stavros Macrakis 2023-03-31
      • kcrisman

        kcrisman - 2023-03-31

        Great, thanks.

         
      • kcrisman

        kcrisman - 2023-03-31

        Context - agreed! I just noted that Sympy considers the cases n=0 and not zero separately, so I considered the Maxima behavior a bug, and was trying to declutter.

         
  • Devin Greene

    Devin Greene - 2025-10-20

    I'd add that this issue may be having some downstream effects on
    packages.

    For example:

    (%i1) load(fourie)$ 
    
    (%i2) declare(n,integer)$
    
    (%i3) fourier(cos(x),x,%pi);
    (%t3)                               a  = 0
                                         0
    
    (%t4)                               a  = 0
                                         n
    
    (%t5)                               b  = 0
                                         n
    
    (%o5)                           [%t3, %t4, %t5]
    (%i6) 
    

    cos(x) is certainly not zero over the interval [-%pi,%pi] !

     

Log in to post a comment.

MongoDB Logo MongoDB