Ignore:
Timestamp:
Sep 9, 2013, 4:37:38 PM (11 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
fc5f58cad717ce5735572253f71f32b365e53989
Parents:
ba49bf104d6b7507ed3b20c7e82c411b63cd90c3
git-author:
Hans Schoenemann <hannes@mathematik.uni-kl.de>2013-09-09 16:37:38+02:00
git-committer:
Janko Boehm <boehm@mathematik.uni-kl.de>2013-09-10 15:30:18+02:00
Message:
fix: enforce integer coeffs in rational functions
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpolys/polys/ext_fields/transext.cc

    rba49bf1 r3f7e6ee  
    141141void handleNestedFractionsOverQ(fraction f, const coeffs cf);
    142142
     143/* test routine, usualy disabled *
     144 * if want to activate it, activate also the calls to check_N *
     145 *
     146void check_normalized(number t,const coeffs cf, const char *f, int l)
     147{
     148  if (IS0(t)) return;
     149  if(rField_is_Q(ntRing))
     150  {
     151    poly pp=NUM(t);
     152    while(pp!=NULL)
     153    {
     154      if (((SR_HDL(pGetCoeff(pp)) & SR_INT)==0)&&(SR_HDL(pGetCoeff(pp))!=NULL))
     155      {
     156        if (pGetCoeff(pp)->s==0)
     157        {
     158          Print("NUM not normalized in %s:%d\n",f,l);
     159          p_Normalize(pp,ntRing);
     160        }
     161        else if (pGetCoeff(pp)->s==1)
     162          Print("NUM is rational in %s:%d\n",f,l);
     163      }
     164      pIter(pp);
     165    }
     166    pp=DEN(t);
     167    while(pp!=NULL)
     168    {
     169      if (((SR_HDL(pGetCoeff(pp)) & SR_INT)==0)&&(SR_HDL(pGetCoeff(pp))!=NULL))
     170      {
     171        if (pGetCoeff(pp)->s==0)
     172        {
     173          Print("NUM not normalized in %s:%d\n",f,l);
     174          p_Normalize(pp,ntRing);
     175        }
     176        else if (pGetCoeff(pp)->s==1)
     177          Print("DEN is rational in %s:%d\n",f,l);
     178      }
     179      pIter(pp);
     180    }
     181  }
     182}
     183#define check_N(A,B) check_normalized(A,B,__FILE__,__LINE__)
     184*/
     185
    143186#ifdef LDEBUG
    144187BOOLEAN ntDBTest(number a, const char *f, const int l, const coeffs cf)
     
    150193  const fraction t = (fraction)a;
    151194
     195  //check_N(a,cf);
    152196  const poly num = NUM(t);
    153197  assume(num != NULL);   /**< t != 0 ==> numerator(t) != 0 */
     
    240284BOOLEAN ntIsZero(number a, const coeffs cf)
    241285{
     286  //check_N(a,cf);
    242287  ntTest(a); // !!!
    243288  return (IS0(a));
     
    246291void ntDelete(number * a, const coeffs cf)
    247292{
     293  //check_N(*a,cf);
    248294  ntTest(*a); // !!!
    249295  fraction f = (fraction)(*a);
     
    257303BOOLEAN ntEqual(number a, number b, const coeffs cf)
    258304{
     305  //check_N(a,cf);
     306  //check_N(b,cf);
    259307  ntTest(a);
    260308  ntTest(b);
     
    301349number ntCopy(number a, const coeffs cf)
    302350{
     351  //check_N(a,cf);
    303352  ntTest(a); // !!!
    304353  if (IS0(a)) return NULL;
     
    317366number ntGetNumerator(number &a, const coeffs cf)
    318367{
     368  //check_N(a,cf);
    319369  ntTest(a);
    320370  if (IS0(a)) return NULL;
     
    370420
    371421  ntTest((number)result);
     422  //check_N((number)result,cf);
    372423  return (number)result;
    373424}
     
    376427number ntGetDenom(number &a, const coeffs cf)
    377428{
     429  //check_N(a,cf);
    378430  ntTest(a);
    379431
     
    382434  COM (result)= 0;
    383435
    384   if (IS0(a)) 
     436  if (IS0(a))
    385437  {
    386438    NUM (result) = p_One(ntRing);
    387439    return (number)result;
    388440  }
    389      
     441
    390442  definiteGcdCancellation(a, cf, FALSE);
    391    
     443
    392444  fraction f = (fraction)a;
    393    
     445
    394446  assume( !IS0(f) );
    395447
    396448  const BOOLEAN denis1 = DENIS1 (f);
    397  
     449
    398450  if( denis1 && (getCoeffType (ntCoeffs) != n_Q) ) // */1 or 0
    399451  {
     
    471523
    472524  ntTest((number)result);
     525  //check_N((number)result,cf);
    473526  return (number)result;
    474527}
     
    476529BOOLEAN ntIsOne(number a, const coeffs cf)
    477530{
     531  //check_N(a,cf);
    478532  ntTest(a); // !!!
    479533  definiteGcdCancellation(a, cf, FALSE);
     
    484538BOOLEAN ntIsMOne(number a, const coeffs cf)
    485539{
     540  //check_N(a,cf);
    486541  ntTest(a);
    487542  definiteGcdCancellation(a, cf, FALSE);
     
    496551number ntNeg(number a, const coeffs cf)
    497552{
     553  //check_N(a,cf);
    498554  ntTest(a);
    499555  if (!IS0(a))
     
    553609
    554610  ntTest((number)result);
     611  //check_N((number)result,cf);
    555612
    556613  return (number)result;
     
    570627      //COM(result) = 0; // done by omAlloc0Bin
    571628      ntTest((number)result);
     629      //check_N((number)result,cf);
    572630      return (number)result;
    573631    }
     
    587645  {
    588646    number g;
    589     // TODO/NOTE: the following should not be necessary (due to
    590     // Hannes!) as NUM (f) should be over Z!!!
    591     // but it is not: normalize it
     647    // the following is necessary because
     648    // NUM (f) should be over Z,
     649    // while p may be over Q
    592650    CPolyCoeffsEnumerator itr(p);
    593651
     
    606664    {
    607665      DEN (f) = p_NSet(g, ntRing);
     666      p_Normalize(DEN(f), ntRing);
    608667      assume( DEN (f) != NULL );
    609668    }
     
    615674  }
    616675
     676  p_Normalize(p, ntRing);
    617677  NUM(f) = p;
    618678  COM(f) = 0;
    619679
     680  //check_N((number)f,cf);
    620681  ntTest((number)f);
    621682  return (number)f;
     
    624685int ntInt(number &a, const coeffs cf)
    625686{
     687  //check_N(a,cf);
    626688  ntTest(a);
    627689  if (IS0(a)) return 0;
     
    651713BOOLEAN ntGreater(number a, number b, const coeffs cf)
    652714{
     715  //check_N(a,cf);
     716  //check_N(b,cf);
    653717  ntTest(a);
    654718  ntTest(b);
     
    702766BOOLEAN ntGreaterZero(number a, const coeffs cf)
    703767{
     768  //check_N(a,cf);
    704769  ntTest(a);
    705770  if (IS0(a)) return FALSE;
     
    749814number ntDiff(number a, number d, const coeffs cf)
    750815{
     816  //check_N(a,cf);
     817  //check_N(d,cf);
    751818  ntTest(a);
    752819  ntTest(d);
     
    773840
    774841  fraction fa = (fraction)a;
    775   if (DENIS1(fa)) {
    776 
     842  if (DENIS1(fa))
     843  {
    777844     fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    778845     NUM(result) = p_Diff(NUM(fa),k,ntRing);
     
    780847     DEN(result) = NULL;
    781848     COM(result) = COM(fa);
     849     //check_N((number)result,cf);
    782850     return (number)result;
    783851  }
     
    792860  heuristicGcdCancellation((number)result, cf);
    793861
     862  //check_N((number)result,cf);
    794863  return (number)result;
    795864}
     
    798867number ntAdd(number a, number b, const coeffs cf)
    799868{
     869  //check_N(a,cf);
     870  //check_N(b,cf);
    800871  ntTest(a);
    801872  ntTest(b);
     
    830901//  ntTest((number)result);
    831902
     903  //check_N((number)result,cf);
    832904  return (number)result;
    833905}
     
    835907number ntSub(number a, number b, const coeffs cf)
    836908{
     909  //check_N(a,cf);
     910  //check_N(b,cf);
    837911  ntTest(a);
    838912  ntTest(b);
     
    865939  heuristicGcdCancellation((number)result, cf);
    866940//  ntTest((number)result);
     941  //check_N((number)result,cf);
    867942  return (number)result;
    868943}
     
    870945number ntMult(number a, number b, const coeffs cf)
    871946{
     947  //check_N(a,cf);
     948  //check_N(b,cf);
    872949  ntTest(a); // !!!?
    873950  ntTest(b); // !!!?
     
    890967
    891968
     969  //check_N((number)result,cf);
    892970  if (db == NULL)
    893971  {
     
    906984      COM(result) = COM(fa) + MULT_COMPLEXITY;
    907985      heuristicGcdCancellation((number)result, cf);
    908     }
    909   } else
     986      //check_N((number)result,cf);
     987    }
     988  }
     989  else
    910990  { // b = ?? / ??
    911991    if (da == NULL)
     
    915995      COM(result) = COM(fb) + MULT_COMPLEXITY;
    916996      heuristicGcdCancellation((number)result, cf);
     997      //check_N((number)result,cf);
    917998    }
    918999    else /* both den's are != 1 */
     
    9221003      COM(result) = COM(fa) + COM(fb) + MULT_COMPLEXITY;
    9231004      heuristicGcdCancellation((number)result, cf);
     1005      //check_N((number)result,cf);
    9241006    }
    9251007  }
     
    9271009//  ntTest((number)result);
    9281010
     1011  //check_N((number)result,cf);
    9291012  return (number)result;
    9301013}
     
    9321015number ntDiv(number a, number b, const coeffs cf)
    9331016{
     1017  //check_N(a,cf);
     1018  //check_N(b,cf);
    9341019  ntTest(a);
    9351020  ntTest(b);
     
    9631048  heuristicGcdCancellation((number)result, cf);
    9641049//  ntTest((number)result);
     1050  //check_N((number)result,cf);
    9651051  return (number)result;
    9661052}
     
    10371123  *b = pow;
    10381124  ntTest(*b);
     1125  //check_N(*b,cf);
    10391126}
    10401127
     
    10701157
    10711158  { /* step (1); see documentation of this procedure above */
    1072     p_Normalize(NUM(f), ntRing);
    1073     p_Normalize(DEN(f), ntRing);
    10741159    number lcmOfDenominators = n_Init(1, ntCoeffs);
    10751160    number c; number tmp;
     
    11641249
    11651250  fraction f = (fraction)a;
    1166   if (COM(f)!=0) p_Normalize(NUM(f), ntRing);
     1251  p_Normalize(NUM(f),ntRing);
    11671252  if (DENIS1(f) || NUMIS1(f)) { COM(f) = 0; return; }
    11681253
    1169   p_Normalize(DEN(f), ntRing);
    1170 
    11711254  assume( DEN(f) != NULL );
     1255  p_Normalize(DEN(f),ntRing);
    11721256
    11731257  /* check whether NUM(f) = DEN(f), and - if so - replace 'a' by 1 */
     
    12201304
    12211305  if (IS0(a)) return;
    1222   if (NUM(f)!=NULL) p_Normalize(NUM(f), ntRing);
    1223   if (DEN(f)!=NULL) p_Normalize(DEN(f), ntRing);
    12241306  if (!simpleTestsHaveAlreadyBeenPerformed)
    12251307  {
    1226     //p_Normalize(NUM(f), ntRing);
    1227     //if (DEN(f)!=NULL) p_Normalize(DEN(f), ntRing);
    12281308    if (DENIS1(f) || NUMIS1(f)) { COM(f) = 0; return; }
    12291309
     
    16631743number ntInvers(number a, const coeffs cf)
    16641744{
     1745  //check_N(a,cf);
    16651746  ntTest(a);
    16661747  if (IS0(a))
     
    17131794  }
    17141795  ntTest((number)result); // !!!!
     1796  //check_N((number)result,cf);
    17151797  return (number)result;
    17161798}
     
    17351817  else                 DEN(ff)=p_NSet(nn,dst->extRing);
    17361818  n_Test((number)ff,dst);
     1819  //check_N((number)ff,dst);
    17371820  return (number)ff;
    17381821}
     
    17831866  DEN(result) = h;
    17841867  COM(result) = COM(f);
     1868  //check_N((number)result,dst);
    17851869  assume(n_Test((number)result, dst));
    17861870  return (number)result;
     
    17911875  assume( n_Test(a, cf) );
    17921876  if (n_IsZero(a, cf)) return NULL;
    1793 
    1794   fraction f = (fraction)omAlloc0Bin(fractionObjectBin);
    1795   // DEN(f) = NULL; COM(f) = 0;
    1796   NUM(f) = prCopyR((poly)a, cf->extRing, dst->extRing);
    1797   assume(n_Test((number)f, dst));
    1798   return (number)f;
     1877  return ntInit(prCopyR((poly)a, cf->extRing, dst->extRing),dst);
    17991878}
    18001879
     
    18181897  NUM(f) = g; // DEN(f) = NULL; COM(f) = 0;
    18191898  assume(n_Test((number)f, dst));
     1899  //check_N((number)f,dst);
    18201900  return (number)f;
    18211901}
     
    18321912  NUM(f) = p; DEN(f) = NULL; COM(f) = 0;
    18331913  assume(n_Test((number)f, dst));
     1914  //check_N((number)f,dst);
    18341915  return (number)f;
    18351916}
     
    18541935  NUM(f) = p; DEN(f) = NULL; COM(f) = 0;
    18551936  assume(n_Test((number)f, dst));
     1937  //check_N((number)f,dst);
    18561938  return (number)f;
    18571939}
     
    19522034  if (n.isZero()) return NULL;
    19532035  poly p=convFactoryPSingP(n,ntRing);
     2036  p_Normalize(p,ntRing);
    19542037  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    19552038  NUM(result) = p;
Note: See TracChangeset for help on using the changeset viewer.