With the following Simplify[Abs[-1 + x], {-1 + x < 0}], I expect Mathematica to return 1-x, but it instead gives the same Abs[-1+x] back. Why is it so?

  • $\begingroup$ Try PowerExpand or PiecewiseExpand. $\endgroup$
    – chyanog
    Aug 12 at 9:47
  • $\begingroup$ Assuming[-1 + x < 0, Abs[-1 + x] // ComplexExpand // Simplify] $\endgroup$
    – Bob Hanlon
    Aug 12 at 15:16

Probably because the simplification you are looking for would result in a "larger" expression.


In[1]:= Simplify[Abs[x], x > 0]
Out[1]= x

In[2]:= Simplify[Abs[x], x < 0]
Out[2]= Abs[x]

In[3]:= Simplify[-Abs[x], x < 0]
Out[3]= x

For Out[2], you probably expect -x. This is actually represented as Times[-1, x], which is more "complex" than Abs[x] according to the complexity measure used by Simplify. The complexity measure is based mostly on LeafCount.

There is an entire section dedicated to this very example in the documentation of Simplify, under Options -> ComplexityFunction. Please check it for more information, and for an alternative complexity function that leads to the result you wanted.

  • $\begingroup$ Yet, Simplify[Times[-1,x],x<0] does not return Abs[x] even though the latter has LeafCount 2 and the former has 3. ;) $\endgroup$
    – yarchik
    Aug 12 at 10:00
  • 3
    $\begingroup$ Yes, it probably does not ever try that transformation. We need two things to let simplification happen: (1) try that particular transformation (2) decide that the result is simpler than the starting point. $\endgroup$
    – Szabolcs
    Aug 12 at 10:04
  • 1
    $\begingroup$ Why is -x interpreted as Times[-1,x] and not Minus[x]? $\endgroup$
    – polfosol
    Aug 13 at 9:57
  • 1
    $\begingroup$ @polfosol x/4 is also interpreted as Times[1/4, x] and not as Divide[x, 4]. I don't know the reason, but my assumption has always been that this is done for canonicalization, i.e. for bringing expressions into a common, easily interpretable form. Consider this polynomial: x^3/3 - 2x^2 + 5x - 9. Look at the FullForm. It has the same structure regardless of whether coefficients are positive or negative and regardless of whether that have the form 1/a or a. This is very convenient for extracting coefficients. This is just one example of the advantages of canonicalization. $\endgroup$
    – Szabolcs
    Aug 13 at 11:15
  • $\begingroup$ @polfosol The more usual use of canonicalization is to make it easy to compare expressions, i.e. Minus[x, 1] and Plus[x, -1] are mathematically equivalent, but formally different. It is useful to bring them to the same form because detecting that they are the same becomes trivial. $\endgroup$
    – Szabolcs
    Aug 13 at 11:21

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.