My Project
Loading...
Searching...
No Matches
Data Structures | Functions
lattice.h File Reference

Go to the source code of this file.

Data Structures

class  lattice
 

Functions

number scalarproduct (bigintmat *a, bigintmat *b)
 
bigintmatminkowksi (bigintmat **elementarray, int size_elementarray, number *poly, int deg, coeffs coef, int precision)
 
bool IsReal (number a, coeffs coef)
 
bool ImagGreaterZero (number a, coeffs coef)
 
number squareroot (number a, coeffs coef, int iteration)
 

Function Documentation

◆ ImagGreaterZero()

bool ImagGreaterZero ( number  a,
coeffs  coef 
)

Definition at line 1104 of file lattice.cc.

1104 { //Im(a)>0
1105 number imag = n_ImPart(a, coef);
1106 bool out = n_GreaterZero(imag,coef);
1107 n_Delete(&imag,coef);
1108 return out;
1109}
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:491
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition: coeffs.h:452
static FORCE_INLINE number n_ImPart(number i, const coeffs cf)
Definition: coeffs.h:790

◆ IsReal()

bool IsReal ( number  a,
coeffs  coef 
)

Definition at line 1097 of file lattice.cc.

1097 { //Im(a)==0
1098 number imag = n_ImPart(a, coef);
1099 bool out = n_IsZero(imag,coef);
1100 n_Delete(&imag,coef);
1101 return out;
1102}
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:461

◆ minkowksi()

bigintmat * minkowksi ( bigintmat **  elementarray,
int  size_elementarray,
number *  poly,
int  deg,
coeffs  coef,
int  precision 
)

Definition at line 948 of file lattice.cc.

