source: git/kernel/kstdfac.cc @ e7c6b22

spielwiese
Last change on this file since e7c6b22 was 672e05, checked in by Hans Schönemann <hannes@…>, 16 years ago
*hannes: fix pLength git-svn-id: file:///usr/local/Singular/svn/trunk@10723 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 24.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: kstdfac.cc,v 1.14 2008-05-20 14:41:02 Singular Exp $ */
5/*
6*  ABSTRACT -  Kernel: factorizing alg. of Buchberger
7*/
8
9#include "mod2.h"
10#include "structs.h"
11#include "omalloc.h"
12#include "polys.h"
13#include "ideals.h"
14#include "febase.h"
15#include "kutil.h"
16#include "kstd1.h"
17#include "khstd.h"
18//#include "cntrlc.h"
19#include "weight.h"
20//#include "ipshell.h"
21#include "intvec.h"
22#ifdef HAVE_FACTORY
23#include "clapsing.h"
24#endif
25#include "ideals.h"
26#include "timer.h"
27#include "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->Shdl=idCopy(o->Shdl);
175  s->S=s->Shdl->m;
176  s->tailRing = o->tailRing;
177  if (o->D!=NULL) s->D=idCopy(o->D);
178  else            s->D=NULL;
179  s->ecartS=(int *)omAlloc(IDELEMS(o->Shdl)*sizeof(int));
180  memcpy(s->ecartS,o->ecartS,IDELEMS(o->Shdl)*sizeof(int));
181  s->sevS=(unsigned long *)omAlloc(IDELEMS(o->Shdl)*sizeof(unsigned long));
182  memcpy(s->sevS,o->sevS,IDELEMS(o->Shdl)*sizeof(unsigned long));
183  s->S_2_R=(int*)omAlloc(IDELEMS(o->Shdl)*sizeof(int));
184  memcpy(s->S_2_R,o->S_2_R,IDELEMS(o->Shdl)*sizeof(int));
185  s->sevT=(unsigned long *)omAlloc(o->tmax*sizeof(unsigned long));
186  memcpy(s->sevT,o->sevT,o->tmax*sizeof(unsigned long));
187  if(o->fromQ!=NULL)
188  {
189    s->fromQ=(int *)omAlloc(IDELEMS(o->Shdl)*sizeof(int));
190    memcpy(s->fromQ,o->fromQ,IDELEMS(o->Shdl)*sizeof(int));
191  }
192  else
193    s->fromQ=NULL;
194  copyT(o,s);//s->T=...
195  s->tail = pInit();
196  copyL(o,s);//s->L=...
197  s->B=initL();
198  s->kHEdge=pCopy(o->kHEdge);
199  s->kNoether=pCopy(o->kNoether);
200  if (o->NotUsedAxis!=NULL)
201  {
202    s->NotUsedAxis=(BOOLEAN *)omAlloc(currRing->N*sizeof(BOOLEAN));
203    memcpy(s->NotUsedAxis,o->NotUsedAxis,currRing->N*sizeof(BOOLEAN));
204  }
205  s->kIdeal=NULL;
206  //s->P=s->L[s->Ll+1];
207  s->P.Init(o->tailRing);
208  s->update=o->update;
209  s->posInLOldFlag=o->posInLOldFlag;
210  s->kModW = o->kModW;
211//   if (o->kModW!=NULL)
212//     s->kModW=ivCopy(o->kModW);
213//   else
214//     s->kModW=NULL;
215  s->pairtest=NULL;
216  s->sl=o->sl;
217  s->mu=o->mu;
218  s->tl=o->tl;
219  s->tmax=o->tmax;
220  s->Ll=o->Ll;
221  s->Lmax=o->Lmax;
222  s->Bl=-1;
223  s->Bmax=setmaxL;
224  s->ak=o->ak;
225  s->syzComp=o->syzComp;
226  s->LazyPass=o->LazyPass;
227  s->LazyDegree=o->LazyDegree;
228  s->HCord=o->HCord;
229  s->lastAxis=o->lastAxis;
230  s->interpt=o->interpt;
231  s->homog=o->homog;
232  s->news=o->news;
233  s->newt=o->newt;
234  s->kHEdgeFound=o->kHEdgeFound;
235  s->honey=o->honey;
236  s->sugarCrit=o->sugarCrit;
237  s->Gebauer=o->Gebauer;
238  s->noTailReduction=o->noTailReduction;
239  s->fromT=o->fromT;
240  s->noetherSet=o->noetherSet;
241  kTest_TS(s);
242  return s;
243}
244
245BOOLEAN k_factorize(poly p,ideal &rfac, ideal &fac_copy)
246{
247  int facdeg=pFDeg(p,currRing);
248  ideal fac=singclap_factorize(pCopy(p),NULL,1);
249  int fac_elems;
250#ifndef HAVE_LIBFAC_P
251  if (fac==NULL)
252  {
253    fac=idInit(1,1);
254    fac->m[0]=pCopy(p);
255    fac_elems=1;
256  }
257  else
258#endif
259    fac_elems=IDELEMS(fac);
260  rfac=fac;
261  fac_copy=idInit(fac_elems,1);
262
263  if ((fac_elems!=1)||(facdeg!=pFDeg(fac->m[0],currRing)))
264  {
265    if (TEST_OPT_DEBUG)
266    {
267      Print("-> %d factors\n",fac_elems);
268      if (fac_elems!=1)
269      {
270        pWrite(p); PrintS(" ->\n");
271        int ii=fac_elems;
272        while(ii>0) { ii--;pWrite(fac->m[ii]); }
273      }
274    }
275    else if (TEST_OPT_PROT)
276    {
277      int ii=fac_elems;
278      if (ii>1)
279      {
280        while(ii>0) { PrintS("F"); ii--; }
281      }
282    }
283#ifndef NDEBUG
284    else if (strat_fac_debug)
285    {
286      pWrite(p);
287      Print("-> %d factors\n",fac_elems);
288      if (fac_elems!=1)
289      {
290        int ii=fac_elems;
291        while(ii>0) { ii--;pWrite(fac->m[ii]); }
292      }
293    }
294#endif
295    return TRUE;
296  }
297  else
298  {
299    pDelete(&(fac->m[0]));
300    fac->m[0]=pCopy(p);
301  }
302  return FALSE;
303}
304
305static void completeReduceFac (kStrategy strat, ideal_list FL)
306{
307  int si;
308
309  strat->noTailReduction = FALSE;
310  if (TEST_OPT_PROT)
311  {
312    PrintLn();
313    if (timerv) writeTime("standard base computed:");
314  }
315  if (TEST_OPT_PROT)
316  {
317    Print("(S:%d)",strat->sl);mflush();
318  }
319  for (si=strat->sl; si>0; si--)
320  {
321    //if (strat->interpt) test_int_std(strat->kIdeal);
322    strat->S[si] = redtailBba(strat->S[si],si-1,strat);
323    if (TEST_OPT_INTSTRATEGY)
324    {
325      pCleardenom(strat->S[si]);
326    }
327    if (TEST_OPT_PROT)
328    {
329      PrintS("-");mflush();
330    }
331    ideal fac;
332    ideal fac_copy;
333
334    if (!k_factorize(strat->S[si],fac,fac_copy))
335    {
336      idDelete(&fac);
337      idDelete(&fac_copy);
338      continue;
339    }
340
341    deleteInS(si,strat);
342
343    int i;
344    for(i=IDELEMS(fac)-1;i>=0;i--)
345    {
346      kStrategy n=strat;
347      if (i>=1)
348      {
349        n=kStratCopy(strat); // includes: memset(&n->P,0,sizeof(n->P));
350        n->next=strat->next;
351        strat->next=n;
352      }
353      else
354      {
355        n->P.Init(strat->tailRing);
356      }
357
358      n->P.p=fac->m[i];
359      n->P.pLength=0;
360      n->initEcart(&n->P);
361      /* enter P.p into s and L */
362      int pos;
363      if (n->sl==-1) pos=0;
364      else pos=posInS(n,n->sl,n->P.p,n->P.ecart);
365      if (TEST_OPT_INTSTRATEGY)
366      {
367        n->P.p = redtailBba(n->P.p,pos-1,n);
368        pCleardenom(n->P.p);
369      }
370      else
371      {
372        pNorm(n->P.p);
373        n->P.p = redtailBba(n->P.p,pos-1,n);
374      }
375      n->P.pLength=0;
376      if (TEST_OPT_DEBUG)
377      {
378        PrintS("new s:");
379        wrp(n->P.p);
380        PrintLn();
381      }
382      enterpairs(n->P.p,n->sl,n->P.ecart,pos,n);
383      enterT(n->P,n);
384      n->enterS(n->P,pos,n, n->tl);
385
386      /* construct D */
387      if (IDELEMS(fac)>1)
388      {
389        if (n->D==NULL)
390        {
391          n->D=idCopy(fac_copy);
392          idSkipZeroes(n->D);
393        }
394        else
395        {
396          idTest(n->D);
397          ideal r=idAdd(n->D,fac_copy);
398          idDelete(&n->D);
399          n->D=r;
400        }
401        if (TEST_OPT_DEBUG)
402        {
403          PrintS("new D:\n");
404          iiWriteMatrix((matrix)n->D,"D",1,0);
405          PrintLn();
406        }
407      }
408#ifndef NDEBUG
409      if(strat_fac_debug)
410      {
411        int ii;
412        Print("---------------------------------------------------------------\ns(%d), set S\n",n->nr);
413        for(ii=0;ii<n->sl;ii++)
414        { Print("s(%d->S[%d]= ",n->nr,ii);pWrite(n->S[ii]);}
415        Print("s(%d), set D\n",n->nr);
416        if (n->D!=NULL)
417        {
418          for(ii=0;ii<IDELEMS(n->D);ii++)
419          { Print("s(%d->D[%d]= ",n->nr,ii);pWrite(n->D->m[ii]);}
420        }
421        else PrintS(" empty\n");
422      }
423#endif
424
425      fac_copy->m[i]=pCopy(fac->m[i]);
426      fac->m[i]=NULL;
427
428      /* check for empty sets */
429      if (n->D!=NULL)
430      {
431        int j=IDELEMS(n->D)-1;
432        while(j>=0)
433        {
434          if (n->D->m[j]!=NULL)
435          {
436            poly r=kNF(n->Shdl,NULL,n->D->m[j],0,KSTD_NF_LAZY | KSTD_NF_NONORM);
437            if (r==NULL)
438            {
439#ifndef NDEBUG
440              if(strat_fac_debug)
441              {
442                Print("empty set s(%d) because: D[%d] -> 0\n",
443                       n->nr, j);
444                Print("s(%d)->D[%d]= ",n->nr,j);pWrite(n->D->m[j]);
445              }
446#endif
447              if (TEST_OPT_DEBUG)
448              {
449                PrintS("empty set because:");
450                wrp(n->D->m[j]);
451                PrintLn();
452                messageSets(n);
453              }
454              while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
455              while (n->tl >= 0)
456              {
457                int i=n->sl;
458                while (i>=0)
459                {
460                  if (n->S[i]==n->T[n->tl].p)
461                  {
462                    n->T[n->tl].p=NULL; n->S[i]=NULL;
463                    break;
464                  }
465                  i--;
466                }
467                pDelete(&n->T[n->tl].p);
468                n->tl--;
469              }
470              memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
471              n->sl=-1;
472              if (strat==n) si=-1;
473              break;
474            }
475            else
476            {
477              pDelete(&r);
478            }
479          }
480          j--;
481        }
482      }
483      /* check for empty sets */
484      {
485        ideal_list Lj=FL;
486        while (Lj!=NULL)
487        {
488          if ((n->sl>=0)&&(n->S[0]!=NULL))
489          {
490            ideal r=kNF(n->Shdl,NULL,Lj->d,0,KSTD_NF_LAZY | KSTD_NF_NONORM);
491#ifndef NDEBUG
492              if(strat_fac_debug)
493              {
494                Print("empty set s(%d) because:L[%d]\n",n->nr,Lj->nr);
495                PrintS("L:\n");
496                iiWriteMatrix((matrix)Lj->d,"L",1,0);
497              }
498#endif
499            if (idIs0(r))
500            {
501              if (TEST_OPT_DEBUG)
502              {
503                Print("empty set because:L[%x]\n",Lj);
504              }
505              while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
506              while (n->tl >= 0)
507              {
508                int i=n->sl;
509                while (i>=0)
510                {
511                  if (n->S[i]==n->T[n->tl].p)
512                  {
513                    n->T[n->tl].p=NULL; n->S[i]=NULL;
514                    break;
515                  }
516                  i--;
517                }
518                pDelete(&n->T[n->tl].p);
519                n->tl--;
520              }
521              memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
522              n->sl=-1;
523              if (strat==n) si=-1;
524              idDelete(&r);
525              break;
526            }
527            idDelete(&r);
528          }
529          Lj=Lj->next;
530        }
531      }
532    } /* for */
533    for(i=0;i<IDELEMS(fac);i++) fac->m[i]=NULL;
534    idDelete(&fac);
535    idDelete(&fac_copy);
536    if ((strat->Ll>=0) && (strat->sl>=0)) break;
537    else si=strat->sl+1;
538  }
539}
540
541ideal bbafac (ideal F, ideal Q,intvec *w,kStrategy strat, ideal_list FL)
542{
543  int   srmax,lrmax;
544  int   olddeg,reduc=0;
545  int red_result = 1;
546  srmax = strat->sl;
547  reduc = olddeg = lrmax = 0;
548  /* compute------------------------------------------------------- */
549  if ((strat->Ll==-1) && (strat->sl>=0))
550  {
551    if (TEST_OPT_REDSB) completeReduceFac(strat,FL);
552  }
553  kTest_TS(strat);
554  while (strat->Ll >= 0)
555  {
556    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
557    if (TEST_OPT_DEBUG) messageSets(strat);
558    //test_int_std(strat->kIdeal);
559    if (strat->Ll== 0) strat->interpt=TRUE;
560    if (TEST_OPT_DEGBOUND
561    && ((strat->honey
562        && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
563      || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
564    {
565      /*
566      *stops computation if
567      * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
568      *a predefined number Kstd1_deg
569      */
570      while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
571      break;
572    }
573    /* picks the last element from the lazyset L */
574    strat->P = strat->L[strat->Ll];
575    strat->Ll--;
576    if (pNext(strat->P.p) == strat->tail)
577    {
578      /* deletes the short spoly and computes */
579      pLmFree(strat->P.p);
580      /* the real one */
581      strat->P.p = ksOldCreateSpoly(strat->P.p1,
582                                    strat->P.p2,
583                                    strat->kNoether);
584    }
585    if (strat->honey)
586    {
587      if (TEST_OPT_PROT)
588        message(strat->P.ecart+pFDeg(strat->P.p,currRing),&olddeg,&reduc,strat, red_result);
589    }
590    else
591    {
592      if (TEST_OPT_PROT)
593        message(pFDeg(strat->P.p,currRing),&olddeg,&reduc,strat, red_result);
594    }
595    /* reduction of the element choosen from L */
596    kTest_TS(strat);
597    red_result = strat->red(&strat->P,strat);
598    if (strat->P.p != NULL)
599    {
600      /* statistic */
601      if (TEST_OPT_PROT) PrintS("s");
602      ideal fac;
603      ideal fac_copy;
604
605      if (!k_factorize(strat->P.p,fac,fac_copy))
606      {
607        if (TEST_OPT_INTSTRATEGY)
608        {
609          strat->P.p = redtailBba(strat->P.p,strat->sl,strat);
610          if (strat->redTailChange) pCleardenom(strat->P.p);
611        }
612        else
613        {
614          pNorm(strat->P.p);
615          strat->P.p = redtailBba(strat->P.p,strat->sl,strat);
616        }
617        if (strat->redTailChange)
618        {
619          idDelete(&fac);
620          idDelete(&fac_copy);
621          if (!k_factorize(strat->P.p,fac,fac_copy))
622          {
623            pDelete(&(fac->m[0]));
624            fac->m[0]=strat->P.p;
625            strat->P.p=NULL;
626          }
627          else
628          {
629            pDelete(&strat->P.p);
630          }
631        }
632      }
633      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
634      int i;
635
636      for(i=IDELEMS(fac)-1;i>=0;i--)
637      {
638        int ii;
639        kStrategy n=strat;
640        if (i>=1)
641        {
642          n=kStratCopy(strat); // includes memset(&n->P,0,sizeof(n->P));
643          kTest_TS(n);
644          n->next=strat->next;
645          strat->next=n;
646        }
647        else
648        {
649          n->P.Init(strat->tailRing);
650        }
651
652        n->P.p=fac->m[i];
653        n->initEcart(&n->P);
654        kTest_TS(n);
655
656        /* enter P.p into s and L */
657        int pos;
658        if (n->sl==-1) pos=0;
659        else pos=posInS(n,n->sl,n->P.p,n->P.ecart);
660
661        // we have already reduced all elements from fac....
662        if (TEST_OPT_INTSTRATEGY)
663        {
664          n->P.p = redtailBba(n->P.p,pos-1,n);
665          if (n->redTailChange)
666          {
667            pCleardenom(n->P.p);
668            n->P.pLength=0;
669          }
670        }
671        else
672        {
673          pNorm(n->P.p);
674          n->P.p = redtailBba(n->P.p,pos-1,n);
675          if (n->redTailChange)
676          {
677            n->P.pLength=0;
678          }
679        }
680        kTest_TS(n);
681
682        if (TEST_OPT_DEBUG)
683        {
684          PrintS("new s:");
685          wrp(n->P.p);
686          PrintLn();
687        }
688        enterpairs(n->P.p,n->sl,n->P.ecart,pos,n);
689        enterT(n->P,n);
690        n->enterS(n->P,pos,n, n->tl);
691        {
692          int i=n->Ll;
693          for(;i>=0;i--)
694          {
695            n->L[i].i_r1= -1;
696            for(ii=0; ii<=n->tl; ii++)
697            {
698              if (n->R[ii]->p==n->L[i].p1)  { n->L[i].i_r1=ii;break; }
699            }
700            n->L[i].i_r2= -1;
701            for(ii=0; ii<=n->tl; ii++)
702            {
703              if (n->R[ii]->p==n->L[i].p2)  { n->L[i].i_r2=ii;break; }
704            }
705          }
706        }
707        kTest_TS(n);
708        if (n->sl>srmax) srmax = n->sl;
709
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,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,0);
825                }
826#endif
827                if (TEST_OPT_DEBUG)
828                {
829                  Print("empty set because:L[%x]\n",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  exitBuchMora(strat);
876  if (TEST_OPT_WEIGHTM)
877  {
878    pRestoreDegProcs(pFDegOld, pLDegOld);
879    if (ecartWeights)
880    {
881      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
882      ecartWeights=NULL;
883    }
884  }
885  if (TEST_OPT_PROT) { PrintLn(); messageStat(srmax,lrmax,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=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())
902    strat->LazyPass=20;
903  else
904    strat->LazyPass=2;
905  strat->LazyDegree = 1;
906  strat->ak = idRankFreeModule(F);
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      pFDegOld = pFDeg;
924      pLDegOld = pLDeg;
925      pSetDegProcs(kModDeg);
926      toReset = TRUE;
927    }
928    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,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[%x] because:L[%x]\n",Lj,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(pFDegOld, pLDegOld);
1027    kModW = NULL;
1028  }
1029  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.