diff --git a/research/two-axis-monomial-geodesics/PROOF.md b/research/two-axis-monomial-geodesics/PROOF.md new file mode 100644 index 0000000000..16547edf4e --- /dev/null +++ b/research/two-axis-monomial-geodesics/PROOF.md @@ -0,0 +1,163 @@ +# Exact two-axis record distances + +## Model and statement + +An address is x=(x0,x1) in F2^2, ordered by x0+2x1. Retain the +affine-quadratic monomial normal form of Cao Yifan / intqwq #4610: + +```text +U |x> = i^(a+c0*x0+c1*x1+2*q*x0*x1) |A*x+b>, +A in GL(2,F2), b in F2^2, a,c0,c1 in Z/4, q in F2. +``` + +Each of the following eight directed records has cost one: + +```text +C01: x1 <- x1+x0 C10: x0 <- x0+x1 +X0: x0 <- x0+1 X1: x1 <- x1+1 +S0: multiply by i^x0 S1: multiply by i^x1 +CZ: multiply by (-1)^(x0*x1) +omega: multiply by i. +``` + +Every exponent uses the current address. Words below are chronological, +with the leftmost record executed first. In particular S_j^-1 and +omega^-1 each require three unit records; they are not additional +cost-one generators. All absolute phases are retained. + +**Finite certificate theorem.** This directed Cayley graph has 3,072 +vertices and diameter eight. Its numbers of vertices at distances zero +through eight from identity are + +```text +1, 8, 42, 162, 467, 884, 940, 475, 93. +``` + +The n=2 extremizer of unpaidmoon #7286 has exact distance six, attained by + +```text +C01, X1, C10, S1, omega, omega. +``` + +This answers its first open question negatively at the requested first +example: sixteen is the length of that elimination, not a lower bound on +all recipes. The claims of shortestness and diameter use the exhaustive +certificate checks below. They are not a proof-kernel formalization. + +## Complete and unique inventory + +There are six binary invertible two-by-two matrices, because their rows +are distinct members of {01,10,11}. There are four translations and +4*4*4*2=128 phase choices, giving 6*4*128=3,072 normal forms. +They are distinct as literal monomials. The four output addresses +recover b and both columns of A. If p(x) is the phase exponent, then + +```text +a = p(0), c0 = p(e0)-p(0), c1 = p(e1)-p(0), +2q = p(e0+e1)-p(e0)-p(e1)+p(0) modulo 4. +``` + +Thus these evaluations recover every phase parameter too. The independent +checker enumerates exactly this Cartesian product and checks 3,072 distinct +literal actions. Its closed-form polynomial gate updates are checked on +all four addresses of every normal form for every one of the eight gates. +This accounts for all 24,576 labeled edges, including loops or repeated +endpoints if any occur; no assumed group presentation substitutes for an +edge check. The enumeration and edge closure bind the computational domain +to the stated group. The primary search reaches every member. + +For example, an affine bit y=b+u*x0+v*x1 over F2 has the Z/4 polynomial + +```text +y = b+(1-2b)*(u*x0+v*x1-2*u*v*x0*x1). +``` + +This gives the S updates. For CZ, expand 2*y0*y1 using arithmetic in F2 +inside the product, and reduce x_j^2 to x_j. CNOT and X only change A,b. +These formulas are implemented independently of the primary basis-action +updates. Gate matrices are also stored literally in the independent check. + +## The distance certificate + +Code each monomial as eight decimal digits: its four output addresses +followed by its four exponents, in the above address order. A certificate +assigns an integer d(v) between zero and eight to every code. The checker +verifies all of the following: + +1. The inventory equals the complete normal-form inventory. +2. Identity has label zero, and it is the only zero label. +3. Every labeled edge u -> v satisfies d(v) <= d(u)+1. +4. Every nonidentity v has an incoming edge u -> v with d(u)=d(v)-1. + +For any length-L word from identity to v, condition 3 telescopes to +d(v)<=L. Condition 4 repeatedly decreases a nonnegative integer until +the unique zero vertex is reached. Reversing these incoming edges gives +a word of length d(v). Hence d(v) is the exact directed distance. The +maximum label is therefore the diameter. +Right multiplication preserves every left-generator edge, so the maximum +distance from identity is also the maximum over all ordered vertex pairs. + +The primary program builds the labels by literal-action breadth-first +search and replays an attaining shortest word for every vertex. The +independent program can consume the exported table, or generate its own +labels by eight bounded normal-form layers before checking the conditions. +Both report the same SHA256 of the sorted complete table. The proof uses +the edge and predecessor checks, rather than trusting the search algorithm +to establish optimality. Three modified certificates must fail, with their +specific rejection reasons checked. + +## Explicit attaining words + +The six-record word has output + +```text +(x1+1, x0+x1+1) +``` + +over F2. Its exponent is + +```text +2+(1-(x0 xor x1)) = 3-x0-x1+2*x0*x1 modulo 4. +``` + +Consequently it is precisely the #7286 witness with + +```text +A = [[0,1],[1,1]], b=(1,1), a=c0=c1=3, q=1. +``` + +Its literal code is 31023223 and its certified distance is six. This +hand calculation establishes the claimed identity without running the +predecessor's elimination. + +A diameter witness has code 02133322 and normal form + +```text +U |x0,x1> = i^(3+3*x1) |x1,x0>. +``` + +It is attained by + +```text +C01, C10, C01, X0, S0, X0, omega, omega. +``` + +The first three records swap the bits. The X0,S0,X0 block contributes +1-x1 to the phase and restores the output address. The final two records +add two. Its certified distance is eight. There are 93 distance-eight +elements in the complete census. + +## Boundary of the conclusion + +This is a one-column optimum in exactly the eight-record alphabet, with +absolute phase and unit record prices. If a physical API prices inverse +phases as one record, identifies global phases, permits extra axes or +dirty workspace, or adds other gates, this distance theorem does not +apply to that different optimization problem. Tensor-lifting the displayed +identities gives equal operators at every positive column count, but +shortestness at larger column counts is not claimed. For example scalar +phases can disappear under an even tensor power. + +The retained physical movement, restoration and tape hypotheses still +govern implementation of the records. This package supplies no physical +caller, new kappa, uniform n-axis optimum or multiplication theorem. diff --git a/research/two-axis-monomial-geodesics/README.md b/research/two-axis-monomial-geodesics/README.md new file mode 100644 index 0000000000..9cb8671ca3 --- /dev/null +++ b/research/two-axis-monomial-geodesics/README.md @@ -0,0 +1,150 @@ +# Two-axis monomials need at most eight elementary records + +**Exact finite certificate. No new kappa.** In the selected two-axis +affine-quadratic monomial alphabet, the directed diameter is exactly eight. +The particular monomial taking sixteen records under unpaidmoon's +[PR #7286](https://github.com/CrocSwap/integer-mult-bounds/pull/7286) +elimination has a shortest recipe of six records: + +```text +C01, X1, C10, S1, omega, omega. +``` + +This contribution was produced by Nick Petalas. Apache-2.0. + +## Result and exact alphabet + +An address is (x0,x1), numbered x0+2*x1. C01 adds bit 0 to bit 1; +C10 adds bit 1 to bit 0. Xj flips bit j, Sj multiplies by i^xj, CZ +multiplies by (-1)^(x0*x1), and omega multiplies by i. Each record costs +one. Words execute left to right. S inverses and omega inverse each +cost three records. No absolute phase is discarded. + +The finite group consists of all + +```text +|x> -> i^(a+c0*x0+c1*x1+2*q*x0*x1) |A*x+b>, +A in GL(2,F2), b in F2^2, a,c0,c1 in Z/4, q in F2. +``` + +There are 3,072 distinct elements. The complete distance census is + +| Distance | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | +|---|---|---|---|---|---|---|---|---|---| +| Elements | 1 | 8 | 42 | 162 | 467 | 884 | 940 | 475 | 93 | + +The six-record word has exactly the predecessor's witness parameters +`A=[[0,1],[1,1]], b=(1,1), a=c0=c1=3, q=1`. Its certified shortest +distance is six. A diameter witness is + +```text +|x0,x1> -> i^(3+3*x1) |x1,x0>, +C01, C10, C01, X0, S0, X0, omega, omega. +``` + +[PROOF.md](PROOF.md) defines the finite certificate theorem and proves why +its exhaustive checks establish shortestness. It also derives both words +by hand. The predecessor's exact elimination count remains a cited result; +none of its scientific code is imported or replayed. + +## Verification and reproduction + +From the worktree root, CPython 3.12 and its standard library suffice: + +```sh +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -W error -B research/two-axis-monomial-geodesics/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -W error -B research/two-axis-monomial-geodesics/independent_check.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/research_package.py --package research/two-axis-monomial-geodesics +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/check_research_commit.py --package research/two-axis-monomial-geodesics --check-source-history +``` + +Another CPython 3.12 executable may replace the local path. VERIFY.json +registers both scientific commands in warning-strict normal and optimized +modes, each with a sixty-second limit. Default runs write nothing. + +The primary checker uses literal actions on four basis addresses. It +enumerates 3,072 states and 24,576 labeled transitions, then replays a +shortest word for every state. It includes four endpoint-changing controls +and two exact-reason domain rejections. The separate checker uses binary +matrix and phase-polynomial parameters, generates the full normal-form +inventory and checks every polynomial transition against literal gate +matrices. Distance inequalities on every edge and a decreasing predecessor +for every nonidentity certify optimality. Three damaged certificates and +one unavailable inverse gate must be rejected. + +Both programs print generated receipts binding all seven package files and +the same sorted distance table. Its canonical SHA256 is +`4aec51eef32c395d364567018d10626bc96fe507b0591fa312ef3c3688ce1d4c`. +All four registered commands passed locally on CPython 3.12.15; the primary +checks took 0.045 and 0.047 seconds, and the separate checks each took +0.153 seconds. These are checker durations, not a runtime speedup claim. +The table can be exported outside the checkout and checked independently: + +```sh +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B research/two-axis-monomial-geodesics/verify.py --write-certificate /fresh/output/DISTANCES.json +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B research/two-axis-monomial-geodesics/independent_check.py --certificate /fresh/output/DISTANCES.json +``` + +The directory must exist; export refuses to overwrite an existing file. +Receipts are generated at execution, not hand-written or committed. The +normal-form checker does not import the primary program or any predecessor +module. These are separate implementations, not independent human review. + +## Scope, sources and limits + +This answers the n=2 first working example in Open next question 1 of +unpaidmoon #7286, head `a51fb99e3cf11c32d7318bd12c35f6d08e07927e`. +It does not alter or audit that pending package. The selected alphabet and +normal form are pinned through Cao Yifan / intqwq #4610's retained +[specialization](../final4610-independent-admission/SPECIALIZATION.md). +Its physical/compiler/native predecessors retain their credit. Classical +finite-group enumeration and shortest-path certificates are not new methods; +the exact synthesis distances and attaining words are the contribution. + +The formal-interface-lemma card changes scope to this finite synthesis +side result. Canonical base is `e54523517d0f03e58352e647c403a5af3e525a57`, +priority revision 8, selected #7000. Its source-binding orientation passed; +that is not a selected construction replay. The advance +[claim](https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19592092) +records the bounded question. Live open PRs, recent claims, local locks, +merged-PR searches and main-tree searches were checked before claiming. +These searches do not cover unpublished work or prove universal novelty. + +The result is for one column, two axes and exactly the eight unit-price +directed records. More axes, extra workspace, a different phase price, +projective equality or a different gate set may shorten recipes. The +operator identities tensor-lift, but shortestness at other column counts +is unclaimed. No physical tape saving, source-word installation, new +supplier, selected-frontier change, uniform all-n optimum or complete +multiplication theorem is established. Independent human and formal +proof-kernel review are unclaimed. No Lean, Docker or selected cold replay +is run; all five inherited assumptions retain their status. + +## Open next questions + +- Can two-axis geodesics replace explicit local subwords in one actual + selected normalizer? First find one literal contiguous subword, compare + its complete endpoint and retain all restoration and record prices. + This package does not search or install such substitutions. +- What is the three-axis directed diameter in the same alphabet? First + design a certified reduction or bounded enumeration of that larger + group. The present certificate gives no all-n diameter formula. + +## Implementation bounds + +Each group inventory contains 3,072 states. Every search is bounded by +3,072 state removals or eight layers, with eight generators per state. +An independent potential check visits exactly 24,576 labeled transitions; +failed-certificate controls may stop early. Each basis action has four +entries. Functions are below sixty lines. Explicit exceptions preserve +checks under -O; normal and optimized warning-strict commands are registered. +No runtime Git, network, subprocess, recursion or dynamic code evaluation +is used. Optional certificate input is a regular file capped at one MB. +Receipt reads cover seven regular files of at most one MB each. + +Power of Ten rule 3 has a managed-runtime deviation: CPython dynamically +allocates bounded integers, tuples, dictionaries and sets. The fixed group +and file bounds limit live state; fixed-buffer allocation is not claimed. +Rule 9 has a bounded callback deviation for two rejection controls. Their +only targets are the named local step and word evaluator, with no external +dispatch. No repository-wide analyzer configuration is changed. diff --git a/research/two-axis-monomial-geodesics/SOURCES.json b/research/two-axis-monomial-geodesics/SOURCES.json new file mode 100644 index 0000000000..6cdebfc533 --- /dev/null +++ b/research/two-axis-monomial-geodesics/SOURCES.json @@ -0,0 +1,24 @@ +{ + "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/final4610-independent-admission/SPECIALIZATION.md", + "usage": "provenance", + "git_blob": "7ee84b30892f7354e1c36611f1a5e9b082dc6147", + "sha256": "70430114f744108223bc1d44b98bc25b696c4b408b7b044c2a8bbdfdb434ac5c" + } + ] +} diff --git a/research/two-axis-monomial-geodesics/TASK.json b/research/two-axis-monomial-geodesics/TASK.json new file mode 100644 index 0000000000..72715870ab --- /dev/null +++ b/research/two-axis-monomial-geodesics/TASK.json @@ -0,0 +1,129 @@ +{ + "schema_version": 1, + "task_id": "formal-interface-lemma", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "formal-interface-lemma", + "question": "Can one uncovered interface implication be formalized with exact caller and certificate bindings?", + "starting_points": [ + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "research/gate-operand-parity-lean/README.md", + "research/staged544-certified-endpoint/README.md", + "research/unconditional-batched-crt/README.md" + ], + "methods": [ + "Formalize a missing boundary lemma identified by the selected review.", + "Audit a formal theorem-to-certificate binding independently." + ], + "acceptance_gate": "State the exact formalized proposition and remaining assumptions; avoid duplicate arithmetic formalizations already present.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Resolve the current selected review, separate complex/ordinary BIT/admitted BIT/outer budgets, and compare the card against live handoffs before starting. Historical ceilings require exact source/model equivalence.", + "scope": "Source-binding orientation only; not a scientific replay or all-size proof. Materialize selected inputs if this checkout is sparse." + }, + "first_experiment": "Write one missing statement with quantified hypotheses, actual caller and existing coverage. A compact-switch lemma is a candidate only after its mathematical contract is reviewed. Establish a bounded proof plan before a separately budgeted proof-assistant build; do not rerun large Lean jobs as orientation.", + "bottleneck_link": "A missing interface proof can reduce the conditional gap even if it does not change kappa.", + "allowed_variations": [ + "Narrow to one formal lemma or one theorem-to-certificate binding." + ], + "scope_change_triggers": [ + "Formalizing already-covered arithmetic and claiming the full multiplication theorem." + ], + "overlap_terms": [ + "hyperplane end", + "formal interface", + "Lean binding", + "3807", + "3857", + "4100", + "gate-operand-parity-lean", + "staged544-certified-endpoint", + "unconditional-batched-crt" + ], + "existing_checks": [ + { + "scope": "PR #3807: scoped gate-operand parity formalization.", + "evidence": "research/gate-operand-parity-lean/README.md", + "remaining": "Exact theorem-to-caller binding and genuinely uncovered interface lemmas.", + "status": "author-checked", + "source_commit": "4c3530f42a6abcc48e7a6bcffd6c901911dc8269", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #3857: certified real-power moment/endpoint arithmetic.", + "evidence": "research/staged544-certified-endpoint/README.md", + "remaining": "Uniform algorithmic implications, not another endpoint digit.", + "status": "author-checked", + "source_commit": "ef4315b8caa605e47a2515004845eb2d2ed71a86", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4100: compact-switch formalization proposed as future validation.", + "evidence": "research/unconditional-batched-crt/README.md", + "remaining": "Audit the statement and assumptions before a formal proof campaign.", + "status": "author-checked", + "source_commit": "337d04939571a637aeab54a0f58f54fde811663a", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + } + ] + }, + "scope_status": "changed", + "actual_scope": "Exact one-column shortest recipes and directed diameter in the two-axis affine-quadratic monomial record alphabet.", + "scope_change_reason": "The card is narrowed to a finite synthesis side result answering unpaidmoon PR7286 Open next question 1; no proof-assistant theorem or selected-assumption discharge is claimed.", + "bottleneck_link": "Shorter exact normalizer record lists can reduce fixed implementation constants. This finite side result supplies no recursive rank or kappa gain and no installed physical caller.", + "budget_minutes": 60, + "stop_rule": "Stop after the first original verified improvement, the six-record witness and exact diameter-eight certificate. Do not expand to three axes or source-word substitution.", + "outcome": "completed", + "evidence": "Literal-action breadth-first enumeration and separate polynomial-normal-form distance-potential certification of every state and labeled transition.", + "author": "Nick Petalas", + "ai_assistance": "Independent human and formal proof-kernel review are unclaimed.", + "open_questions": [ + { + "question": "Install one exact two-axis geodesic in an actual selected normalizer.", + "why_it_matters": "It could reduce an actual fixed record list.", + "first_step": "Pin one contiguous literal subword and compare its complete endpoint and prices.", + "blocked_by": "No source-word substitution or physical cost contract is supplied." + }, + { + "question": "Determine the three-axis directed diameter.", + "why_it_matters": "It tests whether the finite synthesis gain extends to a larger interface.", + "first_step": "Design a certified reduction or bounded group enumeration.", + "blocked_by": "The present certificate covers only two axes." + } + ], + "source_question": { + "pr": 7286, + "author": "unpaidmoon", + "head": "a51fb99e3cf11c32d7318bd12c35f6d08e07927e", + "question": "Open next question 1, n=2 shortest selected-primitive recipe", + "status": "cited question and witness, not replayed" + }, + "claim_url": "https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19592092", + "claim_type": "exact finite certificate", + "overlap": { + "searched_at": "2026-11-13T14:17:36Z", + "open_prs": 810, + "discussion_records": 7421, + "remote_complete_pagination": true, + "local_note_records": 222, + "head_note_records": 10178, + "local_complete": false, + "main_and_merged_terms": [ + "two-axis monomial", + "monomial diameter", + "monomial shortest synthesis", + "3072", + "affine quadratic synthesis", + "Clifford shortest records" + ], + "precommit_upstream": "e54523517d0f03e58352e647c403a5af3e525a57", + "limitations": "Sparse local notes, unpublished work and arbitrary historical diffs are not completely searched; targeted main-tree Git searches supplement the helper." + } +} diff --git a/research/two-axis-monomial-geodesics/VERIFY.json b/research/two-axis-monomial-geodesics/VERIFY.json new file mode 100644 index 0000000000..befa32d329 --- /dev/null +++ b/research/two-axis-monomial-geodesics/VERIFY.json @@ -0,0 +1,59 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 60, + "checks": "Complete literal-action shortest-path census and all attaining word replays." + }, + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-O", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 60, + "checks": "Complete literal-action shortest-path census and all attaining word replays." + }, + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "{package}/independent_check.py" + ], + "timeout_seconds": 60, + "checks": "Complete polynomial normal-form inventory, literal edge checks, distance potentials and rejection controls." + }, + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-O", + "-B", + "{package}/independent_check.py" + ], + "timeout_seconds": 60, + "checks": "Complete polynomial normal-form inventory, literal edge checks, distance potentials and rejection controls." + } + ] +} diff --git a/research/two-axis-monomial-geodesics/independent_check.py b/research/two-axis-monomial-geodesics/independent_check.py new file mode 100644 index 0000000000..0531e634a2 --- /dev/null +++ b/research/two-axis-monomial-geodesics/independent_check.py @@ -0,0 +1,221 @@ +"""Certify distances with normal forms, independently of the primary checker.""" + +import argparse +from collections import Counter +import hashlib +from itertools import product +import json +from pathlib import Path +import sys + + +GATES = ("C01", "C10", "X0", "X1", "S0", "S1", "CZ", "omega") +IDENTITY = (1, 2, 0, 0, 0, 0, 0) +LITERAL_GATES = ( + ((0, 3, 2, 1), (0, 0, 0, 0)), + ((0, 1, 3, 2), (0, 0, 0, 0)), + ((1, 0, 3, 2), (0, 0, 0, 0)), + ((2, 3, 0, 1), (0, 0, 0, 0)), + ((0, 1, 2, 3), (0, 1, 0, 1)), + ((0, 1, 2, 3), (0, 0, 1, 1)), + ((0, 1, 2, 3), (0, 0, 0, 2)), + ((0, 1, 2, 3), (1, 1, 1, 1)), +) + + +def need(condition, message): + if not condition: + raise ValueError(message) + + +def action(form): + r0, r1, b, a, c0, c1, q = form + permutation, phases = [], [] + for x in range(4): + y0 = ((r0 & x).bit_count() & 1) ^ (b & 1) + y1 = ((r1 & x).bit_count() & 1) ^ (b >> 1) + permutation.append(y0 + 2 * y1) + phases.append((a + c0 * (x & 1) + c1 * (x >> 1) + + 2 * q * (x & 1) * (x >> 1)) % 4) + return tuple(permutation), tuple(phases) + + +def key(form): + permutation, phases = action(form) + return "".join(map(str, permutation + phases)) + + +def polynomial_step(form, gate): + r0, r1, b, a, c0, c1, q = form + b0, b1 = b & 1, b >> 1 + u0, v0, u1, v1 = r0 & 1, r0 >> 1, r1 & 1, r1 >> 1 + if gate == "C01": + r1 ^= r0 + b ^= b0 << 1 + elif gate == "C10": + r0 ^= r1 + b ^= b1 + elif gate in ("X0", "X1"): + b ^= 1 if gate == "X0" else 2 + elif gate in ("S0", "S1"): + row, bit = (r0, b0) if gate == "S0" else (r1, b1) + u, v = row & 1, row >> 1 + a += bit + c0 += (1 - 2 * bit) * u + c1 += (1 - 2 * bit) * v + q ^= u * v + elif gate == "CZ": + a += 2 * b0 * b1 + c0 += 2 * (b0 * u1 + b1 * u0 + u0 * u1) + c1 += 2 * (b0 * v1 + b1 * v0 + v0 * v1) + q ^= (u0 * v1 + v0 * u1) & 1 + elif gate == "omega": + a += 1 + else: + raise ValueError("unknown polynomial gate") + return r0, r1, b, a % 4, c0 % 4, c1 % 4, q + + +def forms(): + result = [] + for r0, r1 in product(range(1, 4), repeat=2): + if r0 != r1: + for b, a, c0, c1, q in product(range(4), range(4), range(4), range(4), range(2)): + result.append((r0, r1, b, a, c0, c1, q)) + need(len(result) == 3072, "normal-form count") + return result + + +def unique_object(pairs): + need(len(pairs) <= 8, "too many object keys") + result = dict(pairs) + need(len(result) == len(pairs), "duplicate JSON key") + return result + + +def load_labels(path): + need(path.is_file() and not path.is_symlink(), "regular certificate required") + need(path.stat().st_size <= 1_000_000, "certificate too large") + data = json.loads(path.read_text(encoding="utf-8"), object_pairs_hook=unique_object) + need(set(data) == {"schema", "gates", "distances"}, "certificate fields") + need(data["schema"] == "two-axis-monomial-distances/1", "certificate schema") + need(data["gates"] == list(GATES), "directed gate alphabet") + rows = data["distances"] + need(isinstance(rows, list) and len(rows) == 3072, "certificate row count") + for row in rows: + need(isinstance(row, list) and len(row) == 2, "certificate row shape") + need(isinstance(row[0], str) and len(row[0]) == 8, "action code shape") + need(type(row[1]) is int and 0 <= row[1] <= 8, "distance label range") + result = dict(rows) + need(len(result) == 3072 and rows == sorted(rows), "unique sorted action codes") + return result + + +def generate_labels(universe): + by_key = {key(form): form for form in universe} + labels = {key(IDENTITY): 0} + layer = {key(IDENTITY)} + for depth in range(1, 9): + following_layer = set() + for old_key in layer: + form = by_key[old_key] + for gate in GATES: + new_key = key(polynomial_step(form, gate)) + if new_key not in labels: + labels[new_key] = depth + following_layer.add(new_key) + layer = following_layer + need(len(labels) == 3072, "eight layers cover the group") + return labels + + +def check_labels(labels, universe): + keys = {key(form) for form in universe} + need(len(keys) == 3072 and set(labels) == keys, "complete action inventory") + need(labels[key(IDENTITY)] == 0, "identity label") + need(sum(value == 0 for value in labels.values()) == 1, "unique zero label") + predecessor = {key(IDENTITY)} + comparisons = 0 + for form in universe: + p, phase = action(form) + before = labels[key(form)] + for index, gate in enumerate(GATES): + following = polynomial_step(form, gate) + gp, gphase = LITERAL_GATES[index] + literal = (tuple(gp[y] for y in p), + tuple((phase[x] + gphase[p[x]]) % 4 for x in range(4))) + need(action(following) == literal, "polynomial/literal transition") + after_key = key(following) + after = labels[after_key] + need(after <= before + 1, "edge distance inequality") + if after == before + 1: + predecessor.add(after_key) + comparisons += 1 + need(predecessor == keys, "distance-decreasing predecessor") + return comparisons + + +def word_endpoint(word): + form = IDENTITY + need(len(word) <= 8, "word length") + for gate in word: + form = polynomial_step(form, gate) + return key(form) + + +def rejection_controls(labels, universe): + altered = dict(labels) + altered["31023223"] = 5 + tests = [(altered, "edge distance inequality"), + ({**labels, key(IDENTITY): 1}, "identity label"), + ({k: v for k, v in labels.items() if k != "31023223"}, "complete action inventory")] + for candidate, reason in tests: + try: + check_labels(candidate, universe) + except ValueError as error: + need(str(error) == reason, "wrong certificate rejection") + else: + raise ValueError("invalid certificate accepted") + try: + polynomial_step(IDENTITY, "S0_inverse") + except ValueError as error: + need(str(error) == "unknown polynomial gate", "wrong gate rejection") + else: + raise ValueError("inverse record admitted") + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--certificate", type=Path) + args = parser.parse_args() + universe = forms() + labels = generate_labels(universe) if args.certificate is None else load_labels(args.certificate) + transitions = check_labels(labels, universe) + need(labels["31023223"] == 6 and labels["02133322"] == 8, "sharp labels") + need(word_endpoint(("C01", "X1", "C10", "S1", "omega", "omega")) == "31023223", + "six-record witness") + need(word_endpoint(("C01", "C10", "C01", "X0", "S0", "X0", "omega", "omega")) == "02133322", + "eight-record witness") + rejection_controls(labels, universe) + root = Path(__file__).resolve().parent + files = ("README.md", "PROOF.md", "TASK.json", "SOURCES.json", "VERIFY.json", + "verify.py", "independent_check.py") + hashes = {} + for name in files: + path = root / name + need(path.is_file() and not path.is_symlink(), "regular package file") + need(path.stat().st_size <= 1_000_000, "package file too large") + hashes[name] = hashlib.sha256(path.read_bytes()).hexdigest() + payload = {"schema": "two-axis-monomial-distances/1", "gates": list(GATES), + "distances": sorted([[name, value] for name, value in labels.items()])} + digest = hashlib.sha256(json.dumps(payload, sort_keys=True, separators=(",", ":")).encode()).hexdigest() + print(json.dumps({"result": "PASS_TWO_AXIS_MONOMIAL_POTENTIAL", "states": len(labels), + "transitions": transitions, "histogram": sorted(Counter(labels.values()).items()), + "diameter": max(labels.values()), "certificate_controls": 3, + "domain_controls": 1, "python": sys.version.split()[0], + "distance_certificate_sha256": digest, + "files_sha256": hashes}, sort_keys=True)) + + +if __name__ == "__main__": + main() diff --git a/research/two-axis-monomial-geodesics/verify.py b/research/two-axis-monomial-geodesics/verify.py new file mode 100644 index 0000000000..8d5aa53d71 --- /dev/null +++ b/research/two-axis-monomial-geodesics/verify.py @@ -0,0 +1,171 @@ +"""Exact shortest paths for the directed two-axis elementary record alphabet.""" + +import argparse +from collections import Counter, deque +import hashlib +import json +from pathlib import Path +import sys + + +GATES = ("C01", "C10", "X0", "X1", "S0", "S1", "CZ", "omega") +IDENTITY = ((0, 1, 2, 3), (0, 0, 0, 0)) +TARGET = "31023223" +FARTHEST = "02133322" +TARGET_WORD = ("C01", "X1", "C10", "S1", "omega", "omega") +FARTHEST_WORD = ("C01", "C10", "C01", "X0", "S0", "X0", "omega", "omega") +FILES = ("README.md", "PROOF.md", "TASK.json", "SOURCES.json", "VERIFY.json", + "verify.py", "independent_check.py") + + +def need(condition, message): + if not condition: + raise ValueError(message) + + +def step(state, gate): + """Left-compose one gate on its four literal basis-column images.""" + need(gate in GATES, "unknown gate") + permutation, phases = state + output, exponent = [], [] + for index in range(4): + y, p = permutation[index], phases[index] + bit0, bit1 = y & 1, y >> 1 + if gate == "C01": + y ^= bit0 << 1 + elif gate == "C10": + y ^= bit1 + elif gate == "X0": + y ^= 1 + elif gate == "X1": + y ^= 2 + elif gate == "S0": + p += bit0 + elif gate == "S1": + p += bit1 + elif gate == "CZ": + p += 2 * bit0 * bit1 + else: + p += 1 + output.append(y) + exponent.append(p % 4) + return tuple(output), tuple(exponent) + + +def code(state): + return "".join(str(value) for part in state for value in part) + + +def census(): + distance, parent = {IDENTITY: 0}, {} + pending = deque([IDENTITY]) + transitions = 0 + for _ in range(3072): + need(bool(pending), "group exhausted before 3072 states") + state = pending.popleft() + for gate in GATES: + following = step(state, gate) + transitions += 1 + if following not in distance: + need(len(distance) < 3072, "group exceeds 3072 states") + distance[following] = distance[state] + 1 + parent[following] = (state, gate) + pending.append(following) + need(not pending, "unprocessed states") + need(transitions == 24576, "incomplete edge census") + return distance, parent + + +def shortest_word(state, parents): + result = [] + for _ in range(8): + if state == IDENTITY: + break + state, gate = parents[state] + result.append(gate) + need(state == IDENTITY, "parent chain exceeds diameter") + return tuple(reversed(result)) + + +def execute(word): + need(len(word) <= 16, "word exceeds bounded fixture length") + state = IDENTITY + for gate in word: + state = step(state, gate) + return code(state) + + +def certificate(distance): + return {"schema": "two-axis-monomial-distances/1", + "gates": list(GATES), + "distances": sorted([[code(state), value] + for state, value in distance.items()])} + + +def rejected(action, message): + try: + action() + except ValueError as error: + need(str(error) == message, "unexpected rejection reason") + else: + raise ValueError("control was accepted: " + message) + + +def check_words(distance, parents): + by_code = {code(state): state for state in distance} + need(distance[by_code[TARGET]] == 6, "target distance") + need(distance[by_code[FARTHEST]] == 8, "farthest distance") + need(execute(TARGET_WORD) == TARGET, "six-record endpoint") + need(execute(FARTHEST_WORD) == FARTHEST, "eight-record endpoint") + lengths = Counter() + for state, value in distance.items(): + word = shortest_word(state, parents) + need(len(word) == value and execute(word) == code(state), "word replay") + lengths[value] += 1 + need(execute(TARGET_WORD[:-1]) != TARGET, "omitted absolute phase control") + need(execute(("C10",) + TARGET_WORD[1:]) != TARGET, "CNOT direction control") + need(execute(TARGET_WORD[:3] + ("S0",) + TARGET_WORD[4:]) != TARGET, + "phase-axis control") + need(execute(TARGET_WORD[:3] + ("S1",) * 3 + TARGET_WORD[4:]) != TARGET, + "directed S control") + rejected(lambda: step(IDENTITY, "S1_inverse"), "unknown gate") + rejected(lambda: execute(("omega",) * 17), "word exceeds bounded fixture length") + return sorted(lengths.items()) + + +def receipt(histogram, payload): + root = Path(__file__).resolve().parent + hashes = {} + for name in FILES: + path = root / name + need(path.is_file() and not path.is_symlink(), "missing regular package file") + need(path.stat().st_size <= 1_000_000, "package file too large") + hashes[name] = hashlib.sha256(path.read_bytes()).hexdigest() + return {"result": "PASS_TWO_AXIS_MONOMIAL_GEODESICS", "states": 3072, + "transitions": 24576, "histogram": histogram, "target_distance": 6, + "diameter": 8, "shortest_words_replayed": 3072, + "semantic_controls": 4, "domain_controls": 2, + "distance_certificate_sha256": hashlib.sha256(json.dumps( + payload, sort_keys=True, separators=(",", ":")).encode()).hexdigest(), + "python": sys.version.split()[0], "files_sha256": hashes} + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--write-certificate", type=Path) + args = parser.parse_args() + distance, parents = census() + expected = certificate(distance) + histogram = check_words(distance, parents) + need(histogram == list(enumerate((1, 8, 42, 162, 467, 884, 940, 475, 93))), + "distance distribution") + if args.write_certificate is not None: + with args.write_certificate.open("x", encoding="utf-8") as output: + output.write(json.dumps(expected, separators=(",", ":")) + "\n") + print("WROTE_DISTANCE_CERTIFICATE states=3072") + return + print(json.dumps(receipt(histogram, expected), sort_keys=True)) + + +if __name__ == "__main__": + main()