"""Independent exact checks of arXiv:2608.10397, run with python3 audit_efx.py.""" from functools import lru_cache from itertools import combinations, combinations_with_replacement from pathlib import Path import re ROOT = Path(__file__).resolve().parent LINES = (ROOT / "2608.10397/arXiv-main-v2.tex").read_text().splitlines() def bit_items(s): while s: b = s & -s yield b s -= b def mask(name, alphabet="abcdefgh"): return sum(1 << alphabet.index(x) for x in name) def subsets(s): t = s while True: yield t if not t: break t = (t - 1) & s @lru_cache(None) def partitions(s, n): if n == 1: return [(s,)] return [(t, *p) for t in subsets(s) for p in partitions(s ^ t, n - 1)] def read_goods(): vals = [] for start in (946, 975, 1004): row = [] for line in LINES[start - 1:start + 15]: row += list(map(int, re.findall(r'\d+', line.split('&', 1)[1]))) assert len(row) == 256 vals.append(row) return vals def read_costs(starts, caps, exceptions): vals = [] for start, cap, triples in zip(starts, caps, exceptions): v = [0] + [cap] * 127 for i, line in enumerate(LINES[start - 1:start + 6]): xs = list(map(int, re.findall(r'\d+', line)))[1:] assert len(xs) == 7 - i for j, x in enumerate(xs, i): v[(1 << i) | (1 << j)] = x for triple, cost in triples.items(): v[mask(triple, "1234567")] = cost vals.append(v) return vals def transform(v): order = sorted(range(len(v)), key=lambda s: (v[s], s.bit_count(), s)) scale = len(v) - 1 new = [None] * len(v) for rank, s in enumerate(order): new[s] = (1 << scale) - (1 << (scale - rank)) return new def check_monotonicity(v, submodular=False): full = len(v) - 1 assert v[0] == 0 for s in range(len(v)): for b in bit_items(full ^ s): assert v[s | b] >= v[s] if submodular: for a, b in combinations(bit_items(full ^ s), 2): assert v[s | a] + v[s | b] >= v[s] + v[s | a | b], (s, a, b) def mms(v, n): return max(min(v[b] for b in p) for p in partitions(len(v) - 1, n)) def efx(v, p, i, singleton_positive=False, marginal_positive=False): own = p[i] for j, b in enumerate(p): if j == i: continue for g in bit_items(b): if singleton_positive and v[g] == 0: continue if marginal_positive and v[b ^ g] == v[b]: continue if v[b ^ g] <= v[b] and v[own] < v[b ^ g]: return False for c in bit_items(own): if v[own ^ c] > v[own] and v[own ^ c] < v[b]: return False return True def fair_info(vs, parts, singleton_positive=False, marginal_positive=False): n = len(vs) mus = [mms(v, n) for v in vs] flags = [] for p in parts: flags.append(tuple(v[p[i]] >= mus[i] or efx(v, p, i, singleton_positive, marginal_positive) for i, v in enumerate(vs))) return mus, flags def check_goods(): vs = read_goods() parts = partitions(255, 3) for strict in (False, True): values = list(map(transform, vs)) if strict else vs for v in values: check_monotonicity(v, submodular=strict) mus, flags = fair_info(values, parts) assert not any(map(all, flags)) _, only_singletons = fair_info(values, parts, singleton_positive=True) _, only_marginals = fair_info(values, parts, marginal_positive=True) assert sum(map(all, only_singletons)) == 0 assert sum(map(all, only_marginals)) == (0 if strict else 648) if not strict: assert all(only_marginals[parts.index((255,0,0))]) assert mus == [95, 95, 95] sets = [{p[i] for p, f in zip(parts, flags) if f[i] and p[i].bit_count() == 2} for i in range(3)] for i, line in enumerate((804, 806, 808)): assert sets[i] == {mask(s) for s in re.findall(r'[a-h]{2}(?=,|\\\})', LINES[line - 1])} table_count = 0 for line in LINES[833:900]: m = re.match(r'([123]) & \\texttt\{([a-h]+)\} & ([123]);([123])', line) if not m: continue i, s, j, k = m.groups() i, j, k = int(i)-1, int(j)-1, int(k)-1 s = mask(s) listed = re.findall(r'\\texttt\{([a-h]+)\}\\textsuperscript\{([123]):([a-h])\}', line) assert {p[j] for p, f in zip(parts, flags) if p[i] == s and f[i] and f[j]} == {mask(t) for t, _, _ in listed} for t, target, good in listed: p = [None] * 3 p[i], p[j], p[k] = s, mask(t), 255 ^ s ^ mask(t) b, g = p[int(target)-1], mask(good) assert b & g and vs[k][p[k]] < vs[k][b ^ g] and vs[k][p[k]] < 95 table_count += 1 assert table_count == 36 print("Goods: 6,561 allocations, before and after strictification, zero fair; all 36 certificate rows and their witnesses checked. Positive-marginal convention gives 648 before and zero after refinement.") def cost_instance(): return read_costs((429, 444, 459), [100] * 3, [{"236": x} for x in (21, 30, 28)]) def eefx_costs(): return read_costs((1160, 1175, 1190), (50, 50, 30), ({"145": 49, "246": 48, "156": 49, "456": 47}, {"124": 49, "147": 49, "457": 49, "167": 49, "567": 49, "157": 47}, {"146": 29, "346": 29})) def check_chores(): parts = partitions(127, 3) for strict in (False, True): cs = list(map(transform, cost_instance())) if strict else cost_instance() for c in cs: check_monotonicity(c, strict) vs = [[-x for x in c] for c in cs] mus, flags = fair_info(vs, parts) count = sum(map(all, flags)) print(f"Chores: strict refinement={strict}, EFX-or-MMS allocations={count} out of 2,187.") if strict: assert count == 0 else: assert mus == [-26,-32,-32] and all(flags[parts.index((127,0,0))]) cs = list(map(transform, eefx_costs())) if strict else eefx_costs() for c in cs: check_monotonicity(c, True) fixed = [] for c in cs: v = [-x for x in c] fixed.append({p[0] for p in parts if efx(v, p, 0)}) valid = [p for p in parts if all(s in f for s, f in zip(p, fixed))] def ef1(p): for i, c in enumerate(cs): alpha = min((c[p[i] ^ x] for x in bit_items(p[i])), default=0) if any(alpha > c[b] for j, b in enumerate(p) if j != i): return False return True both = [p for p in valid if ef1(p)] print(f"EEFX+EF1 example: strict refinement={strict}, EEFX={len(valid)}, simultaneous={len(both)}.") if not strict: assert len(valid) == 758 and len(both) == 24 and (127,0,0) in valid if strict: assert len(both) == 0 else: assert (80,6,41) in both def check_certificate_examples(): # Individual normalized fixed profile excluded by the default setting. vs = read_goods() vs[1][mask('b')] = 0 parts = partitions(255, 3) for v in vs: check_monotonicity(v) p = tuple(map(mask, ("ah", "cdg", "bef"))) for singleton_positive, expected in ((False, 0), (True, 6)): mus, flags = fair_info(vs, parts, singleton_positive) assert mus == [95, 95, 95] and sum(map(all, flags)) == expected assert flags[parts.index(p)] == (True, singleton_positive, True) print("Changing only v2(b) to zero: zero fair allocations under §2, six under the script default.") p = (80, 6, 41) # (57,23,146) cs = eefx_costs() completions = (("346", "12"), ("567", "14"), ("357", "2")) for i, (c, (a, b)) in enumerate(zip(cs, completions)): witness = (p[i], mask(a, "1234567"), mask(b, "1234567")) assert witness in partitions(127, 3) assert efx([-x for x in c], witness, 0) assert min(c[p[i] ^ g] for g in bit_items(p[i])) <= min(c[t] for j, t in enumerate(p) if j != i) for sign in (1, -1): vs = [additive([sign * w for w in row]) for row in ((2,3,1), (1,3,2))] parts = partitions(7, 2) mus, flags = fair_info(vs, parts) assert mus == [sign * 3] * 2 assert {p for p, f in zip(parts, flags) if all(f)} == {(2,5), (5,2)} # Allocate 1/3, 2/3 of item 2 in both cases; remaining entire items # assigned along the advantageous directions as in the paper. fraction_numerators = (9,12) if sign == 1 else (-6,-9) assert all(x >= sign * 9 for x in fraction_numerators) assert any(x > sign * 9 for x in fraction_numerators) vs = [[0,-2,-10,-100,-10,-100,-11,-100]] * 2 mu = mms(vs[0], 2) assert mu == -11 assert not any(all(vs[i][t] >= mu and efx(vs[i],p,i) for i,t in enumerate(p)) for p in partitions(7,2)) v = additive([1,1,1,2,2,2]) assert mms(v,3) == 3 assert max(min(v[b] for b in p) for p in partitions(15,2)) == 2 assert max(min(v[b] for b in p) for p in partitions(56,2)) == 2 assert v[8] == 2 and not efx(v, (8,0,55), 0) print("Fractional-PO example, identical-chore conjunction, and EPMMS separation verified.") def additive(weights): return [sum(weights[x.bit_length()-1] for x in bit_items(s)) for s in range(1 << len(weights))] def mixed_transfer(v, initial): p = list(initial) zeros = sum(x for x in bit_items(sum(initial)) if v[x] == 0) for i in range(len(p)): p[i] &= ~zeros while True: transfer = None for i, own in enumerate(p): for j, other in enumerate(p): transfer = next(((j,i,g) for g in bit_items(other) if v[g]>0 and v[own] v[p[0]] for g in bit_items(t))), None) if index is None: break smallest = min(bit_items(p[index]), key=v.__getitem__) p[index] ^= smallest pool |= smallest while True: q = min(bit_items((len(v)-1) ^ pool), key=v.__getitem__, default=None) h = max(bit_items(pool), key=v.__getitem__) if q is None or v[q] >= v[h]: break owner = next(i for i, t in enumerate(p) if t & q) p[owner] ^= q | h pool ^= q | h p.sort(key=v.__getitem__) while pool: h = max(bit_items(pool), key=v.__getitem__) p[0] |= h pool ^= h p.sort(key=v.__getitem__) return tuple(p) def check_algorithms(): configurations = 0 for weights in combinations_with_replacement((-2,-1,0,1,2),4): v = additive(weights) for p in partitions(15,3): algorithms = [mixed_transfer] if min(weights) >= 0: algorithms.append(goods_transform) for algorithm in algorithms: out = algorithm(v,p) assert min(v[t] for t in out) >= min(v[t] for t in p) assert out in partitions(15,3) and all(efx(v,out,i) for i in range(3)) configurations += 1 print(f"Algorithms 2 and 3: {configurations:,} threshold and EFX checks including zeros, ties and mixed signs.") def check_chore_conventions(): # Definition H.2 of arXiv:2602.14668v2 includes every own deletion, # including a zero. Local §2 instead checks zero items in other bundles. v = additive([-3,-3,-2,-2,-2,0]) assert mms(v,2) == -6 for p, paper_passes in (((13,50), False), ((45,18), True)): bf_passes = all(v[p[0]^g] >= v[p[1]] for g in bit_items(p[0])) assert v[p[0]] == -7 and v[p[1]] == -5 assert efx(v,p,0) == paper_passes and bf_passes != paper_passes # Applied unmodified to Algorithm 1, BF Chore-Realloc can break even # the approximate guarantee. Type 1 values every item at zero. v = additive([-6,-6,-4,-4,-4,0,-7,-7]) p = [13,50,192] assert [v[t] for t in p] == [-14,-10,-14] for g in sorted(bit_items(63), key=lambda x:v[x]): src = next(i for i in range(2) if p[i] & g) p[src] ^= g dst = max(range(2), key=lambda i:(v[p[i]], i == src)) p[dst] |= g assert p == [13,50,192] and mms(v,3) == -13 assert not efx(v,p,0) print("IMMX conventions differ both ways. Verbatim Chore-Realloc produces disutility 14 at MMS 13 and violates EFX.") def check_cut_and_choose(): # One agent of each role. Exercise genuine mixed signs, zero MMS and ties. from itertools import product parts = partitions(7,3) profiles = [additive(w) for w in product((-1,0,1),repeat=3)] mus = [mms(v,3) for v in profiles] checked = 0 for i, v1 in enumerate(profiles): for reverse_order in (False, True): ordering = reversed(parts) if reverse_order else parts initial = max(ordering,key=lambda p:min(v1[t] for t in p)) for j, v2 in enumerate(profiles): a,b,c = sorted(initial,key=lambda t:v2[t],reverse=True) transformed = mixed_transfer(v2,(a,b)) choices = (*transformed,c) for k, ve in enumerate(profiles): ei = max(range(3),key=lambda r:ve[choices[r]]) if ei < 2: out = (c,transformed[1-ei],transformed[ei]) else: i1 = max(range(2),key=lambda r:v1[transformed[r]]) out = (transformed[i1],transformed[1-i1],c) assert out in parts assert all(v[out[r]] >= mus[t] or efx(v,out,r) for r,(v,t) in enumerate(((v1,i),(v2,j),(ve,k)))) checked += 1 print(f"Cut and choose: {checked:,} exact mixed-sign allocations checked (Algorithm 1, three agents, three items).") def check_auxiliary_tables(): cs = cost_instance() def parse_set(s): return mask(s, "1234567") def fields(line): return tuple(map(parse_set,re.findall(r'\\bund\{([1-7]+)\}',line))) def beta(c,b): return max((c[b^g] for g in bit_items(b)),default=0) def alpha(c,b): return min((c[b^g] for g in bit_items(b)),default=0) for line in LINES[1091:1105]: bundles=fields(line) match=re.search(r'\$(\d):(\d);\\ (\d+)>(\d+);\\ (\d+)>(\d+)\$',line) i,j,x,mu,y,z=map(int,match.groups()) c=cs[i-1] assert (c[bundles[i-1]],-mms([-t for t in c],3),beta(c,bundles[i-1]),c[bundles[j-1]]) == (x,mu,y,z) cs = eefx_costs() for line in LINES[1268:1288]: if 'bund' not in line: continue bundles=fields(line) slacks=tuple(map(int,re.search(r'\$\((\d+),(\d+),(\d+)\)\$',line).groups())) for c,b,expected in zip(cs,bundles,slacks): gamma=max(min(c[s],c[t]) for s,t in partitions(127^b,2)) assert gamma-beta(c,b) == expected i,j,x,z=map(int,re.search(r'(\d)\\to(\d):(\d+)>(\d+)',line).groups()) assert (alpha(cs[i-1],bundles[i-1]),cs[i-1][bundles[j-1]]) == (x,z) print("All 14 listed non-special chore witnesses and the 18 appendix slack/witness rows agree with the tabulated all-own-deletions convention.") def run_z3(): import importlib.util import z3 import sys spec = importlib.util.spec_from_file_location("paper_search", ROOT / "2608.10397/search_monotone_efx_or_mms.py") paper = importlib.util.module_from_spec(spec) spec.loader.exec_module(paper) if "--verifier-test" in sys.argv: # Supply a normalized monotone profile and the exact MMS; this instance # is never a counterexample, as the unique agent gets everything. sm = paper.SearchModel(1,1) other = z3.Solver() other.add(sm.v[0][0] == 0, sm.v[0][1] == 1, sm.mu[0] == 1) if other.check() != z3.sat: raise RuntimeError("infeasible verifier test fixture") try: result = sm.verify_model(other.model()) except AssertionError: print("Verifier correctly rejected a normalized one-agent noncounterexample.") else: print("Verifier accepted a normalized one-agent noncounterexample:",result) return # Fix the same valuation table and run the actual supplied solver. The # prepublished table is recovered when v2({b})=3 and is solved first. vs = read_goods() for mode in ("all","singleton_positive"): sm = paper.SearchModel(3,8,efx_item_mode=mode,timeout_ms=120000) for i, v in enumerate(vs): for s, x in enumerate(v): if i != 1 or s != 2: sm.solver.add(sm.v[i][s] == z3.Q(x,95)) for singleton, expected in ((3,z3.sat), (0,z3.sat if mode=="all" else z3.unsat)): sm.solver.push() sm.solver.add(sm.v[1][2] == z3.Q(singleton,95)) status=sm.check() print(f"Original Z3 code, pinned 8-item table: mode={mode}, v2(b)={singleton}/95, {status}",flush=True) if status != expected: raise AssertionError((status,expected)) if status == z3.sat: sm.verify_model(sm.model(),verbose=False) sm.solver.pop() if __name__ == "__main__": import sys if "--z3" in sys.argv or "--verifier-test" in sys.argv: run_z3() else: check_goods() check_chores() check_certificate_examples() check_algorithms() check_chore_conventions() check_cut_and_choose() check_auxiliary_tables()