Why This Matters
Not every question has a single answer. When you ask "which values of x make 2x + 1 less than 9?" the answer is a range: every x below 4. An inequality uses symbols like less-than and greater-than to describe relationships where one side is not necessarily equal to the other. Inequalities model constraints, bounds, and thresholds -- the kind of conditions that appear in every real system.
Mathematicians write solution sets using interval notation like (-infinity, 4) to describe all numbers less than 4, or [2, 7] to include both endpoints. Visualizing these solutions on a number line -- with open circles for excluded endpoints and closed circles for included ones -- makes the answer concrete and easy to understand.
In programming, inequalities are everywhere: if-else conditions, loop bounds, input validation, and range checks. Understanding how to solve and combine inequalities gives you the mathematical foundation for reasoning about when code paths execute and what values are valid.
Define Terms
Visual Model
The full process at a glance. Click Start tour to walk through each step.
Solving an inequality works like solving an equation, but watch out for the flip rule when multiplying by negatives.
Code Example
// Solve ax + b < c (or >, <=, >=)
function solveInequality(a, b, c) {
const boundary = (c - b) / a;
// If a is negative, the direction flips
const direction = a > 0 ? "<" : ">";
return { boundary, direction };
}
const result = solveInequality(2, 1, 9);
console.log(`x ${result.direction} ${result.boundary}`); // x < 4
// Check if a value satisfies an inequality
function satisfies(x, boundary, direction) {
if (direction === "<") return x < boundary;
if (direction === ">") return x > boundary;
if (direction === "<=") return x <= boundary;
if (direction === ">=") return x >= boundary;
}
console.log("x=3:", satisfies(3, 4, "<")); // true
console.log("x=4:", satisfies(4, 4, "<")); // false
console.log("x=5:", satisfies(5, 4, "<")); // false
// Compound inequality: low <= x < high
function inRange(x, low, high, lowInclusive, highInclusive) {
const leftOk = lowInclusive ? x >= low : x > low;
const rightOk = highInclusive ? x <= high : x < high;
return leftOk && rightOk;
}
console.log("\n2 <= x < 7:");
console.log("x=2:", inRange(2, 2, 7, true, false)); // true
console.log("x=5:", inRange(5, 2, 7, true, false)); // true
console.log("x=7:", inRange(7, 2, 7, true, false)); // false
console.log("x=1:", inRange(1, 2, 7, true, false)); // falseInteractive Experiment
Try these exercises:
- Solve negative 3x + 6 is greater than 0. Does the inequality sign flip? What is the solution set?
- Write a compound inequality for "x is between -2 and 5, inclusive on both ends." Express it in interval notation.
- Test 10 random integers from -5 to 10 against the inequality 2x - 3 is at least 7. Which ones pass?
- What happens when you have 0x + 5 is greater than 3? Is this always true, never true, or sometimes true?
Quick Quiz
Coding Challenge
Write a function called `satisfiesCompound` that takes a value x, a lower bound, an upper bound, and two booleans (lowerInclusive and upperInclusive). Return true if x falls within the specified range. For example, satisfiesCompound(5, 2, 8, true, false) checks if 5 is in [2, 8) and should return true.
Real-World Usage
Inequalities define boundaries and constraints in every domain:
- Input validation: Checking that a user age is at least 0 and at most 150, or that a password length is at least 8.
- Array bounds: Ensuring an index i satisfies 0 through array.length - 1 prevents out-of-bounds errors.
- Game physics: Collision detection checks if coordinates fall within bounding boxes defined by compound inequalities.
- Database queries: SQL WHERE clauses like
price BETWEEN 10 AND 50are compound inequalities. - Resource limits: Rate limiters check if requests_this_minute is below max_allowed before permitting an API call.