source: git/kernel/walkProc.cc @ 0f401f

spielwiese
Last change on this file since 0f401f was b1dfaf, checked in by Frank Seelisch <seelisch@…>, 14 years ago
patch from Kai (checked for problems under Windows OS: no problems) git-svn-id: file:///usr/local/Singular/svn/trunk@13210 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 10.3 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5
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 <kernel/ring.h>
12#include <kernel/febase.h>
13#include <kernel/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 <kernel/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 pVariables+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    if ( npar > 0 )
91        pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) );
92    else
93        pperm= NULL;
94
95    maFindPerm( sring->names, nvar, sring->parameter, npar,
96                dring->names, nvar, dring->parameter, npar, vperm, pperm,
97                dring->ch);
98
99    for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
100        if ( vperm[k] <= 0 )
101        {
102            WerrorS( "variable names do not agree" );
103            state= WalkIncompatibleRings;
104        }
105
106    for ( k= npar-1; (k >= 0) && (state == WalkOk); k-- )
107        if ( pperm[k] >= 0 )
108        {
109            WerrorS( "paramater names do not agree" );
110            state= WalkIncompatibleRings;
111        }
112
113    //remove this to if you want to allow permutations of variables
114    for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
115      if ( vperm[k] != (k) )
116      {
117        WerrorS( "orders of variables do not agree" );
118        state= WalkIncompatibleRings;
119      }
120
121    //remove this to if you want to allow permutations of parameters
122    for ( k= npar; (k > 0) && (state == WalkOk); k-- )
123      if ( pperm[k-1] != (-k) )
124      {
125        WerrorS( "orders of parameters do not agree" );
126        state= WalkIncompatibleRings;
127      }
128
129      if (pperm != NULL)
130        omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) );
131
132    if ( state != WalkOk ) return state;
133
134    // check if any of the rings are qrings or not
135    if ( (sring->qideal != NULL) || (dring->qideal != NULL) )
136    {
137          WerrorS( "rings are not allowed to be qrings");
138          return WalkIncompatibleRings;
139    }
140
141    int i=0;
142    while(dring->order[i]!=0)
143    {
144      if(
145           !(dring->order[i]==ringorder_a) &&
146           !(dring->order[i]==ringorder_a64) &&
147           !(dring->order[i]==ringorder_lp) &&
148           !(dring->order[i]==ringorder_dp) &&
149           !(dring->order[i]==ringorder_Dp) &&
150           !(dring->order[i]==ringorder_wp) &&
151           !(dring->order[i]==ringorder_Wp) &&
152           !(dring->order[i]==ringorder_C)  &&
153           !(dring->order[i]==ringorder_M)
154         )
155      {
156        state=WalkIncompatibleDestRing;
157      }
158      i++;
159    }
160
161    i=0;
162    while(sring->order[i]!=0)
163    {
164      if(
165           !(sring->order[i]==ringorder_a) &&
166           !(sring->order[i]==ringorder_a64) &&
167           !(sring->order[i]==ringorder_lp) &&
168           !(sring->order[i]==ringorder_dp) &&
169           !(sring->order[i]==ringorder_Dp) &&
170           !(sring->order[i]==ringorder_wp) &&
171           !(sring->order[i]==ringorder_Wp) &&
172           !(sring->order[i]==ringorder_C)  &&
173           !(sring->order[i]==ringorder_M)
174         )
175      {
176       state=WalkIncompatibleSourceRing;
177      }
178      i++;
179    }
180
181    return state;
182}
183
184///////////////////////////////////////////////////////////////////
185
186
187///////////////////////////////////////////////////////////////////
188//fractalWalkConsistency
189///////////////////////////////////////////////////////////////////
190//Description:
191// Checks if the two rings sringHdl and dringHdl are compatible
192// enough to be used for the Walk. This means:
193// 1) Same Characteristic
194// 2) globalOrderings in both rings,
195// 3) Same number of variables
196// 4) same number of parameters
197// 5) variables in one ring have the same names
198//    and order as variables of the other
199// 6) parameters in one ring have the same names
200//    and order as parameters of the other
201// 7) none of the rings are qrings
202// vperm must be a vector of length pVariables+1, initialized by 0.
203// If both rings are compatible, it stores the permutation of the
204// variables if mapped from sringHdl to dringHdl.
205// if the rings are compatible, it returns WalkOk.
206// Should be called with currRing= IDRING( sringHdl );
207///////////////////////////////////////////////////////////////////
208//Uses: IDRING,WerrorS,rPar,omAlloc0,maFindPerm,omFreeSize,sizeof
209///////////////////////////////////////////////////////////////////
210
211WalkState
212fractalWalkConsistency( ring sring, ring dring, int * vperm )
213{
214    int k;
215    WalkState state= WalkOk;
216
217    if ( rChar(sring) != rChar(dring) )
218    {
219        WerrorS( "rings must have same characteristic" );
220        state= WalkIncompatibleRings;
221    }
222
223    if ( (rHasLocalOrMixedOrdering(sring))
224    || (rHasLocalOrMixedOrdering(dring)) )
225    {
226        WerrorS( "only works for global orderings" );
227        state= WalkIncompatibleRings;
228    }
229
230    if ( rVar(sring) != rVar(dring) )
231    {
232        WerrorS( "rings must have same number of variables" );
233        state= WalkIncompatibleRings;
234    }
235
236    if ( rPar(sring) != rPar(dring) )
237    {
238        WerrorS( "rings must have same number of parameters" );
239        state= WalkIncompatibleRings;
240    }
241
242    if ( state != WalkOk ) return state;
243
244    // now the rings have the same number of variables resp. parameters.
245    // check if the names of the variables resp. parameters do agree:
246    int nvar = sring->N;
247    int npar = rPar(sring);
248    int * pperm;
249
250    if ( npar > 0 )
251        pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) );
252    else
253        pperm= NULL;
254
255    maFindPerm( sring->names, nvar, sring->parameter, npar,
256                dring->names, nvar, dring->parameter, npar, vperm, pperm,
257                dring->ch);
258
259    for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
260      if ( vperm[k] <= 0 )
261      {
262        WerrorS( "variable names do not agree" );
263        state= WalkIncompatibleRings;
264      }
265
266    for ( k= npar; (k > 0) && (state == WalkOk); k-- )
267      if ( pperm[k-1] >= 0 )
268      {
269        WerrorS( "parameter names do not agree" );
270        state= WalkIncompatibleRings;
271      }
272
273    //check if order of variables resp. parameters does agree
274    //remove this to if you want to allow permutations of variables
275    for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
276      if ( vperm[k] != (k) )
277      {
278        WerrorS( "orders of variables do not agree" );
279        state= WalkIncompatibleRings;
280      }
281
282    //remove this to if you want to allow permutations of parameters
283    for ( k= npar; (k > 0) && (state == WalkOk); k-- )
284      if ( pperm[k-1] != (-k) )
285      {
286        WerrorS( "orders of parameters do not agree" );
287        state= WalkIncompatibleRings;
288      }
289
290    if (pperm != NULL)
291      omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) );
292
293    if ( state != WalkOk ) return state;
294
295    // check if any of the rings are qrings or not
296    if ( (sring->qideal != NULL) || (dring->qideal != NULL) )
297    {
298          WerrorS( "rings are not allowed to be qrings");
299          return WalkIncompatibleRings;
300    }
301
302    int i=0;
303    while(dring->order[i]!=0){
304      if(  !(dring->order[i]==ringorder_lp) &&
305           !(dring->order[i]==ringorder_dp) &&
306           !(dring->order[i]==ringorder_Dp) &&
307           !(dring->order[i]==ringorder_wp) &&
308           !(dring->order[i]==ringorder_Wp) &&
309           !(dring->order[i]==ringorder_C)  &&
310           !(dring->order[0]==ringorder_M)
311         )
312      {
313        state=WalkIncompatibleDestRing;
314      }
315      i++;
316    }
317
318    i=0;
319    while(sring->order[i]!=0)
320    {
321      if(  !(sring->order[i]==ringorder_lp) &&
322           !(sring->order[i]==ringorder_dp) &&
323           !(sring->order[i]==ringorder_Dp) &&
324           !(sring->order[i]==ringorder_wp) &&
325           !(sring->order[i]==ringorder_Wp) &&
326           !(sring->order[i]==ringorder_C)  &&
327           !(dring->order[0]==ringorder_M)
328         )
329      {
330        state=WalkIncompatibleSourceRing;
331      }
332      i++;
333    }
334
335    return state;
336}
337
338///////////////////////////////////////////////////////////////////
339
340
Note: See TracBrowser for help on using the repository browser.