Graphs and features
for expressions in calculator notation, with parameters, and the points that matter: zeros, poles, holes, maxima and minima, inflection points and the ends of the domain.
Expressions
The parser reads + - * / ^, parentheses, implicit multiplication after a number (2x, 3(x+1)), decimals as exact rationals (0.1 is ), the constants pi and e, and sin cos tan exp ln log sqrt abs min max. Any other name is a parameter, given in the params object as a number, a string such as "3/4", or a Core Rational.
const vp = viewport({ x: [-8, 8], y: [-6, 6], width: 480, height: 360 });
const g = graph("a*sin(b*x) + c*x", { a: 2, b: 1, c: "1/4" }, vp);
g.exact().tight; // true when every column reached two rows or fewer
Features
features(f, params, [a, b]) returns a Refinement whose exact stage holds { zeros, poles, holes, endpoints, extrema, inflections }. The work is done by @ratmath/analytic: symbolic derivatives, exact gcd, square-free and Sturm steps for rational functions, and Krawczyk and Rolle tests for everything else, which prove that a bracket holds exactly one zero.
const f = features("x^3/8 - 2x", {}, [-8, 8]).exact();
f.zeros.map((z) => String(z.at)); // ["-4", "0", "4"]
f.extrema.map((e) => e.kind); // ["max", "min"]
f.inflections.map((i) => String(i.at)); // ["0"]
Each record has at when the point is an exact rational, or lo and hi for a bracket that certainly holds it. unique: true means it is proven to be the only one in the bracket.
Closed forms
When is a rational function, each zero, extremum, inflection point, pole and hole is a root of a polynomial with integer coefficients. @ratmath/algebraic picks out the root inside the certified bracket, and the record gets algebraic: the number in closed form where it has one, with its minimal polynomial. Heights get valueAlgebraic the same way, and intersections(f, g, …) does this for the points where two graphs meet.
const f = features("x^4 - 2x^2 - 1", {}, [-4, 4]).exact();
f.zeros.map((z) => z.algebraic.text); // ["−√(1 + √2)", "√(1 + √2)"]
f.zeros[0].algebraic.tex; // "-\\sqrt{1 + \\sqrt{2}}"
f.zeros[0].algebraic.polynomial; // [-1n, 0n, -2n, 0n, 1n]
f.inflections.map((p) => p.algebraic.text); // ["−√3/3", "√3/3"], each at height −14/9
intersections("x^2", "x + 1", {}, [-4, 4]).exact().map((p) => p.algebraic.text); // ["(1 − √5)/2", "(1 + √5)/2"]
featureLabels(features) turns the records into labels for a scene, typeset as rather than 1.414…, and describe() uses the same forms in its sentences. A root with no closed form (most quintics) keeps its digits and its polynomial. Pass { forms: false } to skip the step.
Holes and poles
A pole is proven where a denominator has a proven zero and the numerator does not vanish there. Certified frames list poles as asymptotes, drawn dashed; unproven float guesses are drawn dotted. A hole is a point where is undefined but has a finite limit, as at 1, with the limit given exactly when possible.
Markers
| Feature | Dot |
|---|---|
| Zero | Filled, in the curve's color |
| Max or min | Filled, darker than the curve |
| Inflection point | Filled, lighter than the curve |
| Hole | Open (the function is not defined there) |
| Domain end, included | Filled |
| Domain end, excluded | Open |
drawMarkers(ctx2d, vp, features, { color, background, scale }) draws them; markerList(features) gives the same list as data for other renderers.
@ratmath/graphics and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math, and SHOW(svg) draws a picture.