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