示例#1
0
def abeff_trianglebound(N, y, t, cond):
    sigma1 = 0.5 * (1 + y)
    sum1, sum2, sum3, sum5 = [0.0 for _ in range(4)]
    b1 = 1
    a1 = mp.power(N, -0.4)
    xN = 4 * mp.pi() * N * N - mp.pi() * t / 4.0
    xNp1 = 4 * mp.pi() * (N + 1) * (N + 1) - mp.pi() * t / 4.0
    delta = mp.pi() * y / (2 * (xN - 6 - (14 + 2 * y) / mp.pi())) + 2 * y * (
        7 + y) * mp.log(abs(1 + y + 1j * xNp1) / (4 * mp.pi)) / (xN * xN)
    expdelta = mp.exp(delta)
    for n in range(1, 30 * N + 1):
        nf = float(n)
        denom = mp.power(nf, sigma1 + (t / 4.0) * mp.log(N * N))
        common1 = mp.exp((t / 4.0) * mp.power(mp.log(nf), 2))
        common2 = common1 * mp.power(nf / N, y) * expdelta * mp.exp(
            t * y * mp.log(n) / (2 * (xN - 6)))
        bn, bn2, bn3, bn5 = [
            common1 * abs(cond[n][2 * i - 1]) for i in range(1, 5)
        ]
        an, an2, an3, an5 = [
            common2 * abs(cond[n][2 * i]) for i in range(1, 5)
        ]
        sum1 += (bn + an) / denom
        sum2 += (bn2 + an2) / denom
        sum3 += (bn3 + an3) / denom
        sum5 += (bn5 + an5) / denom
    return [N, expdelta] + [2 - j for j in [sum1, sum2, sum3, sum5]]
示例#2
0
def small_xi(n, y, cancel_keff=False):
    if cancel_keff:
        keff_factor = mp.mpf(1)
    else:
        keff_factor = (2 - mp.powm1(y, 2))
    return mp.power(-1, n) * keff_factor * (1 + n * y) / (
        mp.mpf(2) * mp.power(y, 3)) * mp.sqrt(mp.power((1 - y) / (1 + y), n))
示例#3
0
def abeff_lemmabound(N, y, t, cond):
    sigma1 = 0.5 * (1 + y)
    sum1, sum2, sum3, sum5 = [0.0 for _ in range(4)]
    b1 = 1
    a1 = mp.power(N, -0.4)
    xN = 4 * mp.pi() * N * N - mp.pi() * t / 4.0
    xNp1 = 4 * mp.pi() * (N + 1) * (N + 1) - mp.pi() * t / 4.0
    delta = mp.pi() * y / (2 * (xN - 6 - (14 + 2 * y) / mp.pi())) + 2 * y * (
        7 + y) * mp.log(abs(1 + y + 1j * xNp1) / (4 * mp.pi)) / (xN * xN)
    expdelta = mp.exp(delta)
    for n in range(2, 30 * N + 1):
        nf = float(n)
        denom = mp.power(nf, sigma1 + (t / 4.0) * mp.log(N * N))
        #print([cond[n][i] for i in range(1,9)])
        common1 = mp.exp((t / 4.0) * mp.power(mp.log(nf), 2))
        common2 = common1 * mp.power(nf / N, y)
        common3 = expdelta * (mp.exp(t * y * mp.log(n) / (2 * (xN - 6))) - 1)
        bn, bn2, bn3, bn5 = [common1 * cond[n][2 * i - 1] for i in range(1, 5)]
        an, an2, an3, an5 = [common2 * cond[n][2 * i] for i in range(1, 5)]
        en, en2, en3, en5 = an * common3, an2 * common3, an3 * common3, an5 * common3
        sum1 += (en + max(
            (1 - a1) * abs(bn + an) / (1 + a1), abs(bn - an))) / denom
        sum2 += (en2 + max(
            (1 - a1) * abs(bn2 + an2) / (1 + a1), abs(bn2 - an2))) / denom
        sum3 += (en3 + max(
            (1 - a1) * abs(bn3 + an3) / (1 + a1), abs(bn3 - an3))) / denom
        sum5 += (en5 + max(
            (1 - a1) * abs(bn5 + an5) / (1 + a1), abs(bn5 - an5))) / denom
    return [N, expdelta] + [1 - a1 - j for j in [sum1, sum2, sum3, sum5]]
