       Re: Unexpected behavior of Simplify

• To: mathgroup at smc.vnet.net
• Subject: [mg63257] Re: Unexpected behavior of Simplify
• 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:=
>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=
>b^2*a^4 + (1 - 2*b^2)*c^2*a^2 + b^2*c^4

>Out=
>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:=
(expr/.{a->z, b->y})/. {y->a, z->b}

Out=
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:=
(expr/.a->b)/.b->a

Out=
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