Python cmath.log() Examples
The following are 30
code examples of cmath.log().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cmath
, or try the search function
.
Example #1
Source File: math2.py From altanalyze with Apache License 2.0 | 6 votes |
def _digamma_complex(x): if not x.imag: return complex(_digamma_real(x.real)) if x.real < 0.5: x = 1.0-x s = pi*cotpi(x) else: s = 0.0 while abs(x) < 10.0: s -= 1.0/x x += 1.0 x2 = x**-2 t = x2 for c in _psi_coeff: s -= c*t if abs(t) < 1e-20: break t *= x2 return s + cmath.log(x) - 0.5/x
Example #2
Source File: matrixelements.py From flavio with MIT License | 6 votes |
def delta_C9(par, wc, q2, scale, qiqj): alpha_s = running.get_alpha(par, scale)['alpha_s'] mb = running.get_mb_pole(par) mc = running.get_mc_pole(par) xi_t = ckm.xi('t', qiqj)(par) xi_u = ckm.xi('u', qiqj)(par) muh = scale/mb sh = q2/mb**2 z = mc**2/mb**2 Lmu = log(scale/mb) Ls = log(sh) # computing this once to save time delta_tmp = wc['C1_'+qiqj] * F_19(muh, z, sh) + wc['C2_'+qiqj] * F_29(muh, z, sh) delta_t = wc['C8eff_'+qiqj] * F_89(Ls, sh) + delta_tmp delta_u = delta_tmp + wc['C1_'+qiqj] * Fu_19(q2, mb, scale) + wc['C2_'+qiqj] * Fu_29(q2, mb, scale) # note the minus sign between delta_t and delta_u. This is because of a sign # switch in the definition of the "Fu" functions between hep-ph/0403185 # (used here) and hep-ph/0412400, see footnote 5 of 0811.1214. return -alpha_s/(4*pi) * (delta_t - xi_u/xi_t * delta_u)
Example #3
Source File: matrixelements.py From flavio with MIT License | 6 votes |
def delta_C7(par, wc, q2, scale, qiqj): alpha_s = running.get_alpha(par, scale)['alpha_s'] mb = running.get_mb_pole(par) mc = par['m_c BVgamma'] xi_t = ckm.xi('t', qiqj)(par) xi_u = ckm.xi('u', qiqj)(par) muh = scale/mb sh = q2/mb**2 z = mc**2/mb**2 Lmu = log(scale/mb) # computing this once to save time delta_tmp = wc['C1_'+qiqj] * F_17(muh, z, sh) + wc['C2_'+qiqj] * F_27(muh, z, sh) delta_t = wc['C8eff_'+qiqj] * F_87(Lmu, sh) + delta_tmp delta_u = delta_tmp + wc['C1_'+qiqj] * Fu_17(q2, mb, scale) + wc['C2_'+qiqj] * Fu_27(q2, mb, scale) # note the minus sign between delta_t and delta_u. This is because of a sign # switch in the definition of the "Fu" functions between hep-ph/0403185 # (used here) and hep-ph/0412400, see footnote 5 of 0811.1214. return -alpha_s/(4*pi) * (delta_t - xi_u/xi_t * delta_u)
Example #4
Source File: bxlnu.py From flavio with MIT License | 6 votes |
def gLR(xc, xl): if xl == 0: return (4*sqrt(xc)*(1 + 9*xc - 9*xc**2 - xc**3 + 6*xc*(1 + xc)*log(xc))).real else: return (4*sqrt(xc)*(sqrt(xc**2 + (-1 + xl)**2 - 2*xc*(1 + xl)) + 10*xc*sqrt(xc**2 + (-1 + xl)**2 - 2*xc*(1 + xl)) + xc**2*sqrt(xc**2 + (-1 + xl)**2 - 2*xc*(1 + xl)) - 5*xl*sqrt(xc**2 + (-1 + xl)**2 - 2*xc*(1 + xl)) - 5*xc*xl*sqrt(xc**2 + (-1 + xl)**2 - 2*xc*(1 + xl)) - 2*xl**2*sqrt(xc**2 + (-1 + xl)**2 - 2*xc*(1 + xl)) - 12*xc*log(2) - 12*xc**2*log(2) + 24*xc*xl*log(2) - 12*xl**2*log(2) - 12*(-1 + xc)*xl**2* log(1 - sqrt(xc)) - 6*xc*log(xc) - 6*xc**2*log(xc) + 12*xc*xl*log(xc) - 3*xl**2*log(xc) - 3*xc*xl**2*log(xc) - 6*xl**2*log(sqrt(xc) - 2*xc + xc**1.5) + 6*xc*xl**2* log(sqrt(xc) - 2*xc + xc**1.5) - 6*xl**2*log(xl) + 6*xc*xl**2*log(xl) + 12*xc*log(1 + xc - xl - sqrt(1 + (xc - xl)**2 - 2*(xc + xl))) + 12*xc**2*log(1 + xc - xl - sqrt(1 + (xc - xl)**2 - 2*(xc + xl))) - 24*xc*xl*log(1 + xc - xl - sqrt(1 + (xc - xl)**2 - 2*(xc + xl))) + 6*xl**2*log(1 + xc - xl - sqrt(1 + (xc - xl)**2 - 2*(xc + xl))) + 6*xc*xl**2* log(1 + xc - xl - sqrt(1 + (xc - xl)**2 - 2*(xc + xl))) + 6*xl**2*log(1 + xc**2 - xl + sqrt(xc**2 + (-1 + xl)**2 - 2*xc*(1 + xl)) - xc*(2 + xl + sqrt(xc**2 + (-1 + xl)**2 - 2*xc*(1 + xl)))) - 6*xc*xl**2* log(1 + xc**2 - xl + sqrt(xc**2 + (-1 + xl)**2 - 2*xc*(1 + xl)) - xc*(2 + xl + sqrt(xc**2 + (-1 + xl)**2 - 2*xc*(1 + xl)))))).real
Example #5
Source File: matrixelements.py From flavio with MIT License | 6 votes |
def F_87(Lmu, sh): """Function $F_8^{(7)}$ giving the contribution of $O_7$ to the matrix element of $O_8$, as given in eq. (40) of hep-ph/0312063. - `sh` is $\hat s=q^2/m_b^2$, """ if sh==0.: return (-4*(33 + 24*Lmu + 6j*pi - 2*pi**2))/27. return (-32/9. * Lmu + 8/27. * pi**2 - 44/9. - 8/9. * 1j * pi + (4/3. * pi**2 - 40/3.) * sh + (32/9. * pi**2 - 316/9.) * sh**2 + (200/27. * pi**2 - 658/9.) * sh**3 - 8/9. * log(sh) * (sh + sh**2 + sh**3)) # Functions for the two-loop virtual corrections to the matrix elements of # O1,2 in b->dl+l- (also needed for doubly Cabibbo-suppressed contributions # to b>sl+l-). Taken from hep-ph/0403185v2 (Seidel)
Example #6
Source File: functions.py From altanalyze with Apache License 2.0 | 6 votes |
def powm1(ctx, x, y): mag = ctx.mag one = ctx.one w = x**y - one M = mag(w) # Only moderate cancellation if M > -8: return w # Check for the only possible exact cases if not w: if (not y) or (x in (1, -1, 1j, -1j) and ctx.isint(y)): return w x1 = x - one magy = mag(y) lnx = ctx.ln(x) # Small y: x^y - 1 ~ log(x)*y + O(log(x)^2 * y^2) if magy + mag(lnx) < -ctx.prec: return lnx*y + (lnx*y)**2/2 # TODO: accurately eval the smaller of the real/imag part return ctx.sum_accurately(lambda: iter([x**y, -1]), 1)
Example #7
Source File: math2.py From altanalyze with Apache License 2.0 | 6 votes |
def ei_taylor(z, _e1=False): s = t = z k = 2 while 1: t = t*z/k term = t/k if abs(term) < 1e-17: break s += term k += 1 s += euler if _e1: s += log(-z) else: if type(z) is float or z.imag == 0.0: s += math_log(abs(z)) else: s += cmath.log(z) return s
Example #8
Source File: eos_mix.py From thermo with MIT License | 5 votes |
def TPD(self, Zz, Zy, zs, ys): # if zs is None: # zs = self.xs # liquid main phase # Z_l = self.Z_l # if ys is None: # ys = self.ys # Z_g = self.Z_g # Might just be easier to come up with my own criteria and analysis z_fugacity_coefficients = self.fugacity_coefficients(Zz, zs) y_fugacity_coefficients = self.fugacity_coefficients(Zy, ys) tot = 0 for yi, phi_yi, zi, phi_zi in zip(ys, y_fugacity_coefficients, zs, z_fugacity_coefficients): di = log(zi) + log(phi_zi) tot += yi*(log(yi) + log(phi_yi) - di) return tot*R*self.T
Example #9
Source File: eos_mix.py From thermo with MIT License | 5 votes |
def d_TPD_dy(self, Zz, Zy, zs, ys): # The gradient should be - for all variables z_fugacity_coefficients = self.fugacity_coefficients(Zz, zs) y_fugacity_coefficients = self.fugacity_coefficients(Zy, ys) gradient = [] for yi, phi_yi, zi, phi_zi in zip(ys, y_fugacity_coefficients, zs, z_fugacity_coefficients): hi = di = log(zi) + log(phi_zi) # same as di k = log(yi) + log(phi_yi) - hi Yi = exp(-k)*yi gradient.append(log(phi_yi) + log(Yi) - di) return gradient
Example #10
Source File: test_poisson.py From hawkeslib with MIT License | 5 votes |
def test_likelihood_pars_ok(self): # with T comp = self.pp.log_likelihood_with_params(self.a, 5., 6.) true = - 5 * 6. + 4 * log(5.) self.assertAlmostEqual(comp, true)
Example #11
Source File: test_cmath_jy.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_faux_complex(self): class Foo: def __complex__(self): return 1.0j class Bar(object): def __complex__(self): return 1.0j self.assertEqual(cmath.log(Foo()), cmath.log(1.0j)) self.assertEqual(cmath.log(Bar()), cmath.log(1.0j))
Example #12
Source File: test_cmath_jy.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_faux_float(self): class Foo: def __float__(self): return 1.0 class Bar(object): def __float__(self): return 1.0 self.assertEqual(cmath.log(Foo()), 0.0) self.assertEqual(cmath.log(Bar()), 0.0)
Example #13
Source File: eos_mix.py From thermo with MIT License | 5 votes |
def TDP_Michelsen(self, Zz, Zy, zs, ys): z_fugacity_coefficients = self.fugacity_coefficients(Zz, zs) y_fugacity_coefficients = self.fugacity_coefficients(Zy, ys) tot = 0 for yi, phi_yi, zi, phi_zi in zip(ys, y_fugacity_coefficients, zs, z_fugacity_coefficients): hi = di = log(zi) + log(phi_zi) # same as di k = log(yi) + log(phi_yi) - hi Yi = exp(-k)*yi tot += Yi*(log(Yi) + log(phi_yi) - hi - 1.) return 1. + tot
Example #14
Source File: math_functions.py From jhTAlib with GNU General Public License v3.0 | 5 votes |
def LOG(df, price='Close'): """ Logarithm Returns: list of floats = jhta.LOG(df, price='Close') """ return [cmath.log(df[price][i]).real for i in range(len(df[price]))]
Example #15
Source File: test_poisson.py From hawkeslib with MIT License | 5 votes |
def test_marginal_likelihood_correct(self): from scipy.integrate import quad f0 = self.pp._get_log_posterior_pot(self.a, self.T, self.pp.mu_hyp) pot = lambda x: np.exp(f0(x)) q = np.log(quad(pot, 0, 20)) ml = self.pp.marginal_likelihood(self.a, self.T) self.assertAlmostEqual(q[0], ml, places=2)
Example #16
Source File: test_cmath_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_log(self): self.assertAlmostEqual(complex(1.60944, 0.927295), cmath.log(complex(3, 4)))
Example #17
Source File: inlinecalculator.py From zim-desktop-wiki with GNU General Public License v2.0 | 5 votes |
def log2(x): 'logarithm base 2' return log(x, 2)
Example #18
Source File: AdaBoost.py From statistical-learning-methods-note with Apache License 2.0 | 5 votes |
def computeBaseClassifierCoefficient(self, classifierIdx): ''' 输入当前正在训练的基分类器下标(从0开始),计算当前的基分类器系数 alpha 。 :param classifierIdx: 当前分类器下标(从0开始) :return: ''' self.alphaList[classifierIdx] = (1.0 / 2 * \ cmath.log((1.0-self.eList[classifierIdx])/self.eList[classifierIdx], cmath.e)\ ).real
Example #19
Source File: test_poisson.py From hawkeslib with MIT License | 5 votes |
def test_likelihood_noT(self): comp = self.pp.log_likelihood_with_params(self.a, 5.) true = - 5.**2 + 4 * log(5.) self.assertAlmostEqual(comp, true)
Example #20
Source File: test_cmath_jy.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_log(self): self.assertAlmostEqual(complex(1.60944, 0.927295), cmath.log(complex(3, 4)))
Example #21
Source File: heat_capacity.py From thermo with MIT License | 5 votes |
def Zabransky_quasi_polynomial_integral(T, Tc, a1, a2, a3, a4, a5, a6): r'''Calculates the integral of liquid heat capacity using the quasi-polynomial model developed in [1]_. Parameters ---------- T : float Temperature [K] a1-a6 : float Coefficients Returns ------- H : float Difference in enthalpy from 0 K, [J/mol] Notes ----- The analytical integral was derived with SymPy; it is a simple polynomial plus some logarithms. Examples -------- >>> H2 = Zabransky_quasi_polynomial_integral(300, 591.79, -3.12743, ... 0.0857315, 13.7282, 1.28971, 6.42297, 4.10989) >>> H1 = Zabransky_quasi_polynomial_integral(200, 591.79, -3.12743, ... 0.0857315, 13.7282, 1.28971, 6.42297, 4.10989) >>> H2 - H1 14662.026406892925 References ---------- .. [1] Zabransky, M., V. Ruzicka Jr, V. Majer, and Eugene S. Domalski. Heat Capacity of Liquids: Critical Review and Recommended Values. 2 Volume Set. Washington, D.C.: Amer Inst of Physics, 1996. ''' Tc2 = Tc*Tc Tc3 = Tc2*Tc term = T - Tc return R*(T*(T*(T*(T*a6/(4.*Tc3) + a5/(3.*Tc2)) + a4/(2.*Tc)) - a1 + a3) + T*a1*log(1. - T/Tc) - 0.5*Tc*(a1 + a2)*log(term*term))
Example #22
Source File: functions.py From altanalyze with Apache License 2.0 | 5 votes |
def log(ctx, x, b=None): if b is None: return ctx.ln(x) wp = ctx.prec + 20 return ctx.ln(x, prec=wp) / ctx.ln(b, prec=wp)
Example #23
Source File: test_cmath_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_log(self): self.assertAlmostEqual(complex(1.60944, 0.927295), cmath.log(complex(3, 4)))
Example #24
Source File: test_cmath_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_faux_float(self): class Foo: def __float__(self): return 1.0 class Bar(object): def __float__(self): return 1.0 self.assertEqual(cmath.log(Foo()), 0.0) self.assertEqual(cmath.log(Bar()), 0.0)
Example #25
Source File: test_cmath_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_faux_complex(self): class Foo: def __complex__(self): return 1.0j class Bar(object): def __complex__(self): return 1.0j self.assertEqual(cmath.log(Foo()), cmath.log(1.0j)) self.assertEqual(cmath.log(Bar()), cmath.log(1.0j))
Example #26
Source File: test_functions.py From altanalyze with Apache License 2.0 | 5 votes |
def test_log(): mp.dps = 15 assert log(1) == 0 for x in [0.5, 1.5, 2.0, 3.0, 100, 10**50, 1e-50]: assert log(x).ae(math.log(x)) assert log(x, x) == 1 assert log(1024, 2) == 10 assert log(10**1234, 10) == 1234 assert log(2+2j).ae(cmath.log(2+2j)) # Accuracy near 1 assert (log(0.6+0.8j).real*10**17).ae(2.2204460492503131) assert (log(0.6-0.8j).real*10**17).ae(2.2204460492503131) assert (log(0.8-0.6j).real*10**17).ae(2.2204460492503131) assert (log(1+1e-8j).real*10**16).ae(0.5) assert (log(1-1e-8j).real*10**16).ae(0.5) assert (log(-1+1e-8j).real*10**16).ae(0.5) assert (log(-1-1e-8j).real*10**16).ae(0.5) assert (log(1j+1e-8).real*10**16).ae(0.5) assert (log(1j-1e-8).real*10**16).ae(0.5) assert (log(-1j+1e-8).real*10**16).ae(0.5) assert (log(-1j-1e-8).real*10**16).ae(0.5) assert (log(1+1e-40j).real*10**80).ae(0.5) assert (log(1j+1e-40).real*10**80).ae(0.5) # Huge assert log(ldexp(1.234,10**20)).ae(log(2)*1e20) assert log(ldexp(1.234,10**200)).ae(log(2)*1e200) # Some special values assert log(mpc(0,0)) == mpc(-inf,0) assert isnan(log(mpc(nan,0)).real) assert isnan(log(mpc(nan,0)).imag) assert isnan(log(mpc(0,nan)).real) assert isnan(log(mpc(0,nan)).imag) assert isnan(log(mpc(nan,1)).real) assert isnan(log(mpc(nan,1)).imag) assert isnan(log(mpc(1,nan)).real) assert isnan(log(mpc(1,nan)).imag)
Example #27
Source File: test_functions.py From altanalyze with Apache License 2.0 | 5 votes |
def test_complex_functions(): for x in (list(range(10)) + list(range(-10,0))): for y in (list(range(10)) + list(range(-10,0))): z = complex(x, y)/4.3 + 0.01j assert exp(mpc(z)).ae(cmath.exp(z)) assert log(mpc(z)).ae(cmath.log(z)) assert cos(mpc(z)).ae(cmath.cos(z)) assert sin(mpc(z)).ae(cmath.sin(z)) assert tan(mpc(z)).ae(cmath.tan(z)) assert sinh(mpc(z)).ae(cmath.sinh(z)) assert cosh(mpc(z)).ae(cmath.cosh(z)) assert tanh(mpc(z)).ae(cmath.tanh(z))
Example #28
Source File: test_functions.py From altanalyze with Apache License 2.0 | 5 votes |
def test_aliases(): assert ln(7) == log(7) assert log10(3.75) == log(3.75,10) assert degrees(5.6) == 5.6 / degree assert radians(5.6) == 5.6 * degree assert power(-1,0.5) == j assert fmod(25,7) == 4.0 and isinstance(fmod(25,7), mpf)
Example #29
Source File: test_functions.py From altanalyze with Apache License 2.0 | 5 votes |
def test_misc_bugs(): # test that this doesn't raise an exception mp.dps = 1000 log(1302) mp.dps = 15
Example #30
Source File: math2.py From altanalyze with Apache License 2.0 | 5 votes |
def _mathfun_n(f_real, f_complex): def f(*args, **kwargs): try: return f_real(*(float(x) for x in args)) except (TypeError, ValueError): return f_complex(*(complex(x) for x in args)) f.__name__ = f_real.__name__ return f # Workaround for non-raising log and sqrt in Python 2.5 and 2.4 # on Unix system