TExcelTAD
Home › Algebra › Absolute Value Equations and Inequalities

Absolute Value Equations and Inequalities

The absolute value ∣x−a∣\lvert x - a \rvert is the distance between xx and aa on the number line, and reading it as a distance turns absolute value problems into plain geometry: ∣x−3∣=5\lvert x - 3 \rvert = 5 asks for the points 5 away from 3, and ∣x−3∣<5\lvert x - 3 \rvert < 5 asks for the points closer than that. This lesson solves both kinds by splitting them into two cases, and ends with the tolerance checks ∣x−a∣<ε\lvert x - a \rvert < \varepsilon that numeric code relies on. The arithmetic of ∣x∣\lvert x \rvert is in Absolute Value.

Equations: two cases

Since ∣u∣=k\lvert u \rvert = k (with k>0k > 0) means uu is kk units from 0, uu must be kk or −k-k:

∣2x−3∣=72x−3=7or2x−3=−72x=10or2x=−4x=5orx=−2check: ∣7∣=7 ✓∣−7∣=7 ✓\begin{aligned} &\lvert 2x - 3 \rvert = 7 \\ 2x - 3 = 7 \quad &\text{or} \quad 2x - 3 = -7 \\ 2x = 10 \quad &\phantom{\text{or}} \quad 2x = -4 \\ x = 5 \quad &\phantom{\text{or}} \quad x = -2 \\[1ex] &\text{check: } \lvert 7 \rvert = 7\ \checkmark \quad \lvert -7 \rvert = 7\ \checkmark \end{aligned}

Three possibilities depending on the right side:

Equation Solutions
∣u∣=k\lvert u \rvert = k with k>0k > 0 two: u=ku = k or u=−ku = -k
∣u∣=0\lvert u \rvert = 0 one: u=0u = 0
∣u∣=k\lvert u \rvert = k with k<0k < 0 none, a distance is never negative

Always isolate the absolute value first: 3∣x+1∣−4=83\lvert x + 1 \rvert - 4 = 8 becomes ∣x+1∣=4\lvert x + 1 \rvert = 4, so x=3x = 3 or x=−5x = -5.

When the unknown is on both sides

If the right side contains xx, it might turn out negative for a candidate, so check each one, just as with radical equations:

∣x−1∣=2x+4case 1: x−1=2x+4  →  x=−5; right side 2(−5)+4=−6<0× rejectcase 2: x−1=−(2x+4)  →  3x=−3  →  x=−1; ∣−2∣=2 and 2(−1)+4=2✓\begin{aligned} &\lvert x - 1 \rvert = 2x + 4 \\ &\text{case 1: } x - 1 = 2x + 4 \;\to\; x = -5;\ \text{right side } 2(-5) + 4 = -6 < 0 && \boldsymbol{\times}\ \text{reject} \\ &\text{case 2: } x - 1 = -(2x + 4) \;\to\; 3x = -3 \;\to\; x = -1;\ \lvert -2 \rvert = 2 \text{ and } 2(-1) + 4 = 2 && \checkmark \end{aligned}
python · try it yourself
from sympy import symbols, Eq, solve, Abs

x = symbols("x", real=True)
print(solve(Eq(Abs(2*x - 3), 7), x))
print(solve(Eq(3*Abs(x + 1) - 4, 8), x))
print(solve(Eq(Abs(x - 1), 2*x + 4), x))
print(solve(Eq(Abs(x + 2), -1), x))
[-2, 5]
[-5, 3]
[-1]
[]

The symbol is declared real=True; without it SymPy would also consider complex numbers, where Abs behaves differently.

Inequalities: inside or outside

Think distance again:

