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
| Method | Signature | Purpose |
|---|---|---|
| num.matrix / identity / parse / linspace | matrix constructors -> Matrix | Build dense double-precision matrices and column vectors |
| num.random / normal | (rows, cols, seed) -> Matrix | Generate 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 / det | linear algebra methods | Solve linear systems (FullPivLU), least squares, inverses, and determinants |
| Matrix.eig_sym / eigvec_sym / svd_* / cholesky | factorizations -> Matrix | Compute symmetric eigendecompositions, thin SVD factors, and Cholesky L factors |
| num.ode(n) | (n: int) -> Ode | Build and solve nonstiff (Adams) or stiff (BDF) ODE systems with SUNDIALS CVODE |
| num.system(n) | (n: int) -> System | Solve nonlinear systems F(x) = 0 with SUNDIALS KINSOL |
| num.integrate / integrate_tol | (expr, var, a, b[, tol]) -> float | Compute 1D definite integrals with adaptive Gauss-Kronrod quadrature |
| num.root | (expr, var, a, b) -> float | Find a bracketed root on [a, b] with Brent's method |
| num.minimize / minimize_path | (expr, vars, guess) -> Matrix | Minimize a multivariate objective with the Nelder-Mead simplex algorithm |
| num.polyfit / polyval / interp | fitting and interpolation | Fit 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");