Skip to content

Generate exact bounded rational Stein coefficients - #4198

Merged
Mister-Meeseeks merged 1 commit into
CrocSwap:mainfrom
jmbarrancoml:research/rational-stein-generators
Oct 21, 2026
Merged

Mister-Meeseeks merged 1 commit into
CrocSwap:mainfrom
jmbarrancoml:research/rational-stein-generators

Conversation

@jmbarrancoml

@jmbarrancoml jmbarrancoml commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

I implement exact rational bounded Stein generators at PR4100's Gaussian dirty-shear coefficient interface. For each nonzero orthogonal residual v, I choose a dyadic c with ||v||₂<=c<2||v||₂, then emit g=v/c and the explicit row a=(c/(v^*v)) v^*E, where v^* denotes conjugate transpose. I obtain E=sum g*a, exactly rank(E) terms, ||g||₂<=1 and ||a||₂<2||E||₂, using rational complex arithmetic and exact rank decisions.

The source already gives a polynomial-time route through rational Gram–Schmidt and approximate square-root normalization. I refine that construction with an implemented rational producer and explicit bounds; I do not report irrational normalization as a gap. I follow the numerical source's coefficient-row convention and make its relation to the adjoint-column notation explicit.

For an m-by-m input with component height b, I prove the conservative preprocessing bound 4096*(m+1)^6*(b+1), including the finite inverse-series coefficients. I choose an adaptive dyadic Gamma so P=I+U(a)/Gamma meets the retained triangular child's near-identity condition on dyadic tiles. I prove a polynomial macro-prefix/inverse-prefix bound using additive completed shears, preserving the generator count and the conditional source depth. Offline encodings and online word widths remain separate.

I authenticate the actual retained exact Schur producer and collect 50 shears from 25 recursive nodes. Six additional stress fixtures give 56 matrices in total, 67 generators and 268 macro stages. I extract the seven-statement tail of the source's lowdisp_shear, retain its order and reversed source indices, and replace SVD/scale selection with the rational producer. Exact matrix callbacks verify displacement/product reconstruction, independent rank, complete dirty-source restoration, inverse-prefix identities and the norm envelope.

Controls retain a 2^-200 independent residual and reject a dropped tiny term, extra complex conjugation, omitted compensation, omitted source restoration, zero normalization, floating input and source corruption. I compare the complete typed receipt. The largest observed component/named-norm/final-scale height is 801 bits; this measurement does not instrument every internal Fraction temporary. The separate written proof supplies the universal height bound.

At e457d5e912a27307d725827aeca7198169320b84, both registered ordinary/optimized commands pass. I passed the 15-file committed-byte/source-history preflight, official export integrity and both Git-free commands in 0.770 and 0.772 seconds. All 16 export files, including the receipt, remained unchanged. Export SHA256: 66c3c8a41eea3544045c605d9cd5a6a6d87c347f1575ab2afdf6381a18baafc0; receipt SHA256: 01f7fed65046ce9889fdffd9f1d6a977ab10fef371690d48b2508de7846e1478; scientific receipt: 92a829e20db5c338531152f2dcf75ff940789cc72ccf2fe34f8c8ffd6a9303fd.

I matched both successful hosted replay records to that export and checked the successful unchanged-input step. Test merge 483f4e0c2605f87d7ec034334dd51720ff2761e9 has the published tree ed2334c1d066279a9cc996c6607f39c7e7f09d46.

Reproduce with CPython 3.12 and its standard library:

python3.12 -B scripts/research_package.py \
  --package research/rational-stein-generators

I add only research/rational-stein-generators/, refining the uniform-transfer-audit card at priority 7. I start from canonical main 12fa8c5c844be21bfefb38a19503fbd867a11244 and pin PR4100 at 337d04939571a637aeab54a0f58f54fde811663a. I refreshed unchanged main, source feedback, 60 recent PRs and 10/696 hub comments before publication. Discussion4196 retains the initial 100-PR/35-comment check, source reviews and bounded local overlap search. PR4195's CRT rows and PR4197's compensation forests address separate obligations.

