tgb.cc
Go to the documentation of this file.
1 //! \file tgb.cc
2 // multiple rings
3 // shorten_tails und dessen Aufrufe pruefen wlength!!!
4 /****************************************
5 * Computer Algebra System SINGULAR *
6 ****************************************/
7 /*
8 * ABSTRACT: slimgb and F4 implementation
9 */
10 //#include <vector>
11 //using namespace std;
12 
13 ///@TODO: delay nur auf Sugarvergr?erung
14 ///@TODO: grade aus ecartS, setze dazu strat->honey; und nutze p.ecart
15 ///@TODO: no tail reductions in syz comp
16 #include <kernel/mod2.h>
17 
18 #include <kernel/GBEngine/tgb.h>
21 
22 #include <misc/options.h>
23 #include <kernel/digitech.h>
24 #include <polys/nc/nc.h>
25 #include <polys/nc/sca.h>
26 #include <polys/prCopy.h>
27 
28 #include <coeffs/longrat.h> // nlQlogSize
29 
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <queue>
33 
34 #define BUCKETS_FOR_NORO_RED 1
35 #define SR_HDL(A) ((long)(A))
36 static const int bundle_size = 100;
37 static const int bundle_size_noro = 10000;
38 static const int delay_factor = 3;
39 #define ADD_LATER_SIZE 500
40 #if 1
41 static omBin lm_bin = NULL;
42 static int add_to_reductors(slimgb_alg* c, poly h, int len, int ecart, BOOLEAN simplified=FALSE);
43 static void multi_reduction(red_object* los, int & losl, slimgb_alg* c);
44 static void multi_reduce_step(find_erg & erg, red_object* r, slimgb_alg* c);
45 static BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, slimgb_alg* c);
46 static poly gcd_of_terms(poly p, ring r);
47 static int tgb_pair_better_gen(const void* ap,const void* bp);
49 static BOOLEAN state_is(calc_state state, const int & i, const int & j, slimgb_alg* c);
51 static int simple_posInS (kStrategy strat, poly p,int len, wlen_type wlen);
52 static int* make_connections(int from, int to, poly bound, slimgb_alg* c);
53 static BOOLEAN has_t_rep(const int & arg_i, const int & arg_j, slimgb_alg* state);
54 static void shorten_tails(slimgb_alg* c, poly monom);
55 static poly redNF2 (poly h,slimgb_alg* c , int &len, number& m,int n=0);
56 static poly redNFTail (poly h,const int sl,kStrategy strat, int len);
57 static int bucket_guess(kBucket* bucket);
58 
59 static void simplify_poly (poly p, ring r)
60 {
61  assume (r == currRing);
62  if(!rField_is_Zp (r))
63  {
64  p_Cleardenom (p, r);
65  //p_Content(p,r); //is a duplicate call, but belongs here
66  }
67  else
68  pNorm (p);
69 }
70 
71 //static const BOOLEAN up_to_radical=TRUE;
72 
73 int slim_nsize (number n, ring r)
74 {
75  if(rField_is_Zp (r))
76  {
77  return 1;
78  }
79  if(rField_is_Q (r))
80  {
81  return nlQlogSize (n, r->cf);
82  }
83  else
84  {
85  return n_Size (n, r);
86  }
87 }
88 
89 static BOOLEAN monomial_root (poly m, ring r)
90 {
91  BOOLEAN changed = FALSE;
92  int i;
93  for(i = 1; i <= rVar (r); i++)
94  {
95  int e = p_GetExp (m, i, r);
96  if(e > 1)
97  {
98  p_SetExp (m, i, 1, r);
99  changed = TRUE;
100  }
101  }
102  if(changed)
103  {
104  p_Setm (m, r);
105  }
106  return changed;
107 }
108 
110 {
111  poly got = gcd_of_terms (h, r);
112  BOOLEAN changed = FALSE;
113  if((got != NULL) && (TEST_V_UPTORADICAL))
114  {
115  poly copy = p_Copy (got, r);
116  //p_wrp(got,c->r);
117  changed = monomial_root (got, r);
118  if(changed)
119  {
120  poly div_by = pDivide (copy, got);
121  poly iter = h;
122  while(iter)
123  {
124  pExpVectorSub (iter, div_by);
125  pIter (iter);
126  }
127  p_Delete (&div_by, r);
128  if(TEST_OPT_PROT)
129  PrintS ("U");
130  }
131  p_Delete (&copy, r);
132  }
133  p_Delete (&got, r);
134  return changed;
135 }
136 
137 static inline poly p_Init_Special (const ring r)
138 {
139  return p_Init (r, lm_bin);
140 }
141 
142 static inline poly pOne_Special (const ring r = currRing)
143 {
144  poly rc = p_Init_Special (r);
145  pSetCoeff0 (rc, n_Init (1, r));
146  return rc;
147 }
148 
149 // zum Initialiseren: in t_rep_gb plazieren:
150 
151 #endif
152 #define LEN_VAR3
153 #define degbound(p) assume(pTotaldegree(p)<10)
154 //#define inDebug(p) assume((debug_Ideal==NULL)||(kNF(debug_Ideal,NULL,p,0,0)==0))
155 
156 //die meisten Varianten stossen sich an coef_buckets
157 
158 #ifdef LEN_VAR1
159 // erste Variante: Laenge: Anzahl der Monome
160 static inline int pSLength (poly p, int l)
161 {
162  return l;
163 }
164 
165 static inline int kSBucketLength (kBucket * bucket, poly lm)
166 {
167  return bucket_guess (bucket);
168 }
169 #endif
170 
171 #ifdef LEN_VAR2
172 // 2. Variante: Laenge: Platz fuer die Koeff.
173 int pSLength (poly p, int l)
174 {
175  int s = 0;
176  while(p != NULL)
177  {
178  s += nSize (pGetCoeff (p));
179  pIter (p);
180  }
181  return s;
182 }
183 
184 int kSBucketLength (kBucket * b, poly lm)
185 {
186  int s = 0;
187  int i;
188  for(i = MAX_BUCKET; i >= 0; i--)
189  {
190  s += pSLength (b->buckets[i], 0);
191  }
192  return s;
193 }
194 #endif
195 
196 #ifdef LEN_VAR3
197 static inline wlen_type pSLength (poly p, int l)
198 {
199  wlen_type c;
200  number coef = pGetCoeff (p);
201  if(rField_is_Q (currRing))
202  {
203  c = nlQlogSize (coef, currRing->cf);
204  }
205  else
206  c = nSize (coef);
207  if(!(TEST_V_COEFSTRAT))
208  {
209  return (wlen_type) c *(wlen_type) l /*pLength(p) */ ;
210  }
211  else
212  {
213  wlen_type res = l;
214  res *= c;
215  res *= c;
216  return res;
217  }
218 }
219 
220 //! TODO CoefBuckets bercksichtigen
222 {
223  int s = 0;
224  wlen_type c;
225  number coef;
226  if(lm == NULL)
227  coef = pGetCoeff (kBucketGetLm (b));
228  //c=nSize(pGetCoeff(kBucketGetLm(b)));
229  else
230  coef = pGetCoeff (lm);
231  //c=nSize(pGetCoeff(lm));
232  if(rField_is_Q (currRing))
233  {
234  c = nlQlogSize (coef, currRing->cf);
235  }
236  else
237  c = nSize (coef);
238 
239  int i;
240  for(i = b->buckets_used; i >= 0; i--)
241  {
242  assume ((b->buckets_length[i] == 0) || (b->buckets[i] != NULL));
243  s += b->buckets_length[i] /*pLength(b->buckets[i]) */ ;
244  }
245 #ifdef HAVE_COEF_BUCKETS
246  assume (b->buckets[0] == kBucketGetLm (b));
247  if(b->coef[0] != NULL)
248  {
249  if(rField_is_Q (currRing))
250  {
251  int modifier = nlQlogSize (pGetCoeff (b->coef[0]), currRing->cf);
252  c += modifier;
253  }
254  else
255  {
256  int modifier = nSize (pGetCoeff (b->coef[0]));
257  c *= modifier;
258  }
259  }
260 #endif
261  if(!(TEST_V_COEFSTRAT))
262  {
263  return s * c;
264  }
265  else
266  {
267  wlen_type res = s;
268  res *= c;
269  res *= c;
270  return res;
271  }
272 }
273 #endif
274 #ifdef LEN_VAR5
275 static inline wlen_type pSLength (poly p, int l)
276 {
277  int c;
278  number coef = pGetCoeff (p);
279  if(rField_is_Q (currRing))
280  {
281  c = nlQlogSize (coef, currRing->cf);
282  }
283  else
284  c = nSize (coef);
285  wlen_type erg = l;
286  erg *= c;
287  erg *= c;
288  //PrintS("lenvar 5");
289  assume (erg >= 0);
290  return erg; /*pLength(p) */ ;
291 }
292 
293 //! TODO CoefBuckets bercksichtigen
295 {
296  wlen_type s = 0;
297  int c;
298  number coef;
299  if(lm == NULL)
300  coef = pGetCoeff (kBucketGetLm (b));
301  //c=nSize(pGetCoeff(kBucketGetLm(b)));
302  else
303  coef = pGetCoeff (lm);
304  //c=nSize(pGetCoeff(lm));
305  if(rField_is_Q (currRing))
306  {
307  c = nlQlogSize (coef, currRing->cf);
308  }
309  else
310  c = nSize (coef);
311 
312  int i;
313  for(i = b->buckets_used; i >= 0; i--)
314  {
315  assume ((b->buckets_length[i] == 0) || (b->buckets[i] != NULL));
316  s += b->buckets_length[i] /*pLength(b->buckets[i]) */ ;
317  }
318 #ifdef HAVE_COEF_BUCKETS
319  assume (b->buckets[0] == kBucketGetLm (b));
320  if(b->coef[0] != NULL)
321  {
322  if(rField_is_Q (currRing))
323  {
324  int modifier = nlQlogSize (pGetCoeff (b->coef[0]), currRing->cf);
325  c += modifier;
326  }
327  else
328  {
329  int modifier = nSize (pGetCoeff (b->coef[0]));
330  c *= modifier;
331  }
332  }
333 #endif
334  wlen_type erg = s;
335  erg *= c;
336  erg *= c;
337  return erg;
338 }
339 #endif
340 
341 #ifdef LEN_VAR4
342 // 4.Variante: Laenge: Platz fuer Leitk * (1+Platz fuer andere Koeff.)
343 int pSLength (poly p, int l)
344 {
345  int s = 1;
346  int c = nSize (pGetCoeff (p));
347  pIter (p);
348  while(p != NULL)
349  {
350  s += nSize (pGetCoeff (p));
351  pIter (p);
352  }
353  return s * c;
354 }
355 
356 int kSBucketLength (kBucket * b)
357 {
358  int s = 1;
359  int c = nSize (pGetCoeff (kBucketGetLm (b)));
360  int i;
361  for(i = MAX_BUCKET; i > 0; i--)
362  {
363  if(b->buckets[i] == NULL)
364  continue;
365  s += pSLength (b->buckets[i], 0);
366  }
367  return s * c;
368 }
369 #endif
370 //BUG/TODO this stuff will fail on internal Schreyer orderings
372 {
373  ring r = c->r;
374  if(p_GetComp (p, r) != 0)
375  return FALSE;
376  if(c->lastDpBlockStart <= (currRing->N))
377  {
378  int i;
379  for(i = 1; i < c->lastDpBlockStart; i++)
380  {
381  if(p_GetExp (p, i, r) != 0)
382  {
383  break;
384  }
385  }
386  if(i >= c->lastDpBlockStart)
387  {
388  //wrp(p);
389  //PrintS("\n");
390  return TRUE;
391  }
392  else
393  return FALSE;
394  }
395  else
396  return FALSE;
397 }
398 
400 {
401  ring r = c->r;
402  if(p_GetComp (p, r) != 0)
403  return FALSE;
404  if(c->lastDpBlockStart <= (currRing->N))
405  {
406  int i;
407  for(i = 1; i < c->lastDpBlockStart; i++)
408  {
409  if(p_GetExp (p, i, r) != 0)
410  {
411  break;
412  }
413  }
414  if(i >= c->lastDpBlockStart)
415  {
416  //wrp(p);
417  //PrintS("\n");
418  return TRUE;
419  }
420  else
421  return FALSE;
422  }
423  else
424  return FALSE;
425 }
426 
427 static int get_last_dp_block_start (ring r)
428 {
429  //ring r=c->r;
430  int last_block;
431 
433  {
434  last_block = rBlocks (r) - 3;
435  }
436  else
437  {
438  last_block = rBlocks (r) - 2;
439  }
440  assume (last_block >= 0);
441  if(r->order[last_block] == ringorder_dp)
442  return r->block0[last_block];
443  return (currRing->N) + 1;
444 }
445 
446 static wlen_type do_pELength (poly p, slimgb_alg * c, int dlm = -1)
447 {
448  if(p == NULL)
449  return 0;
450  wlen_type s = 0;
451  poly pi = p;
452  if(dlm < 0)
453  {
454  dlm = c->pTotaldegree (p);
455  s = 1;
456  pi = p->next;
457  }
458 
459  while(pi)
460  {
461  int d = c->pTotaldegree (pi);
462  if(d > dlm)
463  s += 1 + d - dlm;
464  else
465  ++s;
466  pi = pi->next;
467  }
468  return s;
469 }
470 
471 wlen_type pELength (poly p, slimgb_alg * c, ring /*r*/)
472 {
473  if(p == NULL)
474  return 0;
475  wlen_type s = 0;
476  poly pi = p;
477  int dlm;
478  dlm = c->pTotaldegree (p);
479  s = 1;
480  pi = p->next;
481 
482  while(pi)
483  {
484  int d = c->pTotaldegree (pi);
485  if(d > dlm)
486  s += 1 + d - dlm;
487  else
488  ++s;
489  pi = pi->next;
490  }
491  return s;
492 }
493 
495 {
496  wlen_type s = 0;
497  if(lm == NULL)
498  {
499  lm = kBucketGetLm (b);
500  }
501  if(lm == NULL)
502  return 0;
503  if(elength_is_normal_length (lm, ca))
504  {
505  return bucket_guess (b);
506  }
507  int d = ca->pTotaldegree (lm);
508 #if 0
509  assume (sugar >= d);
510  s = 1 + (bucket_guess (b) - 1) * (sugar - d + 1);
511  return s;
512 #else
513 
514  //int d=pTotaldegree(lm,ca->r);
515  int i;
516  for(i = b->buckets_used; i >= 0; i--)
517  {
518  if(b->buckets[i] == NULL)
519  continue;
520 
521  if((ca->pTotaldegree (b->buckets[i]) <= d)
522  && (elength_is_normal_length (b->buckets[i], ca)))
523  {
524  s += b->buckets_length[i];
525  }
526  else
527  {
528  s += do_pELength (b->buckets[i], ca, d);
529  }
530  }
531  return s;
532 #endif
533 }
534 
535 static inline int pELength (poly p, slimgb_alg * c, int l)
536 {
537  if(p == NULL)
538  return 0;
539  if((l > 0) && (elength_is_normal_length (p, c)))
540  return l;
541  return do_pELength (p, c);
542 }
543 
544 static inline wlen_type pQuality (poly p, slimgb_alg * c, int l = -1)
545 {
546  if(l < 0)
547  l = pLength (p);
548  if(c->isDifficultField)
549  {
550  if(c->eliminationProblem)
551  {
552  wlen_type cs;
553  number coef = pGetCoeff (p);
554  if(rField_is_Q (currRing))
555  {
556  cs = nlQlogSize (coef, currRing->cf);
557  }
558  else
559  cs = nSize (coef);
560  wlen_type erg = cs;
561  if(TEST_V_COEFSTRAT)
562  erg *= cs;
563  //erg*=cs;//for quadratic
564  erg *= pELength (p, c, l);
565  //FIXME: not quadratic coeff size
566  //return cs*pELength(p,c,l);
567  return erg;
568  }
569  //PrintS("I am here");
570  wlen_type r = pSLength (p, l);
571  assume (r >= 0);
572  return r;
573  }
574  if(c->eliminationProblem)
575  return pELength (p, c, l);
576  return l;
577 }
578 
579 static inline int pTotaldegree_full (poly p)
580 {
581  int r = 0;
582  while(p)
583  {
584  int d = pTotaldegree (p);
585  r = si_max (r, d);
586  pIter (p);
587  }
588  return r;
589 }
590 
592 {
593  //works at the moment only for lenvar 1, because in different
594  //case, you have to look on coefs
595  wlen_type s = 0;
596  if(c->isDifficultField)
597  {
598  //s=kSBucketLength(bucket,this->p);
599  if(c->eliminationProblem)
600  {
601  wlen_type cs;
602  number coef;
603 
604  coef = pGetCoeff (kBucketGetLm (bucket));
605  //c=nSize(pGetCoeff(kBucketGetLm(b)));
606 
607  //c=nSize(pGetCoeff(lm));
608  if(rField_is_Q (currRing))
609  {
610  cs = nlQlogSize (coef, currRing->cf);
611  }
612  else
613  cs = nSize (coef);
614 #ifdef HAVE_COEF_BUCKETS
615  if(bucket->coef[0] != NULL)
616  {
617  if(rField_is_Q (currRing))
618  {
619  int modifier = nlQlogSize (pGetCoeff (bucket->coef[0]), currRing->cf);
620  cs += modifier;
621  }
622  else
623  {
624  int modifier = nSize (pGetCoeff (bucket->coef[0]));
625  cs *= modifier;
626  }
627  }
628 #endif
629  //FIXME:not quadratic
630  wlen_type erg = kEBucketLength (this->bucket, this->p, c);
631  //erg*=cs;//for quadratic
632  erg *= cs;
633  if(TEST_V_COEFSTRAT)
634  erg *= cs;
635  //return cs*kEBucketLength(this->bucket,this->p,c);
636  return erg;
637  }
638  s = kSBucketLength (bucket, NULL);
639  }
640  else
641  {
642  if(c->eliminationProblem)
643  //if (false)
644  s = kEBucketLength (this->bucket, this->p, c);
645  else
646  s = bucket_guess (bucket);
647  }
648  return s;
649 }
650 
651 #if 0 //currently unused
652 static void finalize_reduction_step (reduction_step * r)
653 {
654  delete r;
655 }
656 #endif
657 #if 0 //currently unused
658 static int LObject_better_gen (const void *ap, const void *bp)
659 {
660  LObject *a = *(LObject **) ap;
661  LObject *b = *(LObject **) bp;
662  return (pLmCmp (a->p, b->p));
663 }
664 #endif
665 static int red_object_better_gen (const void *ap, const void *bp)
666 {
667  return (pLmCmp (((red_object *) ap)->p, ((red_object *) bp)->p));
668 }
669 
670 #if 0 //currently unused
671 static int pLmCmp_func_inverted (const void *ap1, const void *ap2)
672 {
673  poly p1, p2;
674  p1 = *((poly *) ap1);
675  p2 = *((poly *) ap2);
676  return -pLmCmp (p1, p2);
677 }
678 #endif
679 
680 int tgb_pair_better_gen2 (const void *ap, const void *bp)
681 {
682  return (-tgb_pair_better_gen (ap, bp));
683 }
684 
686 {
687  int i;
688  long not_sev = ~obj.sev;
689  poly p = obj.p;
690  for(i = 0; i <= strat->sl; i++)
691  {
692  if(pLmShortDivisibleBy (strat->S[i], strat->sevS[i], p, not_sev))
693  return i;
694  }
695  return -1;
696 }
697 
699 {
700  int i;
701  long not_sev = ~sev;
702  for(i = 0; i <= strat->sl; i++)
703  {
704  if(pLmShortDivisibleBy (strat->S[i], strat->sevS[i], p, not_sev))
705  return i;
706  }
707  return -1;
708 }
709 
710 static int
712  slimgb_alg * c, int an = 0)
713 {
714  if(pn == 0)
715  return 0;
716 
717  int length = pn - 1;
718  int i;
719  //int an = 0;
720  int en = length;
721 
722  if(pair_better (qe, p[en], c))
723  return length + 1;
724 
725  while(1)
726  {
727  //if (an >= en-1)
728  if(en - 1 <= an)
729  {
730  if(pair_better (p[an], qe, c))
731  return an;
732  return en;
733  }
734  i = (an + en) / 2;
735  if(pair_better (p[i], qe, c))
736  en = i;
737  else
738  an = i;
739  }
740 }
741 
742 static BOOLEAN ascending (int *i, int top)
743 {
744  if(top < 1)
745  return TRUE;
746  if(i[top] < i[top - 1])
747  return FALSE;
748  return ascending (i, top - 1);
749 }
750 
752  sorted_pair_node ** q, int qn, slimgb_alg * c)
753 {
754  int i;
755  int *a = (int *) omalloc (qn * sizeof (int));
756 // int mc;
757 // PrintS("Debug\n");
758 // for(mc=0;mc<qn;mc++)
759 // {
760 // wrp(q[mc]->lcm_of_lm);
761 // PrintS("\n");
762 // }
763 // PrintS("Debug they are in\n");
764 // for(mc=0;mc<pn;mc++)
765 // {
766 // wrp(p[mc]->lcm_of_lm);
767 // PrintS("\n");
768 // }
769  int lastpos = 0;
770  for(i = 0; i < qn; i++)
771  {
772  lastpos = posInPairs (p, pn, q[i], c, si_max (lastpos - 1, 0));
773  // cout<<lastpos<<"\n";
774  a[i] = lastpos;
775  }
776  if((pn + qn) > c->max_pairs)
777  {
778  p =
779  (sorted_pair_node **) omrealloc (p,
780  2 * (pn +
781  qn) *
782  sizeof (sorted_pair_node *));
783  c->max_pairs = 2 * (pn + qn);
784  }
785  for(i = qn - 1; i >= 0; i--)
786  {
787  size_t size;
788  if(qn - 1 > i)
789  size = (a[i + 1] - a[i]) * sizeof (sorted_pair_node *);
790  else
791  size = (pn - a[i]) * sizeof (sorted_pair_node *); //as indices begin with 0
792  memmove (p + a[i] + (1 + i), p + a[i], size);
793  p[a[i] + i] = q[i];
794  }
795  omfree (a);
796  return p;
797 }
798 
799 static BOOLEAN
800 trivial_syzygie (int pos1, int pos2, poly bound, slimgb_alg * c)
801 {
802  poly p1 = c->S->m[pos1];
803  poly p2 = c->S->m[pos2];
804 
805  if(pGetComp (p1) > 0 || pGetComp (p2) > 0)
806  return FALSE;
807  int i = 1;
808  poly m = NULL;
809  poly gcd1 = c->gcd_of_terms[pos1];
810  poly gcd2 = c->gcd_of_terms[pos2];
811 
812  if((gcd1 != NULL) && (gcd2 != NULL))
813  {
814  gcd1->next = gcd2; //may ordered incorrect
815  m = gcd_of_terms (gcd1, c->r);
816  gcd1->next = NULL;
817  }
818  if(m == NULL)
819  {
820  loop
821  {
822  if(pGetExp (p1, i) + pGetExp (p2, i) > pGetExp (bound, i))
823  return FALSE;
824  if(i == (currRing->N))
825  {
826  //PrintS("trivial");
827  return TRUE;
828  }
829  i++;
830  }
831  }
832  else
833  {
834  loop
835  {
836  if(pGetExp (p1, i) - pGetExp (m, i) + pGetExp (p2, i) >
837  pGetExp (bound, i))
838  {
839  pDelete (&m);
840  return FALSE;
841  }
842  if(i == (currRing->N))
843  {
844  pDelete (&m);
845  //PrintS("trivial");
846  return TRUE;
847  }
848  i++;
849  }
850  }
851 }
852 
853 //! returns position sets w as weight
854 int find_best (red_object * r, int l, int u, wlen_type & w, slimgb_alg * c)
855 {
856  int best = l;
857  int i;
858  w = r[l].guess_quality (c);
859  for(i = l + 1; i <= u; i++)
860  {
861  wlen_type w2 = r[i].guess_quality (c);
862  if(w2 < w)
863  {
864  w = w2;
865  best = i;
866  }
867  }
868  return best;
869 }
870 
872 {
874 }
875 
877 {
878  assume (i >= 0);
879  assume (j >= 0);
880  if(has_t_rep (i, j, c))
881  return TRUE;
882  //poly lm=pOne();
883  assume (c->tmp_lm != NULL);
884  poly lm = c->tmp_lm;
885 
886  pLcm (c->S->m[i], c->S->m[j], lm);
887  pSetm (lm);
888  assume (lm != NULL);
889  //int deciding_deg= pTotaldegree(lm);
890  int *i_con = make_connections (i, j, lm, c);
891  //p_Delete(&lm,c->r);
892 
893  for(int n = 0; ((n < c->n) && (i_con[n] >= 0)); n++)
894  {
895  if(i_con[n] == j)
896  {
897  now_t_rep (i, j, c);
898  omFree (i_con);
899  return TRUE;
900  }
901  }
902  omfree (i_con);
903 
904  return FALSE;
905 }
906 
908 {
909  int i;
910  for(i = 0; i <= strat->sl; i++)
911  {
912  if(strat->lenS[i] != pLength (strat->S[i]))
913  return FALSE;
914  }
915  return TRUE;
916 }
917 
918 
919 static void cleanS (kStrategy strat, slimgb_alg * c)
920 {
921  int i = 0;
922  LObject P;
923  while(i <= strat->sl)
924  {
925  P.p = strat->S[i];
926  P.sev = strat->sevS[i];
927  //int dummy=strat->sl;
928  //if(kFindDivisibleByInS(strat,&dummy,&P)!=i)
929  if(kFindDivisibleByInS_easy (strat, P.p, P.sev) != i)
930  {
931  deleteInS (i, strat);
932  //remember destroying poly
933  BOOLEAN found = FALSE;
934  int j;
935  for(j = 0; j < c->n; j++)
936  {
937  if(c->S->m[j] == P.p)
938  {
939  found = TRUE;
940  break;
941  }
942  }
943  if(!found)
944  pDelete (&P.p);
945  //remember additional reductors
946  }
947  else
948  i++;
949  }
950 }
951 
953 {
954  int sum = 0;
955  int i;
956  for(i = bucket->buckets_used; i >= 0; i--)
957  {
958  if(bucket->buckets[i])
959  sum += bucket->buckets_length[i];
960  }
961  return sum;
962 }
963 
964 static int
965 add_to_reductors (slimgb_alg * c, poly h, int len, int ecart,
966  BOOLEAN simplified)
967 {
968  //inDebug(h);
969  assume (lenS_correct (c->strat));
970  assume (len == pLength (h));
971  int i;
972 // if (c->isDifficultField)
973 // i=simple_posInS(c->strat,h,pSLength(h,len),c->isDifficultField);
974 // else
975 // i=simple_posInS(c->strat,h,len,c->isDifficultField);
976 
977  LObject P;
978  memset (&P, 0, sizeof (P));
979  P.tailRing = c->r;
980  P.p = h; /*p_Copy(h,c->r); */
981  P.ecart = ecart;
982  P.FDeg = c->r->pFDeg (P.p, c->r);
983  if(!(simplified))
984  {
985  if(!rField_is_Zp (c->r))
986  {
987  p_Cleardenom (P.p, c->r);
988  //p_Content(P.p,c->r ); //is a duplicate call, but belongs here
989 
990  }
991  else
992  pNorm (P.p);
993  pNormalize (P.p);
994  }
995  wlen_type pq = pQuality (h, c, len);
996  i = simple_posInS (c->strat, h, len, pq);
997  c->strat->enterS (P, i, c->strat, -1);
998 
999  c->strat->lenS[i] = len;
1000  assume (pLength (c->strat->S[i]) == c->strat->lenS[i]);
1001  if(c->strat->lenSw != NULL)
1002  c->strat->lenSw[i] = pq;
1003 
1004  return i;
1005 }
1006 
1007 static void length_one_crit (slimgb_alg * c, int pos, int len)
1008 {
1009  if(c->nc)
1010  return;
1011  if(len == 1)
1012  {
1013  int i;
1014  for(i = 0; i < pos; i++)
1015  {
1016  if(c->lengths[i] == 1)
1017  c->states[pos][i] = HASTREP;
1018  }
1019  for(i = pos + 1; i < c->n; i++)
1020  {
1021  if(c->lengths[i] == 1)
1022  c->states[i][pos] = HASTREP;
1023  }
1024  if(!c->nc)
1025  shorten_tails (c, c->S->m[pos]);
1026  }
1027 }
1028 
1029 static void move_forward_in_S (int old_pos, int new_pos, kStrategy strat)
1030 {
1031  assume (old_pos >= new_pos);
1032  poly p = strat->S[old_pos];
1033  int ecart = strat->ecartS[old_pos];
1034  long sev = strat->sevS[old_pos];
1035  int s_2_r = strat->S_2_R[old_pos];
1036  int length = strat->lenS[old_pos];
1037  assume (length == pLength (strat->S[old_pos]));
1038  wlen_type length_w;
1039  if(strat->lenSw != NULL)
1040  length_w = strat->lenSw[old_pos];
1041  int i;
1042  for(i = old_pos; i > new_pos; i--)
1043  {
1044  strat->S[i] = strat->S[i - 1];
1045  strat->ecartS[i] = strat->ecartS[i - 1];
1046  strat->sevS[i] = strat->sevS[i - 1];
1047  strat->S_2_R[i] = strat->S_2_R[i - 1];
1048  }
1049  if(strat->lenS != NULL)
1050  for(i = old_pos; i > new_pos; i--)
1051  strat->lenS[i] = strat->lenS[i - 1];
1052  if(strat->lenSw != NULL)
1053  for(i = old_pos; i > new_pos; i--)
1054  strat->lenSw[i] = strat->lenSw[i - 1];
1055 
1056  strat->S[new_pos] = p;
1057  strat->ecartS[new_pos] = ecart;
1058  strat->sevS[new_pos] = sev;
1059  strat->S_2_R[new_pos] = s_2_r;
1060  strat->lenS[new_pos] = length;
1061  if(strat->lenSw != NULL)
1062  strat->lenSw[new_pos] = length_w;
1063  //assume(lenS_correct(strat));
1064 }
1065 
1066 static void move_backward_in_S (int old_pos, int new_pos, kStrategy strat)
1067 {
1068  assume (old_pos <= new_pos);
1069  poly p = strat->S[old_pos];
1070  int ecart = strat->ecartS[old_pos];
1071  long sev = strat->sevS[old_pos];
1072  int s_2_r = strat->S_2_R[old_pos];
1073  int length = strat->lenS[old_pos];
1074  assume (length == pLength (strat->S[old_pos]));
1075  wlen_type length_w;
1076  if(strat->lenSw != NULL)
1077  length_w = strat->lenSw[old_pos];
1078  int i;
1079  for(i = old_pos; i < new_pos; i++)
1080  {
1081  strat->S[i] = strat->S[i + 1];
1082  strat->ecartS[i] = strat->ecartS[i + 1];
1083  strat->sevS[i] = strat->sevS[i + 1];
1084  strat->S_2_R[i] = strat->S_2_R[i + 1];
1085  }
1086  if(strat->lenS != NULL)
1087  for(i = old_pos; i < new_pos; i++)
1088  strat->lenS[i] = strat->lenS[i + 1];
1089  if(strat->lenSw != NULL)
1090  for(i = old_pos; i < new_pos; i++)
1091  strat->lenSw[i] = strat->lenSw[i + 1];
1092 
1093  strat->S[new_pos] = p;
1094  strat->ecartS[new_pos] = ecart;
1095  strat->sevS[new_pos] = sev;
1096  strat->S_2_R[new_pos] = s_2_r;
1097  strat->lenS[new_pos] = length;
1098  if(strat->lenSw != NULL)
1099  strat->lenSw[new_pos] = length_w;
1100  //assume(lenS_correct(strat));
1101 }
1102 
1103 static int *make_connections (int from, int to, poly bound, slimgb_alg * c)
1104 {
1105  ideal I = c->S;
1106  int *cans = (int *) omAlloc (c->n * sizeof (int));
1107  int *connected = (int *) omAlloc (c->n * sizeof (int));
1108  cans[0] = to;
1109  int cans_length = 1;
1110  connected[0] = from;
1111  int last_cans_pos = -1;
1112  int connected_length = 1;
1113  long neg_bounds_short = ~p_GetShortExpVector (bound, c->r);
1114 
1115  int not_yet_found = cans_length;
1116  int con_checked = 0;
1117  int pos;
1118 
1119  while(TRUE)
1120  {
1121  if((con_checked < connected_length) && (not_yet_found > 0))
1122  {
1123  pos = connected[con_checked];
1124  for(int i = 0; i < cans_length; i++)
1125  {
1126  if(cans[i] < 0)
1127  continue;
1128  //FIXME: triv. syz. does not hold on noncommutative, check it for modules
1129  if((has_t_rep (pos, cans[i], c))
1130  || ((!rIsPluralRing (c->r))
1131  && (trivial_syzygie (pos, cans[i], bound, c))))
1132  {
1133  connected[connected_length] = cans[i];
1134  connected_length++;
1135  cans[i] = -1;
1136  --not_yet_found;
1137 
1138  if(connected[connected_length - 1] == to)
1139  {
1140  if(connected_length < c->n)
1141  {
1142  connected[connected_length] = -1;
1143  }
1144  omFree (cans);
1145  return connected;
1146  }
1147  }
1148  }
1149  con_checked++;
1150  }
1151  else
1152  {
1153  for(last_cans_pos++; last_cans_pos <= c->n; last_cans_pos++)
1154  {
1155  if(last_cans_pos == c->n)
1156  {
1157  if(connected_length < c->n)
1158  {
1159  connected[connected_length] = -1;
1160  }
1161  omfree (cans);
1162  return connected;
1163  }
1164  if((last_cans_pos == from) || (last_cans_pos == to))
1165  continue;
1167  (I->m[last_cans_pos], c->short_Exps[last_cans_pos], bound,
1168  neg_bounds_short, c->r))
1169  {
1170  cans[cans_length] = last_cans_pos;
1171  cans_length++;
1172  break;
1173  }
1174  }
1175  not_yet_found++;
1176  for(int i = 0; i < con_checked; i++)
1177  {
1178  if(has_t_rep (connected[i], last_cans_pos, c))
1179  {
1180  connected[connected_length] = last_cans_pos;
1181  connected_length++;
1182  cans[cans_length - 1] = -1;
1183  --not_yet_found;
1184  if(connected[connected_length - 1] == to)
1185  {
1186  if(connected_length < c->n)
1187  {
1188  connected[connected_length] = -1;
1189  }
1190  omFree (cans);
1191  return connected;
1192  }
1193  break;
1194  }
1195  }
1196  }
1197  }
1198  if(connected_length < c->n)
1199  {
1200  connected[connected_length] = -1;
1201  }
1202  omfree (cans);
1203  return connected;
1204 }
1205 
1206 #ifdef HEAD_BIN
1207 static inline poly p_MoveHead (poly p, omBin b)
1208 {
1209  poly np;
1210  omTypeAllocBin (poly, np, b);
1211  memmove (np, p, omSizeWOfBin(b) * sizeof (long));
1212  omFreeBinAddr (p);
1213  return np;
1214 }
1215 #endif
1216 
1217 static void replace_pair (int &i, int &j, slimgb_alg * c)
1218 {
1219  if(i < 0)
1220  return;
1221  c->soon_free = NULL;
1222  int syz_deg;
1223  poly lm = pOne ();
1224 
1225  pLcm (c->S->m[i], c->S->m[j], lm);
1226  pSetm (lm);
1227 
1228  int *i_con = make_connections (i, j, lm, c);
1229 
1230  for(int n = 0; ((n < c->n) && (i_con[n] >= 0)); n++)
1231  {
1232  if(i_con[n] == j)
1233  {
1234  now_t_rep (i, j, c);
1235  omFree (i_con);
1236  p_Delete (&lm, c->r);
1237  return;
1238  }
1239  }
1240 
1241  int *j_con = make_connections (j, i, lm, c);
1242 
1243 // if(c->n>1)
1244 // {
1245 // if (i_con[1]>=0)
1246 // i=i_con[1];
1247 // else
1248 // {
1249 // if (j_con[1]>=0)
1250 // j=j_con[1];
1251 // }
1252  // }
1253 
1254  int sugar = syz_deg = c->pTotaldegree (lm);
1255 
1256  p_Delete (&lm, c->r);
1257  if(c->T_deg_full) //Sugar
1258  {
1259  int t_i = c->T_deg_full[i] - c->T_deg[i];
1260  int t_j = c->T_deg_full[j] - c->T_deg[j];
1261  sugar += si_max (t_i, t_j);
1262  //Print("\n max: %d\n",max(t_i,t_j));
1263  }
1264 
1265  for(int m = 0; ((m < c->n) && (i_con[m] >= 0)); m++)
1266  {
1267  if(c->T_deg_full != NULL)
1268  {
1269  int s1 = c->T_deg_full[i_con[m]] + syz_deg - c->T_deg[i_con[m]];
1270  if(s1 > sugar)
1271  continue;
1272  }
1273  if(c->weighted_lengths[i_con[m]] < c->weighted_lengths[i])
1274  i = i_con[m];
1275  }
1276  for(int m = 0; ((m < c->n) && (j_con[m] >= 0)); m++)
1277  {
1278  if(c->T_deg_full != NULL)
1279  {
1280  int s1 = c->T_deg_full[j_con[m]] + syz_deg - c->T_deg[j_con[m]];
1281  if(s1 > sugar)
1282  continue;
1283  }
1284  if(c->weighted_lengths[j_con[m]] < c->weighted_lengths[j])
1285  j = j_con[m];
1286  }
1287 
1288  //can also try dependend search
1289  omfree (i_con);
1290  omfree (j_con);
1291  return;
1292 }
1293 
1294 static void add_later (poly p, const char *prot, slimgb_alg * c)
1295 {
1296  int i = 0;
1297  //check, if it is already in the queue
1298 
1299  while(c->add_later->m[i] != NULL)
1300  {
1301  if(p_LmEqual (c->add_later->m[i], p, c->r))
1302  return;
1303  i++;
1304  }
1305  if(TEST_OPT_PROT)
1306  PrintS (prot);
1307  c->add_later->m[i] = p;
1308 }
1309 
1310 static int simple_posInS (kStrategy strat, poly p, int len, wlen_type wlen)
1311 {
1312  if(strat->sl == -1)
1313  return 0;
1314  if(strat->lenSw)
1315  return pos_helper (strat, p, (wlen_type) wlen, (wlen_set) strat->lenSw,
1316  strat->S);
1317  return pos_helper (strat, p, len, strat->lenS, strat->S);
1318 }
1319 
1320 /*2
1321  *if the leading term of p
1322  *divides the leading term of some S[i] it will be canceled
1323  */
1324 static inline void
1325 clearS (poly p, unsigned long p_sev, int l, int *at, int *k, kStrategy strat)
1326 {
1327  assume (p_sev == pGetShortExpVector (p));
1328  if(!pLmShortDivisibleBy (p, p_sev, strat->S[*at], ~strat->sevS[*at]))
1329  return;
1330  if(l >= strat->lenS[*at])
1331  return;
1332  if(TEST_OPT_PROT)
1333  PrintS ("!");
1334  mflush ();
1335  //pDelete(&strat->S[*at]);
1336  deleteInS ((*at), strat);
1337  (*at)--;
1338  (*k)--;
1339 // assume(lenS_correct(strat));
1340 }
1341 
1342 static int iq_crit (const void *ap, const void *bp)
1343 {
1344  sorted_pair_node *a = *((sorted_pair_node **) ap);
1345  sorted_pair_node *b = *((sorted_pair_node **) bp);
1346  assume (a->i > a->j);
1347  assume (b->i > b->j);
1348 
1349  if(a->deg < b->deg)
1350  return -1;
1351  if(a->deg > b->deg)
1352  return 1;
1353  int comp = pLmCmp (a->lcm_of_lm, b->lcm_of_lm);
1354  if(comp != 0)
1355  return comp;
1356  if(a->expected_length < b->expected_length)
1357  return -1;
1358  if(a->expected_length > b->expected_length)
1359  return 1;
1360  if(a->j > b->j)
1361  return 1;
1362  if(a->j < b->j)
1363  return -1;
1364  return 0;
1365 }
1366 
1367 static wlen_type coeff_mult_size_estimate (int s1, int s2, ring r)
1368 {
1369  if(rField_is_Q (r))
1370  return s1 + s2;
1371  else
1372  return s1 * s2;
1373 }
1374 
1375 static wlen_type pair_weighted_length (int i, int j, slimgb_alg * c)
1376 {
1377  if((c->isDifficultField) && (c->eliminationProblem))
1378  {
1379  int c1 = slim_nsize (p_GetCoeff (c->S->m[i], c->r), c->r);
1380  int c2 = slim_nsize (p_GetCoeff (c->S->m[j], c->r), c->r);
1381  wlen_type el1 = c->weighted_lengths[i] / c1;
1382  assume (el1 != 0);
1383  assume (c->weighted_lengths[i] % c1 == 0);
1384  wlen_type el2 = c->weighted_lengths[j] / c2;
1385  assume (el2 != 0);
1386  //assume (c->weighted_lengths[j] % c2 == 0); // fails in Tst/Plural/dmod_lib.tst
1387  //should be * for function fields
1388  //return (c1+c2) * (el1+el2-2);
1389  wlen_type res = coeff_mult_size_estimate (c1, c2, c->r);
1390  res *= el1 + el2 - 2;
1391  return res;
1392 
1393  }
1394  if(c->isDifficultField)
1395  {
1396  //int cs=slim_nsize(p_GetCoeff(c->S->m[i],c->r),c->r)+
1397  // slim_nsize(p_GetCoeff(c->S->m[j],c->r),c->r);
1398  if(!(TEST_V_COEFSTRAT))
1399  {
1400  wlen_type cs =
1402  (p_GetCoeff (c->S->m[i], c->r), c->r),
1403  slim_nsize (p_GetCoeff (c->S->m[j], c->r),
1404  c->r), c->r);
1405  return (wlen_type) (c->lengths[i] + c->lengths[j] - 2) * (wlen_type) cs;
1406  }
1407  else
1408  {
1409 
1410  wlen_type cs =
1412  (p_GetCoeff (c->S->m[i], c->r), c->r),
1413  slim_nsize (p_GetCoeff (c->S->m[j], c->r),
1414  c->r), c->r);
1415  cs *= cs;
1416  return (wlen_type) (c->lengths[i] + c->lengths[j] - 2) * (wlen_type) cs;
1417  }
1418  }
1419  if(c->eliminationProblem)
1420  {
1421 
1422  return (c->weighted_lengths[i] + c->weighted_lengths[j] - 2);
1423  }
1424  return c->lengths[i] + c->lengths[j] - 2;
1425 
1426 }
1427 
1429  int *ip)
1430 {
1431  p_Test (h, c->r);
1432  assume (h != NULL);
1433  poly got = gcd_of_terms (h, c->r);
1434  if((got != NULL) && (TEST_V_UPTORADICAL))
1435  {
1436  poly copy = p_Copy (got, c->r);
1437  //p_wrp(got,c->r);
1438  BOOLEAN changed = monomial_root (got, c->r);
1439  if(changed)
1440  {
1441  poly div_by = pDivide (copy, got);
1442  poly iter = h;
1443  while(iter)
1444  {
1445  pExpVectorSub (iter, div_by);
1446  pIter (iter);
1447  }
1448  p_Delete (&div_by, c->r);
1449  PrintS ("U");
1450  }
1451  p_Delete (&copy, c->r);
1452  }
1453 
1454 #define ENLARGE(pointer, type) pointer=(type*) omrealloc(pointer, c->array_lengths*sizeof(type))
1455 
1456 #define ENLARGE_ALIGN(pointer, type) {if(pointer)\
1457  pointer=(type*)omReallocAligned(pointer, c->array_lengths*sizeof(type));\
1458  else pointer=(type*)omAllocAligned(c->array_lengths*sizeof(type));}
1459 // BOOLEAN corr=lenS_correct(c->strat);
1460  int sugar;
1461  int ecart = 0;
1462  ++(c->n);
1463  ++(c->S->ncols);
1464  int i, j;
1465  i = c->n - 1;
1466  sorted_pair_node **nodes =
1467  (sorted_pair_node **) omalloc (sizeof (sorted_pair_node *) * i);
1468  int spc = 0;
1469  if(c->n > c->array_lengths)
1470  {
1471  c->array_lengths = c->array_lengths * 2;
1472  assume (c->array_lengths >= c->n);
1473  ENLARGE (c->T_deg, int);
1476 
1477  ENLARGE_ALIGN (c->short_Exps, long);
1478  ENLARGE (c->lengths, int);
1479 #ifndef HAVE_BOOST
1480 #ifndef USE_STDVECBOOL
1481 
1482  ENLARGE_ALIGN (c->states, char *);
1483 #endif
1484 #endif
1486  //if (c->weighted_lengths!=NULL) {
1488  //}
1489  //ENLARGE_ALIGN(c->S->m,poly);
1490  }
1491  pEnlargeSet (&c->S->m, c->n - 1, 1);
1492  if(c->T_deg_full)
1493  ENLARGE (c->T_deg_full, int);
1494  sugar = c->T_deg[i] = c->pTotaldegree (h);
1495  if(c->T_deg_full)
1496  {
1497  sugar = c->T_deg_full[i] = c->pTotaldegree_full (h);
1498  ecart = sugar - c->T_deg[i];
1499  assume (ecart >= 0);
1500  }
1501  c->tmp_pair_lm[i] = pOne_Special (c->r);
1502 
1503  c->tmp_spn[i] = (sorted_pair_node *) omAlloc (sizeof (sorted_pair_node));
1504 
1505  c->lengths[i] = pLength (h);
1506 
1507  //necessary for correct weighted length
1508 
1509  if(!rField_is_Zp (c->r))
1510  {
1511  p_Cleardenom (h, c->r);
1512  //p_Content(h,c->r); //is a duplicate call, but belongs here
1513  }
1514  else
1515  pNorm (h);
1516  pNormalize (h);
1517 
1518  c->weighted_lengths[i] = pQuality (h, c, c->lengths[i]);
1519  c->gcd_of_terms[i] = got;
1520 #ifdef HAVE_BOOST
1521  c->states.push_back (dynamic_bitset <> (i));
1522 
1523 #else
1524 #ifdef USE_STDVECBOOL
1525 
1526  c->states.push_back (vector < bool > (i));
1527 
1528 #else
1529  if(i > 0)
1530  c->states[i] = (char *) omAlloc (i * sizeof (char));
1531  else
1532  c->states[i] = NULL;
1533 #endif
1534 #endif
1535 
1536  c->S->m[i] = h;
1537  c->short_Exps[i] = p_GetShortExpVector (h, c->r);
1538 
1539 #undef ENLARGE
1540 #undef ENLARGE_ALIGN
1541  if(p_GetComp (h, currRing) <= c->syz_comp)
1542  {
1543  for(j = 0; j < i; j++)
1544  {
1545 
1546 
1547 #ifndef HAVE_BOOST
1548  c->states[i][j] = UNCALCULATED;
1549 #endif
1550  assume (p_LmDivisibleBy (c->S->m[i], c->S->m[j], c->r) ==
1551  p_LmShortDivisibleBy (c->S->m[i], c->short_Exps[i], c->S->m[j],
1552  ~(c->short_Exps[j]), c->r));
1553 
1554  if(__p_GetComp (c->S->m[i], c->r) != __p_GetComp (c->S->m[j], c->r))
1555  {
1556  //c->states[i][j]=UNCALCULATED;
1557  //WARNUNG: be careful
1558  continue;
1559  }
1560  else if((!c->nc) && (c->lengths[i] == 1) && (c->lengths[j] == 1))
1561  {
1562  c->states[i][j] = HASTREP;
1563  }
1564  else if(((!c->nc) || (c->is_homog && rIsSCA (c->r)))
1565  && (pHasNotCF (c->S->m[i], c->S->m[j])))
1566 // else if ((!(c->nc)) && (pHasNotCF(c->S->m[i],c->S->m[j])))
1567  {
1568  c->easy_product_crit++;
1569  c->states[i][j] = HASTREP;
1570  continue;
1571  }
1572  else
1574  (c->S->m[i], c->gcd_of_terms[i], c->S->m[j], c->gcd_of_terms[j],
1575  c))
1576  {
1577  c->states[i][j] = HASTREP;
1578  c->extended_product_crit++;
1579  //PrintS("E");
1580  }
1581  // if (c->states[i][j]==UNCALCULATED)
1582  // {
1583 
1584  if((TEST_V_FINDMONOM) && (!c->nc))
1585  {
1586  //PrintS("COMMU");
1587  // if (c->lengths[i]==c->lengths[j])
1588  // {
1589 // poly short_s=ksCreateShortSpoly(c->S->m[i],c->S->m[j],c->r);
1590 // if (short_s==NULL)
1591 // {
1592 // c->states[i][j]=HASTREP;
1593 // }
1594 // else
1595 // {
1596 // p_Delete(&short_s, currRing);
1597 // }
1598 // }
1599  if(c->lengths[i] + c->lengths[j] == 3)
1600  {
1601 
1602 
1603  poly short_s = ksCreateShortSpoly (c->S->m[i], c->S->m[j], c->r);
1604  if(short_s == NULL)
1605  {
1606  c->states[i][j] = HASTREP;
1607  }
1608  else
1609  {
1610  assume (pLength (short_s) == 1);
1611  if(TEST_V_UPTORADICAL)
1612  monomial_root (short_s, c->r);
1613  int iS = kFindDivisibleByInS_easy (c->strat, short_s,
1614  p_GetShortExpVector (short_s,
1615  c->r));
1616  if(iS < 0)
1617  {
1618  //PrintS("N");
1619  if(TRUE)
1620  {
1621  c->states[i][j] = HASTREP;
1622  add_later (short_s, "N", c);
1623  }
1624  else
1625  p_Delete (&short_s, currRing);
1626  }
1627  else
1628  {
1629  if(c->strat->lenS[iS] > 1)
1630  {
1631  //PrintS("O");
1632  if(TRUE)
1633  {
1634  c->states[i][j] = HASTREP;
1635  add_later (short_s, "O", c);
1636  }
1637  else
1638  p_Delete (&short_s, currRing);
1639  }
1640  else
1641  p_Delete (&short_s, currRing);
1642  c->states[i][j] = HASTREP;
1643  }
1644 
1645 
1646  }
1647  }
1648  }
1649  // if (short_s)
1650  // {
1651  assume (spc <= j);
1652  sorted_pair_node *s = c->tmp_spn[spc]; //(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
1653  s->i = si_max (i, j);
1654  s->j = si_min (i, j);
1655  assume (s->j == j);
1656  s->expected_length = pair_weighted_length (i, j, c); //c->lengths[i]+c->lengths[j]-2;
1657 
1658  poly lm = c->tmp_pair_lm[spc]; //=pOne_Special();
1659 
1660  pLcm (c->S->m[i], c->S->m[j], lm);
1661  pSetm (lm);
1662  p_Test (lm, c->r);
1663  s->deg = c->pTotaldegree (lm);
1664 
1665  if(c->T_deg_full) //Sugar
1666  {
1667  int t_i = c->T_deg_full[s->i] - c->T_deg[s->i];
1668  int t_j = c->T_deg_full[s->j] - c->T_deg[s->j];
1669  s->deg += si_max (t_i, t_j);
1670  //Print("\n max: %d\n",max(t_i,t_j));
1671  }
1672  p_Test (lm, c->r);
1673  s->lcm_of_lm = lm;
1674  // pDelete(&short_s);
1675  //assume(lm!=NULL);
1676  nodes[spc] = s;
1677  spc++;
1678 
1679  // }
1680  //else
1681  //{
1682  //c->states[i][j]=HASTREP;
1683  //}
1684  }
1685  } //if syz_comp end
1686 
1687  assume (spc <= i);
1688  //now ideal quotient crit
1689  qsort (nodes, spc, sizeof (sorted_pair_node *), iq_crit);
1690 
1691  sorted_pair_node **nodes_final =
1692  (sorted_pair_node **) omalloc (sizeof (sorted_pair_node *) * i);
1693  int spc_final = 0;
1694  j = 0;
1695  while(j < spc)
1696  {
1697  int lower = j;
1698  int upper;
1699  BOOLEAN has = FALSE;
1700  for(upper = lower + 1; upper < spc; upper++)
1701  {
1702  if(!pLmEqual (nodes[lower]->lcm_of_lm, nodes[upper]->lcm_of_lm))
1703  {
1704  break;
1705  }
1706  if(has_t_rep (nodes[upper]->i, nodes[upper]->j, c))
1707  has = TRUE;
1708  }
1709  upper = upper - 1;
1710  int z;
1711  assume (spc_final <= j);
1712  for(z = 0; z < spc_final; z++)
1713  {
1714  if(p_LmDivisibleBy
1715  (nodes_final[z]->lcm_of_lm, nodes[lower]->lcm_of_lm, c->r))
1716  {
1717  has = TRUE;
1718  break;
1719  }
1720  }
1721 
1722  if(has)
1723  {
1724  for(; lower <= upper; lower++)
1725  {
1726  //free_sorted_pair_node(nodes[lower],c->r);
1727  //omfree(nodes[lower]);
1728  nodes[lower] = NULL;
1729  }
1730  j = upper + 1;
1731  continue;
1732  }
1733  else
1734  {
1735  p_Test (nodes[lower]->lcm_of_lm, c->r);
1736  nodes[lower]->lcm_of_lm = pCopy (nodes[lower]->lcm_of_lm);
1737  assume (__p_GetComp (c->S->m[nodes[lower]->i], c->r) ==
1738  __p_GetComp (c->S->m[nodes[lower]->j], c->r));
1739  nodes_final[spc_final] =
1740  (sorted_pair_node *) omAlloc (sizeof (sorted_pair_node));
1741 
1742  *(nodes_final[spc_final++]) = *(nodes[lower]);
1743  //c->tmp_spn[nodes[lower]->j]=(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
1744  nodes[lower] = NULL;
1745  for(lower = lower + 1; lower <= upper; lower++)
1746  {
1747  // free_sorted_pair_node(nodes[lower],c->r);
1748  //omfree(nodes[lower]);
1749  nodes[lower] = NULL;
1750  }
1751  j = upper + 1;
1752  continue;
1753  }
1754  }
1755 
1756  // Print("i:%d,spc_final:%d",i,spc_final);
1757 
1758  assume (spc_final <= spc);
1759  omfree (nodes);
1760  nodes = NULL;
1761 
1762  add_to_reductors (c, h, c->lengths[c->n - 1], ecart, TRUE);
1763  //i=posInS(c->strat,c->strat->sl,h,0 ecart);
1764  if(!(c->nc))
1765  {
1766  if(c->lengths[c->n - 1] == 1)
1767  shorten_tails (c, c->S->m[c->n - 1]);
1768  }
1769  //you should really update c->lengths, c->strat->lenS, and the oder of polys in strat if you sort after lengths
1770 
1771  //for(i=c->strat->sl; i>0;i--)
1772  // if(c->strat->lenS[i]<c->strat->lenS[i-1]) printf("fehler bei %d\n",i);
1773  if(c->Rcounter > 50)
1774  {
1775  c->Rcounter = 0;
1776  cleanS (c->strat, c);
1777  }
1778 
1779 #ifdef HAVE_PLURAL
1780  // for SCA:
1781  // here write at the end of nodes_final[spc_final,...,spc_final+lmdeg-1]
1782  if(rIsSCA (c->r))
1783  {
1784  const poly pNext = pNext (h);
1785 
1786  if(pNext != NULL)
1787  {
1788  // for additional polynomials
1789  const unsigned int m_iFirstAltVar = scaFirstAltVar (c->r);
1790  const unsigned int m_iLastAltVar = scaLastAltVar (c->r);
1791 
1792  int N = // c->r->N;
1793  m_iLastAltVar - m_iFirstAltVar + 1; // should be enough
1794  // TODO: but we may also use got = gcd({m}_{m\in f}))!
1795 
1796  poly *array_arg = (poly *) omalloc (N * sizeof (poly)); // !
1797  int j = 0;
1798 
1799 
1800  for(unsigned short v = m_iFirstAltVar; v <= m_iLastAltVar; v++)
1801  // for all x_v | Ann(lm(h))
1802  if(p_GetExp (h, v, c->r)) // TODO: use 'got' here!
1803  {
1804  assume (p_GetExp (h, v, c->r) == 1);
1805 
1806  poly p = sca_pp_Mult_xi_pp (v, pNext, c->r); // x_v * h;
1807 
1808  if(p != NULL) // if (x_v * h != 0)
1809  array_arg[j++] = p;
1810  } // for all x_v | Ann(lm(h))
1811 
1812  c->introduceDelayedPairs (array_arg, j);
1813 
1814  omFree (array_arg); // !!!
1815  }
1816 // PrintS("Saturation - done!!!\n");
1817  }
1818 #endif // if SCAlgebra
1819 
1820 
1821  if(!ip)
1822  {
1823  qsort (nodes_final, spc_final, sizeof (sorted_pair_node *),
1825 
1826 
1827  c->apairs =
1828  spn_merge (c->apairs, c->pair_top + 1, nodes_final, spc_final, c);
1829  c->pair_top += spc_final;
1831  omfree (nodes_final);
1832  return NULL;
1833  }
1834  {
1835  *ip = spc_final;
1836  return nodes_final;
1837  }
1838 }
1839 
1840 static poly redNF2 (poly h, slimgb_alg * c, int &len, number & m, int n)
1841 {
1842  m = nInit (1);
1843  if(h == NULL)
1844  return NULL;
1845 
1846  assume (len == pLength (h));
1847  kStrategy strat = c->strat;
1848  if(0 > strat->sl)
1849  {
1850  return h;
1851  }
1852  int j;
1853 
1854  LObject P (h);
1855  P.SetShortExpVector ();
1856  P.bucket = kBucketCreate (currRing);
1857  // BOOLEAN corr=lenS_correct(strat);
1858  kBucketInit (P.bucket, P.p, len /*pLength(P.p) */ );
1859  //wlen_set lenSw=(wlen_set) c->strat->lenS;
1860  //FIXME: plainly wrong
1861  //strat->lenS;
1862  //if (strat->lenSw!=NULL)
1863  // lenSw=strat->lenSw;
1864  //int max_pos=simple_posInS(strat,P.p);
1865  loop
1866  {
1867  //int dummy=strat->sl;
1868  j = kFindDivisibleByInS_easy (strat, P.p, P.sev);
1869  //j=kFindDivisibleByInS(strat,&dummy,&P);
1870  if((j >= 0) && ((!n) ||
1871  ((strat->lenS[j] <= n) &&
1872  ((strat->lenSw == NULL) || (strat->lenSw[j] <= n)))))
1873  {
1874  nNormalize (pGetCoeff (P.p));
1875 #ifdef KDEBUG
1876  if(TEST_OPT_DEBUG)
1877  {
1878  PrintS ("red:");
1879  wrp (h);
1880  PrintS (" with ");
1881  wrp (strat->S[j]);
1882  }
1883 #endif
1884 
1885  number coef = kBucketPolyRed (P.bucket, strat->S[j],
1886  strat->lenS[j] /*pLength(strat->S[j]) */ ,
1887  strat->kNoether);
1888  number m2 = nMult (m, coef);
1889  nDelete (&m);
1890  m = m2;
1891  nDelete (&coef);
1892  h = kBucketGetLm (P.bucket);
1893 
1894  if(h == NULL)
1895  {
1896  len = 0;
1897  kBucketDestroy (&P.bucket);
1898  return NULL;
1899  }
1900  P.p = h;
1901  P.t_p = NULL;
1902  P.SetShortExpVector ();
1903 #ifdef KDEBUG
1904  if(TEST_OPT_DEBUG)
1905  {
1906  PrintS ("\nto:");
1907  wrp (h);
1908  PrintLn ();
1909  }
1910 #endif
1911  }
1912  else
1913  {
1914  kBucketClear (P.bucket, &(P.p), &len);
1915  kBucketDestroy (&P.bucket);
1916  pNormalize (P.p);
1917  assume (len == (pLength (P.p)));
1918  return P.p;
1919  }
1920  }
1921 }
1922 
1924 {
1925  if(h == NULL)
1926  return NULL; //n_Init(1,currRing);
1927  if(TEST_V_MODPSOLVSB)
1928  {
1929  bit_reduce (pNext (h), strat->tailRing);
1930  }
1931  int i;
1932  int len = pLength (h);
1933  for(i = 0; i <= strat->sl; i++)
1934  {
1935  if((strat->lenS[i] > 2)
1936  || ((strat->lenSw != NULL) && (strat->lenSw[i] > 2)))
1937  break;
1938  }
1939  return (redNFTail (h, i - 1, strat, len));
1940 }
1941 
1942 static void line_of_extended_prod (int fixpos, slimgb_alg * c)
1943 {
1944  if(c->gcd_of_terms[fixpos] == NULL)
1945  {
1946  c->gcd_of_terms[fixpos] = gcd_of_terms (c->S->m[fixpos], c->r);
1947  if(c->gcd_of_terms[fixpos])
1948  {
1949  int i;
1950  for(i = 0; i < fixpos; i++)
1951  if((c->states[fixpos][i] != HASTREP)
1952  &&
1954  (c->S->m[fixpos], c->gcd_of_terms[fixpos], c->S->m[i],
1955  c->gcd_of_terms[i], c)))
1956  {
1957  c->states[fixpos][i] = HASTREP;
1958  c->extended_product_crit++;
1959  }
1960  for(i = fixpos + 1; i < c->n; i++)
1961  if((c->states[i][fixpos] != HASTREP)
1962  &&
1964  (c->S->m[fixpos], c->gcd_of_terms[fixpos], c->S->m[i],
1965  c->gcd_of_terms[i], c)))
1966  {
1967  c->states[i][fixpos] = HASTREP;
1968  c->extended_product_crit++;
1969  }
1970  }
1971  }
1972 }
1973 
1974 static void c_S_element_changed_hook (int pos, slimgb_alg * c)
1975 {
1976  length_one_crit (c, pos, c->lengths[pos]);
1977  if(!c->nc)
1978  line_of_extended_prod (pos, c);
1979 }
1980 
1982 {
1983 public:
1987  int n;
1988  poly_tree_node (int sn):l (NULL), r (NULL), n (sn)
1989  {
1990  }
1991 };
1993 {
1994 public:
1996  int n;
1997  int get_n (poly p);
1998  exp_number_builder ():top_level (0), n (0)
1999  {
2000  }
2001 };
2003 {
2004  poly_tree_node **node = &top_level;
2005  while(*node != NULL)
2006  {
2007  int c = pLmCmp (p, (*node)->p);
2008  if(c == 0)
2009  return (*node)->n;
2010  if(c == -1)
2011  node = &((*node)->r);
2012  else
2013  node = &((*node)->l);
2014  }
2015  (*node) = new poly_tree_node (n);
2016  n++;
2017  (*node)->p = pLmInit (p);
2018  return (*node)->n;
2019 }
2020 
2021 //mac_polys exp are smaller iff they are greater by monomial ordering
2022 //corresponding to solving linear equations notation
2023 
2024 //! obsolete
2026 {
2028  int n;
2029 };
2030 
2031 
2032 //! obsolete
2033 void t2ippa_rec (poly * ip, int *ia, poly_tree_node * k, int &offset)
2034 {
2035  if(!k)
2036  return;
2037  t2ippa_rec (ip, ia, k->l, offset);
2038  ip[offset] = k->p;
2039  ia[k->n] = offset;
2040  ++offset;
2041 
2042  t2ippa_rec (ip, ia, k->r, offset);
2043  delete k;
2044 }
2045 
2046 //! obsolete
2047 void t2ippa (poly * ip, int *ia, exp_number_builder & e)
2048 {
2049 
2050  int o = 0;
2051  t2ippa_rec (ip, ia, e.top_level, o);
2052 }
2053 
2054 int anti_poly_order (const void *a, const void *b)
2055 {
2056  return -pLmCmp (((int_poly_pair *) a)->p, ((int_poly_pair *) b)->p);
2057 }
2058 
2060 {
2061  red_object r2 = ro;
2062  ro.validate ();
2063  if((r2.p != ro.p) || (r2.sev != ro.sev))
2064  return FALSE;
2065  return TRUE;
2066 }
2067 
2068 int terms_sort_crit (const void *a, const void *b)
2069 {
2070  return -pLmCmp (*((poly *) a), *((poly *) b));
2071 }
2072 
2073 #if 0 // currently unused
2074 static void unify_terms (poly * terms, int &sum)
2075 {
2076  if(sum == 0)
2077  return;
2078  int last = 0;
2079  int curr = 1;
2080  while(curr < sum)
2081  {
2082  if(!(pLmEqual (terms[curr], terms[last])))
2083  {
2084  terms[++last] = terms[curr];
2085  }
2086  ++curr;
2087  }
2088  sum = last + 1;
2089 }
2090 #endif
2091 #if 0 // currently unused
2092 static void
2093 export_mat (number * number_array, int pn, int tn, const char *format_str,
2094  int mat_nr)
2095 {
2096  char matname[20];
2097  sprintf (matname, format_str, mat_nr);
2098  FILE *out = fopen (matname, "w");
2099  int i, j;
2100  fprintf (out, "mat=[\n");
2101  for(i = 0; i < pn; i++)
2102  {
2103  fprintf (out, "[\n");
2104  for(j = 0; j < tn; j++)
2105  {
2106  if(j > 0)
2107  {
2108  fprintf (out, ", ");
2109  }
2110  fprintf (out, "%i", npInt (number_array[i * tn + j], currRing));
2111  }
2112  if(i < pn - 1)
2113  fprintf (out, "],\n");
2114  else
2115  fprintf (out, "],\n");
2116  }
2117  fprintf (out, "]\n");
2118  fclose (out);
2119 }
2120 #endif
2121 //typedef unsigned short number_type;
2122 
2123 
2124 #ifdef USE_NORO
2125 #ifndef NORO_CACHE
2126 static void
2127 linalg_step_modp (poly * p, poly * p_out, int &pn, poly * terms, int tn,
2128  slimgb_alg * c)
2129 {
2130  static int export_n = 0;
2131  assume (terms[tn - 1] != NULL);
2132  assume (rField_is_Zp (c->r));
2133  //I don't do deletes, copies of number_types ...
2134  const number_type zero = 0; //npInit(0);
2135  int array_size = pn * tn;
2136  number_type *number_array =
2137  (number_type *) omalloc (pn * tn * sizeof (number_type));
2138  int i;
2139  for(i = 0; i < array_size; i++)
2140  {
2141  number_array[i] = zero;
2142  }
2143  for(i = 0; i < pn; i++)
2144  {
2145  poly h = p[i];
2146  //int base=tn*i;
2147  write_poly_to_row (number_array + tn * i, h, terms, tn, c->r);
2148 
2149  }
2150 #if 0
2151  //export matrix
2152  export_mat (number_array, pn, tn, "mat%i.py", ++export_n);
2153 #endif
2154  int rank = pn;
2155  simplest_gauss_modp (number_array, rank, tn);
2156  int act_row = 0;
2157  int p_pos = 0;
2158  for(i = 0; i < pn; i++)
2159  {
2160  poly h = NULL;
2161  int j;
2162  int base = tn * i;
2163  number *row = number_array + base;
2164  h = row_to_poly (row, terms, tn, c->r);
2165 
2166  if(h != NULL)
2167  {
2168  p_out[p_pos++] = h;
2169  }
2170  }
2171  pn = p_pos;
2172  //assert(p_pos==rank)
2173  while(p_pos < pn)
2174  {
2175  p_out[p_pos++] = NULL;
2176  }
2177 #if 0
2178  export_mat (number_array, pn, tn, "mat%i.py", ++export_n);
2179 #endif
2180 }
2181 #endif
2182 #endif
2183 static void mass_add (poly * p, int pn, slimgb_alg * c)
2184 {
2185  int j;
2186  int *ibuf = (int *) omalloc (pn * sizeof (int));
2187  sorted_pair_node ***sbuf =
2188  (sorted_pair_node ***) omalloc (pn * sizeof (sorted_pair_node **));
2189  for(j = 0; j < pn; j++)
2190  {
2191  p_Test (p[j], c->r);
2192  sbuf[j] = add_to_basis_ideal_quotient (p[j], c, ibuf + j);
2193  }
2194  int sum = 0;
2195  for(j = 0; j < pn; j++)
2196  {
2197  sum += ibuf[j];
2198  }
2199  sorted_pair_node **big_sbuf =
2200  (sorted_pair_node **) omalloc (sum * sizeof (sorted_pair_node *));
2201  int partsum = 0;
2202  for(j = 0; j < pn; j++)
2203  {
2204  memmove (big_sbuf + partsum, sbuf[j],
2205  ibuf[j] * sizeof (sorted_pair_node *));
2206  omFree (sbuf[j]);
2207  partsum += ibuf[j];
2208  }
2209 
2210  qsort (big_sbuf, sum, sizeof (sorted_pair_node *), tgb_pair_better_gen2);
2211  c->apairs = spn_merge (c->apairs, c->pair_top + 1, big_sbuf, sum, c);
2212  c->pair_top += sum;
2214  omfree (big_sbuf);
2215  omfree (sbuf);
2216  omfree (ibuf);
2217  //omfree(buf);
2218 #ifdef TGB_DEBUG
2219  int z;
2220  for(z = 1; z <= c->pair_top; z++)
2221  {
2222  assume (pair_better (c->apairs[z], c->apairs[z - 1], c));
2223  }
2224 #endif
2225 
2226 }
2227 
2228 #ifdef NORO_CACHE
2229 #ifndef NORO_NON_POLY
2230 void NoroCache::evaluateRows ()
2231 {
2232  //after that can evaluate placeholders
2233  int i;
2234  buffer = (number *) omAlloc (nIrreducibleMonomials * sizeof (number));
2235  for(i = 0; i < root.branches_len; i++)
2236  {
2237  evaluateRows (1, root.branches[i]);
2238  }
2239  omFree (buffer);
2240  buffer = NULL;
2241 }
2242 
2243 void NoroCache::evaluateRows (int level, NoroCacheNode * node)
2244 {
2245  assume (level >= 0);
2246  if(node == NULL)
2247  return;
2248  if(level < (currRing->N))
2249  {
2250  int i, sum;
2251  for(i = 0; i < node->branches_len; i++)
2252  {
2253  evaluateRows (level + 1, node->branches[i]);
2254  }
2255  }
2256  else
2257  {
2258  DataNoroCacheNode *dn = (DataNoroCacheNode *) node;
2259  if(dn->value_len != backLinkCode)
2260  {
2261  poly p = dn->value_poly;
2262 #ifndef NORO_SPARSE_ROWS_PRE
2263  dn->row = new DenseRow ();
2264  DenseRow *row = dn->row;
2265  memset (buffer, 0, sizeof (number) * nIrreducibleMonomials);
2266 
2267  if(p == NULL)
2268  {
2269  row->array = NULL;
2270  row->begin = 0;
2271  row->end = 0;
2272  return;
2273  }
2274  int i = 0;
2275  int idx;
2276  number *a = buffer;
2277  while(p)
2278  {
2280 
2281  idx = ref->term_index;
2282  assume (idx >= 0);
2283  a[idx] = p_GetCoeff (p, currRing);
2284  if(i == 0)
2285  row->begin = idx;
2286  i++;
2287  pIter (p);
2288  }
2289  row->end = idx + 1;
2290  assume (row->end > row->begin);
2291  int len = row->end - row->begin;
2292  row->array = (number *) omalloc ((len) * sizeof (number));
2293  memcpy (row->array, a + row->begin, len * sizeof (number));
2294 #else
2295  assume (dn->value_len == pLength (dn->value_poly));
2296  dn->row = new SparseRow (dn->value_len);
2297  SparseRow *row = dn->row;
2298  int i = 0;
2299  while(p)
2300  {
2302 
2303  int idx = ref->term_index;
2304  assume (idx >= 0);
2305  row->idx_array[i] = idx;
2306  row->coef_array[i] = p_GetCoeff (p, currRing);
2307  i++;
2308  pIter (p);
2309  }
2310  if(i != dn->value_len)
2311  {
2312  PrintS ("F4 calc wrong, as poly len was wrong\n");
2313  }
2314  assume (i == dn->value_len);
2315 #endif
2316  }
2317  }
2318 }
2319 
2320 void
2321  NoroCache::evaluatePlaceHolder (number * row,
2322  std::vector < NoroPlaceHolder >
2323  &place_holders)
2324 {
2325  int i;
2326  int s = place_holders.size ();
2327  for(i = 0; i < s; i++)
2328  {
2329  DataNoroCacheNode *ref = place_holders[i].ref;
2330  number coef = place_holders[i].coef;
2331  if(ref->value_len == backLinkCode)
2332  {
2333  row[ref->term_index] = npAddM (row[ref->term_index], coef);
2334  }
2335  else
2336  {
2337 #ifndef NORO_SPARSE_ROWS_PRE
2338  DenseRow *ref_row = ref->row;
2339  if(ref_row == NULL)
2340  continue;
2341  number *ref_begin = ref_row->array;
2342  number *ref_end = ref_row->array + (ref_row->end - ref_row->begin);
2343  number *my_pos = row + ref_row->begin;
2344  //TODO npisOne distinction
2345  if(!(npIsOne (coef)))
2346  {
2347  while(ref_begin != ref_end)
2348  {
2349 
2350  *my_pos = npAddM (*my_pos, npMult (coef, *ref_begin));
2351  ++ref_begin;
2352  ++my_pos;
2353  }
2354  }
2355  else
2356  {
2357  while(ref_begin != ref_end)
2358  {
2359 
2360  *my_pos = npAddM (*my_pos, *ref_begin);
2361  ++ref_begin;
2362  ++my_pos;
2363  }
2364  }
2365 
2366 #else
2367  SparseRow *ref_row = ref->row;
2368  if(ref_row == NULL)
2369  continue;
2370  int n = ref_row->len;
2371  int j;
2372  int *idx_array = ref_row->idx_array;
2373  number *coef_array = ref_row->coef_array;
2374  for(j = 0; j < n; j++)
2375  {
2376  int idx = idx_array[j];
2377  number ref_coef = coef_array[j];
2378  row[idx] = npAddM (row[idx], npMult (coef, ref_coef));
2379  }
2380 #endif
2381  }
2382  }
2383 }
2384 #endif
2385 
2386 //poly noro_red_non_unique(poly p, int &len, NoroCache* cache,slimgb_alg* c);
2387 
2388 #ifndef NORO_NON_POLY
2389 MonRedRes
2390 noro_red_mon (poly t, BOOLEAN force_unique, NoroCache * cache, slimgb_alg * c)
2391 {
2392  MonRedRes res_holder;
2393 
2394  //wrp(t);
2395  res_holder.changed = TRUE;
2396  if(force_unique)
2397  {
2398  DataNoroCacheNode *ref = cache->getCacheReference (t);
2399  if(ref != NULL)
2400  {
2401  res_holder.len = ref->value_len;
2402  if(res_holder.len == NoroCache::backLinkCode)
2403  {
2404  res_holder.len = 1;
2405  }
2406  res_holder.coef = p_GetCoeff (t, c->r);
2407  res_holder.p = ref->value_poly;
2408  res_holder.ref = ref;
2409  res_holder.onlyBorrowed = TRUE;
2410  res_holder.changed = TRUE;
2411  p_Delete (&t, c->r);
2412  return res_holder;
2413  }
2414  }
2415  else
2416  {
2417  BOOLEAN succ;
2418  poly cache_lookup = cache->lookup (t, succ, res_holder.len); //don't own this yet
2419  if(succ)
2420  {
2421  if(cache_lookup == t)
2422  {
2423  //know they are equal
2424  //res_holder.len=1;
2425 
2426  res_holder.changed = FALSE;
2427  res_holder.p = t;
2428  res_holder.coef = npInit (1);
2429 
2430  res_holder.onlyBorrowed = FALSE;
2431  return res_holder;
2432  }
2433 
2434  res_holder.coef = p_GetCoeff (t, c->r);
2435  p_Delete (&t, c->r);
2436 
2437  res_holder.p = cache_lookup;
2438 
2439  res_holder.onlyBorrowed = TRUE;
2440  return res_holder;
2441 
2442  }
2443  }
2444 
2445  unsigned long sev = p_GetShortExpVector (t, currRing);
2446  int i = kFindDivisibleByInS_easy (c->strat, t, sev);
2447  if(i >= 0)
2448  {
2449  number coef_bak = p_GetCoeff (t, c->r);
2450 
2451  p_SetCoeff (t, npInit (1), c->r);
2452  assume (npIsOne (p_GetCoeff (c->strat->S[i], c->r)));
2453  number coefstrat = p_GetCoeff (c->strat->S[i], c->r);
2454 
2455  //poly t_copy_mon=p_Copy(t,c->r);
2456  poly exp_diff = cache->temp_term;
2457  p_ExpVectorDiff (exp_diff, t, c->strat->S[i], c->r);
2458  p_SetCoeff (exp_diff, npNeg (nInvers (coefstrat)), c->r);
2459  // nInvers may be npInvers or nvInvers
2460  p_Setm (exp_diff, c->r);
2461  assume (c->strat->S[i] != NULL);
2462  //poly t_to_del=t;
2463  poly res;
2464  res = pp_Mult_mm (pNext (c->strat->S[i]), exp_diff, c->r);
2465 
2466  res_holder.len = c->strat->lenS[i] - 1;
2467  res = noro_red_non_unique (res, res_holder.len, cache, c);
2468 
2469  DataNoroCacheNode *ref = cache->insert (t, res, res_holder.len);
2470  p_Delete (&t, c->r);
2471  //p_Delete(&t_copy_mon,c->r);
2472  //res=pMult_nn(res,coef_bak);
2473  res_holder.changed = TRUE;
2474  res_holder.p = res;
2475  res_holder.coef = coef_bak;
2476  res_holder.onlyBorrowed = TRUE;
2477  res_holder.ref = ref;
2478  return res_holder;
2479  }
2480  else
2481  {
2482  number coef_bak = p_GetCoeff (t, c->r);
2483  number one = npInit (1);
2484  p_SetCoeff (t, one, c->r);
2485  res_holder.len = 1;
2486  if(!(force_unique))
2487  {
2488  res_holder.ref = cache->insert (t, t, res_holder.len);
2489  p_SetCoeff (t, coef_bak, c->r);
2490  //return t;
2491 
2492  //we need distinction
2493  res_holder.changed = FALSE;
2494  res_holder.p = t;
2495 
2496  res_holder.coef = npInit (1);
2497  res_holder.onlyBorrowed = FALSE;
2498  return res_holder;
2499  }
2500  else
2501  {
2502  res_holder.ref = cache->insertAndTransferOwnerShip (t, c->r);
2503  res_holder.coef = coef_bak;
2504  res_holder.onlyBorrowed = TRUE;
2505  res_holder.changed = FALSE;
2506  res_holder.p = t;
2507  return res_holder;
2508  }
2509  }
2510 
2511 }
2512 #endif
2513 //SparseRow* noro_red_to_non_poly(poly p, int &len, NoroCache* cache,slimgb_alg* c);
2514 #ifndef NORO_NON_POLY
2515 //len input and out: Idea: reverse addition
2516 poly noro_red_non_unique (poly p, int &len, NoroCache * cache, slimgb_alg * c)
2517 {
2518  assume (len == pLength (p));
2519  poly orig_p = p;
2520  if(p == NULL)
2521  {
2522  len = 0;
2523  return NULL;
2524  }
2526  kBucketInit (bucket, NULL, 0);
2527  poly unchanged_head = NULL;
2528  poly unchanged_tail = NULL;
2529  int unchanged_size = 0;
2530 
2531  while(p)
2532  {
2533  poly t = p;
2534  pIter (p);
2535  pNext (t) = NULL;
2536 #ifndef SING_NDEBUG
2537  number coef_debug = p_GetCoeff (t, currRing);
2538 #endif
2539  MonRedRes red = noro_red_mon (t, FALSE, cache, c);
2540  if((!(red.changed)) && (!(red.onlyBorrowed)))
2541  {
2542  unchanged_size++;
2543  assume (npIsOne (red.coef));
2544  assume (p_GetCoeff (red.p, currRing) == coef_debug);
2545  if(unchanged_head)
2546  {
2547  pNext (unchanged_tail) = red.p;
2548  pIter (unchanged_tail);
2549  }
2550  else
2551  {
2552  unchanged_tail = red.p;
2553  unchanged_head = red.p;
2554  }
2555  }
2556  else
2557  {
2558  assume (red.len == pLength (red.p));
2559  if(red.onlyBorrowed)
2560  {
2561  if(npIsOne (red.coef))
2562  {
2563  t = p_Copy (red.p, currRing);
2564  }
2565  else
2566  t = pp_Mult_nn (red.p, red.coef, currRing);
2567  }
2568  else
2569  {
2570  if(npIsOne (red.coef))
2571  t = red.p;
2572  else
2573  t = p_Mult_nn (red.p, red.coef, currRing);
2574  }
2575  kBucket_Add_q (bucket, t, &red.len);
2576  }
2577  }
2578  poly res = NULL;
2579  len = 0;
2580  kBucket_Add_q (bucket, unchanged_head, &unchanged_size);
2581  kBucketClear (bucket, &res, &len);
2582  kBucketDestroy (&bucket);
2583  return res;
2584 }
2585 #endif
2586 #ifdef NORO_SPARSE_ROWS_PRE
2587 //len input and out: Idea: reverse addition
2588 
2589 /*template <class number_type> SparseRow<number_type>* noro_red_to_non_poly(poly p, int &len, NoroCache<number_type>* cache,slimgb_alg* c)
2590  * {
2591  if (n_GetChar(currRing->cf)<255)
2592  {
2593  return noro_red_to_non_poly_t<tgb_uint8>(p,len,cache,c);
2594  }
2595  else
2596  {
2597  if (n_GetChar(currRing->cf)<65000)
2598  {
2599  return noro_red_to_non_poly_t<tgb_uint16>(p,len,cache,c);
2600  }
2601  else
2602  {
2603  return noro_red_to_non_poly_t<tgb_uint32>(p,len,cache,c);
2604  }
2605  }
2606 }*/
2607 #endif
2608 //len input and out: Idea: reverse addition
2609 #ifndef NORO_NON_POLY
2610 std::vector < NoroPlaceHolder > noro_red (poly p, int &len, NoroCache * cache,
2611  slimgb_alg * c)
2612 {
2613  std::vector < NoroPlaceHolder > res;
2614  while(p)
2615  {
2616  poly t = p;
2617  pIter (p);
2618  pNext (t) = NULL;
2619 
2620  MonRedRes red = noro_red_mon (t, TRUE, cache, c);
2621  assume (red.onlyBorrowed);
2622  assume (red.coef);
2623  assume (red.ref);
2624  NoroPlaceHolder h;
2625  h.ref = red.ref;
2626  h.coef = red.coef;
2627  assume (!((h.ref->value_poly == NULL) && (h.ref->value_len != 0)));
2628  if(h.ref->value_poly)
2629  res.push_back (h);
2630  }
2631  return res;
2632 }
2633 #endif
2634 
2635 #endif
2636 #ifdef USE_NORO
2637 #ifndef NORO_CACHE
2638 void noro_step (poly * p, int &pn, slimgb_alg * c)
2639 {
2640  poly *reduced = (poly *) omalloc (pn * sizeof (poly));
2641  int j;
2642  int *reduced_len = (int *) omalloc (pn * sizeof (int));
2643  int reduced_c = 0;
2644  //if (TEST_OPT_PROT)
2645  // PrintS("reduced system:\n");
2646 #ifdef NORO_CACHE
2647  NoroCache cache;
2648 #endif
2649  for(j = 0; j < pn; j++)
2650  {
2651 
2652  poly h = p[j];
2653  int h_len = pLength (h);
2654 
2655  number coef;
2656 #ifndef NORO_CACHE
2657  h = redNF2 (p_Copy (h, c->r), c, h_len, coef, 0);
2658 #else
2659  h = noro_red (p_Copy (h, c->r), h_len, &cache, c);
2660  assume (pLength (h) == h_len);
2661 #endif
2662  if(h != NULL)
2663  {
2664 #ifndef NORO_CACHE
2665 
2666  h = redNFTail (h, c->strat->sl, c->strat, h_len);
2667  h_len = pLength (h);
2668 #endif
2669  reduced[reduced_c] = h;
2670  reduced_len[reduced_c] = h_len;
2671  reduced_c++;
2672  if(TEST_OPT_PROT)
2673  Print ("%d ", h_len);
2674  }
2675  }
2676  int reduced_sum = 0;
2677  for(j = 0; j < reduced_c; j++)
2678  {
2679  reduced_sum += reduced_len[j];
2680  }
2681  poly *terms = (poly *) omalloc (reduced_sum * sizeof (poly));
2682  int tc = 0;
2683  for(j = 0; j < reduced_c; j++)
2684  {
2685  poly h = reduced[j];
2686 
2687  while(h != NULL)
2688  {
2689  terms[tc++] = h;
2690  pIter (h);
2691  assume (tc <= reduced_sum);
2692  }
2693  }
2694  assume (tc == reduced_sum);
2695  qsort (terms, reduced_sum, sizeof (poly), terms_sort_crit);
2696  int nterms = reduced_sum;
2697  //if (TEST_OPT_PROT)
2698  //Print("orig estimation:%i\n",reduced_sum);
2699  unify_terms (terms, nterms);
2700  //if (TEST_OPT_PROT)
2701  // Print("actual number of columns:%i\n",nterms);
2702  int rank = reduced_c;
2703  linalg_step_modp (reduced, p, rank, terms, nterms, c);
2704  omfree (terms);
2705 
2706  pn = rank;
2707  omfree (reduced);
2708 
2709  if(TEST_OPT_PROT)
2710  PrintS ("\n");
2711 }
2712 #else
2713 
2714 #endif
2715 #endif
2716 static void go_on (slimgb_alg * c)
2717 {
2718  //set limit of 1000 for multireductions, at the moment for
2719  //programming reasons
2720 #ifdef USE_NORO
2721  //Print("module rank%d\n",c->S->rank);
2722  const BOOLEAN use_noro = c->use_noro;
2723 #else
2724  const BOOLEAN use_noro = FALSE;
2725 #endif
2726  int i = 0;
2727  c->average_length = 0;
2728  for(i = 0; i < c->n; i++)
2729  {
2730  c->average_length += c->lengths[i];
2731  }
2732  c->average_length = c->average_length / c->n;
2733  i = 0;
2734  int max_pairs = bundle_size;
2735 
2736 #ifdef USE_NORO
2737  if((use_noro) || (c->use_noro_last_block))
2738  max_pairs = bundle_size_noro;
2739 #endif
2740  poly *p = (poly *) omalloc ((max_pairs + 1) * sizeof (poly)); //nullterminated
2741 
2742  int curr_deg = -1;
2743  while(i < max_pairs)
2744  {
2745  sorted_pair_node *s = top_pair (c); //here is actually chain criterium done
2746 
2747  if(!s)
2748  break;
2749 
2750  if(curr_deg >= 0)
2751  {
2752  if(s->deg > curr_deg)
2753  break;
2754  }
2755 
2756  else
2757  curr_deg = s->deg;
2758  quick_pop_pair (c);
2759  if(s->i >= 0)
2760  {
2761  //be careful replace_pair use createShortSpoly which is not noncommutative
2762  now_t_rep (s->i, s->j, c);
2763  replace_pair (s->i, s->j, c);
2764 
2765  if(s->i == s->j)
2766  {
2767  free_sorted_pair_node (s, c->r);
2768  continue;
2769  }
2770  now_t_rep (s->i, s->j, c);
2771  }
2772  poly h;
2773  if(s->i >= 0)
2774  {
2775 #ifdef HAVE_PLURAL
2776  if(c->nc)
2777  {
2778  h = nc_CreateSpoly (c->S->m[s->i], c->S->m[s->j] /*, NULL */ , c->r);
2779 
2780  if(h != NULL)
2781  p_Cleardenom (h, c->r);
2782  }
2783  else
2784 #endif
2785  h = ksOldCreateSpoly (c->S->m[s->i], c->S->m[s->j], NULL, c->r);
2786  p_Test (h, c->r);
2787  }
2788  else
2789  {
2790  h = s->lcm_of_lm;
2791  p_Test (h, c->r);
2792  }
2793  // if(s->i>=0)
2794 // now_t_rep(s->j,s->i,c);
2795  number coef;
2796  int mlen = pLength (h);
2797  p_Test (h, c->r);
2798  if((!c->nc) & (!(use_noro)))
2799  {
2800  h = redNF2 (h, c, mlen, coef, 2);
2801  redTailShort (h, c->strat);
2802  nDelete (&coef);
2803  }
2804  p_Test (h, c->r);
2805  free_sorted_pair_node (s, c->r);
2806  if(!h)
2807  continue;
2808  p[i] = h;
2809  i++;
2810  }
2811  p[i] = NULL;
2812 // pre_comp(p,i,c);
2813  if(i == 0)
2814  {
2815  omfree (p);
2816  return;
2817  }
2818 #ifdef TGB_RESORT_PAIRS
2819  c->replaced = new bool[c->n];
2820  c->used_b = FALSE;
2821 #endif
2822 
2823  c->normal_forms += i;
2824  int j;
2825 #ifdef USE_NORO
2826  //if ((!(c->nc))&&(rField_is_Zp(c->r)))
2827  //{
2828  if(use_noro)
2829  {
2830  int pn = i;
2831  if(pn == 0)
2832  {
2833  omfree (p);
2834  return;
2835  }
2836  {
2837  if(n_GetChar(currRing->cf) < 255)
2838  {
2839  noro_step < tgb_uint8 > (p, pn, c);
2840  }
2841  else
2842  {
2843  if(n_GetChar(currRing->cf) < 65000)
2844  {
2845  noro_step < tgb_uint16 > (p, pn, c);
2846  }
2847  else
2848  {
2849  noro_step < tgb_uint32 > (p, pn, c);
2850  }
2851  }
2852  }
2853 
2854  //if (TEST_OPT_PROT)
2855  //{
2856  // Print("reported rank:%i\n",pn);
2857  //}
2858  mass_add (p, pn, c);
2859  omfree (p);
2860  return;
2861  /*if (TEST_OPT_PROT)
2862  for(j=0;j<pn;j++)
2863  {
2864  p_wrp(p[j],c->r);
2865  } */
2866  }
2867 #endif
2868  red_object *buf = (red_object *) omalloc (i * sizeof (red_object));
2869  for(j = 0; j < i; j++)
2870  {
2871  p_Test (p[j], c->r);
2872  buf[j].p = p[j];
2873  buf[j].sev = pGetShortExpVector (p[j]);
2874  buf[j].bucket = kBucketCreate (currRing);
2875  p_Test (p[j], c->r);
2876  int len = pLength (p[j]);
2877  kBucketInit (buf[j].bucket, buf[j].p, len);
2878  buf[j].initial_quality = buf[j].guess_quality (c);
2879  assume (buf[j].initial_quality >= 0);
2880  }
2881  omfree (p);
2882  qsort (buf, i, sizeof (red_object), red_object_better_gen);
2883 // Print("\ncurr_deg:%i\n",curr_deg);
2884  if(TEST_OPT_PROT)
2885  {
2886  Print ("%dM[%d,", curr_deg, i);
2887  }
2888 
2889  multi_reduction (buf, i, c);
2890 #ifdef TGB_RESORT_PAIRS
2891  if(c->used_b)
2892  {
2893  if(TEST_OPT_PROT)
2894  PrintS ("B");
2895  int e;
2896  for(e = 0; e <= c->pair_top; e++)
2897  {
2898  if(c->apairs[e]->i < 0)
2899  continue;
2900  assume (c->apairs[e]->j >= 0);
2901  if((c->replaced[c->apairs[e]->i]) || (c->replaced[c->apairs[e]->j]))
2902  {
2903  sorted_pair_node *s = c->apairs[e];
2904  s->expected_length = pair_weighted_length (s->i, s->j, c);
2905  }
2906  }
2907  qsort (c->apairs, c->pair_top + 1, sizeof (sorted_pair_node *),
2909  }
2910 #endif
2911 #ifdef TGB_DEBUG
2912  {
2913  int k;
2914  for(k = 0; k < i; k++)
2915  {
2916  assume (kFindDivisibleByInS_easy (c->strat, buf[k]) < 0);
2917  int k2;
2918  for(k2 = 0; k2 < i; k2++)
2919  {
2920  if(k == k2)
2921  continue;
2922  assume ((!(p_LmDivisibleBy (buf[k].p, buf[k2].p, c->r)))
2923  || (wrp (buf[k].p), Print (" k %d k2 %d ", k, k2),
2924  wrp (buf[k2].p), FALSE));
2925  }
2926  }
2927  }
2928 #endif
2929  //resort S
2930 
2931  if(TEST_OPT_PROT)
2932  Print ("%i]", i);
2933 
2934  poly *add_those = (poly *) omalloc (i * sizeof (poly));
2935  for(j = 0; j < i; j++)
2936  {
2937  int len;
2938  poly p;
2939  buf[j].flatten ();
2940  kBucketClear (buf[j].bucket, &p, &len);
2941  kBucketDestroy (&buf[j].bucket);
2942  p_Test (p, c->r);
2943  //if (!c->nc) {
2944  if((c->tailReductions) || (lies_in_last_dp_block (p, c)))
2945  {
2946  p = redNFTail (p, c->strat->sl, c->strat, 0);
2947  }
2948  else
2949  {
2950  p = redTailShort (p, c->strat);
2951  }
2952  //}
2953  p_Test (p, c->r);
2954  add_those[j] = p;
2955 
2956  //sbuf[j]=add_to_basis(p,-1,-1,c,ibuf+j);
2957  }
2958  mass_add (add_those, i, c);
2959  omfree (add_those);
2960  omfree (buf);
2961 
2962  if(TEST_OPT_PROT)
2963  Print ("(%d)", c->pair_top + 1);
2964  //TODO: implement that while(!(idIs0(c->add_later)))
2965 #ifdef TGB_RESORT_PAIRS
2966  delete c->replaced;
2967  c->replaced = NULL;
2968  c->used_b = FALSE;
2969 #endif
2970  return;
2971 }
2972 
2973 #ifdef REDTAIL_S
2974 
2975 static poly redNFTail (poly h, const int sl, kStrategy strat, int len)
2976 {
2978  if(h == NULL)
2979  return NULL;
2980  pTest (h);
2981  if(0 > sl)
2982  return h;
2983  if(pNext (h) == NULL)
2984  return h;
2985 
2986  int j;
2987  poly res = h;
2988  poly act = res;
2989  LObject P (pNext (h));
2990  pNext (res) = NULL;
2991  P.bucket = kBucketCreate (currRing);
2992  len--;
2993  h = P.p;
2994  if(len <= 0)
2995  len = pLength (h);
2996  kBucketInit (P.bucket, h /*P.p */ , len /*pLength(P.p) */ );
2997  pTest (h);
2998  loop
2999  {
3000  P.p = h;
3001  P.t_p = NULL;
3002  P.SetShortExpVector ();
3003  loop
3004  {
3005  //int dummy=strat->sl;
3006  j = kFindDivisibleByInS_easy (strat, P.p, P.sev); //kFindDivisibleByInS(strat,&dummy,&P);
3007  if(j >= 0)
3008  {
3009 #ifdef REDTAIL_PROT
3010  PrintS ("r");
3011 #endif
3012  nNormalize (pGetCoeff (P.p));
3013 #ifdef KDEBUG
3014  if(TEST_OPT_DEBUG)
3015  {
3016  PrintS ("red tail:");
3017  wrp (h);
3018  PrintS (" with ");
3019  wrp (strat->S[j]);
3020  }
3021 #endif
3022  number coef;
3023  pTest (strat->S[j]);
3024 #ifdef HAVE_PLURAL
3025  if(nc)
3026  {
3027  nc_BucketPolyRed_Z (P.bucket, strat->S[j], &coef);
3028  }
3029  else
3030 #endif
3031  coef = kBucketPolyRed (P.bucket, strat->S[j],
3032  strat->lenS[j] /*pLength(strat->S[j]) */ ,
3033  strat->kNoether);
3034  pMult_nn (res, coef);
3035  nDelete (&coef);
3036  h = kBucketGetLm (P.bucket);
3037  pTest (h);
3038  if(h == NULL)
3039  {
3040 #ifdef REDTAIL_PROT
3041  PrintS (" ");
3042 #endif
3043  kBucketDestroy (&P.bucket);
3044  return res;
3045  }
3046  pTest (h);
3047  P.p = h;
3048  P.t_p = NULL;
3049  P.SetShortExpVector ();
3050 #ifdef KDEBUG
3051  if(TEST_OPT_DEBUG)
3052  {
3053  PrintS ("\nto tail:");
3054  wrp (h);
3055  PrintLn ();
3056  }
3057 #endif
3058  }
3059  else
3060  {
3061 #ifdef REDTAIL_PROT
3062  PrintS ("n");
3063 #endif
3064  break;
3065  }
3066  } /* end loop current mon */
3067  // poly tmp=pHead(h /*kBucketGetLm(P.bucket)*/);
3068  //act->next=tmp;pIter(act);
3069  act->next = kBucketExtractLm (P.bucket);
3070  pIter (act);
3071  h = kBucketGetLm (P.bucket);
3072  if(h == NULL)
3073  {
3074 #ifdef REDTAIL_PROT
3075  PrintS (" ");
3076 #endif
3077  kBucketDestroy (&P.bucket);
3078  return res;
3079  }
3080  pTest (h);
3081  }
3082 }
3083 #endif
3084 
3085 
3086 //try to fill, return FALSE iff queue is empty
3087 
3088 //transfers ownership of m to mat
3090 {
3091  assume (mat->mp[row] == NULL);
3092  mat->mp[row] = m;
3093 #ifdef TGB_DEBUG
3094  mac_poly r = m;
3095  while(r)
3096  {
3097  assume (r->exp < mat->columns);
3098  r = r->next;
3099  }
3100 #endif
3101 }
3102 
3103 poly
3104 free_row_to_poly (tgb_sparse_matrix * mat, int row, poly * monoms,
3105  int monom_index)
3106 {
3107  poly p = NULL;
3108  poly *set_this = &p;
3109  mac_poly r = mat->mp[row];
3110  mat->mp[row] = NULL;
3111  while(r)
3112  {
3113  (*set_this) = pLmInit (monoms[monom_index - 1 - r->exp]);
3114  pSetCoeff ((*set_this), r->coef);
3115  set_this = &((*set_this)->next);
3116  mac_poly old = r;
3117  r = r->next;
3118  delete old;
3119 
3120  }
3121  return p;
3122 }
3123 
3124 static int poly_crit (const void *ap1, const void *ap2)
3125 {
3126  poly p1, p2;
3127  p1 = *((poly *) ap1);
3128  p2 = *((poly *) ap2);
3129 
3130  int c = pLmCmp (p1, p2);
3131  if(c != 0)
3132  return c;
3133  int l1 = pLength (p1);
3134  int l2 = pLength (p2);
3135  if(l1 < l2)
3136  return -1;
3137  if(l1 > l2)
3138  return 1;
3139  return 0;
3140 }
3141 
3143 {
3144  if(s == 0)
3145  return;
3146  sorted_pair_node **si_array =
3147  (sorted_pair_node **) omalloc (s * sizeof (sorted_pair_node *));
3148 
3149  for(int i = 0; i < s; i++)
3150  {
3151  sorted_pair_node *si =
3152  (sorted_pair_node *) omalloc (sizeof (sorted_pair_node));
3153  si->i = -1;
3154  si->j = -2;
3155  poly p = pa[i];
3156  simplify_poly (p, r);
3157  si->expected_length = pQuality (p, this, pLength (p));
3158  p_Test (p, r);
3159  si->deg = this->pTotaldegree_full (p);
3160  /*if (!rField_is_Zp(r))
3161  {
3162  p_Content(p,r);
3163  p_Cleardenom(p,r);
3164  } */
3165 
3166  si->lcm_of_lm = p;
3167 
3168  // c->apairs[n-1-i]=si;
3169  si_array[i] = si;
3170  }
3171 
3172  qsort (si_array, s, sizeof (sorted_pair_node *), tgb_pair_better_gen2);
3173  apairs = spn_merge (apairs, pair_top + 1, si_array, s, this);
3174  pair_top += s;
3175  omfree (si_array);
3176 }
3177 
3178 slimgb_alg::slimgb_alg (ideal I, int syz_comp, BOOLEAN F4, int deg_pos)
3179 {
3180  this->deg_pos = deg_pos;
3181  lastCleanedDeg = -1;
3182  completed = FALSE;
3183  this->syz_comp = syz_comp;
3184  r = currRing;
3185  nc = rIsPluralRing (r);
3187  //Print("last dp Block start: %i\n", this->lastDpBlockStart);
3188  is_homog = TRUE;
3189  {
3190  int hzz;
3191  for(hzz = 0; hzz < IDELEMS (I); hzz++)
3192  {
3193  assume (I->m[hzz] != NULL);
3194  int d = this->pTotaldegree (I->m[hzz]);
3195  poly t = I->m[hzz]->next;
3196  while(t)
3197  {
3198  if(d != this->pTotaldegree (t))
3199  {
3200  is_homog = FALSE;
3201  break;
3202  }
3203  t = t->next;
3204  }
3205  if(!(is_homog))
3206  break;
3207  }
3208  }
3209  eliminationProblem = ((!(is_homog)) && ((currRing->pLexOrder) || (I->rank > 1)));
3210  tailReductions = ((is_homog) || ((TEST_OPT_REDTAIL) && (!(I->rank > 1))));
3211  // Print("is homog:%d",c->is_homog);
3212  void *h;
3213  int i;
3214  to_destroy = NULL;
3215  easy_product_crit = 0;
3217  if(rField_is_Zp (r))
3219  else
3221  //not fully correct
3222  //(rChar()==0);
3223  F4_mode = F4;
3224 
3225  reduction_steps = 0;
3226  last_index = -1;
3227 
3228  F = NULL;
3229  F_minus = NULL;
3230 
3231  Rcounter = 0;
3232 
3233  soon_free = NULL;
3234 
3235  tmp_lm = pOne ();
3236 
3237  normal_forms = 0;
3238  current_degree = 1;
3239 
3240  max_pairs = 5 * IDELEMS (I);
3241 
3242  apairs =
3243  (sorted_pair_node **) omalloc (sizeof (sorted_pair_node *) * max_pairs);
3244  pair_top = -1;
3245 
3246  int n = IDELEMS (I);
3247  array_lengths = n;
3248 
3249 
3250  i = 0;
3251  this->n = 0;
3252  T_deg = (int *) omalloc (n * sizeof (int));
3253  if(eliminationProblem)
3254  T_deg_full = (int *) omalloc (n * sizeof (int));
3255  else
3256  T_deg_full = NULL;
3257  tmp_pair_lm = (poly *) omalloc (n * sizeof (poly));
3258  tmp_spn = (sorted_pair_node **) omalloc (n * sizeof (sorted_pair_node *));
3259  lm_bin = omGetSpecBin (POLYSIZE + (r->ExpL_Size) * sizeof (long));
3260 #ifdef HEAD_BIN
3261  HeadBin = omGetSpecBin (POLYSIZE + (currRing->ExpL_Size) * sizeof (long));
3262 #endif
3263  /* omUnGetSpecBin(&(c->HeadBin)); */
3264 #ifndef HAVE_BOOST
3265 #ifdef USE_STDVECBOOL
3266 #else
3267  h = omalloc (n * sizeof (char *));
3268 
3269  states = (char **) h;
3270 #endif
3271 #endif
3272  h = omalloc (n * sizeof (int));
3273  lengths = (int *) h;
3274  weighted_lengths = (wlen_type *) omAllocAligned (n * sizeof (wlen_type));
3275  gcd_of_terms = (poly *) omAlloc (n * sizeof (poly));
3276 
3277  short_Exps = (long *) omalloc (n * sizeof (long));
3278  if(F4_mode)
3279  S = idInit (n, I->rank);
3280  else
3281  S = idInit (1, I->rank);
3282  strat = new skStrategy;
3283  if(eliminationProblem)
3284  strat->honey = TRUE;
3285  strat->syzComp = 0;
3289  strat->tailRing = r;
3290  strat->enterS = enterSBba;
3291  strat->sl = -1;
3292  i = n;
3293  i = 1; //some strange bug else
3294  /* initS(c->S,NULL,c->strat); */
3295  /* intS start: */
3296  // i=((i+IDELEMS(c->S)+15)/16)*16;
3297  strat->ecartS = (intset) omAlloc (i * sizeof (int)); /*initec(i); */
3298  strat->sevS = (unsigned long *) omAlloc0 (i * sizeof (unsigned long));
3299  /*initsevS(i); */
3300  strat->S_2_R = (int *) omAlloc0 (i * sizeof (int)); /*initS_2_R(i); */
3301  strat->fromQ = NULL;
3302  strat->Shdl = idInit (1, 1);
3303  strat->S = strat->Shdl->m;
3304  strat->lenS = (int *) omAlloc0 (i * sizeof (int));
3306  strat->lenSw = (wlen_type *) omAlloc0 (i * sizeof (wlen_type));
3307  else
3308  strat->lenSw = NULL;
3309  assume (n > 0);
3310  add_to_basis_ideal_quotient (I->m[0], this, NULL);
3311 
3312  assume (strat->sl == IDELEMS (strat->Shdl) - 1);
3313  if(!(F4_mode))
3314  {
3315  poly *array_arg = I->m;
3316  array_arg++;
3317  introduceDelayedPairs (array_arg, n - 1);
3318  /*
3319  for (i=1;i<n;i++)//the 1 is wanted, because first element is added to basis
3320  {
3321  // add_to_basis(I->m[i],-1,-1,c);
3322  si=(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
3323  si->i=-1;
3324  si->j=-2;
3325  si->expected_length=pQuality(I->m[i],this,pLength(I->m[i]));
3326  si->deg=pTotaldegree(I->m[i]);
3327  if (!rField_is_Zp(r))
3328  {
3329  p_Cleardenom(I->m[i], r);
3330  }
3331  si->lcm_of_lm=I->m[i];
3332 
3333  // c->apairs[n-1-i]=si;
3334  apairs[n-i-1]=si;
3335  ++(pair_top);
3336  } */
3337  }
3338  else
3339  {
3340  for(i = 1; i < n; i++) //the 1 is wanted, because first element is added to basis
3341  add_to_basis_ideal_quotient (I->m[i], this, NULL);
3342  }
3343  for(i = 0; i < IDELEMS (I); i++)
3344  {
3345  I->m[i] = NULL;
3346  }
3347  idDelete (&I);
3348  add_later = idInit (ADD_LATER_SIZE, S->rank);
3349 #ifdef USE_NORO
3350  use_noro = ((!(nc)) && (S->rank <= 1) && (rField_is_Zp (r))
3351  && (!(eliminationProblem)) && (n_GetChar(currRing->cf) <= 32003));
3352  use_noro_last_block = false;
3353  if((!(use_noro)) && (lastDpBlockStart <= (currRing->N)))
3354  {
3355  use_noro_last_block = ((!(nc)) && (S->rank <= 1) && (rField_is_Zp (r))
3356  && (n_GetChar(currRing->cf) <= 32003));
3357  }
3358 #else
3359  use_noro = false;
3360  use_noro_last_block = false;
3361 #endif
3362  //Print("NORO last block %i",use_noro_last_block);
3363  memset (add_later->m, 0, ADD_LATER_SIZE * sizeof (poly));
3364 }
3365 
3367 {
3368 
3369  if(!(completed))
3370  {
3371  poly *add = (poly *) omalloc ((pair_top + 2) * sizeof (poly));
3372  int piter;
3373  int pos = 0;
3374  for(piter = 0; piter <= pair_top; piter++)
3375  {
3376  sorted_pair_node *s = apairs[piter];
3377  if(s->i < 0)
3378  {
3379  //delayed element
3380  if(s->lcm_of_lm != NULL)
3381  {
3382  add[pos] = s->lcm_of_lm;
3383  pos++;
3384  }
3385  }
3386  free_sorted_pair_node (s, r);
3387  apairs[piter] = NULL;
3388  }
3389  pair_top = -1;
3390  add[pos] = NULL;
3391  pos = 0;
3392  while(add[pos] != NULL)
3393  {
3394  add_to_basis_ideal_quotient (add[pos], this, NULL);
3395  pos++;
3396  }
3397  for(piter = 0; piter <= pair_top; piter++)
3398  {
3399  sorted_pair_node *s = apairs[piter];
3400  assume (s->i >= 0);
3401  free_sorted_pair_node (s, r);
3402  apairs[piter] = NULL;
3403  }
3404  pair_top = -1;
3405  }
3406  id_Delete (&add_later, r);
3407  int i, j;
3408  slimgb_alg *c = this;
3409  while(c->to_destroy)
3410  {
3411  pDelete (&(c->to_destroy->p));
3412  poly_list_node *old = c->to_destroy;
3413  c->to_destroy = c->to_destroy->next;
3414  omfree (old);
3415  }
3416  while(c->F)
3417  {
3418  for(i = 0; i < c->F->size; i++)
3419  {
3420  pDelete (&(c->F->mp[i].m));
3421  }
3422  omfree (c->F->mp);
3423  c->F->mp = NULL;
3424  mp_array_list *old = c->F;
3425  c->F = c->F->next;
3426  omfree (old);
3427  }
3428  while(c->F_minus)
3429  {
3430  for(i = 0; i < c->F_minus->size; i++)
3431  {
3432  pDelete (&(c->F_minus->p[i]));
3433  }
3434  omfree (c->F_minus->p);
3435  c->F_minus->p = NULL;
3436  poly_array_list *old = c->F_minus;
3437  c->F_minus = c->F_minus->next;
3438  omfree (old);
3439  }
3440 #ifndef HAVE_BOOST
3441 #ifndef USE_STDVECBOOL
3442  for(int z = 1 /* zero length at 0 */ ; z < c->n; z++)
3443  {
3444  omfree (c->states[z]);
3445  }
3446  omfree (c->states);
3447 #endif
3448 #endif
3449 
3450  omfree (c->lengths);
3451  omfree (c->weighted_lengths);
3452  for(int z = 0; z < c->n; z++)
3453  {
3454  pDelete (&c->tmp_pair_lm[z]);
3455  omfree (c->tmp_spn[z]);
3456  }
3457  omfree (c->tmp_pair_lm);
3458  omfree (c->tmp_spn);
3459 
3460  omfree (c->T_deg);
3461  if(c->T_deg_full)
3462  omfree (c->T_deg_full);
3463 
3464  omFree (c->strat->ecartS);
3465  omFree (c->strat->sevS);
3466 // initsevS(i);
3467  omFree (c->strat->S_2_R);
3468 
3469 
3470  omFree (c->strat->lenS);
3471 
3472  if(c->strat->lenSw)
3473  omFree (c->strat->lenSw);
3474 
3475  for(i = 0; i < c->n; i++)
3476  {
3477  if(c->gcd_of_terms[i])
3478  pDelete (&(c->gcd_of_terms[i]));
3479  }
3480  omfree (c->gcd_of_terms);
3481 
3482  omfree (c->apairs);
3483  if(TEST_OPT_PROT)
3484  {
3485  //Print("calculated %d NFs\n",c->normal_forms);
3486  Print ("\nNF:%i product criterion:%i, ext_product criterion:%i \n",
3488  }
3489 
3490  for(i = 0; i <= c->strat->sl; i++)
3491  {
3492  if(!c->strat->S[i])
3493  continue;
3494  BOOLEAN found = FALSE;
3495  for(j = 0; j < c->n; j++)
3496  {
3497  if(c->S->m[j] == c->strat->S[i])
3498  {
3499  found = TRUE;
3500  break;
3501  }
3502  }
3503  if(!found)
3504  pDelete (&c->strat->S[i]);
3505  }
3506 // for(i=0;i<c->n;i++)
3507 // {
3508 // if (c->rep[i]!=i)
3509 // {
3510 // // for(j=0;j<=c->strat->sl;j++)
3511 // {
3512 // // if(c->strat->S[j]==c->S->m[i])
3513 // {
3514 // // c->strat->S[j]=NULL;
3515 // // break;
3516 // // }
3517 // // }
3518 // // PrintS("R_delete");
3519 // pDelete(&c->S->m[i]);
3520 // }
3521 // }
3522 
3523  if(completed)
3524  {
3525  for(i = 0; i < c->n; i++)
3526  {
3527  assume (c->S->m[i] != NULL);
3528  if(p_GetComp (c->S->m[i], currRing) > this->syz_comp)
3529  continue;
3530  for(j = 0; j < c->n; j++)
3531  {
3532  if((c->S->m[j] == NULL) || (i == j))
3533  continue;
3534  assume (p_LmShortDivisibleBy (c->S->m[j], c->short_Exps[j],
3535  c->S->m[i], ~c->short_Exps[i],
3536  c->r) == p_LmDivisibleBy (c->S->m[j],
3537  c->S->m[i],
3538  c->r));
3539  if(p_LmShortDivisibleBy (c->S->m[j], c->short_Exps[j],
3540  c->S->m[i], ~c->short_Exps[i], c->r))
3541  {
3542  pDelete (&c->S->m[i]);
3543  break;
3544  }
3545  }
3546  }
3547  }
3548  omfree (c->short_Exps);
3549 
3550  ideal I = c->S;
3551  IDELEMS (I) = c->n;
3552  idSkipZeroes (I);
3553  for(i = 0; i <= c->strat->sl; i++)
3554  c->strat->S[i] = NULL;
3555  id_Delete (&c->strat->Shdl, c->r);
3556  pDelete (&c->tmp_lm);
3558  delete c->strat;
3559 }
3560 
3561 ideal t_rep_gb (ring r, ideal arg_I, int syz_comp, BOOLEAN F4_mode)
3562 {
3563  assume (r == currRing);
3564  ring orig_ring = r;
3565  int pos;
3566  ring new_ring = rAssure_TDeg (orig_ring, 1, rVar (orig_ring), pos);
3567  ideal s_h;
3568  if(orig_ring != new_ring)
3569  {
3570  rChangeCurrRing (new_ring);
3571  s_h = idrCopyR_NoSort (arg_I, orig_ring, new_ring);
3572  idTest (s_h);
3573  /*int i;
3574  for(i=0;i<IDELEMS(s_h);i++)
3575  {
3576  poly p=s_h->m[i];
3577  while(p)
3578  {
3579  p_Setm(p,new_ring);
3580  pIter(p);
3581  }
3582  } */
3583  }
3584  else
3585  {
3586  s_h = id_Copy (arg_I, orig_ring);
3587  }
3588 
3589  ideal s_result = do_t_rep_gb (new_ring, s_h, syz_comp, F4_mode, pos);
3590  ideal result;
3591  if(orig_ring != new_ring)
3592  {
3593  idTest (s_result);
3594  rChangeCurrRing (orig_ring);
3595  result = idrMoveR_NoSort (s_result, new_ring, orig_ring);
3596 
3597  idTest (result);
3598  //rChangeCurrRing(new_ring);
3599  rDelete(new_ring);
3600  //rChangeCurrRing(orig_ring);
3601  }
3602  else
3603  result = s_result;
3604  idTest (result);
3605  return result;
3606 }
3607 
3608 ideal
3609 do_t_rep_gb (ring /*r*/, ideal arg_I, int syz_comp, BOOLEAN F4_mode, int deg_pos)
3610 {
3611  // Print("QlogSize(0) %d, QlogSize(1) %d,QlogSize(-2) %d, QlogSize(5) %d\n", QlogSize(nlInit(0)),QlogSize(nlInit(1)),QlogSize(nlInit(-2)),QlogSize(nlInit(5)));
3612 
3613  if(TEST_OPT_PROT)
3614  if(F4_mode)
3615  PrintS ("F4 Modus \n");
3616 
3617  //debug_Ideal=arg_debug_Ideal;
3618  //if (debug_Ideal) PrintS("DebugIdeal received\n");
3619  // Print("Idelems %i \n----------\n",IDELEMS(arg_I));
3620  ideal I = arg_I;
3621  id_Compactify (I,currRing);
3622  if(idIs0 (I))
3623  return I;
3624  int i;
3625  for(i = 0; i < IDELEMS (I); i++)
3626  {
3627  assume (I->m[i] != NULL);
3628  simplify_poly (I->m[i], currRing);
3629  }
3630 
3631  qsort (I->m, IDELEMS (I), sizeof (poly), poly_crit);
3632  //Print("Idelems %i \n----------\n",IDELEMS(I));
3633  //slimgb_alg* c=(slimgb_alg*) omalloc(sizeof(slimgb_alg));
3634  //int syz_comp=arg_I->rank;
3635  slimgb_alg *c = new slimgb_alg (I, syz_comp, F4_mode, deg_pos);
3636 
3637  while((c->pair_top >= 0)
3638  && ((!(TEST_OPT_DEGBOUND))
3639  || (c->apairs[c->pair_top]->deg <= Kstd1_deg)))
3640  {
3641 #ifdef HAVE_F4
3642  if(F4_mode)
3643  go_on_F4 (c);
3644  else
3645 #endif
3646  go_on (c);
3647  }
3648  if(c->pair_top < 0)
3649  c->completed = TRUE;
3650  I = c->S;
3651  delete c;
3652  if(TEST_OPT_REDSB)
3653  {
3654  ideal erg = kInterRed (I, NULL);
3655  assume (I != erg);
3656  id_Delete (&I, currRing);
3657  return erg;
3658  }
3659  //qsort(I->m, IDELEMS(I),sizeof(poly),pLmCmp_func);
3660  assume (I->rank >= id_RankFreeModule (I,currRing));
3661  return (I);
3662 }
3663 
3664 void now_t_rep (const int &arg_i, const int &arg_j, slimgb_alg * c)
3665 {
3666  int i, j;
3667  if(arg_i == arg_j)
3668  {
3669  return;
3670  }
3671  if(arg_i > arg_j)
3672  {
3673  i = arg_j;
3674  j = arg_i;
3675  }
3676  else
3677  {
3678  i = arg_i;
3679  j = arg_j;
3680  }
3681  c->states[j][i] = HASTREP;
3682 }
3683 
3684 static BOOLEAN
3685 has_t_rep (const int &arg_i, const int &arg_j, slimgb_alg * state)
3686 {
3687  assume (0 <= arg_i);
3688  assume (0 <= arg_j);
3689  assume (arg_i < state->n);
3690  assume (arg_j < state->n);
3691  if(arg_i == arg_j)
3692  {
3693  return (TRUE);
3694  }
3695  if(arg_i > arg_j)
3696  {
3697  return (state->states[arg_i][arg_j] == HASTREP);
3698  }
3699  else
3700  {
3701  return (state->states[arg_j][arg_i] == HASTREP);
3702  }
3703 }
3704 
3705 #if 0 // unused
3706 static int pLcmDeg (poly a, poly b)
3707 {
3708  int i;
3709  int n = 0;
3710  for(i = (currRing->N); i; i--)
3711  {
3712  n += si_max (pGetExp (a, i), pGetExp (b, i));
3713  }
3714  return n;
3715 }
3716 #endif
3717 
3718 static void shorten_tails (slimgb_alg * c, poly monom)
3719 {
3720  return;
3721 // BOOLEAN corr=lenS_correct(c->strat);
3722  for(int i = 0; i < c->n; i++)
3723  {
3724  //enter tail
3725 
3726  if(c->S->m[i] == NULL)
3727  continue;
3728  poly tail = c->S->m[i]->next;
3729  poly prev = c->S->m[i];
3730  BOOLEAN did_something = FALSE;
3731  while((tail != NULL) && (pLmCmp (tail, monom) >= 0))
3732  {
3733  if(p_LmDivisibleBy (monom, tail, c->r))
3734  {
3735  did_something = TRUE;
3736  prev->next = tail->next;
3737  tail->next = NULL;
3738  p_Delete (&tail, c->r);
3739  tail = prev;
3740  //PrintS("Shortened");
3741  c->lengths[i]--;
3742  }
3743  prev = tail;
3744  tail = tail->next;
3745  }
3746  if(did_something)
3747  {
3748  int new_pos;
3749  wlen_type q;
3750  q = pQuality (c->S->m[i], c, c->lengths[i]);
3751  new_pos = simple_posInS (c->strat, c->S->m[i], c->lengths[i], q);
3752 
3753  int old_pos = -1;
3754  //assume new_pos<old_pos
3755  for(int z = 0; z <= c->strat->sl; z++)
3756  {
3757  if(c->strat->S[z] == c->S->m[i])
3758  {
3759  old_pos = z;
3760  break;
3761  }
3762  }
3763  if(old_pos == -1)
3764  for(int z = new_pos - 1; z >= 0; z--)
3765  {
3766  if(c->strat->S[z] == c->S->m[i])
3767  {
3768  old_pos = z;
3769  break;
3770  }
3771  }
3772  assume (old_pos >= 0);
3773  assume (new_pos <= old_pos);
3774  assume (pLength (c->strat->S[old_pos]) == c->lengths[i]);
3775  c->strat->lenS[old_pos] = c->lengths[i];
3776  if(c->strat->lenSw)
3777  c->strat->lenSw[old_pos] = q;
3778  if(new_pos < old_pos)
3779  move_forward_in_S (old_pos, new_pos, c->strat);
3780  length_one_crit (c, i, c->lengths[i]);
3781  }
3782  }
3783 }
3784 
3785 #if 0 // currently unused
3786 static sorted_pair_node *pop_pair (slimgb_alg * c)
3787 {
3789 
3790  if(c->pair_top < 0)
3791  return NULL;
3792  else
3793  return (c->apairs[c->pair_top--]);
3794 }
3795 #endif
3796 
3797 void slimgb_alg::cleanDegs (int lower, int upper)
3798 {
3799  assume (is_homog);
3800  int deg;
3801  if(TEST_OPT_PROT)
3802  {
3803  PrintS ("C");
3804  }
3805  for(deg = lower; deg <= upper; deg++)
3806  {
3807  int i;
3808  for(i = 0; i < n; i++)
3809  {
3810  if(T_deg[i] == deg)
3811  {
3812  poly h;
3813  h = S->m[i];
3814  h = redNFTail (h, strat->sl, strat, lengths[i]);
3815  if(!rField_is_Zp (r))
3816  {
3817  p_Cleardenom (h, r);
3818  //p_Content(h,r);
3819  }
3820  else
3821  pNorm (h);
3822  //TODO:GCD of TERMS
3823  poly got =::gcd_of_terms (h, r);
3824  p_Delete (&gcd_of_terms[i], r);
3825  gcd_of_terms[i] = got;
3826  int len = pLength (h);
3827  wlen_type wlen = pQuality (h, this, len);
3828  if(weighted_lengths)
3829  weighted_lengths[i] = wlen;
3830  lengths[i] = len;
3831  assume (h == S->m[i]);
3832  int j;
3833  for(j = 0; j <= strat->sl; j++)
3834  {
3835  if(h == strat->S[j])
3836  {
3837  int new_pos = simple_posInS (strat, h, len, wlen);
3838  if(strat->lenS)
3839  {
3840  strat->lenS[j] = len;
3841  }
3842  if(strat->lenSw)
3843  {
3844  strat->lenSw[j] = wlen;
3845  }
3846  if(new_pos < j)
3847  {
3848  move_forward_in_S (j, new_pos, strat);
3849  }
3850  else
3851  {
3852  if(new_pos > j)
3853  new_pos = new_pos - 1; //is identical with one element
3854  if(new_pos > j)
3855  move_backward_in_S (j, new_pos, strat);
3856  }
3857  break;
3858  }
3859  }
3860  }
3861  }
3862  }
3863  {
3864  int i, j;
3865  for(i = 0; i < this->n; i++)
3866  {
3867  for(j = 0; j < i; j++)
3868  {
3869  if(T_deg[i] + T_deg[j] <= upper)
3870  {
3871  now_t_rep (i, j, this);
3872  }
3873  }
3874  }
3875  }
3876  //TODO resort and update strat->S,strat->lenSw
3877  //TODO mark pairs
3878 }
3879 
3881 {
3882  while(c->pair_top >= 0)
3883  {
3884  super_clean_top_of_pair_list (c); //yeah, I know, it's odd that I use a different proc here
3885  if((c->is_homog) && (c->pair_top >= 0)
3886  && (c->apairs[c->pair_top]->deg >= c->lastCleanedDeg + 2))
3887  {
3888  int upper = c->apairs[c->pair_top]->deg - 1;
3889  c->cleanDegs (c->lastCleanedDeg + 1, upper);
3890  c->lastCleanedDeg = upper;
3891  }
3892  else
3893  {
3894  break;
3895  }
3896  }
3897 
3898  if(c->pair_top < 0)
3899  return NULL;
3900  else
3901  return (c->apairs[c->pair_top]);
3902 }
3903 
3905 {
3906  if(c->pair_top < 0)
3907  return NULL;
3908  else
3909  return (c->apairs[c->pair_top--]);
3910 }
3911 
3913 {
3914  while((c->pair_top >= 0)
3915  && (c->apairs[c->pair_top]->i >= 0)
3916  &&
3918  (c->apairs[c->pair_top]->j, c->apairs[c->pair_top]->i, c)))
3919  {
3920  free_sorted_pair_node (c->apairs[c->pair_top], c->r);
3921  c->pair_top--;
3922  }
3923 }
3924 
3926 {
3927  while((c->pair_top >= 0) && (c->apairs[c->pair_top]->i >= 0)
3928  &&
3929  (!state_is
3930  (UNCALCULATED, c->apairs[c->pair_top]->j, c->apairs[c->pair_top]->i,
3931  c)))
3932  {
3933  free_sorted_pair_node (c->apairs[c->pair_top], c->r);
3934  c->pair_top--;
3935  }
3936 }
3937 
3938 static BOOLEAN
3939 state_is (calc_state state, const int &arg_i, const int &arg_j,
3940  slimgb_alg * c)
3941 {
3942  assume (0 <= arg_i);
3943  assume (0 <= arg_j);
3944  assume (arg_i < c->n);
3945  assume (arg_j < c->n);
3946  if(arg_i == arg_j)
3947  {
3948  return (TRUE);
3949  }
3950  if(arg_i > arg_j)
3951  {
3952  return (c->states[arg_i][arg_j] == state);
3953  }
3954  else
3955  return (c->states[arg_j][arg_i] == state);
3956 }
3957 
3959 {
3960  if(s->i >= 0)
3961  p_Delete (&s->lcm_of_lm, r);
3962  omfree (s);
3963 }
3964 
3965 static BOOLEAN
3967 {
3968  if(a->deg < b->deg)
3969  return TRUE;
3970  if(a->deg > b->deg)
3971  return FALSE;
3972 
3973  int comp = pLmCmp (a->lcm_of_lm, b->lcm_of_lm);
3974  if(comp == 1)
3975  return FALSE;
3976  if(-1 == comp)
3977  return TRUE;
3978  if(a->expected_length < b->expected_length)
3979  return TRUE;
3980  if(a->expected_length > b->expected_length)
3981  return FALSE;
3982  if(a->i + a->j < b->i + b->j)
3983  return TRUE;
3984  if(a->i + a->j > b->i + b->j)
3985  return FALSE;
3986  if(a->i < b->i)
3987  return TRUE;
3988  if(a->i > b->i)
3989  return FALSE;
3990  return TRUE;
3991 }
3992 
3993 static int tgb_pair_better_gen (const void *ap, const void *bp)
3994 {
3995  sorted_pair_node *a = *((sorted_pair_node **) ap);
3996  sorted_pair_node *b = *((sorted_pair_node **) bp);
3997  assume ((a->i > a->j) || (a->i < 0));
3998  assume ((b->i > b->j) || (b->i < 0));
3999  if(a->deg < b->deg)
4000  return -1;
4001  if(a->deg > b->deg)
4002  return 1;
4003 
4004  int comp = pLmCmp (a->lcm_of_lm, b->lcm_of_lm);
4005 
4006  if(comp == 1)
4007  return 1;
4008  if(-1 == comp)
4009  return -1;
4010  if(a->expected_length < b->expected_length)
4011  return -1;
4012  if(a->expected_length > b->expected_length)
4013  return 1;
4014  if(a->i + a->j < b->i + b->j)
4015  return -1;
4016  if(a->i + a->j > b->i + b->j)
4017  return 1;
4018  if(a->i < b->i)
4019  return -1;
4020  if(a->i > b->i)
4021  return 1;
4022  return 0;
4023 }
4024 
4025 static poly gcd_of_terms (poly p, ring r)
4026 {
4027  int max_g_0 = 0;
4028  assume (p != NULL);
4029  int i;
4030  poly m = pOne ();
4031  poly t;
4032  for(i = (currRing->N); i; i--)
4033  {
4034  pSetExp (m, i, pGetExp (p, i));
4035  if(max_g_0 == 0)
4036  if(pGetExp (m, i) > 0)
4037  max_g_0 = i;
4038  }
4039 
4040  t = p->next;
4041  while(t != NULL)
4042  {
4043  if(max_g_0 == 0)
4044  break;
4045  for(i = max_g_0; i; i--)
4046  {
4047  pSetExp (m, i, si_min (pGetExp (t, i), pGetExp (m, i)));
4048  if(max_g_0 == i)
4049  if(pGetExp (m, i) == 0)
4050  max_g_0 = 0;
4051  if((max_g_0 == 0) && (pGetExp (m, i) > 0))
4052  {
4053  max_g_0 = i;
4054  }
4055  }
4056  t = t->next;
4057  }
4058  p_Setm (m, r);
4059  if(max_g_0 > 0)
4060  return m;
4061  pDelete (&m);
4062  return NULL;
4063 }
4064 
4066 {
4067 
4068  if(pGetComp (p1) > 0 || pGetComp (p2) > 0)
4069  return FALSE;
4070  int i = 1;
4071  loop
4072  {
4073  if((pGetExp (p1, i) - pGetExp (m, i) > 0)
4074  && (pGetExp (p2, i) - pGetExp (m, i) > 0))
4075  return FALSE;
4076  if(i == (currRing->N))
4077  return TRUE;
4078  i++;
4079  }
4080 }
4081 
4082 //for impl reasons may return false if the the normal product criterion matches
4083 static inline BOOLEAN
4085  slimgb_alg * c)
4086 {
4087  if(c->nc)
4088  return FALSE;
4089  if(gcd1 == NULL)
4090  return FALSE;
4091  if(gcd2 == NULL)
4092  return FALSE;
4093  gcd1->next = gcd2; //may ordered incorrect
4094  poly m = gcd_of_terms (gcd1, c->r);
4095  gcd1->next = NULL;
4096  if(m == NULL)
4097  return FALSE;
4098 
4099  BOOLEAN erg = pHasNotCFExtended (p1, p2, m);
4100  pDelete (&m);
4101  return erg;
4102 }
4103 
4104 #if 0 //currently unused
4105 static poly kBucketGcd (kBucket * b, ring r)
4106 {
4107  int s = 0;
4108  int i;
4109  poly m, n;
4110  BOOLEAN initialized = FALSE;
4111  for(i = MAX_BUCKET - 1; i >= 0; i--)
4112  {
4113  if(b->buckets[i] != NULL)
4114  {
4115  if(!initialized)
4116  {
4117  m = gcd_of_terms (b->buckets[i], r);
4118  initialized = TRUE;
4119  if(m == NULL)
4120  return NULL;
4121  }
4122  else
4123  {
4124  n = gcd_of_terms (b->buckets[i], r);
4125  if(n == NULL)
4126  {
4127  pDelete (&m);
4128  return NULL;
4129  }
4130  n->next = m;
4131  poly t = gcd_of_terms (n, r);
4132  n->next = NULL;
4133  pDelete (&m);
4134  pDelete (&n);
4135  m = t;
4136  if(m == NULL)
4137  return NULL;
4138 
4139  }
4140  }
4141  }
4142  return m;
4143 }
4144 #endif
4145 
4146 static inline wlen_type quality_of_pos_in_strat_S (int pos, slimgb_alg * c)
4147 {
4148  if(c->strat->lenSw != NULL)
4149  return c->strat->lenSw[pos];
4150  return c->strat->lenS[pos];
4151 }
4152 
4153 #ifdef HAVE_PLURAL
4154 static inline wlen_type
4156  //meant only for nc
4157 {
4158  poly m = pOne ();
4159  pExpVectorDiff (m, high, c->strat->S[pos]);
4160  poly product = nc_mm_Mult_pp (m, c->strat->S[pos], c->r);
4161  wlen_type erg = pQuality (product, c);
4162  pDelete (&m);
4163  pDelete (&product);
4164  return erg;
4165 }
4166 #endif
4167 
4168 static void
4170  find_erg & erg)
4171 {
4172  erg.expand = NULL;
4173  BOOLEAN swap_roles; //from reduce_by, to_reduce_u if fromS
4174  if(erg.fromS)
4175  {
4176  if(pLmEqual (c->strat->S[erg.reduce_by], los[erg.to_reduce_u].p))
4177  {
4178  wlen_type quality_a = quality_of_pos_in_strat_S (erg.reduce_by, c);
4179  int best = erg.to_reduce_u + 1;
4180 /*
4181  for (i=erg.to_reduce_u;i>=erg.to_reduce_l;i--)
4182  {
4183  int qc=los[i].guess_quality(c);
4184  if (qc<quality_a)
4185  {
4186  best=i;
4187  quality_a=qc;
4188  }
4189  }
4190  if(best!=erg.to_reduce_u+1)
4191  {*/
4192  wlen_type qc;
4193  best = find_best (los, erg.to_reduce_l, erg.to_reduce_u, qc, c);
4194  if(qc < quality_a)
4195  {
4196  los[best].flatten ();
4197  int b_pos = kBucketCanonicalize (los[best].bucket);
4198  los[best].p = los[best].bucket->buckets[b_pos];
4199  qc = pQuality (los[best].bucket->buckets[b_pos], c);
4200  if(qc < quality_a)
4201  {
4202  red_object h = los[erg.to_reduce_u];
4203  los[erg.to_reduce_u] = los[best];
4204  los[best] = h;
4205  swap_roles = TRUE;
4206  }
4207  else
4208  swap_roles = FALSE;
4209  }
4210  else
4211  {
4212  swap_roles = FALSE;
4213  }
4214  }
4215  else
4216  {
4217  if(erg.to_reduce_u > erg.to_reduce_l)
4218  {
4219  wlen_type quality_a = quality_of_pos_in_strat_S (erg.reduce_by, c);
4220 #ifdef HAVE_PLURAL
4221  if((c->nc) && (!(rIsSCA (c->r))))
4222  quality_a =
4224  los[erg.to_reduce_u].p, c);
4225 #endif
4226  int best = erg.to_reduce_u + 1;
4227  wlen_type qc;
4228  best = find_best (los, erg.to_reduce_l, erg.to_reduce_u, qc, c);
4229  assume (qc == los[best].guess_quality (c));
4230  if(qc < quality_a)
4231  {
4232  los[best].flatten ();
4233  int b_pos = kBucketCanonicalize (los[best].bucket);
4234  los[best].p = los[best].bucket->buckets[b_pos];
4235  qc = pQuality (los[best].bucket->buckets[b_pos], c);
4236  //(best!=erg.to_reduce_u+1)
4237  if(qc < quality_a)
4238  {
4239  red_object h = los[erg.to_reduce_u];
4240  los[erg.to_reduce_u] = los[best];
4241  los[best] = h;
4242  erg.reduce_by = erg.to_reduce_u;
4243  erg.fromS = FALSE;
4244  erg.to_reduce_u--;
4245  }
4246  }
4247  }
4248  else
4249  {
4250  assume (erg.to_reduce_u == erg.to_reduce_l);
4251  wlen_type quality_a = quality_of_pos_in_strat_S (erg.reduce_by, c);
4252  wlen_type qc = los[erg.to_reduce_u].guess_quality (c);
4253  if(qc < 0)
4254  PrintS ("Wrong wlen_type");
4255  if(qc < quality_a)
4256  {
4257  int best = erg.to_reduce_u;
4258  los[best].flatten ();
4259  int b_pos = kBucketCanonicalize (los[best].bucket);
4260  los[best].p = los[best].bucket->buckets[b_pos];
4261  qc = pQuality (los[best].bucket->buckets[b_pos], c);
4262  assume (qc >= 0);
4263  if(qc < quality_a)
4264  {
4265  BOOLEAN exp = FALSE;
4266  if(qc <= 2)
4267  {
4268  //Print("\n qc is %lld \n",qc);
4269  exp = TRUE;
4270  }
4271  else
4272  {
4273  if(qc < quality_a / 2)
4274  exp = TRUE;
4275  else if(erg.reduce_by < c->n / 4)
4276  exp = TRUE;
4277  }
4278  if(exp)
4279  {
4280  poly clear_into;
4281  los[erg.to_reduce_u].flatten ();
4282  kBucketClear (los[erg.to_reduce_u].bucket, &clear_into,
4283  &erg.expand_length);
4284  erg.expand = pCopy (clear_into);
4285  kBucketInit (los[erg.to_reduce_u].bucket, clear_into,
4286  erg.expand_length);
4287  if(TEST_OPT_PROT)
4288  PrintS ("e");
4289  }
4290  }
4291  }
4292  }
4293 
4294  swap_roles = FALSE;
4295  return;
4296  }
4297  }
4298  else
4299  {
4300  if(erg.reduce_by > erg.to_reduce_u)
4301  {
4302  //then lm(rb)>= lm(tru) so =
4303  assume (erg.reduce_by == erg.to_reduce_u + 1);
4304  int best = erg.reduce_by;
4305  wlen_type quality_a = los[erg.reduce_by].guess_quality (c);
4306  wlen_type qc;
4307  best = find_best (los, erg.to_reduce_l, erg.to_reduce_u, qc, c);
4308 
4309  if(qc < quality_a)
4310  {
4311  red_object h = los[erg.reduce_by];
4312  los[erg.reduce_by] = los[best];
4313  los[best] = h;
4314  }
4315  swap_roles = FALSE;
4316  return;
4317  }
4318  else
4319  {
4320  assume (!pLmEqual (los[erg.reduce_by].p, los[erg.to_reduce_l].p));
4321  assume (erg.to_reduce_u == erg.to_reduce_l);
4322  //further assume, that reduce_by is the above all other polys
4323  //with same leading term
4324  int il = erg.reduce_by;
4325  wlen_type quality_a = los[erg.reduce_by].guess_quality (c);
4326  wlen_type qc;
4327  while((il > 0) && pLmEqual (los[il - 1].p, los[il].p))
4328  {
4329  il--;
4330  qc = los[il].guess_quality (c);
4331  if(qc < quality_a)
4332  {
4333  quality_a = qc;
4334  erg.reduce_by = il;
4335  }
4336  }
4337  swap_roles = FALSE;
4338  }
4339  }
4340  if(swap_roles)
4341  {
4342  if(TEST_OPT_PROT)
4343  PrintS ("b");
4344  poly clear_into;
4345  int new_length;
4346  int bp = erg.to_reduce_u; //bucket_positon
4347  //kBucketClear(los[bp].bucket,&clear_into,&new_length);
4348  new_length = los[bp].clear_to_poly ();
4349  clear_into = los[bp].p;
4350  poly p = c->strat->S[erg.reduce_by];
4351  int j = erg.reduce_by;
4352  int old_length = c->strat->lenS[j]; // in view of S
4353  los[bp].p = p;
4354  kBucketInit (los[bp].bucket, p, old_length);
4355  wlen_type qal = pQuality (clear_into, c, new_length);
4356  int pos_in_c = -1;
4357  int z;
4358  int new_pos;
4359  new_pos = simple_posInS (c->strat, clear_into, new_length, qal);
4360  assume (new_pos <= j);
4361  for(z = c->n; z; z--)
4362  {
4363  if(p == c->S->m[z - 1])
4364  {
4365  pos_in_c = z - 1;
4366  break;
4367  }
4368  }
4369 
4370  int tdeg_full = -1;
4371  int tdeg = -1;
4372  if(pos_in_c >= 0)
4373  {
4374 #ifdef TGB_RESORT_PAIRS
4375  c->used_b = TRUE;
4376  c->replaced[pos_in_c] = TRUE;
4377 #endif
4378  tdeg = c->T_deg[pos_in_c];
4379  c->S->m[pos_in_c] = clear_into;
4380  c->lengths[pos_in_c] = new_length;
4381  c->weighted_lengths[pos_in_c] = qal;
4382  if(c->gcd_of_terms[pos_in_c] == NULL)
4383  c->gcd_of_terms[pos_in_c] = gcd_of_terms (clear_into, c->r);
4384  if(c->T_deg_full)
4385  tdeg_full = c->T_deg_full[pos_in_c] =
4386  c->pTotaldegree_full (clear_into);
4387  else
4388  tdeg_full = tdeg;
4389  c_S_element_changed_hook (pos_in_c, c);
4390  }
4391  else
4392  {
4393  if(c->eliminationProblem)
4394  {
4395  tdeg_full = c->pTotaldegree_full (clear_into);
4396  tdeg = c->pTotaldegree (clear_into);
4397  }
4398  }
4399  c->strat->S[j] = clear_into;
4400  c->strat->lenS[j] = new_length;
4401 
4402  assume (pLength (clear_into) == new_length);
4403  if(c->strat->lenSw != NULL)
4404  c->strat->lenSw[j] = qal;
4405  if(!rField_is_Zp (c->r))
4406  {
4407  p_Cleardenom (clear_into, c->r); //should be unnecessary
4408  //p_Content(clear_into, c->r);
4409  }
4410  else
4411  pNorm (clear_into);
4412 #ifdef FIND_DETERMINISTIC
4413  erg.reduce_by = j;
4414  //resort later see diploma thesis, find_in_S must be deterministic
4415  //during multireduction if spolys are only in the span of the
4416  //input polys
4417 #else
4418  if(new_pos < j)
4419  {
4420  if(c->strat->honey)
4421  c->strat->ecartS[j] = tdeg_full - tdeg;
4422  move_forward_in_S (j, new_pos, c->strat);
4423  erg.reduce_by = new_pos;
4424  }
4425 #endif
4426  }
4427 }
4428 
4429 static int fwbw (red_object * los, int i)
4430 {
4431  int i2 = i;
4432  int step = 1;
4433 
4434  BOOLEAN bw = FALSE;
4435  BOOLEAN incr = TRUE;
4436 
4437  while(1)
4438  {
4439  if(!bw)
4440  {
4441  step = si_min (i2, step);
4442  if(step == 0)
4443  break;
4444  i2 -= step;
4445 
4446  if(!pLmEqual (los[i].p, los[i2].p))
4447  {
4448  bw = TRUE;
4449  incr = FALSE;
4450  }
4451  else
4452  {
4453  if((!incr) && (step == 1))
4454  break;
4455  }
4456  }
4457  else
4458  {
4459  step = si_min (i - i2, step);
4460  if(step == 0)
4461  break;
4462  i2 += step;
4463  if(pLmEqual (los[i].p, los[i2].p))
4464  {
4465  if(step == 1)
4466  break;
4467  else
4468  {
4469  bw = FALSE;
4470  }
4471  }
4472  }
4473  if(incr)
4474  step *= 2;
4475  else
4476  {
4477  if(step % 2 == 1)
4478  step = (step + 1) / 2;
4479  else
4480  step /= 2;
4481  }
4482  }
4483  return i2;
4484 }
4485 
4486 static void
4487 canonicalize_region (red_object * los, int l, int u, slimgb_alg * /*c*/)
4488 {
4489  assume (l <= u + 1);
4490  int i;
4491  for(i = l; i <= u; i++)
4492  {
4493  kBucketCanonicalize (los[i].bucket);
4494  }
4495 }
4496 
4497 #ifdef SING_NDEBUG
4498 static void
4499 multi_reduction_find (red_object * los, int /*losl*/, slimgb_alg * c, int startf,
4500  find_erg & erg)
4501 #else
4502 static void
4503 multi_reduction_find (red_object * los, int losl, slimgb_alg * c, int startf,
4504  find_erg & erg)
4505 #endif
4506 {
4507  kStrategy strat = c->strat;
4508 
4509  assume (startf <= losl);
4510  assume ((startf == losl - 1)
4511  || (pLmCmp (los[startf].p, los[startf + 1].p) == -1));
4512  int i = startf;
4513 
4514  int j;
4515  while(i >= 0)
4516  {
4517  assume ((i == losl - 1) || (pLmCmp (los[i].p, los[i + 1].p) <= 0));
4518  assume (is_valid_ro (los[i]));
4519  j = kFindDivisibleByInS_easy (strat, los[i]);
4520  if(j >= 0)
4521  {
4522  erg.to_reduce_u = i;
4523  erg.reduce_by = j;
4524  erg.fromS = TRUE;
4525  int i2 = fwbw (los, i);
4526  assume (pLmEqual (los[i].p, los[i2].p));
4527  assume ((i2 == 0) || (!pLmEqual (los[i2].p, los[i2 - 1].p)));
4528  assume (i >= i2);
4529 
4530  erg.to_reduce_l = i2;
4531  assume ((i == losl - 1) || (pLmCmp (los[i].p, los[i + 1].p) == -1));
4532  canonicalize_region (los, erg.to_reduce_u + 1, startf, c);
4533  return;
4534  }
4535  if(j < 0)
4536  {
4537  //not reduceable, try to use this for reducing higher terms
4538  int i2 = fwbw (los, i);
4539  assume (pLmEqual (los[i].p, los[i2].p));
4540  assume ((i2 == 0) || (!pLmEqual (los[i2].p, los[i2 - 1].p)));
4541  assume (i >= i2);
4542  if(i2 != i)
4543  {
4544  erg.to_reduce_u = i - 1;
4545  erg.to_reduce_l = i2;
4546  erg.reduce_by = i;
4547  erg.fromS = FALSE;
4548  assume ((i == losl - 1) || (pLmCmp (los[i].p, los[i + 1].p) == -1));
4549  canonicalize_region (los, erg.to_reduce_u + 1, startf, c);
4550  return;
4551  }
4552  i--;
4553  }
4554  }
4555  erg.reduce_by = -1; //error code
4556  return;
4557 }
4558 
4559  // nicht reduzierbare eintraege in ergebnisliste schreiben
4560 // nullen loeschen
4561 // while(finde_groessten leitterm reduzierbar(c,erg))
4562 // {
4563 
4564 static int
4565 multi_reduction_clear_zeroes (red_object * los, int losl, int l, int u)
4566 {
4567  int deleted = 0;
4568  int i = l;
4569  int last = -1;
4570  while(i <= u)
4571  {
4572  if(los[i].p == NULL)
4573  {
4574  kBucketDestroy (&los[i].bucket);
4575 // delete los[i];//here we assume los are constructed with new
4576  //destroy resources, must be added here
4577  if(last >= 0)
4578  {
4579  memmove (los + (int) (last + 1 - deleted), los + (last + 1),
4580  sizeof (red_object) * (i - 1 - last));
4581  }
4582  last = i;
4583  deleted++;
4584  }
4585  i++;
4586  }
4587  if((last >= 0) && (last != losl - 1))
4588  memmove (los + (int) (last + 1 - deleted), los + last + 1,
4589  sizeof (red_object) * (losl - 1 - last));
4590  return deleted;
4591 }
4592 
4594 {
4595  int an = 0;
4596  int en = top;
4597  if(top == -1)
4598  return 0;
4599  if(pLmCmp (key->p, a[top].p) == 1)
4600  return top + 1;
4601  int i;
4602  loop
4603  {
4604  if(an >= en - 1)
4605  {
4606  if(pLmCmp (key->p, a[an].p) == -1)
4607  return an;
4608  return en;
4609  }
4610  i = (an + en) / 2;
4611  if(pLmCmp (key->p, a[i].p) == -1)
4612  en = i;
4613  else
4614  an = i;
4615  }
4616 }
4617 
4618 static void sort_region_down (red_object * los, int l, int u, slimgb_alg * /*c*/)
4619 {
4620  int r_size = u - l + 1;
4621  qsort (los + l, r_size, sizeof (red_object), red_object_better_gen);
4622  int i;
4623  int *new_indices = (int *) omalloc ((r_size) * sizeof (int));
4624  int bound = 0;
4625  BOOLEAN at_end = FALSE;
4626  for(i = l; i <= u; i++)
4627  {
4628  if(!(at_end))
4629  {
4630  bound = new_indices[i - l] =
4631  bound + search_red_object_pos (los + bound, l - bound - 1, los + i);
4632  if(bound == l)
4633  at_end = TRUE;
4634  }
4635  else
4636  {
4637  new_indices[i - l] = l;
4638  }
4639  }
4640  red_object *los_region =
4641  (red_object *) omalloc (sizeof (red_object) * (u - l + 1));
4642  for(int i = 0; i < r_size; i++)
4643  {
4644  new_indices[i] += i;
4645  los_region[i] = los[l + i];
4646  assume ((i == 0) || (new_indices[i] > new_indices[i - 1]));
4647  }
4648 
4649  i = r_size - 1;
4650  int j = u;
4651  int j2 = l - 1;
4652  while(i >= 0)
4653  {
4654  if(new_indices[i] == j)
4655  {
4656  los[j] = los_region[i];
4657  i--;
4658  j--;
4659  }
4660  else
4661  {
4662  assume (new_indices[i] < j);
4663  los[j] = los[j2];
4664  assume (j2 >= 0);
4665  j2--;
4666  j--;
4667  }
4668  }
4669  omfree (los_region);
4670  omfree (new_indices);
4671 }
4672 
4673 //assume that los is ordered ascending by leading term, all non zero
4674 static void multi_reduction (red_object * los, int &losl, slimgb_alg * c)
4675 {
4676  poly *delay = (poly *) omalloc (losl * sizeof (poly));
4677  int delay_s = 0;
4678  //initialize;
4679  assume (c->strat->sl >= 0);
4680  assume (losl > 0);
4681  int i;
4682  wlen_type max_initial_quality = 0;
4683 
4684  for(i = 0; i < losl; i++)
4685  {
4686  los[i].sev = pGetShortExpVector (los[i].p);
4687 //SetShortExpVector();
4688  los[i].p = kBucketGetLm (los[i].bucket);
4689  if(los[i].initial_quality > max_initial_quality)
4690  max_initial_quality = los[i].initial_quality;
4691  // else
4692 // Print("init2_qal=%lld;", los[i].initial_quality);
4693 // Print("initial_quality=%lld;",max_initial_quality);
4694  }
4695 
4696  int curr_pos = losl - 1;
4697 
4698 // nicht reduzierbare eintr�e in ergebnisliste schreiben
4699  // nullen loeschen
4700  while(curr_pos >= 0)
4701  {
4702  if((c->use_noro_last_block)
4703  && (lies_in_last_dp_block (los[curr_pos].p, c)))
4704  {
4705  int pn_noro = curr_pos + 1;
4706  poly *p_noro = (poly *) omalloc (pn_noro * sizeof (poly));
4707  for(i = 0; i < pn_noro; i++)
4708  {
4709  int dummy_len;
4710  poly p;
4711  los[i].p = NULL;
4712  kBucketClear (los[i].bucket, &p, &dummy_len);
4713  p_noro[i] = p;
4714  }
4715  if(n_GetChar(currRing->cf) < 255)
4716  {
4717  noro_step < tgb_uint8 > (p_noro, pn_noro, c);
4718  }
4719  else
4720  {
4721  if(n_GetChar(currRing->cf) < 65000)
4722  {
4723  noro_step < tgb_uint16 > (p_noro, pn_noro, c);
4724  }
4725  else
4726  {
4727  noro_step < tgb_uint32 > (p_noro, pn_noro, c);
4728  }
4729  }
4730  for(i = 0; i < pn_noro; i++)
4731  {
4732  los[i].p = p_noro[i];
4733  los[i].sev = pGetShortExpVector (los[i].p);
4734  //ignore quality
4735  kBucketInit (los[i].bucket, los[i].p, pLength (los[i].p));
4736  }
4737  qsort (los, pn_noro, sizeof (red_object), red_object_better_gen);
4738  int deleted =
4739  multi_reduction_clear_zeroes (los, losl, pn_noro, curr_pos);
4740  losl -= deleted;
4741  curr_pos -= deleted;
4742  break;
4743  }
4744  find_erg erg;
4745 
4746  multi_reduction_find (los, losl, c, curr_pos, erg); //last argument should be curr_pos
4747  if(erg.reduce_by < 0)
4748  break;
4749 
4750  erg.expand = NULL;
4751 
4752  multi_reduction_lls_trick (los, losl, c, erg);
4753 
4754  int i;
4755  // wrp(los[erg.to_reduce_u].p);
4756  //PrintLn();
4757  multi_reduce_step (erg, los, c);
4758 
4759 
4760  if(!TEST_OPT_REDTHROUGH)
4761  {
4762  for(i = erg.to_reduce_l; i <= erg.to_reduce_u; i++)
4763  {
4764  if(los[i].p != NULL) //the check (los[i].p!=NULL) might be invalid
4765  {
4766  //
4767  assume (los[i].initial_quality > 0);
4768  if(los[i].guess_quality (c)
4769  > 1.5 * delay_factor * max_initial_quality)
4770  {
4771  if(TEST_OPT_PROT)
4772  PrintS ("v");
4773  los[i].canonicalize ();
4774  if(los[i].guess_quality (c) > delay_factor * max_initial_quality)
4775  {
4776  if(TEST_OPT_PROT)
4777  PrintS (".");
4778  los[i].clear_to_poly ();
4779  //delay.push_back(los[i].p);
4780  delay[delay_s] = los[i].p;
4781  delay_s++;
4782  los[i].p = NULL;
4783  }
4784  }
4785  }
4786  }
4787  }
4788  int deleted = multi_reduction_clear_zeroes (los, losl, erg.to_reduce_l,
4789  erg.to_reduce_u);
4790  if(erg.fromS == FALSE)
4791  curr_pos = si_max (erg.to_reduce_u, erg.reduce_by);
4792  else
4793  curr_pos = erg.to_reduce_u;
4794  losl -= deleted;
4795  curr_pos -= deleted;
4796 
4797  //Print("deleted %i \n",deleted);
4798  if((TEST_V_UPTORADICAL) && (!(erg.fromS)))
4799  sort_region_down (los, si_min (erg.to_reduce_l, erg.reduce_by),
4800  (si_max (erg.to_reduce_u, erg.reduce_by)) - deleted,
4801  c);
4802  else
4803  sort_region_down (los, erg.to_reduce_l, erg.to_reduce_u - deleted, c);
4804 
4805  if(erg.expand)
4806  {
4807 #ifdef FIND_DETERMINISTIC
4808  int i;
4809  for(i = 0; c->expandS[i]; i++) ;
4810  c->expandS = (poly *) omrealloc (c->expandS, (i + 2) * sizeof (poly));
4811  c->expandS[i] = erg.expand;
4812  c->expandS[i + 1] = NULL;
4813 #else
4814  int ecart = 0;
4815  if(c->eliminationProblem)
4816  {
4817  ecart =
4818  c->pTotaldegree_full (erg.expand) - c->pTotaldegree (erg.expand);
4819  }
4820  add_to_reductors (c, erg.expand, erg.expand_length, ecart);
4821 #endif
4822  }
4823  }
4824 
4825  //sorted_pair_node** pairs=(sorted_pair_node**)
4826  // omalloc(delay_s*sizeof(sorted_pair_node*));
4827  c->introduceDelayedPairs (delay, delay_s);
4828  /*
4829  for(i=0;i<delay_s;i++)
4830  {
4831  poly p=delay[i];
4832  //if (rPar(c->r)==0)
4833  simplify_poly(p,c->r);
4834  sorted_pair_node* si=(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
4835  si->i=-1;
4836  si->j=-1;
4837  if (!rField_is_Zp(c->r))
4838  {
4839  if (!c->nc)
4840  p=redTailShort(p, c->strat);
4841  p_Cleardenom(p, c->r);
4842  p_Content(p, c->r);
4843  }
4844  si->expected_length=pQuality(p,c,pLength(p));
4845  si->deg=pTotaldegree(p);
4846  si->lcm_of_lm=p;
4847  pairs[i]=si;
4848  }
4849  qsort(pairs,delay_s,sizeof(sorted_pair_node*),tgb_pair_better_gen2);
4850  c->apairs=spn_merge(c->apairs,c->pair_top+1,pairs,delay_s,c);
4851  c->pair_top+=delay_s; */
4852  omfree (delay);
4853  //omfree(pairs);
4854  return;
4855 }
4856 
4858 {
4859  assume (p == kBucketGetLm (bucket));
4860 }
4861 
4863 {
4864  p = kBucketGetLm (bucket);
4865  if(p)
4866  sev = pGetShortExpVector (p);
4867 }
4868 
4870 {
4871  flatten ();
4872  int l;
4873  kBucketClear (bucket, &p, &l);
4874  return l;
4875 }
4876 
4877 void reduction_step::reduce (red_object * /*r*/, int /*l*/, int /*u*/)
4878 {
4879 }
4880 
4882 {
4883  number coef;
4884 #ifdef HAVE_PLURAL
4885  if(c->nc)
4886  nc_BucketPolyRed_Z (ro.bucket, p, &coef);
4887  else
4888 #endif
4889  coef = kBucketPolyRed (ro.bucket, p, p_len, c->strat->kNoether);
4890  nDelete (&coef);
4891 }
4892 
4893 void simple_reducer::reduce (red_object * r, int l, int u)
4894 {
4895  this->pre_reduce (r, l, u);
4896  int i;
4897 //debug start
4898 
4899  if(c->eliminationProblem)
4900  {
4901  assume (p_LmEqual (r[l].p, r[u].p, c->r));
4902  /*int lm_deg=pTotaldegree(r[l].p);
4903  reducer_deg=lm_deg+pTotaldegree_full(p)-pTotaldegree(p); */
4904  }
4905 
4906  for(i = l; i <= u; i++)
4907  {
4908  this->do_reduce (r[i]);
4909  }
4910  for(i = l; i <= u; i++)
4911  {
4912  kBucketSimpleContent (r[i].bucket);
4913  r[i].validate ();
4914 #ifdef TGB_DEBUG
4915 #endif
4916  }
4917 }
4918 
4920 {
4921 }
4922 
4924 {
4925  if(fill_back != NULL)
4926  {
4927  kBucketInit (fill_back, p, p_len);
4928  }
4929  fill_back = NULL;
4930 }
4931 
4933 {
4934  static int id = 0;
4935  id++;
4936  unsigned long sev;
4937  BOOLEAN lt_changed = FALSE;
4938  int rn = erg.reduce_by;
4939  poly red;
4940  int red_len;
4941  simple_reducer *pointer;
4942  BOOLEAN work_on_copy = FALSE;
4943  if(erg.fromS)
4944  {
4945  red = c->strat->S[rn];
4946  red_len = c->strat->lenS[rn];
4947  assume (red_len == pLength (red));
4948  }
4949  else
4950  {
4951  r[rn].flatten ();
4952  kBucketClear (r[rn].bucket, &red, &red_len);
4953 
4954  if(!rField_is_Zp (c->r))
4955  {
4956  p_Cleardenom (red, c->r); //should be unnecessary
4957  //p_Content(red, c->r);
4958  }
4959  pNormalize (red);
4960 
4961  if((!(erg.fromS)) && (TEST_V_UPTORADICAL))
4962  {
4963  if(polynomial_root (red, c->r))
4964  lt_changed = TRUE;
4965  sev = p_GetShortExpVector (red, c->r);
4966  }
4967  red_len = pLength (red);
4968  }
4969  if(((TEST_V_MODPSOLVSB) && (red_len > 1))
4970  || ((c->nc) || (erg.to_reduce_u - erg.to_reduce_l > 5)))
4971  {
4972  work_on_copy = TRUE;
4973  // poly m=pOne();
4974  poly m = c->tmp_lm;
4975  pSetCoeff (m, nInit (1));
4976  pSetComp (m, 0);
4977  for(int i = 1; i <= (currRing->N); i++)
4978  pSetExp (m, i, (pGetExp (r[erg.to_reduce_l].p, i) - pGetExp (red, i)));
4979  pSetm (m);
4980  poly red_cp;
4981 #ifdef HAVE_PLURAL
4982  if(c->nc)
4983  red_cp = nc_mm_Mult_pp (m, red, c->r);
4984  else
4985 #endif
4986  red_cp = ppMult_mm (red, m);
4987  if(!erg.fromS)
4988  {
4989  kBucketInit (r[rn].bucket, red, red_len);
4990  }
4991  //now reduce the copy
4992  //static poly redNF2 (poly h,slimgb_alg* c , int &len, number& m,int n)
4993 
4994  if(!c->nc)
4995  redTailShort (red_cp, c->strat);
4996  //number mul;
4997  // red_len--;
4998 // red_cp->next=redNF2(red_cp->next,c,red_len,mul,c->average_length);
4999 // pSetCoeff(red_cp,nMult(red_cp->coef,mul));
5000 // nDelete(&mul);
5001 // red_len++;
5002  red = red_cp;
5003  red_len = pLength (red);
5004  // pDelete(&m);
5005  }
5006 
5007  assume (red_len == pLength (red));
5008 
5009  int reducer_deg = 0;
5010  if(c->eliminationProblem)
5011  {
5012  int lm_deg = c->pTotaldegree (r[erg.to_reduce_l].p);
5013  int ecart;
5014  if(erg.fromS)
5015  {
5016  ecart = c->strat->ecartS[erg.reduce_by];
5017  }
5018  else
5019  {
5020  ecart = c->pTotaldegree_full (red) - lm_deg;
5021  }
5022  reducer_deg = lm_deg + ecart;
5023  }
5024  pointer = new simple_reducer (red, red_len, reducer_deg, c);
5025 
5026  if((!work_on_copy) && (!erg.fromS))
5027  pointer->fill_back = r[rn].bucket;
5028  else
5029  pointer->fill_back = NULL;
5030  pointer->reduction_id = id;
5031  pointer->c = c;
5032 
5033  pointer->reduce (r, erg.to_reduce_l, erg.to_reduce_u);
5034  if(work_on_copy)
5035  pDelete (&pointer->p);
5036  delete pointer;
5037  if(lt_changed)
5038  {
5039  assume (!erg.fromS);
5040  r[erg.reduce_by].sev = sev;
5041  }
5042 }
5043 
5044 void simple_reducer::pre_reduce (red_object * /*r*/, int /*l*/, int /*u*/)
5045 {
5046 }
5047 
5048 #if 0
5049 template int pos_helper<int, int*>(skStrategy*, spolyrec*, int, int*, spolyrec**);
5050 template int pos_helper<long, long*>(skStrategy*, spolyrec*, long, long*, spolyrec**);
5051 
5052 template void noro_step<unsigned char>(spolyrec**, int&, slimgb_alg*);
5053 template void noro_step<unsigned int>(spolyrec**, int&, slimgb_alg*);
5054 template void noro_step<unsigned short>(spolyrec**, int&, slimgb_alg*);
5055 
5056 
5057 template int term_nodes_sort_crit<unsigned char>(void const*, void const*);
5058 template int term_nodes_sort_crit<unsigned int>(void const*, void const*);
5059 template int term_nodes_sort_crit<unsigned short>(void const*, void const*);
5060 
5061 template spolyrec* row_to_poly<unsigned char>(unsigned char*, spolyrec**, int, ip_sring*);
5062 template spolyrec* row_to_poly<unsigned int>(unsigned int*, spolyrec**, int, ip_sring*);
5063 template spolyrec* row_to_poly<unsigned short>(unsigned short*, spolyrec**, int, ip_sring*);
5064 
5065 template void simplest_gauss_modp<unsigned char>(unsigned char*, int, int);
5066 template void simplest_gauss_modp<unsigned int>(unsigned int*, int, int);
5067 template void simplest_gauss_modp<unsigned short>(unsigned short*, int, int);
5068 
5069 
5070 template int modP_lastIndexRow<unsigned char>(unsigned char*, int);
5071 template int modP_lastIndexRow<unsigned int>(unsigned int*, int);
5072 template int modP_lastIndexRow<unsigned short>(unsigned short*, int);
5073 
5074 template SparseRow<unsigned char>* noro_red_to_non_poly_t<unsigned char>(spolyrec*, int&, NoroCache<unsigned char>*, slimgb_alg*);
5075 template SparseRow<unsigned int>* noro_red_to_non_poly_t<unsigned int>(spolyrec*, int&, NoroCache<unsigned int>*, slimgb_alg*);
5076 template SparseRow<unsigned short>* noro_red_to_non_poly_t<unsigned short>(spolyrec*, int&, NoroCache<unsigned short>*, slimgb_alg*);
5077 
5078 
5079 template MonRedResNP<unsigned char> noro_red_mon_to_non_poly<unsigned char>(spolyrec*, NoroCache<unsigned char>*, slimgb_alg*);
5080 template MonRedResNP<unsigned int> noro_red_mon_to_non_poly<unsigned int>(spolyrec*, NoroCache<unsigned int>*, slimgb_alg*);
5081 template MonRedResNP<unsigned short> noro_red_mon_to_non_poly<unsigned short>(spolyrec*, NoroCache<unsigned short>*, slimgb_alg*);
5082 
5083 template SparseRow<unsigned char>* noro_red_to_non_poly_dense<unsigned char>(MonRedResNP<unsigned char>*, int, NoroCache<unsigned char>*);
5084 template SparseRow<unsigned char>* noro_red_to_non_poly_sparse<unsigned char>(MonRedResNP<unsigned char>*, int, NoroCache<unsigned char>*);
5085 template SparseRow<unsigned int>* noro_red_to_non_poly_dense<unsigned int>(MonRedResNP<unsigned int>*, int, NoroCache<unsigned int>*);
5086 template SparseRow<unsigned int>* noro_red_to_non_poly_sparse<unsigned int>(MonRedResNP<unsigned int>*, int, NoroCache<unsigned int>*);
5087 template SparseRow<unsigned short>* noro_red_to_non_poly_dense<unsigned short>(MonRedResNP<unsigned short>*, int, NoroCache<unsigned short>*);
5088 template SparseRow<unsigned short>* noro_red_to_non_poly_sparse<unsigned short>(MonRedResNP<unsigned short>*, int, NoroCache<unsigned short>*);
5089 
5090 
5091 
5092 template class DataNoroCacheNode<unsigned char>;
5093 template class DataNoroCacheNode<unsigned int>;
5094 template class DataNoroCacheNode<unsigned short>;
5095 
5096 template class NoroCache<unsigned char>;
5097 template class NoroCache<unsigned int>;
5098 template class NoroCache<unsigned short>;
5099 
5100 
5101 
5102 template void add_coef_times_dense<unsigned char>(unsigned char*, int, unsigned char const*, int, snumber*);
5103 template void add_coef_times_dense<unsigned int>(unsigned int*, int, unsigned int const*, int, snumber*);
5104 template void add_coef_times_dense<unsigned short>(unsigned short*, int, unsigned short const*, int, snumber*);
5105 template void add_coef_times_sparse<unsigned char>(unsigned char*, int, SparseRow<unsigned char>*, snumber*);
5106 template void add_coef_times_sparse<unsigned int>(unsigned int*, int, SparseRow<unsigned int>*, snumber*);
5107 template void add_coef_times_sparse<unsigned short>(unsigned short*, int, SparseRow<unsigned short>*, snumber*);
5108 template void add_dense<unsigned char>(unsigned char*, int, unsigned char const*, int);
5109 template void add_dense<unsigned int>(unsigned int*, int, unsigned int const*, int);
5110 template void add_dense<unsigned short>(unsigned short*, int, unsigned short const*, int);
5111 template void add_sparse<unsigned char>(unsigned char*, int, SparseRow<unsigned char>*);
5112 template void add_sparse<unsigned int>(unsigned int*, int, SparseRow<unsigned int>*);
5113 template void add_sparse<unsigned short>(unsigned short*, int, SparseRow<unsigned short>*);
5114 
5115 
5116 template void sub_dense<unsigned char>(unsigned char*, int, unsigned char const*, int);
5117 template void sub_dense<unsigned int>(unsigned int*, int, unsigned int const*, int);
5118 template void sub_dense<unsigned short>(unsigned short*, int, unsigned short const*, int);
5119 template void sub_sparse<unsigned char>(unsigned char*, int, SparseRow<unsigned char>*);
5120 template void sub_sparse<unsigned int>(unsigned int*, int, SparseRow<unsigned int>*);
5121 template void sub_sparse<unsigned short>(unsigned short*, int, SparseRow<unsigned short>*);
5122 template void write_coef_idx_to_buffer_dense<unsigned char>(CoefIdx<unsigned char>*, int&, unsigned char*, int);
5123 template void write_coef_idx_to_buffer_dense<unsigned int>(CoefIdx<unsigned int>*, int&, unsigned int*, int);
5124 template void write_coef_idx_to_buffer_dense<unsigned short>(CoefIdx<unsigned short>*, int&, unsigned short*, int);
5125 template void write_coef_idx_to_buffer<unsigned char>(CoefIdx<unsigned char>*, int&, int*, unsigned char*, int);
5126 template void write_coef_idx_to_buffer<unsigned int>(CoefIdx<unsigned int>*, int&, int*, unsigned int*, int);
5127 template void write_coef_idx_to_buffer<unsigned short>(CoefIdx<unsigned short>*, int&, int*, unsigned short*, int);
5128 template void write_coef_times_xx_idx_to_buffer_dense<unsigned char>(CoefIdx<unsigned char>*, int&, unsigned char*, int, snumber*);
5129 template void write_coef_times_xx_idx_to_buffer_dense<unsigned int>(CoefIdx<unsigned int>*, int&, unsigned int*, int, snumber*);
5130 template void write_coef_times_xx_idx_to_buffer_dense<unsigned short>(CoefIdx<unsigned short>*, int&, unsigned short*, int, snumber*);
5131 template void write_coef_times_xx_idx_to_buffer<unsigned char>(CoefIdx<unsigned char>*, int&, int*, unsigned char*, int, snumber*);
5132 template void write_coef_times_xx_idx_to_buffer<unsigned int>(CoefIdx<unsigned int>*, int&, int*, unsigned int*, int, snumber*);
5133 template void write_coef_times_xx_idx_to_buffer<unsigned short>(CoefIdx<unsigned short>*, int&, int*, unsigned short*, int, snumber*);
5134 template void write_minus_coef_idx_to_buffer_dense<unsigned char>(CoefIdx<unsigned char>*, int&, unsigned char*, int);
5135 template void write_minus_coef_idx_to_buffer_dense<unsigned int>(CoefIdx<unsigned int>*, int&, unsigned int*, int);
5136 template void write_minus_coef_idx_to_buffer_dense<unsigned short>(CoefIdx<unsigned short>*, int&, unsigned short*, int);
5137 template void write_minus_coef_idx_to_buffer<unsigned char>(CoefIdx<unsigned char>*, int&, int*, unsigned char*, int);
5138 template void write_minus_coef_idx_to_buffer<unsigned int>(CoefIdx<unsigned int>*, int&, int*, unsigned int*, int);
5139 template void write_minus_coef_idx_to_buffer<unsigned short>(CoefIdx<unsigned short>*, int&, int*, unsigned short*, int);
5140 
5141 
5142 template class std::vector<DataNoroCacheNode<unsigned char>*>;
5143 template class std::vector<DataNoroCacheNode<unsigned int>*>;
5144 template class std::vector<DataNoroCacheNode<unsigned short>*>;
5145 template class std::vector<PolySimple>;
5146 
5147 template void std::sort( CoefIdx<unsigned char>* , CoefIdx<unsigned char>* );
5148 template void std::sort( CoefIdx<unsigned int>* , CoefIdx<unsigned int>* );
5149 template void std::sort( CoefIdx<unsigned short>*, CoefIdx<unsigned short>* );
5150 
5151 template void std::sort_heap<CoefIdx<unsigned char>*>(CoefIdx<unsigned char>*, CoefIdx<unsigned char>*);
5152 template void std::sort_heap<CoefIdx<unsigned int>*>(CoefIdx<unsigned int>*, CoefIdx<unsigned int>*);
5153 template void std::sort_heap<CoefIdx<unsigned short>*>(CoefIdx<unsigned short>*, CoefIdx<unsigned short>*);
5154 
5155 template void std::make_heap<CoefIdx<unsigned char>*>(CoefIdx<unsigned char>*, CoefIdx<unsigned char>*);
5156 template void std::make_heap<CoefIdx<unsigned int>*>(CoefIdx<unsigned int>*, CoefIdx<unsigned int>*);
5157 template void std::make_heap<CoefIdx<unsigned short>*>(CoefIdx<unsigned short>*, CoefIdx<unsigned short>*);
5158 #endif
5159 
5160 #if 0
5161 template void std::__final_insertion_sort<CoefIdx<unsigned char>*>(CoefIdx<unsigned char>*, CoefIdx<unsigned char>*);
5162 template void std::__final_insertion_sort<CoefIdx<unsigned int>*>(CoefIdx<unsigned int>*, CoefIdx<unsigned int>*);
5163 template void std::__final_insertion_sort<CoefIdx<unsigned short>*>(CoefIdx<unsigned short>*, CoefIdx<unsigned short>*);
5164 
5165 template void std::__introsort_loop<CoefIdx<unsigned char>*, long>(CoefIdx<unsigned char>*, CoefIdx<unsigned char>*, long);
5166 template void std::__introsort_loop<CoefIdx<unsigned int>*, long>(CoefIdx<unsigned int>*, CoefIdx<unsigned int>*, long);
5167 template void std::__introsort_loop<CoefIdx<unsigned short>*, long>(CoefIdx<unsigned short>*, CoefIdx<unsigned short>*, long);
5168 
5169 template void std::__heap_select<CoefIdx<unsigned char>*>(CoefIdx<unsigned char>*, CoefIdx<unsigned char>*, CoefIdx<unsigned char>*);
5170 template void std::__heap_select<CoefIdx<unsigned int>*>(CoefIdx<unsigned int>*, CoefIdx<unsigned int>*, CoefIdx<unsigned int>*);
5171 template void std::__heap_select<CoefIdx<unsigned short>*>(CoefIdx<unsigned short>*, CoefIdx<unsigned short>*, CoefIdx<unsigned short>*);
5172 
5173 template void std::__insertion_sort<CoefIdx<unsigned char>*>(CoefIdx<unsigned char>*, CoefIdx<unsigned char>*);
5174 template void std::__insertion_sort<CoefIdx<unsigned int>*>(CoefIdx<unsigned int>*, CoefIdx<unsigned int>*);
5175 template void std::__insertion_sort<CoefIdx<unsigned short>*>(CoefIdx<unsigned short>*, CoefIdx<unsigned short>*);
5176 
5177 template void std::__move_median_first<CoefIdx<unsigned char>*>(CoefIdx<unsigned char>*, CoefIdx<unsigned char>*, CoefIdx<unsigned char>*);
5178 template void std::__move_median_first<CoefIdx<unsigned int>*>(CoefIdx<unsigned int>*, CoefIdx<unsigned int>*, CoefIdx<unsigned int>*);
5179 template void std::__move_median_first<CoefIdx<unsigned short>*>(CoefIdx<unsigned short>*, CoefIdx<unsigned short>*, CoefIdx<unsigned short>*);
5180 
5181 template void std::__unguarded_linear_insert<CoefIdx<unsigned char>*>(CoefIdx<unsigned char>*);
5182 template void std::__unguarded_linear_insert<CoefIdx<unsigned int>*>(CoefIdx<unsigned int>*);
5183 template void std::__unguarded_linear_insert<CoefIdx<unsigned short>*>(CoefIdx<unsigned short>*);
5184 
5185 template void std::__adjust_heap<CoefIdx<unsigned char>*, long, CoefIdx<unsigned char> >(CoefIdx<unsigned char>*, long, long, CoefIdx<unsigned char>);
5186 template void std::__adjust_heap<CoefIdx<unsigned int>*, long, CoefIdx<unsigned int> >(CoefIdx<unsigned int>*, long, long, CoefIdx<unsigned int>);
5187 template void std::__adjust_heap<CoefIdx<unsigned short>*, long, CoefIdx<unsigned short> >(CoefIdx<unsigned short>*, long, long, CoefIdx<unsigned short>);
5188 
5189 template void std::__push_heap<CoefIdx<unsigned char>*, long, CoefIdx<unsigned char> >(CoefIdx<unsigned char>*, long, long, CoefIdx<unsigned char>);
5190 template void std::__push_heap<CoefIdx<unsigned int>*, long, CoefIdx<unsigned int> >(CoefIdx<unsigned int>*, long, long, CoefIdx<unsigned int>);
5191 template void std::__push_heap<CoefIdx<unsigned short>*, long, CoefIdx<unsigned short> >(CoefIdx<unsigned short>*, long, long, CoefIdx<unsigned short>);
5192 
5193 template CoefIdx<unsigned char>* std::__unguarded_partition<CoefIdx<unsigned char>*, CoefIdx<unsigned char> >(CoefIdx<unsigned char>*, CoefIdx<unsigned char>*, CoefIdx<unsigned char> const&);
5194 template CoefIdx<unsigned int>* std::__unguarded_partition<CoefIdx<unsigned int>*, CoefIdx<unsigned int> >(CoefIdx<unsigned int>*, CoefIdx<unsigned int>*, CoefIdx<unsigned int> const&);
5195 template CoefIdx<unsigned short>* std::__unguarded_partition<CoefIdx<unsigned short>*, CoefIdx<unsigned short> >(CoefIdx<unsigned short>*, CoefIdx<unsigned short>*, CoefIdx<unsigned short> const&);
5196 
5197 #endif
5198 
DataNoroCacheNode< number_type > * insertAndTransferOwnerShip(poly t, ring)
Definition: tgb_internal.h:644
static int iq_crit(const void *ap, const void *bp)
Definition: tgb.cc:1342
#define __p_GetComp(p, r)
Definition: monomials.h:71
template void noro_step< tgb_uint32 >(poly *p, int &pn, slimgb_alg *c)
static int add_to_reductors(slimgb_alg *c, poly h, int len, int ecart, BOOLEAN simplified=FALSE)
Definition: tgb.cc:965
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:500
void noro_step(poly *p, int &pn, slimgb_alg *c)
static void replace_pair(int &i, int &j, slimgb_alg *c)
Definition: tgb.cc:1217
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
Definition: gb_hack.h:53
#define TEST_OPT_REDTAIL
Definition: options.h:111
poly_tree_node * top_level
Definition: tgb.cc:1995
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define pDivide(a, b)
Definition: polys.h:264
void introduceDelayedPairs(poly *pa, int s)
Definition: tgb.cc:3142
unsigned int reduction_steps
Definition: tgb_internal.h:257
unsigned long pTotaldegree(poly p)
Definition: tgb_internal.h:286
BOOLEAN honey
Definition: kutil.h:371
poly lookup(poly term, BOOLEAN &succ, int &len)
static wlen_type quality_of_pos_in_strat_S_mult_high(int pos, poly high, slimgb_alg *c)
Definition: tgb.cc:4155
CFArray copy(const CFList &list)
write elements of list into an array
#define pSetm(p)
Definition: polys.h:241
static void sort_region_down(red_object *los, int l, int u, slimgb_alg *)
Definition: tgb.cc:4618
static void add_later(poly p, const char *prot, slimgb_alg *c)
Definition: tgb.cc:1294
void kBucketInit(kBucket_pt bucket, poly lm, int length)
Definition: kbuckets.cc:472
const poly a
Definition: syzextra.cc:212
static BOOLEAN pHasNotCFExtended(poly p1, poly p2, poly m)
Definition: tgb.cc:4065
int level(const CanonicalForm &f)
poly_tree_node(int sn)
Definition: tgb.cc:1988
omBin_t * omBin
Definition: omStructs.h:12
void PrintLn()
Definition: reporter.cc:322
static CanonicalForm bound(const CFMatrix &M)
Definition: cf_linsys.cc:460
#define Print
Definition: emacs.cc:83
int syzComp
Definition: kutil.h:357
sorted_pair_node ** add_to_basis_ideal_quotient(poly h, slimgb_alg *c, int *ip)
Definition: tgb.cc:1428
int get_n(poly p)
Definition: tgb.cc:2002
#define TEST_OPT_DEGBOUND
Definition: options.h:108
void initBuchMoraPos(kStrategy strat)
Definition: kutil.cc:7466
static BOOLEAN extended_product_criterion(poly p1, poly gcd1, poly p2, poly gcd2, slimgb_alg *c)
Definition: tgb.cc:4084
number npInit(long i, const coeffs r)
Definition: modulop.cc:130
void simplest_gauss_modp(number_type *a, int nrows, int ncols)
static int red_object_better_gen(const void *ap, const void *bp)
Definition: tgb.cc:665
'SR_INT' is the type of those integers small enough to fit into 29 bits.
Definition: longrat.h:46
int find_best(red_object *r, int l, int u, wlen_type &w, slimgb_alg *c)
returns position sets w as weight
Definition: tgb.cc:854
class sLObject LObject
Definition: kutil.h:58
sorted_pair_node ** apairs
Definition: tgb_internal.h:241
static void move_backward_in_S(int old_pos, int new_pos, kStrategy strat)
Definition: tgb.cc:1066
#define nNormalize(n)
Definition: numbers.h:30
long npInt(number &n, const coeffs r)
Definition: modulop.cc:145
#define TEST_OPT_PROT
Definition: options.h:98
wlen_set lenSw
Definition: kutil.h:318
loop
Definition: myNF.cc:98
#define pSetExp(p, i, v)
Definition: polys.h:42
static int si_min(const int a, const int b)
Definition: auxiliary.h:167
#define FALSE
Definition: auxiliary.h:140
ideal t_rep_gb(ring r, ideal arg_I, int syz_comp, BOOLEAN F4_mode)
Definition: tgb.cc:3561
int * S_2_R
Definition: kutil.h:342
static int get_last_dp_block_start(ring r)
Definition: tgb.cc:427
return P p
Definition: myNF.cc:203
number kBucketPolyRed(kBucket_pt bucket, poly p1, int l1, poly spNoether)
Definition: kbuckets.cc:1064
ideal id_Copy(ideal h1, const ring r)
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p
Definition: polys.h:105
obsolete
Definition: tgb.cc:2025
static unsigned add[]
Definition: misc_ip.cc:79
sorted_pair_node ** tmp_spn
Definition: tgb_internal.h:237
wlen_type * weighted_lengths
Definition: tgb_internal.h:230
static int nlQlogSize(number n, const coeffs r)
only used by slimgb (tgb.cc)
Definition: longrat.h:74
virtual void reduce(red_object *r, int l, int u)
we assume hat all occuring red_objects have same lm, and all occ. lm's in r[l...u] are the same...
Definition: tgb.cc:4877
BOOLEAN tailReductions
Definition: tgb_internal.h:279
#define p_GetComp(p, r)
Definition: monomials.h:72
#define pTest(p)
Definition: polys.h:387
poly_tree_node * r
Definition: tgb.cc:1986
#define pExpVectorDiff(pr, p1, p2)
Definition: polys.h:91
int expand_length
Definition: tgb_internal.h:386
BOOLEAN use_noro_last_block
Definition: tgb_internal.h:275
static poly redNF2(poly h, slimgb_alg *c, int &len, number &m, int n=0)
Definition: tgb.cc:1840
static poly pp_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:927
static poly last
Definition: hdegree.cc:1056
kBucket_pt bucket
Definition: tgb_internal.h:309
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition: coeffs.h:537
template void noro_step< tgb_uint8 >(poly *p, int &pn, slimgb_alg *c)
int to_reduce_u
Definition: tgb_internal.h:387
#define ppMult_mm(p, m)
Definition: polys.h:172
int * idx_array
Definition: tgb_internal.h:514
int pTotaldegree_full(poly p)
Definition: tgb_internal.h:294
#define omAllocAligned
Definition: omAllocDecl.h:273
const ideal
Definition: gb_hack.h:42
static int multi_reduction_clear_zeroes(red_object *los, int losl, int l, int u)
Definition: tgb.cc:4565
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
const poly kBucketGetLm(kBucket_pt bucket)
Definition: kbuckets.cc:485
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:531
void id_Delete(ideal *h, ring r)
kBucket_pt fill_back
Definition: tgb_internal.h:361
CFFListIterator iter
Definition: facAbsBiFact.cc:54
poly kNoether
Definition: kutil.h:328
KINLINE poly ksOldCreateSpoly(poly p1, poly p2, poly spNoether, ring r)
Definition: kInline.h:1102
int exp
Definition: tgbgauss.h:45
static BOOLEAN polynomial_root(poly h, ring r)
Definition: tgb.cc:109
poly_tree_node * l
Definition: tgb.cc:1985
char N base
Definition: ValueTraits.h:144
#define MAX_BUCKET
Bucket definition (should be no one elses business, though)
Definition: kbuckets.h:174
void free_sorted_pair_node(sorted_pair_node *s, ring r)
Definition: tgb.cc:3958
static void multi_reduce_step(find_erg &erg, red_object *r, slimgb_alg *c)
Definition: tgb.cc:4932
static void multi_reduction_lls_trick(red_object *los, int, slimgb_alg *c, find_erg &erg)
Definition: tgb.cc:4169
#define omUnGetSpecBin(bin_ptr)
Definition: omBin.h:14
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition: p_polys.h:962
Definition: ring.h:203
int * T_deg_full
Definition: tgb_internal.h:234
#define TRUE
Definition: auxiliary.h:144
#define TEST_OPT_REDSB
Definition: options.h:99
int kFindDivisibleByInS_easy(kStrategy strat, const red_object &obj)
Definition: tgb.cc:685
static void shorten_tails(slimgb_alg *c, poly monom)
Definition: tgb.cc:3718
number * array
Definition: tgb_internal.h:499
#define pHasNotCF(p1, p2)
Definition: polys.h:233
NoroCacheNode root
Definition: tgb_internal.h:751
void deleteInS(int i, kStrategy strat)
Definition: kutil.cc:932
poly free_row_to_poly(tgb_sparse_matrix *mat, int row, poly *monoms, int monom_index)
Definition: tgb.cc:3104
#define pLcm(a, b, m)
Definition: polys.h:266
ring rAssure_TDeg(ring r, int start_var, int end_var, int &pos)
Definition: ring.cc:4440
BOOLEAN is_valid_ro(red_object &ro)
Definition: tgb.cc:2059
static poly redTailShort(poly h, kStrategy strat)
Definition: tgb.cc:1923
int normal_forms
Definition: tgb_internal.h:262
#define POLYSIZE
Definition: monomials.h:241
int k
Definition: cfEzgcd.cc:93
void cleanDegs(int lower, int upper)
Definition: tgb.cc:3797
calc_state
Definition: tgb_internal.h:322
int_pair_node * soon_free
Definition: tgb_internal.h:240
#define TEST_OPT_DEBUG
Definition: options.h:103
void t2ippa_rec(poly *ip, int *ia, poly_tree_node *k, int &offset)
obsolete
Definition: tgb.cc:2033
static void move_forward_in_S(int old_pos, int new_pos, kStrategy strat)
Definition: tgb.cc:1029
#define pExpVectorSub(p1, p2)
Definition: polys.h:88
number coef
Definition: tgbgauss.h:43
static poly pOne_Special(const ring r=currRing)
Definition: tgb.cc:142
number * buffer
Definition: tgb_internal.h:752
DataNoroCacheNode< number_type > * insert(poly term, poly nf, int len)
Definition: tgb_internal.h:604
mac_poly_r * next
Definition: tgbgauss.h:44
static BOOLEAN monomial_root(poly m, ring r)
Definition: tgb.cc:89
static BOOLEAN trivial_syzygie(int pos1, int pos2, poly bound, slimgb_alg *c)
Definition: tgb.cc:800
#define omTypeAllocBin(type, addr, bin)
Definition: omAllocDecl.h:203
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
poly ksCreateShortSpoly(poly p1, poly p2, ring tailRing)
Definition: kspoly.cc:563
#define omAlloc(size)
Definition: omAllocDecl.h:210
static BOOLEAN elength_is_normal_length(poly p, slimgb_alg *c)
Definition: tgb.cc:371
static bool rIsPluralRing(const ring r)
we must always have this test!
Definition: ring.h:355
void clean_top_of_pair_list(slimgb_alg *c)
Definition: tgb.cc:3925
slimgb_alg * c
Definition: tgb_internal.h:354
static int tgb_pair_better_gen(const void *ap, const void *bp)
Definition: tgb.cc:3993
kBucket_pt kBucketCreate(ring bucket_ring)
Creation/Destruction of buckets.
Definition: kbuckets.cc:198
static number p_SetCoeff(poly p, number n, ring r)
Definition: p_polys.h:401
int terms_sort_crit(const void *a, const void *b)
Definition: tgb.cc:2068
int pos_helper(kStrategy strat, poly p, len_type len, set_type setL, polyset set)
Definition: tgb_internal.h:394
int tdeg(poly p)
Definition: walkSupport.cc:38
#define pGetComp(p)
Component.
Definition: polys.h:37
static int pLength(poly a)
Definition: p_polys.h:189
poly kBucketExtractLm(kBucket_pt bucket)
Definition: kbuckets.cc:490
static int * make_connections(int from, int to, poly bound, slimgb_alg *c)
Definition: tgb.cc:1103
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition: p_polys.h:811
bool found
Definition: facFactorize.cc:56
virtual ~slimgb_alg()
Definition: tgb.cc:3366
int comp(const CanonicalForm &A, const CanonicalForm &B)
compare polynomials
static wlen_type pSLength(poly p, int l)
Definition: tgb.cc:197
static void multi_reduction(red_object *los, int &losl, slimgb_alg *c)
Definition: tgb.cc:4674
#define mflush()
Definition: reporter.h:42
static wlen_type coeff_mult_size_estimate(int s1, int s2, ring r)
Definition: tgb.cc:1367
BOOLEAN F4_mode
Definition: tgb_internal.h:281
#define pIter(p)
Definition: monomials.h:44
sorted_pair_node * top_pair(slimgb_alg *c)
Definition: tgb.cc:3880
poly res
Definition: myNF.cc:322
ideal add_later
Definition: tgb_internal.h:226
mp_array_list * next
Definition: tgb_internal.h:200
~simple_reducer()
Definition: tgb.cc:4923
void(* initEcart)(TObject *L)
Definition: kutil.h:279
void canonicalize()
Definition: tgb.cc:871
void bit_reduce(poly &f, ring r)
Definition: digitech.cc:15
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
#define pGetExp(p, i)
Exponent.
Definition: polys.h:41
long * short_Exps
Definition: tgb_internal.h:231
virtual void do_reduce(red_object &ro)
Definition: tgb.cc:4881
static int rBlocks(ring r)
Definition: ring.h:507
static wlen_type quality_of_pos_in_strat_S(int pos, slimgb_alg *c)
Definition: tgb.cc:4146
BOOLEAN nc
Definition: tgb_internal.h:282
clock_t to
Definition: walk.cc:99
ideal do_t_rep_gb(ring, ideal arg_I, int syz_comp, BOOLEAN F4_mode, int deg_pos)
Definition: tgb.cc:3609
const ring r
Definition: syzextra.cc:208
static int pTotaldegree_full(poly p)
Definition: tgb.cc:579
static BOOLEAN has_t_rep(const int &arg_i, const int &arg_j, slimgb_alg *state)
Definition: tgb.cc:3685
#define ADD_LATER_SIZE
Definition: tgb.cc:39
sorted_pair_node * quick_pop_pair(slimgb_alg *c)
Definition: tgb.cc:3904
poly row_to_poly(number_type *row, poly *terms, int tn, ring r)
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:205
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
static void go_on(slimgb_alg *c)
Definition: tgb.cc:2716
static wlen_type do_pELength(poly p, slimgb_alg *c, int dlm=-1)
Definition: tgb.cc:446
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent : the integer VarOffset encodes:
Definition: p_polys.h:465
virtual ~reduction_step()
Definition: tgb.cc:4919
int j
Definition: myNF.cc:70
wlen_type kEBucketLength(kBucket *b, poly lm, slimgb_alg *ca)
Definition: tgb.cc:494
poly expand
Definition: tgb_internal.h:385
#define omFreeBinAddr(addr)
Definition: omAllocDecl.h:258
#define omFree(addr)
Definition: omAllocDecl.h:261
int tgb_pair_better_gen2(const void *ap, const void *bp)
Definition: tgb.cc:680
static long pTotaldegree(poly p)
Definition: polys.h:253
unsigned long p_GetShortExpVector(poly p, const ring r)
Definition: p_polys.cc:4556
polyrec * poly
Definition: hilb.h:10
#define assume(x)
Definition: mod2.h:405
intset fromQ
Definition: kutil.h:319
DataNoroCacheNode< number_type > * getCacheReference(poly term)
int status int void * buf
Definition: si_signals.h:58
slimgb_alg(ideal I, int syz_comp, BOOLEAN F4, int deg_pos)
Definition: tgb.cc:3178
void initEcartBBA(TObject *h)
Definition: kutil.cc:1133
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:64
kStrategy strat
Definition: tgb_internal.h:232
poly_array_list * next
Definition: tgb_internal.h:208
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl.cc )
Definition: polys.h:140
#define nMult(n1, n2)
Definition: numbers.h:17
#define pLmShortDivisibleBy(a, sev_a, b, not_sev_b)
Divisibility tests based on Short Exponent vectors sev_a == pGetShortExpVector(a) not_sev_b == ~ pGet...
Definition: polys.h:134
void init_with_mac_poly(tgb_sparse_matrix *mat, int row, mac_poly m)
Definition: tgb.cc:3089
pNormalize(P.p)
int search_red_object_pos(red_object *a, int top, red_object *key)
Definition: tgb.cc:4593
#define omfree(addr)
Definition: omAllocDecl.h:237
poly sca_pp_Mult_xi_pp(short i, const poly pPoly, const ring rRing)
Definition: sca.cc:1217
static poly p_Init_Special(const ring r)
Definition: tgb.cc:137
static BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition: p_polys.h:1707
ideal kInterRed(ideal F, ideal Q)
Definition: kstd1.cc:3059
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:77
void write_poly_to_row(number_type *row, poly h, poly *terms, int tn, ring r)
makes on each red_object in a region a single_step
Definition: tgb_internal.h:346
P bucket
Definition: myNF.cc:79
#define pSetComp(p, v)
Definition: polys.h:38
int m
Definition: cfEzgcd.cc:119
void idDelete(ideal *h, ring r=currRing)
delete an ideal
Definition: ideals.h:31
BOOLEAN lenS_correct(kStrategy strat)
Definition: tgb.cc:907
#define pMult_nn(p, n)
Definition: polys.h:171
int extended_product_crit
Definition: tgb_internal.h:269
BOOLEAN isDifficultField
Definition: tgb_internal.h:276
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:7325
static omBin lm_bin
Definition: tgb.cc:41
static int si_max(const int a, const int b)
Definition: auxiliary.h:166
void kBucketSimpleContent(kBucket_pt)
Definition: kbuckets.cc:1165
static int bucket_guess(kBucket *bucket)
Definition: tgb.cc:952
static poly redNFTail(poly h, const int sl, kStrategy strat, int len)
Definition: tgb.cc:2975
static int posInPairs(sorted_pair_node **p, int pn, sorted_pair_node *qe, slimgb_alg *c, int an=0)
Definition: tgb.cc:711
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:294
static poly p_Mult_nn(poly p, number n, const ring r)
Definition: p_polys.h:902
static BOOLEAN rField_is_Q(const ring r)
Definition: ring.h:452
#define TEST_V_COEFSTRAT
Definition: options.h:132
mp_array_list * F
Definition: tgb_internal.h:250
poly * expandS
Definition: tgb_internal.h:238
#define pOne()
Definition: polys.h:286
number_type * coef_array
Definition: tgb_internal.h:515
polyset S
Definition: kutil.h:304
#define IDELEMS(i)
Definition: simpleideals.h:19
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition: p_polys.h:1673
static void length_one_crit(slimgb_alg *c, int pos, int len)
Definition: tgb.cc:1007
wlen_type guess_quality(slimgb_alg *c)
Definition: tgb.cc:591
void idSkipZeroes(ideal ide)
static short scaFirstAltVar(ring r)
Definition: sca.h:18
BOOLEAN is_homog
Definition: tgb_internal.h:278
intset lenS
Definition: kutil.h:317
static BOOLEAN pair_better(sorted_pair_node *a, sorted_pair_node *b, slimgb_alg *c=NULL)
Definition: tgb.cc:3966
#define nDelete(n)
Definition: numbers.h:16
static const int delay_factor
Definition: tgb.cc:38
static const int bundle_size_noro
Definition: tgb.cc:37
#define p_Test(p, r)
Definition: p_polys.h:160
void rChangeCurrRing(ring r)
Definition: polys.cc:14
static void c_S_element_changed_hook(int pos, slimgb_alg *c)
Definition: tgb.cc:1974
wlen_type pELength(poly p, slimgb_alg *c, ring)
Definition: tgb.cc:471
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
static BOOLEAN rField_is_Zp(const ring r)
Definition: ring.h:446
kStrategy strat
Definition: myNF.cc:319
#define nInvers(a)
Definition: numbers.h:33
static void p_Delete(poly *p, const ring r)
Definition: p_polys.h:850
#define omGetSpecBin(size)
Definition: omBin.h:11
static int poly_crit(const void *ap1, const void *ap2)
Definition: tgb.cc:3124
static void super_clean_top_of_pair_list(slimgb_alg *c)
Definition: tgb.cc:3912
int lastCleanedDeg
Definition: tgb_internal.h:272
#define pi
Definition: libparse.cc:1143
intset ecartS
Definition: kutil.h:307
ideal idInit(int idsize, int rank)
Definition: simpleideals.cc:40
#define p_LmEqual(p1, p2, r)
Definition: p_polys.h:1519
int current_degree
Definition: tgb_internal.h:263
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
wlen_type expected_length
Definition: tgb_internal.h:158
static void p_ExpVectorDiff(poly pr, poly p1, poly p2, const ring r)
Definition: p_polys.h:1402
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent : VarOffset encodes the position in p->exp
Definition: p_polys.h:484
#define ENLARGE(pointer, type)
int lastDpBlockStart
Definition: tgb_internal.h:271
static void clearS(poly p, unsigned long p_sev, int l, int *at, int *k, kStrategy strat)
Definition: tgb.cc:1325
poly temp_term
Definition: tgb_internal.h:590
virtual void pre_reduce(red_object *r, int l, int u)
Definition: tgb.cc:5044
int average_length
Definition: tgb_internal.h:270
#define omalloc(size)
Definition: omAllocDecl.h:228
#define omrealloc(addr, size)
Definition: omAllocDecl.h:233
#define TEST_V_MODPSOLVSB
Definition: options.h:131
#define NULL
Definition: omList.c:10
static void mass_add(poly *p, int pn, slimgb_alg *c)
Definition: tgb.cc:2183
void pEnlargeSet(poly **p, int l, int increment)
Definition: p_polys.cc:3511
static void cleanS(kStrategy strat, slimgb_alg *c)
Definition: tgb.cc:919
static const int backLinkCode
Definition: tgb_internal.h:603
int64 wlen_type
Definition: kutil.h:54
static poly gcd_of_terms(poly p, ring r)
Definition: tgb.cc:4025
char ** states
Definition: tgb_internal.h:221
static BOOLEAN ascending(int *i, int top)
Definition: tgb.cc:742
void rDelete(ring r)
unconditionally deletes fields in r
Definition: ring.cc:448
ring tailRing
Definition: kutil.h:343
BOOLEAN use_noro
Definition: tgb_internal.h:274
number npNeg(number c, const coeffs r)
Definition: modulop.cc:314
void t2ippa(poly *ip, int *ia, exp_number_builder &e)
obsolete
Definition: tgb.cc:2047
virtual void reduce(red_object *r, int l, int u)
we assume hat all occuring red_objects have same lm, and all occ. lm's in r[l...u] are the same...
Definition: tgb.cc:4893
int * lengths
Definition: tgb_internal.h:229
void pNorm(poly p, const ring R=currRing)
Definition: polys.h:334
BOOLEAN completed
Definition: tgb_internal.h:277
static BOOLEAN state_is(calc_state state, const int &i, const int &j, slimgb_alg *c)
Definition: tgb.cc:3939
const CanonicalForm & w
Definition: facAbsFact.cc:55
#define pDelete(p_ptr)
Definition: polys.h:157
#define omSizeWOfBin(bin_ptr)
poly * tmp_pair_lm
Definition: tgb_internal.h:236
static short scaLastAltVar(ring r)
Definition: sca.h:25
template void noro_step< tgb_uint16 >(poly *p, int &pn, slimgb_alg *c)
number npMult(number a, number b, const coeffs r)
Definition: modulop.cc:115
unsigned long * sevS
Definition: kutil.h:320
#define nSize(n)
Definition: numbers.h:39
BOOLEAN eliminationProblem
Definition: tgb_internal.h:280
static bool rIsSCA(const ring r)
Definition: nc.h:206
#define pNext(p)
Definition: monomials.h:43
int array_lengths
Definition: tgb_internal.h:261
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:436
int * intset
Definition: kutil.h:53
NoroCacheNode ** branches
Definition: tgb_internal.h:432
poly p
Definition: tgb.cc:2027
#define pSetCoeff0(p, n)
Definition: monomials.h:67
#define p_GetCoeff(p, r)
Definition: monomials.h:57
wlen_type initial_quality
Definition: tgb_internal.h:314
static int simple_posInS(kStrategy strat, poly p, int len, wlen_type wlen)
Definition: tgb.cc:1310
poly * gcd_of_terms
Definition: tgb_internal.h:239
int sl
Definition: kutil.h:351
static wlen_type pair_weighted_length(int i, int j, slimgb_alg *c)
Definition: tgb.cc:1375
void sort(CFArray &A, int l=0)
quick sort A
unsigned long sev
Definition: tgb_internal.h:311
poly_list_node * next
Definition: tgb_internal.h:182
poly_array_list * F_minus
Definition: tgb_internal.h:251
#define TEST_V_FINDMONOM
Definition: options.h:134
p exp[i]
Definition: DebugPrint.cc:39
wlen_type * wlen_set
Definition: kutil.h:55
BOOLEAN good_has_t_rep(int i, int j, slimgb_alg *c)
Definition: tgb.cc:876
static poly nc_mm_Mult_pp(const poly m, const poly p, const ring r)
Definition: nc.h:240
static void simplify_poly(poly p, ring r)
Definition: tgb.cc:59
BOOLEAN fromS
Definition: tgb_internal.h:390
static poly nc_CreateSpoly(const poly p1, const poly p2, const ring r)
Definition: nc.h:258
END_NAMESPACE const void * p2
Definition: syzextra.cc:202
sorted_pair_node ** spn_merge(sorted_pair_node **p, int pn, sorted_pair_node **q, int qn, slimgb_alg *c)
Definition: tgb.cc:751
static scmon act
Definition: hdegree.cc:1057
int nIrreducibleMonomials
Definition: tgb_internal.h:703
int easy_product_crit
Definition: tgb_internal.h:268
static BOOLEAN lies_in_last_dp_block(poly p, slimgb_alg *c)
Definition: tgb.cc:399
static const int bundle_size
Definition: tgb.cc:36
int clear_to_poly()
Definition: tgb.cc:4869
void flatten()
Definition: tgb.cc:4857
#define TEST_V_UPTORADICAL
Definition: options.h:133
void wrp(poly p)
Definition: polys.h:281
void enterSBba(LObject p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:6927
kBucketDestroy & P
Definition: myNF.cc:191
int reduce_by
Definition: tgb_internal.h:389
int Kstd1_deg
Definition: kutil.cc:228
static void canonicalize_region(red_object *los, int l, int u, slimgb_alg *)
Definition: tgb.cc:4487
#define TEST_OPT_REDTHROUGH
Definition: options.h:116
int syz_comp
array_lengths should be greater equal n;
Definition: tgb_internal.h:260
ideal Shdl
Definition: kutil.h:301
int slim_nsize(number n, ring r)
Definition: tgb.cc:73
#define nInit(i)
Definition: numbers.h:24
void(* enterS)(LObject h, int pos, kStrategy strat, int atR)
Definition: kutil.h:285
int offset
Definition: libparse.cc:1091
int to_reduce_l
Definition: tgb_internal.h:388
static Poly * h
Definition: janet.cc:978
int BOOLEAN
Definition: auxiliary.h:131
int kBucketCanonicalize(kBucket_pt bucket)
int anti_poly_order(const void *a, const void *b)
Definition: tgb.cc:2054
BOOLEAN idIs0(ideal h)
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1248
const poly b
Definition: syzextra.cc:213
poly p_Cleardenom(poly p, const ring r)
Definition: p_polys.cc:2655
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition: polys.h:31
BOOLEAN rRing_has_CompLastBlock(ring r)
Definition: ring.cc:5073
ideal idrCopyR_NoSort(ideal id, ring src_r, ring dest_r)
Definition: prCopy.cc:205
static FORCE_INLINE int n_Size(number n, const coeffs r)
return a non-negative measure for the complexity of n; return 0 only when n represents zero; (used fo...
Definition: coeffs.h:569
void id_Compactify(ideal id, const ring r)
static void line_of_extended_prod(int fixpos, slimgb_alg *c)
Definition: tgb.cc:1942
BOOLEAN npIsOne(number a, const coeffs r)
Definition: modulop.cc:184
static wlen_type pQuality(poly p, slimgb_alg *c, int l=-1)
Definition: tgb.cc:544
mac_poly * mp
Definition: tgbgauss.h:56
#define pLmEqual(p1, p2)
Definition: polys.h:111
#define omAlloc0(size)
Definition: omAllocDecl.h:211
return result
Definition: facAbsBiFact.cc:76
int l
Definition: cfEzgcd.cc:94
static void nc_BucketPolyRed_Z(kBucket_pt b, poly p, number *c)
Definition: nc.h:303
void validate()
Definition: tgb.cc:4862
ideal idrMoveR_NoSort(ideal &id, ring src_r, ring dest_r)
Definition: prCopy.cc:261
#define ENLARGE_ALIGN(pointer, type)
poly_list_node * to_destroy
Definition: tgb_internal.h:248
#define pCopy(p)
return a copy of the poly
Definition: polys.h:156
static int fwbw(red_object *los, int i)
Definition: tgb.cc:4429
void now_t_rep(const int &arg_i, const int &arg_j, slimgb_alg *c)
Definition: tgb.cc:3664
void kBucket_Add_q(kBucket_pt bucket, poly q, int *l)
Add to Bucket a poly ,i.e. Bpoly == q+Bpoly.
Definition: kbuckets.cc:637
static void multi_reduction_find(red_object *los, int losl, slimgb_alg *c, int startf, find_erg &erg)
Definition: tgb.cc:4503
#define idTest(id)
Definition: ideals.h:63
monom_poly * mp
Definition: tgb_internal.h:198
wlen_type kSBucketLength(kBucket *b, poly lm=NULL)
TODO CoefBuckets bercksichtigen.
Definition: tgb.cc:221
SparseRow< number_type > * row
Definition: tgb_internal.h:550