"""Reconstruct finite Jouhet–Mosaki linear forms over a real quadratic field. Run with Python 3 and SymPy. All identities and integrality tests are exact. The paper proves the limiting estimates separately. """ from math import comb, factorial, prod from sympy import Poly, QQ, Symbol, cyclotomic_poly, sqrt from sympy.functions.combinatorial.numbers import stirling def residues(field, q, A, r, n): """Expand q**(n*(r-1)) times (3.8) at every pole, through order A.""" Q = q**2 zero, one = field.zero, field.one power = ((A - 2*r)*n + A)//2 - 2 e = n*(r - 1) scale = q**(e - A*(n*n - 1) - (power + 1)) scale *= prod((one - Q**i for i in range(1, n + 1)), start=one)**(A - 2*r) factors = [Q**i for i in (*range(-r*n, 0), *range(n, n + r*n))] poles = [q**(1 - 2*j) for j in range(n + 1)] all_d = [] for j, t in enumerate(poles): # The h-th entry is the coefficient of u**h at T = t + u. series = [scale * comb(power, h) * t**(power-h) if h <= power else zero for h in range(A)] for a in factors: constant = one - a*t series = [series[0]*constant] + [ constant*series[h] - a*series[h-1] for h in range(1, A) ] for i, other in enumerate(poles): if i == j: continue gap = t - other inv = [(-1)**h * comb(A+h-1, h) * gap**(-A-h) for h in range(A)] series = [sum((series[h-k]*inv[k] for k in range(h+1)), zero) for h in range(A)] # (3.9) converts coefficients at (T-t)**(-s) to (1-T/t)**(-s). all_d.append([(-1)**s * t**(-s) * series[A-s] for s in range(1, A+1)]) # Check the resulting partial fractions against (3.8) at T = -1. T = -one numerator = scale * T**power * prod((one - a*T for a in factors), start=one) denominator = prod(((T-t)**A for t in poles), start=one) reconstructed = sum((d / (one - T/t)**s for t, row in zip(poles, all_d) for s, d in enumerate(row, 1)), zero) assert numerator == denominator * reconstructed return all_d def parts(field, q, A, r, n): """Compute the normalized P_s(1,Q) and one finite tail from (3.17).""" zero, one = field.zero, field.one rows = residues(field, q, A, r, n) P = [sum(((-1)**j * q**(1-2*j) * row[s] for j, row in enumerate(rows)), zero) for s in range(A)] tail = zero for j, row in enumerate(rows): for k in range(1, j+1): inverse = (one - q**(2*k-1))**(-1) # Horner's rule for sum_{s=1}^A d_{s,j} * inverse**s. value = zero for d in reversed(row): value = inverse*(d + value) tail += (-1)**(j+k) * q**(2*(k-j)) * value return P, tail, rows def centered_denominator(field, q, A, r, n): """Evaluate (A-1)! q**(-deg(G)/2) G(q) directly by cyclotomic factors.""" x = Symbol("x") product = field.one degree = 0 for k in range(1, 2*n+1): multiplicity = A-1 + (k % 2) + (k == 1) if k % 2 == 0: multiplicity += 2*r*(n//(k//2)) phi = Poly(cyclotomic_poly(k, x), x) value = field.zero for coefficient in phi.all_coeffs(): value = value*q + int(coefficient) product *= value**multiplicity degree += phi.degree()*multiplicity assert degree % 2 == 0 return factorial(A-1) * q**(-degree//2) * product def check(trace, A, r, n): radical = sqrt(trace**2-4) field = QQ.algebraic_field(radical) q = field.from_sympy((trace-radical)/2) inverse = q**(-1) P, tail, rows = parts(field, q, A, r, n) other_P, other_tail, other_rows = parts(field, inverse, A, r, n) # (3.12) for the raw pole residues, incorporating our normalization. for row, other in zip(rows, reversed(other_rows)): assert all(v == -(q**(2-2*n))*u for u, v in zip(row, other)) assert P == other_P assert all(field.to_sympy(v).is_Rational for v in P) # (3.15) and (3.16), including the correction to the constant term. coeffs = [tail + other_tail - P[0]/2] for weight in range(2, A, 2): coeffs.append(sum((2*int(stirling(s-1, weight-1, kind=1))*P[s-1]/factorial(s-1) for s in range(weight, A+1)), field.zero)) coeffs = [field.to_sympy(v) for v in coeffs] assert all(v.is_Rational for v in coeffs) C = field.to_sympy(centered_denominator(field, q, A, r, n)) assert C.is_Integer and C > 0 assert all((v*C).is_Integer for v in coeffs) if (trace, A, r, n) == (3, 3, 1, 1): assert 5*coeffs[0] == -21 and 5*coeffs[1] == 22 print(f"trace={trace}, A={A}, r={r}, n={n}: {len(coeffs)} rational coefficients; " f"all integral after clearing; denominator has {len(str(C))} digits") if __name__ == "__main__": for parameters in [(3, 3, 1, 1), (3, 21, 3, 1), (3, 21, 3, 3), (3, 21, 3, 5), (4, 21, 3, 3)]: check(*parameters)