def tensor_get_an_no_deg1(L1, L2, d1, d2, BadPrimeInfo): """ Same as the above in the case no dimension is 1 """ if d1 == 1 or d2 == 1: raise ValueError('min(d1,d2) should not be 1, use direct method then') s1 = len(L1) s2 = len(L2) if s1 < s2: S = s1 if s2 <= s1: S = s2 BadPrimes = [] for bpi in BadPrimeInfo: BadPrimes.append(bpi[0]) P = prime_range(S + 1) Z = S * [1] S = RealField()(S) for p in P: f = S.log(base=p).floor() q = 1 E1 = [] E2 = [] if not p in BadPrimes: for i in range(f): q = q * p E1.append(L1[q - 1]) E2.append(L2[q - 1]) e1 = list_to_euler_factor(E1, f + 1) e2 = list_to_euler_factor(E2, f + 1) # ld1 = d1 # not used # ld2 = d2 # not used else: # either convolve, or have one input be the answer and other 1-t i = BadPrimes.index(p) e1 = BadPrimeInfo[i][1] e2 = BadPrimeInfo[i][2] # ld1 = e1.degree() # not used # ld2 = e2.degree() # not used F = e1.list()[0].parent().fraction_field() R = PowerSeriesRing(F, "T", default_prec=f + 1) e1 = R(e1) e2 = R(e2) E = tensor_local_factors(e1, e2, f) A = euler_factor_to_list(E, f) while len(A) < f: A.append(0) q = 1 for i in range(f): q = q * p Z[q - 1] = A[i] all_an_from_prime_powers(Z) return Z
def tensor_get_an_no_deg1(L1, L2, d1, d2, BadPrimeInfo): """ Same as the above in the case no dimension is 1 """ if d1==1 or d2==1: raise ValueError('min(d1,d2) should not be 1, use direct method then') s1 = len(L1) s2 = len(L2) if s1 < s2: S = s1 if s2 <= s1: S = s2 BadPrimes = [] for bpi in BadPrimeInfo: BadPrimes.append(bpi[0]) P = prime_range(S+1) Z = S * [1] S = RealField()(S) for p in P: f = S.log(base=p).floor() q = 1 E1 = [] E2 = [] if not p in BadPrimes: for i in range(f): q=q*p E1.append(L1[q-1]) E2.append(L2[q-1]) e1 = list_to_euler_factor(E1,f+1) e2 = list_to_euler_factor(E2,f+1) # ld1 = d1 # not used # ld2 = d2 # not used else: # either convolve, or have one input be the answer and other 1-t i = BadPrimes.index(p) e1 = BadPrimeInfo[i][1] e2 = BadPrimeInfo[i][2] # ld1 = e1.degree() # not used # ld2 = e2.degree() # not used F = e1.list()[0].parent().fraction_field() R = PowerSeriesRing(F, "T", default_prec=f+1) e1 = R(e1) e2 = R(e2) E = tensor_local_factors(e1,e2,f) A = euler_factor_to_list(E,f) while len(A) < f: A.append(0) q = 1 for i in range(f): q = q*p Z[q-1]=A[i] all_an_from_prime_powers(Z) return Z
def get_euler_factor(L, p): """ takes L list of all ans and p is a prime it returns the euler factor at p # utility function to get an Euler factor, unused """ S = RealField()(len(L)) f = S.log(base=p).floor() E = [] q = 1 for i in range(f): q = q * p E.append(L[q - 1]) return list_to_euler_factor(E, f)
def get_euler_factor(L,p): """ takes L list of all ans and p is a prime it returns the euler factor at p # utility function to get an Euler factor, unused """ S = RealField()(len(L)) f = S.log(base=p).floor() E = [] q = 1 for i in range(f): q = q*p E.append(L[q-1]) return list_to_euler_factor(E,f)
def all_an_from_prime_powers(L): """ L is a list of an such that the terms are correct for all n which are prime powers and all others are equal to 1; this function changes the list in place to make the correct ans for all n """ S = ZZ(len(L)) for p in prime_range(S + 1): q = 1 Sr = RealField()(len(L)) f = Sr.log(base=p).floor() for k in range(f): q = q * p for m in range(2, 1 + (S // q)): if (m % p) != 0: L[m * q - 1] = L[m * q - 1] * L[q - 1]
def all_an_from_prime_powers(L): """ L is a list of an such that the terms are correct for all n which are prime powers and all others are equal to 1; this function changes the list in place to make the correct ans for all n """ S = ZZ(len(L)) for p in prime_range(S+1): q = 1 Sr = RealField()(len(L)) f = Sr.log(base=p).floor() for k in range(f): q = q*p for m in range(2, 1+(S//q)): if (m%p) != 0: L[m*q-1] = L[m*q-1] * L[q-1]
def tensor_get_an_deg1(L, D, BadPrimeInfo): """ Same as above, except that the BadPrimeInfo is now a list of lists of the form [p,f] where f is a polynomial. """ s1 = len(L) s2 = len(D) if s1 < s2: S = s1 if s2 <= s1: S = s2 BadPrimes = [] for bpi in BadPrimeInfo: BadPrimes.append(bpi[0]) P = prime_range(S + 1) Z = S * [1] S = RealField()(S) # fix bug for p in P: f = S.log(base=p).floor() q = 1 u = 1 e = D[p - 1] if not p in BadPrimes: for i in range(f): q = q * p u = u * e Z[q - 1] = u * L[q - 1] else: i = BadPrimes.index(p) e = BadPrimeInfo[i][1] F = e.list()[0].parent().fraction_field() R = PowerSeriesRing(F, "T", default_prec=f + 1) e = R(e) A = euler_factor_to_list(e, f) for i in range(f): q = q * p Z[q - 1] = A[i] all_an_from_prime_powers(Z) return Z
def tensor_get_an_deg1(L, D, BadPrimeInfo): """ Same as above, except that the BadPrimeInfo is now a list of lists of the form [p,f] where f is a polynomial. """ s1 = len(L) s2 = len(D) if s1 < s2: S = s1 if s2 <= s1: S = s2 BadPrimes = [] for bpi in BadPrimeInfo: BadPrimes.append(bpi[0]) P = prime_range(S+1) Z = S * [1] S = RealField()(S) # fix bug for p in P: f = S.log(base=p).floor() q = 1 u = 1 e = D[p-1] if not p in BadPrimes: for i in range(f): q = q*p u = u*e Z[q-1] = u*L[q-1] else: i = BadPrimes.index(p) e = BadPrimeInfo[i][1] F = e.list()[0].parent().fraction_field() R = PowerSeriesRing(F, "T", default_prec=f+1) e = R(e) A = euler_factor_to_list(e,f) for i in range(f): q = q*p Z[q-1] = A[i] all_an_from_prime_powers(Z) return Z