In this question I will talk about a toy example, it should be clear what do I actually mean in general. Also, not only Factor
but also Apart
and several other important operators have this behavior.
Say, Factor[1/(1 - t)]
produces -(1/(-1 + t))
which is not just formatting but full form change: FullForm[1/(1 - t)]
is
Power[Plus[1,Times[-1,t]],-1]
while FullForm[Factor[1/(1 - t)]]
gives
Times[-1,Power[Plus[-1,t],-1]]
which I find sort of inconvenient sometimes. Not that I care about internals of representing objects, most probably it is optimized in some way, but when I need to work with such expressions, introduction of redundant extra minus signs, etc. is which I find inconvenient.
What would be the correct way to deal with this? One related question I found is How to put terms in lexicographic order? where one of possibilities named was to issue
$PrePrint = PolynomialForm[#, TraditionalOrder -> True] &;
but some adverse effects of it were also mentioned. And in fact, TraditionalOrder
is not what I would need anyway, it gives something still different, namely (in this particular case) -(1/(t-1))
.
Also, after having posted the question, I discovered in the Related column to the right another one, How do I prevent Mathematica from reformatting the expressions that I copy as LaTeX?, but also in this case I cannot really figure out whether I can use answers there for my purposes.
As suggested by bbgodfrey here is a more illustrative example. Issuing
gives
while what I would like to see is
Simplify
restores-(1/(-1 + t))
to the desired form. Perhaps, you could provide a typical expression with which you are having such problems. $\endgroup$Apart[((1-3 t^2-t w+t^2 w+5 t^3 w-t^2 w^2-2 t^3 w^2)z w)/((1-3 t^2) (1-w) (1-2 t w)(1-z w)),w]
gives-((t (1+2 t))/(2 (-1+3 t^2)))+(-z+t z)/((-1+2 t) (-1+w) (-1+z))-(t (-z+2 t^2 z))/(2 (-1+2 t) (-1+3 t^2) (-1+2 t w) (2 t-z))-(-t^2-2 t^3-t z+t^2 z+5 t^3 z+z^2-3 t^2 z^2)/((-1+3 t^2) (2 t-z) (-1+z) (-1+w z))
.Simplify
just puts it all together in this case which is not what I want, whileMap[Simplify,%]
does not change anything. $\endgroup$PolynomialForm
appears to work well in this case. As I remarked above, such work-arounds tend to be problem-specific. $\endgroup$PolynomialForm
? $\endgroup$PolynomialForm
applied to the expression in your comment above. However, you should not expect it to give you the desired form in all cases. Also, I recommend against using $PrePrint for the reasons given in How to put terms in lexicographic order. $\endgroup$