source: git/kernel/kstdfac.cc @ 601105

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