7
$\begingroup$

This question already has an answer here:

I'd like to show my students what happens with the telescoping series $\sum_{n=1}^\infty\left[\frac{1}{n}-\frac{1}{n+1}\right]$. For example, I would like to display the partial sum: $$s_5=\left[1-\frac12\right]+\left[\frac12-\frac13\right]+\left[\frac13-\frac14\right]+\left[\frac14-\frac15\right]+\left[\frac15-\frac16\right]$$ I've not used HoldForm before, but I tried:

Table[HoldForm[1/n - 1/(n + 1)], {n, 1, 5}]

But that didn't work. Any suggestions?

$\endgroup$

marked as duplicate by Kuba Feb 22 '17 at 6:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ Far from perfect, but a bit better : show[n_?NumericQ] := Defer[1/n - 1/(n + 1)]; Table[show[n], {n, 5}] outputs {1 1/1 - 1/(1 + 1), 1/2 - 1/(2 + 1), 1/3 - 1/(3 + 1), 1/4 - 1/(4 + 1), 1/5 - 1/(5 + 1)}. $\endgroup$ – anderstood Feb 21 '17 at 16:58
  • 1
    $\begingroup$ Or, better, this show[n_?NumericQ] := Block[{m = n + 1}, Inactivate[1/n - 1/m, Plus]]: $\endgroup$ – anderstood Feb 21 '17 at 18:30
  • $\begingroup$ Do you think it is a valid duplicate: Getting terms and only evaluate specific parts? $\endgroup$ – Kuba Feb 21 '17 at 20:09
  • $\begingroup$ Related: 110532 $\endgroup$ – Edmund Feb 21 '17 at 22:12
  • $\begingroup$ I'd like to thank all my colleagues for tremendous help. There is a lot to learn here and some great examples to share with my students. $\endgroup$ – David Feb 22 '17 at 7:28
9
$\begingroup$

In the following way you can get the printed result you are asking for:

lst=Table[1/n, {n, 1,6}];
Inactive[Plus] @@ MapThread[Defer[Subtract[##]]& ,{Most[lst], Rest[lst]}]

enter image description here

Addendum

Here is another, simpler, solution:

HoldForm[1 - 1/2] + Sum[With[{n = n, m = n + 1}, HoldForm[1/n - 1/m]], {n, 2, 5}]

When we would have started the summation with n=1 instead of n=2, the very first number 1/1 would have turned up as 1*1/1, which is not what we want. Compare this question. An acceptable output is given by:

Sum[With[{n=n, m=n+1}, HoldForm[Divide[1,n]-Divide[1,m]]], {n,1,5}]
$\endgroup$
  • $\begingroup$ @egwene sedai. Many thanks for including the output! $\endgroup$ – Fred Simons Feb 21 '17 at 18:57
  • $\begingroup$ I think you need to make two edits, as in: Sum[With[{n=n,m=n+1},HoldForm[Divide[1,n]-Divide[1,m]]],{n,1,5}] and HoldForm[1 - 1/2] + Sum[With[{n = n,m = n + 1}, HoldForm[1/n - 1/m]], {n, 2, 5}]. Awesome answer. $\endgroup$ – David Mar 15 '17 at 4:45
  • $\begingroup$ @David. You are right that I do not need the three arguments form of With. So I edited my answer accordingly.. $\endgroup$ – Fred Simons Mar 15 '17 at 7:59
4
$\begingroup$

Here's a start, first by inactivating Plus everywhere, then reactivating it in the denominators:

ReplaceAll[
 Block[{Plus = Inactive[Plus]}, Sum[1/i - 1/(i + 1), {i, 1, 5}]],
 -Inactive[Plus][v__]^(-1) :> -Plus[v]^(-1)
]

Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ Simpler is Inactivate[Sum[1/i - 1/(i+1), {i, 5}], Plus] although it isn't equivalent because Sum produces an active Plus. $\endgroup$ – Carl Woll Feb 21 '17 at 17:13
  • $\begingroup$ @CarlWoll It is simpler to write, but the result gets reordered when I use Inactivate. I do not fully understand why, but I wanted to retain the ordering shown in OP. $\endgroup$ – MarcoB Feb 21 '17 at 17:16
2
$\begingroup$
d = Table[If[n == 1, 1, 1/ToString[n]] - 1/ToString[n + 1], {n, 1, 5}];
s = "[" <> ToString[d[[1]], StandardForm] <> "]";

For[ii = 2, ii <= Length[d], ii++,
 s = s <> "+[" <> ToString[d[[ii]], StandardForm] <> "]";
 ]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.