source: git/Singular/walk_ip.cc @ fd1b1be

fieker-DuValspielwiese
Last change on this file since fd1b1be was fd1b1be, checked in by Oleksandr Motsak <motsak@…>, 10 years ago
Minor header correction
  • Property mode set to 100644
File size: 9.6 KB
RevLine 
[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>
[599326]14#include <kernel/febase.h>
[737a68]15#include <kernel/polys.h>
[599326]16#include <kernel/ideals.h>
[0fb34ba]17#include <polys/matpol.h>
[57fa2c4]18#include <kernel/GBEngine/kstd1.h>
[0fb34ba]19#include <polys/monomials/ring.h>
[599326]20#include <Singular/subexpr.h>
[0fb34ba]21#include <polys/monomials/maps.h>
[57fa2c4]22#include <kernel/GBEngine/syz.h>
[0fb34ba]23#include <coeffs/numbers.h>
[599326]24#include <Singular/lists.h>
25#include <Singular/attrib.h>
26#include <Singular/ipconv.h>
[44ca2f]27#include <Singular/links/silink.h>
[57fa2c4]28#include <kernel/GBEngine/stairc.h>
[0fb34ba]29#include <polys/weight.h>
[54764c8]30#include <kernel/spectrum/semic.h>
31#include <kernel/spectrum/splist.h>
32#include <kernel/spectrum/spectrum.h>
[47417b]33//#include <kernel/gnumpfl.h>
34//#include <kernel/mpr_base.h>
35//#include <kernel/ffields.h>
36#include <polys/clapsing.h>
[5ab313]37#include <kernel/combinatorics/hutil.h>
[599326]38#include <Singular/ipshell.h>
[b88d52]39#include <kernel/groebner_walk/walkMain.h>
40#include <kernel/groebner_walk/walkProc.h>
41#include <kernel/groebner_walk/walkSupport.h>
[0fb34ba]42#include <polys/prCopy.h>
[54e28f]43
[fd1b1be]44//#include <stdlib.h>
45#include <stdio.h>
46#include <string.h>
47#include <ctype.h>
48#include <math.h>
49
[54e28f]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;
[d30a399]65    BITSET save1,save2;
66    SI_SAVE_OPT(save1,save2);
67    si_opt_1 &= (~Sy_bit(OPT_REDSB)); //make sure option noredSB is set
[54e28f]68
69    ring destRing = currRing;
70    ideal destIdeal = NULL;
71    idhdl sourceRingHdl = (idhdl)first->data;
[0deb6a]72    ring sourceRing = IDRING(sourceRingHdl);
73    rChangeCurrRing( sourceRing );
[54e28f]74
75    if(state==WalkOk)
76    {
[3bef0a]77      int * vperm = (int *)omAlloc0( (currRing->N+1)*sizeof( int ) );
[0deb6a]78      state= walkConsistency( sourceRing, destRing, vperm );
[3bef0a]79      omFreeSize( (ADDRESS)vperm, (currRing->N+1)*sizeof(int) );
[54e28f]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
[d30a399]110    SI_RESTORE_OPT(save1,save2);//making sure options are as before function call
[54e28f]111
112    ring almostDestRing=currRing;
[0deb6a]113    rChangeCurrRing(destRing);
[54e28f]114
115    switch (state) {
116        case WalkOk:
[3bef0a]117          destIdeal=idrMoveR(destIdeal,currRing,almostDestRing);
[54e28f]118          break;
119
120        case WalkIncompatibleRings:
121          Werror("ring %s and current ring are incompatible\n",
122                 first->Name() );
[ebbb9c]123          destIdeal= NULL;
[54e28f]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");
[ebbb9c]128          destIdeal= NULL;
[54e28f]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());
[0deb6a]133          rChangeCurrRing(destRing);
[ebbb9c]134          destIdeal= NULL;
[54e28f]135          break;
136
137        case WalkNoIdeal:
138          Werror( "Can't find ideal %s in ring %s.\n",
139                   second->Name(), first->Name() );
[ebbb9c]140          destIdeal= NULL;
[54e28f]141          break;
142
143        case WalkOverFlowError:
144          Werror( "Overflow occured.\n");
[ebbb9c]145          destIdeal= NULL;
[54e28f]146          break;
147
148        default:
[ebbb9c]149           destIdeal= NULL;
[54e28f]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
[0deb6a]173  //VECTOR STRATEGY IS USED AND FALSE THAT THE START VECTOR IS
[54e28f]174  //MAXIMALLY PERTURBED
175
176    BOOLEAN unperturbedStartVectorStrategy=TRUE;
177
178    WalkState state = WalkOk;
[d30a399]179    BITSET save1,save2;
180    SI_SAVE_OPT(save1,save2);
181    si_opt_1 &= (~Sy_bit(OPT_REDSB)); //make sure option noredSB is set
[54e28f]182
183    ring destRing = currRing;
184    ideal destIdeal = NULL;
185    idhdl sourceRingHdl = (idhdl)first->data;
186    rSetHdl( sourceRingHdl );
187    ring sourceRing = currRing;
188
[3bef0a]189    int * vperm = (int *)omAlloc0( (currRing->N+1)*sizeof( int ) );
[0deb6a]190    state= fractalWalkConsistency( sourceRing, destRing, vperm );
[3bef0a]191    omFreeSize( (ADDRESS)vperm, (currRing->N+1)*sizeof(int) );
[54e28f]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
[d30a399]215    SI_RESTORE_OPT(save1,save2);//making sure options are as before functiocall
[54e28f]216
217     if ( state == WalkOk )
218     {
219       ring almostDestRing=currRing;
[0deb6a]220       rChangeCurrRing(destRing);
[69745c]221       destIdeal=idrMoveR(destIdeal, almostDestRing, destRing);
[54e28f]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() );
[0deb6a]235            rChangeCurrRing(destRing);
[ebbb9c]236            destIdeal= NULL;
[54e28f]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");
[0deb6a]242            rChangeCurrRing(destRing);
[ebbb9c]243            destIdeal= NULL;
[54e28f]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());
[0deb6a]250            rChangeCurrRing(destRing);
[ebbb9c]251            destIdeal= NULL;
[54e28f]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() );
[0deb6a]258            rChangeCurrRing(destRing);
[ebbb9c]259            destIdeal= NULL;
[54e28f]260            return destIdeal;
261            break;
262
263        case WalkOverFlowError:
[1573a3]264            Werror( "Overflow occured in ring %s.\n", first->Name() );
[0deb6a]265            rChangeCurrRing(destRing);
[ebbb9c]266            destIdeal= NULL;
[54e28f]267            return destIdeal;
268            break;
269
270        default:
[0deb6a]271            rChangeCurrRing(destRing);
[54e28f]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
[def568]309// not used, bad impl.
310//int64 getint64(lists l)
311//{
312//  return (int64)(long)(l->m[1].data);
313//}
[54e28f]314
315///////////////////////////////////////////////////////////////////
Note: See TracBrowser for help on using the repository browser.