Skip to main content

Crate mathr

Crate mathr 

Source
Expand description

§mathr

A pure-Rust mathematics library and CLI that bundles symbolic and numerical computation:

  • Expression AST, parser and evaluator (expr, parser, eval) with a standard library of elementary functions (sin, cos, exp, log, …) and constants (pi, e, …).
  • FFT from scratch (fft): Cooley–Tukey radix-2 (forward, inverse, 2D, real-input) plus magnitude / power spectra, convolution, cross-correlation, and window functions (Hann, Hamming, Blackman).
  • Numerical calculus (calculus): high-order finite-difference derivatives, trapezoidal and Simpson’s integrators, adaptive quadrature, partial derivatives and gradients.
  • Symbolic algebra (symbolic, simplify): differentiation by the usual calculus rules, plus a simplifier that flattens identities and folds constants. Expression equality via canonical form (expr).
  • Equation solving (solver): bisection, Newton–Raphson (with numeric-derivative fallback), secant, and Durand–Kerner for polynomial roots.
  • Plotting (plot): PNG output via plotters, with single-, multi- and scatter-plot variants.
  • Matrix operations (matrix): arithmetic, determinant, inverse, linear system solving, trace, LU decomposition with partial pivoting, rank estimation, Cholesky decomposition, SVD, power iteration, and symmetric eigenvalue decomposition via the QR algorithm, Hessenberg decomposition, and real Schur decomposition.
  • Sparse matrices (sparse): CSR/CSC compressed storage with matrix–vector products, transposition, sparse×sparse multiplication, Jacobi-preconditioned conjugate gradient for symmetric positive-definite systems, and BiCGStab for general nonsymmetric systems.
  • Statistics (stats): mean, median, variance, stddev, quartiles, correlation, linear regression.
  • Curve fitting (curvefit): Levenberg–Marquardt nonlinear least squares with numeric Jacobians, parameter standard errors.
  • Logistic regression (logit): binary classification via IRLS with Wald standard errors and stable log-likelihood.
  • Distributions & tests (dists): Student-t, chi-squared, F, binomial, Poisson, uniform pdf/cdf, normal quantile, regularized incomplete beta, and classical hypothesis tests (t-tests, chi-squared goodness-of-fit, one-way ANOVA).
  • Number theory (numtheory): GCD, LCM, primality, factorization, binomial coefficients, Fibonacci, sieve, Euler’s totient, Miller–Rabin, Chinese Remainder Theorem, modular exponentiation, Jacobi symbol, continued fractions, linear Diophantine solver.
  • ODE solvers (ode): Euler, RK4, RK4 systems, adaptive RKF45.
  • Stiff ODE solvers (stiff): backward Euler and implicit trapezoidal (Crank–Nicolson) for stiff systems — A-stable, per-step Newton with numeric Jacobians.
  • Taylor series (taylor): symbolic Taylor expansion around a point.
  • Laurent series (laurent): expansion around poles with negative powers.
  • Rational arithmetic (rational): exact Rational type with GCD reduction, arithmetic, parsing.
  • Notebook (notebook): .mnb file format with cells of TeX/math expressions and results.
  • Web notebook server (server): minimal HTTP server serving a Jupyter-like web UI.
  • Interpolation (interpolate): Lagrange, Newton divided-difference, linear interpolation, and natural / clamped cubic splines.
  • Monotone interpolation (pchip): piecewise cubic Hermite (Fritsch–Carlson) that never overshoots the local data range.
  • B-spline interpolation (bspline): Cox–de Boor basis functions, de Boor curve evaluation, and clamped interpolating splines via knot averaging (with automatic degree reduction for few points).
  • Optimization (optim): derivative-free minimization — golden- section search in 1-D and Nelder–Mead simplex in N dimensions.
  • Special functions (special): Gamma, log-Gamma, Beta, erf, erfc, sinc, incomplete gamma P, Bessel functions J_0, J_1, J_n.

The CLI (mathr "<expr or command>") is a thin wrapper around the same library functions. It accepts plain math expressions, LaTeX/TeX input, and command keywords like diff, solve, int, gcd, etc.

Re-exports§

pub use error::MathError;
pub use error::Result;

Modules§

apart
Partial fraction decomposition (“apart”) for rational functions.
autodiff
Automatic differentiation using dual numbers.
bigdec
Arbitrary-precision decimal arithmetic.
bigint
Arbitrary-precision integer arithmetic for number theory.
bspline
B-spline basis, curves, and interpolating splines.
calculus
Numerical calculus: differentiation, integration, vector calculus helpers.
complex
curvefit
Levenberg–Marquardt nonlinear least-squares curve fitting.
dists
Probability distributions and classical hypothesis tests.
error
eval
expr
fastmath
Chebyshev-based fast approximations of transcendental functions.
fft
FFT implementation from scratch.
interpolate
Polynomial interpolation from scratch.
interval
Interval arithmetic for rigorous bounds on computations over the Expr AST.
laurent
Laurent series expansion from scratch.
limit
Symbolic limits: direct substitution, L’Hôpital’s rule, numeric fallback.
logit
Logistic regression via iteratively reweighted least squares (IRLS).
mathml
MathML (Presentation) export and import for Expr.
matrix
Matrix operations from scratch.
notebook
Math notebook format (.mnb) — a JSON-based notebook with cells of TeX/math expressions and their evaluated results.
numtheory
Number theory from scratch.
ode
Ordinary differential equation (ODE) solvers from scratch.
optim
Derivative-free function minimization.
parser
pchip
Monotone cubic Hermite interpolation (PCHIP, Fritsch–Carlson).
plot
Plotting via the plotters crate. Output is rendered to PNG files.
poly
Polynomial expansion (distribution) over the Expr AST.
prelude
Re-exports of the most common types for downstream use mathr::*;.
rational
Exact rational arithmetic.
repl
An interactive REPL that ties together the parser, evaluator, symbolic differentiation, numeric integration, root-finders and plotter.
serialize
Expression serialization for Expr in three interchangeable formats:
server
Minimal HTTP server for the math notebook web UI.
simplify
Algebraic simplification of Expr values.
solver
Equation solvers: Newton–Raphson, bisection, secant, and polynomial root finding via the Durand–Kerner method.
sparse
Sparse matrix storage (CSR/CSC) and iterative solvers.
special
Special functions from scratch.
stats
Descriptive statistics from scratch.
stiff
Implicit (A-stable) ODE solvers for stiff systems.
symbolic
Symbolic differentiation.
taylor
Symbolic Taylor series expansion from scratch.