My Project
Loading...
Searching...
No Matches
kstdhelper.cc File Reference

Go to the source code of this file.

Functions

static int kFindLuckyPrime (ideal F, ideal Q)
 
poly kTryHC (ideal F, ideal Q)
 
static ideal kTryHilbstd_homog (ideal F, ideal Q)
 
static ideal kTryHilbstd_nonhomog (ideal F, ideal Q)
 
ideal kTryHilbstd (ideal F, ideal Q)
 
ideal kTryHilbstd_par (ideal F, ideal Q, tHomog h, intvec **mw)
 

Function Documentation

◆ kFindLuckyPrime()

static int kFindLuckyPrime ( ideal F,
ideal Q )
static

Definition at line 26 of file kstdhelper.cc.

27{
28 int prim=32003;
29 // assume coeff are in Q
30 return prim;
31}

◆ kTryHC()

poly kTryHC ( ideal F,
ideal Q )

Definition at line 33 of file kstdhelper.cc.

34{
35 if (Q!=NULL)
36 return NULL;
37 int prim=kFindLuckyPrime(F,Q);
38 if (TEST_OPT_PROT) Print("try HC in ring over ZZ/%d\n",prim);
39 // create Zp_ring
40 ring save_ring=currRing;
41 ring Zp_ring=rCopy0(save_ring);
42 nKillChar(Zp_ring->cf);
43 Zp_ring->cf=nInitChar(n_Zp, (void*)(long)prim);
44 rComplete(Zp_ring);
45 // map data
46 rChangeCurrRing(Zp_ring);
47 nMapFunc nMap=n_SetMap(save_ring->cf,Zp_ring->cf);
48 if (nMap==NULL) return NULL;
49 ideal FF=id_PermIdeal(F,1,IDELEMS(F),NULL,save_ring,Zp_ring,nMap,NULL,0,0);
50 ideal QQ=NULL;
51 if (Q!=NULL) QQ=id_PermIdeal(Q,1,IDELEMS(Q),NULL,save_ring,Zp_ring,nMap,NULL,0,0);
52 // call std
53 kStrategy strat=new skStrategy;
54 strat->LazyPass=20;
55 strat->LazyDegree = 1;
56 strat->kModW=kModW=NULL;
57 strat->kHomW=kHomW=NULL;
58 strat->homog = (tHomog)idHomIdeal(F,Q);
59 ideal res=mora(FF,QQ,NULL,NULL,strat);
60 // clean
61 idDelete(&FF);
62 poly HC=NULL;
63 if (strat->kNoether!=NULL) scComputeHC(res,QQ,0,HC);
64 delete strat;
65 if (QQ!=NULL) idDelete(&QQ);
66 idDelete(&res);
67 // map back
68 rChangeCurrRing(save_ring);
69 if (HC!=NULL)
70 {
71 //p_IncrExp(HC,Zp_ring->N,Zp_ring);
72 for (int i=rVar(Zp_ring)-1; i>0; i--)
73 {
74 if (pGetExp(HC, i) > 0) pDecrExp(HC,i);
75 }
76 p_Setm(HC,Zp_ring);
77 if (TEST_OPT_PROT) Print("HC(%ld) found\n",pTotaldegree(HC));
78 pSetCoeff0(HC,nInit(1));
79 }
80 else
81 {
82 if (TEST_OPT_PROT) PrintS("HC not found\n");
83 }
84 rDelete(Zp_ring);
85 return HC;
86}
int i
Definition cfEzgcd.cc:132
intvec * kModW
Definition kutil.h:336
poly kNoether
Definition kutil.h:330
intvec * kHomW
Definition kutil.h:337
int LazyPass
Definition kutil.h:354
int LazyDegree
Definition kutil.h:354
char homog
Definition kutil.h:371
@ n_Zp
\F{p < 2^31}
Definition coeffs.h:29
static FORCE_INLINE nMapFunc n_SetMap(const coeffs src, const coeffs dst)
set the mapping function pointers for translating numbers from src to dst
Definition coeffs.h:701
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:406
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
void nKillChar(coeffs r)
undo all initialisations
Definition numbers.cc:556
#define Print
Definition emacs.cc:80
CanonicalForm res
Definition facAbsFact.cc:60
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge)
Definition hdegree.cc:1074
#define idDelete(H)
delete an ideal
Definition ideals.h:29
static BOOLEAN idHomIdeal(ideal id, ideal Q=NULL)
Definition ideals.h:91
ideal mora(ideal F, ideal Q, intvec *w, bigintmat *hilb, kStrategy strat)
Definition kstd1.cc:1878
VAR intvec * kHomW
Definition kstd1.cc:2405
VAR intvec * kModW
Definition kstd1.cc:2405
static int kFindLuckyPrime(ideal F, ideal Q)
Definition kstdhelper.cc:26
#define pSetCoeff0(p, n)
Definition monomials.h:59
#define nInit(i)
Definition numbers.h:24
#define NULL
Definition omList.c:12
#define TEST_OPT_PROT
Definition options.h:105
static void p_Setm(poly p, const ring r)
Definition p_polys.h:235
void rChangeCurrRing(ring r)
Definition polys.cc:16
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
static long pTotaldegree(poly p)
Definition polys.h:283
#define pGetExp(p, i)
Exponent.
Definition polys.h:42
#define pDecrExp(p, i)
Definition polys.h:45
void PrintS(const char *s)
Definition reporter.cc:284
BOOLEAN rComplete(ring r, int force)
this needs to be called whenever a new ring is created: new fields in ring are created (like VarOffse...
Definition ring.cc:3526
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition ring.cc:1426
void rDelete(ring r)
unconditionally deletes fields in r
Definition ring.cc:454
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition ring.h:598
ideal id_PermIdeal(ideal I, int R, int C, const int *perm, const ring src, const ring dst, nMapFunc nMap, const int *par_perm, int P, BOOLEAN use_mult)
mapping ideals/matrices to other rings
#define IDELEMS(i)
#define Q
Definition sirandom.c:26
tHomog
Definition structs.h:31
skStrategy * kStrategy
Definition structs.h:54

◆ kTryHilbstd()

ideal kTryHilbstd ( ideal F,
ideal Q )

Definition at line 270 of file kstdhelper.cc.

271{
272 if(!TEST_V_PURE_GB)
273 {
275 if (h==(tHomog)TRUE) return kTryHilbstd_homog(F,Q);
276 if (h==(tHomog)FALSE) return kTryHilbstd_nonhomog(F,Q);
277 }
278 return NULL;
279}
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
STATIC_VAR Poly * h
Definition janet.cc:971
static ideal kTryHilbstd_nonhomog(ideal F, ideal Q)
static ideal kTryHilbstd_homog(ideal F, ideal Q)
Definition kstdhelper.cc:90
#define TEST_V_PURE_GB
Definition options.h:137
BOOLEAN id_HomIdealDP(ideal id, ideal Q, const ring r)

◆ kTryHilbstd_homog()

static ideal kTryHilbstd_homog ( ideal F,
ideal Q )
static

Definition at line 90 of file kstdhelper.cc.

91{
92 // create Zp_ring
93 ring save_ring=currRing;
94 BITSET save_opt;SI_SAVE_OPT1(save_opt);
95 int prim=kFindLuckyPrime(F,Q);
96 coeffs cf=nInitChar(n_Zp, (void*)(long)prim);
97 ring Zp_ring=rDefault(cf,save_ring->N,save_ring->names,ringorder_dp);
98 // map data
99 nMapFunc nMap=n_SetMap(save_ring->cf,Zp_ring->cf);
100 if (nMap==NULL) return NULL;
101 rChangeCurrRing(Zp_ring);
102 ideal FF=id_PermIdeal(F,1,IDELEMS(F),NULL,save_ring,Zp_ring,nMap,NULL,0,0);
103 ideal QQ=NULL;
104 if (Q!=NULL) QQ=id_PermIdeal(Q,1,IDELEMS(Q),NULL,save_ring,Zp_ring,nMap,NULL,0,0);
105 // compute GB in Zp_ring
108 if(TEST_OPT_PROT) PrintS("std in charp ------------------\n");
109 ideal GB=kStd_internal(FF,QQ,(tHomog)TRUE,NULL,NULL,0,0,NULL,NULL);
110 // compute hilb
111 bigintmat* hilb=hFirstSeries0b(GB,QQ,NULL,NULL,Zp_ring,coeffs_BIGINT);
112 // clean up Zp_ring
113 rChangeCurrRing(save_ring);
114 id_Delete(&GB,Zp_ring);
115 id_Delete(&FF,Zp_ring);
116 if (QQ!=NULL) id_Delete(&QQ,Zp_ring);
117 rDelete(Zp_ring);
118 // std with hilb
119 intvec *w=NULL;
120 if(TEST_OPT_PROT) PrintS("stdhilb in basering ------------------\n");
121 SI_RESTORE_OPT1(save_opt);
122 ideal result=kStd_internal(F,Q,(tHomog)TRUE,&w,hilb);
123 if (w!=NULL) delete w;
124 delete hilb;
125 return result;
126}
#define BITSET
Definition auxiliary.h:85
CanonicalForm cf
Definition cfModGcd.cc:4091
Matrices of numbers.
Definition bigintmat.h:51
return result
const CanonicalForm & w
Definition facAbsFact.cc:51
bigintmat * hFirstSeries0b(ideal I, ideal Q, intvec *wdegree, intvec *shifts, const ring src, const coeffs biv_cf)
Definition hilb.cc:2655
ideal kStd_internal(ideal F, ideal Q, tHomog h, intvec **w, bigintmat *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
pure GB/SB computations
Definition kstd1.cc:2430
The main handler for Singular numbers which are suitable for Singular polynomials.
VAR unsigned si_opt_1
Definition options.c:5
#define OPT_REDTAIL
Definition options.h:92
#define SI_SAVE_OPT1(A)
Definition options.h:21
#define SI_RESTORE_OPT1(A)
Definition options.h:24
#define OPT_REDSB
Definition options.h:77
#define Sy_bit(x)
Definition options.h:31
VAR coeffs coeffs_BIGINT
Definition polys.cc:14
ring rDefault(const coeffs cf, int N, char **n, int ord_size, rRingOrder_t *ord, int *block0, int *block1, int **wvhdl, unsigned long bitmask)
Definition ring.cc:103
@ ringorder_dp
Definition ring.h:79
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix

◆ kTryHilbstd_nonhomog()

static ideal kTryHilbstd_nonhomog ( ideal F,
ideal Q )
static

Definition at line 128 of file kstdhelper.cc.

129{
130 if(TEST_OPT_PROT) PrintS("std in charp, homogenized ------------------\n");
131 // create Zp_ring, need 1 more variable
132 ring save_ring=currRing;
133 BITSET save_opt;SI_SAVE_OPT1(save_opt);
134 coeffs cf=nInitChar(n_Zp, (void*)(long)32003);
135 char **names=(char**)omAlloc0((currRing->N+1) * sizeof(char *));
136 for(int i=0;i<currRing->N;i++)
137 {
138 names[i]=omStrDup(currRing->names[i]);
139 }
140 names[currRing->N]=omStrDup("@");
141 ring Zp_ring=rDefault(cf,save_ring->N+1,names,ringorder_dp);
142 // map data
143 nMapFunc nMap=n_SetMap(save_ring->cf,Zp_ring->cf);
144 if (nMap==NULL) return NULL;
145 rChangeCurrRing(Zp_ring);
146 ideal FF=id_PermIdeal(F,1,IDELEMS(F),NULL,save_ring,Zp_ring,nMap,NULL,0,0);
147 ideal QQ=NULL;
148 if (Q!=NULL) QQ=id_PermIdeal(Q,1,IDELEMS(Q),NULL,save_ring,Zp_ring,nMap,NULL,0,0);
149 // homogenize
150 ideal tmp=id_HomogenDP(FF,Zp_ring->N,Zp_ring);
151 id_Delete(&FF,Zp_ring);
152 FF=tmp;
153 if (QQ!=NULL)
154 {
155 tmp=id_HomogenDP(QQ,Zp_ring->N,Zp_ring);
156 id_Delete(&QQ,Zp_ring);
157 QQ=tmp;
158 }
159 // compute GB in Zp_ring
162 ideal GB=kStd_internal(FF,QQ,(tHomog)TRUE,NULL,NULL,0,0,NULL,NULL);
163 // compute hilb
164 bigintmat* hilb=hFirstSeries0b(GB,QQ,NULL,NULL,Zp_ring,coeffs_BIGINT);
165 // clean up Zp_ring
166 id_Delete(&GB,Zp_ring);
167 id_Delete(&FF,Zp_ring);
168 if (QQ!=NULL) id_Delete(&QQ,Zp_ring);
169 rChangeCurrRing(save_ring);
170 rDelete(Zp_ring);
171 //omFreeBin(Zp_ring,sip_sring_bin);
172 // create Q_ring
173 cf=nCopyCoeff(save_ring->cf);
174 int nblocks=rBlocks(save_ring)+1;
175 names=(char**)omAlloc0((save_ring->N+1) * sizeof(char *));
176 for(int i=0;i<save_ring->N;i++)
177 {
178 names[i]=omStrDup(save_ring->names[i]);
179 }
180 names[save_ring->N]=omStrDup("@");
181 rRingOrder_t *order = (rRingOrder_t *) omAlloc(nblocks* sizeof(rRingOrder_t));
182 int *block0 = (int *)omAlloc0(nblocks * sizeof(int));
183 int *block1 = (int *)omAlloc0(nblocks * sizeof(int));
184 int **wvhdl=(int**)omAlloc0(nblocks * sizeof(int *));
185 for (int j=0; j<nblocks-1; j++)
186 {
187 if (save_ring->wvhdl[j]!=NULL)
188 {
189 #ifdef HAVE_OMALLOC
190 wvhdl[j] = (int*) omMemDup(save_ring->wvhdl[j]);
191 #else
192 {
193 int l=save_ring->block1[j]-save_ring->block0[j]+1;
194 if (save_ring->order[j]==ringorder_a64) l*=2;
195 else if (save_ring->order[j]==ringorder_M) l=l*l;
196 else if (save_ring->order[j]==ringorder_am)
197 {
198 l+=save_ring->wvhdl[j][save_ring->block1[j]-save_ring->block0[j]+1]+1;
199 }
200 wvhdl[j]=(int*)omalloc(l*sizeof(int));
201 memcpy(wvhdl[j],save_ring->wvhdl[j],l*sizeof(int));
202 }
203 #endif
204 }
205 }
206 memcpy(order,save_ring->order,(nblocks-1) * sizeof(rRingOrder_t));
207 memcpy(block0,save_ring->block0,(nblocks-1) * sizeof(int));
208 memcpy(block1,save_ring->block1,(nblocks-1) * sizeof(int));
209 order[nblocks-1]=ringorder_lp;
210 block0[nblocks-1]=save_ring->N+1;
211 block1[nblocks-1]=save_ring->N+1;
212
213 ring Q_ring=rDefault(cf,save_ring->N+1,names,nblocks,order,block0,block1,wvhdl,save_ring->wanted_maxExp);
214 // map data
215 nMap=n_SetMap(save_ring->cf,Q_ring->cf);
216 if (nMap==NULL) return NULL;
217 rChangeCurrRing(Q_ring);
218 FF=id_PermIdeal(F,1,IDELEMS(F),NULL,save_ring,Q_ring,nMap,NULL,0,0);
219 QQ=NULL;
220 if (Q!=NULL) QQ=id_PermIdeal(Q,1,IDELEMS(Q),NULL,save_ring,Q_ring,nMap,NULL,0,0);
221 // homogenize
222 if(TEST_OPT_PROT) PrintS("stdhilb in basering, homogenized ------------------\n");
223 tmp=id_HomogenDP(FF,Q_ring->N,Q_ring);
224 id_Delete(&FF,Q_ring);
225 FF=tmp;
226 if (QQ!=NULL)
227 {
228 tmp=id_HomogenDP(QQ,Q_ring->N,Q_ring);
229 id_Delete(&QQ,Q_ring);
230 QQ=tmp;
231 }
232 // std with hilb
233 intvec *w=NULL;
234 tmp=kStd_internal(FF,QQ,testHomog,&w,hilb);
235 if (w!=NULL) delete w;
236 delete hilb;
237 // dehomogenize
238 if(TEST_OPT_PROT) PrintS("de-homogenize, interred ------------------\n");
239 poly one=pOne();
240 tmp=id_Subst(tmp,Q_ring->N,one,Q_ring);
241 p_Delete(&one,Q_ring);
242 // map back to save_ring
243 rChangeCurrRing(save_ring);
244 nMap=n_SetMap(Q_ring->cf,save_ring->cf);
245 GB=id_PermIdeal(tmp,1,IDELEMS(tmp),NULL,Q_ring,save_ring,nMap,NULL,0,0);
246 // clean up Q_ring
247 id_Delete(&FF,Q_ring);
248 if (QQ!=NULL) id_Delete(&QQ,Q_ring);
249 id_Delete(&tmp,Q_ring);
250 rDelete(Q_ring);
251 //omFreeBin(Q_ring,sip_sring_bin);
252 SI_RESTORE_OPT1(save_opt);
253 int dummy;
254 if (TEST_OPT_REDSB)
255 {
257 idSkipZeroes(GB);
258 ideal GB2=kInterRedBba(GB,currRing->qideal,dummy);
259 idDelete(&GB);
260 return GB2;
261 }
262 else
263 {
265 idSkipZeroes(GB);
266 return GB;
267 }
268}
int l
Definition cfEzgcd.cc:100
static FORCE_INLINE coeffs nCopyCoeff(const coeffs r)
"copy" coeffs, i.e. increment ref
Definition coeffs.h:437
int j
Definition facHensel.cc:110
ideal kInterRedBba(ideal F, ideal Q, int &need_retry)
Definition kstd1.cc:3546
#define omStrDup(s)
#define omAlloc(size)
#define omalloc(size)
#define omAlloc0(size)
#define omMemDup(s)
#define TEST_OPT_REDSB
Definition options.h:106
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
#define pOne()
Definition polys.h:316
static int rBlocks(const ring r)
Definition ring.h:574
rRingOrder_t
order stuff
Definition ring.h:69
@ ringorder_lp
Definition ring.h:78
@ ringorder_am
Definition ring.h:90
@ ringorder_a64
for int64 weights
Definition ring.h:72
@ ringorder_M
Definition ring.h:75
void id_DelDiv(ideal id, const ring r)
delete id[j], if LT(j) == coeff*mon*LT(i) and vice versa, i.e., delete id[i], if LT(i) == coeff*mon*L...
ideal id_HomogenDP(ideal h, int varnum, const ring r)
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
ideal id_Subst(ideal id, int n, poly e, const ring r)
@ testHomog
Definition structs.h:34

◆ kTryHilbstd_par()

ideal kTryHilbstd_par ( ideal F,
ideal Q,
tHomog h,
intvec ** mw )

Definition at line 281 of file kstdhelper.cc.

282{
283#if 0
284 if(!TEST_V_PURE_GB)
285 {
286 int cp_std[2];
287 int cp_hstd[2];
288 int err1=pipe(cp_std);// [0] is read , [1] is write
289 int err2=pipe(cp_hstd);
290 if (err1||err2)
291 {
292 Werror("pipe failed with %d\n",errno);
293 si_close(cp_std[0]);
294 si_close(cp_std[1]);
295 si_close(cp_hstd[0]);
296 si_close(cp_hstd[1]);
297 return NULL;
298 }
299 pid_t pid_std=fork();
300 if (pid_std==0) /*child std*/
301 {
303 si_close(cp_std[0]);
304 si_close(cp_hstd[0]);
305 si_close(cp_hstd[1]);
306 ssiInfo d;
307 memset(&d,0,sizeof(d));
308 d.f_write=fdopen(cp_std[1],"w");
309 d.fd_write=cp_std[1];
310 d.r=currRing;
312 ideal res=kStd_internal(F,Q,h,mw);
314 fclose(d.f_write);
315 _exit(0);
316 }
317 pid_t pid_hstd=fork();
318 if (pid_hstd==0) /*child hstd*/
319 {
321 si_close(cp_hstd[0]);
322 si_close(cp_std[0]);
323 si_close(cp_std[1]);
324 ssiInfo d;
325 memset(&d,0,sizeof(d));
326 d.f_write=fdopen(cp_hstd[1],"w");
327 d.fd_write=cp_hstd[1];
328 d.r=currRing;
329
331 ideal res=kTryHilbstd(F,Q);
332 if (res!=NULL)
333 {
335 }
336 fclose(d.f_write);
337 _exit(0);
338 }
339 /*parent*/
340 si_close(cp_std[1]);
341 si_close(cp_hstd[1]);
342 #ifdef HAVE_POLL
343 pollfd pfd[2];
344 pfd[0].fd=cp_std[0];
345 pfd[0].events=POLLIN;
346 pfd[1].fd=cp_hstd[0];
347 pfd[1].events=POLLIN;
348 int s=si_poll(pfd,2,-1); // wait infinite
349 ideal res;
350 ssiInfo d;
351 memset(&d,0,sizeof(d));
352 d.r=currRing;
353 if (s==1) //std
354 {
355 d.f_read=s_open(cp_std[0]);
356 d.fd_read=cp_std[0];
357 res=ssiReadIdeal(&d);
358 si_close(cp_hstd[0]);
359 s_close(d.f_read);
360 si_close(cp_std[0]);
361 kill(pid_hstd,SIGTERM);
362 si_waitpid(pid_std,NULL,0);
363 si_waitpid(pid_hstd,NULL,0);
364 }
365 else if(s==2)
366 {
367 d.f_read=s_open(cp_hstd[0]);
368 d.fd_read=cp_hstd[0];
369 res=ssiReadIdeal(&d);
370 si_close(cp_std[0]);
371 s_close(d.f_read);
372 si_close(cp_hstd[0]);
373 kill(pid_std,SIGTERM);
374 si_waitpid(pid_hstd,NULL,0);
375 si_waitpid(pid_std,NULL,0);
376 }
377 return res;
378 #endif
379 }
380#endif
381 return NULL;
382}
si_hdl_typ si_set_signal(int sig, si_hdl_typ signal_handler)
meta function for binding a signal to an handler
Definition cntrlc.cc:121
void sig_term_hdl_child(int)
Definition cntrlc.cc:86
const CanonicalForm int s
Definition facAbsFact.cc:51
@ IDEAL_CMD
Definition grammar.cc:285
ideal kTryHilbstd(ideal F, ideal Q)
VAR unsigned si_opt_2
Definition options.c:6
#define V_PURE_GB
Definition options.h:71
void Werror(const char *fmt,...)
Definition reporter.cc:189
s_buff s_open(int fd)
Definition s_buff.cc:32
int s_close(s_buff &F)
Definition s_buff.cc:46
int fd_write
Definition s_buff.h:26
s_buff f_read
Definition s_buff.h:22
FILE * f_write
Definition s_buff.h:23
ring r
Definition s_buff.h:24
int fd_read
Definition s_buff.h:26