My Project
Loading...
Searching...
No Matches
kstdhelper.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/*
5* ABSTRACT: wrapper to try stdhild within std
6*/
7
8
9#include "kernel/mod2.h"
10
11#include "coeffs/bigintmat.h"
12#include "coeffs/longrat.h"
13#include "misc/options.h"
14#include "misc/intvec.h"
15#include "reporter/si_signals.h"
16#include "kernel/polys.h"
17#define TRANSEXT_PRIVATES
19#undef TRANSEXT_PRIVATES
23#include "kernel/ideals.h"
26#include "Singular/ipid.h"
27#include "Singular/cntrlc.h"
29#include "Singular/feOpt.h"
30
31static int kFindLuckyPrime(ideal F, ideal Q) // TODO
32{
33 int prim=32003;
34 // assume coeff are in Q
35 return prim;
36}
37
39{
40 if (Q!=NULL)
41 return NULL;
42 int prim=kFindLuckyPrime(F,Q);
43 if (TEST_OPT_PROT) Print("try HC in ring over ZZ/%d\n",prim);
44 // create Zp_ring
47 nKillChar(Zp_ring->cf);
48 Zp_ring->cf=nInitChar(n_Zp, (void*)(long)prim);
50 // map data
53 if (nMap==NULL) return NULL;
57 // call std
58 kStrategy strat=new skStrategy;
59 strat->LazyPass=20;
60 strat->LazyDegree = 1;
61 strat->kModW=kModW=NULL;
62 strat->kHomW=kHomW=NULL;
63 strat->homog = (tHomog)idHomIdeal(F,Q);
64 ideal res=mora(FF,QQ,NULL,NULL,strat);
65 // clean
66 idDelete(&FF);
67 poly HC=NULL;
68 if (strat->kNoether!=NULL) scComputeHC(res,QQ,0,HC);
69 delete strat;
70 if (QQ!=NULL) idDelete(&QQ);
71 idDelete(&res);
72 // map back
74 if (HC!=NULL)
75 {
76 //p_IncrExp(HC,Zp_ring->N,Zp_ring);
77 for (int i=rVar(Zp_ring)-1; i>0; i--)
78 {
79 int e;
80 if ((e=pGetExp(HC, i)) > 0) pSetExp(HC,i,e-1);
81 }
83 if (TEST_OPT_PROT) Print("HC(%ld) found\n",pTotaldegree(HC));
85 }
86 else
87 {
88 if (TEST_OPT_PROT) PrintS("HC not found\n");
89 }
91 return HC;
92}
93
94// --------------------------------------------------------
95static number nMapQa2Zp(number a, const coeffs src, const coeffs dst)
96{
97 if (a==NULL) return a;
99 poly p=NUM(f);
100 while(pNext(p)!=NULL) pIter(p);
101 return nlModP(pGetCoeff(p),src->extRing->cf,dst);
102}
103
104static number nMapZpa2Zp(number a, const coeffs src, const coeffs dst)
105{
106 if (a==NULL) return a;
108 poly p=NUM(f);
109 while(pNext(p)!=NULL) pIter(p);
110 return pGetCoeff(p);
111}
112
114{
115 // create Zp_ring
118 int prim=kFindLuckyPrime(F,Q);
119 //if(nCoeff_is_transExt(save_ring->cf)
120 //&&(nCoeff_is_Zp(save_ring->cf->extRing->cf)))
121 // prim=save_ring->cf->extRing->cf->ch;
122 if(nCoeff_is_Zp(save_ring->cf))
123 prim=save_ring->cf->ch;
124 coeffs cf=nInitChar(n_Zp, (void*)(long)prim);
126 // map data
128 if (nMap==NULL)
129 {
131 {
132 if (nCoeff_is_Q(save_ring->cf->extRing->cf))
134 else if (nCoeff_is_Zp(save_ring->cf->extRing->cf))
136 else
137 {
139 return NULL;
140 }
141 }
142 else
143 {
145 return NULL;
146 }
147 }
150 ideal QQ=NULL;
152 // compute GB in Zp_ring
153 si_opt_1&= ~Sy_bit(OPT_REDSB);
154 si_opt_1&= ~Sy_bit(OPT_REDTAIL);
155 if(TEST_OPT_PROT) Print("std in char. %d ------------------\n",prim);
157 // compute hilb
159 // clean up Zp_ring
161 id_Delete(&GB,Zp_ring);
163 if (QQ!=NULL) id_Delete(&QQ,Zp_ring);
165 // std with hilb
166 intvec *w=NULL;
167 if(TEST_OPT_PROT) PrintS("stdhilb in basering ------------------\n");
170 if (w!=NULL) delete w;
171 delete hilb;
172 return result;
173}
174
176{
177 int prim=kFindLuckyPrime(F,Q);
178 //if(nCoeff_is_transExt(save_ring->cf)
179 //&&(nCoeff_is_Zp(save_ring->cf->extRing->cf)))
180 // prim=save_ring->cf->extRing->cf->ch;
181 if(nCoeff_is_Zp(currRing->cf))
182 prim=currRing->cf->ch;
183 if(TEST_OPT_PROT) Print("std in char. %d, homogenized ------------------\n",prim);
184 // create Zp_ring, need 1 more variable
187 coeffs cf=nInitChar(n_Zp, (void*)(long)prim);
188 char **names=(char**)omAlloc0((currRing->N+1) * sizeof(char *));
189 for(int i=0;i<currRing->N;i++)
190 {
191 names[i]=omStrDup(currRing->names[i]);
192 }
193 names[currRing->N]=omStrDup("@");
195 // map data
197 if (nMap==NULL) return NULL;
200 ideal QQ=NULL;
202 // homogenize
205 FF=tmp;
206 if (QQ!=NULL)
207 {
210 QQ=tmp;
211 }
212 // compute GB in Zp_ring
213 si_opt_1&= ~Sy_bit(OPT_REDSB);
214 si_opt_1&= ~Sy_bit(OPT_REDTAIL);
216 // compute hilb
218 // clean up Zp_ring
219 id_Delete(&GB,Zp_ring);
221 if (QQ!=NULL) id_Delete(&QQ,Zp_ring);
224 //omFreeBin(Zp_ring,sip_sring_bin);
225 // create Q_ring
228 names=(char**)omAlloc0((save_ring->N+1) * sizeof(char *));
229 for(int i=0;i<save_ring->N;i++)
230 {
231 names[i]=omStrDup(save_ring->names[i]);
232 }
233 names[save_ring->N]=omStrDup("@");
235 int *block0 = (int *)omAlloc0(nblocks * sizeof(int));
236 int *block1 = (int *)omAlloc0(nblocks * sizeof(int));
237 int **wvhdl=(int**)omAlloc0(nblocks * sizeof(int *));
238 for (int j=0; j<nblocks-1; j++)
239 {
240 if (save_ring->wvhdl[j]!=NULL)
241 {
242 #ifdef HAVE_OMALLOC
243 wvhdl[j] = (int*) omMemDup(save_ring->wvhdl[j]);
244 #else
245 {
246 int l=save_ring->block1[j]-save_ring->block0[j]+1;
247 if (save_ring->order[j]==ringorder_a64) l*=2;
248 else if (save_ring->order[j]==ringorder_M) l=l*l;
249 else if (save_ring->order[j]==ringorder_am)
250 {
251 l+=save_ring->wvhdl[j][save_ring->block1[j]-save_ring->block0[j]+1]+1;
252 }
253 wvhdl[j]=(int*)omalloc(l*sizeof(int));
254 memcpy(wvhdl[j],save_ring->wvhdl[j],l*sizeof(int));
255 }
256 #endif
257 }
258 }
259 memcpy(order,save_ring->order,(nblocks-1) * sizeof(rRingOrder_t));
260 memcpy(block0,save_ring->block0,(nblocks-1) * sizeof(int));
261 memcpy(block1,save_ring->block1,(nblocks-1) * sizeof(int));
262 order[nblocks-1]=ringorder_lp;
263 block0[nblocks-1]=save_ring->N+1;
264 block1[nblocks-1]=save_ring->N+1;
265
266 ring Q_ring=rDefault(cf,save_ring->N+1,names,nblocks,order,block0,block1,wvhdl,save_ring->wanted_maxExp);
267 // map data
268 nMap=n_SetMap(save_ring->cf,Q_ring->cf);
269 if (nMap==NULL) return NULL;
272 QQ=NULL;
274 // homogenize
275 if(TEST_OPT_PROT) PrintS("stdhilb in basering, homogenized ------------------\n");
278 FF=tmp;
279 if (QQ!=NULL)
280 {
283 QQ=tmp;
284 }
285 // std with hilb
286 intvec *w=NULL;
288 if (w!=NULL) delete w;
289 delete hilb;
290 // dehomogenize
291 if(TEST_OPT_PROT) PrintS("de-homogenize, interred ------------------\n");
292 poly one=pOne();
293 tmp=id_Subst(tmp,Q_ring->N,one,Q_ring);
294 p_Delete(&one,Q_ring);
295 // map back to save_ring
297 nMap=n_SetMap(Q_ring->cf,save_ring->cf);
299 // clean up Q_ring
301 if (QQ!=NULL) id_Delete(&QQ,Q_ring);
304 //omFreeBin(Q_ring,sip_sring_bin);
306 int dummy;
307 if (TEST_OPT_REDSB)
308 {
310 idSkipZeroes(GB);
311 ideal GB2=kInterRedBba(GB,currRing->qideal,dummy);
312 idDelete(&GB);
313 return GB2;
314 }
315 else
316 {
318 idSkipZeroes(GB);
319 return GB;
320 }
321}
322
324{
325 if (rField_is_Ring(currRing)) return NULL;
326 if(!TEST_V_PURE_GB)
327 {
329 if (h==(tHomog)TRUE) return kTryHilbstd_homog(F,Q);
330 if((!rField_is_Q(currRing))
332 ) return NULL;
333 if (h==(tHomog)FALSE) return kTryHilbstd_nonhomog(F,Q);
334 }
335 return NULL;
336}
337
339{
341 if (cpus<1)
342 {
343 //WerrorS("no sub-processes allowed");
344 return NULL;
345 }
346#if 0
347 if(!TEST_V_PURE_GB)
348 {
349 int cp_std[2];
350 int cp_hstd[2];
351 int err1=pipe(cp_std);// [0] is read , [1] is write
352 int err2=pipe(cp_hstd);
353 if (err1||err2)
354 {
355 Werror("pipe failed with %d\n",errno);
356 si_close(cp_std[0]);
357 si_close(cp_std[1]);
358 si_close(cp_hstd[0]);
359 si_close(cp_hstd[1]);
360 return NULL;
361 }
363 if (pid_std==0) /*child std*/
364 {
366 si_close(cp_std[0]);
367 si_close(cp_hstd[0]);
368 si_close(cp_hstd[1]);
369 ssiInfo d;
370 memset(&d,0,sizeof(d));
371 d.f_write=fdopen(cp_std[1],"w");
372 d.fd_write=cp_std[1];
373 d.r=currRing;
377 fclose(d.f_write);
378 _exit(0);
379 }
381 if (pid_hstd==0) /*child hstd*/
382 {
384 si_close(cp_hstd[0]);
385 si_close(cp_std[0]);
386 si_close(cp_std[1]);
387 ssiInfo d;
388 memset(&d,0,sizeof(d));
389 d.f_write=fdopen(cp_hstd[1],"w");
390 d.fd_write=cp_hstd[1];
391 d.r=currRing;
392
395 if (res!=NULL)
396 {
398 }
399 fclose(d.f_write);
400 _exit(0);
401 }
402 /*parent*/
403 si_close(cp_std[1]);
404 si_close(cp_hstd[1]);
405 #ifdef HAVE_POLL
406 pollfd pfd[2];
407 pfd[0].fd=cp_std[0];
408 pfd[0].events=POLLIN;
409 pfd[1].fd=cp_hstd[0];
410 pfd[1].events=POLLIN;
411 int s=si_poll(pfd,2,-1); // wait infinite
412 ideal res;
413 ssiInfo d;
414 memset(&d,0,sizeof(d));
415 d.r=currRing;
416 if (s==1) //std
417 {
418 d.f_read=s_open(cp_std[0]);
419 d.fd_read=cp_std[0];
420 res=ssiReadIdeal(&d);
421 si_close(cp_hstd[0]);
422 s_close(d.f_read);
423 si_close(cp_std[0]);
424 kill(pid_hstd,SIGTERM);
427 }
428 else if(s==2)
429 {
430 d.f_read=s_open(cp_hstd[0]);
431 d.fd_read=cp_hstd[0];
432 res=ssiReadIdeal(&d);
433 si_close(cp_std[0]);
434 s_close(d.f_read);
435 si_close(cp_hstd[0]);
436 kill(pid_std,SIGTERM);
439 }
440 return res;
441 #endif
442 }
443#endif
444 return NULL;
445}
#define BITSET
Definition auxiliary.h:85
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
int p
Definition cfModGcd.cc:4086
CanonicalForm cf
Definition cfModGcd.cc:4091
FILE * f
Definition checklibs.c:9
Matrices of numbers.
Definition bigintmat.h:51
intvec * kModW
Definition kutil.h:334
poly kNoether
Definition kutil.h:328
intvec * kHomW
Definition kutil.h:335
int LazyPass
Definition kutil.h:352
int LazyDegree
Definition kutil.h:352
char homog
Definition kutil.h:369
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
@ 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:703
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
Definition coeffs.h:801
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition numbers.cc:412
static FORCE_INLINE coeffs nCopyCoeff(const coeffs r)
"copy" coeffs, i.e. increment ref
Definition coeffs.h:439
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition coeffs.h:795
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:563
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition coeffs.h:913
#define Print
Definition emacs.cc:80
return result
const CanonicalForm int s
Definition facAbsFact.cc:51
CanonicalForm res
Definition facAbsFact.cc:60
const CanonicalForm & w
Definition facAbsFact.cc:51
int j
Definition facHensel.cc:110
static void * feOptValue(feOptIndex opt)
Definition feOpt.h:40
@ IDEAL_CMD
Definition grammar.cc:285
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge)
Definition hdegree.cc:1074
bigintmat * hFirstSeries0b(ideal I, ideal Q, intvec *wdegree, intvec *shifts, const ring src, const coeffs biv_cf)
Definition hilb.cc:2019
#define idDelete(H)
delete an ideal
Definition ideals.h:29
static BOOLEAN idHomIdeal(ideal id, ideal Q=NULL)
Definition ideals.h:91
STATIC_VAR Poly * h
Definition janet.cc:971
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:2434
ideal kInterRedBba(ideal F, ideal Q, int &need_retry)
Definition kstd1.cc:3551
ideal mora(ideal F, ideal Q, intvec *w, bigintmat *hilb, kStrategy strat)
Definition kstd1.cc:1887
VAR intvec * kHomW
Definition kstd1.cc:2409
VAR intvec * kModW
Definition kstd1.cc:2409
static ideal kTryHilbstd_nonhomog(ideal F, ideal Q)
static int kFindLuckyPrime(ideal F, ideal Q)
Definition kstdhelper.cc:31
static number nMapQa2Zp(number a, const coeffs src, const coeffs dst)
Definition kstdhelper.cc:95
static ideal kTryHilbstd_homog(ideal F, ideal Q)
static number nMapZpa2Zp(number a, const coeffs src, const coeffs dst)
ideal kTryHilbstd_par(ideal F, ideal Q, tHomog h, intvec **mw)
poly kTryHC(ideal F, ideal Q)
Definition kstdhelper.cc:38
ideal kTryHilbstd(ideal F, ideal Q)
number nlModP(number q, const coeffs, const coeffs Zp)
Definition longrat.cc:1572
#define pIter(p)
Definition monomials.h:37
#define pNext(p)
Definition monomials.h:36
#define pSetCoeff0(p, n)
Definition monomials.h:59
static number & pGetCoeff(poly p)
return an alias to the leading coefficient of p assumes that p != NULL NOTE: not copy
Definition monomials.h:44
The main handler for Singular numbers which are suitable for Singular polynomials.
#define nInit(i)
Definition numbers.h:24
#define omStrDup(s)
#define omAlloc(size)
#define omalloc(size)
#define omAlloc0(size)
#define omMemDup(s)
#define NULL
Definition omList.c:12
VAR unsigned si_opt_2
Definition options.c:6
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
#define TEST_OPT_REDSB
Definition options.h:106
#define V_PURE_GB
Definition options.h:71
#define TEST_V_PURE_GB
Definition options.h:137
#define TEST_OPT_PROT
Definition options.h:105
static void p_Setm(poly p, const ring r)
Definition p_polys.h:235
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
void rChangeCurrRing(ring r)
Definition polys.cc:16
VAR coeffs coeffs_BIGINT
Definition polys.cc:14
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
Compatibility layer for legacy polynomial operations (over currRing)
static long pTotaldegree(poly p)
Definition polys.h:283
#define pGetExp(p, i)
Exponent.
Definition polys.h:42
#define pSetExp(p, i, v)
Definition polys.h:43
#define pOne()
Definition polys.h:316
#define NUM
Definition readcf.cc:180
void PrintS(const char *s)
Definition reporter.cc:288
void Werror(const char *fmt,...)
Definition reporter.cc:189
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:3527
ring rCopy0(const ring r, BOOLEAN copy_qideal, BOOLEAN copy_ordering)
Definition ring.cc:1427
void rDelete(ring r)
unconditionally deletes fields in r
Definition ring.cc:454
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
static BOOLEAN rField_is_Zp(const ring r)
Definition ring.h:506
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_dp
Definition ring.h:79
@ ringorder_M
Definition ring.h:75
static BOOLEAN rField_is_Q(const ring r)
Definition ring.h:512
static short rVar(const ring r)
#define rVar(r) (r->N)
Definition ring.h:598
#define rField_is_Ring(R)
Definition ring.h:491
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
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
BOOLEAN id_HomIdealDP(ideal id, ideal Q, const ring r)
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_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
ideal id_Subst(ideal id, int n, poly e, const ring r)
#define IDELEMS(i)
#define Q
Definition sirandom.c:26
tHomog
Definition structs.h:31
@ testHomog
Definition structs.h:34