MathGroup Archive 2002

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

Search the Archive

Why doesn't this rule work?

  • To: mathgroup at
  • Subject: [mg32447] Why doesn't this rule work?
  • From: James Jennings <djeimz at>
  • Date: Mon, 21 Jan 2002 02:54:59 -0500 (EST)
  • Sender: owner-wri-mathgroup at

Suppose I want to simplify expressions linear in a, b, and c where a+b=c 
-- something of this sort.

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.


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.


  • Prev by Date: RE: combining lists
  • Next by Date: Re: Simplify with assumptions
  • Previous by thread: Programming question
  • Next by thread: Re: Why doesn't this rule work?