3
$\begingroup$

I define a simple expression $\Omega$:

x1 = m3*Sqrt[3];
y1 = 0;
x2 = Sqrt[3]/2*(2*m3 - 1);
y2 = 1/2;
x3 = x2;
y3 = -y2;

r1 = Sqrt[(x - x1)^2 + (y - y1)^2];
r2 = Sqrt[(x - x2)^2 + (y - y2)^2];  
r3 = Sqrt[(x - x3)^2 + (y - y3)^2];

Ω = (1 - 2*m3)/r1 + m3/r2 + m3/r3 + 1/2*(x^2 + y^2);

I also define some rules:

rule1 = {m3*Sqrt[3] -> x10, 1/2*Sqrt[3]*(2*m3 - 1) -> x20};
rule2 = {((x - x10)^2 + y^2) -> r10, ((x - x20)^2 + (y - 1/2)^2) -> r20,
         ((x - x20)^2 + (y + 1/2)^2) -> r30};

When I compute the first derivative with respect to $x$

Ωx = D[Ω, x];

and I try to simplify it after applying my rules; i.e.,

Simplify[Ωx /. rule1 /. rule2]

I get the following output

enter image description here

As you can see, the rules work well in the second term, while on the other hand they fail in the third and fourth term. Why?

Any suggestions on how to simplify the output according to the above-mentioned rules?

$\endgroup$
1
  • 1
    $\begingroup$ Rules are applied to expressions in FullForm. And, rule1[[2]] // FullForm does not match anything in Ωx // FullForm. $\endgroup$
    – bbgodfrey
    Commented Sep 18, 2016 at 13:25

2 Answers 2

5
$\begingroup$

As I noted in a comment above, rules are applied to expressions in FullForm. And, rule1[[2]] // FullForm does not match anything in Ωx // FullForm. Often, small changes can cause rules to work. Here, for instance, define

rule1 = {m3*Sqrt[3] -> x10, Sqrt[3]*(2*m3 - 1) -> 2 x20};

Then,

Simplify[Ωx /. rule1 /. rule2]

(* x + ((-1 + 2 m3) (x - x10))/r10^(3/2) + (m3 (-x + x20))/r20^(3/2) + 
   (m3 (-x + x20))/r30^(3/2) *)

which may be the desired form.

So why did this seemingly inconsequential change help? rule1[[2]] // FullForm as originally defined contained Rational[1,2], while Ωx // FullForm contained Rational[-1,2]. Redefining rule1[[2]] to eliminate the factor of 1/2 also eliminated this inconsistency between rule1[[2]] and Ωx. Such behavior is not uncommon.

$\endgroup$
0
$\begingroup$

I would rewrite the definitions using SetDelayed ie

x1[m3_] := m3*Sqrt[3];
y1 = 0;
x2[m3_] := Sqrt[3]/2*(2*m3 - 1);
y2 = 1/2;
x3[m3_] := x2[m3];
y3 = -y2;

r1[m3_, x_, y_] := Sqrt[(x - x1[m3])^2 + (y - y1)^2];
r2[m3_, x_, y_] := Sqrt[(x - x2[m3])^2 + (y - y2)^2];
r3[m3_, x_, y_] := Sqrt[(x - x3[m3])^2 + (y - y3)^2];

Ω[m3_, x_, y_] := (1 - 2*m3)/r1[m3, x, y] + m3/r2[m3, x, y] + 
 + m3/r3[m3, x, y] + 1/2*(x^2 + y^2);

Then, I would perform the differentiation, ie

Ωx = D[Ω[m3, x, y], x]

Then I'd notice how

MapAt[f, Ωx, {{2, 4, 1}, {3, 4, 1}, {4, 4, 1}}]

singles out the specific parts I aim to transform, and I'd take it from there.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.