#!/usr/bin/env python3 """Job #4192 (pursue route 8; step set by #1848): does split-D51 admit a SPARSE Farkas certificate? Same system and assembly as #1848's solve1291.py (#453's split1090.build(), maps1086.json sha-pinned): find y >= 0 (conditioned rows [h,a,i]) and z free (equalities) with A^T y + E^T z <= 0 on all 107572 columns and f.z > 0. The step's method, fixed before any run: LP0: fix f.z = 1 and minimise sum(y) (L1 on the conditioned-row multipliers); LP1..LP4: iteratively reweighted L1, minimise sum_r y_r / (y_r^{prev} + eps) with eps = 1e-3 * max(y^{prev}). Each LP solution is rounded (#462's S1 rule at T = 1e14: y = rint(max(y,0) T), z = rint(z T)), shifted by #562's u1111.json (z' = z - delta u, needs f.z > 108 delta), verified with split1090.verify(), written as a certificate file, and checked with #1848's check1291.py UNCHANGED. Its verdict line is what certifies. Its control 4 expects a nonzero shift, so a candidate that needs no shift fails that control by design; this is reported, not hidden. Per candidate: nonzero y, nonzero z, the slot/phase distribution of the support rows [h,a,i] per anchor h, and the slot overlap between anchors 101 and 103. PRE-REGISTERED (from the step): success = a certified certificate with <= 500 nonzero y confined to <= 20 of the 51 slots; failure = every certified certificate needs > 2000 conditioned rows spread over most of the 51 slots. stdout is the artifact (JSON); progress and timing go to stderr. """ import hashlib, json, subprocess, sys, time, warnings from collections import Counter from pathlib import Path import numpy as np from scipy.optimize import linprog, OptimizeWarning from scipy.sparse import csr_matrix, hstack, vstack HERE = Path(__file__).parent sys.path.insert(0, str(HERE)) from split1090 import build, verify, load, MAPS # noqa: E402 U_SHA = '896ea25a40195b554a3ea35242dc40ebafcfd48a0cde4e1797e09766f291968e' T0 = time.time() def log(o): print(json.dumps(o), file=sys.stderr, flush=True) def solve(A, E, fv, w, seconds=1800): nA, nE = A.shape[0], E.shape[0] top = hstack([A.T.tocsr(), E.T.tocsr()], format='csr') nzf = np.flatnonzero(fv != 0) eq = csr_matrix((fv[nzf], (np.zeros(len(nzf), dtype=int), nA + nzf)), shape=(1, nA + nE)) c = np.concatenate([w, np.zeros(nE)]) bounds = [(0, None)] * nA + [(None, None)] * nE with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=OptimizeWarning) lp = linprog(c, A_ub=top, b_ub=np.zeros(A.shape[1]), A_eq=eq, b_eq=np.ones(1), bounds=bounds, method='highs-ds', options={'time_limit': float(seconds), 'primal_feasibility_tolerance': 1e-9, 'dual_feasibility_tolerance': 1e-9}) if lp.x is None: return None, int(lp.status), str(lp.message)[:120] return (np.asarray(lp.x[:nA]), np.asarray(lp.x[nA:])), int(lp.status), str(lp.message)[:120] def certify(tag, A, E, f, lab, cov, y, z, U, T=1e14): nE = E.shape[0] yi = [int(t) for t in np.rint(np.maximum(y, 0) * T).astype(np.int64)] zi = [int(t) for t in np.rint(z * T).astype(np.int64)] v0 = verify(A, E, f, lab, yi, zi) delta = max(int(v0['max_combined_coefficient']), 0); fz = int(v0['normalization_multiplier_sum']) u = U['u']; fu = 108 z2 = [zi[i] - delta * u[i] for i in range(nE)] v = verify(A, E, f, lab, yi, z2) rec = {'candidate': tag, 'delta': delta, 'f_dot_z_before_shift': fz, 'shift_criterion': fz > fu * delta, 'split1090_verify_ok': bool(v['ok'])} if not v['ok']: return rec, None cert = {'job': 4192, 'maps_sha256': MAPS, 'row_order': 'split1090.build() eq_labels / cov_labels', 'equality_labels': [list(L) for L in lab], 'conditioned_labels': [list(L) for L in cov], 'shift_delta': delta, 'scale': T, 'inequality_multipliers': yi, 'equality_multipliers': z2} text = json.dumps(cert, separators=(',', ':')) + '\n' fn = HERE / ('cert4192-%s.json' % tag) fn.write_bytes(text.encode('utf-8')) ck = subprocess.run([sys.executable, 'check1291.py', fn.name], cwd=HERE, capture_output=True, text=True) last = json.loads(ck.stdout.strip().splitlines()[-1]) fails = [l for l in ck.stdout.splitlines() if l.startswith('FAIL')] rec.update(certificate_file=fn.name, certificate_sha256=hashlib.sha256(text.encode()).hexdigest(), check1291_verdict=last['verdict'], check1291_fail_lines=fails, check1291_exit=ck.returncode) supp = [r for r, t in enumerate(yi) if t] rec['y_nonzero'] = len(supp); rec['z_nonzero'] = sum(1 for t in z2 if t) rec['max_abs_multiplier'] = max(max(abs(t) for t in yi), max(abs(t) for t in z2)) by = {} for h in (101, 103): rows = [cov[r] for r in supp if cov[r][0] == h] by[str(h)] = {'rows': len(rows), 'slots': sorted({r[2] for r in rows}), 'phases': len({r[1] for r in rows}), 'rows_per_slot': dict(sorted(Counter(r[2] for r in rows).items())), 'rows_per_phase': dict(sorted(Counter(r[1] for r in rows).items()))} s101, s103 = set(by['101']['slots']), set(by['103']['slots']) rec['by_anchor'] = by rec['slots_total'] = len(s101 | s103); rec['slots_common'] = sorted(s101 & s103) return rec, supp def main(): _, mapping = load('maps1086.json', MAPS) A, E, f, sng, blk, lab, cov, size2, ordq, H, Q, kind = build(mapping) nA, nE = A.shape[0], E.shape[0] assert (A.shape[1], nA, nE) == (107572, 5091, 3939) fv = np.asarray(f, dtype=float) raw = (HERE / 'u1111.json').read_bytes(); assert hashlib.sha256(raw).hexdigest() == U_SHA U = json.loads(raw) c1291 = json.loads((HERE / 'cert1291.json').read_bytes()) base_support = sum(1 for t in c1291['inequality_multipliers'] if t) out = {'job': 4192, 'route_id': 8, 'maps_sha256': MAPS, 'columns': int(A.shape[1]), 'conditioned_rows': nA, 'equalities': nE, 'baseline_cert1291_y_nonzero': base_support, 'iterations': []} w = np.ones(nA) prev = None for it in range(5): t1 = time.time() sol, status, msg = solve(A, E, fv, w) rec = {'lp': it, 'status': status, 'message': msg.split(' (')[0], 'wall_s': round(time.time() - t1)} if sol is None: out['iterations'].append(rec); log(rec); break y, z = sol ymax = float(y.max()) rec['sum_y'] = float(y.sum()); rec['y_support_float_1e-9rel'] = int((y > 1e-9 * ymax).sum()) cr, supp = certify('lp%d' % it, A, E, f, lab, cov, y, z, U) rec['certification'] = cr out['iterations'].append(rec) log({k: v for k, v in rec.items() if k != 'certification'} | {'y_nonzero': cr.get('y_nonzero'), 'verdict': cr.get('check1291_verdict')}) w = 1.0 / (np.maximum(y, 0) + 1e-3 * ymax) certs = [r['certification'] for r in out['iterations'] if r.get('certification', {}).get('check1291_verdict') == 'EXACT_FARKAS_SPLIT_D51_INFEASIBLE'] best = min(certs, key=lambda r: r['y_nonzero']) if certs else None out['smallest_certified'] = None if best is None else {k: best[k] for k in ('candidate', 'y_nonzero', 'z_nonzero', 'slots_total', 'slots_common', 'certificate_sha256')} if best: succ = best['y_nonzero'] <= 500 and best['slots_total'] <= 20 fail = all(r['y_nonzero'] > 2000 for r in certs) out['prereg'] = 'SUCCESS' if succ else ('FAILURE' if fail else 'NEITHER (between the two clauses)') print(json.dumps(out, sort_keys=True, indent=1)) log({'stage': 'complete', 'wall_s': round(time.time() - T0)}) if __name__ == '__main__': main()