diff --git a/research/dyadic-correction-rank-gap/PROOF.md b/research/dyadic-correction-rank-gap/PROOF.md new file mode 100644 index 0000000000..57284a499e --- /dev/null +++ b/research/dyadic-correction-rank-gap/PROOF.md @@ -0,0 +1,184 @@ +# When a two-role field-rank optimum is dyadic + +Put D=Z[1/2]. Let a=(a1,a2) be a row in D^2 and b=(b1,b2)^T a +column in D^2 with `a*b=1`. Seek P in GL_2(D) with `a*P=e1^T` and +`P*e1=b`. Rank means rank over Q. The objective is rank(P-I). + +[PR #7654](https://github.com/CrocSwap/integer-mult-bounds/pull/7654) +proves the general minimum over a field and leaves dyadic attainment open. +[PR #6016](https://github.com/petalas/integer-mult-bounds/blob/d2df1a6e3caf20c47fff89e6064f3747016fb954/research/dyadic-basis-conditioning/PROOF.md) +already classifies the two-role completions by their unit determinant. +We use that parameterization to decide the different rank objective. +The parameterization and unit classification are credited source facts, +not new general algebra tools. The argument below is self-contained. + +## Exact classification + +Every compatible dyadic completion has the form + +```text +P(t) = [ b1 -a2*t ] t in D^* = { +/- 2^k : k in Z }. + [ b2 a1*t ] + +det P(t) = t, +det(P(t)-I) = (1-a1)*t + 1-b1. +``` + +The first endpoint fixes the first column. The second column is in the +one-dimensional kernel of a, so it is `t*(-a2,a1)^T`. Its determinant is +`t*(a*b)=t`. A dyadic matrix has a dyadic inverse exactly when its +determinant is a dyadic unit. This proves the parameterization in this +setting and its converse. + +The complete rank table is: + +| Condition | Minimum over Q | Minimum over D | Dyadic attaining t | +| --- | ---: | ---: | --- | +| a=e1^T and b=e1 | 0 | 0 | 1 | +| a1=b1=1, excluding the first row | 1 | 1 | 1 | +| Exactly one of a1,b1 equals 1 | 2 | 2 | 1 | +| a1!=1 and b1!=1, tau is a dyadic unit | 1 | 1 | tau | +| a1!=1 and b1!=1, tau is not a dyadic unit | 1 | 2 | 1 | + +Here tau=(b1-1)/(1-a1). It is nonzero in the last two rows. +The zero-rank case requires P=I and hence both endpoints in the first +row. Outside that case, rank one is equivalent to det(P-I)=0. +If both first coordinates are one, the displayed determinant is zero +for every allowed t. If exactly one is one, it is nonzero for every +nonzero t. Otherwise its unique zero is tau. Over Q that zero is a +legal nonzero determinant. Over D it is legal exactly when tau is a +unit. This proves every row, with no bounded exponent search. + +The field table also equals the specialization of PR #7654's formula: + +```text +1[a != e1^T] + 1[b != e1] - min(1[a1 != 1], 1[b1 != 1]). +``` + +Here pi=a, g=e1^T and d(e1)=b-e1. Thus `pi*d=1-a1` and +`g*d=b1-1`. The finite check compares this separate formula with the table. + +## A strict gap with integral coefficients + +Take a=e2^T=(0,1) and b=4e1+e2=(4,1)^T. Both are primitive and +`a*b=1`. The compatible matrices are + +```text +P(t) = [ 4 -t ], det(P(t)-I)=t-3. + [ 1 0 ] +``` + +The unique field-minimum completion is P(3). It has integer entries, +is invertible over Q, and has correction rank one. But its determinant +is 3, so its inverse has an odd denominator. It is not in GL_2(D). +Every dyadic completion has correction rank two. P(1) attains two +and has determinant one. Thus legal dyadic completion exists, while +its minimum correction rank is strictly larger than the field minimum. +This is not an infeasible or nonprimitive input contract. + +The fixed line of the rank-one candidate is `F=Q*(e1+e2)`. +The modules `D*e1`, `D*(4e1+e2)`, and `D*(e1+e2)` are each saturated. +However the source basis [e1,e1+e2] has determinant 1, while the target +basis [4e1+e2,e1+e2] has determinant 3. The latter spans a submodule +with quotient D/3D. Saturation of the individual modules does not make +their required sum saturated. This is the missing arithmetic step in +this example; a field basis extension alone cannot supply it. + +## An unbounded gap, including coupled extra coordinates + +Let m>=1 and n=2m+k with k>=0. Split the coordinates into X, Y and Z +of dimensions m, m and k. Impose only + +```text +P*e_i = 4e_i+f_i, f_i^T*P = e_i^T, 1<=i<=m, +P in GL_n(D), +``` + +where e_i is the i-th X vector and f_i is the i-th Y vector. The +other columns and rows are free except for these equations. The exact +minimum correction rank is m over Q and 2m over D. Thus the additive +gap can be arbitrarily large. Coupling different pairs or extra +coordinates does not remove it. + +Over Q the prescribed displacement columns 3e_i+f_i are independent, +so rank(P-I)>=m. The matrix with blocks [[4I,-3I],[I,0]] on X+Y and +identity on Z attains m and has determinant 3^m. + +For the dyadic lower bound reduce all coefficients modulo 3. This is +valid because powers of two are invertible modulo 3. A dyadic-unit +determinant remains nonzero, so the reduced matrix Pbar is invertible. +Let F=ker(Pbar-I). The dual equations imply F is contained in +H={ (x,y,z):x=y }, whose dimension is n-m. The reduced prescribed +image of X is B={ (x,x,0) }, an m-dimensional subspace of H. +If v in F lies in B, write `v=Pbar*s` with s in X. Then `Pbar*v=v` and +`Pbar*s=v`; injectivity gives s=v. But X intersects B only at zero. +Thus F intersects B only at zero. The dimension formula in H gives + +```text +dim F <= (n-m)-m, rank(Pbar-I) >= 2m. +``` + +Reduction modulo 3 cannot increase the rank of a dyadic matrix: +every minor that is zero over Q is zero in D and stays zero after +reduction. Hence rank_Q(P-I)>=rank_F3(Pbar-I)>=2m. This uses the +fixed-subspace method of PR #7654 at an odd-prime reduction; the +method and reduction principle are not claimed as new general tools. + +The matrix with blocks [[4I,-I],[I,0]] on X+Y and identity on Z has +determinant one and correction rank 2m. It attains the dyadic lower +bound. The m=1 result above is its first case. The lower bound admits +arbitrary changes on the extra coordinates; the attaining word chooses +to leave them unchanged. No physical workspace is free in this theorem. + +## Literal attaining word + +For arbitrary values x,y in a common chart, execute: + +```text +x <- x-y +y <- y+x +x <- x+3*y +``` + +The successive pairs are (x0-y0,y0), (x0-y0,x0), and +`(4*x0-y0,x0)`. Thus the word is exactly P(1). It uses three ADDs, +with coefficients -1,1,3. Its inverse uses the reversed list with +negated coefficients. No extra field, zero input, SCALE, odd division +or native MOVE is used. Extra coordinates are unchanged in this +attaining construction. For m pairs, apply these three ADDs to each pair, for 3m ADDs in total. +The word is an algebraic operation list, not a fixed-tape service or +a scalar-instruction optimum. + +## Verification and limits + +The verifier examines all 6561 two-by-two matrices with entries in +{-2,-3/2,-1,-1/2,0,1/2,1,3/2,2}. Of these, 2480 have a dyadic-unit +determinant. It derives each matrix's endpoint pair from its inverse, +and no matrix has rank below the classification. It also enumerates +all 308 normalized integer pairs in [-5,5]^4. The combined set has +928 distinct contracts. A constructed completion attains the exact +classified minimum for every contract; 336 have a strict field/dyadic +gap. Exact elimination checks ranks, and literal row operations check +the word and inverse for m=1 through 4 and k=0 through 3. A separate +finite-field check enumerates all 11330 admissible reduced completions +for (m,k)=(1,0),(1,1),(1,2),(2,0), with counts 2,48,11232,48. It +checks the rank floor even when the free blocks couple pairs and extra +coordinates. Six controls reject +nonunit determinants, odd denominators and omitted endpoint conditions. +The proofs above establish the unbounded statements. The finite checks +do not substitute for those proofs. + +This result answers a dyadic-attainment subcase of GQ08. General +higher-dimensional paired contracts, an actual helper cut, operation +optimality, coefficient/prefix range, physical delivery, native charts, +rounding, restoration in a full caller and the complete paid/target +invoice remain open. Correction rank is not itself an implementation +price. No kappa or selected-assumption change follows. + +Prepared by Ali Romman with substantial OpenAI Codex assistance. +Credit Nick Petalas for PR #7654's question and field formula and +PR #6016's completion parameterization, Ali Romman for PR #5611's +dyadic helper interface, and Dugongue for GQ08 in PR #5803. +No predecessor code was copied or replayed. The exact cited sources +serve as context; every proof and executable check here is self-contained. +Apache-2.0. Independent human and formal-kernel review are unclaimed. diff --git a/research/dyadic-correction-rank-gap/README.md b/research/dyadic-correction-rank-gap/README.md new file mode 100644 index 0000000000..ceaeb83d5b --- /dev/null +++ b/research/dyadic-correction-rank-gap/README.md @@ -0,0 +1,84 @@ +# Dyadic completion can require more correction rank + +The exact field minimum in [PR #7654](https://github.com/CrocSwap/integer-mult-bounds/pull/7654) +need not be attainable with a dyadic inverse. This package classifies +rank(P-I) for every normalized two-role dyadic row/column contract. +For m prescribed pairs, the contract `P*e_i=4e_i+f_i` and +`f_i^T*P=e_i^T` has minimum **m over Q and 2m over Z[1/2]**. +The lower bound permits arbitrary coupling with any extra coordinates. +At m=1 the field-minimum matrix has integer entries but determinant 3. +A three-ADD word per pair attains the dyadic minimum with determinant one. + +This is a scoped proof with exact finite corroboration. Read +[PROOF.md](PROOF.md), [verify.py](verify.py) and [RESULT.json](RESULT.json). +The complete two-role test depends on whether the single required +determinant is a dyadic unit; no bounded exponent search is used. +No new kappa, physical supplier or selected-assumption discharge is claimed. + +## Evidence and reproduction + +Use CPython 3.12 and its standard library from the repository root. + +```sh +python3.12 -I -W error -B research/dyadic-correction-rank-gap/verify.py +python3.12 -I -W error -B -O research/dyadic-correction-rank-gap/verify.py +python3.12 -B scripts/research_package.py --package research/dyadic-correction-rank-gap +python3.12 -B scripts/check_research_commit.py --package research/dyadic-correction-rank-gap --check-source-history --check-modes +``` + +Expected markers are PASS_DYADIC_CORRECTION_RANK_GAP, +PASS_REGISTERED_RESEARCH_PACKAGE and PASS_RESEARCH_COMMIT_BYTES. +The checks cover 6561 literal grid matrices, including 2480 dyadic +invertible matrices, all 308 normalized integer pairs in [-5,5]^4, +and 928 distinct contracts. The constructed completions attain every +classified minimum. There are 336 strict-gap contracts in this finite +union. The word and inverse pass exact matrix checks on 16 (pair-count, +extra-coordinate) shapes. All 11330 admissible matrices in four small +modular domains satisfy the rank floor, including coupled free blocks. +Six controls reject invalid completions or contracts. + +The written proof is uniform in the allowed dyadic coefficients, and +the separating family permits any number of pairs and extra coordinates. No +predecessor scientific replay, selected cold replay, Lean or Docker +run is required or claimed. Independent human and formal-kernel review +remain open. There are no external run-time inputs. + +## Current task and prior coverage + +Canonical main is `e54523517d0f03e58352e647c403a5af3e525a57`, with priority +revision 8 and selected PR #7000 unchanged. The [advance claim](https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19702329) +takes the released PR #7654 dyadic-attainment handoff. The current +baseline metadata check passed. The PR/Discussion overlap cache includes +both open and closed bodies; sparse local notes and unpublished work +remain coverage limits. + +[PR #6016](https://github.com/CrocSwap/integer-mult-bounds/pull/6016) +already gives the completion parameterization and optimizes conditioning. +The present result optimizes correction rank. PR #5904 concerns eligible +observation acquisition, and PR #6027 concerns common invariant lattices. +The new arithmetic obstruction does not replace any of those results. +[SOURCES.json](SOURCES.json) pins the task and selected record. The exact +context sources below are citations, not external executable dependencies. + +## Open next questions + +Which higher-dimensional paired contracts attain the field minimum over +Z[1/2]? Start with the sums of the prescribed and fixed modules; the +example shows that individually saturated modules can have a sum with +odd index. This question matters before an optimizer treats field rank +as a legal dyadic completion budget. A full criterion and an actual +source cut remain missing. The [task record](TASK.json) gives the first +step and blockers. Physical implementation, range/precision bounds and +the complete caller invoice remain separate obligations. + +## Credit and exact sources + +Prepared by Ali Romman with substantial OpenAI Codex assistance. +Nick Petalas supplied the field formula and dyadic question in +[PR #7654's proof](https://github.com/petalas/integer-mult-bounds/blob/0438595fadc4902fa20cb88aecc305b526193a99/research/primal-dual-completion-rank/PROOF.md) +and the known two-role parameterization in +[PR #6016's proof](https://github.com/petalas/integer-mult-bounds/blob/d2df1a6e3caf20c47fff89e6064f3747016fb954/research/dyadic-basis-conditioning/PROOF.md). +Ali Romman's [PR #5611 proof](https://github.com/aliromman/integer-mult-bounds/blob/c132f93acaee6dd8d5ee5006da0670dfef3e9362/research/dyadic-helper-basis-completion/PROOF.md) +supplies the dyadic helper interface. Dugongue posed GQ08 in +[PR #5803](https://github.com/CrocSwap/integer-mult-bounds/pull/5803). +No predecessor code was copied. New work is Apache-2.0. diff --git a/research/dyadic-correction-rank-gap/RESULT.json b/research/dyadic-correction-rank-gap/RESULT.json new file mode 100644 index 0000000000..c744672462 --- /dev/null +++ b/research/dyadic-correction-rank-gap/RESULT.json @@ -0,0 +1,144 @@ +{ + "complete_modular_completion_counts": { + "1,0": 2, + "1,1": 48, + "1,2": 11232, + "2,0": 48 + }, + "distinct_contracts": 928, + "family_pair_and_extra_shapes": [ + [ + 1, + 0 + ], + [ + 1, + 1 + ], + [ + 1, + 2 + ], + [ + 1, + 3 + ], + [ + 2, + 0 + ], + [ + 2, + 1 + ], + [ + 2, + 2 + ], + [ + 2, + 3 + ], + [ + 3, + 0 + ], + [ + 3, + 1 + ], + [ + 3, + 2 + ], + [ + 3, + 3 + ], + [ + 4, + 0 + ], + [ + 4, + 1 + ], + [ + 4, + 2 + ], + [ + 4, + 3 + ] + ], + "field_and_dyadic_minimum_counts": { + "0,0": 1, + "1,1": 427, + "1,2": 336, + "2,2": 164 + }, + "literal_add_word": [ + [ + 0, + 1, + "-1" + ], + [ + 1, + 0, + "1" + ], + [ + 0, + 1, + "3" + ] + ], + "literal_dyadic_invertible_matrices": 2480, + "literal_grid_matrices_examined": 6561, + "normalized_integer_pairs": 308, + "rejected_controls": [ + "integer nonunit", + "dropped dual", + "dropped primal", + "odd denominator", + "unnormalized pair", + "nondyadic pair" + ], + "status": "PASS_DYADIC_CORRECTION_RANK_GAP", + "strict_gap_witness": { + "column": [ + 4, + 1 + ], + "dyadic_determinant": 1, + "dyadic_matrix": [ + [ + 4, + -1 + ], + [ + 1, + 0 + ] + ], + "dyadic_minimum": 2, + "field_minimum": 1, + "rational_determinant": 3, + "rational_matrix": [ + [ + 4, + -3 + ], + [ + 1, + 0 + ] + ], + "row": [ + 0, + 1 + ] + } +} diff --git a/research/dyadic-correction-rank-gap/SOURCES.json b/research/dyadic-correction-rank-gap/SOURCES.json new file mode 100644 index 0000000000..5335fa97d9 --- /dev/null +++ b/research/dyadic-correction-rank-gap/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/dyadic-correction-rank-gap/TASK.json b/research/dyadic-correction-rank-gap/TASK.json new file mode 100644 index 0000000000..fad60f3841 --- /dev/null +++ b/research/dyadic-correction-rank-gap/TASK.json @@ -0,0 +1,83 @@ +{ + "schema_version": 1, + "task_id": "uniform-transfer-audit", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "uniform-transfer-audit", + "question": "Can one of the selected record's five inherited assumptions be proved at its actual caller?", + "starting_points": [ + "docs/research/current-priorities.md", + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md" + ], + "methods": [ + "Construct and independently check one source-bound instance of the stated first experiment.", + "Seek an exact counterexample or target-specific complete-budget obstruction to that same proposed change." + ], + "acceptance_gate": "Identify the proposition and what would change downstream; do not equate a finite replay with a universal proof.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Read revision 8, the selected review and live exact-source handoffs. Then follow this card's bounded first_experiment.", + "scope": "Source-bound orientation only, not a supplier replay or theorem proof." + }, + "first_experiment": "Choose one assumption ID (native_all_columns, owned_erasure, compiler, precision_tape, analytic_recovery), one quantified implication and exact dependency closure. Check current handoffs, including #5625 row reentry and #5707 root-prefix lowering, without treating their partial scope as the whole theorem. Prove or falsify that implication with a caller-bound argument; stop at the chosen obligation. Finite tests or root digits do not discharge an all-size statement.", + "bottleneck_link": "Judge the actual current supplier contract and complete signed target/paid bill; frozen-profile ceilings require an applicability proof.", + "allowed_variations": [ + "One exact source head, helper/cut region or quantified proposition and changed hypothesis; check live handoffs first. Different seeds are not different scopes." + ], + "scope_change_triggers": [ + "Changing source head, helper/cut domain, operation alphabet or caller boundary without recording the new scope.", + "Treating an archived proposal or local numerical pass as complete supplier admission." + ], + "overlap_terms": [ + "native_all_columns", + "owned_erasure", + "compiler", + "precision_tape", + "analytic_recovery" + ], + "existing_checks": [ + { + "scope": "PR #4100: proposed unconditional construction and finite checks, without independent acceptance.", + "evidence": "research/unconditional-batched-crt/README.md", + "remaining": "Independent proof audit of one caller-bound all-size implication; all other premises remain explicit.", + "status": "author-checked", + "source_commit": "337d04939571a637aeab54a0f58f54fde811663a", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "Selected PR5599: complete helper-subspace construction and independent caller replay; five framework assumptions remain.", + "evidence": "docs/research/pr-intake-evidence/pr5599-completion/PROOF-REVIEW.md", + "remaining": "The next experiment must identify uncovered source-specific work. Successor archive intake does not transfer this admission.", + "status": "reviewed", + "source_commit": "09dd0965711ca7eeb169057a420abab1c9052137", + "selected_record_sha256": "2a0220e866417774606e0f991e41b9c1d26b1f43b97857238cf478dbc7d330b5" + } + ] + }, + "scope_status": "changed", + "actual_scope": "Classify the minimum dyadic correction rank for normalized two-role dual pairs and prove an unbounded field-versus-dyadic gap with arbitrary coupled extra coordinates.", + "scope_change_reason": "The live PR7654 handoff leaves dyadic attainment open. This package resolves the two-role interface and a dimension-uniform obstruction, rather than a full selected transfer audit.", + "bottleneck_link": "A field-rank optimum can require an odd determinant and fail legal dyadic reversibility even for primitive compatible endpoints. The result prevents that arithmetic gap from being priced as a completed helper map.", + "budget_minutes": 60, + "stop_rule": "Stop at the two-role classification, the strict gap and its attaining word; do not expand to a physical caller without a complete invoice.", + "outcome": "completed", + "evidence": "PROOF.md; RESULT.json; literal matrix census, independent field formula, attaining completions, 16 word/inverse shapes, complete 11330-matrix modular checks and six rejection controls.", + "author": "Ali Romman", + "ai_assistance": "Substantial OpenAI Codex assistance; no independent human or formal-kernel review claimed.", + "open_questions": [ + { + "question": "Which higher-dimensional paired dyadic contracts attain the field minimum?", + "why_it_matters": "Field rank alone can understate the legal completion rank even when each prescribed module is saturated.", + "first_step": "Study the odd-prime indices of sums of prescribed and candidate fixed modules, starting from the displayed index-three example.", + "blocked_by": "A full arithmetic completion criterion and an actual source cut with complete implementation costs are absent." + } + ] +} diff --git a/research/dyadic-correction-rank-gap/VERIFY.json b/research/dyadic-correction-rank-gap/VERIFY.json new file mode 100644 index 0000000000..50f75d4853 --- /dev/null +++ b/research/dyadic-correction-rank-gap/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": "Exact dyadic unit/rank classification; full small matrix and normalized pair census; field formula; attaining words and inverse; six rejection controls." + }, + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "-O", + "{package}/verify.py" + ], + "timeout_seconds": 60, + "checks": "Exact dyadic unit/rank classification; full small matrix and normalized pair census; field formula; attaining words and inverse; six rejection controls." + } + ] +} diff --git a/research/dyadic-correction-rank-gap/verify.py b/research/dyadic-correction-rank-gap/verify.py new file mode 100644 index 0000000000..1528542679 --- /dev/null +++ b/research/dyadic-correction-rank-gap/verify.py @@ -0,0 +1,238 @@ +#!/usr/bin/env python3 +"""Check dyadic rank attainment and the strict-gap completion. + +Ali Romman, with substantial OpenAI Codex assistance. Apache-2.0. +""" +from collections import Counter +from fractions import Fraction as F +from itertools import product +import json +from pathlib import Path + +ROOT = Path(__file__).resolve().parent + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def power_two(n): + return n > 0 and n & (n-1) == 0 + + +def dyadic(x): + return power_two(F(x).denominator) + + +def unit(x): + x = F(x) + return power_two(abs(x.numerator)) and power_two(x.denominator) + + +def determinant(p): + return p[0][0]*p[1][1]-p[0][1]*p[1][0] + + +def rank(matrix): + a = [[F(x) for x in row] for row in matrix] + pivot = 0 + for column in range(len(a[0])): + found = next((i for i in range(pivot, len(a)) if a[i][column]), None) + if found is None: + continue + a[pivot], a[found] = a[found], a[pivot] + value = a[pivot][column] + a[pivot] = [x/value for x in a[pivot]] + for i in range(len(a)): + if i != pivot: + value = a[i][column] + a[i] = [x-value*y for x, y in zip(a[i], a[pivot])] + pivot += 1 + if pivot == len(a): + break + return pivot + + +def correction_rank(p): + return rank([[x-int(i == j) for j, x in enumerate(row)] for i, row in enumerate(p)]) + + +def rank_mod_three(matrix): + a = [[int(x) % 3 for x in row] for row in matrix] + pivot = 0 + for column in range(len(a[0])): + found = next((i for i in range(pivot, len(a)) if a[i][column]), None) + if found is None: + continue + a[pivot], a[found] = a[found], a[pivot] + a[pivot] = [(x*a[pivot][column]) % 3 for x in a[pivot]] + for i in range(len(a)): + if i != pivot: + value = a[i][column] + a[i] = [(x-value*y) % 3 for x, y in zip(a[i], a[pivot])] + pivot += 1 + if pivot == len(a): + break + return pivot + + +def completion(a, b, t): + return ((b[0], -t*a[1]), (b[1], t*a[0])) + + +def classify(a, b): + a, b = tuple(map(F, a)), tuple(map(F, b)) + require(len(a) == len(b) == 2 and all(dyadic(x) for x in (*a, *b)), 'dyadic pair') + require(sum(x*y for x, y in zip(a, b)) == 1, 'normalized pair') + if a == b == (1, 0): + return 0, 0, F(1) + if a[0] == b[0] == 1: + return 1, 1, F(1) + if a[0] == 1 or b[0] == 1: + return 2, 2, F(1) + t = (b[0]-1)/(1-a[0]) + return 1, (1 if unit(t) else 2), (t if unit(t) else F(1)) + + +def validate(a, b, p): + require(all(dyadic(x) for row in p for x in row), 'nondyadic coefficient') + require(unit(determinant(p)), 'nonunit determinant') + require(tuple(row[0] for row in p) == tuple(b), 'primal endpoint') + require(tuple(sum(a[i]*p[i][j] for i in range(2)) for j in range(2)) == (1, 0), + 'dual endpoint') + + +def matrix_word(n, instructions): + p = [[F(int(i == j)) for j in range(n)] for i in range(n)] + for target, source, coefficient in instructions: + p[target] = [x+coefficient*y for x, y in zip(p[target], p[source])] + return p + + +def verify(): + contracts = set() + literal_matrices = 0 + grid = [F(i, 2) for i in range(-4, 5)] + for entries in product(grid, repeat=4): + p = (entries[:2], entries[2:]) + det = determinant(p) + if not unit(det): + continue + a = (p[1][1]/det, -p[0][1]/det) + b = (p[0][0], p[1][0]) + contracts.add((a, b)) + _, required, _ = classify(a, b) + require(correction_rank(p) >= required, 'literal matrix below claimed minimum') + validate(a, b, p) + literal_matrices += 1 + integer_pairs = 0 + for values in product(range(-5, 6), repeat=4): + a, b = tuple(map(F, values[:2])), tuple(map(F, values[2:])) + if sum(x*y for x, y in zip(a, b)) == 1: + contracts.add((a, b)) + integer_pairs += 1 + cases = Counter() + for a, b in sorted(contracts): + field_min, dyadic_min, t = classify(a, b) + p = completion(a, b, t) + validate(a, b, p) + require(correction_rank(p) == dyadic_min, 'attaining completion rank') + published_field_formula = (int(a != (1, 0))+int(b != (1, 0)) + - min(int(a[0] != 1), int(b[0] != 1))) + require(field_min == published_field_formula, 'field formula') + field_t = (b[0]-1)/(1-a[0]) if a[0] != 1 and b[0] != 1 else F(1) + require(correction_rank(completion(a, b, field_t)) == field_min, + 'field attainment') + cases[(field_min, dyadic_min)] += 1 + a, b = (F(0), F(1)), (F(4), F(1)) + rational = completion(a, b, F(3)) + require(rational == ((4, -3), (1, 0)) and determinant(rational) == 3 + and correction_rank(rational) == 1, 'rational gap witness') + shapes = [] + for m, extra in product(range(1, 5), range(4)): + n = 2*m+extra + word = [(t, s, F(c)) for i in range(m) + for t, s, c in [(i, m+i, -1), (m+i, i, 1), (i, m+i, 3)]] + inverse = [(t, s, -c) for t, s, c in reversed(word)] + p = matrix_word(n, word) + rational = [[F(int(i == j)) for j in range(n)] for i in range(n)] + for i in range(m): + rational[i][i] = 4; rational[i][m+i] = -3 + rational[m+i][i] = 1; rational[m+i][m+i] = 0 + for matrix in (p, rational): + require(all(matrix[j][i] == 4*int(j == i)+int(j == m+i) + and matrix[m+i][j] == int(j == i) + for i in range(m) for j in range(n)), 'family endpoint') + require(correction_rank(p) == 2*m and correction_rank(rational) == m, + 'family rank gap') + q = matrix_word(n, inverse) + require(all(sum(p[i][k]*q[k][j] for k in range(n)) == int(i == j) + for i in range(n) for j in range(n)), 'inverse word') + shapes.append([m, extra]) + modular_counts = {} + for m, extra in [(1, 0), (1, 1), (1, 2), (2, 0)]: + size, n, count = m+extra, 2*m+extra, 0 + for entries in product(range(3), repeat=size*size): + jmatrix = [entries[i*size:(i+1)*size] for i in range(size)] + if rank_mod_three(jmatrix) != size: + continue + p = [[0]*n for _ in range(n)] + for i in range(m): + p[i][i] = p[m+i][i] = 1 + rows = list(range(m))+list(range(2*m, n)) + for i, row in enumerate(rows): + for j in range(size): + p[row][m+j] = jmatrix[i][j] + require(rank_mod_three(p) == n, 'complete modular parameterization') + require(rank_mod_three([[x-int(i == j) for j, x in enumerate(row)] + for i, row in enumerate(p)]) >= 2*m, + 'modular fixed-space floor') + count += 1 + modular_counts[f'{m},{extra}'] = count + rational = completion(a, b, F(3)) + word = [(0, 1, F(-1)), (1, 0, F(1)), (0, 1, F(3))] + controls = [ + ('integer nonunit', a, b, rational), + ('dropped dual', a, b, ((F(4), F(-9)), (F(1), F(-2)))), + ('dropped primal', a, b, ((F(1), F(0)), (F(0), F(1)))), + ('odd denominator', (F(-2), F(5)), (F(2), F(1)), + ((F(2), F(-5, 3)), (F(1), F(-2, 3)))), + ] + for name, row, column, p in controls: + try: + validate(row, column, p) + except ValueError: + pass + else: + raise ValueError('accepted control: '+name) + for bad in [((0, 0), (1, 0)), ((F(1, 3), 0), (3, 0))]: + try: + classify(*bad) + except ValueError: + pass + else: + raise ValueError('accepted invalid pair') + result = { + 'status': 'PASS_DYADIC_CORRECTION_RANK_GAP', + 'literal_grid_matrices_examined': len(grid)**4, + 'literal_dyadic_invertible_matrices': literal_matrices, + 'normalized_integer_pairs': integer_pairs, + 'distinct_contracts': len(contracts), + 'field_and_dyadic_minimum_counts': {f'{x},{y}': count for (x, y), count in sorted(cases.items())}, + 'strict_gap_witness': {'row': [0, 1], 'column': [4, 1], + 'rational_matrix': [[4, -3], [1, 0]], + 'rational_determinant': 3, 'field_minimum': 1, + 'dyadic_matrix': [[4, -1], [1, 0]], + 'dyadic_determinant': 1, 'dyadic_minimum': 2}, + 'literal_add_word': [[t, s, str(c)] for t, s, c in word], + 'family_pair_and_extra_shapes': shapes, + 'complete_modular_completion_counts': modular_counts, + 'rejected_controls': [name for name, *_ in controls]+['unnormalized pair', 'nondyadic pair'], + } + require(json.loads((ROOT/'RESULT.json').read_text()) == result, 'retained receipt') + return result + + +if __name__ == '__main__': + print(json.dumps(verify(), sort_keys=True, indent=2))