walk_ip.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 /*
5 * ABSTRACT: frwalk: interpreter link
6 */
7 
8 #include <kernel/mod2.h>
9 #include <Singular/tok.h>
10 #include <misc/options.h>
11 #include <Singular/ipid.h>
12 #include <misc/intvec.h>
13 #include <omalloc/omalloc.h>
14 #include <kernel/polys.h>
15 #include <kernel/ideals.h>
16 #include <polys/matpol.h>
17 #include <kernel/GBEngine/kstd1.h>
18 #include <polys/monomials/ring.h>
19 #include <Singular/subexpr.h>
20 #include <polys/monomials/maps.h>
21 #include <kernel/GBEngine/syz.h>
22 #include <coeffs/numbers.h>
23 #include <Singular/lists.h>
24 #include <Singular/attrib.h>
25 #include <Singular/ipconv.h>
26 #include <Singular/links/silink.h>
28 #include <polys/weight.h>
29 #include <kernel/spectrum/semic.h>
30 #include <kernel/spectrum/splist.h>
32 //#include <kernel/gnumpfl.h>
33 //#include <kernel/mpr_base.h>
34 //#include <kernel/ffields.h>
35 #include <polys/clapsing.h>
37 #include <Singular/ipshell.h>
41 #include <polys/prCopy.h>
42 
43 //#include <stdlib.h>
44 #include <stdio.h>
45 #include <string.h>
46 #include <ctype.h>
47 #include <math.h>
48 
49 ///////////////////////////////////////////////////////////////////
50 //walkProc
51 ///////////////////////////////////////////////////////////////////
52 //Description: The main function for the Walk-Algorithm. Checks the
53 //input-data, and calls walk64 (see walkMain.cc). Returns the new
54 //groebner basis or something else if an error occoured.
55 ///////////////////////////////////////////////////////////////////
56 //Uses: omAlloc0,walkConsistency,rGetGlobalOrderWeightVec,
57 //omFreeSize,sizeof,IDIDEAL,walk64,rSetHdl,idrMoveR,Werror,idInit
58 ///////////////////////////////////////////////////////////////////
59 
60 ideal
61 walkProc(leftv first, leftv second)
62 {
63  WalkState state = WalkOk;
64  BITSET save1,save2;
65  SI_SAVE_OPT(save1,save2);
66  si_opt_1 &= (~Sy_bit(OPT_REDSB)); //make sure option noredSB is set
67 
68  ring destRing = currRing;
69  ideal destIdeal = NULL;
70  idhdl sourceRingHdl = (idhdl)first->data;
71  ring sourceRing = IDRING(sourceRingHdl);
72  rChangeCurrRing( sourceRing );
73 
74  if(state==WalkOk)
75  {
76  int * vperm = (int *)omAlloc0( (currRing->N+1)*sizeof( int ) );
77  state= walkConsistency( sourceRing, destRing, vperm );
78  omFreeSize( (ADDRESS)vperm, (currRing->N+1)*sizeof(int) );
79  }
80 
81  int64vec* currw64=rGetGlobalOrderWeightVec(sourceRing);
82  int64vec* destVec64=rGetGlobalOrderWeightVec(destRing);
83 
84  ideal sourceIdeal;
85  BOOLEAN sourcIdealIsSB=FALSE;
86  if ( state == WalkOk )
87  {
88  idhdl ih = currRing->idroot->get( second->Name(), myynest );
89  if ( (ih != NULL) && (IDTYP(ih)==IDEAL_CMD) )
90  {
91  sourceIdeal = idCopy(IDIDEAL( ih ));
92  if(hasFlag((leftv)ih,FLAG_STD)){
93  sourcIdealIsSB=TRUE;
94  }
95  }
96  else
97  {
98  state=WalkNoIdeal;
99  }
100  }
101 
102  if ( state == WalkOk )
103  {
104  // Now the settings are compatible with Walk
105  state=walk64(sourceIdeal,currw64,destRing,destVec64,
106  destIdeal,sourcIdealIsSB);
107  }
108 
109  SI_RESTORE_OPT(save1,save2);//making sure options are as before function call
110 
111  ring almostDestRing=currRing;
112  rChangeCurrRing(destRing);
113 
114  switch (state) {
115  case WalkOk:
116  destIdeal=idrMoveR(destIdeal,currRing,almostDestRing);
117  break;
118 
120  Werror("ring %s and current ring are incompatible\n",
121  first->Name() );
122  destIdeal= NULL;
123  break;
124 
126  Werror( "Order of basering not allowed,\n must be a combination of a,A,lp,dp,Dp,wp,Wp,M and C.\n");
127  destIdeal= NULL;
128  break;
129 
131  Werror( "Order of %s not allowed,\n must be a combination of a,A,lp,dp,Dp,wp,Wp,M and C.\n",first->Name());
132  rChangeCurrRing(destRing);
133  destIdeal= NULL;
134  break;
135 
136  case WalkNoIdeal:
137  Werror( "Can't find ideal %s in ring %s.\n",
138  second->Name(), first->Name() );
139  destIdeal= NULL;
140  break;
141 
142  case WalkOverFlowError:
143  Werror( "Overflow occurred.\n");
144  destIdeal= NULL;
145  break;
146 
147  default:
148  destIdeal= NULL;
149  }
150 
151  return destIdeal;
152 }
153 
154 ///////////////////////////////////////////////////////////////////
155 //fractalWalkProc
156 ///////////////////////////////////////////////////////////////////
157 //Description: The main function for the Fractalwalk-Algorithm.
158 //Responsible for contact between user and walk64. Checks the
159 //input-data, and calls fractalWalk64. Returns the new groebner
160 //basis or something else if an error occurred.
161 ///////////////////////////////////////////////////////////////////
162 //Uses: omAlloc0,fractalWalkConsistency,omFreeSize,sizeof,IDIDEAL,
163 //fractalWalk64,rSetHdl,idrMoveR,Werror,idInit
164 ///////////////////////////////////////////////////////////////////
165 
166 ideal
168 {
169 
170  //unperturbedStartVectorStrategy SHOULD BE SET BY THE USER THROUGH
171  //A THIRD ARGUMENT. TRUE MEANS THAT THE UNPERTURBED START
172  //VECTOR STRATEGY IS USED AND FALSE THAT THE START VECTOR IS
173  //MAXIMALLY PERTURBED
174 
175  BOOLEAN unperturbedStartVectorStrategy=TRUE;
176 
177  WalkState state = WalkOk;
178  BITSET save1,save2;
179  SI_SAVE_OPT(save1,save2);
180  si_opt_1 &= (~Sy_bit(OPT_REDSB)); //make sure option noredSB is set
181 
182  ring destRing = currRing;
183  ideal destIdeal = NULL;
184  idhdl sourceRingHdl = (idhdl)first->data;
185  rSetHdl( sourceRingHdl );
186  ring sourceRing = currRing;
187 
188  int * vperm = (int *)omAlloc0( (currRing->N+1)*sizeof( int ) );
189  state= fractalWalkConsistency( sourceRing, destRing, vperm );
190  omFreeSize( (ADDRESS)vperm, (currRing->N+1)*sizeof(int) );
191 
192  ideal sourceIdeal;
193  BOOLEAN sourcIdealIsSB=FALSE;
194  if ( state == WalkOk ) {
195  idhdl ih = currRing->idroot->get( second->Name(), myynest );
196  if ( (ih != NULL) && (IDTYP(ih)==IDEAL_CMD) ) {
197  sourceIdeal = IDIDEAL( ih );
198  if(hasFlag((leftv)ih,FLAG_STD)){
199  sourcIdealIsSB=TRUE;
200  }
201  }
202  else {
203  state=WalkNoIdeal;
204  }
205  }
206 
207  if ( state == WalkOk ) {
208  // Now the settings are compatible with Walk
209  state=fractalWalk64(sourceIdeal,destRing,destIdeal,
210  sourcIdealIsSB,
211  unperturbedStartVectorStrategy);
212  }
213 
214  SI_RESTORE_OPT(save1,save2);//making sure options are as before functiocall
215 
216  if ( state == WalkOk )
217  {
218  ring almostDestRing=currRing;
219  rChangeCurrRing(destRing);
220  destIdeal=idrMoveR(destIdeal, almostDestRing, destRing);
221  }
222 
223 
224  switch (state) {
225 
226  case WalkOk:
227  destIdeal=sortRedSB(destIdeal);
228  return(destIdeal);
229  break;
230 
232  Werror( "ring %s and current ring are incompatible\n",
233  first->Name() );
234  rChangeCurrRing(destRing);
235  destIdeal= NULL;
236  return destIdeal;
237  break;
238 
240  Werror( "Order of basering not allowed,\n must be a combination of lp,dp,Dp,wp,Wp and C or just M.\n");
241  rChangeCurrRing(destRing);
242  destIdeal= NULL;
243  return destIdeal;
244  break;
245 
247  Werror( "Order of %s not allowed,\n must be a combination of lp,dp,Dp,wp,Wp and C or just M.\n",
248  first->Name());
249  rChangeCurrRing(destRing);
250  destIdeal= NULL;
251  return destIdeal;
252  break;
253 
254  case WalkNoIdeal:
255  Werror( "Can't find ideal %s in ring %s.\n",
256  second->Name(), first->Name() );
257  rChangeCurrRing(destRing);
258  destIdeal= NULL;
259  return destIdeal;
260  break;
261 
262  case WalkOverFlowError:
263  Werror( "Overflow occurred in ring %s.\n", first->Name() );
264  rChangeCurrRing(destRing);
265  destIdeal= NULL;
266  return destIdeal;
267  break;
268 
269  default:
270  rChangeCurrRing(destRing);
271  destIdeal= idInit(1,1);
272  return destIdeal;
273  }
274 
275 
276  return NULL;
277 }
278 
279 
280 ///////////////////////////////////////////////////////////////////
281 //getiv64
282 ///////////////////////////////////////////////////////////////////
283 //Description: retrieves the int64vec from input list l
284 ///////////////////////////////////////////////////////////////////
285 //Assumes: that the first entry of l is an int64vec
286 ///////////////////////////////////////////////////////////////////
287 //Uses: none
288 ///////////////////////////////////////////////////////////////////
289 
291 {
292  return (int64vec*)(l->m[0].data);
293 }
294 
295 ///////////////////////////////////////////////////////////////////
296 
297 
298 ///////////////////////////////////////////////////////////////////
299 //getint64
300 ///////////////////////////////////////////////////////////////////
301 //Description: retrieves the int64 from input list l
302 ///////////////////////////////////////////////////////////////////
303 //Assumes: that the second entry of l is an int64
304 ///////////////////////////////////////////////////////////////////
305 //Uses: none
306 ///////////////////////////////////////////////////////////////////
307 
308 // not used, bad impl.
309 //int64 getint64(lists l)
310 //{
311 // return (int64)(long)(l->m[1].data);
312 //}
313 
314 ///////////////////////////////////////////////////////////////////
#define OPT_REDSB
Definition: options.h:71
int64vec * rGetGlobalOrderWeightVec(ring r)
ideal sortRedSB(ideal G)
unsigned si_opt_1
Definition: options.c:5
sleftv * m
Definition: lists.h:45
Class used for (list of) interpreter objects.
Definition: subexpr.h:83
Definition: lists.h:22
WalkState
Definition: walkMain.h:7
#define FALSE
Definition: auxiliary.h:140
Compatiblity layer for legacy polynomial operations (over currRing)
WalkState walk64(ideal I, int64vec *currw64, ring destRing, int64vec *destVec64, ideal &destIdeal, BOOLEAN sourceIsSB)
Definition: walkMain.cc:222
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define TRUE
Definition: auxiliary.h:144
#define IDIDEAL(a)
Definition: ipid.h:132
void * ADDRESS
Definition: auxiliary.h:161
#define BITSET
Definition: structs.h:17
#define Sy_bit(x)
Definition: options.h:30
const char * Name()
Definition: subexpr.h:121
Definition: idrec.h:34
void * data
Definition: subexpr.h:89
int myynest
Definition: febase.cc:46
ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition: polys.cc:12
#define IDTYP(a)
Definition: ipid.h:118
WalkState walkConsistency(ring sring, ring dring, int *vperm)
Definition: walkProc.cc:57
#define SI_RESTORE_OPT(A, B)
Definition: options.h:22
WalkState fractalWalk64(ideal sourceIdeal, ring destRing, ideal &destIdeal, BOOLEAN sourceIsSB, BOOLEAN unperturbedStartVectorStrategy)
Definition: walkMain.cc:614
int64vec * getiv64(lists l)
Definition: walk_ip.cc:290
ideal idrMoveR(ideal &id, ring src_r, ring dest_r)
Definition: prCopy.cc:249
idrec * idhdl
Definition: ring.h:18
#define FLAG_STD
Definition: ipid.h:108
ideal idCopy(ideal A)
Definition: ideals.h:73
void rChangeCurrRing(ring r)
Definition: polys.cc:14
ideal idInit(int idsize, int rank)
initialise an ideal / module
Definition: simpleideals.cc:38
ideal walkProc(leftv first, leftv second)
Definition: walk_ip.cc:61
#define NULL
Definition: omList.c:10
#define hasFlag(A, F)
Definition: ipid.h:111
#define IDRING(a)
Definition: ipid.h:126
#define SI_SAVE_OPT(A, B)
Definition: options.h:19
WalkState fractalWalkConsistency(ring sring, ring dring, int *vperm)
Definition: walkProc.cc:223
ideal fractalWalkProc(leftv first, leftv second)
Definition: walk_ip.cc:167
void rSetHdl(idhdl h)
Definition: ipshell.cc:5030
int BOOLEAN
Definition: auxiliary.h:131
void Werror(const char *fmt,...)
Definition: reporter.cc:199
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int l
Definition: cfEzgcd.cc:94