5
$\begingroup$

I am trying to get

   s[n_]:=Sum[1/2^k,{k,1,n}]

to show me the actual terms involved in the $n$th partial sum and not just the sum itself. I've tried Expand, Apart, etc. to no avail. Ideas?

Edit based on early comments: Is it necessary to use Table to accomplish this rather than some algebraic command applied to s[n] or some option of Sum?

$\endgroup$
5
  • $\begingroup$ s[n_] := Row[Riffle[Table[1/2^k, {k, 1, n}], "+"]] then? $\endgroup$ Nov 9, 2012 at 16:01
  • 1
    $\begingroup$ Or s[n_Integer?Positive] := Array[1/2^# &, n, 1, Defer[Plus[##]] &] allowing you to copy/paste the result and evaluate it. $\endgroup$
    – Sasha
    Nov 9, 2012 at 16:04
  • 5
    $\begingroup$ @J.M. I am sure you are aware of the shortcut Row[Table[1/2^k, {k, 1, n}], "+"] to your code. $\endgroup$
    – Sasha
    Nov 9, 2012 at 16:05
  • $\begingroup$ @Sasha, not until you brought it up, actually; thanks! $\endgroup$ Nov 9, 2012 at 16:09
  • 3
    $\begingroup$ @J.M. Row[list,s] inserts s as a separator between successive elements. Damn! there is too much functionality to dig up $\endgroup$ Nov 9, 2012 at 18:37

1 Answer 1

7
$\begingroup$

If working in the notebook the following

s[n_Integer?Positive] := Array[1/2^# &, n, 1, Defer[Plus[##]] &]

will produce an expression that can be copied, pasted and would evaluate as if the sum was explicitly typed in.

Alternatively you can build a visual resemblance of the sum using Row:

s[n_Integer?Positive] := Row[Table[1/2^k, {k, 1, n}], "+"]
$\endgroup$
4
  • 1
    $\begingroup$ That first one is so cool! ;-) $\endgroup$
    – JohnD
    Nov 10, 2012 at 19:00
  • 1
    $\begingroup$ @Sasha How would you handle this one: s[n_Integer?Positive] := Row[Table[(-1)^k/2^k, {k, 1, n}], "+"]. That is, how would you get the signs to alternate? $\endgroup$
    – David
    Mar 15, 2017 at 17:02
  • 1
    $\begingroup$ You would need to either use Riffle or Row[ Flatten[ {If[ Negative[#], "-", "+"], #}& /@ Table[ (-1)^k/2^k, {k, n}]]] $\endgroup$
    – Sasha
    Mar 15, 2017 at 17:12
  • $\begingroup$ f[n_Integer?Positive] := Sum[(-1)^k/2^k x^k, {k, 1, n}] /. {Plus :> Inactive[Plus], x -> 1} $\endgroup$
    – Bob Hanlon
    Sep 10, 2017 at 0:00

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.