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

spielwiese
Last change on this file since 6c55ae was 6c55ae, checked in by Hans Schönemann <hannes@…>, 15 years ago
*hannes: chainCrit ->strat git-svn-id: file:///usr/local/Singular/svn/trunk@11439 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 25.0 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: kstdfac.cc,v 1.16 2009-02-22 17:38:18 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->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->kIdeal=NULL;
208  //s->P=s->L[s->Ll+1];
209  s->P.Init(o->tailRing);
210  s->update=o->update;
211  s->posInLOldFlag=o->posInLOldFlag;
212  s->kModW = o->kModW;
213//   if (o->kModW!=NULL)
214//     s->kModW=ivCopy(o->kModW);
215//   else
216//     s->kModW=NULL;
217  s->pairtest=NULL;
218  s->sl=o->sl;
219  s->mu=o->mu;
220  s->tl=o->tl;
221  s->tmax=o->tmax;
222  s->Ll=o->Ll;
223  s->Lmax=o->Lmax;
224  s->Bl=-1;
225  s->Bmax=setmaxL;
226  s->ak=o->ak;
227  s->syzComp=o->syzComp;
228  s->LazyPass=o->LazyPass;
229  s->LazyDegree=o->LazyDegree;
230  s->HCord=o->HCord;
231  s->lastAxis=o->lastAxis;
232  s->interpt=o->interpt;
233  s->homog=o->homog;
234  s->news=o->news;
235  s->newt=o->newt;
236  s->kHEdgeFound=o->kHEdgeFound;
237  s->honey=o->honey;
238  s->sugarCrit=o->sugarCrit;
239  s->Gebauer=o->Gebauer;
240  s->noTailReduction=o->noTailReduction;
241  s->fromT=o->fromT;
242  s->noetherSet=o->noetherSet;
243  kTest_TS(s);
244  return s;
245}
246
247BOOLEAN k_factorize(poly p,ideal &rfac, ideal &fac_copy)
248{
249  int facdeg=pFDeg(p,currRing);
250  ideal fac=singclap_factorize(pCopy(p),NULL,1);
251  int fac_elems;
252#ifndef HAVE_LIBFAC_P
253  if (fac==NULL)
254  {
255    fac=idInit(1,1);
256    fac->m[0]=pCopy(p);
257    fac_elems=1;
258  }
259  else
260#endif
261    fac_elems=IDELEMS(fac);
262  rfac=fac;
263  fac_copy=idInit(fac_elems,1);
264
265  if ((fac_elems!=1)||(facdeg!=pFDeg(fac->m[0],currRing)))
266  {
267    if (TEST_OPT_DEBUG)
268    {
269      Print("-> %d factors\n",fac_elems);
270      if (fac_elems!=1)
271      {
272        pWrite(p); PrintS(" ->\n");
273        int ii=fac_elems;
274        while(ii>0) { ii--;pWrite(fac->m[ii]); }
275      }
276    }
277    else if (TEST_OPT_PROT)
278    {
279      int ii=fac_elems;
280      if (ii>1)
281      {
282        while(ii>0) { PrintS("F"); ii--; }
283      }
284    }
285#ifndef NDEBUG
286    else if (strat_fac_debug)
287    {
288      pWrite(p);
289      Print("-> %d factors\n",fac_elems);
290      if (fac_elems!=1)
291      {
292        int ii=fac_elems;
293        while(ii>0) { ii--;pWrite(fac->m[ii]); }
294      }
295    }
296#endif
297    return TRUE;
298  }
299  else
300  {
301    pDelete(&(fac->m[0]));
302    fac->m[0]=pCopy(p);
303  }
304  return FALSE;
305}
306
307static void completeReduceFac (kStrategy strat, ideal_list FL)
308{
309  int si;
310
311  strat->noTailReduction = FALSE;
312  if (TEST_OPT_PROT)
313  {
314    PrintLn();
315    if (timerv) writeTime("standard base computed:");
316  }
317  if (TEST_OPT_PROT)
318  {
319    Print("(S:%d)",strat->sl);mflush();
320  }
321  for (si=strat->sl; si>0; si--)
322  {
323    //if (strat->interpt) test_int_std(strat->kIdeal);
324    strat->S[si] = redtailBba(strat->S[si],si-1,strat);
325    if (TEST_OPT_INTSTRATEGY)
326    {
327      pCleardenom(strat->S[si]);
328    }
329    if (TEST_OPT_PROT)
330    {
331      PrintS("-");mflush();
332    }
333    ideal fac;
334    ideal fac_copy;
335
336    if (!k_factorize(strat->S[si],fac,fac_copy))
337    {
338      idDelete(&fac);
339      idDelete(&fac_copy);
340      continue;
341    }
342
343    deleteInS(si,strat);
344
345    int i;
346    for(i=IDELEMS(fac)-1;i>=0;i--)
347    {
348      kStrategy n=strat;
349      if (i>=1)
350      {
351        n=kStratCopy(strat); // includes: memset(&n->P,0,sizeof(n->P));
352        n->next=strat->next;
353        strat->next=n;
354      }
355      else
356      {
357        n->P.Init(strat->tailRing);
358      }
359
360      n->P.p=fac->m[i];
361      n->P.pLength=0;
362      n->initEcart(&n->P);
363      /* enter P.p into s and L */
364      int pos;
365      if (n->sl==-1) pos=0;
366      else pos=posInS(n,n->sl,n->P.p,n->P.ecart);
367      if (TEST_OPT_INTSTRATEGY)
368      {
369        n->P.p = redtailBba(n->P.p,pos-1,n);
370        pCleardenom(n->P.p);
371      }
372      else
373      {
374        pNorm(n->P.p);
375        n->P.p = redtailBba(n->P.p,pos-1,n);
376      }
377      n->P.pLength=0;
378      if (TEST_OPT_DEBUG)
379      {
380        PrintS("new s:");
381        wrp(n->P.p);
382        PrintLn();
383      }
384      enterpairs(n->P.p,n->sl,n->P.ecart,pos,n);
385      enterT(n->P,n);
386      n->enterS(n->P,pos,n, n->tl);
387
388      /* construct D */
389      if (IDELEMS(fac)>1)
390      {
391        if (n->D==NULL)
392        {
393          n->D=idCopy(fac_copy);
394          idSkipZeroes(n->D);
395        }
396        else
397        {
398          idTest(n->D);
399          ideal r=idAdd(n->D,fac_copy);
400          idDelete(&n->D);
401          n->D=r;
402        }
403        if (TEST_OPT_DEBUG)
404        {
405          PrintS("new D:\n");
406          iiWriteMatrix((matrix)n->D,"D",1,0);
407          PrintLn();
408        }
409      }
410#ifndef NDEBUG
411      if(strat_fac_debug)
412      {
413        int ii;
414        Print("---------------------------------------------------------------\ns(%d), set S\n",n->nr);
415        for(ii=0;ii<n->sl;ii++)
416        { Print("s(%d->S[%d]= ",n->nr,ii);pWrite(n->S[ii]);}
417        Print("s(%d), set D\n",n->nr);
418        if (n->D!=NULL)
419        {
420          for(ii=0;ii<IDELEMS(n->D);ii++)
421          { Print("s(%d->D[%d]= ",n->nr,ii);pWrite(n->D->m[ii]);}
422        }
423        else PrintS(" empty\n");
424      }
425#endif
426
427      fac_copy->m[i]=pCopy(fac->m[i]);
428      fac->m[i]=NULL;
429
430      /* check for empty sets */
431      if (n->D!=NULL)
432      {
433        int j=IDELEMS(n->D)-1;
434        while(j>=0)
435        {
436          if (n->D->m[j]!=NULL)
437          {
438            poly r=kNF(n->Shdl,NULL,n->D->m[j],0,KSTD_NF_LAZY | KSTD_NF_NONORM);
439            if (r==NULL)
440            {
441#ifndef NDEBUG
442              if(strat_fac_debug)
443              {
444                Print("empty set s(%d) because: D[%d] -> 0\n",
445                       n->nr, j);
446                Print("s(%d)->D[%d]= ",n->nr,j);pWrite(n->D->m[j]);
447              }
448#endif
449              if (TEST_OPT_DEBUG)
450              {
451                PrintS("empty set because:");
452                wrp(n->D->m[j]);
453                PrintLn();
454                messageSets(n);
455              }
456              while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
457              while (n->tl >= 0)
458              {
459                int i=n->sl;
460                while (i>=0)
461                {
462                  if (n->S[i]==n->T[n->tl].p)
463                  {
464                    n->T[n->tl].p=NULL; n->S[i]=NULL;
465                    break;
466                  }
467                  i--;
468                }
469                pDelete(&n->T[n->tl].p);
470                n->tl--;
471              }
472              memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
473              n->sl=-1;
474              if (strat==n) si=-1;
475              break;
476            }
477            else
478            {
479              pDelete(&r);
480            }
481          }
482          j--;
483        }
484      }
485      /* check for empty sets */
486      {
487        ideal_list Lj=FL;
488        while (Lj!=NULL)
489        {
490          if ((n->sl>=0)&&(n->S[0]!=NULL))
491          {
492            ideal r=kNF(n->Shdl,NULL,Lj->d,0,KSTD_NF_LAZY | KSTD_NF_NONORM);
493#ifndef NDEBUG
494              if(strat_fac_debug)
495              {
496                Print("empty set s(%d) because:L[%d]\n",n->nr,Lj->nr);
497                PrintS("L:\n");
498                iiWriteMatrix((matrix)Lj->d,"L",1,0);
499              }
500#endif
501            if (idIs0(r))
502            {
503              if (TEST_OPT_DEBUG)
504              {
505                Print("empty set because:L[%x]\n",Lj);
506              }
507              while (n->Ll >= 0) deleteInL(n->L,&n->Ll,n->Ll,n);
508              while (n->tl >= 0)
509              {
510                int i=n->sl;
511                while (i>=0)
512                {
513                  if (n->S[i]==n->T[n->tl].p)
514                  {
515                    n->T[n->tl].p=NULL; n->S[i]=NULL;
516                    break;
517                  }
518                  i--;
519                }
520                pDelete(&n->T[n->tl].p);
521                n->tl--;
522              }
523              memset(n->Shdl->m,0,IDELEMS(n->Shdl)*sizeof(poly));
524              n->sl=-1;
525              if (strat==n) si=-1;
526              idDelete(&r);
527              break;
528            }
529            idDelete(&r);
530          }
531          Lj=Lj->next;
532        }
533      }
534    } /* for */
535    for(i=0;i<IDELEMS(fac);i++) fac->m[i]=NULL;
536    idDelete(&fac);
537    idDelete(&fac_copy);
538    if ((strat->Ll>=0) && (strat->sl>=0)) break;
539    else si=strat->sl+1;
540  }
541}
542
543ideal bbafac (ideal F, ideal Q,intvec *w,kStrategy strat, ideal_list FL)
544{
545  int   srmax,lrmax;
546  int   olddeg,reduc=0;
547  int red_result = 1;
548  srmax = strat->sl;
549  reduc = olddeg = lrmax = 0;
550  /* compute------------------------------------------------------- */
551  if ((strat->Ll==-1) && (strat->sl>=0))
552  {
553    if (TEST_OPT_REDSB) completeReduceFac(strat,FL);
554  }
555  kTest_TS(strat);
556  while (strat->Ll >= 0)
557  {
558    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
559    if (TEST_OPT_DEBUG) messageSets(strat);
560    //test_int_std(strat->kIdeal);
561    if (strat->Ll== 0) strat->interpt=TRUE;
562    if (TEST_OPT_DEGBOUND
563    && ((strat->honey
564        && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p,currRing)>Kstd1_deg))
565      || ((!strat->honey) && (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+pFDeg(strat->P.p,currRing),&olddeg,&reduc,strat, red_result);
591    }
592    else
593    {
594      if (TEST_OPT_PROT)
595        message(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) pCleardenom(strat->P.p);
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            pCleardenom(n->P.p);
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        if (n->sl>srmax) srmax = n->sl;
711
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,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,0);
827                }
828#endif
829                if (TEST_OPT_DEBUG)
830                {
831                  Print("empty set because:L[%x]\n",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    kTest_TS(strat);
868    if ((strat->Ll==-1) && (strat->sl>=0))
869    {
870      if (TEST_OPT_REDSB) completeReduceFac(strat,FL);
871    }
872    kTest_TS(strat);
873  }
874  if (TEST_OPT_DEBUG) messageSets(strat);
875  /* complete reduction of the standard basis--------- */
876  /* release temp data-------------------------------- */
877  exitBuchMora(strat);
878  if (TEST_OPT_WEIGHTM)
879  {
880    pRestoreDegProcs(pFDegOld, pLDegOld);
881    if (ecartWeights)
882    {
883      omFreeSize((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
884      ecartWeights=NULL;
885    }
886  }
887  if (TEST_OPT_PROT) { PrintLn(); messageStat(srmax,lrmax,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=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())
904    strat->LazyPass=20;
905  else
906    strat->LazyPass=2;
907  strat->LazyDegree = 1;
908  strat->ak = idRankFreeModule(F);
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      pFDegOld = pFDeg;
926      pLDegOld = pLDeg;
927      pSetDegProcs(kModDeg);
928      toReset = TRUE;
929    }
930    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,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[%x] because:L[%x]\n",Lj,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(pFDegOld, pLDegOld);
1029    kModW = NULL;
1030  }
1031  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.