1 | #include "mod2.h" |
---|
2 | #include <omalloc.h> |
---|
3 | #include "p_polys.h" |
---|
4 | //#include "prCopy.h" |
---|
5 | #include "ideals.h" |
---|
6 | #include "ring.h" |
---|
7 | #include "febase.h" |
---|
8 | #include "structs.h" |
---|
9 | #include "polys.h" |
---|
10 | #include "stdlib.h" |
---|
11 | |
---|
12 | |
---|
13 | #include "kutil.h" |
---|
14 | #include "kInline.cc" |
---|
15 | #include "kstd1.h" |
---|
16 | #include "kbuckets.h" |
---|
17 | |
---|
18 | #define FULLREDUCTIONS |
---|
19 | //#define HALFREDUCTIONS |
---|
20 | #define HEAD_BIN |
---|
21 | //#define HOMOGENEOUS_EXAMPLE |
---|
22 | #define REDTAIL_S |
---|
23 | #define PAR_N 5 |
---|
24 | //#define REDTAIL_PROT |
---|
25 | //#define QUICK_SPOLY_TEST |
---|
26 | //#define DIAGONAL_GOING |
---|
27 | //#define RANDOM_WALK |
---|
28 | struct int_pair_node{ |
---|
29 | int_pair_node* next; |
---|
30 | int a; |
---|
31 | int b; |
---|
32 | }; |
---|
33 | BOOLEAN lenS_correct(kStrategy strat){ |
---|
34 | int i; |
---|
35 | for(i=0;i<=strat->sl;i++){ |
---|
36 | if (strat->lenS[i]!=pLength(strat->S[i])) |
---|
37 | return FALSE; |
---|
38 | } |
---|
39 | return TRUE; |
---|
40 | |
---|
41 | } |
---|
42 | int bucket_guess(kBucket* bucket){ |
---|
43 | int sum=0; |
---|
44 | int i; |
---|
45 | for (i=0;i<MAX_BUCKET+1;i++){ |
---|
46 | sum+=bucket->buckets_length[i]; |
---|
47 | } |
---|
48 | return sum; |
---|
49 | } |
---|
50 | struct redNF_inf{ |
---|
51 | poly h; |
---|
52 | LObject* P; |
---|
53 | int_pair_node* pending; |
---|
54 | int len_upper_bound; |
---|
55 | int i; |
---|
56 | int j; |
---|
57 | BOOLEAN need_std_rep; |
---|
58 | BOOLEAN is_free; |
---|
59 | BOOLEAN started; |
---|
60 | }; |
---|
61 | |
---|
62 | #ifdef RANDOM_WALK |
---|
63 | int my_rand(int n){ |
---|
64 | //RANDOM integer beetween 0,..,n-1 |
---|
65 | int erg=(double(rand())/RAND_MAX) *n; |
---|
66 | return ((erg>=n)?erg-1:erg); |
---|
67 | |
---|
68 | } |
---|
69 | #endif |
---|
70 | enum calc_state |
---|
71 | { |
---|
72 | UNCALCULATED, |
---|
73 | HASTREP, |
---|
74 | UNIMPORTANT, |
---|
75 | SOONTREP |
---|
76 | }; |
---|
77 | struct calc_dat |
---|
78 | { |
---|
79 | int* rep; |
---|
80 | char** states; |
---|
81 | ideal S; |
---|
82 | ring r; |
---|
83 | int* lengths; |
---|
84 | long* short_Exps; |
---|
85 | kStrategy strat; |
---|
86 | int** deg; |
---|
87 | int* T_deg; |
---|
88 | int* misses; |
---|
89 | int_pair_node* soon_free; |
---|
90 | redNF_inf* work_on; |
---|
91 | #ifdef HEAD_BIN |
---|
92 | struct omBin_s* HeadBin; |
---|
93 | #endif |
---|
94 | int max_misses; |
---|
95 | int found_i; |
---|
96 | int found_j; |
---|
97 | int continue_i; |
---|
98 | int continue_j; |
---|
99 | int n; |
---|
100 | int skipped_i; |
---|
101 | int normal_forms; |
---|
102 | int skipped_pairs; |
---|
103 | int current_degree; |
---|
104 | int misses_counter; |
---|
105 | int misses_series; |
---|
106 | }; |
---|
107 | BOOLEAN find_next_pair(calc_dat* c); |
---|
108 | void shorten_tails(calc_dat* c, poly monom); |
---|
109 | void replace_pair(int & i, int & j, calc_dat* c); |
---|
110 | void initial_data(calc_dat* c); |
---|
111 | void add_to_basis(poly h, calc_dat* c); |
---|
112 | void do_this_spoly_stuff(int i,int j,calc_dat* c); |
---|
113 | ideal t_rep_gb(ring r,ideal arg_I); |
---|
114 | BOOLEAN has_t_rep(const int & arg_i, const int & arg_j, calc_dat* state); |
---|
115 | int* make_connections(int from, poly bound, calc_dat* c); |
---|
116 | int* make_connections(int from, int to, poly bound, calc_dat* c); |
---|
117 | void now_t_rep(const int & arg_i, const int & arg_j, calc_dat* c); |
---|
118 | void soon_t_rep(const int & arg_i, const int & arg_j, calc_dat* c); |
---|
119 | int pLcmDeg(poly a, poly b); |
---|
120 | int simple_posInS (kStrategy strat, poly p,int len); |
---|
121 | |
---|
122 | BOOLEAN find_next_pair(calc_dat* c) |
---|
123 | { |
---|
124 | int start_i,start_j,i,j; |
---|
125 | start_i=0; |
---|
126 | start_j=-1; |
---|
127 | #ifndef HOMOGENEOUS_EXAMPLE |
---|
128 | if (c->misses_series>80){ |
---|
129 | c->current_degree++; |
---|
130 | c->misses_series=0; |
---|
131 | } |
---|
132 | #endif |
---|
133 | start_i=c->continue_i; |
---|
134 | start_j=c->continue_j; |
---|
135 | #ifndef DIAGONAL_GOING |
---|
136 | for (int i=start_i;i<c->n;i++){ |
---|
137 | if (c->T_deg[i]>c->current_degree) |
---|
138 | { |
---|
139 | c->skipped_pairs++; |
---|
140 | continue; |
---|
141 | } |
---|
142 | for(int j=(i==start_i)?start_j+1:0;j<i;j++){ |
---|
143 | // printf("searching at %d,%d",i,j); |
---|
144 | if (c->misses_counter>=2) { |
---|
145 | c->skipped_pairs++; |
---|
146 | break; |
---|
147 | } |
---|
148 | if (c->states[i][j]==UNCALCULATED){ |
---|
149 | if(c->deg[i][j]<=c->current_degree) |
---|
150 | { |
---|
151 | c->continue_i=c->found_i=i; |
---|
152 | c->continue_j=c->found_j=j; |
---|
153 | return TRUE; |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | ++(c->skipped_pairs); |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | c->misses_counter=0; |
---|
162 | } |
---|
163 | |
---|
164 | |
---|
165 | if (!((start_i==1) &&(start_j==0))){ |
---|
166 | c->continue_i=1; |
---|
167 | c->continue_j=0; |
---|
168 | return find_next_pair(c); |
---|
169 | } |
---|
170 | |
---|
171 | #else |
---|
172 | int z=0; |
---|
173 | i=start_i; |
---|
174 | j=start_j; |
---|
175 | z=start_i+start_j; |
---|
176 | while(z<=(2*c->n-3)){ |
---|
177 | |
---|
178 | while(i>j){ |
---|
179 | if(i>=c->n) { |
---|
180 | if (c->skipped_i<0) c->skipped_i=i; |
---|
181 | } else{ |
---|
182 | if(c->states[i][j]==UNCALCULATED){ |
---|
183 | if (c->deg[i][j]<=c->current_degree) |
---|
184 | { |
---|
185 | c->continue_i=c->found_i=i; |
---|
186 | c->continue_j=c->found_j=j; |
---|
187 | return TRUE; |
---|
188 | } |
---|
189 | else |
---|
190 | { |
---|
191 | ++(c->skipped_pairs); |
---|
192 | } |
---|
193 | } |
---|
194 | } |
---|
195 | --i; |
---|
196 | ++j; |
---|
197 | } |
---|
198 | ++z; |
---|
199 | i=z; |
---|
200 | j=0; |
---|
201 | } |
---|
202 | #endif |
---|
203 | if (c->skipped_pairs>0){ |
---|
204 | ++(c->current_degree); |
---|
205 | c->skipped_pairs=0; |
---|
206 | c->continue_i=0; |
---|
207 | c->continue_j=0; |
---|
208 | return find_next_pair(c); |
---|
209 | } |
---|
210 | return FALSE; |
---|
211 | } |
---|
212 | void move_forward_in_S(int old_pos, int new_pos,kStrategy strat) |
---|
213 | { |
---|
214 | assume(old_pos>=new_pos); |
---|
215 | poly p=strat->S[old_pos]; |
---|
216 | int ecart=strat->ecartS[old_pos]; |
---|
217 | long sev=strat->sevS[old_pos]; |
---|
218 | int s_2_r=strat->S_2_R[old_pos]; |
---|
219 | int length=strat->lenS[old_pos]; |
---|
220 | int i; |
---|
221 | for (i=old_pos; i>new_pos; i--) |
---|
222 | { |
---|
223 | strat->S[i] = strat->S[i-1]; |
---|
224 | strat->ecartS[i] = strat->ecartS[i-1]; |
---|
225 | strat->sevS[i] = strat->sevS[i-1]; |
---|
226 | strat->S_2_R[i] = strat->S_2_R[i-1]; |
---|
227 | } |
---|
228 | if (strat->lenS!=NULL) |
---|
229 | for (i=old_pos; i>new_pos; i--) |
---|
230 | strat->lenS[i] = strat->lenS[i-1]; |
---|
231 | |
---|
232 | strat->S[new_pos]=p; |
---|
233 | strat->ecartS[new_pos]=ecart; |
---|
234 | strat->sevS[new_pos]=sev; |
---|
235 | strat->S_2_R[new_pos]=s_2_r; |
---|
236 | strat->lenS[new_pos]=length; |
---|
237 | //assume(lenS_correct(strat)); |
---|
238 | } |
---|
239 | void replace_pair(int & i, int & j, calc_dat* c) |
---|
240 | { |
---|
241 | c->soon_free=NULL; |
---|
242 | int curr_deg; |
---|
243 | poly lm=pOne(); |
---|
244 | |
---|
245 | pLcm(c->S->m[i], c->S->m[j], lm); |
---|
246 | pSetm(lm); |
---|
247 | int deciding_deg= pFDeg(lm); |
---|
248 | int* i_con =make_connections(i,j,lm,c); |
---|
249 | int z=0; |
---|
250 | |
---|
251 | for (int n=0;((n<c->n) && (i_con[n]>=0));n++){ |
---|
252 | if (i_con[n]==j){ |
---|
253 | // curr_deg=pFDeg(lm); |
---|
254 | // for(int z1=0;((z1<c->n) && (i_con[z1]>=0));z1++) |
---|
255 | // for (int z2=z1+1;((z2<c->n)&&(i_con[z2]>=0));z2++) |
---|
256 | // { |
---|
257 | // pLcm(c->S->m[i_con[z1]], c->S->m[i_con[z2]], lm); |
---|
258 | // pSetm(lm); |
---|
259 | // if (pFDeg(lm)==curr_deg) |
---|
260 | // now_t_rep(i_con[z1],i_con[z2],c); |
---|
261 | // } |
---|
262 | now_t_rep(i,j,c); |
---|
263 | omfree(i_con); |
---|
264 | p_Delete(&lm,c->r); |
---|
265 | return; |
---|
266 | } |
---|
267 | } |
---|
268 | |
---|
269 | int* j_con =make_connections(j,lm,c); |
---|
270 | i= i_con[0]; |
---|
271 | j=j_con[0]; |
---|
272 | if(c->n>1){ |
---|
273 | if (i_con[1]>=0) |
---|
274 | i=i_con[1]; |
---|
275 | else { |
---|
276 | if (j_con[1]>=0) |
---|
277 | j=j_con[1]; |
---|
278 | } |
---|
279 | } |
---|
280 | pLcm(c->S->m[i], c->S->m[j], lm); |
---|
281 | pSetm(lm); |
---|
282 | poly short_s; |
---|
283 | curr_deg=pFDeg(lm); |
---|
284 | int_pair_node* last=NULL; |
---|
285 | |
---|
286 | for (int n=0;((n<c->n) && (j_con[n]>=0));n++){ |
---|
287 | for (int m=0;((m<c->n) && (i_con[m]>=0));m++){ |
---|
288 | pLcm(c->S->m[i_con[m]], c->S->m[j_con[n]], lm); |
---|
289 | pSetm(lm); |
---|
290 | if (pFDeg(lm)>=deciding_deg) |
---|
291 | { |
---|
292 | soon_t_rep(i_con[m],j_con[n],c); |
---|
293 | int_pair_node* h= (int_pair_node*)omalloc(sizeof(int_pair_node)); |
---|
294 | if (last!=NULL) |
---|
295 | last->next=h; |
---|
296 | else |
---|
297 | c->soon_free=h; |
---|
298 | h->next=NULL; |
---|
299 | h->a=i_con[m]; |
---|
300 | h->b=j_con[n]; |
---|
301 | last=h; |
---|
302 | } |
---|
303 | // if ((comp_deg<curr_deg) |
---|
304 | // || |
---|
305 | // ((comp_deg==curr_deg) && |
---|
306 | short_s=ksCreateShortSpoly(c->S->m[i_con[m]],c->S->m[j_con[n]],c->r); |
---|
307 | if (short_s==NULL) { |
---|
308 | i=i_con[m]; |
---|
309 | j=j_con[n]; |
---|
310 | now_t_rep(i_con[m],j_con[n],c); |
---|
311 | p_Delete(&lm,c->r); |
---|
312 | omfree(i_con); |
---|
313 | omfree(j_con); |
---|
314 | |
---|
315 | return; |
---|
316 | |
---|
317 | } |
---|
318 | #ifdef QUICK_SPOLY_TEST |
---|
319 | |
---|
320 | for (int dz=0;dz<=c->n;dz++){ |
---|
321 | if (dz==c->n) { |
---|
322 | //have found not head reducing pair |
---|
323 | i=i_con[m]; |
---|
324 | j=j_con[n]; |
---|
325 | p_Delete(&short_s,c->r); |
---|
326 | p_Delete(&lm,c->r); |
---|
327 | omfree(i_con); |
---|
328 | omfree(j_con); |
---|
329 | |
---|
330 | return; |
---|
331 | } |
---|
332 | if (p_LmDivisibleBy(c->S->m[dz],short_s,c->r)) break; |
---|
333 | } |
---|
334 | #endif |
---|
335 | int comp_deg(pFDeg(short_s)); |
---|
336 | p_Delete(&short_s,c->r); |
---|
337 | if ((comp_deg<curr_deg) |
---|
338 | || |
---|
339 | ((comp_deg==curr_deg) && |
---|
340 | (c->misses[i]+c->misses[j] |
---|
341 | <= |
---|
342 | c->misses[i_con[m]]+c->misses[j_con[n]]))) |
---|
343 | // if ((comp_deg<curr_deg) |
---|
344 | // || |
---|
345 | // ((comp_deg==curr_deg) && |
---|
346 | // (c->lengths[i]+c->lengths[j] |
---|
347 | // <= |
---|
348 | // c->lengths[i_con[m]]+c->lengths[j_con[n]]))) |
---|
349 | |
---|
350 | { |
---|
351 | curr_deg=comp_deg; |
---|
352 | i=i_con[m]; |
---|
353 | j=j_con[n]; |
---|
354 | } |
---|
355 | } |
---|
356 | } |
---|
357 | p_Delete(&lm,c->r); |
---|
358 | omfree(i_con); |
---|
359 | omfree(j_con); |
---|
360 | return; |
---|
361 | } |
---|
362 | int* make_connections(int from, poly bound, calc_dat* c) |
---|
363 | { |
---|
364 | ideal I=c->S; |
---|
365 | int s=pFDeg(bound); |
---|
366 | int* cans=(int*) omalloc(c->n*sizeof(int)); |
---|
367 | int* connected=(int*) omalloc(c->n*sizeof(int)); |
---|
368 | int cans_length=0; |
---|
369 | connected[0]=from; |
---|
370 | int connected_length=1; |
---|
371 | long neg_bounds_short= ~p_GetShortExpVector(bound,c->r); |
---|
372 | for (int i=0;i<c->n;i++){ |
---|
373 | if (c->T_deg[i]>s) continue; |
---|
374 | if (i!=from){ |
---|
375 | if(p_LmShortDivisibleBy(I->m[i],c->short_Exps[i],bound,neg_bounds_short,c->r)){ |
---|
376 | cans[cans_length]=i; |
---|
377 | cans_length++; |
---|
378 | } |
---|
379 | } |
---|
380 | } |
---|
381 | int not_yet_found=cans_length; |
---|
382 | int con_checked=0; |
---|
383 | int pos; |
---|
384 | while((not_yet_found>0) && (con_checked<connected_length)){ |
---|
385 | pos=connected[con_checked]; |
---|
386 | for(int i=0;i<cans_length;i++){ |
---|
387 | if (cans[i]<0) continue; |
---|
388 | if (has_t_rep(pos,cans[i],c)){ |
---|
389 | |
---|
390 | connected[connected_length]=cans[i]; |
---|
391 | connected_length++; |
---|
392 | cans[i]=-1; |
---|
393 | --not_yet_found; |
---|
394 | |
---|
395 | } |
---|
396 | } |
---|
397 | con_checked++; |
---|
398 | } |
---|
399 | if (connected_length<c->n){ |
---|
400 | connected[connected_length]=-1; |
---|
401 | } |
---|
402 | omfree(cans); |
---|
403 | return connected; |
---|
404 | } |
---|
405 | int* make_connections(int from, int to, poly bound, calc_dat* c) |
---|
406 | { |
---|
407 | ideal I=c->S; |
---|
408 | int s=pFDeg(bound); |
---|
409 | int* cans=(int*) omalloc(c->n*sizeof(int)); |
---|
410 | int* connected=(int*) omalloc(c->n*sizeof(int)); |
---|
411 | cans[0]=to; |
---|
412 | int cans_length=1; |
---|
413 | connected[0]=from; |
---|
414 | int last_cans_pos=-1; |
---|
415 | int connected_length=1; |
---|
416 | long neg_bounds_short= ~p_GetShortExpVector(bound,c->r); |
---|
417 | // for (int i=0;i<c->n;i++){ |
---|
418 | // if (c->T_deg[i]>s) continue; |
---|
419 | // if (i!=from){ |
---|
420 | // if(p_LmShortDivisibleBy(I->m[i],c->short_Exps[i],bound,neg_bounds_short,c->r)){ |
---|
421 | // cans[cans_length]=i; |
---|
422 | // cans_length++; |
---|
423 | // } |
---|
424 | // } |
---|
425 | // } |
---|
426 | int not_yet_found=cans_length; |
---|
427 | int con_checked=0; |
---|
428 | int pos; |
---|
429 | BOOLEAN can_find_more=TRUE; |
---|
430 | while(((not_yet_found>0) && (con_checked<connected_length))||can_find_more){ |
---|
431 | if ((con_checked<connected_length)&& (not_yet_found>0)){ |
---|
432 | pos=connected[con_checked]; |
---|
433 | for(int i=0;i<cans_length;i++){ |
---|
434 | if (cans[i]<0) continue; |
---|
435 | if (has_t_rep(pos,cans[i],c)){ |
---|
436 | |
---|
437 | connected[connected_length]=cans[i]; |
---|
438 | connected_length++; |
---|
439 | cans[i]=-1; |
---|
440 | --not_yet_found; |
---|
441 | |
---|
442 | if (connected[connected_length-1]==to){ |
---|
443 | if (connected_length<c->n){ |
---|
444 | connected[connected_length]=-1; |
---|
445 | } |
---|
446 | |
---|
447 | omfree(cans); |
---|
448 | return connected; |
---|
449 | } |
---|
450 | } |
---|
451 | } |
---|
452 | con_checked++; |
---|
453 | } else { |
---|
454 | |
---|
455 | for(last_cans_pos++;last_cans_pos<=c->n;last_cans_pos++){ |
---|
456 | if (last_cans_pos==c->n){ |
---|
457 | if (connected_length<c->n){ |
---|
458 | connected[connected_length]=-1; |
---|
459 | } |
---|
460 | omfree(cans); |
---|
461 | return connected; |
---|
462 | } |
---|
463 | if ((last_cans_pos==from)||(last_cans_pos==to)) |
---|
464 | continue; |
---|
465 | if(p_LmShortDivisibleBy(I->m[last_cans_pos],c->short_Exps[last_cans_pos],bound,neg_bounds_short,c->r)){ |
---|
466 | cans[cans_length]=last_cans_pos; |
---|
467 | cans_length++; |
---|
468 | break; |
---|
469 | } |
---|
470 | } |
---|
471 | not_yet_found++; |
---|
472 | for (int i=0;i<con_checked;i++){ |
---|
473 | if (has_t_rep(connected[i],last_cans_pos,c)){ |
---|
474 | |
---|
475 | connected[connected_length]=last_cans_pos; |
---|
476 | connected_length++; |
---|
477 | cans[cans_length-1]=-1; |
---|
478 | |
---|
479 | --not_yet_found; |
---|
480 | if (connected[connected_length-1]==to){ |
---|
481 | if (connected_length<c->n){ |
---|
482 | connected[connected_length]=-1; |
---|
483 | } |
---|
484 | |
---|
485 | omfree(cans); |
---|
486 | return connected; |
---|
487 | } |
---|
488 | break; |
---|
489 | } |
---|
490 | |
---|
491 | } |
---|
492 | } |
---|
493 | } |
---|
494 | if (connected_length<c->n){ |
---|
495 | connected[connected_length]=-1; |
---|
496 | } |
---|
497 | |
---|
498 | omfree(cans); |
---|
499 | return connected; |
---|
500 | } |
---|
501 | #ifdef HEAD_BIN |
---|
502 | static inline poly p_MoveHead(poly p, omBin b) |
---|
503 | { |
---|
504 | poly np; |
---|
505 | omTypeAllocBin(poly, np, b); |
---|
506 | memmove(np, p, b->sizeW*sizeof(long)); |
---|
507 | omFreeBinAddr(p); |
---|
508 | return np; |
---|
509 | } |
---|
510 | #endif |
---|
511 | int init_red_phase1(calc_dat* c, int i, int j){ |
---|
512 | int counter; |
---|
513 | for(counter=0;(counter<PAR_N)||(c->work_on[i].is_free);counter++){} |
---|
514 | assume(counter<PAR_N); |
---|
515 | |
---|
516 | int pos=counter; |
---|
517 | c->work_on[pos].is_free=FALSE; |
---|
518 | c->work_on[pos].i=i; |
---|
519 | c->work_on[pos].j=j; |
---|
520 | return pos; |
---|
521 | } |
---|
522 | void init_red_spoly_phase2(calc_dat* c,int pos){ |
---|
523 | poly h=ksOldCreateSpoly(c->S->m[c->work_on[pos].i], c->S->m[c->work_on[pos].j], NULL, c->r); |
---|
524 | if (h==NULL){ |
---|
525 | c->work_on[pos].is_free=TRUE; |
---|
526 | return; |
---|
527 | } |
---|
528 | if (c->work_on[pos].P!=NULL) |
---|
529 | delete c->work_on[pos].P; |
---|
530 | c->work_on[pos].P=new LObject(h); |
---|
531 | |
---|
532 | |
---|
533 | int len=pLength(h); |
---|
534 | c->work_on[pos].len_upper_bound=len; |
---|
535 | c->work_on[pos].P=new LObject(h); |
---|
536 | c->work_on[pos].P->SetShortExpVector(); |
---|
537 | c->work_on[pos].P->bucket = kBucketCreate(currRing); |
---|
538 | kBucketInit(c->work_on[pos].P->bucket,c->work_on[pos].P->p,len /*pLength(P.p)*/); |
---|
539 | |
---|
540 | }; |
---|
541 | void initial_data(calc_dat* c){ |
---|
542 | void* h; |
---|
543 | int i,j; |
---|
544 | c->work_on=(redNF_inf*) omalloc(PAR_N*sizeof(redNF_inf)); |
---|
545 | int counter; |
---|
546 | for(counter=0;counter<PAR_N;counter++){ |
---|
547 | c->work_on[counter].is_free=TRUE; |
---|
548 | } |
---|
549 | c->misses_series=0; |
---|
550 | c->soon_free=NULL; |
---|
551 | c->misses_counter=0; |
---|
552 | c->max_misses=0; |
---|
553 | c->normal_forms=0; |
---|
554 | c->current_degree=1; |
---|
555 | c->skipped_pairs=0; |
---|
556 | int n=c->S->idelems(); |
---|
557 | c->n=n; |
---|
558 | c->T_deg=(int*) omalloc(n*sizeof(int)); |
---|
559 | c->continue_i=0; |
---|
560 | c->continue_j=0; |
---|
561 | c->skipped_i=-1; |
---|
562 | #ifdef HEAD_BIN |
---|
563 | c->HeadBin=omGetSpecBin(POLYSIZE + (currRing->ExpL_Size)*sizeof(long)); |
---|
564 | #endif |
---|
565 | /* omUnGetSpecBin(&(c->HeadBin)); */ |
---|
566 | h=omalloc(n*sizeof(char*)); |
---|
567 | if (h!=NULL) |
---|
568 | c->states=(char**) h; |
---|
569 | else |
---|
570 | exit(1); |
---|
571 | c->misses=(int*) omalloc(n*sizeof(int)); |
---|
572 | c->deg=(int **) omalloc(n*sizeof(int*)); |
---|
573 | h=omalloc(n*sizeof(int)); |
---|
574 | if (h!=NULL) |
---|
575 | c->lengths=(int*) h; |
---|
576 | else |
---|
577 | exit(1); |
---|
578 | |
---|
579 | h=omalloc(n*sizeof(int)); |
---|
580 | if (h!=NULL) |
---|
581 | c->rep=(int*) h; |
---|
582 | else |
---|
583 | exit(1); |
---|
584 | c->short_Exps=(long*) omalloc(n*sizeof(long)); |
---|
585 | for (i=0;i<n;i++) |
---|
586 | { |
---|
587 | #ifdef HEAD_BIN |
---|
588 | c->S->m[i]=p_MoveHead(c->S->m[i],c->HeadBin); |
---|
589 | #endif |
---|
590 | c->T_deg[i]=pFDeg(c->S->m[i]); |
---|
591 | c->lengths[i]=pLength(c->S->m[i]); |
---|
592 | c->misses[i]=0; |
---|
593 | c->states[i]=(char *)omAlloc((i+1)*sizeof(char)); |
---|
594 | c->deg[i]=(int*) omAlloc((i+1)*sizeof(int)); |
---|
595 | for (j=0;j<i;j++){ |
---|
596 | //check product criterion |
---|
597 | if (pHasNotCF(c->S->m[i],c->S->m[j])){ |
---|
598 | c->states[i][j]=HASTREP; |
---|
599 | } else { |
---|
600 | c->states[i][j]=UNCALCULATED; |
---|
601 | } |
---|
602 | c->deg[i][j]=pLcmDeg(c->S->m[i],c->S->m[j]); |
---|
603 | } |
---|
604 | if ((c->lengths[i]==1) && (c->lengths[j]==1)) |
---|
605 | c->states[i][j]=HASTREP; |
---|
606 | c->rep[i]=i; |
---|
607 | c->short_Exps[i]=p_GetShortExpVector(c->S->m[i],c->r); |
---|
608 | |
---|
609 | } |
---|
610 | |
---|
611 | |
---|
612 | c->strat=new skStrategy; |
---|
613 | c->strat->syzComp = 0; |
---|
614 | initBuchMoraCrit(c->strat); |
---|
615 | initBuchMoraPos(c->strat); |
---|
616 | c->strat->initEcart = initEcartBBA; |
---|
617 | c->strat->enterS = enterSBba; |
---|
618 | c->strat->sl = -1; |
---|
619 | /* initS(c->S,NULL,c->strat); */ |
---|
620 | /* intS start: */ |
---|
621 | i=((i+IDELEMS(c->S)+15)/16)*16; |
---|
622 | c->strat->ecartS=(intset)omAlloc(i*sizeof(int)); /*initec(i);*/ |
---|
623 | c->strat->sevS=(unsigned long*)omAlloc0(i*sizeof(unsigned long)); |
---|
624 | /*initsevS(i);*/ |
---|
625 | c->strat->S_2_R=(int*)omAlloc0(i*sizeof(int));/*initS_2_R(i);*/ |
---|
626 | c->strat->fromQ=NULL; |
---|
627 | c->strat->Shdl=idInit(i,1); |
---|
628 | c->strat->S=c->strat->Shdl->m; |
---|
629 | c->strat->lenS=(int*)omAlloc0(i*sizeof(int)); |
---|
630 | for (i=0; i<IDELEMS(c->S); i++) |
---|
631 | { |
---|
632 | int pos; |
---|
633 | assume (c->S->m[i]!=NULL); |
---|
634 | LObject h; |
---|
635 | h.p = c->S->m[i]; |
---|
636 | h.pNorm(); |
---|
637 | c->strat->initEcart(&h); |
---|
638 | assume(c->lengths[i]==pLength(h.p)); |
---|
639 | if (c->strat->sl==-1) pos=0; |
---|
640 | else pos = simple_posInS(c->strat,h.p,c->lengths[i]); |
---|
641 | h.sev = pGetShortExpVector(h.p); |
---|
642 | c->strat->enterS(h,pos,c->strat); |
---|
643 | c->strat->lenS[pos]=c->lengths[i]; |
---|
644 | } |
---|
645 | //c->strat->lenS=(int*)omAlloc0(IDELEMS(c->strat->Shdl)*sizeof(int)); |
---|
646 | //for (i=c->strat->sl;i>=0;i--) |
---|
647 | //{ |
---|
648 | // pNorm(c->strat->S[i]); |
---|
649 | // c->strat->lenS[i]=pLength(c->strat->S[i]); |
---|
650 | //} |
---|
651 | /* initS end */ |
---|
652 | } |
---|
653 | int simple_posInS (kStrategy strat, poly p,int len) |
---|
654 | { |
---|
655 | if(strat->sl==-1) return 0; |
---|
656 | polyset set=strat->S; |
---|
657 | intset setL=strat->lenS; |
---|
658 | int length=strat->sl; |
---|
659 | int i; |
---|
660 | int an = 0; |
---|
661 | int en= length; |
---|
662 | |
---|
663 | if ((len>setL[length]) |
---|
664 | || ((len==setL[length]) && (pLmCmp(set[length],p)== -1))) |
---|
665 | return length+1; |
---|
666 | |
---|
667 | loop |
---|
668 | { |
---|
669 | if (an >= en-1) |
---|
670 | { |
---|
671 | if ((len<setL[an]) |
---|
672 | || ((len==setL[length]) && (pLmCmp(set[an],p) == 1))) return an; |
---|
673 | return en; |
---|
674 | } |
---|
675 | i=(an+en) / 2; |
---|
676 | if ((len<setL[i]) |
---|
677 | || ((len==setL[i]) && (pLmCmp(set[i],p) == 1))) en=i; |
---|
678 | //else if ((len>setL[i]) |
---|
679 | //|| ((len==setL[i]) && (pLmCmp(set[i],p) == -1))) an=i; |
---|
680 | else an=i; |
---|
681 | } |
---|
682 | } |
---|
683 | /*2 |
---|
684 | *if the leading term of p |
---|
685 | *divides the leading term of some S[i] it will be canceled |
---|
686 | */ |
---|
687 | static inline void clearS (poly p, unsigned long p_sev,int l, int* at, int* k, |
---|
688 | kStrategy strat) |
---|
689 | { |
---|
690 | assume(p_sev == pGetShortExpVector(p)); |
---|
691 | if (!pLmShortDivisibleBy(p,p_sev, strat->S[*at], ~ strat->sevS[*at])) return; |
---|
692 | if (l>=strat->lenS[*at]) return; |
---|
693 | PrintS("!");mflush(); |
---|
694 | //pDelete(&strat->S[*at]); |
---|
695 | deleteInS((*at),strat); |
---|
696 | (*at)--; |
---|
697 | (*k)--; |
---|
698 | // assume(lenS_correct(strat)); |
---|
699 | } |
---|
700 | void add_to_basis(poly h, int i_pos, int j_pos,calc_dat* c) |
---|
701 | { |
---|
702 | // BOOLEAN corr=lenS_correct(c->strat); |
---|
703 | BOOLEAN R_found=FALSE; |
---|
704 | void* hp; |
---|
705 | PrintS("s"); |
---|
706 | ++(c->n); |
---|
707 | ++(c->S->ncols); |
---|
708 | int i,j; |
---|
709 | i=c->n-1; |
---|
710 | c->T_deg=(int*) omrealloc(c->T_deg,c->n*sizeof(int)); |
---|
711 | c->T_deg[i]=pFDeg(h); |
---|
712 | hp=omrealloc(c->rep, c->n *sizeof(int)); |
---|
713 | if (hp!=NULL){ |
---|
714 | c->rep=(int*) hp; |
---|
715 | } else { |
---|
716 | exit(1); |
---|
717 | } |
---|
718 | c->short_Exps=(long *) omrealloc(c->short_Exps ,c->n*sizeof(long)); |
---|
719 | |
---|
720 | hp=omrealloc(c->lengths, c->n *sizeof(int)); |
---|
721 | if (hp!=NULL){ |
---|
722 | c->lengths=(int*) hp; |
---|
723 | } else { |
---|
724 | exit(1); |
---|
725 | } |
---|
726 | c->misses=(int*) omrealloc(c->misses,c->n*sizeof(int)); |
---|
727 | c->misses[i]=0; |
---|
728 | c->lengths[i]=pLength(h); |
---|
729 | hp=omrealloc(c->states, c->n * sizeof(char*)); |
---|
730 | if (hp!=NULL){ |
---|
731 | c->states=(char**) hp; |
---|
732 | } else { |
---|
733 | exit(1); |
---|
734 | } |
---|
735 | c->deg=(int**) omrealloc(c->deg, c->n * sizeof(int*)); |
---|
736 | c->rep[i]=i; |
---|
737 | hp=omalloc(i*sizeof(char)); |
---|
738 | if (hp!=NULL){ |
---|
739 | c->states[i]=(char*) hp; |
---|
740 | } else { |
---|
741 | exit(1); |
---|
742 | } |
---|
743 | c->deg[i]=(int*) omalloc(i*sizeof(int)); |
---|
744 | hp=omrealloc(c->S->m,c->n*sizeof(poly)); |
---|
745 | if (hp!=NULL){ |
---|
746 | c->S->m=(poly*) hp; |
---|
747 | } else { |
---|
748 | exit(1); |
---|
749 | } |
---|
750 | c->S->m[i]=h; |
---|
751 | c->short_Exps[i]=p_GetShortExpVector(h,c->r); |
---|
752 | for (j=0;j<i;j++){ |
---|
753 | c->deg[i][j]=pLcmDeg(c->S->m[i],c->S->m[j]); |
---|
754 | if (c->rep[j]==j){ |
---|
755 | //check product criterion |
---|
756 | |
---|
757 | c->states[i][j]=UNCALCULATED; |
---|
758 | |
---|
759 | |
---|
760 | //lies I[i] under I[j] ? |
---|
761 | if(p_LmShortDivisibleBy(c->S->m[i],c->short_Exps[i],c->S->m[j],~(c->short_Exps[j]),c->r)){ |
---|
762 | c->rep[j]=i; |
---|
763 | PrintS("R"); R_found=TRUE; |
---|
764 | if((i_pos>=0) && (j_pos>=0)){ |
---|
765 | c->misses[i_pos]--; |
---|
766 | c->misses[j_pos]--; |
---|
767 | } |
---|
768 | for(int z=0;z<j;z++){ |
---|
769 | if (c->states[j][z]==UNCALCULATED){ |
---|
770 | c->states[j][z]=UNIMPORTANT; |
---|
771 | } |
---|
772 | } |
---|
773 | for(int z=j+1;z<i;z++){ |
---|
774 | if (c->states[z][j]==UNCALCULATED){ |
---|
775 | c->states[z][j]=UNIMPORTANT; |
---|
776 | } |
---|
777 | } |
---|
778 | } |
---|
779 | } |
---|
780 | else { |
---|
781 | c->states[i][j]=UNIMPORTANT; |
---|
782 | } |
---|
783 | if ((c->lengths[i]==1) && (c->lengths[j]==1)) |
---|
784 | c->states[i][j]=HASTREP; |
---|
785 | else if (pHasNotCF(c->S->m[i],c->S->m[j])) |
---|
786 | c->states[i][j]=HASTREP; |
---|
787 | |
---|
788 | } |
---|
789 | if (c->skipped_i>0){ |
---|
790 | c->continue_i=c->skipped_i; |
---|
791 | c->continue_j=0; |
---|
792 | c->skipped_i=-1; |
---|
793 | } |
---|
794 | |
---|
795 | //i=posInS(c->strat,c->strat->sl,h,0 /*ecart*/); |
---|
796 | i=simple_posInS(c->strat,h,c->lengths[c->n-1]); |
---|
797 | |
---|
798 | LObject P; memset(&P,0,sizeof(P)); |
---|
799 | P.tailRing=c->r; |
---|
800 | P.p=h; /*p_Copy(h,c->r);*/ |
---|
801 | P.FDeg=pFDeg(P.p,c->r); |
---|
802 | if (!rField_is_Zp(c->r)) pCleardenom(P.p); |
---|
803 | //enterT(P,c->strat,-1); |
---|
804 | c->strat->enterS(P,i,c->strat); |
---|
805 | c->strat->lenS[i]=/*pLength(c->strat->S[i]);*/ c->lengths[c->n-1]; |
---|
806 | pNorm(c->strat->S[i]); |
---|
807 | if (0 /*R_found && (i<c->strat->sl)*/) |
---|
808 | { |
---|
809 | i++; |
---|
810 | unsigned long h_sev = pGetShortExpVector(h); |
---|
811 | loop |
---|
812 | { |
---|
813 | if (i>c->strat->sl) break; |
---|
814 | clearS(h,h_sev,c->lengths[c->n-1], &i,&(c->strat->sl),c->strat); |
---|
815 | i++; |
---|
816 | } |
---|
817 | } |
---|
818 | if (c->lengths[c->n-1]==1) |
---|
819 | shorten_tails(c,c->S->m[c->n-1]); |
---|
820 | // if (corr){ |
---|
821 | |
---|
822 | // corr=lenS_correct(c->strat); |
---|
823 | // if(!corr){ |
---|
824 | // PrintS("korupted in shorten tails"); |
---|
825 | // } |
---|
826 | // } |
---|
827 | //you should really update c->lengths, c->strat->lenS, and the oder of polys in strat if you sort after lengths |
---|
828 | |
---|
829 | //for(i=c->strat->sl; i>0;i--) |
---|
830 | // if(c->strat->lenS[i]<c->strat->lenS[i-1]) printf("fehler bei %d\n",i); |
---|
831 | } |
---|
832 | #if 0 |
---|
833 | static poly redNF (poly h,kStrategy strat) |
---|
834 | { |
---|
835 | int j = 0; |
---|
836 | int z = 3; |
---|
837 | unsigned long not_sev; |
---|
838 | |
---|
839 | if (0 > strat->sl) |
---|
840 | { |
---|
841 | return h; |
---|
842 | } |
---|
843 | not_sev = ~ pGetShortExpVector(h); |
---|
844 | loop |
---|
845 | { |
---|
846 | if (pLmShortDivisibleBy(strat->S[j], strat->sevS[j], h, not_sev)) |
---|
847 | { |
---|
848 | //if (strat->interpt) test_int_std(strat->kIdeal); |
---|
849 | /*- compute the s-polynomial -*/ |
---|
850 | #ifdef KDEBUG |
---|
851 | if (TEST_OPT_DEBUG) |
---|
852 | { |
---|
853 | PrintS("red:"); |
---|
854 | wrp(h); |
---|
855 | PrintS(" with "); |
---|
856 | wrp(strat->S[j]); |
---|
857 | } |
---|
858 | #endif |
---|
859 | h = ksOldSpolyRed(strat->S[j],h,strat->kNoether); |
---|
860 | #ifdef KDEBUG |
---|
861 | if (TEST_OPT_DEBUG) |
---|
862 | { |
---|
863 | PrintS("\nto:"); |
---|
864 | wrp(h); |
---|
865 | PrintLn(); |
---|
866 | } |
---|
867 | #endif |
---|
868 | if (h == NULL) return NULL; |
---|
869 | z++; |
---|
870 | if (z>=10) |
---|
871 | { |
---|
872 | z=0; |
---|
873 | pNormalize(h); |
---|
874 | } |
---|
875 | /*- try to reduce the s-polynomial -*/ |
---|
876 | j = 0; |
---|
877 | not_sev = ~ pGetShortExpVector(h); |
---|
878 | } |
---|
879 | else |
---|
880 | { |
---|
881 | if (j >= strat->sl) return h; |
---|
882 | j++; |
---|
883 | } |
---|
884 | } |
---|
885 | } |
---|
886 | #else |
---|
887 | |
---|
888 | static poly redNF2 (poly h,calc_dat* c , int &len) |
---|
889 | { |
---|
890 | len=0; |
---|
891 | if (h==NULL) return NULL; |
---|
892 | int j; |
---|
893 | |
---|
894 | kStrategy strat=c->strat; |
---|
895 | len=pLength(h); |
---|
896 | int len_upper_bound=len; |
---|
897 | if (0 > strat->sl) |
---|
898 | { |
---|
899 | return h; |
---|
900 | } |
---|
901 | LObject P(h); |
---|
902 | P.SetShortExpVector(); |
---|
903 | P.bucket = kBucketCreate(currRing); |
---|
904 | // BOOLEAN corr=lenS_correct(strat); |
---|
905 | kBucketInit(P.bucket,P.p,len /*pLength(P.p)*/); |
---|
906 | //int max_pos=simple_posInS(strat,P.p); |
---|
907 | loop |
---|
908 | { |
---|
909 | // if (corr){ |
---|
910 | |
---|
911 | // corr=lenS_correct(strat); |
---|
912 | // if(!corr){ |
---|
913 | // PrintS("korupt"); |
---|
914 | // } |
---|
915 | // } |
---|
916 | int compare_bound; |
---|
917 | compare_bound=bucket_guess(P.bucket); |
---|
918 | len_upper_bound=min(compare_bound,len_upper_bound); |
---|
919 | j=kFindDivisibleByInS(strat->S,strat->sevS,strat->sl,&P); |
---|
920 | if (j>=0) |
---|
921 | { |
---|
922 | poly sec_copy=NULL; |
---|
923 | //pseudo code |
---|
924 | BOOLEAN must_expand=FALSE; |
---|
925 | BOOLEAN must_replace_in_basis=(len_upper_bound<strat->lenS[j]);//first test |
---|
926 | if (must_replace_in_basis) |
---|
927 | { |
---|
928 | //second test |
---|
929 | if (pLmEqual(P.p,strat->S[j])) |
---|
930 | { |
---|
931 | PrintS("b"); |
---|
932 | sec_copy=kBucketClear(P.bucket); |
---|
933 | kBucketInit(P.bucket,pCopy(sec_copy),pLength(sec_copy)); |
---|
934 | } |
---|
935 | else |
---|
936 | { |
---|
937 | must_replace_in_basis=FALSE; |
---|
938 | if ((len_upper_bound==1) |
---|
939 | ||(len_upper_bound==2) |
---|
940 | ||(len_upper_bound<strat->lenS[j]/2)) |
---|
941 | { |
---|
942 | PrintS("e"); |
---|
943 | sec_copy=kBucketClear(P.bucket); |
---|
944 | kBucketInit(P.bucket,pCopy(sec_copy),pLength(sec_copy)); |
---|
945 | must_expand=TRUE; |
---|
946 | } |
---|
947 | } |
---|
948 | } |
---|
949 | // must_expand=FALSE; |
---|
950 | // must_replace_in_basis=FALSE; |
---|
951 | nNormalize(pGetCoeff(P.p)); |
---|
952 | #ifdef KDEBUG |
---|
953 | if (TEST_OPT_DEBUG) |
---|
954 | { |
---|
955 | PrintS("red:"); |
---|
956 | wrp(h); |
---|
957 | PrintS(" with "); |
---|
958 | wrp(strat->S[j]); |
---|
959 | } |
---|
960 | #endif |
---|
961 | len_upper_bound=len_upper_bound+strat->lenS[j]-2; |
---|
962 | number coef=kBucketPolyRed(P.bucket,strat->S[j], |
---|
963 | strat->lenS[j]/*pLength(strat->S[j])*/, |
---|
964 | strat->kNoether); |
---|
965 | nDelete(&coef); |
---|
966 | h = kBucketGetLm(P.bucket); |
---|
967 | |
---|
968 | if (must_replace_in_basis){ |
---|
969 | int pos_in_c=-1; |
---|
970 | poly p=strat->S[j]; |
---|
971 | int z; |
---|
972 | |
---|
973 | int new_length=pLength(sec_copy); |
---|
974 | Print("%i",strat->lenS[j]-new_length); |
---|
975 | len_upper_bound=new_length +strat->lenS[j]-2;//old entries length |
---|
976 | int new_pos=simple_posInS(c->strat,strat->S[j],new_length);//hack |
---|
977 | |
---|
978 | // p=NULL; |
---|
979 | for (z=c->n;z;z--) |
---|
980 | { |
---|
981 | if(p==c->S->m[z-1]) |
---|
982 | { |
---|
983 | |
---|
984 | |
---|
985 | pos_in_c=z-1; |
---|
986 | |
---|
987 | break; |
---|
988 | } |
---|
989 | } |
---|
990 | if (z<=0){ |
---|
991 | //not in c->S |
---|
992 | //LEAVE |
---|
993 | deleteInS(j,c->strat); |
---|
994 | //ENTER |
---|
995 | int mlength=pLength(sec_copy); |
---|
996 | int mi=simple_posInS(c->strat,sec_copy,mlength); |
---|
997 | |
---|
998 | LObject mP; memset(&mP,0,sizeof(mP)); |
---|
999 | mP.tailRing=c->r; |
---|
1000 | mP.p=sec_copy; /*p_Copy(h,c->r);*/ |
---|
1001 | mP.FDeg=pFDeg(mP.p,c->r); |
---|
1002 | if (!rField_is_Zp(c->r)) pCleardenom(mP.p); |
---|
1003 | //enterT(P,c->strat,-1); |
---|
1004 | c->strat->enterS(mP,mi,c->strat); |
---|
1005 | c->strat->lenS[mi]=mlength; |
---|
1006 | pNorm(c->strat->S[mi]); |
---|
1007 | } |
---|
1008 | else { |
---|
1009 | //shorten_tails may alter position (not the length, even not by recursion in GLOBAL case) |
---|
1010 | |
---|
1011 | strat->S[j]=sec_copy; |
---|
1012 | c->strat->lenS[j]=new_length; |
---|
1013 | pDelete(&p); |
---|
1014 | |
---|
1015 | // replace_quietly(c,j,sec_copy); |
---|
1016 | // have to do many additional things for consistency |
---|
1017 | { |
---|
1018 | |
---|
1019 | |
---|
1020 | |
---|
1021 | |
---|
1022 | int old_pos=j; |
---|
1023 | new_pos=min(old_pos, new_pos); |
---|
1024 | assume(new_pos<=old_pos); |
---|
1025 | |
---|
1026 | |
---|
1027 | c->strat->lenS[old_pos]=new_length; |
---|
1028 | int i=0; |
---|
1029 | for(i=new_pos;i<old_pos;i++){ |
---|
1030 | if (strat->lenS[i]<=new_length) |
---|
1031 | new_pos++; |
---|
1032 | else |
---|
1033 | break; |
---|
1034 | } |
---|
1035 | if (new_pos<old_pos) |
---|
1036 | move_forward_in_S(old_pos,new_pos,c->strat); |
---|
1037 | |
---|
1038 | c->S->m[pos_in_c]=sec_copy; |
---|
1039 | |
---|
1040 | c->lengths[pos_in_c]=new_length; |
---|
1041 | if (new_length==1) |
---|
1042 | { |
---|
1043 | int i; |
---|
1044 | for ( i=0;i<pos_in_c;i++) |
---|
1045 | { |
---|
1046 | if (c->lengths[i]==1) |
---|
1047 | c->states[pos_in_c][i]=HASTREP; |
---|
1048 | } |
---|
1049 | for ( i=z;i<c->n;i++){ |
---|
1050 | if (c->lengths[i]==1) |
---|
1051 | c->states[i][pos_in_c]=HASTREP; |
---|
1052 | } |
---|
1053 | shorten_tails(c,sec_copy); |
---|
1054 | } |
---|
1055 | } |
---|
1056 | } |
---|
1057 | } |
---|
1058 | if(must_expand){ |
---|
1059 | //i=posInS(c->strat,c->strat->sl,h,0 /*ecart*/); |
---|
1060 | int mlength=pLength(sec_copy); |
---|
1061 | int mi=simple_posInS(c->strat,sec_copy,mlength); |
---|
1062 | |
---|
1063 | LObject mP; memset(&mP,0,sizeof(mP)); |
---|
1064 | mP.tailRing=c->r; |
---|
1065 | mP.p=sec_copy; /*p_Copy(h,c->r);*/ |
---|
1066 | mP.FDeg=pFDeg(mP.p,c->r); |
---|
1067 | if (!rField_is_Zp(c->r)) pCleardenom(mP.p); |
---|
1068 | //enterT(P,c->strat,-1); |
---|
1069 | c->strat->enterS(mP,mi,c->strat); |
---|
1070 | c->strat->lenS[mi]=mlength; |
---|
1071 | pNorm(c->strat->S[mi]); |
---|
1072 | |
---|
1073 | } |
---|
1074 | if (h==NULL) return NULL; |
---|
1075 | P.p=h; |
---|
1076 | P.t_p=NULL; |
---|
1077 | P.SetShortExpVector(); |
---|
1078 | #ifdef KDEBUG |
---|
1079 | if (TEST_OPT_DEBUG) |
---|
1080 | { |
---|
1081 | PrintS("\nto:"); |
---|
1082 | wrp(h); |
---|
1083 | PrintLn(); |
---|
1084 | } |
---|
1085 | #endif |
---|
1086 | } |
---|
1087 | else |
---|
1088 | { |
---|
1089 | kBucketClear(P.bucket,&(P.p),&len); |
---|
1090 | kBucketDestroy(&P.bucket); |
---|
1091 | pNormalize(P.p); |
---|
1092 | return P.p; |
---|
1093 | } |
---|
1094 | } |
---|
1095 | } |
---|
1096 | static poly redNF (poly h,kStrategy strat, int &len) |
---|
1097 | { |
---|
1098 | len=0; |
---|
1099 | if (h==NULL) return NULL; |
---|
1100 | int j; |
---|
1101 | |
---|
1102 | len=pLength(h); |
---|
1103 | if (0 > strat->sl) |
---|
1104 | { |
---|
1105 | return h; |
---|
1106 | } |
---|
1107 | LObject P(h); |
---|
1108 | P.SetShortExpVector(); |
---|
1109 | P.bucket = kBucketCreate(currRing); |
---|
1110 | kBucketInit(P.bucket,P.p,len /*pLength(P.p)*/); |
---|
1111 | //int max_pos=simple_posInS(strat,P.p); |
---|
1112 | loop |
---|
1113 | { |
---|
1114 | j=kFindDivisibleByInS(strat->S,strat->sevS,strat->sl,&P); |
---|
1115 | if (j>=0) |
---|
1116 | { |
---|
1117 | nNormalize(pGetCoeff(P.p)); |
---|
1118 | #ifdef KDEBUG |
---|
1119 | if (TEST_OPT_DEBUG) |
---|
1120 | { |
---|
1121 | PrintS("red:"); |
---|
1122 | wrp(h); |
---|
1123 | PrintS(" with "); |
---|
1124 | wrp(strat->S[j]); |
---|
1125 | } |
---|
1126 | #endif |
---|
1127 | number coef=kBucketPolyRed(P.bucket,strat->S[j], |
---|
1128 | strat->lenS[j]/*pLength(strat->S[j])*/, |
---|
1129 | strat->kNoether); |
---|
1130 | nDelete(&coef); |
---|
1131 | h = kBucketGetLm(P.bucket); |
---|
1132 | if (h==NULL) return NULL; |
---|
1133 | P.p=h; |
---|
1134 | P.t_p=NULL; |
---|
1135 | P.SetShortExpVector(); |
---|
1136 | #ifdef KDEBUG |
---|
1137 | if (TEST_OPT_DEBUG) |
---|
1138 | { |
---|
1139 | PrintS("\nto:"); |
---|
1140 | wrp(h); |
---|
1141 | PrintLn(); |
---|
1142 | } |
---|
1143 | #endif |
---|
1144 | } |
---|
1145 | else |
---|
1146 | { |
---|
1147 | kBucketClear(P.bucket,&(P.p),&len); |
---|
1148 | kBucketDestroy(&P.bucket); |
---|
1149 | pNormalize(P.p); |
---|
1150 | return P.p; |
---|
1151 | } |
---|
1152 | } |
---|
1153 | } |
---|
1154 | #endif |
---|
1155 | #ifdef REDTAIL_S |
---|
1156 | poly redNFTail (poly h,const int sl,kStrategy strat, int len) |
---|
1157 | { |
---|
1158 | if (h==NULL) return NULL; |
---|
1159 | if (pNext(h)==NULL) return h; |
---|
1160 | pTest(h); |
---|
1161 | if (0 > sl) |
---|
1162 | return h; |
---|
1163 | |
---|
1164 | int j; |
---|
1165 | poly res=h; |
---|
1166 | poly act=res; |
---|
1167 | LObject P(pNext(h)); |
---|
1168 | pNext(res)=NULL; |
---|
1169 | P.bucket = kBucketCreate(currRing); |
---|
1170 | len--; |
---|
1171 | h=P.p; |
---|
1172 | if (len <=0) len=pLength(h); |
---|
1173 | kBucketInit(P.bucket,h /*P.p*/,len /*pLength(P.p)*/); |
---|
1174 | pTest(h); |
---|
1175 | loop |
---|
1176 | { |
---|
1177 | P.p=h; |
---|
1178 | P.t_p=NULL; |
---|
1179 | P.SetShortExpVector(); |
---|
1180 | loop |
---|
1181 | { |
---|
1182 | j=kFindDivisibleByInS(strat->S,strat->sevS,sl,&P); |
---|
1183 | if (j>=0) |
---|
1184 | { |
---|
1185 | #ifdef REDTAIL_PROT |
---|
1186 | PrintS("r"); |
---|
1187 | #endif |
---|
1188 | nNormalize(pGetCoeff(P.p)); |
---|
1189 | #ifdef KDEBUG |
---|
1190 | if (TEST_OPT_DEBUG) |
---|
1191 | { |
---|
1192 | PrintS("red tail:"); |
---|
1193 | wrp(h); |
---|
1194 | PrintS(" with "); |
---|
1195 | wrp(strat->S[j]); |
---|
1196 | } |
---|
1197 | #endif |
---|
1198 | number coef; |
---|
1199 | pTest(strat->S[j]); |
---|
1200 | coef=kBucketPolyRed(P.bucket,strat->S[j], |
---|
1201 | strat->lenS[j]/*pLength(strat->S[j])*/,strat->kNoether); |
---|
1202 | pMult_nn(res,coef); |
---|
1203 | nDelete(&coef); |
---|
1204 | h = kBucketGetLm(P.bucket); |
---|
1205 | pTest(h); |
---|
1206 | if (h==NULL) |
---|
1207 | { |
---|
1208 | #ifdef REDTAIL_PROT |
---|
1209 | PrintS(" "); |
---|
1210 | #endif |
---|
1211 | return res; |
---|
1212 | } |
---|
1213 | pTest(h); |
---|
1214 | P.p=h; |
---|
1215 | P.t_p=NULL; |
---|
1216 | P.SetShortExpVector(); |
---|
1217 | #ifdef KDEBUG |
---|
1218 | if (TEST_OPT_DEBUG) |
---|
1219 | { |
---|
1220 | PrintS("\nto tail:"); |
---|
1221 | wrp(h); |
---|
1222 | PrintLn(); |
---|
1223 | } |
---|
1224 | #endif |
---|
1225 | } |
---|
1226 | else |
---|
1227 | { |
---|
1228 | #ifdef REDTAIL_PROT |
---|
1229 | PrintS("n"); |
---|
1230 | #endif |
---|
1231 | break; |
---|
1232 | } |
---|
1233 | } /* end loop current mon */ |
---|
1234 | poly tmp=pHead(h /*kBucketGetLm(P.bucket)*/); |
---|
1235 | act->next=tmp;pIter(act); |
---|
1236 | poly tmp2=pHead(h); |
---|
1237 | pNeg(tmp2); |
---|
1238 | int ltmp2=1; |
---|
1239 | pTest(tmp2); |
---|
1240 | kBucket_Add_q(P.bucket, tmp2, <mp2); |
---|
1241 | |
---|
1242 | h = kBucketGetLm(P.bucket); |
---|
1243 | if (h==NULL) |
---|
1244 | { |
---|
1245 | #ifdef REDTAIL_PROT |
---|
1246 | PrintS(" "); |
---|
1247 | #endif |
---|
1248 | return res; |
---|
1249 | } |
---|
1250 | pTest(h); |
---|
1251 | } |
---|
1252 | } |
---|
1253 | #endif |
---|
1254 | |
---|
1255 | void do_this_spoly_stuff(int i,int j,calc_dat* c){ |
---|
1256 | poly f=c->S->m[i]; |
---|
1257 | poly g=c->S->m[j]; |
---|
1258 | poly h=ksOldCreateSpoly(f, g, NULL, c->r); |
---|
1259 | poly hr=NULL; |
---|
1260 | #ifdef FULLREDUCTIONS |
---|
1261 | if (h!=NULL) |
---|
1262 | { |
---|
1263 | int len; |
---|
1264 | |
---|
1265 | hr=redNF2(h,c,len); |
---|
1266 | // hr=redNF(h,c->strat,len); |
---|
1267 | |
---|
1268 | if (hr!=NULL) |
---|
1269 | #ifdef REDTAIL_S |
---|
1270 | hr = redNFTail(hr,c->strat->sl,c->strat,len); |
---|
1271 | #else |
---|
1272 | hr = redtailBba(hr,c->strat->sl,c->strat); |
---|
1273 | #endif |
---|
1274 | |
---|
1275 | } |
---|
1276 | #else |
---|
1277 | if (h!=NULL) |
---|
1278 | { |
---|
1279 | int len; |
---|
1280 | hr=redNF2(h,c,len); |
---|
1281 | } |
---|
1282 | #endif |
---|
1283 | c->normal_forms++; |
---|
1284 | if (hr==NULL) |
---|
1285 | { |
---|
1286 | PrintS("-"); |
---|
1287 | c->misses_counter++; |
---|
1288 | c->misses[i]++; |
---|
1289 | c->misses[j]++; |
---|
1290 | c->misses_series++; |
---|
1291 | } |
---|
1292 | else |
---|
1293 | { |
---|
1294 | c->misses_series=0; |
---|
1295 | #ifdef HEAD_BIN |
---|
1296 | hr=p_MoveHead(hr,c->HeadBin); |
---|
1297 | #endif |
---|
1298 | add_to_basis(hr, i,j,c); |
---|
1299 | } |
---|
1300 | } |
---|
1301 | |
---|
1302 | ideal t_rep_gb(ring r,ideal arg_I){ |
---|
1303 | ideal I_temp=idCopy(arg_I); //kInterRed(arg_I); |
---|
1304 | ideal I=idCompactify(I_temp); |
---|
1305 | idDelete(&I_temp); |
---|
1306 | calc_dat* c=(calc_dat*) omalloc(sizeof(calc_dat)); |
---|
1307 | c->r=currRing; |
---|
1308 | c->S=I; |
---|
1309 | initial_data(c); |
---|
1310 | while (find_next_pair(c)){ |
---|
1311 | int i,j; |
---|
1312 | int z; |
---|
1313 | i=c->found_i; |
---|
1314 | j=c->found_j; |
---|
1315 | replace_pair(i,j,c); |
---|
1316 | if (!(c->states[max(i,j)][min(i,j)]==HASTREP)){ |
---|
1317 | do_this_spoly_stuff(i,j,c); |
---|
1318 | } |
---|
1319 | //else |
---|
1320 | // PrintS("f"); |
---|
1321 | |
---|
1322 | now_t_rep(i,j,c); |
---|
1323 | now_t_rep(c->found_i,c->found_j,c); |
---|
1324 | #ifdef RANDOM_WALK |
---|
1325 | c->continue_i=my_rand(c->n-1)+1; |
---|
1326 | c->continue_j=my_rand(c->continue_i); |
---|
1327 | #endif |
---|
1328 | int_pair_node* h=c->soon_free; |
---|
1329 | while(h!=NULL) |
---|
1330 | { |
---|
1331 | int_pair_node* s=h; |
---|
1332 | now_t_rep(h->a,h->b,c); |
---|
1333 | |
---|
1334 | h=h->next; |
---|
1335 | omfree(s); |
---|
1336 | } |
---|
1337 | |
---|
1338 | |
---|
1339 | } |
---|
1340 | omfree(c->rep); |
---|
1341 | for(int z=0;z<c->n;z++){ |
---|
1342 | omfree(c->states[z]); |
---|
1343 | } |
---|
1344 | omfree(c->states); |
---|
1345 | omfree(c->lengths); |
---|
1346 | printf("calculated %d NFs\n",c->normal_forms); |
---|
1347 | omfree(c); |
---|
1348 | return(I); |
---|
1349 | } |
---|
1350 | void now_t_rep(const int & arg_i, const int & arg_j, calc_dat* c){ |
---|
1351 | int i,j; |
---|
1352 | if (arg_i==arg_j){ |
---|
1353 | return; |
---|
1354 | } |
---|
1355 | if (arg_i>arg_j){ |
---|
1356 | i=arg_j; |
---|
1357 | j=arg_i; |
---|
1358 | } else { |
---|
1359 | i=arg_i; |
---|
1360 | j=arg_j; |
---|
1361 | } |
---|
1362 | c->states[j][i]=HASTREP; |
---|
1363 | } |
---|
1364 | void soon_t_rep(const int& arg_i, const int& arg_j, calc_dat* c) |
---|
1365 | { |
---|
1366 | int i,j; |
---|
1367 | if (arg_i==arg_j){ |
---|
1368 | return; |
---|
1369 | } |
---|
1370 | if (arg_i>arg_j){ |
---|
1371 | i=arg_j; |
---|
1372 | j=arg_i; |
---|
1373 | } else { |
---|
1374 | i=arg_i; |
---|
1375 | j=arg_j; |
---|
1376 | } |
---|
1377 | if (! |
---|
1378 | (c->states[j][i]==HASTREP)) |
---|
1379 | c->states[j][i]=SOONTREP; |
---|
1380 | } |
---|
1381 | BOOLEAN has_t_rep(const int & arg_i, const int & arg_j, calc_dat* state){ |
---|
1382 | |
---|
1383 | if (arg_i==arg_j) |
---|
1384 | { |
---|
1385 | return (TRUE); |
---|
1386 | } |
---|
1387 | if (arg_i>arg_j) |
---|
1388 | { |
---|
1389 | return (state->states[arg_i][arg_j]==HASTREP); |
---|
1390 | } else |
---|
1391 | { |
---|
1392 | return (state->states[arg_j][arg_i]==HASTREP); |
---|
1393 | } |
---|
1394 | } |
---|
1395 | int pLcmDeg(poly a, poly b) |
---|
1396 | { |
---|
1397 | int i; |
---|
1398 | int n=0; |
---|
1399 | for (i=pVariables; i; i--) |
---|
1400 | { |
---|
1401 | n+=max( pGetExp(a,i), pGetExp(b,i)); |
---|
1402 | } |
---|
1403 | return n; |
---|
1404 | |
---|
1405 | } |
---|
1406 | int pMinDeg3(poly f){ |
---|
1407 | if (f==NULL){ |
---|
1408 | return(-1); |
---|
1409 | |
---|
1410 | } |
---|
1411 | |
---|
1412 | poly h=f->next; |
---|
1413 | int n=pFDeg(h); |
---|
1414 | int i=0; |
---|
1415 | while((i<2)){ |
---|
1416 | if (h==NULL) |
---|
1417 | return(n); |
---|
1418 | h=h->next; |
---|
1419 | if (h!=NULL){ |
---|
1420 | n=min(n,pFDeg(h)); |
---|
1421 | } |
---|
1422 | i++; |
---|
1423 | } |
---|
1424 | |
---|
1425 | return n; |
---|
1426 | } |
---|
1427 | |
---|
1428 | |
---|
1429 | void shorten_tails(calc_dat* c, poly monom) |
---|
1430 | { |
---|
1431 | // BOOLEAN corr=lenS_correct(c->strat); |
---|
1432 | for(int i=0;i<c->n;i++) |
---|
1433 | { |
---|
1434 | //enter tail |
---|
1435 | if (c->rep[i]!=i) continue; |
---|
1436 | if (c->S->m[i]==NULL) continue; |
---|
1437 | poly tail=c->S->m[i]->next; |
---|
1438 | poly prev=c->S->m[i]; |
---|
1439 | BOOLEAN did_something=FALSE; |
---|
1440 | while((tail!=NULL)&& (pLmCmp(tail, monom)>=0)) |
---|
1441 | { |
---|
1442 | if (p_LmDivisibleBy(monom,tail,c->r)) |
---|
1443 | { |
---|
1444 | did_something=TRUE; |
---|
1445 | prev->next=tail->next; |
---|
1446 | tail->next=NULL; |
---|
1447 | p_Delete(& tail,c->r); |
---|
1448 | tail=prev; |
---|
1449 | //PrintS("Shortened"); |
---|
1450 | c->lengths[i]--; |
---|
1451 | } |
---|
1452 | prev=tail; |
---|
1453 | tail=tail->next; |
---|
1454 | } |
---|
1455 | if (did_something) |
---|
1456 | { |
---|
1457 | int new_pos=simple_posInS(c->strat,c->S->m[i],c->lengths[i]); |
---|
1458 | int old_pos=-1; |
---|
1459 | //assume new_pos<old_pos |
---|
1460 | for (int z=0;z<=c->strat->sl;z++) |
---|
1461 | { |
---|
1462 | if (c->strat->S[z]==c->S->m[i]) |
---|
1463 | { |
---|
1464 | old_pos=z; |
---|
1465 | break; |
---|
1466 | } |
---|
1467 | } |
---|
1468 | if (old_pos== -1) |
---|
1469 | for (int z=new_pos-1;z>=0;z--) |
---|
1470 | { |
---|
1471 | if (c->strat->S[z]==c->S->m[i]) |
---|
1472 | { |
---|
1473 | old_pos=z; |
---|
1474 | break; |
---|
1475 | } |
---|
1476 | } |
---|
1477 | assume(old_pos>=0); |
---|
1478 | assume(pLength(c->strat->S[old_pos])==c->lengths[i]); |
---|
1479 | c->strat->lenS[old_pos]=c->lengths[i]; |
---|
1480 | if (new_pos<old_pos) |
---|
1481 | move_forward_in_S(old_pos,new_pos,c->strat); |
---|
1482 | if (c->lengths[i]==1) |
---|
1483 | { |
---|
1484 | |
---|
1485 | int j; |
---|
1486 | for ( j=0;j<i;j++) |
---|
1487 | { |
---|
1488 | if (c->lengths[j]==1) |
---|
1489 | c->states[i][j]=HASTREP; |
---|
1490 | } |
---|
1491 | for ( j=i+1;j<c->n;j++){ |
---|
1492 | if (c->lengths[j]==1) |
---|
1493 | c->states[j][i]=HASTREP; |
---|
1494 | } |
---|
1495 | shorten_tails(c,c->S->m[i]); |
---|
1496 | } |
---|
1497 | } |
---|
1498 | |
---|
1499 | } |
---|
1500 | // if (corr){ |
---|
1501 | |
---|
1502 | // corr=lenS_correct(c->strat); |
---|
1503 | // if(!corr){ |
---|
1504 | // PrintS("korupted in shorten tails"); |
---|
1505 | // } |
---|
1506 | // } |
---|
1507 | } |
---|