source: git/kernel/kstdfac.cc @ 3ad53dd

spielwiese
Last change on this file since 3ad53dd was 18ff4c, checked in by Hans Schönemann <hannes@…>, 17 years ago
*hannes: NF, code cleanup git-svn-id: file:///usr/local/Singular/svn/trunk@10253 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 24.8 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: kstdfac.cc,v 1.11 2007-07-25 10:53:15 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      if (TEST_OPT_DEBUG)
376      {
377        PrintS("new s:");
378        wrp(n->P.p);
379        PrintLn();
380      }
381      enterpairs(n->P.p,n->sl,n->P.ecart,pos,n);
382      enterT(n->P,n);
383      n->enterS(n->P,pos,n, n->tl);
384
385      /* construct D */
386      if (IDELEMS(fac)>1)
387      {
388        if (n->D==NULL)
389        {
390          n->D=idCopy(fac_copy);
391          idSkipZeroes(n->D);
392        }
393        else
394        {
395          idTest(n->D);
396          ideal r=idAdd(n->D,fac_copy);
397          idDelete(&n->D);
398          n->D=r;
399        }
400        if (TEST_OPT_DEBUG)
401        {
402          PrintS("new D:\n");
403          iiWriteMatrix((matrix)n->D,"D",1,0);
404          PrintLn();
405        }
406      }
407#ifndef NDEBUG
408      if(strat_fac_debug)
409      {
410        int ii;
411        Print("---------------------------------------------------------------\ns(%d), set S\n",n->nr);
412        for(ii=0;ii<n->sl;ii++)
413        { Print("s(%d->S[%d]= ",n->nr,ii);pWrite(n->S[ii]);}
414        Print("s(%d), set D\n",n->nr);
415        if (n->D!=NULL)
416        {
417          for(ii=0;ii<IDELEMS(n->D);ii++)
418          { Print("s(%d->D[%d]= ",n->nr,ii);pWrite(n->D->m[ii]);}
419        }
420        else PrintS(" empty\n");
421      }
422#endif
423
424      fac_copy->m[i]=pCopy(fac->m[i]);
425      fac->m[i]=NULL;
426
427      /* check for empty sets */
428      if (n->D!=NULL)
429      {
430        int j=IDELEMS(n->D)-1;
431        while(j>=0)
432        {
433          if (n->D->m[j]!=NULL)
434          {
435            poly r=kNF(n->Shdl,NULL,n->D->m[j],0,KSTD_NF_LAZY | KSTD_NF_NONORM);
436            if (r==NULL)
437            {
438#ifndef NDEBUG
439              if(strat_fac_debug)
440              {
441                Print("empty set s(%d) because: D[%d] -> 0\n",
442                       n->nr, j);
443                Print("s(%d)->D[%d]= ",n->nr,j);pWrite(n->D->m[j]);
444              }
445#endif
446              if (TEST_OPT_DEBUG)
447              {
448                PrintS("empty set because:");
449                wrp(n->D->m[j]);
450                PrintLn();
451                messageSets(n);
452              }
453              while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
454              while (n->tl >= 0)
455              {
456                int i=n->sl;
457                while (i>=0)
458                {
459                  if (n->S[i]==n->T[n->tl].p)
460                  {
461                    n->T[n->tl].p=NULL; n->S[i]=NULL;
462                    break;
463                  }
464                  i--;
465                }
466                pDelete(&n->T[n->tl].p);
467                n->tl--;
468              }
469              memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
470              n->sl=-1;
471              if (strat==n) si=-1;
472              break;
473            }
474            else
475            {
476              pDelete(&r);
477            }
478          }
479          j--;
480        }
481      }
482      /* check for empty sets */
483      {
484        ideal_list Lj=FL;
485        while (Lj!=NULL)
486        {
487          if ((n->sl>=0)&&(n->S[0]!=NULL))
488          {
489            ideal r=kNF(n->Shdl,NULL,Lj->d,0,KSTD_NF_LAZY | KSTD_NF_NONORM);
490#ifndef NDEBUG
491              if(strat_fac_debug)
492              {
493                Print("empty set s(%d) because:L[%d]\n",n->nr,Lj->nr);
494                PrintS("L:\n");
495                iiWriteMatrix((matrix)Lj->d,"L",1,0);
496              }
497#endif
498            if (idIs0(r))
499            {
500              if (TEST_OPT_DEBUG)
501              {
502                Print("empty set because:L[%x]\n",Lj);
503              }
504              while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
505              while (n->tl >= 0)
506              {
507                int i=n->sl;
508                while (i>=0)
509                {
510                  if (n->S[i]==n->T[n->tl].p)
511                  {
512                    n->T[n->tl].p=NULL; n->S[i]=NULL;
513                    break;
514                  }
515                  i--;
516                }
517                pDelete(&n->T[n->tl].p);
518                n->tl--;
519              }
520              memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
521              n->sl=-1;
522              if (strat==n) si=-1;
523              idDelete(&r);
524              break;
525            }
526            idDelete(&r);
527          }
528          Lj=Lj->next;
529        }
530      }
531    } /* for */
532    for(i=0;i<IDELEMS(fac);i++) fac->m[i]=NULL;
533    idDelete(&fac);
534    idDelete(&fac_copy);
535    if ((strat->Ll>=0) && (strat->sl>=0)) break;
536    else si=strat->sl+1;
537  }
538}
539
540ideal bbafac (ideal F, ideal Q,intvec *w,kStrategy strat, ideal_list FL)
541{
542  int   srmax,lrmax;
543  int   olddeg,reduc=0;
544  int red_result = 1;
545  srmax = strat->sl;
546  reduc = olddeg = lrmax = 0;
547  /* compute------------------------------------------------------- */
548  if ((strat->Ll==-1) && (strat->sl>=0))
549  {
550    if (TEST_OPT_REDSB) completeReduceFac(strat,FL);
551  }
552  kTest_TS(strat);
553  while (strat->Ll >= 0)
554  {
555    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
556    if (TEST_OPT_DEBUG) messageSets(strat);
557    //test_int_std(strat->kIdeal);
558    if (strat->Ll== 0) strat->interpt=TRUE;
559    if (TEST_OPT_DEGBOUND
560    && ((strat->honey
561        && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
562      || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))))
563    {
564      /*
565      *stops computation if
566      * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
567      *a predefined number Kstd1_deg
568      */
569      while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
570      break;
571    }
572    /* picks the last element from the lazyset L */
573    strat->P = strat->L[strat->Ll];
574    strat->Ll--;
575    if (pNext(strat->P.p) == strat->tail)
576    {
577      /* deletes the short spoly and computes */
578      pLmFree(strat->P.p);
579      /* the real one */
580      strat->P.p = ksOldCreateSpoly(strat->P.p1,
581                                    strat->P.p2,
582                                    strat->kNoether);
583    }
584    if (strat->honey)
585    {
586      if (TEST_OPT_PROT)
587        message(strat->P.ecart+pFDeg(strat->P.p,currRing),&olddeg,&reduc,strat, red_result);
588    }
589    else
590    {
591      if (TEST_OPT_PROT)
592        message(pFDeg(strat->P.p,currRing),&olddeg,&reduc,strat, red_result);
593    }
594    /* reduction of the element choosen from L */
595    kTest_TS(strat);
596    red_result = strat->red(&strat->P,strat);
597    if (strat->P.p != NULL)
598    {
599      /* statistic */
600      if (TEST_OPT_PROT) PrintS("s");
601      ideal fac;
602      ideal fac_copy;
603
604      if (!k_factorize(strat->P.p,fac,fac_copy))
605      {
606        if (TEST_OPT_INTSTRATEGY)
607        {
608          strat->P.p = redtailBba(strat->P.p,strat->sl,strat);
609          if (strat->redTailChange) pCleardenom(strat->P.p);
610        }
611        else
612        {
613          pNorm(strat->P.p);
614          strat->P.p = redtailBba(strat->P.p,strat->sl,strat);
615        }
616        if (strat->redTailChange)
617        {
618          idDelete(&fac);
619          idDelete(&fac_copy);
620          if (!k_factorize(strat->P.p,fac,fac_copy))
621          {
622            pDelete(&(fac->m[0]));
623            fac->m[0]=strat->P.p;
624            strat->P.p=NULL;
625          }
626          else
627          {
628            pDelete(&strat->P.p);
629          }
630        }
631      }
632      if (strat->P.lcm!=NULL) pLmFree(strat->P.lcm);
633      int i;
634
635      for(i=IDELEMS(fac)-1;i>=0;i--)
636      {
637        int ii;
638        kStrategy n=strat;
639        if (i>=1)
640        {
641          n=kStratCopy(strat); // includes memset(&n->P,0,sizeof(n->P));
642          kTest_TS(n);
643          n->next=strat->next;
644          strat->next=n;
645        }
646        else
647        {
648          n->P.Init(strat->tailRing);
649        }
650
651        n->P.p=fac->m[i];
652        n->initEcart(&n->P);
653        kTest_TS(n);
654
655        /* enter P.p into s and L */
656        int pos;
657        if (n->sl==-1) pos=0;
658        else pos=posInS(n,n->sl,n->P.p,n->P.ecart);
659
660        // we have already reduced all elements from fac....
661        if (TEST_OPT_INTSTRATEGY)
662        {
663          n->P.p = redtailBba(n->P.p,pos-1,n);
664          if (n->redTailChange) pCleardenom(n->P.p);
665        }
666        else
667        {
668          pNorm(n->P.p);
669          n->P.p = redtailBba(n->P.p,pos-1,n);
670        }
671        kTest_TS(n);
672
673        if (TEST_OPT_DEBUG)
674        {
675          PrintS("new s:");
676          wrp(n->P.p);
677          PrintLn();
678        }
679        enterpairs(n->P.p,n->sl,n->P.ecart,pos,n);
680        enterT(n->P,n);
681        n->enterS(n->P,pos,n, n->tl);
682        {
683          int i=n->Ll;
684          for(;i>=0;i--)
685          {
686            n->L[i].i_r1= -1;
687            for(ii=0; ii<=n->tl; ii++)
688            {
689              if (n->R[ii]->p==n->L[i].p1)  { n->L[i].i_r1=ii;break; }
690            }
691            n->L[i].i_r2= -1;
692            for(ii=0; ii<=n->tl; ii++)
693            {
694              if (n->R[ii]->p==n->L[i].p2)  { n->L[i].i_r2=ii;break; }
695            }
696          }
697        }
698        kTest_TS(n);
699        if (n->sl>srmax) srmax = n->sl;
700
701        /* construct D */
702        if (IDELEMS(fac)>1)
703        {
704          if (n->D==NULL)
705          {
706            n->D=idCopy(fac_copy);
707            idSkipZeroes(n->D);
708          }
709          else
710          {
711            idTest(n->D);
712            ideal r=idAdd(n->D,fac_copy);
713            idDelete(&n->D);
714            n->D=r;
715          }
716          if (TEST_OPT_DEBUG)
717          {
718            PrintS("new D:\n");
719            iiWriteMatrix((matrix)n->D,"D",1,0);
720            PrintLn();
721          }
722        }
723#ifndef NDEBUG
724        if(strat_fac_debug)
725        {
726          int ii;
727          Print("-------------------------------------------------------------\ns(%d), set S\n",n->nr);
728          for(ii=0;ii<n->sl;ii++)
729          { Print("s(%d->S[%d]= ",n->nr,ii);pWrite(n->S[ii]);}
730          Print("s(%d), set D\n",n->nr);
731          if (n->D!=NULL)
732          {
733            for(ii=0;ii<IDELEMS(n->D);ii++)
734            { Print("s(%d->D[%d]= ",n->nr,ii);pWrite(n->D->m[ii]);}
735          }
736          else PrintS(" empty\n");
737        }
738#endif
739
740        fac_copy->m[i]=pCopy(fac->m[i]);
741        fac->m[i]=NULL;
742
743        /* check for empty sets */
744        if (n->D!=NULL)
745        {
746          int j=IDELEMS(n->D)-1;
747          while(j>=0)
748          {
749            if (n->D->m[j]!=NULL)
750            {
751              poly r=kNF(n->Shdl,NULL,n->D->m[j],0,KSTD_NF_LAZY | KSTD_NF_NONORM);
752              if (r==NULL)
753              {
754#ifndef NDEBUG
755                if(strat_fac_debug)
756                {
757                  Print("empty set s(%d) because: D[%d] -> 0\n",
758                       n->nr, j);
759                  Print("s(%d)->D[%d]= ",n->nr,j);pWrite(n->D->m[j]);
760                }
761#endif
762                if (TEST_OPT_DEBUG)
763                {
764                  PrintS("empty set because:");
765                  wrp(n->D->m[j]);
766                  PrintLn();
767                  messageSets(n);
768                }
769                //if (n->Ll >=0) Print("Ll:%d|",n->Ll);
770                while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
771                //if (n->tl >=0) Print("tl:%d|",n->tl);
772                while (n->tl >= 0)
773                {
774                  int i=n->sl;
775                  while (i>=0)
776                  {
777                    if (n->S[i]==n->T[n->tl].p)
778                    {
779                      n->T[n->tl].p=NULL; n->S[i]=NULL;
780                      break;
781                    }
782                    i--;
783                  }
784                  pDelete(&n->T[n->tl].p);
785                  n->tl--;
786                }
787                memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
788                n->sl=-1;
789                break;
790              }
791              else
792              {
793                pDelete(&r);
794              }
795            }
796            j--;
797          }
798        }
799
800        /* check for empty sets */
801        {
802          ideal_list Lj=FL;
803          while (Lj!=NULL)
804          {
805            if ((n->sl>=0)&&(n->S[0]!=NULL))
806            {
807              ideal r=kNF(n->Shdl,NULL,Lj->d,0,KSTD_NF_LAZY | KSTD_NF_NONORM);
808              if (idIs0(r))
809              {
810#ifndef NDEBUG
811                if(strat_fac_debug)
812                {
813                  Print("empty set s(%d) because:L[%d]\n",n->nr,Lj->nr);
814                  PrintS("L:\n");
815                  iiWriteMatrix((matrix)Lj->d,"L",1,0);
816                }
817#endif
818                if (TEST_OPT_DEBUG)
819                {
820                  Print("empty set because:L[%x]\n",Lj);
821                }
822                while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
823                while (n->tl >= 0)
824                {
825                  int i=n->sl;
826                  while (i>=0)
827                  {
828                    if (n->S[i]==n->T[n->tl].p)
829                    {
830                      n->T[n->tl].p=NULL; n->S[i]=NULL;
831                      break;
832                    }
833                    i--;
834                  }
835                  pDelete(&n->T[n->tl].p);
836                  n->tl--;
837                }
838                memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
839                n->sl=-1;
840                idDelete(&r);
841                break;
842              }
843              idDelete(&r);
844            }
845            Lj=Lj->next;
846          }
847        }
848      } /* for */
849      for(i=0;i<IDELEMS(fac);i++) fac->m[i]=NULL;
850      idDelete(&fac);
851      idDelete(&fac_copy);
852    }
853#ifdef KDEBUG
854    strat->P.lcm=NULL;
855#endif
856    kTest_TS(strat);
857    if ((strat->Ll==-1) && (strat->sl>=0))
858    {
859      if (TEST_OPT_REDSB) completeReduceFac(strat,FL);
860    }
861    kTest_TS(strat);
862  }
863  if (TEST_OPT_DEBUG) messageSets(strat);
864  /* complete reduction of the standard basis--------- */
865  /* release temp data-------------------------------- */
866  exitBuchMora(strat);
867  if (TEST_OPT_WEIGHTM)
868  {
869    pRestoreDegProcs(pFDegOld, pLDegOld);
870    if (ecartWeights)
871    {
872      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
873      ecartWeights=NULL;
874    }
875  }
876  if (TEST_OPT_PROT) { PrintLn(); messageStat(srmax,lrmax,0,strat); }
877  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
878  return (strat->Shdl);
879}
880#endif
881
882ideal_list kStdfac(ideal F, ideal Q, tHomog h,intvec ** w,ideal D)
883{
884#ifdef HAVE_FACTORY
885  ideal r;
886  BOOLEAN b=pLexOrder,toReset=FALSE;
887  BOOLEAN delete_w=(w==NULL);
888  kStrategy strat=new skStrategy;
889  kStrategy orgstrat=strat;
890  ideal_list L=NULL;
891
892  if (rField_has_simple_inverse())
893    strat->LazyPass=20;
894  else
895    strat->LazyPass=2;
896  strat->LazyDegree = 1;
897  strat->ak = idRankFreeModule(F);
898  if ((h==testHomog))
899  {
900    if (strat->ak==0)
901    {
902      h = (tHomog)idHomIdeal(F,Q);
903      w=NULL;
904    }
905    else
906      h = (tHomog)idHomModule(F,Q,w);
907  }
908  if (h==isHomog)
909  {
910    if ((w!=NULL) && (*w!=NULL))
911    {
912      kModW = *w;
913      strat->kModW = *w;
914      pFDegOld = pFDeg;
915      pLDegOld = pLDeg;
916      pSetDegProcs(kModDeg);
917      toReset = TRUE;
918    }
919    pLexOrder = TRUE;
920    strat->LazyPass*=2;
921  }
922  strat->homog=h;
923  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
924  initBuchMoraPos(strat);
925  initBba(F,strat);
926  initBuchMora(F, Q,strat);
927  if (D!=NULL)
928  {
929    strat->D=idCopy(D);
930  }
931// Ende der Initalisierung
932  while (strat!=NULL)
933  {
934    if (TEST_OPT_DEBUG)
935      PrintS("====================================\n");
936    if (w!=NULL)
937      r=bbafac(F,Q,*w,strat,L);
938    else
939      r=bbafac(F,Q,NULL,strat,L);
940#ifdef KDEBUG
941    int i;
942    for (i=0; i<IDELEMS(r); i++) pTest(r->m[i]);
943#endif
944    idSkipZeroes(r);
945    // Testausgabe:
946    //if (!idIs0(r))
947    //{
948    //  PrintS("===================================================\n");
949    //  iiWriteMatrix((matrix)r,"S",1,0);
950    //  PrintS("\n===================================================\n");
951    //}
952    //else
953    //{
954    //  PrintS("=========empty============================\n");
955    //}
956    if(!idIs0(r))
957    {
958      ideal_list LL=(ideal_list)omAlloc(sizeof(*LL));
959      LL->d=r;
960#ifndef NDEBUG
961      LL->nr=strat->nr;
962#endif
963      LL->next=L;
964      L=LL;
965    }
966    strat=strat->next;
967  }
968  /* check for empty sets */
969  if (L!=NULL)
970  {
971    ideal_list Lj=L->next;
972    ideal_list Lj_prev=L;
973    while (Lj!=NULL)
974    {
975      ideal_list Li=L;
976      while(Li!=Lj)
977      {
978        ideal r=kNF(Lj->d,NULL,Li->d,0,KSTD_NF_LAZY | KSTD_NF_NONORM);
979        if (idIs0(r))
980        {
981#ifndef NDEBUG
982          if(strat_fac_debug)
983          {
984            Print("empty set L(%d) because:L(%d)\n",Lj->nr,Li->nr);
985          }
986#endif
987          if (TEST_OPT_DEBUG)
988          {
989            Print("empty set L[%x] because:L[%x]\n",Lj,Li);
990          }
991          // delete L[j],
992          Li=L; 
993          if (Lj_prev!=NULL)
994          {
995            Lj=Lj_prev;
996            if (Lj==L) Lj_prev=NULL;
997            else
998            {
999              Lj_prev=L;
1000              while(Lj_prev->next!=Lj) Lj_prev=Lj_prev->next;
1001            }
1002          }
1003          else Lj=NULL;
1004        }
1005        else
1006        {
1007          Li=Li->next;
1008        }
1009        idDelete (&r);
1010      }
1011      if (Lj!=NULL) Lj=Lj->next;
1012    }
1013  }
1014// Ende: aufraeumen
1015  if (toReset)
1016  {
1017    pRestoreDegProcs(pFDegOld, pLDegOld);
1018    kModW = NULL;
1019  }
1020  pLexOrder = b;
1021  delete(strat);
1022  strat=orgstrat;
1023  while (strat!=NULL)
1024  {
1025    orgstrat=strat->next;
1026    delete(strat);
1027    strat=orgstrat;
1028  }
1029  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
1030  return L;
1031#else
1032  return NULL;
1033#endif
1034}
Note: See TracBrowser for help on using the repository browser.