Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4237 > unrolled thread
| Started by | Irretrev Unable <irdeva_ble@yahoo.com> |
|---|---|
| First post | 2011-08-09 11:27 +0000 |
| Last post | 2011-08-10 10:44 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
More robust pattern based replacement rules? Irretrev Unable <irdeva_ble@yahoo.com> - 2011-08-09 11:27 +0000
Re: More robust pattern based replacement rules? Peter Pein <petsie@dordos.net> - 2011-08-10 10:44 +0000
| From | Irretrev Unable <irdeva_ble@yahoo.com> |
|---|---|
| Date | 2011-08-09 11:27 +0000 |
| Subject | More robust pattern based replacement rules? |
| Message-ID | <j1r5ir$fjs$1@smc.vnet.net> |
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.
[toc] | [next] | [standalone]
| From | Peter Pein <petsie@dordos.net> |
|---|---|
| Date | 2011-08-10 10:44 +0000 |
| Message-ID | <j1tnes$pgb$1@smc.vnet.net> |
| In reply to | #4237 |
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[1]:= sr=(v_. a b) + (w_. c d )/;w==-v:>e v Out[1]= a b v_.+c d w_./;w==-v:>e v In[2]:= a b-c d/.sr Out[2]= e In[3]:= - a b+c d/.sr Out[3]= -e should do what you want. Peter
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web