TExcelTAD
Home › Basic Math & Pre-Algebra › Inequalities

Inequalities

An inequality compares two expressions that are not necessarily equal: one side is smaller, larger, or "at most" or "at least" the other. You solve it almost exactly like an equation, with one extra rule about negative numbers. The answer is usually a whole range of numbers rather than a single value.

The four symbols

Symbol Read as Example true statement
<< less than 3<73 < 7
>> greater than −1>−4-1 > -4
≤\le less than or equal to 5≤55 \le 5
≥\ge greater than or equal to 9≥29 \ge 2

The small end of << points at the smaller number. In code these are <, >, <= and >=.

A solution such as x<3x < 3 contains infinitely many numbers: 2, 0, −100 and 2.999 all work. On a number line it is drawn as a ray. An open circle at 3 means 3 itself is excluded (<<, >>), and a filled circle means it is included (≤\le, ≥\ge):

text
x < 3        ←———————————○        (3 not included)
x ≥ −2              ●———————————→  (−2 included)
            −3 −2 −1  0  1  2  3  4

Solving: same moves, one twist

You may add or subtract the same number on both sides, and multiply or divide by a positive number, without changing the direction:

2x+5<172x<12subtract 5x<6divide by 2 (positive, so keep <)\begin{aligned} 2x + 5 &< 17 \\ 2x &< 12 && \text{subtract 5} \\ x &< 6 && \text{divide by 2 (positive, so keep } < \text{)} \end{aligned}

Multiplying or dividing by a negative number reverses the inequality. Look at a true statement: 2<52 < 5. Multiply both sides by −1 and you get −2 and −5. On the number line −2 is to the right of −5, so the true statement is now −2>−5-2 > -5.

−3x+4≥19−3x≥15subtract 4x≤−5divide by −3: flip ≥ to ≤check x=−6: −3⋅(−6)+4=22≥19 ✓check x=0: 4≥19 × (0 is not in x≤−5, good)\begin{aligned} -3x + 4 &\ge 19 \\ -3x &\ge 15 && \text{subtract 4} \\ x &\le -5 && \text{divide by } {-3}\text{: flip } \ge \text{ to } \le \\ &\text{check } x = -6{:}\ -3 \cdot (-6) + 4 = 22 \ge 19\ \checkmark \\ &\text{check } x = 0{:}\ 4 \ge 19\ \times\ \text{(0 is not in } x \le -5\text{, good)} \end{aligned}

Tip: To check an inequality, test one number inside your answer and one outside. The inside number must make the original inequality true and the outside number must make it false.

Compound inequalities

−1≤2x+3<9-1 \le 2x + 3 < 9 means two conditions at once. Do each step to all three parts:

−1≤2x+3<9−4≤2x<6subtract 3−2≤x<3divide by 2\begin{aligned} -1 \le{} &2x + 3 < 9 \\ -4 \le{} &2x < 6 && \text{subtract 3} \\ -2 \le{} &x < 3 && \text{divide by 2} \end{aligned}

Python supports exactly this chained style, so you can test the answer for a list of numbers:

python · try it yourself
def ok(x):
    return -1 <= 2*x + 3 < 9

for x in [-3, -2, 0, 2.5, 3, 4]:
    print(f"x = {x:>4}: {ok(x)}")
x =   -3: False
x =   -2: True
x =    0: True
x =  2.5: True
x =    3: False
x =    4: False

Checking with SymPy

SymPy's solve also handles inequalities in one variable. It prints the answer as a logical statement: & means "and", and oo is SymPy's spelling of infinity (∞\infty).

python · try it yourself
from sympy import symbols, solve

x = symbols("x", real=True)
print(solve(2*x + 5 < 17, x))
print(solve(-3*x + 4 >= 19, x))
print(solve([2*x + 3 >= -1, 2*x + 3 < 9], x))
x < 6
x <= -5
(-2 <= x) & (x < 3)

In software

Inequalities are everywhere code makes a decision:

  • Bounds checks. A valid list index satisfies 0≤i<len⁡(a)0 \le i < \operatorname{len}(a). Most off-by-one bugs come from mixing up << and ≤\le at the end of a range.
  • Clamping. max(lo, min(hi, v)) forces lo≤v≤hi\text{lo} \le v \le \text{hi}, for a volume slider or a camera angle.
  • Budgets and limits. "Show free shipping if total≥50\text{total} \ge 50", "rate-limit when requests>100\text{requests} > 100 per minute".
  • Collision tests. Two boxes overlap when four inequalities hold at once (see AABB collision).

