Antiderivatives

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 FF is offered as an antiderivative of ff, then F′=fF' = f can be tested by equal, which has three answers. They become:

equal(F′, f)What integrate does
equalReturns FF with verified: "proven". The normal form shows the derivative is the integrand.
undecidedReturns FF 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.
differentThrows 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 ax+bax + b are looked up: powers, eue^u, sin⁡u\sin u, log⁡u\log u, arctan⁡u\arctan u and so on, each divided by aa.

Partial fractions. A rational function is split by algebraic into a polynomial plus terms A(x−r)k\dfrac{A}{(x-r)^k} and Bx+C(x2+px+q)k\dfrac{Bx + C}{(x^2+px+q)^k}. 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

∫dxqk=q′(k−1) D qk−1+2a(2k−3)(k−1) D∫dxqk−1,q=ax2+bx+c,D=4ac−b2. \int \frac{dx}{q^k} = \frac{q'}{(k-1)\,D\,q^{k-1}} + \frac{2a(2k-3)}{(k-1)\,D}\int \frac{dx}{q^{k-1}}, \qquad q = ax^2+bx+c,\quad D = 4ac - b^2.

Powers of sine and cosine. A product such as sin⁡3xcos⁡2x\sin^3 x\cos^2 x or cos⁡3xsin⁡2x\cos 3x \sin 2x is rewritten as a sum of sines and cosines of multiple angles, using cos⁡Acos⁡B=12(cos⁡(A−B)+cos⁡(A+B))\cos A\cos B = \tfrac12(\cos(A-B) + \cos(A+B)) and its companions, and then integrated term by term.

Substitution. Each subexpression g(x)g(x) is tried as uu: if the integrand divided by g′(x)g'(x) can be written with uu alone, the problem becomes ∫h(u) du\int h(u)\,du. For a square root of a linear expression the substitution is turned around, x=(u2−b)/ax = (u^2 - b)/a, which removes the root.

Integration by parts. ∫u dv=uv−∫v du\int u\,dv = uv - \int v\,du, with uu chosen as a logarithm or inverse function first and a polynomial second. The product eaxsin⁡bxe^{ax}\sin bx, where parts leads back to the start, is solved for directly.

Square roots of quadratics. ax2+bx+c\sqrt{ax^2+bx+c} 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 (ex2e^{x^2}, sin⁡x/x\sin x / x), and some that do are out of reach here. In both cases found is false.

The absolute value in the logarithm

∫dx/x\int dx/x is log⁡∣x∣\log|x|, 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 F(b)−F(a)F(b) - F(a), 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 [−1/x]−11=−2\left[-1/x\right]_{-1}^{1} = -2 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 lim⁡x→b−F(x)−lim⁡x→a+F(x)\lim_{x\to b^-} F(x) - \lim_{x\to a^+} F(x), 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
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