def dipole_moment(charge, a):
    '''
    Purpose: to calculate the value of dipole moment

    Return: returns dipole moment calculated
    '''
    # Editing Value of charge as per the unit

    if charge[1] in ('Coulomb', 'C'):
        charge = charge[0]
    elif charge[1] in ('microCoulomb', 'uC'):
        charge = mp.fmul(charge[0], 10**(-6))
    elif charge[1] in ('milliCoulomb', 'mC'):
        charge = mp.fmul(charge[0], 10**(-3))
    elif charge[1] in ('electronCharge', 'eC'):
        charge = mp.fmul(charge[0], mp.fmul(1.60217646,
                                            mp.fmul(10,
                                                    -19)))  # 1.60217646⋅10-19
    elif charge[1] in ('nanoCoulomb', 'nC'):
        charge = mp.fmul(charge[0], mp.power(10, -10))
    elif charge[1] in ('picoCoulomb', 'pC'):
        charge = mp.fmul(charge[0], mp.power(10, -12))

    # Editing value of a as per the unit
    if a[1].lower() in ('meters', 'm'):
        a = a[0]
    elif a[1].lower() in ('centimeters', 'cm'):
        a = mp.fmul(a[0], 10**(-2))
    elif a[1].lower() in ('millimeters', 'mm'):
        a = mp.fmul(a[0], 10**(-3))
    elif a[1].lower() in ('angstroms', 'a', 'A'):
        a = mp.fmul(a[0], 10**(-10))

    return mp.fmul(charge, mp.fmul(2, a))
示例#5
0
def Ht_AFE_A(z, t):
    """
    This is the much more accurate approx functional eqn posted by Terry at
    https://terrytao.wordpress.com/2018/02/02/polymath15-second-thread-generalising-the-riemann-siegel-approximate-functional-equation/#comment-492182
    :param z: point at which H_t is computed
    :param t: the "time" parameter
    :return: the A part in Ht
    """
    z, t = mp.mpc(z), mp.mpc(t)
    s = (1 + 1j * z.real - z.imag) / 2
    tau = mp.sqrt(s.imag / (2 * mp.pi()))
    N = int(tau)

    A_pre = (1/16) * s * (s-1) \
            * mp.power(mp.pi(), -1*s/2) * mp.gamma(s/2)
    A_sum = 0.0
    for n in range(1, N + 1):
        if t.real > 0:
            A_sum += mp.exp(
                (t / 16) * mp.power(mp.log(
                    (s + 4) / (2 * mp.pi() * n * n)), 2)) / mp.power(n, s)
        else:
            A_sum += 1 / mp.power(n, s)

    return A_pre * A_sum
示例#6
0
def Ht_AFE_B(z, t):
    """
    This is the much more accurate approx functional eqn posted by Terry at
    https://terrytao.wordpress.com/2018/02/02/polymath15-second-thread-generalising-the-riemann-siegel-approximate-functional-equation/#comment-492182
    :param z: point at which H_t is computed
    :param t: the "time" parameter
    :return: the B part in Ht
    """
    z, t = mp.mpc(z), mp.mpc(t)
    s = (1 + 1j * z.real - z.imag) / 2
    tau = mp.sqrt(s.imag / (2 * mp.pi()))
    M = int(tau)

    B_pre = (1 / 16.0) * s * (s - 1) * mp.power(mp.pi(), 0.5 *
                                                (s - 1)) * mp.gamma(0.5 *
                                                                    (1 - s))
    B_sum = 0.0
    for m in range(1, M + 1):
        if t.real > 0:
            B_sum += mp.exp(
                (t / 16.0) * mp.power(mp.log(
                    (5 - s) / (2 * mp.pi() * m * m)), 2)) / mp.power(m, 1 - s)
        else:
            B_sum += 1 / mp.power(m, 1 - s)

    return B_pre * B_sum
示例#7
0
def _SolveForT0(A, B, t, tInterval):
    """There are four solutions to the equation (including complex ones). Here we use x instead of t0
    for convenience.
    """

    """
    SolveQuartic(2*A, -4*A*T + 2*B, 3*A*T**2 - 3*B*T, -A*T**3 + 3*B*T**2, -B*T**3)
    """
    if (Abs(A) < epsilon):
        def f(x):
            return Mul(number('2'), B)*x*x*x - Prod([number('3'), B, t])*x*x + Prod([number('3'), B, t, t])*x - Mul(B, mp.power(t, 3))
        sols = [mp.findroot(f, x0=0.5*t)]
    else:
        sols = SolveQuartic(Add(A, A),
                            Add(Prod([number('-4'), A, t]), Mul(number('2'), B)),
                            Sub(Prod([number('3'), A, t, t]), Prod([number('3'), B, t])),
                            Sub(Prod([number('3'), B, t, t]), Mul(A, mp.power(t, 3))),
                            Neg(Mul(B, mp.power(t, 3))))

    realSols = [sol for sol in sols if type(sol) is mp.mpf and sol in tInterval]
    if len(realSols) > 1:
        # I think this should not happen. We should either have one or no solution.
        raise NotImplementedError
    elif len(realSols) == 0:
        return None
    else:
        return realSols[0]
