RE: algebraic substitution rules
- To: mathgroup at smc.vnet.net
- Subject: [mg30755] RE: [mg30716] algebraic substitution rules
- From: "David Park" <djmp at earthlink.net>
- Date: Sun, 9 Sep 2001 03:26:59 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Isabelle, If you look up ReplaceAll in Help you will see that it says: "ReplaceAll looks at each part of expr, tries all the rules on it, and then goes on to the next part of expr. The first rule that applies to a particular part is used; no further rules are tried on that part, or on any of its subparts." Mathematica first looked at the entire expression and found that a_ matched. So it would have done an Expand on the entire expression if you had only used a_ :> Expand[a] instead of a_ -> Expand[a] (which gets evaluated to a -> a). After that it will make no further modifications to the entire expression or its subparts. You could do it in two steps. 1 + x^2 + x^3 + x^4 /. {x^2 -> 1 + x , x^3 -> x(1 + x) , x^4 -> (1 + x)^2} /. a_ :> Expand[a] 3 + 4*x + 2*x^2 David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ > -----Original Message----- > From: Cattiaux Isabelle [mailto:Isabelle.Cattiaux at univ-valenciennes.fr] To: mathgroup at smc.vnet.net > Sent: Saturday, September 08, 2001 2:56 AM > To: mathgroup at smc.vnet.net > Subject: [mg30755] [mg30716] algebraic substitution rules > > > > Hi, > > Could someone tell me why the first substitution rule > works and the second doesn't > > In[1]:== > 1+x^2+x^3+x^4 /. {x^2->1+x ,x^3->x(1+x) ,x^4->(1+x)^2} > > Out[1]== > 2 + x + x(1 + x)+ (1 + x)^2 > > In[78]:== > 1+x^2+x^3+x^4 /. {x^2->1+x ,x^3->x(1+x) ,x^4->(1+x)^2,a_->Expand[a]} > > Out[78]== > 1 + x^2 + x^3 + x^4 > > -- > Isabelle Cattiaux-Huillard > Universite de Valenciennes >