Curves, data and slope fields
A graph y = f(x) is one kind of picture. This page covers the others: curves given by a parameter, polar curves, the points where two graphs meet, measured data, slope fields, solutions of differential equations, and a description of a graph in words.
Parametric and polar curves
A parametric curve gives both coordinates as functions of a parameter t. A polar curve gives the distance r from the origin as a function of the angle.
parametric({ x: "cos(3t)", y: "sin(2t)" }, {}, [0, "44/7"], vp); // a Lissajous figure
polar("1 + cos(t)", {}, [0, "44/7"], vp); // a cardioid
polar("2cos(a*t)", { a: 3 }, [0, "22/7"], vp); // parameters work as in graph()
Both return a Refinement, like graph. The quick stage is a float polyline. The exact stage is a cells frame with the same promise a certified graph makes: every point of the curve lies in a lit pixel.
The proof works on the parameter. The range of t is cut into pieces. For a piece T, interval arithmetic gives a box that contains for every t in T. A box that misses the screen is dropped. A box no larger than a pixel is lit. Any other box is cut in half and both halves are tried again. Because each box contains its part of the curve, nothing is missed, and because boxes shrink to a pixel, the curve stays one or two pixels thick. The frame's tight flag is false only if a piece could not be shrunk within the limits (maxDepth, maxBoxes).
Where two graphs meet
intersections("x^2", "x + 2", {}, [-3, 3]).exact();
// [{ kind: "exact", at: -1, value: 1 }, { kind: "exact", at: 2, value: 4 }]
intersections("sin(x)", "cos(x)", {}, [0, 7]).exact();
// brackets around π/4 and 5π/4, each with an enclosure of the common value
The meeting points of f and g are the zeros of f − g, so they come with the same proofs as zeros: exact rationals where they are rational, otherwise a bracket with a proven sign change, and possible where nothing could be decided. Each record also carries the common value, exactly or as an enclosure.
Data
scatter([[1, 2], [2, "7/2"], [3, 3]], { join: true }); // dots, joined in order
bars([[1, 4], [2, 7], [3, 5]]); // one bar per [x, height]
histogram(values, { bins: 8, range: [0, 4] }); // .counts and .edges
These are frames in world coordinates that every renderer draws. Data is measured, so nothing here is a proof; it is drawn where the numbers say. A histogram value on an inner edge goes to the bin on its right, and the last bin includes its right end.
Slope fields and solutions
slopeField("x - y", {}, vp); // y′ = x − y
solutionCurve({ f: "t - y", y0: 1, until: 3 }, vp); // Refinement
A slope field draws a short segment at each grid point with the slope the equation gives there. solutionCurve draws one solution. Its quick stage is a Runge–Kutta sketch. Its exact stage comes from the validated solver in @ratmath/analytic: for each pixel column, the lit span provably contains the solution over that column. If the solution blows up before the end, the frame has complete: false and a reason, and stops where the proof stops.
A graph in words
describe("x^3 - 3x", {}, [-3, 3]);
describe turns the certified features of a graph into sentences: where it meets the axis, its asymptotes and holes, its highest and lowest points, where it changes the way it bends, and where its domain ends. Use it for alt text. Every sentence comes from a proven record, and anything undecided is reported as undecided.
Axes in π, fractions and powers of ten
sceneSVG(vp, layers, { axes: { xUnit: "pi" } }); // ticks at π/2, π, 3π/2, …
sceneSVG(vp, layers, { axes: { yUnit: "fraction" } }); // ticks at 1/4, 1/2, 3/4, …
const g = graph(logScale("x^2", { x: true, y: true }), {}, logVp);
sceneSVG(logVp, [g.exact()], { axes: { xScale: "log", yScale: "log" } });
For logarithmic axes the viewport is in log10 coordinates: logScale rewrites f so that the horizontal coordinate u stands for x = 10u and the vertical one for log10 of the value. The picture is still certified, and the axes label whole powers of ten.
@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.