Re: Replacement gyrations

*To*: mathgroup at smc.vnet.net*Subject*: [mg55899] Re: [mg55872] Replacement gyrations*From*: Daniel Lichtblau <danl at wolfram.com>*Date*: Sat, 9 Apr 2005 03:55:51 -0400 (EDT)*References*: <200504080537.BAA25184@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

carlos at colorado.edu wrote: > A Solve for 4 variables W11,W12,W21,W22 produces, after Simplify > > Wsol={{W11 -> (A2*x21 + A1*x32)/(L86^2*(-(x32*y21) + x21*y32)), > W12 -> (A2*y21 + A1*y32)/(-(L86^2*x32*y21) + L86^2*x21*y32), > W21 -> (A2*x21 + A1*x32)/(L75^2*(-(x32*y21) + x21*y32)), > W22 -> (A2*y21 + A1*y32)/(-(L75^2*x32*y21) + L75^2*x21*y32)}} > > Question 1: why do L86^2 and L75^2 come out as a factor in two > expression denominators and not in the others? Seems a random event. This is in the nature of the beast. I'm pretty sure such vagaries have been discussed on MathGroup several times over the years. My guess as to cause in this particular case would be that FactorSquareFree was used on an earlier form that reduced leaf count but did not get to the form you indicate above. (Had it been utilized later it would have lowered leaf counts by pulling out those factors in all cases. That's what leads me to surmise that it is used relatively earlier in the Simplify canon.) > This uncertainty inhibits the action of further replacement rules such > as > (-(x32*y21) + x21*y32) -> 2*A123 > > which works on W11 and W21 only. We've discussed this before. You are attempting to do algebraic replacement. That is not reliably accomplished with syntactic replacement rules. That is to say, the issue is actually one of user error in expectations rather than uncertainty in expression form, because the behavior you indicate is very much as designed. So how to accomplish algebraic replacement? Below is an enhanced version of what I showed last week at http://forums.wolfram.com/mathgroup/archive/2005/Apr/msg00026.html replacementFunction[expr_,rep_,vars_] := With[ {num=Numerator[expr],den=Denominator[expr]}, If [PolynomialQ[num,vars] && PolynomialQ[den,vars], PolynomialReduce[num, rep, vars][[2]] / PolynomialReduce[den, rep, vars][[2]] , expr] ] In your example we have Wsol={W11 -> (A2*x21 + A1*x32)/(L86^2*(-(x32*y21) + x21*y32)), W12 -> (A2*y21 + A1*y32)/(-(L86^2*x32*y21) + L86^2*x21*y32), W21 -> (A2*x21 + A1*x32)/(L75^2*(-(x32*y21) + x21*y32)), W22 -> (A2*y21 + A1*y32)/(-(L75^2*x32*y21) + L75^2*x21*y32)}; exprs = {W11,W12,W21,W22} /. Wsol; In[31]:= InputForm[Map[replacementFunction[#, (-(x32*y21) + x21*y32)-2*A123, Variables[expr]]&, exprs]] Out[31]//InputForm= {(A2*x21 + A1*x32)/(2*A123*L86^2), (A2*y21 + A1*y32)/(2*A123*L86^2), (A2*x21 + A1*x32)/(2*A123*L75^2), (A2*y21 + A1*y32)/(2*A123*L75^2)} > Question 2: I tried Collect [Wsol,{L86,L75}] to try to force grouping > of L86^2 and L75^2, but it has no effect. > Do I need to say Wsol=Wsol*L86^2*L75^2, Simplify, replace and finally > Wsol=Wsol/L86^2*L75^2 ? Or fool around with Numerator and Denominator? Offhand I see no good way around working explicitly with Numerator and Denominator. Strictly speaking one should preprocess via Together. I did not do that only to show that PolynomialReduce did not need to have L75^2 and L86^2 factored out in order to work. If you really want to use Collect and avoid Numerator and Denominator you can use MapAll as below. MapAll[Collect[#,{L86,L75}]&, exprs] This will have the effect of factoring out those L's from denominators. Daniel Lichtblau Wolfram Research

**References**:**Replacement gyrations***From:*carlos@colorado.edu