from mpmath import mp

def Z(t, n_terms=1000):
    """
    Z(t) ≈ Σ cos(π/4 - t*log(n)) / √n  for n = 1 to n_terms
    High precision using mpmath.
    """
    t = mp.mpf(t)
    result = mp.mpf(0)
    for n in range(1, n_terms + 1):
        result += mp.cos(mp.pi/4 - t * mp.log(n)) / mp.sqrt(n)
    return 2 * result

# Higher precision context
mp.dps = 50

# Verify
print(f"Z(14.134725) = {Z(14.134725, n_terms=1000)}")
print(f"Z(21.022040) = {Z(21.022040, n_terms=1000)}")
print(f"Z(30.424826) = {Z(30.424826, n_terms=1000)}")
print(f"Z(1.936803) = {Z(1.936803, n_terms=31)}")
print(f"Z(1.936804) = {Z(1.936804, n_terms=31)}")
print(f"Z(1.936805) = {Z(1.936805, n_terms=31)}")
print(mp.exp(1))
