# substitute() is buggy?

+1 vote

I'm not sure if this is a bug or if I'm missing something. Here's an example (wasn't able to reproduce the bug in simpler examples):

{ \mu, \nu, \lambda, \kappa, \rho, \sigma# }::Indices(total, position=fixed).

\partial{#}::PartialDerivative.
\nabla{#}::Derivative.

def expand_nabla(ex):
for nabla in ex[r'\nabla']:
nabla.name=r'\partial'
dindex = nabla.indices().__next__()
for arg in nabla.args():
ret:=0;
for index in arg.free_indices():
t2:= @(arg);
if index.parent_rel==sub:
t1:= -\Gamma^{\sigma1}_{@(dindex) @(index)};
t2[index]:= _{\sigma1};
else:
t1:= \Gamma^{@(index)}_{@(dindex) \sigma1};
t2[index]:= ^{\sigma1};
ret += Ex(str(nabla.multiplier)) * t1 * t2
nabla += ret
return ex

ex1:= covd1_{\alpha \rho \sigma} = \nabla_{\alpha}{h_{\rho \sigma}}:
expand_nabla(ex1)
rename_dummies(ex1);

ex2:= covd2_{\lambda \alpha \rho \sigma} = \nabla_{\lambda}{covd1_{\alpha \rho \sigma}}:
expand_nabla(ex2)
rename_dummies(ex2);
substitute(ex2,ex1, repeat = True);

There are four terms which require this substitution in the final step. The result seems to actually substitute for three of them but one term doesn't get substituted as in the image below:

https://ibb.co/QD7rQrF

That term which did not get substituted has an index \alpha on covd2. But you did not declare \alpha to be part of the index set total. Hence that object does not match the rule in ex1.
Just add \alpha to the index set and it works.