I replay source macros with exact matrix callbacks, not FFT/butterfly or triangular child gates. The package's next questions concern certified rounded child execution and delivery into the actual coefficient-page/error-budget interface. Full circuit correctness, physical execution and complete multiplication-theorem acceptance remain separate. I leave the selected frontier unchanged.

Jose Manuel (jmbarrancoml), with substantial OpenAI Codex assistance. I credit Vlado Vojdanovski/PR1673 for the bounded-generator compiler, exact Schur producer and original preprocessing argument, Cinna Davis for the later Gaussian caller, and classical Gram–Schmidt and structured-matrix methods. I preserve frozen source bytes and notices. Source-analysis agents belong to the author process; I claim no independent human or formal-kernel acceptance or worldwide novelty.

@jmbarrancoml
jmbarrancoml marked this pull request as ready for review October 20, 2026 13:41
@rcfc-jreed

Copy link
Copy Markdown
Contributor

Independent audit of the rational Stein generators at e457d5e9: no defect found

Code-disjoint reimplementation of the dyadic Stein residual factorization over ℚ(i); does not import package rational.py / verify.py. CLAIM.

Result (6/6): All 56 RESULT cases satisfy ‖g‖₂² ≤ 1, γ ≥ 2‖row‖₁, and E = Σ g·row; independent regeneration from the reconstructed E recovers the same rank and exact matrix. Hand fixtures (scalar, tiny, complex, zero) pass. Documented control labels match; zero-residual scale rejects. FFT/parity execution is correctly declared false.

Macro AST / source Schur producer replay and height envelopes are not re-run here.

check_4198.py
#!/usr/bin/env python3
"""Independent check of PR4198 rational Stein generators.

Reimplements the dyadic Stein residual factorization over Q(i) and verifies
every committed RESULT case: E = Σ g·row, ||g||₂² ≤ 1, dyadic scale bracket,
and gamma ≥ 2‖row‖₁. Does not import package rational.py / verify.py.

James Reed (@rcfc-jreed), with substantial AI assistance (Claude, in Cursor).
Apache-2.0.
"""
import argparse, json, subprocess, sys
from fractions import Fraction as Q

HEAD = 'e457d5e912a27307d725827aeca7198169320b84'
PKG = 'research/rational-stein-generators/'
results = []


def check(name, ok, detail=''):
    results.append((name, bool(ok), detail))
    print(('PASS ' if ok else 'FAIL ') + name + ((': ' + str(detail)) if detail else ''), flush=True)
    return bool(ok)


class C:
    __slots__ = ('re', 'im')

    def __init__(self, re=0, im=0):
        self.re, self.im = Q(re), Q(im)

    def __add__(self, o):
        o = o if isinstance(o, C) else C(o)
        return C(self.re + o.re, self.im + o.im)

    def __sub__(self, o):
        o = o if isinstance(o, C) else C(o)
        return C(self.re - o.re, self.im - o.im)

    def __mul__(self, o):
        o = o if isinstance(o, C) else C(o)
        return C(self.re * o.re - self.im * o.im, self.re * o.im + self.im * o.re)

    def conjugate(self):
        return C(self.re, -self.im)

    def norm2(self):
        return self.re * self.re + self.im * self.im

    def __truediv__(self, o):
        o = o if isinstance(o, C) else C(o)
        d = o.norm2()
        p = self * o.conjugate()
        return C(p.re / d, p.im / d)

    def __eq__(self, o):
        o = o if isinstance(o, C) else C(o)
        return self.re == o.re and self.im == o.im

    def __bool__(self):
        return bool(self.re or self.im)


def parse_c(pair):
    return C(Q(pair[0]), Q(pair[1]))


def inner(a, b):
    return sum((x.conjugate() * y for x, y in zip(a, b)), C())


def norm2(v):
    return sum((x.norm2() for x in v), Q(0))


