1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id$ */ |
---|
5 | |
---|
6 | #include "config.h" |
---|
7 | #include <kernel/mod2.h> |
---|
8 | #include <kernel/structs.h> |
---|
9 | #include <kernel/structs.h> |
---|
10 | #include <kernel/polys.h> |
---|
11 | #include <kernel/ideals.h> |
---|
12 | #include <polys/monomials/ring.h> |
---|
13 | #include <kernel/febase.h> |
---|
14 | #include <polys/monomials/maps.h> |
---|
15 | #include <omalloc/omalloc.h> |
---|
16 | #include <kernel/kstd1.h> |
---|
17 | #include <kernel/fglm.h> |
---|
18 | #include <kernel/walkMain.h> |
---|
19 | #include <kernel/walkSupport.h> |
---|
20 | #include <kernel/walkProc.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 | |
---|
56 | WalkState |
---|
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( "paramater 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 | if ( pperm[k-1] != (-k) ) |
---|
135 | { |
---|
136 | WerrorS( "orders of parameters do not agree" ); |
---|
137 | state= WalkIncompatibleRings; |
---|
138 | } |
---|
139 | |
---|
140 | if (pperm != NULL) |
---|
141 | omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) ); |
---|
142 | |
---|
143 | if ( state != WalkOk ) return state; |
---|
144 | |
---|
145 | // check if any of the rings are qrings or not |
---|
146 | if ( (sring->qideal != NULL) || (dring->qideal != NULL) ) |
---|
147 | { |
---|
148 | WerrorS( "rings are not allowed to be qrings"); |
---|
149 | return WalkIncompatibleRings; |
---|
150 | } |
---|
151 | |
---|
152 | int i=0; |
---|
153 | while(dring->order[i]!=0) |
---|
154 | { |
---|
155 | if( |
---|
156 | !(dring->order[i]==ringorder_a) && |
---|
157 | !(dring->order[i]==ringorder_a64) && |
---|
158 | !(dring->order[i]==ringorder_lp) && |
---|
159 | !(dring->order[i]==ringorder_dp) && |
---|
160 | !(dring->order[i]==ringorder_Dp) && |
---|
161 | !(dring->order[i]==ringorder_wp) && |
---|
162 | !(dring->order[i]==ringorder_Wp) && |
---|
163 | !(dring->order[i]==ringorder_C) && |
---|
164 | !(dring->order[i]==ringorder_M) |
---|
165 | ) |
---|
166 | { |
---|
167 | state=WalkIncompatibleDestRing; |
---|
168 | } |
---|
169 | i++; |
---|
170 | } |
---|
171 | |
---|
172 | i=0; |
---|
173 | while(sring->order[i]!=0) |
---|
174 | { |
---|
175 | if( |
---|
176 | !(sring->order[i]==ringorder_a) && |
---|
177 | !(sring->order[i]==ringorder_a64) && |
---|
178 | !(sring->order[i]==ringorder_lp) && |
---|
179 | !(sring->order[i]==ringorder_dp) && |
---|
180 | !(sring->order[i]==ringorder_Dp) && |
---|
181 | !(sring->order[i]==ringorder_wp) && |
---|
182 | !(sring->order[i]==ringorder_Wp) && |
---|
183 | !(sring->order[i]==ringorder_C) && |
---|
184 | !(sring->order[i]==ringorder_M) |
---|
185 | ) |
---|
186 | { |
---|
187 | state=WalkIncompatibleSourceRing; |
---|
188 | } |
---|
189 | i++; |
---|
190 | } |
---|
191 | |
---|
192 | return state; |
---|
193 | } |
---|
194 | |
---|
195 | /////////////////////////////////////////////////////////////////// |
---|
196 | |
---|
197 | |
---|
198 | /////////////////////////////////////////////////////////////////// |
---|
199 | //fractalWalkConsistency |
---|
200 | /////////////////////////////////////////////////////////////////// |
---|
201 | //Description: |
---|
202 | // Checks if the two rings sringHdl and dringHdl are compatible |
---|
203 | // enough to be used for the Walk. This means: |
---|
204 | // 1) Same Characteristic |
---|
205 | // 2) globalOrderings in both rings, |
---|
206 | // 3) Same number of variables |
---|
207 | // 4) same number of parameters |
---|
208 | // 5) variables in one ring have the same names |
---|
209 | // and order as variables of the other |
---|
210 | // 6) parameters in one ring have the same names |
---|
211 | // and order as parameters of the other |
---|
212 | // 7) none of the rings are qrings |
---|
213 | // vperm must be a vector of length (currRing->N)+1, initialized by 0. |
---|
214 | // If both rings are compatible, it stores the permutation of the |
---|
215 | // variables if mapped from sringHdl to dringHdl. |
---|
216 | // if the rings are compatible, it returns WalkOk. |
---|
217 | // Should be called with currRing= IDRING( sringHdl ); |
---|
218 | /////////////////////////////////////////////////////////////////// |
---|
219 | //Uses: IDRING,WerrorS,rPar,omAlloc0,maFindPerm,omFreeSize,sizeof |
---|
220 | /////////////////////////////////////////////////////////////////// |
---|
221 | |
---|
222 | WalkState |
---|
223 | fractalWalkConsistency( ring sring, ring dring, int * vperm ) |
---|
224 | { |
---|
225 | int k; |
---|
226 | WalkState state= WalkOk; |
---|
227 | |
---|
228 | if ( rChar(sring) != rChar(dring) ) |
---|
229 | { |
---|
230 | WerrorS( "rings must have same characteristic" ); |
---|
231 | state= WalkIncompatibleRings; |
---|
232 | } |
---|
233 | |
---|
234 | if ( (rHasLocalOrMixedOrdering(sring)) |
---|
235 | || (rHasLocalOrMixedOrdering(dring)) ) |
---|
236 | { |
---|
237 | WerrorS( "only works for global orderings" ); |
---|
238 | state= WalkIncompatibleRings; |
---|
239 | } |
---|
240 | |
---|
241 | if ( rVar(sring) != rVar(dring) ) |
---|
242 | { |
---|
243 | WerrorS( "rings must have same number of variables" ); |
---|
244 | state= WalkIncompatibleRings; |
---|
245 | } |
---|
246 | |
---|
247 | if ( rPar(sring) != rPar(dring) ) |
---|
248 | { |
---|
249 | WerrorS( "rings must have same number of parameters" ); |
---|
250 | state= WalkIncompatibleRings; |
---|
251 | } |
---|
252 | |
---|
253 | if ( state != WalkOk ) return state; |
---|
254 | |
---|
255 | // now the rings have the same number of variables resp. parameters. |
---|
256 | // check if the names of the variables resp. parameters do agree: |
---|
257 | int nvar = sring->N; |
---|
258 | int npar = rPar(sring); |
---|
259 | int * pperm; |
---|
260 | char **snames; |
---|
261 | char **dnames; |
---|
262 | |
---|
263 | if ( npar > 0 ) |
---|
264 | { |
---|
265 | snames=sring->cf->extRing->names; |
---|
266 | dnames=dring->cf->extRing->names; |
---|
267 | pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) ); |
---|
268 | } |
---|
269 | else |
---|
270 | { |
---|
271 | pperm= NULL; |
---|
272 | snames=NULL; |
---|
273 | dnames=NULL; |
---|
274 | } |
---|
275 | |
---|
276 | maFindPerm( sring->names, nvar, snames, npar, |
---|
277 | dring->names, nvar, dnames, npar, vperm, pperm, |
---|
278 | dring->cf->type); |
---|
279 | |
---|
280 | for ( k= nvar; (k > 0) && (state == WalkOk); k-- ) |
---|
281 | if ( vperm[k] <= 0 ) |
---|
282 | { |
---|
283 | WerrorS( "variable names do not agree" ); |
---|
284 | state= WalkIncompatibleRings; |
---|
285 | } |
---|
286 | |
---|
287 | for ( k= npar; (k > 0) && (state == WalkOk); k-- ) |
---|
288 | if ( pperm[k-1] >= 0 ) |
---|
289 | { |
---|
290 | WerrorS( "parameter names do not agree" ); |
---|
291 | state= WalkIncompatibleRings; |
---|
292 | } |
---|
293 | |
---|
294 | //check if order of variables resp. parameters does agree |
---|
295 | //remove this to if you want to allow permutations of variables |
---|
296 | for ( k= nvar; (k > 0) && (state == WalkOk); k-- ) |
---|
297 | if ( vperm[k] != (k) ) |
---|
298 | { |
---|
299 | WerrorS( "orders of variables do not agree" ); |
---|
300 | state= WalkIncompatibleRings; |
---|
301 | } |
---|
302 | |
---|
303 | //remove this to if you want to allow permutations of parameters |
---|
304 | for ( k= npar; (k > 0) && (state == WalkOk); k-- ) |
---|
305 | if ( pperm[k-1] != (-k) ) |
---|
306 | { |
---|
307 | WerrorS( "orders of parameters do not agree" ); |
---|
308 | state= WalkIncompatibleRings; |
---|
309 | } |
---|
310 | |
---|
311 | if (pperm != NULL) |
---|
312 | omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) ); |
---|
313 | |
---|
314 | if ( state != WalkOk ) return state; |
---|
315 | |
---|
316 | // check if any of the rings are qrings or not |
---|
317 | if ( (sring->qideal != NULL) || (dring->qideal != NULL) ) |
---|
318 | { |
---|
319 | WerrorS( "rings are not allowed to be qrings"); |
---|
320 | return WalkIncompatibleRings; |
---|
321 | } |
---|
322 | |
---|
323 | int i=0; |
---|
324 | while(dring->order[i]!=0){ |
---|
325 | if( !(dring->order[i]==ringorder_lp) && |
---|
326 | !(dring->order[i]==ringorder_dp) && |
---|
327 | !(dring->order[i]==ringorder_Dp) && |
---|
328 | !(dring->order[i]==ringorder_wp) && |
---|
329 | !(dring->order[i]==ringorder_Wp) && |
---|
330 | !(dring->order[i]==ringorder_C) && |
---|
331 | !(dring->order[0]==ringorder_M) |
---|
332 | ) |
---|
333 | { |
---|
334 | state=WalkIncompatibleDestRing; |
---|
335 | } |
---|
336 | i++; |
---|
337 | } |
---|
338 | |
---|
339 | i=0; |
---|
340 | while(sring->order[i]!=0) |
---|
341 | { |
---|
342 | if( !(sring->order[i]==ringorder_lp) && |
---|
343 | !(sring->order[i]==ringorder_dp) && |
---|
344 | !(sring->order[i]==ringorder_Dp) && |
---|
345 | !(sring->order[i]==ringorder_wp) && |
---|
346 | !(sring->order[i]==ringorder_Wp) && |
---|
347 | !(sring->order[i]==ringorder_C) && |
---|
348 | !(dring->order[0]==ringorder_M) |
---|
349 | ) |
---|
350 | { |
---|
351 | state=WalkIncompatibleSourceRing; |
---|
352 | } |
---|
353 | i++; |
---|
354 | } |
---|
355 | |
---|
356 | return state; |
---|
357 | } |
---|
358 | |
---|
359 | /////////////////////////////////////////////////////////////////// |
---|
360 | |
---|
361 | |
---|