"""Concrete smaller-source rectangular branches toward BH(1499,120). Known restricted sources of orders567,585 and729 provide actual boundaries. Root-valued corner and simultaneous cross-row completion are still open. """ from __future__ import annotations import argparse import hashlib import json from functools import cache from math import gcd from pathlib import Path import numpy as np from search.code.fifth_source_assembly import exact_column_gram, root_vectors from hadamard.coefficients import CyclotomicField ROOT = Path(__file__).resolve().parents[2] CYCLE = np.array([[0, 1, -1], [-1, 0, 1], [1, -1, 0]], dtype=np.int64) def branch_parameters(source_order, input_order): n, d = int(source_order), int(input_order) if n != source_order or d != input_order or (n - d) % 2: raise ValueError("the source and input orders must have the same parity") s, delta = (n - d) // 2, n - 2 * d if not 0 < s <= d or delta <= 0: raise ValueError("the rectangular branch requires positive metric and at most d selected rows") return {"source_order": n, "input_order": d, "selected_rows": s, "omitted_rows": d - s, "selected_metric_norm": delta, "complement_metric_norm": n, "phase": 120, "known_input_constructor_available": d in (567, 585, 729), "known_input_route": ({567: "restricted BH7 followed by four exact triplings", 585: "restricted BH13 followed by two triplings, tensor the admitted fifth-root chirp", 729: "restricted BH3 followed by five exact triplings"}.get(d)), "characteristic_zero_source_constructed": False} def _components(source): source = np.asarray(source, dtype=np.int64) % 6 if np.any(source % 3 == 0): raise ValueError("the saved input seed must use only unreal sixth roots") a = np.array([0, 1, -1, 0, -1, 1], dtype=np.int64)[source] b = np.array([0, 1, 1, 0, -1, -1], dtype=np.int64)[source] return a, b def _triple(source): a, b = _components(source) aa = np.kron(b, np.ones((3, 3), dtype=np.int64)) bb = np.kron(a, np.eye(3, dtype=np.int64)) + np.kron(b, CYCLE) return np.array([[4, 2], [5, 1]], dtype=np.int64)[(aa + 1) // 2, (bb + 1) // 2] @cache def _sixth_source(input_order): seed_order, repetitions = {117: (13, 2), 567: (7, 4), 729: (3, 5)}[int(input_order)] if seed_order == 13: from search.code.inverse_blocks import known_order_thirteen_source source = np.asarray(known_order_thirteen_source(), dtype=np.int64) else: data = json.loads((ROOT / "certificates/scalar-lift/large-joint-targets.json").read_text()) source = np.asarray(next(row["exponents"] for row in data["verified_sources"] if row["order"] == seed_order), dtype=np.int64) _components(source) for _ in range(repetitions): source = _triple(source) if source.shape != (input_order, input_order): raise ValueError("the smaller-source tripling order is wrong") return source @cache def known_source(input_order): """Actual complete BH(d,120), with raw admitted cubic/fifth colors.""" if int(input_order) == 585: cubic = (20 * _sixth_source(117) + 80) % 120 fifth = _fifth_chirp() source = (cubic[:, None, :, None] + fifth[None, :, None, :]).reshape(585, 585) % 120 else: source = (20 * _sixth_source(int(input_order)) + 104) % 120 if np.any(source % 3 == 2) or np.any(source % 5 == 0): raise ValueError("the constructed smaller source left the permitted alphabet") return source def _fifth_chirp(): return np.array([[24 * ((3 * (i + j) ** 2 + 1) % 5) for j in range(5)] for i in range(5)], dtype=np.int64) @cache def _verify_sixth_gram(input_order): source = _sixth_source(int(input_order)) a, b = _components(source) aw = [sum(1 << j for j, value in enumerate(row) if value == 1) for row in a] bw = [sum(1 << j for j, value in enumerate(row) if value == 1) for row in b] n = len(source) for i in range(n): for j in range(i): aa, bb = n - 2 * (aw[i] ^ aw[j]).bit_count(), n - 2 * (bw[i] ^ bw[j]).bit_count() ab, ba = n - 2 * (aw[i] ^ bw[j]).bit_count(), n - 2 * (bw[i] ^ aw[j]).bit_count() if aa + 3 * bb or ab != ba: raise ValueError("an exact smaller-source Gram entry failed") return {"order": n, "all_row_pairs_checked": n * (n - 1) // 2, "exact_unreal_component_Gram_verified": True} @cache def source_certificate(input_order): if int(input_order) == 585: factor = _verify_sixth_gram(117) fifth = _fifth_chirp() gram = exact_column_gram(fifth, 120) expected = np.zeros_like(gram) expected[np.arange(5), np.arange(5), 0] = 5 if not np.array_equal(gram, expected): raise ValueError("the fifth-root tensor factor has an incorrect Gram") upper = known_source(input_order) return {"order": 585, "phase": 120, "construction": "BH117 tensor chirped BH5, with independent cubic and fifth colors", "factor117_exact_Gram": factor, "factor5_complete_exact_Gram_verified": True, "complete_585_Gram_verified_by_tensor_identity": True, "all_raw_cubic_fifth_alphabet_entries_verified": True, "cubic_colors": sorted(set((upper % 3).ravel().tolist())), "fifth_colors": sorted(set((4 * upper % 5).ravel().tolist())), "source_exponent_sha256": hashlib.sha256(upper.astype(" s: raise ValueError("the simple unit/zero root-sum row does not fit this branch") x = np.full(s, 24, dtype=np.int64) y = np.r_[np.full(delta, 64, dtype=np.int64), np.full(s - delta, 84, dtype=np.int64)] boundary = problem["T_L"][0] rows = np.array([np.r_[x, y, boundary], np.r_[y, x, boundary]]) roots = root_vectors(120) gram = np.array([[roots[(first - second) % 120].sum(axis=0) for second in rows] for first in rows]) expected = np.zeros_like(gram) expected[0, 0, 0] = expected[1, 1, 0] = 1499 if not np.array_equal(gram, expected) or np.any(rows % 3 == 2) or np.any(rows % 5 == 0): raise ValueError("the actual-length admitted root pair failed its full exact Gram") return {"input_order": input_order, "source_order": 1499, "selected_rows": s, "unit_root_sum_positions": delta, "zero_root_sum_positions": s - delta, "E_row_squared_norm": delta, "F_row_squared_norm": 3 * delta + 4 * (s - delta), "pair_phases": {"unit_sum": [24, 64], "zero_sum": [24, 84]}, "full_two_by_two_Gram_of_length1499_rows_verified": True, "all_entries_in_raw_phase120_lift_alphabet": True, "boundary_input_row_index": problem["selected_row_indices"][0], "two_row_exponent_sha256": hashlib.sha256(rows.astype(" 4 else "OPEN_ROOT_COMPLETION" reason = "E has a nonzero entry with squared modulus delta, but every sum of two unit roots has squared modulus at most4." elif kind == "normalized_small_Butson_blocks": block = int(metric["block_order"]) if parameters["selected_rows"] % block: raise ValueError("the proposed complete blocks do not tile the selected space") if delta > 4 * block: status, reason = "EXCLUDED_ROOT_SUM_ENTRY_BOUND", "Each E entry has squared modulus delta/block_order>4." elif delta % block: status, reason = "EXCLUDED_ROOT_SUM_INTEGRAL_NORM", "The rational squared modulus delta/block_order is not an integer, whereas the squared norm of an integral root sum is an algebraic integer." else: status, reason = "OPEN_ROOT_COMPLETION", "This entrywise gate does not settle the simultaneous corner and root split." elif kind == "dense_integral_root_split": status, reason = "OPEN_ROOT_COMPLETION", "The actual two-row root gate passes; a complete coupled E,F,D remains missing." else: raise ValueError("unsupported finite metric descriptor") return {**parameters, "row_selection_descriptor": dict(selection), "selected_row_indices_sha256": hashlib.sha256(json.dumps(rows).encode()).hexdigest(), "metric_descriptor": metric, "status": status, "reason": reason, "actual_row_subset_selected": True, "source_constructed": False} def initial_catalogue(input_orders=(567, 729)): result = [] selections = [{"kind": "stride", "step": step, "shift": shift} for step, shift in ((1, 0), (1, 1), (2, 7))] for d in input_orders: block_orders = {567: (2,), 585: (), 729: (5, 7, 35)}[d] metrics = [{"kind": "monomial", "root_phase_shift": 0}, {"kind": "nonuniform_spectral_monomial", "phase_slope": 1, "phase_shift": 15}, {"kind": "nonuniform_spectral_monomial", "phase_slope": 7, "phase_shift": 24}, *[{"kind": "normalized_small_Butson_blocks", "block_order": k} for k in block_orders], {"kind": "dense_integral_root_split"}] for selection in selections: for metric in metrics: result.append(branch_prefilter(1499, d, selection, metric)) return result def certificate(input_orders=(567, 729)): catalogue = initial_catalogue(input_orders) return {"schema": "rectangular-smaller-Butson-sources-v1", "source_order": 1499, "phase": 120, "verified_small_metric_inputs": small_metric_inputs(), "branches": [{"parameters": branch_parameters(1499, d), "known_input": source_certificate(d), "metric_norms": metric_certificate(d), "actual_root_pair": root_pair_control(d)} for d in input_orders], "finite_branch_catalogue": catalogue, "finite_branch_count": len(catalogue), "excluded_finite_branches": sum(row["status"].startswith("EXCLUDED") for row in catalogue), "open_dense_completion_branches": sum(row["status"] == "OPEN_ROOT_COMPLETION" for row in catalogue), "new_characteristic_zero_source_or_real_order_constructed": False} def main(): parser = argparse.ArgumentParser(description=__doc__) action = parser.add_mutually_exclusive_group(required=True) action.add_argument("--output", type=Path) action.add_argument("--check", type=Path) parser.add_argument("--input-order", type=int, choices=(567, 585, 729)) args = parser.parse_args() report = certificate((args.input_order,) if args.input_order is not None else (567, 729)) if args.output: args.output.write_text(json.dumps(report, indent=2) + "\n") elif json.loads(args.check.read_text()) != report: raise ValueError("the rectangular smaller-source certificate failed replay") print(json.dumps({key: report[key] for key in ("finite_branch_count", "excluded_finite_branches", "open_dense_completion_branches")})) if __name__ == "__main__": main()