I have the result of a calculation (which is too long to mention here) and it gives
-I (t2 - t4) (((Hy vx^2 - Hx vx vy + vz (Hz vy - Hy vz)) Re[Ex] +
Hx vz^2 Re[Ey] - Ey vz^2 Re[Hx] +
vx (Hy vy Re[Ey] - Hz vz Re[Ey] + Ex vy Re[Hx]) +
vy (3 Hx vz Re[Ez] - 3 Ez vz Re[Hx]) + (-Ex vx^2 + Ex vz^2 +
vx (-Ey vy + 3 Ez vz)) Re[Hy] - Ex vy vz Re[Hz] +
vx (-3 Hy vz Re[Ez] + Ey vz Re[Hz]) +
vy^2 Real[I Ey Conjugate[Hx]]))
So, I have the following replacement rule
{f_ x_ + f_ y_ -> f (x + y), f_ x_ - f_ y_ -> f (x - y)}
If I now do
3 Hx Re[Ez] vz - 3 Ez Re[Hx] vz //. {f_ x_ + f_ y_ -> f (x + y), f_ x_ - f_ y_ -> f (x - y)}
This gives me
(3 Hx Re[Ez] - 3 Ez Re[Hx]) vz
If I do the same on the above equation the rule just gives the same thing back to me. What I want is (I have manually manipulated this to give what I want to obtain as requested.)
-I (t2 - t4) (-vx vy Abs[Ex]^2) +
vz^2 (Hx Re[Ey] - Ey Re[Hx]) +
vx vy (Hy Re[Ey] + Ex Re[Hx]) +
vy vz 3 (Hx Re[Ez] - Ez Re[Hx]) +
(-vx^2 + vz^2) (Ex Re[Hy] - Hy Re[Ex])
- vy vx Abs[Hy]^2
- vy vz (Ex Re[Hz] + Hz Re[Ex])
vx vz 3 (Hy Re[Ez] + Ez Re[Hy])
+ vx vz (Ey Re[Hz] - Hz Re[Ey]) +
vy^2 Real[I Ey Conjugate[Hx]]
My substitution rules are
replrule1 = {f_ x_ + f_ y_ -> f (x + y), f_ x_ - f_ y_ -> f (x - y)}
replrule2 = a_Complex x_ Re[y_] + b_Complex y_ Re[x_] :>
Abs[a] Real[I x Conjugate[y]] /; a == -b
replrule4 = x_ Re[y_] - y_ Re[x_] -> Real[I x Conjugate[y]]
After that substitution I also want to apply
b_Complex y_ Re[x_] + a_Complex x_ Re[y_] :> Abs[a] Real[I x Conjugate[y]] /; a == -b
Which has been a previous question of mine here.


//.then I guess that is not producing the result you want. Would you please include the exact output that you desire? – Mr.Wizard♦ Feb 11 '12 at 13:353 Hx Re[Ez] vz - 3 Ez Re[Hx] vzin the output after doing the replacement. Again I have to ask, what is the compete result that you are expecting? I am asking you to manually manipulate that complete expression into the form that you desire. I cannot otherwise understand what you expect to end up where. – Mr.Wizard♦ Feb 11 '12 at 13:533 Hx vz Re[Ez] - 3 Ez vz Re[Hx]in the output which is to me the same but maybe Mathematica sees it differently internally. – Jonas Teuwen Feb 11 '12 at 17:07