2

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?

xzczd
  • 65,995
  • 9
  • 163
  • 468
Jasmine
  • 1,225
  • 3
  • 10
  • Is $i$ imaginary unit? Are you sure the result given in $\LaTeX$ is correct? – xzczd Apr 29 '21 at 05:15
  • @xzczd I have edited the question. There is a negative sign missing. Also i is imaginary unit. – Jasmine Apr 29 '21 at 05:30
  • 1
    Then I suggest making the imaginary $ \mathrm{i} $ upright, not to be confused with the index $ i $. – Αλέξανδρος Ζεγγ Apr 29 '21 at 05:51
  • 1
    @ΑλέξανδροςΖεγγ Alternatively, one may consider \mathbf{i}. – xzczd Apr 29 '21 at 06:01
  • “I am finding the issue because order matters here. X is operator. So it's order is important. ” The statement is a bit confusing to me. Can you elaborate a bit? – xzczd Apr 29 '21 at 06:44
  • @xzczd This is because X_ij X_kl is not equal to X_kl X_ij – Jasmine Apr 29 '21 at 06:51
  • Then why does $-\sum_{i,j,k,l}\left(g_{ijkl}\hat{X}{ij}\hat{X}{kl}+ig_{ijkl}\hat{X}{ij}\delta{kl}+ig_{ijkl}\delta_{ij}\hat{X}{kl}-g{ijkl}\delta_{ij}\delta_{kl}\right)=-\sum_{i,j,k,l}g_{ijkl}\hat{X}{ij}\hat{X}{kl}$? Is $\delta$ KroneckerDelta? – xzczd Apr 29 '21 at 07:28
  • @xzczd I didn't understand what you meant? – Jasmine Apr 29 '21 at 07:58
  • I mean, knowing "g and X are antisymmetric tensors" doesn't seem to be enough to deduce the last summation, please clarify. – xzczd Apr 29 '21 at 08:01
  • @xzczd Editted. I have elaborated – Jasmine Apr 29 '21 at 08:19
  • …Then, isn't this question essentially a duplicate of https://mathematica.stackexchange.com/a/226190/1871 ? – xzczd Apr 29 '21 at 10:00
  • @xzczd No. this is because in that problem, they were just matrix coefficients. But here they are operators, that means order matters. – Jasmine Apr 29 '21 at 10:03

1 Answers1

4

SumHeld, IndexUnify and SumTogether are almost irrelevant to this task, please avoid utilizing others' code blindly. Then, though not a duplicate, this question is strongly related to your previous question. We just need to modify the rule there a little to make it handle non-commutative multiply.

We first define functions for expansion of non-commutative multiply. The first 3 definitions are taken from document of NonCommutativeMultiply:

ExpandNCM[(h : NonCommutativeMultiply)[a___, b_Times, c___]] := 
 Most[b] ExpandNCM[h[a, Last[b], c]]
ExpandNCM[a_] := ExpandAll[a]
ExpandNCM[(h : NonCommutativeMultiply)[a___, b_Plus, c___]] := 
 Distribute[h[a, b, c], Plus, h, Plus, ExpandNCM[h[##]] &]

ExpandNCM[c_ (h : NonCommutativeMultiply)@a__] := c ExpandNCM[h@a] // Expand

Then, modify a bit the definitions of Kronecker delta in my previous answer to make it handle non-commutative multiply:

Clear[δ];
SetAttributes[δ, Orderless]
δ /: δ[a_, b_] h_[former___, b_, latter___] := h[former, a, latter]

δ /: (expr : Except[__δ]) ** δ[a_, b_] := δ[a, b] expr δ /: δ[a_, b_] ** (expr : Except[__δ]) := δ[a, b] expr

Finally, take the definition of antisymmetric tensor from my previous answer and add one more definition so that $g_{ijll}=0$:

g[arg__] /; ! OrderedQ@{arg} := Signature@{arg} g @@ Sort@{arg}

g[___, a_, a_, ___] := 0

Now the desired output is obtained:

g[i, j, k, l] ((X[i, j] + I δ[i, j])/I) ** ((X[k, l] + I δ[k, l])/I) // ExpandNCM
(* -g[i, j, k, l] X[i, j] ** X[k, l] *)
xzczd
  • 65,995
  • 9
  • 163
  • 468