Antiderivatives that have been checked
Finding an antiderivative is a search; checking one is a calculation. integrate searches with the methods of a calculus course, then differentiates what it found and compares the result with the integrand. Nothing is returned that has not passed that comparison.
Using it
import { integrate } from "@ratmath/symbolic";
const r = integrate("x*exp(x)");
String(r); // x*exp(x) - exp(x) + C (proven: its derivative is the integrand)
r.result; // the Expr x*exp(x) - exp(x)
r.verified; // "proven"
r.steps; // [ { rule: "by parts", detail: "u = x, dv = exp(x) dx: …" }, { rule: "table", … } ]
String(integrate("1/(x^2 - 1)").result); // log(abs(-1 + x))/2 - log(abs(1 + x))/2
String(integrate("sin(x)^2").result); // x/2 - sin(2*x)/4
String(integrate("x/sqrt(x^2 + 1)").result); // sqrt(x^2 + 1)
String(integrate("1/(x^2 + 1)^2").result); // x/(2*x^2 + 2) + atan(x)/2
integrate("exp(x^2)").found; // false: nothing is guessed
Proven and checked
If is offered as an antiderivative of , then can be tested by equal, which has three answers. They become:
equal(F′, f) | What integrate does |
|---|---|
| equal | Returns with verified: "proven". The normal form shows the derivative is the integrand. |
| undecided | Returns with verified: "checked" if the two agreed at every exact test point (certified evaluation), and says how many. This happens when the identity needed is beyond the normal form. |
| different | Throws the candidate away and reports that nothing was found. |
The search can therefore be adventurous without being dangerous: a mistake in a method cannot reach you as an answer.
The methods
Linearity and the table. Sums and constant multiples are taken apart, and single functions of a linear inside are looked up: powers, , , , and so on, each divided by .
Partial fractions. A rational function is split by algebraic into a polynomial plus terms and . The first kind integrate to logarithms and powers. For the second, the numerator is split into a multiple of the derivative of the quadratic, which gives a logarithm or a power, and a constant, which gives an arctangent through the reduction formula
Powers of sine and cosine. A product such as or is rewritten as a sum of sines and cosines of multiple angles, using and its companions, and then integrated term by term.
Substitution. Each subexpression is tried as : if the integrand divided by can be written with alone, the problem becomes . For a square root of a linear expression the substitution is turned around, , which removes the root.
Integration by parts. , with chosen as a logarithm or inverse function first and a polynomial second. The product , where parts leads back to the start, is solved for directly.
Square roots of quadratics. and its reciprocal use the standard forms that a trigonometric substitution produces.
const r = integrate("x*sqrt(x + 1)");
r.steps.map((s) => `${s.rule}: ${s.detail}`);
// substitution: u = sqrt(x + 1), so x = u^2 - 1 and dx = 2*u du: the integrand becomes 2*u^4 - 2*u^2
// power rule: u^4
// power rule: u^2
These are methods, not a decision procedure. Some integrands have no elementary antiderivative at all (, ), and some that do are out of reach here. In both cases found is false.
The absolute value in the logarithm
is , which is correct on each side of zero separately. The result shows log(abs(x)) unless the assumptions prove the inside positive.
String(integrate("1/x").result); // log(abs(x))
String(integrate("1/x", "x", { assume: { x: "positive" } }).result); // log(x)
Definite integrals
With from and to the fundamental theorem gives , but only when the integrand is continuous between the ends. That condition is the one students forget, so it is checked: the integrand is integrated by certified quadrature from analytic, and the exact value must lie in the certified interval.
const d = integrate("1/(x^2 + 1)", "x", { from: 0, to: 1 });
String(d.value); // pi/4
d.enclosure; // { low: 0.78539816339710…, high: 0.78539816339779… } exact rationals
d.agrees; // true
const bad = integrate("1/x^2", "x", { from: -1, to: 1 });
bad.value; // null
bad.note; // "the integrand could not be bounded on the interval (it may be undefined or unbounded inside), so F(b) − F(a) is not offered as the integral"
Without that check the formula gives for the integral of a positive function.
Improper integrals
An end may be "inf" or "-inf", and the integrand may be unbounded at an end. Then the value is , with both limits found by limit, and the judge is the certified improper integral from analytic, which also proves divergence. Without a certificate nothing is offered, since the integrand might blow up inside the interval.
integrate("1/x^2", "x", { from: 1, to: "inf" }).value; // 1
integrate("1/sqrt(x)", "x", { from: 0, to: 1 }).value; // 2
integrate("1/(1 + x^2)", "x", { from: "-inf", to: "inf" }).value; // pi
integrate("1/x", "x", { from: 1, to: "inf" }).diverges; // true
@ratmath/symbolic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.