Unit circles through three of n points
Show that n points in the plane have only o(n²) unit circles passing through three of them; the best construction gives n^{3/2}.

| 1 | """Verify the finite linear algebra for the fixed abscissa obstruction.""" |
| 2 | |
| 3 | from fractions import Fraction |
| 4 | from itertools import combinations |
| 5 | from math import prod |
| 6 | |
| 7 | |
| 8 | WEIGHTS = { |
| 9 | (-5, 0, 5): 175, |
| 10 | (-5, 1, 4): -702, |
| 11 | (-5, 2, 3): 336, |
| 12 | (-4, 0, 4): 512, |
| 13 | (-4, 1, 3): -210, |
| 14 | (-3, 0, 3): -351, |
| 15 | (-3, 1, 2): 240, |
| 16 | } |
| 17 | |
| 18 | |
| 19 | def entry(triple, index): |
| 20 | """Return the coefficient of the indexed value in its divided difference.""" |
| 21 | if index not in triple: |
| 22 | return Fraction(0) |
| 23 | return Fraction(1, prod(index - other for other in triple if other != index)) |
| 24 | |
| 25 | |
| 26 | def determinant(matrix): |
| 27 | """Compute a small determinant by rational elimination with row pivots.""" |
| 28 | rows = [row.copy() for row in matrix] |
| 29 | result = Fraction(1) |
| 30 | for col in range(len(rows)): |
| 31 | pivot_row = next((r for r in range(col, len(rows)) if rows[r][col]), None) |
| 32 | if pivot_row is None: |
| 33 | return Fraction(0) |
| 34 | if pivot_row != col: |
| 35 | rows[col], rows[pivot_row] = rows[pivot_row], rows[col] |
| 36 | result = -result |
| 37 | leading = rows[col][col] |
| 38 | result *= leading |
| 39 | for r in range(col + 1, len(rows)): |
| 40 | multiplier = rows[r][col] / leading |
| 41 | for c in range(col + 1, len(rows)): |
| 42 | rows[r][c] -= multiplier * rows[col][c] |
| 43 | return result |
| 44 | |
| 45 | |
| 46 | def main(): |
| 47 | indices = range(-5, 6) |
| 48 | triples = [triple for triple in combinations(indices, 3) if sum(triple) == 0] |
| 49 | columns = [index for index in indices if index not in (0, 1, 2)] |
| 50 | minor = [[entry(triple, index) for index in columns] for triple in triples[:8]] |
| 51 | assert len(triples) == 13 |
| 52 | assert determinant(minor) == Fraction(1, 149361408000) |
| 53 | for index in indices: |
| 54 | total = Fraction(0) |
| 55 | for triple, weight in WEIGHTS.items(): |
| 56 | reflected = tuple(-vertex for vertex in reversed(triple)) |
| 57 | total += weight * (entry(triple, index) + entry(reflected, index)) / 2 |
| 58 | assert total == 0 |
| 59 | moments = [] |
| 60 | for degree in range(5): |
| 61 | moment = sum( |
| 62 | weight * (first * first + first * second + second * second) ** degree |
| 63 | for (first, second, _), weight in WEIGHTS.items() |
| 64 | ) |
| 65 | moments.append(moment) |
| 66 | assert moments == [0, 0, 0, 0, 1451520] |
| 67 | assert sum(weight * prod(triple) ** 2 for triple, weight in WEIGHTS.items()) == 0 |
| 68 | assert Fraction(3, 16) * moments[4] == 272160 |
| 69 | print("The minor, row cancellation, and moments are exact.") |
| 70 | |
| 71 | |
| 72 | if __name__ == "__main__": |
| 73 | main() |