I am interested in the way Mathematica evaluates sums where the upper limit of the index is not an integer - i.e., sums that are some sense mathematically meaningless. For example:

{Sum[Cos[x - i], {i, 0, x}], Sum[Cos[x - i], {i, 0, Floor[x]}]} /. x -> 3.5

 {-0.2892805393, -0.7892805393}

The second number is clear and accurate. But what does that first number actually represent?

What assumptions has Mathematica made in order to be able to evaluate the sum?


1 Answer 1

Sum[foo[i], {i, 1, 3.5}]
foo[1] + foo[2] + foo[3]

How -0.289281 is obtained in the first case in OP: Sum evaluates before ReplaceAll takes effect:

Sum[Cos[x - i], {i, 0, x}]
1/2 (1 + Cos[x] + Cot[1/2] Sin[x])
% /. x -> 3.5

You can see this using Trace:

Trace[Sum[Cos[x - i], {i, 0, x}] /. x -> 3.5] // Column

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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