Macaulay2 Engine
Loading...
Searching...
No Matches
fplll-interface.cpp
Go to the documentation of this file.
1#include "fplll-interface.hpp"
2#include "mutablemat.hpp"
3
4#ifdef HAVE_FPLLL
5#include <stddef.h>
6#include <fplll.h>
7#endif
8
9bool fp_LLL(MutableMatrix *M, MutableMatrix *U, int strategy)
10{
11 (void) M;
12 (void) U;
13 (void) strategy;
14#ifndef HAVE_FPLLL
15 ERROR("fplll is not available (configure M2 with fplll!)");
16 return 0;
17#else
18 assert(U == NULL);
19 double delta = 0.99;
20 double eta = 0.51;
21 fplll::LLLMethod method = fplll::LM_WRAPPER;
22 fplll::FloatType floatType = fplll::FT_DEFAULT;
23 int precision = 0;
24 int flags = fplll::LLL_DEFAULT;
25
26 int ncols = static_cast<int>(M->n_rows());
27 int nrows = static_cast<int>(M->n_cols());
28
29 fplll::ZZ_mat<mpz_t> mat(nrows, ncols);
30
31 for (int i = 0; i < nrows; i++)
32 for (int j = 0; j < ncols; j++)
33 {
34 ring_elem a;
35 if (M->get_entry(j, i, a))
36 {
37 mpz_set(mat[i][j].get_data(), a.get_mpz());
38 }
39 }
40
41 int result =
42 lll_reduction(mat, delta, eta, method, floatType, precision, flags);
43
44 switch (result)
45 {
46 case fplll::RED_SUCCESS:
47 break;
48 case fplll::RED_BABAI_FAILURE:
49 ERROR("Error in fpLLL");
50 return 0;
51 case fplll::RED_LLL_FAILURE:
52 ERROR("infinite loop in LLL");
53 return 0;
54 default:
55 ERROR("unknown error in fpLLL");
56 return 0;
57 }
58
59 /* Put this back into M */
60 mpz_t a;
61 mpz_init(a);
62
63 for (int j = 0; j < ncols; j++)
64 for (int i = 0; i < nrows; i++)
65 {
66 mpz_set(a, mat[i][j].get_data());
67 ring_elem b = globalZZ->from_int(a);
68 M->set_entry(j, i, b);
69 }
70 mpz_clear(a);
71 return true;
72#endif
73}
74
75// Local Variables:
76// compile-command: "make -C $M2BUILDDIR/Macaulay2/e "
77// indent-tabs-mode: nil
78// End:
virtual size_t n_rows() const =0
virtual size_t n_cols() const =0
virtual bool get_entry(size_t r, size_t c, ring_elem &result) const =0
virtual bool set_entry(size_t r, size_t c, const ring_elem a)=0
Abstract base class for mutable matrices over an arbitrary engine Ring, the in-place counterpart of t...
Definition mat.hpp:79
bool fp_LLL(MutableMatrix *M, MutableMatrix *U, int strategy)
Engine-side wrapper around the external fplll lattice-reduction library.
RingZZ * globalZZ
Definition relem.cpp:13
const int ERROR
Definition m2-mem.cpp:55
VALGRIND_MAKE_MEM_DEFINED & result(result)
Umbrella header that ties together MutableMat declarations, implementations, and the SLP variant.
mpz_srcptr get_mpz() const
Definition ringelem.hpp:127