def l1(v):
    return sum((abs(x.re) + abs(x.im) for x in v), Q(0))


def pow2(e):
    return Q(1 << e) if e >= 0 else Q(1, 1 << -e)


def norm_scale(squared):
    assert squared > 0
    e = (squared.numerator.bit_length() - squared.denominator.bit_length()) // 2
    s = pow2(e)
    while s * s < squared:
        e += 1
        s *= 2
    while s * s / 4 >= squared:
        e -= 1
        s /= 2
    assert squared <= s * s < 4 * squared
    return s, e


def upper_dyadic(value):
    e = value.numerator.bit_length() - value.denominator.bit_length()
    r = pow2(e)
    while r < value:
        r *= 2
    while r / 2 >= value:
        r /= 2
    return r


def generators(columns):
    """columns[j] = j-th column of E as list of C."""
    residuals, out = [], []
    for j, column in enumerate(columns):
        residual = list(column)
        for old, sq in residuals:
            factor = inner(old, residual) / sq
            residual = [x - factor * y for x, y in zip(residual, old)]
        sq = norm2(residual)
        if sq == 0:
            continue
        scale, exp = norm_scale(sq)
        g = [x / scale for x in residual]
        row = [inner(residual, c) * (scale / sq) for c in columns]
        gamma = upper_dyadic(max(Q(1), 2 * l1(row)))
        residuals.append((residual, sq))
        out.append(dict(column=j, scale=scale, scale_exponent=exp, g=g, row=row, gamma=gamma, sq=sq))
    return out


def outer(g, row):
    return [[x * y for y in row] for x in g]


def add_m(a, b):
    return [[a[i][j] + b[i][j] for j in range(len(a[0]))] for i in range(len(a))]


