source: git/kernel/GBEngine/kstdfac.cc @ 4676d5

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