source: git/kernel/walkProc.cc @ 19370c

spielwiese
Last change on this file since 19370c was 841e96d, checked in by Hans Schönemann <hannes@…>, 19 years ago
*hannes: frwalk stuff git-svn-id: file:///usr/local/Singular/svn/trunk@8047 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: walkProc.cc,v 1.1 2005-05-04 15:41:27 Singular Exp $ */
5
6#include "mod2.h"
7#include "structs.h"
8#include "structs.h"
9#include "polys.h"
10#include "ideals.h"
11#include "ring.h"
12#include "febase.h"
13#include "maps.h"
14#include "omalloc.h"
15#include "kstd1.h"
16#include "fglm.h"
17#include "walkMain.h"
18#include "walkSupport.h"
19#include "walkProc.h"
20#include "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( idhdl sringHdl, idhdl dringHdl, int * vperm )
57{
58    int k;
59    WalkState state= WalkOk;
60    ring dring = IDRING( dringHdl );
61    ring sring = IDRING( sringHdl );
62
63    if ( rChar(sring) != rChar(dring) )
64    {
65        WerrorS( "rings must have same characteristic" );
66        state= WalkIncompatibleRings;
67    }
68    else if ( (sring->OrdSgn != 1) || (dring->OrdSgn != 1) )
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 = sring->N;
89    int npar = rPar(sring);
90    int * pperm;
91    if ( npar > 0 )
92        pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) );
93    else
94        pperm= NULL;
95
96    maFindPerm( sring->names, nvar, sring->parameter, npar,
97                dring->names, nvar, dring->parameter, npar, vperm, pperm,
98                dring->ch);
99
100    for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
101        if ( vperm[k] <= 0 ) {
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            WerrorS( "paramater names do not agree" );
109            state= WalkIncompatibleRings;
110        }
111
112    //remove this to if you want to allow permutations of variables
113    for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
114      if ( vperm[k] != (k) ) {
115        WerrorS( "orders of variables do not agree" );
116        state= WalkIncompatibleRings;
117      }
118
119    //remove this to if you want to allow permutations of parameters
120    for ( k= npar; (k > 0) && (state == WalkOk); k-- )
121      if ( pperm[k-1] != (-k) ) {
122        WerrorS( "orders of parameters do not agree" );
123        state= WalkIncompatibleRings;
124      }
125
126      if (pperm != NULL)
127        omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) );
128
129    if ( state != WalkOk ) return state;
130
131    // check if any of the rings are qrings or not
132    if ( (sring->qideal != NULL) || (dring->qideal != NULL) ){
133          Werror( "rings are not allowed to be qrings");
134          return WalkIncompatibleRings;
135    }
136
137    int i=0;
138    while(dring->order[i]!=0){
139      if(
140           !(dring->order[i]==ringorder_a) &&
141           !(dring->order[i]==ringorder_a64) &&
142           !(dring->order[i]==ringorder_lp) &&
143           !(dring->order[i]==ringorder_dp) &&
144           !(dring->order[i]==ringorder_Dp) &&
145           !(dring->order[i]==ringorder_wp) &&
146           !(dring->order[i]==ringorder_Wp) &&
147           !(dring->order[i]==ringorder_C)  &&
148           !(dring->order[i]==ringorder_M)
149         ) {
150
151        state=WalkIncompatibleDestRing;
152      }
153      i++;
154    }
155
156    i=0;
157    while(sring->order[i]!=0){
158      if(
159           !(sring->order[i]==ringorder_a) &&
160           !(sring->order[i]==ringorder_a64) &&
161           !(sring->order[i]==ringorder_lp) &&
162           !(sring->order[i]==ringorder_dp) &&
163           !(sring->order[i]==ringorder_Dp) &&
164           !(sring->order[i]==ringorder_wp) &&
165           !(sring->order[i]==ringorder_Wp) &&
166           !(sring->order[i]==ringorder_C)  &&
167           !(sring->order[i]==ringorder_M)
168         ) {
169       state=WalkIncompatibleSourceRing;
170      }
171      i++;
172    }
173
174    return state;
175}
176
177///////////////////////////////////////////////////////////////////
178
179
180///////////////////////////////////////////////////////////////////
181//fractalWalkConsistency
182///////////////////////////////////////////////////////////////////
183//Description:
184// Checks if the two rings sringHdl and dringHdl are compatible
185// enough to be used for the Walk. This means:
186// 1) Same Characteristic
187// 2) globalOrderings in both rings,
188// 3) Same number of variables
189// 4) same number of parameters
190// 5) variables in one ring have the same names
191//    and order as variables of the other
192// 6) parameters in one ring have the same names
193//    and order as parameters of the other
194// 7) none of the rings are qrings
195// vperm must be a vector of length pVariables+1, initialized by 0.
196// If both rings are compatible, it stores the permutation of the
197// variables if mapped from sringHdl to dringHdl.
198// if the rings are compatible, it returns WalkOk.
199// Should be called with currRing= IDRING( sringHdl );
200///////////////////////////////////////////////////////////////////
201//Uses: IDRING,WerrorS,rPar,omAlloc0,maFindPerm,omFreeSize,sizeof
202///////////////////////////////////////////////////////////////////
203
204WalkState
205fractalWalkConsistency( idhdl sringHdl, idhdl dringHdl, int * vperm )
206{
207    int k;
208    WalkState state= WalkOk;
209    ring dring = IDRING( dringHdl );
210    ring sring = IDRING( sringHdl );
211
212    if ( rChar(sring) != rChar(dring) ) {
213        WerrorS( "rings must have same characteristic" );
214        state= WalkIncompatibleRings;
215    }
216
217    if ( (sring->OrdSgn != 1) || (dring->OrdSgn != 1) ) {
218        WerrorS( "only works for global orderings" );
219        state= WalkIncompatibleRings;
220    }
221
222    if ( sring->N != dring->N )
223    {
224        WerrorS( "rings must have same number of variables" );
225        state= WalkIncompatibleRings;
226    }
227
228    if ( rPar(sring) != rPar(dring) )
229    {
230        WerrorS( "rings must have same number of parameters" );
231        state= WalkIncompatibleRings;
232    }
233
234    if ( state != WalkOk ) return state;
235
236    // now the rings have the same number of variables resp. parameters.
237    // check if the names of the variables resp. parameters do agree:
238    int nvar = sring->N;
239    int npar = rPar(sring);
240    int * pperm;
241
242    if ( npar > 0 )
243        pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) );
244    else
245        pperm= NULL;
246
247    maFindPerm( sring->names, nvar, sring->parameter, npar,
248                dring->names, nvar, dring->parameter, npar, vperm, pperm,
249                dring->ch);
250
251    for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
252      if ( vperm[k] <= 0 ) {
253        WerrorS( "variable names do not agree" );
254        state= WalkIncompatibleRings;
255      }
256
257    for ( k= npar; (k > 0) && (state == WalkOk); k-- )
258      if ( pperm[k-1] >= 0 ){
259        WerrorS( "parameter names do not agree" );
260        state= WalkIncompatibleRings;
261      }
262
263    //check if order of variables resp. parameters does agree
264    //remove this to if you want to allow permutations of variables
265    for ( k= nvar; (k > 0) && (state == WalkOk); k-- )
266      if ( vperm[k] != (k) ) {
267        WerrorS( "orders of variables do not agree" );
268        state= WalkIncompatibleRings;
269      }
270
271    //remove this to if you want to allow permutations of parameters
272    for ( k= npar; (k > 0) && (state == WalkOk); k-- )
273      if ( pperm[k-1] != (-k) ) {
274        WerrorS( "orders of parameters do not agree" );
275        state= WalkIncompatibleRings;
276      }
277
278    if (pperm != NULL)
279      omFreeSize( (ADDRESS)pperm, (npar+1)*sizeof( int ) );
280
281    if ( state != WalkOk ) return state;
282
283    // check if any of the rings are qrings or not
284    if ( (sring->qideal != NULL) || (dring->qideal != NULL) ){
285          Werror( "rings are not allowed to be qrings");
286          return WalkIncompatibleRings;
287    }
288
289    int i=0;
290    while(dring->order[i]!=0){
291      if(  !(dring->order[i]==ringorder_lp) &&
292           !(dring->order[i]==ringorder_dp) &&
293           !(dring->order[i]==ringorder_Dp) &&
294           !(dring->order[i]==ringorder_wp) &&
295           !(dring->order[i]==ringorder_Wp) &&
296           !(dring->order[i]==ringorder_C)  &&
297           !(dring->order[0]==ringorder_M)
298         ) {
299        state=WalkIncompatibleDestRing;
300      }
301      i++;
302    }
303
304    i=0;
305    while(sring->order[i]!=0){
306      if(  !(sring->order[i]==ringorder_lp) &&
307           !(sring->order[i]==ringorder_dp) &&
308           !(sring->order[i]==ringorder_Dp) &&
309           !(sring->order[i]==ringorder_wp) &&
310           !(sring->order[i]==ringorder_Wp) &&
311           !(sring->order[i]==ringorder_C)  &&
312           !(dring->order[0]==ringorder_M)
313         ) {
314        state=WalkIncompatibleSourceRing;
315      }
316      i++;
317    }
318
319    return state;
320}
321
322///////////////////////////////////////////////////////////////////
323
324
Note: See TracBrowser for help on using the repository browser.