diff --git a/research/thin-query-shear-floor/README.md b/research/thin-query-shear-floor/README.md new file mode 100644 index 0000000000..590d36e4ba --- /dev/null +++ b/research/thin-query-shear-floor/README.md @@ -0,0 +1,98 @@ +# The p16 query-only shears cannot be absorbed by their neighbours + +**Negative result, no new κ.** [#4440](../query-thinned-controllers/README.md) +replaced selected full native calls by copied rank-one query shears, and +[#4470](../joint-helper-lattice/README.md)'s p16 complex controller keeps 15 of +them. The retained BIT controller has the same 15. Each costs one rank-one job +per port: 1,680 complex and 1,665 BIT paid jobs, about 0.7% of each paid moment. +Because the surplus is thin, the companion package +`research/productive-lever-reprice` (separate PR) finds that free +shears on both sides would give a raw ceiling near 0.0099. #4440 lists "a +changed local query/native alphabet" as its next improvement question. This +package closes three natural ways to remove the shears, in the replay model of +`query-thinned-controllers/controller.py`. + +## The thin block + +At thin stage `2j` the word bridges pair `j−1` with pair `j`, applies the +forward shear `Y_{j−1} += Q^{-1} X_{j−1}`, and unbridges. Its net effect is + + Y_{j−1} += Q^{-1}(X_{j−1} + X_j), Y_j += Q^{-1}(X_{j−1} + X_j), + +one rank-one query per port that feeds two pairs. Both neighbouring full calls, +at stages `2j−1` and `2j+1`, are backward (`X += −Q Y`) on pairs `j−1` and `j`. + +## 1. Fusion with a neighbouring full call needs two queries + +For all 15 thin stages on each side, the verifier composes the bridged block +with the previous and with the next full call, exactly as the replay does. + +- Complex: every composite has nonzero `Q^1` and `Q^{-1}` coefficient matrices. +- BIT (`Q^{-1} = Q`): every composite has a Q-coefficient matrix of rank 2 over + GF(2)(D), shown by a nonzero 2×2 minor. + +A full call `D_s S(Q^{±1})` has Laurent support `{Q^0, Q^{±1}}` and +Q-coefficient rank 1 (checked as a control). So a fused call would need two +independent query results per port, and re-framing helper boundaries cannot +absorb the shear. + +## 2. Lazy central frames give nothing + +Exactly, + + S_x(−Q) S_y(Q^{-1}) = signed_swap · diag(Q^{-1}, Q) · S_x(Q), + +so a thin query can be traded for a change of central frame on fields. Model a +field as `Q^a · logical`, with `a` in Z/2. For BIT `Q^2 = I`; for complex `Q^2` +is a Pauli phase and is treated as free, which only favours the trade. The costs +are as follows: flipping a field costs 1; an ADD across different parities costs +1 (it becomes a Q-shear); a query between different parities is free (it becomes +a Pauli shear), and between equal parities it costs 1; a full call needs equal +parities. All fields start and end at parity 0. + +**Floor.** Each thin query on pair `k` lies in a window that starts at the full +call on the same pair `k` and contains only ADD and IDLE events. At the full call +the two fields agree, ADD and IDLE never change a parity, so either the query is +paid or a flip inside the window is paid. The 15 windows are disjoint (checked on +both controllers), so the cost is at least 15. The present controller attains +15, so the optimum is 15 on both sides. An inserted SWAP breaks the window +property, as a control. A CP-SAT run over the whole word in the same model found +the same optimum; it was discovery only and is not used. + +## 3. A two-query native word gains nothing in gather-type schemes + +The query on port `p` is a rank-one recursive query along that port's line +`q_p`. All lines are distinct: 112 nonzero 9-bit lines in complex +(`DATA-PHASES.json`) and 111 E8-root lines up to sign in BIT (`WORD.json.gz`). In +schemes built from linear maps, rank-one queries and free scalars and routes, +one query serves one line, so a second independent query costs one rank-one job +per port. Riding on a query the native word already makes returns `Q(f+u)`, and +linearity cannot split `Qf` from `Qu` without another query. The directions +also differ, since the native result goes to `X` and the shear's to `Y`. +Changing the shape does not help either: merging a stage's 112 rank-one jobs +into 14 rank-eight jobs saves less than one unit of moment at κ = 0.00302015 +(`RESULT.json`). A native word implementing the fused block therefore costs at +least the old word plus 112 rank-one jobs per stage, which is the present bill. + +**Scope.** Parts 1 and 2 are exact in the stated models. Part 3 is a bound for +gather-type schemes only. It is not a proof for every circuit, for example one +that recodes addresses so that different lines meet. The remaining route is a +redesigned local family whose ports share query lines, which is the same opening +recorded for the H branch in #4580. + +## Open next questions + +- Is there a redesigned local family whose ports share query lines `q`, so that + one query serves several ports? That is the only opening left by part 3, and + the same one the H branch leaves (#4580). No candidate is known. +- Part 3 is scoped to gather-type schemes; a general lower bound for the fused + block (any circuit, including address recoding) is open. + +## Reproduce + +```sh +python3.12 -B scripts/research_package.py --package research/thin-query-shear-floor +``` + +Standard library only; under one second. Prepared by Matarener (Mark) with +Claude Code assistance. Apache-2.0. diff --git a/research/thin-query-shear-floor/RESULT.json b/research/thin-query-shear-floor/RESULT.json new file mode 100644 index 0000000000..a6fb42506c --- /dev/null +++ b/research/thin-query-shear-floor/RESULT.json @@ -0,0 +1,487 @@ +{ + "bit": { + "fusion": [ + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 5 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 5 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 12 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 12 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 19 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 19 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 26 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 26 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 33 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 33 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 40 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 40 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 47 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 47 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 53 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 53 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 59 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 59 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 65 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 65 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 71 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 71 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 77 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 77 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 83 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 83 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 89 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 89 + }, + { + "fused_with": "previous", + "rank_Q_mod2": 2, + "thin_event": 95 + }, + { + "fused_with": "next", + "rank_Q_mod2": 2, + "thin_event": 95 + } + ], + "fusion_blocks_checked": 30, + "parity_floor": { + "attained": 15, + "lower_bound": 15, + "thin_queries": 15, + "windows": [ + [ + 1, + 5 + ], + [ + 8, + 12 + ], + [ + 15, + 19 + ], + [ + 22, + 26 + ], + [ + 29, + 33 + ], + [ + 36, + 40 + ], + [ + 43, + 47 + ], + [ + 50, + 53 + ], + [ + 56, + 59 + ], + [ + 62, + 65 + ], + [ + 68, + 71 + ], + [ + 74, + 77 + ], + [ + 80, + 83 + ], + [ + 86, + 89 + ], + [ + 92, + 95 + ] + ] + } + }, + "complex": { + "fusion": [ + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 5 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 5 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 12 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 12 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 19 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 19 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 26 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 26 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 33 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 33 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 40 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 40 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 47 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 47 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 53 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 53 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 59 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 59 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 65 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 65 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 71 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 71 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 77 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 77 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 83 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 83 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 89 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 89 + }, + { + "fused_with": "previous", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 95 + }, + { + "fused_with": "next", + "rank_Q": 1, + "rank_Q_inverse": 1, + "thin_event": 95 + } + ], + "fusion_blocks_checked": 30, + "parity_floor": { + "attained": 15, + "lower_bound": 15, + "thin_queries": 15, + "windows": [ + [ + 1, + 5 + ], + [ + 8, + 12 + ], + [ + 15, + 19 + ], + [ + 22, + 26 + ], + [ + 29, + 33 + ], + [ + 36, + 40 + ], + [ + 43, + 47 + ], + [ + 50, + 53 + ], + [ + 56, + 59 + ], + [ + 62, + 65 + ], + [ + 68, + 71 + ], + [ + 74, + 77 + ], + [ + 80, + 83 + ], + [ + 86, + 89 + ], + [ + 92, + 95 + ] + ] + } + }, + "new_kappa": false, + "query_lines": { + "bit_distinct_lines": 111, + "complex_distinct_q": 112 + }, + "rank_merge_saving_at_0.00302015": [ + "0.701181", + "0.701181" + ], + "schema": "thin-query-shear-floor/1", + "status": "PASS_THIN_QUERY_SHEAR_FLOOR" +} diff --git a/research/thin-query-shear-floor/SOURCES.json b/research/thin-query-shear-floor/SOURCES.json new file mode 100644 index 0000000000..faa2d9f3c1 --- /dev/null +++ b/research/thin-query-shear-floor/SOURCES.json @@ -0,0 +1,54 @@ +{ + "schema_version": 1, + "base_commit": "f626db5c3a3d781d8f7695038776c621651f75e1", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "ed33caef5c5827693e9572d252a66f99cbb73d40", + "sha256": "5732707cc1e460b090b53f2463162749ad860de878a18f7408938671d295a9d9" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "64bfc5af6709ed9811171e0a2108f05e1219cb65", + "sha256": "352a6184713b8843d96fd2c2071eb7aeaa655906b7c51d45ad444912666c8a96" + }, + { + "path": "research/joint-helper-lattice/CONTROLLER.json", + "usage": "input", + "git_blob": "49a2f0675819f9deeea27ed77be2c2b6ff2e87e5", + "sha256": "1f5d6aa267e4e66048818714b5d3b5eae17a58abe91d15deeaa34574f7391a5f" + }, + { + "path": "research/kappa-0023-productive-jobs/dependencies/kappa-next-regime/direct-decoder/sources/DATA-PHASES.json", + "usage": "input", + "git_blob": "d9a4f84211182ca200c081ea061d724c8a2cfb70", + "sha256": "c5916ff312678f12aba403847643fbbc29f643acec60bdf836fa56cd3e8251fa" + }, + { + "path": "research/kappa-rebuild/architecture/mixed_target_probe.py", + "usage": "input", + "git_blob": "4fc05ab08138218ba9f09e5c89b649afae7c914e", + "sha256": "011c3c9d0cf81103dc84d709a0e36793eb7c5ae3f23c85eac27650ef13afa04a" + }, + { + "path": "research/kappa-rebuild/bit/sources/pr589-regenerated/WORD.json.gz", + "usage": "input", + "git_blob": "85a4499bf9e4911a705d50567a2c2ef6cf23739a", + "sha256": "e3e301e62bc2b41dbf1ceac0acf3d35824ebeab1848c5a2142d4577b109da52f" + }, + { + "path": "research/query-thinned-controllers/BIT-CONTROLLER.json", + "usage": "input", + "git_blob": "89c400d5970024b3debe870c36ce43889beed001", + "sha256": "39ac84fb848b908f7ba051fae4556d507900c421dc5d23501a9c0cb1d61fd08d" + }, + { + "path": "research/query-thinned-controllers/controller.py", + "usage": "input", + "git_blob": "d4557e08cfb9fe57cc1ae4024705a72dc95f3583", + "sha256": "8b462d660487b1be4940357c4c7522967b1bfaede3c02b1c66109b85acae0fd2" + } + ] +} diff --git a/research/thin-query-shear-floor/TASK.json b/research/thin-query-shear-floor/TASK.json new file mode 100644 index 0000000000..4a8355e093 --- /dev/null +++ b/research/thin-query-shear-floor/TASK.json @@ -0,0 +1,72 @@ +{ + "schema_version": 1, + "task_id": "complex-new-helper-inventory", + "priority_revision": 7, + "base_commit": "f626db5c3a3d781d8f7695038776c621651f75e1", + "original_card": { + "id": "complex-new-helper-inventory", + "question": "Can a new local cost interface change the deficit-to-recursive-cost ratio beyond current packing?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/complex-local-word-ceiling/README.md", + "research/heterogeneous-owner-assembly/README.md", + "certificates/selected-result.json", + "research/selected-k8-unrestricted-ends/README.md" + ], + "methods": [ + "Propose a changed helper inventory and derive an optimistic exact moment.", + "Design a small completed instance and independently verify its endpoint and rank bill." + ], + "acceptance_gate": "A new physically realizable contract outside the frozen catalogue whose per-call profile, screened with ceiling.ceiling(), beats the selected word's packing ceiling; a lower cap does not establish identical circuitry or order attainable optima, and is insufficient to pass the stronger-budget target under this model. A scoped local result may be retained without a complete supplier. Expanding it into further construction rounds requires the family-level budget and obligation gate in research-family-status.md; an optimistic passing relaxation alone is not acceptance.", + "first_step": { + "command": [ + "python3", + "-B", + "research/complex-local-word-ceiling/verify.py" + ], + "expected": "PASS_COMPLEX_LOCAL_WORD_CEILING", + "inspect": "Read the selected word's per-call local profile, its packing ceiling and the lever table; run levers.py for the ideal budget of the lever you target.", + "scope": "Positive control and planning budget only; this is not a new construction or full cold replay." + }, + "first_experiment": "Before any synthesis, write the candidate per-call local profile (and centre charge / unpaid coordinates if changed) and screen it with ceiling.ceiling(); reject it if even the ideal ceiling does not beat the selected word's by your stated margin.", + "bottleneck_link": "Packing of the selected word is capped at +0.87% (ceiling model); only a lower local excess spend or a changed coverage law raises the cap.", + "allowed_variations": [ + "Narrow to one changed boundary or helper type with explicit counts.", + "If the coverage law, template or guard changes, derive an applicable fully charged replacement bound instead of applying the incumbent ceiling outside its scope." + ], + "scope_change_triggers": [ + "Mixing only providers already inside the pinned catalogue.", + "Only changing helper terminal subspaces and monotone frames within the fixed scalar word, entrances and cleanup contract already covered by #1995/#2013.", + "Continuing a partial cost improvement while leaving the same unpriced consumer, restoration or central-readout obligation unresolved; refresh the family expansion decision first. Local product-retiming evidence has a narrow scope and is not a ban on changed graphs or contracts." + ], + "overlap_terms": [ + "helper inventory", + "heterogeneous-owner", + "mutable leaver" + ] + }, + "scope_status": "changed", + "actual_scope": "Check whether the 15 query-only shears of the p16 controllers (#4470 complex, retained BIT) can be removed by fusion with neighbouring full calls, by lazy central-Gaussian frames, or by a two-query native word.", + "scope_change_reason": "The card asks for a new local cost interface; this package tests the query-shear interface change that #4440 lists as its next improvement question and records three scoped closures. It constructs no new interface.", + "bottleneck_link": "Query shears are 0.7% of each paid moment but, with the thin surplus, free shears on both sides would raise the raw ceiling to about 0.0099; this package shows the three direct routes to that do not work.", + "budget_minutes": 120, + "stop_rule": "Stop after the fusion algebra, the parity floor and the scoped two-query bound; no new native word or controller is built.", + "outcome": "negative-result", + "evidence": "RESULT.json: 30 fusion blocks per side (each needs Q and Q^-1 in complex, Q-coefficient rank 2 in BIT), parity floor 15 attained with disjoint windows on both controllers, 112/111 distinct query lines, merge saving under one unit. README.md gives the arguments and their scope.", + "author": "Matarener (Mark), with Claude Code assistance", + "ai_assistance": "Substantial Claude Code assistance in analysis, code and writing; standard-library exact arithmetic; a CP-SAT run was discovery only; no independent human review.", + "open_questions": [ + { + "question": "Is there a redesigned local family whose ports share query lines q?", + "why_it_matters": "It is the only route left open by the gather-type bound, here and for the H branch (#4580).", + "first_step": "Search port codes of the native supplier for coincident q lines before any construction.", + "blocked_by": "All 112 complex and 111 BIT lines are distinct in the current suppliers." + }, + { + "question": "Is there a general (non-gather) lower bound for the fused two-query block?", + "why_it_matters": "Part 3 does not cover address recodings that make lines meet.", + "first_step": "State the circuit model and try the rank-of-Q-coefficient argument over recoded addresses.", + "blocked_by": "No formal model of recoded query lines in the repository." + } + ] +} diff --git a/research/thin-query-shear-floor/VERIFY.json b/research/thin-query-shear-floor/VERIFY.json new file mode 100644 index 0000000000..4c4df43a79 --- /dev/null +++ b/research/thin-query-shear-floor/VERIFY.json @@ -0,0 +1,25 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/joint-helper-lattice/CONTROLLER.json", + "research/kappa-0023-productive-jobs/dependencies/kappa-next-regime/direct-decoder/sources/DATA-PHASES.json", + "research/kappa-rebuild/architecture/mixed_target_probe.py", + "research/kappa-rebuild/bit/sources/pr589-regenerated/WORD.json.gz", + "research/query-thinned-controllers/BIT-CONTROLLER.json", + "research/query-thinned-controllers/controller.py" + ], + "commands": [ + { + "argv": [ + "{python}", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Fusion of each of the 15 bridged thin blocks with the previous and next full call (30 per side): complex needs both Q and Q^-1, BIT has Q-coefficient rank 2; a single full call has one query (control). Parity floor: every thin query lies in a disjoint ADD/IDLE-only window after a full call on its pair, so cost >= 15 = attained; inserted SWAP breaks a window (control). 112 complex / 111 BIT distinct query lines, duplicate detected (control); merging 112 rank-one into 14 rank-eight jobs saves < 1." + } + ] +} diff --git a/research/thin-query-shear-floor/verify.py b/research/thin-query-shear-floor/verify.py new file mode 100644 index 0000000000..2699583c54 --- /dev/null +++ b/research/thin-query-shear-floor/verify.py @@ -0,0 +1,269 @@ +#!/usr/bin/env python3 +"""The 15 query-only shears of the p16 controllers cannot be absorbed by their neighbours. + +#4440 replaced selected full native calls by copied rank-one query shears; #4470 +keeps 15 of them per port in its p16 complex controller, and the retained BIT +controller has the same 15. Each costs one rank-one job per port. Making them +free would be worth a raw ceiling near 0.0099 on both sides (see the companion +productive-lever-reprice package), so this package checks three ways to remove +them, in the replay model of query-thinned-controllers/controller.py. + +1. Fusion with a neighbouring full call. For every thin stage, the bridged + shear block composed with the previous or next full native call on the same + pair needs two independent query results per port: complex has both Q^1 and + Q^-1 terms; BIT (Q^-1 = Q) has a Q-coefficient matrix of rank 2. A full call + D_s S(Q^e) has Laurent support {Q^0, Q^e} and Q-coefficient rank 1. +2. Lazy central frames. With W = S_x(-Q) S_y(Q^-1) = signed_swap diag(Q^-1,Q) + S_x(Q), a thin query can be traded for a change of the central frame parity + of fields. In the parity model (transport 1, ADD across parities 1, query + free across parities and 1 otherwise, full calls need equal parities), each + thin query sits in a window that starts at a full call on its own pair and + contains only ADD and IDLE events; the windows are disjoint. Hence every + thin stage costs at least 1, the optimum is 15, and the controller already + attains it. (A CP-SAT run on the whole word found the same optimum.) +3. A two-query native word. The per-port query lines are all distinct (112 + complex, 111 BIT), so in gather-type schemes (linear maps, rank-one queries, + free scalars and routes) a second query needs one rank-one job per port, and a + query riding on an existing one returns Q(f+u), which linearity cannot split. + Merging the 112 rank-one jobs of a stage into 14 rank-8 jobs saves under one + unit of moment at the current saving. + +Controls: a window with an inserted SWAP is rejected by the window check; a +single full call is confirmed to have Q-coefficient rank 1; a duplicated query +line is detected. Standard library only. Prepared by Matarener with Claude +Code assistance. Apache-2.0. +""" +from collections import Counter +from fractions import Fraction as Q +from pathlib import Path +import gzip +import importlib.util +import json +import sys + +sys.dont_write_bytecode = True +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +KR = ROOT/'research/kappa-rebuild' +DEP = ROOT/'research/kappa-0023-productive-jobs/dependencies/kappa-next-regime' +CONTROLLERS = {'complex': ROOT/'research/joint-helper-lattice/CONTROLLER.json', + 'bit': ROOT/'research/query-thinned-controllers/BIT-CONTROLLER.json'} + + +def need(ok, why): + if not ok: + raise SystemExit('FAIL: ' + why) + + +def load(path, name): + spec = importlib.util.spec_from_file_location(name, path) + module = importlib.util.module_from_spec(spec) + sys.modules[name] = module + spec.loader.exec_module(module) + return module + + +# Laurent polynomials in (Q, D) as {(q_exp, d_exp): Fraction}; matrices act on column vectors. +def padd(a, b, c=1): + out = dict(a) + for k, v in b.items(): + out[k] = out.get(k, 0)+c*v + if out[k] == 0: + del out[k] + return out + + +def pmul(a, b): + out = {} + for (q1, d1), v1 in a.items(): + for (q2, d2), v2 in b.items(): + k = (q1+q2, d1+d2) + out[k] = out.get(k, 0)+v1*v2 + if out[k] == 0: + del out[k] + return out + + +def apply(rows, event, fields, with_d): + """Left-multiply the row-polynomial matrix by one replay event (controller.py semantics).""" + op = event[0] + if op in ('LOCAL', 'QUERY_SHEAR'): + _, stage, pair, backward = event + x, y = 2*pair, 2*pair+1 + if backward: + x, y = y, x + term = {(1 if backward else -1, 0): Q(-1 if backward else 1)} + ix, iy = fields.index(x), fields.index(y) + rows[iy] = [padd(a, pmul(term, b)) for a, b in zip(rows[iy], rows[ix])] + if op == 'LOCAL' and with_d: + for role in (ix, iy): + rows[role] = [pmul({(0, 1): Q(1)}, a) for a in rows[role]] + elif op == 'ADD': + _, dst, src, *c = event + idst, isrc = fields.index(dst), fields.index(src) + rows[idst] = [padd(a, b, c[0] if c else 1) for a, b in zip(rows[idst], rows[isrc])] + elif op == 'IDLE': + pass # commuting D multipliers of other stages; they do not change Q-structure + else: + raise ValueError(op) + return rows + + +def block(events, fields, with_d=True): + n = len(fields) + rows = [[{(0, 0): Q(1)} if i == j else {} for j in range(n)] for i in range(n)] + for e in events: + rows = apply(rows, e, fields, with_d) + return rows + + +def coeff(rows, qexp): + return [[sum(v for (q, d), v in e.items() if q == qexp) for e in row] for row in rows] + + +def coeff_poly(rows, qexp): + return [[{d: v for (q, d), v in e.items() if q == qexp} for e in row] for row in rows] + + +def rank(rows): + rows = [list(map(Q, r)) for r in rows] + r = 0 + for c in range(len(rows[0]) if rows else 0): + piv = next((i for i in range(r, len(rows)) if rows[i][c]), None) + if piv is None: + continue + rows[r], rows[piv] = rows[piv], rows[r] + for i in range(len(rows)): + if i != r and rows[i][c]: + f = rows[i][c]/rows[r][c] + rows[i] = [x-f*y for x, y in zip(rows[i], rows[r])] + r += 1 + return r + + +def mod2_rank_generic(polys): + """Rank over GF(2)(D) via a nonzero 2x2 minor (D-polynomials mod 2); returns 2 if one exists, else <= 1.""" + def pm(a, b): + out = Counter() + for i, x in a.items(): + for j, y in b.items(): + out[i+j] += x*y + return {k: v % 2 for k, v in out.items() if v % 2} + n = len(polys) + for i in range(n): + for j in range(i+1, n): + for k in range(n): + for l in range(k+1, n): + a, b = pm(polys[i][k], polys[j][l]), pm(polys[i][l], polys[j][k]) + diff = Counter(a) + diff.update(b) + if any(v % 2 for v in diff.values()): + return 2 + return 1 if any(any(v % 2 for v in e.values()) for row in polys for e in row) else 0 + + +def thin_windows(events): + """For each QUERY_SHEAR: (index, pair, start index of the full call on the same pair, bridge span).""" + out = [] + for i, e in enumerate(events): + if e[0] != 'QUERY_SHEAR': + continue + pair = e[2] + j = max(k for k in range(i) if events[k][0] == 'LOCAL' and events[k][2] == pair) + out.append((i, pair, j)) + return out + + +def window_ok(events, i, j): + return all(events[k][0] in ('ADD', 'IDLE') for k in range(j+1, i)) + + +def fusion(kind, events): + """Q-structure of thin block + previous and + next full call on the involved pairs.""" + results = [] + for i, pair, j in thin_windows(events): + bridge = events[i-2:i] + [events[i]] + events[i+1:i+3] + need([b[0] for b in bridge] == ['ADD', 'ADD', 'QUERY_SHEAR', 'ADD', 'ADD'], f'{kind}: bridged thin block at {i}') + fields = sorted({2*pair, 2*pair+1, 2*pair+2, 2*pair+3}) + nxt = next(k for k in range(i+1, len(events)) if events[k][0] == 'LOCAL') + need(events[nxt][2] == pair+1, f'{kind}: next full call is on pair {pair+1}') + need(all(events[k][0] == 'ADD' for k in range(i+3, nxt)), f'{kind}: only bridge ADDs before next call') + for label, word in (('previous', [events[j]] + bridge), ('next', bridge + [events[nxt]])): + rows = block(word, fields) + if kind == 'complex': + r1, rm = rank(coeff(rows, 1)), rank(coeff(rows, -1)) + need(r1 >= 1 and rm >= 1, f'complex {label} fusion needs both Q and Q^-1 at {i}') + results.append(dict(thin_event=i, fused_with=label, rank_Q=r1, rank_Q_inverse=rm)) + else: + plus, minus = coeff_poly(rows, 1), coeff_poly(rows, -1) + summed = [[padd(a, b) for a, b in zip(r, s)] for r, s in zip(plus, minus)] + r2 = mod2_rank_generic(summed) + need(r2 == 2, f'BIT {label} fusion has Q-coefficient rank 2 at {i}') + results.append(dict(thin_event=i, fused_with=label, rank_Q_mod2=r2)) + # Control: one full call alone has support {Q^0, Q^e} and Q-coefficient rank 1. + first = next(e for e in events if e[0] == 'LOCAL') + rows = block([first], [0, 1]) + e = 1 if first[3] else -1 + need(rank(coeff(rows, e)) == 1 and not any(any(v for v in r) for r in coeff(rows, -e)), + f'{kind}: a single full call has one query (control)') + return results + + +def parity_floor(kind, events): + windows = thin_windows(events) + need(len(windows) == 15, f'{kind}: 15 thin queries') + for i, pair, j in windows: + need(window_ok(events, i, j), f'{kind}: window of thin event {i} has only ADD/IDLE') + spans = sorted((j, i) for i, _, j in windows) + need(all(a[1] < b[0] for a, b in zip(spans, spans[1:])), f'{kind}: windows are disjoint') + bad = list(events) + i, pair, j = windows[0] + bad.insert(j+1, ['SWAP', 2*pair, 2*pair+1]) + i2, _, j2 = thin_windows(bad)[0] + need(not window_ok(bad, i2, j2), f'{kind}: inserted SWAP breaks the window (control)') + return dict(thin_queries=15, lower_bound=15, attained=15, windows=[[j, i] for i, _, j in windows]) + + +def distinct_lines(): + phases = json.loads((DEP/'direct-decoder/sources/DATA-PHASES.json').read_text()) + qs = [r['q'] for r in phases['recipes']] + need([r['port'] for r in phases['recipes']] == list(range(112)), 'complex recipes per port') + need(len(qs) == 112 and len(set(qs)) == 112 and all(0 < q < 512 for q in qs), + 'complex: 112 distinct nonzero 9-bit query lines') + mutated = qs[:] + mutated[1] = mutated[0] + need(len(set(mutated)) == 111, 'duplicate line detected (control)') + word = json.loads(gzip.decompress((KR/'bit/sources/pr589-regenerated/WORD.json.gz').read_bytes())) + lines = [tuple(Q(x) for x in q) for q in word['lines']] + need(len(lines) == 111 and all(sum(x*x for x in q) == 4 for q in lines), 'BIT root lines') + need(len({max(q, tuple(-x for x in q)) for q in lines}) == 111, 'BIT: 111 distinct port lines up to sign') + return dict(complex_distinct_q=112, bit_distinct_lines=111) + + +def merge_saving(): + E = load(KR/'architecture/mixed_target_probe.py', 'tqs_probe') + c = Q('0.00302015') + lo, hi = E.h_interval(8, c) + saving = (112-14*hi, 112-14*lo) + need(0 < saving[0] and saving[1] < 1, 'merging 112 rank-one into 14 rank-eight saves under one unit') + return [f'{float(saving[0]):.6f}', f'{float(saving[1]):.6f}'] + + +def main(): + out = {'schema': 'thin-query-shear-floor/1', 'new_kappa': False} + for kind, path in CONTROLLERS.items(): + w = json.loads(path.read_text()) + need(w['pairs'] == 16, f'{kind}: p16 controller') + events = w['physical_events'] + fz = fusion(kind, events) + out[kind] = {'fusion_blocks_checked': len(fz), 'fusion': fz, 'parity_floor': parity_floor(kind, events)} + print(kind, len(fz), 'fusion blocks need two queries; parity floor 15 = 15', flush=True) + out['query_lines'] = distinct_lines() + out['rank_merge_saving_at_0.00302015'] = merge_saving() + out['status'] = 'PASS_THIN_QUERY_SHEAR_FLOOR' + (HERE/'RESULT.json').write_text(json.dumps(out, indent=2, sort_keys=True)+'\n', newline='\n') + print(out['status'], flush=True) + + +if __name__ == '__main__': + main()