"""Finite basic-Pyramid illustration over GF(17), not a deployed codec.""" import argparse import json from itertools import combinations from pathlib import Path P, K = 17, 8 def lagrange_row(x): row = [] for j in range(K): v = 1 for m in range(K): if m != j: v = v * (x - m) * pow(j - m, -1, P) % P row.append(v) return row def generators(): original = [lagrange_row(x) for x in range(11)] parity = original[8] split = original[:8] + [ [v if j < 4 else 0 for j, v in enumerate(parity)], [v if j >= 4 else 0 for j, v in enumerate(parity)], ] + original[9:] return original, split def rank(rows): a = [[v % P for v in row] for row in rows] r = 0 for c in range(K): pivot = next((i for i in range(r, len(a)) if a[i][c]), None) if pivot is None: continue a[r], a[pivot] = a[pivot], a[r] inv = pow(a[r][c], -1, P) a[r] = [v * inv % P for v in a[r]] for i in range(r + 1, len(a)): factor = a[i][c] a[i] = [(v - factor * w) % P for v, w in zip(a[i], a[r])] r += 1 if r == len(a): break return r def encode(matrix, data): if len(data) != K or any(type(x) is not int or not 0 <= x < P for x in data): raise ValueError("Expected eight integer GF(17) elements in [0,16]") return [sum(a * b for a, b in zip(row, data)) % P for row in matrix] def summarize(matrix, losses): counts = {} for erased in combinations(range(len(matrix)), losses): r = rank([row for i, row in enumerate(matrix) if i not in erased]) counts[str(r)] = counts.get(str(r), 0) + 1 return {"losses": losses, "total": sum(counts.values()), "recoverable": counts.get(str(K), 0), "ranks": counts} def results(): original, split = generators() # A degree-seven polynomial vanishing on the surviving evaluation points. # Losing d0..d3 leaves local parity and two global parities for four unknowns. erased = [0, 1, 2, 3] roots = [4, 5, 6, 7, 8, 9, 10] witness = [] for x in range(K): value = 1 for root in roots: value = value * (x - root) % P witness.append(value) return { "schemaVersion": 1, "kind": "constructed finite-field example", "field": {"prime": P, "operations": "integer arithmetic modulo 17, not XOR"}, "assumptions": ["Known erasure locations", "Correct survivors from one codeword", "One field symbol per fragment", "No device or latency measurement"], "original": {"n": 11, "k": K, "matrix": original, "erasureCounts": [summarize(original, r) for r in range(5)]}, "pyramid": {"n": 12, "k": K, "coordinates": ["d"+str(i) for i in range(8)] + ["local0", "local1", "global0", "global1"], "matrix": split, "erasureCounts": [summarize(split, r) for r in range(5)], "singleDataRepairHelpers": 4, "affectedParitySymbolsPerDataChange": 3}, "ambiguity": {"erased": erased, "zeroPayload": [0]*K, "differentPayload": witness, "differentCodeword": encode(split, witness), "survivorRank": rank([r for i, r in enumerate(split) if i not in erased])}, "limits": [ "Counts describe these explicit coefficients, not every basic Pyramid code.", "Uniform pattern fractions are not field failure probabilities.", "No generalized Pyramid code or maximal-recoverability claim.", "This is not a numerical reproduction of either paper's recovery table." ] } def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--check", action="store_true") args = parser.parse_args() encoded = json.dumps(results(), indent=2) + "\n" target = Path(__file__).with_name("results.json") if args.check: if target.read_text() != encoded: raise SystemExit("Generated results differ") print("Pyramid results match") else: target.write_text(encoded) if __name__ == "__main__": main()