source: git/kernel/F4.cc @ 6a9f2e

spielwiese
Last change on this file since 6a9f2e was 762407, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
config.h is for sources files only FIX: config.h should only be used by source (not from inside kernel/mod2.h!) NOTE: each source file should better include mod2.h right after config.h, while headers should better not include mod2.h.
  • Property mode set to 100644
File size: 18.5 KB
Line 
1#include "config.h"
2#include <kernel/mod2.h>
3#include <kernel/F4.h>
4#include <kernel/tgb_internal.h>
5#include <kernel/tgbgauss.h>
6/****************************************
7*  Computer Algebra System SINGULAR     *
8****************************************/
9/* $Id$ */
10/*
11* ABSTRACT: F4 implementation
12*/
13static int posInPolys (poly*  p, int pn, poly qe,slimgb_alg* c)
14{
15  if(pn==0) return 0;
16
17  int length=pn-1;
18  int i;
19  int an = 0;
20  int en= length;
21
22  if (pLmCmp(qe,p[en])==1)
23    return length+1;
24
25  while(1)
26  {
27      //if (an >= en-1)
28    if(en-1<=an)
29    {
30      if (pLmCmp(p[an],qe)==1) return an;
31      return en;
32    }
33    i=(an+en) / 2;
34    if (pLmCmp(p[i],qe)==1)
35      en=i;
36    else an=i;
37  }
38}
39
40static tgb_sparse_matrix* build_sparse_matrix(poly* p,int p_index,poly* done, int done_index, slimgb_alg* c){
41  tgb_sparse_matrix* t=new tgb_sparse_matrix(p_index,done_index,c->r);
42  int i, pos;
43  //  Print("\n 0:%s\n",pString(done[done_index-1]));
44  //Print("\n 1:%s\n",pString(done[done_index-2]));
45  //  assume((!(pLmEqual(done[done_index-1],done[done_index-2]))));
46#ifdef TGB_DEGUG
47  for(i=0;i<done_index;i++)
48{
49  int j;
50  for(j=0;j<i;j++)
51  {
52    assume((!(pLmEqual(done[i],done[j]))));
53  }
54}
55#endif
56  for(i=0;i<p_index;i++)
57{ 
58    // Print("%i ter Eintrag:%s\n",i,pString(p[i]));
59  mac_poly m=NULL;
60  mac_poly* set_this=&m;
61  poly p_i=p[i];
62  while(p_i)
63  {
64
65    int v=-1;
66    pos=posInPolys (done, done_index, p_i,c);
67    if((done_index>pos)&&(pLmEqual(p_i,done[pos])))
68      v=pos;
69    if((pos>0) &&(pLmEqual(p_i,done[pos-1])))
70      v=pos-1;
71    assume(v!=-1);
72      //v is ascending ordered, we need descending order
73    v=done_index-1-v;
74    (*set_this)=new mac_poly_r();
75    (*set_this)->exp=v;
76       
77    (*set_this)->coef=nCopy(p_i->coef);
78    set_this=&(*set_this)->next;
79    p_i=p_i->next;
80
81  }
82  init_with_mac_poly(t,i,m);
83}
84  return t;
85}
86static tgb_matrix* build_matrix(poly* p,int p_index,poly* done, int done_index, slimgb_alg* c){
87  tgb_matrix* t=new tgb_matrix(p_index,done_index);
88  int i, pos;
89  //  Print("\n 0:%s\n",pString(done[done_index-1]));
90  //Print("\n 1:%s\n",pString(done[done_index-2]));
91  assume((!(pLmEqual(done[done_index-1],done[done_index-2]))));
92#ifdef TGB_DEGUG
93  for(i=0;i<done_index;i++)
94{
95  int j;
96  for(j=0;j<i;j++)
97  {
98    assume((!(pLmEqual(done[i],done[j]))));
99  }
100}
101#endif
102  for(i=0;i<p_index;i++)
103{ 
104    // Print("%i ter Eintrag:%s\n",i,pString(p[i]));
105  poly p_i=p[i];
106  while(p_i)
107  {
108
109    int v=-1;
110    pos=posInPolys (done, done_index, p_i,c);
111    if((done_index>pos)&&(pLmEqual(p_i,done[pos])))
112      v=pos;
113    if((pos>0) &&(pLmEqual(p_i,done[pos-1])))
114      v=pos-1;
115    assume(v!=-1);
116      //v is ascending ordered, we need descending order
117    v=done_index-1-v;
118    number nt=t->get(i,v);
119    nDelete(&nt);
120    t->set(i,v,nCopy(p_i->coef));
121    p_i=p_i->next;
122  }
123}
124  return t;
125}
126
127static int retranslate(poly* m,tgb_sparse_matrix* mat,poly* done, slimgb_alg* c){
128  int i;
129  int m_index=0;
130  for(i=0;i<mat->get_rows();i++)
131  {
132    if(mat->zero_row(i))
133    {
134      mat->free_row(i);
135      continue;
136    }
137    m[m_index++]= free_row_to_poly(mat, i, done, mat->get_columns());
138
139  }
140
141  delete mat;
142  return m_index;
143
144}
145//!returns m_index and destroys mat
146 static int retranslate(poly* m,tgb_matrix* mat,poly* done, slimgb_alg* c){
147  int i;
148  int m_index=0;
149  for(i=0;i<mat->get_rows();i++)
150  {
151    if(mat->zero_row(i))
152    {
153      mat->free_row(i);
154      continue;
155    }
156   
157    m[m_index]=pInit();
158    int v=mat->min_col_not_zero_in_row(i);
159    //v=done_index-1-pos; => pos=done_index-1-v=mat->get_columns()-1-v
160    int pos=mat->get_columns()-1-v;
161    int* ev=(int*) omalloc((c->r->N+1)*sizeof(int));
162    pGetExpV(done[pos],ev);
163    pSetExpV(m[m_index],ev);
164    omfree(ev);
165   
166    poly p=m[m_index];
167    pSetCoeff(p,mat->get(i,v));
168    while((v=mat->next_col_not_zero(i,v))!=mat->get_columns())
169    {
170      poly pn=pInit();
171     
172      //v=done_index-1-pos; => pos=done_index-1-v=mat->get_columns()-1-v
173      pos=mat->get_columns()-1-v;
174      ev=(int*) omalloc((c->r->N+1)*sizeof(int));
175      pGetExpV(done[pos],ev);
176      pSetExpV(pn,ev);
177      omfree(ev);
178      pSetCoeff(pn,mat->get(i,v));
179      p->next=pn;
180      p=pn;
181    }
182    p->next=NULL;
183    mat->free_row(i, FALSE);
184    m_index++;
185  }
186
187  delete mat;
188  return m_index;
189
190}
191static int pLmCmp_func(const void* ap1, const void* ap2){
192    poly p1,p2;
193    p1=*((poly*) ap1);
194    p2=*((poly*)ap2);
195
196    return pLmCmp(p1,p2);
197}
198static int monom_poly_crit(const void* ap1, const void* ap2){
199  monom_poly* p1;
200  monom_poly* p2;
201  p1=((monom_poly*) ap1);
202  p2=((monom_poly*)ap2);
203  if(((unsigned long) p1->f)>((unsigned long) p2->f)) return 1;
204  if(((unsigned long) p1->f)<((unsigned long)p2->f)) return -1; 
205
206  return pLmCmp(p1->m,p2->m);
207 
208}
209static int posInMonomPolys (monom_poly*  p, int pn, monom_poly & qe,slimgb_alg* c)
210{
211  if(pn==0) return 0;
212
213  int length=pn-1;
214  int i;
215  int an = 0;
216  int en= length;
217
218  if (monom_poly_crit(&qe,&p[en])==1)
219    return length+1;
220
221  while(1)
222  {
223      //if (an >= en-1)
224    if(en-1<=an)
225    {
226      if (monom_poly_crit(&p[an],&qe)==1) return an;
227      return en;
228    }
229    i=(an+en) / 2;
230    if (monom_poly_crit(&p[i],&qe)==1)
231      en=i;
232    else an=i;
233  }
234}
235static void simplify(monom_poly& h, slimgb_alg* c){
236  mp_array_list* F=c->F;
237  poly_array_list* F_minus=c->F_minus;
238  while(F)
239  {
240    assume(F_minus!=NULL);
241    int i;
242    int posm=posInMonomPolys (F->mp, F->size, h,c);
243#ifdef TGB_DEBUG
244#endif
245     //for(i=0;i<F->size;i++)
246    for(i=si_min(posm,F->size-1);i>=0;i--)
247{
248      //      if((i>=posm)&&(F->mp[i].f!=h.f)) break;
249  if((i<posm)&&(F->mp[i].f!=h.f)) break;
250  if ((h.f==F->mp[i].f) &&(p_LmDivisibleBy(F->mp[i].m,h.m,c->r)))
251  {
252       
253        //      Print("found");
254       
255          //according to the algorithm you should test (!(pIsConstant(F[i].m)))
256          //but I think this is only because of bad formulation
257    int j;
258       
259    poly lm=pLmInit(h.f);
260    pSetCoeff(lm,nInit(1));
261
262    lm=pMult_mm(lm,F->mp[i].m);
263
264    int pos;
265    j=-1;
266    pos=posInPolys (F_minus->p, F_minus->size, lm,c);
267    if((F_minus->size>pos)&&(pLmEqual(lm,F_minus->p[pos])))
268      j=pos;
269    if((pos>0) &&(pLmEqual(lm,F_minus->p[pos-1])))
270      j=pos-1;
271    assume(j!=-1);
272      //        if(j==-1) Print("\n jAltert \n");
273//      for(j=0;j<F_minus->size;j++)
274//      {
275//        if (pLmEqual(F_minus->p[j],lm))
276//          break;
277//      }
278//      assume(j<F_minus->size);
279    pDelete(&lm);
280    if(j>=0)
281    {
282      pExpVectorSub(h.m,F->mp[i].m);
283      h.f=F_minus->p[j];
284    }
285    break;
286  }
287}
288    F=F->next;
289    F_minus=F_minus->next;
290  }
291  assume(F_minus==NULL);
292}
293
294void go_on_F4 (slimgb_alg* c){
295  //set limit of 1000 for multireductions, at the moment for
296  //programming reasons
297  int max_par;
298  if (c->is_homog)
299    max_par=PAR_N_F4;
300  else
301    max_par=200;
302  int done_size=max_par*2;
303  poly* done=(poly*) omalloc(done_size*sizeof(poly));
304  int done_index=0; //done_index must always be smaller than done_size
305  int chosen_size=max_par*2;
306  monom_poly* chosen=(monom_poly*) omalloc(chosen_size*sizeof(monom_poly));
307  int chosen_index=0;
308  //  monom_poly* vgl=(monom_poly*) omalloc(chosen_size*sizeof(monom_poly));
309  int i=0;
310  c->average_length=0;
311  for(i=0;i<c->n;i++){
312    c->average_length+=c->lengths[i];
313  }
314  c->average_length=c->average_length/c->n;
315  i=0;
316  poly* p;
317  int nfs=0;
318  int curr_deg=-1;
319
320  //choose pairs and preprocess symbolically
321  while(chosen_index<max_par)
322  {
323   
324    //    sorted_pair_node* s=c->apairs[c->pair_top];
325    sorted_pair_node* s;
326    if(c->pair_top>=0)
327      s=top_pair(c);//here is actually chain criterium done
328    else
329      s=NULL;
330    if (!s) break;
331    nfs++;
332    if(curr_deg>=0)
333    {
334      if (s->deg >curr_deg) break;
335    }
336
337    else curr_deg=s->deg;
338    quick_pop_pair(c);
339    if(s->i>=0)
340    {
341      //replace_pair(s->i,s->j,c);
342      if(s->i==s->j) 
343      {
344        free_sorted_pair_node(s,c->r);
345        continue;
346      }
347    }
348    assume(s->i>=0);
349    monom_poly h;
350    BOOLEAN only_free=FALSE;
351    if(s->i>=0)
352    {
353     
354      poly lcm=pOne();
355     
356      pLcm(c->S->m[s->i], c->S->m[s->j], lcm);
357      pSetm(lcm);
358      assume(lcm!=NULL);
359      poly factor1=pCopy(lcm);
360      pExpVectorSub(factor1,c->S->m[s->i]);
361      poly factor2=pCopy(lcm);
362      pExpVectorSub(factor2,c->S->m[s->j]);
363
364      if(done_index>=done_size)
365      {
366        done_size+=max_par;
367        done=(poly*) omrealloc(done,done_size*sizeof(poly));
368      }
369      done[done_index++]=lcm;
370      if(chosen_index+1>=chosen_size)
371      {
372        //max_par must be greater equal 2
373        chosen_size+=si_max(max_par,2);
374        chosen=(monom_poly*) omrealloc(chosen,chosen_size*sizeof(monom_poly));
375      }
376      h.f=c->S->m[s->i];
377      h.m=factor1;
378      chosen[chosen_index++]=h;
379      h.f=c->S->m[s->j];
380      h.m=factor2;
381      chosen[chosen_index++]=h;
382    }
383    else
384    {
385      if(chosen_index>=chosen_size)
386      {
387        chosen_size+=max_par;
388        chosen=(monom_poly*) omrealloc(chosen,chosen_size*sizeof(monom_poly));
389      }
390      h.f=s->lcm_of_lm;
391      h.m=pOne();
392      //pSetm(h.m); done by pOne
393      chosen[chosen_index++]=h;
394      //must carefull remember to destroy such a h;
395      poly_list_node* next=c->to_destroy;
396     
397      c->to_destroy=(poly_list_node*) omalloc(sizeof(poly_list_node));
398      c->to_destroy->p=h.f;
399      c->to_destroy->next=next;
400      only_free=TRUE;
401    }
402
403    if(s->i>=0)
404      now_t_rep(s->j,s->i,c);
405
406    if(!(only_free))
407      free_sorted_pair_node(s,c->r);
408    else
409      omfree(s);
410   
411 
412
413  }
414  c->normal_forms+=nfs;
415  if (TEST_OPT_PROT)
416    Print("M[%i, ",nfs);
417  //next Step, simplify all pairs
418  for(i=0;i<chosen_index;i++)
419  {
420    //    PrintS("simplifying ");
421    //Print("from %s",pString(chosen[i].m));
422    //Print(", %s", pString(chosen[i].f));
423    simplify(chosen[i],c);
424    //Print(" to %s",pString(chosen[i].m));
425    //Print(", %s \n", pString(chosen[i].f));
426  }
427 
428  //next Step remove duplicate entries
429  qsort(chosen,chosen_index,sizeof(monom_poly),monom_poly_crit);
430  int pos=0;
431  for(i=1;i<chosen_index;i++)
432  {
433    if(((chosen[i].f!=chosen[pos].f))||(!(pLmEqual(chosen[i].m,chosen[pos].m))))
434      chosen[++pos]=chosen[i];
435    else pDelete(&(chosen[i].m));
436  }
437  if(chosen_index>0)
438    chosen_index=pos+1;
439  //next step process polys
440  int p_size=2*chosen_index;
441  int p_index=0;
442  p=(poly*) omalloc(p_size*sizeof(poly));
443  for(p_index=0;p_index<chosen_index;p_index++)
444  {
445    p[p_index]=ppMult_mm(chosen[p_index].f,chosen[p_index].m);
446  }
447
448  qsort(done, done_index,sizeof(poly),pLmCmp_func);
449  pos=0;
450  //Print("Done_index:%i",done_index);
451  if(done_index>0)
452  {
453    pTest(done[0]);
454  }
455  for(i=1;i<done_index;i++)
456  {
457    pTest(done[i]);
458    if((!(pLmEqual(done[i],done[pos]))))
459      done[++pos]=done[i];
460    else pDelete(&(done[i]));
461  }
462  if(done_index>0)
463    done_index=pos+1;
464#ifdef TGB_DEBUG
465  for(i=0;i<done_index;i++)
466{
467  int j;
468  for(j=0;j<i;j++)
469  {
470    assume((!pLmEqual(done[j],done[i])));
471  }
472}
473#endif
474#ifdef TGB_DEBUG
475  for(i=0;i<done_index;i++)
476{
477  pTest(done[i]);
478}
479#endif
480  poly* m;
481  int m_index=0;
482  int m_size=0;
483  for(i=0;i<p_index;i++)
484{
485  m_size+=pLength(p[i]);
486}
487  m=(poly*) omalloc(m_size*sizeof(poly));
488  //q=(poly*) omalloc(m_size*sizeof(poly));
489
490 
491
492  for(i=0;i<p_index;i++)
493{
494
495  poly p_i=p[i];
496
497  pTest(p[i]);
498
499  while(p_i)
500  {
501
502    m[m_index]=pLmInit(p_i);
503
504    pSetCoeff(m[m_index],nInit(1));
505
506    p_i=p_i->next;
507
508    m_index++;
509
510  }
511}
512
513  int q_size=m_index;
514  poly* q=(poly*) omalloc(q_size*sizeof(poly));
515  int q_index=0;
516  //next Step additional reductors
517
518  while(m_index>0)
519{
520#ifdef TGB_DEBUG
521     
522      for(i=0;i<done_index;i++)
523{
524  pTest(done[i]);
525}
526#endif
527
528    qsort(m, m_index,sizeof(poly),pLmCmp_func);
529
530   
531    pos=0;
532#ifdef TGB_DEBUG
533     
534      for(i=0;i<done_index;i++)
535{
536       
537  pTest(done[i]);
538}
539#endif
540    for(i=1;i<m_index;i++)
541{
542  pTest(m[i]);
543  pTest(m[pos]);
544  if((!(pLmEqual(m[i],m[pos]))))
545    m[++pos]=m[i];
546  else pDelete(&(m[i]));
547}
548    if(m_index>1)
549      m_index=pos+1;
550    if(done_size<done_index+m_index)
551{
552  done_size=done_index+2*m_index;
553  done=(poly*) omrealloc(done,done_size*sizeof(poly));
554}
555    if(chosen_size<chosen_index+m_index)
556{
557  chosen_size=chosen_index+2*m_index;
558  chosen=(monom_poly*) omrealloc(chosen,chosen_size*sizeof(monom_poly));
559}
560    q_index=0;
561    if(q_size<m_index)
562{
563  q_size=2*m_index;
564  omfree(q);
565  q=(poly*) omalloc(q_size*sizeof(poly));
566}
567
568    for(i=0;i<m_index;i++)
569{
570
571#ifdef TGB_DEBUG
572{
573  int my_i;
574  for(my_i=0;my_i<done_index;my_i++)
575  {
576    int my_j;
577    for(my_j=0;my_j<my_i;my_j++)
578    {
579      assume((!pLmEqual(done[my_j],done[my_i])));
580    }
581  }
582}
583#endif
584      BOOLEAN in_done=FALSE;
585      pTest(m[i]);
586
587      pos=posInPolys (done, done_index, m[i],c);
588#ifdef TGB_DEBUG
589{
590  int my_i;
591  for (my_i=0;my_i<done_index;my_i++)
592    pTest(done[my_i]);
593}
594#endif     
595      if(((done_index>pos)&&(pLmEqual(m[i],done[pos]))) ||(pos>0) &&(pLmEqual(m[i],done[pos-1])))
596        in_done=TRUE;
597      if (!(in_done))
598{
599       
600  int S_pos=kFindDivisibleByInS_easy(c->strat,m[i], pGetShortExpVector(m[i]));
601  if(S_pos>=0)
602  {
603    monom_poly h;
604    h.f=c->strat->S[S_pos];
605    h.m=pOne();
606    int* ev=(int*) omalloc((c->r->N+1)*sizeof(int));
607    pGetExpV(m[i],ev);
608    pSetExpV(h.m,ev);
609    omfree(ev);
610    pExpVectorSub(h.m,c->strat->S[S_pos]);
611    simplify(h,c);
612    q[q_index]=ppMult_mm(h.f,h.m);
613    chosen[chosen_index++]=h;
614    q_index++;
615  }
616  pTest(m[i]);
617#ifdef TGB_DEBUG
618{
619  int my_i;
620  for (my_i=0;my_i<done_index;my_i++)
621    pTest(done[my_i]);
622}
623#endif     
624        memmove(&(done[pos+1]),&(done[pos]), (done_index-pos)*sizeof(poly));
625        done[pos]=m[i];
626 done_index++;
627#ifdef TGB_DEBUG
628{
629  int my_i;
630  for (my_i=0;my_i<done_index;my_i++)
631  {
632            //      Print("Position %i pos %i size %i\n",my_i,pos,done_index);
633    pTest(done[my_i]);
634  }
635}
636#endif     
637}
638      else
639        pDelete(&m[i]);
640#ifdef TGB_DEBUG
641{
642  int my_i;
643  for(my_i=0;my_i<done_index;my_i++)
644  {
645    pTest(done[my_i]);
646    int my_j;
647    for(my_j=0;my_j<my_i;my_j++)
648    {
649      assume((!pLmEqual(done[my_j],done[my_i])));
650    }
651  }
652}
653#endif
654}
655    if(p_size<p_index+q_index)
656{
657  p_size=p_index+2*q_index;
658  p=(poly*) omrealloc(p,p_size*sizeof(poly));
659}
660    for (i=0;i<q_index;i++)
661      p[p_index++]=q[i];
662    m_index=0;
663    int sum=0;
664    for(i=0;i<p_index;i++)
665{
666  sum+=pLength(p[i])-1;
667}
668    if (m_size<sum)
669{
670  omfree(m);
671  m=(poly*) omalloc(sum*sizeof(poly));
672}
673    m_size=sum;
674    for(i=0;i<q_index;i++)
675{
676  poly p_i=q[i]->next;
677  while(p_i)
678  {
679    m[m_index]=pLmInit(p_i);
680    pSetCoeff(m[m_index],nInit(1));
681    p_i=p_i->next;
682    m_index++;
683  }
684}
685    //qsort(done, done_index,sizeof(poly),pLmCmp_func);
686#ifdef TGB_DEBUG
687    for(i=0;i<done_index;i++)
688{
689  pTest(done[i]);
690}
691#endif
692}
693#ifdef TGB_DEBUG
694  for(i=0;i<done_index;i++)
695{
696  int j;
697  for(j=0;j<i;j++)
698  {
699    assume((!pLmEqual(done[j],done[i])));
700  }
701}
702#endif
703  omfree(m);
704  omfree(q);
705  if (TEST_OPT_PROT)
706    Print("Mat[%i x %i], ",chosen_index, done_index);
707  //next Step build matrix
708#ifdef TGB_DEBUG
709  for(i=0;i<done_index;i++)
710{
711  int j;
712  for(j=0;j<i;j++)
713  {
714    assume((!pLmEqual(done[j],done[i])));
715  }
716}
717#endif
718  assume(p_index==chosen_index);
719 
720 //  tgb_matrix* mat=build_matrix(p,p_index,done, done_index,c);
721 
722//   simple_gauss2(mat);
723  tgb_sparse_matrix* mat=build_sparse_matrix(p,p_index,done, done_index,c);
724  simple_gauss(mat,c);
725  m_size=mat->get_rows();
726  m=(poly*) omalloc(m_size*sizeof(poly));
727  m_index=retranslate(m,mat,done,c);
728 
729  mat=NULL;
730  for(i=0;i<done_index;i++)
731    pDelete(&done[i]);
732  omfree(done);
733  done=NULL;
734  //next Step addElements to basis
735  int F_plus_size=m_index;
736  poly* F_plus=(poly*)omalloc(F_plus_size*sizeof(poly));
737  int F_plus_index=0;
738  int F_minus_size=m_index;
739  poly* F_minus=(poly*) omalloc(F_minus_size*sizeof(poly));
740  int F_minus_index=0;
741
742  //better algorithm replace p by its monoms, qsort,delete duplicates and binary search for testing if monom is contained in array
743  qsort(p, p_index,sizeof(poly),pLmCmp_func);
744  for(i=0;i<p_index;i++)
745    pDelete(&p[i]->next);
746  for(i=m_index-1;i>=0;--i)
747{
748  int j;
749  int pos=posInPolys (p,p_index, m[i],c);
750  BOOLEAN minus=FALSE;
751  if(((p_index>pos)&&(pLmEqual(m[i],p[pos]))) ||(pos>0) &&(pLmEqual(m[i],p[pos-1])))
752    minus=TRUE;
753   
754  if(minus)
755  {
756    F_minus[F_minus_index++]=m[i];
757    m[i]=NULL;
758  }
759  else
760  {
761    F_plus[F_plus_index++]=m[i];
762    m[i]=NULL;
763  }
764}
765
766//   for(i=m_index-1;i>=0;--i)
767//   {
768//     int j;
769//     BOOLEAN minus=FALSE;
770//     for(j=0;j<p_index;j++)
771//       if (pLmEqual(p[j],m[i]))
772//       {
773//      minus=TRUE;
774//      break;
775//       }
776//     if(minus)
777//     {
778//       F_minus[F_minus_index++]=m[i];
779//       m[i]=NULL;
780//     }
781//     else
782//     {
783//       F_plus[F_plus_index++]=m[i];
784//       m[i]=NULL;
785//     }
786//   }
787  //in this order F_minus will be automatically ascending sorted
788  //to make this sure for foreign gauss
789  //uncomment the following line
790  //  qsort(F_minus, F_minus_index,sizeof(poly),pLmCmp_func);
791  assume((F_plus_index+F_minus_index)==m_index);
792  if (TEST_OPT_PROT)
793    Print("%i]", F_plus_index);
794  for(i=0;i<p_index;i++) 
795    pDelete(&p[i]);
796  omfree(p);
797  p=NULL;
798  omfree(m);
799  m=NULL;
800
801  //the F_minus list must be cleared separately at the end
802  mp_array_list** F_i;
803  poly_array_list** F_m_i;
804  F_i=&(c->F);
805  F_m_i=&(c->F_minus);
806
807  while((*F_i)!=NULL)
808{
809  assume((*F_m_i)!=NULL);
810  F_i=(&((*F_i)->next));
811  F_m_i=(&((*F_m_i)->next));
812}
813  assume((*F_m_i)==NULL);
814  //should resize the array to save memory
815  //F and F_minus
816  qsort(chosen,chosen_index,sizeof(monom_poly),monom_poly_crit);//important for simplify
817  (*F_m_i)=(poly_array_list*) omalloc(sizeof(poly_array_list));
818  (*F_m_i)->size=F_minus_index;
819  (*F_m_i)->p=F_minus;
820  (*F_m_i)->next=NULL;
821  (*F_i)=(mp_array_list*) omalloc(sizeof(poly_array_list));
822  (*F_i)->size=chosen_index;
823  (*F_i)->mp=chosen;
824  (*F_i)->next=NULL;
825 
826  if(F_plus_index>0)
827{
828  int j;
829  int* ibuf=(int*) omalloc(F_plus_index*sizeof(int));
830  sorted_pair_node*** sbuf=(sorted_pair_node***) omalloc(F_plus_index*sizeof(sorted_pair_node**));
831 
832  for(j=0;j<F_plus_index;j++)
833  {
834    int len;
835    poly p=F_plus[j];
836   
837    // delete buf[j];
838    //remember to free res here
839    //    p=redTailShort(p, c->strat);
840    sbuf[j]=add_to_basis_ideal_quotient(p,c,ibuf+j);
841   
842  }
843  int sum=0;
844  for(j=0;j<F_plus_index;j++)
845  {
846    sum+=ibuf[j];
847  }
848  sorted_pair_node** big_sbuf=(sorted_pair_node**) omalloc(sum*sizeof(sorted_pair_node*));
849  int partsum=0;
850  for(j=0;j<F_plus_index;j++)
851  {
852    memmove(big_sbuf+partsum, sbuf[j],ibuf[j]*sizeof(sorted_pair_node*));
853    omfree(sbuf[j]);
854    partsum+=ibuf[j];
855  }
856
857  qsort(big_sbuf,sum,sizeof(sorted_pair_node*),tgb_pair_better_gen2);
858  c->apairs=spn_merge(c->apairs,c->pair_top+1,big_sbuf,sum,c);
859  c->pair_top+=sum;
860  clean_top_of_pair_list(c);
861  omfree(big_sbuf);
862  omfree(sbuf);
863  omfree(ibuf);
864}
865  omfree(F_plus);
866#ifdef TGB_DEBUG
867  int z;
868  for(z=1;z<=c->pair_top;z++)
869{
870  assume(pair_better(c->apairs[z],c->apairs[z-1],c));
871}
872#endif
873
874  return;
875}
Note: See TracBrowser for help on using the repository browser.