walkProc.cc
Go to the documentation of this file.
1 /****************************************
2 * Computer Algebra System SINGULAR *
3 ****************************************/
4 
5 
6 
7 
8 #include <kernel/mod2.h>
9 #include <kernel/structs.h>
10 #include <kernel/structs.h>
11 #include <kernel/polys.h>
12 #include <kernel/ideals.h>
13 #include <polys/monomials/ring.h>
14 #include <polys/monomials/maps.h>
15 #include <omalloc/omalloc.h>
16 #include <kernel/GBEngine/kstd1.h>
17 #include <kernel/fglm/fglm.h>
21 #include <polys/prCopy.h>
22 
23 ///////////////////////////////////////////////////////////////////
24 //Frame procedures for Groebner Walk and Fractal Walk
25 ///////////////////////////////////////////////////////////////////
26 //v1.3 2004-11-15
27 ///////////////////////////////////////////////////////////////////
28 //implemented by Henrik Strohmayer
29 ///////////////////////////////////////////////////////////////////
30 
31 
32 ///////////////////////////////////////////////////////////////////
33 //walkConsistency
34 ///////////////////////////////////////////////////////////////////
35 //Description:
36 // Checks if the two rings sringHdl and dringHdl are compatible
37 // enough to be used for the Walk. This means:
38 // 1) Same Characteristic
39 // 2) globalOrderings in both rings,
40 // 3) Same number of variables
41 // 4) same number of parameters
42 // 5) variables in one ring have the same names
43 // and order as variables of the other
44 // 6) parameters in one ring have the same names
45 // and order as parameters of the other
46 // 7) none of the rings are qrings
47 // vperm must be a vector of length (currRing->N)+1, initialized by 0.
48 // If both rings are compatible, it stores the permutation of the
49 // variables if mapped from sringHdl to dringHdl.
50 // if the rings are compatible, it returns WalkOk.
51 // Should be called with currRing= IDRING( sringHdl );
52 ///////////////////////////////////////////////////////////////////
53 //Uses: IDRING,WerrorS,rPar,omAlloc0,maFindPerm,omFreeSize,sizeof
54 ///////////////////////////////////////////////////////////////////
55 
57 walkConsistency( ring sring, ring dring, int * vperm )
58 {
59  int k;
60  WalkState state= WalkOk;
61 
62  if ( rChar(sring) != rChar(dring) )
63  {
64  WerrorS( "rings must have same characteristic" );
65  state= WalkIncompatibleRings;
66  }
67  else if ( (rHasLocalOrMixedOrdering(sring))
68  || (rHasLocalOrMixedOrdering(dring)) )
69  {
70  WerrorS( "only works for global orderings" );
71  state= WalkIncompatibleRings;
72  }
73  else if ( sring->N != dring->N )
74  {
75  WerrorS( "rings must have same number of variables" );
76  state= WalkIncompatibleRings;
77  }
78  else if ( rPar(sring) != rPar(dring) )
79  {
80  WerrorS( "rings must have same number of parameters" );
81  state= WalkIncompatibleRings;
82  }
83 
84  if ( state != WalkOk ) return state;
85  // now the rings have the same number of variables resp. parameters.
86  // check if the names of the variables resp. parameters do agree:
87 
88  int nvar = rVar(sring);
89  int npar = rPar(sring);
90  int * pperm;
91  char **snames;
92  char **dnames;
93  if ( npar > 0 )
94  {
95  snames=sring->cf->extRing->names;
96  dnames=dring->cf->extRing->names;
97  pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) );
98  }
99  else
100  {
101  snames=NULL;
102  dnames=NULL;
103  pperm= NULL;
104  }
105 
106  maFindPerm( sring->names, nvar, snames, npar,
107  dring->names, nvar, dnames, npar, vperm, pperm,
108  dring->cf->type);
109 
110  for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
111  if ( vperm[k] <= 0 )
112  {
113  WerrorS( "variable names do not agree" );
114  state= WalkIncompatibleRings;
115  }
116 
117  for ( k= npar-1; (k >= 0) && (state == WalkOk); k-- )
118  if ( pperm[k] >= 0 )
119  {
120  WerrorS( "parameter names do not agree" );
121  state= WalkIncompatibleRings;
122  }
123 
124  //remove this to if you want to allow permutations of variables
125  for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
126  if ( vperm[k] != (k) )
127  {
128  WerrorS( "orders of variables do not agree" );
129  state= WalkIncompatibleRings;
130  }
131 
132  //remove this to if you want to allow permutations of parameters
133  for ( k= npar; (k > 0) && (state == WalkOk); k-- )
134  {
135  if ( pperm[k-1] != (-k) )
136  {
137  WerrorS( "orders of parameters do not agree" );
138  state= WalkIncompatibleRings;
139  }
140  }
141  if (pperm != NULL)
142  omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) );
143 
144  if ( state != WalkOk ) return state;
145 
146  // check if any of the rings are qrings or not
147  if ( (sring->qideal != NULL) || (dring->qideal != NULL) )
148  {
149  WerrorS( "rings are not allowed to be qrings");
150  return WalkIncompatibleRings;
151  }
152 
153  int i=0;
154  while(dring->order[i]!=0)
155  {
156  if(
157  !(dring->order[i]==ringorder_a) &&
158  !(dring->order[i]==ringorder_a64) &&
159  !(dring->order[i]==ringorder_lp) &&
160  !(dring->order[i]==ringorder_dp) &&
161  !(dring->order[i]==ringorder_Dp) &&
162  !(dring->order[i]==ringorder_wp) &&
163  !(dring->order[i]==ringorder_Wp) &&
164  !(dring->order[i]==ringorder_C) &&
165  !(dring->order[i]==ringorder_M)
166  )
167  {
169  }
170  i++;
171  }
172 
173  i=0;
174  while(sring->order[i]!=0)
175  {
176  if(
177  !(sring->order[i]==ringorder_a) &&
178  !(sring->order[i]==ringorder_a64) &&
179  !(sring->order[i]==ringorder_lp) &&
180  !(sring->order[i]==ringorder_dp) &&
181  !(sring->order[i]==ringorder_Dp) &&
182  !(sring->order[i]==ringorder_wp) &&
183  !(sring->order[i]==ringorder_Wp) &&
184  !(sring->order[i]==ringorder_C) &&
185  !(sring->order[i]==ringorder_M)
186  )
187  {
189  }
190  i++;
191  }
192 
193  return state;
194 }
195 
196 ///////////////////////////////////////////////////////////////////
197 
198 
199 ///////////////////////////////////////////////////////////////////
200 //fractalWalkConsistency
201 ///////////////////////////////////////////////////////////////////
202 //Description:
203 // Checks if the two rings sringHdl and dringHdl are compatible
204 // enough to be used for the Walk. This means:
205 // 1) Same Characteristic
206 // 2) globalOrderings in both rings,
207 // 3) Same number of variables
208 // 4) same number of parameters
209 // 5) variables in one ring have the same names
210 // and order as variables of the other
211 // 6) parameters in one ring have the same names
212 // and order as parameters of the other
213 // 7) none of the rings are qrings
214 // vperm must be a vector of length (currRing->N)+1, initialized by 0.
215 // If both rings are compatible, it stores the permutation of the
216 // variables if mapped from sringHdl to dringHdl.
217 // if the rings are compatible, it returns WalkOk.
218 // Should be called with currRing= IDRING( sringHdl );
219 ///////////////////////////////////////////////////////////////////
220 //Uses: IDRING,WerrorS,rPar,omAlloc0,maFindPerm,omFreeSize,sizeof
221 ///////////////////////////////////////////////////////////////////
222 
223 WalkState
224 fractalWalkConsistency( ring sring, ring dring, int * vperm )
225 {
226  int k;
227  WalkState state= WalkOk;
228 
229  if ( rChar(sring) != rChar(dring) )
230  {
231  WerrorS( "rings must have same characteristic" );
232  state= WalkIncompatibleRings;
233  }
234 
235  if ( (rHasLocalOrMixedOrdering(sring))
236  || (rHasLocalOrMixedOrdering(dring)) )
237  {
238  WerrorS( "only works for global orderings" );
239  state= WalkIncompatibleRings;
240  }
241 
242  if ( rVar(sring) != rVar(dring) )
243  {
244  WerrorS( "rings must have same number of variables" );
245  state= WalkIncompatibleRings;
246  }
247 
248  if ( rPar(sring) != rPar(dring) )
249  {
250  WerrorS( "rings must have same number of parameters" );
251  state= WalkIncompatibleRings;
252  }
253 
254  if ( state != WalkOk ) return state;
255 
256  // now the rings have the same number of variables resp. parameters.
257  // check if the names of the variables resp. parameters do agree:
258  int nvar = sring->N;
259  int npar = rPar(sring);
260  int * pperm;
261  char **snames;
262  char **dnames;
263 
264  if ( npar > 0 )
265  {
266  snames=sring->cf->extRing->names;
267  dnames=dring->cf->extRing->names;
268  pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) );
269  }
270  else
271  {
272  pperm= NULL;
273  snames=NULL;
274  dnames=NULL;
275  }
276 
277  maFindPerm( sring->names, nvar, snames, npar,
278  dring->names, nvar, dnames, npar, vperm, pperm,
279  dring->cf->type);
280 
281  for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
282  if ( vperm[k] <= 0 )
283  {
284  WerrorS( "variable names do not agree" );
285  state= WalkIncompatibleRings;
286  }
287 
288  for ( k= npar; (k > 0) && (state == WalkOk); k-- )
289  if ( pperm[k-1] >= 0 )
290  {
291  WerrorS( "parameter names do not agree" );
292  state= WalkIncompatibleRings;
293  }
294 
295  //check if order of variables resp. parameters does agree
296  //remove this to if you want to allow permutations of variables
297  for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
298  if ( vperm[k] != (k) )
299  {
300  WerrorS( "orders of variables do not agree" );
301  state= WalkIncompatibleRings;
302  }
303 
304  //remove this to if you want to allow permutations of parameters
305  for ( k= npar; (k > 0) && (state == WalkOk); k-- )
306  if ( pperm[k-1] != (-k) )
307  {
308  WerrorS( "orders of parameters do not agree" );
309  state= WalkIncompatibleRings;
310  }
311 
312  if (pperm != NULL)
313  omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) );
314 
315  if ( state != WalkOk ) return state;
316 
317  // check if any of the rings are qrings or not
318  if ( (sring->qideal != NULL) || (dring->qideal != NULL) )
319  {
320  WerrorS( "rings are not allowed to be qrings");
321  return WalkIncompatibleRings;
322  }
323 
324  int i=0;
325  while(dring->order[i]!=0){
326  if( !(dring->order[i]==ringorder_lp) &&
327  !(dring->order[i]==ringorder_dp) &&
328  !(dring->order[i]==ringorder_Dp) &&
329  !(dring->order[i]==ringorder_wp) &&
330  !(dring->order[i]==ringorder_Wp) &&
331  !(dring->order[i]==ringorder_C) &&
332  !(dring->order[0]==ringorder_M)
333  )
334  {
336  }
337  i++;
338  }
339 
340  i=0;
341  while(sring->order[i]!=0)
342  {
343  if( !(sring->order[i]==ringorder_lp) &&
344  !(sring->order[i]==ringorder_dp) &&
345  !(sring->order[i]==ringorder_Dp) &&
346  !(sring->order[i]==ringorder_wp) &&
347  !(sring->order[i]==ringorder_Wp) &&
348  !(sring->order[i]==ringorder_C) &&
349  !(dring->order[0]==ringorder_M)
350  )
351  {
353  }
354  i++;
355  }
356 
357  return state;
358 }
359 
360 ///////////////////////////////////////////////////////////////////
361 
362 
BOOLEAN rHasLocalOrMixedOrdering(const ring r)
Definition: ring.h:751
for int64 weights
Definition: ring.h:79
WalkState
Definition: walkMain.h:7
Compatiblity layer for legacy polynomial operations (over currRing)
static int rPar(const ring r)
(r->cf->P)
Definition: ring.h:590
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
int rChar(ring r)
Definition: ring.cc:686
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition: ring.h:583
void * ADDRESS
Definition: auxiliary.h:115
void WerrorS(const char *s)
Definition: feFopen.cc:24
int k
Definition: cfEzgcd.cc:93
WalkState walkConsistency(ring sring, ring dring, int *vperm)
Definition: walkProc.cc:57
int i
Definition: cfEzgcd.cc:123
void maFindPerm(char const *const *const preim_names, int preim_n, char const *const *const preim_par, int preim_p, char const *const *const names, int n, char const *const *const par, int nop, int *perm, int *par_perm, n_coeffType ch)
Definition: maps.cc:169
#define NULL
Definition: omList.c:10
WalkState fractalWalkConsistency(ring sring, ring dring, int *vperm)
Definition: walkProc.cc:224
#define omAlloc0(size)
Definition: omAllocDecl.h:211