source: git/Singular/walk_ip.cc @ 4676d5

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