Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4505
| From | Irretrev Unable <irdeva_ble@yahoo.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: More robust pattern based replacement rules? |
| Date | 2011-08-21 09:34 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j2qje8$d09$1@smc.vnet.net> (permalink) |
| References | <1313198560.22381.YahooMailClassic@web45110.mail.sp1.yahoo.com> |
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
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: More robust pattern based replacement rules? Irretrev Unable <irdeva_ble@yahoo.com> - 2011-08-21 09:34 +0000
csiph-web