Sub topic 3
Graphing Modulus Expressions and Areas Such as |x| + |y| <= k
This chapter assumes you can solve single-modulus inequalities, split expressions at critical points, and factorise quadratics.
Graphing |x| + |y| <= k
The four sign cases of x and y turn |x| + |y| = k into four line segments. Together they form a square with vertices (±k, 0) and (0, ±k). Both diagonals have length 2k, so the area is (2k · 2k)/2 = 2k². The number of integer points with |x| + |y| <= k is 2k² + 2k + 1.
k = 3
pts = sum(1 for x in range(-k, k + 1) for y in range(-k, k + 1) if abs(x) + abs(y) <= k)
print(pts, 2 * k * k + 2 * k + 1, 2 * k * k) # 25 25 18The Triangle Inequality and When Equality Holds
The triangle inequality says |a + b| <= |a| + |b|. Equality holds exactly when ab >= 0, which means a and b have the same sign or one of them is zero. A related form is |a - b| >= ||a| - |b||. For example, |x| + |x - 5| >= |x - (x - 5)| = 5, and the minimum of 5 is reached for every x in [0, 5].
Minimising Sums of Absolute Values with the Median
The sum |x - a₁| + ... + |x - aₙ| is smallest when x is the median of the points. When n is even, any x between the two middle points gives the minimum.
points = [1, 4, 7, 10]
print(min(sum(abs(x - a) for a in points) for x in range(-20, 21))) # 12, for any x in [4, 7]AM-GM for Maximum and Minimum Problems
The AM-GM inequality says that for positive a and b, (a + b)/2 >= √(ab), with equality only when a = b. Two standard uses:
- If x + y = 10, the product xy is at most 25.
- For x > 0, x + 9/x >= 6.
Both a and b must be positive. If you apply AM-GM to negative values, the bound you get is wrong.
Extreme Values of Quadratic and Related Expressions
The quadratic ax² + bx + c has its vertex at x = -b/(2a), and the extreme value there is c - b²/(4a). When a > 0 that value is a minimum, and when a < 0 it is a maximum. For example, x² - 6x + 13 = (x - 3)² + 4, so its minimum is 4, reached at x = 3.
Counting Integer Solutions Without Off-by-One Errors
| Set (a, b integers) | Integer count |
|---|---|
| [a, b] | b - a + 1 |
| (a, b) | b - a - 1 |
| [a, b) or (a, b] | b - a |
Worked example: solving |x - 3| + |x + 2| < 9 gives -4 < x < 5. The integers in that open interval are -3 through 4, so there are 8 of them.
Exam Strategy: Substitution, Option Elimination and Boundary Checks
Plug a boundary value such as 0, a critical point, or an endpoint into the condition, and you can usually eliminate two options in seconds.
Exercise
Find the area of the region |x| + |y| <= 4 and the number of integer points inside it or on its boundary.
Show answer
The area is 2(4²) = 32. The number of integer points is 2(16) + 8 + 1 = 41.
Exercise
Find the minimum of |x - 1| + |x - 2| + |x - 6|.
Show answer
The median of 1, 2 and 6 is 2. At x = 2 the sum is 1 + 0 + 4 = 5.