How do I let mathematica compute a tensor contraction like
$\delta_{ab}\delta_{bc}$
with an output
$\delta_{ac}$
efficiently?
I tried TensorContract and TensorReduce but they were not helpful.
Thanks for your help!
How do I let mathematica compute a tensor contraction like
$\delta_{ab}\delta_{bc}$
with an output
$\delta_{ac}$
efficiently?
I tried TensorContract and TensorReduce but they were not helpful.
Thanks for your help!
A straightforward way to implement Kronecker Delta is as follows:
SetAttributes[\[Delta], Orderless];
\[Delta][a_, b_] f_[c___, b_, d__] ^:= f[c, a, d] /; ! NumericQ[b];
\[Delta][a_, a_] := dim /; ! NumericQ[a];
\[Delta][a_, b_] := Boole[a == b] /; NumericQ[a] && NumericQ[b];
Format[\[Delta][a_, b_]] := Subscript[\[Delta], a, b];
where dim is the dimension of the vector space. We see that it satisfies required conditions:
In[1]:= {\[Delta][a, b] \[Delta][b, d], \[Delta][a, b] f[b, c], \[Delta][a, b] == \[Delta][b, a], \[Delta][1, 2], \[Delta][1, 1], \[Delta][a, a]}
Out[1]:= {Subscript[\[Delta], a, d], f[a, c], True, 0, 1,dim}
In other words, for the input
$\left\{\delta _{a,b} \delta _{b,d},\delta _{a,b} f(b,c),\delta _{a,b}=\delta _{b,a},\delta _{1,2},\delta _{1,1},\delta _{a,a}\right\}$
we get the expected output:
$\left\{\delta _{a,d},f(a,c),\text{True},0,1,dim\right\}$
Try this:
Subscript[δ, i_, j_] := KroneckerDelta[i, j];
ruleDelta =
KroneckerDelta[1, i_] KroneckerDelta[1, k_] +
KroneckerDelta[2, i_] KroneckerDelta[2, k_] +
KroneckerDelta[3, i_] KroneckerDelta[3,
k_] -> Subscript[δ, i, k]
On your screen it looks as follows:
Then
Sum[Subscript[δ, i, j]*Subscript[δ, j, k], {j, 1,3}] /. ruleDelta
(* KroneckerDelta[i, k] *)
Looking as
on the screen.
Have fun!
ruleDelta = a__*KroneckerDelta[1, i_] KroneckerDelta[1, k_] -> a*(Subscript[\[Delta], i, k] - KroneckerDelta[2, i] KroneckerDelta[2, k] - KroneckerDelta[3, i] KroneckerDelta[3, k]) then Sum[b*Subscript[\[Delta], i, j]*Subscript[\[Delta], j, k], {j, 1, 3}] /. ruleDelta // Simplify yields what you expect.
– Alexei Boulbitch
Feb 26 '20 at 16:01