示例#8
0
 def v(sigma, t, a0, ksumcache):
     if (sigma >= 0):
         return 1 + 0.4 * mp.power(9, sigma) / a0 + 0.346 * mp.power(
             2, 3 * sigma / 2.0) / (a0**2)
     if (sigma < 0):
         K = int(mp.floor(-1 * sigma) + 3)
         return 1 + mp.power(0.9, mp.ceil(-1 * sigma)) * ksumcache[K]
示例#9
0
def abtoyx_e3(z, t):
    x = z.real
    xdash = x + mp.pi() * t / 4.0
    y = z.imag
    sigma1, sigma2 = 0.5 * (1 + y), 0.5 * (1 - y)
    s1, s2 = sigma1 + 0.5j * xdash, sigma2 + 0.5j * xdash
    N = int(mp.sqrt(0.25 * x / mp.pi()))
    sum1_L, sum1_R = 0.0, 0.0
    factor2 = 1 - 1 / mp.power(2.0, s1 + (t / 4.0) * mp.log(N * N / 2.0))
    factor3 = 1 - 1 / mp.power(3.0, s1 + (t / 4.0) * mp.log(N * N / 2.0))
    factorN = mp.power(N, -0.4)
    for n in range(1, N + 1):
        n = float(n)
        sum1_L += mp.power(n, -1 * s1 - (t / 4.0) * mp.log(N * N / n))
        sum1_R += mp.power(n, -1 * s2 - (t / 4.0) * mp.log(N * N / n))
    sum1_R = sum1_R * factorN
    sum12_L, sum12_R = sum1_L * factor2, sum1_R * factor2
    sum123_L, sum123_R = sum12_L * factor3, sum12_R * factor3
    absum1_L, absum1_R, absum12_L, absum12_R, absum123_L, absum123_R = abs(
        sum1_L), abs(sum1_R), abs(sum12_L), abs(sum12_R), abs(sum123_L), abs(
            sum123_R)
    abdiff1, abdiff12, abdiff123 = absum1_L - absum1_R, absum12_L - absum12_R, absum123_L - absum123_R
    return [
        sum1_L, sum1_R, absum1_L, absum1_R, abdiff1, sum12_L, sum12_R,
        absum12_L, absum12_R, abdiff12, sum123_L, sum123_R, absum123_L,
        absum123_R, abdiff123
    ]
示例#10
0
def _SolveForT0(A, B, t, tInterval):
    """There are four solutions to the equation (including complex ones). Here we use x instead of t0
    for convenience.
    """
    """
    SolveQuartic(2*A, -4*A*T + 2*B, 3*A*T**2 - 3*B*T, -A*T**3 + 3*B*T**2, -B*T**3)
    """
    if (Abs(A) < epsilon):

        def f(x):
            return Mul(number('2'), B) * x * x * x - Prod(
                [number('3'), B, t]) * x * x + Prod(
                    [number('3'), B, t, t]) * x - Mul(B, mp.power(t, 3))

        sols = [mp.findroot(f, x0=0.5 * t)]
    else:
        sols = SolveQuartic(
            Add(A, A), Add(Prod([number('-4'), A, t]), Mul(number('2'), B)),
            Sub(Prod([number('3'), A, t, t]), Prod([number('3'), B, t])),
            Sub(Prod([number('3'), B, t, t]), Mul(A, mp.power(t, 3))),
            Neg(Mul(B, mp.power(t, 3))))

    realSols = [
        sol for sol in sols if type(sol) is mp.mpf and sol in tInterval
    ]
    if len(realSols) > 1:
        # I think this should not happen. We should either have one or no solution.
        raise NotImplementedError
    elif len(realSols) == 0:
        return None
    else:
        return realSols[0]
示例#11
0
def F0(s):
    # works only for x > 14 approx due to the sqrt(x/4PI) factor
    term1 = mp.power(PI,-1*s/2)*mp.gamma((s+4)/2)
    x=2*s.imag
    N = int(mp.sqrt(x/(4*PI)))
    running_sum=0
    for n in range(1,N+1):
        running_sum += 1/mp.power(n,s)
    return term1*running_sum
示例#12
0
def RSZ_upto_c1(x):
    x = mp.mpf(x.real)
    tau = mp.sqrt(x/(2*PI))
    N = int(tau.real)
    p = tau-N
    running_sum=0
    for n in range(1,N+1):
        running_sum += mp.cos(RStheta(x) - x*mp.log(n))/mp.sqrt(n)
    return (2*running_sum + mp.power(-1,N-1)*mp.power(tau,-0.5)*(c0(p) - (1/tau)*c1(p))).real
