source: git/kernel/walkMain.cc @ 6a9f2e

fieker-DuValspielwiese
Last change on this file since 6a9f2e was 762407, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
config.h is for sources files only FIX: config.h should only be used by source (not from inside kernel/mod2.h!) NOTE: each source file should better include mod2.h right after config.h, while headers should better not include mod2.h.
  • Property mode set to 100644
File size: 17.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5/*
6 * ABSTRACT: fractal walk stuff
7 *
8*/
9#include <string.h>
10#include "config.h"
11#include <kernel/mod2.h>
12#include <misc/options.h>
13#include <misc/intvec.h>
14#include <misc/int64vec.h>
15#include <kernel/polys.h>
16#include <kernel/ideals.h>
17#include <polys/monomials/ring.h>
18#include <kernel/walkMain.h>
19#include <kernel/walkSupport.h>
20#include <polys/prCopy.h>
21#include <kernel/kstd1.h>
22#include <polys/matpol.h>
23#include <polys/monomials/ring.h>
24
25
26///////////////////////////////////////////////////////////////////
27//Groebner Walk and Fractal Walk
28///////////////////////////////////////////////////////////////////
29//v1.3 2004-11-15
30///////////////////////////////////////////////////////////////////
31//implemented by Henrik Strohmayer
32///////////////////////////////////////////////////////////////////
33//in C++:
34///////////////////////////////////////////////////////////////////
35
36
37int overflow_error; //global variable
38
39/*
40overflow_error table
41 1: Miv64DotProduct mult
42 2: Miv64DotProduct add
43 3: gett64 zaehler mult
44 4: gett64 zaehler add
45 5: gett64 nenner mult
46 6: gett64 nenner add
47 7: nextw64 mult a
48 8: nextw64 mult b
49 9: nextw64 add
5010: getinveps64 mult
5111: getinveps64 add
5212: getTaun64 mult
5313: getTaun64 add
54*/
55
56///////////////////////////////////////////////////////////////////
57//fistWalkStep64
58///////////////////////////////////////////////////////////////////
59//Description: adapts currRing for the algorithm and moves G into
60//it, calculating the appropriate GB if currw not is inside of
61//the current groebner cone
62///////////////////////////////////////////////////////////////////
63//Assumes: that the option redSB is turned off
64///////////////////////////////////////////////////////////////////
65//Uses: init64, rCopy0AndAddA, rComplete, rChangeCurrRing, matIdLift,
66//mpMult, idInterRed, idStd, idCopy, idrMoveR,currwOnBorder64
67///////////////////////////////////////////////////////////////////
68
69WalkState firstWalkStep64(ideal & G,int64vec* currw64, ring destRing){
70  WalkState state=WalkOk;
71  /* OLDRING **************************************************** */
72  ideal nextG;
73  BITSET optionState;
74
75  if (currwOnBorder64(G,currw64))
76  {
77    ideal Gw=init64(G,currw64);
78    ring oldRing=currRing;
79  /* NEWRING **************************************************** */
80    ring rnew=rCopy0AndAddA(destRing,currw64);
81    rComplete(rnew);
82    rChangeCurrRing(rnew);
83
84    ideal newGw=idrMoveR(Gw, oldRing, rnew);
85
86
87 //HIER GEANDERT
88  matrix L=mpNew(1,1);
89  idLiftStd(newGw,&L);
90
91//       //turn off bucket representation of polynomials and on redSB
92//     optionState=test;
93//     //test|=Sy_bit(OPT_NOT_BUCKETS);
94//     test|=Sy_bit(OPT_REDSB);
95
96//     ideal newStdGw=idStd(newGw);
97
98//    //turn on bucket representation of polynomials and off redSB
99//    test=optionState;
100
101//     matrix L=matIdLift(newGw,newStdGw);
102//     idDelete(&newStdGw);
103
104    idDelete(&newGw);
105
106    nextG=idrMoveR(G,oldRing, rnew); idTest(nextG);
107
108    matrix nextGmat=(matrix)nextG;
109
110    matrix resMat=mp_Mult(nextGmat,L,rnew);
111    idDelete((ideal *)&nextGmat);
112    idDelete((ideal *)&L);
113
114    nextG=(ideal)resMat;
115
116    optionState=test;
117    test|=Sy_bit(OPT_REDSB);
118    nextG = idInterRed(nextG);
119    test=optionState;
120  }
121  else
122  {
123    ring oldRing=currRing;
124    ring rnew=rCopy0AndAddA(destRing,currw64);
125    rComplete(rnew);
126    rChangeCurrRing(rnew);
127    nextG=idrMoveR(G,oldRing, rnew);
128  }
129
130  G=nextG;
131  return(state);
132}
133
134///////////////////////////////////////////////////////////////////
135
136
137///////////////////////////////////////////////////////////////////
138//walkStep64
139///////////////////////////////////////////////////////////////////
140//Description: one step in the groebner walk
141///////////////////////////////////////////////////////////////////
142//Assumes: that the option redSB is turned off
143///////////////////////////////////////////////////////////////////
144//Uses: init, rCopyAndChangeA, matIdLift, mpMult,
145//idInterRed, mStd, idCopy, idrMoveR
146///////////////////////////////////////////////////////////////////
147
148WalkState walkStep64(ideal & G,int64vec* currw64, int step){
149  WalkState state=WalkOk;
150  BITSET optionState;
151
152/* OLDRING ****************************************************** */
153  ideal Gw=init64(G,currw64);
154
155  ring oldRing=currRing;
156
157/* NEWRING ****************************************************** */
158  rCopyAndChangeA(currw64);
159
160  ideal newGw=idrMoveR(Gw, oldRing,currRing);
161
162  //HIER GEANDERT
163  matrix L=mpNew(1,1);
164  ideal newStdGw=idLiftStd(newGw,&L);
165
166//what it looked like before idStd and idLift were replaced
167//by idLiftStd
168//   optionState=test;
169//   test|=Sy_bit(OPT_REDSB);
170//   test|=Sy_bit(OPT_NOT_BUCKETS);
171
172//   //PrintS("  new initial forms:\n");
173//   for (int ii=0; ii <IDELEMS(newGw); ii++) pCleardenom(newGw->m[ii]);
174//   //idShow(newGw);
175//   ideal newStdGw=idStd(newGw);
176//     PrintS("  std for initial forms done\n");
177
178//   test=optionState;
179
180//  matrix L=matIdLift(newGw,newStdGw);
181
182//  idDelete(&newStdGw);
183
184  idDelete(&newGw);
185    //PrintS("  lift for initial forms done\n");
186
187  ideal nextG=idrMoveR(G,oldRing,currRing);
188  rDelete(oldRing);
189
190  matrix nextGmat=(matrix)nextG;
191
192  matrix resMat=mp_Mult(nextGmat,L,currRing);
193  idDelete((ideal *)&nextGmat);
194  idDelete((ideal *)&L);
195    //PrintS("  lift done\n");
196
197  nextG=(ideal)resMat;
198
199  optionState=test;
200  test|=Sy_bit(OPT_REDSB);
201  nextG = idInterRed(nextG);
202  test=optionState;
203
204  G=nextG;
205  return(state);
206}
207
208///////////////////////////////////////////////////////////////////
209
210
211///////////////////////////////////////////////////////////////////
212//walk64
213///////////////////////////////////////////////////////////////////
214//Description: the main function of groebner walk, keeping
215//everything together
216///////////////////////////////////////////////////////////////////
217//Uses: mStd, getnthrow, firstwalkStep64, nextt64,
218//nextw64, walkStep64, changecurrRing
219///////////////////////////////////////////////////////////////////
220
221WalkState walk64(ideal I,int64vec* currw64,ring destRing,
222int64vec* destVec64,ideal  & destIdeal,BOOLEAN sourceIsSB){
223
224  //some initializations
225  WalkState state=WalkOk;
226  BITSET optionState;
227  test|=Sy_bit(OPT_REDTAIL);
228  overflow_error=FALSE;
229  int step=0;
230  ideal G=I;
231
232  optionState=test;
233  test|=Sy_bit(OPT_REDSB);
234  if(!sourceIsSB)
235  {
236    ideal GG=idStd(G);
237    idDelete(&G); G=GG;
238  }
239  else
240    G=idInterRed(G);
241  test=optionState;
242
243  ideal nextG;
244  state=firstWalkStep64(G,currw64,destRing);
245  nextG=G;
246
247  if(overflow_error){
248      state=WalkOverFlowError;
249    return(state);
250    }
251
252   int64 nexttvec0,nexttvec1;
253   //int64vec* nexttvec64=nextt64(nextG,currw64,destVec64);
254   nextt64(nextG,currw64,destVec64,nexttvec0,nexttvec1);
255
256  //while(0<t<=1) ( t=((*nexttvec64)[0])/((*nexttvec64)[1]) )
257  //while( (*nexttvec64)[0]<=(*nexttvec64)[1] ) {
258  while (nexttvec0<=nexttvec1 ) {
259
260    step=step+1;
261
262    //int64vec *tt=nextw64(currw64,destVec64,nexttvec64);
263    int64vec *tt=nextw64(currw64,destVec64,nexttvec0,nexttvec1);
264    delete currw64; currw64=tt; tt=NULL;
265
266    if (TEST_OPT_PROT)
267    {
268      PrintS("walk step:"); currw64->show(); PrintLn();
269    }
270
271    state=walkStep64(nextG,currw64,step);
272    //uppdates nextG if all is OK
273
274    if(overflow_error){
275      return(WalkOverFlowError);
276    }
277
278    //delete nexttvec64;
279    //nexttvec64=nextt64(nextG,currw64,destVec64);
280    nextt64(nextG,currw64,destVec64,nexttvec0,nexttvec1);
281
282  }
283
284  destIdeal=sortRedSB(nextG);
285  return(state);
286}
287
288///////////////////////////////////////////////////////////////////
289
290
291
292///////////////////////////////////////////////////////////////////
293//FRACTAL WALK PART BEGINS HERE
294///////////////////////////////////////////////////////////////////
295
296///////////////////////////////////////////////////////////////////
297//firstFractalWalkStep64
298///////////////////////////////////////////////////////////////////
299//Description: called once before fractalRec64 is called, to set up
300//the ring and move G into it, has two different strategies
301///////////////////////////////////////////////////////////////////
302//Uses: firstWalkStep64,currwOnBorder64,getTaun64,rCopy0AndAddA,
303//getiv64,iv64Size,rComplete,rChangeCurrRing,idrMoveR,idStd,matIdLift
304///////////////////////////////////////////////////////////////////
305
306
307//unperturbedStartVectorStrategy IS NOW NOT ALLWAYS AS DEFAULT SET
308//TO TRUE BUT IS INPUT FROM fractalWalk64
309WalkState firstFractalWalkStep64(ideal & G,int64vec* & currw64,
310intvec* currMat, ring destRing,
311BOOLEAN unperturbedStartVectorStrategy){
312
313    //This strategy Uses the ordinary walk for the first step
314    if(unperturbedStartVectorStrategy){
315      return(unperturbedFirstStep64(G,currw64,destRing));
316    //here G is updated since its adress is given as argument
317    }
318
319    //This strategy makes sure that the start vector lies inside the start cone
320    //thus no step is needed within the start cone.
321    else{
322      if(currwOnBorder64(G,currw64))
323      {
324        int64 dummy64;
325        getTaun64(G,currMat,iv64Size(currw64),&currw64,dummy64);
326        //currw64=getiv64(getTaun64(G,currMat,iv64Size(currw64)));
327      }
328      ring oldRing=currRing;
329      ring newRing=rCopy0AndAddA(destRing,currw64);
330      rComplete(newRing);
331      rChangeCurrRing(newRing);
332      G=idrMoveR(G,oldRing,newRing);
333    }
334
335  return(WalkOk);
336}
337
338///////////////////////////////////////////////////////////////////
339
340
341
342//DIESE FUNKTION ERSETZT firstWalkStep FUR fractalWalk
343///////////////////////////////////////////////////////////////////
344//unperturbedFirstStep64
345///////////////////////////////////////////////////////////////////
346//Description: adapts currRing for the algorithm and moves G into
347//it, calculating the appropriate GB if currw not is inside of
348//the current groebner cone
349///////////////////////////////////////////////////////////////////
350//Assumes: that the option redSB is turned off
351///////////////////////////////////////////////////////////////////
352//Uses: init64, rCopy0AndAddA, rComplete, rChangeCurrRing, matIdLift,
353//mpMult, idInterRed, idStd, idCopy, idrMoveR,currwOnBorder64
354///////////////////////////////////////////////////////////////////
355
356WalkState unperturbedFirstStep64(ideal & G,int64vec* currw64, ring destRing){
357  WalkState state=WalkOk;
358  /* OLDRING **************************************************** */
359  ideal nextG;
360  BITSET optionState;
361
362  if (currwOnBorder64(G,currw64))
363  {
364    ideal Gw=init64(G,currw64);
365    ring oldRing=currRing;
366  /* NEWRING **************************************************** */
367    ring rnew=rCopy0AndAddA(destRing,currw64);
368    rComplete(rnew);
369    rChangeCurrRing(rnew);
370
371    ideal newGw=idrMoveR(Gw, oldRing,rnew);
372
373      //turn off bucket representation of polynomials and on redSB
374    optionState=test;
375    //test|=Sy_bit(OPT_NOT_BUCKETS);
376    test|=Sy_bit(OPT_REDSB);
377
378    ideal newStdGw=idStd(newGw);
379
380   //turn on bucket representation of polynomials and off redSB
381   test=optionState;
382
383    matrix L=matIdLift(newGw,newStdGw);
384    idDelete(&newStdGw);
385    idDelete(&newGw);
386
387    nextG=idrMoveR(G,oldRing,rnew); idTest(nextG);
388
389    matrix nextGmat=(matrix)nextG;
390
391    matrix resMat=mp_Mult(nextGmat,L,rnew);
392    idDelete((ideal *)&nextGmat);
393    idDelete((ideal *)&L);
394
395    nextG=(ideal)resMat;
396
397    optionState=test;
398    test|=Sy_bit(OPT_REDSB);
399    nextG = idInterRed(nextG);
400    test=optionState;
401  }
402  else
403  {
404    ring oldRing=currRing;
405    ring rnew=rCopy0AndAddA(destRing,currw64);
406    rComplete(rnew);
407    rChangeCurrRing(rnew);
408    nextG=idrMoveR(G,oldRing,rnew);
409  }
410
411  G=nextG;
412  return(state);
413}
414
415///////////////////////////////////////////////////////////////////
416
417
418
419///////////////////////////////////////////////////////////////////
420//fractalRec64
421///////////////////////////////////////////////////////////////////
422//Description: the recursion function used in fractalWalk64
423//(see appropriate par of thesis for more details)
424///////////////////////////////////////////////////////////////////
425//Assumes: that the option redSB is turned off
426///////////////////////////////////////////////////////////////////
427//Uses: getTaun64,getint64,getiv64,invEpsOk64,nextt64,nextw64,
428//init64,idCopy,noPolysOfMoreThanTwoTerms,rCopy0,rComplete,
429//rChangeCurrRing,rSetWeightVec,idrMoveR,mpMult,idInterRed
430///////////////////////////////////////////////////////////////////
431
432WalkState fractalRec64(ideal  & G,int64vec* currw64, intvec* destMat,
433                       int level,int step)
434{
435
436if (TEST_OPT_PROT)
437{  PrintS("fractal walk, weights");currw64->show();PrintLn(); }
438WalkState state=WalkOk;
439BITSET optionState=test;
440
441//1
442int64vec* w=(currw64);
443int64vec* old_w=(currw64);
444int64vec* sigma=(currw64);
445
446//lists taunpair64=getTaun64(G,destMat,level);
447//int64vec* w2=getiv64(taunpair64);
448//int64 inveps64=getint64(taunpair64);
449int64vec* w2;
450int64 inveps64;
451getTaun64(G,destMat,level,&w2,inveps64);
452
453//2
454while(1){
455
456  //int64vec* tvec64=nextt64(G,w,w2);
457  int64 tvec0,tvec1;
458  nextt64(G,w,w2,tvec0,tvec1);
459
460  if(overflow_error){
461    return WalkOverFlowError;
462  }
463
464  //tvec[1]>tvec[2] iff t>1 or t ist undefined i.e.is (2,0)
465  //if ((*tvec64)[0]>(*tvec64)[1])
466  if (tvec0>tvec1)
467  {
468    if(invEpsOk64(G,destMat,level,inveps64)) {
469      return(state);
470  }
471  else
472  {
473      //taunpair64=getTaun64(G,destMat,level);
474      //w2=getiv64(taunpair64);
475      //inveps64=getint64(taunpair64);
476      delete w2;
477      getTaun64(G,destMat,level,&w2,inveps64);
478
479      //tvec64=nextt64(G,w,w2);
480      nextt64(G,w,w2,tvec0,tvec1);
481
482      if(overflow_error){
483        return WalkOverFlowError;
484      }
485
486      //if((*tvec64)[0]>(*tvec64)[1])
487      if(tvec0>tvec1)
488      {
489        return(state);
490      }
491    }
492  }
493
494  //i.e. t=1 and we have reached the target vector
495  //if( ((*tvec64)[0]==(*tvec64)[1]) && (level!=iv64Size(w)) )
496  if( (tvec0==tvec1) && (level!=iv64Size(w)) )
497  {
498    state=fractalRec64(G,old_w,destMat,level+1,step);
499    return(state);
500  }
501  else
502  {
503    w=nextw64(w,w2,tvec0,tvec1);
504
505//3
506    ideal Gw=init64(G,w);  //finding initial ideal for new w
507
508    ring oldRing=currRing;
509
510    ideal GwCp=idCopy(Gw);
511    ideal GCp=idCopy(G);
512
513    ideal newGw;
514    ideal newStdGw;
515    ideal newG;
516
517//4
518    if ( level==iv64Size(w) || noPolysWithMoreThanTwoTerms(Gw) ){
519
520//5
521/*NEWRING**********************************************************/
522
523      //this assumes order has A-vector as first vector
524      ring newring=rCopy0(currRing);
525      rComplete(newring);
526      rSetWeightVec(newring,w->iv64GetVec());
527      rChangeCurrRing(newring);
528      //rSetWeightVec(newring,w->iv64GetVec());
529      //rComplete(newring,1);
530
531      newGw=idrMoveR(GwCp,oldRing,newring);
532
533      test|=Sy_bit(OPT_REDSB);
534      newStdGw=idStd(newGw); //computes new reduced GB of Gw
535      test=optionState;
536    }
537    else
538    {
539//7
540/*THE RING FROM THE RECURSION STEP BELOW***************************/
541      //Here we can choose whether to call fractalrec with old_w,
542      //which is the last w from the top level, or with sigma,
543      //the original start vector. The impact on the algorithm is not obvious.
544
545      state=fractalRec64(Gw,sigma,destMat,level+1,step);
546
547      //The resulting GB is Gw since its adress is given as argument.
548      ideal recG=Gw;
549      ring temp=currRing;
550
551/*NEWRING**********************************************************/
552
553      //this assumes order has A-vector as first vector
554      ring newring=rCopy0(currRing);
555      rComplete(newring);
556      rChangeCurrRing(newring);
557      rSetWeightVec(currRing,w->iv64GetVec());
558      rComplete(newring,1);
559
560      newGw=idrMoveR(GwCp,oldRing,newring);
561
562      newStdGw=idrMoveR(recG,temp,newring);
563    }
564
565//8
566    //lifting comes either after level=nvars(ring), after Gw has
567    //no poly with more than two terms or after
568    //fractalRec64(Gw,level+1) has returned
569
570    //test|=Sy_bit(OPT_NOT_BUCKETS);
571    matrix L=matIdLift(newGw,newStdGw);
572    test=optionState;
573
574    newG=idrMoveR(GCp,oldRing,currRing);
575    matrix MG=(matrix)newG;
576
577    matrix resMat=mp_Mult(MG,L,currRing);
578    idDelete((ideal *)&MG);
579    idDelete((ideal *)&L);
580    G=(ideal)resMat;
581
582//9
583
584    test|=Sy_bit(OPT_REDSB);
585    G=idInterRed(G);
586    test=optionState;
587
588    old_w=iv64Copy(w);
589    if(level==1) step=step+1;
590
591  }
592
593}
594}
595
596
597///////////////////////////////////////////////////////////////////
598
599
600//ANOTHER INPUT-VARIABLE ADDED: unperturbedStartVectorStrategy
601//THIS SHOULD BE SET IN walkProc.cc BY THE USER
602///////////////////////////////////////////////////////////////////
603//fractalWalk64
604///////////////////////////////////////////////////////////////////
605//Description:
606///////////////////////////////////////////////////////////////////
607//Uses:fractalRec64,firstFractalWalkStep64,idStd,idInterRed,
608//int64VecToIntVec,getNthRow,sortRedSB
609///////////////////////////////////////////////////////////////////
610
611WalkState fractalWalk64(ideal sourceIdeal,ring destRing,
612ideal & destIdeal,BOOLEAN sourceIsSB,
613BOOLEAN unperturbedStartVectorStrategy)
614{
615
616  overflow_error=FALSE; //global
617  WalkState state=WalkOk;
618  test|=Sy_bit(OPT_REDTAIL);
619  ideal G;
620
621  BITSET optionState=test;
622  test|=Sy_bit(OPT_REDSB);
623  if(!sourceIsSB)
624  {
625    G=idStd(sourceIdeal);
626  }
627
628  else
629  {
630    G=idInterRed(idCopy(sourceIdeal));
631  }
632
633  test=optionState; //switches REDSB off
634
635  //matrices for the orders of the rings
636  intvec *destMat=int64VecToIntVec(rGetGlobalOrderMatrix(destRing));
637  intvec *currMat=int64VecToIntVec(rGetGlobalOrderMatrix(currRing));
638
639  int64vec* currw64=getNthRow64(currMat,1); //start vector
640
641  state=firstFractalWalkStep64(G,currw64,currMat,destRing,
642                               unperturbedStartVectorStrategy);
643  delete currMat;
644
645  state=fractalRec64(G,currw64,destMat,1,1);
646  if(state==WalkOk)
647    destIdeal=G;
648
649  if(overflow_error)
650    state=WalkOverFlowError;
651
652  delete currw64;
653  delete destMat;
654  return state;
655}
656
657
658/////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.