source: git/Singular/janet.cc @ 312083

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