I could very well be missing something obvious, but this has always bugged me with Mathematica and I don't know why it does it or how to fix it.
If I enter any polynomial, say, x^2 + x - 1 for example, the output is always in the form:
-1 + x + x^2
And again:
input: Expand[(x^2 - 1) ((-3 + x)^2 - 4)]
output: -5 + 6 x + 4 x^2 - 6 x^3 + x^4
I find this much more difficult to read than the traditional way, from highest power to lowest. Is there anything I can do to change this? I'm aware that TraditionalForm prints them properly, but it is generally not recommended to do calculations with TraditionalForm so I'd like to avoid that if possible. Then again, IS IT that bad to do calculations with TraditionalForm like it warns?
Answer
As Daniel Lichtblau wrote in the comment you can use TraditionalForm
Expand[(x^2 - 1) ((-3 + x)^2 - 4)] // TraditionalForm
$x^4-6 x^3+4 x^2+6 x-5$
However, it works perfectly only with univariate polynomials
Expand[(x + y + 1)^5] // TraditionalForm
$x^5+5 x^4 y+5 x^4+10 x^3 y^2+20 x^3 y+10 x^3+10 x^2 y^3+30 x^2 y^2+30 x^2 y+10 x^2+5 x y^4+20 x y^3+30 x y^2+20 x y+5 x+y^5+5 y^4+10 y^3+10 y^2+5 y+1$
You can see that $5x$ is before $y^5$ and so on.
My solution consist in the manual sorting of monomials
OrderedForm = HoldForm[+##] & @@ MonomialList[#][[
Ordering[Total[#] & @@@ CoefficientRules[#], All, GreaterEqual]]] &;
Expand[(x + y + 1)^5] // OrderedForm
x^5+5 x^4 y+10 x^3 y^2+10 x^2 y^3+5 x y^4+y^5+5 x^4+20 x^3 y+30 x^2 y^2+20 x y^3+5 y^4+
10 x^3+30 x^2 y+30 x y^2+10 y^3+10 x^2+20 x y+10 y^2+5 x+5 y+1
Comments
Post a Comment