# formdegree.py -- algebraic degree of bistochastic forms: refine a form to high precision, then find the minimal # polynomial (LLL) of a random rational combination of the real and imaginary parts of all multipliers. import numpy as np, random, time from decimal import Decimal as D, getcontext from lll import minpoly from hpform import refine def hp_entries(E, q, prec): """H_ij = zeta_q^E_ij as Decimal (re, im) lists, to precision prec.""" getcontext().prec=prec+40 import math # cos/sin of 2 pi k/q via Decimal Taylor series pi=D(0); # Machin: pi = 16 atan(1/5) - 4 atan(1/239) def atan_inv(x): x=D(x); t=1/x; s=t; x2=x*x; k=1; sign=-1 while True: t/=x2; term=t/(2*k+1) if term< D(10)**(-prec-30): break s+=sign*term; sign=-sign; k+=1 return s pi=16*atan_inv(5)-4*atan_inv(239) def cs(k): x=2*pi*k/q; c=D(1); s=x; tc=D(1); ts=x; n=1 while True: tc=-tc*x*x/((2*n-1)*(2*n)); ts=-ts*x*x/((2*n)*(2*n+1)); n+=1 if abs(tc)