1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | |
---|
5 | #ifdef HAVE_CONFIG_H |
---|
6 | #include "singularconfig.h" |
---|
7 | #endif /* HAVE_CONFIG_H */ |
---|
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 <kernel/febase.h> |
---|
15 | #include <polys/monomials/maps.h> |
---|
16 | #include <omalloc/omalloc.h> |
---|
17 | #include <kernel/kstd1.h> |
---|
18 | #include <kernel/fglm/fglm.h> |
---|
19 | #include <kernel/walkMain.h> |
---|
20 | #include <kernel/walkSupport.h> |
---|
21 | #include <kernel/walkProc.h> |
---|
22 | #include <polys/prCopy.h> |
---|
23 | |
---|
24 | /////////////////////////////////////////////////////////////////// |
---|
25 | //Frame procedures for Groebner Walk and Fractal Walk |
---|
26 | /////////////////////////////////////////////////////////////////// |
---|
27 | //v1.3 2004-11-15 |
---|
28 | /////////////////////////////////////////////////////////////////// |
---|
29 | //implemented by Henrik Strohmayer |
---|
30 | /////////////////////////////////////////////////////////////////// |
---|
31 | |
---|
32 | |
---|
33 | /////////////////////////////////////////////////////////////////// |
---|
34 | //walkConsistency |
---|
35 | /////////////////////////////////////////////////////////////////// |
---|
36 | //Description: |
---|
37 | // Checks if the two rings sringHdl and dringHdl are compatible |
---|
38 | // enough to be used for the Walk. This means: |
---|
39 | // 1) Same Characteristic |
---|
40 | // 2) globalOrderings in both rings, |
---|
41 | // 3) Same number of variables |
---|
42 | // 4) same number of parameters |
---|
43 | // 5) variables in one ring have the same names |
---|
44 | // and order as variables of the other |
---|
45 | // 6) parameters in one ring have the same names |
---|
46 | // and order as parameters of the other |
---|
47 | // 7) none of the rings are qrings |
---|
48 | // vperm must be a vector of length (currRing->N)+1, initialized by 0. |
---|
49 | // If both rings are compatible, it stores the permutation of the |
---|
50 | // variables if mapped from sringHdl to dringHdl. |
---|
51 | // if the rings are compatible, it returns WalkOk. |
---|
52 | // Should be called with currRing= IDRING( sringHdl ); |
---|
53 | /////////////////////////////////////////////////////////////////// |
---|
54 | //Uses: IDRING,WerrorS,rPar,omAlloc0,maFindPerm,omFreeSize,sizeof |
---|
55 | /////////////////////////////////////////////////////////////////// |
---|
56 | |
---|
57 | WalkState |
---|
58 | walkConsistency( ring sring, ring dring, int * vperm ) |
---|
59 | { |
---|
60 | int k; |
---|
61 | WalkState state= WalkOk; |
---|
62 | |
---|
63 | if ( rChar(sring) != rChar(dring) ) |
---|
64 | { |
---|
65 | WerrorS( "rings must have same characteristic" ); |
---|
66 | state= WalkIncompatibleRings; |
---|
67 | } |
---|
68 | else if ( (rHasLocalOrMixedOrdering(sring)) |
---|
69 | || (rHasLocalOrMixedOrdering(dring)) ) |
---|
70 | { |
---|
71 | WerrorS( "only works for global orderings" ); |
---|
72 | state= WalkIncompatibleRings; |
---|
73 | } |
---|
74 | else if ( sring->N != dring->N ) |
---|
75 | { |
---|
76 | WerrorS( "rings must have same number of variables" ); |
---|
77 | state= WalkIncompatibleRings; |
---|
78 | } |
---|
79 | else if ( rPar(sring) != rPar(dring) ) |
---|
80 | { |
---|
81 | WerrorS( "rings must have same number of parameters" ); |
---|
82 | state= WalkIncompatibleRings; |
---|
83 | } |
---|
84 | |
---|
85 | if ( state != WalkOk ) return state; |
---|
86 | // now the rings have the same number of variables resp. parameters. |
---|
87 | // check if the names of the variables resp. parameters do agree: |
---|
88 | |
---|
89 | int nvar = rVar(sring); |
---|
90 | int npar = rPar(sring); |
---|
91 | int * pperm; |
---|
92 | char **snames; |
---|
93 | char **dnames; |
---|
94 | if ( npar > 0 ) |
---|
95 | { |
---|
96 | snames=sring->cf->extRing->names; |
---|
97 | dnames=dring->cf->extRing->names; |
---|
98 | pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) ); |
---|
99 | } |
---|
100 | else |
---|
101 | { |
---|
102 | snames=NULL; |
---|
103 | dnames=NULL; |
---|
104 | pperm= NULL; |
---|
105 | } |
---|
106 | |
---|
107 | maFindPerm( sring->names, nvar, snames, npar, |
---|
108 | dring->names, nvar, dnames, npar, vperm, pperm, |
---|
109 | dring->cf->type); |
---|
110 | |
---|
111 | for ( k= nvar; (k > 0) && (state == WalkOk); k-- ) |
---|
112 | if ( vperm[k] <= 0 ) |
---|
113 | { |
---|
114 | WerrorS( "variable names do not agree" ); |
---|
115 | state= WalkIncompatibleRings; |
---|
116 | } |
---|
117 | |
---|
118 | for ( k= npar-1; (k >= 0) && (state == WalkOk); k-- ) |
---|
119 | if ( pperm[k] >= 0 ) |
---|
120 | { |
---|
121 | WerrorS( "paramater names do not agree" ); |
---|
122 | state= WalkIncompatibleRings; |
---|
123 | } |
---|
124 | |
---|
125 | //remove this to if you want to allow permutations of variables |
---|
126 | for ( k= nvar; (k > 0) && (state == WalkOk); k-- ) |
---|
127 | if ( vperm[k] != (k) ) |
---|
128 | { |
---|
129 | WerrorS( "orders of variables do not agree" ); |
---|
130 | state= WalkIncompatibleRings; |
---|
131 | } |
---|
132 | |
---|
133 | //remove this to if you want to allow permutations of parameters |
---|
134 | for ( k= npar; (k > 0) && (state == WalkOk); k-- ) |
---|
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 | { |
---|
168 | state=WalkIncompatibleDestRing; |
---|
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 | { |
---|
188 | state=WalkIncompatibleSourceRing; |
---|
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 | { |
---|
335 | state=WalkIncompatibleDestRing; |
---|
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 | { |
---|
352 | state=WalkIncompatibleSourceRing; |
---|
353 | } |
---|
354 | i++; |
---|
355 | } |
---|
356 | |
---|
357 | return state; |
---|
358 | } |
---|
359 | |
---|
360 | /////////////////////////////////////////////////////////////////// |
---|
361 | |
---|
362 | |
---|