Why does this non-zero integral evaluate to 0?

I want to perform formal computations using SageMath, which involve integrals of trigonometric functions. I noticed some inconsistencies and narrowed my issues down to the following basic problem.

Why does the following source code return 0?

var('n t')
assume(n, 'integer')
integrate(cos(2 * pi * n * t), t, 0, 1)


While I agree that the integral is zero when n is non-zero, mathematically, the integral is worth 1 when n is zero. Up to my understanding, I only tell SageMath that n is an integer here, so it should handle the case n = 0 also.

I checked that integrate(cos(2 * pi * 0 * t), t, 0, 1) correctly returns 1, so SageMath seems to be aware of this possibility, but somehow misses the fact that n could be 0.

What am I missing?

edit retag close merge delete

( 2023-03-31 22:54:29 +0100 )edit

Sort by ยป oldest newest most voted

You can reproduce this with the following Maxima code:

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


which will return 0. As one of the Maxima devs points out in his comment at the SO question about the same topic:

Although there are places in the code where Maxima will ask if a variable is zero or nonzero, these are triggered only if a corresponding special case is detected; Maxima doesn't try to analyze results to see if there are cases which aren't covered, such as n = 0 in your example.

In this case, a little further investigation reveals that the antiderivative found is wrong for $n=0$:

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


which obviously doesn't work in that case. In fact, we get this result even if n is not an integer!

I've opened Maxima bug report 4125 for this. Thanks for reporting!

more

Also note Sympy does this correctly, though Sage can't interpret its definite integral (it does do the antiderivative correctly). See https://github.com/sagemath/sage/issu... for more progress and tracking.

( 2023-03-31 23:19:22 +0100 )edit

Update: Maxima devs don't consider a removable discontinuity a bug, but the integer bit remains.

( 2023-03-31 23:58:04 +0100 )edit