
CyRoot
Root finding in Cython. Python callbacks when convenient, native callbacks when speed matters.
cy-root solves scalar equations and nonlinear systems with bracketing,
Newton-type, quasi-Newton, and optimization-based methods. It combines a broad
algorithm selection with resumable solvers, bounded iteration histories, and
analytic or numerical derivatives.
- Start in Python. Pass ordinary functions; vector callbacks receive tuples and can return sequences or NumPy arrays.
- Compile the hot path. Native callback adapters let Cython/C++ consumers execute the numerical loops without the GIL. Python callbacks still acquire it.
- Inspect each iteration. Run to completion or step through a solver, with copied states, call counts, and explicit stopping reasons.
- Use higher derivatives. Scalar Householder uses a native runtime-order recurrence; vector derivative plans include Jacobians, Hessians, and higher mixed partials.
The examples below use the 2.0 API, which introduces breaking changes from 1.x.
See The Iterations
Scalar Equations
Bisection contracts a bracket; Newton follows a tangent; Halley uses second-order information. The animation replays the actual solver histories for the same cubic.
Nonlinear Systems
Newton and Powell dogleg start at the same point on a curved residual valley. Newton first moves outside the close-up; dogleg takes a longer path of smaller steps. Both reach the root in this example.
For a 3D view, plot the residual norm as height: $z=|F(x,y)|_\infty$. The two horizontal axes are input coordinates. All residual components vanish where the surface meets the zero plane ($z=0$). A positive local minimum is not a root. Height is linear; surface colors use a logarithmic scale.
Watch The 3D Residual Surface
These are iteration comparisons, not timing benchmarks. Derivative costs and trial evaluations differ between methods. Background curves and contours are sampled separately from the recorded solver calls.
Try different methods locally:
python -m pip install -e '.[examples]'
python examples/scalar_steps.py --methods brent secant householder
python examples/vector_steps.py --methods broyden lbfgs
python examples/vector_steps.py --view surface
The figures have sliders. Their rendering helpers live in examples/plotting.py, outside the package API, and take copied histories and plot callables. You can reuse them in a notebook or replace them with your own plots. Jupyter is not required.
Install
Install the 2.x release:
python -m pip install 'cy-root>=2,<3'
To build from a source checkout:
git clone https://github.com/inspiros/cy-root.git
cd cy-root
python -m pip install -e .
The source targets Python 3.11–3.14 and requires NumPy and SciPy. Building from source also requires Cython 3.3.0, a C++17 compiler, and Python development headers. SciPy supplies native BLAS/LAPACK; the numerical core can call these without the GIL. See building and testing for local checks.
Documentation
Read the manual, choose a method, or build the documentation website. The manual covers native callbacks, numerical derivatives, and the shared stopping rules.
Quick Start
A Scalar Root
from cyroot import bisect, newton
def f(x):
return x*x - 2.
bracketed = bisect(f, 1., 2.)
analytic = newton(f, lambda x: 2*x, 1.5)
numerical = newton(f, None, 1.5) # Native finite-difference plan.
assert bracketed.success and analytic.success and numerical.success
print(analytic.root) # Approximately 1.414213562373095.
Algorithm controls and stopping tolerances are keyword-only. Newton-type and
optimization-based entry points keep the function, derivative providers, and
starting point in that order; use None for a numerical derivative.
A Vector Root, Including Rectangular Systems
from cyroot import generalized_newton
def residual(point):
x, y = point
return (x - 1., y - 2., x + y - 3.)
result = generalized_newton(residual, None, (0., 0.))
assert result.success
print(result.root) # Approximately (1., 2.).
Here the Jacobian has three rows and two columns: three residuals, two unknowns. Newton uses a rank-aware least-squares step for rectangular systems. Shape support depends on the method; Broyden and several other quasi-Newton methods expect square systems.
Native Callbacks
From a source checkout, compile the typed Python example:
python -m pip install Cython==3.3.0 setuptools
cd examples
python pure_python_callback_setup.py build_ext --inplace
Then pass its native callback descriptors to the same Newton interface:
from cyroot import newton
import pure_python_callback as native
result = newton(native.callback(), native.derivative_callback(), 1.5)
assert result.success
assert abs(result.root - 2.**.5) < 1e-10
The example compiles x*x - 2 and 2*x into native functions. Its small ABI
bridges let the solver call them without the GIL. Passing the compiled Python
wrapper native.residual directly still uses Python's call machinery. This is
ahead-of-time compilation; CyRoot does not JIT-compile arbitrary Python functions.
Higher-Order And Optimization-Based Methods
from cyroot import halley, householder, scalar_lbfgs
f = lambda x: x*x - 2.
third_order = halley(f, lambda x: 2*x, lambda x: 2., 1.5)
higher_order = householder(f, None, 1.5, d=4)
optimized = scalar_lbfgs(f, lambda x: 2*x, 1.5)
assert third_order.success and higher_order.success and optimized.success
The optimization family minimizes a residual objective and then checks the original root tolerance. A stationary point with a nonzero residual is reported as a failure to find a root. Scalar and vector conveniences are available for Levenberg–Marquardt, BFGS, L-BFGS, and Powell dogleg. An external-optimizer bridge can also reuse a residual objective and its transformed derivatives.
Step, Inspect, Resume
from cyroot import as_root_snapshot
from cyroot.native import Newton
solver = Newton(lambda x: x*x - 2., lambda x: 2*x, 1.5, history=32)
first = as_root_snapshot(solver.step())
final = as_root_snapshot(solver.run())
history = tuple(map(as_root_snapshot, solver.history))
assert final.residual_converged
assert history[-1].root == final.root
print(first.root, final.f_calls, final.termination_reason)
RootSnapshot provides common scalar/vector values and retains the original
record in diagnostics. History is bounded and opt-in; history_truncated
reports when the capacity was insufficient. Hybisect's multi-root searches keep
a separate search/event interface.
Check the stopping reason as well as success: scalar bracket convergence can
establish success before the residual meets its tolerance.
residual_converged distinguishes those outcomes. Precision stagnation and
optimizer stationarity do not by themselves establish a residual root.
Algorithms
| Family | Scalar equations | Vector systems |
|---|---|---|
| Bracketing | Bisection, Hybisect, regula falsi, Illinois, Pegasus, Anderson–Björck, Dekker, Brent, Chandrupatla, Ridders, TOMS748, Wu, ITP | Vrahatis sign-polygon bisection |
| Newton-type | Newton, damped Newton, Homeier, Halley, Super-Halley, Chebyshev, tangent hyperbolas, runtime-order Householder | Generalized Newton, damped Newton, matrix-free Newton–Krylov (GMRES/LSQR), Halley, Super-Halley, Chebyshev, tangent hyperbolas |
| Quasi-Newton / interpolation | Secant, Sidi, Steffensen, inverse quadratic interpolation, hyperbolic interpolation, complex Muller | Wolfe–Bittner, Robinson, Barnes, Traub–Steffensen, good/bad Broyden, Klement |
| Optimization-based | Levenberg–Marquardt, BFGS, L-BFGS, Powell dogleg | Levenberg–Marquardt, BFGS, L-BFGS, Powell dogleg |
Derivative plans support scalar derivatives and dense vector tensors of shape
(outputs, inputs, ..., inputs), with memory and stencil budgets. Analytic and
numerical providers can be combined. Higher tensor orders have substantial
storage and sampling costs.
Numerical derivative providers include fixed finite differences, adaptive Richardson refinement, and complex-step for holomorphic residuals. Plans cover scalar derivatives, rectangular Jacobians, full mixed Hessians, and higher tensors. See the numerical derivative example.
SCALAR_ROOT_FINDING_METHODS and VECTOR_ROOT_FINDING_METHODS expose supported
method names. Use direct functions or the find_scalar_root / find_vector_root
dispatchers.
Citation
If CyRoot supports your research, please cite the software using the all-versions DOI. Citation metadata in this repository describes version 2.0.1. GitHub's Cite this repository button provides BibTeX and APA citations.
License
MIT licensed, see LICENSE.
Metadata
Release files for cy-root 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cy_root-2.0.1.tar.gz | 2.2 MB | Without provenance | Details for cy_root-2.0.1.tar.gz |
Built distributions (wheels)
Total release size: 129.3 MB
Release files / cy_root-2.0.1.tar.gz
| Download URL | cy_root-2.0.1.tar.gz |
|---|---|
| Size | 2.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
89beaa9a75a3983eb8aaf5ba0e7b011cff0001ff6410b0130ab1f01b4b1296d1
|
|
BLAKE2b-256 checksum How to use checksums |
54ffc7ad8b29631beee72c163019fb776314da297a75856a93c9a343803de243
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp314-cp314-win_amd64.whl
| Download URL | cy_root-2.0.1-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 3.4 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
29287c191b3903e4f43b54268623e772f87fff27fbfc9462a74142767381610a
|
|
BLAKE2b-256 checksum How to use checksums |
a6779c94de2e1bb6c56c2d1e3c6d767568403011bcdd322fc61bd8bbb4ebd3be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cy_root-2.0.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 24.4 MB |
| Tags | CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
b2d49aa22256ad72356a65c1fcfe761b659fa6ce63b6ad65601062153f5cd12a
|
|
BLAKE2b-256 checksum How to use checksums |
65bd7a30efa22c0f2dd447580666b51c161a5521148feb48bc7d514c1e405b9a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | cy_root-2.0.1-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
6992c5bbec020c655e5684cc9a958d865d610daff95a631e460746dff8c62b1a
|
|
BLAKE2b-256 checksum How to use checksums |
37ad6abeef2402747d1d655e82e463caad6cbbcb4efbcfae55768724cfb7dfe8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp313-cp313-win_amd64.whl
| Download URL | cy_root-2.0.1-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 3.3 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
cb436e5d29b7a581405a8e56af83db9134c64bba8abf0711abe87b4bd80f420e
|
|
BLAKE2b-256 checksum How to use checksums |
19c0d4b8ebe81ea4e90aab6db1dc0de250a6e30438916a8b177a92848fc1e7ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cy_root-2.0.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 24.7 MB |
| Tags | CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
09abd4a8975951f42470bb34c8a5cf2b6a2f7f5a10e6a4ae69f986ebdde9f331
|
|
BLAKE2b-256 checksum How to use checksums |
18f6e608dc0121eb33d8653abac71b2d66cc11f3f15aa2606ec40f4271c2e6fb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | cy_root-2.0.1-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f077f3b15744a7b3c185309b3dbab9d11e0659c2e6b2d09906064cfde3b824c4
|
|
BLAKE2b-256 checksum How to use checksums |
c47fc08e812aa72b598b128887baf4c8e23063de319f286cc354e2b1111a478d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp312-cp312-win_amd64.whl
| Download URL | cy_root-2.0.1-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 3.3 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
1b551c8e9ec5c4ab8184d6d1030d222e9ec058b41a416d7b3630014a7b9c84b7
|
|
BLAKE2b-256 checksum How to use checksums |
cc9b10c5465c109b657d12b3a8979c8582746369e0e53fa99e2ae1dd4c033494
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cy_root-2.0.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 24.9 MB |
| Tags | CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
373d81665e7cc57143b742df7dcf898ca5a2cc0947d8cf95ae10a62dbbece135
|
|
BLAKE2b-256 checksum How to use checksums |
a050369c562f0e1e733bc36475bc32d83d1c06541c63ff28477c88f4d7d12898
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | cy_root-2.0.1-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
39cbdabff971cc5bb96eed2f4e107126c980ea75811bea1be31d2c213547e66d
|
|
BLAKE2b-256 checksum How to use checksums |
157d2561a298f10de44753758db9c7a8968f8db42a295561381b75466301cc35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp311-cp311-win_amd64.whl
| Download URL | cy_root-2.0.1-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 3.3 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
fe79055d800dc30b2a81edf5a81108cd47ed01f4b0f1c1c631b3c47b2a289f87
|
|
BLAKE2b-256 checksum How to use checksums |
3e5784d0873d2a7a6cb139f58c72e8bc9721825a180f4181286050e325e1fa22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cy_root-2.0.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 24.8 MB |
| Tags | CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
a66cf12526391ff14aafa9f1056483c7a67ccffb8721bf6840415b5d7a3965cd
|
|
BLAKE2b-256 checksum How to use checksums |
72879597a43c269c33f35b0768b07654fd48910fd30bfa9cf8ae7b9481983f4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / cy_root-2.0.1-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | cy_root-2.0.1-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
723a9a1e32590e8833237d2f71e801a4e83b6432a5f5916fe100c1c68dbeeecc
|
|
BLAKE2b-256 checksum How to use checksums |
cfa27da4fc8ca7d4e0d720141cdee07505bfc6dd816cae95c6a54a29ee8c8388
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for cy-root 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.