Inequality (k>0k > 0) Meaning Becomes Shape
∣u∣<k\lvert u \rvert < k closer than kk to 0 −k<u<k-k < u < k ("and") one interval
∣u∣≤k\lvert u \rvert \le k at most kk from 0 −k≤u≤k-k \le u \le k one closed interval
∣u∣>k\lvert u \rvert > k farther than kk u<−ku < -k or u>ku > k two rays
∣u∣≥k\lvert u \rvert \ge k at least kk away u≤−ku \le -k or u≥ku \ge k two rays
∣x−4∣≤3−3≤x−4≤31≤x≤7[1,7]: the points within 3 of 4∣2x+1∣>52x+1<−5or2x+1>5x<−3orx>2(−∞,−3)∪(2,∞)\begin{aligned} &\lvert x - 4 \rvert \le 3 \\ &-3 \le x - 4 \le 3 \\ &1 \le x \le 7 && [1, 7]\text{: the points within 3 of 4} \\[1ex] &\lvert 2x + 1 \rvert > 5 \\ &2x + 1 < -5 \quad \text{or} \quad 2x + 1 > 5 \\ &x < -3 \quad \text{or} \quad x > 2 && (-\infty, -3) \cup (2, \infty) \end{aligned}

Tip: "Less than" gives a "less" (bounded) answer, a single interval, solved as a compound "and" inequality. "Greater than" gives two pieces, an "or".

python · try it yourself
from sympy import symbols, solveset, Abs, S

x = symbols("x", real=True)
print(solveset(Abs(x - 4) <= 3, x, S.Reals))
print(solveset(Abs(2*x + 1) > 5, x, S.Reals))
print(solveset(Abs(x) < -2, x, S.Reals))     # never true
print(solveset(Abs(x) >= -2, x, S.Reals))    # always true
Interval(1, 7)
Union(Interval.open(-oo, -3), Interval.open(2, oo))
EmptySet
Reals

Every interval a≤x≤ba \le x \le b can be written as one absolute value: centre m=a+b2m = \frac{a + b}{2}, radius r=b−a2r = \frac{b - a}{2}, and then ∣x−m∣≤r\lvert x - m \rvert \le r. For [1,7][1, 7]: m=4m = 4, r=3r = 3.

In software: tolerance checks

Floating-point numbers are rarely exactly equal, so numeric code asks whether two values are close: ∣x−a∣<ε\lvert x - a \rvert < \varepsilon, "xx lies within ε\varepsilon of aa". This is an absolute value inequality, and it equals the interval a−ε<x<a+εa - \varepsilon < x < a + \varepsilon.

python · try it yourself
import math

x = 0.1 + 0.2
print(x == 0.3)
print(abs(x - 0.3) < 1e-9)                     # |x - a| < eps
print(math.isclose(x, 0.3))                    # relative tolerance

target, eps = 100.0, 0.5
for reading in [99.4, 99.6, 100.5, 100.49]:
    print(reading, abs(reading - target) < eps)
False
True
True
99.4 False
99.6 True
100.5 False
100.49 True

The same inequality appears as a stopping rule in iterative algorithms (stop when ∣xn+1−xn∣<10−12\lvert x_{n+1} - x_n \rvert < 10^{-12}), as a "snap to grid" test in editors (snap when the cursor is within 8 px of a gridline), as a hit test for a 1D slider, and in unit tests (pytest.approx). math.isclose uses a relative tolerance ∣x−a∣≤rel⋅max⁡(∣x∣,∣a∣)\lvert x - a \rvert \le \text{rel} \cdot \max(\lvert x \rvert, \lvert a \rvert), which works for very large and very small numbers alike.

Exercises

Exercise 1: An equation

Solve ∣3x+6∣=12\lvert 3x + 6 \rvert = 12.

Answer

x=2x = 2 or x=−6x = -6

Solution
3x+6=12  ⇒  x=23x+6=−12  ⇒  3x=−18  ⇒  x=−6\begin{aligned} 3x + 6 = 12 \;&\Rightarrow\; x = 2 \\ 3x + 6 = -12 \;&\Rightarrow\; 3x = -18 \;\Rightarrow\; x = -6 \end{aligned}

Exercise 2: Isolate first

Solve 2∣x−5∣+3=12\lvert x - 5 \rvert + 3 = 1.