948 {
949 DEBUG_BLOCK(true);
950 DEBUG_PRINT(("Begin Minkowski map\n"));
951 DEBUG_PRINT(("Input check\n"));
952 if(elementarray == NULL || poly == NULL || coef != elementarray[0]->basecoeffs()){
953 WerrorS("wrong input!\n");
954 return NULL;
955 }
956
957 for(int i=1;i<size_elementarray;i++){
958 if(coef != elementarray[0]->basecoeffs()){
959 WerrorS("wrong input!\n");
960 return NULL;
961 }
962 }
963
964 //char = 0
965 if ( !(nCoeff_is_Z(coef) || nCoeff_is_R(coef) || nCoeff_is_Q(coef) ||
966 nCoeff_is_long_R(coef) || nCoeff_is_long_C(coef)) ){
967 WerrorS("Ground field not implemented!\n");
968 return NULL;
969 }
970
971 if(deg<2){
972 WerrorS("degree of polynomial to small\n");
973 return NULL;
974 }
975 //check and define precision for Q
976 if(precision<6){
977 precision = 6;
978 }
979 if ( !(nCoeff_is_R(coef) || nCoeff_is_long_R(coef) || nCoeff_is_long_C(coef)) ){
980 setGMPFloatDigits( precision+6,precision+6);
981 }
982
983 DEBUG_PRINT(("find roots\n"));
984 ring CurrOldRing = rCopy(currRing);//need to change currRing, because rootContainer uses the coef of it
985 char* n[] = {(char*)"i"};
986 ring newring = rDefault(coef, 1, n);
987 rChangeCurrRing(newring);
988 DEBUG_PRINT(("initialize rootContainer\n"));
989 rootContainer * rootcont= new rootContainer();
990 rootcont->fillContainer( poly, NULL, 1, deg, rootContainer::onepoly, 1 );///
991 rootcont->solver( precision+12);
992 int number_roots = rootcont ->getAnzRoots();
993 if(number_roots != deg){
994 WerrorS("something went wrong: \n\tnot all roots found\n");
995 return NULL;
996 }
997 LongComplexInfo paramComp;
998 paramComp.float_len = si_min (precision+6, 32767);
999 paramComp.float_len2 = si_min (precision+8, 32767);
1000 paramComp.par_name=(const char*)"i";
1001
1002 coeffs comp = nInitChar(n_long_C, &paramComp);
1003
1004 number* roots = new number[deg+1];
1005 number* complexroots = new number[deg+1];
1006 int r1 = 0;
1007 int r2 = 0;
1008 for(int j=0; j<deg; j++){
1009 number a = n_Copy((number)(rootcont->getRoot(j)),comp);
1010 if( IsReal(a,comp)){
1011 roots[r1] = n_Copy(a,comp);
1012 r1++;
1013 }else if(ImagGreaterZero(a, comp)){
1014 complexroots[r2] = n_Copy(a,comp);
1015 r2++;
1016 }
1017 n_Delete(&a,comp);
1018 }
1019 rChangeCurrRing(CurrOldRing);
1020 DEBUG_PRINT(("delete some variables\n"));
1021 rDelete(newring);
1022 delete &n;
1023 //delete rootcont;DEBUG_PRINT(("can't delete rootcontainer rootcont\n"));
1024 DEBUG_VAR(r1);
1025 DEBUG_VAR(r2);
1026 for(int j=0;j<r2;j++){
1027 roots[r1+j]= n_Copy(complexroots[j],comp);
1028 n_Delete(&complexroots[j],comp);
1029 }
1030 delete complexroots;
1031 DEBUG_PRINT(("map elementarray to complex\n"));
1032 bigintmat ** elements = new bigintmat*[size_elementarray];
1033 for(int i=0;i<size_elementarray;i++){
1034 elements[i] = bimChangeCoeff(elementarray[i],comp);
1035 }
1036 DEBUG_PRINT(("generate output matrix\n"));
1037 DEBUG_PRINT(("real part\n"));
1038 bigintmat * complexmat = new bigintmat(r1+2*r2,size_elementarray,comp);
1039 for(int i=1; i<= r1; i++){
1040 number pot = n_Init(1,comp);
1041 for(int l=0; l< deg; l++){
1042 for(int j=0; j<size_elementarray;j++){
1043 number mult = n_Mult(pot,elements[j]->view(l),comp);
1044 complexmat->rawset(i,j+1,n_Add(complexmat->view(i,j+1),mult,comp),comp);
1045 n_Delete(&mult,comp);
1046 }
1047 n_InpMult(pot, roots[i-1],comp);
1048 }
1049 n_Delete(&pot,comp);
1050 }
1051 DEBUG_PRINT(("imaginary part\n"));
1052 number sqrt2 = n_Init(1,comp);
1053 if(r2>0){
1054 number two = n_Init(2,comp);
1055 number sqrt2 = squareroot(two,comp,precision+10);
1056 n_Delete(&two,comp);
1057 for(int i=1; i<= r2; i++){
1058 number pot = n_Init(1,comp);
1059 for(int l=0; l< deg; l++){
1060 for(int j=0; j<size_elementarray;j++){
1061 number mult = n_Mult(pot,elements[j]->view(l),comp);
1062 complexmat->rawset(r1+2*i,j+1,n_Add(complexmat->view(r1+2*i,j+1),mult,comp),comp);
1063 n_Delete(&mult,comp);
1064 }
1065 n_InpMult(pot, roots[i-1],comp);
1066 }
1067 n_Delete(&pot,comp);
1068 for(int j=1;j<=size_elementarray;j++){
1069 complexmat->set(r1+2*i,j,n_Mult(complexmat->view(r1+2*i,j),sqrt2,comp),comp);
1070 complexmat->set(r1+2*i-1,j,n_RePart(complexmat->view(r1+2*i,j),comp),comp);
1071 complexmat->set(r1+2*i,j,n_ImPart(complexmat->view(r1+2*i,j),comp),comp);
1072 }
1073 }
1074 }
1075 DEBUG_PRINT(("delete Variables\n"));
1076 for(int i=0;i<size_elementarray;i++){
1077 delete elements[i];
1078 }
1079 delete elements;
1080 for(int i=0;i<r1+r2;i++){
1081 n_Delete(&roots[i],comp);
1082 }
1083 delete roots;
1084
1085 DEBUG_PRINT(("to real\n"));
1086 LongComplexInfo paramReal;
1087 paramReal.float_len = si_min (precision, 32767);
1088 paramReal.float_len2 = si_min (precision, 32767);
1089 paramComp.par_name=(const char*)"i";
1090 coeffs real = nInitChar(n_long_R, &paramReal);
1091 //setGMPFloatDigits( precision, precision);
1092 bigintmat * realmat = bimChangeCoeff(complexmat,real);
1093 delete complexmat;
1094 return realmat;
1095}
static int si_min(const int a, const int b)
Definition: auxiliary.h:125
bigintmat * bimChangeCoeff(bigintmat *a, coeffs cnew)
Liefert Kopier von Matrix a zurück, mit coeffs cnew statt den ursprünglichen.
Definition: bigintmat.cc:1804
int l
Definition: cfEzgcd.cc:100
int i
Definition: cfEzgcd.cc:132
Matrices of numbers.
Definition: bigintmat.h:51
number view(int i, int j) const
view an entry an entry. NOTE: starts at [1,1]
Definition: bigintmat.cc:127
void rawset(int i, number n, const coeffs C=NULL)
replace an entry with the given number n (only delete old). NOTE: starts at [0]. Should be named set_...
Definition: bigintmat.h:196
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:95
complex root finder for univariate polynomials based on laguers algorithm
Definition: mpr_numeric.h:66
gmp_complex * getRoot(const int i)
Definition: mpr_numeric.h:88
void fillContainer(number *_coeffs, number *_ievpoint, const int _var, const int _tdg, const rootType _rt, const int _anz)
Definition: mpr_numeric.cc:300
int getAnzRoots()
Definition: mpr_numeric.h:97
bool solver(const int polishmode=PM_NONE)
Definition: mpr_numeric.cc:437
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:633
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
Definition: coeffs.h:448
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:647
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition: coeffs.h:813
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:888
@ n_long_R
real floating point (GMP) numbers
Definition: coeffs.h:33
@ n_long_C
complex floating point (GMP) numbers
Definition: coeffs.h:41
short float_len2
additional char-flags, rInit
Definition: coeffs.h:102
const char * par_name
parameter name
Definition: coeffs.h:103
static FORCE_INLINE number n_RePart(number i, const coeffs cf)
Definition: coeffs.h:787
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition: coeffs.h:803
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:413
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:535
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:638
short float_len
additional char-flags, rInit
Definition: coeffs.h:101
static FORCE_INLINE BOOLEAN nCoeff_is_R(const coeffs r)
Definition: coeffs.h:833
static FORCE_INLINE BOOLEAN nCoeff_is_long_C(const coeffs r)
Definition: coeffs.h:891
int j
Definition: facHensel.cc:110
int comp(const CanonicalForm &A, const CanonicalForm &B)
compare polynomials
void WerrorS(const char *s)
Definition: feFopen.cc:24
bool IsReal(number a, coeffs coef)
Definition: lattice.cc:1097
#define DEBUG_VAR(x)
Definition: lattice.cc:35
number squareroot(number a, coeffs coef, int prec)
Definition: lattice.cc:1111
#define DEBUG_BLOCK(x)
Definition: lattice.cc:29
bool ImagGreaterZero(number a, coeffs coef)
Definition: lattice.cc:1104
#define DEBUG_PRINT(x)
Definition: lattice.cc:33
void mult(unsigned long *result, unsigned long *a, unsigned long *b, unsigned long p, int dega, int degb)
Definition: minpoly.cc:647
void setGMPFloatDigits(size_t digits, size_t rest)
Set size of mantissa digits - the number of output digits (basis 10) the size of mantissa consists of...
Definition: mpr_complex.cc:60
The main handler for Singular numbers which are suitable for Singular polynomials.
#define NULL
Definition: omList.c:12
void rChangeCurrRing(ring r)
Definition: polys.cc:15
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:450
ring rDefault(const coeffs cf, int N, char **n, int ord_size, rRingOrder_t *ord, int *block0, int *block1, int **wvhdl, unsigned long bitmask)
Definition: ring.cc:102
ring rCopy(ring r)
Definition: ring.cc:1731
static void view(const intvec *v)
Definition: mod_main.cc:189

