A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Despite their seemingly simple nature, there are still many unknowns about primes which makes them an always interesting topic to discuss. One of my favorite topics in primes are Prime Sieves, which are methods by which one could generate a list of primes rather easily.
In this brief article I would go over the Sieve of Eratosthenes, it's simplicity, a couple of simple ways to make it into an even more efficient Sieve, the Sieve of Sundaram, and the connection between those 2 sieves that was not at all obvious to me at first sight.
Eratosthenes lived more than 2000 years ago and was a man of many talents as he was a mathematician, poet, astronomer, music theorist, and of course a geographer since he invented the discipline of geography. however he is best known for being the first person to calculate the circumference of the Earth (with about 15% margin of error but I dare you to do any better with 2000 year old technology)
His Prime Sieve method is extremely simple. Start with a list all numbers from to with all of them unmarked.
Go to the first unmarked number and you get your first prime: , then simply mark every number of the form
Now go to next unmarked number and you get your second prime: , then simply mark every number of the form
Now go to next unmarked number and you get your third prime: ,then simply mark every number of the form
And so on...
doing this would mark all composite numbers but would leave all the prime numbers unmarked, to be later collected.
The Sieve of Eratosthenes also hides within in a rather large simplification: to get all prime numbers up to you only need to check all numbers up to and no further.
Why ? well simply because if you divide by a number larger than it's square root you get a number which is by definition smaller than it's square root, and since you have already checked all numbers beneath to see if they are primes or not, and have also marked all of their multiples, no further information is gained.
Another way to look at it is to observe that if you have a list of all primes numbers then you can derive from it the list of all prime numbers up to . this is because all numbers that are smaller than must have a factor that is smaller than which by the definitions of the primes must mean that it's either a prime or can be divided by another prime smaller than it. As such, if in our Eratosthenes Sieve we reach we can confidently say that we have generated all prime numbers up to the-next-prime-number, and since this prime is bigger or equal to we have generated all prime numbers up to
If you have a mind like Eratosthenes you might have noticed a way to simplify our sieve even further. since each list up to gives us all primes up to we don't need to go over all the numbers between and when we mark the multiples of since they would be already marked.
For example let's say that our Eratosthenes Sieve algorithm has already generated the prime list and is just reaching . according to our original statement the algorithm now needs to mark all multiples of which are . but since we already know that all numbers up to are either primes or composites of primes smaller than we can start marking all multiples of from onward and skip entirely.
As you can see this Sieve is extremely efficient at what it does.
Another useful sieve is the Sieve of Sundaram which can generate all prime numbers with the exception of 2. This sieve was only discovered in 1934 by Indian mathematician S. P. Sundaram, so it's a quite recent addition to prime research mathematics.
It's basic principle is simple:
each odd number can be written as a multiple of 2 other odd numbers . multiplying them gives us
With the exception of 2 every prime number is an odd number and can only be written only as so that . As such as long as or does not equal any odd number of the form is an odd composite.
And so by iterating over all natural numbers in we could get all numbers where would be a odd composite. While on the other hand, the list we would be left after removing all : would be all the numbers where .
I would call all Sundaram Numbers and all Non Sundaram Numbers.
the first 25 Sundaram Numbers are
and the first 25 Non Sundaram Numbers are
At first it seems like there is no way to generate the Sundaram Numbers other than using 2 numbers but what I have recently learned by experimenting with them is that there is a quite simple and (an after the fact obvious) way of generating the Sundaram Numbers from the Non Sundaram Numbers . And the most striking aspect of that method is that it's only a slight variation of the Sieve of Eratosthenes.
First I'll present the Eratosthenes-Sundaram sieve and later on would give a full explanation of why it works.
Start with a list all numbers from to with all of them unmarked.
Go to the first unmarked number and you get your first Non Sundaram Number: , then simply mark every number of the form
Now go to next unmarked number and you get your second Non Sundaram Number: , then simply mark every number of the form
Now go to next unmarked number and you get your third Non Sundaram Number: , then simply mark every number of the form
Now go to next unmarked number and you get your fourth Non Sundaram Number: , then simply mark every number of the form
And so on...
At the end, all marked numbers would be the Sundaram Numbers and all unmarked numbers would be the Non Sundaram Numbers.
So why is it so?
First either list that is given to us by the Sundaram Numbers or Non Sundaram Numbers is a list of natural odd numbers that were reduced by and divided by .
So if we have a list of natural odd numbers (excluding )
the list our algorithm would be given would be
Or vice versa we could say that
From this we could easily observe that any addition we might do in the second list would be doubled in the first list. For example if in we do then in it would be translated to
Now assuming we would have wanted to use our original Sieve of Eratosthenes on we would see that all numbers of the form would be gone and as such in the process of getting to the next unmarked number instead of marking every number of the form we would only need to mark every second number which is of the form . we already know that the list obtained would be either marked odd composites or unmarked primes. Translating it to would give us either marked Sundaram Numbers or unmarked Non Sundaram Numbers.
Translating this to where
As you can see it seems like the sieve Sundaram discovered was hidden in plain site for 2000 years for all to see, but only recently has been pointed out. Those hidden connections are what makes math fun to research and discover.