Loading...
Searching...
No Matches
lattice Class Reference

`#include <lattice.h>`

## Public Member Functions

| lattice (bigintmat *basis)
| ~lattice ()
bool | LLL ()
bool | LLL (number &c)
bigintmat * | get_basis ()
bigintmat * | get_reduced_basis ()
bigintmat * | get_transformation_matrix ()
bigintmat * | enumerate_all (number a)
bigintmat * | enumerate_next (number a, bigintmat *x)
bigintmat * | enumerate_next (number a)
bigintmat * | enumerate_next (bigintmat *x)
bigintmat * | enumerate_next ()

## Private Member Functions

void | RED (int k, int l)
void | SWAP (int k, int k_max)
void | SWAPG (int k, int k_max)
bool | gram_schmidt (int k)
void | gram_schmidt_MLLL (int k)
void | compute_gram_matrix ()
number | enumerate_get_next ()
bool | quadratic_supplement ()
void | increase_x (int index)
number | check_bound (int index)

## Private Attributes

bigintmat ** | basis
bigintmat * | gram_matrix
int | n
int | m
coeffs | coef
number | c
bigintmat ** | b
bigintmat ** | b_star
number * | B
bigintmat * | H
bigintmat * | my
number * | d
int | rank
bool | trans_matrix
bool | independentVectors
bool | integral
bigintmat * | Q
bigintmat * | x
number * | bound
coeffs | out_coef

## Detailed Description

Definition at line 6 of file lattice.h.

## Constructor & Destructor Documentation

## lattice()

lattice::lattice | ( | bigintmat * | basis | ) |

Definition at line 52 of file lattice.cc.

{
DEBUG_BLOCK(true);
DEBUG_PRINT(("Creating new lattice..."));
n = basismatrix->cols();
m = basismatrix->rows();
out_coef = basismatrix->basecoeffs();
DEBUG_PRINT(("always set coef =out_coef"));
coef =out_coef;
//NOTE: Add transformation from rings to fields here
// exact <-> rounded
basis = new bigintmat*[n+1]; //basis[0] is not used
basis[0] = NULL;
for(int i=1; i<=n; i++) {
basis[i] = new bigintmat(m,1,coef);
basismatrix->getcol(i,basis[i]);
}
gram_matrix = bimCopy(basismatrix);
c = NULL;
B = NULL;
b = NULL;
b_star = NULL;
H = NULL;
my = NULL;
Q = NULL;
rank = 0;
independentVectors = true;
integral = true;
trans_matrix = true;
//for enumeration
x = NULL;
bound = NULL;
DEBUG_PRINT(("Done\n"));
}
bimCopy
bigintmat * bimCopy(const bigintmat *b)
same as copy constructor - apart from it being able to accept NULL as input
Definition bigintmat.cc:403
i
int i
Definition cfEzgcd.cc:132
lattice::my
bigintmat * my
Definition lattice.h:40
lattice::m
int m
Definition lattice.h:20
lattice::integral
bool integral
Definition lattice.h:55
lattice::rank
int rank
Definition lattice.h:46
lattice::H
bigintmat * H
Definition lattice.h:37
lattice::trans_matrix
bool trans_matrix
Definition lattice.h:49
lattice::B
number * B
Definition lattice.h:34
lattice::independentVectors
bool independentVectors
Definition lattice.h:52
lattice::basis
bigintmat ** basis
Definition lattice.h:11
lattice::gram_matrix
bigintmat * gram_matrix
Definition lattice.h:14
lattice::c
number c
Definition lattice.h:25
lattice::out_coef
coeffs out_coef
Definition lattice.h:67
lattice::n
int n
Definition lattice.h:17
lattice::coef
coeffs coef
Definition lattice.h:22
lattice::bound
number * bound
Definition lattice.h:64
lattice::Q
bigintmat * Q
Definition lattice.h:58
lattice::x
bigintmat * x
Definition lattice.h:61
lattice::b_star
bigintmat ** b_star
Definition lattice.h:31
lattice::b
bigintmat ** b
Definition lattice.h:28
DEBUG_BLOCK
#define DEBUG_BLOCK(x)
Definition lattice.cc:29
DEBUG_PRINT
#define DEBUG_PRINT(x)
Definition lattice.cc:33
NULL
#define NULL
Definition omList.c:12

## ~lattice()

lattice::~lattice | ( |  | ) |

Definition at line 90 of file lattice.cc.

