hlll.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 Copyright (C) 2017-1018 Laurent Grémy.
5
6 This file is part of fplll. fplll is free software: you
7 can redistribute it and/or modify it under the terms of the GNU Lesser
8 General Public License as published by the Free Software Foundation,
9 either version 2.1 of the License, or (at your option) any later version.
10
11 fplll is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with fplll. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef FPLLL_HLLL_H
20#define FPLLL_HLLL_H
21
22#include "householder.h"
23#include <cmath>
24
26
27template <class ZT, class FT> class HLLLReduction
28{
29public:
36 HLLLReduction(MatHouseholder<ZT, FT> &arg_m, double delta, double eta, double theta, double c,
37 int flags)
38 : m(arg_m)
39 {
40 this->delta = delta;
41 this->eta = eta;
42 this->theta = theta;
43 this->c = c;
44 sr = pow(2.0, -(double)m.get_d() * c);
45 verbose = flags & LLL_VERBOSE;
46 dR.resize(m.get_d());
47 eR.resize(m.get_d());
48 status = -1;
49 }
50
54 bool hlll();
55
56 // Get the status of the computation
57 inline int get_status() { return status; }
58
59private:
60 // Paramters to (delta, eta, theta) hlll-reduce the basis b in m.
61 FT delta, eta, theta;
63
64 // Arbitraty c > 0
65 FT c;
66 // Multiplicative coefficient used to check if a vector is size-reduced or not.
67 FT sr;
68 // Verbose mode.
69 bool verbose;
70
71 // Temporary variables
72 FT ftmp0, ftmp1, ftmp2;
73 long expo0, expo1, expo2;
74
75 int status;
76
85 void size_reduction(int kappa, int size_reduction_end, int size_reduction_start = 0);
86
90 inline void print_params();
91
92 // Precompute dR[k] * 2^(2*row_expo[k]) = delta_ * R(k, k)^2
93 vector<FT> dR;
94
95 // Compute dR[k]
96 inline void compute_dR(int k);
97
98 // Set the status of the computation and print message if verbose
99 inline bool set_status(int new_status);
100
101 // Precompute eR[k] * 2^row_expo[k] = eta * R(k, k)
102 vector<FT> eR;
103
104 // Compute eR[k]
105 inline void compute_eR(int k);
106
107 // Verify if b[k] is is correctry size reduced
108 bool verify_size_reduction(int kappa);
109
110 // Test if delta * R(k - 1, k - 1)^2 <= ||b[k]||^2 - sum_{i = 0}^{i < k - 1}R[k][i]^2 (depending
111 // on the way ftmp1 is computed, this test can be slightly different, but the purpose keeps the
112 // same)
113 bool lovasz_test(int k);
114};
115
116template <class ZT, class FT> inline void HLLLReduction<ZT, FT>::print_params()
117{
118 cerr << "Entering HLLL" << endl
119 << "delta = " << delta << endl
120 << "eta = " << eta << endl
121 << "theta = " << theta << endl
122 << "c = " << c << endl
123 << "precision = " << FT::get_prec() << endl
124 << "row_expo = " << static_cast<int>(m.is_enable_row_expo()) << endl
125 << "long_in_size_reduction = " << static_cast<int>(m.is_row_op_force_long()) << endl;
126
127#ifndef HOUSEHOLDER_PRECOMPUTE_INVERSE
128 cerr << "householder_precompute_inverse = 0" << endl;
129#else // HOUSEHOLDER_PRECOMPUTE_INVERSE
130 cerr << "householder_precompute_inverse = 1" << endl;
131#endif // HOUSEHOLDER_PRECOMPUTE_INVERSE
132
133#ifndef HOUSEHOLDER_USE_SIZE_REDUCTION_TEST
134 // Condition to break incomplete size reduction: ||b[k]||^2 > 0.1 * t
135 cerr << "householder_use_size_reduction_test = 0" << endl;
136#else // HOUSEHOLDER_USE_SIZE_REDUCTION_TEST
137 // Condition to break incomplete size reduction: ||b[k]||^2 > sr * t
138 cerr << "householder_use_size_reduction_test = 1" << endl;
139#endif // HOUSEHOLDER_USE_SIZE_REDUCTION_TEST
140
141#ifndef HOUSEHOLDER_VERIFY_SIZE_REDUCTION_HPLLL
142 cerr << "householder_verify_size_reduction_hplll = 0" << endl;
143#else // HOUSEHOLDER_VERIFY_SIZE_REDUCTION_HPLLL
144 cerr << "householder_verify_size_reduction_hplll = 1" << endl;
145#endif // HOUSEHOLDER_VERIFY_SIZE_REDUCTION_HPLLL
146}
147
148template <class ZT, class FT> inline void HLLLReduction<ZT, FT>::compute_dR(int k)
149{
150 m.get_R(dR[k], k, k);
151 dR[k].mul(dR[k], dR[k]);
152 dR[k].mul(delta, dR[k]); // dR[k] = delta * R(k, k)^2
153}
154
155template <class ZT, class FT> inline void HLLLReduction<ZT, FT>::compute_eR(int k)
156{
157 m.get_R(eR[k], k, k);
158 eR[k].mul(delta, eR[k]); // eR[k] = eta * R(k, k)
159}
160
161template <class ZT, class FT> inline bool HLLLReduction<ZT, FT>::set_status(int new_status)
162{
163 status = new_status;
164 if (verbose)
165 {
166 if (status == RED_SUCCESS)
167 {
168 cerr << "End of HLLL: success" << endl;
169 }
170 else
171 {
172 cerr << "End of HLLL: failure: " << RED_STATUS_STR[status] << endl;
173 cerr << RED_STATUS_STR[RedStatus::RED_URL_ERR] << endl;
174 }
175 }
176 return status == RED_SUCCESS;
177}
178
179template <class ZT, class FT>
180int is_hlll_reduced(MatHouseholder<ZT, FT> &m, double delta, double eta, double theta);
181
183
184#endif /* FPLLL_HLLL_H */
Definition: hlll.h:28
bool hlll()
Househorder inside LLL reduction.
Definition: hlll.cpp:26
int get_status()
Definition: hlll.h:57
HLLLReduction(MatHouseholder< ZT, FT > &arg_m, double delta, double eta, double theta, double c, int flags)
Definition: hlll.h:36
Definition: householder.h:39
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
@ LLL_VERBOSE
Definition: defs.h:224
int is_hlll_reduced(MatHouseholder< ZT, FT > &m, double delta, double eta, double theta)
Definition: hlll.cpp:507