Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Unexpected behavior of Simplify

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63257] Re: Unexpected behavior of Simplify
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Tue, 20 Dec 2005 23:35:41 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

On 12/20/05 at 4:19 AM, gleam at flashmail.com wrote:

>What is the explanation for this behavior?

<code changed to InputForm for readability>

>In[1]:=
>ClearAll[a, b, c]
>expr = c^4*b^2 + a^4*b^2 + c^2*a^2*(1 - 2*b^2); 
>Simplify[expr]
>Simplify[expr /. {a -> b,  b -> a}] /. {a -> b, b -> a}

>Out[3]=
>b^2*a^4 + (1 - 2*b^2)*c^2*a^2 + b^2*c^4

>Out[4]=
>a^2*c^2 + b^2*(a^2 - c^2)^2

>The second application of the replacement is merely for clarity;
>the unexpected behavior is present without it.

What behaviour were you expecting? What is it you want?

Are you trying to swap a and b everywhere in the expression, i.e.,

In[5]:=
(expr/.{a->z, b->y})/. {y->a, z->b}

Out[5]=
a^2*b^4 + (1 - 2*a^2)*c^2*b^2 + a^2*c^4

Or perhaps you intended for the first rule to be applied then the second, i.e.,

In[11]:=
(expr/.a->b)/.b->a

Out[11]=
a^6 + c^4*a^2 + (1 - 2*a^2)*c^2*a^2

Clearly, the results depend on the details in which the rules are applied. I am sure this is documented in the Mathematica Book somewhere. But rather than rely on details I find difficult to recall when needed, it seems to me far better to write code to explicitly require a specific application order. In general, there isn't any significant performance hit and it is considerably easier to determine what was meant and maintain the code. 
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Unexpected behavior of Simplify
  • Next by Date: Re: Re: Replacement equivalence?
  • Previous by thread: Re: Unexpected behavior of Simplify
  • Next by thread: Re: Unexpected behavior of Simplify