{
DEBUG_BLOCK(true);
DEBUG_PRINT(("Deleting lattice..."));
if(basis != NULL) {
for(int i=0; i<=n; i++) {
delete basis[i];
}
delete[] basis;
}
if(b != NULL) {
for(int i=0; i<=n; i++) {
delete b[i];
}
delete[] b;
}
if(b_star != NULL) {
for(int i=0; i<=n; i++) {
delete b_star[i];
}
delete[] b_star;
}
delete H;
delete my;
delete[] B;
n_Delete(&c,coef);
delete Q;
DEBUG_PRINT(("Done\n"));
}
n_Delete
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:461

## Member Function Documentation

## check_bound()

number lattice::check_bound | ( | int | index | ) |

inline private

Definition at line 855 of file lattice.cc.

{
DEBUG_BLOCK(true);DEBUG_PRINT(("check bound\n"));DEBUG_VAR(index);
number check = n_Init(0,coef);DEBUG_PRINT(("x:\n"));x->Print();
for(int i=index + 1;i<=Q->cols();i++){DEBUG_VAR(i);
number mult = n_Mult(x->view(i,1),Q->view(index,i),coef);
n_InpAdd(check,mult,coef);
n_Delete(&mult,coef);
}
n_InpAdd(check, x->view(index,1), coef);
n_InpMult(check, check, coef);
n_InpMult(check, Q->get(index,index), coef);
return check;
}
n_Mult
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
Definition coeffs.h:639
n_Init
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition coeffs.h:541
n_InpMult
static FORCE_INLINE void n_InpMult(number &a, number b, const coeffs r)
multiplication of 'a' and 'b'; replacement of 'a' by the product a*b
Definition coeffs.h:644
n_InpAdd
static FORCE_INLINE void n_InpAdd(number &a, number b, const coeffs r)
addition of 'a' and 'b'; replacement of 'a' by the sum a+b
Definition coeffs.h:649
DEBUG_VAR
#define DEBUG_VAR(x)
Definition lattice.cc:35
check
VAR int check
Definition libparse.cc:1106
mult
void mult(unsigned long *result, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition minpoly.cc:647
index
static int index(p_Length length, p_Ord ord)
Definition p_Procs_Impl.h:592

## compute_gram_matrix()

void lattice::compute_gram_matrix | ( |  | ) |

inline private

Definition at line 828 of file lattice.cc.

{
if(gram_matrix != NULL) {
delete gram_matrix;
gram_matrix = NULL;
}
gram_matrix = new bigintmat(n,n,coef);
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
gram_matrix->set(i,j,scalarproduct(basis[i],basis[j]));
}
}
}
j
int j
Definition facHensel.cc:110
scalarproduct
number scalarproduct(bigintmat *a, bigintmat *b)
Definition lattice.cc:915

## enumerate_all()

bigintmat * lattice::enumerate_all | ( | number | a | ) |

Definition at line 507 of file lattice.cc.

