defs.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) 2013 Damien Stehle
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_DEFS_H
20#define FPLLL_DEFS_H
21
22#ifndef __CYGWIN__
23#define FPLLL_WITH_LONG_DOUBLE
24#endif
25
26#define FPLLL_WITH_DPE
27#define FPLLL_WITH_ZDOUBLE
28#define FPLLL_WITH_ZLONG
29#define FPLLL_WITH_GETRUSAGE
30
31#include <algorithm>
32#include <climits>
33#include <cmath>
34#include <cstddef>
35#include <cstdio>
36#include <cstdlib>
37#include <cstring>
38#include <ctime>
39#include <fstream>
40#include <iostream>
41#include <limits>
42#include <sstream>
43#include <stdexcept>
44#include <string>
45
46#ifdef FPLLL_WITH_GETRUSAGE
47#include <sys/resource.h>
48#include <sys/time.h>
49#include <unistd.h>
50#endif
51
52#include "fplll_config.h"
53#ifdef HAVE_LIBMPIR
54#include <mpir.h>
55#endif
56#ifdef HAVE_LIBGMP
57#include <gmp.h>
58#endif
59#include <mpfr.h>
60#ifdef FPLLL_WITH_DPE
61#include "nr/dpe.h"
62#endif
63
64#if defined(__sun) || defined(__CYGWIN__)
65#include <ieeefp.h>
66extern "C" long double ldexpl(long double x, int exp);
67#ifndef NAN
68#define NAN __builtin_nanf("")
69#endif
70#endif
71
72#define FPLLL_INFO(x) \
73 { \
74 cerr << x << endl; \
75 }
76#define FPLLL_ABORT(x) \
77 { \
78 cerr << "fplll: " << x << endl; \
79 abort(); \
80 }
81#define FPLLL_CHECK(x, y) \
82 { \
83 if (!(x)) \
84 FPLLL_ABORT(y); \
85 }
86
87#ifdef DEBUG
88#include <cassert>
89extern int debug_depth;
90#define FPLLL_TRACE(x) std::cerr << "TRACE: " << std::string(debug_depth * 2, ' ') << x << std::endl
91struct DebugTracer
92{
93 DebugTracer(const char *f) : f(f) { debug_depth++; }
94 ~DebugTracer()
95 {
96 debug_depth--;
97 FPLLL_TRACE("</" << f << ">");
98 }
99 std::string f;
100};
101#define FPLLL_DEBUG_ABORT(x) FPLLL_ABORT(x)
102#define FPLLL_DEBUG_CHECK(x) assert(x);
103#define FPLLL_TRACE_IN(x) \
104 FPLLL_TRACE("<" << __func__ << " " << x << ">"); \
105 DebugTracer debugTracer(__func__);
106#define FPLLL_DEBUG_SAFEVECT
107#else
108#define FPLLL_DEBUG_ABORT(x)
109#define FPLLL_DEBUG_CHECK(x)
110#define FPLLL_TRACE(x)
111#define FPLLL_TRACE_IN(x)
112#endif
113
114#define FPLLL_BEGIN_NAMESPACE \
115 namespace fplll \
116 {
117#define FPLLL_END_NAMESPACE }
118
122
123using namespace std;
124
125/* this trick will not work on 16-bit machines*/
126#if (LONG_MAX == 2147483647L)
127const int CPU_SIZE = 32;
128const int CPU_SIZE_1 = 30;
129const double MAX_LONG_FAST = 0x1p30;
130const long int EXPO_MAX = 30;
131#else
132const int CPU_SIZE = 64;
133const int CPU_SIZE_1 = 53;
134const double MAX_LONG_FAST = 0x1p53;
135const long int EXPO_MAX = 53;
136#endif
137
138const int MAX_EXP_DOUBLE = 1000;
139const int PREC_DOUBLE = 53;
140const int PREC_DD = 106;
141const int PREC_QD = 212;
142
143const double LLL_DEF_DELTA = 0.99;
144const double LLL_DEF_ETA = 0.51;
145const double LLL_DEF_EPSILON = 0.01;
147
148// Constraint: 1/2 < eta - theta
149const double HLLL_DEF_THETA = 0.001;
150// Constant for the size reduction.
151const double HLLL_DEF_C = 0.1;
152
154{
156 // Skips value 1
168 RED_STATUS_MAX = 13
170
171const char *const RED_STATUS_STR[RED_STATUS_MAX] = {
172 "success",
173 "",
174 "infinite number in GSO",
175 "infinite loop in babai",
176 "infinite loop in LLL",
177 "error in SVP solver",
178 "error in BKZ",
179 "time limit exceeded in BKZ",
180 "loops limit exceeded in BKZ",
181 "error in HLLL",
182 "increase of the norm",
183 "error in weak size reduction",
184 "Please see https://github.com/fplll/fplll/wiki/fplll-errors-FAQ for more information."};
185
187{
191 LM_FAST = 3
193
194const char *const LLL_METHOD_STR[6] = {"wrapper", "proved", "heuristic", "fast"};
195
196// LM_HEURISTIC is not (yet) an option for HLLL and cannot be called from the fplll binary, then
197// we leave empty the third string.
198const char *const HLLL_METHOD_STR[4] = {"wrapper", "proved", "", "fast"};
199
201{
204 ZT_DOUBLE = 2
206
207const char *const INT_TYPE_STR[5] = {"mpz", "long", "double"};
208
210{
215 FT_DD = 4,
216 FT_QD = 5,
217 FT_MPFR = 6
219
220const char *const FLOAT_TYPE_STR[7] = {"", "double", "long double", "dpe", "dd", "qd", "mpfr"};
221
223{
227 LLL_DEFAULT = 0
229
231{
233 SVPM_PROVED = 2
235
237{
239 CVPM_PROVED = 2
241
243{
247 SVP_DUAL = 4
249
251{
255
256const double BKZ_DEF_AUTO_ABORT_SCALE = 1.0;
258const double BKZ_DEF_GH_FACTOR = 1.1;
261
263{
274 BKZ_SLD_RED = 0x200
276
278{
280 HKZ_VERBOSE = 1
282
283#ifndef FPLLL_DEFAULT_STRATEGY_PATH
284#define FPLLL_DEFAULT_STRATEGY_PATH ""
285#endif
286
287#ifndef FPLLL_DEFAULT_STRATEGY
288#define FPLLL_DEFAULT_STRATEGY ""
289#endif
290
292{
296
298{
299 PRUNER_CVP =
300 0x1, // Do not Halve the count of nodes, according to enumeration optimization from symmetry
301 // Descent methods. If several activated, pruner will execute them in the order below.
303 PRUNER_GRADIENT = 0x4, // Activate the gradient descent
305 // Verbosity
307 // Optimize w.r.t to half of the coefficients (those of even indices)
308 // (by default this is not enabled)
310 // Optimize goal set to single enumeration cost while fixing the probability ~ target. Note that
311 // flags PRUNER_HALF and PRUNER_SINGLE are mutually exclusive.
312 PRUNER_SINGLE = 0x40
314
315#define PRUNER_ZEALOUS (PRUNER_GRADIENT | PRUNER_NELDER_MEAD)
316
318
319#endif
const int MAX_EXP_DOUBLE
Definition: defs.h:138
const char *const FLOAT_TYPE_STR[7]
Definition: defs.h:220
const double LLL_DEF_DELTA
Definition: defs.h:143
CVPFlags
Definition: defs.h:251
@ CVP_DEFAULT
Definition: defs.h:252
@ CVP_VERBOSE
Definition: defs.h:253
const char *const LLL_METHOD_STR[6]
Definition: defs.h:194
const char *const RED_STATUS_STR[RED_STATUS_MAX]
Definition: defs.h:171
CVPMethod
Definition: defs.h:237
@ CVPM_FAST
Definition: defs.h:238
@ CVPM_PROVED
Definition: defs.h:239
const int BKZ_DEF_RERANDOMIZATION_DENSITY
Definition: defs.h:260
#define FPLLL_TRACE(x)
Definition: defs.h:110
BKZFlags
Definition: defs.h:263
@ BKZ_VERBOSE
Definition: defs.h:265
@ BKZ_SD_VARIANT
Definition: defs.h:273
@ BKZ_SLD_RED
Definition: defs.h:274
@ BKZ_GH_BND
Definition: defs.h:272
@ BKZ_NO_LLL
Definition: defs.h:266
@ BKZ_DEFAULT
Definition: defs.h:264
@ BKZ_MAX_LOOPS
Definition: defs.h:267
@ BKZ_BOUNDED_LLL
Definition: defs.h:269
@ BKZ_MAX_TIME
Definition: defs.h:268
@ BKZ_DUMP_GSO
Definition: defs.h:271
@ BKZ_AUTO_ABORT
Definition: defs.h:270
const double LLL_DEF_ETA
Definition: defs.h:144
const double MAX_LONG_FAST
Definition: defs.h:134
RedStatus
Definition: defs.h:154
@ RED_BKZ_TIME_LIMIT
Definition: defs.h:162
@ RED_GSO_FAILURE
Definition: defs.h:157
@ RED_LLL_FAILURE
Definition: defs.h:159
@ RED_BABAI_FAILURE
Definition: defs.h:158
@ RED_BKZ_FAILURE
Definition: defs.h:161
@ RED_URL_ERR
Definition: defs.h:167
@ RED_ENUM_FAILURE
Definition: defs.h:160
@ RED_HLLL_FAILURE
Definition: defs.h:164
@ RED_BKZ_LOOPS_LIMIT
Definition: defs.h:163
@ RED_SUCCESS
Definition: defs.h:155
@ RED_HLLL_NORM_FAILURE
Definition: defs.h:165
@ RED_HLLL_SR_FAILURE
Definition: defs.h:166
@ RED_STATUS_MAX
Definition: defs.h:168
const int CPU_SIZE
Definition: defs.h:132
LLLMethod
Definition: defs.h:187
@ LM_FAST
Definition: defs.h:191
@ LM_PROVED
Definition: defs.h:189
@ LM_HEURISTIC
Definition: defs.h:190
@ LM_WRAPPER
Definition: defs.h:188
#define FPLLL_END_NAMESPACE
Definition: defs.h:117
const char *const HLLL_METHOD_STR[4]
Definition: defs.h:198
const int PREC_QD
Definition: defs.h:141
const int PREC_DOUBLE
Definition: defs.h:139
const double LLL_DEF_EPSILON
Definition: defs.h:145
SVPMethod
Definition: defs.h:231
@ SVPM_FAST
Definition: defs.h:232
@ SVPM_PROVED
Definition: defs.h:233
const double HLLL_DEF_C
Definition: defs.h:151
const int PREC_DD
Definition: defs.h:140
FloatType
Definition: defs.h:210
@ FT_QD
Definition: defs.h:216
@ FT_DPE
Definition: defs.h:214
@ FT_MPFR
Definition: defs.h:217
@ FT_DD
Definition: defs.h:215
@ FT_DOUBLE
Definition: defs.h:212
@ FT_LONG_DOUBLE
Definition: defs.h:213
@ FT_DEFAULT
Definition: defs.h:211
const int SIZE_RED_FAILURE_THRESH
Definition: defs.h:146
HKZFlags
Definition: defs.h:278
@ HKZ_DEFAULT
Definition: defs.h:279
@ HKZ_VERBOSE
Definition: defs.h:280
const double BKZ_DEF_GH_FACTOR
Definition: defs.h:258
IntType
Definition: defs.h:201
@ ZT_DOUBLE
Definition: defs.h:204
@ ZT_MPZ
Definition: defs.h:202
@ ZT_LONG
Definition: defs.h:203
const double HLLL_DEF_THETA
Definition: defs.h:149
const double BKZ_DEF_AUTO_ABORT_SCALE
Definition: defs.h:256
const int BKZ_DEF_AUTO_ABORT_MAX_NO_DEC
Definition: defs.h:257
SVPFlags
Definition: defs.h:243
@ SVP_VERBOSE
Definition: defs.h:245
@ SVP_DEFAULT
Definition: defs.h:244
@ SVP_DUAL
Definition: defs.h:247
@ SVP_OVERRIDE_BND
Definition: defs.h:246
PrunerMetric
Definition: defs.h:292
@ PRUNER_METRIC_PROBABILITY_OF_SHORTEST
Definition: defs.h:293
@ PRUNER_METRIC_EXPECTED_SOLUTIONS
Definition: defs.h:294
const double BKZ_DEF_MIN_SUCCESS_PROBABILITY
Definition: defs.h:259
#define FPLLL_BEGIN_NAMESPACE
Definition: defs.h:114
PrunerFlags
Definition: defs.h:298
@ PRUNER_SINGLE
Definition: defs.h:312
@ PRUNER_START_FROM_INPUT
Definition: defs.h:302
@ PRUNER_VERBOSE
Definition: defs.h:306
@ PRUNER_NELDER_MEAD
Definition: defs.h:304
@ PRUNER_GRADIENT
Definition: defs.h:303
@ PRUNER_CVP
Definition: defs.h:299
@ PRUNER_HALF
Definition: defs.h:309
const char *const INT_TYPE_STR[5]
Definition: defs.h:207
const long int EXPO_MAX
Definition: defs.h:135
const int CPU_SIZE_1
Definition: defs.h:133
LLLFlags
Definition: defs.h:223
@ LLL_VERBOSE
Definition: defs.h:224
@ LLL_DEFAULT
Definition: defs.h:227
@ LLL_EARLY_RED
Definition: defs.h:225
@ LLL_SIEGEL
Definition: defs.h:226
FP_NR< F > exp(const FP_NR< F > &a)
Definition: nr_FP.inl:572