示例#13
0
def Ft(s,t):
    # works only for x > 14 approx due to the sqrt(x/4PI) factor
    term1 = mp.power(PI,-1*s/2)*mp.gamma((s+4)/2)
    x=2*s.imag
    N = int(mp.sqrt(x/(4*PI)))
    running_sum=0
    for n in range(1,N+1):
        running_sum += mp.exp((t/16)*mp.power(mp.log((s+4)/(2*PI*n*n)),2))/mp.power(n,s) # main eqn 
    return term1*running_sum
示例#14
0
def phi_decay(u,n_max=100):
    running_sum=0
    u=mp.mpc(u)
    for n in range(1,n_max+1):
        term1=2*PI_sq*mp.power(n,4)*mp.exp(9*u) - 3*PI*mp.power(n,2)*mp.exp(5*u)
        term2=mp.exp(-1*PI*mp.power(n,2)*mp.exp(4*u))
        running_sum += term1*term2
        #print n,term1, term2, running_sum
    return running_sum
示例#15
0
def F0(s):
    # works only for x > 14 approx due to the sqrt(x/4PI) factor
    term1 = mp.power(mp.pi(), -0.5 * s) * mp.gamma(0.5 * (s + 4))
    x = 2 * s.imag
    N = int(mp.sqrt(x / (4 * mp.pi())))
    running_sum = 0
    for n in range(1, N + 1):
        running_sum += 1 / mp.power(n, s)
    return term1 * running_sum
示例#16
0
def big_xi(n, y, cancel_keff=False):
    if cancel_keff:
        keff_factor = mp.mpf(1)
    else:
        keff_factor = (2 - mp.powm1(y, 2))
    poly_part = 3 + 3 * n * y + (3 * (n * n - 1)) * mp.power(
        y, 2) + (2 * n * (n * n - 1)) * mp.power(y, 3)
    return mp.power(-1, n) * keff_factor / (
        mp.mpf(12) * mp.power(y, 5)) * mp.sqrt(mp.power(
            (1 - y) / (1 + y), n)) * poly_part
示例#17
0
def two_stars(t,rho,NMAX):
    # compute Hermite polynomials 
    Hm1 = (mp.mpf(1)-Phi(t))/phi(t)
    H = [hermite(N,t) for N in range(NMAX+1)] + [Hm1]
    # compute partial sum (up to NMAX)
    ans = mp.mpf(0)
    for N in range(NMAX+1):
        ans = ans + mp.power(rho,N) * mp.power(H[N-1],2) / mp.factorial(N)
    ans = ans*mp.power(phi(t),2)
    return( ans )
示例#18
0
def Ht_Effective(z, t):
    """
    This uses the effective approximation of H_t from Terry's blog
    :param z: point at which H_t is computed
    :param t: the "time" parameter
    :return: H_t as a sum of two terms that are analogous to A and B, but now also with an efffective error bound (returned as percentage of |H_t|
    """
    z, t = mp.mpc(z), mp.mpc(t)
    sigma = (1 - z.imag) / 2.0
    T = (z.real) / 2.0
    Tdash = T + t * mp.pi() / 8.0
    s1 = sigma + 1j * T
    s2 = 1 - sigma + 1j * T
    N = int((mp.sqrt(Tdash / (2 * mp.pi()))).real)

    alph1 = alpha1(s1)
    alph2 = alpha1(s2).conjugate()
    A0_expo = (t / 4.0) * alph1 * alph1
    B0_expo = (t / 4.0) * alph2 * alph2
    H01_est1 = H01(s1)
    H01_est2 = H01(s2).conjugate()

    #begin main estimate block
    A0 = mp.exp(A0_expo) * H01_est1
    B0 = mp.exp(B0_expo) * H01_est2
    A_sum = 0.0
    B_sum = 0.0
    for n in range(1, N + 1):
        A_sum += 1 / mp.power(n, s1 + (t / 2.0) * alph1 -
                              (t / 4.0) * mp.log(n))
        B_sum += 1 / mp.power(
            n, 1 - s1 + (t / 2.0) * alph2 - (t / 4.0) * mp.log(n))
    A = A0 * A_sum
    B = B0 * B_sum
    H = (A + B) / 8.0
    #end main estimate block

    #begin error block
    A0_err_expo = (t / 4.0) * (abs(alph1)**2)  #A0_expo.real may also work
    B0_err_expo = (t / 4.0) * (abs(alph2)**2)  #B0_expo.real may also work
    epserr_1 = mp.exp(A0_err_expo) * abs(H01_est1) * abs(eps_err(s1, t)) / (
        (T - 3.33) * 8.0)
    epserr_2 = mp.exp(B0_err_expo) * abs(H01_est2) * abs(eps_err(s2, t)) / (
        (T - 3.33) * 8.0)
    epserr = epserr_1 + epserr_2

    C0 = mp.sqrt(mp.pi()) * mp.exp(-1 * (t / 64.0) * (mp.pi()**2)) * mp.power(
        Tdash, 1.5) * mp.exp(-1 * mp.pi() * T / 4.0)
    C = C0 * vwf_err(s1, t) / 8.0
    toterr = epserr + C
    #print(epserr_1, epserr_2, C0, vwf_err(s1, t), C, toterr.real)
    #end error block

    if z.imag == 0: return (H.real, toterr.real / abs(H.real))
    else: return (H, toterr.real / abs(H))
