I have the following expression in Mathematica
-((E^(2 - 2 Sqrt[(x[1] - x[2])^2]) (x[1] - x[2]))/Sqrt[(x[1] -
x[2])^2])
I want to replace anything of the form Sqrt[t^2]
to t
. I tried
-((E^(2 - 2 Sqrt[(x[1] - x[2])^2]) (x[1] - x[2]))/
Sqrt[(x[1] - x[2])^2]) /. Sqrt[(t_)^2] -> t
But it just does the changes in the numerator and not in the denominator. What is that I am doing wrong here? Thanks in advance! -dbm
FullForm
you'll see that you need{Sqrt[(t_)^2] -> t, 1/Sqrt[t_^2] -> 1/t}
. $\endgroup$FullForm[]
when a replacement doesn't work $\endgroup$FullForm[Sqrt[x]] == Power[x, Rational[1,2]]
whileFullForm[1/Sqrt[x]] == Power[x, Rational[-1,2]]
and therefore your pattern will not match. $\endgroup$