MathGroup Archive 2007

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

Search the Archive

Re: how to make Sum[n,{n,1,5}] to print 1+2+3+4+5? HoldForm?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79384] Re: how to make Sum[n,{n,1,5}] to print 1+2+3+4+5? HoldForm?
  • From: Albert <awnl at arcor.net>
  • Date: Wed, 25 Jul 2007 05:31:23 -0400 (EDT)
  • References: <f86qdq$o7p$1@smc.vnet.net>

Nasser Abbasi wrote:
> hi, I am using version 6
> 
> what is the trick to make Sum[] just print the terms first, before
> adding them? Say I want to do
> 
> r= Sum[n,{n,1,5}]
> 
> But I want to see  1+2+3+4+5, i.e. the terms printed out before they
> are actually added.
> 
> then later I can do Evaluate[r] or N[r] something like this to get it
> to actually do the sum.
> 
> I tried the different Hold commands, but non seems to do it.


the following does what I think you want, but it's somewhat verbose:


In[17]:= r=Sum[With[{n=n},HoldForm[n]],{n,1,5}]
Out[17]= 1+2+3+4+5
In[18]:= ReleaseHold[r]
Out[18]= 15


the trick is to put the n into HoldForm in an evaluated form.

hth,

albert


  • Prev by Date: Cyclic permutations
  • Next by Date: Re: Insanely Large PDFs
  • Previous by thread: Re: how to make Sum[n,{n,1,5}] to print 1+2+3+4+5? HoldForm?
  • Next by thread: Re: how to make Sum[n,{n,1,5}] to print 1+2+3+4+5? HoldForm?