2

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

dbm
  • 1,239
  • 7
  • 21

2 Answers2

2

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])]
Jason B.
  • 68,381
  • 3
  • 139
  • 286
1

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])
bill s
  • 68,936
  • 4
  • 101
  • 191