{
//Quadratic Supplement
DEBUG_BLOCK(true);
DEBUG_PRINT(("Start enumerate_all\n"));
DEBUG_PRINT(("check input\n"));
if(!n_GreaterZero(a,out_coef)){
if(n_IsZero(a,out_coef) && n==m){
return new bigintmat(m,1,out_coef);
} else {
DEBUG_PRINT(("negative input\n"));
return NULL;
}
}
if( Q == NULL){
if(quadratic_supplement()){
return NULL;
}
}
DEBUG_PRINT(("Q defined\n"));
//Q->Print();PrintS("\n");
//usefull numbers
number zero = n_Init(0,coef);
number minusOne = n_Init(-1,coef);
//backtracking for elements
//DEBUG_BLOCK(true);
DEBUG_PRINT(("Start backtracking\n"));
DEBUG_PRINT(("Initialize vector and other variables\n"));
std::vector<std::pair<number,bigintmat*> > elementsvector;
elementsvector.push_back( std::make_pair(zero, new bigintmat(m,1,out_coef)));
if( x != NULL){
delete x;
x=NULL;
}
x = new bigintmat(m,1,coef);
//x->Print();PrintS("\n");
DEBUG_PRINT(("map a\n"));
if(bound != NULL){
delete bound;
bound = NULL;
}
bound = new number[n+1];
nMapFunc f = n_SetMap(out_coef, coef);
bound[1] = f(a, out_coef, coef);//map a to coef
//n_Print(bound[1],coef);PrintS("\n");
DEBUG_PRINT(("set bound\n"));
for(int i = 2; i<n+1; i++){
bound[i] = n_Copy(bound[1],coef);
//n_Print(bound[i],coef);PrintS("\n");
}
DEBUG_PRINT(("find element\n"));
//bigintmat* elements = enumerate_next(a);
increase_x(1);
number check = enumerate_get_next();
while(!n_Equal(minusOne,check,coef)){
//append x to elements
DEBUG_PRINT(("new element to list\n"));
//elements->appendCol(bimChangeout_coeff(x,out_coef));
check = n_Sub(bound[1],check,coef);
check = n_Sub(bound[n],check,coef);
elementsvector.push_back(std::make_pair(n_Copy(check,coef),bimCopy(x)));
//n_Print(elementsvector[elementsvector.size()-1].first,coef);PrintS("\n");
for(unsigned i=1; i<elementsvector.size();i++){
if(n_Greater(elementsvector[i].first,check,coef)){
elementsvector.pop_back();
elementsvector.insert(elementsvector.begin()+i,std::make_pair(n_Copy(check,coef),bimCopy(x)));
DEBUG_VAR(elementsvector.size());
break;
}
}
if(elementsvector.size() >= 1000000){
elementsvector.pop_back();
}
increase_x(1);
DEBUG_PRINT(("increased x:\n"));x->Print();
n_Delete(&check,coef);
check = enumerate_get_next();
DEBUG_PRINT(("got it\n"));
}
DEBUG_PRINT(("generate bigintmat for return\n"));
bigintmat* elements = new bigintmat(m,1,out_coef);
if(b!=NULL){
for(unsigned i=1; i<elementsvector.size();i++){
elements->appendCol(bimChangeCoeff(elementsvector[i].second,out_coef));
}
} else {
for(unsigned i=1; i<elementsvector.size();i++){
elements->appendCol(bimChangeCoeff(elementsvector[i].second,out_coef));
}
}
delete bound;
bound = NULL;
delete x;
x = NULL;
return elements;
}
bimChangeCoeff
bigintmat * bimChangeCoeff(bigintmat *a, coeffs cnew)
Liefert Kopier von Matrix a zurück, mit coeffs cnew statt den ursprünglichen.
Definition bigintmat.cc:1797
f
FILE * f
Definition checklibs.c:9
bigintmat::appendCol
void appendCol(bigintmat *a)
horizontally join the matrices, m <- m|a
Definition bigintmat.cc:1078
lattice::quadratic_supplement
bool quadratic_supplement()
Definition lattice.cc:775
lattice::increase_x
void increase_x(int index)
Definition lattice.cc:841
lattice::enumerate_get_next
number enumerate_get_next()
Definition lattice.cc:718
n_Copy
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition coeffs.h:457
n_GreaterZero
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff 'n' is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2),...
Definition coeffs.h:500
n_SetMap
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition coeffs.h:703
n_Greater
static FORCE_INLINE BOOLEAN n_Greater(number a, number b, const coeffs r)
ordered fields: TRUE iff 'a' is larger than 'b'; in Z/pZ: TRUE iff la > lb, where la and lb are the l...
Definition coeffs.h:517
n_IsZero
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition coeffs.h:470
n_Sub
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
Definition coeffs.h:658
n_Equal
static FORCE_INLINE BOOLEAN n_Equal(number a, number b, const coeffs r)
TRUE iff 'a' and 'b' represent the same number; they may have different representations.
Definition coeffs.h:466
nMapFunc
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80

## enumerate_get_next()

number lattice::enumerate_get_next | ( |  | ) |

inline private

Definition at line 718 of file lattice.cc.

{
DEBUG_BLOCK(true);
DEBUG_PRINT(("enumerate_get_next\t\t\t\t\taaaaaaaaaaaaa\n"));
number one = n_Init(1,coef);
number zero = n_Init(0,coef);
number minusOne = n_Init(-1,coef);
int index =1;
//x->Print();PrintS("\n");
//DEBUG_PRINT(("first time changing x\n"));
//increase_x(1);
DEBUG_PRINT(("actual backtracking\n"));
while (index <= m) {
DEBUG_PRINT(("update check\n"));
number check = check_bound(index);
DEBUG_PRINT(("check check\n"));
if (n_Greater(check,bound[index],coef)){
DEBUG_PRINT(("element to great\n"));
if(!(n_GreaterZero(x->view(index,1),coef) || n_IsZero(x->view(index,1),coef))){
bound[index] = zero;
x->set(index,1,zero,coef);
index++;
if(index<= m){
increase_x(index);
}
} else {
if(index == n){
return minusOne;
}
x->set(index,1,minusOne,coef);
}
} else if(index == 1){
DEBUG_PRINT(("possible new element\n"));
if(n_IsZero(x->view(n,1),coef)){
int j=n-1;
while(n_IsZero(x->view(j,1),coef)){
j--;
}DEBUG_VAR(j);
if(n_GreaterZero(x->view(j,1),coef)){
return check;
} else {
index = j+1;
x->zero();
x->set(index,1,one,coef);
}
} else {
DEBUG_PRINT(("return\n"));
return check;
}
} else {
DEBUG_PRINT(("reduce index\n"));
index--;
bound[index] = n_Sub(bound[index+1],check,coef);
}
}
return minusOne;
}
lattice::check_bound
number check_bound(int index)
Definition lattice.cc:855

