1

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? – J. M.'s missing motivation May 23 '17 at 08: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? – Alejandro Marcos Aragon May 23 '17 at 08:35
  • 1
    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 09:14
  • 1
    "inability to understand simple replacement rules" - more of "replacement rules don't do what you think they do", actually. – J. M.'s missing motivation May 23 '17 at 09:15
  • @J.M. what happens if the replacement rule I have is non-linear? – Alejandro Marcos Aragon May 23 '17 at 09:17
  • 1
    @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 09:24

0 Answers0