# regions.py -- job #8: exact-rational bookkeeping for research/grouped-divisor-moment.md (14)-(19) # and research/TWIN-REDUCTION.md section 3. Fractions only; regions are handled as convex polygons, # not sampled. Box: U < d <= D0 ~ x^(19/25), Y < e <= E0 ~ x^(19/20) (RESEARCH-HANDOFF.md section 3). from fractions import Fraction as F from itertools import combinations import sys BOX = [(-1, 0, -F(6, 25)), (1, 0, F(19, 25)), (0, -1, -F(1, 20)), (0, 1, F(19, 20))] # alpha*d + beta*n <= c def budgets(d, n, side="right"): a, b = d + F(6, 25), n + F(1, 20) if side == "left": a, b = b, a return ((1 + a) / 2, a / 2 + 3 * b / 2, a) def poly(hs): """Vertices (CCW) of the closed convex polygon {alpha*d + beta*n <= c for (alpha, beta, c) in hs}.""" pts = set() for (a1, b1, c1), (a2, b2, c2) in combinations(hs, 2): det = F(a1) * b2 - F(a2) * b1 if det == 0: continue d = (F(c1) * b2 - F(c2) * b1) / det; n = (F(a1) * c2 - F(a2) * c1) / det if all(a * d + b * n <= c for a, b, c in hs): pts.add((d, n)) pts = sorted(pts) if len(pts) < 3: return pts def cross(o, p, q): return (p[0] - o[0]) * (q[1] - o[1]) - (p[1] - o[1]) * (q[0] - o[0]) lo, up = [], [] for p in pts: while len(lo) >= 2 and cross(lo[-2], lo[-1], p) <= 0: lo.pop() lo.append(p) for p in reversed(pts): while len(up) >= 2 and cross(up[-2], up[-1], p) <= 0: up.pop() up.append(p) return lo[:-1] + up[:-1] def area(v): return abs(sum(v[i][0] * v[(i + 1) % len(v)][1] - v[(i + 1) % len(v)][0] * v[i][1] for i in range(len(v)))) / 2 if len(v) >= 3 else F(0) def extreme(v, f, best=min): val = best(f(*p) for p in v); return val, [p for p in v if f(*p) == val] def fmt(p): return "(" + ", ".join(str(t) for t in p) + ")" ge = lambda a, b, c: (-a, -b, -c) # a*d + b*n >= c print("== 1. budgets -> regions (right orientation; left swaps a, b) ==") for side in ("right", "left"): names = ("zero (1+a)/2", "cross a/2+3b/2", "period a") for k, name in enumerate(names): # budget is affine: B(d, n) = B0 + Bd*d + Bn*n; B < 1 <=> Bd*d + Bn*n < 1 - B0 B0 = budgets(F(0), F(0), side)[k]; Bd = budgets(F(1), F(0), side)[k] - B0; Bn = budgets(F(0), F(1), side)[k] - B0 s = max(abs(Bd), abs(Bn)) print(f" {side:5} {name:15}: {Bd/s}*delta + {Bn/s}*nu < {(1-B0)/s}", file=sys.stderr) print(" note (15): delta < 19/25, delta + 3 nu < 161/100; left: 3 delta + nu < 123/100 (and nu < 19/20)") print("== 2. left region inside the old region 5 delta + 2 nu < 123/50 ==") Lp = poly(BOX + [(3, 1, F(123, 100))]) mx, at = extreme(Lp, lambda d, n: 5 * d + 2 * n, max) print(f" max of 5 delta + 2 nu on closure(left region) cap box = {mx} at {[fmt(p) for p in at]}; < 123/50: {mx < F(123, 50)}") print(f" note's bound 246/100 - delta <= 222/100 uses delta >= 6/25: max 2(3d+n)-d on box = {F(246,100) - F(6,25)}") print("== 3. uniform product threshold of the strict union ==") # complement of {d+n<19/25} u {5d+2n<123/50} u {d<19/25 and d+3n<161/100} = P1 u P2 (closures) P1 = poly(BOX + [ge(1, 1, F(19, 25)), ge(5, 2, F(123, 50)), ge(1, 0, F(19, 25))]) P2 = poly(BOX + [ge(1, 1, F(19, 25)), ge(5, 2, F(123, 50)), ge(1, 3, F(161, 100))]) for name, P in (("P1 (delta >= 19/25)", P1), ("P2 (delta + 3nu >= 161/100)", P2)): m, at = extreme(P, lambda d, n: d + n) if P else (None, []) print(f" {name}: min delta+nu = {m} on {[fmt(p) for p in at]}; area {area(P)}") w = (F(8, 25), F(11, 25)) print(f" witness {fmt(w)}: delta+nu = {sum(w)}, 5d+2n = {5*w[0]+2*w[1]}, d+3n = {w[0]+3*w[1]}, in closure(P2) as a point of the argmin segment: " f"{all(a*w[0]+b*w[1] <= c for a,b,c in BOX + [ge(1,1,F(19,25)), ge(5,2,F(123,50)), ge(1,3,F(161,100))])}") print("== 4. the concrete cuts (19): what they leave in E_dagger ==") Q1 = poly(BOX + [ge(1, 1, F(3, 4)), ge(5, 2, F(49, 20)), ge(1, 0, F(151, 200))]) Q2 = poly(BOX + [ge(1, 1, F(3, 4)), ge(5, 2, F(49, 20)), ge(1, 3, F(321, 200))]) Q12 = poly(BOX + [ge(1, 1, F(3, 4)), ge(5, 2, F(49, 20)), ge(1, 0, F(151, 200)), ge(1, 3, F(321, 200))]) for name, P in (("Q1 (d > x^151/200)", Q1), ("Q2 (de^3 > x^321/200)", Q2)): m, at = extreme(P, lambda d, n: d + n) print(f" {name}: min delta+nu = {m} on {[fmt(p) for p in at]}") W3 = area(Q1) + area(Q2) - area(Q12); U3 = area(P1) + area(P2) - area(poly(BOX + [ge(1,1,F(19,25)), ge(5,2,F(123,50)), ge(1,0,F(19,25)), ge(1,3,F(161,100))])) print(f" area: box {area(poly(BOX))}, W_dagger(three cuts) {W3} = {float(W3):.6f}, strict-uncovered {U3} = {float(U3):.6f}, " f"controlled but retained by the margins {W3 - U3} = {float(W3 - U3):.6f}") S = poly(BOX + [ge(1, 1, F(3, 4)), (1, 1, F(19, 25)), ge(5, 2, F(49, 20)), ge(1, 3, F(321, 200))]) print(f" strip below the product threshold kept in E_dagger: 3/4 <= d+n <= 19/25, 5d+2n >= 49/20, d+3n >= 321/200: vertices {[fmt(p) for p in S]}, area {area(S)}") print(f" fourth W_dagger condition (d > x^141/200 or de^3 > x^1631/1000 or de <= x^77/100) holds on all of it: max d+n = {extreme(S, lambda d,n: d+n, max)[0]} <= 77/100") pt = (F(32, 100), F(435, 1000)) print(f" sample {fmt(pt)}: d+n = {sum(pt)}, budgets right = {[str(b) for b in budgets(*pt)]}, 5d+2n = {5*pt[0]+2*pt[1]}, d+3n = {pt[0]+3*pt[1]}") print("== 5. slack of each cut and the controlled point nearest to failure ==") C = poly(BOX + [(1, 0, F(151, 200)), (1, 3, F(321, 200))]) for k, name in enumerate(("zero", "cross", "period")): m, at = extreme(C, lambda d, n: budgets(d, n)[k], max) print(f" cut C: max right {name} budget = {m} (slack {1 - m}) at {[fmt(p) for p in at]}") print(f" exponent slack: A {F(19,25) - F(3,4)} in delta+nu; B {F(123,50) - F(49,20)} in 5delta+2nu; kappa {F(19,25) - F(151,200)}; lambda {F(161,100) - F(321,200)}") corner = (F(151, 200), (F(321, 200) - F(151, 200)) / 3) print(f" corner of C {fmt(corner)}: budgets {[str(b) for b in budgets(*corner)]}; outside cut A: {sum(corner) > F(3,4)}; outside cut B: {5*corner[0]+2*corner[1] > F(49,20)}") print("== 6. named points in the notes ==") for name, p in (("benchmark (2/5, 2/5)", (F(2, 5), F(2, 5))), ("section 6 (8/25, 9/20)", (F(8, 25), F(9, 20))), ("witness (8/25, 11/25)", (F(8, 25), F(11, 25))), ("vertical control (19/25, 1/20)", (F(19, 25), F(1, 20)))): d, n = p; r = budgets(d, n); l = budgets(d, n, "left") strict = (d + n < F(19, 25), 5 * d + 2 * n < F(123, 50), d < F(19, 25) and d + 3 * n < F(161, 100)) cuts = (d + n <= F(3, 4), 5 * d + 2 * n <= F(49, 20), d <= F(151, 200) and d + 3 * n <= F(321, 200)) print(f" {name}: right {[str(b) for b in r]}, left {[str(b) for b in l]}, strict regions {strict}, cut sets {cuts}") print(f" 397/400 = 103/100 - 3/80: {F(103,100) - F(3,80) == F(397,400)}; deficit 3/2 - 36/25 = {F(3,2) - F(36,25)}; " f"36/25 = 2 - 14/25: {2 - F(14,25) == F(36,25)}; A ~ x^(14/25 + 1/2 - 1) = x^{F(14,25) + F(1,2) - 1}") print(f" TWIN-REDUCTION section 4, p = 19/25 - delta: right zero = 1 - p/2 and period = 1 - p: " f"{all(budgets(d, F(1,3))[0] == 1 - (F(19,25)-d)/2 and budgets(d, F(1,3))[2] == 1 - (F(19,25)-d) for d in (F(1,4), F(1,2), F(3,4)))}") print("== 7. the validator's coverage grid, recomputed ==") g = new = 0; disagree = 0 for i in range(240, 761, 2): for j in range(50, 951, 2): d, n = F(i, 1000), F(j, 1000) covered = all(b < 1 for b in budgets(d, n)) claim = d < F(19, 25) and d + 3 * n < F(161, 100) disagree += covered != claim old = d + n < F(19, 25) or 5 * d + 2 * n < F(123, 50) new += covered and not old; g += 1 print(f" grid points {g}, points added {new}, budget/region disagreements {disagree} (validator prints 117711 and 14752)")