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