Changeset a2d993 in git for libpolys/polys/simpleideals.cc
- Timestamp:
- Apr 15, 2011, 11:32:40 AM (13 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 3d65bed222aced007a5c042b50c9f815f724b2e5
- Parents:
- 2f5547f23ef54968be591558663090e0f192f644
- git-author:
- Hans Schoenemann <hannes@mathematik.uni-kl.de>2011-04-15 11:32:40+02:00
- git-committer:
- Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:30:33+01:00
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/polys/simpleideals.cc
r2f5547 ra2d993 14 14 #include <omalloc/omalloc.h> 15 15 #include <polys/monomials/p_polys.h> 16 #include <polys/weight.h> 17 #include <polys/matpol.h> 16 18 #include <misc/intvec.h> 17 19 #include <polys/simpleideals.h> 20 #include "sbuckets.h" 18 21 19 22 static poly * idpower; … … 790 793 791 794 /*2 792 *the minimal index of used variables - 1793 */794 int p_LowVar (poly p, const ring r)795 {796 int k,l,lex;797 798 if (p == NULL) return -1;799 800 k = 32000;/*a very large dummy value*/801 while (p != NULL)802 {803 l = 1;804 lex = p_GetExp(p,l,r);805 while ((l < rVar(r)) && (lex == 0))806 {807 l++;808 lex = p_GetExp(p,l,r);809 }810 l--;811 if (l < k) k = l;812 pIter(p);813 }814 return k;815 }816 817 /*2818 795 *initialized a field with r numbers between beg and end for the 819 796 *procedure idNextChoise … … 1085 1062 // return id; 1086 1063 //} 1087 static void id NextPotence(ideal given, ideal result,1088 int begin, int end, int deg, int restdeg, poly ap )1064 static void id_NextPotence(ideal given, ideal result, 1065 int begin, int end, int deg, int restdeg, poly ap, const ring r) 1089 1066 { 1090 1067 poly p; 1091 1068 int i; 1092 1069 1093 p = p Power(pCopy(given->m[begin]),restdeg);1070 p = p_Power(p_Copy(given->m[begin],r),restdeg,r); 1094 1071 i = result->nrows; 1095 result->m[i] = p Mult(pCopy(ap),p);1072 result->m[i] = p_Mult_q(p_Copy(ap,r),p,r); 1096 1073 //PrintS("."); 1097 1074 (result->nrows)++; … … 1104 1081 for (i=restdeg-1;i>0;i--) 1105 1082 { 1106 p = p Power(pCopy(given->m[begin]),i);1107 p = p Mult(pCopy(ap),p);1108 id NextPotence(given, result, begin+1, end, deg, restdeg-i, p);1109 p Delete(&p);1110 } 1111 id NextPotence(given, result, begin+1, end, deg, restdeg, ap);1083 p = p_Power(p_Copy(given->m[begin],r),i,r); 1084 p = p_Mult_q(p_Copy(ap,r),p,r); 1085 id_NextPotence(given, result, begin+1, end, deg, restdeg-i, p,r); 1086 p_Delete(&p,r); 1087 } 1088 id_NextPotence(given, result, begin+1, end, deg, restdeg, ap,r); 1112 1089 } 1113 1090 … … 1126 1103 //Print("ideal contains %d elements\n",i); 1127 1104 p1=p_One(r); 1128 id NextPotence(temp,result,0,IDELEMS(temp)-1,exp,exp,p1);1105 id_NextPotence(temp,result,0,IDELEMS(temp)-1,exp,exp,p1,r); 1129 1106 p_Delete(&p1,r); 1130 1107 id_Delete(&temp,r); … … 1136 1113 1137 1114 /*2 1138 * compute the which-th ar-minor of the matrix a1139 */1140 poly idMinor(matrix a, int ar, unsigned long which, ideal R)1141 {1142 int i,j,k,size;1143 unsigned long curr;1144 int *rowchoise,*colchoise;1145 BOOLEAN rowch,colch;1146 ideal result;1147 matrix tmp;1148 poly p,q;1149 1150 i = binom(a->rows(),ar);1151 j = binom(a->cols(),ar);1152 1153 rowchoise=(int *)omAlloc(ar*sizeof(int));1154 colchoise=(int *)omAlloc(ar*sizeof(int));1155 if ((i>512) || (j>512) || (i*j >512)) size=512;1156 else size=i*j;1157 result=idInit(size,1);1158 tmp=mpNew(ar,ar);1159 k = 0; /* the index in result*/1160 curr = 0; /* index of current minor */1161 idInitChoise(ar,1,a->rows(),&rowch,rowchoise);1162 while (!rowch)1163 {1164 idInitChoise(ar,1,a->cols(),&colch,colchoise);1165 while (!colch)1166 {1167 if (curr == which)1168 {1169 for (i=1; i<=ar; i++)1170 {1171 for (j=1; j<=ar; j++)1172 {1173 MATELEM(tmp,i,j) = MATELEM(a,rowchoise[i-1],colchoise[j-1]);1174 }1175 }1176 p = mpDetBareiss(tmp);1177 if (p!=NULL)1178 {1179 if (R!=NULL)1180 {1181 q = p;1182 p = kNF(R,currQuotient,q);1183 pDelete(&q);1184 }1185 /*delete the matrix tmp*/1186 for (i=1; i<=ar; i++)1187 {1188 for (j=1; j<=ar; j++) MATELEM(tmp,i,j) = NULL;1189 }1190 idDelete((ideal*)&tmp);1191 omFreeSize((ADDRESS)rowchoise,ar*sizeof(int));1192 omFreeSize((ADDRESS)colchoise,ar*sizeof(int));1193 return (p);1194 }1195 }1196 curr++;1197 idGetNextChoise(ar,a->cols(),&colch,colchoise);1198 }1199 idGetNextChoise(ar,a->rows(),&rowch,rowchoise);1200 }1201 return (poly) 1;1202 }1203 1204 #ifdef WITH_OLD_MINOR1205 /*21206 * compute all ar-minors of the matrix a1207 */1208 ideal idMinors(matrix a, int ar, ideal R)1209 {1210 int i,j,k,size;1211 int *rowchoise,*colchoise;1212 BOOLEAN rowch,colch;1213 ideal result;1214 matrix tmp;1215 poly p,q;1216 1217 i = binom(a->rows(),ar);1218 j = binom(a->cols(),ar);1219 1220 rowchoise=(int *)omAlloc(ar*sizeof(int));1221 colchoise=(int *)omAlloc(ar*sizeof(int));1222 if ((i>512) || (j>512) || (i*j >512)) size=512;1223 else size=i*j;1224 result=idInit(size,1);1225 tmp=mpNew(ar,ar);1226 k = 0; /* the index in result*/1227 idInitChoise(ar,1,a->rows(),&rowch,rowchoise);1228 while (!rowch)1229 {1230 idInitChoise(ar,1,a->cols(),&colch,colchoise);1231 while (!colch)1232 {1233 for (i=1; i<=ar; i++)1234 {1235 for (j=1; j<=ar; j++)1236 {1237 MATELEM(tmp,i,j) = MATELEM(a,rowchoise[i-1],colchoise[j-1]);1238 }1239 }1240 p = mpDetBareiss(tmp);1241 if (p!=NULL)1242 {1243 if (R!=NULL)1244 {1245 q = p;1246 p = kNF(R,currQuotient,q);1247 pDelete(&q);1248 }1249 if (p!=NULL)1250 {1251 if (k>=size)1252 {1253 pEnlargeSet(&result->m,size,32);1254 size += 32;1255 }1256 result->m[k] = p;1257 k++;1258 }1259 }1260 idGetNextChoise(ar,a->cols(),&colch,colchoise);1261 }1262 idGetNextChoise(ar,a->rows(),&rowch,rowchoise);1263 }1264 /*delete the matrix tmp*/1265 for (i=1; i<=ar; i++)1266 {1267 for (j=1; j<=ar; j++) MATELEM(tmp,i,j) = NULL;1268 }1269 idDelete((ideal*)&tmp);1270 if (k==0)1271 {1272 k=1;1273 result->m[0]=NULL;1274 }1275 omFreeSize((ADDRESS)rowchoise,ar*sizeof(int));1276 omFreeSize((ADDRESS)colchoise,ar*sizeof(int));1277 pEnlargeSet(&result->m,size,k-size);1278 IDELEMS(result) = k;1279 return (result);1280 }1281 #else1282 /*21283 * compute all ar-minors of the matrix a1284 * the caller of mpRecMin1285 * the elements of the result are not in R (if R!=NULL)1286 */1287 ideal idMinors(matrix a, int ar, ideal R)1288 {1289 int elems=0;1290 int r=a->nrows,c=a->ncols;1291 int i;1292 matrix b;1293 ideal result,h;1294 ring origR;1295 ring tmpR;1296 long bound;1297 1298 if((ar<=0) || (ar>r) || (ar>c))1299 {1300 Werror("%d-th minor, matrix is %dx%d",ar,r,c);1301 return NULL;1302 }1303 h = idMatrix2Module(mpCopy(a));1304 bound = smExpBound(h,c,r,ar);1305 idDelete(&h);1306 tmpR=smRingChange(&origR,bound);1307 b = mpNew(r,c);1308 for (i=r*c-1;i>=0;i--)1309 {1310 if (a->m[i])1311 b->m[i] = prCopyR(a->m[i],origR);1312 }1313 if (R!=NULL)1314 {1315 R = idrCopyR(R,origR);1316 //if (ar>1) // otherwise done in mpMinorToResult1317 //{1318 // matrix bb=(matrix)kNF(R,currQuotient,(ideal)b);1319 // bb->rank=b->rank; bb->nrows=b->nrows; bb->ncols=b->ncols;1320 // idDelete((ideal*)&b); b=bb;1321 //}1322 }1323 result=idInit(32,1);1324 if(ar>1) mpRecMin(ar-1,result,elems,b,r,c,NULL,R);1325 else mpMinorToResult(result,elems,b,r,c,R);1326 idDelete((ideal *)&b);1327 if (R!=NULL) idDelete(&R);1328 idSkipZeroes(result);1329 rChangeCurrRing(origR);1330 result = idrMoveR(result,tmpR);1331 smKillModifiedRing(tmpR);1332 idTest(result);1333 return result;1334 }1335 #endif1336 1337 /*21338 1115 *skips all zeroes and double elements, searches also for units 1339 1116 */ … … 1362 1139 1363 1140 /*2 1364 *returns TRUE if id1 is a submodule of id21365 */1366 BOOLEAN idIsSubModule(ideal id1,ideal id2)1367 {1368 int i;1369 poly p;1370 1371 if (idIs0(id1)) return TRUE;1372 for (i=0;i<IDELEMS(id1);i++)1373 {1374 if (id1->m[i] != NULL)1375 {1376 p = kNF(id2,currQuotient,id1->m[i]);1377 if (p != NULL)1378 {1379 pDelete(&p);1380 return FALSE;1381 }1382 }1383 }1384 return TRUE;1385 }1386 1387 /*21388 1141 * returns the ideals of initial terms 1389 1142 */ 1390 ideal id Head(ideal h)1143 ideal id_Head(ideal h,const ring r) 1391 1144 { 1392 1145 ideal m = idInit(IDELEMS(h),h->rank); … … 1395 1148 for (i=IDELEMS(h)-1;i>=0; i--) 1396 1149 { 1397 if (h->m[i]!=NULL) m->m[i]=p Head(h->m[i]);1150 if (h->m[i]!=NULL) m->m[i]=p_Head(h->m[i],r); 1398 1151 } 1399 1152 return m; 1400 1153 } 1401 1154 1402 ideal id Homogen(ideal h, int varnum)1155 ideal id_Homogen(ideal h, int varnum,const ring r) 1403 1156 { 1404 1157 ideal m = idInit(IDELEMS(h),h->rank); … … 1407 1160 for (i=IDELEMS(h)-1;i>=0; i--) 1408 1161 { 1409 m->m[i]=p Homogen(h->m[i],varnum);1162 m->m[i]=p_Homogen(h->m[i],varnum,r); 1410 1163 } 1411 1164 return m; … … 1413 1166 1414 1167 /*------------------type conversions----------------*/ 1415 ideal id Vec2Ideal(poly vec)1168 ideal id_Vec2Ideal(poly vec, const ring R) 1416 1169 { 1417 1170 ideal result=idInit(1,1); 1418 1171 omFree((ADDRESS)result->m); 1419 1172 result->m=NULL; // remove later 1420 p Vec2Polys(vec, &(result->m), &(IDELEMS(result)));1173 p_Vec2Polys(vec, &(result->m), &(IDELEMS(result)),R); 1421 1174 return result; 1422 1175 } 1423 1176 1424 #define NEW_STUFF 1425 #ifndef NEW_STUFF 1177 1426 1178 // converts mat to module, destroys mat 1427 ideal idMatrix2Module(matrix mat) 1428 { 1429 int mc=MATCOLS(mat); 1430 int mr=MATROWS(mat); 1431 ideal result = idInit(si_max(mc,1),si_max(mr,1)); 1432 int i,j; 1433 poly h; 1434 1435 for(j=0;j<mc /*MATCOLS(mat)*/;j++) /* j is also index in result->m */ 1436 { 1437 for (i=1;i<=mr /*MATROWS(mat)*/;i++) 1438 { 1439 h = MATELEM(mat,i,j+1); 1440 if (h!=NULL) 1441 { 1442 MATELEM(mat,i,j+1)=NULL; 1443 pSetCompP(h,i); 1444 result->m[j] = pAdd(result->m[j],h); 1445 } 1446 } 1447 } 1448 // obachman: need to clean this up 1449 idDelete((ideal*) &mat); 1450 return result; 1451 } 1452 #else 1453 1454 #include "sbuckets.h" 1455 1456 // converts mat to module, destroys mat 1457 ideal idMatrix2Module(matrix mat) 1179 ideal id_Matrix2Module(matrix mat, const ring R) 1458 1180 { 1459 1181 int mc=MATCOLS(mat); … … 1463 1185 poly h; 1464 1186 poly p; 1465 sBucket_pt bucket = sBucketCreate( currRing);1187 sBucket_pt bucket = sBucketCreate(R); 1466 1188 1467 1189 for(j=0;j<mc /*MATCOLS(mat)*/;j++) /* j is also index in result->m */ … … 1474 1196 l=pLength(h); 1475 1197 MATELEM(mat,i,j+1)=NULL; 1476 p_SetCompP(h,i, currRing);1198 p_SetCompP(h,i, R); 1477 1199 sBucket_Merge_p(bucket, h, l); 1478 1200 } … … 1483 1205 1484 1206 // obachman: need to clean this up 1485 id Delete((ideal*) &mat);1207 id_Delete((ideal*) &mat,R); 1486 1208 return result; 1487 1209 } 1488 #endif1489 1210 1490 1211 /*2 1491 1212 * converts a module into a matrix, destroyes the input 1492 1213 */ 1493 matrix id Module2Matrix(ideal mod)1214 matrix id_Module2Matrix(ideal mod, const ring R) 1494 1215 { 1495 1216 matrix result = mpNew(mod->rank,IDELEMS(mod)); … … 1507 1228 pNext(h)=NULL; 1508 1229 // cp = si_max(1,pGetComp(h)); // if used for ideals too 1509 cp = p GetComp(h);1510 p SetComp(h,0);1511 p SetmComp(h);1230 cp = p_GetComp(h,R); 1231 p_SetComp(h,0,R); 1232 p_SetmComp(h,R); 1512 1233 #ifdef TEST 1513 1234 if (cp>mod->rank) … … 1525 1246 } 1526 1247 } 1527 id Delete((ideal *)&result);1248 id_Delete((ideal *)&result,R); 1528 1249 result=d; 1529 1250 } 1530 1251 #endif 1531 MATELEM(result,cp,i+1) = p Add(MATELEM(result,cp,i+1),h);1252 MATELEM(result,cp,i+1) = p_Add_q(MATELEM(result,cp,i+1),h,R); 1532 1253 } 1533 1254 } 1534 1255 // obachman 10/99: added the following line, otherwise memory leack! 1535 id Delete(&mod);1256 id_Delete(&mod,R); 1536 1257 return result; 1537 1258 } 1538 1259 1539 matrix id Module2formatedMatrix(ideal mod,int rows, int cols)1260 matrix id_Module2formatedMatrix(ideal mod,int rows, int cols, const ring R) 1540 1261 { 1541 1262 matrix result = mpNew(rows,cols); 1542 int i,cp,r=id RankFreeModule(mod),c=IDELEMS(mod);1263 int i,cp,r=id_RankFreeModule(mod,R),c=IDELEMS(mod); 1543 1264 poly p,h; 1544 1265 … … 1554 1275 pIter(p); 1555 1276 pNext(h)=NULL; 1556 cp = p GetComp(h);1277 cp = p_GetComp(h,R); 1557 1278 if (cp<=r) 1558 1279 { 1559 p SetComp(h,0);1560 p SetmComp(h);1561 MATELEM(result,cp,i+1) = p Add(MATELEM(result,cp,i+1),h);1280 p_SetComp(h,0,R); 1281 p_SetmComp(h,R); 1282 MATELEM(result,cp,i+1) = p_Add_q(MATELEM(result,cp,i+1),h,R); 1562 1283 } 1563 1284 else 1564 p Delete(&h);1565 } 1566 } 1567 id Delete(&mod);1285 p_Delete(&h,R); 1286 } 1287 } 1288 id_Delete(&mod,R); 1568 1289 return result; 1569 1290 } … … 1573 1294 * destroy id 1574 1295 */ 1575 ideal id Subst(ideal id, int n, poly e)1296 ideal id_Subst(ideal id, int n, poly e, const ring r) 1576 1297 { 1577 1298 int k=MATROWS((matrix)id)*MATCOLS((matrix)id); … … 1581 1302 for(k--;k>=0;k--) 1582 1303 { 1583 res->m[k]=p Subst(id->m[k],n,e);1304 res->m[k]=p_Subst(id->m[k],n,e,r); 1584 1305 id->m[k]=NULL; 1585 1306 } 1586 id Delete(&id);1307 id_Delete(&id,r); 1587 1308 return res; 1588 1309 } 1589 1310 1590 BOOLEAN id HomModule(ideal m, ideal Q, intvec **w)1311 BOOLEAN id_HomModule(ideal m, ideal Q, intvec **w, const ring R) 1591 1312 { 1592 1313 if (w!=NULL) *w=NULL; 1593 if ((Q!=NULL) && (!id HomIdeal(Q,NULL))) return FALSE;1314 if ((Q!=NULL) && (!id_HomIdeal(Q,NULL,R))) return FALSE; 1594 1315 if (idIs0(m)) 1595 1316 { … … 1603 1324 poly p=NULL; 1604 1325 pFDegProc d; 1605 if ( pLexOrder && (currRing->order[0]==ringorder_lp))1326 if (R->pLexOrder && (R->order[0]==ringorder_lp)) 1606 1327 d=p_Totaldegree; 1607 1328 else 1608 1329 d=pFDeg; 1609 1330 int length=IDELEMS(m); 1610 poly setP=m->m;1611 poly set F=(polyset)omAlloc(length*sizeof(poly));1331 poly* P=m->m; 1332 poly* F=(poly*)omAlloc(length*sizeof(poly)); 1612 1333 for (i=length-1;i>=0;i--) 1613 1334 { 1614 1335 p=F[i]=P[i]; 1615 cmax=si_max(cmax,(long)p MaxComp(p));1336 cmax=si_max(cmax,(long)p_MaxComp(p,R)); 1616 1337 } 1617 1338 cmax++; … … 1625 1346 { 1626 1347 p=F[i]; 1627 while ((p!=NULL) && (iscom[p GetComp(p)]==0)) pIter(p);1348 while ((p!=NULL) && (iscom[p_GetComp(p,R)]==0)) pIter(p); 1628 1349 } 1629 1350 if ((p==NULL) && (i<length)) … … 1645 1366 // order = p->order; 1646 1367 // order = pFDeg(p,currRing); 1647 order = d(p, currRing) +diff[pGetComp(p)];1368 order = d(p,R) +diff[p_GetComp(p,R)]; 1648 1369 //order += diff[pGetComp(p)]; 1649 1370 p = F[i]; … … 1654 1375 while (p!=NULL) 1655 1376 { 1656 if ( pLexOrder && (currRing->order[0]==ringorder_lp))1657 ord=p Totaldegree(p);1377 if (R->pLexOrder && (R->order[0]==ringorder_lp)) 1378 ord=p_Totaldegree(p,R); 1658 1379 else 1659 1380 // ord = p->order; 1660 ord = pFDeg(p, currRing);1661 if (iscom[p GetComp(p)]==0)1662 { 1663 diff[p GetComp(p)] = order-ord;1664 iscom[p GetComp(p)] = 1;1381 ord = pFDeg(p,R); 1382 if (iscom[p_GetComp(p,R)]==0) 1383 { 1384 diff[p_GetComp(p,R)] = order-ord; 1385 iscom[p_GetComp(p,R)] = 1; 1665 1386 /* 1666 1387 *PrintS("new diff: "); … … 1681 1402 *Print("order %d, ord %d, diff %d\n",order,ord,diff[pGetComp(p)]); 1682 1403 */ 1683 if (order != (ord+diff[p GetComp(p)]))1404 if (order != (ord+diff[p_GetComp(p,R)])) 1684 1405 { 1685 1406 omFreeSize((ADDRESS) iscom,cmax*sizeof(int)); … … 1711 1432 } 1712 1433 1713 BOOLEAN idTestHomModule(ideal m, ideal Q, intvec *w) 1714 { 1715 if ((Q!=NULL) && (!idHomIdeal(Q,NULL))) { PrintS(" Q not hom\n"); return FALSE;} 1716 if (idIs0(m)) return TRUE; 1717 1718 int cmax=-1; 1719 int i; 1720 poly p=NULL; 1721 int length=IDELEMS(m); 1722 polyset P=m->m; 1723 for (i=length-1;i>=0;i--) 1724 { 1725 p=P[i]; 1726 if (p!=NULL) cmax=si_max(cmax,(int)pMaxComp(p)+1); 1727 } 1728 if (w != NULL) 1729 if (w->length()+1 < cmax) 1730 { 1731 // Print("length: %d - %d \n", w->length(),cmax); 1732 return FALSE; 1733 } 1734 1735 if(w!=NULL) 1736 pSetModDeg(w); 1737 1738 for (i=length-1;i>=0;i--) 1739 { 1740 p=P[i]; 1741 poly q=p; 1742 if (p!=NULL) 1743 { 1744 int d=pFDeg(p,currRing); 1745 loop 1746 { 1747 pIter(p); 1748 if (p==NULL) break; 1749 if (d!=pFDeg(p,currRing)) 1750 { 1751 //pWrite(q); wrp(p); Print(" -> %d - %d\n",d,pFDeg(p,currRing)); 1752 if(w!=NULL) 1753 pSetModDeg(NULL); 1754 return FALSE; 1755 } 1756 } 1757 } 1758 } 1759 1760 if(w!=NULL) 1761 pSetModDeg(NULL); 1762 1763 return TRUE; 1764 } 1765 1766 ideal idJet(ideal i,int d) 1434 // uses glabl vars via pSetModDeg 1435 //BOOLEAN idTestHomModule(ideal m, ideal Q, intvec *w) 1436 //{ 1437 // if ((Q!=NULL) && (!idHomIdeal(Q,NULL))) { PrintS(" Q not hom\n"); return FALSE;} 1438 // if (idIs0(m)) return TRUE; 1439 // 1440 // int cmax=-1; 1441 // int i; 1442 // poly p=NULL; 1443 // int length=IDELEMS(m); 1444 // poly* P=m->m; 1445 // for (i=length-1;i>=0;i--) 1446 // { 1447 // p=P[i]; 1448 // if (p!=NULL) cmax=si_max(cmax,(int)pMaxComp(p)+1); 1449 // } 1450 // if (w != NULL) 1451 // if (w->length()+1 < cmax) 1452 // { 1453 // // Print("length: %d - %d \n", w->length(),cmax); 1454 // return FALSE; 1455 // } 1456 // 1457 // if(w!=NULL) 1458 // pSetModDeg(w); 1459 // 1460 // for (i=length-1;i>=0;i--) 1461 // { 1462 // p=P[i]; 1463 // poly q=p; 1464 // if (p!=NULL) 1465 // { 1466 // int d=pFDeg(p,currRing); 1467 // loop 1468 // { 1469 // pIter(p); 1470 // if (p==NULL) break; 1471 // if (d!=pFDeg(p,currRing)) 1472 // { 1473 // //pWrite(q); wrp(p); Print(" -> %d - %d\n",d,pFDeg(p,currRing)); 1474 // if(w!=NULL) 1475 // pSetModDeg(NULL); 1476 // return FALSE; 1477 // } 1478 // } 1479 // } 1480 // } 1481 // 1482 // if(w!=NULL) 1483 // pSetModDeg(NULL); 1484 // 1485 // return TRUE; 1486 //} 1487 1488 ideal id_Jet(ideal i,int d, const ring R) 1767 1489 { 1768 1490 ideal r=idInit((i->nrows)*(i->ncols),i->rank); … … 1773 1495 for(k=(i->nrows)*(i->ncols)-1;k>=0; k--) 1774 1496 { 1775 r->m[k]=pp Jet(i->m[k],d);1497 r->m[k]=pp_Jet(i->m[k],d,R); 1776 1498 } 1777 1499 return r; 1778 1500 } 1779 1501 1780 ideal id JetW(ideal i,int d, intvec * iv)1502 ideal id_JetW(ideal i,int d, intvec * iv, const ring R) 1781 1503 { 1782 1504 ideal r=idInit(IDELEMS(i),i->rank); … … 1787 1509 else 1788 1510 { 1789 short *w=iv2array(iv );1511 short *w=iv2array(iv,R); 1790 1512 int k; 1791 1513 for(k=0; k<IDELEMS(i); k++) 1792 1514 { 1793 r->m[k]=pp JetW(i->m[k],d,w);1794 } 1795 omFreeSize((ADDRESS)w,(rVar( r)+1)*sizeof(short));1515 r->m[k]=pp_JetW(i->m[k],d,w,R); 1516 } 1517 omFreeSize((ADDRESS)w,(rVar(R)+1)*sizeof(short)); 1796 1518 } 1797 1519 return r; 1798 }1799 1800 int idMinDegW(ideal M,intvec *w)1801 {1802 int d=-1;1803 for(int i=0;i<IDELEMS(M);i++)1804 {1805 int d0=pMinDeg(M->m[i],w);1806 if(-1<d0&&(d0<d||d==-1))1807 d=d0;1808 }1809 return d;1810 }1811 1812 ideal idSeries(int n,ideal M,matrix U,intvec *w)1813 {1814 for(int i=IDELEMS(M)-1;i>=0;i--)1815 {1816 if(U==NULL)1817 M->m[i]=pSeries(n,M->m[i],NULL,w);1818 else1819 {1820 M->m[i]=pSeries(n,M->m[i],MATELEM(U,i+1,i+1),w);1821 MATELEM(U,i+1,i+1)=NULL;1822 }1823 }1824 if(U!=NULL)1825 idDelete((ideal*)&U);1826 return M;1827 }1828 1829 matrix idDiff(matrix i, int k)1830 {1831 int e=MATCOLS(i)*MATROWS(i);1832 matrix r=mpNew(MATROWS(i),MATCOLS(i));1833 r->rank=i->rank;1834 int j;1835 for(j=0; j<e; j++)1836 {1837 r->m[j]=pDiff(i->m[j],k);1838 }1839 return r;1840 }1841 1842 matrix idDiffOp(ideal I, ideal J,BOOLEAN multiply)1843 {1844 matrix r=mpNew(IDELEMS(I),IDELEMS(J));1845 int i,j;1846 for(i=0; i<IDELEMS(I); i++)1847 {1848 for(j=0; j<IDELEMS(J); j++)1849 {1850 MATELEM(r,i+1,j+1)=pDiffOp(I->m[i],J->m[j],multiply);1851 }1852 }1853 return r;1854 }1855 1856 int idElem(const ideal F)1857 {1858 int i=0,j=IDELEMS(F)-1;1859 1860 while(j>=0)1861 {1862 if ((F->m)[j]!=NULL) i++;1863 j--;1864 }1865 return i;1866 }1867 1868 /*1869 *computes module-weights for liftings of homogeneous modules1870 */1871 intvec * idMWLift(ideal mod,intvec * weights)1872 {1873 if (idIs0(mod)) return new intvec(2);1874 int i=IDELEMS(mod);1875 while ((i>0) && (mod->m[i-1]==NULL)) i--;1876 intvec *result = new intvec(i+1);1877 while (i>0)1878 {1879 (*result)[i]=pFDeg(mod->m[i],currRing)+(*weights)[pGetComp(mod->m[i])];1880 }1881 return result;1882 }1883 1884 /*21885 *sorts the kbase for idCoef* in a special way (lexicographically1886 *with x_max,...,x_1)1887 */1888 ideal idCreateSpecialKbase(ideal kBase,intvec ** convert)1889 {1890 int i;1891 ideal result;1892 1893 if (idIs0(kBase)) return NULL;1894 result = idInit(IDELEMS(kBase),kBase->rank);1895 *convert = idSort(kBase,FALSE);1896 for (i=0;i<(*convert)->length();i++)1897 {1898 result->m[i] = pCopy(kBase->m[(**convert)[i]-1]);1899 }1900 return result;1901 }1902 1903 /*21904 *returns the index of a given monom in the list of the special kbase1905 */1906 int idIndexOfKBase(poly monom, ideal kbase)1907 {1908 int j=IDELEMS(kbase);1909 1910 while ((j>0) && (kbase->m[j-1]==NULL)) j--;1911 if (j==0) return -1;1912 int i=rVar(r);1913 while (i>0)1914 {1915 loop1916 {1917 if (pGetExp(monom,i)>pGetExp(kbase->m[j-1],i)) return -1;1918 if (pGetExp(monom,i)==pGetExp(kbase->m[j-1],i)) break;1919 j--;1920 if (j==0) return -1;1921 }1922 if (i==1)1923 {1924 while(j>0)1925 {1926 if (pGetComp(monom)==pGetComp(kbase->m[j-1])) return j-1;1927 if (pGetComp(monom)>pGetComp(kbase->m[j-1])) return -1;1928 j--;1929 }1930 }1931 i--;1932 }1933 return -1;1934 }1935 1936 /*21937 *decomposes the monom in a part of coefficients described by the1938 *complement of how and a monom in variables occuring in how, the1939 *index of which in kbase is returned as integer pos (-1 if it don't1940 *exists)1941 */1942 poly idDecompose(poly monom, poly how, ideal kbase, int * pos)1943 {1944 int i;1945 poly coeff=p_One(r), base=p_One(r);1946 1947 for (i=1;i<=rVar(r);i++)1948 {1949 if (pGetExp(how,i)>0)1950 {1951 pSetExp(base,i,pGetExp(monom,i));1952 }1953 else1954 {1955 pSetExp(coeff,i,pGetExp(monom,i));1956 }1957 }1958 pSetComp(base,pGetComp(monom));1959 pSetm(base);1960 pSetCoeff(coeff,nCopy(pGetCoeff(monom)));1961 pSetm(coeff);1962 *pos = idIndexOfKBase(base,kbase);1963 if (*pos<0)1964 pDelete(&coeff);1965 pDelete(&base);1966 return coeff;1967 }1968 1969 /*21970 *returns a matrix A of coefficients with kbase*A=arg1971 *if all monomials in variables of how occur in kbase1972 *the other are deleted1973 */1974 matrix idCoeffOfKBase(ideal arg, ideal kbase, poly how)1975 {1976 matrix result;1977 ideal tempKbase;1978 poly p,q;1979 intvec * convert;1980 int i=IDELEMS(kbase),j=IDELEMS(arg),k,pos;1981 #if 01982 while ((i>0) && (kbase->m[i-1]==NULL)) i--;1983 if (idIs0(arg))1984 return mpNew(i,1);1985 while ((j>0) && (arg->m[j-1]==NULL)) j--;1986 result = mpNew(i,j);1987 #else1988 result = mpNew(i, j);1989 while ((j>0) && (arg->m[j-1]==NULL)) j--;1990 #endif1991 1992 tempKbase = idCreateSpecialKbase(kbase,&convert);1993 for (k=0;k<j;k++)1994 {1995 p = arg->m[k];1996 while (p!=NULL)1997 {1998 q = idDecompose(p,how,tempKbase,&pos);1999 if (pos>=0)2000 {2001 MATELEM(result,(*convert)[pos],k+1) =2002 pAdd(MATELEM(result,(*convert)[pos],k+1),q);2003 }2004 else2005 pDelete(&q);2006 pIter(p);2007 }2008 }2009 idDelete(&tempKbase);2010 return result;2011 1520 } 2012 1521 … … 2097 1606 #endif 2098 1607 2099 static void idDeleteComps(ideal arg,int* red_comp,int del) 2100 // red_comp is an array [0..args->rank] 2101 { 2102 int i,j; 2103 poly p; 2104 2105 for (i=IDELEMS(arg)-1;i>=0;i--) 2106 { 2107 p = arg->m[i]; 2108 while (p!=NULL) 2109 { 2110 j = pGetComp(p); 2111 if (red_comp[j]!=j) 2112 { 2113 pSetComp(p,red_comp[j]); 2114 pSetmComp(p); 2115 } 2116 pIter(p); 2117 } 2118 } 2119 (arg->rank) -= del; 2120 } 2121 2122 /*2 2123 * returns the presentation of an isomorphic, minimally 2124 * embedded module (arg represents the quotient!) 2125 */ 2126 ideal idMinEmbedding(ideal arg,BOOLEAN inPlace, intvec **w, const ring r) 2127 { 2128 if (idIs0(arg)) return idInit(1,arg->rank); 2129 int i,next_gen,next_comp; 2130 ideal res=arg; 2131 if (!inPlace) res = id_Copy(arg,r); 2132 res->rank=si_max(res->rank,id_RankFreeModule(res,r)); 2133 int *red_comp=(int*)omAlloc((res->rank+1)*sizeof(int)); 2134 for (i=res->rank;i>=0;i--) red_comp[i]=i; 2135 2136 int del=0; 2137 loop 2138 { 2139 next_gen = idReadOutPivot(res,&next_comp); 2140 if (next_gen<0) break; 2141 del++; 2142 syGaussForOne(res,next_gen,next_comp,0,IDELEMS(res)); 2143 for(i=next_comp+1;i<=arg->rank;i++) red_comp[i]--; 2144 if ((w !=NULL)&&(*w!=NULL)) 2145 { 2146 for(i=next_comp;i<(*w)->length();i++) (**w)[i-1]=(**w)[i]; 2147 } 2148 } 2149 2150 idDeleteComps(res,red_comp,del); 2151 idSkipZeroes(res); 2152 omFree(red_comp); 2153 2154 if ((w !=NULL)&&(*w!=NULL) &&(del>0)) 2155 { 2156 intvec *wtmp=new intvec((*w)->length()-del); 2157 for(i=0;i<res->rank;i++) (*wtmp)[i]=(**w)[i]; 2158 delete *w; 2159 *w=wtmp; 2160 } 2161 return res; 2162 } 2163 2164 intvec * idQHomWeight(ideal id) 1608 intvec * id_QHomWeight(ideal id, const ring r) 2165 1609 { 2166 1610 poly head, tail; … … 2181 1625 all++; 2182 1626 for (k=1;k<=coldim;k++) 2183 IMATELEM(*imat,all,k) = p GetExpDiff(head,tail,k);1627 IMATELEM(*imat,all,k) = p_GetExpDiff(head,tail,k,r); 2184 1628 if (all==rowmax) 2185 1629 { … … 2209 1653 } 2210 1654 2211 BOOLEAN id IsZeroDim(ideal I)1655 BOOLEAN id_IsZeroDim(ideal I, const ring r) 2212 1656 { 2213 1657 BOOLEAN *UsedAxis=(BOOLEAN *)omAlloc0(rVar(r)*sizeof(BOOLEAN)); … … 2218 1662 { 2219 1663 po=I->m[i]; 2220 if ((po!=NULL) &&((n=p IsPurePower(po))!=0)) UsedAxis[n-1]=TRUE;1664 if ((po!=NULL) &&((n=p_IsPurePower(po,r))!=0)) UsedAxis[n-1]=TRUE; 2221 1665 } 2222 1666 for(i=rVar(r)-1;i>=0;i--) … … 2323 1767 } 2324 1768 #endif 2325 /* currently unsed:2326 ideal idChineseRemainder(ideal *xx, intvec *iv)2327 {2328 int rl=iv->length();2329 number *q=(number *)omAlloc(rl*sizeof(number));2330 int i;2331 for(i=0; i<rl; i++)2332 {2333 q[i]=nInit((*iv)[i]);2334 }2335 return idChineseRemainder(xx,q,rl);2336 }2337 */2338 /*2339 * lift ideal with coeffs over Z (mod N) to Q via Farey2340 */2341 ideal id_Farey(ideal x, number N, const ring r)2342 {2343 int cnt=IDELEMS(x)*x->nrows;2344 ideal result=idInit(cnt,x->rank);2345 result->nrows=x->nrows; // for lifting matrices2346 result->ncols=x->ncols; // for lifting matrices2347 2348 int i;2349 for(i=cnt-1;i>=0;i--)2350 {2351 poly h=p_Copy(x->m[i],r);2352 result->m[i]=h;2353 while(h!=NULL)2354 {2355 number c=pGetCoeff(h);2356 pSetCoeff0(h,nlFarey(c,N));2357 n_Delete(&c,r->cf);2358 pIter(h);2359 }2360 while((result->m[i]!=NULL)&&(n_IsZero(pGetCoeff(result->m[i]),r->cf)))2361 {2362 p_LmDelete(&(result->m[i]),r);2363 }2364 h=result->m[i];2365 while((h!=NULL) && (pNext(h)!=NULL))2366 {2367 if(n_IsZero(pGetCoeff(pNext(h)),r->cf))2368 {2369 p_LmDelete(&pNext(h),r);2370 }2371 else pIter(h);2372 }2373 }2374 return result;2375 }2376 1769 2377 1770 /*2
Note: See TracChangeset
for help on using the changeset viewer.