Macaulay2 Engine
Loading...
Searching...
No Matches

◆ initializeLLL()

bool LLLoperations::initializeLLL ( const MutableMatrix * A,
gmp_QQ threshold,
MutableMatrix *& LLLstate )
staticprivate

Definition at line 28 of file LLL.cpp.

31{
32 // First check m: should be a matrix over globalZZ.
33 if (A == nullptr || A->get_ring() != globalZZ)
34 {
35 ERROR("LLL only defined for matrices over ZZ");
36 return false;
37 }
38
39 ring_elem num = globalZZ->from_int(mpq_numref(threshold));
40 ring_elem den = globalZZ->from_int(mpq_denref(threshold));
41 // Check that 'threshold' is in range, and set the numerator, denom
42 if (!checkThreshold(num, den))
43 {
44 ERROR("LLL threshold should be in the range (1/4, 1]");
45 globalZZ->remove(num);
46 globalZZ->remove(den);
47 return false;
48 }
49
50 // LLLstate has n+4 columns, and n rows.
51 // First n columns: LLLstate(i,i) = D#i
52 // LLLstate(i,j) = lambda#(j,i) for
53 // Last four columns just have entries in row 0:
54 // The entries are: k, kmax, alphaTop, alphaBottom: all are ZZ values.
55
56 size_t n = A->n_cols();
57 LLLstate = MutableMatrix::zero_matrix(globalZZ, n, n + 4, A->is_dense());
58 if (n > 0)
59 {
60 LLLstate->set_entry(0, n, globalZZ->from_long(1)); // k := 2
61 // LLLstate->set_entry(0,n+1,globalZZ->from_long(0)); // kmax := 1
62 LLLstate->set_entry(
63 0, n + 2, num); // Set threshold numerator, denominator
64 LLLstate->set_entry(0, n + 3, den);
65 ring_elem dot;
66 A->dot_product(0, 0, dot);
67 LLLstate->set_entry(0, 0, dot); // D#1 := dot(A,0,0)
68 }
69 return true;
70}
static bool checkThreshold(ring_elem num, ring_elem den)
Definition LLL.cpp:10
virtual bool dot_product(size_t i, size_t j, ring_elem &result) const =0
virtual size_t n_cols() const =0
static MutableMatrix * zero_matrix(const Ring *R, size_t nrows, size_t ncols, bool dense)
Definition mat.cpp:54
virtual bool is_dense() const =0
virtual const Ring * get_ring() const =0
virtual bool set_entry(size_t r, size_t c, const ring_elem a)=0
virtual ring_elem from_long(long n) const
Definition ZZ.cpp:110
virtual void remove(ring_elem &f) const
Definition ZZ.cpp:194
virtual ring_elem from_int(mpz_srcptr n) const
Definition ZZ.cpp:119
RingZZ * globalZZ
Definition relem.cpp:13
const int ERROR
Definition m2-mem.cpp:55

References checkThreshold(), MutableMatrix::dot_product(), ERROR, MutableMatrix::get_ring(), globalZZ, MutableMatrix::is_dense(), MutableMatrix::n_cols(), MutableMatrix::set_entry(), and MutableMatrix::zero_matrix().

Referenced by LLL().