MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: simplifying inside sum, Mathematica 5.1

  • To: mathgroup at
  • Subject: [mg53762] Re: simplifying inside sum, Mathematica 5.1
  • From: Maxim <ab_def at>
  • Date: Wed, 26 Jan 2005 04:37:34 -0500 (EST)
  • Organization: MTU-Intel ISP
  • References: <ct4h70$av2$>
  • Sender: owner-wri-mathgroup at

Mathematica does use some implicit assumptions about the iteration bounds:

Sum[1, {k, 1/2, n}]

1/2 + n

This assumes that the sum is taken over the points k = 1/2, 3/2, ..., n;  
that is, when evaluating Sum[f[k], {k, a, b}] symbolically Mathematica  
assumes that (b-a) is integer. For a value of n such that (n-1/2) is not  
integer (say n=5) Out[1] would be incorrect in the sense that Sum[1, {k,  
1/2, 5}] does not equal 1/2 + 5.

So if we take

Sum[Sin[Pi*k]^2, {k, n}]

(1 + 2*n - 2*I^(2*n)*n*Cos[n*Pi] - Cos[2*n*Pi])/4

the result again doesn't hold for an arbitrary non-integer n (Out[2] can  
be complex), and since n is assumed to be integer, Mathematica indeed  
could have simplified the summand by doing Refine[Sin[Pi*k]^2, Element[k,  
Integers]] to obtain 0 immediately.

What seems to be the real problem is that Mathematica doesn't handle those  
implicit assumptions in a consistent way:

Sum[Cos[Pi*k], {k, 1/2, 2*n}]


Sum[UnitStep[1 - k], {k, 1/2, Infinity}]


Sum[Sqrt[k], {k, 1/2, n + 1/2}]

HarmonicNumber[1/2 + n, -1/2]

It is easy to verify that Out[3] is incorrect for any value of n (again,  
in the sense that if we substitute any numerical value for n before  
evaluating the sum, we will obtain 0, not 1), Out[4] cannot be correct  
because a sum of UnitStep terms cannot be half-integer, and Out[5] may  
happen to be correct for some values of n, but not for integer n.

Next, what if we take a sum from a to b with a>b?

Sum[1, {k, Infinity, 1}]


Sum[1/k^2, {k, Infinity, 1}]


Sum[1/(k^2 + 1), {k, Infinity, -Infinity}]


Out[6] can be justified if we assume

Sum[f[k], {k, a, b}] == -Sum[f[k], {k, b, a}].

Out[7] is fine under the assumption

Sum[f[k], {k, a, b}] == Sum[f[k], {k, b, a}].

Out[8] is valid if we agree that

Sum[f[k], {k, a, b}] == 0 provided that a>b.

Each of these three conventions makes sense and can be useful. However, it  
is impossible to reconcile all three answers with one another (I prefer  
the third case, again because it agrees with numerical summation). We  
should choose one and only one convention and stick to it, otherwise it's  
just as good as returning a random result.

Finally, the general form of the iterator is {k, a, b, d}:

Sum[1/k^2, {k, Infinity, 1, -1}]

<Infinity::indet warning>


Even in these trivial examples we can see that Mathematica simply doesn't  
have a clear definition of how a symbolic sum is understood in such cases,  
and consequently, doesn't have a consistent implementation either.

Maxim Rytin
m.r at

  • Prev by Date: Re: Monte Carlo Simulation Experiences
  • Next by Date: random array of n 2-tuples
  • Previous by thread: Re: Re: simplifying inside sum, Mathematica 5.1
  • Next by thread: Re: Re: simplifying inside sum, Mathematica 5.1