Whats the Mathematica command for the skew harmonic number?

What's the Mathematica code for the skew harmonic number: $$\overline{H}_n=\sum_{k=1}^n \frac{(-1)^{k-1}}{k}.$$

Wolfram expresses this number as $$\ln(2)-(-1)^n \text{LerchPhi}(-1,1,n+1).$$

I am wondering if there is a shorter command that Mathematica can understand.

• Is Sum[(-1)^(k-1)/k,{k,n}] satisfactory? – Adam Feb 24 at 22:14
• @Adam thank you but this is just the sum representation. I'm looking for a simple code. – Ali Shadhar Feb 24 at 22:28
• H[n_]:=Sum[(-1)^(k-1)/k,{k,n}] --or-- H[n_] := (Log[ 2] - (-1)^n LerchPhi[-1, 1, n + 1]) ? – Denis Cousineau Feb 24 at 22:57
• SeriesCoefficient[Log[x + 1]/(1 - x), {x, 0, n}]... – ciao Feb 24 at 23:04
• It's not clear why you don't find the expression in terms of the Lerch transcendent satisfactory. – J. M.'s torpor Feb 25 at 1:52

Log[2] + (-1)^n*(1/2)*(PolyGamma[1/2 + n/2] - PolyGamma[1 + n/2])


or

Log[2] + (-1)^n*(1/2)*(HarmonicNumber[-(1/2) + n/2] - HarmonicNumber[n/2])


?

• Thank you for the efforts +1 – Ali Shadhar Feb 25 at 2:29
Clear["Global*"]

\$Version

(* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *)

f[n_] = Sum[(-1)^(k - 1)/k, {k, n}] /. (-1)^(n + 1) :> -(-1)^n

(* (-1)^(1 + n) LerchPhi[-1, 1, 1 + n] + Log[2] *)


For large n this converges to Log[2]

Limit[f[n], n -> Infinity]

(* Log[2] *)


The real part of f is

f2[n_] = Assuming[Element[n, Reals],
Re[f[n]] // ComplexExpand // FullSimplify]

(* -Cos[n π] LerchPhi[-1, 1, 1 + n] + Log[2] *)


f2 is equal to f for integer arguments:

Assuming[Element[n, Integers], f[n] == f2[n] // Simplify]

(* True *)


Graphically,

Show[
Plot[f2[n], {n, 0, 25},
PlotRange -> All,
GridLines -> {None, {Log[2]}},
GridLinesStyle ->
Directive[Gray, AbsoluteThickness[1], Dashed]],
DiscretePlot[f[n], {n, 0, 25},
PlotStyle -> ColorData[97][2]]]


• Thank you. I'm wondering if there is a shorter expression. +1 though. – Ali Shadhar Feb 25 at 2:28
• I'll only note that (-1)^(1 + n) LerchPhi[-1, 1, 1 + n] + Log[2] // FunctionExpand does nothing, but (-1)^(1 + n) HurwitzLerchPhi[-1, 1, 1 + n] + Log[2] // FunctionExpand` can be simplified into the expressions in Andreas's answer. – J. M.'s torpor Feb 25 at 4:20