I'm using the package xTensor in xAct. My issue is that inside a module indices are replaced by strings of the form $##### which make the final output unreadable. In a related post Print expressions using local variables in Module without Dollar sign: is that possible there is an answer to the case where there is a single contracted index, but I need a solution for when there are multiple indices. Let me sketch the idea here and give two examples to show the difference.
First we load the package (which can easily be downloaded from the xAct website) and define a manifold with a metric:
<< xAct`xTensor`
DefManifold[M,D,IndexRange[a,f]]
DefMetric[-1,G[-a,-b],CD]
This defines the Christoffel symbol and Ricci tensor of the metric G and you can obtain the explicit expressions in terms of the metric like so:
ChristoffelCD[c,-a,-b]//ChristoffelToMetric
RicciCD[-a,-b]//RiemannToChristoffel//ChristoffelToMetric
The problem is that the output of these lines contain contracted indices which are replaced with something like \$##### because they are redefined inside the module. I want the output to contain just a,b,c,d,e,f, not the dollar signs.
The solution from the linked post is to define the following function (horizontal scroll):
dollars[expr_] := Module[{}, StringReplace[ToString[expr, FormatType -> StandardForm], c : WordCharacter ~~ "$" ~~ DigitCharacter .. :> c]];
This function does the job for the Christoffel connection, since it only involves one contraction. For example it replaces f\$##### by f:
dollars@(ChristoffelCD[c,-a,-b]//ChristoffelToMetric)
However, if you try to do this for the Ricci tensor, then there are multiple contracted indices in the connection squared terms:
RicciCD[-a,-b]//RiemannToChristoffel
The squared connection terms contain two contractions denoted with the indices f\$34123 and f\$91232 in the output (the numbers are arbitary). If you then apply the "dollars" function both these indices are replaced by f, so you end up with an object with more than two f indices in some terms, which doesn't make sense:
dollars@(RicciCD[-a,-b]//RiemannToChristoffel)
My question is: how do I generalize the function dollars[expr_] to count the number of times a \$-sign index has been used, and then return an expression with no duplicate indices?
Any help is greatly appreciated, cheers.