# Write result of integral as Kronecker delta

Here is some Mathematica code:

kroneckerIntegral = Integrate[Sin[m*Pi*x]*Sin[n*Pi*x], {x, 0, 1}, Assumptions -> {n \[Element] Integers, m \[Element] Integers}]
FullSimplify[kroneckerIntegral, {n \[Element] Integers, m \[Element] Integers}]
FullSimplify[Integrate[Sin[m*Pi*x]*Sin[m*Pi*x], {x, 0, 1}], {m \[Element] Integers}]


The resulting Mathematica output of these three lines is:

$$\frac{n \sin (\pi m) \cos (\pi n)-m \cos (\pi m) \sin (\pi n)}{\pi m^2-\pi n^2}$$ $$0$$ $$\frac{1}{2}$$

So essentially kroneckerIntegral can be written in terms of a Kronecker delta as $\frac{\delta_{mn} - \delta_{-nm}}{2}$, which is also a direct result of the well known Fourier orthogonality relations.

Now how do I get Mathematica to simplify the integral to that expression? The reason I want to do this is because I have some long calculation that involves a few of these integrals and it would be convenient to tell Mathematica e.g. in form of a rule that I need this expression in terms of the Kronecker delta.

• Actually, the result isn't what you state. It's $\frac{1}{2}(\delta_{m,n}-\delta_{m,-n})$. – Jens Jun 13 '17 at 18:27
• – Jens Jun 13 '17 at 18:46
• @Jens thanks for the linked question and that correction! I completely forgot about those negative numbers ;) I added your result to the question. – Wolpertinger Jun 14 '17 at 5:56

Edit: updated with Jens' correct term.

Not sure if this is exactly what you are looking for, but it gets you close? Uses Inactivate to do a replace of the integral...

term = Inactivate[ Integrate[Sin[m*Pi*x]*Sin[m*Pi*x], {x, 0, 1}] ]
kroneckerTerm = term/.term->1/2(KroneckerDelta[m,n]-KroneckerDelta[m,-n])

kroneckerTerm/.{n->2,m->3}

(*  0 *)

kroneckerTerm/.{n->2,m->2}

(*  1/2 *)


If you are trying to do a find and replace on some really large expression, you can inactivate the whole thing, do a replace, and Activate it. For example...

bigterm = Inactivate[
Integrate[Sin[m*Pi*x]*Sin[m*Pi*x], {x, 0, 1}] +
Integrate[Sin[m*Pi*x]*Sin[m*Pi*x], {x, 0, 1}]^2 +
Sin[Integrate[Sin[m*Pi*x]*Sin[m*Pi*x], {x, 0, 1}]]
];

(bigterm/. term -> 1/2 (KroneckerDelta[m, n] - KroneckerDelta[m, -n]))//Activate

(*  1/2 (-KroneckerDelta[m, -n] + KroneckerDelta[m, n])
+ 1/4 (-KroneckerDelta[m, -n] + KroneckerDelta[m, n])^2
+ Sin[1/2 (-KroneckerDelta[m, -n] + KroneckerDelta[m, n])]  *)

• +1 awesome stuff, exactly what I needed! – Wolpertinger Jun 14 '17 at 8:24
• Glad to help! Props to @Carl Woll for turning me on to Inactivate – MikeY Jun 14 '17 at 12:23