Limits in closed form
limit gives the exact value of a limit where the standard methods find one, says when the two sides disagree, and compares its answer with the certified limit from analytic.
Using it
import { limit } from "@ratmath/symbolic";
const r = limit("(x^2 - 1)/(x - 1)", "x", 1);
String(r); // 2 (x -> 1; cancel, then substitute; confirmed by certified evaluation)
r.kind; // "finite"
String(r.value); // "2"
r.method; // "cancel, then substitute"
r.confirmed; // true
String(limit("sin(x)/x", "x", 0).value); // 1
String(limit("(1 - cos(x))/x^2", "x", 0).value); // 1/2
String(limit("(2x^2 + 1)/(x^2 - 3)", "x", "inf").value); // 2
String(limit("sqrt(x^2 + x) - x", "x", "inf").value); // 1/2
String(limit("(1 + 1/x)^x", "x", "inf").value); // e
String(limit("sin(a*x)/x", "x", 0).value); // a
The point is an expression, or "inf" or "-inf". The option { side: "left" } or { side: "right" } asks for a one-sided limit.
The kinds of answer
kind | Meaning |
|---|---|
"finite" | The limit is value, an exact expression. |
"inf", "-inf" | The expression grows without bound, with that sign. |
"none" | The one-sided limits differ; reason gives both. |
"numeric" | No closed form was found, but analytic certified an enclosure of the limit (enclosure). |
"unknown" | Nothing was found. at infinity is an example: it has no limit, and the library does not claim to prove that. |
String(limit("1/x", "x", 0)); // no limit: -inf from the left, inf from the right
String(limit("1/x^2", "x", 0)); // inf
String(limit("abs(x)/x", "x", 0)); // no limit: -1 from the left, 1 from the right
String(limit("abs(x)/x", "x", 0, { side: "left" }).value); // -1
How a limit is found
Cancel, then substitute. The expression is put in normal form, which cancels common factors: becomes . If the result is defined near the point on the side in question, its value there is the limit, by continuity.
Leading terms. When numerator and denominator both vanish (or the denominator alone does), each is expanded about the point:
If the limit is 0; if it is ; if the quotient is unbounded, with a sign fixed by the signs of , , the side, and whether is even. This is l'Hôpital's rule applied as many times as needed, done in one step: differentiating times is exactly reading off the first nonzero coefficient. The coefficients come from taylor and are exact.
At infinity. Put and let from the right. Square roots are tidied using , so becomes , whose leading terms give .
Powers with the variable in the exponent. For the limit of is found first, and the answer is its exponential. That is how .
The cross-check
When the expression has no other letters, analytic can often certify an interval that contains the limit, by a different argument from the one used here. If the closed form lies in that interval, confirmed is true. If it lies outside, the closed form is dropped and the certified interval is returned instead, as a "numeric" answer.
@ratmath/symbolic and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.