My Project
Loading...
Searching...
No Matches
nc.cc
Go to the documentation of this file.
1#define PLURAL_INTERNAL_DECLARATIONS
2
3#include "kernel/mod2.h"
4
5#include "misc/options.h"
6
8#include "polys/prCopy.h"
9#include "polys/nc/gb_hack.h"
10
11#include "kernel/polys.h"
12
13#include "kernel/ideals.h"
15
16#include "kernel/GBEngine/nc.h"
17
18ideal twostd(ideal I) // works in currRing only!
19{
20 ideal J = kStd2(I, currRing->qideal, testHomog, NULL, (bigintmat*)NULL, 0, 0, NULL); // in currRing!!!
21 idSkipZeroes(J); // ring independent!
22
23 const int rN = currRing->N;
24
25 loop
26 {
27 ideal K = NULL;
28 const int s = idElem(J); // ring independent
29
30 for(int i = 0; i < s; i++)
31 {
32 const poly p = J->m[i];
33
34#ifdef PDEBUG
36#if 0
37 PrintS("p: "); // !
39#endif
40#endif
41
42 for (int j = 1; j <= rN; j++) // for all j = 1..N
43 {
44 poly varj = p_One( currRing);
45 p_SetExp(varj, j, 1, currRing);
46 p_Setm(varj, currRing);
47
48 poly q = pp_Mult_mm(p, varj, currRing); // q = J[i] * var(j),
49
50#ifdef PDEBUG
51 p_Test(varj, currRing);
53 p_Test(q, currRing);
54#if 0
55 PrintS("Reducing p: "); // !
57 PrintS("With q: "); // !
58 p_Write(q, currRing);
59#endif
60#endif
61
62 p_Delete(&varj, currRing);
63
64 if (q != NULL)
65 {
66#ifdef PDEBUG
67#if 0
68 Print("Reducing q[j = %d]: ", j); // !
69 p_Write(q, currRing);
70
71 PrintS("With p:");
73
74#endif
75#endif
76
77 // bug: lm(p) may not divide lm(p * var(i)) in a SCA!
78 if( p_LmDivisibleBy(p, q, currRing) )
79 q = nc_ReduceSpoly(p, q, currRing);
80
81
82#ifdef PDEBUG
83 p_Test(q, currRing);
84#if 0
85 PrintS("reductum q/p: ");
86 p_Write(q, currRing);
87
88 // PrintS("With J!\n");
89#endif
90#endif
91
92// if( q != NULL)
93 q = kNF(J, currRing->qideal, q, 0, KSTD_NF_NONORM); // in currRing!!!
94
95#ifdef PDEBUG
96 p_Test(q, currRing);
97#if 0
98 PrintS("NF(J/currRing->qideal)=> q: "); // !
99 p_Write(q, currRing);
100#endif
101#endif
102 if (q!=NULL)
103 {
104 if (p_IsConstant(q, currRing)) // => return (1)!
105 {
106 p_Delete(&q, currRing);
107 id_Delete(&J, currRing);
108
109 if (K != NULL)
110 id_Delete(&K, currRing);
111
112 ideal Q = idInit(1,1); // ring independent!
113 Q->m[0] = p_One(currRing);
114
115 return(Q);
116 }
117
118// flag = false;
119
120 // K += q:
121
122 ideal Q = idInit(1,1); // ring independent
123 Q->m[0]=q;
124
125 if( K == NULL )
126 K = Q;
127 else
128 {
129 ideal id_tmp = id_SimpleMove(K, Q,currRing);
130 K = id_tmp; // K += Q
131 }
132 }
133
134
135 } // if q != NULL
136 } // for all variables
137
138 }
139
140 if (K == NULL) // nothing new: i.e. all elements are two-sided
141 return(J);
142 // now we update GrBasis J with K
143 // iSize=IDELEMS(J);
144#ifdef PDEBUG
145 idTest(J); // in currRing!
146#if 0
147 PrintS("J:");
148 idPrint(J);
149 PrintLn();
150#endif // debug
151#endif
152
153
154
155#ifdef PDEBUG
156 idTest(K); // in currRing!
157#if 0
158 PrintS("+K:");
159 idPrint(K);
160 PrintLn();
161#endif // debug
162#endif
163
164
165 int iSize = idElem(J); // ring independent
166
167 // J += K:
168 ideal id_tmp = id_SimpleMove(J,K,currRing);
169
170#if 1
171 BITSET save1;
172 SI_SAVE_OPT1(save1);
173 si_opt_1|=Sy_bit(OPT_SB_1); // ring independent
174 J = kStd2(id_tmp, currRing->qideal, testHomog, NULL, (bigintmat*)NULL, 0, iSize); // J = J + K, J - std // in currRing!
175 SI_RESTORE_OPT1(save1);
176#else
177 J=kStd2(id_tmp, currRing->qideal,testHomog,NULL,NULL,0,0,NULL);
178#endif
179
180 id_Delete(&id_tmp, currRing);
181 idSkipZeroes(J); // ring independent
182
183#ifdef PDEBUG
184 idTest(J); // in currRing!
185#if 0
186 PrintS("J:");
187 idPrint(J);
188 PrintLn();
189#endif // debug
190#endif
191 } // loop
192}
193
194
195
196
197static ideal idPrepareStd(ideal T, ideal s, int k)
198{
199 // T is a left SB, without zeros, s is a list with zeros
200#ifdef PDEBUG
201 if (IDELEMS(s)!=IDELEMS(T))
202 {
203 PrintS("ideals of diff. size!!!");
204 }
205#endif
206 ideal t = idCopy(T);
207 int j,rs=id_RankFreeModule(s, currRing);
208 poly p,q;
209
210 ideal res = idInit(2*idElem(t),1+idElem(t));
211 if (rs == 0)
212 {
213 for (j=0; j<IDELEMS(t); j++)
214 {
215 if (s->m[j]!=NULL) pSetCompP(s->m[j],1);
216 if (t->m[j]!=NULL) pSetCompP(t->m[j],1);
217 }
218 k = si_max(k,1);
219 }
220 for (j=0; j<IDELEMS(t); j++)
221 {
222 if (s->m[j]!=NULL)
223 {
224 p = s->m[j];
225 q = pOne();
226 pSetComp(q,k+1+j);
227 pSetmComp(q);
228#if 0
229 while (pNext(p)) pIter(p);
230 pNext(p) = q;
231#else
232 p = pAdd(p,q);
233 s->m[j] = p;
234#ifdef PDEBUG
235 pTest(p);
236#endif
237#endif
238 }
239 }
240 res = idSimpleAdd(t,s);
241 idDelete(&t);
242 res->rank = 1+idElem(T);
243 return(res);
244}
245
246
247ideal Approx_Step(ideal L)
248{
249 int N=currRing->N;
250 int i,j; // k=syzcomp
251 int flag, flagcnt=0, syzcnt=0;
252 int syzcomp = 0;
253 ideal I = kStd2(L, currRing->qideal,testHomog,NULL,(bigintmat*)NULL,0,0,NULL);
254 idSkipZeroes(I);
255 ideal s_I;
256 int idI = idElem(I);
257 ideal trickyQuotient;
258 if (currRing->qideal !=NULL)
259 {
260 trickyQuotient = idSimpleAdd(currRing->qideal,I);
261 }
262 else
263 trickyQuotient = I;
264 idSkipZeroes(trickyQuotient);
265 poly *var = (poly *)omAlloc0((N+1)*sizeof(poly));
266 // poly *W = (poly *)omAlloc0((2*N+1)*sizeof(poly));
267 resolvente S = (resolvente)omAlloc0((N+1)*sizeof(ideal));
268 ideal SI, res;
269 matrix MI;
270 poly x=pOne();
271 var[0]=x;
272 ideal h2, s_h2, s_h3;
273 poly p,q;
274 // init vars
275 for (i=1; i<=N; i++ )
276 {
277 x = pOne();
278 pSetExp(x,i,1);
279 pSetm(x);
280 var[i]=pCopy(x);
281 }
282 // init NF's
283 for (i=1; i<=N; i++ )
284 {
285 h2 = idInit(idI,1);
286 flag = 0;
287 for (j=0; j< idI; j++ )
288 {
289 q = pp_Mult_mm(I->m[j],var[i],currRing);
290 q = kNF(I,currRing->qideal,q,0,0);
291 if (q!=0)
292 {
293 h2->m[j]=pCopy(q);
294 // p_Shift(&(h2->m[flag]),1, currRing);
295 flag++;
296 pDelete(&q);
297 }
298 else
299 h2->m[j]=0;
300 }
301 // W[1..IDELEMS(I)]
302 if (flag >0)
303 {
304 // compute syzygies with values in I
305 // idSkipZeroes(h2);
306 // h2 = idSimpleAdd(h2,I);
307 // h2->rank=flag+idI+1;
308 idTest(h2);
309 //idShow(h2);
310 ring orig_ring = currRing;
311 ring syz_ring = rAssure_SyzComp(orig_ring, TRUE);
312 syzcomp = 1;
313 rSetSyzComp(syzcomp, syz_ring);
314 if (orig_ring != syz_ring)
315 {
316 rChangeCurrRing(syz_ring);
317 s_h2=idrCopyR_NoSort(h2,orig_ring, syz_ring);
318 // s_trickyQuotient=idrCopyR_NoSort(trickyQuotient,orig_ring);
319 // rDebugPrint(syz_ring);
320 s_I=idrCopyR_NoSort(I,orig_ring, syz_ring);
321 }
322 else
323 {
324 s_h2 = h2;
325 s_I = I;
326 // s_trickyQuotient=trickyQuotient;
327 }
328 idTest(s_h2);
329 // idTest(s_trickyQuotient);
330 Print(".proceeding with the variable %d\n",i);
331 s_h3 = idPrepareStd(s_I, s_h2, 1);
332 BITSET save1;
333 SI_SAVE_OPT1(save1);
335 idTest(s_h3);
336 idDelete(&s_h2);
337 s_h2=idCopy(s_h3);
338 idDelete(&s_h3);
339 PrintS("...computing Syz");
340 s_h3 = kStd2(s_h2, currRing->qideal,(tHomog)FALSE,NULL,(bigintmat*)NULL,syzcomp,idI);
341 SI_RESTORE_OPT1(save1);
342 //idShow(s_h3);
343 if (orig_ring != syz_ring)
344 {
345 idDelete(&s_h2);
346 for (j=0; j<IDELEMS(s_h3); j++)
347 {
348 if (s_h3->m[j] != NULL)
349 {
350 if (p_MinComp(s_h3->m[j],syz_ring) > syzcomp) // i.e. it is a syzygy
351 p_Shift(&s_h3->m[j], -syzcomp, currRing);
352 else
353 pDelete(&s_h3->m[j]);
354 }
355 }
356 idSkipZeroes(s_h3);
357 s_h3->rank -= syzcomp;
358 rChangeCurrRing(orig_ring);
359 // s_h3 = idrMoveR_NoSort(s_h3, syz_ring, orig_ring);
360 s_h3 = idrMoveR_NoSort(s_h3, syz_ring, orig_ring);
361 rDelete(syz_ring);
362 }
363 idTest(s_h3);
364 S[syzcnt]=kStd2(s_h3,currRing->qideal,(tHomog)FALSE,NULL,(bigintmat*)NULL);
365 syzcnt++;
366 idDelete(&s_h3);
367 } // end if flag >0
368 else
369 {
370 flagcnt++;
371 }
372 }
373 if (flagcnt == N)
374 {
375 PrintS("the input is a two--sided ideal");
376 return(I);
377 }
378 if (syzcnt >0)
379 {
380 Print("..computing Intersect of %d modules\n",syzcnt);
381 if (syzcnt == 1)
382 SI = S[0];
383 else
384 SI = idMultSect(S, syzcnt);
385 //idShow(SI);
386 MI = id_Module2Matrix(SI,currRing);
387 res= idInit(MATCOLS(MI),1);
388 for (i=1; i<= MATCOLS(MI); i++)
389 {
390 p = NULL;
391 for (j=0; j< idElem(I); j++)
392 {
393 q = pCopy(MATELEM(MI,j+1,i));
394 if (q!=NULL)
395 {
396 q = pMult(q,pCopy(I->m[j]));
397 p = pAdd(p,q);
398 }
399 }
400 res->m[i-1]=p;
401 }
402 PrintS("final std");
405 return(res);
406 }
407 else
408 {
409 PrintS("No syzygies");
410 return(I);
411 }
412}
#define BITSET
Definition auxiliary.h:85
static int si_max(const int a, const int b)
Definition auxiliary.h:125
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
Variable x
Definition cfModGcd.cc:4090
int p
Definition cfModGcd.cc:4086
Matrices of numbers.
Definition bigintmat.h:51
#define Print
Definition emacs.cc:80
const CanonicalForm int s
Definition facAbsFact.cc:51
CanonicalForm res
Definition facAbsFact.cc:60
int j
Definition facHensel.cc:110
ideal idMultSect(resolvente arg, int length, GbVariant alg)
Definition ideals.cc:472
#define idDelete(H)
delete an ideal
Definition ideals.h:29
#define idSimpleAdd(A, B)
Definition ideals.h:42
#define idPrint(id)
Definition ideals.h:46
#define idTest(id)
Definition ideals.h:47
ideal idCopy(ideal A)
Definition ideals.h:60
ideal * resolvente
Definition ideals.h:18
STATIC_VAR jList * T
Definition janet.cc:30
ideal kStd2(ideal F, ideal Q, tHomog h, intvec **w, bigintmat *hilb, int syzComp, int newIdeal, intvec *vw, s_poly_proc_t sp)
generic interface to GB/SB computations, large hilbert vectors
Definition kstd1.cc:2607
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition kstd1.cc:3230
#define KSTD_NF_NONORM
Definition kstd1.h:22
static poly nc_ReduceSpoly(const poly p1, poly p2, const ring r)
Definition nc.h:254
#define MATELEM(mat, i, j)
1-based access to matrix
Definition matpol.h:29
ip_smatrix * matrix
Definition matpol.h:43
#define MATCOLS(i)
Definition matpol.h:27
#define pIter(p)
Definition monomials.h:37
#define pNext(p)
Definition monomials.h:36
ideal Approx_Step(ideal L)
Ann: ???
Definition nc.cc:247
static ideal idPrepareStd(ideal T, ideal s, int k)
Definition nc.cc:197
ideal twostd(ideal I)
Compute two-sided GB:
Definition nc.cc:18
#define omAlloc0(size)
#define NULL
Definition omList.c:12
VAR unsigned si_opt_1
Definition options.c:5
#define OPT_SB_1
Definition options.h:96
#define SI_SAVE_OPT1(A)
Definition options.h:21
#define SI_RESTORE_OPT1(A)
Definition options.h:24
#define Sy_bit(x)
Definition options.h:31
void p_Shift(poly *p, int i, const ring r)
shifts components of the vector p by i
Definition p_polys.cc:4873
poly p_One(const ring r)
Definition p_polys.cc:1314
void p_Write(poly p, ring lmRing, ring tailRing)
Definition polys0.cc:342
static poly pp_Mult_mm(poly p, poly m, const ring r)
Definition p_polys.h:1033
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition p_polys.h:490
static long p_MinComp(poly p, ring lmRing, ring tailRing)
Definition p_polys.h:315
static void p_Setm(poly p, const ring r)
Definition p_polys.h:235
static BOOLEAN p_IsConstant(const poly p, const ring r)
Definition p_polys.h:1985
static BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition p_polys.h:1912
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
#define p_Test(p, r)
Definition p_polys.h:161
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
Compatibility layer for legacy polynomial operations (over currRing).
#define pAdd(p, q)
Definition polys.h:204
#define pTest(p)
Definition polys.h:415
#define pDelete(p_ptr)
Definition polys.h:187
#define pSetm(p)
Definition polys.h:272
#define pSetCompP(a, i)
Definition polys.h:304
#define pSetComp(p, v)
Definition polys.h:39
#define pMult(p, q)
Definition polys.h:208
#define pSetmComp(p)
TODO:
Definition polys.h:274
#define pSetExp(p, i, v)
Definition polys.h:43
#define pCopy(p)
return a copy of the poly
Definition polys.h:186
#define pOne()
Definition polys.h:316
ideal idrMoveR_NoSort(ideal &id, ring src_r, ring dest_r)
Definition prCopy.cc:261
ideal idrCopyR_NoSort(ideal id, ring src_r, ring dest_r)
Definition prCopy.cc:205
void PrintS(const char *s)
Definition reporter.cc:288
void PrintLn()
Definition reporter.cc:314
ring rAssure_SyzComp(const ring r, BOOLEAN complete)
Definition ring.cc:4527
void rDelete(ring r)
unconditionally deletes fields in r
Definition ring.cc:454
void rSetSyzComp(int k, const ring r)
Definition ring.cc:5230
ideal idInit(int idsize, int rank)
initialise an ideal / module
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
matrix id_Module2Matrix(ideal mod, const ring R)
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
ideal id_SimpleMove(ideal h1, ideal h2, const ring R)
concat the lists h1 and h2 without zeros, destroys h1,h2
#define IDELEMS(i)
static int idElem(const ideal F)
number of non-zero polys in F
#define Q
Definition sirandom.c:26
tHomog
Definition structs.h:31
@ testHomog
Definition structs.h:34
#define loop
Definition structs.h:71