"""Verify a rational n = 15 construction and two coordinate-wise upper bounds.""" from fractions import Fraction from itertools import combinations from pathlib import Path TARGET = Fraction(31, 1485) WEIGHTS = ( { (1, 7, 15): Fraction(8, 225), (2, 7, 11): Fraction(31, 225), (5, 9, 13): Fraction(31, 45), (11, 13, 15): Fraction(31, 225), }, { (1, 3, 10): Fraction(2, 33), (4, 8, 10): Fraction(31, 33), }, ) def area(triangle): (ax, ay), (bx, by), (cx, cy) = triangle return abs((bx - ax) * (cy - ay) - (cx - ax) * (by - ay)) / 2 def axis_bound(points, axis, weights): """Bound the minimum for a fixed other axis and fixed triangle orientations.""" assert sum(weights.values()) == 1 and min(weights.values()) > 0 coefficients = [Fraction(0)] * len(points) for triple, weight in weights.items(): positions = [points[i - 1][axis] for i in triple] fixed = [points[i - 1][1 - axis] for i in triple] a, b, c = fixed terms = ((b - c) / 2, (c - a) / 2, (a - b) / 2) value = sum(t * x for t, x in zip(terms, positions)) assert abs(value) == TARGET sign = 1 if value > 0 else -1 for index, term in zip(triple, terms): coefficients[index - 1] += weight * sign * term return sum(max(0, coefficient) for coefficient in coefficients) def main(): path = Path(__file__).with_name("deletion-certificate.dat") points = [tuple(map(Fraction, line.split())) for line in path.read_text().splitlines()] assert len(points) == len(set(points)) == 15 assert all(0 <= value <= 1 for p in points for value in p) areas = list(map(area, combinations(points, 3))) assert min(areas) == TARGET print(f"Exact minimum {TARGET} attained by {areas.count(TARGET)} of {len(areas)} triangles.") for axis, label in enumerate("xy"): bound = axis_bound(points, axis, WEIGHTS[axis]) assert bound == TARGET print(f"Vary {label} with the other axis and orientations fixed: upper bound {bound}.") if __name__ == "__main__": main()