Skip to content

Releases: TYEclipse/dsh-complex

v0.3.0 — complex_poly: polynomial evaluation and every root

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

v0.2.0 — inverse functions, complex powers, quadratic solver

Choose a tag to compare

@TYEclipse TYEclipse released this 04 Oct 21:53

dsh-complex v0.2.0 — inverses, complex powers, quadratic solver

Maintenance release (R60) of the complex-number toolbox. Three user-visible additions, one real correctness fix.

Added

  • complex_quadratic — solve a z² + b z + c = 0 with complex coefficients: the discriminant, both roots (principal square root first), the Vieta invariants −b/a and c/a, and each root's residual |a z² + b z + c| so the answer is self-checking. a = 0 degrades to the linear equation; a = b = 0 reports "every complex number is a solution" or "no solution" instead of inventing a root. Example: z² + i z + 1 = 0 → 0.6180339887i, -1.6180339887i.
  • complex_calc(operation="pow") — general complex power a^b = exp(b·log a) with both operands complex: i^i = 0.2078795764, 2^(1+i) = 1.5384778027+1.2779225526i, (-1)^0.5 = i. 0^(positive real) = 0; 0^0 and 0^(non-positive real) are honest errors.
  • complex_functions — six inverse functions: asin, acos, atan, asinh, acosh, atanh, with the branch cut of each reported in the result note.

Fixed

  • Silent conjugate values on the branch cuts. The naive principal-square-root identities return the conjugate value exactly on the cuts (real |x| > 1, imaginary |y| > 1): asin(2) came back as 1.5707963268-1.3169578969i instead of 1.5707963268+1.3169578969i, with the same defect in atanh(2), atan(±2i) and asinh(±2i). The cut cases now use the explicit C99 continuation (asin(x) = sign(x)·π/2 + i·acosh|x|, atan(iy) = π/2 + i·sign(y)·atanh(1/|y|), asinh(iy) = acosh|y| + i·sign(y)·π/2, atanh(x) = atanh(1/x) + iπ/2, acos = π/2 − asin) and are verified point-by-point against CPython cmath on a grid that includes all four cuts.

Changed

  • The oracle now ships with the repository: test/oracle/anchors.py (sections A legacy / B inverses & cuts / C complex powers / D quadratic, with a --check self-test) — it replaces the throwaway script that previously lived in /tmp.
  • Tests 123 → 181; coverage baseline 88.60% → 92.72%.
  • complex_calc's integer power and every existing tool anchor are unchanged (no regressions).

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


中文说明

新增

  • complex_quadratic:求 复系数 二次方程 a z² + b z + c = 0——判别式、两根(主平方根那支在前)、韦达不变量 −b/a 与 c/a、每根回代残差(答案自检);a = 0 退化为一次方程,a = b = 0 时如实报「任意复数皆解 / 无解」,不编造根。
  • complex_calc 新增 pow:任意复幂 a^b = exp(b·log a)(两操作数都可为复数)——i^i、2^(1+i)、(-1)^0.5;0^(正实数) = 0,0^0 与 0^(非正实数) 诚实报错。
  • complex_functions 新增 6 个反函数:asin / acos / atan / asinh / acosh / atanh,各自切割位置写入结果 note。

修复

  • 分支切割上的静默错误:朴素「主平方根恒等式」在实轴 |x| > 1、虚轴 |y| > 1 的切割上会返回共轭值(asin(2) 曾给 −1.3169578969i,实为 +1.3169578969i;atanh(2)、atan(±2i)、asinh(±2i) 同型)——切割处改用显式 C99 延拓,并用覆盖四条切割的网格逐点与 cmath 对齐。

变更

  • oracle 随仓提交(test/oracle/anchors.py,--check 自校验),取代原先放在 /tmp 的一次性脚本。
  • 测试 123 → 181;覆盖率基线 88.60% → 92.72%;既有工具锚点无回归。

安装:dsh plugin --profile web add github:TYEclipse/dsh-complex#v0.2.0

v0.1.0

Choose a tag to compare

@TYEclipse TYEclipse released this 08 Sep 22:02

v0.1.0 — initial release

Five pure-math tools for complex arithmetic on the principal branch, zero runtime dependencies:

  • complex_parse — parse "3+4i" / "-2i" / "5∠53.13°" (i or j, implicit coefficient 1, scientific notation) into the full identity: rectangular/polar/exponential forms, modulus, argument (rad + deg), conjugate
  • complex_calc — add / subtract / multiply / divide / conjugate / reciprocal / integer power (De Moivre, exponent −1000..1000)
  • complex_convert — polar ↔ rectangular conversion
  • complex_functions — principal values of exp / log / sin / cos / tan / sinh / cosh / sqrt, with branch conventions reported in the result note
  • complex_roots — all n n-th roots (n = 1..64), listed from the principal root

Deterministic closed-form arithmetic: raw IEEE doubles during computation, rounding + dust-snapping only at the output boundary (10 decimals by default, configurable). 123 tests, all anchored by an independent Python cmath oracle.


v0.1.0 —— 首发版本

主值分支上的复数运算,5 个纯数学工具,零运行时依赖:

  • complex_parse — 解析 "3+4i" / "-2i" / "5∠53.13°"(i/j 均可、系数 1 可省略、科学计数法)→ 完整身份:直角/极坐标/指数形式、模、辐角(弧度与角度)、共轭
  • complex_calc — 加 / 减 / 乘 / 除 / 共轭 / 倒数 / 整数幂(De Moivre,指数 −1000..1000)
  • complex_convert — 极坐标 ↔ 直角坐标互转
  • complex_functions — exp / log / sin / cos / tan / sinh / cosh / sqrt 的主值,分支约定写入结果 note
  • complex_roots — 全部 n 个 n 次方根(n = 1..64),从主根起排列

确定性闭式计算:计算过程保留原始 IEEE double,仅在输出边界做舍入与尘埃归零(默认 10 位小数,可配)。123 个测试全绿,全部锚点由独立 Python cmath oracle 生成。