Library for root finding of single-valued real functions?

123 views
Skip to first unread message

awaw...@gmail.com

unread,
Mar 4, 2025, 10:11:06 AMMar 4
to golang-nuts
Hi Fellow Gophers

I wonder what is the canonical Go library for finding roots of single-valued real functions?

In particular, I am finding an implementation of Brent's method.
Brent's method is the default algorithm in R, Matlab, and Scipy.

Gonum has a pretty comprehensive list of facilities for optimization, but I couldn't find one that does simple root finding.
There seem to be two packages out there that implement Brent's method, but they are of dubious provenance:
* https://pkg.go.dev/github.com/cpmech/gosl/num#Brent . Relies on the derivative of f, f'(x), which shouldn't be the case for Brent's method. Plus, it pulls in a deluge of dependencies, and is not in pure Go.
* https://pkg.go.dev/go.skia.org/infra/pinpoint/go/compare/stats . The zeroin function is not even exported, so presumably of unknown quality.

Jason E. Aten

unread,
Mar 4, 2025, 4:49:44 PMMar 4
to golang-nuts
I can't speak to canon (the intersection of Gophers and numerical people is 
already the intersection of two small niches...so there's not a whole lotta canon),
but Brent's method is standard stuff straight out of Numerical Recipes, Section 9.3, page 352


( I see this is cited by the cpmech/gosl library you referenced.) Anyway -- it's a very 
short method and you can probably have an LLM give you Go implementation or port in 20 seconds. 
Ask your LLM to write you some tests too and you should be good to go in another
couple of minutes.

Message has been deleted

awaw...@gmail.com

unread,
Mar 5, 2025, 5:46:23 AMMar 5
to golang-nuts
Hi Jason

Thanks for providing a great reference: Numerical Recipes!
I have followed your suggestion and filed https://github.com/gonum/exp/pull/65 accordingly.
Reply all
Reply to author
Forward
0 new messages