TExcelTAD
Home › Algebra › Solving Inequalities

Solving Inequalities

An inequality such as 3x−4<113x - 4 < 11 describes a whole range of numbers rather than a single value. It is solved almost exactly like an equation, with one extra rule: multiplying or dividing both sides by a negative number reverses the direction of the inequality sign. This lesson explains the rule, the ways to write the answer, and how inequalities show up as range checks and clamping in code. The first look is Inequalities in Basic Math.

The symbols

Symbol Read as Boundary included? Interval for "x…3x \ldots 3"
x<3x < 3 less than no (−∞,3)(-\infty, 3)
x≤3x \le 3 less than or equal to yes (−∞,3](-\infty, 3]
x>3x > 3 greater than no (3,∞)(3, \infty)
x≥3x \ge 3 greater than or equal to yes [3,∞)[3, \infty)

In interval notation, a round bracket ( ) means the endpoint is excluded and a square bracket [ ] means it is included. ∞\infty always gets a round bracket, since it is not a number. On a number line, an open circle ○ marks an excluded endpoint and a filled circle ● an included one.

The rules

You may do these to both sides without changing the direction:

  • add or subtract any number,
  • multiply or divide by a positive number.

If you multiply or divide by a negative number, flip the sign: << becomes >>, ≤\le becomes ≥\ge.

Why? Multiplying by −1 mirrors the number line. 2<52 < 5 is true, but −2<−5-2 < -5 is false: after mirroring, −2 is to the right of −5, so −2>−5-2 > -5.

python · try it yourself
a, b = 2, 5
print(a < b)            # True
print(-a < -b)          # False: the order reversed
print(-a > -b)          # True after flipping the sign
print(a / -1 > b / -1)  # dividing by a negative flips too
True
False
True
True

Worked examples

3x−4<113x<15add 4x<5divide by 3 (positive, no flip)answer: (−∞,5)\begin{aligned} 3x - 4 &< 11 \\ 3x &< 15 && \text{add 4} \\ x &< 5 && \text{divide by 3 (positive, no flip)} \\ &\text{answer: } (-\infty, 5) \end{aligned}
7−2x≥13−2x≥6subtract 7x≤−3divide by −2: FLIP ≥ to ≤answer: (−∞,−3]check x=−4: 7+8=15≥13 ✓check x=0: 7≥13 × (0 is not in the set) ✓\begin{aligned} 7 - 2x &\ge 13 \\ -2x &\ge 6 && \text{subtract 7} \\ x &\le -3 && \text{divide by } {-2}\text{: FLIP } {\ge} \text{ to } {\le} \\ &\text{answer: } (-\infty, -3] \\[1ex] &\text{check } x = -4{:}\ 7 + 8 = 15 \ge 13\ \checkmark \qquad \text{check } x = 0{:}\ 7 \ge 13\ \boldsymbol{\times}\ (0 \text{ is not in the set})\ \checkmark \end{aligned}
5(x−1)>2x+75x−5>2x+73x>12x>4answer: (4,∞)\begin{aligned} 5(x - 1) &> 2x + 7 \\ 5x - 5 &> 2x + 7 \\ 3x &> 12 \\ x &> 4 && \text{answer: } (4, \infty) \end{aligned}

Tip: To check an inequality, test one number inside your answer (it should work) and one outside (it should fail). Testing the boundary itself tells you whether it belongs.

You can avoid dividing by a negative altogether by moving the xx terms to the side where the coefficient stays positive: 7−2x≥137 - 2x \ge 13 becomes 7−13≥2x7 - 13 \ge 2x, so −3≥x-3 \ge x, the same answer.

SymPy's solveset gives the interval directly, and reduce_inequalities gives it as a condition:

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

x = symbols("x")
print(solveset(3*x - 4 < 11, x, S.Reals))
print(solveset(7 - 2*x >= 13, x, S.Reals))
print(solveset(5*(x - 1) > 2*x + 7, x, S.Reals))
print(reduce_inequalities(7 - 2*x >= 13, x))
Interval.open(-oo, 5)
Interval(-oo, -3)
Interval.open(4, oo)
(-oo < x) & (x <= -3)

Interval(-oo, -3) is SymPy's way to print (−∞,−3](-\infty, -3]: the ∞\infty end is never actually included.

In software: validation and clamping