## enumerate_next() [1/4]

bigintmat * lattice::enumerate_next | ( |  | ) |

Definition at line 691 of file lattice.cc.

{
DEBUG_BLOCK(true);
DEBUG_PRINT(("enumerate_next\n"));
if(Q == NULL){
Werror("not initialized\n");
return NULL;
}
if(bound == NULL || x == NULL){
return NULL;
}
increase_x(1);
number minusOne = n_Init(-1,coef);
number one = n_Init(1,coef);
DEBUG_PRINT(("find element\n"));
number norm = enumerate_get_next();
DEBUG_PRINT(("generate bigintmat for return\n"));
if(n_Equal(minusOne,norm,coef)){
if(!n_Equal(minusOne, x->view(1,1),coef)){
x->rawset(1,1, n_Add(one,x->view(1,1),coef),coef);
}
return NULL;
}
bigintmat * out = bimChangeCoeff(x,out_coef);
return out;
}
n_Add
static FORCE_INLINE number n_Add(number a, number b, const coeffs r)
return the sum of 'a' and 'b', i.e., a+b
Definition coeffs.h:653
norm
mipo *CanonicalForm norm
Definition facAlgExt.cc:61
Werror
void Werror(const char *fmt,...)
Definition reporter.cc:189

## enumerate_next() [2/4]

bigintmat * lattice::enumerate_next | ( | bigintmat * | x | ) |

Definition at line 676 of file lattice.cc.

{
DEBUG_BLOCK(true);
DEBUG_PRINT(("Start enumerate_next bigintmat\n"));
if(bound == NULL){
Werror("no bound for elements given\n");
return NULL;
}
if (in == NULL || in->rows()!=n || in->cols()!=1){
DEBUG_PRINT(("Dimension error of input\n"));
return NULL;
}
number a = bound[n];
return enumerate_next(a,in);
}
lattice::enumerate_next
bigintmat * enumerate_next()
Definition lattice.cc:691

## enumerate_next() [3/4]

bigintmat * lattice::enumerate_next | ( | number | a | ) |

Definition at line 664 of file lattice.cc.

{
DEBUG_BLOCK(true);
DEBUG_PRINT(("Start enumerate_next number\n"));
bigintmat * in =new bigintmat(m,1,out_coef);
if(x == NULL){
in->set(1,1,n_Init(1,out_coef),out_coef);
} else {
in = bimChangeCoeff(x,out_coef);
}
return enumerate_next(a,in);
}
bigintmat::set
void set(int i, int j, number n, const coeffs C=NULL)
replace an entry with a copy (delete old + copy new!). NOTE: starts at [1,1]
Definition bigintmat.cc:93

## enumerate_next() [4/4]

bigintmat * lattice::enumerate_next | ( | number | a,
|  | bigintmat * | x )

Definition at line 605 of file lattice.cc.

{//next element x with norm(x)<a and x=in possible
DEBUG_BLOCK(true);
DEBUG_PRINT(("Start enumerate_next number and bigintmat\n"));
if (in == NULL || in->rows()!=n || in->cols()!=1){
DEBUG_PRINT(("Dimension error of input\n"));
return NULL;
}
if(!n_GreaterZero(a,out_coef) || n_IsZero(a,out_coef) ){
DEBUG_PRINT(("negative input\n"));
return NULL;
}
DEBUG_PRINT(("check quadratic\n"));
if( Q == NULL){
if(!quadratic_supplement()){
return NULL;
}
}
DEBUG_PRINT(("Q defined\n"));
//Q->Print();PrintS("\n");
//usefull numbers
number check;
//backtracking for elements
//DEBUG_BLOCK(true);
DEBUG_PRINT(("Start backtracking\n"));
DEBUG_PRINT(("Initialize variables\n"));
if( x != NULL){
delete x;
x=NULL;
}
x = bimChangeCoeff(in,coef);
if( bound != NULL){
delete bound;
bound=NULL;
}
bound = new number[n+1];
DEBUG_PRINT(("set bound\n"));
nMapFunc f = n_SetMap(out_coef, coef);
bound[n] = f(a, out_coef, coef);//map a to coef
for(int j = n; j>1; j--){
check = check_bound(j);
bound[j-1] = n_Sub(bound[j],check,coef);
//n_Delete(&check, coef);
}
number minusOne = n_Init(-1,coef);
DEBUG_PRINT(("find element\n"));
number norm = enumerate_get_next();
DEBUG_PRINT(("generate bigintmat for return\n"));
if(n_Equal(minusOne,norm,coef)){
return NULL;
}
bigintmat * out = bimChangeCoeff(x,out_coef);
return out;
}

