MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: troubles with Transformation Rules (Version 3)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg40949] RE: [mg40928] troubles with Transformation Rules (Version 3)
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Fri, 25 Apr 2003 08:04:41 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com


>-----Original Message-----
>From: Paolo Bientinesi [mailto:pauldj at cs.utexas.edu]
To: mathgroup at smc.vnet.net
>Sent: Thursday, April 24, 2003 11:30 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg40949] [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
>

Paolo,

yes, the manual says that. But also, that each part is only transformed
once. Looking at the FullForm...

In[8]:= FullForm[exp]
Out[8]//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]]]]

In[11]:= FullForm[sub1[[1, 1]]]
Out[11]//FullForm=
Plus[C0, Times[-1, Dot[A02, f[A22, B, C2]]]]

...shows that Plus[C0, --something--, Times[-1, Dot[A02, f[A22, B, C2]]]]
has been transformed by rule sub1, such it will not be touched (as a whole)
again by rule sub2. But that transformation you desired is within that!
ReplaceRepeated of course will do that. Also don't forget that matching is
done top-down with ReplaceAll.

Using Replace will replace parts bottom-up:

In[28]:=
Replace[exp, {-A02.(f[A22, B, C2] | X3) + C0 + r___ -> X1 + r, 
    f[A22, B, C2] -> X3}, {0, Infinity}]
Out[28]=
X1 - A01.f[A11, B, C1 - A12.X3]

Here I had to modify rule sub1, as to (1) allow for match at level {0},
which is done differently as for ReplaceAll. Perhaps this is at the heart of
your understanding, and (2) also to account for a possible prior replacement
for X3. As your rules are conflicting anyhow... 

In[7]:= exp /. sub1 /. sub2
Out[7]= X1 - A01.f[A11, B, C1 - A12.X3]


...is the right way to do it (if you won't prefer a different rule set).


--
Hartmut Wolf



  • Prev by Date: Re: 3 eqns 3 unknws
  • Next by Date: Re: Displaying many digits
  • Previous by thread: Re: troubles with Transformation Rules (Version 3)
  • Next by thread: Re: Mathematica and polynomial surface fitting...