"""Necessary local and trace conditions for the two-diagonal cubic pencil.""" from fractions import Fraction from functools import cache from itertools import product from math import gcd, lcm def column_counts(late): """Entries are sums of local degrees of the later coordinate.""" for left in range(late + 1): for right in range(late - left + 1): center = late - left - right bound = min(left, right, center // 2) for step in range(-bound, bound + 1): yield ( (left - step, left, left + step), (center + 2*step, center, center - 2*step), (right - step, right, right + step), ) def row_counts(early, cols, a, b): """Off-diagonal cell ratios fix five of the nine row entries.""" lm = cols[0][1] * b // a rm = cols[2][1] * b // a ml = cols[1][0] * b // a mr = cols[1][2] * b // a mm = early - ml - mr if min(early-lm, early-rm, mm) < 0 or bool(mm) != bool(cols[1][1]): return for ll in range(early - lm + 1): lr = early - lm - ll # The sums of h on the three f-fibres form an arithmetic progression. diff = 2*(mr - ml) - (lr - ll) if (early - rm - diff) % 2: continue rl = (early - rm - diff) // 2 rr = early - rm - rl if min(rl, rr) < 0: continue rows = ((ll,lm,lr), (ml,mm,mr), (rl,rm,rr)) if all(bool(rows[i][j]) == bool(cols[i][j]) for i,j in product(range(3),repeat=2)): yield rows def corner_weights(a, b, early, late, incidence): total = Fraction(3*a*early, late) - 3*b if total <= 0: return # There is a noncentral marked point on at least one diagonal. weights = set() for i,j in ((0,0),(2,2),(0,2),(2,0)): uf, vg = incidence[i][j] for u in range(1, uf+1): for v in range(1, vg+1): num = a*u-b*v if num <= 0: continue contacts = range(u,late+1) if u == v else (min(u,v),) for w in contacts: first = Fraction(num,w) c = first if i == j else total - first d = total - c if 0 < c <= d: weights.add((c,d)) for c,d in weights: scale = lcm(c.denominator,d.denominator) yield (a*scale,b*scale,int(c*scale),int(d*scale)) @cache def cell_options(uf, vg, kind, a, b, c, d, late): """Return upper bounds on point counts, indexed by both diagonal contacts.""" if not uf: return ((0,0,0),) if kind == 'off': factor = gcd(a,b) n = uf // (b//factor) if n*(b//factor) == uf and n*(a//factor) == vg: return ((n,0,0),) return () branches = [] for u in range(1,uf+1): for v in range(1,vg+1): m = min(u,v) sequence = range(m,late+1) if u == v else (m,) if kind == 'pos': contacts = ((w,0) for w in sequence) elif kind == 'neg': contacts = ((0,w) for w in sequence) else: contacts = {(m,w) for w in sequence} | {(w,m) for w in sequence} for w,z in contacts: if a*u == b*v+c*w+d*z: branches.append((u,v,w,z)) @cache def grow(p,q): if not p: return {(0,0,0)} if not q else set() return {(n+1,w+w0,z+z0) for u,v,w,z in branches if u<=p and v<=q for n,w0,z0 in grow(p-u,q-v) if w+w0<=late and z+z0<=late} return tuple(grow(uf,vg)) def admissible(early, late): answers = set() for cols in column_counts(late): off = gcd(cols[0][1],cols[2][1],cols[1][0],cols[1][2]) for a in range(2,off+1): if off%a: continue for b in range(1,a): if gcd(a,b)>1: continue for rows in row_counts(early,cols,a,b): incidence = tuple(tuple(zip(row,col)) for row,col in zip(rows,cols)) for weights in corner_weights(a,b,early,late,incidence): states = {(0,0):0} for i,j in product(range(3),repeat=2): kind = ('both' if i==j==1 else 'pos' if i==j else 'neg' if i+j==2 else 'off') options = cell_options(*incidence[i][j],kind,*weights,late) nxt = {} for (w,z),n in states.items(): for q,u,v in options: key = (w+u,z+v) if max(key)<=late: nxt[key] = max(nxt.get(key,0),n+q) states=nxt if not states: break if states.get((late,late),0) >= max(2*late,2*early+2*late-16): answers.add(weights) return sorted(answers) if __name__ == '__main__': survivors = [] pairs = 0 for early in range(1,16): for late in range(early+1,17): if 2*late>3*early or 2*late-early>16: continue pairs += 1 for weights in admissible(early,late): survivors.append((early,late,weights)) assert survivors == [(5,6,(2,1,1,1))] print('Degree pairs:', pairs) print('Survivors (early degree, late degree, exponents):', survivors)