MMA differently handles division by zero. How to control this behavior?
In this case it delivers the expected error:
i/(i + k) /. {i -> 0, k -> 0}
(* Indeterminate *)
but if you calculate the same using Sum
Sum[i/(i + k), {i, 0, 0}] /. k -> 0
or Sum[0/k, {i, 0, 0}] /. k -> 0
(* 0 *)
the result is 0 presumably because MMA internally uses the limit:
Limit[0/(0 + k), k -> 0]
(* 0 *)
Trace
the evaluation you will see that theSum
is evaluated symbolically prior to the replacement. The symbolicSum
is zero and there is nok
to be replaced. Also,Inactive[Sum][i/(i + k), {i, 0, 0}] /. k -> 0 // Activate
evaluates to1
since Mathematica always immediately simplifiessymbol/symbol
to1
$\endgroup$symbol/symbol
in the first case? How can the symbol reduction in the sum be switched off? $\endgroup$Trace
and you will see that both variables are first replaced by zero resulting in0/(0+0)
so there is nosymbol/symbol
$\endgroup$Piecewise
or equivalent structure. $\endgroup$Sum[]
is evaluated in your code before the replacementk -> 0
(which is in no way connected with limits). The sum becomes0
, because0/k
evaluates to0
wheni = 0
. Then all instances ofk
that are left (which is none) are replaced by0
.Block[{k = 0}, Sum[i/(i + k), {i, 0, 0}]]
in effect hask
andi
evaluated simultaneously each time a term is computed.Sum[Evaluate[i/(i + k) /. k -> 0], {i, 0, 0}]
hask
evaluated first, before the sum is computed.Trace[]
will show these steps. $\endgroup$