source: git/kernel/walkProc.cc @ 7b8818

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