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.

Is it possible to have terms like f[w-c] be formatted like this and not like f[-c + w]. I use Mathematica (7.0) for simplifying and manipulating terms -- so it is really annoying and unnecessarily hard to read/reason about such terms.

Things I found:

  • TraditionalForm: gives almost every time the expected result, but I have to use it manually.
share|improve this question
1  
Thanks a lot - could you post your comment as an answer? –  epsilonhalbe Aug 15 '12 at 22:27
1  
Please consider doing that kind of manipulation only when it is strictly necessary.Trying to force Mma to format expressions the way you would can be very frustrating. –  belisarius Aug 15 '12 at 23:07
    
Yeah i just found out that doing $Preprint = PolynomialFor[#, TraditionalOrder -> True] &; makes the file not open correctly but in a session it works fine. Did not know how fragile Mma was. –  epsilonhalbe Aug 17 '12 at 6:16
    
I wanted to mention that you can also use the commands Find and Replace under Edit. –  math-visitor Aug 23 '12 at 6:08

1 Answer 1

up vote 14 down vote accepted

If you want to order your terms this way but not perform the other formatting that TraditionalForm does, you might like to try the (undocumented) PolynomialForm[expr, TraditionalOrder -> True]. That will change output like this:

Expand[(x+y-1)^3]
(* -> -1+3 x-3 x^2+x^3+3 y-6 x y+3 x^2 y-3 y^2+3 x y^2+y^3 *)

into this:

PolynomialForm[%,TraditionalOrder->True]
(* -> x^3+3 y x^2-3 x^2+3 y^2 x-6 y x+3 x+y^3-3 y^2+3 y-1 *)

You will still have to apply it manually, however, unless you do something like:

$PrePrint = PolynomialForm[#, TraditionalOrder -> True] &;

If you choose to use this, you should be aware that it might interfere with the printing of certain objects and forms. TraditionalForm prints with an incorrect font, for instance, because PolynomialForm wraps the output with an additional TagBox that lacks the TraditionalForm tag. Also, some expressions that look like they should be affected by PolynomialForm aren't: it has no effect on Series objects unless you apply Normal first--but this changes the meaning of the expression as well as its presentation.

Moreover, what you see onscreen will no longer be reflective of the real structure, which may be misleading:

f[w - c]
(* -> f[w - c] *)

FullForm[%]
(* -> f[Plus[Times[-1,c],w]] *)

If you're working with Gröbner bases or similar, things could get seriously confusing. However, as long as you're aware of the limitations and don't depend (mathematically or pattern-wise) on the order of terms, it should be relatively safe to use $PrePrint in this way.


Aside: Although PolynomialForm isn't widely known (being undocumented), it's been mentioned a few times already on Mathematica.SE, as well as on MathGroup. As this is the first question dealing exclusively with this issue, I'm not sure whether it's better closed as a duplicate of a previous question, or (given that this is a common query) turned into a canonical answer. In case of the latter, I edited the title to improve searchability. Other answers, possibly commenting on the wisdom of this undertaking, would be helpful. I hope others will cast their votes, post their answers, and/or make their edits accordingly.

share|improve this answer
    
at first thanks for the great answer - I especially like it that you point out the features AND the limitations of the solution. –  epsilonhalbe Aug 16 '12 at 15:16
    
Re: your aside, I think this is a good question (with your edits) and your answer is great and could serve as the canonical answer for such questions. I wouldn't vote to close. –  rm -rf Aug 17 '12 at 1:06

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.