Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4288

Re: More robust pattern based replacement rules?

From Leonid Shifrin <lshifr@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: More robust pattern based replacement rules?
Date 2011-08-10 10:59 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j1tob0$pu9$1@smc.vnet.net> (permalink)
References <201108091120.HAA15815@smc.vnet.net>

Show all headers | View raw


You can do something like this:

rl = (a b v___ + c d w___) /; v == -w :> e v

So that

In[121]:= a b - c d /. rl

Out[121]= e

In[122]:= -a b + c d /. rl

Out[122]= -e


Regards,
Leonid



On Tue, Aug 9, 2011 at 3:20 PM, Irretrev Unable <irdeva_ble@yahoo.com>wrote:

> 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.
>
>

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: More robust pattern based replacement rules? Leonid Shifrin <lshifr@gmail.com> - 2011-08-10 10:59 +0000

csiph-web