[Date Index]
[Thread Index]
[Author Index]
precedence for ReplaceAll?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg110537] precedence for ReplaceAll?
*From*: Matthias Fripp <mfripp at gmail.com>
*Date*: Thu, 24 Jun 2010 04:27:06 -0400 (EDT)
I am having trouble using ReplaceAll to replace symbols that already
have a delayed assignment.
e.g., this input:
In[287]:=
a := A c
b := B c
a /. {a -> x, b -> y}
b /. {a -> x, b -> y}
a + b /. {a -> x, b -> y}
a * b /. {a -> x, b -> y}
gives this output:
Out[289]= x
Out[290]= y
Out[291]= x + y
Out[292]= A B c^2
All of this works as expected except for the final term. I would have
expected to get the result "x y". Is there any way to force
Mathematica to produce that result?
If on the other hand the original assignment is a := A + c and b := B
+ c, I get an unexpected output for the sum, but the expected output
(x y) for the product. If I insert d instead of one of the c's, I get
various other (unpredictable) kinds of result.
My first guess is that Mathematica is doing a sort of "double
ReplaceAll", where it first tries the pattern given in the delayed
assignment, and any symbols matched by that are not tested against the
explicit ReplaceAll. But that doesn't explain why the sum works and
not the product. Am I thinking about this the wrong way?
Thanks for any help you can give!
Matthias Fripp
Prev by Date:
**Re: More about algebraic simplification**
Next by Date:
**Re: Newby Q: How to specify reals**
Previous by thread:
**Re: ContourStyle Question**
Next by thread:
**Re: precedence for ReplaceAll?**
| |