source: git/Singular/walk_ip.cc @ 667ba1

spielwiese
Last change on this file since 667ba1 was 762407, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
config.h is for sources files only FIX: config.h should only be used by source (not from inside kernel/mod2.h!) NOTE: each source file should better include mod2.h right after config.h, while headers should better not include mod2.h.
  • Property mode set to 100644
File size: 9.5 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5/*
6* ABSTRACT: frwalk: interpreter link
7*/
8
9//#include <stdlib.h>
10#include <stdio.h>
11#include <string.h>
12#include <ctype.h>
13#include <math.h>
14
15#include "config.h"
16#include <kernel/mod2.h>
17#include <Singular/tok.h>
18#include <misc/options.h>
19#include <Singular/ipid.h>
20#include <misc/intvec.h>
21#include <omalloc/omalloc.h>
22#include <kernel/febase.h>
23#include <kernel/polys.h>
24#include <kernel/ideals.h>
25#include <polys/matpol.h>
26#include <kernel/kstd1.h>
27#include <polys/monomials/ring.h>
28#include <Singular/subexpr.h>
29#include <polys/monomials/maps.h>
30#include <kernel/syz.h>
31#include <coeffs/numbers.h>
32#include <Singular/lists.h>
33#include <Singular/attrib.h>
34#include <Singular/ipconv.h>
35#include <Singular/silink.h>
36#include <kernel/stairc.h>
37#include <polys/weight.h>
38#include <kernel/semic.h>
39#include <kernel/splist.h>
40#include <kernel/spectrum.h>
41//#include <kernel/gnumpfl.h>
42//#include <kernel/mpr_base.h>
43//#include <kernel/ffields.h>
44#include <polys/clapsing.h>
45#include <kernel/hutil.h>
46#include <Singular/ipshell.h>
47#include <kernel/walkMain.h>
48#include <kernel/walkProc.h>
49#include <kernel/walkSupport.h>
50#include <polys/prCopy.h>
51
52///////////////////////////////////////////////////////////////////
53//walkProc
54///////////////////////////////////////////////////////////////////
55//Description: The main function for the Walk-Algorithm. Checks the
56//input-data, and calls walk64 (see walkMain.cc). Returns the new
57//groebner basis or something else if an error occoured.
58///////////////////////////////////////////////////////////////////
59//Uses: omAlloc0,walkConsistency,rGetGlobalOrderWeightVec,
60//omFreeSize,sizeof,IDIDEAL,walk64,rSetHdl,idrMoveR,Werror,idInit
61///////////////////////////////////////////////////////////////////
62
63ideal
64walkProc(leftv first, leftv second)
65{
66    WalkState state = WalkOk;
67    BITSET saveTest=test;
68    test &= (~Sy_bit(OPT_REDSB)); //make sure option noredSB is set
69
70    ring destRing = currRing;
71    ideal destIdeal = NULL;
72    idhdl sourceRingHdl = (idhdl)first->data;
73    ring sourceRing = IDRING(sourceRingHdl);
74    rChangeCurrRing( sourceRing );
75
76    if(state==WalkOk)
77    {
78      int * vperm = (int *)omAlloc0( (currRing->N+1)*sizeof( int ) );
79      state= walkConsistency( sourceRing, destRing, vperm );
80      omFreeSize( (ADDRESS)vperm, (currRing->N+1)*sizeof(int) );
81    }
82
83    int64vec* currw64=rGetGlobalOrderWeightVec(sourceRing);
84    int64vec* destVec64=rGetGlobalOrderWeightVec(destRing);
85
86    ideal sourceIdeal;
87    BOOLEAN sourcIdealIsSB=FALSE;
88    if ( state == WalkOk )
89    {
90      idhdl ih = currRing->idroot->get( second->Name(), myynest );
91      if ( (ih != NULL) && (IDTYP(ih)==IDEAL_CMD) )
92      {
93           sourceIdeal = idCopy(IDIDEAL( ih ));
94           if(hasFlag((leftv)ih,FLAG_STD)){
95              sourcIdealIsSB=TRUE;
96           }
97      }
98      else
99      {
100        state=WalkNoIdeal;
101      }
102    }
103
104    if ( state == WalkOk )
105    {
106      // Now the settings are compatible with Walk
107      state=walk64(sourceIdeal,currw64,destRing,destVec64,
108                   destIdeal,sourcIdealIsSB);
109    }
110
111    test=saveTest;//making sure options are as before function call
112
113    ring almostDestRing=currRing;
114    rChangeCurrRing(destRing);
115
116    switch (state) {
117        case WalkOk:
118          destIdeal=idrMoveR(destIdeal,currRing,almostDestRing);
119          break;
120
121        case WalkIncompatibleRings:
122          Werror("ring %s and current ring are incompatible\n",
123                 first->Name() );
124          destIdeal= idInit(0,0);
125          break;
126
127        case WalkIncompatibleDestRing:
128          Werror( "Order of basering not allowed,\n must be a combination of a,A,lp,dp,Dp,wp,Wp,M and C.\n");
129          destIdeal= idInit(0,0);
130          break;
131
132        case WalkIncompatibleSourceRing:
133          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());
134          rChangeCurrRing(destRing);
135          destIdeal= idInit(0,0);
136          break;
137
138        case WalkNoIdeal:
139          Werror( "Can't find ideal %s in ring %s.\n",
140                   second->Name(), first->Name() );
141          destIdeal= idInit(0,0);
142          break;
143
144        case WalkOverFlowError:
145          Werror( "Overflow occured.\n");
146          destIdeal= idInit(0,0);
147          break;
148
149        default:
150           destIdeal= idInit(1,1);
151    }
152
153    return destIdeal;
154}
155
156///////////////////////////////////////////////////////////////////
157//fractalWalkProc
158///////////////////////////////////////////////////////////////////
159//Description: The main function for the Fractalwalk-Algorithm.
160//Responsible for contact between user and walk64. Checks the
161//input-data, and calls fractalWalk64. Returns the new groebner
162//basis or something else if an error occured.
163///////////////////////////////////////////////////////////////////
164//Uses: omAlloc0,fractalWalkConsistency,omFreeSize,sizeof,IDIDEAL,
165//fractalWalk64,rSetHdl,idrMoveR,Werror,idInit
166///////////////////////////////////////////////////////////////////
167
168ideal
169fractalWalkProc(leftv first, leftv second)
170{
171
172  //unperturbedStartVectorStrategy SHOULD BE SET BY THE USER THROUGH
173  //A THIRD ARGUMENT. TRUE MEANS THAT THE UNPERTURBED START
174  //VECTOR STRATEGY IS USED AND FALSE THAT THE START VECTOR IS
175  //MAXIMALLY PERTURBED
176
177    BOOLEAN unperturbedStartVectorStrategy=TRUE;
178
179    WalkState state = WalkOk;
180    BITSET saveTest=test;
181    test &= (~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    test=saveTest;//making sure options are as before functiocall
216
217     if ( state == WalkOk )
218     {
219       ring almostDestRing=currRing;
220       rChangeCurrRing(destRing);
221       destIdeal=idrMoveR(destIdeal,destRing,almostDestRing);
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= idInit(0,0);
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= idInit(0,0);
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= idInit(0,0);
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= idInit(0,0);
260            return destIdeal;
261            break;
262
263        case WalkOverFlowError:
264            Werror( "Overflow occured in ring %s.\n", first->Name() );
265            rChangeCurrRing(destRing);
266            destIdeal= idInit(0,0);
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.