Step records

Step records for every operation

explain.solve(…), explain.factor(…) and the rest run an operation and return its answer with the list of named steps that produced it, for an app to show. A step is shown only if it was checked, and it says how.

Using it

import { explain, sym } from "@ratmath/symbolic";

const d = explain.expand("(x + 1)^2 - (x - 1)^2");
String(d);
// expand (x + 1)^2 - (x - 1)^2
// 1. multiply out
//     (x + 1)^2  =  x^2 + 2*x + 1   [proven]
// 2. multiply out
//     (x - 1)^2  =  x^2 - 2*x + 1   [proven]
// 3. collect like terms
//     x^2 + 2*x + 1 - (x^2 - 2*x + 1)  =  4*x   [proven]
// result: 4*x

d.steps[0].rule;        // "multiply out"
String(d.steps[0].to);  // "x^2 + 2*x + 1"
d.steps[0].check;       // "proven"
d.toTeX();              // an aligned block of the steps

String(sym("x^4 - 1").explain("factor"));       // the same, as a method
String(explain.solve("sqrt(x + 3) = x - 3"));   // the method's steps, the check, and the rejected candidate

Every operation has one: expand, factor, collect, apart, simplify, rewrite, equal, solve, solveInequality, solveSystem, integrate, limit, taylor and sum. Each takes the same arguments as the operation and returns a Derivation: operation, input, result (what the operation itself returns), steps and omitted.

Three ways a step is checked

checkMeaning
"proven"The step is an equality A=BA = B and the normal form of A−BA - B is 0, or it is a proof in itself (a point that separates two expressions, an antidifference that differences back to the term).
"test points"AA and BB agree to certified precision at exact test points, but the normal form could not show they are equal. This is evidence, not proof, and checkedAt says how many points agreed.
"by the result"The step is part of a method whose outcome is checked as a whole: the solutions of an equation are put back into it, an antiderivative is differentiated, an antidifference is differenced. Squaring both sides is not an equivalence, so it cannot be checked on its own; what matters is that the candidates it produces are.

A step between two expressions that could not be checked at all is not shown; omitted counts such steps. So an app that displays a derivation never displays an unchecked equality.

What the steps are

Rewriting. expand multiplies out each term that needs it and then collects like terms; a quotient is first brought over a common denominator, with the cancelled factors named. factor expands and then factors over the rationals. apart forms one fraction, factors the denominator, and splits. simplify shows each rule the assumptions allow, then the choice of the smallest equal form. rewrite shows each rule application, and the rules that were blocked because their conditions were not proven.

Equality. The normal form of each side, and then either the difference reducing to 0, a point where certified values of the two sides do not overlap, or the plain statement that the question is undecided.

Solving, integrating, limits and sums. The steps of the method in the order they were taken (substitution, zero product, quadratic formula, inverse sine with every turn, integration by parts, partial fractions, sums of powers, telescoping, …), followed by the check that makes them trustworthy: solutions put back, rejected candidates with the reason, the derivative of the antiderivative, the antidifference.

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