## get_basis()

bigintmat * lattice::get_basis | ( |  | ) |

Definition at line 874 of file lattice.cc.

{
bigintmat * r = new bigintmat(m,n,coef);
for(int j=1; j<=n; j++) {
r->setcol(j,basis[j]);
}
return r;
}
bigintmat::setcol
void setcol(int j, bigintmat *m)
Setzt j-te Spalte gleich übergebenem Vektor (Matrix) m.
Definition bigintmat.cc:821

## get_reduced_basis()

bigintmat * lattice::get_reduced_basis | ( |  | ) |

Definition at line 882 of file lattice.cc.

{
bigintmat * r = new bigintmat(m,n,coef);
for(int j=1; j<=n; j++) {
r->setcol(j,b[j]);
}
return r;
}

## get_transformation_matrix()

bigintmat * lattice::get_transformation_matrix | ( |  | ) |

Definition at line 890 of file lattice.cc.

{
return bimCopy(H);
}

## gram_schmidt()

bool lattice::gram_schmidt | ( | int | k | ) |

inline private

Definition at line 430 of file lattice.cc.

{
DEBUG_PRINT(("Start gram_schmidt(%d)\n",k));
delete b_star[k];
b_star[k] = bimCopy(b[k]);
for(int j=1; j<k; j++) {
my->set(k,j,n_Div(scalarproduct(b[k],b_star[j]),B[j],coef),coef);
b_star[k]->sub(bimMult(b_star[j],my->view(k,j),coef));
}
B[k] = scalarproduct(b_star[k],b_star[k]);
if(n_IsZero(B[k],coef)){
Werror("did not form a basis\n");
DEBUG_PRINT(("End of gram_schmidt(%d)\n",k));
return true;
} else {
DEBUG_PRINT(("End of gram_schmidt(%d)\n",k));
return false;
}
}
bimMult
bigintmat * bimMult(bigintmat *a, bigintmat *b)
Definition bigintmat.cc:253
k
int k
Definition cfEzgcd.cc:99
n_Div
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
Definition coeffs.h:618

## gram_schmidt_MLLL()

void lattice::gram_schmidt_MLLL | ( | int | k | ) |

inline private

Definition at line 454 of file lattice.cc.

{
DEBUG_PRINT(("Start gram_schmidt_MLLL(%d)\n",k));
for(int j=1; j<k; j++) {
if(n_IsZero(B[j],coef)) {
my->set(k,j,n_Init(0,coef));
} else {
my->set(k,j,n_Div(scalarproduct(b[k],b_star[j]),B[j],coef),coef);
}
}
delete b_star[k];
b_star[k] = bimCopy(b[k]);
for(int j=1; j<k; j++) {
b_star[k]->sub(bimMult(b_star[j],my->view(k,j),coef));
}
B[k] = scalarproduct(b_star[k],b_star[k]);
DEBUG_PRINT(("End of gram_schmidt_MLLL(%d)\n",k));
}

## increase_x()

void lattice::increase_x | ( | int | index | ) |

inline private

Definition at line 841 of file lattice.cc.

{
number one = n_Init(1,coef);x->Print();
number newNumber;
if (n_GreaterZero(x->view(index,1),coef) || n_IsZero(x->view(index,1),coef)){
newNumber = n_Add(one,x->view(index,1),coef); //x_i=x_i+1
} else {
newNumber = n_Sub(x->view(index,1),one,coef);//x_i=x_i-1
}
x->set(index,1,newNumber,coef);
x->Print();
n_Delete(&one,coef);
n_Delete(&newNumber,coef);
}

## LLL() [1/2]

bool lattice::LLL | ( |  | ) |

Definition at line 133 of file lattice.cc.

{
// c = 3/4
number three = n_Init(3, coef);
number four = n_Init(4, coef);
number default_c = n_Div(three,four,coef);
n_Delete(&three,coef);
n_Delete(&four,coef);
return lattice::LLL(default_c);
}
lattice::LLL
bool LLL()
Definition lattice.cc:133

## LLL() [2/2]

bool lattice::LLL | ( | number & | c | ) |

Definition at line 143 of file lattice.cc.

