Why MMA delivers this result?
To see more clearly what's happening, let's do one function per line.
Limit[k Sum[1/i,{i,1,k-1}],k->0]
is the same as
f1=Sum[1/i,{i,1,k-1}]
$=H_{k-1}$
f2=k f1
$=kH_{k-1}$
f3=Limit[f2,k->0]
$=-1$
The basic issue is Mathematica evaluates the Sum
first assuming it is not empty. This is indeed an issue you can encounter in Mathematica and can be a bit annoying. The basic issue is Sum
will give a general form assuming some things about your variables. You can explicitly see these assumptions by using GenerateConditions
. Consider the following:
Sum[1/i,{i,1,-1}]
$=0$
Sum[1/i, {i, 1, k-1}]
$=H_{k-1}$
Sum[1/i, {i, 1, k-1}]/. k->0
$=$ ComplexInfinity
Sum[1/i,{i,1,k-1},GenerateConditions->True]
$=H_{k-1}\text{ if }k\in \mathbb{Z}\land k\geq 2$
Sum[1/i,{i,1,k-1},GenerateConditions->True]/. k->0
$=$ Undefined
and how to interpret or reformulate it?
I've encountered this a few times in the past and never found an elegant solution. What I ended up doing was just defining the special cases separately. For your case that's simple. Just plug in $k=0$ initially:
With[{k = 0}, k Sum[1/i, {i, 1, k - 1}]]
gives 0.
In more complicated situations you can use Piecewise
, If
, or Condition
to control the evaluation at a lower level.
k* Sum[1/i, {i, 1, k - 1}]
performs $k H_{k-1}$. $\endgroup$Sum[1/i, {i, 1, -1}]
equals0
andHarmonicNumber[-1]
isComplexInfinity
and0*HarmonicNumber[-1]
performsIndeterminate
. $\endgroup$Sum
something similar toSum[...,{i,1,-1}]
. $\endgroup$