Repository navigation
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)andp'(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 withmultiplicity: 2, not as two near-identical numbers (neighbouring results are clustered at a 1e-6 relative distance). convergedis the real step-tolerance result. A run that misses it is markedfalsewith 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.
- A multiple root such as
- Edge cases are honest: all-zero coefficients, a non-zero constant (no roots), degree above the limit, an unparsable coefficient (named by
coefficient[i]), orevaluatewithoutzall returnvalid: falsewith the reason. Leading zero coefficients are trimmed and reported innote.
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 intop, plus the Vieta sum/product invariants.--checkpasses. - Tests 181 → 207; coverage 92.72% → 94.20% (baseline ratcheted up).
- Lossless-JSON guard unified on the shared template helper (
assertLossless: liveundefinedkeys,-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