RE: a finicky rule
- To: mathgroup at smc.vnet.net
- Subject: [mg41732] RE: [mg41714] a finicky rule
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Tue, 3 Jun 2003 07:13:14 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
>-----Original Message----- >From: Selwyn Hollis [mailto:selwynh at earthlink.net] To: mathgroup at smc.vnet.net >Sent: Monday, June 02, 2003 10:35 AM >To: mathgroup at smc.vnet.net >Subject: [mg41732] [mg41714] a finicky rule > > >Group, > >I'm having a difficult time understanding the following behavior. > >I define this rule: > > pullx := c_. + (a_.) x_^(p_.) + (b_.)x_^(q_.) -> > c + x (a x^(p-1) + b x^(q-1)) > >and it works here: > > x^3 + x^2 - 1 /. pullx > > -1 + x*(x + x^2) > >but not here: > > x^3 - x^2 - 1 /. pullx > > -1 - x^2 + x^3 > >even though the pattern matches: > > MatchQ[x^3 - x^2 - 1, pullx[[1]]] > > True > >I thought perhaps some simplification was being done on the >result, but: > > (x^2 - x)*x - 1 > > -1 + x (-x + x^2) > >Any ideas? (This is 4.1, Mac OS X.) > >Thanks. > >----- >Selwyn Hollis >http://www.math.armstrong.edu/faculty/hollis > Dear Selwyn, MatchQ doesn't tell enough. If you define In[11]:= pull[x] := c_. + (a_.) x^(p_.) + (b_.)x^(q_.) :> c + x (a x^(p - 1) + b x^(q - 1)) In[12]:= x^3 - x^2 - 1 /. pull[x] Out[12]= -1 + x*(-x + x^2) In[13]:= x^3 + x^2 - 1 /. pull[x] Out[13]= -1 + x*(x + x^2) You see it works. So we might suspect, there is a problem with matching x. In[10]:= x^3 - x^2 - 1 // FullForm Out[10]//FullForm= Plus[-1, Times[-1, Power[x, 2]], Power[x, 3]] might indicate the problem, diagnostic shows: In[7]:= pullxdiagn = c_. + (a_.) x_^(p_.) + (b_.)x_^(q_.) :> "matched: {a,b,c,x,p,q}\n" <> ToString[{a, b, c, x, p, q}, StandardForm] In[9]:= x^3 + x^2 - 1 /. pullxdiagn Out[9]= "matched: {a,b,c,x,p,q} {1, 1, -1, x, 2, 3} In fact, everything matched as intended, but... In[8]:= x^3 - x^2 - 1 /. pullxdiagn Out[8]= matched: {a,b,c,x,p,q} {1, x^2, x^3, -1, 1, 1} ...results completely scrambled. The pattern is just too vague and ambiguous! (It might be funny to compose the expression from the matched pattern variables by hand! For the pattern as well as for the transformed expression.) -- Hartmut Wolf