# The code below focuses on record values for x in x^2-py^2=-2. # PLy is the known initial segment of the record list # startp is the prime to start the search at # m is the number of rounds to go, cycling through larger primes. def recordxmin2primelistextend(PL, startp, m): pr = startp # Set the beginning prime value k = len(PL) # Compute the number of items in the given list print("Number of initial data points is", k) # Announce the current number of data points R = PL[k-1][1] # Find the current record x-value in the list PL p = PL[k-1][0] # Find the current record prime in the list PL NEW = 0 # Set the number of new data points at 0 NList = [] # Initiate an empty list for the new data for i in range(m+1): # Start running through the next m prime numbers pr = next_prime(pr) # Increase the prime number from the current value K. = QuadraticField(pr) # Call on the mathematical technology needed cf = continued_fraction(sqrtpr); # Find the continued fraction of sqrt of prime kk = cf.period() # Find the period of the continued fraction mm = len(kk)+1 # Find the length mm of the period for i in range(2*mm+1): # Search solution among first 2mm+1 convergents ppr = cf.convergent(i).numerator() # x-value of convergent i qqr = cf.convergent(i).denominator() # y-value of the convergent i if (ppr^2 - pr*qqr^2 == -2): # If x^2 - p y^2 = -2, x is a candidate if (ppr>R): # If this x exceeds the current record value, NList = NList + [(pr, ppr)] # extend the new data list by a new term (p, x) R = ppr # Update the record value of x NEW = NEW+1 # Increase the new data count by 1 break else: # If the x is not a record, break # End the search for this prime number print("Number of new data points", NEW) # When all is done, say how many new data points print("Start Prime", pr) return(pr, NList)