#!/usr/bin/env python3 """Generate Beyleveld's 14 points from Chappell's algebraic coordinates.""" import argparse from fractions import Fraction def root_midpoint(digits): # The cubic is strictly decreasing on this bracket and changes sign. lower, upper = Fraction(7, 100), Fraction(8, 100) tolerance = Fraction(1, 10 ** (digits + 6)) while upper - lower > tolerance: middle = (lower + upper) / 2 value = ((8 * middle - 12) * middle - 12) * middle + 1 if value > 0: lower = middle else: upper = middle return (lower + upper) / 2 def coordinates(digits): a = root_midpoint(digits) a_squared = a * a representatives = ( (a, Fraction(0)), (Fraction(0), (1 - a + 2 * a_squared) / 5), ((5 - 12 * a + 4 * a_squared) / 14, (9 + 26 * a + 38 * a_squared) / 35), (Fraction(1, 2), (1 + 4 * a + 12 * a_squared) / 10), ) scale = 10 ** digits points = set() for x, y in representatives: x, y = round(x * scale), round(y * scale) points.update(((x, y), (scale - x, y), (x, scale - y), (scale - x, scale - y))) return sorted(points) def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--digits', type=int, default=40, help='decimal places in the coordinate grid') args = parser.parse_args() if not 1 <= args.digits <= 200: parser.error('--digits must be between 1 and 200') scale = 10 ** args.digits def decimal(grid_coordinate): whole, remainder = divmod(grid_coordinate, scale) return f'{whole}.{remainder:0{args.digits}d}'.rstrip('0').rstrip('.') for x, y in coordinates(args.digits): print(decimal(x), decimal(y)) if __name__ == '__main__': main()