CGO_ENABLED=0LICENSE=BSD-3-ClauseTested onamd64arm64riscv64loong64ppc64les390xgo-numerics is the numerical layer of the Go scientific stack built on go-ndarray: optimisation and root finding, quadrature and ODE solvers, and special functions. Correct: every result is compared with an answer computed independently — SciPy, the netlib Fortran, and mpmath at 192 and 320 bits — and errors are measured, in ulps where it matters. Fast: timed against SciPy on one core, and faster on every case below.
func main() {
// Lotka–Volterra: prey y0 and predators y1.
lotka := func(t float64, y, dydt []float64) {
dydt[0] = 1.5*y[0] - y[0]*y[1]
dydt[1] = -3*y[1] + y[0]*y[1]
}
sol, err := integrate.SolveIVP(lotka, [2]float64{0, 15}, []float64{10, 5},
&integrate.IVPOptions{Method: integrate.DOP853, RTol: 1e-10, DenseOutput: true})
if err != nil {
panic(err)
}
// The dense output between the steps, and the steps themselves.
t := make([]float64, 600)
prey, pred := make([]float64, len(t)), make([]float64, len(t))
for i := range t {
t[i] = 15 * float64(i) / float64(len(t)-1)
y := sol.Sol.Eval(t[i])
prey[i], pred[i] = y[0], y[1]
}
stepPrey := make([]float64, len(sol.T))
for k, y := range sol.Y {
stepPrey[k] = y[0]
}
fig, axs := plot.Subplots(1, 1, plot.FigSize(6.4, 4))
ax := axs[0][0]
ax.Plot(t, prey, plot.Label("prey"))
ax.Plot(t, pred, plot.Label("predators"), plot.LineStyle("--"))
ax.Plot(sol.T, stepPrey, plot.Marker("o"), plot.LineStyle("None"),
plot.MarkerSize(3), plot.Color("C0"), plot.Label("accepted steps"))
ax.SetTitle(fmt.Sprintf("DOP853, rtol 1e-10: %d steps, %d evaluations", sol.NSteps, sol.NFev))
ax.SetYLim(-0.5, 19)
ax.SetXLabel(`time $t$`)
ax.Legend(plot.Loc("upper left"))
if err := fig.SaveSVG(os.Stdout); err != nil {
panic(err)
}
writeReadout(fig, ax, sol) // the solver's values under the page's pointer
}
integrate solves Lotka–Volterra with DOP853 at a relative tolerance of 1e-10; the lines are its dense output, the dots its accepted steps, and the title prints the counts it returned. go-plot drew the SVG. Point at the curves (or focus the figure and use the arrow keys): the readout is the solver's own float64, printed in full — the dense output every 0.005 in t, or an accepted step when the pointer is on its dot. The CI runs the program again and fails if one byte of the figure or of those values differs.
A census of 339 scientific notebooks set optimize's order — minimize, minimize_scalar, scalar roots, root, least_squares and curve_fit, linprog — and integrate and special cover quad, solve_ivp and the functions every statistic is computed with. Each Go function names the reference call it corresponds to.
Nelder–Mead, Powell, CG, BFGS, Newton-CG and L-BFGS-B; SLSQP and an interior-point method (trust-constr) with bounds, equality and inequality constraints; quadratic programming by a Goldfarb–Idnani active set and OSQP's ADMM; Brent, Ridder and Newton for scalar roots; MINPACK's hybrid method for systems.
Levenberg–Marquardt and trust-region reflective with bounds and robust losses; CurveFit with the parameter covariance, the model per point or over arrays (Model.Vec, one call per sweep as SciPy's); linear programming with duals.
QUADPACK ported from the netlib Fortran: singularities, infinite ranges, oscillatory and algebraic weights, Cauchy principal values; double, triple and N-dimensional integrals.
RK45, RK23, DOP853, Radau and BDF with events and dense output, and an automatic Runge–Kutta/BDF switch for problems that turn stiff.
Gamma, beta, erf and the normal distribution, incomplete gamma and beta and their inverses, Bessel functions of real order, zeta, elliptic integrals — and special/cmplx, a drop-in math/cmplx whose every part is measured in ulps against mpmath (Tanh(400+1i) is 1, not NaN).
Curve-fit data, covariances, LP matrices and ODE solutions are *ndarray.Array; special/nd applies a function element-wise with broadcasting, across cores.
The fixtures are written by scripts that call the reference — SciPy 1.18.1, the netlib Fortran, mpmath at 192 and 320 bits — committed, and compared in the tests. What differs, and why, is in each library's documentation.
116 of 124 fixture integrals take exactly SciPy 1.18.1’s subdivision path: the same evaluation count, the value to 1e-12. Three of the others are where SciPy’s C translation departs from the netlib Fortran, and this port agrees with the Fortran. (integrate)
110 of 120 solve_ivp runs of the ported methods take exactly SciPy’s steps: the same function evaluations, steps, Jacobians and LU decompositions. (integrate)
On the arithmetic-only problems, 36 of 38 Minimize runs take SciPy’s exact path (identical nit, nfev, njev); L-BFGS-B is bit-identical to SciPy’s C code built with sequential BLAS. (optimize)
100 of 100 statuses and 88 of 100 runs on SciPy’s exact path (nit, nfev, njev, multipliers) over 36 Hock–Schittkowski problems and 10 stress cases; on each of the other 12, SciPy’s own arm64 and x86_64 wheels disagree with each other. (optimize v0.3.0)
The interior-point method on the same 100 runs: success or failure as SciPy on all 100, every successful objective within 1e-5 of SciPy’s or 1e-4 of the optimum; 59 to 68 runs on SciPy’s exact path, where SciPy’s own two wheels disagree on 35. (optimize v0.4.0)
Quadprog’s ADMM runs exactly OSQP v1.0.0’s iterations (same status, iteration and ρ-update counts) on 38 of 38 planted and 12 of 12 sparse cases, and on 25 of 25 generated benchmark instances; on 33 Maros–Mészáros problems it reaches Clarabel’s objective on 27 and ends with OSQP’s own status on the other 6. The active set is checked against Clarabel and the quadprog package. (optimize v0.5.0)
Root/Fsolve: 23 of 23 runs with identical counts, status and message, x bit-identical. Linprog: 46 of 46 statuses against HiGHS, objective error at most 1.8e-15 with the simplex. (optimize)
About 250 000 points in 419 regions over 62 functions, against mpmath at high precision: the maximum error is at or below SciPy’s in 418 regions, and the one exception is a tie at 1.05 ulp. (special)
One thing broken at a time — a BFGS term dropped, a sign flipped in Moré–Thuente, a Kronrod weight nudged by 1e-6, a coefficient of the Γ(1+t) core moved by 1.5 ulp — and each break makes the suite fail. (optimize, integrate, special)
Medians of interleaved Go and SciPy 1.18.1 runs on one core of a shared 16-core Apple M4 Max, from each library's docs/perf.md; the rows marked refbench were started below a 1-minute load of 8, the others on a loaded host. SciPy's numbers include its Python callbacks, which is most of its time on small problems; the documentation gives them without, too. No case below is slower than SciPy today. The functions that still are, among them Yn and Iv, the incomplete beta function and Softmax (special v0.20.0, refbench 2026-11-16, SciPy only), are listed with their ratios in special#33.
| case | go-numerics | SciPy 1.18.1 | SciPy / Go |
|---|---|---|---|
| Brentq, x³ − 2x − 5 (optimize v0.9.0, refbench 2026-11-13) | 0.14 µs | 4.0 µs | 29× |
| Rosenbrock n=100, BFGS (optimize v0.9.0, refbench 2026-11-13, O(n²) update, within the accuracy contract) | 5.42 ms | 47.3 ms | 8.7× |
| Rosenbrock n=100, L-BFGS-B (optimize v0.9.0, refbench 2026-11-13, go-simd kernels, within the accuracy contract) | 2.23 ms | 11.7 ms | 5.3× |
| SLSQP, Hock–Schittkowski 71 (optimize v0.9.0, slsqpbench 2026-11-13, load 7.1–8.0) | 5.95 µs | 117 µs | 20× |
| trust-constr, Hock–Schittkowski 71 (optimize v0.9.0, slsqpbench 2026-11-13, load 7.1–8.0) | 527 µs | 33.5 ms | 64× |
curve_fit, 10⁴ points, LM, model per point / Model.Vec (optimize v0.9.0, refbench 2026-11-13) | 1.37 / 0.78 ms | 1.50 / 1.46 ms | 1.10× / 1.87× |
curve_fit, 10⁴ points, TRF, model per point / Model.Vec (optimize v0.9.0, refbench 2026-11-13) | 1.95 / 1.39 ms | 2.42 / 2.45 ms | 1.24× / 1.76× |
| ∫₀¹ log x/√x, Quad (integrate) | 4.7 µs | 30.1 µs | 6× |
| Lotka–Volterra, RK45 (integrate) | 18.1 µs | 1.67 ms | 92× |
| Van der Pol μ=1000, Radau (integrate) | 199.9 µs | 37.72 ms | 189× |
| Gamma, 10⁴ points, one thread (special v0.20.0, refbench v0.4.0 2026-11-16, load 4.0–8.0, SciPy only) | 8.37 ns/elem | 10.03 ns/elem | 1.20× |
Gamma, 10⁴ points, special/nd on one goroutine (special v0.20.0, same run) | 8.37 ns/elem | 9.98 ns/elem | 1.19× |
| Jn, integer-order Bessel J, 10⁴ points, one thread (special v0.20.0, same run) | 128 ns/elem | 722 ns/elem | 5.6× |
| Kn, integer-order Bessel K, 10⁴ points, one thread (special v0.20.0, same run) | 40 ns/elem | 357 ns/elem | 8.9× |
Minimisation (Nelder–Mead, Powell, CG, BFGS, Newton-CG, L-BFGS-B), constrained minimisation (SLSQP and the trust-constr interior-point method: bounds, equality and inequality constraints), quadratic programming (Quadprog: Goldfarb–Idnani active set and OSQP v1.0.0's ADMM, dense or sparse), scalar and system roots (Brent, MINPACK hybrd), nonlinear least squares (Levenberg–Marquardt, trust-region reflective, robust losses), curve fitting with covariance, linear programming (simplex, interior point).
Adaptive quadrature ported from the netlib QUADPACK, fixed and sample rules, double, triple and N-dimensional integrals, and initial value problems with RK45, RK23, DOP853, Radau, BDF and ODEPACK's LSODA (automatic Adams/BDF stiffness switching, with banded Jacobians, tcrit, hmin and an Exact option that equals SciPy's lsoda.c), with events and dense output. Release v0.3.0.
Gamma, beta, error and normal functions, incomplete gamma and beta and their inverses, Bessel, zeta, combinatorics, logistic helpers and complete elliptic integrals, each measured in ULPs against mpmath; special/nd applies them element-wise to go-ndarray arrays, across cores. Release v0.5.7: I1, I1e, K1 and K1e from fitted octave interpolants, faster and more accurate; Comb, Factorial, Factorial2 and Xlog1py faster with the same bits.
The documentation (Hugo + Hextra): one section per library, made of its own README, design, verification, accuracy and performance documents, with figures each library computed. Source →
Logos and icons for the organization, in SVG / PNG / JPG / ICO / ICNS across colour, white and black variants.
go-numerics computes on the arrays of go-ndarray, its results plot with go-plot, and a go-notebook cell can use all three. What is not in v0.1 yet — constrained minimisers, global optimisers, boundary value problems, complex-valued integrands — is listed in the documentation.
Read the source on GitHub →