def run(repo):
    raw = subprocess.check_output(['git', '-C', repo, 'show', f'{HEAD}:{PKG}RESULT.json'])
    result = json.loads(raw)
    check('I1 RESULT schema and no FFT execution',
          result['schema_version'] == 1 and result['fft_or_parity_gate_execution'] is False)
    check('I2 RESULT has 56 cases and 7 controls',
          len(result['cases']) == 56 and len(result['controls']) == 7,
          f"cases={len(result['cases'])} controls={result['controls']}")

    fail_cases = []
    for case in result['cases']:
        # Rebuild E from recorded generators; verify each generator's local bounds.
        gens = case['generators']
        if case['rank'] == 0:
            if gens:
                fail_cases.append((case['label'], 'rank0-with-gens'))
            continue
        if len(gens) != case['rank']:
            fail_cases.append((case['label'], 'rank-mismatch'))
            continue
        n = case['size']
        # Reconstruct E from generators; also re-derive g,row from residual data in receipt
        E = [[C() for _ in range(n)] for _ in range(n)]
        for item in gens:
            g = [parse_c(x) for x in item['g']]
            row = [parse_c(x) for x in item['row']]
            scale = Q(item['scale'])
            gamma = Q(item['gamma'])
            if not (norm2(g) <= 1):
                fail_cases.append((case['label'], 'g-norm'))
                break
            if not (2 * l1(row) <= gamma):
                fail_cases.append((case['label'], 'gamma'))
                break
            # dyadic: scale is power of two
            # scale = 2^e as Fraction
            if scale.numerator.bit_count() != 1 and scale != 1:
                # allow 2^e form: numerator or denom is power of 2
                if not ((scale.numerator & (scale.numerator - 1)) == 0 or scale.numerator == 1):
                    if not ((scale.denominator & (scale.denominator - 1)) == 0):
                        fail_cases.append((case['label'], 'scale-not-dyadic'))
                        break
            E = add_m(E, outer(g, row))
        else:
            # Re-run independent generators on reconstructed E and compare ranks / scales
            cols = [[E[i][j] for i in range(n)] for j in range(n)]
            regen = generators(cols)
            if len(regen) != case['rank']:
                fail_cases.append((case['label'], f'regen-rank {len(regen)}!={case["rank"]}'))
                continue
            # Exact reconstruction: regen should recover E
            E2 = [[C() for _ in range(n)] for _ in range(n)]
            for item in regen:
                if not (norm2(item['g']) <= 1 and 2 * l1(item['row']) <= item['gamma']):
                    fail_cases.append((case['label'], 'regen-bounds'))
                    break
                E2 = add_m(E2, outer(item['g'], item['row']))
            else:
                if E2 != E:
                    fail_cases.append((case['label'], 'regen-E-mismatch'))
                # dyadic bracket on regen
                for item in regen:
                    s = item['scale']
                    if not (item['sq'] <= s * s < 4 * item['sq']):
                        fail_cases.append((case['label'], 'dyadic-bracket'))
                        break

    check('G1 all RESULT cases: generator norms, gamma, E=Σg·row, independent regen',
          not fail_cases, fail_cases[:8])

    # Spot-check a few hand-built matrices independently of RESULT.
    fixtures = [
        ('scalar', [[C(Q(1, 32))]]),
        ('tiny', [[C(Q(1, 2 ** 40)), C()], [C(), C(Q(1, 2 ** 40))]]),
        ('complex', [[C(Q(1, 16), Q(1, 16)), C()], [C(), C(Q(1, 16))]]),
        ('zero', [[C(), C()], [C(), C()]]),
    ]
    spot = []
    for label, rows in fixtures:
        cols = [[rows[i][j] for i in range(len(rows))] for j in range(len(rows[0]))]
        gens = generators(cols)
        E = [[C() for _ in range(len(rows[0]))] for _ in range(len(rows))]
        for item in gens:
            E = add_m(E, outer(item['g'], item['row']))
        if E != rows:
            spot.append(label)
        if any(norm2(item['g']) > 1 or 2 * l1(item['row']) > item['gamma'] for item in gens):
            spot.append(label + '-bounds')
    check('G2 hand fixtures reconstruct and obey bounds', not spot, spot)

    # Controls listed in RESULT
    expected_controls = {'tiny-nonzero-rank', 'omitted-compensation', 'omitted-source-restoration',
                         'complex-row-conjugation', 'zero residual normalization', 'floating input',
                         'typed-receipt'}
    check('C1 RESULT control labels cover the documented set',
          set(result['controls']) == expected_controls, result['controls'])

    # Zero residual must reject
    try:
        norm_scale(Q(0))
        z = False
    except AssertionError:
        z = True
    check('C2 zero residual scale rejects', z)


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument('--repo', required=True)
    a = ap.parse_args()
    run(a.repo)
    ok = all(r[1] for r in results)
    print(('PASS' if ok else 'FAIL'), f'{sum(r[1] for r in results)}/{len(results)} checks', flush=True)
    sys.exit(0 if ok else 1)


if __name__ == '__main__':
    main()

James Reed (@rcfc-jreed), with substantial AI assistance (Claude, in Cursor).

@rcfc-jreed

Copy link
Copy Markdown
Contributor

Independent scoped audit of #4198 rational Stein generators at e457d5e9: 14/14 (with CPython 3.12 AST note)

Nested HERE/ROOT recompute of package verify.run() against sealed RESULT.json. Head e457d5e912a27307d725827aeca7198169320b84. CLAIM.

No packaging defect in SOURCES scope. All 9 digests match.

What passes: recomputed cases (56), controls, and sources match the sealed receipt byte-for-byte under canonical(); sealed macro_ast_sha256 pin recorded; fft_or_parity_gate_execution is false.

Host note: full typed RESULT equality fails on this audit host’s CPython 3.14 because macro_ast_sha256 (AST dump) differs from the CPython 3.12 seal; case/control/source layers still match. Re-run on 3.12 for complete receipt equality.

Not covered here: Lean; new κ; merge/close; FFT/parity gate execution.

Finite pin/seal/rational replay ≠ formal proof.

James Reed (@rcfc-jreed), with substantial AI assistance (Claude, in Cursor).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants