0
$\begingroup$

I have monomials with variables $a_1,\, a_2,\,\dots$ also their complex conjugates. I found that their order within the monomial depends on at which point I set the overline for the complex conjugate. It was impossible to order them by their index (i.e., have $a_1$ and $\bar a_1$ close together).

But now I added coefficients for the monomial terms and, because they are greek letters, they will be sorted to the end of the monomial. What causes/influences this ordering? How can I get them placed at the beginning?

Here's code for two monomials, both as LaTeX and input, showing what I am experiencing.

$\qquad \left\{a_1 \beta _1 S_{i_1},\,a_3 a_6 \beta _2 \overline{a_4} \right\}$

{Subscript[β, 1]*Subscript[a, 1]*Subscript[S, Subscript[i, 1]], 
 OverBar[Subscript[a, 4]]*Subscript[β, 2]*Subscript[a, 3]*Subscript[a, 6]}
$\endgroup$

1 Answer 1

0
$\begingroup$

I found How do I reassign canonical ordering of symbols? and adapted Simon Woods answer to my problem. The following does the trick:

reorderSymbols[expr_, symbols_List] := With[{s = symbols}, 
  HoldForm[Evaluate[expr /. Thread[s -> Sort@s]]] /. Thread[Sort@s -> s]]

reorderPoly[poly_] := Module[{ss},
  mapC[c_] := Map[(Subscript[c, #1])&,Range[Length[poly]]];
  ss = Flatten[Map[mapC,{\[Alpha],\[Beta],\[Gamma],\[Delta],\[CurlyEpsilon],\[Zeta]}]]~Join~Map[(Subscript[a, #])&,Range[6]]~Join~Map[(
  \!\(\*OverscriptBox[
  SubscriptBox[\(a\), \(#\)], \(_\)]\))&,Range[6]];
  reorderSymbols[poly, ss]
]

reorderPoly[{Subscript[β, 1]*Subscript[a, 1]*Subscript[S, Subscript[i, 1]], 
  OverBar[Subscript[a, 4]]*Subscript[β, 2]*Subscript[a, 3]*Subscript[a, 6]}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.