# Ordinary reciprocal-cubic Mahler measure at one real argument.
# Recompute radicals inside a callable, for example lambda: 4+2*mp.sqrt(5).
import mpmath as mp

def g(argument, working=140):
    with mp.workdps(working):
        k = mp.mpf(argument() if callable(argument) else argument)
        if not mp.isfinite(k):
            raise ValueError('A finite real argument is required.')
        if k == 0:
            return mp.mpf(0)
        edges = [mp.mpf(0), mp.pi/2]
        if -1 <= k < 0:
            edges += [mp.acos((1+s*mp.sqrt(1+k))/2) for s in [-1, 1]]
        elif 0 < k < 8:
            edges += [mp.acos((mp.sqrt(1+k)-1)/2)]
        edges = sorted(set(edges))
        pieces = []
        for left, right in zip(edges, edges[1:]):
            c = mp.cos((left+right)/2)
            active = abs(k-4*c*c) >= 4*c
            def integrand(theta):
                c = mp.cos(theta)
                if not active:
                    return mp.log(2*c)
                b = abs(k-4*c*c)
                return mp.log((b+mp.sqrt(max(0, b*b-16*c*c)))/2)
            result, error = mp.quad(integrand, [left, right],
                                    error=True, maxdegree=9)
            if not mp.isfinite(result) or error >= mp.power(10, -working+15):
                raise ArithmeticError('Quadrature did not converge.')
            pieces.append(result)
        return 2*mp.fsum(pieces)/mp.pi

low = g(4, 140)
high = g(4, 190)
with mp.workdps(200):
    assert abs(low-high) < mp.mpf('1e-115')*max(1, abs(high))
    print(mp.nstr(high, 100))
# Precision agreement and quadrature estimates are not certified bounds.
