 This lecture is part of Berkeley Math 115, an introductory undergraduate course on number theory, and will be mostly about solving equations modulo prime powers. So the problem we have is we want to solve the equation f of x is common to 0 modulo m. And we quickly recall we do this in several steps. First of all we can reduce to the case where m is a prime power using the Chinese remainder theorem. Next we reduce from the case of prime powers to the case of primes. And thirdly we do the case of m being a prime. And what we're going to do in today's lecture is this one here. So I previously covered the Chinese remainder theorem and in a future lecture we'll be discussing the case when m is a prime number. So we're going to discuss several methods for reducing from the case p to the n to the case of p. The first method we're going to discuss is the stupid method. The next case is the not quite so stupid method. The third case is essentially Hensel's lemma, or Hensel's method. And the fourth method is Newton's method. Actually this is really only three methods because Hensel's method and Newton's method are really the same. Except they're the same if you look deeply. I mean superficially they look different but they're really the same method. So let's try and solve the following equation in order to illustrate the methods. Let's suppose we want to solve x squared is common to seven, modulo three to the hundred. And let's try a stupid method is to try x equals zero, one, two, all the way up to three to the hundred. Well three to the hundred minus one I guess. Well this is obviously far too slow. So here we have three to the hundred is our number p to the n. And this is going to take about on the order of p to the n steps. And this will just be huge at least if n is reasonably large. You take more than the age of the universe to find the solution. So let's have a slightly better method. What we're going to do is first of all solve mod three to the one, then mod three to the two, then mod three to the three and so on and gradually work our way up. So we can solve mod three. You want to solve x squared is common to seven, mod three. And here, well the prime is pretty small. So let's just use trial and error. We just test all the numbers mod three to see which of them has squared equal to seven. And we can find the solution is x is congruent to one, mod three. There's another solution x is congruent to minus one, mod three. But let's just take x equals one, mod three. And next we want to solve the equation. Let's call this x one. Next we want to solve x squared is common to seven, mod three squared. And we notice that this implies that x is seven, mod three. So let's start by taking x is congruent to x one, mod three. And now this means that x is equal to x one or x one plus three or x one plus six. And we can just try these and see which works. So try to see which works. And if we do this, we can find the solution x two is equal to x one plus three times one. So we take this solution here. And now we do the same thing. We want to solve x squared is congruent to seven, mod three cubed. And we try x is going to be equal to x two plus three squared times something or other. And there are only three possibilities because I carefully chose three to be a small prime here. If this was a bigger prime, this would be a bit more difficult. We'll discuss that in a moment. And we find that we can then find that x, let's call it x three is going to be x one, which is one plus three times one. So this is x two. And then we just do some trial and error. And we find we get naught times, sorry, one times three squared. And then we can go on like this and we find x four is equal to one plus one times three plus one times three squared plus naught times three cubed and so on. And we can keep on producing more and more numbers like this as long as our patients holds out. In fact, you can think of this as the number for x for one, one plus one times three plus one times three squared plus naught times three cubed sort of looks like a number in base three. We can just write it down as one, one, one, zero in base three and we can continue like this. In fact, and we find it sort of looks like this in base three. In other words, if you take this bit of the number, it will be a solution modulo three to the one, two, three, four, five, six, seven, eight and so on. So that's the slightly better method. And let's check how many steps to work to get a solution mod p to the end where we need n steps where we take x one up to x two up to x n. But each step we need to search through p possible answers. So it takes about O of p and p times n steps, which is much less than O of p to the n steps, which was the stupid method. So we've speeded things up a reasonable amount. And if p is small, like three or five or something, this is actually a perfectly good method. But it's not going to work so well if p is really large, you know, if p is a 10 or 20 digit number, then this will this will get rather tediously slow. Fortunately, there's a better method. But due to Hensel, but before doing that, let's discuss a problem with this method. So you notice we're taking x one and then lifting it to a solution x two and then lifting it to a solution x three. So this is modulo three. This is modulo three squared modulo three cubed and so on. And we have the following problem. Can we always lift x i to x i plus one is this unique. Now in the problem we did of working out x squared is cognitive seven modulo three to the n. It turns out the lift always is exist and always is unique. However, this this does not always this need not be true. The solution sometimes might not exist and might not be unique even if it does exist. So so let's see an example where it gets a bit more complicated. Let's do the example of x squared is cognitive 17 modulo two to the something big say two to the 10. And let's solve it mod two. Well, mod two x is going to be congruent to one. There's no problem. Mod four, there are two things x can be one or three. So one squared and three squared above 17 mod two mod eight. There's no problem yet. We get one, five, three and seven. And the reason I'm writing them in this funny order is because one and five lift one and three and seven kind of lift. Lift three. So here we're getting two ways of lifting a solution mod four to a solution mod eight and two ways of lifting this solution to a mod eight. So the solution is not unique. But it gets worse because if we do one and 16, we can lift one to one or nine modulo 16. We can lift seven to 15 or seven, I think. And however, we can't lift three or five at all. So three and five turn out to be sort of fake solutions that you can't lift them any further. So we come to a stop at this point. And mod 32. Similarly, nine can be lifted to nine and it can also be lifted to 41. So nine lifts nine or 25. Seven can be lifted to seven or to 23. And 15 has no lifts to a solution and one has no lifts. And it sort of goes on like this at each step. Some of the solutions can be lifted to two solutions and some of the solutions of no lifts at all. So this is rather more complicated than the case of X squared is convent of three modulo three to the N. So now we get onto Hensel's lemma, which will sort of partly explain why this kind of goes wrong and the previous example worked. So Hensel's lemma looks the following. Suppose we've solved f of X1 is convent to zero mod P. And we try to solve f of X1 plus AP is convent to zero mod P squared. So we've got a solution is a solution mod P. And this is going to be a solution mod P squared, which lifts the solution we found mod P by adding a multiple of P and a is the number that we're trying to find. So we want to find what is a. Well, let's apply Taylor's theorem where we can you remember this says f of this says f of X1 plus a times P is equal to f of X1 plus. AP times the derivative of f of X1 plus AP squared over two factorial times the second derivative of X1 and so on. And if X1 is a polynomial, then. Well, you might think we can't really differentiate things because you know f is a sort of function mod P or something, but we can define derivatives of polynomials perfectly well. And this formula works just fine for polynomials. It's not really an infinite series at all. It's just a finite series that you can check. And now this is going to be mostly divisible by he squared. Well, maybe not because we've got this division by two factorial. So if P was equal to two, we might possibly get a little problem there. We'll have to discuss that later. So let's put a slight question mark there because we kind of hope this is going to be divisible by P squared and we hope all the other terms will also be divisible by P squared. And now we've got to solve this. We want this to be this bit to be congruent to zero mod P squared. And you notice that f of X1 is already zero mod P by assumption. So we've got to add a multiple of P. And to do this, all we have to do is to solve a P f prime of X is congruent to P times something or other modulo P squared. And then we can divide through by P and we have to solve a of f prime of X. Sorry, X1 is congruent to something or other modulo P. Since we're dividing this by P, we need to divide this thing by P as well. So we've got to solve this equation for a where where star is some complicated mess I don't really care about. I mean, you can work out what it is. And you notice this is solvable if f prime of X1 is not congruent to zero modulo P because then it has an inverse. So this sort of explains why the first problem we did of solving X squared minus seven is congruent to naught mod three to the n has a solution because the derivative of this is 2X and 2X at X equals one is none zero mod three. Whereas if we try and solve the other one, X squared is congruent to 17 modulo two to the n. Then we notice that the derivative is actually divisible by P at the solution we found, which is why things were going a bit funny. So for example, this says we can solve X squared is congruent to seven modulo three to the n for any n. Because the derivative, if we take f of X is X squared minus seven, then f prime of X is equal to 2X. And this is not congruent to zero mod three for X equals X1 where X1 is the number one. So, okay, well, strictly speaking, we only showed that work for the first step. But if we try and solve modulo P to the n plus one, so we can say if we've got a solution f of Xn is congruent to zero mod P to the n, we want to lift this to f of Xn plus a times P is congruent to zero modulo P to the n plus one. And you can do almost exactly the same thing that we did in the case n equals one. We just write this as f of Xn plus a P f prime of Xn. And we notice that this is not congruent to zero mod P. And then this is going to be a piece a P or squared times something or other. And this will be divisible by P to the n plus one if we go far enough. You notice that, sorry, that's not an a times P. It's a times P to the n here. So that's a times P to the n squared. This is indeed divisible by P to the n plus one. So just as before, this ends up having to solve a times f prime of Xn is congruent to something complicated modulo P. And we can solve this because f prime of X is not congruent to zero mod P. Well, there was one slight problem that we put off for later. There was this funny factorial on the bottom. So it's not entirely clear. This really is divisible by some power of P because there might be some factors of P in the bottom. So let's take a closer look at this. We've got a term something to the n times d by df to the n of f of something divided by n factorial. And the key point here is that if we take a polynomial f of X and differentiate it n times and divide by n factorial, this has integer coefficients. So we can take a look at this. So f of X might be say, let's just do the case of X to the K. It's enough to do a monomial bilinearity. Then the first derivative is K X to the K minus one. Well, this term has integral coefficients. The next derivative is K times K minus one X to the K minus two. And if we divide that by two factorial, then this still has integer coefficients because either K or K minus one is even. So this division by two really doesn't matter. The next derivative is going to be K, K minus one, K minus two. And then we have to divide by three factorial from the Taylor series. Then we get X to the K minus three. And we notice this is again an integer because it's just a binomial coefficient and binomial coefficients are integers. So the coefficients of the derivatives of X to the K, if we take the derivative and divide by n factorial, this will always be an integer because it's just a binomial coefficient. So when we wanted all these things to be divisible by p squared or whatever, all the factorials at the bottom don't really matter because they're cancelled out by factors we get by taking a high derivative of f. So to summarize, we get Hensel's lemma. We can solve f of X is congruent to zero mod p to the n if, first of all, we can solve mod p. So we find f of X one is congruent to zero mod p. So we have to solve mod p just to get everything going. And secondly, when f prime of X one is not congruent to zero mod p. And if this condition holds, then X one can be lifted to a unique solution modulo p to the n for any n. So we notice that this condition really is necessary. So for instance, X squared is congruent to five can be solved mod two and two squared, but not modulo two cubed. And you see this condition fails. We have f of X equals X squared minus five and X one equals one. But f prime of X one is not congruent to zero modulo two. So condition two fails. I mean, we can find a solution mod two and we can even lift it to a solution mod two squared, but then we get stuck mod two cubed. So now Hensel's method is a lot faster if p is large, because the number of steps is very roughly O of n. Well, there should be factors of log of p to the power of something in there. But you can say that this is less than the previous method, which was took about p times n steps, because every step we had to test p different values and Hensel's lemma says provide the derivative is non zero. You don't have to test all these p values. You can just find the solution directly by dividing by the derivative, which is fast using Euclid's algorithm. So finally, we will discuss Newton's method. Now, if you've been to a numerical analysis course or maybe even a calculus course, you've come across Newton's method for real function. So we want to solve f of x equals zero where f is now some sort of real function. And you remember it goes like this. What we do is we sort of look at the graph of f of x. So this is y equals f of x. And then we choose some value x one say. And what you do is you make the following construction. You look at the point on the graph with x coordinate x one, and then you draw the tangent line down here. And this is going to be the point x two. And then you do the same thing again. You draw the tangent line here and we get the point x three. And geometrically, it's very plausible that these numbers x one, x two and x three will get closer and closer to a root of f of x. So we can easily write down the formula for x n plus one. You can see that this point here is x one f of x one. And this line here has slope the tangent of f of x one. So you can work out what the tangent line is and work out where it intersects the origin. And we find x two is equal to x one minus f of x one divided by f prime of x one. And similarly, x of n plus one is equal to x of n minus f of x n divided by f prime of x n. So this is Newton's method. And sometimes it converges to a root of f and sometimes it goes horribly wrong. I mean, if you start close to a zero of multiplicity one, then Newton's method works really, really well and converges really fast. If you start at some random point, then Newton's method sometimes just goes completely chaotic and can start x one, x two and x three can sort of start jumping all over the place or end up in a cycle or something weird. So anyway, sometimes it works and sometimes it doesn't. So now instead of doing it for the reals, let's do it for modulo p to the n. So suppose f of x, suppose f of x is congruent to zero, modulo p to the n for some n. And we're going to now look at x minus f of x divided by f prime of x. So we apply Newton's method. Let's try and work out what this is. Well, we have f of x minus f of x over f prime of x. And we expand this out by Taylor's theme. So it's going to be f of x plus f prime of x times minus f of x over f prime of x. So that's this term here. Then we get plus f double prime of x over two factorial times minus f of x over f prime of x all squared and so on. And now a key point here is that the first two terms cancel. In fact, Newton's method is the choice of this funny correction to x is sort of more or less designed so that the first two terms cancel out with each other. And what about the remaining terms? Well, this will be some sort of integer because you remember the two factorial kind of cancels out with the second derivative. And what about this term here? Well, this will be divisible by p to the 2n if f prime of x is not congruent to zero modulo p. Because if it's not congruent to zero mod p, then it has an inverse modulo p to the n. And f of x is divisible by p to the n. So f of x squared is also divisible by p to the n. And similarly, all the remaining terms will be divisible by p cubed p to the 4 and so on. So the conclusion is that f of x minus f of x over f prime of x is congruent to zero mod p to the 2n if f prime of x is not congruent to zero mod p. If it is congruent to zero mod p, we may not even be able to do this division modulo p. So this gives Newton's method. It says that if f of x is congruent to zero mod p to the n and f prime of x is not congruent to zero mod p, then f of x minus f of x over f prime of x is congruent to zero modulo p to the 2n. And you notice this condition will still be satisfied for the new solution because this is congruent to x modulo p. So if we start off with a number whose derivative is non-zero, we will keep getting numbers whose derivative is non-zero. So we double the exponent of p at each step. And you notice this is actually much better than Hensel's method because Hensel's method sort of adds one to the exponent at each step, whereas now we're actually doubling it. But actually they're not really all that different. You notice both Newton's method and Hensel's method depend on the fact that derivative is non-zero. And this should give you a strong hint that they're actually very closely related. And in fact you find that Newton's method really is just Hensel's method if you write it out except we're noticing. You just sort of do Hensel's method except you just notice that you actually double the number of... double the exponent of p. So let's just have an example of Newton's method. So let's solve... Suppose we found the solution 13 squared is congruent to 7 modulo 3 cubed. And we want to solve something squared is congruent to 7 mod 3 to the 6. So we take our polynomial to be f of x is equal to x squared minus 7, so f prime of x is just 2x. So f prime of 13 is equal to 26, which is not congruent to 0 mod 3, so we're okay. So the new root is 13 minus 13 squared minus 7 divided by 26. So this is the number x, this is f of x, and this 26 is f prime of x. And of course we're doing all this modulo 3 to the 6. We're not taking the rational number 13 squared minus 17 over 26. We're taking 13 squared minus 7 over 26 modulo 3 to the 6. And you can work this out using Euclid's algorithm as before, and this is congruent to 175 modulo 3 to the 6. So 175 squared is congruent to 7 mod 3 to the 6. And if we repeat this, we will get a solution modulo 3 to the power of 12, and then 3 to the power of 24. So the exponent of n is increasing really rapidly. Okay, so I think I'll have a break now. In the next part of this lecture, I'll discuss what happens if the derivative of f is non-zero.