"""Authoritative exact boundary certificate for nonclique r44 caps.""" from fractions import Fraction as F from itertools import combinations from pathlib import Path import json def solve(A,b): n=len(b);M=[[F(x)for x in row]+[F(v)]for row,v in zip(A,b)] for j in range(n): p=next((i for i in range(j,n)if M[i][j]),None) if p is None:return None M[j],M[p]=M[p],M[j];c=M[j][j];M[j]=[x/c for x in M[j]] for i in range(n): if i!=j: c=M[i][j];M[i]=[x-c*y for x,y in zip(M[i],M[j])] return tuple(row[-1]for row in M) def dot(a,b):return sum(x*y for x,y in zip(a,b)) records=[] expected={'edge':F(202,75),'star2':F(107,40),'star3':F(332,125),'triangle':F(2773,1058)} for name,H in [('edge',[(0,1)]),('star2',[(0,1),(0,2)]),('star3',[(0,1),(0,2),(0,3)]),('triangle',[(0,1),(0,2),(1,2)])]: deg=[sum(i in e for e in H)for i in range(4)];q=[1+d for d in deg];Q=sum(q) lines=[] for i in range(4): row=[F(0)]*4;row[i]=1;lines.append((tuple(row),F(1))) for i in range(4): for j in range(4): row=[F(0)]*4;row[i]+=7;row[j]-=q[i] for u,v in H: if u==i:row[v]+=1 elif v==i:row[u]+=1 lines.append((tuple(row),F(7))) V=set() for active in combinations(lines,3): x=solve([[1]*4]+[a for a,b in active],[5]+[b for a,b in active]) if x is not None and all(dot(a,x)>=b for a,b in lines):V.add(x) def loss(x):return 7*dot(x,x)-35+2*sum(x[i]*x[j]for i,j in H) def base(x):return loss(x)-dot(q,x)**2/Q vals=[(base(x),x)for x in V] worst=max(vals) r=2 if Q in (6,8) else 4;D=6*r-r*(r-1)-Q budget=F(6-r,2)+F(4,D) assert len(V)==14 and worst[0]==expected[name] and budget>worst[0] print(name,'q',Q,'verts',len(V),'maxbase',worst[0],float(worst[0]),'at',worst[1],'budget',budget,'margin',budget-worst[0]) # Hessian of base after x3=5-x0-x1-x2; calculate second differences/2. def f(x):return base(tuple(x)+(5-sum(x),)) z=[F(0)]*3;c=f(z);A=[[F(0)]*3 for _ in range(3)] for i in range(3): p=z.copy();p[i]=1;m=z.copy();m[i]=-1;A[i][i]=(f(p)+f(m)-2*c)/2 for j in range(i): u=z.copy();u[i]=1;v=z.copy();v[j]=1;p=z.copy();p[i]=p[j]=1 A[i][j]=A[j][i]=(f(p)-f(u)-f(v)+c)/2 d2=A[0][0]*A[1][1]-A[0][1]**2 d3=A[0][0]*(A[1][1]*A[2][2]-A[1][2]**2)-A[0][1]*(A[0][1]*A[2][2]-A[0][2]*A[1][2])+A[0][2]*(A[0][1]*A[1][2]-A[0][2]*A[1][1]) print('positive minors',A[0][0],d2,d3) assert min(A[0][0],d2,d3)>0 records.append(dict(pattern=name,missing_edges=H,port_counts=q,maximum_base=str(worst[0]), connector_vertices=r,new_deficiency=D,budget=str(budget),margin=str(budget-worst[0]), convexity_minors=list(map(str,(A[0][0],d2,d3))),vertices=[list(map(str,x))for x in sorted(V)])) Path(__file__).with_suffix('.json').write_text(json.dumps(records,indent=2)+'\n') print('PASS: all four convex boundary optimizations have strict certified margins.')