Changeset 2fc974 in git


Ignore:
Timestamp:
Apr 12, 2011, 2:40:17 PM (12 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'f875bbaccd0831e36aaed09ff6adeb3eb45aeb94')
Children:
c385d40ef3a9c855b644be8fed2928f6eedc7be1
Parents:
a64791477ec20b2ed1ff3c7042d7f2dc9c892600
Message:
fix tgb.cc(sun warnings, MBs patch)

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

Legend:

Unmodified
Added
Removed
  • kernel/tgb.cc

    ra647914 r2fc974  
    1111//#include <vector>
    1212//using namespace std;
    13 
    1413
    1514///@TODO: delay nur auf Sugarvergr?erung
     
    6968  }
    7069}
    71 static BOOLEAN monomial_root(poly m, ring r){
     70static BOOLEAN monomial_root(poly m, ring r)
     71{
    7272    BOOLEAN changed=FALSE;
    7373    int i;
    74     for(i=1;i<=rVar(r);i++){
     74    for(i=1;i<=rVar(r);i++)
     75    {
    7576        int e=p_GetExp(m,i,r);
    76         if (e>1){
     77        if (e>1)
     78        {
    7779            p_SetExp(m,i,1,r);
    7880            changed=TRUE;
     
    8486    return changed;
    8587}
    86 static BOOLEAN polynomial_root(poly h, ring r){
     88static BOOLEAN polynomial_root(poly h, ring r)
     89{
    8790  poly got=gcd_of_terms(h,r);
    8891  BOOLEAN changed=FALSE;
     
    9598         poly div_by=pDivide(copy, got);
    9699         poly iter=h;
    97          while(iter){
     100         while(iter)
     101         {
    98102            pExpVectorSub(iter,div_by);
    99103            pIter(iter);
     
    127131//die meisten Varianten stossen sich an coef_buckets
    128132
    129 
    130 
    131133#ifdef LEN_VAR1
    132134// erste Variante: Laenge: Anzahl der Monome
     
    156158#endif
    157159
    158 
    159 
    160 
    161 
    162 
    163 int QlogSize(number n){
    164 
    165     if (SR_HDL(n) & SR_INT){
     160int QlogSize(number n)
     161{
     162    if (SR_HDL(n) & SR_INT)
     163    {
    166164       long i=SR_TO_INT(n);
    167165       if (i==0) return 0;
     
    181179}
    182180
    183 
    184181#ifdef LEN_VAR3
    185182static inline wlen_type pSLength(poly p,int l)
     
    187184  wlen_type c;
    188185  number coef=pGetCoeff(p);
    189   if (rField_is_Q(currRing)){
     186  if (rField_is_Q(currRing))
     187  {
    190188    c=QlogSize(coef);
    191189  }
     
    194192  if (!(TEST_V_COEFSTRAT))
    195193      return (wlen_type)c*(wlen_type)l /*pLength(p)*/;
    196   else {
     194  else
     195  {
    197196    wlen_type res=l;
    198197    res*=c;
     
    213212    coef=pGetCoeff(lm);
    214213    //c=nSize(pGetCoeff(lm));
    215   if (rField_is_Q(currRing)){
     214  if (rField_is_Q(currRing))
     215  {
    216216    c=QlogSize(coef);
    217217  }
     
    227227  #ifdef HAVE_COEF_BUCKETS
    228228  assume(b->buckets[0]==kBucketGetLm(b));
    229   if (b->coef[0]!=NULL){
    230 
    231     if (rField_is_Q(currRing)){
     229  if (b->coef[0]!=NULL)
     230  {
     231    if (rField_is_Q(currRing))
     232    {
    232233      int modifier=QlogSize(pGetCoeff(b->coef[0]));
    233234      c+=modifier;
    234   }
    235     else{
     235    }
     236    else
     237    {
    236238      int modifier=nSize(pGetCoeff(b->coef[0]));
    237       c*=modifier;}
    238     }
     239      c*=modifier;
     240    }
     241  }
    239242  #endif
    240   if (!(TEST_V_COEFSTRAT)){
    241   return s*c;
    242   } else
     243  if (!(TEST_V_COEFSTRAT))
     244  {
     245    return s*c;
     246  }
     247  else
    243248  {
    244249    wlen_type res=s;
     
    254259  int c;
    255260  number coef=pGetCoeff(p);
    256   if (rField_is_Q(currRing)){
     261  if (rField_is_Q(currRing))
     262  {
    257263    c=QlogSize(coef);
    258264  }
     
    278284    coef=pGetCoeff(lm);
    279285    //c=nSize(pGetCoeff(lm));
    280   if (rField_is_Q(currRing)){
     286  if (rField_is_Q(currRing))
     287  {
    281288    c=QlogSize(coef);
    282289  }
     
    292299  #ifdef HAVE_COEF_BUCKETS
    293300  assume(b->buckets[0]==kBucketGetLm(b));
    294   if (b->coef[0]!=NULL){
    295 
    296     if (rField_is_Q(currRing)){
     301  if (b->coef[0]!=NULL)
     302  {
     303    if (rField_is_Q(currRing))
     304    {
    297305      int modifier=QlogSize(pGetCoeff(b->coef[0]));
    298306      c+=modifier;
    299   }
    300     else{
     307    }
     308    else
     309    {
    301310      int modifier=nSize(pGetCoeff(b->coef[0]));
    302311      c*=modifier;}
     
    334343#endif
    335344//BUG/TODO this stuff will fail on internal Schreyer orderings
    336 static BOOLEAN elength_is_normal_length(poly p, slimgb_alg* c){
     345static BOOLEAN elength_is_normal_length(poly p, slimgb_alg* c)
     346{
    337347    ring r=c->r;
    338348    if (p_GetComp(p,r)!=0) return FALSE;
    339     if (c->lastDpBlockStart<=pVariables){
     349    if (c->lastDpBlockStart<=pVariables)
     350    {
    340351        int i;
    341         for(i=1;i<c->lastDpBlockStart;i++){
    342             if (p_GetExp(p,i,r)!=0){
     352        for(i=1;i<c->lastDpBlockStart;i++)
     353        {
     354            if (p_GetExp(p,i,r)!=0)
     355            {
    343356                break;
    344357            }
     
    350363        }
    351364        else return FALSE;
    352     }else
     365    }
     366    else
    353367    return FALSE;
    354368}
    355369
    356 static BOOLEAN lies_in_last_dp_block(poly p, slimgb_alg* c){
     370static BOOLEAN lies_in_last_dp_block(poly p, slimgb_alg* c)
     371{
    357372    ring r=c->r;
    358373    if (p_GetComp(p,r)!=0) return FALSE;
    359     if (c->lastDpBlockStart<=pVariables){
     374    if (c->lastDpBlockStart<=pVariables)
     375    {
    360376        int i;
    361         for(i=1;i<c->lastDpBlockStart;i++){
    362             if (p_GetExp(p,i,r)!=0){
     377        for(i=1;i<c->lastDpBlockStart;i++)
     378        {
     379            if (p_GetExp(p,i,r)!=0)
     380            {
    363381                break;
    364382            }
     
    370388        }
    371389        else return FALSE;
    372     }else
     390    }
     391    else
    373392    return FALSE;
    374393}
    375394
    376 static int get_last_dp_block_start(ring r){
     395static int get_last_dp_block_start(ring r)
     396{
    377397    //ring r=c->r;
    378398    int last_block;
    379399
    380     if (rRing_has_CompLastBlock(r)){
     400    if (rRing_has_CompLastBlock(r))
     401    {
    381402        last_block=rBlocks(r) - 3;
    382403    }
    383     else {last_block=rBlocks(r)-2;}
     404    else
     405    {last_block=rBlocks(r)-2;}
    384406    assume(last_block>=0);
    385407    if (r->order[last_block]==ringorder_dp)
    386408        return r->block0[last_block];
    387409    return pVariables+1;
    388 
    389 }
    390 
    391 static wlen_type do_pELength(poly p, slimgb_alg* c, int dlm=-1){
    392 
     410}
     411
     412static wlen_type do_pELength(poly p, slimgb_alg* c, int dlm=-1)
     413{
    393414  if(p==NULL) return 0;
    394415  wlen_type s=0;
    395416  poly pi=p;
    396   if(dlm<0){
     417  if(dlm<0)
     418  {
    397419    dlm=c->pTotaldegree(p);
    398420    s=1;
     
    400422  }
    401423
    402   while(pi){
     424  while(pi)
     425  {
    403426    int d=c->pTotaldegree(pi);
    404427    if(d>dlm)
     
    411434}
    412435
    413 wlen_type pELength(poly p, slimgb_alg* c, ring r){
     436wlen_type pELength(poly p, slimgb_alg* c, ring r)
     437{
    414438  if(p==NULL) return 0;
    415439  wlen_type s=0;
    416440  poly pi=p;
    417441  int dlm;
    418     dlm=c->pTotaldegree(p);
    419     s=1;
    420     pi=p->next;
    421 
    422 
    423   while(pi){
     442  dlm=c->pTotaldegree(p);
     443  s=1;
     444  pi=p->next;
     445
     446  while(pi)
     447  {
    424448    int d=c->pTotaldegree(pi);
    425449    if(d>dlm)
     
    435459{
    436460  wlen_type s=0;
    437   if(lm==NULL){
     461  if(lm==NULL)
     462  {
    438463    lm=kBucketGetLm(b);
    439464  }
    440465  if(lm==NULL) return 0;
    441   if(elength_is_normal_length(lm,ca)) {
     466  if(elength_is_normal_length(lm,ca))
     467  {
    442468    return bucket_guess(b);
    443469  }
     
    449475  #else
    450476
    451 
    452477  //int d=pTotaldegree(lm,ca->r);
    453478  int i;
     
    456481    if(b->buckets[i]==NULL) continue;
    457482
    458     if ((ca->pTotaldegree(b->buckets[i])<=d) &&(elength_is_normal_length(b->buckets[i],ca))){
     483    if ((ca->pTotaldegree(b->buckets[i])<=d) &&(elength_is_normal_length(b->buckets[i],ca)))
     484    {
    459485        s+=b->buckets_length[i];
    460     } else
     486    }
     487    else
    461488    {
    462489    s+=do_pELength(b->buckets[i],ca,d);
     
    467494}
    468495
    469 static inline int pELength(poly p, slimgb_alg* c,int l){
     496static inline int pELength(poly p, slimgb_alg* c,int l)
     497{
    470498  if (p==NULL) return 0;
    471499  if ((l>0) &&(elength_is_normal_length(p,c)))
     
    474502}
    475503
    476 
    477 
    478 
    479 static inline wlen_type pQuality(poly p, slimgb_alg* c, int l=-1){
    480 
     504static inline wlen_type pQuality(poly p, slimgb_alg* c, int l=-1)
     505{
    481506  if(l<0)
    482507    l=pLength(p);
    483508  if(c->isDifficultField) {
    484     if(c->eliminationProblem){
     509    if(c->eliminationProblem)
     510    {
    485511      wlen_type cs;
    486512      number coef=pGetCoeff(p);
    487       if (rField_is_Q(currRing)){
     513      if (rField_is_Q(currRing))
     514      {
    488515         cs=QlogSize(coef);
    489516      }
     
    508535}
    509536
    510 static inline int pTotaldegree_full(poly p){
     537static inline int pTotaldegree_full(poly p)
     538{
    511539  int r=0;
    512   while(p){
     540  while(p)
     541  {
    513542    int d=pTotaldegree(p);
    514543    r=si_max(r,d);
     
    518547}
    519548
    520 wlen_type red_object::guess_quality(slimgb_alg* c){
     549wlen_type red_object::guess_quality(slimgb_alg* c)
     550{
    521551    //works at the moment only for lenvar 1, because in different
    522552    //case, you have to look on coefs
    523553    wlen_type s=0;
    524     if (c->isDifficultField){
     554    if (c->isDifficultField)
     555    {
    525556      //s=kSBucketLength(bucket,this->p);
    526       if(c->eliminationProblem){
     557      if(c->eliminationProblem)
     558      {
    527559    wlen_type cs;
    528560    number coef;
     
    532564
    533565    //c=nSize(pGetCoeff(lm));
    534     if (rField_is_Q(currRing)){
     566    if (rField_is_Q(currRing))
     567    {
    535568      cs=QlogSize(coef);
    536569    }
     
    538571      cs=nSize(coef);
    539572    #ifdef HAVE_COEF_BUCKETS
    540     if (bucket->coef[0]!=NULL){
    541       if (rField_is_Q(currRing)){
     573    if (bucket->coef[0]!=NULL)
     574    {
     575      if (rField_is_Q(currRing))
     576      {
    542577        int modifier=QlogSize(pGetCoeff(bucket->coef[0]));
    543578        cs+=modifier;
    544579      }
    545       else{
     580      else
     581      {
    546582        int modifier=nSize(pGetCoeff(bucket->coef[0]));
    547583        cs*=modifier;}
     
    566602      else s=bucket_guess(bucket);
    567603    }
    568 
    569604    return s;
    570605}
    571606
    572 
    573 
    574 static void finalize_reduction_step(reduction_step* r){
     607static void finalize_reduction_step(reduction_step* r)
     608{
    575609  delete r;
    576610}
     
    583617static int red_object_better_gen(const void* ap, const void* bp)
    584618{
    585 
    586 
    587619  return(pLmCmp(((red_object*) ap)->p,((red_object*) bp)->p));
    588620}
    589621
    590 
    591 static int pLmCmp_func_inverted(const void* ap1, const void* ap2){
    592     poly p1,p2;
     622static int pLmCmp_func_inverted(const void* ap1, const void* ap2)
     623{
     624  poly p1,p2;
    593625  p1=*((poly*) ap1);
    594626  p2=*((poly*)ap2);
    595 
    596627  return -pLmCmp(p1,p2);
    597628}
    598629
    599 int tgb_pair_better_gen2(const void* ap,const void* bp){
     630int tgb_pair_better_gen2(const void* ap,const void* bp)
     631{
    600632  return(-tgb_pair_better_gen(ap,bp));
    601633}
    602 int kFindDivisibleByInS_easy(kStrategy strat,const red_object & obj){
     634int kFindDivisibleByInS_easy(kStrategy strat,const red_object & obj)
     635{
    603636  int i;
    604637  long not_sev=~obj.sev;
    605638  poly p=obj.p;
    606   for(i=0;i<=strat->sl;i++){
     639  for(i=0;i<=strat->sl;i++)
     640  {
    607641    if (pLmShortDivisibleBy(strat->S[i],strat->sevS[i],p,not_sev))
    608642      return i;
     
    610644  return -1;
    611645}
    612 int kFindDivisibleByInS_easy(kStrategy strat,poly p, long sev){
     646int kFindDivisibleByInS_easy(kStrategy strat,poly p, long sev)
     647{
    613648  int i;
    614649  long not_sev=~sev;
    615   for(i=0;i<=strat->sl;i++){
     650  for(i=0;i<=strat->sl;i++)
     651  {
    616652    if (pLmShortDivisibleBy(strat->S[i],strat->sevS[i],p,not_sev))
    617653      return i;
     
    646682}
    647683
    648 static BOOLEAN  ascending(int* i,int top){
     684static BOOLEAN  ascending(int* i,int top)
     685{
    649686  if(top<1) return TRUE;
    650687  if(i[top]<i[top-1]) return FALSE;
     
    652689}
    653690
    654 sorted_pair_node**  spn_merge(sorted_pair_node** p, int pn,sorted_pair_node **q, int qn,slimgb_alg* c){
     691sorted_pair_node**  spn_merge(sorted_pair_node** p, int pn,sorted_pair_node **q, int qn,slimgb_alg* c)
     692{
    655693  int i;
    656694  int* a= (int*) omalloc(qn*sizeof(int));
     
    659697//   for(mc=0;mc<qn;mc++)
    660698// {
    661 
    662699//     wrp(q[mc]->lcm_of_lm);
    663700//     PrintS("\n");
     
    666703//   for(mc=0;mc<pn;mc++)
    667704// {
    668 
    669705//     wrp(p[mc]->lcm_of_lm);
    670706//     PrintS("\n");
    671707// }
    672708  int lastpos=0;
    673   for(i=0;i<qn;i++){
     709  for(i=0;i<qn;i++)
     710  {
    674711    lastpos=posInPairs(p,pn,q[i],c, si_max(lastpos-1,0));
    675712    //   cout<<lastpos<<"\n";
    676713    a[i]=lastpos;
    677 
    678   }
    679   if((pn+qn)>c->max_pairs){
     714  }
     715  if((pn+qn)>c->max_pairs)
     716  {
    680717    p=(sorted_pair_node**) omrealloc(p,2*(pn+qn)*sizeof(sorted_pair_node*));
    681718    c->max_pairs=2*(pn+qn);
    682719  }
    683   for(i=qn-1;i>=0;i--){
     720  for(i=qn-1;i>=0;i--)
     721  {
    684722    size_t size;
    685723    if(qn-1>i)
     
    694732}
    695733
    696 
    697 static BOOLEAN trivial_syzygie(int pos1,int pos2,poly bound,slimgb_alg* c){
    698 
    699 
     734static BOOLEAN trivial_syzygie(int pos1,int pos2,poly bound,slimgb_alg* c)
     735{
    700736  poly p1=c->S->m[pos1];
    701737  poly p2=c->S->m[pos2];
    702 
    703738
    704739  if (pGetComp(p1) > 0 || pGetComp(p2) > 0)
     
    710745
    711746  if((gcd1!=NULL) && (gcd2!=NULL))
    712     {
    713       gcd1->next=gcd2; //may ordered incorrect
    714       m=gcd_of_terms(gcd1,c->r);
    715       gcd1->next=NULL;
    716 
    717     }
    718 
     747  {
     748    gcd1->next=gcd2; //may ordered incorrect
     749    m=gcd_of_terms(gcd1,c->r);
     750    gcd1->next=NULL;
     751  }
    719752  if (m==NULL)
    720753  {
     
    722755      {
    723756  if (pGetExp(p1, i)+ pGetExp(p2, i) > pGetExp(bound,i))   return FALSE;
    724   if (i == pVariables){
     757  if (i == pVariables)
     758  {
    725759    //PrintS("trivial");
    726760    return TRUE;
     
    736770    pDelete(&m);
    737771    return FALSE;}
    738   if (i == pVariables){
     772  if (i == pVariables)
     773  {
    739774    pDelete(&m);
    740775    //PrintS("trivial");
     
    744779      }
    745780  }
    746 
    747 
    748 
    749 
    750781}
    751782
    752783//! returns position sets w as weight
    753 int find_best(red_object* r,int l, int u, wlen_type &w, slimgb_alg* c){
     784int find_best(red_object* r,int l, int u, wlen_type &w, slimgb_alg* c)
     785{
    754786  int best=l;
    755787  int i;
    756788  w=r[l].guess_quality(c);
    757   for(i=l+1;i<=u;i++){
     789  for(i=l+1;i<=u;i++)
     790  {
    758791    wlen_type w2=r[i].guess_quality(c);
    759     if(w2<w){
     792    if(w2<w)
     793    {
    760794      w=w2;
    761795      best=i;
    762796    }
    763 
    764797  }
    765798 return best;
    766799}
    767800
    768 
    769 void red_object::canonicalize(){
     801void red_object::canonicalize()
     802{
    770803  kBucketCanonicalize(bucket);
    771 
    772 
    773 }
    774 BOOLEAN good_has_t_rep(int i, int j,slimgb_alg* c){
     804}
     805
     806BOOLEAN good_has_t_rep(int i, int j,slimgb_alg* c)
     807{
    775808  assume(i>=0);
    776809    assume(j>=0);
     
    787820  //p_Delete(&lm,c->r);
    788821
    789 
    790   for (int n=0;((n<c->n) && (i_con[n]>=0));n++){
    791     if (i_con[n]==j){
     822  for (int n=0;((n<c->n) && (i_con[n]>=0));n++)
     823  {
     824    if (i_con[n]==j)
     825    {
    792826      now_t_rep(i,j,c);
    793827      omfree(i_con);
    794 
    795828      return TRUE;
    796829    }
     
    800833  return FALSE;
    801834}
    802 BOOLEAN lenS_correct(kStrategy strat){
     835BOOLEAN lenS_correct(kStrategy strat)
     836{
    803837  int i;
    804   for(i=0;i<=strat->sl;i++){
     838  for(i=0;i<=strat->sl;i++)
     839  {
    805840    if (strat->lenS[i]!=pLength(strat->S[i]))
    806841      return FALSE;
     
    841876  }
    842877}
    843 static int bucket_guess(kBucket* bucket){
     878static int bucket_guess(kBucket* bucket)
     879{
    844880  int sum=0;
    845881  int i;
    846   for (i=bucket->buckets_used;i>=0;i--){
     882  for (i=bucket->buckets_used;i>=0;i--)
     883  {
    847884    if(bucket->buckets[i])
    848885       sum+=bucket->buckets_length[i];
     
    850887  return sum;
    851888}
    852 
    853 
    854 
    855 
    856 
    857889
    858890static int add_to_reductors(slimgb_alg* c, poly h, int len, int ecart, BOOLEAN simplified)
     
    888920  c->strat->enterS(P,i,c->strat,-1);
    889921
    890 
    891 
    892922  c->strat->lenS[i]=len;
    893923  assume(pLength(c->strat->S[i])==c->strat->lenS[i]);
     
    896926
    897927  return i;
    898 
    899 }
     928}
     929
    900930static void length_one_crit(slimgb_alg* c, int pos, int len)
    901931{
     
    910940        c->states[pos][i]=HASTREP;
    911941    }
    912     for ( i=pos+1;i<c->n;i++){
     942    for ( i=pos+1;i<c->n;i++)
     943    {
    913944      if (c->lengths[i]==1)
    914945        c->states[i][pos]=HASTREP;
     
    918949  }
    919950}
    920 
    921951
    922952static void move_forward_in_S(int old_pos, int new_pos,kStrategy strat)
     
    10101040  int pos;
    10111041
    1012   while(TRUE){
    1013     if ((con_checked<connected_length)&& (not_yet_found>0)){
     1042  while(TRUE)
     1043  {
     1044    if ((con_checked<connected_length)&& (not_yet_found>0))
     1045    {
    10141046      pos=connected[con_checked];
    1015       for(int i=0;i<cans_length;i++){
     1047      for(int i=0;i<cans_length;i++)
     1048      {
    10161049        if (cans[i]<0) continue;
    10171050        //FIXME: triv. syz. does not hold on noncommutative, check it for modules
    10181051        if ((has_t_rep(pos,cans[i],c)) ||((!rIsPluralRing(c->r))&&(trivial_syzygie(pos,cans[i],bound,c))))
    10191052{
    1020 
    10211053          connected[connected_length]=cans[i];
    10221054          connected_length++;
     
    10241056          --not_yet_found;
    10251057
    1026           if (connected[connected_length-1]==to){
    1027             if (connected_length<c->n){
     1058          if (connected[connected_length-1]==to)
     1059          {
     1060            if (connected_length<c->n)
     1061            {
    10281062              connected[connected_length]=-1;
    10291063            }
     
    10371071    else
    10381072    {
    1039       for(last_cans_pos++;last_cans_pos<=c->n;last_cans_pos++){
    1040         if (last_cans_pos==c->n){
    1041           if (connected_length<c->n){
     1073      for(last_cans_pos++;last_cans_pos<=c->n;last_cans_pos++)
     1074      {
     1075        if (last_cans_pos==c->n)
     1076        {
     1077          if (connected_length<c->n)
     1078          {
    10421079            connected[connected_length]=-1;
    10431080          }
     
    10471084        if ((last_cans_pos==from)||(last_cans_pos==to))
    10481085          continue;
    1049         if(p_LmShortDivisibleBy(I->m[last_cans_pos],c->short_Exps[last_cans_pos],bound,neg_bounds_short,c->r)){
     1086        if(p_LmShortDivisibleBy(I->m[last_cans_pos],c->short_Exps[last_cans_pos],bound,neg_bounds_short,c->r))
     1087        {
    10501088          cans[cans_length]=last_cans_pos;
    10511089          cans_length++;
     
    10541092      }
    10551093      not_yet_found++;
    1056       for (int i=0;i<con_checked;i++){
    1057         if (has_t_rep(connected[i],last_cans_pos,c)){
    1058 
     1094      for (int i=0;i<con_checked;i++)
     1095      {
     1096        if (has_t_rep(connected[i],last_cans_pos,c))
     1097        {
    10591098          connected[connected_length]=last_cans_pos;
    10601099          connected_length++;
    10611100          cans[cans_length-1]=-1;
    1062 
    10631101          --not_yet_found;
    1064           if (connected[connected_length-1]==to){
    1065             if (connected_length<c->n){
     1102          if (connected[connected_length-1]==to)
     1103          {
     1104            if (connected_length<c->n)
     1105            {
    10661106              connected[connected_length]=-1;
    10671107            }
    1068 
    10691108            omfree(cans);
    10701109            return connected;
     
    10751114    }
    10761115  }
    1077   if (connected_length<c->n){
     1116  if (connected_length<c->n)
     1117  {
    10781118    connected[connected_length]=-1;
    10791119  }
    1080 
    10811120  omfree(cans);
    10821121  return connected;
     
    11181157  int* j_con =make_connections(j,i,lm,c);
    11191158
    1120 //   if(c->n>1){
     1159//   if(c->n>1)
     1160//   {
    11211161//     if (i_con[1]>=0)
    11221162//       i=i_con[1];
    1123 //     else {
     1163//     else
     1164//     {
    11241165//       if (j_con[1]>=0)
    11251166//         j=j_con[1];
     
    11271168 // }
    11281169
    1129   int sugar=c->pTotaldegree(lm);
     1170  int sugar=syz_deg=c->pTotaldegree(lm);
     1171
    11301172  p_Delete(&lm, c->r);
    1131   if(c->T_deg_full)//Sugar
    1132   {
    1133     int t_i=c->T_deg_full[i]-c->T_deg[i];
    1134     int t_j=c->T_deg_full[j]-c->T_deg[j];
    1135     sugar+=si_max(t_i,t_j);
    1136     //Print("\n max: %d\n",max(t_i,t_j));
    1137   }
     1173    if(c->T_deg_full)//Sugar
     1174    {
     1175      int t_i=c->T_deg_full[i]-c->T_deg[i];
     1176      int t_j=c->T_deg_full[j]-c->T_deg[j];
     1177      sugar+=si_max(t_i,t_j);
     1178      //Print("\n max: %d\n",max(t_i,t_j));
     1179    }
    11381180
    11391181  for (int m=0;((m<c->n) && (i_con[m]>=0));m++)
     
    11461188    if (c->weighted_lengths[i_con[m]]<c->weighted_lengths[i])
    11471189        i=i_con[m];
    1148   }
    1149   for (int m=0;((m<c->n) && (j_con[m]>=0));m++)
    1150   {
    1151     if (c->T_deg_full!=NULL)
    1152     {
    1153       int s1=c->T_deg_full[j_con[m]]+syz_deg-c->T_deg[j_con[m]];
    1154       if (s1>sugar) continue;
    1155     }
    1156     if (c->weighted_lengths[j_con[m]]<c->weighted_lengths[j])
    1157       j=j_con[m];
    1158   }
    1159 
    1160   //can also try dependend search
     1190    }
     1191    for (int m=0;((m<c->n) && (j_con[m]>=0));m++)
     1192    {
     1193        if (c->T_deg_full!=NULL)
     1194        {
     1195        int s1=c->T_deg_full[j_con[m]]+syz_deg-c->T_deg[j_con[m]];
     1196        if (s1>sugar) continue;}
     1197        if (c->weighted_lengths[j_con[m]]<c->weighted_lengths[j])
     1198            j=j_con[m];
     1199    }
     1200
     1201     //can also try dependend search
    11611202  omfree(i_con);
    11621203  omfree(j_con);
    1163 }
    1164 
     1204  return;
     1205}
    11651206
    11661207static void add_later(poly p, const char* prot, slimgb_alg* c)
     
    11681209    int i=0;
    11691210    //check, if it is already in the queue
    1170 
    11711211
    11721212    while(c->add_later->m[i]!=NULL)
     
    11821222static int simple_posInS (kStrategy strat, poly p,int len, wlen_type wlen)
    11831223{
    1184 
    1185 
    11861224  if(strat->sl==-1) return 0;
    11871225  if (strat->lenSw) return pos_helper(strat,p,(wlen_type) wlen,(wlen_set) strat->lenSw,strat->S);
    11881226  return pos_helper(strat,p,len,strat->lenS,strat->S);
    1189 
    11901227}
    11911228
     
    12101247}
    12111248
    1212 
    1213 
    12141249static int iq_crit(const void* ap,const void* bp)
    12151250{
     
    12181253  assume(a->i>a->j);
    12191254  assume(b->i>b->j);
    1220 
    12211255
    12221256  if (a->deg<b->deg) return -1;
     
    12311265  return 0;
    12321266}
    1233 static wlen_type coeff_mult_size_estimate(int s1, int s2, ring r){
     1267static wlen_type coeff_mult_size_estimate(int s1, int s2, ring r)
     1268{
    12341269    if (rField_is_Q(r)) return s1+s2;
    12351270    else return s1*s2;
    12361271}
    1237 static wlen_type pair_weighted_length(int i, int j, slimgb_alg* c){
     1272static wlen_type pair_weighted_length(int i, int j, slimgb_alg* c)
     1273{
    12381274    if ((c->isDifficultField) && (c->eliminationProblem))  {
    12391275        int c1=slim_nsize(p_GetCoeff(c->S->m[i],c->r),c->r);
     
    12551291        //int cs=slim_nsize(p_GetCoeff(c->S->m[i],c->r),c->r)+
    12561292        //    slim_nsize(p_GetCoeff(c->S->m[j],c->r),c->r);
    1257         if(!(TEST_V_COEFSTRAT)){
     1293        if(!(TEST_V_COEFSTRAT))
     1294        {
    12581295        wlen_type cs=
    12591296            coeff_mult_size_estimate(
     
    12621299        return (wlen_type)(c->lengths[i]+c->lengths[j]-2)*
    12631300            (wlen_type)cs;}
    1264             else {
     1301            else
     1302            {
    12651303
    12661304            wlen_type cs=
     
    12931331         poly div_by=pDivide(copy, got);
    12941332         poly iter=h;
    1295          while(iter){
     1333         while(iter)
     1334         {
    12961335            pExpVectorSub(iter,div_by);
    12971336            pIter(iter);
     
    13361375    //}
    13371376    //ENLARGE(c->S->m,poly);
    1338 
    13391377  }
    13401378  pEnlargeSet(&c->S->m,c->n-1,1);
     
    13481386    assume(ecart>=0);
    13491387  }
    1350 
    1351 
    13521388  c->tmp_pair_lm[i]=pOne_Special(c->r);
    13531389
    1354 
    13551390  c->tmp_spn[i]=(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
    1356 
    13571391
    13581392  c->lengths[i]=pLength(h);
     
    13641398    p_Cleardenom(h, c->r);
    13651399    //p_Content(h,c->r); //is a duplicate call, but belongs here
    1366 
    13671400  }
    13681401  else
     
    13791412
    13801413    c->states.push_back(vector<bool>(i));
    1381 
    13821414
    13831415  #else
     
    13931425
    13941426#undef ENLARGE
    1395   if (p_GetComp(h,currRing)<=c->syz_comp){
    1396   for (j=0;j<i;j++){
     1427  if (p_GetComp(h,currRing)<=c->syz_comp)
     1428  {
     1429  for (j=0;j<i;j++)
     1430  {
    13971431
    13981432
     
    14031437     p_LmShortDivisibleBy(c->S->m[i],c->short_Exps[i],c->S->m[j],~(c->short_Exps[j]),c->r));
    14041438
    1405 
    1406     if (_p_GetComp(c->S->m[i],c->r)!=_p_GetComp(c->S->m[j],c->r)){
     1439    if (_p_GetComp(c->S->m[i],c->r)!=_p_GetComp(c->S->m[j],c->r))
     1440    {
    14071441      //c->states[i][j]=UNCALCULATED;
    14081442      //WARNUNG: be careful
    14091443      continue;
    1410     } else
    1411     if ((!c->nc) && (c->lengths[i]==1) && (c->lengths[j]==1)){
     1444    }
     1445    else
     1446    if ((!c->nc) && (c->lengths[i]==1) && (c->lengths[j]==1))
     1447    {
    14121448      c->states[i][j]=HASTREP;
    1413 
    1414       }
     1449    }
    14151450    else if (( (!c->nc) || (c->is_homog && rIsSCA(c->r) ) ) &&  (pHasNotCF(c->S->m[i],c->S->m[j])))
    14161451//     else if ((!(c->nc)) &&  (pHasNotCF(c->S->m[i],c->S->m[j])))
     
    14241459      c->states[i][j]=HASTREP;
    14251460      c->extended_product_crit++;
    1426 
    14271461      //PrintS("E");
    14281462    }
    1429       //  if (c->states[i][j]==UNCALCULATED){
     1463      //  if (c->states[i][j]==UNCALCULATED)
     1464      //  {
    14301465
    14311466    if ((TEST_V_FINDMONOM) &&(!c->nc)) {
    14321467        //PrintS("COMMU");
    1433        //  if (c->lengths[i]==c->lengths[j]){
     1468       //  if (c->lengths[i]==c->lengths[j])
     1469       //  {
    14341470//             poly short_s=ksCreateShortSpoly(c->S->m[i],c->S->m[j],c->r);
    1435 //             if (short_s==NULL){
     1471//             if (short_s==NULL)
     1472//             {
    14361473//                 c->states[i][j]=HASTREP;
    1437 //             } else
     1474//             }
     1475//             else
    14381476//             {
    14391477//                 p_Delete(&short_s, currRing);
    14401478//             }
    14411479//         }
    1442         if (c->lengths[i]+c->lengths[j]==3){
     1480        if (c->lengths[i]+c->lengths[j]==3)
     1481        {
    14431482
    14441483
     
    14681507                else
    14691508                {
    1470                     if (c->strat->lenS[iS]>1){
     1509                    if (c->strat->lenS[iS]>1)
     1510                    {
    14711511                        //PrintS("O");
    14721512                        if (TRUE) {
    14731513                        c->states[i][j]=HASTREP;
    14741514                        add_later(short_s,"O",c);
    1475                         } else p_Delete(&short_s,currRing);
     1515                        }
     1516                        else p_Delete(&short_s,currRing);
    14761517                    }
    14771518                    else
     
    15221563  }//if syz_comp end
    15231564
    1524 
    1525 
    1526 
    15271565  assume(spc<=i);
    15281566  //now ideal quotient crit
     
    15411579      if(!pLmEqual(nodes[lower]->lcm_of_lm,nodes[upper]->lcm_of_lm))
    15421580      {
    1543         break;
     1581  break;
    15441582      }
    15451583      if (has_t_rep(nodes[upper]->i,nodes[upper]->j,c))
    1546         has=TRUE;
     1584  has=TRUE;
    15471585    }
    15481586    upper=upper-1;
     
    15921630  //  Print("i:%d,spc_final:%d",i,spc_final);
    15931631
    1594 
    1595 
    1596 
    15971632  assume(spc_final<=spc);
    15981633  omfree(nodes);
     
    16011636  add_to_reductors(c, h, c->lengths[c->n-1], ecart,TRUE);
    16021637  //i=posInS(c->strat,c->strat->sl,h,0 ecart);
    1603   if (!(c->nc)){
     1638  if (!(c->nc))
     1639  {
    16041640    if (c->lengths[c->n-1]==1)
    16051641      shorten_tails(c,c->S->m[c->n-1]);
     
    16561692
    16571693
    1658   if(!ip){
     1694  if(!ip)
     1695  {
    16591696    qsort(nodes_final,spc_final,sizeof(sorted_pair_node*),tgb_pair_better_gen2);
    16601697
     
    16701707    return nodes_final;
    16711708  }
    1672 
    1673 
    1674 
    1675 }
    1676 
     1709}
    16771710
    16781711static poly redNF2 (poly h,slimgb_alg* c , int &len, number&  m,int n)
     
    17581791}
    17591792
    1760 
    1761 
    1762 static poly redTailShort(poly h, kStrategy strat){
     1793static poly redTailShort(poly h, kStrategy strat)
     1794{
    17631795  if (h==NULL) return NULL;//n_Init(1,currRing);
    1764   if (TEST_V_MODPSOLVSB){
     1796  if (TEST_V_MODPSOLVSB)
     1797  {
    17651798    bit_reduce(pNext(h), strat->tailRing);
    17661799  }
     
    17681801  int i;
    17691802  int len=pLength(h);
    1770   for(i=0;i<=strat->sl;i++){
     1803  for(i=0;i<=strat->sl;i++)
     1804  {
    17711805    if((strat->lenS[i]>2) || ((strat->lenSw!=NULL) && (strat->lenSw[i]>2)))
    17721806      break;
     
    17751809}
    17761810
    1777 static void line_of_extended_prod(int fixpos,slimgb_alg* c){
     1811static void line_of_extended_prod(int fixpos,slimgb_alg* c)
     1812{
    17781813    if (c->gcd_of_terms[fixpos]==NULL)
    17791814  {
     
    17961831  }
    17971832}
    1798 static void c_S_element_changed_hook(int pos, slimgb_alg* c){
     1833static void c_S_element_changed_hook(int pos, slimgb_alg* c)
     1834{
    17991835  length_one_crit(c,pos, c->lengths[pos]);
    18001836  if (!c->nc)
     
    18071843  poly_tree_node* r;
    18081844  int n;
    1809   poly_tree_node(int sn):l(NULL),r(NULL),n(sn){}
     1845  poly_tree_node(int sn):l(NULL),r(NULL),n(sn)
     1846  {}
    18101847};
    18111848class exp_number_builder{
     
    18141851  int n;
    18151852  int get_n(poly p);
    1816   exp_number_builder():top_level(0),n(0){}
     1853  exp_number_builder():top_level(0),n(0)
     1854  {}
    18171855};
    1818 int exp_number_builder::get_n(poly p){
     1856int exp_number_builder::get_n(poly p)
     1857{
    18191858  poly_tree_node** node=&top_level;
    1820   while(*node!=NULL){
     1859  while(*node!=NULL)
     1860  {
    18211861    int c=pLmCmp(p,(*node)->p);
    18221862    if (c==0) return (*node)->n;
     
    18421882
    18431883//! obsolete
    1844 void t2ippa_rec(poly* ip,int* ia, poly_tree_node* k, int &offset){
     1884void t2ippa_rec(poly* ip,int* ia, poly_tree_node* k, int &offset)
     1885{
    18451886    if(!k) return;
    18461887    t2ippa_rec(ip,ia,k->l,offset);
     
    18541895
    18551896//! obsolete
    1856 void t2ippa(poly* ip,int* ia,exp_number_builder & e){
     1897void t2ippa(poly* ip,int* ia,exp_number_builder & e)
     1898{
    18571899
    18581900  int o=0;
    18591901  t2ippa_rec(ip,ia,e.top_level,o);
    18601902}
    1861 int anti_poly_order(const void* a, const void* b){
     1903int anti_poly_order(const void* a, const void* b)
     1904{
    18621905  return -pLmCmp(((int_poly_pair*) a)->p,((int_poly_pair*) b)->p );
    18631906}
    18641907
    1865 BOOLEAN is_valid_ro(red_object & ro){
     1908BOOLEAN is_valid_ro(red_object & ro)
     1909{
    18661910  red_object r2=ro;
    18671911  ro.validate();
     
    18691913  return TRUE;
    18701914}
    1871 int terms_sort_crit(const void* a, const void* b){
     1915int terms_sort_crit(const void* a, const void* b)
     1916{
    18721917  return -pLmCmp(*((poly*) a),*((poly*) b));
    18731918}
    1874 static void unify_terms(poly* terms,int & sum){
     1919static void unify_terms(poly* terms,int & sum)
     1920{
    18751921  if (sum==0) return;
    18761922  int last=0;
    18771923  int curr=1;
    1878   while(curr<sum){
    1879     if (!(pLmEqual(terms[curr],terms[last]))){
     1924  while(curr<sum)
     1925  {
     1926    if (!(pLmEqual(terms[curr],terms[last])))
     1927    {
    18801928      terms[++last]=terms[curr];
    18811929    }
     
    18841932  sum=last+1;
    18851933}
    1886 static void export_mat(number* number_array,int pn, int tn,const char* format_str, int mat_nr){
     1934static void export_mat(number* number_array,int pn, int tn,const char* format_str, int mat_nr)
     1935{
    18871936  char matname[20];
    18881937  sprintf(matname,format_str,mat_nr);
     
    18901939  int i,j;
    18911940  fprintf(out,"mat=[\n");
    1892   for(i=0;i<pn;i++){
     1941  for(i=0;i<pn;i++)
     1942  {
    18931943    fprintf(out,"[\n");
    18941944    for(j=0;j<tn;j++)
     
    19131963#ifdef USE_NORO
    19141964#ifndef NORO_CACHE
    1915 static void linalg_step_modp(poly *p, poly* p_out, int& pn, poly* terms,int tn, slimgb_alg* c){
     1965static void linalg_step_modp(poly *p, poly* p_out, int& pn, poly* terms,int tn, slimgb_alg* c)
     1966{
    19161967  static int export_n=0;
    19171968  assume(terms[tn-1]!=NULL);
     
    19221973  number_type* number_array=(number_type*) omalloc(pn*tn*sizeof(number_type));
    19231974  int i;
    1924   for(i=0;i<array_size;i++){
     1975  for(i=0;i<array_size;i++)
     1976  {
    19251977    number_array[i]=zero;
    19261978  }
    1927   for(i=0;i<pn;i++){
     1979  for(i=0;i<pn;i++)
     1980  {
    19281981    poly h=p[i];
    19291982    //int base=tn*i;
     
    19391992  int act_row=0;
    19401993  int p_pos=0;
    1941   for(i=0;i<pn;i++){
     1994  for(i=0;i<pn;i++)
     1995  {
    19421996    poly h=NULL;
    19431997    int j;
     
    19532007  pn=p_pos;
    19542008  //assert(p_pos==rank)
    1955   while(p_pos<pn){
     2009  while(p_pos<pn)
     2010  {
    19562011    p_out[p_pos++]=NULL;
    19572012  }
     
    19622017#endif
    19632018#endif
    1964 static void mass_add(poly* p, int pn,slimgb_alg* c){
     2019static void mass_add(poly* p, int pn,slimgb_alg* c)
     2020{
    19652021    int j;
    19662022    int* ibuf=(int*) omalloc(pn*sizeof(int));
    19672023    sorted_pair_node*** sbuf=(sorted_pair_node***) omalloc(pn*sizeof(sorted_pair_node**));
    1968     for(j=0;j<pn;j++){
     2024    for(j=0;j<pn;j++)
     2025    {
    19692026      p_Test(p[j],c->r);
    19702027      sbuf[j]=add_to_basis_ideal_quotient(p[j],c,ibuf+j);
    19712028    }
    19722029    int sum=0;
    1973     for(j=0;j<pn;j++){
     2030    for(j=0;j<pn;j++)
     2031    {
    19742032      sum+=ibuf[j];
    19752033    }
     
    20032061#ifdef NORO_CACHE
    20042062#ifndef NORO_NON_POLY
    2005 void NoroCache::evaluateRows(){
     2063void NoroCache::evaluateRows()
     2064{
    20062065  //after that can evaluate placeholders
    20072066  int i;
    20082067  buffer=(number*) omalloc(nIrreducibleMonomials*sizeof(number));
    2009   for(i=0;i<root.branches_len;i++){
     2068  for(i=0;i<root.branches_len;i++)
     2069  {
    20102070    evaluateRows(1,root.branches[i]);
    20112071  }
     
    20132073  buffer=NULL;
    20142074}
    2015 void NoroCache::evaluateRows(int level, NoroCacheNode* node){
     2075void NoroCache::evaluateRows(int level, NoroCacheNode* node)
     2076{
    20162077  assume(level>=0);
    20172078  if (node==NULL) return;
    2018   if (level<pVariables){
     2079  if (level<pVariables)
     2080  {
    20192081    int i,sum;
    2020     for(i=0;i<node->branches_len;i++){
     2082    for(i=0;i<node->branches_len;i++)
     2083    {
    20212084      evaluateRows(level+1,node->branches[i]);
    20222085    }
    2023   } else {
     2086  }
     2087  else
     2088  {
    20242089    DataNoroCacheNode* dn=(DataNoroCacheNode*) node;
    2025     if (dn->value_len!=backLinkCode){
     2090    if (dn->value_len!=backLinkCode)
     2091    {
    20262092      poly p=dn->value_poly;
    20272093      #ifndef NORO_SPARSE_ROWS_PRE
     
    20342100      int idx;
    20352101      number* a=buffer;
    2036       while(p){
     2102      while(p)
     2103      {
    20372104        DataNoroCacheNode* ref=getCacheReference(p);
    20382105
     
    20542121      SparseRow* row=dn->row;
    20552122      int i=0;
    2056       while(p){
     2123      while(p)
     2124      {
    20572125        DataNoroCacheNode* ref=getCacheReference(p);
    20582126
     
    20612129        row->idx_array[i]=idx;
    20622130        row->coef_array[i]=p_GetCoeff(p,currRing);
    2063 
    20642131        i++;
    20652132        pIter(p);
    20662133      }
    2067       if (i!=dn->value_len){
     2134      if (i!=dn->value_len)
     2135      {
    20682136        PrintS("F4 calc wrong, as poly len was wrong\n");
    20692137      }
    20702138      assume(i==dn->value_len);
    20712139      #endif
    2072 
    2073     }
    2074   }
    2075 }
    2076 
    2077 void NoroCache::evaluatePlaceHolder(number* row,std::vector<NoroPlaceHolder>& place_holders){
     2140    }
     2141  }
     2142}
     2143
     2144void NoroCache::evaluatePlaceHolder(number* row,std::vector<NoroPlaceHolder>& place_holders)
     2145{
    20782146  int i;
    20792147  int s=place_holders.size();
    2080   for(i=0;i<s;i++){
     2148  for(i=0;i<s;i++)
     2149  {
    20812150    DataNoroCacheNode* ref=place_holders[i].ref;
    20822151    number coef=place_holders[i].coef;
    2083     if (ref->value_len==backLinkCode){
     2152    if (ref->value_len==backLinkCode)
     2153    {
    20842154      row[ref->term_index]=npAddM(row[ref->term_index],coef);
    2085     } else {
     2155    }
     2156    else
     2157    {
    20862158      #ifndef NORO_SPARSE_ROWS_PRE
    20872159      DenseRow* ref_row=ref->row;
     
    20912163      number* my_pos=row+ref_row->begin;
    20922164      //TODO npisOne distinction
    2093       if (!(npIsOne(coef))){
    2094         while(ref_begin!=ref_end){
     2165      if (!(npIsOne(coef)))
     2166      {
     2167        while(ref_begin!=ref_end)
     2168        {
    20952169
    20962170          *my_pos=npAddM(*my_pos,npMult(coef,*ref_begin));
     
    20992173        }
    21002174      }
    2101       else{
    2102         while(ref_begin!=ref_end){
     2175      else
     2176      {
     2177        while(ref_begin!=ref_end)
     2178        {
    21032179
    21042180          *my_pos=npAddM(*my_pos,*ref_begin);
     
    21072183        }
    21082184      }
    2109 
    2110 
    21112185
    21122186    #else
     
    21172191    int* idx_array=ref_row->idx_array;
    21182192    number* coef_array=ref_row->coef_array;
    2119     for(j=0;j<n;j++){
     2193    for(j=0;j<n;j++)
     2194    {
    21202195      int idx=idx_array[j];
    21212196      number ref_coef=coef_array[j];
     
    21252200  }
    21262201  }
    2127 
    21282202}
    21292203#endif
    21302204
    2131 
    2132 
    21332205//poly noro_red_non_unique(poly p, int &len, NoroCache* cache,slimgb_alg* c);
    21342206
    2135 
    21362207#ifndef NORO_NON_POLY
    2137 MonRedRes noro_red_mon(poly t, BOOLEAN force_unique, NoroCache* cache,slimgb_alg* c){
     2208MonRedRes noro_red_mon(poly t, BOOLEAN force_unique, NoroCache* cache,slimgb_alg* c)
     2209{
    21382210  MonRedRes res_holder;
    21392211
    21402212  //wrp(t);
    21412213  res_holder.changed=TRUE;
    2142   if (force_unique){
     2214  if (force_unique)
     2215  {
    21432216    DataNoroCacheNode* ref=cache->getCacheReference(t);
    2144     if (ref!=NULL){
     2217    if (ref!=NULL)
     2218    {
    21452219      res_holder.len=ref->value_len;
    2146       if (res_holder.len==NoroCache::backLinkCode){
     2220      if (res_holder.len==NoroCache::backLinkCode)
     2221      {
    21472222        res_holder.len=1;
    2148 
    2149 
    21502223      }
    21512224      res_holder.coef=p_GetCoeff(t,c->r);
     
    21572230      return res_holder;
    21582231    }
    2159   } else{
     2232  }
     2233  else
     2234  {
    21602235    BOOLEAN succ;
    21612236    poly cache_lookup=cache->lookup(t,succ, res_holder.len);//don't own this yet
    2162     if (succ){
    2163       if (cache_lookup==t){
     2237    if (succ)
     2238    {
     2239      if (cache_lookup==t)
     2240      {
    21642241      //know they are equal
    21652242      //res_holder.len=1;
     
    22122289      //p_Delete(&t_copy_mon,c->r);
    22132290      //res=pMult_nn(res,coef_bak);
    2214 
    22152291    res_holder.changed=TRUE;
    22162292    res_holder.p=res;
     
    22192295    res_holder.ref=ref;
    22202296    return res_holder;
    2221 
    2222   } else {
     2297  }
     2298  else
     2299  {
    22232300    number coef_bak=p_GetCoeff(t,c->r);
    22242301    number one=npInit(1);
    22252302    p_SetCoeff(t,one,c->r);
    22262303    res_holder.len=1;
    2227     if (!(force_unique)){
     2304    if (!(force_unique))
     2305    {
    22282306      res_holder.ref=cache->insert(t,t,res_holder.len);
    22292307      p_SetCoeff(t,coef_bak,c->r);
     
    22372315      res_holder.onlyBorrowed=FALSE;
    22382316      return res_holder;
    2239     } else {
     2317    }
     2318    else
     2319    {
    22402320      res_holder.ref=cache->insertAndTransferOwnerShip(t,c->r);
    22412321      res_holder.coef=coef_bak;
     
    22522332#ifndef NORO_NON_POLY
    22532333//len input and out: Idea: reverse addition
    2254 poly noro_red_non_unique(poly p, int &len, NoroCache* cache,slimgb_alg* c){
     2334poly noro_red_non_unique(poly p, int &len, NoroCache* cache,slimgb_alg* c)
     2335{
    22552336  assume(len==pLength(p));
    22562337  poly orig_p=p;
     
    22652346  int unchanged_size=0;
    22662347
    2267   while(p){
     2348  while(p)
     2349  {
    22682350    poly t=p;
    22692351    pIter(p);
     
    22732355#endif
    22742356    MonRedRes red=noro_red_mon(t,FALSE,cache,c);
    2275     if ((!(red.changed))&&(!(red.onlyBorrowed))){
     2357    if ((!(red.changed))&&(!(red.onlyBorrowed)))
     2358    {
    22762359      unchanged_size++;
    22772360      assume(npIsOne(red.coef));
    22782361      assume(p_GetCoeff(red.p,currRing)==coef_debug);
    2279       if (unchanged_head){
     2362      if (unchanged_head)
     2363      {
    22802364        pNext(unchanged_tail)=red.p;
    22812365        pIter(unchanged_tail);
    2282       } else{
     2366      }
     2367      else
     2368      {
    22832369        unchanged_tail=red.p;
    22842370        unchanged_head=red.p;
    22852371      }
    2286     } else{
     2372    }
     2373    else
     2374    {
    22872375      assume(red.len==pLength(red.p));
    2288       if (red.onlyBorrowed){
    2289         if (npIsOne(red.coef)){
     2376      if (red.onlyBorrowed)
     2377      {
     2378        if (npIsOne(red.coef))
     2379        {
    22902380          t=p_Copy(red.p,currRing);
    2291         }else
     2381        }
     2382        else
    22922383        t=pp_Mult_nn(red.p,red.coef,currRing);
    2293       } else {
     2384      }
     2385      else
     2386      {
    22942387        if (npIsOne(red.coef))
    22952388        t=red.p;
     
    23052398  kBucketClear(bucket,&res,&len);
    23062399  kBucketDestroy(&bucket);
    2307 
    2308 
    2309 
    2310 
    23112400  return res;
    23122401}
     
    23152404//len input and out: Idea: reverse addition
    23162405
    2317 /*template <class number_type> SparseRow<number_type>* noro_red_to_non_poly(poly p, int &len, NoroCache<number_type>* cache,slimgb_alg* c){
    2318   if (npPrimeM<255){
     2406/*template <class number_type> SparseRow<number_type>* noro_red_to_non_poly(poly p, int &len, NoroCache<number_type>* cache,slimgb_alg* c)
     2407 * {
     2408  if (npPrimeM<255)
     2409  {
    23192410    return noro_red_to_non_poly_t<tgb_uint8>(p,len,cache,c);
    2320   } else {
    2321     if (npPrimeM<65000){
     2411  }
     2412  else
     2413  {
     2414    if (npPrimeM<65000)
     2415    {
    23222416      return noro_red_to_non_poly_t<tgb_uint16>(p,len,cache,c);
    2323     } else{
     2417    }
     2418    else
     2419    {
    23242420      return noro_red_to_non_poly_t<tgb_uint32>(p,len,cache,c);
    23252421    }
     
    23292425//len input and out: Idea: reverse addition
    23302426#ifndef NORO_NON_POLY
    2331 std::vector<NoroPlaceHolder> noro_red(poly p, int &len, NoroCache* cache,slimgb_alg* c){
     2427std::vector<NoroPlaceHolder> noro_red(poly p, int &len, NoroCache* cache,slimgb_alg* c)
     2428{
    23322429  std::vector<NoroPlaceHolder> res;
    2333    while(p){
     2430   while(p)
     2431   {
    23342432      poly t=p;
    23352433      pIter(p);
     
    23512449#endif
    23522450
    2353 
    2354 
    2355 
    2356 
    23572451#endif
    23582452#ifdef USE_NORO
    23592453#ifndef NORO_CACHE
    2360 void noro_step(poly*p,int &pn,slimgb_alg* c){
     2454void noro_step(poly*p,int &pn,slimgb_alg* c)
     2455{
    23612456  poly* reduced=(poly*) omalloc(pn*sizeof(poly));
    23622457  int j;
     
    23682463  NoroCache cache;
    23692464#endif
    2370   for(j=0;j<pn;j++){
     2465  for(j=0;j<pn;j++)
     2466  {
    23712467
    23722468    poly h=p[j];
     
    23802476    assume(pLength(h)==h_len);
    23812477#endif
    2382     if (h!=NULL){
     2478    if (h!=NULL)
     2479    {
    23832480#ifndef NORO_CACHE
    23842481
     
    23862483      h_len=pLength(h);
    23872484#endif
    2388 
    2389 
    23902485      reduced[reduced_c]=h;
    23912486      reduced_len[reduced_c]=h_len;
     
    23962491  }
    23972492  int reduced_sum=0;
    2398   for(j=0;j<reduced_c;j++){
     2493  for(j=0;j<reduced_c;j++)
     2494  {
    23992495    reduced_sum+=reduced_len[j];
    24002496  }
    24012497  poly* terms=(poly*) omalloc(reduced_sum*sizeof(poly));
    24022498  int tc=0;
    2403   for(j=0;j<reduced_c;j++){
     2499  for(j=0;j<reduced_c;j++)
     2500  {
    24042501    poly h=reduced[j];
    24052502
    2406     while(h!=NULL){
     2503    while(h!=NULL)
     2504    {
    24072505      terms[tc++]=h;
    24082506      pIter(h);
     
    24302528#else
    24312529
    2432 
    2433 
    24342530#endif
    24352531#endif
    2436 static void go_on (slimgb_alg* c){
     2532static void go_on (slimgb_alg* c)
     2533{
    24372534  //set limit of 1000 for multireductions, at the moment for
    24382535  //programming reasons
     
    24452542  int i=0;
    24462543  c->average_length=0;
    2447   for(i=0;i<c->n;i++){
     2544  for(i=0;i<c->n;i++)
     2545  {
    24482546    c->average_length+=c->lengths[i];
    24492547  }
     
    24592557
    24602558  int curr_deg=-1;
    2461   while(i<max_pairs){
     2559  while(i<max_pairs)
     2560  {
    24622561    sorted_pair_node* s=top_pair(c);//here is actually chain criterium done
    24632562
    2464 
    24652563    if (!s) break;
    24662564
    2467     if(curr_deg>=0){
     2565    if(curr_deg>=0)
     2566    {
    24682567      if (s->deg >curr_deg) break;
    24692568    }
     
    24712570    else curr_deg=s->deg;
    24722571    quick_pop_pair(c);
    2473     if(s->i>=0){
     2572    if(s->i>=0)
     2573    {
    24742574      //be careful replace_pair use createShortSpoly which is not noncommutative
    24752575      now_t_rep(s->i,s->j,c);
     
    24982598    p_Test(h,c->r);
    24992599    }
    2500     else{
     2600    else
     2601    {
    25012602      h=s->lcm_of_lm;
    25022603      p_Test(h,c->r);
     
    25072608    int mlen=pLength(h);
    25082609    p_Test(h,c->r);
    2509     if ((!c->nc)&(!(use_noro))){
     2610    if ((!c->nc)&(!(use_noro)))
     2611    {
    25102612      h=redNF2(h,c,mlen,coef,2);
    25112613      redTailShort(h,c->strat);
     
    25172619    int len=pLength(h);
    25182620    p[i]=h;
    2519 
    25202621    i++;
    25212622  }
    25222623  p[i]=NULL;
    25232624//  pre_comp(p,i,c);
    2524   if(i==0){
     2625  if(i==0)
     2626  {
    25252627    omfree(p);
    25262628    return;
     
    25342636  int j;
    25352637#ifdef USE_NORO
    2536   //if ((!(c->nc))&&(rField_is_Zp(c->r))){
    2537   if (use_noro){
     2638  //if ((!(c->nc))&&(rField_is_Zp(c->r)))
     2639  //{
     2640  if (use_noro)
     2641  {
    25382642    int pn=i;
    25392643    if (pn==0) {omfree(p);return;}
    2540 
    2541     {
    2542 
    2543       if (npPrimeM<255){
     2644    {
     2645      if (npPrimeM<255)
     2646      {
    25442647        noro_step<tgb_uint8>(p,pn,c);
    2545       } else {
    2546         if (npPrimeM<65000){
     2648      }
     2649      else
     2650      {
     2651        if (npPrimeM<65000)
     2652        {
    25472653          noro_step<tgb_uint16>(p,pn,c);
    2548         } else{
     2654        }
     2655        else
     2656        {
    25492657          noro_step<tgb_uint32>(p,pn,c);
    25502658        }
    25512659      }
    2552 
    2553 
    2554 
    2555     }
    2556 
    2557     //if (TEST_OPT_PROT){
     2660    }
     2661
     2662    //if (TEST_OPT_PROT)
     2663    //{
    25582664    //  Print("reported rank:%i\n",pn);
    25592665    //}
     
    25622668    return;
    25632669    /*if (TEST_OPT_PROT)
    2564       for(j=0;j<pn;j++){
     2670      for(j=0;j<pn;j++)
     2671      {
    25652672        p_wrp(p[j],c->r);
    25662673      }*/
     
    25682675#endif
    25692676  red_object* buf=(red_object*) omalloc(i*sizeof(red_object));
    2570   for(j=0;j<i;j++){
     2677  for(j=0;j<i;j++)
     2678  {
    25712679    p_Test(p[j],c->r);
    25722680    buf[j].p=p[j];
     
    25742682    buf[j].bucket = kBucketCreate(currRing);
    25752683    p_Test(p[j],c->r);
    2576     if (c->eliminationProblem){
     2684    if (c->eliminationProblem)
     2685    {
    25772686        buf[j].sugar=c->pTotaldegree_full(p[j]);
    25782687    }
     
    25962705        PrintS("B");
    25972706    int e;
    2598     for(e=0;e<=c->pair_top;e++){
     2707    for(e=0;e<=c->pair_top;e++)
     2708    {
    25992709        if(c->apairs[e]->i<0) continue;
    26002710        assume(c->apairs[e]->j>=0);
     
    26372747    p_Test(p,c->r);
    26382748    //if (!c->nc) {
    2639       if ((c->tailReductions) ||(lies_in_last_dp_block(p,c))){
     2749      if ((c->tailReductions) ||(lies_in_last_dp_block(p,c)))
     2750      {
    26402751      p=redNFTail(p,c->strat->sl,c->strat, 0);
    2641       } else {
     2752      }
     2753      else
     2754      {
    26422755      p=redTailShort(p, c->strat);
    26432756      }
     
    26512764  omfree(add_those);
    26522765  omfree(buf);
    2653 
    2654 
    2655 
    2656 
    2657 
    2658 
    26592766
    26602767  if (TEST_OPT_PROT)
     
    26682775  return;
    26692776}
    2670 
    2671 
    26722777
    26732778#ifdef REDTAIL_S
     
    27202825            pTest(strat->S[j]);
    27212826#ifdef HAVE_PLURAL
    2722             if (nc){
     2827            if (nc)
     2828            {
    27232829              nc_BucketPolyRed_Z(P.bucket, strat->S[j], &coef);
    2724             } else
     2830            }
     2831            else
    27252832#endif
    27262833              coef=kBucketPolyRed(P.bucket,strat->S[j],
     
    27802887
    27812888//transfers ownership of m to mat
    2782 void init_with_mac_poly(tgb_sparse_matrix* mat, int row, mac_poly m){
     2889void init_with_mac_poly(tgb_sparse_matrix* mat, int row, mac_poly m)
     2890{
    27832891  assume(mat->mp[row]==NULL);
    27842892  mat->mp[row]=m;
    27852893#ifdef TGB_DEBUG
    27862894  mac_poly r=m;
    2787   while(r){
     2895  while(r)
     2896  {
    27882897    assume(r->exp<mat->columns);
    27892898    r=r->next;
     
    27912900#endif
    27922901}
    2793 poly free_row_to_poly(tgb_sparse_matrix* mat, int row, poly* monoms, int monom_index){
     2902poly free_row_to_poly(tgb_sparse_matrix* mat, int row, poly* monoms, int monom_index)
     2903{
    27942904  poly p=NULL;
    27952905  poly* set_this=&p;
     
    28072917  }
    28082918  return p;
    2809 
    2810 }
    2811 
    2812 
    2813 
    2814 
    2815 
    2816 
    2817 
    2818 
    2819 
    2820 
    2821 
    2822 static int poly_crit(const void* ap1, const void* ap2){
     2919}
     2920
     2921static int poly_crit(const void* ap1, const void* ap2)
     2922{
    28232923  poly p1,p2;
    28242924  p1=*((poly*) ap1);
     
    28332933  return 0;
    28342934}
    2835 void slimgb_alg::introduceDelayedPairs(poly* pa,int s){
     2935
     2936void slimgb_alg::introduceDelayedPairs(poly* pa,int s)
     2937{
    28362938    if (s==0) return;
    28372939    sorted_pair_node** si_array=(sorted_pair_node**) omalloc(s* sizeof(sorted_pair_node*));
     
    28572959        //      c->apairs[n-1-i]=si;
    28582960        si_array[i]=si;
    2859 
    28602961  }
    28612962
     
    28652966  omfree(si_array);
    28662967}
     2968
    28672969slimgb_alg::slimgb_alg(ideal I, int syz_comp,BOOLEAN F4,int deg_pos)
    28682970{
     
    29323034  pair_top=-1;
    29333035
    2934   int nn=IDELEMS(I);
    2935   array_lengths=nn;
     3036  int n=IDELEMS(I);
     3037  array_lengths=n;
     3038
    29363039
    29373040  i=0;
    29383041  this->n=0;
    2939   T_deg=(int*) omalloc(nn*sizeof(int));
     3042  T_deg=(int*) omalloc(n*sizeof(int));
    29403043  if(eliminationProblem)
    2941     T_deg_full=(int*) omalloc(nn*sizeof(int));
     3044    T_deg_full=(int*) omalloc(n*sizeof(int));
    29423045  else
    29433046    T_deg_full=NULL;
    2944   tmp_pair_lm=(poly*) omalloc(nn*sizeof(poly));
    2945   tmp_spn=(sorted_pair_node**) omalloc(nn*sizeof(sorted_pair_node*));
     3047  tmp_pair_lm=(poly*) omalloc(n*sizeof(poly));
     3048  tmp_spn=(sorted_pair_node**) omalloc(n*sizeof(sorted_pair_node*));
    29463049  lm_bin=omGetSpecBin(POLYSIZE + (r->ExpL_Size)*sizeof(long));
    29473050#ifdef HEAD_BIN
     
    29523055  #ifdef USE_STDVECBOOL
    29533056  #else
    2954   h=omalloc(nn*sizeof(char*));
     3057  h=omalloc(n*sizeof(char*));
    29553058
    29563059  states=(char**) h;
     
    29593062  h=omalloc(n*sizeof(int));
    29603063  lengths=(int*) h;
    2961   weighted_lengths=(wlen_type*)omalloc(nn*sizeof(wlen_type));
    2962   gcd_of_terms=(poly*) omalloc(nn*sizeof(poly));
    2963 
    2964   short_Exps=(long*) omalloc(nn*sizeof(long));
     3064  weighted_lengths=(wlen_type*)omalloc(n*sizeof(wlen_type));
     3065  gcd_of_terms=(poly*) omalloc(n*sizeof(poly));
     3066
     3067  short_Exps=(long*) omalloc(n*sizeof(long));
    29653068  if (F4_mode)
    2966     S=idInit(nn,I->rank);
     3069    S=idInit(n,I->rank);
    29673070  else
    29683071    S=idInit(1,I->rank);
     
    29773080  strat->enterS = enterSBba;
    29783081  strat->sl = -1;
    2979   i=nn;
     3082  i=n;
    29803083  i=1;//some strange bug else
    29813084  /* initS(c->S,NULL,c->strat); */
     
    29953098    strat->lenSw=NULL;
    29963099  sorted_pair_node* si;
    2997   assume(nn>0);
     3100  assume(n>0);
    29983101  add_to_basis_ideal_quotient(I->m[0],this,NULL);
    29993102
     
    30013104  if(!(F4_mode))
    30023105  {
    3003     poly* array_arg=I->m;
    3004     array_arg++;
    3005     introduceDelayedPairs(array_arg,n-1);
    3006     /*
     3106        poly* array_arg=I->m;
     3107        array_arg++;
     3108        introduceDelayedPairs(array_arg,n-1);
     3109        /*
    30073110    for (i=1;i<n;i++)//the 1 is wanted, because first element is added to basis
    30083111    {
     
    30193122      si->lcm_of_lm=I->m[i];
    30203123
    3021       //      c->apairs[nn-1-i]=si;
    3022       apairs[nn-i-1]=si;
     3124      //      c->apairs[n-1-i]=si;
     3125      apairs[n-i-1]=si;
    30233126      ++(pair_top);
    3024     }
    3025     */
     3127    }*/
    30263128  }
    30273129  else
    30283130  {
    3029     for (i=1;i<nn;i++)//the 1 is wanted, because first element is added to basis
     3131    for (i=1;i<n;i++)//the 1 is wanted, because first element is added to basis
    30303132      add_to_basis_ideal_quotient(I->m[i],this,NULL);
    30313133  }
     
    30523154slimgb_alg::~slimgb_alg()
    30533155{
     3156
    30543157  if (!(completed))
    30553158  {
    3056     poly* add=(poly*) omalloc((pair_top+2)*sizeof(poly));
    3057     int piter;
    3058     int pos=0;
    3059     for(piter=0;piter<=pair_top;piter++)
    3060     {
    3061       sorted_pair_node* s=apairs[piter];
    3062       if (s->i<0)
    3063       {
    3064         //delayed element
    3065         if (s->lcm_of_lm!=NULL)
    3066         {
    3067           add[pos]=s->lcm_of_lm;
    3068           pos++;
     3159      poly* add=(poly*) omalloc((pair_top+2)*sizeof(poly));
     3160      int piter;
     3161      int pos=0;
     3162      for(piter=0;piter<=pair_top;piter++)
     3163      {
     3164        sorted_pair_node* s=apairs[piter];
     3165        if (s->i<0)
     3166        {
     3167            //delayed element
     3168            if (s->lcm_of_lm!=NULL)
     3169            {
     3170                add[pos]=s->lcm_of_lm;
     3171                pos++;
     3172            }
    30693173        }
    3070       }
    3071       free_sorted_pair_node(s,r);
    3072       apairs[piter]=NULL;
    3073     }
    3074     pair_top=-1;
    3075     add[pos]=NULL;
    3076     pos=0;
    3077     while(add[pos]!=NULL)
    3078     {
    3079       add_to_basis_ideal_quotient(add[pos],this,NULL);
    3080       pos++;
    3081     }
    3082     for(piter=0;piter<=pair_top;piter++)
    3083     {
    3084       sorted_pair_node* s=apairs[piter];
    3085       assume(s->i>=0);
    3086       free_sorted_pair_node(s,r);
    3087       apairs[piter]=NULL;
    3088     }
    3089     pair_top=-1;
     3174        free_sorted_pair_node(s,r);
     3175        apairs[piter]=NULL;
     3176      }
     3177      pair_top=-1;
     3178      add[pos]=NULL;
     3179      pos=0;
     3180      while(add[pos]!=NULL)
     3181      {
     3182        add_to_basis_ideal_quotient(add[pos],this,NULL);
     3183        pos++;
     3184      }
     3185      for(piter=0;piter<=pair_top;piter++)
     3186      {
     3187        sorted_pair_node* s=apairs[piter];
     3188        assume(s->i>=0);
     3189        free_sorted_pair_node(s,r);
     3190        apairs[piter]=NULL;
     3191      }
     3192      pair_top=-1;
    30903193  }
    30913194  id_Delete(&add_later,r);
     
    31513254//   initsevS(i);
    31523255  omFree(c->strat->S_2_R);
     3256
     3257
    31533258  omFree(c->strat->lenS);
    31543259
     
    31843289    if(!found) pDelete(&c->strat->S[i]);
    31853290  }
    3186 //   for(i=0;i<c->n;i++){
    3187 //     if (c->rep[i]!=i){
    3188 // //       for(j=0;j<=c->strat->sl;j++){
    3189 // //   if(c->strat->S[j]==c->S->m[i]){
     3291//   for(i=0;i<c->n;i++)
     3292//   {
     3293//     if (c->rep[i]!=i)
     3294//     {
     3295// //       for(j=0;j<=c->strat->sl;j++)
     3296// {
     3297// //   if(c->strat->S[j]==c->S->m[i])
     3298// {
    31903299// //     c->strat->S[j]=NULL;
    31913300// //     break;
     
    31993308  if (completed)
    32003309  {
    3201     for(i=0;i<c->n;i++)
    3202     {
    3203       assume(c->S->m[i]!=NULL);
    3204       if (p_GetComp(c->S->m[i],currRing)>this->syz_comp) continue;
    3205       for(j=0;j<c->n;j++)
    3206       {
    3207         if((c->S->m[j]==NULL)||(i==j))
    3208           continue;
    3209         assume(p_LmShortDivisibleBy(c->S->m[j],c->short_Exps[j],
     3310  for(i=0;i<c->n;i++)
     3311  {
     3312    assume(c->S->m[i]!=NULL);
     3313    if (p_GetComp(c->S->m[i],currRing)>this->syz_comp) continue;
     3314    for(j=0;j<c->n;j++)
     3315    {
     3316      if((c->S->m[j]==NULL)||(i==j))
     3317        continue;
     3318      assume(p_LmShortDivisibleBy(c->S->m[j],c->short_Exps[j],
    32103319             c->S->m[i],~c->short_Exps[i],
    32113320             c->r)==p_LmDivisibleBy(c->S->m[j],
    32123321             c->S->m[i],
    32133322             c->r));
    3214         if (p_LmShortDivisibleBy(c->S->m[j],c->short_Exps[j],
     3323      if (p_LmShortDivisibleBy(c->S->m[j],c->short_Exps[j],
    32153324          c->S->m[i],~c->short_Exps[i],
    32163325          c->r))
    3217         {
    3218           pDelete(&c->S->m[i]);
    3219           break;
    3220         }
    3221       }
    3222     }
     3326      {
     3327        pDelete(&c->S->m[i]);
     3328        break;
     3329      }
     3330    }
     3331  }
    32233332  }
    32243333  omfree(c->short_Exps);
    32253334
    32263335  ideal I=c->S;
    3227 
    32283336  IDELEMS(I)=c->n;
    3229 
    32303337  idSkipZeroes(I);
    32313338  for(i=0;i<=c->strat->sl;i++)
     
    32383345ideal t_rep_gb(ring r,ideal arg_I, int syz_comp, BOOLEAN F4_mode)
    32393346{
    3240   assume(r==currRing);
    3241   ring orig_ring=r;
    3242   int pos;
    3243   ring new_ring=rAssure_TDeg(orig_ring,1,rVar(orig_ring),pos);
    3244 
    3245   ideal s_h;
    3246   if (orig_ring != new_ring)
    3247   {
    3248     rChangeCurrRing(new_ring);
    3249     s_h=idrCopyR_NoSort(arg_I,orig_ring);
    3250     idTest(s_h);
    3251     /*int i;
    3252 
    3253     for(i=0;i<IDELEMS(s_h);i++)
    3254     {
    3255       poly p=s_h->m[i];
    3256       while(p)
    3257       {
     3347    assume(r==currRing);
     3348    ring orig_ring=r;
     3349    int pos;
     3350    ring new_ring=rAssure_TDeg(orig_ring,1,rVar(orig_ring),pos);
     3351    ideal s_h;
     3352    if (orig_ring != new_ring)
     3353    {
     3354        rChangeCurrRing(new_ring);
     3355        s_h=idrCopyR_NoSort(arg_I,orig_ring);
     3356        idTest(s_h);
     3357        /*int i;
     3358        for(i=0;i<IDELEMS(s_h);i++)
     3359        {
     3360            poly p=s_h->m[i];
     3361            while(p)
     3362            {
    32583363                p_Setm(p,new_ring);
    32593364                pIter(p);
    3260       }
    3261     }
    3262     */
    3263   }
    3264   else
    3265   {
    3266     s_h = id_Copy(arg_I,orig_ring);
    3267   }
    3268 
    3269   ideal s_result=do_t_rep_gb(new_ring,s_h,syz_comp,F4_mode,pos);
    3270   ideal result;
    3271   if(orig_ring != new_ring)
    3272   {
    3273     idTest(s_result);
    3274     rChangeCurrRing(orig_ring);
    3275     result = idrMoveR_NoSort(s_result, new_ring);
    3276 
     3365            }
     3366        }*/
     3367    }
     3368    else
     3369    {
     3370        s_h = id_Copy(arg_I,orig_ring);
     3371    }
     3372
     3373    ideal s_result=do_t_rep_gb(new_ring,s_h,syz_comp,F4_mode,pos);
     3374    ideal result;
     3375    if(orig_ring != new_ring)
     3376    {
     3377        idTest(s_result);
     3378        rChangeCurrRing(orig_ring);
     3379        result = idrMoveR_NoSort(s_result, new_ring);
     3380
     3381        idTest(result);
     3382        //rChangeCurrRing(new_ring);
     3383        rKill(new_ring);
     3384        //rChangeCurrRing(orig_ring);
     3385    }
     3386    else
     3387        result=s_result;
    32773388    idTest(result);
    3278     //rChangeCurrRing(new_ring);
    3279     rKill(new_ring);
    3280     //rChangeCurrRing(orig_ring);
    3281   }
    3282   else
    3283     result=s_result;
    3284   idTest(result);
    3285   return result;
    3286 }
    3287 
    3288 ideal do_t_rep_gb(ring r,ideal arg_I, int syz_comp, BOOLEAN F4_mode,int deg_pos){
     3389    return result;
     3390}
     3391
     3392ideal do_t_rep_gb(ring r,ideal arg_I, int syz_comp, BOOLEAN F4_mode,int deg_pos)
     3393{
    32893394  //  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)));
    32903395
     
    33363441  return(I);
    33373442}
     3443
    33383444void now_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* c)
    33393445{
     
    33933499  {
    33943500    //enter tail
     3501
    33953502    if (c->S->m[i]==NULL) continue;
    33963503    poly tail=c->S->m[i]->next;
     
    34443551      if (c->strat->lenSw)
    34453552        c->strat->lenSw[old_pos]=q;
    3446 
    34473553      if (new_pos<old_pos)
    34483554        move_forward_in_S(old_pos,new_pos,c->strat);
    3449 
    34503555      length_one_crit(c,i,c->lengths[i]);
    34513556    }
    34523557  }
    34533558}
     3559
    34543560static sorted_pair_node* pop_pair(slimgb_alg* c)
    34553561{
     
    34593565  else return (c->apairs[c->pair_top--]);
    34603566}
     3567
    34613568void slimgb_alg::cleanDegs(int lower, int upper)
    34623569{
     
    34743581      if (T_deg[i]==deg)
    34753582      {
    3476         poly h;
    3477         h=S->m[i];
    3478         h=redNFTail(h,strat->sl,strat,lengths[i]);
    3479         if (!rField_is_Zp(r))
    3480         {
    3481           p_Cleardenom(h,r);
    3482           //p_Content(h,r);
    3483         }
    3484         else pNorm(h);
     3583          poly h;
     3584          h=S->m[i];
     3585          h=redNFTail(h,strat->sl,strat,lengths[i]);
     3586          if (!rField_is_Zp(r))
     3587          {
     3588            p_Cleardenom(h,r);
     3589            //p_Content(h,r);
     3590          }
     3591          else pNorm(h);
    34853592          //TODO:GCD of TERMS
    3486         poly got=::gcd_of_terms(h,r);
    3487         p_Delete(&gcd_of_terms[i],r);
    3488         gcd_of_terms[i]=got;
    3489         int len=pLength(h);
    3490         wlen_type wlen=pQuality(h,this,len);
    3491         if (weighted_lengths)
    3492           weighted_lengths[i]=wlen;
    3493         lengths[i]=len;
    3494         assume(h==S->m[i]);
    3495         int j;
    3496         for(j=0;j<=strat->sl;j++)
    3497         {
    3498           if (h==strat->S[j])
    3499           {
    3500             int new_pos=simple_posInS(strat, h,len, wlen);
    3501             if (strat->lenS)
    3502             {
    3503               strat->lenS[j]=len;
     3593          poly got=::gcd_of_terms(h,r);
     3594          p_Delete(&gcd_of_terms[i],r);
     3595          gcd_of_terms[i]=got;
     3596          int len=pLength(h);
     3597          wlen_type wlen=pQuality(h,this,len);
     3598          if (weighted_lengths)
     3599            weighted_lengths[i]=wlen;
     3600          lengths[i]=len;
     3601          assume(h==S->m[i]);
     3602          int j;
     3603          for(j=0;j<=strat->sl;j++)
     3604          {
     3605            if (h==strat->S[j])
     3606            {
     3607              int new_pos=simple_posInS(strat, h,len, wlen);
     3608              if (strat->lenS)
     3609              {
     3610                strat->lenS[j]=len;
     3611              }
     3612              if (strat->lenSw)
     3613              {
     3614                strat->lenSw[j]=wlen;
     3615              }
     3616              if (new_pos<j)
     3617              {
     3618                move_forward_in_S(j,new_pos,strat);
     3619              }
     3620              else
     3621              {
     3622                if (new_pos>j)
     3623                 new_pos=new_pos-1;//is identical with one element
     3624                if (new_pos>j)
     3625                  move_backward_in_S(j,new_pos,strat);
     3626              }
     3627              break;
    35043628            }
    3505             if (strat->lenSw)
    3506             {
    3507               strat->lenSw[j]=wlen;
    3508             }
    3509             if (new_pos<j)
    3510             {
    3511               move_forward_in_S(j,new_pos,strat);
    3512             }
    3513             else
    3514             {
    3515               if (new_pos>j)
    3516                 new_pos=new_pos-1;//is identical with one element
    3517               if (new_pos>j)
    3518                 move_backward_in_S(j,new_pos,strat);
    3519             }
    3520             break;
    35213629          }
    35223630        }
    3523       }
    35243631    }
    35253632  }
     
    35313638      {
    35323639        if (T_deg[i]+T_deg[j]<=upper)
    3533         {
     3640        {
    35343641          now_t_rep(i,j,this);
    35353642        }
     
    35403647  //TODO mark pairs
    35413648}
     3649
    35423650sorted_pair_node* top_pair(slimgb_alg* c)
    35433651{
     
    35563664    }
    35573665  }
     3666
    35583667  if(c->pair_top<0) return NULL;
    35593668  else return (c->apairs[c->pair_top]);
    35603669}
     3670
    35613671sorted_pair_node* quick_pop_pair(slimgb_alg* c)
    35623672{
     
    35753685  }
    35763686}
     3687
    35773688void clean_top_of_pair_list(slimgb_alg* c)
    35783689{
     
    35833694  }
    35843695}
     3696
    35853697static BOOLEAN state_is(calc_state state, const int & arg_i, const  int & arg_j, slimgb_alg* c)
    35863698{
     
    36063718  omfree(s);
    36073719}
     3720
    36083721static BOOLEAN pair_better(sorted_pair_node* a,sorted_pair_node* b, slimgb_alg* c)
    36093722{
     
    36323745  if (a->deg>b->deg) return 1;
    36333746
    3634   int comp=pLmCmp(a->lcm_of_lm, b->lcm_of_lm);
     3747 int comp=pLmCmp(a->lcm_of_lm, b->lcm_of_lm);
    36353748
    36363749  if (comp==1) return 1;
    36373750  if (-1==comp) return -1;
    3638   if (a->expected_length<b->expected_length) return -1;
     3751   if (a->expected_length<b->expected_length) return -1;
    36393752  if (a->expected_length>b->expected_length) return 1;
    36403753  if (a->i+a->j<b->i+b->j) return -1;
    3641   if (a->i+a->j>b->i+b->j) return 1;
     3754   if (a->i+a->j>b->i+b->j) return 1;
    36423755  if (a->i<b->i) return -1;
    3643   if (a->i>b->i) return 1;
     3756   if (a->i>b->i) return 1;
    36443757  return 0;
    36453758}
     
    36543767  for (i=pVariables; i; i--)
    36553768  {
    3656     pSetExp(m,i, pGetExp(p,i));
    3657     if (max_g_0==0)
    3658       if (pGetExp(m,i)>0)
    3659         max_g_0=i;
    3660   }
     3769      pSetExp(m,i, pGetExp(p,i));
     3770      if (max_g_0==0)
     3771  if (pGetExp(m,i)>0)
     3772    max_g_0=i;
     3773  }
     3774
    36613775  t=p->next;
    36623776  while (t!=NULL)
     
    36673781      pSetExp(m,i, si_min(pGetExp(t,i),pGetExp(m,i)));
    36683782      if (max_g_0==i)
    3669         if (pGetExp(m,i)==0)
    3670           max_g_0=0;
     3783  if (pGetExp(m,i)==0)
     3784    max_g_0=0;
    36713785      if ((max_g_0==0) && (pGetExp(m,i)>0))
    36723786      {
    3673         max_g_0=i;
     3787  max_g_0=i;
    36743788      }
    36753789    }
     
    36823796  return NULL;
    36833797}
     3798
    36843799static inline BOOLEAN pHasNotCFExtended(poly p1, poly p2, poly m)
    36853800{
     3801
    36863802  if (pGetComp(p1) > 0 || pGetComp(p2) > 0)
    36873803    return FALSE;
     
    36953811}
    36963812
    3697 
    36983813//for impl reasons may return false if the the normal product criterion matches
    36993814static inline BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, slimgb_alg* c)
     
    37023817    return FALSE;
    37033818  if(gcd1==NULL) return FALSE;
    3704   if(gcd2==NULL) return FALSE;
    3705   gcd1->next=gcd2; //may ordered incorrect
    3706   poly m=gcd_of_terms(gcd1,c->r);
    3707   gcd1->next=NULL;
    3708   if (m==NULL) return FALSE;
    3709 
    3710   BOOLEAN erg=pHasNotCFExtended(p1,p2,m);
    3711   pDelete(&m);
    3712   return erg;
    3713 }
     3819        if(gcd2==NULL) return FALSE;
     3820        gcd1->next=gcd2; //may ordered incorrect
     3821        poly m=gcd_of_terms(gcd1,c->r);
     3822        gcd1->next=NULL;
     3823        if (m==NULL) return FALSE;
     3824
     3825        BOOLEAN erg=pHasNotCFExtended(p1,p2,m);
     3826        pDelete(&m);
     3827        return erg;
     3828}
     3829
    37143830static poly kBucketGcd(kBucket* b, ring r)
    37153831{
     
    37243840      if (!initialized)
    37253841      {
    3726         m=gcd_of_terms(b->buckets[i],r);
    3727         initialized=TRUE;
    3728         if (m==NULL) return NULL;
     3842  m=gcd_of_terms(b->buckets[i],r);
     3843  initialized=TRUE;
     3844  if (m==NULL) return NULL;
    37293845      }
    37303846      else
    3731       {
    3732         n=gcd_of_terms(b->buckets[i],r);
    3733         if (n==NULL)
    3734         {
    3735           pDelete(&m);
    3736           return NULL;
    3737         }
    3738         n->next=m;
    3739         poly t=gcd_of_terms(n,r);
    3740         n->next=NULL;
    3741         pDelete(&m);
    3742         pDelete(&n);
    3743         m=t;
    3744         if (m==NULL) return NULL;
    3745       }
     3847  {
     3848    n=gcd_of_terms(b->buckets[i],r);
     3849    if (n==NULL) {
     3850      pDelete(&m);
     3851      return NULL;
     3852    }
     3853    n->next=m;
     3854    poly t=gcd_of_terms(n,r);
     3855    n->next=NULL;
     3856    pDelete(&m);
     3857    pDelete(&n);
     3858    m=t;
     3859    if (m==NULL) return NULL;
     3860
     3861  }
    37463862    }
    37473863  }
     
    37543870  return c->strat->lenS[pos];
    37553871}
     3872
    37563873#ifdef HAVE_PLURAL
    37573874static inline wlen_type quality_of_pos_in_strat_S_mult_high(int pos, poly high, slimgb_alg* c)
     
    37803897      int best=erg.to_reduce_u+1;
    37813898/*
    3782       for (i=erg.to_reduce_u;i>=erg.to_reduce_l;i--){
     3899      for (i=erg.to_reduce_u;i>=erg.to_reduce_l;i--)
     3900      {
    37833901  int qc=los[i].guess_quality(c);
    3784   if (qc<quality_a){
     3902  if (qc<quality_a)
     3903  {
    37853904    best=i;
    37863905    quality_a=qc;
    37873906  }
    37883907      }
    3789       if(best!=erg.to_reduce_u+1){
    3790 */
     3908      if(best!=erg.to_reduce_u+1)
     3909      {*/
    37913910      wlen_type qc;
    37923911      best=find_best(los,erg.to_reduce_l,erg.to_reduce_u,qc,c);
    37933912      if(qc<quality_a)
    37943913      {
    3795         los[best].flatten();
    3796         int b_pos=kBucketCanonicalize(los[best].bucket);
    3797         los[best].p=los[best].bucket->buckets[b_pos];
    3798         qc=pQuality(los[best].bucket->buckets[b_pos],c);
    3799         if(qc<quality_a)
    3800         {
    3801           red_object h=los[erg.to_reduce_u];
    3802           los[erg.to_reduce_u]=los[best];
    3803           los[best]=h;
    3804           swap_roles=TRUE;
    3805         }
    3806         else
    3807           swap_roles=FALSE;
     3914  los[best].flatten();
     3915  int b_pos=kBucketCanonicalize(los[best].bucket);
     3916  los[best].p=los[best].bucket->buckets[b_pos];
     3917  qc=pQuality(los[best].bucket->buckets[b_pos],c);
     3918  if(qc<quality_a)
     3919  {
     3920    red_object h=los[erg.to_reduce_u];
     3921    los[erg.to_reduce_u]=los[best];
     3922    los[best]=h;
     3923    swap_roles=TRUE;
     3924  }
     3925  else
     3926    swap_roles=FALSE;
    38083927      }
    38093928      else
    38103929      {
    3811         swap_roles=FALSE;
    3812       }
     3930  swap_roles=FALSE;
     3931      }
     3932    }
     3933      else
     3934    {
     3935      if (erg.to_reduce_u>erg.to_reduce_l)
     3936      {
     3937  int i;
     3938  wlen_type quality_a=quality_of_pos_in_strat_S(erg.reduce_by,c);
     3939  #ifdef HAVE_PLURAL
     3940  if ((c->nc) && (!(rIsSCA(c->r))))
     3941    quality_a=quality_of_pos_in_strat_S_mult_high(erg.reduce_by, los[erg.to_reduce_u].p, c);
     3942  #endif
     3943  int best=erg.to_reduce_u+1;
     3944  wlen_type qc;
     3945  best=find_best(los,erg.to_reduce_l,erg.to_reduce_u,qc,c);
     3946  assume(qc==los[best].guess_quality(c));
     3947  if(qc<quality_a)
     3948  {
     3949    los[best].flatten();
     3950    int b_pos=kBucketCanonicalize(los[best].bucket);
     3951    los[best].p=los[best].bucket->buckets[b_pos];
     3952    qc==pQuality(los[best].bucket->buckets[b_pos],c);
     3953    //(best!=erg.to_reduce_u+1)
     3954    if(qc<quality_a)
     3955    {
     3956    red_object h=los[erg.to_reduce_u];
     3957    los[erg.to_reduce_u]=los[best];
     3958    los[best]=h;
     3959    erg.reduce_by=erg.to_reduce_u;
     3960    erg.fromS=FALSE;
     3961    erg.to_reduce_u--;
     3962    }
     3963  }
     3964      }
     3965      else
     3966      {
     3967  assume(erg.to_reduce_u==erg.to_reduce_l);
     3968  wlen_type quality_a=
     3969        quality_of_pos_in_strat_S(erg.reduce_by,c);
     3970  wlen_type qc=los[erg.to_reduce_u].guess_quality(c);
     3971  if (qc<0) PrintS("Wrong wlen_type");
     3972  if(qc<quality_a)
     3973  {
     3974    int best=erg.to_reduce_u;
     3975    los[best].flatten();
     3976    int b_pos=kBucketCanonicalize(los[best].bucket);
     3977    los[best].p=los[best].bucket->buckets[b_pos];
     3978    qc=pQuality(los[best].bucket->buckets[b_pos],c);
     3979    assume(qc>=0);
     3980    if(qc<quality_a)
     3981    {
     3982      BOOLEAN exp=FALSE;
     3983      if(qc<=2)
     3984      {
     3985         //Print("\n qc is %lld \n",qc);
     3986         exp=TRUE;
     3987      }
     3988      else
     3989      {
     3990         if (qc<quality_a/2)
     3991          exp=TRUE;
     3992         else
     3993       if(erg.reduce_by<c->n/4)
     3994          exp=TRUE;
     3995      }
     3996      if (exp)
     3997      {
     3998        poly clear_into;
     3999        los[erg.to_reduce_u].flatten();
     4000        kBucketClear(los[erg.to_reduce_u].bucket,&clear_into,&erg.expand_length);
     4001        erg.expand=pCopy(clear_into);
     4002        kBucketInit(los[erg.to_reduce_u].bucket,clear_into,erg.expand_length);
     4003        if (TEST_OPT_PROT)
     4004    PrintS("e");
     4005      }
     4006    }
     4007  }
     4008      }
     4009
     4010      swap_roles=FALSE;
     4011      return;
     4012      }
     4013  }
     4014  else
     4015  {
     4016    if(erg.reduce_by>erg.to_reduce_u)
     4017    {
     4018      //then lm(rb)>= lm(tru) so =
     4019      assume(erg.reduce_by==erg.to_reduce_u+1);
     4020      int best=erg.reduce_by;
     4021      wlen_type quality_a=los[erg.reduce_by].guess_quality(c);
     4022      wlen_type qc;
     4023      best=find_best(los,erg.to_reduce_l,erg.to_reduce_u,qc,c);
     4024
     4025      int i;
     4026      if(qc<quality_a)
     4027      {
     4028    red_object h=los[erg.reduce_by];
     4029    los[erg.reduce_by]=los[best];
     4030    los[best]=h;
     4031  }
     4032  swap_roles=FALSE;
     4033  return;
    38134034    }
    38144035    else
    38154036    {
    3816       if (erg.to_reduce_u>erg.to_reduce_l)
    3817       {
    3818         int i;
    3819         wlen_type quality_a=quality_of_pos_in_strat_S(erg.reduce_by,c);
    3820 #ifdef HAVE_PLURAL
    3821         if ((c->nc) && (!(rIsSCA(c->r))))
    3822          quality_a=quality_of_pos_in_strat_S_mult_high(erg.reduce_by, los[erg.to_reduce_u].p, c);
     4037      assume(!pLmEqual(los[erg.reduce_by].p,los[erg.to_reduce_l].p));
     4038      assume(erg.to_reduce_u==erg.to_reduce_l);
     4039      //further assume, that reduce_by is the above all other polys
     4040      //with same leading term
     4041      int il=erg.reduce_by;
     4042      wlen_type quality_a =los[erg.reduce_by].guess_quality(c);
     4043      wlen_type qc;
     4044      while((il>0) && pLmEqual(los[il-1].p,los[il].p))
     4045      {
     4046  il--;
     4047  qc=los[il].guess_quality(c);
     4048  if (qc<quality_a)
     4049  {
     4050    quality_a=qc;
     4051    erg.reduce_by=il;
     4052  }
     4053      }
     4054      swap_roles=FALSE;
     4055    }
     4056  }
     4057  if(swap_roles)
     4058  {
     4059    if (TEST_OPT_PROT)
     4060      PrintS("b");
     4061    poly clear_into;
     4062    int dummy_len;
     4063    int new_length;
     4064    int bp=erg.to_reduce_u;//bucket_positon
     4065    //kBucketClear(los[bp].bucket,&clear_into,&new_length);
     4066    new_length=los[bp].clear_to_poly();
     4067    clear_into=los[bp].p;
     4068    poly p=c->strat->S[erg.reduce_by];
     4069    int j=erg.reduce_by;
     4070    int old_length=c->strat->lenS[j];// in view of S
     4071    los[bp].p=p;
     4072    if (c->eliminationProblem)
     4073    {
     4074        los[bp].sugar=c->pTotaldegree_full(p);
     4075    }
     4076    kBucketInit(los[bp].bucket,p,old_length);
     4077    wlen_type qal=pQuality(clear_into,c,new_length);
     4078    int pos_in_c=-1;
     4079    int z;
     4080    int new_pos;
     4081    new_pos=simple_posInS(c->strat,clear_into,new_length, qal);
     4082    assume(new_pos<=j);
     4083    for (z=c->n;z;z--)
     4084    {
     4085      if(p==c->S->m[z-1])
     4086      {
     4087  pos_in_c=z-1;
     4088  break;
     4089      }
     4090    }
     4091
     4092    int tdeg_full=-1;
     4093    int tdeg=-1;
     4094    if(pos_in_c>=0)
     4095    {
     4096      #ifdef TGB_RESORT_PAIRS
     4097      c->used_b=TRUE;
     4098      c->replaced[pos_in_c]=TRUE;
     4099      #endif
     4100      tdeg=c->T_deg[pos_in_c];
     4101      c->S->m[pos_in_c]=clear_into;
     4102      c->lengths[pos_in_c]=new_length;
     4103      c->weighted_lengths[pos_in_c]=qal;
     4104      if (c->gcd_of_terms[pos_in_c]==NULL)
     4105        c->gcd_of_terms[pos_in_c]=gcd_of_terms(clear_into,c->r);
     4106      if (c->T_deg_full)
     4107        tdeg_full=c->T_deg_full[pos_in_c]=c->pTotaldegree_full(clear_into);
     4108      else tdeg_full=tdeg;
     4109      c_S_element_changed_hook(pos_in_c,c);
     4110    }
     4111    else
     4112    {
     4113      if (c->eliminationProblem)
     4114      {
     4115        tdeg_full=c->pTotaldegree_full(clear_into);
     4116        tdeg=c->pTotaldegree(clear_into);
     4117      }
     4118    }
     4119    c->strat->S[j]=clear_into;
     4120    c->strat->lenS[j]=new_length;
     4121
     4122    assume(pLength(clear_into)==new_length);
     4123    if(c->strat->lenSw!=NULL)
     4124      c->strat->lenSw[j]=qal;
     4125    if (!rField_is_Zp(c->r))
     4126    {
     4127      p_Cleardenom(clear_into,c->r);//should be unnecessary
     4128      //p_Content(clear_into, c->r);
     4129    }
     4130    else
     4131      pNorm(clear_into);
     4132#ifdef FIND_DETERMINISTIC
     4133    erg.reduce_by=j;
     4134    //resort later see diploma thesis, find_in_S must be deterministic
     4135    //during multireduction if spolys are only in the span of the
     4136    //input polys
     4137#else
     4138    if (new_pos<j)
     4139    {
     4140      if (c->strat->honey) c->strat->ecartS[j]=tdeg_full-tdeg;
     4141      move_forward_in_S(j,new_pos,c->strat);
     4142      erg.reduce_by=new_pos;
     4143    }
    38234144#endif
    3824         int best=erg.to_reduce_u+1;
    3825         wlen_type qc;
    3826         best=find_best(los,erg.to_reduce_l,erg.to_reduce_u,qc,c);
    3827         assume(qc==los[best].guess_quality(c));
    3828         if(qc<quality_a)
    3829         {
    3830           los[best].flatten();
    3831           int b_pos=kBucketCanonicalize(los[best].bucket);
    3832           los[best].p=los[best].bucket->buckets[b_pos];
    3833           qc==pQuality(los[best].bucket->buckets[b_pos],c);
    3834           //(best!=erg.to_reduce_u+1)
    3835           if(qc<quality_a)
    3836           {
    3837             red_object h=los[erg.to_reduce_u];
    3838             los[erg.to_reduce_u]=los[best];
    3839             los[best]=h;
    3840             erg.reduce_by=erg.to_reduce_u;
    3841             erg.fromS=FALSE;
    3842             erg.to_reduce_u--;
    3843           }
    3844         }
    3845       }
    3846       else
    3847       {
    3848         assume(erg.to_reduce_u==erg.to_reduce_l);
    3849         wlen_type quality_a=
    3850           quality_of_pos_in_strat_S(erg.reduce_by,c);
    3851          wlen_type qc=los[erg.to_reduce_u].guess_quality(c);
    3852          if (qc<0) PrintS("Wrong wlen_type");
    3853          if(qc<quality_a)
    3854          {
    3855            int best=erg.to_reduce_u;
    3856            los[best].flatten();
    3857            int b_pos=kBucketCanonicalize(los[best].bucket);
    3858            los[best].p=los[best].bucket->buckets[b_pos];
    3859            qc=pQuality(los[best].bucket->buckets[b_pos],c);
    3860            assume(qc>=0);
    3861            if(qc<quality_a)
    3862            {
    3863              BOOLEAN exp=FALSE;
    3864              if(qc<=2)
    3865              {
    3866                //Print("\n qc is %lld \n",qc);
    3867                exp=TRUE;
    3868              }
    3869              else
    3870              {
    3871                if (qc<quality_a/2)
    3872                  exp=TRUE;
    3873                else
    3874                  if(erg.reduce_by<c->n/4)
    3875                    exp=TRUE;
    3876              }
    3877              if (exp)
    3878              {
    3879                poly clear_into;
    3880                los[erg.to_reduce_u].flatten();
    3881                kBucketClear(los[erg.to_reduce_u].bucket,&clear_into,&erg.expand_length);
    3882                erg.expand=pCopy(clear_into);
    3883                kBucketInit(los[erg.to_reduce_u].bucket,clear_into,erg.expand_length);
    3884                if (TEST_OPT_PROT) PrintS("e");
    3885              }
    3886            }
    3887          }
    3888        }
    3889        swap_roles=FALSE;
    3890        return;
    3891      }
    3892    }
    3893    else
    3894    {
    3895      if(erg.reduce_by>erg.to_reduce_u)
    3896      {
    3897        //then lm(rb)>= lm(tru) so =
    3898        assume(erg.reduce_by==erg.to_reduce_u+1);
    3899        int best=erg.reduce_by;
    3900        wlen_type quality_a=los[erg.reduce_by].guess_quality(c);
    3901        wlen_type qc;
    3902        best=find_best(los,erg.to_reduce_l,erg.to_reduce_u,qc,c);
    3903 
    3904        int i;
    3905        if(qc<quality_a)
    3906        {
    3907          red_object h=los[erg.reduce_by];
    3908          los[erg.reduce_by]=los[best];
    3909          los[best]=h;
    3910        }
    3911        swap_roles=FALSE;
    3912        return;
    3913      }
    3914      else
    3915      {
    3916        assume(!pLmEqual(los[erg.reduce_by].p,los[erg.to_reduce_l].p));
    3917        assume(erg.to_reduce_u==erg.to_reduce_l);
    3918        //further assume, that reduce_by is the above all other polys
    3919        //with same leading term
    3920        int il=erg.reduce_by;
    3921        wlen_type quality_a =los[erg.reduce_by].guess_quality(c);
    3922        wlen_type qc;
    3923        while((il>0) && pLmEqual(los[il-1].p,los[il].p))
    3924        {
    3925          il--;
    3926          qc=los[il].guess_quality(c);
    3927          if (qc<quality_a)
    3928          {
    3929            quality_a=qc;
    3930            erg.reduce_by=il;
    3931          }
    3932        }
    3933        swap_roles=FALSE;
    3934      }
    3935    }
    3936    if(swap_roles)
    3937    {
    3938      if (TEST_OPT_PROT) PrintS("b");
    3939      poly clear_into;
    3940      int dummy_len;
    3941      int new_length;
    3942      int bp=erg.to_reduce_u;//bucket_positon
    3943      //kBucketClear(los[bp].bucket,&clear_into,&new_length);
    3944      new_length=los[bp].clear_to_poly();
    3945      clear_into=los[bp].p;
    3946      poly p=c->strat->S[erg.reduce_by];
    3947      int j=erg.reduce_by;
    3948      int old_length=c->strat->lenS[j];// in view of S
    3949      los[bp].p=p;
    3950      if (c->eliminationProblem)
    3951      {
    3952         los[bp].sugar=c->pTotaldegree_full(p);
    3953      }
    3954      kBucketInit(los[bp].bucket,p,old_length);
    3955      wlen_type qal=pQuality(clear_into,c,new_length);
    3956      int pos_in_c=-1;
    3957      int z;
    3958      int new_pos;
    3959      new_pos=simple_posInS(c->strat,clear_into,new_length, qal);
    3960      assume(new_pos<=j);
    3961      for (z=c->n;z;z--)
    3962      {
    3963        if(p==c->S->m[z-1])
    3964        {
    3965          pos_in_c=z-1;
    3966          break;
    3967        }
    3968      }
    3969 
    3970      int tdeg_full=-1;
    3971      int tdeg=-1;
    3972      if(pos_in_c>=0)
    3973      {
    3974        #ifdef TGB_RESORT_PAIRS
    3975        c->used_b=TRUE;
    3976        c->replaced[pos_in_c]=TRUE;
    3977        #endif
    3978        tdeg=c->T_deg[pos_in_c];
    3979        c->S->m[pos_in_c]=clear_into;
    3980        c->lengths[pos_in_c]=new_length;
    3981        c->weighted_lengths[pos_in_c]=qal;
    3982        if (c->gcd_of_terms[pos_in_c]==NULL)
    3983          c->gcd_of_terms[pos_in_c]=gcd_of_terms(clear_into,c->r);
    3984        if (c->T_deg_full)
    3985          tdeg_full=c->T_deg_full[pos_in_c]=c->pTotaldegree_full(clear_into);
    3986        else tdeg_full=tdeg;
    3987        c_S_element_changed_hook(pos_in_c,c);
    3988      }
    3989      else
    3990      {
    3991        if (c->eliminationProblem)
    3992        {
    3993          tdeg_full=c->pTotaldegree_full(clear_into);
    3994          tdeg=c->pTotaldegree(clear_into);
    3995        }
    3996      }
    3997      c->strat->S[j]=clear_into;
    3998      c->strat->lenS[j]=new_length;
    3999 
    4000      assume(pLength(clear_into)==new_length);
    4001      if(c->strat->lenSw!=NULL)
    4002        c->strat->lenSw[j]=qal;
    4003      if (!rField_is_Zp(c->r))
    4004      {
    4005        p_Cleardenom(clear_into,c->r);//should be unnecessary
    4006        //p_Content(clear_into, c->r);
    4007      }
    4008      else
    4009        pNorm(clear_into);
    4010 #ifdef FIND_DETERMINISTIC
    4011      erg.reduce_by=j;
    4012      //resort later see diploma thesis, find_in_S must be deterministic
    4013      //during multireduction if spolys are only in the span of the
    4014      //input polys
    4015 #else
    4016      if (new_pos<j)
    4017      {
    4018        if (c->strat->honey) c->strat->ecartS[j]=tdeg_full-tdeg;
    4019        move_forward_in_S(j,new_pos,c->strat);
    4020        erg.reduce_by=new_pos;
    4021      }
    4022 #endif
    4023    }
    4024 }
    4025 static int fwbw(red_object* los, int i){
     4145  }
     4146}
     4147
     4148static int fwbw(red_object* los, int i)
     4149{
    40264150   int i2=i;
    40274151   int step=1;
     
    40474171   if ((!incr) &&(step==1)) break;
    40484172       }
    4049 
    4050 
    40514173     }
    40524174     else
    40534175     {
    4054 
    40554176       step=si_min(i-i2,step);
    40564177       if (step==0) break;
    40574178       i2+=step;
    4058        if(pLmEqual(los[i].p,los[i2].p)){
     4179       if(pLmEqual(los[i].p,los[i2].p))
     4180       {
    40594181   if(step==1) break;
    40604182   else
     
    40634185   }
    40644186       }
    4065 
    40664187     }
    40674188     if (incr)
     
    40734194       else
    40744195   step/=2;
    4075 
    40764196     }
    40774197   }
    40784198   return i2;
    40794199}
    4080 static void canonicalize_region(red_object* los, int l, int u,slimgb_alg* c){
     4200
     4201static void canonicalize_region(red_object* los, int l, int u,slimgb_alg* c)
     4202{
    40814203    assume(l<=u+1);
    40824204    int i;
    4083     for(i=l;i<=u;i++){
     4205    for(i=l;i<=u;i++)
     4206    {
    40844207        kBucketCanonicalize(los[i].bucket);
    40854208    }
    4086 
    4087 }
    4088 static void multi_reduction_find(red_object* los, int losl,slimgb_alg* c,int startf,find_erg & erg){
     4209}
     4210static void multi_reduction_find(red_object* los, int losl,slimgb_alg* c,int startf,find_erg & erg)
     4211{
    40894212  kStrategy strat=c->strat;
    40904213
     
    40944217
    40954218  int j;
    4096   while(i>=0){
     4219  while(i>=0)
     4220  {
    40974221    assume((i==losl-1)||(pLmCmp(los[i].p,los[i+1].p)<=0));
    40984222    assume(is_valid_ro(los[i]));
    40994223    assume((!(c->eliminationProblem))||(los[i].sugar>=c->pTotaldegree(los[i].p)));
    41004224    j=kFindDivisibleByInS_easy(strat,los[i]);
    4101     if(j>=0){
    4102 
     4225    if(j>=0)
     4226    {
    41034227      erg.to_reduce_u=i;
    41044228      erg.reduce_by=j;
     
    41094233      assume(i>=i2);
    41104234
    4111 
    41124235      erg.to_reduce_l=i2;
    41134236      assume((i==losl-1)||(pLmCmp(los[i].p,los[i+1].p)==-1));
     
    41154238      return;
    41164239    }
    4117     if (j<0){
    4118 
     4240    if (j<0)
     4241    {
    41194242      //not reduceable, try to use this for reducing higher terms
    41204243      int i2=fwbw(los,i);
     
    41224245      assume((i2==0)||(!pLmEqual(los[i2].p,los[i2-1].p)));
    41234246      assume(i>=i2);
    4124       if(i2!=i){
    4125 
    4126 
     4247      if(i2!=i)
     4248      {
    41274249  erg.to_reduce_u=i-1;
    41284250  erg.to_reduce_l=i2;
     
    41334255  return;
    41344256      }
    4135 
    41364257      i--;
    41374258    }
     
    41434264 //  nicht reduzierbare eintraege in ergebnisliste schreiben
    41444265//   nullen loeschen
    4145 //   while(finde_groessten leitterm reduzierbar(c,erg)){
     4266//   while(finde_groessten leitterm reduzierbar(c,erg))
     4267//   {
    41464268
    41474269static int multi_reduction_clear_zeroes(red_object* los, int  losl, int l, int u)
    41484270{
    4149 
    4150 
    41514271  int deleted=0;
    41524272  int  i=l;
     
    41544274  while(i<=u)
    41554275  {
    4156 
    4157     if(los[i].p==NULL){
     4276    if(los[i].p==NULL)
     4277    {
    41584278      kBucketDestroy(&los[i].bucket);
    41594279//      delete los[i];//here we assume los are constructed with new
     
    41714291      memmove(los+(int)(last+1-deleted),los+last+1,sizeof(red_object)*(losl-1-last));
    41724292  return deleted;
    4173 
    4174 }
    4175 int search_red_object_pos(red_object* a, int top, red_object* key ){
    4176 
     4293}
     4294
     4295int search_red_object_pos(red_object* a, int top, red_object* key )
     4296{
    41774297    int an = 0;
    41784298    int en= top;
     
    41954315        an=i;
    41964316    }
    4197 
    4198 }
     4317}
     4318
    41994319static void sort_region_down(red_object* los, int l, int u, slimgb_alg* c)
    42004320{
     
    42054325  int bound=0;
    42064326  BOOLEAN at_end=FALSE;
    4207   for(i=l;i<=u;i++){
    4208     if (!(at_end)){
     4327  for(i=l;i<=u;i++)
     4328  {
     4329    if (!(at_end))
     4330    {
    42094331      bound=new_indices[i-l]=bound+search_red_object_pos(los+bound,l-bound-1,los+i);
    42104332      if (bound==l) at_end=TRUE;
    42114333    }
    4212     else{
     4334    else
     4335    {
    42134336      new_indices[i-l]=l;
    42144337    }
    42154338  }
    42164339  red_object* los_region=(red_object*) omalloc(sizeof(red_object)*(u-l+1));
    4217   for (int i=0;i<r_size;i++){
     4340  for (int i=0;i<r_size;i++)
     4341  {
    42184342    new_indices[i]+=i;
    42194343    los_region[i]=los[l+i];
    42204344    assume((i==0)||(new_indices[i]>new_indices[i-1]));
    4221 
    42224345  }
    42234346
     
    42254348  int j=u;
    42264349  int j2=l-1;
    4227   while(i>=0){
    4228     if (new_indices[i]==j){
     4350  while(i>=0)
     4351  {
     4352    if (new_indices[i]==j)
     4353    {
    42294354      los[j]=los_region[i];
    42304355      i--;
    42314356      j--;
    4232     } else{
     4357    }
     4358    else
     4359    {
    42334360      assume(new_indices[i]<j);
    42344361      los[j]=los[j2];
     
    42394366  }
    42404367  omfree(los_region);
    4241 
    42424368  omfree(new_indices);
    4243 
    42444369}
    42454370
     
    42554380  wlen_type max_initial_quality=0;
    42564381
    4257   for(i=0;i<losl;i++){
     4382  for(i=0;i<losl;i++)
     4383  {
    42584384    los[i].sev=pGetShortExpVector(los[i].p);
    42594385//SetShortExpVector();
     
    42694395  int curr_pos=losl-1;
    42704396
    4271 
    42724397//  nicht reduzierbare eintrᅵe in ergebnisliste schreiben
    42734398  // nullen loeschen
    4274   while(curr_pos>=0){
    4275     if ((c->use_noro_last_block)&&(lies_in_last_dp_block(los[curr_pos].p,c))){
     4399  while(curr_pos>=0)
     4400  {
     4401    if ((c->use_noro_last_block)&&(lies_in_last_dp_block(los[curr_pos].p,c)))
     4402    {
    42764403        int pn_noro=curr_pos+1;
    42774404        poly* p_noro=(poly*) omalloc(pn_noro*sizeof(poly));
    4278         for(i=0;i<pn_noro;i++){
     4405        for(i=0;i<pn_noro;i++)
     4406        {
    42794407            int dummy_len;
    42804408            poly p;
     
    42834411            p_noro[i]=p;
    42844412        }
    4285 
    4286 
    4287         if (npPrimeM<255){
     4413        if (npPrimeM<255)
     4414        {
    42884415          noro_step<tgb_uint8>(p_noro,pn_noro,c);
    4289         } else {
    4290           if (npPrimeM<65000){
     4416        }
     4417        else
     4418        {
     4419          if (npPrimeM<65000)
     4420          {
    42914421            noro_step<tgb_uint16>(p_noro,pn_noro,c);
    4292           } else{
     4422          }
     4423          else
     4424          {
    42934425            noro_step<tgb_uint32>(p_noro,pn_noro,c);
    42944426          }
    42954427        }
    4296         for(i=0;i<pn_noro;i++){
     4428        for(i=0;i<pn_noro;i++)
     4429        {
    42974430            los[i].p=p_noro[i];
    42984431            los[i].sev=pGetShortExpVector(los[i].p);
    42994432            //ignore quality
    43004433            kBucketInit(los[i].bucket,los[i].p,pLength(los[i].p));
    4301 
    43024434        }
    43034435        qsort(los,pn_noro,sizeof(red_object),red_object_better_gen);
     
    43124444    if(erg.reduce_by<0) break;
    43134445
    4314 
    4315 
    43164446    erg.expand=NULL;
    43174447    int d=erg.to_reduce_u-erg.to_reduce_l+1;
    43184448
    4319 
    43204449    multi_reduction_lls_trick(los,losl,c,erg);
    4321 
    43224450
    43234451    int i;
     
    43364464         //
    43374465         assume(los[i].initial_quality>0);
    4338 
    43394466               if(los[i].guess_quality(c)
    4340                   >1.5*delay_factor*max_initial_quality){
     4467                  >1.5*delay_factor*max_initial_quality)
     4468                  {
    43414469                       if (TEST_OPT_PROT)
    43424470                           PrintS("v");
    43434471                       los[i].canonicalize();
    43444472                       if(los[i].guess_quality(c)
    4345                            >delay_factor*max_initial_quality){
     4473                           >delay_factor*max_initial_quality)
     4474                           {
    43464475                               if (TEST_OPT_PROT)
    43474476                                   PrintS(".");
     
    43504479                               delay[delay_s]=los[i].p;
    43514480                               delay_s++;
    4352 
    43534481                               los[i].p=NULL;
    4354 
    43554482                      }
    43564483                  }
    4357 
    43584484            }
    43594485     }
     
    43724498    else
    43734499    sort_region_down(los, erg.to_reduce_l, erg.to_reduce_u-deleted, c);
    4374 
    43754500
    43764501    if(erg.expand)
     
    43844509#else
    43854510      int ecart=0;
    4386       if (c->eliminationProblem){
     4511      if (c->eliminationProblem)
     4512      {
    43874513        ecart=c->pTotaldegree_full(erg.expand)-c->pTotaldegree(erg.expand);
    43884514      }
     
    43904516#endif
    43914517    }
    4392 
    4393   }
    4394 
     4518  }
    43954519
    43964520  //sorted_pair_node** pairs=(sorted_pair_node**)
     
    43984522  c->introduceDelayedPairs(delay,delay_s);
    43994523  /*
    4400   for(i=0;i<delay_s;i++){
    4401 
     4524  for(i=0;i<delay_s;i++)
     4525  {
    44024526      poly p=delay[i];
    44034527      //if (rPar(c->r)==0)
     
    44064530      si->i=-1;
    44074531      si->j=-1;
    4408        if (!rField_is_Zp(c->r)){
     4532       if (!rField_is_Zp(c->r))
     4533       {
    44094534        if (!c->nc)
    44104535            p=redTailShort(p, c->strat);
     
    44144539      si->expected_length=pQuality(p,c,pLength(p));
    44154540      si->deg=pTotaldegree(p);
    4416 
    44174541      si->lcm_of_lm=p;
    44184542      pairs[i]=si;
     
    44254549  return;
    44264550}
    4427 void red_object::flatten(){
     4551
     4552void red_object::flatten()
     4553{
    44284554  assume(p==kBucketGetLm(bucket));
    44294555}
    4430 void red_object::validate(){
     4556
     4557void red_object::validate()
     4558{
    44314559  p=kBucketGetLm(bucket);
    44324560  if(p)
    44334561    sev=pGetShortExpVector(p);
    44344562}
    4435 int red_object::clear_to_poly(){
     4563
     4564int red_object::clear_to_poly()
     4565{
    44364566  flatten();
    44374567  int l;
     
    44404570}
    44414571
    4442 
    4443 
    4444 
    4445 
    44464572void reduction_step::reduce(red_object* r, int l, int u){}
     4573
    44474574void simple_reducer::do_reduce(red_object & ro)
    44484575{
     
    44594586}
    44604587
    4461 
    4462 void simple_reducer::reduce(red_object* r, int l, int u){
     4588void simple_reducer::reduce(red_object* r, int l, int u)
     4589{
    44634590  this->pre_reduce(r,l,u);
    44644591  int i;
     
    44664593  int im;
    44674594
    4468 
    4469   if(c->eliminationProblem){
     4595  if(c->eliminationProblem)
     4596  {
    44704597    assume(p_LmEqual(r[l].p,r[u].p,c->r));
    44714598    /*int lm_deg=pTotaldegree(r[l].p);
     
    44734600  }
    44744601
    4475   for(i=l;i<=u;i++){
    4476 
    4477 
    4478 
     4602  for(i=l;i<=u;i++)
     4603  {
    44794604    this->do_reduce(r[i]);
    4480     if (c->eliminationProblem){
     4605    if (c->eliminationProblem)
     4606    {
    44814607        r[i].sugar=si_max(r[i].sugar,reducer_deg);
    44824608    }
    44834609  }
    4484   for(i=l;i<=u;i++){
    4485 
     4610  for(i=l;i<=u;i++)
     4611  {
    44864612    kBucketSimpleContent(r[i].bucket);
    44874613    r[i].validate();
     
    44904616  }
    44914617}
     4618
    44924619reduction_step::~reduction_step(){}
    4493 simple_reducer::~simple_reducer(){
     4620
     4621simple_reducer::~simple_reducer()
     4622{
    44944623  if(fill_back!=NULL)
    44954624  {
     
    44974626  }
    44984627  fill_back=NULL;
    4499 
    4500 }
    4501 
    4502 void multi_reduce_step(find_erg & erg, red_object* r, slimgb_alg* c){
     4628}
     4629
     4630void multi_reduce_step(find_erg & erg, red_object* r, slimgb_alg* c)
     4631{
    45034632  static int id=0;
    45044633  id++;
     
    45104639  simple_reducer* pointer;
    45114640  BOOLEAN work_on_copy=FALSE;
    4512   if(erg.fromS){
     4641  if(erg.fromS)
     4642  {
    45134643    red=c->strat->S[rn];
    45144644    red_len=c->strat->lenS[rn];
     
    45394669    red_len=pLength(red);
    45404670  }
    4541   if (((TEST_V_MODPSOLVSB)&&(red_len>1))||((c->nc)||(erg.to_reduce_u-erg.to_reduce_l>5))){
     4671  if (((TEST_V_MODPSOLVSB)&&(red_len>1))||((c->nc)||(erg.to_reduce_u-erg.to_reduce_l>5)))
     4672  {
    45424673    work_on_copy=TRUE;
    45434674    // poly m=pOne();
     
    45554686    #endif
    45564687      red_cp=ppMult_mm(red,m);
    4557     if(!erg.fromS){
     4688    if(!erg.fromS)
     4689    {
    45584690      kBucketInit(r[rn].bucket,red,red_len);
    45594691    }
     
    45724704    red_len=pLength(red);
    45734705    // pDelete(&m);
    4574 
    45754706  }
    45764707  int i;
    45774708
    4578 
    4579 
    45804709  assume(red_len==pLength(red));
    45814710
    45824711  int reducer_deg=0;
    4583   if (c->eliminationProblem){
     4712  if (c->eliminationProblem)
     4713  {
    45844714     int lm_deg=c->pTotaldegree(r[erg.to_reduce_l].p);
    45854715     int ecart;
    4586      if (erg.fromS){
     4716     if (erg.fromS)
     4717     {
    45874718       ecart=c->strat->ecartS[erg.reduce_by];
    4588      } else {
     4719     }
     4720     else
     4721     {
    45894722       ecart=c->pTotaldegree_full(red)-lm_deg;
    45904723     }
     
    46034736  if(work_on_copy) pDelete(&pointer->p);
    46044737  delete pointer;
    4605   if (lt_changed){
     4738  if (lt_changed)
     4739  {
    46064740    assume(!erg.fromS);
    46074741    r[erg.reduce_by].sev=sev;
    46084742  }
    4609 
    4610 };
    4611 
    4612 
    4613 
     4743}
    46144744
    46154745void simple_reducer:: pre_reduce(red_object* r, int l, int u){}
Note: See TracChangeset for help on using the changeset viewer.