source: git/kernel/tgb_obsolete.cc @ d491e3

spielwiese
Last change on this file since d491e3 was d491e3, checked in by Michael Brickenstein <bricken@…>, 19 years ago
*bricken: non commutative seems to work git-svn-id: file:///usr/local/Singular/svn/trunk@8437 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.5 KB
Line 
1#include "tgb_internal.h"
2static poly redNF (poly h,kStrategy strat, int &len)
3{
4  len=0;
5  if (h==NULL) return NULL;
6  int j;
7
8  len=pLength(h);
9  if (0 > strat->sl)
10  {
11    return h;
12  }
13  LObject P(h);
14  P.SetShortExpVector();
15  P.bucket = kBucketCreate(currRing);
16  kBucketInit(P.bucket,P.p,len /*pLength(P.p)*/);
17  //int max_pos=simple_posInS(strat,P.p);
18  loop
19    {
20      j=kFindDivisibleByInS(strat->S,strat->sevS,strat->sl,&P);
21      if (j>=0)
22      {
23        nNormalize(pGetCoeff(P.p));
24#ifdef KDEBUG
25        if (TEST_OPT_DEBUG)
26        {
27          PrintS("red:");
28          wrp(h);
29          PrintS(" with ");
30          wrp(strat->S[j]);
31        }
32#endif
33        number coef=kBucketPolyRed(P.bucket,strat->S[j],
34                                   strat->lenS[j]/*pLength(strat->S[j])*/,
35                                   strat->kNoether);
36        nDelete(&coef);
37        h = kBucketGetLm(P.bucket);
38        if (h==NULL) return NULL;
39        P.p=h;
40        P.t_p=NULL;
41        P.SetShortExpVector();
42#ifdef KDEBUG
43        if (TEST_OPT_DEBUG)
44        {
45          PrintS("\nto:");
46          wrp(h);
47          PrintLn();
48        }
49#endif
50      }
51      else
52      {
53        kBucketClear(P.bucket,&(P.p),&len);
54        kBucketDestroy(&P.bucket);
55        pNormalize(P.p);
56        return P.p;
57      }
58    }
59}
60int find_best(red_object* r,int l, int u, int &w, calc_dat* c){
61
62  int sz=u-l+1;
63  int n=sz/10+1;
64  int filled=0;
65  int* indizes=(int*) omalloc(n*sizeof(int));
66  int* weight=(int*) omalloc(n*sizeof(int));
67  int worst=-1;
68  int i; 
69  for(i=l;i<=u;i++){
70    int q=r[i].guess_quality(c);
71    if ((filled<n)||(q<worst)){
72      if(filled<n){
73        worst=si_max(q,worst);
74        indizes[filled]=i;
75        weight[filled]=q;
76        filled++;
77      }
78    }
79    else{
80      int j;
81      for(j=0;j<filled;j++){
82        if (worst==weight[j]){
83          weight[j]=q;
84          indizes[j]=i;
85        }
86      }
87      worst=-1;
88      for(j=0;j<filled;j++){
89        if (worst<weight[j]){
90          worst=weight[j];
91        }
92      }
93    }
94  }
95  assume(filled==n);
96  int pos=0;
97
98  for(i=0;i<filled;i++){ 
99    r[indizes[i]].canonicalize();
100    weight[i]=r[indizes[i]].guess_quality(c);
101    if(weight[i]<weight[pos]) pos=i;
102  }
103  w=weight[pos];
104  pos=indizes[pos];
105
106  omfree(indizes);
107  omfree(weight);
108
109  assume(w==r[pos].guess_quality(c));
110  assume(l<=pos);
111  assume(u>=pos);
112  return pos;
113 
114}
115static poly redNF (poly h,kStrategy strat)
116{
117  int j = 0;
118  int z = 3;
119  unsigned long not_sev;
120
121  if (0 > strat->sl)
122  {
123    return h;
124  }
125  not_sev = ~ pGetShortExpVector(h);
126  loop
127  {
128    if (pLmShortDivisibleBy(strat->S[j], strat->sevS[j], h, not_sev))
129    {
130        //if (strat->interpt) test_int_std(strat->kIdeal);
131      /*- compute the s-polynomial -*/
132#ifdef KDEBUG
133        if (TEST_OPT_DEBUG)
134{
135         
136  PrintS("red:");
137  wrp(h);
138  PrintS(" with ");
139  wrp(strat->S[j]);
140}
141#endif
142        h = ksOldSpolyRed(strat->S[j],h,strat->kNoether);
143#ifdef KDEBUG
144        if (TEST_OPT_DEBUG)
145{
146  PrintS("\nto:");
147  wrp(h);
148  PrintLn();
149}
150#endif
151        if (h == NULL) return NULL;
152        z++;
153        if (z>=10)
154{
155  z=0;
156  pNormalize(h);
157}
158        /*- try to reduce the s-polynomial -*/
159        j = 0;
160        not_sev = ~ pGetShortExpVector(h);
161    }
162    else
163{
164  if (j >= strat->sl) return h;
165  j++;
166}
167  }
168}
169static sorted_pair_node** add_to_basis(poly h, int i_pos, int j_pos,calc_dat* c, int* ip)
170{
171
172  assume(h!=NULL);
173//  BOOLEAN corr=lenS_correct(c->strat);
174  BOOLEAN R_found=FALSE;
175  void* hp;
176
177  ++(c->n);
178  ++(c->S->ncols);
179  int i,j;
180  i=c->n-1;
181  sorted_pair_node** nodes=(sorted_pair_node**) omalloc(sizeof(sorted_pair_node*)*i);
182  int spc=0;
183  c->T_deg=(int*) omrealloc(c->T_deg,c->n*sizeof(int));
184  c->T_deg[i]=pTotaldegree(h);
185  if(c->T_deg_full){
186    c->T_deg_full=(int*) omrealloc(c->T_deg_full,c->n*sizeof(int));
187    c->T_deg_full[i]=pTotaldegree_full(h);
188  }
189 
190  c->tmp_pair_lm=(poly*) omrealloc(c->tmp_pair_lm,c->n*sizeof(poly));
191  c->tmp_pair_lm[i]=pOne_Special(c->r);
192  c->tmp_spn=(sorted_pair_node**) omrealloc(c->tmp_spn,c->n*sizeof(sorted_pair_node*));
193  c->tmp_spn[i]=(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
194
195  hp=omrealloc(c->rep, c->n *sizeof(int));
196  if (hp!=NULL){
197    c->rep=(int*) hp;
198  } else {
199    exit(1);
200  }
201  c->short_Exps=(long *) omrealloc(c->short_Exps ,c->n*sizeof(long));
202
203  hp=omrealloc(c->lengths, c->n *sizeof(int));
204  if (hp!=NULL){
205    c->lengths=(int*) hp;
206  } else {
207    exit(1);
208  }
209  c->lengths[i]=pLength(h);
210  hp=omrealloc(c->states, c->n * sizeof(char*));
211 
212  c->states=(char**) hp;
213  c->gcd_of_terms=(poly*) omrealloc(c->gcd_of_terms, c->n *sizeof(poly));
214  c->gcd_of_terms[i]=gcd_of_terms(h,c->r);
215  c->rep[i]=i;
216  if (i>0)
217    hp=omalloc(i*sizeof(char));
218  else
219    hp=NULL;
220  if (hp!=NULL){
221    c->states[i]=(char*) hp;
222  } else {
223    //exit(1);
224  }
225  hp=omrealloc(c->S->m,c->n*sizeof(poly));
226  if (hp!=NULL){
227    c->S->m=(poly*) hp;
228  } else {
229    exit(1);
230  }
231  c->S->m[i]=h;
232  c->short_Exps[i]=p_GetShortExpVector(h,c->r);
233  for (j=0;j<i;j++){
234    if (c->rep[j]==j){
235      //check product criterion
236
237      c->states[i][j]=UNCALCULATED;
238      assume(p_LmDivisibleBy(c->S->m[i],c->S->m[j],c->r)==
239          p_LmShortDivisibleBy(c->S->m[i],c->short_Exps[i],c->S->m[j],~(c->short_Exps[j]),c->r));
240      if(!c->F4_mode)
241      {
242        assume(!(p_LmDivisibleBy(c->S->m[j],c->S->m[i],c->r)));
243      }
244      //lies I[i] under I[j] ?
245      if(p_LmShortDivisibleBy(c->S->m[i],c->short_Exps[i],c->S->m[j],~(c->short_Exps[j]),c->r)){
246        c->rep[j]=i;
247        if (TEST_OPT_PROT)
248          PrintS("R"); 
249        R_found=TRUE;
250
251        c->Rcounter++;
252        if((i_pos>=0) && (j_pos>=0)){
253       
254        }
255        for(int z=0;z<j;z++){
256          if(c->rep[z]!=z) continue;
257          if (c->states[j][z]==UNCALCULATED){
258            c->states[j][z]=UNIMPORTANT;
259          }
260        }
261        for(int z=j+1;z<i;z++){
262          if(c->rep[z]!=z) continue;
263          if (c->states[z][j]==UNCALCULATED){
264            c->states[z][j]=UNIMPORTANT;
265          }
266        }
267      }
268    }
269    else {
270      c->states[i][j]=UNIMPORTANT;
271    }
272    if ((c->lengths[i]==1) && (c->lengths[j]==1))
273      c->states[i][j]=HASTREP;
274    else if (pHasNotCF(c->S->m[i],c->S->m[j])){
275      c->easy_product_crit++;
276      c->states[i][j]=HASTREP;
277    }
278    else if(extended_product_criterion(c->S->m[i],c->gcd_of_terms[i],c->S->m[j],c->gcd_of_terms[j],c)){
279      c->states[i][j]=HASTREP;
280      c->extended_product_crit++;
281                                        //PrintS("E");
282    }
283    if (c->states[i][j]==UNCALCULATED){
284
285     
286//      poly short_s=ksCreateShortSpoly(c->S->m[i],c->S->m[j],c->r);
287      //    if (short_s)
288      //    {
289      sorted_pair_node* s=(sorted_pair_node*) omalloc(sizeof(sorted_pair_node));
290      s->i=si_max(i,j);
291      s->j=si_min(i,j);
292      s->expected_length=c->lengths[i]+c->lengths[j]-2;
293     
294      poly lm=pOne();
295
296      pLcm(c->S->m[i], c->S->m[j], lm);
297      pSetm(lm);
298      s->deg=pTotaldegree(lm);
299      if(c->T_deg_full)
300      {
301        int t_i=c->T_deg_full[s->i]-c->T_deg[s->i];
302        int t_j=c->T_deg_full[s->j]-c->T_deg[s->j];
303        s->deg+=si_max(t_i,t_j);
304      }
305      s->lcm_of_lm=lm;
306//          pDelete(&short_s);
307        //assume(lm!=NULL);
308      nodes[spc]=s;
309      spc++;
310        // }
311        //else
312        //{
313        //c->states[i][j]=HASTREP;
314        //}
315    }
316  }
317
318  add_to_reductors(c, h, c->lengths[c->n-1]);
319  //i=posInS(c->strat,c->strat->sl,h,0 ecart);
320
321  if (c->lengths[c->n-1]==1)
322    shorten_tails(c,c->S->m[c->n-1]);
323  //you should really update c->lengths, c->strat->lenS, and the oder of polys in strat if you sort after lengths
324
325  //for(i=c->strat->sl; i>0;i--)
326  //  if(c->strat->lenS[i]<c->strat->lenS[i-1]) printf("fehler bei %d\n",i);
327  if (c->Rcounter>50) {
328    c->Rcounter=0;
329    cleanS(c->strat,c);
330  }
331  if(!ip){
332    qsort(nodes,spc,sizeof(sorted_pair_node*),pair_better_gen2);
333 
334   
335    c->apairs=merge(c->apairs,c->pair_top+1,nodes,spc,c);
336    c->pair_top+=spc;
337    clean_top_of_pair_list(c);
338    omfree(nodes);
339    return NULL;
340  }
341  {
342    *ip=spc;
343    return nodes;
344  }
345
346 
347
348}
349
350static void do_this_spoly_stuff(int i,int j,calc_dat* c){
351  poly f=c->S->m[i];
352  poly g=c->S->m[j];
353  poly h=ksOldCreateSpoly(f, g, NULL, c->r);
354  poly hr=NULL;
355#ifdef FULLREDUCTIONS
356  if (h!=NULL)
357{
358  int len;
359
360//    hr=redNF2(h,c,len);
361//      hr=redNF(h,c->strat,len);
362
363  if (hr!=NULL)
364#ifdef REDTAIL_S
365        hr = redNFTail(hr,c->strat->sl,c->strat,len);
366#else
367    hr = redtailBba(hr,c->strat->sl,c->strat);
368#endif
369
370}
371#else
372  if (h!=NULL)
373{
374  int len;
375//    hr=redNF2(h,c,len);
376}
377#endif
378  c->normal_forms++;
379  if (hr==NULL)
380{
381  notice_miss(i, j, c);
382
383}
384  else
385{
386
387#ifdef HEAD_BIN
388    hr=p_MoveHead(hr,c->HeadBin);
389#endif
390    add_to_basis(hr, i,j,c);
391}
392}
Note: See TracBrowser for help on using the repository browser.