diff --git a/research/odd-kernel-coeff-bit-tariff/CERTIFICATE.json b/research/odd-kernel-coeff-bit-tariff/CERTIFICATE.json new file mode 100644 index 0000000000..34d3fe0961 --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/CERTIFICATE.json @@ -0,0 +1,63 @@ +{ + "claim": { + "odd_baseline_strictly_exceeds_dyadic_on_grid": true, + "odd_fused_strictly_exceeds_dyadic_on_grid": true, + "tables_never_pay_on_this_tariff": true, + "typed_child_xor_counts_identical": true + }, + "counts": { + "grid_rows": 198, + "odd_baseline_exceeds_dyadic": 165, + "odd_fused_exceeds_dyadic": 165 + }, + "j_max": 32, + "kappa_decimal": "0.001672660197076918", + "kappa_fraction": "836330098538459/500000000000000000", + "kernels": [ + 1, + 3, + 5, + 7, + 9, + 15 + ], + "no_new_kappa": true, + "odd_kernels": [ + 3, + 5, + 7, + 9, + 15 + ], + "schema_version": 1, + "spot": { + "T_fused_j2": { + "1": 102, + "15": 168, + "3": 126, + "5": 145, + "7": 147, + "9": 166 + }, + "T_word": { + "1": 45, + "15": 64, + "2": 38, + "3": 49, + "4": 32, + "5": 55, + "7": 56 + }, + "non_monotone": { + "T(1)": 45, + "T(2)": 38, + "T(4)": 32 + } + }, + "status": "PASS_ODD_KERNEL_COEFF_BIT_TARIFF", + "tariff": { + "definition": "T_word(k) = sum over affine diagonal/control coefficients c=p/q in lowest terms of bit_length(|p|)+bit_length(q); T_fused(q,j)=2*T_word(q*2^j)+T_word(q*2^{j+1}); T_baseline(q,j)=4*T_word(q*2^j).", + "name": "ADDRESS_affine_coeff_num_den_bit_sum", + "unit_coeff_bits": 20 + } +} diff --git a/research/odd-kernel-coeff-bit-tariff/MASTER-HANDOFF.md b/research/odd-kernel-coeff-bit-tariff/MASTER-HANDOFF.md new file mode 100644 index 0000000000..2cf16cd35f --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/MASTER-HANDOFF.md @@ -0,0 +1,48 @@ +# MASTER-HANDOFF — odd-kernel-coeff-bit-tariff + +## Claim (one sentence) + +Under the named ADDRESS affine coefficient-bit tariff, every certified odd +kernel `q∈{3,5,7,9,15}` strictly exceeds the dyadic fused and baseline bills +on `j=0..32`, so larger-`q` coefficient tables never pay for themselves +despite identical typed child/XOR counts (answers #2687 OQ2). + +## Closest prior + +- #2687 / `research/odd-kernel-query-pair` — exclusion pattern; OQ2 left open +- PR840 / `research/dyadic-query-pair` — dyadic fusion and ADDRESS shape +- triadic-query-pair — kernel-3 specialization feeding #2687 + +## New checkable fact + +Named tariff `T_word` / `T_fused` / `T_baseline`; closed form; prior +`address_word` cross-check; `165+165` strict odd-over-dyadic exceedances; +non-monotonicity of `T_word` (`32<38<45` at `|k|=4,2,1`). + +## Evidence commands + +```sh +python3.12 -I -B research/odd-kernel-coeff-bit-tariff/verify.py +python3.12 -I -O -Werror -B research/odd-kernel-coeff-bit-tariff/verify.py +python3.12 -I -B research/odd-kernel-coeff-bit-tariff/independent.py +python3.12 -I -B research/odd-kernel-coeff-bit-tariff/test_package.py +python3.12 -B scripts/research_package.py --package research/odd-kernel-coeff-bit-tariff +``` + +## Soft-overlap vs leave-alones + +Clear of flag-0 tail / stock envelope / gate-operand / C5 / side-correction / +present-head / groups B–D native clusters. Touches only the #840 / #2687 +odd-kernel cascade at the unanswered coefficient-bit OQ. Soft-overlap with +#2687 is intentional predecessor pin of `program.py`, not a typed-invoice +reprint. + +## Attribution + +Author Wentao Li ``. Neutral AI assistance disclosure. +No `Co-authored-by: Victor Li`. No CrocSwap PR from this worker (master publishes). + +## Disposition + +Ready for master independent review / publish decision. Kappa unchanged +(`0.001672660197076918`). diff --git a/research/odd-kernel-coeff-bit-tariff/NOTICE.md b/research/odd-kernel-coeff-bit-tariff/NOTICE.md new file mode 100644 index 0000000000..e1bf8fa72e --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/NOTICE.md @@ -0,0 +1,17 @@ +# Notice — research/odd-kernel-coeff-bit-tariff + +Prepared by Wentao Li (GitHub VictorLiwentao, X @Is__Victor) with substantial +AI assistance. New material is Apache-2.0 under the repository LICENSE. + +Predecessor credit: + +- Wentao Li / #2687 (`research/odd-kernel-query-pair`) — general odd-kernel + exclusion pattern; OQ2 (coefficient-table bit tariff) answered here. +- Wentao Li / PR840 (`research/dyadic-query-pair`) — three-query dyadic fusion + and ADDRESS lowering shape. +- Pending fork package `research/triadic-query-pair/` — kernel-3 specialization + feeding #2687. +- Karl Appel / applecrusher / PR521 — native unipotent ADDRESS query lowering. +- commdata2338 / PR677 — completed DATA-shear boundaries without a private row. + +No independent human review is claimed. No selected frontier or kappa change. diff --git a/research/odd-kernel-coeff-bit-tariff/PROOF.md b/research/odd-kernel-coeff-bit-tariff/PROOF.md new file mode 100644 index 0000000000..78af6543e1 --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/PROOF.md @@ -0,0 +1,92 @@ +# Coefficient-bit tariff for odd-kernel ADDRESS lowerings + +## Claim + +Let `address_word(k)` be the seven-event ADDRESS lowering of +`M(k)=I+(k/4)sr^T` used by PR840 / `#2687`. Define the **coefficient-bit +tariff** + +```text +T_word(k) = Σ_{c = p/q in affine coeffs} ( bit_length(|p|) + bit_length(q) ) +``` + +with each `c` in lowest terms. For kernel `q` and dyadic index `j`, + +```text +T_fused(q,j) = 2·T_word(q·2^j) + T_word(q·2^{j+1}) +T_baseline(q,j) = 4·T_word(q·2^j) +``` + +matching the three-query fused and four-query separate power lists. Then for +every certified odd kernel `q ∈ {3,5,7,9,15}` and every `j ∈ {0,…,32}`: + +```text +T_fused(q,j) > T_fused(1,j) +T_baseline(q,j) > T_baseline(1,j). +``` + +Typed child / affine / XOR counts remain `3/18/2` (fused) and `4/24/4` +(baseline) independent of `q`. Therefore, on this named tariff, larger-`q` +coefficient tables never pay for themselves against the dyadic path. + +Selected kappa is unchanged. + +## Closed form for `T_word` + +The affine coefficients of `address_word(k)` are ten units `±1` together with + +```text +a, 1+a, -a, -a, -1/a, 1/a - 1 where a = k/4. +``` + +Each unit contributes `bit_length(1)+bit_length(1)=2`, so + +```text +T_word(k) = 20 + bits(a) + bits(1+a) + 2·bits(a) + bits(4/k) + bits((4-k)/k) +``` + +with `bits(p/q)=bit_length(|p|)+bit_length(q)`. The formula is sign-invariant +(`T_word(k)=T_word(-k)`) and matches direct enumeration on `|k|≤64`. + +## Non-monotonicity + +`T_word` is **not** monotone in `|k|`: + +```text +T_word(4) = 32 < T_word(2) = 38 < T_word(1) = 45. +``` + +A word-level “larger `|k|` ⇒ larger bill” argument is false. The claim is the +fused/baseline program comparison on the certified kernel grid, not word +monotonicity. + +## Grid evidence + +For each of the `5×33 = 165` odd pairs `(q,j)` the verifier checks fused and +baseline strict exceedance separately (`165` comparisons each). Spot values at `j=2`: + +| q | T_fused(q,2) | T_baseline(q,2) | +|---:|---:|---:| +| 1 | 102 | 128 | +| 3 | 126 | 160 | +| 5 | 145 | 184 | +| 7 | 147 | 188 | +| 9 | 166 | 212 | +| 15 | 168 | 216 | + +Fusion saves coefficient bits for every kernel, but the odd fused bill remains +strictly above the dyadic fused bill on the whole grid. + +## Relation to `#2687` / PR840 + +`#2687` proved the excluded-prime admission pattern and recorded identical +typed invoices for all odd `q`, leaving open whether coefficient-table +bit-sizes can still favor some `q` under a concrete physical tariff. This +package attaches one named tariff to the same `address_word` and answers that +obligation in the negative on `j=0..32` for the certified kernels. + +## What this does not claim + +- No alternate tariff (max-height only, packing, modulus-dependent encoding). +- No BIT-supplier hosting bill (still `#2687` OQ1). +- No new kappa and no production adoption. diff --git a/research/odd-kernel-coeff-bit-tariff/README.md b/research/odd-kernel-coeff-bit-tariff/README.md new file mode 100644 index 0000000000..2036af8d37 --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/README.md @@ -0,0 +1,83 @@ +# Odd-kernel coefficient-bit tariff (answers #2687 OQ2) + +**Card `connector-alphabet-change`, priority revision 6**, refined to open +question 2 of +[#2687](https://github.com/CrocSwap/integer-mult-bounds/pull/2687) +(`research/odd-kernel-query-pair`). No new kappa +(`0.001672660197076918`). + +`#2687` showed that every odd kernel `q` has the same typed fused invoice as +the dyadic case (`4→3` children, `24→18` affine, `4→2` XOR) and left open +whether coefficient-table bit-sizes can still favor some larger `q` under a +concrete physical tariff. This package attaches one named tariff to the PR840 +`address_word` lowering and answers that obligation. + +**Tariff.** For each affine diagonal/control coefficient `c=p/q` in lowest +terms, charge `bit_length(|p|)+bit_length(q)`. Summing over `address_word(k)` +gives `T_word(k)`. Program bills are + +```text +T_fused(q,j) = 2·T_word(q·2^j) + T_word(q·2^{j+1}) +T_baseline(q,j) = 4·T_word(q·2^j) +``` + +**Result.** On the certified kernels `{1,3,5,7,9,15}` and every +`j∈{0,…,32}`, every odd kernel strictly exceeds the dyadic fused and baseline +bills (`165+165` comparisons). `T_word` is not monotone in `|k|` +(`T(4)=32 < T(2)=38 < T(1)=45`), so the claim is the program comparison, not +a word-level size argument. Larger-`q` tables never pay for themselves on this +tariff. + +```sh +python3.12 -I -B research/odd-kernel-coeff-bit-tariff/verify.py +``` + +Expected: + +```text +PASS_ODD_KERNEL_COEFF_BIT_TARIFF kernels=[1, 3, 5, 7, 9, 15] j=0..32 odd_fused_exceeds_dyadic=165 odd_baseline_exceeds_dyadic=165 no_new_kappa +``` + +## Evidence + +- Closed-form `T_word` (ten unit coeffs + six variable rationals in `a=k/4`) + matches enumeration on `|k|≤64` and the byte-pinned `#2687` `address_word`. +- Grid: odd fused/baseline bills exceed dyadic at every `(q,j)` above. +- Spot `j=2`: dyadic fused `102` vs odd `{126,145,147,166,168}`. +- Fusion saves bits for every kernel but does not overturn odd `>` dyadic. +- Non-monotonicity control and inflated-dyadic adversarial control. + +Default verify is read-only against `CERTIFICATE.json`. Admission uses +`need()` and stays enforced under `python -O`. Explicit `--write` regenerates +the certificate only. + +## Reproduce + +```sh +python3.12 -I -B research/odd-kernel-coeff-bit-tariff/verify.py +python3.12 -I -O -Werror -B research/odd-kernel-coeff-bit-tariff/verify.py +python3.12 -I -B research/odd-kernel-coeff-bit-tariff/independent.py +python3.12 -I -B research/odd-kernel-coeff-bit-tariff/test_package.py +python3.12 -B scripts/research_package.py --package research/odd-kernel-coeff-bit-tariff +``` + +## Open next questions + +1. **Does any alternate physical tariff ever make a certified odd kernel beat + dyadic at some `j`?** First step: name max-height / packing / modulus-dependent + encoding on the same coefficients and replay the grid. Blocked by: no + alternate tariff admitted here. +2. **Can an admitted BIT supplier host a small odd-kernel shear with a favorable + fully charged bill versus dyadic?** First step: one exact source-return + boundary with routing, precision and dispatch. Blocked by: still `#2687` OQ1; + not constructed here. + +## Credit + +Credit `#2687` / `research/odd-kernel-query-pair` (OQ2 answered), PR840 / +`research/dyadic-query-pair`, the pending triadic kernel-3 package, and +PR521/PR677 ADDRESS / DATA-shear lineage. Predecessor notices are unchanged. + +Prepared by Wentao Li ([VictorLiwentao](https://github.com/VictorLiwentao), +[@Is__Victor](https://x.com/Is__Victor)) with substantial AI assistance, under +Apache-2.0. No independent human review is claimed. No new kappa. diff --git a/research/odd-kernel-coeff-bit-tariff/SOURCES.json b/research/odd-kernel-coeff-bit-tariff/SOURCES.json new file mode 100644 index 0000000000..79b17d5010 --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/SOURCES.json @@ -0,0 +1,48 @@ +{ + "schema_version": 1, + "base_commit": "20ecf2891d80b5acf18d980b2164fb44ea7faa90", + "files": [ + { + "path": "research/odd-kernel-query-pair/program.py", + "usage": "input", + "git_blob": "93699aec204ee787418254b10e50a1dd84e8bfc3", + "sha256": "f167826e66d39cd448651f7cdb27ba150a846786b2e1a9a2c7dad5100028a7c2", + "size_bytes": 6332 + }, + { + "path": "research/odd-kernel-query-pair/README.md", + "usage": "provenance", + "git_blob": "5b79bbd87534804fff944ca8de5e7ce88a07e9c9", + "sha256": "b7c1cf0518eff8cc7c9682e9038cb78d93ce9cae7b2d44f40a8286875fb019a2", + "size_bytes": 4258 + }, + { + "path": "research/odd-kernel-query-pair/TASK.json", + "usage": "provenance", + "git_blob": "1834f1fb4e7727708f9c89104fff50cd48281332", + "sha256": "886925d67cd1f52dc00591574217751bbe9bffd82956c6cefbc35267b32c8dfb", + "size_bytes": 4576 + }, + { + "path": "research/dyadic-query-pair/PROOF.md", + "usage": "provenance", + "git_blob": "aaba3e501de1f761c783ec7f0dc9307ef45ab5d7", + "sha256": "9a5ce93b866371189c797fbe8837c6a0bd22c5cf71ed84d60b9ae1c22a5ec83a", + "size_bytes": 10567 + }, + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "b1fea0c94436b236cc2b7d41a7be032811b94c81", + "sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129", + "size_bytes": 10725 + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "67f085acd86acd7d4e03922d9cf4b26bca66fed5", + "sha256": "47b42433f5a85809a3aadd29c2c339da2c6ed728e4f7762df6b88bccb7874cf0", + "size_bytes": 58553 + } + ] +} diff --git a/research/odd-kernel-coeff-bit-tariff/TASK.json b/research/odd-kernel-coeff-bit-tariff/TASK.json new file mode 100644 index 0000000000..13b11957e5 --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/TASK.json @@ -0,0 +1,68 @@ +{ + "schema_version": 1, + "task_id": "connector-alphabet-change", + "priority_revision": 6, + "base_commit": "20ecf2891d80b5acf18d980b2164fb44ea7faa90", + "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": "Answer #2687 (odd-kernel-query-pair) OQ2: under the named ADDRESS affine coefficient-bit tariff T_word / T_fused / T_baseline, every certified odd kernel q in {3,5,7,9,15} strictly exceeds the dyadic q=1 bill at each j in 0..32, so larger-q coefficient tables never pay for themselves despite identical typed child/XOR counts.", + "scope_change_reason": "The drawn connector-alphabet card is redirected to the unanswered coefficient-table physical-tariff obligation left open by #2687 after the general odd-kernel exclusion pattern; this is a scoped #840-style cost lemma on the same ADDRESS lowering, not another typed child/XOR census.", + "bottleneck_link": "Identical typed invoices for odd kernels leave open whether coefficient-table growth can still favor some q under a concrete bit tariff; closing that obligation prevents a false physical win from typed counts alone.", + "budget_minutes": 60, + "stop_rule": "Stop after the named tariff, closed-form T_word, prior-program cross-check, 165+165 grid exceedances, independent replay and package controls. No supplier hosting search and no new kappa.", + "outcome": "completed", + "evidence": "CERTIFICATE.json, PROOF.md, tariff.py, verify.py, independent.py and test_package.py. On j=0..32 every odd kernel exceeds dyadic fused and baseline bills (165+165); T_word is not monotone in |k| (T(4)=32 < T(2)=38 < T(1)=45).", + "author": "Wentao Li", + "ai_assistance": "Substantial AI assistance for reading #2687 OQ2, deriving the coefficient-bit tariff, implementing the verifier and controls, and writing this package.", + "open_questions": [ + { + "question": "Does any alternate physical tariff (max-height only, tape-cell packing, or modulus-dependent encoding) ever make a certified odd kernel beat dyadic at some j?", + "why_it_matters": "This package fixes one named num+den bit-sum tariff; a different cost model could reorder kernels.", + "first_step": "Name the alternate tariff on the same address_word coefficients and replay the j=0..32 grid.", + "blocked_by": "No alternate tariff is admitted here." + }, + { + "question": "Can an admitted BIT supplier host a small odd-kernel shear with a favorable fully charged bill versus dyadic after routing, precision and dispatch?", + "why_it_matters": "Coefficient-bit obstruction is local to ADDRESS tables; supplier hosting remains #2687 OQ1.", + "first_step": "Trace one exact source-return boundary and price routing against the dyadic PR840 path.", + "blocked_by": "No hosted instance is constructed here." + } + ] +} diff --git a/research/odd-kernel-coeff-bit-tariff/VERIFY.json b/research/odd-kernel-coeff-bit-tariff/VERIFY.json new file mode 100644 index 0000000000..efcf1eeaab --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/VERIFY.json @@ -0,0 +1,53 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/odd-kernel-query-pair/program.py" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Source pins; closed-form T_word; prior program cross-check; 165 odd fused and baseline exceedances on j=0..32; certificate admission." + }, + { + "argv": [ + "{python}", + "-I", + "-O", + "-Werror", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "need() admission remains enforced under -O; identical PASS marker." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/independent.py" + ], + "timeout_seconds": 60, + "checks": "Independent closed-form fused bills; 165 exceedances; match local tariff.py." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/test_package.py" + ], + "timeout_seconds": 180, + "checks": "Duplicate JSON keys; temp certificate corruption rejected; package files unchanged after read-only verify; -O -Werror control." + } + ] +} diff --git a/research/odd-kernel-coeff-bit-tariff/independent.py b/research/odd-kernel-coeff-bit-tariff/independent.py new file mode 100644 index 0000000000..cbda166cab --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/independent.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 +"""Independent replay of the coefficient-bit tariff lemma (no verify import). + +Rebuilds T_word from the closed-form variable coefficients and checks that +every odd kernel on j=0..32 strictly exceeds the dyadic fused bill. +Prepared by Wentao Li with substantial AI assistance. Apache-2.0. +""" +from __future__ import annotations + +from fractions import Fraction +from pathlib import Path + +HERE = Path(__file__).resolve().parent +MARKER = ( + "PASS_ODD_KERNEL_COEFF_BIT_TARIFF_INDEPENDENT " + "kernels=[1, 3, 5, 7, 9, 15] j=0..32 " + "odd_fused_exceeds_dyadic=165 no_new_kappa" +) +ODD = (3, 5, 7, 9, 15) +J_MAX = 32 + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +def bits(value): + value = Fraction(value) + return abs(value.numerator).bit_length() + value.denominator.bit_length() + + +def T_word(k): + a = Fraction(k, 4) + variable = (a, 1 + a, -a, -a, -1 / a, 1 / a - 1) + return 20 + sum(bits(c) for c in variable) + + +def T_fused(j, q): + a = q * (1 << j) + return 2 * T_word(a) + T_word(2 * a) + + +def main(): + need(T_word(4) == 32 and T_word(2) == 38 and T_word(1) == 45, + "non-monotone spot") + exceeds = 0 + for j in range(0, J_MAX + 1): + dy = T_fused(j, 1) + for q in ODD: + bill = T_fused(j, q) + need(bill > dy, f"q={q} j={j}") + exceeds += 1 + need(exceeds == 165, "165 comparisons") + # Cross-check local tariff.py closed form without importing verify. + import runpy + + tariff = runpy.run_path(str(HERE / "tariff.py")) + for j in (0, 2, 8, 16, 32): + for q in (1, 3, 15): + need(T_fused(j, q) == tariff["T_fused"](j, q), "match tariff module") + print(MARKER) + + +if __name__ == "__main__": + main() diff --git a/research/odd-kernel-coeff-bit-tariff/tariff.py b/research/odd-kernel-coeff-bit-tariff/tariff.py new file mode 100644 index 0000000000..c4028f56c6 --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/tariff.py @@ -0,0 +1,95 @@ +"""Coefficient-bit tariff for PR840 / odd-kernel ADDRESS query lowerings. + +Tariff T_word(k) sums bit_length(|numerator|) + bit_length(denominator) over +every affine diagonal and control coefficient in address_word(k), reduced. + +Prepared by Wentao Li with substantial AI assistance. Apache-2.0. +""" +from __future__ import annotations + +from fractions import Fraction + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +def odd_kernel_power(j, sign=1, kernel=1): + need(type(j) is int and j >= 0, "nonnegative dyadic index") + need(type(sign) is int and sign in (-1, 1), "integer sign") + need(type(kernel) is int and kernel > 0 and kernel % 2 == 1, "positive odd kernel") + return sign * kernel * (1 << j) + + +def address_word(k): + """Seven events for M(k)=I+(k/4) s r^T; identical shape to odd-kernel-query-pair.""" + need(type(k) is int and k != 0, "nonzero integer query power") + a = Fraction(k, 4) + return ( + ("affine", 2, Fraction(1), ((0, Fraction(-1)),)), + ("affine", 3, Fraction(1), ((0, Fraction(1)),)), + ("affine", 5, a, ((0, 1 + a), (2, -a), (3, -a))), + ("child", 0, 5), + ("affine", 2, Fraction(1), ((0, Fraction(1)),)), + ("affine", 3, Fraction(1), ((0, Fraction(-1)),)), + ("affine", 5, -1 / a, ((0, 1 / a - 1), (2, Fraction(1)), + (3, Fraction(1)))), + ) + + +def coeff_bit_length(value): + """Bits charged for one reduced rational coefficient.""" + value = Fraction(value) + return abs(value.numerator).bit_length() + value.denominator.bit_length() + + +def word_coefficients(k): + """All affine diagonal and control coefficients of address_word(k).""" + out = [] + for event in address_word(k): + if event[0] != "affine": + continue + out.append(Fraction(event[2])) + for _, c in event[3]: + out.append(Fraction(c)) + return tuple(out) + + +def T_word(k): + """Named physical tariff: total numerator+denominator bit lengths.""" + return sum(coeff_bit_length(c) for c in word_coefficients(k)) + + +def fused_powers(j, kernel=1, sign=1): + a = odd_kernel_power(j, sign, kernel) + return (-a, 2 * a, -a) + + +def baseline_powers(j, kernel=1, sign=1): + a = odd_kernel_power(j, sign, kernel) + return (-a, a, a, -a) + + +def T_program(powers): + return sum(T_word(k) for k in powers) + + +def T_fused(j, kernel=1): + return T_program(fused_powers(j, kernel)) + + +def T_baseline(j, kernel=1): + return T_program(baseline_powers(j, kernel)) + + +def closed_form_T_word(k): + """Independent closed form matching address_word's six variable coeffs + units. + + Unit (±1) coefficients contribute 10 * 2 = 20 bits. Variable coefficients + are a, 1+a, -a, -a, -1/a, 1/a-1 with a = k/4. + """ + need(type(k) is int and k != 0, "nonzero k") + a = Fraction(k, 4) + variable = (a, 1 + a, -a, -a, -1 / a, 1 / a - 1) + return 20 + sum(coeff_bit_length(c) for c in variable) diff --git a/research/odd-kernel-coeff-bit-tariff/test_package.py b/research/odd-kernel-coeff-bit-tariff/test_package.py new file mode 100644 index 0000000000..b2a2c9e185 --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/test_package.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python3 +"""Package controls: duplicate JSON keys, certificate corruption, read-only verify. + +Prepared by Wentao Li with substantial AI assistance. Apache-2.0. +""" +from __future__ import annotations + +import json +import os +import subprocess +import tempfile +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +MARKER = "PASS_ODD_KERNEL_COEFF_BIT_TARIFF_PACKAGE_TESTS" + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +def run(argv, env=None, check=True): + return subprocess.run( + argv, + cwd=str(ROOT), + env=env, + text=True, + capture_output=True, + check=check, + ) + + +def test_duplicate_json_keys(): + bad = '{"a":1,"a":2}\n' + with tempfile.TemporaryDirectory() as tmp: + path = Path(tmp) / "dup.json" + path.write_text(bad) + # verify's read_json rejects duplicates when loading certificate. + # Exercise the same hook locally. + seen = [] + + def hook(pairs): + keys = [k for k, _ in pairs] + if len(keys) != len(set(keys)): + seen.append(True) + return dict(pairs) + + json.loads(bad, object_pairs_hook=hook) + need(seen, "duplicate key detected") + + +def test_certificate_corruption_rejected(): + cert = HERE / "CERTIFICATE.json" + original = cert.read_bytes() + try: + corrupt = json.loads(original) + corrupt["counts"]["odd_fused_exceeds_dyadic"] = 0 + cert.write_text(json.dumps(corrupt, indent=2, sort_keys=True) + "\n") + proc = run( + ["python3.12", "-I", "-B", str(HERE / "verify.py")], + check=False, + ) + need(proc.returncode != 0, "corrupt certificate must fail") + need("certificate mismatch" in (proc.stderr + proc.stdout), + "mismatch message") + finally: + cert.write_bytes(original) + + +def test_readonly_verify_unchanged(): + before = { + path.name: path.read_bytes() + for path in HERE.iterdir() + if path.is_file() + } + env = os.environ.copy() + env.pop("PYTHONOPTIMIZE", None) + proc = run(["python3.12", "-I", "-B", str(HERE / "verify.py")], env=env) + need(proc.returncode == 0, proc.stderr) + need("PASS_ODD_KERNEL_COEFF_BIT_TARIFF" in proc.stdout, "pass marker") + after = { + path.name: path.read_bytes() + for path in HERE.iterdir() + if path.is_file() + } + need(before == after, "verify must not mutate package files") + + +def test_optimize_still_admits(): + env = os.environ.copy() + env["PYTHONOPTIMIZE"] = "1" + proc = run( + ["python3.12", "-I", "-O", "-Werror", "-B", str(HERE / "verify.py")], + env=env, + ) + need(proc.returncode == 0, proc.stderr) + need("PASS_ODD_KERNEL_COEFF_BIT_TARIFF" in proc.stdout, "pass under -O") + + +def main(): + test_duplicate_json_keys() + test_certificate_corruption_rejected() + test_readonly_verify_unchanged() + test_optimize_still_admits() + print(MARKER + " groups=4") + + +if __name__ == "__main__": + main() diff --git a/research/odd-kernel-coeff-bit-tariff/verify.py b/research/odd-kernel-coeff-bit-tariff/verify.py new file mode 100644 index 0000000000..415e6d2e83 --- /dev/null +++ b/research/odd-kernel-coeff-bit-tariff/verify.py @@ -0,0 +1,258 @@ +#!/usr/bin/env python3 +"""Odd-kernel coefficient-bit tariff vs dyadic (answers #2687 OQ2). + +Under the named ADDRESS coefficient-bit tariff, every certified odd kernel +strictly exceeds the dyadic fused (and baseline) bill at each dyadic index +j in 0..32. Typed child/XOR counts stay identical, so larger-q coefficient +tables never pay for themselves on this tariff. No new kappa. + +Admission uses need() and remains active under python -O. +Prepared by Wentao Li with substantial AI assistance. Apache-2.0. +""" +from __future__ import annotations + +import argparse +import hashlib +import json +import runpy +from pathlib import Path + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +MARKER = ( + "PASS_ODD_KERNEL_COEFF_BIT_TARIFF " + "kernels=[1, 3, 5, 7, 9, 15] j=0..32 " + "odd_fused_exceeds_dyadic=165 " + "odd_baseline_exceeds_dyadic=165 " + "no_new_kappa" +) +KAPPA_DECIMAL = "0.001672660197076918" +KAPPA_FRACTION = "836330098538459/500000000000000000" +KERNELS = (1, 3, 5, 7, 9, 15) +ODD_KERNELS = (3, 5, 7, 9, 15) +J_MAX = 32 +PRIOR_README = "research/odd-kernel-query-pair/README.md" +PRIOR_TASK = "research/odd-kernel-query-pair/TASK.json" +PRIOR_PROGRAM = "research/odd-kernel-query-pair/program.py" +INPUTS = (PRIOR_PROGRAM,) + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +def pairs_unique(pairs): + value = {} + for key, item in pairs: + need(key not in value, "duplicate JSON key") + value[key] = item + return value + + +def read_json(path): + raw = Path(path).read_bytes() + need(len(raw) <= 4_000_000, "input exceeds 4 MB") + return json.loads(raw, object_pairs_hook=pairs_unique) + + +def pin_sources(): + manifest = read_json(HERE / "SOURCES.json") + need(manifest["base_commit"] == "20ecf2891d80b5acf18d980b2164fb44ea7faa90", + "base commit pin") + rows = manifest["files"] + inputs = [row for row in rows if row["usage"] == "input"] + need(tuple(row["path"] for row in inputs) == INPUTS, "input inventory") + pinned = {} + for row in rows: + path = ROOT / row["path"] + raw = path.read_bytes() + need(len(raw) == row["size_bytes"], "source size: " + row["path"]) + digest = hashlib.sha256(raw).hexdigest() + need(digest == row["sha256"], "source hash: " + row["path"]) + pinned[row["path"]] = raw + return pinned + + +def load_tariff(): + ns = runpy.run_path(str(HERE / "tariff.py")) + return ns + + +def bind_prior_oq(pinned): + readme = pinned[PRIOR_README].decode("utf-8") + task = pinned[PRIOR_TASK].decode("utf-8") + need("coefficient-table bit-sizes for larger `q`" in readme, + "cite: #2687 README OQ2") + need("Do coefficient-table bit-sizes for larger q ever pay for themselves" + in task, + "cite: #2687 TASK OQ2") + prog = pinned[PRIOR_PROGRAM].decode("utf-8") + need("def address_word(k):" in prog, "cite: prior address_word") + need("a = Fraction(k, 4)" in prog, "cite: prior a=k/4") + + +def cross_check_prior_program(pinned, tariff): + """Byte-pinned prior program must agree on address_word coeffs and T_word.""" + prior = runpy.run_path(str(ROOT / PRIOR_PROGRAM)) + for k in (1, -1, 3, 4, 5, 12, 15, 16, 48, -20, 40): + ours = tariff["word_coefficients"](k) + theirs = [] + for event in prior["address_word"](k): + if event[0] != "affine": + continue + theirs.append(event[2]) + for _, c in event[3]: + theirs.append(c) + need(tuple(ours) == tuple(theirs), f"coeff match k={k}") + need(tariff["T_word"](k) == sum( + tariff["coeff_bit_length"](c) for c in theirs + ), f"T_word match k={k}") + + +def evaluate(write=False): + pinned = pin_sources() + bind_prior_oq(pinned) + tariff = load_tariff() + + # Closed form equals enumeration. + for k in list(range(-64, 0)) + list(range(1, 65)): + need(tariff["T_word"](k) == tariff["closed_form_T_word"](k), + f"closed form k={k}") + need(tariff["T_word"](k) == tariff["T_word"](-k), f"sign free k={k}") + + # Non-monotonicity control: T_word is not monotone in |k|. + need(tariff["T_word"](4) < tariff["T_word"](2) < tariff["T_word"](1), + "T_word not monotone (4<2<1)") + need(tariff["T_word"](4) == 32, "dyadic sweet spot T(4)=32") + + cross_check_prior_program(pinned, tariff) + + # Typed invoice invariance reused from prior: fused always 3/18/2. + # We only re-check power lists and child counts via powers. + rows = [] + odd_fused_exceeds = 0 + odd_baseline_exceeds = 0 + for j in range(0, J_MAX + 1): + dy_f = tariff["T_fused"](j, 1) + dy_b = tariff["T_baseline"](j, 1) + need(len(tariff["fused_powers"](j, 1)) == 3, "fused query count") + need(len(tariff["baseline_powers"](j, 1)) == 4, "baseline query count") + for q in KERNELS: + fused = tariff["T_fused"](j, q) + base = tariff["T_baseline"](j, q) + row = { + "j": j, + "kernel": q, + "a": q * (1 << j), + "T_fused": fused, + "T_baseline": base, + "T_word_a": tariff["T_word"](q * (1 << j)), + "T_word_2a": tariff["T_word"](2 * q * (1 << j)), + } + rows.append(row) + if q == 1: + need(fused == 2 * row["T_word_a"] + row["T_word_2a"], + "fused additive") + continue + need(fused > dy_f, f"fused q={q} j={j}: {fused} !> {dy_f}") + need(base > dy_b, f"baseline q={q} j={j}: {base} !> {dy_b}") + odd_fused_exceeds += 1 + odd_baseline_exceeds += 1 + + need(odd_fused_exceeds == len(ODD_KERNELS) * (J_MAX + 1), + "odd fused exceed count") + need(odd_baseline_exceeds == len(ODD_KERNELS) * (J_MAX + 1), + "odd baseline exceed count") + need(odd_fused_exceeds == 165, "165 odd fused comparisons") + need(odd_baseline_exceeds == 165, "165 odd baseline comparisons") + + # Spot checks at the OQ's suggested first step (fix j, q in {1,3,5,7}). + for j in (0, 1, 2, 4): + bills = {q: tariff["T_fused"](j, q) for q in (1, 3, 5, 7)} + need(bills[1] < bills[3] < bills[5], f"growth at j={j}: {bills}") + need(bills[1] < bills[7], f"q=7 exceeds dyadic at j={j}") + + # Fusion saves coefficient bits but never reverses the odd>dyadic order. + for j in range(0, J_MAX + 1): + for q in ODD_KERNELS: + save_q = tariff["T_baseline"](j, q) - tariff["T_fused"](j, q) + save_1 = tariff["T_baseline"](j, 1) - tariff["T_fused"](j, 1) + need(save_q > 0 and save_1 > 0, "fusion saves bits") + need(tariff["T_fused"](j, q) > tariff["T_fused"](j, 1), + "fusion does not overturn odd>dyadic") + + selected = read_json(ROOT / "certificates/selected-result.json") + need(selected.get("kappa") == KAPPA_FRACTION, "selected kappa unchanged") + + # Adversarial controls. + fake_dyadic = tariff["T_fused"](2, 1) + 100 + need(tariff["T_fused"](2, 3) > tariff["T_fused"](2, 1), "positive control") + need(not (tariff["T_fused"](2, 3) > fake_dyadic), + "control: inflated dyadic would break strict exceed vs q=3 at j=2") + + certificate = { + "schema_version": 1, + "status": "PASS_ODD_KERNEL_COEFF_BIT_TARIFF", + "kappa_decimal": KAPPA_DECIMAL, + "kappa_fraction": KAPPA_FRACTION, + "tariff": { + "name": "ADDRESS_affine_coeff_num_den_bit_sum", + "definition": ( + "T_word(k) = sum over affine diagonal/control coefficients c=p/q " + "in lowest terms of bit_length(|p|)+bit_length(q); " + "T_fused(q,j)=2*T_word(q*2^j)+T_word(q*2^{j+1}); " + "T_baseline(q,j)=4*T_word(q*2^j)." + ), + "unit_coeff_bits": 20, + }, + "kernels": list(KERNELS), + "odd_kernels": list(ODD_KERNELS), + "j_max": J_MAX, + "counts": { + "odd_fused_exceeds_dyadic": odd_fused_exceeds, + "odd_baseline_exceeds_dyadic": odd_baseline_exceeds, + "grid_rows": len(rows), + }, + "spot": { + "T_word": {str(k): tariff["T_word"](k) for k in (1, 2, 3, 4, 5, 7, 15)}, + "T_fused_j2": {str(q): tariff["T_fused"](2, q) for q in KERNELS}, + "non_monotone": {"T(1)": 45, "T(2)": 38, "T(4)": 32}, + }, + "claim": { + "odd_fused_strictly_exceeds_dyadic_on_grid": True, + "odd_baseline_strictly_exceeds_dyadic_on_grid": True, + "typed_child_xor_counts_identical": True, + "tables_never_pay_on_this_tariff": True, + }, + "no_new_kappa": True, + } + admit_certificate(certificate, write=write) + return certificate + + +def admit_certificate(certificate, write=False): + path = HERE / "CERTIFICATE.json" + if write: + path.write_text(json.dumps(certificate, indent=2, sort_keys=True) + "\n") + return + need(path.is_file(), "missing CERTIFICATE.json") + committed = read_json(path) + need(committed == certificate, "certificate mismatch") + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "--write", + action="store_true", + help="regenerate CERTIFICATE.json (explicit write path only)", + ) + args = parser.parse_args(argv) + certificate = evaluate(write=args.write) + need(certificate["status"] == "PASS_ODD_KERNEL_COEFF_BIT_TARIFF", "status") + print(MARKER) + + +if __name__ == "__main__": + main()