import mpmath as mp
mp.mp.dps = 40

# Holomorphic section counts on CP^2: h^0(O(k)) = (k+1)(k+2)/2
def h0(k):
    return (k+1)*(k+2)//2

for k in range(0,6):
    print(f"h0(O({k})) = {h0(k)}")

print()
# The two ladders in the corpus:
# (A) mass-partition note: FS block 19 = h0(O(1))+h0(O(2))+h0(O(3)) = 3+6+10, stops at k=3=Ngen
print("mass-partition FS block: 3+6+10 =", h0(1)+h0(2)+h0(3), "(k=1..3)")
# (B) live CKM ladder (appendix_AO): lambda = 6+10+15 = 31 = h0(O(2))+h0(O(3))+h0(O(4)), k=2..4
print("live CKM ladder:         6+10+15 =", h0(2)+h0(3)+h0(4), "(k=2..4)")

print()
# Target abundance
Ob_h2 = 0.02237   # Planck baryon
target = 0.12      # Omega_chi h^2 needed for 3rd peak
ratio_needed = target/Ob_h2
print(f"Needed Omega_chi/Omega_b = {target}/{Ob_h2} = {ratio_needed:.4f}")
print(f"16/3 = {16/3:.4f}")
print()

# The retired construction: 16/3 = (19-3)/3.  19 here is the FS block.
print("retired: (19-3)/3 =", (19-3)/3, "= 16/3; here 19 = 3+6+10 FS block (k=1..3)")
print()

# Question: any topological partition giving ~5.36 (=0.12/0.02237) WITHOUT the retired 19?
# Enumerate candidate integer ratios from the microsector bricks:
Ngen = 3
nnz = 57
kmax = 60
dimM7 = 7
b3 = 1
chiCP2 = 3
spinor16 = 16
e8 = 8

bricks = {'Ngen':3,'nnz':57,'kmax':60,'dimM7':7,'spinor16':16,'e8':8,
          'b3':1,'chiCP2':3,'h0O1':3,'h0O2':6,'h0O3':10,'h0O4':15,
          '12gauge':12,'31':31,'19':19,'96':96}

print(f"--- integer ratios within 2% of needed {ratio_needed:.4f} ---")
hits=[]
names=list(bricks.keys())
for n1 in names:
    for n2 in names:
        v=bricks[n1]/bricks[n2]
        if abs(v-ratio_needed)/ratio_needed < 0.02:
            hits.append((n1,n2,v))
for h in sorted(hits,key=lambda x:abs(x[2]-ratio_needed)):
    print(f"  {h[0]}/{h[1]} = {h[2]:.4f}")

print()
# Also test Omega_chi h^2 directly as a topological fraction of something
# Could 0.12 be a fraction f * Omega_m or relate to nnz/kmax etc as energy fraction?
print(f"nnz/kmax = 57/60 = {57/60}")
print(f"Ngen/kmax = 3/60 = {3/60} (= 0.05)")
print(f"(kmax-nnz)/kmax = 3/60 = 0.05")
print(f"chiCP2/(spinor16+... )")
