- Timestamp:
- Feb 28, 2011, 5:36:07 PM (13 years ago)
- Branches:
- (u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'c5facdfddea2addfd91babd8b9019161dea4b695')
- Children:
- 0d6970109b48f04bc456f5aee530b7c06be12c64
- Parents:
- a33266f6b0236cbf3b512cbd4edad959fd94d6c3
- Location:
- kernel
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/clapconv.cc
ra33266 r661c214 18 18 #include <kernel/modulop.h> 19 19 #include <kernel/longalg.h> 20 #include <kernel/longtrans.h> 20 21 #include <kernel/polys.h> 21 22 #include <kernel/febase.h> … … 398 399 lnumber l=(lnumber)r->minpoly; 399 400 if (p_GetExp(a,1,r->algring) >= p_GetExp(l->z,1,r->algring)) 400 a = na pRemainder( a, l->z);401 a = naRemainder( a, l->z); 401 402 } 402 403 } -
kernel/clapconv.h
ra33266 r661c214 13 13 14 14 #include <kernel/structs.h> 15 #include <kernel/long alg.h>15 #include <kernel/longtrans.h> 16 16 #include <kernel/ring.h> 17 17 #ifdef HAVE_FACTORY -
kernel/clapsing.cc
ra33266 r661c214 602 602 { 603 603 lnumber c=(lnumber)pGetCoeff(p); 604 p_Delete(&c->z, nacRing);604 p_Delete(&c->z,currRing->algring); // 2nd arg used to be nacRing 605 605 c->z=convFactoryPSingP( i.getItem() / g, currRing->algring ); 606 606 //nTest((number)c); -
kernel/clapsing.h
ra33266 r661c214 17 17 #include <kernel/intvec.h> 18 18 #include <kernel/matpol.h> 19 #include <kernel/long alg.h>19 #include <kernel/longtrans.h> 20 20 21 21 poly singclap_gcd ( poly f, poly g ); -
kernel/longalg.cc
ra33266 r661c214 26 26 #endif 27 27 #include <kernel/longalg.h> 28 29 struct snaIdeal 30 { 31 int anz; 32 napoly *liste; 33 }; 34 typedef struct snaIdeal * naIdeal; 35 36 naIdeal naI=NULL; 37 38 omBin snaIdeal_bin = omGetSpecBin(sizeof(snaIdeal)); 39 40 int naNumbOfPar; 41 napoly naMinimalPoly; 42 #define naParNames (currRing->parameter) 43 static int naIsChar0; 44 static ring naMapRing; 28 #include <kernel/longtrans.h> 45 29 46 30 #ifdef LDEBUG … … 51 35 #endif 52 36 37 naIdeal naI = NULL; 38 napoly naMinimalPoly; 39 omBin snaIdeal_bin = omGetSpecBin(sizeof(snaIdeal)); 53 40 number (*naMap)(number from); 54 /* procedure variables */ 55 static numberfunc 56 nacMult, nacSub, nacAdd, nacDiv, nacIntDiv; 57 static number (*nacGcd)(number a, number b, const ring r); 58 static number (*nacLcm)(number a, number b, const ring r); 59 static number (*nacInit)(int i, const ring r); 60 static int (*nacInt)(number &n, const ring r); 61 static void (*nacDelete)(number *a, const ring r); 62 #undef n_Delete 63 #define n_Delete(A,R) nacDelete(A,R) 64 void (*nacNormalize)(number &a); 65 static number (*nacNeg)(number a); 66 number (*nacCopy)(number a); 67 static number (*nacInvers)(number a); 68 BOOLEAN (*nacIsZero)(number a); 69 static BOOLEAN (*nacIsOne)(number a); 70 static BOOLEAN (*nacIsMOne)(number a); 71 static BOOLEAN (*nacGreaterZero)(number a); 72 static const char * (*nacRead) (const char *s, number *a); 73 static napoly napRedp(napoly q); 74 static napoly napTailred(napoly q); 75 static BOOLEAN napDivPoly(napoly p, napoly q); 76 static int napExpi(int i, napoly a, napoly b); 77 ring nacRing; 78 79 void naCoefNormalize(number pp); 80 81 #define napCopy(p) p_Copy(p,nacRing) 82 83 static number nadGcd( number a, number b, const ring r) { return nacInit(1,r); } 41 42 static number nadGcd( number a, number b, const ring r) { return ntcInit(1,r); } 84 43 /*2 85 44 * sets the appropriate operators … … 120 79 } 121 80 122 n aNumbOfPar=rPar(r);81 ntNumbOfPar=rPar(r); 123 82 if (i == 1) 124 83 { 125 n aIsChar0 = 1;84 ntIsChar0 = 1; 126 85 } 127 86 else if (i < 0) 128 87 { 129 n aIsChar0 = 0;88 ntIsChar0 = 0; 130 89 npSetChar(-i, r->algring); // to be changed HS 131 90 } … … 137 96 #endif 138 97 nacRing = r->algring; 139 nacInit = nacRing->cf->cfInit; 140 nacInt = nacRing->cf->n_Int; 141 nacCopy = nacRing->cf->nCopy; 142 nacAdd = nacRing->cf->nAdd; 143 nacSub = nacRing->cf->nSub; 144 nacNormalize = nacRing->cf->nNormalize; 145 nacNeg = nacRing->cf->nNeg; 146 nacIsZero = nacRing->cf->nIsZero; 147 nacRead = nacRing->cf->nRead; 148 nacGreaterZero = nacRing->cf->nGreaterZero; 149 nacIsOne = nacRing->cf->nIsOne; 150 nacIsMOne = nacRing->cf->nIsMOne; 151 nacGcd = nacRing->cf->nGcd; 152 nacLcm = nacRing->cf->nLcm; 153 nacMult = nacRing->cf->nMult; 154 nacDiv = nacRing->cf->nDiv; 155 nacIntDiv = nacRing->cf->nIntDiv; 156 nacInvers = nacRing->cf->nInvers; 157 nacDelete = nacRing->cf->cfDelete; 158 } 159 160 /*============= procedure for polynomials: napXXXX =======================*/ 161 162 163 164 #ifdef LDEBUG 165 static void napTest(napoly p) 166 { 167 while (p != NULL) 168 { 169 if (naIsChar0) 170 nlDBTest(pGetCoeff(p), "", 0); 171 pIter(p); 172 } 173 } 174 #else 175 #define napTest(p) ((void) 0) 176 #endif 177 178 #define napSetCoeff(p,n) {n_Delete(&pGetCoeff(p),nacRing);pGetCoeff(p)=n;} 179 #define napComp(p,q) p_LmCmp((poly)p,(poly)q, nacRing) 180 #define napMultT(A,E) A=(napoly)p_Mult_mm((poly)A,(poly)E,nacRing) 181 #define napDeg(p) (int)p_Totaldegree(p, nacRing) 182 183 /*3 184 * creates an napoly 185 */ 186 napoly napInitz(number z) 187 { 188 napoly a = (napoly)p_Init(nacRing); 189 pGetCoeff(a) = z; 190 return a; 191 } 192 193 /*3 194 * copy a napoly. poly 195 */ 196 static napoly napCopyNeg(napoly p) 197 { 198 napoly r=napCopy(p); 199 r=(napoly)p_Neg((poly)r, nacRing); 200 return r; 201 } 202 203 /*3 204 * returns ph * z 205 */ 206 static void napMultN(napoly p, number z) 207 { 208 number t; 209 210 while (p!=NULL) 211 { 212 t = nacMult(pGetCoeff(p), z); 213 nacNormalize(t); 214 n_Delete(&pGetCoeff(p),nacRing); 215 pGetCoeff(p) = t; 216 pIter(p); 217 } 218 } 219 220 /*3 221 * division with remainder: f = g*q + r, 222 * returns r and destroys f 223 */ 224 napoly napRemainder(napoly f, const napoly g) 225 { 226 napoly a, h, qq; 227 228 qq = (napoly)p_Init(nacRing); 229 pNext(qq) = NULL; 230 p_Normalize(g, nacRing); 231 p_Normalize(f, nacRing); 232 a = f; 233 do 234 { 235 napSetExp(qq,1, p_GetExp(a,1,nacRing) - p_GetExp(g,1,nacRing)); 236 napSetm(qq); 237 pGetCoeff(qq) = nacDiv(pGetCoeff(a), pGetCoeff(g)); 238 pGetCoeff(qq) = nacNeg(pGetCoeff(qq)); 239 nacNormalize(pGetCoeff(qq)); 240 h = napCopy(g); 241 napMultT(h, qq); 242 p_Normalize(h,nacRing); 243 n_Delete(&pGetCoeff(qq),nacRing); 244 a = napAdd(a, h); 245 } 246 while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing))); 247 omFreeBinAddr(qq); 248 return a; 249 } 250 251 /*3 252 * division with rest; f = g*q + r, destroy f 253 */ 254 static void napDivMod(napoly f, napoly g, napoly *q, napoly *r) 255 { 256 napoly a, h, b, qq; 257 258 qq = (napoly)p_Init(nacRing); 259 pNext(qq) = b = NULL; 260 p_Normalize(g,nacRing); 261 p_Normalize(f,nacRing); 262 a = f; 263 do 264 { 265 napSetExp(qq,1, p_GetExp(a,1,nacRing) - p_GetExp(g,1,nacRing)); 266 p_Setm(qq,nacRing); 267 pGetCoeff(qq) = nacDiv(pGetCoeff(a), pGetCoeff(g)); 268 nacNormalize(pGetCoeff(qq)); 269 b = napAdd(b, napCopy(qq)); 270 pGetCoeff(qq) = nacNeg(pGetCoeff(qq)); 271 h = napCopy(g); 272 napMultT(h, qq); 273 p_Normalize(h,nacRing); 274 n_Delete(&pGetCoeff(qq),nacRing); 275 a = napAdd(a, h); 276 } 277 while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing))); 278 omFreeBinAddr(qq); 279 *q = b; 280 *r = a; 281 } 282 283 /*3 284 * returns z with z*x mod c = 1 285 */ 286 static napoly napInvers(napoly x, const napoly c) 287 { 288 napoly y, r, qa, qn, q; 289 number t, h; 290 291 if (p_GetExp(x,1,nacRing) >= p_GetExp(c,1,nacRing)) 292 x = napRemainder(x, c); 293 if (x==NULL) 294 { 295 goto zero_divisor; 296 } 297 if (p_GetExp(x,1,nacRing)==0) 298 { 299 if (!nacIsOne(pGetCoeff(x))) 300 { 301 nacNormalize(pGetCoeff(x)); 302 t = nacInvers(pGetCoeff(x)); 303 nacNormalize(t); 304 n_Delete(&pGetCoeff(x),nacRing); 305 pGetCoeff(x) = t; 306 } 307 return x; 308 } 309 y = napCopy(c); 310 napDivMod(y, x, &qa, &r); 311 if (r==NULL) 312 { 313 goto zero_divisor; 314 } 315 if (p_GetExp(r,1,nacRing)==0) 316 { 317 nacNormalize(pGetCoeff(r)); 318 t = nacInvers(pGetCoeff(r)); 319 nacNormalize(t); 320 t = nacNeg(t); 321 napMultN(qa, t); 322 n_Delete(&t,nacRing); 323 p_Normalize(qa,nacRing); 324 p_Delete(&x,nacRing); 325 p_Delete(&r,nacRing); 326 return qa; 327 } 328 y = x; 329 x = r; 330 napDivMod(y, x, &q, &r); 331 if (r==NULL) 332 { 333 goto zero_divisor; 334 } 335 if (p_GetExp(r,1,nacRing)==0) 336 { 337 q = p_Mult_q(q, qa,nacRing); 338 q = napAdd(q, p_ISet(1,nacRing)); 339 nacNormalize(pGetCoeff(r)); 340 t = nacInvers(pGetCoeff(r)); 341 napMultN(q, t); 342 p_Normalize(q,nacRing); 343 n_Delete(&t,nacRing); 344 p_Delete(&x,nacRing); 345 p_Delete(&r,nacRing); 346 if (p_GetExp(q,1,nacRing) >= p_GetExp(c,1,nacRing)) 347 q = napRemainder(q, c); 348 return q; 349 } 350 q = p_Mult_q(q, napCopy(qa),nacRing); 351 q = napAdd(q, p_ISet(1,nacRing)); 352 qa = napNeg(qa); 353 loop 354 { 355 y = x; 356 x = r; 357 napDivMod(y, x, &qn, &r); 358 if (r==NULL) 359 { 360 break; 361 } 362 if (p_GetExp(r,1,nacRing)==0) 363 { 364 q = p_Mult_q(q, qn,nacRing); 365 q = napNeg(q); 366 q = napAdd(q, qa); 367 nacNormalize(pGetCoeff(r)); 368 t = nacInvers(pGetCoeff(r)); 369 //nacNormalize(t); 370 napMultN(q, t); 371 p_Normalize(q,nacRing); 372 n_Delete(&t,nacRing); 373 p_Delete(&x,nacRing); 374 p_Delete(&r,nacRing); 375 if (p_GetExp(q,1,nacRing) >= p_GetExp(c,1,nacRing)) 376 q = napRemainder(q, c); 377 return q; 378 } 379 y = q; 380 q = p_Mult_q(napCopy(q), qn, nacRing); 381 q = napNeg(q); 382 q = napAdd(q, qa); 383 qa = y; 384 } 385 // zero divisor found: 386 zero_divisor: 387 Werror("zero divisor found - your minpoly is not irreducible"); 388 return x; 389 } 390 391 /*3 392 * the max degree of an napoly poly (used for test of "simple" et al.) 393 */ 394 static int napMaxDeg(napoly p) 395 { 396 int d = 0; 397 while(p!=NULL) 398 { 399 d=si_max(d,napDeg(p)); 400 pIter(p); 401 } 402 return d; 403 } 404 405 /*3 406 * the max degree of an napoly poly (used for test of "simple" et al.) 407 */ 408 static int napMaxDegLen(napoly p, int &l) 409 { 410 int d = 0; 411 int ll=0; 412 while(p!=NULL) 413 { 414 d=si_max(d,napDeg(p)); 415 pIter(p); 416 ll++; 417 } 418 l=ll; 419 return d; 420 } 421 422 423 /*3 424 *writes a polynomial number 425 */ 426 void napWrite(napoly p,const BOOLEAN has_denom, const ring r) 427 { 428 ring nacring=r->algring; 429 if (p==NULL) 430 StringAppendS("0"); 431 else if (p_LmIsConstant(p,nacring)) 432 { 433 BOOLEAN kl=FALSE; 434 if (has_denom) 435 { 436 number den=nacring->cf->cfGetDenom(pGetCoeff(p),nacring ); 437 kl=!n_IsOne(den,nacring); 438 n_Delete(&den, nacring); 439 } 440 if (kl) StringAppendS("("); 441 //StringAppendS("-1"); 442 n_Write(pGetCoeff(p),nacring); 443 if (kl) StringAppendS(")"); 444 } 445 else 446 { 447 StringAppendS("("); 448 loop 449 { 450 BOOLEAN wroteCoeff=FALSE; 451 if ((p_LmIsConstant(p,nacring)) 452 || ((!n_IsOne(pGetCoeff(p),nacring)) 453 && (!n_IsMOne(pGetCoeff(p),nacring)))) 454 { 455 n_Write(pGetCoeff(p),nacring); 456 wroteCoeff=(r->ShortOut==0); 457 } 458 else if (n_IsMOne(pGetCoeff(p),nacring)) 459 { 460 StringAppendS("-"); 461 } 462 int i; 463 for (i = 0; i < r->P; i++) 464 { 465 int e=p_GetExp(p,i+1,nacring); 466 if (e > 0) 467 { 468 if (wroteCoeff) 469 StringAppendS("*"); 470 else 471 wroteCoeff=(r->ShortOut==0); 472 StringAppendS(r->parameter[i]); 473 if (e > 1) 474 { 475 if (r->ShortOut == 0) 476 StringAppendS("^"); 477 StringAppend("%d", e); 478 } 479 } 480 } /*for*/ 481 pIter(p); 482 if (p==NULL) 483 break; 484 if (n_GreaterZero(pGetCoeff(p),nacring)) 485 StringAppendS("+"); 486 } 487 StringAppendS(")"); 488 } 489 } 490 491 492 static const char *napHandleMons(const char *s, int i, napoly ex) 493 { 494 int j; 495 if (strncmp(s,naParNames[i],strlen(naParNames[i]))==0) 496 { 497 s+=strlen(naParNames[i]); 498 if ((*s >= '0') && (*s <= '9')) 499 { 500 s = eati(s, &j); 501 napAddExp(ex,i+1,j); 502 } 503 else 504 napAddExp(ex,i+1,1); 505 } 506 return s; 507 } 508 static const char *napHandlePars(const char *s, int i, napoly ex) 509 { 510 int j; 511 if (strcmp(s,naParNames[i])==0) 512 { 513 s+=strlen(naParNames[i]); 514 napSetExp(ex,i+1,1); 515 } 516 return s; 517 } 518 519 /*3 reads a monomial */ 520 static const char *napRead(const char *s, napoly *b) 521 { 522 napoly a; 523 int i; 524 a = (napoly)p_Init(nacRing); 525 if ((*s >= '0') && (*s <= '9')) 526 { 527 s = nacRead(s, &pGetCoeff(a)); 528 if (nacIsZero(pGetCoeff(a))) 529 { 530 p_LmDelete(&a,nacRing); 531 *b = NULL; 532 return s; 533 } 534 } 535 else 536 pGetCoeff(a) = nacInit(1,nacRing); 537 i = 0; 538 const char *olds=s; 539 loop 540 { 541 s = napHandlePars(s, i, a); 542 if (olds == s) 543 i++; 544 else if (*s == '\0') 545 { 546 *b = a; 547 return s; 548 } 549 if (i >= naNumbOfPar) 550 break; 551 } 552 i=0; 553 loop 554 { 555 olds = s; 556 s = napHandleMons(s, i, a); 557 if (olds == s) 558 i++; 559 else 560 i = 0; 561 if ((*s == '\0') || (i >= naNumbOfPar)) 562 break; 563 } 564 *b = a; 565 return s; 566 } 567 568 static int napExp(napoly a, napoly b) 569 { 570 while (pNext(a)!=NULL) pIter(a); 571 int m = p_GetExp(a,1,nacRing); 572 if (m==0) return 0; 573 while (pNext(b)!=NULL) pIter(b); 574 int mm=p_GetExp(b,1,nacRing); 575 if (m > mm) m = mm; 576 return m; 577 } 578 579 /* 580 * finds the smallest i-th exponent in a and b 581 * used to find it in a fraction 582 */ 583 static int napExpi(int i, napoly a, napoly b) 584 { 585 if (a==NULL || b==NULL) return 0; 586 int m = p_GetExp(a,i+1,nacRing); 587 if (m==0) return 0; 588 while (pNext(a) != NULL) 589 { 590 pIter(a); 591 if (m > p_GetExp(a,i+1,nacRing)) 592 { 593 m = p_GetExp(a,i+1,nacRing); 594 if (m==0) return 0; 595 } 596 } 597 do 598 { 599 if (m > p_GetExp(b,i+1,nacRing)) 600 { 601 m = p_GetExp(b,i+1,nacRing); 602 if (m==0) return 0; 603 } 604 pIter(b); 605 } 606 while (b != NULL); 607 return m; 608 } 609 610 static void napContent(napoly ph) 611 { 612 number h,d; 613 napoly p; 614 615 p = ph; 616 if (nacIsOne(pGetCoeff(p))) 617 return; 618 h = nacCopy(pGetCoeff(p)); 619 pIter(p); 620 do 621 { 622 d=nacGcd(pGetCoeff(p), h, nacRing); 623 if(nacIsOne(d)) 624 { 625 n_Delete(&h,nacRing); 626 n_Delete(&d,nacRing); 627 return; 628 } 629 n_Delete(&h,nacRing); 630 h = d; 631 pIter(p); 632 } 633 while (p!=NULL); 634 h = nacInvers(d); 635 n_Delete(&d,nacRing); 636 p = ph; 637 while (p!=NULL) 638 { 639 d = nacMult(pGetCoeff(p), h); 640 n_Delete(&pGetCoeff(p),nacRing); 641 pGetCoeff(p) = d; 642 pIter(p); 643 } 644 n_Delete(&h,nacRing); 645 } 646 647 static void napCleardenom(napoly ph) 648 { 649 number d, h; 650 napoly p; 651 652 if (!naIsChar0) 653 return; 654 p = ph; 655 h = nacInit(1,nacRing); 656 while (p!=NULL) 657 { 658 d = nacLcm(h, pGetCoeff(p), nacRing); 659 n_Delete(&h,nacRing); 660 h = d; 661 pIter(p); 662 } 663 if(!nacIsOne(h)) 664 { 665 p = ph; 666 while (p!=NULL) 667 { 668 d=nacMult(h, pGetCoeff(p)); 669 n_Delete(&pGetCoeff(p),nacRing); 670 nacNormalize(d); 671 pGetCoeff(p) = d; 672 pIter(p); 673 } 674 n_Delete(&h,nacRing); 675 } 676 napContent(ph); 677 } 678 679 static napoly napGcd0(napoly a, napoly b) 680 { 681 number x, y; 682 if (!naIsChar0) 683 return p_ISet(1,nacRing); 684 x = nacCopy(pGetCoeff(a)); 685 if (nacIsOne(x)) 686 return napInitz(x); 687 while (pNext(a)!=NULL) 688 { 689 pIter(a); 690 y = nacGcd(x, pGetCoeff(a), nacRing); 691 n_Delete(&x,nacRing); 692 x = y; 693 if (nacIsOne(x)) 694 return napInitz(x); 695 } 696 do 697 { 698 y = nacGcd(x, pGetCoeff(b), nacRing); 699 n_Delete(&x,nacRing); 700 x = y; 701 if (nacIsOne(x)) 702 return napInitz(x); 703 pIter(b); 704 } 705 while (b!=NULL); 706 return napInitz(x); 707 } 708 709 /*3 710 * result =gcd(a,b) 711 */ 712 static napoly napGcd(napoly a, napoly b) 713 { 714 int i; 715 napoly g, x, y, h; 716 if ((a==NULL) 717 || ((pNext(a)==NULL)&&(nacIsZero(pGetCoeff(a))))) 718 { 719 if ((b==NULL) 720 || ((pNext(b)==NULL)&&(nacIsZero(pGetCoeff(b))))) 721 { 722 return p_ISet(1,nacRing); 723 } 724 return napCopy(b); 725 } 726 else 727 if ((b==NULL) 728 || ((pNext(b)==NULL)&&(nacIsZero(pGetCoeff(b))))) 729 { 730 return napCopy(a); 731 } 732 if (naMinimalPoly != NULL) 733 { 734 if (p_GetExp(a,1,nacRing) >= p_GetExp(b,1,nacRing)) 735 { 736 x = a; 737 y = b; 738 } 739 else 740 { 741 x = b; 742 y = a; 743 } 744 if (!naIsChar0) g = p_ISet(1,nacRing); 745 else g = napGcd0(x, y); 746 if (pNext(y)==NULL) 747 { 748 napSetExp(g,1, napExp(x, y)); 749 p_Setm(g,nacRing); 750 return g; 751 } 752 x = napCopy(x); 753 y = napCopy(y); 754 loop 755 { 756 h = napRemainder(x, y); 757 if (h==NULL) 758 { 759 napCleardenom(y); 760 if (!nacIsOne(pGetCoeff(g))) 761 napMultN(y, pGetCoeff(g)); 762 p_LmDelete(&g,nacRing); 763 return y; 764 } 765 else if (pNext(h)==NULL) 766 break; 767 x = y; 768 y = h; 769 } 770 p_Delete(&y,nacRing); 771 p_LmDelete(&h,nacRing); 772 napSetExp(g,1, napExp(a, b)); 773 p_Setm(g,nacRing); 774 return g; 775 } 776 // Hmm ... this is a memory leak 777 // x = (napoly)p_Init(nacRing); 778 g=a; 779 h=b; 780 if (!naIsChar0) x = p_ISet(1,nacRing); 781 else x = napGcd0(g,h); 782 for (i=(naNumbOfPar-1); i>=0; i--) 783 { 784 napSetExp(x,i+1, napExpi(i,a,b)); 785 p_Setm(x,nacRing); 786 } 787 return x; 788 } 789 790 791 number napLcm(napoly a) 792 { 793 number h = nacInit(1,nacRing); 794 795 if (naIsChar0) 796 { 797 number d; 798 napoly b = a; 799 800 while (b!=NULL) 801 { 802 d = nacLcm(h, pGetCoeff(b), nacRing); 803 n_Delete(&h,nacRing); 804 h = d; 805 pIter(b); 806 } 807 } 808 return h; 809 } 810 811 812 /*2 813 * meins (for reduction in algebraic extension) 814 * checks if head of p divides head of q 815 * doesn't delete p and q 816 */ 817 static BOOLEAN napDivPoly (napoly p, napoly q) 818 { 819 int j=1; /* evtl. von naNumber.. -1 abwaerts zaehlen */ 820 821 while (p_GetExp(p,j,nacRing) <= p_GetExp(q,j,nacRing)) 822 { 823 j++; 824 if (j > naNumbOfPar) 825 return 1; 826 } 827 return 0; 828 } 829 830 831 /*2 832 * meins (for reduction in algebraic extension) 833 * Normalform of poly with naI 834 * changes q and returns it 835 */ 836 napoly napRedp (napoly q) 837 { 838 napoly h = (napoly)p_Init(nacRing); 839 int i=0,j; 840 841 loop 842 { 843 if (napDivPoly (naI->liste[i], q)) 844 { 845 /* h = lt(q)/lt(naI->liste[i])*/ 846 pGetCoeff(h) = nacCopy(pGetCoeff(q)); 847 for (j=naNumbOfPar; j>0; j--) 848 napSetExp(h,j, p_GetExp(q,j,nacRing) - p_GetExp(naI->liste[i],j,nacRing)); 849 p_Setm(h,nacRing); 850 h = p_Mult_q(h, napCopy(naI->liste[i]),nacRing); 851 h = napNeg (h); 852 q = napAdd (q, napCopy(h)); 853 p_Delete (&pNext(h),nacRing); 854 if (q == NULL) 855 { 856 p_Delete(&h,nacRing); 857 return q; 858 } 859 /* try to reduce further */ 860 i = 0; 861 } 862 else 863 { 864 i++; 865 if (i >= naI->anz) 866 { 867 p_Delete(&h,nacRing); 868 return q; 869 } 870 } 871 } 872 } 873 874 875 /*2 876 * meins (for reduction in algebraic extension) 877 * reduces the tail of Poly q 878 * needs q != NULL 879 * changes q and returns it 880 */ 881 napoly napTailred (napoly q) 882 { 883 napoly h; 884 885 h = pNext(q); 886 while (h != NULL) 887 { 888 h = napRedp (h); 889 if (h == NULL) 890 return q; 891 pIter(h); 892 } 893 return q; 894 } 895 98 ntcInit = nacRing->cf->cfInit; 99 ntcInt = nacRing->cf->n_Int; 100 ntcCopy = nacRing->cf->nCopy; 101 ntcAdd = nacRing->cf->nAdd; 102 ntcSub = nacRing->cf->nSub; 103 ntcNormalize = nacRing->cf->nNormalize; 104 ntcNeg = nacRing->cf->nNeg; 105 ntcIsZero = nacRing->cf->nIsZero; 106 ntcRead = nacRing->cf->nRead; 107 ntcGreaterZero = nacRing->cf->nGreaterZero; 108 ntcIsOne = nacRing->cf->nIsOne; 109 ntcIsMOne = nacRing->cf->nIsMOne; 110 ntcGcd = nacRing->cf->nGcd; 111 ntcLcm = nacRing->cf->nLcm; 112 ntcMult = nacRing->cf->nMult; 113 ntcDiv = nacRing->cf->nDiv; 114 ntcIntDiv = nacRing->cf->nIntDiv; 115 ntcInvers = nacRing->cf->nInvers; 116 ntcDelete = nacRing->cf->cfDelete; 117 } 896 118 897 119 /*================ procedure for rational functions: naXXXX =================*/ … … 963 185 if ((l!=NULL)&&(l->n==NULL)&&(p_IsConstant(l->z,r->algring))) 964 186 { 965 return n acInt(pGetCoeff(l->z),r->algring);187 return ntcInt(pGetCoeff(l->z),r->algring); 966 188 } 967 189 return 0; … … 1052 274 // if (p_LmIsConstant(x,nacRing)) 1053 275 // { 1054 // number inv=n acInvers(pGetCoeff(x));276 // number inv=ntcInvers(pGetCoeff(x)); 1055 277 // napMultN(lu->z,inv); 1056 278 // n_Delete(&inv,nacRing); … … 1177 399 { 1178 400 if (p_GetExp(lo->z,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 1179 lo->z = na pRemainder(lo->z, naMinimalPoly);401 lo->z = naRemainder(lo->z, naMinimalPoly); 1180 402 if ((x!=NULL) && (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing))) 1181 x = na pRemainder(x, naMinimalPoly);403 x = naRemainder(x, naMinimalPoly); 1182 404 } 1183 405 if (naI!=NULL) … … 1193 415 } 1194 416 } 1195 if ((x!=NULL) && (p_LmIsConstant(x,nacRing)) && n acIsOne(pGetCoeff(x)))417 if ((x!=NULL) && (p_LmIsConstant(x,nacRing)) && ntcIsOne(pGetCoeff(x))) 1196 418 p_Delete(&x,nacRing); 1197 419 lo->n = x; … … 1277 499 { 1278 500 if (p_GetExp(lo->z,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 1279 lo->z = na pRemainder(lo->z, naMinimalPoly);501 lo->z = naRemainder(lo->z, naMinimalPoly); 1280 502 if (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 1281 x = na pRemainder(x, naMinimalPoly);503 x = naRemainder(x, naMinimalPoly); 1282 504 } 1283 505 if (naI!=NULL) … … 1293 515 } 1294 516 } 1295 if ((p_LmIsConstant(x,nacRing)) && n acIsOne(pGetCoeff(x)))517 if ((p_LmIsConstant(x,nacRing)) && ntcIsOne(pGetCoeff(x))) 1296 518 p_Delete(&x,nacRing); 1297 519 lo->n = x; … … 1348 570 lo->z = p_ISet(1,nacRing); 1349 571 x = b->z; 1350 if ((!p_LmIsConstant(x,nacRing)) || !n acIsOne(pGetCoeff(x)))572 if ((!p_LmIsConstant(x,nacRing)) || !ntcIsOne(pGetCoeff(x))) 1351 573 x = napCopy(x); 1352 574 else … … 1361 583 x = p_Mult_q(x, lo->z,nacRing); 1362 584 if (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 1363 x = na pRemainder(x, naMinimalPoly);585 x = naRemainder(x, naMinimalPoly); 1364 586 lo->z = x; 1365 587 lo->n = NULL; 1366 588 while (x!=NULL) 1367 589 { 1368 n acNormalize(pGetCoeff(x));590 ntcNormalize(pGetCoeff(x)); 1369 591 pIter(x); 1370 592 } … … 1405 627 if (zb!=NULL) 1406 628 { 1407 return (n acGreaterZero(pGetCoeff(zb->z))||(!p_LmIsConstant(zb->z,nacRing)));629 return (ntcGreaterZero(pGetCoeff(zb->z))||(!p_LmIsConstant(zb->z,nacRing))); 1408 630 } 1409 631 /* else */ return FALSE; … … 1474 696 if ((naMinimalPoly!=NULL) 1475 697 && (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing))) 1476 a->z = na pRemainder(x, naMinimalPoly);698 a->z = naRemainder(x, naMinimalPoly); 1477 699 else if (naI!=NULL) 1478 700 { … … 1506 728 return NULL; 1507 729 int i; 1508 char *s=(char *)omAlloc(4* n aNumbOfPar);730 char *s=(char *)omAlloc(4* ntNumbOfPar); 1509 731 char *t=(char *)omAlloc(8); 1510 732 s[0]='\0'; 1511 for (i = 0; i <= n aNumbOfPar - 1; i++)733 for (i = 0; i <= ntNumbOfPar - 1; i++) 1512 734 { 1513 735 int e=p_GetExp(ph->z,i+1,nacRing); … … 1576 798 if (p_LmIsConstant(a->z,nacRing)) 1577 799 { 1578 return n acIsOne(pGetCoeff(a->z));800 return ntcIsOne(pGetCoeff(a->z)); 1579 801 } 1580 802 else return FALSE; … … 1589 811 else 1590 812 { 1591 t = n acSub(pGetCoeff(x), pGetCoeff(y));1592 if (!n acIsZero(t))813 t = ntcSub(pGetCoeff(x), pGetCoeff(y)); 814 if (!ntcIsZero(t)) 1593 815 { 1594 816 n_Delete(&t,nacRing); … … 1632 854 if (a->n==NULL) 1633 855 { 1634 if (p_LmIsConstant(a->z,nacRing)) return n acIsMOne(pGetCoeff(a->z));856 if (p_LmIsConstant(a->z,nacRing)) return ntcIsMOne(pGetCoeff(a->z)); 1635 857 /*else return FALSE;*/ 1636 858 } … … 1666 888 x = (lnumber)a; 1667 889 y = (lnumber)b; 1668 if ((n aNumbOfPar == 1) && (naMinimalPoly!=NULL))890 if ((ntNumbOfPar == 1) && (naMinimalPoly!=NULL)) 1669 891 { 1670 892 if (pNext(x->z)!=NULL) … … 1706 928 1707 929 /*2 1708 * n aNumbOfPar = 1:930 * ntNumbOfPar = 1: 1709 931 * clears denominator algebraic case; 1710 932 * tries to simplify ratio transcendental case; … … 1712 934 * cancels monomials 1713 935 * occuring in denominator 1714 * and enumerator ? n aNumbOfPar != 1;936 * and enumerator ? ntNumbOfPar != 1; 1715 937 * 1716 938 * #defines for Factory: … … 1810 1032 if (p->n!=NULL) 1811 1033 { 1812 if(!n acGreaterZero(pGetCoeff(p->n)))1034 if(!ntcGreaterZero(pGetCoeff(p->n))) 1813 1035 { 1814 1036 p->z=napNeg(p->z); … … 1846 1068 x = p_Mult_q(x, y,nacRing); 1847 1069 if (p_GetExp(x,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 1848 x = na pRemainder(x, naMinimalPoly);1070 x = naRemainder(x, naMinimalPoly); 1849 1071 p->z = x; 1850 1072 p->n = y = NULL; 1851 norm=n aIsChar0;1073 norm=ntIsChar0; 1852 1074 } 1853 1075 … … 1857 1079 // DO NOT REDUCE naMinimalPoly with itself 1858 1080 { 1859 x = na pRemainder(x, naMinimalPoly);1081 x = naRemainder(x, naMinimalPoly); 1860 1082 p->z = x; 1861 norm=n aIsChar0;1083 norm=ntIsChar0; 1862 1084 } 1863 1085 /* normalize all coefficients in n and z (if in Q) */ … … 1873 1095 { 1874 1096 int i; 1875 for (i=n aNumbOfPar-1; i>=0; i--)1097 for (i=ntNumbOfPar-1; i>=0; i--) 1876 1098 { 1877 1099 napoly xx=x; … … 1895 1117 if (p_LmIsConstant(y,nacRing)) /* i.e. => simplify to (1/c)*z / monom */ 1896 1118 { 1897 if (n acIsOne(pGetCoeff(y)))1119 if (ntcIsOne(pGetCoeff(y))) 1898 1120 { 1899 1121 p_LmDelete(&y,nacRing); … … 1902 1124 return; 1903 1125 } 1904 number h1 = n acInvers(pGetCoeff(y));1905 n acNormalize(h1);1126 number h1 = ntcInvers(pGetCoeff(y)); 1127 ntcNormalize(h1); 1906 1128 napMultN(x, h1); 1907 1129 n_Delete(&h1,nacRing); … … 1912 1134 } 1913 1135 #ifndef FACTORY_GCD_TEST 1914 if (n aNumbOfPar == 1) /* apply built-in gcd */1136 if (ntNumbOfPar == 1) /* apply built-in gcd */ 1915 1137 { 1916 1138 napoly x1,y1; … … 1928 1150 loop 1929 1151 { 1930 r = na pRemainder(x1, y1);1152 r = naRemainder(x1, y1); 1931 1153 if ((r==NULL) || (pNext(r)==NULL)) break; 1932 1154 x1 = y1; … … 1947 1169 y = p->n; 1948 1170 /* collect all denoms from y and multiply x and y by it */ 1949 if (n aIsChar0)1171 if (ntIsChar0) 1950 1172 { 1951 1173 number n=napLcm(y); … … 1955 1177 while(x!=NULL) 1956 1178 { 1957 n acNormalize(pGetCoeff(x));1179 ntcNormalize(pGetCoeff(x)); 1958 1180 pIter(x); 1959 1181 } … … 1961 1183 while(y!=NULL) 1962 1184 { 1963 n acNormalize(pGetCoeff(y));1185 ntcNormalize(pGetCoeff(y)); 1964 1186 pIter(y); 1965 1187 } … … 1968 1190 if (pNext(y)==NULL) 1969 1191 { 1970 if (n acIsOne(pGetCoeff(y)))1192 if (ntcIsOne(pGetCoeff(y))) 1971 1193 { 1972 1194 if (p_GetExp(y,1,nacRing)==0) … … 2000 1222 x=p->z; 2001 1223 y=p->n; 2002 if(!n acGreaterZero(pGetCoeff(y)))1224 if(!ntcGreaterZero(pGetCoeff(y))) 2003 1225 { 2004 1226 x=napNeg(x); 2005 1227 y=napNeg(y); 2006 1228 } 2007 number g=n acCopy(pGetCoeff(x));1229 number g=ntcCopy(pGetCoeff(x)); 2008 1230 pIter(x); 2009 1231 while (x!=NULL) 2010 1232 { 2011 number d=n acGcd(g,pGetCoeff(x), nacRing);2012 if(n acIsOne(d))1233 number d=ntcGcd(g,pGetCoeff(x), nacRing); 1234 if(ntcIsOne(d)) 2013 1235 { 2014 1236 n_Delete(&g,nacRing); … … 2023 1245 while (y!=NULL) 2024 1246 { 2025 number d=n acGcd(g,pGetCoeff(y), nacRing);2026 if(n acIsOne(d))1247 number d=ntcGcd(g,pGetCoeff(y), nacRing); 1248 if(ntcIsOne(d)) 2027 1249 { 2028 1250 n_Delete(&g,nacRing); … … 2039 1261 while (x!=NULL) 2040 1262 { 2041 number d = n acIntDiv(pGetCoeff(x),g);1263 number d = ntcIntDiv(pGetCoeff(x),g); 2042 1264 napSetCoeff(x,d); 2043 1265 pIter(x); … … 2045 1267 while (y!=NULL) 2046 1268 { 2047 number d = n acIntDiv(pGetCoeff(y),g);1269 number d = ntcIntDiv(pGetCoeff(y),g); 2048 1270 napSetCoeff(y,d); 2049 1271 pIter(y); … … 2063 1285 lnumber b = (lnumber)lb; 2064 1286 result = (lnumber)omAlloc0Bin(rnumber_bin); 2065 //if (((naMinimalPoly==NULL) && (naI==NULL)) || !n aIsChar0)1287 //if (((naMinimalPoly==NULL) && (naI==NULL)) || !ntIsChar0) 2066 1288 //{ 2067 1289 // result->z = p_ISet(1,nacRing); … … 2073 1295 napoly x = p_Copy(a->z, r->algring); 2074 1296 number t = napLcm(b->z); // get all denom of b->z 2075 if (!n acIsOne(t))1297 if (!ntcIsOne(t)) 2076 1298 { 2077 1299 number bt, rr; … … 2079 1301 while (xx!=NULL) 2080 1302 { 2081 bt = n acGcd(t, pGetCoeff(xx), r->algring);2082 rr = n acMult(t, pGetCoeff(xx));1303 bt = ntcGcd(t, pGetCoeff(xx), r->algring); 1304 rr = ntcMult(t, pGetCoeff(xx)); 2083 1305 n_Delete(&pGetCoeff(xx),r->algring); 2084 pGetCoeff(xx) = n acDiv(rr, bt);2085 n acNormalize(pGetCoeff(xx));1306 pGetCoeff(xx) = ntcDiv(rr, bt); 1307 ntcNormalize(pGetCoeff(xx)); 2086 1308 n_Delete(&bt,r->algring); 2087 1309 n_Delete(&rr,r->algring); … … 2134 1356 naI->liste[i]=napCopy(h->z); 2135 1357 /* If it isn't normalized (lc = 1) do this */ 2136 if (!n acIsOne(pGetCoeff(naI->liste[i])))1358 if (!ntcIsOne(pGetCoeff(naI->liste[i]))) 2137 1359 { 2138 1360 x=naI->liste[i]; 2139 n acNormalize(pGetCoeff(x));2140 a=n acCopy(pGetCoeff(x));2141 number aa=n acInvers(a);1361 ntcNormalize(pGetCoeff(x)); 1362 a=ntcCopy(pGetCoeff(x)); 1363 number aa=ntcInvers(a); 2142 1364 n_Delete(&a,nacRing); 2143 1365 napMultN(x,aa); … … 2158 1380 l->z=(napoly)p_Init(nacRing); 2159 1381 int i=(int)((long)c); 2160 if (i>((long)n aMapRing->ch>>2)) i-=(long)naMapRing->ch;1382 if (i>((long)ntMapRing->ch>>2)) i-=(long)ntMapRing->ch; 2161 1383 pGetCoeff(l->z)=nlInit(i, nacRing); 2162 1384 l->n=NULL; … … 2199 1421 if (npIsZero(c)) return NULL; 2200 1422 int i=(int)((long)c); 2201 if (i>(long)n aMapRing->ch) i-=(long)naMapRing->ch;2202 number n=npInit(i,n aMapRing);1423 if (i>(long)ntMapRing->ch) i-=(long)ntMapRing->ch; 1424 number n=npInit(i,ntMapRing); 2203 1425 if (npIsZero(n)) return NULL; 2204 1426 lnumber l=(lnumber)omAllocBin(rnumber_bin); … … 2227 1449 } 2228 1450 2229 static number (*nacMap)(number);2230 static int naParsToCopy;2231 static napoly napMap(napoly p)2232 {2233 napoly w, a;2234 2235 if (p==NULL) return NULL;2236 a = w = (napoly)p_Init(nacRing);2237 int i;2238 for(i=1;i<=naParsToCopy;i++)2239 napSetExp(a,i,napGetExpFrom(p,i,naMapRing));2240 p_Setm(a,nacRing);2241 pGetCoeff(w) = nacMap(pGetCoeff(p));2242 loop2243 {2244 pIter(p);2245 if (p==NULL) break;2246 pNext(a) = (napoly)p_Init(nacRing);2247 pIter(a);2248 for(i=1;i<=naParsToCopy;i++)2249 napSetExp(a,i,napGetExpFrom(p,i,naMapRing));2250 p_Setm(a,nacRing);2251 pGetCoeff(a) = nacMap(pGetCoeff(p));2252 }2253 pNext(a) = NULL;2254 return w;2255 }2256 2257 static napoly napPerm(napoly p,const int *par_perm,const ring src_ring,const nMapFunc nMap)2258 {2259 napoly w, a;2260 2261 if (p==NULL) return NULL;2262 w = (napoly)p_Init(nacRing);2263 int i;2264 BOOLEAN not_null=TRUE;2265 loop2266 {2267 for(i=1;i<=rPar(src_ring);i++)2268 {2269 int e;2270 if (par_perm!=NULL) e=par_perm[i-1];2271 else e=-i;2272 int ee=napGetExpFrom(p,i,src_ring);2273 if (e<0)2274 napSetExp(w,-e,ee);2275 else if (ee>0)2276 not_null=FALSE;2277 }2278 pGetCoeff(w) = nMap(pGetCoeff(p));2279 p_Setm(w,nacRing);2280 pIter(p);2281 if (!not_null)2282 {2283 if (p==NULL)2284 {2285 p_Delete(&w,nacRing);2286 return NULL;2287 }2288 /* else continue*/2289 n_Delete(&(pGetCoeff(w)),nacRing);2290 }2291 else2292 {2293 if (p==NULL) return w;2294 else2295 {2296 pNext(w)=napPerm(p,par_perm,src_ring,nMap);2297 return w;2298 }2299 }2300 }2301 }2302 2303 1451 /*2 2304 1452 * map _(a) -> _(b) … … 2316 1464 if (p_GetExp(erg->z,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 2317 1465 { 2318 erg->z = na pRemainder(erg->z, naMinimalPoly);1466 erg->z = naRemainder(erg->z, naMinimalPoly); 2319 1467 if (erg->z==NULL) 2320 1468 { … … 2327 1475 { 2328 1476 if (p_GetExp(erg->n,1,nacRing) >= p_GetExp(naMinimalPoly,1,nacRing)) 2329 erg->n = na pRemainder(erg->n, naMinimalPoly);2330 if ((p_IsConstant(erg->n,nacRing)) && n acIsOne(pGetCoeff(erg->n)))1477 erg->n = naRemainder(erg->n, naMinimalPoly); 1478 if ((p_IsConstant(erg->n,nacRing)) && ntcIsOne(pGetCoeff(erg->n))) 2331 1479 p_Delete(&(erg->n),nacRing); 2332 1480 } … … 2337 1485 nMapFunc naSetMap(const ring src, const ring dst) 2338 1486 { 2339 n aMapRing=src;1487 ntMapRing=src; 2340 1488 if (rField_is_Q_a(dst)) /* -> Q(a) */ 2341 1489 { … … 2351 1499 { 2352 1500 int i; 2353 n aParsToCopy=0;1501 ntParsToCopy=0; 2354 1502 for(i=0;i<rPar(src);i++) 2355 1503 { … … 2357 1505 ||(strcmp(src->parameter[i],dst->parameter[i])!=0)) 2358 1506 return NULL; 2359 n aParsToCopy++;1507 ntParsToCopy++; 2360 1508 } 2361 n acMap=nacCopy;2362 if ((n aParsToCopy==rPar(dst))&&(naParsToCopy==rPar(src)))1509 ntcMap=ntcCopy; 1510 if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src))) 2363 1511 return naCopy; /* Q(a) -> Q(a) */ 2364 1512 return naMapQaQb; /* Q(a..) -> Q(a..) */ … … 2387 1535 if (rChar(src)==rChar(dst)) 2388 1536 { 2389 n acMap=nacCopy;1537 ntcMap=ntcCopy; 2390 1538 } 2391 1539 else 2392 1540 { 2393 n acMap = npMapP;1541 ntcMap = npMapP; 2394 1542 } 2395 1543 int i; 2396 n aParsToCopy=0;1544 ntParsToCopy=0; 2397 1545 for(i=0;i<rPar(src);i++) 2398 1546 { … … 2400 1548 ||(strcmp(src->parameter[i],dst->parameter[i])!=0)) 2401 1549 return NULL; 2402 n aParsToCopy++;1550 ntParsToCopy++; 2403 1551 } 2404 if ((n aParsToCopy==rPar(dst))&&(naParsToCopy==rPar(src))2405 && (n acMap==nacCopy))1552 if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src)) 1553 && (ntcMap==ntcCopy)) 2406 1554 return naCopy; /* Z/p(a) -> Z/p(a) */ 2407 1555 return naMapQaQb; /* Z/p(a),Z/p'(a) -> Z/p(b)*/ … … 2409 1557 } 2410 1558 return NULL; /* default */ 2411 }2412 2413 /*22414 * convert a napoly number into a poly2415 */2416 poly naPermNumber(number z, int * par_perm, int P, ring oldRing)2417 {2418 if (z==NULL) return NULL;2419 poly res=NULL;2420 poly p;2421 napoly za=((lnumber)z)->z;2422 napoly zb=((lnumber)z)->n;2423 nMapFunc nMap=naSetMap(oldRing,currRing);2424 if (currRing->parameter!=NULL)2425 nMap=currRing->algring->cf->cfSetMap(oldRing->algring, nacRing);2426 else2427 nMap=currRing->cf->cfSetMap(oldRing->algring, currRing);2428 if (nMap==NULL) return NULL; /* emergency exit only */2429 do2430 {2431 p = pInit();2432 pNext(p)=NULL;2433 nNew(&pGetCoeff(p));2434 int i;2435 for(i=pVariables;i;i--)2436 pSetExp(p,i, 0);2437 if (rRing_has_Comp(currRing)) pSetComp(p, 0);2438 napoly pa=NULL;2439 lnumber pan;2440 if (currRing->parameter!=NULL)2441 {2442 assume(oldRing->algring!=NULL);2443 pGetCoeff(p)=(number)omAlloc0Bin(rnumber_bin);2444 pan=(lnumber)pGetCoeff(p);2445 pan->s=2;2446 pan->z=napInitz(nMap(pGetCoeff(za)));2447 pa=pan->z;2448 }2449 else2450 {2451 pGetCoeff(p)=nMap(pGetCoeff(za));2452 }2453 for(i=0;i<P;i++)2454 {2455 if(napGetExpFrom(za,i+1,oldRing)!=0)2456 {2457 if(par_perm==NULL)2458 {2459 if ((rPar(currRing)>=i) && (pa!=NULL))2460 {2461 napSetExp(pa,i+1,napGetExpFrom(za,i+1,oldRing));2462 p_Setm(pa,nacRing);2463 }2464 else2465 {2466 pDelete(&p);2467 break;2468 }2469 }2470 else if(par_perm[i]>0)2471 pSetExp(p,par_perm[i],napGetExpFrom(za,i+1,oldRing));2472 else if((par_perm[i]<0)&&(pa!=NULL))2473 {2474 napSetExp(pa,-par_perm[i], napGetExpFrom(za,i+1,oldRing));2475 p_Setm(pa,nacRing);2476 }2477 else2478 {2479 pDelete(&p);2480 break;2481 }2482 }2483 }2484 if (p!=NULL)2485 {2486 pSetm(p);2487 if (zb!=NULL)2488 {2489 if (currRing->P>0)2490 {2491 pan->n=napPerm(zb,par_perm,oldRing,nMap);2492 if(pan->n==NULL) /* error in mapping or mapping to variable */2493 pDelete(&p);2494 }2495 else2496 pDelete(&p);2497 }2498 pTest(p);2499 res=pAdd(res,p);2500 }2501 pIter(za);2502 }2503 while (za!=NULL);2504 pTest(res);2505 return res;2506 }2507 2508 number naGetDenom(number &n, const ring r)2509 {2510 lnumber x=(lnumber)n;2511 if (x->n!=NULL)2512 {2513 lnumber rr=(lnumber)omAlloc0Bin(rnumber_bin);2514 rr->z=p_Copy(x->n,r->algring);2515 rr->s = 2;2516 return (number)rr;2517 }2518 return n_Init(1,r);2519 }2520 2521 number naGetNumerator(number &n, const ring r)2522 {2523 lnumber x=(lnumber)n;2524 lnumber rr=(lnumber)omAlloc0Bin(rnumber_bin);2525 rr->z=p_Copy(x->z,r->algring);2526 rr->s = 2;2527 return (number)rr;2528 1559 } 2529 1560 … … 2545 1576 while(p!=NULL) 2546 1577 { 2547 if ((n aIsChar0 && nlIsZero(pGetCoeff(p)))2548 || ((!n aIsChar0) && npIsZero(pGetCoeff(p))))1578 if ((ntIsChar0 && nlIsZero(pGetCoeff(p))) 1579 || ((!ntIsChar0) && npIsZero(pGetCoeff(p)))) 2549 1580 { 2550 1581 Print("coeff 0 in %s:%d\n",f,l); … … 2558 1589 return FALSE; 2559 1590 } 2560 //if (n aIsChar0 && (((int)p->ko &3) == 0) && (p->ko->s==0) && (x->s==2))1591 //if (ntIsChar0 && (((int)p->ko &3) == 0) && (p->ko->s==0) && (x->s==2)) 2561 1592 //{ 2562 1593 // Print("normalized with non-normal coeffs in %s:%d\n",f,l); 2563 1594 // return FALSE; 2564 1595 //} 2565 if (n aIsChar0 && !(nlDBTest(pGetCoeff(p),f,l)))1596 if (ntIsChar0 && !(nlDBTest(pGetCoeff(p),f,l))) 2566 1597 return FALSE; 2567 1598 pIter(p); … … 2570 1601 while(p!=NULL) 2571 1602 { 2572 if (n aIsChar0 && !(nlDBTest(pGetCoeff(p),f,l)))1603 if (ntIsChar0 && !(nlDBTest(pGetCoeff(p),f,l))) 2573 1604 return FALSE; 2574 1605 pIter(p); -
kernel/longalg.h
ra33266 r661c214 11 11 #include <kernel/longrat.h> 12 12 #include <kernel/polys-impl.h> 13 #include <kernel/longtrans.h> 13 14 14 typedef polyrec * napoly; 15 struct snaIdeal 16 { 17 int anz; 18 napoly *liste; 19 }; 20 typedef struct snaIdeal * naIdeal; 21 extern omBin snaIdeal_bin; 22 extern naIdeal naI; 23 extern napoly naMinimalPoly; 15 24 16 struct slnumber; 17 typedef struct slnumber * lnumber; 18 19 struct slnumber 20 { 21 napoly z; 22 napoly n; 23 BOOLEAN s; 24 }; 25 26 extern napoly naMinimalPoly; 27 extern ring nacRing; 28 extern int naNumbOfPar; 29 30 void naSetChar(int p, ring r); 25 void naSetChar(int p, ring r); 31 26 void naDelete (number *p, const ring r); 32 27 number naInit(int i, const ring r); /* z := i */ … … 64 59 BOOLEAN naDBTest(number a, const char *f,const int l); 65 60 #endif 61 napoly naRemainder(napoly f, const napoly g); 62 void naSetIdeal(ideal I); 63 extern number (*naMap)(number from); 64 void naCoefNormalize(number pp); 66 65 67 void naSetIdeal(ideal I);68 69 // external access to the interna70 poly naPermNumber(number z, int * par_perm, int P, ring r);71 #define napAddExp(p,i,e) (p_AddExp(p,i,e,currRing->algring))72 #define napLength(p) pLength(p)73 #define napNeg(p) (p_Neg(p,currRing->algring))74 #define napVariables naNumbOfPar75 #define napGetCoeff(p) pGetCoeff(p)76 #define napGetExpFrom(p,i,r) (p_GetExp(p,i,r->algring))77 #define napSetExp(p,i,e) (p_SetExp(p,i,e,currRing->algring))78 #define napNew() (p_Init(currRing->algring))79 #define napAdd(p1,p2) (p_Add_q(p1,p2,currRing->algring))80 #define napSetm(p) p_Setm(p,currRing->algring)81 // #define nanumber lnumber82 napoly napRemainder(napoly f, const napoly g);83 number naGetDenom(number &n, const ring r);84 number naGetNumerator(number &n, const ring r);85 66 #endif 86 67 -
kernel/longtrans.cc
ra33266 r661c214 26 26 #include <kernel/clapconv.h> 27 27 #endif 28 #include <kernel/longtrans.h> 28 29 #include <kernel/longalg.h> 29 #include <kernel/longtrans.h> 30 31 struct sntIdeal 32 { 33 int anz; 34 napoly *liste; 35 }; 36 typedef struct sntIdeal * ntIdeal; 37 38 ntIdeal ntI=NULL; 39 40 omBin sntIdeal_bin = omGetSpecBin(sizeof(sntIdeal)); 41 42 #define ntParNames (currRing->parameter) 43 static int ntIsChar0; 44 static ring ntMapRing; 30 31 ring nacRing; 32 int ntIsChar0; 33 ring ntMapRing; 34 int ntParsToCopy; 35 int ntNumbOfPar; 36 37 number (*ntMap)(number from); 38 numberfunc ntcMult, ntcSub, ntcAdd, ntcDiv, ntcIntDiv; 39 number (*ntcGcd)(number a, number b, const ring r); 40 number (*ntcLcm)(number a, number b, const ring r); 41 number (*ntcInit)(int i, const ring r); 42 int (*ntcInt)(number &n, const ring r); 43 void (*ntcDelete)(number *a, const ring r); 44 void (*ntcNormalize)(number &a); 45 number (*ntcNeg)(number a); 46 number (*ntcCopy)(number a); 47 number (*ntcInvers)(number a); 48 BOOLEAN (*ntcIsZero)(number a); 49 BOOLEAN (*ntcIsOne)(number a); 50 BOOLEAN (*ntcIsMOne)(number a); 51 BOOLEAN (*ntcGreaterZero)(number a); 52 const char * (*ntcRead) (const char *s, number *a); 53 number (*ntcMap)(number); 45 54 46 55 #ifdef LDEBUG … … 51 60 #endif 52 61 53 number (*ntMap)(number from);54 /* procedure variables */55 static numberfunc56 ntcMult, ntcSub, ntcAdd, ntcDiv, ntcIntDiv;57 static number (*ntcGcd)(number a, number b, const ring r);58 static number (*ntcLcm)(number a, number b, const ring r);59 static number (*ntcInit)(int i, const ring r);60 static int (*ntcInt)(number &n, const ring r);61 static void (*ntcDelete)(number *a, const ring r);62 #undef n_Delete63 #define n_Delete(A,R) ntcDelete(A,R)64 void (*ntcNormalize)(number &a);65 static number (*ntcNeg)(number a);66 number (*ntcCopy)(number a);67 static number (*ntcInvers)(number a);68 BOOLEAN (*ntcIsZero)(number a);69 static BOOLEAN (*ntcIsOne)(number a);70 static BOOLEAN (*ntcIsMOne)(number a);71 static BOOLEAN (*ntcGreaterZero)(number a);72 static const char * (*ntcRead) (const char *s, number *a);73 static napoly ntpRedp(napoly q);74 static napoly ntpTailred(napoly q);75 static BOOLEAN ntpDivPoly(napoly p, napoly q);76 static int ntpExpi(int i, napoly a, napoly b);77 ring ntcRing;78 79 void ntCoefNormalize(number pp);80 81 #define ntpCopy(p) p_Copy(p,ntcRing)82 83 62 static number ntdGcd( number a, number b, const ring r) { return ntcInit(1,r); } 84 63 /*2 … … 87 66 void ntSetChar(int i, ring r) 88 67 { 89 if (n tI!=NULL)68 if (naI!=NULL) 90 69 { 91 70 int j; 92 for (j=n tI->anz-1; j>=0; j--)93 p_Delete (&n tI->liste[j],ntcRing);94 omFreeSize((ADDRESS)n tI->liste,ntI->anz*sizeof(napoly));95 omFreeBin((ADDRESS)n tI, sntIdeal_bin);96 n tI=NULL;71 for (j=naI->anz-1; j>=0; j--) 72 p_Delete (&naI->liste[j],nacRing); 73 omFreeSize((ADDRESS)naI->liste,naI->anz*sizeof(napoly)); 74 omFreeBin((ADDRESS)naI, snaIdeal_bin); 75 naI=NULL; 97 76 } 98 77 ntMap = ntCopy; 78 79 naMinimalPoly = NULL; 99 80 100 81 if (r->minideal!=NULL) 101 82 { 102 n tI=(ntIdeal)omAllocBin(sntIdeal_bin);103 n tI->anz=IDELEMS(r->minideal);104 n tI->liste=(napoly*)omAlloc(ntI->anz*sizeof(napoly));83 naI=(naIdeal)omAllocBin(snaIdeal_bin); 84 naI->anz=IDELEMS(r->minideal); 85 naI->liste=(napoly*)omAlloc(naI->anz*sizeof(napoly)); 105 86 int j; 106 for (j=n tI->anz-1; j>=0; j--)87 for (j=naI->anz-1; j>=0; j--) 107 88 { 108 89 lnumber a = (lnumber)pGetCoeff(r->minideal->m[j]); 109 n tI->liste[j]=ntpCopy(a->z);110 } 111 } 112 113 n aNumbOfPar=rPar(r);90 naI->liste[j]=napCopy(a->z); 91 } 92 } 93 94 ntNumbOfPar=rPar(r); 114 95 if (i == 1) 115 96 { … … 127 108 } 128 109 #endif 129 ntcRing = r->algring; 130 ntcInit = ntcRing->cf->cfInit; 131 ntcInt = ntcRing->cf->n_Int; 132 ntcCopy = ntcRing->cf->nCopy; 133 ntcAdd = ntcRing->cf->nAdd; 134 ntcSub = ntcRing->cf->nSub; 135 ntcNormalize = ntcRing->cf->nNormalize; 136 ntcNeg = ntcRing->cf->nNeg; 137 ntcIsZero = ntcRing->cf->nIsZero; 138 ntcRead = ntcRing->cf->nRead; 139 ntcGreaterZero = ntcRing->cf->nGreaterZero; 140 ntcIsOne = ntcRing->cf->nIsOne; 141 ntcIsMOne = ntcRing->cf->nIsMOne; 142 ntcGcd = ntcRing->cf->nGcd; 143 ntcLcm = ntcRing->cf->nLcm; 144 ntcMult = ntcRing->cf->nMult; 145 ntcDiv = ntcRing->cf->nDiv; 146 ntcIntDiv = ntcRing->cf->nIntDiv; 147 ntcInvers = ntcRing->cf->nInvers; 148 ntcDelete = ntcRing->cf->cfDelete; 149 } 150 151 /*============= procedure for polynomials: ntpXXXX =======================*/ 152 153 110 nacRing = r->algring; 111 ntcInit = nacRing->cf->cfInit; 112 ntcInt = nacRing->cf->n_Int; 113 ntcCopy = nacRing->cf->nCopy; 114 ntcAdd = nacRing->cf->nAdd; 115 ntcSub = nacRing->cf->nSub; 116 ntcNormalize = nacRing->cf->nNormalize; 117 ntcNeg = nacRing->cf->nNeg; 118 ntcIsZero = nacRing->cf->nIsZero; 119 ntcRead = nacRing->cf->nRead; 120 ntcGreaterZero = nacRing->cf->nGreaterZero; 121 ntcIsOne = nacRing->cf->nIsOne; 122 ntcIsMOne = nacRing->cf->nIsMOne; 123 ntcGcd = nacRing->cf->nGcd; 124 ntcLcm = nacRing->cf->nLcm; 125 ntcMult = nacRing->cf->nMult; 126 ntcDiv = nacRing->cf->nDiv; 127 ntcIntDiv = nacRing->cf->nIntDiv; 128 ntcInvers = nacRing->cf->nInvers; 129 ntcDelete = nacRing->cf->cfDelete; 130 } 131 132 /*============= procedure for polynomials: napXXXX =======================*/ 154 133 155 134 #ifdef LDEBUG 156 static void ntpTest(napoly p)135 void napTest(napoly p) 157 136 { 158 137 while (p != NULL) … … 164 143 } 165 144 #else 166 #define n tpTest(p) ((void) 0)145 #define napTest(p) ((void) 0) 167 146 #endif 168 147 169 #define ntpSetCoeff(p,n) {n_Delete(&pGetCoeff(p),ntcRing);pGetCoeff(p)=n;}170 #define ntpComp(p,q) p_LmCmp((poly)p,(poly)q, ntcRing)171 #define ntpMultT(A,E) A=(napoly)p_Mult_mm((poly)A,(poly)E,ntcRing)172 #define ntpDeg(p) (int)p_Totaldegree(p, ntcRing)173 174 148 /*3 175 * creates an napoly176 */ 177 napoly n tpInitz(number z)178 { 179 napoly a = (napoly)p_Init(n tcRing);149 * creates an napoly 150 */ 151 napoly napInitz(number z) 152 { 153 napoly a = (napoly)p_Init(nacRing); 180 154 pGetCoeff(a) = z; 181 155 return a; … … 185 159 * copy a napoly. poly 186 160 */ 187 static napoly ntpCopyNeg(napoly p)188 { 189 napoly r=n tpCopy(p);190 r=(napoly)p_Neg((poly)r, n tcRing);161 napoly napCopyNeg(napoly p) 162 { 163 napoly r=napCopy(p); 164 r=(napoly)p_Neg((poly)r, nacRing); 191 165 return r; 192 166 } … … 195 169 * returns ph * z 196 170 */ 197 static void ntpMultN(napoly p, number z)171 void napMultN(napoly p, number z) 198 172 { 199 173 number t; … … 203 177 t = ntcMult(pGetCoeff(p), z); 204 178 ntcNormalize(t); 205 n_Delete(&pGetCoeff(p),n tcRing);179 n_Delete(&pGetCoeff(p),nacRing); 206 180 pGetCoeff(p) = t; 207 181 pIter(p); … … 210 184 211 185 /*3 212 * division with rest; f = g*q + r, destroy f 213 */ 214 static void ntpDivMod(napoly f, napoly g, napoly *q, napoly *r) 215 { 216 napoly a, h, b, qq; 217 218 qq = (napoly)p_Init(ntcRing); 219 pNext(qq) = b = NULL; 220 p_Normalize(g,ntcRing); 221 p_Normalize(f,ntcRing); 186 * division with remainder: f = g*q + r, 187 * returns r and destroys f 188 */ 189 napoly naRemainder(napoly f, const napoly g) 190 { 191 napoly a, h, qq; 192 193 qq = (napoly)p_Init(nacRing); 194 pNext(qq) = NULL; 195 p_Normalize(g, nacRing); 196 p_Normalize(f, nacRing); 222 197 a = f; 223 198 do 224 199 { 225 napSetExp(qq,1, p_GetExp(a,1,ntcRing) - p_GetExp(g,1,ntcRing)); 226 p_Setm(qq,ntcRing); 200 napSetExp(qq,1, p_GetExp(a,1,nacRing) - p_GetExp(g,1,nacRing)); 201 napSetm(qq); 202 pGetCoeff(qq) = ntcDiv(pGetCoeff(a), pGetCoeff(g)); 203 pGetCoeff(qq) = ntcNeg(pGetCoeff(qq)); 204 ntcNormalize(pGetCoeff(qq)); 205 h = napCopy(g); 206 napMultT(h, qq); 207 p_Normalize(h,nacRing); 208 n_Delete(&pGetCoeff(qq),nacRing); 209 a = napAdd(a, h); 210 } 211 while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing))); 212 omFreeBinAddr(qq); 213 return a; 214 } 215 216 /*3 217 * division with rest; f = g*q + r, destroy f 218 */ 219 void napDivMod(napoly f, napoly g, napoly *q, napoly *r) 220 { 221 napoly a, h, b, qq; 222 223 qq = (napoly)p_Init(nacRing); 224 pNext(qq) = b = NULL; 225 p_Normalize(g,nacRing); 226 p_Normalize(f,nacRing); 227 a = f; 228 do 229 { 230 napSetExp(qq,1, p_GetExp(a,1,nacRing) - p_GetExp(g,1,nacRing)); 231 p_Setm(qq,nacRing); 227 232 pGetCoeff(qq) = ntcDiv(pGetCoeff(a), pGetCoeff(g)); 228 233 ntcNormalize(pGetCoeff(qq)); 229 b = napAdd(b, n tpCopy(qq));234 b = napAdd(b, napCopy(qq)); 230 235 pGetCoeff(qq) = ntcNeg(pGetCoeff(qq)); 231 h = n tpCopy(g);232 n tpMultT(h, qq);233 p_Normalize(h,n tcRing);234 n_Delete(&pGetCoeff(qq),n tcRing);236 h = napCopy(g); 237 napMultT(h, qq); 238 p_Normalize(h,nacRing); 239 n_Delete(&pGetCoeff(qq),nacRing); 235 240 a = napAdd(a, h); 236 241 } 237 while ((a!=NULL) && (p_GetExp(a,1,n tcRing) >= p_GetExp(g,1,ntcRing)));242 while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing))); 238 243 omFreeBinAddr(qq); 239 244 *q = b; … … 244 249 * returns z with z*x mod c = 1 245 250 */ 246 static napoly ntpInvers(napoly x, const napoly c)251 napoly napInvers(napoly x, const napoly c) 247 252 { 248 253 napoly y, r, qa, qn, q; 249 254 number t, h; 250 255 251 if (p_GetExp(x,1,n tcRing) >= p_GetExp(c,1,ntcRing))252 x = na pRemainder(x, c);256 if (p_GetExp(x,1,nacRing) >= p_GetExp(c,1,nacRing)) 257 x = naRemainder(x, c); 253 258 if (x==NULL) 254 259 { 255 260 goto zero_divisor; 256 261 } 257 if (p_GetExp(x,1,n tcRing)==0)262 if (p_GetExp(x,1,nacRing)==0) 258 263 { 259 264 if (!ntcIsOne(pGetCoeff(x))) … … 262 267 t = ntcInvers(pGetCoeff(x)); 263 268 ntcNormalize(t); 264 n_Delete(&pGetCoeff(x),n tcRing);269 n_Delete(&pGetCoeff(x),nacRing); 265 270 pGetCoeff(x) = t; 266 271 } 267 272 return x; 268 273 } 269 y = n tpCopy(c);270 n tpDivMod(y, x, &qa, &r);274 y = napCopy(c); 275 napDivMod(y, x, &qa, &r); 271 276 if (r==NULL) 272 277 { 273 278 goto zero_divisor; 274 279 } 275 if (p_GetExp(r,1,n tcRing)==0)280 if (p_GetExp(r,1,nacRing)==0) 276 281 { 277 282 ntcNormalize(pGetCoeff(r)); … … 279 284 ntcNormalize(t); 280 285 t = ntcNeg(t); 281 n tpMultN(qa, t);282 n_Delete(&t,n tcRing);283 p_Normalize(qa,n tcRing);284 p_Delete(&x,n tcRing);285 p_Delete(&r,n tcRing);286 napMultN(qa, t); 287 n_Delete(&t,nacRing); 288 p_Normalize(qa,nacRing); 289 p_Delete(&x,nacRing); 290 p_Delete(&r,nacRing); 286 291 return qa; 287 292 } 288 293 y = x; 289 294 x = r; 290 n tpDivMod(y, x, &q, &r);295 napDivMod(y, x, &q, &r); 291 296 if (r==NULL) 292 297 { 293 298 goto zero_divisor; 294 299 } 295 if (p_GetExp(r,1,n tcRing)==0)296 { 297 q = p_Mult_q(q, qa,n tcRing);298 q = napAdd(q, p_ISet(1,n tcRing));300 if (p_GetExp(r,1,nacRing)==0) 301 { 302 q = p_Mult_q(q, qa,nacRing); 303 q = napAdd(q, p_ISet(1,nacRing)); 299 304 ntcNormalize(pGetCoeff(r)); 300 305 t = ntcInvers(pGetCoeff(r)); 301 n tpMultN(q, t);302 p_Normalize(q,n tcRing);303 n_Delete(&t,n tcRing);304 p_Delete(&x,n tcRing);305 p_Delete(&r,n tcRing);306 if (p_GetExp(q,1,n tcRing) >= p_GetExp(c,1,ntcRing))307 q = na pRemainder(q, c);306 napMultN(q, t); 307 p_Normalize(q,nacRing); 308 n_Delete(&t,nacRing); 309 p_Delete(&x,nacRing); 310 p_Delete(&r,nacRing); 311 if (p_GetExp(q,1,nacRing) >= p_GetExp(c,1,nacRing)) 312 q = naRemainder(q, c); 308 313 return q; 309 314 } 310 q = p_Mult_q(q, n tpCopy(qa),ntcRing);311 q = napAdd(q, p_ISet(1,n tcRing));315 q = p_Mult_q(q, napCopy(qa),nacRing); 316 q = napAdd(q, p_ISet(1,nacRing)); 312 317 qa = napNeg(qa); 313 318 loop … … 315 320 y = x; 316 321 x = r; 317 n tpDivMod(y, x, &qn, &r);322 napDivMod(y, x, &qn, &r); 318 323 if (r==NULL) 319 324 { 320 325 break; 321 326 } 322 if (p_GetExp(r,1,n tcRing)==0)323 { 324 q = p_Mult_q(q, qn,n tcRing);327 if (p_GetExp(r,1,nacRing)==0) 328 { 329 q = p_Mult_q(q, qn,nacRing); 325 330 q = napNeg(q); 326 331 q = napAdd(q, qa); … … 328 333 t = ntcInvers(pGetCoeff(r)); 329 334 //ntcNormalize(t); 330 n tpMultN(q, t);331 p_Normalize(q,n tcRing);332 n_Delete(&t,n tcRing);333 p_Delete(&x,n tcRing);334 p_Delete(&r,n tcRing);335 if (p_GetExp(q,1,n tcRing) >= p_GetExp(c,1,ntcRing))336 q = na pRemainder(q, c);335 napMultN(q, t); 336 p_Normalize(q,nacRing); 337 n_Delete(&t,nacRing); 338 p_Delete(&x,nacRing); 339 p_Delete(&r,nacRing); 340 if (p_GetExp(q,1,nacRing) >= p_GetExp(c,1,nacRing)) 341 q = naRemainder(q, c); 337 342 return q; 338 343 } 339 344 y = q; 340 q = p_Mult_q(n tpCopy(q), qn, ntcRing);345 q = p_Mult_q(napCopy(q), qn, nacRing); 341 346 q = napNeg(q); 342 347 q = napAdd(q, qa); … … 352 357 * the max degree of an napoly poly (used for test of "simple" et al.) 353 358 */ 354 static int ntpMaxDeg(napoly p)359 int napMaxDeg(napoly p) 355 360 { 356 361 int d = 0; 357 362 while(p!=NULL) 358 363 { 359 d=si_max(d,n tpDeg(p));364 d=si_max(d,napDeg(p)); 360 365 pIter(p); 361 366 } … … 366 371 * the max degree of an napoly poly (used for test of "simple" et al.) 367 372 */ 368 static int ntpMaxDegLen(napoly p, int &l)373 int napMaxDegLen(napoly p, int &l) 369 374 { 370 375 int d = 0; … … 372 377 while(p!=NULL) 373 378 { 374 d=si_max(d,n tpDeg(p));379 d=si_max(d,napDeg(p)); 375 380 pIter(p); 376 381 ll++; … … 384 389 *writes a polynomial number 385 390 */ 386 void n tpWrite(napoly p,const BOOLEAN has_denom, const ring r)387 { 388 ring n tcring=r->algring;391 void napWrite(napoly p,const BOOLEAN has_denom, const ring r) 392 { 393 ring nacring=r->algring; 389 394 if (p==NULL) 390 395 StringAppendS("0"); 391 else if (p_LmIsConstant(p,n tcring))396 else if (p_LmIsConstant(p,nacring)) 392 397 { 393 398 BOOLEAN kl=FALSE; 394 399 if (has_denom) 395 400 { 396 number den=n tcring->cf->cfGetDenom(pGetCoeff(p),ntcring );397 kl=!n_IsOne(den,n tcring);398 n_Delete(&den, n tcring);401 number den=nacring->cf->cfGetDenom(pGetCoeff(p),nacring ); 402 kl=!n_IsOne(den,nacring); 403 n_Delete(&den, nacring); 399 404 } 400 405 if (kl) StringAppendS("("); 401 406 //StringAppendS("-1"); 402 n_Write(pGetCoeff(p),n tcring);407 n_Write(pGetCoeff(p),nacring); 403 408 if (kl) StringAppendS(")"); 404 409 } … … 409 414 { 410 415 BOOLEAN wroteCoeff=FALSE; 411 if ((p_LmIsConstant(p,n tcring))412 || ((!n_IsOne(pGetCoeff(p),n tcring))413 && (!n_IsMOne(pGetCoeff(p),n tcring))))414 { 415 n_Write(pGetCoeff(p),n tcring);416 if ((p_LmIsConstant(p,nacring)) 417 || ((!n_IsOne(pGetCoeff(p),nacring)) 418 && (!n_IsMOne(pGetCoeff(p),nacring)))) 419 { 420 n_Write(pGetCoeff(p),nacring); 416 421 wroteCoeff=(r->ShortOut==0); 417 422 } 418 else if (n_IsMOne(pGetCoeff(p),n tcring))423 else if (n_IsMOne(pGetCoeff(p),nacring)) 419 424 { 420 425 StringAppendS("-"); … … 423 428 for (i = 0; i < r->P; i++) 424 429 { 425 int e=p_GetExp(p,i+1,n tcring);430 int e=p_GetExp(p,i+1,nacring); 426 431 if (e > 0) 427 432 { … … 442 447 if (p==NULL) 443 448 break; 444 if (n_GreaterZero(pGetCoeff(p),n tcring))449 if (n_GreaterZero(pGetCoeff(p),nacring)) 445 450 StringAppendS("+"); 446 451 } … … 450 455 451 456 452 static const char *ntpHandleMons(const char *s, int i, napoly ex)457 const char *napHandleMons(const char *s, int i, napoly ex) 453 458 { 454 459 int j; 455 if (strncmp(s,n tParNames[i],strlen(ntParNames[i]))==0)456 { 457 s+=strlen(n tParNames[i]);460 if (strncmp(s,naParNames[i],strlen(naParNames[i]))==0) 461 { 462 s+=strlen(naParNames[i]); 458 463 if ((*s >= '0') && (*s <= '9')) 459 464 { … … 466 471 return s; 467 472 } 468 static const char *ntpHandlePars(const char *s, int i, napoly ex)473 const char *napHandlePars(const char *s, int i, napoly ex) 469 474 { 470 475 int j; 471 if (strcmp(s,n tParNames[i])==0)472 { 473 s+=strlen(n tParNames[i]);476 if (strcmp(s,naParNames[i])==0) 477 { 478 s+=strlen(naParNames[i]); 474 479 napSetExp(ex,i+1,1); 475 480 } … … 478 483 479 484 /*3 reads a monomial */ 480 static const char *ntpRead(const char *s, napoly *b)485 const char *napRead(const char *s, napoly *b) 481 486 { 482 487 napoly a; 483 488 int i; 484 a = (napoly)p_Init(n tcRing);489 a = (napoly)p_Init(nacRing); 485 490 if ((*s >= '0') && (*s <= '9')) 486 491 { … … 488 493 if (ntcIsZero(pGetCoeff(a))) 489 494 { 490 p_LmDelete(&a,n tcRing);495 p_LmDelete(&a,nacRing); 491 496 *b = NULL; 492 497 return s; … … 494 499 } 495 500 else 496 pGetCoeff(a) = ntcInit(1,n tcRing);501 pGetCoeff(a) = ntcInit(1,nacRing); 497 502 i = 0; 498 503 const char *olds=s; 499 504 loop 500 505 { 501 s = n tpHandlePars(s, i, a);506 s = napHandlePars(s, i, a); 502 507 if (olds == s) 503 508 i++; … … 507 512 return s; 508 513 } 509 if (i >= n aNumbOfPar)514 if (i >= ntNumbOfPar) 510 515 break; 511 516 } … … 514 519 { 515 520 olds = s; 516 s = n tpHandleMons(s, i, a);521 s = napHandleMons(s, i, a); 517 522 if (olds == s) 518 523 i++; 519 524 else 520 525 i = 0; 521 if ((*s == '\0') || (i >= n aNumbOfPar))526 if ((*s == '\0') || (i >= ntNumbOfPar)) 522 527 break; 523 528 } … … 526 531 } 527 532 528 static int ntpExp(napoly a, napoly b)533 int napExp(napoly a, napoly b) 529 534 { 530 535 while (pNext(a)!=NULL) pIter(a); 531 int m = p_GetExp(a,1,n tcRing);536 int m = p_GetExp(a,1,nacRing); 532 537 if (m==0) return 0; 533 538 while (pNext(b)!=NULL) pIter(b); 534 int mm=p_GetExp(b,1,n tcRing);539 int mm=p_GetExp(b,1,nacRing); 535 540 if (m > mm) m = mm; 536 541 return m; … … 541 546 * used to find it in a fraction 542 547 */ 543 static int ntpExpi(int i, napoly a, napoly b)548 int napExpi(int i, napoly a, napoly b) 544 549 { 545 550 if (a==NULL || b==NULL) return 0; 546 int m = p_GetExp(a,i+1,n tcRing);551 int m = p_GetExp(a,i+1,nacRing); 547 552 if (m==0) return 0; 548 553 while (pNext(a) != NULL) 549 554 { 550 555 pIter(a); 551 if (m > p_GetExp(a,i+1,n tcRing))552 { 553 m = p_GetExp(a,i+1,n tcRing);556 if (m > p_GetExp(a,i+1,nacRing)) 557 { 558 m = p_GetExp(a,i+1,nacRing); 554 559 if (m==0) return 0; 555 560 } … … 557 562 do 558 563 { 559 if (m > p_GetExp(b,i+1,n tcRing))560 { 561 m = p_GetExp(b,i+1,n tcRing);564 if (m > p_GetExp(b,i+1,nacRing)) 565 { 566 m = p_GetExp(b,i+1,nacRing); 562 567 if (m==0) return 0; 563 568 } … … 568 573 } 569 574 570 static void ntpContent(napoly ph)575 void napContent(napoly ph) 571 576 { 572 577 number h,d; … … 580 585 do 581 586 { 582 d=ntcGcd(pGetCoeff(p), h, n tcRing);587 d=ntcGcd(pGetCoeff(p), h, nacRing); 583 588 if(ntcIsOne(d)) 584 589 { 585 n_Delete(&h,n tcRing);586 n_Delete(&d,n tcRing);590 n_Delete(&h,nacRing); 591 n_Delete(&d,nacRing); 587 592 return; 588 593 } 589 n_Delete(&h,n tcRing);594 n_Delete(&h,nacRing); 590 595 h = d; 591 596 pIter(p); … … 593 598 while (p!=NULL); 594 599 h = ntcInvers(d); 595 n_Delete(&d,n tcRing);600 n_Delete(&d,nacRing); 596 601 p = ph; 597 602 while (p!=NULL) 598 603 { 599 604 d = ntcMult(pGetCoeff(p), h); 600 n_Delete(&pGetCoeff(p),n tcRing);605 n_Delete(&pGetCoeff(p),nacRing); 601 606 pGetCoeff(p) = d; 602 607 pIter(p); 603 608 } 604 n_Delete(&h,n tcRing);605 } 606 607 static void ntpCleardenom(napoly ph)609 n_Delete(&h,nacRing); 610 } 611 612 void napCleardenom(napoly ph) 608 613 { 609 614 number d, h; … … 613 618 return; 614 619 p = ph; 615 h = ntcInit(1,n tcRing);620 h = ntcInit(1,nacRing); 616 621 while (p!=NULL) 617 622 { 618 d = ntcLcm(h, pGetCoeff(p), n tcRing);619 n_Delete(&h,n tcRing);623 d = ntcLcm(h, pGetCoeff(p), nacRing); 624 n_Delete(&h,nacRing); 620 625 h = d; 621 626 pIter(p); … … 627 632 { 628 633 d=ntcMult(h, pGetCoeff(p)); 629 n_Delete(&pGetCoeff(p),n tcRing);634 n_Delete(&pGetCoeff(p),nacRing); 630 635 ntcNormalize(d); 631 636 pGetCoeff(p) = d; 632 637 pIter(p); 633 638 } 634 n_Delete(&h,n tcRing);635 } 636 n tpContent(ph);637 } 638 639 static napoly ntpGcd0(napoly a, napoly b)639 n_Delete(&h,nacRing); 640 } 641 napContent(ph); 642 } 643 644 napoly napGcd0(napoly a, napoly b) 640 645 { 641 646 number x, y; 642 647 if (!ntIsChar0) 643 return p_ISet(1,n tcRing);648 return p_ISet(1,nacRing); 644 649 x = ntcCopy(pGetCoeff(a)); 645 650 if (ntcIsOne(x)) 646 return n tpInitz(x);651 return napInitz(x); 647 652 while (pNext(a)!=NULL) 648 653 { 649 654 pIter(a); 650 y = ntcGcd(x, pGetCoeff(a), n tcRing);651 n_Delete(&x,n tcRing);655 y = ntcGcd(x, pGetCoeff(a), nacRing); 656 n_Delete(&x,nacRing); 652 657 x = y; 653 658 if (ntcIsOne(x)) 654 return n tpInitz(x);659 return napInitz(x); 655 660 } 656 661 do 657 662 { 658 y = ntcGcd(x, pGetCoeff(b), n tcRing);659 n_Delete(&x,n tcRing);663 y = ntcGcd(x, pGetCoeff(b), nacRing); 664 n_Delete(&x,nacRing); 660 665 x = y; 661 666 if (ntcIsOne(x)) 662 return n tpInitz(x);667 return napInitz(x); 663 668 pIter(b); 664 669 } 665 670 while (b!=NULL); 666 return n tpInitz(x);671 return napInitz(x); 667 672 } 668 673 … … 670 675 * result =gcd(a,b) 671 676 */ 672 static napoly ntpGcd(napoly a, napoly b)677 napoly napGcd(napoly a, napoly b) 673 678 { 674 679 int i; … … 680 685 || ((pNext(b)==NULL)&&(ntcIsZero(pGetCoeff(b))))) 681 686 { 682 return p_ISet(1,n tcRing);683 } 684 return n tpCopy(b);687 return p_ISet(1,nacRing); 688 } 689 return napCopy(b); 685 690 } 686 691 else … … 688 693 || ((pNext(b)==NULL)&&(ntcIsZero(pGetCoeff(b))))) 689 694 { 690 return ntpCopy(a); 695 return napCopy(a); 696 } 697 if (naMinimalPoly != NULL) 698 { 699 if (p_GetExp(a,1,nacRing) >= p_GetExp(b,1,nacRing)) 700 { 701 x = a; 702 y = b; 703 } 704 else 705 { 706 x = b; 707 y = a; 708 } 709 if (!ntIsChar0) g = p_ISet(1,nacRing); 710 else g = napGcd0(x, y); 711 if (pNext(y)==NULL) 712 { 713 napSetExp(g,1, napExp(x, y)); 714 p_Setm(g,nacRing); 715 return g; 716 } 717 x = napCopy(x); 718 y = napCopy(y); 719 loop 720 { 721 h = naRemainder(x, y); 722 if (h==NULL) 723 { 724 napCleardenom(y); 725 if (!ntcIsOne(pGetCoeff(g))) 726 napMultN(y, pGetCoeff(g)); 727 p_LmDelete(&g,nacRing); 728 return y; 729 } 730 else if (pNext(h)==NULL) 731 break; 732 x = y; 733 y = h; 734 } 735 p_Delete(&y,nacRing); 736 p_LmDelete(&h,nacRing); 737 napSetExp(g,1, napExp(a, b)); 738 p_Setm(g,nacRing); 739 return g; 691 740 } 692 741 // Hmm ... this is a memory leak 693 // x = (napoly)p_Init(n tcRing);742 // x = (napoly)p_Init(nacRing); 694 743 g=a; 695 744 h=b; 696 if (!ntIsChar0) x = p_ISet(1,n tcRing);697 else x = n tpGcd0(g,h);698 for (i=(n aNumbOfPar-1); i>=0; i--)699 { 700 napSetExp(x,i+1, n tpExpi(i,a,b));701 p_Setm(x,n tcRing);745 if (!ntIsChar0) x = p_ISet(1,nacRing); 746 else x = napGcd0(g,h); 747 for (i=(ntNumbOfPar-1); i>=0; i--) 748 { 749 napSetExp(x,i+1, napExpi(i,a,b)); 750 p_Setm(x,nacRing); 702 751 } 703 752 return x; … … 705 754 706 755 707 number n tpLcm(napoly a)708 { 709 number h = ntcInit(1,n tcRing);756 number napLcm(napoly a) 757 { 758 number h = ntcInit(1,nacRing); 710 759 711 760 if (ntIsChar0) … … 716 765 while (b!=NULL) 717 766 { 718 d = ntcLcm(h, pGetCoeff(b), n tcRing);719 n_Delete(&h,n tcRing);767 d = ntcLcm(h, pGetCoeff(b), nacRing); 768 n_Delete(&h,nacRing); 720 769 h = d; 721 770 pIter(b); … … 731 780 * doesn't delete p and q 732 781 */ 733 static BOOLEAN ntpDivPoly (napoly p, napoly q)734 { 735 int j=1; /* evtl. von n tNumber.. -1 abwaerts zaehlen */736 737 while (p_GetExp(p,j,n tcRing) <= p_GetExp(q,j,ntcRing))782 BOOLEAN napDivPoly (napoly p, napoly q) 783 { 784 int j=1; /* evtl. von naNumber.. -1 abwaerts zaehlen */ 785 786 while (p_GetExp(p,j,nacRing) <= p_GetExp(q,j,nacRing)) 738 787 { 739 788 j++; 740 if (j > n aNumbOfPar)789 if (j > ntNumbOfPar) 741 790 return 1; 742 791 } … … 747 796 /*2 748 797 * meins (for reduction in algebraic extension) 749 * Normalform of poly with n tI798 * Normalform of poly with naI 750 799 * changes q and returns it 751 800 */ 752 napoly n tpRedp (napoly q)753 { 754 napoly h = (napoly)p_Init(n tcRing);801 napoly napRedp (napoly q) 802 { 803 napoly h = (napoly)p_Init(nacRing); 755 804 int i=0,j; 756 805 757 806 loop 758 807 { 759 if (n tpDivPoly (ntI->liste[i], q))760 { 761 /* h = lt(q)/lt(n tI->liste[i])*/808 if (napDivPoly (naI->liste[i], q)) 809 { 810 /* h = lt(q)/lt(naI->liste[i])*/ 762 811 pGetCoeff(h) = ntcCopy(pGetCoeff(q)); 763 for (j=n aNumbOfPar; j>0; j--)764 napSetExp(h,j, p_GetExp(q,j,n tcRing) - p_GetExp(ntI->liste[i],j,ntcRing));765 p_Setm(h,n tcRing);766 h = p_Mult_q(h, n tpCopy(ntI->liste[i]),ntcRing);812 for (j=ntNumbOfPar; j>0; j--) 813 napSetExp(h,j, p_GetExp(q,j,nacRing) - p_GetExp(naI->liste[i],j,nacRing)); 814 p_Setm(h,nacRing); 815 h = p_Mult_q(h, napCopy(naI->liste[i]),nacRing); 767 816 h = napNeg (h); 768 q = napAdd (q, n tpCopy(h));769 p_Delete (&pNext(h),n tcRing);817 q = napAdd (q, napCopy(h)); 818 p_Delete (&pNext(h),nacRing); 770 819 if (q == NULL) 771 820 { 772 p_Delete(&h,n tcRing);821 p_Delete(&h,nacRing); 773 822 return q; 774 823 } … … 779 828 { 780 829 i++; 781 if (i >= n tI->anz)782 { 783 p_Delete(&h,n tcRing);830 if (i >= naI->anz) 831 { 832 p_Delete(&h,nacRing); 784 833 return q; 785 834 } … … 795 844 * changes q and returns it 796 845 */ 797 napoly n tpTailred (napoly q)846 napoly napTailred (napoly q) 798 847 { 799 848 napoly h; … … 802 851 while (h != NULL) 803 852 { 804 h = n tpRedp (h);853 h = napRedp (h); 805 854 if (h == NULL) 806 855 return q; … … 810 859 } 811 860 812 813 /*================ procedure for rational functions: ntXXXX =================*/ 814 815 /*2 816 * z:= i 817 */ 818 number ntInit(int i, const ring r) 819 { 820 if (i!=0) 821 { 822 number c=n_Init(i,r->algring); 823 if (!n_IsZero(c,r->algring)) 824 { 825 poly z=p_Init(r->algring); 826 pSetCoeff0(z,c); 827 lnumber l = (lnumber)omAllocBin(rnumber_bin); 828 l->z = z; 829 l->s = 2; 830 l->n = NULL; 831 return (number)l; 832 } 833 } 834 /*else*/ 835 return NULL; 836 } 837 838 number ntPar(int i) 839 { 840 lnumber l = (lnumber)omAllocBin(rnumber_bin); 841 l->s = 2; 842 l->z = p_ISet(1,ntcRing); 843 napSetExp(l->z,i,1); 844 p_Setm(l->z,ntcRing); 845 l->n = NULL; 846 return (number)l; 847 } 848 849 int ntParDeg(number n) /* i := deg(n) */ 850 { 851 lnumber l = (lnumber)n; 852 if (l==NULL) return -1; 853 return ntpDeg(l->z); 854 } 855 856 //int ntParDeg(number n) /* i := deg(n) */ 857 //{ 858 // lnumber l = (lnumber)n; 859 // if (l==NULL) return -1; 860 // return ntpMaxDeg(l->z)+ntpMaxDeg(l->n); 861 //} 862 863 int ntSize(number n) /* size desc. */ 864 { 865 lnumber l = (lnumber)n; 866 if (l==NULL) return -1; 867 int len_z; 868 int len_n; 869 int o=ntpMaxDegLen(l->z,len_z)+ntpMaxDegLen(l->n,len_n); 870 return (len_z+len_n)+o; 871 } 872 873 /*2 874 * convert a number to int (if possible) 875 */ 876 int ntInt(number &n, const ring r) 877 { 878 lnumber l=(lnumber)n; 879 if ((l!=NULL)&&(l->n==NULL)&&(p_IsConstant(l->z,r->algring))) 880 { 881 return ntcInt(pGetCoeff(l->z),r->algring); 882 } 883 return 0; 884 } 885 886 /*2 887 * deletes p 888 */ 889 void ntDelete(number *p, const ring r) 890 { 891 if ((*p)!=NULL) 892 { 893 lnumber l = (lnumber) * p; 894 if (l==NULL) return; 895 p_Delete(&(l->z),r->algring); 896 p_Delete(&(l->n),r->algring); 897 omFreeBin((ADDRESS)l, rnumber_bin); 898 } 899 *p = NULL; 900 } 901 902 /*2 903 * copy p to erg 904 */ 905 number ntCopy(number p) 906 { 861 napoly napMap(napoly p) 862 { 863 napoly w, a; 864 907 865 if (p==NULL) return NULL; 908 ntTest(p); 909 lnumber erg; 910 lnumber src = (lnumber)p; 911 erg = (lnumber)omAlloc0Bin(rnumber_bin); 912 erg->z = p_Copy(src->z, ntcRing); 913 erg->n = p_Copy(src->n, ntcRing); 914 erg->s = src->s; 915 return (number)erg; 916 } 917 number nt_Copy(number p, const ring r) 918 { 919 if (p==NULL) return NULL; 920 lnumber erg; 921 lnumber src = (lnumber)p; 922 erg = (lnumber)omAlloc0Bin(rnumber_bin); 923 erg->z = p_Copy(src->z,r->algring); 924 erg->n = p_Copy(src->n,r->algring); 925 erg->s = src->s; 926 return (number)erg; 927 } 928 929 /*2 930 * addition; lu:= la + lb 931 */ 932 number ntAdd(number la, number lb) 933 { 934 if (la==NULL) return ntCopy(lb); 935 if (lb==NULL) return ntCopy(la); 936 937 napoly x, y; 938 lnumber lu; 939 lnumber a = (lnumber)la; 940 lnumber b = (lnumber)lb; 941 #ifdef LDEBUG 942 omCheckAddrSize(a,sizeof(snumber)); 943 omCheckAddrSize(b,sizeof(snumber)); 944 #endif 945 if (b->n!=NULL) x = pp_Mult_qq(a->z, b->n,ntcRing); 946 else x = ntpCopy(a->z); 947 if (a->n!=NULL) y = pp_Mult_qq(b->z, a->n,ntcRing); 948 else y = ntpCopy(b->z); 949 napoly res = napAdd(x, y); 950 if (res==NULL) 951 { 952 return (number)NULL; 953 } 954 lu = (lnumber)omAllocBin(rnumber_bin); 955 lu->z=res; 956 if (a->n!=NULL) 957 { 958 if (b->n!=NULL) x = pp_Mult_qq(a->n, b->n,ntcRing); 959 else x = ntpCopy(a->n); 960 } 961 else 962 { 963 if (b->n!=NULL) x = ntpCopy(b->n); 964 else x = NULL; 965 } 966 //if (x!=NULL) 967 //{ 968 // if (p_LmIsConstant(x,ntcRing)) 969 // { 970 // number inv=ntcInvers(pGetCoeff(x)); 971 // ntpMultN(lu->z,inv); 972 // n_Delete(&inv,ntcRing); 973 // ntpDelete(&x); 974 // } 975 //} 976 lu->n = x; 977 lu->s = FALSE; 978 if (/*lu->n*/ x!=NULL) 979 { 980 number luu=(number)lu; 981 //if (p_IsConstant(lu->n,ntcRing)) ntCoefNormalize(luu); 982 //else 983 ntNormalize(luu); 984 lu=(lnumber)luu; 985 } 986 //else lu->s=2; 987 ntTest((number)lu); 988 return (number)lu; 989 } 990 991 /*2 992 * subtraction; r:= la - lb 993 */ 994 number ntSub(number la, number lb) 995 { 996 lnumber lu; 997 998 if (lb==NULL) return ntCopy(la); 999 if (la==NULL) 1000 { 1001 lu = (lnumber)ntCopy(lb); 1002 lu->z = napNeg(lu->z); 1003 return (number)lu; 1004 } 1005 1006 lnumber a = (lnumber)la; 1007 lnumber b = (lnumber)lb; 1008 1009 #ifdef LDEBUG 1010 omCheckAddrSize(a,sizeof(snumber)); 1011 omCheckAddrSize(b,sizeof(snumber)); 1012 #endif 1013 1014 napoly x, y; 1015 if (b->n!=NULL) x = pp_Mult_qq(a->z, b->n,ntcRing); 1016 else x = ntpCopy(a->z); 1017 if (a->n!=NULL) y = p_Mult_q(ntpCopy(b->z), ntpCopyNeg(a->n),ntcRing); 1018 else y = ntpCopyNeg(b->z); 1019 napoly res = napAdd(x, y); 1020 if (res==NULL) 1021 { 1022 return (number)NULL; 1023 } 1024 lu = (lnumber)omAllocBin(rnumber_bin); 1025 lu->z=res; 1026 if (a->n!=NULL) 1027 { 1028 if (b->n!=NULL) x = pp_Mult_qq(a->n, b->n,ntcRing); 1029 else x = ntpCopy(a->n); 1030 } 1031 else 1032 { 1033 if (b->n!=NULL) x = ntpCopy(b->n); 1034 else x = NULL; 1035 } 1036 lu->n = x; 1037 lu->s = FALSE; 1038 if (/*lu->n*/ x!=NULL) 1039 { 1040 number luu=(number)lu; 1041 //if (p_IsConstant(lu->n,ntcRing)) ntCoefNormalize(luu); 1042 //else 1043 ntNormalize(luu); 1044 lu=(lnumber)luu; 1045 } 1046 //else lu->s=2; 1047 ntTest((number)lu); 1048 return (number)lu; 1049 } 1050 1051 /*2 1052 * multiplication; r:= la * lb 1053 */ 1054 number ntMult(number la, number lb) 1055 { 1056 if ((la==NULL) || (lb==NULL)) 1057 return NULL; 1058 1059 lnumber a = (lnumber)la; 1060 lnumber b = (lnumber)lb; 1061 lnumber lo; 1062 napoly x; 1063 1064 #ifdef LDEBUG 1065 omCheckAddrSize(a,sizeof(snumber)); 1066 omCheckAddrSize(b,sizeof(snumber)); 1067 #endif 1068 ntTest(la); 1069 ntTest(lb); 1070 1071 lo = (lnumber)omAllocBin(rnumber_bin); 1072 lo->z = pp_Mult_qq(a->z, b->z,ntcRing); 1073 1074 if (a->n==NULL) 1075 { 1076 if (b->n==NULL) 1077 x = NULL; 1078 else 1079 x = ntpCopy(b->n); 1080 } 1081 else 1082 { 1083 if (b->n==NULL) 1084 { 1085 x = ntpCopy(a->n); 1086 } 1087 else 1088 { 1089 x = pp_Mult_qq(b->n, a->n, ntcRing); 1090 } 1091 } 1092 if (ntI!=NULL) 1093 { 1094 lo->z = ntpRedp (lo->z); 1095 if (lo->z != NULL) 1096 lo->z = ntpTailred (lo->z); 1097 if (x!=NULL) 1098 { 1099 x = ntpRedp (x); 1100 if (x!=NULL) 1101 x = ntpTailred (x); 1102 } 1103 } 1104 if ((x!=NULL) && (p_LmIsConstant(x,ntcRing)) && ntcIsOne(pGetCoeff(x))) 1105 p_Delete(&x,ntcRing); 1106 lo->n = x; 1107 lo->s = 0; 1108 if(lo->z==NULL) 1109 { 1110 omFreeBin((ADDRESS)lo, rnumber_bin); 1111 lo=NULL; 1112 } 1113 else if (lo->n!=NULL) 1114 { 1115 number luu=(number)lo; 1116 // if (p_IsConstant(lo->n,ntcRing)) ntCoefNormalize(luu); 1117 // else 1118 ntNormalize(luu); 1119 lo=(lnumber)luu; 1120 } 1121 //if (naMinimalPoly==NULL) lo->s=2; 1122 ntTest((number)lo); 1123 return (number)lo; 1124 } 1125 1126 number ntIntDiv(number la, number lb) 1127 { 1128 lnumber res; 1129 lnumber a = (lnumber)la; 1130 lnumber b = (lnumber)lb; 1131 if (a==NULL) 1132 { 1133 return NULL; 1134 } 1135 if (b==NULL) 1136 { 1137 WerrorS(nDivBy0); 1138 return NULL; 1139 } 1140 assume(a->z!=NULL && b->z!=NULL); 1141 assume(a->n==NULL && b->n==NULL); 1142 res = (lnumber)omAllocBin(rnumber_bin); 1143 res->z = ntpCopy(a->z); 1144 res->n = ntpCopy(b->z); 1145 res->s = 0; 1146 number nres=(number)res; 1147 ntNormalize(nres); 1148 1149 //ntpDelete(&res->n); 1150 ntTest(nres); 1151 return nres; 1152 } 1153 1154 /*2 1155 * division; lo:= la / lb 1156 */ 1157 number ntDiv(number la, number lb) 1158 { 1159 lnumber lo; 1160 lnumber a = (lnumber)la; 1161 lnumber b = (lnumber)lb; 1162 napoly x; 1163 1164 if (a==NULL) 1165 return NULL; 1166 1167 if (b==NULL) 1168 { 1169 WerrorS(nDivBy0); 1170 return NULL; 1171 } 1172 #ifdef LDEBUG 1173 omCheckAddrSize(a,sizeof(snumber)); 1174 omCheckAddrSize(b,sizeof(snumber)); 1175 #endif 1176 lo = (lnumber)omAllocBin(rnumber_bin); 1177 if (b->n!=NULL) 1178 lo->z = pp_Mult_qq(a->z, b->n,ntcRing); 1179 else 1180 lo->z = ntpCopy(a->z); 1181 if (a->n!=NULL) 1182 x = pp_Mult_qq(b->z, a->n, ntcRing); 1183 else 1184 x = ntpCopy(b->z); 1185 if (ntI!=NULL) 1186 { 1187 lo->z = ntpRedp (lo->z); 1188 if (lo->z != NULL) 1189 lo->z = ntpTailred (lo->z); 1190 if (x!=NULL) 1191 { 1192 x = ntpRedp (x); 1193 if (x!=NULL) 1194 x = ntpTailred (x); 1195 } 1196 } 1197 if ((p_LmIsConstant(x,ntcRing)) && ntcIsOne(pGetCoeff(x))) 1198 p_Delete(&x,ntcRing); 1199 lo->n = x; 1200 lo->s = 0; 1201 if (lo->n!=NULL) 1202 { 1203 number luu=(number)lo; 1204 //if (p_IsConstant(lo->n,ntcRing)) ntCoefNormalize(luu); 1205 //else 1206 ntNormalize(luu); 1207 lo=(lnumber)luu; 1208 } 1209 //else lo->s=2; 1210 ntTest((number)lo); 1211 return (number)lo; 1212 } 1213 1214 /*2 1215 * za:= - za, inplace 1216 */ 1217 number ntNeg(number za) 1218 { 1219 if (za!=NULL) 1220 { 1221 lnumber e = (lnumber)za; 1222 ntTest(za); 1223 e->z = napNeg(e->z); 1224 } 1225 return za; 1226 } 1227 1228 /*2 1229 * 1/a 1230 */ 1231 number ntInvers(number a) 1232 { 1233 lnumber lo; 1234 lnumber b = (lnumber)a; 1235 napoly x; 1236 1237 if (b==NULL) 1238 { 1239 WerrorS(nDivBy0); 1240 return NULL; 1241 } 1242 #ifdef LDEBUG 1243 omCheckAddrSize(b,sizeof(snumber)); 1244 #endif 1245 lo = (lnumber)omAlloc0Bin(rnumber_bin); 1246 lo->s = b->s; 1247 if (b->n!=NULL) 1248 lo->z = ntpCopy(b->n); 1249 else 1250 lo->z = p_ISet(1,ntcRing); 1251 x = b->z; 1252 if ((!p_LmIsConstant(x,ntcRing)) || !ntcIsOne(pGetCoeff(x))) 1253 x = ntpCopy(x); 1254 else 1255 { 1256 lo->n = NULL; 1257 ntTest((number)lo); 1258 return (number)lo; 1259 } 1260 lo->n = x; 1261 if (lo->n!=NULL) 1262 { 1263 number luu=(number)lo; 1264 //if (p_IsConstant(lo->n,ntcRing)) ntCoefNormalize(luu); 1265 //else 1266 ntNormalize(luu); 1267 lo=(lnumber)luu; 1268 } 1269 ntTest((number)lo); 1270 return (number)lo; 1271 } 1272 1273 1274 BOOLEAN ntIsZero(number za) 1275 { 1276 lnumber zb = (lnumber)za; 1277 ntTest(za); 1278 #ifdef LDEBUG 1279 if ((zb!=NULL) && (zb->z==NULL)) WerrorS("internal zero error(2)"); 1280 #endif 1281 return (zb==NULL); 1282 } 1283 1284 1285 BOOLEAN ntGreaterZero(number za) 1286 { 1287 lnumber zb = (lnumber)za; 1288 #ifdef LDEBUG 1289 if ((zb!=NULL) && (zb->z==NULL)) WerrorS("internal zero error(3)"); 1290 #endif 1291 ntTest(za); 1292 if (zb!=NULL) 1293 { 1294 return (ntcGreaterZero(pGetCoeff(zb->z))||(!p_LmIsConstant(zb->z,ntcRing))); 1295 } 1296 /* else */ return FALSE; 1297 } 1298 1299 1300 /*2 1301 * a = b ? 1302 */ 1303 BOOLEAN ntEqual (number a, number b) 1304 { 1305 if(a==b) return TRUE; 1306 if((a==NULL)&&(b!=NULL)) return FALSE; 1307 if((b==NULL)&&(a!=NULL)) return FALSE; 1308 1309 lnumber aa=(lnumber)a; 1310 lnumber bb=(lnumber)b; 1311 1312 int an_deg=0; 1313 if(aa->n!=NULL) 1314 an_deg=ntpDeg(aa->n); 1315 int bn_deg=0; 1316 if(bb->n!=NULL) 1317 bn_deg=ntpDeg(bb->n); 1318 if(an_deg+ntpDeg(bb->z)!=bn_deg+ntpDeg(aa->z)) 1319 return FALSE; 1320 #if 0 1321 ntNormalize(a); 1322 aa=(lnumber)a; 1323 ntNormalize(b); 1324 bb=(lnumber)b; 1325 if((aa->n==NULL)&&(bb->n!=NULL)) return FALSE; 1326 if((bb->n==NULL)&&(aa->n!=NULL)) return FALSE; 1327 if(ntpComp(aa->z,bb->z)!=0) return FALSE; 1328 if((aa->n!=NULL) && (ntpComp(aa->n,bb->n))) return FALSE; 1329 #endif 1330 number h = ntSub(a, b); 1331 BOOLEAN bo = ntIsZero(h); 1332 ntDelete(&h,currRing); 1333 return bo; 1334 } 1335 1336 1337 BOOLEAN ntGreater (number a, number b) 1338 { 1339 if (ntIsZero(a)) 1340 return FALSE; 1341 if (ntIsZero(b)) 1342 return TRUE; /* a!= 0)*/ 1343 return ntpDeg(((lnumber)a)->z)>ntpDeg(((lnumber)b)->z); 1344 } 1345 1346 /*2 1347 * reads a number 1348 */ 1349 const char *ntRead(const char *s, number *p) 1350 { 1351 napoly x; 1352 lnumber a; 1353 s = ntpRead(s, &x); 1354 if (x==NULL) 1355 { 1356 *p = NULL; 1357 return s; 1358 } 1359 *p = (number)omAlloc0Bin(rnumber_bin); 1360 a = (lnumber)*p; 1361 if (ntI!=NULL) 1362 { 1363 a->z = ntpRedp(x); 1364 if (a->z != NULL) 1365 a->z = ntpTailred (a->z); 1366 } 1367 else 1368 a->z = x; 1369 if(a->z==NULL) 1370 { 1371 omFreeBin((ADDRESS)*p, rnumber_bin); 1372 *p=NULL; 1373 } 1374 else 1375 { 1376 a->n = NULL; 1377 a->s = 0; 1378 ntTest(*p); 1379 } 1380 return s; 1381 } 1382 1383 /*2 1384 * tries to convert a number to a name 1385 */ 1386 char * ntName(number n) 1387 { 1388 lnumber ph = (lnumber)n; 1389 if (ph==NULL) 1390 return NULL; 1391 int i; 1392 char *s=(char *)omAlloc(4* naNumbOfPar); 1393 char *t=(char *)omAlloc(8); 1394 s[0]='\0'; 1395 for (i = 0; i <= naNumbOfPar - 1; i++) 1396 { 1397 int e=p_GetExp(ph->z,i+1,ntcRing); 1398 if (e > 0) 1399 { 1400 if (e >1) 1401 { 1402 sprintf(t,"%s%d",ntParNames[i],e); 1403 strcat(s,t); 1404 } 1405 else 1406 { 1407 strcat(s,ntParNames[i]); 1408 } 1409 } 1410 } 1411 omFreeSize((ADDRESS)t,8); 1412 if (s[0]=='\0') 1413 { 1414 omFree((ADDRESS)s); 1415 return NULL; 1416 } 1417 return s; 1418 } 1419 1420 /*2 1421 * writes a number 1422 */ 1423 void ntWrite(number &phn, const ring r) 1424 { 1425 lnumber ph = (lnumber)phn; 1426 if (ph==NULL) 1427 StringAppendS("0"); 1428 else 1429 { 1430 phn->s = 0; 1431 BOOLEAN has_denom=(ph->n!=NULL); 1432 ntpWrite(ph->z,has_denom/*(ph->n!=NULL)*/,r); 1433 if (has_denom/*(ph->n!=NULL)*/) 1434 { 1435 StringAppendS("/"); 1436 ntpWrite(ph->n,TRUE,r); 1437 } 1438 } 1439 } 1440 1441 /*2 1442 * za == 1 ? 1443 */ 1444 BOOLEAN ntIsOne(number za) 1445 { 1446 lnumber a = (lnumber)za; 1447 napoly x, y; 1448 number t; 1449 if (a==NULL) return FALSE; 1450 #ifdef LDEBUG 1451 omCheckAddrSize(a,sizeof(snumber)); 1452 if (a->z==NULL) 1453 { 1454 WerrorS("internal zero error(4)"); 1455 return FALSE; 1456 } 1457 #endif 1458 if (a->n==NULL) 1459 { 1460 if (p_LmIsConstant(a->z,ntcRing)) 1461 { 1462 return ntcIsOne(pGetCoeff(a->z)); 1463 } 1464 else return FALSE; 1465 } 1466 #if 0 1467 x = a->z; 1468 y = a->n; 1469 do 1470 { 1471 if (ntpComp(x, y)) 1472 return FALSE; 1473 else 1474 { 1475 t = ntcSub(pGetCoeff(x), pGetCoeff(y)); 1476 if (!ntcIsZero(t)) 1477 { 1478 n_Delete(&t,ntcRing); 1479 return FALSE; 1480 } 1481 else 1482 n_Delete(&t,ntcRing); 1483 } 1484 pIter(x); 1485 pIter(y); 1486 } 1487 while ((x!=NULL) && (y!=NULL)); 1488 if ((x!=NULL) || (y!=NULL)) return FALSE; 1489 p_Delete(&a->z,ntcRing); 1490 p_Delete(&a->n,ntcRing); 1491 a->z = p_ISet(1,ntcRing); 1492 a->n = NULL; 1493 return TRUE; 1494 #else 1495 return FALSE; 1496 #endif 1497 } 1498 1499 /*2 1500 * za == -1 ? 1501 */ 1502 BOOLEAN ntIsMOne(number za) 1503 { 1504 lnumber a = (lnumber)za; 1505 napoly x, y; 1506 number t; 1507 if (a==NULL) return FALSE; 1508 #ifdef LDEBUG 1509 omCheckAddrSize(a,sizeof(snumber)); 1510 if (a->z==NULL) 1511 { 1512 WerrorS("internal zero error(5)"); 1513 return FALSE; 1514 } 1515 #endif 1516 if (a->n==NULL) 1517 { 1518 if (p_LmIsConstant(a->z,ntcRing)) return ntcIsMOne(pGetCoeff(a->z)); 1519 /*else return FALSE;*/ 1520 } 1521 return FALSE; 1522 } 1523 1524 /*2 1525 * returns the i-th power of p (i>=0) 1526 */ 1527 void ntPower(number p, int i, number *rc) 1528 { 1529 number x; 1530 *rc = ntInit(1,currRing); 1531 for (; i > 0; i--) 1532 { 1533 x = ntMult(*rc, p); 1534 ntDelete(rc,currRing); 1535 *rc = x; 1536 } 1537 } 1538 1539 /*2 1540 * result =gcd(a,b) 1541 */ 1542 number ntGcd(number a, number b, const ring r) 1543 { 1544 if (a==NULL) return ntCopy(b); 1545 if (b==NULL) return ntCopy(a); 1546 1547 lnumber x, y; 1548 lnumber result = (lnumber)omAlloc0Bin(rnumber_bin); 1549 1550 x = (lnumber)a; 1551 y = (lnumber)b; 1552 #ifndef HAVE_FACTORY 1553 result->z = ntpGcd(x->z, y->z); // change from ntpGcd0 1554 #else 1555 int c=ABS(nGetChar()); 1556 if (c==1) c=0; 1557 setCharacteristic( c ); 1558 1559 napoly rz=ntpGcd(x->z, y->z); 1560 CanonicalForm F, G, R; 1561 R=convSingPFactoryP(rz,r->algring); 1562 p_Normalize(x->z,ntcRing); 1563 F=convSingPFactoryP(x->z,r->algring)/R; 1564 p_Normalize(y->z,ntcRing); 1565 G=convSingPFactoryP(y->z,r->algring)/R; 1566 F = gcd( F, G ); 1567 if (F.isOne()) 1568 result->z= rz; 1569 else 1570 { 1571 p_Delete(&rz,r->algring); 1572 result->z=convFactoryPSingP( F*R,r->algring ); 1573 p_Normalize(result->z,ntcRing); 1574 } 1575 #endif 1576 ntTest((number)result); 1577 return (number)result; 1578 } 1579 1580 1581 /*2 1582 * naNumbOfPar = 1: 1583 * clears denominator algebraic case; 1584 * tries to simplify ratio transcendental case; 1585 * 1586 * cancels monomials 1587 * occuring in denominator 1588 * and enumerator ? naNumbOfPar != 1; 1589 * 1590 * #defines for Factory: 1591 * FACTORY_GCD_TEST: do not apply built in gcd for 1592 * univariate polynomials, always use Factory 1593 */ 1594 //#define FACTORY_GCD_TEST 1595 void ntCoefNormalize(number pp) 1596 { 1597 if (pp==NULL) return; 1598 lnumber p = (lnumber)pp; 1599 number nz; // all denom. of the numerator 1600 nz=p_GetAllDenom(p->z,ntcRing); 1601 BOOLEAN norm=FALSE; 1602 if (!n_IsOne(nz,ntcRing)) 1603 { 1604 norm=TRUE; 1605 p->z=p_Mult_nn(p->z,nz,ntcRing); 1606 if (p->n==NULL) 1607 { 1608 p->n=p_NSet(nz,ntcRing); 1609 } 1610 else 1611 { 1612 p->n=p_Mult_nn(p->n,nz,ntcRing); 1613 n_Delete(&nz, ntcRing); 1614 } 1615 } 1616 else 1617 { 1618 n_Delete(&nz, ntcRing); 1619 } 1620 if (norm) 1621 { 1622 norm=FALSE; 1623 p_Normalize(p->z,ntcRing); 1624 p_Normalize(p->n,ntcRing); 1625 } 1626 number nn; 1627 nn=p_GetAllDenom(p->n,ntcRing); 1628 if (!n_IsOne(nn,ntcRing)) 1629 { 1630 norm=TRUE; 1631 p->n=p_Mult_nn(p->n,nn,ntcRing); 1632 p->z=p_Mult_nn(p->z,nn,ntcRing); 1633 n_Delete(&nn, ntcRing); 1634 } 1635 else 1636 { 1637 n_Delete(&nn, ntcRing); 1638 } 1639 if (norm) 1640 { 1641 p_Normalize(p->z,ntcRing); 1642 p_Normalize(p->n,ntcRing); 1643 } 1644 // remove common factors in n, z: 1645 if (p->n!=NULL) 1646 { 1647 poly pp=p->z; 1648 nz=n_Copy(pGetCoeff(pp),ntcRing); 1649 pIter(pp); 1650 while(pp!=NULL) 1651 { 1652 if (n_IsOne(nz,ntcRing)) break; 1653 number d=n_Gcd(nz,pGetCoeff(pp),ntcRing); 1654 n_Delete(&nz,ntcRing); nz=d; 1655 pIter(pp); 1656 } 1657 if (!n_IsOne(nz,ntcRing)) 1658 { 1659 pp=p->n; 1660 nn=n_Copy(pGetCoeff(pp),ntcRing); 1661 pIter(pp); 1662 while(pp!=NULL) 1663 { 1664 if (n_IsOne(nn,ntcRing)) break; 1665 number d=n_Gcd(nn,pGetCoeff(pp),ntcRing); 1666 n_Delete(&nn,ntcRing); nn=d; 1667 pIter(pp); 1668 } 1669 number ng=n_Gcd(nz,nn,ntcRing); 1670 n_Delete(&nn,ntcRing); 1671 if (!n_IsOne(ng,ntcRing)) 1672 { 1673 number ni=n_Invers(ng,ntcRing); 1674 p->z=p_Mult_nn(p->z,ni,ntcRing); 1675 p->n=p_Mult_nn(p->n,ni,ntcRing); 1676 p_Normalize(p->z,ntcRing); 1677 p_Normalize(p->n,ntcRing); 1678 n_Delete(&ni,ntcRing); 1679 } 1680 n_Delete(&ng,ntcRing); 1681 } 1682 n_Delete(&nz,ntcRing); 1683 } 1684 if (p->n!=NULL) 1685 { 1686 if(!ntcGreaterZero(pGetCoeff(p->n))) 1687 { 1688 p->z=napNeg(p->z); 1689 p->n=napNeg(p->n); 1690 } 1691 1692 if (/*(p->n!=NULL) && */ 1693 (p_IsConstant(p->n,ntcRing)) 1694 && (n_IsOne(pGetCoeff(p->n),ntcRing))) 1695 { 1696 p_Delete(&(p->n), ntcRing); 1697 p->n = NULL; 1698 } 1699 } 1700 } 1701 1702 void ntNormalize(number &pp) 1703 { 1704 1705 //ntTest(pp); // input may not be "normal" 1706 lnumber p = (lnumber)pp; 1707 1708 if (p==NULL) 1709 return; 1710 ntCoefNormalize(pp); 1711 p->s = 2; 1712 napoly x = p->z; 1713 napoly y = p->n; 1714 1715 BOOLEAN norm=FALSE; 1716 1717 if (y==NULL) return; 1718 1719 if ((x!=NULL) && (y!=NULL)) 1720 { 1721 int i; 1722 for (i=naNumbOfPar-1; i>=0; i--) 1723 { 1724 napoly xx=x; 1725 napoly yy=y; 1726 int m = ntpExpi(i, yy, xx); 1727 if (m != 0) // in this case xx!=NULL!=yy 1728 { 1729 while (xx != NULL) 1730 { 1731 napAddExp(xx,i+1, -m); 1732 pIter(xx); 1733 } 1734 while (yy != NULL) 1735 { 1736 napAddExp(yy,i+1, -m); 1737 pIter(yy); 1738 } 1739 } 1740 } 1741 } 1742 if (p_LmIsConstant(y,ntcRing)) /* i.e. => simplify to (1/c)*z / monom */ 1743 { 1744 if (ntcIsOne(pGetCoeff(y))) 1745 { 1746 p_LmDelete(&y,ntcRing); 1747 p->n = NULL; 1748 ntTest(pp); 1749 return; 1750 } 1751 number h1 = ntcInvers(pGetCoeff(y)); 1752 ntcNormalize(h1); 1753 ntpMultN(x, h1); 1754 n_Delete(&h1,ntcRing); 1755 p_LmDelete(&y,ntcRing); 1756 p->n = NULL; 1757 ntTest(pp); 1758 return; 1759 } 1760 #ifndef FACTORY_GCD_TEST 1761 if (naNumbOfPar == 1) /* apply built-in gcd */ 1762 { 1763 napoly x1,y1; 1764 if (p_GetExp(x,1,ntcRing) >= p_GetExp(y,1,ntcRing)) 1765 { 1766 x1 = ntpCopy(x); 1767 y1 = ntpCopy(y); 1768 } 1769 else 1770 { 1771 x1 = ntpCopy(y); 1772 y1 = ntpCopy(x); 1773 } 1774 napoly r; 1775 loop 1776 { 1777 r = napRemainder(x1, y1); 1778 if ((r==NULL) || (pNext(r)==NULL)) break; 1779 x1 = y1; 1780 y1 = r; 1781 } 1782 if (r!=NULL) 1783 { 1784 p_Delete(&r,ntcRing); 1785 p_Delete(&y1,ntcRing); 1786 } 1787 else 1788 { 1789 ntpDivMod(x, y1, &(p->z), &r); 1790 ntpDivMod(y, y1, &(p->n), &r); 1791 p_Delete(&y1,ntcRing); 1792 } 1793 x = p->z; 1794 y = p->n; 1795 /* collect all denoms from y and multiply x and y by it */ 1796 if (ntIsChar0) 1797 { 1798 number n=ntpLcm(y); 1799 ntpMultN(x,n); 1800 ntpMultN(y,n); 1801 n_Delete(&n,ntcRing); 1802 while(x!=NULL) 1803 { 1804 ntcNormalize(pGetCoeff(x)); 1805 pIter(x); 1806 } 1807 x = p->z; 1808 while(y!=NULL) 1809 { 1810 ntcNormalize(pGetCoeff(y)); 1811 pIter(y); 1812 } 1813 y = p->n; 1814 } 1815 if (pNext(y)==NULL) 1816 { 1817 if (ntcIsOne(pGetCoeff(y))) 1818 { 1819 if (p_GetExp(y,1,ntcRing)==0) 1820 { 1821 p_LmDelete(&y,ntcRing); 1822 p->n = NULL; 1823 } 1824 ntTest(pp); 1825 return; 1826 } 1827 } 1828 } 1829 #endif /* FACTORY_GCD_TEST */ 1830 #ifdef HAVE_FACTORY 1831 #ifndef FACTORY_GCD_TEST 1832 else 1833 #endif 1834 { 1835 napoly xx,yy; 1836 singclap_algdividecontent(x,y,xx,yy); 1837 if (xx!=NULL) 1838 { 1839 p->z=xx; 1840 p->n=yy; 1841 p_Delete(&x,ntcRing); 1842 p_Delete(&y,ntcRing); 1843 } 1844 } 1845 #endif 1846 /* remove common factors from z and n */ 1847 x=p->z; 1848 y=p->n; 1849 if(!ntcGreaterZero(pGetCoeff(y))) 1850 { 1851 x=napNeg(x); 1852 y=napNeg(y); 1853 } 1854 number g=ntcCopy(pGetCoeff(x)); 1855 pIter(x); 1856 while (x!=NULL) 1857 { 1858 number d=ntcGcd(g,pGetCoeff(x), ntcRing); 1859 if(ntcIsOne(d)) 1860 { 1861 n_Delete(&g,ntcRing); 1862 n_Delete(&d,ntcRing); 1863 ntTest(pp); 1864 return; 1865 } 1866 n_Delete(&g,ntcRing); 1867 g = d; 1868 pIter(x); 1869 } 1870 while (y!=NULL) 1871 { 1872 number d=ntcGcd(g,pGetCoeff(y), ntcRing); 1873 if(ntcIsOne(d)) 1874 { 1875 n_Delete(&g,ntcRing); 1876 n_Delete(&d,ntcRing); 1877 ntTest(pp); 1878 return; 1879 } 1880 n_Delete(&g,ntcRing); 1881 g = d; 1882 pIter(y); 1883 } 1884 x=p->z; 1885 y=p->n; 1886 while (x!=NULL) 1887 { 1888 number d = ntcIntDiv(pGetCoeff(x),g); 1889 ntpSetCoeff(x,d); 1890 pIter(x); 1891 } 1892 while (y!=NULL) 1893 { 1894 number d = ntcIntDiv(pGetCoeff(y),g); 1895 ntpSetCoeff(y,d); 1896 pIter(y); 1897 } 1898 n_Delete(&g,ntcRing); 1899 ntTest(pp); 1900 } 1901 1902 /*2 1903 * returns in result->n 1 1904 * and in result->z the lcm(a->z,b->n) 1905 */ 1906 number ntLcm(number la, number lb, const ring r) 1907 { 1908 lnumber result; 1909 lnumber a = (lnumber)la; 1910 lnumber b = (lnumber)lb; 1911 result = (lnumber)omAlloc0Bin(rnumber_bin); 1912 //if (((naMinimalPoly==NULL) && (ntI==NULL)) || !ntIsChar0) 1913 //{ 1914 // result->z = p_ISet(1,ntcRing); 1915 // return (number)result; 1916 //} 1917 //ntNormalize(lb); 1918 ntTest(la); 1919 ntTest(lb); 1920 napoly x = p_Copy(a->z, r->algring); 1921 number t = ntpLcm(b->z); // get all denom of b->z 1922 if (!ntcIsOne(t)) 1923 { 1924 number bt, rr; 1925 napoly xx=x; 1926 while (xx!=NULL) 1927 { 1928 bt = ntcGcd(t, pGetCoeff(xx), r->algring); 1929 rr = ntcMult(t, pGetCoeff(xx)); 1930 n_Delete(&pGetCoeff(xx),r->algring); 1931 pGetCoeff(xx) = ntcDiv(rr, bt); 1932 ntcNormalize(pGetCoeff(xx)); 1933 n_Delete(&bt,r->algring); 1934 n_Delete(&rr,r->algring); 1935 pIter(xx); 1936 } 1937 } 1938 n_Delete(&t,r->algring); 1939 result->z = x; 1940 #ifdef HAVE_FACTORY 1941 if (b->n!=NULL) 1942 { 1943 result->z=singclap_alglcm(result->z,b->n); 1944 p_Delete(&x,r->algring); 1945 } 1946 #endif 1947 ntTest(la); 1948 ntTest(lb); 1949 ntTest((number)result); 1950 return ((number)result); 1951 } 1952 1953 /*2 1954 * input: a set of constant polynomials 1955 * sets the global variable ntI 1956 */ 1957 void ntSetIdeal(ideal I) 1958 { 1959 int i; 1960 1961 if (idIs0(I)) 1962 { 1963 for (i=ntI->anz-1; i>=0; i--) 1964 p_Delete(&ntI->liste[i],ntcRing); 1965 omFreeBin((ADDRESS)ntI, sntIdeal_bin); 1966 ntI=NULL; 1967 } 1968 else 1969 { 1970 lnumber h; 1971 number a; 1972 napoly x; 1973 1974 ntI=(ntIdeal)omAllocBin(sntIdeal_bin); 1975 ntI->anz=IDELEMS(I); 1976 ntI->liste=(napoly*)omAlloc(ntI->anz*sizeof(napoly)); 1977 for (i=IDELEMS(I)-1; i>=0; i--) 1978 { 1979 h=(lnumber)pGetCoeff(I->m[i]); 1980 /* We only need the enumerator of h, as we expect it to be a polynomial */ 1981 ntI->liste[i]=ntpCopy(h->z); 1982 /* If it isn't normalized (lc = 1) do this */ 1983 if (!ntcIsOne(pGetCoeff(ntI->liste[i]))) 1984 { 1985 x=ntI->liste[i]; 1986 ntcNormalize(pGetCoeff(x)); 1987 a=ntcCopy(pGetCoeff(x)); 1988 number aa=ntcInvers(a); 1989 n_Delete(&a,ntcRing); 1990 ntpMultN(x,aa); 1991 n_Delete(&aa,ntcRing); 1992 } 1993 } 1994 } 1995 } 1996 1997 /*2 1998 * map Z/p -> Q(a) 1999 */ 2000 number ntMapP0(number c) 2001 { 2002 if (npIsZero(c)) return NULL; 2003 lnumber l=(lnumber)omAllocBin(rnumber_bin); 2004 l->s=2; 2005 l->z=(napoly)p_Init(ntcRing); 2006 int i=(int)((long)c); 2007 if (i>((long)ntMapRing->ch>>2)) i-=(long)ntMapRing->ch; 2008 pGetCoeff(l->z)=nlInit(i, ntcRing); 2009 l->n=NULL; 2010 return (number)l; 2011 } 2012 2013 /*2 2014 * map Q -> Q(a) 2015 */ 2016 number ntMap00(number c) 2017 { 2018 if (nlIsZero(c)) return NULL; 2019 lnumber l=(lnumber)omAllocBin(rnumber_bin); 2020 l->s=0; 2021 l->z=(napoly)p_Init(ntcRing); 2022 pGetCoeff(l->z)=nlCopy(c); 2023 l->n=NULL; 2024 return (number)l; 2025 } 2026 2027 /*2 2028 * map Z/p -> Z/p(a) 2029 */ 2030 number ntMapPP(number c) 2031 { 2032 if (npIsZero(c)) return NULL; 2033 lnumber l=(lnumber)omAllocBin(rnumber_bin); 2034 l->s=2; 2035 l->z=(napoly)p_Init(ntcRing); 2036 pGetCoeff(l->z)=c; /* omit npCopy, because npCopy is a no-op */ 2037 l->n=NULL; 2038 return (number)l; 2039 } 2040 2041 /*2 2042 * map Z/p' -> Z/p(a) 2043 */ 2044 number ntMapPP1(number c) 2045 { 2046 if (npIsZero(c)) return NULL; 2047 int i=(int)((long)c); 2048 if (i>(long)ntMapRing->ch) i-=(long)ntMapRing->ch; 2049 number n=npInit(i,ntMapRing); 2050 if (npIsZero(n)) return NULL; 2051 lnumber l=(lnumber)omAllocBin(rnumber_bin); 2052 l->s=2; 2053 l->z=(napoly)p_Init(ntcRing); 2054 pGetCoeff(l->z)=n; 2055 l->n=NULL; 2056 return (number)l; 2057 } 2058 2059 /*2 2060 * map Q -> Z/p(a) 2061 */ 2062 number ntMap0P(number c) 2063 { 2064 if (nlIsZero(c)) return NULL; 2065 number n=npInit(nlModP(c,npPrimeM),ntcRing); 2066 if (npIsZero(n)) return NULL; 2067 npTest(n); 2068 lnumber l=(lnumber)omAllocBin(rnumber_bin); 2069 l->s=2; 2070 l->z=(napoly)p_Init(ntcRing); 2071 pGetCoeff(l->z)=n; 2072 l->n=NULL; 2073 return (number)l; 2074 } 2075 2076 static number (*ntcMap)(number); 2077 static int ntParsToCopy; 2078 static napoly ntpMap(napoly p) 2079 { 2080 napoly w, a; 2081 2082 if (p==NULL) return NULL; 2083 a = w = (napoly)p_Init(ntcRing); 866 a = w = (napoly)p_Init(nacRing); 2084 867 int i; 2085 868 for(i=1;i<=ntParsToCopy;i++) 2086 869 napSetExp(a,i,napGetExpFrom(p,i,ntMapRing)); 2087 p_Setm(a,n tcRing);870 p_Setm(a,nacRing); 2088 871 pGetCoeff(w) = ntcMap(pGetCoeff(p)); 2089 872 loop … … 2091 874 pIter(p); 2092 875 if (p==NULL) break; 2093 pNext(a) = (napoly)p_Init(n tcRing);876 pNext(a) = (napoly)p_Init(nacRing); 2094 877 pIter(a); 2095 878 for(i=1;i<=ntParsToCopy;i++) 2096 879 napSetExp(a,i,napGetExpFrom(p,i,ntMapRing)); 2097 p_Setm(a,n tcRing);880 p_Setm(a,nacRing); 2098 881 pGetCoeff(a) = ntcMap(pGetCoeff(p)); 2099 882 } … … 2102 885 } 2103 886 2104 static napoly ntpPerm(napoly p,const int *par_perm,const ring src_ring,const nMapFunc nMap)887 napoly napPerm(napoly p,const int *par_perm,const ring src_ring,const nMapFunc nMap) 2105 888 { 2106 889 napoly w, a; 2107 890 2108 891 if (p==NULL) return NULL; 2109 w = (napoly)p_Init(n tcRing);892 w = (napoly)p_Init(nacRing); 2110 893 int i; 2111 894 BOOLEAN not_null=TRUE; … … 2124 907 } 2125 908 pGetCoeff(w) = nMap(pGetCoeff(p)); 2126 p_Setm(w,n tcRing);909 p_Setm(w,nacRing); 2127 910 pIter(p); 2128 911 if (!not_null) … … 2130 913 if (p==NULL) 2131 914 { 2132 p_Delete(&w,n tcRing);915 p_Delete(&w,nacRing); 2133 916 return NULL; 2134 917 } 2135 918 /* else continue*/ 2136 n_Delete(&(pGetCoeff(w)),n tcRing);919 n_Delete(&(pGetCoeff(w)),nacRing); 2137 920 } 2138 921 else … … 2141 924 else 2142 925 { 2143 pNext(w)=n tpPerm(p,par_perm,src_ring,nMap);926 pNext(w)=napPerm(p,par_perm,src_ring,nMap); 2144 927 return w; 2145 928 } … … 2149 932 2150 933 /*2 2151 * map _(a) -> _(b)2152 */2153 number ntMapQaQb(number c)2154 {2155 if (c==NULL) return NULL;2156 lnumber erg= (lnumber)omAlloc0Bin(rnumber_bin);2157 lnumber src =(lnumber)c;2158 erg->s=src->s;2159 erg->z=ntpMap(src->z);2160 erg->n=ntpMap(src->n);2161 return (number)erg;2162 }2163 2164 nMapFunc ntSetMap(const ring src, const ring dst)2165 {2166 ntMapRing=src;2167 if (rField_is_Q_a(dst)) /* -> Q(a) */2168 {2169 if (rField_is_Q(src))2170 {2171 return ntMap00; /*Q -> Q(a)*/2172 }2173 if (rField_is_Zp(src))2174 {2175 return ntMapP0; /* Z/p -> Q(a)*/2176 }2177 if (rField_is_Q_a(src))2178 {2179 int i;2180 ntParsToCopy=0;2181 for(i=0;i<rPar(src);i++)2182 {2183 if ((i>=rPar(dst))2184 ||(strcmp(src->parameter[i],dst->parameter[i])!=0))2185 return NULL;2186 ntParsToCopy++;2187 }2188 ntcMap=ntcCopy;2189 if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src)))2190 return ntCopy; /* Q(a) -> Q(a) */2191 return ntMapQaQb; /* Q(a..) -> Q(a..) */2192 }2193 }2194 /*-----------------------------------------------------*/2195 if (rField_is_Zp_a(dst)) /* -> Z/p(a) */2196 {2197 if (rField_is_Q(src))2198 {2199 return ntMap0P; /*Q -> Z/p(a)*/2200 }2201 if (rField_is_Zp(src))2202 {2203 if (src->ch==dst->ch)2204 {2205 return ntMapPP; /* Z/p -> Z/p(a)*/2206 }2207 else2208 {2209 return ntMapPP1; /* Z/p' -> Z/p(a)*/2210 }2211 }2212 if (rField_is_Zp_a(src))2213 {2214 if (rChar(src)==rChar(dst))2215 {2216 ntcMap=ntcCopy;2217 }2218 else2219 {2220 ntcMap = npMapP;2221 }2222 int i;2223 ntParsToCopy=0;2224 for(i=0;i<rPar(src);i++)2225 {2226 if ((i>=rPar(dst))2227 ||(strcmp(src->parameter[i],dst->parameter[i])!=0))2228 return NULL;2229 ntParsToCopy++;2230 }2231 if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src))2232 && (ntcMap==ntcCopy))2233 return ntCopy; /* Z/p(a) -> Z/p(a) */2234 return ntMapQaQb; /* Z/p(a),Z/p'(a) -> Z/p(b)*/2235 }2236 }2237 return NULL; /* default */2238 }2239 2240 /*22241 934 * convert a napoly number into a poly 2242 935 */ 2243 poly n tPermNumber(number z, int * par_perm, int P, ring oldRing)936 poly napPermNumber(number z, int * par_perm, int P, ring oldRing) 2244 937 { 2245 938 if (z==NULL) return NULL; … … 2248 941 napoly za=((lnumber)z)->z; 2249 942 napoly zb=((lnumber)z)->n; 2250 nMapFunc nMap=n tSetMap(oldRing,currRing);943 nMapFunc nMap=naSetMap(oldRing,currRing); 2251 944 if (currRing->parameter!=NULL) 2252 nMap=currRing->algring->cf->cfSetMap(oldRing->algring, n tcRing);945 nMap=currRing->algring->cf->cfSetMap(oldRing->algring, nacRing); 2253 946 else 2254 947 nMap=currRing->cf->cfSetMap(oldRing->algring, currRing); … … 2271 964 pan=(lnumber)pGetCoeff(p); 2272 965 pan->s=2; 2273 pan->z=n tpInitz(nMap(pGetCoeff(za)));966 pan->z=napInitz(nMap(pGetCoeff(za))); 2274 967 pa=pan->z; 2275 968 } … … 2287 980 { 2288 981 napSetExp(pa,i+1,napGetExpFrom(za,i+1,oldRing)); 2289 p_Setm(pa,n tcRing);982 p_Setm(pa,nacRing); 2290 983 } 2291 984 else … … 2300 993 { 2301 994 napSetExp(pa,-par_perm[i], napGetExpFrom(za,i+1,oldRing)); 2302 p_Setm(pa,n tcRing);995 p_Setm(pa,nacRing); 2303 996 } 2304 997 else … … 2316 1009 if (currRing->P>0) 2317 1010 { 2318 pan->n=n tpPerm(zb,par_perm,oldRing,nMap);1011 pan->n=napPerm(zb,par_perm,oldRing,nMap); 2319 1012 if(pan->n==NULL) /* error in mapping or mapping to variable */ 2320 1013 pDelete(&p); … … 2333 1026 } 2334 1027 1028 number napGetDenom(number &n, const ring r) 1029 { 1030 lnumber x=(lnumber)n; 1031 if (x->n!=NULL) 1032 { 1033 lnumber rr=(lnumber)omAlloc0Bin(rnumber_bin); 1034 rr->z=p_Copy(x->n,r->algring); 1035 rr->s = 2; 1036 return (number)rr; 1037 } 1038 return n_Init(1,r); 1039 } 1040 1041 number napGetNumerator(number &n, const ring r) 1042 { 1043 lnumber x=(lnumber)n; 1044 lnumber rr=(lnumber)omAlloc0Bin(rnumber_bin); 1045 rr->z=p_Copy(x->z,r->algring); 1046 rr->s = 2; 1047 return (number)rr; 1048 } 1049 1050 /*================ procedure for rational functions: ntXXXX =================*/ 1051 1052 /*2 1053 * z:= i 1054 */ 1055 number ntInit(int i, const ring r) 1056 { 1057 if (i!=0) 1058 { 1059 number c=n_Init(i,r->algring); 1060 if (!n_IsZero(c,r->algring)) 1061 { 1062 poly z=p_Init(r->algring); 1063 pSetCoeff0(z,c); 1064 lnumber l = (lnumber)omAllocBin(rnumber_bin); 1065 l->z = z; 1066 l->s = 2; 1067 l->n = NULL; 1068 return (number)l; 1069 } 1070 } 1071 /*else*/ 1072 return NULL; 1073 } 1074 1075 /*3 1076 * division with remainder: f = g*q + r, 1077 * returns r and destroys f 1078 */ 1079 napoly ntRemainder(napoly f, const napoly g) 1080 { 1081 napoly a, h, qq; 1082 1083 qq = (napoly)p_Init(nacRing); 1084 pNext(qq) = NULL; 1085 p_Normalize(g, nacRing); 1086 p_Normalize(f, nacRing); 1087 a = f; 1088 do 1089 { 1090 napSetExp(qq,1, p_GetExp(a,1,nacRing) - p_GetExp(g,1,nacRing)); 1091 napSetm(qq); 1092 pGetCoeff(qq) = ntcDiv(pGetCoeff(a), pGetCoeff(g)); 1093 pGetCoeff(qq) = ntcNeg(pGetCoeff(qq)); 1094 ntcNormalize(pGetCoeff(qq)); 1095 h = napCopy(g); 1096 napMultT(h, qq); 1097 p_Normalize(h,nacRing); 1098 n_Delete(&pGetCoeff(qq),nacRing); 1099 a = napAdd(a, h); 1100 } 1101 while ((a!=NULL) && (p_GetExp(a,1,nacRing) >= p_GetExp(g,1,nacRing))); 1102 omFreeBinAddr(qq); 1103 return a; 1104 } 1105 1106 number ntPar(int i) 1107 { 1108 lnumber l = (lnumber)omAllocBin(rnumber_bin); 1109 l->s = 2; 1110 l->z = p_ISet(1,nacRing); 1111 napSetExp(l->z,i,1); 1112 p_Setm(l->z,nacRing); 1113 l->n = NULL; 1114 return (number)l; 1115 } 1116 1117 int ntParDeg(number n) /* i := deg(n) */ 1118 { 1119 lnumber l = (lnumber)n; 1120 if (l==NULL) return -1; 1121 return napDeg(l->z); 1122 } 1123 1124 //int ntParDeg(number n) /* i := deg(n) */ 1125 //{ 1126 // lnumber l = (lnumber)n; 1127 // if (l==NULL) return -1; 1128 // return napMaxDeg(l->z)+napMaxDeg(l->n); 1129 //} 1130 1131 int ntSize(number n) /* size desc. */ 1132 { 1133 lnumber l = (lnumber)n; 1134 if (l==NULL) return -1; 1135 int len_z; 1136 int len_n; 1137 int o=napMaxDegLen(l->z,len_z)+napMaxDegLen(l->n,len_n); 1138 return (len_z+len_n)+o; 1139 } 1140 1141 /*2 1142 * convert a number to int (if possible) 1143 */ 1144 int ntInt(number &n, const ring r) 1145 { 1146 lnumber l=(lnumber)n; 1147 if ((l!=NULL)&&(l->n==NULL)&&(p_IsConstant(l->z,r->algring))) 1148 { 1149 return ntcInt(pGetCoeff(l->z),r->algring); 1150 } 1151 return 0; 1152 } 1153 1154 /*2 1155 * deletes p 1156 */ 1157 void ntDelete(number *p, const ring r) 1158 { 1159 if ((*p)!=NULL) 1160 { 1161 lnumber l = (lnumber) * p; 1162 if (l==NULL) return; 1163 p_Delete(&(l->z),r->algring); 1164 p_Delete(&(l->n),r->algring); 1165 omFreeBin((ADDRESS)l, rnumber_bin); 1166 } 1167 *p = NULL; 1168 } 1169 1170 /*2 1171 * copy p to erg 1172 */ 1173 number ntCopy(number p) 1174 { 1175 if (p==NULL) return NULL; 1176 ntTest(p); 1177 lnumber erg; 1178 lnumber src = (lnumber)p; 1179 erg = (lnumber)omAlloc0Bin(rnumber_bin); 1180 erg->z = p_Copy(src->z, nacRing); 1181 erg->n = p_Copy(src->n, nacRing); 1182 erg->s = src->s; 1183 return (number)erg; 1184 } 1185 number nt_Copy(number p, const ring r) 1186 { 1187 if (p==NULL) return NULL; 1188 lnumber erg; 1189 lnumber src = (lnumber)p; 1190 erg = (lnumber)omAlloc0Bin(rnumber_bin); 1191 erg->z = p_Copy(src->z,r->algring); 1192 erg->n = p_Copy(src->n,r->algring); 1193 erg->s = src->s; 1194 return (number)erg; 1195 } 1196 1197 /*2 1198 * addition; lu:= la + lb 1199 */ 1200 number ntAdd(number la, number lb) 1201 { 1202 if (la==NULL) return ntCopy(lb); 1203 if (lb==NULL) return ntCopy(la); 1204 1205 napoly x, y; 1206 lnumber lu; 1207 lnumber a = (lnumber)la; 1208 lnumber b = (lnumber)lb; 1209 #ifdef LDEBUG 1210 omCheckAddrSize(a,sizeof(snumber)); 1211 omCheckAddrSize(b,sizeof(snumber)); 1212 #endif 1213 if (b->n!=NULL) x = pp_Mult_qq(a->z, b->n,nacRing); 1214 else x = napCopy(a->z); 1215 if (a->n!=NULL) y = pp_Mult_qq(b->z, a->n,nacRing); 1216 else y = napCopy(b->z); 1217 napoly res = napAdd(x, y); 1218 if (res==NULL) 1219 { 1220 return (number)NULL; 1221 } 1222 lu = (lnumber)omAllocBin(rnumber_bin); 1223 lu->z=res; 1224 if (a->n!=NULL) 1225 { 1226 if (b->n!=NULL) x = pp_Mult_qq(a->n, b->n,nacRing); 1227 else x = napCopy(a->n); 1228 } 1229 else 1230 { 1231 if (b->n!=NULL) x = napCopy(b->n); 1232 else x = NULL; 1233 } 1234 //if (x!=NULL) 1235 //{ 1236 // if (p_LmIsConstant(x,nacRing)) 1237 // { 1238 // number inv=ntcInvers(pGetCoeff(x)); 1239 // napMultN(lu->z,inv); 1240 // n_Delete(&inv,nacRing); 1241 // napDelete(&x); 1242 // } 1243 //} 1244 lu->n = x; 1245 lu->s = FALSE; 1246 if (/*lu->n*/ x!=NULL) 1247 { 1248 number luu=(number)lu; 1249 //if (p_IsConstant(lu->n,nacRing)) ntCoefNormalize(luu); 1250 //else 1251 ntNormalize(luu); 1252 lu=(lnumber)luu; 1253 } 1254 //else lu->s=2; 1255 ntTest((number)lu); 1256 return (number)lu; 1257 } 1258 1259 /*2 1260 * subtraction; r:= la - lb 1261 */ 1262 number ntSub(number la, number lb) 1263 { 1264 lnumber lu; 1265 1266 if (lb==NULL) return ntCopy(la); 1267 if (la==NULL) 1268 { 1269 lu = (lnumber)ntCopy(lb); 1270 lu->z = napNeg(lu->z); 1271 return (number)lu; 1272 } 1273 1274 lnumber a = (lnumber)la; 1275 lnumber b = (lnumber)lb; 1276 1277 #ifdef LDEBUG 1278 omCheckAddrSize(a,sizeof(snumber)); 1279 omCheckAddrSize(b,sizeof(snumber)); 1280 #endif 1281 1282 napoly x, y; 1283 if (b->n!=NULL) x = pp_Mult_qq(a->z, b->n,nacRing); 1284 else x = napCopy(a->z); 1285 if (a->n!=NULL) y = p_Mult_q(napCopy(b->z), napCopyNeg(a->n),nacRing); 1286 else y = napCopyNeg(b->z); 1287 napoly res = napAdd(x, y); 1288 if (res==NULL) 1289 { 1290 return (number)NULL; 1291 } 1292 lu = (lnumber)omAllocBin(rnumber_bin); 1293 lu->z=res; 1294 if (a->n!=NULL) 1295 { 1296 if (b->n!=NULL) x = pp_Mult_qq(a->n, b->n,nacRing); 1297 else x = napCopy(a->n); 1298 } 1299 else 1300 { 1301 if (b->n!=NULL) x = napCopy(b->n); 1302 else x = NULL; 1303 } 1304 lu->n = x; 1305 lu->s = FALSE; 1306 if (/*lu->n*/ x!=NULL) 1307 { 1308 number luu=(number)lu; 1309 //if (p_IsConstant(lu->n,nacRing)) ntCoefNormalize(luu); 1310 //else 1311 ntNormalize(luu); 1312 lu=(lnumber)luu; 1313 } 1314 //else lu->s=2; 1315 ntTest((number)lu); 1316 return (number)lu; 1317 } 1318 1319 /*2 1320 * multiplication; r:= la * lb 1321 */ 1322 number ntMult(number la, number lb) 1323 { 1324 if ((la==NULL) || (lb==NULL)) 1325 return NULL; 1326 1327 lnumber a = (lnumber)la; 1328 lnumber b = (lnumber)lb; 1329 lnumber lo; 1330 napoly x; 1331 1332 #ifdef LDEBUG 1333 omCheckAddrSize(a,sizeof(snumber)); 1334 omCheckAddrSize(b,sizeof(snumber)); 1335 #endif 1336 ntTest(la); 1337 ntTest(lb); 1338 1339 lo = (lnumber)omAllocBin(rnumber_bin); 1340 lo->z = pp_Mult_qq(a->z, b->z,nacRing); 1341 1342 if (a->n==NULL) 1343 { 1344 if (b->n==NULL) 1345 x = NULL; 1346 else 1347 x = napCopy(b->n); 1348 } 1349 else 1350 { 1351 if (b->n==NULL) 1352 { 1353 x = napCopy(a->n); 1354 } 1355 else 1356 { 1357 x = pp_Mult_qq(b->n, a->n, nacRing); 1358 } 1359 } 1360 if (naI!=NULL) 1361 { 1362 lo->z = napRedp (lo->z); 1363 if (lo->z != NULL) 1364 lo->z = napTailred (lo->z); 1365 if (x!=NULL) 1366 { 1367 x = napRedp (x); 1368 if (x!=NULL) 1369 x = napTailred (x); 1370 } 1371 } 1372 if ((x!=NULL) && (p_LmIsConstant(x,nacRing)) && ntcIsOne(pGetCoeff(x))) 1373 p_Delete(&x,nacRing); 1374 lo->n = x; 1375 lo->s = 0; 1376 if(lo->z==NULL) 1377 { 1378 omFreeBin((ADDRESS)lo, rnumber_bin); 1379 lo=NULL; 1380 } 1381 else if (lo->n!=NULL) 1382 { 1383 number luu=(number)lo; 1384 // if (p_IsConstant(lo->n,nacRing)) ntCoefNormalize(luu); 1385 // else 1386 ntNormalize(luu); 1387 lo=(lnumber)luu; 1388 } 1389 //if (naMinimalPoly==NULL) lo->s=2; 1390 ntTest((number)lo); 1391 return (number)lo; 1392 } 1393 1394 number ntIntDiv(number la, number lb) 1395 { 1396 lnumber res; 1397 lnumber a = (lnumber)la; 1398 lnumber b = (lnumber)lb; 1399 if (a==NULL) 1400 { 1401 return NULL; 1402 } 1403 if (b==NULL) 1404 { 1405 WerrorS(nDivBy0); 1406 return NULL; 1407 } 1408 assume(a->z!=NULL && b->z!=NULL); 1409 assume(a->n==NULL && b->n==NULL); 1410 res = (lnumber)omAllocBin(rnumber_bin); 1411 res->z = napCopy(a->z); 1412 res->n = napCopy(b->z); 1413 res->s = 0; 1414 number nres=(number)res; 1415 ntNormalize(nres); 1416 1417 //napDelete(&res->n); 1418 ntTest(nres); 1419 return nres; 1420 } 1421 1422 /*2 1423 * division; lo:= la / lb 1424 */ 1425 number ntDiv(number la, number lb) 1426 { 1427 lnumber lo; 1428 lnumber a = (lnumber)la; 1429 lnumber b = (lnumber)lb; 1430 napoly x; 1431 1432 if (a==NULL) 1433 return NULL; 1434 1435 if (b==NULL) 1436 { 1437 WerrorS(nDivBy0); 1438 return NULL; 1439 } 1440 #ifdef LDEBUG 1441 omCheckAddrSize(a,sizeof(snumber)); 1442 omCheckAddrSize(b,sizeof(snumber)); 1443 #endif 1444 lo = (lnumber)omAllocBin(rnumber_bin); 1445 if (b->n!=NULL) 1446 lo->z = pp_Mult_qq(a->z, b->n,nacRing); 1447 else 1448 lo->z = napCopy(a->z); 1449 if (a->n!=NULL) 1450 x = pp_Mult_qq(b->z, a->n, nacRing); 1451 else 1452 x = napCopy(b->z); 1453 if (naI!=NULL) 1454 { 1455 lo->z = napRedp (lo->z); 1456 if (lo->z != NULL) 1457 lo->z = napTailred (lo->z); 1458 if (x!=NULL) 1459 { 1460 x = napRedp (x); 1461 if (x!=NULL) 1462 x = napTailred (x); 1463 } 1464 } 1465 if ((p_LmIsConstant(x,nacRing)) && ntcIsOne(pGetCoeff(x))) 1466 p_Delete(&x,nacRing); 1467 lo->n = x; 1468 lo->s = 0; 1469 if (lo->n!=NULL) 1470 { 1471 number luu=(number)lo; 1472 //if (p_IsConstant(lo->n,nacRing)) ntCoefNormalize(luu); 1473 //else 1474 ntNormalize(luu); 1475 lo=(lnumber)luu; 1476 } 1477 //else lo->s=2; 1478 ntTest((number)lo); 1479 return (number)lo; 1480 } 1481 1482 /*2 1483 * za:= - za, inplace 1484 */ 1485 number ntNeg(number za) 1486 { 1487 if (za!=NULL) 1488 { 1489 lnumber e = (lnumber)za; 1490 ntTest(za); 1491 e->z = napNeg(e->z); 1492 } 1493 return za; 1494 } 1495 1496 /*2 1497 * 1/a 1498 */ 1499 number ntInvers(number a) 1500 { 1501 lnumber lo; 1502 lnumber b = (lnumber)a; 1503 napoly x; 1504 1505 if (b==NULL) 1506 { 1507 WerrorS(nDivBy0); 1508 return NULL; 1509 } 1510 #ifdef LDEBUG 1511 omCheckAddrSize(b,sizeof(snumber)); 1512 #endif 1513 lo = (lnumber)omAlloc0Bin(rnumber_bin); 1514 lo->s = b->s; 1515 if (b->n!=NULL) 1516 lo->z = napCopy(b->n); 1517 else 1518 lo->z = p_ISet(1,nacRing); 1519 x = b->z; 1520 if ((!p_LmIsConstant(x,nacRing)) || !ntcIsOne(pGetCoeff(x))) 1521 x = napCopy(x); 1522 else 1523 { 1524 lo->n = NULL; 1525 ntTest((number)lo); 1526 return (number)lo; 1527 } 1528 lo->n = x; 1529 if (lo->n!=NULL) 1530 { 1531 number luu=(number)lo; 1532 //if (p_IsConstant(lo->n,nacRing)) ntCoefNormalize(luu); 1533 //else 1534 ntNormalize(luu); 1535 lo=(lnumber)luu; 1536 } 1537 ntTest((number)lo); 1538 return (number)lo; 1539 } 1540 1541 1542 BOOLEAN ntIsZero(number za) 1543 { 1544 lnumber zb = (lnumber)za; 1545 ntTest(za); 1546 #ifdef LDEBUG 1547 if ((zb!=NULL) && (zb->z==NULL)) WerrorS("internal zero error(2)"); 1548 #endif 1549 return (zb==NULL); 1550 } 1551 1552 1553 BOOLEAN ntGreaterZero(number za) 1554 { 1555 lnumber zb = (lnumber)za; 1556 #ifdef LDEBUG 1557 if ((zb!=NULL) && (zb->z==NULL)) WerrorS("internal zero error(3)"); 1558 #endif 1559 ntTest(za); 1560 if (zb!=NULL) 1561 { 1562 return (ntcGreaterZero(pGetCoeff(zb->z))||(!p_LmIsConstant(zb->z,nacRing))); 1563 } 1564 /* else */ return FALSE; 1565 } 1566 1567 1568 /*2 1569 * a = b ? 1570 */ 1571 BOOLEAN ntEqual (number a, number b) 1572 { 1573 if(a==b) return TRUE; 1574 if((a==NULL)&&(b!=NULL)) return FALSE; 1575 if((b==NULL)&&(a!=NULL)) return FALSE; 1576 1577 lnumber aa=(lnumber)a; 1578 lnumber bb=(lnumber)b; 1579 1580 int an_deg=0; 1581 if(aa->n!=NULL) 1582 an_deg=napDeg(aa->n); 1583 int bn_deg=0; 1584 if(bb->n!=NULL) 1585 bn_deg=napDeg(bb->n); 1586 if(an_deg+napDeg(bb->z)!=bn_deg+napDeg(aa->z)) 1587 return FALSE; 1588 #if 0 1589 ntNormalize(a); 1590 aa=(lnumber)a; 1591 ntNormalize(b); 1592 bb=(lnumber)b; 1593 if((aa->n==NULL)&&(bb->n!=NULL)) return FALSE; 1594 if((bb->n==NULL)&&(aa->n!=NULL)) return FALSE; 1595 if(napComp(aa->z,bb->z)!=0) return FALSE; 1596 if((aa->n!=NULL) && (napComp(aa->n,bb->n))) return FALSE; 1597 #endif 1598 number h = ntSub(a, b); 1599 BOOLEAN bo = ntIsZero(h); 1600 ntDelete(&h,currRing); 1601 return bo; 1602 } 1603 1604 1605 BOOLEAN ntGreater (number a, number b) 1606 { 1607 if (ntIsZero(a)) 1608 return FALSE; 1609 if (ntIsZero(b)) 1610 return TRUE; /* a!= 0)*/ 1611 return napDeg(((lnumber)a)->z)>napDeg(((lnumber)b)->z); 1612 } 1613 1614 /*2 1615 * reads a number 1616 */ 1617 const char *ntRead(const char *s, number *p) 1618 { 1619 napoly x; 1620 lnumber a; 1621 s = napRead(s, &x); 1622 if (x==NULL) 1623 { 1624 *p = NULL; 1625 return s; 1626 } 1627 *p = (number)omAlloc0Bin(rnumber_bin); 1628 a = (lnumber)*p; 1629 if (naI!=NULL) 1630 { 1631 a->z = napRedp(x); 1632 if (a->z != NULL) 1633 a->z = napTailred (a->z); 1634 } 1635 else 1636 a->z = x; 1637 if(a->z==NULL) 1638 { 1639 omFreeBin((ADDRESS)*p, rnumber_bin); 1640 *p=NULL; 1641 } 1642 else 1643 { 1644 a->n = NULL; 1645 a->s = 0; 1646 ntTest(*p); 1647 } 1648 return s; 1649 } 1650 1651 /*2 1652 * tries to convert a number to a name 1653 */ 1654 char * ntName(number n) 1655 { 1656 lnumber ph = (lnumber)n; 1657 if (ph==NULL) 1658 return NULL; 1659 int i; 1660 char *s=(char *)omAlloc(4* ntNumbOfPar); 1661 char *t=(char *)omAlloc(8); 1662 s[0]='\0'; 1663 for (i = 0; i <= ntNumbOfPar - 1; i++) 1664 { 1665 int e=p_GetExp(ph->z,i+1,nacRing); 1666 if (e > 0) 1667 { 1668 if (e >1) 1669 { 1670 sprintf(t,"%s%d",naParNames[i],e); 1671 strcat(s,t); 1672 } 1673 else 1674 { 1675 strcat(s,naParNames[i]); 1676 } 1677 } 1678 } 1679 omFreeSize((ADDRESS)t,8); 1680 if (s[0]=='\0') 1681 { 1682 omFree((ADDRESS)s); 1683 return NULL; 1684 } 1685 return s; 1686 } 1687 1688 /*2 1689 * writes a number 1690 */ 1691 void ntWrite(number &phn, const ring r) 1692 { 1693 lnumber ph = (lnumber)phn; 1694 if (ph==NULL) 1695 StringAppendS("0"); 1696 else 1697 { 1698 phn->s = 0; 1699 BOOLEAN has_denom=(ph->n!=NULL); 1700 napWrite(ph->z,has_denom/*(ph->n!=NULL)*/,r); 1701 if (has_denom/*(ph->n!=NULL)*/) 1702 { 1703 StringAppendS("/"); 1704 napWrite(ph->n,TRUE,r); 1705 } 1706 } 1707 } 1708 1709 /*2 1710 * za == 1 ? 1711 */ 1712 BOOLEAN ntIsOne(number za) 1713 { 1714 lnumber a = (lnumber)za; 1715 napoly x, y; 1716 number t; 1717 if (a==NULL) return FALSE; 1718 #ifdef LDEBUG 1719 omCheckAddrSize(a,sizeof(snumber)); 1720 if (a->z==NULL) 1721 { 1722 WerrorS("internal zero error(4)"); 1723 return FALSE; 1724 } 1725 #endif 1726 if (a->n==NULL) 1727 { 1728 if (p_LmIsConstant(a->z,nacRing)) 1729 { 1730 return ntcIsOne(pGetCoeff(a->z)); 1731 } 1732 else return FALSE; 1733 } 1734 #if 0 1735 x = a->z; 1736 y = a->n; 1737 do 1738 { 1739 if (napComp(x, y)) 1740 return FALSE; 1741 else 1742 { 1743 t = ntcSub(pGetCoeff(x), pGetCoeff(y)); 1744 if (!ntcIsZero(t)) 1745 { 1746 n_Delete(&t,nacRing); 1747 return FALSE; 1748 } 1749 else 1750 n_Delete(&t,nacRing); 1751 } 1752 pIter(x); 1753 pIter(y); 1754 } 1755 while ((x!=NULL) && (y!=NULL)); 1756 if ((x!=NULL) || (y!=NULL)) return FALSE; 1757 p_Delete(&a->z,nacRing); 1758 p_Delete(&a->n,nacRing); 1759 a->z = p_ISet(1,nacRing); 1760 a->n = NULL; 1761 return TRUE; 1762 #else 1763 return FALSE; 1764 #endif 1765 } 1766 1767 /*2 1768 * za == -1 ? 1769 */ 1770 BOOLEAN ntIsMOne(number za) 1771 { 1772 lnumber a = (lnumber)za; 1773 napoly x, y; 1774 number t; 1775 if (a==NULL) return FALSE; 1776 #ifdef LDEBUG 1777 omCheckAddrSize(a,sizeof(snumber)); 1778 if (a->z==NULL) 1779 { 1780 WerrorS("internal zero error(5)"); 1781 return FALSE; 1782 } 1783 #endif 1784 if (a->n==NULL) 1785 { 1786 if (p_LmIsConstant(a->z,nacRing)) return ntcIsMOne(pGetCoeff(a->z)); 1787 /*else return FALSE;*/ 1788 } 1789 return FALSE; 1790 } 1791 1792 /*2 1793 * returns the i-th power of p (i>=0) 1794 */ 1795 void ntPower(number p, int i, number *rc) 1796 { 1797 number x; 1798 *rc = ntInit(1,currRing); 1799 for (; i > 0; i--) 1800 { 1801 x = ntMult(*rc, p); 1802 ntDelete(rc,currRing); 1803 *rc = x; 1804 } 1805 } 1806 1807 /*2 1808 * result =gcd(a,b) 1809 */ 1810 number ntGcd(number a, number b, const ring r) 1811 { 1812 if (a==NULL) return ntCopy(b); 1813 if (b==NULL) return ntCopy(a); 1814 1815 lnumber x, y; 1816 lnumber result = (lnumber)omAlloc0Bin(rnumber_bin); 1817 1818 x = (lnumber)a; 1819 y = (lnumber)b; 1820 #ifndef HAVE_FACTORY 1821 result->z = napGcd(x->z, y->z); // change from napGcd0 1822 #else 1823 int c=ABS(nGetChar()); 1824 if (c==1) c=0; 1825 setCharacteristic( c ); 1826 1827 napoly rz=napGcd(x->z, y->z); 1828 CanonicalForm F, G, R; 1829 R=convSingPFactoryP(rz,r->algring); 1830 p_Normalize(x->z,nacRing); 1831 F=convSingPFactoryP(x->z,r->algring)/R; 1832 p_Normalize(y->z,nacRing); 1833 G=convSingPFactoryP(y->z,r->algring)/R; 1834 F = gcd( F, G ); 1835 if (F.isOne()) 1836 result->z= rz; 1837 else 1838 { 1839 p_Delete(&rz,r->algring); 1840 result->z=convFactoryPSingP( F*R,r->algring ); 1841 p_Normalize(result->z,nacRing); 1842 } 1843 #endif 1844 ntTest((number)result); 1845 return (number)result; 1846 } 1847 1848 1849 /*2 1850 * ntNumbOfPar = 1: 1851 * clears denominator algebraic case; 1852 * tries to simplify ratio transcendental case; 1853 * 1854 * cancels monomials 1855 * occuring in denominator 1856 * and enumerator ? ntNumbOfPar != 1; 1857 * 1858 * #defines for Factory: 1859 * FACTORY_GCD_TEST: do not apply built in gcd for 1860 * univariate polynomials, always use Factory 1861 */ 1862 //#define FACTORY_GCD_TEST 1863 void ntCoefNormalize(number pp) 1864 { 1865 if (pp==NULL) return; 1866 lnumber p = (lnumber)pp; 1867 number nz; // all denom. of the numerator 1868 nz=p_GetAllDenom(p->z,nacRing); 1869 BOOLEAN norm=FALSE; 1870 if (!n_IsOne(nz,nacRing)) 1871 { 1872 norm=TRUE; 1873 p->z=p_Mult_nn(p->z,nz,nacRing); 1874 if (p->n==NULL) 1875 { 1876 p->n=p_NSet(nz,nacRing); 1877 } 1878 else 1879 { 1880 p->n=p_Mult_nn(p->n,nz,nacRing); 1881 n_Delete(&nz, nacRing); 1882 } 1883 } 1884 else 1885 { 1886 n_Delete(&nz, nacRing); 1887 } 1888 if (norm) 1889 { 1890 norm=FALSE; 1891 p_Normalize(p->z,nacRing); 1892 p_Normalize(p->n,nacRing); 1893 } 1894 number nn; 1895 nn=p_GetAllDenom(p->n,nacRing); 1896 if (!n_IsOne(nn,nacRing)) 1897 { 1898 norm=TRUE; 1899 p->n=p_Mult_nn(p->n,nn,nacRing); 1900 p->z=p_Mult_nn(p->z,nn,nacRing); 1901 n_Delete(&nn, nacRing); 1902 } 1903 else 1904 { 1905 n_Delete(&nn, nacRing); 1906 } 1907 if (norm) 1908 { 1909 p_Normalize(p->z,nacRing); 1910 p_Normalize(p->n,nacRing); 1911 } 1912 // remove common factors in n, z: 1913 if (p->n!=NULL) 1914 { 1915 poly pp=p->z; 1916 nz=n_Copy(pGetCoeff(pp),nacRing); 1917 pIter(pp); 1918 while(pp!=NULL) 1919 { 1920 if (n_IsOne(nz,nacRing)) break; 1921 number d=n_Gcd(nz,pGetCoeff(pp),nacRing); 1922 n_Delete(&nz,nacRing); nz=d; 1923 pIter(pp); 1924 } 1925 if (!n_IsOne(nz,nacRing)) 1926 { 1927 pp=p->n; 1928 nn=n_Copy(pGetCoeff(pp),nacRing); 1929 pIter(pp); 1930 while(pp!=NULL) 1931 { 1932 if (n_IsOne(nn,nacRing)) break; 1933 number d=n_Gcd(nn,pGetCoeff(pp),nacRing); 1934 n_Delete(&nn,nacRing); nn=d; 1935 pIter(pp); 1936 } 1937 number ng=n_Gcd(nz,nn,nacRing); 1938 n_Delete(&nn,nacRing); 1939 if (!n_IsOne(ng,nacRing)) 1940 { 1941 number ni=n_Invers(ng,nacRing); 1942 p->z=p_Mult_nn(p->z,ni,nacRing); 1943 p->n=p_Mult_nn(p->n,ni,nacRing); 1944 p_Normalize(p->z,nacRing); 1945 p_Normalize(p->n,nacRing); 1946 n_Delete(&ni,nacRing); 1947 } 1948 n_Delete(&ng,nacRing); 1949 } 1950 n_Delete(&nz,nacRing); 1951 } 1952 if (p->n!=NULL) 1953 { 1954 if(!ntcGreaterZero(pGetCoeff(p->n))) 1955 { 1956 p->z=napNeg(p->z); 1957 p->n=napNeg(p->n); 1958 } 1959 1960 if (/*(p->n!=NULL) && */ 1961 (p_IsConstant(p->n,nacRing)) 1962 && (n_IsOne(pGetCoeff(p->n),nacRing))) 1963 { 1964 p_Delete(&(p->n), nacRing); 1965 p->n = NULL; 1966 } 1967 } 1968 } 1969 1970 void ntNormalize(number &pp) 1971 { 1972 1973 //ntTest(pp); // input may not be "normal" 1974 lnumber p = (lnumber)pp; 1975 1976 if (p==NULL) 1977 return; 1978 ntCoefNormalize(pp); 1979 p->s = 2; 1980 napoly x = p->z; 1981 napoly y = p->n; 1982 1983 BOOLEAN norm=FALSE; 1984 1985 if (y==NULL) return; 1986 1987 if ((x!=NULL) && (y!=NULL)) 1988 { 1989 int i; 1990 for (i=ntNumbOfPar-1; i>=0; i--) 1991 { 1992 napoly xx=x; 1993 napoly yy=y; 1994 int m = napExpi(i, yy, xx); 1995 if (m != 0) // in this case xx!=NULL!=yy 1996 { 1997 while (xx != NULL) 1998 { 1999 napAddExp(xx,i+1, -m); 2000 pIter(xx); 2001 } 2002 while (yy != NULL) 2003 { 2004 napAddExp(yy,i+1, -m); 2005 pIter(yy); 2006 } 2007 } 2008 } 2009 } 2010 if (p_LmIsConstant(y,nacRing)) /* i.e. => simplify to (1/c)*z / monom */ 2011 { 2012 if (ntcIsOne(pGetCoeff(y))) 2013 { 2014 p_LmDelete(&y,nacRing); 2015 p->n = NULL; 2016 ntTest(pp); 2017 return; 2018 } 2019 number h1 = ntcInvers(pGetCoeff(y)); 2020 ntcNormalize(h1); 2021 napMultN(x, h1); 2022 n_Delete(&h1,nacRing); 2023 p_LmDelete(&y,nacRing); 2024 p->n = NULL; 2025 ntTest(pp); 2026 return; 2027 } 2028 #ifndef FACTORY_GCD_TEST 2029 if (ntNumbOfPar == 1) /* apply built-in gcd */ 2030 { 2031 napoly x1,y1; 2032 if (p_GetExp(x,1,nacRing) >= p_GetExp(y,1,nacRing)) 2033 { 2034 x1 = napCopy(x); 2035 y1 = napCopy(y); 2036 } 2037 else 2038 { 2039 x1 = napCopy(y); 2040 y1 = napCopy(x); 2041 } 2042 napoly r; 2043 loop 2044 { 2045 r = ntRemainder(x1, y1); 2046 if ((r==NULL) || (pNext(r)==NULL)) break; 2047 x1 = y1; 2048 y1 = r; 2049 } 2050 if (r!=NULL) 2051 { 2052 p_Delete(&r,nacRing); 2053 p_Delete(&y1,nacRing); 2054 } 2055 else 2056 { 2057 napDivMod(x, y1, &(p->z), &r); 2058 napDivMod(y, y1, &(p->n), &r); 2059 p_Delete(&y1,nacRing); 2060 } 2061 x = p->z; 2062 y = p->n; 2063 /* collect all denoms from y and multiply x and y by it */ 2064 if (ntIsChar0) 2065 { 2066 number n=napLcm(y); 2067 napMultN(x,n); 2068 napMultN(y,n); 2069 n_Delete(&n,nacRing); 2070 while(x!=NULL) 2071 { 2072 ntcNormalize(pGetCoeff(x)); 2073 pIter(x); 2074 } 2075 x = p->z; 2076 while(y!=NULL) 2077 { 2078 ntcNormalize(pGetCoeff(y)); 2079 pIter(y); 2080 } 2081 y = p->n; 2082 } 2083 if (pNext(y)==NULL) 2084 { 2085 if (ntcIsOne(pGetCoeff(y))) 2086 { 2087 if (p_GetExp(y,1,nacRing)==0) 2088 { 2089 p_LmDelete(&y,nacRing); 2090 p->n = NULL; 2091 } 2092 ntTest(pp); 2093 return; 2094 } 2095 } 2096 } 2097 #endif /* FACTORY_GCD_TEST */ 2098 #ifdef HAVE_FACTORY 2099 #ifndef FACTORY_GCD_TEST 2100 else 2101 #endif 2102 { 2103 napoly xx,yy; 2104 singclap_algdividecontent(x,y,xx,yy); 2105 if (xx!=NULL) 2106 { 2107 p->z=xx; 2108 p->n=yy; 2109 p_Delete(&x,nacRing); 2110 p_Delete(&y,nacRing); 2111 } 2112 } 2113 #endif 2114 /* remove common factors from z and n */ 2115 x=p->z; 2116 y=p->n; 2117 if(!ntcGreaterZero(pGetCoeff(y))) 2118 { 2119 x=napNeg(x); 2120 y=napNeg(y); 2121 } 2122 number g=ntcCopy(pGetCoeff(x)); 2123 pIter(x); 2124 while (x!=NULL) 2125 { 2126 number d=ntcGcd(g,pGetCoeff(x), nacRing); 2127 if(ntcIsOne(d)) 2128 { 2129 n_Delete(&g,nacRing); 2130 n_Delete(&d,nacRing); 2131 ntTest(pp); 2132 return; 2133 } 2134 n_Delete(&g,nacRing); 2135 g = d; 2136 pIter(x); 2137 } 2138 while (y!=NULL) 2139 { 2140 number d=ntcGcd(g,pGetCoeff(y), nacRing); 2141 if(ntcIsOne(d)) 2142 { 2143 n_Delete(&g,nacRing); 2144 n_Delete(&d,nacRing); 2145 ntTest(pp); 2146 return; 2147 } 2148 n_Delete(&g,nacRing); 2149 g = d; 2150 pIter(y); 2151 } 2152 x=p->z; 2153 y=p->n; 2154 while (x!=NULL) 2155 { 2156 number d = ntcIntDiv(pGetCoeff(x),g); 2157 napSetCoeff(x,d); 2158 pIter(x); 2159 } 2160 while (y!=NULL) 2161 { 2162 number d = ntcIntDiv(pGetCoeff(y),g); 2163 napSetCoeff(y,d); 2164 pIter(y); 2165 } 2166 n_Delete(&g,nacRing); 2167 ntTest(pp); 2168 } 2169 2170 /*2 2171 * returns in result->n 1 2172 * and in result->z the lcm(a->z,b->n) 2173 */ 2174 number ntLcm(number la, number lb, const ring r) 2175 { 2176 lnumber result; 2177 lnumber a = (lnumber)la; 2178 lnumber b = (lnumber)lb; 2179 result = (lnumber)omAlloc0Bin(rnumber_bin); 2180 //if (((naMinimalPoly==NULL) && (naI==NULL)) || !ntIsChar0) 2181 //{ 2182 // result->z = p_ISet(1,nacRing); 2183 // return (number)result; 2184 //} 2185 //ntNormalize(lb); 2186 ntTest(la); 2187 ntTest(lb); 2188 napoly x = p_Copy(a->z, r->algring); 2189 number t = napLcm(b->z); // get all denom of b->z 2190 if (!ntcIsOne(t)) 2191 { 2192 number bt, rr; 2193 napoly xx=x; 2194 while (xx!=NULL) 2195 { 2196 bt = ntcGcd(t, pGetCoeff(xx), r->algring); 2197 rr = ntcMult(t, pGetCoeff(xx)); 2198 n_Delete(&pGetCoeff(xx),r->algring); 2199 pGetCoeff(xx) = ntcDiv(rr, bt); 2200 ntcNormalize(pGetCoeff(xx)); 2201 n_Delete(&bt,r->algring); 2202 n_Delete(&rr,r->algring); 2203 pIter(xx); 2204 } 2205 } 2206 n_Delete(&t,r->algring); 2207 result->z = x; 2208 #ifdef HAVE_FACTORY 2209 if (b->n!=NULL) 2210 { 2211 result->z=singclap_alglcm(result->z,b->n); 2212 p_Delete(&x,r->algring); 2213 } 2214 #endif 2215 ntTest(la); 2216 ntTest(lb); 2217 ntTest((number)result); 2218 return ((number)result); 2219 } 2220 2221 /*2 2222 * map Z/p -> Q(a) 2223 */ 2224 number ntMapP0(number c) 2225 { 2226 if (npIsZero(c)) return NULL; 2227 lnumber l=(lnumber)omAllocBin(rnumber_bin); 2228 l->s=2; 2229 l->z=(napoly)p_Init(nacRing); 2230 int i=(int)((long)c); 2231 if (i>((long)ntMapRing->ch>>2)) i-=(long)ntMapRing->ch; 2232 pGetCoeff(l->z)=nlInit(i, nacRing); 2233 l->n=NULL; 2234 return (number)l; 2235 } 2236 2237 /*2 2238 * map Q -> Q(a) 2239 */ 2240 number ntMap00(number c) 2241 { 2242 if (nlIsZero(c)) return NULL; 2243 lnumber l=(lnumber)omAllocBin(rnumber_bin); 2244 l->s=0; 2245 l->z=(napoly)p_Init(nacRing); 2246 pGetCoeff(l->z)=nlCopy(c); 2247 l->n=NULL; 2248 return (number)l; 2249 } 2250 2251 /*2 2252 * map Z/p -> Z/p(a) 2253 */ 2254 number ntMapPP(number c) 2255 { 2256 if (npIsZero(c)) return NULL; 2257 lnumber l=(lnumber)omAllocBin(rnumber_bin); 2258 l->s=2; 2259 l->z=(napoly)p_Init(nacRing); 2260 pGetCoeff(l->z)=c; /* omit npCopy, because npCopy is a no-op */ 2261 l->n=NULL; 2262 return (number)l; 2263 } 2264 2265 /*2 2266 * map Z/p' -> Z/p(a) 2267 */ 2268 number ntMapPP1(number c) 2269 { 2270 if (npIsZero(c)) return NULL; 2271 int i=(int)((long)c); 2272 if (i>(long)ntMapRing->ch) i-=(long)ntMapRing->ch; 2273 number n=npInit(i,ntMapRing); 2274 if (npIsZero(n)) return NULL; 2275 lnumber l=(lnumber)omAllocBin(rnumber_bin); 2276 l->s=2; 2277 l->z=(napoly)p_Init(nacRing); 2278 pGetCoeff(l->z)=n; 2279 l->n=NULL; 2280 return (number)l; 2281 } 2282 2283 /*2 2284 * map Q -> Z/p(a) 2285 */ 2286 number ntMap0P(number c) 2287 { 2288 if (nlIsZero(c)) return NULL; 2289 number n=npInit(nlModP(c,npPrimeM),nacRing); 2290 if (npIsZero(n)) return NULL; 2291 npTest(n); 2292 lnumber l=(lnumber)omAllocBin(rnumber_bin); 2293 l->s=2; 2294 l->z=(napoly)p_Init(nacRing); 2295 pGetCoeff(l->z)=n; 2296 l->n=NULL; 2297 return (number)l; 2298 } 2299 2300 /*2 2301 * map _(a) -> _(b) 2302 */ 2303 number ntMapQaQb(number c) 2304 { 2305 if (c==NULL) return NULL; 2306 lnumber erg= (lnumber)omAlloc0Bin(rnumber_bin); 2307 lnumber src =(lnumber)c; 2308 erg->s=src->s; 2309 erg->z=napMap(src->z); 2310 erg->n=napMap(src->n); 2311 return (number)erg; 2312 } 2313 2314 nMapFunc ntSetMap(const ring src, const ring dst) 2315 { 2316 ntMapRing=src; 2317 if (rField_is_Q_a(dst)) /* -> Q(a) */ 2318 { 2319 if (rField_is_Q(src)) 2320 { 2321 return ntMap00; /*Q -> Q(a)*/ 2322 } 2323 if (rField_is_Zp(src)) 2324 { 2325 return ntMapP0; /* Z/p -> Q(a)*/ 2326 } 2327 if (rField_is_Q_a(src)) 2328 { 2329 int i; 2330 ntParsToCopy=0; 2331 for(i=0;i<rPar(src);i++) 2332 { 2333 if ((i>=rPar(dst)) 2334 ||(strcmp(src->parameter[i],dst->parameter[i])!=0)) 2335 return NULL; 2336 ntParsToCopy++; 2337 } 2338 ntcMap=ntcCopy; 2339 if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src))) 2340 return ntCopy; /* Q(a) -> Q(a) */ 2341 return ntMapQaQb; /* Q(a..) -> Q(a..) */ 2342 } 2343 } 2344 /*-----------------------------------------------------*/ 2345 if (rField_is_Zp_a(dst)) /* -> Z/p(a) */ 2346 { 2347 if (rField_is_Q(src)) 2348 { 2349 return ntMap0P; /*Q -> Z/p(a)*/ 2350 } 2351 if (rField_is_Zp(src)) 2352 { 2353 if (src->ch==dst->ch) 2354 { 2355 return ntMapPP; /* Z/p -> Z/p(a)*/ 2356 } 2357 else 2358 { 2359 return ntMapPP1; /* Z/p' -> Z/p(a)*/ 2360 } 2361 } 2362 if (rField_is_Zp_a(src)) 2363 { 2364 if (rChar(src)==rChar(dst)) 2365 { 2366 ntcMap=ntcCopy; 2367 } 2368 else 2369 { 2370 ntcMap = npMapP; 2371 } 2372 int i; 2373 ntParsToCopy=0; 2374 for(i=0;i<rPar(src);i++) 2375 { 2376 if ((i>=rPar(dst)) 2377 ||(strcmp(src->parameter[i],dst->parameter[i])!=0)) 2378 return NULL; 2379 ntParsToCopy++; 2380 } 2381 if ((ntParsToCopy==rPar(dst))&&(ntParsToCopy==rPar(src)) 2382 && (ntcMap==ntcCopy)) 2383 return ntCopy; /* Z/p(a) -> Z/p(a) */ 2384 return ntMapQaQb; /* Z/p(a),Z/p'(a) -> Z/p(b)*/ 2385 } 2386 } 2387 return NULL; /* default */ 2388 } 2389 2390 /*2 2391 * convert a napoly number into a poly 2392 */ 2393 poly ntPermNumber(number z, int * par_perm, int P, ring oldRing) 2394 { 2395 if (z==NULL) return NULL; 2396 poly res=NULL; 2397 poly p; 2398 napoly za=((lnumber)z)->z; 2399 napoly zb=((lnumber)z)->n; 2400 nMapFunc nMap=ntSetMap(oldRing,currRing); 2401 if (currRing->parameter!=NULL) 2402 nMap=currRing->algring->cf->cfSetMap(oldRing->algring, nacRing); 2403 else 2404 nMap=currRing->cf->cfSetMap(oldRing->algring, currRing); 2405 if (nMap==NULL) return NULL; /* emergency exit only */ 2406 do 2407 { 2408 p = pInit(); 2409 pNext(p)=NULL; 2410 nNew(&pGetCoeff(p)); 2411 int i; 2412 for(i=pVariables;i;i--) 2413 pSetExp(p,i, 0); 2414 if (rRing_has_Comp(currRing)) pSetComp(p, 0); 2415 napoly pa=NULL; 2416 lnumber pan; 2417 if (currRing->parameter!=NULL) 2418 { 2419 assume(oldRing->algring!=NULL); 2420 pGetCoeff(p)=(number)omAlloc0Bin(rnumber_bin); 2421 pan=(lnumber)pGetCoeff(p); 2422 pan->s=2; 2423 pan->z=napInitz(nMap(pGetCoeff(za))); 2424 pa=pan->z; 2425 } 2426 else 2427 { 2428 pGetCoeff(p)=nMap(pGetCoeff(za)); 2429 } 2430 for(i=0;i<P;i++) 2431 { 2432 if(napGetExpFrom(za,i+1,oldRing)!=0) 2433 { 2434 if(par_perm==NULL) 2435 { 2436 if ((rPar(currRing)>=i) && (pa!=NULL)) 2437 { 2438 napSetExp(pa,i+1,napGetExpFrom(za,i+1,oldRing)); 2439 p_Setm(pa,nacRing); 2440 } 2441 else 2442 { 2443 pDelete(&p); 2444 break; 2445 } 2446 } 2447 else if(par_perm[i]>0) 2448 pSetExp(p,par_perm[i],napGetExpFrom(za,i+1,oldRing)); 2449 else if((par_perm[i]<0)&&(pa!=NULL)) 2450 { 2451 napSetExp(pa,-par_perm[i], napGetExpFrom(za,i+1,oldRing)); 2452 p_Setm(pa,nacRing); 2453 } 2454 else 2455 { 2456 pDelete(&p); 2457 break; 2458 } 2459 } 2460 } 2461 if (p!=NULL) 2462 { 2463 pSetm(p); 2464 if (zb!=NULL) 2465 { 2466 if (currRing->P>0) 2467 { 2468 pan->n=napPerm(zb,par_perm,oldRing,nMap); 2469 if(pan->n==NULL) /* error in mapping or mapping to variable */ 2470 pDelete(&p); 2471 } 2472 else 2473 pDelete(&p); 2474 } 2475 pTest(p); 2476 res=pAdd(res,p); 2477 } 2478 pIter(za); 2479 } 2480 while (za!=NULL); 2481 pTest(res); 2482 return res; 2483 } 2484 2335 2485 number ntGetDenom(number &n, const ring r) 2336 2486 { -
kernel/longtrans.h
ra33266 r661c214 4 4 * Computer Algebra System SINGULAR * 5 5 ****************************************/ 6 /* $Id: longtrans. cc12469 2011-02-25 13:38:49Z seelisch $ */6 /* $Id: longtrans.h 12469 2011-02-25 13:38:49Z seelisch $ */ 7 7 /* 8 8 * ABSTRACT: numbers in transcendental field extensions, i.e., … … 12 12 #include <kernel/longrat.h> 13 13 #include <kernel/polys-impl.h> 14 #include <kernel/longalg.h>15 14 16 extern ring ntcRing;15 typedef polyrec * napoly; 17 16 17 struct slnumber; 18 typedef struct slnumber * lnumber; 18 19 19 void ntSetChar(int p, ring r); 20 struct slnumber 21 { 22 napoly z; 23 napoly n; 24 BOOLEAN s; 25 }; 26 27 extern int ntNumbOfPar; 28 #define naParNames (currRing->parameter) 29 extern ring nacRing; 30 extern int ntIsChar0; 31 extern ring ntMapRing; 32 extern int ntParsToCopy; 33 34 void ntSetChar(int p, ring r); 20 35 void ntDelete (number *p, const ring r); 21 36 number ntInit(int i, const ring r); /* z := i */ … … 53 68 BOOLEAN ntDBTest(number a, const char *f,const int l); 54 69 #endif 70 napoly ntRemainder(napoly f, const napoly g); 71 void ntSetIdeal(ideal I); 72 extern number (*ntMap)(number from); 73 void ntCoefNormalize(number pp); 55 74 56 void ntSetIdeal(ideal I); 75 /* procedure variables for operations in coefficient field/ring */ 76 extern numberfunc ntcMult, ntcSub, ntcAdd, ntcDiv, ntcIntDiv; 77 extern number (*ntcGcd)(number a, number b, const ring r); 78 extern number (*ntcLcm)(number a, number b, const ring r); 79 extern number (*ntcInit)(int i, const ring r); 80 extern int (*ntcInt)(number &n, const ring r); 81 extern void (*ntcDelete)(number *a, const ring r); 82 #undef n_Delete 83 #define n_Delete(A,R) ntcDelete(A,R) 84 extern void (*ntcNormalize)(number &a); 85 extern number (*ntcNeg)(number a); 86 extern number (*ntcCopy)(number a); 87 extern number (*ntcInvers)(number a); 88 extern BOOLEAN (*ntcIsZero)(number a); 89 extern BOOLEAN (*ntcIsOne)(number a); 90 extern BOOLEAN (*ntcIsMOne)(number a); 91 extern BOOLEAN (*ntcGreaterZero)(number a); 92 extern const char * (*ntcRead) (const char *s, number *a); 93 extern number (*ntcMap)(number); 94 95 // external access to the interna 96 poly napPermNumber(number z, int * par_perm, int P, ring r); 97 #define napAddExp(p,i,e) (p_AddExp(p,i,e,currRing->algring)) 98 #define napLength(p) pLength(p) 99 #define napNeg(p) (p_Neg(p,currRing->algring)) 100 #define napVariables naNumbOfPar 101 #define napGetCoeff(p) pGetCoeff(p) 102 #define napGetExpFrom(p,i,r) (p_GetExp(p,i,r->algring)) 103 #define napSetExp(p,i,e) (p_SetExp(p,i,e,currRing->algring)) 104 #define napNew() (p_Init(currRing->algring)) 105 #define napAdd(p1,p2) (p_Add_q(p1,p2,currRing->algring)) 106 #define napSetm(p) p_Setm(p,currRing->algring) 107 #define napCopy(p) p_Copy(p,nacRing) 108 #define napSetCoeff(p,n) {n_Delete(&pGetCoeff(p),nacRing);pGetCoeff(p)=n;} 109 #define napComp(p,q) p_LmCmp((poly)p,(poly)q, nacRing) 110 #define napMultT(A,E) A=(napoly)p_Mult_mm((poly)A,(poly)E,nacRing) 111 #define napDeg(p) (int)p_Totaldegree(p, nacRing) 112 number napGetDenom(number &n, const ring r); 113 number napGetNumerator(number &n, const ring r); 114 void napTest(napoly p); 115 napoly napInitz(number z); 116 napoly napCopyNeg(napoly p); 117 void napMultN(napoly p, number z); 118 void napDivMod(napoly f, napoly g, napoly *q, napoly *r); 119 napoly napInvers(napoly x, const napoly c); 120 int napMaxDeg(napoly p); 121 int napMaxDegLen(napoly p, int &l); 122 void napWrite(napoly p,const BOOLEAN has_denom, const ring r); 123 const char *napHandleMons(const char *s, int i, napoly ex); 124 const char *napHandlePars(const char *s, int i, napoly ex); 125 const char *napRead(const char *s, napoly *b); 126 int napExp(napoly a, napoly b); 127 int napExpi(int i, napoly a, napoly b); 128 void napContent(napoly ph); 129 void napCleardenom(napoly ph); 130 napoly napGcd0(napoly a, napoly b); 131 napoly napGcd(napoly a, napoly b); 132 number napLcm(napoly a); 133 BOOLEAN napDivPoly (napoly p, napoly q); 134 napoly napRedp (napoly q); 135 napoly napTailred (napoly q); 136 napoly napMap(napoly p); 137 napoly napPerm(napoly p,const int *par_perm,const ring src_ring,const nMapFunc nMap); 57 138 58 139 #endif -
kernel/maps.cc
ra33266 r661c214 17 17 #include <omalloc/omalloc.h> 18 18 #include <kernel/kstd1.h> 19 #include <kernel/long alg.h>19 #include <kernel/longtrans.h> 20 20 #include <kernel/maps.h> 21 21 #include <kernel/prCopy.h> -
kernel/numbers.cc
ra33266 r661c214 140 140 else if (rField_is_Extension(r)) 141 141 { 142 if (r->minpoly == NULL)142 if (r->minpoly != NULL) 143 143 { 144 144 naSetChar(c,r); … … 321 321 if (rField_is_Extension(r)) 322 322 { 323 //n aInitChar(c,TRUE,r);324 n->cfDelete = n aDelete;325 n-> nNormalize = naNormalize;326 n->cfInit = n aInit;327 n->nPar = n aPar;328 n->nParDeg = n aParDeg;329 n->n_Int = n aInt;330 n->nAdd = n aAdd;331 n->nSub = n aSub;332 n->nMult = n aMult;333 n->nDiv = n aDiv;334 n->nExactDiv = n aDiv;335 n->nIntDiv = n aIntDiv;336 n->nNeg = n aNeg;337 n->nInvers = n aInvers;338 n->nCopy = n aCopy;339 n->cfCopy = n a_Copy;340 n->nGreater = n aGreater;341 n->nEqual = n aEqual;342 n->nIsZero = n aIsZero;343 n->nIsOne = n aIsOne;344 n->nIsMOne = n aIsMOne;345 n->nGreaterZero = n aGreaterZero;346 n->cfWrite = n aWrite;347 n->nRead = n aRead;348 n->nPower = n aPower;349 n->nGcd = n aGcd;350 n->nLcm = n aLcm;351 n->cfSetMap = n aSetMap;352 n->nName = n aName;353 n->nSize = n aSize;354 n->cfGetDenom = na GetDenom;355 n->cfGetNumerator = na GetNumerator;356 #ifdef LDEBUG 357 n->nDBTest = n aDBTest;323 //ntInitChar(c,TRUE,r); 324 n->cfDelete = ntDelete; 325 n->nNormalize = ntNormalize; 326 n->cfInit = ntInit; 327 n->nPar = ntPar; 328 n->nParDeg = ntParDeg; 329 n->n_Int = ntInt; 330 n->nAdd = ntAdd; 331 n->nSub = ntSub; 332 n->nMult = ntMult; 333 n->nDiv = ntDiv; 334 n->nExactDiv = ntDiv; 335 n->nIntDiv = ntIntDiv; 336 n->nNeg = ntNeg; 337 n->nInvers = ntInvers; 338 n->nCopy = ntCopy; 339 n->cfCopy = nt_Copy; 340 n->nGreater = ntGreater; 341 n->nEqual = ntEqual; 342 n->nIsZero = ntIsZero; 343 n->nIsOne = ntIsOne; 344 n->nIsMOne = ntIsMOne; 345 n->nGreaterZero = ntGreaterZero; 346 n->cfWrite = ntWrite; 347 n->nRead = ntRead; 348 n->nPower = ntPower; 349 n->nGcd = ntGcd; 350 n->nLcm = ntLcm; 351 n->cfSetMap = ntSetMap; 352 n->nName = ntName; 353 n->nSize = ntSize; 354 n->cfGetDenom = napGetDenom; 355 n->cfGetNumerator = napGetNumerator; 356 #ifdef LDEBUG 357 n->nDBTest = ntDBTest; 358 358 #endif 359 359 } -
kernel/polys1.cc
ra33266 r661c214 20 20 #include <kernel/intvec.h> 21 21 #include <kernel/longalg.h> 22 #include <kernel/longtrans.h> 22 23 #include <kernel/ring.h> 23 24 #include <kernel/ideals.h> … … 1237 1238 { 1238 1239 qq=pOne(); 1239 aq=na PermNumber(pGetCoeff(p),par_perm,OldPar, oldRing);1240 aq=napPermNumber(pGetCoeff(p),par_perm,OldPar, oldRing); 1240 1241 if ((currRing->minpoly!=NULL) 1241 1242 && ((rField_is_Zp_a()) || (rField_is_Q_a()))) -
kernel/ring.cc
ra33266 r661c214 18 18 #include <kernel/febase.h> 19 19 #include <kernel/intvec.h> 20 #include <kernel/long alg.h>20 #include <kernel/longtrans.h> 21 21 #include <kernel/ffields.h> 22 22 #include <kernel/ideals.h>
Note: See TracChangeset
for help on using the changeset viewer.