Reference

Everything in the library

Numbers can be JS integers, bigints, strings such as "3/4" or "0.1" (decimals are exact), Core Rationals, or Core intervals such as R`1/2:1`. Functions marked R return a Refinement: .quick is the float preview, .exact() or await .settle() gives the certified answer. When a hypothesis fails (a log of something that can reach 0, a divisor that can be 0, a point outside the domain), the library throws an AnalyticError with a code and a reason. It does not return a bound it cannot prove.

Formulas

callreturnsnotes
fn(text, { variable, params })AnalyticFunction or PiecewiseFunctionText, an AST, or the piecewise form "rule if region; …; rule otherwise"
f.value(x, { digits = 20, maxBits = 8192 })R RationalIntervala point interval for rational-only formulas; bits double until the digits are met or maxBits is reached
f.range(I, { digits = 6, order = 8, maxPieces = 256 })R RationalIntervalpreview: 256 samples (trust rough)
f.integral(a, b, { digits = 12, order = 12, maxPieces })R RationalIntervalpreview: Gauss–Legendre
f.limit(c, { digits = 20, side })RationalInterval or ±Infinityc is a rational point, "inf" or "-inf"; side is "left" or "right". Throws no-limit where the two sides differ or the function keeps oscillating
f.asymptotic("inf" | "-inf"){ exp, power, log, coefficient, oscillates, term }the leading behaviour ekx·xp·log(x)m·(coefficient + a part that dies out)
f.improperIntegral(a, b, { digits = 10, singular })R RationalInterval, ±Infinity or NaNan end at "inf" / "-inf" or where f is undefined; singular lists interior singular points. ±Infinity is a proven divergence; an integral that cannot be decided throws undecided
f.taylor(c, n = 6, { digits })RationalInterval[]enclosures of f⁽ᵏ⁾(c)/k! for k = 0…n, n ≤ 16; exact points for rational values; removable quotients are divided as series
f.derivative()a new functionsymbolic and simplified
f.model(D, { order, bits, centre })TaylorModelcertified on the domain D
f.regular()a functionthe same function with holes of its rational summands cancelled; used by range and integral
f.float(x)numberno guarantee
f.with({ a: "3/8" })a new functionother parameter values (sliders)
f.toString()stringcalculator notation that parses back

Grammar: + - * / ^ (or **), parentheses, implicit products (2x, 3(x+1), 2sin(x)), -x^2 = -(x^2), ^ right-associative. Functions: exp log ln log1p sqrt cbrt sin cos tan asin acos atan sinh cosh tanh erf erfc abs min max (arcsin arccos arctan too), sec csc cot sech csch coth asinh acosh atanh (written out in the others as they are read), and the special functions gamma lgamma digamma trigamma beta(a, b) besselJ(n, x) Si fresnelS fresnelC; constants pi e. A name of three or more letters written against a parenthesis, such as foo(x), is refused as an unknown function rather than read as a product. A power with an odd denominator, x^(1/3), is the real root and is defined for negative x. Ranges and integrals may cross points where the function is not smooth (abs, cbrt at 0); there the bounds come from interval evaluation. It is the same grammar and the same plain AST as @ratmath/graphics.

Features of a function

