source: git/kernel/groebner_walk/walkProc.cc @ 6cf934

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