From 719d9c8a74d8756003e2d478b89804c58cc85b96 Mon Sep 17 00:00:00 2001 From: ahrazzle <38987266+ahrazzle@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:37:24 +0000 Subject: [PATCH] =?UTF-8?q?Classify=20integer-shift=20cubic=20repairs=20at?= =?UTF-8?q?=20odd=20S=20and=20certify=20twenty=20general-frame=20arities?= =?UTF-8?q?=20(no=20=CE=BA)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds research/cubic-odd-s-shift-floor: - Theorem A: for odd S = r(r-1)/2, a parity lemma, an integral weight and a factorization reduce three-query repair in PR6653's integer-shift alphabet to a finite search. Over the 99 odd-S arities 3 <= r <= 200, exactly 17 admit three queries (all previously covered); the other 82, including 15, 22, 30 and 31, need four, with explicit four-query certificates. - Theorem B: twenty new three-query arities (48 ... 192) in the PR6212 / PR7475 general-frame contract, each with a literal integer-shear program. - Two separate exact checkers (normal and -O) and a byte-for-byte certificate generator. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01ErDAeESzficxtkpvZpvqVP --- .../cubic-odd-s-shift-floor/CERTIFICATES.json | 8244 +++++++++++++++++ research/cubic-odd-s-shift-floor/PROOF.md | 231 + research/cubic-odd-s-shift-floor/README.md | 243 + research/cubic-odd-s-shift-floor/SOURCES.json | 42 + research/cubic-odd-s-shift-floor/TASK.json | 109 + research/cubic-odd-s-shift-floor/VERIFY.json | 77 + research/cubic-odd-s-shift-floor/build.py | 307 + .../independent_check.py | 345 + research/cubic-odd-s-shift-floor/verify.py | 566 ++ 9 files changed, 10164 insertions(+) create mode 100644 research/cubic-odd-s-shift-floor/CERTIFICATES.json create mode 100644 research/cubic-odd-s-shift-floor/PROOF.md create mode 100644 research/cubic-odd-s-shift-floor/README.md create mode 100644 research/cubic-odd-s-shift-floor/SOURCES.json create mode 100644 research/cubic-odd-s-shift-floor/TASK.json create mode 100644 research/cubic-odd-s-shift-floor/VERIFY.json create mode 100644 research/cubic-odd-s-shift-floor/build.py create mode 100644 research/cubic-odd-s-shift-floor/independent_check.py create mode 100644 research/cubic-odd-s-shift-floor/verify.py diff --git a/research/cubic-odd-s-shift-floor/CERTIFICATES.json b/research/cubic-odd-s-shift-floor/CERTIFICATES.json new file mode 100644 index 0000000000..96eff1a7f3 --- /dev/null +++ b/research/cubic-odd-s-shift-floor/CERTIFICATES.json @@ -0,0 +1,8244 @@ +{ + "schema_version": 1, + "r_max": 200, + "conventions": { + "defect": "D_r(A,B) = sum_{i= 3` children `y += a^3; a += b`, starting from arbitrary +incoming `(Y, A, B)`. The eager endpoint is `(Y + r A^3, A, B)`. The deferred +endpoint is `(Y + sum_{i= 3`, a repair with at most three queries in `I` is the same thing +as three **distinct** integer nodes with **nonzero** dyadic weights. The +verifier also checks the two-node case directly for `r <= 200`: two distinct +integer nodes need `(c - c')^2 = M/3` and weight `S/(c - c')`, and no odd-S +arity in range passes. + +## Lemma 1 (PR6653 node lemma) + +For distinct rationals `c_0, c_1, c_2`, rational weights with +`D_r = sum_j q_j (A + c_j B)^3` exist if and only if + +``` +3 e2(c) = n e1(c) - 3S. +``` + +The weights are then unique: +`q_j = S (n - 3(c_k + c_l)) / (3 (c_j - c_k)(c_j - c_l))`, where `{j,k,l} = {0,1,2}`. +The proof is in the pinned PR6653 README. `verify.py` independently +recomputes the weights by Gaussian elimination. + +## Lemma 2: shifted coordinates + +Put `w_j = 6 c_j - n`, as PR6653's first open question suggests. Then + +``` +node equation <=> e2(w) = -K, +q_j = -6S (w_k + w_l) / ((w_j - w_k)(w_j - w_l)). +``` + +*Proof.* `36 e2(c) = e2(w) + 2n e1(w) + 3n^2` and `6 e1(c) = e1(w) + 3n`. +Substituting into `36 e2(c) = 12 n e1(c) - 36 S` gives +`e2(w) = 3n^2 - 36S = -3(2r^2 - 2r - 1)`. + +For the weights, `n - 3(c_k + c_l) = -(w_k + w_l)/2`, and +`3(c_j - c_k)(c_j - c_l) = (w_j - w_k)(w_j - w_l)/12`. ∎ + +## Lemma 3: a parity obstruction + +Let `S` be odd, and let integers `c_j` satisfy the node equation. Then the +`c_j` are not all congruent modulo 2. + +*Proof.* Each `w_j = 6c_j - n` is odd. If all `c_j` had one parity, then +all `6c_j` would agree mod 4, so `w_j = e + 4t_j` with a common odd `e`. +Then `w_j w_k = e^2 + 4e(t_j + t_k) + 16 t_j t_k ≡ 1 + 4(t_j + t_k) (mod 8)`. +Summing the three pairs gives `e2(w) ≡ 3 + 8(t_0 + t_1 + t_2) ≡ 3 (mod 8)`. +On the other hand, `-K = 3 - 12S ≡ 7 (mod 8)` when `S` is odd. ∎ + +So exactly one node, call it `c_0`, has the other parity. The gaps +`x = c_1 - c_0` and `y = c_2 - c_0` are odd, and `y - x` is even. + +## Lemma 4: one weight is a nonzero integer + +In that labelling, `w_1 = w_0 + 6x` and `w_2 = w_0 + 6y`, so Lemma 2 gives + +``` +q_0 = -S (w_0 + 3x + 3y) / (3xy). +``` + +The denominator `3xy` is odd. A dyadic `q_0` is therefore an integer, and +`q_0 != 0` by Lemma 0. ∎ + +## Lemma 5: a bound and finite fibres + +The node equation becomes `3w_0^2 + 12(x+y) w_0 + 36xy = -3M`, that is + +``` +(E) w_0^2 + 4(x+y) w_0 + 12xy + M = 0 + <=> (w_0 + 3x)(w_0 + x + 4y) = 3x^2 - M. +``` + +**Bound.** Put `s = w_0 + 2(x+y)`. Then (E) gives +`s^2 = 4(x^2 - xy + y^2) - M < 4(|x| + |y|)^2`, because `M > 0`. Hence +`|w_0 + 3(x+y)| = |s + x + y| < 3(|x| + |y|)`. Lemma 4 gives +`3|x||y| <= S |w_0 + 3(x+y)|`, so `|x||y| < S(|x| + |y|)`. With +`m = min(|x|, |y|)` and `L = max(|x|, |y|)`, this says `mL < S(m+L) <= 2SL`. +Therefore `m < 2S`. + +**Fibres.** Swap the names of `c_1` and `c_2` if needed, so that `|x| = m`. +Then `x` is odd and `0 < |x| < 2S`. Let `N = 3x^2 - M`. + +- If `N != 0`, then `d = w_0 + 3x` is a nonzero divisor of `N`. It + determines `w_0 = d - 3x` and `4y = N/d - d + 2x`. Both `d` and + `N/d = w_0 + x + 4y` are even, since `w_0` and `x` are odd. +- If `N = 0`, then either `w_0 = -3x` or `w_0 = -x - 4y`. + - In the first case `q_0 = -S/x`, which needs `x | S`. For `r <= 200` this + case occurs only at `r = 14` (`x = ±11`, `S = 91`) and at `r = 134` + (`x = ±109`, `S = 8911`). In neither case does `x` divide `S`, and the + verifier fails if it ever would. + - In the second case `q_0 = -S(2x - y)/(3xy)`, and integrality forces + `y | Sx`. + +Every case is finite, so for odd `S` the integer-shift three-query question +is decided by a finite computation. ∎ + +**Remark (the independent route).** Lemma 2 also gives +`q_2 = -S(w_0 + 3x)/(3y(y - x))`. Since `y` is odd, a dyadic `q_2` needs +`y | S(w_0 + 3x)`. When `N != 0`, `w_0 + 3x` divides `N`, so `y` divides the odd +part of `S N`. `independent_check.py` therefore enumerates the larger gap +`y` instead, and solves (E) for `w_0`. When `N = 0`, a zero `w_0 + 3x` would +make `q_2 = 0`, so the second branch above is the only one. The search's +`d`-route (`verify.py`) and `y`-route (`independent_check.py`) share no code +and agree on every node set. + +## Theorem A + +For every `r >= 3` with `S` odd, Lemmas 3–5 decide whether three queries +suffice in `I`. Among the 99 arities `3 <= r <= 200` with `S` odd: + +1. Exactly 17 admit three queries in `I`: + `3, 6, 7, 11, 19, 26, 27, 42, 50, 51, 62, 90, 91, 98, 114, 155, 162`. + These have 34 node sets in total, all listed in `CERTIFICATES.json`. + Each of the 17 lies in PR6653's table of earlier classes or among its + certificates, so `I` adds no new odd-S arity. +2. At the other 82, which include `15, 22, 30, 31, 34, 39, 43, 58`, three + queries are impossible in `I`. A four-query integer-shift certificate is + recorded for each. The minimum query count in `I` is therefore exactly + four at these 82 arities. + +PR6653's bounded search covered nodes in a window of width 160. Theorem A +shows that its failures at 15, 22, 30 and 31 were not artifacts of that +window: no integer-shift certificate exists at any size. The statement +concerns `I` only: + +- 44 of the 82 arities have three-query repairs in `G`. Examples are + `r ≡ 2 (mod 3)`, through PR6212's `b^3` query, and `r mod 9` in `{0,1}`, + through PR6215's original-b family. +- The remaining 38 have no known three-query repair in any alphabet. + Theorem A says that any such repair must leave `I`: it needs a query on + `b`, a write to `b`, or a non-integer shift. + +This is consistent with apoursh's PR7479, which shows that finite odd-modulus +tests cannot give a four-query bound in the unrestricted contract. The +obstruction here uses the 2-adic Lemma 3 together with the size bound of +Lemma 5, and it holds only in the restricted alphabet, which PR7479 leaves open. + +## Theorem B: twenty general-frame arities + +At each of + +``` +48, 49, 57, 60, 69, 84, 88, 96, 105, 112, 120, 121, 124, 132, 133, 148, +169, 177, 184, 192 +``` + +`CERTIFICATES.json` records primitive integer rows `(u_j, v_j)`, dyadic weights +with `D_r = sum_j q_j (u_j A + v_j B)^3`, and a literal program in `G`. The +programs use integer determinant-one shears and three queries, retain all +children and restore both arbitrary sources. With PR6212's lower bound, three +is the exact query minimum at these arities. + +None of the twenty lies in: + +- PR6653's table of earlier classes (`r ≡ 2 mod 3`, `r` in `{3,4}`, + `r mod 9` in `{0,1}`, `2^s`, `2^s+1`); +- PR6653's 17 certificates; +- PR7475 (`r = 24`); +- PR7478's Pell family (`r^2 - 3m^2 = 1`). + +All twenty have even `S`. For the four integer-shift ones, Theorem A +forces this. The certificates fall into three kinds: + +- At `124, 169, 177, 184` the rows are monic, so these are integer-shift + certificates whose nodes lie outside PR6653's search window. +- At `84, 105, 121, 132, 148` two rows are non-monic. +- The remaining eleven use one non-monic row, as PR7475 did at `r = 24`. + +The shear counts are explicit upper bounds from a small compiler search in +`build.py`. They are not minimality claims. + +## What is not claimed + +- No physical price or caller invoice is given. +- No shear-count optimality is claimed. +- No claim is made about the alphabet `G` at the 38 open odd-S arities, or + at the even-S arities `40, 61, 141, 165, 168, 193, 196`. +- The twenty rows and weights came from an external search that is not part + of acceptance. Each certificate is accepted only by exact checks. +- Lean or other proof-kernel review is not claimed. The two checkers are + separate AI-assisted implementations, not independent human review. diff --git a/research/cubic-odd-s-shift-floor/README.md b/research/cubic-odd-s-shift-floor/README.md new file mode 100644 index 0000000000..139176a2b9 --- /dev/null +++ b/research/cubic-odd-s-shift-floor/README.md @@ -0,0 +1,243 @@ +# Integer shifts need four cubic-repair queries at 82 odd-S arities; general frames give twenty new three-query arities + +**Scoped proof with a complete finite classification and exact certificates; +no new κ.** Prepared by ahrazzle with substantial AI assistance. Apache-2.0. + +This addresses Open next question 1 of Nick Petalas's +[PR6653](https://github.com/CrocSwap/integer-mult-bounds/pull/6653): do +`r = 15, 22, 24, 30, 31, ...` admit three dyadic queries? It also +answers, for one restricted alphabet, the restricted-family question in +apoursh's [PR7479](https://github.com/CrocSwap/integer-mult-bounds/pull/7479) +(Open next question 2). The setting is PR6200's fixed cubic reader. All `r` +children `y += a^3; a += b` are retained, and the arbitrary incoming sources +must be restored exactly to the eager endpoint `(Y + rA^3, A, B)`. + +## Results + +**A. The integer-shift alphabet needs four queries at 82 of the 99 odd-S arities up to 200.** +The integer-shift alphabet is PR6653's certificate alphabet with no reads of +`b`: only `a += k*b` with integer `k`, and only `y += q*a^3` with dyadic `q`. +Let `S = r(r-1)/2` be odd, and let three integer nodes satisfy PR6653's node +equation. Three lemmas then reduce the problem to a finite computation: + +- In shifted coordinates `w = 6c - (2r-1)`, a mod-8 argument shows that + exactly one node has the other parity. +- That node's weight must be a nonzero integer, which bounds the smaller gap + below `2S`. +- The node equation factors as `(w_0+3x)(w_0+x+4y) = 3x^2 - M`, so each gap + has finitely many partners. + +Running the finite search over all 99 odd-S arities `3 <= r <= 200` gives: + +| | arities | +|---|---| +| three integer-shift queries exist (34 node sets) | 3, 6, 7, 11, 19, 26, 27, 42, 50, 51, 62, 90, 91, 98, 114, 155, 162 | +| impossible; four suffice (certificate each) | the other 82, including **15, 22, 30, 31**, 34, 39, 43, 58 | + +Every solvable arity is already in PR6653's classes or certificates. So +PR6653's bounded integer-direction search failed at 15, 22, 30 and 31 for a +structural reason, not because its window was too small. The exact +integer-shift minimum at those 82 arities is **four**. + +This is a statement about the integer-shift alphabet only. 44 of the 82 +arities already have three-query repairs in the general alphabet, for +example through PR6212's `b^3` query or PR6215's original-b family. For +the other 38, any three-query repair must query `b`, write `b`, or use a +non-integer shift. + +**B. Twenty new three-query arities.** At + +```text +48, 49, 57, 60, 69, 84, 88, 96, 105, 112, 120, 121, 124, 132, 133, 148, 169, 177, 184, 192 +``` + +three dyadic queries repair the reader exactly in the general-frame contract +of [PR6212](https://github.com/CrocSwap/integer-mult-bounds/pull/6212) and +[PR7475](https://github.com/CrocSwap/integer-mult-bounds/pull/7475). Each +certificate has a literal program built from integer determinant-one shears. +With PR6212's lower bound, three is the exact minimum. None of these arities +is in: + +- PR6653's prior-class table or its 17 certificates; +- PR7475 (`r = 24`); +- [PR7478](https://github.com/CrocSwap/integer-mult-bounds/pull/7478)'s Pell family. + +Two of the rows are non-monic at 84, 105, 121, 132 and 148. The +certificates at 124, 169, 177 and 184 are integer-shift certificates whose +nodes lie outside PR6653's search window. Example, `r = 57`: + +```text +D_57 = -(209/512)(5A-4B)^3 + (11039/512)(A+12B)^3 + (7543/256)(A+44B)^3 +``` + +| r | rows `(u,v)` of `uA+vB` | weights | shears | +|---:|---|---|---:| +| 48 | (13,184) (1,-40) (1,24) | -47/1024, -1081/512, 105421/1024 | 8 | +| 49 | (5,-1217) (1,-141) (1,115) | 245/16384, -118139/16384, 43757/8192 | 8 | +| 57 | (5,-4) (1,12) (1,44) | -209/512, 11039/512, 7543/256 | 6 | +| 60 | (5,242) (1,-6) (1,74) | 295/1024, -4307/128, -2419/1024 | 8 | +| 69 | (31,963) (1,-35) (1,29) | 1955/65536, -523549/65536, -1803683/2048 | 8 | +| 84 | (11,-1235) (1,295) (7,2193) | -17513/2097152, 557345/8192, -348019/2097152 | 12 | +| 88 | (5,272) (1,-16) (1,36) | 29/32, -1073/32, -319/4 | 8 | +| 96 | (5,-208) (1,-48) (1,80) | -95/64, 36005/256, 11495/256 | 8 | +| 105 | (13,1396) (1,68) (7,-36) | 1001/262144, 4046315/65536, -53599/262144 | 12 | +| 112 | (19,-120) (1,56) (1,88) | -11/1024, 2933/128, 51985/1024 | 8 | +| 120 | (5,2781) (1,-263) (1,761) | 149345/1048576, -11044985/1048576, -1905785/262144 | 6 | +| 121 | (37,5067) (1,47) (7,73) | 605/2097152, 2424235/16384, -994015/2097152 | 12 | +| 124 | (1,259) (1,-765) (1,-253) | 4195571/262144, 291059/262144, -2243315/131072 | 4 | +| 132 | (19,-20806) (1,670) (7,-9390) | -9229/4194304, 201427/32768, 109385/4194304 | 10 | +| 133 | (11,1106) (1,-10) (1,102) | 77/512, -41459/512, -15257/128 | 8 | +| 148 | (19,-635) (1,-249) (11,1357) | -705257/67108864, 9538193/8388608, 3577049/67108864 | 14 | +| 169 | (1,340) (1,-52) (1,204) | -169/16, -31265/512, 36673/512 | 4 | +| 177 | (1,-2765) (1,-2253) (1,1331) | 2024231/262144, -431585/32768, 1428449/262144 | 4 | +| 184 | (1,84) (1,-160) (1,64) | 3013/4, -253/32, -23851/32 | 4 | +| 192 | (7,160) (1,96) (1,608) | -47177/65536, 2018297/8192, 35335/65536 | 6 | + +Here `D_r = sum_i (A+iB)^3 - rA^3 = sum_j q_j (u_j A + v_j B)^3`. The programs +subtract these terms. Shear counts are explicit upper bounds, not +minimality claims. + +After this package, the arities `r <= 200` with no known three-query +repair in any alphabet are: + +- the 38 odd-S arities listed in `CERTIFICATES.json`, starting with 15, 22, + 30, 31, 34, 39, 43, 58; +- the even-S arities 40, 61, 141, 165, 168, 193 and 196. + +[PROOF.md](PROOF.md) has the contract, lemmas and theorems. +[CERTIFICATES.json](CERTIFICATES.json) records all 34 node sets, 17 +three-query, 82 four-query and 20 general-frame certificates, with their +literal programs. + +## Evidence and reproduction + +From the repository root, with CPython 3.12 and the standard library only: + +```sh +python3.12 -B scripts/research_package.py --package research/cubic-odd-s-shift-floor +python3.12 -I -W error -B research/cubic-odd-s-shift-floor/verify.py +python3.12 -I -W error -B research/cubic-odd-s-shift-floor/independent_check.py +python3.12 -I -W error -B research/cubic-odd-s-shift-floor/build.py --check +``` + +The registered manifest runs both checkers twice, normally and under `-O`, +plus the byte-for-byte regeneration. Each check is explicit, so it stays +active under `-O`. Local times were about 60 s, 85 s and 95 s. The expected +markers are `PASS_CUBIC_ODD_S_SHIFT_FLOOR` and +`PASS_CUBIC_ODD_S_SHIFT_FLOOR_INDEPENDENT`. + +- [verify.py](verify.py) + - Authenticates the four pinned predecessor files and checks four textual + anchors. These are PR6653's alphabet and substitution, PR6212's two-query + and four-query statements, and PR6653's uncovered-arity list. It also + rejects two in-memory byte mutations. + - Reruns the complete search for Theorem A from scratch. It factors + `3x^2 - M` for every odd gap `|x| < 2S` with a quadratic sieve and + enumerates divisors. + - Checks every certificate by exact coefficient comparison and weight-ring + and contract checks. It recomputes the weights of integer nodes by + Gaussian elimination. + - Executes every program symbolically over all `r` retained children, and + on dirty rational inputs. + - Runs nine rejection controls. Among them, at `r = 12` the same search + misses PR6653's same-parity certificate `(-21,-5,11)`, which shows that + the odd-S parity lemma is load-bearing. +- [independent_check.py](independent_check.py) + - Imports neither of the other scripts. + - Takes the other route of PROOF.md's Remark: it enumerates the larger gap + over divisors of `S(3x^2 - M)`, solves the node quadratic, and finds + square roots by Cipolla's method. + - Checks identities by evaluating both sides at six non-proportional + points, summing the left side child by child. + - Runs programs in its own interpreter, recomputes the predecessor + arities, and rejects five mutations. +- [build.py](build.py) + - Regenerates `CERTIFICATES.json`. The four-query certificates are the + lexicographically first integer nodes in `[-12, 12]`. + - Compiles the twenty general-frame rows into integer-shear programs. + +The twenty general-frame rows and weights were found by an external search +that is not included. Acceptance replays only the exact certificates and +does not depend on that search. Theorem A, by contrast, is a complete +classification: its search is the proof, and both checkers run it in full. +The two checkers are separate AI-assisted implementations. Independent +human or proof-kernel review is not claimed. + +## Scope and coordination + +[TASK.json](TASK.json) keeps the original `joint-query-controller` card. It +declares a **changed** scope: a source-restoration and coefficient side +question, the same family as PR7475, PR7478 and PR7479, not a priced +supplier. + +- Physical event prices, precision, routing and caller invoices remain + unknown. +- Three queries need not be cheaper than `r` eager restoration shears. +- The selected result and its five framework assumptions are unchanged. + +Canonical main was `e54523517d0f03e58352e647c403a5af3e525a57` on entry and +again before submission. Overlap checks: + +- Every open PR head from #7480 through #7538 was fetched, along with the + ledger's cubic PRs (#6200 through #6797) and PR7475, PR7478 and PR7479. +- The only concurrent cubic-reader work found is Nick Petalas's + [PR7506](https://github.com/CrocSwap/integer-mult-bounds/pull/7506). It + shows that any three-query repair at `r = 15`, in any frame, needs two rows + of height above 64. That result and Theorem A are complementary: PR7506 + bounds all frames at one arity, while Theorem A excludes integer shifts of + every size at 82 arities. +- `scripts/find_overlap.py --offline` found only the local cubic packages + already cited. + +These checks are leads, not a novelty certificate. + +## Open next questions + +1. **General frames at the 38 open odd-S arities, starting with r = 15.** + - *Why it matters:* this is the remaining three-versus-four question. + Theorem A shows that any such repair must leave the integer-shift + alphabet. + - *First step:* extend Lemma 3 to primitive rows with even `u` (dyadic + shifts), where the mod-8 argument changes. Then combine it with + PR7506's height bound. + - *Blocker:* with non-monic rows, the weight that Lemma 4 makes integral + need not be integral. +2. **Even-S arities 40, 61, 141, 165, 168, 193, 196.** + - *Why it matters:* these are the only even-S arities `r <= 200` still + open after this package. + - *Local evidence (not packaged):* a C search found no three-query + dyadic certificate with two integer nodes `|c| <= 12000` and the third + row forced by the node equation, of any denominator. + - *First step:* search two non-monic rows. Alternatively, test the + squareness condition of the node equation for local obstructions. + - *Blocker:* even `S` has no parity lemma, so no finite reduction is + known. +3. **Prices.** + - *Why it matters:* the four-shear integer programs at 124, 169, 177 and + 184 and the six-shear programs at 57, 120 and 192 are the cheapest + candidates against `r` eager shears. + - *First step:* price their weighted queries and shears under one pinned + backend, using PR7475's event inequality. + - *Blocker:* unpriced coefficient preparation, precision, routing and + caller work. + +These questions are also recorded in [TASK.json](TASK.json). + +## Attribution + +- Nick Petalas: PR6200 supplies the reader, defect and rational comparison, + and PR6653 the node lemma, integer-shift alphabet, shifted coordinates and + the open question. +- apoursh: + - PR6212: the dyadic lower bound and general-frame contract; + - PR6215: the original-b family; + - PR7475: the `r = 24` general frame; + - PR7478: the Pell family; + - PR7479: local solubility. +- AAAmirinu's PR6246 and CubeJerry's PR6250 supply the power-of-two + families. + +Their results are cited and pinned, not re-proved, except where this +package re-checks a statement. The proofs, search, certificates and +checkers here were prepared with substantial AI assistance, as recorded in +TASK.json. diff --git a/research/cubic-odd-s-shift-floor/SOURCES.json b/research/cubic-odd-s-shift-floor/SOURCES.json new file mode 100644 index 0000000000..ee40bbd5df --- /dev/null +++ b/research/cubic-odd-s-shift-floor/SOURCES.json @@ -0,0 +1,42 @@ +{ + "schema_version": 1, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "75d77b328ea02ded535e7f23aee5b1e55d0bb1a8", + "sha256": "154c3d30455d778fd3343b6b4851f0fa4665f0f7625b0adb3675e2bafbbf6bf1" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "research/cubic-three-query-arities/CERTIFICATES.json", + "usage": "input", + "git_blob": "ae72c7ef712704e4915e396facea262a256707ff", + "sha256": "b4839a5cfff2f69d902622a06d271842a079e953f534fb4c7dbc2b152589aef9" + }, + { + "path": "research/cubic-three-query-arities/README.md", + "usage": "input", + "git_blob": "80c3a43f12e0ad4d586ed69eb3c8278cb60475e2", + "sha256": "d6f818ad69170fde178582595d3b5aa3e5ea1e6e4fde9d8e866f185aa2de5b55" + }, + { + "path": "research/dyadic-cubic-repair/PROOF.md", + "usage": "input", + "git_blob": "a1c41a9afc83302f8b664bb45467821b9c088f0f", + "sha256": "1296f12278e198b6a22d8d88355cd58c1ee4fc2ab0e6941721614bb06cb1e7d5" + }, + { + "path": "research/dyadic-cubic-repair/README.md", + "usage": "input", + "git_blob": "de6b0954b428d7b4d3421c97c29f4bc6517f04d2", + "sha256": "2a291420d43c4ab0157c23ab3adfc7494b90b6cf11ab7bb6842c99ece7a0594d" + } + ] +} diff --git a/research/cubic-odd-s-shift-floor/TASK.json b/research/cubic-odd-s-shift-floor/TASK.json new file mode 100644 index 0000000000..399bafb142 --- /dev/null +++ b/research/cubic-odd-s-shift-floor/TASK.json @@ -0,0 +1,109 @@ +{ + "schema_version": 1, + "task_id": "joint-query-controller", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "joint-query-controller", + "question": "Can a changed query demand or caller remove real work while satisfying native chronology and restoration?", + "starting_points": [ + "docs/research/current-priorities.md", + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md" + ], + "methods": [ + "Construct and independently check one source-bound instance of the stated first experiment.", + "Seek an exact counterexample or target-specific complete-budget obstruction to that same proposed change." + ], + "acceptance_gate": "A source-bound arbitrary-input identity and legal producer/consumer boundary with the complete paid and productive target invoice, including restoration, ownership, native alignment and extra charges. Price under the actual current model; historical ceiling.py assumptions must be established before use. A favorable optimistic relaxation keeps a route open but is not a completed supplier. A scoped local result remains useful; expansion requires the family-level budget gate.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read revision 8, the selected review and live exact-source handoffs. Then follow this card's bounded first_experiment.", + "scope": "Source-bound orientation only, not a supplier replay or theorem proof." + }, + "first_experiment": "Choose an exact caller and a new demand/interface hypothesis. Read the scoped #5617/#5631/#5649/#5747 and #5720/#5745 objections before rebuilding an excluded schedule. Compare the complete matched source/consumer protocols including all retained helper outputs. For an active-mode injection, first check #5745: its canonical delivery claim repays the eight removed centre jobs. Audit that exact claim or change its channel/feedback hypothesis; do not repeat the same free-injection search. Stop if the full favorable budget fails or the required restored output is unobservable.", + "bottleneck_link": "Judge the actual current supplier contract and complete signed target/paid bill; frozen-profile ceilings require an applicability proof.", + "allowed_variations": [ + "One exact source head, helper/cut region or quantified proposition and changed hypothesis; check live handoffs first. Different seeds are not different scopes." + ], + "scope_change_triggers": [ + "Changing source head, helper/cut domain, operation alphabet or caller boundary without recording the new scope.", + "Treating an archived proposal or local numerical pass as complete supplier admission." + ], + "overlap_terms": [ + "query demand", + "active mode", + "5720", + "5745", + "5747", + "caller" + ], + "existing_checks": [ + { + "scope": "PR #4166: author-checked installed producer/service/return/bridge connection; native-component comparison loses.", + "evidence": "research/qq16-caller-install/README.md", + "remaining": "Complete matched physical protocol bill, or changed source-compatible demand/circuit; no affordable supplier yet.", + "status": "author-checked", + "source_commit": "0b082d22a0e9a442d264ab0633e35ef26c790630", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "Selected PR5599: complete helper-subspace construction and independent caller replay; five framework assumptions remain.", + "evidence": "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "remaining": "The next experiment must identify uncovered source-specific work. Successor archive intake does not transfer this admission.", + "status": "reviewed", + "source_commit": "09dd0965711ca7eeb169057a420abab1c9052137", + "selected_record_sha256": "2a0220e866417774606e0f991e41b9c1d26b1f43b97857238cf478dbc7d330b5" + } + ] + }, + "scope_status": "changed", + "actual_scope": "Decide three-versus-four dyadic cube queries for PR6200's fixed cubic reader in PR6653's integer-shift alphabet (integer a += k*b only, queries on a only) at every odd-S arity 3 <= r <= 200, and certify twenty further arities with three general-frame queries (PR6212/PR7475 contract); retain all r children and restore arbitrary dirty sources.", + "scope_change_reason": "A bounded coefficient/restoration side question of the joint-query-controller card, continuing PR6653 Open next question 1 and PR7479 Open next question 2, not the card's complete physical supplier acceptance gate. Changes the alphabet relative to the card: the obstruction is proved only for integer shifts on a, the certificates use general frames.", + "bottleneck_link": "Side result: closes the integer-direction route at 82 odd-S arities (so any three-query repair there must use b or non-integer shifts) and adds twenty exact three-query arities. Physical prices and caller overhead remain unknown; no supplier or kappa change.", + "budget_minutes": 60, + "stop_rule": "Stop after the complete odd-S integer-shift classification to r=200, explicit four-query witnesses, twenty independently replayed general-frame programs and two separate exact checkers; do not extend to physical savings without a matched bill.", + "outcome": "partial", + "evidence": "PROOF.md: Lemmas 0-5 and Theorems A-B. CERTIFICATES.json: 34 integer node sets, 17 three-query and 82 four-query integer-shift programs, 20 general-frame programs. verify.py (complete d-route search, exact elimination, symbolic execution, source pins, nine controls) and independent_check.py (y-route search with Cipolla roots, six-point identities, separate interpreter, five controls), each normal and under -O; build.py --check regenerates the certificates byte for byte.", + "author": "ahrazzle", + "ai_assistance": "Substantial AI assistance: certificate search, proofs, both checkers and the generator were produced with AI agents (including Anthropic Claude); the two checkers are separate implementations. No independent human or formal proof-kernel review is claimed.", + "open_questions": [ + { + "question": "Do the 38 open odd-S arities r <= 200 (first 15, 22, 30, 31) admit three dyadic queries in general frames?", + "why_it_matters": "It is the remaining three-versus-four question; Theorem A shows a repair must read or write b or use non-integer shifts.", + "first_step": "Extend the parity Lemma 3 to primitive rows with even u (dyadic shifts) and combine with PR7506's height-64 bound at r=15.", + "blocked_by": "With non-monic rows the weight made integral in Lemma 4 need not be integral, so no size bound is known." + }, + { + "question": "Do the even-S arities 40, 61, 141, 165, 168, 193, 196 admit three dyadic queries?", + "why_it_matters": "They are the only even-S arities r <= 200 still open after this package.", + "first_step": "Search two non-monic rows with the third row forced by the node equation, or test local solvability of the squareness condition; a local unpackaged search with two integer nodes |c| <= 12000 found none.", + "blocked_by": "For even S there is no parity lemma and hence no finite reduction." + }, + { + "question": "Do the cheapest new programs (four shears at 124, 169, 177, 184; six at 57, 120, 192) beat r eager restoration shears?", + "why_it_matters": "Query-count minima only matter if the complete event bill is smaller.", + "first_step": "Price their weighted queries and shears under one pinned backend using PR7475's event inequality.", + "blocked_by": "Unpriced coefficient preparation, precision, routing, storage and caller work." + } + ], + "family_decision": { + "decision": "narrow", + "boundary": "Fixed cubic reader, all r children retained, arbitrary dirty sources restored exactly, no output feedback; integer-shift alphabet for Theorem A, PR6212 general frames for Theorem B; 3 <= r <= 200.", + "evidence_status": "author-checked with two separate AI-assisted implementations", + "obligations": { + "integer_shift_classification_odd_s_r_le_200": "proved (finite reduction plus complete search)", + "four_query_integer_shift_upper_bound": "constructive", + "twenty_general_frame_certificates": "constructive, exact", + "general_frame_status_at_45_open_arities": "unknown", + "physical_prices_and_complete_caller_invoice": "unknown" + }, + "stop": "No further arity census until the parity lemma is extended to non-monic rows or a priced comparison is requested." + } +} diff --git a/research/cubic-odd-s-shift-floor/VERIFY.json b/research/cubic-odd-s-shift-floor/VERIFY.json new file mode 100644 index 0000000000..55d1e023fb --- /dev/null +++ b/research/cubic-odd-s-shift-floor/VERIFY.json @@ -0,0 +1,77 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/cubic-three-query-arities/CERTIFICATES.json", + "research/cubic-three-query-arities/README.md", + "research/dyadic-cubic-repair/PROOF.md", + "research/dyadic-cubic-repair/README.md" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 230, + "checks": "Source pins and anchors, complete odd-S integer-shift classification (d-route), exact certificates, symbolic and dirty program replay, nine rejection controls" + }, + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "-O", + "{package}/verify.py" + ], + "timeout_seconds": 230, + "checks": "The primary checks under optimized Python (explicit checks, no asserts)" + }, + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "{package}/independent_check.py" + ], + "timeout_seconds": 230, + "checks": "Independent y-route classification with Cipolla roots, six-point identities, separate program interpreter, predecessor arities, five mutation controls" + }, + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "-O", + "{package}/independent_check.py" + ], + "timeout_seconds": 230, + "checks": "The independent checks under optimized Python" + }, + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "{package}/build.py", + "--check" + ], + "timeout_seconds": 240, + "checks": "CERTIFICATES.json regenerates byte for byte" + } + ] +} diff --git a/research/cubic-odd-s-shift-floor/build.py b/research/cubic-odd-s-shift-floor/build.py new file mode 100644 index 0000000000..ee39df941f --- /dev/null +++ b/research/cubic-odd-s-shift-floor/build.py @@ -0,0 +1,307 @@ +#!/usr/bin/env python3 +"""Generate CERTIFICATES.json for research/cubic-odd-s-shift-floor. + + python3.12 -B research/cubic-odd-s-shift-floor/build.py # write + python3.12 -B research/cubic-odd-s-shift-floor/build.py --check # compare + +Deterministic. It reuses verify.py's complete integer-shift search, takes +the lexicographically first four-node integer certificate with nodes in +[-12, 12] at each arity that needs four queries, and compiles the twenty +general-frame rows/weights below into explicit integer-shear programs. +The twenty rows and weights came from an external search that is not part +of acceptance; every certificate is accepted only by the exact checks. +Prepared by ahrazzle with substantial AI assistance. Apache-2.0. +""" + +from __future__ import annotations + +import importlib.util +import itertools +import json +import pathlib +import sys +from fractions import Fraction + +PKG = pathlib.Path(__file__).resolve().parent +spec = importlib.util.spec_from_file_location("cubic_floor_verify", PKG / "verify.py") +V = importlib.util.module_from_spec(spec) +spec.loader.exec_module(V) + +GENERAL = { + 48: ([(13, 184), (1, -40), (1, 24)], ["-47/1024", "-1081/512", "105421/1024"]), + 49: ([(5, -1217), (1, -141), (1, 115)], ["245/16384", "-118139/16384", "43757/8192"]), + 57: ([(5, -4), (1, 12), (1, 44)], ["-209/512", "11039/512", "7543/256"]), + 60: ([(5, 242), (1, -6), (1, 74)], ["295/1024", "-4307/128", "-2419/1024"]), + 69: ([(31, 963), (1, -35), (1, 29)], ["1955/65536", "-523549/65536", "-1803683/2048"]), + 84: ([(11, -1235), (1, 295), (7, 2193)], ["-17513/2097152", "557345/8192", "-348019/2097152"]), + 88: ([(5, 272), (1, -16), (1, 36)], ["29/32", "-1073/32", "-319/4"]), + 96: ([(5, -208), (1, -48), (1, 80)], ["-95/64", "36005/256", "11495/256"]), + 105: ([(13, 1396), (1, 68), (7, -36)], ["1001/262144", "4046315/65536", "-53599/262144"]), + 112: ([(19, -120), (1, 56), (1, 88)], ["-11/1024", "2933/128", "51985/1024"]), + 120: ([(5, 2781), (1, -263), (1, 761)], ["149345/1048576", "-11044985/1048576", "-1905785/262144"]), + 121: ([(37, 5067), (1, 47), (7, 73)], ["605/2097152", "2424235/16384", "-994015/2097152"]), + 124: ([(1, 259), (1, -765), (1, -253)], ["4195571/262144", "291059/262144", "-2243315/131072"]), + 132: ([(19, -20806), (1, 670), (7, -9390)], ["-9229/4194304", "201427/32768", "109385/4194304"]), + 133: ([(11, 1106), (1, -10), (1, 102)], ["77/512", "-41459/512", "-15257/128"]), + 148: ([(19, -635), (1, -249), (11, 1357)], ["-705257/67108864", "9538193/8388608", "3577049/67108864"]), + 169: ([(1, 340), (1, -52), (1, 204)], ["-169/16", "-31265/512", "36673/512"]), + 177: ([(1, -2765), (1, -2253), (1, 1331)], ["2024231/262144", "-431585/32768", "1428449/262144"]), + 184: ([(1, 84), (1, -160), (1, 64)], ["3013/4", "-253/32", "-23851/32"]), + 192: ([(7, 160), (1, 96), (1, 608)], ["-47177/65536", "2018297/8192", "35335/65536"]), +} + + +def fstr(x: Fraction) -> str: + return str(x.numerator) if x.denominator == 1 else f"{x.numerator}/{x.denominator}" + + +# --------------------------------------------------- SL2(Z) shear words + +def mat_mul(X, Y): + return ((X[0][0] * Y[0][0] + X[0][1] * Y[1][0], X[0][0] * Y[0][1] + X[0][1] * Y[1][1]), + (X[1][0] * Y[0][0] + X[1][1] * Y[1][0], X[1][0] * Y[0][1] + X[1][1] * Y[1][1])) + + +def op_matrix(kind: str, k: int): + return ((1, k), (0, 1)) if kind == "a" else ((1, 0), (k, 1)) + + +def _greedy(G): + """Nearest-integer Euclid on the first column; -I is cleared with + S^2, S = U_-1 L_1 U_-1. Returns reduction ops E_1..E_m (E_m...E_1 G = I).""" + red, M = [], G + while M[1][0] != 0: + (p, _), (r, _) = M + if p == 0: + o = ("a", r) + elif abs(p) > abs(r): + o = ("a", -round(Fraction(p, r))) + else: + o = ("b", -round(Fraction(r, p))) + red.append(o) + M = mat_mul(op_matrix(*o), M) + if M[0][0] == -1: + for o in [("a", -1), ("b", 1), ("a", -1)] * 2: + red.append(o) + M = mat_mul(op_matrix(*o), M) + if M[0][1]: + red.append(("a", -M[0][1])) + return red + + +def _dfs(G, budget): + best, stack = None, [(G, [])] + while stack and budget > 0: + budget -= 1 + M, red = stack.pop() + (p, q), (r, s) = M + if r == 0: + if p == 1: + red = red + ([("a", -q)] if q else []) + if best is None or len(red) < len(best): + best = red + continue + if best is not None and len(red) + 1 >= len(best): + continue + cand = [] + if p == 0: + cand.append(("a", r)) + elif abs(p) > abs(r): + lo = -(p // r) + cand += [("a", lo), ("a", lo - 1)] if p % r else [("a", lo)] + else: + lo = -(r // p) + cand += [("b", lo), ("b", lo - 1)] if r % p else [("b", lo)] + cand.sort(key=lambda o: abs(M[0][0] + o[1] * M[1][0]) if o[0] == "a" + else abs(M[1][0] + o[1] * M[0][0]), reverse=True) + for o in cand: + if o[1] != 0: + stack.append((mat_mul(op_matrix(*o), M), red + [o])) + return best + + +def word(G, budget: int = 300): + """Shear ops o_1..o_n (('a', k): a += k*b, ('b', k): b += k*a) with + O_n...O_1 = G: the shorter of a bounded rounding search and a greedy + Euclid word, checked by multiplication.""" + red = _greedy(G) + alt = _dfs(G, budget) + if alt is not None and len(alt) < len(red): + red = alt + out = [(kind, -k) for kind, k in reversed(red)] + acc = ((1, 0), (0, 1)) + for kind, k in out: + acc = mat_mul(op_matrix(kind, k), acc) + if acc != G: + raise SystemExit("shear word does not multiply to G") + return out + + +def inv(F): + (a1, a2), (b1, b2) = F + return ((b2, -a2), (-b1, a1)) + + +def egcd(x: int, y: int): + if y == 0: + return (x, 1, 0) if x >= 0 else (-x, -1, 0) + g, s, t = egcd(y, x % y) + return g, t, s - (x // y) * t + + +def transitions(F, row, reg: str, T: int = 2): + """All G in SL2(Z) (bounded completions) with (G F) having `row` in reg.""" + Fi = inv(F) + g = row[0] * Fi[0][0] + row[1] * Fi[1][0] + h = row[0] * Fi[0][1] + row[1] * Fi[1][1] + d, s, t = egcd(g, h) + if d != 1: + raise SystemExit("non-primitive row") + for k in range(-T, T + 1): + if reg == "a": # det [[g,h],[x,y]] = g y - h x = 1 + x, y = -t + k * g, s + k * h + yield ((g, h), (x, y)) + else: # det [[x,y],[g,h]] = x h - y g = 1 + x, y = t + k * g, -s + k * h + yield ((x, y), (g, h)) + + +def compile_general(r: int, rows, weights): + """Search query order, register, sign and completions for few shears.""" + best = None + start = ((1, r), (0, 1)) + for order in itertools.permutations(range(3)): + for regs in itertools.product("ab", repeat=3): + for signs in itertools.product((1, -1), repeat=3): + partial = [(start, [], 0)] + for j, reg, sg in zip(order, regs, signs): + row = (sg * rows[j][0], sg * rows[j][1]) + nxt = [] + for F, ev, cost in partial: + if (F[0] if reg == "a" else F[1]) == row: + Gs = [((1, 0), (0, 1))] + else: + Gs = list(transitions(F, row, reg)) + for G in Gs: + w = word(G) if G != ((1, 0), (0, 1)) else [] + F2 = mat_mul(G, F) + q = -Fraction(weights[j]) * sg + e2 = ev + [("a+=b" if kd == "a" else "b+=a", k) for kd, k in w] + e2 = e2 + [("y+=a^3" if reg == "a" else "y+=b^3", q)] + nxt.append((F2, e2, cost + len(w))) + nxt.sort(key=lambda z: z[2]) + partial = nxt[:12] + for F, ev, cost in partial: + w = word(inv(F)) if F != ((1, 0), (0, 1)) else [] + total = cost + len(w) + ev2 = ev + [("a+=b" if kd == "a" else "b+=a", k) for kd, k in w] + key = (total, json.dumps([[a, fstr(Fraction(b))] for a, b in ev2])) + if best is None or key < best[0]: + best = (key, ev2) + return best[1] + + +def shift_program(r: int, nodes, weights): + """Integer-shift program visiting nodes; r first and 0 last if present.""" + order = sorted(range(len(nodes)), key=lambda j: (nodes[j] != r, nodes[j] == 0, j)) + ev, cur = [], r + for j in order: + if nodes[j] != cur: + ev.append(("a+=b", nodes[j] - cur)) + cur = nodes[j] + ev.append(("y+=a^3", -weights[j])) + if cur != 0: + ev.append(("a+=b", -cur)) + return ev + + +def four_node_certificate(r: int, box: int = 12): + S1 = Fraction(sum(range(r))) + m = [Fraction(0), S1, Fraction(sum(i * i for i in range(r))), S1 * S1] + for c in itertools.combinations(range(-box, box + 1), 4): + A = [[Fraction(x) ** k for x in c] + [m[k]] for k in range(4)] + for col in range(4): + piv = next(i for i in range(col, 4) if A[i][col] != 0) + A[col], A[piv] = A[piv], A[col] + for i in range(4): + if i != col and A[i][col] != 0: + f = A[i][col] / A[col][col] + A[i] = [x - f * y for x, y in zip(A[i], A[col])] + q = [A[i][4] / A[i][i] for i in range(4)] + if all(x != 0 and V.is_dyadic(x) for x in q): + return list(c), q + raise SystemExit(f"no four-node certificate at r={r}") + + +def ev_json(ev): + return [[k, fstr(Fraction(x))] for k, x in ev] + + +def build() -> str: + primes = V.primes_upto(70000) + odd_s = [r for r in range(3, V.R_MAX + 1) if (r * (r - 1) // 2) % 2] + table = {r: V.integer_shift_triples(r, primes) for r in odd_s} + solvable = [r for r in odd_s if table[r]] + impossible = [r for r in odd_s if not table[r]] + certs = [] + for r in solvable: + nodes = list(min(table[r], key=lambda t: (max(map(abs, t)), t))) + w = V.node_weights(r, nodes) + ev = shift_program(r, nodes, w) + certs.append({"r": r, "kind": "three-shift", "rows": [[1, c] for c in nodes], + "weights": [fstr(x) for x in w], "shears": V.shear_count(ev), + "program": ev_json(ev)}) + for r in impossible: + nodes, w = four_node_certificate(r) + ev = shift_program(r, nodes, w) + certs.append({"r": r, "kind": "four-shift", "rows": [[1, c] for c in nodes], + "weights": [fstr(x) for x in w], "shears": V.shear_count(ev), + "program": ev_json(ev)}) + for r, (rows, ws) in GENERAL.items(): + ev = compile_general(r, rows, ws) + certs.append({"r": r, "kind": "general", "rows": [list(x) for x in rows], + "weights": ws, "shears": V.shear_count(ev), "program": ev_json(ev)}) + c6653 = json.loads((V.ROOT / V.PR6653_CERTS).read_text(encoding="utf-8")) + p6653 = {c["r"] for c in c6653["certificates"]} + pell = V.pell_arities(V.R_MAX) + known = {r for r in range(3, V.R_MAX + 1) + if V.covered_6653(r) or r in p6653 or r == V.PR7475_R24 or r in pell} + after = known | set(GENERAL) + data = { + "schema_version": 1, + "r_max": V.R_MAX, + "conventions": { + "defect": "D_r(A,B) = sum_{i None: + text = build() + out = PKG / "CERTIFICATES.json" + if "--check" in sys.argv[1:]: + if out.read_text(encoding="utf-8") != text: + raise SystemExit("FAIL: CERTIFICATES.json differs from regeneration") + print("PASS CERTIFICATES.json regenerates byte for byte") + else: + out.write_text(text, encoding="utf-8") + print(f"wrote {out}") + + +if __name__ == "__main__": + main() diff --git a/research/cubic-odd-s-shift-floor/independent_check.py b/research/cubic-odd-s-shift-floor/independent_check.py new file mode 100644 index 0000000000..3ba9e9b493 --- /dev/null +++ b/research/cubic-odd-s-shift-floor/independent_check.py @@ -0,0 +1,345 @@ +#!/usr/bin/env python3 +"""Independent checker for research/cubic-odd-s-shift-floor. + +Imports neither verify.py nor build.py, and uses different routes: + +* identities are checked by evaluating both sides at six pairwise + non-proportional points (a binary cubic form is fixed by four), with the + left side summed child by child; +* programs run in a separate interpreter on six input pairs; every event is + a linear source change or a cube of a linear form, so y_final - Y is a + binary cubic form and the registers are linear forms, and agreement at + these points is an identity; +* the integer-shift classification enumerates the LARGER gap y over the odd + divisors of S*N(x) and solves the node quadratic for the odd node, instead + of enumerating divisors d of N(x) (PROOF.md, Remark after Lemma 5); + modular square roots use Cipolla's method; +* predecessor arities are recomputed (Pell by direct square test). + +Prepared by ahrazzle with substantial AI assistance. Apache-2.0. +""" + +from __future__ import annotations + +import json +import math +import pathlib +import sys +from fractions import Fraction as Q + +HERE = pathlib.Path(__file__).resolve().parent +TOP = HERE.parents[1] +POINTS = [(1, 0), (0, 1), (1, 1), (1, -1), (2, 1), (3, -2)] + + +def stop(why: str) -> None: + print("INDEPENDENT FAIL:", why) + sys.exit(1) + + +def lhs(r: int, A: Q, B: Q) -> Q: + total = Q(0) + for i in range(r): + total += (A + i * B) ** 3 + return total - r * A ** 3 + + +def rhs(rows, weights, A: Q, B: Q) -> Q: + return sum(Q(w) * (u * A + v * B) ** 3 for (u, v), w in zip(rows, weights)) + + +def two_power(n: int) -> bool: + return n > 0 and n & (n - 1) == 0 + + +def dyadic(x: Q) -> bool: + return two_power(x.denominator) + + +def interpret(r: int, program, Y: Q, A: Q, B: Q): + y, a, b = Y, A, B + for _ in range(r): + y = y + a * a * a + a = a + b + for name, val in program: + k = Q(val) + if name == "a+=b": + a = a + k * b + elif name == "b+=a": + b = b + k * a + elif name == "y+=a^3": + y = y + k * a * a * a + elif name == "y+=b^3": + y = y + k * b * b * b + else: + stop("unknown event " + name) + return y, a, b + + +def program_repairs(r: int, program) -> bool: + for (A, B), Y in zip(POINTS, (Q(7), Q(-3, 5), Q(0), Q(11, 2), Q(-1), Q(4))): + A, B = Q(A), Q(B) + if interpret(r, program, Y, A, B) != (Y + r * A ** 3, A, B): + return False + return True + + +def in_alphabet(program, kind: str) -> bool: + for name, val in program: + k = Q(val) + if k == 0 or not dyadic(k): + return False + if kind != "general" and (name not in ("a+=b", "y+=a^3") + or (name == "a+=b" and k.denominator != 1)): + return False + return True + + +# ------------------------------------------------ independent enumeration + +def small_primes(limit: int) -> list[int]: + flags = [True] * (limit + 1) + flags[0] = flags[1] = False + for i in range(2, int(limit ** 0.5) + 1): + if flags[i]: + for j in range(i * i, limit + 1, i): + flags[j] = False + return [i for i, f in enumerate(flags) if f] + + +def cipolla(n: int, p: int): + n %= p + if n == 0: + return 0 + if pow(n, (p - 1) // 2, p) != 1: + return None + t = 0 + while pow((t * t - n) % p, (p - 1) // 2, p) != p - 1: + t += 1 + w = (t * t - n) % p + + def mul(x, y): + return ((x[0] * y[0] + x[1] * y[1] * w) % p, (x[0] * y[1] + x[1] * y[0]) % p) + + acc, base, e = (1, 0), (t, 1), (p + 1) // 2 + while e: + if e & 1: + acc = mul(acc, base) + base = mul(base, base) + e >>= 1 + if acc[0] * acc[0] % p != n: + stop("Cipolla root") + return acc[0] + + +def factor_by_trial(n: int, primes) -> dict[int, int]: + out: dict[int, int] = {} + for p in primes: + if p * p > n: + break + while n % p == 0: + out[p] = out.get(p, 0) + 1 + n //= p + if n > 1: + out[n] = out.get(n, 0) + 1 + return out + + +SQUARE_MASKS = {m: {i * i % m for i in range(m)} for m in (64, 63, 65, 11)} + + +def exact_sqrt(n: int): + if n < 0: + return None + for m, ok in SQUARE_MASKS.items(): + if n % m not in ok: + return None + s = math.isqrt(n) + return s if s * s == n else None + + +def good_triple(r: int, nodes) -> bool: + S, n = r * (r - 1) // 2, 2 * r - 1 + if len(set(nodes)) < 3: + return False + c0, c1, c2 = nodes + if 3 * (c0 * c1 + c0 * c2 + c1 * c2) != n * (c0 + c1 + c2) - 3 * S: + return False + for j in range(3): + k, l = nodes[(j + 1) % 3], nodes[(j + 2) % 3] + w = Q(S * (n - 3 * (k + l)), 3 * (nodes[j] - k) * (nodes[j] - l)) + if w == 0 or not dyadic(w): + return False + return True + + +def classify(r: int, primes) -> list[tuple]: + """Integer node triples at odd S. x = smaller gap from the odd-parity + node (|x| < 2S), y = larger gap; y | odd part of S*N(x), N = 3x^2 - M.""" + S, n = r * (r - 1) // 2, 2 * r - 1 + M = 2 * r * r - 2 * r - 1 + fS = factor_by_trial(S, primes) + xs = list(range(1, 2 * S, 2)) + val = [abs(3 * x * x - M) for x in xs] + fac = [dict() for _ in xs] + lim = math.isqrt(max(val)) + 1 + for p in primes: + if p > lim: + break + if p == 2 or (p == 3 and M % 3): + continue + if p == 3: + hits = range(len(xs)) + else: + root = cipolla(M * pow(3, p - 2, p), p) + if root is None: + continue + hits = [] + for t in sorted({root, (p - root) % p}): + first = t if t % 2 else t + p + hits.extend(range((first - 1) // 2, len(xs), p)) + for i in hits: + while val[i] and val[i] % p == 0: + val[i] //= p + fac[i][p] = fac[i].get(p, 0) + 1 + found = set() + for i, xa in enumerate(xs): + while val[i] and val[i] % 2 == 0: + val[i] //= 2 + if val[i] > 1: + fac[i][val[i]] = fac[i].get(val[i], 0) + 1 + N = 3 * xa * xa - M + if N == 0: + if S % xa == 0: + stop(f"r={r}: unhandled family") + f = dict(fS) + for p, e in factor_by_trial(xa, primes).items(): + f[p] = f.get(p, 0) + e + else: + f = dict(fS) + for p, e in fac[i].items(): + f[p] = f.get(p, 0) + e + divisors = [1] + for p, e in f.items(): + if p != 2: + divisors = [d * p ** k for d in divisors for k in range(e + 1)] + for x in (xa, -xa): + for d in divisors: + if d < xa: + continue + for y in (d, -d): + if N == 0: + roots = [-x - 4 * y] + else: + s = exact_sqrt(4 * (x * x - x * y + y * y) - M) + if s is None: + continue + roots = [-2 * (x + y) + s, -2 * (x + y) - s] + for w0 in roots: + if (w0 + n) % 6 == 0: + c0 = (w0 + n) // 6 + t = (c0, c0 + x, c0 + y) + if good_triple(r, t): + found.add(tuple(sorted(t))) + return sorted(found) + + +def pell_like(limit: int) -> set[int]: + out = set() + for r in range(7, limit + 1): + m = math.isqrt((r * r - 1) // 3) + if r * r - 3 * m * m == 1: + out.add(r) + return out + + +def main() -> None: + data = json.loads((HERE / "CERTIFICATES.json").read_text(encoding="utf-8")) + prior = json.loads((TOP / "research/cubic-three-query-arities/CERTIFICATES.json") + .read_text(encoding="utf-8")) + certs = data["certificates"] + kinds: dict[str, list[int]] = {"three-shift": [], "four-shift": [], "general": []} + for c in certs: + r, rows = c["r"], [tuple(x) for x in c["rows"]] + ws = [Q(w) for w in c["weights"]] + for A, B in POINTS: + if lhs(r, Q(A), Q(B)) != rhs(rows, ws, Q(A), Q(B)): + stop(f"identity r={r} at {(A, B)}") + if any(w == 0 or not dyadic(w) for w in ws): + stop(f"weight ring r={r}") + if any(math.gcd(u, v) != 1 for u, v in rows): + stop(f"row not primitive r={r}") + if len({(Q(v, u) if u else "inf") for u, v in rows}) != len(rows): + stop(f"repeated direction r={r}") + if not in_alphabet(c["program"], c["kind"]): + stop(f"alphabet r={r}") + if not program_repairs(r, c["program"]): + stop(f"program r={r}") + q = sum(1 for e in c["program"] if e[0].startswith("y")) + if q != len(rows) or c["shears"] != len(c["program"]) - q: + stop(f"event counts r={r}") + if c["kind"] != "general" and any(u != 1 for u, _ in rows): + stop(f"non-monic row in integer-shift certificate r={r}") + kinds[c["kind"]].append(r) + print(f"INDEPENDENT PASS {len(certs)} certificates: six-point identities and " + "six-input program executions") + + primes = small_primes(70000) + odd = [r for r in range(3, data["r_max"] + 1) if (r * (r - 1)) % 4 == 2] + table = {r: classify(r, primes) for r in odd} + sol = [r for r in odd if table[r]] + rec = data["integer_shift_odd_s"] + if {int(k): [tuple(t) for t in v] for k, v in rec["three_query_node_sets"].items()} != \ + {r: table[r] for r in sol}: + stop("node-set table differs") + if rec["three_query_impossible"] != [r for r in odd if r not in sol]: + stop("impossible list differs") + if kinds["three-shift"] != sol or kinds["four-shift"] != rec["three_query_impossible"]: + stop("program coverage") + print(f"INDEPENDENT PASS classification: {len(sol)} of {len(odd)} odd-S arities admit " + f"three integer-shift queries; {sum(map(len, table.values()))} node sets") + + def pow2ish(r: int) -> bool: + return two_power(r) or two_power(r - 1) + + classes = {r for r in range(3, data["r_max"] + 1) + if r % 3 == 2 or r in (3, 4) or r % 9 in (0, 1) or pow2ish(r)} + known = classes | {c["r"] for c in prior["certificates"]} | {24} | pell_like(data["r_max"]) + if set(kinds["general"]) & known or len(kinds["general"]) != 20: + stop("general-frame novelty") + if not set(sol) <= known: + stop("a solvable integer-shift arity outside predecessor classes") + after = known | set(kinds["general"]) + open_odd = [r for r in rec["three_query_impossible"] if r not in after] + open_even = [r for r in range(3, data["r_max"] + 1) + if (r * (r - 1)) % 4 == 0 and r not in after] + if data["open_after_package"] != {"odd_s": open_odd, "even_s": open_even}: + stop("open lists") + print("INDEPENDENT PASS bookkeeping: 20 new arities; open lists agree") + + # Mutations that must be rejected. + g = next(c for c in certs if c["kind"] == "general" and c["r"] == 84) + rows, ws = [tuple(x) for x in g["rows"]], [Q(w) for w in g["weights"]] + if all(lhs(84, Q(A), Q(B)) == rhs(rows, ws[::-1], Q(A), Q(B)) for A, B in POINTS): + stop("permuted weights accepted") + prog = [list(e) for e in g["program"]] + k = next(i for i, e in enumerate(prog) if e[0] in ("a+=b", "b+=a")) + prog[k][1] = str(Q(prog[k][1]) + 1) + if program_repairs(84, prog): + stop("altered shear accepted") + prog = [list(e) for e in g["program"]] + j = next(i for i, e in enumerate(prog) if e[0] == "y+=b^3") if any( + e[0] == "y+=b^3" for e in prog) else next(i for i, e in enumerate(prog) if e[0] == "y+=a^3") + prog[j][0] = "y+=a^3" if prog[j][0] == "y+=b^3" else "y+=b^3" + if program_repairs(84, prog): + stop("query on the wrong source accepted") + if in_alphabet([["b+=a", "1"]], "four-shift") or in_alphabet([["a+=b", "1/2"]], "three-shift"): + stop("integer-shift alphabet too permissive") + if good_triple(15, (0, 1, 2)) or classify(7, primes) != [(0, 1, 5)]: + stop("triple test") + print("INDEPENDENT PASS 5 mutation controls rejected") + print("PASS_CUBIC_ODD_S_SHIFT_FLOOR_INDEPENDENT") + + +if __name__ == "__main__": + main() diff --git a/research/cubic-odd-s-shift-floor/verify.py b/research/cubic-odd-s-shift-floor/verify.py new file mode 100644 index 0000000000..3320d3dbf7 --- /dev/null +++ b/research/cubic-odd-s-shift-floor/verify.py @@ -0,0 +1,566 @@ +#!/usr/bin/env python3 +"""Primary verifier for research/cubic-odd-s-shift-floor. + +Standard library only; every check is exact rational or integer arithmetic. + +1. Authenticates the pinned predecessor bytes and the statements used here. +2. Recomputes, from scratch, every integer-shift three-query repair at the + 99 arities 3 <= r <= 200 with S = r(r-1)/2 odd (Theorem A of PROOF.md). + The search is finite because of Lemmas 2-5, and it is complete. +3. Checks every certificate in CERTIFICATES.json by exact coefficient + comparison, weight-ring and contract checks. +4. Executes every literal repair program symbolically (all r retained + children, then the appended events) and on dirty rational inputs. +5. Checks the arity bookkeeping against the predecessor classes. +6. Runs rejection controls that must fail. + +Explicit checks raise SystemExit, so they stay active under python -O. +Prepared by ahrazzle with substantial AI assistance. Apache-2.0. +""" + +from __future__ import annotations + +import hashlib +import json +import math +import pathlib +import random +import sys +from fractions import Fraction + +PKG = pathlib.Path(__file__).resolve().parent +ROOT = PKG.parents[1] +R_MAX = 200 + +PR6653_README = "research/cubic-three-query-arities/README.md" +PR6653_CERTS = "research/cubic-three-query-arities/CERTIFICATES.json" +PR6212_README = "research/dyadic-cubic-repair/README.md" +PR6212_PROOF = "research/dyadic-cubic-repair/PROOF.md" + +# Open (unmerged) predecessors, recorded by exact head; not executable inputs. +PR7475_R24 = 24 # ee81d7e993025b62983ac3def76991af1a58eb01 +PR7478_HEAD = "233d639b89bed930e4db22e509170dfb62bd1cd9" # Pell family r^2-3n^2=1 + + +def fail(msg: str) -> None: + print(f"FAIL: {msg}") + raise SystemExit(1) + + +def require(cond: bool, msg: str) -> None: + if not cond: + fail(msg) + + +# ---------------------------------------------------------------- sources + +def authenticate_sources(mutate: str | None = None) -> dict[str, bytes]: + """Return pinned input bytes after checking their SHA256 pins. + + `mutate` names one input whose in-memory bytes are altered, as a control. + """ + pins = json.loads((PKG / "SOURCES.json").read_text(encoding="utf-8")) + out: dict[str, bytes] = {} + for row in pins["files"]: + if row["usage"] != "input": + continue + data = (ROOT / row["path"]).read_bytes() + if row["path"] == mutate: + data = data + b" " + if hashlib.sha256(data).hexdigest() != row["sha256"]: + raise ValueError(f"pinned input changed: {row['path']}") + out[row["path"]] = data + return out + + +# ---------------------------------------------------------------- algebra + +def cube(u: Fraction, v: Fraction) -> tuple[Fraction, ...]: + """Coefficients of (uA + vB)^3 on A^3, A^2B, AB^2, B^3.""" + return (u ** 3, 3 * u * u * v, 3 * u * v * v, v ** 3) + + +def defect(r: int) -> tuple[Fraction, ...]: + """sum_{i tuple[Fraction, ...]: + acc = [Fraction(0)] * 4 + for u, v, q in terms: + for k, c in enumerate(cube(Fraction(u), Fraction(v))): + acc[k] += Fraction(q) * c + return tuple(acc) + + +def is_dyadic(x: Fraction) -> bool: + d = x.denominator + return d & (d - 1) == 0 + + +def dyadic_ratio(num: int, den: int) -> bool: + """num/den is a nonzero element of Z[1/2].""" + if num == 0 or den == 0: + return False + d = abs(den) // math.gcd(num, den) + return d & (d - 1) == 0 + + +def node_weights(r: int, c) -> list[Fraction]: + """Weights on (A + c_j B)^3 by exact elimination of the first three + coefficient equations (not by the closed formula).""" + S1 = Fraction(sum(range(r))) + S2 = Fraction(sum(i * i for i in range(r))) + m = [[Fraction(1)] * 3, [Fraction(x) for x in c], + [Fraction(x) ** 2 for x in c]] + rhs = [Fraction(0), S1, S2] + n = 3 + for col in range(n): + piv = next((i for i in range(col, n) if m[i][col] != 0), None) + require(piv is not None, "singular node system") + m[col], m[piv] = m[piv], m[col] + rhs[col], rhs[piv] = rhs[piv], rhs[col] + for i in range(n): + if i != col and m[i][col] != 0: + f = m[i][col] / m[col][col] + m[i] = [a - f * b for a, b in zip(m[i], m[col])] + rhs[i] -= f * rhs[col] + return [rhs[i] / m[i][i] for i in range(n)] + + +# ---------------------------------------------------------------- programs + +EVENTS = ("a+=b", "b+=a", "y+=a^3", "y+=b^3") + + +def run_symbolic(r: int, events) -> tuple[tuple, tuple, tuple]: + """Execute r retained children and the appended events on formal + arbitrary sources. Registers are linear forms in (A, B); the output + change is a cubic form. Returns (output change, a, b).""" + a = (Fraction(1), Fraction(0)) + b = (Fraction(0), Fraction(1)) + dy = [Fraction(0)] * 4 + + def add_cube(w: Fraction, f) -> None: + for k, c in enumerate(cube(f[0], f[1])): + dy[k] += w * c + + for _ in range(r): + add_cube(Fraction(1), a) + a = (a[0] + b[0], a[1] + b[1]) + for kind, val in events: + x = Fraction(val) + if kind == "a+=b": + a = (a[0] + x * b[0], a[1] + x * b[1]) + elif kind == "b+=a": + b = (b[0] + x * a[0], b[1] + x * a[1]) + elif kind == "y+=a^3": + add_cube(x, a) + elif kind == "y+=b^3": + add_cube(x, b) + else: + fail(f"unknown event {kind}") + return tuple(dy), a, b + + +def run_literal(r: int, events, y: Fraction, a: Fraction, b: Fraction): + for _ in range(r): + y += a ** 3 + a += b + for kind, val in events: + x = Fraction(val) + if kind == "a+=b": + a += x * b + elif kind == "b+=a": + b += x * a + elif kind == "y+=a^3": + y += x * a ** 3 + elif kind == "y+=b^3": + y += x * b ** 3 + return y, a, b + + +def program_ok(r: int, events, rng: random.Random) -> bool: + dy, a, b = run_symbolic(r, events) + if dy != (Fraction(r), 0, 0, 0) or a != (1, 0) or b != (0, 1): + return False + for _ in range(3): + Y, A, B = (Fraction(rng.randint(-10 ** 6, 10 ** 6), rng.randint(1, 999)) + for _ in range(3)) + if run_literal(r, events, Y, A, B) != (Y + r * A ** 3, A, B): + return False + return True + + +def contract_ok(events, alphabet: str) -> bool: + """integer-shift: only a += k*b (k in Z) and y += q*a^3 (q dyadic). + general-frame: determinant-one shears with dyadic k and dyadic queries + on either named source.""" + for kind, val in events: + x = Fraction(val) + if kind not in EVENTS or not is_dyadic(x) or x == 0: + return False + if alphabet == "integer-shift": + if kind in ("b+=a", "y+=b^3"): + return False + if kind == "a+=b" and x.denominator != 1: + return False + return True + + +def query_count(events) -> int: + return sum(1 for k, _ in events if k.startswith("y+=")) + + +def shear_count(events) -> int: + return sum(1 for k, _ in events if not k.startswith("y+=")) + + +# ------------------------------------------------- complete classification + +def primes_upto(n: int) -> list[int]: + sieve = bytearray([1]) * (n + 1) + sieve[0:2] = b"\x00\x00" + for i in range(2, math.isqrt(n) + 1): + if sieve[i]: + sieve[i * i::i] = bytearray(len(range(i * i, n + 1, i))) + return [i for i in range(n + 1) if sieve[i]] + + +def sqrt_mod(n: int, p: int) -> int | None: + """A square root of n modulo the odd prime p (Tonelli-Shanks).""" + n %= p + if n == 0: + return 0 + if pow(n, (p - 1) // 2, p) != 1: + return None + if p % 4 == 3: + return pow(n, (p + 1) // 4, p) + q, s = p - 1, 0 + while q % 2 == 0: + q //= 2 + s += 1 + z = 2 + while pow(z, (p - 1) // 2, p) != p - 1: + z += 1 + m, c, t, root = s, pow(z, q, p), pow(n, q, p), pow(n, (q + 1) // 2, p) + while t != 1: + i, t2 = 0, t + while t2 != 1: + t2 = t2 * t2 % p + i += 1 + bb = pow(c, 1 << (m - i - 1), p) + m, c, t, root = i, bb * bb % p, t * bb * bb % p, root * bb % p + require(root * root % p == n, "modular square root") + return root + + +def triple_ok(r: int, c) -> bool: + """Distinct integer nodes satisfying the node equation with nonzero + dyadic weights; weights from the closed formula of PROOF.md Lemma 1.""" + S, a = r * (r - 1) // 2, 2 * r - 1 + if len(set(c)) != 3: + return False + e1 = c[0] + c[1] + c[2] + e2 = c[0] * c[1] + c[0] * c[2] + c[1] * c[2] + if 3 * e2 != a * e1 - 3 * S: + return False + for j in range(3): + k, l = (j + 1) % 3, (j + 2) % 3 + if not dyadic_ratio(S * (a - 3 * (c[k] + c[l])), + 3 * (c[j] - c[k]) * (c[j] - c[l])): + return False + return True + + +def integer_shift_triples(r: int, primes: list[int]) -> list[tuple[int, int, int]]: + """All integer node triples giving a three-query dyadic repair at r. + + Complete when S is odd (PROOF.md Lemmas 2-5): exactly one node c0 has + the other parity; with x = c1-c0 the smaller gap, x is odd, |x| < 2S, + and d = w0 + 3x divides N = 3x^2 - M, where w0 = 6c0 - (2r-1), + M = 2r^2 - 2r - 1 and (w0+3x)(w0+x+4y) = N. + """ + S, a = r * (r - 1) // 2, 2 * r - 1 + M = 4 * S - 1 + n = S # x = 2i+1 for 0 <= i < S + Ns = [3 * (2 * i + 1) ** 2 - M for i in range(n)] + rem = [abs(v) for v in Ns] + fac: list[dict[int, int]] = [dict() for _ in range(n)] + for i in range(n): + if rem[i] == 0: + continue + for p in (2, 3): + e = 0 + while rem[i] % p == 0: + rem[i] //= p + e += 1 + if e: + fac[i][p] = e + top = math.isqrt(max(rem)) + 1 + for p in primes: + if p > top: + break + if p < 5: + continue + t = sqrt_mod(M * pow(3, -1, p), p) + if t is None: + continue + for root in {t, (-t) % p}: + x0 = root if root % 2 else root + p # odd x, x = root mod p + for i in range((x0 - 1) // 2, n, p): + if rem[i] == 0: + continue + e = 0 + while rem[i] % p == 0: + rem[i] //= p + e += 1 + if e: + fac[i][p] = e + found: set[tuple[int, int, int]] = set() + for i in range(n): + xa = 2 * i + 1 + N = Ns[i] + if N == 0: + # (w0+3x)(w0+x+4y) = 0. Branch w0 = -3x gives q0 = -S/x. + require(S % xa != 0, f"r={r}: unhandled infinite family") + # Branch w0 = -x-4y: q0 integral forces y | S*x (y odd). + m = S * xa + divs = [dv for dv in range(1, math.isqrt(m) + 1) if m % dv == 0] + divs = sorted(set(divs + [m // dv for dv in divs])) + for x in (xa, -xa): + for dv in divs: + for y in (dv, -dv): + w0 = -x - 4 * y + if (w0 + a) % 6 == 0: + c0 = (w0 + a) // 6 + c = (c0, c0 + x, c0 + y) + if triple_ok(r, c): + found.add(tuple(sorted(c))) + continue + if rem[i] > 1: + fac[i][rem[i]] = fac[i].get(rem[i], 0) + 1 + prod = 1 + for p, e in fac[i].items(): + prod *= p ** e + require(prod == abs(N), "factorization") + odd = [1] + for p, e in fac[i].items(): + if p != 2: + odd = [o * p ** k for o in odd for k in range(e + 1)] + v2 = fac[i].get(2, 0) + # w0 and x are odd, so d = w0+3x and N/d = w0+x+4y are both even. + ds = [s * (1 << j) * o for j in range(1, v2) for o in odd for s in (1, -1)] + for x in (xa, -xa): + for d in ds: + w0 = d - 3 * x + if (w0 + a) % 6: + continue + y4 = N // d - d + 2 * x + if y4 % 4: + continue + y = y4 // 4 + c0 = (w0 + a) // 6 + c = (c0, c0 + x, c0 + y) + if y not in (0, x): + e1 = sum(c) + e2 = c[0] * c[1] + c[0] * c[2] + c[1] * c[2] + require(3 * e2 == a * e1 - 3 * S, "divisor parametrization") + if triple_ok(r, c): + found.add(tuple(sorted(c))) + return sorted(found) + + +def two_query_integer_shift(r: int) -> bool: + """Two distinct integer nodes need (c-c')^2 = M/3 and weight S/(c-c') + dyadic (PROOF.md Lemma 1, two-node case).""" + S, M = r * (r - 1) // 2, 2 * r * r - 2 * r - 1 + if M % 3: + return False + x = math.isqrt(M // 3) + return x * x == M // 3 and dyadic_ratio(S, x) + + +# -------------------------------------------------------------- bookkeeping + +def is_power_of_two(x: int) -> bool: + return x >= 1 and x & (x - 1) == 0 + + +def covered_6653(r: int) -> bool: + """The prior classes tabulated in PR6653 (PR6212, PR6215, PR6246, PR6250).""" + return (r % 3 == 2 or r in (3, 4) or r % 9 in (0, 1) + or is_power_of_two(r) or is_power_of_two(r - 1)) + + +def pell_arities(limit: int) -> set[int]: + """PR7478: equal-weight repairs exist exactly at r^2 - 3n^2 = 1, r >= 7.""" + out, (r, n) = set(), (2, 1) + while r <= limit: + if r >= 7: + out.add(r) + r, n = 2 * r + 3 * n, r + 2 * n + return out + + +# --------------------------------------------------------------------- main + +def main() -> None: + rng = random.Random(20261113) + src = authenticate_sources() + r6653 = src[PR6653_README].decode("utf-8") + c6653 = json.loads(src[PR6653_CERTS].decode("utf-8")) + r6212 = src[PR6212_README].decode("utf-8") + p6212 = src[PR6212_PROOF].decode("utf-8") + require("Every certificate uses only the PR6212 alphabet: integer shears" in r6653, + "PR6653 alphabet anchor") + require("`v_j = 6c_j - (2r-1)`" in r6653, "PR6653 open-question substitution anchor") + require("two queries suffice **only for r=2**" in r6212, "PR6212 two-query anchor") + require("## Four integer queries for every r" in p6212, "PR6212 four-query anchor") + unc = [r for r in range(3, 161) if not covered_6653(r)] + require(c6653["uncovered_arities"] == unc, "PR6653 uncovered list") + p6653 = {c["r"]: c["directions"] for c in c6653["certificates"]} + for control in (PR6653_CERTS, PR6212_README): + try: + authenticate_sources(mutate=control) + except ValueError: + continue + fail(f"mutated pinned input accepted: {control}") + print("PASS sources: 4 pinned inputs, 4 anchors, PR6653 uncovered list, 2 byte mutations rejected") + + data = json.loads((PKG / "CERTIFICATES.json").read_text(encoding="utf-8")) + require(data["r_max"] == R_MAX, "r_max") + + # ---- Theorem A: complete integer-shift classification at odd S. + primes = primes_upto(70000) + odd_s = [r for r in range(3, R_MAX + 1) if (r * (r - 1) // 2) % 2] + require(len(odd_s) == 99, "99 odd-S arities") + table = {r: integer_shift_triples(r, primes) for r in odd_s} + solvable = [r for r in odd_s if table[r]] + impossible = [r for r in odd_s if not table[r]] + rec = data["integer_shift_odd_s"] + require(rec["arities"] == odd_s, "recorded odd-S arities") + require({int(k): [tuple(t) for t in v] for k, v in rec["three_query_node_sets"].items()} + == {r: table[r] for r in solvable}, "recorded complete node-set table") + require(rec["three_query_impossible"] == impossible, "recorded impossible list") + require(len(solvable) == 17 and len(impossible) == 82, "17 / 82 split") + require(all(not two_query_integer_shift(r) for r in odd_s), "no two-query integer-shift repair") + for r in (15, 22, 30, 31): + require(r in impossible, f"r={r} impossible") + for r in (6, 7, 42, 51, 114): + require(tuple(sorted(p6653[r])) in table[r], f"PR6653 certificate at r={r} recovered") + require(all(covered_6653(r) or r in p6653 for r in solvable), + "every solvable odd-S arity lies in a predecessor class") + nsets = sum(len(v) for v in table.values()) + print(f"PASS Theorem A: 99 odd-S arities, {nsets} node sets at 17 arities, 82 need four queries") + + # ---- certificates and programs + seen = {"three-shift": [], "four-shift": [], "general": []} + for cert in data["certificates"]: + r, kind = cert["r"], cert["kind"] + terms = [(row[0], row[1], Fraction(q)) for row, q in zip(cert["rows"], cert["weights"])] + require(form_sum(terms) == defect(r), f"{kind} identity r={r}") + require(all(q != 0 and is_dyadic(q) for _, _, q in terms), f"weights r={r}") + require(all(math.gcd(u, v) == 1 for u, v, _ in terms), f"primitive rows r={r}") + require(len({Fraction(v, u) if u else None for u, v, _ in terms}) == len(terms), + f"distinct directions r={r}") + ev = [tuple(e) for e in cert["program"]] + alphabet = "general-frame" if kind == "general" else "integer-shift" + require(contract_ok(ev, alphabet), f"contract r={r}") + require(query_count(ev) == len(terms), f"query count r={r}") + require(shear_count(ev) == cert["shears"], f"shear count r={r}") + require(program_ok(r, ev, rng), f"program r={r}") + if kind != "general": + require(all(u == 1 for u, _, _ in terms), f"monic rows r={r}") + c = [v for _, v, _ in terms] + w = node_weights(r, c) if len(c) == 3 else None + if w is not None: + require(w == [q for _, _, q in terms], f"eliminated weights r={r}") + if kind == "three-shift": + require(tuple(sorted(v for _, v, _ in terms)) in table[r], f"node set r={r}") + require(len(terms) == 3, "three queries") + seen["three-shift"].append(r) + elif kind == "four-shift": + require(len(terms) == 4, "four queries") + seen["four-shift"].append(r) + else: + require(len(terms) == 3, "three queries") + seen["general"].append(r) + require(seen["three-shift"] == solvable, "one three-query program per solvable arity") + require(seen["four-shift"] == impossible, "one four-query program per impossible arity") + new20 = seen["general"] + require(len(new20) == 20 and len(set(new20)) == 20, "twenty general-frame arities") + nonunit2 = [c["r"] for c in data["certificates"] + if c["kind"] == "general" and sum(row[0] != 1 for row in c["rows"]) >= 2] + print(f"PASS certificates: {len(solvable)} three-query and {len(impossible)} four-query " + f"integer-shift programs, 20 general-frame programs (two non-monic rows at {nonunit2})") + + # ---- bookkeeping against predecessors + pell = pell_arities(R_MAX) + known = {r for r in range(3, R_MAX + 1) + if covered_6653(r) or r in p6653 or r == PR7475_R24 or r in pell} + require(not (set(new20) & known), "a general-frame arity was already covered") + require(all(r % 4 in (0, 1) for r in new20), "general-frame arities have even S") + after = known | set(new20) + open_odd = [r for r in impossible if r not in after] + open_even = [r for r in range(3, R_MAX + 1) + if (r * (r - 1) // 2) % 2 == 0 and r not in after] + require(len(open_odd) == 38 and len([r for r in impossible if r in known]) == 44, + "44 of the 82 have predecessor three-query repairs in G; 38 are open") + require(data["open_after_package"]["odd_s"] == open_odd, "recorded open odd-S list") + require(data["open_after_package"]["even_s"] == open_even, "recorded open even-S list") + print(f"PASS bookkeeping: 20 new arities outside PR6653 classes/certificates, PR7475 and " + f"PR7478; still open r<=200: {len(open_odd)} odd-S, even-S {open_even}") + + # ---- rejection controls (each must fail) + controls = 0 + gen = next(c for c in data["certificates"] if c["kind"] == "general") + r0 = gen["r"] + bad = [(row[0], row[1], Fraction(q)) for row, q in zip(gen["rows"], gen["weights"])] + bad[0] = (bad[0][0], bad[0][1], bad[0][2] + Fraction(1, 1024)) + require(form_sum(bad) != defect(r0), "control: perturbed weight accepted") + controls += 1 + terms = [(row[0], row[1], Fraction(q)) for row, q in zip(gen["rows"], gen["weights"])] + require(form_sum(terms) != defect(r0 + 1), "control: wrong arity accepted") + controls += 1 + ev = [tuple(e) for e in gen["program"]] + last = max(i for i, e in enumerate(ev) if not e[0].startswith("y+=")) + require(not program_ok(r0, ev[:last] + ev[last + 1:], rng), "control: missing restore accepted") + controls += 1 + q1 = next(i for i, e in enumerate(ev) if e[0].startswith("y+=") and i > 0 + and not ev[i - 1][0].startswith("y+=")) + swapped = ev[:q1 - 1] + [ev[q1], ev[q1 - 1]] + ev[q1 + 1:] + require(not program_ok(r0, swapped, rng), "control: query moved before its shear accepted") + controls += 1 + drop = [e for i, e in enumerate(ev) if i != next(j for j, f in enumerate(ev) if f[0].startswith("y+="))] + require(not program_ok(r0, drop, rng), "control: omitted query accepted") + controls += 1 + require(not contract_ok(ev, "integer-shift") or all(row[0] == 1 for row in gen["rows"]), + "control: general frame passed as integer shift") + controls += 1 + three = next(c for c in data["certificates"] if c["kind"] == "three-shift" and c["r"] == 6) + c = [v for _, v in three["rows"]] + require(not triple_ok(6, (c[0], c[1], c[2] + 1)), "control: shifted node accepted") + controls += 1 + # The search is complete only for odd S: at r=12 (S=66) PR6653's + # same-parity certificate (-21,-5,11) has no odd-one-out node. + require(triple_ok(12, tuple(p6653[12])), "PR6653 r=12 certificate") + require(tuple(sorted(p6653[12])) not in integer_shift_triples(12, primes), + "control: odd-S search reached a same-parity triple") + controls += 1 + four = next(c for c in data["certificates"] if c["kind"] == "four-shift") + rows = [list(x) for x in four["rows"]] + rows[1][1] += 1 + w4 = [Fraction(q) for q in four["weights"]] + require(form_sum([(u, v, q) for (u, v), q in zip(rows, w4)]) != defect(four["r"]), + "control: moved four-query node accepted") + controls += 1 + print(f"PASS controls: {controls} rejection controls failed as required") + print("PASS_CUBIC_ODD_S_SHIFT_FLOOR") + + +if __name__ == "__main__": + main()