Is there a way to perform the below summation in Mathematica?
$$\frac{\left(\hat{X}_{ij}+\mathbb i\delta_{ij}\right)}{\mathbb{i}}\frac{\left(\hat{X}_{kl}+\mathbb i\delta_{kl}\right)}{\mathbb{i}}$$
I am finding the issue because order matters here. X is operator. So it's order is important. g and X are antisymmetric tensors. The answer to the above equation I am expecting is:
$$-\text{test}=\sum_{i,j,k,l}g_{ijkl}\frac{\left(\hat{X}_{ij}+\mathbb i\delta_{ij}\right)}{\mathbb i}\frac{\left(\hat{X}_{kl}+\mathbb i\delta_{kl}\right)}{\mathbb i} =-\sum_{i,j,k,l}g_{ijkl}\left(\hat{X}_{ij}+\mathbb i\delta_{ij}\right)\left(\hat{X}_{kl}+\mathbb i\delta_{kl}\right) =-\sum_{i,j,k,l}g_{ijkl}\left(\hat{X}_{ij}\hat{X}_{kl}+\mathbb i\hat{X}_{ij}\delta_{kl}+\mathbb i\delta_{ij}\hat{X}_{kl}+\mathbb i\mathbb i\delta_{ij}\delta_{kl}\right) =-\left(\sum_{i,j,k,l}g_{ijkl}\hat{X}_{ij}\hat{X}_{kl}+\sum_{i,j,k,l}g_{ijkl}\mathbb i\hat{X}_{ij}\delta_{kl}+\sum_{i,j,k,l}g_{ijkl}\mathbb i\delta_{ij}\hat{X}_{kl}+\sum_{i,j,k,l}g_{ijkl}\mathbb i\mathbb i\delta_{ij}\delta_{kl}\right) =-\left(\sum_{i,j,k,l}g_{ijkl}\hat{X}_{ij}\hat{X}_{kl}+\sum_{i,j,k,l}g_{ijll}\mathbb i\hat{X}_{ij}+\sum_{i,j,k,l}g_{ijll}\mathbb i\hat{X}_{kl}+\sum_{i,j,k,l}g_{ijll}\mathbb i\mathbb i\delta_{ij}\right) $$
Since $g$ is an antisymmetric tensor, if any of the two indices are same then it will be zero. Thus, $$g_{ijll}=0$$
Thus we get the answer: $$test=-\sum_{i,j,k,l}g_{ijkl}\hat{X}_{ij}\hat{X}_{kl}$$
Can I implement this using the following code:
SumHeld /: MakeBoxes[SumHeld[expr_, ranges__], form_] :=
MakeBoxes[Sum[expr, ranges], form]
SumHeld /:
SyntaxInformation[
SumHeld] = {"LocalVariables" -> {"Table", {2, Infinity}}};
SumHeld /: c_?NumericQ SumHeld[rest_, range__] :=
SumHeld[c rest, range]
IndexUnify[HoldPattern@Plus[sums : SumHeld[_, __] ..]] :=
Plus @@ With[{targetIndices = List @@ #[[-1, 2 ;;, 1]],
sourceIndicesList = List @@@ #[[;; , 2 ;;, 1]]},
Function[{sum, sourceIndices},
sum /. Thread[
sourceIndices ->
Take[targetIndices, Length@sourceIndices]]] @@@
Transpose@{#, sourceIndicesList}] &@
SortBy[Flatten /@ {sums}, Length]
SumTogether[HoldPattern@Plus[sums : SumHeld[_, sameRanges__] ..]] :=
SumHeld[Plus @@ {sums}[[;; , 1]], sameRanges]
SumTogether[HoldPattern@Plus[sums : SumHeld[_, __] ..]] /;
UnsameQ @@ {sums}[[;; , 2 ;;]] :=
Plus @@ SumTogether@*Plus @@@ GatherBy[{sums}, Rest]
SumHeld[expr_, {lst_List,
dim_}] := (term |->
SumHeld[term,
Sequence @@
Table[If[Count[term, patt, ∞] == 2, {patt, dim},
Nothing], {patt, lst}]]) /@ expr
How to modify the above code to incorporate to handle operators?
\mathbf{i}. – xzczd Apr 29 '21 at 06:01KroneckerDelta? – xzczd Apr 29 '21 at 07:28