Answer

No solution.

Solution
2∣x−5∣=−2∣x−5∣=−1an absolute value cannot be negative→no solution\begin{aligned} 2\lvert x - 5 \rvert &= -2 \\ \lvert x - 5 \rvert &= -1 && \text{an absolute value cannot be negative} \to \text{no solution} \end{aligned}

Exercise 3: Inside and outside

Solve (a) ∣x+3∣<4\lvert x + 3 \rvert < 4 and (b) ∣5−x∣≥2\lvert 5 - x \rvert \ge 2. Give intervals.

Answer

(a) (−7,1)(-7, 1); (b) (−∞,3]∪[7,∞)(-\infty, 3] \cup [7, \infty)

Solution
(a) −4<x+3<4  ⇒  −7<x<1(b) ∣5−x∣=∣x−5∣, so x−5≤−2 or x−5≥2  ⇒  x≤3 or x≥7\begin{aligned} &\text{(a) } -4 < x + 3 < 4 \;\Rightarrow\; -7 < x < 1 \\ &\text{(b) } \lvert 5 - x \rvert = \lvert x - 5 \rvert,\ \text{so } x - 5 \le -2 \text{ or } x - 5 \ge 2 \;\Rightarrow\; x \le 3 \text{ or } x \ge 7 \end{aligned}
python · try it yourself
from sympy import symbols, solveset, Abs, S
x = symbols("x", real=True)
print(solveset(Abs(x + 3) < 4, x, S.Reals))
print(solveset(Abs(5 - x) >= 2, x, S.Reals))
Interval.open(-7, 1)
Union(Interval(-oo, 3), Interval(7, oo))

Exercise 4: Interval to absolute value

A valid temperature is 18≤t≤2618 \le t \le 26. Write this as one absolute value inequality and code it as ok(t).

Answer

∣t−22∣≤4\lvert t - 22 \rvert \le 4

Solution

Centre 18+262=22\frac{18 + 26}{2} = 22, radius 26−182=4\frac{26 - 18}{2} = 4.

python · try it yourself
def ok(t):
    return abs(t - 22) <= 4

print([ok(t) for t in [17.9, 18, 22, 26, 26.1]])
[False, True, True, True, False]

Exercise 5: Snap to grid

An editor snaps the cursor to the nearest vertical gridline (lines every 50 px) when ∣x−nearest∣≤6\lvert x - \text{nearest} \rvert \le 6. Write snap(x) that returns the gridline if close enough and xx otherwise. Test 103, 108, 147 and 125.

Answer

100, 108, 150, 125

Solution

The nearest gridline is 50⋅round⁡(x/50)50 \cdot \operatorname{round}(x/50). For 103 it is 100 (distance 3, snap); 108 is 8 away, no snap; 147 is 3 from 150, snap; 125 is 25 from both, no snap. (Python's round sends 2.5 to the even number 2, so 125 picks 100, but it is too far away either way.)

python · try it yourself
def snap(x, step=50, radius=6):
    nearest = step * round(x / step)
    return nearest if abs(x - nearest) <= radius else x

print([snap(x) for x in [103, 108, 147, 125]])
[100, 108, 150, 125]

Test yourself

How many solutions does ∣x−7∣=0\lvert x - 7 \rvert = 0 have?

  1. None
  2. One
  3. Two
  4. Infinitely many

Which is the solution of ∣x−2∣<5\lvert x - 2 \rvert < 5?

  1. x<7x < 7
  2. x<−3x < -3 or x>7x > 7
  3. −3<x<7-3 < x < 7
  4. −7<x<3-7 < x < 3

The check abs(x - a) < 1e-9 is equivalent to:

  1. x<a−10−9x < a - 10^{-9}
  2. a−10−9<x<a+10−9a - 10^{-9} < x < a + 10^{-9}
  3. x>a+10−9x > a + 10^{-9} or x<a−10−9x < a - 10^{-9}
  4. x=ax = a exactly