From 4c245831b51d39e7e129c90b237c6423718f3cef Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 11 Nov 2026 15:25:13 +0000 Subject: [PATCH] Prove adjacent swaps of the #7041 block word miss mask (4). The index-17 boundary edit asked by PR #7226, and every other adjacent transposition of that length-42 floor word, has no pair that reads as the weight-1 mask (4). No kappa change. Co-authored-by: unpaidmoon --- .../PROOF.md | 119 +++++++ .../README.md | 86 +++++ .../SOURCES.json | 18 + .../TASK.json | 68 ++++ .../VERIFY.json | 34 ++ .../verify.py | 307 ++++++++++++++++++ 6 files changed, 632 insertions(+) create mode 100644 research/six-source-c7-boundary-swap-mask4/PROOF.md create mode 100644 research/six-source-c7-boundary-swap-mask4/README.md create mode 100644 research/six-source-c7-boundary-swap-mask4/SOURCES.json create mode 100644 research/six-source-c7-boundary-swap-mask4/TASK.json create mode 100644 research/six-source-c7-boundary-swap-mask4/VERIFY.json create mode 100644 research/six-source-c7-boundary-swap-mask4/verify.py diff --git a/research/six-source-c7-boundary-swap-mask4/PROOF.md b/research/six-source-c7-boundary-swap-mask4/PROOF.md new file mode 100644 index 0000000000..bd6367531b --- /dev/null +++ b/research/six-source-c7-boundary-swap-mask4/PROOF.md @@ -0,0 +1,119 @@ +# Adjacent swaps miss mask (4) + +The alphabet and the pair predicate are unchanged. A floor word on six +sources in characteristic 7 has length 42 and uses each source seven times. +`q_t` is the count vector of the first `t` letters. A pair `0 ≤ s ≤ t ≤ 41` +reads as a binary mask when every coordinate of `q_s + q_t` lies in +`{0, 1, 7, 8, 14}` and the two readings, that allowed set and reduction +modulo 7, agree. The mask bit is 1 exactly on `{1, 8}`. Mask `(4)` is the +weight-1 mask whose only 1 is source 4. + +The block word is + +```text +350122222224444444000000111111333333555555 +``` + +with blocks `3, 5, 0, 1, 2^7, 4^7, 0^6, 1^6, 3^6, 5^6`. String indices are +0-based. Indices `11..17` are the seven `4`s and indices `18..23` are the +six following `0`s, so index 17 is the last `4` and index 18 is the +following `0`. + +## One prefix moves + +Let `w` be the word and let `w'` be `w` with indices `i` and `i+1` +exchanged, `0 ≤ i ≤ 40`. Write `a = w_i` and `b = w_{i+1}`. The prefix +`q_t` counts letters `w_0, ..., w_{t-1}`. + +- If `t ≤ i`, those letters do not include index `i` or `i+1`. +- If `t ≥ i+2`, those letters include both indices. +- If `t = i+1`, the counted letters include index `i` and exclude `i+1`. + +Thus `q'_t = q_t` for every `t ≠ i+1`. When `a ≠ b`, + +```text +q'_{i+1} = q_{i+1} - e_a + e_b. +``` + +When `a = b`, the word is unchanged. There are 32 such indices and 9 +indices where the letters differ. The nine are the block boundaries +`0, 1, 2, 3, 10, 17, 23, 29, 35`. + +A pair whose endpoints both avoid `i+1` therefore has the same sum on `w` +and on `w'`. A pair that uses the endpoint `i+1` has the other endpoint +anywhere in `0..41`, so there are 42 such pairs. The domain of adjacent +transpositions is exactly the 41 index pairs. This count is the +completeness statement for the census. + +## The unswapped word + +`verify.py` evaluates all `42 · 43 / 2 = 903` pairs of `w`. None reads as +mask `(4)`. Every pair that avoids the moved prefix inherits that miss. + +## The named boundary + +Take `i = 17`, so `a = 4` and `b = 0`. The only moved prefix is `q_18`. +Direct count gives + +```text +q_18 = (1, 1, 7, 1, 7, 1), +q'_18 = (2, 1, 7, 1, 6, 1) = q_18 - e_4 + e_0. +``` + +Suppose `q'_18 + r` reads as mask `(4)`. Coordinate 4 of the sum is +`6 + r_4`. It lies in `{1, 8}` and `r_4 ≥ 0`, so `r_4 = 2` and the sum is +8. The other five coordinates lie in `{0, 7, 14}`: + +| source | `q'_18` | admissible `r` | +|---:|---:|---| +| 0 | 2 | 5 | +| 1 | 1 | 6 | +| 2 | 7 | 0 or 7 | +| 3 | 1 | 6 | +| 4 | 6 | 2 | +| 5 | 1 | 6 | + +No other value in `0..7` works. The two admissible vectors are + +```text +(5, 6, 0, 6, 2, 6), sum 25, +(5, 6, 7, 6, 2, 6), sum 32. +``` + +The coordinate sum of `q_u` is `u`, so the other endpoint would have to be +25 or 32. Both differ from 18, hence those prefixes are the original +prefixes. At `t = 25` and `t = 32` the original word already has source 0 +and source 4 equal to 7, not 5 and 2. The doubled prefix `2 q'_18 = +(4, 2, 14, 2, 12, 2)` has coordinate 4 equal to 12, so the pair `(18, 18)` +is not mask `(4)` either. + +Both admissible sums do read as mask `(4)`: + +```text +q'_18 + (5, 6, 0, 6, 2, 6) = (7, 7, 7, 7, 8, 7), +q'_18 + (5, 6, 7, 6, 2, 6) = (7, 7, 14, 7, 8, 7). +``` + +The obstruction is that those prefixes do not occur, not that the predicate +rejects the shape. The same checker evaluates the 42 incident pairs and +finds none. It also records that exactly two readings change, both from a +nonzero mask to a non-reading: `(0, 18)` leaves `(0, 1, 3, 5)`, and +`(18, 41)` leaves `(0, 1, 3)`. + +## The other eight boundaries + +For each of the other eight indices the same one-prefix identity holds, and +the 42 incident pairs are evaluated with the same predicate. None reads as +mask `(4)`. The recorded changed prefixes are checked against +`q_{i+1} - e_a + e_b`. Equal-letter swaps are checked to be the original +word. Together with the 903-pair census of `w`, every adjacent transposition +misses mask `(4)`. + +## What this does not say + +The census does not range over non-adjacent transpositions, over other +floor words, or over the seventeen missed weight-3 masks. A depth-two block +needs every nonzero mask. Missing mask `(4)` on these 42 words does not +decide whether some other floor word realizes it, and it does not decide +characteristic 7. No supplier, consumer, or selected frontier changes. The +selected conditional κ remains `363005817/100000000000`. diff --git a/research/six-source-c7-boundary-swap-mask4/README.md b/research/six-source-c7-boundary-swap-mask4/README.md new file mode 100644 index 0000000000..2199359b98 --- /dev/null +++ b/research/six-source-c7-boundary-swap-mask4/README.md @@ -0,0 +1,86 @@ +# Adjacent swaps of the #7041 block word miss mask (4) + +**Exhaustive finite census, with a coordinate proof for the named boundary. No new κ.** On the length-42 block word + +```text +350122222224444444000000111111333333555555 +``` + +no pair reads as the weight-1 mask `(4)`. The same is true after every adjacent transposition. In particular it is true after exchanging string indices 17 and 18, the last `4` and the following `0`, which is the word + +```text +350122222224444440400000111111333333555555 +``` + +The selected conditional κ remains `363005817/100000000000`. This package does not change it. + +## Interface, unchanged + +A floor word on six sources in characteristic 7 has length 42 and calls each source seven times. `q_t` counts the first `t` letters. A pair `0 ≤ s ≤ t ≤ 41` reads as a mask when every coordinate of `q_s + q_t` lies in `{0, 1, 7, 8, 14}` and that reading agrees with reduction modulo 7. Mask `(4)` has its only 1 on source 4. This is the predicate of PR #7041 and of the unswapped inventory PR #7226. The argument is in [PROOF.md](PROOF.md). + +## What is proved + +An adjacent exchange of indices `i` and `i+1` moves only the prefix `q_{i+1}`. Pairs that avoid that endpoint keep the sums of the original word, and the original 903 pairs miss mask `(4)`. The 42 pairs that use the moved endpoint are evaluated directly. + +Nine indices have unequal letters: `0, 1, 2, 3, 10, 17, 23, 29, 35`. The other 32 adjacent swaps are the original word. None of the nine realizes mask `(4)`. + +For index 17 the moved prefix is `q'_18 = (2, 1, 7, 1, 6, 1)`. A sum `q'_18 + r` reads as mask `(4)` only for + +```text +r = (5, 6, 0, 6, 2, 6) or r = (5, 6, 7, 6, 2, 6), +``` + +whose coordinate sums are 25 and 32. Neither vector is `q_25` or `q_32`. Both target sums do read as mask `(4)`, so the predicate is not what rejects them. Exactly two readings change, and both become non-readings: `(0, 18)` leaves `(0, 1, 3, 5)`, and `(18, 41)` leaves `(0, 1, 3)`. + +## Task and overlap + +Session r280, item 3 of the ordered eligible list rebuilt on 2026-11-11 against `e54523517d0f03e58352e647c403a5af3e525a57`. + +Open handoffs were dropped when a later post completed them, a merged result answered them, the canonical artifact is an open pull request, the post says no target was taken, or the exclusion list already delivers that request. That removes the delivered 19 October index, the H25 chain, the V02 handoffs whose artifacts are open PRs #7136 and #7137 (with #7284 and #7288 already recording the receipt and assumption gaps), the 10 November CI-document handoff claimed through 2026-11-11T16:35:00Z, and the 7 November caller handoffs whose artifacts are open PRs #6837, #6862 and #6863. Three prose handoffs remain. Today's search-failure notes update the second and third and do not close them. The revision-8 next-decision rows follow, then unnamed catalogue cards: + +1. Three signed added frames at seven calls (discussion comment 19377832). +2. Eight-source singleton connector at length 30 (comment 19377982, updated by comment 19537798). +3. **This package.** Six-source depth-two block at `c = 7` (comment 19384981, updated by comment 19537594). +4. Complex helpers (`p104-side-correction`, `coverage-law-change`). +5. BIT (`bit-helper-contract`). +6. New decoders and interfaces. +7. Supplier audit (`supplier-boundary-audit`). +8. All-size audit (`uniform-transfer-audit`). +9. Verification tooling (`replay-runtime`). +10. `bit-new-register-model`. + +Card `connector-alphabet-change`, scope **changed**. The card asks for one new connector operation. The alphabet stays the unsigned dirty connector. The piece taken is open question 1 of PR #7226: the index-17 boundary swap, which that inventory states and does not evaluate. The other eight block boundaries are the same one-prefix census, not a second question. PR #7041 supplies the word and the two masks it was built to realize. PR #7037, PR #7016, PR #7032 and PR #7045 are different claims and are not redone. + +Overlap refresh at 2026-11-11T15:22:29Z covered 589 open PR bodies and 7,253 discussion records, with complete reported pagination, plus local notes at this base. No open PR body, discussion record, or local note contains the swapped literal `350122222224444440400000111111333333555555`. Closed PR bodies were not fetched beyond local notes and the ledger. + +## Reproduce + +Python 3.12, standard library only, from the repository root. The census is 42 words times 903 pairs and finishes in well under a second. + +```sh +python3 -B research/six-source-c7-boundary-swap-mask4/verify.py +python3 -O -B research/six-source-c7-boundary-swap-mask4/verify.py +python3 -B scripts/research_package.py --package research/six-source-c7-boundary-swap-mask4 --check-only +python3 -B scripts/research_package.py --package research/six-source-c7-boundary-swap-mask4 +``` + +The direct marker is + +```text +PASS_SIX_SOURCE_C7_BOUNDARY_SWAP_MASK4 pairs=903 boundaries=9 identities=32 named_index=17 mask4_pairs=0 adjacent_mask4_pairs=0 changed_readings=2 positive_targets=2 controls=4 no_new_kappa=true +``` + +Failures raise `SystemExit`, so `-O` does not disable them. The four controls are the floor-word literal, the named coordinate obstruction, the nine-boundary census, and the predicate controls. The predicate controls accept the two absent target sums as mask `(4)`, reject coordinate 2, and reject coordinate 15 because the allowed-set and modulo-7 readings split. + +Not run: `make frontier7000-verify`, any SAT search, a census of non-adjacent transpositions, and the seventeen weight-3 masks on the index-10 swap. + +## Open next questions + +1. Which of the 17 weight-3 masks missed by the unswapped word appear after exchanging indices 10 and 11, the last `2` and the first `4`? *Why:* that is open question 2 of PR #7226. This package only tracks mask `(4)`, including at that boundary. *First step:* evaluate those 17 masks on that one swapped word. *Blocked by:* nothing algebraic; the weight-3 predicate is not implemented here. +2. Does a non-adjacent transposition of this word realize mask `(4)`? *Why:* the one-prefix reduction uses adjacency. Two moved prefixes can cooperate. *First step:* one pair of indices at distance 2 whose letters are `4` and `0`. *Blocked by:* nothing external; the domain is the `C(42, 2) = 861` transpositions, which this census does not enter. + +## Credit + +The depth-two interface and the weight identity are Nick Petalas's (PR #4231, PR #4248, PR #6107), with the Ross Richardson PR #934 / PR #943 lineage. JosieElliston's PR #6141 leaves characteristic 7 open. The diagonal equality case is `research/six-source-c7-diagonal-obstruction` (upstream PR #6941). The block word is upstream PR #7041. The question answered here is open question 1 of upstream PR #7226; that inventory is not recomputed. + +Prepared by unpaidmoon with substantial Cursor Grok assistance. Apache-2.0. diff --git a/research/six-source-c7-boundary-swap-mask4/SOURCES.json b/research/six-source-c7-boundary-swap-mask4/SOURCES.json new file mode 100644 index 0000000000..5335fa97d9 --- /dev/null +++ b/research/six-source-c7-boundary-swap-mask4/SOURCES.json @@ -0,0 +1,18 @@ +{ + "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" + } + ] +} diff --git a/research/six-source-c7-boundary-swap-mask4/TASK.json b/research/six-source-c7-boundary-swap-mask4/TASK.json new file mode 100644 index 0000000000..592d9eb6fe --- /dev/null +++ b/research/six-source-c7-boundary-swap-mask4/TASK.json @@ -0,0 +1,68 @@ +{ + "schema_version": 1, + "task_id": "connector-alphabet-change", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "connector-alphabet-change", + "question": "Does one explicit extension of the connector alphabet offer a favorable completed budget?", + "starting_points": [ + "docs/research/research-family-status.md", + "research/universal-connector-boundary/README.md", + "certificates/selected-result.json" + ], + "methods": [ + "Construct and charge a legal extra operation on a minimal instance.", + "Prove a target-specific bound after adding one specified operation family." + ], + "acceptance_gate": "State which fixed-alphabet premise changes and charge its implementation; do not declare it free. 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/universal-connector-boundary/verify.py" + ], + "expected": "PASS_UNIVERSAL_CONNECTOR_BOUNDARY", + "inspect": "Reproduce the 945-pairing control, then read Exact interface to list the allowed calls.", + "scope": "Positive control / source-bound orientation only; this is not a new construction or full cold replay." + }, + "first_experiment": "Add exactly one legally priced operation and test a tiny dirty-input instance before enumerating larger cases.", + "bottleneck_link": "A new legal connector operation could change recursive interface cost; a larger census in the same alphabet is a separate side result.", + "allowed_variations": [ + "Choose one additional operation and a small source count for its first counterexample." + ], + "scope_change_triggers": [ + "Keeping the alphabet and only increasing the source count; record this as a changed assignment.", + "Extending a source-count census without naming a supplier/interface decision it could change; audit #2973 pruning concerns before relying on the affected predecessor exclusions." + ], + "overlap_terms": [ + "universal connector", + "source-toggle", + "connector alphabet" + ] + }, + "scope_status": "changed", + "actual_scope": "On the PR #7041 length-42 block word, mask (4) has no realizing pair. The same holds after every adjacent transposition, including the exchange of string indices 17 and 18 named by open question 1 of PR #7226. The unrestricted six-source depth-two question at c=7 stays open.", + "scope_change_reason": "The catalogue card asks for one new connector operation. This package keeps the unsigned dirty connector alphabet fixed and answers one released edit inside the c=7 depth-two handoff: the index-17 boundary swap of the block word, which PR #7226 states and does not evaluate. A new operation is not the missing step.", + "bottleneck_link": "Side result on the recursive-interface schedule. It does not change a supplier, a consumer, or kappa. Mask (4) is one of the four weight-1 masks the block word misses; showing that the named boundary edit still misses it removes that one-letter repair.", + "budget_minutes": 60, + "stop_rule": "Stop once every adjacent transposition, including index 17, is shown to miss mask (4), or stop if any incident pair reads as that mask.", + "outcome": "negative-result", + "evidence": "Written one-prefix argument plus an exhaustive standard-library census: 903 pairs of the unswapped word, 9 unequal adjacent boundaries, and 32 equal-letter identities. For index 17 the only moved prefix is q'_18 = (2,1,7,1,6,1), and the only two count vectors that would read as mask (4) against it are absent. Exactly two readings change, both to non-readings.", + "author": "unpaidmoon", + "ai_assistance": "Substantial Cursor Grok assistance: the obstruction, the exhaustive checker, and the package text.", + "open_questions": [ + { + "question": "Which of the 17 weight-3 masks missed by the unswapped word appear after exchanging indices 10 and 11?", + "why_it_matters": "That is open question 2 of PR #7226. This census only tracks mask (4), so it does not say whether the 2/4 boundary creates a missed weight-3 mask.", + "first_step": "Evaluate those 17 masks on the single word obtained by swapping indices 10 and 11.", + "blocked_by": "Nothing algebraic. The weight-3 predicate is not implemented in this package." + }, + { + "question": "Does a non-adjacent transposition of this block word realize mask (4)?", + "why_it_matters": "Adjacency is what keeps the edit to one prefix. Two moved prefixes can cooperate, so the adjacent miss does not bound a general transposition.", + "first_step": "Swap one pair of indices at distance 2 whose letters are 4 and 0, and rerun the 903-pair predicate.", + "blocked_by": "Nothing external. The full domain is the 861 transpositions, which this census does not enter." + } + ] +} diff --git a/research/six-source-c7-boundary-swap-mask4/VERIFY.json b/research/six-source-c7-boundary-swap-mask4/VERIFY.json new file mode 100644 index 0000000000..6358353645 --- /dev/null +++ b/research/six-source-c7-boundary-swap-mask4/VERIFY.json @@ -0,0 +1,34 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 60, + "checks": "Exhaustive census: 903 pairs of the block word miss mask (4); all 41 adjacent transpositions miss it, including the index-17 boundary. The named swap moves only q_18, and the two admissible mask-(4) partners are absent at t=25 and t=32. Four controls cover the literal, that obstruction, the nine boundaries, and the predicate." + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 60, + "checks": "Same checks under optimized Python. Failures are explicit exceptions, not assertions." + } + ] +} diff --git a/research/six-source-c7-boundary-swap-mask4/verify.py b/research/six-source-c7-boundary-swap-mask4/verify.py new file mode 100644 index 0000000000..96eec9960d --- /dev/null +++ b/research/six-source-c7-boundary-swap-mask4/verify.py @@ -0,0 +1,307 @@ +#!/usr/bin/env python3 +"""Adjacent swaps of the PR #7041 block word miss the weight-1 mask (4). + +The word is 3,5,0,1, 2^7, 4^7, 0^6, 1^6, 3^6, 5^6. Swapping string +indices 17 and 18 exchanges the last 4 with the following 0. Every +adjacent transposition, including that one, is checked. Evidence class: +exhaustive finite census of a 42-letter word and its 41 adjacent +transpositions. Not a search over floor words, and not a kappa change. +""" + +K = 6 +C = 7 +LENGTH = 42 +BLOCKS = ( + (3, 1), + (5, 1), + (0, 1), + (1, 1), + (2, 7), + (4, 7), + (0, 6), + (1, 6), + (3, 6), + (5, 6), +) +LITERAL = "350122222224444444000000111111333333555555" +NAMED_INDEX = 17 +ALLOWED = {0: 0, 1: 1, 7: 0, 8: 1, 14: 0} +MASK4 = (0, 0, 0, 0, 1, 0) +PAIR_COUNT = LENGTH * (LENGTH + 1) // 2 +# The nine places where consecutive letters differ. Each row is +# (index, left letter, right letter, changed prefix q'_{index+1}). +BOUNDARIES = ( + (0, 3, 5, (0, 0, 0, 0, 0, 1)), + (1, 5, 0, (1, 0, 0, 1, 0, 0)), + (2, 0, 1, (0, 1, 0, 1, 0, 1)), + (3, 1, 2, (1, 0, 1, 1, 0, 1)), + (10, 2, 4, (1, 1, 6, 1, 1, 1)), + (17, 4, 0, (2, 1, 7, 1, 6, 1)), + (23, 0, 1, (6, 2, 7, 1, 7, 1)), + (29, 1, 3, (7, 6, 7, 2, 7, 1)), + (35, 3, 5, (7, 7, 7, 6, 7, 2)), +) +NAMED_CHANGED = ( + ((0, 18), (1, 1, 0, 1, 0, 1), None, (2, 1, 7, 1, 6, 1)), + ((18, 41), (1, 1, 0, 1, 0, 0), None, (9, 8, 14, 8, 13, 7)), +) +# Arithmetic targets that would read as mask (4) against q'_18. +CANDIDATES = ( + (25, (5, 6, 0, 6, 2, 6)), + (32, (5, 6, 7, 6, 2, 6)), +) + + +def fail(message): + raise SystemExit("FAIL: " + message) + + +def expand(blocks): + letters = [] + for source, count in blocks: + if source not in range(K) or count < 1: + fail("bad block %s" % ((source, count),)) + letters.extend([source] * count) + return tuple(letters) + + +def prefix_table(letters): + if len(letters) != LENGTH or any(letter not in range(K) for letter in letters): + fail("not a length-42 word on sources 0..5") + running = [0] * K + table = [tuple(running)] + for letter in letters: + running[letter] += 1 + table.append(tuple(running)) + if table[-1] != (C,) * K: + fail("final count is not seven calls of each source") + if any(letters.count(source) != C for source in range(K)): + fail("not a floor word") + return tuple(table) + + +def add(left, right): + return tuple(left[source] + right[source] for source in range(K)) + + +def readings(total): + """Mask from {0,1,7,8,14}, or None when a coordinate is outside it. + + The residue reading modulo 7 must agree. A disagreement is a predicate + failure, not a choice of reading. + """ + allowed_bits = [] + modular_bits = [] + allowed_ok = True + modular_ok = True + for value in total: + if value not in ALLOWED: + allowed_ok = False + else: + allowed_bits.append(ALLOWED[value]) + residue = value % C + if residue not in (0, 1): + modular_ok = False + else: + modular_bits.append(residue) + allowed_mask = tuple(allowed_bits) if allowed_ok else None + modular_mask = tuple(modular_bits) if modular_ok else None + if allowed_mask != modular_mask: + fail("allowed-set and mod-7 readings disagree on " + str(total)) + return allowed_mask + + +def mask4_hits(table): + hits = [] + examined = 0 + for left in range(LENGTH): + for right in range(left, LENGTH): + examined += 1 + total = add(table[left], table[right]) + mask = readings(total) + if mask is None: + continue + weight = sum(mask) + if (left + right - weight) % C: + fail("weight identity failed at %s mask %s" % ((left, right), mask)) + if mask == MASK4: + hits.append((left, right, total)) + if examined != PAIR_COUNT: + fail("visited %s pairs, expected %s" % (examined, PAIR_COUNT)) + return tuple(hits) + + +def changed_readings(original, swapped): + rows = [] + for left in range(LENGTH): + for right in range(left, LENGTH): + before = readings(add(original[left], original[right])) + after_total = add(swapped[left], swapped[right]) + after = readings(after_total) + if before != after: + rows.append(((left, right), before, after, after_total)) + return tuple(rows) + + +def swap(letters, index): + if not 0 <= index < LENGTH - 1: + fail("swap index %s is outside 0..40" % index) + swapped = list(letters) + swapped[index], swapped[index + 1] = swapped[index + 1], swapped[index] + return tuple(swapped) + + +def check_word(done): + letters = expand(BLOCKS) + literal = "".join(str(source) for source in letters) + if literal != LITERAL: + fail("block literal changed") + if len(BOUNDARIES) != 9: + fail("boundary table length changed") + seen = [] + for index, left, right, _prefix in BOUNDARIES: + if letters[index] != left or letters[index + 1] != right or left == right: + fail("boundary %s is not letters %s,%s" % (index, left, right)) + seen.append(index) + computed = [index for index in range(LENGTH - 1) if letters[index] != letters[index + 1]] + if computed != seen: + fail("boundaries are %s, word has %s" % (seen, computed)) + if letters[NAMED_INDEX] != 4 or letters[NAMED_INDEX + 1] != 0: + fail("index 17 is not the last 4 followed by 0") + # Seven 4s occupy indices 11..17, so 17 is the last one. + if letters[11:18] != (4,) * 7 or letters[18:24] != (0,) * 6: + fail("the 4-block or the following 0-block moved") + table = prefix_table(letters) + if mask4_hits(table): + fail("the unswapped word already realizes mask (4)") + done.append("floor-word") + return letters, table + + +def check_named_obstruction(letters, table, done): + swapped_letters = swap(letters, NAMED_INDEX) + swapped = prefix_table(swapped_letters) + if "".join(str(source) for source in swapped_letters) != "350122222224444440400000111111333333555555": + fail("named swap literal changed") + diffs = [index for index in range(LENGTH + 1) if table[index] != swapped[index]] + if diffs != [NAMED_INDEX + 1]: + fail("named swap moves prefixes %s" % (diffs,)) + expected = (2, 1, 7, 1, 6, 1) + manual = tuple( + table[18][source] + (1 if source == 0 else -1 if source == 4 else 0) + for source in range(K) + ) + if swapped[18] != expected or manual != expected: + fail("q'_18 is %s, not q_18 - e_4 + e_0" % (swapped[18],)) + for endpoint, vector in CANDIDATES: + if sum(vector) != endpoint: + fail("candidate %s does not sum to its index" % (vector,)) + total = add(expected, vector) + if readings(total) != MASK4: + fail("candidate sum %s does not read as mask (4)" % (total,)) + if table[endpoint][0] != C or table[endpoint][4] != C: + fail("q_%s does not have sources 0 and 4 equal to 7" % endpoint) + if table[endpoint] == vector or swapped[endpoint] == vector: + fail("candidate %s occurs as a prefix" % (vector,)) + # These indices are not 18, so the swapped word keeps the original prefix. + if swapped[endpoint] != table[endpoint]: + fail("candidate index %s was moved by the named swap" % endpoint) + double = add(expected, expected) + if readings(double) == MASK4 or double[4] in (1, 8): + fail("the doubled changed prefix reads as mask (4)") + incident = [] + for other in range(LENGTH): + left, right = sorted((18, other)) + total = add(swapped[left], swapped[right]) + if readings(total) == MASK4: + incident.append((left, right, total)) + if incident: + fail("an incident pair realizes mask (4): %s" % (incident,)) + if len({(18, other) for other in range(LENGTH)}) != LENGTH: + fail("incident endpoint count changed") + hits = mask4_hits(swapped) + if hits: + fail("named swap realizes mask (4) at %s" % (hits,)) + changed = changed_readings(table, swapped) + if changed != NAMED_CHANGED: + fail("named reading changes are %s" % (changed,)) + done.append("named-obstruction") + return swapped + + +def check_adjacent(letters, table, done): + nontrivial = 0 + identities = 0 + for index in range(LENGTH - 1): + swapped_letters = swap(letters, index) + if letters[index] == letters[index + 1]: + if swapped_letters != letters: + fail("equal-letter swap at %s changed the word" % index) + identities += 1 + continue + nontrivial += 1 + swapped = prefix_table(swapped_letters) + diffs = [point for point in range(LENGTH + 1) if table[point] != swapped[point]] + if diffs != [index + 1]: + fail("swap %s moves prefixes %s" % (index, diffs)) + left, right = letters[index], letters[index + 1] + manual = list(table[index + 1]) + manual[left] -= 1 + manual[right] += 1 + if swapped[index + 1] != tuple(manual): + fail("swap %s prefix is not q - e_%s + e_%s" % (index, left, right)) + row = next(item for item in BOUNDARIES if item[0] == index) + if row[3] != swapped[index + 1]: + fail("recorded prefix at %s is %s, computed %s" % (index, row[3], swapped[index + 1])) + hits = mask4_hits(swapped) + if hits: + fail("adjacent swap %s realizes mask (4) at %s" % (index, hits)) + if nontrivial != 9 or identities != 32: + fail("split is boundaries %s identities %s" % (nontrivial, identities)) + done.append("adjacent-census") + + +def check_controls(done): + if readings((0, 0, 0, 0, 1, 0)) != MASK4: + fail("unit source-4 sum does not read as mask (4)") + if readings((0, 0, 0, 0, 8, 0)) != MASK4: + fail("coordinate 8 does not read as mask (4)") + if readings((2, 1, 7, 1, 6, 1)) is not None: + fail("the changed prefix itself was accepted as a reading") + if readings((7, 7, 7, 7, 8, 7)) != MASK4: + fail("the first arithmetic target lost mask (4)") + if readings((7, 7, 14, 7, 8, 7)) != MASK4: + fail("the second arithmetic target lost mask (4)") + # 2 is outside the allowed set and is not 0 or 1 mod 7, so both readings reject. + if readings((0, 0, 0, 0, 2, 0)) is not None: + fail("coordinate 2 was accepted") + # 15 is 1 mod 7 but not in the allowed set, so the two readings split. + try: + readings((0, 0, 0, 0, 15, 0)) + except SystemExit as exc: + if "disagree" not in str(exc): + fail("coordinate 15 failed for the wrong reason: %s" % exc) + else: + fail("coordinate 15 did not split the two readings") + done.append("predicate-controls") + + +def main(): + done = [] + letters, table = check_word(done) + check_named_obstruction(letters, table, done) + check_adjacent(letters, table, done) + check_controls(done) + expected = ["floor-word", "named-obstruction", "adjacent-census", "predicate-controls"] + if done != expected: + fail("checks finished as %s" % (done,)) + print( + "PASS_SIX_SOURCE_C7_BOUNDARY_SWAP_MASK4 " + "pairs=903 boundaries=9 identities=32 named_index=17 " + "mask4_pairs=0 adjacent_mask4_pairs=0 changed_readings=2 " + "positive_targets=2 controls=4 no_new_kappa=true" + ) + + +if __name__ == "__main__": + main()