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[2] σ)] + 
     Erf[(Sqrt[n] b[i])/(Sqrt[2] σ)]))/(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.

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

1 Answer 1


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[2] σ)]-Erf[(Sqrt[n] (b-λ))/(Sqrt[2] σ)]))/(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}]

enter image description here

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}]

enter image description here

It is not simplified to 0 (even with Simplify and FullSimplify).

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.