source: git/kernel/tgb_obsolete.cc @ cafd4ff

spielwiese
Last change on this file since cafd4ff was 599326, checked in by Kai Krüger <krueger@…>, 14 years ago
Anne, Kai, Frank: - changes to #include "..." statements to allow cleaner build structure - affected directories: omalloc, kernel, Singular - not yet done: IntergerProgramming git-svn-id: file:///usr/local/Singular/svn/trunk@13032 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 12.4 KB
Line 
1#include <kernel/tgb_internal.h>
2#if 0
3static void notice_miss(int i, int j, slimgb_alg* c){
4  if (TEST_OPT_PROT)
5    PrintS("-");
6 
7}
8#endif
9static poly redNF (poly h,kStrategy strat, int &len)
10{
11  len=0;
12  if (h==NULL) return NULL;
13  int j;
14
15  len=pLength(h);
16  if (0 > strat->sl)
17  {
18    return h;
19  }
20  LObject P(h);
21  P.SetShortExpVector();
22  P.bucket = kBucketCreate(currRing);
23  kBucketInit(P.bucket,P.p,len /*pLength(P.p)*/);
24  //int max_pos=simple_posInS(strat,P.p);
25  loop
26    {
27      j=kFindDivisibleByInS(strat->S,strat->sevS,strat->sl,&P);
28      if (j>=0)
29      {
30        nNormalize(pGetCoeff(P.p));
31#ifdef KDEBUG
32        if (TEST_OPT_DEBUG)
33        {
34          PrintS("red:");
35          wrp(h);
36          PrintS(" with ");
37          wrp(strat->S[j]);
38        }
39#endif
40        number coef=kBucketPolyRed(P.bucket,strat->S[j],
41                                   strat->lenS[j]/*pLength(strat->S[j])*/,
42                                   strat->kNoether);
43        nDelete(&coef);
44        h = kBucketGetLm(P.bucket);
45        if (h==NULL) return NULL;
46        P.p=h;
47        P.t_p=NULL;
48        P.SetShortExpVector();
49#ifdef KDEBUG
50        if (TEST_OPT_DEBUG)
51        {
52          PrintS("\nto:");
53          wrp(h);
54          PrintLn();
55        }
56#endif
57      }
58      else
59      {
60        kBucketClear(P.bucket,&(P.p),&len);
61        kBucketDestroy(&P.bucket);
62        pNormalize(P.p);
63        return P.p;
64      }
65    }
66}
67int find_best(red_object* r,int l, int u, int &w, calc_dat* c){
68
69  int sz=u-l+1;
70  int n=sz/10+1;
71  int filled=0;
72  int* indizes=(int*) omalloc(n*sizeof(int));
73  int* weight=(int*) omalloc(n*sizeof(int));
74  int worst=-1;
75  int i; 
76  for(i=l;i<=u;i++){
77    int q=r[i].guess_quality(c);
78    if ((filled<n)||(q<worst)){
79      if(filled<n){
80        worst=si_max(q,worst);
81        indizes[filled]=i;
82        weight[filled]=q;
83        filled++;
84      }
85    }
86    else{
87      int j;
88      for(j=0;j<filled;j++){
89        if (worst==weight[j]){
90          weight[j]=q;
91          indizes[j]=i;
92        }
93      }
94      worst=-1;
95      for(j=0;j<filled;j++){
96        if (worst<weight[j]){
97          worst=weight[j];
98        }
99      }
100    }
101  }
102  assume(filled==n);
103  int pos=0;
104
105  for(i=0;i<filled;i++){ 
106    r[indizes[i]].canonicalize();
107    weight[i]=r[indizes[i]].guess_quality(c);
108    if(weight[i]<weight[pos]) pos=i;
109  }
110  w=weight[pos];
111  pos=indizes[pos];
112
113  omfree(indizes);
114  omfree(weight);
115
116  assume(w==r[pos].guess_quality(c));
117  assume(l<=pos);
118  assume(u>=pos);
119  return pos;
120 
121}
122static poly redNF (poly h,kStrategy strat)
123{
124  int j = 0;
125  int z = 3;
126  unsigned long not_sev;
127
128  if (0 > strat->sl)
129  {
130    return h;
131  }
132  not_sev = ~ pGetShortExpVector(h);
133  loop
134  {
135    if (pLmShortDivisibleBy(strat->S[j], strat->sevS[j], h, not_sev))
136    {
137        //if (strat->interpt) test_int_std(strat->kIdeal);
138      /*- compute the s-polynomial -*/
139#ifdef KDEBUG
140        if (TEST_OPT_DEBUG)
141{
142         
143  PrintS("red:");
144  wrp(h);
145  PrintS(" with ");
146  wrp(strat->S[j]);
147}
148#endif
149        h = ksOldSpolyRed(strat->S[j],h,strat->kNoether);
150#ifdef KDEBUG
151        if (TEST_OPT_DEBUG)
152{
153  PrintS("\nto:");
154  wrp(h);
155  PrintLn();
156}
157#endif
158        if (h == NULL) return NULL;
159        z++;
160        if (z>=10)
161{
162  z=0;
163  pNormalize(h);
164}
165        /*- try to reduce the s-polynomial -*/
166        j = 0;
167        not_sev = ~ pGetShortExpVector(h);
168    }
169    else
170{
171  if (j >= strat->sl) return h;
172  j++;
173}
174  }
175}
176static sorted_pair_node** add_to_basis(poly h, int i_pos, int j_pos,calc_dat* c, int* ip)
177{
178
179  assume(h!=NULL);
180//  BOOLEAN corr=lenS_correct(c->strat);
181  BOOLEAN R_found=FALSE;
182  void* hp;
183
184  ++(c->n);
185  ++(c->S->ncols);
186  int i,j;
187  i=c->n-1;
188  sorted_pair_node** nodes=(sorted_pair_node**) omalloc(sizeof(sorted_pair_node*)*i);
189  int spc=0;
190  c->T_deg=(int*) omrealloc(c->T_deg,c->n*sizeof(int));
191  c->T_deg[i]=pTotaldegree(h);
192  if(c->T_deg_full){
193    c->T_deg_full=(int*) omrealloc(c->T_deg_full,c->n*sizeof(int));
194    c->T_deg_full[i]=pTotaldegree_full(h);
195  }
196 
197  c->tmp_pair_lm=(poly*) omrealloc(c->tmp_pair_lm,c->n*sizeof(poly));
198  c->tmp_pair_lm[i]=pOne_Special(c->r);
199  c->tmp_spn=(sorted_pair_node**) omrealloc(c->tmp_spn,c->n*sizeof(sorted_pair_node*));
200  c->tmp_spn[i]=(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
201
202  hp=omrealloc(c->rep, c->n *sizeof(int));
203  if (hp!=NULL){
204    c->rep=(int*) hp;
205  } else {
206    exit(1);
207  }
208  c->short_Exps=(long *) omrealloc(c->short_Exps ,c->n*sizeof(long));
209
210  hp=omrealloc(c->lengths, c->n *sizeof(int));
211  if (hp!=NULL){
212    c->lengths=(int*) hp;
213  } else {
214    exit(1);
215  }
216  c->lengths[i]=pLength(h);
217  hp=omrealloc(c->states, c->n * sizeof(char*));
218 
219  c->states=(char**) hp;
220  c->gcd_of_terms=(poly*) omrealloc(c->gcd_of_terms, c->n *sizeof(poly));
221  c->gcd_of_terms[i]=gcd_of_terms(h,c->r);
222  c->rep[i]=i;
223  if (i>0)
224    hp=omalloc(i*sizeof(char));
225  else
226    hp=NULL;
227  if (hp!=NULL){
228    c->states[i]=(char*) hp;
229  } else {
230    //exit(1);
231  }
232  hp=omrealloc(c->S->m,c->n*sizeof(poly));
233  if (hp!=NULL){
234    c->S->m=(poly*) hp;
235  } else {
236    exit(1);
237  }
238  c->S->m[i]=h;
239  c->short_Exps[i]=p_GetShortExpVector(h,c->r);
240  for (j=0;j<i;j++){
241    if (c->rep[j]==j){
242      //check product criterion
243
244      c->states[i][j]=UNCALCULATED;
245      assume(p_LmDivisibleBy(c->S->m[i],c->S->m[j],c->r)==
246          p_LmShortDivisibleBy(c->S->m[i],c->short_Exps[i],c->S->m[j],~(c->short_Exps[j]),c->r));
247      if(!c->F4_mode)
248      {
249        assume(!(p_LmDivisibleBy(c->S->m[j],c->S->m[i],c->r)));
250      }
251      //lies I[i] under I[j] ?
252      if(p_LmShortDivisibleBy(c->S->m[i],c->short_Exps[i],c->S->m[j],~(c->short_Exps[j]),c->r)){
253        c->rep[j]=i;
254        if (TEST_OPT_PROT)
255          PrintS("R"); 
256        R_found=TRUE;
257
258        c->Rcounter++;
259        if((i_pos>=0) && (j_pos>=0)){
260       
261        }
262        for(int z=0;z<j;z++){
263          if(c->rep[z]!=z) continue;
264          if (c->states[j][z]==UNCALCULATED){
265            c->states[j][z]=UNIMPORTANT;
266          }
267        }
268        for(int z=j+1;z<i;z++){
269          if(c->rep[z]!=z) continue;
270          if (c->states[z][j]==UNCALCULATED){
271            c->states[z][j]=UNIMPORTANT;
272          }
273        }
274      }
275    }
276    else {
277      c->states[i][j]=UNIMPORTANT;
278    }
279    if ((c->lengths[i]==1) && (c->lengths[j]==1))
280      c->states[i][j]=HASTREP;
281    else if (pHasNotCF(c->S->m[i],c->S->m[j])){
282      c->easy_product_crit++;
283      c->states[i][j]=HASTREP;
284    }
285    else if(extended_product_criterion(c->S->m[i],c->gcd_of_terms[i],c->S->m[j],c->gcd_of_terms[j],c)){
286      c->states[i][j]=HASTREP;
287      c->extended_product_crit++;
288                                        //PrintS("E");
289    }
290    if (c->states[i][j]==UNCALCULATED){
291
292     
293//      poly short_s=ksCreateShortSpoly(c->S->m[i],c->S->m[j],c->r);
294      //    if (short_s)
295      //    {
296      sorted_pair_node* s=(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
297      s->i=si_max(i,j);
298      s->j=si_min(i,j);
299      s->expected_length=c->lengths[i]+c->lengths[j]-2;
300     
301      poly lm=pOne();
302
303      pLcm(c->S->m[i], c->S->m[j], lm);
304      pSetm(lm);
305      s->deg=pTotaldegree(lm);
306      if(c->T_deg_full)
307      {
308        int t_i=c->T_deg_full[s->i]-c->T_deg[s->i];
309        int t_j=c->T_deg_full[s->j]-c->T_deg[s->j];
310        s->deg+=si_max(t_i,t_j);
311      }
312      s->lcm_of_lm=lm;
313//          pDelete(&short_s);
314        //assume(lm!=NULL);
315      nodes[spc]=s;
316      spc++;
317        // }
318        //else
319        //{
320        //c->states[i][j]=HASTREP;
321        //}
322    }
323  }
324
325  add_to_reductors(c, h, c->lengths[c->n-1]);
326  //i=posInS(c->strat,c->strat->sl,h,0 ecart);
327
328  if (c->lengths[c->n-1]==1)
329    shorten_tails(c,c->S->m[c->n-1]);
330  //you should really update c->lengths, c->strat->lenS, and the oder of polys in strat if you sort after lengths
331
332  //for(i=c->strat->sl; i>0;i--)
333  //  if(c->strat->lenS[i]<c->strat->lenS[i-1]) printf("fehler bei %d\n",i);
334  if (c->Rcounter>50) {
335    c->Rcounter=0;
336    cleanS(c->strat,c);
337  }
338  if(!ip){
339    qsort(nodes,spc,sizeof(sorted_pair_node*),pair_better_gen2);
340 
341   
342    c->apairs=merge(c->apairs,c->pair_top+1,nodes,spc,c);
343    c->pair_top+=spc;
344    clean_top_of_pair_list(c);
345    omfree(nodes);
346    return NULL;
347  }
348  {
349    *ip=spc;
350    return nodes;
351  }
352
353 
354
355}
356
357static void do_this_spoly_stuff(int i,int j,calc_dat* c){
358  poly f=c->S->m[i];
359  poly g=c->S->m[j];
360  poly h=ksOldCreateSpoly(f, g, NULL, c->r);
361  poly hr=NULL;
362#ifdef FULLREDUCTIONS
363  if (h!=NULL)
364{
365  int len;
366
367//    hr=redNF2(h,c,len);
368//      hr=redNF(h,c->strat,len);
369
370  if (hr!=NULL)
371#ifdef REDTAIL_S
372        hr = redNFTail(hr,c->strat->sl,c->strat,len);
373#else
374    hr = redtailBba(hr,c->strat->sl,c->strat);
375#endif
376
377}
378#else
379  if (h!=NULL)
380{
381  int len;
382//    hr=redNF2(h,c,len);
383}
384#endif
385  c->normal_forms++;
386  if (hr==NULL)
387{
388  notice_miss(i, j, c);
389
390}
391  else
392{
393
394#ifdef HEAD_BIN
395    hr=p_MoveHead(hr,c->HeadBin);
396#endif
397    add_to_basis(hr, i,j,c);
398}
399}
400
401#if 0
402static void replace_pair(int & i, int & j, slimgb_alg* c)
403{
404  c->soon_free=NULL;
405  int curr_deg;
406  poly lm=pOne();
407
408  pLcm(c->S->m[i], c->S->m[j], lm);
409  pSetm(lm);
410  int deciding_deg= pTotaldegree(lm);
411  int* i_con =make_connections(i,j,lm,c);
412 
413  for (int n=0;((n<c->n) && (i_con[n]>=0));n++){
414    if (i_con[n]==j){
415      now_t_rep(i,j,c);
416      omfree(i_con);
417      p_Delete(&lm,c->r);
418      return;
419    }
420  }
421
422  int* j_con =make_connections(j,lm,c);
423  i= i_con[0];
424  j=j_con[0];
425  if(c->n>1){
426    if (i_con[1]>=0)
427      i=i_con[1];
428    else {
429      if (j_con[1]>=0)
430        j=j_con[1];
431    }
432  }
433  pLcm(c->S->m[i], c->S->m[j], lm);
434  pSetm(lm);
435  poly short_s;
436  curr_deg=pTotaldegree(lm);
437  int_pair_node* last=NULL;
438
439  for (int n=0;((n<c->n) && (j_con[n]>=0));n++){
440    for (int m=0;((m<c->n) && (i_con[m]>=0));m++){
441      pLcm(c->S->m[i_con[m]], c->S->m[j_con[n]], lm);
442      pSetm(lm);
443      if (pTotaldegree(lm)>=deciding_deg)
444      {
445        soon_t_rep(i_con[m],j_con[n],c);
446        int_pair_node* h= (int_pair_node*)omalloc(sizeof(int_pair_node));
447        if (last!=NULL)
448          last->next=h;
449        else
450          c->soon_free=h;
451        h->next=NULL;
452        h->a=i_con[m];
453        h->b=j_con[n];
454        last=h;
455      }
456      //      if ((comp_deg<curr_deg)
457      //  ||
458      //  ((comp_deg==curr_deg) &&
459      short_s=ksCreateShortSpoly(c->S->m[i_con[m]],c->S->m[j_con[n]],c->r);
460      if (short_s==NULL) {
461        i=i_con[m];
462        j=j_con[n];
463        now_t_rep(i_con[m],j_con[n],c);
464        p_Delete(&lm,c->r);
465        omfree(i_con);
466        omfree(j_con);
467
468        return;
469      }
470#ifdef QUICK_SPOLY_TEST
471      for (int dz=0;dz<=c->n;dz++){
472        if (dz==c->n) {
473          //have found not head reducing pair
474          i=i_con[m];
475          j=j_con[n];
476          p_Delete(&short_s,c->r);
477          p_Delete(&lm,c->r);
478          omfree(i_con);
479          omfree(j_con);
480
481          return;
482        }
483        if (p_LmDivisibleBy(c->S->m[dz],short_s,c->r)) break;
484      }
485#endif
486      int comp_deg(pTotaldegree(short_s));
487      p_Delete(&short_s,c->r);
488      if ((comp_deg<curr_deg))
489         
490      {
491        curr_deg=comp_deg;
492        i=i_con[m];
493        j=j_con[n];
494      }
495    }
496  }
497  p_Delete(&lm,c->r);
498  omfree(i_con);
499  omfree(j_con);
500  return;
501}
502#endif
503
504#if 0
505//not needed any more, but should work
506static int* make_connections(int from, poly bound, slimgb_alg* c)
507{
508  ideal I=c->S;
509  int s=pTotaldegree(bound);
510  int* cans=(int*) omalloc(c->n*sizeof(int));
511  int* connected=(int*) omalloc(c->n*sizeof(int));
512  int cans_length=0;
513  connected[0]=from;
514  int connected_length=1;
515  long neg_bounds_short= ~p_GetShortExpVector(bound,c->r);
516  for (int i=0;i<c->n;i++){
517    if (c->T_deg[i]>s) continue;
518    if (i!=from){
519      if(p_LmShortDivisibleBy(I->m[i],c->short_Exps[i],bound,neg_bounds_short,c->r)){
520        cans[cans_length]=i;
521        cans_length++;
522      }
523    }
524  }
525  int not_yet_found=cans_length;
526  int con_checked=0;
527  int pos;
528  while((not_yet_found>0) && (con_checked<connected_length)){
529    pos=connected[con_checked];
530    for(int i=0;i<cans_length;i++){
531      if (cans[i]<0) continue;
532      if (has_t_rep(pos,cans[i],c))
533      {
534        connected[connected_length]=cans[i];
535        connected_length++;
536        cans[i]=-1;
537        --not_yet_found;
538      }
539    }
540    con_checked++;
541  }
542  if (connected_length<c->n){
543    connected[connected_length]=-1;
544  }
545  omfree(cans);
546  return connected;
547}
548#endif
549#if 0
550static void soon_t_rep(const int& arg_i, const int& arg_j, slimgb_alg* c)
551{
552  assume(0<=arg_i);
553  assume(0<=arg_j);
554  assume(arg_i<c->n);
555  assume(arg_j<c->n);
556  int i,j;
557  if (arg_i==arg_j){
558    return;
559  }
560  if (arg_i>arg_j){
561    i=arg_j;
562    j=arg_i;
563  } else {
564    i=arg_i;
565    j=arg_j;
566  }
567  if (!
568      (c->states[j][i]==HASTREP))
569    c->states[j][i]=SOONTREP;
570}
571#endif
Note: See TracBrowser for help on using the repository browser.