source: git/Singular/janet.cc @ b38f81

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