My Project
Loading...
Searching...
No Matches
simpleideals.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
9/* includes */
10
11
12
13#include "misc/auxiliary.h"
14
15#include "misc/options.h"
16#include "misc/intvec.h"
17
18#include "matpol.h"
19
20#include "monomials/p_polys.h"
21#include "weight.h"
22#include "sbuckets.h"
23#include "clapsing.h"
24
25#include "simpleideals.h"
26
28
30/*collects the monomials in makemonoms, must be allocated before*/
32/*index of the actual monomial in idpower*/
33
34/// initialise an ideal / module
35ideal idInit(int idsize, int rank)
36{
37 assume( idsize >= 0 && rank >= 0 );
38
39 ideal hh = (ideal)omAllocBin(sip_sideal_bin);
40
41 IDELEMS(hh) = idsize; // ncols
42 hh->nrows = 1; // ideal/module!
43
44 hh->rank = rank; // ideal: 1, module: >= 0!
45
46 if (idsize>0)
47 hh->m = (poly *)omAlloc0(idsize*sizeof(poly));
48 else
49 hh->m = NULL;
50
51 return hh;
52}
53
54#ifdef PDEBUG
55// this is only for outputting an ideal within the debugger
56// therefore it accept the otherwise illegal id==NULL
57void idShow(const ideal id, const ring lmRing, const ring tailRing, const int debugPrint)
58{
59 assume( debugPrint >= 0 );
60
61 if( id == NULL )
62 PrintS("(NULL)");
63 else
64 {
65 Print("Module of rank %ld,real rank %ld and %d generators.\n",
66 id->rank,id_RankFreeModule(id, lmRing, tailRing),IDELEMS(id));
67
68 int j = (id->ncols*id->nrows) - 1;
69 while ((j > 0) && (id->m[j]==NULL)) j--;
70 for (int i = 0; i <= j; i++)
71 {
72 Print("generator %d: ",i); p_wrp(id->m[i], lmRing, tailRing);PrintLn();
73 }
74 }
75}
76#endif
77
78/// index of generator with leading term in ground ring (if any);
79/// otherwise -1
80int id_PosConstant(ideal id, const ring r)
81{
82 id_Test(id, r);
83 const int N = IDELEMS(id) - 1;
84 const poly * m = id->m + N;
85
86 for (int k = N; k >= 0; --k, --m)
87 {
88 const poly p = *m;
89 if (p!=NULL)
90 if (p_LmIsConstantComp(p, r) == TRUE)
91 return k;
92 }
93
94 return -1;
95}
96
97/// initialise the maximal ideal (at 0)
98ideal id_MaxIdeal (const ring r)
99{
100 int nvars;
101#ifdef HAVE_SHIFTBBA
102 if (r->isLPring)
103 {
104 nvars = r->isLPring;
105 }
106 else
107#endif
108 {
109 nvars = rVar(r);
110 }
111 ideal hh = idInit(nvars, 1);
112 for (int l=nvars-1; l>=0; l--)
113 {
114 hh->m[l] = p_One(r);
115 p_SetExp(hh->m[l],l+1,1,r);
116 p_Setm(hh->m[l],r);
117 }
118 id_Test(hh, r);
119 return hh;
120}
121
122/// deletes an ideal/module/matrix
123void id_Delete (ideal * h, ring r)
124{
125 if (*h == NULL)
126 return;
127
128 id_Test(*h, r);
129
130 const long elems = (long)(*h)->nrows * (long)(*h)->ncols;
131
132 if ( elems > 0 )
133 {
134 assume( (*h)->m != NULL );
135
136 if (r!=NULL)
137 {
138 long j = elems;
139 do
140 {
141 j--;
142 poly pp=((*h)->m[j]);
143 if (pp!=NULL) p_Delete(&pp, r);
144 }
145 while (j>0);
146 }
147
148 omFreeSize((ADDRESS)((*h)->m),sizeof(poly)*elems);
149 }
150
152 *h=NULL;
153}
154
155void id_Delete0 (ideal * h, ring r)
156{
157 long j = IDELEMS(*h);
158
159 if(j>0)
160 {
161 do
162 {
163 j--;
164 poly pp=((*h)->m[j]);
165 if (pp!=NULL) p_Delete(&pp, r);
166 }
167 while (j>0);
168 omFree((ADDRESS)((*h)->m));
169 }
170
172 *h=NULL;
173}
174
175
176/// Shallowdeletes an ideal/matrix
177void id_ShallowDelete (ideal *h, ring r)
178{
179 id_Test(*h, r);
180
181 if (*h == NULL)
182 return;
183
184 int j,elems;
185 elems=j=(*h)->nrows*(*h)->ncols;
186 if (j>0)
187 {
188 assume( (*h)->m != NULL );
189 do
190 {
191 p_ShallowDelete(&((*h)->m[--j]), r);
192 }
193 while (j>0);
194 omFreeSize((ADDRESS)((*h)->m),sizeof(poly)*elems);
195 }
197 *h=NULL;
198}
199
200/// gives an ideal/module the minimal possible size
201void idSkipZeroes (ideal ide)
202{
203 if(ide!=NULL)
204 {
205 int k;
206 int j = -1;
207 int idelems=IDELEMS(ide);
208 BOOLEAN change=FALSE;
209
210 for (k=0; k<idelems; k++)
211 {
212 if (ide->m[k] != NULL)
213 {
214 j++;
215 if (change)
216 {
217 ide->m[j] = ide->m[k];
218 ide->m[k] = NULL;
219 }
220 }
221 else
222 {
223 change=TRUE;
224 }
225 }
226 if (change)
227 {
228 if (j == -1)
229 j = 0;
230 j++;
231 pEnlargeSet(&(ide->m),idelems,j-idelems);
232 IDELEMS(ide) = j;
233 }
234 }
235}
236
237int idSkipZeroes0 (ideal ide) /*idSkipZeroes without realloc*/
238{
239 assume (ide != NULL);
240
241 int k;
242 int j = -1;
243 int idelems=IDELEMS(ide);
244
245 k=0;
246 while((k<idelems)&&(ide->m[k] != NULL)) k++;
247 if (k==idelems) return idelems;
248 // now: k: pos of first NULL entry
249 j=k; k=k+1;
250 for (; k<idelems; k++)
251 {
252 if (ide->m[k] != NULL)
253 {
254 ide->m[j] = ide->m[k];
255 ide->m[k] = NULL;
256 j++;
257 }
258 }
259 if (j<=1) return 1;
260 return j;
261}
262
263/// copies the first k (>= 1) entries of the given ideal/module
264/// and returns these as a new ideal/module
265/// (Note that the copied entries may be zero.)
266ideal id_CopyFirstK (const ideal ide, const int k,const ring r)
267{
268 id_Test(ide, r);
269
270 assume( ide != NULL );
271 assume( k <= IDELEMS(ide) );
272
273 ideal newI = idInit(k, ide->rank);
274
275 for (int i = 0; i < k; i++)
276 newI->m[i] = p_Copy(ide->m[i],r);
277
278 return newI;
279}
280
281/// ideal id = (id[i]), result is leadcoeff(id[i]) = 1
282void id_Norm(ideal id, const ring r)
283{
284 id_Test(id, r);
285 for (int i=IDELEMS(id)-1; i>=0; i--)
286 {
287 if (id->m[i] != NULL)
288 {
289 p_Norm(id->m[i],r);
290 }
291 }
292}
293
294/// ideal id = (id[i]), c any unit
295/// if id[i] = c*id[j] then id[j] is deleted for j > i
296void id_DelMultiples(ideal id, const ring r)
297{
298 id_Test(id, r);
299
300 int i, j;
301 int k = IDELEMS(id)-1;
302 for (i=k; i>=0; i--)
303 {
304 if (id->m[i]!=NULL)
305 {
306 for (j=k; j>i; j--)
307 {
308 if (id->m[j]!=NULL)
309 {
310 if (rField_is_Ring(r))
311 {
312 /* if id[j] = c*id[i] then delete id[j].
313 In the below cases of a ground field, we
314 check whether id[i] = c*id[j] and, if so,
315 delete id[j] for historical reasons (so
316 that previous output does not change) */
317 if (p_ComparePolys(id->m[j], id->m[i],r)) p_Delete(&id->m[j],r);
318 }
319 else
320 {
321 if (p_ComparePolys(id->m[i], id->m[j],r)) p_Delete(&id->m[j],r);
322 }
323 }
324 }
325 }
326 }
327}
328
329/// ideal id = (id[i])
330/// if id[i] = id[j] then id[j] is deleted for j > i
331void id_DelEquals(ideal id, const ring r)
332{
333 id_Test(id, r);
334
335 int i, j;
336 int k = IDELEMS(id)-1;
337 for (i=k; i>=0; i--)
338 {
339 if (id->m[i]!=NULL)
340 {
341 for (j=k; j>i; j--)
342 {
343 if ((id->m[j]!=NULL)
344 && (p_EqualPolys(id->m[i], id->m[j],r)))
345 {
346 p_Delete(&id->m[j],r);
347 }
348 }
349 }
350 }
351}
352
353/// Delete id[j], if Lm(j) == Lm(i) and both LC(j), LC(i) are units and j > i
354void id_DelLmEquals(ideal id, const ring r)
355{
356 id_Test(id, r);
357
358 int i, j;
359 int k = IDELEMS(id)-1;
360 for (i=k; i>=0; i--)
361 {
362 if (id->m[i] != NULL)
363 {
364 for (j=k; j>i; j--)
365 {
366 if ((id->m[j] != NULL)
367 && p_LmEqual(id->m[i], id->m[j],r)
368#ifdef HAVE_RINGS
369 && n_IsUnit(pGetCoeff(id->m[i]),r->cf) && n_IsUnit(pGetCoeff(id->m[j]),r->cf)
370#endif
371 )
372 {
373 p_Delete(&id->m[j],r);
374 }
375 }
376 }
377 }
378}
379
380/// delete id[j], if LT(j) == coeff*mon*LT(i)
381static void id_DelDiv_SEV(ideal id, int k,const ring r)
382{
383 int kk = k+1;
384 long *sev=(long*)omAlloc0(kk*sizeof(long));
385 while(id->m[k]==NULL) k--;
386 BOOLEAN only_lm=r->cf->has_simple_Alloc;
387 if (only_lm)
388 {
389 for (int i=k; i>=0; i--)
390 {
391 if((id->m[i]!=NULL) && (pNext(id->m[i])!=NULL))
392 {
393 only_lm=FALSE;
394 break;
395 }
396 }
397 }
398 for (int i=k; i>=0; i--)
399 {
400 if(id->m[i]!=NULL)
401 {
402 sev[i]=p_GetShortExpVector(id->m[i],r);
403 }
404 }
405 if (only_lm)
406 {
407 for (int i=0; i<k; i++)
408 {
409 if (id->m[i] != NULL)
410 {
411 poly m_i=id->m[i];
412 long sev_i=sev[i];
413 for (int j=i+1; j<=k; j++)
414 {
415 if (id->m[j]!=NULL)
416 {
417 if (p_LmShortDivisibleBy(m_i, sev_i,id->m[j],~sev[j],r))
418 {
419 p_LmFree(&id->m[j],r);
420 }
421 else if (p_LmShortDivisibleBy(id->m[j],sev[j], m_i,~sev_i,r))
422 {
423 p_LmFree(&id->m[i],r);
424 break;
425 }
426 }
427 }
428 }
429 }
430 }
431 else
432 {
433 for (int i=0; i<k; i++)
434 {
435 if (id->m[i] != NULL)
436 {
437 poly m_i=id->m[i];
438 long sev_i=sev[i];
439 for (int j=i+1; j<=k; j++)
440 {
441 if (id->m[j]!=NULL)
442 {
443 if (p_LmShortDivisibleBy(m_i, sev_i, id->m[j],~sev[j],r))
444 {
445 p_Delete(&id->m[j],r);
446 }
447 else if (p_LmShortDivisibleBy(id->m[j],sev[j], m_i,~sev_i,r))
448 {
449 p_Delete(&id->m[i],r);
450 break;
451 }
452 }
453 }
454 }
455 }
456 }
457 omFreeSize(sev,kk*sizeof(long));
458}
459
460
461/// delete id[j], if LT(j) == coeff*mon*LT(i) and vice versa, i.e.,
462/// delete id[i], if LT(i) == coeff*mon*LT(j)
463void id_DelDiv(ideal id, const ring r)
464{
465 id_Test(id, r);
466
467 int i, j;
468 int k = IDELEMS(id)-1;
469#ifdef HAVE_RINGS
470 if (rField_is_Ring(r))
471 {
472 for (i=k-1; i>=0; i--)
473 {
474 if (id->m[i] != NULL)
475 {
476 for (j=k; j>i; j--)
477 {
478 if (id->m[j]!=NULL)
479 {
480 if (p_DivisibleByRingCase(id->m[i], id->m[j],r))
481 {
482 p_Delete(&id->m[j],r);
483 }
484 else if (p_DivisibleByRingCase(id->m[j], id->m[i],r))
485 {
486 p_Delete(&id->m[i],r);
487 break;
488 }
489 }
490 }
491 }
492 }
493 }
494 else
495#endif
496 {
497 /* the case of a coefficient field: */
498 if (k>9)
499 {
500 id_DelDiv_SEV(id,k,r);
501 return;
502 }
503 for (i=k-1; i>=0; i--)
504 {
505 if (id->m[i] != NULL)
506 {
507 for (j=k; j>i; j--)
508 {
509 if (id->m[j]!=NULL)
510 {
511 if (p_LmDivisibleBy(id->m[i], id->m[j],r))
512 {
513 p_Delete(&id->m[j],r);
514 }
515 else if (p_LmDivisibleBy(id->m[j], id->m[i],r))
516 {
517 p_Delete(&id->m[i],r);
518 break;
519 }
520 }
521 }
522 }
523 }
524 }
525}
526
527/// test if the ideal has only constant polynomials
528/// NOTE: zero ideal/module is also constant
529BOOLEAN id_IsConstant(ideal id, const ring r)
530{
531 id_Test(id, r);
532
533 for (int k = IDELEMS(id)-1; k>=0; k--)
534 {
535 if (!p_IsConstantPoly(id->m[k],r))
536 return FALSE;
537 }
538 return TRUE;
539}
540
541/// copy an ideal
542ideal id_Copy(ideal h1, const ring r)
543{
544 id_Test(h1, r);
545
546 ideal h2 = idInit(IDELEMS(h1), h1->rank);
547 for (int i=IDELEMS(h1)-1; i>=0; i--)
548 h2->m[i] = p_Copy(h1->m[i],r);
549 return h2;
550}
551
552#ifdef PDEBUG
553/// Internal verification for ideals/modules and dense matrices!
554void id_DBTest(ideal h1, int level, const char *f,const int l, const ring r, const ring tailRing)
555{
556 if (h1 != NULL)
557 {
558 // assume(IDELEMS(h1) > 0); for ideal/module, does not apply to matrix
559 omCheckAddrSize(h1,sizeof(*h1));
560
561 assume( h1->ncols >= 0 );
562 assume( h1->nrows >= 0 ); // matrix case!
563
564 assume( h1->rank >= 0 );
565
566 const long n = ((long)h1->ncols * (long)h1->nrows);
567
568 assume( !( n > 0 && h1->m == NULL) );
569
570 if( h1->m != NULL && n > 0 )
571 omdebugAddrSize(h1->m, n * sizeof(poly));
572
573 long new_rk = 0; // inlining id_RankFreeModule(h1, r, tailRing);
574
575 /* to be able to test matrices: */
576 for (long i=n - 1; i >= 0; i--)
577 {
578 _pp_Test(h1->m[i], r, tailRing, level);
579 const long k = p_MaxComp(h1->m[i], r, tailRing);
580 if (k > new_rk) new_rk = k;
581 }
582
583 // dense matrices only contain polynomials:
584 // h1->nrows == h1->rank > 1 && new_rk == 0!
585 assume( !( h1->nrows == h1->rank && h1->nrows > 1 && new_rk > 0 ) ); //
586
587 if(new_rk > h1->rank)
588 {
589 dReportError("wrong rank %d (should be %d) in %s:%d\n",
590 h1->rank, new_rk, f,l);
591 omPrintAddrInfo(stderr, h1, " for ideal");
592 h1->rank = new_rk;
593 }
594 }
595 else
596 {
597 Print("error: ideal==NULL in %s:%d\n",f,l);
598 assume( h1 != NULL );
599 }
600}
601#endif
602
603#ifdef PDEBUG
604/// Internal verification for ideals/modules and dense matrices!
605void id_DBLmTest(ideal h1, int level, const char *f,const int l, const ring r)
606{
607 if (h1 != NULL)
608 {
609 // assume(IDELEMS(h1) > 0); for ideal/module, does not apply to matrix
610 omCheckAddrSize(h1,sizeof(*h1));
611
612 assume( h1->ncols >= 0 );
613 assume( h1->nrows >= 0 ); // matrix case!
614
615 assume( h1->rank >= 0 );
616
617 const long n = ((long)h1->ncols * (long)h1->nrows);
618
619 assume( !( n > 0 && h1->m == NULL) );
620
621 if( h1->m != NULL && n > 0 )
622 omdebugAddrSize(h1->m, n * sizeof(poly));
623
624 long new_rk = 0; // inlining id_RankFreeModule(h1, r, tailRing);
625
626 /* to be able to test matrices: */
627 for (long i=n - 1; i >= 0; i--)
628 {
629 if (h1->m[i]!=NULL)
630 {
631 _p_LmTest(h1->m[i], r, level);
632 const long k = p_GetComp(h1->m[i], r);
633 if (k > new_rk) new_rk = k;
634 }
635 }
636
637 // dense matrices only contain polynomials:
638 // h1->nrows == h1->rank > 1 && new_rk == 0!
639 assume( !( h1->nrows == h1->rank && h1->nrows > 1 && new_rk > 0 ) ); //
640
641 if(new_rk > h1->rank)
642 {
643 dReportError("wrong rank %d (should be %d) in %s:%d\n",
644 h1->rank, new_rk, f,l);
645 omPrintAddrInfo(stderr, h1, " for ideal");
646 h1->rank = new_rk;
647 }
648 }
649 else
650 {
651 Print("error: ideal==NULL in %s:%d\n",f,l);
652 assume( h1 != NULL );
653 }
654}
655#endif
656
657/// for idSort: compare a and b revlex inclusive module comp.
658static int p_Comp_RevLex(poly a, poly b,BOOLEAN nolex, const ring R)
659{
660 if (b==NULL) return 1;
661 if (a==NULL) return -1;
662
663 if (nolex)
664 {
665 int r=p_LtCmp(a,b,R);
666 return r;
667 #if 0
668 if (r!=0) return r;
669 number h=n_Sub(pGetCoeff(a),pGetCoeff(b),R->cf);
670 r = -1+n_IsZero(h,R->cf)+2*n_GreaterZero(h,R->cf); /* -1: <, 0:==, 1: > */
671 n_Delete(&h, R->cf);
672 return r;
673 #endif
674 }
675 int l=rVar(R);
676 while ((l>0) && (p_GetExp(a,l,R)==p_GetExp(b,l,R))) l--;
677 if (l==0)
678 {
679 if (p_GetComp(a,R)==p_GetComp(b,R))
680 {
681 number h=n_Sub(pGetCoeff(a),pGetCoeff(b),R->cf);
682 int r = -1+n_IsZero(h,R->cf)+2*n_GreaterZero(h,R->cf); /* -1: <, 0:==, 1: > */
683 n_Delete(&h,R->cf);
684 return r;
685 }
686 if (p_GetComp(a,R)>p_GetComp(b,R)) return 1;
687 }
688 else if (p_GetExp(a,l,R)>p_GetExp(b,l,R))
689 return 1;
690 return -1;
691}
692
693// sorts the ideal w.r.t. the actual ringordering
694// uses lex-ordering when nolex = FALSE
695intvec *id_Sort(const ideal id, const BOOLEAN nolex, const ring r)
696{
697 id_Test(id, r);
698
699 intvec * result = new intvec(IDELEMS(id));
700 int i, j, actpos=0, newpos;
701 int diff, olddiff, lastcomp, newcomp;
702 BOOLEAN notFound;
703
704 for (i=0;i<IDELEMS(id);i++)
705 {
706 if (id->m[i]!=NULL)
707 {
708 notFound = TRUE;
709 newpos = actpos / 2;
710 diff = (actpos+1) / 2;
711 diff = (diff+1) / 2;
712 lastcomp = p_Comp_RevLex(id->m[i],id->m[(*result)[newpos]],nolex,r);
713 if (lastcomp<0)
714 {
715 newpos -= diff;
716 }
717 else if (lastcomp>0)
718 {
719 newpos += diff;
720 }
721 else
722 {
723 notFound = FALSE;
724 }
725 //while ((newpos>=0) && (newpos<actpos) && (notFound))
726 while (notFound && (newpos>=0) && (newpos<actpos))
727 {
728 newcomp = p_Comp_RevLex(id->m[i],id->m[(*result)[newpos]],nolex,r);
729 olddiff = diff;
730 if (diff>1)
731 {
732 diff = (diff+1) / 2;
733 if ((newcomp==1)
734 && (actpos-newpos>1)
735 && (diff>1)
736 && (newpos+diff>=actpos))
737 {
738 diff = actpos-newpos-1;
739 }
740 else if ((newcomp==-1)
741 && (diff>1)
742 && (newpos<diff))
743 {
744 diff = newpos;
745 }
746 }
747 if (newcomp<0)
748 {
749 if ((olddiff==1) && (lastcomp>0))
750 notFound = FALSE;
751 else
752 newpos -= diff;
753 }
754 else if (newcomp>0)
755 {
756 if ((olddiff==1) && (lastcomp<0))
757 {
758 notFound = FALSE;
759 newpos++;
760 }
761 else
762 {
763 newpos += diff;
764 }
765 }
766 else
767 {
768 notFound = FALSE;
769 }
770 lastcomp = newcomp;
771 if (diff==0) notFound=FALSE; /*hs*/
772 }
773 if (newpos<0) newpos = 0;
774 if (newpos>actpos) newpos = actpos;
775 while ((newpos<actpos) && (p_Comp_RevLex(id->m[i],id->m[(*result)[newpos]],nolex,r)==0))
776 newpos++;
777 for (j=actpos;j>newpos;j--)
778 {
779 (*result)[j] = (*result)[j-1];
780 }
781 (*result)[newpos] = i;
782 actpos++;
783 }
784 }
785 for (j=0;j<actpos;j++) (*result)[j]++;
786 return result;
787}
788
789/// concat the lists h1 and h2 without zeros
790ideal id_SimpleAdd (ideal h1,ideal h2, const ring R)
791{
792 id_Test(h1, R);
793 id_Test(h2, R);
794
795 if ( idIs0(h1) )
796 {
797 ideal res=id_Copy(h2,R);
798 if (res->rank<h1->rank) res->rank=h1->rank;
799 return res;
800 }
801 if ( idIs0(h2) )
802 {
803 ideal res=id_Copy(h1,R);
804 if (res->rank<h2->rank) res->rank=h2->rank;
805 return res;
806 }
807
808 int j = IDELEMS(h1)-1;
809 while ((j >= 0) && (h1->m[j] == NULL)) j--;
810
811 int i = IDELEMS(h2)-1;
812 while ((i >= 0) && (h2->m[i] == NULL)) i--;
813
814 const int r = si_max(h1->rank, h2->rank);
815
816 ideal result = idInit(i+j+2,r);
817
818 int l;
819
820 for (l=j; l>=0; l--)
821 result->m[l] = p_Copy(h1->m[l],R);
822
823 j = i+j+1;
824 for (l=i; l>=0; l--, j--)
825 result->m[j] = p_Copy(h2->m[l],R);
826
827 return result;
828}
829
830/// concat the lists h1 and h2 without zeros, destroys h1,h2
831ideal id_SimpleMove (ideal h1,ideal h2, const ring R)
832{
833 if ( idIs0(h1) )
834 {
835 ideal res=h2;
836 if (res->rank<h1->rank) res->rank=h1->rank;
837 id_Delete(&h1,R);
838 return res;
839 }
840 if ( idIs0(h2) )
841 {
842 ideal res=h1;
843 if (res->rank<h2->rank) res->rank=h2->rank;
844 id_Delete(&h2,R);
845 return res;
846 }
847
848 int j = IDELEMS(h1)-1;
849 while ((j >= 0) && (h1->m[j] == NULL)) j--;
850
851 int i = IDELEMS(h2)-1;
852 while ((i >= 0) && (h2->m[i] == NULL)) i--;
853
854 const int r = si_max(h1->rank, h2->rank);
855
856 ideal result = idInit(i+j+2,r);
857
858 int l;
859
860 for (l=j; l>=0; l--)
861 {
862 result->m[l] = h1->m[l];
863 h1->m[l] = NULL;
864 }
865
866 j = i+j+1;
867 for (l=i; l>=0; l--, j--)
868 {
869 result->m[j] = h2->m[l];
870 h2->m[l] = NULL;
871 }
872
873 id_Delete(&h1,R);
874 id_Delete(&h2,R);
875 return result;
876}
877
878/// insert h2 into h1 (if h2 is not the zero polynomial)
879/// return TRUE iff h2 was indeed inserted
880BOOLEAN idInsertPoly (ideal h1, poly h2)
881{
882 if (h2==NULL) return FALSE;
883 assume (h1 != NULL);
884
885 int j = IDELEMS(h1) - 1;
886
887 while ((j >= 0) && (h1->m[j] == NULL)) j--;
888 j++;
889 if (j==IDELEMS(h1))
890 {
891 pEnlargeSet(&(h1->m),IDELEMS(h1),16);
892 IDELEMS(h1)+=16;
893 }
894 h1->m[j]=h2;
895 return TRUE;
896}
897
898/// insert p into I on position pos
899BOOLEAN idInsertPolyOnPos (ideal I, poly p,int pos)
900{
901 if (p==NULL) return FALSE;
902 assume (I != NULL);
903
904 int j = IDELEMS(I) - 1;
905
906 while ((j >= 0) && (I->m[j] == NULL)) j--;
907 j++;
908 if (j==IDELEMS(I))
909 {
910 pEnlargeSet(&(I->m),IDELEMS(I),IDELEMS(I)+1);
911 IDELEMS(I)+=1;
912 }
913 for(j = IDELEMS(I)-1;j>pos;j--)
914 I->m[j] = I->m[j-1];
915 I->m[pos]=p;
916 return TRUE;
917}
918
919
920/*! insert h2 into h1 depending on the two boolean parameters:
921 * - if zeroOk is true, then h2 will also be inserted when it is zero
922 * - if duplicateOk is true, then h2 will also be inserted when it is
923 * already present in h1
924 * return TRUE iff h2 was indeed inserted
925 */
926BOOLEAN id_InsertPolyWithTests (ideal h1, const int validEntries,
927 const poly h2, const bool zeroOk, const bool duplicateOk, const ring r)
928{
929 id_Test(h1, r);
930 p_Test(h2, r);
931
932 if ((!zeroOk) && (h2 == NULL)) return FALSE;
933 if (!duplicateOk)
934 {
935 bool h2FoundInH1 = false;
936 int i = 0;
937 while ((i < validEntries) && (!h2FoundInH1))
938 {
939 h2FoundInH1 = p_EqualPolys(h1->m[i], h2,r);
940 i++;
941 }
942 if (h2FoundInH1) return FALSE;
943 }
944 if (validEntries == IDELEMS(h1))
945 {
946 pEnlargeSet(&(h1->m), IDELEMS(h1), 16);
947 IDELEMS(h1) += 16;
948 }
949 h1->m[validEntries] = h2;
950 return TRUE;
951}
952
953/// h1 + h2
954ideal id_Add (ideal h1,ideal h2, const ring r)
955{
956 id_Test(h1, r);
957 id_Test(h2, r);
958
959 ideal result = id_SimpleAdd(h1,h2,r);
961 return result;
962}
963
964/// h1 * h2
965/// one h_i must be an ideal (with at least one column)
966/// the other h_i may be a module (with no columns at all)
967ideal id_Mult (ideal h1,ideal h2, const ring R)
968{
969 id_Test(h1, R);
970 id_Test(h2, R);
971
972 int j = IDELEMS(h1);
973 while ((j > 0) && (h1->m[j-1] == NULL)) j--;
974
975 int i = IDELEMS(h2);
976 while ((i > 0) && (h2->m[i-1] == NULL)) i--;
977
978 j *= i;
979 int r = si_max( h2->rank, h1->rank );
980 if (j==0)
981 {
982 if ((IDELEMS(h1)>0) && (IDELEMS(h2)>0)) j=1;
983 return idInit(j, r);
984 }
985 ideal hh = idInit(j, r);
986
987 int k = 0;
988 for (i=0; i<IDELEMS(h1); i++)
989 {
990 if (h1->m[i] != NULL)
991 {
992 for (j=0; j<IDELEMS(h2); j++)
993 {
994 if (h2->m[j] != NULL)
995 {
996 hh->m[k] = pp_Mult_qq(h1->m[i],h2->m[j],R);
997 k++;
998 }
999 }
1000 }
1001 }
1002
1003 id_Compactify(hh,R);
1004 return hh;
1005}
1006
1007/// returns true if h is the zero ideal
1009{
1010 if ((h!=NULL) && (h->m!=NULL))
1011 {
1012 for( int i = IDELEMS(h)-1; i >= 0; i-- )
1013 if(h->m[i] != NULL)
1014 return FALSE;
1015 }
1016 return TRUE;
1017}
1018
1019/// returns true if h is generated by monomials
1021{
1022 assume (h != NULL);
1023
1024 BOOLEAN found_mon=FALSE;
1025 if (h->m!=NULL)
1026 {
1027 for( int i = IDELEMS(h)-1; i >= 0; i-- )
1028 {
1029 if(h->m[i] != NULL)
1030 {
1031 if(pNext(h->m[i])!=NULL) return FALSE;
1032 found_mon=TRUE;
1033 }
1034 }
1035 }
1036 return found_mon;
1037}
1038
1039/// returns true if F in R/Q has a "simple" GB
1040BOOLEAN idIsSimpleGB (ideal F, ideal Q)
1041{
1042 assume (F != NULL);
1043 int non_zero=0;
1044 int triple=0;
1045
1046 if (LIKELY(F->m!=NULL))
1047 {
1048 for( int i = IDELEMS(F)-1; i >= 0; i-- )
1049 {
1050 poly p;
1051 if((p=F->m[i]) != NULL)
1052 {
1053 non_zero++;
1054 if (Q!=NULL) return FALSE;
1055 if(pNext(p)!=NULL)
1056 {
1057 if(pNext(pNext(p))!=NULL)
1058 {
1059 triple++;
1060 if (non_zero>1) return FALSE;
1061 }
1062 }
1063 }
1064 }
1065 }
1066 if (non_zero<=1) return TRUE; // no zerodivisors
1067 if (triple>1) return FALSE;
1068 if ((triple==1)&&(non_zero>1)) return FALSE;
1069 return TRUE;
1070}
1071
1072/// return the maximal component number found in any polynomial in s
1073long id_RankFreeModule (ideal s, ring lmRing, ring tailRing)
1074{
1075 long j = 0;
1076
1077 if (rRing_has_Comp(tailRing) && rRing_has_Comp(lmRing))
1078 {
1079 poly *p=s->m;
1080 for (unsigned int l=IDELEMS(s); l > 0; --l, ++p)
1081 if (*p != NULL)
1082 {
1083 pp_Test(*p, lmRing, tailRing);
1084 const long k = p_MaxComp(*p, lmRing, tailRing);
1085 if (k>j) j = k;
1086 }
1087 }
1088
1089 return j; // return -1;
1090}
1091
1092BOOLEAN id_IsModule(ideal A, const ring src)
1093{
1094 if ((src->VarOffset[0]== -1)
1095 || (src->pCompIndex<0))
1096 return FALSE; // ring without components
1097 for (int i=IDELEMS(A)-1;i>=0;i--)
1098 {
1099 if (A->m[i]!=NULL)
1100 {
1101 if (p_GetComp(A->m[i],src)>0)
1102 return TRUE;
1103 else
1104 return FALSE;
1105 }
1106 }
1107 return A->rank>1;
1108}
1109
1110
1111/*2
1112*returns true if id is homogeneous with respect to the actual weights
1113*/
1114BOOLEAN id_HomIdeal (ideal id, ideal Q, const ring r)
1115{
1116 int i;
1117 BOOLEAN b;
1118 i = 0;
1119 b = TRUE;
1120 while ((i < IDELEMS(id)) && b)
1121 {
1122 b = p_IsHomogeneous(id->m[i],r);
1123 i++;
1124 }
1125 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1126 {
1127 i=0;
1128 while ((i < IDELEMS(Q)) && b)
1129 {
1130 b = p_IsHomogeneous(Q->m[i],r);
1131 i++;
1132 }
1133 }
1134 return b;
1135}
1136
1137/*2
1138*returns true if id is homogeneous with respect to totaldegree
1139*/
1140BOOLEAN id_HomIdealDP (ideal id, ideal Q, const ring r)
1141{
1142 int i;
1143 BOOLEAN b;
1144 i = 0;
1145 b = TRUE;
1146 while ((i < IDELEMS(id)) && b)
1147 {
1148 b = p_IsHomogeneousDP(id->m[i],r);
1149 i++;
1150 }
1151 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1152 {
1153 i=0;
1154 while ((i < IDELEMS(Q)) && b)
1155 {
1156 b = p_IsHomogeneousDP(Q->m[i],r);
1157 i++;
1158 }
1159 }
1160 return b;
1161}
1162
1163BOOLEAN id_HomIdealW (ideal id, ideal Q, const intvec *w, const ring r)
1164{
1165 int i;
1166 BOOLEAN b;
1167 i = 0;
1168 b = TRUE;
1169 while ((i < IDELEMS(id)) && b)
1170 {
1171 b = p_IsHomogeneousW(id->m[i],w,r);
1172 i++;
1173 }
1174 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1175 {
1176 i=0;
1177 while ((i < IDELEMS(Q)) && b)
1178 {
1179 b = p_IsHomogeneousW(Q->m[i],w,r);
1180 i++;
1181 }
1182 }
1183 return b;
1184}
1185
1186BOOLEAN id_HomModuleW (ideal id, ideal Q, const intvec *w, const intvec *module_w, const ring r)
1187{
1188 int i;
1189 BOOLEAN b;
1190 i = 0;
1191 b = TRUE;
1192 while ((i < IDELEMS(id)) && b)
1193 {
1194 b = p_IsHomogeneousW(id->m[i],w,module_w,r);
1195 i++;
1196 }
1197 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1198 {
1199 i=0;
1200 while ((i < IDELEMS(Q)) && b)
1201 {
1202 b = p_IsHomogeneousW(Q->m[i],w,r);
1203 i++;
1204 }
1205 }
1206 return b;
1207}
1208
1209/*2
1210*initialized a field with r numbers between beg and end for the
1211*procedure idNextChoise
1212*/
1213void idInitChoise (int r,int beg,int end,BOOLEAN *endch,int * choise)
1214{
1215 /*returns the first choise of r numbers between beg and end*/
1216 int i;
1217 for (i=0; i<r; i++)
1218 {
1219 choise[i] = 0;
1220 }
1221 if (r <= end-beg+1)
1222 for (i=0; i<r; i++)
1223 {
1224 choise[i] = beg+i;
1225 }
1226 if (r > end-beg+1)
1227 *endch = TRUE;
1228 else
1229 *endch = FALSE;
1230}
1231
1232/*2
1233*returns the next choise of r numbers between beg and end
1234*/
1235void idGetNextChoise (int r,int end,BOOLEAN *endch,int * choise)
1236{
1237 int i = r-1,j;
1238 while ((i >= 0) && (choise[i] == end))
1239 {
1240 i--;
1241 end--;
1242 }
1243 if (i == -1)
1244 *endch = TRUE;
1245 else
1246 {
1247 choise[i]++;
1248 for (j=i+1; j<r; j++)
1249 {
1250 choise[j] = choise[i]+j-i;
1251 }
1252 *endch = FALSE;
1253 }
1254}
1255
1256/*2
1257*takes the field choise of d numbers between beg and end, cancels the t-th
1258*entree and searches for the ordinal number of that d-1 dimensional field
1259* w.r.t. the algorithm of construction
1260*/
1261int idGetNumberOfChoise(int t, int d, int begin, int end, int * choise)
1262{
1263 int * localchoise,i,result=0;
1264 BOOLEAN b=FALSE;
1265
1266 if (d<=1) return 1;
1267 localchoise=(int*)omAlloc((d-1)*sizeof(int));
1268 idInitChoise(d-1,begin,end,&b,localchoise);
1269 while (!b)
1270 {
1271 result++;
1272 i = 0;
1273 while ((i<t) && (localchoise[i]==choise[i])) i++;
1274 if (i>=t)
1275 {
1276 i = t+1;
1277 while ((i<d) && (localchoise[i-1]==choise[i])) i++;
1278 if (i>=d)
1279 {
1280 omFreeSize((ADDRESS)localchoise,(d-1)*sizeof(int));
1281 return result;
1282 }
1283 }
1284 idGetNextChoise(d-1,end,&b,localchoise);
1285 }
1286 omFreeSize((ADDRESS)localchoise,(d-1)*sizeof(int));
1287 return 0;
1288}
1289
1290/*2
1291*computes the binomial coefficient
1292*/
1293int binom (int n,int r)
1294{
1295 int i;
1296 int64 result;
1297
1298 if (r==0) return 1;
1299 if (n-r<r) return binom(n,n-r);
1300 result = n-r+1;
1301 for (i=2;i<=r;i++)
1302 {
1303 result *= n-r+i;
1304 result /= i;
1305 }
1306 if (result>MAX_INT_VAL)
1307 {
1308 WarnS("overflow in binomials");
1309 result=0;
1310 }
1311 return (int)result;
1312}
1313
1314
1315/// the free module of rank i
1316ideal id_FreeModule (int i, const ring r)
1317{
1318 assume(i >= 0);
1319 if (r->isLPring)
1320 {
1321 PrintS("In order to address bimodules, the command freeAlgebra should be used.");
1322 }
1323 ideal h = idInit(i, i);
1324
1325 for (int j=0; j<i; j++)
1326 {
1327 h->m[j] = p_One(r);
1328 p_SetComp(h->m[j],j+1,r);
1329 p_SetmComp(h->m[j],r);
1330 }
1331
1332 return h;
1333}
1334
1335/*2
1336*computes recursively all monomials of a certain degree
1337*in every step the actvar-th entry in the exponential
1338*vector is incremented and the other variables are
1339*computed by recursive calls of makemonoms
1340*if the last variable is reached, the difference to the
1341*degree is computed directly
1342*vars is the number variables
1343*actvar is the actual variable to handle
1344*deg is the degree of the monomials to compute
1345*monomdeg is the actual degree of the monomial in consideration
1346*/
1347static void makemonoms(int vars,int actvar,int deg,int monomdeg, const ring r)
1348{
1349 poly p;
1350 int i=0;
1351
1352 if ((idpowerpoint == 0) && (actvar ==1))
1353 {
1355 monomdeg = 0;
1356 }
1357 while (i<=deg)
1358 {
1359 if (deg == monomdeg)
1360 {
1362 idpowerpoint++;
1363 return;
1364 }
1365 if (actvar == vars)
1366 {
1367 p_SetExp(idpower[idpowerpoint],actvar,deg-monomdeg,r);
1370 idpowerpoint++;
1371 return;
1372 }
1373 else
1374 {
1376 makemonoms(vars,actvar+1,deg,monomdeg,r);
1378 }
1379 monomdeg++;
1380 p_SetExp(idpower[idpowerpoint],actvar,p_GetExp(idpower[idpowerpoint],actvar,r)+1,r);
1383 i++;
1384 }
1385}
1386
1387#ifdef HAVE_SHIFTBBA
1388/*2
1389*computes recursively all letterplace monomials of a certain degree
1390*vars is the number of original variables (lV)
1391*deg is the degree of the monomials to compute
1392*
1393*NOTE: We use idpowerpoint as the last index of the previous call
1394*/
1395static void lpmakemonoms(int vars, int deg, const ring r)
1396{
1397 assume(deg <= r->N/r->isLPring);
1398 if (deg == 0)
1399 {
1400 idpower[0] = p_One(r);
1401 return;
1402 }
1403 else
1404 {
1405 lpmakemonoms(vars, deg - 1, r);
1406 }
1407
1408 int size = idpowerpoint + 1;
1409 for (int j = 2; j <= vars; j++)
1410 {
1411 for (int i = 0; i < size; i++)
1412 {
1413 idpowerpoint = (j-1)*size + i;
1415 }
1416 }
1417 for (int j = 1; j <= vars; j++)
1418 {
1419 for (int i = 0; i < size; i++)
1420 {
1421 idpowerpoint = (j-1)*size + i;
1422 p_SetExp(idpower[idpowerpoint], ((deg - 1) * r->isLPring) + j, 1, r);
1425 }
1426 }
1427}
1428#endif
1429
1430/*2
1431*returns the deg-th power of the maximal ideal of 0
1432*/
1433ideal id_MaxIdeal(int deg, const ring r)
1434{
1435 if (deg < 1)
1436 {
1437 ideal I=idInit(1,1);
1438 I->m[0]=p_One(r);
1439 return I;
1440 }
1441 if (deg == 1
1442#ifdef HAVE_SHIFTBBA
1443 && !r->isLPring
1444#endif
1445 )
1446 {
1447 return id_MaxIdeal(r);
1448 }
1449
1450 int vars, i;
1451#ifdef HAVE_SHIFTBBA
1452 if (r->isLPring)
1453 {
1454 vars = r->isLPring - r->LPncGenCount;
1455 i = 1;
1456 // i = vars^deg
1457 for (int j = 0; j < deg; j++)
1458 {
1459 i *= vars;
1460 }
1461 }
1462 else
1463#endif
1464 {
1465 vars = rVar(r);
1466 i = binom(vars+deg-1,deg);
1467 }
1468 if (i<=0) return idInit(1,1);
1469 ideal id=idInit(i,1);
1470 idpower = id->m;
1471 idpowerpoint = 0;
1472#ifdef HAVE_SHIFTBBA
1473 if (r->isLPring)
1474 {
1475 lpmakemonoms(vars, deg, r);
1476 }
1477 else
1478#endif
1479 {
1480 makemonoms(vars,1,deg,0,r);
1481 }
1482 idpower = NULL;
1483 idpowerpoint = 0;
1484 return id;
1485}
1486
1487static void id_NextPotence(ideal given, ideal result,
1488 int begin, int end, int deg, int restdeg, poly ap, const ring r)
1489{
1490 poly p;
1491 int i;
1492
1493 p = p_Power(p_Copy(given->m[begin],r),restdeg,r);
1494 i = result->nrows;
1495 result->m[i] = p_Mult_q(p_Copy(ap,r),p,r);
1496//PrintS(".");
1497 (result->nrows)++;
1498 if (result->nrows >= IDELEMS(result))
1499 {
1500 pEnlargeSet(&(result->m),IDELEMS(result),16);
1501 IDELEMS(result) += 16;
1502 }
1503 if (begin == end) return;
1504 for (i=restdeg-1;i>0;i--)
1505 {
1506 p = p_Power(p_Copy(given->m[begin],r),i,r);
1507 p = p_Mult_q(p_Copy(ap,r),p,r);
1508 id_NextPotence(given, result, begin+1, end, deg, restdeg-i, p,r);
1509 p_Delete(&p,r);
1510 }
1511 id_NextPotence(given, result, begin+1, end, deg, restdeg, ap,r);
1512}
1513
1514ideal id_Power(ideal given,int exp, const ring r)
1515{
1516 ideal result,temp;
1517 poly p1;
1518 int i;
1519
1520 if (idIs0(given)) return idInit(1,1);
1521 temp = id_Copy(given,r);
1522 idSkipZeroes(temp);
1523 i = binom(IDELEMS(temp)+exp-1,exp);
1524 result = idInit(i,1);
1525 result->nrows = 0;
1526//Print("ideal contains %d elements\n",i);
1527 p1=p_One(r);
1528 id_NextPotence(temp,result,0,IDELEMS(temp)-1,exp,exp,p1,r);
1529 p_Delete(&p1,r);
1530 id_Delete(&temp,r);
1531 result->nrows = 1;
1534 return result;
1535}
1536
1537/*2
1538*skips all zeroes and double elements, searches also for units
1539*/
1540void id_Compactify(ideal id, const ring r)
1541{
1542 int i;
1543 BOOLEAN b=FALSE;
1544
1545 i = IDELEMS(id)-1;
1546 while ((! b) && (i>=0))
1547 {
1548 b=p_IsUnit(id->m[i],r);
1549 i--;
1550 }
1551 if (b)
1552 {
1553 for(i=IDELEMS(id)-1;i>=0;i--) p_Delete(&id->m[i],r);
1554 id->m[0]=p_One(r);
1555 }
1556 else
1557 {
1558 id_DelMultiples(id,r);
1559 }
1560 idSkipZeroes(id);
1561}
1562
1563/// returns the ideals of initial terms
1564ideal id_Head(ideal h,const ring r)
1565{
1566 ideal m = idInit(IDELEMS(h),h->rank);
1567
1568 if (r->cf->has_simple_Alloc)
1569 {
1570 for (int i=IDELEMS(h)-1;i>=0; i--)
1571 if (h->m[i]!=NULL)
1572 m->m[i]=p_CopyPowerProduct0(h->m[i],pGetCoeff(h->m[i]),r);
1573 }
1574 else
1575 {
1576 for (int i=IDELEMS(h)-1;i>=0; i--)
1577 if (h->m[i]!=NULL)
1578 m->m[i]=p_Head(h->m[i],r);
1579 }
1580
1581 return m;
1582}
1583
1584ideal id_Homogen(ideal h, int varnum,const ring r)
1585{
1586 ideal m = idInit(IDELEMS(h),h->rank);
1587 int i;
1588
1589 for (i=IDELEMS(h)-1;i>=0; i--)
1590 {
1591 m->m[i]=p_Homogen(h->m[i],varnum,r);
1592 }
1593 return m;
1594}
1595
1596ideal id_HomogenDP(ideal h, int varnum,const ring r)
1597{
1598 ideal m = idInit(IDELEMS(h),h->rank);
1599 int i;
1600
1601 for (i=IDELEMS(h)-1;i>=0; i--)
1602 {
1603 m->m[i]=p_HomogenDP(h->m[i],varnum,r);
1604 }
1605 return m;
1606}
1607
1608/*------------------type conversions----------------*/
1609ideal id_Vec2Ideal(poly vec, const ring R)
1610{
1611 ideal result=idInit(1,1);
1613 p_Vec2Polys(vec, &(result->m), &(IDELEMS(result)),R);
1614 return result;
1615}
1616
1617/// for julia: convert an array of poly to vector
1618poly id_Array2Vector(poly *m, unsigned n, const ring R)
1619{
1620 poly h;
1621 int l;
1622 sBucket_pt bucket = sBucketCreate(R);
1623
1624 for(unsigned j=0;j<n ;j++)
1625 {
1626 h = m[j];
1627 if (h!=NULL)
1628 {
1629 h=p_Copy(h, R);
1630 l=pLength(h);
1631 p_SetCompP(h,j+1, R);
1632 sBucket_Merge_p(bucket, h, l);
1633 }
1634 }
1635 sBucketClearMerge(bucket, &h, &l);
1636 sBucketDestroy(&bucket);
1637 return h;
1638}
1639
1640/// converts mat to module, destroys mat
1641ideal id_Matrix2Module(matrix mat, const ring R)
1642{
1643 int mc=MATCOLS(mat);
1644 int mr=MATROWS(mat);
1645 ideal result = idInit(mc,mr);
1646 int i,j,l;
1647 poly h;
1648 sBucket_pt bucket = sBucketCreate(R);
1649
1650 for(j=0;j<mc /*MATCOLS(mat)*/;j++) /* j is also index in result->m */
1651 {
1652 for (i=0;i<mr /*MATROWS(mat)*/;i++)
1653 {
1654 h = MATELEM0(mat,i,j);
1655 if (h!=NULL)
1656 {
1657 l=pLength(h);
1658 MATELEM0(mat,i,j)=NULL;
1659 p_SetCompP(h,i+1, R);
1660 sBucket_Merge_p(bucket, h, l);
1661 }
1662 }
1663 sBucketClearMerge(bucket, &(result->m[j]), &l);
1664 }
1665 sBucketDestroy(&bucket);
1666
1667 // obachman: need to clean this up
1668 id_Delete((ideal*) &mat,R);
1669 return result;
1670}
1671
1672/*2
1673* converts a module into a matrix, destroys the input
1674*/
1675matrix id_Module2Matrix(ideal mod, const ring R)
1676{
1677 matrix result = mpNew(mod->rank,IDELEMS(mod));
1678 long i; long cp;
1679 poly p,h;
1680
1681 for(i=0;i<IDELEMS(mod);i++)
1682 {
1683 p=pReverse(mod->m[i]);
1684 mod->m[i]=NULL;
1685 while (p!=NULL)
1686 {
1687 h=p;
1688 pIter(p);
1689 pNext(h)=NULL;
1690 cp = si_max(1L,p_GetComp(h, R)); // if used for ideals too
1691 //cp = p_GetComp(h,R);
1692 p_SetComp(h,0,R);
1693 p_SetmComp(h,R);
1694#ifdef TEST
1695 if (cp>mod->rank)
1696 {
1697 Print("## inv. rank %ld -> %ld\n",mod->rank,cp);
1698 int k,l,o=mod->rank;
1699 mod->rank=cp;
1700 matrix d=mpNew(mod->rank,IDELEMS(mod));
1701 for (l=0; l<o; l++)
1702 {
1703 for (k=0; k<IDELEMS(mod); k++)
1704 {
1707 }
1708 }
1709 id_Delete((ideal *)&result,R);
1710 result=d;
1711 }
1712#endif
1713 MATELEM0(result,cp-1,i) = p_Add_q(MATELEM0(result,cp-1,i),h,R);
1714 }
1715 }
1716 // obachman 10/99: added the following line, otherwise memory leak!
1717 id_Delete(&mod,R);
1718 return result;
1719}
1720
1721matrix id_Module2formatedMatrix(ideal mod,int rows, int cols, const ring R)
1722{
1723 matrix result = mpNew(rows,cols);
1724 int i,cp,r=id_RankFreeModule(mod,R),c=IDELEMS(mod);
1725 poly p,h;
1726
1727 if (r>rows) r = rows;
1728 if (c>cols) c = cols;
1729 for(i=0;i<c;i++)
1730 {
1731 p=pReverse(mod->m[i]);
1732 mod->m[i]=NULL;
1733 while (p!=NULL)
1734 {
1735 h=p;
1736 pIter(p);
1737 pNext(h)=NULL;
1738 cp = p_GetComp(h,R);
1739 if (cp<=r)
1740 {
1741 p_SetComp(h,0,R);
1742 p_SetmComp(h,R);
1743 MATELEM0(result,cp-1,i) = p_Add_q(MATELEM0(result,cp-1,i),h,R);
1744 }
1745 else
1746 p_Delete(&h,R);
1747 }
1748 }
1749 id_Delete(&mod,R);
1750 return result;
1751}
1752
1753ideal id_ResizeModule(ideal mod,int rows, int cols, const ring R)
1754{
1755 // columns?
1756 if (cols!=IDELEMS(mod))
1757 {
1758 for(int i=IDELEMS(mod)-1;i>=cols;i--) p_Delete(&mod->m[i],R);
1759 pEnlargeSet(&(mod->m),IDELEMS(mod),cols-IDELEMS(mod));
1760 IDELEMS(mod)=cols;
1761 }
1762 // rows?
1763 if (rows<mod->rank)
1764 {
1765 for(int i=IDELEMS(mod)-1;i>=0;i--)
1766 {
1767 if (mod->m[i]!=NULL)
1768 {
1769 while((mod->m[i]!=NULL) && (p_GetComp(mod->m[i],R)>rows))
1770 mod->m[i]=p_LmDeleteAndNext(mod->m[i],R);
1771 poly p=mod->m[i];
1772 while(pNext(p)!=NULL)
1773 {
1774 if (p_GetComp(pNext(p),R)>rows)
1776 else
1777 pIter(p);
1778 }
1779 }
1780 }
1781 }
1782 mod->rank=rows;
1783 return mod;
1784}
1785
1786/*2
1787* substitute the n-th variable by the monomial e in id
1788* destroy id
1789*/
1790ideal id_Subst(ideal id, int n, poly e, const ring r)
1791{
1792 int k=MATROWS((matrix)id)*MATCOLS((matrix)id);
1793 ideal res=(ideal)mpNew(MATROWS((matrix)id),MATCOLS((matrix)id));
1794
1795 res->rank = id->rank;
1796 for(k--;k>=0;k--)
1797 {
1798 res->m[k]=p_Subst(id->m[k],n,e,r);
1799 id->m[k]=NULL;
1800 }
1801 id_Delete(&id,r);
1802 return res;
1803}
1804
1805BOOLEAN id_HomModule(ideal m, ideal Q, intvec **w, const ring R)
1806{
1807 if (w!=NULL) *w=NULL;
1808 if ((Q!=NULL) && (!id_HomIdeal(Q,NULL,R))) return FALSE;
1809 if (idIs0(m))
1810 {
1811 if (w!=NULL) (*w)=new intvec(m->rank);
1812 return TRUE;
1813 }
1814
1815 long cmax=1,order=0,ord,* diff,diffmin=32000;
1816 int *iscom;
1817 int i;
1818 poly p=NULL;
1819 pFDegProc d;
1820 if (R->pLexOrder && (R->order[0]==ringorder_lp))
1821 d=p_Totaldegree;
1822 else
1823 d=R->pFDeg;
1824 int length=IDELEMS(m);
1825 poly* P=m->m;
1826 poly* F=(poly*)omAlloc(length*sizeof(poly));
1827 for (i=length-1;i>=0;i--)
1828 {
1829 p=F[i]=P[i];
1830 cmax=si_max(cmax,p_MaxComp(p,R));
1831 }
1832 cmax++;
1833 diff = (long *)omAlloc0(cmax*sizeof(long));
1834 if (w!=NULL) *w=new intvec(cmax-1);
1835 iscom = (int *)omAlloc0(cmax*sizeof(int));
1836 i=0;
1837 while (i<=length)
1838 {
1839 if (i<length)
1840 {
1841 p=F[i];
1842 while ((p!=NULL) && (iscom[__p_GetComp(p,R)]==0)) pIter(p);
1843 }
1844 if ((p==NULL) && (i<length))
1845 {
1846 i++;
1847 }
1848 else
1849 {
1850 if (p==NULL) /* && (i==length) */
1851 {
1852 i=0;
1853 while ((i<length) && (F[i]==NULL)) i++;
1854 if (i>=length) break;
1855 p = F[i];
1856 }
1857 //if (pLexOrder && (currRing->order[0]==ringorder_lp))
1858 // order=pTotaldegree(p);
1859 //else
1860 // order = p->order;
1861 // order = pFDeg(p,currRing);
1862 order = d(p,R) +diff[__p_GetComp(p,R)];
1863 //order += diff[pGetComp(p)];
1864 p = F[i];
1865//Print("Actual p=F[%d]: ",i);pWrite(p);
1866 F[i] = NULL;
1867 i=0;
1868 }
1869 while (p!=NULL)
1870 {
1871 if (R->pLexOrder && (R->order[0]==ringorder_lp))
1872 ord=p_Totaldegree(p,R);
1873 else
1874 // ord = p->order;
1875 ord = R->pFDeg(p,R);
1876 if (iscom[__p_GetComp(p,R)]==0)
1877 {
1878 diff[__p_GetComp(p,R)] = order-ord;
1879 iscom[__p_GetComp(p,R)] = 1;
1880/*
1881*PrintS("new diff: ");
1882*for (j=0;j<cmax;j++) Print("%d ",diff[j]);
1883*PrintLn();
1884*PrintS("new iscom: ");
1885*for (j=0;j<cmax;j++) Print("%d ",iscom[j]);
1886*PrintLn();
1887*Print("new set %d, order %d, ord %d, diff %d\n",pGetComp(p),order,ord,diff[pGetComp(p)]);
1888*/
1889 }
1890 else
1891 {
1892/*
1893*PrintS("new diff: ");
1894*for (j=0;j<cmax;j++) Print("%d ",diff[j]);
1895*PrintLn();
1896*Print("order %d, ord %d, diff %d\n",order,ord,diff[pGetComp(p)]);
1897*/
1898 if (order != (ord+diff[__p_GetComp(p,R)]))
1899 {
1900 omFreeSize((ADDRESS) iscom,cmax*sizeof(int));
1901 omFreeSize((ADDRESS) diff,cmax*sizeof(long));
1902 omFreeSize((ADDRESS) F,length*sizeof(poly));
1903 delete *w;*w=NULL;
1904 return FALSE;
1905 }
1906 }
1907 pIter(p);
1908 }
1909 }
1910 omFreeSize((ADDRESS) iscom,cmax*sizeof(int));
1911 omFreeSize((ADDRESS) F,length*sizeof(poly));
1912 for (i=1;i<cmax;i++) (**w)[i-1]=(int)(diff[i]);
1913 for (i=1;i<cmax;i++)
1914 {
1915 if (diff[i]<diffmin) diffmin=diff[i];
1916 }
1917 if (w!=NULL)
1918 {
1919 for (i=1;i<cmax;i++)
1920 {
1921 (**w)[i-1]=(int)(diff[i]-diffmin);
1922 }
1923 }
1924 omFreeSize((ADDRESS) diff,cmax*sizeof(long));
1925 return TRUE;
1926}
1927
1928ideal id_Jet(const ideal i,int d, const ring R)
1929{
1930 ideal r=idInit((i->nrows)*(i->ncols),i->rank);
1931 r->nrows = i-> nrows;
1932 r->ncols = i-> ncols;
1933 //r->rank = i-> rank;
1934
1935 for(long k=((long)(i->nrows))*((long)(i->ncols))-1;k>=0; k--)
1936 r->m[k]=pp_Jet(i->m[k],d,R);
1937
1938 return r;
1939}
1940
1941ideal id_Jet0(const ideal i, const ring R)
1942{
1943 ideal r=idInit((i->nrows)*(i->ncols),i->rank);
1944 r->nrows = i-> nrows;
1945 r->ncols = i-> ncols;
1946 //r->rank = i-> rank;
1947
1948 for(long k=((long)(i->nrows))*((long)(i->ncols))-1;k>=0; k--)
1949 r->m[k]=pp_Jet0(i->m[k],R);
1950
1951 return r;
1952}
1953
1954ideal id_JetW(const ideal i,int d, intvec * iv, const ring R)
1955{
1956 ideal r=idInit(IDELEMS(i),i->rank);
1957 if (ecartWeights!=NULL)
1958 {
1959 WerrorS("cannot compute weighted jets now");
1960 }
1961 else
1962 {
1963 int *w=iv2array(iv,R);
1964 int k;
1965 for(k=0; k<IDELEMS(i); k++)
1966 {
1967 r->m[k]=pp_JetW(i->m[k],d,w,R);
1968 }
1969 omFreeSize((ADDRESS)w,(rVar(R)+1)*sizeof(int));
1970 }
1971 return r;
1972}
1973
1974#if 0
1975static void idDeleteComp(ideal arg,int red_comp)
1976{
1977 int i,j;
1978 poly p;
1979
1980 for (i=IDELEMS(arg)-1;i>=0;i--)
1981 {
1982 p = arg->m[i];
1983 while (p!=NULL)
1984 {
1985 j = pGetComp(p);
1986 if (j>red_comp)
1987 {
1988 pSetComp(p,j-1);
1989 pSetm(p);
1990 }
1991 pIter(p);
1992 }
1993 }
1994 (arg->rank)--;
1995}
1996#endif
1997
1998intvec * id_QHomWeight(ideal id, const ring r)
1999{
2000 poly head, tail;
2001 int k;
2002 int in=IDELEMS(id)-1, ready=0, all=0,
2003 coldim=rVar(r), rowmax=2*coldim;
2004 if (in<0) return NULL;
2005 intvec *imat=new intvec(rowmax+1,coldim,0);
2006
2007 do
2008 {
2009 head = id->m[in--];
2010 if (head!=NULL)
2011 {
2012 tail = pNext(head);
2013 while (tail!=NULL)
2014 {
2015 all++;
2016 for (k=1;k<=coldim;k++)
2017 IMATELEM(*imat,all,k) = p_GetExpDiff(head,tail,k,r);
2018 if (all==rowmax)
2019 {
2020 ivTriangIntern(imat, ready, all);
2021 if (ready==coldim)
2022 {
2023 delete imat;
2024 return NULL;
2025 }
2026 }
2027 pIter(tail);
2028 }
2029 }
2030 } while (in>=0);
2031 if (all>ready)
2032 {
2033 ivTriangIntern(imat, ready, all);
2034 if (ready==coldim)
2035 {
2036 delete imat;
2037 return NULL;
2038 }
2039 }
2040 intvec *result = ivSolveKern(imat, ready);
2041 delete imat;
2042 return result;
2043}
2044
2045BOOLEAN id_IsZeroDim(ideal I, const ring r)
2046{
2047 BOOLEAN *UsedAxis=(BOOLEAN *)omAlloc0(rVar(r)*sizeof(BOOLEAN));
2048 int i,n;
2049 poly po;
2051 for(i=IDELEMS(I)-1;i>=0;i--)
2052 {
2053 po=I->m[i];
2054 if ((po!=NULL) &&((n=p_IsPurePower(po,r))!=0)) UsedAxis[n-1]=TRUE;
2055 }
2056 for(i=rVar(r)-1;i>=0;i--)
2057 {
2058 if(UsedAxis[i]==FALSE) {res=FALSE; break;} // not zero-dim.
2059 }
2060 omFreeSize(UsedAxis,rVar(r)*sizeof(BOOLEAN));
2061 return res;
2062}
2063
2064void id_Normalize(ideal I,const ring r) /* for ideal/matrix */
2065{
2066 if (rField_has_simple_inverse(r)) return; /* Z/p, GF(p,n), R, long R/C */
2067 int i;
2068 for(i=I->nrows*I->ncols-1;i>=0;i--)
2069 {
2070 poly p=I->m[i];
2071 if (p!=NULL) p_Normalize(p,r);
2072 }
2073}
2074
2075int id_MinDegW(ideal M,intvec *w, const ring r)
2076{
2077 int d=-1;
2078 for(int i=0;i<IDELEMS(M);i++)
2079 {
2080 if (M->m[i]!=NULL)
2081 {
2082 int d0=p_MinDeg(M->m[i],w,r);
2083 if(-1<d0&&((d0<d)||(d==-1)))
2084 d=d0;
2085 }
2086 }
2087 return d;
2088}
2089
2090// #include "kernel/clapsing.h"
2091
2092/*2
2093* transpose a module
2094*/
2095ideal id_Transp(ideal a, const ring rRing)
2096{
2097 int r = a->rank, c = IDELEMS(a);
2098 ideal b = idInit(r,c);
2099
2100 int i;
2101 for (i=c; i>0; i--)
2102 {
2103 poly p=a->m[i-1];
2104 while(p!=NULL)
2105 {
2106 poly h=p_Head(p, rRing);
2107 int co=__p_GetComp(h, rRing)-1;
2108 p_SetComp(h, i, rRing);
2109 p_Setm(h, rRing);
2110 h->next=b->m[co];
2111 b->m[co]=h;
2112 pIter(p);
2113 }
2114 }
2115 for (i=IDELEMS(b)-1; i>=0; i--)
2116 {
2117 poly p=b->m[i];
2118 if(p!=NULL)
2119 {
2120 b->m[i]=p_SortMerge(p,rRing,TRUE);
2121 }
2122 }
2123 return b;
2124}
2125
2126/*2
2127* The following is needed to compute the image of certain map used in
2128* the computation of cohomologies via BGG
2129* let M = { w_1, ..., w_k }, k = size(M) == ncols(M), n = nvars(currRing).
2130* assuming that nrows(M) <= m*n; the procedure computes:
2131* transpose(M) * transpose( var(1) I_m | ... | var(n) I_m ) :== transpose(module{f_1, ... f_k}),
2132* where f_i = \sum_{j=1}^{m} (w_i, v_j) gen(j), (w_i, v_j) is a `scalar` multiplication.
2133* that is, if w_i = (a^1_1, ... a^1_m) | (a^2_1, ..., a^2_m) | ... | (a^n_1, ..., a^n_m) then
2134
2135 (a^1_1, ... a^1_m) | (a^2_1, ..., a^2_m) | ... | (a^n_1, ..., a^n_m)
2136* var_1 ... var_1 | var_2 ... var_2 | ... | var_n ... var(n)
2137* gen_1 ... gen_m | gen_1 ... gen_m | ... | gen_1 ... gen_m
2138+ =>
2139 f_i =
2140
2141 a^1_1 * var(1) * gen(1) + ... + a^1_m * var(1) * gen(m) +
2142 a^2_1 * var(2) * gen(1) + ... + a^2_m * var(2) * gen(m) +
2143 ...
2144 a^n_1 * var(n) * gen(1) + ... + a^n_m * var(n) * gen(m);
2145
2146 NOTE: for every f_i we run only ONCE along w_i saving partial sums into a temporary array of polys of size m
2147*/
2148ideal id_TensorModuleMult(const int m, const ideal M, const ring rRing)
2149{
2150// #ifdef DEBU
2151// WarnS("tensorModuleMult!!!!");
2152
2153 assume(m > 0);
2154 assume(M != NULL);
2155
2156 const int n = rRing->N;
2157
2158 assume(M->rank <= m * n);
2159
2160 const int k = IDELEMS(M);
2161
2162 ideal idTemp = idInit(k,m); // = {f_1, ..., f_k }
2163
2164 for( int i = 0; i < k; i++ ) // for every w \in M
2165 {
2166 poly pTempSum = NULL;
2167
2168 poly w = M->m[i];
2169
2170 while(w != NULL) // for each term of w...
2171 {
2172 poly h = p_Head(w, rRing);
2173
2174 const int gen = __p_GetComp(h, rRing); // 1 ...
2175
2176 assume(gen > 0);
2177 assume(gen <= n*m);
2178
2179 // TODO: write a formula with %, / instead of while!
2180 /*
2181 int c = gen;
2182 int v = 1;
2183 while(c > m)
2184 {
2185 c -= m;
2186 v++;
2187 }
2188 */
2189
2190 int cc = gen % m;
2191 if( cc == 0) cc = m;
2192 int vv = 1 + (gen - cc) / m;
2193
2194// assume( cc == c );
2195// assume( vv == v );
2196
2197 // 1<= c <= m
2198 assume( cc > 0 );
2199 assume( cc <= m );
2200
2201 assume( vv > 0 );
2202 assume( vv <= n );
2203
2204 assume( (cc + (vv-1)*m) == gen );
2205
2206 p_IncrExp(h, vv, rRing); // h *= var(j) && // p_AddExp(h, vv, 1, rRing);
2207 p_SetComp(h, cc, rRing);
2208
2209 p_Setm(h, rRing); // adjust degree after the previous steps!
2210
2211 pTempSum = p_Add_q(pTempSum, h, rRing); // it is slow since h will be usually put to the back of pTempSum!!!
2212
2213 pIter(w);
2214 }
2215
2216 idTemp->m[i] = pTempSum;
2217 }
2218
2219 // simplify idTemp???
2220
2221 ideal idResult = id_Transp(idTemp, rRing);
2222
2223 id_Delete(&idTemp, rRing);
2224
2225 return(idResult);
2226}
2227
2228ideal id_ChineseRemainder(ideal *xx, number *q, int rl, const ring r)
2229{
2230 int cnt=0;int rw=0; int cl=0;
2231 int i,j;
2232 // find max. size of xx[.]:
2233 for(j=rl-1;j>=0;j--)
2234 {
2235 i=IDELEMS(xx[j])*xx[j]->nrows;
2236 if (i>cnt) cnt=i;
2237 if (xx[j]->nrows >rw) rw=xx[j]->nrows; // for lifting matrices
2238 if (xx[j]->ncols >cl) cl=xx[j]->ncols; // for lifting matrices
2239 }
2240 if (rw*cl !=cnt)
2241 {
2242 WerrorS("format mismatch in CRT");
2243 return NULL;
2244 }
2245 ideal result=idInit(cnt,xx[0]->rank);
2246 result->nrows=rw; // for lifting matrices
2247 result->ncols=cl; // for lifting matrices
2248 number *x=(number *)omAlloc(rl*sizeof(number));
2249 poly *p=(poly *)omAlloc(rl*sizeof(poly));
2250 CFArray inv_cache(rl);
2251 EXTERN_VAR int n_SwitchChinRem; //TEST
2252 int save_n_SwitchChinRem=n_SwitchChinRem;
2254 for(i=cnt-1;i>=0;i--)
2255 {
2256 for(j=rl-1;j>=0;j--)
2257 {
2258 if(i>=IDELEMS(xx[j])*xx[j]->nrows) // out of range of this ideal
2259 p[j]=NULL;
2260 else
2261 p[j]=xx[j]->m[i];
2262 }
2263 result->m[i]=p_ChineseRemainder(p,x,q,rl,inv_cache,r);
2264 for(j=rl-1;j>=0;j--)
2265 {
2266 if(i<IDELEMS(xx[j])*xx[j]->nrows) xx[j]->m[i]=p[j];
2267 }
2268 }
2269 n_SwitchChinRem=save_n_SwitchChinRem;
2270 omFreeSize(p,rl*sizeof(poly));
2271 omFreeSize(x,rl*sizeof(number));
2272 for(i=rl-1;i>=0;i--) id_Delete(&(xx[i]),r);
2273 omFreeSize(xx,rl*sizeof(ideal));
2274 return result;
2275}
2276
2277void id_Shift(ideal M, int s, const ring r)
2278{
2279// id_Test( M, r );
2280
2281// assume( s >= 0 ); // negative is also possible // TODO: verify input ideal in such a case!?
2282
2283 for(int i=IDELEMS(M)-1; i>=0;i--)
2284 p_Shift(&(M->m[i]),s,r);
2285
2286 M->rank += s;
2287
2288// id_Test( M, r );
2289}
2290
2291ideal id_Delete_Pos(const ideal I, const int p, const ring r)
2292{
2293 if ((p<0)||(p>=IDELEMS(I))) return NULL;
2294 ideal ret=idInit(IDELEMS(I)-1,I->rank);
2295 for(int i=0;i<p;i++) ret->m[i]=p_Copy(I->m[i],r);
2296 for(int i=p+1;i<IDELEMS(I);i++) ret->m[i-1]=p_Copy(I->m[i],r);
2297 return ret;
2298}
2299
2300ideal id_PermIdeal(ideal I,int R, int C,const int *perm, const ring src, const ring dst,
2301 nMapFunc nMap, const int *par_perm, int P, BOOLEAN use_mult)
2302{
2303 ideal II=(ideal)mpNew(R,C);
2304 II->rank=I->rank;
2305 for(int i=R*C-1; i>=0; i--)
2306 {
2307 II->m[i]=p_PermPoly(I->m[i],perm,src,dst,nMap,par_perm,P,use_mult);
2308 }
2309 return II;
2310}
All the auxiliary stuff.
long int64
Definition auxiliary.h:68
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
#define LIKELY(X)
Definition auxiliary.h:404
void * ADDRESS
Definition auxiliary.h:120
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 &)
CanonicalForm FACTORY_PUBLIC pp(const CanonicalForm &)
CanonicalForm pp ( const CanonicalForm & f ).
Definition cf_gcd.cc:676
Array< CanonicalForm > CFArray
CanonicalForm head(const CanonicalForm &f)
int level(const CanonicalForm &f)
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
cl
Definition cfModGcd.cc:4108
CanonicalForm b
Definition cfModGcd.cc:4111
int int ncols
Definition cf_linsys.cc:32
int nrows
Definition cf_linsys.cc:32
FILE * f
Definition checklibs.c:9
long rank
Definition matpol.h:19
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_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff 'n' is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2),...
Definition coeffs.h:500
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 number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
Definition coeffs.h:658
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:461
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
Definition coeffs.h:80
#define Print
Definition emacs.cc:80
#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
fq_nmod_poly_t * vec
Definition facHensel.cc:108
int j
Definition facHensel.cc:110
void WerrorS(const char *s)
Definition feFopen.cc:24
#define STATIC_VAR
Definition globaldefs.h:7
#define EXTERN_VAR
Definition globaldefs.h:6
#define VAR
Definition globaldefs.h:5
static BOOLEAN length(leftv result, leftv arg)
Definition interval.cc:257
void ivTriangIntern(intvec *imat, int &ready, int &all)
Definition intvec.cc:404
intvec * ivSolveKern(intvec *imat, int dimtr)
Definition intvec.cc:442
#define IMATELEM(M, I, J)
Definition intvec.h:86
STATIC_VAR Poly * h
Definition janet.cc:971
poly p_ChineseRemainder(poly *xx, mpz_ptr *x, mpz_ptr *q, int rl, mpz_ptr *C, const ring R)
VAR int n_SwitchChinRem
Definition longrat.cc:3075
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition matpol.cc:37
ip_smatrix * matrix
Definition matpol.h:43
#define MATELEM0(mat, i, j)
0-based access to matrix
Definition matpol.h:31
#define MATROWS(i)
Definition matpol.h:26
#define MATCOLS(i)
Definition matpol.h:27
#define assume(x)
Definition mod2.h:389
int dReportError(const char *fmt,...)
Definition dError.cc:44
#define p_GetComp(p, r)
Definition monomials.h:64
#define pIter(p)
Definition monomials.h:37
#define pNext(p)
Definition monomials.h:36
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 rRing_has_Comp(r)
Definition monomials.h:266
gmp_float exp(const gmp_float &a)
STATIC_VAR gmp_float * diff
const int MAX_INT_VAL
Definition mylimits.h:12
Definition ap.h:40
#define omFreeSize(addr, size)
#define omAlloc(size)
#define omAllocBin(bin)
#define omdebugAddrSize(addr, size)
#define omCheckAddrSize(addr, size)
#define omFree(addr)
#define omAlloc0(size)
#define omFreeBin(addr, bin)
#define omFreeBinAddr(addr)
#define omGetSpecBin(size)
Definition omBin.h:11
#define NULL
Definition omList.c:12
omBin_t * omBin
Definition omStructs.h:12
int p_IsPurePower(const poly p, const ring r)
return i, if head depends only on var(i)
Definition p_polys.cc:1227
poly pp_Jet(poly p, int m, const ring R)
Definition p_polys.cc:4497
poly p_HomogenDP(poly p, int varnum, const ring r)
Definition p_polys.cc:3365
BOOLEAN p_ComparePolys(poly p1, poly p2, const ring r)
returns TRUE if p1 is a skalar multiple of p2 assume p1 != NULL and p2 != NULL
Definition p_polys.cc:4743
BOOLEAN p_DivisibleByRingCase(poly f, poly g, const ring r)
divisibility check over ground ring (which may contain zero divisors); TRUE iff LT(f) divides LT(g),...
Definition p_polys.cc:1646
poly p_Homogen(poly p, int varnum, const ring r)
Definition p_polys.cc:3319
poly p_Subst(poly p, int n, poly e, const ring r)
Definition p_polys.cc:4097
void p_Vec2Polys(poly v, poly **p, int *len, const ring r)
Definition p_polys.cc:3750
void p_Shift(poly *p, int i, const ring r)
shifts components of the vector p by i
Definition p_polys.cc:4873
poly p_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:4269
poly p_Power(poly p, int i, const ring r)
Definition p_polys.cc:2245
void p_Normalize(poly p, const ring r)
Definition p_polys.cc:3952
void p_Norm(poly p1, const ring r)
Definition p_polys.cc:3844
poly pp_Jet0(poly p, const ring R)
Definition p_polys.cc:4525
int p_MinDeg(poly p, intvec *w, const ring R)
Definition p_polys.cc:4615
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition p_polys.cc:4947
BOOLEAN p_IsHomogeneousW(poly p, const intvec *w, const ring r)
Definition p_polys.cc:3451
poly p_One(const ring r)
Definition p_polys.cc:1314
void pEnlargeSet(poly **p, int l, int increment)
Definition p_polys.cc:3821
BOOLEAN p_IsHomogeneous(poly p, const ring r)
Definition p_polys.cc:3408
poly pp_JetW(poly p, int m, int *w, const ring R)
Definition p_polys.cc:4570
poly p_CopyPowerProduct0(const poly p, number n, const ring r)
like p_Head, but with coefficient n
Definition p_polys.cc:5135
BOOLEAN p_IsHomogeneousDP(poly p, const ring r)
Definition p_polys.cc:3432
BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r)
Definition p_polys.cc:4679
static int pLength(poly a)
Definition p_polys.h:190
static long p_GetExpDiff(poly p1, poly p2, int i, ring r)
Definition p_polys.h:637
static poly p_Add_q(poly p, poly q, const ring r)
Definition p_polys.h:938
static poly p_Mult_q(poly p, poly q, const ring r)
Definition p_polys.h:1125
#define p_LmEqual(p1, p2, r)
Definition p_polys.h:1744
BOOLEAN _p_LmTest(poly p, ring r, int level)
Definition pDebug.cc:322
void p_ShallowDelete(poly *p, const ring r)
static void p_SetCompP(poly p, int i, ring r)
Definition p_polys.h:256
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
#define pp_Test(p, lmRing, tailRing)
Definition p_polys.h:163
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition p_polys.h:249
static long p_IncrExp(poly p, int v, ring r)
Definition p_polys.h:593
static void p_Setm(poly p, const ring r)
Definition p_polys.h:235
#define p_SetmComp
Definition p_polys.h:246
static poly p_SortMerge(poly p, const ring r, BOOLEAN revert=FALSE)
Definition p_polys.h:1250
static poly pReverse(poly p)
Definition p_polys.h:337
static int p_LtCmp(poly p, poly q, const ring r)
Definition p_polys.h:1642
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 BOOLEAN p_LmShortDivisibleBy(poly a, unsigned long sev_a, poly b, unsigned long not_sev_b, const ring r)
Definition p_polys.h:1931
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 BOOLEAN p_LmDivisibleBy(poly a, poly b, const ring r)
Definition p_polys.h:1912
static long p_MaxComp(poly p, ring lmRing, ring tailRing)
Definition p_polys.h:294
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
static poly pp_Mult_qq(poly p, poly q, const ring r)
Definition p_polys.h:1167
static void p_LmFree(poly p, ring)
Definition p_polys.h:685
static BOOLEAN p_IsUnit(const poly p, const ring r)
Definition p_polys.h:2012
static poly p_LmDeleteAndNext(poly p, const ring r)
Definition p_polys.h:757
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
BOOLEAN _pp_Test(poly p, ring lmRing, ring tailRing, int level)
Definition pDebug.cc:332
#define p_Test(p, r)
Definition p_polys.h:161
static BOOLEAN p_IsConstantPoly(const poly p, const ring r)
Definition p_polys.h:1999
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition polys0.cc:373
#define pSetm(p)
Definition polys.h:272
#define pGetComp(p)
Component.
Definition polys.h:38
#define pSetComp(p, v)
Definition polys.h:39
void PrintS(const char *s)
Definition reporter.cc:288
void PrintLn()
Definition reporter.cc:314
long(* pFDegProc)(poly p, ring r)
Definition ring.h:39
@ ringorder_lp
Definition ring.h:78
static short rVar(const ring r)
define rVar(r) (r->N)
Definition ring.h:603
static BOOLEAN rField_has_simple_inverse(const ring r)
Definition ring.h:559
#define rField_is_Ring(R)
Definition ring.h:491
void sBucketClearMerge(sBucket_pt bucket, poly *p, int *length)
Definition sbuckets.cc:237
void sBucket_Merge_p(sBucket_pt bucket, poly p, int length)
Merges p into Spoly: assumes Bpoly and p have no common monoms destroys p!
Definition sbuckets.cc:148
void sBucketDestroy(sBucket_pt *bucket)
Definition sbuckets.cc:103
sBucket_pt sBucketCreate(const ring r)
Definition sbuckets.cc:96
sBucket * sBucket_pt
Definition sbuckets.h:16
void id_DBLmTest(ideal h1, int level, const char *f, const int l, const ring r)
Internal verification for ideals/modules and dense matrices!
ideal id_Add(ideal h1, ideal h2, const ring r)
h1 + h2
STATIC_VAR int idpowerpoint
ideal id_Vec2Ideal(poly vec, const ring R)
ideal idInit(int idsize, int rank)
initialise an ideal / module
int id_PosConstant(ideal id, const ring r)
index of generator with leading term in ground ring (if any); otherwise -1
int binom(int n, int r)
void id_Delete(ideal *h, ring r)
deletes an ideal/module/matrix
BOOLEAN id_IsModule(ideal A, const ring src)
int idSkipZeroes0(ideal ide)
void id_DBTest(ideal h1, int level, const char *f, const int l, const ring r, const ring tailRing)
Internal verification for ideals/modules and dense matrices!
poly id_Array2Vector(poly *m, unsigned n, const ring R)
for julia: convert an array of poly to vector
static void id_NextPotence(ideal given, ideal result, int begin, int end, int deg, int restdeg, poly ap, const ring r)
intvec * id_Sort(const ideal id, const BOOLEAN nolex, const ring r)
sorts the ideal w.r.t. the actual ringordering uses lex-ordering when nolex = FALSE
intvec * id_QHomWeight(ideal id, const ring r)
void id_Norm(ideal id, const ring r)
ideal id = (id[i]), result is leadcoeff(id[i]) = 1
BOOLEAN id_HomIdeal(ideal id, ideal Q, const ring r)
STATIC_VAR poly * idpower
static void makemonoms(int vars, int actvar, int deg, int monomdeg, const ring r)
BOOLEAN id_HomModuleW(ideal id, ideal Q, const intvec *w, const intvec *module_w, const ring r)
void idGetNextChoise(int r, int end, BOOLEAN *endch, int *choise)
void id_Normalize(ideal I, const ring r)
normialize all polys in id
ideal id_Transp(ideal a, const ring rRing)
transpose a module
void id_Delete0(ideal *h, ring r)
ideal id_FreeModule(int i, const ring r)
the free module of rank i
BOOLEAN id_IsZeroDim(ideal I, const ring r)
ideal id_Homogen(ideal h, int varnum, const ring r)
BOOLEAN idIsSimpleGB(ideal F, ideal Q)
returns true if F in R/Q has a "simple" GB
ideal id_Power(ideal given, int exp, const ring r)
BOOLEAN id_HomIdealDP(ideal id, ideal Q, const ring r)
matrix id_Module2Matrix(ideal mod, const ring R)
ideal id_Head(ideal h, const ring r)
returns the ideals of initial terms
BOOLEAN idInsertPoly(ideal h1, poly h2)
insert h2 into h1 (if h2 is not the zero polynomial) return TRUE iff h2 was indeed inserted
ideal id_Copy(ideal h1, const ring r)
copy an ideal
BOOLEAN id_IsConstant(ideal id, const ring r)
test if the ideal has only constant polynomials NOTE: zero ideal/module is also constant
BOOLEAN idIs0(ideal h)
returns true if h is the zero ideal
BOOLEAN id_HomIdealW(ideal id, ideal Q, const intvec *w, const ring r)
ideal id_TensorModuleMult(const int m, const ideal M, const ring rRing)
long id_RankFreeModule(ideal s, ring lmRing, ring tailRing)
return the maximal component number found in any polynomial in s
BOOLEAN idInsertPolyOnPos(ideal I, poly p, int pos)
insert p into I on position pos
ideal id_Jet0(const ideal i, const ring R)
ideal id_MaxIdeal(const ring r)
initialise the maximal ideal (at 0)
void id_DelDiv(ideal id, const ring r)
delete id[j], if LT(j) == coeff*mon*LT(i) and vice versa, i.e., delete id[i], if LT(i) == coeff*mon*L...
int id_MinDegW(ideal M, intvec *w, const ring r)
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
void id_ShallowDelete(ideal *h, ring r)
Shallowdeletes an ideal/matrix.
BOOLEAN id_InsertPolyWithTests(ideal h1, const int validEntries, const poly h2, const bool zeroOk, const bool duplicateOk, const ring r)
insert h2 into h1 depending on the two boolean parameters:
ideal id_Mult(ideal h1, ideal h2, const ring R)
h1 * h2 one h_i must be an ideal (with at least one column) the other h_i may be a module (with no co...
ideal id_CopyFirstK(const ideal ide, const int k, const ring r)
copies the first k (>= 1) entries of the given ideal/module and returns these as a new ideal/module (...
matrix id_Module2formatedMatrix(ideal mod, int rows, int cols, const ring R)
void idShow(const ideal id, const ring lmRing, const ring tailRing, const int debugPrint)
ideal id_Matrix2Module(matrix mat, const ring R)
converts mat to module, destroys mat
ideal id_ResizeModule(ideal mod, int rows, int cols, const ring R)
ideal id_Delete_Pos(const ideal I, const int p, const ring r)
static int p_Comp_RevLex(poly a, poly b, BOOLEAN nolex, const ring R)
for idSort: compare a and b revlex inclusive module comp.
void id_DelEquals(ideal id, const ring r)
ideal id = (id[i]) if id[i] = id[j] then id[j] is deleted for j > i
VAR omBin sip_sideal_bin
ideal id_Jet(const ideal i, int d, const ring R)
static void id_DelDiv_SEV(ideal id, int k, const ring r)
delete id[j], if LT(j) == coeff*mon*LT(i)
ideal id_SimpleAdd(ideal h1, ideal h2, const ring R)
concat the lists h1 and h2 without zeros
void id_DelLmEquals(ideal id, const ring r)
Delete id[j], if Lm(j) == Lm(i) and both LC(j), LC(i) are units and j > i.
ideal id_JetW(const ideal i, int d, intvec *iv, const ring R)
ideal id_HomogenDP(ideal h, int varnum, const ring r)
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
void id_Shift(ideal M, int s, const ring r)
int idGetNumberOfChoise(int t, int d, int begin, int end, int *choise)
void idInitChoise(int r, int beg, int end, BOOLEAN *endch, int *choise)
ideal id_PermIdeal(ideal I, int R, int C, const int *perm, const ring src, const ring dst, nMapFunc nMap, const int *par_perm, int P, BOOLEAN use_mult)
mapping ideals/matrices to other rings
ideal id_ChineseRemainder(ideal *xx, number *q, int rl, const ring r)
static void lpmakemonoms(int vars, int deg, const ring r)
ideal id_SimpleMove(ideal h1, ideal h2, const ring R)
concat the lists h1 and h2 without zeros, destroys h1,h2
void id_Compactify(ideal id, const ring r)
BOOLEAN idIsMonomial(ideal h)
returns true if h is generated by monomials
BOOLEAN id_HomModule(ideal m, ideal Q, intvec **w, const ring R)
ideal id_Subst(ideal id, int n, poly e, const ring r)
#define IDELEMS(i)
#define id_Test(A, lR)
The following sip_sideal structure has many different uses throughout Singular. Basic use-cases for i...
#define R
Definition sirandom.c:27
#define A
Definition sirandom.c:24
#define M
Definition sirandom.c:25
#define Q
Definition sirandom.c:26
int * iv2array(intvec *iv, const ring R)
Definition weight.cc:200
EXTERN_VAR short * ecartWeights
Definition weight.h:12
#define omPrintAddrInfo(A, B, C)
Definition xalloc.h:270