School algebra, checked
Five rewrites that a course does by hand: completing the square, composing functions, reading a sinusoid, implicit differentiation and differentiating an integral with variable limits. Each follows the method of the course and then checks its answer with the normal form.
Using it
import { completeSquare, compose, sinusoid, implicitDiff, leibniz } from "@ratmath/symbolic";
String(completeSquare("x^2 - 8x + 11").form); // (x - 4)^2 - 5, vertex (4, -5)
String(compose("2x - 3", "x^2 + 1").value); // 2*x^2 - 1
compose("sqrt(x)", "x - 3").note; // defined only where x - 3 >= 0: x in [3, inf)
const s = sinusoid("3sin(2x - pi/2) + 1");
[s.amplitude, s.period, s.phaseShift, s.midline].map(String); // ["3", "pi", "pi/4", "1"]
String(sinusoid("sin(x) + cos(x)").form); // sqrt(2)*sin(x + pi/4)
implicitDiff("x^2 + y^2 = 25").at({ x: 3, y: 4 }).first; // -3/4
String(leibniz("cos(t)", "t", "0", "x^2").value); // 2*x*cos(x^2)
Completing the square
For the vertex is at , and is the value there:
completeSquare reads , , from the derivatives at 0 (so the input can be written any way), builds the form and expands it back to prove it equal. The coefficients can contain letters: completeSquare("x^2 + b*x + c") is .
Composition and its domain
puts in for the variable of . It is defined where is defined and is in the domain of . compose collects the conditions of (a square root needs its argument , a logarithm , a quotient a nonzero denominator), writes them in terms of , and solves them with solveInequality. When that set is smaller than the domain of , the note says so.
Sinusoids
For : the amplitude is , the period , the midline , and the phase shift (the graph of moved right by that much). sinusoid also takes a sum of sines and cosines of one frequency and writes it as one sine:
The angle is , plus when , and becomes an exact multiple of at the standard values. The identity is proven through , which the normal form knows.
Implicit differentiation
Differentiate with a function of : , so wherever . With { order: 2 }, . at(point) checks that an exact point is on the curve before evaluating.
The Leibniz rule
leibniz gives the boundary terms, and the last integral when depends on : in closed form when integrate finds it, otherwise as the integrand left to do. When does not depend on the answer is compared with integrating first and differentiating.
| Export | Returns |
|---|---|
completeSquare(expr, x) | { form, a, h, k, vertex, verified } |
compose(f, g, x) | { value, unsimplified, domain, note } |
sinusoid(expr, x) | { fn, amplitude, A, B, C, D, period, frequency, phaseShift, midline, form, verified } |
implicitDiff(F, x, y, { order }) | { first, second, steps, at(point) } |
leibniz(f, t, lower, upper, x) | { value, boundary, integral, steps } |
@ratmath/symbolic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.