 Welcome back to our lecture series math 3120 transition to advanced mathematics for students at Southern Utah University. As usual, I'm your professor today, Dr. Andrew Missildine. So in this first video for lecture 23, I want to talk about the so-called Euclidean algorithm. Now, in order to do that, we need to remember a little vocabulary we haven't talked about for a while. So recall that a common divisor of say integers a and b, a common divisor would be some other integer c such that c divides a and c divides b. We say that a common divisor is the greatest common divisor. Let's call it d for the moment for short. The greatest common divisor has the property that if you have some common divisor c of a and b, then in fact, c divides d as well. So that's why we call it the greatest common divisor. It's the biggest divisor in such that every other divisor will devise it as well. And of course, we're assuming that the greatest common divisor is a positive integer in this situation. Euclidean algorithm has a lot to do with greatest common divisors, our GCDs. So that review is a little bit necessary. Another thing I also want to mention before we talk about the Euclidean algorithm is a very, a very important, very useful lemma that will be useful not just in this, but in future considerations of integers. Suppose that we have a common divisor d of the integers a and b, then in fact, d will also be a common divisor of any linear combination of a and b. So a and b are integers. If r and s are also integers, such that d is a common divisor of a and b, then it turns out that d will divide the linear combination a, r plus b, s. In particular, it's true that the d would divide the sum of a and b. It would also divide their difference. So we use these properties all the times. So if, if d divides every term in a sum or difference, then it divides the sum and difference themselves. That's how we want to interpret this lemma. So to do so, let's take our assumption here. a is a common divisor, excuse me, d is a common divisor of a and b. Therefore, there exist integers x and y, such that a equals dx and b equals dy, like so. So then if you consider the linear combination a, r plus b, s, well, a is equal to dx, b is equal to dy. And so if we rewrite that sum on the right hand side, we can factor it as d times x, r plus y, z. And since x, r plus y, y, z, sorry, y, s, since that is an integer in the set z, this then tells us that d divides the linear combination a, r plus b, s. We're going to use this fact all the time in this video and also the future. So this is one that you're going to want to remember. Okay. Okay, so now we're going to prove that the greatest common divisor of two integers can be written as a linear combination of the integers themselves. So if a and b are integers and are there, so if a and b are integers, then there exist other integers, r and s, such that the linear combination a, r plus b, s is equal to the greatest common divisor of a, b, of a and b there. This is actually extremely useful property when one talks about lots of theorems involving integers. We use this one all the time. And this is essentially what we mean by the Euclidean algorithm. What we're going to do right now is we're going to prove that the integers, r and s exist. And this is going to be a consequence of the well ordering principle for which if you recall previously in our lecture series, we proved the division algorithm first by the well ordering principle, which guaranteed the existence of the quotient and remainder. But then like the division algorithm in this case, the well ordering principle, it doesn't give us the numbers, it just tells us they exist. We actually do need an algorithm to show what those numbers are. And that's where the Euclidean algorithm comes into play. We'll talk about that in just a second. But we're going to first prove their existence because we have to know they exist in order to find them. And so the algorithm actually depends on their existence. So we'll get to that shortly. But let's first prove that this linear combination is in fact possible. Now, in the statement here, I said that a and b can be any integers, but I'm actually going to push it towards the fact that we can assume without the loss of generality that a and b are actually positive integers. Because if b, for example, was equal to zero, if you take the GCD of any integer with zero, you get back a itself. And this is from the fact that zero is actually equal to a times zero. So therefore, a divides zero, a clearly divides a. And so that'll be the greatest common divisor between the two, if one of them zero. So we can assume that the integers a and b are non-zero. I guess I didn't finish the argument there. The GCD is equal to a. And you can write that as one times a plus zero times one. One and one are integers so that I can express a as a linear combination of a and b there, pretty easily, which is the GCD. So we can assume that a and b are non-zero. We can also assume that they're positive. Because for example, if b was negative, that means that negative b is actually a positive number. And so if this result, that is, if we can write the GCD as a linear combination, if that holds for positive numbers, then grab the GCD of a and negative b. Let's call it d. So d can then be written as some integer times a and some integer times negative b. Because again, negative b is a positive number there. Moving the negative sign over, if s was an integer, so is negative s. And therefore, d is equal to a r plus b times negative s. So without the loss of generality, we can assume the two integers going forward are positive. In particular, that makes them natural numbers. And that's how the well-ordering principle is going to come into play here. So to apply the well-ordering principle, the general template of the proof is the following. You're going to construct a subset of the natural numbers. In this case, we're going to take the set s, where we take the set of all possible linear combinations of a and b using integral coefficients. And we require that this linear combination be positive. So we take all of the a r plus b s's such that it's positive, where the r and the s are allowed to vary over integers. Now be aware, the r and the s do not have to be positive numbers. For example, if I take something like 11 minus two times three in this situation, my a is equal to 11, my b is equal to three, my r is equal to one, and my s is equal to negative two. Notice in this situation, 11 take away six is equal to five. This is a positive quantity, even if the coefficients are negative. That's perfectly acceptable. No worries about that. They just have to be, the r and s just have to be integers, but we want the linear combination a r plus b s to be positive. Now clearly, because we require that this integer to be a positive integer, this makes s into a subset of the natural numbers. The well-ordering principle guarantees that every non-empty subset of natural numbers has a minimum element. Well, is it non-empty? Now by assumption, a is a positive number, and therefore the same linear combination we considered beforehand, a is equal to one times a plus zero times b. That a is positive, so this linear combination is positive. It thus belongs to s. Therefore, we get that s is non-empty. b is also in that set, but to show that it's non-empty, I just need to show that there's at least something in there. There's going to be a bunch of stuff in there. It's probably going to be an infinite set, but nonetheless, we demonstrate at least one element so it's non-empty. Hence, the well-ordering principle applies to the set s. s then has a minimum element. Let's call that minimum element d, and then let's suppose that the integers r and s are specific integers that obtain the minimum element d. There could be other coefficients other than the r and s we have in consideration, but nonetheless, d is the smallest element inside this set, even if there could be other combinations that produce it. This is just one combination. That'll be enough for our consideration. Now, our goal now is to show that this minimum element, so this is how a well-ordering principle proof typically works. We come up with a set of natural numbers. We show it's non-empty, then we invoke the well-ordering principle to get a minimum element, and then we argue that the minimum element is the thing we were looking for, and if we set up the original set s correctly, that'll do it. We want to now show that d is the greatest common divisor of a and b. Now, if we can show that d is equal to the gcd of a and b, we know that d can be expressed as a linear combination of a and a and b. That's by construction, so that will then prove the theorem. We have to show that d is the gcd we're looking for. Now, to be a gcd, it has to first be a common divisor, and then we have to show it's the greatest common divisor at that point. Let's first show it's a common divisor. I claim that d is a divisor of a. That's what we're going to prove right now. We're going to begin by using the division algorithm, which we proved previously. By the division algorithm, there exist integers q and t such that a equals to qd plus t. In addition, we also know that the remainder t is strictly less than d, and it itself is non-negative. It could be equal to zero. We actually claim it's equal to zero. We'll see that in just a second. If you take this equation and solve it for t, you end up with t is equal to a minus qd. Remember, d is a member of the set s, and as an element of that set, it's a linear combination of a and b. If we substitute that in for d, we get the following equation right here. Now, if you distribute the q, we'll end up with a minus aqr plus, I guess it's a minus there, minus bqs. We can combine like terms and factor this. This looks like a times one minus qr plus b minus qs, like so. Now, this linear combination is equal to t. Again, by the division algorithm, t is non-negative. Let's consider the possibility if t was a positive number. This would mean that t would then belong to the set s. But wait a second, if t belongs to s, it's a linear combination, we also get by the division algorithm that t is less than d. If t belonged to s, then since t is smaller than d, this would violate the minimality of d. The well-ordered principle gave us that d was the smallest member of s. Since t is smaller than s, excuse me, since t is smaller than d, t cannot belong to the set s. As such, that means t can't be positive. But the other possibility, since t has to be greater than equal to zero, this would then mean that t is equal to zero itself. Now, if t is equal to zero, that then gives us that a equals dq. Hence, d divides a. Now, by a similar reasoning, we can use the exact same argument and show that d divides b as well. Therefore, d is a common divisor of a and b. That's the first step. Now, to be the greatest common divisor, we have to show that any other divisor of a and b also divides d itself. Now, let's suppose e is a common divisor of a and b. Now, remember, d is equal to a r plus b s. So by the limo we saw in the previous slide, since e divides a and e divides b, e will divide any linear combination of a and b. Therefore, e will also divide d itself. And as e was an arbitrary common divisor of a and b, we then can conclude that d is the greatest common divisor. That's what we're trying to seek out here. Now, like I mentioned, with the division algorithm, we did a similar proof. We used the well-ordering principle to show that the quotients and remainders existed, but it didn't actually tell you how to find them. We have to use long division from primary school, secondary school, to help us find that remainder and quotient. So how do we find these coefficients, r and s, which are guaranteed to exist? How do we find the greatest common divisor, which we know exists by the previous theorem? Well, this is where we're going to prove this. We're going to turn to the Euclidean algorithm, named after, of course, the very famous ancient mathematician Euclid. In particular, what we now describe in modern terms as the Euclidean algorithm was described in Euclid's classic text, The Elements, which a lot of important mathematics actually comes from that text. It's extremely old, thousands of years old, but Euclid's work is sort of like the first step towards what we now call modern mathematics, advanced mathematics. And so a lot of things are attributed to Euclid because of his work he did in The Elements here. So we're going to describe the Euclidean algorithm. So we're going to come up with an algorithm that produces the GCD of any two positive integers, A and B, and also produces the coefficients in that linear combination. And it turns out this will be a result of the well-ordering principle again. Basically, we're going to use induction to argue that this algorithm always works. Now, we're going to, this algorithm actually comes from a recursive sequence. Remember, recursive sequences are sequences defined using induction. We have to have a base case. And so in our sequence, we're going to have a sequence of numbers. We're going to call them Rn. They'll be in R0, R1, R2, R3, R4, R5 as n goes towards infinity. The first term in our sequence, R0 will be the positive number A. And the second number, R1, will be the positive number B. Without the loss of generality, we'll suppose that A is the larger positive number than B, okay? Because if they're equal to each other, like the GCD between A and A would be A, which therefore doesn't require any calculation. So we can assume that A and B are different. They're both positive, and we'll suppose A is the larger one. So A will be the zero term in this sequence. B will be the first term in the sequence. And then every other term in this sequence will be defined recursively as K is larger than or equal to two. And we'll recursively define it using the division algorithm. That is, to get R2, we can take A and we can divide it by B. We get some quotient Q. And then we get a remainder. We're going to call that remainder R2. Then for the next one, we're going to take B and we're going to divide it by R2. We'll get some other quotient. We'll call it Q2, I guess, to give it a name. And then we'll get another remainder R3. And then to get R4, we take R2 divided by R3. There's some quotient Q3. I actually don't care about the quotients here. We then get the remainder R4. And then we continue this odd infinitum, right? We just continue to do this over and over and over again. Therefore, to produce the kth term of the sequence, we take the K minus 2 remainder and we divide it by the K minus 1 remainder. And that produces then the kth remainder in this sequence here. So now I want to analyze what this sequence of natural numbers is doing. Now notice that each time we iterate this process, we look for the next remainder, then the next remainder, then the next remainder, these remainders are constructed using the division algorithm. And the division algorithm has the condition that the remainders are getting smaller over time. That is for the sake of our sequence here, we're going to get that R sub k plus 1 will be less than R sub k because the remainders are getting smaller and smaller smaller. But at the same time, the remainders are always going to be non-negative. We can't get a negative integer here. We only get pods of integers or 0. And as such, if we look at this sequence, this is a sequence of natural numbers. If we take the set of all remainders that appear in the sequence, that's a sequence of natural numbers which is non-empty because it does include A and B in it, for example. Therefore, the well ordering principle applies and the sequence contains a minimal element. Now, I should also mention that this is a sequence of decreasing natural numbers. So eventually, this sequence has to converge and I don't need any powerful calculus results like the monotone convergence theorem which would apply here. I can actually just get away with the pigeonhole principle. You have only finitely many boxes. A is the largest number in this sequence. And so if you take A, A minus 1, A minus 2, A minus 3, eventually all the way down to 0, you have finitely many boxes here. Finitely many boxes. On the other hand, our sequence is indexed by the natural numbers. So there's infinitely many terms in the sequence. So I should try to fit infinitely many pigeons into finitely many pigeonholes. There has to be at least one pigeonhole that contains a duplicate. In fact, I can say there's at least one pigeonhole that contains infinitely many pigeons. Imagine how that's going to fit there. But nonetheless, there has to be a repetition. And if there's repetition in this sequence, so there's some point where you're going to get Rn equals Rn plus 1, when you do the division there, you're going to end up with, well, the division will just turn out to be Rn plus 1 equals, excuse me, Rn equals 1 times Rn plus 0, which this next term is then Rn plus 2. And so eventually, because of repetition, eventually this sequence has to converge to 0. And so there'll be infinitely many terms in 0. Once it hits 0, it stays at 0. So let's consider the first non-zero number in this sequence. Sorry, not the first non-zero, the last non-zero number here. So let Rn be the last non-zero remainder in this sequence, because again, by the well-ordered principle, this will eventually approach 0. So I've been claimed that this number, this last non-zero remainder is the GCD, and we can prove this by induction. So if Rn is the last non-zero remainder, that means Rn plus 1 is equal to 0. In which case, if you look at the equation from the division algorithm, Rn minus 1 is equal to Q times Rn plus 0. I keep on using the symbol Q for the quotient, because I actually don't want to care what it is. There is some quotient, but the important thing is the remainder here is 0. So this tells us that you can scratch off that part, and Rn divides Rn minus 1, and note here that the GCD of Rn minus 1 and Rn is equal to Rn, because this always happens if A divides B, then the GCD of A and B is equal to A. A divides itself, A also divides B, so it has to be the greatest common divisor. We're making that observation right here. This serves as our base case. So the GCD between Rn minus 1 and Rn is Rn itself. So then let's suppose that the GCD of Rn minus K and Rn minus K plus 1 is equal to Rn. So then consider the division algorithm equation associated to Rn minus K and Rn minus K plus 1. So Rn minus K plus 1 is the remainder if you take Rn minus K minus 1 divided by Rn minus K. Now by Lemma 194, which we proved earlier in this video here, you can actually take this equation right here. Since Rn divides Rn minus K and Rn divides Rn minus K plus 1, by that Lemma has to also divide Rn minus K minus 1. So Rn is a common divisor of Rn minus K minus 1 and Rn minus K. I want to show that it's the greatest common divisor, so let's take some other divisor, call it D. So D divides Rn minus K minus 1 and Rn minus K. Now taking this equation and solving for Rn minus K plus 1, we get this equation and then we can apply the Lemma again. Since D is a divisor of this and that, then it has to also be a divisor of this. Now that then from there by our inductive hypothesis, the greatest common divisor in that setting is Rn and therefore D has to divide Rn because it's a common divisor of Rn minus K and Rn minus K plus 1. The GCD of them is Rn, so therefore D divides that. So since D was an arbitrary divisor of Rn minus K minus 1 and Rn minus K, we then can conclude that Rn is the greatest common divisor between Rn minus K minus 1 and Rn minus K. And therefore by induction, Rn is going to be the GCD of all of those consecutive remainders in the sequence we constructed. In particular, if you go to the start of the sequence, Rn will be the GCD of R0, R1, which of course is the GCD of A and B. Now I've just described and proved the Euclidean algorithm in a very abstract setting. Let's look at a specific example to see actually how it plays out. So let's take the numbers 9, excuse me, A equals 945 and B equals 2414. I always said A is supposed to be the bigger one, so it's okay. You can always swap them around, relabel them. It doesn't really matter whatsoever. We're going to start doing, we're going to do division over and over and over again. Multiplication is often described as being repeated addition. We're kind of going to treat division as being repeated subtraction. That's how the long division algorithm works. So I'm going to take 2415 and divide it by 945. So 945 goes into 2415 two times and you have a remainder of 525. So what I'm next going to do is I'm going to take 945 and I'm going to divide it by 525. 525 goes into 945 one times and it has a remainder of 420. Next I take 5200, 525, excuse me, and divide it by 420. Likewise 420 goes into 525 one time with a remainder of 105. And then I'm going to take 420 and divide it by 105. 105 goes into 420 exactly four times and you have a remainder of zero. So the fact that we got a remainder of zero then tells us that the last remainder that we had used is the GCD here. So this right here is the GCD of 945 with 2415. And the Euclidean algorithm is extremely slick and efficient at finding the greatest common divisor. The greatest common divisor you just do division over and over and over again. And then the last non zero remainder will be the GCD. And it turns out this algorithm, the Euclidean algorithm using the division algorithm is much, much more efficient than how most of us do it in grade school where we start to factor these things. 945 is five times something and this is also five times something and then you keep on factoring. You look for the prime factorizations for which that's actually a time consuming process in comparison to the division algorithm. I don't need a factorization of the two numbers to find their GCD. Now I also promise that the greatest common that the Euclidean algorithm doesn't just find the GCD, which was 105 in this situation. I can also express the GCD as a linear combination of A and B. And how do you do that? You actually take these, you ignore the last line, the fact that you get zero tells you that you terminate the process, you go to the previous line. And then you take these equations and you can actually start solving for 105. Like take this equation right here, 105 is equal to 525 minus 420. But then when you look at the previous equation, you can solve that equation for 420 and you can plug it into this equation right here. If you do that, you'll end up with 105 is equal to 525 minus and then you replace 420 with 945 minus 525 like so. So then when you combine like terms, you have a 525 and you get a minus minus 525. So you get two times 525 minus 945 like so, which notice 945 was one of the original numbers. Then you take the equation above that. So we've used this one now, we use this one. You take the equation above that, you solve for 525, you substitute that into the equation and you end up with 105. Equally, we have two times 525. 525 is 2415 minus two times 945. And then you subtract from it 945. And so then you try to combine like terms. You're going to get that 105. I'll do this in a different color to make it stand out here. You get that 105 is equal to two times 2415. And then here what happens, you're going to get two times negative two. That's a negative four. You're going to add another negative in there. So you end up with negative five times 945. And so sure enough, I'll let you double check that, that 105, which was the greatest common divisor between 2415 and 945, it can be expressed as a linear combination. I take two times 2415 and subtract from it five times 945. And that'll then produce the combination I'm looking for or again, our coefficients were two and negative five there. And so therefore this demonstrates how we can use the Euclidean algorithm, not just to find the GCD, but how we can express the GCD as a linear combination of the integers we wanted.