diff --git a/research/paid-history-quotient/README.md b/research/paid-history-quotient/README.md new file mode 100644 index 0000000000..f1c72c7c8e --- /dev/null +++ b/research/paid-history-quotient/README.md @@ -0,0 +1,100 @@ +# Additional paid returns with retained observations + +This package gives an exact finite-dimensional audit of additional paid returns. +It includes every supplied initial observation before it applies a lower bound. +A correctly versioned observation can remove a charge. A copy of an old version +need not remove it. The complete kappa calculation does not change. + +## Statement and proof + +Let R be a finite-dimensional unital matrix algebra over Q, with dimension r. +A field row is a d by dN rational matrix on N named independent input fields. +Let H be the left R-module generated by the supplied initial rows. Let T be +the left R-module generated by all required final rows. Set + +``` +Delta = dim_Q(H + T) - dim_Q(H). +m >= ceil(Delta / r). +``` + +Here m counts additional paid calls. Each call returns one actual new field +row at the same capacity. The call can act on a row that uses earlier paid +returns. Ordinary operations are left actions by R and scalar row combinations. +They preserve the current history module. Each actual paid return t adds Rt, +whose dimension is at most r. Keep a conceptual copy of every paid return, +even after physical overwrite or clear. After m returns the history dimension +is at most dim(H)+mr. It contains H+T at completion. Subtraction proves the bound. +No commutation or R-linearity of a paid operator is needed. All rows must denote +linear maps on the same independent input space. Target rows include required +dirty returns; zero scratch has no independent input column. + +The bound is necessary. Delta=0 means that the target rows lie in the supplied +ordinary closure. It does not prove that the required storage, scalar operations, +ownership, access, or final erasure are free. The dimension bound need not be a +sharp return count for a restricted paid alphabet. + +The code forms R from the identity and the supplied ordinary generators. It +repeatedly left-multiplies new basis elements by each generator. Stabilization +occurs after at most d squared independent elements. The resulting span contains +every generator word, so products omitted from an initial generator list cannot +create a false positive charge. Exact rational elimination computes H and H+T. +There is no floating-point rank decision. The direct tool accepts JSON with +`dimension`, distinct `inputs`, `ordinary_generators`, `initial`, and `targets`. +Each initial or target row has d rows and d times N columns. Use integer values +or rational strings. Example: d=2, inputs=["x"], no ordinary generators, +initial=[I_2], targets=[diag(1,-1)] gives Delta=1 and m>=1. Supplying the target +as an initial observation gives Delta=0. + +## Evidence and reproduction + +```sh +python3 -B scripts/research_package.py --package research/paid-history-quotient +python3 -B research/paid-history-quotient/audit.py /path/to/interface.json +``` + +Python 3.12 and its standard library suffice. The registered normal and optimized +checks cover all cached subsets for one through five distinct inputs, 96 literal +programs with feedback and overwrite, and all 1152 prefixes. Controls distinguish +old and current versions, require full ordinary closure, and reject ambiguous +input names, malformed matrices, floats and zero denominators. Every check uses +an explicit exception. The written proof gives the general finite-matrix result; +the finite tests do not prove an all-width native statement. + +## Scope and overlap + +This answers an algebraic part of the retained-observation question in +[PR #5446](https://github.com/CrocSwap/integer-mult-bounds/pull/5446), at +`0d0bcf3fa261c9591e7e60ed5926c6e04d360f9e`. Its +[pointwise proof](https://github.com/Clear1nsight/integer-mult-bounds/blob/0d0bcf3fa261c9591e7e60ed5926c6e04d360f9e/docs/research/standalone-history-scalar-ceiling/proofs/pointwise-lemma-v1.md) +supplies the actual-return history principle and the distinction from a parent +cut with observations. This package supplies a finite rational computation for +an explicit initial module. It neither repeats its tensor-width theorem nor +claims to have extracted the current physical caller. + +[PR #5427](https://github.com/CrocSwap/integer-mult-bounds/pull/5427) tests specific +frozen formal-word observations. [PR #5441](https://github.com/CrocSwap/integer-mult-bounds/pull/5441) +checks finite-memory endpoint tables and routing ranks. Those are different +contracts. The overlap search covered 319 open PRs, 4715 Discussion records, +and all 7402 tracked in-scope notes on canonical main +`32890bc5de034ab8fc93ac88ead7279a6a416d04`, priority revision 7. Arbitrary diffs, +unpublished work, and exhaustive historical PR bodies remain outside coverage. +The selected baseline helper stopped on omitted sparse source inputs; no +baseline or selected cold-replay pass is claimed. + +## Open next questions + +Extract one actual boundary's complete current rows and ordinary generators. +Verify source versions, phases, ownership, access and final returns, then apply +the audit. This could prevent a duplicate charge or certify a necessary added +cost. The missing physical row and availability ledger is the blocker. Do not +replace it with a list of desired observations. Semisimple component bounds +may strengthen the dimension ratio; that is a separate algebraic task. + +## Credit + +Chris R / Clear1nsight and the retained PR5425/PR5446 authors supply the paid-history +argument and application question. Classical module dimension and rational +elimination supply the mathematical method. This package does not claim those +principles as new. The exact source is linked above; no predecessor code is +imported or changed. Ali Romman with substantial OpenAI Codex assistance. +Apache-2.0. No independent human review or proof-kernel acceptance is claimed. diff --git a/research/paid-history-quotient/SOURCES.json b/research/paid-history-quotient/SOURCES.json new file mode 100644 index 0000000000..1a711914dd --- /dev/null +++ b/research/paid-history-quotient/SOURCES.json @@ -0,0 +1,27 @@ +{ + "schema_version": 1, + "base_commit": "32890bc5de034ab8fc93ac88ead7279a6a416d04", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "fc3d4ba105e1f097d0d7d051a308281e86ab1446", + "sha256": "66974efdced4083c00025f97d95d83909a226cdf801edb9301c195c6641f6903" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "f126dd2e2dad2b669e75d1d0d0bd05c600725602", + "sha256": "f7a48bfa2659b88378282a8eee7d9fe52cdf505594124c4d1686b58510fffd72" + } + ], + "external_provenance": [ + { + "repository": "Clear1nsight/integer-mult-bounds", + "commit": "0d0bcf3fa261c9591e7e60ed5926c6e04d360f9e", + "path": "docs/research/standalone-history-scalar-ceiling/proofs/pointwise-lemma-v1.md", + "git_blob": "5aeadc6617e81e66b3918eab4e248ba263cdd2a9", + "usage": "Read-only proof precedent; no runtime import." + } + ] +} diff --git a/research/paid-history-quotient/TASK.json b/research/paid-history-quotient/TASK.json new file mode 100644 index 0000000000..5c74a2f267 --- /dev/null +++ b/research/paid-history-quotient/TASK.json @@ -0,0 +1,95 @@ +{ + "schema_version": 1, + "task_id": "formal-interface-lemma", + "priority_revision": 7, + "base_commit": "32890bc5de034ab8fc93ac88ead7279a6a416d04", + "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_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Inventory the gate-operand parity lemma (#3807) and certified endpoint arithmetic (#3857). Neither is a full multiplication proof. For #4100, audit the compact-switch statement and its hypotheses before formalizing it.", + "scope": "Source-binding orientation only; no scientific replay, theorem acceptance or supplier admission. Budget any heavy replay separately." + }, + "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 finite rational lower bound on additional paid returns with supplied initial observations.", + "scope_change_reason": "Take the PR5446 handoff as a written interface lemma and exact audit instead of a Lean formalization.", + "bottleneck_link": "Avoid a duplicate standalone charge at a caller boundary that already has useful paid observations.", + "budget_minutes": 60, + "stop_rule": "Prove the dimension bound and test finite chronological programs; do not construct a caller.", + "outcome": "completed", + "evidence": "README.md proof; verify.py exact cache and chronological checks.", + "author": "Ali Romman", + "ai_assistance": "Substantial OpenAI Codex assistance.", + "open_questions": [ + { + "question": "What is the exact initial module at one actual caller boundary?", + "why_it_matters": "It determines which additional paid charges are necessary.", + "first_step": "Extract complete versioned physical rows and ordinary generators.", + "blocked_by": "No physical availability, ownership or source-version ledger is supplied here." + } + ] +} diff --git a/research/paid-history-quotient/VERIFY.json b/research/paid-history-quotient/VERIFY.json new file mode 100644 index 0000000000..b90c62b899 --- /dev/null +++ b/research/paid-history-quotient/VERIFY.json @@ -0,0 +1,30 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Exact cache cases, complete chronological prefixes, version and closure controls." + }, + { + "argv": [ + "{python}", + "-I", + "-B", + "-O", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Exact cache cases, complete chronological prefixes, version and closure controls." + } + ] +} diff --git a/research/paid-history-quotient/audit.py b/research/paid-history-quotient/audit.py new file mode 100644 index 0000000000..365d6a4ca2 --- /dev/null +++ b/research/paid-history-quotient/audit.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +"""Compute an exact lower bound for a finite paid-history interface. + +Ali Romman with substantial OpenAI Codex assistance. Apache-2.0. +""" +import argparse +from fractions import Fraction as Q +import json +from pathlib import Path + + +def scalar(value): + if type(value) not in (int, str): + raise ValueError("use integers or rational strings") + return Q(value) + + +def matrix(value, rows, columns): + if not isinstance(value, list) or len(value) != rows: + raise ValueError("invalid row count") + if any(not isinstance(row, list) or len(row) != columns for row in value): + raise ValueError("invalid column count") + return tuple(tuple(scalar(x) for x in row) for row in value) + + +def identity(d): + return tuple(tuple(Q(i == j) for j in range(d)) for i in range(d)) + + +def multiply(a, b): + return tuple(tuple(sum(x * y for x, y in zip(row, col)) + for col in zip(*b)) for row in a) + + +def flat(a): + return tuple(x for row in a for x in row) + + +class Span: + def __init__(self): + self.rows = {} + + def add(self, vector): + row = list(vector) + for pivot, basis in sorted(self.rows.items()): + c = row[pivot] + row = [x - c * y for x, y in zip(row, basis)] + pivot = next((i for i, x in enumerate(row) if x), None) + if pivot is None: + return False + c = row[pivot] + self.rows[pivot] = tuple(x / c for x in row) + return True + + def __len__(self): + return len(self.rows) + + +def algebra(d, generators): + basis, span = [identity(d)], Span() + span.add(flat(basis[0])) + index = 0 + while index < len(basis): + for generator in generators: + product = multiply(generator, basis[index]) + if span.add(flat(product)): + basis.append(product) + index += 1 + return basis + + +def audit(data): + d = data['dimension'] + if type(d) is not int or d < 1: + raise ValueError("dimension must be a positive integer") + names = data['inputs'] + if (not isinstance(names, list) or not names + or any(not isinstance(x, str) or not x for x in names) + or len(set(names)) != len(names)): + raise ValueError("input versions must have distinct nonempty names") + generators = [matrix(x, d, d) for x in data['ordinary_generators']] + initial = [matrix(x, d, d * len(names)) for x in data['initial']] + targets = [matrix(x, d, d * len(names)) for x in data['targets']] + ordinary = algebra(d, generators) + span = Span() + for row in initial: + for a in ordinary: + span.add(flat(multiply(a, row))) + initial_rank = len(span) + for row in targets: + for a in ordinary: + span.add(flat(multiply(a, row))) + delta = len(span) - initial_rank + return {'ordinary_dimension': len(ordinary), 'initial_dimension': initial_rank, + 'joint_dimension': len(span), 'target_quotient_dimension': delta, + 'additional_return_lower_bound': (delta + len(ordinary) - 1) // len(ordinary), + 'targets_in_initial_ordinary_closure': delta == 0} + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('input', type=Path) + args = parser.parse_args() + try: + result = audit(json.loads(args.input.read_text(encoding='utf-8'))) + except (ValueError, KeyError, TypeError, ZeroDivisionError) as error: + parser.error(str(error)) + print(json.dumps(result, sort_keys=True)) + + +if __name__ == '__main__': + main() diff --git a/research/paid-history-quotient/verify.py b/research/paid-history-quotient/verify.py new file mode 100644 index 0000000000..a1db712ba1 --- /dev/null +++ b/research/paid-history-quotient/verify.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +"""Check exact history bounds and full chronological examples. + +Ali Romman with substantial OpenAI Codex assistance. Apache-2.0. +""" +from copy import deepcopy +from itertools import combinations +import json +import random +import sys +from pathlib import Path +sys.path.insert(0, str(Path(__file__).resolve().parent)) +from audit import audit, algebra, multiply + + +def require(condition, message): + if not condition: + raise ValueError(message) + + +def block(a, position, n): + return [[a[i][j % 2] if j // 2 == position else 0 for j in range(2*n)] + for i in range(2)] + + +def encode(a): + return [[str(x) for x in row] for row in a] + + +def main(): + I, X, Z = [[1,0],[0,1]], [[0,1],[1,0]], [[1,0],[0,-1]] + cases = 0 + for n in range(1, 6): + for k in range(n+1): + for cached in combinations(range(n), k): + data = {'dimension':2,'inputs':[f'v{i}@now' for i in range(n)], + 'ordinary_generators':[], + 'initial':[block(I,i,n) for i in range(n)] + [block(Z,i,n) for i in cached], + 'targets':[block(Z,i,n) for i in range(n)]} + result = audit(data) + require(result['target_quotient_dimension'] == n-k, 'cached quotient') + require(result['additional_return_lower_bound'] == n-k, 'cached lower bound') + cases += 1 + E12, E21 = [[0,1],[0,0]], [[0,0],[1,0]] + require(len(algebra(2,[tuple(map(tuple,E12)),tuple(map(tuple,E21))])) == 4, + 'products must be included') + base = {'dimension':2,'inputs':['old','new'],'ordinary_generators':[], + 'initial':[block(I,i,2) for i in range(2)] + [block(Z,0,2)], + 'targets':[block(Z,1,2)]} + require(audit(base)['additional_return_lower_bound'] == 1, 'stale version') + good = deepcopy(base); good['initial'].append(block(Z,1,2)) + require(audit(good)['additional_return_lower_bound'] == 0, 'current observation') + closure = deepcopy(base); closure['ordinary_generators'] = [E12,E21] + require(audit(closure)['additional_return_lower_bound'] == 0, 'ordinary closure') + controls = 3 + for key, value in [('dimension',True), ('inputs',['same','same']), + ('ordinary_generators',[[[1.0,0],[0,1]]]), + ('targets',[[[1,0],[0,1]]]), + ('ordinary_generators',[[['1/0',0],[0,1]]])]: + bad=deepcopy(base); bad[key]=value + try: audit(bad) + except (ValueError, ZeroDivisionError): controls += 1 + else: raise ValueError('accepted invalid input: '+key) + rng=random.Random(7301) + programs=prefixes=0 + for generators in ([],[Z],[E12],[E12,E21]): + for _ in range(24): + rows=[block(I,0,2),block(I,1,2),[[0]*4 for _ in range(2)]] + initial=deepcopy(rows); paid=0 + for step in range(12): + dst,src=rng.sample(range(3),2) + if step % 3 == 0: + operator=[[rng.randrange(-2,3) for _ in range(2)] for _ in range(2)] + rows[dst]=[list(r) for r in multiply(operator,rows[dst])]; paid+=1 + elif step % 3 == 1: + rows[dst]=[[x+y for x,y in zip(a,b)] for a,b in zip(rows[dst],rows[src])] + elif generators: + rows[dst]=[list(r) for r in multiply(rng.choice(generators),rows[dst])] + else: + rows[dst]=deepcopy(rows[src]) + data={'dimension':2,'inputs':['x','y'],'ordinary_generators':generators, + 'initial':initial,'targets':[encode(a) for a in rows]} + require(audit(data)['additional_return_lower_bound'] <= paid, + 'history bound exceeds literal paid returns') + prefixes+=1 + programs+=1 + print('PASS_PAID_HISTORY_QUOTIENT '+json.dumps( + {'cache_cases':cases,'literal_programs':programs,'prefixes':prefixes,'controls':controls},sort_keys=True)) + + +if __name__ == '__main__': + main()