示例#19
0
def Ft(s, t):
    # works only for x > 14 approx due to the sqrt(x/4PI) factor
    term1 = mp.power(mp.pi(), -0.5 * s) * mp.gamma(0.5 * (s + 4))
    x = 2 * s.imag
    N = int(mp.sqrt(x / (4 * mp.pi())))
    running_sum = 0
    for n in range(1, N + 1):
        running_sum += mp.exp(
            (t / 16.0) * mp.power(mp.log(
                (s + 4) /
                (2 * mp.pi() * n * n)), 2)) / mp.power(n, s)  # main eqn
    return term1 * running_sum
示例#20
0
def SolveQuartic(a, b, c, d, e):
    """
    SolveQuartic solves a quartic (fouth order) equation of the form
            ax^4 + bx^3 + cx^2 + dx + e = 0.
    For the detail of formulae presented here, see https://en.wikipedia.org/wiki/Quartic_function
    """
    # Check types
    if type(a) is not mp.mpf:
        a = mp.mpf("{:.15e}".format(a))
    if type(b) is not mp.mpf:
        b = mp.mpf("{:.15e}".format(b))
    if type(c) is not mp.mpf:
        c = mp.mpf("{:.15e}".format(c))
    if type(d) is not mp.mpf:
        d = mp.mpf("{:.15e}".format(d))
    if type(e) is not mp.mpf:
        e = mp.mpf("{:.15e}".format(e))

    """
    # Working code (more readable but probably less precise)
    p = (8*a*c - 3*b*b)/(8*a*a)
    q = (b**3 - 4*a*b*c + 8*a*a*d)/(8*a*a*a)
    delta0 = c*c - 3*b*d + 12*a*e
    delta1 = 2*(c**3) - 9*b*c*d + 27*b*b*e + 27*a*d*d - 72*a*c*e
    Q = mp.nthroot(pointfive*(delta1 + mp.sqrt(delta1*delta1 - 4*mp.power(delta0, 3))), 3)
    S = pointfive*mp.sqrt(-mp.fdiv(mp.mpf('2'), mp.mpf('3'))*p + (one/(3*a))*(Q + delta0/Q))

    x1 = -b/(4*a) - S + pointfive*mp.sqrt(-4*S*S - 2*p + q/S)
    x2 = -b/(4*a) - S - pointfive*mp.sqrt(-4*S*S - 2*p + q/S)
    x3 = -b/(4*a) + S + pointfive*mp.sqrt(-4*S*S - 2*p - q/S)
    x4 = -b/(4*a) + S - pointfive*mp.sqrt(-4*S*S - 2*p - q/S)
    """
    p = mp.fdiv(Sub(Prod([number('8'), a, c]), Mul(number('3'), mp.power(b, 2))), Mul(number('8'), mp.power(a, 2)))
    q = mp.fdiv(Sum([mp.power(b, 3), Prod([number('-4'), a, b, c]), Prod([number('8'), mp.power(a, 2), d])]), Mul(8, mp.power(a, 3)))
    delta0 = Sum([mp.power(c, 2), Prod([number('-3'), b, d]), Prod([number('12'), a, e])])
    delta1 = Sum([Mul(2, mp.power(c, 3)), Prod([number('-9'), b, c, d]), Prod([number('27'), mp.power(b, 2), e]), Prod([number('27'), a, mp.power(d, 2)]), Prod([number('-72'), a, c, e])])
    Q = mp.nthroot(Mul(pointfive, Add(delta1, mp.sqrt(Add(mp.power(delta1, 2), Mul(number('-4'), mp.power(delta0, 3)))))), 3)
    S = Mul(pointfive, mp.sqrt(Mul(mp.fdiv(mp.mpf('-2'), mp.mpf('3')), p) + Mul(mp.fdiv(one, Mul(number('3'), a)), Add(Q, mp.fdiv(delta0, Q)))))

    # log.debug("p = {0}".format(mp.nstr(p, n=_prec)))
    # log.debug("q = {0}".format(mp.nstr(q, n=_prec)))
    # log.debug("delta0 = {0}".format(mp.nstr(delta0, n=_prec)))
    # log.debug("delta1 = {0}".format(mp.nstr(delta1, n=_prec)))
    # log.debug("Q = {0}".format(mp.nstr(Q, n=_prec)))
    # log.debug("S = {0}".format(mp.nstr(S, n=_prec)))

    x1 = Sum([mp.fdiv(b, Mul(number('-4'), a)), Neg(S), Mul(pointfive, mp.sqrt(Sum([Mul(number('-4'), mp.power(S, 2)), Mul(number('-2'), p), mp.fdiv(q, S)])))])
    x2 = Sum([mp.fdiv(b, Mul(number('-4'), a)), Neg(S), Neg(Mul(pointfive, mp.sqrt(Sum([Mul(number('-4'), mp.power(S, 2)), Mul(number('-2'), p), mp.fdiv(q, S)]))))])
    x3 = Sum([mp.fdiv(b, Mul(number('-4'), a)), S, Mul(pointfive, mp.sqrt(Sum([Mul(number('-4'), mp.power(S, 2)), Mul(number('-2'), p), Neg(mp.fdiv(q, S))])))])
    x4 = Sum([mp.fdiv(b, Mul(number('-4'), a)), S, Neg(Mul(pointfive, mp.sqrt(Sum([Mul(number('-4'), mp.power(S, 2)), Mul(number('-2'), p), Neg(mp.fdiv(q, S))]))))])
    
    return [x1, x2, x3, x4]
