<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 The largest prime (so far)
A new record for the largest prime has been found lately. Let explore this number and know more about it and how to deal with it using some Python, Numpy and finally using we will take a loog at Cython and GMP.
Step1:  This number of was found in 2016 using the Great Internet Mersenne Prime Search (GIMPS). This prime is one of the Mersenne Prime whice are of the defined by the following formula
Step2:  The smallest none-prime (composite) number is $2^{11}-1=2047$ which is a composite number.
Step3:  The largest prime number is that was found lately is
Step4:  Lucasâ€“Lehmer test
A very easy way to test a Mersenne Prime is the Lucas-Lehmer test which uses the Lucas series.
$4, 14, 37634 ... $
The series starts with 4 then uses the last value in this formula
Step5:  The test is if the Mersenne Prime number of $n^2-1$ is a divided by $S_{n-2}$ you should get a remaining of 0. The problem is this series goes very large very fast. So there is another way to do this test.
<ASSISTANT_TASK:>
Python Code:
import numpy as np
import math
from datetime import datetime
%load_ext Cython
Explanation: The largest prime (so far)
A new record for the largest prime has been found lately. Let explore this number and know more about it and how to deal with it using some Python, Numpy and finally using we will take a loog at Cython and GMP.
End of explanation
2**2-1
2**3-1
2**5-1
2**7-1
Explanation: This number of was found in 2016 using the Great Internet Mersenne Prime Search (GIMPS). This prime is one of the Mersenne Prime whice are of the defined by the following formula:
$$2^p-1$$
Where $p$ is a prime number. This is called a psudo-prime meaning not all Mersenne Prime are primes.
$2^2-1=3$
$2^3-1=7$
$2^5-1=31$
$2^7-1=127$   ...
End of explanation
2**11-1
Explanation: The smallest none-prime (composite) number is $2^{11}-1=2047$ which is a composite number.
End of explanation
p = 74207281
the_number = (2 ** p) - 1
Explanation: The largest prime number is that was found lately is:
$$2^{74,207,281}-1$$
The reason why I didn't put the actual value is that the number if very large (over 22 million digits).
End of explanation
S = 4
print(S)
print(len(str(S)))
S = S ** 2 - 2
print(S)
print(len(str(S)), "digits")
S = S ** 2 - 2
print(S)
print(len(str(S)), "digits")
S = S ** 2 - 2
print(S)
print(len(str(S)), "digits")
S = S ** 2 - 2
print(S)
print(len(str(S)), "digits")
S = S ** 2 - 2
print(S)
print(len(str(S)), "digits")
# The largest prime (so far)
the_number = 2 ** 74207281 - 1
print(int(math.log10(the_number))+1, "digits")
Explanation: Lucasâ€“Lehmer test
A very easy way to test a Mersenne Prime is the Lucas-Lehmer test which uses the Lucas series.
$4, 14, 37634 ... $
The series starts with 4 then uses the last value in this formula:
$S_i=S_{i-1}^2-2$
End of explanation
p = 74207281
the_number = (2 ** p) - 1
S = 4
time_stamp = datetime.now()
for i in range(p-2):
    S = (S ** 2 - 2) % the_number
    if i % 1 == 0:
        print(i, datetime.now() - time_stamp,"")
        time_stamp = datetime.now()
if S == 0:
    print("PRIME")
%%cython
cdef unsigned long p = 61
cdef unsigned long P = (2 ** p) - 1
S = 4
for i in range(p-2):
    S = S ** 2 - 2
    S = S % P
    if i % 10 == 0:
        print(i)
if S == 0:
    print("PRIME")
%%cython --link-args=-lgmp
cdef extern from "gmp.h":
    ctypedef struct mpz_t:
        pass
    
    ctypedef unsigned long mp_bitcnt_t
    
    cdef void mpz_init(mpz_t)
    cdef void mpz_init_set_ui(mpz_t, unsigned int)
    
    cdef void mpz_add(mpz_t, mpz_t, mpz_t)
    cdef void mpz_add_ui(mpz_t, const mpz_t, unsigned long int)
    
    cdef void mpz_sub (mpz_t, const mpz_t, const mpz_t)
    cdef void mpz_sub_ui (mpz_t, const mpz_t, unsigned long int)
    cdef void mpz_ui_sub (mpz_t, unsigned long int, const mpz_t)
    
    cdef void mpz_mul (mpz_t, const mpz_t, const mpz_t)
    cdef void mpz_mul_si (mpz_t, const mpz_t, long int)
    cdef void mpz_mul_ui (mpz_t, const mpz_t, unsigned long int)
    
    cdef void mpz_mul_2exp (mpz_t, const mpz_t, mp_bitcnt_t)
    
    cdef void mpz_mod (mpz_t, const mpz_t, const mpz_t)
    
    cdef unsigned long int mpz_get_ui(const mpz_t)
#cdef unsigned long p = 61
cdef mp_bitcnt_t p = 74207281
cdef mpz_t t # = 1
cdef mpz_t a # = 1
cdef mpz_t P # = (2 ** p) - 1
cdef mpz_t S # = 4
mpz_init(t)
mpz_init_set_ui(t, 1)
mpz_init(a)
mpz_init_set_ui(a, 2)
mpz_init(P)
mpz_mul_2exp(P,t,p)
mpz_sub_ui(P,P,1)
mpz_init(S)
mpz_init_set_ui(S, 4)
for i in range(p-2):
    #S = S ** 2 - 2
    mpz_mul(S,S,S)
    mpz_sub_ui(S,S,2)
    
    #S = S % P
    mpz_mod(S,S,P)
    
    if i % 1000 == 0:
        print(i)
if mpz_get_ui(S) == 0:
    print("PRIME")
else:
    print("COMPOSITE")
#print(mpz_get_ui(P))
Explanation: The test is if the Mersenne Prime number of $n^2-1$ is a divided by $S_{n-2}$ you should get a remaining of 0. The problem is this series goes very large very fast. So there is another way to do this test.
End of explanation
<END_TASK>