bkz.h
Go to the documentation of this file.
1/* Copyright (C) 2011 Xavier Pujol
2 (C) 2014-2016 Martin R. Albrecht
3 (C) 2016 Michael Walter
4
5 This file is part of fplll. fplll is free software: you
6 can redistribute it and/or modify it under the terms of the GNU Lesser
7 General Public License as published by the Free Software Foundation,
8 either version 2.1 of the License, or (at your option) any later version.
9
10 fplll is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with fplll. If not, see <http://www.gnu.org/licenses/>. */
17
18#ifndef FPLLL_BKZ_H
19#define FPLLL_BKZ_H
20
21#include "bkz_param.h"
22#include "enum/enumerate.h"
23#include "enum/evaluator.h"
24#include "lll.h"
25
27
33template <class ZT, class FT> class BKZAutoAbort
34{
35public:
46 BKZAutoAbort(MatGSOInterface<ZT, FT> &m, int num_rows, int start_row = 0)
47 : m(m), old_slope(numeric_limits<double>::max()), no_dec(-1), num_rows(num_rows),
48 start_row(start_row)
49 {
50 }
51
70 bool test_abort(double scale = 1.0, int maxNoDec = 5);
71
72private:
74 double old_slope;
75 int no_dec;
76 int num_rows;
77 int start_row;
78};
79
87template <class ZT, class FT> class BKZReduction
88{
99public:
102
118 bool svp_preprocessing(int kappa, unsigned int block_size, const BKZParam &param);
119
141 bool svp_postprocessing(int kappa, int block_size, const vector<FT> &solution, bool dual = false);
142
164 bool svp_reduction(int kappa, int block_size, const BKZParam &param, bool dual = false);
165
185 bool tour(const int loop, int &kappa_max, const BKZParam &param, int min_row, int max_row);
186
204 bool sd_tour(const int loop, const BKZParam &param, int min_row, int max_row);
205
223 bool hkz(int &kappa_max, const BKZParam &param, int min_row, int max_row);
224
243 bool slide_tour(const int loop, const BKZParam &param, int min_row, int max_row);
244
255 bool bkz();
256
271 void rerandomize_block(int min_row, int max_row, int density);
272
287 void dump_gso(const std::string &filename, bool append, const std::string &step, const int loop,
288 const double time);
289
294
298 long nodes;
299
300private:
301 void print_tour(const int loop, int min_row, int max_row);
302 void print_params(const BKZParam &param, ostream &out);
303
304 bool set_status(int new_status);
305
306 const PruningParams &get_pruning(int kappa, unsigned int block_size, const BKZParam &par) const;
307
308 // handles the general case of inserting a vector into the (dual) basis, i.e.
309 // when none of the coefficients are \pm 1
310 bool svp_postprocessing_generic(int kappa, int block_size, const vector<FT> &solution,
311 bool dual = false);
312 // a truncated tour: svp reducing from min_row to max_row without decreasing the window
313 // size (simply returns when the last block is reduced)
314 bool trunc_tour(int &kappa_max, const BKZParam &param, int min_row, int max_row);
315 // a truncated dual tour: dual svp reducing from max_row to min_row without decreasing
316 // the window size (simply returns when the first block is reduced)
317 bool trunc_dtour(const BKZParam &param, int min_row, int max_row);
318
319 const BKZParam &param;
320 int num_rows;
322 LLLReduction<ZT, FT> &lll_obj;
323 // evaluator passed to the enumeration object to handle solutions found
324 FastEvaluator<FT> evaluator;
325 // slack variable for svp reductions
326 FT delta;
327
328 // an acronym for the type of block reduction used, for reporting purposes
329 const char *algorithm;
330 // current value of the potential function as defined in the slide reduction paper
331 // used to reliably determine terminating condition during slide reduction
332 FT sld_potential;
333
334 // Temporary data
335 const vector<FT> empty_target, empty_sub_tree;
336 FT max_dist, delta_max_dist;
337 double cputime_start;
338};
339
357int bkz_reduction(ZZ_mat<mpz_t> *B, ZZ_mat<mpz_t> *U, const BKZParam &param,
358 FloatType float_type = FT_DEFAULT, int precision = 0);
359
380int bkz_reduction(ZZ_mat<mpz_t> &b, int block_size, int flags = BKZ_DEFAULT,
381 FloatType float_type = FT_DEFAULT, int precision = 0);
382
405int bkz_reduction(ZZ_mat<mpz_t> &b, ZZ_mat<mpz_t> &u, int block_size, int flags = BKZ_DEFAULT,
406 FloatType float_type = FT_DEFAULT, int precision = 0);
407
427 int precision = 0);
428
430
431#endif
int bkz_reduction(ZZ_mat< mpz_t > *B, ZZ_mat< mpz_t > *U, const BKZParam &param, FloatType float_type=FT_DEFAULT, int precision=0)
Performs block reduction using BKZParam object.
Definition: bkz.cpp:851
int hkz_reduction(ZZ_mat< mpz_t > &b, int flags=HKZ_DEFAULT, FloatType float_type=FT_DEFAULT, int precision=0)
Performs HKZ reduction.
Definition: bkz.cpp:948
Performs a heuristic check if BKZ can be terminated.
Definition: bkz.h:34
bool test_abort(double scale=1.0, int maxNoDec=5)
Performs the check.
Definition: bkz.cpp:800
BKZAutoAbort(MatGSOInterface< ZT, FT > &m, int num_rows, int start_row=0)
Create an BKZAutoAbort object.
Definition: bkz.h:46
Definition: bkz_param.h:69
The class performing block reduction.
Definition: bkz.h:88
bool bkz()
Runs the main loop of block reduction.
Definition: bkz.cpp:522
long nodes
Definition: bkz.h:298
bool svp_preprocessing(int kappa, unsigned int block_size, const BKZParam &param)
Preprocesses a block.
Definition: bkz.cpp:101
void rerandomize_block(int min_row, int max_row, int density)
Definition: bkz.cpp:44
bool sd_tour(const int loop, const BKZParam &param, int min_row, int max_row)
Runs a SD-BKZ tour.
Definition: bkz.cpp:444
int status
Definition: bkz.h:293
bool hkz(int &kappa_max, const BKZParam &param, int min_row, int max_row)
HKZ reduces a block.
Definition: bkz.cpp:420
BKZReduction(MatGSOInterface< ZT, FT > &m, LLLReduction< ZT, FT > &lll_obj, const BKZParam &param)
Create a BKZObject.
Definition: bkz.cpp:30
void dump_gso(const std::string &filename, bool append, const std::string &step, const int loop, const double time)
Dumps the shape of the basis.
Definition: bkz.cpp:729
bool svp_reduction(int kappa, int block_size, const BKZParam &param, bool dual=false)
(d)SVP-reduce a block.
Definition: bkz.cpp:275
bool svp_postprocessing(int kappa, int block_size, const vector< FT > &solution, bool dual=false)
Inserts given (dual) vector into the basis.
Definition: bkz.cpp:129
~BKZReduction()
Definition: bkz.cpp:41
bool tour(const int loop, int &kappa_max, const BKZParam &param, int min_row, int max_row)
Runs a BKZ tour.
Definition: bkz.cpp:361
bool slide_tour(const int loop, const BKZParam &param, int min_row, int max_row)
Runs a tour of slide reduction.
Definition: bkz.cpp:466
Definition: evaluator.h:165
Definition: lll.h:30
Definition: gso_interface.h:60
Definition: pruner.h:32
@ BKZ_DEFAULT
Definition: defs.h:264
#define FPLLL_END_NAMESPACE
Definition: defs.h:117
FloatType
Definition: defs.h:210
@ FT_DEFAULT
Definition: defs.h:211
@ HKZ_DEFAULT
Definition: defs.h:279
#define FPLLL_BEGIN_NAMESPACE
Definition: defs.h:114
fplll_extenum_enumf std::function< extenum_cb_set_config > std::function< extenum_cb_process_sol > std::function< extenum_cb_process_subsol > bool dual
Definition: enumerate_ext_api.h:91
fplll_float float_type
Definition: enumeration.h:61