示例#21
0
def abtoybound(N, y, t, cond):
    sigma1, sigma2 = 0.5 * (1 + y), 0.5 * (1 - y)
    sum1_L, sum1_R, sum12_L, sum12_R, sum123_L, sum123_R, sum1235_L, sum1235_R = [
        0.0 for _ in range(8)
    ]
    ddxsum1_L, ddxsum1_R, ddxsum12_L, ddxsum12_R, ddxsum123_L, ddxsum123_R, ddxsum1235_L, ddxsum1235_R = [
        0.0 for _ in range(8)
    ]
    factorN = 1 / mp.power(N, 0.4)
    for n in range(1, 30 * N + 1):
        nf = float(n)
        denom1 = mp.power(nf, sigma1 + (t / 4.0) * mp.log(N * N / nf))
        denom2 = mp.power(nf, sigma2 + (t / 4.0) * mp.log(N * N / nf))
        term1_L = abs(cond[n][1] / denom1)
        term1_R = abs(cond[n][2] / denom2)
        sum1_L += term1_L
        sum1_R += term1_R
        ddxsum1_L += mp.log(n) * term1_L
        ddxsum1_R += mp.log(n) * term1_R
        term12_L = abs(cond[n][3] / denom1)
        term12_R = abs(cond[n][4] / denom2)
        sum12_L += term12_L
        sum12_R += term12_R
        ddxsum12_L += mp.log(n) * term12_L
        ddxsum12_R += mp.log(n) * term12_R
        term123_L = abs(cond[n][5] / denom1)
        term123_R = abs(cond[n][6] / denom2)
        sum123_L += term123_L
        sum123_R += term123_R
        ddxsum123_L += mp.log(n) * term123_L
        ddxsum123_R += mp.log(n) * term123_R
        term1235_L = abs(cond[n][7] / denom1)
        term1235_R = abs(cond[n][8] / denom2)
        sum1235_L += term1235_L
        sum1235_R += term1235_R
        ddxsum1235_L += mp.log(n) * term1235_L
        ddxsum1235_R += mp.log(n) * term1235_R
    sum1_L, sum12_L, sum123_L, sum1235_L = sum1_L - 1, sum12_L - 1, sum123_L - 1, sum1235_L - 1
    sum1_R, sum12_R, sum123_R, sum1235_R = sum1_R * factorN, sum12_R * factorN, sum123_R * factorN, sum1235_R * factorN
    ddxsum1_L, ddxsum12_L, ddxsum123_L, ddxsum1235_L = 0.5 * ddxsum1_L, 0.5 * ddxsum12_L, 0.5 * ddxsum123_L, 0.5 * ddxsum1235_L
    ddxsum1_R, ddxsum12_R, ddxsum123_R, ddxsum1235_R = 0.5 * ddxsum1_R * factorN, 0.5 * ddxsum12_R * factorN, 0.5 * ddxsum123_R * factorN, 0.5 * ddxsum1235_R * factorN

    abdiff1, ddxsum1 = 1 - sum1_L - sum1_R, ddxsum1_L + ddxsum1_R
    abdiff12, ddxsum12 = 1 - sum12_L - sum12_R, ddxsum12_L + ddxsum12_R
    abdiff123, ddxsum123 = 1 - sum123_L - sum123_R, ddxsum123_L + ddxsum123_R
    abdiff1235, ddxsum1235 = 1 - sum1235_L - sum1235_R, ddxsum1235_L + ddxsum1235_R
    return [
        sum1_L, sum1_R, abdiff1, ddxsum1_L, ddxsum1_R, ddxsum1, sum12_L,
        sum12_R, abdiff12, ddxsum12_L, ddxsum12_R, ddxsum12, sum123_L,
        sum123_R, abdiff123, ddxsum123_L, ddxsum123_R, ddxsum123, sum1235_L,
        sum1235_R, abdiff1235, ddxsum1235_L, ddxsum1235_R, ddxsum1235
    ]
