Download certificate_impl.py from PureOne/Aeonixi-1.0-Shuffled-Regression: direct link, hf CLI and curl.
- Browser
- Download file 22.8 kB
-
https://huggingface.co/datasets/PureOne/Aeonixi-1.0-Shuffled-Regression/resolve/main/certificate_impl.py
- Command line
-
hf download hf://datasets/PureOne/Aeonixi-1.0-Shuffled-Regression/certificate_impl.py
-
curl -L -o certificate_impl.py https://huggingface.co/datasets/PureOne/Aeonixi-1.0-Shuffled-Regression/resolve/main/certificate_impl.py
22.8 kB
| """Exact rational certification for partial shuffled least-squares regression. | |
| Reference implementation for small instances. All arithmetic is fractions.Fraction; | |
| there are no numerical rank tolerances. The assignment bounds are polynomial-time, | |
| but the complete branch-and-bound search is exponential in the worst case. | |
| Rows of X and Y are vectors; k is the required matching cardinality. The returned | |
| objective is the sum of squared errors, not its square root. No external packages | |
| are required. Run this file for deterministic exhaustive validation. | |
| """ | |
| from fractions import Fraction as Q | |
| from itertools import combinations, permutations | |
| import json | |
| import random | |
| def rat_matrix(A): | |
| return [[Q(x) for x in row] for row in A] | |
| def transpose(A): | |
| return [list(c) for c in zip(*A)] | |
| def mul(A, B): | |
| BT = transpose(B) | |
| return [[sum((a*b for a, b in zip(row, col)), Q(0)) | |
| for col in BT] for row in A] | |
| def pivot_columns(A): | |
| C = [row[:] for row in A] | |
| if not C: | |
| return [] | |
| h, w = len(C), len(C[0]) | |
| pivots, i = [], 0 | |
| for j in range(w): | |
| p = next((p for p in range(i, h) if C[p][j]), None) | |
| if p is None: | |
| continue | |
| C[i], C[p] = C[p], C[i] | |
| s = C[i][j] | |
| C[i] = [a/s for a in C[i]] | |
| for t in range(h): | |
| if t != i and C[t][j]: | |
| s = C[t][j] | |
| C[t] = [a-s*b for a, b in zip(C[t], C[i])] | |
| pivots.append(j) | |
| i += 1 | |
| if i == h: | |
| break | |
| return pivots | |
| def inverse(A): | |
| n = len(A) | |
| C = [row[:] + [Q(i == j) for j in range(n)] | |
| for i, row in enumerate(A)] | |
| for j in range(n): | |
| p = next((p for p in range(j, n) if C[p][j]), None) | |
| if p is None: | |
| raise ValueError('singular matrix') | |
| C[j], C[p] = C[p], C[j] | |
| s = C[j][j] | |
| C[j] = [a/s for a in C[j]] | |
| for i in range(n): | |
| if i != j and C[i][j]: | |
| s = C[i][j] | |
| C[i] = [a-s*b for a, b in zip(C[i], C[j])] | |
| return [row[n:] for row in C] | |
| def norm2(v): | |
| return sum((x*x for x in v), Q(0)) | |
| class Anchor: | |
| """Exact LS fit, including a rational representation of its row space. | |
| A = A_K H, H[:, K] = I. Hence x is in row(A) iff x = x_K H. | |
| For such x, leverage is x_K (A_K^T A_K)^-1 x_K^T. | |
| """ | |
| def __init__(self, A, B, d, m): | |
| self.d, self.m = d, m | |
| self.K = pivot_columns(A) | |
| self.rank = len(self.K) | |
| if not self.K: | |
| self.Ginv, self.H, self.L = [], [], [] | |
| self.F = sum((norm2(y) for y in B), Q(0)) | |
| else: | |
| C = [[row[j] for j in self.K] for row in A] | |
| CT = transpose(C) | |
| self.Ginv = inverse(mul(CT, C)) | |
| plus = mul(self.Ginv, CT) | |
| self.H = mul(plus, A) | |
| self.L = mul(plus, B) | |
| predicted = mul(C, self.L) | |
| self.F = sum((norm2([a-b for a, b in zip(y, z)]) | |
| for y, z in zip(B, predicted)), Q(0)) | |
| def coefficients(self): | |
| W = [[Q(0) for _ in range(self.m)] for _ in range(self.d)] | |
| for j, col in enumerate(self.K): | |
| W[col] = self.L[j][:] | |
| return W | |
| def edge(self, x, y, q=1): | |
| """Minimum of (anchor excess)/q + squared error of this edge.""" | |
| if not self.K: | |
| return norm2(y) if not any(x) else Q(0) | |
| xK = [[x[j] for j in self.K]] | |
| if mul(xK, self.H)[0] != x: | |
| return Q(0) # An unconstrained nullspace direction fits this row. | |
| z = mul(xK, self.L)[0] | |
| ell = mul(mul(xK, self.Ginv), transpose(xK))[0][0] | |
| return norm2([a-b for a, b in zip(y, z)]) / (1 + q*ell) | |
| def hungarian(C): | |
| """Square rational LAP with primal permutation and feasible optimal dual.""" | |
| n = len(C) | |
| if not n: | |
| return {'value': Q(0), 'perm': [], 'u': [], 'v': []} | |
| assert all(len(row) == n for row in C) | |
| u, v = [Q(0)]*(n+1), [Q(0)]*(n+1) | |
| p, way = [0]*(n+1), [0]*(n+1) | |
| for i in range(1, n+1): | |
| p[0], j0 = i, 0 | |
| minv, used = [None]*(n+1), [False]*(n+1) | |
| while True: | |
| used[j0] = True | |
| i0, delta, j1 = p[j0], None, 0 | |
| for j in range(1, n+1): | |
| if not used[j]: | |
| cur = C[i0-1][j-1] - u[i0] - v[j] | |
| if minv[j] is None or cur < minv[j]: | |
| minv[j], way[j] = cur, j0 | |
| if delta is None or minv[j] < delta: | |
| delta, j1 = minv[j], j | |
| for j in range(n+1): | |
| if used[j]: | |
| u[p[j]] += delta | |
| v[j] -= delta | |
| elif minv[j] is not None: | |
| minv[j] -= delta | |
| j0 = j1 | |
| if p[j0] == 0: | |
| break | |
| while True: | |
| j1 = way[j0] | |
| p[j0] = p[j1] | |
| j0 = j1 | |
| if j0 == 0: | |
| break | |
| perm = [0]*n | |
| for j in range(1, n+1): | |
| perm[p[j]-1] = j-1 | |
| value = sum((C[i][perm[i]] for i in range(n)), Q(0)) | |
| return {'value': value, 'perm': perm, 'u': u[1:], 'v': v[1:]} | |
| def verify_lap(C, cert): | |
| n = len(C) | |
| p, u, v = cert['perm'], cert['u'], cert['v'] | |
| return (all(isinstance(x, (int, Q)) for x in u+v+[cert['value']]) | |
| and all(type(j) is int for j in p) | |
| and sorted(p) == list(range(n)) and len(u) == len(v) == n | |
| and all(u[i]+v[j] <= C[i][j] for i in range(n) for j in range(n)) | |
| and sum((C[i][p[i]] for i in range(n)), Q(0)) == cert['value'] | |
| and sum(u, Q(0))+sum(v, Q(0)) == cert['value']) | |
| def padded_cost(C, q): | |
| n, m = len(C), len(C[0]) | |
| assert 1 <= q <= min(n, m) | |
| assert all(c >= 0 for row in C for c in row) | |
| forbidden = 1 + sum((sum(row, Q(0)) for row in C), Q(0)) | |
| return ([row[:] + [Q(0)]*(n-q) for row in C] | |
| + [[Q(0)]*m + [forbidden]*(n-q) for _ in range(m-q)]) | |
| def partial_assignment(C, q): | |
| padded = padded_cost(C, q) | |
| cert = hungarian(padded) | |
| n, m = len(C), len(C[0]) | |
| edges = [(i, j) for i, j in enumerate(cert['perm']) if i < n and j < m] | |
| assert len(edges) == q and verify_lap(padded, cert) | |
| return {'value': cert['value'], 'edges': edges, 'lap': cert} | |
| def maximum_matching(adj, m): | |
| n = len(adj) | |
| right = [-1]*m | |
| def augment(i, seen): | |
| for j in adj[i]: | |
| if j not in seen: | |
| seen.add(j) | |
| if right[j] < 0 or augment(right[j], seen): | |
| right[j] = i | |
| return True | |
| return False | |
| for i in range(n): | |
| augment(i, set()) | |
| left = [-1]*n | |
| for j, i in enumerate(right): | |
| if i >= 0: | |
| left[i] = j | |
| # Konig certificate: alternating reachability from unmatched left vertices. | |
| seenL = {i for i in range(n) if left[i] < 0} | |
| seenR = set() | |
| stack = list(seenL) | |
| while stack: | |
| i = stack.pop() | |
| for j in adj[i]: | |
| if j != left[i] and j not in seenR: | |
| seenR.add(j) | |
| if right[j] >= 0 and right[j] not in seenL: | |
| seenL.add(right[j]) | |
| stack.append(right[j]) | |
| pairs = [(i, j) for i, j in enumerate(left) if j >= 0] | |
| coverL = sorted(set(range(n))-seenL) | |
| coverR = sorted(seenR) | |
| assert len(pairs) == len(coverL)+len(coverR) | |
| return pairs, coverL, coverR | |
| def bottleneck_assignment(C, q): | |
| n, m = len(C), len(C[0]) | |
| values = sorted(set(c for row in C for c in row)) | |
| lo, hi = 0, len(values)-1 | |
| while lo < hi: | |
| mid = (lo+hi)//2 | |
| adj = [[j for j in range(m) if C[i][j] <= values[mid]] for i in range(n)] | |
| pairs, _, _ = maximum_matching(adj, m) | |
| if len(pairs) >= q: | |
| hi = mid | |
| else: | |
| lo = mid+1 | |
| t = values[lo] | |
| pairs, _, _ = maximum_matching( | |
| [[j for j in range(m) if C[i][j] <= t] for i in range(n)], m) | |
| lowpairs, coverL, coverR = maximum_matching( | |
| [[j for j in range(m) if C[i][j] < t] for i in range(n)], m) | |
| assert len(lowpairs) < q | |
| return {'value': t, 'edges': pairs[:q], 'cover_left': coverL, | |
| 'cover_right': coverR} | |
| def verify_bottleneck(C, q, cert): | |
| t, edges = cert['value'], cert['edges'] | |
| L, R = set(cert['cover_left']), set(cert['cover_right']) | |
| n, m = len(C), len(C[0]) | |
| return (isinstance(t, (int, Q)) and 1 <= q <= min(n, m) | |
| and all(type(i) is int and 0 <= i < n for i in L) | |
| and all(type(j) is int and 0 <= j < m for j in R) | |
| and all(type(i) is int and type(j) is int | |
| and 0 <= i < n and 0 <= j < m for i, j in edges) | |
| and len(edges) == q and len({i for i, j in edges}) == q | |
| and len({j for i, j in edges}) == q | |
| and all(C[i][j] <= t for i, j in edges) | |
| and len(L)+len(R) < q | |
| and all(C[i][j] >= t or i in L or j in R | |
| for i in range(n) for j in range(m))) | |
| def fit(X, Y, P): | |
| return Anchor([X[i] for i, j in P], [Y[j] for i, j in P], len(X[0]), len(Y[0])) | |
| def node_bound(X, Y, P, sources, targets, q): | |
| anchor = fit(X, Y, P) | |
| if q == 0: | |
| return {'value': anchor.F, 'anchor': anchor, 'completion': []} | |
| summed = [[anchor.edge(X[i], Y[j], q) for j in targets] for i in sources] | |
| singleton = [[anchor.edge(X[i], Y[j], 1) for j in targets] for i in sources] | |
| ac = partial_assignment(summed, q) | |
| bc = bottleneck_assignment(singleton, q) | |
| assert verify_bottleneck(singleton, q, bc) | |
| return {'value': anchor.F+max(ac['value'], bc['value']), 'anchor': anchor, | |
| 'sum_certificate': ac, 'bottleneck_certificate': bc, | |
| 'sum_costs': summed, 'singleton_costs': singleton, | |
| 'completion': [(sources[i], targets[j]) for i, j in ac['edges']]} | |
| def exact_solve(X, Y, k, bound_mode='combined', retain_proof=False): | |
| """Exact search with all optimal ties, rational lower bounds, and statistics. | |
| Traverses source indices in order; each source is either omitted or assigned | |
| to an unused target. A node is pruned only when its lower bound is strictly | |
| greater than the current incumbent, preserving all optimal ties. | |
| """ | |
| if bound_mode not in ('anchor', 'bottleneck', 'combined'): | |
| raise ValueError('unknown bound mode') | |
| X, Y = rat_matrix(X), rat_matrix(Y) | |
| n, m = len(X), len(Y) | |
| assert 1 <= k <= min(n, m) | |
| initial = tuple((i, i) for i in range(k)) | |
| best = fit(X, Y, initial).F | |
| optimal = {initial} | |
| stats = {'nodes': 0, 'bound_prunes': 0, 'leaves': 0, | |
| 'lap_certificates_checked': 0, 'hall_certificates_checked': 0} | |
| def consider(P): | |
| nonlocal best, optimal | |
| F = fit(X, Y, P).F | |
| key = tuple(P) | |
| if F < best: | |
| best, optimal = F, {key} | |
| elif F == best: | |
| optimal.add(key) | |
| def visit(start, targets, P): | |
| stats['nodes'] += 1 | |
| q = k-len(P) | |
| if q == 0: | |
| stats['leaves'] += 1 | |
| consider(P) | |
| return {'kind': 'leaf', 'objective': fit(X, Y, P).F} if retain_proof else None | |
| if n-start < q or len(targets) < q: | |
| return {'kind': 'infeasible'} if retain_proof else None | |
| cert = node_bound(X, Y, P, list(range(start, n)), targets, q) | |
| stats['lap_certificates_checked'] += 1 | |
| stats['hall_certificates_checked'] += 1 | |
| consider(sorted(P+cert['completion'])) | |
| lower = cert['anchor'].F | |
| if bound_mode == 'bottleneck': | |
| lower += cert['bottleneck_certificate']['value'] | |
| elif bound_mode == 'combined': | |
| lower = cert['value'] | |
| if lower > best: | |
| stats['bound_prunes'] += 1 | |
| return ({'kind': 'prune', 'lower_bound': lower, | |
| 'sum_lap': cert['sum_certificate']['lap'], | |
| 'bottleneck': cert['bottleneck_certificate']} | |
| if retain_proof else None) | |
| # The skip branch exists precisely when enough source rows remain. | |
| children = [] | |
| skipped = None | |
| if n-start > q: | |
| skipped = visit(start+1, targets, P) | |
| for j in targets: | |
| child = visit(start+1, [t for t in targets if t != j], P+[(start, j)]) | |
| if retain_proof: | |
| children.append({'target': j, 'node': child}) | |
| return ({'kind': 'branch', 'skip': skipped, 'assign': children} | |
| if retain_proof else None) | |
| proof = visit(0, list(range(m)), []) | |
| canonical = min(optimal) | |
| return {'objective': best, 'matching': canonical, | |
| 'coefficients': fit(X, Y, canonical).coefficients(), | |
| 'all_optima': sorted(optimal), 'stats': stats, 'bound_mode': bound_mode, | |
| 'proof_tree': proof} | |
| def verify_proof(X, Y, k, result): | |
| """Check a complete search transcript without running search or assignment. | |
| Verification is polynomial in transcript length and rational bit lengths; | |
| the transcript itself can be exponentially large. This checker verifies | |
| exact optimality and completeness of the stated optimal-tie list. | |
| """ | |
| try: | |
| X, Y = rat_matrix(X), rat_matrix(Y) | |
| n, m = len(X), len(Y) | |
| if (not X or not Y or not X[0] or not Y[0] | |
| or any(len(row) != len(X[0]) for row in X) | |
| or any(len(row) != len(Y[0]) for row in Y) | |
| or type(k) is not int or not 1 <= k <= min(n, m)): | |
| return False | |
| if result['bound_mode'] not in ('anchor', 'bottleneck', 'combined'): | |
| return False | |
| optimum = result['objective'] | |
| Pstar = [tuple(e) for e in result['matching']] | |
| if (not isinstance(optimum, (int, Q)) or optimum < 0 | |
| or len(Pstar) != k or len({i for i, j in Pstar}) != k | |
| or len({j for i, j in Pstar}) != k | |
| or not all(type(i) is int and type(j) is int | |
| and 0 <= i < n and 0 <= j < m for i, j in Pstar) | |
| or fit(X, Y, Pstar).F != optimum): | |
| return False | |
| W = result['coefficients'] | |
| if (len(W) != len(X[0]) or any(len(row) != len(Y[0]) for row in W) | |
| or not all(isinstance(a, (int, Q)) for row in W for a in row)): | |
| return False | |
| actual = sum((norm2([a-b for a, b in zip(mul([X[i]], W)[0], Y[j])]) | |
| for i, j in Pstar), Q(0)) | |
| if actual != optimum: | |
| return False | |
| except (KeyError, TypeError, IndexError, ValueError, ZeroDivisionError): | |
| return False | |
| found_ties = set() | |
| def check(node, start, targets, P): | |
| q = k-len(P) | |
| kind = node['kind'] | |
| if q == 0: | |
| F = fit(X, Y, P).F | |
| if kind != 'leaf' or node['objective'] != F or F < optimum: | |
| return False | |
| if F == optimum: | |
| found_ties.add(tuple(P)) | |
| return True | |
| if n-start < q or len(targets) < q: | |
| return kind == 'infeasible' | |
| if kind == 'prune': | |
| anchor = fit(X, Y, P) | |
| sources = list(range(start, n)) | |
| C = [[anchor.edge(X[i], Y[j], q) for j in targets] for i in sources] | |
| D = [[anchor.edge(X[i], Y[j], 1) for j in targets] for i in sources] | |
| ac, bc = node['sum_lap'], node['bottleneck'] | |
| if not verify_lap(padded_cost(C, q), ac) or not verify_bottleneck(D, q, bc): | |
| return False | |
| mode = result['bound_mode'] | |
| increment = (Q(0) if mode == 'anchor' else bc['value'] | |
| if mode == 'bottleneck' else max(ac['value'], bc['value'])) | |
| lower = anchor.F+increment | |
| return lower == node['lower_bound'] and lower > optimum | |
| if kind != 'branch' or [c['target'] for c in node['assign']] != targets: | |
| return False | |
| if n-start > q: | |
| if node['skip'] is None or not check(node['skip'], start+1, targets, P): | |
| return False | |
| elif node['skip'] is not None: | |
| return False | |
| return all(check(c['node'], start+1, | |
| [t for t in targets if t != c['target']], | |
| P+[(start, c['target'])]) for c in node['assign']) | |
| try: | |
| good = check(result['proof_tree'], 0, list(range(m)), []) | |
| declared = {tuple(tuple(e) for e in P) for P in result['all_optima']} | |
| return good and found_ties == declared | |
| except (KeyError, TypeError, IndexError, ValueError, ZeroDivisionError): | |
| return False | |
| def json_encode(obj): | |
| if isinstance(obj, Q): | |
| return {'rational': [obj.numerator, obj.denominator]} | |
| raise TypeError(type(obj).__name__) | |
| def json_decode(obj): | |
| if set(obj) == {'rational'}: | |
| return Q(*obj['rational']) | |
| return obj | |
| def enumerate_matchings(sources, targets, k): | |
| for I in combinations(sources, k): | |
| for J in permutations(targets, k): | |
| yield tuple(zip(I, J)) | |
| def exhaustive_solve(X, Y, k): | |
| best, opt = None, [] | |
| for P in enumerate_matchings(range(len(X)), range(len(Y)), k): | |
| F = fit(X, Y, P).F | |
| if best is None or F < best: | |
| best, opt = F, [P] | |
| elif F == best: | |
| opt.append(P) | |
| return best, sorted(opt) | |
| def validation_suite(seed=731, count=40): | |
| rng = random.Random(seed) | |
| report = {'seed': seed, 'random_instances': count, 'matching_checks': 0, | |
| 'node_bound_checks': 0, 'rank_increase_checks': 0, | |
| 'nodes': 0, 'prunes': 0, 'passed': False} | |
| for case in range(count): | |
| n, m = rng.randint(2, 5), rng.randint(2, 5) | |
| d, out = rng.randint(1, 3), rng.randint(1, 2) | |
| k = rng.randint(1, min(n, m)) | |
| X = rat_matrix([[rng.randint(-2, 2) for _ in range(d)] for _ in range(n)]) | |
| Y = rat_matrix([[rng.randint(-3, 3) for _ in range(out)] for _ in range(m)]) | |
| expected, ties = exhaustive_solve(X, Y, k) | |
| actual = exact_solve(X, Y, k, retain_proof=True) | |
| assert actual['objective'] == expected | |
| assert actual['all_optima'] == ties | |
| assert verify_proof(X, Y, k, actual) | |
| report['matching_checks'] += 1 | |
| report['nodes'] += actual['stats']['nodes'] | |
| report['prunes'] += actual['stats']['bound_prunes'] | |
| h = rng.randint(0, k-1) | |
| P = [(i, i) for i in range(h)] | |
| sources, targets, q = list(range(h, n)), list(range(h, m)), k-h | |
| cert = node_bound(X, Y, P, sources, targets, q) | |
| for E in enumerate_matchings(sources, targets, q): | |
| assert cert['value'] <= fit(X, Y, P+list(E)).F | |
| report['node_bound_checks'] += 1 | |
| # Verify singleton formula directly, including source rank increases. | |
| A = cert['anchor'] | |
| for i in sources: | |
| for j in targets: | |
| updated = fit(X, Y, P+[(i, j)]) | |
| assert updated.F-A.F == A.edge(X[i], Y[j], 1) | |
| if updated.rank > A.rank: | |
| report['rank_increase_checks'] += 1 | |
| # Covariate-instability example: an arbitrarily small nonzero design fits Y. | |
| for scale in (10, 1000, 10**9): | |
| old = fit([[Q(0)]], [[Q(1)]], [(0, 0)]).F | |
| new = fit([[Q(1, scale)]], [[Q(1)]], [(0, 0)]).F | |
| assert old == 1 and new == 0 | |
| # Three rows overdetermine a scalar fit; bounds must prune at least one branch. | |
| X = rat_matrix([[1], [2], [4], [7]]) | |
| Y = rat_matrix([[2], [4], [8], [15]]) | |
| actual = exact_solve(X, Y, 4) | |
| expected, ties = exhaustive_solve(X, Y, 4) | |
| assert actual['objective'] == expected and actual['all_optima'] == ties | |
| assert actual['stats']['bound_prunes'] > 0 | |
| report['structured_example'] = {'objective': str(actual['objective']), | |
| 'stats': actual['stats']} | |
| report['passed'] = True | |
| return report | |
| def write_validation_artifacts(directory): | |
| from pathlib import Path | |
| import time | |
| dest = Path(directory) | |
| dest.mkdir(parents=True, exist_ok=True) | |
| report = validation_suite() | |
| examples = [ | |
| ([[1], [2], [4], [7]], [[2], [4], [8], [15]], 4), | |
| ([[1, 0], [0, 1], [1, 1], [2, 1], [1, 3]], | |
| [[2, 1], [1, 3], [3, 4], [5, 5], [5, 10]], 5), | |
| ([[1], [2], [3], [5], [9]], [[3], [6], [10], [15], [26]], 4), | |
| ] | |
| report['bound_comparison'] = [] | |
| for index, (X, Y, k) in enumerate(examples): | |
| row = {'example': index, 'N': len(X), 'M': len(Y), 'k': k, 'modes': {}} | |
| objectives = set() | |
| for mode in ('anchor', 'bottleneck', 'combined'): | |
| start = time.perf_counter() | |
| result = exact_solve(X, Y, k, mode, retain_proof=True) | |
| elapsed = time.perf_counter()-start | |
| assert verify_proof(X, Y, k, result) | |
| objectives.add(result['objective']) | |
| row['modes'][mode] = {**result['stats'], 'seconds': elapsed, | |
| 'objective': str(result['objective']), | |
| 'optima': len(result['all_optima'])} | |
| if index == 1 and mode == 'combined': | |
| payload = {'X': X, 'Y': Y, 'k': k, 'result': result} | |
| encoded = json.dumps(payload, default=json_encode, indent=2) | |
| (dest/'exact_proof_example.json').write_text(encoded) | |
| decoded = json.loads(encoded, object_hook=json_decode) | |
| assert verify_proof(decoded['X'], decoded['Y'], decoded['k'], decoded['result']) | |
| # Corrupting the claimed objective must invalidate the certificate. | |
| decoded['result']['objective'] -= 1 | |
| assert not verify_proof(decoded['X'], decoded['Y'], decoded['k'], decoded['result']) | |
| decoded = json.loads(encoded, object_hook=json_decode) | |
| decoded['result']['coefficients'][0][0] += 1 | |
| assert not verify_proof(decoded['X'], decoded['Y'], decoded['k'], decoded['result']) | |
| decoded = json.loads(encoded, object_hook=json_decode) | |
| decoded['result']['proof_tree']['assign'].pop() | |
| assert not verify_proof(decoded['X'], decoded['Y'], decoded['k'], decoded['result']) | |
| assert len(objectives) == 1 | |
| report['bound_comparison'].append(row) | |
| bad = {'value': Q(1), 'edges': [(0, -1)], 'cover_left': [], 'cover_right': []} | |
| assert not verify_bottleneck([[Q(1)]], 1, bad) | |
| report['proof_transcript_checks'] = ('40 random instances and 9 comparison runs; JSON round-trip; ' | |
| 'objective/coefficient/branch deletion tamper rejected; ' | |
| 'negative-index bottleneck witness rejected') | |
| (dest/'verification_results.json').write_text(json.dumps(report, indent=2)) | |
| return report | |
| if __name__ == '__main__': | |
| print(json.dumps(validation_suite(), indent=2)) | |