# LLL(...,Strategy=>...) -- choose among different algorithms

## Synopsis

• Usage:
LLL(...,Strategy=>n)
• Inputs:
• The strategy n can be one of the symbols or lists given below.

## Description

There are several variants of the LLL reduction algorithm implemented. There are three all integer versions: NTL, CohenEngine, and CohenTopLevel. The NTL version (NTL is an excellent package written by Victor shoup) is generally the best, however, the top level version is written in the Macaulay2 language, and so is easily modifiable and can be used to understand the algorithm better. There are also a number of approximate LLL variants implemented in NTL. These use real numbers instead of exact integer arithmetic, and so are often much faster, but only provide approximate answers (i.e. the result might not be an LLL basis, only close to one). Much of the information here about NTL's algorithms comes directly from the NTL documentation (translated to be relevant here).

Here is the complete list of possible strategies:

• LLL(m, Strategy => NTL)
• LLL(m, Strategy => CohenEngine)
• LLL(m, Strategy => CohenTopLevel)

• LLL(m, Strategy => RealFP)
• LLL(m, Strategy => RealQP)
• LLL(m, Strategy => RealXD)
• LLL(m, Strategy => RealRR)

• LLL(m, Strategy => {Givens,RealFP})
• LLL(m, Strategy => {Givens,RealQP})
• LLL(m, Strategy => {Givens,RealXD})
• LLL(m, Strategy => {Givens,RealRR})

• LLL(m, Strategy => {BKZ,RealFP})
• LLL(m, Strategy => {BKZ,RealQP})
• LLL(m, Strategy => {BKZ,RealQP1})
• LLL(m, Strategy => {BKZ,RealXD})
• LLL(m, Strategy => {BKZ,RealRR})

• LLL(m, Strategy => {BKZ,Givens,RealFP})
• LLL(m, Strategy => {BKZ,Givens,RealQP})
• LLL(m, Strategy => {BKZ,Givens,RealQP1})
• LLL(m, Strategy => {BKZ,Givens,RealXD})
• LLL(m, Strategy => {BKZ,Givens,RealRR})
The first three are similar all-integer algorithms, basically the one which appears in H. Cohen's book. The rest of the algorithms are approximate variants, provided by Victor Shoup's NTL package. For these, there are three choices to be made: (1) the reduction condition, (2) the choice of orthogonalization strategy, and (3) the choice of precision.

## Reduction condition

• default -- the classical LLL reduction condition
• BKZ -- Block Korkin-Zolotarev reduction.This is slower, but yields a higher-quality basis, i.e., one with shorter vectors. For a description, see [C. P. Schnorr and M. Euchner, Proc. Fundamentals of Computation Theory, LNCS 529, pp. 68-85, 1991]. This basically generalizes the LLL reduction condition from blocks of size 2 to blocks of larger size.

## Orthogonalization Strategy

• default -- Classical Gramm-Schmidt Orthogonalization, This choice uses classical methods for computing the Gramm-Schmidt othogonalization. It is fast but prone to stability problems. This strategy was first proposed by Schnorr and Euchner in the paper mentioned above. The version implemented here is substantially different, improving both stability and performance.
• Givens -- Givens Orthogonalization, This is a bit slower, but generally much more stable, and is really the preferred orthogonalization strategy. For a nice description of this, see Chapter 5 of [G. Golub and C. van Loan, Matrix Computations, 3rd edition, Johns Hopkins Univ. Press, 1996].

## Precision

• RealFP -- double
• RealQP -- quad_float (quasi quadruple precision) useful when roundoff errors can cause problems
• RealQP1 -- only available in the BKZ variant, uses double precision for the search phase of the BKZ reduction, and quad_float for the orthogonalization
• RealXD -- xdouble (extended exponent doubles) useful when numbers get too big
• RealRR -- RR (arbitrary precision floating point) useful for large precision and magnitudes
Generally speaking, the choice RealFP will be the fastest, but may be prone to roundoff errors and/or overflow.

## Putting it all together

This subsection comes directly from Victor Shoup's LLL documentation

I think it is safe to say that nobody really understands how the LLL algorithm works. The theoretical analyses are a long way from describing what "really" happens in practice. Choosing the best variant for a certain application ultimately is a matter of trial and error.

The first thing to try is Strategy => RealFP. It is the fastest of the routines, and is adequate for many applications.

If there are precision problems, you will most likely get a warning message, something like "warning--relaxing reduction". If there are overflow problems, you should get an error message saying that the numbers are too big.

If either of these happens, the next thing to try is Strategy=>{Givens,RealFP}, which uses the somewhat slower, but more stable, Givens rotations. This approach also has the nice property that the numbers remain smaller, so there is less chance of an overflow.

If you are still having precision problems try Strategy=>RealQP or Strategy=>{Givens,RealQP}, which use quadratic precision.

If you are still having overflow problems, try Strategy=>RealXD or Strategy=>{Givens,RealXD}

I haven't yet come across a case where one *really* needs the extra precision available in the RealRR variants.

All of the above discussion applies to the BKZ variants as well. In addition, if you have a matrix with really big entries, you might try using Strategy=>{Givens,RealFP} or Strategy=>RealXD first to reduce the sizes of the numbers, before running one of the BKZ variants.

Also, one shouldn't rule out using the "all integer" LLL routines. For some highly structured matrices, this is not necessarily much worse than some of the floating point versions, and can under certain circumstances even be better.

 i1 : m1 = map(ZZ^50, ZZ^50, (j,i) -> (i+1)^8 * (j+1)^4 + i + j + 2); 50 50 o1 : Matrix ZZ <--- ZZ i2 : m = syz m1; 50 47 o2 : Matrix ZZ <--- ZZ i3 : time LLL m; -- used 0.0162097 seconds 50 47 o3 : Matrix ZZ <--- ZZ i4 : time LLL(m, Strategy=>CohenEngine); -- used 0.0779385 seconds 50 47 o4 : Matrix ZZ <--- ZZ i5 : time LLL(m, Strategy=>CohenTopLevel); -- used 0.173686 seconds 50 47 o5 : Matrix ZZ <--- ZZ i6 : time LLL(m, Strategy=>{Givens,RealFP}); -- used 0.0239203 seconds 50 47 o6 : Matrix ZZ <--- ZZ i7 : time LLL(m, Strategy=>{Givens,RealQP}); -- used 0.0969379 seconds 50 47 o7 : Matrix ZZ <--- ZZ i8 : time LLL(m, Strategy=>{Givens,RealXD}); -- used 0.112375 seconds 50 47 o8 : Matrix ZZ <--- ZZ i9 : time LLL(m, Strategy=>{Givens,RealRR}); -- used 0.606216 seconds 50 47 o9 : Matrix ZZ <--- ZZ i10 : time LLL(m, Strategy=>{BKZ,Givens,RealQP}); -- used 0.223222 seconds 50 47 o10 : Matrix ZZ <--- ZZ

## Further information

• Default value: NTL
• Function: LLL -- compute an LLL basis
• Option key: Strategy -- an optional argument

## Caveat

For most of the options, the columns do not need to be linearly independent. The strategies CohenEngine and CohenTopLevel currently require the columns to be linearly independent.