diff --git a/research/cold-wrapper-quadratic81/CLAIM.md b/research/cold-wrapper-quadratic81/CLAIM.md new file mode 100644 index 0000000000..b843580dec --- /dev/null +++ b/research/cold-wrapper-quadratic81/CLAIM.md @@ -0,0 +1,56 @@ +# Sprint claim + +- Track: independent verification; fresh OS-random seed **81**, drawn with + `secrets.randbelow(100)` on 2026-10-13. +- Base: `66849e1475c930fd7732b1a0067ffee7e1e95f60` (freshly fetched main). +- Object: the selected #626 cold-helper pair `E = []`, + `U = [268, 140, 45, 30]`, width 4; helper register 442 in both providers. + This is recipe `0:429` in CK and `0:413` in JP8. Among each provider's 14 + lexicographically sorted rank-4 cold recipes, seed `81 % 14 = 11` selects it. +- Method: independent closed matrix-entry formulas over Gaussian integers, + checking every one of the 512 basis inputs and all 512 output coordinates. + No imports from the Clifford tableau/compiler or existing state evaluator. +- Deliverable: pinned instance, exact full-operator check, meaningful wrong + phase/geometry/monomial controls, and a proof of the kernel formula's scope. + No new kappa and no full formal multiplication theorem. +- Claim time: 2026-10-13 04:25 UTC; expected finish: 04:50 UTC. + Final quarter reserved for verification and handoff. +- Three candidates: prime-power cyclic inverse identity (already two engines, + plus #668/#666), entering-helper wrapper (literal proofs in #593 and #581), + and this rank-4 cold wrapper. The third has no selected literal Lean theorem + and benefits from a different all-basis matrix-entry implementation. +- Overlap: #662 accelerates the existing tableau/zero-state checker and compares + circuit-prefix states; this is an independent closed-kernel calculation. + #680 studies fixed register words, not this supplier wrapper. #675 audits + owner boundaries. Current negative results and review scope remain intact. +- No pinned coordination issue exists; Discussions remains disabled and #650 + asks for a channel. This local claim avoids opening a reservation issue. + +Joshua Snider (`jsnider3`), with substantial OpenAI Codex assistance. Apache-2.0. + +## Evidence-driven scope refinement — 04:30 UTC + +PR #702 at `27db45ac6befa99d6c06be920a93845023e81937` appeared at +04:26:49 UTC while this work was in progress. It covers all 14 cold frames +using direct matrix entries, including this pair. The initial one-pair replay +here passed, but would duplicate that method. The single pivot keeps the same +helper and replaces the deliverable with an affine-support certificate and +coefficient-wise quadratic-phase identity over 13 Boolean variables. This +independently corroborates #702 by symbolic algebra rather than a second +all-column enumerator. No #702 implementation or result is imported. + +## Result — 2026-10-13 04:39 UTC + +Submitted [PR #712](https://github.com/CrocSwap/integer-mult-bounds/pull/712). +The affine support map is bijective and the quadratic phase residual vanishes +at all 92 coefficient positions. Thirteen rejection controls pass; five test +groups include direct checks of all six phase components on all 8,192 Boolean +assignments. Normal and optimized isolated runs from a separate committed-files-only +worktree reproduce the exact saved certificate. Selected-record and whitespace +checks passed. No new kappa or full theorem is claimed. + +Final overlap refresh through #711 found #702 as the related amplitude audit, +credited for its broader frame coverage. The symbolic method is distinct and +upstream main remains at the recorded base. No pinned sprint issue exists, so +this is the local result update and handoff link. The source contribution is +commit `634026a`; this follow-up changes only the claim's handoff record. diff --git a/research/cold-wrapper-quadratic81/EXPECTED.json b/research/cold-wrapper-quadratic81/EXPECTED.json new file mode 100644 index 0000000000..3cbea3786b --- /dev/null +++ b/research/cold-wrapper-quadratic81/EXPECTED.json @@ -0,0 +1,882 @@ +{ + "status": "PASS_COLD_WRAPPER_QUADRATIC_CERTIFICATE", + "bindings": [ + { + "provider": "ck", + "recipe_key": "0:429", + "helper": 442 + }, + { + "provider": "jp8", + "recipe_key": "0:413", + "helper": 442 + } + ], + "variables": 13, + "coefficient_domain": "Z/4Z; X_i^2=X_i", + "phase_coefficient_positions": 92, + "certificate": { + "completed_basis": [ + 268, + 140, + 45, + 30, + 1, + 2, + 4, + 8, + 64 + ], + "output_forms": [ + 2991, + 3487, + 14139, + 14135, + 3469, + 2958, + 64, + 14607, + 2435 + ], + "kernel_difference_forms": [ + 2179, + 14735, + 2990, + 3485 + ], + "spectator_displacement_forms": [ + 0, + 0, + 0, + 0, + 0 + ], + "delta_map_rows": [ + 4, + 12, + 5, + 6 + ], + "delta_map_inverse_images": [ + 0, + 15, + 8, + 7, + 1, + 14, + 9, + 6, + 2, + 13, + 10, + 5, + 3, + 12, + 11, + 4 + ], + "components": { + "right_phase_x": [ + [ + 0, + 1 + ], + [ + 1, + 2 + ], + [ + 2, + 2 + ], + [ + 4, + 1 + ], + [ + 8, + 1 + ], + [ + 16, + 2 + ], + [ + 32, + 2 + ], + [ + 128, + 3 + ], + [ + 3, + 2 + ], + [ + 5, + 2 + ], + [ + 6, + 2 + ], + [ + 9, + 2 + ], + [ + 10, + 2 + ], + [ + 12, + 2 + ], + [ + 18, + 2 + ], + [ + 20, + 2 + ], + [ + 24, + 2 + ], + [ + 33, + 2 + ], + [ + 36, + 2 + ], + [ + 40, + 2 + ], + [ + 129, + 2 + ], + [ + 130, + 2 + ], + [ + 257, + 2 + ], + [ + 258, + 2 + ], + [ + 260, + 2 + ], + [ + 264, + 2 + ], + [ + 384, + 2 + ] + ], + "left_phase_z": [ + [ + 0, + 2 + ], + [ + 128, + 1 + ], + [ + 256, + 1 + ], + [ + 512, + 3 + ], + [ + 1024, + 3 + ], + [ + 2048, + 1 + ], + [ + 4096, + 2 + ], + [ + 3, + 2 + ], + [ + 132, + 2 + ], + [ + 136, + 2 + ], + [ + 257, + 2 + ], + [ + 258, + 2 + ], + [ + 260, + 2 + ], + [ + 264, + 2 + ], + [ + 513, + 2 + ], + [ + 516, + 2 + ], + [ + 520, + 2 + ], + [ + 1026, + 2 + ], + [ + 1028, + 2 + ], + [ + 1032, + 2 + ], + [ + 2049, + 2 + ], + [ + 2050, + 2 + ], + [ + 2052, + 2 + ], + [ + 2056, + 2 + ], + [ + 2304, + 2 + ], + [ + 4097, + 2 + ], + [ + 4098, + 2 + ], + [ + 4224, + 2 + ], + [ + 4352, + 2 + ], + [ + 6144, + 2 + ] + ], + "minus_delta_weight": [ + [ + 512, + 3 + ], + [ + 1024, + 3 + ], + [ + 2048, + 3 + ], + [ + 4096, + 3 + ] + ], + "minus_canonical_phase_y": [ + [ + 1, + 1 + ], + [ + 2, + 1 + ], + [ + 4, + 2 + ], + [ + 8, + 2 + ], + [ + 128, + 2 + ], + [ + 256, + 2 + ], + [ + 512, + 1 + ], + [ + 1024, + 1 + ], + [ + 2048, + 2 + ], + [ + 5, + 2 + ], + [ + 6, + 2 + ], + [ + 9, + 2 + ], + [ + 10, + 2 + ], + [ + 17, + 2 + ], + [ + 20, + 2 + ], + [ + 24, + 2 + ], + [ + 34, + 2 + ], + [ + 36, + 2 + ], + [ + 40, + 2 + ], + [ + 132, + 2 + ], + [ + 136, + 2 + ], + [ + 144, + 2 + ], + [ + 160, + 2 + ], + [ + 272, + 2 + ], + [ + 288, + 2 + ], + [ + 513, + 2 + ], + [ + 514, + 2 + ], + [ + 544, + 2 + ], + [ + 640, + 2 + ], + [ + 768, + 2 + ], + [ + 1025, + 2 + ], + [ + 1026, + 2 + ], + [ + 1040, + 2 + ], + [ + 1152, + 2 + ], + [ + 1280, + 2 + ], + [ + 2064, + 2 + ], + [ + 2080, + 2 + ], + [ + 2560, + 2 + ], + [ + 3072, + 2 + ], + [ + 4100, + 2 + ], + [ + 4104, + 2 + ] + ], + "canonical_phase_x": [ + [ + 16, + 1 + ], + [ + 32, + 1 + ], + [ + 18, + 2 + ], + [ + 20, + 2 + ], + [ + 24, + 2 + ], + [ + 33, + 2 + ], + [ + 36, + 2 + ], + [ + 40, + 2 + ], + [ + 132, + 2 + ], + [ + 136, + 2 + ], + [ + 260, + 2 + ], + [ + 264, + 2 + ] + ], + "canonical_difference_weight": [ + [ + 0, + 1 + ], + [ + 1, + 1 + ], + [ + 2, + 1 + ], + [ + 4, + 1 + ], + [ + 8, + 1 + ], + [ + 16, + 1 + ], + [ + 32, + 1 + ], + [ + 128, + 2 + ], + [ + 256, + 1 + ], + [ + 512, + 1 + ], + [ + 1024, + 1 + ], + [ + 2048, + 2 + ], + [ + 4096, + 3 + ], + [ + 12, + 2 + ], + [ + 17, + 2 + ], + [ + 20, + 2 + ], + [ + 24, + 2 + ], + [ + 34, + 2 + ], + [ + 36, + 2 + ], + [ + 40, + 2 + ], + [ + 129, + 2 + ], + [ + 130, + 2 + ], + [ + 132, + 2 + ], + [ + 136, + 2 + ], + [ + 144, + 2 + ], + [ + 160, + 2 + ], + [ + 260, + 2 + ], + [ + 264, + 2 + ], + [ + 272, + 2 + ], + [ + 288, + 2 + ], + [ + 384, + 2 + ], + [ + 514, + 2 + ], + [ + 516, + 2 + ], + [ + 520, + 2 + ], + [ + 544, + 2 + ], + [ + 640, + 2 + ], + [ + 768, + 2 + ], + [ + 1025, + 2 + ], + [ + 1028, + 2 + ], + [ + 1032, + 2 + ], + [ + 1040, + 2 + ], + [ + 1152, + 2 + ], + [ + 1280, + 2 + ], + [ + 2049, + 2 + ], + [ + 2050, + 2 + ], + [ + 2052, + 2 + ], + [ + 2056, + 2 + ], + [ + 2064, + 2 + ], + [ + 2080, + 2 + ], + [ + 2304, + 2 + ], + [ + 2560, + 2 + ], + [ + 3072, + 2 + ], + [ + 4097, + 2 + ], + [ + 4098, + 2 + ], + [ + 4100, + 2 + ], + [ + 4104, + 2 + ], + [ + 4224, + 2 + ], + [ + 4352, + 2 + ], + [ + 6144, + 2 + ] + ] + }, + "residual": [] + }, + "negative_controls": [ + { + "name": "left_phase", + "counterexample": { + "assignment_mask": 0, + "input": 0, + "delta": 0, + "phase_error_mod4": 1 + } + }, + { + "name": "left_translation", + "rejection": "Output leaves canonical support" + }, + { + "name": "left_linear", + "counterexample": { + "assignment_mask": 1, + "input": 1, + "delta": 0, + "phase_error_mod4": 2 + } + }, + { + "name": "missing_left", + "rejection": "Output leaves canonical support" + }, + { + "name": "right_phase", + "counterexample": { + "assignment_mask": 0, + "input": 0, + "delta": 0, + "phase_error_mod4": 1 + } + }, + { + "name": "right_translation", + "counterexample": { + "assignment_mask": 0, + "input": 0, + "delta": 0, + "phase_error_mod4": 1 + } + }, + { + "name": "right_linear", + "counterexample": { + "assignment_mask": 1, + "input": 1, + "delta": 0, + "phase_error_mod4": 2 + } + }, + { + "name": "missing_right", + "rejection": "Output leaves canonical support" + }, + { + "name": "swapped_wrappers", + "rejection": "Output leaves canonical support" + }, + { + "name": "right_quadratic", + "counterexample": { + "assignment_mask": 3, + "input": 3, + "delta": 0, + "phase_error_mod4": 2 + } + }, + { + "name": "input_Z8", + "counterexample": { + "assignment_mask": 256, + "input": 256, + "delta": 0, + "phase_error_mod4": 2 + }, + "residual": [ + [ + 256, + 2 + ] + ], + "zero_input_column_unchanged": true + }, + { + "name": "wrong_terminal_same_rank", + "rejection": "Output leaves canonical support" + }, + { + "name": "wrong_width", + "rejection": "Wrong residual width" + } + ] +} diff --git a/research/cold-wrapper-quadratic81/INSTANCE.json b/research/cold-wrapper-quadratic81/INSTANCE.json new file mode 100644 index 0000000000..fa30b5d749 --- /dev/null +++ b/research/cold-wrapper-quadratic81/INSTANCE.json @@ -0,0 +1,97 @@ +{ + "n": 9, + "seed": 81, + "helper": 442, + "providers": { + "ck": "0:429", + "jp8": "0:413" + }, + "recipe": { + "entrance_rank": 0, + "frame": 0, + "left": { + "linear_Z4": [ + 3, + 3, + 3, + 2, + 0, + 0, + 0, + 0, + 0 + ], + "matrix_rows": [ + 21, + 38, + 75, + 139, + 6, + 5, + 256, + 12, + 4 + ], + "offset": 0, + "phase": 0, + "quadratic_rows": [ + 1, + 2, + 12, + 4, + 0, + 0, + 0, + 0, + 0 + ] + }, + "rank": 4, + "right": { + "linear_Z4": [ + 2, + 2, + 1, + 1, + 2, + 2, + 0, + 3, + 0 + ], + "matrix_rows": [ + 13, + 14, + 387, + 140, + 33, + 18, + 436, + 440, + 64 + ], + "offset": 8, + "phase": 1, + "quadratic_rows": [ + 430, + 413, + 319, + 319, + 14, + 13, + 0, + 387, + 143 + ] + }, + "terminal": 429, + "terminal_rank": 4, + "terminal_vectors": [ + 268, + 140, + 45, + 30 + ], + "vectors": [] + } +} diff --git a/research/cold-wrapper-quadratic81/README.md b/research/cold-wrapper-quadratic81/README.md new file mode 100644 index 0000000000..f6e503163a --- /dev/null +++ b/research/cold-wrapper-quadratic81/README.md @@ -0,0 +1,186 @@ +# A quadratic-phase certificate for one selected cold wrapper + +**Independent finite verification; no new kappa.** For the selected #626 cold +helper 442, this package checks the exact identity + +\[ +T_U=L(C_4\otimes I_{32})R, +\qquad U=(268,140,45,30),\quad E=0. +\] + +It occurs as recipe `0:429` in CK and `0:413` in JP8. The serialized monomials +are identical in both providers. The certificate consists of an affine support +bijection and a zero quadratic polynomial over `Z/4Z` in 13 Boolean variables. +There are **92 coefficient positions**: one constant, 13 linear and 78 quadratic. + +Concurrent [PR #702](https://github.com/CrocSwap/integer-mult-bounds/pull/702), +head `27db45ac6befa99d6c06be920a93845023e81937`, checks all 14 selected cold +wrappers by direct amplitudes. It appeared during this run. This package +independently corroborates one of those identities through symbolic phase +composition and support algebra. Its code imports neither #702 nor the existing +Clifford compiler, tableau checker, or state-vector executor. The initial +all-column experiment was retired once the overlap was discovered; see +[CLAIM.md](CLAIM.md). + +## Reproduce + +Python 3.11+ and the standard library suffice, from the repository root: + +```sh +python3 -I -B research/cold-wrapper-quadratic81/verify.py +python3 -I -O -B research/cold-wrapper-quadratic81/test_verify.py +``` + +Expected: `PASS_COLD_WRAPPER_QUADRATIC_CERTIFICATE 13 variables, 92 coefficient positions, 13 rejection controls`, followed by five passing tests. +`--out /tmp/cold-wrapper-quadratic.json` emits the deterministic certificate; +without `--out`, the recomputed certificate must equal `EXPECTED.json`. +All rejection checks remain active under `-O`. No source generation, compiler, +network access, solver, or Lean installation is needed. + +## Operator convention and kernel + +All vectors and matrix rows use little-endian bits. The source's one-bit gate is + +\[ +C=\frac{1+i}{2}I+\frac{1-i}{2}X. +\] + +On the first four coordinates its entry from `a` to `a xor delta` is + +\[ +h(\delta)=2^{-4}(1+i)^{4-|\delta|}(1-i)^{|\delta|} + =-\tfrac14 i^{-|\delta|}. +\] + +A serialized monomial acts by +`M|x> = i^(phi_M + q_M(x)) |G_M x xor b_M>`, where +`q_M(x) = sum alpha_i x_i + 2 sum_(i> 9 + z = direct_map(right['matrix_rows'], x, right['offset']) ^ delta + y = direct_map(left['matrix_rows'], z, left['offset']) + c = direct_map(inverse, x ^ y) + self.assertEqual(c >> 4, 0) + self.assertEqual(y, sum(affine_value(f, assignment) * (2 ** i) + for i, f in enumerate(self.certificate['output_forms']))) + expected = { + 'right_phase_x': direct_phase(right['quadratic_rows'], right['linear_Z4'], x, right['phase']), + 'left_phase_z': direct_phase(left['quadratic_rows'], left['linear_Z4'], z, left['phase']), + 'minus_delta_weight': -delta.bit_count() % 4, + 'minus_canonical_phase_y': -direct_phase(q, alpha, y) % 4, + 'canonical_phase_x': direct_phase(q, alpha, x), + 'canonical_difference_weight': c.bit_count() % 4, + } + for name, value in expected.items(): + self.assertEqual(polynomial_value(self.certificate['components'][name], assignment), + value, (name, assignment)) + self.assertEqual(sum(expected.values()) % 4, 0) + + def test_corrupt_symbolic_coefficient_has_concrete_witness(self): + for mask in [0] + [2 ** i for i in range(13)] + [(2 ** i) | (2 ** j) for i in range(13) for j in range(i + 1, 13)]: + for coefficient in (1, 2, 3): + witness = check.witness({mask: coefficient}) + self.assertEqual(polynomial_value({mask: coefficient}, witness['assignment_mask']), coefficient) + + def test_each_recorded_phase_counterexample_is_nonzero(self): + controls = check.controls(self.recipe) + self.assertEqual(len(controls), 13) + for control in controls: + if 'counterexample' in control: + self.assertIn(control['counterexample']['phase_error_mod4'], (1, 2, 3)) + + def test_optimized_fresh_process(self): + completed = subprocess.run([sys.executable, '-I', '-O', '-B', str(HERE / 'verify.py')], + cwd='/tmp', capture_output=True, text=True) + self.assertEqual(completed.returncode, 0, completed.stderr) + self.assertIn('PASS_COLD_WRAPPER_QUADRATIC_CERTIFICATE', completed.stdout) + + +if __name__ == '__main__': + unittest.main() diff --git a/research/cold-wrapper-quadratic81/verify.py b/research/cold-wrapper-quadratic81/verify.py new file mode 100644 index 0000000000..9b86e68c2f --- /dev/null +++ b/research/cold-wrapper-quadratic81/verify.py @@ -0,0 +1,270 @@ +#!/usr/bin/env python3 +"""Symbolic affine-support and Z/4 quadratic-phase check for one cold wrapper. + +No imports from Clifford, tableau, compiler or state-vector code. +Joshua Snider, with substantial OpenAI Codex assistance. Apache-2.0. +""" +import argparse +from copy import deepcopy +from hashlib import sha256 +import gzip +import json +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +N, WIDTH, VARIABLES = 9, 4, 13 +SIZE = 2 ** N +CONSTANT = 2 ** VARIABLES +X = [2 ** i for i in range(N)] +DELTA = [2 ** (N + i) for i in range(WIDTH)] + + +def require(ok, message): + if not ok: + raise ValueError(message) + + +def add(*polynomials): + out = {} + for polynomial in polynomials: + for term, coefficient in polynomial.items(): + out[term] = (out.get(term, 0) + coefficient) % 4 + return {term: coefficient for term, coefficient in out.items() if coefficient} + + +def scale(polynomial, coefficient): + return {term: value * coefficient % 4 for term, value in polynomial.items() + if value * coefficient % 4} + + +def multiply(a, b): + # Boolean quotient: X_i^2 = X_i, hence union of monomial supports. + out = {} + for left, av in a.items(): + for right, bv in b.items(): + term = left | right + out[term] = (out.get(term, 0) + av * bv) % 4 + return {term: coefficient for term, coefficient in out.items() if coefficient} + + +def lift(form): + """Lift an affine XOR to its exact degree <= 2 Boolean polynomial mod 4.""" + constant = int(bool(form & CONSTANT)) + indices = [i for i in range(VARIABLES) if form & (2 ** i)] + sign = 1 - 2 * constant + result = {0: constant} if constant else {} + for i in indices: + result[2 ** i] = sign % 4 + for position, i in enumerate(indices): + for j in indices[position + 1:]: + result[(2 ** i) | (2 ** j)] = (-2 * sign) % 4 + return result + + +def linear_map(rows, forms, offset=0): + result = [] + for i, row in enumerate(rows): + value = CONSTANT if offset & (2 ** i) else 0 + for j, form in enumerate(forms): + if row & (2 ** j): + value ^= form + result.append(value) + return result + + +def phase(quadratic, linear, forms, constant=0): + terms = [{0: constant % 4}] + lifted = [lift(form) for form in forms] + terms.extend(scale(lifted[i], linear[i]) for i in range(N)) + terms.extend(scale(multiply(lifted[i], lifted[j]), 2) + for i in range(N) for j in range(i + 1, N) + if quadratic[i] & (2 ** j)) + result = add(*terms) + require(all(mask.bit_count() <= 2 for mask in result), 'Phase exceeds quadratic degree') + return result + + +def canonical_geometry(vectors): + # Enumerate the span to choose the same specified greedy complement, + # without importing rank, inverse, transpose or canonical_frame. + basis, span = [], {0} + for vector in vectors: + require(type(vector) is int and 0 < vector < SIZE and vector not in span, + 'Invalid terminal basis') + basis.append(vector) + span |= {value ^ vector for value in span} + for vector in (2 ** i for i in range(N)): + if vector not in span: + basis.append(vector) + span |= {value ^ vector for value in span} + require(len(vectors) == WIDTH and len(basis) == N, 'Wrong frame dimension') + physical = [] + for mask in range(SIZE): + value = 0 + for i, vector in enumerate(basis): + if mask & (2 ** i): + value ^= vector + physical.append(value) + require(len(set(physical)) == SIZE, 'Nonbijective coordinate map') + inverse = [0] * SIZE + for i, value in enumerate(physical): + inverse[value] = i + columns = [inverse[2 ** i] for i in range(N)] + inverse_rows = [sum(2 ** j for j in range(N) if columns[j] & (2 ** i)) for i in range(N)] + quadratic = [sum(((int(i == j) + (columns[i] & columns[j]).bit_count()) % 2) * (2 ** j) + for j in range(N)) for i in range(N)] + linear = [(quadratic[i] >> i) & 1 for i in range(N)] + return basis, inverse_rows, quadratic, linear + + +def validate_monomial(recipe): + require(set(recipe) == {'matrix_rows', 'quadratic_rows', 'linear_Z4', 'offset', 'phase'}, + 'Unexpected monomial fields') + rows, q, alpha = (recipe[k] for k in ('matrix_rows', 'quadratic_rows', 'linear_Z4')) + require(len(rows) == len(q) == len(alpha) == N, 'Wrong monomial dimension') + require(all(type(v) is int and 0 <= v < SIZE for v in rows + q) + and all(type(v) is int and 0 <= v < 4 for v in alpha), 'Invalid coefficients') + require(type(recipe['offset']) is int and 0 <= recipe['offset'] < SIZE + and type(recipe['phase']) is int and 0 <= recipe['phase'] < 4, 'Invalid affine phase') + require(all(((q[i] >> j) & 1) == ((q[j] >> i) & 1) for i in range(N) for j in range(N)), + 'Nonsymmetric quadratic form') + require(all(alpha[i] % 2 == ((q[i] >> i) & 1) for i in range(N)), 'Wrong diagonal lift') + images = {sum(((row & x).bit_count() % 2) * (2 ** i) for i, row in enumerate(rows)) + for x in range(SIZE)} + require(len(images) == SIZE, 'Noninvertible monomial') + + +def derive(recipe, terminal=None): + require(recipe['rank'] == WIDTH, 'Wrong residual width') + left, right = recipe['left'], recipe['right'] + validate_monomial(left) + validate_monomial(right) + basis, inverse, q, alpha = canonical_geometry(terminal or recipe['terminal_vectors']) + right_output = linear_map(right['matrix_rows'], X, right['offset']) + z = [form ^ (DELTA[i] if i < WIDTH else 0) for i, form in enumerate(right_output)] + y = linear_map(left['matrix_rows'], z, left['offset']) + displacement = [a ^ b for a, b in zip(y, X)] + coordinates = linear_map(inverse, displacement) + require(coordinates[WIDTH:] == [0] * (N - WIDTH), 'Output leaves canonical support') + c = coordinates[:WIDTH] + p_rows = [(form >> N) & (2 ** WIDTH - 1) for form in c] + images = [sum(((row & delta).bit_count() % 2) * (2 ** i) for i, row in enumerate(p_rows)) + for delta in range(2 ** WIDTH)] + require(len(set(images)) == 2 ** WIDTH, 'Path-to-kernel coordinates are not bijective') + inverse_images = [images.index(value) for value in range(2 ** WIDTH)] + components = { + 'right_phase_x': phase(right['quadratic_rows'], right['linear_Z4'], X, right['phase']), + 'left_phase_z': phase(left['quadratic_rows'], left['linear_Z4'], z, left['phase']), + 'minus_delta_weight': scale(add(*(lift(form) for form in DELTA)), -1), + 'minus_canonical_phase_y': scale(phase(q, alpha, y), -1), + 'canonical_phase_x': phase(q, alpha, X), + 'canonical_difference_weight': add(*(lift(form) for form in c)), + } + residual = add(*components.values()) + require(all(mask.bit_count() <= 2 for mask in residual), 'Residual exceeds quadratic degree') + return {'completed_basis': basis, 'output_forms': y, 'kernel_difference_forms': c, + 'spectator_displacement_forms': coordinates[WIDTH:], 'delta_map_rows': p_rows, + 'delta_map_inverse_images': inverse_images, 'components': components, + 'residual': residual} + + +def witness(polynomial): + mask = min(polynomial, key=lambda x: (x.bit_count(), x)) + value = sum(coefficient for term, coefficient in polynomial.items() if term & mask == term) % 4 + require(value != 0, 'Failed to extract phase counterexample') + return {'assignment_mask': mask, 'input': mask & (SIZE - 1), 'delta': mask >> N, + 'phase_error_mod4': value} + + +def identity_monomial(): + return dict(matrix_rows=[2 ** i for i in range(N)], quadratic_rows=[0] * N, + linear_Z4=[0] * N, offset=0, phase=0) + + +def controls(recipe): + reports = [] + def reject(name, mutate, terminal=None): + changed = deepcopy(recipe) + mutate(changed) + try: + result = derive(changed, terminal) + except ValueError as error: + reports.append({'name': name, 'rejection': str(error)}) + return None + require(result['residual'], 'Invalid wrapper accepted: ' + name) + reports.append({'name': name, 'counterexample': witness(result['residual'])}) + return result + for side in ('left', 'right'): + reject(side + '_phase', lambda r, s=side: r[s].update(phase=(r[s]['phase'] + 1) % 4)) + reject(side + '_translation', lambda r, s=side: r[s].update(offset=r[s]['offset'] ^ 1)) + reject(side + '_linear', lambda r, s=side: r[s]['linear_Z4'].__setitem__(0, (r[s]['linear_Z4'][0] + 2) % 4)) + reject('missing_' + side, lambda r, s=side: r.update({s: identity_monomial()})) + reject('swapped_wrappers', lambda r: r.update(left=recipe['right'], right=recipe['left'])) + def quadratic(r): + r['right']['quadratic_rows'][0] ^= 2 + r['right']['quadratic_rows'][1] ^= 1 + reject('right_quadratic', quadratic) + blind = reject('input_Z8', lambda r: r['right']['linear_Z4'].__setitem__(8, (r['right']['linear_Z4'][8] + 2) % 4)) + require(blind is not None and blind['residual'] == {2 ** 8: 2}, 'Unexpected Z8 residual') + reports[-1]['residual'] = [[2 ** 8, 2]] + reports[-1]['zero_input_column_unchanged'] = True + reject('wrong_terminal_same_rank', lambda r: None, [269, 140, 45, 30]) + reject('wrong_width', lambda r: r.update(rank=3)) + return reports + + +def load_instance(): + sources = json.loads((HERE / 'SOURCES.json').read_bytes()) + for name, expected in sources['sha256'].items(): + require(sha256((ROOT / name).read_bytes()).hexdigest() == expected, 'Source bytes changed: ' + name) + instance = json.loads((HERE / 'INSTANCE.json').read_bytes()) + require(instance['n'] == N and instance['seed'] == 81 and instance['helper'] == 442, + 'Wrong scoped instance') + require(instance['providers'] == {'ck': '0:429', 'jp8': '0:413'}, 'Wrong selected providers') + recipe = instance['recipe'] + require(recipe['vectors'] == [] and recipe['terminal_vectors'] == [268, 140, 45, 30] + and recipe['terminal'] == 429, 'Wrong selected frame pair') + bindings = [] + for provider, key in instance['providers'].items(): + package = ROOT / 'research/community-k492-audit/pr626/replay/mixed-global/base/providers' / provider + word = json.loads(gzip.decompress((package / 'CANONICAL-WORD.json.gz').read_bytes())) + recipes = json.loads((package / 'RESIDUAL-ADAPTERS.json').read_bytes())['recipes'] + candidates = sorted(k for k, value in recipes.items() if k.startswith('0:') and value['rank'] == WIDTH) + require(len(candidates) == 14 and candidates[81 % len(candidates)] == key, 'Seeded selection changed') + chosen = recipes[key] + require(all(chosen[k] == recipe[k] for k in recipe if k != 'terminal'), 'Provider recipe changed') + helper = instance['helper'] + require(word['start'][helper] == 0 and word['frames'][0] == [] + and word['final'][helper] == chosen['terminal'] + and word['frames'][chosen['terminal']] == recipe['terminal_vectors'], 'Detached helper') + bindings.append({'provider': provider, 'recipe_key': key, 'helper': helper}) + return instance, bindings + + +def serial(polynomial): + return [[mask, value] for mask, value in sorted(polynomial.items(), key=lambda item: (item[0].bit_count(), item[0]))] + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--out', type=Path) + args = parser.parse_args() + instance, bindings = load_instance() + certificate = derive(instance['recipe']) + require(not certificate['residual'], 'Selected phase polynomial is not zero') + certificate['components'] = {name: serial(poly) for name, poly in certificate['components'].items()} + certificate['residual'] = serial(certificate['residual']) + report = {'status': 'PASS_COLD_WRAPPER_QUADRATIC_CERTIFICATE', 'bindings': bindings, + 'variables': VARIABLES, 'coefficient_domain': 'Z/4Z; X_i^2=X_i', + 'phase_coefficient_positions': 1 + VARIABLES + VARIABLES * (VARIABLES - 1) // 2, + 'certificate': certificate, 'negative_controls': controls(instance['recipe'])} + if args.out: + args.out.write_text(json.dumps(report, indent=2) + '\n') + else: + require(report == json.loads((HERE / 'EXPECTED.json').read_bytes()), 'Recorded certificate changed') + print(report['status'], '13 variables, 92 coefficient positions, 13 rejection controls') + + +if __name__ == '__main__': + main()