source: git/Singular/janet.cc @ 92d684

spielwiese
Last change on this file since 92d684 was fe66ba8, checked in by Martin Lee <martinlee84@…>, 13 years ago
fixed janet.cc
  • Property mode set to 100644
File size: 17.6 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <time.h>
5
6#include <kernel/mod2.h>
7#include <omalloc/omalloc.h>
8#include <polys/polys.h>
9#include <coeffs/numbers.h>
10#include <polys/monomials/ring.h>
11#include <kernel/ideals.h>
12#include <Singular/subexpr.h>
13#include <polys/kbuckets.h>
14#include <coeffs/longrat.h>
15#include <polys/monomials/p_polys.h>
16
17#if (defined(__CYGWIN__))
18#include <ctype.h>
19#endif
20#include <stdarg.h>
21
22#include <kernel/febase.h>
23#include <Singular/janet.h>
24#include <kernel/kutil.h>
25
26//------GLOBALS-------
27static int m_s,v_s,vectorized,VarN1,offset;
28static jList *T,*Q;
29static TreeM *G;
30static Poly *phD;
31static NodeM *FreeNodes;
32static int degree_compatible;
33static int (*ListGreatMove)(jList *,jList *,poly);
34static int Mask[8]={0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1};
35
36//#define DebugPrint
37
38//#define pow_(x) pTotaldegree((x))
39//#define pow_(x) pDeg((x))
40pFDegProc jDeg;
41#define pow_(x) jDeg((x),currRing)
42
43void Debug()
44{
45  LCI it=T->root;
46
47  PrintS("T==================================\n");
48  while (it)
49  {
50    pWrite(it->info->root);
51    it=it->next;
52  }
53
54  it=Q->root;
55
56  PrintS("Q==================================\n");
57  while (it)
58  {
59    if (it->info->root) pWrite(it->info->root);
60    else
61    {
62      Print("%d.........",it->info->prolonged);
63      pWrite(it->info->history);
64    }
65    it=it->next;
66  }
67  PrintS("===================================\n");
68}
69
70int ReducePolyLead(Poly *x,Poly *y)
71{
72  if (!x->root || !y->root)
73    return 0;
74
75/*  poly b1=pDivide(x->root,y->root);
76
77  number gcd=nGcd(pGetCoeff(x->root),pGetCoeff(y->root),currRing);
78
79  number a1=nDiv(pGetCoeff(y->root),gcd);
80  pGetCoeff(b1)=nDiv(pGetCoeff(x->root),gcd);
81
82  x->root=pMult_nn(x->root,a1);
83  nDelete(&a1);
84
85  x->root=pMinus_mm_Mult_qq(x->root,b1,y->root);
86
87  pDelete(&b1);
88*/
89#if 1
90  if (x->root_b==NULL)
91  {
92    if (x->root_l<=0) x->root_l=pLength(x->root);
93    x->root_b=kBucketCreate(currRing);
94    kBucketInit(x->root_b,x->root,x->root_l);
95  }
96  number coef;
97  if (y->root_l<=0) y->root_l=pLength(y->root);
98  coef=kBucketPolyRed(x->root_b,y->root,y->root_l,NULL);
99  nDelete(&coef);
100  x->root=kBucketGetLm(x->root_b);
101  if (x->root==NULL)
102  {
103    kBucketDestroy(&x->root_b);
104    x->root_b=NULL;
105    x->root_l=0;
106  }
107#else
108  x->root=ksOldSpolyRed(y->root,x->root,NULL);
109#endif
110//  if (x->root) p_Content(x->root,currRing);
111//  if (x->root) pSimpleContent(x->root,5);
112
113  return 1;
114}
115
116int ReducePoly(Poly *x,poly from,Poly *y)
117{
118  if (!x->root || !y->root)
119    return 0;
120
121/*  poly b1=pDivide(from,y->root);
122
123  number gcd=nGcd(pGetCoeff(from),pGetCoeff(y->root),currRing);
124
125  number a1=nDiv(pGetCoeff(y->root),gcd);
126  pGetCoeff(b1)=nDiv(pGetCoeff(from),gcd);
127
128  x->root=pMult_nn(x->root,a1);
129  nDelete(&a1);*/
130
131//  x->root=pMinus_mm_Mult_qq(x->root,b1,y->root);
132//  pDelete(&b1);
133
134  ksOldSpolyTail(y->root,x->root,from,NULL,currRing);
135  y->root_l=0;
136
137  return 1;
138}
139
140void PNF(Poly *p, TreeM *F)
141{
142  if (p->root==NULL) return;
143
144  Poly *f;
145  BOOLEAN done=FALSE;
146  poly temp=p->root;
147
148//  if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
149  int count=0;
150  poly pp=p->root;
151  int old_size=nSize(pGetCoeff(pp));
152  p->root_l=0;
153  while(temp->next)
154  {
155    f=is_div_(F,temp->next);
156    if (f)
157    {
158      if (ReducePoly(p,temp,f)) //temp->next
159      {
160        count++;
161        //if (TEST_OPT_PROT) { PrintS("-"); mflush(); }
162        if ((f!=NULL)
163        && (count>20)
164        && (nSize(pGetCoeff(pp))>old_size)
165        )
166        {
167           //pSimpleContent(pp,2);
168           p_Content(pp,currRing);
169           count=0;
170         //  old_size=nSize(pGetCoeff(pp));
171        }
172      }
173      done=TRUE;
174    }
175    else
176      temp=temp->next;
177   }
178
179  if (done) p_Content(p->root,currRing);
180  //if (done) pSimpleContent(p->root,-1);
181  pTest(p->root);
182}
183
184void NFL(Poly *p, TreeM *F)
185{
186  Poly *f;
187  int g1,f1,gg;
188
189  if ((f=is_div_(F,p->lead))==NULL) return;
190
191  int pX=pow_(p->lead);
192  int phX=pow_(p->history);
193
194  if (pX!=phX)
195  {
196    int phF=pow_(f->history);
197    if (pX >= (phX+phF))
198    {
199      pDelete(&p->root);
200      //p->root=NULL;
201      return;
202    }
203
204/*    poly p2=pInit();
205    pLcm(p->history,f->history,p2);
206    pSetm(p2);
207
208    if (pLmCmp(p->root,p2) > 0)
209    {
210      pLmDelete(&p2);
211      pDelete(&p->root);
212      //p->root=NULL;
213      return;
214    }
215
216    pLmDelete(&p2);
217*/
218/*    for(int i=0, gg=0 ; i<currRing->N;i++)
219      if ((g1=pGetExp(p->history,i+1)) > (f1=pGetExp(f->history,i+1)))
220        gg+=g1;
221      else gg+=f1;
222
223    if (pX > gg)
224      {
225        pDelete(&p->root);
226        //x->root=NULL;
227        return;
228    }
229*/
230    int pF=pow_(f->lead);
231
232    if ((pX == pF) && (pF == phF))
233    {
234      pLmDelete(&f->history);
235      f->history=pCopy(p->history);
236    }
237  }
238
239  //if (TEST_OPT_PROT) { PrintS("R"); mflush(); }
240  int old_size, count;
241  count=0;
242  while(f && p->root)
243  {
244//    PrintS("R");
245//    if (TEST_OPT_PROT) { PrintS("R"); mflush(); }
246#if 0
247    old_size=nSize(pGetCoeff(p->root));
248#endif
249    if (ReducePolyLead(p,f) == 0) break;
250    if (p->root!=NULL)
251    {
252      count++;
253#if 0
254      if ((count>4) && (3<nSize(pGetCoeff(p->root)))
255      && (nSize(pGetCoeff(p->root))>old_size))
256      {
257        pSimpleContent(p->root,old_size);
258        count=0;
259      }
260#else
261      if (count>500)
262      {
263        kBucketClear(p->root_b,&p->root,&p->root_l);
264        p_SimpleContent(p->root,2,currRing);
265        kBucketInit(p->root_b,p->root,p->root_l);
266        count=0;
267        //PrintS(".");
268      }
269#endif
270      f=is_div_(F,p->root);
271    }
272  }
273#if 1
274  if (p->root_b!=NULL)
275  {
276    kBucketClear(p->root_b,&p->root,&p->root_l);
277    kBucketDestroy(&p->root_b);
278    p->root_b=NULL;
279  }
280#endif
281
282  if (!p->root)
283    return;
284
285  InitHistory(p);
286  InitProl(p);
287  InitLead(p);
288  p->changed=1;
289
290  p_Content(p->root,currRing);
291  //pSimpleContent(p->root,-1);
292  pTest(p->root);
293}
294
295int ValidatePoly(Poly *x, TreeM *F)
296{
297  Poly *f,*g;
298  int g1,f1;
299
300  if (x->root) return 1;
301
302  g=is_present(T,x->history); //it's a prolongation - do we have a parent ?
303
304  if (!g)  return 0; //if not - kill him !
305
306  poly lmX=pDivide(x->lead,g->root);
307  pGetCoeff(lmX)=nInit(1);
308
309/*  if ((f=is_div_(F,lmX)) != NULL)
310  {
311    int pX=pow_(lmX);
312    int phX=pow_(x->history);
313
314    if (pX!=phX)
315    {
316      int phF=pow_(f->history);
317      if (pX >= (phX+phF))
318      {
319        pLmDelete(&lmX);
320        //x->root=NULL;
321        return 0;
322      }
323
324      for(int i=0, gg=0 ; i<currRing->N;i++)
325        if ((g1=pGetExp(x->history,i+1)) > (f1=pGetExp(f->history,i+1)))
326          gg+=g1;
327        else
328          gg+=f1;
329
330      if (pX > gg)
331      {
332        pLmDelete(&lmX);
333        return 0;
334      }
335      int pF=pow_(f->root);
336
337      if ((pX == pF) && (pF == phF))
338        f->history=x->history;
339    }
340  }
341
342  pLmDelete(&lmX);
343
344*/
345  x->root=pCopy(g->root);
346  x->root_l=g->root_l;
347
348  x->root=pMult(x->root,lmX);
349
350  pTest(x->root);
351
352  x->prolonged=-1;
353
354  return 1;
355}
356
357Poly *NewPoly(poly p)
358{
359  Poly *beg=(Poly *)GCM(sizeof(Poly));
360
361  beg->root=p;//(p == NULL ? pInit() : p);
362  beg->root_b=NULL;
363  beg->root_l=0;
364  beg->history=NULL;//pInit();
365  beg->lead=NULL;
366  beg->mult=(char *)GCMA(sizeof(char)*2*offset);
367
368  for (int i=0; i < currRing->N; i++)
369  {
370    ClearMult(beg,i);
371    ClearProl(beg,i);
372  };
373
374  beg->prolonged=-1;
375
376  return beg;
377}
378
379void DestroyPoly(Poly *x)
380{
381  pDelete(&x->root);
382  pDelete(&x->history);
383  if (x->lead) pDelete(&x->lead);
384  GCF(x->mult);
385  GCF(x);
386}
387
388void ControlProlong(Poly *x)
389{
390  for (int i = 0; i< offset; i++)
391  {
392    (x->mult+offset)[i]&=~((x->mult)[i]);
393//    if (!GetMult(x,i) && !GetProl(x,i))
394//      ProlVar(x,i);
395  }
396}
397
398void InitHistory(Poly *p)
399{
400  if (p->history) pLmDelete(&p->history);
401  p->history=pLmInit(p->root);
402  p->changed=0;
403}
404
405void InitLead(Poly *p)
406{
407  if (p->lead) pLmDelete(&p->lead);
408  p->lead=pLmInit(p->root);
409  p->prolonged=-1;
410}
411
412void InitProl(Poly *p)
413{
414  memset(p->mult+offset,0,sizeof(char)*offset);
415}
416
417int GetMult(Poly *x,int i)
418{
419  return x->mult[i/8] & Mask[i%8];
420}
421
422void SetMult(Poly *x,int i)
423{
424  x->mult[i/8] |= Mask[i%8];
425}
426
427void ClearMult(Poly *x,int i)
428{
429  x->mult[i/8] &= ~Mask[i%8];
430}
431
432int GetProl(Poly *x, int i)
433{
434  return (x->mult+offset)[i/8] & Mask[i%8];
435}
436
437void SetProl(Poly *x, int i)
438{
439  (x->mult+offset)[i/8] |= Mask[i%8];
440}
441
442void ClearProl(Poly *x, int i)
443{
444  (x->mult+offset)[i/8] &= ~Mask[i%8];
445}
446
447int LengthCompare(poly p1,poly p2)
448{
449  do
450  {
451    if (p1 == NULL) return 1;
452    if (p2 == NULL) return 0;
453    pIter(p1);
454    pIter(p2);
455  }while(p1 && p2);
456  return 1;
457}
458
459int ProlCompare(Poly *item1, Poly *item2)
460{
461  switch(pLmCmp(item1->lead,item2->lead))
462  {
463    case -1:
464      return 1;
465
466    case 1:
467      return 0;
468
469    default:
470      if ((item1->root_l<=0)||(item2->root_l<=0))
471        return LengthCompare(item1->root,item2->root);
472      return item1->root_l<=item2->root_l;
473  }
474}
475
476void ProlVar(Poly *temp,int i)
477{
478  Poly *Pr;
479
480  if (!GetProl(temp,i) && !GetMult(temp,i))
481  {
482    Pr=NewPoly();
483    SetProl(temp,i);
484
485    Pr->prolonged=i;
486    Pr->history=pLmInit(temp->history);
487    Pr->lead=pLmInit(temp->lead);
488    pIncrExp(Pr->lead,i+1);
489    pSetm(Pr->lead);
490     InitProl(temp);
491
492     Pr->changed=0;
493//    pTest(Pr->root);
494      InsertInCount(Q,Pr);
495   }
496}
497
498void DestroyListNode(ListNode *x)
499{
500  DestroyPoly(x->info);
501  GCF(x);
502}
503
504ListNode* CreateListNode(Poly *x)
505{
506  ListNode* ret=(ListNode *)GCM(sizeof(ListNode));
507  ret->info=x;
508  ret->next=NULL;
509  return ret;
510}
511
512
513Poly *FindMinList(jList *L)
514{
515  LI min=&(L->root);
516  LI l;
517  LCI xl;
518  Poly *x;
519
520  if (degree_compatible)
521  {
522    while ((*min) && ((*min)->info->root == NULL))
523      min=&((*min)->next);
524  }
525
526  if (!(*min)) return NULL;
527
528  l=&((*min)->next);
529
530  while (*l)
531  {
532    if ((*l)->info->root != NULL)
533    {
534      if (ProlCompare((*l)->info,(*min)->info))
535        min=l;
536    }
537
538    l=&((*l)->next);
539  }
540  x=(*min)->info;
541  xl=*min;
542  *min=(*min)->next;
543  GCF(xl);
544
545  return x;
546}
547
548void InsertInList(jList *x,Poly *y)
549{
550  ListNode *ins;
551  LI ix=&(x->root);
552
553  while (*ix)
554  {
555    if (pLmCmp(y->lead,(*ix)->info->lead) == -1)
556      ix=(ListNode **)&((*ix)->next);
557    else
558      break;
559  }
560
561  ins=CreateListNode(y);
562  ins->next=(ListNode *)(*ix);
563  *ix=ins;
564  return;
565}
566
567void InsertInCount(jList *x,Poly *y)
568{
569  ListNode *ins;
570  LI ix=&(x->root);
571
572  ins=CreateListNode(y);
573  ins->next=(ListNode *)(*ix);
574  *ix=ins;
575  return;
576}
577
578int ListGreatMoveOrder(jList *A,jList *B,poly x)
579{
580  LCI y=A->root;
581
582  if (!y || pLmCmp(y->info->lead,x) < 0) return 0;
583
584  while(y && pLmCmp(y->info->lead,x) >= 0)
585  {
586    InsertInCount(B,y->info);
587    A->root=y->next;
588    GCF(y);
589    y=A->root;
590  }
591
592  return 1;
593}
594
595int ListGreatMoveDegree(jList *A,jList *B,poly x)
596{
597  LCI y=A->root;
598  int pow_x=pow_(x);
599
600  if (!y || pow_(y->info->lead) <= pow_x) return 0;
601
602  while(y && pow_(y->info->lead) > pow_x)
603  {
604    InsertInCount(B,y->info);
605    A->root=y->next;
606    GCF(y);
607    y=A->root;
608  }
609
610  return 1;
611}
612
613int CountList(jList *Q)
614{
615  int i=0;
616  LCI y=Q->root;
617
618  while(y)
619  {
620    i++;
621    y=y->next;
622  }
623
624  return i;
625}
626
627void NFListQ()
628{
629  LCI ll;
630  int p,p1;
631  LI l;
632
633  do
634  {
635    if (!Q->root) break;
636
637    ll=Q->root;
638
639    p=pow_(Q->root->info->lead);
640
641    while (ll)
642    {
643      int ploc=pow_(ll->info->lead);
644      if (ploc < p) p=ploc;
645      ll=ll->next;
646    }
647
648    p1=1;
649
650    l=&(Q->root);
651
652    while (*l)
653    {
654//      PrintS("*");
655      int ploc=pow_((*l)->info->lead);
656
657      if (ploc == p)
658      {
659        if (!ValidatePoly((*l)->info,G))
660        {
661          ll=(*l);
662          *l=(*l)->next;
663          DestroyListNode(ll);
664          continue;
665        };
666
667        (*l)->info->changed=0;
668//        PrintS("!");
669        NFL((*l)->info,G);
670//                                PrintS("$");
671        if (!(*l)->info->root)
672        {
673          ll=(*l);
674          *l=(*l)->next;
675          DestroyListNode(ll);
676          continue;
677        };
678        p1=0;
679      }
680
681      l=&((*l)->next);
682    }
683  }while(p1);
684//  PrintLn();
685}
686
687
688void ForEachPNF(jList *x,int i)
689{
690  LCI y=x->root;
691
692  while(y)
693  {
694    if (pow_(y->info->root) == i) PNF(y->info,G);
695    y=y->next;
696  }
697}
698
699void ForEachControlProlong(jList *x)
700{
701  LCI y=x->root;
702
703  while(y)
704  {
705    ControlProlong(y->info);
706    y=y->next;
707  }
708}
709
710void DestroyList(jList *x)
711{
712  LCI y=x->root,z;
713
714  while(y)
715  {
716    z=y->next;
717    DestroyPoly(y->info);
718    GCF(y);
719    y=z;
720  }
721
722  GCF(x);
723}
724
725Poly* is_present(jList *F,poly x)
726{
727  LCI iF=F->root;
728  while(iF)
729    if (pLmCmp(iF->info->root,x) == 0)
730      return iF->info;
731    else iF=iF->next;
732
733  return NULL;
734}
735
736int GB_length()
737{
738  LCI iT=T->root;
739  int l=0;
740
741  while(iT)
742  {
743    if (pow_(iT->info->lead) == pow_(iT->info->history))
744      ++l;
745    iT=iT->next;
746  }
747
748  return l;
749}
750
751static Poly *temp_l;
752
753NodeM* create()
754{
755  NodeM *y;
756
757  if (FreeNodes == NULL)
758  {
759    y=(NodeM *)GCM(sizeof(NodeM));
760  }
761  else
762  {
763    y=FreeNodes;
764    FreeNodes=FreeNodes->left;
765  }
766
767  y->left=y->right=NULL;
768  y->ended=NULL;
769  return y;
770}
771
772void DestroyFreeNodes()
773{
774  NodeM *y;
775
776  while((y=FreeNodes)!=NULL)
777  {
778    FreeNodes=FreeNodes->left;
779    GCF(y);
780  }
781}
782
783static void go_right(NodeM *current,poly_function disp)
784{
785  if (current)
786  {
787    go_right(current->left,disp);
788    if (current->ended) disp(current->ended);
789    go_right(current->right,disp);
790  }
791}
792
793void ForEach(TreeM *t,poly_function disp)
794{
795  go_right(t->root,disp);
796}
797
798void DestroyTree(NodeM *G)
799{
800  if (G)
801  {
802    DestroyTree(G->left);
803    DestroyTree(G->right);
804    G->left=FreeNodes;
805    FreeNodes=G;
806  }
807}
808
809void Define(TreeM **G)
810{
811  *G=(TreeM *)GCM(sizeof(TreeM));
812  (*G)->root=create();
813}
814
815int sp_div(poly m1,poly m2,int from)
816{
817
818  if (pow_(m2) == 0 && pow_(m1)) return 0;
819
820  for(int k=from; k < currRing->N; k++)
821    if (pGetExp(m1,k+1) < pGetExp(m2,k+1)) return 0;
822
823  return 1;
824}
825
826void div_l(poly item, NodeM *x,int from)
827{
828  if (x && !temp_l)
829  {
830    div_l(item,x->left,from);
831    if ((x->ended) && sp_div(item,x->ended->root,from))
832    {
833      temp_l=x->ended;
834      return;
835    };
836    div_l(item,x->right,from);
837  }
838}
839
840Poly* is_div_upper(poly item, NodeM *x,int from)
841{
842  temp_l=NULL;
843  div_l(item,x,from);
844  return temp_l;
845}
846
847Poly* is_div_(TreeM *tree, poly item)
848{
849  int power_tmp,i,i_con=currRing->N-1;
850  NodeM *curr=tree->root;
851
852  if (!curr) return NULL;
853  if (pow_(item) == 0) return NULL;
854
855  for ( ; i_con>=0 && !pGetExp(item,i_con+1) ; i_con--)
856    ;
857
858  for (i=0; i <= i_con ; i++)
859  {
860    power_tmp=pGetExp(item,i+1);
861
862    while (power_tmp)
863    {
864      if (curr->ended) return curr->ended;
865
866      if (!curr->left)
867      {
868        if (curr->right)
869          return is_div_upper(item,curr->right,i); //??????
870        return NULL;
871      }
872
873      curr=curr->left;
874      power_tmp--;
875    }
876
877    if (curr->ended) return curr->ended;
878
879    if (!curr->right) return NULL;
880
881    curr=curr->right;
882  }
883
884  if (curr->ended) return curr->ended;
885  else return NULL;
886}
887
888static void ClearMultiplicative(NodeM *xx,int i)
889{
890  if (!xx) return;
891
892  while (xx->left)
893  {
894    ClearMultiplicative(xx->right, i);
895    xx = xx->left;
896  }
897  if ((xx->ended) && (GetMult(xx->ended,i)))
898  {
899    ClearMult(xx->ended,i);
900    ProlVar(xx->ended,i);
901  }
902  else
903    ClearMultiplicative(xx->right,i);
904}
905//======================================================
906void insert_(TreeM **tree, Poly *item)
907{
908 int power_tmp,i,i_con=currRing->N-1;
909 NodeM *curr=(*tree)->root;
910
911 for ( ; (i_con>=0) && !pGetExp(item->root,i_con+1) ; i_con--)
912  SetMult(item,i_con);
913
914 for (i = 0; i<= i_con; i++)
915 //<=
916 {
917  power_tmp=pGetExp(item->root,i+1);
918
919  ClearMult(item,i);
920
921  while (power_tmp)
922  {
923   if (!curr->left)
924   {
925     SetMult(item,i);
926     ClearMultiplicative(curr->right,i);
927     curr->left=create();
928   };
929   curr=curr->left;
930   power_tmp--;
931  };
932
933  if (i<i_con)
934  {
935   if (!curr->left) SetMult(item,i);
936   if (!curr->right) curr->right=create();
937   curr=curr->right;
938
939   ProlVar(item,i);
940  }
941 }
942
943 curr->ended=item;
944}
945
946void Initialization(char *Ord)
947{
948  offset=(currRing->N % 8 == 0) ? (currRing->N/8)*8 : (currRing->N/8+1)*8;
949  if (strstr(Ord,"dp\0") || strstr(Ord,"Dp\0"))
950  {
951    degree_compatible=1;
952    jDeg=pDeg;
953    ListGreatMove=ListGreatMoveDegree;
954  }
955  else
956  {
957    degree_compatible=0;
958    jDeg=p_Totaldegree;
959    ListGreatMove=ListGreatMoveOrder;
960  }
961
962  Define(&G);
963};
964
965static Poly *h,*f;
966
967void insert_in_G(Poly *x)
968{
969 insert_(&G,x);
970}
971
972void T2G();
973
974void Q2TG()
975{
976  LCI t;
977  Poly *x;
978
979  while (Q->root)
980  {
981    t=Q->root;
982    x=t->info;
983    insert_(&G,x);
984    InsertInList(T,x);
985    Q->root=t->next;
986    GCF(t);
987  }
988}
989
990int ComputeBasis(jList *_lT,jList *_lQ)
991{
992  int gb_l,i,ret_value=1;
993
994  T=_lT; Q=_lQ;
995
996//  Debug();
997
998  while((h=FindMinList(Q))!=NULL)
999  {
1000//        PrintS("New element\n");
1001//  Debug();
1002
1003        if (!degree_compatible)
1004        {
1005          if (!ValidatePoly(h,G))
1006          {
1007            DestroyPoly(h);
1008            continue;
1009          }
1010
1011          h->changed=0;
1012
1013          NFL(h,G);
1014
1015          if (!h->root)
1016          {
1017            DestroyPoly(h);
1018            continue;
1019          }
1020        }
1021
1022        if (h->root)
1023        {
1024          if (pIsConstant(h->root))
1025          {
1026            WarnS("Constant in basis\n");
1027            return 0;
1028          }
1029
1030          if (h->changed && ListGreatMove(T,Q,h->root))
1031          {
1032//      PrintS("<-\n");
1033            DestroyTree(G->root);
1034            G->root=create();
1035            T2G();
1036          }
1037        }
1038
1039//  PrintS("PNF\n");
1040        PNF(h,G);
1041//        Print("{%d}\n",pow_(h->root));
1042        insert_(&G,h);
1043        InsertInList(T,h);
1044
1045//  PrintS("For each PNF\n");
1046        if (degree_compatible)
1047            ForEachPNF(T,pow_(h->root));
1048
1049//  PrintS("Control of prolongations\n");
1050        if (h->changed)
1051            ForEachControlProlong(T);
1052        else
1053            ControlProlong(h);
1054
1055//  Debug();
1056
1057//  PrintS("NFListQ\n");
1058        if (degree_compatible)
1059            NFListQ();
1060//Debug();
1061    }
1062
1063//    gb_l=GB_length();
1064
1065    Print("Length of Janet basis: %d\n",CountList(T));
1066//    Print("Length of Groebner basis:    %d\n",gb_l);
1067
1068    DestroyTree(G->root);
1069    GCF(G);
1070    DestroyFreeNodes();
1071
1072    return 1;
1073}
1074
1075void T2G()
1076{
1077 LCI i=T->root;
1078 while (i)
1079 {
1080  insert_(&G,i->info);
1081  i=i->next;
1082 }
1083}
Note: See TracBrowser for help on using the repository browser.