{
DEBUG_PRINT(("Start LLL\n"));
if(b == NULL) {
b = new bigintmat*[n+1]; //b[0] is not used
b[0] = NULL;
for(int j=1; j<=n; j++) {
b[j] = bimCopy(basis[j]);
}
} else {
b[0] = NULL;
for(int j=1; j<=n; j++) {
delete b[j];
b[j] = bimCopy(basis[j]);
}
}
if(b_star == NULL) {
b_star = new bigintmat*[n+1]; //b_star[0] is not used
for(int j=0; j<=n; j++) {
b_star[j] = NULL;
}
} else {
for(int j=0; j<=n; j++) {
delete b_star[j];
b_star[j] = NULL;
}
}
if(B == NULL) {
B = new number[n+1]; //B[0] is not used
}
for(int j=0; j<=n; j++) {
B[j] = n_Init(0,coef);
}
delete H;
if(trans_matrix) {
H = new bigintmat(n,n,coef);
} else {
H = NULL;
}
delete my;
my = new bigintmat(m,n,coef);
delete[] d;
if(integral) {
d = new number[n+1];
} else {
d = NULL;
}
this->c = c;
if (n == 0) {
return true;
}
if (n == 1) {
return false;
}
DEBUG_BIM(b[1]);
DEBUG_BIM(b[2]);
DEBUG_BIM(b[3]);
DEBUG_PRINT(("Initialize\n"));
int k = 2;
int k_max = 1;
b_star[1] = bimCopy(b[1]);
B[1] = scalarproduct(b[1],b[1]);
if(trans_matrix) {
H->one();
}
do{
DEBUG_PRINT(("Incremental Gram-Schmidt\n"));
DEBUG_VAR(k);
DEBUG_VAR(k_max);
if(k > k_max){
k_max = k;
if(independentVectors) {
if(gram_schmidt(k)){
return true;
}
} else {
gram_schmidt_MLLL(k);
}
}
DEBUG_PRINT(("Test LLL condition\n"));
while(true){
RED(k,k-1);
// if((B[k] < (c- my*my)*B[k-1]))
if(n_Greater(n_Mult(n_Sub(c, n_Mult(my->view(k,k-1), my->view(k,k-1), coef), coef), B[k-1], coef), B[k], coef)){
if(independentVectors) {
SWAP(k,k_max);
} else {
SWAPG(k,k_max);
}
if(k>2){
k--;
}
} else {
for(int l=k-2; l>0; l--){
RED(k,l);
}
k++;
break;
}
}
} while(k <= n);
rank = n;
for(int i=1; b[i]->isZero() && i<=n; i++) {
rank--;
}
DEBUG_BIM(b[1]);
DEBUG_BIM(b[2]);
DEBUG_BIM(b[3]);
DEBUG_PRINT(("End of LLL\n"));
return false;
}
l
int l
Definition cfEzgcd.cc:100
lattice::SWAP
void SWAP(int k, int k_max)
Definition lattice.cc:315
lattice::SWAPG
void SWAPG(int k, int k_max)
Definition lattice.cc:357
lattice::gram_schmidt
bool gram_schmidt(int k)
Definition lattice.cc:430
lattice::gram_schmidt_MLLL
void gram_schmidt_MLLL(int k)
Definition lattice.cc:454
lattice::RED
void RED(int k, int l)
Definition lattice.cc:276
lattice::d
number * d
Definition lattice.h:43
DEBUG_BIM
#define DEBUG_BIM(x)
Definition lattice.cc:37

## quadratic_supplement()

bool lattice::quadratic_supplement | ( |  | ) |

inline private

Definition at line 775 of file lattice.cc.

{
//DEBUG_BLOCK(true);
delete Q;
Q = NULL;
if(n != m) { //NOTE: rank?
return true;
}
compute_gram_matrix();
Q = gram_matrix;
number zero = n_Init(0,coef);
number mult;
DEBUG_PRINT(("Begin Quadratic Suplement\n"));
for(int i = 1; i<Q->cols();i++){
if(n_IsZero( Q->view(i,i), coef)){
DEBUG_PRINT(("matrix not positive definite\n"));
delete Q;
Q = NULL;
return true;
}
for( int j=i+1; j<=Q->cols();j++){
Q->rawset(j,i,Q->get(i,j),coef);
Q->rawset(i,j,n_Div(Q->get(i,j),Q->view(i,i),coef),coef);
}
for(int m=i+1; m<=Q->rows();m++){
for(int n=i+1; n<=Q->cols();n++){
mult = n_Mult(Q->view(m,i),Q->view(i,n),coef);
Q->rawset(m,n,n_Sub(Q->get(m,n),mult,coef),coef);
n_Delete(&mult,coef);
}
}
}
DEBUG_PRINT(("Set Zeros\n"));
for(int i = 2; i<=Q->cols();i++){
for(int j = 1; j<i;j++){
Q->set(i,j,zero,coef);
}
}
n_Delete(&zero,coef);
DEBUG_PRINT(("Test: matrix positive definite\n"));
for(int i=1; i<=Q->cols();i++){
if(!n_GreaterZero( Q->view(i,i), coef)){
DEBUG_PRINT(("matrix not positive definite\n"));
delete Q;
Q = NULL;
return true;
}
}
return false;
}
lattice::compute_gram_matrix
void compute_gram_matrix()
Definition lattice.cc:828

