Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Re: Why doesn't this rule work?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32486] Re: Why doesn't this rule work?
  • From: "Ersek, Ted R" <ErsekTR at navair.navy.mil>
  • Date: Wed, 23 Jan 2002 01:00:04 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

James Jennings wanted to know why the following rule has no effect.
In[]:= c-a-b /. n1_. c+n2_. a /; n1==-n2 -> n1 b 
Out[]= -a-b+c 
---------------
I don't know why, but I can recommend some ways that do work.
In[]:=  c-a-b+d /. ((n1_.*c+n2_.*a+others_.)/; n1==-n2 )-> n1*b+others
Out[]= d


In[]:=  c-a-b+d /.{ n_.* c - n_.* a -> n*b, -n_.* c + n_.* a -> -n*b}

Out[]= d


However, neither of the above will work in a more complicated example such
as the one below. 
For a more robust solution use rule below.

In[]:=  expr=Exp[p/2+x/2]*c-Exp[(p+x)/2]*a-b+d;
     expr /.((n1_.*c+n2_.*a+others_.) /;Simplify[n1+n2]===0 )-> n1*b+others

Out[]=  -b + d + b*E^(Pi/2 + x/2)


----------
Regards,
Ted Ersek

Get Mathematica tips, tricks from
http://www.verbeia.com/mathematica/tips/Tricks.html



  • Prev by Date: Re: confusion with triple integral...
  • Next by Date: a difficult Bessel intergral
  • Previous by thread: Re: Why doesn't this rule work?
  • Next by thread: Re: Why doesn't this rule work?