@ratmath/analytic

Answers about functions that come with a proof

A JavaScript library for calculus on exact rational numbers. Ask for a value, a range, an integral, the zeros or the solution of a differential equation. You get a floating-point answer at once, then an interval that is guaranteed to contain the true answer.

Move the slider. The curve and the guesses follow at float speed. When you stop, the zeros are proven, each one in its own small bracket that is shown to contain exactly one. The integral and the range come back as intervals, and the true values are inside them.

Why intervals

Most values of exp, sin or an integral are irrational, so no fraction is exactly right. RatMath's answer is a rational interval that certainly contains the true value, as narrow as you ask. Every step that could lose accuracy (a truncated series, a rounded constant, a range over a whole interval) is counted and added to the interval. So the result is a statement you can rely on, not an estimate.

Underneath sits the Taylor model: an exact polynomial plus an interval remainder, valid on a whole interval of inputs. Arithmetic, composition, integration and ODE steps all act on these models and keep that guarantee.

A first program

import { R } from "@ratmath/core";
import { fn, zeros, ode } from "@ratmath/analytic";

const f = fn("exp(sin(x))*x");
f.value("1/3").quick.value;          // 0.46235716975704894 (float, at once)
f.value("1/3", { digits: 30 }).exact();  // RationalInterval, 30 correct digits
f.integral(0, 1).exact();            // certified ∫₀¹
f.derivative().toString();           // "exp(sin(x))*cos(x)*x + exp(sin(x))"

zeros("x^3 - 3x + 1", [-3, 3]).exact();   // three brackets, each with exactly one zero
ode.solve({ f: "y^2 + t", y0: "1/2", until: "1/2" }).exact().final;  // y(1/2), certified

Topics

Try itEdit the code and run it with @ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs