# Replace doesn't replace the denominator [duplicate]

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

-

## marked as duplicate by Michael E2, Artes, Sjoerd C. de Vries, m_goldberg, R. M.♦Nov 6 '13 at 0:53

If you look at FullForm you'll see that you need {Sqrt[(t_)^2] -> t, 1/Sqrt[t_^2] -> 1/t}. – b.gatessucks Nov 5 '13 at 17:09
Yep, always use FullForm[] when a replacement doesn't work – Dr. belisarius Nov 5 '13 at 17:11
It worked. But I don't understand the concept. Let's say, we want to replace E^(1 - x[1] + x[2]) to m[1,2]. Then the replacement doesn't change E^(2 - 2 (x[1] - x[2])) even thought it should be replaced by m[1,2]^2. – dbm Nov 5 '13 at 17:27
Because FullForm[Sqrt[x]] == Power[x, Rational[1,2]] while FullForm[1/Sqrt[x]] == Power[x, Rational[-1,2]] and therefore your pattern will not match. – b.gatessucks Nov 5 '13 at 17:58
This question has an answer here: Pitfalls. Related question: Why is ReplaceAll behaving like this? – Michael E2 Nov 5 '13 at 19:02

When you have expressions you want to simplify in this way, I like to use PowerExpand. Try

PowerExpand[-((E^(2 - 2 Sqrt[(x[1] - x[2])^2]) (x[1] - x[2]))/Sqrt[(x[1] - x[2])^2])]

-

You can also use FullSimplify with an assumption that the parameters are real-valued.

FullSimplify[-((E^(2 - 2 Sqrt[(x[1] - x[2])^2]) (x[1] - x[2]))/
Sqrt[(x[1] - x[2])^2]), Assumptions->{x[1] > x[2] > 0}]

-E^(2 - 2 x[1] + 2 x[2])

-