Changeset 7d1e80 in git


Ignore:
Timestamp:
Aug 11, 2016, 4:31:28 PM (8 years ago)
Author:
Adi Popescu <adi_popescum@…>
Branches:
(u'spielwiese', '4a9821a93ffdc22a6696668bd4f6b8c9de3e6c5f')
Children:
9005c821174cb97b8111112064f52487e4ca2220
Parents:
d5d857d04cf9046b2cdd0a2ce1fae1415473c269
Message:
Christians sba fixed
Location:
kernel/GBEngine
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/GBEngine/kstd2.cc

    rd5d857 r7d1e80  
    1010#include <kernel/mod2.h>
    1111
    12 #define ADIDEBUG 1
     12//#define ADIDEBUG 1
    1313#define GCD_SBA 1
    1414
     
    21952195  sba_interreduction_operations = 0;
    21962196#endif
    2197 
     2197 
    21982198  ideal F1 = F0;
    21992199  ring sRing, currRingOld;
     
    22082208    }
    22092209  }
     2210  ideal F;
    22102211  // sort ideal F
    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];
     2212  //Put the SigDrop element on the correct position (think of sbaEnterS)
     2213  //We also sort them
     2214  if(rField_is_Ring(currRing) && strat->sigdrop)
     2215  {
     2216    #if 1
     2217    F = idInit(IDELEMS(F1),F1->rank);
     2218    for (int i=0; i<IDELEMS(F1);++i)
     2219      F->m[i] = F1->m[i];
     2220    if(strat->sbaEnterS >= 0)
     2221    {
     2222      poly dummy;
     2223      dummy = pCopy(F->m[0]); //the sigdrop element
     2224      for(int i = 0;i<strat->sbaEnterS;i++)
     2225        F->m[i] = F->m[i+1];
     2226      F->m[strat->sbaEnterS] = dummy;
     2227    }
     2228    #else
     2229    F = idInit(1,F1->rank);
     2230    //printf("\nBefore the initial block sorting:\n");idPrint(F1);
     2231    F->m[0] = F1->m[0];
     2232    int pos;
     2233    if(strat->sbaEnterS >= 0)
     2234    {
     2235      for(int i=1;i<=strat->sbaEnterS;i++)
     2236      {
     2237        pos = posInIdealMonFirst(F,F1->m[i],1,strat->sbaEnterS);
     2238        idInsertPolyOnPos(F,F1->m[i],pos);
     2239      }
     2240      for(int i=strat->sbaEnterS+1;i<IDELEMS(F1);i++)
     2241      {
     2242        pos = posInIdealMonFirst(F,F1->m[i],strat->sbaEnterS+1,IDELEMS(F));
     2243        idInsertPolyOnPos(F,F1->m[i],pos);
     2244      }
     2245      poly dummy;
     2246      dummy = pCopy(F->m[0]); //the sigdrop element
     2247      for(int i = 0;i<strat->sbaEnterS;i++)
     2248        F->m[i] = F->m[i+1];
     2249      F->m[strat->sbaEnterS] = dummy;
     2250    }
     2251    else
     2252    {
     2253      for(int i=1;i<IDELEMS(F1);i++)
     2254      {
     2255        pos = posInIdealMonFirst(F,F1->m[i],1,IDELEMS(F));
     2256        idInsertPolyOnPos(F,F1->m[i],pos);
     2257      }
     2258    }
     2259    #endif
     2260    //printf("\nAfter the initial block sorting:\n");idPrint(F);getchar();
     2261  }
     2262  else
     2263  {
     2264    F       = idInit(IDELEMS(F1),F1->rank);
     2265    intvec *sort  = idSort(F1);
     2266    for (int i=0; i<sort->length();++i)
     2267      F->m[i] = F1->m[(*sort)[i]-1];
     2268    if(rField_is_Ring(currRing))
     2269    {
     2270      // put the monomials after the sbaEnterS polynomials
     2271      //printf("\nThis is the ideal before sorting (sbaEnterS = %i)\n",strat->sbaEnterS);idPrint(F);
     2272      int nrmon = 0;
     2273      for(int i = IDELEMS(F)-1,j;i>strat->sbaEnterS+nrmon+1 ;i--)
     2274      {
     2275        //pWrite(F->m[i]);
     2276        if(F->m[i] != NULL && pNext(F->m[i]) == NULL)
     2277        {
     2278          poly mon = F->m[i];
     2279          for(j = i;j>strat->sbaEnterS+nrmon+1;j--)
     2280          {
     2281            F->m[j] = F->m[j-1];
     2282          }
     2283          F->m[j] = mon;
     2284          nrmon++;
     2285        }
     2286        //idPrint(F);
     2287      }
     2288    }
     2289  }
     2290    //printf("\nThis is the ideal after sorting\n");idPrint(F);getchar();
     2291  if(rField_is_Ring(currRing))
     2292    strat->sigdrop = FALSE;
     2293  strat->nrsyzcrit = 0;
     2294  strat->nrrewcrit = 0;
    22152295#if SBA_INTERRED_START
    22162296  F = kInterRed(F,NULL);
     
    22222302  printf("\n");
    22232303#endif
    2224 #ifdef KDEBUG
    2225   bba_count++;
    2226   int loop_count = 0;
    2227 #endif /* KDEBUG */
    22282304  int   srmax,lrmax, red_result = 1;
    22292305  int   olddeg,reduc;
     
    22322308  BOOLEAN withT     = TRUE;
    22332309  strat->max_lower_index = 0;
    2234 
    22352310  //initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
    22362311  initSbaCrit(strat); /*set Gebauer, honey, sugarCrit*/
    22372312  initSbaPos(strat);
    2238   //initBuchMoraPos(strat);
    22392313  initHilbCrit(F,Q,&hilb,strat);
    22402314  initSba(F,strat);
    22412315  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
    22422316  /*Shdl=*/initSbaBuchMora(F, Q,strat);
     2317  idTest(strat->Shdl);
    22432318  if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
    22442319  srmax = strat->sl;
    22452320  reduc = olddeg = lrmax = 0;
    2246 
    22472321#ifndef NO_BUCKETS
    22482322  if (!TEST_OPT_NOT_BUCKETS)
     
    22572331  kTest_TS(strat);
    22582332
    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 
    22712333#ifdef HAVE_TAIL_RING
    22722334  if(!idIs0(F) &&(!rField_is_Ring(currRing)))  // create strong gcd poly computes with tailring and S[i] ->to be fixed
     
    22792341    kDebugPrint(strat);
    22802342  }
    2281 
    2282 
     2343  // We add the elements directly in S from the previous loop
     2344  if(rField_is_Ring(currRing) && strat->sbaEnterS >= 0)
     2345  {
     2346    for(int i = 0;i<strat->sbaEnterS;i++)
     2347    {
     2348      //Update: now the element is at the corect place
     2349      //i+1 because on the 0 position is the sigdrop element
     2350      enterT(strat->L[strat->Ll-(i)],strat);
     2351      strat->enterS(strat->L[strat->Ll-(i)], strat->sl+1, strat, strat->tl);
     2352    }
     2353    strat->Ll = strat->Ll - strat->sbaEnterS;
     2354    strat->sbaEnterS = -1;
     2355  }
     2356  kTest_TS(strat);
    22832357#ifdef KDEBUG
    22842358  //kDebugPrint(strat);
     
    22872361  while (strat->Ll >= 0)
    22882362  {
    2289   #ifdef ADIDEBUG
     2363    #ifdef ADIDEBUG
    22902364    printf("\n      ------------------------NEW LOOP\n");
    22912365    printf("\nShdl = \n");
     
    23152389    printf("\n   list   L\n");
    23162390    int iii;
    2317     #if 1
     2391    #if 0
    23182392    for(iii = 0; iii<= strat->Ll; iii++)
    23192393    {
    23202394        printf("\nL[%i]:\n",iii);
    2321         p_Write(strat->L[iii].p, strat->tailRing);
    2322         p_Write(strat->L[iii].p1, strat->tailRing);
    2323         p_Write(strat->L[iii].p2, strat->tailRing);
     2395        p_Write(strat->L[iii].p, currRing);
     2396        p_Write(strat->L[iii].p1, currRing);
     2397        p_Write(strat->L[iii].p2, currRing);
    23242398        p_Write(strat->L[iii].sig, currRing);
    23252399    }
     
    23332407    }
    23342408    #endif
    2335     getchar();
     2409    //getchar();
    23362410    #endif
    23372411    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
    23382412    #ifdef KDEBUG
    2339       loop_count++;
    23402413      if (TEST_OPT_DEBUG) messageSets(strat);
    23412414    #endif
     
    23462419            || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
    23472420    {
     2421
    23482422       //stops computation if
    23492423       // 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
     
    23702444      // initialize new syzygy rules for the next iteration step
    23712445      initSyzRules(strat);
    2372 
    23732446    }
    23742447    /*********************************************************************
     
    23792452    strat->P = strat->L[strat->Ll];
    23802453    strat->Ll--;
    2381     /* reduction of the element choosen from L */
    2382 
     2454   
     2455    if(rField_is_Ring(currRing))
     2456      strat->sbaEnterS = pGetComp(strat->P.sig) - 1;
     2457   
     2458    #ifdef ADIDEBUG
     2459    printf("\n-------------------------\nThis is the current element P\n");
     2460    p_Write(strat->P.p,strat->tailRing);
     2461    p_Write(strat->P.p1,strat->tailRing);
     2462    p_Write(strat->P.p2,strat->tailRing);
     2463    p_Write(strat->P.sig,currRing);
     2464    #endif
     2465    /* reduction of the element chosen from L */
    23832466    if (!strat->rewCrit2(strat->P.sig, ~strat->P.sevSig, strat->P.GetLmCurrRing(), strat, strat->P.checked+1)) {
    23842467      //#if 1
    23852468#ifdef DEBUGF5
    2386       Print("SIG OF NEXT PAIR TO HANDLE IN SIG-BASED ALGORITHM\n");
    2387       Print("-------------------------------------------------\n");
     2469      PrintS("SIG OF NEXT PAIR TO HANDLE IN SIG-BASED ALGORITHM\n");
     2470      PrintS("-------------------------------------------------\n");
    23882471      pWrite(strat->P.sig);
    23892472      pWrite(pHead(strat->P.p));
    23902473      pWrite(pHead(strat->P.p1));
    23912474      pWrite(pHead(strat->P.p2));
    2392       Print("-------------------------------------------------\n");
     2475      PrintS("-------------------------------------------------\n");
    23932476#endif
    23942477      if (pNext(strat->P.p) == strat->tail)
     
    23962479        // deletes the short spoly
    23972480        /*
    2398 #ifdef HAVE_RINGS
    23992481        if (rField_is_Ring(currRing))
    24002482          pLmDelete(strat->P.p);
    24012483        else
    2402 #endif
    24032484          pLmFree(strat->P.p);
    24042485*/
     
    24322513          strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
    24332514        // for input polys, prepare reduction
    2434         strat->P.PrepareRed(strat->use_buckets);
     2515        if(!rField_is_Ring(currRing))
     2516          strat->P.PrepareRed(strat->use_buckets);
    24352517      }
    24362518      if (strat->P.p == NULL && strat->P.t_p == NULL)
     
    24422524        //#if 1
    24432525#ifdef DEBUGF5
    2444         Print("Poly before red: ");
     2526        PrintS("Poly before red: ");
    24452527        pWrite(pHead(strat->P.p));
    24462528        pWrite(strat->P.sig);
     
    24702552      red_result = 2;
    24712553    }
     2554    if(rField_is_Ring(currRing))
     2555    {
     2556      if(strat->P.sig!= NULL && !nGreaterZero(pGetCoeff(strat->P.sig)))
     2557      {
     2558        strat->P.p = pNeg(strat->P.p);
     2559        strat->P.sig = pNeg(strat->P.sig);
     2560      }
     2561      strat->P.pLength = pLength(strat->P.p);
     2562      if(strat->P.sig != NULL)
     2563        strat->P.sevSig = pGetShortExpVector(strat->P.sig);
     2564      if(strat->P.p != NULL)
     2565        strat->P.sev = pGetShortExpVector(strat->P.p);
     2566    }
     2567    #ifdef ADIDEBUG
     2568    printf("\nAfter reduce (redresult=%i): \n",red_result);pWrite(strat->P.p);pWrite(strat->P.sig);
     2569    #endif
     2570    //sigdrop case
     2571    if(rField_is_Ring(currRing) && strat->sigdrop)
     2572    {
     2573      //First reduce it as much as one can
     2574      #ifdef ADIDEBUG
     2575      printf("\nSigdrop in the reduce. Trying redring\n");
     2576      #endif
     2577      red_result = redRing(&strat->P,strat);
     2578      if(red_result == 0)
     2579      {
     2580        #ifdef ADIDEBUG
     2581        printf("\nSigdrop cancelled since redRing reduced to 0\n");
     2582        #endif
     2583        strat->sigdrop = FALSE;
     2584        pDelete(&strat->P.sig);
     2585        strat->P.sig = NULL;
     2586      }
     2587      else
     2588      {
     2589        #ifdef ADIDEBUG
     2590        printf("\nStill Sigdrop - redRing reduced to:\n");pWrite(strat->P.p);
     2591        #endif
     2592        strat->enterS(strat->P, 0, strat, strat->tl);
     2593        if (TEST_OPT_PROT)
     2594          PrintS("-");
     2595        break;
     2596      }
     2597    }
     2598    if(rField_is_Ring(currRing) && strat->blockred > strat->blockredmax)
     2599    {
     2600      #ifdef ADIDEBUG
     2601      printf("\nToo many blocked reductions\n");
     2602      #endif
     2603      strat->sigdrop = TRUE;
     2604      break;
     2605    }
     2606   
    24722607    if (errorreported)  break;
    24732608
     
    24752610#ifdef DEBUGF5
    24762611    if (red_result != 0) {
    2477         Print("Poly after red: ");
     2612        PrintS("Poly after red: ");
    24782613        pWrite(pHead(strat->P.p));
    24792614        pWrite(strat->P.GetLmCurrRing());
     
    24822617    }
    24832618#endif
     2619    if (TEST_OPT_PROT)
     2620    {
     2621      if(strat->P.p != NULL)
     2622        message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
     2623                &olddeg,&reduc,strat, red_result);
     2624      else
     2625        message((strat->honey ? strat->P.ecart : 0),
     2626                &olddeg,&reduc,strat, red_result);
     2627    }
    24842628
    24852629    if (strat->overflow)
    24862630    {
    2487         if (!kStratChangeTailRing(strat)) { Werror("OVERFLOW.."); break;}
    2488     }
    2489 
     2631        if (!kStratChangeTailRing(strat)) { WerrorS("OVERFLOW.."); break;}
     2632    }
    24902633    // reduction to non-zero new poly
    24912634    if (red_result == 1)
     
    25102653      int pos = strat->sl+1;
    25112654
    2512 #ifdef KDEBUG
    2513 #if MYTEST
    2514       PrintS("New S: "); pDebugPrint(strat->P.p); PrintLn();
    2515 #endif /* MYTEST */
    2516 #endif /* KDEBUG */
    2517 
    25182655      // reduce the tail and normalize poly
    25192656      // in the ring case we cannot expect LC(f) = 1,
    25202657      // therefore we call pContent instead of pNorm
     2658      #ifdef HAVE_RINGS
     2659      poly beforetailred;
     2660      if(rField_is_Ring(currRing))
     2661        beforetailred = pCopy(strat->P.sig);
     2662      #endif
    25212663#if SBA_TAIL_RED
    2522       if (strat->sbaOrder != 2) {
    2523         if ((TEST_OPT_INTSTRATEGY) || (rField_is_Ring(currRing)))
    2524         {
    2525           strat->P.pCleardenom();
    2526           if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
     2664      if(rField_is_Ring(currRing))
     2665      { 
     2666        if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
     2667          strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
     2668      }
     2669      else
     2670      {
     2671        if (strat->sbaOrder != 2) {
     2672          if (TEST_OPT_INTSTRATEGY)
    25272673          {
    2528             strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
    25292674            strat->P.pCleardenom();
     2675            if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
     2676            {
     2677              strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
     2678              strat->P.pCleardenom();
     2679            }
    25302680          }
     2681          else
     2682          {
     2683            strat->P.pNorm();
     2684            if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
     2685              strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
     2686          }
     2687        }
     2688      }
     2689      // It may happen that we have lost the sig in redtailsba
     2690      // It cannot reduce to 0 since here we are doing just tail reduction.
     2691      // Best case scenerio: remains the leading term
     2692      if(rField_is_Ring(currRing) && strat->sigdrop)     
     2693      {
     2694        #ifdef ADIDEBUG
     2695        printf("\n Still sigdrop after redtailSba - it reduced to \n");pWrite(strat->P.p);
     2696        #endif
     2697        strat->enterS(strat->P, 0, strat, strat->tl);
     2698        break;
     2699      }
     2700#endif
     2701    if(rField_is_Ring(currRing))
     2702    {
     2703      if(strat->P.sig == NULL || pLtCmp(beforetailred,strat->P.sig) == 1)
     2704      {
     2705        #ifdef ADIDEBUG
     2706        printf("\nSigDrop after TAILred\n");pWrite(beforetailred);pWrite(strat->P.sig);
     2707        #endif
     2708        strat->sigdrop = TRUE;
     2709        //Reduce it as much as you can
     2710        red_result = redRing(&strat->P,strat);
     2711        if(red_result == 0)
     2712        {
     2713          //It reduced to 0, cancel the sigdrop
     2714          #ifdef ADIDEBUG
     2715          printf("\nReduced to 0 via redRing. Cancel sigdrop\n");
     2716          #endif
     2717          strat->sigdrop = FALSE;
     2718          p_Delete(&strat->P.sig,currRing);strat->P.sig = NULL;
    25312719        }
    25322720        else
    25332721        {
    2534           strat->P.pNorm();
    2535           if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
    2536             strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
    2537         }
    2538       }
    2539 #endif
    2540 
     2722          #ifdef ADIDEBUG
     2723          printf("\nReduced to this via redRing.SIGDROP\n");pWrite(strat->P.p);
     2724          #endif
     2725          strat->enterS(strat->P, 0, strat, strat->tl);
     2726          break;
     2727        }
     2728      }
     2729      p_Delete(&beforetailred,currRing);
     2730      // strat->P.p = NULL may appear if we had  a sigdrop above and reduced to 0 via redRing
     2731      if(strat->P.p == NULL)
     2732        goto case_when_red_result_changed;
     2733    }
     2734    #ifdef ADIDEBUG
     2735    printf("\nNach redTailSba: \n");
     2736    p_Write(strat->P.p,strat->tailRing);p_Write(strat->P.sig,currRing);
     2737    #endif
    25412738    // remove sigsafe label since it is no longer valid for the next element to
    25422739    // be reduced
     
    25602757#ifdef KDEBUG
    25612758      if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
    2562 #if MYTEST
    2563 //#if 1
    2564       PrintS("New (reduced) S: "); pDebugPrint(strat->P.p); PrintLn();
    2565 #endif /* MYTEST */
    25662759#endif /* KDEBUG */
    25672760
     
    25962789      pWrite(strat->P.sig);
    25972790      */
    2598 #ifdef HAVE_RINGS
    25992791      if (rField_is_Ring(currRing))
    2600         superenterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat, strat->tl);
     2792        superenterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
    26012793      else
    2602 #endif
    26032794        enterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
    2604       // posInS only depends on the leading term
     2795      #ifdef ADIDEBUG
     2796        printf("\nThis element is added to S\n");
     2797        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);
     2798        //getchar();
     2799        #endif
     2800      if(rField_is_Ring(currRing) && strat->sigdrop)
     2801        break;
     2802      if(rField_is_Ring(currRing))
     2803        strat->P.sevSig = p_GetShortExpVector(strat->P.sig,currRing);
    26052804      strat->enterS(strat->P, pos, strat, strat->tl);
    26062805      if(strat->sbaOrder != 1)
     
    27282927    printf("---------------------------\n");
    27292928    Print(" %d. ELEMENT ADDED TO GCURR:\n",strat->sl+1);
    2730     Print("LEAD POLY:  "); pWrite(pHead(strat->S[strat->sl]));
    2731     Print("SIGNATURE:  "); pWrite(strat->sig[strat->sl]);
    2732 #endif
    2733       /*
    2734       if (newrules)
    2735       {
    2736         newrules  = FALSE;
    2737       }
    2738       */
    2739 #if 0
    2740       int pl=pLength(strat->P.p);
    2741       if (pl==1)
    2742       {
    2743         //if (TEST_OPT_PROT)
    2744         //PrintS("<1>");
    2745       }
    2746       else if (pl==2)
    2747       {
    2748         //if (TEST_OPT_PROT)
    2749         //PrintS("<2>");
    2750       }
    2751 #endif
    2752       if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
    2753 //      Print("[%d]",hilbeledeg);
    2754       if (strat->P.lcm!=NULL)
    2755 #ifdef HAVE_RINGS
    2756         pLmDelete(strat->P.lcm);
    2757 #else
    2758         pLmFree(strat->P.lcm);
    2759 #endif
    2760       if (strat->sl>srmax) srmax = strat->sl;
    2761     }
    2762     else
    2763     {
    2764       // adds signature of the zero reduction to
    2765       // strat->syz. This is the leading term of
    2766       // syzygy and can be used in syzCriterion()
    2767       // the signature is added if and only if the
    2768       // pair was not detected by the rewritten criterion in strat->red = redSig
    2769       if (red_result!=2) {
    2770 #if SBA_PRINT_ZERO_REDUCTIONS
    2771         zeroreductions++;
    2772 #endif
    2773         int pos = posInSyz(strat, strat->P.sig);
    2774         enterSyz(strat->P, strat, pos);
    2775 //#if 1
    2776 #ifdef DEBUGF5
    2777         Print("ADDING STUFF TO SYZ :  ");
    2778         //pWrite(strat->P.p);
    2779         pWrite(strat->P.sig);
    2780 #endif
    2781       }
    2782       if (strat->P.p1 == NULL && strat->minim > 0)
    2783       {
    2784         p_Delete(&strat->P.p2, currRing, strat->tailRing);
    2785       }
    2786     }
    2787 
    2788 #ifdef KDEBUG
    2789     memset(&(strat->P), 0, sizeof(strat->P));
    2790 #endif /* KDEBUG */
    2791     kTest_TS(strat);
    2792   }
    2793 #ifdef KDEBUG
    2794 #if MYTEST
    2795   PrintS("bba finish GB: currRing: "); rWrite(currRing);
    2796 #endif /* MYTEST */
    2797   if (TEST_OPT_DEBUG) messageSets(strat);
    2798 #endif /* KDEBUG */
    2799 
    2800   if (TEST_OPT_SB_1)
    2801   {
    2802     #ifdef HAVE_RINGS
    2803     if(!rField_is_Ring(currRing))
    2804     #endif
    2805     {
    2806         int k=1;
    2807         int j;
    2808         while(k<=strat->sl)
    2809         {
    2810           j=0;
    2811           loop
    2812           {
    2813             if (j>=k) break;
    2814             clearS(strat->S[j],strat->sevS[j],&k,&j,strat);
    2815             j++;
    2816           }
    2817           k++;
    2818         }
    2819     }
    2820   }
    2821 
    2822   /* complete reduction of the standard basis--------- */
    2823   if (TEST_OPT_REDSB)
    2824   {
    2825     completeReduce(strat);
    2826 #ifdef HAVE_TAIL_RING
    2827     if (strat->completeReduce_retry)
    2828     {
    2829       // completeReduce needed larger exponents, retry
    2830       // to reduce with S (instead of T)
    2831       // and in currRing (instead of strat->tailRing)
    2832       cleanT(strat);strat->tailRing=currRing;
    2833       int i;
    2834       for(i=strat->sl;i>=0;i--) strat->S_2_R[i]=-1;
    2835       completeReduce(strat);
    2836     }
    2837 #endif
    2838   }
    2839   else if (TEST_OPT_PROT) PrintLn();
    2840 
    2841 #if SBA_PRINT_SIZE_SYZ
    2842   // that is correct, syzl is counting one too far
    2843   size_syz = strat->syzl;
    2844 #endif
    2845   exitSba(strat);
    2846 //  if (TEST_OPT_WEIGHTM)
    2847 //  {
    2848 //    pRestoreDegProcs(pFDegOld, pLDegOld);
    2849 //    if (ecartWeights)
    2850 //    {
    2851 //      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
    2852 //      ecartWeights=NULL;
    2853 //    }
    2854 //  }
    2855   if (TEST_OPT_PROT) messageStat(hilbcount,strat);
    2856   if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
    2857 
    2858 #ifdef KDEBUG
    2859 #if MYTEST
    2860   PrintS("bba_end: currRing: "); rWrite(currRing);
    2861 #endif /* MYTEST */
    2862 #endif /* KDEBUG */
    2863 #if SBA_PRINT_SIZE_G
    2864   size_g_non_red  = IDELEMS(strat->Shdl);
    2865 #endif
    2866   if ((strat->sbaOrder == 1 || strat->sbaOrder == 3) && sRing!=currRingOld)
    2867   {
    2868     rChangeCurrRing (currRingOld);
    2869     F0          = idrMoveR (F1, sRing, currRing);
    2870     strat->Shdl = idrMoveR_NoSort (strat->Shdl, sRing, currRing);
    2871     rDelete (sRing);
    2872   }
    2873   id_DelDiv(strat->Shdl, currRing);
    2874   idSkipZeroes(strat->Shdl);
    2875   idTest(strat->Shdl);
    2876 
    2877 #if SBA_PRINT_SIZE_G
    2878   size_g   = IDELEMS(strat->Shdl);
    2879 #endif
    2880 #ifdef DEBUGF5
    2881   printf("SIZE OF SHDL: %d\n",IDELEMS(strat->Shdl));
    2882   int oo = 0;
    2883   while (oo<IDELEMS(strat->Shdl))
    2884   {
    2885     printf(" %d.   ",oo+1);
    2886     pWrite(pHead(strat->Shdl->m[oo]));
    2887     oo++;
    2888   }
    2889 #endif
    2890 #if SBA_PRINT_ZERO_REDUCTIONS
    2891   printf("----------------------------------------------------------\n");
    2892   printf("ZERO REDUCTIONS:            %ld\n",zeroreductions);
    2893   zeroreductions  = 0;
    2894 #endif
    2895 #if SBA_PRINT_REDUCTION_STEPS
    2896   printf("----------------------------------------------------------\n");
    2897   printf("S-REDUCTIONS:               %ld\n",sba_reduction_steps);
    2898 #endif
    2899 #if SBA_PRINT_OPERATIONS
    2900   printf("OPERATIONS:                 %ld\n",sba_operations);
    2901 #endif
    2902 #if SBA_PRINT_REDUCTION_STEPS
    2903   printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
    2904   printf("INTERREDUCTIONS:            %ld\n",sba_interreduction_steps);
    2905 #endif
    2906 #if SBA_PRINT_OPERATIONS
    2907   printf("INTERREDUCTION OPERATIONS:  %ld\n",sba_interreduction_operations);
    2908 #endif
    2909 #if SBA_PRINT_REDUCTION_STEPS
    2910   printf("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
    2911   printf("ALL REDUCTIONS:             %ld\n",sba_reduction_steps+sba_interreduction_steps);
    2912   sba_interreduction_steps  = 0;
    2913   sba_reduction_steps       = 0;
    2914 #endif
    2915 #if SBA_PRINT_OPERATIONS
    2916   printf("ALL OPERATIONS:             %ld\n",sba_operations+sba_interreduction_operations);
    2917   sba_interreduction_operations = 0;
    2918   sba_operations                = 0;
    2919 #endif
    2920 #if SBA_PRINT_SIZE_G
    2921   printf("----------------------------------------------------------\n");
    2922   printf("SIZE OF G:                  %d / %d\n",size_g,size_g_non_red);
    2923   size_g          = 0;
    2924   size_g_non_red  = 0;
    2925 #endif
    2926 #if SBA_PRINT_SIZE_SYZ
    2927   printf("SIZE OF SYZ:                %ld\n",size_syz);
    2928   printf("----------------------------------------------------------\n");
    2929   size_syz  = 0;
    2930 #endif
    2931 #if SBA_PRINT_PRODUCT_CRITERION
    2932   printf("PRODUCT CRITERIA:           %ld\n",product_criterion);
    2933   product_criterion = 0;
    2934 #endif
    2935   return (strat->Shdl);
    2936 }
    2937 
    2938 ideal sbaZ (ideal F0, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
    2939 {
    2940   // ring order stuff:
    2941   // in sba we have (until now) two possibilities:
    2942   // 1. an incremental computation w.r.t. (C,monomial order)
    2943   // 2. a (possibly non-incremental) computation w.r.t. the
    2944   //    induced Schreyer order.
    2945   // The corresponding orders are computed in sbaRing(), depending
    2946   // on the flag strat->sbaOrder
    2947 #if SBA_PRINT_ZERO_REDUCTIONS
    2948   long zeroreductions           = 0;
    2949 #endif
    2950 #if SBA_PRINT_PRODUCT_CRITERION
    2951   long product_criterion        = 0;
    2952 #endif
    2953 #if SBA_PRINT_SIZE_G
    2954   int size_g                    = 0;
    2955   int size_g_non_red            = 0;
    2956 #endif
    2957 #if SBA_PRINT_SIZE_SYZ
    2958   long size_syz                 = 0;
    2959 #endif
    2960   // global variable
    2961 #if SBA_PRINT_REDUCTION_STEPS
    2962   sba_reduction_steps           = 0;
    2963   sba_interreduction_steps      = 0;
    2964 #endif
    2965 #if SBA_PRINT_OPERATIONS
    2966   sba_operations                = 0;
    2967   sba_interreduction_operations = 0;
    2968 #endif
    2969  
    2970   ideal F1 = F0;
    2971   ring sRing, currRingOld;
    2972   currRingOld  = currRing;
    2973   if (strat->sbaOrder == 1 || strat->sbaOrder == 3)
    2974   {
    2975     sRing = sbaRing(strat);
    2976     if (sRing!=currRingOld)
    2977     {
    2978       rChangeCurrRing (sRing);
    2979       F1 = idrMoveR (F0, currRingOld, currRing);
    2980     }
    2981   }
    2982   ideal F;
    2983   // sort ideal F
    2984   //Put the SigDrop element on the correct position (think of sbaEnterS)
    2985   //We also sort them
    2986   if(rField_is_Ring(currRing) && strat->sigdrop)
    2987   {
    2988     #if 1
    2989     F = idInit(IDELEMS(F1),F1->rank);
    2990     for (int i=0; i<IDELEMS(F1);++i)
    2991       F->m[i] = F1->m[i];
    2992     if(strat->sbaEnterS >= 0)
    2993     {
    2994       poly dummy;
    2995       dummy = pCopy(F->m[0]); //the sigdrop element
    2996       for(int i = 0;i<strat->sbaEnterS;i++)
    2997         F->m[i] = F->m[i+1];
    2998       F->m[strat->sbaEnterS] = dummy;
    2999     }
    3000     #else
    3001     F = idInit(1,F1->rank);
    3002     //printf("\nBefore the initial block sorting:\n");idPrint(F1);
    3003     F->m[0] = F1->m[0];
    3004     int pos;
    3005     if(strat->sbaEnterS >= 0)
    3006     {
    3007       for(int i=1;i<=strat->sbaEnterS;i++)
    3008       {
    3009         pos = posInIdealMonFirst(F,F1->m[i],1,strat->sbaEnterS);
    3010         idInsertPolyOnPos(F,F1->m[i],pos);
    3011       }
    3012       for(int i=strat->sbaEnterS+1;i<IDELEMS(F1);i++)
    3013       {
    3014         pos = posInIdealMonFirst(F,F1->m[i],strat->sbaEnterS+1,IDELEMS(F));
    3015         idInsertPolyOnPos(F,F1->m[i],pos);
    3016       }
    3017       poly dummy;
    3018       dummy = pCopy(F->m[0]); //the sigdrop element
    3019       for(int i = 0;i<strat->sbaEnterS;i++)
    3020         F->m[i] = F->m[i+1];
    3021       F->m[strat->sbaEnterS] = dummy;
    3022     }
    3023     else
    3024     {
    3025       for(int i=1;i<IDELEMS(F1);i++)
    3026       {
    3027         pos = posInIdealMonFirst(F,F1->m[i],1,IDELEMS(F));
    3028         idInsertPolyOnPos(F,F1->m[i],pos);
    3029       }
    3030     }
    3031     #endif
    3032     //printf("\nAfter the initial block sorting:\n");idPrint(F);getchar();
    3033   }
    3034   else
    3035   {
    3036     F       = idInit(IDELEMS(F1),F1->rank);
    3037     intvec *sort  = idSort(F1);
    3038     for (int i=0; i<sort->length();++i)
    3039       F->m[i] = F1->m[(*sort)[i]-1];
    3040     if(rField_is_Ring(currRing))
    3041     {
    3042       // put the monomials after the sbaEnterS polynomials
    3043       //printf("\nThis is the ideal before sorting (sbaEnterS = %i)\n",strat->sbaEnterS);idPrint(F);
    3044       int nrmon = 0;
    3045       for(int i = IDELEMS(F)-1,j;i>strat->sbaEnterS+nrmon+1 ;i--)
    3046       {
    3047         //pWrite(F->m[i]);
    3048         if(F->m[i] != NULL && pNext(F->m[i]) == NULL)
    3049         {
    3050           poly mon = F->m[i];
    3051           for(j = i;j>strat->sbaEnterS+nrmon+1;j--)
    3052           {
    3053             F->m[j] = F->m[j-1];
    3054           }
    3055           F->m[j] = mon;
    3056           nrmon++;
    3057         }
    3058         //idPrint(F);
    3059       }
    3060     }
    3061   }
    3062     //printf("\nThis is the ideal after sorting\n");idPrint(F);getchar();
    3063   if(rField_is_Ring(currRing))
    3064     strat->sigdrop = FALSE;
    3065   strat->nrsyzcrit = 0;
    3066   strat->nrrewcrit = 0;
    3067 #if SBA_INTERRED_START
    3068   F = kInterRed(F,NULL);
    3069 #endif
    3070 #if F5DEBUG
    3071   printf("SBA COMPUTATIONS DONE IN THE FOLLOWING RING:\n");
    3072   rWrite (currRing);
    3073   printf("ordSgn = %d\n",currRing->OrdSgn);
    3074   printf("\n");
    3075 #endif
    3076   int   srmax,lrmax, red_result = 1;
    3077   int   olddeg,reduc;
    3078   int hilbeledeg=1,hilbcount=0,minimcnt=0;
    3079   LObject L;
    3080   BOOLEAN withT     = TRUE;
    3081   strat->max_lower_index = 0;
    3082   //initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
    3083   initSbaCrit(strat); /*set Gebauer, honey, sugarCrit*/
    3084   initSbaPos(strat);
    3085   initHilbCrit(F,Q,&hilb,strat);
    3086   initSba(F,strat);
    3087   /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
    3088   /*Shdl=*/initSbaBuchMora(F, Q,strat);
    3089   idTest(strat->Shdl);
    3090   if (strat->minim>0) strat->M=idInit(IDELEMS(F),F->rank);
    3091   srmax = strat->sl;
    3092   reduc = olddeg = lrmax = 0;
    3093 #ifndef NO_BUCKETS
    3094   if (!TEST_OPT_NOT_BUCKETS)
    3095     strat->use_buckets = 1;
    3096 #endif
    3097 
    3098   // redtailBBa against T for inhomogenous input
    3099   // if (!TEST_OPT_OLDSTD)
    3100   //   withT = ! strat->homog;
    3101 
    3102   // strat->posInT = posInT_pLength;
    3103   kTest_TS(strat);
    3104 
    3105 #ifdef HAVE_TAIL_RING
    3106   if(!idIs0(F) &&(!rField_is_Ring(currRing)))  // create strong gcd poly computes with tailring and S[i] ->to be fixed
    3107     kStratInitChangeTailRing(strat);
    3108 #endif
    3109   if (BVERBOSE(23))
    3110   {
    3111     if (test_PosInT!=NULL) strat->posInT=test_PosInT;
    3112     if (test_PosInL!=NULL) strat->posInL=test_PosInL;
    3113     kDebugPrint(strat);
    3114   }
    3115   // We add the elements directly in S from the previous loop
    3116   if(rField_is_Ring(currRing) && strat->sbaEnterS >= 0)
    3117   {
    3118     for(int i = 0;i<strat->sbaEnterS;i++)
    3119     {
    3120       //Update: now the element is at the corect place
    3121       //i+1 because on the 0 position is the sigdrop element
    3122       enterT(strat->L[strat->Ll-(i)],strat);
    3123       strat->enterS(strat->L[strat->Ll-(i)], strat->sl+1, strat, strat->tl);
    3124     }
    3125     strat->Ll = strat->Ll - strat->sbaEnterS;
    3126     strat->sbaEnterS = -1;
    3127   }
    3128   kTest_TS(strat);
    3129 #ifdef KDEBUG
    3130   //kDebugPrint(strat);
    3131 #endif
    3132   /* compute------------------------------------------------------- */
    3133   while (strat->Ll >= 0)
    3134   {
    3135     #ifdef ADIDEBUG
    3136     printf("\n      ------------------------NEW LOOP\n");
    3137     printf("\nShdl = \n");
    3138     #if 0
    3139     idPrint(strat->Shdl);
    3140     #else
    3141     for(int ii = 0; ii<=strat->sl;ii++)
    3142     {
    3143       printf("\nS[%i]:  ",ii);p_Write(strat->S[ii],strat->tailRing);
    3144       printf("sig:   ");pWrite(strat->sig[ii]);
    3145     }
    3146     #endif
    3147     #if 0
    3148     for(int iii = 0; iii< strat->syzl; iii++)
    3149     {
    3150         printf("\nsyz[%i]:\n",iii);
    3151         p_Write(strat->syz[iii], currRing);
    3152     }
    3153     #endif
    3154     #if 0
    3155     for(int iii = 0; iii<= strat->tl; iii++)
    3156     {
    3157         printf("\nT[%i]:\n",iii);
    3158         p_Write(strat->T[iii].p, currRing);
    3159     }
    3160     #endif
    3161     printf("\n   list   L\n");
    3162     int iii;
    3163     #if 0
    3164     for(iii = 0; iii<= strat->Ll; iii++)
    3165     {
    3166         printf("\nL[%i]:\n",iii);
    3167         p_Write(strat->L[iii].p, currRing);
    3168         p_Write(strat->L[iii].p1, currRing);
    3169         p_Write(strat->L[iii].p2, currRing);
    3170         p_Write(strat->L[iii].sig, currRing);
    3171     }
    3172     #else
    3173     {
    3174         printf("L[%i]:",strat->Ll);
    3175         p_Write(strat->L[strat->Ll].p, strat->tailRing);
    3176         p_Write(strat->L[strat->Ll].p1, strat->tailRing);
    3177         p_Write(strat->L[strat->Ll].p2, strat->tailRing);
    3178         p_Write(strat->L[strat->Ll].sig, currRing);
    3179     }
    3180     #endif
    3181     //getchar();
    3182     #endif
    3183     if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
    3184     #ifdef KDEBUG
    3185       if (TEST_OPT_DEBUG) messageSets(strat);
    3186     #endif
    3187     if (strat->Ll== 0) strat->interpt=TRUE;
    3188     /*
    3189     if (TEST_OPT_DEGBOUND
    3190         && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
    3191             || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
    3192     {
    3193 
    3194        //stops computation if
    3195        // 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
    3196        //a predefined number Kstd1_deg
    3197       while ((strat->Ll >= 0)
    3198         && (strat->L[strat->Ll].p1!=NULL) && (strat->L[strat->Ll].p2!=NULL)
    3199         && ((strat->honey && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
    3200             || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg)))
    3201         )
    3202         deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
    3203       if (strat->Ll<0) break;
    3204       else strat->noClearS=TRUE;
    3205     }
    3206     */
    3207     if (strat->sbaOrder == 1 && pGetComp(strat->L[strat->Ll].sig) != strat->currIdx)
    3208     {
    3209       strat->currIdx  = pGetComp(strat->L[strat->Ll].sig);
    3210 #if F5C
    3211       // 1. interreduction of the current standard basis
    3212       // 2. generation of new principal syzygy rules for syzCriterion
    3213       f5c ( strat, olddeg, minimcnt, hilbeledeg, hilbcount, srmax,
    3214           lrmax, reduc, Q, w, hilb );
    3215 #endif
    3216       // initialize new syzygy rules for the next iteration step
    3217       initSyzRules(strat);
    3218     }
    3219     /*********************************************************************
    3220       * interrreduction step is done, we can go on with the next iteration
    3221       * step of the signature-based algorithm
    3222       ********************************************************************/
    3223     /* picks the last element from the lazyset L */
    3224     strat->P = strat->L[strat->Ll];
    3225     strat->Ll--;
    3226    
    3227     if(rField_is_Ring(currRing))
    3228       strat->sbaEnterS = pGetComp(strat->P.sig) - 1;
    3229    
    3230     #ifdef ADIDEBUG
    3231     printf("\n-------------------------\nThis is the current element P\n");
    3232     p_Write(strat->P.p,strat->tailRing);
    3233     p_Write(strat->P.p1,strat->tailRing);
    3234     p_Write(strat->P.p2,strat->tailRing);
    3235     p_Write(strat->P.sig,currRing);
    3236     #endif
    3237     /* reduction of the element chosen from L */
    3238     // We do not delete via RewCrit strong pairs or extended spolys over rings
    3239     // these should have .lcm = NULL
    3240     if (strat->P.lcm == NULL || !strat->rewCrit2(strat->P.sig, ~strat->P.sevSig, strat->P.GetLmCurrRing(), strat, strat->P.checked+1)) {
    3241       //#if 1
    3242 #ifdef DEBUGF5
    3243       PrintS("SIG OF NEXT PAIR TO HANDLE IN SIG-BASED ALGORITHM\n");
    3244       PrintS("-------------------------------------------------\n");
    3245       pWrite(strat->P.sig);
    3246       pWrite(pHead(strat->P.p));
    3247       pWrite(pHead(strat->P.p1));
    3248       pWrite(pHead(strat->P.p2));
    3249       PrintS("-------------------------------------------------\n");
    3250 #endif
    3251       if (pNext(strat->P.p) == strat->tail)
    3252       {
    3253         // deletes the short spoly
    3254         /*
    3255         if (rField_is_Ring(currRing))
    3256           pLmDelete(strat->P.p);
    3257         else
    3258           pLmFree(strat->P.p);
    3259 */
    3260           // TODO: needs some masking
    3261           // TODO: masking needs to vanish once the signature
    3262           //       sutff is completely implemented
    3263           strat->P.p = NULL;
    3264         poly m1 = NULL, m2 = NULL;
    3265 
    3266         // check that spoly creation is ok
    3267         while (strat->tailRing != currRing &&
    3268             !kCheckSpolyCreation(&(strat->P), strat, m1, m2))
    3269         {
    3270           assume(m1 == NULL && m2 == NULL);
    3271           // if not, change to a ring where exponents are at least
    3272           // large enough
    3273           if (!kStratChangeTailRing(strat))
    3274           {
    3275             WerrorS("OVERFLOW...");
    3276             break;
    3277           }
    3278         }
    3279         // create the real one
    3280         ksCreateSpoly(&(strat->P), NULL, strat->use_buckets,
    3281             strat->tailRing, m1, m2, strat->R);
    3282 
    3283       }
    3284       else if (strat->P.p1 == NULL)
    3285       {
    3286         if (strat->minim > 0)
    3287           strat->P.p2=p_Copy(strat->P.p, currRing, strat->tailRing);
    3288         // for input polys, prepare reduction
    3289         if(!rField_is_Ring(currRing))
    3290           strat->P.PrepareRed(strat->use_buckets);
    3291       }
    3292       if (strat->P.p == NULL && strat->P.t_p == NULL)
    3293       {
    3294         red_result = 0;
    3295       }
    3296       else
    3297       {
    3298         //#if 1
    3299 #ifdef DEBUGF5
    3300         PrintS("Poly before red: ");
    3301         pWrite(pHead(strat->P.p));
    3302         pWrite(strat->P.sig);
    3303 #endif
    3304 #if SBA_PRODUCT_CRITERION
    3305         if (strat->P.prod_crit) {
    3306 #if SBA_PRINT_PRODUCT_CRITERION
    3307           product_criterion++;
    3308 #endif
    3309           int pos = posInSyz(strat, strat->P.sig);
    3310           enterSyz(strat->P, strat, pos);
    3311           if (strat->P.lcm!=NULL)
    3312             pLmFree(strat->P.lcm);
    3313           red_result = 2;
    3314         } else {
    3315           red_result = strat->red(&strat->P,strat);
    3316         }
    3317 #else
    3318         red_result = strat->red(&strat->P,strat);
    3319 #endif
    3320       }
    3321     } else {
    3322       /*
    3323       if (strat->P.lcm != NULL)
    3324         pLmFree(strat->P.lcm);
    3325         */
    3326       red_result = 2;
    3327     }
    3328     if(rField_is_Ring(currRing))
    3329     {
    3330       if(strat->P.sig!= NULL && !nGreaterZero(pGetCoeff(strat->P.sig)))
    3331       {
    3332         strat->P.p = pNeg(strat->P.p);
    3333         strat->P.sig = pNeg(strat->P.sig);
    3334       }
    3335       strat->P.pLength = pLength(strat->P.p);
    3336       if(strat->P.sig != NULL)
    3337         strat->P.sevSig = pGetShortExpVector(strat->P.sig);
    3338       if(strat->P.p != NULL)
    3339         strat->P.sev = pGetShortExpVector(strat->P.p);
    3340     }
    3341     #ifdef ADIDEBUG
    3342     printf("\nAfter reduce (redresult=%i): \n",red_result);pWrite(strat->P.p);pWrite(strat->P.sig);
    3343     #endif
    3344     //sigdrop case
    3345     if(rField_is_Ring(currRing) && strat->sigdrop)
    3346     {
    3347       //First reduce it as much as one can
    3348       #ifdef ADIDEBUG
    3349       printf("\nSigdrop in the reduce. Trying redring\n");
    3350       #endif
    3351       red_result = redRing(&strat->P,strat);
    3352       if(red_result == 0)
    3353       {
    3354         #ifdef ADIDEBUG
    3355         printf("\nSigdrop cancelled since redRing reduced to 0\n");
    3356         #endif
    3357         strat->sigdrop = FALSE;
    3358         pDelete(&strat->P.sig);
    3359         strat->P.sig = NULL;
    3360       }
    3361       else
    3362       {
    3363         #ifdef ADIDEBUG
    3364         printf("\nStill Sigdrop - redRing reduced to:\n");pWrite(strat->P.p);
    3365         #endif
    3366         strat->enterS(strat->P, 0, strat, strat->tl);
    3367         if (TEST_OPT_PROT)
    3368           PrintS("-");
    3369         break;
    3370       }
    3371     }
    3372     if(rField_is_Ring(currRing) && strat->blockred > strat->blockredmax)
    3373     {
    3374       #ifdef ADIDEBUG
    3375       printf("\nToo many blocked reductions\n");
    3376       #endif
    3377       strat->sigdrop = TRUE;
    3378       break;
    3379     }
    3380    
    3381     if (errorreported)  break;
    3382 
    3383 //#if 1
    3384 #ifdef DEBUGF5
    3385     if (red_result != 0) {
    3386         PrintS("Poly after red: ");
    3387         pWrite(pHead(strat->P.p));
    3388         pWrite(strat->P.GetLmCurrRing());
    3389         pWrite(strat->P.sig);
    3390         printf("%d\n",red_result);
    3391     }
    3392 #endif
    3393     if (TEST_OPT_PROT)
    3394     {
    3395       if(strat->P.p != NULL)
    3396         message((strat->honey ? strat->P.ecart : 0) + strat->P.pFDeg(),
    3397                 &olddeg,&reduc,strat, red_result);
    3398       else
    3399         message((strat->honey ? strat->P.ecart : 0),
    3400                 &olddeg,&reduc,strat, red_result);
    3401     }
    3402 
    3403     if (strat->overflow)
    3404     {
    3405         if (!kStratChangeTailRing(strat)) { WerrorS("OVERFLOW.."); break;}
    3406     }
    3407     // reduction to non-zero new poly
    3408     if (red_result == 1)
    3409     {
    3410       // get the polynomial (canonicalize bucket, make sure P.p is set)
    3411       strat->P.GetP(strat->lmBin);
    3412 
    3413       // sig-safe computations may lead to wrong FDeg computation, thus we need
    3414       // to recompute it to make sure everything is alright
    3415       (strat->P).FDeg = (strat->P).pFDeg();
    3416       // in the homogeneous case FDeg >= pFDeg (sugar/honey)
    3417       // but now, for entering S, T, we reset it
    3418       // in the inhomogeneous case: FDeg == pFDeg
    3419       if (strat->homog) strat->initEcart(&(strat->P));
    3420 
    3421       /* statistic */
    3422       if (TEST_OPT_PROT) PrintS("s");
    3423 
    3424       //int pos=posInS(strat,strat->sl,strat->P.p,strat->P.ecart);
    3425       // in F5E we know that the last reduced element is already the
    3426       // the one with highest signature
    3427       int pos = strat->sl+1;
    3428 
    3429       // reduce the tail and normalize poly
    3430       // in the ring case we cannot expect LC(f) = 1,
    3431       // therefore we call pContent instead of pNorm
    3432       #ifdef HAVE_RINGS
    3433       poly beforetailred;
    3434       if(rField_is_Ring(currRing))
    3435         beforetailred = pCopy(strat->P.sig);
    3436       #endif
    3437 #if SBA_TAIL_RED
    3438       if(rField_is_Ring(currRing))
    3439       { 
    3440         if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
    3441           strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
    3442       }
    3443       else
    3444       {
    3445         if (strat->sbaOrder != 2) {
    3446           if (TEST_OPT_INTSTRATEGY)
    3447           {
    3448             strat->P.pCleardenom();
    3449             if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
    3450             {
    3451               strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
    3452               strat->P.pCleardenom();
    3453             }
    3454           }
    3455           else
    3456           {
    3457             strat->P.pNorm();
    3458             if ((TEST_OPT_REDSB)||(TEST_OPT_REDTAIL))
    3459               strat->P.p = redtailSba(&(strat->P),pos-1,strat, withT);
    3460           }
    3461         }
    3462       }
    3463       // It may happen that we have lost the sig in redtailsba
    3464       // It cannot reduce to 0 since here we are doing just tail reduction.
    3465       // Best case scenerio: remains the leading term
    3466       if(rField_is_Ring(currRing) && strat->sigdrop)     
    3467       {
    3468         #ifdef ADIDEBUG
    3469         printf("\n Still sigdrop after redtailSba - it reduced to \n");pWrite(strat->P.p);
    3470         #endif
    3471         strat->enterS(strat->P, 0, strat, strat->tl);
    3472         break;
    3473       }
    3474 #endif
    3475     if(rField_is_Ring(currRing))
    3476     {
    3477       if(strat->P.sig == NULL || pLtCmp(beforetailred,strat->P.sig) == 1)
    3478       {
    3479         #ifdef ADIDEBUG
    3480         printf("\nSigDrop after TAILred\n");pWrite(beforetailred);pWrite(strat->P.sig);
    3481         #endif
    3482         strat->sigdrop = TRUE;
    3483         //Reduce it as much as you can
    3484         red_result = redRing(&strat->P,strat);
    3485         if(red_result == 0)
    3486         {
    3487           //It reduced to 0, cancel the sigdrop
    3488           #ifdef ADIDEBUG
    3489           printf("\nReduced to 0 via redRing. Cancel sigdrop\n");
    3490           #endif
    3491           strat->sigdrop = FALSE;
    3492           p_Delete(&strat->P.sig,currRing);strat->P.sig = NULL;
    3493         }
    3494         else
    3495         {
    3496           #ifdef ADIDEBUG
    3497           printf("\nReduced to this via redRing.SIGDROP\n");pWrite(strat->P.p);
    3498           #endif
    3499           strat->enterS(strat->P, 0, strat, strat->tl);
    3500           break;
    3501         }
    3502       }
    3503       p_Delete(&beforetailred,currRing);
    3504       // strat->P.p = NULL may appear if we had  a sigdrop above and reduced to 0 via redRing
    3505       if(strat->P.p == NULL)
    3506         goto case_when_red_result_changed;
    3507     }
    3508     #ifdef ADIDEBUG
    3509     printf("\nNach redTailSba: \n");
    3510     p_Write(strat->P.p,strat->tailRing);p_Write(strat->P.sig,currRing);
    3511     #endif
    3512     // remove sigsafe label since it is no longer valid for the next element to
    3513     // be reduced
    3514     if (strat->sbaOrder == 1)
    3515     {
    3516       for (int jj = 0; jj<strat->tl+1; jj++)
    3517       {
    3518         if (pGetComp(strat->T[jj].sig) == strat->currIdx)
    3519         {
    3520           strat->T[jj].is_sigsafe = FALSE;
    3521         }
    3522       }
    3523     }
    3524     else
    3525     {
    3526       for (int jj = 0; jj<strat->tl+1; jj++)
    3527       {
    3528         strat->T[jj].is_sigsafe = FALSE;
    3529       }
    3530     }
    3531 #ifdef KDEBUG
    3532       if (TEST_OPT_DEBUG){PrintS("new s:");strat->P.wrp();PrintLn();}
    3533 #endif /* KDEBUG */
    3534 
    3535       // min_std stuff
    3536       if ((strat->P.p1==NULL) && (strat->minim>0))
    3537       {
    3538         if (strat->minim==1)
    3539         {
    3540           strat->M->m[minimcnt]=p_Copy(strat->P.p,currRing,strat->tailRing);
    3541           p_Delete(&strat->P.p2, currRing, strat->tailRing);
    3542         }
    3543         else
    3544         {
    3545           strat->M->m[minimcnt]=strat->P.p2;
    3546           strat->P.p2=NULL;
    3547         }
    3548         if (strat->tailRing!=currRing && pNext(strat->M->m[minimcnt])!=NULL)
    3549           pNext(strat->M->m[minimcnt])
    3550             = strat->p_shallow_copy_delete(pNext(strat->M->m[minimcnt]),
    3551                                            strat->tailRing, currRing,
    3552                                            currRing->PolyBin);
    3553         minimcnt++;
    3554       }
    3555 
    3556       // enter into S, L, and T
    3557       //if ((!TEST_OPT_IDLIFT) || (pGetComp(strat->P.p) <= strat->syzComp))
    3558       enterT(strat->P, strat);
    3559       strat->T[strat->tl].is_sigsafe = FALSE;
    3560       /*
    3561       printf("hier\n");
    3562       pWrite(strat->P.GetLmCurrRing());
    3563       pWrite(strat->P.sig);
    3564       */
    3565       if (rField_is_Ring(currRing))
    3566         superenterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
    3567       else
    3568         enterpairsSig(strat->P.p,strat->P.sig,strat->sl+1,strat->sl,strat->P.ecart,pos,strat, strat->tl);
    3569       #ifdef ADIDEBUG
    3570         printf("\nThis element is added to S\n");
    3571         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);
    3572         //getchar();
    3573         #endif
    3574       if(rField_is_Ring(currRing) && strat->sigdrop)
    3575         break;
    3576       if(rField_is_Ring(currRing))
    3577         strat->P.sevSig = p_GetShortExpVector(strat->P.sig,currRing);
    3578       strat->enterS(strat->P, pos, strat, strat->tl);
    3579       if(strat->sbaOrder != 1)
    3580       {
    3581         BOOLEAN overwrite = FALSE;
    3582         for (int tk=0; tk<strat->sl+1; tk++)
    3583         {
    3584           if (pGetComp(strat->sig[tk]) == pGetComp(strat->P.sig))
    3585           {
    3586             //printf("TK %d / %d\n",tk,strat->sl);
    3587             overwrite = FALSE;
    3588             break;
    3589           }
    3590         }
    3591         //printf("OVERWRITE %d\n",overwrite);
    3592         if (overwrite)
    3593         {
    3594           int cmp = pGetComp(strat->P.sig);
    3595           int* vv = (int*)omAlloc((currRing->N+1)*sizeof(int));
    3596           pGetExpV (strat->P.p,vv);
    3597           pSetExpV (strat->P.sig, vv);
    3598           pSetComp (strat->P.sig,cmp);
    3599 
    3600           strat->P.sevSig = pGetShortExpVector (strat->P.sig);
    3601           int i;
    3602           LObject Q;
    3603           for(int ps=0;ps<strat->sl+1;ps++)
    3604           {
    3605 
    3606             strat->newt = TRUE;
    3607             if (strat->syzl == strat->syzmax)
    3608             {
    3609               pEnlargeSet(&strat->syz,strat->syzmax,setmaxTinc);
    3610               strat->sevSyz = (unsigned long*) omRealloc0Size(strat->sevSyz,
    3611                   (strat->syzmax)*sizeof(unsigned long),
    3612                   ((strat->syzmax)+setmaxTinc)
    3613                   *sizeof(unsigned long));
    3614               strat->syzmax += setmaxTinc;
    3615             }
    3616             Q.sig = pCopy(strat->P.sig);
    3617             // add LM(F->m[i]) to the signature to get a Schreyer order
    3618             // without changing the underlying polynomial ring at all
    3619             if (strat->sbaOrder == 0)
    3620               p_ExpVectorAdd (Q.sig,strat->S[ps],currRing);
    3621             // since p_Add_q() destroys all input
    3622             // data we need to recreate help
    3623             // each time
    3624             // ----------------------------------------------------------
    3625             // in the Schreyer order we always know that the multiplied
    3626             // module monomial strat->P.sig gives the leading monomial of
    3627             // the corresponding principal syzygy
    3628             // => we do not need to compute the "real" syzygy completely
    3629             poly help = p_Copy(strat->sig[ps],currRing);
    3630             p_ExpVectorAdd (help,strat->P.p,currRing);
    3631             Q.sig = p_Add_q(Q.sig,help,currRing);
    3632             //printf("%d. SYZ  ",i+1);
    3633             //pWrite(strat->syz[i]);
    3634             Q.sevSig = p_GetShortExpVector(Q.sig,currRing);
    3635             i = posInSyz(strat, Q.sig);
    3636             enterSyz(Q, strat, i);
    3637           }
    3638         }
    3639       }
    3640       // deg - idx - lp/rp
    3641       // => we need to add syzygies with indices > pGetComp(strat->P.sig)
    3642       if(strat->sbaOrder == 0 || strat->sbaOrder == 3)
    3643       {
    3644         int cmp     = pGetComp(strat->P.sig);
    3645         int max_cmp = IDELEMS(F);
    3646         int* vv = (int*)omAlloc((currRing->N+1)*sizeof(int));
    3647         pGetExpV (strat->P.p,vv);
    3648         LObject Q;
    3649         int pos;
    3650         int idx = p_GetComp(strat->P.sig,currRing);
    3651         //printf("++ -- adding syzygies -- ++\n");
    3652         // if new element is the first one in this index
    3653         if (strat->currIdx < idx) {
    3654           for (int i=0; i<strat->sl; ++i) {
    3655             Q.sig = p_Copy(strat->P.sig,currRing);
    3656             p_ExpVectorAdd(Q.sig,strat->S[i],currRing);
    3657             poly help = p_Copy(strat->sig[i],currRing);
    3658             p_ExpVectorAdd(help,strat->P.p,currRing);
    3659             Q.sig = p_Add_q(Q.sig,help,currRing);
    3660             //pWrite(Q.sig);
    3661             pos = posInSyz(strat, Q.sig);
    3662             enterSyz(Q, strat, pos);
    3663           }
    3664           strat->currIdx = idx;
    3665         } else {
    3666           // if the element is not the first one in the given index we build all
    3667           // possible syzygies with elements of higher index
    3668           for (int i=cmp+1; i<=max_cmp; ++i) {
    3669             pos = -1;
    3670             for (int j=0; j<strat->sl; ++j) {
    3671               if (p_GetComp(strat->sig[j],currRing) == i) {
    3672                 pos = j;
    3673                 break;
    3674               }
    3675             }
    3676             if (pos != -1) {
    3677               Q.sig = p_One(currRing);
    3678               p_SetExpV(Q.sig, vv, currRing);
    3679               // F->m[i-1] corresponds to index i
    3680               p_ExpVectorAdd(Q.sig,F->m[i-1],currRing);
    3681               p_SetComp(Q.sig, i, currRing);
    3682               poly help = p_Copy(strat->P.sig,currRing);
    3683               p_ExpVectorAdd(help,strat->S[pos],currRing);
    3684               Q.sig = p_Add_q(Q.sig,help,currRing);
    3685               if (strat->sbaOrder == 0) {
    3686                 if (p_LmCmp(Q.sig,strat->syz[strat->syzl-1],currRing) == -currRing->OrdSgn) {
    3687                   pos = posInSyz(strat, Q.sig);
    3688                   enterSyz(Q, strat, pos);
    3689                 }
    3690               } else {
    3691                 pos = posInSyz(strat, Q.sig);
    3692                 enterSyz(Q, strat, pos);
    3693               }
    3694             }
    3695           }
    3696           //printf("++ -- done adding syzygies -- ++\n");
    3697         }
    3698       }
    3699 //#if 1
    3700 #if DEBUGF50
    3701     printf("---------------------------\n");
    3702     Print(" %d. ELEMENT ADDED TO GCURR:\n",strat->sl+1);
    37032929    PrintS("LEAD POLY:  "); pWrite(pHead(strat->S[strat->sl]));
    37042930    PrintS("SIGNATURE:  "); pWrite(strat->sig[strat->sl]);
     
    38493075  size_g_non_red  = IDELEMS(strat->Shdl);
    38503076#endif
    3851  
     3077  if(!rField_is_Ring(currRing))
     3078      exitSba(strat);
    38523079  // I have to add the initial input polynomials which where not used (p1 and p2 = NULL)
    38533080  #ifdef HAVE_RINGS
     
    39003127    strat->Shdl = idrMoveR_NoSort (strat->Shdl, sRing, currRing);
    39013128    rChangeCurrRing (sRing);
    3902     exitSba(strat);
     3129    if(rField_is_Ring(currRing))
     3130      exitSba(strat);
    39033131    rChangeCurrRing (currRingOld);
    39043132    if(strat->tailRing == sRing)
     
    39073135  }
    39083136  if(rField_is_Ring(currRing) && !strat->sigdrop)
     3137    id_DelDiv(strat->Shdl, currRing);
     3138  if(!rField_is_Ring(currRing))
    39093139    id_DelDiv(strat->Shdl, currRing);
    39103140  idSkipZeroes(strat->Shdl);
  • kernel/GBEngine/kutil.cc

    rd5d857 r7d1e80  
    1212#define MYTEST 0
    1313
    14 #define ADIDEBUG 1
     14//#define ADIDEBUG 1
    1515//All vs Just strategy over rings:
    1616// 1 - Just
     
    72247224BOOLEAN arriRewCriterion(poly /*sig*/, unsigned long /*not_sevSig*/, poly /*lm*/, kStrategy strat, int start=0)
    72257225{
     7226  #ifdef ADIDEBUG
    72267227  printf("\narriRewCrit\n");
     7228  #endif
    72277229  if(rField_is_Ring(currRing))
    72287230    return FALSE;
     
    72407242        printf("\narriRewCrit deleted: sig, P.sig\n");
    72417243        #endif
    7242         printf("\nDelete!\n");
    72437244        pDelete(&p1);
    72447245        pDelete(&p2);
     
    72547255BOOLEAN arriRewCriterionPre(poly sig, unsigned long not_sevSig, poly lm, kStrategy strat, int /*start=0*/)
    72557256{
     7257  #ifdef ADIDEBUG
    72567258  printf("\narriRewCritPre\n");
     7259  #endif
    72577260  //Over Rings, there are still some changes to do: considering coeffs
    72587261  if(rField_is_Ring(currRing))
     
    72717274    {
    72727275      deleteInL(strat->B,&strat->Bl,found,strat);
     7276      #ifdef ADIDEBUG
    72737277      printf("\nDelete!\n");
     7278      #endif
    72747279    }
    72757280    else
    72767281    {
     7282      #ifdef ADIDEBUG
    72777283      printf("\nDelete this one!\n");
     7284      #endif
    72787285      return TRUE;
    72797286    }
     
    72917298        pDelete(&p1);
    72927299        pDelete(&p2);
     7300        #ifdef ADIDEBUG
    72937301        printf("\nDelete this one!\n");
     7302        #endif
    72947303        return TRUE;
    72957304      }
Note: See TracChangeset for help on using the changeset viewer.