wrapper.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_WRAPPER_H
19#define FPLLL_WRAPPER_H
20
21#include "nr/matrix.h"
22
24
25/* The matrix b must not be modified before calling lll().
26 lll() must be called only once. */
27
51{
52public:
53 /* u must be either empty or the identity matrix */
54 Wrapper(ZZ_mat<mpz_t> &b, ZZ_mat<mpz_t> &u, ZZ_mat<mpz_t> &u_inv, double delta, double eta,
55 int flags);
56
57 // Used for HLLL
58 Wrapper(ZZ_mat<mpz_t> &b, ZZ_mat<mpz_t> &u, ZZ_mat<mpz_t> &u_inv, double delta, double eta,
59 double theta, double c, int flags);
60
61 bool lll();
62
63 // Call HLLL on the wrapper object
64 // TODO: this wrapper does not offers as many options as the one of LLL (for example, use long
65 // instead of mpz_t, modify delta, ...)
66 bool hlll();
67
68 int status;
69
70private:
73 ZZ_mat<mpz_t> &u_inv;
74
75#ifdef FPLLL_WITH_ZLONG
76 ZZ_mat<long> b_long;
77 ZZ_mat<long> u_long; // Always empty
78 ZZ_mat<long> u_inv_long; // Always empty
79#endif
80
81 double delta;
82 double eta;
83 int good_prec;
84 bool use_long;
85 int flags;
86
87 bool little(int kappa, int precision);
88
89 template <class Z, class F>
90 int call_lll(ZZ_mat<Z> &bz, ZZ_mat<Z> &uz, ZZ_mat<Z> &u_inv_z, LLLMethod method, int precision,
91 double delta, double eta);
92
93 template <class F> int fast_lll(double delta, double eta);
94
95 template <class Z, class F>
96 int heuristic_lll(ZZ_mat<Z> &bz, ZZ_mat<Z> &uz, ZZ_mat<Z> &u_inv_z, int precision, double delta,
97 double eta);
98
99 template <class Z, class F>
100 int proved_lll(ZZ_mat<Z> &bz, ZZ_mat<Z> &uz, ZZ_mat<Z> &u_inv_z, int precision, double delta,
101 double eta);
102
103 int heuristic_loop(int precision);
104 int proved_loop(int precision);
105 int last_lll();
106
107 void set_use_long(bool value);
108 int increase_prec(int precision);
109
110 int max_exponent;
111 int n;
112 int d;
113 int last_early_red;
114
115 // For HLLL
116 double theta;
117 double c;
118
119 // High level function, select depending on method and precision the best way to call
120 // HLLL (types, flags enabled, ...)
121 template <class F> bool call_hlll(LLLMethod method, int precision);
122
123 // = call_hlll(LM_FAST, 0);
124 template <class F> bool fast_hlll();
125
126 // = call_hlll(LM_PROVED, precision);
127 template <class F> bool proved_hlll(int precision);
128
129 // Perform proved_hlll until grood_prec is reached or the lattice is reduced
130 int hlll_proved_loop(int precision);
131
132 // Perform proved version of HLLL with good_prec
133 bool last_hlll();
134};
135
136#define FPLLL_DECLARE_LLL(T) \
137 int lll_reduction(ZZ_mat<T> &b, double delta = LLL_DEF_DELTA, double eta = LLL_DEF_ETA, \
138 LLLMethod method = LM_WRAPPER, FloatType floatType = FT_DEFAULT, \
139 int precision = 0, int flags = LLL_DEFAULT); \
140 \
141 int lll_reduction(ZZ_mat<T> &b, ZZ_mat<T> &u, double delta = LLL_DEF_DELTA, \
142 double eta = LLL_DEF_ETA, LLLMethod method = LM_WRAPPER, \
143 FloatType floatType = FT_DEFAULT, int precision = 0, int flags = LLL_DEFAULT); \
144 \
145 int lll_reduction(ZZ_mat<T> &b, ZZ_mat<T> &u, ZZ_mat<T> &u_inv, double delta = LLL_DEF_DELTA, \
146 double eta = LLL_DEF_ETA, LLLMethod method = LM_WRAPPER, \
147 FloatType floatType = FT_DEFAULT, int precision = 0, int flags = LLL_DEFAULT);
148
150
151#ifdef FPLLL_WITH_ZLONG
153#endif
154
155#ifdef FPLLL_WITH_ZDOUBLE
156FPLLL_DECLARE_LLL(double)
157#endif
158
159// HLLL
160
165#define FPLLL_DECLARE_HLLL(T) \
166 int hlll_reduction(ZZ_mat<T> &b, double delta = LLL_DEF_DELTA, double eta = LLL_DEF_ETA, \
167 double theta = HLLL_DEF_THETA, double c = HLLL_DEF_C, \
168 LLLMethod method = LM_WRAPPER, FloatType float_type = FT_DEFAULT, \
169 int precision = 0, int flags = LLL_DEFAULT, bool nolll = false); \
170 int hlll_reduction(ZZ_mat<T> &b, ZZ_mat<T> &u, double delta = LLL_DEF_DELTA, \
171 double eta = LLL_DEF_ETA, double theta = HLLL_DEF_THETA, \
172 double c = HLLL_DEF_C, LLLMethod method = LM_WRAPPER, \
173 FloatType float_type = FT_DEFAULT, int precision = 0, \
174 int flags = LLL_DEFAULT, bool nolll = false); \
175 int hlll_reduction(ZZ_mat<T> &b, ZZ_mat<T> &u, ZZ_mat<T> &u_inv, double delta = LLL_DEF_DELTA, \
176 double eta = LLL_DEF_ETA, double theta = HLLL_DEF_THETA, \
177 double c = HLLL_DEF_C, LLLMethod method = LM_WRAPPER, \
178 FloatType float_type = FT_DEFAULT, int precision = 0, \
179 int flags = LLL_DEFAULT, bool nolll = false);
180
182
183#ifdef FPLLL_WITH_ZLONG
185#endif
186
187#ifdef FPLLL_WITH_ZDOUBLE
188FPLLL_DECLARE_HLLL(double)
189#endif
190
192
193#endif
Wrapper. This class provides an externally callable API for LLL reducing some basis b....
Definition: wrapper.h:51
bool hlll()
Definition: wrapper.cpp:478
bool lll()
Definition: wrapper.cpp:281
int status
Definition: wrapper.h:68
Wrapper(ZZ_mat< mpz_t > &b, ZZ_mat< mpz_t > &u, ZZ_mat< mpz_t > &u_inv, double delta, double eta, int flags)
Definition: wrapper.cpp:45
LLLMethod
Definition: defs.h:187
#define FPLLL_END_NAMESPACE
Definition: defs.h:117
#define FPLLL_BEGIN_NAMESPACE
Definition: defs.h:114
#define FPLLL_DECLARE_HLLL(T)
Definition: wrapper.h:165
#define FPLLL_DECLARE_LLL(T)
Definition: wrapper.h:136