Re: Transformation rule problem
- To: mathgroup at smc.vnet.net
- Subject: [mg58088] Re: Transformation rule problem
- From: "Peltio" <peltio at trilight.zone>
- Date: Sat, 18 Jun 2005 06:07:40 -0400 (EDT)
- References: <d8rnfg$l4b$1@smc.vnet.net>
- Reply-to: "Peltio" <peltioNOSPAM at despammed.com.invalid>
- Sender: owner-wri-mathgroup at wolfram.com
"Oliver Buerschaper" wrote: >In a sum like for example > > a^2 b^4 + a^3 b + a^5 + a^5 b > >I'd like to replace every instance of the product (a b) by a different >expression, let's call it d. Thus my result should look like > > d^2 b^2 + a^2 d + a^5 + a^4 d Brute force to the rescue! rulen[a_, b_][d_] = a^n_*b^m_ :> d*(a^(n - 1)*b^(m - 1)); rulea[a_, b_][d_] = a*b^m_ :> d*b^(m - 1); ruleb[a_, b_][d_] = a^n_*b :> d*a^(n - 1); mySimplify[expr_, a_ b_ -> d_] := (expr //. rulen[a, b][d]) /. {rulea[a, b][d], ruleb[a, b][d]} This only works when a and b are not "mixable", i.e. they are immediately identifiable by sheer pattern matching. cheers, Peltio Invalid address in reply to. Crafty demunging required to mail me.
- Follow-Ups:
- associative arrays
- From: Ed Peschko <esp5@mdssdev05.comp.pge.com>
- associative arrays