P.S.
This is a backup of my question at MSE.
Wikipedia explains in number theory,
Mills' constant is defined as:
"The smallest positive real number A such that the floor function of the double exponential function floor(A^(3^(n)) is a prime number, for all natural numbers n. This constant is named after William H. Mills who proved in 1947 the existence of A based on results of Guido Hoheisel and Albert Ingham on the prime gaps. Its value is unknown, but if the Riemann hypothesis is true, it is approximately 1.3063778838630806904686144926... (sequence
A051021 in OEIS)."
In other words floor(A^(3^(n))) is said to be a prime-representing function, because f(x) is a prime number for all positive integral values of x.
The demonstration made by Mills in 1947 (
pdf here) is very easy to follow (one must be careful about the already
known typos of the paper to follow properly the explanation).
It is also known that floor(Q^k^n) always works if k is at least 3, so there are other constants not defined yet that will work just if k is equal to or more than 3. It is also kown that k=2 might not work because it depends on the
Legendre's conjecture: is there always a prime between N2 and (N+1)^2. It it's thought to be extremely difficult.
Based on the original demonstration and using the
Bertrand's postulate as key for some manipulations I was able to find a constant L that for floor(L^2^n) provides a sequence of integers (the difference is that they are not primes directly) such as there is an associated sequence of primes obtained from them. Here is how it works:
According to Bertrand's postulate for a given prime p_i it holds:
p_i < p_j < 2p_i for some existing prime p_j
Now adding +p_i^2+1:
p_i+p_i^2+1 < p_j+p_i^2+1 < 2p_i+p_i^2+1
Which is also true for:
p_i^2 < p_j+p_i^2+1 < (p_i+1)^2
Calling e_j = p_j+p_i^2+1 it is possible to build a sequence of integers E_0, E_1,...E_n such as:
E_0=P_0=2
E_0^2 < E_1 < (E_0+1)^2
E_1^2 < E_2 < (E_1+1)^2
...
E_(n-1)^2 < E_n < (E_(n-1)+1)^2
...
The same conditions for the sequence shown in Mill's demonstration would hold for this expression, and in this case the exponent is 2 instead 3. It is possible because the sequence is not directly a sequence of primes, but a sequence of integers attached to primes by Bertrand's postulate according to the manipulation:
P_n = E_n-(E(n-1)^2-1)
An in the same fashion as Mill's constant:
E_n=floor(L^(2^(n)))
Where L is obtained after some manual calculations (up to n=11) as
L_11=1.71979778440410781908547548439826963...
The way of manually calculating the constant is as follows, in the same fashion that Mill's demonstration, the relationship between L_n (the constant calculated after knowing the nth element of the sequence E_n) and E_n is:
L_n=E_n^(1/(2^n))
These are the calculations for the first 5 elements in Excel (the accuracy of the decimals of L is not so good, but it works properly).
L slightly grows on every iteration but the growth is each time smaller, so it clearly tends to a fixed value when n tends to infinity.
(graph here)
For instance for n=1..5 floor(L^(2^(n)) is:
E_1=2
E_2=8 and P_1=E_2-(E_1)^2-1=8-2^2-1=3
E_3=76 and P_2=E_3-(E_2)^2-1=76-8^2-1=76-64-1=11
E_4=5856 and P_3=E_4-(E_3)^2-1=5856-76^2-1=5856-5776-1=79
E_5=34298594 and P_4=E_5-(E_4)^2-1=34298594-5856^2-1=5857
etc.
So in essence the prime-representing function would be:
floor(L^(2^(n))-E_(n-1) for n>=2
being the starting element of the sequence E_1=2 and L the value of L_n when n tends to infinity.
This is the Python code to calculate and test L:
def mb():
from sympy import nextprime
from gmpy2 import is_prime
import matplotlib.pyplot as plt
import matplotlib as mpl
import decimal
print("L constant test. Equivalent to Mill's constant applying Bertrand's postulate")
print("----------------------------------------------------------------------------")
print()
# Decimal precision is required, change according to test_limit
decimal.getcontext().prec = 2000
# List of elements E_n generated by L^(2^(n))
E_n = []
# List of progressive calculations of L_n, the last one of the list is the most accurate
# capable of calculate all the associated primes
L_n=[]
# List of primes obtained from L^(2^(n))-E_(n-1) associated to the Bertrand's postulate
P_n=[]
# depth of L: L will be able to calculate the primes L^(2^(n))-E_(n-1) for n=1 to test_limit-1
test_limit=12
for n in range(1,test_limit):
if n==1:
# E_1=2
E_n.append(2)
else:
# E_n=(E_(n-1)^2)+1
# Be aware that the Python list starts in index 0 and the last current element is index n-1:
# that is why n-2 appears in the calculation below
E_n.append((E_n[n-2]**(decimal.Decimal(2)))+P_n[n-2]+1)
# Next prime greater than E_n: it will be in the interval [E_(n-1),2*E_(n-1)] (Bertrand's postulate)
P_n.append(nextprime(E_n[n-1]))
# Calculation of L_n
L_n.append(E_n[n-1]**(decimal.Decimal(1)/(decimal.Decimal(2)**(decimal.Decimal(n)))))
print("List of Elements of L^(2^(n)) for n = 1 to " + str(test_limit-1) + ":")
mystr = ""
for i in E_n:
mystr=mystr+str(i)+"\t"
print(mystr)
print()
print("List of Primes obtained from L constant: L^(2^(n))-E_(n-1)-1 for n = 1 to :" + str(test_limit-1) + ":")
mystr = ""
for i in P_n:
mystr=mystr+str(i)+"\t"
print(mystr)
print()
print("List of calculations of L_n (the most accurate one is the last one) for n = 1 to :" + str(test_limit-1) + ":")
mystr = ""
ax = plt.gca()
ax.set_axis_bgcolor((0, 0, 0))
figure = plt.gcf()
figure.set_size_inches(18, 16)
n=1
for i in L_n:
mystr=mystr+str(i)+"\t"
plt.plot(n,i,"w*")
n=n+1
print(mystr)
# Print the graph of the evolution of L_n
# Clearly it tends to one specific value when n tend to infinity
plt.show()
#Testing the constant
print()
print("L Accuracy Test: using the most accurate value of L will calculate the primes associated")
print("to the constant and will compare them to the original primes used to create the constant.")
print("If they are the same ones, the constant is able to regenerate them and the theoretical background")
print("applied would be correct.")
#Using the most accurate value of L available
L = L_n[len(L_n)-1]
print()
print("L most accurated value is:")
print(L)
print()
for i in range(1,test_limit):
print()
tester = int(L**(decimal.Decimal(2)**(decimal.Decimal(i))))
if i==1:
tester_prime = 2
else:
tester_prime = decimal.Decimal(tester) - (E_n[i-2]*E_n[i-2]) - 1
print("Current calculated E:\t" + str(tester) + " for n = " + str(i))
print("Original value of E:\t" +str(E_n[i-1]) + " for n = " + str(i))
if tester == E_n[i-1]:
print("Current calculated prime:\t" + str(tester_prime) + " for n = " + str(i))
if i==1:
print("Original value of prime:\t2 for n = " + str(i))
else:
print("Original value of prime:\t" + str(P_n[i-2]) + " for n = " + str(i))
else:
# If we arrive to this point, then the constant and the theory would not be correct
print("ERROR L does not generate the correct original E")
return
print()
print("TEST FINISHED CORRECTLY: L generates properly the primes associated to the Bertrand's postulate")
mb()
Initially L=1.71979778... seems not have been defined before, but who knows. At least I was not able to find such constant Mill's constant-related papers on Internet. I find it interesting. I am trying to calculate a more accurate value of the constant (will try to update this post as soon as possible). The reality is that it is able to obtain only prime numbers if the precision is correct (in the same way as the Mill's constant).
The advantage of L versus A (the original Mill's constant) is:
1. The growing rate of the double exponential is lower due to the use of powers of 2 instead of powers of 3 or more, so for the same quantity of n values calculated L provides smaller primes than A in less time.
2. The use of L^(2^(n)) does not require the validation of Legendre's conjecture because it depend on Bertrand's postulate, so the theory would hold.
I have made a question at MSE about this calculations. According to the feedback, initially it seems that the manipulations I did for the theory are correct and could open an alternative way of calculating prime-representing functions with lower rate of growth. I am wrapping-up the ideas and preparing a paper. I will try to update this post as soon as I finish it.