Changeset 6e338f in git
- Timestamp:
- Jan 31, 2014, 8:16:13 PM (10 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'fc741b6502fd8a97288eaa3eba6e5220f3c3df87')
- Children:
- b933aa2fe9e404c447f02411a78e2abe2d885e9c
- Parents:
- c274a029c85d80fc1e67a20a94756f2afdcefd08
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/hilb.cc
rc274a0 r6e338f 30 30 static int hLength; 31 31 //ADICHANGES 32 static int NNN;33 static mpz_t ec;34 static mpz_ptr hilbertcoef = (mpz_ptr)omAlloc(NNN*sizeof(mpz_t));35 static std::vector<int> hilbertpowers;36 static std::vector<int> hilbertpowerssorted;37 32 static std::vector<int> degsort; 38 static std::vector<int> eulerprop;39 static ideal eulersimp;40 static int steps, prune = 0, moreprune = 0, eulerstep, eulerskips=0;41 33 42 34 … … 294 286 idPrint(res);*/ 295 287 return(res); 296 }297 298 //puts in hilbertpowerssorted the two new entries and shifts if needed the old ones299 static void PutInVector(int degvalue, int oldposition, int where)300 {301 hilbertpowerssorted.resize(hilbertpowerssorted.size()+2);302 int i;303 for(i=hilbertpowerssorted.size()-1;i>=where+2;i--)304 {305 hilbertpowerssorted[i] = hilbertpowerssorted[i-2];306 }307 hilbertpowerssorted[where] = degvalue;308 hilbertpowerssorted[where+1] = oldposition;309 }310 311 //sorts hilbertpowers (new finds the positions)312 static void SortPowerVec()313 {314 int i,j;315 int test;316 bool flag;317 //printf("Size of hilbertpowers: %i", hilbertpowers.size());318 hilbertpowerssorted.resize(2);319 hilbertpowerssorted[0] = hilbertpowers[0];320 hilbertpowerssorted[1] = 0;321 for(i=1;i<hilbertpowers.size();i++)322 {323 flag=TRUE;324 if(hilbertpowers[i]<=hilbertpowerssorted[0])325 {326 flag=FALSE;327 PutInVector(hilbertpowers[i], i, 0);328 }329 if((hilbertpowers[i]>=hilbertpowerssorted[hilbertpowerssorted.size()-2]) && (flag == TRUE))330 {331 flag=FALSE;332 PutInVector(hilbertpowers[i], i, hilbertpowerssorted.size()-2);333 }334 if(flag==TRUE)335 {336 for(j=2;(j<=hilbertpowerssorted.size()-4)&&(flag);j=j+2)337 {338 if(hilbertpowers[i]<=hilbertpowerssorted[j])339 {340 flag=FALSE;341 PutInVector(hilbertpowers[i], i, j);342 }343 }344 }345 }346 288 } 347 289 … … 483 425 return(I); 484 426 } 485 486 #if 0487 //Constructs a list of the simplices (for which we have to compute the Euler Characteristic)488 static void eulerSimpAdd(ideal newsimp)489 {490 if(idIs0(newsimp))491 {492 return;493 }494 ideal P;495 int i;496 bool flag;497 P = idInit(1,1);498 for(i=0;i<IDELEMS(newsimp);i++)499 {500 P->m[0] = pAdd(P->m[0], pCopy(newsimp->m[i]));501 }502 poly p = pCopy(P->m[0]);503 //idPrint(eulersimp);504 //idPrint(newsimp);505 //idPrint(P);506 int terms = 0, deg = 0, howmanyvars = 0;507 terms = IDELEMS(newsimp);508 deg = DegMon(newsimp->m[0]);509 flag=TRUE;510 for(i=1;(i<IDELEMS(newsimp))&&(flag==TRUE);i++)511 {512 513 if(deg != DegMon(newsimp->m[i]))514 {515 //The ideal is not homogenous516 flag=FALSE;517 }518 }519 if(!flag)520 {521 deg = 0;522 }523 int* e;524 howmanyvars = pGetVariables(p, e);525 flag = FALSE;526 int thisone;527 //idPrint(eulersimp);528 if(idIs0(eulersimp))529 {530 eulersimp = idAddMon(eulersimp, P);531 eulerprop.resize(eulerprop.size()+3);532 eulerprop[eulerprop.size()-3] = terms ;533 eulerprop[eulerprop.size()-2] = deg ;534 eulerprop[eulerprop.size()-1] = howmanyvars ;535 return;536 }537 //for(i=0;i<IDELEMS(eulersimp);i++)538 //{539 // printf("\n%i %i %i\n",eulerprop[3*i],eulerprop[3*i+1],eulerprop[3*i+2]);540 //}541 i=0;542 543 for(i = 0; (i<IDELEMS(eulersimp)) && (!flag);i++)544 {545 if((eulerprop[3*i] == terms) && (eulerprop[3*i+1] == deg) && (eulerprop[3*i+2] == howmanyvars))546 {547 // !!!!!!!!!!!!!!!!!!!have to do it!!!!!!!!!!!!!!!!!!!!!!!!!!548 //if(TestIfIsSame(p, eulersimp->m[i]))549 {550 flag = TRUE;551 thisone = i;552 //It is the the same simplex, and hence we already know it's euler characteristic553 }554 }555 }556 if(!flag)557 {558 eulersimp = idAddMon(eulersimp, P);559 eulerprop.resize(eulerprop.size()+3);560 eulerprop[eulerprop.size()-3] = terms ;561 eulerprop[eulerprop.size()-2] = deg ;562 eulerprop[eulerprop.size()-1] = howmanyvars ;563 }564 if(flag)565 {566 eulerskips++;567 hilbertcoef = (mpz_ptr)omRealloc(hilbertcoef, (NNN+1)*sizeof(mpz_t));568 mpz_init(&hilbertcoef[NNN]);569 mpz_set(&hilbertcoef[NNN], &hilbertcoef[thisone]);570 hilbertpowers.resize(NNN+1);571 NNN++;572 }573 return;574 }575 #endif576 427 577 428 //searches for a variable that is not yet used (assumes that the ideal is sqrfree) … … 921 772 922 773 //computes the Euler Characteristic of the ideal 923 static void eulerchar (ideal I, int variables )774 static void eulerchar (ideal I, int variables, mpz_ptr ec) 924 775 { 925 776 loop 926 777 { 927 //idPrint(I);printf("%i", variables);928 eulerstep++;929 778 mpz_t dummy; 930 779 if(JustVar(I) == TRUE) … … 944 793 ideal p = idInit(1,1); 945 794 p->m[0] = SearchP(I); 946 //pWrite(p->m[0]);947 795 ideal Ip = idQuotMon(I,p); 948 796 Ip = SortByDeg(Ip); … … 955 803 } 956 804 } 957 eulerchar(Ip, variables-howmanyvarinp );805 eulerchar(Ip, variables-howmanyvarinp, ec); 958 806 id_Delete(&Ip, currRing); 959 //ideal Iplusp = idAddMon(I,p);960 //eulerchar(Iplusp, variables);961 //id_Delete(&Iplusp, currRing);962 //return;963 807 I = idAddMon(I,p); 964 808 } … … 1013 857 return(FALSE); 1014 858 } 1015 //if(DegMon(p)<DegMon(I->m[IDELEMS(I)-1]))1016 //{1017 // return(FALSE);1018 //}1019 #if 01020 if(p == NULL)1021 {1022 if(IDELEMS(I) == 0)1023 {1024 return(TRUE);1025 }1026 if(IDELEMS(I) == 1)1027 {1028 if(I->m[0] == poly(0))1029 {1030 return(TRUE);1031 }1032 }1033 return(FALSE);1034 }1035 if(IDELEMS(I)==0)1036 {1037 return(FALSE);1038 }1039 if(IDELEMS(I) == 1)1040 {1041 if(I->m[0] == poly(0))1042 {1043 return(FALSE);1044 }1045 }1046 #endif1047 859 int i,j; 1048 860 bool flag; … … 1091 903 } 1092 904 1093 #if 01094 //return TRUE if a | b, a, b monomials1095 static bool Divides(poly a, poly b)1096 {1097 if(a == NULL)1098 {1099 return(FALSE);1100 }1101 if(b == NULL)1102 {1103 return(TRUE);1104 }1105 int i;1106 for(i=1;i<=currRing->N;i++)1107 {1108 if(p_GetExp(a,i,currRing) > p_GetExp(b,i,currRing))1109 {1110 return(FALSE);1111 }1112 }1113 return(TRUE);1114 }1115 #endif1116 1117 905 //the Roune Slice Algorithm 1118 void rouneslice(ideal I, ideal S, poly q, poly x )906 void rouneslice(ideal I, ideal S, poly q, poly x, int &prune, int &moreprune, int &steps, int &NNN, mpz_ptr &hilbertcoef, int* &hilbpower) 1119 907 { 1120 908 loop 1121 909 { 1122 steps++;910 (steps)++; 1123 911 int i,j; 1124 912 int dummy; 1125 mpz_t dummympz;1126 913 poly m; 1127 914 clock_t t; … … 1134 921 if(IsIn(S->m[i],I)) 1135 922 { 1136 //idPrint(I);idPrint(S);getchar();1137 923 S->m[i]=NULL; 1138 924 prune++; … … 1159 945 } 1160 946 p_Setm(m, currRing); 1161 //printf("\n Check if m is in S: %i\n", IsIn(m,S));pWrite(m);idPrint(S);1162 947 if(IsIn(m,S)) 1163 948 { 1164 //printf("\nIt was deleted: \n");pWrite(I->m[i]);1165 949 I->m[i]=NULL; 1166 950 //printf("\n Deleted, since pi(m) is in S\n");pWrite(m); … … 1210 994 if(idIs0(I)) 1211 995 { 1212 /*if(!pIsConstantPoly(q))1213 {1214 mpz_init(dummympz);1215 mpz_set_si(dummympz, -1);1216 hilbertcoef = (mpz_ptr)omRealloc(hilbertcoef, (NNN+1)*sizeof(mpz_t));1217 mpz_init(&hilbertcoef[NNN]);1218 mpz_set(&hilbertcoef[NNN], dummympz);1219 hilbertpowers.resize(NNN+1);1220 hilbertpowers[NNN] = DegMon(q);1221 NNN++;1222 pWrite(q);1223 //printf("\nOld ERROR\n");getchar();1224 }*/1225 996 id_Delete(&I, currRing); 1226 997 id_Delete(&S, currRing); 1227 998 p_Delete(&m, currRing); 1228 999 break; 1229 //return;1230 1000 } 1231 1001 S = SortByDeg(S); … … 1234 1004 { 1235 1005 //printf("\nx does not divide lcm(I)"); 1236 //pWrite(x);pWrite(m);idPrint(I);1237 1006 //printf("\nEmpty set");pWrite(q); 1238 //idPrint(S);pWrite(q);1239 //getchar();1240 1007 id_Delete(&I, currRing); 1241 1008 id_Delete(&S, currRing); … … 1254 1021 { 1255 1022 koszsimp->m[i] = I->m[i]; 1256 //pWrite(koszsimp->m[i]);1257 /*for(j = 1;j<=currRing->N;j++)1258 {1259 if(p_GetExp(koszsimp->m[i],j,currRing)!=0)1260 {1261 p_SetExp(koszsimp->m[i],j,0,currRing);1262 }1263 else1264 {1265 p_SetExp(koszsimp->m[i],j,1,currRing);1266 }1267 }*/1268 //pWrite(koszsimp->m[i]);1269 1023 } 1270 1024 //idPrint(koszsimp); 1271 1025 //getchar(); 1272 1026 //printf("\n Euler Characteristic = "); 1273 mpz_init(dummympz);1274 1027 t = clock(); 1275 eulerstep=0;1276 1028 //idPrint(koszsimp); 1277 1029 //getchar(); 1278 eulerchar(koszsimp, currRing->N); 1279 if(((float)(clock()-t)/CLOCKS_PER_SEC)!=0) 1280 { 1281 //printf("\nEulerChar took %f \n",(float)(clock()-t)/CLOCKS_PER_SEC); 1282 //idPrint(koszsimp);getchar(); 1283 } 1284 //printf("\nEulerChar tooked %i steps\n", eulerstep); 1285 //gmp_printf("dummy %Zd \n", dummympz); 1286 //gmp_printf("ec %Zd \n", ec); 1030 mpz_t ec; 1031 mpz_init(ec); 1032 mpz_ptr ec_ptr = ec; 1033 eulerchar(koszsimp, currRing->N, ec_ptr); 1034 bool flag = FALSE; 1035 if(NNN==0) 1036 { 1037 hilbertcoef = (mpz_ptr)omAlloc((NNN+1)*sizeof(mpz_t)); 1038 hilbpower = (int*)omAlloc((NNN+1)*sizeof(int)); 1039 mpz_init( &hilbertcoef[NNN]); 1040 mpz_set( &hilbertcoef[NNN], ec); 1041 mpz_clear(ec); 1042 hilbpower[NNN] = DegMon(q); 1043 NNN++; 1044 } 1045 else 1046 { 1047 //I look if the power appears already 1048 for(i = 0;(i<NNN)&&(flag == FALSE)&&(DegMon(q)>=hilbpower[i]);i++) 1049 { 1050 if((hilbpower[i]) == (DegMon(q))) 1051 { 1052 flag = TRUE; 1053 mpz_add(&hilbertcoef[i],&hilbertcoef[i],ec_ptr); 1054 } 1055 } 1056 if(flag == FALSE) 1057 { 1058 hilbertcoef = (mpz_ptr)omRealloc(hilbertcoef, (NNN+1)*sizeof(mpz_t)); 1059 hilbpower = (int*)omRealloc(hilbpower, (NNN+1)*sizeof(int)); 1060 mpz_init(&hilbertcoef[NNN]); 1061 for(j = NNN; j>i; j--) 1062 { 1063 mpz_set(&hilbertcoef[j],&hilbertcoef[j-1]); 1064 hilbpower[j] = hilbpower[j-1]; 1065 } 1066 mpz_set( &hilbertcoef[i], ec); 1067 mpz_clear(ec); 1068 hilbpower[i] = DegMon(q); 1069 NNN++; 1070 } 1071 } 1072 #if 0 1073 for(i = 0; i<NNN; i++) 1074 { 1075 gmp_printf("\n// %8Zd t^%d",&hilbertcoef[i],hilbpower[i]); 1076 } 1077 printf("\n"); 1287 1078 //getchar(); 1288 //if(DegMon(q)==7) {getchar();} 1289 mpz_set(dummympz, ec); 1290 mpz_sub(ec, ec, ec); 1291 hilbertcoef = (mpz_ptr)omRealloc(hilbertcoef, (NNN+1)*sizeof(mpz_t)); 1292 mpz_init(&hilbertcoef[NNN]); 1293 mpz_set(&hilbertcoef[NNN], dummympz); 1294 mpz_clear(dummympz); 1295 hilbertpowers.resize(NNN+1); 1296 hilbertpowers[NNN] = DegMon(q); 1297 NNN++; 1079 #endif 1298 1080 break; 1299 //return;1300 1081 } 1301 1082 m = ChooseP(I); 1302 1083 p = idInit(1,1); 1303 1084 p->m[0] = m; 1304 //idPrint(I);idPrint(p);1305 //idTest(I);idTest(p);1306 1085 ideal Ip = idQuotMon(I,p); 1307 1086 Ip = SortByDeg(Ip); 1308 1087 ideal Sp = idQuotMon(I,p); 1309 1088 Sp = SortByDeg(Sp); 1310 //printf("\np, q = \n");pWrite(m);pWrite(q);1311 1089 poly pq = pp_Mult_mm(q,m,currRing); 1312 rouneslice(Ip, Sp, pq, x); 1313 //idPrint(Ip); 1314 //id_Delete(&Ip, currRing); 1315 //id_Delete(&Sp, currRing); 1090 rouneslice(Ip, Sp, pq, x, prune, moreprune, steps, NNN, hilbertcoef,hilbpower); 1091 id_Delete(&Ip, currRing); 1092 id_Delete(&Sp, currRing); 1316 1093 S = idAddMon(S,p); 1317 //p->m[0]=NULL; id_Delete(&p, currRing); // p->m[0] was also in S 1094 p->m[0]=NULL; 1095 id_Delete(&p, currRing); // p->m[0] was also in S 1318 1096 p_Delete(&pq,currRing); 1319 //Splusp = idSimplify(Splusp); 1320 // rouneslice(I, S, q, x); tail-recursion solved via loop 1321 1322 //id_Delete(&Splusp, currRing); 1323 //return; 1324 } 1325 } 1326 1097 } 1098 } 1327 1099 1328 1100 //it computes the first hilbert series by means of Roune Slice Algorithm … … 1331 1103 I = SortByDeg(I); 1332 1104 printf("Adi changes are here: \n"); 1333 int i; 1334 eulersimp = idInit(1,1); 1105 int i, NNN = 0; 1106 int steps = 0, prune = 0, moreprune = 0; 1107 mpz_ptr hilbertcoef; 1108 int *hilbpower; 1335 1109 ideal S = idInit(1,1); 1336 1110 poly q = p_ISet(1,currRing); … … 1344 1118 I = id_Mult(I,X,currRing); 1345 1119 printf("\n-------------RouneSlice--------------\n"); 1346 steps=0; 1347 rouneslice(I,S,q,X->m[0]); 1120 rouneslice(I,S,q,X->m[0],prune, moreprune, steps, NNN, hilbertcoef, hilbpower); 1348 1121 printf("\nIn total Prune got rid of %i elements\n",prune); 1349 1122 printf("\nIn total More Prune got rid of %i elements\n",moreprune); 1350 //printf("\nWe skipped computing the EulerChar for %i simplices\n",eulerskips);1351 1123 printf("\nSteps of rouneslice: %i\n\n", steps); 1352 /*for(i=0;i<NNN;i++)1353 {1354 gmp_printf(" %Zd ", &hilbertcoef[i]);1355 }1356 printf("\n");1357 for(i=0;i<NNN;i++)1358 {1359 printf(" %d ", hilbertpowers[i]);1360 }*/1361 SortPowerVec();1362 /*printf("\n");1363 for(i=0;i<hilbertpowerssorted.size();i++)1364 {1365 printf(" %d ", hilbertpowerssorted[i]);1366 }*/1367 1124 mpz_t coefhilb; 1368 1125 mpz_t dummy; … … 1370 1127 mpz_init(dummy); 1371 1128 printf("\n// %8d t^0",1); 1372 for(i=0;i<hilbertpowerssorted.size();i=i+2) 1373 { 1374 mpz_set(dummy, &hilbertcoef[hilbertpowerssorted[i+1]]); 1375 mpz_add(coefhilb, coefhilb, dummy); 1376 while((hilbertpowerssorted[i]==hilbertpowerssorted[i+2]) && (i<=hilbertpowerssorted.size()-2)) 1377 { 1378 i=i+2; 1379 mpz_add(coefhilb, coefhilb, &hilbertcoef[hilbertpowerssorted[i+1]]); 1380 } 1381 if(mpz_sgn(coefhilb)!=0) 1382 { 1383 gmp_printf("\n// %8Zd t^%d",coefhilb,hilbertpowerssorted[i]); 1384 } 1385 mpz_sub(coefhilb, coefhilb, coefhilb); 1386 } 1387 omFreeSize(hilbertcoef, NNN*sizeof(mpz_t)); 1129 for(i = 0; i<NNN; i++) 1130 { 1131 if(mpz_sgn(&hilbertcoef[i])!=0) 1132 { 1133 gmp_printf("\n// %8Zd t^%d",&hilbertcoef[i],hilbpower[i]); 1134 } 1135 } 1136 omFreeSize(hilbertcoef, (NNN)*sizeof(mpz_t)); 1137 omFreeSize(hilbpower, (NNN)*sizeof(int)); 1388 1138 printf("\n-------------------------------------\n"); 1389 1139 }
Note: See TracChangeset
for help on using the changeset viewer.