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]

enter image description here


enter image description here

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

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

Sort @ {Plus[Power[x, 2], y], z, Power[w, -1]} // FullForm
| improve this answer | |
  • $\begingroup$ Thank you for your detailed explanation! $\endgroup$ – Nick Feb 1 '15 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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