My Project
Loading...
Searching...
No Matches
ideals.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/*
5* ABSTRACT - all basic methods to manipulate ideals
6*/
7
8/* includes */
9
10#include "kernel/mod2.h"
11
12#include "misc/options.h"
13#include "misc/intvec.h"
14
15#include "coeffs/coeffs.h"
16#include "coeffs/numbers.h"
17// #include "coeffs/longrat.h"
18
19
21#include "polys/matpol.h"
22#include "polys/weight.h"
23#include "polys/sparsmat.h"
24#include "polys/prCopy.h"
25#include "polys/nc/nc.h"
26
27
28#include "kernel/ideals.h"
29
30#include "kernel/polys.h"
31
34#include "kernel/GBEngine/tgb.h"
35#include "kernel/GBEngine/syz.h"
36#include "Singular/ipshell.h" // iiCallLibProc1
37#include "Singular/ipid.h" // ggetid
38
39
40#if 0
41#include "Singular/ipprint.h" // ipPrint_MA0
42#endif
43
44/* #define WITH_OLD_MINOR */
45
46/*0 implementation*/
47
48/*2
49*returns a minimized set of generators of h1
50*/
51ideal idMinBase (ideal h1, ideal *SB)
52{
53 ideal h2, h3,h4,e;
54 int j,k;
55 int i,l,ll;
56 intvec * wth;
57 BOOLEAN homog;
59 {
60 WarnS("minbase applies only to the local or homogeneous case over coefficient fields");
61 e=idCopy(h1);
62 return e;
63 }
64 homog = idHomModule(h1,currRing->qideal,&wth);
66 {
67 if(!homog)
68 {
69 WarnS("minbase applies only to the local or homogeneous case over coefficient fields");
70 e=idCopy(h1);
71 return e;
72 }
73 else
74 {
75 ideal re=kMin_std2(h1,currRing->qideal,(tHomog)homog,&wth,h2,(bigintmat*)NULL,0,3);
76 idDelete(&re);
77 return h2;
78 }
79 }
80 e=idInit(1,h1->rank);
81 if (idIs0(h1))
82 {
83 return e;
84 }
85 h2 = kStd2(h1,currRing->qideal,isNotHomog,NULL,(bigintmat*)NULL);
86 if (SB!=NULL) *SB=h2;
87 h3 = idMaxIdeal(1);
88 h4=idMult(h2,h3);
89 idDelete(&h3);
90 h3=kStd2(h4,currRing->qideal,isNotHomog,NULL,(bigintmat*)NULL);
91 k = IDELEMS(h3);
92 while ((k > 0) && (h3->m[k-1] == NULL)) k--;
93 j = -1;
94 l = IDELEMS(h2);
95 while ((l > 0) && (h2->m[l-1] == NULL)) l--;
96 for (i=l-1; i>=0; i--)
97 {
98 if (h2->m[i] != NULL)
99 {
100 ll = 0;
101 while ((ll < k) && ((h3->m[ll] == NULL)
102 || !pDivisibleBy(h3->m[ll],h2->m[i])))
103 ll++;
104 if (ll >= k)
105 {
106 j++;
107 if (j > IDELEMS(e)-1)
108 {
109 pEnlargeSet(&(e->m),IDELEMS(e),16);
110 IDELEMS(e) += 16;
111 }
112 e->m[j] = pCopy(h2->m[i]);
113 }
114 }
115 }
116 if (SB==NULL) idDelete(&h2);
117 idDelete(&h3);
118 idDelete(&h4);
119 if (currRing->qideal!=NULL)
120 {
121 h3=idInit(1,e->rank);
122 h2=kNF(h3,currRing->qideal,e);
123 idDelete(&h3);
124 idDelete(&e);
125 e=h2;
126 }
127 idSkipZeroes(e);
128 return e;
129}
130
131
132static ideal idSectWithElim (ideal h1,ideal h2, GbVariant alg)
133// does not destroy h1,h2
134{
135 if (TEST_OPT_PROT) PrintS("intersect by elimination method\n");
136 assume(!idIs0(h1));
137 assume(!idIs0(h2));
138 assume(IDELEMS(h1)<=IDELEMS(h2));
141 // add a new variable:
142 int j;
143 ring origRing=currRing;
144 ring r=rCopy0(origRing);
145 r->N++;
146 r->block0[0]=1;
147 r->block1[0]= r->N;
148 omFree(r->order);
149 r->order=(rRingOrder_t*)omAlloc0(3*sizeof(rRingOrder_t));
150 r->order[0]=ringorder_dp;
151 r->order[1]=ringorder_C;
152 char **names=(char**)omAlloc0(rVar(r) * sizeof(char_ptr));
153 for (j=0;j<r->N-1;j++) names[j]=r->names[j];
154 names[r->N-1]=omStrDup("@");
155 omFree(r->names);
156 r->names=names;
157 rComplete(r,TRUE);
158 // fetch h1, h2
159 ideal h;
160 h1=idrCopyR(h1,origRing,r);
161 h2=idrCopyR(h2,origRing,r);
162 // switch to temp. ring r
164 // create 1-t, t
165 poly omt=p_One(currRing);
166 p_SetExp(omt,r->N,1,currRing);
167 p_Setm(omt,currRing);
168 poly t=p_Copy(omt,currRing);
169 omt=p_Neg(omt,currRing);
170 omt=p_Add_q(omt,pOne(),currRing);
171 // compute (1-t)*h1
172 h1=(ideal)mp_MultP((matrix)h1,omt,currRing);
173 // compute t*h2
174 h2=(ideal)mp_MultP((matrix)h2,pCopy(t),currRing);
175 // (1-t)h1 + t*h2
176 h=idInit(IDELEMS(h1)+IDELEMS(h2),1);
177 int l;
178 for (l=IDELEMS(h1)-1; l>=0; l--)
179 {
180 h->m[l] = h1->m[l]; h1->m[l]=NULL;
181 }
182 j=IDELEMS(h1);
183 for (l=IDELEMS(h2)-1; l>=0; l--)
184 {
185 h->m[l+j] = h2->m[l]; h2->m[l]=NULL;
186 }
187 idDelete(&h1);
188 idDelete(&h2);
189 // eliminate t:
190 ideal res=idElimination2(h,t,NULL,alg);
191 // cleanup
192 idDelete(&h);
193 pDelete(&t);
194 if (res!=NULL) res=idrMoveR(res,r,origRing);
195 rChangeCurrRing(origRing);
196 rDelete(r);
197 return res;
198}
199
200static ideal idGroebner(ideal temp,int syzComp,GbVariant alg, bigintmat* hilb=NULL, intvec* w=NULL, tHomog hom=testHomog)
201{
202 //Print("syz=%d\n",syzComp);
203 //PrintS(showOption());
204 //PrintLn();
205 ideal res=NULL;
206 if (w==NULL)
207 {
208 if (hom==testHomog)
209 hom=(tHomog)idHomModule(temp,currRing->qideal,&w); //sets w to weight vector or NULL
210 }
211 else
212 {
213 w=ivCopy(w);
214 hom=isHomog;
215 }
216#ifdef HAVE_SHIFTBBA
217 if (rIsLPRing(currRing)) alg = GbStd;
218#endif
219 if ((alg==GbStd)||(alg==GbDefault))
220 {
221 if (TEST_OPT_PROT &&(alg==GbStd)) { PrintS("std:"); mflush(); }
222 res = kStd2(temp,currRing->qideal,hom,&w,hilb,syzComp);
223 idDelete(&temp);
224 }
225 else if (alg==GbSlimgb)
226 {
227 if (TEST_OPT_PROT) { PrintS("slimgb:"); mflush(); }
228 res = t_rep_gb(currRing, temp, syzComp);
229 idDelete(&temp);
230 }
231 else if (alg==GbGroebner)
232 {
233 if (TEST_OPT_PROT) { PrintS("groebner:"); mflush(); }
234 BOOLEAN err;
235 res=(ideal)iiCallLibProc1("groebner",temp,MODUL_CMD,err);
236 if (err)
237 {
238 Werror("error %d in >>groebner<<",err);
239 res=idInit(1,1);
240 }
241 }
242 else if (alg==GbModstd)
243 {
244 if (TEST_OPT_PROT) { PrintS("modStd:"); mflush(); }
245 BOOLEAN err;
246 void *args[]={temp,(void*)1,NULL};
247 int arg_t[]={MODUL_CMD,INT_CMD,0};
248 leftv temp0=ii_CallLibProcM("modStd",args,arg_t,currRing,err);
249 res=(ideal)temp0->data;
251 if (err)
252 {
253 Werror("error %d in >>modStd<<",err);
254 res=idInit(1,1);
255 }
256 }
257 else if (alg==GbSba)
258 {
259 if (TEST_OPT_PROT) { PrintS("sba:"); mflush(); }
260 res = kSba(temp,currRing->qideal,hom,&w,1,0,NULL);
261 if (w!=NULL) delete w;
262 }
263 else if (alg==GbStdSat)
264 {
265 if (TEST_OPT_PROT) { PrintS("std:sat:"); mflush(); }
266 BOOLEAN err;
267 // search for 2nd block of vars
268 int i=0;
269 int block=-1;
270 loop
271 {
272 if ((currRing->order[i]!=ringorder_c)
273 && (currRing->order[i]!=ringorder_C)
274 && (currRing->order[i]!=ringorder_s))
275 {
276 if (currRing->order[i]==0) { err=TRUE;break;}
277 block++;
278 if (block==1) { block=i; break;}
279 }
280 i++;
281 }
282 if (block>0)
283 {
284 if (TEST_OPT_PROT)
285 {
286 Print("sat(%d..%d)\n",currRing->block0[block],currRing->block1[block]);
287 mflush();
288 }
289 ideal v=idInit(currRing->block1[block]-currRing->block0[block]+1,1);
290 for(i=currRing->block0[block];i<=currRing->block1[block];i++)
291 {
292 v->m[i-currRing->block0[block]]=pOne();
293 pSetExp(v->m[i-currRing->block0[block]],i,1);
294 pSetm(v->m[i-currRing->block0[block]]);
295 }
296 void *args[]={temp,v,NULL};
297 int arg_t[]={MODUL_CMD,IDEAL_CMD,0};
298 leftv temp0=ii_CallLibProcM("satstd",args,arg_t,currRing,err);
299 res=(ideal)temp0->data;
301 }
302 if (err)
303 {
304 Werror("error %d in >>satstd<<",err);
305 res=idInit(1,1);
306 }
307 }
308 if (w!=NULL) delete w;
309 return res;
310}
311
312/*2
313* h3 := h1 intersect h2
314*/
315ideal idSect (ideal h1,ideal h2, GbVariant alg)
316{
317 int i,j,k;
318 unsigned length;
319 int flength = id_RankFreeModule(h1,currRing);
320 int slength = id_RankFreeModule(h2,currRing);
321 int rank=si_max(h1->rank,h2->rank);
322 if ((idIs0(h1)) || (idIs0(h2))) return idInit(1,rank);
323
324 BITSET save_opt;
325 SI_SAVE_OPT1(save_opt);
327
328 ideal first,second,temp,temp1,result;
329 poly p,q;
330
331 if (IDELEMS(h1)<IDELEMS(h2))
332 {
333 first = h1;
334 second = h2;
335 }
336 else
337 {
338 first = h2;
339 second = h1;
340 int t=flength; flength=slength; slength=t;
341 }
342 length = si_max(flength,slength);
343 if (length==0)
344 {
345 if ((currRing->qideal==NULL)
346 && (currRing->OrdSgn==1)
349 return idSectWithElim(first,second,alg);
350 else length = 1;
351 }
352 if (TEST_OPT_PROT) PrintS("intersect by syzygy methods\n");
353 j = IDELEMS(first);
354
355 ring orig_ring=currRing;
356 ring syz_ring=rAssure_SyzOrder(orig_ring,TRUE);
357 rSetSyzComp(length,syz_ring);
358 rChangeCurrRing(syz_ring);
360
361 while ((j>0) && (first->m[j-1]==NULL)) j--;
362 temp = idInit(j /*IDELEMS(first)*/+IDELEMS(second),length+j);
363 k = 0;
364 for (i=0;i<j;i++)
365 {
366 if (first->m[i]!=NULL)
367 {
368 if (syz_ring==orig_ring)
369 temp->m[k] = pCopy(first->m[i]);
370 else
371 temp->m[k] = prCopyR(first->m[i], orig_ring, syz_ring);
372 q = pOne();
373 pSetComp(q,i+1+length);
374 pSetmComp(q);
375 if (flength==0) p_Shift(&(temp->m[k]),1,currRing);
376 p = temp->m[k];
377 while (pNext(p)!=NULL) pIter(p);
378 pNext(p) = q;
379 k++;
380 }
381 }
382 for (i=0;i<IDELEMS(second);i++)
383 {
384 if (second->m[i]!=NULL)
385 {
386 if (syz_ring==orig_ring)
387 temp->m[k] = pCopy(second->m[i]);
388 else
389 temp->m[k] = prCopyR(second->m[i], orig_ring,currRing);
390 if (slength==0) p_Shift(&(temp->m[k]),1,currRing);
391 k++;
392 }
393 }
394 intvec *w=NULL;
395
396 if ((alg!=GbDefault)
397 && (alg!=GbGroebner)
398 && (alg!=GbModstd)
399 && (alg!=GbSlimgb)
400 && (alg!=GbStd))
401 {
402 WarnS("wrong algorithm for GB");
403 alg=GbDefault;
404 }
405 temp1=idGroebner(temp,length,alg);
406
407 if(syz_ring!=orig_ring)
408 rChangeCurrRing(orig_ring);
409
410 result = idInit(IDELEMS(temp1),rank);
411 j = 0;
412 for (i=0;i<IDELEMS(temp1);i++)
413 {
414 if ((temp1->m[i]!=NULL)
415 && (__p_GetComp(temp1->m[i],syz_ring)>length))
416 {
417 if(syz_ring==orig_ring)
418 {
419 p = temp1->m[i];
420 }
421 else
422 {
423 p = prMoveR(temp1->m[i], syz_ring,orig_ring);
424 }
425 temp1->m[i]=NULL;
426 while (p!=NULL)
427 {
428 q = pNext(p);
429 pNext(p) = NULL;
430 k = pGetComp(p)-1-length;
431 pSetComp(p,0);
432 pSetmComp(p);
433 /* Warning! multiply only from the left! it's very important for Plural */
434 result->m[j] = pAdd(result->m[j],pMult(p,pCopy(first->m[k])));
435 p = q;
436 }
437 j++;
438 }
439 }
440 if(syz_ring!=orig_ring)
441 {
442 rChangeCurrRing(syz_ring);
443 idDelete(&temp1);
444 rChangeCurrRing(orig_ring);
445 rDelete(syz_ring);
446 }
447 else
448 {
449 idDelete(&temp1);
450 }
451
453 SI_RESTORE_OPT1(save_opt);
455 {
456 w=NULL;
457 temp1=kStd2(result,currRing->qideal,testHomog,&w,(bigintmat*)NULL);
458 if (w!=NULL) delete w;
460 idSkipZeroes(temp1);
461 return temp1;
462 }
463 //else
464 // temp1=kInterRed(result,currRing->qideal);
465 return result;
466}
467
468/*2
469* ideal/module intersection for a list of objects
470* given as 'resolvente'
471*/
473{
474 int i,j=0,k=0,l,maxrk=-1,realrki;
475 unsigned syzComp;
476 ideal bigmat,tempstd,result;
477 poly p;
478 int isIdeal=0;
479
480 /* find 0-ideals and max rank -----------------------------------*/
481 for (i=0;i<length;i++)
482 {
483 if (!idIs0(arg[i]))
484 {
485 realrki=id_RankFreeModule(arg[i],currRing);
486 k++;
487 j += IDELEMS(arg[i]);
488 if (realrki>maxrk) maxrk = realrki;
489 }
490 else
491 {
492 if (arg[i]!=NULL)
493 {
494 return idInit(1,arg[i]->rank);
495 }
496 }
497 }
498 if (maxrk == 0)
499 {
500 isIdeal = 1;
501 maxrk = 1;
502 }
503 /* init -----------------------------------------------------------*/
504 j += maxrk;
505 syzComp = k*maxrk;
506
507 BITSET save_opt;
508 SI_SAVE_OPT1(save_opt);
510
511 ring orig_ring=currRing;
512 ring syz_ring=rAssure_SyzOrder(orig_ring,TRUE);
513 rSetSyzComp(syzComp,syz_ring);
514 rChangeCurrRing(syz_ring);
515
516 bigmat = idInit(j,(k+1)*maxrk);
517 /* create unit matrices ------------------------------------------*/
518 for (i=0;i<maxrk;i++)
519 {
520 for (j=0;j<=k;j++)
521 {
522 p = pOne();
523 pSetComp(p,i+1+j*maxrk);
524 pSetmComp(p);
525 bigmat->m[i] = pAdd(bigmat->m[i],p);
526 }
527 }
528 /* enter given ideals ------------------------------------------*/
529 i = maxrk;
530 k = 0;
531 for (j=0;j<length;j++)
532 {
533 if (arg[j]!=NULL)
534 {
535 for (l=0;l<IDELEMS(arg[j]);l++)
536 {
537 if (arg[j]->m[l]!=NULL)
538 {
539 if (syz_ring==orig_ring)
540 bigmat->m[i] = pCopy(arg[j]->m[l]);
541 else
542 bigmat->m[i] = prCopyR(arg[j]->m[l], orig_ring,currRing);
543 p_Shift(&(bigmat->m[i]),k*maxrk+isIdeal,currRing);
544 i++;
545 }
546 }
547 k++;
548 }
549 }
550 /* std computation --------------------------------------------*/
551 if ((alg!=GbDefault)
552 && (alg!=GbGroebner)
553 && (alg!=GbModstd)
554 && (alg!=GbSlimgb)
555 && (alg!=GbStd))
556 {
557 WarnS("wrong algorithm for GB");
558 alg=GbDefault;
559 }
560 tempstd=idGroebner(bigmat,syzComp,alg);
561
562 if(syz_ring!=orig_ring)
563 rChangeCurrRing(orig_ring);
564
565 /* interpret result ----------------------------------------*/
566 result = idInit(IDELEMS(tempstd),maxrk);
567 k = 0;
568 for (j=0;j<IDELEMS(tempstd);j++)
569 {
570 if ((tempstd->m[j]!=NULL) && (__p_GetComp(tempstd->m[j],syz_ring)>syzComp))
571 {
572 if (syz_ring==orig_ring)
573 p = pCopy(tempstd->m[j]);
574 else
575 p = prCopyR(tempstd->m[j], syz_ring,currRing);
576 p_Shift(&p,-syzComp-isIdeal,currRing);
577 result->m[k] = p;
578 k++;
579 }
580 }
581 /* clean up ----------------------------------------------------*/
582 if(syz_ring!=orig_ring)
583 rChangeCurrRing(syz_ring);
584 idDelete(&tempstd);
585 if(syz_ring!=orig_ring)
586 {
587 rChangeCurrRing(orig_ring);
588 rDelete(syz_ring);
589 }
590 SI_RESTORE_OPT1(save_opt);
592 return result;
593}
594
595/*2
596*computes syzygies of h1,
597*if quot != NULL it computes in the quotient ring modulo "quot"
598*works always in a ring with ringorder_s
599*/
600/* construct a "matrix" (h11 may be NULL)
601 * h1 h11
602 * E_n 0
603 * and compute a (column) GB of it, with a syzComp=rows(h1)=rows(h11)
604 * currRing must be a syz-ring with syzComp set
605 * result is a "matrix":
606 * G 0
607 * T S
608 * where G: GB of (h1+h11)
609 * T: G/h11=h1*T
610 * S: relative syzygies(h1) modulo h11
611 * if V_IDLIFT is set, ignore/do not return S
612 */
613static ideal idPrepare (ideal h1, ideal h11, tHomog hom, int syzcomp, intvec **w, GbVariant alg)
614{
615 ideal h2,h22;
616 int j,k;
617 poly p,q;
618
619 assume(!idIs0(h1));
621 if (h11!=NULL)
622 {
623 k = si_max(k,(int)id_RankFreeModule(h11,currRing));
624 h22=idCopy(h11);
625 }
626 h2=idCopy(h1);
627 int i = IDELEMS(h2);
628 if (h11!=NULL) i+=IDELEMS(h22);
629 if (k == 0)
630 {
631 id_Shift(h2,1,currRing);
632 if (h11!=NULL) id_Shift(h22,1,currRing);
633 k = 1;
634 }
635 if (syzcomp<k)
636 {
637 Warn("syzcomp too low, should be %d instead of %d",k,syzcomp);
638 syzcomp = k;
640 }
641 h2->rank = syzcomp+i;
642
643 //if (hom==testHomog)
644 //{
645 // if(idHomIdeal(h1,currRing->qideal))
646 // {
647 // hom=TRUE;
648 // }
649 //}
650
651 for (j=0; j<IDELEMS(h2); j++)
652 {
653 p = h2->m[j];
654 q = pOne();
655#ifdef HAVE_SHIFTBBA
656 // non multiplicative variable
657 if (rIsLPRing(currRing))
658 {
659 pSetExp(q, currRing->isLPring - currRing->LPncGenCount + j + 1, 1);
660 p_Setm(q, currRing);
661 }
662#endif
663 pSetComp(q,syzcomp+1+j);
664 pSetmComp(q);
665 if (p!=NULL)
666 {
667#ifdef HAVE_SHIFTBBA
668 if (rIsLPRing(currRing))
669 {
670 h2->m[j] = pAdd(p, q);
671 }
672 else
673#endif
674 {
675 while (pNext(p)) pIter(p);
676 p->next = q;
677 }
678 }
679 else
680 h2->m[j]=q;
681 }
682 if (h11!=NULL)
683 {
684 ideal h=id_SimpleAdd(h2,h22,currRing);
685 id_Delete(&h2,currRing);
686 id_Delete(&h22,currRing);
687 h2=h;
688 }
689
690 idTest(h2);
691 #if 0
693 PrintS(" --------------before std------------------------\n");
694 ipPrint_MA0(TT,"T");
695 PrintLn();
696 idDelete((ideal*)&TT);
697 #endif
698
699 if ((alg!=GbDefault)
700 && (alg!=GbGroebner)
701 && (alg!=GbModstd)
702 && (alg!=GbSlimgb)
703 && (alg!=GbStd))
704 {
705 WarnS("wrong algorithm for GB");
706 alg=GbDefault;
707 }
708
709 ideal h3;
710 if (w!=NULL) h3=idGroebner(h2,syzcomp,alg,NULL,*w,hom);
711 else h3=idGroebner(h2,syzcomp,alg,NULL,NULL,hom);
712 return h3;
713}
714
715ideal idExtractG_T_S(ideal s_h3,matrix *T,ideal *S,long syzComp,
716 int h1_size,BOOLEAN inputIsIdeal,const ring oring, const ring sring)
717{
718 // now sort the result, SB : leave in s_h3
719 // T: put in s_h2 (*T as a matrix)
720 // syz: put in *S
721 idSkipZeroes(s_h3);
722 ideal s_h2 = idInit(IDELEMS(s_h3), s_h3->rank); // will become T
723
724 #if 0
726 Print("after std: --------------syzComp=%d------------------------\n",syzComp);
727 ipPrint_MA0(TT,"T");
728 PrintLn();
729 idDelete((ideal*)&TT);
730 #endif
731
732 int j, i=0;
733 for (j=0; j<IDELEMS(s_h3); j++)
734 {
735 if (s_h3->m[j] != NULL)
736 {
737 if (pGetComp(s_h3->m[j]) <= syzComp) // syz_ring == currRing
738 {
739 i++;
740 poly q = s_h3->m[j];
741 while (pNext(q) != NULL)
742 {
743 if (pGetComp(pNext(q)) > syzComp)
744 {
745 s_h2->m[i-1] = pNext(q);
746 pNext(q) = NULL;
747 }
748 else
749 {
750 pIter(q);
751 }
752 }
753 if (!inputIsIdeal) p_Shift(&(s_h3->m[j]), -1,currRing);
754 }
755 else
756 {
757 // we a syzygy here:
758 if (S!=NULL)
759 {
760 p_Shift(&s_h3->m[j], -syzComp,currRing);
761 (*S)->m[j]=s_h3->m[j];
762 s_h3->m[j]=NULL;
763 }
764 else
765 p_Delete(&(s_h3->m[j]),currRing);
766 }
767 }
768 }
769 idSkipZeroes(s_h3);
770
771 #if 0
773 PrintS("T: ----------------------------------------\n");
774 ipPrint_MA0(TT,"T");
775 PrintLn();
776 idDelete((ideal*)&TT);
777 #endif
778
779 if (S!=NULL) idSkipZeroes(*S);
780
781 if (sring!=oring)
782 {
783 rChangeCurrRing(oring);
784 }
785
786 if (T!=NULL)
787 {
788 *T = mpNew(h1_size,i);
789
790 for (j=0; j<i; j++)
791 {
792 if (s_h2->m[j] != NULL)
793 {
794 poly q = prMoveR( s_h2->m[j], sring,oring);
795 s_h2->m[j] = NULL;
796
797 if (q!=NULL)
798 {
799 q=pReverse(q);
800 while (q != NULL)
801 {
802 poly p = q;
803 pIter(q);
804 pNext(p) = NULL;
805 int t=pGetComp(p);
806 pSetComp(p,0);
807 pSetmComp(p);
808 MATELEM(*T,t-syzComp,j+1) = pAdd(MATELEM(*T,t-syzComp,j+1),p);
809 }
810 }
811 }
812 }
813 }
814 id_Delete(&s_h2,sring);
815
816 for (i=0; i<IDELEMS(s_h3); i++)
817 {
818 s_h3->m[i] = prMoveR_NoSort(s_h3->m[i], sring,oring);
819 }
820 if (S!=NULL)
821 {
822 for (i=0; i<IDELEMS(*S); i++)
823 {
824 (*S)->m[i] = prMoveR_NoSort((*S)->m[i], sring,oring);
825 }
826 }
827 return s_h3;
828}
829
830/*2
831* compute the syzygies of h1 in R/quot,
832* weights of components are in w
833* if setRegularity, return the regularity in deg
834* do not change h1, w
835*/
836ideal idSyzygies (ideal h1, tHomog h,intvec **w, BOOLEAN setSyzComp,
837 BOOLEAN setRegularity, int *deg, GbVariant alg)
838{
839 ideal s_h1;
840 int j, k, length=0,reg;
841 BOOLEAN isMonomial=TRUE;
842 int ii, idElemens_h1;
843
844 assume(h1 != NULL);
845
846 idElemens_h1=IDELEMS(h1);
847#ifdef PDEBUG
848 for(ii=0;ii<idElemens_h1 /*IDELEMS(h1)*/;ii++) pTest(h1->m[ii]);
849#endif
850 if (idIs0(h1))
851 {
852 ideal result=idFreeModule(idElemens_h1/*IDELEMS(h1)*/);
853 return result;
854 }
855 int slength=(int)id_RankFreeModule(h1,currRing);
856 k=si_max(1,slength /*id_RankFreeModule(h1)*/);
857
858 assume(currRing != NULL);
859 ring orig_ring=currRing;
860 ring syz_ring=rAssure_SyzComp(orig_ring,TRUE);
861 if (setSyzComp) rSetSyzComp(k,syz_ring);
862
863 if (orig_ring != syz_ring)
864 {
865 rChangeCurrRing(syz_ring);
866 s_h1=idrCopyR_NoSort(h1,orig_ring,syz_ring);
867 }
868 else
869 {
870 s_h1 = h1;
871 }
872
873 idTest(s_h1);
874
875 BITSET save_opt;
876 SI_SAVE_OPT1(save_opt);
878
879 ideal s_h3=idPrepare(s_h1,NULL,h,k,w,alg); // main (syz) GB computation
880
881 SI_RESTORE_OPT1(save_opt);
882
883 if (orig_ring != syz_ring)
884 {
885 idDelete(&s_h1);
886 for (j=0; j<IDELEMS(s_h3); j++)
887 {
888 if (s_h3->m[j] != NULL)
889 {
890 if (p_MinComp(s_h3->m[j],syz_ring) > k)
891 p_Shift(&s_h3->m[j], -k,syz_ring);
892 else
893 p_Delete(&s_h3->m[j],syz_ring);
894 }
895 }
896 idSkipZeroes(s_h3);
897 s_h3->rank -= k;
898 rChangeCurrRing(orig_ring);
899 s_h3 = idrMoveR_NoSort(s_h3, syz_ring, orig_ring);
900 rDelete(syz_ring);
901 #ifdef HAVE_PLURAL
902 if (rIsPluralRing(orig_ring))
903 {
904 id_DelMultiples(s_h3,orig_ring);
905 idSkipZeroes(s_h3);
906 }
907 #endif
908 idTest(s_h3);
909 return s_h3;
910 }
911
912 ideal e = idInit(IDELEMS(s_h3), s_h3->rank);
913
914 for (j=IDELEMS(s_h3)-1; j>=0; j--)
915 {
916 if (s_h3->m[j] != NULL)
917 {
918 if (p_MinComp(s_h3->m[j],syz_ring) <= k)
919 {
920 e->m[j] = s_h3->m[j];
921 isMonomial=isMonomial && (pNext(s_h3->m[j])==NULL);
922 p_Delete(&pNext(s_h3->m[j]),syz_ring);
923 s_h3->m[j] = NULL;
924 }
925 }
926 }
927
928 idSkipZeroes(s_h3);
929 idSkipZeroes(e);
930
931 if ((deg != NULL)
932 && (!isMonomial)
934 && (setRegularity)
935 && (h==isHomog)
938 )
939 {
940 assume(orig_ring==syz_ring);
941 ring dp_C_ring = rAssure_dp_C(syz_ring); // will do rChangeCurrRing later
942 if (dp_C_ring != syz_ring)
943 {
944 rChangeCurrRing(dp_C_ring);
945 e = idrMoveR_NoSort(e, syz_ring, dp_C_ring);
946 }
948 intvec * dummy = syBetti(res,length,&reg, *w);
949 *deg = reg+2;
950 delete dummy;
951 for (j=0;j<length;j++)
952 {
953 if (res[j]!=NULL) idDelete(&(res[j]));
954 }
955 omFreeSize((ADDRESS)res,length*sizeof(ideal));
956 idDelete(&e);
957 if (dp_C_ring != orig_ring)
958 {
959 rChangeCurrRing(orig_ring);
960 rDelete(dp_C_ring);
961 }
962 }
963 else
964 {
965 idDelete(&e);
966 }
967 assume(orig_ring==currRing);
968 idTest(s_h3);
969 if (currRing->qideal != NULL)
970 {
971 ideal ts_h3=kStd2(s_h3,currRing->qideal,h,w,(bigintmat*)NULL);
972 idDelete(&s_h3);
973 s_h3 = ts_h3;
974 }
975 return s_h3;
976}
977
978/*
979*computes a standard basis for h1 and stores the transformation matrix
980* in ma
981*/
982ideal idLiftStd (ideal h1, matrix* T, tHomog hi, ideal * S, GbVariant alg,
983 ideal h11)
984{
985 int inputIsIdeal=id_RankFreeModule(h1,currRing);
986 long k;
987 intvec *w=NULL;
988
989 idDelete((ideal*)T);
990 BOOLEAN lift3=FALSE;
991 if (S!=NULL) { lift3=TRUE; idDelete(S); }
992 if (idIs0(h1))
993 {
994 *T=mpNew(1,IDELEMS(h1));
995 if (lift3)
996 {
997 *S=idFreeModule(IDELEMS(h1));
998 }
999 return idInit(1,h1->rank);
1000 }
1001
1002 BITSET saveOpt1,saveOpt2;
1003 SI_SAVE_OPT(saveOpt1,saveOpt2);
1005 k=si_max(1,inputIsIdeal);
1006
1007 if ((!lift3)&&(!TEST_OPT_RETURN_SB)) si_opt_2 |=Sy_bit(V_IDLIFT);
1008
1009 ring orig_ring = currRing;
1010 ring syz_ring = rAssure_SyzOrder(orig_ring,TRUE);
1011 rSetSyzComp(k,syz_ring);
1012 rChangeCurrRing(syz_ring);
1013
1014 ideal s_h1;
1015
1016 if (orig_ring != syz_ring)
1017 s_h1 = idrCopyR_NoSort(h1,orig_ring,syz_ring);
1018 else
1019 s_h1 = h1;
1020 ideal s_h11=NULL;
1021 if (h11!=NULL)
1022 {
1023 s_h11=idrCopyR_NoSort(h11,orig_ring,syz_ring);
1024 }
1025
1026
1027 ideal s_h3=idPrepare(s_h1,s_h11,hi,k,&w,alg); // main (syz) GB computation
1028
1029
1030 if (w!=NULL) delete w;
1031 if (syz_ring!=orig_ring)
1032 {
1033 idDelete(&s_h1);
1034 if (s_h11!=NULL) idDelete(&s_h11);
1035 }
1036
1037 if (S!=NULL) (*S)=idInit(IDELEMS(s_h3),IDELEMS(h1));
1038
1039 s_h3=idExtractG_T_S(s_h3,T,S,k,IDELEMS(h1),inputIsIdeal,orig_ring,syz_ring);
1040
1041 if (syz_ring!=orig_ring) rDelete(syz_ring);
1042 s_h3->rank=h1->rank;
1043 SI_RESTORE_OPT(saveOpt1,saveOpt2);
1044 return s_h3;
1045}
1046
1047static void idPrepareStd(ideal s_temp, int k)
1048{
1049 int j,rk=id_RankFreeModule(s_temp,currRing);
1050 poly p,q;
1051
1052 if (rk == 0)
1053 {
1054 for (j=0; j<IDELEMS(s_temp); j++)
1055 {
1056 if (s_temp->m[j]!=NULL) pSetCompP(s_temp->m[j],1);
1057 }
1058 k = si_max(k,1);
1059 }
1060 for (j=0; j<IDELEMS(s_temp); j++)
1061 {
1062 if (s_temp->m[j]!=NULL)
1063 {
1064 p = s_temp->m[j];
1065 q = pOne();
1066 //pGetCoeff(q)=nInpNeg(pGetCoeff(q)); //set q to -1
1067 pSetComp(q,k+1+j);
1068 pSetmComp(q);
1069#ifdef HAVE_SHIFTBBA
1070 // non multiplicative variable
1071 if (rIsLPRing(currRing))
1072 {
1073 pSetExp(q, currRing->isLPring - currRing->LPncGenCount + j + 1, 1);
1074 p_Setm(q, currRing);
1075 s_temp->m[j] = pAdd(p, q);
1076 }
1077 else
1078#endif
1079 {
1080 while (pNext(p)) pIter(p);
1081 pNext(p) = q;
1082 }
1083 }
1084 }
1085 s_temp->rank = k+IDELEMS(s_temp);
1086}
1087
1088static void idLift_setUnit(int e_mod, matrix *unit)
1089{
1090 if (unit!=NULL)
1091 {
1092 *unit=mpNew(e_mod,e_mod);
1093 // make sure that U is a diagonal matrix of units
1094 for(int i=e_mod;i>0;i--)
1095 {
1096 MATELEM(*unit,i,i)=pOne();
1097 }
1098 }
1099}
1100/*2
1101*computes a representation of the generators of submod with respect to those
1102* of mod
1103*/
1104/// represents the generators of submod in terms of the generators of mod
1105/// (Matrix(SM)*U-Matrix(rest)) = Matrix(M)*Matrix(result)
1106/// goodShape: maximal non-zero index in generators of SM <= that of M
1107/// isSB: generators of M form a Groebner basis
1108/// divide: allow SM not to be a submodule of M
1109/// U is an diagonal matrix of units (non-constant only in local rings)
1110/// rest is: 0 if SM in M, SM if not divide, NF(SM,std(M)) if divide
1111ideal idLift(ideal mod, ideal submod,ideal *rest, BOOLEAN goodShape,
1112 BOOLEAN isSB, BOOLEAN divide, matrix *unit, GbVariant alg)
1113{
1114 int lsmod =id_RankFreeModule(submod,currRing), j, k;
1115 int comps_to_add=0;
1116 int idelems_mod=IDELEMS(mod);
1117 int idelems_submod=IDELEMS(submod);
1118 poly p;
1119
1120 if (idIs0(submod))
1121 {
1122 if (rest!=NULL)
1123 {
1124 *rest=idInit(1,mod->rank);
1125 }
1126 idLift_setUnit(idelems_submod,unit);
1127 return idInit(1,idelems_mod);
1128 }
1129 if (idIs0(mod)) /* and not idIs0(submod) */
1130 {
1131 if (rest!=NULL)
1132 {
1133 *rest=idCopy(submod);
1134 idLift_setUnit(idelems_submod,unit);
1135 return idInit(1,idelems_mod);
1136 }
1137 else
1138 {
1139 WerrorS("2nd module does not lie in the first");
1140 return NULL;
1141 }
1142 }
1143 if (unit!=NULL)
1144 {
1145 comps_to_add = idelems_submod;
1146 while ((comps_to_add>0) && (submod->m[comps_to_add-1]==NULL))
1147 comps_to_add--;
1148 }
1150 if ((k!=0) && (lsmod==0)) lsmod=1;
1151 k=si_max(k,(int)mod->rank);
1152 if (k<submod->rank) { WarnS("rk(submod) > rk(mod) ?");k=submod->rank; }
1153
1154 ring orig_ring=currRing;
1155 ring syz_ring=rAssure_SyzOrder(orig_ring,TRUE);
1156 rSetSyzComp(k,syz_ring);
1157 rChangeCurrRing(syz_ring);
1158
1159 ideal s_mod, s_temp;
1160 if (orig_ring != syz_ring)
1161 {
1162 s_mod = idrCopyR_NoSort(mod,orig_ring,syz_ring);
1163 s_temp = idrCopyR_NoSort(submod,orig_ring,syz_ring);
1164 }
1165 else
1166 {
1167 s_mod = idCopy(mod);
1168 s_temp = idCopy(submod);
1169 }
1170 BITSET save2;
1171 SI_SAVE_OPT2(save2);
1172
1173 if ((rest==NULL)
1175 && (!rIsNCRing(currRing))
1176 && (!TEST_OPT_RETURN_SB))
1178 else
1180 ideal s_h3;
1181 if (isSB && !TEST_OPT_IDLIFT)
1182 {
1183 s_h3 = idCopy(s_mod);
1184 idPrepareStd(s_h3, k+comps_to_add);
1185 }
1186 else
1187 {
1188 s_h3 = idPrepare(s_mod,NULL,(tHomog)FALSE,k+comps_to_add,NULL,alg);
1189 }
1190 SI_RESTORE_OPT2(save2);
1191 if (errorreported)
1192 {
1193 rChangeCurrRing(orig_ring);
1194 return NULL;
1195 }
1196
1197 if (!goodShape)
1198 {
1199 for (j=0;j<IDELEMS(s_h3);j++)
1200 {
1201 if ((s_h3->m[j] != NULL) && (pMinComp(s_h3->m[j]) > k))
1202 p_Delete(&(s_h3->m[j]),currRing);
1203 }
1204 }
1205 idSkipZeroes(s_h3);
1206 if (lsmod==0)
1207 {
1208 id_Shift(s_temp,1,currRing);
1209 }
1210 if (unit!=NULL)
1211 {
1212 for(j = 0;j<comps_to_add;j++)
1213 {
1214 p = s_temp->m[j];
1215 if (p!=NULL)
1216 {
1217 while (pNext(p)!=NULL) pIter(p);
1218 pNext(p) = pOne();
1219 pIter(p);
1220 pSetComp(p,1+j+k);
1221 pSetmComp(p);
1222 p = pNeg(p);
1223 }
1224 }
1225 s_temp->rank += (k+comps_to_add);
1226 }
1227 ideal s_result = kNF(s_h3,currRing->qideal,s_temp,k);
1228 s_result->rank = s_h3->rank;
1229 ideal s_rest = idInit(IDELEMS(s_result),k);
1230 idDelete(&s_h3);
1231 idDelete(&s_temp);
1232
1233 for (j=0;j<IDELEMS(s_result);j++)
1234 {
1235 if (s_result->m[j]!=NULL)
1236 {
1237 if (pGetComp(s_result->m[j])<=k)
1238 {
1239 if (!divide)
1240 {
1241 if (rest==NULL)
1242 {
1243 if (isSB)
1244 {
1245 WarnS("first module not a standardbasis\n"
1246 "// ** or second not a proper submodule");
1247 }
1248 else
1249 WerrorS("2nd module does not lie in the first");
1250 }
1251 idDelete(&s_result);
1252 idDelete(&s_rest);
1253 if(syz_ring!=orig_ring)
1254 {
1255 idDelete(&s_mod);
1256 rChangeCurrRing(orig_ring);
1257 rDelete(syz_ring);
1258 }
1259 if (unit!=NULL)
1260 {
1261 idLift_setUnit(idelems_submod,unit);
1262 }
1263 if (rest!=NULL) *rest=idCopy(submod);
1264 s_result=idInit(idelems_submod,idelems_mod);
1265 return s_result;
1266 }
1267 else
1268 {
1269 p = s_rest->m[j] = s_result->m[j];
1270 while ((pNext(p)!=NULL) && (pGetComp(pNext(p))<=k)) pIter(p);
1271 s_result->m[j] = pNext(p);
1272 pNext(p) = NULL;
1273 }
1274 }
1275 p_Shift(&(s_result->m[j]),-k,currRing);
1276 pNeg(s_result->m[j]);
1277 }
1278 }
1279 if ((lsmod==0) && (s_rest!=NULL))
1280 {
1281 for (j=IDELEMS(s_rest);j>0;j--)
1282 {
1283 if (s_rest->m[j-1]!=NULL)
1284 {
1285 p_Shift(&(s_rest->m[j-1]),-1,currRing);
1286 }
1287 }
1288 }
1289 if(syz_ring!=orig_ring)
1290 {
1291 idDelete(&s_mod);
1292 rChangeCurrRing(orig_ring);
1293 s_result = idrMoveR_NoSort(s_result, syz_ring, orig_ring);
1294 s_rest = idrMoveR_NoSort(s_rest, syz_ring, orig_ring);
1295 rDelete(syz_ring);
1296 }
1297 if (rest!=NULL)
1298 {
1299 s_rest->rank=mod->rank;
1300 *rest = s_rest;
1301 }
1302 else
1303 idDelete(&s_rest);
1304 if (unit!=NULL)
1305 {
1306 *unit=mpNew(idelems_submod,idelems_submod);
1307 int i;
1308 for(i=0;i<IDELEMS(s_result);i++)
1309 {
1310 poly p=s_result->m[i];
1311 poly q=NULL;
1312 while(p!=NULL)
1313 {
1314 if(pGetComp(p)<=comps_to_add)
1315 {
1316 pSetComp(p,0);
1317 if (q!=NULL)
1318 {
1319 pNext(q)=pNext(p);
1320 }
1321 else
1322 {
1323 pIter(s_result->m[i]);
1324 }
1325 pNext(p)=NULL;
1326 MATELEM(*unit,i+1,i+1)=pAdd(MATELEM(*unit,i+1,i+1),p);
1327 if(q!=NULL) p=pNext(q);
1328 else p=s_result->m[i];
1329 }
1330 else
1331 {
1332 q=p;
1333 pIter(p);
1334 }
1335 }
1336 p_Shift(&s_result->m[i],-comps_to_add,currRing);
1337 }
1338 }
1339 s_result->rank=idelems_mod;
1340 return s_result;
1341}
1342
1343/*2
1344*computes division of P by Q with remainder up to (w-weighted) degree n
1345*P, Q, and w are not changed
1346*/
1347void idLiftW(ideal P,ideal Q,int n,matrix &T, ideal &R,int *w)
1348{
1349 long N=0;
1350 int i;
1351 for(i=IDELEMS(Q)-1;i>=0;i--)
1352 if(w==NULL)
1353 N=si_max(N,p_Deg(Q->m[i],currRing));
1354 else
1355 N=si_max(N,p_DegW(Q->m[i],w,currRing));
1356 N+=n;
1357
1358 T=mpNew(IDELEMS(Q),IDELEMS(P));
1359 R=idInit(IDELEMS(P),P->rank);
1360
1361 for(i=IDELEMS(P)-1;i>=0;i--)
1362 {
1363 poly p;
1364 if(w==NULL)
1365 p=ppJet(P->m[i],N);
1366 else
1367 p=ppJetW(P->m[i],N,w);
1368
1369 int j=IDELEMS(Q)-1;
1370 while(p!=NULL)
1371 {
1372 if(pDivisibleBy(Q->m[j],p))
1373 {
1374 poly p0=p_DivideM(pHead(p),pHead(Q->m[j]),currRing);
1375 if(w==NULL)
1376 p=pJet(pSub(p,ppMult_mm(Q->m[j],p0)),N);
1377 else
1378 p=pJetW(pSub(p,ppMult_mm(Q->m[j],p0)),N,w);
1379 pNormalize(p);
1380 if(((w==NULL)&&(p_Deg(p0,currRing)>n))||((w!=NULL)&&(p_DegW(p0,w,currRing)>n)))
1381 p_Delete(&p0,currRing);
1382 else
1383 MATELEM(T,j+1,i+1)=pAdd(MATELEM(T,j+1,i+1),p0);
1384 j=IDELEMS(Q)-1;
1385 }
1386 else
1387 {
1388 if(j==0)
1389 {
1390 poly p0=p;
1391 pIter(p);
1392 pNext(p0)=NULL;
1393 if(((w==NULL)&&(p_Deg(p0,currRing)>n))
1394 ||((w!=NULL)&&(p_DegW(p0,w,currRing)>n)))
1395 p_Delete(&p0,currRing);
1396 else
1397 R->m[i]=pAdd(R->m[i],p0);
1398 j=IDELEMS(Q)-1;
1399 }
1400 else
1401 j--;
1402 }
1403 }
1404 }
1405}
1406
1407/*2
1408*computes the quotient of h1,h2 : internal routine for idQuot
1409*BEWARE: the returned ideals may contain incorrectly ordered polys !
1410*
1411*/
1412static ideal idInitializeQuot (ideal h1, ideal h2, BOOLEAN h1IsStb, BOOLEAN *addOnlyOne, int *kkmax)
1413{
1414 idTest(h1);
1415 idTest(h2);
1416
1417 ideal temph1;
1418 poly p,q = NULL;
1419 int i,l,ll,k,kkk,kmax;
1420 int j = 0;
1421 int k1 = id_RankFreeModule(h1,currRing);
1422 int k2 = id_RankFreeModule(h2,currRing);
1423 tHomog hom=isNotHomog;
1424 k=si_max(k1,k2);
1425 if (k==0)
1426 k = 1;
1427 if ((k2==0) && (k>1)) *addOnlyOne = FALSE;
1428 intvec * weights;
1429 hom = (tHomog)idHomModule(h1,currRing->qideal,&weights);
1430 if /**addOnlyOne &&*/ (/*(*/ !h1IsStb /*)*/)
1431 temph1 = kStd2(h1,currRing->qideal,hom,&weights,(bigintmat*)NULL);
1432 else
1433 temph1 = idCopy(h1);
1434 if (weights!=NULL) delete weights;
1435 if (currRing->qideal!=NULL)
1436 {
1437 int kk=si_max(k1,k2);
1438 if (kk==0)
1439 {
1440 ideal tmp=id_SimpleAdd(temph1,currRing->qideal,currRing);
1441 id_Delete(&temph1,currRing);
1442 temph1=tmp;
1443 }
1444 else
1445 {
1446 for(int i=1;i<=kk;i++)
1447 {
1448 ideal q=id_Copy(currRing->qideal,currRing);
1449 id_Shift(q,i,currRing); q->rank=i;
1450 ideal tmp=id_SimpleAdd(temph1,q,currRing);
1451 id_Delete(&q,currRing);
1452 id_Delete(&temph1,currRing);
1453 temph1=tmp;
1454 }
1455 }
1456 }
1457 idTest(temph1);
1458/*--- making a single vector from h2 ---------------------*/
1459 for (i=0; i<IDELEMS(h2); i++)
1460 {
1461 if (h2->m[i] != NULL)
1462 {
1463 p = pCopy(h2->m[i]);
1464 if (k2 == 0)
1465 p_Shift(&p,j*k+1,currRing);
1466 else
1467 p_Shift(&p,j*k,currRing);
1468 q = pAdd(q,p);
1469 j++;
1470 }
1471 }
1472 *kkmax = kmax = j*k+1;
1473/*--- adding a monomial for the result (syzygy) ----------*/
1474 p = q;
1475 while (pNext(p)!=NULL) pIter(p);
1476 pNext(p) = pOne();
1477 pIter(p);
1478 pSetComp(p,kmax);
1479 pSetmComp(p);
1480/*--- constructing the big matrix ------------------------*/
1481 ideal h4 = idInit(k,kmax+k-1);
1482 h4->m[0] = q;
1483 if (k2 == 0)
1484 {
1485 for (i=1; i<k; i++)
1486 {
1487 if (h4->m[i-1]!=NULL)
1488 {
1489 p = p_Copy_noCheck(h4->m[i-1], currRing); /*h4->m[i-1]!=NULL*/
1490 p_Shift(&p,1,currRing);
1491 h4->m[i] = p;
1492 }
1493 else break;
1494 }
1495 }
1496 idSkipZeroes(h4);
1497 kkk = IDELEMS(h4);
1498 i = IDELEMS(temph1);
1499 for (l=0; l<i; l++)
1500 {
1501 if(temph1->m[l]!=NULL)
1502 {
1503 for (ll=0; ll<j; ll++)
1504 {
1505 p = pCopy(temph1->m[l]);
1506 if (k1 == 0)
1507 p_Shift(&p,ll*k+1,currRing);
1508 else
1509 p_Shift(&p,ll*k,currRing);
1510 if (kkk >= IDELEMS(h4))
1511 {
1512 pEnlargeSet(&(h4->m),IDELEMS(h4),16);
1513 IDELEMS(h4) += 16;
1514 }
1515 h4->m[kkk] = p;
1516 kkk++;
1517 }
1518 }
1519 }
1520/*--- if h2 goes in as single vector - the h1-part is just SB ---*/
1521 if (*addOnlyOne)
1522 {
1523 idSkipZeroes(h4);
1524 p = h4->m[0];
1525 for (i=0;i<IDELEMS(h4)-1;i++)
1526 {
1527 h4->m[i] = h4->m[i+1];
1528 }
1529 h4->m[IDELEMS(h4)-1] = p;
1530 }
1531 idDelete(&temph1);
1532 //idTest(h4);//see remark at the beginning
1533 return h4;
1534}
1535
1536/*2
1537*computes the quotient of h1,h2
1538*/
1539ideal idQuot (ideal h1, ideal h2, BOOLEAN h1IsStb, BOOLEAN resultIsIdeal)
1540{
1541 // first check for special case h1:(0)
1542 if (idIs0(h2))
1543 {
1544 ideal res;
1545 if (resultIsIdeal)
1546 {
1547 res = idInit(1,1);
1548 res->m[0] = pOne();
1549 }
1550 else
1551 res = idFreeModule(h1->rank);
1552 return res;
1553 }
1554 int i, kmax;
1555 BOOLEAN addOnlyOne=TRUE;
1556 tHomog hom=isNotHomog;
1557 intvec * weights1;
1558
1559 ideal s_h4 = idInitializeQuot (h1,h2,h1IsStb,&addOnlyOne,&kmax);
1560
1561 hom = (tHomog)idHomModule(s_h4,currRing->qideal,&weights1);
1562
1563 ring orig_ring=currRing;
1564 ring syz_ring=rAssure_SyzOrder(orig_ring,TRUE);
1565 rSetSyzComp(kmax-1,syz_ring);
1566 rChangeCurrRing(syz_ring);
1567 if (orig_ring!=syz_ring)
1568 // s_h4 = idrMoveR_NoSort(s_h4,orig_ring, syz_ring);
1569 s_h4 = idrMoveR(s_h4,orig_ring, syz_ring);
1570 idTest(s_h4);
1571
1572 #if 0
1573 matrix m=idModule2Matrix(idCopy(s_h4));
1574 PrintS("start:\n");
1575 ipPrint_MA0(m,"Q");
1576 idDelete((ideal *)&m);
1577 PrintS("last elem:");wrp(s_h4->m[IDELEMS(s_h4)-1]);PrintLn();
1578 #endif
1579
1580 ideal s_h3;
1581 BITSET old_test1;
1582 SI_SAVE_OPT1(old_test1);
1584 if (addOnlyOne)
1585 {
1587 s_h3 = kStd2(s_h4,currRing->qideal,hom,&weights1,(bigintmat*)NULL,0/*kmax-1*/,IDELEMS(s_h4)-1);
1588 }
1589 else
1590 {
1591 //s_h3 = kStd2(s_h4,currRing->qideal,hom,&weights1,(bigintmat*)NULL,kmax-1);
1592 // qideal added in idInitializeQuotient
1593 s_h3 = kStd2(s_h4,NULL,hom,&weights1,(bigintmat*)NULL,kmax-1);
1594 }
1595 SI_RESTORE_OPT1(old_test1);
1596
1597 #if 0
1598 // only together with the above debug stuff
1599 idSkipZeroes(s_h3);
1600 m=idModule2Matrix(idCopy(s_h3));
1601 Print("result, kmax=%d:\n",kmax);
1602 ipPrint_MA0(m,"S");
1603 idDelete((ideal *)&m);
1604 #endif
1605
1606 idTest(s_h3);
1607 if (weights1!=NULL) delete weights1;
1608 idDelete(&s_h4);
1609
1610 for (i=0;i<IDELEMS(s_h3);i++)
1611 {
1612 if ((s_h3->m[i]!=NULL) && (pGetComp(s_h3->m[i])>=kmax))
1613 {
1614 if (resultIsIdeal)
1615 p_Shift(&s_h3->m[i],-kmax,currRing);
1616 else
1617 p_Shift(&s_h3->m[i],-kmax+1,currRing);
1618 }
1619 else
1620 p_Delete(&s_h3->m[i],currRing);
1621 }
1622 if (resultIsIdeal)
1623 s_h3->rank = 1;
1624 else
1625 s_h3->rank = h1->rank;
1626 if(syz_ring!=orig_ring)
1627 {
1628 rChangeCurrRing(orig_ring);
1629 s_h3 = idrMoveR_NoSort(s_h3, syz_ring, orig_ring);
1630 rDelete(syz_ring);
1631 }
1632 idSkipZeroes(s_h3);
1633 idTest(s_h3);
1634 return s_h3;
1635}
1636
1637/*2
1638* eliminate delVar (product of vars) in h1
1639*/
1640ideal idElimination2 (ideal h1,poly delVar,bigintmat *hilb, GbVariant alg)
1641{
1642 int i,j=0,k,l;
1643 ideal h,hh, h3;
1644 rRingOrder_t *ord;
1645 int *block0,*block1;
1646 int ordersize=2;
1647 int **wv;
1648 tHomog hom;
1649 intvec * w;
1650 ring tmpR;
1651 ring origR = currRing;
1652
1653 if (delVar==NULL)
1654 {
1655 return idCopy(h1);
1656 }
1657 if ((currRing->qideal!=NULL) && rIsPluralRing(origR))
1658 {
1659 WerrorS("cannot eliminate in a qring");
1660 return NULL;
1661 }
1662 if (idIs0(h1)) return idInit(1,h1->rank);
1663#ifdef HAVE_PLURAL
1664 if (rIsPluralRing(origR))
1665 /* in the NC case, we have to check the admissibility of */
1666 /* the subalgebra to be intersected with */
1667 {
1668 if ((ncRingType(origR) != nc_skew) && (ncRingType(origR) != nc_exterior)) /* in (quasi)-commutative algebras every subalgebra is admissible */
1669 {
1670 if (nc_CheckSubalgebra(delVar,origR))
1671 {
1672 WerrorS("no elimination is possible: subalgebra is not admissible");
1673 return NULL;
1674 }
1675 }
1676 }
1677#endif
1678 hom=(tHomog)idHomModule(h1,NULL,&w); //sets w to weight vector or NULL
1679 h3=idInit(16,h1->rank);
1680 ordersize=rBlocks(origR)+1;
1681#if 0
1682 if (rIsPluralRing(origR)) // we have too keep the ordering: it may be needed
1683 // for G-algebra
1684 {
1685 for (k=0;k<ordersize-1; k++)
1686 {
1687 block0[k+1] = origR->block0[k];
1688 block1[k+1] = origR->block1[k];
1689 ord[k+1] = origR->order[k];
1690 if (origR->wvhdl[k]!=NULL) wv[k+1] = (int*) omMemDup(origR->wvhdl[k]);
1691 }
1692 }
1693 else
1694 {
1695 block0[1] = 1;
1696 block1[1] = (currRing->N);
1697 if (origR->OrdSgn==1) ord[1] = ringorder_wp;
1698 else ord[1] = ringorder_ws;
1699 wv[1]=(int*)omAlloc0((currRing->N)*sizeof(int));
1700 double wNsqr = (double)2.0 / (double)(currRing->N);
1702 int *x= (int * )omAlloc(2 * ((currRing->N) + 1) * sizeof(int));
1703 int sl=IDELEMS(h1) - 1;
1704 wCall(h1->m, sl, x, wNsqr);
1705 for (sl = (currRing->N); sl!=0; sl--)
1706 wv[1][sl-1] = x[sl + (currRing->N) + 1];
1707 omFreeSize((ADDRESS)x, 2 * ((currRing->N) + 1) * sizeof(int));
1708
1709 ord[2]=ringorder_C;
1710 ord[3]=0;
1711 }
1712#else
1713#endif
1714 if ((hom==TRUE) && (origR->OrdSgn==1) && (!rIsPluralRing(origR)))
1715 {
1716 #if 1
1717 // we change to an ordering:
1718 // aa(1,1,1,...,0,0,0),wp(...),C
1719 // this seems to be better than version 2 below,
1720 // according to Tst/../elimiate_[3568].tat (- 17 %)
1721 ord=(rRingOrder_t*)omAlloc0(4*sizeof(rRingOrder_t));
1722 block0=(int*)omAlloc0(4*sizeof(int));
1723 block1=(int*)omAlloc0(4*sizeof(int));
1724 wv=(int**) omAlloc0(4*sizeof(int**));
1725 block0[0] = block0[1] = 1;
1726 block1[0] = block1[1] = rVar(origR);
1727 wv[0]=(int*)omAlloc0((rVar(origR) + 1)*sizeof(int));
1728 // use this special ordering: like ringorder_a, except that pFDeg, pWeights
1729 // ignore it
1730 ord[0] = ringorder_aa;
1731 for (j=0;j<rVar(origR);j++)
1732 if (pGetExp(delVar,j+1)!=0) wv[0][j]=1;
1733 BOOLEAN wp=FALSE;
1734 for (j=0;j<rVar(origR);j++)
1735 if (p_Weight(j+1,origR)!=1) { wp=TRUE;break; }
1736 if (wp)
1737 {
1738 wv[1]=(int*)omAlloc0((rVar(origR) + 1)*sizeof(int));
1739 for (j=0;j<rVar(origR);j++)
1740 wv[1][j]=p_Weight(j+1,origR);
1741 ord[1] = ringorder_wp;
1742 }
1743 else
1744 ord[1] = ringorder_dp;
1745 #else
1746 // we change to an ordering:
1747 // a(w1,...wn),wp(1,...0.....),C
1748 ord=(int*)omAlloc0(4*sizeof(int));
1749 block0=(int*)omAlloc0(4*sizeof(int));
1750 block1=(int*)omAlloc0(4*sizeof(int));
1751 wv=(int**) omAlloc0(4*sizeof(int**));
1752 block0[0] = block0[1] = 1;
1753 block1[0] = block1[1] = rVar(origR);
1754 wv[0]=(int*)omAlloc0((rVar(origR) + 1)*sizeof(int));
1755 wv[1]=(int*)omAlloc0((rVar(origR) + 1)*sizeof(int));
1756 ord[0] = ringorder_a;
1757 for (j=0;j<rVar(origR);j++)
1758 wv[0][j]=pWeight(j+1,origR);
1759 ord[1] = ringorder_wp;
1760 for (j=0;j<rVar(origR);j++)
1761 if (pGetExp(delVar,j+1)!=0) wv[1][j]=1;
1762 #endif
1763 ord[2] = ringorder_C;
1764 ord[3] = (rRingOrder_t)0;
1765 }
1766 else
1767 {
1768 // we change to an ordering:
1769 // aa(....),orig_ordering
1770 ord=(rRingOrder_t*)omAlloc0(ordersize*sizeof(rRingOrder_t));
1771 block0=(int*)omAlloc0(ordersize*sizeof(int));
1772 block1=(int*)omAlloc0(ordersize*sizeof(int));
1773 wv=(int**) omAlloc0(ordersize*sizeof(int**));
1774 for (k=0;k<ordersize-1; k++)
1775 {
1776 block0[k+1] = origR->block0[k];
1777 block1[k+1] = origR->block1[k];
1778 ord[k+1] = origR->order[k];
1779 if (origR->wvhdl[k]!=NULL)
1780 #ifdef HAVE_OMALLOC
1781 wv[k+1] = (int*) omMemDup(origR->wvhdl[k]);
1782 #else
1783 {
1784 int l=(origR->block1[k]-origR->block0[k]+1)*sizeof(int);
1785 if (origR->order[k]==ringorder_a64) l*=2;
1786 wv[k+1]=(int*)omalloc(l);
1787 memcpy(wv[k+1],origR->wvhdl[k],l);
1788 }
1789 #endif
1790 }
1791 block0[0] = 1;
1792 block1[0] = rVar(origR);
1793 wv[0]=(int*)omAlloc0((rVar(origR) + 1)*sizeof(int));
1794 for (j=0;j<rVar(origR);j++)
1795 if (pGetExp(delVar,j+1)!=0) wv[0][j]=1;
1796 // use this special ordering: like ringorder_a, except that pFDeg, pWeights
1797 // ignore it
1798 ord[0] = ringorder_aa;
1799 }
1800 // fill in tmp ring to get back the data later on
1801 tmpR = rCopy0(origR,FALSE,FALSE); // qring==NULL
1802 //rUnComplete(tmpR);
1803 tmpR->p_Procs=NULL;
1804 tmpR->order = ord;
1805 tmpR->block0 = block0;
1806 tmpR->block1 = block1;
1807 tmpR->wvhdl = wv;
1808 rComplete(tmpR, 1);
1809
1810#ifdef HAVE_PLURAL
1811 /* update nc structure on tmpR */
1812 if (rIsPluralRing(origR))
1813 {
1814 if ( nc_rComplete(origR, tmpR, false) ) // no quotient ideal!
1815 {
1816 WerrorS("no elimination is possible: ordering condition is violated");
1817 // cleanup
1818 rDelete(tmpR);
1819 if (w!=NULL)
1820 delete w;
1821 return NULL;
1822 }
1823 }
1824#endif
1825 // change into the new ring
1826 //pChangeRing((currRing->N),currRing->OrdSgn,ord,block0,block1,wv);
1827 rChangeCurrRing(tmpR);
1828
1829 //h = idInit(IDELEMS(h1),h1->rank);
1830 // fetch data from the old ring
1831 //for (k=0;k<IDELEMS(h1);k++) h->m[k] = prCopyR( h1->m[k], origR);
1832 h=idrCopyR(h1,origR,currRing);
1833 if (origR->qideal!=NULL)
1834 {
1835 WarnS("eliminate in q-ring: experimental");
1836 ideal q=idrCopyR(origR->qideal,origR,currRing);
1837 ideal s=idSimpleAdd(h,q);
1838 idDelete(&h);
1839 idDelete(&q);
1840 h=s;
1841 }
1842 // compute GB
1843 if ((alg!=GbDefault)
1844 && (alg!=GbGroebner)
1845 && (alg!=GbModstd)
1846 && (alg!=GbSlimgb)
1847 && (alg!=GbSba)
1848 && (alg!=GbStd))
1849 {
1850 WarnS("wrong algorithm for GB");
1851 alg=GbDefault;
1852 }
1853 hh=idGroebner(h,0,alg,hilb);
1854 // go back to the original ring
1855 rChangeCurrRing(origR);
1856 i = IDELEMS(hh)-1;
1857 while ((i >= 0) && (hh->m[i] == NULL)) i--;
1858 j = -1;
1859 // fetch data from temp ring
1860 for (k=0; k<=i; k++)
1861 {
1862 l=(currRing->N);
1863 while ((l>0) && (p_GetExp( hh->m[k],l,tmpR)*pGetExp(delVar,l)==0)) l--;
1864 if (l==0)
1865 {
1866 j++;
1867 if (j >= IDELEMS(h3))
1868 {
1869 pEnlargeSet(&(h3->m),IDELEMS(h3),16);
1870 IDELEMS(h3) += 16;
1871 }
1872 h3->m[j] = prMoveR( hh->m[k], tmpR,origR);
1873 hh->m[k] = NULL;
1874 }
1875 }
1876 id_Delete(&hh, tmpR);
1877 idSkipZeroes(h3);
1878 rDelete(tmpR);
1879 if (w!=NULL)
1880 delete w;
1881 return h3;
1882}
1883
1884ideal idElimination(ideal h1,poly delVar,intvec *hilb, GbVariant alg)
1885{
1886 bigintmat *hh=iv2biv(hilb,coeffs_BIGINT);
1887 ideal res=idElimination2(h1,delVar,hh,alg);
1888 if (hh!=NULL) delete hh;
1889 return res;
1890}
1891
1892#ifdef WITH_OLD_MINOR
1893/*2
1894* compute the which-th ar-minor of the matrix a
1895*/
1896poly idMinor(matrix a, int ar, unsigned long which, ideal R)
1897{
1898 int i,j/*,k,size*/;
1899 unsigned long curr;
1900 int *rowchoise,*colchoise;
1901 BOOLEAN rowch,colch;
1902 // ideal result;
1903 matrix tmp;
1904 poly p,q;
1905
1906 rowchoise=(int *)omAlloc(ar*sizeof(int));
1907 colchoise=(int *)omAlloc(ar*sizeof(int));
1908 tmp=mpNew(ar,ar);
1909 curr = 0; /* index of current minor */
1910 idInitChoise(ar,1,a->rows(),&rowch,rowchoise);
1911 while (!rowch)
1912 {
1913 idInitChoise(ar,1,a->cols(),&colch,colchoise);
1914 while (!colch)
1915 {
1916 if (curr == which)
1917 {
1918 for (i=1; i<=ar; i++)
1919 {
1920 for (j=1; j<=ar; j++)
1921 {
1922 MATELEM(tmp,i,j) = MATELEM(a,rowchoise[i-1],colchoise[j-1]);
1923 }
1924 }
1925 p = mp_DetBareiss(tmp,currRing);
1926 if (p!=NULL)
1927 {
1928 if (R!=NULL)
1929 {
1930 q = p;
1931 p = kNF(R,currRing->qideal,q);
1932 p_Delete(&q,currRing);
1933 }
1934 }
1935 /*delete the matrix tmp*/
1936 for (i=1; i<=ar; i++)
1937 {
1938 for (j=1; j<=ar; j++) MATELEM(tmp,i,j) = NULL;
1939 }
1940 idDelete((ideal*)&tmp);
1941 omFreeSize((ADDRESS)rowchoise,ar*sizeof(int));
1942 omFreeSize((ADDRESS)colchoise,ar*sizeof(int));
1943 return (p);
1944 }
1945 curr++;
1946 idGetNextChoise(ar,a->cols(),&colch,colchoise);
1947 }
1948 idGetNextChoise(ar,a->rows(),&rowch,rowchoise);
1949 }
1950 return (poly) 1;
1951}
1952
1953/*2
1954* compute all ar-minors of the matrix a
1955*/
1956ideal idMinors(matrix a, int ar, ideal R)
1957{
1958 int i,j,/*k,*/size;
1959 int *rowchoise,*colchoise;
1960 BOOLEAN rowch,colch;
1961 ideal result;
1962 matrix tmp;
1963 poly p,q;
1964
1965 i = binom(a->rows(),ar);
1966 j = binom(a->cols(),ar);
1967 size=i*j;
1968
1969 rowchoise=(int *)omAlloc(ar*sizeof(int));
1970 colchoise=(int *)omAlloc(ar*sizeof(int));
1971 result=idInit(size,1);
1972 tmp=mpNew(ar,ar);
1973 // k = 0; /* the index in result*/
1974 idInitChoise(ar,1,a->rows(),&rowch,rowchoise);
1975 while (!rowch)
1976 {
1977 idInitChoise(ar,1,a->cols(),&colch,colchoise);
1978 while (!colch)
1979 {
1980 for (i=1; i<=ar; i++)
1981 {
1982 for (j=1; j<=ar; j++)
1983 {
1984 MATELEM(tmp,i,j) = MATELEM(a,rowchoise[i-1],colchoise[j-1]);
1985 }
1986 }
1987 p = mp_DetBareiss(tmp,currRing);
1988 if (p!=NULL)
1989 {
1990 if (R!=NULL)
1991 {
1992 q = p;
1993 p = kNF(R,currRing->qideal,q);
1994 p_Delete(&q,currRing);
1995 }
1996 }
1997 if (k>=size)
1998 {
1999 pEnlargeSet(&result->m,size,32);
2000 size += 32;
2001 }
2002 result->m[k] = p;
2003 k++;
2004 idGetNextChoise(ar,a->cols(),&colch,colchoise);
2005 }
2006 idGetNextChoise(ar,a->rows(),&rowch,rowchoise);
2007 }
2008 /*delete the matrix tmp*/
2009 for (i=1; i<=ar; i++)
2010 {
2011 for (j=1; j<=ar; j++) MATELEM(tmp,i,j) = NULL;
2012 }
2013 idDelete((ideal*)&tmp);
2014 if (k==0)
2015 {
2016 k=1;
2017 result->m[0]=NULL;
2018 }
2019 omFreeSize((ADDRESS)rowchoise,ar*sizeof(int));
2020 omFreeSize((ADDRESS)colchoise,ar*sizeof(int));
2022 IDELEMS(result) = k;
2023 return (result);
2024}
2025#else
2026
2027
2028/// compute all ar-minors of the matrix a
2029/// the caller of mpRecMin
2030/// the elements of the result are not in R (if R!=NULL)
2031ideal idMinors(matrix a, int ar, ideal R)
2032{
2033
2034 const ring origR=currRing;
2035 id_Test((ideal)a, origR);
2036
2037 const int r = a->nrows;
2038 const int c = a->ncols;
2039
2040 if((ar<=0) || (ar>r) || (ar>c))
2041 {
2042 Werror("%d-th minor, matrix is %dx%d",ar,r,c);
2043 return NULL;
2044 }
2045
2046 ideal h = id_Matrix2Module(mp_Copy(a,origR),origR);
2047 long bound = sm_ExpBound(h,c,r,ar,origR);
2048 id_Delete(&h, origR);
2049
2050 ring tmpR = sm_RingChange(origR,bound);
2051
2052 matrix b = mpNew(r,c);
2053
2054 for (int i=r*c-1;i>=0;i--)
2055 if (a->m[i] != NULL)
2056 b->m[i] = prCopyR(a->m[i],origR,tmpR);
2057
2058 id_Test( (ideal)b, tmpR);
2059
2060 if (R!=NULL)
2061 {
2062 R = idrCopyR(R,origR,tmpR); // TODO: overwrites R? memory leak?
2063 //if (ar>1) // otherwise done in mpMinorToResult
2064 //{
2065 // matrix bb=(matrix)kNF(R,currRing->qideal,(ideal)b);
2066 // bb->rank=b->rank; bb->nrows=b->nrows; bb->ncols=b->ncols;
2067 // idDelete((ideal*)&b); b=bb;
2068 //}
2069 id_Test( R, tmpR);
2070 }
2071
2072 int size=binom(r,ar)*binom(c,ar);
2073 ideal result = idInit(size,1);
2074
2075 int elems = 0;
2076
2077 if(ar>1)
2078 mp_RecMin(ar-1,result,elems,b,r,c,NULL,R,tmpR);
2079 else
2080 mp_MinorToResult(result,elems,b,r,c,R,tmpR);
2081
2082 id_Test( (ideal)b, tmpR);
2083
2084 id_Delete((ideal *)&b, tmpR);
2085
2086 if (R!=NULL) id_Delete(&R,tmpR);
2087
2088 rChangeCurrRing(origR);
2089 result = idrMoveR(result,tmpR,origR);
2090 sm_KillModifiedRing(tmpR);
2091 idTest(result);
2092 return result;
2093}
2094#endif
2095
2096/*2
2097*returns TRUE if id1 is a submodule of id2
2098*/
2099BOOLEAN idIsSubModule(ideal id1,ideal id2)
2100{
2101 int i;
2102 poly p;
2103
2104 if (idIs0(id1)) return TRUE;
2105 for (i=0;i<IDELEMS(id1);i++)
2106 {
2107 if (id1->m[i] != NULL)
2108 {
2109 p = kNF(id2,currRing->qideal,id1->m[i]);
2110 if (p != NULL)
2111 {
2113 return FALSE;
2114 }
2115 }
2116 }
2117 return TRUE;
2118}
2119
2121{
2122 if ((Q!=NULL) && (!idHomIdeal(Q,NULL))) { PrintS(" Q not hom\n"); return FALSE;}
2123 if (idIs0(m)) return TRUE;
2124
2125 int cmax=-1;
2126 int i;
2127 poly p=NULL;
2128 int length=IDELEMS(m);
2129 polyset P=m->m;
2130 for (i=length-1;i>=0;i--)
2131 {
2132 p=P[i];
2133 if (p!=NULL) cmax=si_max(cmax,(int)pMaxComp(p)+1);
2134 }
2135 if (w != NULL)
2136 if (w->length()+1 < cmax)
2137 {
2138 // Print("length: %d - %d \n", w->length(),cmax);
2139 return FALSE;
2140 }
2141
2142 if(w!=NULL)
2144
2145 for (i=length-1;i>=0;i--)
2146 {
2147 p=P[i];
2148 if (p!=NULL)
2149 {
2150 int d=currRing->pFDeg(p,currRing);
2151 loop
2152 {
2153 pIter(p);
2154 if (p==NULL) break;
2155 if (d!=currRing->pFDeg(p,currRing))
2156 {
2157 //pWrite(q); wrp(p); Print(" -> %d - %d\n",d,pFDeg(p,currRing));
2158 if(w!=NULL)
2160 return FALSE;
2161 }
2162 }
2163 }
2164 }
2165
2166 if(w!=NULL)
2168
2169 return TRUE;
2170}
2171
2172ideal idSeries(int n,ideal M,matrix U,intvec *w)
2173{
2174 for(int i=IDELEMS(M)-1;i>=0;i--)
2175 {
2176 if(U==NULL)
2177 M->m[i]=pSeries(n,M->m[i],NULL,w);
2178 else
2179 {
2180 M->m[i]=pSeries(n,M->m[i],MATELEM(U,i+1,i+1),w);
2181 MATELEM(U,i+1,i+1)=NULL;
2182 }
2183 }
2184 if(U!=NULL)
2185 idDelete((ideal*)&U);
2186 return M;
2187}
2188
2190{
2191 int e=MATCOLS(i)*MATROWS(i);
2193 r->rank=i->rank;
2194 int j;
2195 for(j=0; j<e; j++)
2196 {
2197 r->m[j]=pDiff(i->m[j],k);
2198 }
2199 return r;
2200}
2201
2202matrix idDiffOp(ideal I, ideal J,BOOLEAN multiply)
2203{
2204 matrix r=mpNew(IDELEMS(I),IDELEMS(J));
2205 int i,j;
2206 for(i=0; i<IDELEMS(I); i++)
2207 {
2208 for(j=0; j<IDELEMS(J); j++)
2209 {
2210 MATELEM(r,i+1,j+1)=pDiffOp(I->m[i],J->m[j],multiply);
2211 }
2212 }
2213 return r;
2214}
2215
2216/*3
2217*handles for some ideal operations the ring/syzcomp management
2218*returns all syzygies (componentwise-)shifted by -syzcomp
2219*or -syzcomp-1 (in case of ideals as input)
2220static ideal idHandleIdealOp(ideal arg,int syzcomp,int isIdeal=FALSE)
2221{
2222 ring orig_ring=currRing;
2223 ring syz_ring=rAssure_SyzOrder(orig_ring, TRUE); rChangeCurrRing(syz_ring);
2224 rSetSyzComp(length, syz_ring);
2225
2226 ideal s_temp;
2227 if (orig_ring!=syz_ring)
2228 s_temp=idrMoveR_NoSort(arg,orig_ring, syz_ring);
2229 else
2230 s_temp=arg;
2231
2232 ideal s_temp1 = kStd2(s_temp,currRing->qideal,testHomog,&w,NULL,length);
2233 if (w!=NULL) delete w;
2234
2235 if (syz_ring!=orig_ring)
2236 {
2237 idDelete(&s_temp);
2238 rChangeCurrRing(orig_ring);
2239 }
2240
2241 idDelete(&temp);
2242 ideal temp1=idRingCopy(s_temp1,syz_ring);
2243
2244 if (syz_ring!=orig_ring)
2245 {
2246 rChangeCurrRing(syz_ring);
2247 idDelete(&s_temp1);
2248 rChangeCurrRing(orig_ring);
2249 rDelete(syz_ring);
2250 }
2251
2252 for (i=0;i<IDELEMS(temp1);i++)
2253 {
2254 if ((temp1->m[i]!=NULL)
2255 && (pGetComp(temp1->m[i])<=length))
2256 {
2257 pDelete(&(temp1->m[i]));
2258 }
2259 else
2260 {
2261 p_Shift(&(temp1->m[i]),-length,currRing);
2262 }
2263 }
2264 temp1->rank = rk;
2265 idSkipZeroes(temp1);
2266
2267 return temp1;
2268}
2269*/
2270
2271#ifdef HAVE_SHIFTBBA
2272ideal idModuloLP (ideal h2,ideal h1, tHomog, intvec ** w, matrix *T, GbVariant alg)
2273{
2274 intvec *wtmp=NULL;
2275 if (T!=NULL) idDelete((ideal*)T);
2276
2277 int i,k,rk,flength=0,slength,length;
2278 poly p,q;
2279
2280 if (idIs0(h2))
2281 return idFreeModule(si_max(1,h2->ncols));
2282 if (!idIs0(h1))
2283 flength = id_RankFreeModule(h1,currRing);
2284 slength = id_RankFreeModule(h2,currRing);
2285 length = si_max(flength,slength);
2286 if (length==0)
2287 {
2288 length = 1;
2289 }
2290 ideal temp = idInit(IDELEMS(h2),length+IDELEMS(h2));
2291 if ((w!=NULL)&&((*w)!=NULL))
2292 {
2293 //Print("input weights:");(*w)->show(1);PrintLn();
2294 int d;
2295 int k;
2296 wtmp=new intvec(length+IDELEMS(h2));
2297 for (i=0;i<length;i++)
2298 ((*wtmp)[i])=(**w)[i];
2299 for (i=0;i<IDELEMS(h2);i++)
2300 {
2301 poly p=h2->m[i];
2302 if (p!=NULL)
2303 {
2304 d = p_Deg(p,currRing);
2305 k= pGetComp(p);
2306 if (slength>0) k--;
2307 d +=((**w)[k]);
2308 ((*wtmp)[i+length]) = d;
2309 }
2310 }
2311 //Print("weights:");wtmp->show(1);PrintLn();
2312 }
2313 for (i=0;i<IDELEMS(h2);i++)
2314 {
2315 temp->m[i] = pCopy(h2->m[i]);
2316 q = pOne();
2317 // non multiplicative variable
2318 pSetExp(q, currRing->isLPring - currRing->LPncGenCount + i + 1, 1);
2319 p_Setm(q, currRing);
2320 pSetComp(q,i+1+length);
2321 pSetmComp(q);
2322 if(temp->m[i]!=NULL)
2323 {
2324 if (slength==0) p_Shift(&(temp->m[i]),1,currRing);
2325 p = temp->m[i];
2326 temp->m[i] = pAdd(p, q);
2327 }
2328 else
2329 temp->m[i]=q;
2330 }
2331 rk = k = IDELEMS(h2);
2332 if (!idIs0(h1))
2333 {
2334 pEnlargeSet(&(temp->m),IDELEMS(temp),IDELEMS(h1));
2335 IDELEMS(temp) += IDELEMS(h1);
2336 for (i=0;i<IDELEMS(h1);i++)
2337 {
2338 if (h1->m[i]!=NULL)
2339 {
2340 temp->m[k] = pCopy(h1->m[i]);
2341 if (flength==0) p_Shift(&(temp->m[k]),1,currRing);
2342 k++;
2343 }
2344 }
2345 }
2346
2347 ring orig_ring=currRing;
2348 ring syz_ring=rAssure_SyzOrder(orig_ring, TRUE);
2349 rSetSyzComp(length,syz_ring);
2350 rChangeCurrRing(syz_ring);
2351 // we can use OPT_RETURN_SB only, if syz_ring==orig_ring,
2352 // therefore we disable OPT_RETURN_SB for modulo:
2353 // (see tr. #701)
2354 //if (TEST_OPT_RETURN_SB)
2355 // rSetSyzComp(IDELEMS(h2)+length, syz_ring);
2356 //else
2357 // rSetSyzComp(length, syz_ring);
2358 ideal s_temp;
2359
2360 if (syz_ring != orig_ring)
2361 {
2362 s_temp = idrMoveR_NoSort(temp, orig_ring, syz_ring);
2363 }
2364 else
2365 {
2366 s_temp = temp;
2367 }
2368
2369 idTest(s_temp);
2370 BITSET save_opt,save_opt2;
2371 SI_SAVE_OPT(save_opt,save_opt2);
2374 ideal s_temp1 = idGroebner(s_temp,length,alg);
2375 SI_RESTORE_OPT(save_opt,save_opt2);
2376
2377 //if (wtmp!=NULL) Print("output weights:");wtmp->show(1);PrintLn();
2378 if ((w!=NULL) && (*w !=NULL) && (wtmp!=NULL))
2379 {
2380 delete *w;
2381 *w=new intvec(IDELEMS(h2));
2382 for (i=0;i<IDELEMS(h2);i++)
2383 ((**w)[i])=(*wtmp)[i+length];
2384 }
2385 if (wtmp!=NULL) delete wtmp;
2386
2387 if (T==NULL)
2388 {
2389 for (i=0;i<IDELEMS(s_temp1);i++)
2390 {
2391 if (s_temp1->m[i]!=NULL)
2392 {
2393 if (((int)pGetComp(s_temp1->m[i]))<=length)
2394 {
2395 p_Delete(&(s_temp1->m[i]),currRing);
2396 }
2397 else
2398 {
2399 p_Shift(&(s_temp1->m[i]),-length,currRing);
2400 }
2401 }
2402 }
2403 }
2404 else
2405 {
2406 *T=mpNew(IDELEMS(s_temp1),IDELEMS(h2));
2407 for (i=0;i<IDELEMS(s_temp1);i++)
2408 {
2409 if (s_temp1->m[i]!=NULL)
2410 {
2411 if (((int)pGetComp(s_temp1->m[i]))<=length)
2412 {
2413 do
2414 {
2415 p_LmDelete(&(s_temp1->m[i]),currRing);
2416 } while((int)pGetComp(s_temp1->m[i])<=length);
2417 poly q = prMoveR( s_temp1->m[i], syz_ring,orig_ring);
2418 s_temp1->m[i] = NULL;
2419 if (q!=NULL)
2420 {
2421 q=pReverse(q);
2422 do
2423 {
2424 poly p = q;
2425 long t=pGetComp(p);
2426 pIter(q);
2427 pNext(p) = NULL;
2428 pSetComp(p,0);
2429 pSetmComp(p);
2430 pTest(p);
2431 MATELEM(*T,(int)t-length,i) = pAdd(MATELEM(*T,(int)t-length,i),p);
2432 } while (q != NULL);
2433 }
2434 }
2435 else
2436 {
2437 p_Shift(&(s_temp1->m[i]),-length,currRing);
2438 }
2439 }
2440 }
2441 }
2442 s_temp1->rank = rk;
2443 idSkipZeroes(s_temp1);
2444
2445 if (syz_ring!=orig_ring)
2446 {
2447 rChangeCurrRing(orig_ring);
2448 s_temp1 = idrMoveR_NoSort(s_temp1, syz_ring, orig_ring);
2449 rDelete(syz_ring);
2450 // Hmm ... here seems to be a memory leak
2451 // However, simply deleting it causes memory trouble
2452 // idDelete(&s_temp);
2453 }
2454 idTest(s_temp1);
2455 return s_temp1;
2456}
2457#endif
2458
2459/*2
2460* represents (h1+h2)/h2=h1/(h1 intersect h2)
2461*/
2462//ideal idModulo (ideal h2,ideal h1)
2463ideal idModulo (ideal h2,ideal h1, tHomog hom, intvec ** w, matrix *T, GbVariant alg)
2464{
2465#ifdef HAVE_SHIFTBBA
2466 if (rIsLPRing(currRing))
2467 return idModuloLP(h2,h1,hom,w,T,alg);
2468#endif
2469 intvec *wtmp=NULL;
2470 if (T!=NULL) idDelete((ideal*)T);
2471
2472 int i,flength=0,slength,length;
2473
2474 if (idIs0(h2))
2475 return idFreeModule(si_max(1,h2->ncols));
2476 if (!idIs0(h1))
2477 flength = id_RankFreeModule(h1,currRing);
2478 slength = id_RankFreeModule(h2,currRing);
2479 length = si_max(flength,slength);
2480 BOOLEAN inputIsIdeal=FALSE;
2481 if (length==0)
2482 {
2483 length = 1;
2484 inputIsIdeal=TRUE;
2485 }
2486 if ((w!=NULL)&&((*w)!=NULL))
2487 {
2488 //Print("input weights:");(*w)->show(1);PrintLn();
2489 int d;
2490 int k;
2491 wtmp=new intvec(length+IDELEMS(h2));
2492 for (i=0;i<length;i++)
2493 ((*wtmp)[i])=(**w)[i];
2494 for (i=0;i<IDELEMS(h2);i++)
2495 {
2496 poly p=h2->m[i];
2497 if (p!=NULL)
2498 {
2499 d = p_Deg(p,currRing);
2500 k= pGetComp(p);
2501 if (slength>0) k--;
2502 d +=((**w)[k]);
2503 ((*wtmp)[i+length]) = d;
2504 }
2505 }
2506 //Print("weights:");wtmp->show(1);PrintLn();
2507 }
2508 ideal s_temp1;
2509 ring orig_ring=currRing;
2510 ring syz_ring=rAssure_SyzOrder(orig_ring, TRUE);
2511 rSetSyzComp(length,syz_ring);
2512 {
2513 rChangeCurrRing(syz_ring);
2514 ideal s1,s2;
2515
2516 if (syz_ring != orig_ring)
2517 {
2518 s1 = idrCopyR_NoSort(h1, orig_ring, syz_ring);
2519 s2 = idrCopyR_NoSort(h2, orig_ring, syz_ring);
2520 }
2521 else
2522 {
2523 s1=idCopy(h1);
2524 s2=idCopy(h2);
2525 }
2526
2527 BITSET save_opt,save_opt2;
2528 SI_SAVE_OPT(save_opt,save_opt2);
2529 if (T==NULL) si_opt_1 |= Sy_bit(OPT_REDTAIL);
2531 s_temp1 = idPrepare(s2,s1,testHomog,length,w,alg);
2532 SI_RESTORE_OPT(save_opt,save_opt2);
2533 }
2534
2535 //if (wtmp!=NULL) Print("output weights:");wtmp->show(1);PrintLn();
2536 if ((w!=NULL) && (*w !=NULL) && (wtmp!=NULL))
2537 {
2538 delete *w;
2539 *w=new intvec(IDELEMS(h2));
2540 for (i=0;i<IDELEMS(h2);i++)
2541 ((**w)[i])=(*wtmp)[i+length];
2542 }
2543 if (wtmp!=NULL) delete wtmp;
2544
2545 ideal result=idInit(IDELEMS(s_temp1),IDELEMS(h2));
2546 s_temp1=idExtractG_T_S(s_temp1,T,&result,length,IDELEMS(h2),inputIsIdeal,orig_ring,syz_ring);
2547
2548 idDelete(&s_temp1);
2549 if (syz_ring!=orig_ring)
2550 {
2551 rDelete(syz_ring);
2552 }
2553 idTest(h2);
2554 idTest(h1);
2555 idTest(result);
2556 if (T!=NULL) idTest((ideal)*T);
2557 return result;
2558}
2559
2560/*
2561*computes module-weights for liftings of homogeneous modules
2562*/
2563#if 0
2564static intvec * idMWLift(ideal mod,intvec * weights)
2565{
2566 if (idIs0(mod)) return new intvec(2);
2567 int i=IDELEMS(mod);
2568 while ((i>0) && (mod->m[i-1]==NULL)) i--;
2569 intvec *result = new intvec(i+1);
2570 while (i>0)
2571 {
2572 (*result)[i]=currRing->pFDeg(mod->m[i],currRing)+(*weights)[pGetComp(mod->m[i])];
2573 }
2574 return result;
2575}
2576#endif
2577
2578/*2
2579*sorts the kbase for idCoef* in a special way (lexicographically
2580*with x_max,...,x_1)
2581*/
2582ideal idCreateSpecialKbase(ideal kBase,intvec ** convert)
2583{
2584 int i;
2585 ideal result;
2586
2587 if (idIs0(kBase)) return NULL;
2588 result = idInit(IDELEMS(kBase),kBase->rank);
2589 *convert = idSort(kBase,FALSE);
2590 for (i=0;i<(*convert)->length();i++)
2591 {
2592 result->m[i] = pCopy(kBase->m[(**convert)[i]-1]);
2593 }
2594 return result;
2595}
2596
2597/*2
2598*returns the index of a given monom in the list of the special kbase
2599*/
2600int idIndexOfKBase(poly monom, ideal kbase)
2601{
2602 int j=IDELEMS(kbase);
2603
2604 while ((j>0) && (kbase->m[j-1]==NULL)) j--;
2605 if (j==0) return -1;
2606 int i=(currRing->N);
2607 while (i>0)
2608 {
2609 loop
2610 {
2611 if (pGetExp(monom,i)>pGetExp(kbase->m[j-1],i)) return -1;
2612 if (pGetExp(monom,i)==pGetExp(kbase->m[j-1],i)) break;
2613 j--;
2614 if (j==0) return -1;
2615 }
2616 if (i==1)
2617 {
2618 while(j>0)
2619 {
2620 if (pGetComp(monom)==pGetComp(kbase->m[j-1])) return j-1;
2621 if (pGetComp(monom)>pGetComp(kbase->m[j-1])) return -1;
2622 j--;
2623 }
2624 }
2625 i--;
2626 }
2627 return -1;
2628}
2629
2630/*2
2631*decomposes the monom in a part of coefficients described by the
2632*complement of how and a monom in variables occurring in how, the
2633*index of which in kbase is returned as integer pos (-1 if it don't
2634*exists)
2635*/
2636poly idDecompose(poly monom, poly how, ideal kbase, int * pos)
2637{
2638 int i;
2639 poly coeff=pOne(), base=pOne();
2640
2641 for (i=1;i<=(currRing->N);i++)
2642 {
2643 if (pGetExp(how,i)>0)
2644 {
2645 pSetExp(base,i,pGetExp(monom,i));
2646 }
2647 else
2648 {
2649 pSetExp(coeff,i,pGetExp(monom,i));
2650 }
2651 }
2652 pSetComp(base,pGetComp(monom));
2653 pSetm(base);
2654 pSetCoeff(coeff,nCopy(pGetCoeff(monom)));
2655 pSetm(coeff);
2656 *pos = idIndexOfKBase(base,kbase);
2657 if (*pos<0)
2658 p_Delete(&coeff,currRing);
2659 p_Delete(&base,currRing);
2660 return coeff;
2661}
2662
2663/*2
2664*returns a matrix A of coefficients with kbase*A=arg
2665*if all monomials in variables of how occur in kbase
2666*the other are deleted
2667*/
2668matrix idCoeffOfKBase(ideal arg, ideal kbase, poly how)
2669{
2670 matrix result;
2671 ideal tempKbase;
2672 poly p,q;
2673 intvec * convert;
2674 int i=IDELEMS(kbase),j=IDELEMS(arg),k,pos;
2675#if 0
2676 while ((i>0) && (kbase->m[i-1]==NULL)) i--;
2677 if (idIs0(arg))
2678 return mpNew(i,1);
2679 while ((j>0) && (arg->m[j-1]==NULL)) j--;
2680 result = mpNew(i,j);
2681#else
2682 result = mpNew(i, j);
2683 while ((j>0) && (arg->m[j-1]==NULL)) j--;
2684#endif
2685
2686 tempKbase = idCreateSpecialKbase(kbase,&convert);
2687 for (k=0;k<j;k++)
2688 {
2689 p = arg->m[k];
2690 while (p!=NULL)
2691 {
2692 q = idDecompose(p,how,tempKbase,&pos);
2693 if (pos>=0)
2694 {
2695 MATELEM(result,(*convert)[pos],k+1) =
2696 pAdd(MATELEM(result,(*convert)[pos],k+1),q);
2697 }
2698 else
2699 p_Delete(&q,currRing);
2700 pIter(p);
2701 }
2702 }
2703 idDelete(&tempKbase);
2704 return result;
2705}
2706
2707static void idDeleteComps(ideal arg,int* red_comp,int del)
2708// red_comp is an array [0..args->rank]
2709{
2710 int i,j;
2711 poly p;
2712
2713 for (i=IDELEMS(arg)-1;i>=0;i--)
2714 {
2715 p = arg->m[i];
2716 while (p!=NULL)
2717 {
2718 j = pGetComp(p);
2719 if (red_comp[j]!=j)
2720 {
2721 pSetComp(p,red_comp[j]);
2722 pSetmComp(p);
2723 }
2724 pIter(p);
2725 }
2726 }
2727 (arg->rank) -= del;
2728}
2729
2730/*3
2731* searches for the next unit in the components of the module arg and
2732* returns the first one;
2733*/
2734static int id_ReadOutPivot(ideal arg,int* comp, const ring r)
2735{
2736 int i=0,j, generator=-1;
2737 int rk_arg=arg->rank; //idRankFreeModule(arg);
2738 int * componentIsUsed =(int *)omAlloc((rk_arg+1)*sizeof(int));
2739 poly p;
2740
2741 while ((generator<0) && (i<IDELEMS(arg)))
2742 {
2743 memset(componentIsUsed,0,(rk_arg+1)*sizeof(int));
2744 p = arg->m[i];
2745 if (rField_is_Ring(r))
2746 {
2747 while (p!=NULL)
2748 {
2749 j = __p_GetComp(p,r);
2750 if (componentIsUsed[j]==0)
2751 {
2752 if (p_LmIsConstantComp(p,r) &&
2753 n_IsUnit(pGetCoeff(p),r->cf))
2754 {
2755 generator = i;
2756 componentIsUsed[j] = 1;
2757 }
2758 else
2759 {
2760 componentIsUsed[j] = -1;
2761 }
2762 }
2763 else if (componentIsUsed[j]>0)
2764 {
2765 (componentIsUsed[j])++;
2766 }
2767 pIter(p);
2768 }
2769 }
2770 else
2771 {
2772 while (p!=NULL)
2773 {
2774 j = __p_GetComp(p,r);
2775 if (componentIsUsed[j]==0)
2776 {
2777 if (p_LmIsConstantComp(p,r))
2778 {
2779 generator = i;
2780 componentIsUsed[j] = 1;
2781 }
2782 else
2783 {
2784 componentIsUsed[j] = -1;
2785 }
2786 }
2787 else if (componentIsUsed[j]>0)
2788 {
2789 (componentIsUsed[j])++;
2790 }
2791 pIter(p);
2792 }
2793 }
2794 i++;
2795 }
2796 i = 0;
2797 *comp = -1;
2798 for (j=0;j<=rk_arg;j++)
2799 {
2800 if (componentIsUsed[j]>0)
2801 {
2802 if ((*comp==-1) || (componentIsUsed[j]<i))
2803 {
2804 *comp = j;
2805 i= componentIsUsed[j];
2806 }
2807 }
2808 }
2809 omFree(componentIsUsed);
2810 return generator;
2811}
2812
2813/*2
2814* returns the presentation of an isomorphic, minimally
2815* embedded module (arg represents the quotient!)
2816*/
2817static ideal idMinEmbedding1(ideal arg,BOOLEAN inPlace, intvec **w,
2818 int* red_comp, int &del)
2819{
2820 if (idIs0(arg)) return idInit(1,arg->rank);
2821 int i,next_gen,next_comp;
2822 ideal res=arg;
2823 if (!inPlace) res = idCopy(arg);
2825 for (i=res->rank;i>=0;i--) red_comp[i]=i;
2826
2827 loop
2828 {
2829 next_gen = id_ReadOutPivot(res, &next_comp, currRing);
2830 if (next_gen<0) break;
2831 del++;
2832 syGaussForOne(res,next_gen,next_comp,0,IDELEMS(res));
2833 for(i=next_comp+1;i<=arg->rank;i++) red_comp[i]--;
2834 if ((w !=NULL)&&(*w!=NULL))
2835 {
2836 for(i=next_comp;i<(*w)->length();i++) (**w)[i-1]=(**w)[i];
2837 }
2838 }
2839
2841
2842 if ((w !=NULL)&&(*w!=NULL) &&(del>0))
2843 {
2844 int nl=si_max((*w)->length()-del,1);
2845 intvec *wtmp=new intvec(nl);
2846 for(i=0;i<nl;i++) (*wtmp)[i]=(**w)[i];
2847 delete *w;
2848 *w=wtmp;
2849 }
2850 return res;
2851}
2852
2853ideal idMinEmbedding(ideal arg,BOOLEAN inPlace, intvec **w)
2854{
2855 int *red_comp=(int*)omAlloc((arg->rank+1)*sizeof(int));
2856 int del=0;
2857 ideal res=idMinEmbedding1(arg,inPlace,w,red_comp,del);
2858 idDeleteComps(res,red_comp,del);
2859 omFree(red_comp);
2860 return res;
2861}
2862
2863ideal idMinEmbedding_with_map(ideal arg,intvec **w, ideal &trans)
2864{
2865 int *red_comp=(int*)omAlloc((arg->rank+1)*sizeof(int));
2866 int del=0;
2867 ideal res=idMinEmbedding1(arg,FALSE,w,red_comp,del);
2868 trans=idLift(arg,res,NULL,TRUE,FALSE,FALSE,NULL);
2869 //idDeleteComps(res,red_comp,del);
2870 omFree(red_comp);
2871 return res;
2872}
2873
2874ideal idMinEmbedding_with_map_v(ideal arg,intvec **w, ideal &trans, int* g)
2875{
2876 if (idIs0(arg))
2877 {
2878 trans=idFreeModule(arg->rank);
2879 if (g!=NULL)
2880 {
2881 for(int i=0;i<arg->rank;i++) g[i]=i+1;
2882 }
2883 return arg;
2884 }
2885 int *red_comp=(int*)omAlloc((arg->rank+1)*sizeof(int));
2886 int del=0;
2887 ideal res=idMinEmbedding1(arg,FALSE,w,red_comp,del);
2888 trans=idLift(arg,res,NULL,TRUE,FALSE,FALSE,NULL);
2889 for(int i=1;i<=arg->rank;i++)
2890 {
2891 g[i-1]=red_comp[i];
2892 }
2893 idDeleteComps(res,red_comp,del);
2894 return res;
2895}
2896
2897extern void ipPrint_MA0(matrix m, const char *name);
2898#if 0 // unused
2899ideal idMinEmbedding_with_map0(ideal arg,intvec **w, ideal &trans)
2900{
2901 ideal a=idCopy(arg);
2902 // add unit matrix to a
2903 int k=a->rank+1;
2904 const int rk=a->rank;
2905 poly p;
2906 int i;
2907 for(i=0;i<IDELEMS(a);i++,k++)
2908 {
2909 p=pOne();
2911 a->m[i]=p_Add_q(a->m[i],p,currRing);
2912 }
2913 // search a unit in orig part of a
2914 // and subtract, start at start
2915 int start=0;
2916 loop
2917 {
2918 PrintS("matrix:\n");
2919 ipPrint_MA0((matrix)a,"a");
2920 i=start;
2921 if (i>=IDELEMS(a)) break;
2922 p=a->m[i];
2923 start=IDELEMS(a);
2924 while((p!=NULL)&&(pGetComp(p)<=rk)&&(p_Totaldegree(p,currRing)>0)) pIter(p);
2925 if ((p!=NULL)&&(pGetComp(p)<=rk)&&(p_Totaldegree(p,currRing)==0))
2926 { // found const in vector i, comp k
2927 k=pGetComp(p);
2928 // normalize:
2929 number n=nCopy(pGetCoeff(p));
2930 n=nInpNeg(n);
2931 a->m[i]=p_Div_nn(p,n,currRing);
2932 // subtract
2933 BOOLEAN changed=FALSE;
2934 for(int j=IDELEMS(a)-1;j>=0;j--)
2935 {
2936 if (j!=i)
2937 {
2938 poly q=p_Vec2Poly(a->m[j],k,currRing);
2939 if (q!=NULL)
2940 {
2941 start=j; // changed entries start at j
2942 changed=TRUE;
2943 poly s=p_Mult_q(a->m[i],q,currRing);
2944 a->m[j]=p_Add_q(a->m[j],s,currRing);
2945 }
2946 }
2947 }
2948 if(changed) continue;
2949 }
2950 else i++;
2951 }
2952 // a -> result,trans
2953 trans=idInit(IDELEMS(a),IDELEMS(a));
2954 ideal result=idInit(IDELEMS(a),rk);
2955 for(i=0;i<IDELEMS(a);i++)
2956 {
2957 while(a->m[i]!=NULL)
2958 {
2959 poly p=a->m[i];
2960 a->m[i]=p->next;
2961 p->next=NULL;
2962 if(pGetComp(p)<=rk)
2963 {
2964 result->m[i]=p_Add_q(result->m[i],p,currRing);
2965 }
2966 else
2967 {
2968 p_Shift(&p,-rk,currRing);
2969 trans->m[i]=p_Add_q(trans->m[i],p,currRing);
2970 }
2971 }
2972 }
2973 PrintS("prune:\n");
2975 PrintS("trans:\n");
2976 ipPrint_MA0((matrix)trans,"T");
2977 idDelete(&a);
2978 return result;
2979}
2980#endif
2981#include "polys/clapsing.h"
2982
2983#if 0
2984poly id_GCD(poly f, poly g, const ring r)
2985{
2986 ring save_r=currRing;
2987 rChangeCurrRing(r);
2988 ideal I=idInit(2,1); I->m[0]=f; I->m[1]=g;
2989 intvec *w = NULL;
2990 ideal S=idSyzygies(I,testHomog,&w);
2991 if (w!=NULL) delete w;
2992 poly gg=pTakeOutComp(&(S->m[0]),2);
2993 idDelete(&S);
2994 poly gcd_p=singclap_pdivide(f,gg,r);
2995 p_Delete(&gg,r);
2996 rChangeCurrRing(save_r);
2997 return gcd_p;
2998}
2999#else
3000poly id_GCD(poly f, poly g, const ring r)
3001{
3002 ideal I=idInit(2,1); I->m[0]=f; I->m[1]=g;
3003 intvec *w = NULL;
3004
3005 ring save_r = currRing;
3006 rChangeCurrRing(r);
3007 ideal S=idSyzygies(I,testHomog,&w);
3008 rChangeCurrRing(save_r);
3009
3010 if (w!=NULL) delete w;
3011 poly gg=p_TakeOutComp(&(S->m[0]), 2, r);
3012 id_Delete(&S, r);
3013 poly gcd_p=singclap_pdivide(f,gg, r);
3014 p_Delete(&gg, r);
3015
3016 return gcd_p;
3017}
3018#endif
3019
3020#if 0
3021/*2
3022* xx,q: arrays of length 0..rl-1
3023* xx[i]: SB mod q[i]
3024* assume: char=0
3025* assume: q[i]!=0
3026* destroys xx
3027*/
3028ideal id_ChineseRemainder(ideal *xx, number *q, int rl, const ring R)
3029{
3030 int cnt=IDELEMS(xx[0])*xx[0]->nrows;
3031 ideal result=idInit(cnt,xx[0]->rank);
3032 result->nrows=xx[0]->nrows; // for lifting matrices
3033 result->ncols=xx[0]->ncols; // for lifting matrices
3034 int i,j;
3035 poly r,h,hh,res_p;
3036 number *x=(number *)omAlloc(rl*sizeof(number));
3037 for(i=cnt-1;i>=0;i--)
3038 {
3039 res_p=NULL;
3040 loop
3041 {
3042 r=NULL;
3043 for(j=rl-1;j>=0;j--)
3044 {
3045 h=xx[j]->m[i];
3046 if ((h!=NULL)
3047 &&((r==NULL)||(p_LmCmp(r,h,R)==-1)))
3048 r=h;
3049 }
3050 if (r==NULL) break;
3051 h=p_Head(r, R);
3052 for(j=rl-1;j>=0;j--)
3053 {
3054 hh=xx[j]->m[i];
3055 if ((hh!=NULL) && (p_LmCmp(r,hh, R)==0))
3056 {
3057 x[j]=p_GetCoeff(hh, R);
3058 hh=p_LmFreeAndNext(hh, R);
3059 xx[j]->m[i]=hh;
3060 }
3061 else
3062 x[j]=n_Init(0, R->cf); // is R->cf really n_Q???, yes!
3063 }
3064
3065 number n=n_ChineseRemainder(x,q,rl, R->cf);
3066
3067 for(j=rl-1;j>=0;j--)
3068 {
3069 x[j]=NULL; // nlInit(0...) takes no memory
3070 }
3071 if (n_IsZero(n, R->cf)) p_Delete(&h, R);
3072 else
3073 {
3074 p_SetCoeff(h,n, R);
3075 //Print("new mon:");pWrite(h);
3076 res_p=p_Add_q(res_p, h, R);
3077 }
3078 }
3079 result->m[i]=res_p;
3080 }
3081 omFree(x);
3082 for(i=rl-1;i>=0;i--) id_Delete(&(xx[i]), R);
3083 omFree(xx);
3084 return result;
3085}
3086#endif
3087/* currently unused:
3088ideal idChineseRemainder(ideal *xx, intvec *iv)
3089{
3090 int rl=iv->length();
3091 number *q=(number *)omAlloc(rl*sizeof(number));
3092 int i;
3093 for(i=0; i<rl; i++)
3094 {
3095 q[i]=nInit((*iv)[i]);
3096 }
3097 return idChineseRemainder(xx,q,rl);
3098}
3099*/
3100/*
3101 * lift ideal with coeffs over Z (mod N) to Q via Farey
3102 */
3103ideal id_Farey(ideal x, number N, const ring r)
3104{
3105 int cnt=IDELEMS(x)*x->nrows;
3106 ideal result=idInit(cnt,x->rank);
3107 result->nrows=x->nrows; // for lifting matrices
3108 result->ncols=x->ncols; // for lifting matrices
3109
3110 int i;
3111 for(i=cnt-1;i>=0;i--)
3112 {
3113 result->m[i]=p_Farey(x->m[i],N,r);
3114 }
3115 return result;
3116}
3117
3118
3119
3120
3121// uses glabl vars via pSetModDeg
3122/*
3123BOOLEAN idTestHomModule(ideal m, ideal Q, intvec *w)
3124{
3125 if ((Q!=NULL) && (!idHomIdeal(Q,NULL))) { PrintS(" Q not hom\n"); return FALSE;}
3126 if (idIs0(m)) return TRUE;
3127
3128 int cmax=-1;
3129 int i;
3130 poly p=NULL;
3131 int length=IDELEMS(m);
3132 poly* P=m->m;
3133 for (i=length-1;i>=0;i--)
3134 {
3135 p=P[i];
3136 if (p!=NULL) cmax=si_max(cmax,(int)pMaxComp(p)+1);
3137 }
3138 if (w != NULL)
3139 if (w->length()+1 < cmax)
3140 {
3141 // Print("length: %d - %d \n", w->length(),cmax);
3142 return FALSE;
3143 }
3144
3145 if(w!=NULL)
3146 p_SetModDeg(w, currRing);
3147
3148 for (i=length-1;i>=0;i--)
3149 {
3150 p=P[i];
3151 poly q=p;
3152 if (p!=NULL)
3153 {
3154 int d=p_FDeg(p,currRing);
3155 loop
3156 {
3157 pIter(p);
3158 if (p==NULL) break;
3159 if (d!=p_FDeg(p,currRing))
3160 {
3161 //pWrite(q); wrp(p); Print(" -> %d - %d\n",d,pFDeg(p,currRing));
3162 if(w!=NULL)
3163 p_SetModDeg(NULL, currRing);
3164 return FALSE;
3165 }
3166 }
3167 }
3168 }
3169
3170 if(w!=NULL)
3171 p_SetModDeg(NULL, currRing);
3172
3173 return TRUE;
3174}
3175*/
3176
3177/// keeps the first k (>= 1) entries of the given ideal
3178/// (Note that the kept polynomials may be zero.)
3179void idKeepFirstK(ideal id, const int k)
3180{
3181 for (int i = IDELEMS(id)-1; i >= k; i--)
3182 {
3183 if (id->m[i] != NULL) pDelete(&id->m[i]);
3184 }
3185 int kk=k;
3186 if (k==0) kk=1; /* ideals must have at least one element(0)*/
3187 pEnlargeSet(&(id->m), IDELEMS(id), kk-IDELEMS(id));
3188 IDELEMS(id) = kk;
3189}
3190
3191typedef struct
3192{
3193 poly p;
3195} poly_sort;
3196
3197int pCompare_qsort(const void *a, const void *b)
3198{
3199 return (p_Compare(((poly_sort *)a)->p, ((poly_sort *)b)->p,currRing));
3200}
3201
3202void idSort_qsort(poly_sort *id_sort, int idsize)
3203{
3204 qsort(id_sort, idsize, sizeof(poly_sort), pCompare_qsort);
3205}
3206
3207/*2
3208* ideal id = (id[i])
3209* if id[i] = id[j] then id[j] is deleted for j > i
3210*/
3211void idDelEquals(ideal id)
3212{
3213 int idsize = IDELEMS(id);
3214 poly_sort *id_sort = (poly_sort *)omAlloc0(idsize*sizeof(poly_sort));
3215 for (int i = 0; i < idsize; i++)
3216 {
3217 id_sort[i].p = id->m[i];
3218 id_sort[i].index = i;
3219 }
3220 idSort_qsort(id_sort, idsize);
3221 int index, index_i, index_j;
3222 int i = 0;
3223 for (int j = 1; j < idsize; j++)
3224 {
3225 if (id_sort[i].p != NULL && pEqualPolys(id_sort[i].p, id_sort[j].p))
3226 {
3227 index_i = id_sort[i].index;
3228 index_j = id_sort[j].index;
3229 if (index_j > index_i)
3230 {
3231 index = index_j;
3232 }
3233 else
3234 {
3235 index = index_i;
3236 i = j;
3237 }
3238 pDelete(&id->m[index]);
3239 }
3240 else
3241 {
3242 i = j;
3243 }
3244 }
3245 omFreeSize((ADDRESS)(id_sort), idsize*sizeof(poly_sort));
3246}
3247
3249
3251{
3252 BOOLEAN b = FALSE; // set b to TRUE, if spoly was changed,
3253 // let it remain FALSE otherwise
3254 if (strat->P.t_p==NULL)
3255 {
3256 poly p=strat->P.p;
3257
3258 // iterate over all terms of p and
3259 // compute the minimum mm of all exponent vectors
3260 int *mm=(int*)omAlloc((1+rVar(currRing))*sizeof(int));
3261 int *m0=(int*)omAlloc0((1+rVar(currRing))*sizeof(int));
3262 p_GetExpV(p,mm,currRing);
3263 bool nonTrivialSaturationToBeDone=true;
3264 for (; p!=NULL; pIter(p))
3265 {
3266 nonTrivialSaturationToBeDone=false;
3267 p_GetExpV(p,m0,currRing);
3268 for (int i=rVar(currRing); i>0; i--)
3269 {
3271 {
3272 mm[i]=si_min(mm[i],m0[i]);
3273 if (mm[i]>0) nonTrivialSaturationToBeDone=true;
3274 }
3275 else mm[i]=0;
3276 }
3277 // abort if the minimum is zero in each component
3278 if (!nonTrivialSaturationToBeDone) break;
3279 }
3280 if (nonTrivialSaturationToBeDone)
3281 {
3282 // std::cout << "simplifying!" << std::endl;
3283 if (TEST_OPT_PROT) { PrintS("S"); mflush(); }
3284 p=p_Copy(strat->P.p,currRing);
3285 //pWrite(p);
3286 // for (int i=rVar(currRing); i>0; i--)
3287 // if (mm[i]!=0) Print("x_%d:%d ",i,mm[i]);
3288 //PrintLn();
3289 strat->P.Init(strat->tailRing);
3290 //memset(&strat->P,0,sizeof(strat->P));
3291 //strat->P.tailRing = strat->tailRing; // done by Init
3292 strat->P.p=p;
3293 while(p!=NULL)
3294 {
3295 for (int i=rVar(currRing); i>0; i--)
3296 {
3297 p_SubExp(p,i,mm[i],currRing);
3298 }
3299 p_Setm(p,currRing);
3300 pIter(p);
3301 }
3302 b = TRUE;
3303 }
3304 omFree(mm);
3305 omFree(m0);
3306 }
3307 else
3308 {
3309 poly p=strat->P.t_p;
3310
3311 // iterate over all terms of p and
3312 // compute the minimum mm of all exponent vectors
3313 int *mm=(int*)omAlloc((1+rVar(currRing))*sizeof(int));
3314 int *m0=(int*)omAlloc0((1+rVar(currRing))*sizeof(int));
3315 p_GetExpV(p,mm,strat->tailRing);
3316 bool nonTrivialSaturationToBeDone=true;
3317 for (; p!=NULL; pIter(p))
3318 {
3319 nonTrivialSaturationToBeDone=false;
3320 p_GetExpV(p,m0,strat->tailRing);
3321 for(int i=rVar(currRing); i>0; i--)
3322 {
3324 {
3325 mm[i]=si_min(mm[i],m0[i]);
3326 if (mm[i]>0) nonTrivialSaturationToBeDone = true;
3327 }
3328 else mm[i]=0;
3329 }
3330 // abort if the minimum is zero in each component
3331 if (!nonTrivialSaturationToBeDone) break;
3332 }
3333 if (nonTrivialSaturationToBeDone)
3334 {
3335 if (TEST_OPT_PROT) { PrintS("S"); mflush(); }
3336 p=p_Copy(strat->P.t_p,strat->tailRing);
3337 //p_Write(p,strat->tailRing);
3338 // for (int i=rVar(currRing); i>0; i--)
3339 // if (mm[i]!=0) Print("x_%d:%d ",i,mm[i]);
3340 //PrintLn();
3341 strat->P.Init(strat->tailRing);
3342 //memset(&strat->P,0,sizeof(strat->P));
3343 //strat->P.tailRing = strat->tailRing;// done by Init
3344 strat->P.t_p=p;
3345 while(p!=NULL)
3346 {
3347 for(int i=rVar(currRing); i>0; i--)
3348 {
3349 p_SubExp(p,i,mm[i],strat->tailRing);
3350 }
3351 p_Setm(p,strat->tailRing);
3352 pIter(p);
3353 }
3354 strat->P.GetP();
3355 b = TRUE;
3356 }
3357 omFree(mm);
3358 omFree(m0);
3359 }
3360 return b; // return TRUE if sp was changed, FALSE if not
3361}
3362
3363ideal id_Satstd(const ideal I, ideal J, const ring r)
3364{
3365 ring save=currRing;
3366 if (currRing!=r) rChangeCurrRing(r);
3367 idSkipZeroes(J);
3368 id_satstdSaturatingVariables=(int*)omAlloc0((1+rVar(currRing))*sizeof(int));
3369 int k=IDELEMS(J);
3370 if (k>1)
3371 {
3372 for (int i=0; i<k; i++)
3373 {
3374 poly x = J->m[i];
3375 int li = p_Var(x,r);
3376 if (li>0)
3378 else
3379 {
3380 if (currRing!=save) rChangeCurrRing(save);
3381 WerrorS("ideal generators must be variables");
3382 return NULL;
3383 }
3384 }
3385 }
3386 else
3387 {
3388 poly x = J->m[0];
3389 if (pNext(x)!=NULL)
3390 {
3391 Werror("generator must be a monomial");
3392 if (currRing!=save) rChangeCurrRing(save);
3393 return NULL;
3394 }
3395 for (int i=1; i<=r->N; i++)
3396 {
3397 int li = p_GetExp(x,i,r);
3398 if (li==1)
3400 else if (li>1)
3401 {
3402 if (currRing!=save) rChangeCurrRing(save);
3403 Werror("exponent(x(%d)^%d) must be 0 or 1",i,li);
3404 return NULL;
3405 }
3406 }
3407 }
3408 ideal res=kStd2(I,r->qideal,testHomog,NULL,(bigintmat*)NULL,0,0,NULL,id_sat_vars_sp);
3411 if (currRing!=save) rChangeCurrRing(save);
3412 return res;
3413}
3414
3415ideal id_Sat_principal(ideal I, ideal J, const ring origR)
3416{
3417 rRingOrder_t *ord;
3418 int *block0,*block1;
3419 int **wv;
3420
3421 // construction extension ring
3422 ord=(rRingOrder_t*)omAlloc0(4*sizeof(rRingOrder_t));
3423 block0=(int*)omAlloc0(4*sizeof(int));
3424 block1=(int*)omAlloc0(4*sizeof(int));
3425 wv=(int**) omAlloc0(4*sizeof(int**));
3426 wv[0]=(int*)omAlloc0((rVar(origR) + 2)*sizeof(int));
3427 block0[0] = block0[1] = 1;
3428 block1[0] = block1[1] = rVar(origR)+1;
3429 // use this special ordering: like ringorder_a, except that pFDeg, pWeights
3430 // ignore it
3431 ord[0] = ringorder_aa;
3432 wv[0][rVar(origR)]=1;
3433 BOOLEAN wp=FALSE;
3434 for (int j=0;j<rVar(origR);j++)
3435 if (p_Weight(j+1,origR)!=1) { wp=TRUE;break; }
3436 if (wp)
3437 {
3438 wv[1]=(int*)omAlloc0((rVar(origR) + 1)*sizeof(int));
3439 for (int j=0;j<rVar(origR);j++)
3440 wv[1][j]=p_Weight(j+1,origR);
3441 ord[1] = ringorder_wp;
3442 }
3443 else
3444 ord[1] = ringorder_dp;
3445 ord[2] = ringorder_C;
3446 ord[3] = (rRingOrder_t)0;
3447 char **names=(char**)omAlloc0((origR->N+1) * sizeof(char *));
3448 for (int j=0;j<rVar(origR);j++)
3449 names[j]=origR->names[j];
3450 names[rVar(origR)]=(char*)"@";
3451 ring tmpR=rDefault(nCopyCoeff(origR->cf),rVar(origR)+1,names,4,ord,block0,block1,wv);
3452 omFree(names);
3453 rComplete(tmpR, 1);
3454 rChangeCurrRing(tmpR);
3455 // map I
3456 ideal II=idrCopyR(I,origR,tmpR);
3457 // map J
3458 ideal JJ=idrCopyR(J,origR,tmpR);
3459 // J[1]*t-1
3460 poly t=pOne();
3461 p_SetExp(t,rVar(tmpR),1,tmpR);
3462 p_Setm(t,tmpR);
3463 poly p=JJ->m[0];
3464 p_Norm(p,currRing);
3465 p=p_Mult_q(p,t,tmpR);
3466 p=p_Sub(p,pOne(),tmpR);
3467 JJ->m[0]=p;
3468 ideal T=id_SimpleAdd(II,JJ,tmpR);
3469 idTest(T);
3470 id_Delete(&II,tmpR);
3471 id_Delete(&JJ,tmpR);
3472 // elimination
3473 t=pOne();
3474 p_SetExp(t,rVar(tmpR),1,tmpR);
3475 p_Setm(t,tmpR);
3476 ideal TT=idGroebner(T,0,GbStd);
3477 p_Delete(&t,tmpR);
3478 for(int j=0;j<IDELEMS(TT);j++)
3479 {
3480 if ((TT->m[j]!=NULL)
3481 && (p_GetExp(TT->m[j],rVar(tmpR),tmpR)>0))
3482 {
3483 p_Delete(&TT->m[j],tmpR);
3484 }
3485 }
3486 // map back
3487 ideal TTT=idrCopyR(TT,tmpR,origR);
3488 id_Delete(&TT,tmpR);
3489 rChangeCurrRing(origR);
3490 rDelete(tmpR);
3491 idSkipZeroes(TTT);
3492 return TTT;
3493}
3494
3495ideal idSaturate_intern(ideal I, ideal J, int &k, BOOLEAN isIdeal, BOOLEAN isSB)
3496{
3497 if(idIs0(J))
3498 {
3499 ideal res;
3500 if(isIdeal)
3501 {
3502 res=idInit(1,1);
3503 res->m[0]=pOne();
3504 }
3505 else
3506 {
3507 res=idFreeModule(I->rank);
3508 }
3509 k=1;
3510 return(res);
3511 }
3512 BITSET save_opt;SI_SAVE_OPT2(save_opt);
3513 //if (idElem(J)==1)
3514 //{
3515 // idSkipZeroes(J);
3516 // return id_Sat_principal(I,J,currRing);
3517 //}
3518 //---------------------------------------------------
3520 {
3521 BOOLEAN only_vars=TRUE; // enabled for I:x_i
3522 if (idElem(J)==1)
3523 {
3524 for(int j=IDELEMS(J)-1;j>=0;j--)
3525 {
3526 poly p=J->m[j];
3527 if (p!=NULL)
3528 {
3529 if (pVar(p)==0)
3530 {
3531 only_vars=FALSE;
3532 break;
3533 }
3534 }
3535 }
3536 }
3537 if (only_vars && isIdeal && rOrd_is_Totaldegree_Ordering(currRing)
3538 && (idElem(J)==1))
3539 {
3540 ideal Iquot,Istd;
3541 intvec *w=NULL;
3542 Istd=id_Satstd(I,J,currRing);
3544 k=0;
3545 loop
3546 {
3547 k++;
3548 Iquot=idQuot(Istd,J,TRUE,isIdeal);
3549 ideal tmp=kNF(Istd,currRing->qideal,Iquot,5);
3550 int elem=idElem(tmp);
3551 id_Delete(&tmp,currRing);
3552 id_Delete(&Istd,currRing);
3553 Istd=Iquot;
3554 w=NULL;
3555 Istd=kStd2(Iquot,currRing->qideal,testHomog,&w,(bigintmat*)NULL);
3556 if (w!=NULL) delete w;
3557 id_Delete(&Iquot,currRing);
3558 if (elem==0) break;
3559 }
3560 k--;
3561 idSkipZeroes(Istd);
3562 //PrintS("\nSatstd:\n");
3563 //iiWriteMatrix((matrix)I,"I",1,currRing,0); PrintLn();
3564 //iiWriteMatrix((matrix)J,"J",1,currRing,0); PrintLn();
3565 //iiWriteMatrix((matrix)Istd,"res",1,currRing,0);PrintLn();
3566 //id_Delete(&Istd,currRing);
3567 SI_RESTORE_OPT2(save_opt);
3568 return Istd;
3569 }
3570 }
3571 //--------------------------------------------------
3572 ideal Iquot,Istd;
3573 intvec *w=NULL;
3574 Istd=idCopy(I);
3575 k=0;
3576 loop
3577 {
3578 k++;
3579 Iquot=idQuot(Istd,J,isSB,isIdeal);
3580 isSB=FALSE;
3581 si_opt_2|=Sy_bit(V_PURE_GB); // used from 2nd loop on
3582 ideal tmp=kNF(Istd,currRing->qideal,Iquot,5);
3583 int elem=idElem(tmp);
3584 id_Delete(&tmp,currRing);
3585 id_Delete(&Istd,currRing);
3586 Istd=Iquot;
3587 if (elem==0) break;
3588 }
3589 k--;
3590 Istd=kStd2(Iquot,currRing->qideal,testHomog,&w,(bigintmat*)NULL);
3591 idSkipZeroes(Istd);
3592 SI_RESTORE_OPT2(save_opt);
3593 //if (only_vars)
3594 //{
3595 // iiWriteMatrix((matrix)Istd,"org",1,currRing,0);
3596 //}
3597 return Istd;
3598}
3599ideal idSaturate(ideal I, ideal J, int &k, BOOLEAN isIdeal)
3600{
3601 return idSaturate_intern(I,J,k,isIdeal,FALSE);
3602}
3603ideal idSaturateGB(ideal I, ideal J, int &k, BOOLEAN isIdeal)
3604{
3605 return idSaturate_intern(I,J,k,isIdeal,TRUE);
3606}
3607
3608ideal id_Homogenize(ideal I, int var_num, const ring r)
3609{
3610 ideal II=id_Copy(I,r);
3611 if (var_num==1)
3612 {
3613 ring tmpR=rAssure_Dp_C(r);
3614 if (tmpR!=r)
3615 {
3616 rChangeCurrRing(tmpR);
3617 II=idrMoveR(II,r,tmpR);
3618 }
3619 ideal III=id_Homogen(II,1,tmpR);
3620 id_Delete(&II,tmpR);
3621 intvec *ww=NULL;
3622 II=kStd2(III,currRing->qideal,(tHomog)TRUE,&ww,(bigintmat*)NULL);
3623 if (ww!=NULL) delete ww;
3624 id_Delete(&III,tmpR);
3625 if (tmpR!=r)
3626 {
3627 rChangeCurrRing(r);
3628 II=idrMoveR(II,tmpR,r);
3629 }
3630 return II;
3631 }
3632 ideal III=idInit(IDELEMS(II),1);
3633 int *perm=(int*)omAlloc0((rVar(r)+1)*sizeof(int));
3634 for(int i=rVar(r)-1; i>0; i--) perm[i]=i;
3635 perm[var_num]=1;
3636 perm[1]=var_num;
3637 for(int i=IDELEMS(II)-1; i>=0;i--)
3638 {
3639 III->m[i]=p_PermPoly(II->m[i],perm,r,r,ndCopyMap,NULL,0,FALSE);
3640 }
3641 id_Delete(&II,r);
3642 II=id_Homogenize(III,1,r);
3643 id_Delete(&III,r);
3644 III=idInit(IDELEMS(II),1);
3645 for(int i=IDELEMS(II)-1; i>=0;i--)
3646 {
3647 III->m[i]=p_PermPoly(II->m[i],perm,r,r,ndCopyMap,NULL,0,FALSE);
3648 }
3649 id_Delete(&II,r);
3650 return III;
3651}
3652
3653ideal id_HomogenizeW(ideal I, int var_num, intvec *w,const ring r)
3654{
3655 ideal II=id_Copy(I,r);
3656 if (var_num==1)
3657 {
3658 ring tmpR=rAssure_Wp_C(r,w);
3659 if (tmpR!=r)
3660 {
3661 rChangeCurrRing(tmpR);
3662 II=idrMoveR(II,r,tmpR);
3663 }
3664 ideal III=id_Homogen(II,1,tmpR);
3665 id_Delete(&II,tmpR);
3666 intvec *ww=NULL;
3667 II=kStd2(III,currRing->qideal,(tHomog)TRUE,&ww,(bigintmat*)NULL);
3668 if (ww!=NULL) delete ww;
3669 id_Delete(&III,tmpR);
3670 if (tmpR!=r)
3671 {
3672 rChangeCurrRing(r);
3673 II=idrMoveR(II,tmpR,r);
3674 }
3675 return II;
3676 }
3677 ideal III=idInit(IDELEMS(II),1);
3678 int *perm=(int*)omAlloc0((rVar(r)+1)*sizeof(int));
3679 for(int i=rVar(r)-1; i>0; i--) perm[i]=i;
3680 perm[var_num]=1;
3681 perm[1]=var_num;
3682 for(int i=IDELEMS(II)-1; i>=0;i--)
3683 {
3684 III->m[i]=p_PermPoly(II->m[i],perm,r,r,ndCopyMap,NULL,0,FALSE);
3685 }
3686 id_Delete(&II,r);
3687 II=id_HomogenizeW(III,1,w,r);
3688 id_Delete(&III,r);
3689 III=idInit(IDELEMS(II),1);
3690 for(int i=IDELEMS(II)-1; i>=0;i--)
3691 {
3692 III->m[i]=p_PermPoly(II->m[i],perm,r,r,ndCopyMap,NULL,0,FALSE);
3693 }
3694 id_Delete(&II,r);
3695 return III;
3696}
3697
3698GbVariant syGetAlgorithm(char *n, const ring r, const ideal /*M*/)
3699{
3700 GbVariant alg=GbDefault;
3701 if (strcmp(n,"default")==0) alg=GbDefault;
3702 else if (strcmp(n,"slimgb")==0) alg=GbSlimgb;
3703 else if (strcmp(n,"std")==0) alg=GbStd;
3704 else if (strcmp(n,"sba")==0) alg=GbSba;
3705 else if (strcmp(n,"singmatic")==0) alg=GbSingmatic;
3706 else if (strcmp(n,"groebner")==0) alg=GbGroebner;
3707 else if (strcmp(n,"modstd")==0) alg=GbModstd;
3708 else if (strcmp(n,"ffmod")==0) alg=GbFfmod;
3709 else if (strcmp(n,"nfmod")==0) alg=GbNfmod;
3710 else if (strcmp(n,"std:sat")==0) alg=GbStdSat;
3711 else Warn(">>%s<< is an unknown algorithm",n);
3712
3713 if (alg==GbSlimgb) // test conditions for slimgb
3714 {
3715 if(rHasGlobalOrdering(r)
3716 &&(!rIsNCRing(r))
3717 &&(r->qideal==NULL)
3718 &&(!rField_is_Ring(r)))
3719 {
3720 return GbSlimgb;
3721 }
3722 if (TEST_OPT_PROT)
3723 WarnS("requires: coef:field, commutative, global ordering, not qring");
3724 }
3725 else if (alg==GbSba) // cond. for sba
3726 {
3727 if(rField_is_Domain(r)
3728 &&(!rIsNCRing(r))
3729 &&(rHasGlobalOrdering(r)))
3730 {
3731 return GbSba;
3732 }
3733 if (TEST_OPT_PROT)
3734 WarnS("requires: coef:domain, commutative, global ordering");
3735 }
3736 else if (alg==GbGroebner) // cond. for groebner
3737 {
3738 return GbGroebner;
3739 }
3740 else if(alg==GbModstd) // cond for modstd: Q or Q(a)
3741 {
3742 if(ggetid("modStd")==NULL)
3743 {
3744 WarnS(">>modStd<< not found");
3745 }
3746 else if(rField_is_Q(r)
3747 &&(!rIsNCRing(r))
3748 &&(rHasGlobalOrdering(r)))
3749 {
3750 return GbModstd;
3751 }
3752 if (TEST_OPT_PROT)
3753 WarnS("requires: coef:QQ, commutative, global ordering");
3754 }
3755 else if(alg==GbStdSat) // cond for std:sat: 2 blocks of variables
3756 {
3757 if(ggetid("satstd")==NULL)
3758 {
3759 WarnS(">>satstd<< not found");
3760 }
3761 else
3762 {
3763 return GbStdSat;
3764 }
3765 }
3766
3767 return GbStd; // no conditions for std
3768}
3769//----------------------------------------------------------------------------
3770// GB-algorithms and their pre-conditions
3771// std slimgb sba singmatic modstd ffmod nfmod groebner
3772// + + + - + - - + coeffs: QQ
3773// + + + + - - - + coeffs: ZZ/p
3774// + + + - ? - + + coeffs: K[a]/f
3775// + + + - ? + - + coeffs: K(a)
3776// + - + - - - - + coeffs: domain, not field
3777// + - - - - - - + coeffs: zero-divisors
3778// + + + + - ? ? + also for modules: C
3779// + + - + - ? ? + also for modules: all orderings
3780// + + - - - - - + exterior algebra
3781// + + - - - - - + G-algebra
3782// + + + + + + + + degree ordering
3783// + - + + + + + + non-degree ordering
3784// - - - + + + + + parallel
#define BITSET
Definition auxiliary.h:85
static int si_max(const int a, const int b)
Definition auxiliary.h:125
int BOOLEAN
Definition auxiliary.h:88
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
void * ADDRESS
Definition auxiliary.h:120
static int si_min(const int a, const int b)
Definition auxiliary.h:126
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
CF_NO_INLINE FACTORY_PUBLIC CanonicalForm mod(const CanonicalForm &, const CanonicalForm &)
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
int l
Definition cfEzgcd.cc:100
int m
Definition cfEzgcd.cc:128
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
Variable x
Definition cfModGcd.cc:4090
int p
Definition cfModGcd.cc:4086
g
Definition cfModGcd.cc:4098
CanonicalForm b
Definition cfModGcd.cc:4111
static CanonicalForm bound(const CFMatrix &M)
Definition cf_linsys.cc:460
FILE * f
Definition checklibs.c:9
poly singclap_pdivide(poly f, poly g, const ring r)
Definition clapsing.cc:649
Matrices of numbers.
Definition bigintmat.h:51
int nrows
Definition matpol.h:20
long rank
Definition matpol.h:19
int ncols
Definition matpol.h:21
poly * m
Definition matpol.h:18
int & cols()
Definition matpol.h:24
int & rows()
Definition matpol.h:23
ring tailRing
Definition kutil.h:342
LObject P
Definition kutil.h:301
void * data
Definition subexpr.h:88
Coefficient rings, fields and other domains suitable for Singular polynomials.
number ndCopyMap(number a, const coeffs src, const coeffs dst)
Definition numbers.cc:293
static FORCE_INLINE BOOLEAN n_IsUnit(number n, const coeffs r)
TRUE iff n has a multiplicative inverse in the given coeff field/ring r.
Definition coeffs.h:521
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition coeffs.h:470
static FORCE_INLINE coeffs nCopyCoeff(const coeffs r)
"copy" coeffs, i.e. increment ref
Definition coeffs.h:439
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
Definition coeffs.h:541
#define Print
Definition emacs.cc:80
#define Warn
Definition emacs.cc:77
#define WarnS
Definition emacs.cc:78
return result
const CanonicalForm int s
Definition facAbsFact.cc:51
CanonicalForm res
Definition facAbsFact.cc:60
const CanonicalForm & w
Definition facAbsFact.cc:51
CanonicalForm divide(const CanonicalForm &ff, const CanonicalForm &f, const CFList &as)
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
int j
Definition facHensel.cc:110
int comp(const CanonicalForm &A, const CanonicalForm &B)
compare polynomials
char name(const Variable &v)
Definition factory.h:189
VAR short errorreported
Definition feFopen.cc:23
void WerrorS(const char *s)
Definition feFopen.cc:24
#define STATIC_VAR
Definition globaldefs.h:7
@ IDEAL_CMD
Definition grammar.cc:285
@ MODUL_CMD
Definition grammar.cc:288
GbVariant syGetAlgorithm(char *n, const ring r, const ideal)
Definition ideals.cc:3698
static ideal idMinEmbedding1(ideal arg, BOOLEAN inPlace, intvec **w, int *red_comp, int &del)
Definition ideals.cc:2817
int index
Definition ideals.cc:3194
static void idPrepareStd(ideal s_temp, int k)
Definition ideals.cc:1047
matrix idCoeffOfKBase(ideal arg, ideal kbase, poly how)
Definition ideals.cc:2668
void idLiftW(ideal P, ideal Q, int n, matrix &T, ideal &R, int *w)
Definition ideals.cc:1347
static void idLift_setUnit(int e_mod, matrix *unit)
Definition ideals.cc:1088
ideal idSyzygies(ideal h1, tHomog h, intvec **w, BOOLEAN setSyzComp, BOOLEAN setRegularity, int *deg, GbVariant alg)
Definition ideals.cc:836
matrix idDiff(matrix i, int k)
Definition ideals.cc:2189
ideal id_Sat_principal(ideal I, ideal J, const ring origR)
Definition ideals.cc:3415
ideal idSaturateGB(ideal I, ideal J, int &k, BOOLEAN isIdeal)
Definition ideals.cc:3603
static ideal idGroebner(ideal temp, int syzComp, GbVariant alg, bigintmat *hilb=NULL, intvec *w=NULL, tHomog hom=testHomog)
Definition ideals.cc:200
BOOLEAN idTestHomModule(ideal m, ideal Q, intvec *w)
Definition ideals.cc:2120
ideal id_Homogenize(ideal I, int var_num, const ring r)
Definition ideals.cc:3608
ideal idLiftStd(ideal h1, matrix *T, tHomog hi, ideal *S, GbVariant alg, ideal h11)
Definition ideals.cc:982
void idDelEquals(ideal id)
Definition ideals.cc:3211
int pCompare_qsort(const void *a, const void *b)
Definition ideals.cc:3197
ideal idQuot(ideal h1, ideal h2, BOOLEAN h1IsStb, BOOLEAN resultIsIdeal)
Definition ideals.cc:1539
ideal id_HomogenizeW(ideal I, int var_num, intvec *w, const ring r)
Definition ideals.cc:3653
ideal idMinors(matrix a, int ar, ideal R)
compute all ar-minors of the matrix a the caller of mpRecMin the elements of the result are not in R ...
Definition ideals.cc:2031
ideal idSaturate(ideal I, ideal J, int &k, BOOLEAN isIdeal)
Definition ideals.cc:3599
void ipPrint_MA0(matrix m, const char *name)
Definition ipprint.cc:57
BOOLEAN idIsSubModule(ideal id1, ideal id2)
Definition ideals.cc:2099
ideal idSeries(int n, ideal M, matrix U, intvec *w)
Definition ideals.cc:2172
ideal idMinEmbedding_with_map_v(ideal arg, intvec **w, ideal &trans, int *g)
Definition ideals.cc:2874
ideal idCreateSpecialKbase(ideal kBase, intvec **convert)
Definition ideals.cc:2582
static ideal idPrepare(ideal h1, ideal h11, tHomog hom, int syzcomp, intvec **w, GbVariant alg)
Definition ideals.cc:613
poly id_GCD(poly f, poly g, const ring r)
Definition ideals.cc:3000
int idIndexOfKBase(poly monom, ideal kbase)
Definition ideals.cc:2600
poly idDecompose(poly monom, poly how, ideal kbase, int *pos)
Definition ideals.cc:2636
ideal idSaturate_intern(ideal I, ideal J, int &k, BOOLEAN isIdeal, BOOLEAN isSB)
Definition ideals.cc:3495
ideal idElimination2(ideal h1, poly delVar, bigintmat *hilb, GbVariant alg)
Definition ideals.cc:1640
matrix idDiffOp(ideal I, ideal J, BOOLEAN multiply)
Definition ideals.cc:2202
void idSort_qsort(poly_sort *id_sort, int idsize)
Definition ideals.cc:3202
static ideal idInitializeQuot(ideal h1, ideal h2, BOOLEAN h1IsStb, BOOLEAN *addOnlyOne, int *kkmax)
Definition ideals.cc:1412
ideal idElimination(ideal h1, poly delVar, intvec *hilb, GbVariant alg)
Definition ideals.cc:1884
static ideal idSectWithElim(ideal h1, ideal h2, GbVariant alg)
Definition ideals.cc:132
ideal idSect(ideal h1, ideal h2, GbVariant alg)
Definition ideals.cc:315
ideal idMultSect(resolvente arg, int length, GbVariant alg)
Definition ideals.cc:472
void idKeepFirstK(ideal id, const int k)
keeps the first k (>= 1) entries of the given ideal (Note that the kept polynomials may be zero....
Definition ideals.cc:3179
ideal idLift(ideal mod, ideal submod, ideal *rest, BOOLEAN goodShape, BOOLEAN isSB, BOOLEAN divide, matrix *unit, GbVariant alg)
represents the generators of submod in terms of the generators of mod (Matrix(SM)*U-Matrix(rest)) = M...
Definition ideals.cc:1111
STATIC_VAR int * id_satstdSaturatingVariables
Definition ideals.cc:3248
ideal idExtractG_T_S(ideal s_h3, matrix *T, ideal *S, long syzComp, int h1_size, BOOLEAN inputIsIdeal, const ring oring, const ring sring)
Definition ideals.cc:715
static void idDeleteComps(ideal arg, int *red_comp, int del)
Definition ideals.cc:2707
ideal idModulo(ideal h2, ideal h1, tHomog hom, intvec **w, matrix *T, GbVariant alg)
Definition ideals.cc:2463
ideal idMinEmbedding_with_map(ideal arg, intvec **w, ideal &trans)
Definition ideals.cc:2863
ideal idMinBase(ideal h1, ideal *SB)
Definition ideals.cc:51
ideal id_Farey(ideal x, number N, const ring r)
Definition ideals.cc:3103
ideal id_Satstd(const ideal I, ideal J, const ring r)
Definition ideals.cc:3363
static int id_ReadOutPivot(ideal arg, int *comp, const ring r)
Definition ideals.cc:2734
ideal idModuloLP(ideal h2, ideal h1, tHomog, intvec **w, matrix *T, GbVariant alg)
Definition ideals.cc:2272
static BOOLEAN id_sat_vars_sp(kStrategy strat)
Definition ideals.cc:3250
ideal idMinEmbedding(ideal arg, BOOLEAN inPlace, intvec **w)
Definition ideals.cc:2853
int binom(int n, int r)
GbVariant
Definition ideals.h:119
@ GbGroebner
Definition ideals.h:126
@ GbModstd
Definition ideals.h:127
@ GbStdSat
Definition ideals.h:130
@ GbSlimgb
Definition ideals.h:123
@ GbFfmod
Definition ideals.h:128
@ GbNfmod
Definition ideals.h:129
@ GbDefault
Definition ideals.h:120
@ GbStd
Definition ideals.h:122
@ GbSingmatic
Definition ideals.h:131
@ GbSba
Definition ideals.h:124
#define idDelete(H)
delete an ideal
Definition ideals.h:29
#define idSimpleAdd(A, B)
Definition ideals.h:42
void idGetNextChoise(int r, int end, BOOLEAN *endch, int *choise)
ideal id_Copy(ideal h1, const ring r)
copy an ideal
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
static BOOLEAN idHomModule(ideal m, ideal Q, intvec **w)
Definition ideals.h:96
#define idTest(id)
Definition ideals.h:47
static BOOLEAN idHomIdeal(ideal id, ideal Q=NULL)
Definition ideals.h:91
static ideal idMult(ideal h1, ideal h2)
hh := h1 * h2
Definition ideals.h:84
ideal idCopy(ideal A)
Definition ideals.h:60
#define idMaxIdeal(D)
initialise the maximal ideal (at 0)
Definition ideals.h:33
ideal * resolvente
Definition ideals.h:18
void idInitChoise(int r, int beg, int end, BOOLEAN *endch, int *choise)
static intvec * idSort(ideal id, BOOLEAN nolex=TRUE)
Definition ideals.h:188
ideal idFreeModule(int i)
Definition ideals.h:111
static BOOLEAN length(leftv result, leftv arg)
Definition interval.cc:257
bigintmat * iv2biv(intvec *hilb, const coeffs cf)
Definition intvec.cc:851
intvec * ivCopy(const intvec *o)
Definition intvec.h:146
idhdl ggetid(const char *n)
Definition ipid.cc:581
EXTERN_VAR omBin sleftv_bin
Definition ipid.h:145
leftv ii_CallLibProcM(const char *n, void **args, int *arg_types, const ring R, BOOLEAN &err)
args: NULL terminated array of arguments arg_types: 0 terminated array of corresponding types
Definition iplib.cc:710
void * iiCallLibProc1(const char *n, void *arg, int arg_type, BOOLEAN &err)
Definition iplib.cc:636
STATIC_VAR jList * T
Definition janet.cc:30
STATIC_VAR Poly * h
Definition janet.cc:971
void p_TakeOutComp(poly *p, long comp, poly *q, int *lq, const ring r)
Definition p_polys.cc:3620
ideal kMin_std2(ideal F, ideal Q, tHomog h, intvec **w, ideal &M, bigintmat *hilb, int syzComp, int reduced)
Definition kstd1.cc:3069
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
ideal kSba(ideal F, ideal Q, tHomog h, intvec **w, int sbaOrder, int arri, bigintmat *hilb, int syzComp, int newIdeal, intvec *vw)
Definition kstd1.cc:2668
poly kNF(ideal F, ideal Q, poly p, int syzComp, int lazyReduce)
Definition kstd1.cc:3229
@ nc_skew
Definition nc.h:16
@ nc_exterior
Definition nc.h:21
static nc_type & ncRingType(nc_struct *p)
Definition nc.h:159
BOOLEAN nc_CheckSubalgebra(poly PolyVar, ring r)
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition matpol.cc:37
matrix mp_MultP(matrix a, poly p, const ring R)
multiply a matrix 'a' by a poly 'p', destroy the args
Definition matpol.cc:141
matrix mp_Copy(matrix a, const ring r)
copies matrix a (from ring r to r)
Definition matpol.cc:57
void mp_MinorToResult(ideal result, int &elems, matrix a, int r, int c, ideal R, const ring)
entries of a are minors and go to result (only if not in R)
Definition matpol.cc:1501
void mp_RecMin(int ar, ideal result, int &elems, matrix a, int lr, int lc, poly barDiv, ideal R, const ring r)
produces recursively the ideal of all arxar-minors of a
Definition matpol.cc:1597
poly mp_DetBareiss(matrix a, const ring r)
returns the determinant of the matrix m; uses Bareiss algorithm
Definition matpol.cc:1670
#define MATELEM(mat, i, j)
1-based access to matrix
Definition matpol.h:29
ip_smatrix * matrix
Definition matpol.h:43
#define MATROWS(i)
Definition matpol.h:26
#define MATCOLS(i)
Definition matpol.h:27
#define assume(x)
Definition mod2.h:389
#define pIter(p)
Definition monomials.h:37
#define pNext(p)
Definition monomials.h:36
#define p_GetCoeff(p, r)
Definition monomials.h:50
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
#define __p_GetComp(p, r)
Definition monomials.h:63
#define nInpNeg(n)
Definition numbers.h:21
#define nCopy(n)
Definition numbers.h:15
#define omStrDup(s)
#define omFreeSize(addr, size)
#define omAlloc(size)
#define omalloc(size)
#define omFree(addr)
#define omAlloc0(size)
#define omFreeBin(addr, bin)
#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 SI_SAVE_OPT(A, B)
Definition options.h:20
#define TEST_OPT_IDLIFT
Definition options.h:131
#define SI_SAVE_OPT2(A)
Definition options.h:22
#define OPT_REDTAIL_SYZ
Definition options.h:88
#define OPT_REDTAIL
Definition options.h:92
#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 SI_RESTORE_OPT2(A)
Definition options.h:25
#define Sy_bit(x)
Definition options.h:31
#define TEST_OPT_RETURN_SB
Definition options.h:114
#define V_PURE_GB
Definition options.h:71
#define TEST_V_INTERSECT_ELIM
Definition options.h:146
#define TEST_V_INTERSECT_SYZ
Definition options.h:147
#define TEST_OPT_NOTREGULARITY
Definition options.h:122
#define TEST_OPT_PROT
Definition options.h:105
#define V_IDLIFT
Definition options.h:63
#define SI_RESTORE_OPT(A, B)
Definition options.h:23
static int index(p_Length length, p_Ord ord)
poly p_DivideM(poly a, poly b, const ring r)
Definition p_polys.cc:1582
poly p_Farey(poly p, number N, const ring r)
Definition p_polys.cc:54
int p_Weight(int i, const ring r)
Definition p_polys.cc:706
void p_Shift(poly *p, int i, const ring r)
shifts components of the vector p by i
Definition p_polys.cc:4860
poly p_PermPoly(poly p, const int *perm, const ring oldRing, const ring dst, nMapFunc nMap, const int *par_perm, int OldPar, BOOLEAN use_mult)
Definition p_polys.cc:4256
poly p_Div_nn(poly p, const number n, const ring r)
Definition p_polys.cc:1506
void p_Norm(poly p1, const ring r)
Definition p_polys.cc:3844
int p_Compare(const poly a, const poly b, const ring R)
Definition p_polys.cc:5050
long p_DegW(poly p, const int *w, const ring R)
Definition p_polys.cc:691
poly p_Vec2Poly(poly v, int k, const ring r)
Definition p_polys.cc:3698
void p_SetModDeg(intvec *w, ring r)
Definition p_polys.cc:3798
int p_Var(poly m, const ring r)
Definition p_polys.cc:4810
poly p_One(const ring r)
Definition p_polys.cc:1314
poly p_Sub(poly p1, poly p2, const ring r)
Definition p_polys.cc:1994
void pEnlargeSet(poly **p, int l, int increment)
Definition p_polys.cc:3821
long p_Deg(poly a, const ring r)
Definition p_polys.cc:586
static poly p_Neg(poly p, const ring r)
Definition p_polys.h:1114
static poly p_Add_q(poly p, poly q, const ring r)
Definition p_polys.h:938
static void p_LmDelete(poly p, const ring r)
Definition p_polys.h:725
static poly p_Mult_q(poly p, poly q, const ring r)
Definition p_polys.h:1125
static long p_SubExp(poly p, int v, long ee, ring r)
Definition p_polys.h:615
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 poly p_Copy_noCheck(poly p, const ring r)
returns a copy of p (without any additional testing)
Definition p_polys.h:838
static number p_SetCoeff(poly p, number n, ring r)
Definition p_polys.h:414
static poly pReverse(poly p)
Definition p_polys.h:337
static BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
Definition p_polys.h:1008
static poly p_Head(const poly p, const ring r)
copy the (leading) term of p
Definition p_polys.h:862
static int p_LmCmp(poly p, poly q, const ring r)
Definition p_polys.h:1601
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition p_polys.h:471
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
static void p_GetExpV(poly p, int *ev, const ring r)
Definition p_polys.h:1541
static poly p_LmFreeAndNext(poly p, ring)
Definition p_polys.h:713
static poly p_Copy(poly p, const ring r)
returns a copy of p
Definition p_polys.h:848
static long p_Totaldegree(poly p, const ring r)
Definition p_polys.h:1528
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).
#define pAdd(p, q)
Definition polys.h:204
#define pTest(p)
Definition polys.h:415
#define pDelete(p_ptr)
Definition polys.h:187
#define ppJet(p, m)
Definition polys.h:367
#define pHead(p)
returns newly allocated copy of Lm(p), coef is copied, next=NULL, p might be NULL
Definition polys.h:68
#define pSetm(p)
Definition polys.h:272
#define pNeg(p)
Definition polys.h:199
#define ppMult_mm(p, m)
Definition polys.h:202
#define pSetCompP(a, i)
Definition polys.h:304
#define pGetComp(p)
Component.
Definition polys.h:38
#define pDiff(a, b)
Definition polys.h:297
#define pSetCoeff(p, n)
deletes old coeff before setting the new one
Definition polys.h:32
#define pVar(m)
Definition polys.h:381
#define pJet(p, m)
Definition polys.h:368
#define pSub(a, b)
Definition polys.h:288
#define pWeight(i)
Definition polys.h:281
#define ppJetW(p, m, iv)
Definition polys.h:369
#define pMaxComp(p)
Definition polys.h:300
#define pSetComp(p, v)
Definition polys.h:39
void wrp(poly p)
Definition polys.h:311
#define pMult(p, q)
Definition polys.h:208
#define pJetW(p, m, iv)
Definition polys.h:370
#define pDiffOp(a, b, m)
Definition polys.h:298
#define pSeries(n, p, u, w)
Definition polys.h:372
#define pGetExp(p, i)
Exponent.
Definition polys.h:42
#define pSetmComp(p)
TODO:
Definition polys.h:274
#define pNormalize(p)
Definition polys.h:318
#define pEqualPolys(p1, p2)
Definition polys.h:400
#define pDivisibleBy(a, b)
returns TRUE, if leading monom of a divides leading monom of b i.e., if there exists a expvector c > ...
Definition polys.h:139
#define pSetExp(p, i, v)
Definition polys.h:43
void pTakeOutComp(poly *p, long comp, poly *q, int *lq, const ring R=currRing)
Splits *p into two polys: *q which consists of all monoms with component == comp and *p of all other ...
Definition polys.h:339
#define pCopy(p)
return a copy of the poly
Definition polys.h:186
#define pOne()
Definition polys.h:316
#define pMinComp(p)
Definition polys.h:301
poly * polyset
Definition polys.h:260
poly prMoveR(poly &p, ring src_r, ring dest_r)
Definition prCopy.cc:90
ideal idrMoveR(ideal &id, ring src_r, ring dest_r)
Definition prCopy.cc:248
poly prCopyR(poly p, ring src_r, ring dest_r)
Definition prCopy.cc:34
ideal idrCopyR(ideal id, ring src_r, ring dest_r)
Definition prCopy.cc:192
ideal idrMoveR_NoSort(ideal &id, ring src_r, ring dest_r)
Definition prCopy.cc:261
poly prMoveR_NoSort(poly &p, ring src_r, ring dest_r)
Definition prCopy.cc:101
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
void Werror(const char *fmt,...)
Definition reporter.cc:189
#define mflush()
Definition reporter.h:58
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 rAssure_SyzComp(const ring r, BOOLEAN complete)
Definition ring.cc:4527
BOOLEAN nc_rComplete(const ring src, ring dest, bool bSetupQuotient)
Definition ring.cc:5833
ring rAssure_Wp_C(const ring r, intvec *w)
Definition ring.cc:4942
ring rAssure_Dp_C(const ring r)
Definition ring.cc:5124
BOOLEAN rOrd_is_Totaldegree_Ordering(const ring r)
Definition ring.cc:2043
ring rAssure_SyzOrder(const ring r, BOOLEAN complete)
Definition ring.cc:4522
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
void rSetSyzComp(int k, const ring r)
Definition ring.cc:5230
ring rAssure_dp_C(const ring r)
Definition ring.cc:5119
static BOOLEAN rHasGlobalOrdering(const ring r)
Definition ring.h:768
static BOOLEAN rIsPluralRing(const ring r)
we must always have this test!
Definition ring.h:406
static int rBlocks(const ring r)
Definition ring.h:574
static BOOLEAN rField_is_Domain(const ring r)
Definition ring.h:493
static BOOLEAN rIsLPRing(const ring r)
Definition ring.h:417
rRingOrder_t
order stuff
Definition ring.h:69
@ ringorder_a
Definition ring.h:71
@ ringorder_a64
for int64 weights
Definition ring.h:72
@ ringorder_C
Definition ring.h:74
@ ringorder_dp
Definition ring.h:79
@ ringorder_c
Definition ring.h:73
@ ringorder_aa
for idElimination, like a, except pFDeg, pWeigths ignore it
Definition ring.h:93
@ ringorder_ws
Definition ring.h:88
@ ringorder_s
s?
Definition ring.h:77
@ ringorder_wp
Definition ring.h:82
static BOOLEAN rField_is_Q(const ring r)
Definition ring.h:512
static BOOLEAN rIsNCRing(const ring r)
Definition ring.h:427
static short rVar(const ring r)
define rVar(r) (r->N)
Definition ring.h:598
#define rField_is_Ring(R)
Definition ring.h:491
#define block
Definition scanner.cc:646
ideal idInit(int idsize, int rank)
initialise an ideal / module
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
ideal id_Homogen(ideal h, int varnum, const ring r)
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 id_DelMultiples(ideal id, const ring r)
ideal id = (id[i]), c any unit if id[i] = c*id[j] then id[j] is deleted for j > i
ideal id_Matrix2Module(matrix mat, const ring R)
converts mat to module, destroys mat
ideal id_SimpleAdd(ideal h1, ideal h2, const ring R)
concat the lists h1 and h2 without zeros
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
void id_Shift(ideal M, int s, const ring r)
ideal id_ChineseRemainder(ideal *xx, number *q, int rl, const ring r)
#define IDELEMS(i)
#define id_Test(A, lR)
static int idElem(const ideal F)
number of non-zero polys in F
#define R
Definition sirandom.c:27
#define M
Definition sirandom.c:25
#define Q
Definition sirandom.c:26
long sm_ExpBound(ideal m, int di, int ra, int t, const ring currRing)
Definition sparsmat.cc:188
ring sm_RingChange(const ring origR, long bound)
Definition sparsmat.cc:258
void sm_KillModifiedRing(ring r)
Definition sparsmat.cc:289
sleftv * leftv
Definition structs.h:53
char * char_ptr
Definition structs.h:49
tHomog
Definition structs.h:31
@ isHomog
Definition structs.h:33
@ testHomog
Definition structs.h:34
@ isNotHomog
Definition structs.h:32
skStrategy * kStrategy
Definition structs.h:54
#define loop
Definition structs.h:71
void syGaussForOne(ideal syz, int elnum, int ModComp, int from, int till)
Definition syz.cc:218
intvec * syBetti(resolvente res, int length, int *regularity, intvec *weights, BOOLEAN tomin, int *row_shift)
Definition syz.cc:787
resolvente sySchreyerResolvente(ideal arg, int maxlength, int *length, BOOLEAN isMonomial=FALSE, BOOLEAN notReplace=FALSE)
Definition syz0.cc:855
ideal t_rep_gb(const ring r, ideal arg_I, int syz_comp, BOOLEAN F4_mode)
Definition tgb.cc:3581
@ INT_CMD
Definition tok.h:96
THREAD_VAR double(* wFunctional)(int *degw, int *lpol, int npol, double *rel, double wx, double wNsqr)
Definition weight.cc:20
void wCall(poly *s, int sl, int *x, double wNsqr, const ring R)
Definition weight.cc:108
double wFunctionalBuch(int *degw, int *lpol, int npol, double *rel, double wx, double wNsqr)
Definition weight0.cc:78