# Simple rule appears not to work

I have the following simple code

Clear["Global*"];

V = v0^2/2*Log[x^2 + (y/q)^2 + rc^2];
sub = {(v0^2/(x^2 + (y/q)^2 + rc^2)) -> (arg)};

Vx = D[V, x];
Vy = D[V, y];

Vxx = Simplify[D[V, {x, 2}]];
Vxy = Simplify[D[Vx, y]];
Vyy = Simplify[D[V, {y, 2}]];
Vyx = Simplify[D[Vy, x]];

Print["******************************"]
Print["Vx = ", Vx //. sub]
Print["Vy = ", Vy //. sub]
Print["Vxx = ", Vxx //. sub]
Print["Vxy = ", Vxy //. sub]
Print["Vyx = ", Vyx //. sub]
Print["Vyy = ", Vyy //. sub]
Print["*****************************"]


which calculates the first and second derivatives the function $V$. The printed results I added a rule sub in order to make the output much simpler. However, for a strange reason, the rule applies correctly to the first derivatives $Vx$ and $Vy$ but it has no effect to the second ones $(Vxx, Vxy, Vyx, Vyy)$. Any ideas why?

-
Yes, because rules apply to the FullForm of an expression. If the FullForm does not match then nothing will be replaced. The pattern you use for the replacement is pretty complicated so it is not very surprising that it only matches in a few special cases. Rewrite your rule such that the left hand side is simpler and try again. – sebhofer Jul 25 '13 at 16:27

One of the best ways to diagnose pattern matching problems is look at the FullForm or TreeForm of the left-hand side of the pattern as well as the object you are attempting to match:

sub[[1, 1]] // TreeForm


Vxx // TreeForm
`

For the pattern to match the structure must be the same (or appear within the structure), and as you can see they are very different.

For the mathematical transformation I believe you are attempting these related questions may be helpful:

Replacing term by variable with Mathematica

-