"""Exact formal closure of Hadamard existence under specified classical rules. Input leaves certify H(4*a_i). Output H(2**E*product(a_i)). E is minimal only among trees built from the 2-, 4-, and 12-input rules listed here. No matrix, source witness, global order novelty, or new theorem is claimed. """ from __future__ import annotations import argparse,json from math import prod RULES={2:3,4:4,12:9} def exponent_catalogue(limit=64,rules=RULES): if type(limit)is not int or not 1<=limit<=256:raise ValueError('limit must be1..256') exponents={1:2};plans={1:None} for n in range(2,limit+1): best=None for arity,output_exponent in sorted(rules.items()): if n=1) return c def prime_power(q): if type(q)is not int or q<2:return None p=2 while p*p<=q and q%p:p+=1 if p*p>q:return(q,1) remaining=q;power=0 while remaining%p==0:remaining//=p;power+=1 return(p,power)if remaining==1 else None def specialize_uniform(q_values,r_values): if len(q_values)!=len(r_values)or not q_values:raise ValueError('paired nonempty parameters required') for q,r in zip(q_values,r_values): if q%4!=1 or not prime_power(q)or type(r)is not int or r<0:raise ValueError('q=1mod4 prime powers and r>=0 required') orders=[1262*(q+1)*q**r for q,r in zip(q_values,r_values)] e,plans=exponent_catalogue(len(orders));tree=proof_tree(len(orders),plans) target=2**e[len(orders)]*prod(order//4 for order in orders) verify_certificate(tree,orders,target) provenance=dict( status='Previously established all-parameter mathematical construction theorem; not proved by the generic arithmetic checker.', formula='H(1262*(q+1)*q^r), q=1mod4 a prime power, r>=0', proof_paths=['search/docs/EXTENDED_SPENCE_FAMILIES.md','search/docs/SPENCE_SCALAR_FAMILIES.md'], retained_source_record='certificates/scalar-lift/extended-spence-families-20261128.json', components='Turyn strong starters, Spence recurrence and the verified T631 orthogonal design', matrix_entry_replay_performed_here=False,new_Lean_claim=False) hypotheses=[dict(order=order,q=q,r=r,existence_source='retained uniform T631/Spence theorem')for order,q,r in zip(orders,q_values,r_values)] return dict(parameters=[dict(q=q,r=r,prime_power=prime_power(q))for q,r in zip(q_values,r_values)], input_orders=orders,input_existence_hypotheses=hypotheses, input_source_theorem_provenance=provenance, conclusion_status='Existence follows from the retained uniform source theorem and the cited classical product rules; no new source matrix is asserted.', target_order=target,power_of_two=e[len(orders)],tree=tree) def tamper_controls(): from copy import deepcopy orders=[4,12,28,52];e,p=exponent_catalogue(4);tree=proof_tree(4,p) target=16*prod(n//4 for n in orders);verify_certificate(tree,orders,target) cases=[] tests=[] bad=deepcopy(tree);bad['children'][1]=deepcopy(bad['children'][0]);tests.append(('duplicate_input',bad,orders,target)) bad=deepcopy(tree);bad['rule']='product_2';tests.append(('wrong_rule_label',bad,orders,target)) bad=deepcopy(tree);bad['arity']=12;tests.append(('wrong_arity',bad,orders,target)) bad=deepcopy(tree);bad['children'][0]['input_index']=True;tests.append(('boolean_input_index',bad,orders,target)) tests.append(('wrong_target',tree,orders,target*2));tests.append(('invalid_input_order',tree,[4,12,28,51],target)) for label,t,inputs,value in tests: try:verify_certificate(t,inputs,value) except (ValueError,KeyError,IndexError):cases.append(dict(tamper=label,rejected=True)) else:raise AssertionError('tamper accepted: '+label) return cases def report(limit=64): e,p=exponent_catalogue(limit) controls=[] for n in range(1,limit+1): values=[4*(1+(17*i)%29)for i in range(n)] actual,leaves=verify_tree(proof_tree(n,p),values) assert sorted(leaves)==list(range(n)) assert actual==2**e[n]*prod(value//4 for value in values) controls.append(dict(leaves=n,exponent=e[n],arithmetic_tree_verified=True, input_existence_assumed_not_verified_here=True)) # Twelve improves a closure that includes the binary and four-input rules. old,_=exponent_catalogue(limit,{2:3,4:4}) if limit>=12:assert e[12]==9 and old[12]==10 recurrence=caterpillar_exponents(limit) independent=[dict(leaves=n,**count_enumeration(n))for n in range(1,limit+1)] for entry in independent: assert e[entry['leaves']]==entry['exponent']==2+recurrence[entry['leaves']] return dict(schema='scoped-Hadamard-existence-product-closure-v1', scope='Formal existence certificates only. Minimal exponent within the declared product-tree rules; no global optimality or matrix/order novelty claim.', input_existence_hypotheses=dict(generic_rule='For each i, assume a real Hadamard matrix H(input_orders[i]) has separately been established.', generic_checker_scope='Rule arithmetic, positive multiples of four and exact once-only leaf usage; no input matrix-existence verification.', uniform_specializations='Input existence is supplied by the separately retained all-parameter T631/Spence theorem, whose provenance accompanies every specialization.'), rules=[dict(inputs=k,each_input_order='4*a_i',output_order=f'2^{v} * product(a_i)',output_power_of_two=v)for k,v in RULES.items()], source_urls=['https://ajc.maths.uq.edu.au/pdf/7/ocr-ajc-v7-p123.pdf'], exponents={str(n):e[n]for n in range(1,limit+1)}, exponent_with_only_binary_and_four_input={str(n):old[n]for n in range(1,limit+1)}, proof_trees={str(n):proof_tree(n,p)for n in[4,12]if n<=limit}, numeric_tree_controls=controls, independent_rule_count_enumeration=independent, caterpillar_recurrence='c(1)=0; c(r)=min(1+c(r-1),2+c(r-3),7+c(r-11)), omitting invalid indices; E(r)=2+c(r)', tamper_rejection_controls=tamper_controls(), uniform_numeric_specializations=[specialize_uniform([5,13,17,25],[0,1,0,2]),specialize_uniform([5]*12,[0]*12)], uniform_source_substitution=dict(input_order='1262*(q_i+1)*q_i^r_i',hypotheses='q_i odd prime powers congruent1mod4; r_i>=0', general_output='2^(E(s)-s) * 631^s * product((q_i+1)*q_i^r_i)', integrality='Each q_i+1 is even, so the rational-looking prefactor always gives the integer2^E(s)*product(631*(q_i+1)/2*q_i^r_i).', four_input_output='631^4 * product_{i=1}^4((q_i+1)*q_i^r_i)', twelve_input_output='631^12/8 * product_{i=1}^12((q_i+1)*q_i^r_i)', status='Classical-product corollaries of the existing uniform source theorem, not additional counted new families.'), all_checks_passed=True) if __name__=='__main__': ap=argparse.ArgumentParser(description=__doc__);ap.add_argument('--limit',type=int,default=64);ap.add_argument('--output');a=ap.parse_args() result=report(a.limit);text=json.dumps(result,indent=2)+'\n' if a.output:open(a.output,'w').write(text) print(json.dumps(dict(all_checks_passed=True,limit=a.limit,E12=result['exponents'].get('12'),E64=result['exponents'].get('64'))))