MathGroup Archive 1999

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

Search the Archive

Re: Eliminating (-1)^2

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16441] Re: Eliminating (-1)^2
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 13 Mar 1999 02:21:49 -0500
  • References: <7c5cmt$7ti@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Nicolas B.E. Sawyer wrote in message <7c5cmt$7ti at smc.vnet.net>...
>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?
>
>2) Using InputForm
>
>In[132]:=
>(-(1 - a)x - a y)^2
>
>Out[132]=
>                    2
>(-((1 - a) x) - a y)
>
>but with StandardForm
>
>In[130]:=
>\!\(\((\(-\((1 - a)\)\) x - a\ y)\)\^2\)
>
>Out[130]=
>                  2
>((-1 + a) x - a y)
>
>Why the difference in the results and why doesn't either give the
>following?
>
>                 2
>((1 - a) x + a y)
>
>Finally, since
>
>Simplify[(-x - y)^2]
>
>gives
>
>       2
>(x + y)
>
>why does
>
>Simplify[(-(1 - a)*x - a*y)^2]
>
>yield
>
>                  2
>((-1 + a) x - a y)    ?
>
>--
>Nicolas B.E. Sawyer
>
>
>Department of Electrical and Electronic Engineering,
>University of Nottingham,
>University Park,
>Nottingham,
>NG7 2RD.
>
>Tel: +44 115 9515151 ext 12028
>Fax: +44 115 9515616
>
>E-mail: nbes at eee.nottingham.ac.uk
>

Nicholas:
With
$Version
"Microsoft Windows 3.0 (April 25, 1997)"

1)
(-(1-a)x -a y)^2/.p_^2 :> (Collect[-p,x])^2

    ((1 - a)*x + a*y)^2

2) I don't get the same as you do with InputForm

(-(1 - a)x - a y)^2

    ((-1 + a)*x - a*y)^2

With regard to Simplify - the measure is largely by leaf count and we have

LeafCount[(-x-y)^2]

    9

LeafCount[(x+y)^2]

    5

but

LeafCount[((-1+a) x-a y)^2]

    12

LeafCount[((1-a) x+a y)^2]

    13

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565





  • Prev by Date: Re: Matrix Manipulation
  • Next by Date: Re: Subscripted Variables
  • Previous by thread: RE: Eliminating (-1)^2
  • Next by thread: RE: Eliminating (-1)^2