"""Exact fixed-code GF(7) repair minima. Python standard library only. Run minimum.py --write to generate minimum-results.json, or --check to verify it. Importing this module performs no searches and writes no files. """ import argparse import itertools import json from pathlib import Path FIELD = 7 DIRECTIONS = [(1, x) for x in range(7)] + [(0, 1)] SUBSPACES = [()] + [(pair,) for pair in DIRECTIONS] + [((1, 0), (0, 1))] COSTS = tuple(map(len, SUBSPACES)) SCOPE = ( "Fixed Hulett/Wootters Figure 4 code. Noninteractive GF(7)-linear repair " "from four selected available helpers, without symbol extension. " "Not a nonlinear optimum, outage probability, latency or physical-I/O result." ) def encode(message): a, b, c, d, e, f = message return [ (a, d), (b, e), (c, f), ((a + 4*b + 3*c) % 7, (a + d + 4*e + 3*f) % 7), ((3*a + 6*b + 6*c) % 7, (c + 3*d + 6*e + 6*f) % 7), ((6*a + 6*b + 3*c) % 7, (6*d + 6*e + 3*f) % 7), ] BASIS = [tuple(int(i == j) for j in range(6)) for i in range(6)] NODE_ROWS = [ [tuple(encode(v)[node][coordinate] for v in BASIS) for coordinate in range(2)] for node in range(6) ] def kernel(matrix): rows = [list(row) for row in matrix] pivots = [] for column in range(6): chosen = next((i for i in range(len(pivots), len(rows)) if rows[i][column]), None) if chosen is None: continue target = len(pivots) rows[chosen], rows[target] = rows[target], rows[chosen] inverse = pow(rows[target][column], -1, FIELD) rows[target] = [(x * inverse) % FIELD for x in rows[target]] for i in range(len(rows)): if i != target: factor = rows[i][column] rows[i] = [(x - factor*y) % FIELD for x, y in zip(rows[i], rows[target])] pivots.append(column) vectors = [] for free in range(6): if free in pivots: continue vector = [0] * 6 vector[free] = 1 for i, pivot in enumerate(pivots): vector[pivot] = -rows[i][free] % FIELD vectors.append(tuple(vector)) return vectors def row(helper, pair): return tuple((pair[0]*a + pair[1]*b) % FIELD for a, b in zip(*NODE_ROWS[helper])) TRANSFORMS = [ [tuple(row(helper, pair) for pair in space) for space in SUBSPACES] for helper in range(6) ] def repairs(failed, matrix): return all(encode(v)[failed] == (0, 0) for v in kernel(matrix)) def helper_cases(): for failed in range(6): survivors = [n for n in range(6) if n != failed] for omitted in survivors: yield failed, [n for n in survivors if n != omitted] def schedule_rows(helpers, states): return [vector for helper, state in zip(helpers, states) for vector in TRANSFORMS[helper][state]] def verify_witness(case): failed, helpers = case["failed"], case["helpers"] if type(failed) is not int or failed not in range(6): raise ValueError("Invalid failed node") if (not isinstance(helpers, list) or len(helpers) != 4 or any(type(h) is not int or h not in range(6) for h in helpers) or helpers != sorted(set(helpers)) or failed in helpers): raise ValueError("Four sorted distinct surviving helpers required") states = case["witnessStates"] if (not isinstance(states, list) or len(states) != 4 or any(type(s) is not int or s not in range(10) for s in states)): raise ValueError("Invalid helper subspaces") symbols = case["minimumSymbols"] if type(symbols) is not int or symbols != sum(COSTS[s] for s in states): raise ValueError("Witness cost mismatch") if not repairs(failed, schedule_rows(helpers, states)): raise ValueError("Witness cannot recover the lost node") def validate_witness_inventory(report): expected = {(f, tuple(h)) for f, h in helper_cases()} cases = report["cases"] if len(cases) != 30: raise ValueError("Expected 30 cases") for case in cases: verify_witness(case) actual = {(c["failed"], tuple(c["helpers"])) for c in cases} if actual != expected: raise ValueError("Missing or duplicate case") # This verifies upper-bound certificates only; --check also reruns the # exhaustive lower-bound search and compares every field of the report. def results(): states = [s for s in itertools.product(range(10), repeat=4) if sum(COSTS[i] for i in s) <= 4] if len(states) != 7435: raise RuntimeError("Unexpected subspace inventory") cases = [] for failed, helpers in helper_cases(): counts = [0] * 5 witness = None for choice in states: if repairs(failed, schedule_rows(helpers, choice)): counts[sum(COSTS[i] for i in choice)] += 1 if witness is None: witness = choice if any(counts[:4]): raise RuntimeError("Unexpected repair below four symbols") minimum = 4 if witness is None: minimum = 5 for full in range(4): for singles in itertools.product(range(1, 9), repeat=3): choice = list(singles) choice.insert(full, 9) if repairs(failed, schedule_rows(helpers, choice)): witness = choice break if witness is not None: break if witness is None: raise RuntimeError("No five-symbol upper bound found") cases.append({ "failed": failed, "helpers": helpers, "testedSubspaces": len(states), "successfulBySymbolCount": counts, "minimumSymbols": minimum, "witnessStates": list(witness), }) report = { "schemaVersion": 1, "field": FIELD, "nodes": 6, "recoveryThreshold": 3, "symbolsPerNode": 2, "helperCount": 4, "source": "https://arxiv.org/abs/1707.02337v1", "sourceLocator": "Figure 4, PDF page 16; sections 2.2 and 6.1.", "scope": SCOPE, "stateCoefficients": [[list(pair) for pair in space] for space in SUBSPACES], "testedSubspaces": len(states) * len(cases), "minimumFourCases": sum(c["minimumSymbols"] == 4 for c in cases), "minimumFiveCases": sum(c["minimumSymbols"] == 5 for c in cases), "cases": cases, } validate_witness_inventory(report) return report def main(): parser = argparse.ArgumentParser(description=__doc__) mode = parser.add_mutually_exclusive_group(required=True) mode.add_argument("--write", action="store_true") mode.add_argument("--check", action="store_true") args = parser.parse_args() report = results() path = Path(__file__).with_name("minimum-results.json") if args.write: path.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8") elif json.loads(path.read_text(encoding="utf-8")) != report: raise SystemExit("Published minimum report differs from exhaustive computation") print(json.dumps({key: report[key] for key in ["testedSubspaces", "minimumFourCases", "minimumFiveCases"]})) if __name__ == "__main__": main()