Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10718

Re: Rearranging terms - user-defined

From Andrzej Kozlowski <akozlowski@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Rearranging terms - user-defined
Date 2012-07-01 06:12 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jsopoc$115$1@smc.vnet.net> (permalink)
References <201206300919.FAA01695@smc.vnet.net>

Show all headers | View raw


On 30 Jun 2012, at 11:19, drehstuhl2@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

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Rearranging terms - user-defined Andrzej Kozlowski <akozlowski@gmail.com> - 2012-07-01 06:12 +0000

csiph-web