Re: Replace expressions
- To: mathgroup at smc.vnet.net
- Subject: [mg7905] Re: Replace expressions
- From: Daniel Lichtblau <danl>
- Date: Mon, 21 Jul 1997 03:21:58 -0400
- Organization: Wolfram Research, Inc.
- Sender: owner-wri-mathgroup at wolfram.com
Javier Casado wrote:
>
> I need to change expressions like this one:
>
> B^2*C^2*D
>
> with rules such:
>
> B*C -> A
>
> If I try to do that directly, it doesn`t work due to the internal
> representation of Powers. To overcome this problem, I
> have done some intermediate steps to convert the first
> expression to:
>
> Hold[B*B*C*C*D]
>
> so when I apply the referred rule it works fine the first time,
> obtaining Hold[B*C*D*A].
> But if I apply now a rule like A*B -> H, it doesn`t make the
> substitution because the order has changed.
>
> Can anyone help me to achieve what I am looking for, using
> the "Hold" approach or any other method?
>
> (I am using Mathematica 2.2, though a solution for version 3
> would be also welcomed.)
>
> Thanks in advance.
>
> Javier Casado
> jcasado at apdo.com
One can do
In[3]:= b^2*c^2*d /. AlgebraicRules[b*c-a==0, {b,c,a,d}]
2
Out[3]= a d
In[4]:= $Version
Out[4]= Linux 2.2 (June 3, 1995)
The recommended version 3 method uses PolynomialReduce.
In[4]:= $Version
Out[4]= Linux 3.0 (April 25, 1997)
In[5]:= PolynomialReduce[b^2*c^2*d, b*c-a, {b,c,a}] [[2]]
2
Out[5]= a d
The approach using AlgebraicRules will also work in version 3, but it is
neither documented nor recommended.
Daniel Lichtblau
Wolfram Research
danl at wolfram.com