Skip to content

Normalize root-counting chain entries to survive f32 at high degree - #344

Open
naseem173 wants to merge 5 commits into
kmolan:mainfrom
naseem173:fix/normalize-sturm-chain-f32
Open

Normalize root-counting chain entries to survive f32 at high degree#344
naseem173 wants to merge 5 commits into
kmolan:mainfrom
naseem173:fix/normalize-sturm-chain-f32

Conversation

@naseem173

Copy link
Copy Markdown
Contributor

What & why

Fixes #295. root_counting_chain built up each new Sturm-sequence entry from raw pseudo-division remainders with no rescaling, so the coefficient magnitudes could drift geometrically down the chain. For a degree-12 polynomial with two close pairs of roots (0.0001 apart), that drift ran an f32 chain entry to exact zero partway through, and count_real_roots returned 8 instead of 12 -- the same failure mode described in the issue.

The fix renormalizes each new chain entry to unit max-norm (divide every coefficient by the largest absolute coefficient) right after it is built. sign_changes is the only thing that reads the chain back out, and dividing by a positive scalar never changes a sign, so this is a no-op for correctness on every case that already worked -- it only prevents the coefficients from running out of range.

Added count_real_roots_survives_high_degree_f32/_f64, which build the degree-12 polynomial described above and assert the count is 12 at both f32 and f64. The f32 variant fails on main (finds 8) and passes with this change; the f64 variant passes either way, since f64 has enough range that this particular case doesn't run out of it

Checklist

  • cargo test + cargo clippy --all-targets clean locally
  • New public APIs have a doc example
  • No unwrap/expect/panic on library paths (typed errors instead)

Normalize coefficients to prevent overflow and underflow.
Added tests for counting real roots of high-degree polynomials, including a degree-12 polynomial with close pairs of roots to ensure accuracy.
@naseem173
naseem173 requested a review from kmolan as a code owner September 5, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Normalize the Sturm chain entries so high degrees survive f32

1 participant