 All right, so let's take a look at an algorithm for reducing lattice vectors known as LLL. This is after the names of its three inventors, Lenzer, Lenzer, and Lavage. And so this is a reasonably efficient way of finding a reasonably orthogonal basis for a lattice. And conceptually, the algorithm consists of two parts. One, we're going to reduce a non-basis vector, our working vector, by subtracting integer multiples of our current basis vectors. And then we have to decide whether the working vector is going to be the next basis vector, or whether it should replace the basis vector immediately before it. So the decision of whether or not to replace a basis vector is based on the Lavage condition. Roughly speaking, what the Lavage condition does is it determines whether our working vector is big enough to be the next basis vector. And a little bit of preliminaries here, we need to keep track of two sets of vectors. We need to keep track of our current set of basis vectors, and we're trying to reduce this to a nearly orthogonal set. You might think about this set as being a provisional set of basis vectors. And then we also need to compute the set of orthogonal basis vectors that we obtained using the Gram-Schmidt reduction. And we also need to keep track of K. This is the number of the working basis vector. This is the vector that we're actually working to reduce at whatever instant we are in the process of applying the algorithm. So here's the issue. We have a bunch of basis vectors, and we are working to reduce this vector vk. And we have our first few basis vectors. We can think about these as our provisional basis vectors. And we want to reduce this vector vk, and we apply whatever technique we have. We're going to work in the expected fashion. We're going to subtract integer multiples of the previous basis vectors from our working vector. And then at the end of it, we now want to consider these last two vectors, this vk, our current value of our working vector. Again, this is not what we started with, but this is what we end up with after we've subtracted our integer multiples. And then we have our most recently added basis vector vk minus one. Now if there were only two vectors, then we might need to subtract some multiple of the new vk from the old vk minus one. That's our Gaussian reduction. So this requires swapping these two vectors, vk minus one and vk. Now since we have a new vk minus first vector, we then need to go through the entire process once again, this time trying to reduce vk minus one as our new working vector. And so here's the crucial question. When do we want to swap those last two vectors? And that's where the Lavash condition comes in. The decision of whether to swap is based on this Lavash condition. And so here's a reminder. We've also computed the Gram-Schmidt reduction. And so let vk be our working vector, and we're going to define this quantity mu k minus one to be the dot product of vk, our working vector, with vk minus one star. That's the k minus first orthogonal basis vector that we found in the Gram-Schmidt reduction. For vk minus one star, vk minus one star, that's the magnitude of vk minus one squared. So the Lavash condition is then going to be evaluated as follows. If the magnitude of the k-gram-Schmidt vector squared is greater than or equal to three quarters minus this mu squared times the magnitude of the k minus first Gram-Schmidt vector squared. Then vk is an acceptable basis vector, and I can move on to the next vector. Otherwise, I'm going to swap and make vk minus one the working vector. Roughly speaking, the Lavash condition is a size condition. It makes sure that our next vk, our next basis vector, is maybe a little bit larger or so than the preceding vector. Very roughly speaking, this is what it does. Well, let's see how that works. So we've already solved this problem using Gaussian reduction. It would be nice if we got the same answer using the LLL algorithm. So we can see how that's going to work. We're going to choose one of those as our first basis vector, and we'll reduce the second vector. So let's choose 2L137 as our first basis vector. This is the vector we're trying to reduce. So we start by finding the Gram-Schmidt orthogonal basis, and how that works. Well, we'll pick one of our vectors, this one, as our first Gram-Schmidt vector, then we'll reduce the second vector by the Gram-Schmidt process. So that's going to be the second vector minus the projection onto the first vector times 2L137, and that works out to be approximately this as our second vector. So we have our first Gram-Schmidt vector. We have our exactly up-to-rounding orthogonal vector for V1, and there's our Gram-Schmidt basis. Now I want to use V1 to reduce my working vector. So I'm going to take my working vector. I'm going to subtract the rounded dot product, and that gives me 41. And that's now my new vector V2. Now here's an important thing for future reference. It doesn't matter now that we only have two basis vectors, but it'll make a difference in the future. The coefficient here is computed based off of the Gram-Schmidt vector, but it's being multiplied by the lattice vector. Now with just two basis vectors, the Gram-Schmidt vector and the basis vector for the lattice are the same vector, but as we'll see when we look at a three-vector example, they are going to be different. So that's something to keep in mind for future reference. All right, so we've computed our second basis vector, and so now we check the Vash condition to see if we like this or whether we should switch. So we'll calculate our magnitude, magnitude again of the Gram-Schmidt basis vector. The magnitude of the Gram-Schmidt basis vector, the dot product of the new basis vector with the Gram-Schmidt basis over the magnitude squared of the Gram-Schmidt basis vector. And then we'll calculate three-quarters minus mu squared, 0.713. And then I'll check is this greater than or equal to three-quarters minus mu squared times the Gram-Schmidt basis, and it's fairly easy to see that that's not going to be the case. And what that tells us is we need to swap our V1 and V2 vectors. So we'll make that swap, and then again our new V2 is going to be our working vector. So I'll try to reduce the second vector. I have to apply the Gram-Schmidt reduction. So again I'm going to make my first Gram-Schmidt basis vector the first vector, and I'm going to make the second Gram-Schmidt vector. Again, that's going to be my second vector minus the dot product minus the projection. And again, that's going to give me an approximate value of that. And again I'll use V1, my first lattice vector, to reduce my second lattice basis vector. And so again, this is going to be my second basis vector minus the appropriate dot product. Again, this vector here you should keep in mind that's actually our first Gram-Schmidt basis vector. This vector is actually our first lattice vector. And again, these vectors here, that corresponds to the square of the magnitude. Again, that corresponds to the actual Gram-Schmidt basis and not the lattice. Again, in two dimensions these vectors are the same, so it doesn't make any difference. But in three or more dimensions it will make a difference. So I'll compute that, and it works out to be my second basis vector is going to be 132. I'll compute the Lavage condition, magnitude of the Gram-Schmidt basis, magnitude of the Gram-Schmidt basis, dot product, working vector, Gram-Schmidt basis, Gram-Schmidt basis, Gram-Schmidt basis, point out 4.5, my lambda condition. And again, we check the Lavage condition. The magnitude squared is not greater than or equal to 3 quarters minus mu 2 1 times this. So again, we should swap our two basis vectors and continue. So again, we'll take our first Gram-Schmidt basis vector to be the first vector, and I'll apply the Gram-Schmidt reduction to reduce this one. So again, that gives me my two Gram-Schmidt basis vectors. And I'll use my first lattice vector to reduce my second lattice vector to 41, and V2 remains 41, checking the Lavage condition. And I find that my Lavage condition is satisfied when I look at the square of the magnitude. It is greater than 3 quarters minus mu squared times the square of this magnitude. And so that would say I could move on to the next basis vector, except there's only two basis vectors here. So that means we're done, and this is going to correspond to our reasonably orthogonal set of basis vectors for the lattice.