MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Rearranging terms - user-defined

On 30 Jun 2012, at 11:19, drehstuhl2 at wrote:

> Does anyone know how to tell mathematica the following:
> I have an expression like: a + bx -by
> and I want to factorise it like: a + b(x-y)
> BUT: I want Mathematica to show the difference (x-y) whenever possible 
(in the different calculations - not just place b outside the bracket). 
That's because equations are easier to discuss if they are written in a 
special way.

Well, in my opinion the best way is:

a + b x - b y + O[x, y]^2 // Normal

a+b (x-y)

Note that the degree of the O term should be higher than the highest 
polynomial term in your expression. This will work in fact even in non 
polynomial cases such as:

g = a + c*x^2 - 2*c*x*y + c*y^2 + 1/(x^3 - 3*x^2*y + 3*x*y^2 - y^3) + 
18*x - 18*y


Normal[g + O[x, y]^5]
a + c*(x - y)^2 + 18*(x - y) + 1/(x - y)^3

> Another example would be: using probabilities, I always want to write 
mathematica -(1-p) instead of -p+1 throughout the notebook.

Actually, that is involves a  different issue. You can't make 
Mathematica write -(1-p) instead of p-1 without using HoldForm because 
Mathematica will always evaluate

 -(p - 1)

1 - p

You can deal with this using HoldForm but in my opinion it is not worth 
it and likely eventually get you into trouble.

However, if your coefficient is something other than -1 then indeed the 
previous method will also work, for example

 -2p+2 +O[p,1]^2//Normal
 -2 (p-1)

Andrzej Kozlowski

  • Prev by Date: Re: Approximate Zero Times A Symbol
  • Next by Date: Re: Approximate Zero Times A Symbol
  • Previous by thread: Re: Rearranging terms - user-defined
  • Next by thread: Re: Rearranging terms - user-defined