10
$\begingroup$

I am using Mathematica 11.1, and I stumbled upon this strange response using the Abs function.

FullSimplify[Abs[x],x<0]
(* Abs[x] *)

while, for example

FullSimplify[Abs[x],x>0]
(* x *)

as expected.

My question: Why doesn't Mathematica simplify Abs[x] to -x when it is given the extra information x<0? Could it be on purpose?

I looked for duplicates, but I could not find a question that was spot on. I'm sorry if I missed some question.

$\endgroup$
  • $\begingroup$ according to help, Abs[z] is left unevaluated if z is not a numeric quantity So really, both cases should be left unevaluated. But looking at Reduce[Abs[x] == x] it says Re[x] >= 0 && Im[x] == 0 so it seems like this is special case where Abs[z] is simplified to z. But help says it should be unevaluated if z is not numeric! $\endgroup$ – Nasser Apr 23 '17 at 17:35
  • $\begingroup$ @Nasser Thank you for the comment. Does those "unevaluated" rules apply also when FullSimplify is applied? Maybe not. Always. It is still a bit confusing to me, if I per default have to count minus signs... $\endgroup$ – mickep Apr 23 '17 at 17:47
  • 2
    $\begingroup$ This example is discussed in the Documentation for ComplexityFunction (see > Scope there). $\endgroup$ – Shadowray Apr 23 '17 at 17:51
  • $\begingroup$ Thank you for that link @Shadowray. This confirms it is really by design. $\endgroup$ – mickep Apr 23 '17 at 17:54
  • $\begingroup$ fyi, Maple does this operation directly: !Mathematica graphics $\endgroup$ – Nasser Apr 23 '17 at 19:10
13
$\begingroup$

Mathematica considers Times[-1,x] to be a more complex expression than Abs[x].

If you change the complexity function you can get the result you expect, e.g.

FullSimplify[Abs[x], x < 0, ComplexityFunction -> (Count[#, Abs, -1] &)]
(* -x *)
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you, that is interesting. I'm a bit surprised that it then considers (for example) the output $$\frac{1}{2-x}+\frac{1}{1+|x|}$$ to be simpler than $$\frac{3-2x}{2-3x+x^2}$$ when running FullSimplify[1/(1 + Abs[x]) + 1/(1 + Abs[x - 1]), x < 0]. If one changes to 0<x<1 or x>1 as option instead, one gets rid of Abs. Appearantly, what is simpler for me is not simpler for Mathematica. Again, thank you! I will accept this answer unless someone will find a much more convincing answer in the next few days. In the meantime you have an upvote! Cheers! $\endgroup$ – mickep Apr 23 '17 at 17:45
  • $\begingroup$ @mickep Read ComplexityFunction under Properties & Relations. The system needs an objective measurement of complexity. This link will give you the definition of complexity it uses by default, and will tell you how to define your own. $\endgroup$ – Szabolcs Apr 23 '17 at 18:34
  • $\begingroup$ I guess the real question is why the expression is Times[-1,x] rather than just Negate[x] or something. It's not like the OP wrote -1*x... $\endgroup$ – user541686 Apr 23 '17 at 19:32
  • 1
    $\begingroup$ @Mehrdad That seems like a reasonable optimisation to do. It doesn't seem useful to have Negate while there is already a more general construct that suffices, and that isn't that much more complicated. $\endgroup$ – tomsmeding Apr 23 '17 at 20:00
  • 1
    $\begingroup$ @mickep For related issues see this answer: FullSimplify does not work on this expression with no unknowns. It may appear to be version dependent. $\endgroup$ – Artes Apr 24 '17 at 6:31
1
$\begingroup$

In:

Simplify[Abs[x /. x -> -y], x < 0 && y > 0 ]  /. y -> -x

Out:

-x
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.