def wangdomain(own_ship_xy, length, vown, cog=0, k_shape=2, r_static=0.5): """ Parameters ---------- own_ship_xy : (float, float) xy coordinates of ellipse centre. cog : scalar, optional Rotation in degrees anti-clockwise. vown: is the own ship speed represented in knots k_shape :shape index """ # Constant r0 = 0.5 # L is the own ship length, # k_AD and k_DT represent gains of the advance, AD , # and the tactical diameter, D T , k_ad = 10**(0.359 * lg(vown) + 0.0952) k_dt = 10**(0.541 * lg(vown) - 0.0795) R_fore = (1 + 1.34 * sqrt((k_ad)**2 + (k_dt / 2)**2)) * length R_aft = (1 + 0.67 * sqrt((k_ad)**2 + (k_dt / 2)**2)) * length R_starb = (0.2 + k_dt) * length R_port = (0.2 + 0.75 * k_dt) * length R = np.array((R_fore, R_aft, R_starb, R_port)) r_fuzzy = ((ln(1 / r_static)) / (ln(1 / r0)))**(1 / k_shape) R_fuzzy = r_fuzzy * R # y_1: first quadrant x >= 0 y >= 0 x_max = R_fuzzy[0] x_min = -R_fuzzy[1] x_serises_plus = np.linspace(0, x_max, 80) x_serises_minus = np.linspace(x_min, -0.01, 80) # x>=0, y>=0 y_1 = R_fuzzy[2] * pow( (1 - (x_serises_plus / R_fuzzy[0])**k_shape), 1 / k_shape) y_4 = R_fuzzy[3] * -pow( (1 - (x_serises_plus / R_fuzzy[0])**k_shape), 1 / k_shape) y_2 = R_fuzzy[2] * pow( (1 - (-x_serises_minus / R_fuzzy[1])**k_shape), 1 / k_shape) y_3 = R_fuzzy[3] * -pow( (1 - (-x_serises_minus / R_fuzzy[1])**k_shape), 1 / k_shape) # stack the column curve1 = np.column_stack((x_serises_plus, y_1)) curve2 = np.column_stack((x_serises_minus, y_2)) curve3 = np.column_stack((x_serises_minus, y_3)) curve4 = np.column_stack((x_serises_plus, y_4)) # Primacy connection curve4 = np.flipud(curve4) curve3 = np.flipud(curve3) # cat the data series to one curve. curves = np.row_stack((curve1, curve4, curve3, curve2)).T curves[0, :] += own_ship_xy[0] curves[1, :] += own_ship_xy[1] # t_rot = pi * cog / 180 - pi / 2 R_rot = np.array([[cos(t_rot), sin(t_rot)], [-sin(t_rot), cos(t_rot)]]) for i in range(curves.shape[1]): curves[:, i] = np.dot(R_rot, curves[:, i]) return curves
def print_rates(E): from math import log as lg print '%.4e - %.4e - ' \ %(E[0][0], E[0][1]) for i in range(1, len(E)): r1 = lg(E[i-1][0]/E[i][0], 2) r2 = lg(E[i-1][1]/E[i][1], 2) print '%.4e %.2f %.4e %.2f' \ %(E[i][0], r1, E[i][1], r2) print '\n'
def get_L(data, num_clusters, mean_li, cov_li, phi_matrix, pi_vect): L_func_value= 0 #print(pi_vect) #print(phi_matrix) for i in range(len(data)): for j in range(num_clusters): L_func_value += phi_matrix[i][j] * ( lg(pi_vect[j]) + lg(ss.multivariate_normal.pdf(data[i], mean_li[j], cov_li[j], allow_singular=True) ) ) print(L_func_value) return L_func_value
def expg( a, b ): """ Returns the largest ( base, exponent ) tuple from a, b. This solution utilizes logarithmic properties to simplify the calculations. Consider two base-exponent pairs that we want to compare, say a**b and c**d: a**b > c**d ( 10**loga )**b > ( 10**logc )**d 10**( loga * b ) > 10**( logc * d ) Now we have the same base, and we can simplify our comparison: loga * b > logc * d """ return a if lg( a[ 0 ] ) * a[ 1 ] > lg( b[ 0 ] ) * b[ 1 ] else b
def get_public_tags_cloud(force_reload=False): """ return tags cloud: list of tuples-pairs ("tag", "tag_weight"), tag_weight - is a number divisible by 5, 0 <= tag_weight <= 100 Only for published articles. """ value = cache.get_value('tags_cloud') if value is None or force_reload: dbsession = DBSession() q = dbsession.query(func.count(Tag.id), Tag.tag).join(Article).filter(Article.is_draft==False).group_by(Tag.tag) items = list() counts = list() total = 0 for rec in q.all(): if rec[0] <= 0: continue total += rec[0] items.append((rec[1], int(rec[0]))) counts.append(int(rec[0])) if len(counts) != 0: min_count = min(counts) max_counts = max(counts) if min_count == max_counts: # i.e. all tags counts are the same, so they have the same weight weights = [(x[0], 50) for x in items] else: lmm = lg(max_counts) - lg(min_count) weights = [(x[0], (lg(x[1])-lg(min_count)) / lmm) for x in items] weights = [(x[0], int(5*(int(100*x[1])/5))) for x in weights] value = weights else: value = [] cache.set_value('tags_cloud', value) return value
def pearson_criterion(sample, distribution, mean, var): a = 0.05 n = len(sample) # k = int(1.72 * n ** (1 / 3)) k = int(1 + 3.3 * lg(n)) xsi = get_xsi(k - 1, 1 - a) ns, deltas = divide_sample(sample, k, mean, 0.3) print(f"ni: {str(ns)}") ps = count_pi(deltas, distribution) print(f"pi: {str(ps)}") xsi_b = count_xsi_b(ns, ps, n) if xsi_b < xsi: return True return False
class Func: n,p,s,v = map(float,input().split()) sq2 = sqrt(2) lgn = lg(n) a = (n/(p*10**9)) b = s/v @staticmethod def f(c): return Func.a * (Func.lgn)**(c*Func.sq2) + Func.b * (1+1/c) @staticmethod def g(c): return 1/(Func.a * (Func.lgn)**(c*Func.sq2) + Func.b * (1+1/c))
def pre_process(): years_to_bits = { y: 2**(i + 2) for i, y in enumerate(range(1960, 2170, 10)) } years_to_n = {} s, n, year = 0, 2, 1960 while year < 2170: s += lg(n) if s > years_to_bits[year]: years_to_n[year] = n - 1 year += 10 n += 1 return years_to_n
def check_n_selfnum(num): temp=[num] k=9 while(k>1): k =int(lg(num+0.1)) t =int(num//pow(10, k )) num =int(num%pow(10, k)) temp.append(t) # print('k:', k ,' num: ',num) temp.append(num%10) # print('temp : ', temp, 'remove : ',sum(temp)) try: self_num_list.remove(sum(temp)) except: pass
def getAuxInfo(logFileName, profileFileName): logFile = open(logFileName, 'r') csv_reader = csv.reader(logFile, delimiter='\t') log = [tuple(x) for x in csv_reader] log = log[1:] logFile.close() # MSn_Scan -- 0 # Parent_Scan -- 2 # Mono_Intensity -- 10 if log[7] == ('MSn_Scan', 'MSn_Level', 'Parent_Scan', 'Parent_Scan_Level', 'Parent_Mz', 'Mono_Mz', 'Charge_State', 'Monoisotopic_Mass', 'Isotopic_Fit', 'Parent_Intensity', 'Mono_Intensity'): log = log[8:] else: raise Exception profileFile = open(profileFileName, 'r') csv_reader = csv.reader(profileFile, delimiter='\t') profile = [tuple(x) for x in csv_reader] profileFile.close() # AGC_accumulation_time -- 2 # TIC -- 3 if profile[0] == ('MSn_Scan', 'Parent_Scan', 'AGC_accumulation_time', 'TIC'): profile = profile[1:] else: raise Exception dictAuxInfo = {} # len(log) should be equal to len(profile) now for i in range(len(log)): dictAuxInfo[log[i][0]] = (log[i][2], lg( float(log[i][10]) * float(profile[i][2]) / 1000, 10), float(profile[i][3]) * float(profile[i][2]) / 1000) # returns key:ms2 values:(ms1, log10IntensityInTheTrap, TIC_InTheTrap) return dictAuxInfo
def decrypt(self, e): """e is an encrypted message encoded as a polynomial""" if self._f is None or self._g is None: raise Exception("Private key not found.") if e._N <= self._P.get_N(): if not self._fp: self._fp = invert_in_p(self._f, self._P.get_N()) if not self._fq: self._fq = invert_in2tor(self._f, self._P.get_N(), int(lg(self._P.get_q()))) assert (self._h == self._fq * self._g) a = (self._f * e) % self._P.get_q() b = (self._fp * a) % self._P.get_p() return b # decrypted message else: raise Exception("e is too large, must be equal or under size %d" % self._P.get_N())
def rel(val: float, peak: float, digs: int = 0) -> str: if val == 0: return '-inf' return str(round(20 * lg(abs(val) / peak), digs))
#! /usr/bin/env python from functools import partial import sys if sys.version_info > (3, 5): # python 3.5 or above from math import log2 log = log2 str_utf8 = lambda x: str(x, 'utf-8') else: from math import log as lg log = lambda x: lg(x, 2) if x > 0 else 0 str_utf8 = lambda x: str(x).encode('utf-8') import click attrs = [ "edibility", "cap-shape", "cap-surface", "cap-color", "bruises?", "odor", "grill-attachment", "grill-spacing", "grill-size", "grill-color", "stalk-shape", "stalk-root", "stalk-surface-above-ring",
def sharing_chromosomes(n, k): return lg(sum(c(n, i) for i in range(k, n + 1))) - (n * lg(2))
def l2(num): """ log base 2 :rtype real """ return lg(num, 2)
from math import log as lg if __name__=='__main__': n,b,p=map(int,input().split()) bottle= 0 k = pow(2,int(lg(n,2))) towel = n*p while k>=2: bottle += (k*b+int(k/2)) n = int(k/2)+n-k #winners + rem if n>0: k = pow(2,int(lg(n,2))) print (bottle,towel) #else #print ((n-1)*(2*b+1),n*p) ''' A. Tennis Tournament time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tournament takes place in the following way (below, m is the number of the participants of the current round):
#difficulty calculator from math import log as lg rate = 100 #hash/sec idealreward = 1.0/60.0 #block/sec """ idealreward = 1-(1-difficulty)**rate lg(id - 1)/lg(rate) = 1 - difficulty 1- lg(id - 1)/lg(rate) = difficulty """ difficulty = lg(1-idealreward**rate,.5) print difficulty print (2**(160-difficulty))/(2**160)
157185040413215530975165633061, 178617532837899776787217832941, 96368378329569366965481375161, 41702562059995270288416739123, 234425024443044792063543979349, 147325628837781527224761907889, 89981271475268439210802711349, 216948066429127138241721468529, 118962322543851674548159048321 ] #for p in TIMEOUTS: # print(p) from math import log2 as lg import random semiprimes = set([p * q for p in FIFTEEN_DIGIT for q in FIFTEEN_DIGIT]) #semiprimes = set([p*q for p in TEN_DIGIT for q in TWENTY_DIGIT]) suitable = [n for n in semiprimes if 96 <= lg(n) < 97] #suitable = [n for n in semiprimes if lg(n) < 97] #print (format(max(suitable), "02x")) #print (format(min(suitable), "02x")) #print (len(suitable)) random.shuffle(suitable) #for n in suitable: for n in suitable[:200]: #for n in sorted(suitable)[-10:]: #pass print("0x{:02x}".format(n))
147325628837781527224761907889, 89981271475268439210802711349, 216948066429127138241721468529, 118962322543851674548159048321 ] #for p in TIMEOUTS: # print(p) from math import log2 as lg import random semiprimes = set([p*q for p in FIFTEEN_DIGIT for q in FIFTEEN_DIGIT]) #semiprimes = set([p*q for p in TEN_DIGIT for q in TWENTY_DIGIT]) suitable = [n for n in semiprimes if 96 <= lg(n) < 97] #suitable = [n for n in semiprimes if lg(n) < 97] #print (format(max(suitable), "02x")) #print (format(min(suitable), "02x")) #print (len(suitable)) random.shuffle(suitable) #for n in suitable: for n in suitable[:200]: #for n in sorted(suitable)[-10:]: #pass print("0x{:02x}".format(n))
s = s1 = s2 = a1 = a2 = x = f = eps = i = 0 while not ((0 < eps < 1) and (-1 < x < 1)): eps = float(input("Введите точность eps, (0 ;1) << ")) x = float(input("Введите значение x, (-1;1) << ")) s1 = s2 = a1 = a2 = x i = 2 while (abs(a1 + a2) >= eps) and (i < 300): a1 *= ((-x) * (i-1) / i) a2 *= ((-x) / i) s1 += a1 s2 += a2 i += 1 s = s1 + s2 f = ln(x) - exp(-x) + 1 eOut = trunc(lg(round(1/eps))) + 1 print(\ "\n"*2,\ f"Сумма ряда S >> %1.{eOut}f"%s, "\n",\ f"Контрольная формула F >> %1.{eOut}f"%f, "\n",\ "Количество итераций i >> ", i, "\n",\ f"S - F >> %1.{eOut}f"%(s-f),\ sep="")
def log0(x): return 0 if x == 0 else lg(x)
def main(): n, k = map(int, input().split()) if k >= lg(n): print('Your wish is granted!') else: print('You will become a flying monkey!')
def walther(temp_1, nu_1, temp_2, nu_2, temp_3): """ Calculate the kinematic viscosity at temperature `temp_3` based on the kinematic viscosities at temperatures `temp_1` and `temp_2`. The implementation follows standard ASTM D341. Parameters ---------- temp_1: scalar The temperature in :math:`^{\\circ}\\text{C}` that corresponds to the kinematic viscosity :code:`nu_1`. nu_1: scalar The kinematic viscosity in cSt at temperature :code:`temp_1`. temp_2: scalar The temperature in :math:`^{\\circ}\\text{C}` that corresponds to the kinematic viscosity :code:`nu_2`. nu_2: scalar The kinematic viscosity in cSt at temperature :code:`temp_2`. temp_3: ndarray The temperature in :math:`^{\\circ}\\text{C}` for which to calculate the kinematic viscosity. Returns ------- nu_3: ndarray The kinematic viscosity in cSt at temperature :code:`temp_3`. """ abs_zero = -273.15 viscs = [nu_1, nu_2] thetas = [temp_1 - abs_zero, temp_2 - abs_zero, temp_3 - abs_zero] zed = [__zedwalther(nu) for nu in viscs] const_a = (lg(lg(zed[0])) - lg(lg(zed[1])) * lg(thetas[0]) / lg(thetas[1])) / \ (1 - lg(thetas[0]) / lg(thetas[1])) const_b = (const_a - lg(lg(zed[1]))) / lg(thetas[1]) nu_3 = __nuwalther(10**10**(const_a - const_b * np.log10(thetas[2]))) return nu_3
def h(distribution): return sum(p * lg(1 / p) for p in distribution)
#difficulty calculator from math import log as lg rate = 100 #hash/sec idealreward = 1.0 / 60.0 #block/sec """ idealreward = 1-(1-difficulty)**rate lg(id - 1)/lg(rate) = 1 - difficulty 1- lg(id - 1)/lg(rate) = difficulty """ difficulty = lg(1 - idealreward**rate, .5) print difficulty print(2**(160 - difficulty)) / (2**160)