#!/usr/bin/env python3 """Reproduce Comellas--Yebra (2002), page 7, using only decimal arithmetic. Source: https://doi.org/10.37236/1623 Usage: python3 generate.py [--digits 60] > n12.txt No search or random seed: the points are the published construction. """ import argparse from decimal import Decimal, localcontext def coordinates(digits): with localcontext() as context: context.prec = digits + 40 a = Decimal(27) + 3 * Decimal(57).sqrt() # t is the positive cube root of 27 + 3 sqrt(57). t = Decimal(4) tolerance = Decimal(10) ** -(context.prec - 8) for _ in range(200): next_t = (2 * t + a / (t * t)) / 3 if abs(next_t - t) < tolerance: t = next_t break t = next_t else: raise ArithmeticError("cube-root iteration did not converge") x = 1 - (t * t + 6) / (6 * t) y = 2 * x * x - 3 * x + Decimal("0.5") zero, half, one = Decimal(0), Decimal("0.5"), Decimal(1) points = [ (x, zero), (one - x, zero), (zero, x), (one, x), (half, y), (y, half), (one - y, half), (half, one - y), (zero, one - x), (one, one - x), (x, one), (one - x, one), ] return "".join(f"{px:.{digits}f} {py:.{digits}f}\n" for px, py in points) if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--digits", type=int, default=60, help="digits after the decimal point (default: 60)") args = parser.parse_args() if not 1 <= args.digits <= 1000: parser.error("--digits must be between 1 and 1000") print(coordinates(args.digits), end="")