Changeset 152d55 in git
- Timestamp:
- Mar 28, 2011, 5:58:06 PM (12 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- f3b4ae666e6d80d92f6a7b691937cf9d8d40b497
- Parents:
- 83f30732a27330c9f9218cccbd4faeb2571b7c5f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/longtrans.cc
r83f3073 r152d55 518 518 returns the minimum of the two exponents of the 519 519 first variable in la and lb; 520 assumes a != NULL, b != NULL; 520 521 keeps a and b */ 521 522 int napExp(napoly a, napoly b) 522 523 { 524 assume(a != NULL); 525 assume(b != NULL); 523 526 while (pNext(a) != NULL) pIter(a); 524 527 int m = p_GetExp(a, 1, nacRing); … … 561 564 562 565 /* divides out the content of the given napoly; 563 modifies the argument */ 566 assumes that ph != NULL; 567 modifies ph */ 564 568 void napContent(napoly ph) 565 569 { … … 567 571 napoly p; 568 572 569 assume(p != NULL);573 assume(ph != NULL); 570 574 p = ph; 571 575 if (nacIsOne(pGetCoeff(p))) return; 572 576 h = nacCopy(pGetCoeff(p)); 573 577 pIter(p); 574 do578 while (p != NULL) 575 579 { 576 580 d = nacGcd(pGetCoeff(p), h, nacRing); … … 585 589 pIter(p); 586 590 } 587 while (p != NULL);588 591 h = nacInvers(d); 589 592 n_Delete(&d, nacRing); … … 599 602 } 600 603 604 /* removes denominators of coefficients in ph 605 by multiplication with lcm of those; 606 if char != 0, then nothing is done; 607 modifies ph */ 601 608 void napCleardenom(napoly ph) 602 609 { … … 609 616 while (p!=NULL) 610 617 { 611 d = nacLcm(h, pGetCoeff(p), nacRing); 618 d = nacLcm(h, pGetCoeff(p), nacRing); // uses denominator of pGetCoeff(p) 612 619 n_Delete(&h,nacRing); 613 620 h = d; … … 625 632 pIter(p); 626 633 } 627 n_Delete(&h,nacRing);628 }634 } 635 n_Delete(&h,nacRing); 629 636 napContent(ph); 630 637 } 631 638 639 /* returns the gcd of all coefficients in a and b; 640 assumes a != NULL, b != NULL; 641 keeps a, keeps b */ 632 642 napoly napGcd0(napoly a, napoly b) 633 643 { 634 644 number x, y; 645 assume(a != NULL); 646 assume(b != NULL); 635 647 if (!ntIsChar0) return p_ISet(1, nacRing); 636 648 x = nacCopy(pGetCoeff(a)); 637 if (nacIsOne(x)) 638 return napInitz(x); 639 while (pNext(a)!=NULL) 640 { 641 pIter(a); 649 if (nacIsOne(x)) return napInitz(x); 650 pIter(a); 651 while (a!=NULL) 652 { 642 653 y = nacGcd(x, pGetCoeff(a), nacRing); 643 654 n_Delete(&x,nacRing); 644 655 x = y; 645 if (nacIsOne(x)) 646 return napInitz(x);656 if (nacIsOne(x)) return napInitz(x); 657 pIter(a); 647 658 } 648 659 do … … 651 662 n_Delete(&x,nacRing); 652 663 x = y; 653 if (nacIsOne(x)) 654 return napInitz(x); 664 if (nacIsOne(x)) return napInitz(x); 655 665 pIter(b); 656 666 } … … 659 669 } 660 670 661 /*3 662 * result =gcd(a,b) 663 */ 671 /* returns the gcd of a and b; 672 if char != 0, then the constant poly 1 is returned; 673 if a = b = 0, then the constant poly 1 is returned; 674 if a = 0 != b, then b is returned; 675 if a != 0 = b, then a is returned; 676 keeps a, keeps b */ 664 677 napoly napGcd(napoly a, napoly b) 665 678 { 666 679 int i; 667 680 napoly g, x, y, h; 668 if ((a==NULL) 669 || ((pNext(a)==NULL)&&(nacIsZero(pGetCoeff(a))))) 670 { 671 if ((b==NULL) 672 || ((pNext(b)==NULL)&&(nacIsZero(pGetCoeff(b))))) 673 { 674 return p_ISet(1,nacRing); 675 } 676 return napCopy(b); 677 } 678 else 679 if ((b==NULL) 680 || ((pNext(b)==NULL)&&(nacIsZero(pGetCoeff(b))))) 681 { 682 return napCopy(a); 683 } 681 if (a == NULL) 682 { 683 if (b == NULL) return p_ISet(1,nacRing); 684 else return napCopy(b); 685 } 686 else if (b == NULL) return napCopy(a); 687 684 688 if (naMinimalPoly != NULL) 685 { 689 { // we have an algebraic extension 686 690 if (p_GetExp(a,1,nacRing) >= p_GetExp(b,1,nacRing)) 687 691 { … … 726 730 return g; 727 731 } 728 // Hmm ... this is a memory leak 729 // x = (napoly)p_Init(nacRing); 730 g=a; 731 h=b; 732 if (!ntIsChar0) x = p_ISet(1,nacRing); 733 else x = napGcd0(g,h); 734 for (i=(ntNumbOfPar-1); i>=0; i--) 735 { 736 napSetExp(x,i+1, napExpi(i,a,b)); 737 p_Setm(x,nacRing); 738 } 739 return x; 740 } 741 742 732 else 733 { // we have ntNumbOfPar transcendental variables 734 if (!ntIsChar0) x = p_ISet(1,nacRing); 735 else x = napGcd0(a,b); 736 for (i=(ntNumbOfPar-1); i>=0; i--) 737 { 738 napSetExp(x,i+1, napExpi(i,a,b)); 739 p_Setm(x,nacRing); 740 } 741 return x; 742 } 743 } 744 745 /* returns the lcm of all denominators in the coefficients of a; 746 if char != 0, then the constant poly 1 is returned; 747 if a = 0, then the constant poly 1 is returned; 748 keeps a */ 743 749 number napLcm(napoly a) 744 750 { 745 751 number h = nacInit(1,nacRing); 746 747 752 if (ntIsChar0) 748 753 { 749 754 number d; 750 755 napoly b = a; 751 752 756 while (b!=NULL) 753 757 { 754 d = nacLcm(h, pGetCoeff(b), nacRing); 758 d = nacLcm(h, pGetCoeff(b), nacRing); // uses denominator of pGetCoeff(b) 755 759 n_Delete(&h,nacRing); 756 760 h = d; … … 760 764 return h; 761 765 } 762 763 766 764 767 /*2
Note: See TracChangeset
for help on using the changeset viewer.