Changeset db83bf in git


Ignore:
Timestamp:
May 27, 2011, 4:27:42 PM (12 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', '0604212ebb110535022efecad887940825b97c3f')
Children:
5b274570b3977c8b95131bdda194e0b179f17b8b
Parents:
410ea0fb1e22ebcb52e33b6789cf294a2d1f663b
Message:
format, again

git-svn-id: file:///usr/local/Singular/svn/trunk@14251 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/tgb.cc

    r410ea0f rdb83bf  
    4040static omBin lm_bin = NULL;
    4141
    42 static void
    43 simplify_poly (poly p, ring r)
     42static void simplify_poly (poly p, ring r)
    4443{
    4544  assume (r == currRing);
    46   if (!rField_is_Zp (r))
     45  if(!rField_is_Zp (r))
    4746  {
    4847    p_Cleardenom (p, r);
     
    5554//static const BOOLEAN up_to_radical=TRUE;
    5655
    57 int
    58 slim_nsize (number n, ring r)
    59 {
    60   if (rField_is_Zp (r))
     56int slim_nsize (number n, ring r)
     57{
     58  if(rField_is_Zp (r))
    6159  {
    6260    return 1;
    6361  }
    64   if (rField_is_Q (r))
     62  if(rField_is_Q (r))
    6563  {
    6664    return QlogSize (n);
     
    7270}
    7371
    74 static BOOLEAN
    75 monomial_root (poly m, ring r)
     72static BOOLEAN monomial_root (poly m, ring r)
    7673{
    7774  BOOLEAN changed = FALSE;
    7875  int i;
    79   for (i = 1; i <= rVar (r); i++)
     76  for(i = 1; i <= rVar (r); i++)
    8077  {
    8178    int e = p_GetExp (m, i, r);
    82     if (e > 1)
     79    if(e > 1)
    8380    {
    8481      p_SetExp (m, i, 1, r);
     
    8683    }
    8784  }
    88   if (changed)
     85  if(changed)
    8986  {
    9087    p_Setm (m, r);
     
    9390}
    9491
    95 static BOOLEAN
    96 polynomial_root (poly h, ring r)
     92static BOOLEAN polynomial_root (poly h, ring r)
    9793{
    9894  poly got = gcd_of_terms (h, r);
    9995  BOOLEAN changed = FALSE;
    100   if ((got != NULL) && (TEST_V_UPTORADICAL))
     96  if((got != NULL) && (TEST_V_UPTORADICAL))
    10197  {
    10298    poly copy = p_Copy (got, r);
    10399    //p_wrp(got,c->r);
    104100    changed = monomial_root (got, r);
    105     if (changed)
     101    if(changed)
    106102    {
    107103      poly div_by = pDivide (copy, got);
    108104      poly iter = h;
    109       while (iter)
    110       {
    111         pExpVectorSub (iter, div_by);
    112         pIter (iter);
     105      while(iter)
     106      {
     107        pExpVectorSub (iter, div_by);
     108        pIter (iter);
    113109      }
    114110      p_Delete (&div_by, r);
    115       if (TEST_OPT_PROT)
    116         PrintS ("U");
     111      if(TEST_OPT_PROT)
     112        PrintS ("U");
    117113    }
    118114    p_Delete (&copy, r);
     
    122118}
    123119
    124 static inline poly
    125 p_Init_Special (const ring r)
     120static inline poly p_Init_Special (const ring r)
    126121{
    127122  return p_Init (r, lm_bin);
    128123}
    129124
    130 static inline poly
    131 pOne_Special (const ring r = currRing)
     125static inline poly pOne_Special (const ring r = currRing)
    132126{
    133127  poly rc = p_Init_Special (r);
     
    147141#ifdef LEN_VAR1
    148142// erste Variante: Laenge: Anzahl der Monome
    149 static inline int
    150 pSLength (poly p, int l)
     143static inline int pSLength (poly p, int l)
    151144{
    152145  return l;
    153146}
    154147
    155 static inline int
    156 kSBucketLength (kBucket * bucket, poly lm)
     148static inline int kSBucketLength (kBucket * bucket, poly lm)
    157149{
    158150  return bucket_guess (bucket);
     
    162154#ifdef LEN_VAR2
    163155// 2. Variante: Laenge: Platz fuer die Koeff.
    164 int
    165 pSLength (poly p, int l)
     156int pSLength (poly p, int l)
    166157{
    167158  int s = 0;
    168   while (p != NULL)
     159  while(p != NULL)
    169160  {
    170161    s += nSize (pGetCoeff (p));
     
    174165}
    175166
    176 int
    177 kSBucketLength (kBucket * b, poly lm)
     167int kSBucketLength (kBucket * b, poly lm)
    178168{
    179169  int s = 0;
    180170  int i;
    181   for (i = MAX_BUCKET; i >= 0; i--)
     171  for(i = MAX_BUCKET; i >= 0; i--)
    182172  {
    183173    s += pSLength (b->buckets[i], 0);
     
    187177#endif
    188178
    189 int
    190 QlogSize (number n)
    191 {
    192   if (SR_HDL (n) & SR_INT)
     179int QlogSize (number n)
     180{
     181  if(SR_HDL (n) & SR_INT)
    193182  {
    194183    long i = SR_TO_INT (n);
    195     if (i == 0)
     184    if(i == 0)
    196185      return 0;
    197186
     
    200189    int r = 0;
    201190
    202     while (v >>= 1)
     191    while(v >>= 1)
    203192    {
    204193      r++;
     
    211200
    212201#ifdef LEN_VAR3
    213 static inline wlen_type
    214 pSLength (poly p, int l)
     202static inline wlen_type pSLength (poly p, int l)
    215203{
    216204  wlen_type c;
    217205  number coef = pGetCoeff (p);
    218   if (rField_is_Q (currRing))
     206  if(rField_is_Q (currRing))
    219207  {
    220208    c = QlogSize (coef);
     
    222210  else
    223211    c = nSize (coef);
    224   if (!(TEST_V_COEFSTRAT))
     212  if(!(TEST_V_COEFSTRAT))
     213  {
    225214    return (wlen_type) c *(wlen_type) l /*pLength(p) */ ;
     215  }
    226216  else
    227217  {
     
    234224
    235225//! TODO CoefBuckets bercksichtigen
    236 wlen_type
    237 kSBucketLength (kBucket * b, poly lm = NULL)
     226wlen_type kSBucketLength (kBucket * b, poly lm = NULL)
    238227{
    239228  int s = 0;
    240229  wlen_type c;
    241230  number coef;
    242   if (lm == NULL)
     231  if(lm == NULL)
    243232    coef = pGetCoeff (kBucketGetLm (b));
    244233  //c=nSize(pGetCoeff(kBucketGetLm(b)));
     
    246235    coef = pGetCoeff (lm);
    247236  //c=nSize(pGetCoeff(lm));
    248   if (rField_is_Q (currRing))
     237  if(rField_is_Q (currRing))
    249238  {
    250239    c = QlogSize (coef);
     
    254243
    255244  int i;
    256   for (i = b->buckets_used; i >= 0; i--)
     245  for(i = b->buckets_used; i >= 0; i--)
    257246  {
    258247    assume ((b->buckets_length[i] == 0) || (b->buckets[i] != NULL));
     
    261250#ifdef HAVE_COEF_BUCKETS
    262251  assume (b->buckets[0] == kBucketGetLm (b));
    263   if (b->coef[0] != NULL)
    264   {
    265     if (rField_is_Q (currRing))
     252  if(b->coef[0] != NULL)
     253  {
     254    if(rField_is_Q (currRing))
    266255    {
    267256      int modifier = QlogSize (pGetCoeff (b->coef[0]));
     
    275264  }
    276265#endif
    277   if (!(TEST_V_COEFSTRAT))
     266  if(!(TEST_V_COEFSTRAT))
    278267  {
    279268    return s * c;
     
    289278#endif
    290279#ifdef LEN_VAR5
    291 static inline wlen_type
    292 pSLength (poly p, int l)
     280static inline wlen_type pSLength (poly p, int l)
    293281{
    294282  int c;
    295283  number coef = pGetCoeff (p);
    296   if (rField_is_Q (currRing))
     284  if(rField_is_Q (currRing))
    297285  {
    298286    c = QlogSize (coef);
     
    309297
    310298//! TODO CoefBuckets bercksichtigen
    311 wlen_type
    312 kSBucketLength (kBucket * b, poly lm = NULL)
     299wlen_type kSBucketLength (kBucket * b, poly lm = NULL)
    313300{
    314301  wlen_type s = 0;
    315302  int c;
    316303  number coef;
    317   if (lm == NULL)
     304  if(lm == NULL)
    318305    coef = pGetCoeff (kBucketGetLm (b));
    319306  //c=nSize(pGetCoeff(kBucketGetLm(b)));
     
    321308    coef = pGetCoeff (lm);
    322309  //c=nSize(pGetCoeff(lm));
    323   if (rField_is_Q (currRing))
     310  if(rField_is_Q (currRing))
    324311  {
    325312    c = QlogSize (coef);
     
    329316
    330317  int i;
    331   for (i = b->buckets_used; i >= 0; i--)
     318  for(i = b->buckets_used; i >= 0; i--)
    332319  {
    333320    assume ((b->buckets_length[i] == 0) || (b->buckets[i] != NULL));
     
    336323#ifdef HAVE_COEF_BUCKETS
    337324  assume (b->buckets[0] == kBucketGetLm (b));
    338   if (b->coef[0] != NULL)
    339   {
    340     if (rField_is_Q (currRing))
     325  if(b->coef[0] != NULL)
     326  {
     327    if(rField_is_Q (currRing))
    341328    {
    342329      int modifier = QlogSize (pGetCoeff (b->coef[0]));
     
    359346#ifdef LEN_VAR4
    360347// 4.Variante: Laenge: Platz fuer Leitk * (1+Platz fuer andere Koeff.)
    361 int
    362 pSLength (poly p, int l)
     348int pSLength (poly p, int l)
    363349{
    364350  int s = 1;
    365351  int c = nSize (pGetCoeff (p));
    366352  pIter (p);
    367   while (p != NULL)
     353  while(p != NULL)
    368354  {
    369355    s += nSize (pGetCoeff (p));
     
    373359}
    374360
    375 int
    376 kSBucketLength (kBucket * b)
     361int kSBucketLength (kBucket * b)
    377362{
    378363  int s = 1;
    379364  int c = nSize (pGetCoeff (kBucketGetLm (b)));
    380365  int i;
    381   for (i = MAX_BUCKET; i > 0; i--)
    382   {
    383     if (b->buckets[i] == NULL)
     366  for(i = MAX_BUCKET; i > 0; i--)
     367  {
     368    if(b->buckets[i] == NULL)
    384369      continue;
    385370    s += pSLength (b->buckets[i], 0);
     
    389374#endif
    390375//BUG/TODO this stuff will fail on internal Schreyer orderings
    391 static BOOLEAN
    392 elength_is_normal_length (poly p, slimgb_alg * c)
     376static BOOLEAN elength_is_normal_length (poly p, slimgb_alg * c)
    393377{
    394378  ring r = c->r;
    395   if (p_GetComp (p, r) != 0)
     379  if(p_GetComp (p, r) != 0)
    396380    return FALSE;
    397   if (c->lastDpBlockStart <= pVariables)
     381  if(c->lastDpBlockStart <= pVariables)
    398382  {
    399383    int i;
    400     for (i = 1; i < c->lastDpBlockStart; i++)
    401     {
    402       if (p_GetExp (p, i, r) != 0)
    403       {
    404         break;
    405       }
    406     }
    407     if (i >= c->lastDpBlockStart)
     384    for(i = 1; i < c->lastDpBlockStart; i++)
     385    {
     386      if(p_GetExp (p, i, r) != 0)
     387      {
     388        break;
     389      }
     390    }
     391    if(i >= c->lastDpBlockStart)
    408392    {
    409393      //wrp(p);
     
    418402}
    419403
    420 static BOOLEAN
    421 lies_in_last_dp_block (poly p, slimgb_alg * c)
     404static BOOLEAN lies_in_last_dp_block (poly p, slimgb_alg * c)
    422405{
    423406  ring r = c->r;
    424   if (p_GetComp (p, r) != 0)
     407  if(p_GetComp (p, r) != 0)
    425408    return FALSE;
    426   if (c->lastDpBlockStart <= pVariables)
     409  if(c->lastDpBlockStart <= pVariables)
    427410  {
    428411    int i;
    429     for (i = 1; i < c->lastDpBlockStart; i++)
    430     {
    431       if (p_GetExp (p, i, r) != 0)
    432       {
    433         break;
    434       }
    435     }
    436     if (i >= c->lastDpBlockStart)
     412    for(i = 1; i < c->lastDpBlockStart; i++)
     413    {
     414      if(p_GetExp (p, i, r) != 0)
     415      {
     416        break;
     417      }
     418    }
     419    if(i >= c->lastDpBlockStart)
    437420    {
    438421      //wrp(p);
     
    447430}
    448431
    449 static int
    450 get_last_dp_block_start (ring r)
     432static int get_last_dp_block_start (ring r)
    451433{
    452434  //ring r=c->r;
    453435  int last_block;
    454436
    455   if (rRing_has_CompLastBlock (r))
     437  if(rRing_has_CompLastBlock (r))
    456438  {
    457439    last_block = rBlocks (r) - 3;
     
    462444  }
    463445  assume (last_block >= 0);
    464   if (r->order[last_block] == ringorder_dp)
     446  if(r->order[last_block] == ringorder_dp)
    465447    return r->block0[last_block];
    466448  return pVariables + 1;
    467449}
    468450
    469 static wlen_type
    470 do_pELength (poly p, slimgb_alg * c, int dlm = -1)
    471 {
    472   if (p == NULL)
     451static wlen_type do_pELength (poly p, slimgb_alg * c, int dlm = -1)
     452{
     453  if(p == NULL)
    473454    return 0;
    474455  wlen_type s = 0;
    475456  poly pi = p;
    476   if (dlm < 0)
     457  if(dlm < 0)
    477458  {
    478459    dlm = c->pTotaldegree (p);
     
    481462  }
    482463
    483   while (pi)
     464  while(pi)
    484465  {
    485466    int d = c->pTotaldegree (pi);
    486     if (d > dlm)
     467    if(d > dlm)
    487468      s += 1 + d - dlm;
    488469    else
     
    493474}
    494475
    495 wlen_type
    496 pELength (poly p, slimgb_alg * c, ring r)
    497 {
    498   if (p == NULL)
     476wlen_type pELength (poly p, slimgb_alg * c, ring r)
     477{
     478  if(p == NULL)
    499479    return 0;
    500480  wlen_type s = 0;
     
    505485  pi = p->next;
    506486
    507   while (pi)
     487  while(pi)
    508488  {
    509489    int d = c->pTotaldegree (pi);
    510     if (d > dlm)
     490    if(d > dlm)
    511491      s += 1 + d - dlm;
    512492    else
     
    517497}
    518498
    519 wlen_type
    520 kEBucketLength (kBucket * b, poly lm, int sugar, slimgb_alg * ca)
     499wlen_type kEBucketLength (kBucket * b, poly lm, int sugar, slimgb_alg * ca)
    521500{
    522501  wlen_type s = 0;
    523   if (lm == NULL)
     502  if(lm == NULL)
    524503  {
    525504    lm = kBucketGetLm (b);
    526505  }
    527   if (lm == NULL)
     506  if(lm == NULL)
    528507    return 0;
    529   if (elength_is_normal_length (lm, ca))
     508  if(elength_is_normal_length (lm, ca))
    530509  {
    531510    return bucket_guess (b);
     
    540519  //int d=pTotaldegree(lm,ca->r);
    541520  int i;
    542   for (i = b->buckets_used; i >= 0; i--)
    543   {
    544     if (b->buckets[i] == NULL)
     521  for(i = b->buckets_used; i >= 0; i--)
     522  {
     523    if(b->buckets[i] == NULL)
    545524      continue;
    546525
    547     if ((ca->pTotaldegree (b->buckets[i]) <= d)
    548         && (elength_is_normal_length (b->buckets[i], ca)))
     526    if((ca->pTotaldegree (b->buckets[i]) <= d)
     527       && (elength_is_normal_length (b->buckets[i], ca)))
    549528    {
    550529      s += b->buckets_length[i];
     
    559538}
    560539
    561 static inline int
    562 pELength (poly p, slimgb_alg * c, int l)
    563 {
    564   if (p == NULL)
     540static inline int pELength (poly p, slimgb_alg * c, int l)
     541{
     542  if(p == NULL)
    565543    return 0;
    566   if ((l > 0) && (elength_is_normal_length (p, c)))
     544  if((l > 0) && (elength_is_normal_length (p, c)))
    567545    return l;
    568546  return do_pELength (p, c);
    569547}
    570548
    571 static inline wlen_type
    572 pQuality (poly p, slimgb_alg * c, int l = -1)
    573 {
    574   if (l < 0)
     549static inline wlen_type pQuality (poly p, slimgb_alg * c, int l = -1)
     550{
     551  if(l < 0)
    575552    l = pLength (p);
    576   if (c->isDifficultField)
    577   {
    578     if (c->eliminationProblem)
     553  if(c->isDifficultField)
     554  {
     555    if(c->eliminationProblem)
    579556    {
    580557      wlen_type cs;
    581558      number coef = pGetCoeff (p);
    582       if (rField_is_Q (currRing))
    583       {
    584         cs = QlogSize (coef);
     559      if(rField_is_Q (currRing))
     560      {
     561        cs = QlogSize (coef);
    585562      }
    586563      else
    587         cs = nSize (coef);
     564        cs = nSize (coef);
    588565      wlen_type erg = cs;
    589       if (TEST_V_COEFSTRAT)
    590         erg *= cs;
     566      if(TEST_V_COEFSTRAT)
     567        erg *= cs;
    591568      //erg*=cs;//for quadratic
    592569      erg *= pELength (p, c, l);
     
    600577    return r;
    601578  }
    602   if (c->eliminationProblem)
     579  if(c->eliminationProblem)
    603580    return pELength (p, c, l);
    604581  return l;
    605582}
    606583
    607 static inline int
    608 pTotaldegree_full (poly p)
     584static inline int pTotaldegree_full (poly p)
    609585{
    610586  int r = 0;
    611   while (p)
     587  while(p)
    612588  {
    613589    int d = pTotaldegree (p);
     
    618594}
    619595
    620 wlen_type
    621 red_object::guess_quality (slimgb_alg * c)
     596wlen_type red_object::guess_quality (slimgb_alg * c)
    622597{
    623598  //works at the moment only for lenvar 1, because in different
    624599  //case, you have to look on coefs
    625600  wlen_type s = 0;
    626   if (c->isDifficultField)
     601  if(c->isDifficultField)
    627602  {
    628603    //s=kSBucketLength(bucket,this->p);
    629     if (c->eliminationProblem)
     604    if(c->eliminationProblem)
    630605    {
    631606      wlen_type cs;
     
    636611
    637612      //c=nSize(pGetCoeff(lm));
    638       if (rField_is_Q (currRing))
    639       {
    640         cs = QlogSize (coef);
     613      if(rField_is_Q (currRing))
     614      {
     615        cs = QlogSize (coef);
    641616      }
    642617      else
    643         cs = nSize (coef);
     618        cs = nSize (coef);
    644619#ifdef HAVE_COEF_BUCKETS
    645       if (bucket->coef[0] != NULL)
    646       {
    647         if (rField_is_Q (currRing))
    648         {
    649           int modifier = QlogSize (pGetCoeff (bucket->coef[0]));
    650           cs += modifier;
    651         }
    652         else
    653         {
    654           int modifier = nSize (pGetCoeff (bucket->coef[0]));
    655           cs *= modifier;
    656         }
     620      if(bucket->coef[0] != NULL)
     621      {
     622        if(rField_is_Q (currRing))
     623        {
     624          int modifier = QlogSize (pGetCoeff (bucket->coef[0]));
     625          cs += modifier;
     626        }
     627        else
     628        {
     629          int modifier = nSize (pGetCoeff (bucket->coef[0]));
     630          cs *= modifier;
     631        }
    657632      }
    658633#endif
     
    661636      //erg*=cs;//for quadratic
    662637      erg *= cs;
    663       if (TEST_V_COEFSTRAT)
    664         erg *= cs;
     638      if(TEST_V_COEFSTRAT)
     639        erg *= cs;
    665640      //return cs*kEBucketLength(this->bucket,this->p,c);
    666641      return erg;
     
    670645  else
    671646  {
    672     if (c->eliminationProblem)
     647    if(c->eliminationProblem)
    673648      //if (false)
    674649      s = kEBucketLength (this->bucket, this->p, this->sugar, c);
     
    679654}
    680655
    681 #if 0                           //currently unused
    682 static void
    683 finalize_reduction_step (reduction_step * r)
     656#if 0                           //currently unused
     657static void finalize_reduction_step (reduction_step * r)
    684658{
    685659  delete r;
    686660}
    687661#endif
    688 #if 0                           //currently unused
    689 static int
    690 LObject_better_gen (const void *ap, const void *bp)
     662#if 0                           //currently unused
     663static int LObject_better_gen (const void *ap, const void *bp)
    691664{
    692665  LObject *a = *(LObject **) ap;
     
    695668}
    696669#endif
    697 static int
    698 red_object_better_gen (const void *ap, const void *bp)
     670static int red_object_better_gen (const void *ap, const void *bp)
    699671{
    700672  return (pLmCmp (((red_object *) ap)->p, ((red_object *) bp)->p));
    701673}
    702674
    703 #if 0                           //currently unused
    704 static int
    705 pLmCmp_func_inverted (const void *ap1, const void *ap2)
     675#if 0                           //currently unused
     676static int pLmCmp_func_inverted (const void *ap1, const void *ap2)
    706677{
    707678  poly p1, p2;
     
    712683#endif
    713684
    714 int
    715 tgb_pair_better_gen2 (const void *ap, const void *bp)
     685int tgb_pair_better_gen2 (const void *ap, const void *bp)
    716686{
    717687  return (-tgb_pair_better_gen (ap, bp));
    718688}
    719689
    720 int
    721 kFindDivisibleByInS_easy (kStrategy strat, const red_object & obj)
     690int kFindDivisibleByInS_easy (kStrategy strat, const red_object & obj)
    722691{
    723692  int i;
    724693  long not_sev = ~obj.sev;
    725694  poly p = obj.p;
    726   for (i = 0; i <= strat->sl; i++)
    727   {
    728     if (pLmShortDivisibleBy (strat->S[i], strat->sevS[i], p, not_sev))
     695  for(i = 0; i <= strat->sl; i++)
     696  {
     697    if(pLmShortDivisibleBy (strat->S[i], strat->sevS[i], p, not_sev))
    729698      return i;
    730699  }
     
    732701}
    733702
    734 int
    735 kFindDivisibleByInS_easy (kStrategy strat, poly p, long sev)
     703int kFindDivisibleByInS_easy (kStrategy strat, poly p, long sev)
    736704{
    737705  int i;
    738706  long not_sev = ~sev;
    739   for (i = 0; i <= strat->sl; i++)
    740   {
    741     if (pLmShortDivisibleBy (strat->S[i], strat->sevS[i], p, not_sev))
     707  for(i = 0; i <= strat->sl; i++)
     708  {
     709    if(pLmShortDivisibleBy (strat->S[i], strat->sevS[i], p, not_sev))
    742710      return i;
    743711  }
     
    747715static int
    748716posInPairs (sorted_pair_node ** p, int pn, sorted_pair_node * qe,
    749             slimgb_alg * c, int an = 0)
    750 {
    751   if (pn == 0)
     717            slimgb_alg * c, int an = 0)
     718{
     719  if(pn == 0)
    752720    return 0;
    753721
     
    757725  int en = length;
    758726
    759   if (pair_better (qe, p[en], c))
     727  if(pair_better (qe, p[en], c))
    760728    return length + 1;
    761729
    762   while (1)
     730  while(1)
    763731  {
    764732    //if (an >= en-1)
    765     if (en - 1 <= an)
    766     {
    767       if (pair_better (p[an], qe, c))
    768         return an;
     733    if(en - 1 <= an)
     734    {
     735      if(pair_better (p[an], qe, c))
     736        return an;
    769737      return en;
    770738    }
    771739    i = (an + en) / 2;
    772     if (pair_better (p[i], qe, c))
     740    if(pair_better (p[i], qe, c))
    773741      en = i;
    774742    else
     
    777745}
    778746
    779 static BOOLEAN
    780 ascending (int *i, int top)
    781 {
    782   if (top < 1)
     747static BOOLEAN ascending (int *i, int top)
     748{
     749  if(top < 1)
    783750    return TRUE;
    784   if (i[top] < i[top - 1])
     751  if(i[top] < i[top - 1])
    785752    return FALSE;
    786753  return ascending (i, top - 1);
    787754}
    788755
    789 sorted_pair_node **
    790 spn_merge (sorted_pair_node ** p, int pn, sorted_pair_node ** q, int qn,
    791            slimgb_alg * c)
     756sorted_pair_node **spn_merge (sorted_pair_node ** p, int pn,
     757                              sorted_pair_node ** q, int qn, slimgb_alg * c)
    792758{
    793759  int i;
     
    807773// }
    808774  int lastpos = 0;
    809   for (i = 0; i < qn; i++)
     775  for(i = 0; i < qn; i++)
    810776  {
    811777    lastpos = posInPairs (p, pn, q[i], c, si_max (lastpos - 1, 0));
     
    813779    a[i] = lastpos;
    814780  }
    815   if ((pn + qn) > c->max_pairs)
     781  if((pn + qn) > c->max_pairs)
    816782  {
    817783    p =
    818784      (sorted_pair_node **) omrealloc (p,
    819                                        2 * (pn +
    820                                             qn) *
    821                                        sizeof (sorted_pair_node *));
     785                                       2 * (pn +
     786                                            qn) *
     787                                       sizeof (sorted_pair_node *));
    822788    c->max_pairs = 2 * (pn + qn);
    823789  }
    824   for (i = qn - 1; i >= 0; i--)
     790  for(i = qn - 1; i >= 0; i--)
    825791  {
    826792    size_t size;
    827     if (qn - 1 > i)
     793    if(qn - 1 > i)
    828794      size = (a[i + 1] - a[i]) * sizeof (sorted_pair_node *);
    829795    else
    830       size = (pn - a[i]) * sizeof (sorted_pair_node *); //as indices begin with 0
     796      size = (pn - a[i]) * sizeof (sorted_pair_node *); //as indices begin with 0
    831797    memmove (p + a[i] + (1 + i), p + a[i], size);
    832798    p[a[i] + i] = q[i];
     
    842808  poly p2 = c->S->m[pos2];
    843809
    844   if (pGetComp (p1) > 0 || pGetComp (p2) > 0)
     810  if(pGetComp (p1) > 0 || pGetComp (p2) > 0)
    845811    return FALSE;
    846812  int i = 1;
     
    849815  poly gcd2 = c->gcd_of_terms[pos2];
    850816
    851   if ((gcd1 != NULL) && (gcd2 != NULL))
    852   {
    853     gcd1->next = gcd2;          //may ordered incorrect
     817  if((gcd1 != NULL) && (gcd2 != NULL))
     818  {
     819    gcd1->next = gcd2;          //may ordered incorrect
    854820    m = gcd_of_terms (gcd1, c->r);
    855821    gcd1->next = NULL;
    856822  }
    857   if (m == NULL)
     823  if(m == NULL)
    858824  {
    859825    loop
    860826    {
    861       if (pGetExp (p1, i) + pGetExp (p2, i) > pGetExp (bound, i))
    862         return FALSE;
    863       if (i == pVariables)
    864       {
    865         //PrintS("trivial");
    866         return TRUE;
     827      if(pGetExp (p1, i) + pGetExp (p2, i) > pGetExp (bound, i))
     828        return FALSE;
     829      if(i == pVariables)
     830      {
     831        //PrintS("trivial");
     832        return TRUE;
    867833      }
    868834      i++;
     
    873839    loop
    874840    {
    875       if (pGetExp (p1, i) - pGetExp (m, i) + pGetExp (p2, i) >
    876           pGetExp (bound, i))
    877       {
    878         pDelete (&m);
    879         return FALSE;
    880       }
    881       if (i == pVariables)
    882       {
    883         pDelete (&m);
    884         //PrintS("trivial");
    885         return TRUE;
     841      if(pGetExp (p1, i) - pGetExp (m, i) + pGetExp (p2, i) >
     842         pGetExp (bound, i))
     843      {
     844        pDelete (&m);
     845        return FALSE;
     846      }
     847      if(i == pVariables)
     848      {
     849        pDelete (&m);
     850        //PrintS("trivial");
     851        return TRUE;
    886852      }
    887853      i++;
     
    891857
    892858//! returns position sets w as weight
    893 int
    894 find_best (red_object * r, int l, int u, wlen_type & w, slimgb_alg * c)
     859int find_best (red_object * r, int l, int u, wlen_type & w, slimgb_alg * c)
    895860{
    896861  int best = l;
    897862  int i;
    898863  w = r[l].guess_quality (c);
    899   for (i = l + 1; i <= u; i++)
     864  for(i = l + 1; i <= u; i++)
    900865  {
    901866    wlen_type w2 = r[i].guess_quality (c);
    902     if (w2 < w)
     867    if(w2 < w)
    903868    {
    904869      w = w2;
     
    909874}
    910875
    911 void
    912 red_object::canonicalize ()
     876void red_object::canonicalize ()
    913877{
    914878  kBucketCanonicalize (bucket);
    915879}
    916880
    917 BOOLEAN
    918 good_has_t_rep (int i, int j, slimgb_alg * c)
     881BOOLEAN good_has_t_rep (int i, int j, slimgb_alg * c)
    919882{
    920883  assume (i >= 0);
    921884  assume (j >= 0);
    922   if (has_t_rep (i, j, c))
     885  if(has_t_rep (i, j, c))
    923886    return TRUE;
    924887  //poly lm=pOne();
     
    933896  //p_Delete(&lm,c->r);
    934897
    935   for (int n = 0; ((n < c->n) && (i_con[n] >= 0)); n++)
    936   {
    937     if (i_con[n] == j)
     898  for(int n = 0; ((n < c->n) && (i_con[n] >= 0)); n++)
     899  {
     900    if(i_con[n] == j)
    938901    {
    939902      now_t_rep (i, j, c);
     
    947910}
    948911
    949 BOOLEAN
    950 lenS_correct (kStrategy strat)
     912BOOLEAN lenS_correct (kStrategy strat)
    951913{
    952914  int i;
    953   for (i = 0; i <= strat->sl; i++)
    954   {
    955     if (strat->lenS[i] != pLength (strat->S[i]))
     915  for(i = 0; i <= strat->sl; i++)
     916  {
     917    if(strat->lenS[i] != pLength (strat->S[i]))
    956918      return FALSE;
    957919  }
     
    960922
    961923
    962 static void
    963 cleanS (kStrategy strat, slimgb_alg * c)
     924static void cleanS (kStrategy strat, slimgb_alg * c)
    964925{
    965926  int i = 0;
    966927  LObject P;
    967   while (i <= strat->sl)
     928  while(i <= strat->sl)
    968929  {
    969930    P.p = strat->S[i];
     
    971932    //int dummy=strat->sl;
    972933    //if(kFindDivisibleByInS(strat,&dummy,&P)!=i)
    973     if (kFindDivisibleByInS_easy (strat, P.p, P.sev) != i)
     934    if(kFindDivisibleByInS_easy (strat, P.p, P.sev) != i)
    974935    {
    975936      deleteInS (i, strat);
     
    977938      BOOLEAN found = FALSE;
    978939      int j;
    979       for (j = 0; j < c->n; j++)
    980       {
    981         if (c->S->m[j] == P.p)
    982         {
    983           found = TRUE;
    984           break;
    985         }
    986       }
    987       if (!found)
    988         pDelete (&P.p);
     940      for(j = 0; j < c->n; j++)
     941      {
     942        if(c->S->m[j] == P.p)
     943        {
     944          found = TRUE;
     945          break;
     946        }
     947      }
     948      if(!found)
     949        pDelete (&P.p);
    989950      //remember additional reductors
    990951    }
     
    994955}
    995956
    996 static int
    997 bucket_guess (kBucket * bucket)
     957static int bucket_guess (kBucket * bucket)
    998958{
    999959  int sum = 0;
    1000960  int i;
    1001   for (i = bucket->buckets_used; i >= 0; i--)
    1002   {
    1003     if (bucket->buckets[i])
     961  for(i = bucket->buckets_used; i >= 0; i--)
     962  {
     963    if(bucket->buckets[i])
    1004964      sum += bucket->buckets_length[i];
    1005965  }
     
    1009969static int
    1010970add_to_reductors (slimgb_alg * c, poly h, int len, int ecart,
    1011                   BOOLEAN simplified)
     971                  BOOLEAN simplified)
    1012972{
    1013973  //inDebug(h);
     
    1023983  memset (&P, 0, sizeof (P));
    1024984  P.tailRing = c->r;
    1025   P.p = h;                      /*p_Copy(h,c->r); */
     985  P.p = h;                      /*p_Copy(h,c->r); */
    1026986  P.ecart = ecart;
    1027987  P.FDeg = pFDeg (P.p, c->r);
    1028   if (!(simplified))
    1029   {
    1030     if (!rField_is_Zp (c->r))
     988  if(!(simplified))
     989  {
     990    if(!rField_is_Zp (c->r))
    1031991    {
    1032992      p_Cleardenom (P.p, c->r);
     
    10441004  c->strat->lenS[i] = len;
    10451005  assume (pLength (c->strat->S[i]) == c->strat->lenS[i]);
    1046   if (c->strat->lenSw != NULL)
     1006  if(c->strat->lenSw != NULL)
    10471007    c->strat->lenSw[i] = pq;
    10481008
     
    10501010}
    10511011
    1052 static void
    1053 length_one_crit (slimgb_alg * c, int pos, int len)
    1054 {
    1055   if (c->nc)
     1012static void length_one_crit (slimgb_alg * c, int pos, int len)
     1013{
     1014  if(c->nc)
    10561015    return;
    1057   if (len == 1)
     1016  if(len == 1)
    10581017  {
    10591018    int i;
    1060     for (i = 0; i < pos; i++)
    1061     {
    1062       if (c->lengths[i] == 1)
    1063         c->states[pos][i] = HASTREP;
    1064     }
    1065     for (i = pos + 1; i < c->n; i++)
    1066     {
    1067       if (c->lengths[i] == 1)
    1068         c->states[i][pos] = HASTREP;
    1069     }
    1070     if (!c->nc)
     1019    for(i = 0; i < pos; i++)
     1020    {
     1021      if(c->lengths[i] == 1)
     1022        c->states[pos][i] = HASTREP;
     1023    }
     1024    for(i = pos + 1; i < c->n; i++)
     1025    {
     1026      if(c->lengths[i] == 1)
     1027        c->states[i][pos] = HASTREP;
     1028    }
     1029    if(!c->nc)
    10711030      shorten_tails (c, c->S->m[pos]);
    10721031  }
    10731032}
    10741033
    1075 static void
    1076 move_forward_in_S (int old_pos, int new_pos, kStrategy strat)
     1034static void move_forward_in_S (int old_pos, int new_pos, kStrategy strat)
    10771035{
    10781036  assume (old_pos >= new_pos);
     
    10841042  assume (length == pLength (strat->S[old_pos]));
    10851043  wlen_type length_w;
    1086   if (strat->lenSw != NULL)
     1044  if(strat->lenSw != NULL)
    10871045    length_w = strat->lenSw[old_pos];
    10881046  int i;
    1089   for (i = old_pos; i > new_pos; i--)
     1047  for(i = old_pos; i > new_pos; i--)
    10901048  {
    10911049    strat->S[i] = strat->S[i - 1];
     
    10941052    strat->S_2_R[i] = strat->S_2_R[i - 1];
    10951053  }
    1096   if (strat->lenS != NULL)
    1097     for (i = old_pos; i > new_pos; i--)
     1054  if(strat->lenS != NULL)
     1055    for(i = old_pos; i > new_pos; i--)
    10981056      strat->lenS[i] = strat->lenS[i - 1];
    1099   if (strat->lenSw != NULL)
    1100     for (i = old_pos; i > new_pos; i--)
     1057  if(strat->lenSw != NULL)
     1058    for(i = old_pos; i > new_pos; i--)
    11011059      strat->lenSw[i] = strat->lenSw[i - 1];
    11021060
     
    11061064  strat->S_2_R[new_pos] = s_2_r;
    11071065  strat->lenS[new_pos] = length;
    1108   if (strat->lenSw != NULL)
     1066  if(strat->lenSw != NULL)
    11091067    strat->lenSw[new_pos] = length_w;
    11101068  //assume(lenS_correct(strat));
    11111069}
    11121070
    1113 static void
    1114 move_backward_in_S (int old_pos, int new_pos, kStrategy strat)
     1071static void move_backward_in_S (int old_pos, int new_pos, kStrategy strat)
    11151072{
    11161073  assume (old_pos <= new_pos);
     
    11221079  assume (length == pLength (strat->S[old_pos]));
    11231080  wlen_type length_w;
    1124   if (strat->lenSw != NULL)
     1081  if(strat->lenSw != NULL)
    11251082    length_w = strat->lenSw[old_pos];
    11261083  int i;
    1127   for (i = old_pos; i < new_pos; i++)
     1084  for(i = old_pos; i < new_pos; i++)
    11281085  {
    11291086    strat->S[i] = strat->S[i + 1];
     
    11321089    strat->S_2_R[i] = strat->S_2_R[i + 1];
    11331090  }
    1134   if (strat->lenS != NULL)
    1135     for (i = old_pos; i < new_pos; i++)
     1091  if(strat->lenS != NULL)
     1092    for(i = old_pos; i < new_pos; i++)
    11361093      strat->lenS[i] = strat->lenS[i + 1];
    1137   if (strat->lenSw != NULL)
    1138     for (i = old_pos; i < new_pos; i++)
     1094  if(strat->lenSw != NULL)
     1095    for(i = old_pos; i < new_pos; i++)
    11391096      strat->lenSw[i] = strat->lenSw[i + 1];
    11401097
     
    11441101  strat->S_2_R[new_pos] = s_2_r;
    11451102  strat->lenS[new_pos] = length;
    1146   if (strat->lenSw != NULL)
     1103  if(strat->lenSw != NULL)
    11471104    strat->lenSw[new_pos] = length_w;
    11481105  //assume(lenS_correct(strat));
    11491106}
    11501107
    1151 static int *
    1152 make_connections (int from, int to, poly bound, slimgb_alg * c)
     1108static int *make_connections (int from, int to, poly bound, slimgb_alg * c)
    11531109{
    11541110  ideal I = c->S;
     
    11661122  int pos;
    11671123
    1168   while (TRUE)
    1169   {
    1170     if ((con_checked < connected_length) && (not_yet_found > 0))
     1124  while(TRUE)
     1125  {
     1126    if((con_checked < connected_length) && (not_yet_found > 0))
    11711127    {
    11721128      pos = connected[con_checked];
    1173       for (int i = 0; i < cans_length; i++)
    1174       {
    1175         if (cans[i] < 0)
    1176           continue;
    1177         //FIXME: triv. syz. does not hold on noncommutative, check it for modules
    1178         if ((has_t_rep (pos, cans[i], c))
    1179             || ((!rIsPluralRing (c->r))
    1180                 && (trivial_syzygie (pos, cans[i], bound, c))))
    1181         {
    1182           connected[connected_length] = cans[i];
    1183           connected_length++;
    1184           cans[i] = -1;
    1185           --not_yet_found;
    1186 
    1187           if (connected[connected_length - 1] == to)
    1188           {
    1189             if (connected_length < c->n)
    1190             {
    1191               connected[connected_length] = -1;
    1192             }
    1193             omfree (cans);
    1194             return connected;
    1195           }
    1196         }
     1129      for(int i = 0; i < cans_length; i++)
     1130      {
     1131        if(cans[i] < 0)
     1132          continue;
     1133        //FIXME: triv. syz. does not hold on noncommutative, check it for modules
     1134        if((has_t_rep (pos, cans[i], c))
     1135           || ((!rIsPluralRing (c->r))
     1136               && (trivial_syzygie (pos, cans[i], bound, c))))
     1137        {
     1138          connected[connected_length] = cans[i];
     1139          connected_length++;
     1140          cans[i] = -1;
     1141          --not_yet_found;
     1142
     1143          if(connected[connected_length - 1] == to)
     1144          {
     1145            if(connected_length < c->n)
     1146            {
     1147              connected[connected_length] = -1;
     1148            }
     1149            omfree (cans);
     1150            return connected;
     1151          }
     1152        }
    11971153      }
    11981154      con_checked++;
     
    12001156    else
    12011157    {
    1202       for (last_cans_pos++; last_cans_pos <= c->n; last_cans_pos++)
    1203       {
    1204         if (last_cans_pos == c->n)
    1205         {
    1206           if (connected_length < c->n)
    1207           {
    1208             connected[connected_length] = -1;
    1209           }
    1210           omfree (cans);
    1211           return connected;
    1212         }
    1213         if ((last_cans_pos == from) || (last_cans_pos == to))
    1214           continue;
    1215         if (p_LmShortDivisibleBy
    1216             (I->m[last_cans_pos], c->short_Exps[last_cans_pos], bound,
    1217              neg_bounds_short, c->r))
    1218         {
    1219           cans[cans_length] = last_cans_pos;
    1220           cans_length++;
    1221           break;
    1222         }
     1158      for(last_cans_pos++; last_cans_pos <= c->n; last_cans_pos++)
     1159      {
     1160        if(last_cans_pos == c->n)
     1161        {
     1162          if(connected_length < c->n)
     1163          {
     1164            connected[connected_length] = -1;
     1165          }
     1166          omfree (cans);
     1167          return connected;
     1168        }
     1169        if((last_cans_pos == from) || (last_cans_pos == to))
     1170          continue;
     1171        if(p_LmShortDivisibleBy
     1172           (I->m[last_cans_pos], c->short_Exps[last_cans_pos], bound,
     1173            neg_bounds_short, c->r))
     1174        {
     1175          cans[cans_length] = last_cans_pos;
     1176          cans_length++;
     1177          break;
     1178        }
    12231179      }
    12241180      not_yet_found++;
    1225       for (int i = 0; i < con_checked; i++)
    1226       {
    1227         if (has_t_rep (connected[i], last_cans_pos, c))
    1228         {
    1229           connected[connected_length] = last_cans_pos;
    1230           connected_length++;
    1231           cans[cans_length - 1] = -1;
    1232           --not_yet_found;
    1233           if (connected[connected_length - 1] == to)
    1234           {
    1235             if (connected_length < c->n)
    1236             {
    1237               connected[connected_length] = -1;
    1238             }
    1239             omfree (cans);
    1240             return connected;
    1241           }
    1242           break;
    1243         }
    1244       }
    1245     }
    1246   }
    1247   if (connected_length < c->n)
     1181      for(int i = 0; i < con_checked; i++)
     1182      {
     1183        if(has_t_rep (connected[i], last_cans_pos, c))
     1184        {
     1185          connected[connected_length] = last_cans_pos;
     1186          connected_length++;
     1187          cans[cans_length - 1] = -1;
     1188          --not_yet_found;
     1189          if(connected[connected_length - 1] == to)
     1190          {
     1191            if(connected_length < c->n)
     1192            {
     1193              connected[connected_length] = -1;
     1194            }
     1195            omfree (cans);
     1196            return connected;
     1197          }
     1198          break;
     1199        }
     1200      }
     1201    }
     1202  }
     1203  if(connected_length < c->n)
    12481204  {
    12491205    connected[connected_length] = -1;
     
    12541210
    12551211#ifdef HEAD_BIN
    1256 static inline poly
    1257 p_MoveHead (poly p, omBin b)
     1212static inline poly p_MoveHead (poly p, omBin b)
    12581213{
    12591214  poly np;
     
    12651220#endif
    12661221
    1267 static void
    1268 replace_pair (int &i, int &j, slimgb_alg * c)
    1269 {
    1270   if (i < 0)
     1222static void replace_pair (int &i, int &j, slimgb_alg * c)
     1223{
     1224  if(i < 0)
    12711225    return;
    12721226  c->soon_free = NULL;
     
    12791233  int *i_con = make_connections (i, j, lm, c);
    12801234
    1281   for (int n = 0; ((n < c->n) && (i_con[n] >= 0)); n++)
    1282   {
    1283     if (i_con[n] == j)
     1235  for(int n = 0; ((n < c->n) && (i_con[n] >= 0)); n++)
     1236  {
     1237    if(i_con[n] == j)
    12841238    {
    12851239      now_t_rep (i, j, c);
     
    13061260
    13071261  p_Delete (&lm, c->r);
    1308   if (c->T_deg_full)            //Sugar
     1262  if(c->T_deg_full)             //Sugar
    13091263  {
    13101264    int t_i = c->T_deg_full[i] - c->T_deg[i];
     
    13141268  }
    13151269
    1316   for (int m = 0; ((m < c->n) && (i_con[m] >= 0)); m++)
    1317   {
    1318     if (c->T_deg_full != NULL)
     1270  for(int m = 0; ((m < c->n) && (i_con[m] >= 0)); m++)
     1271  {
     1272    if(c->T_deg_full != NULL)
    13191273    {
    13201274      int s1 = c->T_deg_full[i_con[m]] + syz_deg - c->T_deg[i_con[m]];
    1321       if (s1 > sugar)
    1322         continue;
    1323     }
    1324     if (c->weighted_lengths[i_con[m]] < c->weighted_lengths[i])
     1275      if(s1 > sugar)
     1276        continue;
     1277    }
     1278    if(c->weighted_lengths[i_con[m]] < c->weighted_lengths[i])
    13251279      i = i_con[m];
    13261280  }
    1327   for (int m = 0; ((m < c->n) && (j_con[m] >= 0)); m++)
    1328   {
    1329     if (c->T_deg_full != NULL)
     1281  for(int m = 0; ((m < c->n) && (j_con[m] >= 0)); m++)
     1282  {
     1283    if(c->T_deg_full != NULL)
    13301284    {
    13311285      int s1 = c->T_deg_full[j_con[m]] + syz_deg - c->T_deg[j_con[m]];
    1332       if (s1 > sugar)
    1333         continue;
    1334     }
    1335     if (c->weighted_lengths[j_con[m]] < c->weighted_lengths[j])
     1286      if(s1 > sugar)
     1287        continue;
     1288    }
     1289    if(c->weighted_lengths[j_con[m]] < c->weighted_lengths[j])
    13361290      j = j_con[m];
    13371291  }
     
    13431297}
    13441298
    1345 static void
    1346 add_later (poly p, const char *prot, slimgb_alg * c)
     1299static void add_later (poly p, const char *prot, slimgb_alg * c)
    13471300{
    13481301  int i = 0;
    13491302  //check, if it is already in the queue
    13501303
    1351   while (c->add_later->m[i] != NULL)
    1352   {
    1353     if (p_LmEqual (c->add_later->m[i], p, c->r))
     1304  while(c->add_later->m[i] != NULL)
     1305  {
     1306    if(p_LmEqual (c->add_later->m[i], p, c->r))
    13541307      return;
    13551308    i++;
    13561309  }
    1357   if (TEST_OPT_PROT)
     1310  if(TEST_OPT_PROT)
    13581311    PrintS (prot);
    13591312  c->add_later->m[i] = p;
    13601313}
    13611314
    1362 static int
    1363 simple_posInS (kStrategy strat, poly p, int len, wlen_type wlen)
    1364 {
    1365   if (strat->sl == -1)
     1315static int simple_posInS (kStrategy strat, poly p, int len, wlen_type wlen)
     1316{
     1317  if(strat->sl == -1)
    13661318    return 0;
    1367   if (strat->lenSw)
     1319  if(strat->lenSw)
    13681320    return pos_helper (strat, p, (wlen_type) wlen, (wlen_set) strat->lenSw,
    1369                        strat->S);
     1321                       strat->S);
    13701322  return pos_helper (strat, p, len, strat->lenS, strat->S);
    13711323}
     
    13791331{
    13801332  assume (p_sev == pGetShortExpVector (p));
    1381   if (!pLmShortDivisibleBy (p, p_sev, strat->S[*at], ~strat->sevS[*at]))
     1333  if(!pLmShortDivisibleBy (p, p_sev, strat->S[*at], ~strat->sevS[*at]))
    13821334    return;
    1383   if (l >= strat->lenS[*at])
     1335  if(l >= strat->lenS[*at])
    13841336    return;
    1385   if (TEST_OPT_PROT)
     1337  if(TEST_OPT_PROT)
    13861338    PrintS ("!");
    13871339  mflush ();
     
    13931345}
    13941346
    1395 static int
    1396 iq_crit (const void *ap, const void *bp)
     1347static int iq_crit (const void *ap, const void *bp)
    13971348{
    13981349  sorted_pair_node *a = *((sorted_pair_node **) ap);
     
    14011352  assume (b->i > b->j);
    14021353
    1403   if (a->deg < b->deg)
     1354  if(a->deg < b->deg)
    14041355    return -1;
    1405   if (a->deg > b->deg)
     1356  if(a->deg > b->deg)
    14061357    return 1;
    14071358  int comp = pLmCmp (a->lcm_of_lm, b->lcm_of_lm);
    1408   if (comp != 0)
     1359  if(comp != 0)
    14091360    return comp;
    1410   if (a->expected_length < b->expected_length)
     1361  if(a->expected_length < b->expected_length)
    14111362    return -1;
    1412   if (a->expected_length > b->expected_length)
     1363  if(a->expected_length > b->expected_length)
    14131364    return 1;
    1414   if (a->j > b->j)
     1365  if(a->j > b->j)
    14151366    return 1;
    1416   if (a->j < b->j)
     1367  if(a->j < b->j)
    14171368    return -1;
    14181369  return 0;
    14191370}
    14201371
    1421 static wlen_type
    1422 coeff_mult_size_estimate (int s1, int s2, ring r)
    1423 {
    1424   if (rField_is_Q (r))
     1372static wlen_type coeff_mult_size_estimate (int s1, int s2, ring r)
     1373{
     1374  if(rField_is_Q (r))
    14251375    return s1 + s2;
    14261376  else
     
    14281378}
    14291379
    1430 static wlen_type
    1431 pair_weighted_length (int i, int j, slimgb_alg * c)
    1432 {
    1433   if ((c->isDifficultField) && (c->eliminationProblem))
     1380static wlen_type pair_weighted_length (int i, int j, slimgb_alg * c)
     1381{
     1382  if((c->isDifficultField) && (c->eliminationProblem))
    14341383  {
    14351384    int c1 = slim_nsize (p_GetCoeff (c->S->m[i], c->r), c->r);
     
    14481397
    14491398  }
    1450   if (c->isDifficultField)
     1399  if(c->isDifficultField)
    14511400  {
    14521401    //int cs=slim_nsize(p_GetCoeff(c->S->m[i],c->r),c->r)+
    14531402    //    slim_nsize(p_GetCoeff(c->S->m[j],c->r),c->r);
    1454     if (!(TEST_V_COEFSTRAT))
     1403    if(!(TEST_V_COEFSTRAT))
    14551404    {
    14561405      wlen_type cs =
    1457         coeff_mult_size_estimate (slim_nsize
    1458                                   (p_GetCoeff (c->S->m[i], c->r), c->r),
    1459                                   slim_nsize (p_GetCoeff (c->S->m[j], c->r),
    1460                                               c->r), c->r);
     1406        coeff_mult_size_estimate (slim_nsize
     1407                                  (p_GetCoeff (c->S->m[i], c->r), c->r),
     1408                                  slim_nsize (p_GetCoeff (c->S->m[j], c->r),
     1409                                              c->r), c->r);
    14611410      return (wlen_type) (c->lengths[i] + c->lengths[j] - 2) * (wlen_type) cs;
    14621411    }
     
    14651414
    14661415      wlen_type cs =
    1467         coeff_mult_size_estimate (slim_nsize
    1468                                   (p_GetCoeff (c->S->m[i], c->r), c->r),
    1469                                   slim_nsize (p_GetCoeff (c->S->m[j], c->r),
    1470                                               c->r), c->r);
     1416        coeff_mult_size_estimate (slim_nsize
     1417                                  (p_GetCoeff (c->S->m[i], c->r), c->r),
     1418                                  slim_nsize (p_GetCoeff (c->S->m[j], c->r),
     1419                                              c->r), c->r);
    14711420      cs *= cs;
    14721421      return (wlen_type) (c->lengths[i] + c->lengths[j] - 2) * (wlen_type) cs;
    14731422    }
    14741423  }
    1475   if (c->eliminationProblem)
     1424  if(c->eliminationProblem)
    14761425  {
    14771426
     
    14821431}
    14831432
    1484 sorted_pair_node **
    1485 add_to_basis_ideal_quotient (poly h, slimgb_alg * c, int *ip)
     1433sorted_pair_node **add_to_basis_ideal_quotient (poly h, slimgb_alg * c,
     1434                                                int *ip)
    14861435{
    14871436  p_Test (h, c->r);
    14881437  assume (h != NULL);
    14891438  poly got = gcd_of_terms (h, c->r);
    1490   if ((got != NULL) && (TEST_V_UPTORADICAL))
     1439  if((got != NULL) && (TEST_V_UPTORADICAL))
    14911440  {
    14921441    poly copy = p_Copy (got, c->r);
    14931442    //p_wrp(got,c->r);
    14941443    BOOLEAN changed = monomial_root (got, c->r);
    1495     if (changed)
     1444    if(changed)
    14961445    {
    14971446      poly div_by = pDivide (copy, got);
    14981447      poly iter = h;
    1499       while (iter)
    1500       {
    1501         pExpVectorSub (iter, div_by);
    1502         pIter (iter);
     1448      while(iter)
     1449      {
     1450        pExpVectorSub (iter, div_by);
     1451        pIter (iter);
    15031452      }
    15041453      p_Delete (&div_by, c->r);
     
    15191468    (sorted_pair_node **) omalloc (sizeof (sorted_pair_node *) * i);
    15201469  int spc = 0;
    1521   if (c->n > c->array_lengths)
     1470  if(c->n > c->array_lengths)
    15221471  {
    15231472    c->array_lengths = c->array_lengths * 2;
     
    15421491  }
    15431492  pEnlargeSet (&c->S->m, c->n - 1, 1);
    1544   if (c->T_deg_full)
     1493  if(c->T_deg_full)
    15451494    ENLARGE (c->T_deg_full, int);
    15461495  sugar = c->T_deg[i] = c->pTotaldegree (h);
    1547   if (c->T_deg_full)
     1496  if(c->T_deg_full)
    15481497  {
    15491498    sugar = c->T_deg_full[i] = c->pTotaldegree_full (h);
     
    15591508  //necessary for correct weighted length
    15601509
    1561   if (!rField_is_Zp (c->r))
     1510  if(!rField_is_Zp (c->r))
    15621511  {
    15631512    p_Cleardenom (h, c->r);
     
    15791528
    15801529#else
    1581   if (i > 0)
     1530  if(i > 0)
    15821531    c->states[i] = (char *) omalloc (i * sizeof (char));
    15831532  else
     
    15901539
    15911540#undef ENLARGE
    1592   if (p_GetComp (h, currRing) <= c->syz_comp)
    1593   {
    1594     for (j = 0; j < i; j++)
     1541  if(p_GetComp (h, currRing) <= c->syz_comp)
     1542  {
     1543    for(j = 0; j < i; j++)
    15951544    {
    15961545
     
    16001549#endif
    16011550      assume (p_LmDivisibleBy (c->S->m[i], c->S->m[j], c->r) ==
    1602               p_LmShortDivisibleBy (c->S->m[i], c->short_Exps[i], c->S->m[j],
    1603                                     ~(c->short_Exps[j]), c->r));
    1604 
    1605       if (_p_GetComp (c->S->m[i], c->r) != _p_GetComp (c->S->m[j], c->r))
    1606       {
    1607         //c->states[i][j]=UNCALCULATED;
    1608         //WARNUNG: be careful
    1609         continue;
    1610       }
    1611       else if ((!c->nc) && (c->lengths[i] == 1) && (c->lengths[j] == 1))
    1612       {
    1613         c->states[i][j] = HASTREP;
    1614       }
    1615       else if (((!c->nc) || (c->is_homog && rIsSCA (c->r)))
    1616                && (pHasNotCF (c->S->m[i], c->S->m[j])))
     1551              p_LmShortDivisibleBy (c->S->m[i], c->short_Exps[i], c->S->m[j],
     1552                                    ~(c->short_Exps[j]), c->r));
     1553
     1554      if(_p_GetComp (c->S->m[i], c->r) != _p_GetComp (c->S->m[j], c->r))
     1555      {
     1556        //c->states[i][j]=UNCALCULATED;
     1557        //WARNUNG: be careful
     1558        continue;
     1559      }
     1560      else if((!c->nc) && (c->lengths[i] == 1) && (c->lengths[j] == 1))
     1561      {
     1562        c->states[i][j] = HASTREP;
     1563      }
     1564      else if(((!c->nc) || (c->is_homog && rIsSCA (c->r)))
     1565              && (pHasNotCF (c->S->m[i], c->S->m[j])))
    16171566//     else if ((!(c->nc)) &&  (pHasNotCF(c->S->m[i],c->S->m[j])))
    16181567      {
    1619         c->easy_product_crit++;
    1620         c->states[i][j] = HASTREP;
    1621         continue;
     1568        c->easy_product_crit++;
     1569        c->states[i][j] = HASTREP;
     1570        continue;
    16221571      }
    16231572      else
    1624         if (extended_product_criterion
    1625             (c->S->m[i], c->gcd_of_terms[i], c->S->m[j], c->gcd_of_terms[j],
    1626              c))
    1627       {
    1628         c->states[i][j] = HASTREP;
    1629         c->extended_product_crit++;
    1630         //PrintS("E");
     1573        if(extended_product_criterion
     1574           (c->S->m[i], c->gcd_of_terms[i], c->S->m[j], c->gcd_of_terms[j],
     1575            c))
     1576      {
     1577        c->states[i][j] = HASTREP;
     1578        c->extended_product_crit++;
     1579        //PrintS("E");
    16311580      }
    16321581      //  if (c->states[i][j]==UNCALCULATED)
    16331582      //  {
    16341583
    1635       if ((TEST_V_FINDMONOM) && (!c->nc))
    1636       {
    1637         //PrintS("COMMU");
    1638         //  if (c->lengths[i]==c->lengths[j])
    1639         //  {
     1584      if((TEST_V_FINDMONOM) && (!c->nc))
     1585      {
     1586        //PrintS("COMMU");
     1587        //  if (c->lengths[i]==c->lengths[j])
     1588        //  {
    16401589//             poly short_s=ksCreateShortSpoly(c->S->m[i],c->S->m[j],c->r);
    16411590//             if (short_s==NULL)
     
    16481597//             }
    16491598//         }
    1650         if (c->lengths[i] + c->lengths[j] == 3)
    1651         {
    1652 
    1653 
    1654           poly short_s = ksCreateShortSpoly (c->S->m[i], c->S->m[j], c->r);
    1655           if (short_s == NULL)
    1656           {
    1657             c->states[i][j] = HASTREP;
    1658           }
    1659           else
    1660           {
    1661             assume (pLength (short_s) == 1);
    1662             if (TEST_V_UPTORADICAL)
    1663               monomial_root (short_s, c->r);
    1664             int iS =
    1665               kFindDivisibleByInS_easy (c->strat, short_s,
    1666                                         p_GetShortExpVector (short_s, c->r));
    1667             if (iS < 0)
    1668             {
    1669               //PrintS("N");
    1670               if (TRUE)
    1671               {
    1672                 c->states[i][j] = HASTREP;
    1673                 add_later (short_s, "N", c);
    1674               }
    1675               else
    1676                 p_Delete (&short_s, currRing);
    1677             }
    1678             else
    1679             {
    1680               if (c->strat->lenS[iS] > 1)
    1681               {
    1682                 //PrintS("O");
    1683                 if (TRUE)
    1684                 {
    1685                   c->states[i][j] = HASTREP;
    1686                   add_later (short_s, "O", c);
    1687                 }
    1688                 else
    1689                   p_Delete (&short_s, currRing);
    1690               }
    1691               else
    1692                 p_Delete (&short_s, currRing);
    1693               c->states[i][j] = HASTREP;
    1694             }
    1695 
    1696 
    1697           }
    1698         }
     1599        if(c->lengths[i] + c->lengths[j] == 3)
     1600        {
     1601
     1602
     1603          poly short_s = ksCreateShortSpoly (c->S->m[i], c->S->m[j], c->r);
     1604          if(short_s == NULL)
     1605          {
     1606            c->states[i][j] = HASTREP;
     1607          }
     1608          else
     1609          {
     1610            assume (pLength (short_s) == 1);
     1611            if(TEST_V_UPTORADICAL)
     1612              monomial_root (short_s, c->r);
     1613            int iS = kFindDivisibleByInS_easy (c->strat, short_s,
     1614                                               p_GetShortExpVector (short_s,
     1615                                                                    c->r));
     1616            if(iS < 0)
     1617            {
     1618              //PrintS("N");
     1619              if(TRUE)
     1620              {
     1621                c->states[i][j] = HASTREP;
     1622                add_later (short_s, "N", c);
     1623              }
     1624              else
     1625                p_Delete (&short_s, currRing);
     1626            }
     1627            else
     1628            {
     1629              if(c->strat->lenS[iS] > 1)
     1630              {
     1631                //PrintS("O");
     1632                if(TRUE)
     1633                {
     1634                  c->states[i][j] = HASTREP;
     1635                  add_later (short_s, "O", c);
     1636                }
     1637                else
     1638                  p_Delete (&short_s, currRing);
     1639              }
     1640              else
     1641                p_Delete (&short_s, currRing);
     1642              c->states[i][j] = HASTREP;
     1643            }
     1644
     1645
     1646          }
     1647        }
    16991648      }
    17001649      //    if (short_s)
    17011650      //    {
    17021651      assume (spc <= j);
    1703       sorted_pair_node *s = c->tmp_spn[spc];    //(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
     1652      sorted_pair_node *s = c->tmp_spn[spc];    //(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
    17041653      s->i = si_max (i, j);
    17051654      s->j = si_min (i, j);
    17061655      assume (s->j == j);
    1707       s->expected_length = pair_weighted_length (i, j, c);      //c->lengths[i]+c->lengths[j]-2;
    1708 
    1709       poly lm = c->tmp_pair_lm[spc];    //=pOne_Special();
     1656      s->expected_length = pair_weighted_length (i, j, c);      //c->lengths[i]+c->lengths[j]-2;
     1657
     1658      poly lm = c->tmp_pair_lm[spc];    //=pOne_Special();
    17101659
    17111660      pLcm (c->S->m[i], c->S->m[j], lm);
     
    17141663      s->deg = c->pTotaldegree (lm);
    17151664
    1716       if (c->T_deg_full)        //Sugar
    1717       {
    1718         int t_i = c->T_deg_full[s->i] - c->T_deg[s->i];
    1719         int t_j = c->T_deg_full[s->j] - c->T_deg[s->j];
    1720         s->deg += si_max (t_i, t_j);
    1721         //Print("\n max: %d\n",max(t_i,t_j));
     1665      if(c->T_deg_full)         //Sugar
     1666      {
     1667        int t_i = c->T_deg_full[s->i] - c->T_deg[s->i];
     1668        int t_j = c->T_deg_full[s->j] - c->T_deg[s->j];
     1669        s->deg += si_max (t_i, t_j);
     1670        //Print("\n max: %d\n",max(t_i,t_j));
    17221671      }
    17231672      p_Test (lm, c->r);
     
    17341683      //}
    17351684    }
    1736   }                             //if syz_comp end
     1685  }                             //if syz_comp end
    17371686
    17381687  assume (spc <= i);
     
    17441693  int spc_final = 0;
    17451694  j = 0;
    1746   while (j < spc)
     1695  while(j < spc)
    17471696  {
    17481697    int lower = j;
    17491698    int upper;
    17501699    BOOLEAN has = FALSE;
    1751     for (upper = lower + 1; upper < spc; upper++)
    1752     {
    1753       if (!pLmEqual (nodes[lower]->lcm_of_lm, nodes[upper]->lcm_of_lm))
    1754       {
    1755         break;
    1756       }
    1757       if (has_t_rep (nodes[upper]->i, nodes[upper]->j, c))
    1758         has = TRUE;
     1700    for(upper = lower + 1; upper < spc; upper++)
     1701    {
     1702      if(!pLmEqual (nodes[lower]->lcm_of_lm, nodes[upper]->lcm_of_lm))
     1703      {
     1704        break;
     1705      }
     1706      if(has_t_rep (nodes[upper]->i, nodes[upper]->j, c))
     1707        has = TRUE;
    17591708    }
    17601709    upper = upper - 1;
    17611710    int z;
    17621711    assume (spc_final <= j);
    1763     for (z = 0; z < spc_final; z++)
    1764     {
    1765       if (p_LmDivisibleBy
    1766           (nodes_final[z]->lcm_of_lm, nodes[lower]->lcm_of_lm, c->r))
    1767       {
    1768         has = TRUE;
    1769         break;
    1770       }
    1771     }
    1772 
    1773     if (has)
    1774     {
    1775       for (; lower <= upper; lower++)
    1776       {
    1777         //free_sorted_pair_node(nodes[lower],c->r);
    1778         //omfree(nodes[lower]);
    1779         nodes[lower] = NULL;
     1712    for(z = 0; z < spc_final; z++)
     1713    {
     1714      if(p_LmDivisibleBy
     1715         (nodes_final[z]->lcm_of_lm, nodes[lower]->lcm_of_lm, c->r))
     1716      {
     1717        has = TRUE;
     1718        break;
     1719      }
     1720    }
     1721
     1722    if(has)
     1723    {
     1724      for(; lower <= upper; lower++)
     1725      {
     1726        //free_sorted_pair_node(nodes[lower],c->r);
     1727        //omfree(nodes[lower]);
     1728        nodes[lower] = NULL;
    17801729      }
    17811730      j = upper + 1;
     
    17871736      nodes[lower]->lcm_of_lm = pCopy (nodes[lower]->lcm_of_lm);
    17881737      assume (_p_GetComp (c->S->m[nodes[lower]->i], c->r) ==
    1789               _p_GetComp (c->S->m[nodes[lower]->j], c->r));
     1738              _p_GetComp (c->S->m[nodes[lower]->j], c->r));
    17901739      nodes_final[spc_final] =
    1791         (sorted_pair_node *) omalloc (sizeof (sorted_pair_node));
     1740        (sorted_pair_node *) omalloc (sizeof (sorted_pair_node));
    17921741
    17931742      *(nodes_final[spc_final++]) = *(nodes[lower]);
    17941743      //c->tmp_spn[nodes[lower]->j]=(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
    17951744      nodes[lower] = NULL;
    1796       for (lower = lower + 1; lower <= upper; lower++)
    1797       {
    1798         //  free_sorted_pair_node(nodes[lower],c->r);
    1799         //omfree(nodes[lower]);
    1800         nodes[lower] = NULL;
     1745      for(lower = lower + 1; lower <= upper; lower++)
     1746      {
     1747        //  free_sorted_pair_node(nodes[lower],c->r);
     1748        //omfree(nodes[lower]);
     1749        nodes[lower] = NULL;
    18011750      }
    18021751      j = upper + 1;
     
    18131762  add_to_reductors (c, h, c->lengths[c->n - 1], ecart, TRUE);
    18141763  //i=posInS(c->strat,c->strat->sl,h,0 ecart);
    1815   if (!(c->nc))
    1816   {
    1817     if (c->lengths[c->n - 1] == 1)
     1764  if(!(c->nc))
     1765  {
     1766    if(c->lengths[c->n - 1] == 1)
    18181767      shorten_tails (c, c->S->m[c->n - 1]);
    18191768  }
     
    18221771  //for(i=c->strat->sl; i>0;i--)
    18231772  //  if(c->strat->lenS[i]<c->strat->lenS[i-1]) printf("fehler bei %d\n",i);
    1824   if (c->Rcounter > 50)
     1773  if(c->Rcounter > 50)
    18251774  {
    18261775    c->Rcounter = 0;
     
    18311780  // for SCA:
    18321781  // here write at the end of nodes_final[spc_final,...,spc_final+lmdeg-1]
    1833   if (rIsSCA (c->r))
     1782  if(rIsSCA (c->r))
    18341783  {
    18351784    const poly pNext = pNext (h);
    18361785
    1837     if (pNext != NULL)
     1786    if(pNext != NULL)
    18381787    {
    18391788      // for additional polynomials
     
    18411790      const unsigned int m_iLastAltVar = scaLastAltVar (c->r);
    18421791
    1843       int N =                   // c->r->N;
    1844         m_iLastAltVar - m_iFirstAltVar + 1;     // should be enough
     1792      int N =                   // c->r->N;
     1793        m_iLastAltVar - m_iFirstAltVar + 1;     // should be enough
    18451794      // TODO: but we may also use got = gcd({m}_{m\in f}))!
    18461795
    1847       poly *array_arg = (poly *) omalloc (N * sizeof (poly));   // !
     1796      poly *array_arg = (poly *) omalloc (N * sizeof (poly));   // !
    18481797      int j = 0;
    18491798
    18501799
    1851       for (unsigned short v = m_iFirstAltVar; v <= m_iLastAltVar; v++)
    1852         // for all x_v | Ann(lm(h))
    1853         if (p_GetExp (h, v, c->r))      // TODO: use 'got' here!
    1854         {
    1855           assume (p_GetExp (h, v, c->r) == 1);
    1856 
    1857           poly p = sca_pp_Mult_xi_pp (v, pNext, c->r);  // x_v * h;
    1858 
    1859           if (p != NULL)        // if (x_v * h != 0)
    1860             array_arg[j++] = p;
    1861         }                       // for all x_v | Ann(lm(h))
     1800      for(unsigned short v = m_iFirstAltVar; v <= m_iLastAltVar; v++)
     1801        // for all x_v | Ann(lm(h))
     1802        if(p_GetExp (h, v, c->r))       // TODO: use 'got' here!
     1803        {
     1804          assume (p_GetExp (h, v, c->r) == 1);
     1805
     1806          poly p = sca_pp_Mult_xi_pp (v, pNext, c->r);  // x_v * h;
     1807
     1808          if(p != NULL)         // if (x_v * h != 0)
     1809            array_arg[j++] = p;
     1810        }                       // for all x_v | Ann(lm(h))
    18621811
    18631812      c->introduceDelayedPairs (array_arg, j);
    18641813
    1865       omfree (array_arg);       // !!!
     1814      omfree (array_arg);       // !!!
    18661815    }
    18671816//     PrintS("Saturation - done!!!\n");
     
    18701819
    18711820
    1872   if (!ip)
     1821  if(!ip)
    18731822  {
    18741823    qsort (nodes_final, spc_final, sizeof (sorted_pair_node *),
    1875            tgb_pair_better_gen2);
     1824           tgb_pair_better_gen2);
    18761825
    18771826
     
    18891838}
    18901839
    1891 static poly
    1892 redNF2 (poly h, slimgb_alg * c, int &len, number & m, int n)
     1840static poly redNF2 (poly h, slimgb_alg * c, int &len, number & m, int n)
    18931841{
    18941842  m = nInit (1);
    1895   if (h == NULL)
     1843  if(h == NULL)
    18961844    return NULL;
    18971845
    18981846  assume (len == pLength (h));
    18991847  kStrategy strat = c->strat;
    1900   if (0 > strat->sl)
     1848  if(0 > strat->sl)
    19011849  {
    19021850    return h;
     
    19201868    j = kFindDivisibleByInS_easy (strat, P.p, P.sev);
    19211869    //j=kFindDivisibleByInS(strat,&dummy,&P);
    1922     if ((j >= 0) && ((!n) ||
    1923                      ((strat->lenS[j] <= n) &&
    1924                       ((strat->lenSw == NULL) || (strat->lenSw[j] <= n)))))
     1870    if((j >= 0) && ((!n) ||
     1871                    ((strat->lenS[j] <= n) &&
     1872                     ((strat->lenSw == NULL) || (strat->lenSw[j] <= n)))))
    19251873    {
    19261874      nNormalize (pGetCoeff (P.p));
    19271875#ifdef KDEBUG
    1928       if (TEST_OPT_DEBUG)
    1929       {
    1930         PrintS ("red:");
    1931         wrp (h);
    1932         PrintS (" with ");
    1933         wrp (strat->S[j]);
     1876      if(TEST_OPT_DEBUG)
     1877      {
     1878        PrintS ("red:");
     1879        wrp (h);
     1880        PrintS (" with ");
     1881        wrp (strat->S[j]);
    19341882      }
    19351883#endif
    19361884
    19371885      number coef = kBucketPolyRed (P.bucket, strat->S[j],
    1938                                     strat->lenS[j] /*pLength(strat->S[j]) */ ,
    1939                                     strat->kNoether);
     1886                                    strat->lenS[j] /*pLength(strat->S[j]) */ ,
     1887                                    strat->kNoether);
    19401888      number m2 = nMult (m, coef);
    19411889      nDelete (&m);
     
    19441892      h = kBucketGetLm (P.bucket);
    19451893
    1946       if (h == NULL)
    1947       {
    1948         len = 0;
    1949         kBucketDestroy (&P.bucket);
    1950         return NULL;
     1894      if(h == NULL)
     1895      {
     1896        len = 0;
     1897        kBucketDestroy (&P.bucket);
     1898        return NULL;
    19511899      }
    19521900      P.p = h;
     
    19541902      P.SetShortExpVector ();
    19551903#ifdef KDEBUG
    1956       if (TEST_OPT_DEBUG)
    1957       {
    1958         PrintS ("\nto:");
    1959         wrp (h);
    1960         PrintLn ();
     1904      if(TEST_OPT_DEBUG)
     1905      {
     1906        PrintS ("\nto:");
     1907        wrp (h);
     1908        PrintLn ();
    19611909      }
    19621910#endif
     
    19731921}
    19741922
    1975 static poly
    1976 redTailShort (poly h, kStrategy strat)
    1977 {
    1978   if (h == NULL)
    1979     return NULL;                //n_Init(1,currRing);
    1980   if (TEST_V_MODPSOLVSB)
     1923static poly redTailShort (poly h, kStrategy strat)
     1924{
     1925  if(h == NULL)
     1926    return NULL;                //n_Init(1,currRing);
     1927  if(TEST_V_MODPSOLVSB)
    19811928  {
    19821929    bit_reduce (pNext (h), strat->tailRing);
     
    19841931  int i;
    19851932  int len = pLength (h);
    1986   for (i = 0; i <= strat->sl; i++)
    1987   {
    1988     if ((strat->lenS[i] > 2)
    1989         || ((strat->lenSw != NULL) && (strat->lenSw[i] > 2)))
     1933  for(i = 0; i <= strat->sl; i++)
     1934  {
     1935    if((strat->lenS[i] > 2)
     1936       || ((strat->lenSw != NULL) && (strat->lenSw[i] > 2)))
    19901937      break;
    19911938  }
     
    19931940}
    19941941
    1995 static void
    1996 line_of_extended_prod (int fixpos, slimgb_alg * c)
    1997 {
    1998   if (c->gcd_of_terms[fixpos] == NULL)
     1942static void line_of_extended_prod (int fixpos, slimgb_alg * c)
     1943{
     1944  if(c->gcd_of_terms[fixpos] == NULL)
    19991945  {
    20001946    c->gcd_of_terms[fixpos] = gcd_of_terms (c->S->m[fixpos], c->r);
    2001     if (c->gcd_of_terms[fixpos])
     1947    if(c->gcd_of_terms[fixpos])
    20021948    {
    20031949      int i;
    2004       for (i = 0; i < fixpos; i++)
    2005         if ((c->states[fixpos][i] != HASTREP)
    2006             &&
    2007             (extended_product_criterion
    2008              (c->S->m[fixpos], c->gcd_of_terms[fixpos], c->S->m[i],
    2009               c->gcd_of_terms[i], c)))
    2010         {
    2011           c->states[fixpos][i] = HASTREP;
    2012           c->extended_product_crit++;
    2013         }
    2014       for (i = fixpos + 1; i < c->n; i++)
    2015         if ((c->states[i][fixpos] != HASTREP)
    2016             &&
    2017             (extended_product_criterion
    2018              (c->S->m[fixpos], c->gcd_of_terms[fixpos], c->S->m[i],
    2019               c->gcd_of_terms[i], c)))
    2020         {
    2021           c->states[i][fixpos] = HASTREP;
    2022           c->extended_product_crit++;
    2023         }
    2024     }
    2025   }
    2026 }
    2027 
    2028 static void
    2029 c_S_element_changed_hook (int pos, slimgb_alg * c)
     1950      for(i = 0; i < fixpos; i++)
     1951        if((c->states[fixpos][i] != HASTREP)
     1952           &&
     1953           (extended_product_criterion
     1954            (c->S->m[fixpos], c->gcd_of_terms[fixpos], c->S->m[i],
     1955             c->gcd_of_terms[i], c)))
     1956        {
     1957          c->states[fixpos][i] = HASTREP;
     1958          c->extended_product_crit++;
     1959        }
     1960      for(i = fixpos + 1; i < c->n; i++)
     1961        if((c->states[i][fixpos] != HASTREP)
     1962           &&
     1963           (extended_product_criterion
     1964            (c->S->m[fixpos], c->gcd_of_terms[fixpos], c->S->m[i],
     1965             c->gcd_of_terms[i], c)))
     1966        {
     1967          c->states[i][fixpos] = HASTREP;
     1968          c->extended_product_crit++;
     1969        }
     1970    }
     1971  }
     1972}
     1973
     1974static void c_S_element_changed_hook (int pos, slimgb_alg * c)
    20301975{
    20311976  length_one_crit (c, pos, c->lengths[pos]);
    2032   if (!c->nc)
     1977  if(!c->nc)
    20331978    line_of_extended_prod (pos, c);
    20341979}
     
    20411986  poly_tree_node *r;
    20421987  int n;
    2043     poly_tree_node (int sn):l (NULL), r (NULL), n (sn)
     1988  poly_tree_node (int sn):l (NULL), r (NULL), n (sn)
    20441989  {
    20451990  }
     
    20511996  int n;
    20521997  int get_n (poly p);
    2053     exp_number_builder ():top_level (0), n (0)
     1998  exp_number_builder ():top_level (0), n (0)
    20541999  {
    20552000  }
    20562001};
    2057 int
    2058 exp_number_builder::get_n (poly p)
     2002int exp_number_builder::get_n (poly p)
    20592003{
    20602004  poly_tree_node **node = &top_level;
    2061   while (*node != NULL)
     2005  while(*node != NULL)
    20622006  {
    20632007    int c = pLmCmp (p, (*node)->p);
    2064     if (c == 0)
     2008    if(c == 0)
    20652009      return (*node)->n;
    2066     if (c == -1)
     2010    if(c == -1)
    20672011      node = &((*node)->r);
    20682012    else
     
    20872031
    20882032//! obsolete
    2089 void
    2090 t2ippa_rec (poly * ip, int *ia, poly_tree_node * k, int &offset)
    2091 {
    2092   if (!k)
     2033void t2ippa_rec (poly * ip, int *ia, poly_tree_node * k, int &offset)
     2034{
     2035  if(!k)
    20932036    return;
    20942037  t2ippa_rec (ip, ia, k->l, offset);
     
    21022045
    21032046//! obsolete
    2104 void
    2105 t2ippa (poly * ip, int *ia, exp_number_builder & e)
     2047void t2ippa (poly * ip, int *ia, exp_number_builder & e)
    21062048{
    21072049
     
    21102052}
    21112053
    2112 int
    2113 anti_poly_order (const void *a, const void *b)
     2054int anti_poly_order (const void *a, const void *b)
    21142055{
    21152056  return -pLmCmp (((int_poly_pair *) a)->p, ((int_poly_pair *) b)->p);
    21162057}
    21172058
    2118 BOOLEAN
    2119 is_valid_ro (red_object & ro)
     2059BOOLEAN is_valid_ro (red_object & ro)
    21202060{
    21212061  red_object r2 = ro;
    21222062  ro.validate ();
    2123   if ((r2.p != ro.p) || (r2.sev != ro.sev))
     2063  if((r2.p != ro.p) || (r2.sev != ro.sev))
    21242064    return FALSE;
    21252065  return TRUE;
    21262066}
    21272067
    2128 int
    2129 terms_sort_crit (const void *a, const void *b)
     2068int terms_sort_crit (const void *a, const void *b)
    21302069{
    21312070  return -pLmCmp (*((poly *) a), *((poly *) b));
    21322071}
    21332072
    2134 #if 0                           // currently unused
    2135 static void
    2136 unify_terms (poly * terms, int &sum)
    2137 {
    2138   if (sum == 0)
     2073#if 0                           // currently unused
     2074static void unify_terms (poly * terms, int &sum)
     2075{
     2076  if(sum == 0)
    21392077    return;
    21402078  int last = 0;
    21412079  int curr = 1;
    2142   while (curr < sum)
    2143   {
    2144     if (!(pLmEqual (terms[curr], terms[last])))
     2080  while(curr < sum)
     2081  {
     2082    if(!(pLmEqual (terms[curr], terms[last])))
    21452083    {
    21462084      terms[++last] = terms[curr];
     
    21512089}
    21522090#endif
    2153 #if 0                           // currently unused
     2091#if 0                           // currently unused
    21542092static void
    21552093export_mat (number * number_array, int pn, int tn, const char *format_str,
    2156             int mat_nr)
     2094            int mat_nr)
    21572095{
    21582096  char matname[20];
     
    21612099  int i, j;
    21622100  fprintf (out, "mat=[\n");
    2163   for (i = 0; i < pn; i++)
     2101  for(i = 0; i < pn; i++)
    21642102  {
    21652103    fprintf (out, "[\n");
    2166     for (j = 0; j < tn; j++)
    2167     {
    2168       if (j > 0)
    2169       {
    2170         fprintf (out, ", ");
     2104    for(j = 0; j < tn; j++)
     2105    {
     2106      if(j > 0)
     2107      {
     2108        fprintf (out, ", ");
    21712109      }
    21722110      fprintf (out, "%i", npInt (number_array[i * tn + j], currRing));
    21732111    }
    2174     if (i < pn - 1)
     2112    if(i < pn - 1)
    21752113      fprintf (out, "],\n");
    21762114    else
     
    21882126static void
    21892127linalg_step_modp (poly * p, poly * p_out, int &pn, poly * terms, int tn,
    2190                   slimgb_alg * c)
     2128                  slimgb_alg * c)
    21912129{
    21922130  static int export_n = 0;
     
    21942132  assume (rField_is_Zp (c->r));
    21952133  //I don't do deletes, copies of number_types ...
    2196   const number_type zero = 0;   //npInit(0);
     2134  const number_type zero = 0;   //npInit(0);
    21972135  int array_size = pn * tn;
    21982136  number_type *number_array =
    21992137    (number_type *) omalloc (pn * tn * sizeof (number_type));
    22002138  int i;
    2201   for (i = 0; i < array_size; i++)
     2139  for(i = 0; i < array_size; i++)
    22022140  {
    22032141    number_array[i] = zero;
    22042142  }
    2205   for (i = 0; i < pn; i++)
     2143  for(i = 0; i < pn; i++)
    22062144  {
    22072145    poly h = p[i];
     
    22182156  int act_row = 0;
    22192157  int p_pos = 0;
    2220   for (i = 0; i < pn; i++)
     2158  for(i = 0; i < pn; i++)
    22212159  {
    22222160    poly h = NULL;
     
    22262164    h = row_to_poly (row, terms, tn, c->r);
    22272165
    2228     if (h != NULL)
     2166    if(h != NULL)
    22292167    {
    22302168      p_out[p_pos++] = h;
     
    22332171  pn = p_pos;
    22342172  //assert(p_pos==rank)
    2235   while (p_pos < pn)
     2173  while(p_pos < pn)
    22362174  {
    22372175    p_out[p_pos++] = NULL;
     
    22432181#endif
    22442182#endif
    2245 static void
    2246 mass_add (poly * p, int pn, slimgb_alg * c)
     2183static void mass_add (poly * p, int pn, slimgb_alg * c)
    22472184{
    22482185  int j;
     
    22502187  sorted_pair_node ***sbuf =
    22512188    (sorted_pair_node ***) omalloc (pn * sizeof (sorted_pair_node **));
    2252   for (j = 0; j < pn; j++)
     2189  for(j = 0; j < pn; j++)
    22532190  {
    22542191    p_Test (p[j], c->r);
     
    22562193  }
    22572194  int sum = 0;
    2258   for (j = 0; j < pn; j++)
     2195  for(j = 0; j < pn; j++)
    22592196  {
    22602197    sum += ibuf[j];
     
    22632200    (sorted_pair_node **) omalloc (sum * sizeof (sorted_pair_node *));
    22642201  int partsum = 0;
    2265   for (j = 0; j < pn; j++)
     2202  for(j = 0; j < pn; j++)
    22662203  {
    22672204    memmove (big_sbuf + partsum, sbuf[j],
    2268              ibuf[j] * sizeof (sorted_pair_node *));
     2205             ibuf[j] * sizeof (sorted_pair_node *));
    22692206    omfree (sbuf[j]);
    22702207    partsum += ibuf[j];
     
    22812218#ifdef TGB_DEBUG
    22822219  int z;
    2283   for (z = 1; z <= c->pair_top; z++)
     2220  for(z = 1; z <= c->pair_top; z++)
    22842221  {
    22852222    assume (pair_better (c->apairs[z], c->apairs[z - 1], c));
     
    22912228#ifdef NORO_CACHE
    22922229#ifndef NORO_NON_POLY
    2293 void
    2294 NoroCache::evaluateRows ()
     2230void NoroCache::evaluateRows ()
    22952231{
    22962232  //after that can evaluate placeholders
    22972233  int i;
    22982234  buffer = (number *) omalloc (nIrreducibleMonomials * sizeof (number));
    2299   for (i = 0; i < root.branches_len; i++)
     2235  for(i = 0; i < root.branches_len; i++)
    23002236  {
    23012237    evaluateRows (1, root.branches[i]);
     
    23052241}
    23062242
    2307 void
    2308 NoroCache::evaluateRows (int level, NoroCacheNode * node)
     2243void NoroCache::evaluateRows (int level, NoroCacheNode * node)
    23092244{
    23102245  assume (level >= 0);
    2311   if (node == NULL)
     2246  if(node == NULL)
    23122247    return;
    2313   if (level < pVariables)
     2248  if(level < pVariables)
    23142249  {
    23152250    int i, sum;
    2316     for (i = 0; i < node->branches_len; i++)
     2251    for(i = 0; i < node->branches_len; i++)
    23172252    {
    23182253      evaluateRows (level + 1, node->branches[i]);
     
    23222257  {
    23232258    DataNoroCacheNode *dn = (DataNoroCacheNode *) node;
    2324     if (dn->value_len != backLinkCode)
     2259    if(dn->value_len != backLinkCode)
    23252260    {
    23262261      poly p = dn->value_poly;
     
    23302265      memset (buffer, 0, sizeof (number) * nIrreducibleMonomials);
    23312266
    2332       if (p == NULL)
    2333       {
    2334         row->array = NULL;
    2335         row->begin = 0;
    2336         row->end = 0;
    2337         return;
     2267      if(p == NULL)
     2268      {
     2269        row->array = NULL;
     2270        row->begin = 0;
     2271        row->end = 0;
     2272        return;
    23382273      }
    23392274      int i = 0;
    23402275      int idx;
    23412276      number *a = buffer;
    2342       while (p)
    2343       {
    2344         DataNoroCacheNode *ref = getCacheReference (p);
    2345 
    2346         idx = ref->term_index;
    2347         assume (idx >= 0);
    2348         a[idx] = p_GetCoeff (p, currRing);
    2349         if (i == 0)
    2350           row->begin = idx;
    2351         i++;
    2352         pIter (p);
     2277      while(p)
     2278      {
     2279        DataNoroCacheNode *ref = getCacheReference (p);
     2280
     2281        idx = ref->term_index;
     2282        assume (idx >= 0);
     2283        a[idx] = p_GetCoeff (p, currRing);
     2284        if(i == 0)
     2285          row->begin = idx;
     2286        i++;
     2287        pIter (p);
    23532288      }
    23542289      row->end = idx + 1;
     
    23622297      SparseRow *row = dn->row;
    23632298      int i = 0;
    2364       while (p)
    2365       {
    2366         DataNoroCacheNode *ref = getCacheReference (p);
    2367 
    2368         int idx = ref->term_index;
    2369         assume (idx >= 0);
    2370         row->idx_array[i] = idx;
    2371         row->coef_array[i] = p_GetCoeff (p, currRing);
    2372         i++;
    2373         pIter (p);
    2374       }
    2375       if (i != dn->value_len)
    2376       {
    2377         PrintS ("F4 calc wrong, as poly len was wrong\n");
     2299      while(p)
     2300      {
     2301        DataNoroCacheNode *ref = getCacheReference (p);
     2302
     2303        int idx = ref->term_index;
     2304        assume (idx >= 0);
     2305        row->idx_array[i] = idx;
     2306        row->coef_array[i] = p_GetCoeff (p, currRing);
     2307        i++;
     2308        pIter (p);
     2309      }
     2310      if(i != dn->value_len)
     2311      {
     2312        PrintS ("F4 calc wrong, as poly len was wrong\n");
    23782313      }
    23792314      assume (i == dn->value_len);
     
    23842319
    23852320void
    2386 NoroCache::evaluatePlaceHolder (number * row,
    2387                                 std::vector < NoroPlaceHolder >
    2388                                 &place_holders)
     2321  NoroCache::evaluatePlaceHolder (number * row,
     2322                                  std::vector < NoroPlaceHolder >
     2323                                  &place_holders)
    23892324{
    23902325  int i;
    23912326  int s = place_holders.size ();
    2392   for (i = 0; i < s; i++)
     2327  for(i = 0; i < s; i++)
    23932328  {
    23942329    DataNoroCacheNode *ref = place_holders[i].ref;
    23952330    number coef = place_holders[i].coef;
    2396     if (ref->value_len == backLinkCode)
     2331    if(ref->value_len == backLinkCode)
    23972332    {
    23982333      row[ref->term_index] = npAddM (row[ref->term_index], coef);
     
    24022337#ifndef NORO_SPARSE_ROWS_PRE
    24032338      DenseRow *ref_row = ref->row;
    2404       if (ref_row == NULL)
    2405         continue;
     2339      if(ref_row == NULL)
     2340        continue;
    24062341      number *ref_begin = ref_row->array;
    24072342      number *ref_end = ref_row->array + (ref_row->end - ref_row->begin);
    24082343      number *my_pos = row + ref_row->begin;
    24092344      //TODO npisOne distinction
    2410       if (!(npIsOne (coef)))
    2411       {
    2412         while (ref_begin != ref_end)
    2413         {
    2414 
    2415           *my_pos = npAddM (*my_pos, npMult (coef, *ref_begin));
    2416           ++ref_begin;
    2417           ++my_pos;
    2418         }
     2345      if(!(npIsOne (coef)))
     2346      {
     2347        while(ref_begin != ref_end)
     2348        {
     2349
     2350          *my_pos = npAddM (*my_pos, npMult (coef, *ref_begin));
     2351          ++ref_begin;
     2352          ++my_pos;
     2353        }
    24192354      }
    24202355      else
    24212356      {
    2422         while (ref_begin != ref_end)
    2423         {
    2424 
    2425           *my_pos = npAddM (*my_pos, *ref_begin);
    2426           ++ref_begin;
    2427           ++my_pos;
    2428         }
     2357        while(ref_begin != ref_end)
     2358        {
     2359
     2360          *my_pos = npAddM (*my_pos, *ref_begin);
     2361          ++ref_begin;
     2362          ++my_pos;
     2363        }
    24292364      }
    24302365
    24312366#else
    24322367      SparseRow *ref_row = ref->row;
    2433       if (ref_row == NULL)
    2434         continue;
     2368      if(ref_row == NULL)
     2369        continue;
    24352370      int n = ref_row->len;
    24362371      int j;
    24372372      int *idx_array = ref_row->idx_array;
    24382373      number *coef_array = ref_row->coef_array;
    2439       for (j = 0; j < n; j++)
    2440       {
    2441         int idx = idx_array[j];
    2442         number ref_coef = coef_array[j];
    2443         row[idx] = npAddM (row[idx], npMult (coef, ref_coef));
     2374      for(j = 0; j < n; j++)
     2375      {
     2376        int idx = idx_array[j];
     2377        number ref_coef = coef_array[j];
     2378        row[idx] = npAddM (row[idx], npMult (coef, ref_coef));
    24442379      }
    24452380#endif
     
    24592394  //wrp(t);
    24602395  res_holder.changed = TRUE;
    2461   if (force_unique)
     2396  if(force_unique)
    24622397  {
    24632398    DataNoroCacheNode *ref = cache->getCacheReference (t);
    2464     if (ref != NULL)
     2399    if(ref != NULL)
    24652400    {
    24662401      res_holder.len = ref->value_len;
    2467       if (res_holder.len == NoroCache::backLinkCode)
    2468       {
    2469         res_holder.len = 1;
     2402      if(res_holder.len == NoroCache::backLinkCode)
     2403      {
     2404        res_holder.len = 1;
    24702405      }
    24712406      res_holder.coef = p_GetCoeff (t, c->r);
     
    24812416  {
    24822417    BOOLEAN succ;
    2483     poly cache_lookup = cache->lookup (t, succ, res_holder.len);        //don't own this yet
    2484     if (succ)
    2485     {
    2486       if (cache_lookup == t)
    2487       {
    2488         //know they are equal
    2489         //res_holder.len=1;
    2490 
    2491         res_holder.changed = FALSE;
    2492         res_holder.p = t;
    2493         res_holder.coef = npInit (1);
    2494 
    2495         res_holder.onlyBorrowed = FALSE;
    2496         return res_holder;
     2418    poly cache_lookup = cache->lookup (t, succ, res_holder.len);        //don't own this yet
     2419    if(succ)
     2420    {
     2421      if(cache_lookup == t)
     2422      {
     2423        //know they are equal
     2424        //res_holder.len=1;
     2425
     2426        res_holder.changed = FALSE;
     2427        res_holder.p = t;
     2428        res_holder.coef = npInit (1);
     2429
     2430        res_holder.onlyBorrowed = FALSE;
     2431        return res_holder;
    24972432      }
    24982433
     
    25102445  unsigned long sev = p_GetShortExpVector (t, currRing);
    25112446  int i = kFindDivisibleByInS_easy (c->strat, t, sev);
    2512   if (i >= 0)
     2447  if(i >= 0)
    25132448  {
    25142449    number coef_bak = p_GetCoeff (t, c->r);
     
    25492484    p_SetCoeff (t, one, c->r);
    25502485    res_holder.len = 1;
    2551     if (!(force_unique))
     2486    if(!(force_unique))
    25522487    {
    25532488      res_holder.ref = cache->insert (t, t, res_holder.len);
     
    25792514#ifndef NORO_NON_POLY
    25802515//len input and out: Idea: reverse addition
    2581 poly
    2582 noro_red_non_unique (poly p, int &len, NoroCache * cache, slimgb_alg * c)
     2516poly noro_red_non_unique (poly p, int &len, NoroCache * cache, slimgb_alg * c)
    25832517{
    25842518  assume (len == pLength (p));
    25852519  poly orig_p = p;
    2586   if (p == NULL)
     2520  if(p == NULL)
    25872521  {
    25882522    len = 0;
     
    25952529  int unchanged_size = 0;
    25962530
    2597   while (p)
     2531  while(p)
    25982532  {
    25992533    poly t = p;
     
    26042538#endif
    26052539    MonRedRes red = noro_red_mon (t, FALSE, cache, c);
    2606     if ((!(red.changed)) && (!(red.onlyBorrowed)))
     2540    if((!(red.changed)) && (!(red.onlyBorrowed)))
    26072541    {
    26082542      unchanged_size++;
    26092543      assume (npIsOne (red.coef));
    26102544      assume (p_GetCoeff (red.p, currRing) == coef_debug);
    2611       if (unchanged_head)
    2612       {
    2613         pNext (unchanged_tail) = red.p;
    2614         pIter (unchanged_tail);
     2545      if(unchanged_head)
     2546      {
     2547        pNext (unchanged_tail) = red.p;
     2548        pIter (unchanged_tail);
    26152549      }
    26162550      else
    26172551      {
    2618         unchanged_tail = red.p;
    2619         unchanged_head = red.p;
     2552        unchanged_tail = red.p;
     2553        unchanged_head = red.p;
    26202554      }
    26212555    }
     
    26232557    {
    26242558      assume (red.len == pLength (red.p));
    2625       if (red.onlyBorrowed)
    2626       {
    2627         if (npIsOne (red.coef))
    2628         {
    2629           t = p_Copy (red.p, currRing);
    2630         }
    2631         else
    2632           t = pp_Mult_nn (red.p, red.coef, currRing);
     2559      if(red.onlyBorrowed)
     2560      {
     2561        if(npIsOne (red.coef))
     2562        {
     2563          t = p_Copy (red.p, currRing);
     2564        }
     2565        else
     2566          t = pp_Mult_nn (red.p, red.coef, currRing);
    26332567      }
    26342568      else
    26352569      {
    2636         if (npIsOne (red.coef))
    2637           t = red.p;
    2638         else
    2639           t = p_Mult_nn (red.p, red.coef, currRing);
     2570        if(npIsOne (red.coef))
     2571          t = red.p;
     2572        else
     2573          t = p_Mult_nn (red.p, red.coef, currRing);
    26402574      }
    26412575      kBucket_Add_q (bucket, t, &red.len);
     
    26752609#ifndef NORO_NON_POLY
    26762610std::vector < NoroPlaceHolder > noro_red (poly p, int &len, NoroCache * cache,
    2677                                           slimgb_alg * c)
     2611                                          slimgb_alg * c)
    26782612{
    26792613  std::vector < NoroPlaceHolder > res;
    2680   while (p)
     2614  while(p)
    26812615  {
    26822616    poly t = p;
     
    26922626    h.coef = red.coef;
    26932627    assume (!((h.ref->value_poly == NULL) && (h.ref->value_len != 0)));
    2694     if (h.ref->value_poly)
     2628    if(h.ref->value_poly)
    26952629      res.push_back (h);
    26962630  }
     
    27022636#ifdef USE_NORO
    27032637#ifndef NORO_CACHE
    2704 void
    2705 noro_step (poly * p, int &pn, slimgb_alg * c)
     2638void noro_step (poly * p, int &pn, slimgb_alg * c)
    27062639{
    27072640  poly *reduced = (poly *) omalloc (pn * sizeof (poly));
     
    27142647  NoroCache cache;
    27152648#endif
    2716   for (j = 0; j < pn; j++)
     2649  for(j = 0; j < pn; j++)
    27172650  {
    27182651
     
    27272660    assume (pLength (h) == h_len);
    27282661#endif
    2729     if (h != NULL)
     2662    if(h != NULL)
    27302663    {
    27312664#ifndef NORO_CACHE
     
    27372670      reduced_len[reduced_c] = h_len;
    27382671      reduced_c++;
    2739       if (TEST_OPT_PROT)
    2740         Print ("%d ", h_len);
     2672      if(TEST_OPT_PROT)
     2673        Print ("%d ", h_len);
    27412674    }
    27422675  }
    27432676  int reduced_sum = 0;
    2744   for (j = 0; j < reduced_c; j++)
     2677  for(j = 0; j < reduced_c; j++)
    27452678  {
    27462679    reduced_sum += reduced_len[j];
     
    27482681  poly *terms = (poly *) omalloc (reduced_sum * sizeof (poly));
    27492682  int tc = 0;
    2750   for (j = 0; j < reduced_c; j++)
     2683  for(j = 0; j < reduced_c; j++)
    27512684  {
    27522685    poly h = reduced[j];
    27532686
    2754     while (h != NULL)
     2687    while(h != NULL)
    27552688    {
    27562689      terms[tc++] = h;
     
    27742707  omfree (reduced);
    27752708
    2776   if (TEST_OPT_PROT)
     2709  if(TEST_OPT_PROT)
    27772710    PrintS ("\n");
    27782711}
     
    27812714#endif
    27822715#endif
    2783 static void
    2784 go_on (slimgb_alg * c)
     2716static void go_on (slimgb_alg * c)
    27852717{
    27862718  //set limit of 1000 for multireductions, at the moment for
     
    27942726  int i = 0;
    27952727  c->average_length = 0;
    2796   for (i = 0; i < c->n; i++)
     2728  for(i = 0; i < c->n; i++)
    27972729  {
    27982730    c->average_length += c->lengths[i];
     
    28032735
    28042736#ifdef USE_NORO
    2805   if ((use_noro) || (c->use_noro_last_block))
     2737  if((use_noro) || (c->use_noro_last_block))
    28062738    max_pairs = bundle_size_noro;
    28072739#endif
    2808   poly *p = (poly *) omalloc ((max_pairs + 1) * sizeof (poly)); //nullterminated
     2740  poly *p = (poly *) omalloc ((max_pairs + 1) * sizeof (poly)); //nullterminated
    28092741
    28102742  int curr_deg = -1;
    2811   while (i < max_pairs)
    2812   {
    2813     sorted_pair_node *s = top_pair (c); //here is actually chain criterium done
    2814 
    2815     if (!s)
     2743  while(i < max_pairs)
     2744  {
     2745    sorted_pair_node *s = top_pair (c); //here is actually chain criterium done
     2746
     2747    if(!s)
    28162748      break;
    28172749
    2818     if (curr_deg >= 0)
    2819     {
    2820       if (s->deg > curr_deg)
    2821         break;
     2750    if(curr_deg >= 0)
     2751    {
     2752      if(s->deg > curr_deg)
     2753        break;
    28222754    }
    28232755
     
    28252757      curr_deg = s->deg;
    28262758    quick_pop_pair (c);
    2827     if (s->i >= 0)
     2759    if(s->i >= 0)
    28282760    {
    28292761      //be careful replace_pair use createShortSpoly which is not noncommutative
     
    28312763      replace_pair (s->i, s->j, c);
    28322764
    2833       if (s->i == s->j)
    2834       {
    2835         free_sorted_pair_node (s, c->r);
    2836         continue;
     2765      if(s->i == s->j)
     2766      {
     2767        free_sorted_pair_node (s, c->r);
     2768        continue;
    28372769      }
    28382770      now_t_rep (s->i, s->j, c);
    28392771    }
    28402772    poly h;
    2841     if (s->i >= 0)
     2773    if(s->i >= 0)
    28422774    {
    28432775#ifdef HAVE_PLURAL
    2844       if (c->nc)
    2845       {
    2846         h = nc_CreateSpoly (c->S->m[s->i], c->S->m[s->j] /*, NULL */ , c->r);
    2847 
    2848         if (h != NULL)
    2849           p_Cleardenom (h, c->r);
     2776      if(c->nc)
     2777      {
     2778        h = nc_CreateSpoly (c->S->m[s->i], c->S->m[s->j] /*, NULL */ , c->r);
     2779
     2780        if(h != NULL)
     2781          p_Cleardenom (h, c->r);
    28502782      }
    28512783      else
    28522784#endif
    2853         h = ksOldCreateSpoly (c->S->m[s->i], c->S->m[s->j], NULL, c->r);
     2785        h = ksOldCreateSpoly (c->S->m[s->i], c->S->m[s->j], NULL, c->r);
    28542786      p_Test (h, c->r);
    28552787    }
     
    28642796    int mlen = pLength (h);
    28652797    p_Test (h, c->r);
    2866     if ((!c->nc) & (!(use_noro)))
     2798    if((!c->nc) & (!(use_noro)))
    28672799    {
    28682800      h = redNF2 (h, c, mlen, coef, 2);
     
    28722804    p_Test (h, c->r);
    28732805    free_sorted_pair_node (s, c->r);
    2874     if (!h)
     2806    if(!h)
    28752807      continue;
    28762808    p[i] = h;
     
    28792811  p[i] = NULL;
    28802812//  pre_comp(p,i,c);
    2881   if (i == 0)
     2813  if(i == 0)
    28822814  {
    28832815    omfree (p);
     
    28942826  //if ((!(c->nc))&&(rField_is_Zp(c->r)))
    28952827  //{
    2896   if (use_noro)
     2828  if(use_noro)
    28972829  {
    28982830    int pn = i;
    2899     if (pn == 0)
     2831    if(pn == 0)
    29002832    {
    29012833      omfree (p);
     
    29032835    }
    29042836    {
    2905       if (npPrimeM < 255)
    2906       {
    2907         noro_step < tgb_uint8 > (p, pn, c);
     2837      if(npPrimeM < 255)
     2838      {
     2839        noro_step < tgb_uint8 > (p, pn, c);
    29082840      }
    29092841      else
    29102842      {
    2911         if (npPrimeM < 65000)
    2912         {
    2913           noro_step < tgb_uint16 > (p, pn, c);
    2914         }
    2915         else
    2916         {
    2917           noro_step < tgb_uint32 > (p, pn, c);
    2918         }
     2843        if(npPrimeM < 65000)
     2844        {
     2845          noro_step < tgb_uint16 > (p, pn, c);
     2846        }
     2847        else
     2848        {
     2849          noro_step < tgb_uint32 > (p, pn, c);
     2850        }
    29192851      }
    29202852    }
     
    29352867#endif
    29362868  red_object *buf = (red_object *) omalloc (i * sizeof (red_object));
    2937   for (j = 0; j < i; j++)
     2869  for(j = 0; j < i; j++)
    29382870  {
    29392871    p_Test (p[j], c->r);
     
    29422874    buf[j].bucket = kBucketCreate (currRing);
    29432875    p_Test (p[j], c->r);
    2944     if (c->eliminationProblem)
     2876    if(c->eliminationProblem)
    29452877    {
    29462878      buf[j].sugar = c->pTotaldegree_full (p[j]);
     
    29542886  qsort (buf, i, sizeof (red_object), red_object_better_gen);
    29552887//    Print("\ncurr_deg:%i\n",curr_deg);
    2956   if (TEST_OPT_PROT)
     2888  if(TEST_OPT_PROT)
    29572889  {
    29582890    Print ("%dM[%d,", curr_deg, i);
     
    29612893  multi_reduction (buf, i, c);
    29622894#ifdef TGB_RESORT_PAIRS
    2963   if (c->used_b)
    2964   {
    2965     if (TEST_OPT_PROT)
     2895  if(c->used_b)
     2896  {
     2897    if(TEST_OPT_PROT)
    29662898      PrintS ("B");
    29672899    int e;
    2968     for (e = 0; e <= c->pair_top; e++)
    2969     {
    2970       if (c->apairs[e]->i < 0)
    2971         continue;
     2900    for(e = 0; e <= c->pair_top; e++)
     2901    {
     2902      if(c->apairs[e]->i < 0)
     2903        continue;
    29722904      assume (c->apairs[e]->j >= 0);
    2973       if ((c->replaced[c->apairs[e]->i]) || (c->replaced[c->apairs[e]->j]))
    2974       {
    2975         sorted_pair_node *s = c->apairs[e];
    2976         s->expected_length = pair_weighted_length (s->i, s->j, c);
     2905      if((c->replaced[c->apairs[e]->i]) || (c->replaced[c->apairs[e]->j]))
     2906      {
     2907        sorted_pair_node *s = c->apairs[e];
     2908        s->expected_length = pair_weighted_length (s->i, s->j, c);
    29772909      }
    29782910    }
    29792911    qsort (c->apairs, c->pair_top + 1, sizeof (sorted_pair_node *),
    2980            tgb_pair_better_gen2);
     2912           tgb_pair_better_gen2);
    29812913  }
    29822914#endif
     
    29842916  {
    29852917    int k;
    2986     for (k = 0; k < i; k++)
     2918    for(k = 0; k < i; k++)
    29872919    {
    29882920      assume (kFindDivisibleByInS_easy (c->strat, buf[k]) < 0);
    29892921      int k2;
    2990       for (k2 = 0; k2 < i; k2++)
    2991       {
    2992         if (k == k2)
    2993           continue;
    2994         assume ((!(p_LmDivisibleBy (buf[k].p, buf[k2].p, c->r)))
    2995                 || (wrp (buf[k].p), Print (" k %d k2 %d ", k, k2),
    2996                     wrp (buf[k2].p), FALSE));
     2922      for(k2 = 0; k2 < i; k2++)
     2923      {
     2924        if(k == k2)
     2925          continue;
     2926        assume ((!(p_LmDivisibleBy (buf[k].p, buf[k2].p, c->r)))
     2927                || (wrp (buf[k].p), Print (" k %d k2 %d ", k, k2),
     2928                    wrp (buf[k2].p), FALSE));
    29972929      }
    29982930    }
     
    30012933  //resort S
    30022934
    3003   if (TEST_OPT_PROT)
     2935  if(TEST_OPT_PROT)
    30042936    Print ("%i]", i);
    30052937
    30062938  poly *add_those = (poly *) omalloc (i * sizeof (poly));
    3007   for (j = 0; j < i; j++)
     2939  for(j = 0; j < i; j++)
    30082940  {
    30092941    int len;
     
    30142946    p_Test (p, c->r);
    30152947    //if (!c->nc) {
    3016     if ((c->tailReductions) || (lies_in_last_dp_block (p, c)))
     2948    if((c->tailReductions) || (lies_in_last_dp_block (p, c)))
    30172949    {
    30182950      p = redNFTail (p, c->strat->sl, c->strat, 0);
     
    30322964  omfree (buf);
    30332965
    3034   if (TEST_OPT_PROT)
     2966  if(TEST_OPT_PROT)
    30352967    Print ("(%d)", c->pair_top + 1);
    30362968  //TODO: implement that while(!(idIs0(c->add_later)))
     
    30452977#ifdef REDTAIL_S
    30462978
    3047 static poly
    3048 redNFTail (poly h, const int sl, kStrategy strat, int len)
     2979static poly redNFTail (poly h, const int sl, kStrategy strat, int len)
    30492980{
    30502981  BOOLEAN nc = rIsPluralRing (currRing);
    3051   if (h == NULL)
     2982  if(h == NULL)
    30522983    return NULL;
    30532984  pTest (h);
    3054   if (0 > sl)
     2985  if(0 > sl)
    30552986    return h;
    3056   if (pNext (h) == NULL)
     2987  if(pNext (h) == NULL)
    30572988    return h;
    30582989
     
    30652996  len--;
    30662997  h = P.p;
    3067   if (len <= 0)
     2998  if(len <= 0)
    30682999    len = pLength (h);
    30693000  kBucketInit (P.bucket, h /*P.p */ , len /*pLength(P.p) */ );
     
    30773008    {
    30783009      //int dummy=strat->sl;
    3079       j = kFindDivisibleByInS_easy (strat, P.p, P.sev); //kFindDivisibleByInS(strat,&dummy,&P);
    3080       if (j >= 0)
     3010      j = kFindDivisibleByInS_easy (strat, P.p, P.sev); //kFindDivisibleByInS(strat,&dummy,&P);
     3011      if(j >= 0)
    30813012      {
    30823013#ifdef REDTAIL_PROT
    3083         PrintS ("r");
    3084 #endif
    3085         nNormalize (pGetCoeff (P.p));
     3014        PrintS ("r");
     3015#endif
     3016        nNormalize (pGetCoeff (P.p));
    30863017#ifdef KDEBUG
    3087         if (TEST_OPT_DEBUG)
    3088         {
    3089           PrintS ("red tail:");
    3090           wrp (h);
    3091           PrintS (" with ");
    3092           wrp (strat->S[j]);
    3093         }
    3094 #endif
    3095         number coef;
    3096         pTest (strat->S[j]);
     3018        if(TEST_OPT_DEBUG)
     3019        {
     3020          PrintS ("red tail:");
     3021          wrp (h);
     3022          PrintS (" with ");
     3023          wrp (strat->S[j]);
     3024        }
     3025#endif
     3026        number coef;
     3027        pTest (strat->S[j]);
    30973028#ifdef HAVE_PLURAL
    3098         if (nc)
    3099         {
    3100           nc_BucketPolyRed_Z (P.bucket, strat->S[j], &coef);
    3101         }
    3102         else
    3103 #endif
    3104           coef = kBucketPolyRed (P.bucket, strat->S[j],
    3105                                 strat->lenS[j] /*pLength(strat->S[j]) */ ,
    3106                                 strat->kNoether);
    3107         pMult_nn (res, coef);
    3108         nDelete (&coef);
    3109         h = kBucketGetLm (P.bucket);
    3110         pTest (h);
    3111         if (h == NULL)
    3112         {
     3029        if(nc)
     3030        {
     3031          nc_BucketPolyRed_Z (P.bucket, strat->S[j], &coef);
     3032        }
     3033        else
     3034#endif
     3035          coef = kBucketPolyRed (P.bucket, strat->S[j],
     3036                                strat->lenS[j] /*pLength(strat->S[j]) */ ,
     3037                                strat->kNoether);
     3038        pMult_nn (res, coef);
     3039        nDelete (&coef);
     3040        h = kBucketGetLm (P.bucket);
     3041        pTest (h);
     3042        if(h == NULL)
     3043        {
    31133044#ifdef REDTAIL_PROT
    3114           PrintS (" ");
    3115 #endif
    3116           kBucketDestroy (&P.bucket);
    3117           return res;
    3118         }
    3119         pTest (h);
    3120         P.p = h;
    3121         P.t_p = NULL;
    3122         P.SetShortExpVector ();
     3045          PrintS (" ");
     3046#endif
     3047          kBucketDestroy (&P.bucket);
     3048          return res;
     3049        }
     3050        pTest (h);
     3051        P.p = h;
     3052        P.t_p = NULL;
     3053        P.SetShortExpVector ();
    31233054#ifdef KDEBUG
    3124         if (TEST_OPT_DEBUG)
    3125         {
    3126           PrintS ("\nto tail:");
    3127           wrp (h);
    3128           PrintLn ();
    3129         }
     3055        if(TEST_OPT_DEBUG)
     3056        {
     3057          PrintS ("\nto tail:");
     3058          wrp (h);
     3059          PrintLn ();
     3060        }
    31303061#endif
    31313062      }
     
    31333064      {
    31343065#ifdef REDTAIL_PROT
    3135         PrintS ("n");
    3136 #endif
    3137         break;
    3138       }
    3139     }                           /* end loop current mon */
     3066        PrintS ("n");
     3067#endif
     3068        break;
     3069      }
     3070    }                           /* end loop current mon */
    31403071    //   poly tmp=pHead(h /*kBucketGetLm(P.bucket)*/);
    31413072    //act->next=tmp;pIter(act);
     
    31433074    pIter (act);
    31443075    h = kBucketGetLm (P.bucket);
    3145     if (h == NULL)
     3076    if(h == NULL)
    31463077    {
    31473078#ifdef REDTAIL_PROT
     
    31603091
    31613092//transfers ownership of m to mat
    3162 void
    3163 init_with_mac_poly (tgb_sparse_matrix * mat, int row, mac_poly m)
     3093void init_with_mac_poly (tgb_sparse_matrix * mat, int row, mac_poly m)
    31643094{
    31653095  assume (mat->mp[row] == NULL);
     
    31673097#ifdef TGB_DEBUG
    31683098  mac_poly r = m;
    3169   while (r)
     3099  while(r)
    31703100  {
    31713101    assume (r->exp < mat->columns);
     
    31773107poly
    31783108free_row_to_poly (tgb_sparse_matrix * mat, int row, poly * monoms,
    3179                   int monom_index)
     3109                  int monom_index)
    31803110{
    31813111  poly p = NULL;
     
    31833113  mac_poly r = mat->mp[row];
    31843114  mat->mp[row] = NULL;
    3185   while (r)
     3115  while(r)
    31863116  {
    31873117    (*set_this) = pLmInit (monoms[monom_index - 1 - r->exp]);
     
    31963126}
    31973127
    3198 static int
    3199 poly_crit (const void *ap1, const void *ap2)
     3128static int poly_crit (const void *ap1, const void *ap2)
    32003129{
    32013130  poly p1, p2;
     
    32043133
    32053134  int c = pLmCmp (p1, p2);
    3206   if (c != 0)
     3135  if(c != 0)
    32073136    return c;
    32083137  int l1 = pLength (p1);
    32093138  int l2 = pLength (p2);
    3210   if (l1 < l2)
     3139  if(l1 < l2)
    32113140    return -1;
    3212   if (l1 > l2)
     3141  if(l1 > l2)
    32133142    return 1;
    32143143  return 0;
    32153144}
    32163145
    3217 void
    3218 slimgb_alg::introduceDelayedPairs (poly * pa, int s)
    3219 {
    3220   if (s == 0)
     3146void slimgb_alg::introduceDelayedPairs (poly * pa, int s)
     3147{
     3148  if(s == 0)
    32213149    return;
    32223150  sorted_pair_node **si_array =
    32233151    (sorted_pair_node **) omalloc (s * sizeof (sorted_pair_node *));
    32243152
    3225   for (int i = 0; i < s; i++)
     3153  for(int i = 0; i < s; i++)
    32263154  {
    32273155    sorted_pair_node *si =
     
    32653193  {
    32663194    int hzz;
    3267     for (hzz = 0; hzz < IDELEMS (I); hzz++)
     3195    for(hzz = 0; hzz < IDELEMS (I); hzz++)
    32683196    {
    32693197      assume (I->m[hzz] != NULL);
    32703198      int d = this->pTotaldegree (I->m[hzz]);
    32713199      poly t = I->m[hzz]->next;
    3272       while (t)
    3273       {
    3274         if (d != this->pTotaldegree (t))
    3275         {
    3276           is_homog = FALSE;
    3277           break;
    3278         }
    3279         t = t->next;
    3280       }
    3281       if (!(is_homog))
    3282         break;
     3200      while(t)
     3201      {
     3202        if(d != this->pTotaldegree (t))
     3203        {
     3204          is_homog = FALSE;
     3205          break;
     3206        }
     3207        t = t->next;
     3208      }
     3209      if(!(is_homog))
     3210        break;
    32833211    }
    32843212  }
     
    32913219  easy_product_crit = 0;
    32923220  extended_product_crit = 0;
    3293   if (rField_is_Zp (r))
     3221  if(rField_is_Zp (r))
    32943222    isDifficultField = FALSE;
    32953223  else
     
    33273255  this->n = 0;
    33283256  T_deg = (int *) omalloc (n * sizeof (int));
    3329   if (eliminationProblem)
     3257  if(eliminationProblem)
    33303258    T_deg_full = (int *) omalloc (n * sizeof (int));
    33313259  else
     
    33523280
    33533281  short_Exps = (long *) omalloc (n * sizeof (long));
    3354   if (F4_mode)
     3282  if(F4_mode)
    33553283    S = idInit (n, I->rank);
    33563284  else
    33573285    S = idInit (1, I->rank);
    33583286  strat = new skStrategy;
    3359   if (eliminationProblem)
     3287  if(eliminationProblem)
    33603288    strat->honey = TRUE;
    33613289  strat->syzComp = 0;
     
    33673295  strat->sl = -1;
    33683296  i = n;
    3369   i = 1;                        //some strange bug else
     3297  i = 1;                        //some strange bug else
    33703298  /* initS(c->S,NULL,c->strat); */
    33713299  /* intS start: */
    33723300  // i=((i+IDELEMS(c->S)+15)/16)*16;
    3373   strat->ecartS = (intset) omAlloc (i * sizeof (int));  /*initec(i); */
     3301  strat->ecartS = (intset) omAlloc (i * sizeof (int));  /*initec(i); */
    33743302  strat->sevS = (unsigned long *) omAlloc0 (i * sizeof (unsigned long));
    33753303  /*initsevS(i); */
    3376   strat->S_2_R = (int *) omAlloc0 (i * sizeof (int));   /*initS_2_R(i); */
     3304  strat->S_2_R = (int *) omAlloc0 (i * sizeof (int));   /*initS_2_R(i); */
    33773305  strat->fromQ = NULL;
    33783306  strat->Shdl = idInit (1, 1);
    33793307  strat->S = strat->Shdl->m;
    33803308  strat->lenS = (int *) omAlloc0 (i * sizeof (int));
    3381   if ((isDifficultField) || (eliminationProblem))
     3309  if((isDifficultField) || (eliminationProblem))
    33823310    strat->lenSw = (wlen_type *) omAlloc0 (i * sizeof (wlen_type));
    33833311  else
     
    33873315
    33883316  assume (strat->sl == IDELEMS (strat->Shdl) - 1);
    3389   if (!(F4_mode))
     3317  if(!(F4_mode))
    33903318  {
    33913319    poly *array_arg = I->m;
     
    34143342  else
    34153343  {
    3416     for (i = 1; i < n; i++)     //the 1 is wanted, because first element is added to basis
     3344    for(i = 1; i < n; i++)      //the 1 is wanted, because first element is added to basis
    34173345      add_to_basis_ideal_quotient (I->m[i], this, NULL);
    34183346  }
    3419   for (i = 0; i < IDELEMS (I); i++)
     3347  for(i = 0; i < IDELEMS (I); i++)
    34203348  {
    34213349    I->m[i] = NULL;
     
    34253353#ifdef USE_NORO
    34263354  use_noro = ((!(nc)) && (S->rank <= 1) && (rField_is_Zp (r))
    3427               && (!(eliminationProblem)) && (npPrimeM <= 32003));
     3355              && (!(eliminationProblem)) && (npPrimeM <= 32003));
    34283356  use_noro_last_block = false;
    3429   if ((!(use_noro)) && (lastDpBlockStart <= pVariables))
     3357  if((!(use_noro)) && (lastDpBlockStart <= pVariables))
    34303358  {
    34313359    use_noro_last_block = ((!(nc)) && (S->rank <= 1) && (rField_is_Zp (r))
    3432                            && (npPrimeM <= 32003));
     3360                           && (npPrimeM <= 32003));
    34333361  }
    34343362#else
     
    34433371{
    34443372
    3445   if (!(completed))
     3373  if(!(completed))
    34463374  {
    34473375    poly *add = (poly *) omalloc ((pair_top + 2) * sizeof (poly));
    34483376    int piter;
    34493377    int pos = 0;
    3450     for (piter = 0; piter <= pair_top; piter++)
     3378    for(piter = 0; piter <= pair_top; piter++)
    34513379    {
    34523380      sorted_pair_node *s = apairs[piter];
    3453       if (s->i < 0)
    3454       {
    3455         //delayed element
    3456         if (s->lcm_of_lm != NULL)
    3457         {
    3458           add[pos] = s->lcm_of_lm;
    3459           pos++;
    3460         }
     3381      if(s->i < 0)
     3382      {
     3383        //delayed element
     3384        if(s->lcm_of_lm != NULL)
     3385        {
     3386          add[pos] = s->lcm_of_lm;
     3387          pos++;
     3388        }
    34613389      }
    34623390      free_sorted_pair_node (s, r);
     
    34663394    add[pos] = NULL;
    34673395    pos = 0;
    3468     while (add[pos] != NULL)
     3396    while(add[pos] != NULL)
    34693397    {
    34703398      add_to_basis_ideal_quotient (add[pos], this, NULL);
    34713399      pos++;
    34723400    }
    3473     for (piter = 0; piter <= pair_top; piter++)
     3401    for(piter = 0; piter <= pair_top; piter++)
    34743402    {
    34753403      sorted_pair_node *s = apairs[piter];
     
    34833411  int i, j;
    34843412  slimgb_alg *c = this;
    3485   while (c->to_destroy)
     3413  while(c->to_destroy)
    34863414  {
    34873415    pDelete (&(c->to_destroy->p));
     
    34903418    omfree (old);
    34913419  }
    3492   while (c->F)
    3493   {
    3494     for (i = 0; i < c->F->size; i++)
     3420  while(c->F)
     3421  {
     3422    for(i = 0; i < c->F->size; i++)
    34953423    {
    34963424      pDelete (&(c->F->mp[i].m));
     
    35023430    omfree (old);
    35033431  }
    3504   while (c->F_minus)
    3505   {
    3506     for (i = 0; i < c->F_minus->size; i++)
     3432  while(c->F_minus)
     3433  {
     3434    for(i = 0; i < c->F_minus->size; i++)
    35073435    {
    35083436      pDelete (&(c->F_minus->p[i]));
     
    35163444#ifndef HAVE_BOOST
    35173445#ifndef USE_STDVECBOOL
    3518   for (int z = 1 /* zero length at 0 */ ; z < c->n; z++)
     3446  for(int z = 1 /* zero length at 0 */ ; z < c->n; z++)
    35193447  {
    35203448    omfree (c->states[z]);
     
    35263454  omfree (c->lengths);
    35273455  omfree (c->weighted_lengths);
    3528   for (int z = 0; z < c->n; z++)
     3456  for(int z = 0; z < c->n; z++)
    35293457  {
    35303458    pDelete (&c->tmp_pair_lm[z]);
     
    35353463
    35363464  omfree (c->T_deg);
    3537   if (c->T_deg_full)
     3465  if(c->T_deg_full)
    35383466    omfree (c->T_deg_full);
    35393467
     
    35463474  omFree (c->strat->lenS);
    35473475
    3548   if (c->strat->lenSw)
     3476  if(c->strat->lenSw)
    35493477    omFree (c->strat->lenSw);
    35503478
    3551   for (i = 0; i < c->n; i++)
    3552   {
    3553     if (c->gcd_of_terms[i])
     3479  for(i = 0; i < c->n; i++)
     3480  {
     3481    if(c->gcd_of_terms[i])
    35543482      pDelete (&(c->gcd_of_terms[i]));
    35553483  }
     
    35573485
    35583486  omfree (c->apairs);
    3559   if (TEST_OPT_PROT)
     3487  if(TEST_OPT_PROT)
    35603488  {
    35613489    //Print("calculated %d NFs\n",c->normal_forms);
    35623490    Print ("\nNF:%i product criterion:%i, ext_product criterion:%i \n",
    3563            c->normal_forms, c->easy_product_crit, c->extended_product_crit);
    3564   }
    3565 
    3566   for (i = 0; i <= c->strat->sl; i++)
    3567   {
    3568     if (!c->strat->S[i])
     3491           c->normal_forms, c->easy_product_crit, c->extended_product_crit);
     3492  }
     3493
     3494  for(i = 0; i <= c->strat->sl; i++)
     3495  {
     3496    if(!c->strat->S[i])
    35693497      continue;
    35703498    BOOLEAN found = FALSE;
    3571     for (j = 0; j < c->n; j++)
    3572     {
    3573       if (c->S->m[j] == c->strat->S[i])
    3574       {
    3575         found = TRUE;
    3576         break;
    3577       }
    3578     }
    3579     if (!found)
     3499    for(j = 0; j < c->n; j++)
     3500    {
     3501      if(c->S->m[j] == c->strat->S[i])
     3502      {
     3503        found = TRUE;
     3504        break;
     3505      }
     3506    }
     3507    if(!found)
    35803508      pDelete (&c->strat->S[i]);
    35813509  }
     
    35973525//   }
    35983526
    3599   if (completed)
    3600   {
    3601     for (i = 0; i < c->n; i++)
     3527  if(completed)
     3528  {
     3529    for(i = 0; i < c->n; i++)
    36023530    {
    36033531      assume (c->S->m[i] != NULL);
    3604       if (p_GetComp (c->S->m[i], currRing) > this->syz_comp)
    3605         continue;
    3606       for (j = 0; j < c->n; j++)
    3607       {
    3608         if ((c->S->m[j] == NULL) || (i == j))
    3609           continue;
    3610         assume (p_LmShortDivisibleBy (c->S->m[j], c->short_Exps[j],
    3611                                       c->S->m[i], ~c->short_Exps[i],
    3612                                       c->r) == p_LmDivisibleBy (c->S->m[j],
    3613                                                                 c->S->m[i],
    3614                                                                 c->r));
    3615         if (p_LmShortDivisibleBy (c->S->m[j], c->short_Exps[j],
    3616                                   c->S->m[i], ~c->short_Exps[i], c->r))
    3617         {
    3618           pDelete (&c->S->m[i]);
    3619           break;
    3620         }
     3532      if(p_GetComp (c->S->m[i], currRing) > this->syz_comp)
     3533        continue;
     3534      for(j = 0; j < c->n; j++)
     3535      {
     3536        if((c->S->m[j] == NULL) || (i == j))
     3537          continue;
     3538        assume (p_LmShortDivisibleBy (c->S->m[j], c->short_Exps[j],
     3539                                      c->S->m[i], ~c->short_Exps[i],
     3540                                      c->r) == p_LmDivisibleBy (c->S->m[j],
     3541                                                                c->S->m[i],
     3542                                                                c->r));
     3543        if(p_LmShortDivisibleBy (c->S->m[j], c->short_Exps[j],
     3544                                 c->S->m[i], ~c->short_Exps[i], c->r))
     3545        {
     3546          pDelete (&c->S->m[i]);
     3547          break;
     3548        }
    36213549      }
    36223550    }
     
    36273555  IDELEMS (I) = c->n;
    36283556  idSkipZeroes (I);
    3629   for (i = 0; i <= c->strat->sl; i++)
     3557  for(i = 0; i <= c->strat->sl; i++)
    36303558    c->strat->S[i] = NULL;
    36313559  id_Delete (&c->strat->Shdl, c->r);
     
    36353563}
    36363564
    3637 ideal
    3638 t_rep_gb (ring r, ideal arg_I, int syz_comp, BOOLEAN F4_mode)
     3565ideal t_rep_gb (ring r, ideal arg_I, int syz_comp, BOOLEAN F4_mode)
    36393566{
    36403567  assume (r == currRing);
     
    36433570  ring new_ring = rAssure_TDeg (orig_ring, 1, rVar (orig_ring), pos);
    36443571  ideal s_h;
    3645   if (orig_ring != new_ring)
     3572  if(orig_ring != new_ring)
    36463573  {
    36473574    rChangeCurrRing (new_ring);
     
    36663593  ideal s_result = do_t_rep_gb (new_ring, s_h, syz_comp, F4_mode, pos);
    36673594  ideal result;
    3668   if (orig_ring != new_ring)
     3595  if(orig_ring != new_ring)
    36693596  {
    36703597    idTest (s_result);
     
    36883615  //  Print("QlogSize(0) %d, QlogSize(1) %d,QlogSize(-2) %d, QlogSize(5) %d\n", QlogSize(nlInit(0)),QlogSize(nlInit(1)),QlogSize(nlInit(-2)),QlogSize(nlInit(5)));
    36893616
    3690   if (TEST_OPT_PROT)
    3691     if (F4_mode)
     3617  if(TEST_OPT_PROT)
     3618    if(F4_mode)
    36923619      PrintS ("F4 Modus \n");
    36933620
     
    36973624  ideal I = arg_I;
    36983625  idCompactify (I);
    3699   if (idIs0 (I))
     3626  if(idIs0 (I))
    37003627    return I;
    37013628  int i;
    3702   for (i = 0; i < IDELEMS (I); i++)
     3629  for(i = 0; i < IDELEMS (I); i++)
    37033630  {
    37043631    assume (I->m[i] != NULL);
     
    37123639  slimgb_alg *c = new slimgb_alg (I, syz_comp, F4_mode, deg_pos);
    37133640
    3714   while ((c->pair_top >= 0)
    3715         && ((!(TEST_OPT_DEGBOUND))
    3716              || (c->apairs[c->pair_top]->deg <= Kstd1_deg)))
     3641  while((c->pair_top >= 0)
     3642        && ((!(TEST_OPT_DEGBOUND))
     3643            || (c->apairs[c->pair_top]->deg <= Kstd1_deg)))
    37173644  {
    37183645#ifdef HAVE_F4
    3719     if (F4_mode)
     3646    if(F4_mode)
    37203647      go_on_F4 (c);
    37213648    else
     
    37233650      go_on (c);
    37243651  }
    3725   if (c->pair_top < 0)
     3652  if(c->pair_top < 0)
    37263653    c->completed = TRUE;
    37273654  I = c->S;
    37283655  delete c;
    3729   if (TEST_OPT_REDSB)
     3656  if(TEST_OPT_REDSB)
    37303657  {
    37313658    ideal erg = kInterRed (I, NULL);
     
    37393666}
    37403667
    3741 void
    3742 now_t_rep (const int &arg_i, const int &arg_j, slimgb_alg * c)
     3668void now_t_rep (const int &arg_i, const int &arg_j, slimgb_alg * c)
    37433669{
    37443670  int i, j;
    3745   if (arg_i == arg_j)
     3671  if(arg_i == arg_j)
    37463672  {
    37473673    return;
    37483674  }
    3749   if (arg_i > arg_j)
     3675  if(arg_i > arg_j)
    37503676  {
    37513677    i = arg_j;
     
    37673693  assume (arg_i < state->n);
    37683694  assume (arg_j < state->n);
    3769   if (arg_i == arg_j)
     3695  if(arg_i == arg_j)
    37703696  {
    37713697    return (TRUE);
    37723698  }
    3773   if (arg_i > arg_j)
     3699  if(arg_i > arg_j)
    37743700  {
    37753701    return (state->states[arg_i][arg_j] == HASTREP);
     
    37813707}
    37823708
    3783 #if 0                           // unused
    3784 static int
    3785 pLcmDeg (poly a, poly b)
     3709#if 0                           // unused
     3710static int pLcmDeg (poly a, poly b)
    37863711{
    37873712  int i;
    37883713  int n = 0;
    3789   for (i = pVariables; i; i--)
     3714  for(i = pVariables; i; i--)
    37903715  {
    37913716    n += si_max (pGetExp (a, i), pGetExp (b, i));
     
    37953720#endif
    37963721
    3797 static void
    3798 shorten_tails (slimgb_alg * c, poly monom)
     3722static void shorten_tails (slimgb_alg * c, poly monom)
    37993723{
    38003724  return;
    38013725// BOOLEAN corr=lenS_correct(c->strat);
    3802   for (int i = 0; i < c->n; i++)
     3726  for(int i = 0; i < c->n; i++)
    38033727  {
    38043728    //enter tail
    38053729
    3806     if (c->S->m[i] == NULL)
     3730    if(c->S->m[i] == NULL)
    38073731      continue;
    38083732    poly tail = c->S->m[i]->next;
    38093733    poly prev = c->S->m[i];
    38103734    BOOLEAN did_something = FALSE;
    3811     while ((tail != NULL) && (pLmCmp (tail, monom) >= 0))
    3812     {
    3813       if (p_LmDivisibleBy (monom, tail, c->r))
    3814       {
    3815         did_something = TRUE;
    3816         prev->next = tail->next;
    3817         tail->next = NULL;
    3818         p_Delete (&tail, c->r);
    3819         tail = prev;
    3820         //PrintS("Shortened");
    3821         c->lengths[i]--;
     3735    while((tail != NULL) && (pLmCmp (tail, monom) >= 0))
     3736    {
     3737      if(p_LmDivisibleBy (monom, tail, c->r))
     3738      {
     3739        did_something = TRUE;
     3740        prev->next = tail->next;
     3741        tail->next = NULL;
     3742        p_Delete (&tail, c->r);
     3743        tail = prev;
     3744        //PrintS("Shortened");
     3745        c->lengths[i]--;
    38223746      }
    38233747      prev = tail;
    38243748      tail = tail->next;
    38253749    }
    3826     if (did_something)
     3750    if(did_something)
    38273751    {
    38283752      int new_pos;
     
    38333757      int old_pos = -1;
    38343758      //assume new_pos<old_pos
    3835       for (int z = 0; z <= c->strat->sl; z++)
    3836       {
    3837         if (c->strat->S[z] == c->S->m[i])
    3838         {
    3839           old_pos = z;
    3840           break;
    3841         }
    3842       }
    3843       if (old_pos == -1)
    3844         for (int z = new_pos - 1; z >= 0; z--)
    3845         {
    3846           if (c->strat->S[z] == c->S->m[i])
    3847           {
    3848             old_pos = z;
    3849             break;
    3850           }
    3851         }
     3759      for(int z = 0; z <= c->strat->sl; z++)
     3760      {
     3761        if(c->strat->S[z] == c->S->m[i])
     3762        {
     3763          old_pos = z;
     3764          break;
     3765        }
     3766      }
     3767      if(old_pos == -1)
     3768        for(int z = new_pos - 1; z >= 0; z--)
     3769        {
     3770          if(c->strat->S[z] == c->S->m[i])
     3771          {
     3772            old_pos = z;
     3773            break;
     3774          }
     3775        }
    38523776      assume (old_pos >= 0);
    38533777      assume (new_pos <= old_pos);
    38543778      assume (pLength (c->strat->S[old_pos]) == c->lengths[i]);
    38553779      c->strat->lenS[old_pos] = c->lengths[i];
    3856       if (c->strat->lenSw)
    3857         c->strat->lenSw[old_pos] = q;
    3858       if (new_pos < old_pos)
    3859         move_forward_in_S (old_pos, new_pos, c->strat);
     3780      if(c->strat->lenSw)
     3781        c->strat->lenSw[old_pos] = q;
     3782      if(new_pos < old_pos)
     3783        move_forward_in_S (old_pos, new_pos, c->strat);
    38603784      length_one_crit (c, i, c->lengths[i]);
    38613785    }
     
    38633787}
    38643788
    3865 #if 0                           // currently unused
    3866 static sorted_pair_node *
    3867 pop_pair (slimgb_alg * c)
     3789#if 0                           // currently unused
     3790static sorted_pair_node *pop_pair (slimgb_alg * c)
    38683791{
    38693792  clean_top_of_pair_list (c);
    38703793
    3871   if (c->pair_top < 0)
     3794  if(c->pair_top < 0)
    38723795    return NULL;
    38733796  else
     
    38763799#endif
    38773800
    3878 void
    3879 slimgb_alg::cleanDegs (int lower, int upper)
     3801void slimgb_alg::cleanDegs (int lower, int upper)
    38803802{
    38813803  assume (is_homog);
    38823804  int deg;
    3883   if (TEST_OPT_PROT)
     3805  if(TEST_OPT_PROT)
    38843806  {
    38853807    PrintS ("C");
    38863808  }
    3887   for (deg = lower; deg <= upper; deg++)
     3809  for(deg = lower; deg <= upper; deg++)
    38883810  {
    38893811    int i;
    3890     for (i = 0; i < n; i++)
    3891     {
    3892       if (T_deg[i] == deg)
    3893       {
    3894         poly h;
    3895         h = S->m[i];
    3896         h = redNFTail (h, strat->sl, strat, lengths[i]);
    3897         if (!rField_is_Zp (r))
    3898         {
    3899           p_Cleardenom (h, r);
    3900           //p_Content(h,r);
    3901         }
    3902         else
    3903           pNorm (h);
    3904         //TODO:GCD of TERMS
    3905         poly got =::gcd_of_terms (h, r);
    3906         p_Delete (&gcd_of_terms[i], r);
    3907         gcd_of_terms[i] = got;
    3908         int len = pLength (h);
    3909         wlen_type wlen = pQuality (h, this, len);
    3910         if (weighted_lengths)
    3911           weighted_lengths[i] = wlen;
    3912         lengths[i] = len;
    3913         assume (h == S->m[i]);
    3914         int j;
    3915         for (j = 0; j <= strat->sl; j++)
    3916         {
    3917           if (h == strat->S[j])
    3918           {
    3919             int new_pos = simple_posInS (strat, h, len, wlen);
    3920             if (strat->lenS)
    3921             {
    3922               strat->lenS[j] = len;
    3923             }
    3924             if (strat->lenSw)
    3925             {
    3926               strat->lenSw[j] = wlen;
    3927             }
    3928             if (new_pos < j)
    3929             {
    3930               move_forward_in_S (j, new_pos, strat);
    3931             }
    3932             else
    3933             {
    3934               if (new_pos > j)
    3935                 new_pos = new_pos - 1;  //is identical with one element
    3936               if (new_pos > j)
    3937                 move_backward_in_S (j, new_pos, strat);
    3938             }
    3939             break;
    3940           }
    3941         }
     3812    for(i = 0; i < n; i++)
     3813    {
     3814      if(T_deg[i] == deg)
     3815      {
     3816        poly h;
     3817        h = S->m[i];
     3818        h = redNFTail (h, strat->sl, strat, lengths[i]);
     3819        if(!rField_is_Zp (r))
     3820        {
     3821          p_Cleardenom (h, r);
     3822          //p_Content(h,r);
     3823        }
     3824        else
     3825          pNorm (h);
     3826        //TODO:GCD of TERMS
     3827        poly got =::gcd_of_terms (h, r);
     3828        p_Delete (&gcd_of_terms[i], r);
     3829        gcd_of_terms[i] = got;
     3830        int len = pLength (h);
     3831        wlen_type wlen = pQuality (h, this, len);
     3832        if(weighted_lengths)
     3833          weighted_lengths[i] = wlen;
     3834        lengths[i] = len;
     3835        assume (h == S->m[i]);
     3836        int j;
     3837        for(j = 0; j <= strat->sl; j++)
     3838        {
     3839          if(h == strat->S[j])
     3840          {
     3841            int new_pos = simple_posInS (strat, h, len, wlen);
     3842            if(strat->lenS)
     3843            {
     3844              strat->lenS[j] = len;
     3845            }
     3846            if(strat->lenSw)
     3847            {
     3848              strat->lenSw[j] = wlen;
     3849            }
     3850            if(new_pos < j)
     3851            {
     3852              move_forward_in_S (j, new_pos, strat);
     3853            }
     3854            else
     3855            {
     3856              if(new_pos > j)
     3857                new_pos = new_pos - 1;  //is identical with one element
     3858              if(new_pos > j)
     3859                move_backward_in_S (j, new_pos, strat);
     3860            }
     3861            break;
     3862          }
     3863        }
    39423864      }
    39433865    }
     
    39453867  {
    39463868    int i, j;
    3947     for (i = 0; i < this->n; i++)
    3948     {
    3949       for (j = 0; j < i; j++)
    3950       {
    3951         if (T_deg[i] + T_deg[j] <= upper)
    3952         {
    3953           now_t_rep (i, j, this);
    3954         }
     3869    for(i = 0; i < this->n; i++)
     3870    {
     3871      for(j = 0; j < i; j++)
     3872      {
     3873        if(T_deg[i] + T_deg[j] <= upper)
     3874        {
     3875          now_t_rep (i, j, this);
     3876        }
    39553877      }
    39563878    }
     
    39603882}
    39613883
    3962 sorted_pair_node *
    3963 top_pair (slimgb_alg * c)
    3964 {
    3965   while (c->pair_top >= 0)
    3966   {
    3967     super_clean_top_of_pair_list (c);   //yeah, I know, it's odd that I use a different proc here
    3968     if ((c->is_homog) && (c->pair_top >= 0)
    3969         && (c->apairs[c->pair_top]->deg >= c->lastCleanedDeg + 2))
     3884sorted_pair_node *top_pair (slimgb_alg * c)
     3885{
     3886  while(c->pair_top >= 0)
     3887  {
     3888    super_clean_top_of_pair_list (c);   //yeah, I know, it's odd that I use a different proc here
     3889    if((c->is_homog) && (c->pair_top >= 0)
     3890       && (c->apairs[c->pair_top]->deg >= c->lastCleanedDeg + 2))
    39703891    {
    39713892      int upper = c->apairs[c->pair_top]->deg - 1;
     
    39793900  }
    39803901
    3981   if (c->pair_top < 0)
     3902  if(c->pair_top < 0)
    39823903    return NULL;
    39833904  else
     
    39853906}
    39863907
    3987 sorted_pair_node *
    3988 quick_pop_pair (slimgb_alg * c)
    3989 {
    3990   if (c->pair_top < 0)
     3908sorted_pair_node *quick_pop_pair (slimgb_alg * c)
     3909{
     3910  if(c->pair_top < 0)
    39913911    return NULL;
    39923912  else
     
    39943914}
    39953915
    3996 static void
    3997 super_clean_top_of_pair_list (slimgb_alg * c)
    3998 {
    3999   while ((c->pair_top >= 0)
    4000          && (c->apairs[c->pair_top]->i >= 0)
    4001          &&
    4002          (good_has_t_rep
    4003           (c->apairs[c->pair_top]->j, c->apairs[c->pair_top]->i, c)))
     3916static void super_clean_top_of_pair_list (slimgb_alg * c)
     3917{
     3918  while((c->pair_top >= 0)
     3919        && (c->apairs[c->pair_top]->i >= 0)
     3920        &&
     3921        (good_has_t_rep
     3922         (c->apairs[c->pair_top]->j, c->apairs[c->pair_top]->i, c)))
    40043923  {
    40053924    free_sorted_pair_node (c->apairs[c->pair_top], c->r);
     
    40083927}
    40093928
    4010 void
    4011 clean_top_of_pair_list (slimgb_alg * c)
    4012 {
    4013   while ((c->pair_top >= 0) && (c->apairs[c->pair_top]->i >= 0)
    4014          &&
    4015          (!state_is
    4016           (UNCALCULATED, c->apairs[c->pair_top]->j, c->apairs[c->pair_top]->i,
    4017            c)))
     3929void clean_top_of_pair_list (slimgb_alg * c)
     3930{
     3931  while((c->pair_top >= 0) && (c->apairs[c->pair_top]->i >= 0)
     3932        &&
     3933        (!state_is
     3934         (UNCALCULATED, c->apairs[c->pair_top]->j, c->apairs[c->pair_top]->i,
     3935          c)))
    40183936  {
    40193937    free_sorted_pair_node (c->apairs[c->pair_top], c->r);
     
    40243942static BOOLEAN
    40253943state_is (calc_state state, const int &arg_i, const int &arg_j,
    4026           slimgb_alg * c)
     3944          slimgb_alg * c)
    40273945{
    40283946  assume (0 <= arg_i);
     
    40303948  assume (arg_i < c->n);
    40313949  assume (arg_j < c->n);
    4032   if (arg_i == arg_j)
     3950  if(arg_i == arg_j)
    40333951  {
    40343952    return (TRUE);
    40353953  }
    4036   if (arg_i > arg_j)
     3954  if(arg_i > arg_j)
    40373955  {
    40383956    return (c->states[arg_i][arg_j] == state);
     
    40423960}
    40433961
    4044 void
    4045 free_sorted_pair_node (sorted_pair_node * s, ring r)
    4046 {
    4047   if (s->i >= 0)
     3962void free_sorted_pair_node (sorted_pair_node * s, ring r)
     3963{
     3964  if(s->i >= 0)
    40483965    p_Delete (&s->lcm_of_lm, r);
    40493966  omfree (s);
     
    40533970pair_better (sorted_pair_node * a, sorted_pair_node * b, slimgb_alg * c)
    40543971{
    4055   if (a->deg < b->deg)
     3972  if(a->deg < b->deg)
    40563973    return TRUE;
    4057   if (a->deg > b->deg)
     3974  if(a->deg > b->deg)
    40583975    return FALSE;
    40593976
    40603977  int comp = pLmCmp (a->lcm_of_lm, b->lcm_of_lm);
    4061   if (comp == 1)
     3978  if(comp == 1)
    40623979    return FALSE;
    4063   if (-1 == comp)
     3980  if(-1 == comp)
    40643981    return TRUE;
    4065   if (a->expected_length < b->expected_length)
     3982  if(a->expected_length < b->expected_length)
    40663983    return TRUE;
    4067   if (a->expected_length > b->expected_length)
     3984  if(a->expected_length > b->expected_length)
    40683985    return FALSE;
    4069   if (a->i + a->j < b->i + b->j)
     3986  if(a->i + a->j < b->i + b->j)
    40703987    return TRUE;
    4071   if (a->i + a->j > b->i + b->j)
     3988  if(a->i + a->j > b->i + b->j)
    40723989    return FALSE;
    4073   if (a->i < b->i)
     3990  if(a->i < b->i)
    40743991    return TRUE;
    4075   if (a->i > b->i)
     3992  if(a->i > b->i)
    40763993    return FALSE;
    40773994  return TRUE;
    40783995}
    40793996
    4080 static int
    4081 tgb_pair_better_gen (const void *ap, const void *bp)
     3997static int tgb_pair_better_gen (const void *ap, const void *bp)
    40823998{
    40833999  sorted_pair_node *a = *((sorted_pair_node **) ap);
     
    40854001  assume ((a->i > a->j) || (a->i < 0));
    40864002  assume ((b->i > b->j) || (b->i < 0));
    4087   if (a->deg < b->deg)
     4003  if(a->deg < b->deg)
    40884004    return -1;
    4089   if (a->deg > b->deg)
     4005  if(a->deg > b->deg)
    40904006    return 1;
    40914007
    40924008  int comp = pLmCmp (a->lcm_of_lm, b->lcm_of_lm);
    40934009
    4094   if (comp == 1)
     4010  if(comp == 1)
    40954011    return 1;
    4096   if (-1 == comp)
     4012  if(-1 == comp)
    40974013    return -1;
    4098   if (a->expected_length < b->expected_length)
     4014  if(a->expected_length < b->expected_length)
    40994015    return -1;
    4100   if (a->expected_length > b->expected_length)
     4016  if(a->expected_length > b->expected_length)
    41014017    return 1;
    4102   if (a->i + a->j < b->i + b->j)
     4018  if(a->i + a->j < b->i + b->j)
    41034019    return -1;
    4104   if (a->i + a->j > b->i + b->j)
     4020  if(a->i + a->j > b->i + b->j)
    41054021    return 1;
    4106   if (a->i < b->i)
     4022  if(a->i < b->i)
    41074023    return -1;
    4108   if (a->i > b->i)
     4024  if(a->i > b->i)
    41094025    return 1;
    41104026  return 0;
    41114027}
    41124028
    4113 static poly
    4114 gcd_of_terms (poly p, ring r)
     4029static poly gcd_of_terms (poly p, ring r)
    41154030{
    41164031  int max_g_0 = 0;
     
    41194034  poly m = pOne ();
    41204035  poly t;
    4121   for (i = pVariables; i; i--)
     4036  for(i = pVariables; i; i--)
    41224037  {
    41234038    pSetExp (m, i, pGetExp (p, i));
    4124     if (max_g_0 == 0)
    4125       if (pGetExp (m, i) > 0)
    4126         max_g_0 = i;
     4039    if(max_g_0 == 0)
     4040      if(pGetExp (m, i) > 0)
     4041        max_g_0 = i;
    41274042  }
    41284043
    41294044  t = p->next;
    4130   while (t != NULL)
    4131   {
    4132     if (max_g_0 == 0)
     4045  while(t != NULL)
     4046  {
     4047    if(max_g_0 == 0)
    41334048      break;
    4134     for (i = max_g_0; i; i--)
     4049    for(i = max_g_0; i; i--)
    41354050    {
    41364051      pSetExp (m, i, si_min (pGetExp (t, i), pGetExp (m, i)));
    4137       if (max_g_0 == i)
    4138         if (pGetExp (m, i) == 0)
    4139           max_g_0 = 0;
    4140       if ((max_g_0 == 0) && (pGetExp (m, i) > 0))
    4141       {
    4142         max_g_0 = i;
     4052      if(max_g_0 == i)
     4053        if(pGetExp (m, i) == 0)
     4054          max_g_0 = 0;
     4055      if((max_g_0 == 0) && (pGetExp (m, i) > 0))
     4056      {
     4057        max_g_0 = i;
    41434058      }
    41444059    }
     
    41464061  }
    41474062  p_Setm (m, r);
    4148   if (max_g_0 > 0)
     4063  if(max_g_0 > 0)
    41494064    return m;
    41504065  pDelete (&m);
     
    41524067}
    41534068
    4154 static inline BOOLEAN
    4155 pHasNotCFExtended (poly p1, poly p2, poly m)
    4156 {
    4157 
    4158   if (pGetComp (p1) > 0 || pGetComp (p2) > 0)
     4069static inline BOOLEAN pHasNotCFExtended (poly p1, poly p2, poly m)
     4070{
     4071
     4072  if(pGetComp (p1) > 0 || pGetComp (p2) > 0)
    41594073    return FALSE;
    41604074  int i = 1;
    41614075  loop
    41624076  {
    4163     if ((pGetExp (p1, i) - pGetExp (m, i) > 0)
    4164         && (pGetExp (p2, i) - pGetExp (m, i) > 0))
     4077    if((pGetExp (p1, i) - pGetExp (m, i) > 0)
     4078       && (pGetExp (p2, i) - pGetExp (m, i) > 0))
    41654079      return FALSE;
    4166     if (i == pVariables)
     4080    if(i == pVariables)
    41674081      return TRUE;
    41684082    i++;
     
    41734087static inline BOOLEAN
    41744088extended_product_criterion (poly p1, poly gcd1, poly p2, poly gcd2,
    4175                             slimgb_alg * c)
    4176 {
    4177   if (c->nc)
     4089                            slimgb_alg * c)
     4090{
     4091  if(c->nc)
    41784092    return FALSE;
    4179   if (gcd1 == NULL)
     4093  if(gcd1 == NULL)
    41804094    return FALSE;
    4181   if (gcd2 == NULL)
     4095  if(gcd2 == NULL)
    41824096    return FALSE;
    4183   gcd1->next = gcd2;            //may ordered incorrect
     4097  gcd1->next = gcd2;            //may ordered incorrect
    41844098  poly m = gcd_of_terms (gcd1, c->r);
    41854099  gcd1->next = NULL;
    4186   if (m == NULL)
     4100  if(m == NULL)
    41874101    return FALSE;
    41884102
     
    41924106}
    41934107
    4194 #if 0                           //currently unused
    4195 static poly
    4196 kBucketGcd (kBucket * b, ring r)
     4108#if 0                           //currently unused
     4109static poly kBucketGcd (kBucket * b, ring r)
    41974110{
    41984111  int s = 0;
     
    42004113  poly m, n;
    42014114  BOOLEAN initialized = FALSE;
    4202   for (i = MAX_BUCKET - 1; i >= 0; i--)
    4203   {
    4204     if (b->buckets[i] != NULL)
    4205     {
    4206       if (!initialized)
    4207       {
    4208         m = gcd_of_terms (b->buckets[i], r);
    4209         initialized = TRUE;
    4210         if (m == NULL)
    4211           return NULL;
     4115  for(i = MAX_BUCKET - 1; i >= 0; i--)
     4116  {
     4117    if(b->buckets[i] != NULL)
     4118    {
     4119      if(!initialized)
     4120      {
     4121        m = gcd_of_terms (b->buckets[i], r);
     4122        initialized = TRUE;
     4123        if(m == NULL)
     4124          return NULL;
    42124125      }
    42134126      else
    42144127      {
    4215         n = gcd_of_terms (b->buckets[i], r);
    4216         if (n == NULL)
    4217         {
    4218           pDelete (&m);
    4219           return NULL;
    4220         }
    4221         n->next = m;
    4222         poly t = gcd_of_terms (n, r);
    4223         n->next = NULL;
    4224         pDelete (&m);
    4225         pDelete (&n);
    4226         m = t;
    4227         if (m == NULL)
    4228           return NULL;
     4128        n = gcd_of_terms (b->buckets[i], r);
     4129        if(n == NULL)
     4130        {
     4131          pDelete (&m);
     4132          return NULL;
     4133        }
     4134        n->next = m;
     4135        poly t = gcd_of_terms (n, r);
     4136        n->next = NULL;
     4137        pDelete (&m);
     4138        pDelete (&n);
     4139        m = t;
     4140        if(m == NULL)
     4141          return NULL;
    42294142
    42304143      }
     
    42354148#endif
    42364149
    4237 static inline wlen_type
    4238 quality_of_pos_in_strat_S (int pos, slimgb_alg * c)
    4239 {
    4240   if (c->strat->lenSw != NULL)
     4150static inline wlen_type quality_of_pos_in_strat_S (int pos, slimgb_alg * c)
     4151{
     4152  if(c->strat->lenSw != NULL)
    42414153    return c->strat->lenSw[pos];
    42424154  return c->strat->lenS[pos];
     
    42604172static void
    42614173multi_reduction_lls_trick (red_object * los, int losl, slimgb_alg * c,
    4262                            find_erg & erg)
     4174                           find_erg & erg)
    42634175{
    42644176  erg.expand = NULL;
    4265   BOOLEAN swap_roles;           //from reduce_by, to_reduce_u if fromS
    4266   if (erg.fromS)
    4267   {
    4268     if (pLmEqual (c->strat->S[erg.reduce_by], los[erg.to_reduce_u].p))
     4177  BOOLEAN swap_roles;           //from reduce_by, to_reduce_u if fromS
     4178  if(erg.fromS)
     4179  {
     4180    if(pLmEqual (c->strat->S[erg.reduce_by], los[erg.to_reduce_u].p))
    42694181    {
    42704182      wlen_type quality_a = quality_of_pos_in_strat_S (erg.reduce_by, c);
     
    42844196      wlen_type qc;
    42854197      best = find_best (los, erg.to_reduce_l, erg.to_reduce_u, qc, c);
    4286       if (qc < quality_a)
    4287       {
    4288         los[best].flatten ();
    4289         int b_pos = kBucketCanonicalize (los[best].bucket);
    4290         los[best].p = los[best].bucket->buckets[b_pos];
    4291         qc = pQuality (los[best].bucket->buckets[b_pos], c);
    4292         if (qc < quality_a)
    4293         {
    4294           red_object h = los[erg.to_reduce_u];
    4295           los[erg.to_reduce_u] = los[best];
    4296           los[best] = h;
    4297           swap_roles = TRUE;
    4298         }
    4299         else
    4300           swap_roles = FALSE;
     4198      if(qc < quality_a)
     4199      {
     4200        los[best].flatten ();
     4201        int b_pos = kBucketCanonicalize (los[best].bucket);
     4202        los[best].p = los[best].bucket->buckets[b_pos];
     4203        qc = pQuality (los[best].bucket->buckets[b_pos], c);
     4204        if(qc < quality_a)
     4205        {
     4206          red_object h = los[erg.to_reduce_u];
     4207          los[erg.to_reduce_u] = los[best];
     4208          los[best] = h;
     4209          swap_roles = TRUE;
     4210        }
     4211        else
     4212          swap_roles = FALSE;
    43014213      }
    43024214      else
    43034215      {
    4304         swap_roles = FALSE;
     4216        swap_roles = FALSE;
    43054217      }
    43064218    }
    43074219    else
    43084220    {
    4309       if (erg.to_reduce_u > erg.to_reduce_l)
    4310       {
    4311         wlen_type quality_a = quality_of_pos_in_strat_S (erg.reduce_by, c);
     4221      if(erg.to_reduce_u > erg.to_reduce_l)
     4222      {
     4223        wlen_type quality_a = quality_of_pos_in_strat_S (erg.reduce_by, c);
    43124224#ifdef HAVE_PLURAL
    4313         if ((c->nc) && (!(rIsSCA (c->r))))
    4314           quality_a =
    4315             quality_of_pos_in_strat_S_mult_high (erg.reduce_by,
    4316                                                 los[erg.to_reduce_u].p, c);
    4317 #endif
    4318         int best = erg.to_reduce_u + 1;
    4319         wlen_type qc;
    4320         best = find_best (los, erg.to_reduce_l, erg.to_reduce_u, qc, c);
    4321         assume (qc == los[best].guess_quality (c));
    4322         if (qc < quality_a)
    4323         {
    4324           los[best].flatten ();
    4325           int b_pos = kBucketCanonicalize (los[best].bucket);
    4326           los[best].p = los[best].bucket->buckets[b_pos];
    4327           qc = pQuality (los[best].bucket->buckets[b_pos], c);
    4328           //(best!=erg.to_reduce_u+1)
    4329           if (qc < quality_a)
    4330           {
    4331             red_object h = los[erg.to_reduce_u];
    4332             los[erg.to_reduce_u] = los[best];
    4333             los[best] = h;
    4334             erg.reduce_by = erg.to_reduce_u;
    4335             erg.fromS = FALSE;
    4336             erg.to_reduce_u--;
    4337           }
    4338         }
     4225        if((c->nc) && (!(rIsSCA (c->r))))
     4226          quality_a =
     4227            quality_of_pos_in_strat_S_mult_high (erg.reduce_by,
     4228                                                los[erg.to_reduce_u].p, c);
     4229#endif
     4230        int best = erg.to_reduce_u + 1;
     4231        wlen_type qc;
     4232        best = find_best (los, erg.to_reduce_l, erg.to_reduce_u, qc, c);
     4233        assume (qc == los[best].guess_quality (c));
     4234        if(qc < quality_a)
     4235        {
     4236          los[best].flatten ();
     4237          int b_pos = kBucketCanonicalize (los[best].bucket);
     4238          los[best].p = los[best].bucket->buckets[b_pos];
     4239          qc = pQuality (los[best].bucket->buckets[b_pos], c);
     4240          //(best!=erg.to_reduce_u+1)
     4241          if(qc < quality_a)
     4242          {
     4243            red_object h = los[erg.to_reduce_u];
     4244            los[erg.to_reduce_u] = los[best];
     4245            los[best] = h;
     4246            erg.reduce_by = erg.to_reduce_u;
     4247            erg.fromS = FALSE;
     4248            erg.to_reduce_u--;
     4249          }
     4250        }
    43394251      }
    43404252      else
    43414253      {
    4342         assume (erg.to_reduce_u == erg.to_reduce_l);
    4343         wlen_type quality_a = quality_of_pos_in_strat_S (erg.reduce_by, c);
    4344         wlen_type qc = los[erg.to_reduce_u].guess_quality (c);
    4345         if (qc < 0)
    4346           PrintS ("Wrong wlen_type");
    4347         if (qc < quality_a)
    4348         {
    4349           int best = erg.to_reduce_u;
    4350           los[best].flatten ();
    4351           int b_pos = kBucketCanonicalize (los[best].bucket);
    4352           los[best].p = los[best].bucket->buckets[b_pos];
    4353           qc = pQuality (los[best].bucket->buckets[b_pos], c);
    4354           assume (qc >= 0);
    4355           if (qc < quality_a)
    4356           {
    4357             BOOLEAN exp = FALSE;
    4358             if (qc <= 2)
    4359             {
    4360               //Print("\n qc is %lld \n",qc);
    4361               exp = TRUE;
    4362             }
    4363             else
    4364             {
    4365               if (qc < quality_a / 2)
    4366                 exp = TRUE;
    4367               else if (erg.reduce_by < c->n / 4)
    4368                 exp = TRUE;
    4369             }
    4370             if (exp)
    4371             {
    4372               poly clear_into;
    4373               los[erg.to_reduce_u].flatten ();
    4374               kBucketClear (los[erg.to_reduce_u].bucket, &clear_into,
    4375                             &erg.expand_length);
    4376               erg.expand = pCopy (clear_into);
    4377               kBucketInit (los[erg.to_reduce_u].bucket, clear_into,
    4378                            erg.expand_length);
    4379               if (TEST_OPT_PROT)
    4380                 PrintS ("e");
    4381             }
    4382           }
    4383         }
     4254        assume (erg.to_reduce_u == erg.to_reduce_l);
     4255        wlen_type quality_a = quality_of_pos_in_strat_S (erg.reduce_by, c);
     4256        wlen_type qc = los[erg.to_reduce_u].guess_quality (c);
     4257        if(qc < 0)
     4258          PrintS ("Wrong wlen_type");
     4259        if(qc < quality_a)
     4260        {
     4261          int best = erg.to_reduce_u;
     4262          los[best].flatten ();
     4263          int b_pos = kBucketCanonicalize (los[best].bucket);
     4264          los[best].p = los[best].bucket->buckets[b_pos];
     4265          qc = pQuality (los[best].bucket->buckets[b_pos], c);
     4266          assume (qc >= 0);
     4267          if(qc < quality_a)
     4268          {
     4269            BOOLEAN exp = FALSE;
     4270            if(qc <= 2)
     4271            {
     4272              //Print("\n qc is %lld \n",qc);
     4273              exp = TRUE;
     4274            }
     4275            else
     4276            {
     4277              if(qc < quality_a / 2)
     4278                exp = TRUE;
     4279              else if(erg.reduce_by < c->n / 4)
     4280                exp = TRUE;
     4281            }
     4282            if(exp)
     4283            {
     4284              poly clear_into;
     4285              los[erg.to_reduce_u].flatten ();
     4286              kBucketClear (los[erg.to_reduce_u].bucket, &clear_into,
     4287                            &erg.expand_length);
     4288              erg.expand = pCopy (clear_into);
     4289              kBucketInit (los[erg.to_reduce_u].bucket, clear_into,
     4290                           erg.expand_length);
     4291              if(TEST_OPT_PROT)
     4292                PrintS ("e");
     4293            }
     4294          }
     4295        }
    43844296      }
    43854297
     
    43904302  else
    43914303  {
    4392     if (erg.reduce_by > erg.to_reduce_u)
     4304    if(erg.reduce_by > erg.to_reduce_u)
    43934305    {
    43944306      //then lm(rb)>= lm(tru) so =
     
    43994311      best = find_best (los, erg.to_reduce_l, erg.to_reduce_u, qc, c);
    44004312
    4401       if (qc < quality_a)
    4402       {
    4403         red_object h = los[erg.reduce_by];
    4404         los[erg.reduce_by] = los[best];
    4405         los[best] = h;
     4313      if(qc < quality_a)
     4314      {
     4315        red_object h = los[erg.reduce_by];
     4316        los[erg.reduce_by] = los[best];
     4317        los[best] = h;
    44064318      }
    44074319      swap_roles = FALSE;
     
    44174329      wlen_type quality_a = los[erg.reduce_by].guess_quality (c);
    44184330      wlen_type qc;
    4419       while ((il > 0) && pLmEqual (los[il - 1].p, los[il].p))
    4420       {
    4421         il--;
    4422         qc = los[il].guess_quality (c);
    4423         if (qc < quality_a)
    4424         {
    4425           quality_a = qc;
    4426           erg.reduce_by = il;
    4427         }
     4331      while((il > 0) && pLmEqual (los[il - 1].p, los[il].p))
     4332      {
     4333        il--;
     4334        qc = los[il].guess_quality (c);
     4335        if(qc < quality_a)
     4336        {
     4337          quality_a = qc;
     4338          erg.reduce_by = il;
     4339        }
    44284340      }
    44294341      swap_roles = FALSE;
    44304342    }
    44314343  }
    4432   if (swap_roles)
    4433   {
    4434     if (TEST_OPT_PROT)
     4344  if(swap_roles)
     4345  {
     4346    if(TEST_OPT_PROT)
    44354347      PrintS ("b");
    44364348    poly clear_into;
    44374349    int new_length;
    4438     int bp = erg.to_reduce_u;   //bucket_positon
     4350    int bp = erg.to_reduce_u;   //bucket_positon
    44394351    //kBucketClear(los[bp].bucket,&clear_into,&new_length);
    44404352    new_length = los[bp].clear_to_poly ();
     
    44424354    poly p = c->strat->S[erg.reduce_by];
    44434355    int j = erg.reduce_by;
    4444     int old_length = c->strat->lenS[j]; // in view of S
     4356    int old_length = c->strat->lenS[j]; // in view of S
    44454357    los[bp].p = p;
    4446     if (c->eliminationProblem)
     4358    if(c->eliminationProblem)
    44474359    {
    44484360      los[bp].sugar = c->pTotaldegree_full (p);
     
    44554367    new_pos = simple_posInS (c->strat, clear_into, new_length, qal);
    44564368    assume (new_pos <= j);
    4457     for (z = c->n; z; z--)
    4458     {
    4459       if (p == c->S->m[z - 1])
    4460       {
    4461         pos_in_c = z - 1;
    4462         break;
     4369    for(z = c->n; z; z--)
     4370    {
     4371      if(p == c->S->m[z - 1])
     4372      {
     4373        pos_in_c = z - 1;
     4374        break;
    44634375      }
    44644376    }
     
    44664378    int tdeg_full = -1;
    44674379    int tdeg = -1;
    4468     if (pos_in_c >= 0)
     4380    if(pos_in_c >= 0)
    44694381    {
    44704382#ifdef TGB_RESORT_PAIRS
     
    44764388      c->lengths[pos_in_c] = new_length;
    44774389      c->weighted_lengths[pos_in_c] = qal;
    4478       if (c->gcd_of_terms[pos_in_c] == NULL)
    4479         c->gcd_of_terms[pos_in_c] = gcd_of_terms (clear_into, c->r);
    4480       if (c->T_deg_full)
    4481         tdeg_full = c->T_deg_full[pos_in_c] =
    4482           c->pTotaldegree_full (clear_into);
     4390      if(c->gcd_of_terms[pos_in_c] == NULL)
     4391        c->gcd_of_terms[pos_in_c] = gcd_of_terms (clear_into, c->r);
     4392      if(c->T_deg_full)
     4393        tdeg_full = c->T_deg_full[pos_in_c] =
     4394          c->pTotaldegree_full (clear_into);
    44834395      else
    4484         tdeg_full = tdeg;
     4396        tdeg_full = tdeg;
    44854397      c_S_element_changed_hook (pos_in_c, c);
    44864398    }
    44874399    else
    44884400    {
    4489       if (c->eliminationProblem)
    4490       {
    4491         tdeg_full = c->pTotaldegree_full (clear_into);
    4492         tdeg = c->pTotaldegree (clear_into);
     4401      if(c->eliminationProblem)
     4402      {
     4403        tdeg_full = c->pTotaldegree_full (clear_into);
     4404        tdeg = c->pTotaldegree (clear_into);
    44934405      }
    44944406    }
     
    44974409
    44984410    assume (pLength (clear_into) == new_length);
    4499     if (c->strat->lenSw != NULL)
     4411    if(c->strat->lenSw != NULL)
    45004412      c->strat->lenSw[j] = qal;
    4501     if (!rField_is_Zp (c->r))
    4502     {
    4503       p_Cleardenom (clear_into, c->r);  //should be unnecessary
     4413    if(!rField_is_Zp (c->r))
     4414    {
     4415      p_Cleardenom (clear_into, c->r);  //should be unnecessary
    45044416      //p_Content(clear_into, c->r);
    45054417    }
     
    45124424    //input polys
    45134425#else
    4514     if (new_pos < j)
    4515     {
    4516       if (c->strat->honey)
    4517         c->strat->ecartS[j] = tdeg_full - tdeg;
     4426    if(new_pos < j)
     4427    {
     4428      if(c->strat->honey)
     4429        c->strat->ecartS[j] = tdeg_full - tdeg;
    45184430      move_forward_in_S (j, new_pos, c->strat);
    45194431      erg.reduce_by = new_pos;
     
    45234435}
    45244436
    4525 static int
    4526 fwbw (red_object * los, int i)
     4437static int fwbw (red_object * los, int i)
    45274438{
    45284439  int i2 = i;
     
    45324443  BOOLEAN incr = TRUE;
    45334444
    4534   while (1)
    4535   {
    4536     if (!bw)
     4445  while(1)
     4446  {
     4447    if(!bw)
    45374448    {
    45384449      step = si_min (i2, step);
    4539       if (step == 0)
    4540         break;
     4450      if(step == 0)
     4451        break;
    45414452      i2 -= step;
    45424453
    4543       if (!pLmEqual (los[i].p, los[i2].p))
    4544       {
    4545         bw = TRUE;
    4546         incr = FALSE;
     4454      if(!pLmEqual (los[i].p, los[i2].p))
     4455      {
     4456        bw = TRUE;
     4457        incr = FALSE;
    45474458      }
    45484459      else
    45494460      {
    4550         if ((!incr) && (step == 1))
    4551           break;
     4461        if((!incr) && (step == 1))
     4462          break;
    45524463      }
    45534464    }
     
    45554466    {
    45564467      step = si_min (i - i2, step);
    4557       if (step == 0)
    4558         break;
     4468      if(step == 0)
     4469        break;
    45594470      i2 += step;
    4560       if (pLmEqual (los[i].p, los[i2].p))
    4561       {
    4562         if (step == 1)
    4563           break;
    4564         else
    4565         {
    4566           bw = FALSE;
    4567         }
    4568       }
    4569     }
    4570     if (incr)
     4471      if(pLmEqual (los[i].p, los[i2].p))
     4472      {
     4473        if(step == 1)
     4474          break;
     4475        else
     4476        {
     4477          bw = FALSE;
     4478        }
     4479      }
     4480    }
     4481    if(incr)
    45714482      step *= 2;
    45724483    else
    45734484    {
    4574       if (step % 2 == 1)
    4575         step = (step + 1) / 2;
     4485      if(step % 2 == 1)
     4486        step = (step + 1) / 2;
    45764487      else
    4577         step /= 2;
     4488        step /= 2;
    45784489    }
    45794490  }
     
    45864497  assume (l <= u + 1);
    45874498  int i;
    4588   for (i = l; i <= u; i++)
     4499  for(i = l; i <= u; i++)
    45894500  {
    45904501    kBucketCanonicalize (los[i].bucket);
     
    45944505static void
    45954506multi_reduction_find (red_object * los, int losl, slimgb_alg * c, int startf,
    4596                       find_erg & erg)
     4507                      find_erg & erg)
    45974508{
    45984509  kStrategy strat = c->strat;
     
    46004511  assume (startf <= losl);
    46014512  assume ((startf == losl - 1)
    4602           || (pLmCmp (los[startf].p, los[startf + 1].p) == -1));
     4513          || (pLmCmp (los[startf].p, los[startf + 1].p) == -1));
    46034514  int i = startf;
    46044515
    46054516  int j;
    4606   while (i >= 0)
     4517  while(i >= 0)
    46074518  {
    46084519    assume ((i == losl - 1) || (pLmCmp (los[i].p, los[i + 1].p) <= 0));
    46094520    assume (is_valid_ro (los[i]));
    46104521    assume ((!(c->eliminationProblem))
    4611             || (los[i].sugar >= c->pTotaldegree (los[i].p)));
     4522            || (los[i].sugar >= c->pTotaldegree (los[i].p)));
    46124523    j = kFindDivisibleByInS_easy (strat, los[i]);
    4613     if (j >= 0)
     4524    if(j >= 0)
    46144525    {
    46154526      erg.to_reduce_u = i;
     
    46264537      return;
    46274538    }
    4628     if (j < 0)
     4539    if(j < 0)
    46294540    {
    46304541      //not reduceable, try to use this for reducing higher terms
     
    46334544      assume ((i2 == 0) || (!pLmEqual (los[i2].p, los[i2 - 1].p)));
    46344545      assume (i >= i2);
    4635       if (i2 != i)
    4636       {
    4637         erg.to_reduce_u = i - 1;
    4638         erg.to_reduce_l = i2;
    4639         erg.reduce_by = i;
    4640         erg.fromS = FALSE;
    4641         assume ((i == losl - 1) || (pLmCmp (los[i].p, los[i + 1].p) == -1));
    4642         canonicalize_region (los, erg.to_reduce_u + 1, startf, c);
    4643         return;
     4546      if(i2 != i)
     4547      {
     4548        erg.to_reduce_u = i - 1;
     4549        erg.to_reduce_l = i2;
     4550        erg.reduce_by = i;
     4551        erg.fromS = FALSE;
     4552        assume ((i == losl - 1) || (pLmCmp (los[i].p, los[i + 1].p) == -1));
     4553        canonicalize_region (los, erg.to_reduce_u + 1, startf, c);
     4554        return;
    46444555      }
    46454556      i--;
    46464557    }
    46474558  }
    4648   erg.reduce_by = -1;           //error code
     4559  erg.reduce_by = -1;           //error code
    46494560  return;
    46504561}
     
    46614572  int i = l;
    46624573  int last = -1;
    4663   while (i <= u)
    4664   {
    4665     if (los[i].p == NULL)
     4574  while(i <= u)
     4575  {
     4576    if(los[i].p == NULL)
    46664577    {
    46674578      kBucketDestroy (&los[i].bucket);
    46684579//      delete los[i];//here we assume los are constructed with new
    46694580      //destroy resources, must be added here
    4670       if (last >= 0)
    4671       {
    4672         memmove (los + (int) (last + 1 - deleted), los + (last + 1),
    4673                 sizeof (red_object) * (i - 1 - last));
     4581      if(last >= 0)
     4582      {
     4583        memmove (los + (int) (last + 1 - deleted), los + (last + 1),
     4584                sizeof (red_object) * (i - 1 - last));
    46744585      }
    46754586      last = i;
     
    46784589    i++;
    46794590  }
    4680   if ((last >= 0) && (last != losl - 1))
     4591  if((last >= 0) && (last != losl - 1))
    46814592    memmove (los + (int) (last + 1 - deleted), los + last + 1,
    4682              sizeof (red_object) * (losl - 1 - last));
     4593             sizeof (red_object) * (losl - 1 - last));
    46834594  return deleted;
    46844595}
    46854596
    4686 int
    4687 search_red_object_pos (red_object * a, int top, red_object * key)
     4597int search_red_object_pos (red_object * a, int top, red_object * key)
    46884598{
    46894599  int an = 0;
    46904600  int en = top;
    4691   if (top == -1)
     4601  if(top == -1)
    46924602    return 0;
    4693   if (pLmCmp (key->p, a[top].p) == 1)
     4603  if(pLmCmp (key->p, a[top].p) == 1)
    46944604    return top + 1;
    46954605  int i;
    46964606  loop
    46974607  {
    4698     if (an >= en - 1)
    4699     {
    4700       if (pLmCmp (key->p, a[an].p) == -1)
    4701         return an;
     4608    if(an >= en - 1)
     4609    {
     4610      if(pLmCmp (key->p, a[an].p) == -1)
     4611        return an;
    47024612      return en;
    47034613    }
    47044614    i = (an + en) / 2;
    4705     if (pLmCmp (key->p, a[i].p) == -1)
     4615    if(pLmCmp (key->p, a[i].p) == -1)
    47064616      en = i;
    47074617    else
     
    47104620}
    47114621
    4712 static void
    4713 sort_region_down (red_object * los, int l, int u, slimgb_alg * c)
     4622static void sort_region_down (red_object * los, int l, int u, slimgb_alg * c)
    47144623{
    47154624  int r_size = u - l + 1;
     
    47194628  int bound = 0;
    47204629  BOOLEAN at_end = FALSE;
    4721   for (i = l; i <= u; i++)
    4722   {
    4723     if (!(at_end))
     4630  for(i = l; i <= u; i++)
     4631  {
     4632    if(!(at_end))
    47244633    {
    47254634      bound = new_indices[i - l] =
    4726         bound + search_red_object_pos (los + bound, l - bound - 1, los + i);
    4727       if (bound == l)
    4728         at_end = TRUE;
     4635        bound + search_red_object_pos (los + bound, l - bound - 1, los + i);
     4636      if(bound == l)
     4637        at_end = TRUE;
    47294638    }
    47304639    else
     
    47354644  red_object *los_region =
    47364645    (red_object *) omalloc (sizeof (red_object) * (u - l + 1));
    4737   for (int i = 0; i < r_size; i++)
     4646  for(int i = 0; i < r_size; i++)
    47384647  {
    47394648    new_indices[i] += i;
     
    47454654  int j = u;
    47464655  int j2 = l - 1;
    4747   while (i >= 0)
    4748   {
    4749     if (new_indices[i] == j)
     4656  while(i >= 0)
     4657  {
     4658    if(new_indices[i] == j)
    47504659    {
    47514660      los[j] = los_region[i];
     
    47674676
    47684677//assume that los is ordered ascending by leading term, all non zero
    4769 static void
    4770 multi_reduction (red_object * los, int &losl, slimgb_alg * c)
     4678static void multi_reduction (red_object * los, int &losl, slimgb_alg * c)
    47714679{
    47724680  poly *delay = (poly *) omalloc (losl * sizeof (poly));
     
    47784686  wlen_type max_initial_quality = 0;
    47794687
    4780   for (i = 0; i < losl; i++)
     4688  for(i = 0; i < losl; i++)
    47814689  {
    47824690    los[i].sev = pGetShortExpVector (los[i].p);
    47834691//SetShortExpVector();
    47844692    los[i].p = kBucketGetLm (los[i].bucket);
    4785     if (los[i].initial_quality > max_initial_quality)
     4693    if(los[i].initial_quality > max_initial_quality)
    47864694      max_initial_quality = los[i].initial_quality;
    47874695    // else
     
    47944702//  nicht reduzierbare eintrᅵe in ergebnisliste schreiben
    47954703  // nullen loeschen
    4796   while (curr_pos >= 0)
    4797   {
    4798     if ((c->use_noro_last_block)
    4799         && (lies_in_last_dp_block (los[curr_pos].p, c)))
     4704  while(curr_pos >= 0)
     4705  {
     4706    if((c->use_noro_last_block)
     4707       && (lies_in_last_dp_block (los[curr_pos].p, c)))
    48004708    {
    48014709      int pn_noro = curr_pos + 1;
    48024710      poly *p_noro = (poly *) omalloc (pn_noro * sizeof (poly));
    4803       for (i = 0; i < pn_noro; i++)
    4804       {
    4805         int dummy_len;
    4806         poly p;
    4807         los[i].p = NULL;
    4808         kBucketClear (los[i].bucket, &p, &dummy_len);
    4809         p_noro[i] = p;
    4810       }
    4811       if (npPrimeM < 255)
    4812       {
    4813         noro_step < tgb_uint8 > (p_noro, pn_noro, c);
     4711      for(i = 0; i < pn_noro; i++)
     4712      {
     4713        int dummy_len;
     4714        poly p;
     4715        los[i].p = NULL;
     4716        kBucketClear (los[i].bucket, &p, &dummy_len);
     4717        p_noro[i] = p;
     4718      }
     4719      if(npPrimeM < 255)
     4720      {
     4721        noro_step < tgb_uint8 > (p_noro, pn_noro, c);
    48144722      }
    48154723      else
    48164724      {
    4817         if (npPrimeM < 65000)
    4818         {
    4819           noro_step < tgb_uint16 > (p_noro, pn_noro, c);
    4820         }
    4821         else
    4822         {
    4823           noro_step < tgb_uint32 > (p_noro, pn_noro, c);
    4824         }
    4825       }
    4826       for (i = 0; i < pn_noro; i++)
    4827       {
    4828         los[i].p = p_noro[i];
    4829         los[i].sev = pGetShortExpVector (los[i].p);
    4830         //ignore quality
    4831         kBucketInit (los[i].bucket, los[i].p, pLength (los[i].p));
     4725        if(npPrimeM < 65000)
     4726        {
     4727          noro_step < tgb_uint16 > (p_noro, pn_noro, c);
     4728        }
     4729        else
     4730        {
     4731          noro_step < tgb_uint32 > (p_noro, pn_noro, c);
     4732        }
     4733      }
     4734      for(i = 0; i < pn_noro; i++)
     4735      {
     4736        los[i].p = p_noro[i];
     4737        los[i].sev = pGetShortExpVector (los[i].p);
     4738        //ignore quality
     4739        kBucketInit (los[i].bucket, los[i].p, pLength (los[i].p));
    48324740      }
    48334741      qsort (los, pn_noro, sizeof (red_object), red_object_better_gen);
    48344742      int deleted =
    4835         multi_reduction_clear_zeroes (los, losl, pn_noro, curr_pos);
     4743        multi_reduction_clear_zeroes (los, losl, pn_noro, curr_pos);
    48364744      losl -= deleted;
    48374745      curr_pos -= deleted;
     
    48404748    find_erg erg;
    48414749
    4842     multi_reduction_find (los, losl, c, curr_pos, erg); //last argument should be curr_pos
    4843     if (erg.reduce_by < 0)
     4750    multi_reduction_find (los, losl, c, curr_pos, erg); //last argument should be curr_pos
     4751    if(erg.reduce_by < 0)
    48444752      break;
    48454753
     
    48544762
    48554763
    4856     if (!TEST_OPT_REDTHROUGH)
    4857     {
    4858       for (i = erg.to_reduce_l; i <= erg.to_reduce_u; i++)
    4859       {
    4860         if (los[i].p != NULL)   //the check (los[i].p!=NULL) might be invalid
    4861         {
    4862           //
    4863           assume (los[i].initial_quality > 0);
    4864           if (los[i].guess_quality (c)
    4865               > 1.5 * delay_factor * max_initial_quality)
    4866           {
    4867             if (TEST_OPT_PROT)
    4868               PrintS ("v");
    4869             los[i].canonicalize ();
    4870             if (los[i].guess_quality (c) > delay_factor * max_initial_quality)
    4871             {
    4872               if (TEST_OPT_PROT)
    4873                 PrintS (".");
    4874               los[i].clear_to_poly ();
    4875               //delay.push_back(los[i].p);
    4876               delay[delay_s] = los[i].p;
    4877               delay_s++;
    4878               los[i].p = NULL;
    4879             }
    4880           }
    4881         }
    4882       }
    4883     }
    4884     int deleted =
    4885       multi_reduction_clear_zeroes (los, losl, erg.to_reduce_l,
    4886                                     erg.to_reduce_u);
    4887     if (erg.fromS == FALSE)
     4764    if(!TEST_OPT_REDTHROUGH)
     4765    {
     4766      for(i = erg.to_reduce_l; i <= erg.to_reduce_u; i++)
     4767      {
     4768        if(los[i].p != NULL)    //the check (los[i].p!=NULL) might be invalid
     4769        {
     4770          //
     4771          assume (los[i].initial_quality > 0);
     4772          if(los[i].guess_quality (c)
     4773             > 1.5 * delay_factor * max_initial_quality)
     4774          {
     4775            if(TEST_OPT_PROT)
     4776              PrintS ("v");
     4777            los[i].canonicalize ();
     4778            if(los[i].guess_quality (c) > delay_factor * max_initial_quality)
     4779            {
     4780              if(TEST_OPT_PROT)
     4781                PrintS (".");
     4782              los[i].clear_to_poly ();
     4783              //delay.push_back(los[i].p);
     4784              delay[delay_s] = los[i].p;
     4785              delay_s++;
     4786              los[i].p = NULL;
     4787            }
     4788          }
     4789        }
     4790      }
     4791    }
     4792    int deleted = multi_reduction_clear_zeroes (los, losl, erg.to_reduce_l,
     4793                                                erg.to_reduce_u);
     4794    if(erg.fromS == FALSE)
    48884795      curr_pos = si_max (erg.to_reduce_u, erg.reduce_by);
    48894796    else
     
    48934800
    48944801    //Print("deleted %i \n",deleted);
    4895     if ((TEST_V_UPTORADICAL) && (!(erg.fromS)))
     4802    if((TEST_V_UPTORADICAL) && (!(erg.fromS)))
    48964803      sort_region_down (los, si_min (erg.to_reduce_l, erg.reduce_by),
    4897                         (si_max (erg.to_reduce_u, erg.reduce_by)) - deleted,
    4898                         c);
     4804                        (si_max (erg.to_reduce_u, erg.reduce_by)) - deleted,
     4805                        c);
    48994806    else
    49004807      sort_region_down (los, erg.to_reduce_l, erg.to_reduce_u - deleted, c);
    49014808
    4902     if (erg.expand)
     4809    if(erg.expand)
    49034810    {
    49044811#ifdef FIND_DETERMINISTIC
    49054812      int i;
    4906       for (i = 0; c->expandS[i]; i++);
     4813      for(i = 0; c->expandS[i]; i++) ;
    49074814      c->expandS = (poly *) omrealloc (c->expandS, (i + 2) * sizeof (poly));
    49084815      c->expandS[i] = erg.expand;
     
    49104817#else
    49114818      int ecart = 0;
    4912       if (c->eliminationProblem)
    4913       {
    4914         ecart =
    4915           c->pTotaldegree_full (erg.expand) - c->pTotaldegree (erg.expand);
     4819      if(c->eliminationProblem)
     4820      {
     4821        ecart =
     4822          c->pTotaldegree_full (erg.expand) - c->pTotaldegree (erg.expand);
    49164823      }
    49174824      add_to_reductors (c, erg.expand, erg.expand_length, ecart);
     
    49524859}
    49534860
    4954 void
    4955 red_object::flatten ()
     4861void red_object::flatten ()
    49564862{
    49574863  assume (p == kBucketGetLm (bucket));
    49584864}
    49594865
    4960 void
    4961 red_object::validate ()
     4866void red_object::validate ()
    49624867{
    49634868  p = kBucketGetLm (bucket);
    4964   if (p)
     4869  if(p)
    49654870    sev = pGetShortExpVector (p);
    49664871}
    49674872
    4968 int
    4969 red_object::clear_to_poly ()
     4873int red_object::clear_to_poly ()
    49704874{
    49714875  flatten ();
     
    49754879}
    49764880
    4977 void
    4978 reduction_step::reduce (red_object * r, int l, int u)
    4979 {
    4980 }
    4981 
    4982 void
    4983 simple_reducer::do_reduce (red_object & ro)
     4881void reduction_step::reduce (red_object * r, int l, int u)
     4882{
     4883}
     4884
     4885void simple_reducer::do_reduce (red_object & ro)
    49844886{
    49854887  number coef;
    49864888#ifdef HAVE_PLURAL
    4987   if (c->nc)
     4889  if(c->nc)
    49884890    nc_BucketPolyRed_Z (ro.bucket, p, &coef);
    49894891  else
     
    49934895}
    49944896
    4995 void
    4996 simple_reducer::reduce (red_object * r, int l, int u)
     4897void simple_reducer::reduce (red_object * r, int l, int u)
    49974898{
    49984899  this->pre_reduce (r, l, u);
     
    50004901//debug start
    50014902
    5002   if (c->eliminationProblem)
     4903  if(c->eliminationProblem)
    50034904  {
    50044905    assume (p_LmEqual (r[l].p, r[u].p, c->r));
     
    50074908  }
    50084909
    5009   for (i = l; i <= u; i++)
     4910  for(i = l; i <= u; i++)
    50104911  {
    50114912    this->do_reduce (r[i]);
    5012     if (c->eliminationProblem)
     4913    if(c->eliminationProblem)
    50134914    {
    50144915      r[i].sugar = si_max (r[i].sugar, reducer_deg);
    50154916    }
    50164917  }
    5017   for (i = l; i <= u; i++)
     4918  for(i = l; i <= u; i++)
    50184919  {
    50194920    kBucketSimpleContent (r[i].bucket);
     
    50304931simple_reducer::~simple_reducer ()
    50314932{
    5032   if (fill_back != NULL)
     4933  if(fill_back != NULL)
    50334934  {
    50344935    kBucketInit (fill_back, p, p_len);
     
    50374938}
    50384939
    5039 void
    5040 multi_reduce_step (find_erg & erg, red_object * r, slimgb_alg * c)
     4940void multi_reduce_step (find_erg & erg, red_object * r, slimgb_alg * c)
    50414941{
    50424942  static int id = 0;
     
    50494949  simple_reducer *pointer;
    50504950  BOOLEAN work_on_copy = FALSE;
    5051   if (erg.fromS)
     4951  if(erg.fromS)
    50524952  {
    50534953    red = c->strat->S[rn];
     
    50604960    kBucketClear (r[rn].bucket, &red, &red_len);
    50614961
    5062     if (!rField_is_Zp (c->r))
    5063     {
    5064       p_Cleardenom (red, c->r); //should be unnecessary
     4962    if(!rField_is_Zp (c->r))
     4963    {
     4964      p_Cleardenom (red, c->r); //should be unnecessary
    50654965      //p_Content(red, c->r);
    50664966    }
    50674967    pNormalize (red);
    5068     if (c->eliminationProblem)
     4968    if(c->eliminationProblem)
    50694969    {
    50704970      r[rn].sugar = c->pTotaldegree_full (red);
    50714971    }
    50724972
    5073     if ((!(erg.fromS)) && (TEST_V_UPTORADICAL))
    5074     {
    5075       if (polynomial_root (red, c->r))
    5076         lt_changed = TRUE;
     4973    if((!(erg.fromS)) && (TEST_V_UPTORADICAL))
     4974    {
     4975      if(polynomial_root (red, c->r))
     4976        lt_changed = TRUE;
    50774977      sev = p_GetShortExpVector (red, c->r);
    50784978    }
    50794979    red_len = pLength (red);
    50804980  }
    5081   if (((TEST_V_MODPSOLVSB) && (red_len > 1))
    5082       || ((c->nc) || (erg.to_reduce_u - erg.to_reduce_l > 5)))
     4981  if(((TEST_V_MODPSOLVSB) && (red_len > 1))
     4982     || ((c->nc) || (erg.to_reduce_u - erg.to_reduce_l > 5)))
    50834983  {
    50844984    work_on_copy = TRUE;
     
    50874987    pSetCoeff (m, nInit (1));
    50884988    pSetComp (m, 0);
    5089     for (int i = 1; i <= pVariables; i++)
     4989    for(int i = 1; i <= pVariables; i++)
    50904990      pSetExp (m, i, (pGetExp (r[erg.to_reduce_l].p, i) - pGetExp (red, i)));
    50914991    pSetm (m);
    50924992    poly red_cp;
    50934993#ifdef HAVE_PLURAL
    5094     if (c->nc)
     4994    if(c->nc)
    50954995      red_cp = nc_mm_Mult_pp (m, red, c->r);
    50964996    else
    50974997#endif
    50984998      red_cp = ppMult_mm (red, m);
    5099     if (!erg.fromS)
     4999    if(!erg.fromS)
    51005000    {
    51015001      kBucketInit (r[rn].bucket, red, red_len);
     
    51045004    //static poly redNF2 (poly h,slimgb_alg* c , int &len, number&  m,int n)
    51055005
    5106     if (!c->nc)
     5006    if(!c->nc)
    51075007      redTailShort (red_cp, c->strat);
    51085008    //number mul;
     
    51205020
    51215021  int reducer_deg = 0;
    5122   if (c->eliminationProblem)
     5022  if(c->eliminationProblem)
    51235023  {
    51245024    int lm_deg = c->pTotaldegree (r[erg.to_reduce_l].p);
    51255025    int ecart;
    5126     if (erg.fromS)
     5026    if(erg.fromS)
    51275027    {
    51285028      ecart = c->strat->ecartS[erg.reduce_by];
     
    51365036  pointer = new simple_reducer (red, red_len, reducer_deg, c);
    51375037
    5138   if ((!work_on_copy) && (!erg.fromS))
     5038  if((!work_on_copy) && (!erg.fromS))
    51395039    pointer->fill_back = r[rn].bucket;
    51405040  else
     
    51445044
    51455045  pointer->reduce (r, erg.to_reduce_l, erg.to_reduce_u);
    5146   if (work_on_copy)
     5046  if(work_on_copy)
    51475047    pDelete (&pointer->p);
    51485048  delete pointer;
    5149   if (lt_changed)
     5049  if(lt_changed)
    51505050  {
    51515051    assume (!erg.fromS);
     
    51545054}
    51555055
    5156 void
    5157 simple_reducer::pre_reduce (red_object * r, int l, int u)
    5158 {
    5159 }
     5056void simple_reducer::pre_reduce (red_object * r, int l, int u)
     5057{
     5058}
Note: See TracChangeset for help on using the changeset viewer.