What is the best way to solve an equation involving multiple absolute values?

An absolute value expression such as $|ax-b|$ can be rewritten in two cases as $|ax-b|=\begin{cases} ax-b & \text{ if } x\ge \frac{b}{a} \\ b-ax & \text{ if } x< \frac{b}{a} \end{cases}$, so an equation with $n$ separate absolute value expressions can be split up into $2^n$ cases, but is there a better way?

For example, with $|2x-5|+|x-1|+|4x+3|=13$, is there a better way to handle all the possible combinations of $x\ge\frac{5}{2}$ versus $x<\frac{5}{2}$, $x\ge 1$ versus $x< 1$, and $x\ge-\frac{3}{4}$ versus $x<-\frac{3}{4}$?

• For someone who has to solve a lot of equations of this sort, I would always recommend that the first thing to do is to make a plot of the functions of interest, if only to reckon which intervals one should be looking at. – J. M. isn't a mathematician Aug 23 '10 at 22:41
• @J. Mangaldan: The plot is also a good way to verify the answers. There are something like 24 signed-number operations involved in my algebraic solution below, so even with 99% accuracy per operation, that's only a 78.6% chance of correct calculations throughout. – Isaac Aug 23 '10 at 23:32

2 Answers

For an equation with $n$ absolute values, the $n$ places where each absolute value splits into 2 cases divide the number line into $n+1$ regions where, within each region, each absolute value can be replaced by either the expression inside the absolute value or its opposite. Each resulting equation can then be solved, restricting solutions to the corresponding region on the number line.

In the given example,

$\small{\begin{matrix} \leftarrow & -\frac{3}{4} & \text{---} & 1 & \text{---} & \frac{5}{2} & \rightarrow \\ \begin{matrix}-(2x-5)-(x-1)\\-(4x+3)=13\end{matrix} & \begin{matrix}|\\|\end{matrix} & \begin{matrix}-(2x-5)-(x-1)\\+(4x+3)=13\end{matrix} & \begin{matrix}|\\|\end{matrix} & \begin{matrix}-(2x-5)+(x-1)\\+(4x+3)=13\end{matrix} & \begin{matrix}|\\|\end{matrix} & \begin{matrix}(2x-5)+(x-1)\\+(4x+3)=13\end{matrix} \\ -7x+3=13 & | & x+9=13 & | & 3x+7=13 & | & 7x-3=13 \\ x=-\frac{10}{7} & | & x=4\notin[-\frac{3}{4},1] & | & x=2 & | & x=\frac{16}{7}\notin[\frac{5}{2},\infty) \end{matrix}}$

So, the solutions are $x=-\frac{10}{7}$ and $x=2$ (the values that were solutions to an equation for a particular region and were within that region).

• This table is too wide to display correctly for me :/ – Larry Wang Aug 24 '10 at 0:22
• @Kaestur Hakarl: Sorry--with the \small{} wrapper, it just barely fits for me, but I couldn't think of any way to make it smaller and still legible. I'm open to suggestions. – Isaac Aug 24 '10 at 0:33
• See my answer: what you propose is a special case of the CAD algorithm. – Bill Dubuque Aug 24 '10 at 0:49
• How do you determine wich expression belongs in which region? – freethinker36 Nov 15 '19 at 3:14
• @freethinker36 In the original question, $ax-b$ versus $b-ax$ depending on which side of $\frac{b}{a}$ $x$ is on. – Isaac Nov 18 '19 at 20:54

This is merely a very special case of the powerful CAD (cylindrical algebraic decomposition) algorithm for quantifier elimination in real-closed fields, e.g. see Jirstrand's paper [1] for a nice introduction.

[1] M. Jirstrand. Cylindrical algebraic decomposition - an introduction. 1995
Technical report S-58183, Automatic Control group, Department of Electrical Engineering
Linkoping University, Linkoping, Sweden.
Freely available here or here.

• I knew somebody would invoke CAD at some point; this is in fact what Mathematica uses internally for such sets, FYI. On the other hand, I can't imagine making a student do CAD manually! – J. M. isn't a mathematician Aug 24 '10 at 2:06
• In fact I implemented the CAD-related substrate in Macsyma - long before Mathematica existed - which is why I'm familiar with such. The ideas behind CAD are quite simple and certainly can be done manually for small problems like this. – Bill Dubuque Aug 24 '10 at 2:55
• ...so that's why your name was familiar! :D Macsyma really was a gem. Making a student algorithmically go through the steps of CAD for this still seems like "cruel and unusual punishment" to me though. – J. M. isn't a mathematician Aug 24 '10 at 3:01
• I think perhaps you misunderstand my comment. When I say that one can employ CAD manually I don't mean mechanically. One can employ insight to use only the simple parts of CAD needed for this problem - yielding something similar to Isaac's answer. That's hardly punishing at all. Rather, it's instructive. – Bill Dubuque Aug 24 '10 at 3:11
• When you put it that way, then I certainly agree. – J. M. isn't a mathematician Aug 24 '10 at 3:27