示例#22
0
def BoysValue_Asymptotic(n, x):
    F = []

    if x == mp.mpf("0"):
        for i in range(0, n+1):
            F.append(mp.mpf(1.0)/(mp.mpf(2.0*i+1)))
    else:
        for i in range(0, n+1):
            val = mp.sqrt( mp.pi() / mp.power(x, 2*i+1) )
            val *= ( mp.fac2(2*i-1) / mp.power("2", i+1) )
            F.append(val)

    return F
示例#23
0
 def v(sigma, s, t):
     T0 = s.imag
     T0dash = T0 + mp.pi() * t / 8.0
     a0 = mp.sqrt(T0dash / (2 * mp.pi()))
     if (sigma >= 0):
         return 1 + 0.4 * mp.power(9, sigma) / a0 + 0.346 * mp.power(
             2, 3 * sigma / 2.0) / (a0**2)
     if (sigma < 0):
         K = int(mp.floor(-1 * sigma) + 3)
         ksum = 0.0
         for k in range(1, K + 2):
             ksum += mp.power(1.1 / a0, k) * mp.gamma(mp.mpf(k) / 2.0)
         return 1 + mp.power(0.9, mp.ceil(-1 * sigma)) * ksum
示例#24
0
def abtoy_custom_mollifier(N, D, divisors):
    sharpsum = 0.0
    a1 = mp.power(N, -0.4)
    divisors = [float(i) for i in divisors]
    for n in range(2, D * N + 1):
        bnp, anp = 0.0, 0.0
        nf = float(n)
        denom = mp.power(nf, 0.7 + 0.1 * mp.log(N * N))
        for d in divisors:
            common = deltaN(n, d * N) * divdelta(n, d) * lcoeff(d)
            bnp += common * bn(nf / d)
            anp += common * an(nf / d, N)
        sharpsum += max(abs(bnp + anp) / (1 + a1),
                        abs(bnp - anp) / (1 - a1)) / denom
    return [N, sharpsum]
示例#25
0
    def min_value(self, denorm=True):
        """
        Return the smallest possible value.

        If `denorm` is True, include denormalized values.
        """
        return mp.power(2, self.min_exp(denorm))
示例#26
0
文件: util.py 项目: fritzr/pyfp
def next_power(x, n=2):
    """
    Return the value sign(x) * n^k such that n^k is the smallest value > |x|
    for integer k.
    """
    x = abs(x)
    return mp.power(n, mp.floor(mp.log(x, n)) + 1)
示例#27
0
def triangles(t,rho,NMAX):
    # compute Hermite polynomials and factorials
    Hm1 = (mp.mpf(1)-Phi(t))/phi(t)
    H = [hermite(N,t) for N in range(NMAX+1)] + [Hm1]
    factorial = [mp.factorial(i) for i in range(NMAX+1)]
    # compute partial sum (up to NMAX)
    ans = mp.mpf(0)
    for N in range(NMAX+1):
        rhoN = mp.power(rho,N)
        for i in range(N+1):
            for j in range(N+1-i):
                k = N-i-j
                ans = ans + rhoN * ( (H[N-i-1]/factorial[i]) *
                        (H[N-j-1]/factorial[j]) * (H[N-k-1]/factorial[k]))
    ans = ans*mp.power(phi(t),3)
    return(ans)
示例#28
0
文件: util.py 项目: fritzr/pyfp
def floor_power(x, n=2):
    """
    Return the value sign(x) * n^k such that n^k is the largest value <= |x|
    for integer k.
    """
    x = abs(x)
    return mp.power(n, mp.floor(mp.log(x, n)))
示例#29
0
def pi(i: int) -> mp.mpf:
    if i <= 0:
        return 0
    n = mp.mpf('3')
    r = mp.mpf('1')
    c = mp.mpf('1')
    for j in range(i):
        n = mp.mpf('2') * n
        old_r = c
        r = old_r / mp.mpf('2')
        a = mp.sqrt(mp.mpf('1') - mp.power(r, 2))
        d = mp.mpf('1') - a
        c = mp.sqrt(mp.power(d, 2) + mp.power(r, 2))
        P = n * old_r
        res = P / mp.mpf('2')
    return res
示例#30
0
    def compress(self, time_series: List[int]) -> int:
        if time_series is None or len(time_series) == 0:
            return 0

        one_letter_probability = mp.mpf(1.0) / (self._alphabet_max_symbol -
                                                self._alphabet_min_symbol + 1)
        series_probability = mp.power(one_letter_probability, len(time_series))
        return int(mp.ceil(-mp.log(series_probability, 2)))
