Hi Jiger,
> my intention is if one index of the two PD is the same as the index of
> A, it should be replace by ruAz. I don't know if the rule is right, or
> how to express such an idea with a rule?
> SortCovDsStart[PD];
> ruAz = MakeRule[{PD[-b][PD[-a][A[a]]] , mg[-b, -e] mg[a, c] PD[-c][PD[-a][A[e]]]}];
This rule is syntactically correct and given that you have used
SortCovDsStart[PD] I see that you expect xTensor to infer that the PDs
can be reordered in the pattern matching. But MakeRule is not that
intelligent. MakeRule is a way to construct the simplest rules, which
are also the most frequent, but if you need something with more
complicated pattern constructs, then you have to construct the rule
yourself. Using the output of MakeRule is a good starting point:
HoldPattern[PD[-(b_Symbol)][PD[-(a_Symbol)][A[a_Symbol]]]] :>
Module[{t$1, t$2, t$3}, mg[-b, -t$3]*mg[t$1, t$2]*PD[-t$2][PD[-t
$1][A[t$3]]]]
The problem is that the left hand side is only valid for what it says:
the derivative index matching the derivative of A is the most internal
one. We can simply add the two needed alternatives:
HoldPattern[PD[-(b_Symbol)][PD[-(a_Symbol)][A[a_Symbol]]] | PD[-
(a_Symbol)][PD[-(b_Symbol)][A[a_Symbol]]]] :>
Module[{t$1, t$2, t$3}, mg[-b, -t$3]*mg[t$1, t$2]*PD[-t$2][PD[-t
$1][A[t$3]]]]
Now this rule works in the two cases you need. You could also replace
the rule by a list of two rules, having the two needed left-hand-
sides, and the same right-hand-side.
I think that MakeRule should be able to see this equivalent case. I'll
add it in the future.
Cheers,
Jose.