Changeset 36ebfa in git for libpolys/coeffs/longrat.cc
- Timestamp:
- Sep 12, 2012, 1:14:59 PM (12 years ago)
- Branches:
- (u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
- Children:
- 2ed48b369bc0d2a3c22dd1fc1ff4b91704e73ec6d2f30f8ec6d1db506b36602c98b98bf5f86b1c47
- Parents:
- a497a11b6125be1576a34c48429ba326cafa35e2d1fbbf7c96369bd83b0fd1a804e99dfb09dd9e5d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libpolys/coeffs/longrat.cc
rd1fbbf r36ebfa 2645 2645 assume(cf != NULL); 2646 2646 assume(getCoeffType(cf) == ID); 2647 2648 numberCollectionEnumerator.Reset(); 2649 2650 if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial? 2651 { 2652 c = n_Init(1, cf); 2653 return; 2654 } 2655 2647 2656 // all coeffs are given by integers!!! 2648 2657 … … 2651 2660 int s1,s; 2652 2661 s=2147483647; // max. int 2653 numberCollectionEnumerator.Reset(); 2662 2663 2654 2664 int lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf); 2665 2666 int normalcount = 0; 2655 2667 do 2656 2668 { 2657 cand1= numberCollectionEnumerator.Current(); 2658 if (SR_HDL(cand1)&SR_INT) { cand=cand1;break;} 2659 assume(cand1->s==3); // all coeffs should be integers 2669 number& n = numberCollectionEnumerator.Current(); 2670 nlNormalize(n, cf); ++normalcount; 2671 cand1 = n; 2672 2673 if (SR_HDL(cand1)&SR_INT) { cand=cand1; break; } 2674 assume(cand1->s==3); // all coeffs should be integers // ==0?!! after printing 2660 2675 s1=mpz_size1(cand1->z); 2661 2676 if (s>s1) … … 2666 2681 } while (numberCollectionEnumerator.MoveNext() ); 2667 2682 2683 // assume( nlGreaterZero(cand,cf) ); // cand may be a negative integer! 2684 2668 2685 cand=nlCopy(cand,cf); 2669 2686 // part 2: compute gcd(cand,all coeffs) 2687 2670 2688 numberCollectionEnumerator.Reset(); 2671 do 2672 { 2673 nlNormalize(numberCollectionEnumerator.Current(),cf); 2674 nlInpGcd(cand,numberCollectionEnumerator.Current(),cf); 2689 2690 while (numberCollectionEnumerator.MoveNext() ) 2691 { 2692 number& n = numberCollectionEnumerator.Current(); 2693 2694 if( (--normalcount) <= 0) 2695 nlNormalize(n, cf); 2696 2697 nlInpGcd(cand, n, cf); 2698 2699 assume( nlGreaterZero(cand,cf) ); 2700 2675 2701 if(nlIsOne(cand,cf)) 2676 2702 { 2677 c=cand; 2703 c = cand; 2704 2678 2705 if(!lc_is_pos) 2679 2706 { 2680 2707 // make the leading coeff positive 2681 c =nlNeg(c,cf);2708 c = nlNeg(c, cf); 2682 2709 numberCollectionEnumerator.Reset(); 2683 do 2710 2711 while (numberCollectionEnumerator.MoveNext() ) 2684 2712 { 2685 numberCollectionEnumerator.Current()=nlNeg(numberCollectionEnumerator.Current(),cf); 2686 } while (numberCollectionEnumerator.MoveNext() ); 2713 number& nn = numberCollectionEnumerator.Current(); 2714 nn = nlNeg(nn, cf); 2715 } 2687 2716 } 2688 2717 return; 2689 2718 } 2690 } while (numberCollectionEnumerator.MoveNext() );2719 } 2691 2720 2692 2721 // part3: all coeffs = all coeffs / cand 2693 if (!lc_is_pos) cand=nlNeg(cand,cf); 2694 c=cand; 2722 if (!lc_is_pos) 2723 cand = nlNeg(cand,cf); 2724 2725 c = cand; 2695 2726 numberCollectionEnumerator.Reset(); 2696 do 2697 { 2698 number t=nlIntDiv(numberCollectionEnumerator.Current(),cand,cf); 2699 nlDelete(&numberCollectionEnumerator.Current(),cf); 2700 numberCollectionEnumerator.Current()=t; 2701 } while (numberCollectionEnumerator.MoveNext() ); 2702 2727 2728 while (numberCollectionEnumerator.MoveNext() ) 2729 { 2730 number& n = numberCollectionEnumerator.Current(); 2731 number t=nlIntDiv(n, cand, cf); // simple integer exact division, no ratios to remain 2732 nlDelete(&n, cf); 2733 n = t; 2734 } 2703 2735 } 2704 2736 … … 2707 2739 assume(cf != NULL); 2708 2740 assume(getCoeffType(cf) == ID); 2741 2742 numberCollectionEnumerator.Reset(); 2743 2744 if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial? 2745 { 2746 c = n_Init(1, cf); 2747 return; 2748 } 2749 2709 2750 // all coeffs are given by integers after returning from this routine 2710 2751 … … 2712 2753 number cand; 2713 2754 cand=ALLOC_RNUMBER(); 2714 2755 #if defined(LDEBUG) 2715 2756 cand->debug=123456; 2716 2757 #endif 2717 2758 cand->s=3; 2718 2759 2719 2760 int s=0; 2720 mpz_t tmp; 2721 mpz_init(tmp); 2722 numberCollectionEnumerator.Reset(); 2761 // mpz_t tmp; mpz_init(tmp); // tmp = GMP int 2762 2723 2763 int lc_is_pos=nlGreaterZero(numberCollectionEnumerator.Current(),cf); 2764 2724 2765 do 2725 2766 { … … 2730 2771 nlNormalize(cand1, cf); 2731 2772 if ((!(SR_HDL(cand1)&SR_INT)) // not a short int 2732 && (cand1->s==1)) // and is rational2773 && (cand1->s==1)) // and is a normalised rational 2733 2774 { 2734 2775 if (s==0) // first denom, we meet 2735 2776 { 2736 mpz_init_set(cand->z, cand1->n);2777 mpz_init_set(cand->z, cand1->n); // cand->z = cand1->n 2737 2778 s=1; 2738 2779 } 2739 2780 else // we have already something 2740 2781 { 2741 mpz_gcd(tmp,cand->z,cand1->n); 2742 if (mpz_cmp_si(tmp,1)!=0) 2743 { 2744 mpz_divexact(cand->z,cand->z,tmp); 2745 } 2746 mpz_mul(cand->z,cand->z,cand1->n); 2782 mpz_lcm(cand->z, cand->z, cand1->n); 2783 /* 2784 mpz_gcd(tmp,cand->z,cand1->n); // tmp = GCD( cand->z, cand1->n ) 2785 2786 if (mpz_cmp_si(tmp,1)!=0) 2787 mpz_divexact(cand->z,cand->z,tmp); // cand->z /= tmp 2788 2789 mpz_mul(cand->z,cand->z,cand1->n); // cand->z *= cand1->n 2790 */ 2747 2791 } 2748 2792 } 2749 2793 } 2750 } while (numberCollectionEnumerator.MoveNext() ); 2794 } 2795 while (numberCollectionEnumerator.MoveNext() ); 2796 2751 2797 2752 2798 if (s==0) // nothing to do, all coeffs are already integers 2753 2799 { 2754 mpz_clear(tmp);2800 // mpz_clear(tmp); 2755 2801 FREE_RNUMBER(cand); 2756 2802 if (lc_is_pos) … … 2760 2806 // make the leading coeff positive 2761 2807 c=nlInit(-1,cf); 2808 2809 // TODO: incorporate the following into the loop below? 2762 2810 numberCollectionEnumerator.Reset(); 2763 do 2764 { 2765 numberCollectionEnumerator.Current()=nlNeg(numberCollectionEnumerator.Current(),cf); 2766 } while (numberCollectionEnumerator.MoveNext() ); 2811 while (numberCollectionEnumerator.MoveNext() ) 2812 { 2813 number& n = numberCollectionEnumerator.Current(); 2814 n = nlNeg(n, cf); 2815 } 2767 2816 } 2768 2817 return; 2769 2818 } 2770 cand=nlShort3(cand); 2819 2820 cand = nlShort3(cand); 2771 2821 2772 2822 // part2: all coeffs = all coeffs * cand 2773 2823 // make the lead coeff positive 2774 2824 numberCollectionEnumerator.Reset(); 2775 if (!nlGreaterZero(numberCollectionEnumerator.Current(),cf))2776 {2777 cand =nlNeg(cand,cf);2778 }2825 2826 if (!lc_is_pos) 2827 cand = nlNeg(cand, cf); 2828 2779 2829 c = cand; 2780 do 2830 2831 while (numberCollectionEnumerator.MoveNext() ) 2781 2832 { 2782 2833 number &n = numberCollectionEnumerator.Current(); 2783 2834 n_InpMult(n, cand, cf); 2784 } while (numberCollectionEnumerator.MoveNext() );2835 } 2785 2836 2786 2837 }
Note: See TracChangeset
for help on using the changeset viewer.