Skip to content

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

Choose a tag to compare

@TYEclipse TYEclipse released this 04 Oct 21:53
· 1 commit to main since this release

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