Changeset e5d267 in git for libpolys/polys/ext_fields


Ignore:
Timestamp:
Jul 4, 2011, 4:22:10 PM (13 years ago)
Author:
Frank Seelisch <seelisch@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
da49bc5ede2940b54c1e9f92022763151efa76e6
Parents:
df43d9eede47de2604d4c0ff334af81427c1ec57
git-author:
Frank Seelisch <seelisch@mathematik.uni-kl.de>2011-07-04 16:22:10+02:00
git-committer:
Mohamed Barakat <mohamed.barakat@rwth-aachen.de>2011-11-09 12:39:11+01:00
Message:
cancellation of gcd in rat. funct. fields
Location:
libpolys/polys/ext_fields
Files:
2 edited

Legend:

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

    rdf43d9 re5d267  
    2525#include <polys/monomials/p_polys.h>
    2626#include <polys/simpleideals.h>
     27
     28#ifdef HAVE_FACTORY
     29#include <polys/clapsing.h>
     30#endif
    2731
    2832#include <polys/ext_fields/transext.h>
     
    7478  assume(getCoeffType(cf) == ntID);
    7579  fraction t = (fraction)a;
    76   if (is0(t)) return TRUE;
    77   assume(num(t) != NULL);   /**< t != 0 ==> numerator(t) != 0 */
    78   p_Test(num(t), ntRing);
    79   if (!denIs1(t)) p_Test(den(t), ntRing);
     80  if (IS0(t)) return TRUE;
     81  assume(NUM(t) != NULL);   /**< t != 0 ==> numerator(t) != 0 */
     82  p_Test(NUM(t), ntRing);
     83  if (!DENIS1(t)) p_Test(DEN(t), ntRing);
    8084  return TRUE;
    8185}
     
    103107{
    104108  ntTest(a);
    105   return (is0(a));
     109  return (IS0(a));
    106110}
    107111
     
    109113{
    110114  fraction f = (fraction)(*a);
    111   if (is0(f)) return;
    112   p_Delete(&num(f), ntRing);
    113   if (!denIs1(f)) p_Delete(&den(f), ntRing);
     115  if (IS0(f)) return;
     116  p_Delete(&NUM(f), ntRing);
     117  if (!DENIS1(f)) p_Delete(&DEN(f), ntRing);
    114118  omFreeBin((ADDRESS)f, fractionObjectBin);
    115119  *a = NULL;
     
    122126  /// simple tests
    123127  if (a == b) return TRUE;
    124   if ((is0(a)) && (!is0(b))) return FALSE;
    125   if ((is0(b)) && (!is0(a))) return FALSE;
     128  if ((IS0(a)) && (!IS0(b))) return FALSE;
     129  if ((IS0(b)) && (!IS0(a))) return FALSE;
    126130 
    127131  /// cheap test if gcd's have been cancelled in both numbers
    128132  fraction fa = (fraction)a;
    129133  fraction fb = (fraction)b;
    130   if ((c(fa) == 1) && (c(fb) == 1))
    131   {
    132     poly f = p_Add_q(p_Copy(num(fa), ntRing),
    133                      p_Neg(p_Copy(num(fb), ntRing), ntRing),
     134  if ((COM(fa) == 1) && (COM(fb) == 1))
     135  {
     136    poly f = p_Add_q(p_Copy(NUM(fa), ntRing),
     137                     p_Neg(p_Copy(NUM(fb), ntRing), ntRing),
    134138                     ntRing);
    135139    if (f != NULL) { p_Delete(&f, ntRing); return FALSE; }
    136     if (denIs1(fa) && denIs1(fb))  return TRUE;
    137     if (denIs1(fa) && !denIs1(fb)) return FALSE;
    138     if (!denIs1(fa) && denIs1(fb)) return FALSE;
    139     f = p_Add_q(p_Copy(den(fa), ntRing),
    140                 p_Neg(p_Copy(den(fb), ntRing), ntRing),
     140    if (DENIS1(fa) && DENIS1(fb))  return TRUE;
     141    if (DENIS1(fa) && !DENIS1(fb)) return FALSE;
     142    if (!DENIS1(fa) && DENIS1(fb)) return FALSE;
     143    f = p_Add_q(p_Copy(DEN(fa), ntRing),
     144                p_Neg(p_Copy(DEN(fb), ntRing), ntRing),
    141145                ntRing);
    142146    if (f != NULL) { p_Delete(&f, ntRing); return FALSE; }
     
    146150  /* default: the more expensive multiplication test
    147151              a/b = c/d  <==>  a*d = b*c */
    148   poly f = p_Copy(num(fa), ntRing);
    149   if (!denIs1(fb)) f = p_Mult_q(f, p_Copy(den(fb), ntRing), ntRing);
    150   poly g = p_Copy(num(fb), ntRing);
    151   if (!denIs1(fa)) g = p_Mult_q(g, p_Copy(den(fa), ntRing), ntRing);
     152  poly f = p_Copy(NUM(fa), ntRing);
     153  if (!DENIS1(fb)) f = p_Mult_q(f, p_Copy(DEN(fb), ntRing), ntRing);
     154  poly g = p_Copy(NUM(fb), ntRing);
     155  if (!DENIS1(fa)) g = p_Mult_q(g, p_Copy(DEN(fa), ntRing), ntRing);
    152156  poly h = p_Add_q(f, p_Neg(g, ntRing), ntRing);
    153157  if (h == NULL) return TRUE;
     
    162166{
    163167  ntTest(a);
    164   if (is0(a)) return NULL;
    165   fraction f = (fraction)a;
    166   poly g = p_Copy(num(f), ntRing);
    167   poly h = NULL; if (!denIs1(f)) h = p_Copy(den(f), ntRing);
     168  if (IS0(a)) return NULL;
     169  fraction f = (fraction)a;
     170  poly g = p_Copy(NUM(f), ntRing);
     171  poly h = NULL; if (!DENIS1(f)) h = p_Copy(DEN(f), ntRing);
    168172  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    169   num(result) = g;
    170   den(result) = h;
    171   c(result) = c(f);
     173  NUM(result) = g;
     174  DEN(result) = h;
     175  COM(result) = COM(f);
    172176  return (number)result;
    173177}
     
    177181  ntTest(a);
    178182  definiteGcdCancellation(a, cf, FALSE);
    179   if (is0(a)) return NULL;
    180   fraction f = (fraction)a;
    181   poly g = p_Copy(num(f), ntRing);
     183  if (IS0(a)) return NULL;
     184  fraction f = (fraction)a;
     185  poly g = p_Copy(NUM(f), ntRing);
    182186  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    183   num(result) = g;
    184   den(result) = NULL;
    185   c(result) = 0;
     187  NUM(result) = g;
     188  DEN(result) = NULL;
     189  COM(result) = 0;
    186190  return (number)result;
    187191}
     
    193197  fraction f = (fraction)a;
    194198  poly g;
    195   if (is0(f) || denIs1(f)) g = p_One(ntRing);
    196   else g = p_Copy(den(f), ntRing);
     199  if (IS0(f) || DENIS1(f)) g = p_One(ntRing);
     200  else g = p_Copy(DEN(f), ntRing);
    197201  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    198   num(result) = g;
    199   den(result) = NULL;
    200   c(result) = 0;
     202  NUM(result) = g;
     203  DEN(result) = NULL;
     204  COM(result) = 0;
    201205  return (number)result;
    202206}
     
    207211  definiteGcdCancellation(a, cf, FALSE);
    208212  fraction f = (fraction)a;
    209   return denIs1(f) && numIs1(f);
     213  return DENIS1(f) && NUMIS1(f);
    210214}
    211215
     
    215219  definiteGcdCancellation(a, cf, FALSE);
    216220  fraction f = (fraction)a;
    217   if (!denIs1(f)) return FALSE;
    218   poly g = num(f);
     221  if (!DENIS1(f)) return FALSE;
     222  poly g = NUM(f);
    219223  if (!p_IsConstant(g, ntRing)) return FALSE;
    220224  return n_IsMOne(p_GetCoeff(g, ntRing), ntCoeffs);
     
    225229{
    226230  ntTest(a);
    227   if (!is0(a))
     231  if (!IS0(a))
    228232  {
    229233    fraction f = (fraction)a;
    230     num(f) = p_Neg(num(f), ntRing);
     234    NUM(f) = p_Neg(NUM(f), ntRing);
    231235  }
    232236  return a;
     
    245249  {
    246250    fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    247     num(result) = p_ISet(i, ntRing);
    248     den(result) = NULL;
    249     c(result) = 0;
     251    NUM(result) = p_ISet(i, ntRing);
     252    DEN(result) = NULL;
     253    COM(result) = 0;
    250254    return (number)result;
    251255  }
     
    255259{
    256260  ntTest(a);
    257   if (is0(a)) return 0;
     261  if (IS0(a)) return 0;
    258262  definiteGcdCancellation(a, cf, FALSE);
    259263  fraction f = (fraction)a;
    260   if (!denIs1(f)) return 0;
    261   if (!p_IsConstant(num(f), ntRing)) return 0;
    262   return n_Int(p_GetCoeff(num(f), ntRing), ntCoeffs);
     264  if (!DENIS1(f)) return 0;
     265  if (!p_IsConstant(NUM(f), ntRing)) return 0;
     266  return n_Int(p_GetCoeff(NUM(f), ntRing), ntCoeffs);
    263267}
    264268
     
    274278  number aNumCoeff = NULL; int aNumDeg = 0;
    275279  number bNumCoeff = NULL; int bNumDeg = 0;
    276   if (!is0(a))
     280  if (!IS0(a))
    277281  {
    278282    fraction fa = (fraction)a;
    279     aNumDeg = p_Totaldegree(num(fa), ntRing);
    280     aNumCoeff = p_GetCoeff(num(fa), ntRing);
    281   }
    282   if (!is0(b))
     283    aNumDeg = p_Totaldegree(NUM(fa), ntRing);
     284    aNumCoeff = p_GetCoeff(NUM(fa), ntRing);
     285  }
     286  if (!IS0(b))
    283287  {
    284288    fraction fb = (fraction)b;
    285     bNumDeg = p_Totaldegree(num(fb), ntRing);
    286     bNumCoeff = p_GetCoeff(num(fb), ntRing);
     289    bNumDeg = p_Totaldegree(NUM(fb), ntRing);
     290    bNumCoeff = p_GetCoeff(NUM(fb), ntRing);
    287291  }
    288292  if (aNumDeg != bNumDeg) return FALSE;
     
    298302{
    299303  ntTest(a);
    300   if (is0(a)) return FALSE;
    301   fraction f = (fraction)a;
    302   poly g = num(f);
     304  if (IS0(a)) return FALSE;
     305  fraction f = (fraction)a;
     306  poly g = NUM(f);
    303307  return (n_GreaterZero(p_GetCoeff(g, ntRing), ntCoeffs) ||
    304308          (!p_LmIsConstant(g, ntRing)));
     
    326330  p_Setm(p, ntRing);
    327331  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    328   num(result) = p;
    329   den(result) = NULL;
    330   c(result) = 0;
     332  NUM(result) = p;
     333  DEN(result) = NULL;
     334  COM(result) = 0;
    331335  return (number)result;
    332336}
     
    335339{
    336340  ntTest(a); ntTest(b);
    337   if (is0(a)) return ntCopy(b, cf);
    338   if (is0(b)) return ntCopy(a, cf);
     341  if (IS0(a)) return ntCopy(b, cf);
     342  if (IS0(b)) return ntCopy(a, cf);
    339343 
    340344  fraction fa = (fraction)a;
    341345  fraction fb = (fraction)b;
    342346 
    343   poly g = p_Copy(num(fa), ntRing);
    344   if (!denIs1(fb)) g = p_Mult_q(g, p_Copy(den(fb), ntRing), ntRing);
    345   poly h = p_Copy(num(fb), ntRing);
    346   if (!denIs1(fa)) h = p_Mult_q(h, p_Copy(den(fa), ntRing), ntRing);
     347  poly g = p_Copy(NUM(fa), ntRing);
     348  if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing);
     349  poly h = p_Copy(NUM(fb), ntRing);
     350  if (!DENIS1(fa)) h = p_Mult_q(h, p_Copy(DEN(fa), ntRing), ntRing);
    347351  g = p_Add_q(g, h, ntRing);
    348352 
     
    350354 
    351355  poly f;
    352   if      (denIs1(fa) && denIs1(fb))  f = NULL;
    353   else if (!denIs1(fa) && denIs1(fb)) f = p_Copy(den(fa), ntRing);
    354   else if (denIs1(fa) && !denIs1(fb)) f = p_Copy(den(fb), ntRing);
    355   else /* both denom's are != 1 */    f = p_Mult_q(p_Copy(den(fa), ntRing),
    356                                                    p_Copy(den(fb), ntRing),
     356  if      (DENIS1(fa) && DENIS1(fb))  f = NULL;
     357  else if (!DENIS1(fa) && DENIS1(fb)) f = p_Copy(DEN(fa), ntRing);
     358  else if (DENIS1(fa) && !DENIS1(fb)) f = p_Copy(DEN(fb), ntRing);
     359  else /* both denom's are != 1 */    f = p_Mult_q(p_Copy(DEN(fa), ntRing),
     360                                                   p_Copy(DEN(fb), ntRing),
    357361                                                   ntRing);
    358362 
    359363  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    360   num(result) = g;
    361   den(result) = f;
    362   c(result) = c(fa) + c(fb) + ADD_COMPLEXITY;
     364  NUM(result) = g;
     365  DEN(result) = f;
     366  COM(result) = COM(fa) + COM(fb) + ADD_COMPLEXITY;
    363367  heuristicGcdCancellation((number)result, cf);
    364368  return (number)result;
     
    368372{
    369373  ntTest(a); ntTest(b);
    370   if (is0(a)) return ntNeg(ntCopy(b, cf), cf);
    371   if (is0(b)) return ntCopy(a, cf);
     374  if (IS0(a)) return ntNeg(ntCopy(b, cf), cf);
     375  if (IS0(b)) return ntCopy(a, cf);
    372376 
    373377  fraction fa = (fraction)a;
    374378  fraction fb = (fraction)b;
    375379 
    376   poly g = p_Copy(num(fa), ntRing);
    377   if (!denIs1(fb)) g = p_Mult_q(g, p_Copy(den(fb), ntRing), ntRing);
    378   poly h = p_Copy(num(fb), ntRing);
    379   if (!denIs1(fa)) h = p_Mult_q(h, p_Copy(den(fa), ntRing), ntRing);
     380  poly g = p_Copy(NUM(fa), ntRing);
     381  if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing);
     382  poly h = p_Copy(NUM(fb), ntRing);
     383  if (!DENIS1(fa)) h = p_Mult_q(h, p_Copy(DEN(fa), ntRing), ntRing);
    380384  g = p_Add_q(g, p_Neg(h, ntRing), ntRing);
    381385 
     
    383387 
    384388  poly f;
    385   if      (denIs1(fa) && denIs1(fb))  f = NULL;
    386   else if (!denIs1(fa) && denIs1(fb)) f = p_Copy(den(fa), ntRing);
    387   else if (denIs1(fa) && !denIs1(fb)) f = p_Copy(den(fb), ntRing);
    388   else /* both den's are != 1 */      f = p_Mult_q(p_Copy(den(fa), ntRing),
    389                                                    p_Copy(den(fb), ntRing),
     389  if      (DENIS1(fa) && DENIS1(fb))  f = NULL;
     390  else if (!DENIS1(fa) && DENIS1(fb)) f = p_Copy(DEN(fa), ntRing);
     391  else if (DENIS1(fa) && !DENIS1(fb)) f = p_Copy(DEN(fb), ntRing);
     392  else /* both den's are != 1 */      f = p_Mult_q(p_Copy(DEN(fa), ntRing),
     393                                                   p_Copy(DEN(fb), ntRing),
    390394                                                   ntRing);
    391395 
    392396  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    393   num(result) = g;
    394   den(result) = f;
    395   c(result) = c(fa) + c(fb) + ADD_COMPLEXITY;
     397  NUM(result) = g;
     398  DEN(result) = f;
     399  COM(result) = COM(fa) + COM(fb) + ADD_COMPLEXITY;
    396400  heuristicGcdCancellation((number)result, cf);
    397401  return (number)result;
     
    401405{
    402406  ntTest(a); ntTest(b);
    403   if (is0(a) || is0(b)) return NULL;
     407  if (IS0(a) || IS0(b)) return NULL;
    404408 
    405409  fraction fa = (fraction)a;
    406410  fraction fb = (fraction)b;
    407411 
    408   poly g = p_Copy(num(fa), ntRing);
    409   poly h = p_Copy(num(fb), ntRing);
     412  poly g = p_Copy(NUM(fa), ntRing);
     413  poly h = p_Copy(NUM(fb), ntRing);
    410414  g = p_Mult_q(g, h, ntRing);
    411415 
     
    413417 
    414418  poly f;
    415   if      (denIs1(fa) && denIs1(fb))  f = NULL;
    416   else if (!denIs1(fa) && denIs1(fb)) f = p_Copy(den(fa), ntRing);
    417   else if (denIs1(fa) && !denIs1(fb)) f = p_Copy(den(fb), ntRing);
    418   else /* both den's are != 1 */      f = p_Mult_q(p_Copy(den(fa), ntRing),
    419                                                    p_Copy(den(fb), ntRing),
     419  if      (DENIS1(fa) && DENIS1(fb))  f = NULL;
     420  else if (!DENIS1(fa) && DENIS1(fb)) f = p_Copy(DEN(fa), ntRing);
     421  else if (DENIS1(fa) && !DENIS1(fb)) f = p_Copy(DEN(fb), ntRing);
     422  else /* both den's are != 1 */      f = p_Mult_q(p_Copy(DEN(fa), ntRing),
     423                                                   p_Copy(DEN(fb), ntRing),
    420424                                                   ntRing);
    421425 
    422426  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    423   num(result) = g;
    424   den(result) = f;
    425   c(result) = c(fa) + c(fb) + MULT_COMPLEXITY;
     427  NUM(result) = g;
     428  DEN(result) = f;
     429  COM(result) = COM(fa) + COM(fb) + MULT_COMPLEXITY;
    426430  heuristicGcdCancellation((number)result, cf);
    427431  return (number)result;
     
    431435{
    432436  ntTest(a); ntTest(b);
    433   if (is0(a)) return NULL;
    434   if (is0(b)) WerrorS(nDivBy0);
     437  if (IS0(a)) return NULL;
     438  if (IS0(b)) WerrorS(nDivBy0);
    435439 
    436440  fraction fa = (fraction)a;
    437441  fraction fb = (fraction)b;
    438442 
    439   poly g = p_Copy(num(fa), ntRing);
    440   if (!denIs1(fb)) g = p_Mult_q(g, p_Copy(den(fb), ntRing), ntRing);
     443  poly g = p_Copy(NUM(fa), ntRing);
     444  if (!DENIS1(fb)) g = p_Mult_q(g, p_Copy(DEN(fb), ntRing), ntRing);
    441445 
    442446  if (g == NULL) return NULL;   /* may happen due to zero divisors */
    443447 
    444   poly f = p_Copy(num(fb), ntRing);
    445   if (!denIs1(fa)) f = p_Mult_q(f, p_Copy(den(fa), ntRing), ntRing);
     448  poly f = p_Copy(NUM(fb), ntRing);
     449  if (!DENIS1(fa)) f = p_Mult_q(f, p_Copy(DEN(fa), ntRing), ntRing);
    446450 
    447451  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    448   num(result) = g;
    449   den(result) = f;
    450   c(result) = c(fa) + c(fb) + MULT_COMPLEXITY;
     452  NUM(result) = g;
     453  DEN(result) = f;
     454  COM(result) = COM(fa) + COM(fb) + MULT_COMPLEXITY;
    451455  heuristicGcdCancellation((number)result, cf);
    452456  return (number)result;
     
    466470 
    467471  /* special cases first */
    468   if (is0(a))
     472  if (IS0(a))
    469473  {
    470474    if (exp >= 0) *b = NULL;
     
    529533{
    530534  ntTest(a);
    531   if (is0(a)) return;
    532  
    533   fraction f = (fraction)a;
    534   if (denIs1(f) || numIs1(f)) { c(f) = 0; return; }
    535  
    536   /* check whether num(f) = den(f), and - if so - replace 'a' by 1 */
    537   poly difference = p_Add_q(p_Copy(num(f), ntRing),
    538                             p_Neg(p_Copy(den(f), ntRing), ntRing),
    539                             ntRing);
    540   if (difference == NULL)
    541   { /* we also know that numerator and denominator are both != 1 */
    542     p_Delete(&num(f), ntRing); num(f) = p_ISet(1, ntRing);
    543     p_Delete(&den(f), ntRing); den(f) = NULL;
    544     c(f) = 0;
     535  if (IS0(a)) return;
     536 
     537  fraction f = (fraction)a;
     538  if (DENIS1(f) || NUMIS1(f)) { COM(f) = 0; return; }
     539 
     540  /* check whether NUM(f) = DEN(f), and - if so - replace 'a' by 1 */
     541  if (p_EqualPolys(NUM(f), DEN(f), ntRing))
     542  { /* numerator and denominator are both != 1 */
     543    p_Delete(&NUM(f), ntRing); NUM(f) = p_ISet(1, ntRing);
     544    p_Delete(&DEN(f), ntRing); DEN(f) = NULL;
     545    COM(f) = 0;
    545546    return;
    546547  }
    547   else p_Delete(&difference, ntRing);
    548  
    549   if (c(f) <= BOUND_COMPLEXITY) return;
     548 
     549  if (COM(f) <= BOUND_COMPLEXITY) return;
    550550  else definiteGcdCancellation(a, cf, TRUE);
    551551}
     
    561561  if (!skipSimpleTests)
    562562  {
    563     if (is0(a)) return;
    564     if (denIs1(f) || numIs1(f)) { c(f) = 0; return; }
    565  
    566     /* check whether num(f) = den(f), and - if so - replace 'a' by 1 */
    567     poly difference = p_Add_q(p_Copy(num(f), ntRing),
    568                               p_Neg(p_Copy(den(f), ntRing), ntRing),
    569                               ntRing);
    570     if (difference == NULL)
    571     { /* we also know that numerator and denominator are both != 1 */
    572       p_Delete(&num(f), ntRing); num(f) = p_ISet(1, ntRing);
    573       p_Delete(&den(f), ntRing); den(f) = NULL;
    574       c(f) = 0;
     563    if (IS0(a)) return;
     564    if (DENIS1(f) || NUMIS1(f)) { COM(f) = 0; return; }
     565 
     566    /* check whether NUM(f) = DEN(f), and - if so - replace 'a' by 1 */
     567    if (p_EqualPolys(NUM(f), DEN(f), ntRing))
     568    { /* numerator and denominator are both != 1 */
     569      p_Delete(&NUM(f), ntRing); NUM(f) = p_ISet(1, ntRing);
     570      p_Delete(&DEN(f), ntRing); DEN(f) = NULL;
     571      COM(f) = 0;
    575572      return;
    576573    }
    577     else p_Delete(&difference, ntRing);
    578   }
    579  
    580   /* TO BE IMPLEMENTED!
    581      for the time being, cancellation of gcd's does not take place */
    582   Print("// TO BE IMPLEMENTED: transext.cc:definiteGcdCancellation\n");
    583   Print("// (complexity of number = %d, bound = %d)\n",
    584         c(f), BOUND_COMPLEXITY);
    585 }
    586 
     574  }
     575 
     576#ifdef HAVE_FACTORY
     577  /* singclap_gcd destroys its arguments. We hence need copies: */
     578  poly pNum = p_Copy(NUM(f), ntRing);
     579  poly pDen = p_Copy(DEN(f), ntRing);
     580  poly pGcd = singclap_gcd(pNum, pDen, cf->extRing);
     581  if (p_IsConstant(pGcd, ntRing) &&
     582      n_IsOne(p_GetCoeff(pGcd, ntRing), ntCoeffs))
     583  {
     584      /* gcd = 1; nothing to cancel */
     585  }
     586  else
     587  {
     588      poly newNum = singclap_pdivide(NUM(f), pGcd, ntRing);
     589      p_Delete(&NUM(f), ntRing);
     590      NUM(f) = newNum;
     591      poly newDen = singclap_pdivide(DEN(f), pGcd, ntRing);
     592      p_Delete(&DEN(f), ntRing);
     593      if (p_IsConstant(newDen, ntRing) &&
     594          n_IsOne(p_GetCoeff(newDen, ntRing), ntCoeffs))
     595      {
     596        /* newDen = 1 needs to be represented by NULL */
     597        p_Delete(&newDen, ntRing);
     598        newDen = NULL;
     599      }
     600      DEN(f) = newDen;
     601  }
     602  COM(f) = 0;
     603  p_Delete(&pGcd, ntRing);
     604#endif /* HAVE_FACTORY */
     605}
     606
     607/* modifies a */
    587608void ntWrite(number &a, const coeffs cf)
    588609{
    589610  ntTest(a);
    590611  definiteGcdCancellation(a, cf, FALSE);
    591   if (is0(a))
     612  if (IS0(a))
    592613    StringAppendS("0");
    593614  else
    594615  {
    595616    fraction f = (fraction)a;
    596     BOOLEAN useBrackets = !(p_IsConstant(num(f), ntRing)) && (!denIs1(f));
     617    BOOLEAN useBrackets = (!p_IsConstant(NUM(f), ntRing)) && (!DENIS1(f));
    597618    if (useBrackets) StringAppendS("(");
    598     p_String0(num(f), ntRing, ntRing);
     619    p_String0(NUM(f), ntRing, ntRing);
    599620    if (useBrackets) StringAppendS(")");
    600     if (!denIs1(f))
     621    if (!DENIS1(f))
    601622    {
    602623      StringAppendS("/");
    603       useBrackets = !p_IsConstant(den(f), ntRing);
     624      useBrackets = !p_IsConstant(DEN(f), ntRing);
    604625      if (useBrackets) StringAppendS("(");
    605       p_String0(den(f), ntRing, ntRing);
     626      p_String0(DEN(f), ntRing, ntRing);
    606627      if (useBrackets) StringAppendS(")");
    607628    }
     
    617638  {
    618639    fraction f = (fraction)omAlloc0Bin(fractionObjectBin);
    619     num(f) = p;
    620     den(f) = NULL;
    621     c(f) = 0;
     640    NUM(f) = p;
     641    DEN(f) = NULL;
     642    COM(f) = 0;
    622643    *a = (number)f;
    623644    return result;
     
    659680{
    660681  ntTest(a);
    661   if (is0(a)) return -1;
     682  if (IS0(a)) return -1;
    662683  /* this has been taken from the old implementation of field extensions,
    663684     where we computed the sum of the degrees and the numbers of terms in
     
    665686     time being */
    666687  fraction f = (fraction)a;
    667   poly p = num(f);
     688  poly p = NUM(f);
    668689  int noOfTerms = 0;
    669690  int numDegree = 0;
     
    678699  }
    679700  int denDegree = 0;
    680   if (!denIs1(f))
    681   {
    682     p = den(f);
     701  if (!DENIS1(f))
     702  {
     703    p = DEN(f);
    683704    while (p != NULL)
    684705    {
     
    697718{
    698719  ntTest(a);
    699   if (is0(a)) WerrorS(nDivBy0);
     720  if (IS0(a)) WerrorS(nDivBy0);
    700721  fraction f = (fraction)a;
    701722  fraction result = (fraction)omAlloc0Bin(fractionObjectBin);
    702723  poly g;
    703   if (denIs1(f)) g = p_One(ntRing);
    704   else           g = p_Copy(den(f), ntRing);
    705   num(result) = g;
    706   den(result) = p_Copy(num(f), ntRing);
    707   c(result) = c(f);
     724  if (DENIS1(f)) g = p_One(ntRing);
     725  else           g = p_Copy(DEN(f), ntRing);
     726  NUM(result) = g;
     727  DEN(result) = p_Copy(NUM(f), ntRing);
     728  COM(result) = COM(f);
    708729  return (number)result;
    709730}
     
    717738  p_SetCoeff(p, ntCopy(a, src), dst->extRing);
    718739  fraction f = (fraction)omAlloc0Bin(fractionObjectBin);
    719   num(f) = p; den(f) = NULL; c(f) = 0;
     740  NUM(f) = p; DEN(f) = NULL; COM(f) = 0;
    720741  return (number)f;
    721742}
     
    737758  p_SetCoeff(p, q, dst->extRing);
    738759  fraction f = (fraction)omAlloc0Bin(fractionObjectBin);
    739   num(f) = p; den(f) = NULL; c(f) = 0;
     760  NUM(f) = p; DEN(f) = NULL; COM(f) = 0;
    740761  return (number)f;
    741762}
     
    764785  p_SetCoeff(g, q, dst->extRing);
    765786  fraction f = (fraction)omAlloc0Bin(fractionObjectBin);
    766   num(f) = g; den(f) = NULL; c(f) = 0;
     787  NUM(f) = g; DEN(f) = NULL; COM(f) = 0;
    767788  return (number)f;
    768789}
     
    776797  p_SetCoeff(p, ntCopy(a, src), dst->extRing);
    777798  fraction f = (fraction)omAlloc0Bin(fractionObjectBin);
    778   num(f) = p; den(f) = NULL; c(f) = 0;
     799  NUM(f) = p; DEN(f) = NULL; COM(f) = 0;
    779800  return (number)f;
    780801}
     
    796817  p_SetCoeff(p, q, dst->extRing);
    797818  fraction f = (fraction)omAlloc0Bin(fractionObjectBin);
    798   num(f) = p; den(f) = NULL; c(f) = 0;
     819  NUM(f) = p; DEN(f) = NULL; COM(f) = 0;
    799820  return (number)f;
    800821}
     
    907928  cf->cfIntDiv       = ntDiv;
    908929 
     930#ifndef HAVE_FACTORY
     931  PrintS("// Warning: The 'factory' module is not available.\n");
     932  PrintS("//          Hence gcd's cannot be cancelled in any\n");
     933  PrintS("//          computed fraction!\n");
     934#endif
     935 
    909936  return FALSE;
    910937}
  • libpolys/polys/ext_fields/transext.h

    rdf43d9 re5d267  
    5959
    6060/* some useful accessors for fractions: */
    61 #define is0(f) (f == NULL) /**< TRUE iff n represents 0 in K(t_1, .., t_s) */
    62 #define num(f) f->numerator
    63 #define den(f) f->denominator
    64 #define denIs1(f) (f->denominator == NULL) /**< TRUE iff den. represents 1 */
    65 #define numIs1(f) (p_IsConstant(f->numerator, cf->extRing) && \
    66                    n_IsOne(p_GetCoeff(num(f), cf->extRing), cf->extRing->cf))
     61#define IS0(f) (f == NULL) /**< TRUE iff n represents 0 in K(t_1, .., t_s) */
     62#define NUM(f) f->numerator
     63#define DEN(f) f->denominator
     64#define DENIS1(f) (f->denominator == NULL) /**< TRUE iff den. represents 1 */
     65#define NUMIS1(f) (p_IsConstant(f->numerator, cf->extRing) && \
     66                   n_IsOne(p_GetCoeff(f->numerator, cf->extRing), \
     67                           cf->extRing->cf))
    6768                   /**< TRUE iff num. represents 1 */
    68 #define c(f) f->complexity
     69#define COM(f) f->complexity
    6970
    7071/// Get a mapping function from src into the domain of this type (n_transExt)
Note: See TracChangeset for help on using the changeset viewer.