[54e28f] | 1 | /**************************************** |
---|
| 2 | * Computer Algebra System SINGULAR * |
---|
| 3 | ****************************************/ |
---|
| 4 | /* |
---|
| 5 | * ABSTRACT: frwalk: interpreter link |
---|
| 6 | */ |
---|
| 7 | |
---|
[b1dfaf] | 8 | #include <kernel/mod2.h> |
---|
[599326] | 9 | #include <Singular/tok.h> |
---|
[0fb34ba] | 10 | #include <misc/options.h> |
---|
[599326] | 11 | #include <Singular/ipid.h> |
---|
[0fb34ba] | 12 | #include <misc/intvec.h> |
---|
[b1dfaf] | 13 | #include <omalloc/omalloc.h> |
---|
[737a68] | 14 | #include <kernel/polys.h> |
---|
[599326] | 15 | #include <kernel/ideals.h> |
---|
[0fb34ba] | 16 | #include <polys/matpol.h> |
---|
[57fa2c4] | 17 | #include <kernel/GBEngine/kstd1.h> |
---|
[0fb34ba] | 18 | #include <polys/monomials/ring.h> |
---|
[599326] | 19 | #include <Singular/subexpr.h> |
---|
[0fb34ba] | 20 | #include <polys/monomials/maps.h> |
---|
[57fa2c4] | 21 | #include <kernel/GBEngine/syz.h> |
---|
[0fb34ba] | 22 | #include <coeffs/numbers.h> |
---|
[599326] | 23 | #include <Singular/lists.h> |
---|
| 24 | #include <Singular/attrib.h> |
---|
| 25 | #include <Singular/ipconv.h> |
---|
[44ca2f] | 26 | #include <Singular/links/silink.h> |
---|
[57fa2c4] | 27 | #include <kernel/GBEngine/stairc.h> |
---|
[0fb34ba] | 28 | #include <polys/weight.h> |
---|
[54764c8] | 29 | #include <kernel/spectrum/semic.h> |
---|
| 30 | #include <kernel/spectrum/splist.h> |
---|
| 31 | #include <kernel/spectrum/spectrum.h> |
---|
[47417b] | 32 | //#include <kernel/gnumpfl.h> |
---|
| 33 | //#include <kernel/mpr_base.h> |
---|
| 34 | //#include <kernel/ffields.h> |
---|
| 35 | #include <polys/clapsing.h> |
---|
[5ab313] | 36 | #include <kernel/combinatorics/hutil.h> |
---|
[599326] | 37 | #include <Singular/ipshell.h> |
---|
[b88d52] | 38 | #include <kernel/groebner_walk/walkMain.h> |
---|
| 39 | #include <kernel/groebner_walk/walkProc.h> |
---|
| 40 | #include <kernel/groebner_walk/walkSupport.h> |
---|
[0fb34ba] | 41 | #include <polys/prCopy.h> |
---|
[54e28f] | 42 | |
---|
[fd1b1be] | 43 | //#include <stdlib.h> |
---|
| 44 | #include <stdio.h> |
---|
| 45 | #include <string.h> |
---|
| 46 | #include <ctype.h> |
---|
| 47 | #include <math.h> |
---|
| 48 | |
---|
[54e28f] | 49 | /////////////////////////////////////////////////////////////////// |
---|
| 50 | //walkProc |
---|
| 51 | /////////////////////////////////////////////////////////////////// |
---|
| 52 | //Description: The main function for the Walk-Algorithm. Checks the |
---|
| 53 | //input-data, and calls walk64 (see walkMain.cc). Returns the new |
---|
| 54 | //groebner basis or something else if an error occoured. |
---|
| 55 | /////////////////////////////////////////////////////////////////// |
---|
| 56 | //Uses: omAlloc0,walkConsistency,rGetGlobalOrderWeightVec, |
---|
| 57 | //omFreeSize,sizeof,IDIDEAL,walk64,rSetHdl,idrMoveR,Werror,idInit |
---|
| 58 | /////////////////////////////////////////////////////////////////// |
---|
| 59 | |
---|
| 60 | ideal |
---|
| 61 | walkProc(leftv first, leftv second) |
---|
| 62 | { |
---|
| 63 | WalkState state = WalkOk; |
---|
[d30a399] | 64 | BITSET save1,save2; |
---|
| 65 | SI_SAVE_OPT(save1,save2); |
---|
| 66 | si_opt_1 &= (~Sy_bit(OPT_REDSB)); //make sure option noredSB is set |
---|
[54e28f] | 67 | |
---|
| 68 | ring destRing = currRing; |
---|
| 69 | ideal destIdeal = NULL; |
---|
| 70 | idhdl sourceRingHdl = (idhdl)first->data; |
---|
[0deb6a] | 71 | ring sourceRing = IDRING(sourceRingHdl); |
---|
| 72 | rChangeCurrRing( sourceRing ); |
---|
[54e28f] | 73 | |
---|
| 74 | if(state==WalkOk) |
---|
| 75 | { |
---|
[3bef0a] | 76 | int * vperm = (int *)omAlloc0( (currRing->N+1)*sizeof( int ) ); |
---|
[0deb6a] | 77 | state= walkConsistency( sourceRing, destRing, vperm ); |
---|
[3bef0a] | 78 | omFreeSize( (ADDRESS)vperm, (currRing->N+1)*sizeof(int) ); |
---|
[54e28f] | 79 | } |
---|
| 80 | |
---|
| 81 | int64vec* currw64=rGetGlobalOrderWeightVec(sourceRing); |
---|
| 82 | int64vec* destVec64=rGetGlobalOrderWeightVec(destRing); |
---|
| 83 | |
---|
| 84 | ideal sourceIdeal; |
---|
| 85 | BOOLEAN sourcIdealIsSB=FALSE; |
---|
| 86 | if ( state == WalkOk ) |
---|
| 87 | { |
---|
| 88 | idhdl ih = currRing->idroot->get( second->Name(), myynest ); |
---|
| 89 | if ( (ih != NULL) && (IDTYP(ih)==IDEAL_CMD) ) |
---|
| 90 | { |
---|
| 91 | sourceIdeal = idCopy(IDIDEAL( ih )); |
---|
| 92 | if(hasFlag((leftv)ih,FLAG_STD)){ |
---|
| 93 | sourcIdealIsSB=TRUE; |
---|
| 94 | } |
---|
| 95 | } |
---|
| 96 | else |
---|
| 97 | { |
---|
| 98 | state=WalkNoIdeal; |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | if ( state == WalkOk ) |
---|
| 103 | { |
---|
| 104 | // Now the settings are compatible with Walk |
---|
| 105 | state=walk64(sourceIdeal,currw64,destRing,destVec64, |
---|
| 106 | destIdeal,sourcIdealIsSB); |
---|
| 107 | } |
---|
| 108 | |
---|
[d30a399] | 109 | SI_RESTORE_OPT(save1,save2);//making sure options are as before function call |
---|
[54e28f] | 110 | |
---|
| 111 | ring almostDestRing=currRing; |
---|
[0deb6a] | 112 | rChangeCurrRing(destRing); |
---|
[54e28f] | 113 | |
---|
| 114 | switch (state) { |
---|
| 115 | case WalkOk: |
---|
[3bef0a] | 116 | destIdeal=idrMoveR(destIdeal,currRing,almostDestRing); |
---|
[54e28f] | 117 | break; |
---|
| 118 | |
---|
| 119 | case WalkIncompatibleRings: |
---|
| 120 | Werror("ring %s and current ring are incompatible\n", |
---|
| 121 | first->Name() ); |
---|
[ebbb9c] | 122 | destIdeal= NULL; |
---|
[54e28f] | 123 | break; |
---|
| 124 | |
---|
| 125 | case WalkIncompatibleDestRing: |
---|
| 126 | Werror( "Order of basering not allowed,\n must be a combination of a,A,lp,dp,Dp,wp,Wp,M and C.\n"); |
---|
[ebbb9c] | 127 | destIdeal= NULL; |
---|
[54e28f] | 128 | break; |
---|
| 129 | |
---|
| 130 | case WalkIncompatibleSourceRing: |
---|
| 131 | Werror( "Order of %s not allowed,\n must be a combination of a,A,lp,dp,Dp,wp,Wp,M and C.\n",first->Name()); |
---|
[0deb6a] | 132 | rChangeCurrRing(destRing); |
---|
[ebbb9c] | 133 | destIdeal= NULL; |
---|
[54e28f] | 134 | break; |
---|
| 135 | |
---|
| 136 | case WalkNoIdeal: |
---|
| 137 | Werror( "Can't find ideal %s in ring %s.\n", |
---|
| 138 | second->Name(), first->Name() ); |
---|
[ebbb9c] | 139 | destIdeal= NULL; |
---|
[54e28f] | 140 | break; |
---|
| 141 | |
---|
| 142 | case WalkOverFlowError: |
---|
| 143 | Werror( "Overflow occured.\n"); |
---|
[ebbb9c] | 144 | destIdeal= NULL; |
---|
[54e28f] | 145 | break; |
---|
| 146 | |
---|
| 147 | default: |
---|
[ebbb9c] | 148 | destIdeal= NULL; |
---|
[54e28f] | 149 | } |
---|
| 150 | |
---|
| 151 | return destIdeal; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /////////////////////////////////////////////////////////////////// |
---|
| 155 | //fractalWalkProc |
---|
| 156 | /////////////////////////////////////////////////////////////////// |
---|
| 157 | //Description: The main function for the Fractalwalk-Algorithm. |
---|
| 158 | //Responsible for contact between user and walk64. Checks the |
---|
| 159 | //input-data, and calls fractalWalk64. Returns the new groebner |
---|
| 160 | //basis or something else if an error occured. |
---|
| 161 | /////////////////////////////////////////////////////////////////// |
---|
| 162 | //Uses: omAlloc0,fractalWalkConsistency,omFreeSize,sizeof,IDIDEAL, |
---|
| 163 | //fractalWalk64,rSetHdl,idrMoveR,Werror,idInit |
---|
| 164 | /////////////////////////////////////////////////////////////////// |
---|
| 165 | |
---|
| 166 | ideal |
---|
| 167 | fractalWalkProc(leftv first, leftv second) |
---|
| 168 | { |
---|
| 169 | |
---|
| 170 | //unperturbedStartVectorStrategy SHOULD BE SET BY THE USER THROUGH |
---|
| 171 | //A THIRD ARGUMENT. TRUE MEANS THAT THE UNPERTURBED START |
---|
[0deb6a] | 172 | //VECTOR STRATEGY IS USED AND FALSE THAT THE START VECTOR IS |
---|
[54e28f] | 173 | //MAXIMALLY PERTURBED |
---|
| 174 | |
---|
| 175 | BOOLEAN unperturbedStartVectorStrategy=TRUE; |
---|
| 176 | |
---|
| 177 | WalkState state = WalkOk; |
---|
[d30a399] | 178 | BITSET save1,save2; |
---|
| 179 | SI_SAVE_OPT(save1,save2); |
---|
| 180 | si_opt_1 &= (~Sy_bit(OPT_REDSB)); //make sure option noredSB is set |
---|
[54e28f] | 181 | |
---|
| 182 | ring destRing = currRing; |
---|
| 183 | ideal destIdeal = NULL; |
---|
| 184 | idhdl sourceRingHdl = (idhdl)first->data; |
---|
| 185 | rSetHdl( sourceRingHdl ); |
---|
| 186 | ring sourceRing = currRing; |
---|
| 187 | |
---|
[3bef0a] | 188 | int * vperm = (int *)omAlloc0( (currRing->N+1)*sizeof( int ) ); |
---|
[0deb6a] | 189 | state= fractalWalkConsistency( sourceRing, destRing, vperm ); |
---|
[3bef0a] | 190 | omFreeSize( (ADDRESS)vperm, (currRing->N+1)*sizeof(int) ); |
---|
[54e28f] | 191 | |
---|
| 192 | ideal sourceIdeal; |
---|
| 193 | BOOLEAN sourcIdealIsSB=FALSE; |
---|
| 194 | if ( state == WalkOk ) { |
---|
| 195 | idhdl ih = currRing->idroot->get( second->Name(), myynest ); |
---|
| 196 | if ( (ih != NULL) && (IDTYP(ih)==IDEAL_CMD) ) { |
---|
| 197 | sourceIdeal = IDIDEAL( ih ); |
---|
| 198 | if(hasFlag((leftv)ih,FLAG_STD)){ |
---|
| 199 | sourcIdealIsSB=TRUE; |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | else { |
---|
| 203 | state=WalkNoIdeal; |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | if ( state == WalkOk ) { |
---|
| 208 | // Now the settings are compatible with Walk |
---|
| 209 | state=fractalWalk64(sourceIdeal,destRing,destIdeal, |
---|
| 210 | sourcIdealIsSB, |
---|
| 211 | unperturbedStartVectorStrategy); |
---|
| 212 | } |
---|
| 213 | |
---|
[d30a399] | 214 | SI_RESTORE_OPT(save1,save2);//making sure options are as before functiocall |
---|
[54e28f] | 215 | |
---|
| 216 | if ( state == WalkOk ) |
---|
| 217 | { |
---|
| 218 | ring almostDestRing=currRing; |
---|
[0deb6a] | 219 | rChangeCurrRing(destRing); |
---|
[69745c] | 220 | destIdeal=idrMoveR(destIdeal, almostDestRing, destRing); |
---|
[54e28f] | 221 | } |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | switch (state) { |
---|
| 225 | |
---|
| 226 | case WalkOk: |
---|
| 227 | destIdeal=sortRedSB(destIdeal); |
---|
| 228 | return(destIdeal); |
---|
| 229 | break; |
---|
| 230 | |
---|
| 231 | case WalkIncompatibleRings: |
---|
| 232 | Werror( "ring %s and current ring are incompatible\n", |
---|
| 233 | first->Name() ); |
---|
[0deb6a] | 234 | rChangeCurrRing(destRing); |
---|
[ebbb9c] | 235 | destIdeal= NULL; |
---|
[54e28f] | 236 | return destIdeal; |
---|
| 237 | break; |
---|
| 238 | |
---|
| 239 | case WalkIncompatibleDestRing: |
---|
| 240 | Werror( "Order of basering not allowed,\n must be a combination of lp,dp,Dp,wp,Wp and C or just M.\n"); |
---|
[0deb6a] | 241 | rChangeCurrRing(destRing); |
---|
[ebbb9c] | 242 | destIdeal= NULL; |
---|
[54e28f] | 243 | return destIdeal; |
---|
| 244 | break; |
---|
| 245 | |
---|
| 246 | case WalkIncompatibleSourceRing: |
---|
| 247 | Werror( "Order of %s not allowed,\n must be a combination of lp,dp,Dp,wp,Wp and C or just M.\n", |
---|
| 248 | first->Name()); |
---|
[0deb6a] | 249 | rChangeCurrRing(destRing); |
---|
[ebbb9c] | 250 | destIdeal= NULL; |
---|
[54e28f] | 251 | return destIdeal; |
---|
| 252 | break; |
---|
| 253 | |
---|
| 254 | case WalkNoIdeal: |
---|
| 255 | Werror( "Can't find ideal %s in ring %s.\n", |
---|
| 256 | second->Name(), first->Name() ); |
---|
[0deb6a] | 257 | rChangeCurrRing(destRing); |
---|
[ebbb9c] | 258 | destIdeal= NULL; |
---|
[54e28f] | 259 | return destIdeal; |
---|
| 260 | break; |
---|
| 261 | |
---|
| 262 | case WalkOverFlowError: |
---|
[1573a3] | 263 | Werror( "Overflow occured in ring %s.\n", first->Name() ); |
---|
[0deb6a] | 264 | rChangeCurrRing(destRing); |
---|
[ebbb9c] | 265 | destIdeal= NULL; |
---|
[54e28f] | 266 | return destIdeal; |
---|
| 267 | break; |
---|
| 268 | |
---|
| 269 | default: |
---|
[0deb6a] | 270 | rChangeCurrRing(destRing); |
---|
[54e28f] | 271 | destIdeal= idInit(1,1); |
---|
| 272 | return destIdeal; |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | |
---|
| 276 | return NULL; |
---|
| 277 | } |
---|
| 278 | |
---|
| 279 | |
---|
| 280 | /////////////////////////////////////////////////////////////////// |
---|
| 281 | //getiv64 |
---|
| 282 | /////////////////////////////////////////////////////////////////// |
---|
| 283 | //Description: retrieves the int64vec from input list l |
---|
| 284 | /////////////////////////////////////////////////////////////////// |
---|
| 285 | //Assumes: that the first entry of l is an int64vec |
---|
| 286 | /////////////////////////////////////////////////////////////////// |
---|
| 287 | //Uses: none |
---|
| 288 | /////////////////////////////////////////////////////////////////// |
---|
| 289 | |
---|
| 290 | int64vec* getiv64(lists l) |
---|
| 291 | { |
---|
| 292 | return (int64vec*)(l->m[0].data); |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | /////////////////////////////////////////////////////////////////// |
---|
| 296 | |
---|
| 297 | |
---|
| 298 | /////////////////////////////////////////////////////////////////// |
---|
| 299 | //getint64 |
---|
| 300 | /////////////////////////////////////////////////////////////////// |
---|
| 301 | //Description: retrieves the int64 from input list l |
---|
| 302 | /////////////////////////////////////////////////////////////////// |
---|
| 303 | //Assumes: that the second entry of l is an int64 |
---|
| 304 | /////////////////////////////////////////////////////////////////// |
---|
| 305 | //Uses: none |
---|
| 306 | /////////////////////////////////////////////////////////////////// |
---|
| 307 | |
---|
[def568] | 308 | // not used, bad impl. |
---|
| 309 | //int64 getint64(lists l) |
---|
| 310 | //{ |
---|
| 311 | // return (int64)(long)(l->m[1].data); |
---|
| 312 | //} |
---|
[54e28f] | 313 | |
---|
| 314 | /////////////////////////////////////////////////////////////////// |
---|