Inequalities are the language of input validation. A form that accepts an age of at least 13 checks age >= 13; a budget field that must not exceed the balance checks amount <= balance. Solving an inequality tells you the valid range of an input, for example "how many items can I buy for €50 if shipping is €4.50 and items are €6.50?": 6.5n+4.5≤506.5n + 4.5 \le 50 gives n≤7n \le 7, so at most 7.

Clamping forces a value into a range, which is two inequalities enforced at once: the result is the nearest value vv with lo≤v≤hi\text{lo} \le v \le \text{hi}.

python · try it yourself
def clamp(v, lo, hi):
    return max(lo, min(v, hi))

for v in [-12, 40, 130]:
    print(v, "->", clamp(v, 0, 100))

# most items for 50 euros: 6.5n + 4.5 <= 50  ->  n <= 7
n_max = int((50 - 4.5) // 6.5)
print("max items:", n_max, "cost:", 6.5 * n_max + 4.5)
-12 -> 0
40 -> 40
130 -> 100
max items: 7 cost: 50.0

Volume sliders, health bars, camera angles and colour channels (0–255) are all clamped. In a game loop, health = clamp(health + heal, 0, max_health) is an inequality guarantee that a later lesson, Compound Inequalities, writes as 0≤health≤max_health0 \le \text{health} \le \text{max\_health}.

Exercises

Exercise 1: Basic

Solve 4x+9≤14x + 9 \le 1 and write the answer in interval notation.

Answer

x≤−2x \le -2, that is (−∞,−2](-\infty, -2]

Solution
4x≤−8x≤−2\begin{aligned} 4x &\le -8 \\ x &\le -2 \end{aligned}

Dividing by +4 does not flip the sign, even though the right side is negative. Only the sign of the number you divide by matters.

Exercise 2: Negative coefficient

Solve 10−3x>4x−1110 - 3x > 4x - 11.

Answer

x<3x < 3, that is (−∞,3)(-\infty, 3)

Solution
10−7x>−11subtract 4x−7x>−21subtract 10x<3divide by −7, flipcheck x=0: 10>−11 ✓check x=5: −5>9 × ✓\begin{aligned} 10 - 7x &> -11 && \text{subtract } 4x \\ -7x &> -21 && \text{subtract 10} \\ x &< 3 && \text{divide by } {-7}\text{, flip} \\[1ex] &\text{check } x = 0{:}\ 10 > -11\ \checkmark \qquad \text{check } x = 5{:}\ -5 > 9\ \boldsymbol{\times}\ \checkmark \end{aligned}

Exercise 3: A budget

A gym membership costs €30 a month, or €12 a month plus €4 per class. For how many classes per month is the second option cheaper?

Answer

Fewer than 4.5 classes, so at most 4 classes a month.

Solution
12+4c<304c<18c<4.5\begin{aligned} 12 + 4c &< 30 \\ 4c &< 18 \\ c &< 4.5 \end{aligned}

Classes are whole numbers, so c≤4c \le 4. At 5 classes it costs €32, more than €30.

python · try it yourself
from sympy import symbols, solveset, S
c = symbols("c")
print(solveset(12 + 4*c < 30, c, S.Reals))
print([n for n in range(8) if 12 + 4*n < 30])
Interval.open(-oo, 9/2)
[0, 1, 2, 3, 4]

Exercise 4: A validator

Write valid_quantity(q) that accepts whole numbers qq with 1≤q≤991 \le q \le 99 and rejects everything else. Test it on 0, 1, 99, 100 and 2.5.

Answer

False, True, True, False, False

Solution
python · try it yourself
def valid_quantity(q):
    return isinstance(q, int) and 1 <= q <= 99

print([valid_quantity(q) for q in [0, 1, 99, 100, 2.5]])
[False, True, True, False, False]

Test yourself

Solve −4x<20-4x < 20.

  1. x<−5x < -5
  2. x>−5x > -5
  3. x<5x < 5
  4. x>5x > 5

Which interval means 'xx is at least 2'?

  1. (2,∞)(2, \infty)
  2. [2,∞)[2, \infty)
  3. (−∞,2](-\infty, 2]
  4. (−∞,2)(-\infty, 2)

What does clamp(v, 0, 255) return for v = 300?

  1. 300
  2. 0
  3. 255
  4. 45