Datasets:
Formats:
json
Languages:
English
Size:
< 1K
ArXiv:
Tags:
mathematics
matroid-theory
hyperfields
lorentzian-polynomials
symbolic-mathematics
reproducibility
Download code/verify_ilyoxune.py from PureOne/Ilyoxune-Sharp-Hyperfield-Aggregation: direct link, hf CLI and curl.
- Browser
- Download file 20.5 kB
-
https://huggingface.co/datasets/PureOne/Ilyoxune-Sharp-Hyperfield-Aggregation/resolve/main/code/verify_ilyoxune.py
- Command line
-
hf download hf://datasets/PureOne/Ilyoxune-Sharp-Hyperfield-Aggregation/code/verify_ilyoxune.py
-
curl -L -o verify_ilyoxune.py https://huggingface.co/datasets/PureOne/Ilyoxune-Sharp-Hyperfield-Aggregation/resolve/main/code/verify_ilyoxune.py
20.5 kB
| #!/usr/bin/env python3 | |
| """Reproduce finite certificates for Ilyoxune. | |
| Exact rational checks and high-precision numerical checks are labelled separately. | |
| The finite checks supplement, and do not prove, the manuscript's universal theorems. | |
| Uses the Python standard library and mpmath (only for labelled numerical checks). | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| from collections import Counter | |
| from fractions import Fraction as F | |
| from itertools import combinations | |
| from math import factorial, isqrt | |
| from pathlib import Path | |
| import json | |
| import random | |
| def frac(x): | |
| x = F(x) | |
| return str(x.numerator) if x.denominator == 1 else f"{x.numerator}/{x.denominator}" | |
| def determinant(rows): | |
| a = [[F(x) for x in row] for row in rows] | |
| n = len(a) | |
| sign = 1 | |
| value = F(1) | |
| for col in range(n): | |
| pivot = next((i for i in range(col,n) if a[i][col]),None) | |
| if pivot is None: | |
| return F(0) | |
| if pivot != col: | |
| a[col],a[pivot] = a[pivot],a[col] | |
| sign = -sign | |
| p = a[col][col] | |
| value *= p | |
| for j in range(col,n): | |
| a[col][j] /= p | |
| for i in range(col+1,n): | |
| t = a[i][col] | |
| for j in range(col,n): | |
| a[i][j] -= t*a[col][j] | |
| return sign*value | |
| def minors(matrix): | |
| d,n = len(matrix),len(matrix[0]) | |
| return {frozenset(S):abs(determinant([[row[j] for j in S] for row in matrix])) | |
| for S in combinations(range(n),d)} | |
| def root_relations(coeff,d,n): | |
| """Every indexed ordinary strong relation (products of root coefficients).""" | |
| for I0 in combinations(range(n),d-1): | |
| I = frozenset(I0) | |
| for J0 in combinations(range(n),d+1): | |
| J = frozenset(J0) | |
| yield I,J,[coeff[I|{j}]*coeff[J-{j}] for j in sorted(J-I)] | |
| def allrank_checks(): | |
| out=[] | |
| for d,n in [(3,6),(3,7),(4,7),(4,8),(5,8),(5,9),(6,9),(6,10)]: | |
| C=set(range(6,d+3)) | |
| U=frozenset(C|{0,2,4}); Z1=frozenset(C|{0,1,5}); Z2=frozenset(C|{2,3,5}) | |
| a={frozenset(S):F(1) for S in combinations(range(n),d)} | |
| a[U]=F(3,2); a[Z1]=a[Z2]=F(1,4) | |
| strict=taut=0; gap_min=None; terms=Counter() | |
| for I,J,t in root_relations(a,d,n): | |
| gap=sum(t)-2*max(t) | |
| terms[len(t)]+=1 | |
| if len(t)==2: | |
| assert gap==0 | |
| taut+=1 | |
| else: | |
| assert gap>0,(d,n,I,J,t) | |
| strict+=1 | |
| gap_min=gap if gap_min is None else min(gap_min,gap) | |
| out.append(dict(rank=d,ground_set_size=n,coefficients=len(a), | |
| strict_relations=strict,tautological_relations=taut, | |
| term_counts=dict(sorted(terms.items())), | |
| minimum_root_polygon_slack=frac(gap_min))) | |
| return out | |
| def sqrt_interval(x,decimal_digits=80): | |
| x=F(x); scale=10**decimal_digits | |
| k=isqrt((x.numerator*scale*scale)//x.denominator) | |
| lo=F(k,scale) | |
| hi=lo if lo*lo==x else F(k+1,scale) | |
| assert lo*lo<=x<=hi*hi | |
| return lo,hi | |
| def cubic_output(coeff): | |
| return {str(i+1)+str(j+1):coeff[frozenset((i,j,4))]+coeff[frozenset((i,j,5))] | |
| for i,j in combinations(range(4),2)} | |
| def exact_small_witnesses(): | |
| a={frozenset(S):F(1) for S in combinations(range(6),3)} | |
| a[frozenset((0,2,4))]=F(199,100) | |
| a[frozenset((0,1,5))]=a[frozenset((2,3,5))]=F(1,4) | |
| c={S:v*(F(1,4) if 5 in S else 1) for S,v in a.items()} | |
| strict=0 | |
| for I,J,t in root_relations(c,3,6): | |
| gap=sum(t)-2*max(t) | |
| assert gap>=0 | |
| if len(t)>2: | |
| assert gap>0;strict+=1 | |
| g=cubic_output(c) | |
| defect=g['13']*g['24']-g['12']*g['34']-g['14']*g['23'] | |
| assert defect==F(139,1280)>0 | |
| q1=dict(q=1,strict_relations=strict,root_peak='199/100',root_low='1/4', | |
| element6_scale='1/4',output_coefficients={k:frac(v) for k,v in g.items()}, | |
| output_relation_defect=frac(defect),arithmetic='exact rational') | |
| c={} | |
| for S0 in combinations(range(6),3): | |
| S=frozenset(S0) | |
| if S==frozenset((0,2,4)):v=4095 | |
| elif S in (frozenset((0,1,5)),frozenset((2,3,5))):v=8 | |
| elif 5 in S:v=64 | |
| else:v=1024 | |
| c[S]=F(v) | |
| certified=0;cert_min=None | |
| for I,J,t in root_relations(c,3,6): | |
| if len(t)==2: | |
| assert t[0]==t[1];continue | |
| k=max(range(len(t)),key=t.__getitem__) | |
| intervals=[sqrt_interval(v) for v in t] | |
| lower=sum(intervals[j][0] for j in range(len(t)) if j!=k)-intervals[k][1] | |
| assert lower>0,(I,J,t) | |
| cert_min=lower if cert_min is None else min(cert_min,lower) | |
| certified+=1 | |
| g=cubic_output(c) | |
| excess=g['13']*g['24']-(g['14']+g['12'])**2 | |
| assert excess==30592 | |
| q2=dict(q=2,strict_relations=certified,coefficient_values=[8,64,1024,4095], | |
| output_coefficients={k:frac(v) for k,v in g.items()}, | |
| exact_squared_output_excess=frac(excess), | |
| input_root_interval_decimal_digits=80, | |
| certified_minimum_input_slack_lower_bound=frac(cert_min), | |
| arithmetic='exact rational intervals; integer squared output certificate') | |
| return [q1,q2] | |
| def exact_matrix_obstructions(): | |
| # Four unmerged columns supply the sharp p>=q restriction in rank two. | |
| R=[[1,0,1,1,0,0],[0,1,1,-1,0,0]] | |
| m=minors(R) | |
| t=[m[frozenset((0,1))]*m[frozenset((2,3))], | |
| m[frozenset((0,2))]*m[frozenset((1,3))], | |
| m[frozenset((0,3))]*m[frozenset((1,2))]] | |
| assert sorted(t)==[1,1,2] | |
| # Two pairs of parallel columns give rho_zz*rho_12=2 and two unit products. | |
| P=[[1,0,0,0,1,0],[0,1,0,0,0,1]] | |
| mP=minors(P) | |
| bi=mP[frozenset((0,4))]+mP[frozenset((0,5))] | |
| bj=mP[frozenset((1,4))]+mP[frozenset((1,5))] | |
| assert (2*mP[frozenset((4,5))]*mP[frozenset((0,1))],bi*bj)==(2,1) | |
| diamond=[[1,0,-1,0,1,0],[0,1,0,-1,0,1],[1,1,1,1,0,0]] | |
| square=[[0,1,1,0,1,0],[0,0,1,1,0,1],[1,1,1,1,0,0]] | |
| md=minors(diamond); ms=minors(square) | |
| # A merged coefficient is represented by the pair of determinant magnitudes. | |
| pairs=lambda mm:{str(i+1)+str(j+1):[frac(mm[frozenset((i,j,4))]),frac(mm[frozenset((i,j,5))])] | |
| for i,j in combinations(range(4),2)} | |
| pd,ps=pairs(md),pairs(ms) | |
| assert pd['13']==['0','2'] and pd['24']==['2','0'] | |
| assert all(pd[k]==['1','1'] for k in ['12','14','23','34']) | |
| assert ps['13']==['1','1'] and ps['24']==['1','1'] | |
| assert all(sum(F(v) for v in ps[k])==1 for k in ['12','14','23','34']) | |
| return dict(arithmetic='exact integer determinants', | |
| rank2_q_bound=dict(matrix=R,unpowered_quartet_products=[frac(x) for x in t], | |
| necessary_condition='p >= q'), | |
| rank2_one_bound=dict(matrix=P,normalized_repeated_z_products=['2','1','1'], | |
| necessary_condition='p >= 1'), | |
| rank3_diamond=dict(matrix=diamond,merged_determinant_pairs=pd, | |
| powered_output_products=['4','4^q','4'], | |
| necessary_condition='p >= 2(q-1) when q>1'), | |
| rank3_square=dict(matrix=square,merged_determinant_pairs=ps, | |
| powered_output_products=['1','4','1'], | |
| necessary_condition='p >= 2')) | |
| def capped_indices(caps,total): | |
| if not caps: | |
| if total==0:yield () | |
| return | |
| for v in range(min(caps[0],total)+1): | |
| for tail in capped_indices(caps[1:],total-v): | |
| yield (v,)+tail | |
| def merge_normalized(coeff,n): | |
| # Merge the final two variables. Store all exponents in the output's n-1 variables. | |
| raw={} | |
| for S,v in coeff.items(): | |
| beta=[0]*(n-1) | |
| for j in S:beta[min(j,n-2)]+=1 | |
| key=tuple(beta);raw[key]=raw.get(key,0)+v | |
| return {b:v*factorial(b[-1]) for b,v in raw.items()} | |
| def quartet_relations(rho,d,n): | |
| """All non-tautological polarized weak relations, with bounded multiplicities. | |
| n is the INPUT number of variables; output caps are (1,...,1,2). | |
| Repeated z copies are allowed, explaining the factorial normalization. | |
| """ | |
| caps=(1,)*(n-2)+(2,) | |
| for alpha in capped_indices(caps,d-2): | |
| remaining=tuple(c-a for c,a in zip(caps,alpha)) | |
| for beta in capped_indices(remaining,4): | |
| quartet=[i for i,b in enumerate(beta) for _ in range(b)] | |
| i,j,k,l=quartet | |
| pairings=(((i,j),(k,l)),((i,k),(j,l)),((i,l),(j,k))) | |
| products=[] | |
| for ab,cd in pairings: | |
| b=list(alpha);c=list(alpha) | |
| for v in ab:b[v]+=1 | |
| for v in cd:c[v]+=1 | |
| products.append(rho.get(tuple(b),0)*rho.get(tuple(c),0)) | |
| yield alpha,tuple(beta),products | |
| class FormalPolynomial(dict): | |
| """Tiny commutative polynomial ring over Q for exact expansion checks.""" | |
| def __add__(self,other): | |
| if other==0:return self | |
| out=FormalPolynomial(self) | |
| for k,v in other.items():out[k]=out.get(k,F(0))+v | |
| return FormalPolynomial({k:v for k,v in out.items() if v}) | |
| __radd__=__add__ | |
| def __mul__(self,other): | |
| if isinstance(other,(int,F)): | |
| return FormalPolynomial({k:v*other for k,v in self.items() if v*other}) | |
| out=FormalPolynomial() | |
| for k,v in self.items(): | |
| for l,w in other.items(): | |
| m=tuple(sorted(k+l));out[m]=out.get(m,F(0))+v*w | |
| return out | |
| __rmul__=__mul__ | |
| def six_case_symbolic_checks(): | |
| d,n=4,8 | |
| c={frozenset(S):FormalPolynomial({('c_'+''.join(str(i+1) for i in S),):F(1)}) | |
| for S in combinations(range(n),d)} | |
| rho=merge_normalized(c,n) | |
| h,k=n-2,n-1 | |
| z=n-2 | |
| out=[] | |
| for az,bz in [(0,0),(0,1),(0,2),(1,0),(1,1),(2,0)]: | |
| C=tuple(range(d-2-az)) | |
| external=tuple(range(len(C),len(C)+4-bz)) | |
| quartet=external+(z,)*bz | |
| i,j=external[:2] | |
| alpha=[0]*(n-1) | |
| for x in C:alpha[x]+=1 | |
| alpha[z]=az | |
| def base(*xs):return c[frozenset(C+tuple(xs))] | |
| def b(*xs):return base(*xs,h)+base(*xs,k) | |
| if (az,bz)==(0,0): | |
| i,j,l,m=external | |
| expected=[base(i,j)*base(l,m),base(i,l)*base(j,m),base(i,m)*base(j,l)] | |
| elif (az,bz)==(0,1): | |
| i,j,l=external | |
| expected=[base(i,j)*b(l),base(i,l)*b(j),b(i)*base(j,l)] | |
| elif (az,bz)==(0,2): | |
| expected=[2*base(i,j)*base(h,k),b(i)*b(j),b(i)*b(j)] | |
| elif (az,bz)==(1,0): | |
| i,j,l,m=external | |
| expected=[b(i,j)*b(l,m),b(i,l)*b(j,m),b(i,m)*b(j,l)] | |
| elif (az,bz)==(1,1): | |
| i,j,l=external | |
| expected=[2*b(i,j)*base(l,h,k),2*b(i,l)*base(j,h,k),2*base(i,h,k)*b(j,l)] | |
| else: | |
| i,j,l,m=external | |
| expected=[4*base(i,j,h,k)*base(l,m,h,k),4*base(i,l,h,k)*base(j,m,h,k),4*base(i,m,h,k)*base(j,l,h,k)] | |
| i,j,l,m=quartet | |
| actual=[] | |
| for ab,cd in [((i,j),(l,m)),((i,l),(j,m)),((i,m),(j,l))]: | |
| aa=alpha[:];bb=alpha[:] | |
| for x in ab:aa[x]+=1 | |
| for x in cd:bb[x]+=1 | |
| actual.append(rho[tuple(aa)]*rho[tuple(bb)]) | |
| assert actual==expected,(az,bz) | |
| out.append(dict(common_z_multiplicity=az,quartet_z_multiplicity=bz, | |
| product_polynomials=[{' * '.join(m):frac(v) for m,v in sorted(poly.items())} | |
| for poly in actual], | |
| arithmetic='exact formal polynomial identity',status='verified')) | |
| return out | |
| def normalized_numeric_checks(): | |
| import mpmath as mp | |
| mp.mp.dps=90 | |
| rng=random.Random(20261116) | |
| out=[] | |
| for d,n in [(2,6),(3,6),(4,7),(5,8)]: | |
| for trial in range(3): | |
| while True: | |
| A=[[rng.randrange(-7,8) for _ in range(n)] for _ in range(d)] | |
| mm=minors(A) | |
| if all(mm.values()):break | |
| for qstr in ['0.25','0.5','1','1.5','2','3','5','8']: | |
| q=mp.mpf(qstr) | |
| p=max(q,1) if d==2 else 2*max(q,1) | |
| coeff={S:mp.power(mp.mpf(v.numerator)/v.denominator,q) for S,v in mm.items()} | |
| rho=merge_normalized(coeff,n) | |
| count=0; min_rel=None; cases=Counter() | |
| for alpha,beta,t in quartet_relations(rho,d,n): | |
| roots=[mp.power(v,1/p) for v in t] | |
| total=sum(roots);gap=total-2*max(roots) | |
| relative=gap/total if total else mp.mpf(0) | |
| assert relative > -mp.mpf('1e-75'),(d,n,qstr,alpha,beta,relative) | |
| min_rel=relative if min_rel is None else min(min_rel,relative) | |
| cases[f'alpha_z={alpha[-1]},quartet_z={beta[-1]}']+=1 | |
| count+=1 | |
| out.append(dict(rank=d,input_variables=n,matrix_trial=trial+1,matrix=A,q=qstr, | |
| output_parameter=mp.nstr(p,12),weak_relations=count, | |
| case_counts=dict(sorted(cases.items())), | |
| minimum_relative_polygon_slack=mp.nstr(min_rel,30), | |
| precision_decimal_digits=90, | |
| arithmetic='high-precision numerical; not an exact certificate')) | |
| return out | |
| def degenerate_matrices(): | |
| """Full-row-rank integer matrices with reproducible zero-minor patterns.""" | |
| out=[] | |
| # The last two columns are e1,e2; each first-column last coordinate is wi. | |
| xy=[(1,0),(0,1),(-1,1),(2,-1)] | |
| for zero_count in range(5): | |
| A=[[xy[j][0] for j in range(4)]+[1,0], | |
| [xy[j][1] for j in range(4)]+[0,1], | |
| [0 if j<zero_count else 1 for j in range(4)]+[0,0]] | |
| # When all four wi vanish the affine construction is rank deficient. | |
| # A separate full-rank collinear-last-columns case covers wi all zero. | |
| if any(minors(A).values()): | |
| out.append((f'rank3_affine_{zero_count}_zero_weights',A)) | |
| out += [ | |
| ('rank3_parallel_merged_all_zero_weights', | |
| [[1,0,0,1,1,2],[0,1,0,1,0,0],[0,0,1,1,0,0]]), | |
| ('rank3_zero_merged_column', | |
| [[1,0,0,1,1,0],[0,1,0,1,0,0],[0,0,1,1,0,0]]), | |
| ('rank2_parallel_pairs',[[1,0,0,0,1,0],[0,1,0,0,0,1]]), | |
| ('rank2_duplicate_and_zero',[[1,1,0,0,1,0],[0,0,1,0,1,0]]), | |
| ('rank2_loop_merge_q_bound',[[1,0,1,1,0,0],[0,1,1,-1,0,0]])] | |
| # Sparse random full-row-rank examples; labels and every matrix are retained. | |
| rng=random.Random(2026111602) | |
| for d,n in [(2,6),(3,6),(4,7)]: | |
| for trial in range(4): | |
| while True: | |
| A=[[rng.choice([0,0,0,-2,-1,1,2]) for _ in range(n)] for _ in range(d)] | |
| mm=minors(A) | |
| if any(mm.values()) and any(v==0 for v in mm.values()):break | |
| out.append((f'rank{d}_sparse_{trial+1}',A)) | |
| return out | |
| def degenerate_output_checks(): | |
| import mpmath as mp | |
| mp.mp.dps=90 | |
| exact=[];numeric=[];matrix_data=[] | |
| for label,A in degenerate_matrices(): | |
| d,n=len(A),len(A[0]);mm=minors(A) | |
| assert any(mm.values()) and any(v==0 for v in mm.values()) | |
| matrix_data.append(dict(label=label,rank=d,input_variables=n,matrix=A, | |
| zero_maximal_minors=sum(v==0 for v in mm.values()), | |
| nonzero_maximal_minors=sum(v!=0 for v in mm.values()))) | |
| rho=merge_normalized(mm,n) | |
| strict=boundary=relations=0;case_counts=Counter() | |
| for alpha,beta,t in quartet_relations(rho,d,n): | |
| Amax=max(t);others=list(t);others.remove(Amax);B,C=others | |
| if d==2: | |
| gap=B+C-Amax | |
| assert gap>=0,(label,alpha,beta,t) | |
| is_boundary=(gap==0) | |
| else: | |
| # sqrt(A)<=sqrt(B)+sqrt(C), decided using rational arithmetic. | |
| delta=Amax-B-C | |
| if delta<=0: | |
| is_boundary=(delta==0 and B*C==0) | |
| else: | |
| residual=4*B*C-delta*delta | |
| assert residual>=0,(label,alpha,beta,t) | |
| is_boundary=(residual==0) | |
| boundary+=is_boundary;strict+=not is_boundary;relations+=1 | |
| case_counts[f'alpha_z={alpha[-1]},quartet_z={beta[-1]}']+=1 | |
| exact.append(dict(matrix_label=label,input_q=1,output_parameter=1 if d==2 else 2, | |
| relations=relations,strict_relations=strict,boundary_relations=boundary, | |
| case_counts=dict(sorted(case_counts.items())), | |
| arithmetic='exact rational, using squared square-root comparison when output p=2')) | |
| for qstr in ['0.25','0.5','1','1.5','2','3','5','8']: | |
| q=mp.mpf(qstr);p=max(q,1) if d==2 else 2*max(q,1) | |
| coeff={S:mp.power(mp.mpf(v.numerator)/v.denominator,q) for S,v in mm.items()} | |
| rho=merge_normalized(coeff,n) | |
| count=zero_relations=0;min_rel=None | |
| for alpha,beta,t in quartet_relations(rho,d,n): | |
| roots=[mp.power(v,1/p) for v in t] | |
| total=sum(roots);gap=total-2*max(roots) | |
| relative=gap/total if total else mp.mpf(0) | |
| assert relative > -mp.mpf('1e-75'),(label,qstr,alpha,beta,relative) | |
| zero_relations+=(total==0) | |
| min_rel=relative if min_rel is None else min(min_rel,relative) | |
| count+=1 | |
| numeric.append(dict(matrix_label=label,input_q=qstr,output_parameter=mp.nstr(p,12), | |
| relations=count,identically_zero_relations=zero_relations, | |
| minimum_relative_polygon_slack=mp.nstr(min_rel,30), | |
| precision_decimal_digits=90, | |
| arithmetic='high-precision numerical; q=1 is separately certified exactly')) | |
| return dict(matrix_count=len(matrix_data),q_sample_count=8, | |
| numerical_instance_count=len(numeric), | |
| matrices=matrix_data,exact_q1_certificates=exact,numerical_checks=numeric) | |
| def robustness_algebra_checks(): | |
| # These rational checks isolate the constants in the universal argument. | |
| # With 0<L<1, delta=L/16 and eta=L/2048, lower bounds are: | |
| input_factor=F(1,64)-F(8,2048) | |
| output_factor=F(1,8)-F(64,2048) | |
| assert input_factor==F(3,256)>0 | |
| assert output_factor==F(3,32)>0 | |
| return dict(arithmetic='exact rational constant arithmetic', | |
| perturbation_radius='eta=L/2048', | |
| original_normalized_input_slack_at_least='L/16', | |
| input_normalized_slack_after_perturbation_at_least='3L/256', | |
| original_output_defect_at_least='L/2', | |
| output_defect_after_perturbation_at_least='3L/32', | |
| qualification='These checks verify constants; the manuscript proves the hypotheses for every q.') | |
| def main(): | |
| ap=argparse.ArgumentParser() | |
| ap.add_argument('--output',default=str(Path(__file__).with_name('verification_results.json'))) | |
| ap.add_argument('--skip-numerical',action='store_true') | |
| args=ap.parse_args() | |
| result=dict(title='Ilyoxune reproducibility certificates', | |
| scope='Finite exact and numerical checks. Universal assertions require the manuscript proofs.', | |
| allrank_strict_uniform_seed=allrank_checks(), | |
| exact_small_counterexamples=exact_small_witnesses(), | |
| exact_matrix_obstructions=exact_matrix_obstructions(), | |
| robustness_constants=robustness_algebra_checks(), | |
| six_normalized_output_cases=six_case_symbolic_checks()) | |
| if not args.skip_numerical: | |
| result['normalized_output_parameter_checks']=normalized_numeric_checks() | |
| result['degenerate_normalized_output_checks']=degenerate_output_checks() | |
| target=Path(args.output);target.write_text(json.dumps(result,indent=2)+'\n') | |
| print(json.dumps(dict(output=str(target.resolve()),allrank_instances=len(result['allrank_strict_uniform_seed']), | |
| exact_counterexamples=len(result['exact_small_counterexamples']), | |
| numerical_instances=len(result.get('normalized_output_parameter_checks',[])), | |
| degenerate_matrices=result.get('degenerate_normalized_output_checks',{}).get('matrix_count',0), | |
| degenerate_numerical_instances=result.get('degenerate_normalized_output_checks',{}).get('numerical_instance_count',0), | |
| status='all checks passed'),indent=2)) | |
| if __name__=='__main__':main() | |