Tuesday, July 12, 2016

Euler's "Lucky" constant

Based on my results in the previous post regarding a prime-representing function based on Bertrand's postulate I was able to produce a new constant related with Euler's "Lucky" numbers. Initially I did not find this constant in any bibliography or reference, and it seems a nice use of a Mills-like constant. So here are the results:

Euler's "Lucky" constant $E = 2.893392257682316134127494663$

This constant is such that $\lfloor{E^{2^n}}\rfloor-(\lfloor{E^{2^{n-1}}\rfloor})^2+\frac{\lvert n-(\frac{1}{2}) \rvert}{(\frac{1}{2})-n}$ for $n=[0..5]$  provides the sequence of Euler's "Lucky" prime numbers in growing order


Euler's lucky constant E is a Mill's like constant obtained by the encapsulation of Euler's "Lucky" numbers into integers E(n) of [N,(N+1)^2] intervals. This provides a representing function of Euler's "Lucky" primes for n=[0..5].

The calculation of the sequence of elements that will be the lower bounds of the [N,(N+1)^2] intervals is as follows:

E(0)=(2)
E(1)=3+1+(E1^2) = 8
E(2)=5+1+(E2^2) = 70
E(3)=11+1+(E3^2) = 4912
E(4)=17+1+(E4^2) = 24127762
E(5)=41+1+(E5^2) = 582148899128686

And finally Euler's "Lucky" constant (E) has the following value:

E=E(5)^(1/(2^5))=2.893392257682316134127494663





The above manipulation encapsulates the "Lucky" primes into a different upper interval, so the following calculation returns the "Lucky" primes back from the representing function:

Lucky(n+1)=floor(E^(2^n))-(floor(E^(2^(n-1))))^2+(abs(n-(1/2))/((1/2)-n))
for n=0..5

Thus:

Lucky(1)=floor(E^(2^0))-(floor(E^(2^(0-1))))^2+(abs(0-(1/2))/((1/2)-0))=2

Lucky(2)=floor(E^(2^1))-(floor(E^(2^(1-1))))^2+(abs(1-(1/2))/((1/2)-1))=3

Lucky(3)=floor(E^(2^2))-(floor(E^(2^(2-1))))^2+(abs(2-(1/2))/((1/2)-2))=5

Lucky(4)=floor(E^(2^3))-(floor(E^(2^(3-1))))^2+(abs(3-(1/2))/((1/2)-3))=11

Lucky(5)=floor(E^(2^4))-(floor(E^(2^(4-1))))^2+(abs(4-(1/2))/((1/2)-4))=17

Lucky(6)=floor(E^(2^5))-(floor(E^(2^(5-1))))^2+(abs(5-(1/2))/((1/2)-5))=41

Q.E.D.


The term (abs(n-(1/2))/((1/2)-n)) is just a correction to calculate properly the initial case Lucky(1) associated with n=0 and join it to the rest of cases. The value E(0) is an special case because there is not previous term. (abs(n-(1/2))/((1/2)-n))=+1 for n=0 and =-1 for the rest of cases.

Finally, the following polynomial in two variables provides the complete set Euler primes (A196230) for n=[0..5] and x = [1..(floor(E^(2^n))-(floor(E^(2^(n-1))))^2+(abs(n-(1/2))/((1/2)-n)))-1]:

x^2-x+[floor(E^(2^n))-(floor(E^(2^(n-1))))^2+(abs(n-(1/2))/((1/2)-n))] 

I think that this is a very nice application of a Mills-like constant, we can obtain the whole set of Euler's "Lucky" numbers just using a single expression.

Thursday, July 7, 2016

A prime-representing function based on Bertrand's postulate and Mill's constant

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.