# How to sort a "+" sequence and get back a new sequence of "+" sorted? [closed]

How to sort a "+" sequence like

1+5+3+2+4

to get back

1+2+3+4+5

Same sorting problem with polynoms (but I am mainly interested in the above simple "1+5+3+2+4" sorting):

Expand[(x^3 - x + 5)^6]

TraditionalForm[Expand[(x^3 - x + 5)^6]]

Expand[(x^3 - a*x + 5)^6]

Collect[Expand[(x^3 - a*x + b)^6], x, Factor]

TraditionalForm[Collect[Expand[(x^3 - a*x + b)^6], x, Factor]]

Thank you beforehand for an answer.

Regards.

Gianni

• Can you please provide more concrete example for 1+5+3+2+4? This obviously gets evaluated to 15. Are you using inactivated operators? In that case: Sort@Inactivate[1 + 5 + 3 + 2 + 4, Plus] does the job. As for the polynomials: they are sorted by the descending power of $x$. How would you want them to be sorted? By the prefactors? Mar 15 at 13:53
• Plus has the attribute Orderless, which means that terms are automatically sorted into canonical order. Mar 15 at 22:16
• Some possibly related links may be found here: mathematica.stackexchange.com/questions/108147/… Mar 15 at 22:19

sum="{14+5+9+7}";a=ToString[Sort[ToExpression[StringReplace[sum,"+"->","]]]];