Use this file to discover all available pages before exploring further.
The Limits module in MathCore lets you evaluate the limiting behaviour of an expression as a variable approaches a finite value or infinity. It supports two-sided limits, one-sided limits (from the left or the right), and limits at ±∞, and exposes a separate continuity checker that combines limit evaluation with direct function evaluation. For the common 0/0 indeterminate form, Limits also provides automatic L’Hôpital’s rule application.
Controls which side of the approach point is used for evaluation.
#[derive(Debug, Clone, Copy, PartialEq)]pub enum LimitDirection { Left, // approach from below (x → point⁻) Right, // approach from above (x → point⁺) Both, // two-sided; errors if Left ≠ Right}
Variant
Meaning
Left
Approach point from the left (x → point⁻).
Right
Approach point from the right (x → point⁺).
Both
Checks that the left and right limits agree; returns that value.
When LimitDirection::Both is used and the one-sided limits differ, Limits::limit returns Err(MathError::InvalidOperation("Limit does not exist (left != right)")).
Returns Ok(Expr::Number(value)) for a finite limit, Ok(Expr::Symbol("∞")) or Ok(Expr::Symbol("-∞")) for an infinite limit, or Err(MathError) if the limit does not exist or cannot be computed.
sin(x)/x is undefined at x = 0, but its two-sided limit is 1. MathCore evaluates the expression numerically at points approaching the limit from both sides, so it handles this removable discontinuity correctly.
Returns Ok(true) if the two-sided limit exists and equals the function’s value at point (within a tolerance of 1e-9). Returns Ok(false) if the function is undefined at the point, the limit does not exist, or the limit and value differ. Returns Err(MathError) only for expression evaluation failures.
use mathcore::MathCore;use mathcore::calculus::limits::{Limits, LimitDirection};// sin(x)/x is not defined at 0 but its limit is 1 — not continuouslet expr = MathCore::parse("sin(x)/x").unwrap();let continuous = Limits::is_continuous_at(&expr, "x", 1.0).unwrap();println!("sin(x)/x continuous at x=1: {}", continuous); // truelet at_zero = Limits::is_continuous_at(&expr, "x", 0.0).unwrap();println!("sin(x)/x continuous at x=0: {}", at_zero); // false
If both the numerator and denominator evaluate to zero at point, MathCore differentiates both with Calculus::differentiate and recomputes the limit of the resulting ratio. Otherwise it falls back to a direct limit evaluation.
use mathcore::MathCore;use mathcore::calculus::limits::Limits;// lim(x→0) sin(x)/x via L'Hôpital: cos(x)/1 → 1let num = MathCore::parse("sin(x)").unwrap();let den = MathCore::parse("x").unwrap();let limit = Limits::lhopital_rule(&num, &den, "x", 0.0).unwrap();println!("L'Hôpital result: {}", limit); // 1
You can call lhopital_rule proactively for any expression you suspect is a 0/0 form — if it is not, the function falls back gracefully to a standard numerical limit evaluation.
The Limits module uses a numerical approach — evaluating the expression at points very close to the limit point (offset by ±1e-10) and checking for convergence. This means results are subject to floating-point precision. For limits that require symbolic cancellation of terms (such as (x^2 - 1)/(x - 1) at x = 1), use lhopital_rule or simplify the expression with MathCore::simplify before calling Limits::limit.