 This lecture is part of a course on elementary number theory. More precisely, it's the Berkeley course Math 1.15, introduction to the introduction to number theory. What it will cover is things like primes, congruences, quadratic forms, quadratic reciprocity, and Dirichlet's theorem. The course will be very loosely following the textbook by Niven, Zuckerman, and Montgomery on an introduction to the theory of numbers. So number theory is, well, quite a lot of it is about primes. So you recall that a prime number is a number bigger than one that's only divisible by one and itself. And the first few primes look like this. And we can ask some basic questions about prime numbers. So the first question is, how do you find prime numbers? And one way is to use the sieve of Eratosthenes, where what you do is you write out all numbers. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, so on, 20, 30, 40. And we keep going. And you cross off all the ones that aren't prime. Well, first of all, 0 and 1 don't count because 0 and 1 is a unit. And the first number you haven't crossed out is 2. So we write down 2 as a prime. And we then cross off all the multiples of 2 because these can't be prime. And the first one, number not on this list, is 3. So 3 is our next prime. And we now cross off all multiples of 3. So we go 3, 6, 9, 12, 13, 14, 15, 18. So we cross them off like this. And I'm going to miss out a few that should be on that one. And next, we look at the first number we haven't crossed out. And this number is now 5. So 5 is our next prime. And we cross off all multiples of 5, which is easy because those are just those ones there. And then we get to 7, which is the first number not crossed out. And we cross off all multiples of 7. And actually, all of these have already been crossed out, except for that one there. And we can actually stop now because any bigger prime has a square bigger than 49. So it can't be the smallest prime divisible by a number. So what we've done is we've crossed off all numbers less than 50. Those are not divisible by 2, 3, 5, and 7. Well, these are the primes less than the square root of 50. And if we look and see what numbers we've got left, we've got 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47. And if you're doing number 3, you very soon learn all the primes up to about 100. So the next question is, how many primes are there? Well, if we look at this table, primes seem to be fairly common. There's no sign of them suddenly stopping. And so this suggests that the number of primes should actually be infinite. And this is the first theorem of number theory. Due to Euclid, the number of primes is infinite. Well, actually, Euclid didn't say the number of primes is infinite because the Greeks didn't really like the concept of infinity. What Euclid actually said is something equivalent. He said that if you take any finite set of primes p1 up to pn, you can find another prime not in this set. And what he did was he took the product p1 times p2, and so up to times pn, and you add one to it. And what we do is we take a prime factor pn plus 1 of this. And we notice the prime factor pn plus 1 can't be any of these primes p1 up to pn because if it was p1 up to pn, then it would divide this number here, and it would also divide this number here, so it would have to divide 1. So pn plus 1 is a new prime. So let's just see how this works. We start off with all the primes we can think of, which is absolutely no primes at all because we haven't yet started yet. So we take the product of all the primes we thought of, which is actually 1 because this is the product of no primes. And then we add 1 to this and we get our first prime, which is 2. You notice that if you take the product of an empty set of numbers, you get 1 for the same reason that if you take the sum of an empty set of numbers, you just get 0. So this is our first prime, and now we take the product of all the primes we thought of so far, which is just 2, and we add 1 to this and we get 3. And then we take the product of all the primes we thought of and add 1 to this and we get 7. And that's prime. So we now take the product of all the primes we thought of and add 1 to this and this gives us 43. And now we take 2 times 3 times 7 times 43 and add 1 to this. And this time it's not a prime. It's 1807 and this factors as 13 times 139. So our next new prime is actually 13. So it seems to be a common misunderstanding that if you take the product of all the primes you thought of and add 1, then you get another prime. But this isn't actually true. I mean, it breaks down for the first time here. So this shows there are infinitely many primes. The next question is how to find large primes. So there's a sort of game in Play by Number Theist where they sort of compete to see who can find the biggest prime. So how can you do this? Well, one good way is to look at things called Mercena primes. These are named after Mercena who was the first person to discuss them. These are primed to the form 2 to the n minus 1. So let's have a look at a few. Then where we have 2 to the 2 minus 1, which is 3, and we can 2 to the 3 minus 1, which is 7, or we can 2 to the 4 minus 1. Well, this is 15 and it's not prime, which is 3 times 5. Well, you notice the problem here is that 4 isn't a prime because 2 to the a b minus 1 is divisible by 2 to the a minus 1. This is 2 to the a minus 1 times 2 to the a b minus a plus various things up to plus 1. So if we want 2 to the n minus 1 to be prime, we should take n to be a prime. So we can speed it up by just looking at 2 to the primes minus 1. So we have 2 to the 5 minus 1, which is 31, and 2 to the 7 minus 1 is 127. And this seems to be a rather good way of generating primes because you notice whenever we take a prime and take 2 to the p minus 1, we always seem to get a prime. Well, this doesn't actually quite work because if we go to 2 to the 11 minus 1, this is actually equal to 2047, which is just 23 times 199. So this doesn't always work. However, it's still a reasonably good way to generate primes. So 2 to the p minus 1 is quite often prime. We have an open problem. Are there infinitely many Mercerna primes? So no one really knows, although the answer is probably yes for a reason I'll discuss later. So people have used computers to find large numbers of Mercerna primes. And in fact, there are very good tests to see if a very large number is a Mercerna prime. And you can actually test numbers with millions of digits to see if they're Mercerna primes. In fact, most of the time, the largest known prime is actually a Mercerna prime because they're particularly easy to check. And so another famous sort of prime are Fermat primes. Well, if we're going to look at primes to the form 2 to the n minus 1, we should also look at primes to the form 2 to the n plus 1. So let's look at the first few cases just to see what's going on. So 2 to the 0 plus 1 is 2. 2 to the 1 plus 1 is 3. 2 to the 2 plus 1 is 5. 2 to the 3 plus 1 is, well, 2 to the 3 plus 1 is now 9. Now that's not prime, it's 3 times 3. 2 to the 4 plus 1 is 17, that's prime. 2 to the 5 plus 1 is no good because that's 33. And if you think about it a bit, you notice that if we've got a number 2 to the power of AB with A odd, and we add one to this, and this is divisible by 2 to the A plus 1. So the exponent can't be divisible by any odd numbers if we want it to be a prime set. So we should only take n to be power of 2. In other words, we should look at numbers of the form 2 to the 2 to the m plus 1. So let's restart. We have 2 to the 2 to the 0 plus 1 is now 3. So 2 to the 2 to the 1 plus 1 is 5. 2 to the 2 to the 2 plus 1 is 17. 2 to the 2 to the 3 plus 1 is 257. 2 to the 2 to the 4 plus 1 is 65537, as you know if you're a computer scientist. And all of these numbers are prime. These are called the Fermat primes. So 2 doesn't really count as a Fermat prime because 0 is kind of a bit of a special case. And Fermat sort of suggested that in fact, maybe 2 to the 2 to the m plus 1 was always prime. But in fact, this is false because 2 to the 2 to the 5 plus 1 turns out to be divisible by 641. Actually a bit of a historical puzzle about why Fermat didn't notice this because he was perfectly capable of checking that 2 to the 2 to the 5 was divisible by 641. And the consensus seems to be that he probably did check but just made some sort of numerical error and got it wrong. So Fermat primes turn up in a rather unexpected place. There's a famous problem about which regular polygons can you construct using a ruler and compass? And it's easy to figure out how to construct polygons of side four and eight and 16 and some because you can bisect angles. And the Greeks figured out how you can construct polygons of sides three or five or 15. And what Gauss discovered is that if a number is a Fermat prime, then you can construct a polygon with that number of sides using ruler and compass which is really rather bizarre. And in fact, it turns out the only numbers you can construct with ruler and compass are ones that are products of distinct Fermat primes times the power of two. So we have an almost complete list of polygons you can construct by ruler and compass except that nobody knows whether there are any further Fermat primes. So people have checked the next 30 or so cases and haven't found any further Fermat primes. And it's a completely open question about whether there are an infinite number of these or not. Well, so Fermat suggested this might be an easy way to find primes, but it doesn't quite work. So we can ask, is there any easy way to generate large primes? And this is a sort of open question. I mean, it depends a bit on what we mean by an easy way to generate large primes since we have some reasonably fast methods that computers can use to generate large primes. But it'd be really nice if we could find say a polynomial f of n such that f of n is always prime. So are there any polynomials f such that f of n is always prime? Well, the answer is yes, it's quite easy to generate these. We can just write f of n equals three for all n. It's the constant polynomial. So what we really want is f to be non-constant. Otherwise we've got a rather trivial answer. So we want to find a non-constant polynomial such that f of n is prime for all positive integers. And you can get pretty close to this. Suppose I take the polynomial n squared plus n plus 41, just found by Euler. And if you try n equals zero, one, two, three. Well, you'll probably find this is always prime for as long as your patience holds up. In fact, it's prime for all numbers n up to 40. However, it's not prime for n equals 41. And it's obviously not prime for n equals 41 because if you put n equals 41 here, this is divisible by 41, of course. So we can get polynomials that try very hard to be prime, but they don't quite make it. So you can ask, is there any polynomial such that f of n is always prime such that f isn't constant? And the answer is no. And we can see this as follows. Let's look at f of n equals n to the k plus, so something times n to the k plus something times n plus some constant term. And now suppose this constant term is bigger than one, let's call it k. Well, then if we put n equals k, this will be, f of n will be divisible by k because all the terms are divisible by k, so it's not prime. So if the constant term of f is bigger than one, then it can't always be prime. So what happens if the constant term is equal to one? Well, we can just change f of n to f of n plus k to some number k such that the constant term is not equal to one and repeat our arguments. So there's no polynomial that always generates primes apart from the trivial case of a polynomial that's constant. And no one has ever found anything better. I mean, there just doesn't seem to be a really easy, simple way that will always generate primes. Well, we've shown there are infinite number of primes, but we can ask another question. I mean, instead of asking how many primes there are, we can ask how many primes are there less than or equal to x, where x is some number. Now, the number of primes less than or equal to x is often denoted by pi of x, and you've got to be a little bit careful not to muddle this up with the number three, quote, one, four, one, and so on. So pi is the Greek letter for p, which stands for prime. And it's not very easy to find an exact formula for pi of x, and you can see primes are a little bit chaotic, and it would be a bit unreasonable to expect an explicit formula for them, although rather surprisingly there's seen a moment, there is one, but we can ask, what is pi of x roughly equal to? So we can ask roughly how many primes are there. And Gauss came up with a pretty good answer to this. One version of Gauss's suggestion is that pi of x should be approximately x over log of x. And I just warn everybody, since this is a mathematics course, log means log to base e, not to base 10. There's actually no point in taking logs to base 10. So in mathematics, log always means log to base e. And this was finally proved by Hadamard and Dela Valet Poussin, in about 1896, and at the time it was proved this was probably one of the deepest and most difficult theorems proved in the 19th century. So informally, this means, suppose you take all the numbers up to x, it means about one over log x of them are prime. So we can think of this as saying the chance of n being prime is about one over log of x. And you've got to be a little bit careful about what you mean by this, because the chance of n being prime isn't one over log of n. It's either the chance of n being prime is one if n is prime and zero if n is not prime. So it's kind of a little bit meaningless to say what is the chance of n being prime. But whatever, it's sort of reasonably obvious what's meant. So let's have an application of this. Let's ask, is the number of Mersenne primes infinite? So you remember a Mersenne prime is the number of the form two to the n minus one. So what's the chance of two to the n minus one being prime? Well, it's about one over log of two to the n minus one. And this is about some constant evolving log of two over n. So in order to find out the total number of Mersenne primes, what we could do is we could just take the sum over all n of the chance of two to the n minus one being prime. So we take the sum over n of k over n. And this will hopefully give us a rough estimate of the number of Mersenne primes. Well, this is just equal to k times one plus a half plus a third and so on. And this is the famous harmonic series which you remember from calculus is infinite. So this sort of suggests the number of Mersenne primes is infinite. Well, fine, but there's a bit of a problem with this argument. First of all, it assumes these numbers are random and they're obviously not random because they're two to the n minus one. There's another very obvious problem. Suppose we try and ask how many numbers will form two to the n minus two are prime? Well, we can apply exactly the same argument and it suggests there should be an infinite number of primes in the form two to the n minus two. And this is just totally stupid because two to the n minus two is obviously divisible by two so it's almost never prime unless n is two or something. So these probability arguments are a useful guideline to what is true or not but you should always be really cautious when using them because they can give horribly misleading answers. A rule of thumb is that in number theory, arguments using these sort of probabilistic arguments are generally regarded as worth almost nothing because they're very easy to do but they're extremely hard to make rigorous. And they sometimes give the wrong answer and they sometimes give extremely ambiguous answers. Suppose, for example, we try to count how many firma primes are there? Well, what we should do is we should take the sum over one over log of two to the two to the n plus one. Well, the logarithm of this is going to be some constant times one over two to the n if we ignore the plus one. And this is going to be finite so this suggests there should be a finite number of firma primes. And indeed, numerical evidence sort of suggests that maybe the one's firma and you're about to the only ones they have. But there's another argument you could say. You could ask how many primes are there of the form two to the n plus one? Well, here we would take sum over one over log of two to the n plus one and this is going to be about k times one over n and this is going to be infinite. So this argument suggests there should be infinite number of primes in the form two to the n plus one all of which have to be firma primes. So we've got two probabilistic arguments. One of which says there should be an infinite number of firma primes and one of which says there should be a finite number in which is correct. I have no idea and nobody else really has any idea either. So Riemann actually found a rather astonishing explicit formula for the number of primes. What you do is you define the logarithmic integral of x to be the integral from zero to x of one over log of x dx. Well, actually there's a little bit of a problem with this integral because if x is equal to one the integral actually becomes infinite and sort of diverges. So when I say it's equal to that it's not actually equal to that. You need to fit around with this a little bit but I'm not going to worry about this. The logarithmic integral is going to be a given by something slightly modified version of this. And Riemann found the following astonishing explicit formula for primes. Well, first of all, when he wasn't counting primes he was counting prime powers. So Riemann discovered that p to the n should count as one over n of a prime. So in some sense four is really half is sort of 50% of a prime and eight is one third of a prime in some sense. And he found that instead of counting primes it's easier to count prime powers in this funny sense. So pi prime of x is the number of prime powers less than x where p to the n counts as one over n of a prime power. And he found a completely explicit formula for this number here. So this is just equal to the logarithmic integral of x minus sum over some funny numbers row of the logarithmic integral of x to the row. So here the sum is over all these numbers row which are some so called zeros of the zeta function. Shall I explain in a moment? And now this is a really astonishing formula because these are all nice continuous real valued functions. However, this function here is certainly not continuous because it sort of jumps by one whenever x goes beyond a prime power. So we've got this absolutely astonishing formula of a discontinuous function being given as a natural sum of all these nice continuous functions. And here the logarithmic integral of x turns out to be approximately x over log of x. So this explains why the number of primes less than x is approximately given by this number here. So what are these mysterious numbers row? Well, the numbers row that zeros of the zeta function which is given by this number here, one over one to the s plus one over two to the s plus one over three to the s and so on. So for example, zeta of two is equal to one over one squared plus one over two squared plus one over three squared. And this is a rather difficult sum to evaluate. Euler became famous by discovering that it was actually equal to pi squared over six. And the numbers row are the numbers row such that the zeta of a row is equal to zero. Well, there's a bit of a problem here because the known zeros of row tend to be complex numbers and they're complex numbers for which this series doesn't actually converge. So we need to do quite a lot of work in order to make sense of the Riemann zeta function but other complex numbers and then try and work out where the zeros of the Riemann zeta function are. At this point, we come to the probably the most, one of the most famous open problems in mathematics which is the Riemann hypothesis which just says the real part of any zero row is most a half. So, there's a million dollar prize for solving this if you ever managed to solve it. In fact, solving this Riemann hypothesis isn't the hard part. The really hard problem is not in solving the Riemann hypothesis but trying to get someone else to read your solution when you've solved it because crackpots produce several proofs of the Riemann hypothesis every month. So, if you show a proof of the Riemann hypothesis to a mathematician, the mathematician will just throw it in the bin unread because all mathematicians are sick of getting sent proofs of this. Anyway, Riemann's work gives an astonishingly accurate formula for the number of primes less than the number. For example, the number of primes less than a hundred million is exactly equal to 5761455. Riemann's estimate not counting the zeros over row turns out to be 5761522. As you can see, it's sort of already accurate to four significant figures. So, this is using l i of x as an approximation not to pi of x but to the number of prime powers. So, you have to subtract out the squares and cubes and so on of primes. And if you do that, you get this astonishingly accurate formula for the number of numbers less than number. So, one of the basic facts about primes we're going to prove is the fundamental theorem for arithmetic. So, the fundamental theorem of arithmetic says that every integer greater than or equal to naught, sorry, greater than or equal to one, is a product of primes in a unique way. That means unique up to order. And there's a very nice formula for this involving the Riemann's data function, which is one over one to the s plus one over two to the s plus one over three to the s and so on. And Euler discovered that you could write this as follows. It's the product of one over one minus two to the minus s times one over one minus three to the minus s times one over one minus five to the minus s and so on where this is a product over all primes. And this looks rather astonishing if you see it for the first time but it's actually quite easy to prove. If you just write each of these factors as a geometric series, we get one over one plus one over two to the s plus one over four to the s plus one over eight to the s and so on times one plus one over three to the s plus one over nine to the s and so on. And now if you multiply out this product of an infinite number of factors, each of the terms you get by taking one term from each of these factors and multiplying them together. So for instance, if we take this term, this term and this term and ones everywhere else, we get one over two to the s times one over three to the s squared times one over five to the s which is equal one over two times three squared times five which corresponds to one over 90. And now here we have a term one over 90 to the s. So you see every term in this series here comes from a unique term in this infinite product because every integer can be written as a product of prime powers in the unique way. So this is Euler's version of the fundamental theorem of arithmetic. It's this amazing factorization for the Riemann zeta function. Euler also used this to give another proof of Euclid's theorem that there are infinitely many primes. What you do is you just take s equals one. And now you notice this term here is infinite because it's just one over one plus one over half plus a third and sum which is infinite. So it means this product over primes must be, also must be infinite. But if a number of primes were finite, then this would just be a finite non-zero product. So it couldn't be infinite. So the number of primes has to be infinite because this series here diverges for s equals one. So this is a completely bizarre proof. You're saying the number of primes is infinite because the harmonic series diverges. So next thing you can discuss in number theory are diefantine equations. So diefantine equations are named after diefantis of Alexandria and not very much is known about him. I mean, he lived a few centuries in the common era but no one even knows the exact date when he lives. In fact, pretty much all that anybody knows about him is he wrote a book about diefantine equations. So diefantine equations are equations where you want solutions in integers. Actually, diefantis himself didn't discuss solutions in integers, he mostly discussed solutions in rational numbers but whatever. So let's have some examples. Famous example that everyone knows about is Pythagoras's equation, x squared plus y squared equals z squared. And this is solutions in integers that everyone knows. We all know three squared plus four squared equals five squared or five squared plus 12 squared equals 13 squared and so on. Another example you might have linear equations. So can you solve 27x plus 11y equals one? And we'll see fairly soon how to solve all linear diefantine equations using Euclid's algorithm. So in this particular case, we can, for example, take x equals minus two y equals five, gives a simple solution. Another example is the equation two x squared equals y squared. And this is an obvious solution, x equals y equals zero, but it has no other solutions. So this is like asking, is y over x equal to the square root of two? I mean, in other words, this is the square root of two rational and the answer is it can't be in the, when the Greeks discovered this, they got a bit upset about it because there was a feeling that all numbers should be rational and having irrational numbers was a little bit disturbing. So it's quite easy to prove there are no non-zero solutions of this, for instance. This equation implies y must be equal to even because if it were odd, then this side would be odd and this side would be even. So y is even and you can then divide out a factor of two from both sides and you then find x squared is equal to two y squared. Now you found a smaller solution of two x squared equals y squared. So given any non-zero solution, you can find a smaller non-zero solution. So there can't be any non-zero solutions. Another particularly notorious example is actually the n plus y to the n equals z to the n. So this is Fermat's last theorem and we want n to be at least three and we want x, y and z to be greater than zero because if you allow x to be zero, for example, it has some rather obvious trivial solutions. And for many years, this was the most famous open problem in mathematics and there are thousands of incorrect solutions of it until it was finally solved by Andrew Wiles in the 1990s. There are also some variations of this. For example, we can ask what about x to the four plus y to the four plus c to the four equals t to the four. Can we find a non-zero solution of this? Well, you can, but it's really rather difficult. So one solution would be 20615673 to the four plus 26, sorry, equals 2682440 to the four plus 15365639 to the four plus 18796760 to the four. Obviously people had to use a computer to find this because it'd be a bit difficult to find it by hand using trial and error. So as you see from this, it can be really hard to tell whether or not a diaphanetine equation has a solution or not. Sometimes there may be no solutions but it's really difficult to prove. Sometimes they might be solutions but they're really difficult to find because they're rather big. So you can ask the following problem. This is Hilbert's 10th problem. Is there an algorithm to solve all diaphanetine equations? What this means is given a diaphanetine equation, f, x, y, z, and so on, the algorithm should either give you the output tell you there are no solutions or it should find a solution. Now having an algorithm to find a solution if there is a solution is actually really easy. All you have to do is to check all possible solutions in order until you find a solution. The problem is that if the diaphanetine equation has no solutions, your algorithm might just go on forever without ever stopping. So we want the algorithm to actually stop and tell you there are no solutions if there are no solutions. And the answer is that this is not possible in general. It doesn't mean it's impossible for any particular diaphanetine equation. I mean for particular diaphanetine equations we can quite often solve this. And the problem is there's no algorithm that will work for all diaphanetine equations. So this was originally shown by Robinson, Davies, Putnam, and the final step was done by Matje Sevic. Actually he did the last step in showing that this was impossible when he was about 22 or 23 or something. So he was pretty young. So another example of a diaphanetine equation is variations of Pell's equation. So we can ask, can you solve the equation x squared plus equals dy squared plus or minus what? So let me give some examples of this. So we can ask, can you solve x squared equals 94 y squared plus one? Well it turns out the smallest solution is x equals 2143295 and y equals 221064. So again, this is not something that would be easy to do by trial and error. But as we'll see later on in the course that there's a sort of reasonably efficient way of finding these solutions using continued fractions. This is another historical example of this problem. It's just done by Dudney who had some puzzle books. These are actually puzzles that I think he gave in a newspaper column or something. So here he has a puzzle about the Battle of Hastings where he says, well, the men of Harold formed 61 squares, all of the same size. And when Harold joined, they all formed one big square. So what you're trying to do is to solve the equation x squared equals 61y squared plus one. Oops, let me make a fight down a bit so you can see that. And again, the smallest solution of this turned out to be ridiculously big. So here's Dudney's solution. If you look here, he has the total number of men is this rather ridiculously large number here. So even harmless looking diaphanetine equations with rather small coefficients can have absurdly large smallest solutions. Another variation of this is the equation x cubed plus y cubed equals z cubed plus t cubed. And obviously there are trivial solutions because you can take x equals z and y equals t and so on. But we would like a non-trivial solution. And the smallest non-trivial solution would be 1729 is equal to 12 cubed plus one cubed, which is equal to 10 cubed plus nine cubed. There's a famous legend about this number that the mathematician Hardy claimed that he was once visiting Ramanujan when he was ill and mentioned to Ramanujan that his taxicab number was 1729 and said this is a very boring number. And Ramanujan said, no, it's a very interesting number. It's the smallest number that's the sum of two cubes in two different ways. And while this is a charming story, I'm rather skeptical of it because even among mathematicians you don't start conversations by telling the other person your taxicab number. I suspect what might have happened is that Hardy knew perfectly well that this number was the sum of two cubes in two different ways and was just giving it to Ramanujan in a sort of attempt to cheer him up because Ramanujan was feeling a bit miserable or something like that. But anyway, this is now notorious or famous or something as being Ramanujan's taxicab number. So the next part of the lecture I'll record separately because this is getting a little bit long and I'll be continuing examples of some problems in number theory.