My Project  UNKNOWN_GIT_VERSION
janet.cc
Go to the documentation of this file.
1 
2 
3 #include "kernel/mod2.h"
4 #include "omalloc/omalloc.h"
5 
6 #include "coeffs/numbers.h"
7 
8 #include "polys/monomials/ring.h"
10 #include "polys/kbuckets.h"
11 
12 #include "kernel/ideals.h"
13 #include "kernel/polys.h"
14 #include "kernel/GBEngine/kutil.h"
15 #include "kernel/GBEngine/janet.h"
16 
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <stdarg.h>
22 #include <time.h>
23 
24 #if (defined(__CYGWIN__))
25 #include <ctype.h>
26 #endif
27 
28 
29 //------GLOBALS-------
30 static int /*m_s,v_s,vectorized,VarN1,*/offset;
31 static jList *T,*Q;
32 static TreeM *G;
33 // static Poly *phD;
34 static NodeM *FreeNodes;
35 static int degree_compatible;
36 static int (*ListGreatMove)(jList *,jList *,poly);
37 static int Mask[8]={0x80,0x40,0x20,0x10,0x8,0x4,0x2,0x1};
38 
39 //#define DebugPrint
40 
41 //#define pow_(x) pTotaldegree((x))
42 //#define pow_(x) p_Deg((x,currRing))
44 #define pow_(x) jDeg((x),currRing)
45 
46 #if 0
47 void Debug()
48 {
49  LCI it=T->root;
50 
51  PrintS("T==================================\n");
52  while (it)
53  {
54  pWrite(it->info->root);
55  it=it->next;
56  }
57 
58  it=Q->root;
59 
60  PrintS("Q==================================\n");
61  while (it)
62  {
63  if (it->info->root) pWrite(it->info->root);
64  else
65  {
66  Print("%d.........",it->info->prolonged);
67  pWrite(it->info->history);
68  }
69  it=it->next;
70  }
71  PrintS("===================================\n");
72 }
73 #endif
74 
76 {
77  if (!x->root || !y->root)
78  return 0;
79 
80 /* poly b1=pMDivide(x->root,y->root);
81 
82  number gcd=n_Gcd(pGetCoeff(x->root),pGetCoeff(y->root),currRing->cf);
83 
84  number a1=nDiv(pGetCoeff(y->root),gcd);
85  pGetCoeff(b1)=nDiv(pGetCoeff(x->root),gcd);
86 
87  x->root=pMult_nn(x->root,a1);
88  nDelete(&a1);
89 
90  x->root=pMinus_mm_Mult_qq(x->root,b1,y->root);
91 
92  pDelete(&b1);
93 */
94 #if 1
95  if (x->root_b==NULL)
96  {
97  if (x->root_l<=0) x->root_l=pLength(x->root);
98  x->root_b=kBucketCreate(currRing);
99  kBucketInit(x->root_b,x->root,x->root_l);
100  }
101  number coef;
102  if (y->root_l<=0) y->root_l=pLength(y->root);
103  coef=kBucketPolyRed(x->root_b,y->root,y->root_l,NULL);
104  nDelete(&coef);
105  x->root=kBucketGetLm(x->root_b);
106  if (x->root==NULL)
107  {
108  kBucketDestroy(&x->root_b);
109  x->root_b=NULL;
110  x->root_l=0;
111  }
112 #else
113  x->root=ksOldSpolyRed(y->root,x->root,NULL);
114 #endif
115 // if (x->root) p_SimpleContent(x->root,5,currRing);
116 
117  return 1;
118 }
119 
120 int ReducePoly(Poly *x,poly from,Poly *y)
121 {
122  if (!x->root || !y->root)
123  return 0;
124 
125 /* poly b1=pMDivide(from,y->root);
126 
127  number gcd=n_Gcd(pGetCoeff(from),pGetCoeff(y->root),currRing->cf);
128 
129  number a1=nDiv(pGetCoeff(y->root),gcd);
130  pGetCoeff(b1)=nDiv(pGetCoeff(from),gcd);
131 
132  x->root=pMult_nn(x->root,a1);
133  nDelete(&a1);*/
134 
135 // x->root=pMinus_mm_Mult_qq(x->root,b1,y->root);
136 // pDelete(&b1);
137 
138  ksOldSpolyTail(y->root,x->root,from,NULL,currRing);
139  y->root_l=0;
140 
141  return 1;
142 }
143 
144 void PNF(Poly *p, TreeM *F)
145 {
146  if (p->root==NULL) return;
147 
148  Poly *f;
149  BOOLEAN done=FALSE;
150  poly temp=p->root;
151 
152 // if (TEST_OPT_PROT) { PrintS("r"); mflush(); }
153  int count=0;
154  poly pp=p->root;
155  int old_size=nSize(pGetCoeff(pp));
156  p->root_l=0;
157  while(temp->next)
158  {
159  f=is_div_(F,temp->next);
160  if (f)
161  {
162  if (ReducePoly(p,temp,f)) //temp->next
163  {
164  count++;
165  //if (TEST_OPT_PROT) { PrintS("-"); mflush(); }
166  if ((f!=NULL)
167  && (count>20)
168  && (nSize(pGetCoeff(pp))>old_size)
169  )
170  {
172  //p_Content(pp,currRing);
173  count=0;
174  // old_size=nSize(pGetCoeff(pp));
175  }
176  }
177  done=TRUE;
178  }
179  else
180  temp=temp->next;
181  }
182 
183  if (done) p_ContentForGB(p->root,currRing);
184  //if (done) p_SimpleContent(p->root,-1,currRing);
185  pTest(p->root);
186 }
187 
188 void NFL(Poly *p, TreeM *F)
189 {
190  Poly *f;
191  // int g1,f1,gg;
192 
193  if ((f=is_div_(F,p->lead))==NULL) return;
194 
195  int pX=pow_(p->lead);
196  int phX=pow_(p->history);
197 
198  if (pX!=phX)
199  {
200  int phF=pow_(f->history);
201  if (pX >= (phX+phF))
202  {
203  pDelete(&p->root);
204  //p->root=NULL;
205  return;
206  }
207 
208 /* poly p2=pInit();
209  pLcm(p->history,f->history,p2);
210  pSetm(p2);
211 
212  if (pLmCmp(p->root,p2) > 0)
213  {
214  pLmDelete(&p2);
215  pDelete(&p->root);
216  //p->root=NULL;
217  return;
218  }
219 
220  pLmDelete(&p2);
221 */
222 /* for(int i=0, gg=0 ; i<currRing->N;i++)
223  if ((g1=pGetExp(p->history,i+1)) > (f1=pGetExp(f->history,i+1)))
224  gg+=g1;
225  else gg+=f1;
226 
227  if (pX > gg)
228  {
229  pDelete(&p->root);
230  //x->root=NULL;
231  return;
232  }
233 */
234  int pF=pow_(f->lead);
235 
236  if ((pX == pF) && (pF == phF))
237  {
238  pLmFree(&f->history);
239  if (p->history!=NULL)
240  f->history=p_Copy_noCheck(p->history,currRing); /* cf of p->history is NULL */
241  }
242  }
243 
244  //if (TEST_OPT_PROT) { PrintS("R"); mflush(); }
245  int /*old_size, */count;
246  count=0;
247  while(f && p->root)
248  {
249 // PrintS("R");
250 // if (TEST_OPT_PROT) { PrintS("R"); mflush(); }
251 #if 0
252  old_size=nSize(pGetCoeff(p->root));
253 #endif
254  if (ReducePolyLead(p,f) == 0) break;
255  if (p->root!=NULL)
256  {
257  count++;
258 #if 0
259  if ((count>4) && (3<nSize(pGetCoeff(p->root)))
260  && (nSize(pGetCoeff(p->root))>old_size))
261  {
262  p_SimpleContent(p->root,old_size,currRing);
263  count=0;
264  }
265 #else
266  if (count>50)
267  {
268  kBucketClear(p->root_b,&p->root,&p->root_l);
269  p_SimpleContent(p->root,2,currRing);
270  kBucketInit(p->root_b,p->root,p->root_l);
271  count=0;
272  //PrintS(".");
273  }
274 #endif
275  f=is_div_(F,p->root);
276  }
277  }
278 #if 1
279  if (p->root_b!=NULL)
280  {
281  kBucketClear(p->root_b,&p->root,&p->root_l);
282  kBucketDestroy(&p->root_b);
283  p->root_b=NULL;
284  }
285 #endif
286 
287  if (!p->root)
288  return;
289 
290  InitHistory(p);
291  InitProl(p);
292  InitLead(p);
293  p->changed=1;
294 
295  p_ContentForGB(p->root,currRing);
296  //p_SimpleContent(p->root,-1i,currRing);
297  pTest(p->root);
298 }
299 
300 int ValidatePoly(Poly *x, TreeM */*F*/)
301 {
302  Poly /*f,*/*g;
303  // int g1,f1;
304 
305  if (x->root) return 1;
306 
307  g=is_present(T,x->history); //it's a prolongation - do we have a parent ?
308 
309  if (!g) return 0; //if not - kill him !
310 
311  poly lmX=pMDivide(x->lead,g->root);
312  pSetCoeff0(lmX,nInit(1));
313 
314 /* if ((f=is_div_(F,lmX)) != NULL)
315  {
316  int pX=pow_(lmX);
317  int phX=pow_(x->history);
318 
319  if (pX!=phX)
320  {
321  int phF=pow_(f->history);
322  if (pX >= (phX+phF))
323  {
324  pLmDelete(&lmX);
325  //x->root=NULL;
326  return 0;
327  }
328 
329  for(int i=0, gg=0 ; i<currRing->N;i++)
330  if ((g1=pGetExp(x->history,i+1)) > (f1=pGetExp(f->history,i+1)))
331  gg+=g1;
332  else
333  gg+=f1;
334 
335  if (pX > gg)
336  {
337  pLmDelete(&lmX);
338  return 0;
339  }
340  int pF=pow_(f->root);
341 
342  if ((pX == pF) && (pF == phF))
343  f->history=x->history;
344  }
345  }
346 
347  pLmDelete(&lmX);
348 
349 */
350  x->root=pCopy(g->root);
351  x->root_l=g->root_l;
352 
353  x->root=pMult(x->root,lmX);
354 
355  pTest(x->root);
356 
357  x->prolonged=-1;
358 
359  return 1;
360 }
361 
362 Poly *NewPoly(poly p)
363 {
364  Poly *beg=(Poly *)GCM(sizeof(Poly));
365 
366  beg->root=p;//(p == NULL ? pInit() : p);
367  beg->root_b=NULL;
368  beg->root_l=0;
369  beg->history=NULL;//pInit();
370  beg->lead=NULL;
371  beg->mult=(char *)GCMA(sizeof(char)*2*offset);
372 
373  for (int i=0; i < currRing->N; i++)
374  {
375  ClearMult(beg,i);
376  ClearProl(beg,i);
377  };
378 
379  beg->prolonged=-1;
380 
381  return beg;
382 }
383 
385 {
386  pDelete(&x->root);
387  pLmFree(&x->history);
388  if (x->lead!=NULL) pLmFree(&x->lead);
389  GCF(x->mult);
390  GCF(x);
391 }
392 
394 {
395  for (int i = 0; i< offset; i++)
396  {
397  (x->mult+offset)[i]&=~((x->mult)[i]);
398 // if (!GetMult(x,i) && !GetProl(x,i))
399 // ProlVar(x,i);
400  }
401 }
402 
404 {
405  if (p->history) pLmFree(&p->history);
406  p->history=pLmInit(p->root);
407  p->changed=0;
408 }
409 
411 {
412  if (p->lead!=NULL) pLmFree(&p->lead);
413  p->lead=pLmInit(p->root);
414  p->prolonged=-1;
415 }
416 
418 {
419  memset(p->mult+offset,0,sizeof(char)*offset);
420 }
421 
422 int GetMult(Poly *x,int i)
423 {
424  return x->mult[i/8] & Mask[i%8];
425 }
426 
427 void SetMult(Poly *x,int i)
428 {
429  x->mult[i/8] |= Mask[i%8];
430 }
431 
432 void ClearMult(Poly *x,int i)
433 {
434  x->mult[i/8] &= ~Mask[i%8];
435 }
436 
437 int GetProl(Poly *x, int i)
438 {
439  return (x->mult+offset)[i/8] & Mask[i%8];
440 }
441 
442 void SetProl(Poly *x, int i)
443 {
444  (x->mult+offset)[i/8] |= Mask[i%8];
445 }
446 
447 void ClearProl(Poly *x, int i)
448 {
449  (x->mult+offset)[i/8] &= ~Mask[i%8];
450 }
451 
452 int LengthCompare(poly p1,poly p2)
453 {
454  do
455  {
456  if (p1 == NULL) return 1;
457  if (p2 == NULL) return 0;
458  pIter(p1);
459  pIter(p2);
460  }while(p1 && p2);
461  return 1;
462 }
463 
464 int ProlCompare(Poly *item1, Poly *item2)
465 {
466  switch(pLmCmp(item1->lead,item2->lead))
467  {
468  case -1:
469  return 1;
470 
471  case 1:
472  return 0;
473 
474  default:
475  if ((item1->root_l<=0)||(item2->root_l<=0))
476  return LengthCompare(item1->root,item2->root);
477  return item1->root_l<=item2->root_l;
478  }
479 }
480 
481 void ProlVar(Poly *temp,int i)
482 {
483  Poly *Pr;
484 
485  if (!GetProl(temp,i) && !GetMult(temp,i))
486  {
487  Pr=NewPoly();
488  SetProl(temp,i);
489 
490  Pr->prolonged=i;
491  Pr->history=pLmInit(temp->history);
492  Pr->lead=pLmInit(temp->lead);
493  pIncrExp(Pr->lead,i+1);
494  pSetm(Pr->lead);
495  InitProl(temp);
496 
497  Pr->changed=0;
498 // pTest(Pr->root);
499  InsertInCount(Q,Pr);
500  }
501 }
502 
504 {
505  DestroyPoly(x->info);
506  GCF(x);
507 }
508 
510 {
511  ListNode* ret=(ListNode *)GCM(sizeof(ListNode));
512  ret->info=x;
513  ret->next=NULL;
514  return ret;
515 }
516 
517 
519 {
520  LI min=&(L->root);
521  LI l;
522  LCI xl;
523  Poly *x;
524 
525  if (degree_compatible)
526  {
527  while ((*min) && ((*min)->info->root == NULL))
528  min=&((*min)->next);
529  }
530 
531  if (!(*min)) return NULL;
532 
533  l=&((*min)->next);
534 
535  while (*l)
536  {
537  if ((*l)->info->root != NULL)
538  {
539  if (ProlCompare((*l)->info,(*min)->info))
540  min=l;
541  }
542 
543  l=&((*l)->next);
544  }
545  x=(*min)->info;
546  xl=*min;
547  *min=(*min)->next;
548  GCF(xl);
549 
550  return x;
551 }
552 
554 {
555  ListNode *ins;
556  LI ix=&(x->root);
557 
558  while (*ix)
559  {
560  if (pLmCmp(y->lead,(*ix)->info->lead) == -1)
561  ix=(ListNode **)&((*ix)->next);
562  else
563  break;
564  }
565 
566  ins=CreateListNode(y);
567  ins->next=(ListNode *)(*ix);
568  *ix=ins;
569  return;
570 }
571 
573 {
574  ListNode *ins;
575  LI ix=&(x->root);
576 
577  ins=CreateListNode(y);
578  ins->next=(ListNode *)(*ix);
579  *ix=ins;
580  return;
581 }
582 
584 {
585  LCI y=A->root;
586 
587  if (!y || pLmCmp(y->info->lead,x) < 0) return 0;
588 
589  while(y && pLmCmp(y->info->lead,x) >= 0)
590  {
591  InsertInCount(B,y->info);
592  A->root=y->next;
593  GCF(y);
594  y=A->root;
595  }
596 
597  return 1;
598 }
599 
601 {
602  LCI y=A->root;
603  int pow_x=pow_(x);
604 
605  if (!y || pow_(y->info->lead) <= pow_x) return 0;
606 
607  while(y && pow_(y->info->lead) > pow_x)
608  {
609  InsertInCount(B,y->info);
610  A->root=y->next;
611  GCF(y);
612  y=A->root;
613  }
614 
615  return 1;
616 }
617 
619 {
620  int i=0;
621  LCI y=Q->root;
622 
623  while(y)
624  {
625  i++;
626  y=y->next;
627  }
628 
629  return i;
630 }
631 
632 void NFListQ()
633 {
634  LCI ll;
635  int p,p1;
636  LI l;
637 
638  do
639  {
640  if (!Q->root) break;
641 
642  ll=Q->root;
643 
644  p=pow_(Q->root->info->lead);
645 
646  while (ll)
647  {
648  int ploc=pow_(ll->info->lead);
649  if (ploc < p) p=ploc;
650  ll=ll->next;
651  }
652 
653  p1=1;
654 
655  l=&(Q->root);
656 
657  while (*l)
658  {
659 // PrintS("*");
660  int ploc=pow_((*l)->info->lead);
661 
662  if (ploc == p)
663  {
664  if (!ValidatePoly((*l)->info,G))
665  {
666  ll=(*l);
667  *l=(*l)->next;
668  DestroyListNode(ll);
669  continue;
670  };
671 
672  (*l)->info->changed=0;
673 // PrintS("!");
674  NFL((*l)->info,G);
675 // PrintS("$");
676  if (!(*l)->info->root)
677  {
678  ll=(*l);
679  *l=(*l)->next;
680  DestroyListNode(ll);
681  continue;
682  };
683  p1=0;
684  }
685 
686  l=&((*l)->next);
687  }
688  }while(p1);
689 // PrintLn();
690 }
691 
692 
693 void ForEachPNF(jList *x,int i)
694 {
695  LCI y=x->root;
696 
697  while(y)
698  {
699  if (pow_(y->info->root) == i) PNF(y->info,G);
700  y=y->next;
701  }
702 }
703 
705 {
706  LCI y=x->root;
707 
708  while(y)
709  {
710  ControlProlong(y->info);
711  y=y->next;
712  }
713 }
714 
716 {
717  LCI y=x->root,z;
718 
719  while(y)
720  {
721  z=y->next;
722  DestroyPoly(y->info);
723  GCF(y);
724  y=z;
725  }
726 
727  GCF(x);
728 }
729 
731 {
732  LCI iF=F->root;
733  while(iF)
734  if (pLmCmp(iF->info->root,x) == 0)
735  return iF->info;
736  else iF=iF->next;
737 
738  return NULL;
739 }
740 
742 {
743  LCI iT=T->root;
744  int l=0;
745 
746  while(iT)
747  {
748  if (pow_(iT->info->lead) == pow_(iT->info->history))
749  ++l;
750  iT=iT->next;
751  }
752 
753  return l;
754 }
755 
756 static Poly *temp_l;
757 
759 {
760  NodeM *y;
761 
762  if (FreeNodes == NULL)
763  {
764  y=(NodeM *)GCM(sizeof(NodeM));
765  }
766  else
767  {
768  y=FreeNodes;
769  FreeNodes=FreeNodes->left;
770  }
771 
772  y->left=y->right=NULL;
773  y->ended=NULL;
774  return y;
775 }
776 
778 {
779  NodeM *y;
780 
781  while((y=FreeNodes)!=NULL)
782  {
783  FreeNodes=FreeNodes->left;
784  GCF(y);
785  }
786 }
787 
788 #if 0
789 static void go_right(NodeM *current,poly_function disp)
790 {
791  if (current)
792  {
793  go_right(current->left,disp);
794  if (current->ended) disp(current->ended);
795  go_right(current->right,disp);
796  }
797 }
798 
799 void ForEach(TreeM *t,poly_function disp)
800 {
801  go_right(t->root,disp);
802 }
803 #endif
804 
806 {
807  if (G)
808  {
809  DestroyTree(G->left);
810  DestroyTree(G->right);
811  G->left=FreeNodes;
812  FreeNodes=G;
813  }
814 }
815 
816 void Define(TreeM **G)
817 {
818  *G=(TreeM *)GCM(sizeof(TreeM));
819  (*G)->root=create();
820 }
821 
822 int 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 
833 void 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 
847 Poly* 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 
854 Poly* 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 
895 static 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 //======================================================
913 void 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 
953 void 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  {
959  jDeg=p_Deg;
961  }
962  else
963  {
967  }
968 
969  Define(&G);
970 }
971 
972 static Poly *h/*,*f*/;
973 
974 #if 0
975 void insert_in_G(Poly *x)
976 {
977  insert_(&G,x);
978 }
979 #endif
980 
981 void T2G();
982 
983 #if 0
984 void 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 #endif
1000 
1001 int ComputeBasis(jList *_lT,jList *_lQ)
1002 {
1003  // int gb_l,i,ret_value=1;
1004 
1005  T=_lT; Q=_lQ;
1006 
1007 // Debug();
1008 
1009  while((h=FindMinList(Q))!=NULL)
1010  {
1011 // PrintS("New element\n");
1012 // Debug();
1013 
1014  if (!degree_compatible)
1015  {
1016  if (!ValidatePoly(h,G))
1017  {
1018  DestroyPoly(h);
1019  continue;
1020  }
1021 
1022  h->changed=0;
1023 
1024  NFL(h,G);
1025 
1026  if (!h->root)
1027  {
1028  DestroyPoly(h);
1029  continue;
1030  }
1031  }
1032 
1033  if (h->root)
1034  {
1035  if (pIsConstant(h->root))
1036  {
1037  WarnS("Constant in basis\n");
1038  return 0;
1039  }
1040 
1041  if (h->changed && ListGreatMove(T,Q,h->root))
1042  {
1043 // PrintS("<-\n");
1044  DestroyTree(G->root);
1045  G->root=create();
1046  T2G();
1047  }
1048  }
1049 
1050 // PrintS("PNF\n");
1051  PNF(h,G);
1052 // Print("{%d}\n",pow_(h->root));
1053  insert_(&G,h);
1054  InsertInList(T,h);
1055 
1056 // PrintS("For each PNF\n");
1057  if (degree_compatible)
1058  ForEachPNF(T,pow_(h->root));
1059 
1060 // PrintS("Control of prolongations\n");
1061  if (h->changed)
1063  else
1064  ControlProlong(h);
1065 
1066 // Debug();
1067 
1068 // PrintS("NFListQ\n");
1069  if (degree_compatible)
1070  NFListQ();
1071 //Debug();
1072  }
1073 
1074 // gb_l=GB_length();
1075 
1076  Print("Length of Janet basis: %d\n",CountList(T));
1077 // Print("Length of Groebner basis: %d\n",gb_l);
1078 
1079  DestroyTree(G->root);
1080  GCF(G);
1081  DestroyFreeNodes();
1082 
1083  return 1;
1084 }
1085 
1086 void T2G()
1087 {
1088  LCI i=T->root;
1089  while (i)
1090  {
1091  insert_(&G,i->info);
1092  i=i->next;
1093  }
1094 }
DestroyPoly
void DestroyPoly(Poly *x)
Definition: janet.cc:384
ClearProl
void ClearProl(Poly *x, int i)
Definition: janet.cc:447
ReducePoly
int ReducePoly(Poly *x, poly from, Poly *y)
Definition: janet.cc:120
FALSE
#define FALSE
Definition: auxiliary.h:94
InitLead
void InitLead(Poly *p)
Definition: janet.cc:410
omalloc.h
janet.h
pIsConstant
#define pIsConstant(p)
like above, except that Comp might be != 0
Definition: polys.h:223
temp_l
static Poly * temp_l
Definition: janet.cc:756
kutil.h
f
FILE * f
Definition: checklibs.c:9
Poly::changed
int changed
Definition: janet.h:22
Poly
Definition: janet.h:14
offset
static int offset
Definition: janet.cc:30
DestroyFreeNodes
void DestroyFreeNodes()
Definition: janet.cc:777
k
int k
Definition: cfEzgcd.cc:92
pLmFree
static void pLmFree(poly p)
frees the space of the monomial m, assumes m != NULL coef is not freed, m is not advanced
Definition: polys.h:68
is_present
Poly * is_present(jList *F, poly x)
Definition: janet.cc:730
x
Variable x
Definition: cfModGcd.cc:4023
Poly::prolonged
int prolonged
Definition: janet.h:23
y
const CanonicalForm int const CFList const Variable & y
Definition: facAbsFact.cc:57
InsertInList
void InsertInList(jList *x, Poly *y)
Definition: janet.cc:553
ForEachPNF
void ForEachPNF(jList *x, int i)
Definition: janet.cc:693
pGetExp
#define pGetExp(p, i)
Exponent.
Definition: polys.h:40
pFDegProc
long(* pFDegProc)(poly p, ring r)
Definition: ring.h:38
NFListQ
void NFListQ()
Definition: janet.cc:632
Poly::root_b
kBucket_pt root_b
Definition: janet.h:17
kBucketPolyRed
number kBucketPolyRed(kBucket_pt bucket, poly p1, int l1, poly spNoether)
Definition: kbuckets.cc:1075
Poly::history
poly history
Definition: janet.h:19
create
NodeM * create()
Definition: janet.cc:758
polys.h
g
g
Definition: cfModGcd.cc:4031
FreeNodes
static NodeM * FreeNodes
Definition: janet.cc:34
GetProl
int GetProl(Poly *x, int i)
Definition: janet.cc:437
kBucketGetLm
const poly kBucketGetLm(kBucket_pt bucket)
Definition: kbuckets.cc:502
pDelete
#define pDelete(p_ptr)
Definition: polys.h:174
p_SimpleContent
void p_SimpleContent(poly ph, int smax, const ring r)
Definition: p_polys.cc:2489
Variable::next
Variable next() const
Definition: factory.h:137
ComputeBasis
int ComputeBasis(jList *_lT, jList *_lQ)
Definition: janet.cc:1001
pMult
#define pMult(p, q)
Definition: polys.h:194
InsertInCount
void InsertInCount(jList *x, Poly *y)
Definition: janet.cc:572
pIncrExp
#define pIncrExp(p, i)
Definition: polys.h:42
InitHistory
void InitHistory(Poly *p)
Definition: janet.cc:403
TreeM
TreeM
Definition: janet.h:46
Initialization
void Initialization(char *Ord)
Definition: janet.cc:953
pLength
static unsigned pLength(poly a)
Definition: p_polys.h:184
SetMult
void SetMult(Poly *x, int i)
Definition: janet.cc:427
NodeM
NodeM
Definition: janet.h:40
DestroyTree
void DestroyTree(NodeM *G)
Definition: janet.cc:805
ForEachControlProlong
void ForEachControlProlong(jList *x)
Definition: janet.cc:704
ListNode
ListNode
Definition: janet.h:29
currRing
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:13
jList::root
ListNode * root
Definition: janet.h:36
is_div_upper
Poly * is_div_upper(poly item, NodeM *x, int from)
Definition: janet.cc:847
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
GB_length
int GB_length()
Definition: janet.cc:741
PNF
void PNF(Poly *p, TreeM *F)
Definition: janet.cc:144
kBucketDestroy
void kBucketDestroy(kBucket_pt *bucket_pt)
Definition: kbuckets.cc:212
LCI
ListNode * LCI
Definition: janet.h:48
GCMA
#define GCMA(sz)
Definition: janet.h:7
PrintS
void PrintS(const char *s)
Definition: reporter.cc:283
BOOLEAN
int BOOLEAN
Definition: auxiliary.h:85
pTest
#define pTest(p)
Definition: polys.h:396
pow_
#define pow_(x)
Definition: janet.cc:44
kBucketInit
void kBucketInit(kBucket_pt bucket, poly lm, int length)
Definition: kbuckets.cc:489
jDeg
pFDegProc jDeg
Definition: janet.cc:43
T
static jList * T
Definition: janet.cc:31
NFL
void NFL(Poly *p, TreeM *F)
Definition: janet.cc:188
h
static Poly * h
Definition: janet.cc:972
LI
ListNode ** LI
Definition: janet.h:51
mod2.h
Poly::mult
char * mult
Definition: janet.h:21
Mask
static int Mask[8]
Definition: janet.cc:37
degree_compatible
static int degree_compatible
Definition: janet.cc:35
pIter
#define pIter(p)
Definition: monomials.h:35
LengthCompare
int LengthCompare(poly p1, poly p2)
Definition: janet.cc:452
SetProl
void SetProl(Poly *x, int i)
Definition: janet.cc:442
p_polys.h
InitProl
void InitProl(Poly *p)
Definition: janet.cc:417
ListGreatMoveDegree
int ListGreatMoveDegree(jList *A, jList *B, poly x)
Definition: janet.cc:600
poly_function
void(* poly_function)(Poly *)
Definition: janet.h:26
pp
CanonicalForm pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f )
Definition: cf_gcd.cc:248
kBucketClear
void kBucketClear(kBucket_pt bucket, poly *p, int *length)
Definition: kbuckets.cc:517
pMDivide
#define pMDivide(a, b)
Definition: polys.h:275
ProlVar
void ProlVar(Poly *temp, int i)
Definition: janet.cc:481
jList
Definition: janet.h:34
ksOldSpolyRed
KINLINE poly ksOldSpolyRed(poly p1, poly p2, poly spNoether)
Definition: kInline.h:1041
ClearMult
void ClearMult(Poly *x, int i)
Definition: janet.cc:432
pLmInit
#define pLmInit(p)
like pInit, except that expvector is initialized to that of p, p must be != NULL
Definition: polys.h:62
DestroyListNode
void DestroyListNode(ListNode *x)
Definition: janet.cc:503
DestroyList
void DestroyList(jList *x)
Definition: janet.cc:715
CreateListNode
ListNode * CreateListNode(Poly *x)
Definition: janet.cc:509
kbuckets.h
p_ContentForGB
void p_ContentForGB(poly ph, const ring r)
Definition: p_polys.cc:2280
ring.h
p_Deg
long p_Deg(poly a, const ring r)
Definition: p_polys.cc:578
ClearMultiplicative
static void ClearMultiplicative(NodeM *xx, int i)
Definition: janet.cc:895
GCF
#define GCF(x)
Definition: janet.h:8
min
static int min(int a, int b)
Definition: fast_mult.cc:268
p_Copy_noCheck
static poly p_Copy_noCheck(poly p, const ring r)
returns a copy of p (without any additional testing)
Definition: p_polys.h:788
FindMinList
Poly * FindMinList(jList *L)
Definition: janet.cc:518
Print
#define Print
Definition: emacs.cc:79
B
b *CanonicalForm B
Definition: facBivar.cc:52
ListGreatMove
static int(* ListGreatMove)(jList *, jList *, poly)
Definition: janet.cc:36
pSetCoeff0
#define pSetCoeff0(p, n)
Definition: monomials.h:57
GCM
#define GCM(sz)
Definition: janet.h:6
Poly::root
poly root
Definition: janet.h:16
WarnS
#define WarnS
Definition: emacs.cc:77
Q
static jList * Q
Definition: janet.cc:31
NULL
#define NULL
Definition: omList.c:9
is_div_
Poly * is_div_(TreeM *tree, poly item)
Definition: janet.cc:854
ControlProlong
void ControlProlong(Poly *x)
Definition: janet.cc:393
pSetm
#define pSetm(p)
Definition: polys.h:254
ideals.h
insert_
void insert_(TreeM **tree, Poly *item)
Definition: janet.cc:913
l
int l
Definition: cfEzgcd.cc:93
ReducePolyLead
int ReducePolyLead(Poly *x, Poly *y)
Definition: janet.cc:75
nDelete
#define nDelete(n)
Definition: numbers.h:16
ProlCompare
int ProlCompare(Poly *item1, Poly *item2)
Definition: janet.cc:464
ksOldSpolyTail
void ksOldSpolyTail(poly p1, poly q, poly q2, poly spNoether, ring r)
Definition: kInline.h:1071
p_Totaldegree
static long p_Totaldegree(poly p, const ring r)
Definition: p_polys.h:1426
Poly::lead
poly lead
Definition: janet.h:20
p
int p
Definition: cfModGcd.cc:4019
CountList
int CountList(jList *Q)
Definition: janet.cc:618
div_l
void div_l(poly item, NodeM *x, int from)
Definition: janet.cc:833
kBucketCreate
kBucket_pt kBucketCreate(const ring bucket_ring)
Creation/Destruction of buckets.
Definition: kbuckets.cc:205
nInit
#define nInit(i)
Definition: numbers.h:24
pLmCmp
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition: polys.h:101
count
int status int void size_t count
Definition: si_signals.h:58
GetMult
int GetMult(Poly *x, int i)
Definition: janet.cc:422
ListGreatMoveOrder
int ListGreatMoveOrder(jList *A, jList *B, poly x)
Definition: janet.cc:583
pCopy
#define pCopy(p)
return a copy of the poly
Definition: polys.h:173
Define
void Define(TreeM **G)
Definition: janet.cc:816
pGetCoeff
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition: monomials.h:42
G
static TreeM * G
Definition: janet.cc:32
ValidatePoly
int ValidatePoly(Poly *x, TreeM *)
Definition: janet.cc:300
A
#define A
Definition: sirandom.c:23
NewPoly
Poly * NewPoly(poly p)
Definition: janet.cc:362
numbers.h
Poly::root_l
int root_l
Definition: janet.h:18
T2G
void T2G()
Definition: janet.cc:1086
sp_div
int sp_div(poly m1, poly m2, int from)
Definition: janet.cc:822
nSize
#define nSize(n)
Definition: numbers.h:39
pWrite
void pWrite(poly p)
Definition: polys.h:290