source: git/kernel/kstdfac.cc @ 6ce030f

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