MathGroup Archive 1999

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

Search the Archive

RE: Eliminating (-1)^2

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16535] RE: [mg16402] Eliminating (-1)^2
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Tue, 16 Mar 1999 04:00:13 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

I have a slight improvement to the earlier solution I had to a question 
Nicolas B.E. Sawyer  sent in.

The question was:
------------------------

1) How do I get Mathematica to eliminate factors of (-1)^2. Specifically
I want to replace occurrences of (-(1-a)x -a y)^2 by ((1-a)x +a y)^2
within an expression?

------------------------


The replacement rule below will do what you want.
I made it a little more general.  The version below will work for any even
exponent.


In[23]:=
FactorRule=
 expr:(_+__)^n_?EvenQ:>
  (Map[-#&,Part[expr,1],1]^n/.
    Times[-1,a_,b___]:>-a*b);


In[24]:=
(-(1 -a)x - a y)^2 /.FactorRule
Out[24]=
((1 - a)*x + a*y)^2


-----------------------------

My previous version ended with the rule
   Times[-1,a_Plus,b___]:>-a*b);
The version above should work better.


Regards,
Ted Ersek


  • Prev by Date: RE: the simplest way?
  • Next by Date: Animation
  • Previous by thread: Re: Eliminating (-1)^2
  • Next by thread: Re: Re: Eliminating (-1)^2