1
$\begingroup$

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?

$\endgroup$

marked as duplicate by J. M. will be back soon May 23 '17 at 8:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Why not use x1 -> x2 - l1? $\endgroup$ – J. M. will be back soon May 23 '17 at 8:14
  • $\begingroup$ 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? $\endgroup$ – Alejandro Marcos Aragon May 23 '17 at 8:35
  • 1
    $\begingroup$ 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. $\endgroup$ – Kuba May 23 '17 at 9:14
  • 1
    $\begingroup$ "inability to understand simple replacement rules" - more of "replacement rules don't do what you think they do", actually. $\endgroup$ – J. M. will be back soon May 23 '17 at 9:15
  • 1
    $\begingroup$ @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. $\endgroup$ – Kuba May 23 '17 at 9:24

Browse other questions tagged or ask your own question.