Suppose a simple function
f[x_,y_] = Sqrt[(x-y)^2]+Sqrt[(y-x)^2]
Knowing that $x>y>0$, without any commands like Simplify
one can obtain (x-y)
by using the Sqrt[(x-y)^2]-> (x-y)
and Sqrt[(x-y)^2]-> (x-y)
:
f[s2, m2] /. {Sqrt[(x-y)^2] -> x-y,
Sqrt[(y-x)^2] -> x-y}
This might be used for the case of complicated functions involving many terms and other, when the Simplify
command takes so much time. I tried to use it for one complicated function defined dynamically, but there was no result.
What is the reason and how to construct formal rule replacing the expressions like $\sqrt{(x-y)^2}$?
P.S. PowerExpand cripples the expression for the function...
PowerExpand
because you used it without asumptions? For your example,PowerExpand[Sqrt[(x-y)^2] + Sqrt[(y-x)^2], Assumptions-> x>y]
works well. $\endgroup$