"""Exact finite controls for classical composition before final substitution. Seberry--Yamada (1990), Corollary 25, pp.116--117: amicable sign quadruples of orders u,v give an amicable sign quadruple of order 2uv. The all-parameter existence proof is mathematical; these are bounded replays. """ from __future__ import annotations import argparse import hashlib import json from pathlib import Path import numpy as np PRIMARY = 'https://documents.uow.edu.au/~jennie/WEBPDF/139_1990.pdf' def require(value, message): if not value: raise ValueError(message) def checked_quadruple(values): raw = np.asarray(values) require(raw.ndim == 3 and raw.shape[0] == 4 and raw.shape[1] == raw.shape[2] and raw.shape[1] > 0, 'four nonempty square source matrices required') require(np.issubdtype(raw.dtype, np.integer) and not np.issubdtype(raw.dtype, np.bool_), 'source entries must be exact integers') require(np.all((raw == 1) | (raw == -1)), 'source entries must be signs') matrices = raw.astype(np.int64) width = matrices.shape[1] require(np.array_equal(sum(a @ a.T for a in matrices), 4 * width * np.eye(width, dtype=np.int64)), 'summed source Gram identity failed') for i, a in enumerate(matrices): for b in matrices[:i]: require(np.array_equal(a @ b.T, b @ a.T), 'source amicability failed') return matrices def compose(left, right, maximum_order=2048): require(type(maximum_order) is int and maximum_order > 0, 'maximum source order must be a positive integer') raw = [np.asarray(value) for value in (left, right)] for value in raw: require(value.ndim == 3 and value.shape[0] == 4 and value.shape[1] == value.shape[2] and value.shape[1] > 0, 'four nonempty square source matrices required') width = 2 * raw[0].shape[1] * raw[1].shape[1] require(width <= maximum_order, 'dense source replay budget exceeded') a, b = (checked_quadruple(value) for value in raw) A, B, C, D = a E, F, G, H = (A+B)//2, (A-B)//2, (C+D)//2, (C-D)//2 eye = np.eye(2, dtype=np.int64) swap = np.array([[0, 1], [1, 0]], dtype=np.int64) T1, T2, T3, T4 = (np.kron(eye, E), np.kron(eye, F), np.kron(swap, G), np.kron(swap, H)) X, Y, Z, W = b k = np.kron result = np.array([ k(T1,X)+k(T2,Y)+k(T3,Z)+k(T4,W), -k(T1,Y)+k(T2,X)+k(T3,W)-k(T4,Z), -k(T1,Z)-k(T2,W)+k(T3,X)+k(T4,Y), -k(T1,W)+k(T2,Z)-k(T3,Y)+k(T4,X), ], dtype=np.int64) checked_quadruple(result) if all(np.array_equal(x, x.T) for x in (*a, *b)): require(all(np.array_equal(x, x.T) for x in result), 'symmetric source composition failed') return result def starter(q): from search.code import williamson_spence_family as original from search.code import additional_spence_families as additional require(type(q) is int, 'starter parameter must be an integer') if q in original.PARAMETERS: rows = original.starter(q)[0] else: require(q in additional.PARAMETERS, 'parameter is outside the retained finite starters') rows = additional.starter(q)[0] return checked_quadruple([original.circulant(row) for row in rows]) def controls(left_q=5, right_q=13): left, right = starter(left_q), starter(right_q) result = compose(left, right) require(all(np.array_equal(x, x.T) for x in (*left, *right, *result)), 'retained control inputs or output are not symmetric') width = result.shape[1] t = 631 source_first = 4 * t * width after_endpoints = (4 * t * left.shape[1]) * (4 * t * right.shape[1]) // 2 require(after_endpoints == t * source_first, 'source-first order comparison failed') return { 'schema': 'structured-source-product-control-v1', 'source_url': PRIMARY, 'source_location': 'Corollary25, printedpp116-117', 'implementation_sha256': hashlib.sha256(Path(__file__).read_bytes()).hexdigest(), 'input_q': [left_q, right_q], 'input_widths': [int(left.shape[1]), int(right.shape[1])], 'output_width': int(width), 'all_sign_entries_checked': True, 'all_six_amicability_identities_checked': True, 'full_summed_integer_Gram_checked': True, 'symmetric_output_checked': True, 'output_int8_sha256': hashlib.sha256(result.astype(np.int8).tobytes()).hexdigest(), 'literal_output_matrices_pm': [[''.join('+' if x == 1 else '-' for x in row) for row in matrix] for matrix in result], 'conditional_fixed_T631_endpoint_order': int(source_first), 'product_after_individual_endpoints_order': int(after_endpoints), 'endpoint_order_improvement_factor': t, 'scope': 'Finite exact source composition; endpoint follows from the separately verified fixed design and substitution. No dense endpoint, individually new order or new multiplication theorem is claimed.', } def mixed_product_controls(): """Check actual input choices, including the classical alternative baseline.""" from math import prod from theory.code.existence_product_closure import ( count_enumeration, exponent_catalogue, proof_tree, verify_certificate, ) t = 631 records = [] for leaves in (3, 4, 12): inputs = [7572] + [12] * (leaves - 1) exponents, plans = exponent_catalogue(leaves) tree = proof_tree(leaves, plans) target = 2 ** exponents[leaves] * prod(n // 4 for n in inputs) verify_certificate(tree, inputs, target) ordinary_baseline = 2 ** count_enumeration(leaves + 1)['exponent'] * t * 3 ** leaves all_scaled = target * t ** (leaves - 1) require(ordinary_baseline in (target, 2 * target), 'classical baseline comparison failed') records.append({ 'source_parameters_q': [5] * leaves, 'source_stages_r': [0] * leaves, 'input_orders': inputs, 'input_existence': 'H7572 is the retained completed endpoint; H12 is the exact WT3 source array.', 'mixed_product_order': target, 'product_tree': tree, 'all_T_scaled_inputs_order': all_scaled, 'order_if_using_known_H2524_plus_all_plain_inputs': ordinary_baseline, 'improvement_factor_over_that_classical_expression': ordinary_baseline // target, 'comparison_scope': 'Specified input expressions only; another construction may already give this order.', }) return records def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--output', type=Path) args = parser.parse_args() report = controls() report['mixed_endpoint_product_controls'] = mixed_product_controls() if args.output: args.output.write_text(json.dumps(report, indent=2) + '\n') else: print(json.dumps({k:v for k,v in report.items() if k != 'literal_output_matrices_pm'}, indent=2)) if __name__ == '__main__': main()