From 0e80c6baa599d5b110401e1fd041fe45005984b7 Mon Sep 17 00:00:00 2001 From: Nick Petalas Date: Tue, 27 Oct 2026 11:21:13 +0000 Subject: [PATCH] feat(research): certify sharp mixed-rank touching envelopes --- .../mixed-rank-touching-envelope/EXAMPLE.json | 24 +++ .../mixed-rank-touching-envelope/PROOF.md | 121 ++++++++++++ .../mixed-rank-touching-envelope/README.md | 118 ++++++++++++ .../mixed-rank-touching-envelope/SOURCES.json | 18 ++ .../mixed-rank-touching-envelope/TASK.json | 118 ++++++++++++ .../mixed-rank-touching-envelope/VERIFY.json | 32 +++ .../mixed-rank-touching-envelope/envelope.py | 150 +++++++++++++++ .../mixed-rank-touching-envelope/verify.py | 182 ++++++++++++++++++ 8 files changed, 763 insertions(+) create mode 100644 research/mixed-rank-touching-envelope/EXAMPLE.json create mode 100644 research/mixed-rank-touching-envelope/PROOF.md create mode 100644 research/mixed-rank-touching-envelope/README.md create mode 100644 research/mixed-rank-touching-envelope/SOURCES.json create mode 100644 research/mixed-rank-touching-envelope/TASK.json create mode 100644 research/mixed-rank-touching-envelope/VERIFY.json create mode 100644 research/mixed-rank-touching-envelope/envelope.py create mode 100644 research/mixed-rank-touching-envelope/verify.py diff --git a/research/mixed-rank-touching-envelope/EXAMPLE.json b/research/mixed-rank-touching-envelope/EXAMPLE.json new file mode 100644 index 0000000000..5657901c04 --- /dev/null +++ b/research/mixed-rank-touching-envelope/EXAMPLE.json @@ -0,0 +1,24 @@ +{ + "schema": "synchronized-invoice-envelope/v1", + "old": { + "schema": "integer-mult-recursive-invoice/v1", + "contract": { + "model": "synthetic signed power invoice", + "boundary": "arithmetic example; no physical supplier", + "rank_semantics": "H_r costs r^t" + }, + "paid": {"4": 3, "9": 2, "7": 11}, + "targets": {"5": 13} + }, + "new": { + "schema": "integer-mult-recursive-invoice/v1", + "contract": { + "model": "synthetic signed power invoice", + "boundary": "arithmetic example; no physical supplier", + "rank_semantics": "H_r costs r^t" + }, + "paid": {"1": 6, "36": 1, "7": 11}, + "targets": {"5": 13} + }, + "certificate": {"bases": [2, 3], "p": 1, "q": 2, "scale": 1, "offset": 0} +} diff --git a/research/mixed-rank-touching-envelope/PROOF.md b/research/mixed-rank-touching-envelope/PROOF.md new file mode 100644 index 0000000000..da979b3ae5 --- /dev/null +++ b/research/mixed-rank-touching-envelope/PROOF.md @@ -0,0 +1,121 @@ +# Sharp synchronized mixed-rank invoice envelopes + +Let m be a positive even integer, let a_1,...,a_m be integers greater than +one, let p,q be integers with 00 and epsilon>=0 be real. +Define + +```text +D(t) = epsilon + lambda product_(i=1)^m (a_i^(q t) - a_i^p). +``` + +Then D has global minimum epsilon on the whole real line. Its unique minimizer +is t=p/q, which lies inside (0,1). If epsilon=0, its only real zero has exactly +m-fold multiplicity. If epsilon>0, D is strictly positive everywhere. + +## Proof + +Each factor is strictly increasing. It vanishes exactly at p/q, is negative +below p/q, and is positive above p/q. All m factors therefore have the same +nonzero sign away from p/q. Their product is positive because m is even. +At p/q the product vanishes. Positivity of lambda proves both the minimum +and its unique location. + +The derivative of the i-th factor at p/q is +q log(a_i) a_i^p>0. Its zero is simple. The product of m analytic functions +with simple zeros at the same point has a zero of exact multiplicity m. +Adding a positive epsilon removes all zeros, while leaving the minimizer +and the sharp lower envelope unchanged. This proves every claim. + +## Exact signed invoices + +Suppose lambda and epsilon are nonnegative integers, with lambda positive. +Expansion gives + +```text +D(t) = epsilon + lambda sum_(S subset {1,...,m}) + (-1)^(m-|S|) (product_(i not in S) a_i^p) + (product_(i in S) a_i^q)^t. +``` + +All ranks and signed coefficients are integers. Equal subset products must be +combined before comparison. No independence or distinctness of the bases is +assumed. Put positive coefficients into the new paid histogram and negated +negative coefficients into the old paid histogram. This realizes the signed +difference as two nonnegative integer invoices. More generally, the checker +accepts any placement in paid and target histograms whose full net difference +is this polynomial. Identical arbitrary paid and target charges on both sides +cancel. This is arithmetic realization, not a physical construction. + +For rational positive lambda and nonnegative epsilon, clearing their common +denominator gives the same integer-certificate form with the correspondingly +scaled envelope. The executable accepts the integer form only. + +## First mixed-rank example + +For m=2, a_1=2, a_2=3, p=1 and q=2, + +```text +6 - 3*4^t - 2*9^t + 36^t = (4^t-2)(9^t-3) >= 0. +``` + +Equality holds only at t=1/2 and has exact multiplicity two. Thus the seven-job +invoice 6 H1 + H36 costs at least the five-job invoice 3 H4 + 2 H9 for every +power tariff, with equality at sqrt-rank pricing. Adding one H1 to the former +gives sharp minimum gap one for every real t. Swapping the invoices reverses +the ordering, but is not claimed to implement a cheaper physical circuit. + +The ranks 4 and 9 are not powers of a common integer greater than one, since +that integer would have a prime divisor dividing both ranks. This supplies a +genuinely mixed-rank example. There are two coefficient sign changes, and +neither endpoint is zero. A closure rule using simple interior witnesses alone +cannot spend a two-root budget on this double zero. The factor certificate +supplies its multiplicity directly. This is an implication from the documented +certificate rules in #5788, not a replay or audit of its implementation. + +With two distinct prime bases a,b, arbitrary 01 and 00 and epsilon>=0, + +```text +epsilon + lambda product_i (a_i^(q t) - a_i^p) +``` + +has sharp global minimum epsilon, attained uniquely at t=p/q. At epsilon=0, +the unique zero has exact multiplicity m. The written [proof](PROOF.md) covers +all real t and arbitrary finite even m. This is a **scoped algebraic proof**, +with finite executable corroboration. It is an arithmetic side result, with +no physical construction or new kappa claim. + +The first example is + +```text +6 H1 + H36 - 3 H4 - 2 H9 + = (4^t-2)(9^t-3) >= 0, +``` + +where H_r costs r^t. Equality holds only at t=1/2 and is a double zero. Adding +one H1 makes the sharp minimum gap one. Ranks 4 and 9 have no common integer +base. This resolves the touching-point obligation for this explicit infinite +family without numeric root isolation or exhaustion of a global root budget. + +## Scope and predecessors + +The question is the touching-root continuation in Ali Romman's +[#5788](https://github.com/CrocSwap/integer-mult-bounds/pull/5788), pinned at +`56565b9aec29203bddb14f5d0e76a657d7090699`. Its +[proof and limitation](https://github.com/aliromman/integer-mult-bounds/blob/56565b9aec29203bddb14f5d0e76a657d7090699/docs/research/recursive-power-variation.md) +are cited, not audited or replayed. Credit zxv for signed-invoice accounting, +mightyOil for the moment-order context, and woklerx for the specialized +crossing predecessor. Elementary factorization and calculus retain their +classical status; no literature priority is claimed for those methods. + +This changes the `independent-moment` card from checking an existing supplier +to constructing a new exact invoice family and certificate. The card's first +selected-baseline binding command passed; no scientific predecessor replay +was run. [TASK.json](TASK.json) records the changed scope and source URL. +[SOURCES.json](SOURCES.json) binds the revision-8 catalogue and selected record +as historical provenance, with no live mathematical predecessor dependency. + +The complete signed difference is new paid minus new targets minus old paid +plus old targets. `envelope.py` requires equal declared contracts and exact +agreement with an independently supplied sparse factor certificate. Equal +subset-product ranks are combined, including repeated bases. The executable +reports the sharp envelope only after this identity check. Matching contract +text does not prove a source-to-circuit interpretation. + +## Reproduce + +From the repository root, with CPython 3.12 and the standard library: + +```sh +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -W error -B research/mixed-rank-touching-envelope/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -O -W error -B research/mixed-rank-touching-envelope/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/research_package.py --package research/mixed-rank-touching-envelope +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/check_research_commit.py --package research/mixed-rank-touching-envelope --check-source-history +``` + +The first two commands print a generated JSON receipt with package/input hashes, +then `PASS_MIXED_RANK_TOUCHING_ENVELOPE`. They enumerate 696 factor contexts, +4,176 certificates, 49,944 expanded support entries and 23,472 exact +rational-power evaluations, with 26 rejection or mathematical failure controls. +Two-factor contexts use every ordered pair of bases in 2..7, q in 2..5 and +1<=p 0 else (new, "targets") + else: + owner, kind = (new, "paid") if count > 0 else (old, "paid") + key = str(rank) + owner[kind][key] = owner[kind].get(key, 0) + abs(count) + return {"schema": "synchronized-invoice-envelope/v1", "old": old, "new": new, + "certificate": {"bases": list(bases), "p": p, "q": q, + "scale": scale, "offset": offset}} + + +def integer_root(value, q): + low, high = 1, value + for _ in range(31): + if low >= high: + break + middle = (low + high) // 2 + if middle**q < value: + low = middle + 1 + else: + high = middle + ensure(low == high and low**q == value, "rank is not an exact q-th power") + return low + + +def exact_points(doc, coefficients): + cert = doc["certificate"] + p, q = cert["p"], cert["q"] + roots = {rank: integer_root(rank, q) for rank in coefficients} + count = 0 + for numerator in sorted({-1, 0, p - 1, p, p + 1, q, q + 1}): + value = sum(Fraction(coefficient) * Fraction(roots[rank])**numerator + for rank, coefficient in coefficients.items()) + factor = Fraction(cert["scale"]) * prod( + Fraction(base)**numerator - base**p for base in cert["bases"]) + ensure(value == factor + cert["offset"], "rational-power evaluation disagrees") + ensure(value >= cert["offset"], "claimed envelope fails at exact point") + ensure((value == cert["offset"]) == (numerator == p), "wrong equality point") + count += 1 + return count + + +def positive_cases(): + contexts = [(bases, p, q) for bases in itertools.product(range(2, 8), repeat=2) + for q in range(2, 6) for p in range(1, q)] + for length in (4, 6, 8): + contexts.extend((bases, 1, 2) for bases in itertools.product((2, 3), repeat=length)) + cases = points = terms = 0 + for bases, p, q in contexts: + for scale, offset in itertools.product((1, 3), (0, 1, 7)): + doc = document(bases, p, q, scale, offset, bool(cases % 2)) + coefficients = subset_expansion(bases, p, q, scale, offset) + result = envelope.check(doc) + ensure(envelope.expand(doc["certificate"]) == coefficients, "expansions differ") + ensure(result["minimum"] == offset, "wrong minimum") + ensure(result["root_multiplicity"] == (len(bases) if offset == 0 else 0), + "wrong multiplicity") + points += exact_points(doc, coefficients) + terms += len(coefficients) + cases += 1 + return {"contexts": len(contexts), "certificates": cases, + "exact_rational_points": points, "expanded_support_entries": terms} + + +def rejected(call): + try: + call() + except (ValueError, TypeError): + return + raise ValueError("invalid certificate was accepted") + + +def negative_cases(example): + mutations = [] + for key, value in (("bases", [2, 3, 5]), ("bases", [True, 3]), + ("bases", [1, 3]), ("bases", [2] * 10), + ("bases", [64, 64]), ("p", 0), ("p", 2), + ("q", 17), ("scale", 0), ("scale", True), + ("offset", -1), ("offset", 1)): + candidate = copy.deepcopy(example) + candidate["certificate"][key] = value + if value == [64, 64]: + candidate["certificate"]["q"] = 16 + mutations.append(candidate) + for side, kind, key, value in (("new", "targets", "5", 12), + ("old", "targets", "5", 12), + ("new", "paid", "36", 2), + ("old", "paid", "4", True), + ("old", "paid", "04", 3), + ("new", "paid", "1000000001", 1), + ("new", "paid", "2", 10**60 + 1)): + candidate = copy.deepcopy(example) + candidate[side][kind][key] = value + mutations.append(candidate) + candidate = copy.deepcopy(example) + candidate["new"]["contract"]["model"] = "changed model" + mutations.append(candidate) + candidate = copy.deepcopy(example) + candidate["certificate"]["untrusted_claim"] = "positive" + mutations.append(candidate) + for candidate in mutations: + rejected(lambda: envelope.check(candidate)) + for raw in (b'{"x":1,"x":2}', b'{"x":1.0}', b'{"x":NaN}', b' ' * (1024**2 + 1)): + rejected(lambda: envelope.decode(raw)) + ensure(prod(Fraction(a)**0 - a for a in (2, 3, 5)) < 0, "odd-factor control fails") + return len(mutations) + 5 + + +def cli_case(): + path = ROOT / "EXAMPLE.json" + result = subprocess.run([sys.executable, "-I", "-W", "error", "-B", + str(ROOT / "envelope.py"), str(path)], + check=True, capture_output=True, text=True, timeout=15) + parsed = json.loads(result.stdout) + ensure(parsed["input_sha256"] == hashlib.sha256(path.read_bytes()).hexdigest(), + "CLI input hash differs") + ensure(parsed["minimum"] == 0 and parsed["root_multiplicity"] == 2, "wrong CLI envelope") + return parsed + + +def main(): + example, digest = envelope.load(ROOT / "EXAMPLE.json") + ensure(envelope.check(example)["support_size"] == 4, "example support differs") + stats = positive_cases() + stats["rejection_controls"] = negative_cases(example) + stats["example_input_sha256"] = digest + stats["cli"] = cli_case() + names = ("envelope.py", "verify.py", "PROOF.md", "README.md", "TASK.json", + "SOURCES.json", "VERIFY.json", "EXAMPLE.json") + stats["package_sha256"] = {name: hashlib.sha256((ROOT / name).read_bytes()).hexdigest() + for name in names} + print(json.dumps(stats, indent=2, sort_keys=True)) + print("PASS_MIXED_RANK_TOUCHING_ENVELOPE") + + +if __name__ == "__main__": + main()