import pandas as pd import numpy as np # functions needed to create the normalised values def f(x): y = np.log(np.log(x)) - np.log(2) + 0.5 + 1/(np.log(np.log(x))) return y def g(x): y = f(x) + 14 * np.log(np.log(x))/(np.log(x)) return y def h(x): y = np.log(np.log(x)) return y # flagsmall = TRUE; find the q>bound such that mq=ubound(q) and mq<= lbound(q) flagbounds = True #flagbounds = False # functions for lower and upper bounds def ubound(x): y = 5* 0.46178191583709069116175497699385195842/g(x) #Pi^2/(12*exp(Euler)) = 0.46178191583709069116175497699385195842 return y def lbound(x): y = 2.35* 0.46178191583709069116175497699385195842/g(x) #Pi^2/(12*exp(Euler)) = 0.46178191583709069116175497699385195842 return y def LLI_upp(x): y = 2*0.46178191583709069116175497699385195842/h(x) #Pi^2/(12*exp(Euler)) = 0.46178191583709069116175497699385195842 return y def LLI_low(x): y = 1.13*0.46178191583709069116175497699385195842/h(x) #Pi^2/(12*exp(Euler)) = 0.46178191583709069116175497699385195842 return y # function to Find indexes of an element in pandas dataframe # from https://thispointer.com/python-find-indexes-of-an-element-in-pandas-dataframe/ # to be used at the bottom of the script to detect when even == odd def getIndexes(dfObj, value): ''' Get index positions of value in dataframe i.e. dfObj.''' listOfPos = list() # Get bool dataframe with True at positions where the given value exists result = dfObj.isin([value]) # Get list of columns that contains the value seriesObj = result.any() columnNames = list(seriesObj[seriesObj == True].index) # Iterate over list of columns and fetch the rows indexes where value exists for col in columnNames: rows = list(result[col][result[col] == True].index) for row in rows: listOfPos.append((row, col)) # Return a list of tuples indicating the positions of value in the dataframe return listOfPos # function to check for small values; flagsmall is boolean; eps is the bound # uses the previous locator function def checksmallvalues(flagsmall, eps, bound): if flagsmall : print('*** Detecting values mq <', eps, 'and q > ', bound, ' and saving them on file recompute.txt') fileanalysis.write("*** Detecting values mq < ") fileanalysis.write(str(eps)) fileanalysis.write(" and q > ") fileanalysis.write(str(bound)) fileanalysis.write("\n") fileanalysis.write("*** and saving them on file recompute.txt ") fileanalysis.write("\n") # if there are cases of min < eps; compute and prints such cases # to be recomputed with quadruple precision smallvalues = len(df.loc[(df['min'] > 0) & (df['min'] < eps) & (df['q']> bound)]) if smallvalues > 0 : print('*** There are n.',smallvalues,' primes in which mq < ', eps, ' and q >', bound) print('*** recompute them with quadruple precision ***') fileanalysis.write("*** There are n.") fileanalysis.write(str(smallvalues)) fileanalysis.write(" primes in which mq < ") fileanalysis.write(str(eps)) fileanalysis.write(" and q > ") fileanalysis.write(str(bound)) fileanalysis.write("\n") fileanalysis.write("*** recompute them with quadruple precision ***") fileanalysis.write("\n") df['small'] = (df['min'] > 0) & (df['min'] < eps) #print(df['small']) listOfPositions = getIndexes(df, True) filerecomp= open("recompute.txt","w") for i in range(len(listOfPositions)): #print(i+1, ': q = ', df['q'].iloc[listOfPositions[i][0]]) filerecomp.write(str(df['q'].iloc[listOfPositions[i][0]])) filerecomp.write("\n") #print(df['q'].iloc[listOfPositions[i][0]]) # print (listOfPositions) # remove the temporary column del df['small'] filerecomp.close() else: print(' No values mq <', eps, 'with q>', bound, 'detected') fileanalysis.write(" No values mq < ") fileanalysis.write(str(eps)) fileanalysis.write(" with q> ") fileanalysis.write(str(bound)) fileanalysis.write(" detected") fileanalysis.write("\n") else: print('*** Not detecting values <', eps) fileanalysis.write("*** Not detecting values < ") fileanalysis.write(str(eps)) fileanalysis.write("\n") # function to check the lower and upper bounds; flagbounds is boolean; # uses the previous locator function def checkbounds(flagbounds): if flagbounds : ## UPPER BOUND Lamzouri-Li-Sound print('*** Detecting values mq >= ubound(q) = 5 L1/g(q) and saving them on file uexcept.txt') fileanalysis.write("*** Detecting values mq >= ubound(q) = 5 L1/g(q) and saving them on file uexcept.txt") fileanalysis.write("\n") # if there are cases of mq >= ubound(q) = 5 L1/g(q); compute and prints such cases uboundexceptions = len(df.loc[(df['min'] >= ubound(df['q']))]) if uboundexceptions > 0 : print('*** There are n.',uboundexceptions,' primes for which mq >= ubound(q) = 5 L1/g(q)') fileanalysis.write("*** There are n.") fileanalysis.write(str(uboundexceptions)) fileanalysis.write(" primes for which mq >= ubound(q) = 5 L1/g(q)") fileanalysis.write("\n") df['uboundexcep'] = (df['min'] >= ubound(df['q'])) listOfPositions = getIndexes(df, True) fileuexcept= open("uexcept.txt","w") for i in range(len(listOfPositions)): #print(i+1, ': q = ', df['q'].iloc[listOfPositions[i][0]]) fileuexcept.write(str(df['q'].iloc[listOfPositions[i][0]])) fileuexcept.write("\n") #print(df['q'].iloc[listOfPositions[i][0]]) # print (listOfPositions) # remove the temporary column del df['uboundexcep'] fileuexcept.close() else: print(' No primes for which mq >= ubound(q) = 5 L1/g(q) detected') fileanalysis.write(" No primes for which mq >= ubound(q) = 5 L1/g(q) detected ") fileanalysis.write("\n") ## LOWER BOUND Lamzouri-Li-Sound print('*** Detecting values mq <= lbound(q) = 2.35 L1/g(q) and saving them on file lexcept.txt') fileanalysis.write("*** Detecting values mq <= lbound(q) = 2.35 L1/g(q) and saving them on file lexcept.txt") fileanalysis.write("\n") # if there are cases of mq <= lbound(q); compute and prints such cases lboundexceptions = len(df.loc[(df['min'] <= lbound(df['q']))]) if lboundexceptions > 0 : print('*** There are n.',lboundexceptions,' primes for which mq <= lbound(q)= 2.35 L1/g(q)') fileanalysis.write("*** There are n.") fileanalysis.write(str(lboundexceptions)) fileanalysis.write(" primes for which mq <= lbound(q)= 2.35 L1/g(q)") fileanalysis.write("\n") df['lboundexcep'] = (df['min'] <= lbound(df['q'])) listOfPositions = getIndexes(df, True) filelexcept= open("lexcept.txt","w") for i in range(len(listOfPositions)): #print(i+1, ': q = ', df['q'].iloc[listOfPositions[i][0]]) filelexcept.write(str(df['q'].iloc[listOfPositions[i][0]])) filelexcept.write("\n") #print(df['q'].iloc[listOfPositions[i][0]]) #print (listOfPositions) # remove the temporary column del df['lboundexcep'] filelexcept.close() else: print(' No primes for which mq <= lbound(q) = 2.35 L1/g(q) detected') fileanalysis.write(" No primes for which mq <= lbound(q) = 2.35 L1/g(q) detected ") fileanalysis.write("\n") # ## UPPER BOUND with LLI # print('*** Detecting values mq >= LLI-ubound(q)= 2 L1/loglog q and saving them on file uexceptLLI.txt') fileanalysis.write("*** Detecting values mq >= LLI-ubound(q)= 2 L1/loglog q and saving them on file uexceptLLI.txt") fileanalysis.write("\n") # if there are cases of mq >= LLI-ubound(q); compute and prints such cases uboundexceptions = len(df.loc[(df['min'] >= LLI_upp(df['q']))]) if uboundexceptions > 0 : print('*** There are n.',uboundexceptions,' primes for which mq >= LLI-ubound(q)= 2 L1/loglog q') fileanalysis.write("*** There are n.") fileanalysis.write(str(uboundexceptions)) fileanalysis.write(" primes for which mq >= LLI-ubound(q)= 2 L1/loglog q ") fileanalysis.write("\n") df['uboundexcep'] = (df['min'] >= LLI_upp(df['q'])) listOfPositions = getIndexes(df, True) fileuexcept= open("uexceptLLI.txt","w") for i in range(len(listOfPositions)): #print(i+1, ': q = ', df['q'].iloc[listOfPositions[i][0]]) fileuexcept.write(str(df['q'].iloc[listOfPositions[i][0]])) fileuexcept.write("\n") #print(df['q'].iloc[listOfPositions[i][0]]) # print (listOfPositions) # remove the temporary column del df['uboundexcep'] fileuexcept.close() else: print(' No primes for which mq >= LLI-ubound(q) = 2 L1/loglog q detected') fileanalysis.write(" No primes for which mq >= LLI-ubound(q) = 2 L1/loglog q detected ") fileanalysis.write("\n") ## LOWER BOUND with LLI print('*** Detecting values mq <= LLI-lbound(q) = 1.13 L1/loglog q and saving them on file lexcept.txt') fileanalysis.write("*** Detecting values mq <= LLI-lbound(q)= 1.13 L1/loglog q and saving them on file lexceptLLI.txt") fileanalysis.write("\n") # if there are cases of mq <= LLI-lbound(q); compute and prints such cases lboundexceptions = len(df.loc[(df['min'] <= LLI_low(df['q']))]) if lboundexceptions > 0 : print('*** There are n.',lboundexceptions,' primes for which mq <= LLI-lbound(q)= 1.13 L1/loglog q') fileanalysis.write("*** There are n.") fileanalysis.write(str(lboundexceptions)) fileanalysis.write(" primes for which mq <= LLI-lbound(q) = 1.13 L1/loglog q ") fileanalysis.write("\n") df['lboundexcep'] = (df['min'] <= LLI_low(df['q'])) listOfPositions = getIndexes(df, True) filelexcept= open("lexceptLLI.txt","w") for i in range(len(listOfPositions)): #print(i+1, ': q = ', df['q'].iloc[listOfPositions[i][0]]) filelexcept.write(str(df['q'].iloc[listOfPositions[i][0]])) filelexcept.write("\n") #print(df['q'].iloc[listOfPositions[i][0]]) #print (listOfPositions) # remove the temporary column del df['lboundexcep'] filelexcept.close() else: print(' No primes for which mq <= LLI-lbound(q)= 1.13 L1/loglog q detected') fileanalysis.write(" No primes for which mq <= LLI-lbound(q)= 1.13 L1/loglog q detected ") fileanalysis.write("\n") else: print('*** Not checking lower and upper bounds') fileanalysis.write("*** Not checking lower and upper bounds ") fileanalysis.write("\n") # open output fileanalysis fileanalysis= open("../analysis.txt","w") # input data from csv fileanalysis data=pd.read_csv(r'MinL-result.csv', sep=';',dtype='str') data.head(3) df = pd.DataFrame(data, columns= ['q','even','odd']) df = df.astype('float128') # create a new column with min values between even and odd df['min'] = df[['even','odd']].min(axis=1) # create a new column with normalised min values df['norm'] = (g(df['q']) * df['min']) # create a new column with LLI values df['LLI'] = (h(df['q']) * df['min']) #print (df) #FINDING MAX AND MIN and where they are attained #M=df['min'].max() #idxM=df['min'].idxmax() #argM=df['q'].iloc[idxM] #m=df['min'].min() #idxm=df['min'].idxmin() #argm=df['q'].iloc[idxm] #print('minimal value on column min =',m,'attained at q =',argm) #print('maximal value on column min =',M,'attained at q =',argM) #FINDING MAX and second MAX; MIN and second MIN; and where they are attained print(' ***** Statistics for MinL *****') print('name source fileanalysis = MinL-result.csv') fileanalysis.write(" ***** Statistics for MinL ***** ") fileanalysis.write("\n") fileanalysis.write("name source fileanalysis = MinL-result.csv") fileanalysis.write("\n") print(' ***** MAX *****') maxima =df['min'].nlargest(2) M=maxima.iloc[0] idxM=maxima.idxmax() argM=df['q'].iloc[idxM] M1=maxima.iloc[1] idxM1=maxima.idxmin() argM1=df['q'].iloc[idxM1] print('maximal value on column min =',M,'attained at q =',argM) print('second maximal value on column min =',M1,'attained at q =',argM1) fileanalysis.write(" ***** MAX *****\n") fileanalysis.write("maximal value on column min = ") fileanalysis.write(str(M)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argM)) fileanalysis.write("\n") fileanalysis.write("second maximal value on column min = ") fileanalysis.write(str(M1)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argM1)) fileanalysis.write("\n") print(' ***** MIN *****') minima =df['min'].nsmallest(2) m=minima.iloc[0] idxm=minima.idxmin() argm=df['q'].iloc[idxm] m1=minima.iloc[1] idxm1=minima.idxmax() argm1=df['q'].iloc[idxm1] print('minimal value on column min =',m,'attained at q =',argm) print('second minimal value on column min =',m1,'attained at q =',argm1) fileanalysis.write(" ***** MIN *****\n") fileanalysis.write("minimal value on column min = ") fileanalysis.write(str(m)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argm)) fileanalysis.write("\n") fileanalysis.write("second minimal value on column min = ") fileanalysis.write(str(m1)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argm1)) fileanalysis.write("\n") print(' ***** MAX normalised values min*g(q) *****') maxima =df['norm'].nlargest(2) M=maxima.iloc[0] idxM=maxima.idxmax() argM=df['q'].iloc[idxM] M1=maxima.iloc[1] idxM1=maxima.idxmin() argM1=df['q'].iloc[idxM1] print('maximal value on column norm =',M,'attained at q =',argM) print('second maximal value on column norm =',M1,'attained at q =',argM1) fileanalysis.write(" ***** MAX normalised values min*g(q) *****\n") fileanalysis.write("maximal value on column norm = ") fileanalysis.write(str(M)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argM)) fileanalysis.write("\n") fileanalysis.write("second maximal value on column norm = ") fileanalysis.write(str(M1)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argM1)) fileanalysis.write("\n") print(' ***** MIN normalised values min*g(q) *****') minima =df['norm'].nsmallest(2) m=minima.iloc[0] idxm=minima.idxmin() argm=df['q'].iloc[idxm] m1=minima.iloc[1] idxm1=minima.idxmax() argm1=df['q'].iloc[idxm1] print('minimal value on column norm =',m,'attained at q =',argm) print('second minimal value on column norm =',m1,'attained at q =',argm1) fileanalysis.write(" ***** Min normalised values min*g(q) *****\n") fileanalysis.write("minimal value on column norm = ") fileanalysis.write(str(m)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argm)) fileanalysis.write("\n") fileanalysis.write("second minimal value on column norm = ") fileanalysis.write(str(m1)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argm1)) fileanalysis.write("\n") print(' ***** MAX of min* log log q *****') maxima =df['LLI'].nlargest(2) M=maxima.iloc[0] idxM=maxima.idxmax() argM=df['q'].iloc[idxM] M1=maxima.iloc[1] idxM1=maxima.idxmin() argM1=df['q'].iloc[idxM1] print('maximal value on column min*loglogq =',M,'attained at q =',argM) print('second maximal value on column min*loglogq =',M1,'attained at q =',argM1) fileanalysis.write(" ***** MAX of min* log log q *****\n") fileanalysis.write("maximal value on column min*loglogq = ") fileanalysis.write(str(M)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argM)) fileanalysis.write("\n") fileanalysis.write("second maximal value on column min*loglogq = ") fileanalysis.write(str(M1)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argM1)) fileanalysis.write("\n") print(' ***** MIN of min* log log q *****') minima =df['LLI'].nsmallest(2) m=minima.iloc[0] idxm=minima.idxmin() argm=df['q'].iloc[idxm] m1=minima.iloc[1] idxm1=minima.idxmax() argm1=df['q'].iloc[idxm1] print('minimal value on column min*loglogq =',m,'attained at q =',argm) print('second minimal value on column min*loglogq =',m1,'attained at q =',argm1) fileanalysis.write(" ***** Min of min* log log q *****\n") fileanalysis.write("minimal value on column min*loglogq = ") fileanalysis.write(str(m)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argm)) fileanalysis.write("\n") fileanalysis.write("second minimal value on column min*loglogq = ") fileanalysis.write(str(m1)) fileanalysis.write(" attained at q = ") fileanalysis.write(str(argm1)) fileanalysis.write("\n") print(' ***** STATS MinL *****') # number of odd > even for MinL total=float(len(df)) oddgreatereven = len(df.loc[df.odd > df.even]) percent=float(oddgreatereven)/total print('number of odd > even :', oddgreatereven,'percentage =', percent*100) fileanalysis.write(" ***** STATS MinL *****\n") fileanalysis.write("number of odd > even : ") fileanalysis.write(str(oddgreatereven)) fileanalysis.write(" percentage = ") fileanalysis.write(str(percent*100)) fileanalysis.write("\n") # number of even > odd for MinL evengreaterodd = len(df.loc[df.even > df.odd]) percent=float(evengreaterodd)/total print('number of even > odd :',evengreaterodd,'percentage =', percent*100) fileanalysis.write("number of even > odd : ") fileanalysis.write(str(evengreaterodd)) fileanalysis.write(" percentage = ") fileanalysis.write(str(percent*100)) fileanalysis.write("\n") # number of even = odd for MinL evenequalodd = len(df.loc[df.even == df.odd]) percent=float(evenequalodd)/total print('number of even = odd :',evenequalodd,'percentage =', percent*100) fileanalysis.write("number of even = odd : ") fileanalysis.write(str(evenequalodd)) fileanalysis.write(" percentage = ") fileanalysis.write(str(percent*100)) fileanalysis.write("\n") print('total number (oddgreatereven+evengreaterodd) =', oddgreatereven+evengreaterodd) print('total number (evenequalodd) =', evenequalodd) print('total number (number of rows) =', int(total)) fileanalysis.write("total number (oddgreatereven+evengreaterodd) = ") fileanalysis.write(str(oddgreatereven+evengreaterodd)) fileanalysis.write("\n") fileanalysis.write("total number (evenequalodd) = ") fileanalysis.write(str(evenequalodd)) fileanalysis.write("\n") fileanalysis.write("total number (number of rows) = ") fileanalysis.write(str(int(total))) fileanalysis.write("\n") # if there are cases of even == odd; compute and prints such cases if evenequalodd > 0: # create a new (temporary) column with difference even-odd df['even - odd'] = (df['even'] - df['odd']) # Get list of index positions i.e. row & column of all occurrences of 0 in the dataframe listOfPositions = getIndexes(df, 0) print('Primes in which even==odd (prints zero occurrences in even - odd column) : ') print('*** recompute them with quadruple precision ***') for i in range(len(listOfPositions)): print(i+1, ': q = ', df['q'].iloc[listOfPositions[i][0]]) # print (listOfPositions) # remove the temporary column del df['even - odd'] #checking for small values checksmallvalues(flagsmall, eps, bound) #checking for lower and upper bounds checkbounds(flagbounds) # number of even > 1 for MinL greater1 = len(df.loc[df.even > 1]) if greater1 > 0 : print(' ***** Possible wrong datas *******') print('number of even > 1 :',greater1,'percentage =', percent*100) # number of odd > 1 for MinL greater1 = len(df.loc[df.odd > 1]) if greater1 > 0 : print(' ***** Possible wrong datas *******') print('number of odd > 1 :',greater1,'percentage =', percent*100) print(' ***** Exported data frame for gnuplot *****') print(' ***** in fileanalysis named: MinL-result.txt *****') df.to_csv (r'MinL-result.txt', sep='\t', index = False, header=True) print(' ***** End analysis script *****') fileanalysis.write("***** End analysis script *****") fileanalysis.close()