source: git/Singular/kstd2.cc @ 2933bb

fieker-DuValspielwiese
Last change on this file since 2933bb was 2933bb, checked in by Olaf Bachmann <obachman@…>, 25 years ago
* reductions only with T git-svn-id: file:///usr/local/Singular/svn/trunk@3667 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 43.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: kstd2.cc,v 1.28 1999-09-27 12:52:49 obachman Exp $ */
5/*
6*  ABSTRACT -  Kernel: alg. of Buchberger
7*/
8
9#include "mod2.h"
10#include "tok.h"
11#include "mmemory.h"
12#include "polys.h"
13#include "ideals.h"
14#include "febase.h"
15#include "kutil.h"
16#include "kstd1.h"
17#include "kstd2.h"
18#include "khstd.h"
19#include "spolys.h"
20#include "cntrlc.h"
21#include "weight.h"
22#include "ipid.h"
23#include "ipshell.h"
24#include "intvec.h"
25#ifdef STDTRACE
26#include "comm.h"
27#include "lists.h"
28#endif
29#include "spSpolyLoop.h"
30
31// #include "timer.h"
32
33#define HAVE_HOMOG_T
34
35/*2
36* consider the part above syzComp:
37* (assume the polynomial comes from a syz computation)
38* - it is a constant term: return a copy of it
39* - else: return NULL
40*/
41static poly kFromInput(poly p,kStrategy strat)
42{
43  poly q=p;
44
45  if (pGetComp(q)>strat->syzComp) return NULL;
46  while ((q!=NULL) && (pGetComp(q)<=strat->syzComp)) pIter(q);
47  if (pIsConstantComp(q))
48    return pHead(q);
49  return NULL;
50}
51
52/*2
53*  reduction procedure for the syz
54*  and TEST_OPT_MINRES: special minimizing during computations
55*  assumes homogeneous case and degree-ordering
56*/
57static void redSyz (LObject* h,kStrategy strat)
58{
59  int j = 0,i=0,pos;
60  BOOLEAN exchanged=pDivisibleBy((*h).p2,(*h).p1);
61  poly p,q;
62
63  if (exchanged)
64  {
65    q = kFromInput((*h).p1,strat);
66    if (q==NULL)
67    {
68      exchanged = FALSE;
69    }
70    else
71    {
72      while (i<=strat->Ll)
73      {
74        if ((strat->L[i].p1==strat->P.p1) || (strat->L[i].p2==strat->P.p1))
75        {
76          deleteInL(strat->L,&strat->Ll,i,strat);
77        }
78        else
79          i++;
80      }
81      i = 0;
82    }
83  }
84  if (TEST_OPT_DEBUG)
85  {
86    PrintS("red:");
87    wrp(h->p);
88  }
89  i = 0;
90  j = 0;
91  loop
92  {
93#ifdef HAVE_HOMOG_T
94    if (pDivisibleBy(strat->T[i].p,(*h).p))
95    {
96      if ((!exchanged) && (pEqual((*h).p,strat->T[j].p)))
97      {
98        j = 0;
99        while (j<= strat->sl)
100        {
101          if (strat->S[j] == strat->T[i].p) break;
102          j++;
103        }
104        if (j > strat->sl) goto NOTFOUND;
105#else
106    if (pDivisibleBy(strat->S[j],(*h).p))
107    {
108      if ((!exchanged) && (pEqual((*h).p,strat->S[j])))
109      {
110#endif
111        q = kFromInput(strat->S[j],strat);
112        if (q!=NULL)
113        {
114          exchanged = TRUE;
115          p = strat->S[j];
116          if (!TEST_OPT_INTSTRATEGY)
117            pNorm((*h).p);
118          else
119          {
120            //pContent((*h).p);
121            pCleardenom((*h).p);// also does a pContent
122          }
123          strat->S[j] = (*h).p;
124          (*h).p = p;
125#ifndef HAVE_HOMOG_T
126          while ((i<=strat->tl) && (strat->T[i].p!=p)) i++;
127#endif
128          if (i<=strat->tl) strat->T[i].p = strat->S[j];
129          int k;
130          for (k=0;k<=strat->Ll;k++)
131          {
132            if (strat->L[k].p1==p) strat->L[k].p1=strat->S[j];
133            if (strat->L[k].p2==p) strat->L[k].p2=strat->S[j];
134          }
135        }
136      }
137      //if (strat->interpt) test_int_std(strat->kIdeal);
138      /*- compute the s-polynomial -*/
139      if (TEST_OPT_DEBUG)
140      {
141        PrintS(" with ");
142        wrp(strat->S[j]);
143      }
144#ifdef HAVE_HOMOG_T
145      (*h).p = spSpolyRed(strat->T[i].p,(*h).p,strat->kNoether,
146                          strat->spSpolyLoop);
147#else
148      (*h).p = spSpolyRed(strat->S[j],(*h).p,strat->kNoether,
149                          strat->spSpolyLoop);
150#endif
151      if (TEST_OPT_DEBUG)
152      {
153        PrintS("\nto "); wrp((*h).p);PrintLn();
154      }
155      if ((*h).p == NULL)
156      {
157        if (h->lcm!=NULL) pFree1((*h).lcm);
158#ifdef KDEBUG
159        (*h).lcm=NULL;
160#endif
161        return;
162      }
163/*- try to reduce the s-polynomial -*/
164#ifdef HAVE_HOMOG_T
165      i = 0;
166#else
167      j = 0;
168#endif
169    }
170    else
171    {
172#ifdef HAVE_HOMOG_T
173NOTFOUND:
174      if (i >= strat->tl)
175#else
176      if (j >= strat->sl)
177#endif
178      {
179        if (exchanged)
180        {
181          if (pGetComp((*h).p) > strat->syzComp)
182          {
183            pDelete(&((*h).p));
184            return;
185          }
186          else
187          {
188            if (!TEST_OPT_INTSTRATEGY)
189            {
190              pos = posInS(strat->S,strat->sl,(*h).p);
191              pNorm((*h).p);
192              (*h).p = redtailSyz((*h).p,pos-1,strat);
193            }
194            p = (*h).p;
195            while ((pNext(p)!=NULL) && (pGetComp(pNext(p))<=strat->syzComp))
196               pIter(p);
197            pDelete(&pNext(p));
198            pNext(p) = q;
199          }
200        }
201        else if (!TEST_OPT_INTSTRATEGY)
202        {
203          pos = posInS(strat->S,strat->sl,(*h).p);
204          pNorm((*h).p);
205          (*h).p = redtailSyz((*h).p,pos-1,strat);
206        }
207        enterTBba((*h),strat->tl+1,strat);
208        return;
209      }
210#ifdef HAVE_HOMOG_T
211      i++;
212#else
213      j++;
214#endif
215    }
216  }
217}
218
219/*2
220*  reduction procedure for the homogeneous case
221*  and the case of a degree-ordering
222*/
223
224// #define HAVE_HOMOG_T
225
226static void redHomog (LObject* h,kStrategy strat)
227{
228  if (strat->tl<0)
229  {
230    enterTBba((*h),0,strat);
231    return;
232  }
233
234  int j = 0;
235
236  if (strat->ak!=0)
237  {
238    loop
239      {
240#ifdef HAVE_HOMOG_T
241        if (pDivisibleBy1(strat->T[j].p,(*h).p))
242#else
243        if (pDivisibleBy1(strat->S[j],(*h).p))
244#endif
245        {
246          //if (strat->interpt) test_int_std(strat->kIdeal);
247          /*- compute the s-polynomial -*/
248          if (TEST_OPT_DEBUG)
249          {
250            PrintS("red:");
251            wrp(h->p);
252            PrintS(" with ");
253#ifdef HAVE_HOMOG_T
254            wrp(strat->T[j].p);
255#else
256            wrp(strat->S[j]);
257#endif
258          }
259#ifdef HAVE_HOMOG_T
260          (*h).p = spSpolyRed(strat->T[j].p,(*h).p,strat->kNoether,
261                              strat->spSpolyLoop);
262#else
263          (*h).p = spSpolyRed(strat->S[j],(*h).p,strat->kNoether,
264                              strat->spSpolyLoop);
265#endif
266          if (TEST_OPT_DEBUG)
267          {
268            PrintS("\nto ");
269            wrp(h->p);
270            PrintLn();
271          }
272          if ((*h).p == NULL)
273          {
274            if (h->lcm!=NULL) pFree1((*h).lcm);
275#ifdef KDEBUG
276            (*h).lcm=NULL;
277#endif
278            return;
279          }
280          j = 0;
281        }
282        else
283        {
284#ifdef HAVE_HOMOG_T
285          if (j >= strat->tl)
286#else
287          if (j >= strat->sl)
288#endif           
289          {
290            if (TEST_OPT_INTSTRATEGY && strat->homog)
291            {
292              pCleardenom(h->p);
293              enterTBba((*h), strat->posInT(strat->T,strat->tl,(*h)), strat);
294            }
295            else
296              enterTBba((*h),strat->tl+1,strat);
297            return;
298          }
299          j++;
300        }
301      }
302  }
303  else
304  {
305    // no module component
306    loop
307      {
308#ifdef HAVE_HOMOG_T
309        if (pDivisibleBy2(strat->T[j].p,(*h).p))
310#else
311        if (pDivisibleBy2(strat->S[j],(*h).p))
312#endif
313        {
314          //if (strat->interpt) test_int_std(strat->kIdeal);
315          /*- compute the s-polynomial -*/
316          if (TEST_OPT_DEBUG)
317          {
318            PrintS("red:");
319            wrp(h->p);
320            PrintS(" with ");
321#ifdef HAVE_HOMOG_T
322            wrp(strat->T[j].p);
323#else
324            wrp(strat->S[j]);
325#endif
326          }
327#ifdef HAVE_HOMOG_T
328          (*h).p = spSpolyRed(strat->T[j].p,(*h).p,strat->kNoether,
329                              strat->spSpolyLoop);
330#else
331          (*h).p = spSpolyRed(strat->S[j],(*h).p,strat->kNoether,
332                              strat->spSpolyLoop);
333#endif
334          if (TEST_OPT_DEBUG)
335          {
336            PrintS("\nto ");
337            wrp(h->p);
338            PrintLn();
339          }
340          if ((*h).p == NULL)
341          {
342            if (h->lcm!=NULL) pFree1((*h).lcm);
343#ifdef KDEBUG
344            (*h).lcm=NULL;
345#endif
346            return;
347          }
348          j = 0;
349        }
350        else
351        {
352#ifdef HAVE_HOMOG_T
353          if (j >= strat->tl)
354#else
355          if (j >= strat->sl)
356#endif           
357          {
358            if (TEST_OPT_INTSTRATEGY && strat->homog)
359            {
360              pCleardenom(h->p);
361              enterTBba((*h), strat->posInT(strat->T,strat->tl,(*h)), strat);
362            }
363            else
364              enterTBba((*h),strat->tl+1,strat);
365            return;
366          }
367          j++;
368        }
369      }
370  }
371}
372
373#ifdef KEEP_GARBAGE
374/*2
375*  reduction procedure for the homogeneous case
376*  and the case of a degree-ordering
377*/
378static void redHomog0 (LObject* h,kStrategy strat)
379{
380  if (strat->tl<0)
381  {
382    enterTBba((*h),0,strat);
383    return;
384  }
385
386  int j = 0;
387  int k = 0;
388
389  if (strat->ak)
390  {
391    loop
392      {
393        if (pDivisibleBy1(strat->T[j].p,(*h).p))
394        {
395          //if (strat->interpt) test_int_std(strat->kIdeal);
396          /*- compute the s-polynomial -*/
397          if (TEST_OPT_DEBUG)
398          {
399            PrintS("red:");
400            wrp(h->p);
401            PrintS(" with ");
402            wrp(strat->T[j].p);
403          }
404          (*h).p = spSpolyRed(strat->T[j].p,(*h).p,strat->kNoether,
405                              strat->spSpolyLoop);
406          if (TEST_OPT_DEBUG)
407          {
408            PrintS("\nto ");
409            wrp(h->p);
410            PrintLn();
411          }
412          if ((*h).p == NULL)
413          {
414            if (h->lcm!=NULL) pFree1((*h).lcm);
415#ifdef KDEBUG
416            (*h).lcm=NULL;
417#endif
418            return;
419          }
420          j = 0;
421        }
422        else
423        {
424          if (j >= strat->tl)
425          {
426            //pContent((*h).p);
427            pCleardenom((*h).p);// also does a pContent
428/*
429 *       (*h).length=pLength0((*h).p);
430 */
431            k=strat->posInT(strat->T,strat->tl,(*h));
432            enterTBba((*h),k,strat);
433            return;
434          }
435          j++;
436        }
437      }
438  }
439  else
440  {
441    loop
442      {
443
444        // no module component
445        if (pDivisibleBy2(strat->T[j].p,(*h).p))
446        {
447          //if (strat->interpt) test_int_std(strat->kIdeal);
448          /*- compute the s-polynomial -*/
449          if (TEST_OPT_DEBUG)
450          {
451            PrintS("red:");
452            wrp(h->p);
453            PrintS(" with ");
454            wrp(strat->T[j].p);
455          }
456          (*h).p = spSpolyRed(strat->T[j].p,(*h).p,strat->kNoether,
457                              strat->spSpolyLoop);
458          if (TEST_OPT_DEBUG)
459          {
460            PrintS("\nto ");
461            wrp(h->p);
462            PrintLn();
463          }
464          if ((*h).p == NULL)
465          {
466            if (h->lcm!=NULL) pFree1((*h).lcm);
467#ifdef KDEBUG
468            (*h).lcm=NULL;
469#endif
470            return;
471          }
472          j = 0;
473        }
474        else
475        {
476#ifdef HAVE_HOMOG_T
477          if (j >= strat->tl)
478#else
479          if (j >= strat->sl)
480#endif           
481          {
482            //pContent((*h).p);
483            pCleardenom((*h).p);// also does a pContent
484/*
485 *       (*h).length=pLength0((*h).p);
486 */
487            k=strat->posInT(strat->T,strat->tl,(*h));
488            enterTBba((*h),k,strat);
489            return;
490          }
491          j++;
492        }
493      }
494  }
495}
496
497
498/*2
499*  reduction procedure for the inhomogeneous case
500*  and not a degree-ordering
501*/
502static void redLazy (LObject* h,kStrategy strat)
503{
504  if (strat->tl<0)
505  {
506    enterTBba((*h),0,strat);
507    return;
508  }
509
510  int at,d,i;
511  int j = 0;
512  int pass = 0;
513  int reddeg = pFDeg((*h).p);
514
515  loop
516  {
517    if (pDivisibleBy1(strat->S[j],(*h).p))
518    {
519      //if (strat->interpt) test_int_std(strat->kIdeal);
520      /*- compute the s-polynomial -*/
521      if (TEST_OPT_DEBUG)
522      {
523        PrintS("red:");
524        wrp(h->p);
525        PrintS(" with ");
526        wrp(strat->T[j].p);
527      }
528      (*h).p = spSpolyRed(strat->S[j],(*h).p,strat->kNoether
529                          , strat->spSpolyLoop);
530      if (TEST_OPT_DEBUG)
531      {
532        PrintS("\nto ");
533        wrp(h->p);
534        PrintLn();
535      }
536      if ((*h).p == NULL)
537      {
538        if (h->lcm!=NULL) pFree1((*h).lcm);
539#ifdef KDEBUG
540        (*h).lcm=NULL;
541#endif
542        return;
543      }
544      /*- try to reduce the s-polynomial -*/
545      pass++;
546      d = pFDeg((*h).p);
547      if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
548      {
549        at = posInL11(strat->L,strat->Ll,*h,strat);
550        if (at <= strat->Ll)
551        {
552#ifdef HAVE_HOMOG_T
553          i=strat->tl+1;
554#else
555          i=strat->sl+1;
556#endif
557          do
558          {
559            i--;
560            if (i<0)
561            {
562              enterTBba((*h),strat->tl+1,strat);
563              return;
564            }
565          }
566#ifdef HAVE_HOMOG_T
567          } while (!pDivisibleBy1(strat->T[i],(*h).p));
568#else
569          } while (!pDivisibleBy1(strat->S[i],(*h).p));
570#endif       
571          if (TEST_OPT_DEBUG) Print(" ->L[%d]\n",at);
572          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
573          (*h).p = NULL;
574          return;
575        }
576      }
577      else if ((TEST_OPT_PROT) && (strat->Ll < 0) && (d != reddeg))
578      {
579        Print(".%d",d);mflush();
580        reddeg = d;
581      }
582      j = 0;
583    }
584    else
585    {
586      if (j >= strat->sl)
587      {
588        if (TEST_OPT_INTSTRATEGY)
589        {
590          //pContent(h->p);
591          pCleardenom(h->p);// also does a pContent
592        }
593        enterTBba((*h),strat->tl+1,strat);
594        return;
595      }
596      j++;
597    }
598  }
599}
600
601#endif // KEEP_GARBAGE
602
603/*2
604*  reduction procedure for the sugar-strategy (honey)
605* reduces h with elements from T choosing first possible
606* element in T with respect to the given ecart
607*/
608static void redHoney (LObject*  h,kStrategy strat)
609{
610  if (strat->tl<0)
611  {
612    enterTBba((*h),0,strat);
613    return;
614  }
615
616  poly pi;
617  int i,j,at,reddeg,d,pass,ei;
618
619  pass = j = 0;
620  d = reddeg = pFDeg((*h).p)+(*h).ecart;
621  loop
622  {
623    if (pDivisibleBy1(strat->T[j].p,(*h).p))
624    {
625      pi = strat->T[j].p;
626      ei = strat->T[j].ecart;
627      /*
628      * the polynomial to reduce with (up to the moment) is;
629      * pi with ecart ei
630      */
631      i = j;
632      loop
633      {
634        /*- takes the first possible with respect to ecart -*/
635        i++;
636        if (i > strat->tl)
637          break;
638        if ((!BTEST1(20)) && (ei <= (*h).ecart))
639          break;
640        if ((strat->T[i].ecart < ei) && pDivisibleBy1(strat->T[i].p,(*h).p))
641        {
642          /*
643          * the polynomial to reduce with is now;
644          */
645          pi = strat->T[i].p;
646          ei = strat->T[i].ecart;
647        }
648      }
649
650      /*
651      * end of search: have to reduce with pi
652      */
653      if ((pass!=0) && (ei > (*h).ecart))
654      {
655        /*
656        * It is not possible to reduce h with smaller ecart;
657        * if possible h goes to the lazy-set L,i.e
658        * if its position in L would be not the last one
659        */
660        if (strat->Ll >= 0) /* L is not empty */
661        {
662          at = strat->posInL(strat->L,strat->Ll,*h,strat);
663          if(at <= strat->Ll)
664          /*- h will not become the next element to reduce -*/
665          {
666            enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
667            if (TEST_OPT_DEBUG) Print(" ecart too big: -> L%d\n",at);
668            (*h).p = NULL;
669            return;
670          }
671        }
672        if (TEST_OPT_MOREPAIRS)
673        {
674        /*put the polynomial also in the pair set*/
675          strat->fromT = TRUE;
676          if (!TEST_OPT_INTSTRATEGY) pNorm((*h).p);
677          enterpairs((*h).p,strat->sl,(*h).ecart,0,strat);
678        }
679      }
680      if (TEST_OPT_DEBUG)
681      {
682        PrintS("red:");
683        wrp(h->p);
684        PrintS(" with ");
685        wrp(pi);
686      }
687      if (strat->fromT)
688      {
689        strat->fromT=FALSE;
690        (*h).p = spSpolyRedNew(pi,(*h).p,strat->kNoether,
691                               strat->spSpolyLoop);
692      }
693      else
694        (*h).p = spSpolyRed(pi,(*h).p,strat->kNoether, strat->spSpolyLoop);
695      if (TEST_OPT_DEBUG)
696      {
697        PrintS("\nto ");
698        wrp(h->p);
699        PrintLn();
700      }
701      if ((*h).p == NULL)
702      {
703        if (h->lcm!=NULL) pFree1((*h).lcm);
704#ifdef KDEBUG
705        (*h).lcm=NULL;
706#endif
707        return;
708      }
709      /* compute the ecart */
710      if (ei <= (*h).ecart)
711        (*h).ecart = d-pFDeg((*h).p);
712      else
713        (*h).ecart = d-pFDeg((*h).p)+ei-(*h).ecart;
714//      if (strat->syzComp)
715//      {
716//        if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
717//        {
718#ifdef KDEBUG
719//          if (TEST_OPT_DEBUG)
720#endif
721//            PrintS("  >syzComp\n");
722//          if (TEST_OPT_INTSTRATEGY) pContent(h->p);
723//          at=strat->posInT(strat->T,strat->tl,(*h));
724//          enterTBba((*h),at,strat);
725//          return;
726//        }
727//      }
728      /*
729      * try to reduce the s-polynomial h
730      *test first whether h should go to the lazyset L
731      *-if the degree jumps
732      *-if the number of pre-defined reductions jumps
733      */
734      pass++;
735      d = pFDeg((*h).p)+(*h).ecart;
736      if ((strat->Ll >= 0) && ((d > reddeg) || (pass > strat->LazyPass)))
737      {
738        at = strat->posInL(strat->L,strat->Ll,*h,strat);
739        if (at <= strat->Ll)
740        {
741          /*test if h is already standardbasis element*/
742#ifdef HAVE_HOMOG_T
743          i=strat->tl+1;
744#else
745          i=strat->sl+1;
746#endif
747          do
748          {
749            i--;
750            if (i<0)
751            {
752              at=strat->posInT(strat->T,strat->tl,(*h));
753              enterTBba((*h),at,strat);
754              return;
755            }
756#ifdef HAVE_HOMOG_T
757          } while (!pDivisibleBy1(strat->T[i].p,(*h).p));
758#else
759          } while (!pDivisibleBy1(strat->S[i],(*h).p));
760#endif       
761
762          enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
763          if (TEST_OPT_DEBUG)
764            Print(" degree jumped: -> L%d\n",at);
765          (*h).p = NULL;
766          return;
767        }
768      }
769      else if (TEST_OPT_PROT && (strat->Ll < 0) && (d > reddeg))
770      {
771        reddeg = d;
772        Print(".%d",d); mflush();
773      }
774      j = 0;
775    }
776    else
777    {
778      if (j >= strat->tl)
779      {
780        if (TEST_OPT_INTSTRATEGY)
781        {
782          //pContent(h->p);
783          pCleardenom(h->p);// also does a pContent
784        }
785        at=strat->posInT(strat->T,strat->tl,(*h));
786        enterTBba((*h),at,strat);
787        return;
788      }
789      j++;
790    }
791  }
792}
793
794/*2
795*  reduction procedure for tests only
796*  reduces with elements from T and chooses the best possible
797*/
798static void redBest (LObject*  h,kStrategy strat)
799{
800  if (strat->tl<0)
801  {
802    enterTBba((*h),0,strat);
803    return;
804  }
805
806  int j,jbest,at,reddeg,d,pass;
807  poly     p,ph;
808  pass = j = 0;
809
810  if (strat->honey)
811    reddeg = pFDeg((*h).p)+(*h).ecart;
812  else
813    reddeg = pFDeg((*h).p);
814  loop
815  {
816    if (pDivisibleBy(strat->T[j].p,(*h).p))
817    {
818      //if (strat->interpt) test_int_std(strat->kIdeal);
819      /* compute the s-polynomial */
820      if (!TEST_OPT_INTSTRATEGY) pNorm((*h).p);
821#ifdef SDRING
822      // spSpolyShortBba will not work in the SRING case
823      if (pSDRING)
824      {
825        p=spSpolyCreate(strat->T[j].p,(*h).p,strat->kNoether,strat->spSpolyLoop);
826        if (p!=NULL) pDelete(&pNext(p));
827      }
828      else
829#endif
830      p = spSpolyShortBba(strat->T[j].p,(*h).p);
831      /* computes only the first monomial of the spoly  */
832      if (p)
833      {
834        jbest = j;
835        /* looking for the best possible reduction */
836        if ((strat->syzComp==0) || (pMinComp(p) <= strat->syzComp))
837        {
838          loop
839          {
840            j++;
841            if (j > strat->tl)
842              break;
843            if (pDivisibleBy(strat->T[j].p,(*h).p))
844            {
845#ifdef SDRING
846              // spSpolyShortBba will not work in the SRING case
847              if (pSDRING)
848              {
849                ph=spSpolyCreate(strat->T[j].p,(*h).p,strat->kNoether,strat->spSpolyLoop);
850                if (ph!=NULL) pDelete(&pNext(ph));
851              }
852              else
853#endif
854              ph = spSpolyShortBba(strat->T[j].p,(*h).p);
855              if (ph==NULL)
856              {
857                pFree1(p);
858                pDelete(&((*h).p));
859                if (h->lcm!=NULL) pFree1((*h).lcm);
860#ifdef KDEBUG
861                (*h).lcm=NULL;
862#endif
863                return;
864              }
865              else if (pComp0(ph,p) == -1)
866              {
867                pFree1(p);
868                p = ph;
869                jbest = j;
870              }
871              else
872              {
873                pFree1(ph);
874              }
875            }
876          }
877        }
878        pFree1(p);
879        (*h).p = spSpolyRed(strat->T[jbest].p,(*h).p,strat->kNoether,
880                            strat->spSpolyLoop);
881      }
882      else
883      {
884        if (h->lcm!=NULL) pFree1((*h).lcm);
885#ifdef KDEBUG
886        (*h).lcm=NULL;
887#endif
888        (*h).p = NULL;
889        return;
890      }
891      if (strat->honey && pLexOrder)
892        strat->initEcart(h);
893      /* h.length:=l; */
894      /* try to reduce the s-polynomial */
895//      if (strat->syzComp)
896//      {
897//        if ((strat->syzComp>0) && (pMinComp((*h).p) > strat->syzComp))
898//        {
899#ifdef KDEBUG
900//          if (TEST_OPT_DEBUG)
901#endif
902//            PrintS(" >syzComp\n");
903//          if (TEST_OPT_INTSTRATEGY) pContent(h->p);
904//          at=strat->posInT(strat->T,strat->tl,(*h));
905//          enterTBba((*h),at,strat);
906//          return;
907//        }
908//      }
909      if (strat->honey || pLexOrder)
910      {
911        pass++;
912        d = pFDeg((*h).p);
913        if (strat->honey)
914          d += (*h).ecart;
915        if ((strat->Ll >= 0) && ((pass > strat->LazyPass) || (d > reddeg)))
916        {
917          at = strat->posInL(strat->L,strat->Ll,*h,strat);
918          if (at <= strat->Ll)
919          {
920            enterL(&strat->L,&strat->Ll,&strat->Lmax,*h,at);
921            (*h).p = NULL;
922            return;
923          }
924        }
925        else if (TEST_OPT_PROT && (strat->Ll < 0) && (d != reddeg))
926        {
927          reddeg = d;
928          Print("%d.");
929          mflush();
930        }
931      }
932      j = 0;
933    }
934    else
935    {
936      if (j >= strat->tl)
937      {
938        if (TEST_OPT_INTSTRATEGY)
939        {
940          //pContent(h->p);
941          pCleardenom(h->p);// also does a pContent
942        }
943        at=strat->posInT(strat->T,strat->tl,(*h));
944        enterTBba((*h),at,strat);
945        return;
946      }
947      j++;
948    }
949  }
950}
951
952/*2
953*  reduction procedure for the normal form
954*/
955
956static poly redNF (poly h,kStrategy strat)
957{
958  int j = 0;
959  int z = 3;
960
961  if (0 > strat->sl)
962  {
963    return h;
964  }
965  loop
966  {
967    if (pDivisibleBy1(strat->S[j],h))
968    {
969      //if (strat->interpt) test_int_std(strat->kIdeal);
970      /*- compute the s-polynomial -*/
971      if (TEST_OPT_DEBUG)
972      {
973        PrintS("red:");
974        wrp(h);
975        PrintS(" with ");
976        wrp(strat->S[j]);
977      }
978      h = spSpolyRed(strat->S[j],h,strat->kNoether, strat->spSpolyLoop);
979      if (TEST_OPT_DEBUG)
980      {
981        PrintS("\nto:");
982        wrp(h);
983        PrintLn();
984      }
985      if (h == NULL) return NULL;
986      z++;
987      if (z>=10)
988      {
989        z=0;
990        pNormalize(h);
991      }
992      /*- try to reduce the s-polynomial -*/
993      j = 0;
994    }
995    else
996    {
997      if (j >= strat->sl) return h;
998      j++;
999    }
1000  }
1001}
1002
1003void initBba(ideal F,kStrategy strat)
1004{
1005  int i;
1006  idhdl h;
1007 /* setting global variables ------------------- */
1008  strat->enterS = enterSBba;
1009  if ((BTEST1(20)) && (!strat->honey))
1010    strat->red = redBest;
1011  else if (strat->honey)
1012    strat->red = redHoney;
1013#ifdef KEEP_GARBAGE
1014  else if (pLexOrder && !strat->homog)
1015    strat->red = redLazy;
1016  else if (TEST_OPT_INTSTRATEGY && strat->homog)
1017    strat->red = redHomog0;
1018#endif
1019  else
1020    strat->red = redHomog;
1021  if (TEST_OPT_MINRES && strat->homog && (strat->syzComp >0))
1022    strat->red = redSyz;
1023
1024  if (pLexOrder && strat->honey)
1025    strat->initEcart = initEcartNormal;
1026  else
1027    strat->initEcart = initEcartBBA;
1028  if (strat->honey)
1029    strat->initEcartPair = initEcartPairMora;
1030  else
1031    strat->initEcartPair = initEcartPairBba;
1032  strat->kIdeal = NULL;
1033  //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD;
1034  //else              strat->kIdeal->rtyp=MODUL_CMD;
1035  //strat->kIdeal->data=(void *)strat->Shdl;
1036  if ((TEST_OPT_WEIGHTM)&&(F!=NULL))
1037  {
1038    //interred  machen   Aenderung
1039    pFDegOld=pFDeg;
1040    pLDegOld=pLDeg;
1041    h=ggetid("ecart");
1042    if ((h!=NULL) && (IDTYP(h)==INTVEC_CMD))
1043    {
1044      ecartWeights=iv2array(IDINTVEC(h));
1045    }
1046    else
1047    {
1048      ecartWeights=(short *)Alloc((pVariables+1)*sizeof(short));
1049      /*uses automatic computation of the ecartWeights to set them*/
1050      kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights);
1051    }
1052    pFDeg=totaldegreeWecart;
1053    pLDeg=maxdegreeWecart;
1054    for(i=1; i<=pVariables; i++)
1055      Print(" %d",ecartWeights[i]);
1056    PrintLn();
1057    mflush();
1058  }
1059}
1060
1061#ifdef STDTRACE
1062lists bbaLink (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat, stdLink stdTrace)
1063{
1064  int oldLl;
1065  int srmax,lrmax;
1066  int olddeg,reduc;
1067  int anzTupel=0, anzNew = 0, anzSkipped=0;
1068#ifdef SDRING
1069  polyset aug=(polyset)Alloc(setmax*sizeof(poly));
1070  int augmax=setmax, augl=-1;
1071  poly oldLcm=NULL;
1072#endif
1073  int hilbeledeg=1,hilbcount=0,minimcnt=0;
1074
1075  if(stdTrace!=NULL) stdTrace->Start(strat);
1076
1077  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
1078  initHilbCrit(F,Q,&hilb,strat);
1079  initBba(F,strat);
1080  initBuchMoraPos(strat);
1081  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
1082  /*Shdl=*/initBuchMora(F, Q,strat);
1083  if (strat->minim>0)
1084  {
1085    strat->M=idInit(IDELEMS(F),F->rank);
1086  }
1087  srmax = strat->sl;
1088  reduc = olddeg = lrmax = 0;
1089  /* compute------------------------------------------------------- */
1090  while ((stdTrace!=NULL && !stdTrace->CheckEnd(strat)) || (stdTrace == NULL && strat->Ll>=0))
1091  {
1092//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1093    if(stdTrace!=NULL && stdTrace->Receive)
1094    {
1095      stdTrace->ReceiveMsg();
1096      stdTrace->ParseMessage(strat);
1097    }
1098//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1099    if((stdTrace!=NULL && stdTrace->Verwaltung) || (stdTrace == NULL))
1100    {
1101      if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
1102      if (TEST_OPT_DEBUG) messageSets(strat);
1103      //test_int_std(strat->kIdeal);
1104      if (strat->Ll== 0) strat->interpt=TRUE;
1105      if (TEST_OPT_DEGBOUND
1106      && ((strat->honey
1107        && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p)>Kstd1_deg))
1108      || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p)>Kstd1_deg))))
1109      {
1110        /*
1111        *stops computation if
1112        * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
1113        *a predefined number Kstd1_deg
1114        */
1115        while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1116        break;
1117      }
1118    }
1119//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1120    if((stdTrace!=NULL && stdTrace->TupelL) || (stdTrace == NULL ))
1121    {
1122      /* picks the last element from the lazyset L */
1123      strat->P = strat->L[strat->Ll];
1124      anzTupel++;
1125      strat->Ll--;
1126      if(stdTrace!=NULL && stdTrace->TupelStore)
1127      {
1128        if (TEST_OPT_PROT) PrintS(":");
1129        stdTrace->Store(strat->P);
1130        strat->P.p=NULL;
1131        anzSkipped++;
1132      }
1133    }
1134//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1135    if((stdTrace!=NULL && stdTrace->SPoly) || (stdTrace == NULL))
1136    {
1137      kTest(strat);
1138      if (pNext(strat->P.p) == strat->tail)
1139      {
1140        /* deletes the short spoly and computes */
1141        pFree1(strat->P.p);
1142        /* the real one */
1143        strat->P.p = spSpolyCreate(strat->P.p1,strat->P.p2,strat->kNoether);
1144      }
1145      if((strat->P.p1==NULL) && (strat->minim>0))
1146        strat->P.p2=pCopy(strat->P.p);
1147    }
1148//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1149    if((stdTrace!=NULL && stdTrace->Reduzieren) || (stdTrace == NULL))
1150    {
1151#ifdef SDRING
1152      if (strat->P.p != NULL)
1153#endif
1154      {
1155        if (strat->honey)
1156        {
1157          if (TEST_OPT_PROT)
1158            message(strat->P.ecart+pFDeg(strat->P.p),&olddeg,&reduc,strat);
1159        }
1160        else
1161        {
1162          if (TEST_OPT_PROT)
1163            message(pFDeg(strat->P.p),&olddeg,&reduc,strat);
1164        }
1165        /* reduction of the element choosen from L */
1166        oldLl=strat->Ll;
1167        strat->red(&strat->P,strat);
1168        if(stdTrace!=NULL && stdTrace->TupelPosition)
1169          stdTrace->CheckPosition(strat,oldLl);
1170        if((stdTrace!=NULL && stdTrace->TupelMelden))
1171          stdTrace->SendTupel(strat);
1172        if(stdTrace!=NULL && strat->P.p!=NULL && stdTrace->Modus==ModCheck)
1173          anzNew++;
1174      }
1175      if (strat->P.p != NULL)
1176      {
1177#ifdef SDRING
1178        aug[0]=strat->P.p;
1179        augl=0;
1180        if (pSDRING)
1181        {
1182          oldLcm=strat->P.lcm;
1183#ifdef SRING
1184          if (pSRING) psAug(pCopy(strat->P.p),pOne(),&aug,&augl,&augmax);
1185#endif
1186#ifdef DRING
1187          if (pDRING) pdAug(pCopy(strat->P.p),&aug,&augl,&augmax);
1188#endif
1189#ifdef KDEBUG
1190          if (TEST_OPT_DEBUG)
1191          {
1192            PrintS(" aug of ");
1193            wrp(aug[0]);
1194            PrintLn();
1195            int iiaug=augl;
1196            while (iiaug>=0)
1197            {
1198              Print(" to %d:",iiaug);
1199              wrp(aug[iiaug]);
1200              PrintLn();
1201              iiaug--;
1202            }
1203          }
1204#endif
1205        }
1206        for (augl++;augl != 0;)
1207        {
1208          strat->P.p=aug[--augl];
1209          aug[augl]=NULL;
1210          if (pSDRING)
1211          {
1212            if (oldLcm==NULL) strat->P.lcm=NULL;
1213            else  strat->P.lcm=pCopy1(oldLcm);
1214          }
1215          if ((augl!=0)&&(strat->P.p!=NULL))
1216            strat->red(&strat->P,strat);
1217          if (strat->P.p != NULL)
1218          {
1219#endif
1220            /* statistic */
1221            if (TEST_OPT_PROT) PrintS("s");
1222            /* enter P.p into s and L */
1223            {
1224              int pos=posInS(strat->S,strat->sl,strat->P.p);
1225#ifdef SDRING
1226              if ((pSDRING)
1227              && (pos<=strat->sl)
1228              && (pComparePolys(strat->P.p,strat->S[pos])))
1229              {
1230                if (TEST_OPT_PROT)
1231                  PrintS("d");
1232              }
1233              else
1234#endif
1235              {
1236                if (TEST_OPT_INTSTRATEGY)
1237                {
1238                  if ((!TEST_OPT_MINRES)||(strat->syzComp==0)||(!strat->homog))
1239                  {
1240                    strat->P.p = redtailBba(strat->P.p,pos-1,strat);
1241                    //if (strat->redTailChange)
1242                      pCleardenom(strat->P.p);
1243                  }
1244                }
1245                else
1246                {
1247                  pNorm(strat->P.p);
1248                  if ((!TEST_OPT_MINRES)||(strat->syzComp==0)||(!strat->homog))
1249                  {
1250                    strat->P.p = redtailBba(strat->P.p,pos-1,strat);
1251                  }
1252                }
1253                if (TEST_OPT_DEBUG)
1254                {
1255                  PrintS("new s:");
1256                  wrp(strat->P.p);
1257                  PrintLn();
1258                }
1259                if((strat->P.p1==NULL) && (strat->minim>0))
1260                {
1261                  if (strat->minim==1)
1262                  {
1263                    strat->M->m[minimcnt]=pCopy(strat->P.p);
1264                    pDelete(&strat->P.p2);
1265                  }
1266                  else
1267                  {
1268                    strat->M->m[minimcnt]=strat->P.p2;
1269                    strat->P.p2=NULL;
1270                  }
1271                  minimcnt++;
1272                }
1273                enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat);
1274                if (strat->sl==-1) pos=0;
1275                else pos=posInS(strat->S,strat->sl,strat->P.p);
1276                strat->enterS(strat->P,pos,strat);
1277              }
1278              if (hilb!=NULL)
1279              {  // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1280                oldLl=strat->Ll;
1281                khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
1282                if(stdTrace!=NULL)
1283                  stdTrace->CheckHilb(strat,oldLl);
1284              }
1285            }
1286            if (strat->P.lcm!=NULL) pFree1(strat->P.lcm);
1287#ifdef SDRING
1288          }
1289        }
1290        /* delete the old pair */
1291        if (pSDRING &&(oldLcm!=NULL)) pFree1(oldLcm);
1292#endif
1293        if (strat->sl>srmax) srmax = strat->sl;
1294      }
1295      if(stdTrace!=NULL && stdTrace->TupelTesten)
1296        stdTrace->TupelDifferent(strat);
1297    }
1298#ifdef KDEBUG
1299    strat->P.lcm=NULL;
1300#endif
1301    kTest(strat);
1302  }
1303  if(stdTrace !=NULL)
1304  {
1305    if(TEST_OPT_PROT)
1306    {
1307      Print("\n(Tupel  Skipped  New) = (%i  %i  %i)\n",anzTupel, anzSkipped, anzNew);
1308    }
1309  }
1310  if((stdTrace!=NULL && stdTrace->ResultSend) || (stdTrace == NULL))
1311  {
1312    if (TEST_OPT_DEBUG) messageSets(strat);
1313    /* complete reduction of the standard basis--------- */
1314    if (TEST_OPT_REDSB) completeReduce(strat);
1315    /* release temp data-------------------------------- */
1316    exitBuchMora(strat);
1317    if (TEST_OPT_WEIGHTM)
1318    {
1319      pFDeg=pFDegOld;
1320      pLDeg=pLDegOld;
1321      if (ecartWeights)
1322      {
1323        Free((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
1324        ecartWeights=NULL;
1325      }
1326    }
1327#ifdef SDRING
1328    Free((ADDRESS)aug,augmax*sizeof(poly));
1329#endif
1330    if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat);
1331    if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
1332  }
1333  if(stdTrace!=NULL)
1334    stdTrace->End(strat);
1335  lists l=(lists)Alloc(sizeof(slists));
1336  l->Init(2);
1337  l->m[0].rtyp = IDEAL_CMD;
1338  l->m[0].data = (void *) strat->Shdl;
1339  if(stdTrace!=NULL)
1340  {
1341    l->m[1].rtyp = LIST_CMD;
1342    l->m[1].data = (void *)stdTrace->RestTupel();
1343  }
1344  return (l);
1345}
1346
1347#else
1348
1349ideal bba (ideal F, ideal Q,intvec *w,intvec *hilb,kStrategy strat)
1350{
1351  int   srmax,lrmax;
1352  int   olddeg,reduc;
1353#ifdef SDRING
1354  polyset aug=(polyset)Alloc(setmax*sizeof(poly));
1355  int augmax=setmax, augl=-1;
1356  poly oldLcm=NULL;
1357#endif
1358  int hilbeledeg=1,hilbcount=0,minimcnt=0;
1359
1360  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
1361  initHilbCrit(F,Q,&hilb,strat);
1362  initBba(F,strat);
1363  initBuchMoraPos(strat);
1364  /*set enterS, spSpolyShort, reduce, red, initEcart, initEcartPair*/
1365  /*Shdl=*/initBuchMora(F, Q,strat);
1366  if (strat->minim>0)
1367  {
1368    strat->M=idInit(IDELEMS(F),F->rank);
1369  }
1370  srmax = strat->sl;
1371  reduc = olddeg = lrmax = 0;
1372  /* compute------------------------------------------------------- */
1373  while (strat->Ll >= 0)
1374  {
1375    if (strat->Ll > lrmax) lrmax =strat->Ll;/*stat.*/
1376    if (TEST_OPT_DEBUG) messageSets(strat);
1377    //test_int_std(strat->kIdeal);
1378    if (strat->Ll== 0) strat->interpt=TRUE;
1379    if (TEST_OPT_DEGBOUND
1380    && ((strat->honey && (strat->L[strat->Ll].ecart+pFDeg(strat->L[strat->Ll].p)>Kstd1_deg))
1381       || ((!strat->honey) && (pFDeg(strat->L[strat->Ll].p)>Kstd1_deg))))
1382    {
1383      /*
1384      *stops computation if
1385      * 24 IN test and the degree +ecart of L[strat->Ll] is bigger then
1386      *a predefined number Kstd1_deg
1387      */
1388      while (strat->Ll >= 0) deleteInL(strat->L,&strat->Ll,strat->Ll,strat);
1389      break;
1390    }
1391    /* picks the last element from the lazyset L */
1392    strat->P = strat->L[strat->Ll];
1393    strat->Ll--;
1394    kTest(strat);
1395    if (pNext(strat->P.p) == strat->tail)
1396    {
1397      /* deletes the short spoly and computes */
1398      pFree1(strat->P.p);
1399      /* the real one */
1400      strat->P.p = spSpolyCreate(strat->P.p1,
1401                                 strat->P.p2,
1402                                 strat->kNoether,
1403                                 strat->spSpolyLoop);
1404    }
1405    kTest(strat);
1406    if((strat->P.p1==NULL) && (strat->minim>0))
1407      strat->P.p2=pCopy(strat->P.p);
1408#ifdef SDRING
1409    if (strat->P.p != NULL)
1410#endif
1411    {
1412      if (strat->honey)
1413      {
1414        if (TEST_OPT_PROT) message(strat->P.ecart+pFDeg(strat->P.p),&olddeg,&reduc,strat);
1415      }
1416      else
1417      {
1418        if (TEST_OPT_PROT) message(pFDeg(strat->P.p),&olddeg,&reduc,strat);
1419      }
1420      kTest(strat);
1421      /* reduction of the element choosen from L */
1422      strat->red(&strat->P,strat);
1423      pTest(strat->P.p);
1424    }
1425    kTest(strat);
1426    if (strat->P.p != NULL)
1427    {
1428#ifdef SDRING
1429      aug[0]=strat->P.p;
1430      augl=0;
1431      if (pSDRING)
1432      {
1433        oldLcm=strat->P.lcm;
1434#ifdef SRING
1435        if (pSRING) psAug(pCopy(strat->P.p),pOne(),&aug,&augl,&augmax);
1436#endif
1437#ifdef DRING
1438        if (pDRING) pdAug(pCopy(strat->P.p),&aug,&augl,&augmax);
1439#endif
1440#ifdef KDEBUG
1441        if (TEST_OPT_DEBUG)
1442        {
1443          PrintS(" aug of ");
1444          wrp(aug[0]);
1445          PrintLn();
1446          int iiaug=augl;
1447          while (iiaug>=0)
1448          {
1449            Print(" to %d:",iiaug);
1450            wrp(aug[iiaug]);
1451            PrintLn();
1452            iiaug--;
1453          }
1454        }
1455#endif
1456      }
1457      for (augl++;augl != 0;)
1458      {
1459        strat->P.p=aug[--augl];
1460        aug[augl]=NULL;
1461        if (pSDRING)
1462        {
1463          if (oldLcm==NULL) strat->P.lcm=NULL;
1464          else  strat->P.lcm=pCopy1(oldLcm);
1465        }
1466        if ((augl!=0)&&(strat->P.p!=NULL))
1467          strat->red(&strat->P,strat);
1468        if (strat->P.p != NULL)
1469        {
1470#endif
1471          /* statistic */
1472          if (TEST_OPT_PROT) PrintS("s");
1473          /* enter P.p into s and L */
1474          {
1475            int pos=posInS(strat->S,strat->sl,strat->P.p);
1476#ifdef SDRING
1477            if ((pSDRING) && (pos<=strat->sl)&& (pComparePolys(strat->P.p,strat->S[pos])))
1478            {
1479              if (TEST_OPT_PROT)
1480                PrintS("d");
1481            }
1482            else
1483#endif
1484            {
1485              if (TEST_OPT_INTSTRATEGY)
1486              {
1487                if ((!TEST_OPT_MINRES)||(strat->syzComp==0)||(!strat->homog))
1488                {
1489                  strat->P.p = redtailBba(strat->P.p,pos-1,strat);
1490                  //if (strat->redTailChange)
1491                    pCleardenom(strat->P.p);
1492                }
1493              }
1494              else
1495              {
1496                pNorm(strat->P.p);
1497                if ((!TEST_OPT_MINRES)||(strat->syzComp==0)||(!strat->homog))
1498                {
1499                  strat->P.p = redtailBba(strat->P.p,pos-1,strat);
1500                }
1501              }
1502              if (TEST_OPT_DEBUG)
1503              {
1504                PrintS("new s:");
1505                wrp(strat->P.p);
1506                PrintLn();
1507              }
1508              if((strat->P.p1==NULL) && (strat->minim>0))
1509              {
1510                if (strat->minim==1)
1511                {
1512                  strat->M->m[minimcnt]=pCopy(strat->P.p);
1513                  pDelete(&strat->P.p2);
1514                }
1515                else
1516                {
1517                  strat->M->m[minimcnt]=strat->P.p2;
1518                  strat->P.p2=NULL;
1519                }
1520                minimcnt++;
1521              }
1522              enterpairs(strat->P.p,strat->sl,strat->P.ecart,pos,strat);
1523              if (strat->sl==-1) pos=0;
1524              else pos=posInS(strat->S,strat->sl,strat->P.p);
1525              strat->enterS(strat->P,pos,strat);
1526            }
1527            if (hilb!=NULL) khCheck(Q,w,hilb,hilbeledeg,hilbcount,strat);
1528          }
1529          if (strat->P.lcm!=NULL) pFree1(strat->P.lcm);
1530#ifdef SDRING
1531        }
1532      }
1533      /* delete the old pair */
1534      if (pSDRING &&(oldLcm!=NULL)) pFree1(oldLcm);
1535#endif
1536      if (strat->sl>srmax) srmax = strat->sl;
1537    }
1538#ifdef KDEBUG
1539    strat->P.lcm=NULL;
1540#endif
1541    kTest(strat);
1542  }
1543  if (TEST_OPT_DEBUG) messageSets(strat);
1544  /* complete reduction of the standard basis--------- */
1545  if (TEST_OPT_REDSB) completeReduce(strat);
1546  /* release temp data-------------------------------- */
1547  exitBuchMora(strat);
1548  if (TEST_OPT_WEIGHTM)
1549  {
1550    pFDeg=pFDegOld;
1551    pLDeg=pLDegOld;
1552    if (ecartWeights)
1553    {
1554      Free((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
1555      ecartWeights=NULL;
1556    }
1557  }
1558#ifdef SDRING
1559  Free((ADDRESS)aug,augmax*sizeof(poly));
1560#endif
1561  if (TEST_OPT_PROT) messageStat(srmax,lrmax,hilbcount,strat);
1562  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
1563  return (strat->Shdl);
1564}
1565#endif
1566
1567poly kNF2 (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce)
1568{
1569  poly   p;
1570  int   i;
1571
1572  if ((idIs0(F))&&(Q==NULL))
1573    return pCopy(q); /*F=0*/
1574  strat->ak = idRankFreeModule(F);
1575  /*- creating temp data structures------------------- -*/
1576  BITSET save_test=test;
1577  test|=Sy_bit(OPT_REDTAIL);
1578  initBuchMoraCrit(strat);
1579  strat->initEcart = initEcartBBA;
1580  strat->enterS = enterSBba;
1581  /*- set S -*/
1582  strat->sl = -1;
1583  strat->spSpolyLoop = spGetSpolyLoop(currRing, max(strat->ak, pMaxComp(q)),
1584                                      strat->syzComp, FALSE);
1585  /*- init local data struct.---------------------------------------- -*/
1586  /*Shdl=*/initS(F,Q,strat);
1587  /*- compute------------------------------------------------------- -*/
1588  if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
1589  {
1590    for (i=strat->sl;i>=0;i--)
1591      pNorm(strat->S[i]);
1592  }
1593  kTest(strat);
1594  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
1595  p = redNF(pCopy(q),strat);
1596  kTest(strat);
1597  if ((p!=NULL)&&(lazyReduce==0))
1598  {
1599    if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
1600    p = redtailBba(p,strat->sl,strat);
1601  }
1602  kTest(strat);
1603  /*- release temp data------------------------------- -*/
1604  Free((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
1605  idDelete(&strat->Shdl);
1606  test=save_test;
1607  if (TEST_OPT_PROT) PrintLn();
1608  return p;
1609}
1610
1611ideal kNF2 (ideal F,ideal Q,ideal q,kStrategy strat, int lazyReduce)
1612{
1613  poly   p;
1614  int   i;
1615  ideal res;
1616
1617  if (idIs0(q))
1618    return idInit(1,q->rank);
1619  if ((idIs0(F))&&(Q==NULL))
1620    return idCopy(q); /*F=0*/
1621  strat->ak = idRankFreeModule(F);
1622  /*- creating temp data structures------------------- -*/
1623  BITSET save_test=test;
1624  test|=Sy_bit(OPT_REDTAIL);
1625  initBuchMoraCrit(strat);
1626  strat->initEcart = initEcartBBA;
1627  strat->enterS = enterSBba;
1628  /*- set S -*/
1629  strat->sl = -1;
1630  strat->spSpolyLoop =  spGetSpolyLoop(currRing,
1631                                       max(strat->ak, idRankFreeModule(q)),
1632                                       strat->syzComp, FALSE);
1633  /*- init local data struct.---------------------------------------- -*/
1634  /*Shdl=*/initS(F,Q,strat);
1635  /*- compute------------------------------------------------------- -*/
1636  res=idInit(IDELEMS(q),q->rank);
1637  if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0))
1638  {
1639    for (i=strat->sl;i>=0;i--)
1640      pNorm(strat->S[i]);
1641  }
1642  for (i=IDELEMS(q)-1; i>=0; i--)
1643  {
1644    if (q->m[i]!=NULL)
1645    {
1646      if (TEST_OPT_PROT) { PrintS("r");mflush(); }
1647      p = redNF(pCopy(q->m[i]),strat);
1648      if ((p!=NULL)&&(lazyReduce==0))
1649      {
1650        if (TEST_OPT_PROT) { PrintS("t"); mflush(); }
1651        p = redtailBba(p,strat->sl,strat);
1652      }
1653      res->m[i]=p;
1654    }
1655    //else
1656    //  res->m[i]=NULL;
1657  }
1658  /*- release temp data------------------------------- -*/
1659  Free((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
1660  idDelete(&strat->Shdl);
1661  test=save_test;
1662  if (TEST_OPT_PROT) PrintLn();
1663  return res;
1664}
1665
1666static ideal bbared (ideal F, ideal Q,kStrategy strat)
1667{
1668
1669  /* complete reduction of the standard basis--------- */
1670  completeReduce(strat);
1671  /* release temp data-------------------------------- */
1672  exitBuchMora(strat);
1673  if (TEST_OPT_WEIGHTM)
1674  {
1675    pFDeg=pFDegOld;
1676    pLDeg=pLDegOld;
1677    if (ecartWeights)
1678    {
1679      Free((ADDRESS)ecartWeights,(pVariables+1)*sizeof(short));
1680      ecartWeights=NULL;
1681    }
1682  }
1683  if (Q!=NULL) updateResult(strat->Shdl,Q,strat);
1684  return (strat->Shdl);
1685}
1686
1687ideal stdred(ideal F, ideal Q, tHomog h,intvec ** w)
1688{
1689  ideal r;
1690  BOOLEAN b=pLexOrder,toReset=FALSE;
1691  BOOLEAN delete_w=(w==NULL);
1692  kStrategy strat=(kStrategy)Alloc0(sizeof(skStrategy));
1693
1694  if (rField_has_simple_inverse())
1695    strat->LazyPass=20;
1696  else
1697   strat->LazyPass=2;
1698  strat->LazyDegree = 1;
1699  strat->ak = idRankFreeModule(F);
1700  if ((h==testHomog))
1701  {
1702    if (strat->ak==0)
1703    {
1704      h = (tHomog)idHomIdeal(F,Q);
1705      w=NULL;
1706    }
1707    else
1708      h = (tHomog)idHomModule(F,Q,w);
1709  }
1710  if (h==isHomog)
1711  {
1712    if ((w!=NULL) && (*w!=NULL))
1713    {
1714      kModW = *w;
1715      strat->kModW = *w;
1716      pOldFDeg = pFDeg;
1717      pFDeg = kModDeg;
1718      toReset = TRUE;
1719    }
1720    pLexOrder = TRUE;
1721    strat->LazyPass*=2;
1722  }
1723  strat->homog=h;
1724  spSet(currRing);
1725  strat->spSpolyLoop = spGetSpolyLoop(currRing, strat);
1726  initBuchMoraCrit(strat); /*set Gebauer, honey, sugarCrit*/
1727  initBuchMoraPos(strat);
1728  if (pOrdSgn==1)
1729    initBba(F,strat);
1730  else
1731    initMora(F,strat);
1732  initBuchMora(F, Q,strat);
1733  //initS(F,Q,strat);
1734// Ende der Initalisierung
1735  r=bbared(F,Q,strat);
1736#ifdef KDEBUG
1737  int i;
1738  for (i=0; i<IDELEMS(r); i++) pTest(r->m[i]);
1739#endif
1740// Ende: aufraeumen
1741  if (toReset)
1742  {
1743    kModW = NULL;
1744    pFDeg = pOldFDeg;
1745  }
1746  pLexOrder = b;
1747  Free((ADDRESS)strat,sizeof(skStrategy));
1748  if ((delete_w)&&(w!=NULL)&&(*w!=NULL)) delete *w;
1749  idSkipZeroes(r);
1750  return r;
1751}
Note: See TracBrowser for help on using the repository browser.