Summary
Interesting question.
I have just found (18.09.16) a simplification that leads automatically to the KroneckerDelta
representation. See fccs below. I still need to describe the procedure.
Studying a series of examples with increasing number of trig factors we give different useful expressions for the integral: Matrix, SparseArray and KroneckerDelta.
Most of the results are obatined automatically from Mathematica commands.
The approach can be generalized to an arbitrary number of trig factors.
Ingredients are: Limit[]
, auxiliary indices in Table[]
combined with Limit[]
, SparseArray[]
Example of the OP
Let me start with the example of the OP
f0 = Assuming[n ∈ Integers && m ∈ Integers,
Integrate[Cos[n π x] Cos[m π x], {x, 0, 1}]]
0
Putting the assumptions under the integral gives
fcc = Integrate[Cos[n π x] Cos[m π x], {x, 0, 1},
Assumptions -> {{n, m} ∈ Integers}]
$$\text{fcc} = \frac{m \sin (\pi m) \cos (\pi n)-n \cos (\pi m) \sin (\pi n)}{\pi m^2-\pi n^2}$$
Imposing no assumptions at all with the integral gives the same result. Hence at least in version 8 it is not necessary to proceed as proposed by Daniel Lichtblau.
Name convention: The notation cc stands for the product of the two cosines and will be adopted in the more genral cases cs (for Cos * Sin) etc. in the following.
Now we impose the condition of integrity of n and m on the result.
The numerator vanishes at integer values of n and m, but we must be careful as the denominator vanishes also for m^2 == n^2
The case n != ± m
is simple
Simplify[fcc, {{n, m} ∈ Integers, n != m && n != -m}]
(* Out[6]= 0 *)
The case n^2 == m^2
must be treated using the Limit[]
Limit[fcc, m -> n]
(* Out[15]= 1/4 (2 + Sin[2 n π]/(n π)) *)
Limit[fcc, m -> -n]
(* Out[17]= 1/4 (2 + Sin[2 n π]/(n π)) *)
If n == m == 0
we have
Limit[fcc /. m -> 0, n -> 0]
(* Out[21]= 1 *)
The elements of fcc can be calculated uniformly using Limit in combination with an auxiliary index k:
tcc = Table[Limit[fcc, n -> k], {m, -3, 3}, {k, -3, 3}];
% // MatrixForm
$$tcc = \left(
\begin{array}{ccccccc}
\frac{1}{2} & 0 & 0 & 0 & 0 & 0 & \frac{1}{2} \\
0 & \frac{1}{2} & 0 & 0 & 0 & \frac{1}{2} & 0 \\
0 & 0 & \frac{1}{2} & 0 & \frac{1}{2} & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & \frac{1}{2} & 0 & \frac{1}{2} & 0 & 0 \\
0 & \frac{1}{2} & 0 & 0 & 0 & \frac{1}{2} & 0 \\
\frac{1}{2} & 0 & 0 & 0 & 0 & 0 & \frac{1}{2} \\
\end{array}
\right)$$
It is also interesting to define this tensor as a sparse array.
In rule form this reads
acc = ArrayRules[SparseArray[tcc]]
$$\left\{\{1,1\}\to \frac{1}{2},\{1,7\}\to \frac{1}{2},\{2,2\}\to \frac{1}{2},\{2,6\}\to \frac{1}{2},\{3,3\}\to \frac{1}{2},\{3,5\}\to \frac{1}{2},\{4,4\}\to 1,\{5,3\}\to \frac{1}{2},\{5,5\}\to \frac{1}{2},\{6,2\}\to \frac{1}{2},\{6,6\}\to \frac{1}{2},\{7,1\}\to \frac{1}{2},\{7,7\}\to \frac{1}{2},\{\_,\_\}\to 0\right\}$$
Finally, fcc can be written in terms of KroneckerDelta[]
kcc = 1/2 ( KroneckerDelta[n - m] + KroneckerDelta[n + m])
$$kcc = \frac{1}{2} (\delta _{m-n}+\delta _{m+n})$$
tkcc = Table[kcc, {n, -3, 3}, {m, -3, 3}];
% == tcc
(* Out[49]= True *)
The Kronecker representation in this case was easy to guess. Below we shall provide a systematic method to find that representation.
Systematic study
Let us now extend this example to a more systematic study.
Let p = 1, 2, 3, ... be the number of trig factors of the integrand.
The case p = 2 will be completed first.
Sin x Sin
fss = Integrate[Sin[n π x] Sin[m π x], {x, 0, 1}]
$$fss = \frac{n \sin (\pi m) \cos (\pi n)-m \cos (\pi m) \sin (\pi n)}{\pi m^2-\pi n^2}$$
Simplify[fss, {{n, m} ∈ Integers, n != m && n != -m}]
(* Out[3]= 0 *)
Limit[fss, m -> #] & /@ (m /. Solve[n^2 == m^2, m])
Simplify[%, n ∈ Integers]
{1/4 (-2 + Sin[2 n π]/(n π)), 1/2 - Sin[2 n π]/(4 n π)}
{-(1/2), 1/2}
tss = Table[Limit[fss, n -> k], {m, -3, 3}, {k, -3, 3}];
% // MatrixForm
$$\text{tss} = \left(
\begin{array}{ccccccc}
\frac{1}{2} & 0 & 0 & 0 & 0 & 0 & -\frac{1}{2} \\
0 & \frac{1}{2} & 0 & 0 & 0 & -\frac{1}{2} & 0 \\
0 & 0 & \frac{1}{2} & 0 & -\frac{1}{2} & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & -\frac{1}{2} & 0 & \frac{1}{2} & 0 & 0 \\
0 & -\frac{1}{2} & 0 & 0 & 0 & \frac{1}{2} & 0 \\
-\frac{1}{2} & 0 & 0 & 0 & 0 & 0 & \frac{1}{2} \\
\end{array}
\right)$$
ass = ArrayRules[SparseArray[tss]]
$$\text{ass} = \left\{\{1,1\}\to \frac{1}{2},\{1,7\}\to -\frac{1}{2},\{2,2\}\to \frac{1}{2},\{2,6\}\to -\frac{1}{2},\{3,3\}\to \frac{1}{2},\{3,5\}\to -\frac{1}{2},\{5,3\}\to -\frac{1}{2},\{5,5\}\to \frac{1}{2},\{6,2\}\to -\frac{1}{2},\{6,6\}\to \frac{1}{2},\{7,1\}\to -\frac{1}{2},\{7,7\}\to \frac{1}{2},\{\_,\_\}\to 0\right\}$$
kss = 1/2 ( KroneckerDelta[n - m] - KroneckerDelta[n + m]);
$$\text{kss}=\frac{1}{2} (\delta _{n-m}-\delta _{m+n})$$
tdss = Table[kss, {n, -3, 3}, {m, -3, 3}];
tdss == tss
True
Cos x Sin
This case is interesting as it has a less trivial KroneckerDelta representation
fcs = Integrate[Cos[n π x] Sin[m π x], {x, 0, 1}]
$$fcs = \frac{-n \sin (\pi m) \sin (\pi n)+m (-\cos (\pi m)) \cos (\pi n)+m}{\pi m^2-\pi n^2}$$
Simplify[fcs, {{n, m} ∈ Integers, n != m&&n!= - m}]
((1 + (-1)^(1 + m + n)) m)/((m^2 - n^2) π)
Limit[fcs, m -> #] & /@ (m /. Solve[n^2 == m^2, m])
Simplify[%, n ∈ Integers]
{-(Sin[n π]^2/(2 n π)), Sin[n π]^2/(2 n π)}
{0, 0}
tcs = Table[Limit[fcs, n -> k], {m, -3, 3}, {k, -3, 3}];
% // MatrixForm
$$tcs = \left(
\begin{array}{ccccccc}
0 & -\frac{6}{5 \pi } & 0 & -\frac{2}{3 \pi } & 0 & -\frac{6}{5 \pi } & 0 \\
\frac{4}{5 \pi } & 0 & -\frac{4}{3 \pi } & 0 & -\frac{4}{3 \pi } & 0 & \frac{4}{5 \pi } \\
0 & \frac{2}{3 \pi } & 0 & -\frac{2}{\pi } & 0 & \frac{2}{3 \pi } & 0 \\
0 & 0 & 0 & 0 & 0 & 0 & 0 \\
0 & -\frac{2}{3 \pi } & 0 & \frac{2}{\pi } & 0 & -\frac{2}{3 \pi } & 0 \\
-\frac{4}{5 \pi } & 0 & \frac{4}{3 \pi } & 0 & \frac{4}{3 \pi } & 0 & -\frac{4}{5 \pi } \\
0 & \frac{6}{5 \pi } & 0 & \frac{2}{3 \pi } & 0 & \frac{6}{5 \pi } & 0 \\
\end{array}
\right)
$$
acs = ArrayRules[SparseArray[tcs]]
$$\left\{\{1,2\}\to -\frac{6}{5 \pi },\{1,4\}\to -\frac{2}{3 \pi },\{1,6\}\to -\frac{6}{5 \pi },\{2,1\}\to \frac{4}{5 \pi },\{2,3\}\to -\frac{4}{3 \pi },\{2,5\}\to -\frac{4}{3 \pi },\{2,7\}\to \frac{4}{5 \pi },\{3,2\}\to \frac{2}{3 \pi },\{3,4\}\to -\frac{2}{\pi },\{3,6\}\to \frac{2}{3 \pi },\{5,2\}\to -\frac{2}{3 \pi },\{5,4\}\to \frac{2}{\pi },\{5,6\}\to -\frac{2}{3 \pi },\{6,1\}\to -\frac{4}{5 \pi },\{6,3\}\to \frac{4}{3 \pi },\{6,5\}\to \frac{4}{3 \pi },\{6,7\}\to -\frac{4}{5 \pi },\{7,2\}\to \frac{6}{5 \pi },\{7,4\}\to \frac{2}{3 \pi },\{7,6\}\to \frac{6}{5 \pi },\{\_,\_\}\to 0\right\}$$
The Kronecker representation is slightly more complicated as the matrix elements are not constants.
Here's a systematic procedure to calculate the KronekcerDelta repesentation:
Let us assume that
(1) n - m == q
here q is an arbitrary integer. Letting q = -2m + q1 shows that we have covered both cases m==n and m==-n so that (1) can be assumed in general.
Then we write (for thfirst
s1 = Sum[KroneckerDelta[n - m - q] Simplify[Limit[π/2 fcs, m -> n - q],
n ∈ Integers], {q, -3, 3}]
$$= \frac{(1-n) \delta _{m-n+1}}{2 n-1}+\frac{(3-n) \delta _{m-n+3}}{6 n-9}+\frac{(n+1) \delta _{-m+n+1}}{2 n+1}+\frac{(n+3) \delta _{-m+n+3}}{6 n+9}$$
This can be simplified using some minor guesswork to
r1 = Sum[((q - n) KroneckerDelta[q + m - n])/(-q^2 + 2 q n), {q, -3, 3, 2}];
r1 == s1 // Simplify
True
Now observing that only odd numbers q appear we write
((q - n) KroneckerDelta[q + m - n])/(-q^2 + 2 q n) /. q -> 2 i + 1
((1 + 2 i - n) KroneckerDelta[1 + 2 i + m - n])/(-(1 + 2 i)^2 + 2 (1 + 2 i) n)
and arrive at the final expression for the Kronecker representation for fcs
kcs[n_, m_] :=
2/π Sum[(1 + 2 i - n) /((1 + 2 i) (2 n - (1 + 2 i)))
KroneckerDelta[1 + 2 i + m - n], {i, -∞, ∞}]
Latex
$$\text{kcs}(\text{n$\_$},\text{m$\_$})\text{:=}\frac{2 \sum _{i=-\infty }^{\infty } \frac{(2 i-n+1) \delta _{2 i+m-n+1}}{(2 i+1) (2 n-(2 i+1))}}{\pi }$$
Checking it
Table[kcs[n, m], {m, -3, 3}, {n, -3, 3}] == tcs
True
The case p = 3
Cos x Cos x Cos
fccc = Integrate[Cos[n π x] Cos[m π x] Cos[k π x], {x, 0, 1}]
$$\frac{\frac{\sin (\pi (k-m-n))}{k-m-n}+\frac{\sin (\pi (k+m-n))}{k+m-n}+\frac{\sin (\pi (k-m+n))}{k-m+n}+\frac{\sin (\pi (k+m+n))}{k+m+n}}{4 \pi }$$
We connfine ourselves to the KroneckerDelta representation:
kccc = Sum[
Simplify[KroneckerDelta[k - m - n - q] Limit[fccc, k -> n + m + q] +
KroneckerDelta[k + m - n - q] Limit[fccc, k -> n - m + q] +
KroneckerDelta[k - m + n - q] Limit[fccc, k -> -n + m + q] +
KroneckerDelta[k + m + n - q] Limit[fccc, k -> -n - m + q], {k, n,
m} \[Element] Integers], {q, -3, 3}]
$$\text{kccc}=\frac{1}{4} (\delta _{k-m-n}+\delta _{k+m-n}+\delta _{k-m+n}+\delta _{k+m+n})$$
No guesswork was required here.
Cos x Cos x Sin
fccs = Integrate[Cos[n π x] Cos[m π x] Sin[k π x], {x, 0, 1}]
(* Out[6]= (1/(k - m - n) + 1/(k + m - n) + 1/(k - m + n) + 1/(k + m + n) -
Cos[(k - m - n) π]/(k - m - n) - Cos[(k + m - n) π]/(k + m - n) -
Cos[(k - m + n) π]/(k - m + n) - Cos[(k + m + n) π]/(
k + m + n))/(4 π) *)
Kronecker: some first terms
kccs3 = Sum[
Simplify[KroneckerDelta[k - m - n - q] Limit[fccs, k -> n + m + q] +
KroneckerDelta[k + m - n - q] Limit[fccs, k -> n - m + q] +
KroneckerDelta[k - m + n - q] Limit[fccs, k -> -n + m + q] +
KroneckerDelta[k + m + n - q] Limit[fccs, k -> -n - m + q], {k, n,
m} \[Element] Integers], {q, -3, 3}];
(* Output skipped here *)
General result without any guesswork
Notice (18.09.16)
We need to take only the term with KroneckerDelta[k - m - n - q].
The others are covered by q.
kccs[n_, m_, k_] :=
Sum[1/(2 π) ((1/(1 + 2 i) + 1/(1 + 2 i - 2 m) + 1/(
1 + 2 i - 2 n) + 1/(1 + 2 i - 2 m - 2 n)) KroneckerDelta[
1 + 2 i - k - m - n]), {i, -∞, ∞}]
In LaTeX
$$\text{kccs}(\text{n$\_$},\text{m$\_$},\text{k$\_$})\text{:=}\sum _{i=-\infty }^{\infty } \frac{\left(\frac{1}{2 i-2 m-2 n+1}+\frac{1}{2 i-2 m+1}+\frac{1}{2 i-2 n+1}+\frac{1}{2 i+1}\right) \delta _{2 i-k-m-n+1}}{2 \pi }$$
General case
Step 1: calculate the integral f (no assumptions)
Step 2: KroneckerDelta representation
From the exponential representation of the trig functions we find that in theier product all combinations of the sum of all integers corresponsing to the trig factors appear with all possible signs of the summands.
Form the first few (eg. -3..+3) terms of the KroneckerDelta sum using all these sums + an integer parameter q similar to the examples given above.
Step 3: From the result guess the general form of the summands for all q. Look for the parity of the q's and simplify the sum and extend the elementary idex from - infty to + infty.
Integrate[Sin[k \[Pi] x] Cos[n \[Pi] x] Sin[m \[Pi] x], {x, 0, 1}, Assumptions -> Element[{k, m, n}, Reals]]
gives a result that should behave with respect to limits. $\endgroup$ – Daniel Lichtblau Sep 13 '16 at 21:33FourierTransform
will yield generalized functions as needed, butIntegrate
will only output generalized functions if its input contains generalized functions. It's heuristic, not rigorous, and not easy for the user to control. $\endgroup$ – John Doty Sep 14 '16 at 23:20