Ideas

Fast, then certified

Every computation answers twice. The first answer is a floating-point sketch, cheap enough for every frame of a slider drag. The second is certified: computed from the exact rational inputs with interval arithmetic that rounds outward, so its claims are proven.

What "certified" means for a graph

The viewport has rational edges and a grid of pixel cells. Pixel column ii covers the exact interval [xmin⁡+i Δx, xmin⁡+(i+1) Δx][x_{\min} + i\,\Delta x,\ x_{\min} + (i+1)\,\Delta x]. For each column, the library evaluates ff over that whole interval with interval arithmetic, splitting the column where that tightens the result. The rows the enclosure touches are shaded. So:

  • every point (x,f(x))(x, f(x)) of the graph in view lies in a shaded cell, and
  • a cell that is not shaded contains no point of the graph.

The sketch makes no such promise. Above, sin⁡(1/x)\sin(1/x) oscillates infinitely often near 0; the sketch shows a few zigzags, the certified cells shade the whole band. Zoom in and both sharpen.

Refinements

Functions like graph, zeros, features, implicit and region return a Refinement, the same protocol used by RatMath's linalg and analytic libraries.

const g = graph("a*x^2 - 3", { a: "1/2" }, vp);
g.quick.value;           // float sketch, computed on creation
g.quick.trust;           // "rough"
g.exact();               // run the certified stage to the end, synchronously
await g.settle({ signal, sliceMs: 8, onProgress });   // the same, in 8 ms slices

Progress ticks carry a partial frame, so a page can show the certified picture filling in column by column.

Sliders: live

live(compute, onStage, { idleMs }) wires a Refinement to user input. Each call shows the sketch at once. Once input has been still for idleMs, the certified stage runs in time slices; newer input cancels it. Slider values should be exact rationals, such as integer steps of 1/8, so the certified picture is of exactly the function the label shows.

const update = live((a) => graph("a*x^2 - 3", { a }, vp), (stage) => {
  draw(stage.value, stage.exact ? "teal" : "royalblue");
}, { idleMs: 120 });
slider.oninput = () => update(`${slider.value}/8`);

Exact versus certified

Some results are exact: a rational zero, a polygon corner, an intersection point like (118,3158)\left(\tfrac{11}{8}, \tfrac{3\sqrt{15}}{8}\right). Others are certified enclosures: an irrational zero as a bracket [lo,hi][lo, hi] proven to hold exactly one zero, a curve as the set of pixels it can touch. Both are trustworthy; the second is as sharp as the pixel grid or the tolerance you ask for.

Try itEdit the code and run it with @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.
Ctrl/⌘ + Enter runs