[841e96d] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
[341696] | 4 | /* $Id$ */ |
---|
[841e96d] | 5 | |
---|
[599326] | 6 | #include <kernel/mod2.h> |
---|
| 7 | #include <kernel/structs.h> |
---|
| 8 | #include <kernel/structs.h> |
---|
[737a68] | 9 | #include <kernel/polys.h> |
---|
[599326] | 10 | #include <kernel/ideals.h> |
---|
[210e07] | 11 | #include <polys/monomials/ring.h> |
---|
[599326] | 12 | #include <kernel/febase.h> |
---|
[76cfef] | 13 | #include <polys/monomials/maps.h> |
---|
[b1dfaf] | 14 | #include <omalloc/omalloc.h> |
---|
[599326] | 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> |
---|
[76cfef] | 20 | #include <polys/prCopy.h> |
---|
[841e96d] | 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 |
---|
[1f637e] | 46 | // vperm must be a vector of length (currRing->N)+1, initialized by 0. |
---|
[841e96d] | 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 | |
---|
| 55 | WalkState |
---|
[098f98f] | 56 | walkConsistency( ring sring, ring dring, int * vperm ) |
---|
[841e96d] | 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 | } |
---|
[b9642b1] | 66 | else if ( (rHasLocalOrMixedOrdering(sring)) |
---|
| 67 | || (rHasLocalOrMixedOrdering(dring)) ) |
---|
[841e96d] | 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 | |
---|
[b9642b1] | 87 | int nvar = rVar(sring); |
---|
[841e96d] | 88 | int npar = rPar(sring); |
---|
| 89 | int * pperm; |
---|
[38f8dfc] | 90 | char **snames; |
---|
| 91 | char **dnames; |
---|
[841e96d] | 92 | if ( npar > 0 ) |
---|
[38f8dfc] | 93 | { |
---|
| 94 | snames=sring->cf->extRing->names; |
---|
| 95 | dnames=dring->cf->extRing->names; |
---|
[841e96d] | 96 | pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) ); |
---|
[38f8dfc] | 97 | } |
---|
[841e96d] | 98 | else |
---|
[38f8dfc] | 99 | { |
---|
| 100 | snames=NULL; |
---|
| 101 | dnames=NULL; |
---|
[841e96d] | 102 | pperm= NULL; |
---|
[38f8dfc] | 103 | } |
---|
[841e96d] | 104 | |
---|
[38f8dfc] | 105 | maFindPerm( sring->names, nvar, snames, npar, |
---|
| 106 | dring->names, nvar, dnames, npar, vperm, pperm, |
---|
| 107 | dring->cf->type); |
---|
[841e96d] | 108 | |
---|
| 109 | for ( k= nvar; (k > 0) && (state == WalkOk); k-- ) |
---|
[b9642b1] | 110 | if ( vperm[k] <= 0 ) |
---|
| 111 | { |
---|
[841e96d] | 112 | WerrorS( "variable names do not agree" ); |
---|
| 113 | state= WalkIncompatibleRings; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | for ( k= npar-1; (k >= 0) && (state == WalkOk); k-- ) |
---|
[b9642b1] | 117 | if ( pperm[k] >= 0 ) |
---|
| 118 | { |
---|
[841e96d] | 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-- ) |
---|
[b9642b1] | 125 | if ( vperm[k] != (k) ) |
---|
| 126 | { |
---|
[841e96d] | 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-- ) |
---|
[b9642b1] | 133 | if ( pperm[k-1] != (-k) ) |
---|
| 134 | { |
---|
[841e96d] | 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 |
---|
[b9642b1] | 145 | if ( (sring->qideal != NULL) || (dring->qideal != NULL) ) |
---|
| 146 | { |
---|
| 147 | WerrorS( "rings are not allowed to be qrings"); |
---|
[841e96d] | 148 | return WalkIncompatibleRings; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | int i=0; |
---|
[b9642b1] | 152 | while(dring->order[i]!=0) |
---|
| 153 | { |
---|
[841e96d] | 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) |
---|
[b9642b1] | 164 | ) |
---|
| 165 | { |
---|
[841e96d] | 166 | state=WalkIncompatibleDestRing; |
---|
| 167 | } |
---|
| 168 | i++; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | i=0; |
---|
[b9642b1] | 172 | while(sring->order[i]!=0) |
---|
| 173 | { |
---|
[841e96d] | 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) |
---|
[b9642b1] | 184 | ) |
---|
| 185 | { |
---|
[841e96d] | 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 |
---|
[1f637e] | 212 | // vperm must be a vector of length (currRing->N)+1, initialized by 0. |
---|
[841e96d] | 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 | |
---|
| 221 | WalkState |
---|
[098f98f] | 222 | fractalWalkConsistency( ring sring, ring dring, int * vperm ) |
---|
[841e96d] | 223 | { |
---|
| 224 | int k; |
---|
| 225 | WalkState state= WalkOk; |
---|
| 226 | |
---|
[b9642b1] | 227 | if ( rChar(sring) != rChar(dring) ) |
---|
| 228 | { |
---|
[841e96d] | 229 | WerrorS( "rings must have same characteristic" ); |
---|
| 230 | state= WalkIncompatibleRings; |
---|
| 231 | } |
---|
| 232 | |
---|
[b9642b1] | 233 | if ( (rHasLocalOrMixedOrdering(sring)) |
---|
| 234 | || (rHasLocalOrMixedOrdering(dring)) ) |
---|
| 235 | { |
---|
[841e96d] | 236 | WerrorS( "only works for global orderings" ); |
---|
| 237 | state= WalkIncompatibleRings; |
---|
| 238 | } |
---|
| 239 | |
---|
[b9642b1] | 240 | if ( rVar(sring) != rVar(dring) ) |
---|
[841e96d] | 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; |
---|
[38f8dfc] | 259 | char **snames; |
---|
| 260 | char **dnames; |
---|
[841e96d] | 261 | |
---|
| 262 | if ( npar > 0 ) |
---|
[38f8dfc] | 263 | { |
---|
| 264 | snames=sring->cf->extRing->names; |
---|
| 265 | dnames=dring->cf->extRing->names; |
---|
[841e96d] | 266 | pperm= (int *)omAlloc0( (npar+1)*sizeof( int ) ); |
---|
[38f8dfc] | 267 | } |
---|
[841e96d] | 268 | else |
---|
[38f8dfc] | 269 | { |
---|
[841e96d] | 270 | pperm= NULL; |
---|
[38f8dfc] | 271 | snames=NULL; |
---|
| 272 | dnames=NULL; |
---|
| 273 | } |
---|
[841e96d] | 274 | |
---|
[38f8dfc] | 275 | maFindPerm( sring->names, nvar, snames, npar, |
---|
| 276 | dring->names, nvar, dnames, npar, vperm, pperm, |
---|
| 277 | dring->cf->type); |
---|
[841e96d] | 278 | |
---|
| 279 | for ( k= nvar; (k > 0) && (state == WalkOk); k-- ) |
---|
[b9642b1] | 280 | if ( vperm[k] <= 0 ) |
---|
| 281 | { |
---|
[841e96d] | 282 | WerrorS( "variable names do not agree" ); |
---|
| 283 | state= WalkIncompatibleRings; |
---|
| 284 | } |
---|
| 285 | |
---|
| 286 | for ( k= npar; (k > 0) && (state == WalkOk); k-- ) |
---|
[b9642b1] | 287 | if ( pperm[k-1] >= 0 ) |
---|
| 288 | { |
---|
[841e96d] | 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-- ) |
---|
[b9642b1] | 296 | if ( vperm[k] != (k) ) |
---|
| 297 | { |
---|
[841e96d] | 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-- ) |
---|
[b9642b1] | 304 | if ( pperm[k-1] != (-k) ) |
---|
| 305 | { |
---|
[841e96d] | 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 |
---|
[b9642b1] | 316 | if ( (sring->qideal != NULL) || (dring->qideal != NULL) ) |
---|
| 317 | { |
---|
| 318 | WerrorS( "rings are not allowed to be qrings"); |
---|
[841e96d] | 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) |
---|
[b9642b1] | 331 | ) |
---|
| 332 | { |
---|
[841e96d] | 333 | state=WalkIncompatibleDestRing; |
---|
| 334 | } |
---|
| 335 | i++; |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | i=0; |
---|
[b9642b1] | 339 | while(sring->order[i]!=0) |
---|
| 340 | { |
---|
[841e96d] | 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) |
---|
[b9642b1] | 348 | ) |
---|
| 349 | { |
---|
[841e96d] | 350 | state=WalkIncompatibleSourceRing; |
---|
| 351 | } |
---|
| 352 | i++; |
---|
| 353 | } |
---|
| 354 | |
---|
| 355 | return state; |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | /////////////////////////////////////////////////////////////////// |
---|
| 359 | |
---|
| 360 | |
---|