◆ scalarproduct()

number scalarproduct ( bigintmat a,
bigintmat b 
)
inline

Definition at line 915 of file lattice.cc.

915 {
916 if(a->cols()!=1) {
917 Werror("a->cols()!=1 in scalarproduct(a,b)\n");
918 return NULL;
919 }
920 if(b->cols()!=1) {
921 Werror("b->cols()!=1 in scalarproduct(a,b)\n");
922 return NULL;
923 }
924 if(a->rows()!=b->rows()) {
925 Werror("b->cols()!=1 in scalarproduct(a,b)\n");
926 return NULL;
927 }
928 if(a->basecoeffs()!=b->basecoeffs()) {
929 Werror("a->basecoeffs()!=b->basecoeffs() in scalarproduct(a,b)\n");
930 return NULL;
931 }
932
933 coeffs coef = a->basecoeffs();
934 number p = n_Init(0,coef);
935 for(int i = 1; i <= b->rows(); i++){
936 number prod = n_Mult(a->view(i,1), b->view(i,1), coef);
937 n_InpAdd(p, prod, coef);
938 n_Delete(&prod,coef);
939 }
940 return p;
941}
int p
Definition: cfModGcd.cc:4078
CanonicalForm b
Definition: cfModGcd.cc:4103
int cols() const
Definition: bigintmat.h:144
int rows() const
Definition: bigintmat.h:145
coeffs basecoeffs() const
Definition: bigintmat.h:146
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:643
fq_nmod_poly_t prod
Definition: facHensel.cc:100
void Werror(const char *fmt,...)
Definition: reporter.cc:189

◆ squareroot()

number squareroot ( number  a,
coeffs  coef,
int  iteration 
)

Definition at line 1111 of file lattice.cc.

1111 {
1112 if(n_IsZero(a,coef)){
1113 return a;
1114 }
1115 if(!n_GreaterZero(a,coef)){
1116 return n_Init(0,coef);
1117 }
1118 number two = n_Init(2,coef);
1119 number xn = n_Copy(a,coef);
1120 number xn1,xn2;
1121 for(int i=0;i<prec;i++){
1122 xn1 = n_Div(a,xn,coef);
1123 xn2 = n_Add(xn,xn1,coef);
1124 n_Delete(&xn,coef);
1125 xn = n_Div(xn2,two,coef);
1126 n_Delete(&xn1,coef);
1127 n_Delete(&xn2,coef);
1128 }
1129 return xn;
1130}
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:612
VAR int xn
Definition: walk.cc:4508