Skip to content

v0.3.0 — complex_poly: polynomial evaluation and every root

Latest

Choose a tag to compare

@TYEclipse TYEclipse released this 22 Oct 21:49

v0.3.0 — complex_poly: polynomial evaluation and every root

New seventh tool: complex_poly — polynomials with complex coefficients, highest power first (["1","0","-1"] is z² − 1).

  • evaluate — p(z) and p'(z) by Horner's rule.
  • roots — every root up to degree 12 by the Durand–Kerner (Weierstrass) iteration, each with its round-off residual |p(z)|.
    • A multiple root such as (z − 1)² is reported once with multiplicity: 2, not as two near-identical numbers (neighbouring results are clustered at a 1e-6 relative distance).
    • converged is the real step-tolerance result. A run that misses it is marked false with the residuals and a "treat as estimates" note — it is never presented as exact.
    • Integer roots come back exact: z³ − 6z² + 11z − 6 → 1, 2, 3.
  • Edge cases are honest: all-zero coefficients, a non-zero constant (no roots), degree above the limit, an unparsable coefficient (named by coefficient[i]), or evaluate without z all return valid: false with the reason. Leading zero coefficients are trimmed and reported in note.

Quality

  • Expectations come from an independent oracle (test/oracle/anchors.py, section E): evaluation values from a direct power sum (the implementation uses Horner — different path), roots from closed forms (roots of unity, the quadratic formula, expanded products of known integer roots), each root re-substituted into p, plus the Vieta sum/product invariants. --check passes.
  • Tests 181 → 207; coverage 92.72% → 94.20% (baseline ratcheted up).
  • Lossless-JSON guard unified on the shared template helper (assertLossless: live undefined keys, -0, non-finite numbers) — 17 call sites switched.

v0.3.0 中文说明

新增第七个工具 complex_poly:复系数多项式(系数最高次在前,["1","0","-1"] 即 z² − 1)。

  • evaluate:Horner 法给出 p(z) 与 p'(z)。
  • roots:Durand–Kerner(Weierstrass)迭代求全部根(次数 1–12),每根附回代残差 |p(z)|。
    • (z − 1)² 这类重根只报一次并标 multiplicity: 2,不会给出两个几乎相同的数(相邻结果按 1e-6 相对距离归并)。
    • converged 是真实步长判据:未达容差就标 false 并附残差与「按估计值看」的提示,绝不冒充精确解。
    • 整数根原样返回:z³ − 6z² + 11z − 6 → 1, 2, 3。
  • 边界如实报错:全零系数、非零常数(无根)、次数超限、某系数不可解析(按 coefficient[i] 点名)、evaluate 缺 z,一律 valid: false + 原因;前导零系数自动裁掉并在 note 说明实际次数。

质量:期望值来自独立 oracle(test/oracle/anchors.py E 区)——求值走直接幂和、根走闭式并逐根回代 + 韦达不变量,--check 全绿;测试 181 → 207 条,覆盖率 92.72% → 94.20%(基线棘轮上调);无损 JSON 口径统一到共享模板 assertLossless。

Install

dsh plugin --profile web add github:TYEclipse/dsh-complex#v0.3.0