Re: troubles with Transformation Rules (Version 3)
- To: mathgroup at smc.vnet.net
- Subject: [mg40951] Re: [mg40928] troubles with Transformation Rules (Version 3)
- From: Bobby Treat <drmajorbob+MathGroup3528 at mailblocks.com>
- Date: Fri, 25 Apr 2003 08:05:10 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Look at the FullForm of exp and sub1: exp = -A01.f[A11, B, -A12.f[A22, B, C2] + C1] - A02.f[A22, B, C2] + C0; % // FullForm Plus[C0, Times[-1, Dot[A01, f[A11, B, Plus[C1, Times[-1, Dot[A12, f[A22, B, C2]]]]]]], Times[-1, Dot[A02, f[A22, B, C2]]]] sub1 = {-A02.f[A22, B, C2] + C0 -> X1}; sub2 = {f[A22, B, C2] -> X3} ; sub1 // FullForm List[Rule[Plus[C0, Times[-1, Dot[A02, f[A22, B, C2]]]], X1]] and you'll see that the thing you're substituting for isn't there in "exp". That's because the arithmetic is rearranged the way Mathematica likes it. Here's what you need to do: sub1 = {C0 -> X1 + A02.f[A22, B, C2]}; sub2 = {f[A22, B, C2] -> X3} ; and either of these: exp //. Join[sub1, sub2] exp /. sub1 /. sub2 But these don't work: exp /. Join[sub1, sub2] exp /. sub2 /. sub1 You could also do it this way: sub1 = {C0 -> X1 + A02.X3}; sub2 = {f[A22, B, C2] -> X3} ; and then all these work: exp /. Join[sub1, sub2] exp /. sub2 /. sub1 exp /. sub1 /. sub2 Bobby -----Original Message----- From: Paolo Bientinesi <pauldj at cs.utexas.edu> To: mathgroup at smc.vnet.net Subject: [mg40951] [mg40928] troubles with Transformation Rules (Version 3) Hello, could anyone explain the following please? Given exp = -A01.f[A11, B, -A12.f[A22, B, C2] + C1] - A02.f[A22, B, C2] + C0 and sub1={-A02.f[A22,B,C2]+C0->X1} sub2={f[A22,B,C2]->X3} I want to express exp in terms of X1 and X3. The expression exp /. Join[sub1,sub2] returns X1-A01.f[A11,B,C1-A12.f[A22,B,C2]] against the expected X1-A01.f[A11,B,C1-A12.X3] (the manual says that each transf. rule is applied to to each part of the expression) Notice also that exp /. Join[sub2,sub1] returns the same X1-A01.f[A11,B,C1-A12.f[A22,B,C2]] while both exp/.sub1/.sub2 and exp //. Join[sub1,sub2] return the expected X1-A01.f[A11,B,C1-A12.X3] I am using Mathematica 3 thanks -- Paolo pauldj at cs.utexas.edu paolo.bientinesi at iit.cnr.it