Changeset 9ccaaf in git
- Timestamp:
- Jan 23, 2017, 6:11:28 PM (7 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 061eacd047c9477bf1592c43bca9e3c4772a682c
- Parents:
- 6664a6665d5668b38e850926f691ded30e00daa9
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
Tst/Short/absfact.res.gz.uu
r6664a66 r9ccaaf 1 1 begin 640 absfact.res.gz 2 M'XL(" 'QD15@``V%B<V9A8W0N<F5S`.V<WV_;.!+'W_-7$,4"*UE20@Y_21O83 M#WN'6RQPN(>F;X>FD%-[:UPN*6+U(O6OOZ%EDW1$67;6[<-676PB4R0M <;[S4 MX9`:Y >;=WW__%R&$S<@_?_^5O*G6U>7]:O[F^N)F>P9F!`L_K!Y6511?7YC?2 M'XL("(\NAE@``V%B<V9A8W0N<F5S`.V<WV_;.!+'W_-7$,4"*UE20@Y_21O8 3 M#WN'6RQPN(>F;X>FD%-[:UPN*6+U(O6OOZ%EDW1$67;6[<-676PB4R0M:;[S 4 MX9`:YN;=WW__%R&$S<@_?_^5O*G6U>7]:O[F^N)F>P9F!`L_K!Y6511?7YC? 5 5 M9#8CY7R]+.^JRX?%\^6Z*BM;G\^(/1:7;:^[ROL]2Z^FNB1/JX<_R%LR)1&- 6 6 M4Q+5:8._[C^[^GI&UI\>GZHIH:XPGY'/C_<-^6P:9GI2WP))"$SJ2;,Y4I,: … … 11 11 MVW_K166N/KJ)KSL7?'U!K*T8G?EU;3$+F(?!+-#7O]G[7[!#\@$/INP*&`/9 12 12 M?H;WTRA#,Y4)*^))G3!N+)88PY9)(>*V%G\_E7@R*N-)TY:(]U.TX06VWW3, 13 M4I;R5%Q@3?=%6-U]"?9W"YF:E!EJP?8:86$B8]NG:8*_VS[!WA2W `T#>NEL514 M K6C>[6OFU[_]1E`W`=G@F1]-.=(-W#LW<"HD'#TL'&O-K$X:9\.L-,IQPH@`15 M K<SXIM!H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!7:=TB98BO(]/N!##8J2FUU"*.Y<F=4+*$)+#H7;%<`*_\\";=>^ 54 MTJ_;U:^.F-Z2J*]R;'O<;05:8J5&(,RS!B81RVKP'FW?UJ`!<'<JC^0NBL`J 55 M&-"3EFW-PF4CLLW0>ZS<N@,_4&_WT%MW*3`2ZZPF!QH"$]!3P'0VDSN6`$66 56 1>"!E\?5/%_\'F0DI=?Y,```` 57 57 ` 58 58 end -
libpolys/polys/ext_fields/transext.cc
r6664a66 r9ccaaf 68 68 #define NUMIS1(f) (p_IsOne(NUM(f), cf->extRing)) 69 69 70 #define COM(f) f->complexity70 #define COM(f) (f)->complexity 71 71 72 72 73 73 #ifdef LDEBUG 74 BOOLEAN ntDBTest(number a, const char *f, const int l, const coeffs r);74 static BOOLEAN ntDBTest(number a, const char *f, const int l, const coeffs r); 75 75 #endif 76 76 … … 91 91 92 92 /// forward declarations 93 BOOLEAN ntGreaterZero(number a, const coeffs cf); 94 BOOLEAN ntGreater(number a, number b, const coeffs cf); 95 BOOLEAN ntEqual(number a, number b, const coeffs cf); 96 BOOLEAN ntIsOne(number a, const coeffs cf); 97 BOOLEAN ntIsMOne(number a, const coeffs cf); 98 BOOLEAN ntIsZero(number a, const coeffs cf); 99 number ntInit(long i, const coeffs cf); 100 long ntInt(number &a, const coeffs cf); 101 number ntNeg(number a, const coeffs cf); 102 number ntInvers(number a, const coeffs cf); 103 number ntAdd(number a, number b, const coeffs cf); 104 number ntSub(number a, number b, const coeffs cf); 105 number ntMult(number a, number b, const coeffs cf); 106 number ntDiv(number a, number b, const coeffs cf); 107 void ntPower(number a, int exp, number *b, const coeffs cf); 108 number ntCopy(number a, const coeffs cf); 109 void ntWriteLong(number a, const coeffs cf); 110 void ntWriteShort(number a, const coeffs cf); 111 number ntRePart(number a, const coeffs cf); 112 number ntImPart(number a, const coeffs cf); 113 number ntGetDenom(number &a, const coeffs cf); 114 number ntGetNumerator(number &a, const coeffs cf); 115 number ntGcd(number a, number b, const coeffs cf); 116 number ntNormalizeHelper(number a, number b, const coeffs cf); 117 int ntSize(number a, const coeffs cf); 118 void ntDelete(number * a, const coeffs cf); 119 void ntCoeffWrite(const coeffs cf, BOOLEAN details); 120 const char * ntRead(const char *s, number *a, const coeffs cf); 121 static BOOLEAN ntCoeffIsEqual(const coeffs cf, n_coeffType n, void * param); 122 123 void heuristicGcdCancellation(number a, const coeffs cf); 124 void definiteGcdCancellation(number a, const coeffs cf, 93 static void heuristicGcdCancellation(number a, const coeffs cf); 94 static void definiteGcdCancellation(number a, const coeffs cf, 125 95 BOOLEAN simpleTestsHaveAlreadyBeenPerformed); 126 void handleNestedFractionsOverQ(fraction f, const coeffs cf);127 96 128 97 /* test routine, usualy disabled * … … 170 139 171 140 #ifdef LDEBUG 172 BOOLEAN ntDBTest(number a, const char *f, const int l, const coeffs cf)141 static BOOLEAN ntDBTest(number a, const char *f, const int l, const coeffs cf) 173 142 { 174 143 assume(getCoeffType(cf) == n_transExt); … … 323 292 } 324 293 325 BOOLEAN ntIsZero(number a, const coeffs cf)294 static BOOLEAN ntIsZero(number a, const coeffs cf) 326 295 { 327 296 //check_N(a,cf); … … 330 299 } 331 300 332 void ntDelete(number * a, const coeffs cf)301 static void ntDelete(number * a, const coeffs cf) 333 302 { 334 303 //check_N(*a,cf); … … 343 312 } 344 313 345 BOOLEAN ntEqual(number a, number b, const coeffs cf)314 static BOOLEAN ntEqual(number a, number b, const coeffs cf) 346 315 { 347 316 //check_N(a,cf); … … 389 358 } 390 359 391 number ntCopy(number a, const coeffs cf)360 static number ntCopy(number a, const coeffs cf) 392 361 { 393 362 //check_N(a,cf); … … 404 373 ntTest((number)result); 405 374 return (number)result; 406 }407 408 /// TODO: normalization of a!?409 number ntGetNumerator(number &a, const coeffs cf)410 {411 //check_N(a,cf);412 ntTest(a);413 if (IS0(a)) return NULL;414 415 definiteGcdCancellation(a, cf, FALSE);416 417 fraction f = (fraction)a;418 fraction result = (fraction)omAlloc0Bin(fractionObjectBin);419 420 const BOOLEAN denis1= DENIS1 (f);421 422 if (getCoeffType (ntCoeffs) == n_Q && !denis1)423 handleNestedFractionsOverQ (f, cf);424 425 if (getCoeffType (ntCoeffs) == n_Q && denis1)426 {427 assume( DEN (f) == NULL );428 429 number g;430 // TODO/NOTE: the following should not be necessary (due to431 // Hannes!) as NUM (f) should be over Z!!!432 CPolyCoeffsEnumerator itr(NUM(f));433 434 435 n_ClearDenominators(itr, g, ntCoeffs);436 437 if( !n_GreaterZero(g, ntCoeffs) )438 {439 NUM (f) = p_Neg(NUM (f), ntRing);440 g = n_InpNeg(g, ntCoeffs);441 }442 443 // g should be a positive integer now!444 assume( n_GreaterZero(g, ntCoeffs) );445 446 if( !n_IsOne(g, ntCoeffs) )447 {448 DEN (f) = p_NSet(g, ntRing);449 COM (f) ++;450 assume( DEN (f) != NULL );451 }452 else453 n_Delete(&g, ntCoeffs);454 455 ntTest(a);456 }457 458 // Call ntNormalize instead of above?!?459 460 NUM (result) = p_Copy (NUM (f), ntRing); // ???461 //DEN (result) = NULL; // done by ..Alloc0..462 //COM (result) = 0; // done by ..Alloc0..463 464 ntTest((number)result);465 //check_N((number)result,cf);466 return (number)result;467 }468 469 /// TODO: normalization of a!?470 number ntGetDenom(number &a, const coeffs cf)471 {472 //check_N(a,cf);473 ntTest(a);474 475 fraction result = (fraction)omAlloc0Bin(fractionObjectBin);476 //DEN (result)= NULL; // done by ..Alloc0..477 //COM (result)= 0; // done by ..Alloc0..478 479 if (IS0(a))480 {481 NUM (result) = p_One(ntRing);482 return (number)result;483 }484 485 definiteGcdCancellation(a, cf, FALSE);486 487 fraction f = (fraction)a;488 489 assume( !IS0(f) );490 491 const BOOLEAN denis1 = DENIS1 (f);492 493 if( denis1 && (getCoeffType (ntCoeffs) != n_Q) ) // */1 or 0494 {495 NUM (result)= p_One(ntRing);496 ntTest((number)result);497 return (number)result;498 }499 500 if (!denis1) // */* / Q501 {502 assume( DEN (f) != NULL );503 504 if (getCoeffType (ntCoeffs) == n_Q)505 handleNestedFractionsOverQ (f, cf);506 507 ntTest(a);508 509 if( DEN (f) != NULL ) // is it ?? // 1 now???510 {511 assume( !p_IsOne(DEN (f), ntRing) );512 513 NUM (result) = p_Copy (DEN (f), ntRing);514 ntTest((number)result);515 return (number)result;516 }517 // NUM (result) = p_One(ntRing); // NOTE: just in order to be sure...518 }519 520 // */1 / Q521 assume( getCoeffType (ntCoeffs) == n_Q );522 assume( DEN (f) == NULL );523 524 number g;525 // poly num= p_Copy (NUM (f), ntRing); // ???526 527 528 // TODO/NOTE: the following should not be necessary (due to529 // Hannes!) as NUM (f) should be over Z!!!530 CPolyCoeffsEnumerator itr(NUM(f));531 532 n_ClearDenominators(itr, g, ntCoeffs); // may return -1 :(((533 534 if( !n_GreaterZero(g, ntCoeffs) )535 {536 // NUM (f) = p_Neg(NUM (f), ntRing); // Ugly :(((537 // g = n_InpNeg(g, ntCoeffs);538 NUM (f) = p_Neg(NUM (f), ntRing); // Ugly :(((539 g = n_InpNeg(g, ntCoeffs);540 }541 542 // g should be a positive integer now!543 assume( n_GreaterZero(g, ntCoeffs) );544 545 if( !n_IsOne(g, ntCoeffs) )546 {547 assume( n_GreaterZero(g, ntCoeffs) );548 assume( !n_IsOne(g, ntCoeffs) );549 550 DEN (f) = p_NSet(g, ntRing); // update COM(f)???551 assume( DEN (f) != NULL );552 COM (f) ++;553 554 NUM (result)= p_Copy (DEN (f), ntRing);555 }556 else557 { // common denom == 1?558 NUM (result)= p_NSet(g, ntRing); // p_Copy (DEN (f), ntRing);559 // n_Delete(&g, ntCoeffs);560 }561 562 // if (!p_IsConstant (num, ntRing) && pNext(num) != NULL)563 // else564 // g= p_GetAllDenom (num, ntRing);565 // result= (fraction) ntSetMap (ntCoeffs, cf) (g, ntCoeffs, cf);566 567 ntTest((number)result);568 //check_N((number)result,cf);569 return (number)result;570 }571 572 BOOLEAN ntIsOne(number a, const coeffs cf)573 {574 //check_N(a,cf);575 ntTest(a); // !!!576 definiteGcdCancellation(a, cf, FALSE);577 fraction f = (fraction)a;578 return (f!=NULL) && DENIS1(f) && NUMIS1(f);579 }580 581 BOOLEAN ntIsMOne(number a, const coeffs cf)582 {583 //check_N(a,cf);584 ntTest(a);585 definiteGcdCancellation(a, cf, FALSE);586 fraction f = (fraction)a;587 if ((f==NULL) || (!DENIS1(f))) return FALSE;588 poly g = NUM(f);589 if (!p_IsConstant(g, ntRing)) return FALSE;590 return n_IsMOne(p_GetCoeff(g, ntRing), ntCoeffs);591 }592 593 /// this is in-place, modifies a594 number ntNeg(number a, const coeffs cf)595 {596 //check_N(a,cf);597 ntTest(a);598 if (!IS0(a))599 {600 fraction f = (fraction)a;601 NUM(f) = p_Neg(NUM(f), ntRing);602 }603 ntTest(a);604 return a;605 }606 607 number ntImPart(number a, const coeffs cf)608 {609 ntTest(a);610 return NULL;611 }612 613 number ntInit(long i, const coeffs cf)614 {615 if (i != 0)616 {617 poly p=p_ISet(i, ntRing);618 if (p!=NULL)619 {620 fraction result = (fraction)omAlloc0Bin(fractionObjectBin);621 NUM(result) = p;622 //DEN(result) = NULL; // done by omAlloc0Bin623 //COM(result) = 0; // done by omAlloc0Bin624 ntTest((number)result);625 //check_N((number)result,cf);626 return (number)result;627 }628 }629 return NULL;630 }631 632 633 /// takes over p!634 number ntInit(poly p, const coeffs cf)635 {636 if (p == NULL) return NULL;637 638 p_Test( p, ntRing);639 fraction f = (fraction)omAlloc0Bin(fractionObjectBin);640 641 if (nCoeff_is_Q(ntCoeffs))642 {643 number g;644 // the following is necessary because645 // NUM (f) should be over Z,646 // while p may be over Q647 CPolyCoeffsEnumerator itr(p);648 649 n_ClearDenominators(itr, g, ntCoeffs);650 651 if( !n_GreaterZero(g, ntCoeffs) )652 {653 p = p_Neg(p, ntRing);654 g = n_InpNeg(g, ntCoeffs);655 }656 657 // g should be a positive integer now!658 assume( n_GreaterZero(g, ntCoeffs) );659 660 if( !n_IsOne(g, ntCoeffs) )661 {662 DEN (f) = p_NSet(g, ntRing);663 p_Normalize(DEN(f), ntRing);664 assume( DEN (f) != NULL );665 }666 else667 {668 //DEN(f) = NULL; // done by omAlloc0669 n_Delete(&g, ntCoeffs);670 }671 }672 673 p_Normalize(p, ntRing);674 NUM(f) = p;675 //COM(f) = 0; // done by omAlloc0676 677 //check_N((number)f,cf);678 ntTest((number)f);679 return (number)f;680 }681 682 long ntInt(number &a, const coeffs cf)683 {684 //check_N(a,cf);685 ntTest(a);686 if (IS0(a)) return 0;687 definiteGcdCancellation(a, cf, FALSE);688 fraction f = (fraction)a;689 if (!DENIS1(f)) return 0;690 691 const poly aAsPoly = NUM(f);692 693 if(aAsPoly == NULL)694 return 0;695 696 if (!p_IsConstant(aAsPoly, ntRing))697 return 0;698 699 assume( aAsPoly != NULL );700 701 return n_Int(p_GetCoeff(aAsPoly, ntRing), ntCoeffs);702 }703 704 /* This method will only consider the numerators of a and b, without705 cancelling gcd's before.706 Moreover it may return TRUE only if one or both numerators707 are zero or if their degrees are equal. Then TRUE is returned iff708 coeff(numerator(a)) > coeff(numerator(b));709 In all other cases, FALSE will be returned. */710 BOOLEAN ntGreater(number a, number b, const coeffs cf)711 {712 //check_N(a,cf);713 //check_N(b,cf);714 ntTest(a);715 ntTest(b);716 number aNumCoeff = NULL; int aNumDeg = 0;717 number aDenCoeff = NULL; int aDenDeg = 0;718 number bNumCoeff = NULL; int bNumDeg = 0;719 number bDenCoeff = NULL; int bDenDeg = 0;720 if (!IS0(a))721 {722 fraction fa = (fraction)a;723 aNumDeg = p_Totaldegree(NUM(fa), ntRing);724 aNumCoeff = p_GetCoeff(NUM(fa), ntRing);725 if (DEN(fa)!=NULL)726 {727 aDenDeg = p_Totaldegree(DEN(fa), ntRing);728 aDenCoeff=p_GetCoeff(DEN(fa),ntRing);729 }730 }731 else return !(ntGreaterZero (b,cf));732 if (!IS0(b))733 {734 fraction fb = (fraction)b;735 bNumDeg = p_Totaldegree(NUM(fb), ntRing);736 bNumCoeff = p_GetCoeff(NUM(fb), ntRing);737 if (DEN(fb)!=NULL)738 {739 bDenDeg = p_Totaldegree(DEN(fb), ntRing);740 bDenCoeff=p_GetCoeff(DEN(fb),ntRing);741 }742 }743 else return ntGreaterZero(a,cf);744 if (aNumDeg-aDenDeg > bNumDeg-bDenDeg) return TRUE;745 if (aNumDeg-aDenDeg < bNumDeg-bDenDeg) return FALSE;746 number aa;747 number bb;748 if (bDenCoeff==NULL) aa=n_Copy(aNumCoeff,ntCoeffs);749 else aa=n_Mult(aNumCoeff,bDenCoeff,ntCoeffs);750 if (aDenCoeff==NULL) bb=n_Copy(bNumCoeff,ntCoeffs);751 else bb=n_Mult(bNumCoeff,aDenCoeff,ntCoeffs);752 BOOLEAN rr= n_Greater(aa, bb, ntCoeffs);753 n_Delete(&aa,ntCoeffs);754 n_Delete(&bb,ntCoeffs);755 return rr;756 }757 758 /* this method will only consider the numerator of a, without cancelling759 the gcd before;760 returns TRUE iff the leading coefficient of the numerator of a is > 0761 or the leading term of the numerator of a is not a762 constant */763 BOOLEAN ntGreaterZero(number a, const coeffs cf)764 {765 //check_N(a,cf);766 ntTest(a);767 if (IS0(a)) return FALSE;768 fraction f = (fraction)a;769 poly g = NUM(f);770 return (!p_LmIsConstant(g,ntRing)|| n_GreaterZero(pGetCoeff(g), ntCoeffs));771 }772 773 void ntCoeffWrite(const coeffs cf, BOOLEAN details)774 {775 assume( cf != NULL );776 777 const ring A = cf->extRing;778 779 assume( A != NULL );780 assume( A->cf != NULL );781 782 n_CoeffWrite(A->cf, details);783 784 // rWrite(A);785 786 const int P = rVar(A);787 assume( P > 0 );788 789 PrintS("(");790 791 for (int nop=0; nop < P; nop ++)792 {793 Print("%s", rRingVar(nop, A));794 if (nop!=P-1) PrintS(", ");795 }796 797 PrintS(")");798 799 assume( A->qideal == NULL );800 801 /*802 PrintS("// Coefficients live in the rational function field\n");803 Print("// K(");804 for (int i = 0; i < rVar(ntRing); i++)805 {806 if (i > 0) PrintS(" ");807 Print("%s", rRingVar(i, ntRing));808 }809 PrintS(") with\n");810 PrintS("// K: "); n_CoeffWrite(cf->extRing->cf);811 */812 }813 814 number ntDiff(number a, number d, const coeffs cf)815 {816 //check_N(a,cf);817 //check_N(d,cf);818 ntTest(a);819 ntTest(d);820 821 if (IS0(d))822 {823 WerrorS("ringvar expected");824 return NULL;825 }826 fraction t = (fraction) d;827 if (!DENIS1(t))828 {829 WerrorS("expected differentiation by a variable");830 return NULL;831 }832 int k=p_Var(NUM(t),ntRing);833 if (k==0)834 {835 WerrorS("expected differentiation by a variable");836 return NULL;837 }838 839 if (IS0(a)) return ntCopy(a, cf);840 841 fraction fa = (fraction)a;842 fraction result = (fraction)omAlloc0Bin(fractionObjectBin);843 if (DENIS1(fa))844 {845 NUM(result) = p_Diff(NUM(fa),k,ntRing);846 //DEN(result) = NULL; // done by ..Alloc0..847 if (NUM(result)==NULL)848 {849 omFreeBin((ADDRESS)result, fractionObjectBin);850 return(NULL);851 }852 COM(result) = COM(fa);853 //check_N((number)result,cf);854 ntTest((number)result);855 return (number)result;856 }857 858 poly fg = p_Mult_q(p_Copy(DEN(fa),ntRing),p_Diff(NUM(fa),k,ntRing),ntRing);859 poly gf = p_Mult_q(p_Copy(NUM(fa),ntRing),p_Diff(DEN(fa),k,ntRing),ntRing);860 NUM(result) = p_Sub(fg,gf,ntRing);861 if (NUM(result)==NULL) return(NULL);862 DEN(result) = pp_Mult_qq(DEN(fa), DEN(fa), ntRing);863 COM(result) = COM(fa) + COM(fa) + DIFF_COMPLEXITY;864 heuristicGcdCancellation((number)result, cf);865 866 //check_N((number)result,cf);867 ntTest((number)result);868 return (number)result;869 }870 871 872 number ntAdd(number a, number b, const coeffs cf)873 {874 //check_N(a,cf);875 //check_N(b,cf);876 ntTest(a);877 ntTest(b);878 if (IS0(a)) return ntCopy(b, cf);879 if (IS0(b)) return ntCopy(a, cf);880 881 fraction fa = (fraction)a;882 fraction fb = (fraction)b;883 884 poly g = p_Copy(NUM(fa), ntRing);885 if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing);886 poly h = p_Copy(NUM(fb), ntRing);887 if (!DENIS1(fa)) h = p_Mult_q(h, p_Copy(DEN(fa), ntRing), ntRing);888 g = p_Add_q(g, h, ntRing);889 890 if (g == NULL) return NULL;891 892 poly f;893 if (DENIS1(fa) && DENIS1(fb)) f = NULL;894 else if (!DENIS1(fa) && DENIS1(fb)) f = p_Copy(DEN(fa), ntRing);895 else if (DENIS1(fa) && !DENIS1(fb)) f = p_Copy(DEN(fb), ntRing);896 else /* both denom's are != 1 */ f = p_Mult_q(p_Copy(DEN(fa), ntRing),897 p_Copy(DEN(fb), ntRing),898 ntRing);899 900 fraction result = (fraction)omAllocBin(fractionObjectBin);901 NUM(result) = g;902 DEN(result) = f;903 COM(result) = COM(fa) + COM(fb) + ADD_COMPLEXITY;904 heuristicGcdCancellation((number)result, cf);905 906 // ntTest((number)result);907 908 //check_N((number)result,cf);909 ntTest((number)result);910 return (number)result;911 }912 913 number ntSub(number a, number b, const coeffs cf)914 {915 //check_N(a,cf);916 //check_N(b,cf);917 ntTest(a);918 ntTest(b);919 if (IS0(a)) return ntNeg(ntCopy(b, cf), cf);920 if (IS0(b)) return ntCopy(a, cf);921 922 fraction fa = (fraction)a;923 fraction fb = (fraction)b;924 925 poly g = p_Copy(NUM(fa), ntRing);926 if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing);927 poly h = p_Copy(NUM(fb), ntRing);928 if (!DENIS1(fa)) h = p_Mult_q(h, p_Copy(DEN(fa), ntRing), ntRing);929 g = p_Add_q(g, p_Neg(h, ntRing), ntRing);930 931 if (g == NULL) return NULL;932 933 poly f;934 if (DENIS1(fa) && DENIS1(fb)) f = NULL;935 else if (!DENIS1(fa) && DENIS1(fb)) f = p_Copy(DEN(fa), ntRing);936 else if (DENIS1(fa) && !DENIS1(fb)) f = p_Copy(DEN(fb), ntRing);937 else /* both den's are != 1 */ f = p_Mult_q(p_Copy(DEN(fa), ntRing),938 p_Copy(DEN(fb), ntRing),939 ntRing);940 941 fraction result = (fraction)omAllocBin(fractionObjectBin);942 NUM(result) = g;943 DEN(result) = f;944 COM(result) = COM(fa) + COM(fb) + ADD_COMPLEXITY;945 heuristicGcdCancellation((number)result, cf);946 // ntTest((number)result);947 //check_N((number)result,cf);948 ntTest((number)result);949 return (number)result;950 }951 952 number ntMult(number a, number b, const coeffs cf)953 {954 //check_N(a,cf);955 //check_N(b,cf);956 ntTest(a); // !!!?957 ntTest(b); // !!!?958 959 if (IS0(a) || IS0(b)) return NULL;960 961 fraction fa = (fraction)a;962 fraction fb = (fraction)b;963 964 const poly g = pp_Mult_qq(NUM(fa), NUM(fb), ntRing);965 966 if (g == NULL) return NULL; // may happen due to zero divisors???967 968 fraction result = (fraction)omAllocBin(fractionObjectBin);969 970 NUM(result) = g;971 972 const poly da = DEN(fa);973 const poly db = DEN(fb);974 975 976 //check_N((number)result,cf);977 if (db == NULL)978 {979 // b = ? // NULL980 981 if(da == NULL)982 { // both fa && fb are ?? // NULL!983 assume (da == NULL && db == NULL);984 DEN(result) = NULL;985 COM(result) = 0;986 }987 else988 {989 assume (da != NULL && db == NULL);990 DEN(result) = p_Copy(da, ntRing);991 COM(result) = COM(fa) + MULT_COMPLEXITY;992 heuristicGcdCancellation((number)result, cf);993 //check_N((number)result,cf);994 }995 }996 else997 { // b = ?? / ??998 if (da == NULL)999 { // a == ? // NULL1000 assume( db != NULL && da == NULL);1001 DEN(result) = p_Copy(db, ntRing);1002 COM(result) = COM(fb) + MULT_COMPLEXITY;1003 heuristicGcdCancellation((number)result, cf);1004 //check_N((number)result,cf);1005 }1006 else /* both den's are != 1 */1007 {1008 assume (da != NULL && db != NULL);1009 DEN(result) = pp_Mult_qq(da, db, ntRing);1010 COM(result) = COM(fa) + COM(fb) + MULT_COMPLEXITY;1011 heuristicGcdCancellation((number)result, cf);1012 //check_N((number)result,cf);1013 }1014 }1015 1016 // ntTest((number)result);1017 1018 //check_N((number)result,cf);1019 ntTest((number)result);1020 return (number)result;1021 }1022 1023 static void ntNormalizeDen(fraction result, const ring R)1024 {1025 if ((nCoeff_has_simple_inverse(R->cf))1026 && (result!=NULL)1027 && (DEN(result)!=NULL))1028 {1029 poly n=DEN(result);1030 if (!n_IsOne(pGetCoeff(n),R->cf))1031 {1032 number inv=n_Invers(pGetCoeff(n),R->cf);1033 DEN(result)=p_Mult_nn(n,inv,R);1034 NUM(result)=p_Mult_nn(NUM(result),inv,R);1035 n_Delete(&inv,R->cf);1036 if (p_IsOne(DEN(result), R))1037 {1038 n=DEN(result);1039 DEN(result)=NULL;1040 COM(result) = 0;1041 p_Delete(&n,R);1042 }1043 }1044 }1045 }1046 1047 number ntDiv(number a, number b, const coeffs cf)1048 {1049 //check_N(a,cf);1050 //check_N(b,cf);1051 ntTest(a);1052 ntTest(b);1053 if (IS0(a)) return NULL;1054 if (IS0(b)) WerrorS(nDivBy0);1055 1056 fraction fa = (fraction)a;1057 fraction fb = (fraction)b;1058 1059 poly g = p_Copy(NUM(fa), ntRing);1060 if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing);1061 1062 if (g == NULL) return NULL; /* may happen due to zero divisors */1063 1064 poly f = p_Copy(NUM(fb), ntRing);1065 if (!DENIS1(fa)) f = p_Mult_q(f, p_Copy(DEN(fa), ntRing), ntRing);1066 1067 fraction result = (fraction)omAlloc0Bin(fractionObjectBin);1068 NUM(result) = g;1069 if (!n_GreaterZero(pGetCoeff(f),ntCoeffs))1070 {1071 g=p_Neg(g,ntRing);1072 f=p_Neg(f,ntRing);1073 NUM(result) = g;1074 }1075 if (!p_IsConstant(f,ntRing) || !n_IsOne(pGetCoeff(f),ntCoeffs))1076 {1077 DEN(result) = f;1078 }1079 COM(result) = COM(fa) + COM(fb) + MULT_COMPLEXITY;1080 // definiteGcdCancellation((number)result, cf,FALSE);1081 heuristicGcdCancellation((number)result, cf);1082 // ntTest((number)result);1083 //check_N((number)result,cf);1084 ntNormalizeDen(result,ntRing);1085 ntTest((number)result);1086 return (number)result;1087 }1088 1089 /* 0^0 = 0;1090 for |exp| <= 7 compute power by a simple multiplication loop;1091 for |exp| >= 8 compute power along binary presentation of |exp|, e.g.1092 p^13 = p^1 * p^4 * p^8, where we utilise that1093 p^(2^(k+1)) = p^(2^k) * p^(2^k);1094 intermediate cancellation is controlled by the in-place method1095 heuristicGcdCancellation; see there.1096 */1097 void ntPower(number a, int exp, number *b, const coeffs cf)1098 {1099 ntTest(a);1100 1101 /* special cases first */1102 if (IS0(a))1103 {1104 if (exp >= 0) *b = NULL;1105 else WerrorS(nDivBy0);1106 }1107 else if (exp == 0) { *b = ntInit(1, cf); return;}1108 else if (exp == 1) { *b = ntCopy(a, cf); return;}1109 else if (exp == -1) { *b = ntInvers(a, cf); return;}1110 1111 int expAbs = exp; if (expAbs < 0) expAbs = -expAbs;1112 1113 /* now compute a^expAbs */1114 number pow; number t;1115 if (expAbs <= 7)1116 {1117 pow = ntCopy(a, cf);1118 for (int i = 2; i <= expAbs; i++)1119 {1120 t = ntMult(pow, a, cf);1121 ntDelete(&pow, cf);1122 pow = t;1123 heuristicGcdCancellation(pow, cf);1124 }1125 }1126 else1127 {1128 pow = ntInit(1, cf);1129 number factor = ntCopy(a, cf);1130 while (expAbs != 0)1131 {1132 if (expAbs & 1)1133 {1134 t = ntMult(pow, factor, cf);1135 ntDelete(&pow, cf);1136 pow = t;1137 heuristicGcdCancellation(pow, cf);1138 }1139 expAbs = expAbs / 2;1140 if (expAbs != 0)1141 {1142 t = ntMult(factor, factor, cf);1143 ntDelete(&factor, cf);1144 factor = t;1145 heuristicGcdCancellation(factor, cf);1146 }1147 }1148 ntDelete(&factor, cf);1149 }1150 1151 /* invert if original exponent was negative */1152 if (exp < 0)1153 {1154 t = ntInvers(pow, cf);1155 ntDelete(&pow, cf);1156 pow = t;1157 }1158 *b = pow;1159 ntTest(*b);1160 //check_N(*b,cf);1161 375 } 1162 376 … … 1185 399 calling procedure); 1186 400 modifies f */ 1187 void handleNestedFractionsOverQ(fraction f, const coeffs cf)401 static void handleNestedFractionsOverQ(fraction f, const coeffs cf) 1188 402 { 1189 403 assume(nCoeff_is_Q(ntCoeffs)); … … 1273 487 DEN(f) = p_Neg(DEN(f), ntRing); 1274 488 } 1275 489 COM(f)=BOUND_COMPLEXITY+1; 1276 490 ntTest((number)f); // TODO! 491 } 492 493 /// TODO: normalization of a!? 494 static number ntGetNumerator(number &a, const coeffs cf) 495 { 496 //check_N(a,cf); 497 ntTest(a); 498 if (IS0(a)) return NULL; 499 500 definiteGcdCancellation(a, cf, FALSE); 501 502 fraction f = (fraction)a; 503 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 504 505 const BOOLEAN denis1= DENIS1 (f); 506 507 if (getCoeffType (ntCoeffs) == n_Q && !denis1) 508 handleNestedFractionsOverQ (f, cf); 509 510 if (getCoeffType (ntCoeffs) == n_Q && denis1) 511 { 512 assume( DEN (f) == NULL ); 513 514 number g; 515 // TODO/NOTE: the following should not be necessary (due to 516 // Hannes!) as NUM (f) should be over Z!!! 517 CPolyCoeffsEnumerator itr(NUM(f)); 518 519 520 n_ClearDenominators(itr, g, ntCoeffs); 521 522 if( !n_GreaterZero(g, ntCoeffs) ) 523 { 524 NUM (f) = p_Neg(NUM (f), ntRing); 525 g = n_InpNeg(g, ntCoeffs); 526 } 527 528 // g should be a positive integer now! 529 assume( n_GreaterZero(g, ntCoeffs) ); 530 531 if( !n_IsOne(g, ntCoeffs) ) 532 { 533 DEN (f) = p_NSet(g, ntRing); 534 COM (f) ++; 535 assume( DEN (f) != NULL ); 536 } 537 else 538 n_Delete(&g, ntCoeffs); 539 540 ntTest(a); 541 } 542 543 // Call ntNormalize instead of above?!? 544 545 NUM (result) = p_Copy (NUM (f), ntRing); // ??? 546 //DEN (result) = NULL; // done by ..Alloc0.. 547 //COM (result) = 0; // done by ..Alloc0.. 548 549 ntTest((number)result); 550 //check_N((number)result,cf); 551 return (number)result; 552 } 553 554 /// TODO: normalization of a!? 555 static number ntGetDenom(number &a, const coeffs cf) 556 { 557 //check_N(a,cf); 558 ntTest(a); 559 560 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 561 //DEN (result)= NULL; // done by ..Alloc0.. 562 //COM (result)= 0; // done by ..Alloc0.. 563 564 if (IS0(a)) 565 { 566 NUM (result) = p_One(ntRing); 567 return (number)result; 568 } 569 570 definiteGcdCancellation(a, cf, FALSE); 571 572 fraction f = (fraction)a; 573 574 assume( !IS0(f) ); 575 576 const BOOLEAN denis1 = DENIS1 (f); 577 578 if( denis1 && (getCoeffType (ntCoeffs) != n_Q) ) // */1 or 0 579 { 580 NUM (result)= p_One(ntRing); 581 ntTest((number)result); 582 return (number)result; 583 } 584 585 if (!denis1) // */* / Q 586 { 587 assume( DEN (f) != NULL ); 588 589 if (getCoeffType (ntCoeffs) == n_Q) 590 handleNestedFractionsOverQ (f, cf); 591 592 ntTest(a); 593 594 if( DEN (f) != NULL ) // is it ?? // 1 now??? 595 { 596 assume( !p_IsOne(DEN (f), ntRing) ); 597 598 NUM (result) = p_Copy (DEN (f), ntRing); 599 ntTest((number)result); 600 return (number)result; 601 } 602 // NUM (result) = p_One(ntRing); // NOTE: just in order to be sure... 603 } 604 605 // */1 / Q 606 assume( getCoeffType (ntCoeffs) == n_Q ); 607 assume( DEN (f) == NULL ); 608 609 number g; 610 // poly num= p_Copy (NUM (f), ntRing); // ??? 611 612 613 // TODO/NOTE: the following should not be necessary (due to 614 // Hannes!) as NUM (f) should be over Z!!! 615 CPolyCoeffsEnumerator itr(NUM(f)); 616 617 n_ClearDenominators(itr, g, ntCoeffs); // may return -1 :((( 618 619 if( !n_GreaterZero(g, ntCoeffs) ) 620 { 621 // NUM (f) = p_Neg(NUM (f), ntRing); // Ugly :((( 622 // g = n_InpNeg(g, ntCoeffs); 623 NUM (f) = p_Neg(NUM (f), ntRing); // Ugly :((( 624 g = n_InpNeg(g, ntCoeffs); 625 } 626 627 // g should be a positive integer now! 628 assume( n_GreaterZero(g, ntCoeffs) ); 629 630 if( !n_IsOne(g, ntCoeffs) ) 631 { 632 assume( n_GreaterZero(g, ntCoeffs) ); 633 assume( !n_IsOne(g, ntCoeffs) ); 634 635 DEN (f) = p_NSet(g, ntRing); // update COM(f)??? 636 assume( DEN (f) != NULL ); 637 COM (f) ++; 638 639 NUM (result)= p_Copy (DEN (f), ntRing); 640 } 641 else 642 { // common denom == 1? 643 NUM (result)= p_NSet(g, ntRing); // p_Copy (DEN (f), ntRing); 644 // n_Delete(&g, ntCoeffs); 645 } 646 647 // if (!p_IsConstant (num, ntRing) && pNext(num) != NULL) 648 // else 649 // g= p_GetAllDenom (num, ntRing); 650 // result= (fraction) ntSetMap (ntCoeffs, cf) (g, ntCoeffs, cf); 651 652 ntTest((number)result); 653 //check_N((number)result,cf); 654 return (number)result; 655 } 656 657 static BOOLEAN ntIsOne(number a, const coeffs cf) 658 { 659 //check_N(a,cf); 660 ntTest(a); // !!! 661 definiteGcdCancellation(a, cf, FALSE); 662 fraction f = (fraction)a; 663 return (f!=NULL) && DENIS1(f) && NUMIS1(f); 664 } 665 666 static BOOLEAN ntIsMOne(number a, const coeffs cf) 667 { 668 //check_N(a,cf); 669 ntTest(a); 670 definiteGcdCancellation(a, cf, FALSE); 671 fraction f = (fraction)a; 672 if ((f==NULL) || (!DENIS1(f))) return FALSE; 673 poly g = NUM(f); 674 if (!p_IsConstant(g, ntRing)) return FALSE; 675 return n_IsMOne(p_GetCoeff(g, ntRing), ntCoeffs); 676 } 677 678 /// this is in-place, modifies a 679 static number ntNeg(number a, const coeffs cf) 680 { 681 //check_N(a,cf); 682 ntTest(a); 683 if (!IS0(a)) 684 { 685 fraction f = (fraction)a; 686 NUM(f) = p_Neg(NUM(f), ntRing); 687 } 688 ntTest(a); 689 return a; 690 } 691 692 number ntInit(long i, const coeffs cf) 693 { 694 if (i != 0) 695 { 696 poly p=p_ISet(i, ntRing); 697 if (p!=NULL) 698 { 699 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 700 NUM(result) = p; 701 //DEN(result) = NULL; // done by omAlloc0Bin 702 //COM(result) = 0; // done by omAlloc0Bin 703 ntTest((number)result); 704 //check_N((number)result,cf); 705 return (number)result; 706 } 707 } 708 return NULL; 709 } 710 711 712 /// takes over p! 713 number ntInit(poly p, const coeffs cf) 714 { 715 if (p == NULL) return NULL; 716 717 p_Test( p, ntRing); 718 fraction f = (fraction)omAlloc0Bin(fractionObjectBin); 719 720 if (nCoeff_is_Q(ntCoeffs)) 721 { 722 number g; 723 // the following is necessary because 724 // NUM (f) should be over Z, 725 // while p may be over Q 726 CPolyCoeffsEnumerator itr(p); 727 728 n_ClearDenominators(itr, g, ntCoeffs); 729 730 if( !n_GreaterZero(g, ntCoeffs) ) 731 { 732 p = p_Neg(p, ntRing); 733 g = n_InpNeg(g, ntCoeffs); 734 } 735 736 // g should be a positive integer now! 737 assume( n_GreaterZero(g, ntCoeffs) ); 738 739 if( !n_IsOne(g, ntCoeffs) ) 740 { 741 DEN (f) = p_NSet(g, ntRing); 742 p_Normalize(DEN(f), ntRing); 743 assume( DEN (f) != NULL ); 744 } 745 else 746 { 747 //DEN(f) = NULL; // done by omAlloc0 748 n_Delete(&g, ntCoeffs); 749 } 750 } 751 752 p_Normalize(p, ntRing); 753 NUM(f) = p; 754 //COM(f) = 0; // done by omAlloc0 755 756 //check_N((number)f,cf); 757 ntTest((number)f); 758 return (number)f; 759 } 760 761 static long ntInt(number &a, const coeffs cf) 762 { 763 //check_N(a,cf); 764 ntTest(a); 765 if (IS0(a)) return 0; 766 definiteGcdCancellation(a, cf, FALSE); 767 fraction f = (fraction)a; 768 if (!DENIS1(f)) return 0; 769 770 const poly aAsPoly = NUM(f); 771 772 if(aAsPoly == NULL) 773 return 0; 774 775 if (!p_IsConstant(aAsPoly, ntRing)) 776 return 0; 777 778 assume( aAsPoly != NULL ); 779 780 return n_Int(p_GetCoeff(aAsPoly, ntRing), ntCoeffs); 781 } 782 783 /* this method will only consider the numerator of a, without cancelling 784 the gcd before; 785 returns TRUE iff the leading coefficient of the numerator of a is > 0 786 or the leading term of the numerator of a is not a 787 constant */ 788 static BOOLEAN ntGreaterZero(number a, const coeffs cf) 789 { 790 //check_N(a,cf); 791 ntTest(a); 792 if (IS0(a)) return FALSE; 793 fraction f = (fraction)a; 794 poly g = NUM(f); 795 return (!p_LmIsConstant(g,ntRing)|| n_GreaterZero(pGetCoeff(g), ntCoeffs)); 796 } 797 798 /* This method will only consider the numerators of a and b, without 799 cancelling gcd's before. 800 Moreover it may return TRUE only if one or both numerators 801 are zero or if their degrees are equal. Then TRUE is returned iff 802 coeff(numerator(a)) > coeff(numerator(b)); 803 In all other cases, FALSE will be returned. */ 804 static BOOLEAN ntGreater(number a, number b, const coeffs cf) 805 { 806 //check_N(a,cf); 807 //check_N(b,cf); 808 ntTest(a); 809 ntTest(b); 810 number aNumCoeff = NULL; int aNumDeg = 0; 811 number aDenCoeff = NULL; int aDenDeg = 0; 812 number bNumCoeff = NULL; int bNumDeg = 0; 813 number bDenCoeff = NULL; int bDenDeg = 0; 814 if (!IS0(a)) 815 { 816 fraction fa = (fraction)a; 817 aNumDeg = p_Totaldegree(NUM(fa), ntRing); 818 aNumCoeff = p_GetCoeff(NUM(fa), ntRing); 819 if (DEN(fa)!=NULL) 820 { 821 aDenDeg = p_Totaldegree(DEN(fa), ntRing); 822 aDenCoeff=p_GetCoeff(DEN(fa),ntRing); 823 } 824 } 825 else return !(ntGreaterZero (b,cf)); 826 if (!IS0(b)) 827 { 828 fraction fb = (fraction)b; 829 bNumDeg = p_Totaldegree(NUM(fb), ntRing); 830 bNumCoeff = p_GetCoeff(NUM(fb), ntRing); 831 if (DEN(fb)!=NULL) 832 { 833 bDenDeg = p_Totaldegree(DEN(fb), ntRing); 834 bDenCoeff=p_GetCoeff(DEN(fb),ntRing); 835 } 836 } 837 else return ntGreaterZero(a,cf); 838 if (aNumDeg-aDenDeg > bNumDeg-bDenDeg) return TRUE; 839 if (aNumDeg-aDenDeg < bNumDeg-bDenDeg) return FALSE; 840 number aa; 841 number bb; 842 if (bDenCoeff==NULL) aa=n_Copy(aNumCoeff,ntCoeffs); 843 else aa=n_Mult(aNumCoeff,bDenCoeff,ntCoeffs); 844 if (aDenCoeff==NULL) bb=n_Copy(bNumCoeff,ntCoeffs); 845 else bb=n_Mult(bNumCoeff,aDenCoeff,ntCoeffs); 846 BOOLEAN rr= n_Greater(aa, bb, ntCoeffs); 847 n_Delete(&aa,ntCoeffs); 848 n_Delete(&bb,ntCoeffs); 849 return rr; 850 } 851 852 static void ntCoeffWrite(const coeffs cf, BOOLEAN details) 853 { 854 assume( cf != NULL ); 855 856 const ring A = cf->extRing; 857 858 assume( A != NULL ); 859 assume( A->cf != NULL ); 860 861 n_CoeffWrite(A->cf, details); 862 863 // rWrite(A); 864 865 const int P = rVar(A); 866 assume( P > 0 ); 867 868 PrintS("("); 869 870 for (int nop=0; nop < P; nop ++) 871 { 872 Print("%s", rRingVar(nop, A)); 873 if (nop!=P-1) PrintS(", "); 874 } 875 876 PrintS(")"); 877 878 assume( A->qideal == NULL ); 879 880 /* 881 PrintS("// Coefficients live in the rational function field\n"); 882 Print("// K("); 883 for (int i = 0; i < rVar(ntRing); i++) 884 { 885 if (i > 0) PrintS(" "); 886 Print("%s", rRingVar(i, ntRing)); 887 } 888 PrintS(") with\n"); 889 PrintS("// K: "); n_CoeffWrite(cf->extRing->cf); 890 */ 891 } 892 893 number ntDiff(number a, number d, const coeffs cf) 894 { 895 //check_N(a,cf); 896 //check_N(d,cf); 897 ntTest(a); 898 ntTest(d); 899 900 if (IS0(d)) 901 { 902 WerrorS("ringvar expected"); 903 return NULL; 904 } 905 fraction t = (fraction) d; 906 if (!DENIS1(t)) 907 { 908 WerrorS("expected differentiation by a variable"); 909 return NULL; 910 } 911 int k=p_Var(NUM(t),ntRing); 912 if (k==0) 913 { 914 WerrorS("expected differentiation by a variable"); 915 return NULL; 916 } 917 918 if (IS0(a)) return ntCopy(a, cf); 919 920 fraction fa = (fraction)a; 921 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 922 if (DENIS1(fa)) 923 { 924 NUM(result) = p_Diff(NUM(fa),k,ntRing); 925 //DEN(result) = NULL; // done by ..Alloc0.. 926 if (NUM(result)==NULL) 927 { 928 omFreeBin((ADDRESS)result, fractionObjectBin); 929 return(NULL); 930 } 931 COM(result) = COM(fa)+DIFF_COMPLEXITY; 932 //check_N((number)result,cf); 933 ntTest((number)result); 934 return (number)result; 935 } 936 937 poly fg = p_Mult_q(p_Copy(DEN(fa),ntRing),p_Diff(NUM(fa),k,ntRing),ntRing); 938 poly gf = p_Mult_q(p_Copy(NUM(fa),ntRing),p_Diff(DEN(fa),k,ntRing),ntRing); 939 NUM(result) = p_Sub(fg,gf,ntRing); 940 if (NUM(result)==NULL) return(NULL); 941 DEN(result) = pp_Mult_qq(DEN(fa), DEN(fa), ntRing); 942 COM(result) = COM(fa) + COM(fa) + DIFF_COMPLEXITY; 943 heuristicGcdCancellation((number)result, cf); 944 945 //check_N((number)result,cf); 946 ntTest((number)result); 947 return (number)result; 948 } 949 950 static number ntAdd(number a, number b, const coeffs cf) 951 { 952 //check_N(a,cf); 953 //check_N(b,cf); 954 ntTest(a); 955 ntTest(b); 956 if (IS0(a)) return ntCopy(b, cf); 957 if (IS0(b)) return ntCopy(a, cf); 958 959 fraction fa = (fraction)a; 960 fraction fb = (fraction)b; 961 962 poly g = p_Copy(NUM(fa), ntRing); 963 if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing); 964 poly h = p_Copy(NUM(fb), ntRing); 965 if (!DENIS1(fa)) h = p_Mult_q(h, p_Copy(DEN(fa), ntRing), ntRing); 966 g = p_Add_q(g, h, ntRing); 967 968 if (g == NULL) return NULL; 969 970 poly f; 971 if (DENIS1(fa) && DENIS1(fb)) f = NULL; 972 else if (!DENIS1(fa) && DENIS1(fb)) f = p_Copy(DEN(fa), ntRing); 973 else if (DENIS1(fa) && !DENIS1(fb)) f = p_Copy(DEN(fb), ntRing); 974 else /* both denom's are != 1 */ f = p_Mult_q(p_Copy(DEN(fa), ntRing), 975 p_Copy(DEN(fb), ntRing), 976 ntRing); 977 978 fraction result = (fraction)omAllocBin(fractionObjectBin); 979 NUM(result) = g; 980 DEN(result) = f; 981 COM(result) = COM(fa) + COM(fb) + ADD_COMPLEXITY; 982 heuristicGcdCancellation((number)result, cf); 983 984 // ntTest((number)result); 985 986 //check_N((number)result,cf); 987 ntTest((number)result); 988 return (number)result; 989 } 990 991 static number ntSub(number a, number b, const coeffs cf) 992 { 993 //check_N(a,cf); 994 //check_N(b,cf); 995 ntTest(a); 996 ntTest(b); 997 if (IS0(a)) return ntNeg(ntCopy(b, cf), cf); 998 if (IS0(b)) return ntCopy(a, cf); 999 1000 fraction fa = (fraction)a; 1001 fraction fb = (fraction)b; 1002 1003 poly g = p_Copy(NUM(fa), ntRing); 1004 if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing); 1005 poly h = p_Copy(NUM(fb), ntRing); 1006 if (!DENIS1(fa)) h = p_Mult_q(h, p_Copy(DEN(fa), ntRing), ntRing); 1007 g = p_Add_q(g, p_Neg(h, ntRing), ntRing); 1008 1009 if (g == NULL) return NULL; 1010 1011 poly f; 1012 if (DENIS1(fa) && DENIS1(fb)) f = NULL; 1013 else if (!DENIS1(fa) && DENIS1(fb)) f = p_Copy(DEN(fa), ntRing); 1014 else if (DENIS1(fa) && !DENIS1(fb)) f = p_Copy(DEN(fb), ntRing); 1015 else /* both den's are != 1 */ f = p_Mult_q(p_Copy(DEN(fa), ntRing), 1016 p_Copy(DEN(fb), ntRing), 1017 ntRing); 1018 1019 fraction result = (fraction)omAllocBin(fractionObjectBin); 1020 NUM(result) = g; 1021 DEN(result) = f; 1022 COM(result) = COM(fa) + COM(fb) + ADD_COMPLEXITY; 1023 heuristicGcdCancellation((number)result, cf); 1024 // ntTest((number)result); 1025 //check_N((number)result,cf); 1026 ntTest((number)result); 1027 return (number)result; 1028 } 1029 1030 static number ntMult(number a, number b, const coeffs cf) 1031 { 1032 //check_N(a,cf); 1033 //check_N(b,cf); 1034 ntTest(a); // !!!? 1035 ntTest(b); // !!!? 1036 1037 if (IS0(a) || IS0(b)) return NULL; 1038 1039 fraction fa = (fraction)a; 1040 fraction fb = (fraction)b; 1041 1042 const poly g = pp_Mult_qq(NUM(fa), NUM(fb), ntRing); 1043 1044 if (g == NULL) return NULL; // may happen due to zero divisors??? 1045 1046 fraction result = (fraction)omAllocBin(fractionObjectBin); 1047 1048 NUM(result) = g; 1049 1050 const poly da = DEN(fa); 1051 const poly db = DEN(fb); 1052 1053 1054 //check_N((number)result,cf); 1055 if (db == NULL) 1056 { 1057 // b = ? // NULL 1058 1059 if(da == NULL) 1060 { // both fa && fb are ?? // NULL! 1061 assume (da == NULL && db == NULL); 1062 DEN(result) = NULL; 1063 COM(result) = 0; 1064 } 1065 else 1066 { 1067 assume (da != NULL && db == NULL); 1068 DEN(result) = p_Copy(da, ntRing); 1069 COM(result) = COM(fa) + MULT_COMPLEXITY; 1070 heuristicGcdCancellation((number)result, cf); 1071 //check_N((number)result,cf); 1072 } 1073 } 1074 else 1075 { // b = ?? / ?? 1076 if (da == NULL) 1077 { // a == ? // NULL 1078 assume( db != NULL && da == NULL); 1079 DEN(result) = p_Copy(db, ntRing); 1080 COM(result) = COM(fb) + MULT_COMPLEXITY; 1081 heuristicGcdCancellation((number)result, cf); 1082 //check_N((number)result,cf); 1083 } 1084 else /* both den's are != 1 */ 1085 { 1086 assume (da != NULL && db != NULL); 1087 DEN(result) = pp_Mult_qq(da, db, ntRing); 1088 COM(result) = COM(fa) + COM(fb) + MULT_COMPLEXITY; 1089 heuristicGcdCancellation((number)result, cf); 1090 //check_N((number)result,cf); 1091 } 1092 } 1093 1094 // ntTest((number)result); 1095 1096 //check_N((number)result,cf); 1097 ntTest((number)result); 1098 return (number)result; 1099 } 1100 1101 static void ntNormalizeDen(fraction result, const ring R) 1102 { 1103 if ((nCoeff_has_simple_inverse(R->cf)) 1104 && (result!=NULL) 1105 && (DEN(result)!=NULL)) 1106 { 1107 poly n=DEN(result); 1108 if (!n_IsOne(pGetCoeff(n),R->cf)) 1109 { 1110 number inv=n_Invers(pGetCoeff(n),R->cf); 1111 DEN(result)=p_Mult_nn(n,inv,R); 1112 NUM(result)=p_Mult_nn(NUM(result),inv,R); 1113 n_Delete(&inv,R->cf); 1114 if (p_IsOne(DEN(result), R)) 1115 { 1116 n=DEN(result); 1117 DEN(result)=NULL; 1118 COM(result) = 0; 1119 p_Delete(&n,R); 1120 } 1121 } 1122 } 1123 } 1124 1125 static number ntDiv(number a, number b, const coeffs cf) 1126 { 1127 //check_N(a,cf); 1128 //check_N(b,cf); 1129 ntTest(a); 1130 ntTest(b); 1131 if (IS0(a)) return NULL; 1132 if (IS0(b)) WerrorS(nDivBy0); 1133 1134 fraction fa = (fraction)a; 1135 fraction fb = (fraction)b; 1136 1137 poly g = p_Copy(NUM(fa), ntRing); 1138 if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing); 1139 1140 if (g == NULL) return NULL; /* may happen due to zero divisors */ 1141 1142 poly f = p_Copy(NUM(fb), ntRing); 1143 if (!DENIS1(fa)) f = p_Mult_q(f, p_Copy(DEN(fa), ntRing), ntRing); 1144 1145 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 1146 NUM(result) = g; 1147 if (!n_GreaterZero(pGetCoeff(f),ntCoeffs)) 1148 { 1149 g=p_Neg(g,ntRing); 1150 f=p_Neg(f,ntRing); 1151 NUM(result) = g; 1152 } 1153 if (!p_IsConstant(f,ntRing) || !n_IsOne(pGetCoeff(f),ntCoeffs)) 1154 { 1155 DEN(result) = f; 1156 } 1157 COM(result) = COM(fa) + COM(fb) + MULT_COMPLEXITY; 1158 // definiteGcdCancellation((number)result, cf,FALSE); 1159 heuristicGcdCancellation((number)result, cf); 1160 // ntTest((number)result); 1161 //check_N((number)result,cf); 1162 ntNormalizeDen(result,ntRing); 1163 ntTest((number)result); 1164 return (number)result; 1165 } 1166 1167 static number ntInvers(number a, const coeffs cf) 1168 { 1169 //check_N(a,cf); 1170 ntTest(a); 1171 if (IS0(a)) 1172 { 1173 WerrorS(nDivBy0); 1174 return NULL; 1175 } 1176 fraction f = (fraction)a; 1177 assume( f != NULL ); 1178 1179 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); 1180 1181 assume( NUM(f) != NULL ); 1182 const poly den = DEN(f); 1183 1184 if (den == NULL) 1185 NUM(result) = p_One(ntRing); 1186 else 1187 NUM(result) = p_Copy(den, ntRing); 1188 1189 if( !NUMIS1(f) ) 1190 { 1191 poly num_f=NUM(f); 1192 BOOLEAN neg= !n_GreaterZero(pGetCoeff(num_f),ntCoeffs); 1193 if (neg) 1194 { 1195 num_f=p_Neg(p_Copy(num_f, ntRing), ntRing); 1196 NUM(result)=p_Neg(NUM(result), ntRing); 1197 } 1198 else 1199 { 1200 num_f=p_Copy(num_f, ntRing); 1201 } 1202 DEN(result) = num_f; 1203 COM(result) = COM(f); 1204 if (neg) 1205 { 1206 if (p_IsOne(num_f, ntRing)) 1207 { 1208 DEN(result)=NULL; 1209 //COM(result) = 0; 1210 p_Delete(&num_f,ntRing); 1211 } 1212 } 1213 } 1214 //else// Alloc0 1215 //{ 1216 // DEN(result) = NULL; 1217 // COM(result) = 0; 1218 //} 1219 ntNormalizeDen(result,ntRing); 1220 ntTest((number)result); // !!!! 1221 //check_N((number)result,cf); 1222 return (number)result; 1223 } 1224 1225 /* 0^0 = 0; 1226 for |exp| <= 7 compute power by a simple multiplication loop; 1227 for |exp| >= 8 compute power along binary presentation of |exp|, e.g. 1228 p^13 = p^1 * p^4 * p^8, where we utilise that 1229 p^(2^(k+1)) = p^(2^k) * p^(2^k); 1230 intermediate cancellation is controlled by the in-place method 1231 heuristicGcdCancellation; see there. 1232 */ 1233 static void ntPower(number a, int exp, number *b, const coeffs cf) 1234 { 1235 ntTest(a); 1236 1237 /* special cases first */ 1238 if (IS0(a)) 1239 { 1240 if (exp >= 0) *b = NULL; 1241 else WerrorS(nDivBy0); 1242 } 1243 else if (exp == 0) { *b = ntInit(1, cf); return;} 1244 else if (exp == 1) { *b = ntCopy(a, cf); return;} 1245 else if (exp == -1) { *b = ntInvers(a, cf); return;} 1246 1247 int expAbs = exp; if (expAbs < 0) expAbs = -expAbs; 1248 1249 /* now compute a^expAbs */ 1250 number pow; number t; 1251 if (expAbs <= 7) 1252 { 1253 pow = ntCopy(a, cf); 1254 for (int i = 2; i <= expAbs; i++) 1255 { 1256 t = ntMult(pow, a, cf); 1257 ntDelete(&pow, cf); 1258 pow = t; 1259 heuristicGcdCancellation(pow, cf); 1260 } 1261 } 1262 else 1263 { 1264 pow = ntInit(1, cf); 1265 number factor = ntCopy(a, cf); 1266 while (expAbs != 0) 1267 { 1268 if (expAbs & 1) 1269 { 1270 t = ntMult(pow, factor, cf); 1271 ntDelete(&pow, cf); 1272 pow = t; 1273 heuristicGcdCancellation(pow, cf); 1274 } 1275 expAbs = expAbs / 2; 1276 if (expAbs != 0) 1277 { 1278 t = ntMult(factor, factor, cf); 1279 ntDelete(&factor, cf); 1280 factor = t; 1281 heuristicGcdCancellation(factor, cf); 1282 } 1283 } 1284 ntDelete(&factor, cf); 1285 } 1286 1287 /* invert if original exponent was negative */ 1288 if (exp < 0) 1289 { 1290 t = ntInvers(pow, cf); 1291 ntDelete(&pow, cf); 1292 pow = t; 1293 } 1294 *b = pow; 1295 ntTest(*b); 1296 //check_N(*b,cf); 1277 1297 } 1278 1298 1279 1299 /* modifies a */ 1280 1300 /* this is an intermediate simplification routine - not a comple "normalize" */ 1281 void heuristicGcdCancellation(number a, const coeffs cf)1301 static void heuristicGcdCancellation(number a, const coeffs cf) 1282 1302 { 1283 1303 if (IS0(a)) return; … … 1364 1384 1365 1385 /// modifies a 1366 void definiteGcdCancellation(number a, const coeffs cf,1386 static void definiteGcdCancellation(number a, const coeffs cf, 1367 1387 BOOLEAN simpleTestsHaveAlreadyBeenPerformed) 1368 1388 { … … 1372 1392 1373 1393 if (IS0(a)) return; 1394 if (COM(f)==0) return; 1374 1395 if (DENIS1(f) || NUMIS1(f)) { COM(f) = 0; ntTest(a); return; } 1375 1396 if (!simpleTestsHaveAlreadyBeenPerformed) … … 1441 1462 1442 1463 /* here we assume: NUM(f), DEN(f) !=NULL, in Z_a reqp. Z/p_a */ 1464 //StringSetS("");ntWriteLong(a,cf); 1443 1465 poly pGcd = singclap_gcd_and_divide(NUM(f), DEN(f), ntRing); 1444 1466 //PrintS("gcd= ");p_wrp(pGcd,ntRing);PrintLn(); … … 1493 1515 } 1494 1516 p_Delete(&pGcd, ntRing); 1517 // StringAppendS(" -> ");ntWriteLong(a,cf);StringAppendS("\n");{ char* s = StringEndS(); Print("%s", s); omFree(s); } 1495 1518 COM(f) = 0; 1496 1519 … … 1513 1536 } 1514 1537 1515 void ntWriteLong(number a, const coeffs cf)1538 static void ntWriteLong(number a, const coeffs cf) 1516 1539 { 1517 1540 ntTest(a); … … 1538 1561 } 1539 1562 1540 void ntWriteShort(number a, const coeffs cf)1563 static void ntWriteShort(number a, const coeffs cf) 1541 1564 { 1542 1565 ntTest(a); … … 1563 1586 } 1564 1587 1565 const char * ntRead(const char *s, number *a, const coeffs cf)1588 static const char * ntRead(const char *s, number *a, const coeffs cf) 1566 1589 { 1567 1590 poly p; … … 1573 1596 } 1574 1597 1575 void ntNormalize (number &a, const coeffs cf)1598 static void ntNormalize (number &a, const coeffs cf) 1576 1599 { 1577 1600 if ( /*(*/ a!=NULL /*)*/ ) … … 1579 1602 //PrintS("num=");p_wrp(NUM(a),ntRing); 1580 1603 //PrintS(" den=");p_wrp(DEN(a),ntRing);PrintLn(); 1581 definiteGcdCancellation(a, cf, FALSE);1604 if (COM((fraction)a)>0) definiteGcdCancellation(a, cf, FALSE); 1582 1605 if ((DEN((fraction)a)!=NULL) 1583 1606 &&(!n_GreaterZero(pGetCoeff(DEN((fraction)a)),ntCoeffs))) … … 1614 1637 } 1615 1638 1616 number ntNormalizeHelper(number a, number b, const coeffs cf)1639 static number ntNormalizeHelper(number a, number b, const coeffs cf) 1617 1640 { 1618 1641 ntTest(a); … … 1702 1725 } 1703 1726 1704 number ntGcd(number a, number b, const coeffs cf)1727 static number ntGcd(number a, number b, const coeffs cf) 1705 1728 { 1706 1729 ntTest(a); … … 1778 1801 //} 1779 1802 1780 int ntSize(number a, const coeffs cf)1803 static int ntSize(number a, const coeffs cf) 1781 1804 { 1782 1805 ntTest(a); … … 1805 1828 } 1806 1829 1807 number ntInvers(number a, const coeffs cf)1808 {1809 //check_N(a,cf);1810 ntTest(a);1811 if (IS0(a))1812 {1813 WerrorS(nDivBy0);1814 return NULL;1815 }1816 fraction f = (fraction)a;1817 assume( f != NULL );1818 1819 fraction result = (fraction)omAlloc0Bin(fractionObjectBin);1820 1821 assume( NUM(f) != NULL );1822 const poly den = DEN(f);1823 1824 if (den == NULL)1825 NUM(result) = p_One(ntRing);1826 else1827 NUM(result) = p_Copy(den, ntRing);1828 1829 if( !NUMIS1(f) )1830 {1831 poly num_f=NUM(f);1832 BOOLEAN neg= !n_GreaterZero(pGetCoeff(num_f),ntCoeffs);1833 if (neg)1834 {1835 num_f=p_Neg(p_Copy(num_f, ntRing), ntRing);1836 NUM(result)=p_Neg(NUM(result), ntRing);1837 }1838 else1839 {1840 num_f=p_Copy(num_f, ntRing);1841 }1842 DEN(result) = num_f;1843 COM(result) = COM(f);1844 if (neg)1845 {1846 if (p_IsOne(num_f, ntRing))1847 {1848 DEN(result)=NULL;1849 //COM(result) = 0;1850 p_Delete(&num_f,ntRing);1851 }1852 }1853 }1854 //else// Alloc01855 //{1856 // DEN(result) = NULL;1857 // COM(result) = 0;1858 //}1859 ntNormalizeDen(result,ntRing);1860 ntTest((number)result); // !!!!1861 //check_N((number)result,cf);1862 return (number)result;1863 }1864 1865 1830 /* assumes that src = Q or Z, dst = Q(t_1, ..., t_s) */ 1866 number ntMap00(number a, const coeffs src, const coeffs dst)1831 static number ntMap00(number a, const coeffs src, const coeffs dst) 1867 1832 { 1868 1833 n_Test(a, src); … … 1888 1853 } 1889 1854 1890 number ntMapZ0(number a, const coeffs src, const coeffs dst)1855 static number ntMapZ0(number a, const coeffs src, const coeffs dst) 1891 1856 { 1892 1857 n_Test(a, src); … … 1902 1867 1903 1868 /* assumes that src = Z/p, dst = Q(t_1, ..., t_s) */ 1904 number ntMapP0(number a, const coeffs src, const coeffs dst)1869 static number ntMapP0(number a, const coeffs src, const coeffs dst) 1905 1870 { 1906 1871 n_Test(a, src); … … 1918 1883 1919 1884 /* assumes that either src = K(t_1, ..., t_s), dst = K(t_1, ..., t_s) */ 1920 number ntCopyMap(number a, const coeffs cf, const coeffs dst)1885 static number ntCopyMap(number a, const coeffs cf, const coeffs dst) 1921 1886 { 1922 1887 ntTest(a); … … 1947 1912 } 1948 1913 1949 number ntGenMap(number a, const coeffs cf, const coeffs dst)1914 static number ntGenMap(number a, const coeffs cf, const coeffs dst) 1950 1915 { 1951 1916 ntTest(a); … … 2026 1991 } 2027 1992 2028 number ntCopyAlg(number a, const coeffs cf, const coeffs dst)1993 static number ntCopyAlg(number a, const coeffs cf, const coeffs dst) 2029 1994 { 2030 1995 n_Test(a, cf) ; … … 2033 1998 } 2034 1999 2035 number ntGenAlg(number a, const coeffs cf, const coeffs dst)2000 static number ntGenAlg(number a, const coeffs cf, const coeffs dst) 2036 2001 { 2037 2002 n_Test(a, cf) ; … … 2043 2008 2044 2009 /* assumes that src = Q, dst = Z/p(t_1, ..., t_s) */ 2045 number ntMap0P(number a, const coeffs src, const coeffs dst)2010 static number ntMap0P(number a, const coeffs src, const coeffs dst) 2046 2011 { 2047 2012 n_Test(a, src) ; … … 2067 2032 2068 2033 /* assumes that src = Z/p, dst = Z/p(t_1, ..., t_s) */ 2069 number ntMapPP(number a, const coeffs src, const coeffs dst)2034 static number ntMapPP(number a, const coeffs src, const coeffs dst) 2070 2035 { 2071 2036 n_Test(a, src) ; … … 2082 2047 2083 2048 /* assumes that src = Z/u, dst = Z/p(t_1, ..., t_s), where u != p */ 2084 number ntMapUP(number a, const coeffs src, const coeffs dst)2049 static number ntMapUP(number a, const coeffs src, const coeffs dst) 2085 2050 { 2086 2051 n_Test(a, src) ; … … 2181 2146 #endif 2182 2147 2183 void ntKillChar(coeffs cf)2148 static void ntKillChar(coeffs cf) 2184 2149 { 2185 2150 if ((--cf->extRing->ref) == 0) 2186 2151 rDelete(cf->extRing); 2187 2152 } 2188 number ntConvFactoryNSingN( const CanonicalForm n, const coeffs cf)2153 static number ntConvFactoryNSingN( const CanonicalForm n, const coeffs cf) 2189 2154 { 2190 2155 if (n.isZero()) return NULL; … … 2198 2163 return (number)result; 2199 2164 } 2200 CanonicalForm ntConvSingNFactoryN( number n, BOOLEAN /*setChar*/, const coeffs cf )2165 static CanonicalForm ntConvSingNFactoryN( number n, BOOLEAN /*setChar*/, const coeffs cf ) 2201 2166 { 2202 2167 ntTest(n); … … 2497 2462 } 2498 2463 2499 numberntChineseRemainder(number *x, number *q,int rl, BOOLEAN /*sym*/,CFArray &inv_cache,const coeffs cf)2464 static number ntChineseRemainder(number *x, number *q,int rl, BOOLEAN /*sym*/,CFArray &inv_cache,const coeffs cf) 2500 2465 { 2501 2466 fraction result = (fraction)omAlloc0Bin(fractionObjectBin); … … 2527 2492 } 2528 2493 2529 numberntFarey(number p, number n, const coeffs cf)2494 static number ntFarey(number p, number n, const coeffs cf) 2530 2495 { 2531 2496 // n is really a bigint … … 2595 2560 cf->cfGetDenom = ntGetDenom; 2596 2561 cf->cfGetNumerator = ntGetNumerator; 2597 cf->cfRePart = ntCopy;2598 cf->cfImPart = ntImPart;2562 //cf->cfRePart = ntCopy; 2563 //cf->cfImPart = ntImPart; 2599 2564 cf->cfCoeffWrite = ntCoeffWrite; 2600 2565 #ifdef LDEBUG
Note: See TracChangeset
for help on using the changeset viewer.