source: git/kernel/GBEngine/kstdfac.cc @ 1e94e6

spielwiese
Last change on this file since 1e94e6 was 1e94e6, checked in by Hans Schoenemann <hannes@…>, 6 years ago
opt: removed p_LmHead (-> p_LmInit)
  • Property mode set to 100644
File size: 23.1 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/*
5*  ABSTRACT -  Kernel: factorizing alg. of Buchberger
6*/
7
8
9
10
11#include "kernel/mod2.h"
12#include "omalloc/omalloc.h"
13#include "misc/options.h"
14#include "kernel/polys.h"
15#include "kernel/ideals.h"
16#include "kernel/GBEngine/kutil.h"
17#include "kernel/GBEngine/kstd1.h"
18#include "kernel/GBEngine/khstd.h"
19#include "polys/weight.h"
20#include "misc/intvec.h"
21#include "polys/clapsing.h"
22#include "kernel/ideals.h"
23#include "kernel/GBEngine/kstdfac.h"
24
25int strat_nr=0;
26/*3
27* copy o->T to n->T, assumes that n->S is already copied
28*/
29static void copyT (kStrategy o,kStrategy n)
30{
31  int i,j;
32  poly  p;
33  TSet t=(TSet)omAlloc0(o->tmax*sizeof(TObject));
34  TObject** r = (TObject**)omAlloc0(o->tmax*sizeof(TObject*));
35
36  for (j=0; j<=o->tl; j++)
37  {
38    t[j] = o->T[j];
39    r[t[j].i_r] = &t[j];
40    p = o->T[j].p;
41    i = -1;
42    loop
43    {
44      i++;
45      if (i>o->sl)
46      {
47        t[j].p=pCopy(p);
48        break;
49      }
50      if (p == o->S[i])
51      {
52        t[j].p=n->S[i];
53        break;
54      }
55    }
56    t[j].t_p = NULL; // ?? or t[j].p ??
57    t[j].max_exp = NULL; // ?? or p_GetMaxExpP(t[j].t_p,o->tailRing); ??
58    t[j].pLength =  pLength(p);
59  }
60  n->T=t;
61  n->R=r;
62}
63
64/*3
65* copy o->L to n->L, assumes that n->T,n->tail is already copied
66*/
67static void copyL (kStrategy o,kStrategy n)
68{
69  int i,j;
70  poly  p;
71  LSet l=(LSet)omAlloc(o->Lmax*sizeof(LObject));
72
73  for (j=0; j<=o->Ll; j++)
74  {
75    l[j] = o->L[j];
76    // copy .p ----------------------------------------------
77    if (pNext(o->L[j].p)!=o->tail)
78      l[j].p=pCopy(o->L[j].p);
79    else
80    {
81      l[j].p=p_LmInit(o->L[j].p,currRing);
82      if (pGetCoeff(o->L[j].p)!=NULL) pSetCoeff0(l[j].p,nCopy(pGetCoeff(o->L[j].p)));
83      pNext(l[j].p)=n->tail;
84    }
85    // copy .lcm ----------------------------------------------
86    if (o->L[j].lcm!=NULL)
87      l[j].lcm=pLmInit(o->L[j].lcm);
88    else
89      l[j].lcm=NULL;
90    l[j].p1=NULL;
91    l[j].p2=NULL;
92    l[j].t_p = NULL;
93
94    // copy .p1 , i_r1----------------------------------------------
95    p = o->L[j].p1;
96    i = -1;
97    loop
98    {
99      if(p==NULL) break;
100      i++;
101      if(i>o->tl)
102      {
103        WarnS("poly p1 not found in T:");wrp(p);PrintLn();
104        l[j].p1=pCopy(p);
105        l[j].i_r1=-1;
106        break;
107      }
108      if (p == o->T[i].p)
109      {
110        l[j].p1=n->T[i].p;
111        l[j].i_r1=n->T[i].i_r;
112        break;
113      }
114    }
115
116    // copy .p2 , i_r2----------------------------------------------
117    p = o->L[j].p2;
118    i = -1;
119    loop
120    {
121      if(p==NULL) break;
122      i++;
123      if(i>o->tl)
124      {
125        WarnS("poly p2 not found in T:");wrp(p);PrintLn();
126        l[j].p2=pCopy(p);
127        l[j].i_r2=-1;
128        break;
129      }
130      if (p == o->T[i].p)
131      {
132        l[j].p2=n->T[i].p;
133        l[j].i_r2=n->T[i].i_r;
134        break;
135      }
136    }
137
138    // copy .ecart ---------------------------------------------
139    l[j].ecart=o->L[j].ecart;
140    // copy .length --------------------------------------------
141    l[j].length=o->L[j].length;
142    // copy .pLength -------------------------------------------
143    l[j].pLength=o->L[j].pLength;
144    // copy .sev -----------------------------------------------
145    l[j].sev=o->L[j].sev;
146    l[j].i_r = o->L[j].i_r;
147    //l[j].i_r1 = o->L[j].i_r1;
148    //l[j].i_r2 = o->L[j].i_r2;
149  }
150  n->L=l;
151}
152
153kStrategy kStratCopy(kStrategy o)
154{
155  // int i;
156  kTest_TS(o);
157  kStrategy s=new skStrategy;
158  s->next=NULL;
159  s->red=o->red;
160  s->initEcart=o->initEcart;
161  s->posInT=o->posInT;
162  s->posInL=o->posInL;
163  s->enterS=o->enterS;
164  s->initEcartPair=o->initEcartPair;
165  s->posInLOld=o->posInLOld;
166  s->enterOnePair=o->enterOnePair;
167  s->chainCrit=o->chainCrit;
168  s->Shdl=idCopy(o->Shdl);
169  s->S=s->Shdl->m;
170  s->tailRing = o->tailRing;
171  if (o->D!=NULL) s->D=idCopy(o->D);
172  else            s->D=NULL;
173  s->ecartS=(int *)omAlloc(IDELEMS(o->Shdl)*sizeof(int));
174  memcpy(s->ecartS,o->ecartS,IDELEMS(o->Shdl)*sizeof(int));
175  s->sevS=(unsigned long *)omAlloc(IDELEMS(o->Shdl)*sizeof(unsigned long));
176  memcpy(s->sevS,o->sevS,IDELEMS(o->Shdl)*sizeof(unsigned long));
177  s->S_2_R=(int*)omAlloc(IDELEMS(o->Shdl)*sizeof(int));
178  memcpy(s->S_2_R,o->S_2_R,IDELEMS(o->Shdl)*sizeof(int));
179  s->sevT=(unsigned long *)omAlloc(o->tmax*sizeof(unsigned long));
180  memcpy(s->sevT,o->sevT,o->tmax*sizeof(unsigned long));
181  if(o->fromQ!=NULL)
182  {
183    s->fromQ=(int *)omAlloc(IDELEMS(o->Shdl)*sizeof(int));
184    memcpy(s->fromQ,o->fromQ,IDELEMS(o->Shdl)*sizeof(int));
185  }
186  else
187    s->fromQ=NULL;
188  copyT(o,s);//s->T=...
189  s->tail = pInit();
190  copyL(o,s);//s->L=...
191  s->B=initL();
192  s->kHEdge=pCopy(o->kHEdge);
193  s->kNoether=pCopy(o->kNoether);
194  if (o->NotUsedAxis!=NULL)
195  {
196    s->NotUsedAxis=(BOOLEAN *)omAlloc(currRing->N*sizeof(BOOLEAN));
197    memcpy(s->NotUsedAxis,o->NotUsedAxis,currRing->N*sizeof(BOOLEAN));
198  }
199  //s->P=s->L[s->Ll+1];
200  s->P.Init(o->tailRing);
201  s->update=o->update;
202  s->posInLOldFlag=o->posInLOldFlag;
203  s->kModW = o->kModW;
204//   if (o->kModW!=NULL)
205//     s->kModW=ivCopy(o->kModW);
206//   else
207//     s->kModW=NULL;
208  s->pairtest=NULL;
209  s->sl=o->sl;
210  s->mu=o->mu;
211  s->tl=o->tl;
212  s->tmax=o->tmax;
213  s->Ll=o->Ll;
214  s->Lmax=o->Lmax;
215  s->Bl=-1;
216  s->Bmax=setmaxL;
217  s->ak=o->ak;
218  s->syzComp=o->syzComp;
219  s->LazyPass=o->LazyPass;
220  s->LazyDegree=o->LazyDegree;
221  s->HCord=o->HCord;
222  s->lastAxis=o->lastAxis;
223  s->interpt=o->interpt;
224  s->homog=o->homog;
225  s->news=o->news;
226  s->newt=o->newt;
227  s->kHEdgeFound=o->kHEdgeFound;
228  s->honey=o->honey;
229  s->sugarCrit=o->sugarCrit;
230  s->Gebauer=o->Gebauer;
231  s->noTailReduction=o->noTailReduction;
232  s->fromT=o->fromT;
233  s->noetherSet=o->noetherSet;
234#ifdef HAVE_SHIFTBBA
235  s->lV=o->lV;
236#endif
237#ifdef HAVE_PLURAL
238  s->no_prod_crit=o->no_prod_crit;
239#endif
240  kTest_TS(s);
241  return s;
242}
243
244BOOLEAN k_factorize(poly p,ideal &rfac, ideal &fac_copy)
245{
246  int facdeg=currRing->pFDeg(p,currRing);
247  ideal fac=singclap_factorize(pCopy(p),NULL,1,currRing);
248  int fac_elems;
249  fac_elems=IDELEMS(fac);
250  rfac=fac;
251  fac_copy=idInit(fac_elems,1);
252
253  if ((fac_elems!=1)||(facdeg!=currRing->pFDeg(fac->m[0],currRing)))
254  {
255    if (TEST_OPT_DEBUG)
256    {
257      Print("%d factors:\n",fac_elems);
258      pWrite(p); PrintS(" ->\n");
259      int ii=fac_elems;
260      while(ii>0) { ii--;pWrite(fac->m[ii]); }
261    }
262    else if (TEST_OPT_PROT)
263    {
264      int ii=fac_elems;
265      if (ii>1)
266      {
267        while(ii>0) { PrintS("F"); ii--; }
268      }
269    }
270    return TRUE;
271  }
272  else
273  {
274    pDelete(&(fac->m[0]));
275    fac->m[0]=pCopy(p);
276  }
277  return FALSE;
278}
279
280static void completeReduceFac (kStrategy strat, ideal_list FL)
281{
282  int si;
283
284  strat->noTailReduction = FALSE;
285  if (TEST_OPT_PROT)
286  {
287    PrintLn();
288//    if (timerv) writeTime("standard base computed:");
289  }
290  if (TEST_OPT_PROT)
291  {
292    Print("(S:%d)",strat->sl);mflush();
293  }
294  for (si=strat->sl; si>0; si--)
295  {
296    strat->S[si] = redtailBba(strat->S[si],si-1,strat);
297    if (TEST_OPT_INTSTRATEGY)
298    {
299      strat->S[si]=p_Cleardenom(strat->S[si], currRing);
300    }
301    if (TEST_OPT_PROT)
302    {
303      PrintS("-");mflush();
304    }
305    int i;
306    if (strat->redTailChange)
307    {
308      for(i=strat->tl;i>=0;i--)
309      {
310        strat->initEcart(&strat->T[i]);
311      }
312    }
313    ideal fac;
314    ideal fac_copy;
315
316    if (!k_factorize(strat->S[si],fac,fac_copy))
317    {
318      idDelete(&fac);
319      idDelete(&fac_copy);
320      continue;
321    }
322
323    deleteInS(si,strat);
324
325    for(i=IDELEMS(fac)-1;i>=0;i--)
326    {
327      kStrategy n=strat;
328      if (i>=1)
329      {
330        n=kStratCopy(strat); // includes: memset(&n->P,0,sizeof(n->P));
331        n->next=strat->next;
332        strat->next=n;
333      }
334      else
335      {
336        n->P.Init(strat->tailRing);
337      }
338
339      n->P.p=fac->m[i];
340      //n->P.pLength=pLength(n->P.p); // by initEcart
341      n->initEcart(&n->P);
342      /* enter P.p into s and L */
343      int pos;
344      if (n->sl==-1) pos=0;
345      else pos=posInS(n,n->sl,n->P.p,n->P.ecart);
346      if (TEST_OPT_INTSTRATEGY)
347      {
348        n->P.p = redtailBba(n->P.p,pos-1,n);
349        n->P.pCleardenom();
350      }
351      else
352      {
353        pNorm(n->P.p);
354        n->P.p = redtailBba(n->P.p,pos-1,n);
355      }
356      n->P.pLength=pLength(n->P.p);
357      if (TEST_OPT_DEBUG)
358      {
359        Print("new s(%d)->S:",n->nr);
360        pWrite(n->P.p);
361      }
362      enterpairs(n->P.p,n->sl,n->P.ecart,pos,n);
363      enterT(n->P,n);
364      n->enterS(n->P,pos,n, n->tl);
365
366      /* construct D */
367      if (IDELEMS(fac)>1)
368      {
369        if (n->D==NULL)
370        {
371          n->D=idCopy(fac_copy);
372          idSkipZeroes(n->D);
373        }
374        else
375        {
376          idTest(n->D);
377          ideal r=idAdd(n->D,fac_copy);
378          idDelete(&n->D);
379          n->D=r;
380        }
381        if (TEST_OPT_DEBUG)
382        {
383          Print("new s(%d)->D:\n",n->nr);
384          iiWriteMatrix((matrix)n->D,"D",1,currRing,0);
385          PrintLn();
386        }
387      }
388
389      fac_copy->m[i]=pCopy(fac->m[i]);
390      fac->m[i]=NULL;
391
392      /* check for empty sets */
393      if (n->D!=NULL)
394      {
395        int j=IDELEMS(n->D)-1;
396        while(j>=0)
397        {
398          if (n->D->m[j]!=NULL)
399          {
400            poly r=kNF(n->Shdl,NULL,n->D->m[j],0,KSTD_NF_LAZY | KSTD_NF_NONORM);
401            if (r==NULL)
402            {
403              if (TEST_OPT_DEBUG)
404              {
405                Print("empty set s(%d) because D[%d]:",n->nr,j);
406                pWrite(n->D->m[j]);
407                messageSets(n);
408              }
409              while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
410              while (n->tl >= 0)
411              {
412                int i=n->sl;
413                while (i>=0)
414                {
415                  if (n->S[i]==n->T[n->tl].p)
416                  {
417                    n->T[n->tl].p=NULL; n->S[i]=NULL;
418                    break;
419                  }
420                  i--;
421                }
422                pDelete(&n->T[n->tl].p);
423                n->tl--;
424              }
425              memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
426              n->sl=-1;
427              if (strat==n) si=-1;
428              break;
429            }
430            else
431            {
432              pDelete(&r);
433            }
434          }
435          j--;
436        }
437      }
438      /* check for empty sets */
439      {
440        ideal_list Lj=FL;
441        while (Lj!=NULL)
442        {
443          if ((n->sl>=0)&&(n->S[0]!=NULL))
444          {
445            ideal r=kNF(n->Shdl,NULL,Lj->d,0,KSTD_NF_LAZY | KSTD_NF_NONORM);
446            if (idIs0(r))
447            {
448              if (TEST_OPT_DEBUG)
449              {
450                Print("empty set because:L[%p]\n",(void *)Lj);
451                iiWriteMatrix((matrix)Lj->d,"L",1,currRing,0);
452              }
453              while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
454              while (n->tl >= 0)
455              {
456                int i=n->sl;
457                while (i>=0)
458                {
459                  if (n->S[i]==n->T[n->tl].p)
460                  {
461                    n->T[n->tl].p=NULL; n->S[i]=NULL;
462                    break;
463                  }
464                  i--;
465                }
466                pDelete(&n->T[n->tl].p);
467                n->tl--;
468              }
469              memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
470              n->sl=-1;
471              if (strat==n) si=-1;
472              idDelete(&r);
473              break;
474            }
475            idDelete(&r);
476          }
477          Lj=Lj->next;
478        }
479      }
480    } /* for */
481    for(i=0;i<IDELEMS(fac);i++) fac->m[i]=NULL;
482    idDelete(&fac);
483    idDelete(&fac_copy);
484    if ((strat->Ll>=0) && (strat->sl>=0)) break;
485    else si=strat->sl+1;
486  }
487}
488
489ideal bbafac (ideal /*F*/, ideal Q,intvec */*w*/,kStrategy strat, ideal_list FL)
490{
491  int   olddeg,reduc=0;
492  int red_result = 1;
493  reduc = olddeg = 0;
494  /* compute------------------------------------------------------- */
495  if ((strat->Ll==-1) && (strat->sl>=0))
496  {
497    if (TEST_OPT_REDSB) completeReduceFac(strat,FL);
498  }
499  kTest_TS(strat);
500  while (strat->Ll >= 0)
501  {
502    if (TEST_OPT_DEBUG) messageSets(strat);
503    if (strat->Ll== 0) strat->interpt=TRUE;
504    if (TEST_OPT_DEGBOUND
505    && ((strat->honey
506        && (strat->L[strat->Ll].ecart+currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
507      || ((!strat->honey) && (currRing->pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
508    {
509      /*
510      *stops computation if
511      * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
512      *a predefined number Kstd1_deg
513      */
514      while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
515      break;
516    }
517    /* picks the last element from the lazyset L */
518    strat->P = strat->L[strat->Ll];
519    strat->Ll--;
520    if (pNext(strat->P.p) == strat->tail)
521    {
522      /* deletes the short spoly and computes */
523      pLmFree(strat->P.p);
524      /* the real one */
525      strat->P.p = ksOldCreateSpoly(strat->P.p1,
526                                    strat->P.p2,
527                                    strat->kNoether);
528    }
529    if (strat->honey)
530    {
531      if (TEST_OPT_PROT)
532        message(strat->P.ecart+currRing->pFDeg(strat->P.p,currRing),&olddeg,&reduc,strat, red_result);
533    }
534    else
535    {
536      if (TEST_OPT_PROT)
537        message(currRing->pFDeg(strat->P.p,currRing),&olddeg,&reduc,strat, red_result);
538    }
539    /* reduction of the element chosen from L */
540    kTest_TS(strat);
541    red_result = strat->red(&strat->P,strat);
542    if (strat->P.p != NULL)
543    {
544      /* statistic */
545      if (TEST_OPT_PROT) PrintS("s");
546      ideal fac;
547      ideal fac_copy;
548
549      if (!k_factorize(strat->P.p,fac,fac_copy))
550      {
551        if (TEST_OPT_INTSTRATEGY)
552        {
553          strat->P.p = redtailBba(strat->P.p,strat->sl,strat);
554          if (strat->redTailChange) strat->P.pCleardenom();
555        }
556        else
557        {
558          pNorm(strat->P.p);
559          strat->P.p = redtailBba(strat->P.p,strat->sl,strat);
560        }
561        if (strat->redTailChange)
562        {
563          idDelete(&fac);
564          idDelete(&fac_copy);
565          if (!k_factorize(strat->P.p,fac,fac_copy))
566          {
567            pDelete(&(fac->m[0]));
568            fac->m[0]=strat->P.p;
569            strat->P.p=NULL;
570          }
571          else
572          {
573            pDelete(&strat->P.p);
574          }
575        }
576      }
577      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
578      int i;
579
580      for(i=IDELEMS(fac)-1;i>=0;i--)
581      {
582        int ii;
583        kStrategy n=strat;
584        if (i>=1)
585        {
586          n=kStratCopy(strat); // includes memset(&n->P,0,sizeof(n->P));
587          kTest_TS(n);
588          n->next=strat->next;
589          strat->next=n;
590        }
591        else
592        {
593          n->P.Init(strat->tailRing);
594        }
595
596        n->P.p=fac->m[i];
597        //n->P.pLength=pLength(n->P.p); // by initEcart
598        n->initEcart(&n->P);
599        kTest_TS(n);
600
601        /* enter P.p into s and L */
602        int pos;
603        if (n->sl==-1) pos=0;
604        else pos=posInS(n,n->sl,n->P.p,n->P.ecart);
605
606        // we have already reduced all elements from fac....
607        if (TEST_OPT_INTSTRATEGY)
608        {
609          n->P.p = redtailBba(n->P.p,pos-1,n);
610          if (n->redTailChange)
611          {
612            n->P.pCleardenom();
613            n->P.pLength=pLength(n->P.p);
614          }
615        }
616        else
617        {
618          pNorm(n->P.p);
619          n->P.p = redtailBba(n->P.p,pos-1,n);
620          if (n->redTailChange)
621          {
622            n->P.pLength=pLength(n->P.p);
623          }
624        }
625        kTest_TS(n);
626
627        if (TEST_OPT_DEBUG)
628        {
629          PrintS("new s:");
630          wrp(n->P.p);
631          PrintLn();
632        }
633        enterpairs(n->P.p,n->sl,n->P.ecart,pos,n);
634        enterT(n->P,n);
635        n->enterS(n->P,pos,n, n->tl);
636        {
637          int i=n->Ll;
638          for(;i>=0;i--)
639          {
640            n->L[i].i_r1= -1;
641            for(ii=0; ii<=n->tl; ii++)
642            {
643              if (n->R[ii]->p==n->L[i].p1)  { n->L[i].i_r1=ii;break; }
644            }
645            n->L[i].i_r2= -1;
646            for(ii=0; ii<=n->tl; ii++)
647            {
648              if (n->R[ii]->p==n->L[i].p2)  { n->L[i].i_r2=ii;break; }
649            }
650          }
651        }
652        kTest_TS(n);
653        /* construct D */
654        if (IDELEMS(fac)>1)
655        {
656          if (n->D==NULL)
657          {
658            n->D=idCopy(fac_copy);
659            idSkipZeroes(n->D);
660          }
661          else
662          {
663            idTest(n->D);
664            ideal r=idAdd(n->D,fac_copy);
665            idDelete(&n->D);
666            n->D=r;
667          }
668          if (TEST_OPT_DEBUG)
669          {
670            PrintS("new D:\n");
671            iiWriteMatrix((matrix)n->D,"D",1,currRing,0);
672            PrintLn();
673          }
674        }
675
676        fac_copy->m[i]=pCopy(fac->m[i]);
677        fac->m[i]=NULL;
678
679        /* check for empty sets */
680        if (n->D!=NULL)
681        {
682          int j=IDELEMS(n->D)-1;
683          while(j>=0)
684          {
685            if (n->D->m[j]!=NULL)
686            {
687              poly r=kNF(n->Shdl,NULL,n->D->m[j],0,KSTD_NF_LAZY | KSTD_NF_NONORM);
688              if (r==NULL)
689              {
690                if (TEST_OPT_DEBUG)
691                {
692                  Print("empty set s(%d) because: D[%d]:", n->nr,j);
693                  pWrite(n->D->m[j]);
694                  messageSets(n);
695                }
696                //if (n->Ll >=0) Print("Ll:%d|",n->Ll);
697                while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
698                //if (n->tl >=0) Print("tl:%d|",n->tl);
699                while (n->tl >= 0)
700                {
701                  int i=n->sl;
702                  while (i>=0)
703                  {
704                    if (n->S[i]==n->T[n->tl].p)
705                    {
706                      n->T[n->tl].p=NULL; n->S[i]=NULL;
707                      break;
708                    }
709                    i--;
710                  }
711                  pDelete(&n->T[n->tl].p);
712                  n->tl--;
713                }
714                memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
715                n->sl=-1;
716                break;
717              }
718              else
719              {
720                pDelete(&r);
721              }
722            }
723            j--;
724          }
725        }
726
727        /* check for empty sets */
728        {
729          ideal_list Lj=FL;
730          while (Lj!=NULL)
731          {
732            if ((n->sl>=0)&&(n->S[0]!=NULL))
733            {
734              ideal r=kNF(n->Shdl,NULL,Lj->d,0,KSTD_NF_LAZY | KSTD_NF_NONORM);
735              if (idIs0(r))
736              {
737                if (TEST_OPT_DEBUG)
738                {
739                  #ifdef KDEBUG
740                  Print("empty set s(%d) because:L[%d]\n",n->nr,Lj->nr);
741                  #else
742                  Print("empty set s(%d) because:\n",n->nr);
743                  #endif
744                  iiWriteMatrix((matrix)Lj->d,"L",1,currRing,0);
745                }
746                while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
747                while (n->tl >= 0)
748                {
749                  int i=n->sl;
750                  while (i>=0)
751                  {
752                    if (n->S[i]==n->T[n->tl].p)
753                    {
754                      n->T[n->tl].p=NULL; n->S[i]=NULL;
755                      break;
756                    }
757                    i--;
758                  }
759                  pDelete(&n->T[n->tl].p);
760                  n->tl--;
761                }
762                memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
763                n->sl=-1;
764                idDelete(&r);
765                break;
766              }
767              idDelete(&r);
768            }
769            Lj=Lj->next;
770          }
771        }
772      } /* for */
773      for(i=0;i<IDELEMS(fac);i++) fac->m[i]=NULL;
774      idDelete(&fac);
775      idDelete(&fac_copy);
776    }
777#ifdef KDEBUG
778    strat->P.lcm=NULL;
779#endif
780    kTest_TS(strat);
781    if ((strat->Ll==-1) && (strat->sl>=0))
782    {
783      if (TEST_OPT_REDSB) completeReduceFac(strat,FL);
784    }
785    kTest_TS(strat);
786  }
787#ifdef KDEBUG
788  if (TEST_OPT_DEBUG) messageSets(strat);
789#endif
790  /* complete reduction of the standard basis--------- */
791  /* release temp data-------------------------------- */
792  if (TEST_OPT_WEIGHTM)
793  {
794    pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
795    if (ecartWeights)
796    {
797      omFreeSize((ADDRESS)ecartWeights,((currRing->N)+1)*sizeof(short));
798      ecartWeights=NULL;
799    }
800  }
801  exitBuchMora(strat);
802  if (TEST_OPT_PROT) { PrintLn(); messageStat(0,strat); }
803  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
804  return (strat->Shdl);
805}
806
807ideal_list kStdfac(ideal F, ideal Q, tHomog h,intvec ** w,ideal D)
808{
809  ideal r;
810  BOOLEAN b=currRing->pLexOrder,toReset=FALSE;
811  BOOLEAN delete_w=(w==NULL);
812  kStrategy strat=new skStrategy;
813  kStrategy orgstrat=strat;
814  ideal_list L=NULL;
815
816  if (rField_has_simple_inverse(currRing))
817    strat->LazyPass=20;
818  else
819    strat->LazyPass=2;
820  strat->LazyDegree = 1;
821  strat->ak = id_RankFreeModule(F,currRing);
822  if (h==testHomog)
823  {
824    if (strat->ak==0)
825    {
826      h = (tHomog)idHomIdeal(F,Q);
827      w=NULL;
828    }
829    else
830      h = (tHomog)idHomModule(F,Q,w);
831  }
832  if (h==isHomog)
833  {
834    if ((w!=NULL) && (*w!=NULL))
835    {
836      kModW = *w;
837      strat->kModW = *w;
838      strat->pOrigFDeg = currRing->pFDeg;
839      strat->pOrigLDeg = currRing->pLDeg;
840      pSetDegProcs(currRing,kModDeg);
841      toReset = TRUE;
842    }
843    currRing->pLexOrder = TRUE;
844    strat->LazyPass*=2;
845  }
846  strat->homog=h;
847  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
848  initBuchMoraPos(strat);
849  initBba(strat);
850  initBuchMora(F, Q,strat);
851  if (D!=NULL)
852  {
853    strat->D=idCopy(D);
854  }
855// Ende der Initalisierung
856  while (strat!=NULL)
857  {
858    if (TEST_OPT_DEBUG)
859      PrintS("====================================\n");
860    if (w!=NULL)
861      r=bbafac(F,Q,*w,strat,L);
862    else
863      r=bbafac(F,Q,NULL,strat,L);
864#ifdef KDEBUG
865    int i;
866    for (i=0; i<IDELEMS(r); i++) pTest(r->m[i]);
867#endif
868    idSkipZeroes(r);
869    // Testausgabe:
870    //if (!idIs0(r))
871    //{
872    //  PrintS("===================================================\n");
873    //  iiWriteMatrix((matrix)r,"S",1,currRing,0);
874    //  PrintS("\n===================================================\n");
875    //}
876    //else
877    //{
878    //  PrintS("=========empty============================\n");
879    //}
880    if(!idIs0(r))
881    {
882      ideal_list LL=(ideal_list)omAlloc(sizeof(*LL));
883      LL->d=r;
884#ifndef SING_NDEBUG
885      LL->nr=strat->nr;
886#endif
887      LL->next=L;
888      L=LL;
889    }
890    strat=strat->next;
891  }
892  /* check for empty sets */
893  if (L!=NULL)
894  {
895    ideal_list Lj=L->next;
896    ideal_list Lj_prev=L;
897    while (Lj!=NULL)
898    {
899      ideal_list Li=L;
900      while(Li!=Lj)
901      {
902        ideal r=kNF(Lj->d,NULL,Li->d,0,KSTD_NF_LAZY | KSTD_NF_NONORM);
903        if (idIs0(r))
904        {
905#ifdef KDEBUG
906          if (TEST_OPT_DEBUG)
907          {
908            Print("empty set L[%p] because:L[%p]\n",(void*)Lj,(void*)Li);
909          }
910#endif
911          // delete L[j],
912          Li=L;
913          if (Lj_prev!=NULL)
914          {
915            Lj=Lj_prev;
916            if (Lj==L) Lj_prev=NULL;
917            else
918            {
919              Lj_prev=L;
920              while(Lj_prev->next!=Lj) Lj_prev=Lj_prev->next;
921            }
922          }
923          else Lj=NULL;
924        }
925        else
926        {
927          Li=Li->next;
928        }
929        idDelete (&r);
930      }
931      if (Lj!=NULL) Lj=Lj->next;
932    }
933  }
934// Ende: aufraeumen
935  if (toReset)
936  {
937    pRestoreDegProcs(currRing,strat->pOrigFDeg, strat->pOrigLDeg);
938    kModW = NULL;
939  }
940  currRing->pLexOrder = b;
941  delete(strat);
942  strat=orgstrat;
943  while (strat!=NULL)
944  {
945    orgstrat=strat->next;
946    delete(strat);
947    strat=orgstrat;
948  }
949  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
950  return L;
951}
Note: See TracBrowser for help on using the repository browser.