// matrix.cc // implementation of class matrix #ifndef MATRIX_CC #define MATRIX_CC #include "matrix.h" ////////////// constructors and destructor ////////////////////////////////// typedef Integer* IntegerP; typedef BigInt* BigIntP; matrix::matrix(const short& row_number, const short& column_number) :rows(row_number),columns(column_number) { _kernel_dimension=-2; // LLL-algorithm not yet performed // argument check if((rows<=0)||(columns<=0)) // bad input, set "error flag" { cerr<<"\nWARNING: matrix::matrix(const short&, const short&):\n" "argument out of range"<>rows; if(!input) // input failure, set "error flag" { cerr<<"\nWARNING: matrix::matrix(ifstream&): input failure"<>columns; if(!input) // input failure, set "error flag" { cerr<<"\nWARNING: matrix::matrix(ifstream&): input failure"<>coefficients[i][j]; if(!input) // bad input, set error flag { cerr<<"\nWARNING: matrix::matrix(ifstream&): input failure"<>coefficients[i][j]; if(!input) // bad input, set error flag { columns=-2; return; } } } matrix::matrix(const matrix& A) :rows(A.rows),columns(A.columns),_kernel_dimension(A._kernel_dimension) { if(columns<0) { cerr<<"\nWARNING: matrix::matrix(const matrix&):\n" "Building a matrix from a corrupt one"<0) { H=new BigIntP[_kernel_dimension]; for(short k=0;k<_kernel_dimension;k++) H[k]=new BigInt[columns]; for(short k=0;k<_kernel_dimension;k++) for(short j=0;j0) // LLL-algorithm performed { for(short i=0;i<_kernel_dimension;i++) delete[] H[i]; delete[] H; } } //////////////////// object properties ////////////////////////////////////// BOOLEAN matrix::is_nonnegative() const { for(short i=0;iBigInt(0)) if(min_index==-1) min_index=i; else if(M[i] desired vector does not exist return 0; // add the square of the norm to the vectors with the least common zero // components // discard the others for(short i=current_position;i<_kernel_dimension;i++) if(M[i]!=min) M[i]=-1; else for(short j=0;jBigInt(0)) if(min_index==0) min_index=i; else if(M[i]columns) // more negative than positive components in H[0] // all variables corresponding to positive components will be flipped { r=columns-r; F=new short[r]; memset(F,0,r*sizeof(short)); short counter=0; for(short j=0;j BigInt(0)) { F[counter]=j; counter++; } } else // more (or as many) positive than negative components in v // all variables corresponding to negative components will be flipped { F=new short[r]; memset(F,0,r*sizeof(short)); short counter=0; for(short j=0;j which is already staurated return 0; short number_of_sat_var=0; sat_var=new short[columns/2]; memset(sat_var,0,sizeof(short)*(columns/2)); BOOLEAN* ideal_saturated_by_var=new BOOLEAN[columns]; // auxiliary array used to remember by which variables the ideal has still to // be saturated for(short j=0;j BigInt(0)) pos_sat_var++; else if(H[k][j]< BigInt(0)) neg_sat_var++; } } // now add the smaller set to the saturation variables if(pos_sat_var<=neg_sat_var) { for(short j=0;j BigInt(0)) // ideal has to be saturated by the variables corresponding // to positive components { sat_var[number_of_sat_var]=j; ideal_saturated_by_var[j]=TRUE; number_of_sat_var++; } else if(H[k][j]< BigInt(0)) // then the ideal is automatically saturated by the variables // corresponding to negative components ideal_saturated_by_var[j]=TRUE; } else { for(short j=0;j BigInt(0)) // then the ideal is automatically saturated by the variables // corresponding to positive components ideal_saturated_by_var[j]=TRUE; } } // clean up memory delete[] ideal_saturated_by_var; return number_of_sat_var; } //////////////////// output /////////////////////////////////////////////// void matrix::print() const { printf("\n%3d x %3d\n",rows,columns); for(short i=0;i