Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
3  
Orderless entities are placed in the same order that Sort uses. Sort works with very general expressions and has no notion of "polynomialhood". You might try using TraditionalForm on your expression, as that will often display polynomials, at least univariate ones, in the order you expect. –  Daniel Lichtblau Sep 27 '13 at 20:39
1  
You can preform all calculations before applying TraditionalForm. –  ybeltukov Sep 27 '13 at 21:25
    
For two reasons, it's actually more natural to write a polynomial in terms of ascending powers of the variable x instead of the more usual, traditional notation with descending powers: (1) a polynomial is a special case of a power series, and power series are written with ascending powers of x; and (2) ascending powers lead more readily to the computationally efficient Horner's form a0 + x(a1 + x(a2 + x(...}) ...). –  murray Sep 28 '13 at 20:13
add comment

1 Answer

up vote 5 down vote accepted

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
share|improve this answer
    
I like your solution! I must say that I don't understand how your function works, I don't know much about anything that uses the # symbol in Mathematica yet, but it does order things well. The only downside is that it seems like calculations cannot be done until converted back to StandardForm. Is there a way around that? –  Brendan Sep 27 '13 at 23:15
2  
@Brendan There is great compilation about such symbols: What the @#%^&*?! do all those funny signs mean?. You don't need to perform calculations on converted expressions (TraditionalForm, OrderedForm, etc.). Just convert only the final result. If you want to see intermediate results use something like (p3=p1+p2)//OrderedForm. –  ybeltukov Sep 27 '13 at 23:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.