#!/usr/bin/env python3 """Independent exact-arithmetic audit of the n=170 parameter cases and witnesses. Run with Python 3 and no third-party packages. Outputs are written next to this script, so the whole audit directory can be moved or zipped as a self-contained bundle. The parameter search uses the exact block formulas stated in certificates/MINIMUM.md; it does not import the upstream verifier. """ from __future__ import annotations import hashlib import itertools import json from collections import deque from pathlib import Path HERE = Path(__file__).resolve().parent N_MAX = 170 def product_bound(x_cap: int, zw_cap: int, total_cap: int) -> int: """max X(Z+W), with X>=1, Z+W>=1 and X+Z+W<=total_cap.""" best = 0 for x in range(1, min(x_cap, total_cap - 1) + 1): zw = min(zw_cap, total_cap - x) if zw >= 1: best = max(best, x * zw) return best def orbit_parameter_search(which: int) -> dict: """Exhaust all integer block sizes in compatibility orbit 3 or 4.""" if which not in (3, 4): raise ValueError(which) feasible = [] raw_parameter_tuples = 0 multitype_parameter_tuples = 0 outer_kept = 0 x_stage_kept = 0 exact_states = 0 all_positive_states = 0 # At n<=170, 2(a+b+c+d)+4+2 <= 170 is necessary because # X>=1 and Z+W>=1 in any counterexample. for a in range(83): for b in range(83 - a): for c in range(83 - a - b): for d in range(83 - a - b - c): k = a + b + c + d if 2 * k + 6 > N_MAX: continue raw_parameter_tuples += 1 # One bridge type is impossible for a counterexample: # after a G_8 symmetry, only a>0 remains and # Q=-a^2-a(X+Z)-(X-Z)^2/2 < 0. Zero types is disconnected. bridge_types = sum(t > 0 for t in (a, b, c, d)) if bridge_types < 2: continue multitype_parameter_tuples += 1 if which == 3: x_cap = a zw_cap = a + b + c z_cap, w_cap = a + c, b else: x_cap = a + b zw_cap = a + b z_cap, w_cap = a, b # Every actual graph has 4 D-vertices plus the 2k matched # core vertices and X+Z+W triangle vertices. Omitting the # (nonnegative) witness count only enlarges this budget. triangle_budget = min(x_cap + zw_cap, N_MAX - 4 - 2 * k) if triangle_budget < 2 or x_cap < 1 or zw_cap < 1: continue nc_max = 2 * k + triangle_budget # Certified exact cone bound: 2Q <= floor(N_C^2/30). q_cone_ub = (nc_max * nc_max) // 30 # From the displayed Q formula, drop the nonpositive # square and -2ZW terms and maximize X(Z+W) exactly. q_product_ub = ( 2 * product_bound(x_cap, zw_cap, triangle_budget) - 2 * (a + d) * (b + c) ) q_outer_ub = min(q_cone_ub, q_product_ub) # Forced centers: a1 and at least one of a2,b2. The # formulae in the certificate give these safe upper bounds # on their respective contributions to S-3M. h1_ub = -3 * a - 3 * b - d - 2 h2_ub = -min( 3 * a + 3 * c + d + 2, 3 * b + 3 * d + c + 2, ) # X>=1 and Z+W>=1 imply the core linear term <= -2k-6; # the contribution of all D-pairs is <= +1. outer_ub2 = q_outer_ub - 2 * k - 6 + 2 * h1_ub + 2 * h2_ub + 2 if outer_ub2 < 2: continue outer_kept += 1 x_top = min(x_cap, triangle_budget - 1) for x_total in range(1, x_top + 1): zw_top = min(zw_cap, triangle_budget - x_total) if zw_top < 1: continue u1 = a + b - c - d + x_total # For any Z,W with Z+W<=zw_top, drop -u2^2 and # -2ZW; this is an exact integer upper bound on 2Q. q_x_ub = min( q_cone_ub, 2 * x_total * zw_top - u1 * u1 - 2 * (a + d) * (b + c), ) h1_x_ub = -3 * a - 3 * b - 2 * x_total - d x_ub2 = ( q_x_ub - 2 * k - 3 * (x_total + 1) + 2 * h1_x_ub + 2 * h2_ub + 2 ) if x_ub2 < 2: continue x_stage_kept += 1 z_top = min(z_cap, zw_top) for z_total in range(z_top + 1): w_top = min(w_cap, zw_top - z_total) for w_total in range(w_top + 1): if z_total + w_total == 0: continue # The exact 8-block variables allowed in each # maximal compatible pattern. if which == 3: x_splits = [(x_total, 0)] z21_lo = max(0, z_total - a) z21_hi = min(c, z_total) z_splits = [ (z_total - z21, z21) for z21 in range(z21_lo, z21_hi + 1) ] else: x11_lo = max(0, x_total - b) x11_hi = min(a, x_total) x_splits = [ (x11, x_total - x11) for x11 in range(x11_lo, x11_hi + 1) ] z_splits = [(z_total, 0)] for (x11, x12), (z11, z21) in itertools.product(x_splits, z_splits): w12 = w_total overlap = max(0, x11 + z11 - a) + max(0, x12 + w12 - b) u1 = a + b - c - d + x_total u2 = a + c - b - d + z_total - w_total q2 = ( 2 * x_total * (z_total + w_total) - u1 * u1 - u2 * u2 - 2 * (a + d) * (b + c) - 2 * z_total * w_total ) core2 = ( q2 - 2 * k - 3 * (x_total + z_total + w_total) - 2 * overlap ) # Exact doubled hub contributions. A1 is # forced into C; the other flags follow the # triangle-partner forcing rules. ha1 = -3 * a - 3 * b - 2 * x_total - c - d + z21 ha2 = -3 * a - 3 * c - 2 * z_total - b - d - w_total + x12 hb1 = -3 * c - 3 * d - a - b - x_total + z11 + w12 hb2 = -3 * b - 3 * d - 2 * w_total - a - c - z_total + x11 a2_flags = (1,) if z_total >= 1 else (0, 1) b2_flags = (1,) if w_total >= 1 else (0, 1) for in_a2, in_b2, in_b1 in itertools.product(a2_flags, b2_flags, (0, 1)): needs_side1 = int(not in_a2 or not in_b2) needs_side2 = 1 - in_b1 # Two different witnesses are needed # when both roles occur: they cannot be # D vertices (all opposite D distances # <=4 with >=2 bridge types), nor can a # single partition/W vertex be far from # b1 and from an excluded e2 hub. n_lb = ( 2 * k + x_total + z_total + w_total + 4 + needs_side1 + needs_side2 ) if n_lb > N_MAX: continue pair_d = ( (-2 if in_b1 else 0) + (-2 if in_a2 and in_b2 else 0) + (1 if in_a2 and a == 0 else 0) + (1 if in_b2 and b == 0 else 0) + (1 if in_b1 and in_a2 and c == 0 else 0) + (1 if in_b1 and in_b2 and d == 0 else 0) ) doubled_upper = core2 + 2 * ( ha1 + (ha2 if in_a2 else 0) + (hb1 if in_b1 else 0) + (hb2 if in_b2 else 0) + pair_d ) exact_states += 1 if doubled_upper >= 2: all_positive_states += 1 assert doubled_upper % 2 == 0 feasible.append( { "n_lower_bound": n_lb, "S_minus_3M_upper": doubled_upper // 2, "a": a, "b": b, "c": c, "d": d, "x11": x11, "x12": x12, "z11": z11, "w12": w12, "z21": z21, "a2_in_C": in_a2, "b1_in_C": in_b1, "b2_in_C": in_b2, } ) assert feasible, f"orbit {which}: no feasible cases" assert all(item["n_lower_bound"] == 170 for item in feasible) return { "orbit": which, "n_max": N_MAX, "raw_parameter_tuples": raw_parameter_tuples, "parameter_tuples_after_single_type_exclusion": multitype_parameter_tuples, "outer_bound_survivors": outer_kept, "x_stage_survivors": x_stage_kept, "exact_flagged_states": exact_states, "positive_upper_bound_states": all_positive_states, "minimum_n_lower_bound": min(s["n_lower_bound"] for s in feasible), "cases": feasible, } def build_f1( a: int, d: int, extra_u_edge: bool = False, extra_v_edge: bool = False, ) -> tuple[list[str], list[tuple[int, int]]]: labels = ["a1", "b1", "a2", "b2"] p = list(range(len(labels), len(labels) + a)) labels += [f"p{i:02d}" for i in range(1, a + 1)] q = list(range(len(labels), len(labels) + a)) labels += [f"q{i:02d}" for i in range(1, a + 1)] x = list(range(len(labels), len(labels) + a)) labels += [f"x{i:02d}" for i in range(1, a + 1)] z = list(range(len(labels), len(labels) + a)) labels += [f"z{i:02d}" for i in range(1, a + 1)] u = list(range(len(labels), len(labels) + d)) labels += [f"u{i:02d}" for i in range(1, d + 1)] v = list(range(len(labels), len(labels) + d)) labels += [f"v{i:02d}" for i in range(1, d + 1)] ell1, ell2 = len(labels), len(labels) + 1 labels += ["ell1", "ell2"] edges: list[tuple[int, int]] = [(0, 1), (2, 3)] for i in range(a): edges.extend( [ (0, p[i]), (2, q[i]), (p[i], q[i]), (0, x[i]), (p[i], x[i]), (2, z[i]), (q[i], z[i]), ] ) for j in range(d): edges.extend([(1, u[j]), (3, v[j]), (u[j], v[j])]) edges.extend([(0, ell1), (2, ell2)]) if extra_u_edge: edges.append((u[0], u[1])) if extra_v_edge: edges.append((v[0], v[1])) return labels, edges def all_pairs_distances(n: int, edges: list[tuple[int, int]]) -> list[list[int]]: adj = [set() for _ in range(n)] for u, v in edges: adj[u].add(v) adj[v].add(u) result = [] for start in range(n): distance = [-1] * n distance[start] = 0 queue = deque([start]) while queue: current = queue.popleft() for neighbor in adj[current]: if distance[neighbor] < 0: distance[neighbor] = distance[current] + 1 queue.append(neighbor) assert all(value >= 0 for value in distance) result.append(distance) return result def verify_edge_effect() -> dict: """Independently compute all changed center-pair distances for U/V edges.""" base_labels, base_edges = build_f1(22, 38) n = len(base_labels) base_adj = [set() for _ in range(n)] for u, v in base_edges: base_adj[u].add(v) base_adj[v].add(u) base_dist = all_pairs_distances(n, base_edges) ecc = [max(row) for row in base_dist] centers = [v for v, value in enumerate(ecc) if value == 4] assert len(centers) == 166 expected = { "U": {frozenset(("u01", "u02")), frozenset(("u01", "v02")), frozenset(("u02", "v01"))}, "V": {frozenset(("v01", "v02")), frozenset(("u01", "v02")), frozenset(("u02", "v01"))}, } output = {} for side in ("U", "V"): labels, edges = build_f1(22, 38, extra_u_edge=(side == "U"), extra_v_edge=(side == "V")) changed = all_pairs_distances(n, edges) differences = [] for i, j in itertools.combinations(centers, 2): delta = changed[i][j] - base_dist[i][j] if delta: differences.append( { "pair": sorted((labels[i], labels[j])), "base_distance": base_dist[i][j], "new_distance": changed[i][j], "delta": delta, } ) actual = {frozenset(row["pair"]) for row in differences} assert actual == expected[side] assert all(row["delta"] == -1 for row in differences) output[side] = {"changed_center_pairs": differences, "S_change": -len(differences)} # A U edge {1,2} and V edge {2,3} share an index but not an unordered # index pair; they are both allowed, and their six affected center pairs # are distinct. This checks additivity when the two sides share a vertex # index, the only potentially non-obvious overlap case. labels, edges = build_f1(22, 38) u = [i for i, name in enumerate(labels) if name.startswith("u")] v = [i for i, name in enumerate(labels) if name.startswith("v")] edges.extend([(u[1], u[2]), (v[2], v[3])]) temporary_adj = [set() for _ in range(n)] for left, right in edges: temporary_adj[left].add(right) temporary_adj[right].add(left) assert max( len(temporary_adj[left] & temporary_adj[right]) for left in range(n) for right in range(left + 1, n) ) <= 1 both = all_pairs_distances(n, edges) multi_diff = [] for i, j in itertools.combinations(centers, 2): delta = both[i][j] - base_dist[i][j] if delta: multi_diff.append((i, j, delta)) assert len(multi_diff) == 6 and all(delta == -1 for _, _, delta in multi_diff) output["two_distinct_index_pairs"] = {"changed_center_pair_count": 6, "S_change": -6} return output def encode_graph6(n: int, edges: list[tuple[int, int]]) -> str: edge_set = {tuple(sorted(e)) for e in edges} if len(edge_set) != len(edges): raise AssertionError("duplicate edge") if any(u == v or u < 0 or v >= n for u, v in edge_set): raise AssertionError("invalid edge") if n <= 62: header = chr(n + 63) elif n <= 258047: header = "~" + "".join(chr(63 + ((n >> shift) & 63)) for shift in (12, 6, 0)) else: raise ValueError("n too large for this graph6 encoder") bits = [] for j in range(1, n): for i in range(j): bits.append(1 if (i, j) in edge_set else 0) while len(bits) % 6: bits.append(0) payload = [] for pos in range(0, len(bits), 6): val = 0 for bit in bits[pos : pos + 6]: val = (val << 1) | bit payload.append(chr(63 + val)) return header + "".join(payload) def decode_graph6(text: str) -> tuple[int, list[tuple[int, int]]]: pos = 0 if text.startswith("~"): n = ((ord(text[1]) - 63) << 12) | ((ord(text[2]) - 63) << 6) | (ord(text[3]) - 63) pos = 4 else: n = ord(text[0]) - 63 pos = 1 bits = [] for ch in text[pos:]: value = ord(ch) - 63 bits.extend((value >> shift) & 1 for shift in (5, 4, 3, 2, 1, 0)) edges = [] cursor = 0 for j in range(1, n): for i in range(j): if bits[cursor]: edges.append((i, j)) cursor += 1 return n, edges def graph_measurements(labels: list[str], edges: list[tuple[int, int]]) -> dict: n = len(labels) edge_set = {tuple(sorted(edge)) for edge in edges} assert len(edge_set) == len(edges) adj = [set() for _ in range(n)] for u, v in edges: assert 0 <= u < n and 0 <= v < n and u != v adj[u].add(v) adj[v].add(u) adjmask = [sum(1 << w for w in neigh) for neigh in adj] # C4-free iff every pair has at most one common neighbor. max_common_neighbors = 0 for u in range(n): for v in range(u + 1, n): max_common_neighbors = max(max_common_neighbors, len(adj[u] & adj[v])) assert max_common_neighbors <= 1 dists = [] eccentricities = [] for start in range(n): distance = [-1] * n distance[start] = 0 queue = deque([start]) while queue: current = queue.popleft() for neighbor in adj[current]: if distance[neighbor] < 0: distance[neighbor] = distance[current] + 1 queue.append(neighbor) assert all(value >= 0 for value in distance) dists.append(distance) eccentricities.append(max(distance)) radius = min(eccentricities) centers = [v for v, e in enumerate(eccentricities) if e == radius] pair_count = len(centers) * (len(centers) - 1) // 2 distance_sum = sum( dists[centers[i]][centers[j]] for i in range(len(centers)) for j in range(i + 1, len(centers)) ) # Exact total-domination check by exhaustive bit-mask coverage of all # subsets of size at most 3; the displayed D verifies size 4. full = (1 << n) - 1 tested = {"size_1": 0, "size_2": 0, "size_3": 0} for size in (1, 2, 3): found = False for chosen in itertools.combinations(range(n), size): tested[f"size_{size}"] += 1 covered = 0 for v in chosen: covered |= adjmask[v] if covered == full: found = True break assert not found, f"total dominating set of size {size}: {found}" D = [0, 1, 2, 3] covered = 0 for v in D: covered |= adjmask[v] assert covered == full assert all(eccentricities[v] == 5 for v in (1, 3, labels.index("ell1"), labels.index("ell2"))) # Check basic connectivity and expected center/noncenter partition. assert radius == 4 assert len(centers) == 166 assert set(centers) == set(range(n)) - {1, 3, labels.index("ell1"), labels.index("ell2")} return { "n": n, "m": len(edges), "connected": True, "C4_free": True, "max_common_neighbors": max_common_neighbors, "gamma_t": 4, "gamma_t_subsets_tested": tested, "radius": radius, "center_size": len(centers), "noncenters": [labels[v] for v, e in enumerate(eccentricities) if e != radius], "M": pair_count, "S": distance_sum, "S_minus_3M": distance_sum - 3 * pair_count, } def verify_examples() -> dict: cases = [ ("F1(21,40)", 21, 40, False, 271, 2), ("F1(22,38)", 22, 38, False, 272, 4), ("F1(22,38)+u01u02", 22, 38, True, 273, 1), ] results = [] graph6_records = [] for name, a, d, extra, expected_m, expected_excess in cases: labels, edges = build_f1(a, d, extra) measurements = graph_measurements(labels, edges) assert measurements["m"] == expected_m assert measurements["S_minus_3M"] == expected_excess graph6 = encode_graph6(len(labels), edges) decoded_n, decoded_edges = decode_graph6(graph6) assert decoded_n == len(labels) assert sorted(decoded_edges) == sorted(tuple(sorted(edge)) for edge in edges) results.append( { "name": name, "vertex_labels_by_index": labels, "edges_by_label": [[labels[u], labels[v]] for u, v in edges], "graph6": graph6, "graph6_sha256": hashlib.sha256(graph6.encode("ascii")).hexdigest(), "measurements": measurements, } ) graph6_records.append(graph6) assert len({r["measurements"]["m"] for r in results}) == 3 return { "definition": "F1(a,d): D={a1b1,a2b2}; for i, edges a1-pi,a2-qi,pi-qi,a1-xi,pi-xi,a2-zi,qi-zi; for j, edges b1-uj,b2-vj,uj-vj; leaves ell1-a1 and ell2-a2. Third graph adds u01-u02.", "cases": results, "pairwise_nonisomorphic_by_distinct_edge_counts": True, "graph6_file": "minimum_examples.g6", }, graph6_records def main() -> None: search = { "scope": "Exact integer parameter search conditional on the certified 8-cone inequality and structural lemmas stated in MINIMUM.md.", "orbits": [orbit_parameter_search(3), orbit_parameter_search(4)], } examples, records = verify_examples() edge_effect = verify_edge_effect() out = {"parameter_search": search, "finite_examples": examples, "extra_edge_effect": edge_effect} (HERE / "minimum_replicate.json").write_text(json.dumps(out, indent=2) + "\n", encoding="utf-8") (HERE / "minimum_examples.g6").write_text("\n".join(records) + "\n", encoding="ascii") for result in search["orbits"]: print( f"orbit{result['orbit']}: raw={result['raw_parameter_tuples']}; " f"multi-type={result['parameter_tuples_after_single_type_exclusion']}; " f"outer={result['outer_bound_survivors']}; x-stage={result['x_stage_survivors']}; " f"exact={result['exact_flagged_states']}; positive={result['positive_upper_bound_states']}; " f"min n_lb={result['minimum_n_lower_bound']}" ) for case in result["cases"]: print(" ", json.dumps(case, sort_keys=True)) for case in examples["cases"]: m = case["measurements"] print( f"{case['name']}: n={m['n']} m={m['m']} connected={m['connected']} " f"C4-free={m['C4_free']} gamma_t={m['gamma_t']} rad={m['radius']} " f"|C|={m['center_size']} M={m['M']} S={m['S']} S-3M={m['S_minus_3M']} " f"graph6_sha256={case['graph6_sha256']}" ) print("extra edge effect:", json.dumps(edge_effect, sort_keys=True)) print("wrote minimum_replicate.json and minimum_examples.g6 next to this script") if __name__ == "__main__": main()