source: git/Singular/janet.cc @ db34980

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