# Usage of Assuming for Integration

For some reason, when I enter the following integration in Mathematica

Assuming[{k ∈ Integers}, Integrate[ Exp[ I k t], {t, -π, π}]]


the result turns out to be 0. However, clearly, if $k = 0$, the integral should evaluate to $2\pi$ instead. Can someone explain this behavior?

• which version of Mathematica are you using? – chuy Feb 19 '13 at 15:08
• 7.0.1.0 for MacOSx 32bit – TriSSSe Feb 19 '13 at 15:09
• Maybe related to this ? – b.gates.you.know.what Feb 19 '13 at 15:22
• Another recent example here mathematica.stackexchange.com/questions/97154/… – Dimitris Oct 16 '15 at 12:12
• Possibly enlightening, particularly as a supplement to Daniel Lichtblau's answer below: "The Possible Issues section of the documentation for Simplify states: 'The Wolfram Language evaluates zero times a symbolic expression to zero ... Because of this, results of simplification of expressions with singularities are uncertain.' " (From Bill Hanlon's answer to a similar question) – jjc385 Apr 30 '17 at 16:20

I can explain this.

The definite flavor of Integrate works with assumptions in a few ways. One is to use them in Simplify, Refine, and a few other places that accept Assumptions, to do what they will in the hope of attaining a better result (it also uses them to determine convergence and presence or absence of path singularities). Those places also get the $Assumptions default when there are no explicit Assumptions option settings in Integrate, hence one can do Assuming[...,Integrate[...]] with similar effect. But there is a difference. Simplify et al. return "generic results", so e.g. Sin[ k π]/k will simplify to 0 if told that k is an integer. Simplify[ Sin[ k π]/k, Assumptions-> k ∈ Integers] (* Out= 0 *)  Integrate knows Simplify will do this, and wishes it would not (always) be so aggressive. So it takes its Assumptions option and recasts things regarded as Integers into Reals. That's why the related example Integrate[ Exp[ I k t], {t, -π, π}, Assumptions -> {k ∈ Integers}]  manages to provide a correct result. But Integrate does not attempt to mess with $Assumptions that may have been set outside its scope. This is what happens when one instead uses the Assuming[...,Integrate[...]] construction. In that case a trig result like the one I showed will be (over?-)simplified to zero.

Upshot: Integrate subverts the explicit Integrate assumptions of the user in order to avoid this generic simplification pitfall. It's not clear to me at this point which is the bug and which is the feature. Since there are valid arguments for either, and since I think tangling with global $Assumptions inside Integrate is a risky endeavor, I regard this as best left alone. • Thanks for explaining how the assumptions are working! I have one more question though. 0 is clearly an integer and Sin[kPi]/k for k=0 gives "Indeterminate". How can Mathematica then Simplify Sin[kPi]/k for k being integer to 0? I would expect a conditional expression (Indeterminate for k=0, and 0 else), or at least some kind of warning. – TriSSSe Feb 21 '13 at 9:47 • That's what I meant by giving a "generic" result. It holds for all but finitely many cases. – Daniel Lichtblau Feb 21 '13 at 14:29 • Ok after googling "mathematica generic results", it now makes sense. As a beginner, I was not aware of this behavior. Thanks again. – TriSSSe Feb 22 '13 at 8:38 • There's one problem with this difference between Assuming and Assumptions: the result gets cached if Assuming is used first, and the Assumptions version will return the cached result later. – Szabolcs Feb 11 '14 at 14:15 Try :  Integrate[ Exp[ I k t], {t, -π, π}, Assumptions -> {k ∈ Integers}] (* (2 Sin[k π])/k *) Limit[ Integrate[ Exp[ I k t], {t, -π, π}, Assumptions -> {k ∈ Integers}] , k -> 0] (* 2 π *)  • I thought Assuming[...,Integrate[...]] was equivalent to Integrate[..., Assumptions->...] What's the difference? – ssch Feb 19 '13 at 14:39 • @ssch I don't know, but I've noticed the difference several times. It has appeared on the site before I think. – b.gates.you.know.what Feb 19 '13 at 14:48 • Now I am even more confused. So apparently it makes a difference how one specifies assumptions, which should not happen? But then again, I am still convinced that the output to my original line of code is just plain wrong. That is what I cannot get into my head. – TriSSSe Feb 19 '13 at 14:54 • @Christian Agreed, this is just unexpected and confusing Assuming[k \[Element] Integers, {$Assumptions,Integrate[Exp[I*k*t], {t, -Pi, Pi}, Assumptions->\$Assumptions]}] gives {k \[Element] Integers, 0} – ssch Feb 19 '13 at 15:01

For this example, you could use FourierCoefficient instead of Integrate:

FourierCoefficient[1, t, k, FourierParameters->{-1,1}]


2 π DiscreteDelta[k]

Your integral is the well-known inverse Fourier transform of the constant 1, except the 1/(2 Pi) multiplier is missing. In the k domain of Reals, the indefinite integral will yield a complex Sinc function of t and k, but the definite integral will yield a real Sinc function of k, as you can verify by redoing the integration in the domain of the reals. A Sinc function is equivalent to a Dirac delta in the limit as k approaches 0, but ONLY over the Reals.

If you integrate in the domain of integer k, then you are integrating a function that yields a discontinuous indefinite integral because of the singularity at k=0 in the Sinc function, and the definite integral over the integers becomes zero because the singularity has zero width over the domain of integers. Important note: To answer your question, if you explicitly set k=0 before integrating (as your question implies), you are making the implicit assumption that the integration is to be carried over the domain of the reals, even if you tell Mathematica that the assumption is for k over the integers, because k is now fixed as a constant, and defining the domain of integration of k becomes arbitrary. In this case the integral yields the constant 2 Pi, as I explain below.

Anyway, what you were doing is trying to integrate a complex function which has a cosine (real/even/symmetric) part and sine (imaginary/odd/antisymmetric) part over a full cycle from -Pi to Pi, with the condition that k is an integer. As you see, the integral will vanish (be equal to zero) for every value of integer k other than 0, because the positive and negative parts of the integral will cancel out exactly, both for the cosine wave and the sine wave. When k=0, the cosine part equals 1, and the sine part vanishes, so when you carry out the definite integration in the domain of the Reals you get a constant value of 2 Pi, as expected.

(* Explicitly set k=0, but integrate over the Reals *)
k = 0; Assuming[{k \[Element] Reals}, Integrate[Exp[I k t], {t, -Pi, Pi}]]
(* Output: 2 Pi *)

(* Explicitly set k=0, but integrate over the Integers *)
k = 0; Assuming[{k \[Element] Integers}, Integrate[Exp[I k t], {t, -Pi, Pi}]]
(* Output: 2 Pi *)


Below is what the real and imaginary parts look like for different values of integer k:

(* Convert the exponential integrand to trigonometric form for ease of visualizing *)
ExpToTrig[Exp[I k t]] (* Output: Cos[k t] + I Sin[k t] *)
Plot[{Cos[k t], Sin[k t]} /. k -> 1, {t, -\[Pi], \[Pi]}] Animate[Plot[{Cos[k t], Sin[k t]}, {t, -\[Pi], \[Pi]}], {k, 0, 5, 1}] 