#!/usr/bin/env python3 """The twelve points of Comellas and Yebra (2002), page 7, from their closed form. x = 1 - (A**(2/3) + 6) / (6 * A**(1/3)), A = 27 + 3*sqrt(57), y = 2*x**2 - 3*x + 1/2. The paper states H12 >= x/4 + x*y/2 - x**2/2 = 0.032599, the smallest positive root of 64*t**3 + 80*t**2 + 28*t - 1 = 0 (0.0325988586... to ten decimals). Prints the twelve points `x y` with PRINT_DIGITS significant digits each. """ import sys from decimal import Decimal, getcontext getcontext().prec = 60 PRINT_DIGITS = 45 def cbrt(v): """Cube root of a nonnegative Decimal, Newton's method.""" if v == 0: return Decimal(0) guess = Decimal(repr(round(float(v) ** (1 / 3), 12))) three = Decimal(3) for _ in range(200): nxt = (2 * guess + v / (guess * guess)) / three if nxt == guess: return guess guess = nxt return guess def main(): sqrt57 = Decimal(57).sqrt() a = 27 + 3 * sqrt57 a13 = cbrt(a) a23 = a13 * a13 x = 1 - (a23 + 6) / (6 * a13) y = 2 * x * x - 3 * x + Decimal(1) / 2 # The paper's bound, and the cubic it should equal; assert both. h = x / 4 + x * y / 2 - x * x / 2 t = Decimal(1) for _ in range(200): # Newton on 64 t^3 + 80 t^2 + 28 t - 1 f = 64 * t**3 + 80 * t**2 + 28 * t - 1 fp = 192 * t**2 + 160 * t + 28 nxt = t - f / fp if nxt == t: break t = nxt assert abs(h - t) < Decimal("1e-50"), f"closed form mismatch: {h} vs {t}" points = [ (x, Decimal(0)), (1 - x, Decimal(0)), (Decimal(0), x), (Decimal(1), x), (Decimal(1) / 2, y), (y, Decimal(1) / 2), (1 - y, Decimal(1) / 2), (Decimal(1) / 2, 1 - y), (Decimal(0), 1 - x), (Decimal(1), 1 - x), (x, Decimal(1)), (1 - x, Decimal(1)), ] for px, py in points: print(f"{px:.{PRINT_DIGITS}f} {py:.{PRINT_DIGITS}f}") print(f"# x = {x}", file=sys.stderr) print(f"# y = {y}", file=sys.stderr) print(f"# x/4 + xy/2 - x^2/2 = {h}", file=sys.stderr) if __name__ == "__main__": main()