Solving an inequality tells you the exact threshold. For example, how many €7.50 items fit a €60 budget after a €4.25 delivery fee?

python · try it yourself
import math

def clamp(v, lo, hi):
    return max(lo, min(hi, v))

print([clamp(v, 0, 100) for v in [-20, 35, 140]])

# 7.5n + 4.25 <= 60  ->  n <= (60 - 4.25) / 7.5
limit = (60 - 4.25) / 7.5
print(round(limit, 3), "-> at most", math.floor(limit), "items")
[0, 35, 100]
7.433 -> at most 7 items

Because nn must be a whole number, the largest allowed value is the floor of 7.433, which is 7.

Exercises

Exercise 1: One step with a flip

Solve −4x<20-4x < 20 and give one number that satisfies it and one that doesn't.

Answer

x>−5x > -5 (for example 0 works, −6 does not).

Solution
−4x<20x>−5divide by −4, flip < to >check x=0: −4⋅0=0<20 ✓check x=−6: −4⋅(−6)=24<20 ×\begin{aligned} -4x &< 20 \\ x &> -5 && \text{divide by } {-4}\text{, flip } < \text{ to } > \\ &\text{check } x = 0{:}\ -4 \cdot 0 = 0 < 20\ \checkmark \\ &\text{check } x = -6{:}\ -4 \cdot (-6) = 24 < 20\ \times \end{aligned}

Exercise 2: Variables on both sides

Solve 3x−7≥5x+13x - 7 \ge 5x + 1.

Answer

x≤−4x \le -4

Solution
3x−7≥5x+1−2x−7≥1subtract 5x−2x≥8add 7x≤−4divide by −2, flipcheck x=−4: −19≥−19 ✓ (equal is allowed)\begin{aligned} 3x - 7 &\ge 5x + 1 \\ -2x - 7 &\ge 1 && \text{subtract } 5x \\ -2x &\ge 8 && \text{add 7} \\ x &\le -4 && \text{divide by } {-2}\text{, flip} \\ &\text{check } x = -4{:}\ -19 \ge -19\ \checkmark\ \text{(equal is allowed)} \end{aligned}

Alternatively, move the xx terms to the right side (−8≥2x-8 \ge 2x) and you never divide by a negative: −4≥x-4 \ge x, which is the same answer.

Exercise 3: Compound

Solve 4<3−x≤94 < 3 - x \le 9.

Answer

−6≤x<−1-6 \le x < -1

Solution
4<3−x≤91<−x≤6subtract 3−1>x≥−6multiply by −1, flip both signs−6≤x<−1rewrite smallest first\begin{aligned} 4 &< 3 - x \le 9 \\ 1 &< -x \le 6 && \text{subtract 3} \\ -1 &> x \ge -6 && \text{multiply by } {-1}\text{, flip both signs} \\ -6 &\le x < -1 && \text{rewrite smallest first} \end{aligned}
python · try it yourself
print([x for x in range(-8, 2) if 4 < 3 - x <= 9])
[-6, -5, -4, -3, -2]

Exercise 4: Game level threshold

A character needs at least 1000 XP for the next level. They have 340 XP and earn 45 XP per quest. Write and solve an inequality for the number of quests qq, then compute it in Python with math.ceil.

Answer

340+45q≥1000340 + 45q \ge 1000 gives q≥14.67q \ge 14.67, so 15 quests.

Solution
340+45q≥100045q≥660q≥14.666…\begin{aligned} 340 + 45q &\ge 1000 \\ 45q &\ge 660 \\ q &\ge 14.666\ldots \end{aligned}

qq must be a whole number, so we round up: 14 quests give 970 XP (not enough), 15 give 1015.

python · try it yourself
import math
q = math.ceil((1000 - 340) / 45)
print(q, 340 + 45 * (q - 1), 340 + 45 * q)
15 970 1015

Test yourself

Solve −2x>8-2x > 8.

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

Which condition describes a valid index ii for a Python list of length nn?

  1. 0<i≤n0 < i \le n
  2. 0≤i≤n0 \le i \le n
  3. 0≤i<n0 \le i < n
  4. 1≤i≤n1 \le i \le n

On a number line, how do you draw x≥2x \ge 2?

  1. Open circle at 2, ray to the left
  2. Filled circle at 2, ray to the right
  3. Open circle at 2, ray to the right
  4. Filled circle at 2, ray to the left