I am trying to get Mathematica to evaluate integrals such as the well-known Fourier orthogonality relations
$\int_0^L \sin \frac{2 m \pi x}{L} \sin\frac{2 n \pi x}{L}\,\mathrm{d}x=\begin{cases}0& m\ne n\\\frac{L}{2} & m=n\end{cases}$
I expected the following code would return a ConditionalExpression representing the two cases:
Assuming[Element[m, Integers] && Element[n, Integers],
Integrate[Sin[(2 m \[Pi] x)/L] Sin[(2 n \[Pi] x)/L], {x, 0, L}]]
However, the result is zero (i.e. it assumes $m\ne n$). I have to add an additional assumption that m==n to get Mathematica to evaluate the 'interesting' case. Am I missing something? Is there a way to get both results at once, without needing to already know the conditions for each case? (My ultimate application is a more complicated integral where I'm not confident I have identified all the relevant conditions.)
I'm sure finding the answer to this would be straightforward if only I knew what to search for!
If it's relevant, I'm using Mathematica 12.1.
Piecewise[{{FullSimplify[ Integrate[Sin[(2 m \[Pi] x)/L] Sin[(2 n \[Pi] x)/L], {x, 0, L}, Assumptions -> {L > 0, m \[Element] Integers, n \[Element] Integers, m == n}], Assumptions -> {{n, m} \[Element] Integers}], m == n}, {FullSimplify[ Integrate[Sin[(2 m \[Pi] x)/L] Sin[(2 n \[Pi] x)/L], {x, 0, L}, Assumptions -> {L > 0, m \[Element] Integers, n \[Element] Integers, m != n}], Assumptions -> {{n, m} \[Element] Integers}], m != n}}]? – Mariusz Iwaniuk Mar 30 '20 at 15:47Assumingavoids some redundancy:Assuming[{L > 0, Element[m | n, Integers]}, Piecewise[{{Assuming[m == n, Integrate[Sin[(2 m \[Pi] x)/L] Sin[(2 n \[Pi] x)/L], {x, 0, L}] // FullSimplify], m == n}, {Assuming[m != n, Integrate[Sin[(2 m \[Pi] x)/L] Sin[(2 n \[Pi] x)/L], {x, 0, L}] // FullSimplify], m != n}}]]– Bob Hanlon Mar 30 '20 at 16:50