"""Reproduce the 568-vertex simple graph X_7 and its binary incidence rank. Run with Python 3.10 or later. Add --edges FILE to write the sorted edge list. Vertices 4*k through 4*k+3 are the characters on Klein block k. Vertices 560 through 567 are the eight markers in binary digit order. """ import argparse from collections import Counter from itertools import combinations from pathlib import Path def compose(left, right): return tuple(left[value] for value in right) def klein_blocks(): identity = tuple(range(7)) involutions = set() for a, b, c, d in combinations(identity, 4): for x, y, z, t in ((a, b, c, d), (a, c, b, d), (a, d, b, c)): permutation = list(identity) permutation[x], permutation[y] = y, x permutation[z], permutation[t] = t, z involutions.add(tuple(permutation)) ordered = sorted(involutions) indices = {element: index for index, element in enumerate(ordered)} triples = set() for (i, first), (j, second) in combinations(enumerate(ordered), 2): product = compose(first, second) if product in indices: triples.add(tuple(sorted((i, j, indices[product])))) return ordered, sorted(triples) def binary_rank(blocks): pivots = {} for block in blocks: row = sum(1 << column for column in block) while row: pivot = row.bit_length() - 1 if pivot not in pivots: pivots[pivot] = row break row ^= pivots[pivot] return len(pivots) def character_bit(block, character, h): # The first two elements of the sorted triple generate its Klein group. first, second = character & 1, (character >> 1) & 1 return (first, second, first ^ second)[block.index(h)] def graph_edges(blocks): count = 4 * len(blocks) edges = set() for (i, left), (j, right) in combinations(enumerate(blocks), 2): common = set(left).intersection(right) if common: (h,) = common for a in range(4): for b in range(4): if character_bit(left, a, h) == character_bit(right, b, h): edges.add((4 * i + a, 4 * j + b)) for i in range(len(blocks)): for digit in range(8): if (i >> digit) & 1: for a in range(4): edges.add((4 * i + a, count + digit)) for digit in range(7): edges.add((count + digit, count + digit + 1)) return sorted(edges) def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--edges", type=Path, help="write pairs of zero-based vertex IDs") args = parser.parse_args() involutions, blocks = klein_blocks() multiplicities = Counter(h for block in blocks for h in block) assert len(involutions) == 105 and len(blocks) == 140 assert len(multiplicities) == 105 and set(multiplicities.values()) == {4} rank = binary_rank(blocks) assert rank == 105 edges = graph_edges(blocks) degree = Counter(vertex for edge in edges for vertex in edge) markers = tuple(range(560, 568)) marker_degrees = [degree[v] for v in markers] assert len(edges) == 6967 and len(degree) == 568 assert all(0 <= x < y < 568 for x, y in edges) assert all(degree[v] == 18 + (v // 4).bit_count() for v in range(560)) assert marker_degrees == [281, 282, 274, 274, 258, 258, 258, 49] neighborhoods = [set() for _ in range(568)] for x, y in edges: neighborhoods[x].add(y) neighborhoods[y].add(x) for vertex in range(560): code = sum(1 << i for i, marker in enumerate(markers) if marker in neighborhoods[vertex]) assert code == vertex // 4 print(f"Double transpositions: {len(involutions)}") print(f"Klein four blocks: {len(blocks)}") print(f"Binary incidence rank: {rank}") print(f"Vertices: {len(degree)}") print(f"Edges: {len(edges)}") print("Marker degrees:", *marker_degrees) if args.edges: separator = "\t" if args.edges.suffix.lower() == ".tsv" else " " args.edges.write_text("".join(f"{x}{separator}{y}\n" for x, y in edges), encoding="ascii") if __name__ == "__main__": main()