Quick Summary
LeetArxiv teaches programmers PhD-level math in C and Python. We code the original LLL paper in Python.

1.0 Paper Introduction
The 1982 paper, Factoring Polynomials with Rational Coefficients (Lenstra, Lenstra & Lovasz, 1982)1 introduced LLL, an algorithm for finding short vectors in a lattice in polynomial time.
The LLL (Lenstra, Lenstra & Lovasz) algorithm is used to (Hoejj, 2015)2:
Factorize polynomials with fractional coefficients.
Solve diophantine equations like we did before in Blankinship’s GCD algorithm.
Index calculus solutions like we did in Solving the Pell equation.
Perform linear algebra where integer solutions are desired.
Fun fact
Laszlo Lovasz was awarded an honorary degree from Yale in part due to this paper (Yale, 2024)3.
This is part of our series on LLL and we already covered lattice reduction in 2-Dimensions, and gaussian lattice sieving .
You can code along to the GitHub.
1.1 Introduction to Lattices
Informally, a lattice is the set of linear combinations of an integer basis (Harvard, Math 55A)4 or the subgroup generated by integer basis vectors.
Here’s a list of lattice-adjacent definitions from (Lenstra, 2008)5.
Lattice - a discrete subgroup of a Euclidean vector space.
Geometry of numbers - the branch of math that occupies itself with lattices.
Basis vectors - linearly independent vectors that generate a lattice.
Reduced basis - short basis vectors that are (or almost) orthogonal (Encyclopedia of Math, 2020)6
Rank of the lattice - a count of the number of basis vectors.
Fundamental parallelpiped of lattice - the shape in space formed by lattice basis vectors when the coefficients range between 0 and 1 (MIT, 2009)7
Determinant of the lattice - the volume of the parallelpiped matrix of the lattice.
LLL is a fast algorithm for finding short basis vectors that span a lattice. LLL-reduced bases satisfy the size condition and Lovasz condition summarized below (Vasylenko, 2026)8 :
2.0 LLL Reduction Algorithm
However convoluted the pseudocode looks, the algorithm’s super simple to state:
Find the gram-schmidt coefficient matrix of your current basis.
Attempt to subtract a multiple of your current vector from the other basis vectors.
Perform swaps and update the gram-schmidt.
All this is summarized in (Schaefer, 2021)9:
2.1 Coding LLL
This code is available on GitHub.
First, we write a function to perform Gram-Schmidt orthogonalization:
Then we used the function above to write an LLL reduction function:
We test our code and observe a reduced basis with small norms is found:
It works! The original paper was written for polynomial factorization and one would achieve this by:
Here are some free gpu credits from Runpod if you made it this far lol.
You might also enjoy:
References
Lenstra, A. K., Lenstra, H. W. Jr., & Lovász, L. (1982). Factoring polynomials with rational coefficients. Mathematische Annalen. 261 (4): 515–534.doi:10.1007/BF01457454
Hoejj, M.,. (2015). Solving problems with the LLL algorithm. Florida State University. Slides Link.
Lenstra, Jr. H.W,. (2008). Lattices. Surveys in algorithmic number theory, edited by J. P. Buhler and P. Stevenhagen, Math. Sci. Res. Inst. Publ.44, Cambridge University Press, New York.
MIT, 18.409. (2009). Lattice. In Topics in Theoretical Computer Science: An Algorithmist’s Toolkit. PDF Link.
Schaefer, S. (2021). LLL Algorithm. YouTube Video.

