## RED()

void lattice::RED | ( | int | k,
|  | int | l )

inline private

Definition at line 276 of file lattice.cc.

{
DEBUG_PRINT(("Start RED with k=%d and l=%d\n",k,l));
DEBUG_BIM(b[1]);
DEBUG_BIM(b[2]);
DEBUG_BIM(b[3]);
number n_1div2 = n_Div(n_Init( 1,coef),n_Init(2,coef),coef);
number n_neg1div2 = n_Div(n_Init(-1,coef),n_Init(2,coef),coef);
number my_kl = my->get(k,l);
DEBUG_N(my_kl);
// if(|my_kl| > 1/2)
if (n_Greater (my_kl,n_1div2,coef) || n_Greater (n_neg1div2,my_kl,coef)) {
number my_klplus1div2;
if(n_Greater (my_kl,n_Init(0,coef),coef)) {
my_klplus1div2 = n_Add(my_kl, n_1div2, coef);
} else {
my_klplus1div2 = n_Add(my_kl, n_neg1div2, coef);
}
number q = n_Div(n_GetNumerator(my_klplus1div2,coef),n_GetDenom(my_klplus1div2,coef),coef);
DEBUG_N(q);
b[k]->sub(bimMult(b[l],q,coef));
if(trans_matrix) {
H->addcol(k,l,n_Mult(q,n_Init(-1,coef),coef),coef);
}
my->set(k,l,n_Sub(my->view(k,l),q,coef),coef);
for(int i=1;i<=l-1;i++){
my->set(k,i,n_Sub(my->view(k,i), n_Mult(q, my->view(l,i),coef), coef), coef);
}
}
DEBUG_PRINT(("End of RED\n"));
}
n_GetDenom
static FORCE_INLINE number n_GetDenom(number &n, const coeffs r)
return the denominator of n (if elements of r are by nature not fractional, result is 1)
Definition coeffs.h:606
n_GetNumerator
static FORCE_INLINE number n_GetNumerator(number &n, const coeffs r)
return the numerator of n (if elements of r are by nature not fractional, result is n)
Definition coeffs.h:611
DEBUG_N
#define DEBUG_N(x)
Definition lattice.cc:36

## SWAP()

void lattice::SWAP | ( | int | k,
|  | int | k_max )

inline private

Definition at line 315 of file lattice.cc.

