Changeset e40da9f in git for kernel/GBEngine


Ignore:
Timestamp:
Aug 10, 2016, 12:36:45 PM (8 years ago)
Author:
Adi Popescu <adi_popescum@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
cc94f7e8ad1f5795a4149ec66525d5a5a3dfd6c2
Parents:
ef27298cfb747d136e3418af99edf58c03b12a05
Message:
trying to fix Christian sba algorithm
Location:
kernel/GBEngine
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/GBEngine/kspoly.cc

    ref2729 re40da9f  
    175175 *
    176176 ***************************************************************/
     177 
    177178int ksReducePolySig(LObject* PR,
    178179                 TObject* PW,
     
    182183                 kStrategy strat)
    183184{
    184 #ifdef ADIDEBUG
    185 printf("\nksReducePolySig\n");
    186 pWrite(PR->p);pWrite(PR->sig);
    187 pWrite(PW->p);pWrite(PW->sig);
    188 #endif
    189185#ifdef KDEBUG
    190186  red_count++;
     
    242238#endif
    243239    p_ExpVectorAddSub(sigMult,PR->GetLmCurrRing(),PW->GetLmCurrRing(),currRing);
     240//#if 1
     241#ifdef DEBUGF5
     242    printf("------------------- IN KSREDUCEPOLYSIG: --------------------\n");
     243    pWrite(pHead(f1));
     244    pWrite(pHead(f2));
     245    pWrite(sigMult);
     246    pWrite(PR->sig);
     247    printf("--------------\n");
     248#endif
     249    int sigSafe = p_LmCmp(PR->sig,sigMult,currRing);
     250    // now we can delete the copied polynomial data used for checking for
     251    // sig-safeness of the reduction step
     252//#if 1
     253#ifdef DEBUGF5
     254    printf("%d -- %d sig\n",sigSafe,PW->is_sigsafe);
     255
     256#endif
     257    //pDelete(&f1);
     258    pDelete(&sigMult);
     259    // go on with the computations only if the signature of p2 is greater than the
     260    // signature of fm*p1
     261    if(sigSafe != 1)
     262    {
     263      PR->is_redundant = TRUE;
     264      return 3;
     265    }
     266    //PW->is_sigsafe  = TRUE;
     267  }
     268  PR->is_redundant = FALSE;
     269  poly p1 = PR->GetLmTailRing();   // p2 | p1
     270  poly p2 = PW->GetLmTailRing();   // i.e. will reduce p1 with p2; lm = LT(p1) / LM(p2)
     271  poly t2 = pNext(p2), lm = p1;    // t2 = p2 - LT(p2); really compute P = LC(p2)*p1 - LT(p1)/LM(p2)*p2
     272  assume(p1 != NULL && p2 != NULL);// Attention, we have rings and there LC(p2) and LC(p1) are special
     273  p_CheckPolyRing(p1, tailRing);
     274  p_CheckPolyRing(p2, tailRing);
     275
     276  pAssume1(p2 != NULL && p1 != NULL &&
     277      p_DivisibleBy(p2,  p1, tailRing));
     278
     279  pAssume1(p_GetComp(p1, tailRing) == p_GetComp(p2, tailRing) ||
     280      (p_GetComp(p2, tailRing) == 0 &&
     281       p_MaxComp(pNext(p2),tailRing) == 0));
     282
     283#ifdef HAVE_PLURAL
     284  if (rIsPluralRing(currRing))
     285  {
     286    // for the time being: we know currRing==strat->tailRing
     287    // no exp-bound checking needed
     288    // (only needed if exp-bound(tailring)<exp-b(currRing))
     289    if (PR->bucket!=NULL)  nc_kBucketPolyRed(PR->bucket, p2,coef);
     290    else
     291    {
     292      poly _p = (PR->t_p != NULL ? PR->t_p : PR->p);
     293      assume(_p != NULL);
     294      nc_PolyPolyRed(_p, p2, coef, currRing);
     295      if (PR->t_p!=NULL) PR->t_p=_p; else PR->p=_p;
     296      PR->pLength=0; // usaully not used, GetpLength re-comoutes it if needed
     297    }
     298    return 0;
     299  }
     300#endif
     301
     302  if (t2==NULL)           // Divisor is just one term, therefore it will
     303  {                       // just cancel the leading term
     304    PR->LmDeleteAndIter();
     305    if (coef != NULL) *coef = n_Init(1, tailRing);
     306    return 0;
     307  }
     308
     309  p_ExpVectorSub(lm, p2, tailRing); // Calculate the Monomial we must multiply to p2
     310
     311  if (tailRing != currRing)
     312  {
     313    // check that reduction does not violate exp bound
     314    while (PW->max != NULL && !p_LmExpVectorAddIsOk(lm, PW->max, tailRing))
     315    {
     316      // undo changes of lm
     317      p_ExpVectorAdd(lm, p2, tailRing);
     318      if (strat == NULL) return 2;
     319      if (! kStratChangeTailRing(strat, PR, PW)) return -1;
     320      tailRing = strat->tailRing;
     321      p1 = PR->GetLmTailRing();
     322      p2 = PW->GetLmTailRing();
     323      t2 = pNext(p2);
     324      lm = p1;
     325      p_ExpVectorSub(lm, p2, tailRing);
     326      ret = 1;
     327    }
     328  }
     329
     330  // take care of coef buisness
     331  if (! n_IsOne(pGetCoeff(p2), tailRing))
     332  {
     333    number bn = pGetCoeff(lm);
     334    number an = pGetCoeff(p2);
     335    int ct = ksCheckCoeff(&an, &bn, tailRing->cf);    // Calculate special LC
     336    p_SetCoeff(lm, bn, tailRing);
     337    if ((ct == 0) || (ct == 2))
     338      PR->Tail_Mult_nn(an);
     339    if (coef != NULL) *coef = an;
     340    else n_Delete(&an, tailRing);
     341  }
     342  else
     343  {
     344    if (coef != NULL) *coef = n_Init(1, tailRing);
     345  }
     346
     347
     348  // and finally,
     349  PR->Tail_Minus_mm_Mult_qq(lm, t2, PW->GetpLength() - 1, spNoether);
     350  assume(PW->GetpLength() == pLength(PW->p != NULL ? PW->p : PW->t_p));
     351  PR->LmDeleteAndIter();
     352
     353  // the following is commented out: shrinking
     354#ifdef HAVE_SHIFTBBA_NONEXISTENT
     355  if ( (currRing->isLPring) && (!strat->homog) )
     356  {
     357    // assume? h->p in currRing
     358    PR->GetP();
     359    poly qq = p_Shrink(PR->p, currRing->isLPring, currRing);
     360    PR->Clear(); // does the right things
     361    PR->p = qq;
     362    PR->t_p = NULL;
     363    PR->SetShortExpVector();
     364  }
     365#endif
     366
     367#if defined(KDEBUG) && defined(TEST_OPT_DEBUG_RED)
     368  if (TEST_OPT_DEBUG)
     369  {
     370    Print(" to: "); PR->wrp(); Print("\n");
     371  }
     372#endif
     373  return ret;
     374}
     375 
     376int ksReducePolySigRing(LObject* PR,
     377                 TObject* PW,
     378                 long /*idx*/,
     379                 poly spNoether,
     380                 number *coef,
     381                 kStrategy strat)
     382{
     383#ifdef ADIDEBUG
     384printf("\nksReducePolySig\n");
     385pWrite(PR->p);pWrite(PR->sig);
     386pWrite(PW->p);pWrite(PW->sig);
     387#endif
     388#ifdef KDEBUG
     389  red_count++;
     390#ifdef TEST_OPT_DEBUG_RED
     391  if (TEST_OPT_DEBUG)
     392  {
     393    Print("Red %d:", red_count); PR->wrp(); Print(" with:");
     394    PW->wrp();
     395  }
     396#endif
     397#endif
     398  int ret = 0;
     399  ring tailRing = PR->tailRing;
     400  kTest_L(PR);
     401  kTest_T(PW);
     402
     403  // signature-based stuff:
     404  // checking for sig-safeness first
     405  // NOTE: This has to be done in the current ring
     406  //
     407  /**********************************************
     408   *
     409   * TODO:
     410   * --------------------------------------------
     411   * if strat->sbaOrder == 1
     412   * Since we are subdividing lower index and
     413   * current index reductions it is enough to
     414   * look at the polynomial part of the signature
     415   * for a check. This should speed-up checking
     416   * a lot!
     417   * if !strat->sbaOrder == 0
     418   * We are not subdividing lower and current index
     419   * due to the fact that we are using the induced
     420   * Schreyer order
     421   *
     422   * nevertheless, this different behaviour is
     423   * taken care of by is_sigsafe
     424   * => one reduction procedure can be used for
     425   * both, the incremental and the non-incremental
     426   * attempt!
     427   * --------------------------------------------
     428   *
     429   *********************************************/
     430  //printf("COMPARE IDX: %ld -- %ld\n",idx,strat->currIdx);
     431  if (!PW->is_sigsafe)
     432  {
     433    poly sigMult = pCopy(PW->sig);   // copy signature of reducer
     434//#if 1
     435#ifdef DEBUGF5
     436    printf("IN KSREDUCEPOLYSIG: \n");
     437    pWrite(pHead(f1));
     438    pWrite(pHead(f2));
     439    pWrite(sigMult);
     440    printf("--------------\n");
     441#endif
     442    p_ExpVectorAddSub(sigMult,PR->GetLmCurrRing(),PW->GetLmCurrRing(),currRing);
    244443    //I have also to set the leading coeficient for sigMult (in the case of rings)
    245444    if(rField_is_Ring(currRing))
  • kernel/GBEngine/kstd1.cc

    ref2729 re40da9f  
    15391539  // for sig-safe reductions in signature-based
    15401540  // standard basis computations
    1541   strat->red          = redSig;
     1541  if(rField_is_Ring(currRing))
     1542    strat->red = redSigRing;
     1543  else
     1544    strat->red        = redSig;
    15421545  //strat->sbaOrder  = 1;
    15431546  strat->currIdx      = 1;
     
    25202523      else
    25212524      {
     2525        strat->sigdrop = FALSE;
    25222526        if (w!=NULL)
    25232527          r=sba(F,Q,*w,hilb,strat);
     
    25442548  {
    25452549    //--------------------------RING CASE-------------------------
     2550    assume(sbaOrder == 1);
     2551    assume(arri == 0);
    25462552    if(idIs0(F))
    25472553      return idInit(1,F->rank);
  • kernel/GBEngine/kstd2.cc

    ref2729 re40da9f  
    668668  pWrite(Red->GetLmCurrRing());
    669669  */
    670   ret = ksReducePolySig(Red, PW, 1, NULL, &coef, strat);
     670  if(rField_is_Ring(currRing))
     671    ret = ksReducePolySigRing(Red, PW, 1, NULL, &coef, strat);
     672  else
     673    ret = ksReducePolySig(Red, PW, 1, NULL, &coef, strat);
    671674  if (!ret)
    672675  {
     
    691694*  signatures
    692695*/
     696
    693697int redSig (LObject* h,kStrategy strat)
     698{
     699  if (strat->tl<0) return 1;
     700  //if (h->GetLmTailRing()==NULL) return 0; // HS: SHOULD NOT BE NEEDED!
     701  //printf("FDEGS: %ld -- %ld\n",h->FDeg, h->pFDeg());
     702  assume(h->FDeg == h->pFDeg());
     703//#if 1
     704#ifdef DEBUGF5
     705  Print("------- IN REDSIG -------\n");
     706  Print("p: ");
     707  pWrite(pHead(h->p));
     708  Print("p1: ");
     709  pWrite(pHead(h->p1));
     710  Print("p2: ");
     711  pWrite(pHead(h->p2));
     712  Print("---------------------------\n");
     713#endif
     714  poly h_p;
     715  int i,j,at,pass, ii;
     716  int start=0;
     717  int sigSafe;
     718  unsigned long not_sev;
     719  // long reddeg,d;
     720
     721  pass = j = 0;
     722  // d = reddeg = h->GetpFDeg();
     723  h->SetShortExpVector();
     724  int li;
     725  h_p = h->GetLmTailRing();
     726  not_sev = ~ h->sev;
     727  loop
     728  {
     729    j = kFindDivisibleByInT(strat, h, start);
     730    if (j < 0)
     731    {
     732      return 1;
     733    }
     734
     735    li = strat->T[j].pLength;
     736    ii = j;
     737    /*
     738     * the polynomial to reduce with (up to the moment) is;
     739     * pi with length li
     740     */
     741    i = j;
     742#if 1
     743    if (TEST_OPT_LENGTH)
     744    loop
     745    {
     746      /*- search the shortest possible with respect to length -*/
     747      i++;
     748      if (i > strat->tl)
     749        break;
     750      if (li<=1)
     751        break;
     752      if ((strat->T[i].pLength < li)
     753         &&
     754          p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
     755                               h_p, not_sev, strat->tailRing))
     756      {
     757        /*
     758         * the polynomial to reduce with is now;
     759         */
     760        li = strat->T[i].pLength;
     761        ii = i;
     762      }
     763    }
     764    start = ii+1;
     765#endif
     766
     767    /*
     768     * end of search: have to reduce with pi
     769     */
     770#ifdef KDEBUG
     771    if (TEST_OPT_DEBUG)
     772    {
     773      PrintS("red:");
     774      h->wrp();
     775      PrintS(" with ");
     776      strat->T[ii].wrp();
     777    }
     778#endif
     779    assume(strat->fromT == FALSE);
     780//#if 1
     781#ifdef DEBUGF5
     782    Print("BEFORE REDUCTION WITH %d:\n",ii);
     783    Print("--------------------------------\n");
     784    pWrite(h->sig);
     785    pWrite(strat->T[ii].sig);
     786    pWrite(h->GetLmCurrRing());
     787    pWrite(pHead(h->p1));
     788    pWrite(pHead(h->p2));
     789    pWrite(pHead(strat->T[ii].p));
     790    Print("--------------------------------\n");
     791    printf("INDEX OF REDUCER T: %d\n",ii);
     792#endif
     793    sigSafe = ksReducePolySig(h, &(strat->T[ii]), strat->S_2_R[ii], NULL, NULL, strat);
     794#if SBA_PRINT_REDUCTION_STEPS
     795    if (sigSafe != 3)
     796      sba_reduction_steps++;
     797#endif
     798#if SBA_PRINT_OPERATIONS
     799    if (sigSafe != 3)
     800      sba_operations  +=  pLength(strat->T[ii].p);
     801#endif
     802    // if reduction has taken place, i.e. the reduction was sig-safe
     803    // otherwise start is already at the next position and the loop
     804    // searching reducers in T goes on from index start
     805//#if 1
     806#ifdef DEBUGF5
     807    Print("SigSAFE: %d\n",sigSafe);
     808#endif
     809    if (sigSafe != 3)
     810    {
     811      // start the next search for reducers in T from the beginning
     812      start = 0;
     813#ifdef KDEBUG
     814      if (TEST_OPT_DEBUG)
     815      {
     816        PrintS("\nto ");
     817        h->wrp();
     818        PrintLn();
     819      }
     820#endif
     821
     822      h_p = h->GetLmTailRing();
     823      if (h_p == NULL)
     824      {
     825        if (h->lcm!=NULL) pLmFree(h->lcm);
     826#ifdef KDEBUG
     827        h->lcm=NULL;
     828#endif
     829        return 0;
     830      }
     831      h->SetShortExpVector();
     832      not_sev = ~ h->sev;
     833      /*
     834      * try to reduce the s-polynomial h
     835      *test first whether h should go to the lazyset L
     836      *-if the degree jumps
     837      *-if the number of pre-defined reductions jumps
     838      */
     839      pass++;
     840      if (!TEST_OPT_REDTHROUGH && (strat->Ll >= 0) && (pass > strat->LazyPass))
     841      {
     842        h->SetLmCurrRing();
     843        at = strat->posInL(strat->L,strat->Ll,h,strat);
     844        if (at <= strat->Ll)
     845        {
     846          int dummy=strat->sl;
     847          if (kFindDivisibleByInS(strat, &dummy, h) < 0)
     848          {
     849            return 1;
     850          }
     851          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
     852#ifdef KDEBUG
     853          if (TEST_OPT_DEBUG)
     854            Print(" lazy: -> L%d\n",at);
     855#endif
     856          h->Clear();
     857          return -1;
     858        }
     859      }
     860    }
     861  }
     862}
     863
     864
     865int redSigRing (LObject* h,kStrategy strat)
    694866{
    695867  //Since reduce is really bad for SBA we use the following idea:
    696868  // We first check if we can build a gcd pair between h and S
    697869  //where the sig remains the same and replace h by this gcd poly
     870  assume(rField_is_Ring(currRing));
    698871  #if GCD_SBA
    699872  #ifdef ADIDEBUG
    700873  printf("\nBefore sbaCheckGcdPair ");pWrite(h->p);
    701874  #endif
    702   //sbaCheckGcdPair(h,strat);
    703875  while(sbaCheckGcdPair(h,strat))
    704876  {
     
    713885  #endif
    714886  poly beforeredsig;
    715   if(rField_is_Ring(currRing))
    716     beforeredsig = pCopy(h->sig);
     887  beforeredsig = pCopy(h->sig);
    717888   
    718889  if (strat->tl<0) return 1;
     
    758929      printf("\nBefore sbaCheckGcdPair ");pWrite(h->p);
    759930      #endif
    760       //sbaCheckGcdPair(h,strat);
    761931      while(sbaCheckGcdPair(h,strat))
    762932      {
     
    788958          return 0;
    789959        }
    790         if(rField_is_Ring(currRing))
    791         {
    792           //Check for sigdrop after reduction
    793           if(pLtCmp(beforeredsig,h->sig) == 1)
     960        //Check for sigdrop after reduction
     961        if(pLtCmp(beforeredsig,h->sig) == 1)
     962        {
     963          #ifdef ADIDEBUG
     964          printf("\nSigDrop after reduce\n");pWrite(beforeredsig);pWrite(h->sig);
     965          #endif
     966          strat->sigdrop = TRUE;
     967          //Reduce it as much as you can
     968          int red_result = redRing(h,strat);
     969          if(red_result == 0)
     970          {
     971            //It reduced to 0, cancel the sigdrop
     972            #ifdef ADIDEBUG
     973            printf("\nReduced to 0 via redRing. Cancel sigdrop\n");
     974            #endif
     975            strat->sigdrop = FALSE;
     976            p_Delete(&h->sig,currRing);h->sig = NULL;
     977            return 0;
     978          }
     979          else
    794980          {
    795981            #ifdef ADIDEBUG
    796             printf("\nSigDrop after reduce\n");pWrite(beforeredsig);pWrite(h->sig);
     982            printf("\nReduced to this via redRing.SIGDROP\n");pWrite(h->p);
    797983            #endif
    798             strat->sigdrop = TRUE;
    799             //Reduce it as much as you can
    800             int red_result = redRing(h,strat);
    801             if(red_result == 0)
    802             {
    803               //It reduced to 0, cancel the sigdrop
    804               #ifdef ADIDEBUG
    805               printf("\nReduced to 0 via redRing. Cancel sigdrop\n");
    806               #endif
    807               strat->sigdrop = FALSE;
    808               p_Delete(&h->sig,currRing);h->sig = NULL;
    809               return 0;
    810             }
    811             else
    812             {
    813               #ifdef ADIDEBUG
    814               printf("\nReduced to this via redRing.SIGDROP\n");pWrite(h->p);
    815               #endif
    816               //strat->enterS(*h, strat->sl+1, strat, strat->tl);
    817               return 0;
    818             }
     984            //strat->enterS(*h, strat->sl+1, strat, strat->tl);
     985            return 0;
    819986          }
    820           p_Delete(&beforeredsig,currRing);
    821         }
     987        }
     988        p_Delete(&beforeredsig,currRing);
    822989        return 1;
    823990      }
     
    832999    i = j;
    8331000    if (TEST_OPT_LENGTH)
    834     if(rField_is_Ring(currRing))
    835     {
    836       loop
    837       {
    838         /*- search the shortest possible with respect to length -*/
    839         i++;
    840         if (i > strat->tl)
    841           break;
    842         if (li<=1)
    843           break;
    844         if ((strat->T[i].pLength < li)
    845            && n_DivBy(pGetCoeff(h_p),pGetCoeff(strat->T[i].p),currRing->cf)
    846            && p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
    847                                  h_p, not_sev, strat->tailRing))
    848         {
    849           /*
    850            * the polynomial to reduce with is now;
    851            */
    852           li = strat->T[i].pLength;
    853           ii = i;
    854         }
    855       }
    856     }
    857     else
    858     {
    859       loop
    860       {
    861         /*- search the shortest possible with respect to length -*/
    862         i++;
    863         if (i > strat->tl)
    864           break;
    865         if (li<=1)
    866           break;
    867         if ((strat->T[i].pLength < li)
    868            && p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
    869                                  h_p, not_sev, strat->tailRing))
    870         {
    871           /*
    872            * the polynomial to reduce with is now;
    873            */
    874           li = strat->T[i].pLength;
    875           ii = i;
    876         }
    877       }
    878     }
     1001    loop
     1002    {
     1003      /*- search the shortest possible with respect to length -*/
     1004      i++;
     1005      if (i > strat->tl)
     1006        break;
     1007      if (li<=1)
     1008        break;
     1009      if ((strat->T[i].pLength < li)
     1010         && n_DivBy(pGetCoeff(h_p),pGetCoeff(strat->T[i].p),currRing->cf)
     1011         && p_LmShortDivisibleBy(strat->T[i].GetLmTailRing(), strat->sevT[i],
     1012                               h_p, not_sev, strat->tailRing))
     1013      {
     1014        /*
     1015         * the polynomial to reduce with is now;
     1016         */
     1017        li = strat->T[i].pLength;
     1018        ii = i;
     1019      }
     1020    }
     1021   
    8791022    start = ii+1;
    8801023
     
    9081051    printf("\nWe reduce it with:\n");p_Write(strat->T[ii].p,strat->tailRing);pWrite(strat->T[ii].sig);
    9091052    #endif
    910     sigSafe = ksReducePolySig(h, &(strat->T[ii]), strat->S_2_R[ii], NULL, NULL, strat);
     1053    sigSafe = ksReducePolySigRing(h, &(strat->T[ii]), strat->S_2_R[ii], NULL, NULL, strat);
    9111054    #ifdef ADIDEBUG
    9121055    printf("\nAfter small reduction:\n");pWrite(h->p);pWrite(h->sig);
    9131056    #endif
    914     if(rField_is_Ring(currRing) && h->p == NULL && h->sig == NULL)
     1057    if(h->p == NULL && h->sig == NULL)
    9151058    {
    9161059      //Trivial case catch
     
    10801223      strat->redTailChange=TRUE;
    10811224      #ifdef ADIDEBUG
    1082       printf("\nWill TAILreduce * with *:\n");pWrite(Ln.p);pWrite(Ln.sig);
    1083       pWrite(With->p);pWrite(With->sig);pWrite(L->sig);
     1225      printf("\nWill TAILreduce * with *:\n");p_Write(Ln.p,strat->tailRing);pWrite(Ln.sig);
     1226      p_Write(With->p,strat->tailRing);pWrite(With->sig);pWrite(L->sig);
    10841227      #endif
    10851228      int ret = ksReducePolyTailSig(L, With, &Ln, strat);
     
    20522195  sba_interreduction_operations = 0;
    20532196#endif
    2054  
     2197
    20552198  ideal F1 = F0;
    20562199  ring sRing, currRingOld;
     
    20652208    }
    20662209  }
    2067   ideal F;
    20682210  // sort ideal F
    2069   //Put the SigDrop element on the correct position (think of sbaEnterS)
    2070   //We also sort them
    2071   if(rField_is_Ring(currRing) && strat->sigdrop)
    2072   {
    2073     #if 1
    2074     F = idInit(IDELEMS(F1),F1->rank);
    2075     for (int i=0; i<IDELEMS(F1);++i)
    2076       F->m[i] = F1->m[i];
    2077     if(strat->sbaEnterS >= 0)
    2078     {
    2079       poly dummy;
    2080       dummy = pCopy(F->m[0]); //the sigdrop element
    2081       for(int i = 0;i<strat->sbaEnterS;i++)
    2082         F->m[i] = F->m[i+1];
    2083       F->m[strat->sbaEnterS] = dummy;
    2084     }
    2085     #else
    2086     F = idInit(1,F1->rank);
    2087     //printf("\nBefore the initial block sorting:\n");idPrint(F1);
    2088     F->m[0] = F1->m[0];
    2089     int pos;
    2090     if(strat->sbaEnterS >= 0)
    2091     {
    2092       for(int i=1;i<=strat->sbaEnterS;i++)
    2093       {
    2094         pos = posInIdealMonFirst(F,F1->m[i],1,strat->sbaEnterS);
    2095         idInsertPolyOnPos(F,F1->m[i],pos);
    2096       }
    2097       for(int i=strat->sbaEnterS+1;i<IDELEMS(F1);i++)
    2098       {
    2099         pos = posInIdealMonFirst(F,F1->m[i],strat->sbaEnterS+1,IDELEMS(F));
    2100         idInsertPolyOnPos(F,F1->m[i],pos);
    2101       }
    2102       poly dummy;
    2103       dummy = pCopy(F->m[0]); //the sigdrop element
    2104       for(int i = 0;i<strat->sbaEnterS;i++)
    2105         F->m[i] = F->m[i+1];
    2106       F->m[strat->sbaEnterS] = dummy;
    2107     }
    2108     else
    2109     {
    2110       for(int i=1;i<IDELEMS(F1);i++)
    2111       {
    2112         pos = posInIdealMonFirst(F,F1->m[i],1,IDELEMS(F));
    2113         idInsertPolyOnPos(F,F1->m[i],pos);
    2114       }
    2115     }
    2116     #endif
    2117     //printf("\nAfter the initial block sorting:\n");idPrint(F);getchar();
    2118   }
    2119   else
    2120   {
    2121     F       = idInit(IDELEMS(F1),F1->rank);
    2122     intvec *sort  = idSort(F1);
    2123     for (int i=0; i<sort->length();++i)
    2124       F->m[i] = F1->m[(*sort)[i]-1];
    2125   // put the monomials after the sbaEnterS polynomials
    2126   //printf("\nThis is the ideal before sorting (sbaEnterS = %i)\n",strat->sbaEnterS);idPrint(F);
    2127   int nrmon = 0;
    2128   for(int i = IDELEMS(F)-1,j;i>strat->sbaEnterS+nrmon+1 ;i--)
    2129   {
    2130     //pWrite(F->m[i]);
    2131     if(F->m[i] != NULL && pNext(F->m[i]) == NULL)
    2132     {
    2133       poly mon = F->m[i];
    2134       for(j = i;j>strat->sbaEnterS+nrmon+1;j--)
    2135       {
    2136         F->m[j] = F->m[j-1];
    2137       }
    2138       F->m[j] = mon;
    2139       nrmon++;
    2140     }
    2141     //idPrint(F);
    2142   }
    2143   }
    2144     //printf("\nThis is the ideal after sorting\n");idPrint(F);getchar();
    2145   #ifdef HAVE_RINGS
    2146   if(rField_is_Ring(currRing))
    2147     strat->sigdrop = FALSE;
    2148   strat->nrsyzcrit = 0;
    2149   strat->nrrewcrit = 0;
    2150   #endif
     2211  ideal F       = idInit(IDELEMS(F1),F1->rank);
     2212  intvec *sort  = idSort(F1);
     2213  for (int i=0; i<sort->length();++i)
     2214    F->m[i] = F1->m[(*sort)[i]-1];
    21512215#if SBA_INTERRED_START
    21522216  F = kInterRed(F,NULL);
     
    21582222  printf("\n");
    21592223#endif
     2224#ifdef KDEBUG
     2225  bba_count++;
     2226  int loop_count = 0;
     2227#endif /* KDEBUG */
    21602228  int   srmax,lrmax, red_result = 1;
    21612229  int   olddeg,reduc;
     
    21642232  BOOLEAN withT     = TRUE;
    21652233  strat->max_lower_index = 0;
     2234
    21662235  //initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
    21672236  initSbaCrit(strat); /*set Gebauer, honey, sugarCrit*/
    21682237  initSbaPos(strat);
     2238  //initBuchMoraPos(strat);
    21692239  initHilbCrit(F,Q,&hilb,strat);
    21702240  initSba(F,strat);
     
    21742244  srmax = strat->sl;
    21752245  reduc = olddeg = lrmax = 0;
     2246
    21762247#ifndef NO_BUCKETS
    21772248  if (!TEST_OPT_NOT_BUCKETS)
     
    21862257  kTest_TS(strat);
    21872258
     2259#ifdef KDEBUG
     2260#if MYTEST
     2261  if (TEST_OPT_DEBUG)
     2262  {
     2263    PrintS("bba start GB: currRing: ");
     2264    // rWrite(currRing);PrintLn();
     2265    rDebugPrint(currRing);
     2266    PrintLn();
     2267  }
     2268#endif /* MYTEST */
     2269#endif /* KDEBUG */
     2270
    21882271#ifdef HAVE_TAIL_RING
    21892272  if(!idIs0(F) &&(!rField_is_Ring(currRing)))  // create strong gcd poly computes with tailring and S[i] ->to be fixed
     
    21962279    kDebugPrint(strat);
    21972280  }
    2198   // We add the elements directly in S from the previous loop
    2199   if(rField_is_Ring(currRing) && strat->sbaEnterS >= 0)
    2200   {
    2201     for(int i = 0;i<strat->sbaEnterS;i++)
    2202     {
    2203       //Update: now the element is at the corect place
    2204       //i+1 because on the 0 position is the sigdrop element
    2205       enterT(strat->L[strat->Ll-(i)],strat);
    2206       strat->enterS(strat->L[strat->Ll-(i)], strat->sl+1, strat, strat->tl);
    2207     }
    2208     strat->Ll = strat->Ll - strat->sbaEnterS;
    2209     strat->sbaEnterS = -1;
    2210   }
    2211   kTest_TS(strat);
     2281
     2282
    22122283#ifdef KDEBUG
    22132284  //kDebugPrint(strat);
     
    22162287  while (strat->Ll >= 0)
    22172288  {
    2218     #ifdef ADIDEBUG
    2219     printf("\n      ------------------------NEW LOOP\n");
    2220     printf("\nShdl = \n");
    2221     #if 0
    2222     idPrint(strat->Shdl);
    2223     #else
    2224     for(int ii = 0; ii<=strat->sl;ii++)
    2225     {
    2226       printf("\nS[%i]:  ",ii);p_Write(strat->S[ii],strat->tailRing);
    2227       printf("sig:   ");pWrite(strat->sig[ii]);
    2228     }
    2229     #endif
    2230     #if 0
    2231     for(int iii = 0; iii< strat->syzl; iii++)
    2232     {
    2233         printf("\nsyz[%i]:\n",iii);
    2234         p_Write(strat->syz[iii], currRing);
    2235     }
    2236     #endif
    2237     #if 0
    2238     for(int iii = 0; iii<= strat->tl; iii++)
    2239     {
    2240         printf("\nT[%i]:\n",iii);
    2241         p_Write(strat->T[iii].p, currRing);
    2242     }
    2243     #endif
    2244     printf("\n   list   L\n");
    2245     int iii;
    2246     #if 1
    2247     for(iii = 0; iii<= strat->Ll; iii++)
    2248     {
    2249         printf("\nL[%i]:\n",iii);
    2250         p_Write(strat->L[iii].p, currRing);
    2251         p_Write(strat->L[iii].p1, currRing);
    2252         p_Write(strat->L[iii].p2, currRing);
    2253         p_Write(strat->L[iii].sig, currRing);
    2254     }
    2255     #else
    2256     {
    2257         printf("L[%i]:",strat->Ll);
    2258         p_Write(strat->L[strat->Ll].p, strat->tailRing);
    2259         p_Write(strat->L[strat->Ll].p1, strat->tailRing);
    2260         p_Write(strat->L[strat->Ll].p2, strat->tailRing);
    2261         p_Write(strat->L[strat->Ll].sig, strat->tailRing);
    2262     }
    2263     #endif
    2264     //getchar();
    2265     #endif
    22662289    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
    22672290    #ifdef KDEBUG
     2291      loop_count++;
    22682292      if (TEST_OPT_DEBUG) messageSets(strat);
    22692293    #endif
     
    22742298            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
    22752299    {
    2276 
    22772300       //stops computation if
    22782301       // 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
     
    22992322      // initialize new syzygy rules for the next iteration step
    23002323      initSyzRules(strat);
     2324
    23012325    }
    23022326    /*********************************************************************
     
    23072331    strat->P = strat->L[strat->Ll];
    23082332    strat->Ll--;
    2309    
    2310     if(rField_is_Ring(currRing))
    2311       strat->sbaEnterS = pGetComp(strat->P.sig) - 1;
    2312    
    2313     #ifdef ADIDEBUG
    2314     printf("\n-------------------------\nThis is the current element P\n");
    2315     pWrite(strat->P.p);
    2316     pWrite(strat->P.p1);
    2317     pWrite(strat->P.p2);
    2318     pWrite(strat->P.sig);
    2319     #endif
    2320     /* reduction of the element chosen from L */
    2321     // We do not delete via RewCrit strong pairs or extended spolys over rings
    2322     // these should have .lcm = NULL
    2323     if (strat->P.lcm == NULL || !strat->rewCrit2(strat->P.sig, ~strat->P.sevSig, strat->P.GetLmCurrRing(), strat, strat->P.checked+1)) {
     2333    /* reduction of the element choosen from L */
     2334
     2335    if (!strat->rewCrit2(strat->P.sig, ~strat->P.sevSig, strat->P.GetLmCurrRing(), strat, strat->P.checked+1)) {
    23242336      //#if 1
    23252337#ifdef DEBUGF5
     
    23362348        // deletes the short spoly
    23372349        /*
     2350#ifdef HAVE_RINGS
    23382351        if (rField_is_Ring(currRing))
    23392352          pLmDelete(strat->P.p);
    23402353        else
     2354#endif
    23412355          pLmFree(strat->P.p);
    23422356*/
     
    23702384          strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
    23712385        // for input polys, prepare reduction
    2372         if(!rField_is_Ring(currRing))
    2373           strat->P.PrepareRed(strat->use_buckets);
     2386        strat->P.PrepareRed(strat->use_buckets);
    23742387      }
    23752388      if (strat->P.p == NULL && strat->P.t_p == NULL)
     
    24092422      red_result = 2;
    24102423    }
    2411     if(rField_is_Ring(currRing))
    2412     {
    2413       if(strat->P.sig!= NULL && !nGreaterZero(pGetCoeff(strat->P.sig)))
    2414       {
    2415         strat->P.p = pNeg(strat->P.p);
    2416         strat->P.sig = pNeg(strat->P.sig);
    2417       }
    2418       strat->P.pLength = pLength(strat->P.p);
    2419       if(strat->P.sig != NULL)
    2420         strat->P.sevSig = pGetShortExpVector(strat->P.sig);
    2421       if(strat->P.p != NULL)
    2422         strat->P.sev = pGetShortExpVector(strat->P.p);
    2423     }
    2424     #ifdef ADIDEBUG
    2425     printf("\nAfter reduce (redresult=%i): \n",red_result);pWrite(strat->P.p);pWrite(strat->P.sig);
    2426     #endif
    2427     //sigdrop case
    2428     if(rField_is_Ring(currRing) && strat->sigdrop)
    2429     {
    2430       //First reduce it as much as one can
    2431       #ifdef ADIDEBUG
    2432       printf("\nSigdrop in the reduce. Trying redring\n");
    2433       #endif
    2434       red_result = redRing(&strat->P,strat);
    2435       if(red_result == 0)
    2436       {
    2437         #ifdef ADIDEBUG
    2438         printf("\nSigdrop cancelled since redRing reduced to 0\n");
    2439         #endif
    2440         strat->sigdrop = FALSE;
    2441         pDelete(&strat->P.sig);
    2442         strat->P.sig = NULL;
    2443       }
    2444       else
    2445       {
    2446         #ifdef ADIDEBUG
    2447         printf("\nStill Sigdrop - redRing reduced to:\n");pWrite(strat->P.p);
    2448         #endif
    2449         strat->enterS(strat->P, 0, strat, strat->tl);
    2450         if (TEST_OPT_PROT)
    2451           PrintS("-");
    2452         break;
    2453       }
    2454     }
    2455     if(strat->blockred > strat->blockredmax)
    2456     {
    2457       #ifdef ADIDEBUG
    2458       printf("\nToo many blocked reductions\n");
    2459       #endif
    2460       strat->sigdrop = TRUE;
    2461       break;
    2462     }
    2463    
    24642424    if (errorreported)  break;
    24652425
     
    24742434    }
    24752435#endif
    2476     if (TEST_OPT_PROT)
    2477     {
    2478       if(strat->P.p != NULL)
    2479         message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
    2480                 &olddeg,&reduc,strat, red_result);
    2481       else
    2482         message((strat->honey ? strat->P.ecart : 0),
    2483                 &olddeg,&reduc,strat, red_result);
    2484     }
    24852436
    24862437    if (strat->overflow)
     
    24882439        if (!kStratChangeTailRing(strat)) { Werror("OVERFLOW.."); break;}
    24892440    }
     2441
    24902442    // reduction to non-zero new poly
    24912443    if (red_result == 1)
     
    25102462      int pos = strat->sl+1;
    25112463
     2464#ifdef KDEBUG
     2465#if MYTEST
     2466      PrintS("New S: "); pDebugPrint(strat->P.p); PrintLn();
     2467#endif /* MYTEST */
     2468#endif /* KDEBUG */
     2469
    25122470      // reduce the tail and normalize poly
    25132471      // in the ring case we cannot expect LC(f) = 1,
    25142472      // therefore we call pContent instead of pNorm
    2515       #ifdef HAVE_RINGS
    2516       poly beforetailred;
    2517       if(rField_is_Ring(currRing))
    2518         beforetailred = pCopy(strat->P.sig);
    2519       #endif
    25202473#if SBA_TAIL_RED
    2521       if(rField_is_Ring(currRing))
    2522       { 
    2523         if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
    2524           strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
    2525       }
    2526       else
    2527       {
    2528         if (strat->sbaOrder != 2) {
    2529           if (TEST_OPT_INTSTRATEGY)
     2474      if (strat->sbaOrder != 2) {
     2475        if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing)))
     2476        {
     2477          strat->P.pCleardenom();
     2478          if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
    25302479          {
     2480            strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
    25312481            strat->P.pCleardenom();
    2532             if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
    2533             {
    2534               strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
    2535               strat->P.pCleardenom();
    2536             }
    25372482          }
    2538           else
    2539           {
    2540             strat->P.pNorm();
    2541             if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
    2542               strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
    2543           }
    2544         }
    2545       }
    2546       // It may happen that we have lost the sig in redtailsba
    2547       // It cannot reduce to 0 since here we are doing just tail reduction.
    2548       // Best case scenerio: remains the leading term
    2549       if(rField_is_Ring(currRing) && strat->sigdrop)     
    2550       {
    2551         #ifdef ADIDEBUG
    2552         printf("\n Still sigdrop after redtailSba - it reduced to \n");pWrite(strat->P.p);
    2553         #endif
    2554         strat->enterS(strat->P, 0, strat, strat->tl);
    2555         break;
    2556       }
    2557 #endif
    2558     if(rField_is_Ring(currRing))
    2559     {
    2560       if(strat->P.sig == NULL || pLtCmp(beforetailred,strat->P.sig) == 1)
    2561       {
    2562         #ifdef ADIDEBUG
    2563         printf("\nSigDrop after TAILred\n");pWrite(beforetailred);pWrite(strat->P.sig);
    2564         #endif
    2565         strat->sigdrop = TRUE;
    2566         //Reduce it as much as you can
    2567         red_result = redRing(&strat->P,strat);
    2568         if(red_result == 0)
    2569         {
    2570           //It reduced to 0, cancel the sigdrop
    2571           #ifdef ADIDEBUG
    2572           printf("\nReduced to 0 via redRing. Cancel sigdrop\n");
    2573           #endif
    2574           strat->sigdrop = FALSE;
    2575           p_Delete(&strat->P.sig,currRing);strat->P.sig = NULL;
    25762483        }
    25772484        else
    25782485        {
    2579           #ifdef ADIDEBUG
    2580           printf("\nReduced to this via redRing.SIGDROP\n");pWrite(strat->P.p);
    2581           #endif
    2582           strat->enterS(strat->P, 0, strat, strat->tl);
    2583           break;
    2584         }
    2585       }
    2586       p_Delete(&beforetailred,currRing);
    2587       // strat->P.p = NULL may appear if we had  a sigdrop above and reduced to 0 via redRing
    2588       if(strat->P.p == NULL)
    2589         goto case_when_red_result_changed;
    2590     }
    2591     #ifdef ADIDEBUG
    2592     printf("\nNach redTailSba: \n");
    2593     pWrite(strat->P.p);pWrite(strat->P.sig);
    2594     #endif
     2486          strat->P.pNorm();
     2487          if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
     2488            strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
     2489        }
     2490      }
     2491#endif
     2492
    25952493    // remove sigsafe label since it is no longer valid for the next element to
    25962494    // be reduced
     
    26142512#ifdef KDEBUG
    26152513      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
     2514#if MYTEST
     2515//#if 1
     2516      PrintS("New (reduced) S: "); pDebugPrint(strat->P.p); PrintLn();
     2517#endif /* MYTEST */
    26162518#endif /* KDEBUG */
    26172519
     
    26462548      pWrite(strat->P.sig);
    26472549      */
     2550#ifdef HAVE_RINGS
    26482551      if (rField_is_Ring(currRing))
    2649         superenterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
     2552        superenterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
    26502553      else
     2554#endif
    26512555        enterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
    2652       #ifdef ADIDEBUG
    2653         printf("\nThis element is added to S\n");
    2654         p_Write(strat->P.p, strat->tailRing);p_Write(strat->P.p1, strat->tailRing);p_Write(strat->P.p2, strat->tailRing);pWrite(strat->P.sig);
    2655         getchar();
    2656         #endif
    26572556      // posInS only depends on the leading term
    2658      
    2659       if(rField_is_Ring(currRing) && strat->sigdrop)
    2660         break;
    2661       strat->P.sevSig = p_GetShortExpVector(strat->P.sig,currRing);
    26622557      strat->enterS(strat->P, pos, strat, strat->tl);
    2663      
    26642558      if(strat->sbaOrder != 1)
    26652559      {
     
    28202714    else
    28212715    {
     2716      // adds signature of the zero reduction to
     2717      // strat->syz. This is the leading term of
     2718      // syzygy and can be used in syzCriterion()
     2719      // the signature is added if and only if the
     2720      // pair was not detected by the rewritten criterion in strat->red = redSig
     2721      if (red_result!=2) {
     2722#if SBA_PRINT_ZERO_REDUCTIONS
     2723        zeroreductions++;
     2724#endif
     2725        int pos = posInSyz(strat, strat->P.sig);
     2726        enterSyz(strat->P, strat, pos);
     2727//#if 1
     2728#ifdef DEBUGF5
     2729        Print("ADDING STUFF TO SYZ :  ");
     2730        //pWrite(strat->P.p);
     2731        pWrite(strat->P.sig);
     2732#endif
     2733      }
     2734      if (strat->P.p1 == NULL && strat->minim > 0)
     2735      {
     2736        p_Delete(&strat->P.p2, currRing, strat->tailRing);
     2737      }
     2738    }
     2739
     2740#ifdef KDEBUG
     2741    memset(&(strat->P), 0, sizeof(strat->P));
     2742#endif /* KDEBUG */
     2743    kTest_TS(strat);
     2744  }
     2745#ifdef KDEBUG
     2746#if MYTEST
     2747  PrintS("bba finish GB: currRing: "); rWrite(currRing);
     2748#endif /* MYTEST */
     2749  if (TEST_OPT_DEBUG) messageSets(strat);
     2750#endif /* KDEBUG */
     2751
     2752  if (TEST_OPT_SB_1)
     2753  {
     2754    #ifdef HAVE_RINGS
     2755    if(!rField_is_Ring(currRing))
     2756    #endif
     2757    {
     2758        int k=1;
     2759        int j;
     2760        while(k<=strat->sl)
     2761        {
     2762          j=0;
     2763          loop
     2764          {
     2765            if (j>=k) break;
     2766            clearS(strat->S[j],strat->sevS[j],&k,&j,strat);
     2767            j++;
     2768          }
     2769          k++;
     2770        }
     2771    }
     2772  }
     2773
     2774  /* complete reduction of the standard basis--------- */
     2775  if (TEST_OPT_REDSB)
     2776  {
     2777    completeReduce(strat);
     2778#ifdef HAVE_TAIL_RING
     2779    if (strat->completeReduce_retry)
     2780    {
     2781      // completeReduce needed larger exponents, retry
     2782      // to reduce with S (instead of T)
     2783      // and in currRing (instead of strat->tailRing)
     2784      cleanT(strat);strat->tailRing=currRing;
     2785      int i;
     2786      for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
     2787      completeReduce(strat);
     2788    }
     2789#endif
     2790  }
     2791  else if (TEST_OPT_PROT) PrintLn();
     2792
     2793#if SBA_PRINT_SIZE_SYZ
     2794  // that is correct, syzl is counting one too far
     2795  size_syz = strat->syzl;
     2796#endif
     2797  exitSba(strat);
     2798//  if (TEST_OPT_WEIGHTM)
     2799//  {
     2800//    pRestoreDegProcs(pFDegOld, pLDegOld);
     2801//    if (ecartWeights)
     2802//    {
     2803//      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
     2804//      ecartWeights=NULL;
     2805//    }
     2806//  }
     2807  if (TEST_OPT_PROT) messageStat(hilbcount,strat);
     2808  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
     2809
     2810#ifdef KDEBUG
     2811#if MYTEST
     2812  PrintS("bba_end: currRing: "); rWrite(currRing);
     2813#endif /* MYTEST */
     2814#endif /* KDEBUG */
     2815#if SBA_PRINT_SIZE_G
     2816  size_g_non_red  = IDELEMS(strat->Shdl);
     2817#endif
     2818  if ((strat->sbaOrder == 1 || strat->sbaOrder == 3) && sRing!=currRingOld)
     2819  {
     2820    rChangeCurrRing (currRingOld);
     2821    F0          = idrMoveR (F1, sRing, currRing);
     2822    strat->Shdl = idrMoveR_NoSort (strat->Shdl, sRing, currRing);
     2823    rDelete (sRing);
     2824  }
     2825  id_DelDiv(strat->Shdl, currRing);
     2826  idSkipZeroes(strat->Shdl);
     2827  idTest(strat->Shdl);
     2828
     2829#if SBA_PRINT_SIZE_G
     2830  size_g   = IDELEMS(strat->Shdl);
     2831#endif
     2832#ifdef DEBUGF5
     2833  printf("SIZE OF SHDL: %d\n",IDELEMS(strat->Shdl));
     2834  int oo = 0;
     2835  while (oo<IDELEMS(strat->Shdl))
     2836  {
     2837    printf(" %d.   ",oo+1);
     2838    pWrite(pHead(strat->Shdl->m[oo]));
     2839    oo++;
     2840  }
     2841#endif
     2842#if SBA_PRINT_ZERO_REDUCTIONS
     2843  printf("----------------------------------------------------------\n");
     2844  printf("ZERO REDUCTIONS:            %ld\n",zeroreductions);
     2845  zeroreductions  = 0;
     2846#endif
     2847#if SBA_PRINT_REDUCTION_STEPS
     2848  printf("----------------------------------------------------------\n");
     2849  printf("S-REDUCTIONS:               %ld\n",sba_reduction_steps);
     2850#endif
     2851#if SBA_PRINT_OPERATIONS
     2852  printf("OPERATIONS:                 %ld\n",sba_operations);
     2853#endif
     2854#if SBA_PRINT_REDUCTION_STEPS
     2855  printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
     2856  printf("INTERREDUCTIONS:            %ld\n",sba_interreduction_steps);
     2857#endif
     2858#if SBA_PRINT_OPERATIONS
     2859  printf("INTERREDUCTION OPERATIONS:  %ld\n",sba_interreduction_operations);
     2860#endif
     2861#if SBA_PRINT_REDUCTION_STEPS
     2862  printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
     2863  printf("ALL REDUCTIONS:             %ld\n",sba_reduction_steps+sba_interreduction_steps);
     2864  sba_interreduction_steps  = 0;
     2865  sba_reduction_steps       = 0;
     2866#endif
     2867#if SBA_PRINT_OPERATIONS
     2868  printf("ALL OPERATIONS:             %ld\n",sba_operations+sba_interreduction_operations);
     2869  sba_interreduction_operations = 0;
     2870  sba_operations                = 0;
     2871#endif
     2872#if SBA_PRINT_SIZE_G
     2873  printf("----------------------------------------------------------\n");
     2874  printf("SIZE OF G:                  %d / %d\n",size_g,size_g_non_red);
     2875  size_g          = 0;
     2876  size_g_non_red  = 0;
     2877#endif
     2878#if SBA_PRINT_SIZE_SYZ
     2879  printf("SIZE OF SYZ:                %ld\n",size_syz);
     2880  printf("----------------------------------------------------------\n");
     2881  size_syz  = 0;
     2882#endif
     2883#if SBA_PRINT_PRODUCT_CRITERION
     2884  printf("PRODUCT CRITERIA:           %ld\n",product_criterion);
     2885  product_criterion = 0;
     2886#endif
     2887  return (strat->Shdl);
     2888}
     2889
     2890ideal sbaZ (ideal F0, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
     2891{
     2892  // ring order stuff:
     2893  // in sba we have (until now) two possibilities:
     2894  // 1. an incremental computation w.r.t. (C,monomial order)
     2895  // 2. a (possibly non-incremental) computation w.r.t. the
     2896  //    induced Schreyer order.
     2897  // The corresponding orders are computed in sbaRing(), depending
     2898  // on the flag strat->sbaOrder
     2899#if SBA_PRINT_ZERO_REDUCTIONS
     2900  long zeroreductions           = 0;
     2901#endif
     2902#if SBA_PRINT_PRODUCT_CRITERION
     2903  long product_criterion        = 0;
     2904#endif
     2905#if SBA_PRINT_SIZE_G
     2906  int size_g                    = 0;
     2907  int size_g_non_red            = 0;
     2908#endif
     2909#if SBA_PRINT_SIZE_SYZ
     2910  long size_syz                 = 0;
     2911#endif
     2912  // global variable
     2913#if SBA_PRINT_REDUCTION_STEPS
     2914  sba_reduction_steps           = 0;
     2915  sba_interreduction_steps      = 0;
     2916#endif
     2917#if SBA_PRINT_OPERATIONS
     2918  sba_operations                = 0;
     2919  sba_interreduction_operations = 0;
     2920#endif
     2921 
     2922  ideal F1 = F0;
     2923  ring sRing, currRingOld;
     2924  currRingOld  = currRing;
     2925  if (strat->sbaOrder == 1 || strat->sbaOrder == 3)
     2926  {
     2927    sRing = sbaRing(strat);
     2928    if (sRing!=currRingOld)
     2929    {
     2930      rChangeCurrRing (sRing);
     2931      F1 = idrMoveR (F0, currRingOld, currRing);
     2932    }
     2933  }
     2934  ideal F;
     2935  // sort ideal F
     2936  //Put the SigDrop element on the correct position (think of sbaEnterS)
     2937  //We also sort them
     2938  if(rField_is_Ring(currRing) && strat->sigdrop)
     2939  {
     2940    #if 1
     2941    F = idInit(IDELEMS(F1),F1->rank);
     2942    for (int i=0; i<IDELEMS(F1);++i)
     2943      F->m[i] = F1->m[i];
     2944    if(strat->sbaEnterS >= 0)
     2945    {
     2946      poly dummy;
     2947      dummy = pCopy(F->m[0]); //the sigdrop element
     2948      for(int i = 0;i<strat->sbaEnterS;i++)
     2949        F->m[i] = F->m[i+1];
     2950      F->m[strat->sbaEnterS] = dummy;
     2951    }
     2952    #else
     2953    F = idInit(1,F1->rank);
     2954    //printf("\nBefore the initial block sorting:\n");idPrint(F1);
     2955    F->m[0] = F1->m[0];
     2956    int pos;
     2957    if(strat->sbaEnterS >= 0)
     2958    {
     2959      for(int i=1;i<=strat->sbaEnterS;i++)
     2960      {
     2961        pos = posInIdealMonFirst(F,F1->m[i],1,strat->sbaEnterS);
     2962        idInsertPolyOnPos(F,F1->m[i],pos);
     2963      }
     2964      for(int i=strat->sbaEnterS+1;i<IDELEMS(F1);i++)
     2965      {
     2966        pos = posInIdealMonFirst(F,F1->m[i],strat->sbaEnterS+1,IDELEMS(F));
     2967        idInsertPolyOnPos(F,F1->m[i],pos);
     2968      }
     2969      poly dummy;
     2970      dummy = pCopy(F->m[0]); //the sigdrop element
     2971      for(int i = 0;i<strat->sbaEnterS;i++)
     2972        F->m[i] = F->m[i+1];
     2973      F->m[strat->sbaEnterS] = dummy;
     2974    }
     2975    else
     2976    {
     2977      for(int i=1;i<IDELEMS(F1);i++)
     2978      {
     2979        pos = posInIdealMonFirst(F,F1->m[i],1,IDELEMS(F));
     2980        idInsertPolyOnPos(F,F1->m[i],pos);
     2981      }
     2982    }
     2983    #endif
     2984    //printf("\nAfter the initial block sorting:\n");idPrint(F);getchar();
     2985  }
     2986  else
     2987  {
     2988    F       = idInit(IDELEMS(F1),F1->rank);
     2989    intvec *sort  = idSort(F1);
     2990    for (int i=0; i<sort->length();++i)
     2991      F->m[i] = F1->m[(*sort)[i]-1];
     2992    if(rField_is_Ring(currRing))
     2993    {
     2994      // put the monomials after the sbaEnterS polynomials
     2995      //printf("\nThis is the ideal before sorting (sbaEnterS = %i)\n",strat->sbaEnterS);idPrint(F);
     2996      int nrmon = 0;
     2997      for(int i = IDELEMS(F)-1,j;i>strat->sbaEnterS+nrmon+1 ;i--)
     2998      {
     2999        //pWrite(F->m[i]);
     3000        if(F->m[i] != NULL && pNext(F->m[i]) == NULL)
     3001        {
     3002          poly mon = F->m[i];
     3003          for(j = i;j>strat->sbaEnterS+nrmon+1;j--)
     3004          {
     3005            F->m[j] = F->m[j-1];
     3006          }
     3007          F->m[j] = mon;
     3008          nrmon++;
     3009        }
     3010        //idPrint(F);
     3011      }
     3012    }
     3013  }
     3014    //printf("\nThis is the ideal after sorting\n");idPrint(F);getchar();
     3015  if(rField_is_Ring(currRing))
     3016    strat->sigdrop = FALSE;
     3017  strat->nrsyzcrit = 0;
     3018  strat->nrrewcrit = 0;
     3019#if SBA_INTERRED_START
     3020  F = kInterRed(F,NULL);
     3021#endif
     3022#if F5DEBUG
     3023  printf("SBA COMPUTATIONS DONE IN THE FOLLOWING RING:\n");
     3024  rWrite (currRing);
     3025  printf("ordSgn = %d\n",currRing->OrdSgn);
     3026  printf("\n");
     3027#endif
     3028  int   srmax,lrmax, red_result = 1;
     3029  int   olddeg,reduc;
     3030  int hilbeledeg=1,hilbcount=0,minimcnt=0;
     3031  LObject L;
     3032  BOOLEAN withT     = TRUE;
     3033  strat->max_lower_index = 0;
     3034  //initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
     3035  initSbaCrit(strat); /*set Gebauer, honey, sugarCrit*/
     3036  initSbaPos(strat);
     3037  initHilbCrit(F,Q,&hilb,strat);
     3038  initSba(F,strat);
     3039  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
     3040  /*Shdl=*/initSbaBuchMora(F, Q,strat);
     3041  idTest(strat->Shdl);
     3042  if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
     3043  srmax = strat->sl;
     3044  reduc = olddeg = lrmax = 0;
     3045#ifndef NO_BUCKETS
     3046  if (!TEST_OPT_NOT_BUCKETS)
     3047    strat->use_buckets = 1;
     3048#endif
     3049
     3050  // redtailBBa against T for inhomogenous input
     3051  // if (!TEST_OPT_OLDSTD)
     3052  //   withT = ! strat->homog;
     3053
     3054  // strat->posInT = posInT_pLength;
     3055  kTest_TS(strat);
     3056
     3057#ifdef HAVE_TAIL_RING
     3058  if(!idIs0(F) &&(!rField_is_Ring(currRing)))  // create strong gcd poly computes with tailring and S[i] ->to be fixed
     3059    kStratInitChangeTailRing(strat);
     3060#endif
     3061  if (BVERBOSE(23))
     3062  {
     3063    if (test_PosInT!=NULL) strat->posInT=test_PosInT;
     3064    if (test_PosInL!=NULL) strat->posInL=test_PosInL;
     3065    kDebugPrint(strat);
     3066  }
     3067  // We add the elements directly in S from the previous loop
     3068  if(rField_is_Ring(currRing) && strat->sbaEnterS >= 0)
     3069  {
     3070    for(int i = 0;i<strat->sbaEnterS;i++)
     3071    {
     3072      //Update: now the element is at the corect place
     3073      //i+1 because on the 0 position is the sigdrop element
     3074      enterT(strat->L[strat->Ll-(i)],strat);
     3075      strat->enterS(strat->L[strat->Ll-(i)], strat->sl+1, strat, strat->tl);
     3076    }
     3077    strat->Ll = strat->Ll - strat->sbaEnterS;
     3078    strat->sbaEnterS = -1;
     3079  }
     3080  kTest_TS(strat);
     3081#ifdef KDEBUG
     3082  //kDebugPrint(strat);
     3083#endif
     3084  /* compute------------------------------------------------------- */
     3085  while (strat->Ll >= 0)
     3086  {
     3087    #ifdef ADIDEBUG
     3088    printf("\n      ------------------------NEW LOOP\n");
     3089    printf("\nShdl = \n");
     3090    #if 0
     3091    idPrint(strat->Shdl);
     3092    #else
     3093    for(int ii = 0; ii<=strat->sl;ii++)
     3094    {
     3095      printf("\nS[%i]:  ",ii);p_Write(strat->S[ii],strat->tailRing);
     3096      printf("sig:   ");pWrite(strat->sig[ii]);
     3097    }
     3098    #endif
     3099    #if 0
     3100    for(int iii = 0; iii< strat->syzl; iii++)
     3101    {
     3102        printf("\nsyz[%i]:\n",iii);
     3103        p_Write(strat->syz[iii], currRing);
     3104    }
     3105    #endif
     3106    #if 0
     3107    for(int iii = 0; iii<= strat->tl; iii++)
     3108    {
     3109        printf("\nT[%i]:\n",iii);
     3110        p_Write(strat->T[iii].p, currRing);
     3111    }
     3112    #endif
     3113    printf("\n   list   L\n");
     3114    int iii;
     3115    #if 0
     3116    for(iii = 0; iii<= strat->Ll; iii++)
     3117    {
     3118        printf("\nL[%i]:\n",iii);
     3119        p_Write(strat->L[iii].p, currRing);
     3120        p_Write(strat->L[iii].p1, currRing);
     3121        p_Write(strat->L[iii].p2, currRing);
     3122        p_Write(strat->L[iii].sig, currRing);
     3123    }
     3124    #else
     3125    {
     3126        printf("L[%i]:",strat->Ll);
     3127        p_Write(strat->L[strat->Ll].p, strat->tailRing);
     3128        p_Write(strat->L[strat->Ll].p1, strat->tailRing);
     3129        p_Write(strat->L[strat->Ll].p2, strat->tailRing);
     3130        p_Write(strat->L[strat->Ll].sig, currRing);
     3131    }
     3132    #endif
     3133    //getchar();
     3134    #endif
     3135    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
     3136    #ifdef KDEBUG
     3137      if (TEST_OPT_DEBUG) messageSets(strat);
     3138    #endif
     3139    if (strat->Ll== 0) strat->interpt=TRUE;
     3140    /*
     3141    if (TEST_OPT_DEGBOUND
     3142        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
     3143            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
     3144    {
     3145
     3146       //stops computation if
     3147       // 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
     3148       //a predefined number Kstd1_deg
     3149      while ((strat->Ll >= 0)
     3150        && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
     3151        && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
     3152            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))
     3153        )
     3154        deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
     3155      if (strat->Ll<0) break;
     3156      else strat->noClearS=TRUE;
     3157    }
     3158    */
     3159    if (strat->sbaOrder == 1 && pGetComp(strat->L[strat->Ll].sig) != strat->currIdx)
     3160    {
     3161      strat->currIdx  = pGetComp(strat->L[strat->Ll].sig);
     3162#if F5C
     3163      // 1. interreduction of the current standard basis
     3164      // 2. generation of new principal syzygy rules for syzCriterion
     3165      f5c ( strat, olddeg, minimcnt, hilbeledeg, hilbcount, srmax,
     3166          lrmax, reduc, Q, w, hilb );
     3167#endif
     3168      // initialize new syzygy rules for the next iteration step
     3169      initSyzRules(strat);
     3170    }
     3171    /*********************************************************************
     3172      * interrreduction step is done, we can go on with the next iteration
     3173      * step of the signature-based algorithm
     3174      ********************************************************************/
     3175    /* picks the last element from the lazyset L */
     3176    strat->P = strat->L[strat->Ll];
     3177    strat->Ll--;
     3178   
     3179    if(rField_is_Ring(currRing))
     3180      strat->sbaEnterS = pGetComp(strat->P.sig) - 1;
     3181   
     3182    #ifdef ADIDEBUG
     3183    printf("\n-------------------------\nThis is the current element P\n");
     3184    p_Write(strat->P.p,strat->tailRing);
     3185    p_Write(strat->P.p1,strat->tailRing);
     3186    p_Write(strat->P.p2,strat->tailRing);
     3187    p_Write(strat->P.sig,currRing);
     3188    #endif
     3189    /* reduction of the element chosen from L */
     3190    // We do not delete via RewCrit strong pairs or extended spolys over rings
     3191    // these should have .lcm = NULL
     3192    if (strat->P.lcm == NULL || !strat->rewCrit2(strat->P.sig, ~strat->P.sevSig, strat->P.GetLmCurrRing(), strat, strat->P.checked+1)) {
     3193      //#if 1
     3194#ifdef DEBUGF5
     3195      Print("SIG OF NEXT PAIR TO HANDLE IN SIG-BASED ALGORITHM\n");
     3196      Print("-------------------------------------------------\n");
     3197      pWrite(strat->P.sig);
     3198      pWrite(pHead(strat->P.p));
     3199      pWrite(pHead(strat->P.p1));
     3200      pWrite(pHead(strat->P.p2));
     3201      Print("-------------------------------------------------\n");
     3202#endif
     3203      if (pNext(strat->P.p) == strat->tail)
     3204      {
     3205        // deletes the short spoly
     3206        /*
     3207        if (rField_is_Ring(currRing))
     3208          pLmDelete(strat->P.p);
     3209        else
     3210          pLmFree(strat->P.p);
     3211*/
     3212          // TODO: needs some masking
     3213          // TODO: masking needs to vanish once the signature
     3214          //       sutff is completely implemented
     3215          strat->P.p = NULL;
     3216        poly m1 = NULL, m2 = NULL;
     3217
     3218        // check that spoly creation is ok
     3219        while (strat->tailRing != currRing &&
     3220            !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
     3221        {
     3222          assume(m1 == NULL && m2 == NULL);
     3223          // if not, change to a ring where exponents are at least
     3224          // large enough
     3225          if (!kStratChangeTailRing(strat))
     3226          {
     3227            WerrorS("OVERFLOW...");
     3228            break;
     3229          }
     3230        }
     3231        // create the real one
     3232        ksCreateSpoly(&(strat->P), NULL, strat->use_buckets,
     3233            strat->tailRing, m1, m2, strat->R);
     3234
     3235      }
     3236      else if (strat->P.p1 == NULL)
     3237      {
     3238        if (strat->minim > 0)
     3239          strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
     3240        // for input polys, prepare reduction
     3241        if(!rField_is_Ring(currRing))
     3242          strat->P.PrepareRed(strat->use_buckets);
     3243      }
     3244      if (strat->P.p == NULL && strat->P.t_p == NULL)
     3245      {
     3246        red_result = 0;
     3247      }
     3248      else
     3249      {
     3250        //#if 1
     3251#ifdef DEBUGF5
     3252        Print("Poly before red: ");
     3253        pWrite(pHead(strat->P.p));
     3254        pWrite(strat->P.sig);
     3255#endif
     3256#if SBA_PRODUCT_CRITERION
     3257        if (strat->P.prod_crit) {
     3258#if SBA_PRINT_PRODUCT_CRITERION
     3259          product_criterion++;
     3260#endif
     3261          int pos = posInSyz(strat, strat->P.sig);
     3262          enterSyz(strat->P, strat, pos);
     3263          if (strat->P.lcm!=NULL)
     3264            pLmFree(strat->P.lcm);
     3265          red_result = 2;
     3266        } else {
     3267          red_result = strat->red(&strat->P,strat);
     3268        }
     3269#else
     3270        red_result = strat->red(&strat->P,strat);
     3271#endif
     3272      }
     3273    } else {
     3274      /*
     3275      if (strat->P.lcm != NULL)
     3276        pLmFree(strat->P.lcm);
     3277        */
     3278      red_result = 2;
     3279    }
     3280    if(rField_is_Ring(currRing))
     3281    {
     3282      if(strat->P.sig!= NULL && !nGreaterZero(pGetCoeff(strat->P.sig)))
     3283      {
     3284        strat->P.p = pNeg(strat->P.p);
     3285        strat->P.sig = pNeg(strat->P.sig);
     3286      }
     3287      strat->P.pLength = pLength(strat->P.p);
     3288      if(strat->P.sig != NULL)
     3289        strat->P.sevSig = pGetShortExpVector(strat->P.sig);
     3290      if(strat->P.p != NULL)
     3291        strat->P.sev = pGetShortExpVector(strat->P.p);
     3292    }
     3293    #ifdef ADIDEBUG
     3294    printf("\nAfter reduce (redresult=%i): \n",red_result);pWrite(strat->P.p);pWrite(strat->P.sig);
     3295    #endif
     3296    //sigdrop case
     3297    if(rField_is_Ring(currRing) && strat->sigdrop)
     3298    {
     3299      //First reduce it as much as one can
     3300      #ifdef ADIDEBUG
     3301      printf("\nSigdrop in the reduce. Trying redring\n");
     3302      #endif
     3303      red_result = redRing(&strat->P,strat);
     3304      if(red_result == 0)
     3305      {
     3306        #ifdef ADIDEBUG
     3307        printf("\nSigdrop cancelled since redRing reduced to 0\n");
     3308        #endif
     3309        strat->sigdrop = FALSE;
     3310        pDelete(&strat->P.sig);
     3311        strat->P.sig = NULL;
     3312      }
     3313      else
     3314      {
     3315        #ifdef ADIDEBUG
     3316        printf("\nStill Sigdrop - redRing reduced to:\n");pWrite(strat->P.p);
     3317        #endif
     3318        strat->enterS(strat->P, 0, strat, strat->tl);
     3319        if (TEST_OPT_PROT)
     3320          PrintS("-");
     3321        break;
     3322      }
     3323    }
     3324    if(rField_is_Ring(currRing) && strat->blockred > strat->blockredmax)
     3325    {
     3326      #ifdef ADIDEBUG
     3327      printf("\nToo many blocked reductions\n");
     3328      #endif
     3329      strat->sigdrop = TRUE;
     3330      break;
     3331    }
     3332   
     3333    if (errorreported)  break;
     3334
     3335//#if 1
     3336#ifdef DEBUGF5
     3337    if (red_result != 0) {
     3338        Print("Poly after red: ");
     3339        pWrite(pHead(strat->P.p));
     3340        pWrite(strat->P.GetLmCurrRing());
     3341        pWrite(strat->P.sig);
     3342        printf("%d\n",red_result);
     3343    }
     3344#endif
     3345    if (TEST_OPT_PROT)
     3346    {
     3347      if(strat->P.p != NULL)
     3348        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
     3349                &olddeg,&reduc,strat, red_result);
     3350      else
     3351        message((strat->honey ? strat->P.ecart : 0),
     3352                &olddeg,&reduc,strat, red_result);
     3353    }
     3354
     3355    if (strat->overflow)
     3356    {
     3357        if (!kStratChangeTailRing(strat)) { Werror("OVERFLOW.."); break;}
     3358    }
     3359    // reduction to non-zero new poly
     3360    if (red_result == 1)
     3361    {
     3362      // get the polynomial (canonicalize bucket, make sure P.p is set)
     3363      strat->P.GetP(strat->lmBin);
     3364
     3365      // sig-safe computations may lead to wrong FDeg computation, thus we need
     3366      // to recompute it to make sure everything is alright
     3367      (strat->P).FDeg = (strat->P).pFDeg();
     3368      // in the homogeneous case FDeg >= pFDeg (sugar/honey)
     3369      // but now, for entering S, T, we reset it
     3370      // in the inhomogeneous case: FDeg == pFDeg
     3371      if (strat->homog) strat->initEcart(&(strat->P));
     3372
     3373      /* statistic */
     3374      if (TEST_OPT_PROT) PrintS("s");
     3375
     3376      //int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
     3377      // in F5E we know that the last reduced element is already the
     3378      // the one with highest signature
     3379      int pos = strat->sl+1;
     3380
     3381      // reduce the tail and normalize poly
     3382      // in the ring case we cannot expect LC(f) = 1,
     3383      // therefore we call pContent instead of pNorm
     3384      #ifdef HAVE_RINGS
     3385      poly beforetailred;
     3386      if(rField_is_Ring(currRing))
     3387        beforetailred = pCopy(strat->P.sig);
     3388      #endif
     3389#if SBA_TAIL_RED
     3390      if(rField_is_Ring(currRing))
     3391      { 
     3392        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
     3393          strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
     3394      }
     3395      else
     3396      {
     3397        if (strat->sbaOrder != 2) {
     3398          if (TEST_OPT_INTSTRATEGY)
     3399          {
     3400            strat->P.pCleardenom();
     3401            if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
     3402            {
     3403              strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
     3404              strat->P.pCleardenom();
     3405            }
     3406          }
     3407          else
     3408          {
     3409            strat->P.pNorm();
     3410            if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
     3411              strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
     3412          }
     3413        }
     3414      }
     3415      // It may happen that we have lost the sig in redtailsba
     3416      // It cannot reduce to 0 since here we are doing just tail reduction.
     3417      // Best case scenerio: remains the leading term
     3418      if(rField_is_Ring(currRing) && strat->sigdrop)     
     3419      {
     3420        #ifdef ADIDEBUG
     3421        printf("\n Still sigdrop after redtailSba - it reduced to \n");pWrite(strat->P.p);
     3422        #endif
     3423        strat->enterS(strat->P, 0, strat, strat->tl);
     3424        break;
     3425      }
     3426#endif
     3427    if(rField_is_Ring(currRing))
     3428    {
     3429      if(strat->P.sig == NULL || pLtCmp(beforetailred,strat->P.sig) == 1)
     3430      {
     3431        #ifdef ADIDEBUG
     3432        printf("\nSigDrop after TAILred\n");pWrite(beforetailred);pWrite(strat->P.sig);
     3433        #endif
     3434        strat->sigdrop = TRUE;
     3435        //Reduce it as much as you can
     3436        red_result = redRing(&strat->P,strat);
     3437        if(red_result == 0)
     3438        {
     3439          //It reduced to 0, cancel the sigdrop
     3440          #ifdef ADIDEBUG
     3441          printf("\nReduced to 0 via redRing. Cancel sigdrop\n");
     3442          #endif
     3443          strat->sigdrop = FALSE;
     3444          p_Delete(&strat->P.sig,currRing);strat->P.sig = NULL;
     3445        }
     3446        else
     3447        {
     3448          #ifdef ADIDEBUG
     3449          printf("\nReduced to this via redRing.SIGDROP\n");pWrite(strat->P.p);
     3450          #endif
     3451          strat->enterS(strat->P, 0, strat, strat->tl);
     3452          break;
     3453        }
     3454      }
     3455      p_Delete(&beforetailred,currRing);
     3456      // strat->P.p = NULL may appear if we had  a sigdrop above and reduced to 0 via redRing
     3457      if(strat->P.p == NULL)
     3458        goto case_when_red_result_changed;
     3459    }
     3460    #ifdef ADIDEBUG
     3461    printf("\nNach redTailSba: \n");
     3462    p_Write(strat->P.p,strat->tailRing);p_Write(strat->P.sig,currRing);
     3463    #endif
     3464    // remove sigsafe label since it is no longer valid for the next element to
     3465    // be reduced
     3466    if (strat->sbaOrder == 1)
     3467    {
     3468      for (int jj = 0; jj<strat->tl+1; jj++)
     3469      {
     3470        if (pGetComp(strat->T[jj].sig) == strat->currIdx)
     3471        {
     3472          strat->T[jj].is_sigsafe = FALSE;
     3473        }
     3474      }
     3475    }
     3476    else
     3477    {
     3478      for (int jj = 0; jj<strat->tl+1; jj++)
     3479      {
     3480        strat->T[jj].is_sigsafe = FALSE;
     3481      }
     3482    }
     3483#ifdef KDEBUG
     3484      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
     3485#endif /* KDEBUG */
     3486
     3487      // min_std stuff
     3488      if ((strat->P.p1==NULL) && (strat->minim>0))
     3489      {
     3490        if (strat->minim==1)
     3491        {
     3492          strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
     3493          p_Delete(&strat->P.p2, currRing, strat->tailRing);
     3494        }
     3495        else
     3496        {
     3497          strat->M->m[minimcnt]=strat->P.p2;
     3498          strat->P.p2=NULL;
     3499        }
     3500        if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
     3501          pNext(strat->M->m[minimcnt])
     3502            = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
     3503                                           strat->tailRing, currRing,
     3504                                           currRing->PolyBin);
     3505        minimcnt++;
     3506      }
     3507
     3508      // enter into S, L, and T
     3509      //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
     3510      enterT(strat->P, strat);
     3511      strat->T[strat->tl].is_sigsafe = FALSE;
     3512      /*
     3513      printf("hier\n");
     3514      pWrite(strat->P.GetLmCurrRing());
     3515      pWrite(strat->P.sig);
     3516      */
     3517      if (rField_is_Ring(currRing))
     3518        superenterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
     3519      else
     3520        enterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
     3521      #ifdef ADIDEBUG
     3522        printf("\nThis element is added to S\n");
     3523        p_Write(strat->P.p, strat->tailRing);p_Write(strat->P.p1, strat->tailRing);p_Write(strat->P.p2, strat->tailRing);pWrite(strat->P.sig);
     3524        //getchar();
     3525        #endif
     3526      if(rField_is_Ring(currRing) && strat->sigdrop)
     3527        break;
     3528      if(rField_is_Ring(currRing))
     3529        strat->P.sevSig = p_GetShortExpVector(strat->P.sig,currRing);
     3530      strat->enterS(strat->P, pos, strat, strat->tl);
     3531      if(strat->sbaOrder != 1)
     3532      {
     3533        BOOLEAN overwrite = FALSE;
     3534        for (int tk=0; tk<strat->sl+1; tk++)
     3535        {
     3536          if (pGetComp(strat->sig[tk]) == pGetComp(strat->P.sig))
     3537          {
     3538            //printf("TK %d / %d\n",tk,strat->sl);
     3539            overwrite = FALSE;
     3540            break;
     3541          }
     3542        }
     3543        //printf("OVERWRITE %d\n",overwrite);
     3544        if (overwrite)
     3545        {
     3546          int cmp = pGetComp(strat->P.sig);
     3547          int* vv = (int*)omAlloc((currRing->N+1)*sizeof(int));
     3548          pGetExpV (strat->P.p,vv);
     3549          pSetExpV (strat->P.sig, vv);
     3550          pSetComp (strat->P.sig,cmp);
     3551
     3552          strat->P.sevSig = pGetShortExpVector (strat->P.sig);
     3553          int i;
     3554          LObject Q;
     3555          for(int ps=0;ps<strat->sl+1;ps++)
     3556          {
     3557
     3558            strat->newt = TRUE;
     3559            if (strat->syzl == strat->syzmax)
     3560            {
     3561              pEnlargeSet(&strat->syz,strat->syzmax,setmaxTinc);
     3562              strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
     3563                  (strat->syzmax)*sizeof(unsigned long),
     3564                  ((strat->syzmax)+setmaxTinc)
     3565                  *sizeof(unsigned long));
     3566              strat->syzmax += setmaxTinc;
     3567            }
     3568            Q.sig = pCopy(strat->P.sig);
     3569            // add LM(F->m[i]) to the signature to get a Schreyer order
     3570            // without changing the underlying polynomial ring at all
     3571            if (strat->sbaOrder == 0)
     3572              p_ExpVectorAdd (Q.sig,strat->S[ps],currRing);
     3573            // since p_Add_q() destroys all input
     3574            // data we need to recreate help
     3575            // each time
     3576            // ----------------------------------------------------------
     3577            // in the Schreyer order we always know that the multiplied
     3578            // module monomial strat->P.sig gives the leading monomial of
     3579            // the corresponding principal syzygy
     3580            // => we do not need to compute the "real" syzygy completely
     3581            poly help = p_Copy(strat->sig[ps],currRing);
     3582            p_ExpVectorAdd (help,strat->P.p,currRing);
     3583            Q.sig = p_Add_q(Q.sig,help,currRing);
     3584            //printf("%d. SYZ  ",i+1);
     3585            //pWrite(strat->syz[i]);
     3586            Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
     3587            i = posInSyz(strat, Q.sig);
     3588            enterSyz(Q, strat, i);
     3589          }
     3590        }
     3591      }
     3592      // deg - idx - lp/rp
     3593      // => we need to add syzygies with indices > pGetComp(strat->P.sig)
     3594      if(strat->sbaOrder == 0 || strat->sbaOrder == 3)
     3595      {
     3596        int cmp     = pGetComp(strat->P.sig);
     3597        int max_cmp = IDELEMS(F);
     3598        int* vv = (int*)omAlloc((currRing->N+1)*sizeof(int));
     3599        pGetExpV (strat->P.p,vv);
     3600        LObject Q;
     3601        int pos;
     3602        int idx = p_GetComp(strat->P.sig,currRing);
     3603        //printf("++ -- adding syzygies -- ++\n");
     3604        // if new element is the first one in this index
     3605        if (strat->currIdx < idx) {
     3606          for (int i=0; i<strat->sl; ++i) {
     3607            Q.sig = p_Copy(strat->P.sig,currRing);
     3608            p_ExpVectorAdd(Q.sig,strat->S[i],currRing);
     3609            poly help = p_Copy(strat->sig[i],currRing);
     3610            p_ExpVectorAdd(help,strat->P.p,currRing);
     3611            Q.sig = p_Add_q(Q.sig,help,currRing);
     3612            //pWrite(Q.sig);
     3613            pos = posInSyz(strat, Q.sig);
     3614            enterSyz(Q, strat, pos);
     3615          }
     3616          strat->currIdx = idx;
     3617        } else {
     3618          // if the element is not the first one in the given index we build all
     3619          // possible syzygies with elements of higher index
     3620          for (int i=cmp+1; i<=max_cmp; ++i) {
     3621            pos = -1;
     3622            for (int j=0; j<strat->sl; ++j) {
     3623              if (p_GetComp(strat->sig[j],currRing) == i) {
     3624                pos = j;
     3625                break;
     3626              }
     3627            }
     3628            if (pos != -1) {
     3629              Q.sig = p_One(currRing);
     3630              p_SetExpV(Q.sig, vv, currRing);
     3631              // F->m[i-1] corresponds to index i
     3632              p_ExpVectorAdd(Q.sig,F->m[i-1],currRing);
     3633              p_SetComp(Q.sig, i, currRing);
     3634              poly help = p_Copy(strat->P.sig,currRing);
     3635              p_ExpVectorAdd(help,strat->S[pos],currRing);
     3636              Q.sig = p_Add_q(Q.sig,help,currRing);
     3637              if (strat->sbaOrder == 0) {
     3638                if (p_LmCmp(Q.sig,strat->syz[strat->syzl-1],currRing) == -currRing->OrdSgn) {
     3639                  pos = posInSyz(strat, Q.sig);
     3640                  enterSyz(Q, strat, pos);
     3641                }
     3642              } else {
     3643                pos = posInSyz(strat, Q.sig);
     3644                enterSyz(Q, strat, pos);
     3645              }
     3646            }
     3647          }
     3648          //printf("++ -- done adding syzygies -- ++\n");
     3649        }
     3650      }
     3651//#if 1
     3652#if DEBUGF50
     3653    printf("---------------------------\n");
     3654    Print(" %d. ELEMENT ADDED TO GCURR:\n",strat->sl+1);
     3655    Print("LEAD POLY:  "); pWrite(pHead(strat->S[strat->sl]));
     3656    Print("SIGNATURE:  "); pWrite(strat->sig[strat->sl]);
     3657#endif
     3658      /*
     3659      if (newrules)
     3660      {
     3661        newrules  = FALSE;
     3662      }
     3663      */
     3664#if 0
     3665      int pl=pLength(strat->P.p);
     3666      if (pl==1)
     3667      {
     3668        //if (TEST_OPT_PROT)
     3669        //PrintS("<1>");
     3670      }
     3671      else if (pl==2)
     3672      {
     3673        //if (TEST_OPT_PROT)
     3674        //PrintS("<2>");
     3675      }
     3676#endif
     3677      if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
     3678//      Print("[%d]",hilbeledeg);
     3679      if (strat->P.lcm!=NULL)
     3680#ifdef HAVE_RINGS
     3681        pLmDelete(strat->P.lcm);
     3682#else
     3683        pLmFree(strat->P.lcm);
     3684#endif
     3685      if (strat->sl>srmax) srmax = strat->sl;
     3686    }
     3687    else
     3688    {
    28223689      case_when_red_result_changed:
    28233690      // adds signature of the zero reduction to
     
    29353802#endif
    29363803 
    2937   idTest(strat->Shdl);
    29383804  // I have to add the initial input polynomials which where not used (p1 and p2 = NULL)
    29393805  #ifdef HAVE_RINGS
     
    29553821    //  {printf("\nS[%i] = %p\n",kk,strat->Shdl->m[kk]);pWrite(strat->Shdl->m[kk]);}
    29563822    //idPrint(strat->Shdl);
    2957   idTest(strat->Shdl);
    29583823    //printf("\nk = %i\n",k);
    29593824    for(;k>=0 && strat->L[k].p1 == NULL && strat->L[k].p2 == NULL;k--)
     
    29803845  //idSkipZeroes(strat->Shdl);
    29813846  //idPrint(strat->Shdl);
    2982   idTest(strat->Shdl);
    29833847 
    29843848  if ((strat->sbaOrder == 1 || strat->sbaOrder == 3) && sRing!=currRingOld)
  • kernel/GBEngine/kutil.cc

    ref2729 re40da9f  
    23812381#else
    23822382void enterOnePairSig (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
     2383#endif
     2384{
     2385  assume(i<=strat->sl);
     2386
     2387  int      l;
     2388  poly m1 = NULL,m2 = NULL; // we need the multipliers for the s-polynomial to compute
     2389              // the corresponding signatures for criteria checks
     2390  LObject  Lp;
     2391  poly pSigMult = p_Copy(pSig,currRing);
     2392  poly sSigMult = p_Copy(strat->sig[i],currRing);
     2393  unsigned long pSigMultNegSev,sSigMultNegSev;
     2394  Lp.i_r = -1;
     2395
     2396#ifdef KDEBUG
     2397  Lp.ecart=0; Lp.length=0;
     2398#endif
     2399  /*- computes the lcm(s[i],p) -*/
     2400  Lp.lcm = pInit();
     2401  k_GetLeadTerms(p,strat->S[i],currRing,m1,m2,currRing);
     2402#ifndef HAVE_RATGRING
     2403  pLcm(p,strat->S[i],Lp.lcm);
     2404#elif defined(HAVE_RATGRING)
     2405  //  if (rIsRatGRing(currRing))
     2406  pLcmRat(p,strat->S[i],Lp.lcm, currRing->real_var_start); // int rat_shift
     2407#endif
     2408  pSetm(Lp.lcm);
     2409
     2410  // set coeffs of multipliers m1 and m2
     2411  pSetCoeff0(m1, nInit(1));
     2412  pSetCoeff0(m2, nInit(1));
     2413//#if 1
     2414#ifdef DEBUGF5
     2415  Print("P1  ");
     2416  pWrite(pHead(p));
     2417  Print("P2  ");
     2418  pWrite(pHead(strat->S[i]));
     2419  Print("M1  ");
     2420  pWrite(m1);
     2421  Print("M2  ");
     2422  pWrite(m2);
     2423#endif
     2424  // get multiplied signatures for testing
     2425  pSigMult = currRing->p_Procs->pp_Mult_mm(pSigMult,m1,currRing);
     2426  pSigMultNegSev = ~p_GetShortExpVector(pSigMult,currRing);
     2427  sSigMult = currRing->p_Procs->pp_Mult_mm(sSigMult,m2,currRing);
     2428  sSigMultNegSev = ~p_GetShortExpVector(sSigMult,currRing);
     2429
     2430//#if 1
     2431#ifdef DEBUGF5
     2432  Print("----------------\n");
     2433  pWrite(pSigMult);
     2434  pWrite(sSigMult);
     2435  Print("----------------\n");
     2436  Lp.checked  = 0;
     2437#endif
     2438  int sigCmp = p_LmCmp(pSigMult,sSigMult,currRing);
     2439//#if 1
     2440#if DEBUGF5
     2441  Print("IN PAIR GENERATION - COMPARING SIGS: %d\n",sigCmp);
     2442  pWrite(pSigMult);
     2443  pWrite(sSigMult);
     2444#endif
     2445  if(sigCmp==0)
     2446  {
     2447    // printf("!!!!   EQUAL SIGS   !!!!\n");
     2448    // pSig = sSig, delete element due to Rewritten Criterion
     2449    pDelete(&pSigMult);
     2450    pDelete(&sSigMult);
     2451    if (rField_is_Ring(currRing))
     2452      pLmDelete(Lp.lcm);
     2453    else
     2454      pLmFree(Lp.lcm);
     2455    Lp.lcm=NULL;
     2456    pDelete (&m1);
     2457    pDelete (&m2);
     2458    return;
     2459  }
     2460  // testing by syzCrit = F5 Criterion
     2461  // testing by rewCrit1 = Rewritten Criterion
     2462  // NOTE: Arri's Rewritten Criterion is tested below, we need Lp.p for it!
     2463  if  ( strat->syzCrit(pSigMult,pSigMultNegSev,strat) ||
     2464        strat->syzCrit(sSigMult,sSigMultNegSev,strat)
     2465        || strat->rewCrit1(sSigMult,sSigMultNegSev,Lp.lcm,strat,i+1)
     2466      )
     2467  {
     2468    pDelete(&pSigMult);
     2469    pDelete(&sSigMult);
     2470    if (rField_is_Ring(currRing))
     2471      pLmDelete(Lp.lcm);
     2472    else
     2473      pLmFree(Lp.lcm);
     2474    Lp.lcm=NULL;
     2475    pDelete (&m1);
     2476    pDelete (&m2);
     2477    return;
     2478  }
     2479  /*
     2480  *the pair (S[i],p) enters B if the spoly != 0
     2481  */
     2482  /*-  compute the short s-polynomial -*/
     2483  if (strat->fromT && !TEST_OPT_INTSTRATEGY)
     2484    pNorm(p);
     2485
     2486  if ((strat->S[i]==NULL) || (p==NULL))
     2487    return;
     2488
     2489  if ((strat->fromQ!=NULL) && (isFromQ!=0) && (strat->fromQ[i]!=0))
     2490    Lp.p=NULL;
     2491  else
     2492  {
     2493    #ifdef HAVE_PLURAL
     2494    if ( rIsPluralRing(currRing) )
     2495    {
     2496      if(pHasNotCF(p, strat->S[i]))
     2497      {
     2498        if(ncRingType(currRing) == nc_lie)
     2499        {
     2500          // generalized prod-crit for lie-type
     2501          strat->cp++;
     2502          Lp.p = nc_p_Bracket_qq(pCopy(p),strat->S[i], currRing);
     2503        }
     2504        else
     2505        if( ALLOW_PROD_CRIT(strat) )
     2506        {
     2507          // product criterion for homogeneous case in SCA
     2508          strat->cp++;
     2509          Lp.p = NULL;
     2510        }
     2511        else
     2512        {
     2513          Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
     2514                nc_CreateShortSpoly(strat->S[i], p, currRing);
     2515
     2516          assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
     2517          pNext(Lp.p) = strat->tail; // !!!
     2518        }
     2519      }
     2520      else
     2521      {
     2522        Lp.p = // nc_CreateSpoly(strat->S[i],p,currRing);
     2523              nc_CreateShortSpoly(strat->S[i], p, currRing);
     2524
     2525        assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
     2526        pNext(Lp.p) = strat->tail; // !!!
     2527      }
     2528    }
     2529    else
     2530    #endif
     2531    {
     2532      assume(!rIsPluralRing(currRing));
     2533      Lp.p = ksCreateShortSpoly(strat->S[i], p, strat->tailRing);
     2534    }
     2535  }
     2536  // store from which element this pair comes from for further tests
     2537  //Lp.from = strat->sl+1;
     2538  if(sigCmp==currRing->OrdSgn)
     2539  {
     2540    // pSig > sSig
     2541    pDelete (&sSigMult);
     2542    Lp.sig    = pSigMult;
     2543    Lp.sevSig = ~pSigMultNegSev;
     2544  }
     2545  else
     2546  {
     2547    // pSig < sSig
     2548    pDelete (&pSigMult);
     2549    Lp.sig    = sSigMult;
     2550    Lp.sevSig = ~sSigMultNegSev;
     2551  }
     2552  if (Lp.p == NULL)
     2553  {
     2554    if (Lp.lcm!=NULL) pLmFree(Lp.lcm);
     2555    int pos = posInSyz(strat, Lp.sig);
     2556    enterSyz(Lp, strat, pos);
     2557  }
     2558  else
     2559  {
     2560    // testing by rewCrit3 = Arris Rewritten Criterion (for F5 nothing happens!)
     2561    if (strat->rewCrit3(Lp.sig,~Lp.sevSig,Lp.p,strat,strat->sl+1))
     2562    {
     2563      pLmFree(Lp.lcm);
     2564      pDelete(&Lp.sig);
     2565      Lp.lcm=NULL;
     2566      pDelete (&m1);
     2567      pDelete (&m2);
     2568      return;
     2569    }
     2570    // in any case Lp is checked up to the next strat->P which is added
     2571    // to S right after this critical pair creation.
     2572    // NOTE: this even holds if the 2nd generator gives the bigger signature
     2573    //       moreover, this improves rewCriterion,
     2574    //       i.e. strat->checked > strat->from if and only if the 2nd generator
     2575    //       gives the bigger signature.
     2576    Lp.checked = strat->sl+1;
     2577    // at this point it is clear that the pair will be added to L, since it has
     2578    // passed all tests up to now
     2579
     2580  // adds buchberger's first criterion
     2581    if (pLmCmp(m2,pHead(p)) == 0)
     2582    {
     2583      Lp.prod_crit = TRUE; // Product Criterion
     2584#if 0
     2585      int pos = posInSyz(strat, Lp.sig);
     2586      enterSyz(Lp, strat, pos);
     2587      Lp.lcm=NULL;
     2588      pDelete (&m1);
     2589      pDelete (&m2);
     2590      return;
     2591#endif
     2592    }
     2593    pDelete (&m1);
     2594    pDelete (&m2);
     2595#if DEBUGF5
     2596    PrintS("SIGNATURE OF PAIR:  ");
     2597    pWrite(Lp.sig);
     2598#endif
     2599    /*- the pair (S[i],p) enters B -*/
     2600    Lp.p1 = strat->S[i];
     2601    Lp.p2 = p;
     2602
     2603    if (
     2604        (!rIsPluralRing(currRing))
     2605//      ||  (rIsPluralRing(currRing) && (ncRingType(currRing) != nc_lie))
     2606       )
     2607    {
     2608      assume(pNext(Lp.p)==NULL); // TODO: this may be violated whenever ext.prod.crit. for Lie alg. is used
     2609      pNext(Lp.p) = strat->tail; // !!!
     2610    }
     2611
     2612    if (atR >= 0)
     2613    {
     2614      Lp.i_r1 = strat->S_2_R[i];
     2615      Lp.i_r2 = atR;
     2616    }
     2617    else
     2618    {
     2619      Lp.i_r1 = -1;
     2620      Lp.i_r2 = -1;
     2621    }
     2622    strat->initEcartPair(&Lp,strat->S[i],p,strat->ecartS[i],ecart);
     2623
     2624    if (TEST_OPT_INTSTRATEGY)
     2625    {
     2626      if (!rIsPluralRing(currRing))
     2627        nDelete(&(Lp.p->coef));
     2628    }
     2629
     2630    l = strat->posInLSba(strat->B,strat->Bl,&Lp,strat);
     2631    enterL(&strat->B,&strat->Bl,&strat->Bmax,Lp,l);
     2632  }
     2633}
     2634
     2635
     2636#ifdef DEBUGF5
     2637void enterOnePairSigRing (int i, poly p, poly pSig, int from, int ecart, int isFromQ, kStrategy strat, int atR = -1)
     2638#else
     2639void enterOnePairSigRing (int i, poly p, poly pSig, int, int ecart, int isFromQ, kStrategy strat, int atR = -1)
    23832640#endif
    23842641{
     
    35863843*using signatures <= only for signature-based standard basis algorithms
    35873844*/
     3845
    35883846void initenterpairsSig (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
    35893847{
     
    36003858      if ((isFromQ)&&(strat->fromQ!=NULL))
    36013859      {
    3602         for (j=0; j<=k && !strat->sigdrop; j++)
     3860        for (j=0; j<=k; j++)
    36033861        {
    36043862          if (!strat->fromQ[j])
     
    36133871      {
    36143872        new_pair=TRUE;
    3615         for (j=0; j<=k && !strat->sigdrop; j++)
     3873        for (j=0; j<=k; j++)
    36163874        {
    36173875          enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
     
    36223880    else
    36233881    {
    3624       for (j=0; j<=k && !strat->sigdrop; j++)
     3882      for (j=0; j<=k; j++)
    36253883      {
    36263884        if ((pGetComp(h)==pGetComp(strat->S[j]))
     
    36293887          new_pair=TRUE;
    36303888          enterOnePairSig(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
     3889        //Print("j:%d, Ll:%d\n",j,strat->Ll);
     3890        }
     3891      }
     3892    }
     3893
     3894    if (new_pair)
     3895    {
     3896#ifdef HAVE_RATGRING
     3897      if (currRing->real_var_start>0)
     3898        chainCritPart(h,ecart,strat);
     3899      else
     3900#endif
     3901      strat->chainCrit(h,ecart,strat);
     3902    }
     3903  }
     3904}
     3905
     3906void initenterpairsSigRing (poly h,poly hSig,int hFrom,int k,int ecart,int isFromQ,kStrategy strat, int atR = -1)
     3907{
     3908
     3909  if ((strat->syzComp==0)
     3910  || (pGetComp(h)<=strat->syzComp))
     3911  {
     3912    int j;
     3913    BOOLEAN new_pair=FALSE;
     3914
     3915    if (pGetComp(h)==0)
     3916    {
     3917      /* for Q!=NULL: build pairs (f,q),(f1,f2), but not (q1,q2)*/
     3918      if ((isFromQ)&&(strat->fromQ!=NULL))
     3919      {
     3920        for (j=0; j<=k && !strat->sigdrop; j++)
     3921        {
     3922          if (!strat->fromQ[j])
     3923          {
     3924            new_pair=TRUE;
     3925            enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
     3926          //Print("j:%d, Ll:%d\n",j,strat->Ll);
     3927          }
     3928        }
     3929      }
     3930      else
     3931      {
     3932        new_pair=TRUE;
     3933        for (j=0; j<=k && !strat->sigdrop; j++)
     3934        {
     3935          enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
     3936          //Print("j:%d, Ll:%d\n",j,strat->Ll);
     3937        }
     3938      }
     3939    }
     3940    else
     3941    {
     3942      for (j=0; j<=k && !strat->sigdrop; j++)
     3943      {
     3944        if ((pGetComp(h)==pGetComp(strat->S[j]))
     3945        || (pGetComp(strat->S[j])==0))
     3946        {
     3947          new_pair=TRUE;
     3948          enterOnePairSigRing(j,h,hSig,hFrom,ecart,isFromQ,strat, atR);
    36313949        //Print("j:%d, Ll:%d\n",j,strat->Ll);
    36323950        }
     
    45504868  printf("\n      Trying to add spolys\n");
    45514869  #endif
    4552   initenterpairsSig(h, hSig, hFrom, k, ecart, 0, strat, atR);
     4870  initenterpairsSigRing(h, hSig, hFrom, k, ecart, 0, strat, atR);
    45534871  if(strat->sigdrop) return;
    45544872  #ifdef ADIDEBUG
     
    68607178    pWrite(pHead(strat->S[k]));
    68617179#endif
    6862     if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing)
    6863     && (!rField_is_Ring(currRing) || (n_DivBy(pGetCoeff(sig),pGetCoeff(strat->sig[k]),currRing)  && pLmCmp(sig,strat->sig[k]) == 1 )))
     7180    if (p_LmShortDivisibleBy(strat->sig[k], strat->sevSig[k], sig, not_sevSig, currRing))
    68647181    {
    68657182//#if 1
     
    90519368  #ifdef ADIDEBUG
    90529369  printf("\nenterT: add in position %i\n",atT);
    9053   pWrite(p.p);pWrite(p.sig);
     9370  p_Write(p.p,strat->tailRing);p_Write(p.sig,currRing);
    90549371  #endif
    90559372  //printf("\nenterT: neue hingefÃŒgt: lÀnge = %i, ecart = %i\n",p.length,p.ecart);
  • kernel/GBEngine/kutil.h

    ref2729 re40da9f  
    521521int redHomog (LObject* h,kStrategy strat);
    522522int redSig (LObject* h,kStrategy strat);
     523int redSigRing (LObject* h,kStrategy strat);
    523524//adds hSig to be able to check with F5's criteria when entering pairs!
    524525void enterpairsSig (poly h, poly hSig, int from, int k, int ec, int pos,kStrategy strat, int atR = -1);
     
    577578void enterOnePairLift (int i,poly p,int ecart, int isFromQ,kStrategy strat, int atR);
    578579void enterOnePairSig (int i,poly p,poly pSig,int ecart, int isFromQ,kStrategy strat, int atR);
     580void enterOnePairSigRing (int i,poly p,poly pSig,int ecart, int isFromQ,kStrategy strat, int atR);
    579581void chainCritNormal (poly p,int ecart,kStrategy strat);
    580582void chainCritOpt_1 (poly,int,kStrategy strat);
     
    717719                 number *coef = NULL,
    718720                 kStrategy strat = NULL);
     721                 
     722int ksReducePolySigRing(LObject* PR,
     723                 TObject* PW,
     724                 long idx,
     725                 poly spNoether = NULL,
     726                 number *coef = NULL,
     727                 kStrategy strat = NULL);
    719728
    720729// Reduces PR at Current->next with PW
Note: See TracChangeset for help on using the changeset viewer.