Is there any easy, general way to handle algebra on variable Sums? For examples, Gaussian Mixtures or Fourier Series:
gau[x_, m_, var_] := (E^(-(x - m)^2/(2 var)))/Sqrt[2 Pi*var];
f[x_] := Sum[gau[x, m[[i]], v[[i]]], {i, 1, n}];
ga[x_] := Sum[a[[m]]*Sin[m*x], {m, 0, Infinity}] // Inactive;
gb[x_] := Sum[b[[m]]*Sin[m*x], {m, 0, Infinity}] // Inactive;
$$f[x]=\sum _{i=1}^n \frac{e^{-\frac{(x-m[[i]])^2}{2 v[[i]]}}}{\sqrt{2 \pi } \sqrt{v[[i]]}}$$
It's easy on paper to do things like integrate this expression:
$$\int_{-\infty }^{\infty } \left(\sum _{i=1}^n \frac{e^{-\frac{(x-m[[i]])^2}{2 v[[i]]}}}{\sqrt{2\pi } \sqrt{v[[i]]}}\right) \, dx = \sum _{i=1}^n 1 = n$$
...or to integrate f[x]^2 analytically:
$$\int_{-\infty }^{\infty } \left(\sum _{i=1}^n \frac{e^{-\frac{(x-m[[i]])^2}{2 v[[i]]}}}{\sqrt{2\pi } \sqrt{v[[i]]}}\right){}^2 \, dx = \frac{1}{2 \sqrt{\pi }} \sum _{i=1}^n \frac{1}{\sqrt{v[[i]]}}+\sum _{i=2}^n \left(\sum _{j=1}^{i-1} \frac{e^{-\frac{(m[[i]]-m[[j]])^2}{2(v[[i]]+v[[j]])}}}{\sqrt{2 \pi } \sqrt{v[[i]]+v[[j]]}}\right) $$
(Sorry, no code for these results; I did them by hand and wrote them in TeX)
In an Answer below, @chris posted code to get MMa to handle just these two specific instances.
MapAt[Integrate[#, {x, -Infinity, Infinity}] &, f[x], 1] // PowerExpand
tt = f[x]^2 /. Power[Sum[a__, b__], 2] :> sum[a (a /. i -> j) // Release, b, b /. {i -> j}]
MapAt[Integrate[#, {x, -Infinity, Infinity}] &, tt, 1] /.sum -> Sum // PowerExpand
But we would have to write new pattern/substitution code if the index was other than "i" or if we wanted to Integrate any higher powers of f or to do other operations on the Sum.
Other examples that would require new code:
exp1 = Integrate[ga[x]*gb[x],{x,0,2Pi}];
equals (derived by hand because MMa pooped out)
Pi*Sum[a[[m]]*b[[m]], {m, 0, Infinity}]
exp2 = Integrate[ga[x]^3,{x,0,2Pi}];
equals (also derived by hand)
(Pi/2)*Sum[Sum[a[[m]]*a[[n]]*(a[[m + n]] + a[[m - n]]), {n, 1, m - 1}], {m, 2,Infinity}]
Is there any way to handle algebraic Sums so that we don't have to anticipate and code around every conceivable math function we might do on them?
(Sorry for posting TeXForm, but no one understood what I was asking for the first time I tried to post this question.)
MapAt[Integrate[#, {x, -Infinity, Infinity}] &, f[x], 1] // PowerExpand
would work for the first $\endgroup$tt = f[x]^2 /. Power[Sum[a__, b__], 2] :> sum[a (a /. i -> j) // Release, b, b /. {i -> j}]
thenMapAt[Integrate[#, {x, -Infinity, Infinity}] &, tt, 1] /. sum -> Sum // PowerExpand
$\endgroup$