# Evaluation order in polynomials

I'm confused by the evaluation order of polynomials containing division. Consider these two polynomials:

(x^2 + y) z/w    (1)
a/b              (2)


And their tree form:

TreeForm[(x^2 + y) z/w]


TreeForm[a/b]


I understand that division is x^-1 which has higher evaluation precedence. But why in the tree form, the power of w^-1 (in the first polynomial) is in the first position, while b^-1 (in the second polynomial) is in the second position?

Times has the Attributes Orderless and Flat. (Among others.)

a/b has the FullForm Times[a, Power[b, -1]]. That is already in the sorted order:

Sort[{a, Power[b, -1]}]

{a, 1/b}


And as there is only one Times the Flat attribute doesn't change anything.

However the first expression is interpreted as:

(x^2 + y) z/w // FullForm // HoldForm

Times[Plus[Power[x,2],y],Times[z,Power[w,-1]]]


And then the Times expressions are combined (for Flat) and sorted (for Orderless):

Sort @ {Plus[Power[x, 2], y], z, Power[w, -1]} // FullForm

List[Power[w,-1],Plus[Power[x,2],y],z]

• Thank you for your detailed explanation!
– Nick
Feb 1 '15 at 10:14