def impfact(n, primelist = None, primefactorization = None): """returns all of the factors needed to test whether a number is primitive abundant""" if primefactorization == None: primefactorization = primes2.pf(n, primelist) r = [] for x in primefactorization: r.append(n/x[0]) return r
def tau(n, primelist = None, primefactorization = None): '''the number-theoretic method for computing the number of factors of n''' if primefactorization == None: #initiate the prime factorization p = primes2.pf(n, primelist) else: p = primefactorization product = 1 #Good start for products for x in p: product*= (x[1]+1) #standard number-theoretic formula for this return product
def phi(n, primelist = None, primefactorization = None): '''The Euler phi function, or the quantity of numbers <= n that are coprime to n.''' if primefactorization == None: #initiate prime factorization p = primes2.pf(n, primelist) else: p = primefactorization for x in p: n=(n/x[0])*(x[0]-1) #standard number-theoretic method for computing the Euler phi function return n
def sigma(n, primelist = None, primefactorization = None): '''the number-theoretic method for computing the sum of the factors of n''' if n == 0: print 'infinity' #don't get too clever else: product = 1 #Good start for products if primefactorization == None: #initiate prime factorization p = primes2.pf(n, primelist) else: p = primefactorization for x in p: product *= ((x[0]**(x[1]+1))-1)/(x[0]-1) #standard number-theoretic method for the sigma function return product
def mu(n, primelist = None, primefactorization = None): '''mu inversion function''' if primefactorization == None: p = primes2.pf(n, primelist) else: p = primefactorization t = 1 for x in p: if x[1] == 1: t*=(-1) else: t = 0 break return t
def isprimab(n, primelist = None, primefactorization = None): '''test whether n is primitive abundant''' if n == 0: return False else: if primefactorization == None: #initiate prime factorization p = primes2.pf(n, primelist) else: p = primefactorization m = number_theory2.nu(n, None, p) #we need to see if n is at all a valid candidate if m == 2: return True #all perfect numbers are primitive abundant elif m > 2: #abundant case more complex f = impfact(n, None, p) #find the necessary factors x = True #initiate bool results for i in range(len(f)): #check each factor if x: #if the last factor was deficient . . . x = number_theory2.isdeficient(f[i], primelist) #check if this one is else: #if the last one already wasn't abundant . . . break #no need to check further return x #return our bool result else: return False #clearly, no deficient numbers are primitive abundant