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
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? $\endgroup$Plus
has the attributeOrderless
, which means that terms are automatically sorted into canonical order. $\endgroup$