Lattice Tester Guide
1.0-9
Software Package For Testing The Uniformity Of Integral Lattices In The Real Space
|
This page contains very basic and relatively short examples demonstrating the usage of the principal functions of LatticeTester.
The examples featured here are available in the directory examples of the repository. They are compiled along the library and their source code includes the description of their usage.
These examples where conceived with two goals in mind:
In the examples you will learn how to create the objects representing the lattices and manipulate them, how to use the methods to manipulate those lattices basis, how to use the reduction algorithms available and how to compute basic mesures of interest like the spectral test and the normalized version of the spectral test.
Please note that the code presented here is in C++, meaning that much of it include statements, variable declarations and output formatting. The code segments relevant to the examples (that actually showcase LatticeTester fonctionnalities) have been commented to facilitate the code reading.
It is not advised to run the BasisConstruction and the Reduction examples on a local machine because they use matrix sets that test their limits. Their execution takes a long time and uses a lot of memory. Users are nonetheless ecouraged to play with these examples, either by modifying them, or by generating another matrix set with the python3
script in the examples/bench.zip
archive.
In the event that you should need more flexibility than what is offered by the executable, we also present the classes containing the main functionnalities of LatticeTester. There are three of them bringing together similar computations :
BasisConstruction
grouping functions helping with basis, dual, and projection constructionsReducer
with functions to do basis reduction and solve the shortest vector problemLatticeAnalysis
that contains functions to do the computation of figures of meritThis section won't go into the depth of each of those class since it would be redundant with their documentation. Instead, we point to the examples, where their usage is demonstrated. We also point out to the following classes without which the usage of the main classes would be difficult :
IntLatticeBasis
is a class representing a lattice basis. This is the lowest level class available to represent a lattice in LatticeTester and it is the class that is needed for the instanciation of a Reducer
.Config
stores all the configuration for the execution of a LatticeAnalysis
. It is possible to lauch tests by passing a Config
object to a LatticeAnalysis
.ParamReader
implements a simple interface to read information from files. It also offers methods to initialize a Config
object from the format of file specified above.Normalizer
is a base class to the implementation of a normalizer to figures of merit. There are many modules implementing various normalizers for the spectral test that are available in LatticeTester.Weights
is a base class to weight multiple figures of merit in some way to build a figure of merit of of them. Although this is not directly used by LatticeTester, it is relevant to point out this class to users interested in computing figures of merit with multiple projections from a lattice.The following example showcases the usage of LatticeTester::BasisConstruction
, either directly on matrices or on IntLatticeBasis
objects. One of the repercutions this has is that this example also showcases how to create an IntLatticeBasis
object.
This example compares the execution time of the two different methods for basis construction as well as the time taken to build a dual basis after one or the other. BasisConstruction
contains two methods to build a basis from a set of generating vectors, GCDConstruction
and LLLConstruction
, described on the LatticeTester::BasisConstruction
page. It is these methods that are compared here. Bellow is the code for the example.
There are two things to learn from this example. First is how to create an IntLatticeBasis
. Second is the way that the BasisConstruction
class is used.
When working only with LatticeTester
it is recommended to represent lattices only by using the IntLatticeBasis
class instead of the IntLattice
class. The reasoning is that IntLattice
does not bring any new functionnality by itself, it is a class that contains virtual methods specifying an easily expandable interface for different lattice types. It is also better to use IntLatticeBasis
because the constructor is all that is needed to get a usable object as is done in this example. This is not the case of the IntLattice
class.
Secondly, the BasisConstruction
class is also very straight forward. Once the object is created, its methods can be called on matrices to transform them in place. Note that the usage of this class does not follow standard object oriented design. Since the algorithms in it are quite simple and are to be applied on basic types only, this constructed more like a container for those function, regrouping them in one simple location. Hence, when an object of this class is created, it is then possible to apply the contained algorithms on different objects as is done here.
The output of this program looks like this:
This is an example showing of the usage of both LatticeTester::ParamReader
and LatticeTester::WriterRes
. These two classes can read from files and format output to them. Since this functionnality is the main way to make a program interractive, most uses that are not scripting will need these classes. Both classes can be created easily, simply by specifying a path for a file that ParamReader
will read from and that WriterRes
will write to. most methods are named quite explicitly as can be seen below.
The way that the reader class works, is that you call a method such as readBMat
in the example and it will store the requested type in a container specified as the first argument. It reads on a line specified as the second argument (starting from 0) and reads starting from the n-th word of that line (n being specified as a third argument, starting from 0). If a fourth argument is needed, it is type specific like here where the matrix needs a dimension.
The writer class works the same, but is a little simpler since everything is written sequentially. This class can also (try to) enforce indentation of the ouputed text. To do that, the usage of the newLine
method, as is done in this example, is needed. This example is fairly limited in scope and does not contain other other information relevant to the usage of LatticeTester
.
This following example is about the usage of the LatticeTester::Reducer
class. This class is central to LatticeTester and contains the most important features of the library. This example uses most of the functions of that class and tries to compare their execution times. This example works very similarly to the BasisConstruction
example.
This example first showcases the usage of the Reducer
class. This class is one that is given a LatticeTester::IntLatticeBasis
and then performs various algorithms on it when its methods are called. The methods this class implements perform what we call "reductions". Reductions are algorithms that reduce, in one way or another, the length of the vectors in the basis stored in the IntLatticeBasis
. This example calls most of them, and the code bellow links to the documentation of these methods.
The program tests three reductions (Dieter, LLL and BKZ) in two ways. First, it performs it and times the execution of the reduction algorithm itself. this is what is shown in the first 3 columns of the results. The program then perform the "Shortest Vector" reduction, which is the search for the shortest non-zero vector in the lattice (see Background). This search is particularly costly so reducing the lattice basis first usually gains time. The next 3 colums show the execution times for the shortest vector reduction depending on the reduction algorithm used first. Finally, the example also records the number of failures of the shortest vector search for each algorithms. Below is an example output for this example.
This examples shows how it is possible to use LatticeTester to compute a variety of figures of merit. This example uses a few different tools that have not been presented before: LatticeTester::BasisConstruction
as a way to build projections of a lattice, LatticeTester::CoordinateSets
, a namespace containing classes to create indices sets and LatticeTester::Weights
and its subclasses that ease the weighting of different projections in a figure of merit.
Note that this example is fairly short, which stands out from the other examples, but also from what we would expect from a typical C++
program. Only a few more lines would be needed to make this program read a file name from the command line to perform the computation of the same figure of merit on different matrices.
The first new class seen here is LatticeTester::UniformWeights
. This is one of the few classes that inherit from the Weights
class stated before. The base class only specifies an interface and the subclasses LatticeTester::UniformWeights
, LatticeTester::ProductWeights
, LatticeTester::ProjectionDependentWeights
and LatticeTester::PODWeights
are implementations of weighting classes. These classes are classes that can assign different weights to different projections of a lattice when computing a figure of merit. Typically, these weights only have to be multiplied to the value computed for a projection by specifying the projection to the object. In the case of this example, uniform weights of value 1 are used. This multiplies 1 to every figure of merit, which does nothing. But using other more sophisticated weights would only change the construction process for them and not the actual usage.
The next new thing going on is the usage of the ProjectionConstruction
method of the BasisConstruction
class. This method is aptly named, as it simply constructs a projection, specified by the third argument, from the first lattice argument and puts it into the second lattice argument. To use this method, it is recommended to pair it with one of the CoordinateSets
. These class can be modified to generate coordinate subsets from a list of coordinates, generally the lattice coordinates. From instances of these classes, it is possible to obtain an iterator to perform a loop over the coordinates sets as is done in the example.
The last thing going on is the usage of some Normalizer
classes. LatticeTester
contains a few classes implementing a normalizer. They are all subclasses of the Normalizer
class and can all be instanciated as specified in the documentation of that class. To use this class, it suffices to divide the length of the shortest vector in the lattice by the bound in the dimension of that vector obtained with getBound(dim)
. If the normalizer has correctly been instanciated, the obtained number should be a mesure rescalled between 0 and 1.