walk.cc
Go to the documentation of this file.
1 /*****************************************
2 * Computer Algebra System SINGULAR *
3 *****************************************/
4 /* $Id$ */
5 /*
6 * ABSTRACT: Implementation of the Groebner walk
7 */
8 
9 // define if the Buchberger alg should be used
10 // to compute a reduced GB of a omega-homogenoues ideal
11 // default: we use the hilbert driven algorithm.
12 #define BUCHBERGER_ALG //we use the improved Buchberger alg.
13 
14 //#define UPPER_BOUND //for the original "Tran" algorithm
15 //#define REPRESENTATION_OF_SIGMA //if one perturbs sigma in Tran
16 
17 //#define TEST_OVERFLOW
18 //#define CHECK_IDEAL
19 //#define CHECK_IDEAL_MWALK
20 
21 //#define NEXT_VECTORS_CC
22 //#define PRINT_VECTORS //to print vectors (sigma, tau, omega)
23 
24 #define INVEPS_SMALL_IN_FRACTAL //to choose the small invers of epsilon
25 #define INVEPS_SMALL_IN_MPERTVECTOR //to choose the small invers of epsilon
26 #define INVEPS_SMALL_IN_TRAN //to choose the small invers of epsilon
27 
28 #define FIRST_STEP_FRACTAL // to define the first step of the fractal
29 //#define MSTDCC_FRACTAL // apply Buchberger alg to compute a red GB, if
30 // tau doesn't stay in the correct cone
31 
32 //#define TIME_TEST // print the used time of each subroutine
33 //#define ENDWALKS //print the size of the last omega-homogenoues Groebner basis
34 
35 /* includes */
36 
37 #include <kernel/mod2.h>
38 #include <misc/intvec.h>
39 #include <Singular/cntrlc.h>
40 #include <misc/options.h>
41 #include <omalloc/omalloc.h>
42 #include <Singular/ipshell.h>
43 #include <Singular/ipconv.h>
44 #include <coeffs/coeffs.h>
45 #include <Singular/subexpr.h>
46 
47 #include <polys/monomials/maps.h>
48 
49 /* include Hilbert-function */
51 
52 /** kstd2.cc */
53 #include <kernel/GBEngine/kutil.h>
54 #include <kernel/GBEngine/khstd.h>
55 
56 #include <Singular/walk.h>
57 #include <kernel/polys.h>
58 #include <kernel/ideals.h>
59 #include <Singular/ipid.h>
60 #include <Singular/tok.h>
61 #include <coeffs/numbers.h>
62 #include <Singular/ipid.h>
63 #include <polys/monomials/ring.h>
64 #include <kernel/GBEngine/kstd1.h>
65 #include <polys/matpol.h>
66 #include <polys/weight.h>
67 #include <misc/intvec.h>
68 #include <kernel/GBEngine/syz.h>
69 #include <Singular/lists.h>
70 #include <polys/prCopy.h>
71 #include <polys/monomials/ring.h>
72 //#include <polys/ext_fields/longalg.h>
73 #include <polys/clapsing.h>
74 
75 #include <coeffs/mpr_complex.h>
76 
77 #include <stdio.h>
78 // === Zeit & System (Holger Croeni ===
79 #include <time.h>
80 #include <sys/time.h>
81 #include <math.h>
82 #include <sys/stat.h>
83 #include <unistd.h>
84 #include <float.h>
85 #include <misc/mylimits.h>
86 #include <sys/types.h>
87 
88 int nstep;
89 
90 extern BOOLEAN ErrorCheck();
91 
92 extern BOOLEAN pSetm_error;
93 
95 
97 
98 clock_t xtif, xtstd, xtlift, xtred, xtnw;
100 
101 /****************************
102  * utilities for TSet, LSet *
103  ****************************/
104 inline static intset initec (int maxnr)
105 {
106  return (intset)omAlloc(maxnr*sizeof(int));
107 }
108 
109 inline static unsigned long* initsevS (int maxnr)
110 {
111  return (unsigned long*)omAlloc0(maxnr*sizeof(unsigned long));
112 }
113 inline static int* initS_2_R (int maxnr)
114 {
115  return (int*)omAlloc0(maxnr*sizeof(int));
116 }
117 
118 /************************************
119  * construct the set s from F u {P} *
120  ************************************/
121 // unused
122 #if 0
123 static void initSSpecialCC (ideal F, ideal Q, ideal P,kStrategy strat)
124 {
125  int i,pos;
126 
127  if (Q!=NULL) i=((IDELEMS(Q)+(setmaxTinc-1))/setmaxTinc)*setmaxTinc;
128  else i=setmaxT;
129 
130  strat->ecartS=initec(i);
131  strat->sevS=initsevS(i);
132  strat->S_2_R=initS_2_R(i);
133  strat->fromQ=NULL;
134  strat->Shdl=idInit(i,F->rank);
135  strat->S=strat->Shdl->m;
136 
137  // - put polys into S -
138  if (Q!=NULL)
139  {
140  strat->fromQ=initec(i);
141  memset(strat->fromQ,0,i*sizeof(int));
142  for (i=0; i<IDELEMS(Q); i++)
143  {
144  if (Q->m[i]!=NULL)
145  {
146  LObject h;
147  h.p = pCopy(Q->m[i]);
148  //if (TEST_OPT_INTSTRATEGY)
149  //{
150  // //pContent(h.p);
151  // h.pCleardenom(); // also does a pContent
152  //}
153  //else
154  //{
155  // h.pNorm();
156  //}
157  strat->initEcart(&h);
159  {
160  deleteHC(&h,strat);
161  }
162  if (h.p!=NULL)
163  {
164  if (strat->sl==-1)
165  pos =0;
166  else
167  {
168  pos = posInS(strat,strat->sl,h.p,h.ecart);
169  }
170  h.sev = pGetShortExpVector(h.p);
171  h.SetpFDeg();
172  strat->enterS(h,pos,strat, strat->tl+1);
173  enterT(h, strat);
174  strat->fromQ[pos]=1;
175  }
176  }
177  }
178  }
179  //- put polys into S -
180  for (i=0; i<IDELEMS(F); i++)
181  {
182  if (F->m[i]!=NULL)
183  {
184  LObject h;
185  h.p = pCopy(F->m[i]);
187  {
188  //h.p=redtailBba(h.p,strat->sl,strat);
189  h.p=redtailBba(h.p,strat->sl,strat);
190  }
191  else
192  {
193  deleteHC(&h,strat);
194  }
195  strat->initEcart(&h);
196  if (h.p!=NULL)
197  {
198  if (strat->sl==-1)
199  pos =0;
200  else
201  pos = posInS(strat,strat->sl,h.p,h.ecart);
202  h.sev = pGetShortExpVector(h.p);
203  strat->enterS(h,pos,strat, strat->tl+1);
204  h.length = pLength(h.p);
205  h.SetpFDeg();
206  enterT(h,strat);
207  }
208  }
209  }
210 #ifdef INITSSPECIAL
211  for (i=0; i<IDELEMS(P); i++)
212  {
213  if (P->m[i]!=NULL)
214  {
215  LObject h;
216  h.p=pCopy(P->m[i]);
217  strat->initEcart(&h);
218  h.length = pLength(h.p);
220  {
221  h.pCleardenom();
222  }
223  else
224  {
225  h.pNorm();
226  }
227  if(strat->sl>=0)
228  {
230  {
231  h.p=redBba(h.p,strat->sl,strat);
232  if (h.p!=NULL)
233  h.p=redtailBba(h.p,strat->sl,strat);
234  }
235  else
236  {
237  h.p=redMora(h.p,strat->sl,strat);
238  strat->initEcart(&h);
239  }
240  if(h.p!=NULL)
241  {
243  {
244  h.pCleardenom();
245  }
246  else
247  {
248  h.is_normalized = 0;
249  h.pNorm();
250  }
251  h.sev = pGetShortExpVector(h.p);
252  h.SetpFDeg();
253  pos = posInS(strat->S,strat->sl,h.p,h.ecart);
254  enterpairsSpecial(h.p,strat->sl,h.ecart,pos,strat,strat->tl+1);
255  strat->enterS(h,pos,strat, strat->tl+1);
256  enterT(h,strat);
257  }
258  }
259  else
260  {
261  h.sev = pGetShortExpVector(h.p);
262  h.SetpFDeg();
263  strat->enterS(h,0,strat, strat->tl+1);
264  enterT(h,strat);
265  }
266  }
267  }
268 #endif
269 }
270 #endif
271 
272 /*****************
273  *interreduce F *
274  *****************/
276 {
277  int j;
278  kStrategy strat = new skStrategy;
279 
280 // if (TEST_OPT_PROT)
281 // {
282 // writeTime("start InterRed:");
283 // mflush();
284 // }
285  //strat->syzComp = 0;
286  strat->kHEdgeFound = (currRing->ppNoether) != NULL;
287  strat->kNoether=pCopy((currRing->ppNoether));
288  strat->ak = id_RankFreeModule(F, currRing);
289  initBuchMoraCrit(strat);
290  strat->NotUsedAxis = (BOOLEAN *)omAlloc((currRing->N+1)*sizeof(BOOLEAN));
291  for(j=currRing->N; j>0; j--)
292  {
293  strat->NotUsedAxis[j] = TRUE;
294  }
295  strat->enterS = enterSBba;
296  strat->posInT = posInT0;
297  strat->initEcart = initEcartNormal;
298  strat->sl = -1;
299  strat->tl = -1;
300  strat->tmax = setmaxT;
301  strat->T = initT();
302  strat->R = initR();
303  strat->sevT = initsevT();
305  {
306  strat->honey = TRUE;
307  }
308 
309  //initSCC(F,Q,strat);
310  initS(F,Q,strat);
311 
312  /*
313  timetmp=clock();//22.01.02
314  initSSpecialCC(F,Q,NULL,strat);
315  tininitS=tininitS+clock()-timetmp;//22.01.02
316  */
317  if(TEST_OPT_REDSB)
318  {
319  strat->noTailReduction=FALSE;
320  }
321  updateS(TRUE,strat);
322 
324  {
325  completeReduce(strat);
326  }
327  pDelete(&strat->kHEdge);
328  omFreeSize((ADDRESS)strat->T,strat->tmax*sizeof(TObject));
329  omFreeSize((ADDRESS)strat->ecartS,IDELEMS(strat->Shdl)*sizeof(int));
330  omFreeSize((ADDRESS)strat->sevS,IDELEMS(strat->Shdl)*sizeof(unsigned long));
331  omFreeSize((ADDRESS)strat->NotUsedAxis,(currRing->N+1)*sizeof(BOOLEAN));
332  omfree(strat->sevT);
333  omfree(strat->S_2_R);
334  omfree(strat->R);
335 
336  if(strat->fromQ)
337  {
338  for(j=0; j<IDELEMS(strat->Shdl); j++)
339  {
340  if(strat->fromQ[j])
341  {
342  pDelete(&strat->Shdl->m[j]);
343  }
344  }
345  omFreeSize((ADDRESS)strat->fromQ,IDELEMS(strat->Shdl)*sizeof(int));
346  strat->fromQ = NULL;
347  }
348 // if (TEST_OPT_PROT)
349 // {
350 // writeTime("end Interred:");
351 // mflush();
352 // }
353  ideal shdl=strat->Shdl;
354  idSkipZeroes(shdl);
355  delete(strat);
356 
357  return shdl;
358 }
359 
360 //unused
361 #if 0
362 static void TimeString(clock_t tinput, clock_t tostd, clock_t tif,clock_t tstd,
363  clock_t tlf,clock_t tred, clock_t tnw, int step)
364 {
365  double totm = ((double) (clock() - tinput))/1000000;
366  double ostd,mostd, mif, mstd, mlf, mred, mnw, mxif,mxstd,mxlf,mxred,mxnw,tot;
367  // double mextra
368  Print("\n// total time = %.2f sec", totm);
369  Print("\n// tostd = %.2f sec = %.2f", ostd=((double) tostd)/1000000,
370  mostd=((((double) tostd)/1000000)/totm)*100);
371  Print("\n// tif = %.2f sec = %.2f", ((double) tif)/1000000,
372  mif=((((double) tif)/1000000)/totm)*100);
373  Print("\n// std = %.2f sec = %.2f", ((double) tstd)/1000000,
374  mstd=((((double) tstd)/1000000)/totm)*100);
375  Print("\n// lift = %.2f sec = %.2f", ((double) tlf)/1000000,
376  mlf=((((double) tlf)/1000000)/totm)*100);
377  Print("\n// ired = %.2f sec = %.2f", ((double) tred)/1000000,
378  mred=((((double) tred)/1000000)/totm)*100);
379  Print("\n// nextw = %.2f sec = %.2f", ((double) tnw)/1000000,
380  mnw=((((double) tnw)/1000000)/totm)*100);
381  PrintS("\n Time for the last step:");
382  Print("\n// xinfo = %.2f sec = %.2f", ((double) xtif)/1000000,
383  mxif=((((double) xtif)/1000000)/totm)*100);
384  Print("\n// xstd = %.2f sec = %.2f", ((double) xtstd)/1000000,
385  mxstd=((((double) xtstd)/1000000)/totm)*100);
386  Print("\n// xlift = %.2f sec = %.2f", ((double) xtlift)/1000000,
387  mxlf=((((double) xtlift)/1000000)/totm)*100);
388  Print("\n// xired = %.2f sec = %.2f", ((double) xtred)/1000000,
389  mxred=((((double) xtred)/1000000)/totm)*100);
390  Print("\n// xnextw= %.2f sec = %.2f", ((double) xtnw)/1000000,
391  mxnw=((((double) xtnw)/1000000)/totm)*100);
392 
393  tot=mostd+mif+mstd+mlf+mred+mnw+mxif+mxstd+mxlf+mxred+mxnw;
394  double res = (double) 100 - tot;
395  Print("\n// &%d&%.2f&%.2f&%.2f&%.2f&%.2f&%.2f&%.2f&%.2f&%.2f&%.2f&%.2f&%.2f&%.2f&%.2f&%.2f(%.2f)\\ \\",
396  step, ostd, totm, mostd,mif,mstd,mlf,mred,mnw,mxif,mxstd,mxlf,mxred,mxnw,tot,res,
397  ((((double) xtextra)/1000000)/totm)*100);
398 }
399 #endif
400 
401 //unused
402 #if 0
403 static void TimeStringFractal(clock_t tinput, clock_t tostd, clock_t tif,clock_t tstd,
404  clock_t textra, clock_t tlf,clock_t tred, clock_t tnw)
405 {
406 
407  double totm = ((double) (clock() - tinput))/1000000;
408  double ostd, mostd, mif, mstd, mextra, mlf, mred, mnw, tot, res;
409  Print("\n// total time = %.2f sec", totm);
410  Print("\n// tostd = %.2f sec = %.2f", ostd=((double) tostd)/1000000,
411  mostd=((((double) tostd)/1000000)/totm)*100);
412  Print("\n// tif = %.2f sec = %.2f", ((double) tif)/1000000,
413  mif=((((double) tif)/1000000)/totm)*100);
414  Print("\n// std = %.2f sec = %.2f", ((double) tstd)/1000000,
415  mstd=((((double) tstd)/1000000)/totm)*100);
416  Print("\n// xstd = %.2f sec = %.2f", ((double) textra)/1000000,
417  mextra=((((double) textra)/1000000)/totm)*100);
418  Print("\n// lift = %.2f sec = %.2f", ((double) tlf)/1000000,
419  mlf=((((double) tlf)/1000000)/totm)*100);
420  Print("\n// ired = %.2f sec = %.2f", ((double) tred)/1000000,
421  mred=((((double) tred)/1000000)/totm)*100);
422  Print("\n// nextw = %.2f sec = %.2f", ((double) tnw)/1000000,
423  mnw=((((double) tnw)/1000000)/totm)*100);
424  tot = mostd+mif+mstd+mextra+mlf+mred+mnw;
425  res = (double) 100.00-tot;
426  Print("\n// &%.2f &%.2f&%.2f &%.2f &%.2f &%.2f &%.2f &%.2f &%.2f&%.2f&%.2f\\ \\ ",
427  ostd,totm,mostd,mif,mstd,mextra,mlf,mred,mnw,tot,res);
428 }
429 #endif
430 
431 #ifdef CHECK_IDEAL_MWALK
432 static void idString(ideal L, const char* st)
433 {
434  int i, nL = IDELEMS(L);
435 
436  Print("\n// ideal %s = ", st);
437  for(i=0; i<nL-1; i++)
438  {
439  Print(" %s, ", pString(L->m[i]));
440  }
441  Print(" %s;", pString(L->m[nL-1]));
442 }
443 #endif
444 
445 #if defined(CHECK_IDEAL_MWALK) || defined(ENDWALKS)
446 static void headidString(ideal L, char* st)
447 {
448  int i, nL = IDELEMS(L);
449 
450  Print("\n// ideal %s = ", st);
451  for(i=0; i<nL-1; i++)
452  {
453  Print(" %s, ", pString(pHead(L->m[i])));
454  }
455  Print(" %s;", pString(pHead(L->m[nL-1])));
456 }
457 #endif
458 
459 #if defined(CHECK_IDEAL_MWALK) || defined(ENDWALKS)
460 static void idElements(ideal L, char* st)
461 {
462  int i, nL = IDELEMS(L);
463  int *K=(int *)omAlloc(nL*sizeof(int));
464 
465  Print("\n// #monoms of %s = ", st);
466  for(i=0; i<nL; i++)
467  {
468  K[i] = pLength(L->m[i]);
469  }
470  int j, nsame;
471  // int nk=0;
472  for(i=0; i<nL; i++)
473  {
474  if(K[i]!=0)
475  {
476  nsame = 1;
477  for(j=i+1; j<nL; j++)
478  {
479  if(K[j]==K[i])
480  {
481  nsame ++;
482  K[j]=0;
483  }
484  }
485  if(nsame == 1)
486  {
487  Print("%d, ",K[i]);
488  }
489  else
490  {
491  Print("%d[%d], ", K[i], nsame);
492  }
493  }
494  }
495  omFree(K);
496 }
497 #endif
498 
499 
500 static void ivString(intvec* iv, const char* ch)
501 {
502  int nV = iv->length()-1;
503  Print("\n// intvec %s = ", ch);
504 
505  for(int i=0; i<nV; i++)
506  {
507  Print("%d, ", (*iv)[i]);
508  }
509  Print("%d;", (*iv)[nV]);
510 }
511 
512 //unused
513 //#if 0
514 static void MivString(intvec* iva, intvec* ivb, intvec* ivc)
515 {
516  int nV = iva->length()-1;
517  int i;
518  PrintS("\n// (");
519  for(i=0; i<nV; i++)
520  {
521  Print("%d, ", (*iva)[i]);
522  }
523  Print("%d) ==> (", (*iva)[nV]);
524  for(i=0; i<nV; i++)
525  {
526  Print("%d, ", (*ivb)[i]);
527  }
528  Print("%d) := (", (*ivb)[nV]);
529 
530  for(i=0; i<nV; i++)
531  {
532  Print("%d, ", (*ivc)[i]);
533  }
534  Print("%d)", (*ivc)[nV]);
535 }
536 //#endif
537 
538 /********************************************************************
539  * returns gcd of integers a and b *
540  ********************************************************************/
541 static inline long gcd(const long a, const long b)
542 {
543  long r, p0 = a, p1 = b;
544  //assume(p0 >= 0 && p1 >= 0);
545  if(p0 < 0)
546  {
547  p0 = -p0;
548  }
549  if(p1 < 0)
550  {
551  p1 = -p1;
552  }
553  while(p1 != 0)
554  {
555  r = p0 % p1;
556  p0 = p1;
557  p1 = r;
558  }
559  return p0;
560 }
561 
562 /*********************************************
563  * cancel gcd of integers zaehler and nenner *
564  *********************************************/
565 static void cancel(mpz_t zaehler, mpz_t nenner)
566 {
567 // assume(zaehler >= 0 && nenner > 0);
568  mpz_t g;
569  mpz_init(g);
570  mpz_gcd(g, zaehler, nenner);
571 
572  mpz_div(zaehler , zaehler, g);
573  mpz_div(nenner , nenner, g);
574 
575  mpz_clear(g);
576 }
577 
578 //unused
579 #if 0
580 static int isVectorNeg(intvec* omega)
581 {
582  int i;
583 
584  for(i=omega->length(); i>=0; i--)
585  {
586  if((*omega)[i]<0)
587  {
588  return 1;
589  }
590  }
591  return 0;
592 }
593 #endif
594 
595 /********************************************************************
596  * compute a weight degree of a monomial p w.r.t. a weight_vector *
597  ********************************************************************/
598 static inline int MLmWeightedDegree(const poly p, intvec* weight)
599 {
600  /* 2147483647 is max. integer representation in SINGULAR */
601  mpz_t sing_int;
602  mpz_init_set_ui(sing_int, 2147483647);
603 
604  int i, wgrad;
605 
606  mpz_t zmul;
607  mpz_init(zmul);
608  mpz_t zvec;
609  mpz_init(zvec);
610  mpz_t zsum;
611  mpz_init(zsum);
612 
613  for (i=currRing->N; i>0; i--)
614  {
615  mpz_set_si(zvec, (*weight)[i-1]);
616  mpz_mul_ui(zmul, zvec, pGetExp(p, i));
617  mpz_add(zsum, zsum, zmul);
618  }
619 
620  wgrad = mpz_get_ui(zsum);
621 
622  if(mpz_cmp(zsum, sing_int)>0)
623  {
624  if(Overflow_Error == FALSE)
625  {
626  PrintLn();
627  PrintS("\n// ** OVERFLOW in \"MwalkInitialForm\": ");
628  mpz_out_str( stdout, 10, zsum);
629  PrintS(" is greater than 2147483647 (max. integer representation)");
631  }
632  }
633 
634  mpz_clear(zmul);
635  mpz_clear(zvec);
636  mpz_clear(zsum);
637  mpz_clear(sing_int);
638 
639  return wgrad;
640 }
641 
642 /********************************************************************
643  * compute a weight degree of a polynomial p w.r.t. a weight_vector *
644  ********************************************************************/
645 static inline int MwalkWeightDegree(poly p, intvec* weight_vector)
646 {
647  assume(weight_vector->length() >= currRing->N);
648  int max = 0, maxtemp;
649 
650  while(p != NULL)
651  {
652  maxtemp = MLmWeightedDegree(p, weight_vector);
653  pIter(p);
654 
655  if (maxtemp > max)
656  {
657  max = maxtemp;
658  }
659  }
660  return max;
661 }
662 
663 
664 /********************************************************************
665  * compute a weight degree of a monomial p w.r.t. a weight_vector *
666  ********************************************************************/
667 static void MLmWeightedDegree_gmp(mpz_t result, const poly p, intvec* weight)
668 {
669  /* 2147483647 is max. integer representation in SINGULAR */
670  mpz_t sing_int;
671  mpz_init_set_ui(sing_int, 2147483647);
672 
673  int i;
674 
675  mpz_t zmul;
676  mpz_init(zmul);
677  mpz_t zvec;
678  mpz_init(zvec);
679  mpz_t ztmp;
680  mpz_init(ztmp);
681 
682  for (i=currRing->N; i>0; i--)
683  {
684  mpz_set_si(zvec, (*weight)[i-1]);
685  mpz_mul_ui(zmul, zvec, pGetExp(p, i));
686  mpz_add(ztmp, ztmp, zmul);
687  }
688  mpz_init_set(result, ztmp);
689  mpz_clear(ztmp);
690  mpz_clear(sing_int);
691  mpz_clear(zvec);
692  mpz_clear(zmul);
693 }
694 
695 
696 /*****************************************************************************
697  * return an initial form of the polynom g w.r.t. a weight vector curr_weight *
698  *****************************************************************************/
699 static poly MpolyInitialForm(poly g, intvec* curr_weight)
700 {
701  if(g == NULL)
702  {
703  return NULL;
704  }
705  mpz_t max; mpz_init(max);
706  mpz_t maxtmp; mpz_init(maxtmp);
707 
708  poly hg, in_w_g = NULL;
709 
710  while(g != NULL)
711  {
712  hg = g;
713  pIter(g);
714  MLmWeightedDegree_gmp(maxtmp, hg, curr_weight);
715 
716  if(mpz_cmp(maxtmp, max)>0)
717  {
718  mpz_init_set(max, maxtmp);
719  pDelete(&in_w_g);
720  in_w_g = pHead(hg);
721  }
722  else
723  {
724  if(mpz_cmp(maxtmp, max)==0)
725  {
726  in_w_g = pAdd(in_w_g, pHead(hg));
727  }
728  }
729  }
730  return in_w_g;
731 }
732 
733 /************************************************************************
734  * compute the initial form of an ideal <G> w.r.t. a weight vector iva *
735  ************************************************************************/
737 {
738  BOOLEAN nError = Overflow_Error;
740 
741  int i, nG = IDELEMS(G);
742  ideal Gomega = idInit(nG, 1);
743 
744  for(i=nG-1; i>=0; i--)
745  {
746  Gomega->m[i] = MpolyInitialForm(G->m[i], ivw);
747  }
748  if(Overflow_Error == FALSE)
749  {
750  Overflow_Error = nError;
751  }
752  return Gomega;
753 }
754 
755 /************************************************************************
756  * test whether the weight vector iv is in the cone of the ideal G *
757  * i.e. test whether in(in_w(g)) = in(g) for all g in G *
758  ************************************************************************/
759 
760 static int test_w_in_ConeCC(ideal G, intvec* iv)
761 {
762  if(G->m[0] == NULL)
763  {
764  PrintS("//** the result may be WRONG, i.e. 0!!\n");
765  return 0;
766  }
767 
768  BOOLEAN nError = Overflow_Error;
770 
771  int i, nG = IDELEMS(G);
772  poly mi, gi;
773 
774  for(i=nG-1; i>=0; i--)
775  {
776  mi = MpolyInitialForm(G->m[i], iv);
777  gi = G->m[i];
778 
779  if(mi == NULL)
780  {
781  pDelete(&mi);
782  if(Overflow_Error == FALSE)
783  {
784  Overflow_Error = nError;
785  }
786  return 0;
787  }
788  if(!pLmEqual(mi, gi))
789  {
790  pDelete(&mi);
791  if(Overflow_Error == FALSE)
792  {
793  Overflow_Error = nError;
794  }
795  return 0;
796  }
797  pDelete(&mi);
798  }
799 
800  if(Overflow_Error == FALSE)
801  {
802  Overflow_Error = nError;
803  }
804  return 1;
805 }
806 
807 /***************************************************
808  * compute a least common multiple of two integers *
809  ***************************************************/
810 static inline long Mlcm(long &i1, long &i2)
811 {
812  long temp = gcd(i1, i2);
813  return ((i1 / temp)* i2);
814 }
815 
816 
817 /***************************************************
818  * return the dot product of two intvecs a and b *
819  ***************************************************/
820 static inline long MivDotProduct(intvec* a, intvec* b)
821 {
822  assume( a->length() == b->length());
823  int i, n = a->length();
824  long result = 0;
825 
826  for(i=n-1; i>=0; i--)
827  {
828  result += (*a)[i] * (*b)[i];
829  }
830  return result;
831 }
832 
833 /*****************************************************
834  * Substract two given intvecs componentwise *
835  *****************************************************/
837 {
838  assume( a->length() == b->length());
839  int i, n = a->length();
840  intvec* result = new intvec(n);
841 
842  for(i=n-1; i>=0; i--)
843  {
844  (*result)[i] = (*a)[i] - (*b)[i];
845  }
846  return result;
847 }
848 
849 /*****************************************************
850  * return the "intvec" lead exponent of a polynomial *
851  *****************************************************/
853 {
854  int i, nR = currRing->N;
855  intvec* result = new intvec(nR);
856 
857  for(i=nR-1; i>=0; i--)
858  {
859  (*result)[i] = pGetExp(f,i+1);
860  }
861  return result;
862 }
863 
864 /*****************************************************
865  * Compare two given intvecs and return 1, if they *
866  * are the same, otherwise 0 *
867  *****************************************************/
868 int MivSame(intvec* u , intvec* v)
869 {
870  assume(u->length() == v->length());
871 
872  int i, niv = u->length();
873 
874  for (i=0; i<niv; i++)
875  {
876  if ((*u)[i] != (*v)[i])
877  {
878  return 0;
879  }
880  }
881  return 1;
882 }
883 
884 /******************************************************
885  * Compare 3 given intvecs and return 0, if the first *
886  * and the second are the same. Return 1, if the *
887  * the second and the third are the same, otherwise 2 *
888  ******************************************************/
889 int M3ivSame(intvec* temp, intvec* u , intvec* v)
890 {
891  assume(temp->length() == u->length() && u->length() == v->length());
892 
893  if((MivSame(temp, u)) == 1)
894  {
895  return 0;
896  }
897  if((MivSame(temp, v)) == 1)
898  {
899  return 1;
900  }
901  return 2;
902 }
903 
904 /*****************************************************
905  * compute a Groebner basis of an ideal *
906  *****************************************************/
908 {
909  BITSET save1,save2;
910  SI_SAVE_OPT(save1,save2);
912  ideal G1 = kStd(G, NULL, testHomog, NULL);
913  SI_RESTORE_OPT(save1,save2);
914 
915  idSkipZeroes(G1);
916  return G1;
917 }
918 
919 /*****************************************************
920  * compute a Groebner basis of an homogeneous ideal *
921  *****************************************************/
923 {
924  BITSET save1,save2;
925  SI_SAVE_OPT(save1,save2);
927  ideal G1 = kStd(G, NULL, isHomog, NULL);
928  SI_RESTORE_OPT(save1,save2);
929 
930  idSkipZeroes(G1);
931  return G1;
932 }
933 
934 
935 /*****************************************************************************
936 * create a weight matrix order as intvec of an extra weight vector (a(iv),lp)*
937 ******************************************************************************/
939 {
940  int i, nR = iv->length();
941 
942  intvec* ivm = new intvec(nR*nR);
943 
944  for(i=0; i<nR; i++)
945  {
946  (*ivm)[i] = (*iv)[i];
947  }
948  for(i=1; i<nR; i++)
949  {
950  (*ivm)[i*nR+i-1] = 1;
951  }
952  return ivm;
953 }
954 
955 /*****************************************************************************
956 * create a weight matrix order as intvec of an extra weight vector (a(iv),lp)*
957 ******************************************************************************/
959 {
960  assume(iv->length() == iw->length());
961  int i, nR = iv->length();
962 
963  intvec* ivm = new intvec(nR*nR);
964 
965  for(i=0; i<nR; i++)
966  {
967  (*ivm)[i] = (*iv)[i];
968  (*ivm)[i+nR] = (*iw)[i];
969  }
970  for(i=2; i<nR; i++)
971  {
972  (*ivm)[i*nR+i-2] = 1;
973  }
974  return ivm;
975 }
976 
977 /*******************************
978  * return intvec = (1, ..., 1) *
979  *******************************/
980 intvec* Mivdp(int nR)
981 {
982  int i;
983  intvec* ivm = new intvec(nR);
984 
985  for(i=nR-1; i>=0; i--)
986  {
987  (*ivm)[i] = 1;
988  }
989  return ivm;
990 }
991 
992 /**********************************
993  * return intvvec = (1,0, ..., 0) *
994  **********************************/
995 intvec* Mivlp(int nR)
996 {
997  intvec* ivm = new intvec(nR);
998  (*ivm)[0] = 1;
999 
1000  return ivm;
1001 }
1002 
1003 //unused
1004 /*****************************************************************************
1005  * print the max total degree and the max coefficient of G *
1006  *****************************************************************************/
1007 #if 0
1008 static void checkComplexity(ideal G, char* cG)
1009 {
1010  int nV = currRing->N;
1011  int nG = IDELEMS(G);
1012  intvec* ivUnit = Mivdp(nV);
1013  int i, tmpdeg, maxdeg=0;
1014  number tmpcoeff , maxcoeff=currRing->cf->nNULL;
1015  poly p;
1016  for(i=nG-1; i>=0; i--)
1017  {
1018  tmpdeg = MwalkWeightDegree(G->m[i], ivUnit);
1019  if(tmpdeg > maxdeg )
1020  {
1021  maxdeg = tmpdeg;
1022  }
1023  }
1024 
1025  for(i=nG-1; i>=0; i--)
1026  {
1027  p = pCopy(G->m[i]);
1028  while(p != NULL)
1029  {
1030  //tmpcoeff = pGetCoeff(pHead(p));
1031  tmpcoeff = pGetCoeff(p);
1032  if(nGreater(tmpcoeff,maxcoeff))
1033  {
1034  maxcoeff = nCopy(tmpcoeff);
1035  }
1036  pIter(p);
1037  }
1038  pDelete(&p);
1039  }
1040  p = pNSet(maxcoeff);
1041  char* pStr = pString(p);
1042  delete ivUnit;
1043  Print("// max total degree of %s = %d\n",cG, maxdeg);
1044  Print("// max coefficient of %s = %s", cG, pStr);//ing(p));
1045  Print(" which consists of %d digits", (int)strlen(pStr));
1046  PrintLn();
1047 }
1048 #endif
1049 
1050 /*****************************************************************************
1051 * If target_ord = intmat(A1, ..., An) then calculate the perturbation *
1052 * vectors *
1053 * tau_p_dep = inveps^(p_deg-1)*A1 + inveps^(p_deg-2)*A2 +... + A_p_deg *
1054 * where *
1055 * inveps > totaldegree(G)*(max(A2)+...+max(A_p_deg)) *
1056 * intmat target_ord is an integer order matrix of the monomial ordering of *
1057 * basering. *
1058 * This programm computes a perturbated vector with a p_deg perturbation *
1059 * degree which smaller than the numbers of variables *
1060 ******************************************************************************/
1061 intvec* MPertVectors(ideal G, intvec* ivtarget, int pdeg)
1062 {
1063  // ivtarget is a matrix order of a degree reverse lex. order
1064  int nV = currRing->N;
1065  //assume(pdeg <= nV && pdeg >= 0);
1066 
1067  int i, j, nG = IDELEMS(G);
1068  intvec* v_null = new intvec(nV);
1069 
1070 
1071  // Check that the perturbed degree is valid
1072  if(pdeg > nV || pdeg <= 0)
1073  {
1074  WerrorS("//** The perturbed degree is wrong!!");
1075  return v_null;
1076  }
1077  delete v_null;
1078 
1079  if(pdeg == 1)
1080  {
1081  return ivtarget;
1082  }
1083  mpz_t *pert_vector = (mpz_t*)omAlloc(nV*sizeof(mpz_t));
1084  //mpz_t *pert_vector1 = (mpz_t*)omAlloc(nV*sizeof(mpz_t));
1085 
1086  for(i=0; i<nV; i++)
1087  {
1088  mpz_init_set_si(pert_vector[i], (*ivtarget)[i]);
1089  // mpz_init_set_si(pert_vector1[i], (*ivtarget)[i]);
1090  }
1091  // Calculate max1 = Max(A2)+Max(A3)+...+Max(Apdeg),
1092  // where the Ai are the i-te rows of the matrix target_ord.
1093  int ntemp, maxAi, maxA=0;
1094  for(i=1; i<pdeg; i++)
1095  {
1096  maxAi = (*ivtarget)[i*nV];
1097  if(maxAi<0)
1098  {
1099  maxAi = -maxAi;
1100  }
1101  for(j=i*nV+1; j<(i+1)*nV; j++)
1102  {
1103  ntemp = (*ivtarget)[j];
1104  if(ntemp < 0)
1105  {
1106  ntemp = -ntemp;
1107  }
1108  if(ntemp > maxAi)
1109  {
1110  maxAi = ntemp;
1111  }
1112  }
1113  maxA += maxAi;
1114  }
1115 
1116  // Calculate inveps = 1/eps, where 1/eps > totaldeg(p)*max1 for all p in G.
1117 
1118  intvec* ivUnit = Mivdp(nV);
1119 
1120  mpz_t tot_deg; mpz_init(tot_deg);
1121  mpz_t maxdeg; mpz_init(maxdeg);
1122  mpz_t inveps; mpz_init(inveps);
1123 
1124 
1125  for(i=nG-1; i>=0; i--)
1126  {
1127  mpz_set_ui(maxdeg, MwalkWeightDegree(G->m[i], ivUnit));
1128  if (mpz_cmp(maxdeg, tot_deg) > 0 )
1129  {
1130  mpz_set(tot_deg, maxdeg);
1131  }
1132  }
1133 
1134  delete ivUnit;
1135  mpz_mul_ui(inveps, tot_deg, maxA);
1136  mpz_add_ui(inveps, inveps, 1);
1137 
1138 
1139  // takes "small" inveps
1140 #ifdef INVEPS_SMALL_IN_MPERTVECTOR
1141  if(mpz_cmp_ui(inveps, pdeg)>0 && pdeg > 3)
1142  {
1143  // Print("\n// choose the\"small\" inverse epsilon := %d / %d = ", mpz_get_si(inveps), pdeg);
1144  mpz_fdiv_q_ui(inveps, inveps, pdeg);
1145  // mpz_out_str(stdout, 10, inveps);
1146  }
1147 #else
1148  // PrintS("\n// the \"big\" inverse epsilon: ");
1149  mpz_out_str(stdout, 10, inveps);
1150 #endif
1151 
1152  // pert(A1) = inveps^(pdeg-1)*A1 + inveps^(pdeg-2)*A2+...+A_pdeg,
1153  // pert_vector := A1
1154  for( i=1; i < pdeg; i++ )
1155  {
1156  for(j=0; j<nV; j++)
1157  {
1158  mpz_mul(pert_vector[j], pert_vector[j], inveps);
1159  if((*ivtarget)[i*nV+j]<0)
1160  {
1161  mpz_sub_ui(pert_vector[j], pert_vector[j],-(*ivtarget)[i*nV+j]);
1162  }
1163  else
1164  {
1165  mpz_add_ui(pert_vector[j], pert_vector[j],(*ivtarget)[i*nV+j]);
1166  }
1167  }
1168  }
1169  mpz_t ztemp;
1170  mpz_init(ztemp);
1171  mpz_set(ztemp, pert_vector[0]);
1172  for(i=1; i<nV; i++)
1173  {
1174  mpz_gcd(ztemp, ztemp, pert_vector[i]);
1175  if(mpz_cmp_si(ztemp, 1) == 0)
1176  {
1177  break;
1178  }
1179  }
1180  if(mpz_cmp_si(ztemp, 1) != 0)
1181  {
1182  for(i=0; i<nV; i++)
1183  {
1184  mpz_divexact(pert_vector[i], pert_vector[i], ztemp);
1185  }
1186  }
1187 
1188  intvec *pert_vector1= new intvec(nV);
1189  j = 0;
1190  for(i=0; i<nV; i++)
1191  {
1192  (* pert_vector1)[i] = mpz_get_si(pert_vector[i]);
1193  (* pert_vector1)[i] = 0.1*(* pert_vector1)[i];
1194  (* pert_vector1)[i] = floor((* pert_vector1)[i] + 0.5);
1195  if((* pert_vector1)[i] == 0)
1196  {
1197  j++;
1198  }
1199  }
1200  if(j > nV - 1)
1201  {
1202  // Print("\n// MPertVectors: geaenderter vector gleich Null! \n");
1203  delete pert_vector1;
1204  goto CHECK_OVERFLOW;
1205  }
1206 
1207 // check that the perturbed weight vector lies in the Groebner cone
1208  if(test_w_in_ConeCC(G,pert_vector1) != 0)
1209  {
1210  // Print("\n// MPertVectors: geaenderter vector liegt in Groebnerkegel! \n");
1211  for(i=0; i<nV; i++)
1212  {
1213  mpz_set_si(pert_vector[i], (*pert_vector1)[i]);
1214  }
1215  }
1216  else
1217  {
1218  //Print("\n// MpertVectors: geaenderter vector liegt nicht in Groebnerkegel! \n");
1219  }
1220  delete pert_vector1;
1221 
1222  CHECK_OVERFLOW:
1223  intvec* result = new intvec(nV);
1224 
1225  /* 2147483647 is max. integer representation in SINGULAR */
1226  mpz_t sing_int;
1227  mpz_init_set_ui(sing_int, 2147483647);
1228 
1229  int ntrue=0;
1230  for(i=0; i<nV; i++)
1231  {
1232  (*result)[i] = mpz_get_si(pert_vector[i]);
1233  if(mpz_cmp(pert_vector[i], sing_int)>=0)
1234  {
1235  ntrue++;
1236  if(Overflow_Error == FALSE)
1237  {
1238  Overflow_Error = TRUE;
1239  PrintS("\n// ** OVERFLOW in \"MPertvectors\": ");
1240  mpz_out_str( stdout, 10, pert_vector[i]);
1241  PrintS(" is greater than 2147483647 (max. integer representation)");
1242  Print("\n// So vector[%d] := %d is wrong!!", i+1, (*result)[i]);
1243  }
1244  }
1245  }
1246 
1247  if(Overflow_Error == TRUE)
1248  {
1249  ivString(result, "pert_vector");
1250  Print("\n// %d element(s) of it is overflow!!", ntrue);
1251  }
1252 
1253  mpz_clear(ztemp);
1254  mpz_clear(sing_int);
1255  omFree(pert_vector);
1256  //omFree(pert_vector1);
1257  mpz_clear(tot_deg);
1258  mpz_clear(maxdeg);
1259  mpz_clear(inveps);
1260 
1262  for(j=0; j<IDELEMS(G); j++)
1263  {
1264  poly p=G->m[j];
1265  while(p!=NULL)
1266  {
1267  p_Setm(p,currRing); pIter(p);
1268  }
1269  }
1270  return result;
1271 }
1272 
1273 /*****************************************************************************
1274  * The following procedure returns *
1275  * Pert(A1) = 1/eps^(pdeg-1)*A_1 + 1/eps^(pdeg-2)*A_2+...+A_pdeg, *
1276  * where the A_i are the i-th rows of the matrix target_ord and *
1277  * 1/eps > deg(p)*(max(A_2) + max(A_3)+...+max(A_pdeg)) *
1278  *****************************************************************************/
1279 intvec* MPertVectorslp(ideal G, intvec* ivtarget, int pdeg)
1280 {
1281  // ivtarget is a matrix order of the lex. order
1282  int nV = currRing->N;
1283  //assume(pdeg <= nV && pdeg >= 0);
1284 
1285  int i, j, nG = IDELEMS(G);
1286  intvec* pert_vector = new intvec(nV);
1287 
1288  //Checking that the perturbated degree is valid
1289  if(pdeg > nV || pdeg <= 0)
1290  {
1291  WerrorS("//** The perturbed degree is wrong!!");
1292  return pert_vector;
1293  }
1294  for(i=0; i<nV; i++)
1295  {
1296  (*pert_vector)[i]=(*ivtarget)[i];
1297  }
1298  if(pdeg == 1)
1299  {
1300  return pert_vector;
1301  }
1302  // Calculate max1 = Max(A2)+Max(A3)+...+Max(Apdeg),
1303  // where the Ai are the i-te rows of the matrix target_ord.
1304  int ntemp, maxAi, maxA=0;
1305  for(i=1; i<pdeg; i++)
1306  {
1307  maxAi = (*ivtarget)[i*nV];
1308  for(j=i*nV+1; j<(i+1)*nV; j++)
1309  {
1310  ntemp = (*ivtarget)[j];
1311  if(ntemp > maxAi)
1312  {
1313  maxAi = ntemp;
1314  }
1315  }
1316  maxA += maxAi;
1317  }
1318 
1319  // Calculate inveps := 1/eps, where 1/eps > deg(p)*max1 for all p in G.
1320  int inveps, tot_deg = 0, maxdeg;
1321 
1322  intvec* ivUnit = Mivdp(nV);//19.02
1323  for(i=nG-1; i>=0; i--)
1324  {
1325  // maxdeg = pTotaldegree(G->m[i], currRing); //it's wrong for ex1,2,rose
1326  maxdeg = MwalkWeightDegree(G->m[i], ivUnit);
1327  if (maxdeg > tot_deg )
1328  {
1329  tot_deg = maxdeg;
1330  }
1331  }
1332  delete ivUnit;
1333 
1334  inveps = (tot_deg * maxA) + 1;
1335 
1336 #ifdef INVEPS_SMALL_IN_FRACTAL
1337  // Print("\n// choose the\"small\" inverse epsilon := %d / %d = ", inveps, pdeg);
1338  if(inveps > pdeg && pdeg > 3)
1339  {
1340  inveps = inveps / pdeg;
1341  }
1342  // Print(" %d", inveps);
1343 #else
1344  PrintS("\n// the \"big\" inverse epsilon %d", inveps);
1345 #endif
1346 
1347  // Pert(A1) = inveps^(pdeg-1)*A1 + inveps^(pdeg-2)*A2+...+A_pdeg
1348  for ( i=1; i < pdeg; i++ )
1349  {
1350  for(j=0; j<nV; j++)
1351  {
1352  (*pert_vector)[j] = inveps*((*pert_vector)[j]) + (*ivtarget)[i*nV+j];
1353  }
1354  }
1355 
1356  int temp = (*pert_vector)[0];
1357  for(i=1; i<nV; i++)
1358  {
1359  temp = gcd(temp, (*pert_vector)[i]);
1360  if(temp == 1)
1361  {
1362  break;
1363  }
1364  }
1365  if(temp != 1)
1366  {
1367  for(i=0; i<nV; i++)
1368  {
1369  (*pert_vector)[i] = (*pert_vector)[i] / temp;
1370  }
1371  }
1372 
1373  intvec* result = pert_vector;
1374  delete pert_vector;
1375  return result;
1376 }
1377 
1378 /*****************************************************************************
1379  * define a lexicographic order matrix as intvec *
1380  *****************************************************************************/
1382 {
1383  int i;
1384  intvec* ivM = new intvec(nV*nV);
1385 
1386  for(i=0; i<nV; i++)
1387  {
1388  (*ivM)[i*nV + i] = 1;
1389  }
1390  return(ivM);
1391 }
1392 
1393 
1394 /*****************************************************************************
1395  * define a reverse lexicographic order (dp) matrix as intvec *
1396  *****************************************************************************/
1398 {
1399  int i;
1400  intvec* ivM = new intvec(nV*nV);
1401 
1402  for(i=0; i<nV; i++)
1403  {
1404  (*ivM)[i] = 1;
1405  }
1406  for(i=1; i<nV; i++)
1407  {
1408  (*ivM)[(i+1)*nV - i] = -1;
1409  }
1410  return(ivM);
1411 }
1412 
1413 /*****************************************************************************
1414  * creates an intvec of the monomial order Wp(ivstart) *
1415  *****************************************************************************/
1417 {
1418  int i;
1419  int nV = ivstart->length();
1420  intvec* ivM = new intvec(nV*nV);
1421 
1422  for(i=0; i<nV; i++)
1423  {
1424  (*ivM)[i] = (*ivstart)[i];
1425  }
1426  for(i=1; i<nV; i++)
1427  {
1428  (*ivM)[i*nV + i-1] = 1;
1429  }
1430  return(ivM);
1431 }
1432 
1433 /*****************************************************************************
1434  * creates an intvec of the monomial order dp(ivstart) *
1435  *****************************************************************************/
1437 {
1438  int i;
1439  int nV = ivstart->length();
1440  intvec* ivM = new intvec(nV*nV);
1441 
1442  for(i=0; i<nV; i++)
1443  {
1444  (*ivM)[i] = (*ivstart)[i];
1445  }
1446  for(i=0; i<nV; i++)
1447  {
1448  (*ivM)[nV+i] = 1;
1449  }
1450  for(i=2; i<nV; i++)
1451  {
1452  (*ivM)[(i+1)*nV - i] = -1;
1453  }
1454  return(ivM);
1455 }
1456 
1457 //unused
1458 #if 0
1459 static intvec* MatrixOrderdp(int nV)
1460 {
1461  int i;
1462  intvec* ivM = new intvec(nV*nV);
1463 
1464  for(i=0; i<nV; i++)
1465  {
1466  (*ivM)[i] = 1;
1467  }
1468  for(i=1; i<nV; i++)
1469  {
1470  (*ivM)[(i+1)*nV - i] = -1;
1471  }
1472  return(ivM);
1473 }
1474 #endif
1475 
1476 intvec* MivUnit(int nV)
1477 {
1478  int i;
1479  intvec* ivM = new intvec(nV);
1480  for(i=nV-1; i>=0; i--)
1481  {
1482  (*ivM)[i] = 1;
1483  }
1484  return(ivM);
1485 }
1486 
1487 
1488 /************************************************************************
1489 * compute a perturbed weight vector of a matrix order w.r.t. an ideal *
1490 *************************************************************************/
1491 int Xnlev;
1493 {
1494  int i, j, nG = IDELEMS(G);
1495  int nV = currRing->N;
1496  int niv = nV*nV;
1497 
1498 
1499  // Calculate maxA = Max(A2) + Max(A3) + ... + Max(AnV),
1500  // where the Ai are the i-te rows of the matrix 'targer_ord'.
1501  int ntemp, maxAi, maxA=0;
1502  for(i=1; i<nV; i++)
1503  {
1504  maxAi = (*ivtarget)[i*nV];
1505  if(maxAi<0)
1506  {
1507  maxAi = -maxAi;
1508  }
1509  for(j=i*nV+1; j<(i+1)*nV; j++)
1510  {
1511  ntemp = (*ivtarget)[j];
1512  if(ntemp < 0)
1513  {
1514  ntemp = -ntemp;
1515  }
1516  if(ntemp > maxAi)
1517  {
1518  maxAi = ntemp;
1519  }
1520  }
1521  maxA = maxA + maxAi;
1522  }
1523  intvec* ivUnit = Mivdp(nV);
1524 
1525  // Calculate inveps = 1/eps, where 1/eps > deg(p)*maxA for all p in G.
1526  mpz_t tot_deg; mpz_init(tot_deg);
1527  mpz_t maxdeg; mpz_init(maxdeg);
1528  mpz_t inveps; mpz_init(inveps);
1529 
1530 
1531  for(i=nG-1; i>=0; i--)
1532  {
1533  mpz_set_ui(maxdeg, MwalkWeightDegree(G->m[i], ivUnit));
1534  if (mpz_cmp(maxdeg, tot_deg) > 0 )
1535  {
1536  mpz_set(tot_deg, maxdeg);
1537  }
1538  }
1539 
1540  delete ivUnit;
1541  //inveps = (tot_deg * maxA) + 1;
1542  mpz_mul_ui(inveps, tot_deg, maxA);
1543  mpz_add_ui(inveps, inveps, 1);
1544 
1545  // takes "small" inveps
1546 #ifdef INVEPS_SMALL_IN_FRACTAL
1547  if(mpz_cmp_ui(inveps, nV)>0 && nV > 3)
1548  {
1549  mpz_cdiv_q_ui(inveps, inveps, nV);
1550  }
1551  //PrintS("\n// choose the \"small\" inverse epsilon!");
1552 #endif
1553 
1554  // PrintLn(); mpz_out_str(stdout, 10, inveps);
1555 
1556  // Calculate the perturbed target orders:
1557  mpz_t *ivtemp=(mpz_t *)omAlloc(nV*sizeof(mpz_t));
1558  mpz_t *pert_vector=(mpz_t *)omAlloc(niv*sizeof(mpz_t));
1559 
1560  for(i=0; i < nV; i++)
1561  {
1562  mpz_init_set_si(ivtemp[i], (*ivtarget)[i]);
1563  mpz_init_set_si(pert_vector[i], (*ivtarget)[i]);
1564  }
1565 
1566  mpz_t ztmp; mpz_init(ztmp);
1567  // BOOLEAN isneg = FALSE;
1568 
1569  for(i=1; i<nV; i++)
1570  {
1571  for(j=0; j<nV; j++)
1572  {
1573  mpz_mul(ztmp, inveps, ivtemp[j]);
1574  if((*ivtarget)[i*nV+j]<0)
1575  {
1576  mpz_sub_ui(ivtemp[j], ztmp, -(*ivtarget)[i*nV+j]);
1577  }
1578  else
1579  {
1580  mpz_add_ui(ivtemp[j], ztmp,(*ivtarget)[i*nV+j]);
1581  }
1582  }
1583 
1584  for(j=0; j<nV; j++)
1585  {
1586  mpz_init_set(pert_vector[i*nV+j],ivtemp[j]);
1587  }
1588  }
1589 
1590  /* 2147483647 is max. integer representation in SINGULAR */
1591  mpz_t sing_int;
1592  mpz_init_set_ui(sing_int, 2147483647);
1593 
1594  intvec* result = new intvec(niv);
1595  intvec* result1 = new intvec(niv);
1596  BOOLEAN nflow = FALSE;
1597 
1598  // computes gcd
1599  mpz_set(ztmp, pert_vector[0]);
1600  for(i=0; i<niv; i++)
1601  {
1602  mpz_gcd(ztmp, ztmp, pert_vector[i]);
1603  if(mpz_cmp_si(ztmp, 1)==0)
1604  {
1605  break;
1606  }
1607  }
1608 
1609  for(i=0; i<niv; i++)
1610  {
1611  mpz_divexact(pert_vector[i], pert_vector[i], ztmp);
1612  (* result)[i] = mpz_get_si(pert_vector[i]);
1613  }
1614 
1615  j = 0;
1616  for(i=0; i<nV; i++)
1617  {
1618  (* result1)[i] = mpz_get_si(pert_vector[i]);
1619  (* result1)[i] = 0.1*(* result1)[i];
1620  (* result1)[i] = floor((* result1)[i] + 0.5);
1621  if((* result1)[i] == 0)
1622  {
1623  j++;
1624  }
1625  }
1626  if(j > nV - 1)
1627  {
1628  // Print("\n// MfPertwalk: geaenderter vector gleich Null! \n");
1629  delete result1;
1630  goto CHECK_OVERFLOW;
1631  }
1632 
1633 // check that the perturbed weight vector lies in the Groebner cone
1634  if(test_w_in_ConeCC(G,result1) != 0)
1635  {
1636  // Print("\n// MfPertwalk: geaenderter vector liegt in Groebnerkegel! \n");
1637  delete result;
1638  result = result1;
1639  for(i=0; i<nV; i++)
1640  {
1641  mpz_set_si(pert_vector[i], (*result1)[i]);
1642  }
1643  }
1644  else
1645  {
1646  delete result1;
1647  // Print("\n// Mfpertwalk: geaenderter vector liegt nicht in Groebnerkegel! \n");
1648  }
1649 
1650  CHECK_OVERFLOW:
1651 
1652  for(i=0; i<niv; i++)
1653  {
1654  if(mpz_cmp(pert_vector[i], sing_int)>0)
1655  {
1656  if(nflow == FALSE)
1657  {
1658  Xnlev = i / nV;
1659  nflow = TRUE;
1660  Overflow_Error = TRUE;
1661  Print("\n// Xlev = %d and the %d-th element is", Xnlev, i+1);
1662  PrintS("\n// ** OVERFLOW in \"Mfpertvector\": ");
1663  mpz_out_str( stdout, 10, pert_vector[i]);
1664  PrintS(" is greater than 2147483647 (max. integer representation)");
1665  Print("\n// So vector[%d] := %d is wrong!!", i+1, (*result)[i]);
1666  }
1667  }
1668  }
1669  if(Overflow_Error == TRUE)
1670  {
1671  ivString(result, "new_vector");
1672  }
1673  omFree(pert_vector);
1674  omFree(ivtemp);
1675  mpz_clear(ztmp);
1676  mpz_clear(tot_deg);
1677  mpz_clear(maxdeg);
1678  mpz_clear(inveps);
1679  mpz_clear(sing_int);
1680 
1682  for(j=0; j<IDELEMS(G); j++)
1683  {
1684  poly p=G->m[j];
1685  while(p!=NULL)
1686  {
1687  p_Setm(p,currRing); pIter(p);
1688  }
1689  }
1690  return result;
1691 }
1692 
1693 /****************************************************************
1694  * Multiplication of two ideals element by element *
1695  * i.e. Let be A := (a_i) and B := (b_i), return C := (a_i*b_i) *
1696  * destroy A, keeps B *
1697  ****************************************************************/
1699 {
1700  int mA = IDELEMS(A), mB = IDELEMS(B);
1701 
1702  if(A==NULL || B==NULL)
1703  {
1704  return NULL;
1705  }
1706  if(mB < mA)
1707  {
1708  mA = mB;
1709  }
1710  ideal result = idInit(mA, 1);
1711 
1712  int i, k=0;
1713  for(i=0; i<mA; i++)
1714  {
1715  result->m[k] = pMult(A->m[i], pCopy(B->m[i]));
1716  A->m[i]=NULL;
1717  if (result->m[k]!=NULL)
1718  {
1719  k++;
1720  }
1721  }
1722 
1723  idDelete(&A);
1724  idSkipZeroes(result);
1725  return result;
1726 }
1727 
1728 /*********************************************************************
1729  * G is a red. Groebner basis w.r.t. <_1 *
1730  * Gomega is an initial form ideal of <G> w.r.t. a weight vector w *
1731  * M is a subideal of <Gomega> and M selft is a red. Groebner basis *
1732  * of the ideal <Gomega> w.r.t. <_w *
1733  * Let m_i = h1.gw1 + ... + hs.gws for each m_i in M; gwi in Gomega *
1734  * return F with n(F) = n(M) and f_i = h1.g1 + ... + hs.gs for each i*
1735  ********************************************************************/
1737 {
1738  ideal Mtmp = idLift(Gw, M, NULL, FALSE, TRUE, TRUE, NULL);
1739 
1740  // If Gw is a GB, then isSB = TRUE, otherwise FALSE
1741  // So, it is better, if one tests whether Gw is a GB
1742  // in ideals.cc:
1743  // idLift (ideal mod, ideal submod,ideal * rest, BOOLEAN goodShape,
1744  // BOOLEAN isSB,BOOLEAN divide,matrix * unit)
1745 
1746  // Let be Mtmp = {m1,...,ms}, where mi=sum hij.in_gj, for all i=1,...,s
1747  // We compute F = {f1,...,fs}, where fi=sum hij.gj
1748  int i, j, nM = IDELEMS(Mtmp);
1749  ideal idpol, idLG;
1750  ideal F = idInit(nM, 1);
1751 
1752  for(i=0; i<nM; i++)
1753  {
1754  idpol = idVec2Ideal(Mtmp->m[i]);
1755  idLG = MidMult(idpol, G);
1756  idpol = NULL;
1757  F->m[i] = NULL;
1758  for(j=IDELEMS(idLG)-1; j>=0; j--)
1759  {
1760  F->m[i] = pAdd(F->m[i], idLG->m[j]);
1761  idLG->m[j]=NULL;
1762  }
1763  idDelete(&idLG);
1764  }
1765  idDelete(&Mtmp);
1766  return F;
1767 }
1768 
1769 //unused
1770 #if 0
1771 static void checkidealCC(ideal G, char* Ch)
1772 {
1773  int i,nmon=0,ntmp;
1774  int nG = IDELEMS(G);
1775  int n = nG-1;
1776  Print("\n//** Ideal %s besteht aus %d Polynomen mit ", Ch, nG);
1777 
1778  for(i=0; i<nG; i++)
1779  {
1780  ntmp = pLength(G->m[i]);
1781  nmon += ntmp;
1782 
1783  if(i != n)
1784  {
1785  Print("%d, ", ntmp);
1786  }
1787  else
1788  {
1789  Print(" bzw. %d ", ntmp);
1790  }
1791  }
1792  PrintS(" Monomen.\n");
1793  Print("//** %s besitzt %d Monome.", Ch, nmon);
1794  PrintLn();
1795 }
1796 #endif
1797 
1798 //unused
1799 #if 0
1800 static void HeadidString(ideal L, char* st)
1801 {
1802  int i, nL = IDELEMS(L)-1;
1803 
1804  Print("// The head terms of the ideal %s = ", st);
1805  for(i=0; i<nL; i++)
1806  {
1807  Print(" %s, ", pString(pHead(L->m[i])));
1808  }
1809  Print(" %s;\n", pString(pHead(L->m[nL])));
1810 }
1811 #endif
1812 
1813 static inline int MivComp(intvec* iva, intvec* ivb)
1814 {
1815  assume(iva->length() == ivb->length());
1816  int i;
1817  for(i=iva->length()-1; i>=0; i--)
1818  {
1819  if((*iva)[i] - (*ivb)[i] != 0)
1820  {
1821  return 0;
1822  }
1823  }
1824  return 1;
1825 }
1826 
1827 /**********************************************
1828  * Look for the smallest absolut value in vec *
1829  **********************************************/
1830 static int MivAbsMax(intvec* vec)
1831 {
1832  int i,k;
1833  if((*vec)[0] < 0)
1834  {
1835  k = -(*vec)[0];
1836  }
1837  else
1838  {
1839  k = (*vec)[0];
1840  }
1841  for(i=1; i < (vec->length()); i++)
1842  {
1843  if((*vec)[i] < 0)
1844  {
1845  if(-(*vec)[i] > k)
1846  {
1847  k = -(*vec)[i];
1848  }
1849  }
1850  else
1851  {
1852  if((*vec)[i] > k)
1853  {
1854  k = (*vec)[i];
1855  }
1856  }
1857  }
1858  return k;
1859 }
1860 
1861 /**********************************************************************
1862  * Compute a next weight vector between curr_weight and target_weight *
1863  * with respect to an ideal <G>. *
1864 **********************************************************************/
1865 static intvec* MwalkNextWeightCC(intvec* curr_weight, intvec* target_weight,
1866  ideal G)
1867 {
1868  BOOLEAN nError = Overflow_Error;
1870 
1871  assume(currRing != NULL && curr_weight != NULL &&
1872  target_weight != NULL && G != NULL);
1873 
1874  int nRing = currRing->N;
1875  int checkRed, j, kkk, nG = IDELEMS(G);
1876  intvec* ivtemp;
1877 
1878  mpz_t t_zaehler, t_nenner;
1879  mpz_init(t_zaehler);
1880  mpz_init(t_nenner);
1881 
1882  mpz_t s_zaehler, s_nenner, temp, MwWd;
1883  mpz_init(s_zaehler);
1884  mpz_init(s_nenner);
1885  mpz_init(temp);
1886  mpz_init(MwWd);
1887 
1888  mpz_t sing_int;
1889  mpz_init(sing_int);
1890  mpz_set_si(sing_int, 2147483647);
1891 
1892  mpz_t sing_int_half;
1893  mpz_init(sing_int_half);
1894  mpz_set_si(sing_int_half, 3*(1073741824/2));
1895 
1896  mpz_t deg_w0_p1, deg_d0_p1;
1897  mpz_init(deg_w0_p1);
1898  mpz_init(deg_d0_p1);
1899 
1900  mpz_t sztn, sntz;
1901  mpz_init(sztn);
1902  mpz_init(sntz);
1903 
1904  mpz_t t_null;
1905  mpz_init(t_null);
1906 
1907  mpz_t ggt;
1908  mpz_init(ggt);
1909 
1910  mpz_t dcw;
1911  mpz_init(dcw);
1912 
1913  //int tn0, tn1, tz1, ncmp, gcd_tmp, ntmp;
1914  int gcd_tmp;
1915  intvec* diff_weight = MivSub(target_weight, curr_weight);
1916 
1917  intvec* diff_weight1 = MivSub(target_weight, curr_weight);
1918  poly g;
1919  //poly g, gw;
1920  for (j=0; j<nG; j++)
1921  {
1922  g = G->m[j];
1923  if (g != NULL)
1924  {
1925  ivtemp = MExpPol(g);
1926  mpz_set_si(deg_w0_p1, MivDotProduct(ivtemp, curr_weight));
1927  mpz_set_si(deg_d0_p1, MivDotProduct(ivtemp, diff_weight));
1928  delete ivtemp;
1929 
1930  pIter(g);
1931  while (g != NULL)
1932  {
1933  ivtemp = MExpPol(g);
1934  mpz_set_si(MwWd, MivDotProduct(ivtemp, curr_weight));
1935  mpz_sub(s_zaehler, deg_w0_p1, MwWd);
1936 
1937  if(mpz_cmp(s_zaehler, t_null) != 0)
1938  {
1939  mpz_set_si(MwWd, MivDotProduct(ivtemp, diff_weight));
1940  mpz_sub(s_nenner, MwWd, deg_d0_p1);
1941 
1942  // check for 0 < s <= 1
1943  if( (mpz_cmp(s_zaehler,t_null) > 0 &&
1944  mpz_cmp(s_nenner, s_zaehler)>=0) ||
1945  (mpz_cmp(s_zaehler, t_null) < 0 &&
1946  mpz_cmp(s_nenner, s_zaehler)<=0))
1947  {
1948  // make both positive
1949  if (mpz_cmp(s_zaehler, t_null) < 0)
1950  {
1951  mpz_neg(s_zaehler, s_zaehler);
1952  mpz_neg(s_nenner, s_nenner);
1953  }
1954 
1955  //compute a simple fraction of s
1956  cancel(s_zaehler, s_nenner);
1957 
1958  if(mpz_cmp(t_nenner, t_null) != 0)
1959  {
1960  mpz_mul(sztn, s_zaehler, t_nenner);
1961  mpz_mul(sntz, s_nenner, t_zaehler);
1962 
1963  if(mpz_cmp(sztn,sntz) < 0)
1964  {
1965  mpz_add(t_nenner, t_null, s_nenner);
1966  mpz_add(t_zaehler,t_null, s_zaehler);
1967  }
1968  }
1969  else
1970  {
1971  mpz_add(t_nenner, t_null, s_nenner);
1972  mpz_add(t_zaehler,t_null, s_zaehler);
1973  }
1974  }
1975  }
1976  pIter(g);
1977  delete ivtemp;
1978  }
1979  }
1980  }
1981 //Print("\n// Alloc Size = %d \n", nRing*sizeof(mpz_t));
1982  mpz_t *vec=(mpz_t*)omAlloc(nRing*sizeof(mpz_t));
1983 
1984 
1985  // there is no 0<t<1 and define the next weight vector that is equal to the current weight vector
1986  if(mpz_cmp(t_nenner, t_null) == 0)
1987  {
1988  #ifndef SING_NDEBUG
1989  Print("\n//MwalkNextWeightCC: t_nenner ist Null!");
1990  #endif
1991  delete diff_weight;
1992  diff_weight = ivCopy(curr_weight);//take memory
1993  goto FINISH;
1994  }
1995 
1996  // define the target vector as the next weight vector, if t = 1
1997  if(mpz_cmp_si(t_nenner, 1)==0 && mpz_cmp_si(t_zaehler,1)==0)
1998  {
1999  delete diff_weight;
2000  diff_weight = ivCopy(target_weight); //this takes memory
2001  goto FINISH;
2002  }
2003 
2004  checkRed = 0;
2005 
2006  SIMPLIFY_GCD:
2007 
2008  // simplify the vectors curr_weight and diff_weight (C-int)
2009  gcd_tmp = (*curr_weight)[0];
2010 
2011  for (j=1; j<nRing; j++)
2012  {
2013  gcd_tmp = gcd(gcd_tmp, (*curr_weight)[j]);
2014  if(gcd_tmp == 1)
2015  {
2016  break;
2017  }
2018  }
2019  if(gcd_tmp != 1)
2020  {
2021  for (j=0; j<nRing; j++)
2022  {
2023  gcd_tmp = gcd(gcd_tmp, (*diff_weight)[j]);
2024  if(gcd_tmp == 1)
2025  {
2026  break;
2027  }
2028  }
2029  }
2030  if(gcd_tmp != 1)
2031  {
2032  for (j=0; j<nRing; j++)
2033  {
2034  (*curr_weight)[j] = (*curr_weight)[j]/gcd_tmp;
2035  (*diff_weight)[j] = (*diff_weight)[j]/gcd_tmp;
2036  }
2037  }
2038  if(checkRed > 0)
2039  {
2040  for (j=0; j<nRing; j++)
2041  {
2042  mpz_set_si(vec[j], (*diff_weight)[j]);
2043  }
2044  goto TEST_OVERFLOW;
2045  }
2046 
2047 #ifdef NEXT_VECTORS_CC
2048  Print("\n// gcd of the weight vectors (current and target) = %d", gcd_tmp);
2049  ivString(curr_weight, "new cw");
2050  ivString(diff_weight, "new dw");
2051 
2052  PrintS("\n// t_zaehler: "); mpz_out_str( stdout, 10, t_zaehler);
2053  PrintS(", t_nenner: "); mpz_out_str( stdout, 10, t_nenner);
2054 #endif
2055 
2056  // BOOLEAN isdwpos;
2057 
2058  // construct a new weight vector
2059  for (j=0; j<nRing; j++)
2060  {
2061  mpz_set_si(dcw, (*curr_weight)[j]);
2062  mpz_mul(s_nenner, t_nenner, dcw);
2063 
2064  if( (*diff_weight)[j]>0)
2065  {
2066  mpz_mul_ui(s_zaehler, t_zaehler, (*diff_weight)[j]);
2067  }
2068  else
2069  {
2070  mpz_mul_ui(s_zaehler, t_zaehler, -(*diff_weight)[j]);
2071  mpz_neg(s_zaehler, s_zaehler);
2072  }
2073  mpz_add(sntz, s_nenner, s_zaehler);
2074  mpz_init_set(vec[j], sntz);
2075 
2076 #ifdef NEXT_VECTORS_CC
2077  Print("\n// j = %d ==> ", j);
2078  PrintS("(");
2079  mpz_out_str( stdout, 10, t_nenner);
2080  Print(" * %d)", (*curr_weight)[j]);
2081  Print(" + ("); mpz_out_str( stdout, 10, t_zaehler);
2082  Print(" * %d) = ", (*diff_weight)[j]);
2083  mpz_out_str( stdout, 10, s_nenner);
2084  PrintS(" + ");
2085  mpz_out_str( stdout, 10, s_zaehler);
2086  PrintS(" = "); mpz_out_str( stdout, 10, sntz);
2087  Print(" ==> vector[%d]: ", j); mpz_out_str(stdout, 10, vec[j]);
2088 #endif
2089 
2090  if(j==0)
2091  {
2092  mpz_set(ggt, sntz);
2093  }
2094  else
2095  {
2096  if(mpz_cmp_si(ggt,1) != 0)
2097  {
2098  mpz_gcd(ggt, ggt, sntz);
2099  }
2100  }
2101  }
2102 
2103 #ifdef NEXT_VECTORS_CC
2104  PrintS("\n// gcd of elements of the vector: ");
2105  mpz_out_str( stdout, 10, ggt);
2106 #endif
2107 
2108 /**********************************************************************
2109 * construct a new weight vector and check whether vec[j] is overflow, *
2110 * i.e. vec[j] > 2^31. *
2111 * If vec[j] doesn't overflow, define a weight vector. Otherwise, *
2112 * report that overflow appears. In the second case, test whether the *
2113 * the correctness of the new vector plays an important role *
2114 **********************************************************************/
2115  kkk=0;
2116  for(j=0; j<nRing; j++)
2117  {
2118  if(mpz_cmp(vec[j], sing_int_half) >= 0)
2119  {
2120  goto REDUCTION;
2121  }
2122  }
2123  checkRed = 1;
2124  for (j=0; j<nRing; j++)
2125  {
2126  (*diff_weight)[j] = mpz_get_si(vec[j]);
2127  }
2128  goto SIMPLIFY_GCD;
2129 
2130  REDUCTION:
2131  for (j=0; j<nRing; j++)
2132  {
2133  (*diff_weight)[j] = mpz_get_si(vec[j]);
2134  }
2135  while(MivAbsMax(diff_weight) >= 5)
2136  {
2137  for (j=0; j<nRing; j++)
2138  {
2139  if(mpz_cmp_si(ggt,1)==0)
2140  {
2141  (*diff_weight1)[j] = floor(0.1*(*diff_weight)[j] + 0.5);
2142  // Print("\n// vector[%d] = %d \n",j+1, (*diff_weight1)[j]);
2143  }
2144  else
2145  {
2146  mpz_divexact(vec[j], vec[j], ggt);
2147  (*diff_weight1)[j] = floor(0.1*(*diff_weight)[j] + 0.5);
2148  // Print("\n// vector[%d] = %d \n",j+1, (*diff_weight1)[j]);
2149  }
2150 /*
2151  if((*diff_weight1)[j] == 0)
2152  {
2153  kkk = kkk + 1;
2154  }
2155 */
2156  }
2157 
2158 
2159 /*
2160  if(kkk > nRing - 1)
2161  {
2162  // diff_weight was reduced to zero
2163  // Print("\n // MwalkNextWeightCC: geaenderter Vector gleich Null! \n");
2164  goto TEST_OVERFLOW;
2165  }
2166 */
2167 
2168  if(test_w_in_ConeCC(G,diff_weight1) != 0)
2169  {
2170  Print("\n// MwalkNextWeightCC: geaenderter vector liegt in Groebnerkegel! \n");
2171  for (j=0; j<nRing; j++)
2172  {
2173  (*diff_weight)[j] = (*diff_weight1)[j];
2174  }
2175  if(MivAbsMax(diff_weight) < 5)
2176  {
2177  checkRed = 1;
2178  goto SIMPLIFY_GCD;
2179  }
2180  }
2181  else
2182  {
2183  // Print("\n// MwalkNextWeightCC: geaenderter vector liegt nicht in Groebnerkegel! \n");
2184  break;
2185  }
2186  }
2187 
2188  TEST_OVERFLOW:
2189 
2190  for (j=0; j<nRing; j++)
2191  {
2192  if(mpz_cmp(vec[j], sing_int)>=0)
2193  {
2194  if(Overflow_Error == FALSE)
2195  {
2196  Overflow_Error = TRUE;
2197  PrintS("\n// ** OVERFLOW in \"MwalkNextWeightCC\": ");
2198  mpz_out_str( stdout, 10, vec[j]);
2199  PrintS(" is greater than 2147483647 (max. integer representation)\n");
2200  //Print("// So vector[%d] := %d is wrong!!\n",j+1, vec[j]);// vec[j] is mpz_t
2201  }
2202  }
2203  }
2204 
2205  FINISH:
2206  delete diff_weight1;
2207  mpz_clear(t_zaehler);
2208  mpz_clear(t_nenner);
2209  mpz_clear(s_zaehler);
2210  mpz_clear(s_nenner);
2211  mpz_clear(sntz);
2212  mpz_clear(sztn);
2213  mpz_clear(temp);
2214  mpz_clear(MwWd);
2215  mpz_clear(deg_w0_p1);
2216  mpz_clear(deg_d0_p1);
2217  mpz_clear(ggt);
2218  omFree(vec);
2219  mpz_clear(sing_int_half);
2220  mpz_clear(sing_int);
2221  mpz_clear(dcw);
2222  mpz_clear(t_null);
2223 
2224 
2225 
2226  if(Overflow_Error == FALSE)
2227  {
2228  Overflow_Error = nError;
2229  }
2231  for(kkk=0; kkk<IDELEMS(G);kkk++)
2232  {
2233  poly p=G->m[kkk];
2234  while(p!=NULL)
2235  {
2236  p_Setm(p,currRing);
2237  pIter(p);
2238  }
2239  }
2240 return diff_weight;
2241 }
2242 
2243 /**********************************************************************
2244 * Compute an intermediate weight vector from iva to ivb w.r.t. *
2245 * the reduced Groebner basis G. *
2246 * Return NULL, if it is equal to iva or iva = avb. *
2247 **********************************************************************/
2249 {
2250  intvec* tmp = new intvec(iva->length());
2251  intvec* result;
2252 
2253  if(G == NULL)
2254  {
2255  return tmp;
2256  }
2257  if(MivComp(iva, ivb) == 1)
2258  {
2259  return tmp;
2260  }
2261  result = MwalkNextWeightCC(iva, ivb, G);
2262 
2263  if(MivComp(result, iva) == 1)
2264  {
2265  delete result;
2266  return tmp;
2267  }
2268 
2269  delete tmp;
2270  return result;
2271 }
2272 
2273 /**************************************************************
2274  * define and execute a new ring which order is (a(vb),a(va),lp,C) *
2275  * ************************************************************/
2276 static void VMrHomogeneous(intvec* va, intvec* vb)
2277 {
2278 
2279  if ((currRing->ppNoether)!=NULL)
2280  {
2281  pDelete(&(currRing->ppNoether));
2282  }
2285  {
2287  }
2288 
2289  ring r = (ring) omAlloc0Bin(sip_sring_bin);
2290  int i, nv = currRing->N;
2291 
2292  r->cf = currRing->cf;
2293  r->N = currRing->N;
2294  int nb = 4;
2295 
2296 
2297  //names
2298  char* Q; // In order to avoid the corrupted memory, do not change.
2299  r->names = (char **) omAlloc0(nv * sizeof(char_ptr));
2300  for(i=0; i<nv; i++)
2301  {
2302  Q = currRing->names[i];
2303  r->names[i] = omStrDup(Q);
2304  }
2305 
2306  //weights: entries for 3 blocks: NULL Made:???
2307  r->wvhdl = (int **)omAlloc0(nb * sizeof(int_ptr));
2308  r->wvhdl[0] = (int*) omAlloc(nv*sizeof(int));
2309  r->wvhdl[1] = (int*) omAlloc((nv-1)*sizeof(int));
2310 
2311  for(i=0; i<nv-1; i++)
2312  {
2313  r->wvhdl[1][i] = (*vb)[i];
2314  r->wvhdl[0][i] = (*va)[i];
2315  }
2316  r->wvhdl[0][nv] = (*va)[nv];
2317 
2318  // order: (1..1),a,lp,C
2319  r->order = (int *) omAlloc(nb * sizeof(int *));
2320  r->block0 = (int *)omAlloc0(nb * sizeof(int *));
2321  r->block1 = (int *)omAlloc0(nb * sizeof(int *));
2322 
2323  // ringorder a for the first block: var 1..nv
2324  r->order[0] = ringorder_a;
2325  r->block0[0] = 1;
2326  r->block1[0] = nv;
2327 
2328  // ringorder a for the second block: var 2..nv
2329  r->order[1] = ringorder_a;
2330  r->block0[1] = 2;
2331  r->block1[1] = nv;
2332 
2333  // ringorder lp for the third block: var 2..nv
2334  r->order[2] = ringorder_lp;
2335  r->block0[2] = 2;
2336  r->block1[2] = nv;
2337 
2338  // ringorder C for the 4th block
2339  // it is very important within "idLift",
2340  // especially, by ring syz_ring=rCurrRingAssure_SyzComp();
2341  // therefore, nb must be (nBlocks(currRing) + 1)
2342  r->order[3] = ringorder_C;
2343 
2344  // polynomial ring
2345  r->OrdSgn = 1;
2346 
2347  // complete ring intializations
2348 
2349  rComplete(r);
2350 
2351  rChangeCurrRing(r);
2352 }
2353 
2354 
2355 /**************************************************************
2356  * define and execute a new ring which order is (a(va),lp,C) *
2357  * ************************************************************/
2358 static ring VMrDefault(intvec* va)
2359 {
2360 
2361  if ((currRing->ppNoether)!=NULL)
2362  {
2363  pDelete(&(currRing->ppNoether));
2364  }
2367  {
2369  }
2370 
2371  ring r = (ring) omAlloc0Bin(sip_sring_bin);
2372  int i, nv = currRing->N;
2373 
2374  r->cf = currRing->cf;
2375  r->N = currRing->N;
2376 
2377  int nb = 4;
2378 
2379  //names
2380  char* Q; // In order to avoid the corrupted memory, do not change.
2381  r->names = (char **) omAlloc0(nv * sizeof(char_ptr));
2382  for(i=0; i<nv; i++)
2383  {
2384  Q = currRing->names[i];
2385  r->names[i] = omStrDup(Q);
2386  }
2387 
2388  /*weights: entries for 3 blocks: NULL Made:???*/
2389  r->wvhdl = (int **)omAlloc0(nb * sizeof(int_ptr));
2390  r->wvhdl[0] = (int*) omAlloc(nv*sizeof(int));
2391  for(i=0; i<nv; i++)
2392  r->wvhdl[0][i] = (*va)[i];
2393 
2394  /* order: a,lp,C,0 */
2395  r->order = (int *) omAlloc(nb * sizeof(int *));
2396  r->block0 = (int *)omAlloc0(nb * sizeof(int *));
2397  r->block1 = (int *)omAlloc0(nb * sizeof(int *));
2398 
2399  // ringorder a for the first block: var 1..nv
2400  r->order[0] = ringorder_a;
2401  r->block0[0] = 1;
2402  r->block1[0] = nv;
2403 
2404  // ringorder lp for the second block: var 1..nv
2405  r->order[1] = ringorder_lp;
2406  r->block0[1] = 1;
2407  r->block1[1] = nv;
2408 
2409  // ringorder C for the third block
2410  // it is very important within "idLift",
2411  // especially, by ring syz_ring=rCurrRingAssure_SyzComp();
2412  // therefore, nb must be (nBlocks(currRing) + 1)
2413  r->order[2] = ringorder_C;
2414 
2415  // the last block: everything is 0
2416  r->order[3] = 0;
2417 
2418  // polynomial ring
2419  r->OrdSgn = 1;
2420 
2421  // complete ring intializations
2422 
2423  rComplete(r);
2424  return r;
2425  //rChangeCurrRing(r);
2426 }
2427 
2428 static ring VMrDefault1(intvec* va)
2429 {
2430 
2431  if ((currRing->ppNoether)!=NULL)
2432  {
2433  pDelete(&(currRing->ppNoether));
2434  }
2437  {
2439  }
2440 
2441  ring r = (ring) omAlloc0Bin(sip_sring_bin);
2442  int i, nv = currRing->N;
2443 
2444  r->cf = currRing->cf;
2445  r->N = currRing->N;
2446 
2447  int nb = 4;
2448 
2449  //names
2450  char* Q; // In order to avoid the corrupted memory, do not change.
2451  r->names = (char **) omAlloc0(nv * sizeof(char_ptr));
2452  for(i=0; i<nv; i++)
2453  {
2454  Q = currRing->names[i];
2455  r->names[i] = omStrDup(Q);
2456  }
2457 
2458  /*weights: entries for 3 blocks: NULL Made:???*/
2459  r->wvhdl = (int **)omAlloc0(nb * sizeof(int_ptr));
2460  r->wvhdl[0] = (int*) omAlloc(nv*sizeof(int));
2461  for(i=0; i<nv; i++)
2462  r->wvhdl[0][i] = (*va)[i];
2463 
2464  /* order: a,lp,C,0 */
2465  r->order = (int *) omAlloc(nb * sizeof(int *));
2466  r->block0 = (int *)omAlloc0(nb * sizeof(int *));
2467  r->block1 = (int *)omAlloc0(nb * sizeof(int *));
2468 
2469  // ringorder a for the first block: var 1..nv
2470  r->order[0] = ringorder_a;
2471  r->block0[0] = 1;
2472  r->block1[0] = nv;
2473 
2474  // ringorder lp for the second block: var 1..nv
2475  r->order[1] = ringorder_lp;
2476  r->block0[1] = 1;
2477  r->block1[1] = nv;
2478 
2479  // ringorder C for the third block
2480  // it is very important within "idLift",
2481  // especially, by ring syz_ring=rCurrRingAssure_SyzComp();
2482  // therefore, nb must be (nBlocks(currRing) + 1)
2483  r->order[2] = ringorder_C;
2484 
2485  // the last block: everything is 0
2486  r->order[3] = 0;
2487 
2488  // polynomial ring
2489  r->OrdSgn = 1;
2490 
2491  // complete ring intializations
2492 
2493  rComplete(r);
2494 
2495  //rChangeCurrRing(r);
2496  return r;
2497 }
2498 
2499 /****************************************************************
2500  * define and execute a new ring with ordering (a(va),Wp(vb),C) *
2501  * **************************************************************/
2502 
2503 static ring VMrRefine(intvec* va, intvec* vb)
2504 {
2505 
2506  if ((currRing->ppNoether)!=NULL)
2507  {
2508  pDelete(&(currRing->ppNoether));
2509  }
2512  {
2514  }
2515 
2516  ring r = (ring) omAlloc0Bin(sip_sring_bin);
2517  int i, nv = currRing->N;
2518 
2519  r->cf = currRing->cf;
2520  r->N = currRing->N;
2521  //int nb = nBlocks(currRing) + 1;
2522  int nb = 4;
2523 
2524  //names
2525  char* Q; // In order to avoid the corrupted memory, do not change.
2526  r->names = (char **) omAlloc0(nv * sizeof(char_ptr));
2527  for(i=0; i<nv; i++)
2528  {
2529  Q = currRing->names[i];
2530  r->names[i] = omStrDup(Q);
2531  }
2532 
2533  //weights: entries for 3 blocks: NULL Made:???
2534  r->wvhdl = (int **)omAlloc0(nb * sizeof(int_ptr));
2535  r->wvhdl[0] = (int*) omAlloc(nv*sizeof(int));
2536  r->wvhdl[1] = (int*) omAlloc(nv*sizeof(int));
2537 
2538  for(i=0; i<nv; i++)
2539  {
2540  r->wvhdl[0][i] = (*va)[i];
2541  r->wvhdl[1][i] = (*vb)[i];
2542  }
2543  r->wvhdl[2]=NULL;
2544  r->wvhdl[3]=NULL;
2545 
2546  // order: (1..1),a,lp,C
2547  r->order = (int *) omAlloc(nb * sizeof(int *));
2548  r->block0 = (int *)omAlloc0(nb * sizeof(int *));
2549  r->block1 = (int *)omAlloc0(nb * sizeof(int *));
2550 
2551  // ringorder a for the first block: var 1..nv
2552  r->order[0] = ringorder_a;
2553  r->block0[0] = 1;
2554  r->block1[0] = nv;
2555 
2556  // ringorder Wp for the second block: var 1..nv
2557  r->order[1] = ringorder_Wp;
2558  r->block0[1] = 1;
2559  r->block1[1] = nv;
2560 
2561  // ringorder lp for the third block: var 1..nv
2562  r->order[2] = ringorder_C;
2563  r->block0[2] = 1;
2564  r->block1[2] = nv;
2565 
2566  // ringorder C for the 4th block
2567  // it is very important within "idLift",
2568  // especially, by ring syz_ring=rCurrRingAssure_SyzComp();
2569  // therefore, nb must be (nBlocks(currRing) + 1)
2570  r->order[3] = 0;
2571 
2572  // polynomial ring
2573  r->OrdSgn = 1;
2574 
2575  // complete ring intializations
2576 
2577  rComplete(r);
2578 
2579  //rChangeCurrRing(r);
2580  return r;
2581 }
2582 
2583 /*****************************************************
2584  * define and execute a new ring with ordering (M,C) *
2585  *****************************************************/
2586 static ring VMatrDefault(intvec* va)
2587 {
2588 
2589  if ((currRing->ppNoether)!=NULL)
2590  {
2591  pDelete(&(currRing->ppNoether));
2592  }
2595  {
2597  }
2598 
2599  ring r = (ring) omAlloc0Bin(sip_sring_bin);
2600  int i, nv = currRing->N;
2601 
2602  r->cf = currRing->cf;
2603  r->N = currRing->N;
2604 
2605  int nb = 4;
2606 
2607  //names
2608  char* Q; // In order to avoid the corrupted memory, do not change.
2609  r->names = (char **) omAlloc0(nv * sizeof(char_ptr));
2610  for(i=0; i<nv; i++)
2611  {
2612  Q = currRing->names[i];
2613  r->names[i] = omStrDup(Q);
2614  }
2615 
2616  /*weights: entries for 3 blocks: NULL Made:???*/
2617  r->wvhdl = (int **)omAlloc0(nb * sizeof(int_ptr));
2618  r->wvhdl[0] = (int*) omAlloc(nv*nv*sizeof(int));
2619  r->wvhdl[1] =NULL; // (int*) omAlloc(nv*sizeof(int));
2620  r->wvhdl[2]=NULL;
2621  r->wvhdl[3]=NULL;
2622  for(i=0; i<nv*nv; i++)
2623  r->wvhdl[0][i] = (*va)[i];
2624 
2625  /* order: a,lp,C,0 */
2626  r->order = (int *) omAlloc(nb * sizeof(int *));
2627  r->block0 = (int *)omAlloc0(nb * sizeof(int *));
2628  r->block1 = (int *)omAlloc0(nb * sizeof(int *));
2629 
2630  // ringorder a for the first block: var 1..nv
2631  r->order[0] = ringorder_M;
2632  r->block0[0] = 1;
2633  r->block1[0] = nv;
2634 
2635  // ringorder C for the second block
2636  r->order[1] = ringorder_C;
2637  r->block0[1] = 1;
2638  r->block1[1] = nv;
2639 
2640 
2641 // ringorder C for the third block: var 1..nv
2642  r->order[2] = ringorder_C;
2643  r->block0[2] = 1;
2644  r->block1[2] = nv;
2645 
2646 
2647  // the last block: everything is 0
2648  r->order[3] = 0;
2649 
2650  // polynomial ring
2651  r->OrdSgn = 1;
2652 
2653  // complete ring intializations
2654 
2655  rComplete(r);
2656 
2657  //rChangeCurrRing(r);
2658  return r;
2659 }
2660 
2661 /***********************************************************
2662  * define and execute a new ring with ordering (a(vb),M,C) *
2663  ***********************************************************/
2664 static ring VMatrRefine(intvec* va, intvec* vb)
2665 {
2666 
2667  if ((currRing->ppNoether)!=NULL)
2668  {
2669  pDelete(&(currRing->ppNoether));
2670  }
2673  {
2675  }
2676 
2677  ring r = (ring) omAlloc0Bin(sip_sring_bin);
2678  int i, nv = currRing->N;
2679  int nvs = nv*nv;
2680  r->cf = currRing->cf;
2681  r->N = currRing->N;
2682 
2683  int nb = 4;
2684 
2685  //names
2686  char* Q; // In order to avoid the corrupted memory, do not change.
2687  r->names = (char **) omAlloc0(nv * sizeof(char_ptr));
2688  for(i=0; i<nv; i++)
2689  {
2690  Q = currRing->names[i];
2691  r->names[i] = omStrDup(Q);
2692  }
2693 
2694  /*weights: entries for 3 blocks: NULL Made:???*/
2695  r->wvhdl = (int **)omAlloc0(nb * sizeof(int_ptr));
2696  r->wvhdl[0] = (int*) omAlloc(nv*sizeof(int));
2697  r->wvhdl[1] = (int*) omAlloc(nvs*sizeof(int));
2698  r->wvhdl[2]=NULL;
2699  r->wvhdl[3]=NULL;
2700  for(i=0; i<nvs; i++)
2701  {
2702  r->wvhdl[1][i] = (*va)[i];
2703  }
2704  for(i=0; i<nv; i++)
2705  {
2706  r->wvhdl[0][i] = (*vb)[i];
2707  }
2708  /* order: a,lp,C,0 */
2709  r->order = (int *) omAlloc(nb * sizeof(int *));
2710  r->block0 = (int *)omAlloc0(nb * sizeof(int *));
2711  r->block1 = (int *)omAlloc0(nb * sizeof(int *));
2712 
2713  // ringorder a for the first block: var 1..nv
2714  r->order[0] = ringorder_a;
2715  r->block0[0] = 1;
2716  r->block1[0] = nv;
2717 
2718  // ringorder M for the second block: var 1..nv
2719  r->order[1] = ringorder_M;
2720  r->block0[1] = 1;
2721  r->block1[1] = nv;
2722 
2723  // ringorder C for the third block: var 1..nv
2724  r->order[2] = ringorder_C;
2725  r->block0[2] = 1;
2726  r->block1[2] = nv;
2727 
2728 
2729  // the last block: everything is 0
2730  r->order[3] = 0;
2731 
2732  // polynomial ring
2733  r->OrdSgn = 1;
2734 
2735  // complete ring intializations
2736 
2737  rComplete(r);
2738 
2739  //rChangeCurrRing(r);
2740  return r;
2741 }
2742 
2743 /**********************************************************************
2744 * define and execute a new ring which order is a lexicographic order *
2745 ***********************************************************************/
2746 static void VMrDefaultlp(void)
2747 {
2748 
2749  if ((currRing->ppNoether)!=NULL)
2750  {
2751  pDelete(&(currRing->ppNoether));
2752  }
2755 
2756  {
2758  }
2759 
2760  ring r = (ring) omAlloc0Bin(sip_sring_bin);
2761  int i, nv = currRing->N;
2762 
2763  r->cf = currRing->cf;
2764  r->N = currRing->N;
2765  int nb = rBlocks(currRing) + 1;
2766 
2767  // names
2768  char* Q; // to avoid the corrupted memory, do not change!!
2769  r->names = (char **) omAlloc0(nv * sizeof(char_ptr));
2770  for(i=0; i<nv; i++)
2771  {
2772  Q = currRing->names[i];
2773  r->names[i] = omStrDup(Q);
2774  }
2775 
2776  /*weights: entries for 3 blocks: NULL Made:???*/
2777 
2778  r->wvhdl = (int **)omAlloc0(nb * sizeof(int_ptr));
2779 
2780  /* order: lp,C,0 */
2781  r->order = (int *) omAlloc(nb * sizeof(int *));
2782  r->block0 = (int *)omAlloc0(nb * sizeof(int *));
2783  r->block1 = (int *)omAlloc0(nb * sizeof(int *));
2784 
2785  /* ringorder lp for the first block: var 1..nv */
2786  r->order[0] = ringorder_lp;
2787  r->block0[0] = 1;
2788  r->block1[0] = nv;
2789 
2790  /* ringorder C for the second block */
2791  r->order[1] = ringorder_C;
2792 
2793  /* the last block: everything is 0 */
2794  r->order[2] = 0;
2795 
2796  /*polynomial ring*/
2797  r->OrdSgn = 1;
2798 
2799  /* complete ring intializations */
2800 
2801  rComplete(r);
2802 
2803  rChangeCurrRing(r);
2804 }
2805 
2806 
2807 /* define a ring with parameters und change to it */
2808 /* DefRingPar and DefRingParlp corrupt still memory */
2809 static void DefRingPar(intvec* va)
2810 {
2811  int i, nv = currRing->N;
2812  int nb = rBlocks(currRing) + 1;
2813 
2814  ring res=(ring)omAllocBin(sip_sring_bin);
2815 
2816  memcpy(res,currRing,sizeof(ip_sring));
2817 
2818  res->VarOffset = NULL;
2819  res->ref=0;
2820 
2821  res->cf = currRing->cf; currRing->cf->ref++;
2822 
2823 
2824  /*weights: entries for 3 blocks: NULL Made:???*/
2825  res->wvhdl = (int **)omAlloc0(nb * sizeof(int_ptr));
2826  res->wvhdl[0] = (int*) omAlloc(nv*sizeof(int));
2827  for(i=0; i<nv; i++)
2828  res->wvhdl[0][i] = (*va)[i];
2829 
2830  /* order: a,lp,C,0 */
2831 
2832  res->order = (int *) omAlloc(nb * sizeof(int *));
2833  res->block0 = (int *)omAlloc0(nb * sizeof(int *));
2834  res->block1 = (int *)omAlloc0(nb * sizeof(int *));
2835 
2836  // ringorder a for the first block: var 1..nv
2837  res->order[0] = ringorder_a;
2838  res->block0[0] = 1;
2839  res->block1[0] = nv;
2840 
2841  // ringorder lp for the second block: var 1..nv
2842  res->order[1] = ringorder_lp;
2843  res->block0[1] = 1;
2844  res->block1[1] = nv;
2845 
2846  // ringorder C for the third block
2847  // it is very important within "idLift",
2848  // especially, by ring syz_ring=rCurrRingAssure_SyzComp();
2849  // therefore, nb must be (nBlocks(currRing) + 1)
2850  res->order[2] = ringorder_C;
2851 
2852  // the last block: everything is 0
2853  res->order[3] = 0;
2854 
2855  // polynomial ring
2856  res->OrdSgn = 1;
2857 
2858 
2859  res->names = (char **)omAlloc0(nv * sizeof(char_ptr));
2860  for (i=nv-1; i>=0; i--)
2861  {
2862  res->names[i] = omStrDup(currRing->names[i]);
2863  }
2864  // complete ring intializations
2865  rComplete(res);
2866 
2867  // clean up history
2869  {
2871  }
2872 
2873 
2874  // execute the created ring
2875  rChangeCurrRing(res);
2876 }
2877 
2878 
2879 static void DefRingParlp(void)
2880 {
2881  int i, nv = currRing->N;
2882 
2883  ring r=(ring)omAllocBin(sip_sring_bin);
2884 
2885  memcpy(r,currRing,sizeof(ip_sring));
2886 
2887  r->VarOffset = NULL;
2888  r->ref=0;
2889 
2890  r->cf = currRing->cf; currRing->cf->ref++;
2891 
2892 
2893  r->cf = currRing->cf;
2894  r->N = currRing->N;
2895  int nb = rBlocks(currRing) + 1;
2896 
2897  // names
2898  char* Q;
2899  r->names = (char **) omAlloc0(nv * sizeof(char_ptr));
2900  for(i=nv-1; i>=0; i--)
2901  {
2902  Q = currRing->names[i];
2903  r->names[i] = omStrDup(Q);
2904  }
2905 
2906  /*weights: entries for 3 blocks: NULL Made:???*/
2907 
2908  r->wvhdl = (int **)omAlloc0(nb * sizeof(int_ptr));
2909 
2910  /* order: lp,C,0 */
2911  r->order = (int *) omAlloc(nb * sizeof(int *));
2912  r->block0 = (int *)omAlloc0(nb * sizeof(int *));
2913  r->block1 = (int *)omAlloc0(nb * sizeof(int *));
2914 
2915  /* ringorder lp for the first block: var 1..nv */
2916  r->order[0] = ringorder_lp;
2917  r->block0[0] = 1;
2918  r->block1[0] = nv;
2919 
2920  /* ringorder C for the second block */
2921  r->order[1] = ringorder_C;
2922 
2923  /* the last block: everything is 0 */
2924  r->order[2] = 0;
2925 
2926  /*polynomial ring*/
2927  r->OrdSgn = 1;
2928 
2929 
2930 // if (rParameter(currRing)!=NULL)
2931 // {
2932 // r->cf->extRing->qideal->m[0]=p_Copy(currRing->cf->extRing->qideal->m[0], currRing->cf->extRing);
2933 // int l=rPar(currRing);
2934 // r->cf->extRing->names=(char **)omAlloc(l*sizeof(char_ptr));
2935 //
2936 // for(i=l-1;i>=0;i--)
2937 // {
2938 // rParameter(r)[i]=omStrDup(rParameter(currRing)[i]);
2939 // }
2940 // }
2941 
2942  // complete ring intializations
2943 
2944  rComplete(r);
2945 
2946  // clean up history
2948  {
2950  }
2951 
2952  // execute the created ring
2953  rChangeCurrRing(r);
2954 }
2955 
2956 //unused
2957 /**************************************************************
2958  * check wheather one or more components of a vector are zero *
2959  **************************************************************/
2960 //#if 0
2961 static int isNolVector(intvec* hilb)
2962 {
2963  int i;
2964  for(i=hilb->length()-1; i>=0; i--)
2965  {
2966  if((* hilb)[i]==0)
2967  {
2968  return 1;
2969  }
2970  }
2971  return 0;
2972 }
2973 //#endif
2974 
2975 /****************************** Februar 2002 ****************************
2976  * G is a Groebner basis w.r.t. (a(curr_weight),lp) and *
2977  * we compute a GB of <G> w.r.t. the lex. order by the perturbation walk *
2978  * its perturbation degree is tp_deg *
2979  * We call the following subfunction LastGB, if *
2980  * the computed intermediate weight vector or *
2981  * if the perturbed target weight vector does NOT lie n the correct cone *
2982  **************************************************************************/
2983 
2984 static ideal LastGB(ideal G, intvec* curr_weight,int tp_deg)
2985 {
2986  BOOLEAN nError = Overflow_Error;
2988 
2989  int i, nV = currRing->N;
2990  int nwalk=0, endwalks=0, nnwinC=1;
2991  int nlast = 0;
2992  ideal Gomega, M, F, Gomega1, Gomega2, M1,F1,result,ssG;
2993  ring newRing, oldRing, TargetRing;
2994  intvec* iv_M_lp;
2995  intvec* target_weight;
2996  intvec* iv_lp = Mivlp(nV); //define (1,0,...,0)
2997  intvec* pert_target_vector;
2998  intvec* ivNull = new intvec(nV);
2999  intvec* extra_curr_weight = new intvec(nV);
3000  intvec* next_weight;
3001 
3002 #ifndef BUCHBERGER_ALG
3003  intvec* hilb_func;
3004 #endif
3005 
3006  // to avoid (1,0,...,0) as the target vector
3007  intvec* last_omega = new intvec(nV);
3008  for(i=nV-1; i>0; i--)
3009  {
3010  (*last_omega)[i] = 1;
3011  }
3012  (*last_omega)[0] = 10000;
3013 
3014  ring EXXRing = currRing;
3015 
3016  // compute a pertubed weight vector of the target weight vector
3017  if(tp_deg > 1 && tp_deg <= nV)
3018  {
3019  //..25.03.03 VMrDefaultlp();// VMrDefault(target_weight);
3020  if (rParameter (currRing) != NULL)
3021  {
3022  DefRingParlp();
3023  }
3024  else
3025  {
3026  VMrDefaultlp();
3027  }
3028  TargetRing = currRing;
3029  ssG = idrMoveR(G,EXXRing,currRing);
3030  iv_M_lp = MivMatrixOrderlp(nV);
3031  //target_weight = MPertVectorslp(ssG, iv_M_lp, tp_deg);
3032  target_weight = MPertVectors(ssG, iv_M_lp, tp_deg);
3033  delete iv_M_lp;
3034  pert_target_vector = target_weight;
3035 
3036  rChangeCurrRing(EXXRing);
3037  G = idrMoveR(ssG, TargetRing,currRing);
3038  }
3039  else
3040  {
3041  target_weight = Mivlp(nV);
3042  }
3043  //Print("\n// ring r%d_%d = %s;\n", tp_deg, nwalk, rString(currRing));
3044 
3045  while(1)
3046  {
3047  nwalk++;
3048  nstep++;
3049  to=clock();
3050  // compute a next weight vector
3051  next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
3052  xtnw=xtnw+clock()-to;
3053 
3054 #ifdef PRINT_VECTORS
3055  MivString(curr_weight, target_weight, next_weight);
3056 #endif
3057 
3058  if(Overflow_Error == TRUE)
3059  {
3060  newRing = currRing;
3061  nnwinC = 0;
3062  if(tp_deg == 1)
3063  {
3064  nlast = 1;
3065  }
3066  delete next_weight;
3067 
3068  //idElements(G, "G");
3069  //Print("\n// ring r%d_%d = %s;\n", tp_deg, nwalk, rString(currRing));
3070 
3071  break;
3072  }
3073 
3074  if(MivComp(next_weight, ivNull) == 1)
3075  {
3076  //Print("\n// ring r%d_%d = %s;\n", tp_deg, nwalk, rString(currRing));
3077  newRing = currRing;
3078  delete next_weight;
3079  break;
3080  }
3081 
3082  if(MivComp(next_weight, target_weight) == 1)
3083  endwalks = 1;
3084 
3085  for(i=nV-1; i>=0; i--)
3086  {
3087  (*extra_curr_weight)[i] = (*curr_weight)[i];
3088  }
3089  /* 06.11.01 NOT Changed */
3090  for(i=nV-1; i>=0; i--)
3091  {
3092  (*curr_weight)[i] = (*next_weight)[i];
3093  }
3094  oldRing = currRing;
3095  to=clock();
3096  // compute an initial form ideal of <G> w.r.t. "curr_vector"
3097  Gomega = MwalkInitialForm(G, curr_weight);
3098  xtif=xtif+clock()-to;
3099 
3100 #ifdef ENDWALKS
3101  if(endwalks == 1)
3102  {
3103  Print("\n// ring r%d_%d = %s;\n", tp_deg, nwalk, rString(currRing));
3104  idElements(Gomega, "Gw");
3105  headidString(Gomega, "Gw");
3106  }
3107 #endif
3108 
3109 #ifndef BUCHBERGER_ALG
3110  if(isNolVector(curr_weight) == 0)
3111  {
3112  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
3113  }
3114  else
3115  {
3116  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
3117  }
3118 #endif // BUCHBERGER_ALG
3119 
3120  /* define a new ring that its ordering is "(a(curr_weight),lp) */
3121  //..25.03.03 VMrDefault(curr_weight);
3122  if (rParameter (currRing) != NULL)
3123  {
3124  DefRingPar(curr_weight);
3125  }
3126  else
3127  {
3128  rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung
3129  }
3130  newRing = currRing;
3131  Gomega1 = idrMoveR(Gomega, oldRing,currRing);
3132 
3133  to=clock();
3134  /* compute a reduced Groebner basis of <Gomega> w.r.t. "newRing" */
3135 #ifdef BUCHBERGER_ALG
3136  M = MstdhomCC(Gomega1);
3137 #else
3138  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
3139  delete hilb_func;
3140 #endif // BUCHBERGER_ALG
3141  xtstd=xtstd+clock()-to;
3142  /* change the ring to oldRing */
3143  rChangeCurrRing(oldRing);
3144  M1 = idrMoveR(M, newRing,currRing);
3145  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
3146 
3147  to=clock();
3148  /* compute a reduced Groebner basis of <G> w.r.t. "newRing" */
3149  F = MLifttwoIdeal(Gomega2, M1, G);
3150  xtlift=xtlift+clock()-to;
3151 
3152  idDelete(&M1);
3153  idDelete(&G);
3154 
3155  /* change the ring to newRing */
3156  rChangeCurrRing(newRing);
3157  F1 = idrMoveR(F, oldRing,currRing);
3158 
3159  to=clock();
3160  /* reduce the Groebner basis <G> w.r.t. new ring */
3161  G = kInterRedCC(F1, NULL);
3162  xtred=xtred+clock()-to;
3163  idDelete(&F1);
3164 
3165  if(endwalks == 1)
3166  {
3167  //Print("\n// ring r%d_%d = %s;\n", tp_deg, nwalk, rString(currRing));
3168  break;
3169  }
3170 
3171  delete next_weight;
3172  }//while
3173 
3174  delete ivNull;
3175 
3176  if(tp_deg != 1)
3177  {
3178  //..25.03.03 VMrDefaultlp();//define and execute the ring "lp"
3179  if (rParameter (currRing) != NULL)
3180  {
3181  DefRingParlp();
3182  }
3183  else
3184  {
3185  VMrDefaultlp();
3186  }
3187  F1 = idrMoveR(G, newRing,currRing);
3188 
3189  if(nnwinC == 0 || test_w_in_ConeCC(F1, pert_target_vector) != 1)
3190  {
3191  oldRing = currRing;
3192  rChangeCurrRing(newRing);
3193  G = idrMoveR(F1, oldRing,currRing);
3194  Print("\n// takes %d steps and calls the recursion of level %d:",
3195  nwalk, tp_deg-1);
3196 
3197  F1 = LastGB(G,curr_weight, tp_deg-1);
3198  }
3199 
3200  TargetRing = currRing;
3201  rChangeCurrRing(EXXRing);
3202  result = idrMoveR(F1, TargetRing,currRing);
3203  }
3204  else
3205  {
3206  if(nlast == 1)
3207  {
3208  //OMEGA_OVERFLOW_LASTGB:
3209  /*
3210  if(MivSame(curr_weight, iv_lp) == 1)
3211  if (rParameter(currRing) != NULL)
3212  DefRingParlp();
3213  else
3214  VMrDefaultlp();
3215  else
3216  if (rParameter(currRing) != NULL)
3217  DefRingPar(curr_weight);
3218  else
3219  VMrDefault(curr_weight);
3220  */
3221 
3222  //..25.03.03 VMrDefaultlp();//define and execute the ring "lp"
3223  if (rParameter (currRing) != NULL)
3224  {
3225  DefRingParlp();
3226  }
3227  else
3228  {
3229  VMrDefaultlp();
3230  }
3231 
3232  F1 = idrMoveR(G, newRing,currRing);
3233  //Print("\n// Apply \"std\" in ring r%d_%d = %s;\n", tp_deg, nwalk, rString(currRing));
3234 
3235  G = MstdCC(F1);
3236  idDelete(&F1);
3237  newRing = currRing;
3238  }
3239 
3240  rChangeCurrRing(EXXRing);
3241  result = idrMoveR(G, newRing,currRing);
3242  }
3243  delete target_weight;
3244  delete last_omega;
3245  delete iv_lp;
3246 
3247  if(Overflow_Error == FALSE)
3248  {
3249  Overflow_Error = nError;
3250  }
3251  return(result);
3252 }
3253 
3254 /**********************************************************
3255  * check whether a polynomial of G has least 3 monomials *
3256  **********************************************************/
3257 static int lengthpoly(ideal G)
3258 {
3259  int i;
3260  for(i=IDELEMS(G)-1; i>=0; i--)
3261  {
3262 #if 0
3263  if(pLength(G->m[i])>2)
3264  {
3265  return 1;
3266  }
3267 #else
3268  if((G->m[i]!=NULL) /* len >=0 */
3269  && (G->m[i]->next!=NULL) /* len >=1 */
3270  && (G->m[i]->next->next!=NULL) /* len >=2 */
3271  && (G->m[i]->next->next->next!=NULL) /* len >=3 */
3272  //&& (G->m[i]->next->next->next->next!=NULL) /* len >=4 */
3273  )
3274  {
3275  return 1;
3276  }
3277 #endif
3278  }
3279  return 0;
3280 }
3281 
3282 /*********************************************************
3283  * check whether a polynomial of G has least 2 monomials *
3284 **********************************************************/
3285 static int islengthpoly2(ideal G)
3286 {
3287  int i;
3288  for(i=IDELEMS(G)-1; i>=0; i--)
3289  {
3290  if((G->m[i]!=NULL) /* len >=0 */
3291  && (G->m[i]->next!=NULL) /* len >=1 */
3292  && (G->m[i]->next->next!=NULL)) /* len >=2 */
3293  {
3294  return 1;
3295  }
3296  }
3297  return 0;
3298 }
3299 
3300 
3301 
3302 /* Implementation of the improved Groebner walk algorithm which is written
3303  by Quoc-Nam Tran (2000).
3304  One perturbs the original target weight vector, only if
3305  the next intermediate weight vector is equal to the current target weight
3306  vector. This must be repeated until the wanted reduced Groebner basis
3307  to reach.
3308  If the numbers of variables is big enough, the representation of the origin
3309  weight vector may be very big. Therefore, it is possible the intermediate
3310  weight vector doesn't stay in the correct Groebner cone.
3311  In this case we have just a reduced Groebner basis of the given ideal
3312  with respect to another monomial order. Then we have to compute
3313  a wanted reduced Groebner basis of it with respect to the given order.
3314  At the following subroutine we use the improved Buchberger algorithm or
3315  the changed perturbation walk algorithm with a decrased degree.
3316  */
3317 
3318 /***************************************
3319  * return the initial term of an ideal *
3320  ***************************************/
3322 {
3323  int i, nH =IDELEMS(h);
3324 
3325  ideal m = idInit(nH,h->rank);
3326 
3327  for (i=nH-1;i>=0; i--)
3328  {
3329  if (h->m[i]!=NULL)
3330  {
3331  m->m[i]=pHead(h->m[i]);
3332  }
3333  }
3334  return m;
3335 }
3336 
3337 /**********************************************
3338  * check whether two head-ideals are the same *
3339  **********************************************/
3340 static inline int test_G_GB_walk(ideal H0, ideal H1)
3341 {
3342  int i, nG = IDELEMS(H0);
3343 
3344  if(nG != IDELEMS(H1))
3345  {
3346  return 0;
3347  }
3348  for(i=nG-1; i>=0; i--)
3349  {
3350 #if 0
3351  poly t;
3352  if((t=pSub(pCopy(H0->m[i]), pCopy(H1->m[i]))) != NULL)
3353  {
3354  pDelete(&t);
3355  return 0;
3356  }
3357  pDelete(&t);
3358 #else
3359  if(!pEqualPolys(H0->m[i],H1->m[i]))
3360  {
3361  return 0;
3362  }
3363 #endif
3364  }
3365  return 1;
3366 }
3367 
3368 //unused
3369 /*****************************************************
3370  * find the maximal total degree of polynomials in G *
3371  *****************************************************/
3372 #if 0
3373 static int Trandegreebound(ideal G)
3374 {
3375  int i, nG = IDELEMS(G);
3376  // int np=1;
3377  int nV = currRing->N;
3378  int degtmp, result = 0;
3379  intvec* ivUnit = Mivdp(nV);
3380 
3381  for(i=nG-1; i>=0; i--)
3382  {
3383  // find the maximal total degree of the polynomial G[i]
3384  degtmp = MwalkWeightDegree(G->m[i], ivUnit);
3385  if(degtmp > result)
3386  {
3387  result = degtmp;
3388  }
3389  }
3390  delete ivUnit;
3391  return result;
3392 }
3393 #endif
3394 
3395 //unused
3396 /************************************************************************
3397  * perturb the weight vector iva w.r.t. the ideal G. *
3398  * the monomial order of the current ring is the w_1 weight lex. order *
3399  * define w := d^(n-1)w_1+ d^(n-2)w_2, ...+ dw_(n-1)+ w_n *
3400  * where d := 1 + max{totdeg(g):g in G}*m, or *
3401  * d := (2*maxdeg*maxdeg + (nV+1)*maxdeg)*m; *
3402  ************************************************************************/
3403 #if 0
3404 static intvec* TranPertVector(ideal G, intvec* iva)
3405 {
3406  BOOLEAN nError = Overflow_Error;
3408 
3409  int i, j;
3410  // int nG = IDELEMS(G);
3411  int nV = currRing->N;
3412 
3413  // define the sequence which expresses the current monomial ordering
3414  // w_1 = iva; w_2 = (1,0,..,0); w_n = (0,...,0,1,0)
3415  intvec* ivMat = MivMatrixOrder(iva);
3416 
3417  int mtmp, m=(*iva)[0];
3418 
3419  for(i=ivMat->length(); i>=0; i--)
3420  {
3421  mtmp = (*ivMat)[i];
3422  if(mtmp <0)
3423  {
3424  mtmp = -mtmp;
3425  }
3426  if(mtmp > m)
3427  {
3428  m = mtmp;
3429  }
3430  }
3431 
3432  // define the maximal total degree of polynomials of G
3433  mpz_t ndeg;
3434  mpz_init(ndeg);
3435 
3436  // 12 Juli 03
3437 #ifndef UPPER_BOUND
3438  mpz_set_si(ndeg, Trandegreebound(G)+1);
3439 #else
3440  mpz_t ztmp;
3441  mpz_init(ztmp);
3442 
3443  mpz_t maxdeg;
3444  mpz_init_set_si(maxdeg, Trandegreebound(G));
3445 
3446  //ndeg = (2*maxdeg*maxdeg + (nV+1)*maxdeg)*m;//Kalkbrenner (1999)
3447  mpz_pow_ui(ztmp, maxdeg, 2);
3448  mpz_mul_ui(ztmp, ztmp, 2);
3449  mpz_mul_ui(maxdeg, maxdeg, nV+1);
3450  mpz_add(ndeg, ztmp, maxdeg);
3451  mpz_mul_ui(ndeg, ndeg, m);
3452 
3453  mpz_clear(ztmp);
3454 
3455  //PrintS("\n// with the new upper degree bound (2d^2+(n+1)d)*m ");
3456  //Print("\n// where d = %d, n = %d and bound = %d", maxdeg, nV, ndeg);
3457 #endif //UPPER_BOUND
3458 
3459 #ifdef INVEPS_SMALL_IN_TRAN
3460  if(mpz_cmp_ui(ndeg, nV)>0 && nV > 3)
3461  {
3462  mpz_cdiv_q_ui(ndeg, ndeg, nV);
3463  }
3464  //PrintS("\n// choose the \"small\" inverse epsilon:");
3465  //mpz_out_str(stdout, 10, ndeg);
3466 #endif
3467  mpz_t deg_tmp;
3468  mpz_init_set(deg_tmp, ndeg);
3469 
3470  mpz_t *ivres=( mpz_t *) omAlloc(nV*sizeof(mpz_t));
3471  mpz_init_set_si(ivres[nV-1],1);
3472 
3473  for(i=nV-2; i>=0; i--)
3474  {
3475  mpz_init_set(ivres[i], deg_tmp);
3476  mpz_mul(deg_tmp, deg_tmp, ndeg);
3477  }
3478 
3479  mpz_t *ivtmp=(mpz_t *)omAlloc(nV*sizeof(mpz_t));
3480  for(i=0; i<nV; i++)
3481  {
3482  mpz_init(ivtmp[i]);
3483  }
3484  mpz_t sing_int;
3485  mpz_init_set_ui(sing_int, 2147483647);
3486 
3487  intvec* repr_vector = new intvec(nV);
3488 
3489  // define ivtmp := ndeg^(n-1).w_1 + ndeg^(n-2).w_2 + ... + w_n
3490  for(i=0; i<nV; i++)
3491  {
3492  for(j=0; j<nV; j++)
3493  {
3494  if( (*ivMat)[i*nV+j] >= 0 )
3495  {
3496  mpz_mul_ui(ivres[i], ivres[i], (*ivMat)[i*nV+j]);
3497  }
3498  else
3499  {
3500  mpz_mul_ui(ivres[i], ivres[i], -(*ivMat)[i*nV+j]);
3501  mpz_neg(ivres[i], ivres[i]);
3502  }
3503  mpz_add(ivtmp[j], ivtmp[j], ivres[i]);
3504  }
3505  }
3506  delete ivMat;
3507 
3508  int ntrue=0;
3509  for(i=0; i<nV; i++)
3510  {
3511  (*repr_vector)[i] = mpz_get_si(ivtmp[i]);
3512  if(mpz_cmp(ivtmp[i], sing_int)>=0)
3513  {
3514  ntrue++;
3515  if(Overflow_Error == FALSE)
3516  {
3517  Overflow_Error = TRUE;
3518 
3519  PrintS("\n// ** OVERFLOW in \"Repr.Vector\": ");
3520  mpz_out_str( stdout, 10, ivtmp[i]);
3521  PrintS(" is greater than 2147483647 (max. integer representation)");
3522  Print("\n// So vector[%d] := %d is wrong!!\n",i+1,(*repr_vector)[i]);
3523  }
3524  }
3525  }
3526  if(Overflow_Error == TRUE)
3527  {
3528  ivString(repr_vector, "repvector");
3529  Print("\n// %d element(s) of it are overflow!!", ntrue);
3530  }
3531 
3532  if(Overflow_Error == FALSE)
3533  Overflow_Error=nError;
3534 
3535  omFree(ivres);
3536  omFree(ivtmp);
3537 
3538  mpz_clear(sing_int);
3539  mpz_clear(deg_tmp);
3540  mpz_clear(ndeg);
3541 
3542  return repr_vector;
3543 }
3544 #endif
3545 
3546 //unused
3547 #if 0
3548 static intvec* TranPertVector_lp(ideal G)
3549 {
3550  BOOLEAN nError = Overflow_Error;
3552  // int j, nG = IDELEMS(G);
3553  int i;
3554  int nV = currRing->N;
3555 
3556  // define the maximal total degree of polynomials of G
3557  mpz_t ndeg;
3558  mpz_init(ndeg);
3559 
3560  // 12 Juli 03
3561 #ifndef UPPER_BOUND
3562  mpz_set_si(ndeg, Trandegreebound(G)+1);
3563 #else
3564  mpz_t ztmp;
3565  mpz_init(ztmp);
3566 
3567  mpz_t maxdeg;
3568  mpz_init_set_si(maxdeg, Trandegreebound(G));
3569 
3570  //ndeg = (2*maxdeg*maxdeg + (nV+1)*maxdeg);//Kalkbrenner (1999)
3571  mpz_pow_ui(ztmp, maxdeg, 2);
3572  mpz_mul_ui(ztmp, ztmp, 2);
3573  mpz_mul_ui(maxdeg, maxdeg, nV+1);
3574  mpz_add(ndeg, ztmp, maxdeg);
3575  // PrintS("\n// with the new upper degree bound (2d^2+(n+1)d)*m ");
3576  // Print("\n// where d = %d, n = %d and bound = %d",
3577  // mpz_get_si(maxdeg), nV, mpz_get_si(ndeg));
3578 
3579  mpz_clear(ztmp);
3580 
3581 #endif
3582 
3583 #ifdef INVEPS_SMALL_IN_TRAN
3584  if(mpz_cmp_ui(ndeg, nV)>0 && nV > 3)
3585  mpz_cdiv_q_ui(ndeg, ndeg, nV);
3586 
3587  //PrintS("\n// choose the \"small\" inverse epsilon:");
3588  // mpz_out_str(stdout, 10, ndeg);
3589 #endif
3590 
3591  mpz_t deg_tmp;
3592  mpz_init_set(deg_tmp, ndeg);
3593 
3594  mpz_t *ivres=(mpz_t *)omAlloc(nV*sizeof(mpz_t));
3595  mpz_init_set_si(ivres[nV-1], 1);
3596 
3597  for(i=nV-2; i>=0; i--)
3598  {
3599  mpz_init_set(ivres[i], deg_tmp);
3600  mpz_mul(deg_tmp, deg_tmp, ndeg);
3601  }
3602 
3603  mpz_t sing_int;
3604  mpz_init_set_ui(sing_int, 2147483647);
3605 
3606  intvec* repr_vector = new intvec(nV);
3607  int ntrue=0;
3608  for(i=0; i<nV; i++)
3609  {
3610  (*repr_vector)[i] = mpz_get_si(ivres[i]);
3611 
3612  if(mpz_cmp(ivres[i], sing_int)>=0)
3613  {
3614  ntrue++;
3615  if(Overflow_Error == FALSE)
3616  {
3617  Overflow_Error = TRUE;
3618  PrintS("\n// ** OVERFLOW in \"Repr.Vector\": ");
3619  mpz_out_str( stdout, 10, ivres[i]);
3620  PrintS(" is greater than 2147483647 (max. integer representation)");
3621  Print("\n// So vector[%d] := %d is wrong!!\n",i+1,(*repr_vector)[i]);
3622  }
3623  }
3624  }
3625  if(Overflow_Error == TRUE)
3626  {
3627  ivString(repr_vector, "repvector");
3628  Print("\n// %d element(s) of it are overflow!!", ntrue);
3629  }
3630  if(Overflow_Error == FALSE)
3631  Overflow_Error = nError;
3632 
3633  omFree(ivres);
3634 
3635  mpz_clear(ndeg);
3636  mpz_clear(sing_int);
3637 
3638  return repr_vector;
3639 }
3640 #endif
3641 
3642 //unused
3643 #if 0
3644 static intvec* RepresentationMatrix_Dp(ideal G, intvec* M)
3645 {
3646  BOOLEAN nError = Overflow_Error;
3648 
3649  int i, j;
3650  int nV = currRing->N;
3651 
3652  intvec* ivUnit = Mivdp(nV);
3653  int degtmp, maxdeg = 0;
3654 
3655  for(i=IDELEMS(G)-1; i>=0; i--)
3656  {
3657  // find the maximal total degree of the polynomial G[i]
3658  degtmp = MwalkWeightDegree(G->m[i], ivUnit);
3659  if(degtmp > maxdeg)
3660  maxdeg = degtmp;
3661  }
3662 
3663  mpz_t ztmp;
3664  mpz_init_set_si(ztmp, maxdeg);
3665  mpz_t *ivres=(mpz_t *)omAlloc(nV*sizeof(mpz_t));
3666  mpz_init_set_si(ivres[nV-1], 1); // (*ivres)[nV-1] = 1;
3667 
3668  for(i=nV-2; i>=0; i--)
3669  {
3670  mpz_init_set(ivres[i], ztmp); //(*ivres)[i] = ztmp;
3671  mpz_mul_ui(ztmp, ztmp, maxdeg); //ztmp *=maxdeg;
3672  }
3673 
3674  mpz_t *ivtmp=(mpz_t*)omAlloc(nV*sizeof(mpz_t));
3675  for(i=0; i<nV; i++)
3676  mpz_init(ivtmp[i]);
3677 
3678  // define ivtmp := ndeg^(n-1).w_1 + ndeg^(n-2).w_2 + ... + w_n
3679  for(i=0; i<nV; i++)
3680  for(j=0; j<nV; j++)
3681  {
3682  if((*M)[i*nV+j] < 0)
3683  {
3684  mpz_mul_ui(ztmp, ivres[i], -(*M)[i*nV+j]);
3685  mpz_neg(ztmp, ztmp);
3686  }
3687  else
3688  mpz_mul_ui(ztmp, ivres[i], (*M)[i*nV+j]);
3689 
3690  mpz_add(ivtmp[j], ivtmp[j], ztmp);
3691  }
3692  delete ivres;
3693  mpz_t sing_int;
3694  mpz_init_set_ui(sing_int, 2147483647);
3695 
3696  int ntrue=0;
3697  intvec* repvector = new intvec(nV);
3698  for(i=0; i<nV; i++)
3699  {
3700  (*repvector)[i] = mpz_get_si(ivtmp[i]);
3701  if(mpz_cmp(ivtmp[i], sing_int)>0)
3702  {
3703  ntrue++;
3704  if(Overflow_Error == FALSE)
3705  {
3706  Overflow_Error = TRUE;
3707  PrintS("\n// ** OVERFLOW in \"Repr.Matrix\": ");
3708  mpz_out_str( stdout, 10, ivtmp[i]);
3709  PrintS(" is greater than 2147483647 (max. integer representation)");
3710  Print("\n// So vector[%d] := %d is wrong!!\n",i+1,(*repvector)[i]);
3711  }
3712  }
3713  }
3714  if(Overflow_Error == TRUE)
3715  {
3716  ivString(repvector, "repvector");
3717  Print("\n// %d element(s) of it are overflow!!", ntrue);
3718  }
3719 
3720  if(Overflow_Error == FALSE)
3721  Overflow_Error = nError;
3722 
3723  mpz_clear(sing_int);
3724  mpz_clear(ztmp);
3725  omFree(ivtmp);
3726  omFree(ivres);
3727  return repvector;
3728 }
3729 #endif
3730 
3731 /*****************************************************************************
3732  * The following subroutine is the implementation of our first improved *
3733  * Groebner walk algorithm, i.e. the first altervative algorithm. *
3734  * First we use the Grobner walk algorithm and then we call the changed *
3735  * perturbation walk algorithm with decreased degree, if an intermediate *
3736  * weight vector is equal to the current target weight vector. *
3737  * This call will be only repeated until we get the wanted reduced Groebner *
3738  * basis or n times, where n is the numbers of variables. *
3739  *****************************************************************************/
3740 
3741 //unused
3742 #if 0
3743 static int testnegintvec(intvec* v)
3744 {
3745  int n = v->length();
3746  int i;
3747  for(i=0; i<n; i++)
3748  {
3749  if((*v)[i]<0)
3750  {
3751  return(1);
3752  }
3753  }
3754  return(0);
3755 }
3756 #endif
3757 
3758 // npwinc = 0, if curr_weight doesn't stay in the correct Groebner cone
3759 static ideal Rec_LastGB(ideal G, intvec* curr_weight,
3760  intvec* orig_target_weight, int tp_deg, int npwinc)
3761 {
3762  BOOLEAN nError = Overflow_Error;
3764  // BOOLEAN nOverflow_Error = FALSE;
3765 
3766  clock_t tproc=0;
3767  clock_t tinput = clock();
3768 
3769  int i, nV = currRing->N;
3770  int nwalk=0, endwalks=0, nnwinC=1;
3771  int nlast = 0;
3772  ideal Gomega, M, F, Gomega1, Gomega2, M1,F1,result,ssG;
3773  ring newRing, oldRing, TargetRing;
3774  intvec* iv_M_lp;
3775  intvec* target_weight;
3776  intvec* ivNull = new intvec(nV); //define (0,...,0)
3777  ring EXXRing = currRing;
3778  //int NEG=0; //19 juni 03
3779  intvec* next_weight;
3780 #ifndef BUCHBERGER_ALG
3781  //08 Juli 03
3782  intvec* hilb_func;
3783 #endif
3784  // to avoid (1,0,...,0) as the target vector
3785  intvec* last_omega = new intvec(nV);
3786  for(i=nV-1; i>0; i--)
3787  (*last_omega)[i] = 1;
3788  (*last_omega)[0] = 10000;
3789 
3790  BOOLEAN isGB = FALSE;
3791 
3792  // compute a pertubed weight vector of the target weight vector
3793  if(tp_deg > 1 && tp_deg <= nV)
3794  {
3795  ideal H0 = idHeadCC(G);
3796 
3797  if (rParameter (currRing) != NULL)
3798  {
3799  DefRingParlp();
3800  }
3801  else
3802  {
3803  VMrDefaultlp();
3804  }
3805  TargetRing = currRing;
3806  ssG = idrMoveR(G,EXXRing,currRing);
3807 
3808  ideal H0_tmp = idrMoveR(H0,EXXRing,currRing);
3809  ideal H1 = idHeadCC(ssG);
3810 
3811  // Apply Lemma 2.2 in Collart et. al (1997) to check whether cone(k-1) is equal to cone(k)
3812  if(test_G_GB_walk(H0_tmp,H1)==1)
3813  {
3814  idDelete(&H0_tmp);
3815  idDelete(&H1);
3816  G = ssG;
3817  ssG = NULL;
3818  newRing = currRing;
3819  delete ivNull;
3820 
3821  if(npwinc != 0)
3822  {
3823  goto LastGB_Finish;
3824  }
3825  else
3826  {
3827  isGB = TRUE;
3828  goto KSTD_Finish;
3829  }
3830  }
3831  idDelete(&H0_tmp);
3832  idDelete(&H1);
3833 
3834  iv_M_lp = MivMatrixOrderlp(nV);
3835  target_weight = MPertVectors(ssG, iv_M_lp, tp_deg);
3836  delete iv_M_lp;
3837  //PrintS("\n// Input is not GB!!");
3838  rChangeCurrRing(EXXRing);
3839  G = idrMoveR(ssG, TargetRing,currRing);
3840 
3841  if(Overflow_Error == TRUE)
3842  {
3843  //nOverflow_Error = Overflow_Error;
3844  //NEG = 1;
3845  newRing = currRing;
3846  goto JUNI_STD;
3847  }
3848  }
3849 
3850  while(1)
3851  {
3852  nwalk ++;
3853  nstep++;
3854 
3855  if(nwalk==1)
3856  {
3857  goto FIRST_STEP;
3858  }
3859  to=clock();
3860  // compute an initial form ideal of <G> w.r.t. "curr_vector"
3861  Gomega = MwalkInitialForm(G, curr_weight);
3862  xtif=xtif+clock()-to;
3863 
3864 #ifndef BUCHBERGER_ALG
3865  if(isNolVector(curr_weight) == 0)
3866  {
3867  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
3868  }
3869  else
3870  {
3871  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
3872  }
3873 #endif // BUCHBERGER_ALG
3874 
3875  oldRing = currRing;
3876 
3877  // defiNe a new ring that its ordering is "(a(curr_weight),lp)
3878  if (rParameter(currRing) != NULL)
3879  {
3880  DefRingPar(curr_weight);
3881  }
3882  else
3883  {
3884  rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung
3885  }
3886  newRing = currRing;
3887  Gomega1 = idrMoveR(Gomega, oldRing,currRing);
3888  to=clock();
3889  // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
3890 #ifdef BUCHBERGER_ALG
3891  M = MstdhomCC(Gomega1);
3892 #else
3893  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
3894  delete hilb_func;
3895 #endif // BUCHBERGER_ALG
3896  xtstd=xtstd+clock()-to;
3897  // change the ring to oldRing
3898  rChangeCurrRing(oldRing);
3899  M1 = idrMoveR(M, newRing,currRing);
3900  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
3901 
3902  to=clock();
3903  // compute a reduced Groebner basis of <G> w.r.t. "newRing" by the lifting process
3904  F = MLifttwoIdeal(Gomega2, M1, G);
3905  xtlift=xtlift+clock()-to;
3906  idDelete(&M1);
3907  idDelete(&Gomega2);
3908  idDelete(&G);
3909 
3910  // change the ring to newRing
3911  rChangeCurrRing(newRing);
3912  F1 = idrMoveR(F, oldRing,currRing);
3913 
3914  to=clock();
3915  // reduce the Groebner basis <G> w.r.t. new ring
3916  G = kInterRedCC(F1, NULL);
3917  xtred=xtred+clock()-to;
3918  idDelete(&F1);
3919 
3920  if(endwalks == 1)
3921  {
3922  break;
3923  }
3924  FIRST_STEP:
3925  to=clock();
3927  // compute a next weight vector
3928  next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
3929  xtnw=xtnw+clock()-to;
3930 #ifdef PRINT_VECTORS
3931  MivString(curr_weight, target_weight, next_weight);
3932 #endif
3933 
3934  if(Overflow_Error == TRUE)
3935  {
3936  //PrintS("\n// ** The next vector does NOT stay in Cone!!\n");
3937 #ifdef TEST_OVERFLOW
3938  goto LastGB_Finish;
3939 #endif
3940 
3941  nnwinC = 0;
3942  if(tp_deg == nV)
3943  {
3944  nlast = 1;
3945  }
3946  delete next_weight;
3947  break;
3948  }
3949 
3950  if(MivComp(next_weight, ivNull) == 1)
3951  {
3952  //newRing = currRing;
3953  delete next_weight;
3954  break;
3955  }
3956 
3957  if(MivComp(next_weight, target_weight) == 1)
3958  {
3959  if(tp_deg == nV)
3960  {
3961  endwalks = 1;
3962  }
3963  else
3964  {
3965  // REC_LAST_GB_ALT2:
3966  //nOverflow_Error = Overflow_Error;
3967  tproc=tproc+clock()-tinput;
3968  /*
3969  Print("\n// takes %d steps and calls \"Rec_LastGB\" (%d):",
3970  nwalk, tp_deg+1);
3971  */
3972  G = Rec_LastGB(G,curr_weight, orig_target_weight, tp_deg+1,nnwinC);
3973  newRing = currRing;
3974  delete next_weight;
3975  break;
3976  }
3977  }
3978 
3979  for(i=nV-1; i>=0; i--)
3980  {
3981  (*curr_weight)[i] = (*next_weight)[i];
3982  }
3983  delete next_weight;
3984  }//while
3985 
3986  delete ivNull;
3987 
3988  if(tp_deg != nV)
3989  {
3990  newRing = currRing;
3991 
3992  if (rParameter(currRing) != NULL)
3993  {
3994  DefRingParlp();
3995  }
3996  else
3997  {
3998  VMrDefaultlp();
3999  }
4000  F1 = idrMoveR(G, newRing,currRing);
4001 
4002  if(nnwinC == 0 || test_w_in_ConeCC(F1, target_weight) != 1 )
4003  {
4004  // nOverflow_Error = Overflow_Error;
4005  //Print("\n// takes %d steps and calls \"Rec_LastGB (%d):", tp_deg+1);
4006  tproc=tproc+clock()-tinput;
4007  F1 = Rec_LastGB(F1,curr_weight, orig_target_weight, tp_deg+1,nnwinC);
4008  }
4009  delete target_weight;
4010 
4011  TargetRing = currRing;
4012  rChangeCurrRing(EXXRing);
4013  result = idrMoveR(F1, TargetRing,currRing);
4014  }
4015  else
4016  {
4017  if(nlast == 1)
4018  {
4019  JUNI_STD:
4020 
4021  newRing = currRing;
4022  if (rParameter(currRing) != NULL)
4023  {
4024  DefRingParlp();
4025  }
4026  else
4027  {
4028  VMrDefaultlp();
4029  }
4030  KSTD_Finish:
4031  if(isGB == FALSE)
4032  {
4033  F1 = idrMoveR(G, newRing,currRing);
4034  }
4035  else
4036  {
4037  F1 = G;
4038  }
4039  to=clock();
4040  // Print("\n// apply the Buchberger's alg in ring = %s",rString(currRing));
4041  // idElements(F1, "F1");
4042  G = MstdCC(F1);
4043  xtextra=xtextra+clock()-to;
4044 
4045 
4046  idDelete(&F1);
4047  newRing = currRing;
4048  }
4049 
4050  LastGB_Finish:
4051  rChangeCurrRing(EXXRing);
4052  result = idrMoveR(G, newRing,currRing);
4053  }
4054 
4055  if(Overflow_Error == FALSE)
4056  {
4057  Overflow_Error=nError;
4058  }
4059 // Print("\n// \"Rec_LastGB\" (%d) took %d steps and %.2f sec.Overflow_Error (%d)", tp_deg, nwalk, ((double) tproc)/1000000, nOverflow_Error);
4060  return(result);
4061 }
4062 
4063 /* The following subroutine is the implementation of our second improved
4064  Groebner walk algorithm, i.e. the second altervative algorithm.
4065  First we use the Grobner walk algorithm and then we call the changed
4066  perturbation walk algorithm with increased degree, if an intermediate
4067  weight vector is equal to the current target weight vector.
4068  This call will be only repeated until we get the wanted reduced Groebner
4069  basis or n times, where n is the numbers of variables.
4070 */
4071 
4072 /******************************
4073  * walk + recursive LastGB *
4074  ******************************/
4075 ideal MAltwalk2(ideal Go, intvec* curr_weight, intvec* target_weight)
4076 {
4077  Set_Error(FALSE);
4079  //BOOLEAN nOverflow_Error = FALSE;
4080  //Print("// pSetm_Error = (%d)", ErrorCheck());
4081 
4082  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0; xtextra=0;
4083  xftinput = clock();
4084  clock_t tostd, tproc;
4085 
4086  nstep = 0;
4087  int i, nV = currRing->N;
4088  int nwalk=0, endwalks=0;
4089  // int nhilb = 1;
4090  ideal Gomega, M, F, Gomega1, Gomega2, M1, F1, G;
4091  //ideal G1;
4092  //ring endRing;
4093  ring newRing, oldRing;
4094  intvec* ivNull = new intvec(nV);
4095  intvec* next_weight;
4096 #if 0
4097  intvec* extra_curr_weight = new intvec(nV);
4098 #endif
4099  //intvec* hilb_func;
4100  intvec* exivlp = Mivlp(nV);
4101 
4102  ring XXRing = currRing;
4103 
4104  //Print("\n// ring r_input = %s;", rString(currRing));
4105  to = clock();
4106  /* compute the reduced Groebner basis of the given ideal w.r.t.
4107  a "fast" monomial order, e.g. degree reverse lex. order (dp) */
4108  G = MstdCC(Go);
4109  tostd=clock()-to;
4110 
4111  /*
4112  Print("\n// Computation of the first std took = %.2f sec",
4113  ((double) tostd)/1000000);
4114  */
4115  if(currRing->order[0] == ringorder_a)
4116  {
4117  goto NEXT_VECTOR;
4118  }
4119  while(1)
4120  {
4121  nwalk ++;
4122  nstep ++;
4123  to = clock();
4124  /* compute an initial form ideal of <G> w.r.t. "curr_vector" */
4125  Gomega = MwalkInitialForm(G, curr_weight);
4126  xtif=xtif+clock()-to;
4127 #if 0
4128  if(Overflow_Error == TRUE)
4129  {
4130  for(i=nV-1; i>=0; i--)
4131  (*curr_weight)[i] = (*extra_curr_weight)[i];
4132  delete extra_curr_weight;
4133  goto LAST_GB_ALT2;
4134  }
4135 #endif
4136  oldRing = currRing;
4137 
4138  /* define a new ring that its ordering is "(a(curr_weight),lp) */
4139  if (rParameter(currRing) != NULL)
4140  {
4141  DefRingPar(curr_weight);
4142  }
4143  else
4144  {
4145  rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung
4146  }
4147  newRing = currRing;
4148  Gomega1 = idrMoveR(Gomega, oldRing,currRing);
4149  to = clock();
4150  /* compute a reduced Groebner basis of <Gomega> w.r.t. "newRing" */
4151  M = MstdhomCC(Gomega1);
4152  xtstd=xtstd+clock()-to;
4153  /* change the ring to oldRing */
4154  rChangeCurrRing(oldRing);
4155  M1 = idrMoveR(M, newRing,currRing);
4156  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
4157 
4158  to = clock();
4159  /* compute the reduced Groebner basis of <G> w.r.t. "newRing"
4160  by the liftig process */
4161  F = MLifttwoIdeal(Gomega2, M1, G);
4162  xtlift=xtlift+clock()-to;
4163  idDelete(&M1);
4164  idDelete(&Gomega2);
4165  idDelete(&G);
4166 
4167  /* change the ring to newRing */
4168  rChangeCurrRing(newRing);
4169  F1 = idrMoveR(F, oldRing,currRing);
4170 
4171  to = clock();
4172  /* reduce the Groebner basis <G> w.r.t. newRing */
4173  G = kInterRedCC(F1, NULL);
4174  xtred=xtred+clock()-to;
4175  idDelete(&F1);
4176 
4177  if(endwalks == 1)
4178  break;
4179 
4180  NEXT_VECTOR:
4181  to = clock();
4182  /* compute a next weight vector */
4183  next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
4184  xtnw=xtnw+clock()-to;
4185 #ifdef PRINT_VECTORS
4186  MivString(curr_weight, target_weight, next_weight);
4187 #endif
4188 
4189  if(Overflow_Error == TRUE)
4190  {
4191  /*
4192  ivString(next_weight, "omega");
4193  PrintS("\n// ** The weight vector does NOT stay in Cone!!\n");
4194  */
4195 #ifdef TEST_OVERFLOW
4196  goto TEST_OVERFLOW_OI;
4197 #endif
4198 
4199  newRing = currRing;
4200  if (rParameter(currRing) != NULL)
4201  {
4202  DefRingPar(target_weight);
4203  }
4204  else
4205  {
4206  rChangeCurrRing(VMrDefault(target_weight)); // Aenderung
4207  }
4208  F1 = idrMoveR(G, newRing,currRing);
4209  G = MstdCC(F1);
4210  idDelete(&F1);
4211  newRing = currRing;
4212  break;
4213  }
4214 
4215  if(MivComp(next_weight, ivNull) == 1)
4216  {
4217  newRing = currRing;
4218  delete next_weight;
4219  break;
4220  }
4221 
4222  if(MivComp(next_weight, target_weight) == 1)
4223  {
4224  if(MivSame(target_weight, exivlp)==1)
4225  {
4226  // LAST_GB_ALT2:
4227  //nOverflow_Error = Overflow_Error;
4228  tproc = clock()-xftinput;
4229  //Print("\n// takes %d steps and calls the recursion of level 2:", nwalk);
4230  /* call the changed perturbation walk algorithm with degree 2 */
4231  G = Rec_LastGB(G, curr_weight, target_weight, 2,1);
4232  newRing = currRing;
4233  delete next_weight;
4234  break;
4235  }
4236  endwalks = 1;
4237  }
4238 
4239  for(i=nV-1; i>=0; i--)
4240  {
4241  //(*extra_curr_weight)[i] = (*curr_weight)[i];
4242  (*curr_weight)[i] = (*next_weight)[i];
4243  }
4244  delete next_weight;
4245  }
4246 #ifdef TEST_OVERFLOW
4247  TEST_OVERFLOW_OI:
4248 #endif
4249  rChangeCurrRing(XXRing);
4250  G = idrMoveR(G, newRing,currRing);
4251  delete ivNull;
4252  delete exivlp;
4253 
4254 #ifdef TIME_TEST
4255  // Print("\n// \"Main procedure\" took %d steps dnd %.2f sec. Overflow_Error (%d)", nwalk, ((double) tproc)/1000000, nOverflow_Error);
4256 
4257  TimeStringFractal(xftinput, tostd, xtif, xtstd, xtextra,xtlift, xtred,xtnw);
4258 
4259  Print("\n// pSetm_Error = (%d)", ErrorCheck());
4260  //Print("\n// Overflow_Error? (%d)", nOverflow_Error);
4261  Print("\n// Awalk2 took %d steps!!", nstep);
4262 #endif
4263 
4264  return(G);
4265 }
4266 
4267 
4268 /**************************************
4269  * perturb the matrix order of "lex" *
4270  **************************************/
4272 {
4273  int nV = currRing->N;
4274  intvec* iv_wlp = MivMatrixOrderlp(nV);
4275  intvec* result = Mfpertvector(I, iv_wlp);
4276  delete iv_wlp;
4277  return result;
4278 }
4279 
4283 int xn;
4286 
4287 #if 0
4288 /********************************
4289  * compute a next weight vector *
4290  ********************************/
4291 static intvec* MWalkRandomNextWeight(ideal G, intvec* curr_weight, intvec* target_weight, int weight_rad, int pert_deg)
4292 {
4293  int i, weight_norm;
4294  int nV = currRing->N;
4295  intvec* next_weight2;
4296  intvec* next_weight22 = new intvec(nV);
4297  intvec* next_weight = MwalkNextWeightCC(curr_weight,target_weight, G);
4298  if(MivComp(next_weight, target_weight) == 1)
4299  {
4300  return(next_weight);
4301  }
4302  else
4303  {
4304  //compute a perturbed next weight vector "next_weight1"
4305  intvec* next_weight1 = MkInterRedNextWeight(MPertVectors(G, MivMatrixOrder(curr_weight), pert_deg), target_weight, G);
4306  //Print("\n // size of next_weight1 = %d", sizeof((*next_weight1)));
4307 
4308  //compute a random next weight vector "next_weight2"
4309  while(1)
4310  {
4311  weight_norm = 0;
4312  while(weight_norm == 0)
4313  {
4314  for(i=0; i<nV; i++)
4315  {
4316  //Print("\n// next_weight[%d] = %d", i, (*next_weight)[i]);
4317  (*next_weight22)[i] = rand() % 60000 - 30000;
4318  weight_norm = weight_norm + (*next_weight22)[i]*(*next_weight22)[i];
4319  }
4320  weight_norm = 1 + floor(sqrt(weight_norm));
4321  }
4322 
4323  for(i=nV-1; i>=0; i--)
4324  {
4325  if((*next_weight22)[i] < 0)
4326  {
4327  (*next_weight22)[i] = 1 + (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
4328  }
4329  else
4330  {
4331  (*next_weight22)[i] = (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
4332  }
4333  //Print("\n// next_weight22[%d] = %d", i, (*next_weight22)[i]);
4334  }
4335 
4336  if(test_w_in_ConeCC(G, next_weight22) == 1)
4337  {
4338  //Print("\n//MWalkRandomNextWeight: next_weight2 im Kegel\n");
4339  next_weight2 = MkInterRedNextWeight(next_weight22, target_weight, G);
4340  delete next_weight22;
4341  break;
4342  }
4343  }
4344  intvec* result = new intvec(nV);
4345  ideal G_test = MwalkInitialForm(G, next_weight);
4346  ideal G_test1 = MwalkInitialForm(G, next_weight1);
4347  ideal G_test2 = MwalkInitialForm(G, next_weight2);
4348 
4349  // compare next_weights
4350  if(IDELEMS(G_test1) < IDELEMS(G_test))
4351  {
4352  if(IDELEMS(G_test2) <= IDELEMS(G_test1)) // |G_test2| <= |G_test1| < |G_test|
4353  {
4354  for(i=0; i<nV; i++)
4355  {
4356  (*result)[i] = (*next_weight2)[i];
4357  }
4358  }
4359  else // |G_test1| < |G_test|, |G_test1| < |G_test2|
4360  {
4361  for(i=0; i<nV; i++)
4362  {
4363  (*result)[i] = (*next_weight1)[i];
4364  }
4365  }
4366  }
4367  else
4368  {
4369  if(IDELEMS(G_test2) <= IDELEMS(G_test)) // |G_test2| <= |G_test| <= |G_test1|
4370  {
4371  for(i=0; i<nV; i++)
4372  {
4373  (*result)[i] = (*next_weight2)[i];
4374  }
4375  }
4376  else // |G_test| <= |G_test1|, |G_test| < |G_test2|
4377  {
4378  for(i=0; i<nV; i++)
4379  {
4380  (*result)[i] = (*next_weight)[i];
4381  }
4382  }
4383  }
4384  delete next_weight;
4385  delete next_weight1;
4386  idDelete(&G_test);
4387  idDelete(&G_test1);
4388  idDelete(&G_test2);
4389  if(test_w_in_ConeCC(G, result) == 1)
4390  {
4391  delete next_weight2;
4392  return result;
4393  }
4394  else
4395  {
4396  delete result;
4397  return next_weight2;
4398  }
4399  }
4400 }
4401 #endif
4402 
4403 /********************************
4404  * compute a next weight vector *
4405  ********************************/
4406 static intvec* MWalkRandomNextWeight(ideal G, intvec* curr_weight, intvec* target_weight, int weight_rad, int pert_deg)
4407 {
4408  int i, weight_norm;
4409  //int randCount=0;
4410  int nV = currRing->N;
4411  intvec* next_weight2;
4412  intvec* next_weight22 = new intvec(nV);
4413  intvec* result = new intvec(nV);
4414 
4415  //compute a perturbed next weight vector "next_weight1"
4416  //intvec* next_weight1 = MkInterRedNextWeight(MPertVectors(G,MivMatrixOrderRefine(curr_weight,target_weight),pert_deg),target_weight,G);
4417  intvec* next_weight1 =MkInterRedNextWeight(curr_weight,target_weight,G);
4418  //compute a random next weight vector "next_weight2"
4419  while(1)
4420  {
4421  weight_norm = 0;
4422  while(weight_norm == 0)
4423  {
4424  for(i=0; i<nV; i++)
4425  {
4426  (*next_weight22)[i] = rand() % 60000 - 30000;
4427  weight_norm = weight_norm + (*next_weight22)[i]*(*next_weight22)[i];
4428  }
4429  weight_norm = 1 + floor(sqrt(weight_norm));
4430  }
4431  for(i=0; i<nV; i++)
4432  {
4433  if((*next_weight22)[i] < 0)
4434  {
4435  (*next_weight22)[i] = 1 + (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
4436  }
4437  else
4438  {
4439  (*next_weight22)[i] = (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
4440  }
4441  }
4442  if(test_w_in_ConeCC(G, next_weight22) == 1)
4443  {
4444  next_weight2 = MkInterRedNextWeight(next_weight22,target_weight,G);
4445  delete next_weight22;
4446  break;
4447  }
4448  }
4449  // compute "usual" next weight vector
4450  intvec* next_weight = MwalkNextWeightCC(curr_weight,target_weight, G);
4451  ideal G_test = MwalkInitialForm(G, next_weight);
4452  ideal G_test2 = MwalkInitialForm(G, next_weight2);
4453 
4454  // compare next weights
4455  if(Overflow_Error == FALSE)
4456  {
4457  ideal G_test1 = MwalkInitialForm(G, next_weight1);
4458  if(IDELEMS(G_test1) < IDELEMS(G_test))
4459  {
4460  if(IDELEMS(G_test2) < IDELEMS(G_test1))
4461  {
4462  // |G_test2| < |G_test1| < |G_test|
4463  for(i=0; i<nV; i++)
4464  {
4465  (*result)[i] = (*next_weight2)[i];
4466  }
4467  }
4468  else
4469  {
4470  // |G_test1| < |G_test|, |G_test1| <= |G_test2|
4471  for(i=0; i<nV; i++)
4472  {
4473  (*result)[i] = (*next_weight1)[i];
4474  }
4475  }
4476  }
4477  else
4478  {
4479  if(IDELEMS(G_test2) < IDELEMS(G_test)) // |G_test2| < |G_test| <= |G_test1|
4480  {
4481  for(i=0; i<nV; i++)
4482  {
4483  (*result)[i] = (*next_weight2)[i];
4484  }
4485  }
4486  else
4487  {
4488  // |G_test| < |G_test1|, |G_test| <= |G_test2|
4489  for(i=0; i<nV; i++)
4490  {
4491  (*result)[i] = (*next_weight)[i];
4492  }
4493  }
4494  }
4495  idDelete(&G_test1);
4496  }
4497  else
4498  {
4500  if(IDELEMS(G_test2) < IDELEMS(G_test))
4501  {
4502  for(i=1; i<nV; i++)
4503  {
4504  (*result)[i] = (*next_weight2)[i];
4505  }
4506  }
4507  else
4508  {
4509  for(i=0; i<nV; i++)
4510  {
4511  (*result)[i] = (*next_weight)[i];
4512  }
4513  }
4514  }
4515  idDelete(&G_test);
4516  idDelete(&G_test2);
4517  if(test_w_in_ConeCC(G, result) == 1)
4518  {
4519  delete next_weight2;
4520  delete next_weight;
4521  delete next_weight1;
4522  return result;
4523  }
4524  else
4525  {
4526  delete result;
4527  delete next_weight2;
4528  delete next_weight1;
4529  return next_weight;
4530  }
4531 }
4532 
4533 
4534 /***************************************************************************
4535  * The procedur REC_GB_Mwalk computes a GB for <G> w.r.t. the weight order *
4536  * otw, where G is a reduced GB w.r.t. the weight order cw. *
4537  * The new procedur Mwalk calls REC_GB. *
4538  ***************************************************************************/
4539 static ideal REC_GB_Mwalk(ideal G, intvec* curr_weight, intvec* orig_target_weight,
4540  int tp_deg, int npwinc)
4541 {
4542  BOOLEAN nError = Overflow_Error;
4544 
4545  int i, nV = currRing->N;
4546  int nwalk=0, endwalks=0, nnwinC=1, nlast = 0;
4547  ideal Gomega, M, F, Gomega1, Gomega2, M1,F1,result,ssG;
4548  ring newRing, oldRing, TargetRing;
4549  intvec* target_weight;
4550  intvec* ivNull = new intvec(nV);
4551 #ifndef BUCHBERGER_ALG
4552  intvec* hilb_func;
4553  // to avoid (1,0,...,0) as the target vector
4554  intvec* last_omega = new intvec(nV);
4555  for(i=nV-1; i>0; i--)
4556  {
4557  (*last_omega)[i] = 1;
4558  }
4559  (*last_omega)[0] = 10000;
4560 #endif
4561  BOOLEAN isGB = FALSE;
4562 
4563  ring EXXRing = currRing;
4564 
4565  // compute a pertubed weight vector of the target weight vector
4566  if(tp_deg > 1 && tp_deg <= nV)
4567  {
4568  ideal H0 = idHeadCC(G);
4569  if (rParameter(currRing) != NULL)
4570  {
4571  DefRingPar(orig_target_weight);
4572  }
4573  else
4574  {
4575  rChangeCurrRing(VMrDefault(orig_target_weight)); // Aenderung
4576  }
4577  TargetRing = currRing;
4578  ssG = idrMoveR(G,EXXRing,currRing);
4579 
4580  ideal H0_tmp = idrMoveR(H0,EXXRing,currRing);
4581  ideal H1 = idHeadCC(ssG);
4582  id_Delete(&H0,EXXRing);
4583 
4584  if(test_G_GB_walk(H0_tmp,H1)==1)
4585  {
4586  //Print("\n//REC_GB_Mwalk: input in %d-th recursive is a GB!\n",tp_deg);
4587  idDelete(&H0_tmp);
4588  idDelete(&H1);
4589  G = ssG;
4590  ssG = NULL;
4591  newRing = currRing;
4592  delete ivNull;
4593  if(npwinc == 0)
4594  {
4595  isGB = TRUE;
4596  goto KSTD_Finish;
4597  }
4598  else
4599  {
4600  goto LastGB_Finish;
4601  }
4602  }
4603  idDelete(&H0_tmp);
4604  idDelete(&H1);
4605 
4606  target_weight = MPertVectors(ssG, MivMatrixOrder(orig_target_weight), tp_deg);
4607 
4608  rChangeCurrRing(EXXRing);
4609  G = idrMoveR(ssG, TargetRing,currRing);
4610  }
4611 
4612  while(1)
4613  {
4614  nwalk ++;
4615  nstep++;
4616  if(nwalk == 1)
4617  {
4618  goto NEXT_STEP;
4619  }
4620  //Print("\n//REC_GB_Mwalk: Entering the %d-th step in the %d-th recursive:\n",nwalk,tp_deg);
4621  to = clock();
4622  // compute an initial form ideal of <G> w.r.t. "curr_vector"
4623  Gomega = MwalkInitialForm(G, curr_weight);
4624  xtif = xtif + clock()-to;
4625 
4626 #ifndef BUCHBERGER_ALG
4627  if(isNolVector(curr_weight) == 0)
4628  {
4629  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
4630  }
4631  else
4632  {
4633  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
4634  }
4635 #endif
4636 
4637  oldRing = currRing;
4638 
4639  // define a new ring with ordering "(a(curr_weight),lp)
4640  if (rParameter(currRing) != NULL)
4641  {
4642  DefRingPar(curr_weight);
4643  }
4644  else
4645  {
4646  rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung
4647  }
4648  newRing = currRing;
4649  Gomega1 = idrMoveR(Gomega, oldRing,currRing);
4650 
4651  to = clock();
4652  // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
4653 #ifdef BUCHBERGER_ALG
4654  M = MstdhomCC(Gomega1);
4655 #else
4656  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
4657  delete hilb_func;
4658 #endif
4659  xtstd = xtstd + clock() - to;
4660 
4661  // change the ring to oldRing
4662  rChangeCurrRing(oldRing);
4663 
4664  M1 = idrMoveR(M, newRing,currRing);
4665  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
4666 
4667  to = clock();
4668  F = MLifttwoIdeal(Gomega2, M1, G);
4669  xtlift = xtlift + clock() -to;
4670 
4671  idDelete(&M1);
4672  idDelete(&Gomega2);
4673  idDelete(&G);
4674 
4675 
4676  // change the ring to newRing
4677  rChangeCurrRing(newRing);
4678  F1 = idrMoveR(F, oldRing,currRing);
4679 
4680  to = clock();
4681  // reduce the Groebner basis <G> w.r.t. new ring
4682  G = kInterRedCC(F1, NULL);
4683  xtred = xtred + clock() -to;
4684 
4685  idDelete(&F1);
4686 
4687  if(endwalks == 1)
4688  {
4689  break;
4690  }
4691  NEXT_STEP:
4692  to = clock();
4693  // compute a next weight vector
4694  intvec* next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
4695 
4696 
4697  xtnw = xtnw + clock() - to;
4698 
4699 #ifdef PRINT_VECTORS
4700  MivString(curr_weight, target_weight, next_weight);
4701 #endif
4702 
4703  if(Overflow_Error == TRUE)
4704  {
4705  //PrintS("\n//REC_GB_Mwalk: The computed vector does NOT stay in the correct cone!!\n");
4706  nnwinC = 0;
4707  if(tp_deg == nV)
4708  {
4709  nlast = 1;
4710  }
4711  delete next_weight;
4712  break;
4713  }
4714  if(MivComp(next_weight, ivNull) == 1)
4715  {
4716  newRing = currRing;
4717  delete next_weight;
4718  break;
4719  }
4720 
4721  if(MivComp(next_weight, target_weight) == 1)
4722  {
4723  if(tp_deg == nV)
4724  {
4725  endwalks = 1;
4726  }
4727  else
4728  {
4729  G = REC_GB_Mwalk(G,curr_weight, orig_target_weight, tp_deg+1,nnwinC);
4730  newRing = currRing;
4731  delete next_weight;
4732  break;
4733  }
4734  }
4735 
4736  for(i=nV-1; i>=0; i--)
4737  {
4738  (*curr_weight)[i] = (*next_weight)[i];
4739  }
4740  delete next_weight;
4741  }
4742 
4743  delete ivNull;
4744 
4745  if(tp_deg != nV)
4746  {
4747  newRing = currRing;
4748 
4749  if (rParameter(currRing) != NULL)
4750  {
4751  DefRingPar(orig_target_weight);
4752  }
4753  else
4754  {
4755  rChangeCurrRing(VMrDefault(orig_target_weight)); // Aenderung
4756  }
4757  F1 = idrMoveR(G, newRing,currRing);
4758 
4759  if(nnwinC == 0)
4760  {
4761  F1 = REC_GB_Mwalk(F1,curr_weight, orig_target_weight, tp_deg+1,nnwinC);
4762  }
4763  else
4764  {
4765  if(test_w_in_ConeCC(F1, target_weight) != 1)
4766  {
4767  F1 = REC_GB_Mwalk(F1,curr_weight, orig_target_weight,tp_deg+1,nnwinC);
4768  }
4769  }
4770  delete target_weight;
4771 
4772  TargetRing = currRing;
4773  rChangeCurrRing(EXXRing);
4774  result = idrMoveR(F1, TargetRing,currRing);
4775  }
4776  else
4777  {
4778  if(nlast == 1)
4779  {
4780  if (rParameter(currRing) != NULL)
4781  {
4782  DefRingPar(orig_target_weight);
4783  }
4784  else
4785  {
4786  rChangeCurrRing(VMrDefault(orig_target_weight)); // Aenderung
4787  }
4788  KSTD_Finish:
4789  if(isGB == FALSE)
4790  {
4791  F1 = idrMoveR(G, newRing,currRing);
4792  }
4793  else
4794  {
4795  F1 = G;
4796  }
4797  to=clock();
4798  // apply Buchberger alg to compute a red. GB of F1
4799  G = MstdCC(F1);
4800  xtextra=clock()-to;
4801  idDelete(&F1);
4802  newRing = currRing;
4803  }
4804 
4805  LastGB_Finish:
4806  rChangeCurrRing(EXXRing);
4807  result = idrMoveR(G, newRing,currRing);
4808  }
4809 
4810  if(Overflow_Error == FALSE)
4811  {
4812  Overflow_Error = nError;
4813  }
4814 #ifndef BUCHBERGER_ALG
4815  delete last_omega;
4816 #endif
4817  return(result);
4818 }
4819 
4820 
4821 // THE NEW GROEBNER WALK ALGORITHM
4822 // Groebnerwalk with a recursive "second" alternative GW, called REC_GB_Mwalk that only computes the last reduced GB
4823 ideal MwalkAlt(ideal Go, intvec* curr_weight, intvec* target_weight)
4824 {
4825  Set_Error(FALSE);
4827  //Print("// pSetm_Error = (%d)", ErrorCheck());
4828 
4829  clock_t tinput, tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
4830  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0;
4831  tinput = clock();
4832  clock_t tim;
4833  nstep=0;
4834  int i;
4835  int nV = currRing->N;
4836  int nwalk=0;
4837  int endwalks=0;
4838 
4839  ideal Gomega, M, F, Gomega1, Gomega2, M1, F1, G;
4840  //ideal G1;
4841  //ring endRing;
4842  ring newRing, oldRing;
4843  intvec* ivNull = new intvec(nV);
4844  intvec* exivlp = Mivlp(nV);
4845 #ifndef BUCHBERGER_ALG
4846  intvec* hilb_func;
4847 #endif
4848  intvec* tmp_weight = new intvec(nV);
4849  for(i=nV-1; i>=0; i--)
4850  (*tmp_weight)[i] = (*curr_weight)[i];
4851 
4852  // to avoid (1,0,...,0) as the target vector
4853  intvec* last_omega = new intvec(nV);
4854  for(i=nV-1; i>0; i--)
4855  (*last_omega)[i] = 1;
4856  (*last_omega)[0] = 10000;
4857 
4858  ring XXRing = currRing;
4859 
4860  to = clock();
4861  // the monomial ordering of this current ring would be "dp"
4862  G = MstdCC(Go);
4863  tostd = clock()-to;
4864 
4865  if(currRing->order[0] == ringorder_a)
4866  goto NEXT_VECTOR;
4867 
4868  while(1)
4869  {
4870  nwalk ++;
4871  nstep ++;
4872  to = clock();
4873  // compute an initial form ideal of <G> w.r.t. "curr_vector"
4874  Gomega = MwalkInitialForm(G, curr_weight);
4875  tif = tif + clock()-to;
4876  oldRing = currRing;
4877 
4878  if(endwalks == 1)
4879  {
4880  /* compute a reduced Groebner basis of Gomega w.r.t. >>_cw by
4881  the recursive changed perturbation walk alg. */
4882  tim = clock();
4883  /*
4884  Print("\n// **** Gr�bnerwalk took %d steps and ", nwalk);
4885  PrintS("\n// **** call the rec. Pert. Walk to compute a red GB of:");
4886  idElements(Gomega, "G_omega");
4887  */
4888 
4889  if(MivSame(exivlp, target_weight)==1)
4890  M = REC_GB_Mwalk(idCopy(Gomega), tmp_weight, curr_weight, 2,1);
4891  else
4892  goto NORMAL_GW;
4893  /*
4894  Print("\n// time for the last std(Gw) = %.2f sec",
4895  ((double) (clock()-tim)/1000000));
4896  PrintS("\n// ***************************************************\n");
4897  */
4898 #ifdef CHECK_IDEAL_MWALK
4899  idElements(Gomega, "G_omega");
4900  headidString(Gomega, "Gw");
4901  idElements(M, "M");
4902  //headidString(M, "M");
4903 #endif
4904  to = clock();
4905  F = MLifttwoIdeal(Gomega, M, G);
4906  xtlift = xtlift + clock() - to;
4907 
4908  idDelete(&Gomega);
4909  idDelete(&M);
4910  idDelete(&G);
4911 
4912  oldRing = currRing;
4913 
4914  /* create a new ring newRing */
4915  if (rParameter(currRing) != NULL)
4916  {
4917  DefRingPar(curr_weight);
4918  }
4919  else
4920  {
4921  rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung
4922  }
4923  newRing = currRing;
4924  F1 = idrMoveR(F, oldRing,currRing);
4925  }
4926  else
4927  {
4928  NORMAL_GW:
4929 #ifndef BUCHBERGER_ALG
4930  if(isNolVector(curr_weight) == 0)
4931  {
4932  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
4933  }
4934  else
4935  {
4936  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
4937  }
4938 #endif // BUCHBERGER_ALG
4939 
4940  // define a new ring that its ordering is "(a(curr_weight),lp)
4941  if (rParameter(currRing) != NULL)
4942  {
4943  DefRingPar(curr_weight);
4944  }
4945  else
4946  {
4947  rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung
4948  }
4949  newRing = currRing;
4950  Gomega1 = idrMoveR(Gomega, oldRing,currRing);
4951 
4952  to = clock();
4953  // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
4954 #ifdef BUCHBERGER_ALG
4955  M = MstdhomCC(Gomega1);
4956 #else
4957  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
4958  delete hilb_func;
4959 #endif // BUCHBERGER_ALG
4960  tstd = tstd + clock() - to;
4961 
4962  // change the ring to oldRing
4963  rChangeCurrRing(oldRing);
4964  M1 = idrMoveR(M, newRing,currRing);
4965  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
4966 
4967  to = clock();
4968  // compute a representation of the generators of submod (M) with respect to those of mod (Gomega). Gomega is a reduced Groebner basis w.r.t. the current ring.
4969  F = MLifttwoIdeal(Gomega2, M1, G);
4970  tlift = tlift + clock() - to;
4971 
4972  idDelete(&M1);
4973  idDelete(&Gomega2);
4974  idDelete(&G);
4975 
4976  // change the ring to newRing
4977  rChangeCurrRing(newRing);
4978  F1 = idrMoveR(F, oldRing,currRing);
4979  }
4980 
4981  to = clock();
4982  // reduce the Groebner basis <G> w.r.t. new ring
4983  G = kInterRedCC(F1, NULL);
4984  if(endwalks != 1)
4985  {
4986  tred = tred + clock() - to;
4987  }
4988  else
4989  {
4990  xtred = xtred + clock() - to;
4991  }
4992  idDelete(&F1);
4993  if(endwalks == 1)
4994  {
4995  break;
4996  }
4997  NEXT_VECTOR:
4998  to = clock();
4999  // compute a next weight vector
5000  intvec* next_weight = MkInterRedNextWeight(curr_weight,target_weight,G);
5001  tnw = tnw + clock() - to;
5002 #ifdef PRINT_VECTORS
5003  MivString(curr_weight, target_weight, next_weight);
5004 #endif
5005 
5006  //if(test_w_in_ConeCC(G, next_weight) != 1)
5007  if(Overflow_Error == TRUE)
5008  {
5009  newRing = currRing;
5010  PrintS("\n// ** The computed vector does NOT stay in Cone!!\n");
5011 
5012  if (rParameter(currRing) != NULL)
5013  {
5014  DefRingPar(target_weight);
5015  }
5016  else
5017  {
5018  rChangeCurrRing(VMrDefault(target_weight)); // Aenderung
5019  }
5020  F1 = idrMoveR(G, newRing,currRing);
5021  G = MstdCC(F1);
5022  idDelete(&F1);
5023 
5024  newRing = currRing;
5025  break;
5026  }
5027 
5028  if(MivComp(next_weight, ivNull) == 1)
5029  {
5030  newRing = currRing;
5031  delete next_weight;
5032  break;
5033  }
5034  if(MivComp(next_weight, target_weight) == 1)
5035  {
5036  endwalks = 1;
5037  }
5038  for(i=nV-1; i>=0; i--)
5039  {
5040  (*tmp_weight)[i] = (*curr_weight)[i];
5041  (*curr_weight)[i] = (*next_weight)[i];
5042  }
5043  delete next_weight;
5044  }
5045  rChangeCurrRing(XXRing);
5046  G = idrMoveR(G, newRing,currRing);
5047 
5048  delete tmp_weight;
5049  delete ivNull;
5050  delete exivlp;
5051 
5052 #ifdef TIME_TEST
5053  TimeString(tinput, tostd, tif, tstd, tlift, tred, tnw, nstep);
5054 
5055  Print("\n// pSetm_Error = (%d)", ErrorCheck());
5056  Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
5057 #endif
5058  return(G);
5059 }
5060 
5061 
5062 /*******************************
5063  * THE GROEBNER WALK ALGORITHM *
5064  *******************************/
5065 ideal Mwalk(ideal Go, intvec* orig_M, intvec* target_M, ring baseRing)
5066 {
5067  BITSET save1 = si_opt_1; // save current options
5068  //si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
5069  //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
5070  //si_opt_1|=(Sy_bit(OPT_REDTAIL)|Sy_bit(OPT_REDSB));
5071  Set_Error(FALSE);
5073 #ifdef TIME_TEST
5074  clock_t tinput, tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
5075  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0;
5076  tinput = clock();
5077  clock_t tim;
5078 #endif
5079  nstep=0;
5080  int i,nwalk,endwalks = 0;
5081  int nV = baseRing->N;
5082 
5083  ideal Gomega, M, F, Gomega1, Gomega2, M1; //, F1;
5084  ring newRing;
5085  ring XXRing = baseRing;
5086  intvec* ivNull = new intvec(nV);
5087  intvec* curr_weight = new intvec(nV);
5088  intvec* target_weight = new intvec(nV);
5089  intvec* exivlp = Mivlp(nV);
5090  intvec* tmp_weight = new intvec(nV);
5091  for(i=0; i<nV; i++)
5092  {
5093  (*tmp_weight)[i] = (*target_M)[i];
5094  }
5095  for(i=0; i<nV; i++)
5096  {
5097  (*curr_weight)[i] = (*orig_M)[i];
5098  (*target_weight)[i] = (*target_M)[i];
5099  }
5100 #ifndef BUCHBERGER_ALG
5101  intvec* hilb_func;
5102  // to avoid (1,0,...,0) as the target vector
5103  intvec* last_omega = new intvec(nV);
5104  for(i=nV-1; i>0; i--)
5105  {
5106  (*last_omega)[i] = 1;
5107  }
5108  (*last_omega)[0] = 10000;
5109 #endif
5111 #ifdef CHECK_IDEAL_MWALK
5112  idString(Go,"Go");
5113 #endif
5114 #ifdef TIME_TEST
5115  to = clock();
5116 #endif
5117  if(orig_M->length() == nV)
5118  {
5119  newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
5120  }
5121  else
5122  {
5123  newRing = VMatrDefault(orig_M);
5124  }
5125  rChangeCurrRing(newRing);
5126  ideal G = MstdCC(idrMoveR(Go,baseRing,currRing));
5127  baseRing = currRing;
5128 #ifdef TIME_TEST
5129  tostd = clock()-to;
5130 #endif
5131 
5132  nwalk = 0;
5133  while(1)
5134  {
5135  nwalk ++;
5136  nstep ++;
5137 #ifdef TIME_TEST
5138  to = clock();
5139 #endif
5140 #ifdef CHECK_IDEAL_MWALK
5141  idString(G,"G");
5142 #endif
5143  Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
5144 #ifdef TIME_TEST
5145  tif = tif + clock()-to; //time for computing initial form ideal
5146 #endif
5147 #ifdef CHECK_IDEAL_MWALK
5148  idString(Gomega,"Gomega");
5149 #endif
5150 #ifndef BUCHBERGER_ALG
5151  if(isNolVector(curr_weight) == 0)
5152  {
5153  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
5154  }
5155  else
5156  {
5157  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
5158  }
5159 #endif
5160  if(nwalk == 1)
5161  {
5162  if(orig_M->length() == nV)
5163  {
5164  newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
5165  }
5166  else
5167  {
5168  newRing = VMatrDefault(orig_M);
5169  }
5170  }
5171  else
5172  {
5173  if(target_M->length() == nV)
5174  {
5175  newRing = VMrRefine(curr_weight,target_weight); //define a new ring with ordering "(a(curr_weight),Wp(target_weight))"
5176  }
5177  else
5178  {
5179  newRing = VMatrRefine(target_M,curr_weight);
5180  }
5181  }
5182  rChangeCurrRing(newRing);
5183  Gomega1 = idrMoveR(Gomega, baseRing,currRing);
5184  idDelete(&Gomega);
5185  // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
5186 #ifdef TIME_TEST
5187  to = clock();
5188 #endif
5189 #ifndef BUCHBERGER_ALG
5190  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
5191  delete hilb_func;
5192 #else
5193  M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
5194 #endif
5195 #ifdef TIME_TEST
5196  tstd = tstd + clock() - to;
5197 #endif
5198  idSkipZeroes(M);
5199 #ifdef CHECK_IDEAL_MWALK
5200  PrintS("\n//** Mwalk: computed M.\n");
5201  idString(M, "M");
5202 #endif
5203  //change the ring to baseRing
5204  rChangeCurrRing(baseRing);
5205  M1 = idrMoveR(M, newRing,currRing);
5206  idDelete(&M);
5207  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
5208  idDelete(&Gomega1);
5209 #ifdef TIME_TEST
5210  to = clock();
5211 #endif
5212  // compute a representation of the generators of submod (M) with respect to those of mod (Gomega), where Gomega is a reduced Groebner basis w.r.t. the current ring
5213  F = MLifttwoIdeal(Gomega2, M1, G);
5214 #ifdef TIME_TEST
5215  tlift = tlift + clock() - to;
5216 #endif
5217 #ifdef CHECK_IDEAL_MWALK
5218  idString(F, "F");
5219 #endif
5220  idDelete(&Gomega2);
5221  idDelete(&M1);
5222  rChangeCurrRing(newRing); // change the ring to newRing
5223  G = idrMoveR(F,baseRing,currRing);
5224  idDelete(&F);
5225  baseRing = currRing;
5226 #ifdef TIME_TEST
5227  to = clock();
5228 #endif
5229  //G = kStd(F1,NULL,testHomog,NULL,NULL,0,0,NULL);
5230 #ifdef TIME_TEST
5231  tstd = tstd + clock() - to;
5232 #endif
5233  idSkipZeroes(G);
5234 #ifdef CHECK_IDEAL_MWALK
5235  idString(G, "G");
5236 #endif
5237 #ifdef TIME_TEST
5238  to = clock();
5239 #endif
5240  intvec* next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);
5241 #ifdef TIME_TEST
5242  tnw = tnw + clock() - to;
5243 #endif
5244 #ifdef PRINT_VECTORS
5245  MivString(curr_weight, target_weight, next_weight);
5246 #endif
5247  if(MivComp(next_weight, ivNull) == 1 || MivComp(target_weight,curr_weight) == 1)// || test_w_in_ConeCC(G, target_weight) == 1 || MivComp(next_weight,curr_weight) == 1)
5248  {
5249 #ifdef CHECK_IDEAL_MWALK
5250  PrintS("\n//** Mwalk: entering last cone.\n");
5251 #endif
5252  Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
5253  if(target_M->length() == nV)
5254  {
5255  newRing = VMrDefault(target_weight); // define a new ring with ordering "(a(curr_weight),lp)
5256  }
5257  else
5258  {
5259  newRing = VMatrDefault(target_M);
5260  }
5261  rChangeCurrRing(newRing);
5262  Gomega1 = idrMoveR(Gomega, baseRing,currRing);
5263  idDelete(&Gomega);
5264 #ifdef CHECK_IDEAL_MWALK
5265  idString(Gomega1, "Gomega");
5266 #endif
5267  M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
5268 #ifdef CHECK_IDEAL_MWALK
5269  idString(M,"M");
5270 #endif
5271  rChangeCurrRing(baseRing);
5272  M1 = idrMoveR(M, newRing,currRing);
5273  idDelete(&M);
5274  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
5275  idDelete(&Gomega1);
5276  F = MLifttwoIdeal(Gomega2, M1, G);
5277 #ifdef CHECK_IDEAL_MWALK
5278  idString(F,"F");
5279 #endif
5280  idDelete(&Gomega2);
5281  idDelete(&M1);
5282  rChangeCurrRing(newRing); // change the ring to newRing
5283  G = idrMoveR(F,baseRing,currRing);
5284  idDelete(&F);
5285  baseRing = currRing;
5286  si_opt_1 = save1; //set original options, e. g. option(RedSB)
5287  idSkipZeroes(G);
5288 #ifdef TIME_TEST
5289  to = clock();
5290 #endif
5291  // if(si_opt_1 == (Sy_bit(OPT_REDSB)))
5292  // {
5293  G = kInterRedCC(G,NULL); //reduce the Groebner basis <G> w.r.t. currRing, if option(redSB) is set
5294  // }
5295 #ifdef TIME_TEST
5296  tred = tred + clock() - to;
5297 #endif
5298  idSkipZeroes(G);
5299  delete next_weight;
5300  break;
5301 #ifdef CHECK_IDEAL_MWALK
5302  PrintS("\n//** Mwalk: last cone.\n");
5303 #endif
5304  }
5305 #ifdef CHECK_IDEAL_MWALK
5306  PrintS("\n//** Mwalk: update weight vectors.\n");
5307 #endif
5308  for(i=nV-1; i>=0; i--)
5309  {
5310  (*tmp_weight)[i] = (*curr_weight)[i];
5311  (*curr_weight)[i] = (*next_weight)[i];
5312  }
5313  delete next_weight;
5314  }
5315  rChangeCurrRing(XXRing);
5316  ideal result = idrMoveR(G,baseRing,currRing);
5317  idDelete(&G);
5318 /*#ifdef CHECK_IDEAL_MWALK
5319  pDelete(&p);
5320 #endif*/
5321  delete tmp_weight;
5322  delete ivNull;
5323  delete exivlp;
5324 #ifndef BUCHBERGER_ALG
5325  delete last_omega;
5326 #endif
5327 #ifdef TIME_TEST
5328  Print("\n//** Mwalk: Groebner Walk took %d steps.\n", nstep);
5329  TimeString(tinput, tostd, tif, tstd, tlift, tred, tnw, nstep);
5330  Print("\n//** Mwalk: Ergebnis.\n");
5331  //Print("\n// pSetm_Error = (%d)", ErrorCheck());
5332  //Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
5333 #endif
5334  return(result);
5335 }
5336 
5337 // 07.11.2012
5338 // THE RANDOM WALK ALGORITHM ideal Go, intvec* orig_M, intvec* target_M, ring baseRing
5339 ideal Mrwalk(ideal Go, intvec* orig_M, intvec* target_M, int weight_rad, int pert_deg, ring baseRing)
5340 {
5341  BITSET save1 = si_opt_1; // save current options
5342  //si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
5343  //si_opt_1 &= (~Sy_bit(OPT_REDTAIL)); // not tail reductions
5344  //si_opt_1|=(Sy_bit(OPT_REDTAIL)|Sy_bit(OPT_REDSB));
5345  Set_Error(FALSE);
5347 #ifdef TIME_TEST
5348  clock_t tinput, tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
5349  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0;
5350  tinput = clock();
5351  clock_t tim;
5352 #endif
5353  nstep=0;
5354  int i,nwalk,endwalks = 0;
5355  int nV = baseRing->N;
5356 
5357  ideal Gomega, M, F, Gomega1, Gomega2, M1; //, F1;
5358  ring newRing;
5359  ring XXRing = baseRing;
5360  intvec* ivNull = new intvec(nV);
5361  intvec* curr_weight = new intvec(nV);
5362  intvec* target_weight = new intvec(nV);
5363  intvec* exivlp = Mivlp(nV);
5364  intvec* tmp_weight = new intvec(nV);
5365  for(i=0; i<nV; i++)
5366  {
5367  (*tmp_weight)[i] = (*target_M)[i];
5368  }
5369  for(i=0; i<nV; i++)
5370  {
5371  (*curr_weight)[i] = (*orig_M)[i];
5372  (*target_weight)[i] = (*target_M)[i];
5373  }
5374 #ifndef BUCHBERGER_ALG
5375  intvec* hilb_func;
5376  // to avoid (1,0,...,0) as the target vector
5377  intvec* last_omega = new intvec(nV);
5378  for(i=nV-1; i>0; i--)
5379  {
5380  (*last_omega)[i] = 1;
5381  }
5382  (*last_omega)[0] = 10000;
5383 #endif
5385 #ifdef CHECK_IDEAL_MWALK
5386  idString(Go,"Go");
5387 #endif
5388 #ifdef TIME_TEST
5389  to = clock();
5390 #endif
5391  if(orig_M->length() == nV)
5392  {
5393  newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
5394  }
5395  else
5396  {
5397  newRing = VMatrDefault(orig_M);
5398  }
5399  rChangeCurrRing(newRing);
5400  ideal G = MstdCC(idrMoveR(Go,baseRing,currRing));
5401  baseRing = currRing;
5402 #ifdef TIME_TEST
5403  tostd = clock()-to;
5404 #endif
5405 
5406  nwalk = 0;
5407  while(1)
5408  {
5409  nwalk ++;
5410  nstep ++;
5411 #ifdef TIME_TEST
5412  to = clock();
5413 #endif
5414 #ifdef CHECK_IDEAL_MWALK
5415  idString(G,"G");
5416 #endif
5417  Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
5418 #ifdef TIME_TEST
5419  tif = tif + clock()-to; //time for computing initial form ideal
5420 #endif
5421 #ifdef CHECK_IDEAL_MWALK
5422  idString(Gomega,"Gomega");
5423 #endif
5424 #ifndef BUCHBERGER_ALG
5425  if(isNolVector(curr_weight) == 0)
5426  {
5427  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
5428  }
5429  else
5430  {
5431  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
5432  }
5433 #endif
5434  if(nwalk == 1)
5435  {
5436  if(orig_M->length() == nV)
5437  {
5438  newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
5439  }
5440  else
5441  {
5442  newRing = VMatrDefault(orig_M);
5443  }
5444  }
5445  else
5446  {
5447  if(target_M->length() == nV)
5448  {
5449  newRing = VMrRefine(curr_weight,target_weight); //define a new ring with ordering "(a(curr_weight),Wp(target_weight))"
5450  }
5451  else
5452  {
5453  newRing = VMatrRefine(target_M,curr_weight);
5454  }
5455  }
5456  rChangeCurrRing(newRing);
5457  Gomega1 = idrMoveR(Gomega, baseRing,currRing);
5458  idDelete(&Gomega);
5459  // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
5460 #ifdef TIME_TEST
5461  to = clock();
5462 #endif
5463 #ifndef BUCHBERGER_ALG
5464  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
5465  delete hilb_func;
5466 #else
5467  M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
5468 #endif
5469 #ifdef TIME_TEST
5470  tstd = tstd + clock() - to;
5471 #endif
5472  idSkipZeroes(M);
5473 #ifdef CHECK_IDEAL_MWALK
5474  PrintS("\n//** Mwalk: computed M.\n");
5475  idString(M, "M");
5476 #endif
5477  //change the ring to baseRing
5478  rChangeCurrRing(baseRing);
5479  M1 = idrMoveR(M, newRing,currRing);
5480  idDelete(&M);
5481  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
5482  idDelete(&Gomega1);
5483 #ifdef TIME_TEST
5484  to = clock();
5485 #endif
5486  // compute a representation of the generators of submod (M) with respect to those of mod (Gomega), where Gomega is a reduced Groebner basis w.r.t. the current ring
5487  F = MLifttwoIdeal(Gomega2, M1, G);
5488 #ifdef TIME_TEST
5489  tlift = tlift + clock() - to;
5490 #endif
5491 #ifdef CHECK_IDEAL_MWALK
5492  idString(F, "F");
5493 #endif
5494  idDelete(&Gomega2);
5495  idDelete(&M1);
5496  rChangeCurrRing(newRing); // change the ring to newRing
5497  G = idrMoveR(F,baseRing,currRing);
5498  idDelete(&F);
5499  baseRing = currRing;
5500 #ifdef TIME_TEST
5501  to = clock();
5502 #endif
5503  //G = kStd(F1,NULL,testHomog,NULL,NULL,0,0,NULL);
5504 #ifdef TIME_TEST
5505  tstd = tstd + clock() - to;
5506 #endif
5507  idSkipZeroes(G);
5508 #ifdef CHECK_IDEAL_MWALK
5509  idString(G, "G");
5510 #endif
5511 #ifdef TIME_TEST
5512  to = clock();
5513 #endif
5514  intvec* next_weight = MWalkRandomNextWeight(G, curr_weight, target_weight, weight_rad, pert_deg);//next_weight = MwalkNextWeightCC(curr_weight,target_weight,G);
5515 #ifdef TIME_TEST
5516  tnw = tnw + clock() - to;
5517 #endif
5518 #ifdef PRINT_VECTORS
5519  MivString(curr_weight, target_weight, next_weight);
5520 #endif
5521  if(MivComp(next_weight, ivNull) == 1 || MivComp(target_weight,curr_weight) == 1)// || test_w_in_ConeCC(G, target_weight) == 1 || MivComp(next_weight,curr_weight) == 1)
5522  {
5523 #ifdef CHECK_IDEAL_MWALK
5524  PrintS("\n//** Mwalk: entering last cone.\n");
5525 #endif
5526  Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
5527  if(target_M->length() == nV)
5528  {
5529  newRing = VMrDefault(target_weight); // define a new ring with ordering "(a(curr_weight),lp)
5530  }
5531  else
5532  {
5533  newRing = VMatrDefault(target_M);
5534  }
5535  rChangeCurrRing(newRing);
5536  Gomega1 = idrMoveR(Gomega, baseRing,currRing);
5537  idDelete(&Gomega);
5538 #ifdef CHECK_IDEAL_MWALK
5539  idString(Gomega1, "Gomega");
5540 #endif
5541  M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
5542 #ifdef CHECK_IDEAL_MWALK
5543  idString(M,"M");
5544 #endif
5545  rChangeCurrRing(baseRing);
5546  M1 = idrMoveR(M, newRing,currRing);
5547  idDelete(&M);
5548  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
5549  idDelete(&Gomega1);
5550  F = MLifttwoIdeal(Gomega2, M1, G);
5551 #ifdef CHECK_IDEAL_MWALK
5552  idString(F,"F");
5553 #endif
5554  idDelete(&Gomega2);
5555  idDelete(&M1);
5556  rChangeCurrRing(newRing); // change the ring to newRing
5557  G = idrMoveR(F,baseRing,currRing);
5558  idDelete(&F);
5559  baseRing = currRing;
5560  si_opt_1 = save1; //set original options, e. g. option(RedSB)
5561  idSkipZeroes(G);
5562 #ifdef TIME_TEST
5563  to = clock();
5564 #endif
5565  // if(si_opt_1 == (Sy_bit(OPT_REDSB)))
5566  // {
5567  //G = kInterRedCC(G,NULL); //reduce the Groebner basis <G> w.r.t. currRing, if option(redSB) is set
5568  // }
5569 #ifdef TIME_TEST
5570  tred = tred + clock() - to;
5571 #endif
5572  idSkipZeroes(G);
5573  delete next_weight;
5574  break;
5575 #ifdef CHECK_IDEAL_MWALK
5576  PrintS("\n//** Mwalk: last cone.\n");
5577 #endif
5578  }
5579 #ifdef CHECK_IDEAL_MWALK
5580  PrintS("\n//** Mwalk: update weight vectors.\n");
5581 #endif
5582  for(i=nV-1; i>=0; i--)
5583  {
5584  (*tmp_weight)[i] = (*curr_weight)[i];
5585  (*curr_weight)[i] = (*next_weight)[i];
5586  }
5587  delete next_weight;
5588  }
5589  rChangeCurrRing(XXRing);
5590  ideal result = idrMoveR(G,baseRing,currRing);
5591  idDelete(&G);
5592 /*#ifdef CHECK_IDEAL_MWALK
5593  pDelete(&p);
5594 #endif*/
5595  delete tmp_weight;
5596  delete ivNull;
5597  delete exivlp;
5598 #ifndef BUCHBERGER_ALG
5599  delete last_omega;
5600 #endif
5601 #ifdef TIME_TEST
5602  Print("\n//** Mwalk: Groebner Walk took %d steps.\n", nstep);
5603  TimeString(tinput, tostd, tif, tstd, tlift, tred, tnw, nstep);
5604  Print("\n//** Mwalk: Ergebnis.\n");
5605  //Print("\n// pSetm_Error = (%d)", ErrorCheck());
5606  //Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
5607 #endif
5608  return(result);
5609 }
5610 
5611 //unused
5612 #if 0
5613 ideal Mwalk_tst(ideal Go, intvec* curr_weight, intvec* target_weight)
5614 {
5615  //clock_t tinput=clock();
5616  //idString(Go,"Ginp");
5617  int i, nV = currRing->N;
5618  int nwalk=0, endwalks=0;
5619 
5620  ideal Gomega, M, F, Gomega1, Gomega2, M1, F1, G;
5621  // ideal G1; ring endRing;
5622  ring newRing, oldRing;
5623  intvec* ivNull = new intvec(nV);
5624  ring XXRing = currRing;
5625 
5626  intvec* tmp_weight = new intvec(nV);
5627  for(i=nV-1; i>=0; i--)
5628  {
5629  (*tmp_weight)[i] = (*curr_weight)[i];
5630  }
5631  /* the monomial ordering of this current ring would be "dp" */
5632  G = MstdCC(Go);
5633 #ifndef BUCHBERGER_ALG
5634  intvec* hilb_func;
5635 #endif
5636  /* to avoid (1,0,...,0) as the target vector */
5637  intvec* last_omega = new intvec(nV);
5638  for(i=nV-1; i>0; i--)
5639  (*last_omega)[i] = 1;
5640  (*last_omega)[0] = 10000;
5641 
5642  while(1)
5643  {
5644  nwalk ++;
5645  //Print("\n// Entering the %d-th step:", nwalk);
5646  //Print("\n// ring r[%d] = %s;", nwalk, rString(currRing));
5647  idString(G,"G");
5648  /* compute an initial form ideal of <G> w.r.t. "curr_vector" */
5649  Gomega = MwalkInitialForm(G, curr_weight);
5650  //ivString(curr_weight, "omega");
5651  idString(Gomega,"Gw");
5652 
5653 #ifndef BUCHBERGER_ALG
5654  if(isNolVector(curr_weight) == 0)
5655  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
5656  else
5657  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
5658 #endif // BUCHBERGER_ALG
5659 
5660 
5661  oldRing = currRing;
5662 
5663  /* define a new ring that its ordering is "(a(curr_weight),lp) */
5664  VMrDefault(curr_weight);
5665  newRing = currRing;
5666 
5667  Gomega1 = idrMoveR(Gomega, oldRing,currRing);
5668 
5669  /* compute a reduced Groebner basis of <Gomega> w.r.t. "newRing" */
5670 #ifdef BUCHBERGER_ALG
5671  M = MstdhomCC(Gomega1);
5672 #else
5673  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
5674  delete hilb_func;
5675 #endif // BUCHBERGER_ALG
5676 
5677  idString(M,"M");
5678 
5679  /* change the ring to oldRing */
5680  rChangeCurrRing(oldRing);
5681  M1 = idrMoveR(M, newRing,currRing);
5682  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
5683 
5684  /* compute a representation of the generators of submod (M)
5685  with respect to those of mod (Gomega).
5686  Gomega is a reduced Groebner basis w.r.t. the current ring */
5687  F = MLifttwoIdeal(Gomega2, M1, G);
5688  idDelete(&M1);
5689  idDelete(&Gomega2);
5690  idDelete(&G);
5691  idString(F,"F");
5692 
5693  /* change the ring to newRing */
5694  rChangeCurrRing(newRing);
5695  F1 = idrMoveR(F, oldRing,currRing);
5696 
5697  /* reduce the Groebner basis <G> w.r.t. new ring */
5698  G = kInterRedCC(F1, NULL);
5699  //idSkipZeroes(G);//done by kInterRed
5700  idDelete(&F1);
5701  idString(G,"G");
5702  if(endwalks == 1)
5703  break;
5704 
5705  /* compute a next weight vector */
5706  intvec* next_weight = MkInterRedNextWeight(curr_weight,target_weight,G);
5707 #ifdef PRINT_VECTORS
5708  MivString(curr_weight, target_weight, next_weight);
5709 #endif
5710 
5711  if(MivComp(next_weight, ivNull) == 1)
5712  {
5713  delete next_weight;
5714  break;
5715  }
5716  if(MivComp(next_weight, target_weight) == 1)
5717  endwalks = 1;
5718 
5719  for(i=nV-1; i>=0; i--)
5720  (*tmp_weight)[i] = (*curr_weight)[i];
5721 
5722  /* 06.11.01 to free the memory: NOT Changed!!*/
5723  for(i=nV-1; i>=0; i--)
5724  (*curr_weight)[i] = (*next_weight)[i];
5725  delete next_weight;
5726  }
5727  rChangeCurrRing(XXRing);
5728  G = idrMoveR(G, newRing,currRing);
5729 
5730  delete tmp_weight;
5731  delete ivNull;
5732  PrintLn();
5733  return(G);
5734 }
5735 #endif
5736 
5737 /**************************************************************/
5738 /* Implementation of the perturbation walk algorithm */
5739 /**************************************************************/
5740 /* If the perturbed target weight vector or an intermediate weight vector
5741  doesn't stay in the correct Groebner cone, we have only
5742  a reduced Groebner basis for the given ideal with respect to
5743  a monomial order which differs to the given order.
5744  Then we have to compute the wanted reduced Groebner basis for it.
5745  For this, we can use
5746  1) the improved Buchberger algorithm or
5747  2) the changed perturbation walk algorithm with a decreased degree.
5748 */
5749 // use kStd, if nP = 0, else call LastGB
5750 ideal Mpwalk(ideal Go, int op_deg, int tp_deg,intvec* curr_weight,
5751  intvec* target_weight, int nP)
5752 {
5753  Set_Error(FALSE );
5755  //Print("// pSetm_Error = (%d)", ErrorCheck());
5756 
5757  clock_t tinput, tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
5758  xtextra=0;
5759  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0;
5760  tinput = clock();
5761 
5762  clock_t tim;
5763 
5764  nstep = 0;
5765  int i, ntwC=1, ntestw=1, nV = currRing->N;
5766  int endwalks=0;
5767 
5768  ideal Gomega, M, F, G, Gomega1, Gomega2, M1,F1,Eresult,ssG;
5769  ring newRing, oldRing, TargetRing;
5770  intvec* iv_M_dp;
5771  intvec* iv_M_lp;
5772  intvec* exivlp = Mivlp(nV);
5773  intvec* orig_target = target_weight;
5774  intvec* pert_target_vector = target_weight;
5775  intvec* ivNull = new intvec(nV);
5776  intvec* iv_dp = MivUnit(nV);// define (1,1,...,1)
5777 #ifndef BUCHBERGER_ALG
5778  intvec* hilb_func;
5779 #endif
5780  intvec* next_weight;
5781 
5782  // to avoid (1,0,...,0) as the target vector
5783  intvec* last_omega = new intvec(nV);
5784  for(i=nV-1; i>0; i--)
5785  (*last_omega)[i] = 1;
5786  (*last_omega)[0] = 10000;
5787 
5788  ring XXRing = currRing;
5789 
5790 
5791  to = clock();
5792  /* perturbs the original vector */
5793  if(MivComp(curr_weight, iv_dp) == 1) //rOrdStr(currRing) := "dp"
5794  {
5795  G = MstdCC(Go);
5796  tostd = clock()-to;
5797  if(op_deg != 1){
5798  iv_M_dp = MivMatrixOrderdp(nV);
5799  //ivString(iv_M_dp, "iv_M_dp");
5800  curr_weight = MPertVectors(G, iv_M_dp, op_deg);
5801  }
5802  }
5803  else
5804  {
5805  //define ring order := (a(curr_weight),lp);
5806  if (rParameter(currRing) != NULL)
5807  DefRingPar(curr_weight);
5808  else
5809  rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 1
5810 
5811  G = idrMoveR(Go, XXRing,currRing);
5812  G = MstdCC(G);
5813  tostd = clock()-to;
5814  if(op_deg != 1){
5815  iv_M_dp = MivMatrixOrder(curr_weight);
5816  curr_weight = MPertVectors(G, iv_M_dp, op_deg);
5817  }
5818  }
5819  delete iv_dp;
5820  if(op_deg != 1) delete iv_M_dp;
5821 
5822  ring HelpRing = currRing;
5823 
5824  /* perturbs the target weight vector */
5825  if(tp_deg > 1 && tp_deg <= nV)
5826  {
5827  if (rParameter(currRing) != NULL)
5828  DefRingPar(target_weight);
5829  else
5830  rChangeCurrRing(VMrDefault(target_weight)); // Aenderung 2
5831 
5832  TargetRing = currRing;
5833  ssG = idrMoveR(G,HelpRing,currRing);
5834  if(MivSame(target_weight, exivlp) == 1)
5835  {
5836  iv_M_lp = MivMatrixOrderlp(nV);
5837  //ivString(iv_M_lp, "iv_M_lp");
5838  //target_weight = MPertVectorslp(ssG, iv_M_lp, tp_deg);
5839  target_weight = MPertVectors(ssG, iv_M_lp, tp_deg);
5840  }
5841  else
5842  {
5843  iv_M_lp = MivMatrixOrder(target_weight);
5844  //target_weight = MPertVectorslp(ssG, iv_M_lp, tp_deg);
5845  target_weight = MPertVectors(ssG, iv_M_lp, tp_deg);
5846  }
5847  delete iv_M_lp;
5848  pert_target_vector = target_weight;
5849  rChangeCurrRing(HelpRing);
5850  G = idrMoveR(ssG, TargetRing,currRing);
5851  }
5852  /*
5853  Print("\n// Perturbationwalkalg. vom Gradpaar (%d,%d):",op_deg,tp_deg);
5854  ivString(curr_weight, "new sigma");
5855  ivString(target_weight, "new tau");
5856  */
5857  while(1)
5858  {
5859  nstep ++;
5860  to = clock();
5861  /* compute an initial form ideal of <G> w.r.t. the weight vector
5862  "curr_weight" */
5863  Gomega = MwalkInitialForm(G, curr_weight);
5864 
5865 
5866 #ifdef ENDWALKS
5867  if(endwalks == 1){
5868  Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
5869  idElements(G, "G");
5870  // idElements(Gomega, "Gw");
5871  headidString(G, "G");
5872  //headidString(Gomega, "Gw");
5873  }
5874 #endif
5875 
5876  tif = tif + clock()-to;
5877 
5878 #ifndef BUCHBERGER_ALG
5879  if(isNolVector(curr_weight) == 0)
5880  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
5881  else
5882  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
5883 #endif // BUCHBERGER_ALG
5884 
5885  oldRing = currRing;
5886 
5887  // define a new ring with ordering "(a(curr_weight),lp)
5888  if (rParameter(currRing) != NULL)
5889  DefRingPar(curr_weight);
5890  else
5891  rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 3
5892 
5893  newRing = currRing;
5894  Gomega1 = idrMoveR(Gomega, oldRing,currRing);
5895 
5896 #ifdef ENDWALKS
5897  if(endwalks==1)
5898  {
5899  Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
5900  idElements(Gomega1, "Gw");
5901  headidString(Gomega1, "headGw");
5902  PrintS("\n// compute a rGB of Gw:\n");
5903 
5904 #ifndef BUCHBERGER_ALG
5905  ivString(hilb_func, "w");
5906 #endif
5907  }
5908 #endif
5909 
5910  tim = clock();
5911  to = clock();
5912  /* compute a reduced Groebner basis of <Gomega> w.r.t. "newRing" */
5913 #ifdef BUCHBERGER_ALG
5914  M = MstdhomCC(Gomega1);
5915 #else
5916  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
5917  delete hilb_func;
5918 #endif // BUCHBERGER_ALG
5919 
5920  if(endwalks == 1){
5921  xtstd = xtstd+clock()-to;
5922 #ifdef ENDWALKS
5923  Print("\n// time for the last std(Gw) = %.2f sec\n",
5924  ((double) clock())/1000000 -((double)tim) /1000000);
5925 #endif
5926  }
5927  else
5928  tstd=tstd+clock()-to;
5929 
5930  /* change the ring to oldRing */
5931  rChangeCurrRing(oldRing);
5932  M1 = idrMoveR(M, newRing,currRing);
5933  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
5934 
5935  //if(endwalks==1) PrintS("\n// Lifting is working:..");
5936 
5937  to=clock();
5938  /* compute a representation of the generators of submod (M)
5939  with respect to those of mod (Gomega).
5940  Gomega is a reduced Groebner basis w.r.t. the current ring */
5941  F = MLifttwoIdeal(Gomega2, M1, G);
5942  if(endwalks != 1)
5943  tlift = tlift+clock()-to;
5944  else
5945  xtlift=clock()-to;
5946 
5947  idDelete(&M1);
5948  idDelete(&Gomega2);
5949  idDelete(&G);
5950 
5951  /* change the ring to newRing */
5952  rChangeCurrRing(newRing);
5953  F1 = idrMoveR(F, oldRing,currRing);
5954 
5955  //if(endwalks==1)PrintS("\n// InterRed is working now:");
5956 
5957  to=clock();
5958  /* reduce the Groebner basis <G> w.r.t. new ring */
5959  G = kInterRedCC(F1, NULL);
5960  if(endwalks != 1)
5961  tred = tred+clock()-to;
5962  else
5963  xtred=clock()-to;
5964 
5965  idDelete(&F1);
5966 
5967  if(endwalks == 1)
5968  break;
5969 
5970  to=clock();
5971  /* compute a next weight vector */
5972  next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
5973  tnw=tnw+clock()-to;
5974 #ifdef PRINT_VECTORS
5975  MivString(curr_weight, target_weight, next_weight);
5976 #endif
5977 
5978  if(Overflow_Error == TRUE)
5979  {
5980  ntwC = 0;
5981  //ntestomega = 1;
5982  //Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
5983  //idElements(G, "G");
5984  delete next_weight;
5985  goto FINISH_160302;
5986  }
5987  if(MivComp(next_weight, ivNull) == 1){
5988  newRing = currRing;
5989  delete next_weight;
5990  //Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
5991  break;
5992  }
5993  if(MivComp(next_weight, target_weight) == 1)
5994  endwalks = 1;
5995 
5996  for(i=nV-1; i>=0; i--)
5997  (*curr_weight)[i] = (*next_weight)[i];
5998 
5999  delete next_weight;
6000  }//while
6001 
6002  if(tp_deg != 1)
6003  {
6004  FINISH_160302:
6005  if(MivSame(orig_target, exivlp) == 1)
6006  if (rParameter(currRing) != NULL)
6007  DefRingParlp();
6008  else
6009  VMrDefaultlp();
6010  else
6011  if (rParameter(currRing) != NULL)
6012  DefRingPar(orig_target);
6013  else
6014  rChangeCurrRing(VMrDefault(orig_target)); //Aenderung
6015 
6016  TargetRing=currRing;
6017  F1 = idrMoveR(G, newRing,currRing);
6018 #ifdef CHECK_IDEAL
6019  headidString(G, "G");
6020 #endif
6021 
6022 
6023  // check whether the pertubed target vector stays in the correct cone
6024  if(ntwC != 0){
6025  ntestw = test_w_in_ConeCC(F1, pert_target_vector);
6026  }
6027 
6028  if( ntestw != 1 || ntwC == 0)
6029  {
6030  /*
6031  if(ntestw != 1){
6032  ivString(pert_target_vector, "tau");
6033  PrintS("\n// ** perturbed target vector doesn't stay in cone!!");
6034  Print("\n// ring r%d = %s;\n", nstep, rString(currRing));
6035  idElements(F1, "G");
6036  }
6037  */
6038  // LastGB is "better" than the kStd subroutine
6039  to=clock();
6040  ideal eF1;
6041  if(nP == 0 || tp_deg == 1 || MivSame(orig_target, exivlp) != 1){
6042  // PrintS("\n// ** calls \"std\" to compute a GB");
6043  eF1 = MstdCC(F1);
6044  idDelete(&F1);
6045  }
6046  else {
6047  // PrintS("\n// ** calls \"LastGB\" to compute a GB");
6048  rChangeCurrRing(newRing);
6049  ideal F2 = idrMoveR(F1, TargetRing,currRing);
6050  eF1 = LastGB(F2, curr_weight, tp_deg-1);
6051  F2=NULL;
6052  }
6053  xtextra=clock()-to;
6054  ring exTargetRing = currRing;
6055 
6056  rChangeCurrRing(XXRing);
6057  Eresult = idrMoveR(eF1, exTargetRing,currRing);
6058  }
6059  else{
6060  rChangeCurrRing(XXRing);
6061  Eresult = idrMoveR(F1, TargetRing,currRing);
6062  }
6063  }
6064  else {
6065  rChangeCurrRing(XXRing);
6066  Eresult = idrMoveR(G, newRing,currRing);
6067  }
6068  delete ivNull;
6069  if(tp_deg != 1)
6070  delete target_weight;
6071 
6072  if(op_deg != 1 )
6073  delete curr_weight;
6074 
6075  delete exivlp;
6076  delete last_omega;
6077 
6078 #ifdef TIME_TEST
6079  TimeStringFractal(tinput, tostd, tif+xtif, tstd+xtstd,0, tlift+xtlift, tred+xtred,
6080  tnw+xtnw);
6081 
6082  Print("\n// pSetm_Error = (%d)", ErrorCheck());
6083  Print("\n// It took %d steps and Overflow_Error? (%d)\n", nstep, Overflow_Error);
6084 #endif
6085  return(Eresult);
6086 }
6087 
6089 
6090 // define a matrix (1 ... 1)
6092 {
6093  int i,j;
6094  intvec* ivM = new intvec(nV*nV);
6095 
6096  for(i=0; i<nV; i++)
6097  for(j=0; j<nV; j++)
6098  (*ivM)[i*nV + j] = 1;
6099 
6100  return(ivM);
6101 }
6102 
6104 int Xcall;
6106 
6107 /***********************************************************************
6108  * Perturb the start weight vector at the top level, i.e. nlev = 1 *
6109  ***********************************************************************/
6110 static ideal rec_fractal_call(ideal G, int nlev, intvec* omtmp)
6111 {
6113  //Print("\n\n// Entering the %d-th recursion:", nlev);
6114 
6115  int i, nV = currRing->N;
6116  ring new_ring, testring;
6117  //ring extoRing;
6118  ideal Gomega, Gomega1, Gomega2, F, F1, Gresult, Gresult1, G1, Gt;
6119  int nwalks = 0;
6120  intvec* Mwlp;
6121 #ifndef BUCHBERGER_ALG
6122  intvec* hilb_func;
6123 #endif
6124 // intvec* extXtau;
6125  intvec* next_vect;
6126  intvec* omega2 = new intvec(nV);
6127  intvec* altomega = new intvec(nV);
6128 
6129  //BOOLEAN isnewtarget = FALSE;
6130 
6131  // to avoid (1,0,...,0) as the target vector (Hans)
6132  intvec* last_omega = new intvec(nV);
6133  for(i=nV-1; i>0; i--)
6134  (*last_omega)[i] = 1;
6135  (*last_omega)[0] = 10000;
6136 
6137  intvec* omega = new intvec(nV);
6138  for(i=0; i<nV; i++) {
6139  if(Xsigma->length() == nV)
6140  (*omega)[i] = (*Xsigma)[i];
6141  else
6142  (*omega)[i] = (*Xsigma)[(nV*(nlev-1))+i];
6143 
6144  (*omega2)[i] = (*Xtau)[(nlev-1)*nV+i];
6145  }
6146 
6147  if(nlev == 1) Xcall = 1;
6148  else Xcall = 0;
6149 
6150  ring oRing = currRing;
6151 
6152  while(1)
6153  {
6154 #ifdef FIRST_STEP_FRACTAL
6155  // perturb the current weight vector only on the top level or
6156  // after perturbation of the both vectors, nlev = 2 as the top level
6157  if((nlev == 1 && Xcall == 0) || (nlev == 2 && Xngleich == 1))
6158  if(islengthpoly2(G) == 1)
6159  {
6160  Mwlp = MivWeightOrderlp(omega);
6161  Xsigma = Mfpertvector(G, Mwlp);
6162  delete Mwlp;
6164  }
6165 #endif
6166  nwalks ++;
6167  NEXT_VECTOR_FRACTAL:
6168  to=clock();
6169  /* determine the next border */
6170  next_vect = MkInterRedNextWeight(omega,omega2,G);
6171  xtnw=xtnw+clock()-to;
6172 #ifdef PRINT_VECTORS
6173  MivString(omega, omega2, next_vect);
6174 #endif
6175  oRing = currRing;
6176 
6177  /* We only perturb the current target vector at the recursion level 1 */
6178  if(Xngleich == 0 && nlev == 1) //(ngleich == 0) important, e.g. ex2, ex3
6179  if (MivComp(next_vect, omega2) == 1)
6180  {
6181  /* to dispense with taking initial (and lifting/interreducing
6182  after the call of recursion */
6183  //Print("\n\n// ** Perturb the both vectors with degree %d with",nlev);
6184  //idElements(G, "G");
6185 
6186  Xngleich = 1;
6187  nlev +=1;
6188 
6189  if (rParameter(currRing) != NULL)
6190  DefRingPar(omtmp);
6191  else
6192  rChangeCurrRing(VMrDefault1(omtmp)); //Aenderung3
6193 
6194  testring = currRing;
6195  Gt = idrMoveR(G, oRing,currRing);
6196 
6197  /* perturb the original target vector w.r.t. the current GB */
6198  delete Xtau;
6199  Xtau = NewVectorlp(Gt);
6200 
6201  rChangeCurrRing(oRing);
6202  G = idrMoveR(Gt, testring,currRing);
6203 
6204  /* perturb the current vector w.r.t. the current GB */
6205  Mwlp = MivWeightOrderlp(omega);
6206  Xsigma = Mfpertvector(G, Mwlp);
6207  delete Mwlp;
6208 
6209  for(i=nV-1; i>=0; i--) {
6210  (*omega2)[i] = (*Xtau)[nV+i];
6211  (*omega)[i] = (*Xsigma)[nV+i];
6212  }
6213 
6214  delete next_vect;
6215  to=clock();
6216 
6217  /* to avoid the value of Overflow_Error that occur in Mfpertvector*/
6219 
6220  next_vect = MkInterRedNextWeight(omega,omega2,G);
6221  xtnw=xtnw+clock()-to;
6222 
6223 #ifdef PRINT_VECTORS
6224  MivString(omega, omega2, next_vect);
6225 #endif
6226  }
6227 
6228 
6229  /* check whether the the computed vector is in the correct cone */
6230  /* If no, the reduced GB of an omega-homogeneous ideal will be
6231  computed by Buchberger algorithm and stop this recursion step*/
6232  //if(test_w_in_ConeCC(G, next_vect) != 1) //e.g. Example s7, cyc6
6233  if(Overflow_Error == TRUE)
6234  {
6235  delete next_vect;
6236  if (rParameter(currRing) != NULL)
6237  {
6238  DefRingPar(omtmp);
6239  }
6240  else
6241  {
6242  rChangeCurrRing(VMrDefault1(omtmp)); // Aenderung4
6243  }
6244 #ifdef TEST_OVERFLOW
6245  Gt = idrMoveR(G, oRing,currRing);
6246  Gt = NULL; return(Gt);
6247 #endif
6248 
6249  //Print("\n\n// apply BB's alg. in ring r = %s;", rString(currRing));
6250  to=clock();
6251  Gt = idrMoveR(G, oRing,currRing);
6252  G1 = MstdCC(Gt);
6253  xtextra=xtextra+clock()-to;
6254  Gt = NULL;
6255 
6256  delete omega2;
6257  delete altomega;
6258 
6259  //Print("\n// Leaving the %d-th recursion with %d steps", nlev, nwalks);
6260  //Print(" ** Overflow_Error? (%d)", Overflow_Error);
6261  nnflow ++;
6262 
6264  return (G1);
6265  }
6266 
6267 
6268  /* If the perturbed target vector stays in the correct cone,
6269  return the current GB,
6270  otherwise, return the computed GB by the Buchberger-algorithm.
6271  Then we update the perturbed target vectors w.r.t. this GB. */
6272 
6273  /* the computed vector is equal to the origin vector, since
6274  t is not defined */
6275  if (MivComp(next_vect, XivNull) == 1)
6276  {
6277  if (rParameter(currRing) != NULL)
6278  DefRingPar(omtmp);
6279  else
6280  rChangeCurrRing(VMrDefault1(omtmp)); //Aenderung5
6281 
6282  testring = currRing;
6283  Gt = idrMoveR(G, oRing,currRing);
6284 
6285  if(test_w_in_ConeCC(Gt, omega2) == 1) {
6286  delete omega2;
6287  delete next_vect;
6288  delete altomega;
6289  //Print("\n// Leaving the %d-th recursion with %d steps ",nlev, nwalks);
6290  //Print(" ** Overflow_Error? (%d)", Overflow_Error);
6291 
6292  return (Gt);
6293  }
6294  else
6295  {
6296  //ivString(omega2, "tau'");
6297  //Print("\n// tau' doesn't stay in the correct cone!!");
6298 
6299 #ifndef MSTDCC_FRACTAL
6300  //07.08.03
6301  //ivString(Xtau, "old Xtau");
6302  intvec* Xtautmp = Mfpertvector(Gt, MivMatrixOrder(omtmp));
6303 #ifdef TEST_OVERFLOW
6304  if(Overflow_Error == TRUE)
6305  Gt = NULL; return(Gt);
6306 #endif
6307 
6308  if(MivSame(Xtau, Xtautmp) == 1)
6309  {
6310  //PrintS("\n// Update vectors are equal to the old vectors!!");
6311  delete Xtautmp;
6312  goto FRACTAL_MSTDCC;
6313  }
6314 
6315  Xtau = Xtautmp;
6316  Xtautmp = NULL;
6317  //ivString(Xtau, "new Xtau");
6318 
6319  for(i=nV-1; i>=0; i--)
6320  (*omega2)[i] = (*Xtau)[(nlev-1)*nV+i];
6321 
6322  //Print("\n// ring tau = %s;", rString(currRing));
6323  rChangeCurrRing(oRing);
6324  G = idrMoveR(Gt, testring,currRing);
6325 
6326  goto NEXT_VECTOR_FRACTAL;
6327 #endif
6328 
6329  FRACTAL_MSTDCC:
6330  //Print("\n// apply BB-Alg in ring = %s;", rString(currRing));
6331  to=clock();
6332  G = MstdCC(Gt);
6333  xtextra=xtextra+clock()-to;
6334 
6335  oRing = currRing;
6336 
6337  // update the original target vector w.r.t. the current GB
6338  if(MivSame(Xivinput, Xivlp) == 1)
6339  if (rParameter(currRing) != NULL)
6340  DefRingParlp();
6341  else
6342  VMrDefaultlp();
6343  else
6344  if (rParameter(currRing) != NULL)
6345  DefRingPar(Xivinput);
6346  else
6347  rChangeCurrRing(VMrDefault1(Xivinput)); //Aenderung6
6348 
6349  testring = currRing;
6350  Gt = idrMoveR(G, oRing,currRing);
6351 
6352  delete Xtau;
6353  Xtau = NewVectorlp(Gt);
6354 
6355  rChangeCurrRing(oRing);
6356  G = idrMoveR(Gt, testring,currRing);
6357 
6358  delete omega2;
6359  delete next_vect;
6360  delete altomega;
6361  /*
6362  Print("\n// Leaving the %d-th recursion with %d steps,", nlev,nwalks);
6363  Print(" ** Overflow_Error? (%d)", Overflow_Error);
6364  */
6365  if(Overflow_Error == TRUE)
6366  nnflow ++;
6367 
6369  return(G);
6370  }
6371  }
6372 
6373  for(i=nV-1; i>=0; i--) {
6374  (*altomega)[i] = (*omega)[i];
6375  (*omega)[i] = (*next_vect)[i];
6376  }
6377  delete next_vect;
6378 
6379  to=clock();
6380  /* Take the initial form of <G> w.r.t. omega */
6381  Gomega = MwalkInitialForm(G, omega);
6382  xtif=xtif+clock()-to;
6383 
6384 #ifndef BUCHBERGER_ALG
6385  if(isNolVector(omega) == 0)
6386  hilb_func = hFirstSeries(Gomega,NULL,NULL,omega,currRing);
6387  else
6388  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
6389 #endif // BUCHBERGER_ALG
6390 
6391  if (rParameter(currRing) != NULL)
6392  DefRingPar(omega);
6393  else
6394  rChangeCurrRing(VMrDefault1(omega)); //Aenderung7
6395 
6396  Gomega1 = idrMoveR(Gomega, oRing,currRing);
6397 
6398  /* Maximal recursion depth, to compute a red. GB */
6399  /* Fractal walk with the alternative recursion */
6400  /* alternative recursion */
6401  // if(nlev == nV || lengthpoly(Gomega1) == 0)
6402  if(nlev == Xnlev || lengthpoly(Gomega1) == 0)
6403  //if(nlev == nV) // blind recursion
6404  {
6405  /*
6406  if(Xnlev != nV)
6407  {
6408  Print("\n// ** Xnlev = %d", Xnlev);
6409  ivString(Xtau, "Xtau");
6410  }
6411  */
6412  to=clock();
6413 #ifdef BUCHBERGER_ALG
6414  Gresult = MstdhomCC(Gomega1);
6415 #else
6416  Gresult =kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,omega);
6417  delete hilb_func;
6418 #endif // BUCHBERGER_ALG
6419  xtstd=xtstd+clock()-to;
6420  }
6421  else {
6422  rChangeCurrRing(oRing);
6423  Gomega1 = idrMoveR(Gomega1, oRing,currRing);
6424  Gresult = rec_fractal_call(idCopy(Gomega1),nlev+1,omega);
6425  }
6426 
6427  //convert a Groebner basis from a ring to another ring,
6428  new_ring = currRing;
6429 
6430  rChangeCurrRing(oRing);
6431  Gresult1 = idrMoveR(Gresult, new_ring,currRing);
6432  Gomega2 = idrMoveR(Gomega1, new_ring,currRing);
6433 
6434  to=clock();
6435  /* Lifting process */
6436  F = MLifttwoIdeal(Gomega2, Gresult1, G);
6437  xtlift=xtlift+clock()-to;
6438  idDelete(&Gresult1);
6439  idDelete(&Gomega2);
6440  idDelete(&G);
6441 
6442  rChangeCurrRing(new_ring);
6443  F1 = idrMoveR(F, oRing,currRing);
6444 
6445  to=clock();
6446  /* Interreduce G */
6447  G = kInterRedCC(F1, NULL);
6448  xtred=xtred+clock()-to;
6449  idDelete(&F1);
6450  }
6451 }
6452 
6453 /************************************************************************
6454  * Perturb the start weight vector at the top level with random element *
6455  ************************************************************************/
6456 static ideal rec_r_fractal_call(ideal G, int nlev, intvec* omtmp, int weight_rad)
6457 {
6459  //Print("\n\n// Entering the %d-th recursion:", nlev);
6460 
6461  int i, nV = currRing->N;
6462  ring new_ring, testring;
6463  //ring extoRing;
6464  ideal Gomega, Gomega1, Gomega2, F, F1, Gresult, Gresult1, G1, Gt;
6465  int nwalks = 0;
6466  intvec* Mwlp;
6467 #ifndef BUCHBERGER_ALG
6468  intvec* hilb_func;
6469 #endif
6470 // intvec* extXtau;
6471  intvec* next_vect;
6472  intvec* omega2 = new intvec(nV);
6473  intvec* altomega = new intvec(nV);
6474 
6475  //BOOLEAN isnewtarget = FALSE;
6476 
6477  // to avoid (1,0,...,0) as the target vector (Hans)
6478  intvec* last_omega = new intvec(nV);
6479  for(i=nV-1; i>0; i--)
6480  (*last_omega)[i] = 1;
6481  (*last_omega)[0] = 10000;
6482 
6483  intvec* omega = new intvec(nV);
6484  for(i=0; i<nV; i++) {
6485  if(Xsigma->length() == nV)
6486  (*omega)[i] = (*Xsigma)[i];
6487  else
6488  (*omega)[i] = (*Xsigma)[(nV*(nlev-1))+i];
6489 
6490  (*omega2)[i] = (*Xtau)[(nlev-1)*nV+i];
6491  }
6492 
6493  if(nlev == 1) Xcall = 1;
6494  else Xcall = 0;
6495 
6496  ring oRing = currRing;
6497 
6498  while(1)
6499  {
6500 #ifdef FIRST_STEP_FRACTAL
6501  // perturb the current weight vector only on the top level or
6502  // after perturbation of the both vectors, nlev = 2 as the top level
6503  if((nlev == 1 && Xcall == 0) || (nlev == 2 && Xngleich == 1))
6504  if(islengthpoly2(G) == 1)
6505  {
6506  Mwlp = MivWeightOrderlp(omega);
6507  Xsigma = Mfpertvector(G, Mwlp);
6508  delete Mwlp;
6510  }
6511 #endif
6512  nwalks ++;
6513  NEXT_VECTOR_FRACTAL:
6514  to=clock();
6515  /* determine the next border */
6516  next_vect = MWalkRandomNextWeight(G, omega,omega2, weight_rad, 1+nlev);
6517  //next_vect = MkInterRedNextWeight(omega,omega2,G);
6518  xtnw=xtnw+clock()-to;
6519 #ifdef PRINT_VECTORS
6520  MivString(omega, omega2, next_vect);
6521 #endif
6522  oRing = currRing;
6523 
6524  /* We only perturb the current target vector at the recursion level 1 */
6525  if(Xngleich == 0 && nlev == 1) //(ngleich == 0) important, e.g. ex2, ex3
6526  if (MivComp(next_vect, omega2) == 1)
6527  {
6528  /* to dispense with taking initial (and lifting/interreducing
6529  after the call of recursion */
6530  //Print("\n\n// ** Perturb the both vectors with degree %d with",nlev);
6531  //idElements(G, "G");
6532 
6533  Xngleich = 1;
6534  nlev +=1;
6535 
6536  if (rParameter(currRing) != NULL)
6537  DefRingPar(omtmp);
6538  else
6539  rChangeCurrRing(VMrDefault1(omtmp)); //Aenderung3
6540 
6541  testring = currRing;
6542  Gt = idrMoveR(G, oRing,currRing);
6543 
6544  /* perturb the original target vector w.r.t. the current GB */
6545  delete Xtau;
6546  Xtau = NewVectorlp(Gt);
6547 
6548  rChangeCurrRing(oRing);
6549  G = idrMoveR(Gt, testring,currRing);
6550 
6551  /* perturb the current vector w.r.t. the current GB */
6552  Mwlp = MivWeightOrderlp(omega);
6553  Xsigma = Mfpertvector(G, Mwlp);
6554  delete Mwlp;
6555 
6556  for(i=nV-1; i>=0; i--) {
6557  (*omega2)[i] = (*Xtau)[nV+i];
6558  (*omega)[i] = (*Xsigma)[nV+i];
6559  }
6560 
6561  delete next_vect;
6562  to=clock();
6563 
6564  /* to avoid the value of Overflow_Error that occur in Mfpertvector*/
6566 
6567  next_vect = MkInterRedNextWeight(omega,omega2,G);
6568  xtnw=xtnw+clock()-to;
6569 
6570 #ifdef PRINT_VECTORS
6571  MivString(omega, omega2, next_vect);
6572 #endif
6573  }
6574 
6575 
6576  /* check whether the the computed vector is in the correct cone */
6577  /* If no, the reduced GB of an omega-homogeneous ideal will be
6578  computed by Buchberger algorithm and stop this recursion step*/
6579  //if(test_w_in_ConeCC(G, next_vect) != 1) //e.g. Example s7, cyc6
6580  if(Overflow_Error == TRUE)
6581  {
6582  delete next_vect;
6583  if (rParameter(currRing) != NULL)
6584  {
6585  DefRingPar(omtmp);
6586  }
6587  else
6588  {
6589  rChangeCurrRing(VMrDefault1(omtmp)); // Aenderung4
6590  }
6591 #ifdef TEST_OVERFLOW
6592  Gt = idrMoveR(G, oRing,currRing);
6593  Gt = NULL; return(Gt);
6594 #endif
6595 
6596  //Print("\n\n// apply BB's alg. in ring r = %s;", rString(currRing));
6597  to=clock();
6598  Gt = idrMoveR(G, oRing,currRing);
6599  G1 = MstdCC(Gt);
6600  xtextra=xtextra+clock()-to;
6601  Gt = NULL;
6602 
6603  delete omega2;
6604  delete altomega;
6605 
6606  //Print("\n// Leaving the %d-th recursion with %d steps", nlev, nwalks);
6607  //Print(" ** Overflow_Error? (%d)", Overflow_Error);
6608  nnflow ++;
6609 
6611  return (G1);
6612  }
6613 
6614 
6615  /* If the perturbed target vector stays in the correct cone,
6616  return the current GB,
6617  otherwise, return the computed GB by the Buchberger-algorithm.
6618  Then we update the perturbed target vectors w.r.t. this GB. */
6619 
6620  /* the computed vector is equal to the origin vector, since
6621  t is not defined */
6622  if (MivComp(next_vect, XivNull) == 1)
6623  {
6624  if (rParameter(currRing) != NULL)
6625  DefRingPar(omtmp);
6626  else
6627  rChangeCurrRing(VMrDefault1(omtmp)); //Aenderung5
6628 
6629  testring = currRing;
6630  Gt = idrMoveR(G, oRing,currRing);
6631 
6632  if(test_w_in_ConeCC(Gt, omega2) == 1) {
6633  delete omega2;
6634  delete next_vect;
6635  delete altomega;
6636  //Print("\n// Leaving the %d-th recursion with %d steps ",nlev, nwalks);
6637  //Print(" ** Overflow_Error? (%d)", Overflow_Error);
6638 
6639  return (Gt);
6640  }
6641  else
6642  {
6643  //ivString(omega2, "tau'");
6644  //Print("\n// tau' doesn't stay in the correct cone!!");
6645 
6646 #ifndef MSTDCC_FRACTAL
6647  //07.08.03
6648  //ivString(Xtau, "old Xtau");
6649  intvec* Xtautmp = Mfpertvector(Gt, MivMatrixOrder(omtmp));
6650 #ifdef TEST_OVERFLOW
6651  if(Overflow_Error == TRUE)
6652  Gt = NULL; return(Gt);
6653 #endif
6654 
6655  if(MivSame(Xtau, Xtautmp) == 1)
6656  {
6657  //PrintS("\n// Update vectors are equal to the old vectors!!");
6658  delete Xtautmp;
6659  goto FRACTAL_MSTDCC;
6660  }
6661 
6662  Xtau = Xtautmp;
6663  Xtautmp = NULL;
6664  //ivString(Xtau, "new Xtau");
6665 
6666  for(i=nV-1; i>=0; i--)
6667  (*omega2)[i] = (*Xtau)[(nlev-1)*nV+i];
6668 
6669  //Print("\n// ring tau = %s;", rString(currRing));
6670  rChangeCurrRing(oRing);
6671  G = idrMoveR(Gt, testring,currRing);
6672 
6673  goto NEXT_VECTOR_FRACTAL;
6674 #endif
6675 
6676  FRACTAL_MSTDCC:
6677  //Print("\n// apply BB-Alg in ring = %s;", rString(currRing));
6678  to=clock();
6679  G = MstdCC(Gt);
6680  xtextra=xtextra+clock()-to;
6681 
6682  oRing = currRing;
6683 
6684  // update the original target vector w.r.t. the current GB
6685  if(MivSame(Xivinput, Xivlp) == 1)
6686  if (rParameter(currRing) != NULL)
6687  DefRingParlp();
6688  else
6689  VMrDefaultlp();
6690  else
6691  if (rParameter(currRing) != NULL)
6692  DefRingPar(Xivinput);
6693  else
6694  rChangeCurrRing(VMrDefault1(Xivinput)); //Aenderung6
6695 
6696  testring = currRing;
6697  Gt = idrMoveR(G, oRing,currRing);
6698 
6699  delete Xtau;
6700  Xtau = NewVectorlp(Gt);
6701 
6702  rChangeCurrRing(oRing);
6703  G = idrMoveR(Gt, testring,currRing);
6704 
6705  delete omega2;
6706  delete next_vect;
6707  delete altomega;
6708  /*
6709  Print("\n// Leaving the %d-th recursion with %d steps,", nlev,nwalks);
6710  Print(" ** Overflow_Error? (%d)", Overflow_Error);
6711  */
6712  if(Overflow_Error == TRUE)
6713  nnflow ++;
6714 
6716  return(G);
6717  }
6718  }
6719 
6720  for(i=nV-1; i>=0; i--) {
6721  (*altomega)[i] = (*omega)[i];
6722  (*omega)[i] = (*next_vect)[i];
6723  }
6724  delete next_vect;
6725 
6726  to=clock();
6727  /* Take the initial form of <G> w.r.t. omega */
6728  Gomega = MwalkInitialForm(G, omega);
6729  xtif=xtif+clock()-to;
6730 
6731 #ifndef BUCHBERGER_ALG
6732  if(isNolVector(omega) == 0)
6733  hilb_func = hFirstSeries(Gomega,NULL,NULL,omega,currRing);
6734  else
6735  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
6736 #endif // BUCHBERGER_ALG
6737 
6738  if (rParameter(currRing) != NULL)
6739  DefRingPar(omega);
6740  else
6741  rChangeCurrRing(VMrDefault1(omega)); //Aenderung7
6742 
6743  Gomega1 = idrMoveR(Gomega, oRing,currRing);
6744 
6745  /* Maximal recursion depth, to compute a red. GB */
6746  /* Fractal walk with the alternative recursion */
6747  /* alternative recursion */
6748  // if(nlev == nV || lengthpoly(Gomega1) == 0)
6749  if(nlev == Xnlev || lengthpoly(Gomega1) == 0)
6750  //if(nlev == nV) // blind recursion
6751  {
6752  /*
6753  if(Xnlev != nV)
6754  {
6755  Print("\n// ** Xnlev = %d", Xnlev);
6756  ivString(Xtau, "Xtau");
6757  }
6758  */
6759  to=clock();
6760 #ifdef BUCHBERGER_ALG
6761  Gresult = MstdhomCC(Gomega1);
6762 #else
6763  Gresult =kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,omega);
6764  delete hilb_func;
6765 #endif // BUCHBERGER_ALG
6766  xtstd=xtstd+clock()-to;
6767  }
6768  else {
6769  rChangeCurrRing(oRing);
6770  Gomega1 = idrMoveR(Gomega1, oRing,currRing);
6771  Gresult = rec_fractal_call(idCopy(Gomega1),nlev+1,omega);
6772  }
6773 
6774  //convert a Groebner basis from a ring to another ring,
6775  new_ring = currRing;
6776 
6777  rChangeCurrRing(oRing);
6778  Gresult1 = idrMoveR(Gresult, new_ring,currRing);
6779  Gomega2 = idrMoveR(Gomega1, new_ring,currRing);
6780 
6781  to=clock();
6782  /* Lifting process */
6783  F = MLifttwoIdeal(Gomega2, Gresult1, G);
6784  xtlift=xtlift+clock()-to;
6785  idDelete(&Gresult1);
6786  idDelete(&Gomega2);
6787  idDelete(&G);
6788 
6789  rChangeCurrRing(new_ring);
6790  F1 = idrMoveR(F, oRing,currRing);
6791 
6792  to=clock();
6793  /* Interreduce G */
6794  G = kInterRedCC(F1, NULL);
6795  xtred=xtred+clock()-to;
6796  idDelete(&F1);
6797  }
6798 }
6799 
6800 
6801 
6802 
6803 /*******************************************************************************
6804  * The implementation of the fractal walk algorithm *
6805  * *
6806  * The main procedur Mfwalk calls the recursive Subroutine *
6807  * rec_fractal_call to compute the wanted Gr�bner basis. *
6808  * At the main procedur we compute the reduced Gr�bner basis w.r.t. a "fast" *
6809  * order, e.g. "dp" and a sequence of weight vectors which are row vectors *
6810  * of a matrix. This matrix defines the given monomial order, e.g. "lp" *
6811  *******************************************************************************/
6812 ideal Mfwalk(ideal G, intvec* ivstart, intvec* ivtarget)
6813 {
6814  Set_Error(FALSE);
6816  //Print("// pSetm_Error = (%d)", ErrorCheck());
6817  //Print("\n// ring ro = %s;", rString(currRing));
6818 
6819  nnflow = 0;
6820  Xngleich = 0;
6821  Xcall = 0;
6822  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0; xtextra=0;
6823  xftinput = clock();
6824 
6825  ring oldRing = currRing;
6826  int i, nV = currRing->N;
6827  XivNull = new intvec(nV);
6828  Xivinput = ivtarget;
6829  ngleich = 0;
6830  to=clock();
6831  ideal I = MstdCC(G);
6832  G = NULL;
6833  xftostd=clock()-to;
6834  Xsigma = ivstart;
6835 
6836  Xnlev=nV;
6837 
6838 #ifdef FIRST_STEP_FRACTAL
6839  ideal Gw = MwalkInitialForm(I, ivstart);
6840  for(i=IDELEMS(Gw)-1; i>=0; i--)
6841  {
6842  if((Gw->m[i]!=NULL) // len >=0
6843  && (Gw->m[i]->next!=NULL) // len >=1
6844  && (Gw->m[i]->next->next!=NULL)) // len >=2
6845  {
6846  intvec* iv_dp = MivUnit(nV); // define (1,1,...,1)
6847  intvec* Mdp;
6848 
6849  if(MivSame(ivstart, iv_dp) != 1)
6850  Mdp = MivWeightOrderdp(ivstart);
6851  else
6852  Mdp = MivMatrixOrderdp(nV);
6853 
6854  Xsigma = Mfpertvector(I, Mdp);
6856 
6857  delete Mdp;
6858  delete iv_dp;
6859  break;
6860  }
6861  }
6862  idDelete(&Gw);
6863 #endif
6864 
6865  ideal I1;
6866  intvec* Mlp;
6867  Xivlp = Mivlp(nV);
6868 
6869  if(MivComp(ivtarget, Xivlp) != 1)
6870  {
6871  if (rParameter(currRing) != NULL)
6872  DefRingPar(ivtarget);
6873  else
6874  rChangeCurrRing(VMrDefault1(ivtarget)); //Aenderung1
6875 
6876  I1 = idrMoveR(I, oldRing,currRing);
6877  Mlp = MivWeightOrderlp(ivtarget);
6878  Xtau = Mfpertvector(I1, Mlp);
6879  }
6880  else
6881  {
6882  if (rParameter(currRing) != NULL)
6883  DefRingParlp();
6884  else
6885  VMrDefaultlp();
6886 
6887  I1 = idrMoveR(I, oldRing,currRing);
6888  Mlp = MivMatrixOrderlp(nV);
6889  Xtau = Mfpertvector(I1, Mlp);
6890  }
6891  delete Mlp;
6893 
6894  //ivString(Xsigma, "Xsigma");
6895  //ivString(Xtau, "Xtau");
6896 
6897  id_Delete(&I, oldRing);
6898  ring tRing = currRing;
6899 
6900  if (rParameter(currRing) != NULL)
6901  DefRingPar(ivstart);
6902  else
6903  rChangeCurrRing(VMrDefault1(ivstart)); //Aenderung2
6904 
6905  I = idrMoveR(I1,tRing,currRing);
6906  to=clock();
6907  ideal J = MstdCC(I);
6908  idDelete(&I);
6909  xftostd=xftostd+clock()-to;
6910 
6911  ideal resF;
6912  ring helpRing = currRing;
6913 
6914  J = rec_fractal_call(J, 1, ivtarget);
6915 
6916  rChangeCurrRing(oldRing);
6917  resF = idrMoveR(J, helpRing,currRing);
6918  idSkipZeroes(resF);
6919 
6920  delete Xivlp;
6921  delete Xsigma;
6922  delete Xtau;
6923  delete XivNull;
6924 
6925 #ifdef TIME_TEST
6926  TimeStringFractal(xftinput, xftostd, xtif, xtstd, xtextra,
6927  xtlift, xtred, xtnw);
6928 
6929 
6930  Print("\n// pSetm_Error = (%d)", ErrorCheck());
6931  Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
6932  Print("\n// the numbers of Overflow_Error (%d)", nnflow);
6933 #endif
6934 
6935  return(resF);
6936 }
6937 
6938 ideal Mfrwalk(ideal G, intvec* ivstart, intvec* ivtarget,int weight_rad)
6939 {
6940  Set_Error(FALSE);
6942  //Print("// pSetm_Error = (%d)", ErrorCheck());
6943  //Print("\n// ring ro = %s;", rString(currRing));
6944 
6945  nnflow = 0;
6946  Xngleich = 0;
6947  Xcall = 0;
6948  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0; xtextra=0;
6949  xftinput = clock();
6950 
6951  ring oldRing = currRing;
6952  int i, nV = currRing->N;
6953  XivNull = new intvec(nV);
6954  Xivinput = ivtarget;
6955  ngleich = 0;
6956  to=clock();
6957  ideal I = MstdCC(G);
6958  G = NULL;
6959  xftostd=clock()-to;
6960  Xsigma = ivstart;
6961 
6962  Xnlev=nV;
6963 
6964 #ifdef FIRST_STEP_FRACTAL
6965  ideal Gw = MwalkInitialForm(I, ivstart);
6966  for(i=IDELEMS(Gw)-1; i>=0; i--)
6967  {
6968  if((Gw->m[i]!=NULL) // len >=0
6969  && (Gw->m[i]->next!=NULL) // len >=1
6970  && (Gw->m[i]->next->next!=NULL)) // len >=2
6971  {
6972  intvec* iv_dp = MivUnit(nV); // define (1,1,...,1)
6973  intvec* Mdp;
6974 
6975  if(MivSame(ivstart, iv_dp) != 1)
6976  Mdp = MivWeightOrderdp(ivstart);
6977  else
6978  Mdp = MivMatrixOrderdp(nV);
6979 
6980  Xsigma = Mfpertvector(I, Mdp);
6982 
6983  delete Mdp;
6984  delete iv_dp;
6985  break;
6986  }
6987  }
6988  idDelete(&Gw);
6989 #endif
6990 
6991  ideal I1;
6992  intvec* Mlp;
6993  Xivlp = Mivlp(nV);
6994 
6995  if(MivComp(ivtarget, Xivlp) != 1)
6996  {
6997  if (rParameter(currRing) != NULL)
6998  DefRingPar(ivtarget);
6999  else
7000  rChangeCurrRing(VMrDefault1(ivtarget)); //Aenderung1
7001 
7002  I1 = idrMoveR(I, oldRing,currRing);
7003  Mlp = MivWeightOrderlp(ivtarget);
7004  Xtau = Mfpertvector(I1, Mlp);
7005  }
7006  else
7007  {
7008  if (rParameter(currRing) != NULL)
7009  DefRingParlp();
7010  else
7011  VMrDefaultlp();
7012 
7013  I1 = idrMoveR(I, oldRing,currRing);
7014  Mlp = MivMatrixOrderlp(nV);
7015  Xtau = Mfpertvector(I1, Mlp);
7016  }
7017  delete Mlp;
7019 
7020  //ivString(Xsigma, "Xsigma");
7021  //ivString(Xtau, "Xtau");
7022 
7023  id_Delete(&I, oldRing);
7024  ring tRing = currRing;
7025 
7026  if (rParameter(currRing) != NULL)
7027  DefRingPar(ivstart);
7028  else
7029  rChangeCurrRing(VMrDefault1(ivstart)); //Aenderung2
7030 
7031  I = idrMoveR(I1,tRing,currRing);
7032  to=clock();
7033  ideal J = MstdCC(I);
7034  idDelete(&I);
7035  xftostd=xftostd+clock()-to;
7036 
7037  ideal resF;
7038  ring helpRing = currRing;
7039 //ideal G, int nlev, intvec* omtmp, int weight_rad)
7040  J = rec_r_fractal_call(J, 1, ivtarget,weight_rad);
7041 
7042  rChangeCurrRing(oldRing);
7043  resF = idrMoveR(J, helpRing,currRing);
7044  idSkipZeroes(resF);
7045 
7046  delete Xivlp;
7047  delete Xsigma;
7048  delete Xtau;
7049  delete XivNull;
7050 
7051 #ifdef TIME_TEST
7052  TimeStringFractal(xftinput, xftostd, xtif, xtstd, xtextra,
7053  xtlift, xtred, xtnw);
7054 
7055 
7056  Print("\n// pSetm_Error = (%d)", ErrorCheck());
7057  Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
7058  Print("\n// the numbers of Overflow_Error (%d)", nnflow);
7059 #endif
7060 
7061  return(resF);
7062 }
7063 
7064 /*******************************************************
7065  * Tran's algorithm *
7066  * *
7067  * use kStd, if nP = 0, else call Ab_Rec_Pert (LastGB) *
7068  *******************************************************/
7069 ideal TranMImprovwalk(ideal G,intvec* curr_weight,intvec* target_tmp, int nP)
7070 {
7071 #ifdef TIME_TEST
7072  clock_t mtim = clock();
7073 #endif
7074  Set_Error(FALSE );
7076  //Print("// pSetm_Error = (%d)", ErrorCheck());
7077  //Print("\n// ring ro = %s;", rString(currRing));
7078 
7079  clock_t tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0, textra=0;
7080 #ifdef TIME_TEST
7081  clock_t tinput = clock();
7082 #endif
7083  int nsteppert=0, i, nV = currRing->N, nwalk=0, npert_tmp=0;
7084  int *npert=(int*)omAlloc(2*nV*sizeof(int));
7085  ideal Gomega, M,F, G1, Gomega1, Gomega2, M1, F1;
7086  //ring endRing;
7087  ring newRing, oldRing, lpRing;
7088  intvec* next_weight;
7089  intvec* ivNull = new intvec(nV); //define (0,...,0)
7090  intvec* iv_dp = MivUnit(nV);// define (1,1,...,1)
7091  intvec* iv_lp = Mivlp(nV); //define (1,0,...,0)
7092  ideal H0;
7093  //ideal H1;
7094  ideal H2, Glp;
7095  int nGB, endwalks = 0, nwalkpert=0, npertstep=0;
7096  intvec* Mlp = MivMatrixOrderlp(nV);
7097  intvec* vector_tmp = new intvec(nV);
7098 #ifndef BUCHBERGER_ALG
7099  intvec* hilb_func;
7100 #endif
7101  /* to avoid (1,0,...,0) as the target vector */
7102  intvec* last_omega = new intvec(nV);
7103  for(i=nV-1; i>0; i--)
7104  (*last_omega)[i] = 1;
7105  (*last_omega)[0] = 10000;
7106 
7107  // intvec* extra_curr_weight = new intvec(nV);
7108  intvec* target_weight = new intvec(nV);
7109  for(i=nV-1; i>=0; i--)
7110  (*target_weight)[i] = (*target_tmp)[i];
7111 
7112  ring XXRing = currRing;
7113  newRing = currRing;
7114 
7115  to=clock();
7116  /* compute a red. GB w.r.t. the help ring */
7117  if(MivComp(curr_weight, iv_dp) == 1) //rOrdStr(currRing) = "dp"
7118  G = MstdCC(G);
7119  else
7120  {
7121  //rOrdStr(currRing) = (a(.c_w..),lp,C)
7122  if (rParameter(currRing) != NULL)
7123  DefRingPar(curr_weight);
7124  else
7125  rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung 4
7126  G = idrMoveR(G, XXRing,currRing);
7127  G = MstdCC(G);
7128  }
7129  tostd=clock()-to;
7130 
7131 #ifdef REPRESENTATION_OF_SIGMA
7132  ideal Gw = MwalkInitialForm(G, curr_weight);
7133 
7134  if(islengthpoly2(Gw)==1)
7135  {
7136  intvec* MDp;
7137  if(MivComp(curr_weight, iv_dp) == 1)
7138  MDp = MatrixOrderdp(nV); //MivWeightOrderlp(iv_dp);
7139  else
7140  MDp = MivWeightOrderlp(curr_weight);
7141 
7142  curr_weight = RepresentationMatrix_Dp(G, MDp);
7143 
7144  delete MDp;
7145 
7146  ring exring = currRing;
7147 
7148  if (rParameter(currRing) != NULL)
7149  DefRingPar(curr_weight);
7150  else
7151  rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 5
7152  to=clock();
7153  Gw = idrMoveR(G, exring,currRing);
7154  G = MstdCC(Gw);
7155  Gw = NULL;
7156  tostd=tostd+clock()-to;
7157  //ivString(curr_weight,"rep. sigma");
7158  goto COMPUTE_NEW_VECTOR;
7159  }
7160 
7161  idDelete(&Gw);
7162  delete iv_dp;
7163 #endif
7164 
7165 
7166  while(1)
7167  {
7168  to=clock();
7169  /* compute an initial form ideal of <G> w.r.t. "curr_vector" */
7170  Gomega = MwalkInitialForm(G, curr_weight);
7171  tif=tif+clock()-to;
7172 
7173 #ifndef BUCHBERGER_ALG
7174  if(isNolVector(curr_weight) == 0)
7175  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
7176  else
7177  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
7178 #endif // BUCHBERGER_ALG
7179 
7180  oldRing = currRing;
7181 
7182  /* define a new ring that its ordering is "(a(curr_weight),lp) */
7183  if (rParameter(currRing) != NULL)
7184  DefRingPar(curr_weight);
7185  else
7186  rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 6
7187 
7188  newRing = currRing;
7189  Gomega1 = idrMoveR(Gomega, oldRing,currRing);
7190 
7191  to=clock();
7192  /* compute a reduced Groebner basis of <Gomega> w.r.t. "newRing" */
7193 #ifdef BUCHBERGER_ALG
7194  M = MstdhomCC(Gomega1);
7195 #else
7196  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
7197  delete hilb_func;
7198 #endif // BUCHBERGER_ALG
7199  tstd=tstd+clock()-to;
7200 
7201  /* change the ring to oldRing */
7202  rChangeCurrRing(oldRing);
7203  M1 = idrMoveR(M, newRing,currRing);
7204  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
7205 
7206  to=clock();
7207  /* compute a representation of the generators of submod (M)
7208  with respect to those of mod (Gomega).
7209  Gomega is a reduced Groebner basis w.r.t. the current ring */
7210  F = MLifttwoIdeal(Gomega2, M1, G);
7211  tlift=tlift+clock()-to;
7212 
7213  idDelete(&M1);
7214  idDelete(&Gomega2);
7215  idDelete(&G);
7216 
7217  /* change the ring to newRing */
7218  rChangeCurrRing(newRing);
7219  F1 = idrMoveR(F, oldRing,currRing);
7220 
7221  to=clock();
7222  /* reduce the Groebner basis <G> w.r.t. new ring */
7223  G = kInterRedCC(F1, NULL);
7224  tred=tred+clock()-to;
7225  idDelete(&F1);
7226 
7227 
7228  COMPUTE_NEW_VECTOR:
7229  newRing = currRing;
7230  nwalk++;
7231  nwalkpert++;
7232  to=clock();
7233  // compute a next weight vector
7234  next_weight = MwalkNextWeightCC(curr_weight,target_weight, G);
7235  tnw=tnw+clock()-to;
7236 #ifdef PRINT_VECTORS
7237  MivString(curr_weight, target_weight, next_weight);
7238 #endif
7239 
7240 
7241  /* check whether the computed intermediate weight vector is in
7242  the correct cone; sometimes it is very big e.g. s7, cyc7.
7243  If it is NOT in the correct cone, then compute directly
7244  a reduced Groebner basis with respect to the lexicographic ordering
7245  for the known Groebner basis that it is computed in the last step.
7246  */
7247  //if(test_w_in_ConeCC(G, next_weight) != 1)
7248  if(Overflow_Error == TRUE)
7249  {
7250  OMEGA_OVERFLOW_TRAN_NEW:
7251  //Print("\n// takes %d steps!", nwalk-1);
7252  //Print("\n//ring lastRing = %s;", rString(currRing));
7253 #ifdef TEST_OVERFLOW
7254  goto BE_FINISH;
7255 #endif
7256 
7257 #ifdef CHECK_IDEAL_MWALK
7258  idElements(G, "G");
7259  //headidString(G, "G");
7260 #endif
7261 
7262  if(MivSame(target_tmp, iv_lp) == 1)
7263  if (rParameter(currRing) != NULL)
7264  DefRingParlp();
7265  else
7266  VMrDefaultlp();
7267  else
7268  if (rParameter(currRing) != NULL)
7269  DefRingPar(target_tmp);
7270  else
7271  rChangeCurrRing(VMrDefault(target_tmp)); // Aenderung 8
7272 
7273  lpRing = currRing;
7274  G1 = idrMoveR(G, newRing,currRing);
7275 
7276  to=clock();
7277  /*apply kStd or LastGB to compute a lex. red. Groebner basis of <G>*/
7278  if(nP == 0 || MivSame(target_tmp, iv_lp) == 0){
7279  //Print("\n\n// calls \"std in ring r_%d = %s;", nwalk, rString(currRing));
7280  G = MstdCC(G1);//no result for qnt1
7281  }
7282  else {
7283  rChangeCurrRing(newRing);
7284  G1 = idrMoveR(G1, lpRing,currRing);
7285 
7286  //Print("\n\n// calls \"LastGB\" (%d) to compute a GB", nV-1);
7287  G = LastGB(G1, curr_weight, nV-1); //no result for kats7
7288 
7289  rChangeCurrRing(lpRing);
7290  G = idrMoveR(G, newRing,currRing);
7291  }
7292  textra=clock()-to;
7293  npert[endwalks]=nwalk-npert_tmp;
7294  npert_tmp = nwalk;
7295  endwalks ++;
7296  break;
7297  }
7298 
7299  /* check whether the computed Groebner basis is really a Groebner basis.
7300  If not, we perturb the target vector with the maximal "perturbation"
7301  degree.*/
7302  if(MivComp(next_weight, target_weight) == 1 ||
7303  MivComp(next_weight, curr_weight) == 1 )
7304  {
7305  //Print("\n//ring r_%d = %s;", nwalk, rString(currRing));
7306 
7307 
7308  //compute the number of perturbations and its step
7309  npert[endwalks]=nwalk-npert_tmp;
7310  npert_tmp = nwalk;
7311 
7312  endwalks ++;
7313 
7314  /*it is very important if the walk only uses one step, e.g. Fate, liu*/
7315  if(endwalks == 1 && MivComp(next_weight, curr_weight) == 1){
7316  rChangeCurrRing(XXRing);
7317  G = idrMoveR(G, newRing,currRing);
7318  goto FINISH;
7319  }
7320  H0 = id_Head(G,currRing);
7321 
7322  if(MivSame(target_tmp, iv_lp) == 1)
7323  if (rParameter(currRing) != NULL)
7324  DefRingParlp();
7325  else
7326  VMrDefaultlp();
7327  else
7328  if (rParameter(currRing) != NULL)
7329  DefRingPar(target_tmp);
7330  else
7331  rChangeCurrRing(VMrDefault(target_tmp)); //Aenderung 9
7332 
7333  lpRing = currRing;
7334  Glp = idrMoveR(G, newRing,currRing);
7335  H2 = idrMoveR(H0, newRing,currRing);
7336 
7337  /* Apply Lemma 2.2 in Collart et. al (1997) to check whether
7338  cone(k-1) is equal to cone(k) */
7339  nGB = 1;
7340  for(i=IDELEMS(Glp)-1; i>=0; i--)
7341  {
7342  poly t;
7343  if((t=pSub(pHead(Glp->m[i]), pCopy(H2->m[i]))) != NULL)
7344  {
7345  pDelete(&t);
7346  idDelete(&H2);//5.5.02
7347  nGB = 0; //i.e. Glp is no reduced Groebner basis
7348  break;
7349  }
7350  pDelete(&t);
7351  }
7352 
7353  idDelete(&H2);//5.5.02
7354 
7355  if(nGB == 1)
7356  {
7357  G = Glp;
7358  Glp = NULL;
7359  break;
7360  }
7361 
7362  /* perturb the target weight vector, if the vector target_tmp
7363  stays in many cones */
7364  poly p;
7365  BOOLEAN plength3 = FALSE;
7366  for(i=IDELEMS(Glp)-1; i>=0; i--)
7367  {
7368  p = MpolyInitialForm(Glp->m[i], target_tmp);
7369  if(p->next != NULL &&
7370  p->next->next != NULL &&
7371  p->next->next->next != NULL)
7372  {
7374 
7375  for(i=0; i<nV; i++)
7376  (*vector_tmp)[i] = (*target_weight)[i];
7377 
7378  delete target_weight;
7379  target_weight = MPertVectors(Glp, Mlp, nV);
7380 
7381  if(MivComp(vector_tmp, target_weight)==1)
7382  {
7383  //PrintS("\n// The old and new representaion vector are the same!!");
7384  G = Glp;
7385  newRing = currRing;
7386  goto OMEGA_OVERFLOW_TRAN_NEW;
7387  }
7388 
7389  if(Overflow_Error == TRUE)
7390  {
7391  rChangeCurrRing(newRing);
7392  G = idrMoveR(Glp, lpRing,currRing);
7393  goto OMEGA_OVERFLOW_TRAN_NEW;
7394  }
7395 
7396  plength3 = TRUE;
7397  pDelete(&p);
7398  break;
7399  }
7400  pDelete(&p);
7401  }
7402 
7403  if(plength3 == FALSE)
7404  {
7405  rChangeCurrRing(newRing);
7406  G = idrMoveR(Glp, lpRing,currRing);
7407  goto TRAN_LIFTING;
7408  }
7409 
7410 
7411  npertstep = nwalk;
7412  nwalkpert = 1;
7413  nsteppert ++;
7414 
7415  /*
7416  Print("\n// Subroutine needs (%d) steps.", nwalk);
7417  idElements(Glp, "last G in walk:");
7418  PrintS("\n// ****************************************");
7419  Print("\n// Perturb the original target vector (%d): ", nsteppert);
7420  ivString(target_weight, "new target");
7421  PrintS("\n// ****************************************\n");
7422  */
7423  rChangeCurrRing(newRing);
7424  G = idrMoveR(Glp, lpRing,currRing);
7425 
7426  delete next_weight;
7427 
7428  //Print("\n// ring rNEW = %s;", rString(currRing));
7429  goto COMPUTE_NEW_VECTOR;
7430  }
7431 
7432  TRAN_LIFTING:
7433  for(i=nV-1; i>=0; i--)
7434  (*curr_weight)[i] = (*next_weight)[i];
7435 
7436  delete next_weight;
7437  }//while
7438 #ifdef TEST_OVERFLOW
7439  BE_FINISH:
7440 #endif
7441  rChangeCurrRing(XXRing);
7442  G = idrMoveR(G, lpRing,currRing);
7443 
7444  FINISH:
7445  delete ivNull;
7446  delete next_weight;
7447  delete iv_lp;
7448  omFree(npert);
7449 
7450 #ifdef TIME_TEST
7451  Print("\n// Computation took %d steps and %.2f sec",
7452  nwalk, ((double) (clock()-mtim)/1000000));
7453 
7454  TimeStringFractal(tinput, tostd, tif, tstd, textra, tlift, tred, tnw);
7455 
7456  Print("\n// pSetm_Error = (%d)", ErrorCheck());
7457  Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
7458 #endif
7459 
7460  return(G);
7461 }
7462 
7463 #if 0
7464 /*******************************************************
7465  * Tran's algorithm with random element *
7466  * *
7467  * use kStd, if nP = 0, else call Ab_Rec_Pert (LastGB) *
7468  *******************************************************/
7469 ideal TranMrImprovwalk(ideal G,intvec* curr_weight,intvec* target_tmp, int nP, int weight_rad, int pert_deg)
7470 {
7471 #ifdef TIME_TEST
7472  clock_t mtim = clock();
7473 #endif
7474  Set_Error(FALSE );
7476  //Print("// pSetm_Error = (%d)", ErrorCheck());
7477  //Print("\n// ring ro = %s;", rString(currRing));
7478 
7479  clock_t tostd, tif=0, tstd=0, tlift=0, tred=0, tnw=0, textra=0;
7480 #ifdef TIME_TEST
7481  clock_t tinput = clock();
7482 #endif
7483  int nsteppert=0, i, nV = currRing->N, nwalk=0, npert_tmp=0;
7484  int *npert=(int*)omAlloc(2*nV*sizeof(int));
7485  ideal Gomega, M,F, G1, Gomega1, Gomega2, M1, F1;
7486  //ring endRing;
7487  ring newRing, oldRing, lpRing;
7488  intvec* next_weight;
7489  intvec* ivNull = new intvec(nV); //define (0,...,0)
7490  intvec* iv_dp = MivUnit(nV);// define (1,1,...,1)
7491  intvec* iv_lp = Mivlp(nV); //define (1,0,...,0)
7492  ideal H0;
7493  //ideal H1;
7494  ideal H2, Glp;
7495  int weight_norm, nGB, endwalks = 0, nwalkpert=0, npertstep=0;
7496  intvec* Mlp = MivMatrixOrderlp(nV);
7497  intvec* vector_tmp = new intvec(nV);
7498 #ifndef BUCHBERGER_ALG
7499  intvec* hilb_func;
7500 #endif
7501  // to avoid (1,0,...,0) as the target vector
7502  intvec* last_omega = new intvec(nV);
7503  for(i=nV-1; i>0; i--)
7504  {
7505  (*last_omega)[i] = 1;
7506  }
7507  (*last_omega)[0] = 10000;
7508 
7509 //intvec* extra_curr_weight = new intvec(nV);
7510  intvec* target_weight = new intvec(nV);
7511  for(i=nV-1; i>=0; i--)
7512  {
7513  (*target_weight)[i] = (*target_tmp)[i];
7514  }
7515  ring XXRing = currRing;
7516  newRing = currRing;
7517 
7518  to=clock();
7519  // compute a red. GB w.r.t. the help ring
7520  if(MivComp(curr_weight, iv_dp) == 1)
7521  {
7522  //rOrdStr(currRing) = "dp"
7523  G = MstdCC(G);
7524  }
7525  else
7526  {
7527  //rOrdStr(currRing) = (a(.c_w..),lp,C)
7528  if (rParameter(currRing) != NULL)
7529  {
7530  DefRingPar(curr_weight);
7531  }
7532  else
7533  {
7534  rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung 10
7535  }
7536  G = idrMoveR(G, XXRing,currRing);
7537  G = MstdCC(G);
7538  }
7539  tostd=clock()-to;
7540 
7541 #ifdef REPRESENTATION_OF_SIGMA
7542  ideal Gw = MwalkInitialForm(G, curr_weight);
7543 
7544  if(islengthpoly2(Gw)==1)
7545  {
7546  intvec* MDp;
7547  if(MivComp(curr_weight, iv_dp) == 1)
7548  {
7549  MDp = MatrixOrderdp(nV); //MivWeightOrderlp(iv_dp);
7550  }
7551  else
7552  {
7553  MDp = MivWeightOrderlp(curr_weight);
7554  }
7555  curr_weight = RepresentationMatrix_Dp(G, MDp);
7556 
7557  delete MDp;
7558 
7559  ring exring = currRing;
7560 
7561  if (rParameter(currRing) != NULL)
7562  {
7563  DefRingPar(curr_weight);
7564  }
7565  else
7566  {
7567  rChangeCurrRing(VMrDefault(curr_weight)); //Aenderung 11
7568  }
7569  to=clock();
7570  Gw = idrMoveR(G, exring,currRing);
7571  G = MstdCC(Gw);
7572  Gw = NULL;
7573  tostd=tostd+clock()-to;
7574  //ivString(curr_weight,"rep. sigma");
7575  goto COMPUTE_NEW_VECTOR;
7576  }
7577 
7578  idDelete(&Gw);
7579  delete iv_dp;
7580 #endif
7581 
7582 
7583  while(1)
7584  {
7585  to=clock();
7586  // compute an initial form ideal of <G> w.r.t. "curr_vector"
7587  Gomega = MwalkInitialForm(G, curr_weight);
7588  tif=tif+clock()-to;
7589 
7590 #ifndef BUCHBERGER_ALG
7591  if(isNolVector(curr_weight) == 0)
7592  {
7593  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
7594  }
7595  else
7596  {
7597  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
7598  }
7599 #endif // BUCHBERGER_ALG
7600 
7601  oldRing = currRing;
7602 
7603  // define a new ring with ordering "(a(curr_weight),lp)
7604  if (rParameter(currRing) != NULL)
7605  {
7606  DefRingPar(curr_weight);
7607  }
7608  else
7609  {
7610  rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung 12
7611  }
7612  newRing = currRing;
7613  Gomega1 = idrMoveR(Gomega, oldRing,currRing);
7614 
7615  to=clock();
7616  // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
7617 #ifdef BUCHBERGER_ALG
7618  M = MstdhomCC(Gomega1);
7619 #else
7620  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
7621  delete hilb_func;
7622 #endif
7623  tstd=tstd+clock()-to;
7624 
7625  // change the ring to oldRing
7626  rChangeCurrRing(oldRing);
7627  M1 = idrMoveR(M, newRing,currRing);
7628  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
7629 
7630  to=clock();
7631  // compute a representation of the generators of submod (M) with respect to those of mod (Gomega).
7632  // Gomega is a reduced Groebner basis w.r.t. the current ring
7633  F = MLifttwoIdeal(Gomega2, M1, G);
7634  tlift=tlift+clock()-to;
7635 
7636  idDelete(&M1);
7637  idDelete(&Gomega2);
7638  idDelete(&G);
7639 
7640  // change the ring to newRing
7641  rChangeCurrRing(newRing);
7642  F1 = idrMoveR(F, oldRing,currRing);
7643 
7644  to=clock();
7645  // reduce the Groebner basis <G> w.r.t. new ring
7646  G = kInterRedCC(F1, NULL);
7647  tred=tred+clock()-to;
7648  idDelete(&F1);
7649 
7650  COMPUTE_NEW_VECTOR:
7651  newRing = currRing;
7652  nwalk++;
7653  nwalkpert++;
7654  to=clock();
7655  // compute a next weight vector
7656  //next_weight = MwalkNextWeightCC(curr_weight,target_weight, G);
7657  next_weight = MWalkRandomNextWeight(G, curr_weight, target_weight, weight_rad, pert_deg);
7658 /*
7659  next_weight = MkInterRedNextWeight(curr_weight,target_weight,G);
7660 
7661  if(MivComp(next_weight, target_weight) != 1)
7662  {
7663  // compute a perturbed next weight vector "next_weight1"
7664  intvec* next_weight1 = MkInterRedNextWeight(MPertVectors(G, MivMatrixOrder(curr_weight), pert_deg), target_weight, G);
7665 
7666  // compare next_weight and next_weight1
7667  ideal G_test = MwalkInitialForm(G, next_weight);
7668  ideal G_test1 = MwalkInitialForm(G, next_weight1);
7669  if(IDELEMS(G_test1) <= IDELEMS(G_test))
7670  {
7671  next_weight = ivCopy(next_weight1);
7672  }
7673  delete next_weight1;
7674  // compute a random next weight vector "next_weight2"
7675  intvec* next_weight22 = ivCopy(target_weight);
7676  // Print("\n// size of target_weight = %d", sizeof((*target_weight)));
7677  k = 0;
7678 
7679  while(test_w_in_ConeCC(G, next_weight22) == 0 && k < 11)
7680  {
7681  k++;
7682  if(k>10)
7683  {
7684  break;
7685  }
7686  weight_norm = 0;
7687  while(weight_norm == 0)
7688  {
7689  for(i=nV-1; i>=0; i--)
7690  {
7691  // Print("\n// next_weight[%d] = %d", i, (*next_weight)[i]);
7692  (*next_weight22)[i] = rand() % 60000 - 30000;
7693  weight_norm = weight_norm + (*next_weight22)[i]*(*next_weight22)[i];
7694  }
7695  weight_norm = 1 + floor(sqrt(weight_norm));
7696  }
7697  for(i=nV-1; i>=0; i--)
7698  {
7699  if((*next_weight22)[i] < 0)
7700  {
7701  (*next_weight22)[i] = 1 + (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
7702  }
7703  else
7704  {
7705  (*next_weight22)[i] = (*curr_weight)[i] + floor(weight_rad*(*next_weight22)[i]/weight_norm);
7706  }
7707  // Print("\n// next_weight22[%d] = %d", i, (*next_weight22)[i]);
7708  }
7709  }
7710 
7711  if(test_w_in_ConeCC(G, next_weight22) == 1)
7712  {
7713  // compare next_weight and next_weight2
7714  // Print("\n// ZUFALL IM KEGEL");
7715  intvec* next_weight2 = MkInterRedNextWeight(next_weight22, target_weight, G);
7716 
7717  ideal G_test2 = MwalkInitialForm(G, next_weight2);
7718  if(IDELEMS(G_test2) <= IDELEMS(G_test))
7719  {
7720  if(IDELEMS(G_test2) <= IDELEMS(G_test1))
7721  {
7722  // Print("\n// ZUFALL BENUTZT!\n");
7723  next_weight = ivCopy(next_weight2);
7724  }
7725  }
7726  idDelete(&G_test2);
7727  delete next_weight2;
7728  }
7729  delete next_weight22;
7730  idDelete(&G_test);
7731  idDelete(&G_test1);
7732  }*/
7733 
7734  tnw=tnw+clock()-to;
7735 #ifdef PRINT_VECTORS
7736  MivString(curr_weight, target_weight, next_weight);
7737 #endif
7738 
7739 /* check whether the computed intermediate weight vector is in
7740  the correct cone; sometimes it is very big e.g. s7, cyc7.
7741  If it is NOT in the correct cone, then compute directly
7742  a reduced Groebner basis with respect to the lexicographic ordering
7743  for the known Groebner basis that it is computed in the last step.
7744 */
7745  //if(test_w_in_ConeCC(G, next_weight) != 1)
7746  if(Overflow_Error == TRUE)
7747  {
7748  OMEGA_OVERFLOW_TRAN_NEW:
7749  //Print("\n// takes %d steps!", nwalk-1);
7750  //Print("\n//ring lastRing = %s;", rString(currRing));
7751 #ifdef TEST_OVERFLOW
7752  goto BE_FINISH;
7753 #endif
7754 
7755 #ifdef CHECK_IDEAL_MWALK
7756  idElements(G, "G");
7757  //headidString(G, "G");
7758 #endif
7759 
7760  if(MivSame(target_tmp, iv_lp) == 1)
7761  {
7762  if (rParameter(currRing) != NULL)
7763  {
7764  DefRingParlp();
7765  }
7766  else
7767  {
7768  VMrDefaultlp();
7769  }
7770  }
7771  else
7772  {
7773  if (rParameter(currRing) != NULL)
7774  {
7775  DefRingPar(target_tmp);
7776  }
7777  else
7778  {
7779  rChangeCurrRing(VMrDefault(target_tmp)); // Aenderung 13
7780  }
7781  }
7782  lpRing = currRing;
7783  G1 = idrMoveR(G, newRing,currRing);
7784 
7785  to=clock();
7786  // apply kStd or LastGB to compute a lex. red. Groebner basis of <G>
7787  if(nP == 0 || MivSame(target_tmp, iv_lp) == 0)
7788  {
7789  //Print("\n\n// calls \"std in ring r_%d = %s;", nwalk, rString(currRing));
7790  G = MstdCC(G1);//no result for qnt1
7791  }
7792  else
7793  {
7794  rChangeCurrRing(newRing);
7795  G1 = idrMoveR(G1, lpRing,currRing);
7796 
7797  //Print("\n\n// calls \"LastGB\" (%d) to compute a GB", nV-1);
7798  G = LastGB(G1, curr_weight, nV-1); //no result for kats7
7799 
7800  rChangeCurrRing(lpRing);
7801  G = idrMoveR(G, newRing,currRing);
7802  }
7803  textra=clock()-to;
7804  npert[endwalks]=nwalk-npert_tmp;
7805  npert_tmp = nwalk;
7806  endwalks ++;
7807  break;
7808  }
7809 
7810  // check whether the computed Groebner basis is really a Groebner basis.
7811  // If not, we perturb the target vector with the maximal "perturbation" degree.
7812 
7813  if(MivComp(next_weight, target_weight) == 1 || MivComp(next_weight, curr_weight) == 1 )
7814  {
7815  //Print("\n//ring r_%d = %s;", nwalk, rString(currRing));
7816 
7817 
7818  //compute the number of perturbations and its step
7819  npert[endwalks]=nwalk-npert_tmp;
7820  npert_tmp = nwalk;
7821 
7822  endwalks ++;
7823 
7824  // it is very important if the walk only uses one step, e.g. Fate, liu
7825  if(endwalks == 1 && MivComp(next_weight, curr_weight) == 1)
7826  {
7827  rChangeCurrRing(XXRing);
7828  G = idrMoveR(G, newRing,currRing);
7829  goto FINISH;
7830  }
7831  H0 = id_Head(G,currRing);
7832 
7833  if(MivSame(target_tmp, iv_lp) == 1)
7834  {
7835  if (rParameter(currRing) != NULL)
7836  {
7837  DefRingParlp();
7838  }
7839  else
7840  {
7841  VMrDefaultlp();
7842  }
7843  }
7844  else
7845  {
7846  if (rParameter(currRing) != NULL)
7847  {
7848  DefRingPar(target_tmp);
7849  }
7850  else
7851  {
7852  rChangeCurrRing(VMrDefault(target_tmp)); // Aenderung 14
7853  }
7854  }
7855  lpRing = currRing;
7856  Glp = idrMoveR(G, newRing,currRing);
7857  H2 = idrMoveR(H0, newRing,currRing);
7858 
7859  // Apply Lemma 2.2 in Collart et. al (1997) to check whether cone(k-1) is equal to cone(k)
7860  nGB = 1;
7861  for(i=IDELEMS(Glp)-1; i>=0; i--)
7862  {
7863  poly t;
7864  if((t=pSub(pHead(Glp->m[i]), pCopy(H2->m[i]))) != NULL)
7865  {
7866  pDelete(&t);
7867  idDelete(&H2);//5.5.02
7868  nGB = 0; //i.e. Glp is no reduced Groebner basis
7869  break;
7870  }
7871  pDelete(&t);
7872  }
7873 
7874  idDelete(&H2);//5.5.02
7875 
7876  if(nGB == 1)
7877  {
7878  G = Glp;
7879  Glp = NULL;
7880  break;
7881  }
7882 
7883  // perturb the target weight vector, if the vector target_tmp stays in many cones
7884  poly p;
7885  BOOLEAN plength3 = FALSE;
7886  for(i=IDELEMS(Glp)-1; i>=0; i--)
7887  {
7888  p = MpolyInitialForm(Glp->m[i], target_tmp);
7889  if(p->next != NULL &&
7890  p->next->next != NULL &&
7891  p->next->next->next != NULL)
7892  {
7894 
7895  for(i=0; i<nV; i++)
7896  {
7897  (*vector_tmp)[i] = (*target_weight)[i];
7898  }
7899  delete target_weight;
7900  target_weight = MPertVectors(Glp, Mlp, nV);
7901 
7902  if(MivComp(vector_tmp, target_weight)==1)
7903  {
7904  //PrintS("\n// The old and new representaion vector are the same!!");
7905  G = Glp;
7906  newRing = currRing;
7907  goto OMEGA_OVERFLOW_TRAN_NEW;
7908  }
7909 
7910  if(Overflow_Error == TRUE)
7911  {
7912  rChangeCurrRing(newRing);
7913  G = idrMoveR(Glp, lpRing,currRing);
7914  goto OMEGA_OVERFLOW_TRAN_NEW;
7915  }
7916 
7917  plength3 = TRUE;
7918  pDelete(&p);
7919  break;
7920  }
7921  pDelete(&p);
7922  }
7923 
7924  if(plength3 == FALSE)
7925  {
7926  rChangeCurrRing(newRing);
7927  G = idrMoveR(Glp, lpRing,currRing);
7928  goto TRAN_LIFTING;
7929  }
7930 
7931 
7932  npertstep = nwalk;
7933  nwalkpert = 1;
7934  nsteppert ++;
7935 
7936  /*
7937  Print("\n// Subroutine needs (%d) steps.", nwalk);
7938  idElements(Glp, "last G in walk:");
7939  PrintS("\n// ****************************************");
7940  Print("\n// Perturb the original target vector (%d): ", nsteppert);
7941  ivString(target_weight, "new target");
7942  PrintS("\n// ****************************************\n");
7943  */
7944  rChangeCurrRing(newRing);
7945  G = idrMoveR(Glp, lpRing,currRing);
7946 
7947  delete next_weight;
7948 
7949  //Print("\n// ring rNEW = %s;", rString(currRing));
7950  goto COMPUTE_NEW_VECTOR;
7951  }
7952 
7953  TRAN_LIFTING:
7954  for(i=nV-1; i>=0; i--)
7955  {
7956  (*curr_weight)[i] = (*next_weight)[i];
7957  }
7958  delete next_weight;
7959  } // end of while
7960 #ifdef TEST_OVERFLOW
7961  BE_FINISH:
7962 #endif
7963  rChangeCurrRing(XXRing);
7964  G = idrMoveR(G, lpRing,currRing);
7965 
7966  FINISH:
7967  delete ivNull;
7968  delete next_weight;
7969  delete iv_lp;
7970  omFree(npert);
7971 
7972 #ifdef TIME_TEST
7973  Print("\n// Computation took %d steps and %.2f sec", nwalk, ((double) (clock()-mtim)/1000000));
7974 
7975  TimeStringFractal(tinput, tostd, tif, tstd, textra, tlift, tred, tnw);
7976 
7977  Print("\n// pSetm_Error = (%d)", ErrorCheck());
7978  Print("\n// Overflow_Error? (%d)\n", Overflow_Error);
7979 #endif
7980 
7981  return(G);
7982 }
7983 #endif
7984 
7985 /*****************************************************************
7986  * compute the reduced Groebner basis of an ideal <Go> w.r.t. lp *
7987  *****************************************************************/
7988 static ideal Mpwalk_MAltwalk1(ideal Go, intvec* curr_weight, int tp_deg)
7989 {
7991  // BOOLEAN nOverflow_Error = FALSE;
7992  clock_t tproc=0;
7993  clock_t tinput=clock();
7994  int i, nV = currRing->N;
7995  int nwalk=0, endwalks=0, ntestwinC=1;
7996  int tp_deg_tmp = tp_deg;
7997  ideal Gomega, M, F, G, M1, F1, Gomega1, Gomega2, G1;
7998  ring newRing, oldRing, TargetRing;
7999  intvec* next_weight;
8000  intvec* ivNull = new intvec(nV);
8001 
8002  ring YXXRing = currRing;
8003 
8004  intvec* iv_M_dpp = MivMatrixOrderlp(nV);
8005  intvec* target_weight;// = Mivlp(nV);
8006  ideal ssG;
8007 
8008  // perturb the target vector
8009  while(1)
8010  {
8011  if(Overflow_Error == FALSE)
8012  {
8013  if (rParameter(currRing) != NULL)
8014  {
8015  DefRingParlp();
8016  }
8017  else
8018  {
8019  VMrDefaultlp();
8020  }
8021  TargetRing = currRing;
8022  ssG = idrMoveR(Go,YXXRing,currRing);
8023  }
8025  if(tp_deg != 1)
8026  {
8027  target_weight = MPertVectors(ssG, iv_M_dpp, tp_deg);
8028  }
8029  else
8030  {
8031  target_weight = Mivlp(nV);
8032  break;
8033  }
8034  if(Overflow_Error == FALSE)
8035  {
8036  break;
8037  }
8038  Overflow_Error = TRUE;
8039  tp_deg --;
8040  }
8041  if(tp_deg != tp_deg_tmp)
8042  {
8043  Overflow_Error = TRUE;
8044  //nOverflow_Error = TRUE;
8045  }
8046 
8047  // Print("\n// tp_deg = %d", tp_deg);
8048  // ivString(target_weight, "pert target");
8049 
8050  delete iv_M_dpp;
8051 #ifndef BUCHBERGER_ALG
8052  intvec* hilb_func;
8053 #endif
8054  // to avoid (1,0,...,0) as the target vector
8055  intvec* last_omega = new intvec(nV);
8056  for(i=nV-1; i>0; i--)
8057  {
8058  (*last_omega)[i] = 1;
8059  }
8060  (*last_omega)[0] = 10000;
8061 
8062  rChangeCurrRing(YXXRing);
8063  G = idrMoveR(ssG, TargetRing,currRing);
8064 
8065  while(1)
8066  {
8067  nwalk ++;
8068  nstep ++;
8069 
8070  if(nwalk==1)
8071  {
8072  goto FIRST_STEP;
8073  }
8074  to=clock();
8075  // compute an initial form ideal of <G> w.r.t. "curr_vector"
8076  Gomega = MwalkInitialForm(G, curr_weight);
8077  xtif=xtif+clock()-to;
8078 
8079 #ifndef BUCHBERGER_ALG
8080  if(isNolVector(curr_weight) == 0)
8081  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
8082  else
8083  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
8084 #endif
8085 
8086  oldRing = currRing;
8087 
8088  // define a new ring that its ordering is "(a(curr_weight),lp)
8089  if (rParameter(currRing) != NULL)
8090  {
8091  DefRingPar(curr_weight);
8092  }
8093  else
8094  {
8095  rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung 15
8096  }
8097  newRing = currRing;
8098  Gomega1 = idrMoveR(Gomega, oldRing,currRing);
8099 
8100 #ifdef ENDWALKS
8101  if(endwalks == 1)
8102  {
8103  Print("\n// it is %d-th step!!", nwalk);
8104  idElements(Gomega1, "Gw");
8105  PrintS("\n// compute a rGB of Gw:");
8106  }
8107 #endif
8108 
8109  to=clock();
8110  // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
8111 #ifdef BUCHBERGER_ALG
8112  M = MstdhomCC(Gomega1);
8113 #else
8114  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
8115  delete hilb_func;
8116 #endif // BUCHBERGER_ALG
8117  xtstd=xtstd+clock()-to;
8118 
8119  // change the ring to oldRing
8120  rChangeCurrRing(oldRing);
8121  M1 = idrMoveR(M, newRing,currRing);
8122  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
8123  to=clock();
8124 
8125  // if(endwalks == 1){PrintS("\n// Lifting is still working:");}
8126 
8127  // compute a reduced Groebner basis of <G> w.r.t. "newRing" by the lifting process
8128  F = MLifttwoIdeal(Gomega2, M1, G);
8129  xtlift=xtlift+clock()-to;
8130 
8131  idDelete(&M1);
8132  idDelete(&Gomega2);
8133  idDelete(&G);
8134 
8135  // change the ring to newRing
8136  rChangeCurrRing(newRing);
8137  F1 = idrMoveR(F, oldRing,currRing);
8138  to=clock();
8139  //if(endwalks == 1){ PrintS("\n// InterRed is still working:");}
8140  // reduce the Groebner basis <G> w.r.t. the new ring
8141  G = kInterRedCC(F1, NULL);
8142  xtred=xtred+clock()-to;
8143  idDelete(&F1);
8144 
8145  if(endwalks == 1)
8146  break;
8147 
8148  FIRST_STEP:
8150  to=clock();
8151  // compute a next weight vector
8152  next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
8153  xtnw=xtnw+clock()-to;
8154 #ifdef PRINT_VECTORS
8155  MivString(curr_weight, target_weight, next_weight);
8156 #endif
8157 
8158  if(Overflow_Error == TRUE)
8159  {
8160  delete next_weight;
8161  if(tp_deg > 1){
8162  //nOverflow_Error = Overflow_Error;
8163  tproc = tproc+clock()-tinput;
8164  //Print("\n// A subroutine takes %d steps and calls \"Mpwalk\" (1,%d):", nwalk, tp_deg-1);
8165  G1 = Mpwalk_MAltwalk1(G, curr_weight, tp_deg-1);
8166  goto MPW_Finish;
8167  }
8168  else {
8169  newRing = currRing;
8170  ntestwinC = 0;
8171  break;
8172  }
8173  }
8174 
8175  if(MivComp(next_weight, ivNull) == 1)
8176  {
8177  newRing = currRing;
8178  delete next_weight;
8179  break;
8180  }
8181  if(MivComp(next_weight, target_weight) == 1)
8182  {
8183  endwalks = 1;
8184  }
8185  for(i=nV-1; i>=0; i--)
8186  {
8187  //(*extra_curr_weight)[i] = (*curr_weight)[i];
8188  (*curr_weight)[i] = (*next_weight)[i];
8189  }
8190  delete next_weight;
8191  }//while
8192 
8193  // check whether the pertubed target vector is correct
8194 
8195  //define and execute ring with lex. order
8196  if (rParameter(currRing) != NULL)
8197  {
8198  DefRingParlp();
8199  }
8200  else
8201  {
8202  VMrDefaultlp();
8203  }
8204  G1 = idrMoveR(G, newRing,currRing);
8205 
8206  if( test_w_in_ConeCC(G1, target_weight) != 1 || ntestwinC == 0)
8207  {
8208  PrintS("\n// The perturbed target vector doesn't STAY in the correct cone!!");
8209  if(tp_deg == 1)
8210  {
8211  //Print("\n// subroutine takes %d steps and applys \"std\"", nwalk);
8212  to=clock();
8213  ideal G2 = MstdCC(G1);
8214  xtextra=xtextra+clock()-to;
8215  idDelete(&G1);
8216  G1 = G2;
8217  G2 = NULL;
8218  }
8219  else
8220  {
8221  //nOverflow_Error = Overflow_Error;
8222  tproc = tproc+clock()-tinput;
8223  // Print("\n// B subroutine takes %d steps and calls \"Mpwalk\" (1,%d) :", nwalk, tp_deg-1);
8224  G1 = Mpwalk_MAltwalk1(G1, curr_weight, tp_deg-1);
8225  }
8226  }
8227 
8228  MPW_Finish:
8229  newRing = currRing;
8230  rChangeCurrRing(YXXRing);
8231  ideal result = idrMoveR(G1, newRing,currRing);
8232 
8233  delete ivNull;
8234  delete target_weight;
8235 
8236  //Print("\n// \"Mpwalk\" (1,%d) took %d steps and %.2f sec. Overflow_Error (%d)", tp_deg, nwalk, ((double) clock()-tinput)/1000000, nOverflow_Error);
8237 
8238  return(result);
8239 }
8240 
8241 /*******************************************************
8242  * THE PERTURBATION WALK ALGORITHM WITH RANDOM ELEMENT *
8243  *******************************************************/
8244 ideal Mprwalk(ideal Go, intvec* curr_weight, intvec* target_weight, int weight_rad, int op_deg, int tp_deg, ring baseRing)
8245 {
8246  BITSET save1 = si_opt_1; // save current options
8247  si_opt_1 &= (~Sy_bit(OPT_REDSB)); // no reduced Groebner basis
8248  Set_Error(FALSE);
8250 #ifdef TIME_TEST
8251  clock_t tinput=0, tostd=0, tif=0, tstd=0, tlift=0, tred=0, tnw=0;
8252  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0;
8253  tinput = clock();
8254  clock_t tim;
8255 #endif
8256  int i,nwalk,nV = baseRing->N;
8257 
8258  ideal G, Gomega, M, F, Gomega1, Gomega2, M1;
8259  ring newRing;
8260  ring XXRing = baseRing;
8261  intvec* exivlp = Mivlp(nV);
8262  intvec* orig_target = target_weight;
8263  intvec* pert_target_vector = target_weight;
8264  intvec* ivNull = new intvec(nV);
8265  intvec* tmp_weight = new intvec(nV);
8266 #ifdef CHECK_IDEAL_MWALK
8267  poly p;
8268 #endif
8269  for(i=0; i<nV; i++)
8270  {
8271  (*tmp_weight)[i] = (*curr_weight)[i];
8272  }
8273 #ifndef BUCHBERGER_ALG
8274  intvec* hilb_func;
8275  // to avoid (1,0,...,0) as the target vector
8276  intvec* last_omega = new intvec(nV);
8277  for(i=0 i<nV; i++)
8278  {
8279  (*last_omega)[i] = 1;
8280  }
8281  (*last_omega)[0] = 10000;
8282 #endif
8283  baseRing = currRing;
8284  newRing = VMrDefault(curr_weight);
8285  rChangeCurrRing(newRing);
8286  G = idrMoveR(Go,baseRing,currRing);
8287 #ifdef TIME_TEST
8288  to = clock();
8289 #endif
8290  G = kStd(G,NULL,testHomog,NULL,NULL,0,0,NULL);
8291  idSkipZeroes(G);
8292 #ifdef TIME_TEST
8293  tostd = tostd + to - clock();
8294 #endif
8295 #ifdef CHECK_IDEAL_MWALK
8296  idString(G,"G");
8297 #endif
8298  if(op_deg >1)
8299  {
8300  if(MivComp(curr_weight,MivUnit(nV)) == 1) //ring order is "dp"
8301  {
8302  curr_weight = MPertVectors(G, MivMatrixOrderdp(nV), op_deg);
8303  }
8304  else //ring order is not "dp"
8305  {
8306  curr_weight = MPertVectors(G, MivMatrixOrder(curr_weight), op_deg);
8307  }
8308  }
8309  baseRing = currRing;
8310  if(tp_deg > 1 && tp_deg <= nV)
8311  {
8312  pert_target_vector = target_weight;
8313  }
8314 #ifdef CHECK_IDEAL_MWALK
8315  ivString(curr_weight, "new curr_weight");
8316  ivString(target_weight, "new target_weight");
8317 #endif
8318  nwalk = 0;
8319  while(1)
8320  {
8321  nwalk ++;
8322 #ifdef TIME_TEST
8323  to = clock();
8324 #endif
8325  Gomega = MwalkInitialForm(G, curr_weight); // compute an initial form ideal of <G> w.r.t. "curr_vector"
8326 #ifdef TIME_TEST
8327  tif = tif + clock()-to; //time for computing initial form ideal
8328 #endif
8329 #ifdef CHECK_IDEAL_MWALK
8330  idString(Gomega,"Gomega");
8331 #endif
8332 #ifndef BUCHBERGER_ALG
8333  if(isNolVector(curr_weight) == 0)
8334  {
8335  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
8336  }
8337  else
8338  {
8339  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
8340  }
8341 #endif
8342  if(nwalk == 1)
8343  {
8344  newRing = VMrDefault(curr_weight); // define a new ring with ordering "(a(curr_weight),lp)
8345  }
8346  else
8347  {
8348  newRing = VMrRefine(curr_weight,target_weight); //define a new ring with ordering "(a(curr_weight),Wp(target_weight))"
8349  }
8350  rChangeCurrRing(newRing);
8351  Gomega1 = idrMoveR(Gomega, baseRing,currRing);
8352  idDelete(&Gomega);
8353  // compute a Groebner basis of <Gomega> w.r.t. "newRing"
8354 #ifdef TIME_TEST
8355  to = clock();
8356 #endif
8357 #ifndef BUCHBERGER_ALG
8358  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
8359  delete hilb_func;
8360 #else
8361  M = kStd(Gomega1,NULL,testHomog,NULL,NULL,0,0,NULL);
8362 #endif
8363  idSkipZeroes(M);
8364 #ifdef TIME_TEST
8365  tstd = tstd + clock() - to;
8366 #endif
8367 #ifdef CHECK_IDEAL_MWALK
8368  idString(M, "M");
8369 #endif
8370  //change the ring to baseRing
8371  rChangeCurrRing(baseRing);
8372  M1 = idrMoveR(M, newRing,currRing);
8373  idDelete(&M);
8374  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
8375  idDelete(&Gomega1);
8376  to = clock();
8377  // compute a representation of the generators of submod (M) with respect to those of mod (Gomega), where Gomega is a reduced Groebner basis w.r.t. the current ring
8378  F = MLifttwoIdeal(Gomega2, M1, G);
8379  idSkipZeroes(F);
8380 #ifdef TIME_TEST
8381  tlift = tlift + clock() - to;
8382 #endif
8383 #ifdef CHECK_IDEAL_MWALK
8384  idString(F,"F");
8385 #endif
8386  rChangeCurrRing(newRing); // change the ring to newRing
8387  G = idrMoveR(F,baseRing,currRing);
8388  idDelete(&F);
8389  baseRing = currRing; // set baseRing equal to newRing
8390 #ifdef CHECK_IDEAL_MWALK
8391  idString(G,"G");
8392 #endif
8393 #ifdef TIME_TEST
8394  to = clock();
8395 #endif
8396  intvec* next_weight = MWalkRandomNextWeight(G, curr_weight, target_weight, weight_rad, op_deg);
8397 #ifdef TIME_TEST
8398  tnw = tnw + clock() - to;
8399 #endif
8400 #ifdef PRINT_VECTORS
8401  MivString(curr_weight, target_weight, next_weight);
8402 #endif
8403  if(Overflow_Error == TRUE)
8404  {
8405  PrintS("\n//**Mprwalk: OVERFLOW: The computed vector does not stay in cone, the result may be wrong.\n");
8406  delete next_weight;
8407  break;
8408  }
8409 
8410  if(test_w_in_ConeCC(G,target_weight) == 1 || MivComp(next_weight, ivNull) == 1)
8411  {
8412  delete next_weight;
8413  break;
8414  }
8415  //update tmp_weight and curr_weight
8416  for(i=nV-1; i>=0; i--)
8417  {
8418  (*tmp_weight)[i] = (*curr_weight)[i];
8419  (*curr_weight)[i] = (*next_weight)[i];
8420  }
8421  delete next_weight;
8422  } //end of while-loop
8423  Print("\n// Mprwalk took %d steps. Ring= %s;\n", nwalk, rString(currRing));
8424  idSkipZeroes(G);
8425  si_opt_1 = save1; //set original options, e. g. option(RedSB)
8426  baseRing = currRing;
8427  rChangeCurrRing(XXRing);
8428  ideal Res = idrMoveR(G,baseRing,currRing);
8429  delete tmp_weight;
8430  delete ivNull;
8431  delete exivlp;
8432 #ifndef BUCHBERGER_ALG
8433  delete last_omega;
8434 #endif
8435 #ifdef TIME_TEST
8436  TimeString(tinput, tostd, tif, tstd, tlift, tred, tnw, nstep);
8437 #endif
8438  return(Res);
8439 }
8440 
8441 /*******************************************************************
8442  * Implementation of the first alternative Groebner Walk Algorithm *
8443  *******************************************************************/
8444 ideal MAltwalk1(ideal Go, int op_deg, int tp_deg, intvec* curr_weight,
8445  intvec* target_weight)
8446 {
8447  Set_Error(FALSE );
8449 #ifdef TIME_TEST
8450  BOOLEAN nOverflow_Error = FALSE;
8451 #endif
8452  // Print("// pSetm_Error = (%d)", ErrorCheck());
8453 
8454  xtif=0; xtstd=0; xtlift=0; xtred=0; xtnw=0; xtextra=0;
8455  xftinput = clock();
8456  clock_t tostd, tproc;
8457 
8458  nstep = 0;
8459  int i, nV = currRing->N;
8460  int nwalk=0, endwalks=0;
8461  int op_tmp = op_deg;
8462  ideal Gomega, M, F, G, Gomega1, Gomega2, M1, F1;
8463  ring newRing, oldRing;
8464  intvec* next_weight;
8465  intvec* iv_M_dp;
8466  intvec* ivNull = new intvec(nV);
8467  intvec* iv_dp = MivUnit(nV);// define (1,1,...,1)
8468  intvec* exivlp = Mivlp(nV);
8469  //intvec* extra_curr_weight = new intvec(nV);
8470 #ifndef BUCHBERGER_ALG
8471  intvec* hilb_func;
8472 #endif
8473  intvec* cw_tmp = curr_weight;
8474 
8475  // to avoid (1,0,...,0) as the target vector
8476  intvec* last_omega = new intvec(nV);
8477  for(i=nV-1; i>0; i--)
8478  {
8479  (*last_omega)[i] = 1;
8480  }
8481  (*last_omega)[0] = 10000;
8482 
8483  ring XXRing = currRing;
8484 
8485  to=clock();
8486  /* compute a pertubed weight vector of the original weight vector.
8487  The perturbation degree is recursive decrease until that vector
8488  stays inn the correct cone. */
8489  while(1)
8490  {
8491  if(Overflow_Error == FALSE)
8492  {
8493  if(MivComp(curr_weight, iv_dp) == 1)
8494  {
8495  //rOrdStr(currRing) = "dp"
8496  if(op_tmp == op_deg)
8497  {
8498  G = MstdCC(Go);
8499  if(op_deg != 1)
8500  {
8501  iv_M_dp = MivMatrixOrderdp(nV);
8502  }
8503  }
8504  }
8505  }
8506  else
8507  {
8508  if(op_tmp == op_deg)
8509  {
8510  //rOrdStr(currRing) = (a(...),lp,C)
8511  if (rParameter(currRing) != NULL)
8512  {
8513  DefRingPar(cw_tmp);
8514  }
8515  else
8516  {
8517  rChangeCurrRing(VMrDefault(cw_tmp)); // Aenderung 16
8518  }
8519  G = idrMoveR(Go, XXRing,currRing);
8520  G = MstdCC(G);
8521  if(op_deg != 1)
8522  iv_M_dp = MivMatrixOrder(cw_tmp);
8523  }
8524  }
8526  if(op_deg != 1)
8527  {
8528  curr_weight = MPertVectors(G, iv_M_dp, op_deg);
8529  }
8530  else
8531  {
8532  curr_weight = cw_tmp;
8533  break;
8534  }
8535  if(Overflow_Error == FALSE)
8536  {
8537  break;
8538  }
8539  Overflow_Error = TRUE;
8540  op_deg --;
8541  }
8542  tostd=clock()-to;
8543 
8544  if(op_tmp != 1 )
8545  delete iv_M_dp;
8546  delete iv_dp;
8547 
8548  if(currRing->order[0] == ringorder_a)
8549  goto NEXT_VECTOR;
8550 
8551  while(1)
8552  {
8553  nwalk ++;
8554  nstep ++;
8555 
8556  to = clock();
8557  // compute an initial form ideal of <G> w.r.t. "curr_vector"
8558  Gomega = MwalkInitialForm(G, curr_weight);
8559  xtif=xtif+clock()-to;
8560 #if 0
8561  if(Overflow_Error == TRUE)
8562  {
8563  for(i=nV-1; i>=0; i--)
8564  (*curr_weight)[i] = (*extra_curr_weight)[i];
8565  delete extra_curr_weight;
8566 
8567  newRing = currRing;
8568  goto MSTD_ALT1;
8569  }
8570 #endif
8571 #ifndef BUCHBERGER_ALG
8572  if(isNolVector(curr_weight) == 0)
8573  {
8574  hilb_func = hFirstSeries(Gomega,NULL,NULL,curr_weight,currRing);
8575  }
8576  else
8577  {
8578  hilb_func = hFirstSeries(Gomega,NULL,NULL,last_omega,currRing);
8579  }
8580 #endif // BUCHBERGER_ALG
8581 
8582  oldRing = currRing;
8583 
8584  // define a new ring which ordering is "(a(curr_weight),lp)
8585  if (rParameter(currRing) != NULL)
8586  {
8587  DefRingPar(curr_weight);
8588  }
8589  else
8590  {
8591  rChangeCurrRing(VMrDefault(curr_weight)); // Aenderung 17
8592  }
8593  newRing = currRing;
8594  Gomega1 = idrMoveR(Gomega, oldRing,currRing);
8595 
8596  to=clock();
8597  // compute a reduced Groebner basis of <Gomega> w.r.t. "newRing"
8598 #ifdef BUCHBERGER_ALG
8599  M = MstdhomCC(Gomega1);
8600 #else
8601  M=kStd(Gomega1,NULL,isHomog,NULL,hilb_func,0,NULL,curr_weight);
8602  delete hilb_func;
8603 #endif // BUCHBERGER_ALG
8604  xtstd=xtstd+clock()-to;
8605 
8606  // change the ring to oldRing
8607  rChangeCurrRing(oldRing);
8608  M1 = idrMoveR(M, newRing,currRing);
8609  Gomega2 = idrMoveR(Gomega1, newRing,currRing);
8610 
8611  to=clock();
8612  // compute a reduced Groebner basis of <G> w.r.t. "newRing" by the lifting process
8613  F = MLifttwoIdeal(Gomega2, M1, G);
8614  xtlift=xtlift+clock()-to;
8615 
8616  idDelete(&M1);
8617  idDelete(&Gomega2);
8618  idDelete(&G);
8619 
8620  // change the ring to newRing
8621  rChangeCurrRing(newRing);
8622  F1 = idrMoveR(F, oldRing,currRing);
8623 
8624  to=clock();
8625  // reduce the Groebner basis <G> w.r.t. new ring
8626  G = kInterRedCC(F1, NULL);
8627  xtred=xtred+clock()-to;
8628  idDelete(&F1);
8629 
8630  if(endwalks == 1)
8631  {
8632  break;
8633  }
8634  NEXT_VECTOR:
8635  to=clock();
8636  // compute a next weight vector
8637  next_weight = MkInterRedNextWeight(curr_weight,target_weight, G);
8638  xtnw=xtnw+clock()-to;
8639 #ifdef PRINT_VECTORS
8640  MivString(curr_weight, target_weight, next_weight);
8641 #endif
8642 
8643  if(Overflow_Error == TRUE)
8644  {
8645  newRing = currRing;
8646 
8647  if (rParameter(currRing) != NULL)
8648  {
8649  DefRingPar(target_weight);
8650  }
8651  else
8652  {
8653  rChangeCurrRing(VMrDefault(target_weight)); // Aenderung 18
8654  }
8655  F1 = idrMoveR(G, newRing,currRing);
8656  G = MstdCC(F1);
8657  idDelete(&F1);
8658  newRing = currRing;
8659  break; //for while
8660  }
8661 
8662 
8663  /* G is the wanted Groebner basis if next_weight == curr_weight */
8664  if(MivComp(next_weight, ivNull) == 1)
8665  {
8666  newRing = currRing;
8667  delete next_weight;
8668  break; //for while
8669  }
8670 
8671  if(MivComp(next_weight, target_weight) == 1)
8672  {
8673  if(tp_deg == 1 || MivSame(target_weight, exivlp) == 0)
8674  endwalks = 1;
8675  else
8676  {
8677  // MSTD_ALT1:
8678 #ifdef TIME_TEST
8679  nOverflow_Error = Overflow_Error;
8680 #endif
8681  tproc = clock()-xftinput;
8682 
8683  //Print("\n// main routine takes %d steps and calls \"Mpwalk\" (1,%d):", nwalk, tp_deg);
8684 
8685  // compute the red. GB of <G> w.r.t. the lex order by the "recursive-modified" perturbation walk alg (1,tp_deg)
8686  G = Mpwalk_MAltwalk1(G, curr_weight, tp_deg);
8687  delete next_weight;
8688  break; // for while
8689  }
8690  }
8691 
8692  //NOT Changed, to free memory
8693  for(i=nV-1; i>=0; i--)
8694  {
8695  //(*extra_curr_weight)[i] = (*curr_weight)[i];
8696  (*curr_weight)[i] = (*next_weight)[i];
8697  }
8698  delete next_weight;
8699  }//while
8700 
8701  rChangeCurrRing(XXRing);
8702  ideal result = idrMoveR(G, newRing,currRing);
8703  id_Delete(&G, newRing);
8704 
8705  delete ivNull;
8706  if(op_deg != 1 )
8707  {
8708  delete curr_weight;
8709  }
8710  delete exivlp;
8711 #ifdef TIME_TEST
8712 
8713  Print("\n// \"Main procedure\" took %d steps, %.2f sec. and Overflow_Error(%d)",
8714  nwalk, ((double) tproc)/1000000, nOverflow_Error);
8715 
8716  TimeStringFractal(xftinput, tostd, xtif, xtstd,xtextra, xtlift, xtred, xtnw);
8717 
8718  Print("\n// pSetm_Error = (%d)", ErrorCheck());
8719  Print("\n// Overflow_Error? (%d)", Overflow_Error);
8720  Print("\n// Awalk1 took %d steps.\n", nstep);
8721 #endif
8722  return(result);
8723 }
static ideal MLifttwoIdeal(ideal Gw, ideal M, ideal G)
Definition: walk.cc:1736
#define OPT_REDSB
Definition: options.h:71
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
ideal Mfwalk(ideal G, intvec *ivstart, intvec *ivtarget)
Definition: walk.cc:6812
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
Definition: gb_hack.h:53
BOOLEAN ErrorCheck()
KINLINE TObject ** initR()
Definition: kInline.h:92
unsigned si_opt_1
Definition: options.c:5
char * pString(poly p)
Definition: polys.h:277
intvec * MivMatrixOrder(intvec *iv)
Definition: walk.cc:938
BOOLEAN honey
Definition: kutil.h:371
const poly a
Definition: syzextra.cc:212
void PrintLn()
Definition: reporter.cc:322
#define Print
Definition: emacs.cc:83
static int test_w_in_ConeCC(ideal G, intvec *iv)
Definition: walk.cc:760
static unsigned long * initsevS(int maxnr)
Definition: walk.cc:109
intvec * Mfpertvector(ideal G, intvec *ivtarget)
Definition: walk.cc:1492
KINLINE unsigned long * initsevT()
Definition: kInline.h:97
#define pAdd(p, q)
Definition: polys.h:174
intvec * Xivlp
Definition: walk.cc:4285
static ideal REC_GB_Mwalk(ideal G, intvec *curr_weight, intvec *orig_target_weight, int tp_deg, int npwinc)
Definition: walk.cc:4539
static long Mlcm(long &i1, long &i2)
Definition: walk.cc:810
static int MivComp(intvec *iva, intvec *ivb)
Definition: walk.cc:1813
poly kHEdge
Definition: kutil.h:327
#define pNSet(n)
Definition: polys.h:284
intvec * Xivinput
Definition: walk.cc:4284
int nnflow
Definition: walk.cc:6103
class sLObject LObject
Definition: kutil.h:58
Definition: lists.h:22
static ring VMrDefault1(intvec *va)
Definition: walk.cc:2428
KINLINE TSet initT()
Definition: kInline.h:81
int ngleich
Definition: walk.cc:4280
ideal kStd(ideal F, ideal Q, tHomog h, intvec **w, intvec *hilb, int syzComp, int newIdeal, intvec *vw)
Definition: kstd1.cc:2067
static int test_G_GB_walk(ideal H0, ideal H1)
Definition: walk.cc:3340
intvec * MMatrixone(int nV)
Definition: walk.cc:6091
int Xngleich
Definition: walk.cc:6105
#define FALSE
Definition: auxiliary.h:140
BOOLEAN noTailReduction
Definition: kutil.h:372
Compatiblity layer for legacy polynomial operations (over currRing)
int * S_2_R
Definition: kutil.h:342
static int MivAbsMax(intvec *vec)
Definition: walk.cc:1830
return P p
Definition: myNF.cc:203
intvec * MivWeightOrderlp(intvec *ivstart)
Definition: walk.cc:1416
f
Definition: cfModGcd.cc:4022
char * rString(ring r)
Definition: ring.cc:644
static ring VMatrDefault(intvec *va)
Definition: walk.cc:2586
void enterT(LObject p, kStrategy strat, int atT)
Definition: kutil.cc:7161
intvec * MivMatrixOrderRefine(intvec *iv, intvec *iw)
Definition: walk.cc:958
BOOLEAN * NotUsedAxis
Definition: kutil.h:332
static ideal LastGB(ideal G, intvec *curr_weight, int tp_deg)
Definition: walk.cc:2984
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
static poly MpolyInitialForm(poly g, intvec *curr_weight)
Definition: walk.cc:699
const ideal
Definition: gb_hack.h:42
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
void id_Delete(ideal *h, ring r)
clock_t xtred
Definition: walk.cc:98
intvec * ivCopy(const intvec *o)
Definition: intvec.h:132
poly kNoether
Definition: kutil.h:328
int tl
Definition: kutil.h:353
intvec * Xsigma
Definition: walk.cc:4281
Definition: ring.h:203
#define TRUE
Definition: auxiliary.h:144
void enterpairsSpecial(poly h, int k, int ecart, int pos, kStrategy strat, int atR=-1)
Definition: kutil.cc:3733
#define TEST_OPT_REDSB
Definition: options.h:99
int length() const
Definition: intvec.h:85
int Xnlev
Definition: walk.cc:1491
unsigned long * sevT
Definition: kutil.h:323
int MivSame(intvec *u, intvec *v)
Definition: walk.cc:868
void * ADDRESS
Definition: auxiliary.h:161
intvec * MivWeightOrderdp(intvec *ivstart)
Definition: walk.cc:1436
static int MLmWeightedDegree(const poly p, intvec *weight)
Definition: walk.cc:598
int ak
Definition: kutil.h:356
g
Definition: cfModGcd.cc:4031
void WerrorS(const char *s)
Definition: feFopen.cc:23
int k
Definition: cfEzgcd.cc:93
static intvec * MivSub(intvec *a, intvec *b)
Definition: walk.cc:836
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition: ring.h:564
#define Q
Definition: sirandom.c:25
intvec * Xtau
Definition: walk.cc:4282
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy ...
Definition: monomials.h:51
static ring VMatrRefine(intvec *va, intvec *vb)
Definition: walk.cc:2664
#define pEqualPolys(p1, p2)
Definition: polys.h:372
static TreeM * G
Definition: janet.cc:38
#define BITSET
Definition: structs.h:17
void Set_Error(BOOLEAN f)
Definition: walk.cc:94
#define omAlloc(size)
Definition: omAllocDecl.h:210
KINLINE poly redtailBba(poly p, int pos, kStrategy strat, BOOLEAN normalize)
Definition: kInline.h:1120
int xn
Definition: walk.cc:4283
#define Sy_bit(x)
Definition: options.h:30
int(* posInT)(const TSet T, const int tl, LObject &h)
Definition: kutil.h:280
ideal Mfrwalk(ideal G, intvec *ivstart, intvec *ivtarget, int weight_rad)
Definition: walk.cc:6938
BOOLEAN Overflow_Error
Definition: walk.cc:96
static void VMrDefaultlp(void)
Definition: walk.cc:2746
static int pLength(poly a)
Definition: p_polys.h:189
static long MivDotProduct(intvec *a, intvec *b)
Definition: walk.cc:820
int posInT0(const TSet, const int length, LObject &)
Definition: kutil.cc:3965
int Xcall
Definition: walk.cc:6104
static void cancel(mpz_t zaehler, mpz_t nenner)
Definition: walk.cc:565
intvec * MPertVectorslp(ideal G, intvec *ivtarget, int pdeg)
Definition: walk.cc:1279
clock_t xftostd
Definition: walk.cc:99
static poly redBba(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:6631
void * data
Definition: subexpr.h:89
#define pIter(p)
Definition: monomials.h:44
poly res
Definition: myNF.cc:322
#define M
Definition: sirandom.c:24
void(* initEcart)(TObject *L)
Definition: kutil.h:279
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
char * char_ptr
Definition: structs.h:56
#define pGetExp(p, i)
Exponent.
Definition: polys.h:41
void initS(ideal F, ideal Q, kStrategy strat)
Definition: kutil.cc:5733
static int rBlocks(ring r)
Definition: ring.h:507
clock_t to
Definition: walk.cc:99
fq_nmod_poly_t * vec
Definition: facHensel.cc:103
const ring r
Definition: syzextra.cc:208
#define SI_RESTORE_OPT(A, B)
Definition: options.h:22
Coefficient rings, fields and other domains suitable for Singular polynomials.
ideal MAltwalk1(ideal Go, int op_deg, int tp_deg, intvec *curr_weight, intvec *target_weight)
Definition: walk.cc:8444
BOOLEAN RingDependend()
Definition: subexpr.cc:369
#define TEST_OPT_INTSTRATEGY
Definition: options.h:105
Definition: intvec.h:16
#define pSub(a, b)
Definition: polys.h:258
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
#define setmaxT
Definition: kutil.h:30
static int islengthpoly2(ideal G)
Definition: walk.cc:3285
static void VMrHomogeneous(intvec *va, intvec *vb)
Definition: walk.cc:2276
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
Definition: ring.cc:3371
#define OPT_REDTAIL
Definition: options.h:86
int j
Definition: myNF.cc:70
static int max(int a, int b)
Definition: fast_mult.cc:264
ideal Mprwalk(ideal Go, intvec *curr_weight, intvec *target_weight, int weight_rad, int op_deg, int tp_deg, ring baseRing)
Definition: walk.cc:8244
#define omFree(addr)
Definition: omAllocDecl.h:261
polyrec * poly
Definition: hilb.h:10
#define assume(x)
Definition: mod2.h:405
intset fromQ
Definition: kutil.h:319
static ideal idHeadCC(ideal h)
Definition: walk.cc:3321
#define A
Definition: sirandom.c:23
#define pGetShortExpVector(a)
returns the "Short Exponent Vector" – used to speed up divisibility tests (see polys-impl.cc )
Definition: polys.h:140
int M3ivSame(intvec *temp, intvec *u, intvec *v)
Definition: walk.cc:889
ideal Mrwalk(ideal Go, intvec *orig_M, intvec *target_M, int weight_rad, int pert_deg, ring baseRing)
Definition: walk.cc:5339
#define omfree(addr)
Definition: omAllocDecl.h:237
ideal Mpwalk(ideal Go, int op_deg, int tp_deg, intvec *curr_weight, intvec *target_weight, int nP)
Definition: walk.cc:5750
gmp_float sqrt(const gmp_float &a)
Definition: mpr_complex.cc:329
ideal idrMoveR(ideal &id, ring src_r, ring dest_r)
Definition: prCopy.cc:248
clock_t xftinput
Definition: walk.cc:99
omBin sip_sring_bin
Definition: ring.cc:54
int m
Definition: cfEzgcd.cc:119
void idDelete(ideal *h, ring r=currRing)
delete an ideal
Definition: ideals.h:31
static intvec * MwalkNextWeightCC(intvec *curr_weight, intvec *target_weight, ideal G)
Definition: walk.cc:1865
void initBuchMoraCrit(kStrategy strat)
Definition: kutil.cc:7325
static intvec * NewVectorlp(ideal I)
Definition: walk.cc:4271
static ideal Mpwalk_MAltwalk1(ideal Go, intvec *curr_weight, int tp_deg)
Definition: walk.cc:7988
int i
Definition: cfEzgcd.cc:123
void PrintS(const char *s)
Definition: reporter.cc:294
clock_t xtstd
Definition: walk.cc:98
void deleteHC(LObject *L, kStrategy strat, BOOLEAN fromNext)
Definition: kutil.cc:235
TObject ** R
Definition: kutil.h:340
static ideal Rec_LastGB(ideal G, intvec *curr_weight, intvec *orig_target_weight, int tp_deg, int npwinc)
Definition: walk.cc:3759
clock_t xtnw
Definition: walk.cc:98
intvec * MPertVectors(ideal G, intvec *ivtarget, int pdeg)
Definition: walk.cc:1061
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL ...
Definition: polys.h:67
polyset S
Definition: kutil.h:304
#define IDELEMS(i)
Definition: simpleideals.h:19
static void MLmWeightedDegree_gmp(mpz_t result, const poly p, intvec *weight)
Definition: walk.cc:667
void idSkipZeroes(ideal ide)
static ideal MstdhomCC(ideal G)
Definition: walk.cc:922
int tmax
Definition: kutil.h:353
#define rHasLocalOrMixedOrdering_currRing()
Definition: ring.h:748
intvec * Mivdp(int nR)
Definition: walk.cc:980
void rChangeCurrRing(ring r)
Definition: polys.cc:14
static void DefRingParlp(void)
Definition: walk.cc:2879
static int isNolVector(intvec *hilb)
Definition: walk.cc:2961
kStrategy strat
Definition: myNF.cc:319
#define omAlloc0Bin(bin)
Definition: omAllocDecl.h:206
BOOLEAN kHEdgeFound
Definition: kutil.h:370
intset ecartS
Definition: kutil.h:307
ideal idInit(int idsize, int rank)
Definition: simpleideals.cc:40
static ideal MstdCC(ideal G)
Definition: walk.cc:907
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
static ideal rec_r_fractal_call(ideal G, int nlev, intvec *omtmp, int weight_rad)
Definition: walk.cc:6456
static long gcd(const long a, const long b)
Definition: walk.cc:541
int nstep
kstd2.cc
Definition: walk.cc:88
static int lengthpoly(ideal G)
Definition: walk.cc:3257
static intvec * MExpPol(poly f)
Definition: walk.cc:852
#define NULL
Definition: omList.c:10
static void DefRingPar(intvec *va)
Definition: walk.cc:2809
ideal idVec2Ideal(poly vec, const ring R=currRing)
Definition: ideals.h:172
BOOLEAN rHasGlobalOrdering(const ring r)
Definition: ring.h:741
ideal TranMImprovwalk(ideal G, intvec *curr_weight, intvec *target_tmp, int nP)
Definition: walk.cc:7069
#define pMult(p, q)
Definition: polys.h:178
b *CanonicalForm B
Definition: facBivar.cc:51
static ideal kInterRedCC(ideal F, ideal Q)
Definition: walk.cc:275
static ideal MidMult(ideal A, ideal B)
Definition: walk.cc:1698
static int MwalkWeightDegree(poly p, intvec *weight_vector)
Definition: walk.cc:645
ideal id_Head(ideal h, const ring r)
int posInS(const kStrategy strat, const int length, const poly p, const int ecart_p)
Definition: kutil.cc:3860
#define pDelete(p_ptr)
Definition: polys.h:157
static void MivString(intvec *iva, intvec *ivb, intvec *ivc)
Definition: walk.cc:514
static ideal rec_fractal_call(ideal G, int nlev, intvec *omtmp)
Definition: walk.cc:6110
void updateS(BOOLEAN toT, kStrategy strat)
Definition: kutil.cc:6695
intvec * MivMatrixOrderdp(int nV)
Definition: walk.cc:1397
unsigned long * sevS
Definition: kutil.h:320
int rtyp
Definition: subexpr.h:92
#define SI_SAVE_OPT(A, B)
Definition: options.h:19
#define nCopy(n)
Definition: numbers.h:15
sleftv sLastPrinted
Definition: subexpr.cc:55
clock_t xtlift
Definition: walk.cc:98
void CleanUp(ring r=currRing)
Definition: subexpr.cc:301
void completeReduce(kStrategy strat, BOOLEAN withT)
Definition: kutil.cc:7991
#define setmaxTinc
Definition: kutil.h:31
ideal MAltwalk2(ideal Go, intvec *curr_weight, intvec *target_weight)
Definition: walk.cc:4075
ideal idLift(ideal mod, ideal submod, ideal *rest, BOOLEAN goodShape, BOOLEAN isSB, BOOLEAN divide, matrix *unit)
Definition: ideals.cc:933
static void p_Setm(poly p, const ring r)
Definition: p_polys.h:436
int * intset
Definition: kutil.h:53
Definition: tok.h:96
int sl
Definition: kutil.h:351
ideal idCopy(ideal A, const ring R=currRing)
Definition: ideals.h:76
intvec * MivUnit(int nV)
Definition: walk.cc:1476
static intset initec(int maxnr)
Definition: walk.cc:104
TSet T
Definition: kutil.h:324
static poly redMora(poly h, int maxIndex, kStrategy strat)
Definition: kutil.cc:6654
void initEcartNormal(TObject *h)
Definition: kutil.cc:1125
intvec * hFirstSeries(ideal S, intvec *modulweight, ideal Q, intvec *wdegree, ring tailRing)
Definition: hilb.cc:1300
void enterSBba(LObject p, int atS, kStrategy strat, int atR)
Definition: kutil.cc:6927
kBucketDestroy & P
Definition: myNF.cc:191
ideal Mwalk(ideal Go, intvec *orig_M, intvec *target_M, ring baseRing)
Definition: walk.cc:5065
ideal MwalkAlt(ideal Go, intvec *curr_weight, intvec *target_weight)
Definition: walk.cc:4823
static void ivString(intvec *iv, const char *ch)
Definition: walk.cc:500
ideal Shdl
Definition: kutil.h:301
ideal MwalkInitialForm(ideal G, intvec *ivw)
Definition: walk.cc:736
void(* enterS)(LObject h, int pos, kStrategy strat, int atR)
Definition: kutil.h:285
int * int_ptr
Definition: structs.h:57
static Poly * h
Definition: janet.cc:978
static ring VMrRefine(intvec *va, intvec *vb)
Definition: walk.cc:2503
int BOOLEAN
Definition: auxiliary.h:131
const poly b
Definition: syzextra.cc:213
clock_t xtextra
Definition: walk.cc:99
BOOLEAN lRingDependend(lists L)
Definition: lists.cc:199
intvec * XivNull
Definition: walk.cc:6088
#define pLmEqual(p1, p2)
Definition: polys.h:111
intvec * MivMatrixOrderlp(int nV)
Definition: walk.cc:1381
#define omAlloc0(size)
Definition: omAllocDecl.h:211
return result
Definition: facAbsBiFact.cc:76
intvec * Mivlp(int nR)
Definition: walk.cc:995
class sTObject TObject
Definition: kutil.h:57
static intvec * MWalkRandomNextWeight(ideal G, intvec *curr_weight, intvec *target_weight, int weight_rad, int pert_deg)
Definition: walk.cc:4406
static ring VMrDefault(intvec *va)
Definition: walk.cc:2358
BOOLEAN pSetm_error
Definition: p_polys.cc:155
#define nGreater(a, b)
Definition: numbers.h:28
#define pCopy(p)
return a copy of the poly
Definition: polys.h:156
clock_t xtif
Definition: walk.cc:98
intvec * MkInterRedNextWeight(intvec *iva, intvec *ivb, ideal G)
Definition: walk.cc:2248
static int * initS_2_R(int maxnr)
Definition: walk.cc:113
#define omStrDup(s)
Definition: omAllocDecl.h:263