示例#31
0
def abtoy_arb_coeff(ldcoeffs):
    global N, D, divisors
    ldcoeffs = np.insert(ldcoeffs, 0, 1)
    sharpsum = 0.0
    a1 = mp.power(N, -0.4)
    divisors = [float(i) for i in divisors]
    for n in range(2, D * N + 1):
        bnp, anp = 0.0, 0.0
        nf = float(n)
        denom = mp.power(nf, 0.7 + 0.1 * mp.log(N * N))
        for i, d in enumerate(divisors):
            common = deltaN(n, d * N) * divdelta(n, d) * ldcoeffs[i]
            bnp += common * bn(nf / d)
            anp += common * an(nf / d, N)
        sharpsum += max(abs(bnp + anp) / (1 + a1),
                        abs(bnp - anp) / (1 - a1)) / denom
    print(ldcoeffs, sharpsum)
    return float(sharpsum)
示例#32
0
def phi_decay(u, n_max=100):
    """
    Computes Phi(u) in Terry' blog at
    https://terrytao.wordpress.com/2018/02/02/polymath15-second-thread-generalising-the-riemann-siegel-approximate-functional-equation/
    :param u: input complex number
    :param n_max: upper limit for summation. It has to be a positive
    integer
    :return: Phi(u)
    """
    running_sum = 0
    u = mp.mpc(u)
    for n in range(1, n_max + 1):
        term1 = 2 * mp.pi() * mp.pi() * mp.power(n, 4) * mp.exp(9*u) \
                - 3 * mp.pi() * mp.power(n, 2) * mp.exp(5*u)
        term2 = mp.exp(-1 * mp.pi() * mp.power(n, 2) * mp.exp(4 * u))
        running_sum += term1 * term2

    return running_sum
示例#33
0
文件: composite.py 项目: wyao09/cs124
def composite():
    for i in range(0, k):
        a = random.randint(2,100)#n-2)
        x = mp.fmod(mp.power(a,d),n)
        if x != 1 and x != n-1:#
            comp = True
            for r in range(1, s):
                x = mp.fmod(mp.power(x,2),n)
                if x == 1:#
                    return a, s, d, r
                if x == n-1:#
                    comp = False
                    break
                """
            if comp:    
                return a, s, d
            else:
                print 'ha'
                """
    return -1, s, d
示例#34
0
 def f(x):
     return Mul(number('2'), B)*x*x*x - Prod([number('3'), B, t])*x*x + Prod([number('3'), B, t, t])*x - Mul(B, mp.power(t, 3))
示例#35
0
from mpmath import mp
from jinja2 import Environment, FileSystemLoader

class str_item:
  def __init__(self, n, l):
    self.number = n
    self.log10 = l[0:2] + "\,".join([l[i:i+3] for i in range(2, len(l), 3)])

if __name__ == "__main__":
  input_dps = 5
  output_dps = 60
  rows_per_page = 50
  mp.dps = output_dps + 10
  
  table_raw = []
  for number in mp.arange(1.0, 10.0, mp.power(10, -(input_dps-1))):
    table_raw.append([number, mp.log10(number)])
  
  table_str = []
  table_str = [str_item(mp.nstr(row[0], input_dps), mp.nstr(row[1], output_dps)) for row in table_raw]

  pages = [table_str[i:i+rows_per_page] for i in range(0, len(table_str), rows_per_page)]
  
  latex_renderer = Environment(
    block_start_string = "%{",
    block_end_string = "%}",
    line_statement_prefix = "%#",
    variable_start_string = "%{{",
    variable_end_string = "%}}",
    loader = FileSystemLoader("."))
  template = latex_renderer.get_template("template.tex")
示例#36
0
文件: composite.py 项目: wyao09/cs124
    print "usage: composite [odd integer to be tested] [parameter for accuracy]"
    print "output with n-1 as 2^s * d: (witness, s, d)"
    sys.exit()

n = int(sys.argv[1]) # odd integer to be tested for primality
"""
s = int(sys.argv[2]) # n-1 as 2^s*d
d = mp.mpf(sys.argv[3])
"""
k = int(sys.argv[2]) # parameter that determines the accuracy of the test
s = 0
d = 0

# find s and d first
for i in range(0, 30):
    x = mp.fdiv((n-1), mp.power(2,i))
    if x - long(x) == 0:
        s = i
        d = int(x)

def composite():
    for i in range(0, k):
        a = random.randint(2,100)#n-2)
        x = mp.fmod(mp.power(a,d),n)
        if x != 1 and x != n-1:#
            comp = True
            for r in range(1, s):
                x = mp.fmod(mp.power(x,2),n)
                if x == 1:#
                    return a, s, d, r
                if x == n-1:#