The first three expressions evaluate as expected and the polynomial is displayed in what I would call "textbook" form. The last expression, however, switches the order of terms. Mathematica employs this change for two-term polynomials if it results in getting rid of the leading negative sign (at least that is the best I can deduce).
x^2 + x + 5 // TraditionalForm
(* x^2 + x + 5 *)
-x^2 + x + 5 // TraditionalForm
(* -x^2 + x + 5 *)
x^2 + x // TraditionalForm
(* x^2 + x *)
-x^2 + x // TraditionalForm
(* x - x^2 *)
These polynomials are the result of prior symbolic manipulation, so I cannot simply use HoldForm
or the equivalent to maintain the desired order.
Is there a way to change this behavior in general so that the last expression displays as -x^2 + x
? I can think of substitution rules to fix this particular example, but would like to find a robust solution that applies as transparently as possible across the board.
Edit
Additionally, PolynomialForm
produces the same results:
PolynomialForm[-x^2 + x , TraditionalOrder -> True]
(* x - x^2 *)
PolynomialForm[-x^2 - x , TraditionalOrder -> True]
(* -x^2 - x *)
It seems that Mathematica will produce the traditional order for polynomial terms except when there are only two terms and reversing the order eliminates the leading negative sign.
PolynomialForm[#, TraditionalOrder -> True] &
but I see that you're going the other way. Let me think about that. $\endgroup$PolynomialForm
and that produces the same results. I will add that information to the question because that will probably be a common thought pattern. $\endgroup$Plus
. But would be nice with a way that lets you override the displayed order ofOrderless
arguments. $\endgroup$