lmnum

lmnum is a native numerical computing host for LMScript that embeds Eigen linear algebra, SUNDIALS ODE and nonlinear solvers, quadrature, root finding, and optimization.

Quick reference

Install lmctl and run any published numerical script directly, or declare cli="lmnum" in an LMScript _lmcode_ block. The current supported release is v0.1.4.

npm install -g @lmctl-ai/lmctl
lmctl https://raw.githubusercontent.com/lmctl-ai/lmnum/main/examples/linear_algebra.lms
MethodSignaturePurpose
num.matrix / identity / parse / linspacematrix constructors -> MatrixBuild dense double-precision matrices and column vectors
num.random / normal(rows, cols, seed) -> MatrixGenerate cross-platform deterministic uniform [0, 1) or standard normal matrices
num.load_csv / Matrix.save_csv(path: string)Load whitespace or comma CSV data and write exact round-trip space-separated tables
Matrix.solve / lstsq / inverse / detlinear algebra methodsSolve linear systems (FullPivLU), least squares, inverses, and determinants
Matrix.eig_sym / eigvec_sym / svd_* / choleskyfactorizations -> MatrixCompute symmetric eigendecompositions, thin SVD factors, and Cholesky L factors
num.ode(n)(n: int) -> OdeBuild and solve nonstiff (Adams) or stiff (BDF) ODE systems with SUNDIALS CVODE
num.system(n)(n: int) -> SystemSolve nonlinear systems F(x) = 0 with SUNDIALS KINSOL
num.integrate / integrate_tol(expr, var, a, b[, tol]) -> floatCompute 1D definite integrals with adaptive Gauss-Kronrod quadrature
num.root(expr, var, a, b) -> floatFind a bracketed root on [a, b] with Brent's method
num.minimize / minimize_path(expr, vars, guess) -> MatrixMinimize a multivariate objective with the Nelder-Mead simplex algorithm
num.polyfit / polyval / interpfitting and interpolationFit least-squares polynomials and evaluate 1D linear interpolants

Solve a stiff Robertson chemical kinetics ODE system with SUNDIALS CVODE BDF:

p = _lmcode_ cli="lmnum" install="github:lmctl-ai/lmnum@latest";
let ode = num.ode(3).stiff().tol(1e-8, 1e-12);
ode.rhs(0, "-0.04*y0 + 1e4*y1*y2")
   .rhs(1, "0.04*y0 - 1e4*y1*y2 - 3e7*y1*y1")
   .rhs(2, "3e7*y1*y1")
   .init(0, 1.0).init(1, 0.0).init(2, 0.0);
let sol = ode.solve(0.0, 40.0, 101);
num.assert_close(sol.get(100, 1) + sol.get(100, 2) + sol.get(100, 3), 1.0, 1e-9);
end _lmcode_
r = run_lmcode(p);
require(r.ok, "stiff ODE solve failed");

Documentation pages

Source repository and releases