"""Classify the nonsingular ordered roots of the symmetric row model.""" import json from fractions import Fraction from math import comb from pathlib import Path from flint import ctx, fmpq_poly, fmpz_poly, nmod_poly from certify_reduced import Interval from row_certificate import ROOT_BRACKET, check_algebra, polynomial, quotient_field, verified_bracket from row_model import build from verify_contact_identities import RING, Rational def coefficients(poly): rows = [[0] * (int(poly.degrees()[1]) + 1) for _ in range(int(poly.degrees()[2]) + 1)] for (_, b, c), value in poly.terms(): rows[int(c)][int(b)] = int(value) return rows def common_monic(sources, modulus): def trim(values): while values and values[-1].is_zero(): values.pop() return values def monic(values): if not values: return values gcd, adj, _ = values[-1].xgcd(modulus) assert gcd.degree() == 0 return [(x * (adj / gcd[0])) % modulus for x in values] def remainder(a, b): a = list(a) while len(a) >= len(b): shift = len(a) - len(b) leading = a[-1] for j, coefficient in enumerate(b[:-1]): a[j + shift] = (a[j + shift] - leading * coefficient) % modulus a.pop() trim(a) return a f, g = [monic(trim([fmpq_poly(row) % modulus for row in source])) for source in sources] while g: f, g = g, monic(remainder(f, g)) return f def real_intervals_above_one(coeffs): def variations(values): signs = [1 if x > 0 else -1 for x in values if x != 0] return sum(x != y for x, y in zip(signs, signs[1:])) poly = fmpq_poly(coeffs) sturm = [poly, poly.derivative()] while not (remaining := -sturm[-2] % sturm[-1]).is_zero(): sturm.append(remaining / abs(remaining[remaining.degree()])) expected = (variations([p(1) for p in sturm]) - variations([p[p.degree()] for p in sturm])) intervals = [] for root, _ in fmpz_poly(coeffs).complex_roots(): if root.imag.is_zero() and root.real > 1: center = Fraction(root.real.str(57, radius=False)) delta = Fraction("1e-54") low, high, _ = verified_bracket(coeffs, (center - delta, center + delta)) assert low > 1 intervals.append(Interval(low, high)) assert len(intervals) == expected assert all(a.high < b.low for a, b in zip(intervals, intervals[1:])) return intervals def forward_positive(common, b): """Require positive Taylor coefficients in c-b, including the constant.""" values = [polynomial([Fraction(str(a)) for a in p.coeffs()], b) for p in common] shifted = [ polynomial([comb(j, i) * values[j] for j in range(i, len(values))], b) for i in range(len(values)) ] return shifted[0].low > 0 and all(x.low >= 0 for x in shifted[1:]) def modular_degree_bound(sources, modulus): for prime in (101, 103, 107, 109, 113, 127, 131, 137): for b, _ in nmod_poly(modulus, prime).roots(): polys = [nmod_poly([int(nmod_poly(row, prime)(b)) for row in source], prime) for source in sources] if all(p.degree() == len(s) - 1 for p, s in zip(polys, sources)): if polys[0].gcd(polys[1]).degree() == 1: return prime, int(b) raise ValueError("no good modular specialization") def main(): ctx.dps = 100 field = json.loads(Path(__file__).with_name("row-field.json").read_text()) for key in ("numerator_c_ascending", "denominator_c_ascending"): field[key] = list(map(Fraction, field[key])) check_algebra(field) modulus = field["polynomial_b_ascending"] _, b, c = map(Rational, RING.gens()) _, _, residuals = build(b, c) f, g = [equation.numerator for equation in residuals] sources = list(map(coefficients, (f, g))) prime, specialization = modular_degree_bound(sources, modulus) print(f"Common root degree in c is one on the degree-27 factor (rank witness p={prime}, b={specialization}).") admitted = 0 for factor, _ in f.resultant(g, 2).factor()[1]: coeffs = coefficients(factor)[0] intervals = real_intervals_above_one(coeffs) if not intervals: continue if coeffs == modulus: root_low, root_high = map(Fraction, ROOT_BRACKET) for x in intervals: y = polynomial(field["numerator_c_ascending"], x) / polynomial(field["denominator_c_ascending"], x) if root_low < x.low and x.high < root_high: assert y.low > x.high admitted += 1 result = "admissible root, checked by row_certificate.py" else: assert y.high < x.low result = "excluded by row ordering" print(f"degree 27 b={float(x.low):.9f}: {result}") continue mod = fmpq_poly(coeffs) common = common_monic(sources, mod) if len(common) == 2: element = quotient_field(mod) try: build(element(fmpq_poly([0, 1])), element(-common[0])) except ZeroDivisionError: reason = "singular denominator" else: raise ValueError("an additional nonsingular linear candidate requires classification") elif len(common) == 1: reason = "no common finite c" else: assert all(forward_positive(common, interval) for interval in intervals) reason = "excluded by row ordering" print(f"degree {mod.degree()}, {len(intervals)} real b>1: {reason}") assert admitted == 1 if __name__ == "__main__": main()