1
$\begingroup$

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 *)

$\endgroup$
7
  • 2
    $\begingroup$ If you Trace the evaluation you will see that the Sum is evaluated symbolically prior to the replacement. The symbolic Sum is zero and there is no k to be replaced. Also, Inactive[Sum][i/(i + k), {i, 0, 0}] /. k -> 0 // Activate evaluates to 1 since Mathematica always immediately simplifies symbol/symbol to 1 $\endgroup$
    – Bob Hanlon
    Commented Jun 27, 2021 at 16:27
  • 1
    $\begingroup$ but why does it not reduce to symbol/symbol in the first case? How can the symbol reduction in the sum be switched off? $\endgroup$ Commented Jun 27, 2021 at 16:37
  • $\begingroup$ Use Trace and you will see that both variables are first replaced by zero resulting in 0/(0+0) so there is no symbol/symbol $\endgroup$
    – Bob Hanlon
    Commented Jun 27, 2021 at 16:41
  • $\begingroup$ If you want a non-standard interpretation specify the conditions and results with Piecewise or equivalent structure. $\endgroup$
    – Bob Hanlon
    Commented Jun 27, 2021 at 16:48
  • 2
    $\begingroup$ Expressions are evaluated in a certain order. Sum[] is evaluated in your code before the replacement k -> 0 (which is in no way connected with limits). The sum becomes 0, because 0/k evaluates to 0 when i = 0. Then all instances of k that are left (which is none) are replaced by 0. Block[{k = 0}, Sum[i/(i + k), {i, 0, 0}]] in effect has k and i evaluated simultaneously each time a term is computed. Sum[Evaluate[i/(i + k) /. k -> 0], {i, 0, 0}] has k evaluated first, before the sum is computed. Trace[] will show these steps. $\endgroup$
    – Michael E2
    Commented Jun 27, 2021 at 17:53

0

Browse other questions tagged or ask your own question.