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