Changeset b85e37 in git
 Timestamp:
 Oct 8, 2009, 7:02:33 PM (14 years ago)
 Branches:
 (u'spielwiese', '828514cf6e480e4bafc26df99217bf2a1ed1ef45')
 Children:
 d8db707919fa01c928aa53fa8778bf431ce018ef
 Parents:
 9193d93b4d40ee988851d32b6b7d64e21ec55ab1
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

kernel/longalg.cc
r9193d9 rb85e37 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: longalg.cc,v 1.5 5 20091008 08:38:31Singular Exp $ */4 /* $Id: longalg.cc,v 1.56 20091008 17:02:33 Singular Exp $ */ 5 5 /* 6 6 * ABSTRACT: algebraic numbers … … 47 47 static number (*nacGcd)(number a, number b, const ring r); 48 48 static number (*nacLcm)(number a, number b, const ring r); 49 static void (*nacDelete)(number *a, const ring r);50 49 static number (*nacInit)(int i, const ring r); 51 50 static int (*nacInt)(number &n, const ring r); 51 static void (*nacDelete)(number *a, const ring r); 52 #undef n_Delete 53 #define n_Delete(A,R) nacDelete(A,R) 52 54 void (*nacNormalize)(number &a); 53 55 static number (*nacNeg)(number a); … … 66 68 ring nacRing; 67 69 68 #define napCopy(p) (napoly)p_Copy((poly)p,nacRing)70 #define napCopy(p) p_Copy(p,nacRing) 69 71 70 72 static number nadGcd( number a, number b, const ring r) { return nacInit(1,r); } … … 137 139 nacGcd = nacRing>cf>nGcd; 138 140 nacLcm = nacRing>cf>nLcm; 139 nacDelete = nacRing>cf>cfDelete;140 141 nacMult = nacRing>cf>nMult; 141 142 nacDiv = nacRing>cf>nDiv; 142 143 nacIntDiv = nacRing>cf>nIntDiv; 143 144 nacInvers = nacRing>cf>nInvers; 145 nacDelete = nacRing>cf>cfDelete; 144 146 } 145 147 … … 163 165 164 166 #define napInit(i) (napoly)p_ISet(i,nacRing) 165 #define napSetCoeff(p,n) {n acDelete(&pGetCoeff(p),nacRing);pGetCoeff(p)=n;}167 #define napSetCoeff(p,n) {n_Delete(&pGetCoeff(p),nacRing);pGetCoeff(p)=n;} 166 168 #define napDelete1(p) p_LmDelete((poly *)p, nacRing) 167 169 #define napComp(p,q) p_LmCmp((poly)p,(poly)q, nacRing) 168 170 #define napMultT(A,E) A=(napoly)p_Mult_mm((poly)A,(poly)E,nacRing) 169 #define napMult(A,B) (napoly)p_Mult_q((poly)A,(poly)B,nacRing)170 #define napMultCopy(A,B) (napoly)pp_Mult_qq((poly)A,(poly)B,nacRing)171 171 #define napIsConstant(p) p_LmIsConstant(p,nacRing) 172 172 #define napDeg(p) (int)p_ExpVectorQuerSum(p, nacRing) … … 203 203 t = nacMult(pGetCoeff(p), z); 204 204 nacNormalize(t); 205 n acDelete(&pGetCoeff(p),nacRing);205 n_Delete(&pGetCoeff(p),nacRing); 206 206 pGetCoeff(p) = t; 207 207 pIter(p); … … 223 223 do 224 224 { 225 napSetExp(qq,1, napGetExp(a,1)  napGetExp(g,1));225 napSetExp(qq,1, p_GetExp(a,1,nacRing)  p_GetExp(g,1,nacRing)); 226 226 napSetm(qq); 227 227 pGetCoeff(qq) = nacDiv(pGetCoeff(a), pGetCoeff(g)); … … 231 231 napMultT(h, qq); 232 232 p_Normalize(h,nacRing); 233 n acDelete(&pGetCoeff(qq),nacRing);233 n_Delete(&pGetCoeff(qq),nacRing); 234 234 a = napAdd(a, h); 235 235 } 236 while ((a!=NULL) && ( napGetExp(a,1) >= napGetExp(g,1)));236 while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing))); 237 237 omFreeBinAddr(qq); 238 238 return a; … … 253 253 do 254 254 { 255 napSetExp(qq,1, napGetExp(a,1)  napGetExp(g,1));255 napSetExp(qq,1, p_GetExp(a,1,nacRing)  p_GetExp(g,1,nacRing)); 256 256 p_Setm(qq,nacRing); 257 257 pGetCoeff(qq) = nacDiv(pGetCoeff(a), pGetCoeff(g)); … … 262 262 napMultT(h, qq); 263 263 p_Normalize(h,nacRing); 264 n acDelete(&pGetCoeff(qq),nacRing);264 n_Delete(&pGetCoeff(qq),nacRing); 265 265 a = napAdd(a, h); 266 266 } 267 while ((a!=NULL) && ( napGetExp(a,1) >= napGetExp(g,1)));267 while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing))); 268 268 omFreeBinAddr(qq); 269 269 *q = b; … … 279 279 number t, h; 280 280 281 if ( napGetExp(x,1) >= napGetExp(c,1))281 if (p_GetExp(x,1,nacRing) >= p_GetExp(c,1,nacRing)) 282 282 x = napRemainder(x, c); 283 283 if (x==NULL) … … 285 285 goto zero_divisor; 286 286 } 287 if ( napGetExp(x,1)==0)287 if (p_GetExp(x,1,nacRing)==0) 288 288 { 289 289 if (!nacIsOne(pGetCoeff(x))) … … 292 292 t = nacInvers(pGetCoeff(x)); 293 293 nacNormalize(t); 294 n acDelete(&pGetCoeff(x),nacRing);294 n_Delete(&pGetCoeff(x),nacRing); 295 295 pGetCoeff(x) = t; 296 296 } … … 303 303 goto zero_divisor; 304 304 } 305 if ( napGetExp(r,1)==0)305 if (p_GetExp(r,1,nacRing)==0) 306 306 { 307 307 nacNormalize(pGetCoeff(r)); … … 310 310 t = nacNeg(t); 311 311 napMultN(qa, t); 312 n acDelete(&t,nacRing);312 n_Delete(&t,nacRing); 313 313 p_Normalize(qa,nacRing); 314 314 p_Delete(&x,nacRing); … … 323 323 goto zero_divisor; 324 324 } 325 if ( napGetExp(r,1)==0)326 { 327 q = napMult(q, qa);325 if (p_GetExp(r,1,nacRing)==0) 326 { 327 q = p_Mult_q(q, qa,nacRing); 328 328 q = napAdd(q, napInit(1)); 329 329 nacNormalize(pGetCoeff(r)); … … 331 331 napMultN(q, t); 332 332 p_Normalize(q,nacRing); 333 n acDelete(&t,nacRing);333 n_Delete(&t,nacRing); 334 334 p_Delete(&x,nacRing); 335 335 p_Delete(&r,nacRing); 336 if ( napGetExp(q,1) >= napGetExp(c,1))336 if (p_GetExp(q,1,nacRing) >= p_GetExp(c,1,nacRing)) 337 337 q = napRemainder(q, c); 338 338 return q; 339 339 } 340 q = napMult(q, napCopy(qa));340 q = p_Mult_q(q, napCopy(qa),nacRing); 341 341 q = napAdd(q, napInit(1)); 342 342 qa = napNeg(qa); … … 350 350 break; 351 351 } 352 if ( napGetExp(r,1)==0)353 { 354 q = napMult(q, qn);352 if (p_GetExp(r,1,nacRing)==0) 353 { 354 q = p_Mult_q(q, qn,nacRing); 355 355 q = napNeg(q); 356 356 q = napAdd(q, qa); … … 360 360 napMultN(q, t); 361 361 p_Normalize(q,nacRing); 362 n acDelete(&t,nacRing);362 n_Delete(&t,nacRing); 363 363 p_Delete(&x,nacRing); 364 364 p_Delete(&r,nacRing); 365 if ( napGetExp(q,1) >= napGetExp(c,1))365 if (p_GetExp(q,1,nacRing) >= p_GetExp(c,1,nacRing)) 366 366 q = napRemainder(q, c); 367 367 return q; 368 368 } 369 369 y = q; 370 q = napMult(napCopy(q), qn);370 q = p_Mult_q(napCopy(q), qn, nacRing); 371 371 q = napNeg(q); 372 372 q = napAdd(q, qa); … … 452 452 for (i = 0; i < naNumbOfPar; i++) 453 453 { 454 if (napGetExp(p,i+1) > 0) 454 int e=p_GetExp(p,i+1,nacRing); 455 if (e > 0) 455 456 { 456 457 if (wroteCoeff) … … 459 460 wroteCoeff=(currRing>ShortOut==0); 460 461 StringAppendS(naParNames[i]); 461 if ( napGetExp(p,(i+1))> 1)462 if (e > 1) 462 463 { 463 464 if (currRing>ShortOut == 0) 464 465 StringAppendS("^"); 465 StringAppend("%d", napGetExp(p,i+1));466 StringAppend("%d", e); 466 467 } 467 468 } … … 530 531 if (olds == s) 531 532 i++; 532 else if (*s == '\0') 533 else if (*s == '\0') 533 534 { 534 535 *b = a; … … 557 558 { 558 559 while (pNext(a)!=NULL) pIter(a); 559 int m = napGetExp(a,1);560 int m = p_GetExp(a,1,nacRing); 560 561 if (m==0) return 0; 561 562 while (pNext(b)!=NULL) pIter(b); 562 int mm= napGetExp(b,1);563 int mm=p_GetExp(b,1,nacRing); 563 564 if (m > mm) m = mm; 564 565 return m; … … 572 573 { 573 574 if (a==NULL  b==NULL) return 0; 574 int m = napGetExp(a,i+1);575 int m = p_GetExp(a,i+1,nacRing); 575 576 if (m==0) return 0; 576 577 while (pNext(a) != NULL) 577 578 { 578 579 pIter(a); 579 if (m > napGetExp(a,i+1))580 { 581 m = napGetExp(a,i+1);580 if (m > p_GetExp(a,i+1,nacRing)) 581 { 582 m = p_GetExp(a,i+1,nacRing); 582 583 if (m==0) return 0; 583 584 } … … 585 586 do 586 587 { 587 if (m > napGetExp(b,i+1))588 { 589 m = napGetExp(b,i+1);588 if (m > p_GetExp(b,i+1,nacRing)) 589 { 590 m = p_GetExp(b,i+1,nacRing); 590 591 if (m==0) return 0; 591 592 } … … 611 612 if(nacIsOne(d)) 612 613 { 613 n acDelete(&h,nacRing);614 n acDelete(&d,nacRing);614 n_Delete(&h,nacRing); 615 n_Delete(&d,nacRing); 615 616 return; 616 617 } 617 n acDelete(&h,nacRing);618 n_Delete(&h,nacRing); 618 619 h = d; 619 620 pIter(p); … … 621 622 while (p!=NULL); 622 623 h = nacInvers(d); 623 n acDelete(&d,nacRing);624 n_Delete(&d,nacRing); 624 625 p = ph; 625 626 while (p!=NULL) 626 627 { 627 628 d = nacMult(pGetCoeff(p), h); 628 n acDelete(&pGetCoeff(p),nacRing);629 n_Delete(&pGetCoeff(p),nacRing); 629 630 pGetCoeff(p) = d; 630 631 pIter(p); 631 632 } 632 n acDelete(&h,nacRing);633 n_Delete(&h,nacRing); 633 634 } 634 635 … … 645 646 { 646 647 d = nacLcm(h, pGetCoeff(p), nacRing); 647 n acDelete(&h,nacRing);648 n_Delete(&h,nacRing); 648 649 h = d; 649 650 pIter(p); … … 655 656 { 656 657 d=nacMult(h, pGetCoeff(p)); 657 n acDelete(&pGetCoeff(p),nacRing);658 n_Delete(&pGetCoeff(p),nacRing); 658 659 nacNormalize(d); 659 660 pGetCoeff(p) = d; 660 661 pIter(p); 661 662 } 662 n acDelete(&h,nacRing);663 n_Delete(&h,nacRing); 663 664 } 664 665 napContent(ph); … … 677 678 pIter(a); 678 679 y = nacGcd(x, pGetCoeff(a), nacRing); 679 n acDelete(&x,nacRing);680 n_Delete(&x,nacRing); 680 681 x = y; 681 682 if (nacIsOne(x)) … … 685 686 { 686 687 y = nacGcd(x, pGetCoeff(b), nacRing); 687 n acDelete(&x,nacRing);688 n_Delete(&x,nacRing); 688 689 x = y; 689 690 if (nacIsOne(x)) … … 720 721 if (naMinimalPoly != NULL) 721 722 { 722 if ( napGetExp(a,1) >= napGetExp(b,1))723 if (p_GetExp(a,1,nacRing) >= p_GetExp(b,1,nacRing)) 723 724 { 724 725 x = a; … … 789 790 { 790 791 d = nacLcm(h, pGetCoeff(b), nacRing); 791 n acDelete(&h,nacRing);792 n_Delete(&h,nacRing); 792 793 h = d; 793 794 pIter(b); … … 807 808 int j=1; /* evtl. von naNumber.. 1 abwaerts zaehlen */ 808 809 809 while ( napGetExp(p,j) <= napGetExp(q,j))810 while (p_GetExp(p,j,nacRing) <= p_GetExp(q,j,nacRing)) 810 811 { 811 812 j++; … … 834 835 pGetCoeff(h) = nacCopy(pGetCoeff(q)); 835 836 for (j=naNumbOfPar; j>0; j) 836 napSetExp(h,j, napGetExp(q,j)  napGetExp(naI>liste[i],j));837 napSetExp(h,j, p_GetExp(q,j,nacRing)  p_GetExp(naI>liste[i],j,nacRing)); 837 838 p_Setm(h,nacRing); 838 h = napMult (h, napCopy(naI>liste[i]));839 h = p_Mult_q(h, napCopy(naI>liste[i]),nacRing); 839 840 h = napNeg (h); 840 841 q = napAdd (q, napCopy(h)); … … 1023 1024 omCheckAddrSize(b,sizeof(snumber)); 1024 1025 lu = (lnumber)omAllocBin(rnumber_bin); 1025 if (b>n!=NULL) x = napMultCopy(a>z, b>n);1026 if (b>n!=NULL) x = pp_Mult_qq(a>z, b>n,nacRing); 1026 1027 else x = napCopy(a>z); 1027 if (a>n!=NULL) y = napMultCopy(b>z, a>n);1028 if (a>n!=NULL) y = pp_Mult_qq(b>z, a>n,nacRing); 1028 1029 else y = napCopy(b>z); 1029 1030 lu>z = napAdd(x, y); … … 1035 1036 if (a>n!=NULL) 1036 1037 { 1037 if (b>n!=NULL) x = napMultCopy(a>n, b>n);1038 if (b>n!=NULL) x = pp_Mult_qq(a>n, b>n,nacRing); 1038 1039 else x = napCopy(a>n); 1039 1040 } … … 1049 1050 // number inv=nacInvers(pGetCoeff(x)); 1050 1051 // napMultN(lu>z,inv); 1051 // n acDelete(&inv,nacRing);1052 // n_Delete(&inv,nacRing); 1052 1053 // napDelete(&x); 1053 1054 // } … … 1088 1089 napoly x, y; 1089 1090 lu = (lnumber)omAllocBin(rnumber_bin); 1090 if (b>n!=NULL) x = napMultCopy(a>z, b>n);1091 if (b>n!=NULL) x = pp_Mult_qq(a>z, b>n,nacRing); 1091 1092 else x = napCopy(a>z); 1092 if (a>n!=NULL) y = napMult(napCopy(b>z), napCopyNeg(a>n));1093 if (a>n!=NULL) y = p_Mult_q(napCopy(b>z), napCopyNeg(a>n),nacRing); 1093 1094 else y = napCopyNeg(b>z); 1094 1095 lu>z = napAdd(x, y); … … 1100 1101 if (a>n!=NULL) 1101 1102 { 1102 if (b>n!=NULL) x = napMultCopy(a>n, b>n);1103 if (b>n!=NULL) x = pp_Mult_qq(a>n, b>n,nacRing); 1103 1104 else x = napCopy(a>n); 1104 1105 } … … 1114 1115 // number inv=nacInvers(pGetCoeff(x)); 1115 1116 // napMultN(lu>z,inv); 1116 // n acDelete(&inv,nacRing);1117 // n_Delete(&inv,nacRing); 1117 1118 // napDelete(&x); 1118 1119 // } … … 1149 1150 1150 1151 lo = (lnumber)omAllocBin(rnumber_bin); 1151 lo>z = napMultCopy(a>z, b>z);1152 lo>z = pp_Mult_qq(a>z, b>z,nacRing); 1152 1153 1153 1154 if (a>n==NULL) … … 1166 1167 else 1167 1168 { 1168 x = napMultCopy(b>n, a>n);1169 x = pp_Mult_qq(b>n, a>n, nacRing); 1169 1170 } 1170 1171 } 1171 1172 if (naMinimalPoly!=NULL) 1172 1173 { 1173 if ( napGetExp(lo>z,1) >= napGetExp(naMinimalPoly,1))1174 if (p_GetExp(lo>z,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 1174 1175 lo>z = napRemainder(lo>z, naMinimalPoly); 1175 if ((x!=NULL) && ( napGetExp(x,1) >= napGetExp(naMinimalPoly,1)))1176 if ((x!=NULL) && (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing))) 1176 1177 x = napRemainder(x, naMinimalPoly); 1177 1178 } … … 1250 1251 napoly x; 1251 1252 1252 if ( (a==NULL)  (a>z==NULL))1253 if (a==NULL) 1253 1254 return NULL; 1254 1255 1255 if ( (b==NULL)  (b>z==NULL))1256 if (b==NULL) 1256 1257 { 1257 1258 WerrorS(nDivBy0); … … 1262 1263 lo = (lnumber)omAllocBin(rnumber_bin); 1263 1264 if (b>n!=NULL) 1264 lo>z = napMultCopy(a>z, b>n);1265 lo>z = pp_Mult_qq(a>z, b>n,nacRing); 1265 1266 else 1266 1267 lo>z = napCopy(a>z); 1267 1268 if (a>n!=NULL) 1268 x = napMultCopy(b>z, a>n);1269 x = pp_Mult_qq(b>z, a>n, nacRing); 1269 1270 else 1270 1271 x = napCopy(b>z); 1271 1272 if (naMinimalPoly!=NULL) 1272 1273 { 1273 if ( napGetExp(lo>z,1) >= napGetExp(naMinimalPoly,1))1274 if (p_GetExp(lo>z,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 1274 1275 lo>z = napRemainder(lo>z, naMinimalPoly); 1275 if ( napGetExp(x,1) >= napGetExp(naMinimalPoly,1))1276 if (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 1276 1277 x = napRemainder(x, naMinimalPoly); 1277 1278 } … … 1351 1352 { 1352 1353 x = napInvers(x, naMinimalPoly); 1353 x = napMult(x, lo>z);1354 if ( napGetExp(x,1) >= napGetExp(naMinimalPoly,1))1354 x = p_Mult_q(x, lo>z,nacRing); 1355 if (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 1355 1356 x = napRemainder(x, naMinimalPoly); 1356 1357 lo>z = x; … … 1383 1384 if ((zb!=NULL) && (zb>z==NULL)) WerrorS("internal zero error(2)"); 1384 1385 #endif 1385 return ( (zb==NULL)  (zb>z==NULL));1386 return (zb==NULL); 1386 1387 } 1387 1388 … … 1394 1395 #endif 1395 1396 naTest(za); 1396 if ( (zb!=NULL) && (zb>z!=NULL))1397 if (zb!=NULL) 1397 1398 { 1398 1399 return (nacGreaterZero(pGetCoeff(zb>z))(!napIsConstant(zb>z))); … … 1464 1465 a = (lnumber)*p; 1465 1466 if ((naMinimalPoly!=NULL) 1466 && ( napGetExp(x,1) >= napGetExp(naMinimalPoly,1)))1467 && (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing))) 1467 1468 a>z = napRemainder(x, naMinimalPoly); 1468 1469 else if (naI!=NULL) … … 1494 1495 { 1495 1496 lnumber ph = (lnumber)n; 1496 if ( (ph==NULL)(ph>z==NULL))1497 if (ph==NULL) 1497 1498 return NULL; 1498 1499 int i; … … 1502 1503 for (i = 0; i <= naNumbOfPar  1; i++) 1503 1504 { 1504 if (napGetExp(ph>z,i+1) > 0) 1505 { 1506 if (napGetExp(ph>z,i+1) >1) 1505 int e=p_GetExp(ph>z,i+1,nacRing); 1506 if (e > 0) 1507 { 1508 if (e >1) 1507 1509 { 1508 sprintf(t,"%s%d",naParNames[i], (int)napGetExp(ph>z,i+1));1510 sprintf(t,"%s%d",naParNames[i],e); 1509 1511 strcat(s,t); 1510 1512 } … … 1530 1532 { 1531 1533 lnumber ph = (lnumber)phn; 1532 if ( (ph==NULL)(ph>z==NULL))1534 if (ph==NULL) 1533 1535 StringAppendS("0"); 1534 1536 else … … 1557 1559 omCheckAddrSize(a,sizeof(snumber)); 1558 1560 #ifdef LDEBUG 1559 if (a>z==NULL) WerrorS("internal zero error(4)"); 1561 if (a>z==NULL) 1562 { 1563 WerrorS("internal zero error(4)"); 1564 return FALSE; 1565 } 1560 1566 #endif 1561 1567 if (a>n==NULL) 1562 1568 { 1563 if (napIsConstant(a>z)) 1564 { 1565 #ifdef LDEBUG 1566 if (a>z==NULL) return FALSE; 1567 else 1568 #endif 1569 return nacIsOne(pGetCoeff(a>z)); 1569 if (napIsConstant(a>z)) 1570 { 1571 return nacIsOne(pGetCoeff(a>z)); 1570 1572 } 1571 1573 else return FALSE; … … 1583 1585 if (!nacIsZero(t)) 1584 1586 { 1585 n acDelete(&t,nacRing);1587 n_Delete(&t,nacRing); 1586 1588 return FALSE; 1587 1589 } 1588 1590 else 1589 n acDelete(&t,nacRing);1591 n_Delete(&t,nacRing); 1590 1592 } 1591 1593 pIter(x); … … 1652 1654 if (a==NULL) return naCopy(b); 1653 1655 if (b==NULL) return naCopy(a); 1654 1656 1655 1657 lnumber x, y; 1656 1658 lnumber result = (lnumber)omAlloc0Bin(rnumber_bin); … … 1676 1678 napoly rz=napGcd(x>z, y>z); 1677 1679 CanonicalForm F, G, R; 1678 R=convSingPFactoryP(rz,r>algring); 1680 R=convSingPFactoryP(rz,r>algring); 1679 1681 p_Normalize(x>z,nacRing); 1680 F=convSingPFactoryP(x>z,r>algring)/R; 1682 F=convSingPFactoryP(x>z,r>algring)/R; 1681 1683 p_Normalize(y>z,nacRing); 1682 G=convSingPFactoryP(y>z,r>algring)/R; 1684 G=convSingPFactoryP(y>z,r>algring)/R; 1683 1685 F = gcd( F, G ); 1684 if (F.isOne()) 1686 if (F.isOne()) 1685 1687 result>z= rz; 1686 1688 else … … 1711 1713 */ 1712 1714 //#define FACTORY_GCD_TEST 1715 void naCoefNormalize(number pp) 1716 { 1717 if (pp==NULL) return; 1718 lnumber p = (lnumber)pp; 1719 number nz; // all denom. of the numerator 1720 nz=p_GetAllDenom(p>z,nacRing); 1721 number nn; 1722 nn=p_GetAllDenom(p>n,nacRing); 1723 BOOLEAN norm=FALSE; 1724 if (!n_IsOne(nz,nacRing)) 1725 { 1726 norm=TRUE; 1727 p>z=p_Mult_nn(p>z,nz,nacRing); 1728 if (p>n==NULL) 1729 { 1730 p>n=p_NSet(nz,nacRing); 1731 } 1732 else 1733 { 1734 p>n=p_Mult_nn(p>n,nz,nacRing); 1735 n_Delete(&nz, nacRing); 1736 } 1737 } 1738 else 1739 { 1740 n_Delete(&nz, nacRing); 1741 } 1742 if (!n_IsOne(nn,nacRing)) 1743 { 1744 norm=TRUE; 1745 p>n=p_Mult_nn(p>n,nn,nacRing); 1746 p>z=p_Mult_nn(p>z,nn,nacRing); 1747 n_Delete(&nn, nacRing); 1748 } 1749 else 1750 { 1751 n_Delete(&nn, nacRing); 1752 } 1753 if (norm) 1754 { 1755 p_Normalize(p>z,nacRing); 1756 p_Normalize(p>n,nacRing); 1757 } 1758 if ((p>n!=NULL) 1759 && (p_IsConstant(p>n,nacRing)) 1760 && (n_IsOne(pGetCoeff(p>n),nacRing))) 1761 { 1762 p_Delete(&(p>n), nacRing); 1763 p>n = NULL; 1764 } 1765 } 1713 1766 void naNormalize(number &pp) 1714 1767 { … … 1719 1772 if ((p==NULL) /* (p>s==2)*/) 1720 1773 return; 1774 naCoefNormalize(pp); 1721 1775 p>s = 2; 1722 1776 napoly x = p>z; 1723 1777 napoly y = p>n; 1778 1779 BOOLEAN norm=FALSE; 1780 1724 1781 if ((y!=NULL) && (naMinimalPoly!=NULL)) 1725 1782 { 1726 1783 y = napInvers(y, naMinimalPoly); 1727 x = napMult(x, y);1728 if ( napGetExp(x,1) >= napGetExp(naMinimalPoly,1))1784 x = p_Mult_q(x, y,nacRing); 1785 if (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 1729 1786 x = napRemainder(x, naMinimalPoly); 1730 1787 p>z = x; 1731 1788 p>n = y = NULL; 1732 } 1789 norm=naIsChar0; 1790 } 1791 1733 1792 /* check for degree of x too high: */ 1734 1793 if ((x!=NULL) && (naMinimalPoly!=NULL) && (x!=naMinimalPoly) 1735 && ( napGetExp(x,1)>napGetExp(naMinimalPoly,1)))1794 && (p_GetExp(x,1,nacRing)>p_GetExp(naMinimalPoly,1,nacRing))) 1736 1795 // DO NOT REDUCE naMinimalPoly with itself 1737 1796 { 1738 1797 x = napRemainder(x, naMinimalPoly); 1739 1798 p>z = x; 1799 norm=naIsChar0; 1740 1800 } 1741 1801 /* normalize all coefficients in n and z (if in Q) */ 1742 if (naIsChar0) 1743 { 1744 while(x!=NULL) 1745 { 1746 nacNormalize(pGetCoeff(x)); 1747 pIter(x); 1748 } 1802 if (norm) 1803 { 1804 naCoefNormalize(pp); 1749 1805 x = p>z; 1806 y = p>n; 1750 1807 } 1751 1808 if (y==NULL) return; 1752 if (naIsChar0) 1753 { 1754 while(y!=NULL) 1755 { 1756 nacNormalize(pGetCoeff(y)); 1757 pIter(y); 1758 } 1759 y = p>n; 1760 // p>n !=NULL: 1761 /* collect all denoms from y and multiply x and y by it */ 1762 number n=napLcm(y); 1763 napMultN(x,n); 1764 napMultN(y,n); 1765 nacDelete(&n,nacRing); 1766 while(x!=NULL) 1767 { 1768 nacNormalize(pGetCoeff(x)); 1769 pIter(x); 1770 } 1771 x = p>z; 1772 while(y!=NULL) 1773 { 1774 nacNormalize(pGetCoeff(y)); 1775 pIter(y); 1776 } 1777 y = p>n; 1778 } 1809 1779 1810 if ((naMinimalPoly == NULL) && (x!=NULL) && (y!=NULL)) 1780 1811 { … … 1812 1843 nacNormalize(h1); 1813 1844 napMultN(x, h1); 1814 n acDelete(&h1,nacRing);1845 n_Delete(&h1,nacRing); 1815 1846 napDelete1(&y); 1816 1847 p>n = NULL; … … 1822 1853 { 1823 1854 napoly x1,y1; 1824 if ( napGetExp(x,1) >= napGetExp(y,1))1855 if (p_GetExp(x,1,nacRing) >= p_GetExp(y,1,nacRing)) 1825 1856 { 1826 1857 x1 = napCopy(x); … … 1859 1890 napMultN(x,n); 1860 1891 napMultN(y,n); 1861 n acDelete(&n,nacRing);1892 n_Delete(&n,nacRing); 1862 1893 while(x!=NULL) 1863 1894 { … … 1877 1908 if (nacIsOne(pGetCoeff(y))) 1878 1909 { 1879 if ( napGetExp(y,1)==0)1910 if (p_GetExp(y,1,nacRing)==0) 1880 1911 { 1881 1912 napDelete1(&y); … … 1919 1950 if(nacIsOne(d)) 1920 1951 { 1921 n acDelete(&g,nacRing);1922 n acDelete(&d,nacRing);1952 n_Delete(&g,nacRing); 1953 n_Delete(&d,nacRing); 1923 1954 naTest(pp); 1924 1955 return; 1925 1956 } 1926 n acDelete(&g,nacRing);1957 n_Delete(&g,nacRing); 1927 1958 g = d; 1928 1959 pIter(x); … … 1933 1964 if(nacIsOne(d)) 1934 1965 { 1935 n acDelete(&g,nacRing);1936 n acDelete(&d,nacRing);1966 n_Delete(&g,nacRing); 1967 n_Delete(&d,nacRing); 1937 1968 naTest(pp); 1938 1969 return; 1939 1970 } 1940 n acDelete(&g,nacRing);1971 n_Delete(&g,nacRing); 1941 1972 g = d; 1942 1973 pIter(y); … … 1956 1987 pIter(y); 1957 1988 } 1958 n acDelete(&g,nacRing);1989 n_Delete(&g,nacRing); 1959 1990 naTest(pp); 1960 1991 } … … 1988 2019 bt = nacGcd(t, pGetCoeff(xx), r>algring); 1989 2020 rr = nacMult(t, pGetCoeff(xx)); 1990 n acDelete(&pGetCoeff(xx),r>algring);2021 n_Delete(&pGetCoeff(xx),r>algring); 1991 2022 pGetCoeff(xx) = nacDiv(rr, bt); 1992 2023 nacNormalize(pGetCoeff(xx)); 1993 n acDelete(&bt,r>algring);1994 n acDelete(&rr,r>algring);2024 n_Delete(&bt,r>algring); 2025 n_Delete(&rr,r>algring); 1995 2026 pIter(xx); 1996 2027 } 1997 2028 } 1998 n acDelete(&t,r>algring);2029 n_Delete(&t,r>algring); 1999 2030 result>z = x; 2000 2031 #ifdef HAVE_FACTORY … … 2047 2078 a=nacCopy(pGetCoeff(x)); 2048 2079 number aa=nacInvers(a); 2049 n acDelete(&a,nacRing);2080 n_Delete(&a,nacRing); 2050 2081 napMultN(x,aa); 2051 n acDelete(&aa,nacRing);2082 n_Delete(&aa,nacRing); 2052 2083 } 2053 2084 } … … 2194 2225 } 2195 2226 /* else continue*/ 2196 n acDelete(&(pGetCoeff(w)),nacRing);2227 n_Delete(&(pGetCoeff(w)),nacRing); 2197 2228 } 2198 2229 else … … 2221 2252 if (naMinimalPoly!=NULL) 2222 2253 { 2223 if ( napGetExp(erg>z,1) >= napGetExp(naMinimalPoly,1))2254 if (p_GetExp(erg>z,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 2224 2255 { 2225 2256 erg>z = napRemainder(erg>z, naMinimalPoly); … … 2233 2264 if (erg>n!=NULL) 2234 2265 { 2235 if ( napGetExp(erg>n,1) >= napGetExp(naMinimalPoly,1))2266 if (p_GetExp(erg>n,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 2236 2267 erg>n = napRemainder(erg>n, naMinimalPoly); 2237 2268 if ((napIsConstant(erg>n)) && nacIsOne(pGetCoeff(erg>n))) … … 2456 2487 return FALSE; 2457 2488 } 2458 if((naMinimalPoly!=NULL)&&(napGetExp(p,1)>napGetExp(naMinimalPoly,1)) 2489 if((naMinimalPoly!=NULL) 2490 &&(p_GetExp(p,1,nacRing)>p_GetExp(naMinimalPoly,1,nacRing)) 2459 2491 &&(p!=naMinimalPoly)) 2460 2492 { … … 2481 2513 } 2482 2514 #endif 2483
Note: See TracChangeset
for help on using the changeset viewer.