#!/usr/bin/env python3 """ Standalone Zero-Trust Verifier for Counterexamples to the Levit-Mandrescu Unimodality & Log-Concavity Conjectures for Very Well-Covered (VWC) Graphs. Zero external dependencies (Python 3 stdlib only, 100% exact arbitrary-precision integers). Verifies: 1. Brute-force calibration on small explicit graphs (2^n subset enumeration) for ALL THREE graph families: - Family A: Connected Bipartite VWC 2-layer join G = (a * K_{c,c}) join_X (b * K_2) - Family B: Connected Corona Graph G = ((a1 * K_d1 U a2 * K_d2) join E_b) o K_1 - Family C: Connected Bipartite VWC 3-layer chain G_1 -> G_2 -> G_3 2. Explicit graph construction and DIRECT structural verification on the actual adjacency bitsets of EVERY headline counterexample: - Simple graph (no self-loops, exact full symmetry), connected, no isolated vertices - Exact Favaron (P1) and (P2) check on ALL m matched pairs {x_i, y_i} (which directly proves every maximal independent set has cardinality exactly m!) - Bipartiteness check (explicit 2-coloring) for Families A & C; Corona structure check (m pendant leaves with distinct neighbors) for Family B - Exact agreement of s_0 = 1, s_1 = n, s_2 = C(n,2) - |E(G)| against the actual edge count 3. Exact arbitrary-precision integer computation of I(G; x) = sum_{k=0}^m s_k x^k and exact integer verification of: - Log-concavity failure: s_k^2 < s_{k-1} * s_{k+1} - Unimodality failure: s_{k-1} > s_k < s_{k+1} (with strict peaks on both sides) - Trimodality (3 strict local maxima, 2 strict local minima) for Family C """ import math import time def poly_mul_exact(a, b): if not a or not b: return [] mx = max(a) * max(b) * min(len(a), len(b)) nbytes = (mx.bit_length() + 8) // 8 ba = bytearray(len(a) * nbytes) for i, v in enumerate(a): ba[i * nbytes : (i + 1) * nbytes] = v.to_bytes(nbytes, "little") bb = bytearray(len(b) * nbytes) for i, v in enumerate(b): bb[i * nbytes : (i + 1) * nbytes] = v.to_bytes(nbytes, "little") A = int.from_bytes(ba, "little") B = int.from_bytes(bb, "little") C = A * B out_len = len(a) + len(b) - 1 bc = C.to_bytes((out_len + 1) * nbytes, "little") return [int.from_bytes(bc[i * nbytes : (i + 1) * nbytes], "little") for i in range(out_len)] def poly_pow_exact(p, e): r = [1] base = p while e: if e & 1: r = poly_mul_exact(r, base) base = poly_mul_exact(base, base) e >>= 1 return r def binom_poly(n, r=1): if r == 1: return [math.comb(n, k) for k in range(n + 1)] res = [0] * (n + 1) p = 1 for k in range(n + 1): res[k] = math.comb(n, k) * p p *= r return res def build_family_A_bipartite_2layer(a, c, b): m = a * c + b n = 2 * m adj = [0] * n xA_mask = (1 << (a * c)) - 1 xB_mask = ((1 << b) - 1) << (a * c) for t in range(a): base = t * c blk_x = ((1 << c) - 1) << base blk_y = blk_x << m for r in range(c): u = base + r adj[u] |= blk_y | xB_mask adj[m + u] |= blk_x for j in range(b): v = a * c + j adj[v] |= (1 << (m + v)) | xA_mask adj[m + v] |= (1 << v) return n, m, adj def build_family_B_corona_mixed(cliques, b): mA = sum(cnt * d for cnt, d in cliques) m = mA + b n = 2 * m adj = [0] * n xA_mask = (1 << mA) - 1 xB_mask = ((1 << b) - 1) << mA base = 0 for cnt, d in cliques: for _ in range(cnt): blk_x = ((1 << d) - 1) << base for r in range(d): u = base + r adj[u] |= (blk_x ^ (1 << u)) | xB_mask | (1 << (m + u)) adj[m + u] |= (1 << u) base += d assert base == mA for j in range(b): v = mA + j adj[v] |= xA_mask | (1 << (m + v)) adj[m + v] |= (1 << v) return n, m, adj def build_family_C_bipartite_3layer(p1, p2, q2, q3): m1 = 4 * p1 m2 = 4 * p2 + q2 m3 = q3 m = m1 + m2 + m3 n = 2 * m adj = [0] * n x1_mask = (1 << m1) - 1 x2_mask = ((1 << m2) - 1) << m1 x3_mask = ((1 << m3) - 1) << (m1 + m2) y1_mask = x1_mask << m y2_mask = x2_mask << m for t in range(p1): base = 4 * t bx = 0xF << base by = bx << m for r in range(4): u = base + r adj[u] |= by adj[m + u] |= bx | x2_mask | x3_mask for t in range(p2): base = m1 + 4 * t bx = 0xF << base by = bx << m for r in range(4): u = base + r adj[u] |= by | y1_mask adj[m + u] |= bx | x3_mask for j in range(q2): u = m1 + 4 * p2 + j adj[u] |= (1 << (m + u)) | y1_mask adj[m + u] |= (1 << u) | x3_mask for j in range(q3): u = m1 + m2 + j adj[u] |= (1 << (m + u)) | y1_mask | y2_mask adj[m + u] |= (1 << u) return n, m, adj def verify_explicit_graph_structure(n, m, adj, expect_bipartite=False, expect_corona=False): assert n == 2 * m edge_deg_sum = 0 for u in range(n): assert (adj[u] & (1 << u)) == 0, f"Self-loop at {u}" assert adj[u] != 0, f"Isolated vertex {u}" edge_deg_sum += adj[u].bit_count() row_to_verts = {} for u in range(n): row_to_verts.setdefault(adj[u], []).append(u) classes = [] for mask_p, verts in row_to_verts.items(): cmask = 0 for u in verts: cmask |= 1 << u classes.append((mask_p, cmask, verts)) num_cls = len(classes) for i in range(num_cls): mp, cp, _ = classes[i] for j in range(i, num_cls): mq, cq, _ = classes[j] a = mp & cq b = mq & cp if a == 0: assert b == 0, f"Asymmetric adjacency between classes {i} and {j}" else: assert a == cq and b == cp, f"Asymmetric adjacency between classes {i} and {j}" assert edge_deg_sum % 2 == 0 num_edges = edge_deg_sum // 2 visited = 1 frontier = 1 while frontier: nxt = 0 tmp = frontier while tmp: lsb = tmp & -tmp u = lsb.bit_length() - 1 nxt |= adj[u] tmp ^= lsb frontier = nxt & ~visited visited |= frontier assert visited == (1 << n) - 1, "Graph is NOT connected!" checked_p2_pairs = set() for i in range(m): x, y = i, m + i assert (adj[x] & (1 << y)) != 0 and (adj[y] & (1 << x)) != 0, f"Missing matching edge ({x},{y})" ax = adj[x] & ~(1 << y) ay = adj[y] & ~(1 << x) assert (ax & ay) == 0, f"Favaron (P1) violated at pair {i}!" if ax != 0 and ay != 0: key = (ax, ay) if key not in checked_p2_pairs: checked_p2_pairs.add(key) if ax.bit_count() <= ay.bit_count(): tmp = ax while tmp: lsb = tmp & -tmp u = lsb.bit_length() - 1 assert (adj[u] & ay) == ay, f"Favaron (P2) violated at pair {i}, u={u}!" tmp ^= lsb else: tmp = ay while tmp: lsb = tmp & -tmp v = lsb.bit_length() - 1 assert (adj[v] & ax) == ax, f"Favaron (P2) violated at pair {i}, v={v}!" tmp ^= lsb if expect_bipartite: color0 = 1 color1 = 0 frontier = 1 cur_c = 0 while frontier: nxt = 0 tmp = frontier while tmp: lsb = tmp & -tmp u = lsb.bit_length() - 1 nxt |= adj[u] tmp ^= lsb if cur_c == 0: assert (nxt & color0) == 0, "Graph is NOT bipartite (odd cycle)!" frontier = nxt & ~color1 color1 |= frontier else: assert (nxt & color1) == 0, "Graph is NOT bipartite (odd cycle)!" frontier = nxt & ~color0 color0 |= frontier cur_c ^= 1 assert (color0 | color1) == (1 << n) - 1 and (color0 & color1) == 0 if expect_corona: for i in range(m): assert adj[m + i] == (1 << i), f"Vertex {m+i} is not a pendant leaf attached only to {i}!" return num_edges def bruteforce_indep_poly_and_vwc(n, m, adj): for u in range(n): assert adj[u] != 0 counts = [0] * (n + 1) max_sizes = set() all_mask = (1 << n) - 1 for mask in range(1 << n): tmp = mask nbrs = 0 ok = True while tmp: lsb = tmp & -tmp u = lsb.bit_length() - 1 if adj[u] & mask: ok = False break nbrs |= adj[u] tmp ^= lsb if not ok: continue k = mask.bit_count() counts[k] += 1 if (mask | nbrs) == all_mask: max_sizes.add(k) assert max_sizes == {m}, f"NOT VWC! Maximal IS sizes = {max_sizes}" assert all(c == 0 for c in counts[m + 1 :]) return counts[: m + 1] def formula_family_A(a, c, b): m = a * c + b kcc = [1] + [2 * math.comb(c, k) for k in range(1, c + 1)] t1 = poly_mul_exact(binom_poly(b, 1), poly_pow_exact(kcc, a)) t2 = poly_mul_exact(binom_poly(a * c, 1), binom_poly(b, 2)) t3 = binom_poly(m, 1) return [t1[k] + t2[k] - t3[k] for k in range(m + 1)] def formula_family_B_mixed(cliques, b): mA = sum(cnt * d for cnt, d in cliques) total_cliques = sum(cnt for cnt, _ in cliques) m = mA + b prod_q = [1] for cnt, d in cliques: prod_q = poly_mul_exact(prod_q, binom_poly(cnt, d + 1)) t1 = poly_mul_exact(binom_poly(m - total_cliques, 1), prod_q) t2 = poly_mul_exact(binom_poly(mA, 1), binom_poly(b, 2)) t3 = binom_poly(m, 1) return [t1[k] + t2[k] - t3[k] for k in range(m + 1)] def formula_family_C(p1, p2, q2, q3): m1 = 4 * p1 m2 = 4 * p2 + q2 m3 = q3 m = m1 + m2 + m3 k4 = [1, 8, 12, 8, 2] t1 = poly_mul_exact(binom_poly(m - m1, 1), poly_pow_exact(k4, p1)) t2 = poly_mul_exact( poly_mul_exact(binom_poly(m - m2, 1), poly_pow_exact(k4, p2)), binom_poly(q2, 2), ) t3 = poly_mul_exact(binom_poly(m - m3, 1), binom_poly(q3, 2)) t0 = binom_poly(m, 1) return [t1[k] + t2[k] + t3[k] - 2 * t0[k] for k in range(m + 1)] def analyze_and_report(name, n, m, num_edges, coeffs, expect_lc_fail=True, expect_min_modes=1): assert len(coeffs) == m + 1 assert coeffs[0] == 1 assert coeffs[1] == n expected_s2 = math.comb(n, 2) - num_edges assert coeffs[2] == expected_s2, f"s_2 = {coeffs[2]} != C(n,2) - |E| = {expected_s2}!" lc_fails = [k for k in range(1, m) if coeffs[k] * coeffs[k] < coeffs[k - 1] * coeffs[k + 1]] local_max = [k for k in range(1, m) if coeffs[k - 1] < coeffs[k] > coeffs[k + 1]] local_min = [k for k in range(1, m) if coeffs[k - 1] > coeffs[k] < coeffs[k + 1]] print(f"\n[{name}]") print(f" |V(G)| = {n}, alpha(G) = m = {m}, |E(G)| = {num_edges}") print(f" Exact checks: s_0 = {coeffs[0]}, s_1 = {coeffs[1]} == n, s_2 = {coeffs[2]} == C(n,2)-|E|") print(f" Log-concavity failures ({len(lc_fails)}): {lc_fails[:12]}{'...' if len(lc_fails) > 12 else ''}") if lc_fails: k = lc_fails[0] lhs = coeffs[k] * coeffs[k] rhs = coeffs[k - 1] * coeffs[k + 1] assert lhs < rhs ratio_str = f"{(lhs * 10**12) // rhs / 1e12:.12f}" print(f" Witness k={k}: s_k^2 < s_{{k-1}}*s_{{k+1}} (EXACT INT TRUE), ratio ~ {ratio_str}") print(f" Strict local maxima ({len(local_max)}): {local_max}") print(f" Strict local minima ({len(local_min)}): {local_min}") for k in sorted(local_max + local_min): kind = "PEAK" if k in local_max else "DIP " print(f" {kind} k={k}: digits={len(str(coeffs[k]))}, log10(s_k)={math.log10(coeffs[k]):.12f}") if kind == "DIP ": assert coeffs[k - 1] > coeffs[k] and coeffs[k + 1] > coeffs[k] rL = ((coeffs[k - 1] * 10**12) // coeffs[k]) / 1e12 rR = ((coeffs[k + 1] * 10**12) // coeffs[k]) / 1e12 print(f" EXACT INT CHECK: s[{k-1}] > s[{k}] (ratio ~ {rL:.12f}), s[{k+1}] > s[{k}] (ratio ~ {rR:.12f})") if expect_lc_fail: assert len(lc_fails) > 0 assert len(local_max) >= expect_min_modes if expect_min_modes >= 2: assert len(local_min) >= expect_min_modes - 1 def main(): t0 = time.time() print("=== STEP 1: Brute-Force 2^n Calibration on Small Explicit Graphs ===") for (a, c, b) in [(1, 2, 2), (2, 2, 2), (1, 3, 2), (1, 4, 2)]: n, m, adj = build_family_A_bipartite_2layer(a, c, b) ne = verify_explicit_graph_structure(n, m, adj, expect_bipartite=True) bf = bruteforce_indep_poly_and_vwc(n, m, adj) fm = formula_family_A(a, c, b) assert bf == fm print(f" Family A (a={a}, c={c}, b={b}), n={n}, m={m}, |E|={ne}: BRUTE-FORCE VWC + EXACT I(G;x) PASS") for cliques, b in [([(1, 2)], 2), ([(2, 2)], 2), ([(1, 2), (1, 3)], 2), ([(2, 3)], 2)]: n, m, adj = build_family_B_corona_mixed(cliques, b) ne = verify_explicit_graph_structure(n, m, adj, expect_corona=True) bf = bruteforce_indep_poly_and_vwc(n, m, adj) fm = formula_family_B_mixed(cliques, b) assert bf == fm print(f" Family B (cliques={cliques}, b={b}), n={n}, m={m}, |E|={ne}: BRUTE-FORCE VWC + EXACT I(G;x) PASS") for (p1, p2, q2, q3) in [(1, 0, 1, 1), (1, 1, 0, 1), (1, 0, 2, 2)]: n, m, adj = build_family_C_bipartite_3layer(p1, p2, q2, q3) ne = verify_explicit_graph_structure(n, m, adj, expect_bipartite=True) bf = bruteforce_indep_poly_and_vwc(n, m, adj) fm = formula_family_C(p1, p2, q2, q3) assert bf == fm print(f" Family C (p1={p1}, p2={p2}, q2={q2}, q3={q3}), n={n}, m={m}, |E|={ne}: BRUTE-FORCE VWC + EXACT I(G;x) PASS") print("\n=== STEP 2: Explicit Graph + Exact Integer Verification of Headline Counterexamples ===") n, m, adj = build_family_A_bipartite_2layer(122, 4, 206) ne = verify_explicit_graph_structure(n, m, adj, expect_bipartite=True) coeffs = formula_family_A(122, 4, 206) analyze_and_report("G_bip_lc = (122 * K_{4,4}) join_X (206 * K_2) [Connected Bipartite VWC, LC Failure]", n, m, ne, coeffs, True, 1) n, m, adj = build_family_A_bipartite_2layer(125, 4, 204) ne = verify_explicit_graph_structure(n, m, adj, expect_bipartite=True) coeffs = formula_family_A(125, 4, 204) analyze_and_report("G_bip_uni = (125 * K_{4,4}) join_X (204 * K_2) [Connected Bipartite VWC, Unimodality + LC Failure]", n, m, ne, coeffs, True, 2) n, m, adj = build_family_B_corona_mixed([(86, 14)], 517) ne = verify_explicit_graph_structure(n, m, adj, expect_corona=True) coeffs = formula_family_B_mixed([(86, 14)], 517) analyze_and_report("G_cor_lc = ((86 * K_14) join E_517) o K_1 [Connected Corona Graph, LC Failure]", n, m, ne, coeffs, True, 1) n, m, adj = build_family_B_corona_mixed([(126, 10), (10, 11)], 603) ne = verify_explicit_graph_structure(n, m, adj, expect_corona=True) coeffs = formula_family_B_mixed([(126, 10), (10, 11)], 603) analyze_and_report("G_cor_uni = ((126 * K_10 U 10 * K_11) join E_603) o K_1 [Connected Corona Graph, Unimodality + LC Failure]", n, m, ne, coeffs, True, 2) n, m, adj = build_family_B_corona_mixed([(143, 10)], 632) ne = verify_explicit_graph_structure(n, m, adj, expect_corona=True) coeffs = formula_family_B_mixed([(143, 10)], 632) analyze_and_report("G_cor_uni_pure = ((143 * K_10) join E_632) o K_1 [Connected Pure-Clique Corona, Unimodality + LC Failure]", n, m, ne, coeffs, True, 2) n, m, adj = build_family_C_bipartite_3layer(900, 450, 734, 1468) ne = verify_explicit_graph_structure(n, m, adj, expect_bipartite=True) coeffs = formula_family_C(900, 450, 734, 1468) analyze_and_report("G_bip_tri = (900*K_{4,4}) -> (450*K_{4,4} U 734*K_2) -> (1468*K_2) [Connected Bipartite VWC, TRIMODAL]", n, m, ne, coeffs, True, 3) print(f"\nALL 6 COUNTEREXAMPLES & 11 BRUTE-FORCE CALIBRATIONS PASSED 100% EXACTLY in {time.time() - t0:.2f}s!") if __name__ == "__main__": main()