       Re: Question about evaluation with Sum

• To: mathgroup at smc.vnet.net
• Subject: [mg19607] Re: [mg19587] Question about evaluation with Sum
• From: "Tomas Garza" <tgarza at mail.internet.com.mx>
• Date: Sat, 4 Sep 1999 21:09:14 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```CORNIL Jack Michel [jmcornil at club-internet.fr] wrote:I have a big problem of
evaluation with the function Sum.

> I have a big problem of evaluation with the function Sum.
> With the very simple following example,
>
>    p=k
>
>    Sum[p,{k, 1, n}]
>
>      p k
>
>    Sum[Evaluate[p], {k, 1, n}]
>
>      1
>      - n (1+n)
>      2
>
>    Sum[p,{k, 1, 5}]
>
>      15
>
> how can I explain my students that
>
>    in the first case p is left unevaluate and it needs Evaluate,
>
>    in the last case p is evaluate correctly  ?
>
> I do not understand how the "Attributes" of Sum can explain this.

Use Trace[expr] to generate a list of all expressions used in the evaluation
of expr.

In:=
Sum[p, {k, 1, n}] // Trace

will show that p is taken as a constant, so that the sum equals p n. Only
after the sum is evaluated it will be replaced by p = k. Hence k n. However,

In:=
Sum[Evaluate[p], {k, 1, n}] // Trace

will show that p is first replaced by its preassigned value k, and only then
the sum is evaluated.

Tomas Garza
Mexico City

```

• Prev by Date: Re: Help: Outer of a list of lists
• Next by Date: Problem with the zero-term of Fourier[]