How can be a fraction inside Hold replaced?
Nothing of the following works:
h = Hold[1/2 (2 + 3 + 3/7) 7];
Replace[h, 1/2 -> q, All]
Replace[h, 3/7 -> q, All]
Replace[h, Times[1, Power[2, -1]] -> q, All]
Replace[h, Times[3, Power[7, -1]] -> q, All]
(* same for all *)
Hold[1/2 (2 + 3 + 3/7) 7]
However replacing single number works:
Replace[h, 7 -> q, All]
Hold[1/2 (2 + 3 + 3/q) q]
Update
Another strange behavior:
h = ToExpression["(2+3)/6*9", InputForm, Hold];
h /. HoldPattern[1/6] -> q
Hold[1/6 (2 + 3) 9]
We see that 1/6 was not replaced.
But now copy Hold[1/6 (2 + 3) 9] from previous output paste it in another cell and append that same rule /. HoldPattern[1/6] -> q.
Hold[1/6 (2 + 3) 9] /. HoldPattern[1/6] -> q
Hold[q (2 + 3) 9]
We see that this time 1/6 was replaced but we used the same expression as is stored in h when the replacement did not occure.
h /. HoldPattern[1/2] -> q$\endgroup$