MathGroup Archive 2012

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

Search the Archive

Re: Rearranging terms - user-defined

  • To: mathgroup at
  • Subject: [mg127109] Re: Rearranging terms - user-defined
  • From: "Nasser M. Abbasi" <nma at>
  • Date: Sun, 1 Jul 2012 02:05:25 -0400 (EDT)
  • Delivered-to:
  • References: <jsmgen$1mf$>
  • Reply-to: nma at

On 6/30/2012 4:21 AM, 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)

How about just simplify or collect?

In[5]:= Simplify[a+b x-b y]
Out[5]= a+b (x-y)

In[6]:= Collect[a+b x-b y,b]
Out[6]= 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.

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

I do not know how to do this, because Mathematica evaluator will
always simplify -(1-p) to -p+1, other than using HoldForm,
but then you can't use the result without releasing the Hold:

In[17]:= expr/.Plus[1,Times[-1,x_]]->HoldForm[-(1-x)]
Out[17]= -(1-p)

May be there is a way. I do not know myself now.


  • Prev by Date: Re: An easier functional way to divide each Column of matrix by a
  • Next by Date: Numerical integration over an arbitrary 2D domain
  • Previous by thread: Re: An easier functional way to divide each Column of matrix by a
  • Next by thread: Re: Rearranging terms - user-defined