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


Groups > comp.soft-sys.math.mathematica > #4505 > unrolled thread

Re: More robust pattern based replacement rules?

Started byIrretrev Unable <irdeva_ble@yahoo.com>
First post2011-08-21 09:34 +0000
Last post2011-08-21 09:34 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: More robust pattern based replacement rules? Irretrev Unable <irdeva_ble@yahoo.com> - 2011-08-21 09:34 +0000

#4505 — Re: More robust pattern based replacement rules?

FromIrretrev Unable <irdeva_ble@yahoo.com>
Date2011-08-21 09:34 +0000
SubjectRe: More robust pattern based replacement rules?
Message-ID<j2qje8$d09$1@smc.vnet.net>
Daniel sent me an excellent suggestion which I thought I would pass on to the group. Daniel's email recommending PolynomialReduce[] is below.


Here's my variant of his approach:

simpMethod[expr_] := Module[{pExpr},

 pExpr = PolynomialReduce[expr, a*b - c*d, {b, d}];
 pExpr[[1]].{e} + pExpr[[2]]
]

simpMethod[a*b - c*d]
Out[54]= e

simpMethod[c*d - a*b]
Out[55]= -e

simpMethod[2*a*b - c*d]
Out[56]= c*d + 2*e

simpMethod[a*b - 2*c*d]
Out[57]= -c*d + e

simpMethod[q*a*b - r*c*d] // Simplify
Out[58]= e*q + c*d*(q - r)


--- On Tue, 8/9/11, Daniel Lichtblau <danl@wolfram.com> wrote:

> From: Daniel Lichtblau <danl@wolfram.com>
> Subject: Re: More robust pattern based replacement rules?
> To: "Irretrev Unable" <irdeva_ble@yahoo.com>
> Date: Tuesday, August 9, 2011, 1:04 PM
> 
> ----- Original Message -----
> > From: "Irretrev Unable" <irdeva_ble@yahoo.com>
> > To: mathgroup@smc.vnet.net
> > Sent: Tuesday, August 9, 2011 6:20:42 AM
> > Subject: More robust pattern based
> replacement rules?
> > 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.
> 
> PolynomialReduce might be a better function for your
> needs.
> 
> In[28]:= e1 = a*b - c*d;
> e2 = c*d - a*b;
> rule = e - (a*b - c*d);
> PolynomialReduce[e1, rule, {a, b, c, d}][[2]]
> PolynomialReduce[e2, rule, {a, b, c, d}][[2]]
> 
> Out[31]= e
> 
> Out[32]= -e
> 
> Daniel Lichtblau
> Wolfram Research
> 
> 

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web