Prime Density and the Chinese Remainder Theorem
Transcript
So, last time we discussed the Chinese remainder theorem, which in general form states that you are given a system of linear equations in one variable, where x is the single variable and the moduli are all different. In fact, they are mutually co-prime numbers n i's. So, this theorem says that there will always be a unique solution, and the solution is given by that expression.
And then we started analyzing how many primes there are in the range from 1 to x, which we will finish today. Any questions so far? What we will prove is that the number of primes between 1 and x, represented by the prime function π(x), has a density of π(x)/x, which is approximately between 1/log(x) and 5/log(x), where log is to base 2.
In particular, it states that the density is very high. It is 1 over log x, which is excellent for any practical application in computer science. This kind of expression was first conjectured by Gauss. In the 1800s, he did calculations by hand and guessed it by looking at the table. But the way it was proved is a long history.
You can read it on Wikipedia. So, this was used to be a conjecture by Gauss that pi times pi is around 1 over log x; simply by looking at the values for various x's, from x equal to 1 to x equal to thousands, he manually tabulated the values, which is why this strange expression.
And then, indeed, it can be shown. So, for computer science, it is enough to just do the estimate, and this will require some lemmas. So, the first lemma says that 2n choose n is at least 4 to the n divided by 2n plus 1. So, the proof of Lemma 1 is just that σ(2n choose i) is 4 to the n.
Right in which you have to show that the middle term is the largest, which is 2n choose n. So, this means that the largest term is at least the average; that is the proof that this is the maximum. Is this clear? So, all these things, you know. So, you can finish this proof. The second lemma is that if you look at the prime powers which divide 2n choose n, they never exceed 2n; although 2n choose n is very large, still the prime powers are small.
So, why is that? So, the idea is that you look at this expression. So, you are multiplying the numbers n plus 1 to 2n, n plus 1, n plus 2, dot dot 2n, and dividing by the numbers, basically n factorial. So, 1 dot 2 dot dot dot n.
So, what happens to the prime powers that divide the denominator? So, say p raised to v, p raised to i divides x for some x from 1 to n; what can you say about whether it is guaranteed that this p raised to i will also divide 2 and choose n?
What can happen is if p raised to i is present in the denominator, then it is forced to be present in the numerator also, right? Because the denominator has to divide the numerator, it is possible that p raised to i is exactly present, and so both of them cancel and p is absent; p does not divide 2 inches. In fact, that is what usually happens. So, if p raised to y divides x between 1 and n, then there exists a y in n plus 1 to 2n such that p raised to y also divides y. Why is that?
Well, because p raised to i is smaller than n, right? So, if you just look at x plus p raised to i, this is still in the range; this is still below 2n. So, there will be some number after x which will be between n plus 1 and 2n, which will also be divisible by p raised to i. So what happens is these higher powers that divide the denominator also divide some number in the numerator, and they get canceled.
So using this, you can deduce that the surviving P powers divide 2N choose N. So if P raised to V divides 2N choose N. Then basically, it is bigger than n, and it divides some number y, which is larger than n.
So, prime powers that actually survive in this division, this p raised to v must be larger than n, and it divides some number that is between n plus 1 and 2n. So, in particular, it is smaller than 2n.
Is that clear? This was too quick, but you can work on it and finish the proof. The idea is basically this: if p raised to v is dividing 2 n choose n, and if it is surviving in this ratio, it cannot be larger than 2 n, because all the extra things are actually common, so they get canceled. So, only small p raised to v's remain, which are between n plus 1 and 2 because they do not have anything to cancel within the denominator.
So, that is a quick sketch of lemma 2. So, all these prime powers are actually smaller than 2n or less than or equal to 2n, and let us do a quick sketch of lemma 3. So, here you have to show that the product of primes up to n never exceeds 4 raised to n. How do you show this?
So, for example, if you take n to be 5, then the product is 1 times 2, and you can also multiply by 5. So, 1 times 2 times 3 times 5, you can see that it is smaller than 4 raised to 5. The product of primes is usually much smaller than 4 raised to n. It is actually even smaller than 3 raised to n, but that proof will be longer. So, let me stick to 4 raised to n. How do you show this?
So, this will be shown by induction: n factorial is smaller than what? No, it is not; it is much, much bigger. Yeah, if it was that easy, then that was in assignment 1, I guess, right? n factorial, n factorial is almost close to n to the n.
But this is 4 raised to n. So, we need this for a good estimate of the density of primes. So, this is non-trivial, but not hard; what you do is we will do induction. So, the base case of induction is done, as I just said; you can check for n equal to 5. That is satisfied.
So, now, let us assume the induction hypothesis and assume it holds for, let us say, n equal to 2m plus 1.
Let us consider n equal to 2m plus 1; let us consider n to be odd, and look at the product. of primes up to 2m plus 1 that is n now.
So, this will be less than. So, we divide this into two kinds of primes; actually, what I want to do is invoke Lemma 2 here, I think. I want to divide this into two kinds of primes: primes that are smaller than m plus 1 and the other kind, which consists of primes that are between the remaining ones. I consider these two, and what do you do next?
So, for the first product, you will do induction, and for the second product, the times are between m plus 2 and 2m plus 1. What do you do with them? Let us do the first one, which is 4 raised to m plus 1, by induction, right?
Because m plus 1 is strictly smaller than n, by induction we can estimate this as 4 to the m plus 1. What do you do with the second one? So, I want to write the following: it is smaller than 2 m plus 1 choose m. Is this correct? Sorry, what in the first step?
The induction hypothesis is that the product of primes up to n is 4 to the n. I do not understand that p is less than or equal to m plus 1. Well, let us try to understand: the first bracket is p less than or equal to m plus 1, and the second one is p greater than m plus 1.
Before the bracket, less than sign. So, these are the primes; is this fine? 1 to m plus 1, that is not fine. Why not? Oh, you are saying it is equal? Yeah, that is fine. I mean, that does not matter. Sure, that is not a problem. The problem is, what do you do with the second factor, the second bracket? I want to claim that this is at most \(2m + 1\) choose \(m\); can I say that?
So, this is actually not lemma 2; this is something even simpler, also a prime that is bigger than m plus 1 and smaller than 2m plus 1, which will not appear in m factorial, for example. So, if it is since it does not appear in m factorial, it only appears in the numerator product, which is m plus 1 dot dot 2 m plus 1.
So, it will divide 2m plus 1, which is the chosen argument. Since p is in the range m plus 1 to 2m plus 1 for all p, p divides 2m plus 1 choose m. Is this clear?
2m + 1 choose m is again m + 1 · 2m + 1 divided by m factorial; this p will not divide m factorial, but it will divide the numerator. So, it will divide this binomial \(2m + 1\) choose \(m\). So, if you just carelessly estimate the product of primes by \(2m + 1\) choose \(m\), it is not a mistake; it is just a very lazy estimate. So we have this. So, now we have replaced primes with something much easier; we now have these two expressions, which are much easier. They are more explicit than just the product of primes, and what do you do now?
So, this is 4 raised to m plus 1 times I say that this 2m plus 1 choose m is at most 4 raised to m. Is this fine? Can you show this? 2m plus 1 choose m is at most 2 raised to 2m. What is the proof?
The proof is that if you look again at the sum of all binomials, it will be 2 raised to the power of 2m plus 1, but then you note that the main largest terms are 2m plus 1 choose m and 2m plus 1 choose m plus 1. There are two terms and then other smaller terms, all of which sum up to 2 raised to 2m plus 1.
So, you can divide that by 2. Is that clear? That is why I wrote 2 raised to 2m, which gives me 4 raised to 2m plus 1. Overall okay. So, the product of primes up to 2m plus 1 we have shown is at most 4 raised to 2m plus 1, which completes the induction step.
So, we have the proof by induction; is this proof complete, or is there any other step remaining? There is one more step: n can be even. So, if n can be 2 m, what happens in this case? So, in this case, you are looking at the product of primes less than or equal to 2m, but trivially, this is the same as the product of primes up to 2m minus 1, right? This is prime.
So, it cannot be 2. So, actually, it even reduces to odd; you can just as well do the 2m minus 1 thing, for which by induction you will get 4 raised to the 2m minus 1, which clearly is less than 4 raised to the 2m, right? So, here the induction step also holds.
That is the induction hypothesis. Is this clear? So, both even and odd n are covered by the induction steps, and hence overall induction holds. So, we have the result that finishes Lemma 3.
So, lemma 3 was that the product of primes up to n is at most 4 to the n; is this clear? So, now we are ready to obtain this prime density estimate. Which still looks very mysterious. I mean, what are these lemmas to do with pi of x, right? So, this is still, even at this stage, non-trivial, but you will see that now it will simply follow. So, here are the steps that are the density estimate theorem. So, let us now prove this.
So, first, we will show the upper bound. So pi x is less than 5 x by log x part; let us do that first. So, for this, the idea is to look at Lemma 3; Lemma 3 states that the product of primes is somewhat small, and from here we want to reduce the number of primes to also be somewhat small.
I mean we know that the number of primes cannot be more than x, because there are only x numbers, but what we want to show is that it is actually smaller than x; it is 5 times log x. So, that will follow from lemma 3 as follows. So, we will use Lemma 3.
So, there are a number of primes in the range from the square root of x to x, but the definition of pi is pi of x minus pi of the square root of x, and so what this means is if you look at the product of primes less than or equal to x.
So, look at these primes which are bigger than the square root of x; right, they are how many π(x) minus π(√x). So, this product is at least this much; let us call this something, maybe n. So, the product of primes up to x, we just focus on the big primes which are bigger than the square root of x. So, that is (√x) raised to (π(x) - π(√x)), and you have an upper bound of 4 raised to x. So, now from this, actually you will be done; if you just take the logarithm of both sides, you will get the answer.
So, this means that pi of x minus pi of square root x times log of square root x is less than 2x, right? And that will give you a bound on pi of x; pi of x is less than something. So, what is that pi of x is less than 4 x by log x to base 2 plus pi of root x, right? So, the difference is at most 4x by log x; that is what I have written here. Is that correct?
And, but then you have pi of the square root of x sitting; what do you replace it with? By the trivial bound, which is the square root of x, you know that the number of primes cannot exceed the range. So, you get 4x by log x plus the square root of x, and this is always smaller than 5x by log x.
for x greater than or equal to 2. So, we have shown that pi x cannot exceed 5 x by log x; is this fine that it is the upper bound? It holds for all x's. So, this is highly non-trivial because pi of x, by definition, is smaller than x, but here we are saying that it is even smaller than it is far away from x, actually, right? But this was still the harder thing: the lower bound, that, well, at least you have these many primes, right? So, that is the more interesting thing for us: how many prime numbers are there.
So, let us do that next; let us show the lower bound on π(x). So, what do you think, which lemma will give you the lower bound on π of x?
That will be the remaining lemmas, which are lemma 1 and 2. Lemma 1 says that this 2n chosen is a large number, and Lemma 2 says that it contains these primes p's. So, from this, we will actually deduce that there are many primes. So, let us see how it is not completely trivial, but you will see that it can be done in an elementary way.
So, we will use Lemma 1. So, first you write 2n choose n as a product of primes.
So, if this is basically the prime factorization of 2n choose n, all the primes that divide, or the distinct primes that divide 2n choose n with their exponent Vp, that is how it factorizes; that is the kind of definition of the RHS. And what can you say about the upper bound of p raised to V, how big is that?
That was lemma 2, right? It is 2n, p divides 2n choose n, and so can you give an easy estimate on this product? It will be 2n raised to something, which is the exponent where you will put the number of primes that can divide 2n choose n. How much is that in terms of pi?
Can a number bigger than 2n, or a prime bigger than 2n, divide this? So, it can be at most π(2n). So, this product, I mean, 2n choose n, is at most 2n to the pi 2n; this is all we have reduced here. And you know from Lemma 1 that this is large; you know that this is, or may be, I should first take the log.
We have shown that this is greater than or equal to 4 to the power of 2n plus 1, and then we take the logarithm. So, what will this give you? This will give So, 2n minus log of 2n plus 1 is less than or equal to 2n log of 2n log of no sorry pi of 2n here, which implies that pi of 2n is at least I guess this is fine, is this ok, this is what we get that pi of 2n is at least 2n with some error term here, but the error term you can see is not too large it is log of 2n plus 1 to base 2n. So, it cannot exceed 2 ever strictly smaller than 2 right. So, that is the estimate.
So, in general, for an arbitrary x, pick a natural number n such that you can get x sandwiched. So, x can be even, odd, or it can also be any real number. So, you can always sandwich it between two even numbers, and then you apply the above inequality.
So, what that inequality says is that pi of x is greater than or equal to, first, I mean obviously, you have greater than this thing greater than pi 2, at least pi 2 n, and then you use that expression, which is now you substitute; you try to substitute x here. So, you will get some not exact, but a lower bound you can now deduce. So, 2n is yet you need to write 2n greater than or equal to x minus 2 in the numerator and for the denominator you need 2n less than or equal to something.
So, which is x. So, log x here minus let me just write this you will get this expression. So, now, you have on the left-hand side pi of x; on the RHS, you have a function in x, you simplify and get this easy conclusion that this is greater than x by log x minus 2.
So, between 1 and x, there are always this many primes: x divided by log x and at most 5 times x divided by log x, both sides we have now. Any questions? So this is good enough for all our computational applications in cryptography, coding theory, and whatever.
One interesting number theoretic fact from here is that you can deduce the presence of a prime in small intervals. So, for example, you can deduce from here that there is always a prime between n and 6n that is a corollary of this.
May be x what we had there x greater than or equal to 5. So, maybe that is where we got 5; I think that was needed here in this calculation that you used. When there are these functions to actually say that it is greater than or equal to, you need x to be sufficiently large. So, you can check that phi works.
So, as a corollary, you get that there is always a prime between a number and six times that. Do you see this? How do you show this using the Density Theorem? What is the number of primes between x and 6x, pi of 6x minus x minus pi x, right? And now you can use both the upper and lower bounds to estimate this difference.
So, this, for example, you want basically a lower bound on this. So, pi of 6x will be at least. So, let me do this approximately. So, this will come out to be at least 6x by log x on the negative side you want to upper bound. So, the upper bound we proved was 5 x log x. In particular, this will come out to be positive. So, no matter what x is, this difference is always positive.
So, this means that you will always find a prime in x and 6x, which is interesting; there is no easy way to prove directly that you can find primes in these small intervals. Can you say that there is always a prime number between x and x plus 10?
Yeah, those things will not work even if I say there is always a prime between x and x plus 1 billion; somebody can run a computer simulation and always find that, well, there is an x for which there is no prime in this interval. So, empirically, you will be able to find these long gaps. Where primes will not exist. So, those things are not true, but the best-known result is x into x, which can be shown to be called Bertrand's postulate.
I will not show this, but you can do it as an exercise or read the proof. So, it was proved by Chebyshev. So, this says that for all n there exists a prime between n and 2n. So, in any interval of this type, a number and twice that, you will be able to find a prime.
Smaller results are not known; they are famous open questions; for example, there is this open question of Lagrange or Legendre from the 1800s. That for all n, there is a prime in the interval between two squares.
So, the conjecture says that if you look at the sequence of squares, there is a prime in every interval. Why is this not a conclusion of Bertrand's postulate? Yeah, because the gap between two squares is smaller than half, it is around the square root of n plus 1, which is definitely less than 2n squared, something like n squared plus n, n squared plus 2. So, in terms of x, it is like x and x plus the square root of x, right? So, it is a much smaller gap; these results are not known; these are conjectures.
There is no empirical counterexample for this; if you list squares, you always get primes in every interval. So that you can try to solve it as a homework exercise. Any questions?
Okay, so then we can quickly do some applications of what you have learned so much in number theory. which is basically in cryptography.
Yeah, cryptography, and there are many other applications, but we cannot do everything in discrete math. We will just sketch some applications; the rest you can read. So, what is cryptography? It is two people who want to communicate over a channel that is being watched by many other adversaries, right? So, the goal is that you should be able to communicate, but they should not be able to deduce. What are you talking about?
So, basically, the issue has to do with security; you want to have a protocol that is as secure as possible. Obviously, it cannot be mathematically secure that those things are kind of impossible, but it should be practically secure. It practically you should have confidence that it can't be broken, which is how all the internet security works.
So, the goal is to transmit messages over an insecure channel.
So, first, let us say the zeroth thing is that if the channel makes some errors, for example, I mean, however you communicate physically—whether by air, by wire, or whatever—there are always errors introduced, or say in a USB or hard disk, however you store information, there are errors. Nothing is error-free. So, you want it to be error-correcting, and the second thing is that the adversary should not be able to understand.
These are the two main issues whenever you are trying to transmit a message. So, first, it has to do with error correction, which we will not discuss in this course; or maybe one thing we can discuss once we have covered finite fields, etc. So, at least we will not discuss it now. The second thing we want to discuss now is the issue of security. So those are the two main concerns.
So, this is with security and first is error correction, so error correcting codes. Now, error-correcting codes are extremely important because if they were not there, then computers would not work, as every device in computers is making errors constantly.
So, which means that your data will be corrupted within a few hours, and you will not be able to do anything if you don't have a method to make sense of corrupted data, right? So, before computers were implemented or physically created before that this error correction mechanism was invented and that mostly is an algebraic method.
So we will do that one day. Second, assuming that the channel is perfect, there is no error; still, you want to hide things from an adversary, right? these methods again the most important methods are algebraic and we will discuss some number theory based methods. So, we do not have much time to do anything.
Let us discuss some basic definitions anyway. So, we will have two players or two parties: the first is A for Alice, the second is B for Bob, and the third is the adversary, which is E for Eve, and there is a channel.
which can model anything; it can be paper being transmitted, being handed over by hand, by post, or it can be wire, or it can be electromagnetic waves, or whatever, or a hard disk. So, that is what this line denotes. And I think this is why we will always say that Alice wants to transmit something to Bob. So, you can also think of B for a bank. So, A can be a customer, say Alice, on a smartphone, and B is the bank.
So, the secret things Alice wants to send to the bank. That is the situation that is happening all the time. These days, in most applications, it can also be two-way; maybe Bob also wants to send a secret to Alice, and then there are many people in the middle who are watching this conversation. You want them to not be able to deduce anything.
So the question is, how is it possible that Eve is looking at each and every bit of the message? How can Eve not know, but Bob know? Do you have any ideas? How is this possible? What is the difference between Eve and Bob? Yes, so the most basic idea would be that Alice and Bob meet early on, share some secrets, and then the remaining communication happens with that secret.
So, E would not have any idea what they are discussing. So, which gives us some notation that A wants to send; let us use the full form here. So, Alice wants to send a message, a message m, and this you can think of simply as a string.
With n bits, it will usually be an English or alphanumeric message, but then you can code it as 01. You can say that A is whatever; you can take Unicode or some standard encoding. So, all the punctuation marks, alphabets, numbers, and everything can be coded into, let us say, 5 bits, right? So, you have these blocks of 5 bits, and you can send anything in any language.
So, ultimately the message m is just a string that models huge text that Alice wants to send. So, 0 and 1 are called the alphabet; the alphabet is binary here, and n is the length of the message. What else is there? So, Alice will encode it to get C. So, that is the code that is the code C. So, we call M plain text and we call C ciphertext and how to convert M to C is the hard thing, it is an algorithm which is encryption algorithm, right.
So, the encryption algorithm, as suggested, will correctly allow Alice and Bob to share a secret S; the encryption algorithm will use S and M to produce C. So encryption algorithm E uses S and M to get or to compute the ciphertext C. So this S is the secret.
So, then this is sent to Bob over the same channel, assuming that the errors are taken care of by some other algorithm that we will discuss a few weeks later. What can Bob do with C now? So, there will be another algorithm which is the decryption algorithm which will convert C back to M using S.
to compute M. And of course, this has to be done I mean the decryption algorithm should be powerful enough to uniquely compute M, otherwise it won't be of any use. I mean, say you are in a war; if you send that the missiles have to be fired at 10 AM and then on the other side they read it as 11 AM, it's not good. So you want the message to be uniquely recovered exactly; there should be no error in that. So both of these things are precise algorithms.
So, everything is now kind of dependent on this secret, right? What will be the secret, and then what will be the encryption? Correspondingly, there will be a decryption. So, do you know any secrets? If you have to send something to your girlfriend, let's say girlfriend number 1 and girlfriend number 2 should not understand. so in that case do you know of a secret way to or what should be the SN encryption algorithm.
So, a method that is thousands of years old is called a substitution cipher. So, what you can do is map the English alphabet, let us say A to Z, to a permutation, right? So, A is, let us say, associated with B, B with C, C with D, and so on, and then Z with A, and that is the secret, okay. So, now when you write letters you write applying a permutation So, that is encryption and decryption will just be inverse permutation.
It is also called the Caesar cipher because old kings were stupid and used it. So, here the setting is. S is a permutation on sigma; let us say it is from E to Z to itself.
So, pi is the secret; the encryption is simply what you take: the S, M, and C will be the ciphertext, which will be just pi applied on M. So, for example, A, B, C will just become under this cyclic forward shift; it will become B, C, D, and decryption will just be pi inverse on C.
which will be pi inverse of pi of m. So, you will uniquely get m right. So, this is basically everything that is dependent on this permutation being secret between Alice and Bob, right? If permutation is not secret enough, then there is no security in this. If the permutation is secret, is this secure? It is not secure; why not?
Sorry. No, no, no, they are fine. So that is not a practical argument. The number of permutations is 26 factorial. How much will Eve search? She will grow old and die. Right, yes, so the problem is this will be fine if the messages are completely arbitrary strings, right? Then it is mathematically fine; it will depend on whether the permutation is guessed or not, and since the permutations are 26 factorial, I mean, 26 factorial is small as a lower bound, this will be much more.
Because you have small a to z, capital A to Z, punctuation marks, and numbers, all that. So, this is at least more than 26 factorial; I mean, this is at least 26 factorial, possibly much more, but 26 factorial already is very large; it is something like 26 to the 20. So, it is impossible to go over all of them. So, mathematically it will be secure, but the problem is that in practice you will use it in a language like English, for example, or Hindi, or whatever.
Then the way languages have evolved, languages have a very, I mean, you can do a statistical analysis and see which alphabets appear more frequently. Like E appears more, A appears more, and Z appears very rarely. So, through a frequency analysis, you will know that in C, the letter that appears most is E, and gradually you will learn about pi.
So, you can look at a few messages from Alice; I mean, Eve can look at a few messages from Alice and deduce the whole permutation π. So, it can be decoded; it can be attacked. Using many M's, which are English text, let us say, any human has written something meaningful. The frequency analysis helps recover or helps break pi or break the secret.
So, basically, you look at 5 or 10 ciphertexts, each of which corresponds to meaningful messages. Just doing a frequency analysis, you will learn which letters are appearing frequently in C, and then you can map it back to what happens in usual English texts, and that will break the secret; you will know pi. Where is A going, where is B going, C, D, E, and that will basically give you something close to the message, and then again, using your English intuition, you can complete the message. So for practical purposes you will have broken the code. So this is the problem. So it can be mathematically secure but very easy to break in practice. So substitution cipher is completely broken.
So we will use more complicated concepts, and ultimately, we will use number theory and algebra to design the best ciphers.

Ask anything
We've read this whole study set, so questions about it get the best answers.