Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg63257] Re: Unexpected behavior of Simplify
  • From: Bill Rowe <readnewsciv at>
  • Date: Tue, 20 Dec 2005 23:35:41 -0500 (EST)
  • Sender: owner-wri-mathgroup at

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

>What is the explanation for this behavior?

<code changed to InputForm for readability>

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

>b^2*a^4 + (1 - 2*b^2)*c^2*a^2 + b^2*c^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.,

(expr/.{a->z, b->y})/. {y->a, z->b}

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.,


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