Overview

Mersenne exponent set: (Me)

A Mersenne exponent is an integer n such that 2n-1 is prime. link

Mersenne number set (Mn)

A Mersenne number is an integer in the form 2n-1, where n is any positive integer. link

Mersenne prime number set (Mp)

A Mersenne prime is a prime number in the form 2p-1, where p is prime. link

Prime number set (Pn)

A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers link

  • Mersenne exponent

    The set of Mersenne exponents is a subset of the prime number set defined in the above headers. When these specific exponents, n, are plugged into the Mersenne number with form 2n-1, the result will be a Mersenne prime.

  • Mersenne number

    Mersenne primes and Mersenne numbers are named after Marin Mersenne, a french scholar from the 1700s. Originally, Mersenne had the list of Mersenne Primes and Mersenne numbers incorrect. The set of primes contained composite numbers (Ex: M67, M257) while the set of composite numbers contained some prime numbers (Ex: M61, M281). Later, Edouard Lucas corrected for these smaller numbers using theories that we will show below.

    The mersenne number set is eclipsed by its own subset the Mersenne Primes. Much research is being conducted to find the next largest prime (GIMPS). Of course this would not be possible without Mersenne numbers.

    Mersenne numbers that are not prime, are composite Mersenne numbers. These are commonly factored to down to a product of primes. Ex: 211-1 = 2047 = 23x89

  • Mersenne prime number

    The star of the show, Mersenne numbers have a great spotlight in the prime number research space. A subset of the Mersenne numbers, these prime numbers are of the form 2p-1, where p is a prime.

    Highest known Mersenne Prime Mp is 51 (M51), which was found in December 2018. This is now the largest known prime, which is represented by 282,589,933-1. This new prime contains 24,862,048 digits. That looks like this.

    The highest confirmed Mersenne prime is M47. It is one thing to calculate the prime, but confirming the number requires factorization and traditional methods that would normally be used to evaluate prime numbers. This must be done to confirm the original calculation. Along with the traditional factorization and confirmation of the lower level exponents, a recalculation is done with shifted bits to validate

  • Prime number

    Using Mersenne primes, we are able to calculate the largest known primes. Large primes have many uses in the real world and theoretical world.

Prime Generator

N-th Prime Calculator

This calculator will return the n-th prime from a set of primes calculated with the Sieve of Eratothenes

We can also find a list of the first 1000 primes here

  • Total Mersenne Exponents: 47 (Found in the set at the top of the page)
  • Total regular primes calculated: 57 Calculate Primes

Enter the index n for the desired prime:

Pn(1) is 2

Pseudocode:

//algorithm Sieve of Eratosthenes is
input: an integer n > 1.
output: all prime numbers from 2 through n.

let A be an array of Boolean values,
indexed by integers 2 to n, initially all set to true.

for i = 2, 3, 4, ..., not exceeding √n do
  if A[i] is true
    for j = i2, i2+i, i2+2i, i2+3i, ..., not exceeding n do
      A[j] := false
return all i such that A[i] is true.

Implementation (Js):

