# Why is Mathematica returning Abs[-1+x] even with assumption x<1?

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?

• Try PowerExpand or PiecewiseExpand. Aug 12 at 9:47
• Assuming[-1 + x < 0, Abs[-1 + x] // ComplexExpand // Simplify] Aug 12 at 15:16

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

Examples:

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

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

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


For Out, 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.

• Yet, Simplify[Times[-1,x],x<0] does not return Abs[x] even though the latter has LeafCount 2 and the former has 3. ;) Aug 12 at 10:00
• 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. Aug 12 at 10:04
• Why is -x interpreted as Times[-1,x] and not Minus[x]? Aug 13 at 9:57
• @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. Aug 13 at 11:15
• @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. Aug 13 at 11:21