Re: Rearranging terms - user-defined
- To: mathgroup at smc.vnet.net
- Subject: [mg127123] Re: Rearranging terms - user-defined
- From: Andrzej Kozlowski <akozlowski at gmail.com>
- Date: Sun, 1 Jul 2012 02:10:15 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201206300919.FAA01695@smc.vnet.net>
On 30 Jun 2012, at 11:19, drehstuhl2 at googlemail.com 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 Then: 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