Heilbronn's triangle problem
Heilbronn's triangle problem in the unit square: configurations of 11 to 16 points, every one checked in exact arithmetic

| 1 | """Classify the nonsingular ordered roots of the symmetric row model.""" |
| 2 | |
| 3 | import json |
| 4 | from fractions import Fraction |
| 5 | from math import comb |
| 6 | from pathlib import Path |
| 7 | |
| 8 | from flint import ctx, fmpq_poly, fmpz_poly, nmod_poly |
| 9 | |
| 10 | from certify_reduced import Interval |
| 11 | from row_certificate import ROOT_BRACKET, check_algebra, polynomial, quotient_field, verified_bracket |
| 12 | from row_model import build |
| 13 | from verify_contact_identities import RING, Rational |
| 14 | |
| 15 | |
| 16 | def coefficients(poly): |
| 17 | rows = [[0] * (int(poly.degrees()[1]) + 1) for _ in range(int(poly.degrees()[2]) + 1)] |
| 18 | for (_, b, c), value in poly.terms(): |
| 19 | rows[int(c)][int(b)] = int(value) |
| 20 | return rows |
| 21 | |
| 22 | |
| 23 | def common_monic(sources, modulus): |
| 24 | def trim(values): |
| 25 | while values and values[-1].is_zero(): |
| 26 | values.pop() |
| 27 | return values |
| 28 | |
| 29 | def monic(values): |
| 30 | if not values: |
| 31 | return values |
| 32 | gcd, adj, _ = values[-1].xgcd(modulus) |
| 33 | assert gcd.degree() == 0 |
| 34 | return [(x * (adj / gcd[0])) % modulus for x in values] |
| 35 | |
| 36 | def remainder(a, b): |
| 37 | a = list(a) |
| 38 | while len(a) >= len(b): |
| 39 | shift = len(a) - len(b) |
| 40 | leading = a[-1] |
| 41 | for j, coefficient in enumerate(b[:-1]): |
| 42 | a[j + shift] = (a[j + shift] - leading * coefficient) % modulus |
| 43 | a.pop() |
| 44 | trim(a) |
| 45 | return a |
| 46 | |
| 47 | f, g = [monic(trim([fmpq_poly(row) % modulus for row in source])) for source in sources] |
| 48 | while g: |
| 49 | f, g = g, monic(remainder(f, g)) |
| 50 | return f |
| 51 | |
| 52 | |
| 53 | def real_intervals_above_one(coeffs): |
| 54 | def variations(values): |
| 55 | signs = [1 if x > 0 else -1 for x in values if x != 0] |
| 56 | return sum(x != y for x, y in zip(signs, signs[1:])) |
| 57 | |
| 58 | poly = fmpq_poly(coeffs) |
| 59 | sturm = [poly, poly.derivative()] |
| 60 | while not (remaining := -sturm[-2] % sturm[-1]).is_zero(): |
| 61 | sturm.append(remaining / abs(remaining[remaining.degree()])) |
| 62 | expected = (variations([p(1) for p in sturm]) |
| 63 | - variations([p[p.degree()] for p in sturm])) |
| 64 | intervals = [] |
| 65 | for root, _ in fmpz_poly(coeffs).complex_roots(): |
| 66 | if root.imag.is_zero() and root.real > 1: |
| 67 | center = Fraction(root.real.str(57, radius=False)) |
| 68 | delta = Fraction("1e-54") |
| 69 | low, high, _ = verified_bracket(coeffs, (center - delta, center + delta)) |
| 70 | assert low > 1 |
| 71 | intervals.append(Interval(low, high)) |
| 72 | assert len(intervals) == expected |
| 73 | assert all(a.high < b.low for a, b in zip(intervals, intervals[1:])) |
| 74 | return intervals |
| 75 | |
| 76 | |
| 77 | def forward_positive(common, b): |
| 78 | """Require positive Taylor coefficients in c-b, including the constant.""" |
| 79 | values = [polynomial([Fraction(str(a)) for a in p.coeffs()], b) for p in common] |
| 80 | shifted = [ |
| 81 | polynomial([comb(j, i) * values[j] for j in range(i, len(values))], b) |
| 82 | for i in range(len(values)) |
| 83 | ] |
| 84 | return shifted[0].low > 0 and all(x.low >= 0 for x in shifted[1:]) |
| 85 | |
| 86 | |
| 87 | def modular_degree_bound(sources, modulus): |
| 88 | for prime in (101, 103, 107, 109, 113, 127, 131, 137): |
| 89 | for b, _ in nmod_poly(modulus, prime).roots(): |
| 90 | polys = [nmod_poly([int(nmod_poly(row, prime)(b)) for row in source], prime) |
| 91 | for source in sources] |
| 92 | if all(p.degree() == len(s) - 1 for p, s in zip(polys, sources)): |
| 93 | if polys[0].gcd(polys[1]).degree() == 1: |
| 94 | return prime, int(b) |
| 95 | raise ValueError("no good modular specialization") |
| 96 | |
| 97 | |
| 98 | def main(): |
| 99 | ctx.dps = 100 |
| 100 | field = json.loads(Path(__file__).with_name("row-field.json").read_text()) |
| 101 | for key in ("numerator_c_ascending", "denominator_c_ascending"): |
| 102 | field[key] = list(map(Fraction, field[key])) |
| 103 | check_algebra(field) |
| 104 | modulus = field["polynomial_b_ascending"] |
| 105 | _, b, c = map(Rational, RING.gens()) |
| 106 | _, _, residuals = build(b, c) |
| 107 | f, g = [equation.numerator for equation in residuals] |
| 108 | sources = list(map(coefficients, (f, g))) |
| 109 | prime, specialization = modular_degree_bound(sources, modulus) |
| 110 | print(f"Common root degree in c is one on the degree-27 factor (rank witness p={prime}, b={specialization}).") |
| 111 | |
| 112 | admitted = 0 |
| 113 | for factor, _ in f.resultant(g, 2).factor()[1]: |
| 114 | coeffs = coefficients(factor)[0] |
| 115 | intervals = real_intervals_above_one(coeffs) |
| 116 | if not intervals: |
| 117 | continue |
| 118 | if coeffs == modulus: |
| 119 | root_low, root_high = map(Fraction, ROOT_BRACKET) |
| 120 | for x in intervals: |
| 121 | y = polynomial(field["numerator_c_ascending"], x) / polynomial(field["denominator_c_ascending"], x) |
| 122 | if root_low < x.low and x.high < root_high: |
| 123 | assert y.low > x.high |
| 124 | admitted += 1 |
| 125 | result = "admissible root, checked by row_certificate.py" |
| 126 | else: |
| 127 | assert y.high < x.low |
| 128 | result = "excluded by row ordering" |
| 129 | print(f"degree 27 b={float(x.low):.9f}: {result}") |
| 130 | continue |
| 131 | |
| 132 | mod = fmpq_poly(coeffs) |
| 133 | common = common_monic(sources, mod) |
| 134 | if len(common) == 2: |
| 135 | element = quotient_field(mod) |
| 136 | try: |
| 137 | build(element(fmpq_poly([0, 1])), element(-common[0])) |
| 138 | except ZeroDivisionError: |
| 139 | reason = "singular denominator" |
| 140 | else: |
| 141 | raise ValueError("an additional nonsingular linear candidate requires classification") |
| 142 | elif len(common) == 1: |
| 143 | reason = "no common finite c" |
| 144 | else: |
| 145 | assert all(forward_positive(common, interval) for interval in intervals) |
| 146 | reason = "excluded by row ordering" |
| 147 | print(f"degree {mod.degree()}, {len(intervals)} real b>1: {reason}") |
| 148 | assert admitted == 1 |
| 149 | |
| 150 | |
| 151 | if __name__ == "__main__": |
| 152 | main() |