Inequalities: the set where it holds
The solution of an inequality is a set of numbers, usually a few intervals. solveInequality finds the points where the answer can change, tests one point in each piece between them, and returns the set with its ends exact.
Using it
import { solveInequality } from "@ratmath/symbolic";
const s = solveInequality("(x - 1)/(x + 2) <= 0");
String(s); // (-2, 1]
s.pieces; // [ { lo: -2, hi: 1, loClosed: false, hiClosed: true } ]
s.contains(0); // true
s.contains(-2); // false: the quotient is undefined there
s.toRegionText(); // "-2:!x:1" Core's region notation
String(solveInequality("x^2 > 2")); // (-inf, -sqrt(2)) U (sqrt(2), inf)
String(solveInequality("abs(x - 3) < 2")); // (1, 5)
String(solveInequality("x^3 - x >= 0")); // [-1, 0] U [1, inf)
String(solveInequality("1/x < 1")); // (-inf, 0) U (1, inf)
String(solveInequality("sqrt(x) < x - 2")); // (4, inf)
String(solveInequality("x^2 < -1")); // no real number
The comparison is one of <, <=, >, >= and !=. A chain such as -3 < 2x + 1 <= 7 is read as both inequalities at once, the intersection of the two sets.
Combining sets
const a = solveInequality("x^2 < 4"), b = solveInequality("x >= 1");
String(a.intersect(b)); // [1, 2)
String(a.union(b)); // (-2, inf)
String(a.complement()); // (-inf, -2] U [2, inf)
String(solveInequality("-3 < 2x + 1 <= 7")); // (-2, 3]
intersect, union and complement put every end of both sets in order (comparing them exactly, so and are told apart and and are proven equal) and decide each end and each gap between ends separately. No end falls inside a gap, so a gap is wholly inside a set or wholly outside it.
The method of critical points
Write the inequality as with . A function built from the usual pieces can change sign only where it is zero or where it stops being continuous or defined. Those are the critical points: the solutions of , the zeros of every denominator, and the ends of the domains of roots and logarithms. Between two neighbouring critical points keeps one sign, so one test point decides the whole piece.
For the critical points are (denominator) and (zero). The three pieces give
| Piece | Test point | Value | Kept? |
|---|---|---|---|
| no | |||
| yes | |||
| no |
and then each critical point is tested on its own: gives 0, which satisfies , and is not in the domain. The answer is .
This is why a common shortcut fails. Multiplying by to get loses the negative numbers, because multiplying by a negative quantity reverses an inequality. The method of critical points never multiplies by anything whose sign is unknown.
Where the proof comes from
The critical points come from solve, and the method is only as good as that list: a missed zero would merge two pieces that should be separate. So solveInequality refuses to answer when the equation's solution is not known to be complete. Signs at test points are decided by certified evaluation at exact rational points, so a sign is never read off a rounded number.
Periodic inequalities
For an inequality with infinitely many pieces, give a range.
String(solveInequality("sin(x) > 1/2", "x", { range: [0, "2*pi"] })); // (pi/6, 5*pi/6)
solveInequality("sin(x) > 1/2");
// refuses: the inequality is periodic: give a bounded range for x, such as { range: [0, "2*pi"] }@ratmath/symbolic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.