       Fwd: Replacing an expression by an expression

• To: mathgroup at smc.vnet.net
• Subject: [mg55659] Fwd: [mg55625] Replacing an expression by an expression
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Fri, 1 Apr 2005 05:36:51 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Could you please remove my reply  since the OP has apparently removed
his post.

Thank you.

Andrzej

Begin forwarded message:

> From: Carlos Felippa <carlos at titan.colorado.edu>
To: mathgroup at smc.vnet.net
> Date: 31 March 2005 18:55:50 GMT+02:00
> To: Andrzej Kozlowski <akoz at mimuw.edu.pl>
> Subject: [mg55659] Re: [mg55625] Replacing an expression by an expression
>
> I have removed that post.  I realize now that
> signs do matter.  Pls do not reply & if you
> have, pls remove.   Thanks, CAF
>
>
> on 3/31/05 8:28 AM, Andrzej Kozlowski at akoz at mimuw.edu.pl wrote:
>
>> *This message was transferred with a trial version of CommuniGate(tm)
>> Pro*
>> On 31 Mar 2005, at 08:24, carlos at colorado.edu wrote:
>>
>>> I have a 8 x 8 symbolic matrix B of complicated entries.
>>> Several partial expressions, however, can be simplified. Sample:
>>>
>>> rep= {(J12*x14-J11*y14)*(J12*(x32+x43)-J11*(y32+y43)) -> A0*(A1-A0)};
>>>
>>> The left expression appears verbatim in entry B[[1,1]], which is
>>>
>>> -(L21*(J12*x14-J11*y14)*(J12*(-x32-x43)+J11*(y32+y43)))/
>>> (16*A412*J*(J11^2+J12^2))
>>>
>>> But when I say B=B/.rep, nothing happens.  For a few entries I could
>>> do
>>> cut and paste by hand:
>>>
>>> -(L21*  A0*(A1-A0)    )/
>>> (16*A412*J*(J11^2+J12^2))
>>>
>>> But it get tedious and error prone for 64.  Any suggestions on how to
>>> get Mathematica to do the replacement?
>>>
>>
>>
>> This is a common problem; the expressions that you are trying to match
>> are semantically  the same but not syntactically so (look carefully at
>> the minus coefficients of x32 and x43). In this case there is a very
>> simple solution
>>
>> In:=
>> v = -(L21*(J12*x14 - J11*y14)*(J12*(-x32 - x43) +
>> J11*(y32 + y43)))/(16*A412*J*(J11^2 + J12^2));
>>
>> In:=
>> rep = {(J12*x14 - J11*y14)*(J12*(x32 + x43) -
>> J11*(y32 + y43)) -> A0*(A1 - A0)};
>>
>> In:=
>> Simplify[v] /. Simplify[rep]
>>
>> Out=
>> (A0*(-A0 + A1)*L21)/(16*A412*J*(J11^2 + J12^2))
>>
>> but this is not guaranteed to work always in such cases (Simplify may
>> in fact rearrange the matching parts so that they no longer match).
>>
>> There is a more subtle way to do this, which should work in all
>> polynomial and rational function cases, but it can be somewhat tricky.
>> Instead of rule we define an ideal:
>>
>> b = {(J12*x14 - J11*y14)*(J12*(x32 + x43) - J11*(y32 + y43)) - A0*(A1
>> -
>> A0)};
>>
>> compute a Groebner basis:
>>
>> gg = GroebnerBasis[b];
>>
>> and then use:
>>
>>
>> Simplify[Last[PolynomialReduce[v, gg,
>> Join[Variables[v], Variables[gg]]]]]
>>
>>
>> (A0*(-A0 + A1)*L21)/(16*A412*J*(J11^2 + J12^2))
>>
>>
>> We were lucky here that the order of variables proved to be just
>> right.
>> In general we may have to try different variable orders.
>>
>> Actually, all of the above will be performed automatically by Simplify
>> with assumptions
>>
>> Simplify[v, (J12*x14 - J11*y14)*(J12*(x32 + x43) -
>> J11*(y32 + y43)) == A0*(A1 - A0)]
>>
>>
>> (A0*(-A0 + A1)*L21)/(16*A412*J*(J11^2 + J12^2))
>>
>> but again we were lucky that the default order of variables happened
>> to
>> be just right. The advantage of the first approach (using
>> PolynomialReduce) is the tone can easier control the order of the
>> variables.
>>
>>
>> Andrzej Kozlowski
>> Chiba, Japan
>> http://www.akikoz.net/andrzej/index.html
>> http://www.mimuw.edu.pl/~akoz/
>>
>
>

```

• Prev by Date: Re: symbolic quaternionic analysis
• Next by Date: Re: Much faster ConvexHull implementation
• Previous by thread: Re: Replacing an expression by an expression
• Next by thread: Re: plotting weighted graphs