diff --git a/research/masked-e8-puncture-threshold/CERTIFICATE.json b/research/masked-e8-puncture-threshold/CERTIFICATE.json new file mode 100644 index 0000000000..2347191923 --- /dev/null +++ b/research/masked-e8-puncture-threshold/CERTIFICATE.json @@ -0,0 +1,132 @@ +{ + "census": { + "counts_by_rank": [ + 1, + 63, + 1281, + 10395, + 33411, + 36435, + 8821 + ], + "maximum_proper_flat": 36, + "rank6_flats": 8821, + "rank6_size_histogram": { + "10": 5040, + "13": 2016, + "16": 1008, + "21": 666, + "30": 63, + "36": 28 + }, + "rank6_supports_sha256": "33b3b5d35229e378c2e68c47a8e09cb0d9dce06484902b8b161abb288d0b3863" + }, + "first_failure_deletions": 27, + "geometry_sha256": "499909f15616b21ed34b704054685a0c90c244fb81819ba458e076b8dd97308c", + "no_new_kappa": true, + "prime": 65537, + "rank_certificate": "Integer root minors have absolute value at most 4096 by squared row norm eight and Hadamard; 65537 exceeds this bound.", + "rigid_through_deletions": 26, + "schema_version": 1, + "status": "PASS_MASKED_E8_PUNCTURE_THRESHOLD", + "symmetry": { + "checked_root_images": 14400, + "reflections": 120, + "target_orbit": 120 + }, + "witness": { + "bad_neighbourhood_lines": 37, + "bad_neighbourhood_rank": 7, + "comparator_copy_ranks": [ + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9 + ], + "copy_ranks": [ + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9 + ], + "deleted_indices": [ + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 58, + 59, + 60, + 61, + 62, + 63, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 106 + ], + "diagonal_mutation_controls": 1, + "first_residual_three": { + "residual": 3, + "source_doubled_root": [ + 2, + 0, + 2, + 0, + 0, + 0, + 0, + 0 + ], + "source_index": 118 + }, + "live_ports": 93, + "live_rank": 8, + "masked_error_entries": 0, + "matrix_entries_checked": 8649, + "normal": [ + 1, + -1, + 2, + 0, + 0, + 0, + 0, + 0 + ], + "single_restoration_controls": 27, + "target_doubled_root": [ + 2, + 2, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "target_index": 119, + "unmasked_error_entries": 56 + } +} diff --git a/research/masked-e8-puncture-threshold/INDEPENDENT.json b/research/masked-e8-puncture-threshold/INDEPENDENT.json new file mode 100644 index 0000000000..10fd165332 --- /dev/null +++ b/research/masked-e8-puncture-threshold/INDEPENDENT.json @@ -0,0 +1,222 @@ +{ + "checker": "independent fundamental-normal Weyl orbits", + "e7": { + "completeness_premise": "standard conjugacy of maximal root-spanned flats to parabolic flats", + "flat_count": 8821, + "flat_sizes": { + "10": 5040, + "13": 2016, + "16": 1008, + "21": 666, + "30": 63, + "36": 28 + }, + "max_flat_size": 36, + "method": "seven rational fundamental-normal Weyl orbits; Bareiss ranks", + "normal_incidence_transcript_sha256": "aa2a1dcf02346931e8f1d6df074c6b41df94ef23907d9cc7c0d8d0baeda1e422", + "orbits": [ + { + "flat_size": 16, + "normal_count": 1008, + "seed": [ + 3, + -3, + 1, + 1, + 1, + 1, + 1, + -1 + ] + }, + { + "flat_size": 21, + "normal_count": 288, + "seed": [ + 2, + -2, + 1, + 1, + 1, + 1, + 1, + 1 + ] + }, + { + "flat_size": 10, + "normal_count": 5040, + "seed": [ + 2, + -2, + 1, + 1, + 1, + 1, + 0, + 0 + ] + }, + { + "flat_size": 13, + "normal_count": 2016, + "seed": [ + 3, + -3, + 2, + 2, + 2, + 0, + 0, + 0 + ] + }, + { + "flat_size": 21, + "normal_count": 378, + "seed": [ + 1, + -1, + 1, + 1, + 0, + 0, + 0, + 0 + ] + }, + { + "flat_size": 36, + "normal_count": 28, + "seed": [ + 1, + -1, + 2, + 0, + 0, + 0, + 0, + 0 + ] + }, + { + "flat_size": 30, + "normal_count": 63, + "seed": [ + 1, + -1, + 0, + 0, + 0, + 0, + 0, + 0 + ] + } + ], + "rank6_supports_sha256": "33b3b5d35229e378c2e68c47a8e09cb0d9dce06484902b8b161abb288d0b3863" + }, + "e8_target_orbit_size": 120, + "first_failure_deletions": 27, + "rigidity_through_deletions": 26, + "root_order": "lexicographically sorted sign-positive doubled E8 roots", + "schema_version": 1, + "scope": "finite geometry and explicit masked identity; no supplier or moment improvement", + "witness": { + "all_pairs_failures": 56, + "bad_neighborhood_rank": 7, + "bad_neighborhood_size": 37, + "baseline_copy_ranks": [ + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9 + ], + "copy_rank_total": 72, + "deleted_indices": [ + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 58, + 59, + 60, + 61, + 62, + 63, + 64, + 65, + 66, + 67, + 68, + 69, + 70, + 71, + 72, + 73, + 106 + ], + "entrywise_checks_per_identity": 8649, + "first_unmasked_failure": [ + 30, + 119, + -6 + ], + "live_count": 93, + "live_rank": 8, + "masked_copy_ranks": [ + 9, + 9, + 9, + 9, + 9, + 9, + 9, + 9 + ], + "masked_entries": 4521, + "masked_failures": 0, + "normal": [ + 1, + -1, + 2, + 0, + 0, + 0, + 0, + 0 + ], + "other_controls": [ + "diagonal mutation rejected", + "omitted affine label changes rank" + ], + "restoration_controls": 27, + "target": [ + 2, + 2, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "target_index": 119, + "twice_residual_census": { + "-2": 27, + "-6": 1, + "2": 27, + "6": 1 + } + } +} diff --git a/research/masked-e8-puncture-threshold/README.md b/research/masked-e8-puncture-threshold/README.md new file mode 100644 index 0000000000..e7f35d8fb1 --- /dev/null +++ b/research/masked-e8-puncture-threshold/README.md @@ -0,0 +1,186 @@ +# Sharp arbitrary-puncture boundary for one-sided E8 masked rigidity + +**Scoped boundary theorem and exact counterexample; no new kappa.** +Deleting at most **26 arbitrary E8 root lines** leaves this implication intact: +if one factor is root-linear, exactness on the even-inner-product mask forces +exactness on every pair. At **27 deletions**, an eight-term counterexample exists. +The term count is unrestricted in the implication; the other factor need not be +root-linear. Coefficients may be rational, real or complex, with ordinary transpose. + +The new delta over [PR1191](https://github.com/CrocSwap/integer-mult-bounds/pull/1191) +is a sharp deletion-cardinality boundary and the first explicit one-sided +mask-only example. PR1191 supplies the local spanning mechanism and its +orthogonal-set deletion extension; those are predecessor results. This package +does not claim that every small-deletion case is outside that extension. +The general rank-eight rigidity work on particular punctures, including +PR1212/1399/1469/1474/1568, permits both factors outside the root space and has +a different hypothesis. It is not superseded by this result. + +## Model and exact local criterion + +Let `L` be any live subset of the 120 E8 root lines, `R` its matrix of +norm-squared-two root representatives, and `G = R R^T`. Put + +`N(j) = {j} union {i in L : r_i dot r_j = 0}`. + +The mask specifies `(D T^T)_ij = 2 G_ij` for every `i in N(j)`: diagonals +and orthogonal pairs. Odd pairs are unspecified. The affine binary label +pairing used for the copied-rank diagnostic is `(G_ij + 1) mod 2`. + +If `R` has rank eight, the following statements are equivalent: + +1. Every `N(j)` spans eight dimensions. +2. For every finite term count `m` and all `D,T` of size `|L| x m`, if + `col(D)` is contained in `col(R)` and the masked equations hold, then + `D T^T = 2G` on all pairs. + +The same implication holds when only `T` is root-linear, by transposition. +Necessity in this criterion uses an explicit **eight-term** counterexample; +it does not assert existence for every separately fixed smaller term count. + +**Proof.** Write `D = R A`. For each target `j`, masked exactness says +`r_i dot (A t_j - 2 r_j) = 0` for every `i in N(j)`. If those roots span +eight dimensions, their rational nonzero minor remains invertible over the +reals and complexes, so `A t_j = 2 r_j`. This proves every column of the +all-pairs identity. This is PR1191's one-sided argument. + +Conversely, if one `N(j)` has deficient rank, choose a nonzero rational +vector `v` annihilating its rows. Since `R` has rank eight, some live root +does not annihilate `v`. Take `D=R`, start with `T=2R`, and change only +row `j` of `T` to `2r_j+v`. Every masked equation remains exact, while at +least one unmasked entry changes. This proves necessity. + +## Why the threshold is 27 + +Each E8 root has 63 orthogonal root lines, forming an E7 section of rank +seven. Every proper root flat of that section contains at most **36** lines. +This is the established PR595/897 finite census; the primary checker here +reconstructs its completeness without importing either predecessor executable. + +After at most 26 deletions, at least 37 orthogonal lines remain at every live +target. They cannot lie in a proper flat, so they span the target's full +seven-dimensional perpendicular space. The retained target itself supplies +the eighth dimension. The local criterion applies, and also proves that the +live roots have global rank eight. + +For completeness, every proper subspace's root set extends to a rank-six +root-generated flat: repeatedly add roots outside its span until rank six. +The primary checker enumerates all such flats by closed extensions from the +empty flat. At a parent `F`, the nonzero root directions in the quotient by +`span(F)` are grouped projectively. Each group is precisely the root set added +by one closed rank-one extension; every root-generated child has such a +parent. Induction therefore proves complete coverage. + +The exact rank-0 through rank-6 counts are +`1, 63, 1281, 10395, 33411, 36435, 8821`. The rank-six size histogram is: + +| Lines in flat | Number of flats | +|---:|---:| +| 10 | 5040 | +| 13 | 2016 | +| 16 | 1008 | +| 21 | 666 | +| 30 | 63 | +| 36 | 28 | + +Primary elimination uses the prime 65537. Doubled roots are integer vectors +of squared norm eight; Hadamard bounds every square minor of order at most +eight by 4096. Reduction cannot turn a nonzero root minor into zero at that +prime. Thus all root-subset ranks and closure memberships agree with rational +arithmetic. This certified finite-field step is a rational rank certificate, +not an uncertified modular nomination. + +Explicit root reflections permute all 120 lines and take the chosen target +to every line. Their formula preserves the ordinary inner product, so the +one-target census applies to every target. The separate checker derives +seven rational fundamental normals from an independently constructed E7 +simple system and enumerates their Weyl orbits, checking every flat's rank +with fraction-free integer elimination. Its orbit-completeness premise is +the standard root-flat/parabolic conjugacy statement; the primary method +provides separate finite completeness. Both entire flat-support sets agree +by a canonical digest, beyond agreement on their histograms. + +## The exact first-failure example + +Use doubled roots `q=2r`, lexicographically sorted with first nonzero entry +positive. Choose + +`q_target = (2,2,0,0,0,0,0,0)` and `v = (1,-1,2,0,0,0,0,0)`. + +Delete exactly the orthogonal lines with `q_i dot v != 0`. There are 27. +The 93 live roots have rank eight, but the target has only 36 surviving +orthogonal roots plus itself, a neighborhood of rank seven. Set `D=R`, +`T=2R`, then add `v` to the target row of `T`. + +Both implementations check all **8649** entries; **4521** are masked. +There are zero masked errors and exactly **56** unmasked errors, all in +the target column. At live root `(2,0,2,0,0,0,0,0)`, the product differs +from `2G` by **3**. Restoring any one of the 27 deleted roots makes the +neighborhood rank eight and rejects this same witness at 26 deletions. +Changing the perturbation to the target root fails on its diagonal. + +The complete separate-term copied-rank diagnostic is **eight ranks of nine, +total 72**, for both this example and its coordinate comparator. For +`0 0 + + +def primitive(vector): + divisor = reduce(math.gcd, vector) + require(divisor != 0, "zero projective normal") + answer = tuple(value // divisor for value in vector) + return answer if positive(answer) else tuple(-value for value in answer) + + +def root_line(vector): + return vector if positive(vector) else tuple(-value for value in vector) + + +def e8_lines(): + roots = [] + for a, b in itertools.combinations(range(8), 2): + for sa, sb in itertools.product((-1, 1), repeat=2): + vector = [0] * 8 + vector[a], vector[b] = 2 * sa, 2 * sb + roots.append(tuple(vector)) + roots.extend(signs for signs in itertools.product((-1, 1), repeat=8) + if signs.count(-1) % 2 == 0) + require(len(roots) == len(set(roots)) == 240, "E8 roots are not 240 distinct vectors") + lines = sorted({root_line(root) for root in roots}) + require(len(lines) == 120, "E8 line count differs from 120") + require(all(dot(root, root) == 8 for root in roots), "incorrect doubled-root norm") + return roots, lines + + +def simple_roots(roots): + positive_roots = {root for root in roots if positive(root)} + return sorted(root for root in positive_roots + if not any(tuple(a - b for a, b in zip(root, other)) in positive_roots + for other in positive_roots)) + + +def solve_rational(matrix, rhs): + rows = [[Fraction(value) for value in row] + [Fraction(value)] + for row, value in zip(matrix, rhs)] + order = len(rows) + require(all(len(row) == order + 1 for row in rows), "nonsquare rational system") + for column in range(order): + pivot = next((row for row in range(column, order) if rows[row][column]), None) + require(pivot is not None, "singular fundamental-normal system") + rows[column], rows[pivot] = rows[pivot], rows[column] + scale = rows[column][column] + rows[column] = [value / scale for value in rows[column]] + for row in range(order): + if row != column: + multiplier = rows[row][column] + rows[row] = [left - multiplier * right + for left, right in zip(rows[row], rows[column])] + return [row[-1] for row in rows] + + +def integer_rank(matrix): + """Rectangular Bareiss elimination; no modular or floating rank inference.""" + if not matrix: + return 0 + rows = [list(row) for row in matrix] + width = len(rows[0]) + require(all(len(row) == width for row in rows), "ragged rank matrix") + rank, previous = 0, 1 + for column in range(width): + pivot_row = next((row for row in range(rank, len(rows)) if rows[row][column]), None) + if pivot_row is None: + continue + rows[rank], rows[pivot_row] = rows[pivot_row], rows[rank] + pivot = rows[rank][column] + for row in range(rank + 1, len(rows)): + multiplier = rows[row][column] + for later in range(column + 1, width): + numerator = pivot * rows[row][later] - multiplier * rows[rank][later] + require(numerator % previous == 0, "Bareiss division is not exact") + rows[row][later] = numerator // previous + rows[row][column] = 0 + previous = pivot + rank += 1 + if rank == len(rows): + break + return rank + + +def root_reflection(root, simple): + numerator = dot(root, simple) + require(numerator % 4 == 0, "nonintegral root reflection") + return tuple(value - numerator // 4 * coefficient + for value, coefficient in zip(root, simple)) + + +def normal_reflection(normal, simple): + # Four times the reflected vector avoids rational intermediate values. + scalar = dot(normal, simple) + return primitive(tuple(4 * value - scalar * coefficient + for value, coefficient in zip(normal, simple))) + + +def root_transitivity(roots, lines, target): + simples = simple_roots(roots) + require(len(simples) == 8 and integer_rank(simples) == 8, "incorrect E8 simple system") + line_set = set(lines) + for simple in simples: + image = {root_line(root_reflection(root, simple)) for root in lines} + require(image == line_set, "E8 simple reflection does not permute all lines") + seen, queue = {target}, deque([target]) + while queue: + root = queue.popleft() + for simple in simples: + image = root_line(root_reflection(root, simple)) + if image not in seen: + seen.add(image) + queue.append(image) + require(seen == line_set, "target Weyl orbit does not cover all 120 lines") + return len(seen) + + +def flat_census(roots, lines, target): + orthogonal_roots = [root for root in roots if dot(root, target) == 0] + orthogonal_lines = [root for root in lines if dot(root, target) == 0] + require(len(orthogonal_roots) == 126 and len(orthogonal_lines) == 63, "incorrect E7 section") + simples = simple_roots(orthogonal_roots) + require(len(simples) == 7 and integer_rank(simples) == 7, "incorrect E7 simple system") + for simple in simples: + require({root_line(root_reflection(root, simple)) for root in orthogonal_lines} + == set(orthogonal_lines), "E7 reflection does not preserve its lines") + gram = [[dot(left, right) for right in simples] for left in simples] + require(all(gram[i][i] == 8 and all(gram[i][j] in (-4, 0) for j in range(7) if j != i) + for i in range(7)), "E7 simple roots have an invalid Cartan form") + for root in orthogonal_lines: + coefficients = solve_rational(gram, [dot(root, simple) for simple in simples]) + require(all(value.denominator == 1 and value >= 0 for value in coefficients), + "positive E7 root lacks nonnegative integer simple coordinates") + require(tuple(sum(coefficients[j] * simples[j][axis] for j in range(7)) + for axis in range(8)) == root, "simple coordinates do not reconstruct the root") + all_normals, all_masks, histogram, orbits = set(), set(), Counter(), [] + transcript = hashlib.sha256() + for coordinate in range(7): + coefficients = solve_rational(gram, [4 * (j == coordinate) for j in range(7)]) + rational_normal = [sum(coefficients[j] * simples[j][axis] for j in range(7)) + for axis in range(8)] + denominator = math.lcm(*(value.denominator for value in rational_normal)) + seed = primitive(tuple(int(value * denominator) for value in rational_normal)) + require(dot(seed, target) == 0, "fundamental normal leaves the E7 space") + seen, queue = {seed}, deque([seed]) + while queue: + normal = queue.popleft() + for simple in simples: + image = normal_reflection(normal, simple) + if image not in seen: + seen.add(image) + queue.append(image) + require(not (seen & all_normals), "two fundamental-normal orbits overlap") + orbit_sizes = Counter() + for normal in sorted(seen): + require(dot(normal, target) == 0, "orbit normal leaves the E7 space") + mask = sum(1 << j for j, root in enumerate(orthogonal_lines) if dot(root, normal) == 0) + flat = [root for j, root in enumerate(orthogonal_lines) if (mask >> j) & 1] + require(integer_rank(flat) == 6, "normal does not define a rank-six E7 root flat") + require(mask not in all_masks, "two projective normals define the same rank-six flat") + all_masks.add(mask) + orbit_sizes[len(flat)] += 1 + transcript.update((str(normal) + ":" + str(mask) + "\n").encode("ascii")) + require(len(orbit_sizes) == 1, "flat cardinality changes inside a Weyl orbit") + histogram.update(orbit_sizes) + all_normals.update(seen) + orbits.append({"seed": list(seed), "normal_count": len(seen), + "flat_size": next(iter(orbit_sizes))}) + expected = {10: 5040, 13: 2016, 16: 1008, 21: 666, 30: 63, 36: 28} + require(dict(histogram) == expected and len(all_masks) == 8821, + "E7 flat census differs from the exact predecessor census") + supports = sorted(tuple(i for i in range(63) if (mask >> i) & 1) for mask in all_masks) + supports_digest = hashlib.sha256(json.dumps(supports, sort_keys=True, + separators=(",", ":")).encode()).hexdigest() + return {"method": "seven rational fundamental-normal Weyl orbits; Bareiss ranks", + "completeness_premise": "standard conjugacy of maximal root-spanned flats to parabolic flats", + "flat_count": len(all_masks), "flat_sizes": {str(k): v for k, v in sorted(histogram.items())}, + "max_flat_size": max(histogram), "orbits": orbits, + "rank6_supports_sha256": supports_digest, + "normal_incidence_transcript_sha256": transcript.hexdigest()} + + +def binary_rank(rows): + # Least-significant-bit pivots differ from the primary high-pivot implementation. + basis = {} + for row in rows: + while row: + pivot = row & -row + if pivot in basis: + row ^= basis[pivot] + else: + basis[pivot] = row + break + return len(basis) + + +def pairing(left, right): + numerator = dot(left, right) + require(numerator % 4 == 0, "root Gram entry is not integral") + return (1 + numerator // 4) % 2 + + +def copy_cost(lines, live, target_index, normal, perturb): + costs = [] + for coordinate in range(8): + row_support = [i for i in live if lines[i][coordinate] != 0] + column_support = [i for i in live if lines[i][coordinate] + + (normal[coordinate] if perturb and i == target_index else 0) != 0] + rows = [sum(pairing(lines[i], lines[j]) << k for k, j in enumerate(column_support)) + for i in row_support] + costs.append(binary_rank(rows)) + return costs + + +def identity_counts(lines, live, target_index, normal): + """D=Z/2 and T=Z+e_target normal^T; compare twice DT^T to Z Z^T.""" + masked_failures, all_failures, masked_entries = [], [], 0 + for i in live: + for j in live: + source = tuple(value + (normal[k] if j == target_index else 0) + for k, value in enumerate(lines[j])) + residual_twice = dot(lines[i], source) - dot(lines[i], lines[j]) + is_masked = pairing(lines[i], lines[j]) == 1 + masked_entries += is_masked + if residual_twice != 0: + all_failures.append((i, j, residual_twice)) + if is_masked: + masked_failures.append((i, j, residual_twice)) + return masked_entries, masked_failures, all_failures + + +def witness_check(lines): + target = (2, 2, 0, 0, 0, 0, 0, 0) + normal = (1, -1, 2, 0, 0, 0, 0, 0) + target_index = lines.index(target) + deleted = [i for i, root in enumerate(lines) + if dot(root, target) == 0 and dot(root, normal) != 0] + live = [i for i in range(120) if i not in deleted] + neighborhood = [i for i in live if pairing(lines[i], target)] + require(len(deleted) == 27 and len(live) == 93 and target_index in live, "invalid puncture witness") + require(integer_rank([lines[i] for i in live]) == 8, "live witness loses global rank") + require(len(neighborhood) == 37 and integer_rank([lines[i] for i in neighborhood]) == 7, + "bad target neighborhood is not rank seven") + require(dot(target, normal) == 0 and all(dot(lines[i], normal) == 0 for i in neighborhood), + "perturbation does not annihilate the masked neighborhood") + _, baseline_mask, baseline_all = identity_counts(lines, live, target_index, (0,) * 8) + require(not baseline_mask and not baseline_all, "baseline is not all-pairs exact") + masked_entries, mask_failures, all_failures = identity_counts(lines, live, target_index, normal) + require(not mask_failures and len(all_failures) == 56, "sharp witness does not separate the identities") + require(all(j == target_index for _, j, _ in all_failures), "witness changes an unintended target") + residual_census = Counter(residual for _, _, residual in all_failures) + require(dict(residual_census) == {-6: 1, -2: 27, 2: 27, 6: 1}, "incorrect exact witness residuals") + baseline_cost = copy_cost(lines, live, target_index, normal, False) + masked_cost = copy_cost(lines, live, target_index, normal, True) + require(baseline_cost == masked_cost == [9] * 8, "incorrect witness copy-rank invoice") + + # All 27 ways to undo one deletion must restore local rigidity and reject this witness. + for restored in deleted: + restored_live = sorted(live + [restored]) + restored_neighborhood = [i for i in restored_live if pairing(lines[i], target)] + require(integer_rank([lines[i] for i in restored_neighborhood]) == 8, + "a 26-puncture restoration fails to recover neighborhood rank eight") + _, failures, _ = identity_counts(lines, restored_live, target_index, normal) + require(failures, "restoring a deleted root failed to reject the mask-only witness") + + # Diagonal inclusion is essential: alpha itself is orthogonal to every off-diagonal E-neighbor. + _, diagonal_failures, _ = identity_counts(lines, live, target_index, target) + require(diagonal_failures and all(i == j == target_index for i, j, _ in diagonal_failures), + "diagonal corruption was not detected at exactly the target diagonal") + require(pairing(target, target) == 1, "mask omits the diagonal") + full_pairing = [sum(pairing(left, right) << j for j, right in enumerate(lines)) for left in lines] + without_affine = [sum((dot(left, right) // 4 % 2) << j for j, right in enumerate(lines)) + for left in lines] + require(binary_rank(full_pairing) == 9 and binary_rank(without_affine) == 8, + "affine-label negative control does not distinguish the two pairings") + nonzero = next((i, j, value) for i, j, value in all_failures) + return {"target": list(target), "target_index": target_index, "normal": list(normal), + "deleted_indices": deleted, "live_count": len(live), "live_rank": 8, + "bad_neighborhood_size": len(neighborhood), "bad_neighborhood_rank": 7, + "entrywise_checks_per_identity": len(live) ** 2, "masked_entries": masked_entries, + "masked_failures": 0, "all_pairs_failures": len(all_failures), + "twice_residual_census": {str(k): v for k, v in sorted(residual_census.items())}, + "first_unmasked_failure": list(nonzero), + "baseline_copy_ranks": baseline_cost, "masked_copy_ranks": masked_cost, + "copy_rank_total": sum(masked_cost), "restoration_controls": len(deleted), + "other_controls": ["diagonal mutation rejected", "omitted affine label changes rank"]} + + +def build_receipt(): + roots, lines = e8_lines() + target = (2, 2, 0, 0, 0, 0, 0, 0) + transitivity = root_transitivity(roots, lines, target) + census = flat_census(roots, lines, target) + witness = witness_check(lines) + require(63 - census["max_flat_size"] == 27, "minimum deletion threshold differs from 27") + return {"schema_version": 1, "checker": "independent fundamental-normal Weyl orbits", + "root_order": "lexicographically sorted sign-positive doubled E8 roots", + "e8_target_orbit_size": transitivity, "e7": census, + "rigidity_through_deletions": 26, "first_failure_deletions": 27, + "witness": witness, + "scope": "finite geometry and explicit masked identity; no supplier or moment improvement"} + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--check", type=Path, help="compare every receipt field against this JSON") + parser.add_argument("--write", type=Path, help="write a new receipt; existing files are not overwritten") + args = parser.parse_args() + try: + here = Path(__file__).resolve().parent + pins = json.loads((here / "SOURCES.json").read_text()) + for name, expected in {**pins["implementation_sha256"], **pins["receipt_sha256"]}.items(): + require(hashlib.sha256((here / name).read_bytes()).hexdigest() == expected, + "package source/receipt drift: " + name) + if args.write: + require(not args.write.exists(), "refusing to overwrite an existing receipt") + receipt = build_receipt() + check_path = args.check or (HERE / "INDEPENDENT.json" if not args.write else None) + if check_path: + require(json.loads(check_path.read_text()) == receipt, "independent receipt differs") + if args.write: + with args.write.open("x") as stream: + json.dump(receipt, stream, indent=2, sort_keys=True) + stream.write("\n") + except (Failure, OSError, ValueError) as error: + parser.exit(1, "FAIL_MASKED_E8_PUNCTURE_THRESHOLD_INDEPENDENT: " + str(error) + "\n") + print("PASS_MASKED_E8_PUNCTURE_THRESHOLD_INDEPENDENT " + "flats=8821 max_flat=36 targets=120 threshold=27 " + "witness_entries=8649 changed=56 copy_rank=72 restoration_controls=27 other_controls=2") + + +if __name__ == "__main__": + main() diff --git a/research/masked-e8-puncture-threshold/test_package.py b/research/masked-e8-puncture-threshold/test_package.py new file mode 100644 index 0000000000..133a2ee037 --- /dev/null +++ b/research/masked-e8-puncture-threshold/test_package.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Bounded on-disk rejection and relocation controls for the research package.""" +import hashlib +import json +from pathlib import Path +import shutil +import subprocess +import sys +import tempfile +import unittest + +HERE = Path(__file__).resolve().parent + + +def invoke(directory, script, *args): + return subprocess.run([sys.executable, "-I", "-O", "-B", str(directory / script), *map(str, args)], + cwd=directory.parent, capture_output=True, text=True, timeout=600) + + +class PackageControls(unittest.TestCase): + def copy(self, temporary): + directory = Path(temporary) / "minimal source with spaces" + shutil.copytree(HERE, directory) + return directory + + def test_complete_support_sets_agree(self): + primary = json.loads((HERE / "CERTIFICATE.json").read_text()) + independent = json.loads((HERE / "INDEPENDENT.json").read_text()) + self.assertEqual(primary["census"]["rank6_supports_sha256"], + independent["e7"]["rank6_supports_sha256"]) + self.assertEqual(primary["witness"]["deleted_indices"], independent["witness"]["deleted_indices"]) + + def test_primary_and_independent_reject_corrupted_receipts(self): + for script, receipt in (("verify.py", "CERTIFICATE.json"), ("independent.py", "INDEPENDENT.json")): + with self.subTest(script=script), tempfile.TemporaryDirectory() as temporary: + directory = self.copy(temporary) + path = directory / receipt + value = json.loads(path.read_text()) + value["first_failure_deletions"] = 26 + path.write_text(json.dumps(value)) + before = path.read_bytes() + result = invoke(directory, script) + self.assertNotEqual(result.returncode, 0) + self.assertIn("source/receipt drift", result.stderr) + self.assertEqual(path.read_bytes(), before) + + def test_primary_and_independent_reject_source_drift(self): + for script in ("verify.py", "independent.py"): + with self.subTest(script=script), tempfile.TemporaryDirectory() as temporary: + directory = self.copy(temporary) + with (directory / script).open("a") as out: + out.write("\n# deliberate changed implementation control\n") + result = invoke(directory, script) + self.assertNotEqual(result.returncode, 0) + self.assertIn("source/receipt drift", result.stderr) + + def test_custom_independent_receipt_rejects_false_geometry(self): + with tempfile.TemporaryDirectory() as temporary: + path = Path(temporary) / "false-result.json" + value = json.loads((HERE / "INDEPENDENT.json").read_text()) + value["e7"]["max_flat_size"] = 37 + path.write_text(json.dumps(value)) + result = invoke(HERE, "independent.py", "--check", path) + self.assertNotEqual(result.returncode, 0) + self.assertIn("independent receipt differs", result.stderr) + + def test_no_overwrite(self): + for script in ("verify.py", "independent.py"): + with self.subTest(script=script), tempfile.TemporaryDirectory() as temporary: + path = Path(temporary) / "retained.json" + path.write_bytes(b"retained evidence\n") + result = invoke(HERE, script, "--write", path) + self.assertNotEqual(result.returncode, 0) + self.assertIn("overwrite", result.stderr) + self.assertEqual(path.read_bytes(), b"retained evidence\n") + + def test_minimal_relocated_read_only_replay(self): + with tempfile.TemporaryDirectory() as temporary: + directory = self.copy(temporary) + before = {f.name: hashlib.sha256(f.read_bytes()).hexdigest() + for f in directory.iterdir() if f.is_file()} + for script in ("verify.py", "independent.py"): + result = invoke(directory, script) + self.assertEqual(result.returncode, 0, result.stdout + result.stderr) + after = {f.name: hashlib.sha256(f.read_bytes()).hexdigest() + for f in directory.iterdir() if f.is_file()} + self.assertEqual(after, before) + + +if __name__ == "__main__": + unittest.main() diff --git a/research/masked-e8-puncture-threshold/verify.py b/research/masked-e8-puncture-threshold/verify.py new file mode 100644 index 0000000000..533713f461 --- /dev/null +++ b/research/masked-e8-puncture-threshold/verify.py @@ -0,0 +1,263 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: Apache-2.0 +"""Closed-flat census and sharp one-sided E8 mask boundary. + +New implementation for @ToikY with substantial OpenAI Codex assistance. +No predecessor executable is imported; checks remain active under -O. +""" +import argparse +from collections import Counter, deque +from fractions import Fraction +import hashlib +import itertools +import json +from pathlib import Path + +HERE = Path(__file__).resolve().parent +P = 65537 +TARGET = (2, 2, 0, 0, 0, 0, 0, 0) +NORMAL = (1, -1, 2, 0, 0, 0, 0, 0) + + +def need(ok, message): + if not ok: + raise ValueError(message) + + +def digest(obj): + return hashlib.sha256(json.dumps(obj, sort_keys=True, separators=(",", ":")).encode()).hexdigest() + + +def dot(a, b): + return sum(x * y for x, y in zip(a, b)) + + +def line(v): + return tuple(v) if next(x for x in v if x) > 0 else tuple(-x for x in v) + + +def roots(): + out = set() + for a, b in itertools.combinations(range(8), 2): + for s in (-1, 1): + v = [0] * 8 + v[a], v[b] = 2, 2 * s + out.add(tuple(v)) + for v in itertools.product((-1, 1), repeat=8): + if sum(x < 0 for x in v) % 2 == 0: + out.add(line(v)) + return sorted(out) + + +def reduce(v, basis): + v = [x % P for x in v] + for pivot, row in basis: + c = v[pivot] + if c: + v = [(x - c * y) % P for x, y in zip(v, row)] + return tuple(v) + + +def normalize(v): + pivot = next((i for i, x in enumerate(v) if x), None) + if pivot is None: + return None + c = pow(v[pivot], -1, P) + return pivot, tuple(x * c % P for x in v) + + +def extend(basis, residual): + p, row = residual + old = [(j, tuple((x - r[p] * y) % P for x, y in zip(r, row))) for j, r in basis] + return tuple(sorted([*old, (p, row)])) + + +def rank(rows): + basis = () + for row in rows: + residual = normalize(reduce(row, basis)) + if residual is not None: + basis = extend(basis, residual) + return len(basis) + + +def rational_rank(rows): + m = [[Fraction(x) for x in row] for row in rows] + p = 0 + for col in range(8): + found = next((i for i in range(p, len(m)) if m[i][col]), None) + if found is None: + continue + m[p], m[found] = m[found], m[p] + c = m[p][col] + m[p] = [x / c for x in m[p]] + for i in range(p + 1, len(m)): + c = m[i][col] + if c: + m[i] = [x - c * y for x, y in zip(m[i], m[p])] + p += 1 + return p + + +def census(e7): + # Every quotient direction gives one closed extension; induction from + # the empty flat establishes coverage of every root-generated flat. + level, counts = {0: ()}, [1] + for dim in range(1, 7): + following = {} + for mask, basis in level.items(): + groups = {} + for i, root in enumerate(e7): + if mask >> i & 1: + continue + residual = normalize(reduce(root, basis)) + need(residual is not None, "parent closure omitted a root") + groups[residual] = groups.get(residual, 0) | (1 << i) + for residual, extra in groups.items(): + child = mask | extra + if child not in following: + following[child] = extend(basis, residual) + level = following + counts.append(len(level)) + print(f"CENSUS rank={dim} flats={len(level)}", flush=True) + need(counts == [1, 63, 1281, 10395, 33411, 36435, 8821], "flat coverage mismatch") + hist = dict(sorted(Counter(m.bit_count() for m in level).items())) + need(hist == {10: 5040, 13: 2016, 16: 1008, 21: 666, 30: 63, 36: 28}, "E7 histogram mismatch") + flats = sorted(tuple(i for i in range(63) if mask >> i & 1) for mask in level) + return {"counts_by_rank": counts, "rank6_size_histogram": hist, + "rank6_flats": len(flats), "rank6_supports_sha256": digest(flats), + "maximum_proper_flat": max(hist)} + + +def symmetry(lines): + index = {r: i for i, r in enumerate(lines)} + permutations = [] + for a in lines: + image = [] + for r in lines: + d = dot(r, a) + need(d % 4 == 0, "reflection not integral") + v = line(tuple(x - (d // 4) * y for x, y in zip(r, a))) + need(v in index, "reflection leaves root lines") + image.append(index[v]) + need(len(set(image)) == 120, "reflection not bijective") + permutations.append(image) + reached = {index[TARGET]} + todo = deque(reached) + while todo: + for image in permutations: + i = image[todo[0]] + if i not in reached: + reached.add(i) + todo.append(i) + todo.popleft() + need(len(reached) == 120, "target orbit incomplete") + return {"reflections": 120, "checked_root_images": 14400, "target_orbit": 120} + + +def f2_rank(rows): + basis = {} + for v in rows: + while v: + p = v.bit_length() - 1 + if p in basis: + v ^= basis[p] + else: + basis[p] = v + break + return len(basis) + + +def copy_cost(lines, live, source): + costs = [] + for k in range(8): + left = [i for i in live if lines[i][k]] + right = [j for j in live if source[j][k]] + costs.append(f2_rank([sum(((dot(lines[i], lines[j]) // 4 + 1) & 1) << h + for h, j in enumerate(right)) for i in left])) + return costs + + +def errors(lines, live, source): + # Twice the residual for D_i=q_i/2 and T_j=source_j. + out = [] + for i in live: + for j in live: + d = dot(lines[i], source[j]) - dot(lines[i], lines[j]) + if d: + out.append((i, j, d, (dot(lines[i], lines[j]) // 4) % 2 == 0)) + return out + + +def witness(lines): + t = lines.index(TARGET) + deleted = [i for i, r in enumerate(lines) if dot(r, TARGET) == 0 and dot(r, NORMAL)] + live = [i for i in range(120) if i not in deleted] + ns = [i for i in live if i == t or dot(lines[i], TARGET) == 0] + need(len(deleted) == 27 and len(live) == 93, "wrong puncture") + need(rank([lines[i] for i in live]) == rational_rank([lines[i] for i in live]) == 8, "live rank not eight") + need(len(ns) == 37 and rank([lines[i] for i in ns]) == rational_rank([lines[i] for i in ns]) == 7, "wrong deficient neighbourhood") + need(all(dot(lines[i], NORMAL) == 0 for i in ns), "normal fails on neighbour") + original = {i: lines[i] for i in live} + source = dict(original) + source[t] = tuple(x + y for x, y in zip(TARGET, NORMAL)) + need(not errors(lines, live, original), "coordinate control failed") + wrong = errors(lines, live, source) + need(len(wrong) == 56 and all(not e[3] and e[1] == t for e in wrong), "not masked exact") + first = next((e for e in wrong if e[2] == 6), None) + need(first is not None, "missing explicit residual three") + costs = copy_cost(lines, live, source) + need(costs == copy_cost(lines, live, original) == [9] * 8, "COPY diagnostic mismatch") + for restored in deleted: + ls = sorted([*live, restored]) + src = {**source, restored: lines[restored]} + need(any(e[3] for e in errors(lines, ls, src)), "26-deletion control did not reject") + need(rank([lines[i] for i in ls if i == t or dot(lines[i], TARGET) == 0]) == 8, "restored span not eight") + bad = dict(original) + bad[t] = tuple(2 * x for x in TARGET) + need(any(e[3] for e in errors(lines, live, bad)), "diagonal mutation not rejected") + return {"target_index": t, "target_doubled_root": TARGET, "normal": NORMAL, + "deleted_indices": deleted, "live_ports": 93, "live_rank": 8, + "bad_neighbourhood_lines": 37, "bad_neighbourhood_rank": 7, + "matrix_entries_checked": 8649, "unmasked_error_entries": 56, + "masked_error_entries": 0, "first_residual_three": {"source_index": first[0], "source_doubled_root": lines[first[0]], "residual": 3}, + "copy_ranks": costs, "comparator_copy_ranks": costs, + "single_restoration_controls": 27, "diagonal_mutation_controls": 1} + + +def run(): + lines = roots() + need(len(lines) == 120 and all(dot(r, r) == 8 for r in lines), "invalid E8") + need(all(dot(a, b) % 4 == 0 for a in lines for b in lines), "invalid Gram") + e7 = [r for r in lines if dot(r, TARGET) == 0] + need(len(e7) == 63 and rank(e7) == 7, "invalid E7") + return {"schema_version": 1, "status": "PASS_MASKED_E8_PUNCTURE_THRESHOLD", + "geometry_sha256": digest(lines), "prime": P, + "rank_certificate": "Integer root minors have absolute value at most 4096 by squared row norm eight and Hadamard; 65537 exceeds this bound.", + "census": census(e7), "symmetry": symmetry(lines), "witness": witness(lines), + "rigid_through_deletions": 26, "first_failure_deletions": 27, + "no_new_kappa": True} + + +def main(): + ap = argparse.ArgumentParser(description=__doc__) + ap.add_argument("--write", type=Path, help="create a fresh receipt; never overwrite") + args = ap.parse_args() + pins = json.loads((HERE / "SOURCES.json").read_text()) + for name, expected in {**pins["implementation_sha256"], **pins["receipt_sha256"]}.items(): + need(hashlib.sha256((HERE / name).read_bytes()).hexdigest() == expected, + "package source/receipt drift: " + name) + if args.write: + need(not args.write.exists(), "refusing to overwrite an existing receipt") + result = run() + if args.write: + with args.write.open("x") as out: + json.dump(result, out, indent=2, sort_keys=True) + out.write("\n") + else: + need(json.loads((HERE / "CERTIFICATE.json").read_text()) == json.loads(json.dumps(result)), "certificate differs from exact replay") + print("PASS_MASKED_E8_PUNCTURE_THRESHOLD rigid=26 first_failure=27 flats=8821 witness_entries=8649 copy=72 no_new_kappa") + + +if __name__ == "__main__": + main()