callrecord kindsfields
zeros(f, [a, b], opts)exact, sign-change, isolated, possible, undefined, everywhereat, lo, hi, unique, multiplicity, atMost, bound, budget
poles(f, [a, b], opts)pole, hole, undefinedorder (rational poles), source: "log" (asymptotes of ln), value (a hole's limit)
extrema(f, [a, b], opts)max, min, flat, possible, constantvalue, unique, touching
inflections(f, [a, b], opts)inflection, possiblevalue, unique, touching
simplestBetween(a, b)Rationalsmallest denominator in [a, b]

All four are R. Options: variable, params, tolerance (bracket width, default 10⁻⁶), pieces (starting pieces, 16), maxDepth (48), maxMultiplicity, flatBits, maxBoxes (2000 per piece), maxMs (8000 in all), sliceMs (15). Previews are { kind: "guess", at }. A stretch of the interval with no record certainly holds none.

kind or fieldmeaning
exactf(at) = 0 exactly, at a rational point
everywhere, constantthe function is identically zero (for zeros) or constant (for extrema) on [lo, hi]; one record covers the stretch
sign-changef has opposite proven signs at lo and hi; with unique, exactly one zero inside
isolatedexactly one zero inside, but f keeps its sign (found through sqrt, abs or an even power)
possibleundecided: maybe no zero, maybe several; atMost: m bounds the count with multiplicity
undefinedf is not defined somewhere on the bracket
boundproven max |f| on a possible bracket of a flat function
budgetthe bracket was left when the work budget ran out
touchingf′ (or f″) has the same proven sign at both ends: no feature, or a pair of them inside

Piecewise

callreturnsnotes
piecewise([[region, rule], …], opts)PiecewiseFunctionfirst matching piece wins
where`2:!x:8`Regiontemplate tag; values may be interpolated
new Region(text | x => bool, { variable, params })Region.test(x), .match(x) → { n }, .intervals(a, b), .breakpoints(a, b)
p.breaks([a, b])R records{ at, value, left, right, kind: continuous | jump | removable | edge | unproven, defined }
p.segments(a, b)arrayopen pieces and points with the active rule
p.value, range, integral, zeros, extrema, inflections, poles, derivativepiece by piece

Differential equations

callreturnsnotes
ode.solve({ f, y0, t0, until, order = 10, step, tol, maxSteps, vars, time, params, float })R ODESolutionpreview: RK4 samples { t, y }
sol.at(t), sol.final, sol.steps, sol.complete, sol.reason, sol.describe()enclosures of y(t)
ode.step({ f, y0, step, order }){ t0, t1, models, model }one validated step, or an error

f is a formula in t and y, an array of formulas for a system (vars names the unknowns), or a JS function (t, y) => model with an optional float twin for previews.

Boundary value problems

callreturnsnotes
bvp({ f, interval, left, right, digits = 8, vars, time, params, guess, order })R BVPSolutionf is y″ as a formula in x, y and dy; each end gives { y } or { dy }. Solved by certified shooting
s.at(x), s.slopeAt(x)RationalIntervalenclosures of y(x) and y′(x)
s.start, s.unknown, s.linear, s.unique, s.tubethe left-end value that was solved for and which one it is; unique is proven for linear problems; tube is the ODESolution

Several variables

callreturnsnotes
field(text, ["x", "y"], { params })ScalarFieldany number of variables
F.partial("x", "y"), F.gradient(), F.hessian(), F.laplacian()ScalarFieldssymbolic and simplified
F.jet(point, { digits, order }){ value, gradient, hessian, smooth }certified at a point or over a box (sides may be [a, b])
F.value(point), F.directional(point, direction, { unit })R RationalInterval
F.linearization(point)ScalarFieldthe tangent plane
F.along({ x: "cos(t)", y: "sin(t)" })AnalyticFunctionthe field along a curve; F.substitute fixes some variables
F.range(region, { digits })R RationalInterval
F.integral(region, { digits, maxBoxes })R RationalIntervalproduct Simpson or Boole rules with proven error terms, refined where the enclosure is widest
F.criticalPoints(box, { digits })R records{ kind: min | max | saddle | degenerate | possible, unique, point, value }; a box with no record holds no critical point
divergence(F, vars), curl(F, vars), jacobian(F, vars)ScalarFieldsF is a list of formulas
lineIntegral(F, vars, curve, [t0, t1])R RationalInterval∫ F·dr for a list, ∫ f ds for one formula
surfaceIntegral(F, vars, surface, ["u", "v"], region)R RationalIntervalthe flux for a list, ∫∫ f dS for one formula

A region is a box { x: [0, 1], y: [0, 2] }, iterated bounds { x: [0, 1], y: ["0", "x^2"] }, region text such as "0:x:1 && 0:y:x", or a Core MultiRegion (R.region).

Fourier series

callreturnsnotes
fourier(f, [a, b], { terms = 10, digits = 10, kind })R FourierSeriesf is a formula, a function or a piecewise function; kind is "full", "sine" or "cosine" (half-range)
S.a, S.b, S.coefficient(n), S.amplitude(n)RationalIntervalsa[0] is a₀, so the mean is a₀/2
S.partial(N)AnalyticFunctionthe partial sum, for plotting
S.value(x, N)RationalIntervalthe partial sum at a point
S.meanSquare(), S.meanSquareError(N)RationalInterval(1/L)∫f² and (1/L)∫(f − SN)², by Parseval

Sequences and series

callreturnsnotes
sequence(term, { variable = "n", from = 1 })Sequenceterm(n), terms(count), limit(), monotone(), bounds(), limsup(), liminf(), accumulation(), supremum(), infimum(), nFor(ε), series(). n! is read as a factorial. See Sequences
deltaFor(f, x0, ε, { delta }), verifyCertificate(certificate){ delta, largest, reason, certificate }; { valid, checks }A δ for ε with its proof, and the independent recheck of an nFor or deltaFor certificate. See ε, N and δ
recursive(next, { start, variable = "x" })RecursiveSequenceterms(count), fixedPoints([a, b]), limit([a, b]) proven by contraction
sum(term, { variable = "n", from = 1 })Seriespartial(N); divergenceTest, ratioTest, rootTest, comparisonTest, integralTest, alternatingTest, tests(); convergence(); termsForError(ε) for alternating series; sum({ digits }) with a proven tail. See Series and convergence tests
powerSeries(coefficient, { index = "n", from = 0, centre = 0 })PowerSeriesradius(), interval() with both ends examined, partial(N), at(x), value(x), derivative(), integral(). See Power series
taylorRemainder(f, { about, order, on }){ coefficients, M, radius, bound, actual, holds }Lagrange's bound beside the true maximum error
functionSequence(term, { variable = "x", index = "n" })FunctionSequencemember(n), pointwise(x), supDistance(n, [a, b], limit), uniform([a, b], limit)

Theorems of vector calculus

callreturnsnotes
greens([P, Q], [x, y], region, { flux }){ statement, left, right, agree, overlap }both sides enclosed; the boundary is built from the region. See Green, Stokes and the divergence theorem
stokes(F, vars, surface, [u, v], region)the same shapecirculation around the image of the parameter region's boundary against the flux of the curl
divergenceTheorem(F, vars, solid, { surface })the same shapeflux through top, bottom and walls against the triple integral of the divergence
changeOfVariables(f, vars, map, newVars, region, { original }){ jacobian, determinant, sign, factor, integrand, value }See Change of variables, potentials, multipliers
potential(F, vars){ conservative, curl, witness, potential, check, value }conservative is true, false or null
lagrange(f, g, vars, box, { multiplier }){ lagrangian, candidates, max, min, complete }candidates are certified critical points of f − λg

Differential equations: methods

callreturnsnotes
firstOrder(rhs, { x, y, method }){ type, types, steps, general, implicit, singular, through(x0, y0) }linear, separable, Bernoulli, homogeneous. See First-order equations
exactEquation(M, N)the same with { exact, factor, potential }integrating factors in x alone or y alone
linearODE(coefficients, forcing){ characteristic, roots, basis, particular, method, general, initial(values, x0) }See Linear equations and Laplace transforms
laplace(f), inverseLaplace(F)formula; { partialFractions, result }with heaviside(t - c) and dirac(t - c); see Steps and impulses
laplaceSolve(coefficients, forcing, initial){ transform, solution, pieces, verified, steps, at(t) }See Steps and impulses
linearSystem(A){ eigenvalues, kind, stability, exponential, solution(x0) }Any size; kinds for 2 by 2. See Systems in the plane
planarSystem([f, g], [x, y])PlanarSystemequilibria(box), jacobian(), nullclines(), conserves(H), along(V), orbit({ from, until })
seriesSolution({ p, q, about, order }){ kind, indicial, exponents, solutions, notes, radius, provenRadius }; each solution has remainder(ρ) and enclose(x) with a proven boundSee Series solutions
heat, laplaceRectangle, laplaceDiscseries solutions with at(…) → { value, partial, tail }See Heat, waves and potentials
transport({ speed, decay, source, initial, interval }){ kind, characteristics, foot, formula, crossing, at(x, t), residual(x, t) }u_t + c·u_x + k·u = s by characteristics. See First-order equations: characteristics
wave({ c, length, position, velocity }){ at(x, t), travelling, modes(N) }d'Alembert's formula
classifyPDE({ A, B, C }), pde.classifyobjecthyperbolic, parabolic or elliptic from B² − 4AC, with the region of each type when the coefficients vary
sturmLiouville({ p, q, w, interval, count })[{ index, eigenvalue, proven }]shooting, each eigenvalue bracketed by validated solutions
antiderivative(tree, name), partialFractions(N, D)the integrals and partial fractions the methods use

Differential geometry

callreturnsnotes
curve(components, parameter, { params })Curvespeed(), curvature(), torsion(), evolute(), length([a, b]), totalCurvature([a, b]), at(t). See Curves
surface(components, [u, v], { params })Surfacefirst(), second(), normal(), gaussian(), mean(), at(u, v), area(region). See Surfaces and curvature
metric({ E, F, G }, [u, v])Metricchristoffel(), gaussian(), geodesic({ from, direction, until }), transport(path, [a, b], vector), geodesicCurvature(path, t), gaussBonnet(region). See Geodesics and Gauss-Bonnet
tidy(tree)formula treequotient of polynomials in variables and calls, with sin² + cos² = 1 used and common factors cancelled
ode.solve({ …, track: false })skips tracking the initial value, which is faster for a single starting point over a short span

Fourier transforms

callreturnsnotes
fourierTransform(f, { convention, support })FourierTransformat(ω) as { re, im } enclosures, formula for the standard pairs (checked against the integrals), check(ω), parseval(), inversion(x). See The Fourier transform
inverseFourier(F).at(x){ re, im }from a formula for F
convolution(f, g)objectat(x) enclosed; theorem(x) checks it against the product of the transforms
heatLine({ k, initial })objectthe heat equation on the whole line: at(x, t), viaTransform(x, t), check(x, t), heat()
dft(values), fft(values)objectexact in the field of n-th roots of unity; fft counts its multiplications and compares with the definition. See The discrete Fourier transform
rootOfUnity(n, k), cyclotomic(n), Cyclotomicexact numbers built from roots of unity
alias(frequency, rate), sinusoidSamples(spec), sample(f, spec)the alias frequency, exact samples of a sinusoid, enclosed samples of a formula

Numerical methods, with their true errors

callreturnsnotes
floatParts(x, typed?)objectsign, exponent, mantissa, bits, the exact rational the double is, its ulp and neighbours; with the typed decimal, the exact representation error. See Floating point, exactly
exactOf(x), nearestDouble(q), floatOp(op, a, b)a double as a rational, the double nearest a rational, and one operation with the rounding it added
roundoff(formula, inputs)objectthe calculation in doubles and exactly, digitsLost, and steps showing where the digits go
bisection(f, [a, b]), newton(f, x0), secant(f, x0, x1), fixedPoint(g, x0)objectiterations each with its true error against the certified root, and the observed order; newton(f, x0, { exact: true }) iterates in exact fractions. See Root-finding methods
gradientDescent(f, start, { method, step, steps })objecta simulated run with fixed steps, backtracking or the exact line search for quadratics; exact fractions for polynomial objectives. See Gradient descent
interpolate(points) or interpolate(f, { nodes })objectdivided differences, newton, lagrange, polynomial, at(x), error(x), maxError([a, b]). See Interpolation and approximation
equallySpaced(a, b, n), chebyshevNodes(a, b, n)Rational[]nodes; the Chebyshev ones rounded to short rationals
spline(points), leastSquares(points, degree)objectthe natural cubic spline and the least-squares polynomial, exact
differences(f, x, { kind, steps }), richardson(f, x)objectdifference quotients in doubles with true error and truncation term; the extrapolation table. See Differences and quadrature rules
quadratureRule(f, [a, b], { rule, n }), romberg(f, [a, b]), gaussRule(f, [a, b], n)objectthe rule's value, the certified integral, the true error and the textbook bound
darboux(f, partition)objectlower and upper sums, exact where f is proven monotone on each piece, else enclosures; with the certified integral between them
legendre(n), gaussLegendre(n)exact Legendre coefficients; certified nodes and weights
odeMethod(f, { method, t0, y0, until, steps }), stepSizeStudy(f, { …, counts }), stability(method)objectEuler, Heun, midpoint, RK4 and Adams-Bashforth with the true global error at every step, observed order, and the stability interval. See Euler to Runge-Kutta

Taylor models

callnotes
Domain(R`a:b`, { centre })centre defaults to the midpoint
TM.x(D, { order = 12, bits = 96 }), TM.constant(D, v), TM.polynomial(D, [a0, a1, …])sources
.add .subtract .negate .multiply .divide .pow(n)with models or numbers
exp sin cos tan log log1p atan asin acos sqrt cbrt erf sinh cosh tanh reciprocal power(g, a)elementary functions of models
.at(x) .range() .integral(a, b) .integrate() .derivative()derivative only for exact polynomials
.coefficients .remainder .centre .order .describe() .toJSON()
series(D, { coefficient or coefficients, degree, order, centre, rule, M, q, error, lookahead })user series; rules lagrange, ratio, alternating, explicit

Fast, then certified

callnotes
job.quick{ value, trust }, trust is good, rough or unsure; computed on first read
job.stages()generator: the preview, progress ticks { done, of, step, partial }, then the exact stage { value, via }
job.exact(), job.exactStage()run to the end synchronously; the value, or the whole stage with its via line
await job.settle({ signal, sliceMs = 8, onStage, onProgress })run in time slices without blocking a page; abort with an AbortController
job.settledtrue once the exact answer is cached
live(compute, onStage, { idleMs = 30, sliceMs, onProgress, onError })returns update(...args): each call cancels the last job, shows its preview at once and its exact answer after idleMs of quiet

Errors

Every refusal is an AnalyticError with a code. The common ones:

codewhen
domainlog, sqrt or a power is applied outside its domain (log of a range that reaches 0)
division-by-zeroa divisor's range contains 0
not-smoothabs, min or max at a corner inside the domain
overflowexp of an argument above 2¹⁶, or a value too large to enclose
hypothesisa series rule fails on the checked terms
outside-domaina model or ODE solution asked about a point outside where it is valid
unbounda name in a formula has no value
bad-expression, bad-region, bad-piecewise, bad-ode, bad-seriesinput that does not parse or does not make sense
budgeta series or search ran past its limit

Points, constants, plumbing

callnotes
enclose.exp(x, bits) (also log, sqrt, cbrt, atan, asin, acos, sin, cos, tan, sinh, cosh, tanh, erf, log1p)points or intervals → RationalInterval
constants.pi(bits), constants.e(bits)
createScope({ digits, bits, order })callable set for evaluators: exp, sin, …, model, integral, range, fn, d, ode, zeros, …
Refinement, live(compute, onStage, { idleMs })the shared fast-then-exact shape
parse, format, differentiate(ast, name), compileFloat(ast), modelOf(ast, env, base), encloseAst(ast, env, bits), freeVariables(ast)expression tools
num(v), v(name), op(o, ...args), call(name, ...args)build an AST by hand
parsePiecewiseText(text)[[region, rule], …] or null when the text is not piecewise
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