1 // -*- C++ -*-
2 //==============================================================================================
3 //
4 //	This file is part of LiDIA --- a library for computational number theory
5 //
6 //	Copyright (c) 1994--2001 the LiDIA Group.  All rights reserved.
7 //
8 //	See http://www.informatik.tu-darmstadt.de/TI/LiDIA/
9 //
10 //----------------------------------------------------------------------------------------------
11 //
12 //	$Id$
13 //
14 //	Author	: Werner Backes (WB), Thorsten Lauer (TL)
15 //	Changes	: See CVS log
16 //
17 //==============================================================================================
18 
19 
20 #ifndef LIDIA_LATTICE_GENSYS_H_GUARD_
21 #define LIDIA_LATTICE_GENSYS_H_GUARD_
22 
23 
24 
25 #ifndef HEADBANGER
26 
27 //
28 // include files needed
29 //
30 
31 
32 
33 #ifndef LIDIA_BI_LATTICE_BASIS_H_GUARD_
34 # include	"LiDIA/lattices/bi_lattice_basis.h"
35 #endif
36 #ifndef LIDIA_BF_LATTICE_BASIS_H_GUARD_
37 # include	"LiDIA/lattices/bf_lattice_basis.h"
38 #endif
39 
40 
41 
42 #ifdef LIDIA_NAMESPACE
43 namespace LiDIA {
44 # define IN_NAMESPACE_LIDIA
45 #endif
46 
47 
48 
49 //
50 // computing mode defines
51 //
52 
53 const sdigit double_mode = 0x00000001; // double = bigfloat
54 const sdigit bigint_mode = 0x00000010;
55 const sdigit bigfloat_mode = 0x00000100;
56 
57 //
58 // IO mode defines
59 //
60 
61 const sdigit own_io_mode = 0x00000001;
62 const sdigit pari_io_mode = 0x00000010;
63 const sdigit maple_io_mode = 0x00000100;
64 const sdigit mathematica_io_mode = 0x00001000;
65 
66 //
67 // Class lattice_gensys
68 //
69 
70 class lattice_gensys
71 {
72 public :
73 	sdigit             		comp_mode;
74 	sdigit             		io_mode;
75 
76 	timer                       CT;
77 
78 	bigint_lattice_basis*	lbi;
79 	bigfloat_lattice_basis*	lbf;
80 
81 public :
82 
83 	//
84 	// Constructors / Destructor
85 	//
86 	lattice_gensys(lidia_size_t, lidia_size_t);
87 	lattice_gensys(lidia_size_t, lidia_size_t, const double**);
88 	lattice_gensys(lidia_size_t, lidia_size_t, const bigint**);
89 	lattice_gensys(lidia_size_t, lidia_size_t, const bigfloat**);
90 	lattice_gensys(const lattice_gensys&);
91 	lattice_gensys(const math_matrix< bigint > &);
92 	lattice_gensys(const math_matrix< bigfloat > &);
93 	virtual ~lattice_gensys();
94 
95 	//
96 	// Input / Output
97 	//
98 	friend std::istream& operator >> (std::istream&, lattice_gensys&);
99 	friend std::ostream& operator << (std::ostream&, const lattice_gensys&);
100 
101 	//
102 	// Assignments
103 	//
104 	lattice_gensys& operator = (const lattice_gensys&);
105 	lattice_gensys& operator = (const math_matrix< bigint > &);
106 	lattice_gensys& operator = (const math_matrix< bigfloat > &);
107 
108 	void assign(const lattice_gensys&);
109 	void assign(const math_matrix< bigint > &);
110 	void assign(const math_matrix< bigfloat > &);
111 
112 	friend void assign(lattice_gensys&, const lattice_gensys&);
113 	friend void assign(lattice_gensys&, const math_matrix< bigint > &);
114 	friend void assign(lattice_gensys&, const math_matrix< bigfloat > &);
115 
116 	//
117 	// Element Operations
118 	//
119 	void member(lidia_size_t, lidia_size_t, double&);
120 	void member(lidia_size_t, lidia_size_t, bigint&);
121 	void member(lidia_size_t, lidia_size_t, bigfloat&);
122 
123 	void sto(lidia_size_t, lidia_size_t, const double&);
124 	void sto(lidia_size_t, lidia_size_t, const bigint&);
125 	void sto(lidia_size_t, lidia_size_t, const bigfloat&);
126 
127 	void member(lidia_size_t&, lidia_size_t&, double**&);
128 	void member(lidia_size_t&, lidia_size_t&, bigint**&);
129 	void member(lidia_size_t&, lidia_size_t&, bigfloat**&);
130 
131 	void member(math_matrix< bigint > &);
132 	void member(math_matrix< bigfloat > &);
133 
134 	void sto(lidia_size_t, lidia_size_t, const double**);
135 	void sto(lidia_size_t, lidia_size_t, const bigint**);
136 	void sto(lidia_size_t, lidia_size_t, const bigfloat**);
137 
138 	lidia_size_t get_no_of_rows();
139 	lidia_size_t get_no_of_columns();
140 
141 	//
142 	// Type Checking
143 	//
144 	bool check_double();
145 	bool check_bigint();
146 
147 	//
148 	// Modes Operations
149 	//
150 	void set_computing_mode(sdigit);
151 	sdigit get_computing_mode();
152 
153 	void set_io_mode(sdigit);
154 	sdigit get_io_mode();
155 
156 	//
157 	// Quality of Reduction
158 	//
set_precision(sdigit)159 	void set_precision(sdigit) { }
get_computed_precision()160 	sdigit get_computed_precision()
161 	{
162 		return 0;
163 	}
get_read_precision()164 	sdigit get_read_precision()
165 	{
166 		return 0;
167 	}
168 
169 	void set_reduction_parameter(double);
170 	void set_reduction_parameter(sdigit, sdigit);
171 	double get_reduction_parameter();
172 	void get_reduction_parameter(sdigit&, sdigit&);
173 
174 	//
175 	// algorithm information
176 	//
177 	sdigit get_no_of_reduction_steps();
178 	sdigit get_no_of_swaps();
179 	sdigit get_no_of_corrections();
180 
181 	//
182 	// Time needed
183 	//
184 	timer& get_computing_time();
185 
186 	//
187 	// Algorithms
188 	//
189 
190 	//
191 	// Buchmann - Kessler
192 	//
193 	void lin_gen_system(lattice_gensys&, lidia_size_t&);
194         friend lattice_gensys lin_gen_system(const lattice_gensys& L,
195 					     lidia_size_t& rank);
196 
197 	void lll_gensys(lidia_size_t&);
198 	void lll_gensys(const lattice_gensys&, lidia_size_t&);
199         friend lattice_gensys lll_gensys(const lattice_gensys& L, lidia_size_t& rank);
200 
201 	void lll_trans_gensys(lattice_gensys&, lidia_size_t&);
202 	friend lattice_gensys lll_trans_gensys(const lattice_gensys& L,
203 					       lattice_gensys& T,
204 					       lidia_size_t& rank);
205 
206 	void mlll(base_vector< bigint > &);
207 	void mlll(const lattice_gensys&, base_vector< bigint > &);
208         friend lattice_gensys mlll(const lattice_gensys& L, base_vector< bigint > & v);
209 
210 	void mlll(bigint*&);
211 	void mlll(const lattice_gensys&, bigint*&);
212         friend lattice_gensys mlll(const lattice_gensys& L, bigint*& v);
213 
214 	void compute_basis(const lattice_gensys&, const lattice_gensys&);
215 
216 	//
217 	// friend functions
218 	//
219 	friend void mlll(math_matrix< bigint > &, const math_matrix< bigint > &, base_vector< bigint > &);
220 	friend void mlll(math_matrix< bigfloat > &, const math_matrix< bigfloat > &, base_vector< bigint > &);
221 	friend void mlll(math_matrix< bigfloat > &, const math_matrix< bigfloat > &, base_vector< bigfloat > &);
222 
223 	friend void mlll(math_matrix< bigint > &, const math_matrix< bigint > &, bigint*&);
224 	friend void mlll(math_matrix< bigfloat > &, const math_matrix< bigfloat > &, bigint*&);
225 	friend void mlll(math_matrix< bigfloat > &, const math_matrix< bigfloat > &, bigfloat*&);
226 
227 	friend void lll_gensys(math_matrix< bigfloat > &, const math_matrix< bigfloat > &, lidia_size_t&);
228 	friend void lll_gensys(math_matrix< bigint > &, const math_matrix< bigint > &, lidia_size_t&);
229 
230 	friend void lll_trans_gensys(math_matrix< bigint > &, math_matrix< bigint > &, lidia_size_t&);
231 	friend void lll_trans_gensys(math_matrix< bigint > &, math_matrix< bigfloat > &, lidia_size_t&);
232 	friend void lll_trans_gensys(math_matrix< bigfloat > &, math_matrix< bigfloat > &, lidia_size_t&);
233 
234 	friend void lin_gen_system(math_matrix< bigint > &, const math_matrix< bigint > &, lidia_size_t&);
235 	friend void lin_gen_system(math_matrix< bigint > &, const math_matrix< bigfloat > &, lidia_size_t&);
236 	friend void lin_gen_system(math_matrix< bigfloat > &, const math_matrix< bigfloat > &, lidia_size_t&);
237 
238 
239 };
240 
241 // friend functions
242 
243 //
244 // Input / Output
245 //
246 std::istream& operator >> (std::istream&, lattice_gensys&);
247 std::ostream& operator << (std::ostream&, const lattice_gensys&);
248 
249 //
250 // Assignments
251 //
252 
253 void assign(lattice_gensys&, const lattice_gensys&);
254 void assign(lattice_gensys&, const math_matrix< bigint > &);
255 void assign(lattice_gensys&, const math_matrix< bigfloat > &);
256 
257 //
258 // Algorithms
259 //
260 
261 //
262 // Buchmann - Kessler
263 //
264 inline
lin_gen_system(const lattice_gensys & L,lidia_size_t & rank)265 lattice_gensys lin_gen_system(const lattice_gensys& L,
266 			      lidia_size_t& rank) {
267     lattice_gensys LL(L);
268     lattice_gensys T(1, 1);
269     LL.lin_gen_system(T, rank);
270     return(T);
271 }
272 
273 inline
lll_gensys(const lattice_gensys & L,lidia_size_t & rank)274 lattice_gensys lll_gensys(const lattice_gensys& L, lidia_size_t& rank) {
275     lattice_gensys TL(L);
276     TL.lll_gensys(rank);
277     return (TL);
278 }
279 
280 inline
lll_trans_gensys(const lattice_gensys & L,lattice_gensys & T,lidia_size_t & rank)281 lattice_gensys lll_trans_gensys(const lattice_gensys& L,
282 				lattice_gensys& T,
283 				lidia_size_t& rank) {
284     lattice_gensys LT(L);
285     LT.lll_gensys(T, rank);
286     return (LT);
287 }
288 
289 inline
mlll(const lattice_gensys & L,base_vector<bigint> & v)290 lattice_gensys mlll(const lattice_gensys& L,
291 		    base_vector< bigint > & v) {
292     lattice_gensys TL(L);
293     TL.mlll(v);
294     return(TL);
295 }
296 
297 inline
mlll(const lattice_gensys & L,bigint * & v)298 lattice_gensys mlll(const lattice_gensys& L, bigint*& v) {
299     lattice_gensys TL(L);
300     TL.mlll(v);
301     return(TL);
302 }
303 
304 void mlll(math_matrix< bigint > &, const math_matrix< bigint > &,
305 	  base_vector< bigint > &);
306 void mlll(math_matrix< bigfloat > &, const math_matrix< bigfloat > &,
307 	  base_vector< bigint > &);
308 void mlll(math_matrix< bigfloat > &, const math_matrix< bigfloat > &,
309 	  base_vector< bigfloat > &);
310 void mlll(math_matrix< bigint > &, const math_matrix< bigint > &,
311 	  bigint*&);
312 void mlll(math_matrix< bigfloat > &, const math_matrix< bigfloat > &,
313 	  bigint*&);
314 void mlll(math_matrix< bigfloat > &, const math_matrix< bigfloat > &,
315 	  bigfloat*&);
316 
317 void lll_gensys(math_matrix< bigfloat > &,
318 		const math_matrix< bigfloat > &, lidia_size_t&);
319 void lll_gensys(math_matrix< bigint > &, const math_matrix< bigint > &,
320 		lidia_size_t&);
321 
322 void lll_trans_gensys(math_matrix< bigint > &, math_matrix< bigint > &,
323 		      lidia_size_t&);
324 void lll_trans_gensys(math_matrix< bigint > &,
325 		      math_matrix< bigfloat > &, lidia_size_t&);
326 void lll_trans_gensys(math_matrix< bigfloat > &,
327 		      math_matrix< bigfloat > &, lidia_size_t&);
328 
329 void lin_gen_system(math_matrix< bigint > &,
330 		    const math_matrix< bigint > &, lidia_size_t&);
331 void lin_gen_system(math_matrix< bigint > &,
332 		    const math_matrix< bigfloat > &, lidia_size_t&);
333 void lin_gen_system(math_matrix< bigfloat > &,
334 		    const math_matrix< bigfloat > &, lidia_size_t&);
335 
336 
337 #endif  // HEADBANGER
338 
339 
340 
341 #ifdef LIDIA_NAMESPACE
342 }	// end of namespace LiDIA
343 # undef IN_NAMESPACE_LIDIA
344 #endif
345 
346 
347 
348 #endif	// LIDIA_LATTICE_GENSYS_H_GUARD_
349