from mpmath import mp
def contacts(k):
points=[mp.mpf(0),mp.mpf(1),mp.sqrt(mp.mpf(1)/2)]
if k<=3:
d=mp.sqrt(max(mp.mpf(0),9-k*k))
points.extend([mp.sqrt((3-d)/8),mp.sqrt((3+d)/8)])
kap=16/(3*mp.sqrt(3))
if 0<k<=kap:
alpha=mp.asin(min(mp.mpf(1),k/kap))/3
points.extend([2/mp.sqrt(3)*mp.sin(alpha),2/mp.sqrt(3)*mp.sin(mp.pi/3-alpha)])
return sorted(set(mp.asin(t) for t in points if 0<=t<=1))
def mahler_at(k):
if k==0:
return 2/mp.pi*mp.quad(lambda a:mp.log(3-4*mp.sin(a)**2),[0,mp.pi/4])
bounds=contacts(k)
def numerator(a):
t=mp.sin(a);D=k*k-48*t*t+64*t**4
if D<0:
return mp.log(2*t)+max(mp.mpf(0),mp.log(3-4*t*t))
large=(k+mp.sqrt(D))/2
small=abs(2*t*(3-4*t*t)/large)
return mp.log(max(2*t,large))+mp.log(max(mp.mpf(1),small))
total=mp.mpf(0)
for left,right in zip(bounds,bounds[1:]):
if right-left<mp.eps:continue
def mapped(u):
if u==0 or u==mp.pi/2:return mp.mpf(0)
a=left+(right-left)*mp.sin(u)**2
if a==0:return mp.mpf(0)
return numerator(a)*(right-left)*mp.sin(2*u)
total+=mp.quad(mapped,[0,mp.pi/4,mp.pi/2])
return 2*total/mp.pi
def r_elliptic(argument, working=140):
with mp.workdps(working):
k=mp.mpf(argument() if callable(argument) else argument)
if not mp.isfinite(k) or k<0:
raise ValueError('A finite nonnegative real k is required.')
return mahler_at(k)
for working in (140,180):
print(mp.nstr(r_elliptic(lambda:mp.sqrt(2),working),105))
# Default coverage: sqrt(n), 0<=n<=36, plus 16/(3*sqrt(3)),
# in increasing k, positive roots, square cases simplified to integers.
The generator applies Jensen's formula to the quadratic torus presentation, retaining both roots. It splits at discriminant zeros and unit-circle contacts and uses a sine-squared endpoint substitution. Quadratures at 140 and 180 decimal digits agree before retaining 100 significant digits. Exact algebraic inputs are recomputed as Sage real intervals at each precision and both endpoints are evaluated numerically. These sensitivity and agreement intervals do not certify quadrature error.
All 38 values were checked at 135 decimal digits by Jensen integration of the original monic cubic with all three roots, separately derived reciprocal-resultant contacts and a cubic endpoint map. This shares Jensen's theorem and mpmath with the primary method. The factorization at 3 was also checked using the source's Bloch–Wigner dilogarithm expression and a Hurwitz-zeta character sum for the line factor. A perturbation of $10^{-90}$ at 3 is rejected. Exact coefficient expansion checks the sign convention, torus transformation, factorizations, contact resultant and elliptic-model discriminant. The displayed complete-elliptic-integral formula was checked at all 28 selected inputs in its range. Reproducible generator, checks, results, software versions and argument selection are attached. These calculations remain heuristic quadrature evidence.