Hi,

I am having difficulties with canonicalizing dummy indices on expressions involving index brackets. In particular, I want to canonicalize indices in a term involving a factor with no symmetries but with dummy indices shared with a gamma matrix, particularly for the purpose of combining with other terms with indices already arranged in canonical order. This works perfectly when no index brackets are present, as in the code sample below,

```
ex := \Gamma^{a b} \Psi_{b a} + \Gamma^{a b} \Psi_{a b};
canonicalise(ex);
```

which gives

```
Γ^{a b} Ψ_{b a} + Γ^{a b} Ψ_{a b}
0
```

However, when index brackets are added, the expression is no longer canonicalized, and hence the terms are no longer combined, as in the code sample below,

```
ex := (\Gamma^{a b})_{\alpha \beta} (\Psi_{b a})_{\gamma \eta} + (\Gamma^{a b})_{\alpha \beta} (\Psi_{a b})_{\gamma \eta};
canonicalise(ex);
```

which gives

```
\indexbracket(Γ^{a b})_{α β} \indexbracket(Ψ_{b a})_{γ η} + \indexbracket(Γ^{a b})_{α β} \indexbracket(Ψ_{a b})_{γ η}
\indexbracket(Γ^{a b})_{α β} \indexbracket(Ψ_{b a})_{γ η} + \indexbracket(Γ^{a b})_{α β} \indexbracket(Ψ_{a b})_{γ η}
```

Is there any way to fix this? I have tried to tease out a solution using an index substitution, which I know is generally counter-recommended (rename_dummies() unfortunately does not help here), as in the code below,

```
ex := (\Gamma^{a b})_{\alpha \beta} (\Psi_{b a})_{\gamma \eta};
substitute(ex, $_{a} -> _{b}, ^{a} -> ^{b}, _{b} -> _{a}, ^{b} -> ^{a}$);
canonicalise(ex);
```

which successfully gives

```
\indexbracket(Γ^{a b})_{α β} \indexbracket(Ψ_{b a})_{γ η}
\indexbracket(Γ^{b a})_{α β} \indexbracket(Ψ_{a b})_{γ η}
\indexbracket(-Γ^{a b})_{α β} \indexbracket(Ψ_{a b})_{γ η}
```

However, applying this index substitution in the context of arithmetic is still a hurdle, and such an index substitution sometimes raises errors when partial derivatives are involved, as in the code below (I have removed the index brackets in order to isolate the feature that is triggering the error),

```
ex := \Gamma_{b c} \Gamma^{b c d} \delta_{a}^{e} \partial_{e}(\Psi_{d});
substitute(ex, $_{e} -> _{b}, ^{e} -> ^{b}, _{b} -> _{c}, ^{b} -> ^{c}, _{c} -> _{d}, ^{c} -> ^{d}, _{d} -> _{e}, ^{d} -> ^{e}$);
```

which raises a triple index error. Note that the same code works with the partial derivative factor replaced, as in the code below.

```
ex := \Gamma_{b c} \Gamma^{b c d} \delta_{a}^{e} \Psi_{e d};
substitute(ex, $_{e} -> _{b}, ^{e} -> ^{b}, _{b} -> _{c}, ^{b} -> ^{c}, _{c} -> _{d}, ^{c} -> ^{d}, _{d} -> _{e}, ^{d} -> ^{e}$);
```

Both the index-canonicalization issue with index brackets and the index-substitution issue with partial derivatives seem to have to do with recognizing vector indices and their symmetries within different branches of the ExNode tree structure of the expression. Am I making a mistake in my index handling? Is there any way to get around these issues?

The full code for the above tests is shown below.

```
{a,b,c,d,e}::Indices(vector)
{a,b,c,d,e}::Integer(0..10)
{\alpha,\beta,\gamma,\eta}::Indices(spinor)
\partial{#}::PartialDerivative
\Psi{#}::Depends(\partial{#})
\Gamma_{#}::GammaMatrix(metric=\delta)
\delta{#}::KroneckerDelta
print('\ntest 1')
ex := \Gamma^{a b} \Psi_{b a} + \Gamma^{a b} \Psi_{a b};
canonicalise(ex);
print('\ntest 2')
ex := (\Gamma^{a b})_{\alpha \beta} (\Psi_{b a})_{\gamma \eta} + (\Gamma^{a b})_{\alpha \beta} (\Psi_{a b})_{\gamma \eta};
canonicalise(ex);
print('\ntest 3')
ex := (\Gamma^{a b})_{\alpha \beta} (\Psi_{b a})_{\gamma \eta};
substitute(ex, $_{a} -> _{b}, ^{a} -> ^{b}, _{b} -> _{a}, ^{b} -> ^{a}$);
canonicalise(ex);
print('\ntest 4')
ex := \Gamma_{b c} \Gamma^{b c d} \delta_{a}^{e} \Psi_{e d};
substitute(ex, $_{e} -> _{b}, ^{e} -> ^{b}, _{b} -> _{c}, ^{b} -> ^{c}, _{c} -> _{d}, ^{c} -> ^{d}, _{d} -> _{e}, ^{d} -> ^{e}$);
print('\ntest 5')
ex := \Gamma_{b c} \Gamma^{b c d} \delta_{a}^{e} \partial_{e}(\Psi_{d});
substitute(ex, $_{e} -> _{b}, ^{e} -> ^{b}, _{b} -> _{c}, ^{b} -> ^{c}, _{c} -> _{d}, ^{c} -> ^{d}, _{d} -> _{e}, ^{d} -> ^{e}$);
```

Thanks in advance.

-Simon