# Mathematica: computing a difficult integral

I am trying to compute the following integral:

Integrate[Exp[Sum[-((cw λ - b[i])^2/(2 σ^2)), {i, 1, n}]], {cw, 0, 1}]


And currently Mathematica outputs

(Sqrt[π/2] σ (Erf[(Sqrt[n] (λ - b[i]))/(Sqrt σ)] +
Erf[(Sqrt[n] b[i])/(Sqrt σ)]))/(Sqrt[n] λ)


Which is not only blatantly incorrect (there can be no dependence on i for example), but also has little connection with my input. If I replace n with an integer in the first expression, the output is the correct result for the integration, but I want the general result with n summands. What am I doing wrong?

Edit: I am willing to make assumptions, such as that λ, σ and all b[i]'s are real. Nonetheless, that does not seem to matter here.

• I'm pretty sure this has been asked before, but I can't find it. Anyone? Sep 29, 2013 at 21:01

In this particular case Mathematica for some reason considers b[i] as a constant. Compare:

Integrate[Exp[Sum[-((cw λ - b)^2/(2 σ^2)), {i, 1, n}]], {cw, 0, 1}]

(Sqrt[π/2] σ (Erf[(b Sqrt[n])/(Sqrt σ)]-Erf[(Sqrt[n] (b-λ))/(Sqrt σ)]))/(Sqrt[n] λ)


A possible workaround consists in the manually expanding the sum

Integrate[Exp[(-n cw^2 λ^2 + 2 cw λ Sum[b[i], {i, 1, n}] -
Sum[b[i]^2, {i, 1, n}])/(2 σ^2)], {cw, 0, 1}] There is another example of the strange behavior of the sum of b[i]

Sum[cw b[i], {i, 1, n}] - cw Sum[b[i], {i, 1, n}] It is not simplified to 0 (even with Simplify and FullSimplify).

• I have expanded the sum already, but this is quite a quirk...
– em70
Sep 29, 2013 at 22:30
• Would you not consider this a bug ? Sep 30, 2013 at 7:12
• @b.gatessucks Yes, it looks like a bug. I usually look for my own mistakes before considering something as a bug. Oct 2, 2013 at 14:39