Ask Your Question
0

Why does this non-zero integral evaluate to 0?

asked 2023-03-29 09:43:21 +0100

cs89 gravatar image

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 flag offensive close merge delete

Comments

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

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-03-31 23:09:52 +0100

kcrisman gravatar image

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!

edit flag offensive delete link more

Comments

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.

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

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

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-03-29 09:43:21 +0100

Seen: 2,951 times

Last updated: Mar 31 '23