I am new to Mathematica so this question may seem rudimentary. Sorry for that! :)
I want to implement the well-known property of Kronecker's Delta
$$\Sigma_{i=1}^{n} a_i \delta_{ij}=a_j,\quad 1 \le j \le n$$
So I wrote the following code
KroDelProp[Eq_] := Module[{R, c, i, j, a, b},
R = Inactive[Sum][c_*KroneckerDelta[i_, j_], {i_, a_, b_}] :> (c /. i -> j);
Eq /. R
]
Eq = Inactive[Sum][a[i]*KroneckerDelta[i, j], {i, 1, n}]
KroDelProp[Eq]
(* a[j] *)
So everything looks fine. But when I use Rule
instead of RuleDelayed
in KroDelProp
then I get
KroDelProp[Eq_] := Module[{R, c, i, j, a, b},
R = Inactive[Sum][c_*KroneckerDelta[i_, j_], {i_, a_, b_}] -> (c /. i -> j);
Eq /. R
]
Eq = Inactive[Sum][a[i]*KroneckerDelta[i, j], {i, 1, n}]
KroDelProp[Eq]
(* a[i] *)
I read the documentation but I couldn't find out what is happening here!
Can someone shed some light on this? :)
I found reading this documentation very useful. Hope that it helps the future readers of this post too.
x = 17; {y -> x, y :> x}
$\endgroup$