# replacement rules don't account for signs [duplicate]

I would like to make a single replacement rule that disregards the sign. I have the following expression:

cond = -((-(2 + s^2) (E2 (x1 - x2) + E1 (x2 - x3)) + Sqrt[(2 + s^2)^2 (E2 (x1 - x2) + E1 (x2 - x3))^2 - 32 E1 E2 s^2 (x1 - x2) (x2 - x3)])/((2 + s^2) (E2 (x1 - x2) + E1 (x2 - x3)) + Sqrt[(2 + s^2)^2 (E2 (x1 - x2) + E1 (x2 - x3))^2 - 32 E1 E2 s^2 (x1 - x2) (x2 - x3)]))


I would like to simplify this expression, but if I make a replacement rule like

cond/.{x2-x1 -> l1}


this does nothing because it doesn't realize that x1-x2 = -l1. Is there a way to solve this?

• Why not use x1 -> x2 - l1? May 23 '17 at 8:14
• This was an example that showed Mathematica's inability to understand simple replacement rules. If I want to do a more complicated replacement then what you suggest would work, would it? May 23 '17 at 8:35
• The bottom line is that ReplaceAll isn't meant to work for math formulas this way. Solve/Eliminate/Reduce etc are. Or you can use x1 -> x2 - l1 to overcome Replacement limitations. For general approach check the link, have you? hard to say without examples, all problems of the same 'class' should be solvable by a solution that works for one of them.
– Kuba
May 23 '17 at 9:14
• "inability to understand simple replacement rules" - more of "replacement rules don't do what you think they do", actually. May 23 '17 at 9:15
• @AlejandroMarcosAragon you clearly didn't read/check links in the duplicate question. Apart of that, nonlinearity is not a problem, the bottle neck is what Solve/Eliminate/Reduce can do.
– Kuba
May 23 '17 at 9:24