"""Boundary examples and exact arithmetic for the source audit.""" from fractions import Fraction from itertools import product, permutations from math import prod def weak_pruning(): # Columns p, q, g, e, x, y; x is too valuable for agent 1 and # y is too valuable for agent 2 under their guessed favorite goods. rows = ((16, 8, 4, 2, 32, 1), (8, 16, 4, 2, 1, 32)) b = ({0}, {1}) for i, row in enumerate(rows): eligible = [j for j in range(2, 6) if row[j] < row[i]] assert max(eligible, key=row.__getitem__) == 2 and 3 in eligible for recipient in (0, 1): a = [set(s) for s in b] a[recipient].add(2) a[1-recipient].update((4, 5)) u = [sum(row[j] for j in s) for row, s in zip(rows, a)] assert set(range(6))-set.union(*a) == {3} gain = [Fraction(row[3], base) for row, base in zip(rows, u)] assert gain[recipient] == Fraction(2,20) > gain[1-recipient] == Fraction(2,49) print("Lemma 8: neither asserted dominance holds; fractional gains 2/20 and 2/49") def bit_model(): for exponent in (10, 1000, 10000): k = 2**exponent for row, preferred in [((100,1),1),((3,2),0)]: products = (2*k*row[1], k*row[0]) assert products[1-preferred]*100 < 81*products[preferred] print("EPTAS: the two fixed-size input families require opposite 90%-approximate assignments") def zero_marginals(): assert 2 > 1 and 2*1 == (2-0)*(1+0) vals = [2,1,0] products = [prod(sum(x for x,who in zip(vals,p) if who == i) for i in range(2)) for p in product(range(2),repeat=3)] assert max(products) == 2 # The approximation and exact optimum for two agents require separate # handling when there is no matching in the positive-edge graph. rows = [(2,1,0)]*3 assert max(prod(sum(row[j] for j,x in enumerate(p) if x == i) for i,row in enumerate(rows)) for p in product(range(3), repeat=3)) == 0 print("Zero-value Nash and safe-transfer witnesses verified") def immx(): costs = (3,3,2,2,0) mms = min(max(sum(c for c,j in zip(costs,p) if j == i) for i in (0,1)) for p in product(range(2),repeat=len(costs))) assert mms == 5 for zero_owner in (0,1): bundles = [[3,3],[2,2]] bundles[zero_owner].append(0) x,y = map(sum,bundles) bf = all(x - g <= y for g in bundles[0]) local = (all(x - g <= y for g in bundles[0] if g > 0) and all(x <= y-g for g in bundles[1] if g == 0)) assert x > mms >= y and bf == (zero_owner == 1) and local != bf print("IMMX: MMS cost 5, observed both directions of failure") def matching_base_case(): rows = ((1,4,2),(4,1,2),(1,2,4)) possible = [tuple(row[j] for row,j in zip(rows,p)) for p in permutations(range(3))] assert (1,1,4) in possible and (4,4,4) in possible print("Singleton matching: two agents can improve while a third keeps the same good") if __name__ == "__main__": weak_pruning() bit_model() zero_marginals() immx() matching_base_case() def leximin(): vals = [0,2,0,3] parts = [(s,3^s) for s in range(4)] def sorted_values(p): return tuple(sorted(vals[s] for s in p)) def leximin_plus(p): return tuple(sorted((vals[s],s.bit_count()) for s in p)) assert set(max(parts,key=sorted_values))=={0,3} assert set(max(parts,key=leximin_plus))=={1,2} assert vals[0] < vals[1] print("Leximin++: value-vector maximization selects (0,3); interleaving sizes selects (0,2)") if __name__ == "__main__": leximin()