# Contracting the KroneckerDelta should bring it back

I would like to define a function $$V[\phi] = \sum_{1\leq i,j,k,l\leq dim}\lambda_{ijkl} \phi_i\phi_j\phi_k\phi_l,$$ with $$\lambda_{ijkl}$$ defined by contractions of the type $$\delta_{ij}\delta_{kl}$$. Taking then several derivatives of $$V$$ with respect to $$\phi_i$$, introducing some function varD that would do the job as follows (with Sstanding for $$\phi$$):

varD[f1_ f2_, x_] := varD[f1, x] f2 + f1 varD[f2, x];
varD[f1_ + f2_, x_] := varD[f1, x] + varD[f2, x];
varD[c_?NumericQ, x_] := 0;
varD[ddelta[a_, b_], x_] := 0;
varD[S[a_], S[c_]] := ddelta[a, c];
ddelta[a_, b_] := ddelta[b, a];
Sum[ddelta[a_, c_] f_[c_] , {c, 1, dim}] -> f[a]

\$IterationLimit::itlim: Iteration limit of 4096 exceeded.


where the last two command lines attempt to reproduce the properties of a KroneckerDelta function and the last line shows the error it leads to. (Probably an intelligent way to use the replacement rule would solve the difficulty, but I'm quite unfamiliar with it [yet].)

Another attempt wrote the last line as such, getting a different error message:

Sum[ddelta[a_, c_] ddelta[c_, b_] , {c, 1, dim}] := ddelta[a, b]

SetDelayed::write: Tag Sum in \!$$\*UnderoverscriptBox[\(\[Sum]$$, $$c = 1$$, $$dim$$]$$ddelta[a_, c_]\ ddelta[c_, b_]$$\) is Protected. >>


So the problem is to allow formal derivatives of objects bringing Kronecker deltas and contracting those $$\delta$$'s with each other into other $$\delta$$'s in order to simplify the result.

I also tried to use the paclet of Carl Woll (see here: Why doesn't Mathematica make an obvious simplification?), but the link was dead.

If anyone as an interesting way to rephrase the problem, I'm open!

• The link is not dead. You just need to call PacletInstall properly to install the paclet, as is specified in the answer. – Carl Woll Aug 26 '19 at 23:46
• How does one call it properly? Writing PacletInstall["TensorSimplify", "Site" -> "http://raw.githubusercontent.com/carlwoll/TensorSimplify/master"] as you said, leads for me to PacletInstall::notavail: No paclet named TensorSimplify is available for download from any currently enabled paclet sites.` – faero Aug 27 '19 at 7:58