"""Compare the schema criterion of main.tex (Theorem 'schema': 2r + 2w < 1 + 5 dim U over all layouts) with the unit-101 exhaustive count (../anc/u101_enum.py, an identical copy of campaign_abp/unit101/u101_enum.py, imported read-only). Steps 1. Re-run unit 101's enumeration and analysis in memory: reproduce 19 645 cells with A <= 8, 5 274 positive, sorting counts (634 NEW). 2. Class of the schema: every column has exactly two slots, none Ga; (H1) a curve occurring in >= 2 columns receives entries in at most one copy; (H2) provable in unit 101's relation model: no relation allowed in any curve slot holding entries. 3. For every cell in the class, evaluate the schema criterion with r(L) = 2 - lam_min(dead set) (unit 101's own adversarial relation model, so the transcendence inputs are the same), over all layouts built from a rich list of subspaces U of Q^3 (all spans of <= 2 vectors in {-1,0,1,2}^3), with components = U cap span(support), full support, and the schema's deadness: Gm slot of column j dead iff P in {x_j = 0}; copy of E_c in column j dead iff e_j not in U_c. Compare the verdict cell by cell with unit 101's (margin > 0). 4. Also evaluate unit 101's own deadness rule (copy dead iff not in the support) in the same layout enumeration, to separate disagreements caused by the graph rule from those caused by the U list. Exact rational arithmetic. Run: python schema_vs_u101.py (from this folder; about 10 minutes). """ import sys, os, itertools, time, json from fractions import Fraction as F sys.dont_write_bytecode = True HERE = os.path.dirname(os.path.abspath(__file__)) U101 = HERE if os.path.exists(os.path.join(HERE, 'u101_enum.py')) else os.path.normpath(os.path.join(HERE, '..', 'anc')) sys.path.insert(0, U101) import u101_enum as u u.LIMIT = 10 ** 9 # no time limit for the in-memory rerun T0 = time.time() out = open(os.path.join(HERE, 'schema_vs_u101_out.log'), 'w', encoding='utf-8') def pr(*a): s = ' '.join(str(x) for x in a); print(s, flush=True); out.write(s + '\n'); out.flush() # ---------------------------------------------------------------- exact linear algebra in Q^3 def rref(vecs): M = [[F(x) for x in v] for v in vecs if any(v)] rows = []; rk = 0 if not M: return () ncol = len(M[0]) for c in range(ncol): p = next((i for i in range(rk, len(M)) if M[i][c] != 0), None) if p is None: continue M[rk], M[p] = M[p], M[rk] piv = M[rk][c]; M[rk] = [x / piv for x in M[rk]] for i in range(len(M)): if i != rk and M[i][c] != 0: f = M[i][c]; M[i] = [a - f * b for a, b in zip(M[i], M[rk])] rk += 1 return tuple(tuple(r) for r in M[:rk]) def dim(vecs): return len(rref(vecs)) def intersect_coord(B, S): """basis of span(B) cap span(e_p : p in S), B a basis (tuple of tuples) of a subspace of Q^3""" if not B: return () out_ = [j for j in range(3) if j not in S] # solve sum a_i B_i with coordinates out_ equal to 0 m = len(B) rows = [[B[i][j] for i in range(m)] for j in out_] # nullspace of rows (|out_| x m) R = rref(rows) if rows else () piv = [] for r in R: piv.append(next(i for i, x in enumerate(r) if x != 0)) free = [i for i in range(m) if i not in piv] basis = [] for f_ in free: a = [F(0)] * m; a[f_] = F(1) for r, p in zip(R, piv): a[p] = -r[f_] v = tuple(sum(a[i] * B[i][j] for i in range(m)) for j in range(3)) basis.append(v) return rref(basis) vals = [-1, 0, 1, 2] vecs = [v for v in itertools.product(vals, repeat=3) if any(v)] Ulist = {(): None} for v in vecs: Ulist.setdefault(rref([v]), None) for v, w in itertools.combinations(vecs, 2): B = rref([v, w]) if len(B) == 2: Ulist.setdefault(B, None) Ulist = list(Ulist) pr('subspaces U in the rich list:', len(Ulist), '(dims:', {d: sum(1 for B in Ulist if len(B) == d) for d in range(3)}, ')') _IC = {} def comp(Ui, S): key = (Ui, S) if key not in _IC: B = Ulist[Ui] X = intersect_coord(B, set(S)) if S else () full = bool(X) if full: for p in S: Sp = tuple(q for q in S if q != p) if len(intersect_coord(B, set(Sp)) if Sp else ()) >= len(X): full = False; break has = {p: (len(rref(list(X) + [tuple(1 if i == p else 0 for i in range(3))])) == len(X)) for p in S} if X else {} _IC[key] = (X, full, has) return _IC[key] def subsets(ps): return [tuple(c) for r in range(len(ps) + 1) for c in itertools.combinations(ps, r)] def schema_eval(cell, rule='schema'): """min over layouts of 1 + 5 dU - 2 r - 2 w (criterion holds iff > 0 for all layouts with dU <= 2).""" cs = cell['colslots']; ds = cell['dslots'] gm_cols = [p for p in range(3) if 'Gm' in cs[p]] ecs = {} for p in range(3): for s in cs[p]: if s[0] == 'E': ecs.setdefault(s, []).append(p) curves = sorted(ecs.items()) lam_cache = {} worst = None for Ui in range(len(Ulist)): for sT in subsets(gm_cols): XT, fullT, hasT = comp(Ui, sT) if sT else ((), True, {}) if sT and not fullT: continue for supp in itertools.product(*[subsets(ps) for s, ps in curves]) if curves else [()]: comps = [XT] if sT else [] ok = True; live = set(('Gm', p) for p in sT); w = len(XT) if sT else 0 for (s, ps), S in zip(curves, supp): if not S: continue X, full, has = comp(Ui, S) if not full: ok = False; break comps.append(X); w += len(X) for p in S: if rule == 'schema': if has[p]: live.add((s, p)) else: live.add((s, p)) if not ok: continue dU = dim([v for X in comps for v in X]) if comps else 0 if dU >= 3: continue dead = tuple(sorted(a for a, (p, s, S_, T) in enumerate(ds) if (s, p) not in live)) if dead not in lam_cache: lam_cache[dead] = u.lam_min(cell, list(dead)) r = 2 - lam_cache[dead] val = 1 + 5 * dU - 2 * r - 2 * w if worst is None or val < worst[0]: worst = (val, dU, w, r, dead, Ui, sT, supp) return worst def in_class(cell): cs = cell['colslots']; ds = cell['dslots']; rows = cell['rows'] if any(len(c) != 2 for c in cs): return False, 'column without exactly two slots' if any('Ga' in c for c in cs): return False, 'Ga slot' copies_with_entries = {} for (p, s, S, T) in ds: if s[0] == 'E': copies_with_entries.setdefault(s, set()).add(p) for s, ps in copies_with_entries.items(): if len(ps) > 1: return False, '(H1) fails' E = [(1, 0), (0, 1)] for d in ds: p, s, S, T = d if s[0] != 'E': continue for z in [E[0], E[1], (1, 1)]: if u.allowed(d, z, rows): return False, '(H2) not provable (relation allowed in a curve slot)' return True, '' # ---------------------------------------------------------------- 1. reproduce unit 101 cells, stats = u.run() pr('unit-101 enumeration:', stats, round(time.time() - T0, 1), 's') from collections import Counter nA = 0; npos = 0; cnt = Counter(); verdict = {}; cls_of = {}; res_of = {} for key in cells: res = u.analyse(key) if res is None: continue nA += 1 pos = res['margin'] > 0 verdict[key] = pos if pos: npos += 1 c, why = u.sort_cell(res); cnt[c] += 1; cls_of[key] = c res_of[key] = res pr('cells with A <= 8:', nA, ' positive:', npos, ' sorting:', dict(cnt), round(time.time() - T0, 1), 's') # ---------------------------------------------------------------- 2-4. schema class and criterion why_out = Counter(); agree = Counter(); dis = [] new_in = 0; new_out = Counter(); w222 = Counter() for key, pos in verdict.items(): sig, rows, plc = key cell = u.build(sig, rows, [list(r) for r in plc]) ok, why = in_class(cell) if cls_of.get(key) == 'NEW': w222[tuple(res_of[key]['weights'])] += 1 if ok: new_in += 1 else: new_out[why] += 1 if not ok: why_out[why] += 1; continue ws = schema_eval(cell, 'schema'); wo = schema_eval(cell, 'support') sch = ws[0] > 0; own = wo[0] > 0 agree[(pos, sch, own)] += 1 if sch != pos or own != pos: dis.append((key, pos, ws, wo)) pr('outside the schema class:', dict(why_out)) pr('inside the class: (unit101 positive, schema criterion holds, criterion with unit-101 deadness holds) -> count') for k_, v in sorted(agree.items()): pr(' ', k_, v) pr('NEW (634): weights', dict(w222), '; in the schema class:', new_in, '; outside:', dict(new_out)) pr('disagreements:', len(dis)) for key, pos, ws, wo in dis[:60]: pr(' ', key, 'u101 positive' if pos else 'u101 negative', '| schema worst', ws[:5], '| support-rule worst', wo[:5]) pr('elapsed', round(time.time() - T0, 1), 's')