Re: replacement x->y except in Exp[x]

*To*: mathgroup at smc.vnet.net*Subject*: [mg110880] Re: replacement x->y except in Exp[x]*From*: Richard Fateman <fateman at cs.berkeley.edu>*Date*: Sat, 10 Jul 2010 03:59:26 -0400 (EDT)*References*: <i14aij$g0p$1@smc.vnet.net> <201007090034.UAA21449@smc.vnet.net> <i16vm6$iuj$1@smc.vnet.net>

Andrzej Kozlowski wrote: .... > Suppose in the expression 2/3 I + x/y I you wish to replace all > fractions (that is 2/3 and x/y) by r and I by d. Without worrying about > evaluation you can do this as follows: > > > Unevaluated[Unevaluated[2/3 I + x/y I] /. HoldPattern[x_/y_] -> r] /. > HoldPattern[I] -> d > > 2 d r > >... > > > All this is perfectly reasonable, logical and a great deal easier than almost anything in an undergraduate math syllabus at a reasonable university. > > Really? So if someone gives you a basket of fruit and says to replace the apples with bananas, you explain that it is easy: First you tell that person to throw away that basket and come up with a new basket in which he has wrapped the whole basket in a layer of aluminum foil. You then replace "apple-wrapped-in-foil" by banana. You then proclaim the problem solved. Unfortunately, if I give you an already unwrapped basket of fruit, it is impossible. (that is, an already simplified Mathematica expression) Which is presumably the usual state of the basket. Here is another way. Fix the pattern matching in Mathematica by changing the way the rules are matched so you don't have to do this nonsense. Here is another way.(2) Provide an alternative matcher. Here is another way (3). Use the pattern matching as given, but run the rules through a transformer so that I->d becomes Complex[k_, j_] -> d j + k. And x_/y_ -> r becomes {Rational[x_/y_]->r, x_ /y_ -> r} A discussion and partial definition of BetterRules, a Mathematica program that does things like this, is in http://www.cs.berkeley.edu/~fateman/papers/better-rules.pdf And yes, this has been discussed previously, here.

**References**:**Re: replacement x->y except in Exp[x]***From:*AES <siegman@stanford.edu>