MathGroup Archive 2005

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

Search the Archive

Re: Replacing an expression by an expression

carlos at 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?

Your notion of verbatim might need some tuning. Those expressions, while 
mathematically equivalent, do not evaluate to the same thing (look at 
placement of minus signs).

Algebraic replacement comes up from time to time, e.g. in

Here is the tactic noted in that post.

replacementFunction[expr_,rep_,vars_] := If [
    PolynomialQ[Numerator[expr],vars] &&
      PolynomialReduce[expr, rep, vars][[2]], expr]

expr = -(L21*(J12*x14-J11*y14)*(J12*(-x32-x43)+J11*(y32+y43)))/

rep = (J12*x14-J11*y14)*(J12*(x32+x43)-J11*(y32+y43))-A0*(A1-A0);

InputForm[replacementFunction[expr, rep, Variables[expr]]]

(-((A0^2*L21)/(A412*J*(J11^2 + J12^2))) +
   (A0*A1*L21)/(A412*J*(J11^2 + J12^2)))/16

Daniel Lichtblau
Wolfram Research

  • Prev by Date: Re: Simplifying Jacobian elliptic functions
  • Next by Date: Re: plotting weighted graphs
  • Previous by thread: Re: Replacing an expression by an expression
  • Next by thread: Re: Replacing an expression by an expression