Design concepts for matrices and lattices in LiDIA
In this paper we present a new template class concept for matrices and lattices. In the design we have focussed on the efficiency of single as well as sequences of operations. In order to get concise and efficient programming code we present a new technique based on template mechanisms and suitable inheritance structures. 1 I N T R O D U C T I O N In many fields in mathematics and computer science, computations on matrices and lattices have various applications, e.g. in class group theory, cryptography, combinatorial optimization and scientific computing. Most of those applications are extremely time consuming and therefore require efficient implementations of the underlying data-types and basic operations. In general, many applications do not call only one but a sequence of lattice and matrix operations. Through the design and the implementation of a new object-oriented concept for matrix and lattice operations in LiDIA 1 [4] we take into account the efficiency of a single algorithm as well as a sequence of different operations. Other computer algebra systems are typically single-algorithmoriented which stands in contrast to our approach. In [iDIA we collect specific information in each step of an operation sequence which is subsequently used in the next step of the on-going computation. In order to achieve ihe maximal efficiency, this concept obviously requires the implementation of several variations of the same algorithm. Using conventional programming methods would result in a large amount of duplicated code. In this paper we present a new concept solving the problem by combining template tL iDIA is a Library for Computa t iona l Number Theory which is being developed by the LiDIA Group at the Ins t i tu te of Prof. Dr. J. Buchmann at the UniversitS.t des Sa.arlandes/TH Darmstad t "'Permission to make digital or hard copies of part or all of this work tbr personal or classroom use is granted without fee provided that copies are not made or distributed tbr profit or commercial advantage and that copies bear this notice ,'rod the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a tee." ¢3 1997 ACM 0-89791-850-9 97 0002 3.50 532 mechanisms with suitable inheritance structures. Our implementation is very efficient (for single algorithms as well as operation sequences), flexible, extendible and results in concise programmlng code which is easy to maintain. In the following we first describe the inheritance structure of the template matrix and lattice classes (section 2.1). Subsequently (section 3), we present a new programmlng technique using so-called template modules and kernels for implementing the classes efficiently. On the basis of running timings (section 4) of LiDIA in comparison with other computer algebra systems we show the efficiency of our new concept. 2 STRUCTURE OF THE MATRIX AND LATTICE CLASSES IN LiDIA In this section we will describe the structure of the matrix and lattice classes of the C + + library [iDIA [4] and present the advantages of our design concept. The basic two concepts are the application of inheritance to template structures and the use of bit fields for coding structure information, storage information and other high level information. By means of the first technique we can support matrices and lattices over different types. In addition, we achieve a gradation of the functions of the classes depending on the operations of the used template type. The second concept allows us to ensure that fast single operations also imply the efficiency of applications calling a sequence of operations. 2.1 Inheritance Structure and Bit Fields The inheritance structure of the template matrix and lattice classes in LiDIA 1.3 is shown in figure 1. The basis of our matrix classes consists of the two classes dense .ma t r ix and spaxse_taatr ix which are invisible for the user. For efficiency reasons, these classes are no virtual base classes [2, 13]. In these classes we define the data structure for sparse and dense matrices (see figure 2) which is explained by some examples in figure 3. As shown in figures 2 and 3 it is possible to create a matrix with dense, sparse or even a mixed representation by combining the dense and sparse data structure elements. Bit fields such as storage.mode, s t r u c t t t r o ~ o d e , £nfo_mode and prLut_mode which are defined in the class sparse_mat r ix store specific matrix information which is extensively used by the derived classes. The bit fields can