Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HoldForm and Sum

22 views
Skip to first unread message

dimitris

unread,
Oct 1, 2011, 3:08:15 AM10/1/11
to
Hell to all.

A (well-known) nice example of the use of HoldForm is:

Sum[(HoldForm[#1] & )[i], {i, 1, 10}]

(*output omited*)

I want to do the same with 1/i

Sum[(HoldForm[#1] & )[1/i], {i, 1, 10}]

Mathematica output is

1/10+1/9+1/8+...+1/3+1/2+1

My first question is how can I get the output in the form

1+1/2+1/3...+1/8+1/9+1/10


My second query comes now. How can I combine HoldForm and Sum (or
anything else) in order to have the following output (unevaluated)?

1+1/2+1/3-1/4-1/5-1/6+1/7+1/8+1/9-1/10-1/11-1/12

that is, three positive terms after three negative and so on.

Thank you in advance for your response.


Alan

unread,
Oct 2, 2011, 2:36:29 AM10/2/11
to
You can get the terms you want as
Sum[(HoldForm[#1] &)[(-1)^Quotient[i - 1, 3]/i], {i, 1, 12}]

I don't know how to keep them in the order you want.

Alan Isaac

Dr. Wolfgang Hintze

unread,
Oct 2, 2011, 2:36:59 AM10/2/11
to

"dimitris" <dimm...@yahoo.com> schrieb im Newsbeitrag
news:j66e8v$hbs$1...@smc.vnet.net...
These two sums do what you want (except for the "ugly" 1/1)

s1 = Sum[HoldForm[1/#] & [i], {i,1, 10}] (* 1/# rather than [1/i] *)


1 1 1 1 1 1 1 1 1 1
- + - + - + - + - + - + - + - + - + --
1 2 3 4 5 6 7 8 9 10

s2 = Sum[(-1)^Floor[(k-1)/3]HoldForm[1/#]&[k],{k,1,12}]//OutputForm


1 1 1 1 1 1 1 1 1 1 1 1
- + - + - - - - - - - + - + - + - - -- - -- - --
1 2 3 4 5 6 7 8 9 10 11 12

Wolfgang


Alan

unread,
Oct 2, 2011, 2:38:01 AM10/2/11
to
Sum[(HoldForm[#1] &)[(-1)^Quotient[i - 1, 3]/i], {i, 1, 12}]

I don't know how to maintain the order in the output ...

Alan Isaac

PS Is anyone else finding that posting in the web interface is unreliable?

Gabriel Landi

unread,
Oct 2, 2011, 2:38:32 AM10/2/11
to
A cheap alternative to the first question is

Row[Most@Flatten@Table[{1/i, "+"}, {i, 1, 10}]]

which, however, is of different Head.



Tong Shiu-sing

unread,
Oct 3, 2011, 4:20:21 AM10/3/11
to
Hello,

You can change the attributes of Plus to achieve the forms:
Unprotect[Plus]
ClearAttributes[Plus, Orderless]

Sum[(HoldForm[#1] &)[1/i], {i, 1, 10}]
gives
1+1/2+1/3...+1/8+1/9+1/10

Sum[((-1)^Quotient[i - 1, 3] HoldForm[#1] &)[1/i], {i, 1, 12}]
gives
1+1/2+1/3-1/4-1/5-1/6+1/7+1/8+1/9-1/10-1/11-1/12

Hope this is useful.

Regards,
Dominic

0 new messages