#!/usr/bin/env python3 """Independent finite checks for the mixed 2/3-cluster cube-free construction. Uses only the Python standard library. The complete combinatorial proof does not depend on these finite checks. Run from any directory; the JSON report is written next to this script unless --output is supplied. """ import argparse import itertools import json import math from fractions import Fraction from pathlib import Path import random import time CUBE_EDGES = [ (u, v) for u in range(8) for v in range(u + 1, 8) if (u ^ v).bit_count() == 1 ] C6_MASKS = [ 511 ^ sum(1 << (3 * i + p[i]) for i in range(3)) for p in itertools.permutations(range(3)) ] def contains_bipartite_c6(mask): return any(mask & cycle == cycle for cycle in C6_MASKS) def partitions_bounded(items, bound=3): if not items: yield [] return first = items[0] for partition in partitions_bounded(items[1:], bound): yield [[first]] + partition for i, block in enumerate(partition): if len(block) < bound: yield partition[:i] + [[first] + block] + partition[i + 1:] def adjacency_from_edges(order, edges): adjacency = [0] * order for u, v in edges: assert u != v adjacency[u] |= 1 << v adjacency[v] |= 1 << u return adjacency def is_c4_free(adjacency): return all( (adjacency[u] & adjacency[v]).bit_count() <= 1 for u in range(len(adjacency)) for v in range(u) ) def check_quotients(): total = independent = c4_free = 0 classes = {} for partition in partitions_bounded(list(range(8))): total += 1 owner = {v: i for i, block in enumerate(partition) for v in block} if any(owner[u] == owner[v] for u, v in CUBE_EDGES): continue independent += 1 quotient_edges = { tuple(sorted((owner[u], owner[v]))) for u, v in CUBE_EDGES } if not is_c4_free(adjacency_from_edges(len(partition), quotient_edges)): continue c4_free += 1 triples = [i for i, block in enumerate(partition) if len(block) == 3] witnesses = [] for i, j in itertools.combinations(triples, 2): mask = 0 for a, u in enumerate(partition[i]): for b, v in enumerate(partition[j]): if (u ^ v).bit_count() == 1: mask |= 1 << (3 * a + b) if contains_bipartite_c6(mask): witnesses.append([i, j]) assert witnesses, partition key = ",".join(map(str, sorted(map(len, partition), reverse=True))) classes[key] = classes.get(key, 0) + 1 return { "partitions_with_blocks_at_most_three": total, "partitions_with_independent_blocks": independent, "independent_block_partitions_with_c4_free_quotient": c4_free, "c4_free_quotient_block_sizes": classes, "all_have_two_triple_blocks_with_crossing_c6": True, } def check_small_blocks(): histogram = {} extremizers = [] for mask in range(512): if contains_bipartite_c6(mask): continue size = mask.bit_count() histogram[size] = histogram.get(size, 0) + 1 if size == 7: extremizers.append(mask) gadget = sum(1 << (3 * i + j) for i in (0, 1) for j in range(3)) | (1 << 6) assert gadget.bit_count() == 7 and not contains_bipartite_c6(gadget) assert max(histogram) == 7 return { "masks_examined": 512, "c6_free_masks_by_edge_count": histogram, "maximum_c6_free_edge_count": 7, "number_of_seven_edge_extremizers": len(extremizers), "chosen_gadget_mask": gadget, } def projective_points(q): points = set() for vector in itertools.product(range(q), repeat=3): if not any(vector): continue pivot = next(x for x in vector if x) inverse = pow(pivot, -1, q) points.add(tuple(x * inverse % q for x in vector)) return sorted(points) def polarity_graph(q): points = projective_points(q) edges = [ (i, j) for i, u in enumerate(points) for j, v in enumerate(points[:i]) if sum(a * b for a, b in zip(u, v)) % q == 0 ] edges = sorted(tuple(sorted(edge)) for edge in edges) adjacency = adjacency_from_edges(len(points), edges) assert len(points) == q * q + q + 1 assert len(edges) == q * (q + 1) ** 2 // 2 assert is_c4_free(adjacency) return edges, adjacency def score_heavy_subset(edges, adjacency, heavy): return ( 4 * len(edges) + 2 * sum(adjacency[u].bit_count() for u in heavy) - sum(u in heavy and v in heavy for u, v in edges) ) def choose_heavy_subset(edges, adjacency, size, seed): order = len(adjacency) combinations = math.comb(order, size) exhaustive = combinations <= 20000 if exhaustive: candidates = itertools.combinations(range(order), size) else: rng = random.Random(seed) candidates = ( tuple(sorted(rng.sample(range(order), size))) for _ in range(5000) ) best_score = -1 best = None examined = 0 for candidate in candidates: examined += 1 heavy = set(candidate) score = score_heavy_subset(edges, adjacency, heavy) if score > best_score: best_score, best = score, heavy expectation = len(edges) * ( 4 + Fraction(4 * size, order) - Fraction(size * (size - 1), order * (order - 1)) ) assert best_score >= expectation return best, best_score, expectation, { "method": "exhaustive" if exhaustive else "deterministic_seed_sampling", "subsets_examined": examined, "seed": seed, } def mixed_blowup(edges, order, heavy): clusters = [] offset = 0 for u in range(order): size = 3 if u in heavy else 2 clusters.append(list(range(offset, offset + size))) offset += size expanded_edges = [] for u, v in edges: for i, a in enumerate(clusters[u]): for j, b in enumerate(clusters[v]): if u in heavy and v in heavy and i == 2 and j != 0: continue expanded_edges.append((a, b)) return adjacency_from_edges(offset, expanded_edges), expanded_edges def distinct_representatives(candidates): """Return an SDR when one exists, for witness reconstruction only.""" def recurse(index, used, chosen): if index == 4: return chosen options = candidates[index] & ~used while options: bit = options & -options options ^= bit answer = recurse(index + 1, used | bit, chosen + [bit.bit_length() - 1]) if answer is not None: return answer return None return recurse(0, 0, []) def cube_witness(adjacency): """Exact test in arbitrary graphs, independently of the cluster proof. For each four-set A, seek four distinct vertices outside A, with the ith vertex adjacent to A minus its ith member. Hall's theorem tests this. """ order = len(adjacency) four_sets_examined = 0 nonempty_candidate_systems = 0 for a, b, c, d in itertools.combinations(range(order), 4): four_sets_examined += 1 outside = ~((1 << a) | (1 << b) | (1 << c) | (1 << d)) na, nb, nc, nd = adjacency[a], adjacency[b], adjacency[c], adjacency[d] candidates = [ nb & nc & nd & outside, na & nc & nd & outside, na & nb & nd & outside, na & nb & nc & outside, ] if not all(candidates): continue nonempty_candidate_systems += 1 unions = [0] * 16 hall = True for mask in range(1, 16): bit = mask & -mask unions[mask] = unions[mask ^ bit] | candidates[bit.bit_length() - 1] if unions[mask].bit_count() < mask.bit_count(): hall = False break if hall: witnesses = distinct_representatives(candidates) assert witnesses is not None return { "A": [a, b, c, d], "B": witnesses, }, four_sets_examined, nonempty_candidate_systems return None, four_sets_examined, nonempty_candidate_systems def check_finite_construction(q, optimal_fraction): started = time.perf_counter() edges, base_adjacency = polarity_graph(q) h = len(base_adjacency) k = round(optimal_fraction * h) heavy, predicted, expectation, selection = choose_heavy_subset( edges, base_adjacency, k, seed=20260905 + q ) adjacency, expanded_edges = mixed_blowup(edges, h, heavy) assert len(expanded_edges) == predicted witness, four_sets, nonempty = cube_witness(adjacency) assert witness is None, (q, witness) return { "q": q, "base_vertices": h, "base_edges": len(edges), "base_c4_free": True, "heavy_vertices": sorted(heavy), "heavy_count": k, "expanded_vertices": len(adjacency), "expanded_edges": len(expanded_edges), "fixed_size_expected_edges_exact": str(expectation), "actual_at_least_expected": True, "selection": selection, "cube_check_method": "four_set_triple_neighborhood_Hall_test", "four_sets_examined": four_sets, "nonempty_candidate_systems": nonempty, "cube_free": True, "elapsed_seconds": round(time.perf_counter() - started, 3), } def main(): parser = argparse.ArgumentParser() parser.add_argument( "--output", type=Path, default=Path(__file__).with_name("lower_construction_verification.json"), ) args = parser.parse_args() x = 2 * math.sqrt(10) - 6 coefficient = (2 + 2 * x - x * x / 2) / (2 + x) ** 1.5 closed_form = math.sqrt((40 * math.sqrt(10) - 112) / 27) assert abs(coefficient - closed_form) < 1e-14 assert abs(1 - 3 * x - x * x / 4) < 1e-14 # Positive controls check that the independent embedding test finds cubes. cube_adjacency = adjacency_from_edges(8, CUBE_EDGES) assert cube_witness(cube_adjacency)[0] is not None k44 = adjacency_from_edges(8, [(a, b) for a in range(4) for b in range(4, 8)]) assert cube_witness(k44)[0] is not None k33 = adjacency_from_edges(6, [(a, b) for a in range(3) for b in range(3, 6)]) assert cube_witness(k33)[0] is None report = { "description": "Finite verification of mixed 2/3-cluster cube-free construction", "quotient_check": check_quotients(), "block_check": check_small_blocks(), "optimized_parameters": { "heavy_fraction_formula": "2*sqrt(10)-6", "heavy_fraction": x, "leading_coefficient_formula": "sqrt((40*sqrt(10)-112)/27)", "leading_coefficient": coefficient, "reference_coefficient": 1 / math.sqrt(2), "relative_increase": coefficient * math.sqrt(2) - 1, "stationary_equation_residual": 1 - 3 * x - x * x / 4, }, "embedding_test_controls_passed": True, "finite_constructions": [], "scope": "Finite checks supplement, and do not replace, the general proof.", } for q in (2, 3, 5): result = check_finite_construction(q, x) report["finite_constructions"].append(result) print(json.dumps(result), flush=True) args.output.write_text(json.dumps(report, indent=2) + "\n") print(f"All checks passed. Report: {args.output}") if __name__ == "__main__": main()