output formatting - How do I get a two-term polynomial with a leading negative sign to display in the correct (i.e. textbook) order?
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.
Comments
Post a Comment