Re: Why doesn't this rule work?

*To*: mathgroup at smc.vnet.net*Subject*: [mg32592] Re: Why doesn't this rule work?*From*: Paul Abbott <paul at physics.uwa.edu.au>*Date*: Thu, 31 Jan 2002 01:45:14 -0500 (EST)*Organization*: University of Western Australia*References*: <a2ghu1$ki$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

James Jennings wrote: > Suppose I want to simplify expressions linear in a, b, and c where a+b=c > -- something of this sort. Since your expressions are (linear) polynomials in a, b, and c, you can use PolynomialReduce to do this sort of thing automatically: In[1]:= Last[PolynomialReduce[a + b, {c - (a + b)}, {a, b, c}]] Out[1]= c In[2]:= Last[PolynomialReduce[a + b + c, {c - (a + b)}, {a, b, c}]] Out[2]= 2c In[3]:= Last[PolynomialReduce[-2 a - 2 b, {c - (a + b)}, {a, b, c}]] Out[3]= -2c In[4]:= Last[PolynomialReduce[c - a - b, {c - (a + b)}, {a, b, c}]] Out[4]= 0 > I also want to apply rules based on c-a=b > > In[]:= c-a /. n1_. c+n2_. a /; n1==-n2 -> n1 b > > Out[]= b The order of terms in the last (list) argument of PolynomialReduce determines the elimination order In[5]:= Last[PolynomialReduce[c - a, {c - (a + b)}, {a, c, b}]] Out[5]= b > Before someone suggests that I should just set c = a+b and be done with > it, my actual problem involved 12 objects like a, b, and c, where 16 > distinct triplets add up like a+b=c. I'm looking for rules that will > keep my expressions as short as possible, even if they aren't unique. You simply add all the "zero identies" to the second argument of PolynomialReduce. Cheers, Paul > > In[]:= a+b /. a+b -> c > > Out[]= c > > In[]:= a+b+c /. a+b -> c > > Out[]= 2 c > > With more complicated coefficients I can use: > > In[]:= -2 a - 2 b /. n_. a+n_. b -> n c > > Out[]= -2 c > > In[]:= -a-b+c /. n_. a+n_. b -> n c > > Out[]= 0 > > I also want to apply rules based on c-a=b > > In[]:= c-a /. n1_. c+n2_. a /; n1==-n2 -> n1 b > > Out[]= b > > The problem comes with I apply the above rule to longer expressions. > > In[]:= c-a-b /. n1_. c+n2_. a /; n1==-n2 -> n1 b > > Out[]= -a-b+c > > Why didn't that work? I had thought that since Plus[] is Orderless, my > rule ought to be applied to all pieces of my expression, but it doesn't > appear to be. -- ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia (CRICOS Provider No 00126G) 35 Stirling Highway Crawley WA 6009 mailto:paul at physics.uwa.edu.au AUSTRALIA http://physics.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________