It seems that a/b
is always replaced with the form: a * b^-1
, Times[a, Power[b, -1]]
. I tried Hold
, Unevaluated
, HoldAll
and this always happens.
Thus a/b /. {Times -> Minus}
leads to a - b^-1
and any_expression /. {Divide -> Minus}
is always unchanged
How can I replace Divide
in a/b
with Minus
to get a-b
?
repl = Times[x_, Power[y_, -1]] -> x - y;
. For testing:{a/b, c a/(b d)} //. repl
$\endgroup$FullForm
of the expression. But why not just do the following:expr /. Numerator[expr]/Denominator[expr] -> Numerator[expr] - Denominator[expr]
whereexpr
is your rational expression you show. This way you do not have to worry about it. Is the above the only example you are looking to change or you have more complicated cases? !Mathematica graphics $\endgroup$