//execute sieve given max as upperbound
function fn(max){
  array = new Array(max);
  for(var i = 0; i < array.length; i++){
    array[i] = true;
  for(var p = 2; p*p < max; p++){
    if(array[p] == true){
      for(var i = p*p; i < max; i+=p){
        array[i] = false;
    }
  }
  for(var p = 2; p < max; p++){
    if(array[p] == true){
      primes.push(p);
  }
}

Sieve of Eratothenes

The Sieve of Eratosthenes is an ancient algorithm that eliminates all composite numbers up to a given number. It is thought that the Greek Mathmatician Eratosthenes of Cyrene is the one to have used it first.

Algorithm desc. The algorithm works by creating a list of booleans from 2 to the upper bound. It then does iterates to the upper bound, checking every element in the boolean array if it is true or false. If it hits an element that is true, then it will iterates over every multiple of that number setting the respective index to false in the boolean list. If it hits false, then another smaller integer was a multiple of that index and it was set to false, skipping to the next list element. At the end, iterate through the boolean list, save all of the indexes of the "true" values. These indexes are the primes from 2 to the upper bound.

Time complexity = O(n(log(logn)))

"Sift the Two's and Sift the Three's, The Sieve of Eratosthenes. When the multiples sublime, The numbers that remain are Prime." - Anonymous

Mersenne Calculator

Mersenne calculator

This calculator will have restricted calculation bounds due to machine and browser limitations. (p > 21701 will be taxing)


Input value n for: 2p-1 where p is a prime

Output from calculating 23-1 is:

(a Mersenne prime!)
7

To check if a Mersenne number is prime we can use the Lucas Lehmer primality test as defined below.

Pseudocode:

// Determine if Mp = 2p − 1 is prime for p > 2
Lucas–Lehmer(p)
var s = 4
var M = 2p − 1
repeat p − 2 times:
  s = ((s × s) − 2) mod M
if s == 0 return PRIME else return COMPOSITE

Implementation (Js):

//Logic for the Mersenne Prime test given the prime p
function lucasLehmerPrime(p){
  var mersenneVal = (2**p)-1;
  var nextVal = 4 % mersenneVal
  for(var i = 1; i < p-1; i++){
    nextVal = (nextVal*nextVal-2) % mersenneVal;
  }
  return nextVal==0;
}

Lucas–Lehmer primality test

LLPT was developed by Edouard Lucas in 1856, and later improved by Lucas in 1878, lastly by Derrick Lehmer in the 1930s. Its most famous application is in GIMPS, the Great Internet Mersenne Prime Search.

The LLPT algorithm has an efficient time-complexity for computational execution. Due to the fact that the iterations only execute up to p-2, the largest known prime would have taken 80 million execution cycles. This can be done relatively quickly on a modern computer. Where the algorithm is least efficient is in the mathmatical operation of 2p-1. This exponent calculation is sort of a hidden algorithm, it is executed in the background by iteratively multiplying 2 together. In applications like GIMP, other algorithms are implemented to square these huge numbers and divide related work loads.

Lucas-Lehmer sequence can be seen here (s2-2): 4, 42-2=14, 142-2=194, ...

Mersenne Binary Calculator

Binary representation of Mersenne Primes and Mersenne Numbers

Input a number to generate of term of n digits of "1". This will binary number that will be a prime or a Mersenne prime

  • Input "11", "89", and "127" to see examples of primes and Mersenne primes. This will also demonstrate simplification of terms as the exponent grows larger.
  • For fun, try higher values like the Mersenne exponent: 21701. It may take a short while to load... but it will. The fact that this extremely large value can be confirmed by the LLPT (in a browser!) blew my mind.

1112 =
710
(A Mersenne prime!)

Binary to Decimal Breakdown:
(22)+(21)+(20)

Note: Once the decimal value surpasses BigInt size, precision is lost and Mersenne primes will not be checked correctly.

Pseudocode:

// Convert binary number n into its decimal representation
BinaryToDecimal(n)
  var decimal = 0
  for i=0, 0 to n.length times:
    decimal = decimal + 2i
    increment i
  return decimal

Implementation (Js):

//base2 to base10 conversion
//given b, the number of binary digits
function fn(b){
  var binDecimalVal = 0;
  for(var i = 0; i < b; i++){
    binDecimalVal += 2n**i;
  }
  //update new variables
  //update UI
}
  • Mersenne Prime representations in binary:

    • 112 = 310
    • 1112 = 710
    • 111112 = 3110
    • 11111112 = 12710
    • 11111111111112 = 819110
    • . . .

Binary to Decimal Conversion

The actual implementation for the calculator above has been optimized to only calculate the difference from the previous number instead of a complete recalculation.

The binary representation of 2n-1 is n repitions of the digit 1. This can be extended to Mersenne primes where 2p-1 is p repitions of the digit 1, p being a Mersenne exponent.

This is because 2n creates a term with single digit of "1" followed by n digits of "0"
When 1 is taken away from this term, the term becomes n-1 digits of "1". In other words, the leading 1 is removed and all the "0"s become "1"s

Ex:
(100000-1)2 = (32-1)10
= 111112 = 3110

Getting back to 100000 from 11111 is more intuitive when we apply carry-overs from the adding operation. In base-2, the highest value is 1. Adding 1+1 would create a carry over.
Ex: 1+1 = 10

Likewise, 11111+1 = 100000, as the 1 carries all the way to the front while switching the trailing "1"s into "0"s.

Interesting facts.

  • Cryptography

    Large primes are used in encryption algorithms for cyber-security. The RSA encryption system is a PRIME example, using two large prime numbers to create a product that then requires prime-factorization. Note: Mersenne primes are not ideal for RSA encryption because they are guessed easily.

  • Javascript limiations

    I learned new limitations of javascript with big integer calculations. I had to research BigInt variable declaration and the javascript runtime memory sizes.

    BigInt allows us to calculate past 2^31, as 231 is a computers max integer. 231 seems odd but they use the first bit to represent the +/- of the integer. This allows computer to have an integer range of -231 to +231 for a total of 232 integer representations.

  • The Great Internet Mersenne Prime Search (GIMPS)

    GIMPS is an ongoing initiative to identify the largest known primes using Mersenne primes. GIMPS has a free program for download that requests assignments and work loads to be ran on the host system. If a computer finds a new prime that which is later confirmed through multiple checks and validations, the user and computer are documented and put in the record list.

    Many computer and hardware enthusiasts have probably heard of the GIMPS program "prime95", as it is heavily used for stress testing computers and processor voltage/power limits.

    The latest information can be found on their homepage: mersenne.org. One of the latest updates is from a contributer, they found a way to eliminate the need for a second primality test to be done when a new prime is found. This saves 95.5% of the workload that would have originally been required.

References

    Many more readings and research to understand these concepts and the maths behind them