lll.h
Go to the documentation of this file.
1/* Copyright (C) 2005-2008 Damien Stehle.
2 Copyright (C) 2007 David Cade.
3 Copyright (C) 2011 Xavier Pujol.
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_LLL_H
19#define FPLLL_LLL_H
20
21#include "gso.h"
22#include "gso_interface.h"
23
25
26/* The precision of FT must be defined before creating an instance of
27 LLLReduction. The matrix b can be modified between each call to lll. */
28
29template <class ZT, class FT> class LLLReduction
30{
31public:
38 LLLReduction(MatGSOInterface<ZT, FT> &m, double delta, double eta, int flags);
39#ifdef FPLLL_WITH_LONG_DOUBLE
40 ~LLLReduction() { LDConvHelper::free(); }
41#endif
52 bool lll(int kappa_min = 0, int kappa_start = 0, int kappa_end = -1,
53 int size_reduction_start = 0);
54
66 inline bool size_reduction(int kappa_min = 0, int kappa_end = -1, int size_reduction_start = 0);
67
68 int status;
71 int zeros;
73
74private:
84 bool babai(int kappa, int size_reduction_end, int size_reduction_start = 0);
85 inline bool early_reduction(int start, int size_reduction_start = 0);
86 inline void print_params();
87 inline bool set_status(int new_status);
88
90 FT delta, eta, swap_threshold;
91
92 bool enable_early_red;
93 bool siegel;
94 bool verbose;
95
96 vector<FT> lovasz_tests;
97 vector<FT> babai_mu;
98 vector<long> babai_expo;
99 ZT ztmp1;
100 FT mu_m_ant, ftmp1;
101};
102
103template <class ZT, class FT>
104bool is_lll_reduced(MatGSOInterface<ZT, FT> &m, double delta, double eta);
105
106template <class ZT, class FT>
107inline bool LLLReduction<ZT, FT>::size_reduction(int kappa_min, int kappa_end,
108 int size_reduction_start)
109{
110 if (kappa_end == -1)
111 kappa_end = m.d;
112
113 extend_vect(babai_mu, kappa_end);
114 extend_vect(babai_expo, kappa_end);
115
116 for (int k = kappa_min; k < kappa_end; k++)
117 {
118 if ((k > 0 && !babai(k, k, size_reduction_start)) || !m.update_gso_row(k))
119 return false;
120 }
121 return set_status(RED_SUCCESS);
122}
123
124template <class ZT, class FT>
125inline bool LLLReduction<ZT, FT>::early_reduction(int start, int size_reduction_start)
126{
127 m.lock_cols();
128 if (verbose)
129 {
130 cerr << "Early reduction start=" << start + 1 << endl;
131 }
132 for (int i = start; i < m.d; i++)
133 {
134 if (!babai(i, start, size_reduction_start))
135 return false;
136 }
137 m.unlock_cols();
138 last_early_red = start;
139 return true;
140}
141
142template <class ZT, class FT> inline void LLLReduction<ZT, FT>::print_params()
143{
144 cerr << "Entering LLL"
145 << "\ndelta = " << delta << "\neta = " << eta << "\nprecision = " << FT::get_prec()
146 << "\nexact_dot_product = " << static_cast<int>(m.enable_int_gram)
147 << "\nrow_expo = " << static_cast<int>(m.enable_row_expo)
148 << "\nearly_red = " << static_cast<int>(enable_early_red)
149 << "\nsiegel_cond = " << static_cast<int>(siegel)
150 << "\nlong_in_babai = " << static_cast<int>(m.row_op_force_long) << endl;
151}
152
153template <class ZT, class FT> inline bool LLLReduction<ZT, FT>::set_status(int new_status)
154{
155 status = new_status;
156 if (verbose)
157 {
158 if (status == RED_SUCCESS)
159 {
160 cerr << "End of LLL: success" << endl;
161 }
162 else
163 {
164 cerr << "End of LLL: failure: " << RED_STATUS_STR[status] << endl;
165 cerr << RED_STATUS_STR[RedStatus::RED_URL_ERR] << endl;
166 }
167 }
168 return status == RED_SUCCESS;
169}
170
172
173#endif
Definition: lll.h:30
int status
Definition: lll.h:68
int final_kappa
Definition: lll.h:69
int n_swaps
Definition: lll.h:72
bool size_reduction(int kappa_min=0, int kappa_end=-1, int size_reduction_start=0)
Size reduction.
Definition: lll.h:107
LLLReduction(MatGSOInterface< ZT, FT > &m, double delta, double eta, int flags)
Definition: lll.cpp:28
~LLLReduction()
Definition: lll.h:40
int zeros
Definition: lll.h:71
int last_early_red
Definition: lll.h:70
bool lll(int kappa_min=0, int kappa_start=0, int kappa_end=-1, int size_reduction_start=0)
LLL reduction.
Definition: lll.cpp:45
Definition: gso_interface.h:60
const char *const RED_STATUS_STR[RED_STATUS_MAX]
Definition: defs.h:171
@ RED_URL_ERR
Definition: defs.h:167
@ RED_SUCCESS
Definition: defs.h:155
#define FPLLL_END_NAMESPACE
Definition: defs.h:117
#define FPLLL_BEGIN_NAMESPACE
Definition: defs.h:114
bool is_lll_reduced(MatGSOInterface< ZT, FT > &m, double delta, double eta)
Definition: lll.cpp:227
FPLLL_BEGIN_NAMESPACE void extend_vect(vector< T > &v, int size)
Definition: numvect.h:25
static void babai(const FP_mat< mpfr_t > &matrix, const Matrix< FP_NR< mpfr_t > > &mu, const Matrix< FP_NR< mpfr_t > > &r, const vector< FP_NR< mpfr_t > > &target, vector< FP_NR< mpfr_t > > &target_coord)
Definition: svpcvp.cpp:517