I'm using Mathematica 12.0 Student Edition. I'm a little confused by the length of time Mathematica takes to evaluate certain sums of Kronecker Deltas or Discrete Deltas. Here's a simple example below:

My global assumptions are

$Assumptions = M \[Element] PositiveIntegers;

When I time the double sum of a Kronecker delta below, I get .171875 seconds:

Timing[Sum[KroneckerDelta[i, j], {i, 1, M}, {j, 1, M}]]

When I time a similar sum, I get 14.7656 seconds (!):

Timing[Sum[1/2 (1 + KroneckerDelta[i, j]), {i, 1, M}, {j, 1, M}]]

Why is there a spike in the amount of time Mathematica takes to evaluate this second sum? Could you please give me a general method to speed up the second evaluation?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.