diff --git a/research/k8-unequal-triple-closure/PROOF.md b/research/k8-unequal-triple-closure/PROOF.md new file mode 100644 index 0000000000..b815910ebd --- /dev/null +++ b/research/k8-unequal-triple-closure/PROOF.md @@ -0,0 +1,161 @@ +# Unequal three-helper closure + +This contribution was produced by Nick Petalas. Apache-2.0. + +## Statement and inherited contract + +Fix either final gauge vector of Philipp / mightyOil's +[PR1322](https://github.com/CrocSwap/integer-mult-bounds/pull/1322), retained +in `research/k8-coherent-triples/CERTIFICATE.json`. Fix its 237 eligible +helpers and its original scalar ADD stream. Let k be that vector, with zero +at all other registers. For an ADD with coefficient of absolute value +p 2^e, where p is positive odd, put u=1 when p=1 and u=0 otherwise. Define + +```text +f_u(z) = |z| - u [z=0] +F(k) = 2 sum_h |k_h| + sum_ADD f_u(e + k_target - k_source). +``` + +The complete scalar tariff in PR1322 differs from F only by a constant. +In particular the first term pays both boundary scales. This tariff and +the eligibility/conjugation contract are cited premises, not new results. +The original macro stream, coefficients, boundary contract and lowering +alphabet remain fixed. + +**Theorem.** For every integer vector d supported on at most three of these +helpers, in either orientation, + +```text +F(k+d) - F(k) >= 8 sum_h max(0, |d_h|-3) >= 0. +``` + +Consequently every improving constant integer gauge move needs at least +four changed helpers. This is a scoped computer-assisted negative proof, +with an exact finite certificate, not a failed bounded search or a global +optimum theorem. PR1322 previously established common-shift triple closure +and explicitly left independently chosen shifts open. It did not assert +arbitrary pair stationarity at its final vector. + +## A finite clipping certificate for an infinite domain + +An incident ADD at helper h has signed change +d_h at its target or -d_h +at its source. At the fixed vector k record it as (u,E,sigma), where +E=e+k_target-k_source and sigma is +1 or -1. Multiplicities are retained. +Let I_h be this multiset, and let I_hb contain just the ADDs joining h and +another eligible helper b. Define the outward unit difference + +```text +V(J,x,s) = sum_(u,E,sigma in J) + [ f_u(E+sigma*x) - f_u(E+sigma*(x-s)) ], s in {-1,+1}. + +D_h(x,s) = 2(|k_h+x|-|k_h+x-s|) + V(I_h,x,s). +m_hb(s) = min_(z in Z) V(I_hb,z,s). +loss_hb(x,s) = max(0, V(I_hb,x,s)-m_hb(s)). +L_h(x,s) = D_h(x,s) - sum of the two largest loss_hb(x,s). +``` + +A missing largest loss is zero. Suppose d_h=x and at most two other +helpers change. If such a neighbor b has displacement y, its actual pair +contribution to the outward difference is V(I_hb,x-y,s), hence is at least +m_hb(s). Unchanged neighbors contribute their baseline difference exactly. +Subtracting the two largest nonnegative losses therefore gives a valid +lower bound on the complete outward difference. It does not assume the +two independently minimized pair contributions can be attained together. + +All minima and all tail inequalities above have finite exact checks. Set + +```text +B_h = max(3, |k_h|, max_(u,E,sigma in I_h) |E|) + 2. +``` + +For fixed s, each V(I_hb,z,s) is constant on each integer tail outside +[-B_h,B_h]. Both arguments of every f then stay strictly on one side of +zero. Thus its minimum over all integers is attained in that finite +interval. The same fact applies to D_h(x,s), every loss, and L_h(x,s) on +the outward tail x=s*t, t>=B_h. The boundary absolute value also has +constant difference there. Checking t=4,...,B_h covers every outward +integer displacement beyond three. + +In each orientation the verifier checks all 1,540 resulting (h,s,t) +rows. The least L_h is exactly 8. These are exact integer inequalities, +including the point discount at exponent zero. Replacing that tariff by +plain absolute value would be a different problem. + +Reduce each coordinate outside [-3,3] one step toward that interval. +The support size never increases, and each step reduces F by at least +8. After sum_h max(0,|d_h|-3) steps the resulting displacement d' is in +[-3,3] and has support at most three. This proves + +```text +F(k+d) - F(k+d') >= 8 sum_h max(0,|d_h|-3). +``` + +The remaining obligation is the bounded claim F(k+d')>=F(k). + +## Exact bounded decomposition and complete coverage + +Let S_h(a)=F(k+a e_h)-F(k). For every helper pair a= 8 sum_h max(0, |d_h|-3) >= 0. +``` + +[PROOF.md](PROOF.md) gives the clipping lemma, its exact finite premises, +the singleton/pair decomposition and the disconnected-component argument. +Each outward clipping step beyond magnitude three costs at least eight +real-component primitives. This reduces the infinite domain to [-3,3] +without relying on a solver's failure to find a witness. + +The standard-library verifier independently extracts the valuation graph +from the retained source archive and consumes PR1322's final vector. In each +orientation it checks all 1,540 clipping rows, with minimum lower bound 8, +and obtains minimum zero on every tested block: + +| Class | Blocks | Independent shift assignments checked | +| --- | ---: | ---: | +| Singletons | 237 | 1,659 | +| Pairs | 27,966 | 1,370,334 | +| Connected triples | 49,898 | 17,115,014 | + +The graph has 2,414 interaction edges and 15,619 incident ADD records per +orientation, with multiplicity. Disconnected triples reduce to their +singleton/pair components. The theorem covers all 2,190,670 three-helper +subsets; the verifier does not execute all shift assignments on every +disconnected triple. Forty synthetic graphs supply 13,720 literal-objective +comparisons, and tariff controls exercise the zero-exponent discount and +paid boundaries. One rejection control prevents clipping without its +premise. Thirty-two complete-objective controls include shifts of magnitude +2^32. The stdout receipt is generated and bound to input and +package hashes; no receipt is handwritten. + +## Reproduce + +From the repository root, with CPython 3.12 and its standard library: + +```sh +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -W error -B research/k8-unequal-triple-closure/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -I -W error -O -B research/k8-unequal-triple-closure/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/research_package.py --package research/k8-unequal-triple-closure +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/check_research_commit.py --package research/k8-unequal-triple-closure --check-source-history +``` + +Another CPython 3.12 executable can replace that local path. The direct +marker is `PASS_K8_UNEQUAL_TRIPLE_CLOSURE`. Each registered command has a +120-second limit and writes no files. The committed-byte/history command +requires a committed package and full Git history. Direct replay also works +from an official Git-free export containing its two declared live inputs. + +## Scope, credit and provenance + +Philipp / mightyOil supplies PR1322's open question, final vector, objective, +common-shift triple result and graph decomposition, following PR1310/1263. +Hanson Sun / bbMisk supplies PR1214's exact pair method; woklerx supplies +PR1161's constant gauge mechanism; Sagar Thakrar supplies the retained +copy-init lowerer. Jeremy Kothe, Rohan Arun, Hao Yan / icekylinx, Douglas +Colkitt and the original supplier/frame/native/compiler lineage retain their +credit. Their files and credit lines are unchanged. The new contributions +are the two-neighbor clipping certificate and unequal-triple closure at +this final vector. General integer-cost decomposition is not claimed as +a new mathematical technique. + +Scientific base is canonical main +`a5bff3bf133e482541c09eba4e773884bdb2b1b7`, priority revision 8. +[SOURCES.json](SOURCES.json) pins the historical source archive, vector, +question, task catalogue and selected record. The current selected binding +orientation passed at kappa 0.003125804. This historical scalar result does +not transfer automatically to that changed P104 supplier. The card's scope +is explicitly changed in [TASK.json](TASK.json). + +The [advance claim](https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19279574) +was preceded by live handoff, reservation, open/merged PR, recent-account +and main README searches. The overlap cache covered 337 open PRs and 5,949 +Discussion records with complete remote pagination; only 89 of 8,623 local +notes were materialized. Main README searches supplemented those sparse +notes. These checks do not exclude unpublished work or establish global +novelty. The time-dependent ADD-once bipartite model of PR6130 is different +from this fixed cyclic graph with constant gauges. + +Four or more changes, temporal gauges, a changed graph or lowerer, native +integration, ownership, full precision, stock and tape costs remain outside +scope. No circuit, recursive paid profile, selected frontier or inherited +framework assumption is changed. Selected scientific replay, predecessor +scientific suites, Lean and Docker were not run. Independent human and +formal proof-kernel review are unclaimed. + +## Open next questions + +Can at least four independently changed helpers improve this final vector? +Start with one explicit displacement and the complete boundary-inclusive +objective. A strict witness would identify the next coupled move; no such +witness or larger-support optimality certificate is supplied. This result +does not authorize an automatic larger historical construction campaign. + +## Implementation constraints + +The new verifier is nonrecursive, uses exact integers, has no subprocess, +network, dynamic import or file-write path, and keeps every function below +60 physical lines. Source hashes are checked before parsing. The source +domain has at most 25,000 events per orientation, 16,000 retained terms, +237 helpers, clipping radius 40 and 60,000 connected triples. The largest +bounded census has 60,000 times 343 assignments. Input handles have scoped +cleanup, failures propagate, and explicit checks remain active under -O. + +Power of Ten rule 3 has a managed-runtime deviation. CPython, JSON and tar +parsing allocate dynamically during this finite command. Reads are capped +at 64 MiB per authenticated input, each decoded member at 16 MiB, and live +tables are bounded by the domains above. This is not a fixed-allocation or +real-time claim. A streaming parser/fixed-storage representation is required +before admitting unbounded data or a persistent service. Warning-strict +normal/optimized execution and in-memory compilation provide diagnostics; +no external linter or type analyzer is claimed. diff --git a/research/k8-unequal-triple-closure/SOURCES.json b/research/k8-unequal-triple-closure/SOURCES.json new file mode 100644 index 0000000000..e77b7a70a6 --- /dev/null +++ b/research/k8-unequal-triple-closure/SOURCES.json @@ -0,0 +1,36 @@ +{ + "schema_version": 1, + "base_commit": "a5bff3bf133e482541c09eba4e773884bdb2b1b7", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "d59b5035e7b4cbaa9d688a1d32dd0d6eb79c466a", + "sha256": "9b8d0eea95b3bf0dfcb7938a732a6439b87a2685dec2a5ab9e525b3b34debbfa" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "research/community-frontier1042-audit/selected-replay.tar.gz", + "usage": "input", + "git_blob": "6f4dc6fe7631d8aacf8081fcaecf32197181685b", + "sha256": "22c3f4dce4b897a1d423d1388801933e288b6a6b1906cb15e1b16a5eb68db754" + }, + { + "path": "research/k8-coherent-triples/CERTIFICATE.json", + "usage": "input", + "git_blob": "552462497e38e9f016cd0b858d2480aab1fa4ae4", + "sha256": "d35776232f149e670fcc7a3b37f6000dd5d0f550c27c66bb67a5d33d904501f8" + }, + { + "path": "research/k8-coherent-triples/README.md", + "usage": "provenance", + "git_blob": "675ce355b6ade05ec7a2baa396b0adae0a741407", + "sha256": "f46f39bde75c28b5be3f2b41251e2157046941efcd9a17bb46051aca6b836631" + } + ] +} diff --git a/research/k8-unequal-triple-closure/TASK.json b/research/k8-unequal-triple-closure/TASK.json new file mode 100644 index 0000000000..0b23b14fcd --- /dev/null +++ b/research/k8-unequal-triple-closure/TASK.json @@ -0,0 +1,93 @@ +{ + "schema_version": 1, + "task_id": "complex-new-helper-inventory", + "priority_revision": 8, + "base_commit": "a5bff3bf133e482541c09eba4e773884bdb2b1b7", + "original_card": { + "id": "complex-new-helper-inventory", + "question": "Can a changed helper inventory earn productive credit that survives completion, compilation and the 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": "A source-bound arbitrary-input identity and legal producer/consumer boundary with the complete paid and productive target invoice, including restoration, ownership, native alignment and extra charges. Price under the actual current model; historical ceiling.py assumptions must be established before use. A favorable optimistic relaxation keeps a route open but is not a completed supplier. A scoped local result remains useful; expansion requires the family-level budget gate.", + "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": "Specify all arbitrary inputs, owned fields, restored outputs and a physically legal consumer. Compare complete P and T, including target debits and precision/stock costs. #5599 is a positive control for target refinement, not permission to split every helper for free. #5614 is a hypothetical compiler budget, not an emitted 145-split word. Stop at the first unpaid boundary or a failing optimistic full bill.", + "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": [ + "productive helper", + "target refinement", + "5599", + "5614" + ], + "existing_checks": [ + { + "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": "Prove that the final historical PR1322 gauge vector cannot improve under independently chosen integer shifts of at most three eligible helpers, in both orientations.", + "scope_change_reason": "A scoped scalar obstruction answers PR1322 Open next question 1. The current card asks for a new recursive helper interface; this historical fixed-graph result does not meet its physical paid-profile gate.", + "bottleneck_link": "Closes a stated coupled constant-gauge escape in a historical complex scalar graph. It does not change the selected P104 profile or kappa.", + "budget_minutes": 60, + "stop_rule": "Stop after exact unequal-triple closure; do not search larger blocks or expand the historical supplier family.", + "outcome": "completed", + "evidence": "PROOF.md and source-bound exact standard-library verifier; registered normal and optimized commands.", + "author": "Nick Petalas", + "ai_assistance": "Independent human and formal proof-kernel review are unclaimed.", + "open_questions": [ + { + "question": "Can at least four independently changed eligible helpers improve this final fixed-graph vector?", + "why_it_matters": "Every saving in the retained constant-gauge model must now change at least four helpers.", + "first_step": "Write an explicit four-helper displacement and compute the complete boundary-inclusive objective. A negative witness is enough; do not infer global stationarity from this result.", + "blocked_by": "No improving larger block or unbounded larger-support certificate is supplied." + } + ], + "claim_type": "Scoped computer-assisted negative proof with exact finite certificate", + "claim_url": "https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19279574", + "overlap": { + "base_commit": "a5bff3bf133e482541c09eba4e773884bdb2b1b7", + "priority_revision": 8, + "open_pr_records": 337, + "discussion_records": 5949, + "local_records": 89, + "local_HEAD_records": 8623, + "limits": "Cached remote pagination complete at the recorded refresh; local notes sparse. Main README and targeted merged PR searches supplement it. Unpublished work and arbitrary historical diffs are not covered.", + "source": "PR #1322", + "source_author": "mightyOil", + "account_weekly_scan_records": 405 + }, + "verification_environment": { + "python": "3.12.15", + "platform": "macOS-27.0.1-arm64-arm-64bit", + "dependencies": "Python standard library only" + } +} diff --git a/research/k8-unequal-triple-closure/VERIFY.json b/research/k8-unequal-triple-closure/VERIFY.json new file mode 100644 index 0000000000..4d0b089777 --- /dev/null +++ b/research/k8-unequal-triple-closure/VERIFY.json @@ -0,0 +1,37 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/community-frontier1042-audit/selected-replay.tar.gz", + "research/k8-coherent-triples/CERTIFICATE.json" + ], + "commands": [ + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Exact source-bound clipping theorem premises and all unequal singleton, pair and connected-triple shifts; disconnected-component reduction; literal objective controls." + }, + { + "argv": [ + "{python}", + "-I", + "-W", + "error", + "-O", + "-B", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "The same full scientific checks with Python assertions disabled." + } + ] +} diff --git a/research/k8-unequal-triple-closure/verify.py b/research/k8-unequal-triple-closure/verify.py new file mode 100644 index 0000000000..6b0740d7fd --- /dev/null +++ b/research/k8-unequal-triple-closure/verify.py @@ -0,0 +1,316 @@ +"""Exact unequal-triple closure, produced by Nick Petalas. Apache-2.0.""" + +from collections import Counter, defaultdict +from hashlib import sha256 +from itertools import combinations, product +from pathlib import Path +import gzip +import json +import random +import tarfile + + +HERE = Path(__file__).resolve().parent +ROOT = HERE.parents[1] +SHIFTS = tuple(range(-3, 4)) +ZERO = (0,) * 49 + + +def need(condition, message): + if not condition: + raise ValueError(message) + + +def bounded_read(path, limit): + with path.open("rb") as stream: + raw = stream.read(limit + 1) + need(len(raw) <= limit, "source capacity") + return raw + + +def bound_sources(): + manifest = json.loads(bounded_read(HERE / "SOURCES.json", 65536)) + inputs = [row for row in manifest["files"] if row["usage"] == "input"] + need(len(inputs) == 2, "two declared live inputs") + result = {} + for row in inputs: + raw = bounded_read(ROOT / row["path"], 64 * 1024 * 1024) + digest = sha256(raw).hexdigest() + need(digest == row["sha256"], "source drift: " + row["path"]) + result[row["path"]] = digest + return result + + +def load_inputs(): + pins = bound_sources() + archive = ROOT / "research/community-frontier1042-audit/selected-replay.tar.gz" + values = [] + with tarfile.open(archive, "r:gz") as stream: + members = stream.getmembers() + need(len(members) <= 20000, "archive inventory capacity") + for name in ("CANONICAL-WORD.json.gz", "LOCAL-PROGRAMS.json.gz"): + matches = [m for m in members if m.name == "slots/local/" + name] + need(len(matches) == 1 and matches[0].isfile(), "unique regular member") + member = matches[0] + need(member.size <= 1024 * 1024, "compressed member capacity") + with stream.extractfile(member) as source: + with gzip.GzipFile(fileobj=source) as decoded: + raw = decoded.read(16 * 1024 * 1024 + 1) + need(len(raw) <= 16 * 1024 * 1024, "decoded member capacity") + values.append(json.loads(raw)) + path = ROOT / "research/k8-coherent-triples/CERTIFICATE.json" + inherited = json.loads(bounded_read(path, 1024 * 1024)) + return values[0], values[1], inherited, pins + + +def eligible(word, programs): + need((word["v"], word["R"]) == (112, 480), "source dimensions") + need(set(programs) == {"forward", "backward"}, "orientations") + excluded = set(word["centers"]) + for events in programs.values(): + need(len(events) <= 25000, "event capacity") + for event in events: + if event[0] == "residual_adapter": + excluded.add(event[2]) + if event[0] == "scalar" and event[1][0] in ("copy", "clear"): + excluded.update(r[1] for r in event[1][1:] + if isinstance(r, list) and r[0] == "L") + helpers = tuple(h for h in range(224, 704) if h not in excluded + and word["start"][h] == 0 and word["final"][h] == 1) + need(len(helpers) == 237, "eligible domain binding") + return helpers + + +def terms_from(events, helpers): + allowed = set(helpers) + terms = [] + for event in events: + if event[0] != "scalar" or event[1][0] != "add": + continue + gate = event[1] + a, denominator = abs(gate[3]), abs(gate[4]) + need(0 < a <= 2**64 and 0 < denominator <= 2**32, "nonzero dyadic coefficient") + need(denominator & (denominator - 1) == 0, "dyadic denominator") + valuation = (a & -a).bit_length() - 1 + exponent = valuation - (denominator.bit_length() - 1) + unit = a >> valuation == 1 + target, source = tuple(r[1] if r[0] == "L" and r[1] in allowed else -1 + for r in gate[1:3]) + if target != -1 or source != -1: + need(target != source and abs(exponent) <= 32, "ADD domain") + terms.append((unit, exponent, target, source)) + need(len(terms) <= 16000, "term capacity") + return tuple(terms) + + +def f(unit, exponent): + return abs(exponent) - int(unit and exponent == 0) + + +def objective(terms, gauges): + return 2 * sum(abs(k) for k in gauges.values()) + sum( + f(u, e + gauges.get(t, 0) - gauges.get(s, 0)) for u, e, t, s in terms) + + +def graph(terms, helpers, gauges): + incident = {h: Counter() for h in helpers} + pairs = {h: defaultdict(Counter) for h in helpers} + shared = defaultdict(Counter) + for unit, e, target, source in terms: + e += gauges.get(target, 0) - gauges.get(source, 0) + for h, other, sign in ((target, source, 1), (source, target, -1)): + if h in incident: + incident[h][unit, e, sign] += 1 + if other in incident: + pairs[h][other][unit, e, sign] += 1 + if target in incident and source in incident: + a, b = sorted((target, source)) + shared[a, b][unit, e, target == a] += 1 + return incident, pairs, shared + + +def slope(records, x, direction): + return sum(n * (f(u, e + sign*x) - f(u, e + sign*(x-direction))) + for (u, e, sign), n in records.items()) + + +def clipping(helpers, gauges, incident, pairs): + digest = sha256() + count, minimum = 0, None + for h in helpers: + radius = max([abs(gauges.get(h, 0)), 3] + [abs(e) for _, e, _ in incident[h]]) + 2 + need(radius <= 40, "clipping radius capacity") + for direction in (-1, 1): + minima = {b: min(slope(ts, x, direction) for x in range(-radius, radius+1)) + for b, ts in pairs[h].items()} + for magnitude in range(4, radius+1): + x = direction * magnitude + base = 2 * (abs(gauges.get(h, 0)+x) + - abs(gauges.get(h, 0)+x-direction)) + base += slope(incident[h], x, direction) + losses = sorted((max(0, slope(ts, x, direction)-minima[b]) + for b, ts in pairs[h].items()), reverse=True) + lower = base - sum(losses[:2]) + need(lower >= 0, "unbounded clipping premise") + minimum = lower if minimum is None else min(minimum, lower) + count += 1 + digest.update(f"{h},{direction},{x},{lower}\n".encode()) + return {"tested_slopes": count, "minimum_lower_bound": minimum, + "sha256": digest.hexdigest()} + + +def curves(helpers, gauges, incident, shared): + singles = {} + for h in helpers: + singles[h] = tuple(2*(abs(gauges.get(h, 0)+d)-abs(gauges.get(h, 0))) + + sum(n*(f(u, e+sign*d)-f(u, e)) + for (u, e, sign), n in incident[h].items()) + for d in SHIFTS) + corrections = {} + for edge, records in shared.items(): + row = [] + for a, b in product(SHIFTS, repeat=2): + value = sum(n*(f(u, e+(a-b if first else b-a)) + - f(u, e+(a if first else -a)) + - f(u, e+(-b if first else b)) + f(u, e)) + for (u, e, first), n in records.items()) + row.append(value) + corrections[edge] = tuple(row) + return singles, corrections + + +def pair_census(helpers, singles, corrections): + digest, histogram = sha256(), Counter() + count = 0 + for a, b in combinations(helpers, 2): + correction = corrections.get((a, b), ZERO) + minimum = min(singles[a][i]+singles[b][j]+correction[7*i+j] + for i in range(7) for j in range(7)) + need(minimum == 0, "improving unequal pair") + histogram[minimum] += 1 + digest.update(f"{a},{b}:{minimum}\n".encode()) + count += 1 + return {"pairs": count, "evaluations": 49*count, + "minimum_histogram": dict(histogram), "sha256": digest.hexdigest()} + + +def triple_census(helpers, singles, corrections): + adjacency = {h: set() for h in helpers} + for a, b in corrections: + adjacency[a].add(b) + adjacency[b].add(a) + triples = sorted({tuple(sorted((h, a, b))) for h in helpers + for a, b in combinations(sorted(adjacency[h]), 2)}) + need(len(triples) <= 60000, "connected triple capacity") + connected, disconnected = 0, 0 + for a, b, c in combinations(helpers, 3): + edges = int(b in adjacency[a])+int(c in adjacency[a])+int(c in adjacency[b]) + connected += int(edges >= 2) + disconnected += int(edges < 2) + need(connected == len(triples), "independent all-triple coverage") + digest, histogram = sha256(), Counter() + for a, b, c in triples: + ab = corrections.get((a, b), ZERO) + ac = corrections.get((a, c), ZERO) + bc = corrections.get((b, c), ZERO) + sa, sb, sc = singles[a], singles[b], singles[c] + minimum = 0 + for i in range(7): + for j in range(7): + fixed = sa[i]+sb[j]+ab[7*i+j] + for k in range(7): + value = fixed+sc[k]+ac[7*i+k]+bc[7*j+k] + minimum = min(minimum, value) + need(minimum == 0, "improving unequal triple") + histogram[minimum] += 1 + digest.update(f"{a},{b},{c}:{minimum}\n".encode()) + return {"connected_triples": len(triples), "disconnected_triples": disconnected, + "all_triples": connected+disconnected, "evaluations": 343*len(triples), + "minimum_histogram": dict(histogram), "sha256": digest.hexdigest()} + + +def decomposed_delta(shifts, singles, corrections): + total = sum(singles[h][d+3] for h, d in shifts.items()) + for a, b in combinations(sorted(shifts), 2): + total += corrections.get((a, b), ZERO)[7*(shifts[a]+3)+shifts[b]+3] + return total + + +def controls(): + rng = random.Random(1029) + comparisons = 0 + for _ in range(40): + helpers = (0, 1, 2) + gauges = {h: rng.randrange(-1, 2) for h in helpers} + terms = tuple((bool(rng.randrange(2)), rng.randrange(-2, 3), t, s) + for t, s in ((0, -1), (-1, 1), (0, 1), (2, 0), (1, 2))) + incident, _, shared = graph(terms, helpers, gauges) + singles, corrections = curves(helpers, gauges, incident, shared) + before = objective(terms, gauges) + for values in product(SHIFTS, repeat=3): + shifts = dict(zip(helpers, values)) + after = {h: gauges[h]+shifts[h] for h in helpers} + need(decomposed_delta(shifts, singles, corrections) + == objective(terms, after)-before, "literal objective control") + comparisons += 1 + need(f(True, 0) == -1 and f(False, 0) == 0, "point discount control") + terms = ((True, -1, 0, -1),) + need(objective(terms, {0: 1}) == objective(terms, {}), "paid boundary control") + need(f(True, 0)-f(True, -1) == -2, "boundary omission would improve") + bad = ((True, 10, 0, -1),) * 3 + incident, pairs, _ = graph(bad, (0,), {}) + try: + clipping((0,), {}, incident, pairs) + except ValueError as error: + need(str(error) == "unbounded clipping premise", "clipping rejection cause") + else: + raise ValueError("unjustified clipping accepted") + return {"synthetic_graphs": 40, "literal_comparisons": comparisons, + "tariff_controls": 3, "clipping_rejection_controls": 1} + + +def actual_clipping_controls(terms, helpers, gauges): + rng = random.Random(237) + before = objective(terms, gauges) + for _ in range(16): + chosen = rng.sample(helpers, 3) + shifts = {h: rng.choice((-2**32, -16, -7, -4, 4, 7, 16, 2**32)) for h in chosen} + changed = {h: gauges.get(h, 0)+shifts.get(h, 0) for h in helpers} + clipped = {h: gauges.get(h, 0)+max(-3, min(3, shifts.get(h, 0))) for h in helpers} + excess = sum(max(0, abs(d)-3) for d in shifts.values()) + need(objective(terms, changed)-objective(terms, clipped) >= 8*excess, + "literal large-shift clipping") + need(objective(terms, clipped) >= before, "literal clipped endpoint") + return 16 + + +def main(): + word, programs, inherited, pins = load_inputs() + helpers = eligible(word, programs) + need(tuple(inherited["eligible_helpers"]) == helpers, "predecessor domain") + results = {} + for orientation in ("forward", "backward"): + gauges = {int(h): k for h, k in inherited["orientations"][orientation]["gauges"].items()} + need(set(gauges) <= set(helpers), "gauge support") + need(all(type(k) is int and abs(k) <= 2 for k in gauges.values()), "gauge capacity") + terms = terms_from(programs[orientation], helpers) + incident, pairs, shared = graph(terms, helpers, gauges) + clip = clipping(helpers, gauges, incident, pairs) + need(clip["minimum_lower_bound"] >= 8, "quantitative eight-unit clipping") + singles, corrections = curves(helpers, gauges, incident, shared) + need(all(min(row) == 0 for row in singles.values()), "improving singleton") + results[orientation] = {"ADD_terms": len(terms), "helpers": len(helpers), + "interaction_edges": len(shared), "clipping": clip, + "singletons": {"count": len(helpers), "evaluations": 7*len(helpers)}, + "pairs": pair_census(helpers, singles, corrections), + "triples": triple_census(helpers, singles, corrections), + "large_shift_controls": actual_clipping_controls(terms, helpers, gauges)} + result = {"status": "PASS_K8_UNEQUAL_TRIPLE_CLOSURE", "orientations": results, + "controls": controls(), "sources": pins} + result["package_sha256"] = {p.name: sha256(bounded_read(p, 1024*1024)).hexdigest() + for p in sorted(HERE.iterdir()) if p.is_file()} + print(json.dumps(result, sort_keys=True)) + + +if __name__ == "__main__": + main()