Re: Series holding the final sum
- To: mathgroup at smc.vnet.net
- Subject: [mg117783] Re: Series holding the final sum
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Thu, 31 Mar 2011 04:02:40 -0500 (EST)
Jon Joseph wrote: > All: Given the following sum: > > Sum[(-1)^(n + 2) x^(2 n + 1)/(2 n + 1), {n, 0, 5}] > > which generates: > > x - x^3/3 + x^5/5 - x^7/7 + x^9/9 - x^11/11 > > I would like to replace x with -1 (%/.x->-1) without the sum being evaluated so I end up with > > -1+1/3-1/5+1/7-1/9+1/11 > > So far I have not been able to find a way to Hold, HoldForm, Unevaluate, or Defer and keep getting -2578/3465. Thanks. Jon= > Here is one method. We replace Plus by plus and define special formatting for the latter. In[17]:= plus /: MakeBoxes[plus[x_], StandardForm] := MakeBoxes[x] plus /: MakeBoxes[plus[x_, y_], StandardForm] := RowBox[{MakeBoxes[x, StandardForm], "+", MakeBoxes[y, StandardForm]}] plus /: MakeBoxes[plus[x_, y_, z__], StandardForm] := RowBox[{MakeBoxes[plus[x, y], StandardForm], "+", MakeBoxes[plus[z]]}] In[20]:= ss = Sum[(-1)^(n + 2) x^(2 n + 1)/(2 n + 1), {n, 0, 5}]; ss2 = ss /. Plus -> plus /. x -> -1 Out[21]= (-1 + 1/3) + ((-(1/5) + 1/7) + (-(1/9) + 1/11)) Daniel Lichtblau Wolfram Research