 This lecture is part of Berkeley Math 115, an introductory course on number theory for undergraduates. This lecture is on binomial coefficients. The first part of it gave some review of some basic properties of binomial coefficients. So this is the second part of the lecture where I'll be discussing some number theoretic properties of binomial coefficients. So first of all we're going to look at binomial coefficients modulo 2. This means what we do is we just write out Pascal's triangle like this. Except whenever we get an even number I put zero and whenever we get an odd number I put one. So I'm putting zero instead of two here because one plus one is even. And we can go on like this. And now here we see we've got a one at each end of the line and a lot of zero is in the middle. And this means that the one here is now giving another copy of this little bit of Pascal's triangle. So it sort of looks like this. And then we get one, one, one, one, one, one, one and then we suddenly get almost all zeros again. And what I want to do is to look at the pattern the zeros are making. So here we have a sort of triangle of zeros and here we have a triangle of zeros except it's a rather small triangle because there's only one zero in it. And what's going to happen here? Well here we're going to get another huge triangle of zeros because whenever you've got a row of zeros everything below it in this triangle just has to be zero. So there's a lot of zeros. And here we've got a one with lots of zeros. So below this one we're going to get another copy of this triangle here. So if I sort of draw this triangle here then what's going to happen is we're going to get another copy of it down here and another copy of it down here. And in particular what I'm going to do is I'm going to get a whole line of ones at the bottom. One, two, three, four, five, six, seven, eight. And now since I've got a whole line of ones I again get a whole line of zeros everywhere except for one at the end. So we're sometimes getting these rows where everything is zero and you can see it's going to kind of repeat like this in a sort of vaguely fractal like pattern. So here this is, you remember we have to count rows in a funny way. So this is row zero and this is row one and this is row two and this is row four and this is row eight and this is row sixteen. Now you notice these are just powers of two. So whenever the row is a power of two almost all the coefficients are vanishing. So what this is saying is that nk is equal to naught if n is two to the power of something and naught is less than k is less than n. So we've got this funny property that every now and then almost all the entries of a row vanish. Well that works for two. We see that sometimes almost all entries of a row are divisible by two and we can ask if the same thing happens for other primes. So let's sort of try three. So here we have one, one, one, one, two, one, one, zero, zero, one because here I'm now going to write zero if something's divisible by three. And you see this is row three and almost everything is divisible by three. And in fact the same thing happens for any prime. So if p is prime we can look at the binomial coefficients p choose k and we see this is zero if naught is less than k is less than p. Obviously p naught is equal to pk is equal to one so these are not divisible by p. And we can prove this in several ways. One way is to use the explicit formula for binomial coefficients. So this is equal to p factorial times k factorial times p minus k factorial. And if we stare at this we see that this is divisible by p because it's got obvious factor of feet p. And these terms here are not divisible by p unless... Well the first term is divisible by p if k is equal to p and the second term is divisible by p if k is equal to zero. So as long as k is not equal to p or zero the factor of p in the numerator won't cancel out with anything in the denominator. So this is divisible by p if naught is less than k less than p. So this will be very useful a little bit later when we will use it to give one of the proofs of Fermat's theorem. So this is a sort of funny application. It means that if we take x plus y to the p this is equal to x to the p plus y to the p plus something times p. So for example if we look at x plus y to the 5 this is equal to x to the 5 plus y to the 5 plus... And now we've got 5 times x to the 4y. Sorry, I'm just going to put the 5 outside the bracket. 5 times x to the 4y plus 2x cubed y squared plus 2x squared y cubed plus xy to the 4. So if you ignore multiples of 5 we had the nice formula that x plus y to the 5 is equal to x to the 5 plus y to the 5. Well when we did in mod 2 we saw that everything vanished not only on the second row but also on the fourth row and on the eighth row and on the sixteenth row. And you can guess the same thing happens for all primes. So suppose we take a power of a prime and look at k. We think this should be divisible by p if not is less than k is less than p to the n. So let's put a question mark because we want to think about whether this is true. Well one way of proving it is to use this fact about x plus y to the p being almost divisible by p. So we know x plus y to the p is equal to x to the p plus y to the p plus p times some sort of junk. Well what about x plus y to the p squared? Well this is equal to x plus y to the p to the power of p and this will be x to the p plus y to the p plus p times something all to the power of p. And this will be x to the p squared plus y to the p squared plus p times something very very complicated because we've got all these p's here and we've got more p times something coming from this. Whatever we still see that x plus y to the p squared is x to the p squared plus y to the p squared if you ignore multiples of p. So this just says that p squared k is equal to naught if naught is less than k is less than p squared. And we can do the same thing and show that the same thing happens for x plus y to the p cubed and so on and just carry on like this. So we see that binomial coefficients are sometimes divisible by p at special values of the numerator. So this is indeed correct. It's quite often useful to know exactly how many times a prime divides binomial coefficient. So for example we might want to know how many times two divides say the binomial coefficient 100 choose 50 or something like that. Well you remember binomial coefficients are n factorial over k factorial times n minus k factorial. So we want to know how many times a prime divides say n factorial. So for instance if we take say 8 factorial let's try and figure out how many times two divides. Well this is 2 times 3 times 4 times 5 times 6 times 7 times 8. And you notice there are 1, 2, 3, 4 even numbers and each of them gives a factor of 2 dividing 8 factorial. So 2 divides 8 factorial at least 4 times. But that doesn't give us the right answer because we notice that this is not only divisible by 2 it's actually divisible by 2 squared. So we should add some more multiples of this. So here I've got these are all divisible by 2 squared. So I should add an extra factor of 2 coming from this and an extra factor of 2 coming from this. So we get an extra factor of 2 squared. And finally the number 8 is actually divisible by 2 cubed. So we get yet another power of 2 dividing it so we have an extra power of 2 to the 1. So all together we get 2 to the 4 times 2 squared times 2 to the 1 which is 2 to the 7 dividing this. Notice by the way the 2 cubed is the total number of 2's dividing 8 but I've already counted 2 of them. One of them here and one of them here so I only count one extra one here not three of them. So 2 to the 7 is the biggest power of 2 dividing 8. And in general if we want to know how many times does p divide n factorial, let's do it. We write all the numbers 1, 2, up to n. And then some of these will be divisible by p so we get p and 2p and so on. So how many are going to be divisible by p? Well we get p divides, well you might think it's n over p but in fact we take the integer part of this. So we sometimes put square brackets around things when we say take the integer part. So that will be the number of numbers below n that are divisible by p. But then we've got to add extra numbers for the factors of p squared. And there are this number with p squared divides something. And then we do the same for p cubed of course so we get the fractional part of n over p cubed and so on. So the number of times p divides n is going to be n over p except we take the integer part plus n over p squared except we take the integer part plus n over p cubed except we take the integer part. And this sum is actually finite because as soon as p to the n is p to the k is bigger than n this term will be 0. You'll notice this is slightly less than the geometric series and so on. In fact it's strictly less than that which is sort of n over p minus 1. This gives a reasonable rough estimate for the number of times p divides n. So let's just do a couple of examples. Let's take 1000 factorial and ask how many zeros at or at the end of it if you write it out in decimal. Well obviously we need to work out how many times does 5 divide this and how many times does 2 divide this. So 5 divides this. Well the number of times 5 divides it is 1000 over 5. We take the integer part of this which is 200 and then we take 1000 over 5 squared and take the integer part of it. But we can more easily just take 200 over 5 and take the integer part of that which is 40. We take 40 over 5 take the integer part of that which is 8. Take 8 over 5 and the integer part of that is 1 and we take 1 over 5 and the integer part of that is 0 so we stop. So we add up all these numbers we get 249. So 5 divides 1000 factorial exactly 249 times. And what about 2? Well we should take 1000 over 2 which is 500 and then 500 over 2 which is 215. This is going to go on a bit but it's a bit pointless because we can see that this is going to be obviously bigger than the number of times 5 divides it. I mean we've already got more than 249. So we see 1000 factorial ends in exactly 249 zeros. And we can use this to work out number of times primes divide binomial coefficients in much the same way. For example let's work out the power of 7 dividing 1000 so 100 choose 40 for no particular reason. And all we do is we do the following calculation. We work out the number of 7s inside 100 where we divide 100 by 7 and this is going to be a little bit more than 14 and we divide 14 over 7. And this is going to be 2 so we've got 16 7s dividing 100 factorial and then we do the same thing with 40 so 40 over 7. This integer part is about 5 and 5 is obviously less than 7 so we can stop there and we just get 5 of these. And then we do 60 over 7 is about 8 and 8 over 7 is about 1 and so all together we get 9 there. So we get 16 7s dividing 100 factorial. We subtract the ones dividing 40 factorial and subtract the ones dividing 60 factorial and this just gives us 2. So this is divisible by 2 powers of the prime 7. Now for later use this lecture it will be useful to know roughly how big are binomial coefficients n choose k. And we can give a very crude estimate which will be good enough for many purposes. The first crude estimate is that n choose k is at most 2 to the n. And that's because the sum of the nth row is 2 to the n as we showed in the previous video. And obviously if the sum of them is 2 to the n then each individual term is 2 to the n. Well obviously the terms are going to be somewhat smaller than that in general. And we might want a lower bound so well in general the lower bound is going to be 1 because some of them are 1. But we can ask for a lower bound for say the middle coefficient. And we notice the middle coefficient is going to be at least 2 to the n over n plus 1. And that's because 2 to the n is the sum of n plus 1 coefficients 2n choose 0, 2n choose 1 and so on. And there are, sorry that should be 2n plus 1 of course. And 2 to the 2n I forgot I changed n to a 2. So 2 to the 2n is the sum of these 2n plus 1 coefficients. And since there are 2n plus 1 of these the middle one is, the average of them must be at most 2 to the 2n over 2n plus 1. And notice that this is the biggest coefficient. So the biggest of these 2n plus 1 coefficients must be at least the average size of them. So we know that this term is at least this and it's at most 2 to the 2n. So we sort of pinned it down to within a factor of about 2n plus 1 which for some purposes is good enough. If we want to be more precise we can do much better by using Stirling's formula. Stirling gave a formula for n factorial which says that n factorial is approximately equal to n to the n plus 1 half times e to the minus n times root 2 pi. Heaven knows where that root 2 pi comes from. Well, we're not actually going to use this because we're only going to be doing some rather rough estimates. But if you do need to know binomial coefficients more precisely you can get them like this again by writing binomial coefficients in terms of factorials and then use it applying Stirling's formula to the factorials. If you want to be even more precise than this then there's an extension of Stirling's formula which gives you an even more accurate form of the error term. So we have pretty good control over the size of factorials and binomial coefficients if we need it. So now I'm going to give an application of this to the following problem. We want to say how many primes are there less than or equal to a number n. And the prime number theorem says that the number of primes less than n is approximately n over log of n. More precisely it says that the ratio of the number of primes less than n divided by this number tends to 1 as n tends to infinity. And the prime number theorem is rather difficult to prove. What I'm going to do is I'm going to sketch how to use binomial coefficients to prove a slightly weaker form of it. So here's a sort of weak form. Instead of saying that, let's see, this is pi of n for the number of primes less than n. So I'm going to denote this by pi of n. So instead of showing that pi of n is close to n over log of n I'm going to say if we take a half of n over log of n this is going to be less than or equal to pi of n is less than or equal to 2n over log of n. So we're sort of getting this bound to within a factor of about 2. And now I'll show how to do this. Well first of all let's try and do the upper bound. So let's try and find an upper bound for pi of n. I'm not going to give full details of these upper bound and lower bound because it becomes a little bit fiddly to get them right. But I'll give the main ideas and there should be enough for you to fill in details if you want to. So the key idea for both the upper bound and the lower bound is to look at the binomial coefficient 2nn and to look at the primes dividing it. So in the earlier part of this lecture I showed that we've got very good control over primes dividing binomial coefficients and we've also got some rough control over the size of this. And by combining these two facts we can get some reasonable control over numbers of primes. So first of all we notice that suppose n is less than a prime p is less than 2n. Then p divides 2nn exactly once. That's because if we look at 2n factorial over n factorial times n factorial we see that p divides this and it does not divide this because it's bigger than n. So we find the product of all primes between n and 2n of p is less than or equal to 2n choose n. So this means product of all primes, primes p between n and 2n. The convention in number theory is whenever you write down p it's usually understood to be a prime. So when you write down an expression like this the convention is it's understood you're taking a product over just primes p. This notation is a bit ambiguous but you get used to it. And we know an upper bound for this. This is at most 2 to the 2n by what we just said. And this gives us a nice upper bound for the number of primes. So let's take the logarithms. So we have the sum over n is less than p is less than 2n of log of p is at most log of 2 to the 2n which is 2n times the log of 2. And we also notice that this bit here is greater than or equal to log of n times the number of primes in the interval from n to 2n. So now this gives us an estimate for the number of primes between n and 2n. So we find the number of primes from n to 2n is at most 2 log 2 times n divided by log of n. And that's very nice because we've got this n over log of n. Well I guess it should be 2n over log of 2n really but so this is going to be approximately log of 2 times 2n over log of 2n. Yes I know log of 2n is not actually equal to log of n but they're actually pretty close because this is just log of n plus log of 2. So these are approximately equal to that. So now we can find the number of primes less than or equal to n is bounded by about 2 times n over log of n. And the way we get this is we divide the interval from 0 to n into the interval from n over 2 to n and the interval from n over 4 to n over 2 and the interval from n over 8 to n over 4 and so on. And on this interval we can obtain a bound for the number of primes because we've got one here. And on this interval we can sort of obtain a bound for the number of primes. Well except that n over 2 might not quite be an integer but so there's a little bit of fiddling going on there. Anyway we've got nice estimates for the number of primes in each of these intervals and we can add them up and give an estimate for the number of primes from 0 to n. And as I said if we do the estimate a little bit more carefully we actually find the bound for the primes less than or equal to n is 2n over log of n. There's nothing special about this number 2. If you work very hard you can actually make this number 2 a little bit smaller. But it seems to be very difficult to make it arbitrarily close to 1 which would give you the upper bound for the prime number theorem. So these very elementary ideas using binomial coefficients can get within a factor of about 2 or maybe 1.5 of the prime number theorem. But it's very difficult to get all the way there. So that's given us an upper bound for the number of primes. Now let's try and find a lower bound for the number of primes less than or equal to n. And for this we're going to again look at the binomial coefficient 2n choose n and again look at the primes dividing it. And what we notice is that the product over p to the k is less than 2n less than or equal to 2n of p is greater than or equal to 2n choose n. So here we're taking a product over all prime powers and we're only taking a product of the prime. So I think that should be 2 times n not 2 to the power of n. And what we do is we need to count up the number of times p divides 2n choose n. And we remember we found a formula for the number of times p divides 2n choose n. We take 2np and we take the integer part of it and then we subtract the integer part of np and we subtract the integer part of np again. And we do the same thing for prime powers so that should be an n. And we do the same thing for prime cubes and so on. And now we look at this expression here and we see that this term here is either 1 or 0. And the reason for this is that if we take any number x then xp 2xp minus xp minus xp is always going to be 1 or 0. And we may as well divide x by p so we're looking at the integer part of 2x minus the integer part of x minus the integer part of x. And this is obviously either 1 or 0 because it just depends on whether the fractional part of x is between 0 and a half or between a half and one. And similarly all these terms here are either 1 or 0. So what we're going to get is a product for each prime power p to the k that's at most 2n we're going to get at most one factor of p dividing 2nk. So if we take all powers of p to the k less than 2n and multiply them that's sort of making all these terms equal to 1 which will make this product bigger. So this product here is at least 2n over k. And now you assume we've got a sort of lower bound for the number of primes or rather the product of all the primes. And now we've got to kind of turn this into account for the number of primes. Well first of all we need to know what 2nn is and this is greater than or equal to 2n, so 2 to the power of 2n over 2n plus 1. Now what we're going to do is to take logarithms of both sides. So we take the sum over p to the k is less than or equal to 2n of log of p is greater than or equal to log of 2 to the 2n divided by 2n plus 1 which is equal to 2n log of 2 minus log of 2n plus 1. And now how do we get from that to counting primes? Well we need to make several simplifying assumptions. First of all the terms with p squared, p cubed and so on are small. So that's because squares and cubes and so on are pretty rare. So we can sort of ignore squares and cubes and primes because that won't make a big difference. The second thing to observe is that the function log of x is constant. Well of course it's not constant, it's almost constant. And if you've seen graphs of log of x in calculus you sort of see the graph is drawn something like this. And it sure doesn't look constant. But that's because you haven't looked at it on a big enough scale. If you zoom out, so say you go up to a billion here, then the graph of log of x looks like this. It's completely indistinguishable from the x-axis because it's so close and then it sort of shoots off down here. So it just looks like a right angled bend. Well that's if the y-axis is on the same scale as the x-axis. If we want to see a little bit more precisely what log of x does, what we do is we rescale the y-axis. So maybe we only go up to a hundred here and a few hundred million or a billion there. And if we do that, the graph of log of x now sort of looks like this. And then just before the zero it turns down. And what you notice is that this is very nearly constant. That's because if we go from here to here, we're going down by a factor of e, say, so log of x just goes down by one. So if this was about 20 or whatever that would go down to about 19 here. So most of this is constant. So if we look at this, we find that this log of p here is very close to being log of 2n for most primes. So let's put all these together. What we then find is that the sum over p is less than or equal to 2n. So now I'm just looking at summing over primes and missing out prime powers of log of 2n is approximately bigger than or equal to 2n times log of 2. Here I'm missing out this term log of 2n plus one because that's much smaller than 2n times log of 2. So this says the number of primes less than or equal to 2n is greater than or equal to 2n log of 2 divided by log of 2n minus some small fudge factors. So you remember there are about three places where I threw away small terms because I found them rather boring. And if you want a really precise result, you really need to keep track of this. But what we notice is that this is really just a constant times n times 2n over log of 2n minus some small bits there. So that is giving us a lower bound for the number of primes less than or equal to 2n, which is pretty close to 2n divided by log of 2n. So we've found that number of primes less than 2n lies between about 2n over log of 2n times a half and 2 times 2n over log of 2n. So we've sort of proved the prime number theorem up to a factor of 2, except that we kind of skimped over a few of the somewhat more technical details. So there's one final application of number theory and binomial coefficients I wanted to mention, which is I'm again going to look at these numbers 2n choose n. The middle binomial coefficients. And if you write these out, you get these numbers 1, 2, 6, 20, 70 and so on. And now you may notice these are divisible by 1, 2, 3, 4, 5. And in fact if you continue a bit more, you find this continues. The binomial coefficient 2n choose n is divisible by n plus 1. And let's divide it by n plus 1 and see what we get. We get the sequence 1, 1, 2, 5, 14 and so on. And this is a very famous sequence called the Catalan numbers. So I want to say a little bit more about the Catalan numbers and explain why they're integers. Well the reason the Catalan numbers are integers is they count various things. They actually count a rather astonishingly large number of things. So I'll just give one or two examples. The simplest way is they count ways to bracket a product. So how can I work out a product of one thing a? Well there's only one thing to do there. I can just multiply it by itself. How about if I want to multiply a, b, a times b? Well there's only one way to do that. Just multiply a by b. What happens if I want a, b, c? Well I can first multiply a by b and get c. Or I can multiply b and c together and then get a. So there are two ways of doing that. And how many ways are there to multiply four things? Well I can take a times b times c times d. Or I can take a times b times c times d where I first multiply c by d and then continue like that. Or I can do a times b and then multiply c by d and then multiply these together. Or I can do b times c and then times a and then times d. Or I can do b times c times d and then multiply by a. And if you see there are five different ways to do that. And if you're very patient you could do what happens if you take product of five things and you would find there are 14 different ways to multiply them together. So if you define Catalan numbers by this formula, by counting these things they're obviously integers. And the problem is why is this number equal to the binomial coefficient here divided by n plus 1? And I'll give a sort of sketch of why this is true. If we denote the Catalan numbers by cn, we know c0 equals 1. And cn is equal to c0 cn minus 1 plus c1 cn minus 2. And so all the way up to plus cn minus 1 c0. And that's because if we want to multiply n things together, a, b, c, d up to something. So if we want to multiply them together what we can do is first we'll take a and then we multiply this by some product of b up to the others. Or we can take a times b times something else. Or we can multiply a, b, c. And there are c2 ways of multiplying these and then we multiply all the rest of these together and there are going to be cn minus 3 ways of bracketing those and so on. So we get this formula for the number of ways of multiplying n things together by just counting over the first two blocks we divide things into and then applying the Catalan numbers to each of these. So how do we identify the Catalan numbers from this funny formula? Well, there's a very neat way of doing this which is to use generating functions. So this is a very powerful tool. What we do is we define a function f of x to be c0 plus c1 x plus c2 x squared and so on. And this formula here means that if we take f of x squared, this is just going to be c0 squared plus c1 c0 plus c0 c1 x plus c0 c2 plus c1 c1 plus c2 c0 x squared. And so on and you see these numbers here are just the numbers appearing here. So this expression here is almost the same as f of x except we have to shift by one. So what we find is that in fact 1 plus f of x squared is equal to f of x. It's because we have to shift by one because this isn't c0, this is c1 and this is c2 and so on. We've got to put this one in here because when we multiply by x, we need to add in the constant term. So here we have a formula for f and this is just a quadratic equation which we can solve using the formula for a quadratic equation. This is equal to 1 minus root of 1 minus 4x divided by 2x. So all we have to do is to work out what this function is and its coefficients are the Catalan numbers. And we can do this as follows. So you remember 1 plus x to the n is equal to 1 plus n choose 1x plus n choose 2x squared and so on all the way up to plus n choose n x to the n. And it turns out the same is true even if n is not an integer. This is Newton's formula. You just find 1 plus x to the power of, let me write it as a so it doesn't look so much like an integer. This is just equal to n choose 0 plus h choose 1x plus h choose 2x squared and this just goes on forever. In particular we find 1 plus x to the half which is the square root of 1 plus x can be written as 1 plus a half x plus a half times minus a half over 2 factorial times x squared plus a half times minus a half times minus 3 over 2 over 3 factorial times x cubed plus a half times minus a half times minus 3 over 2 times minus 5 over 2 over 4 factorial times x 4 and so on. And these expressions here look a little bit messy but in fact there's an easy way to write them out. So that's because if we take 1 times 3 times 5 we can write this as 1 times 2 times 3 times 4 times 5 times 6 divided by 2 times 1 times 2 times 2 times 2 times 3 which is 6 factorial over 2 cubed times 3 factorial. And similarly if we take the product of the first few odd numbers we can write it in terms of factorials using this trick. So doing this we see that the expression for 1 plus x to the half can actually be written that the coefficients can be written in terms of factorials. And if we look at the expression for f of x we find we've got the square root of 1 plus something there. So if we do this we find f of x which was equal to 1 minus the square root of 1 minus 4x over 2x turns out to be the sum of 2n minus 2 factorial over n factorial n minus 1 factorial times x to the n minus 1. Which is the sum over x to the n of 2nn divided by n plus 1. And these coefficients here are just the Catalan numbers and since the Catalan numbers are integers we see that n plus 1 divides 2n choose n. Okay well I said the Catalan numbers also turn up in several other ways. They not only count the number of ways of multiplying n things but they also count various sorts of binary trees and they also count various ways of subdividing polygons. And if you want to see all the ways you can get this rather nice book by Richard Stanley where he lists all the different ways of defining Catalan numbers. So here are the first few, there are ways of cutting up a polygon into triangles, there are various ways of trees and how long does this go on for? Well it goes on for many pages and he has found 214 different sorts of sets that are counted by Catalan numbers and doubtless there have been a few more found since then. So Catalan numbers really do turn up rather often. Okay that will be all for this lecture.