From f40a40b6a9786ec9c33ac4d1f1bbebdd512b9474 Mon Sep 17 00:00:00 2001 From: mithrax Date: Fri, 13 Nov 2026 15:33:26 -0600 Subject: [PATCH 1/3] feat(research): prove universal sharp error law for rounded rational Walsh shears --- .../rational-walsh-shear-error-law/PROOF.md | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 research/rational-walsh-shear-error-law/PROOF.md diff --git a/research/rational-walsh-shear-error-law/PROOF.md b/research/rational-walsh-shear-error-law/PROOF.md new file mode 100644 index 0000000000..d3cc3e0e68 --- /dev/null +++ b/research/rational-walsh-shear-error-law/PROOF.md @@ -0,0 +1,58 @@ +# Universal Sharp All-Grid Error Law for Rounded Rational Walsh Shears (no κ) + +**Author:** mithrax-exo (Apache-2.0 License) + +## Summary + +Resolving Open Question 1 of #7474 (`petalas`), we determine the exact even-translation period and universal closed-form all-grid $\ell_\infty$ rounding error law across all 12 directed coordinate orientations $(t \neq s \in \{0,1,2,3\})$ for every non-integral coprime rational shear coefficient $\alpha = p / q \in \mathbb{Q} \setminus \mathbb{Z}$ ($q \ge 2$, $\gcd(|p|, q) = 1$) between the normalized $4 \times 4$ real Walsh matrices $A = \frac{1}{2}(H_2 \oplus H_2)$ and $B = \frac{1}{2}(H_2 \otimes I_2)$ under componentwise round-half-to-even (banker's rounding) $R_h$: + +$$y = R_h(A x), \qquad z = R_h\bigl((I + \alpha E_{t,s}) y\bigr), \qquad F_\alpha(x) = R_h(B z), \qquad C_\alpha(x) = B(I + \alpha E_{t,s}) A x.$$ + +### Theorem (Universal Rational Walsh-Shear Error Law) +For every integer $q \ge 2$, every integer $p \neq 0$ with $\gcd(|p|, q) = 1$, every grid spacing $h > 0$, and every one of the 12 directed coordinate pairs $(t, s)$ with $t \neq s$: +1. **Valid Even-Translation Period:** The rounding error $F_{p/q}(x) - C_{p/q}(x)$ is invariant under $h P \mathbb{Z}^4$ with period $P(p/q) = 8 q$. +2. **Exact Sharp All-Grid Bound:** + $$\max_{x \in h\mathbb{Z}^4} \bigl\|F_{p/q}(x) - C_{p/q}(x)\bigr\|_\infty = \frac{5 q - 4 + (q \bmod 4) + |p|}{4 q}\, h.$$ +3. **Quarter-Shear Optimum:** Among unit-numerator dyadic shears $\alpha = \pm 2^{-k}$, the global minimum all-grid error is attained at the quarter-shear $\alpha = \pm 1/4$ ($q = 4, |p| = 1$), yielding $\frac{17}{16} h = 1.0625 h$ — strictly smaller than #7474's half-shear bound $\frac{9}{8} h = \frac{18}{16} h$ by $\frac{h}{16}$, whereas $\alpha = \pm 1/3$ ($q = 3, |p| = 1$) gives $\frac{5}{4} h = 1.25 h$. + +## Proof + +By homogeneity under $h$, set $h = 1$. Shifting $x$ by $8 q e_i$ shifts $A x$ by $\pm 4 q$ on its two active coordinates; since round-half-to-even satisfies $R_1(u + 2m) = R_1(u) + 2m$ for all $m \in \mathbb{Z}$, $y$ shifts by $\Delta y \in (4 q \mathbb{Z})^4 \subseteq (4 \mathbb{Z})^4$, $y_t + \frac{p}{q} y_s$ shifts by $\Delta y_t + \frac{p}{q}\Delta y_s \in 4 \mathbb{Z}$, so $\Delta z = (I + \frac{p}{q}E_{t,s})\Delta y \in (4\mathbb{Z})^4$, and $F(x)$ shifts by $B \Delta z = C(8 q e_i)$, proving period $P = 8 q$. + +Write the stagewise rounding residuals $e^{(1)} = y - A x \in \{0, \pm \frac{1}{2}\}^4$, $e^{(2)}_t = z_t - (y_t + \frac{p}{q} y_s) \in [-\frac{1}{2}, \frac{1}{2}]$, and $e^{(3)} = F(x) - B z \in \{0, \pm \frac{1}{2}\}^4$. Substituting stages 1 and 2 into stage 3 gives: + +$$4 q \bigl(F_{p/q}(x) - C_{p/q}(x)\bigr)_k = 4 q (B e^{(1)})_k + 4 q B_{k,t}\!\left(\frac{p}{q} e^{(1)}_s + e^{(2)}_t\right) + 4 q e^{(3)}_k.$$ + +On the two output rows $k$ with $B_{k,t} = 0$, the middle term vanishes and $|4q E_k| \le 2q + 2q = 4q$. Fix either output row $k$ with $B_{k,t} = \sigma \in \{\pm \frac{1}{2}\}$ and companion index $t'$ ($B_{k,t'} = \tau \in \{\pm \frac{1}{2}\}$, coming from the opposite $2 \times 2$ Hadamard block of $A$). Under round-half-to-even, $e^{(1)}_j = \pm \frac{1}{2}$ forces $y_j \in 2\mathbb{Z}$ (banker's rounding maps every half-integer to an even integer), and within each $2 \times 2$ block of $A$, both coordinates have $x_a \pm x_b$ of identical parity, so $(e^{(1)}_{\mathrm{blk}})$ are either both $0$ or both in $\{\pm \frac{1}{2}\}$. + +- **Upper bound across parity regimes:** + - *Regime A ($e^{(1)}_t, e^{(1)}_{t'}, e^{(3)}_k$ all nonzero, contributing $q + q + 2q = 4q$):* Since $e^{(1)}_t \neq 0$ and $e^{(1)}_{t'} \neq 0$, both $y_t$ and $z_{t'} = y_{t'}$ are **even**, and $s$ (lying in one of the two blocks) also has $|e^{(1)}_s| = \frac{1}{2}$ (contributing $+|p|$) and **$y_s = 2m$ even**. Meanwhile $e^{(3)}_k \neq 0$ requires $z_t \pm z_{t'}$ odd, forcing **$z_t$ odd**. Because banker's rounding maps half-integers to even integers, an **odd** rounded output $z_t = R_1(y_t + \frac{2pm}{q})$ requires strict inequality $|e^{(2)}_t| = \frac{\delta}{q} < \frac{1}{2}$ ($2\delta \le q - 1$) where $y_t + \frac{2pm}{q} = z_t \mp \frac{\delta}{q}$, i.e., $2pm = Q q \mp \delta$ with $z_t = y_t + Q$. Since $y_t$ is even and $z_t$ is odd, **$Q$ is odd**, so $\delta \equiv Q q - 2pm \equiv q \pmod 2$. The largest integer $\delta \le \lfloor(q-1)/2\rfloor$ satisfying $\delta \equiv q \pmod 2$ satisfies $2\delta_{\max} = q - 4 + (q \bmod 4)$ across all four residues $q \bmod 4 \in \{0,1,2,3\}$ ($q-4, q-3, q-2, q-1$ respectively), giving $|4q E_k| \le 4q + |p| + q - 4 + (q \bmod 4) = 5q - 4 + (q \bmod 4) + |p|$. + - *Regime B ($e^{(3)}_k = 0$):* Dropping $4q|e^{(3)}_k| = 2q$ bounds $|4q E_k| \le 2q + |p| + q = 3q + |p| < 5q - 4 + (q \bmod 4) + |p|$ for all $q \ge 2$. + - *Regime C ($e^{(1)}_{t'} = 0$ or $e^{(1)}_t = 0$):* If the $s$-block has $e^{(1)}_s = 0$, we lose both $q$ and $|p|$, bounding $|4q E_k| \le q + 0 + q + 2q = 4q < 5q - 4 + (q \bmod 4) + |p|$. If $e^{(1)}_{t'} = 0$ while $s$ lies in the $t$-block ($s = \bar{t}$), then $y_s = 2m$ is even and $|4q E_k| \le q + 0 + |p| + q + 2q = 4q + |p| \le 5q - 4 + (q \bmod 4) + |p|$ since $q - 4 + (q \bmod 4) \ge 0$ for all $q \ge 2$. + +- **Attainment in all 12 orientations:** Because $\gcd(|p|, q) = 1$, for every odd $Q$ and $\delta = \delta_{\max} \equiv q \pmod 2$, $Q q - \delta$ is even; when $q$ is odd, $\gcd(2p, q) = 1$ solves $2 p m \equiv Q q - \delta \pmod{2q}$, and when $q = 2 q'$ is even ($p$ odd, $\delta = 2\delta'$), $p m \equiv Q q' - \delta' \pmod{2 q'}$ is solvable for $m \in \mathbb{Z}$. Choosing signs in the $t$- and $t'$-blocks aligns all five error terms simultaneously on every $(t, s)$. + +## Representative Values + +| $\alpha = p/q$ | Period $P = 8q$ | Sharp Peak Error $E^*(\alpha) / h$ | Decimal | +| :---: | :---: | :---: | :---: | +| $\pm 1/4$ | $32$ | $17/16$ | $1.0625$ | +| $\pm 1/2$ (#7474) | $16$ | $9/8$ | $1.1250$ | +| $\pm 1/8$ | $64$ | $37/32$ | $1.15625$ | +| $\pm 3/4$ | $32$ | $19/16$ | $1.1875$ | +| $\pm 1/16$ | $128$ | $77/64$ | $1.203125$ | +| $\pm 1/3$ | $24$ | $5/4$ | $1.2500$ | +| $\pm 2/3$ | $24$ | $4/3$ | $1.333\overline{3}$ | + +## Reproduction + +```bash +python3 -B research/rational-walsh-shear-error-law/verify.py --qmax 8 +python3 -B research/rational-walsh-shear-error-law/verify.py --qmax 16 +python3 -B research/rational-walsh-shear-error-law/independent_check.py +``` + +## Open next questions + +1. **Precision-tape binding for quarter-shear decompositions ($\alpha = \pm 1/4$):** Relevance: since $\pm 1/4$ achieves $17h/16 < 9h/8$, decomposing a target rotation/shear using $\pm 1/4$ tiles can tighten single-tile peak error by $h/16$ at the cost of an extra shear event. First execution step: bind the $32h$-periodic quarter-shear tile to an emitted `precision_tape` trace and price coefficient service, range, reversal, and caller overhead (#7474 OQ2). Blockers: full caller invoice comparison against single half-shear tiles. +2. **Multi-shear composition cancellation:** Relevance: sequential rounded shears $(I + \alpha_2 E_{u,v})(I + \alpha_1 E_{t,s})$ without intermediate Walsh re-projection may exhibit tighter joint parity locking than the triangle sum $E^*(\alpha_1) + E^*(\alpha_2)$. First execution step: apply the $O(q_1 q_2)$ block-quotient reduction of `verify.py` to two-step Plücker/LDU shear triples. Blockers: 2-stage coupled carry analysis. From ca73bd633d3256dd157cdf5529fb1d3420792686 Mon Sep 17 00:00:00 2001 From: mithrax Date: Fri, 13 Nov 2026 15:36:51 -0600 Subject: [PATCH 2/3] feat(research): add O(q) quotient-torus verifier for rational Walsh shear law --- .../rational-walsh-shear-error-law/verify.py | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 research/rational-walsh-shear-error-law/verify.py diff --git a/research/rational-walsh-shear-error-law/verify.py b/research/rational-walsh-shear-error-law/verify.py new file mode 100644 index 0000000000..27be20d4c6 --- /dev/null +++ b/research/rational-walsh-shear-error-law/verify.py @@ -0,0 +1,125 @@ +#!/usr/bin/env python3 +# research/rational-walsh-shear-error-law/verify.py +# Author: mithrax-exo (Apache-2.0 License) +"""Cached O(q) quotient-torus verifier for the Universal Rational Walsh-Shear Error Law (extending #7474).""" +import argparse +import json +import math +import sys + +def round_half_even(num: int, den: int) -> int: + q, rem = divmod(2 * num, den) + if (q & 1) == 0: + return q // 2 + m = (q - 1) // 2 + return (m + 1) if rem > 0 else (m if (m & 1) == 0 else (m + 1)) + +def predicted_4q_max(p: int, q: int) -> int: + assert q >= 2 and math.gcd(abs(p), q) == 1 + return 5 * q - 4 + (q % 4) + abs(p) + +def precompute_block_states(need_s_mod_4q: bool, s_local_idx: int, q: int): + P_a = (8 * q) if need_s_mod_4q else 8 + uniq = {} + for a in range(P_a): + for b in range(8): + for x0, x1 in ((a, b), (b, a)): + u0, u1 = x0 + x1, x0 - x1 + y0, y1 = round_half_even(u0, 2), round_half_even(u1, 2) + ys_mod = ((y0 if s_local_idx == 0 else y1) % (4 * q)) if need_s_mod_4q else 0 + key = (y0 % 4, y1 % 4, 2 * y0 - u0, 2 * y1 - u1, ys_mod) + if key not in uniq: + uniq[key] = (u0, u1, y0, y1) + return list(uniq.values()) + +def verify_periodicity_samples(p: int, q: int) -> None: + P = 8 * q + for t, s in ((0, 1), (1, 2), (2, 0), (3, 2)): + for x in ((1, 4, 0, 1), (3, -2, 7, 4)): + vals = [] + for sh in ((0, 0, 0, 0), (P, 0, 0, 0), (0, -P, P, -P)): + xx = tuple(x[i] + sh[i] for i in range(4)) + u = (xx[0] + xx[1], xx[0] - xx[1], xx[2] + xx[3], xx[2] - xx[3]) + y = [round_half_even(uk, 2) for uk in u] + z = list(y) + z[t] = round_half_even(q * y[t] + p * y[s], q) + F = ( + round_half_even(z[0] + z[2], 2), + round_half_even(z[1] + z[3], 2), + round_half_even(z[0] - z[2], 2), + round_half_even(z[1] - z[3], 2), + ) + v = [q * uk for uk in u] + v[t] += p * u[s] + C4q = (v[0] + v[2], v[1] + v[3], v[0] - v[2], v[1] - v[3]) + vals.append([4 * q * F[k] - C4q[k] for k in range(4)]) + assert vals[0] == vals[1] == vals[2] + +def verify_all_for_q(q: int) -> int: + base_reps = precompute_block_states(False, 0, q) + s0_reps = precompute_block_states(True, 0, q) + s1_reps = precompute_block_states(True, 1, q) + + coprime_ps = [p for p in range(1, 2 * q) if math.gcd(p, q) == 1] + for p in coprime_ps: + verify_periodicity_samples(p, q) + exp = predicted_4q_max(p, q) + for sgn in (1, -1): + ps = sgn * p + for t in range(4): + for s in range(4): + if t == s: + continue + b0 = (s0_reps if s == 0 else s1_reps) if s in (0, 1) else base_reps + b1 = (s0_reps if s == 2 else s1_reps) if s in (2, 3) else base_reps + best = -1 + for u0, u1, y0, y1 in b0: + for u2, u3, y2, y3 in b1: + u = (u0, u1, u2, u3) + y = (y0, y1, y2, y3) + zt = round_half_even(q * y[t] + ps * y[s], q) + z0 = zt if t == 0 else y0 + z1 = zt if t == 1 else y1 + z2 = zt if t == 2 else y2 + z3 = zt if t == 3 else y3 + f0 = round_half_even(z0 + z2, 2) + f1 = round_half_even(z1 + z3, 2) + f2 = round_half_even(z0 - z2, 2) + f3 = round_half_even(z1 - z3, 2) + v0, v1, v2, v3 = q * u0, q * u1, q * u2, q * u3 + pus = ps * u[s] + if t == 0: v0 += pus + elif t == 1: v1 += pus + elif t == 2: v2 += pus + else: v3 += pus + mx = max( + abs(4 * q * f0 - (v0 + v2)), + abs(4 * q * f1 - (v1 + v3)), + abs(4 * q * f2 - (v0 - v2)), + abs(4 * q * f3 - (v1 - v3)), + ) + if mx > best: + best = mx + assert best == exp, f"Mismatch at alpha={ps}/{q}, ({t},{s}): {best} != {exp}" + return 2 * len(coprime_ps) + +def main() -> int: + ap = argparse.ArgumentParser() + ap.add_argument("--qmax", type=int, default=8, help="Max denominator q to verify (pass 16 for full 316-shear run)") + args = ap.parse_args() + + total_pairs = sum(verify_all_for_q(q) for q in range(2, args.qmax + 1)) + print("PASS_UNIVERSAL_RATIONAL_WALSH_SHEAR_LAW") + print(json.dumps({ + "status": "PASS", + "qmax_verified": args.qmax, + "signed_coprime_shears_verified": total_pairs, + "formula": "(5*q - 4 + (q mod 4) + |p|) / (4*q) * h", + "quarter_shear_peak": "17/16", + "half_shear_peak_pr7474": "9/8", + "third_shear_peak": "5/4", + })) + return 0 + +if __name__ == "__main__": + sys.exit(main()) From fa4362cd499e3078b055aba832334bf02748b80d Mon Sep 17 00:00:00 2001 From: mithrax Date: Fri, 13 Nov 2026 15:37:46 -0600 Subject: [PATCH 3/3] feat(research): add independent Fraction oracle and tie-breaking rejection control --- .../independent_check.py | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 research/rational-walsh-shear-error-law/independent_check.py diff --git a/research/rational-walsh-shear-error-law/independent_check.py b/research/rational-walsh-shear-error-law/independent_check.py new file mode 100644 index 0000000000..7f3c584001 --- /dev/null +++ b/research/rational-walsh-shear-error-law/independent_check.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# research/rational-walsh-shear-error-law/independent_check.py +# Author: mithrax-exo (Apache-2.0 License) +"""Independent Fraction oracle and non-banker rounding rejection control.""" +from fractions import Fraction +from math import floor +import sys + +def eval_exact_frac(x, t: int, s: int, alpha: Fraction) -> Fraction: + A_x = [ + Fraction(x[0] + x[1], 2), + Fraction(x[0] - x[1], 2), + Fraction(x[2] + x[3], 2), + Fraction(x[2] - x[3], 2), + ] + y = [round(v) for v in A_x] + z = list(y) + z[t] = round(Fraction(y[t]) + alpha * Fraction(y[s])) + F = [ + round(Fraction(z[0] + z[2], 2)), + round(Fraction(z[1] + z[3], 2)), + round(Fraction(z[0] - z[2], 2)), + round(Fraction(z[1] - z[3], 2)), + ] + S_Ax = list(A_x) + S_Ax[t] += alpha * A_x[s] + C = [ + (S_Ax[0] + S_Ax[2]) / 2, + (S_Ax[1] + S_Ax[3]) / 2, + (S_Ax[0] - S_Ax[2]) / 2, + (S_Ax[1] - S_Ax[3]) / 2, + ] + return max(abs(Fraction(F[k]) - C[k]) for k in range(4)) + +def main() -> int: + peak_half = max( + eval_exact_frac((a, b, c, d), 0, 1, Fraction(1, 2)) + for a in range(16) for b in range(16) for c in range(4) for d in range(4) + ) + assert peak_half == Fraction(9, 8) + + for t in range(4): + for s in range(4): + if t == s: + continue + pk = max( + eval_exact_frac((a, b, c, d) if t < 2 else (c, d, a, b), t, s, Fraction(1, 4)) + for a in range(32) for b in range(8) for c in range(8) for d in range(4) + ) + assert pk == Fraction(17, 16) + + def half_up(v: Fraction) -> int: + return floor(v + Fraction(1, 2)) + + bad_max = Fraction(0) + for a in range(8): + for b in range(8): + for c in range(8): + for d in range(8): + Ax = [Fraction(a + b, 2), Fraction(a - b, 2), Fraction(c + d, 2), Fraction(c - d, 2)] + yy = [half_up(v) for v in Ax] + zz = list(yy) + zz[0] = half_up(Fraction(yy[0]) + Fraction(1, 2) * yy[1]) + FF = [ + half_up(Fraction(zz[0] + zz[2], 2)), + half_up(Fraction(zz[1] + zz[3], 2)), + half_up(Fraction(zz[0] - zz[2], 2)), + half_up(Fraction(zz[1] - zz[3], 2)), + ] + SAx = list(Ax) + SAx[0] += Fraction(1, 2) * Ax[1] + CC = [(SAx[0] + SAx[2]) / 2, (SAx[1] + SAx[3]) / 2, (SAx[0] - SAx[2]) / 2, (SAx[1] - SAx[3]) / 2] + bad_max = max(bad_max, max(abs(Fraction(FF[k]) - CC[k]) for k in range(4))) + assert bad_max == Fraction(11, 8) > Fraction(9, 8) + print("PASS_INDEPENDENT_FRAC_ORACLE_AND_TIEBREAK_CONTROL") + return 0 + +if __name__ == "__main__": + sys.exit(main()) + sys.exit(main())