Reference implementation of the Fernández Molina series method for solving cubic equations (AIP Advances 12, 045002, 2022).
Project description
fmcubic
A serious, honest Python implementation of the Fernández Molina series method for cubic equations.
Reference: Fernández Molina, R. A., Sigalotti, L. Di G., Rendón, O., & Mejías, A. J. (2022). A rapidly convergent method for solving third-order polynomials. AIP Advances 12, 045002. https://doi.org/10.1063/5.0073851
Authors of the mathematical method: Ramón A. Fernández Molina · Leonardo Di G. Sigalotti · Otto Rendón · Antonio J. Mejías
Reference Python implementation of the method. Explicit about what is faithful to the paper and what is a practical fallback in IEEE-754 double precision.
Install
pip install -e .
# or just drop the `fmcubic/` folder next to your code
Requires Python ≥ 3.11 (uses math.cbrt).
Usage
from fmcubic import solve_cubic
res = solve_cubic(1, -6, 11, -6)
print(res.method) # → "Fernández Molina (trigonometric fallback, Δ<0)"
print(res.branch) # → "trig-viete"
print(res.iterations) # → 1
for r in res.roots:
print(r) # → 1, 2, 3
print(res.notes)
solve_cubic returns a SolveResult with:
| field | meaning |
|---|---|
roots |
three Complex(re, im) roots |
method |
human-readable branch label |
branch |
machine tag (series-A-Eq17, trig-viete, …) |
iterations |
series terms or Newton iterations |
convergence_trace |
per-step approximation of x₁ |
p, q, delta |
depressed-cubic invariants |
ratio |
q²/(4Δ) — the series convergence ratio |
notes |
free-form caveats |
Branch tree
| Tag | Condition | Origin in paper | Status |
|---|---|---|---|
triple-root |
p≈0 ∧ q≈0 | trivial | paper-faithful |
p-axis-Eq57 |
p≈0, q≠0 | Eq. (57) | paper-faithful |
delta-zero |
Δ≈0 | closed form | paper-faithful |
curve-Eq37-58 |
p³ + 27q²/2 ≈ 0 | Eq. (37) + (58) | paper-faithful |
series-A-Eq17 |
Δ>0, | q²/(4Δ) | < 1 |
series-B-Eq30 |
Δ>0, | q²/(4Δ) | > 1 |
buffer-newton |
ratio | ||
trig-viete |
Δ < 0 | Viète | numerical equivalent |
The complex-branch series proposed in the paper for Δ<0 is not implemented faithfully — we use Viète's trigonometric form, which is mathematically exact but is a substitution, not a faithful execution.
Numerical honesty
The solve_cubic docstring spells this out, and the Patel-Teja benchmark
demonstrates it:
Δ = q²/4 + p³/27suffers catastrophic cancellation when q²/4 ≈ −p³/27 (e.g. Patel-Teja case V: ~10⁵¹ + ~10⁵¹ → ~10³⁷). In double precision this leaves ~2 significant digits of Δ.- The series method consumes the ratio 4Δ/q², which is far less sensitive — but any caller using Δ directly should be aware.
- Some polynomials evaluate to
f(x) == 0.0exactly in IEEE-754 at a point that does not satisfy Vieta's relations (spurious zero). Usevieta_residuals(A, B, C, D, roots)to detect this.
Patel-Teja benchmark
from fmcubic import run_patel_teja_validation
report = run_patel_teja_validation()
print("OK?" , report.overall_pass)
for cr in report.cases:
print(cr.case.id, "Δ=", cr.delta, "pass=", cr.pass_overall)
for m in cr.methods:
print(" ", m.method, m.picked, "vieta-sum=", m.vieta["sum"])
| Case | Conditioning | Validation criterion |
|---|---|---|
| Z | severe (Δ ≈ 10⁻³⁴) | FM↔Cardano consensus |
| ρ | well conditioned | FM matches paper to <1e-7 % |
| V | extreme (10⁵¹+10⁵¹) | FM↔Cardano consensus + Vieta check |
Tests
python -m pip install pytest
python -m pytest -q
Covers: triple root, p=0/q≠0, Δ=0, three real roots, complex conjugates, extreme coefficients, buffer zone, Patel-Teja Z/ρ/V, and Vieta consistency.
What's faithful and what isn't (one-page summary)
Faithful to the paper:
- Depression to
y³ + py + q = 0and shift recovery. - All four closed-form special cases (B1-B4) including the special
curve
p³ + 27q²/2 = 0(Eqs. 37 + 58). - Series A (Eq. 17) and Series B (Eq. 30) with incremental binomial
recurrence
c_{i+1} = c_i · (1/3 − i)/(i+1). - Stabilized Eq. (51)-(53) deflation Γ for the other two roots.
Practical / equivalent:
- Trigonometric (Viète) form for Δ<0 — paper proposes a complex series; we substitute the closed form.
- A small buffer zone around |ratio|=1 that switches to Newton-Raphson because the series convergence is impractically slow there.
Not yet implemented:
- The complex-branch series for Δ<0.
- Extended-precision (≥128-bit) mode required to reproduce Patel-Teja cases Z and V exactly.
Mathematical method © Fernández Molina, Sigalotti, Rendón & Mejías (2022). Please cite: AIP Advances 12, 045002. https://doi.org/10.1063/5.0073851
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fmcubic-0.1.0.tar.gz.
File metadata
- Download URL: fmcubic-0.1.0.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b2b3769b0f1f0096091ef3d38239a16c4bb8f659d5fd6d60094bd83ed7c5ad9
|
|
| MD5 |
58c880689681e57f536ca9f6377efd0e
|
|
| BLAKE2b-256 |
92dc20b6c48ef41df74bbdaa0e01e97d9ce2f2bd27f28e3598b5d30dcde33d01
|
File details
Details for the file fmcubic-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fmcubic-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c6f95bfbe53a319be65d162cf576e7a025042e3dc60b3da9198394149bf14fe
|
|
| MD5 |
905afc26c6356d2e1ea81587c1cc70a0
|
|
| BLAKE2b-256 |
dc110656b7c6a8dc7b32fe4d52a0e7a2c30a1d70d23a0f10ef62420e67ad027f
|