Re: More robust pattern based replacement rules?
- To: mathgroup at smc.vnet.net
- Subject: [mg120778] Re: More robust pattern based replacement rules?
- From: Peter Pein <petsie at dordos.net>
- Date: Wed, 10 Aug 2011 06:44:23 -0400 (EDT)
- Delivered-to: firstname.lastname@example.org
- References: <email@example.com>
Am 09.08.2011 13:27, schrieb Irretrev Unable: > I'm trying to come up with a method for creating somewhat more robust pattern based replacement rules. I've cooked up the following simple example: > > simpRule = a b v___ - c d v___ -> e v > > a b - c d /. simpRule > > produces e > > - a b + c d /. simpRule > > produces - a b + c d > > Is there a way to write one simpRule that can handle both cases? > > (The actual rule I'm trying to create has to match more terms with a leading coefficient that is more complicated than a simple minus sign, but I figure that for an initial post I should stick with a simple question.) > > Thanks in advance. > Hi, this: In:= sr=(v_. a b) + (w_. c d )/;w==-v:>e v Out= a b v_.+c d w_./;w==-v:>e v In:= a b-c d/.sr Out= e In:= - a b+c d/.sr Out= -e should do what you want. Peter