Skip to main content

Crate use_calculus

Crate use_calculus 

Source
Expand description

§use-calculus

Small numerical-calculus helpers for direct, explicit Rust code.
Finite-difference derivatives, numerical integration, and simple symmetric limit estimates without a symbolic framework.

Rust 1.95.0+ Edition 2024 Numerical calculus Explicit validation License MIT or Apache-2.0

Surface · When to use it · Installation · Examples · Validation · Scope

use-calculus provides a deliberately small numerical-calculus surface. The crate prefers explicit assumptions over magic defaults: finite-difference steps are caller-chosen, integration sample counts are explicit, and two-sided limit estimates fail when the left and right samples do not agree within a caller-provided tolerance.

Differentiation
Differentiator, central_difference, and second-derivative helpers for small direct estimates.
Integration
IntegrationInterval, Integrator, trapezoidal integration, and Simpson integration.
Explicit failure modes
Non-finite inputs, invalid steps, bad sample counts, and mismatched one-sided limits return CalculusError.

§What this crate provides

AreaRoot exportsBest fit
DifferentiationDifferentiator, central_difference, second_central_differenceSmall slope and curvature estimates on f64 functions
IntegrationIntegrationInterval, Integrator, trapezoidal_integral, simpson_integralSigned area approximations with explicit sample density
LimitsLimitApproximator, symmetric_limitTwo-sided limits where a single symmetric sample scale is a reasonable model
If you need to…Start here
Estimate a derivative at one pointDifferentiator::derivative_at(...)
Approximate a definite integralIntegrator::trapezoidal(...) or Integrator::simpson(...)
Model a signed interval directlyIntegrationInterval::try_new(...)
Reject discontinuities instead of hiding themsymmetric_limit(...) or LimitApproximator

§When to use it directly

Choose use-calculus directly when numerical-calculus helpers are the only math surface you need, or when you want the approximation policy to stay visible instead of being hidden behind a broader abstraction.

ScenarioUse use-calculus directly?Why
You need a few direct derivative or integral estimatesYesThe crate stays small and explicit
You want validation at the boundary of your appYesInvalid steps, bounds, and evaluations become errors
You need symbolic manipulation or automatic differentiationNoThis crate intentionally stays numerical and lightweight
You also need several other math surfacesUsually nouse-math may become the better integration point

§Installation

[dependencies]
use-calculus = "0.0.1"

§Quick examples

§Differentiate and integrate small f64 functions

use use_calculus::{Differentiator, IntegrationInterval, Integrator};

let differentiator = Differentiator::try_new(1.0e-5)?;
let interval = IntegrationInterval::try_new(0.0, 1.0)?;
let integrator = Integrator::try_new(128)?;

let slope = differentiator.derivative_at(|x| x.powi(3), 2.0)?;
let area = integrator.simpson(|x| x * x, interval)?;

assert!((slope - 12.0).abs() < 1.0e-3);
assert!((area - (1.0 / 3.0)).abs() < 1.0e-6);

§Explicitly reject mismatched one-sided limits

use use_calculus::{CalculusError, LimitApproximator};

let limit = LimitApproximator::try_new(1.0e-6, 1.0e-5)?;
let sinc_limit = limit.at(
    |x| {
        if x == 0.0 {
            1.0
        } else {
            x.sin() / x
        }
    },
    0.0,
)?;

assert!((sinc_limit - 1.0).abs() < 1.0e-5);
assert!(matches!(
    limit.at(|x| if x < 0.0 { -1.0 } else { 1.0 }, 0.0),
    Err(CalculusError::LimitMismatch { .. })
));

§Validation model

Use try_new when sample sizes, step sizes, tolerances, and interval bounds may come from user input, files, or network payloads. Use infallible constructors like Differentiator::new(...), IntegrationInterval::new(...), Integrator::new(...), and LimitApproximator::new(...) when values are already trusted and you want direct assembly.

[!IMPORTANT] This crate does not hide approximation policy behind a global epsilon or default grid density. Callers choose the differentiation step, integration density, and limit tolerance directly.

§Scope

  • Small numerical APIs are preferred over symbolic or trait-heavy abstractions.
  • The initial concrete surface is f64-based and focused on explicit approximation helpers.
  • Adaptive quadrature, automatic differentiation, and symbolic manipulation are intentionally out of scope for this first slice.
  • Broader real-number utilities and statistical analysis belong in adjacent focused crates.

§Status

use-calculus is a concrete pre-1.0 crate in the RustUse docs surface. The API remains intentionally small while the broader calculus roadmap is still being designed. Small numerical-calculus helpers for RustUse.

Re-exports§

pub use derivative::Differentiator;
pub use derivative::central_difference;
pub use derivative::second_central_difference;
pub use error::CalculusError;
pub use integral::IntegrationInterval;
pub use integral::Integrator;
pub use integral::simpson_integral;
pub use integral::trapezoidal_integral;
pub use limit::LimitApproximator;
pub use limit::symmetric_limit;

Modules§

derivative
error
integral
limit
prelude