<https://mathematica.stackexchange.com/a/222410/73364> I have obtained the following code from the above link. But it is not working well with my situation. Can anyone help me out? SumHeld /: SyntaxInformation[ SumHeld] = {"LocalVariables" -> {"Table", {2, Infinity}}}; 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] The definitions I am using are the following: x[arg__] /; ! OrderedQ@{arg} := Signature@{arg} x @@ Sort@{arg} Format[x[arg__]] := Subscript[x, arg] g[arg__] /; ! OrderedQ@{arg} := Signature@{arg} g @@ Sort@{arg} g[___, j_, j_, ___] = 0; Format[g[arg__]] := Subscript[g, arg] It's working in the following case: test1 = SumHeld[I* g[i, j, k, l] x[j, l] x[k, \[Alpha]] \[Delta][i, \[Beta]], {j, 1, 5}, {l, 1, 5}, {k, 1, 5}, {i, 1, 5}] + SumHeld[SumHeld[ I *g[i, j, k, l] x[i, k] x[l, \[Alpha]] \[Delta][j, \[Beta]]], {i, 1, 5}, {k, 1, 5}, {l, 1, 5}, {j, 1, 5}] % // IndexUnify Failing case: Test2=SumHeld[I* g[i, j, k, l] x[i, \[Alpha]] x[j, l] \[Delta][k, \[Beta]], {i, 1, 5}, {j, 1, 5}, {l, 1, 5}, {k, 1, 5}] + SumHeld[SumHeld[ I *g[i, j, k, l] x[i, k] x[j, \[Alpha]] \[Delta][l, \[Beta]]], {i, 1, 5}, {k, 1, 5}, {j, 1, 5}, {l, 1, 5}]; % // IndexUnify