Changeset 558f3cc in git


Ignore:
Timestamp:
Jan 4, 2013, 6:39:47 PM (11 years ago)
Author:
Oleksandr Motsak <motsak@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'b4f17ed1d25f93d46dbe29e4b499baecc2fd51bb')
Children:
8f296a6216092a84f1ebb509dbcda5fe428004f7
Parents:
d9947d272d574a169450505d43dc8ad3a5b4d0f0
git-author:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2013-01-04 18:39:47+01:00
git-committer:
Oleksandr Motsak <motsak@mathematik.uni-kl.de>2013-01-15 20:41:56+01:00
Message:
Fix: make positive leading coeff at normalizing!
Location:
libpolys
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libpolys/coeffs/longrat.cc

    rd9947d r558f3cc  
    26642664}
    26652665
    2666 void nlClearContent(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
     2666static void nlClearContent(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
    26672667{
    26682668  assume(cf != NULL);
     
    27572757}
    27582758
    2759 void nlClearContentNoPositiveLead(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
    2760 {
    2761   assume(cf != NULL);
    2762   assume(getCoeffType(cf) == ID);
    2763 
    2764   numberCollectionEnumerator.Reset();
    2765 
    2766   if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
    2767   {
    2768     c = n_Init(1, cf);
    2769     return;
    2770   }
    2771 
    2772   // all coeffs are given by integers!!!
    2773 
    2774   // part 1, find a small candidate for gcd
    2775   number cand1,cand;
    2776   int s1,s;
    2777   s=2147483647; // max. int
    2778 
    2779   const BOOLEAN lc_is_pos = TRUE; // nlGreaterZero(numberCollectionEnumerator.Current(),cf);
    2780 
    2781   int normalcount = 0;
    2782   do
    2783   {
    2784     number& n = numberCollectionEnumerator.Current();
    2785     nlNormalize(n, cf); ++normalcount;
    2786     cand1 = n;
    2787 
    2788     if (SR_HDL(cand1)&SR_INT) { cand=cand1; break; }
    2789     assume(cand1->s==3); // all coeffs should be integers // ==0?!! after printing
    2790     s1=mpz_size1(cand1->z);
    2791     if (s>s1)
    2792     {
    2793       cand=cand1;
    2794       s=s1;
    2795     }
    2796   } while (numberCollectionEnumerator.MoveNext() );
    2797 
    2798 //  assume( nlGreaterZero(cand,cf) ); // cand may be a negative integer!
    2799 
    2800   cand=nlCopy(cand,cf);
    2801   // part 2: compute gcd(cand,all coeffs)
    2802 
    2803   numberCollectionEnumerator.Reset();
    2804 
    2805   while (numberCollectionEnumerator.MoveNext() )
    2806   {
    2807     number& n = numberCollectionEnumerator.Current();
    2808 
    2809     if( (--normalcount) <= 0)
    2810       nlNormalize(n, cf);
    2811 
    2812     nlInpGcd(cand, n, cf);
    2813 
    2814     assume( nlGreaterZero(cand,cf) );
    2815 
    2816     if(nlIsOne(cand,cf))
    2817     {
    2818       c = cand;
    2819 
    2820       if(!lc_is_pos)
    2821       {
    2822         // make the leading coeff positive
    2823         c = nlNeg(c, cf);
    2824         numberCollectionEnumerator.Reset();
    2825 
    2826         while (numberCollectionEnumerator.MoveNext() )
    2827         {
    2828           number& nn = numberCollectionEnumerator.Current();
    2829           nn = nlNeg(nn, cf);
    2830         }
    2831       }
    2832       return;
    2833     }
    2834   }
    2835 
    2836   // part3: all coeffs = all coeffs / cand
    2837   if (!lc_is_pos)
    2838     cand = nlNeg(cand,cf);
    2839 
    2840   c = cand;
    2841   numberCollectionEnumerator.Reset();
    2842 
    2843   while (numberCollectionEnumerator.MoveNext() )
    2844   {
    2845     number& n = numberCollectionEnumerator.Current();
    2846     number t=nlIntDiv(n, cand, cf); // simple integer exact division, no ratios to remain
    2847     nlDelete(&n, cf);
    2848     n = t;
    2849   }
    2850 }
    2851 
    2852 void nlClearDenominators(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
     2759static void nlClearDenominators(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
    28532760{
    28542761  assume(cf != NULL);
     
    29372844  c = cand;
    29382845 
    2939   while (numberCollectionEnumerator.MoveNext() )
    2940   {
    2941     number &n = numberCollectionEnumerator.Current();
    2942     n_InpMult(n, cand, cf);
    2943   }
    2944 
    2945 }
    2946 
    2947 
    2948 void nlClearDenominatorsNoPositiveLead(ICoeffsEnumerator& numberCollectionEnumerator, number& c, const coeffs cf)
    2949 {
    2950   assume(cf != NULL);
    2951   assume(getCoeffType(cf) == ID);
    2952 
    2953   numberCollectionEnumerator.Reset();
    2954 
    2955   if( !numberCollectionEnumerator.MoveNext() ) // empty zero polynomial?
    2956   {
    2957     c = n_Init(1, cf);
    2958     return;
    2959   }
    2960 
    2961   // all coeffs are given by integers after returning from this routine
    2962 
    2963   // part 1, collect product of all denominators /gcds
    2964   number cand;
    2965   cand=ALLOC_RNUMBER();
    2966 #if defined(LDEBUG)
    2967   cand->debug=123456;
    2968 #endif
    2969   cand->s=3;
    2970 
    2971   int s=0;
    2972 
    2973   const BOOLEAN lc_is_pos = TRUE; // nlGreaterZero(numberCollectionEnumerator.Current(),cf);
    2974 
    2975   do
    2976   {
    2977     number& cand1 = numberCollectionEnumerator.Current();
    2978 
    2979     if (!(SR_HDL(cand1)&SR_INT))
    2980     {
    2981       nlNormalize(cand1, cf);
    2982       if ((!(SR_HDL(cand1)&SR_INT)) // not a short int
    2983           && (cand1->s==1))             // and is a normalised rational
    2984       {
    2985         if (s==0) // first denom, we meet
    2986         {
    2987           mpz_init_set(cand->z, cand1->n); // cand->z = cand1->n
    2988           s=1;
    2989         }
    2990         else // we have already something
    2991         {
    2992           mpz_lcm(cand->z, cand->z, cand1->n);
    2993         }
    2994       }
    2995     }
    2996   }
    2997   while (numberCollectionEnumerator.MoveNext() );
    2998 
    2999 
    3000   if (s==0) // nothing to do, all coeffs are already integers
    3001   {
    3002 //    mpz_clear(tmp);
    3003     FREE_RNUMBER(cand);
    3004     if (lc_is_pos)
    3005       c=nlInit(1,cf);
    3006     else
    3007     {
    3008       // make the leading coeff positive
    3009       c=nlInit(-1,cf);
    3010 
    3011       // TODO: incorporate the following into the loop below?
    3012       numberCollectionEnumerator.Reset();
    3013       while (numberCollectionEnumerator.MoveNext() )
    3014       {
    3015         number& n = numberCollectionEnumerator.Current();
    3016         n = nlNeg(n, cf);
    3017       }
    3018     }
    3019     return;
    3020   }
    3021 
    3022   cand = nlShort3(cand);
    3023 
    3024   // part2: all coeffs = all coeffs * cand
    3025   // make the lead coeff positive
    3026   numberCollectionEnumerator.Reset();
    3027 
    3028   if (!lc_is_pos)
    3029     cand = nlNeg(cand, cf);
    3030 
    3031   c = cand;
    3032 
    30332846  while (numberCollectionEnumerator.MoveNext() )
    30342847  {
  • libpolys/polys/ext_fields/algext.cc

    rd9947d r558f3cc  
    11141114  number cc;
    11151115
    1116   extern void nlClearContentNoPositiveLead(ICoeffsEnumerator&, number&, const coeffs);
    1117 
    1118   nlClearContentNoPositiveLead(itr, cc, Q); // TODO: get rid of (-LC) normalization!?
     1116  n_ClearContent(itr, cc, Q); // TODO: get rid of (-LC) normalization!?
    11191117
    11201118  // over alg. ext. of Q // takes over the input number
     
    11901188  number n;
    11911189  CRecursivePolyCoeffsEnumerator<NAConverter> itr(numberCollectionEnumerator); // recursively treat the numbers as polys!
    1192 
    1193   extern void nlClearDenominatorsNoPositiveLead(ICoeffsEnumerator&, number&, const coeffs);
    1194 
    1195   nlClearDenominatorsNoPositiveLead(itr, n, Q); // this should probably be fine...
     1190  n_ClearDenominators(itr, n, Q); // this should probably be fine...
    11961191  c = (number)p_NSet(n, cf->extRing); // over alg. ext. of Q // takes over the input number
    11971192}
  • libpolys/polys/ext_fields/transext.cc

    rd9947d r558f3cc  
    101101
    102102
    103 extern void nlClearContent(ICoeffsEnumerator&, number&, const coeffs);
    104 extern void nlClearContentNoPositiveLead(ICoeffsEnumerator&, number&, const coeffs);
    105 
    106 //extern void nlClearDenominators(ICoeffsEnumerator&, number&, const coeffs);
    107 //extern void nlClearDenominatorsNoPositiveLead(ICoeffsEnumerator&, number&, const coeffs);
    108 
    109 
    110103omBin fractionObjectBin = omGetSpecBin(sizeof(fractionObject));
    111104
     
    315308
    316309    n_ClearDenominators(itr, g, ntRing->cf);
    317 //    nlClearDenominators(itr, g, ntRing->cf);
    318310
    319311    if( !n_GreaterZero(g, ntRing->cf) )
     
    402394
    403395  n_ClearDenominators(itr, g, ntRing->cf); // may return -1 :(((
    404 //    nlClearDenominators(itr, g, ntRing->cf);
    405 
    406396
    407397  if( !n_GreaterZero(g, ntRing->cf) )
     
    556546
    557547    n_ClearDenominators(itr, g, ntRing->cf);
    558 //    nlClearDenominators(itr, g, ntRing->cf);
    559548
    560549    if( !n_GreaterZero(g, ntRing->cf) )
     
    18251814  number cc;
    18261815
    1827 //  nlClearContentNoPositiveLead(itr, cc, Q); // TODO: get rid of (-LC) normalization!?
    1828   nlClearContent(itr, cc, Q);
     1816  n_ClearContent(itr, cc, Q);
    18291817  number g = ntInit(p_NSet(cc, R), cf);
    18301818
Note: See TracChangeset for help on using the changeset viewer.