Reordering indices in alphabetical order

23 views
Skip to first unread message

Sukruti

unread,
Sep 29, 2025, 9:23:09 AM (4 days ago) Sep 29
to xAct Tensor Computer Algebra
Hello,

Does anyone know how to make Mathematica reorder the indices of a given tensorial expression with free indices, in ascending alphabetical order?

Attached notebook shows the question more explicitly.

Best,
Sukruti
How to reorder indices.nb

Thomas Bäckdahl

unread,
Sep 29, 2025, 12:15:24 PM (4 days ago) Sep 29
to xa...@googlegroups.com

Hi!

This was a bit more complicated than I thought because FindFreeIndices sorts the indices, so it can not be used to extract the index ordering. However, FindIndices keeps the order of the indices.

The following two functions might do what you need. SortFreeInds can be dangerous, in particular if you have indices belonging to different VBundles. In that case you have to separate the indices into groups belonging to the same VBundle and only sort within each group. I have also ignored the possibility of blocked indices.

FreeIndsDown[expr_] := 
 ReplaceIndex[
  Evaluate@expr, (# -> DownIndex[#]) & /@ 
   List @@ FindFreeIndices[Evaluate@expr]]

SortFreeInds[expr_] := 
 ReplaceIndex[Evaluate@expr, 
  Thread[(# -> Sort@#) &@
      DeleteCases[List @@ #, 
       Alternatives @@ xAct`xTensor`Private`TakeEPairs[#]] &@
    FindIndices[Evaluate@expr]]]

Regards
Thomas

--
You received this message because you are subscribed to the Google Groups "xAct Tensor Computer Algebra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xact+uns...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/xact/1f764d21-79e9-4310-8b34-6664f6a72ed2n%40googlegroups.com.

Sukruti

unread,
6:18 AM (21 minutes ago) 6:18 AM
to xAct Tensor Computer Algebra
Reply all
Reply to author
Forward
0 new messages