2
$\begingroup$

If you run the following code, the fifth harmonic number is not evaluated as a sum.

Table[HarmonicNumber[i,-1/2],{i,0,5}]

How can I get Mathematica to output Harmonic numbers as a sum. I tried normal and normal form, but they didn't work. Also, I want it to be able to work for

HarmonicNumber[k,-1/2]

To be expresed with a sumation sign.

$\endgroup$
7
$\begingroup$
FunctionExpand[HarmonicNumber[5,-1/2]]
(*3+Sqrt[2]+Sqrt[3]+Sqrt[5]*)

Assuming[Element[k,integers],
  FunctionExpand[HarmonicNumber[k,1/2]]]
(*-HurwitzZeta[1/2, 1 + k] + Zeta[1/2]*)
$\endgroup$
  • $\begingroup$ How do I get the second part to express as a sum instead of (*-HurwitzZeta[1/2, 1 + k] + Zeta[1/2]*) ? $\endgroup$ – Ion Sme May 22 at 17:49
  • $\begingroup$ I certainly may be wrong, but I do not believe there is any specific concrete sum of numerical constants which sum up to the unknown abstract value HarmonicNumber[k,1/2]. Consider a simpler similar problem. I ask you to tell me a specific concrete list of numerical constants that sum up to n, but you cannot use "..." or "just do it n times" or "you know what I mean", what is the list of constants that sum to n when I do not tell you what n is. I suspect the answer is that no one can provide such a sum. $\endgroup$ – Bill May 22 at 22:32
  • $\begingroup$ I was imagining a summation like the one in @BobHanlon's answer, but by applying something like FunctionExpand, rather than making a user defined function. $\endgroup$ – Ion Sme May 25 at 18:48
  • $\begingroup$ Mathematica is an "infinite evaluation system." That means it keeps applying rules until the result doesn't change any more. And it uses an idea of "simplicity" to usually try to drive in the direction of making a result "simpler." So if you evaluate Sum[1/n,{n,1,m}] it over and over applies internal hidden rules trying to make that simpler until it doesn't change. The result is HarmonicNumber[m]. That is the simplest form it can find. Trying to force Mathematica to do other than what it usually wants can be challenging. User functions and telling to not simplify can help sometimes. $\endgroup$ – Bill May 26 at 18:43
5
$\begingroup$
hn[k_, r_] := Inactive[Sum][1/n^r, {n, 1, k}]

hn[k, r]

enter image description here

When Activate'd this is the HarmonicNumber

hn[k, r] // Activate

(* HarmonicNumber[k, r] *)

For your specific example

hn[k, -1/2]

enter image description here

hn[k, -1/2] // Activate

(* HarmonicNumber[k, -(1/2)] *)

To see the expanded form for the first several cases

Table[hn[k, -1/2] // Activate, {k, 1, 7}]

(* {1, 1 + Sqrt[2], 1 + Sqrt[2] + Sqrt[3], 3 + Sqrt[2] + Sqrt[3], 
3 + Sqrt[2] + Sqrt[3] + Sqrt[5], 3 + Sqrt[2] + Sqrt[3] + Sqrt[5] + Sqrt[6], 
3 + Sqrt[2] + Sqrt[3] + Sqrt[5] + Sqrt[6] + Sqrt[7]} *)

or

Table[hn[k, -1/2], {k, 1, 7}] // Activate

(* {1, 1 + Sqrt[2], 1 + Sqrt[2] + Sqrt[3], 3 + Sqrt[2] + Sqrt[3], 
3 + Sqrt[2] + Sqrt[3] + Sqrt[5], 3 + Sqrt[2] + Sqrt[3] + Sqrt[5] + Sqrt[6], 
3 + Sqrt[2] + Sqrt[3] + Sqrt[5] + Sqrt[6] + Sqrt[7]} *)

If activated prior to summation, HarmonicNumber appears for higher values of k

Table[Evaluate[hn[k, -1/2] // Activate], {k, 1, 7}]

(* {1, 1 + Sqrt[2], 1 + Sqrt[2] + Sqrt[3], 3 + Sqrt[2] + Sqrt[3], 
 HarmonicNumber[5, -(1/2)], HarmonicNumber[6, -(1/2)], 
 HarmonicNumber[7, -(1/2)]} *)

FunctionExpand will convert to a sum

% // FunctionExpand

(* {1, 1 + Sqrt[2], 1 + Sqrt[2] + Sqrt[3], 3 + Sqrt[2] + Sqrt[3], 
3 + Sqrt[2] + Sqrt[3] + Sqrt[5], 3 + Sqrt[2] + Sqrt[3] + Sqrt[5] + Sqrt[6], 
3 + Sqrt[2] + Sqrt[3] + Sqrt[5] + Sqrt[6] + Sqrt[7]} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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