Project 4: Inequality and Absolute-Value Region Analyzer

A self-contained deep-dive from the canonical Math from Foundations to Machine Learning curriculum.

  • Difficulty: Intermediate
  • Time: 6-12 hours
  • Language: Python (alternatives: R, Julia, JavaScript)
  • Prerequisites: Project 3
  • Source: HS P13

What You Will Build

Build a solver and visualizer for one-dimensional linear, compound, and absolute-value inequalities plus two-dimensional systems of linear constraints. The one-dimensional engine should emit interval notation, preserve open versus closed endpoints, reverse the comparison when multiplying or dividing by a negative value, and support intersection and union. Translate |x-a| < r into a distance interval and |x-a| > r into two rays. The 2D mode should sample or clip a plotting window, shade the intersection of half-planes, and verify candidate points against every original constraint.

Real World Outcome

For -3 <= 2x + 1 < 7, the tool reports [-2, 3), renders the correct closed/open endpoints, and tests boundary membership. For constraints such as x + y <= 6, x >= 0, and y >= 0, it creates a labeled feasible-region plot and exports representative inside, boundary, and outside points with pass/fail details for each inequality.

Core Question

How does solving an inequality describe a set of valid points rather than a single answer, and how do algebraic boundary rules become visible geometry?

Concepts You Must Understand First

  1. Order properties: adding preserves order; multiplying by a negative reverses it.
  2. Intervals as sets: open, closed, half-open, bounded, and unbounded intervals; unions and intersections.
  3. Absolute value as distance: |x-a| measures distance from a, producing inside or outside regions.
  4. Linear inequalities in two variables: each line divides the plane into two half-planes.
  5. Boundary semantics: strict constraints exclude the line; inclusive constraints include it.

Build Milestones

  1. Parse and normalize one-variable linear inequalities, including negative coefficients and compound chains.
  2. Represent solution sets as interval objects supporting union, intersection, membership, and stable notation.
  3. Add absolute-value patterns for <, <=, >, and >=, including impossible/whole-line cases.
  4. Render number lines and 2D feasible regions with distinct strict/inclusive boundaries.
  5. Validate results using generated point-membership tests against the original expressions.

Hints in Layers

  1. Keep endpoints and inclusion flags as structured data; do not infer them back from formatted strings.
  2. For 2D constraints, test a known point such as the origin to select which side of the boundary is valid.
  3. Use the original constraint evaluator as an oracle for plotted sample points and boundary checks.

Common Pitfalls and Debugging

  • Symptom: solving -2x < 6 gives x < -3. Cause: the sign was not reversed on division by -2. Fix: centralize inequality transformations and test negative multipliers.
  • Symptom: the report says (1, 4] but the plot fills both endpoints. Cause: inclusion flags were lost during rendering. Fix: pass boundary style directly from the interval object.
  • Symptom: shading shows the union of constraints. Cause: masks were combined with OR. Fix: a feasible system requires every constraint, so combine with AND.

Definition of Done

  • Linear, compound, and absolute-value inequalities produce correct interval sets.
  • Negative-coefficient transformations reverse order correctly.
  • Number-line plots preserve open/closed and infinite endpoints.
  • Multiple 2D constraints produce their intersection with labeled boundaries.
  • Boundary and random membership tests agree with original constraints.

Previous: Project 3 · Complete learning path · Next: Project 5