{
DEBUG_PRINT(("Start SWAP with k=%d and k_max=%d\n",k,k_max));
bigintmat * temp = b[k];
b[k] = b[k-1];
b[k-1] = temp;
if(trans_matrix) {
H->swap(k,k-1);
}
for(int j = 1; j <= k-2; j++){
number my_kj = my->get(k,j);
my->set(k,j,my->view(k-1,j),coef);
my->set(k-1,j,my_kj,coef);
}
number my_ = my->get(k,k-1);
number B_ = n_Add(B[k], n_Mult(n_Mult(my_,my_,coef), B[k-1], coef), coef);
my->set(k,k-1,n_Div(n_Mult(my_, B[k-1], coef), B_, coef), coef);
bigintmat * b_ = bimCopy(b_star[k-1]);
b_star[k-1] = bimAdd(b_star[k], bimMult(b_, my_, coef));
b_star[k] = bimSub(bimMult(b_, n_Div(B[k], B_, coef),coef), bimMult( b_star[k], my->view(k,k-1), coef));
delete b_;
B[k] = n_Div(n_Mult(B[k], B[k-1], coef), B_, coef);
B[k-1] = n_Copy(B_, coef);
for(int i = k+1; i <= k_max; i++){
number t = my->get(i,k);
my->set(i,k,n_Sub(my->get(i,k-1), n_Mult(my_, t, coef), coef), coef);
my->set(i,k-1, n_Add(t, n_Mult(my->view(k,k-1), my->view(i,k), coef), coef), coef);
}
DEBUG_PRINT(("End of SWAP\n"));
}
bimSub
bigintmat * bimSub(bigintmat *a, bigintmat *b)
Definition bigintmat.cc:216
bimAdd
bigintmat * bimAdd(bigintmat *a, bigintmat *b)
Matrix-Add/-Sub/-Mult so oder mit operator+/-/* ? @Note: NULL as a result means an error (non-compati...
Definition bigintmat.cc:180

## SWAPG()

void lattice::SWAPG | ( | int | k,
|  | int | k_max )

inline private

Definition at line 357 of file lattice.cc.

{
DEBUG_PRINT(("Start SWAPG with k=%d and k_max=%d\n",k,k_max));
bigintmat * temp = b[k];
b[k] = b[k-1];
b[k-1] = temp;
if(trans_matrix) {
H->swap(k,k-1);
}
for(int j = 1; j <= k-2; j++){
number my_kj = my->get(k,j);
my->set(k,j,my->get(k-1,j),coef);
my->set(k-1,j,my_kj,coef);
}
number my_ = my->get(k,k-1);
number B_ = n_Add(B[k], n_Mult(n_Mult(my_,my_,coef), B[k-1], coef), coef);
if(n_IsZero(B[k],coef)) {
if(n_IsZero(my_,coef)) {
number tempnumber = B[k];
B[k] = B[k-1];
B[k-1] = tempnumber;
bigintmat * temp = b_star[k];
b_star[k] = b_star[k-1];
b_star[k-1] = temp;
for(int i = k+1; i <= k_max; i++){
number tempnumber = my->get(i,k);
my->set(i,k,my->get(i,k-1), coef);
my->set(i,k-1,tempnumber, coef);
}
} else {
B[k-1] = n_Copy(B_, coef); //delete B[k-1] ?
b_star[k-1]->skalmult(my_, coef);
my->set(k,k-1, n_Div(n_Init(1,coef),my_, coef), coef);
for(int i = k+1; i <= k_max; i++){
my->set(i,k-1,n_Div(my->view(i,k-1), my_, coef), coef);
}
}
} else {
number t = n_Div(B[k-1], B_, coef);
my->set(k,k-1,n_Mult(my_,t,coef),coef);
bigintmat * b_ = b_star[k-1];
b_star[k-1] = bimAdd(b_star[k], bimMult(b_, my_, coef));
b_star[k] = bimSub(bimMult(b_, n_Div(B[k], B_, coef),coef), bimMult( b_star[k], my->view(k,k-1), coef));
delete b_;
B[k] = n_Mult(B[k],t,coef); // n_InpMult
B[k-1] = n_Copy(B_, coef);
for(int i = k+1; i <= k_max; i++){
t = my->get(i,k);
my->set(i,k,n_Sub(my->view(i,k-1),n_Mult(my_,t,coef), coef), coef);
my->set(i,k-1,n_Add(t,n_Mult(my->view(k,k-1),my->view(i,k),coef),coef),coef);
}
}
DEBUG_PRINT(("End of SWAPG\n"));
}

## Field Documentation

## B

number* lattice::B

private

Definition at line 34 of file lattice.h.

## b

bigintmat** lattice::b

private

Definition at line 28 of file lattice.h.

## b_star

bigintmat** lattice::b_star

private

Definition at line 31 of file lattice.h.

## basis

bigintmat** lattice::basis

private

Definition at line 11 of file lattice.h.

## bound

number* lattice::bound

private

Definition at line 64 of file lattice.h.

## c

number lattice::c

private

Definition at line 25 of file lattice.h.

## coef

coeffs lattice::coef

private

Definition at line 22 of file lattice.h.

## d

number* lattice::d

private

Definition at line 43 of file lattice.h.

## gram_matrix

bigintmat* lattice::gram_matrix

private

Definition at line 14 of file lattice.h.

## H

bigintmat* lattice::H

private

Definition at line 37 of file lattice.h.

## independentVectors

bool lattice::independentVectors

private

Definition at line 52 of file lattice.h.

## integral

bool lattice::integral

private

Definition at line 55 of file lattice.h.

## m

int lattice::m

private

Definition at line 20 of file lattice.h.

## my

bigintmat* lattice::my

private

Definition at line 40 of file lattice.h.

## n

int lattice::n

private

Definition at line 17 of file lattice.h.

## out_coef

coeffs lattice::out_coef

private

Definition at line 67 of file lattice.h.

## Q

bigintmat* lattice::Q

private

Definition at line 58 of file lattice.h.

## rank

int lattice::rank

private

Definition at line 46 of file lattice.h.

## trans_matrix

bool lattice::trans_matrix

private

Definition at line 49 of file lattice.h.

## x

bigintmat* lattice::x

private

Definition at line 61 of file lattice.h.

The documentation for this class was generated from the following files:

- Singular/dyn_modules/Order/lattice.h
- Singular/dyn_modules/Order/lattice.cc