MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

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

  • To: mathgroup at
  • Subject: [mg110880] Re: replacement x->y except in Exp[x]
  • From: Richard Fateman <fateman at>
  • Date: Sat, 10 Jul 2010 03:59:26 -0400 (EDT)
  • References: <i14aij$g0p$> <> <i16vm6$iuj$>

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.

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

And yes, this has been discussed previously, here.

  • Prev by Date: Re: FittedModel object type
  • Next by Date: Re: Any idea how to parallelize this small code
  • Previous by thread: Re: replacement x->y except in Exp[x]
  • Next by thread: Re: replacement x->y except in Exp[x]