Bug in integrals

50 views
Skip to first unread message

Juan Luis Varona

unread,
Dec 15, 2021, 2:43:07 PM12/15/21
to sage-support
See this example:

f(x)=(x+sin(3*x))*exp(-3*x*I)
g(x)=f(x).expand()
integral(f(x)-g(x),(x,0,2*pi))

The answer is I*pi, but it should be 0.

Many other examples (related to Fourier coefficients) give similar errors. For instance:

f(x)=(x+cos(x))*exp(-x*I)
g(x)=f(x).expand()
integral(f(x)-g(x),(x,0,2*pi))

The answer is -pi, and it should be 0.

It can be easily with sagemath 9.4 in https://sagecell.sagemath.org

Thanks in advance,

Yours,

Juan Luis Varona



Message has been deleted

Emmanuel Charpentier

unread,
Dec 16, 2021, 1:21:03 PM12/16/21
to sage-support

A nice one, indeed. Here, Sage seems to use Maxima’s integrator :

sage: table([[u,(f(x)-g(x)).integrate(x,algorithm=u)] for u in ["maxima", "sympy", "giac", "fricas", "mathematica_free"]], header_row=["Algorithm", "Indefinite integral"])
  Algorithm          Indefinite integral
+------------------+--------------------------------------------------------------------------------------------------------------------------------------+
  maxima             -1/9*(-3*I*x - 1)*cos(3*x) - 1/9*(3*I*x + 1)*e^(-3*I*x) + 1/9*(3*x - I)*sin(3*x) - 1/12*cos(6*x) + 1/12*e^(-6*I*x) + 1/12*I*sin(6*x)
  sympy              0
  giac               0
  fricas             0
  mathematica_free   0

Note that :

sage: (f(x)-g(x)).integrate(x).simplify()
-1/9*(-3*I*x - 1)*cos(3*x) - 1/9*(3*I*x + 1)*e^(-3*I*x) + 1/9*(3*x - I)*sin(3*x) - 1/12*cos(6*x) + 1/12*e^(-6*I*x) + 1/12*I*sin(6*x)

but :

sage: (f(x)-g(x)).integrate(x).simplify_full()
0

and :

sage: (f(x)-g(x)).expand()
0

There are already some reports of incorrect/surprising Maxima definite and indefinite integral errors, often related to choice of branchs or branch cuts not accounted for. Would you care to check them and file a ticket if yours isn’t already known?

Juan Luis Varona

unread,
Dec 16, 2021, 6:11:43 PM12/16/21
to sage-support
Thanks!

It is clear that it is a bug provided by Maxima.
I have checked already in the developer track the already known Maxima bugs in integrals and I have not found similar errors, so I have opened a ticket.

Juan Luis

slelievre

unread,
Dec 18, 2021, 12:02:39 AM12/18/21
to sage-support
2021-12-17, Juan Luis Varona:

>
> Thanks!
>
> It is clear that it is a bug provided by Maxima.
> I have checked already in the developer trac
> the already known Maxima bugs in integrals
> and I have not found similar errors, so I have
> opened a ticket.
>
> Juan Luis

Thanks for opening a ticket about this at

- Sage Trac ticket 33034:
  Make sure integral(f(x) - f(x).expand(), (x, 0, 2*pi)) is zero
  https://trac.sagemath.org/ticket/33034
 
Hope this can get reported upstream and fixed.

Reply all
Reply to author
Forward
0 new messages