def integrandnew(E,mx): y=E/mx if y<1: S1=2-y**2 + 2*y*m.log((mp-mu)*y/(mp-2*mu))-(mp**2 - 2*mu**2)*y/((mp-mu)*(mp - 2*mu)) S2=2*mu**2*(2-m.log(mu**2*y**2/((mp-2*mu)**2*(1-y))))-3*mu*mp*(4./3.-m.log(mu*y**2*(mp-mu)/((mp-2*mu)**2*(1-y))))+mp**2*(1-m.log(y**2*(mp-mu)**2/((mp-2*mu)**2*(1-y)))) const=E*10**(-25)*10**(18)*(1/(0.001*mx))**2*(1/(8.*m.pi)) return const*(2*alpha/(m.pi*y*mx))*(y**2 + 2*y*(polylog((mp-2*mu)/(mp-mu))-polylog(y))+(2-y**2)*m.log(1-y)+(m.log(mp**2/mu**2)-1)*S1-y*S2/(2*mu**2 - 3*mp*mu+mp**2)) else: return 0.
def gf_plc(exponent: float, cutoff: float) -> GF: '''Return the generating function of the powerlaw-with-cutoff degree distribution given its exponent and cutoff, as generated by :class:`epydemic.PLCNetwork`. :param exponent: the exponent of the distribution :param cutoff: the cutoff :returns: the generating function''' return gf_from_series(lambda x: polylog(exponent, x * exp(-1 / cutoff)) / polylog(exponent, exp(-1 / cutoff)))
def Gamma_GO(M, ast, m):# Geometric optics limit GM = GCF * (M/GeV_in_g) # in GeV^-1 TKBH = TBH(M, ast) zBH = m/TKBH In = - zBH * polylog(2, -np.exp(-zBH)) - polylog(3, -np.exp(-zBH))# DM emission rate including greybody factors return 2. * (27/(1024. * np.pi**4 * GM)) * In
def GammaRH(M, MRH): GM = GCF * M / GeV_in_g # GM in GeV**-1 al = GM * MRH # Dimensionless gravitational coupling zBH = 8. * np.pi * al In1 = float(zBH * mpmath.polylog(2, -np.exp(-zBH))) In2 = float(mpmath.polylog(3, -np.exp(-zBH))) In = -In1 - In2 return (gnu / (gf + gs + gv + gnu)) * (27 / (256. * np.pi**3 * GM)) * In #
def IntegralCurve2(S_star, S_L): ic1 = (a / b) * ((Const2) * np.log( (alpha + b * np.exp(S_star / a)) / (alpha + b * np.exp(S_L / a))) - np.exp(-S_star / a) + np.exp(-S_L / a) - (Const3) * (S_star - S_L)) ic2 = (Const4) * (np.log(alpha + b * np.exp(S_star / a)) * (S_star / a) - np.log(alpha + b * np.exp(S_L / a)) * (S_L / a) + polylog(2, -b * np.exp(S_star / a)) - polylog(2, -b * np.exp(S_L / a))) ic3 = (1 / b) * ((np.exp(-S_star / a)) * (a - S_star) - np.exp(-S_L / a) * (a - S_L)) - ((S_star)**2 - (S_L)**2) / (a * alpha) ic = ic1 + ic2 + ic3 B_star_I2 = B_L + ic return B_star_I2
def IntegralCurve2(S_star, S_L): ic1 = -(a / b) * ((-2 * b / alpha) * np.log( (alpha + b * np.exp(S_star / a)) / (alpha + b * np.exp(S_L / a))) - np.exp(-S_star / a) + np.exp(-S_L / a) - (2 * b / (alpha * a)) * (S_star - S_L)) ic2 = (2 * a / alpha) * (np.log(alpha + b * np.exp(S_star / a)) * (S_star / a) - np.log(alpha + b * np.exp(S_L / a)) * (S_L / a) + polylog(2, -b * np.exp(S_star / a)) - polylog(2, -b * np.exp(S_L / a))) ic3 = (1 / b) * ((np.exp(-S_star / a)) * (a - S_star) - np.exp(-S_L / a) * (a - S_L)) - ((S_star)**2 + (S_L)**2) / (a * alpha) B_star_I2 = B_L + ic1 + ic2 + ic3 return B_star_I2
def IntegralCurve1(S_star, S_R): IC1 = -(a / b) * ((-2 * b / alpha) * np.log( (alpha - b * np.exp(S_star / a)) / (alpha - b * np.exp(S_R / a))) - np.exp(-S_star / a) + np.exp(-S_R / a) + (2 * b / (alpha * a)) * (S_star - S_R)) IC2 = -(2 * a / alpha) * (np.log(alpha - b * np.exp(S_star / a)) * (S_star / a) - np.log(alpha - b * np.exp(S_R / a)) * (S_R / a) + polylog(2, b * np.exp(S_star / a)) - polylog(2, b * np.exp(S_R / a))) IC3 = (1 / b) * ((np.exp(-S_star / a)) * (a - S_star) - np.exp(-S_R / a) * (a - S_R)) + ((S_star)**2 - (S_R)**2) / (a * alpha) B_star_I1 = B_R + IC1 + IC2 + IC3 return B_star_I1
def integrand(x, LbyR, T): #print "integrand" n = 0 sum = 0 while True: alpha = 2*n*T*x/(1+1/LbyR) arg = exp(-alpha) value = polylog(3,arg) + alpha*polylog(2,arg) if n == 0: value /= 2 sum += value if value/sum < 1e-13: return sum/(x**2*LbyR) n += 1
def IntegralCurve1(S_star, S_R): IC1 = (a / b) * (-Const2 * np.log( (alpha - b * np.exp(S_star / a)) / (alpha - b * np.exp(S_R / a))) - np.exp(-S_star / a) + np.exp(-S_R / a) + (Const3) * (S_star - S_R)) IC2 = -(Const4) * (np.log(alpha - b * np.exp(S_star / a)) * (S_star / a) - np.log(alpha - b * np.exp(S_R / a)) * (S_R / a) + polylog(2, b * np.exp(S_star / a)) - polylog(2, b * np.exp(S_R / a))) IC3 = (1 / b) * ((np.exp(-S_star / a)) * (a - S_star) - np.exp(-S_R / a) * (a - S_R)) + ((S_star)**2 - (S_R)**2) / (a * alpha) IC = IC1 + IC2 + IC3 B_star_I1 = B_R - IC return B_star_I1
def Compute_F(S_star, S_L, S_R, B_L, B_R): if (S_L <= S_R): IC1 = (a / b) * (-Const2 * np.log( (alpha - b * np.exp(S_star / a)) / (alpha - b * np.exp(S_R / a))) - np.exp(-S_star / a) + np.exp(-S_R / a) + (Const3) * (S_star - S_R)) IC2 = (Const4) * (np.log(alpha - b * np.exp(S_star / a)) * (S_star / a) - np.log(alpha - b * np.exp(S_R / a)) * (S_R / a) + float(polylog(2, b * np.exp(S_star / a))) - float(polylog(2, b * np.exp(S_R / a)))) IC3 = (1 / b) * ((np.exp(-S_star / a)) * (a - S_star) - np.exp(-S_R / a) * (a - S_R)) IC4 = ((S_star)**2 - (S_R)**2) / (a * alpha) B_star_I1 = B_R - IC1 - IC2 + IC3 + IC4 # #print(S_star) # S_star=S_L b_star_H1 = B_L - (2 * Const1) * (np.sqrt(S_L - S_star)) * ( np.sqrt(np.exp(S_L / (rho * C)) - np.exp(S_star / (rho * C)))) f_star = B_star_I1 - b_star_H1 print('F(S*) =', f_star) else: #print('Left Rarefaction and Right Shock') ic1 = (a / b) * ((Const2) * np.log( (alpha + b * np.exp(S_star / a)) / (alpha + b * np.exp(S_L / a))) - np.exp(-S_star / a) + np.exp(-S_L / a) - (Const3) * (S_star - S_L)) ic2 = (Const4) * (np.log(alpha + b * np.exp(S_star / a)) * (S_star / a) - np.log(alpha + b * np.exp(S_L / a)) * (S_L / a) + float(polylog(2, -b * np.exp(S_star / a))) - float(polylog(2, -b * np.exp(S_L / a)))) ic3 = (1 / b) * ((np.exp(-S_star / a)) * (a - S_star) - np.exp(-S_L / a) * (a - S_L)) ic4 = ((S_star)**2 - (S_L)**2) / (a * alpha) B_star_I2 = B_L - ic1 + ic2 + ic3 - ic4 b_star_H2 = B_R + (2 * Const1) * (np.sqrt(S_R - S_star)) * ( np.sqrt(np.exp(S_R / (rho * C)) - np.exp(S_star / (rho * C)))) f_star = B_star_I2 - b_star_H2 print('f(S*) =', f_star) return f_star
def Compute_F(S_star, S_L, S_R, B_L, B_R): if (S_L <= S_R): #print('Left Shock and Right Rarefaction') IC1 = (a / b) * (-Const2 * np.log( (alpha - b * np.exp(S_star / a)) / (alpha - b * np.exp(S_R / a))) - np.exp(-S_star / a) + np.exp(-S_R / a) + (Const3) * (S_star - S_R)) IC2 = -(Const4) * (np.log(alpha - b * np.exp(S_star / a)) * (S_star / a) - np.log(alpha - b * np.exp(S_R / a)) * (S_R / a) + polylog(2, b * np.exp(S_star / a)) - polylog(2, b * np.exp(S_R / a))) IC3 = (1 / b) * ((np.exp(-S_star / a)) * (a - S_star) - np.exp(-S_R / a) * (a - S_R)) + ((S_star)**2 - (S_R)**2) / (a * alpha) IC = IC1 + IC2 + IC3 f_star = B_R - IC - B_L + (2 * Const1) * (np.sqrt(S_L - S_star)) * ( (np.sqrt(np.exp(S_L / (rho * C)))) - (np.sqrt(np.exp(S_star / (rho * C))))) F_star = f_star print('F_star = ', F_star) else: #print('Left Rarefaction and Right Shock') ic1 = (a / b) * ((Const2) * np.log( (alpha + b * np.exp(S_star / a)) / (alpha + b * np.exp(S_L / a))) - np.exp(-S_star / a) + np.exp(-S_L / a) - (Const3) * (S_star - S_L)) ic2 = (Const4) * (np.log(alpha + b * np.exp(S_star / a)) * (S_star / a) - np.log(alpha + b * np.exp(S_L / a)) * (S_L / a) + polylog(2, -b * np.exp(S_star / a)) - polylog(2, -b * np.exp(S_L / a))) ic3 = (1 / b) * ((np.exp(-S_star / a)) * (a - S_star) - np.exp(-S_L / a) * (a - S_L)) - ((S_star)**2 - (S_L)**2) / (a * alpha) ic = ic1 + ic2 + ic3 f_star = B_L - ic - B_R - (2 * Const1) * (np.sqrt(S_R - S_star)) * ( (np.sqrt(np.exp(S_R / (rho * C)))) - (np.sqrt(np.exp(S_star / (rho * C))))) F_star = f_star print('F_star = ', F_star) return F_star
def gf_powerlaw(exponent: float) -> GF: '''Return the generating function of the powerlaw degree distribution with the given exponent. :param exponent: the exponent of the distribution :returns: the generating function''' return gf_from_series(lambda x: polylog(exponent, x) / zeta(exponent))
def fpot_Coulomb_dens_WS(a_r, rho0, R_A, a_A, N_Z, N_A): """ The function of the folding potential - Coulomb potential + WS-type density return: V(r) """ # 1.43996507808 = 197.327053 / 137.035999 (= hbar c * alpha) Ex = -exp((R_A - a_r) / a_A) Coe = 4.0 * pi * rho0 * N_Z * 1.43996507808 / N_A Org_Coulomb = N_Z * 1.43996507808 / a_r SFP_Coulomb = Coe * (a_A**2 * polylog(2, Ex) + 2.0 * a_A**3 * polylog(3, Ex) / a_r) return Org_Coulomb + SFP_Coulomb
def debye_non_integral(x): ''' Non-Integral function for the Debye Integral (has only to be multiplied with factor A!) x = T_D/T (Debye temperature and absolute temperature) ''' # individual summands of integral replacement s1 = 4. / 5. * pi**4 / x**3 s2 = 3 * x * exp(-x) / (exp(-x) - 1) s3 = 12 * log(1 - exp(-x)) s4 = -36 / x * polylog(2, exp(-x)) s5 = -72 / x**2 * polylog(3, exp(-x)) s6 = -72 / x**3 * polylog(4, exp(-x)) DC3 = (s1 + s2 + s3 + s4 + s5 + s6) return DC3
def Compute_dF(S_star, S_L, S_R, B_L, B_R): if (S_L <= S_R): dF_1 = -(a / b) * (-Const2 * (-b * np.exp(S_star / a) / (a * (alpha - b * np.exp(S_star / a)))) + (np.exp(-S_star / a) / a) + Const3) dF_2 = -Const4 * ((-S_star * b * np.exp(S_star / a) / (a**2 * (alpha - b * np.exp(S_star / a))) + np.log(alpha - b * np.exp(S_star / a)) / a) + float(polylog(1, b * np.exp(S_star / a)) / a)) dF_3 = (1 / b) * (-np.exp(-S_star / a) - (-S_star + a) * np.exp(-S_star / a) / a) dF_4 = 2 * S_star / (a * alpha) dF_5 = (2 * Const1) * ( -np.sqrt(np.exp(S_L / (C * rho)) - np.exp(S_star / (C * rho))) / (2 * np.sqrt(S_L - S_star)) - np.sqrt(S_L - S_star) * np.exp(S_star / (C * rho)) / (2 * C * rho * np.sqrt(np.exp(S_L / (C * rho)) - np.exp(S_star / (C * rho))))) dF_star = dF_1 + dF_2 + dF_3 + dF_4 + dF_5 print('dF(S*) =', dF_star) else: df_1 = -(a / b) * (Const2 * (b * np.exp(S_star / a) / (a * (alpha + b * np.exp(S_star / a)))) + (np.exp(-S_star / a) / a) - Const3) df_2 = Const4 * ((np.log(alpha + b * np.exp(S_star / a)) / a + S_star * b * np.exp(S_star / a) / (a**2 * (alpha + b * np.exp(S_star / a)))) + float(polylog(1, -b * np.exp(S_star / a)) / a)) df_3 = (1 / b) * (-np.exp(-S_star / a) - (-S_star + a) * np.exp(-S_star / a) / a) - ( 2 * S_star) / (a * alpha) df_4 = (2 * Const1) * ( -np.sqrt(np.exp(S_R / (C * rho)) - np.exp(S_star / (C * rho))) / (2 * np.sqrt(S_R - S_star)) - np.sqrt(S_R - S_star) * np.exp(S_star / (C * rho)) / (2 * C * rho * np.sqrt(np.exp(S_R / (C * rho)) - np.exp(S_star / (C * rho))))) dF_star = df_1 + df_2 + df_3 - df_4 print('df(S*) =', dF_star) return dF_star
def _makePowerlawWithCutoff(self, alpha: float, kappa: float) -> Callable[[int], float]: '''Create a model function for a powerlaw distribution with exponential cutoff. :param alpha: the exponent of the distribution :param kappa: the degree cutoff :returns: a model function''' C = polylog(alpha, exp(-1.0 / kappa)) def p(k: int) -> float: return (pow((k + 0.0), -alpha) * exp(-(k + 0.0) / kappa)) / C return p
def __init__(self, d, family): """ Creates an Archimedean copula. bounds_param = #x0 = Initial guess. Array of real elements of size (n,), where 'n' is the number of independent variables. """ self.family = family self.d = d if family == 'AMH': self.bounds_param = [(0+ 1e-6, 1-1e-6)] self.theta_start = np.array(0.5) self.phit = lambda theta, t : (1-theta)/(np.exp(t)-theta) self.phit_inv = lambda theta, t : np.log((1-theta+theta*t)/t) self.phit_invp = lambda theta, t : theta/(theta*t-theta+1) self.phit_d = lambda theta, d, t : ((1-theta)/theta)* float(polylog(-d,theta*np.exp(-t)).real) if family == 'clayton': self.bounds_param = [(0+ 1e-6, None)] self.theta_start = np.array(0.5) self.phit = lambda theta, t : (1+ t)**(-1/theta) self.phit_inv = lambda theta, t : (1/theta)*(t**(-theta)-1) self.phitp = lambda theta, t :(-1/theta)*(1+t)**(-1/theta-1) self.phit_d = lambda theta, d, t : np.prod([k+(1/theta) for k in range(0,d) ])*(1+t)**(-(d+1/theta))#(gamma(d+1/theta)/gamma(1/theta) ) if family == 'gumbel': self.bounds_param = [(1+ 1e-6, None)] self.theta_start = np.array(0.5) self.phit = lambda theta, t : 2 self.phit_inv = lambda theta, t : 2 self.phit_d = lambda theta, d, t, : 2 self.cdf = lambda theta, u : self.phit(theta, sum([self.phit_inv(theta, ui) for ui in u])) self.pdf = lambda theta, u : self.phit_d(theta, self.d, sum([self.phit_inv(theta, ui) for ui in u]) ) /np.prod([self.phitp(theta, self.phit_inv(theta, ui)) for ui in u]) self.logl = lambda theta, uj : np.log( ((-1)**d) *self.phit_d(theta, self.d, sum([self.phit_inv(theta, uij) for uij in uj])) ) + sum([np.log(-self.phit_invp(theta, uij)) for uij in uj])
def central_density(self): return mpmath.fp.re(-1.0 / self.debroglie**3 * mpmath.polylog(3.0/2.0, -np.exp(self.beta * (self.chemical_potential))))
def mpmathDilog(z): return mpmath.polylog(2,z)
def Fermi_integral(x, j): r""" Calculate the complete Fermi-Dirac integral. Parameters ---------- x : ~astropy.units.Quantity Argument of the Fermi-Dirac integral function. j : ~astropy.units.Quantity Order/index of the Fermi-Dirac integral function. Returns ------- integral : ~astropy.units.Quantity, complex Complete Fermi-Dirac integral for given argument and order. Raises ------ TypeError If the argument is invalid. ~astropy.units.UnitsError If the argument is a `~astropy.units.Quantity` but is not dimensionless. ValueError If the argument is not entirely finite. See also -------- plasma_dispersion_func Notes ----- The complete Fermi-Dirac integral is defined as: [1]_ .. math:: F_j (x) = \frac{1}{\Gamma (j+1)} \int_0^{\inf} \frac{t^j}{\exp{(t-x)} + 1} dt for j > 0. This is equivalent to the following polylogarithm [2]_ function: .. math:: F_j (x) = -Li_{j+1}\left(-e^{x}\right) Warning: at present this function is limited to relatively small arguments due to limitations in the mpmath package's implementation of polylog. References ---------- .. [1] https://en.wikipedia.org/wiki/Complete_Fermi-Dirac_integral .. [2] https://en.wikipedia.org/wiki/Polylogarithm Examples -------- >>> Fermi_integral(0, 0) (0.6931471805599453-0j) >>> Fermi_integral(1, 0) (1.3132616875182228-0j) >>> Fermi_integral(1, 1) (1.8062860704447743-0j) """ if isinstance(x, (int, float, complex)): arg = -np.exp(x) integral = -1 * complex(polylog(j + 1, arg)) return integral elif isinstance(x, np.ndarray): integral_arr = np.zeros_like(x, dtype='complex') for idx, val in enumerate(x): integral_arr[idx] = -1 * complex(polylog(j + 1, -np.exp(val))) return integral_arr else: raise ValueError(f"Improper type {type(x)} given for argument x.")
def getPolylog( n, k ): return polylog( n, k )
def debye_function_alalytic(self, x): return -1./5.*np.pi**4./x**4.-3./4.+3./x*np.log(1-np.exp(x))+9./x**2.*mpm.polylog(np.exp(x),2)-18./x**3.*mpm.polylog(np.exp(x),3)+18./x**4.*mpm.polylog(np.exp(x),4)