libm-scalar-math retrofit sweep — rc40 (math.sqrt) + rc41 residue (math.{sin,cos,atan2} / math.pi)¶
2026-06-05 (srmech v0.7.0rc40). The §22 discipline closeout: when srmech
itself ships the scalar primitive, route the scalar fallback through srmech's
own A–N cascade, not libm. Now that srmech.amsc.rational.{sqrt,hypot} (rc35)
and rational.{sin,cos,tan,atan,atan2} (rc33) + the pi_cascade exist, the
remaining math.* scalar calls in shipped srmech are routable. This is the
sibling of the rc32 abs()-sweep and the rc33 numpy-math-sweep.
Full AST audit (26 real math.* routable references across 8 files)¶
A precise AST walk (real ast.Call / ast.Attribute nodes, ignoring
docstring/comment text) found 26 routable references. Note: rational.py,
pi_cascade.py and trigonometry.py have zero real calls — the float-trig
cascades are genuinely libm-free (the grep hits there are all docstrings).
| family | count | sites |
|---|---|---|
math.sqrt |
12 | laplacian.py ×5 (Jacobi), bell.py ×2, octonion.py ×1, sm.py ×3, hypercomplex_dft.py ×1 |
math.sin / math.cos / math.atan2 |
12 | kepler.py ×7, compose.py ×3, hypercomplex_dft.py ×2 |
math.pi |
2 | hypercomplex_dft.py ×1, form_function_rotation.py ×1 |
rc40 — math.sqrt routed (12 sites → rational.sqrt)¶
All 12 sites have provably non-negative arguments (sm.py guards >0;
octonion sum_sq ≥ 0; the Jacobi rotations are √(1+x²) ≥ 1 and 1/√d under
if d > 0), so rational.sqrt (which raises on negatives, matching nothing
libm-silent here) is a safe machine-ε drop-in.
amsc/laplacian.py— the 5 cyclic-Jacobi sites (the off-diagonal norm + the rotationt/cangles). Class L now visibly composes Class N: the eigensolver's leaf root is the Class-N rational sqrt. Verified Jacobi vsnumpy.linalg.eigvalsh= 8.9e-16.qm/bell.py— the Tsirelson bound2√2and1/√2constants (bit-exact 0.0).qm/octonion.py—octonion_norm(bit-exact 0.0).qm/sm.py— Higgs vev√(μ²/2λ), Z-mass√(g²+g'²), Yukawa1/√2(bit-exact 0.0). (sm.pyalready importedrational as _srn.)amsc/cascade/hypercomplex_dft.py— the1/√3normalisation constant (bit-exact 0.0).
import math was swapped for the rational import in the four modules that used
math only for sqrt (laplacian/bell/octonion/sm); hypercomplex_dft keeps it
(its cos/sin/pi are rc41 residue).
Ratchet: test_no_math_sqrt_hypot_anywhere_in_srmech (AST) — math.sqrt /
math.hypot calls only go DOWN to zero, never up. cmath.sqrt (genuine complex
root, e.g. the rc39 eigvals 2×2 shift discriminant — no rational peer) and
np.sqrt on a bulk array (no scalar-cascade peer for the vectorised op) are NOT
flagged.
rc41 — math.{sin,cos,atan2} + math.pi routed (14 sites)¶
Done. A different primitive family from rc40's sqrt, with its own machine-ε
anchor considerations (rc33 had to bump the trig float anchor 10**12 →
10**15), and kepler.py's Kepler-equation solver is an iterative Newton loop
where trig accuracy gates convergence — so this was verified machine-ε before
routing: sin 7.8e-16, cos 6.7e-16, atan2 4.4e-16 (all quadrants, multiple
periods); the cascade-π float (pi_cascade_digits(30) → float) is bit-exact
0.0 vs math.pi.
amsc/kepler.py×7 —cos/sin/atan2inpin_slot+ the Kepler Newton solver + the equation-of-centre series →rational.{cos,sin,atan2}.pin_slotbit-exact 0.0 vs libm; Kepler residual|E − e·sinE − M|= 4.4e-16.import mathdropped (kepler usedmathonly for trig).amsc/cascade/compose.py×3 —sinin the Kuramoto-coupling DSL worked examples →rational.sin.import mathKEPT (math.fsumis an exact numerical sum with no transcendental peer).amsc/cascade/hypercomplex_dft.py×2 +math.pi×1 — theexp(μθ)twiddlecos/sin+ the2πfactor →rational.{cos,sin}+ a module-level cascade-π float.import mathdropped.signal_processing/form_function_rotation.py×1 —math.piin the fundamental-mode eigenvalue → cascade-π (its trig was already_srn.cos/sin).import mathdropped.
Ratchet: test_no_math_trig_pi_anywhere_in_srmech (AST) — no
math.{sin,cos,tan,asin,acos,atan,atan2,exp,pi,tau} reference (call OR bare
constant) anywhere in shipped srmech. math.{gcd,isqrt,fsum} are exact integer /
numerical helpers and are NOT flagged.
The libm-scalar-math audit is now fully swept (12 sqrt @ rc40 + 14 trig/π @
rc41 = all 26 routable references). The only math.* remaining in shipped
srmech are gcd ×2, isqrt ×1, fsum ×1 — exact integer / numerical, no libm
transcendental.
Out of scope (legitimately stays)¶
cmath.sqrt— complex root; no rational complex-sqrt primitive. Scientific tier (the rc39 eigvals shift discriminant).np.sqrt(array)/np.cos(array)etc. on bulk arrays — vectorised math with no scalar-cascade peer; the container/bulk carve (elementwise_transcendentalis the explicit scientific-tier vectorised op). Replacing with a Python loop ofrational.*would be a perf catastrophe and is NOT what the discipline asks.**0.5scalar power-as-root — not surveyed here; a future micro-sweep if any appear (none flagged by the routable-math.*audit).