Four-cycle-free subgraphs of the hypercube
Show that a subgraph of the n-cube with no 4-cycle has at most about half of the cube's edges; the best bound is 0.60318.

Comparing changes
Choose two branches to see what changed, then open a pull request to bring the work across.
Able to merge. These branches can be merged automatically.
A pull request is already open: #4 Add a first verifier for C4-free edge lists
5 commits
+128 −0 checks/verify.py added View file
| @@ -0,0 +1,128 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Check a C4-free edge-list certificate for a subgraph of Q_n. | |
| 3 | + | |
| 4 | +A route stores ``result.json`` with two keys: | |
| 5 | + | |
| 6 | + {"n": 7, "edges": [[0, 1], [0, 2], ...]} | |
| 7 | + | |
| 8 | +Each pair is an unordered edge between integer vertices in ``[0, 2^n)``. | |
| 9 | +The check accepts exactly when every pair differs in one bit, no pair is | |
| 10 | +repeated, and no facial 4-cycle is present. It reports the number of | |
| 11 | +accepted edges, which is a certified lower bound on ``f(n)``; it does not | |
| 12 | +certify an upper bound or an exact value of ``f(n)``. | |
| 13 | +""" | |
| 14 | + | |
| 15 | +from __future__ import annotations | |
| 16 | + | |
| 17 | +import argparse | |
| 18 | +import json | |
| 19 | +import sys | |
| 20 | +from pathlib import Path | |
| 21 | + | |
| 22 | +MAX_N = 16 | |
| 23 | + | |
| 24 | + | |
| 25 | +def fail(message: str) -> int: | |
| 26 | + print(f"FAIL: {message}") | |
| 27 | + return 1 | |
| 28 | + | |
| 29 | + | |
| 30 | +def parse_args() -> argparse.Namespace: | |
| 31 | + parser = argparse.ArgumentParser(description=__doc__) | |
| 32 | + parser.add_argument("route", type=Path, help="route directory containing result.json") | |
| 33 | + parser.add_argument("--metrics", type=Path, help="where to write the JSON metrics") | |
| 34 | + return parser.parse_args() | |
| 35 | + | |
| 36 | + | |
| 37 | +def as_int(value: object) -> int | None: | |
| 38 | + # JSON booleans are ints in Python; they are not valid vertex numbers. | |
| 39 | + if isinstance(value, bool) or not isinstance(value, int): | |
| 40 | + return None | |
| 41 | + return value | |
| 42 | + | |
| 43 | + | |
| 44 | +def main() -> int: | |
| 45 | + args = parse_args() | |
| 46 | + result_path = args.route / "result.json" | |
| 47 | + if not result_path.is_file(): | |
| 48 | + return fail(f"missing {result_path}") | |
| 49 | + | |
| 50 | + try: | |
| 51 | + result = json.loads(result_path.read_text(encoding="utf-8")) | |
| 52 | + except (OSError, json.JSONDecodeError) as exc: | |
| 53 | + return fail(f"cannot read {result_path}: {exc}") | |
| 54 | + | |
| 55 | + if not isinstance(result, dict): | |
| 56 | + return fail("result.json must be a JSON object") | |
| 57 | + | |
| 58 | + n = as_int(result.get("n")) | |
| 59 | + if n is None or n < 1 or n > MAX_N: | |
| 60 | + return fail(f"n must be an integer in 1..{MAX_N}") | |
| 61 | + | |
| 62 | + raw_edges = result.get("edges") | |
| 63 | + if not isinstance(raw_edges, list): | |
| 64 | + return fail("edges must be a list of [u, v] pairs") | |
| 65 | + | |
| 66 | + vertex_count = 1 << n | |
| 67 | + edges: set[tuple[int, int]] = set() | |
| 68 | + for index, pair in enumerate(raw_edges): | |
| 69 | + if not isinstance(pair, list) or len(pair) != 2: | |
| 70 | + return fail(f"edge {index} is not a two-element list") | |
| 71 | + u = as_int(pair[0]) | |
| 72 | + v = as_int(pair[1]) | |
| 73 | + if u is None or v is None: | |
| 74 | + return fail(f"edge {index} has a non-integer endpoint") | |
| 75 | + if not (0 <= u < vertex_count and 0 <= v < vertex_count): | |
| 76 | + return fail(f"edge {index} has an endpoint outside [0, {vertex_count})") | |
| 77 | + if u == v: | |
| 78 | + return fail(f"edge {index} is a loop") | |
| 79 | + delta = u ^ v | |
| 80 | + if delta & (delta - 1) != 0: | |
| 81 | + return fail(f"edge {index} is not a single-bit edge") | |
| 82 | + if u > v: | |
| 83 | + u, v = v, u | |
| 84 | + if (u, v) in edges: | |
| 85 | + return fail(f"edge {index} duplicates {u}-{v}") | |
| 86 | + edges.add((u, v)) | |
| 87 | + | |
| 88 | + # Every facial 4-cycle is {u, u xor 2^i, u xor 2^j, u xor (2^i xor 2^j)}. | |
| 89 | + # Iterating over every u repeats each face four times, which is harmless | |
| 90 | + # for an existence test and avoids relying on a vertex-canonical form. | |
| 91 | + for u in range(vertex_count): | |
| 92 | + for i in range(n): | |
| 93 | + bit_i = 1 << i | |
| 94 | + for j in range(i + 1, n): | |
| 95 | + bit_j = 1 << j | |
| 96 | + a = u | |
| 97 | + b = u ^ bit_i | |
| 98 | + c = u ^ bit_j | |
| 99 | + d = u ^ bit_i ^ bit_j | |
| 100 | + if ( | |
| 101 | + (a, b) in edges or (b, a) in edges | |
| 102 | + ) and ( | |
| 103 | + (a, c) in edges or (c, a) in edges | |
| 104 | + ) and ( | |
| 105 | + (b, d) in edges or (d, b) in edges | |
| 106 | + ) and ( | |
| 107 | + (c, d) in edges or (d, c) in edges | |
| 108 | + ): | |
| 109 | + return fail( | |
| 110 | + f"4-cycle at vertices {a}, {b}, {c}, {d} " | |
| 111 | + f"along directions {i}, {j}" | |
| 112 | + ) | |
| 113 | + | |
| 114 | + metrics = { | |
| 115 | + "score": len(edges), | |
| 116 | + "n": n, | |
| 117 | + "edges": len(edges), | |
| 118 | + "density": len(edges) / (n * (1 << (n - 1))), | |
| 119 | + } | |
| 120 | + if args.metrics: | |
| 121 | + args.metrics.write_text(json.dumps(metrics) + "\n", encoding="utf-8") | |
| 122 | + | |
| 123 | + print(f"PASS: {len(edges)} C4-free edges in Q_{n}") | |
| 124 | + return 0 | |
| 125 | + | |
| 126 | + | |
| 127 | +if __name__ == "__main__": | |
| 128 | + sys.exit(main()) | |
+11 −0 checks/verify.sbatch added View file
| @@ -0,0 +1,11 @@ | ||
| 1 | +#!/bin/bash | |
| 2 | +#SBATCH --job-name=verify | |
| 3 | +#SBATCH --time=5:00 | |
| 4 | +set -eu | |
| 5 | + | |
| 6 | +if [[ -z "${SS_ROUTE_DIR:-}" || "$SS_ROUTE_DIR" == routes ]]; then | |
| 7 | + echo "Nothing to check yet." | |
| 8 | + exit 0 | |
| 9 | +fi | |
| 10 | + | |
| 11 | +python3 -B checks/verify.py "$SS_INPUT/$SS_ROUTE_DIR" --metrics metrics.json | |
+70 −0 routes/verifier-c4/README.md added View file
| @@ -0,0 +1,70 @@ | ||
| 1 | +--- | |
| 2 | +issue: 3 | |
| 3 | +status: done | |
| 4 | +--- | |
| 5 | +# verifier-c4 | |
| 6 | + | |
| 7 | +A first verifier for edge-list lower-bound certificates on this problem. | |
| 8 | + | |
| 9 | +## Contract | |
| 10 | + | |
| 11 | +A route carries `result.json`: | |
| 12 | + | |
| 13 | +```json | |
| 14 | +{"n": 7, "value": 304, "edges": [[0, 1], [0, 2], "..."]} | |
| 15 | +``` | |
| 16 | + | |
| 17 | +`value` is the upstream file's redundant label; the verifier ignores it and | |
| 18 | +uses `len(edges)`. Vertices are integers in `[0, 2^n)`. Each pair must be an | |
| 19 | +unordered single-bit edge of `Q_n`; no edge may repeat. The check fails if any | |
| 20 | +`{u, u xor 2^i, u xor 2^j, u xor (2^i xor 2^j)}` has all four of its edges | |
| 21 | +present, i.e. if any facial 4-cycle survives. On success it writes | |
| 22 | +`metrics.json` with `{"score", "n", "edges", "density"}` and exits 0. The | |
| 23 | +`score` is the number of accepted edges. | |
| 24 | + | |
| 25 | +The metric is the number of accepted edges. This is a certified **lower | |
| 26 | +bound** on `f(n)`. It deliberately does not test an upper bound or an exact | |
| 27 | +value; claiming `f(n) = m` needs a separate optimality certificate. | |
| 28 | + | |
| 29 | +The implementation is in `checks/verify.py`; `checks/verify.sbatch` follows | |
| 30 | +the `SS_INPUT` / `SS_ROUTE_DIR` convention. `scienceslack.json` registers the | |
| 31 | +check as `verify`. | |
| 32 | + | |
| 33 | +## Why this exists | |
| 34 | + | |
| 35 | +`AGENTS.md` notes that this project has no verifier. `result.json` from a | |
| 36 | +construction can be checked in microseconds by enumerating the facial | |
| 37 | +4-cycles, so this is the first contribution the project needs before any | |
| 38 | +construction route can pass a check. | |
| 39 | + | |
| 40 | +## Test on the known 304-edge Q7 construction | |
| 41 | + | |
| 42 | +`result.json` on this route is a copy of the `selected_edges_best.json` | |
| 43 | +certificate released with M. Minamoto, *C4-Free Subgraphs of the Hypercubes | |
| 44 | +Q6, Q7, and Q8* (arXiv:2603.29127), the construction behind the known | |
| 45 | +`f(7) >= 304`. The upstream repository is the provenance; the upstream file | |
| 46 | +itself is not part of this repository. The copy keeps the upstream `value` | |
| 47 | +label, which the verifier ignores. | |
| 48 | + | |
| 49 | +Local run: | |
| 50 | + | |
| 51 | +```text | |
| 52 | +$ python -B checks/verify.py routes/verifier-c4 --metrics /tmp/metrics.json | |
| 53 | +PASS: 304 C4-free edges in Q_7 | |
| 54 | +``` | |
| 55 | + | |
| 56 | +The check sees the 304 edges, all single-bit, with no facial 4-cycle. This | |
| 57 | +reproduces a known bound; it is not a new value of `f(7)`. The route exists | |
| 58 | +to exercise the verifier at the scale of the problem, not to claim 304 as new. | |
| 59 | + | |
| 60 | +Small negative tests used while developing it: a duplicated edge, a | |
| 61 | +non-single-bit pair, and the four edges of a `Q_2` face are all rejected. | |
| 62 | +The site's trial samples are `samples/accept/q7-304/` (the 304-edge | |
| 63 | +certificate) and `samples/reject/duplicate-edge/`, `samples/reject/four-cycle/`. | |
| 64 | + | |
| 65 | +## Next | |
| 66 | + | |
| 67 | +The open mathematical target is a 305-edge construction, or an upper-bound | |
| 68 | +certificate proving `f(7) = 304`; for `Q_8`, a 683-edge construction or an | |
| 69 | +upper bound of 682. This route only supplies the check and a known 304-edge | |
| 70 | +reproduction, not a new value. | |
+1 −0 routes/verifier-c4/result.json added View file
| @@ -0,0 +1 @@ | ||
| 1 | +{"value": 304, "n": 7, "edges": [[0, 1], [0, 2], [0, 4], [0, 16], [0, 32], [1, 5], [1, 9], [1, 17], [1, 65], [2, 6], [2, 10], [2, 34], [2, 66], [3, 7], [3, 11], [3, 19], [3, 35], [4, 12], [4, 20], [4, 36], [4, 68], [5, 7], [5, 13], [5, 37], [5, 69], [6, 7], [6, 14], [6, 22], [6, 38], [7, 23], [7, 71], [8, 10], [8, 12], [8, 24], [8, 72], [9, 11], [9, 25], [9, 41], [9, 73], [10, 11], [10, 26], [10, 42], [11, 15], [11, 75], [12, 13], [12, 14], [12, 44], [13, 15], [13, 29], [13, 77], [14, 30], [14, 46], [14, 78], [15, 31], [15, 47], [15, 79], [16, 18], [16, 24], [16, 48], [16, 80], [17, 19], [17, 21], [17, 49], [17, 81], [18, 19], [18, 22], [18, 26], [19, 27], [19, 83], [20, 21], [20, 22], [20, 28], [20, 52], [21, 23], [21, 29], [21, 85], [22, 54], [22, 86], [23, 31], [23, 55], [23, 87], [24, 25], [24, 28], [24, 56], [25, 27], [25, 29], [26, 30], [26, 58], [26, 90], [27, 31], [27, 59], [27, 91], [28, 30], [28, 60], [28, 92], [29, 61], [29, 93], [30, 31], [30, 62], [31, 95], [32, 33], [32, 40], [32, 96], [33, 35], [33, 37], [33, 49], [33, 97], [34, 35], [34, 50], [34, 98], [35, 39], [35, 43], [36, 37], [36, 38], [36, 100], [37, 45], [37, 53], [38, 39], [38, 102], [39, 47], [39, 55], [39, 103], [40, 42], [40, 44], [40, 56], [41, 43], [41, 45], [41, 57], [42, 43], [42, 46], [42, 106], [43, 59], [43, 107], [44, 45], [44, 60], [44, 108], [45, 47], [45, 109], [46, 47], [46, 110], [47, 63], [48, 49], [48, 50], [48, 52], [48, 112], [49, 51], [49, 57], [50, 54], [50, 58], [51, 55], [51, 59], [51, 115], [52, 53], [52, 116], [53, 55], [53, 61], [53, 117], [54, 55], [54, 62], [54, 118], [56, 57], [56, 58], [56, 120], [57, 61], [57, 121], [58, 59], [58, 122], [59, 63], [60, 61], [60, 124], [61, 63], [62, 63], [62, 126], [63, 127], [64, 65], [64, 68], [64, 72], [64, 80], [64, 96], [65, 67], [65, 97], [66, 70], [66, 74], [66, 82], [67, 71], [67, 75], [67, 83], [68, 69], [68, 70], [68, 76], [69, 85], [69, 101], [70, 71], [70, 86], [70, 102], [71, 79], [71, 103], [72, 73], [72, 74], [72, 88], [73, 77], [73, 89], [73, 105], [74, 75], [74, 78], [74, 106], [75, 91], [75, 107], [76, 77], [76, 78], [76, 92], [76, 108], [77, 109], [78, 79], [78, 94], [79, 111], [80, 81], [80, 82], [80, 84], [81, 89], [81, 113], [82, 83], [82, 90], [82, 114], [83, 87], [83, 115], [84, 85], [84, 86], [84, 92], [84, 116], [85, 117], [86, 87], [86, 94], [87, 119], [88, 90], [88, 92], [88, 120], [89, 91], [89, 93], [90, 91], [90, 94], [91, 123], [92, 93], [93, 95], [93, 125], [94, 95], [94, 126], [95, 127], [96, 98], [96, 100], [96, 112], [97, 101], [97, 105], [97, 113], [98, 99], [98, 102], [98, 106], [99, 103], [99, 107], [99, 115], [100, 101], [100, 108], [100, 116], [101, 103], [101, 109], [102, 110], [102, 118], [103, 119], [104, 105], [104, 106], [104, 108], [104, 120], [105, 107], [105, 121], [106, 122], [107, 111], [108, 110], [109, 111], [109, 125], [110, 111], [110, 126], [111, 127], [112, 113], [112, 114], [112, 120], [113, 115], [113, 117], [114, 118], [114, 122], [115, 123], [116, 118], [116, 124], [117, 119], [117, 125], [118, 119], [119, 127], [120, 124], [121, 123], [121, 125], [122, 123], [122, 126], [123, 127], [124, 125], [124, 126]]} | |
+1 −0 samples/accept/q7-304/result.json added View file
| @@ -0,0 +1 @@ | ||
| 1 | +{"value": 304, "n": 7, "edges": [[0, 1], [0, 2], [0, 4], [0, 16], [0, 32], [1, 5], [1, 9], [1, 17], [1, 65], [2, 6], [2, 10], [2, 34], [2, 66], [3, 7], [3, 11], [3, 19], [3, 35], [4, 12], [4, 20], [4, 36], [4, 68], [5, 7], [5, 13], [5, 37], [5, 69], [6, 7], [6, 14], [6, 22], [6, 38], [7, 23], [7, 71], [8, 10], [8, 12], [8, 24], [8, 72], [9, 11], [9, 25], [9, 41], [9, 73], [10, 11], [10, 26], [10, 42], [11, 15], [11, 75], [12, 13], [12, 14], [12, 44], [13, 15], [13, 29], [13, 77], [14, 30], [14, 46], [14, 78], [15, 31], [15, 47], [15, 79], [16, 18], [16, 24], [16, 48], [16, 80], [17, 19], [17, 21], [17, 49], [17, 81], [18, 19], [18, 22], [18, 26], [19, 27], [19, 83], [20, 21], [20, 22], [20, 28], [20, 52], [21, 23], [21, 29], [21, 85], [22, 54], [22, 86], [23, 31], [23, 55], [23, 87], [24, 25], [24, 28], [24, 56], [25, 27], [25, 29], [26, 30], [26, 58], [26, 90], [27, 31], [27, 59], [27, 91], [28, 30], [28, 60], [28, 92], [29, 61], [29, 93], [30, 31], [30, 62], [31, 95], [32, 33], [32, 40], [32, 96], [33, 35], [33, 37], [33, 49], [33, 97], [34, 35], [34, 50], [34, 98], [35, 39], [35, 43], [36, 37], [36, 38], [36, 100], [37, 45], [37, 53], [38, 39], [38, 102], [39, 47], [39, 55], [39, 103], [40, 42], [40, 44], [40, 56], [41, 43], [41, 45], [41, 57], [42, 43], [42, 46], [42, 106], [43, 59], [43, 107], [44, 45], [44, 60], [44, 108], [45, 47], [45, 109], [46, 47], [46, 110], [47, 63], [48, 49], [48, 50], [48, 52], [48, 112], [49, 51], [49, 57], [50, 54], [50, 58], [51, 55], [51, 59], [51, 115], [52, 53], [52, 116], [53, 55], [53, 61], [53, 117], [54, 55], [54, 62], [54, 118], [56, 57], [56, 58], [56, 120], [57, 61], [57, 121], [58, 59], [58, 122], [59, 63], [60, 61], [60, 124], [61, 63], [62, 63], [62, 126], [63, 127], [64, 65], [64, 68], [64, 72], [64, 80], [64, 96], [65, 67], [65, 97], [66, 70], [66, 74], [66, 82], [67, 71], [67, 75], [67, 83], [68, 69], [68, 70], [68, 76], [69, 85], [69, 101], [70, 71], [70, 86], [70, 102], [71, 79], [71, 103], [72, 73], [72, 74], [72, 88], [73, 77], [73, 89], [73, 105], [74, 75], [74, 78], [74, 106], [75, 91], [75, 107], [76, 77], [76, 78], [76, 92], [76, 108], [77, 109], [78, 79], [78, 94], [79, 111], [80, 81], [80, 82], [80, 84], [81, 89], [81, 113], [82, 83], [82, 90], [82, 114], [83, 87], [83, 115], [84, 85], [84, 86], [84, 92], [84, 116], [85, 117], [86, 87], [86, 94], [87, 119], [88, 90], [88, 92], [88, 120], [89, 91], [89, 93], [90, 91], [90, 94], [91, 123], [92, 93], [93, 95], [93, 125], [94, 95], [94, 126], [95, 127], [96, 98], [96, 100], [96, 112], [97, 101], [97, 105], [97, 113], [98, 99], [98, 102], [98, 106], [99, 103], [99, 107], [99, 115], [100, 101], [100, 108], [100, 116], [101, 103], [101, 109], [102, 110], [102, 118], [103, 119], [104, 105], [104, 106], [104, 108], [104, 120], [105, 107], [105, 121], [106, 122], [107, 111], [108, 110], [109, 111], [109, 125], [110, 111], [110, 126], [111, 127], [112, 113], [112, 114], [112, 120], [113, 115], [113, 117], [114, 118], [114, 122], [115, 123], [116, 118], [116, 124], [117, 119], [117, 125], [118, 119], [119, 127], [120, 124], [121, 123], [121, 125], [122, 123], [122, 126], [123, 127], [124, 125], [124, 126]]} | |
+1 −0 samples/reject/duplicate-edge/result.json added View file
| @@ -0,0 +1 @@ | ||
| 1 | +{"n": 2, "edges": [[0, 1], [1, 0]]} | |
+1 −0 samples/reject/four-cycle/result.json added View file
| @@ -0,0 +1 @@ | ||
| 1 | +{"n": 2, "edges": [[0, 1], [0, 2], [1, 3], [2, 3]]} | |
+8 −0 scienceslack.json View file
| @@ -8,6 +8,14 @@ | ||
| 8 | 8 | "also": [ |
| 9 | 9 | "construction" |
| 10 | 10 | ], |
| 11 | + "checks": { | |
| 12 | + "verify": { | |
| 13 | + "path": "checks/verify.sbatch", | |
| 14 | + "method": "C4-free edge-list certificate", | |
| 15 | + "metrics": "metrics.json", | |
| 16 | + "image": "python:3.12-slim" | |
| 17 | + } | |
| 18 | + }, | |
| 11 | 19 | "source": { |
| 12 | 20 | "key": "erdos", |
| 13 | 21 | "name": "Erdős Problems", |