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/// insert h2 into h1 (if h2 is not the zero polynomial)
831/// return TRUE iff h2 was indeed inserted
832BOOLEAN idInsertPoly (ideal h1, poly h2)
833{
834 if (h2==NULL) return FALSE;
835 assume (h1 != NULL);
836
837 int j = IDELEMS(h1) - 1;
838
839 while ((j >= 0) && (h1->m[j] == NULL)) j--;
840 j++;
841 if (j==IDELEMS(h1))
842 {
843 pEnlargeSet(&(h1->m),IDELEMS(h1),16);
844 IDELEMS(h1)+=16;
845 }
846 h1->m[j]=h2;
847 return TRUE;
848}
849
850/// insert p into I on position pos
851BOOLEAN idInsertPolyOnPos (ideal I, poly p,int pos)
852{
853 if (p==NULL) return FALSE;
854 assume (I != NULL);
855
856 int j = IDELEMS(I) - 1;
857
858 while ((j >= 0) && (I->m[j] == NULL)) j--;
859 j++;
860 if (j==IDELEMS(I))
861 {
862 pEnlargeSet(&(I->m),IDELEMS(I),IDELEMS(I)+1);
863 IDELEMS(I)+=1;
864 }
865 for(j = IDELEMS(I)-1;j>pos;j--)
866 I->m[j] = I->m[j-1];
867 I->m[pos]=p;
868 return TRUE;
869}
870
871
872/*! insert h2 into h1 depending on the two boolean parameters:
873 * - if zeroOk is true, then h2 will also be inserted when it is zero
874 * - if duplicateOk is true, then h2 will also be inserted when it is
875 * already present in h1
876 * return TRUE iff h2 was indeed inserted
877 */
878BOOLEAN id_InsertPolyWithTests (ideal h1, const int validEntries,
879 const poly h2, const bool zeroOk, const bool duplicateOk, const ring r)
880{
881 id_Test(h1, r);
882 p_Test(h2, r);
883
884 if ((!zeroOk) && (h2 == NULL)) return FALSE;
885 if (!duplicateOk)
886 {
887 bool h2FoundInH1 = false;
888 int i = 0;
889 while ((i < validEntries) && (!h2FoundInH1))
890 {
891 h2FoundInH1 = p_EqualPolys(h1->m[i], h2,r);
892 i++;
893 }
894 if (h2FoundInH1) return FALSE;
895 }
896 if (validEntries == IDELEMS(h1))
897 {
898 pEnlargeSet(&(h1->m), IDELEMS(h1), 16);
899 IDELEMS(h1) += 16;
900 }
901 h1->m[validEntries] = h2;
902 return TRUE;
903}
904
905/// h1 + h2
906ideal id_Add (ideal h1,ideal h2, const ring r)
907{
908 id_Test(h1, r);
909 id_Test(h2, r);
910
911 ideal result = id_SimpleAdd(h1,h2,r);
913 return result;
914}
915
916/// h1 * h2
917/// one h_i must be an ideal (with at least one column)
918/// the other h_i may be a module (with no columns at all)
919ideal id_Mult (ideal h1,ideal h2, const ring R)
920{
921 id_Test(h1, R);
922 id_Test(h2, R);
923
924 int j = IDELEMS(h1);
925 while ((j > 0) && (h1->m[j-1] == NULL)) j--;
926
927 int i = IDELEMS(h2);
928 while ((i > 0) && (h2->m[i-1] == NULL)) i--;
929
930 j *= i;
931 int r = si_max( h2->rank, h1->rank );
932 if (j==0)
933 {
934 if ((IDELEMS(h1)>0) && (IDELEMS(h2)>0)) j=1;
935 return idInit(j, r);
936 }
937 ideal hh = idInit(j, r);
938
939 int k = 0;
940 for (i=0; i<IDELEMS(h1); i++)
941 {
942 if (h1->m[i] != NULL)
943 {
944 for (j=0; j<IDELEMS(h2); j++)
945 {
946 if (h2->m[j] != NULL)
947 {
948 hh->m[k] = pp_Mult_qq(h1->m[i],h2->m[j],R);
949 k++;
950 }
951 }
952 }
953 }
954
955 id_Compactify(hh,R);
956 return hh;
957}
958
959/// returns true if h is the zero ideal
961{
962 if ((h!=NULL) && (h->m!=NULL))
963 {
964 for( int i = IDELEMS(h)-1; i >= 0; i-- )
965 if(h->m[i] != NULL)
966 return FALSE;
967 }
968 return TRUE;
969}
970
971/// returns true if h is generated by monomials
973{
974 assume (h != NULL);
975
976 BOOLEAN found_mon=FALSE;
977 if (h->m!=NULL)
978 {
979 for( int i = IDELEMS(h)-1; i >= 0; i-- )
980 {
981 if(h->m[i] != NULL)
982 {
983 if(pNext(h->m[i])!=NULL) return FALSE;
984 found_mon=TRUE;
985 }
986 }
987 }
988 return found_mon;
989}
990
991/// return the maximal component number found in any polynomial in s
992long id_RankFreeModule (ideal s, ring lmRing, ring tailRing)
993{
994 long j = 0;
995
996 if (rRing_has_Comp(tailRing) && rRing_has_Comp(lmRing))
997 {
998 poly *p=s->m;
999 for (unsigned int l=IDELEMS(s); l > 0; --l, ++p)
1000 if (*p != NULL)
1001 {
1002 pp_Test(*p, lmRing, tailRing);
1003 const long k = p_MaxComp(*p, lmRing, tailRing);
1004 if (k>j) j = k;
1005 }
1006 }
1007
1008 return j; // return -1;
1009}
1010
1011BOOLEAN id_IsModule(ideal A, const ring src)
1012{
1013 if ((src->VarOffset[0]== -1)
1014 || (src->pCompIndex<0))
1015 return FALSE; // ring without components
1016 for (int i=IDELEMS(A)-1;i>=0;i--)
1017 {
1018 if (A->m[i]!=NULL)
1019 {
1020 if (p_GetComp(A->m[i],src)>0)
1021 return TRUE;
1022 else
1023 return FALSE;
1024 }
1025 }
1026 return A->rank>1;
1027}
1028
1029
1030/*2
1031*returns true if id is homogeneous with respect to the actual weights
1032*/
1033BOOLEAN id_HomIdeal (ideal id, ideal Q, const ring r)
1034{
1035 int i;
1036 BOOLEAN b;
1037 i = 0;
1038 b = TRUE;
1039 while ((i < IDELEMS(id)) && b)
1040 {
1041 b = p_IsHomogeneous(id->m[i],r);
1042 i++;
1043 }
1044 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1045 {
1046 i=0;
1047 while ((i < IDELEMS(Q)) && b)
1048 {
1049 b = p_IsHomogeneous(Q->m[i],r);
1050 i++;
1051 }
1052 }
1053 return b;
1054}
1055
1056/*2
1057*returns true if id is homogeneous with respect to totaldegree
1058*/
1059BOOLEAN id_HomIdealDP (ideal id, ideal Q, const ring r)
1060{
1061 int i;
1062 BOOLEAN b;
1063 i = 0;
1064 b = TRUE;
1065 while ((i < IDELEMS(id)) && b)
1066 {
1067 b = p_IsHomogeneousDP(id->m[i],r);
1068 i++;
1069 }
1070 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1071 {
1072 i=0;
1073 while ((i < IDELEMS(Q)) && b)
1074 {
1075 b = p_IsHomogeneousDP(Q->m[i],r);
1076 i++;
1077 }
1078 }
1079 return b;
1080}
1081
1082BOOLEAN id_HomIdealW (ideal id, ideal Q, const intvec *w, const ring r)
1083{
1084 int i;
1085 BOOLEAN b;
1086 i = 0;
1087 b = TRUE;
1088 while ((i < IDELEMS(id)) && b)
1089 {
1090 b = p_IsHomogeneousW(id->m[i],w,r);
1091 i++;
1092 }
1093 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1094 {
1095 i=0;
1096 while ((i < IDELEMS(Q)) && b)
1097 {
1098 b = p_IsHomogeneousW(Q->m[i],w,r);
1099 i++;
1100 }
1101 }
1102 return b;
1103}
1104
1105BOOLEAN id_HomModuleW (ideal id, ideal Q, const intvec *w, const intvec *module_w, const ring r)
1106{
1107 int i;
1108 BOOLEAN b;
1109 i = 0;
1110 b = TRUE;
1111 while ((i < IDELEMS(id)) && b)
1112 {
1113 b = p_IsHomogeneousW(id->m[i],w,module_w,r);
1114 i++;
1115 }
1116 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1117 {
1118 i=0;
1119 while ((i < IDELEMS(Q)) && b)
1120 {
1121 b = p_IsHomogeneousW(Q->m[i],w,r);
1122 i++;
1123 }
1124 }
1125 return b;
1126}
1127
1128/*2
1129*initialized a field with r numbers between beg and end for the
1130*procedure idNextChoise
1131*/
1132void idInitChoise (int r,int beg,int end,BOOLEAN *endch,int * choise)
1133{
1134 /*returns the first choise of r numbers between beg and end*/
1135 int i;
1136 for (i=0; i<r; i++)
1137 {
1138 choise[i] = 0;
1139 }
1140 if (r <= end-beg+1)
1141 for (i=0; i<r; i++)
1142 {
1143 choise[i] = beg+i;
1144 }
1145 if (r > end-beg+1)
1146 *endch = TRUE;
1147 else
1148 *endch = FALSE;
1149}
1150
1151/*2
1152*returns the next choise of r numbers between beg and end
1153*/
1154void idGetNextChoise (int r,int end,BOOLEAN *endch,int * choise)
1155{
1156 int i = r-1,j;
1157 while ((i >= 0) && (choise[i] == end))
1158 {
1159 i--;
1160 end--;
1161 }
1162 if (i == -1)
1163 *endch = TRUE;
1164 else
1165 {
1166 choise[i]++;
1167 for (j=i+1; j<r; j++)
1168 {
1169 choise[j] = choise[i]+j-i;
1170 }
1171 *endch = FALSE;
1172 }
1173}
1174
1175/*2
1176*takes the field choise of d numbers between beg and end, cancels the t-th
1177*entree and searches for the ordinal number of that d-1 dimensional field
1178* w.r.t. the algorithm of construction
1179*/
1180int idGetNumberOfChoise(int t, int d, int begin, int end, int * choise)
1181{
1182 int * localchoise,i,result=0;
1183 BOOLEAN b=FALSE;
1184
1185 if (d<=1) return 1;
1186 localchoise=(int*)omAlloc((d-1)*sizeof(int));
1187 idInitChoise(d-1,begin,end,&b,localchoise);
1188 while (!b)
1189 {
1190 result++;
1191 i = 0;
1192 while ((i<t) && (localchoise[i]==choise[i])) i++;
1193 if (i>=t)
1194 {
1195 i = t+1;
1196 while ((i<d) && (localchoise[i-1]==choise[i])) i++;
1197 if (i>=d)
1198 {
1199 omFreeSize((ADDRESS)localchoise,(d-1)*sizeof(int));
1200 return result;
1201 }
1202 }
1203 idGetNextChoise(d-1,end,&b,localchoise);
1204 }
1205 omFreeSize((ADDRESS)localchoise,(d-1)*sizeof(int));
1206 return 0;
1207}
1208
1209/*2
1210*computes the binomial coefficient
1211*/
1212int binom (int n,int r)
1213{
1214 int i;
1215 int64 result;
1216
1217 if (r==0) return 1;
1218 if (n-r<r) return binom(n,n-r);
1219 result = n-r+1;
1220 for (i=2;i<=r;i++)
1221 {
1222 result *= n-r+i;
1223 result /= i;
1224 }
1225 if (result>MAX_INT_VAL)
1226 {
1227 WarnS("overflow in binomials");
1228 result=0;
1229 }
1230 return (int)result;
1231}
1232
1233
1234/// the free module of rank i
1235ideal id_FreeModule (int i, const ring r)
1236{
1237 assume(i >= 0);
1238 if (r->isLPring)
1239 {
1240 PrintS("In order to address bimodules, the command freeAlgebra should be used.");
1241 }
1242 ideal h = idInit(i, i);
1243
1244 for (int j=0; j<i; j++)
1245 {
1246 h->m[j] = p_One(r);
1247 p_SetComp(h->m[j],j+1,r);
1248 p_SetmComp(h->m[j],r);
1249 }
1250
1251 return h;
1252}
1253
1254/*2
1255*computes recursively all monomials of a certain degree
1256*in every step the actvar-th entry in the exponential
1257*vector is incremented and the other variables are
1258*computed by recursive calls of makemonoms
1259*if the last variable is reached, the difference to the
1260*degree is computed directly
1261*vars is the number variables
1262*actvar is the actual variable to handle
1263*deg is the degree of the monomials to compute
1264*monomdeg is the actual degree of the monomial in consideration
1265*/
1266static void makemonoms(int vars,int actvar,int deg,int monomdeg, const ring r)
1267{
1268 poly p;
1269 int i=0;
1270
1271 if ((idpowerpoint == 0) && (actvar ==1))
1272 {
1274 monomdeg = 0;
1275 }
1276 while (i<=deg)
1277 {
1278 if (deg == monomdeg)
1279 {
1281 idpowerpoint++;
1282 return;
1283 }
1284 if (actvar == vars)
1285 {
1286 p_SetExp(idpower[idpowerpoint],actvar,deg-monomdeg,r);
1289 idpowerpoint++;
1290 return;
1291 }
1292 else
1293 {
1295 makemonoms(vars,actvar+1,deg,monomdeg,r);
1297 }
1298 monomdeg++;
1299 p_SetExp(idpower[idpowerpoint],actvar,p_GetExp(idpower[idpowerpoint],actvar,r)+1,r);
1302 i++;
1303 }
1304}
1305
1306#ifdef HAVE_SHIFTBBA
1307/*2
1308*computes recursively all letterplace monomials of a certain degree
1309*vars is the number of original variables (lV)
1310*deg is the degree of the monomials to compute
1311*
1312*NOTE: We use idpowerpoint as the last index of the previous call
1313*/
1314static void lpmakemonoms(int vars, int deg, const ring r)
1315{
1316 assume(deg <= r->N/r->isLPring);
1317 if (deg == 0)
1318 {
1319 idpower[0] = p_One(r);
1320 return;
1321 }
1322 else
1323 {
1324 lpmakemonoms(vars, deg - 1, r);
1325 }
1326
1327 int size = idpowerpoint + 1;
1328 for (int j = 2; j <= vars; j++)
1329 {
1330 for (int i = 0; i < size; i++)
1331 {
1332 idpowerpoint = (j-1)*size + i;
1334 }
1335 }
1336 for (int j = 1; j <= vars; j++)
1337 {
1338 for (int i = 0; i < size; i++)
1339 {
1340 idpowerpoint = (j-1)*size + i;
1341 p_SetExp(idpower[idpowerpoint], ((deg - 1) * r->isLPring) + j, 1, r);
1344 }
1345 }
1346}
1347#endif
1348
1349/*2
1350*returns the deg-th power of the maximal ideal of 0
1351*/
1352ideal id_MaxIdeal(int deg, const ring r)
1353{
1354 if (deg < 1)
1355 {
1356 ideal I=idInit(1,1);
1357 I->m[0]=p_One(r);
1358 return I;
1359 }
1360 if (deg == 1
1361#ifdef HAVE_SHIFTBBA
1362 && !r->isLPring
1363#endif
1364 )
1365 {
1366 return id_MaxIdeal(r);
1367 }
1368
1369 int vars, i;
1370#ifdef HAVE_SHIFTBBA
1371 if (r->isLPring)
1372 {
1373 vars = r->isLPring - r->LPncGenCount;
1374 i = 1;
1375 // i = vars^deg
1376 for (int j = 0; j < deg; j++)
1377 {
1378 i *= vars;
1379 }
1380 }
1381 else
1382#endif
1383 {
1384 vars = rVar(r);
1385 i = binom(vars+deg-1,deg);
1386 }
1387 if (i<=0) return idInit(1,1);
1388 ideal id=idInit(i,1);
1389 idpower = id->m;
1390 idpowerpoint = 0;
1391#ifdef HAVE_SHIFTBBA
1392 if (r->isLPring)
1393 {
1394 lpmakemonoms(vars, deg, r);
1395 }
1396 else
1397#endif
1398 {
1399 makemonoms(vars,1,deg,0,r);
1400 }
1401 idpower = NULL;
1402 idpowerpoint = 0;
1403 return id;
1404}
1405
1406static void id_NextPotence(ideal given, ideal result,
1407 int begin, int end, int deg, int restdeg, poly ap, const ring r)
1408{
1409 poly p;
1410 int i;
1411
1412 p = p_Power(p_Copy(given->m[begin],r),restdeg,r);
1413 i = result->nrows;
1414 result->m[i] = p_Mult_q(p_Copy(ap,r),p,r);
1415//PrintS(".");
1416 (result->nrows)++;
1417 if (result->nrows >= IDELEMS(result))
1418 {
1419 pEnlargeSet(&(result->m),IDELEMS(result),16);
1420 IDELEMS(result) += 16;
1421 }
1422 if (begin == end) return;
1423 for (i=restdeg-1;i>0;i--)
1424 {
1425 p = p_Power(p_Copy(given->m[begin],r),i,r);
1426 p = p_Mult_q(p_Copy(ap,r),p,r);
1427 id_NextPotence(given, result, begin+1, end, deg, restdeg-i, p,r);
1428 p_Delete(&p,r);
1429 }
1430 id_NextPotence(given, result, begin+1, end, deg, restdeg, ap,r);
1431}
1432
1433ideal id_Power(ideal given,int exp, const ring r)
1434{
1435 ideal result,temp;
1436 poly p1;
1437 int i;
1438
1439 if (idIs0(given)) return idInit(1,1);
1440 temp = id_Copy(given,r);
1441 idSkipZeroes(temp);
1442 i = binom(IDELEMS(temp)+exp-1,exp);
1443 result = idInit(i,1);
1444 result->nrows = 0;
1445//Print("ideal contains %d elements\n",i);
1446 p1=p_One(r);
1447 id_NextPotence(temp,result,0,IDELEMS(temp)-1,exp,exp,p1,r);
1448 p_Delete(&p1,r);
1449 id_Delete(&temp,r);
1450 result->nrows = 1;
1453 return result;
1454}
1455
1456/*2
1457*skips all zeroes and double elements, searches also for units
1458*/
1459void id_Compactify(ideal id, const ring r)
1460{
1461 int i;
1462 BOOLEAN b=FALSE;
1463
1464 i = IDELEMS(id)-1;
1465 while ((! b) && (i>=0))
1466 {
1467 b=p_IsUnit(id->m[i],r);
1468 i--;
1469 }
1470 if (b)
1471 {
1472 for(i=IDELEMS(id)-1;i>=0;i--) p_Delete(&id->m[i],r);
1473 id->m[0]=p_One(r);
1474 }
1475 else
1476 {
1477 id_DelMultiples(id,r);
1478 }
1479 idSkipZeroes(id);
1480}
1481
1482/// returns the ideals of initial terms
1483ideal id_Head(ideal h,const ring r)
1484{
1485 ideal m = idInit(IDELEMS(h),h->rank);
1486
1487 if (r->cf->has_simple_Alloc)
1488 {
1489 for (int i=IDELEMS(h)-1;i>=0; i--)
1490 if (h->m[i]!=NULL)
1491 m->m[i]=p_CopyPowerProduct0(h->m[i],pGetCoeff(h->m[i]),r);
1492 }
1493 else
1494 {
1495 for (int i=IDELEMS(h)-1;i>=0; i--)
1496 if (h->m[i]!=NULL)
1497 m->m[i]=p_Head(h->m[i],r);
1498 }
1499
1500 return m;
1501}
1502
1503ideal id_Homogen(ideal h, int varnum,const ring r)
1504{
1505 ideal m = idInit(IDELEMS(h),h->rank);
1506 int i;
1507
1508 for (i=IDELEMS(h)-1;i>=0; i--)
1509 {
1510 m->m[i]=p_Homogen(h->m[i],varnum,r);
1511 }
1512 return m;
1513}
1514
1515ideal id_HomogenDP(ideal h, int varnum,const ring r)
1516{
1517 ideal m = idInit(IDELEMS(h),h->rank);
1518 int i;
1519
1520 for (i=IDELEMS(h)-1;i>=0; i--)
1521 {
1522 m->m[i]=p_HomogenDP(h->m[i],varnum,r);
1523 }
1524 return m;
1525}
1526
1527/*------------------type conversions----------------*/
1528ideal id_Vec2Ideal(poly vec, const ring R)
1529{
1530 ideal result=idInit(1,1);
1532 p_Vec2Polys(vec, &(result->m), &(IDELEMS(result)),R);
1533 return result;
1534}
1535
1536/// for julia: convert an array of poly to vector
1537poly id_Array2Vector(poly *m, unsigned n, const ring R)
1538{
1539 poly h;
1540 int l;
1541 sBucket_pt bucket = sBucketCreate(R);
1542
1543 for(unsigned j=0;j<n ;j++)
1544 {
1545 h = m[j];
1546 if (h!=NULL)
1547 {
1548 h=p_Copy(h, R);
1549 l=pLength(h);
1550 p_SetCompP(h,j+1, R);
1551 sBucket_Merge_p(bucket, h, l);
1552 }
1553 }
1554 sBucketClearMerge(bucket, &h, &l);
1555 sBucketDestroy(&bucket);
1556 return h;
1557}
1558
1559/// converts mat to module, destroys mat
1560ideal id_Matrix2Module(matrix mat, const ring R)
1561{
1562 int mc=MATCOLS(mat);
1563 int mr=MATROWS(mat);
1564 ideal result = idInit(mc,mr);
1565 int i,j,l;
1566 poly h;
1567 sBucket_pt bucket = sBucketCreate(R);
1568
1569 for(j=0;j<mc /*MATCOLS(mat)*/;j++) /* j is also index in result->m */
1570 {
1571 for (i=0;i<mr /*MATROWS(mat)*/;i++)
1572 {
1573 h = MATELEM0(mat,i,j);
1574 if (h!=NULL)
1575 {
1576 l=pLength(h);
1577 MATELEM0(mat,i,j)=NULL;
1578 p_SetCompP(h,i+1, R);
1579 sBucket_Merge_p(bucket, h, l);
1580 }
1581 }
1582 sBucketClearMerge(bucket, &(result->m[j]), &l);
1583 }
1584 sBucketDestroy(&bucket);
1585
1586 // obachman: need to clean this up
1587 id_Delete((ideal*) &mat,R);
1588 return result;
1589}
1590
1591/*2
1592* converts a module into a matrix, destroys the input
1593*/
1594matrix id_Module2Matrix(ideal mod, const ring R)
1595{
1596 matrix result = mpNew(mod->rank,IDELEMS(mod));
1597 long i; long cp;
1598 poly p,h;
1599
1600 for(i=0;i<IDELEMS(mod);i++)
1601 {
1602 p=pReverse(mod->m[i]);
1603 mod->m[i]=NULL;
1604 while (p!=NULL)
1605 {
1606 h=p;
1607 pIter(p);
1608 pNext(h)=NULL;
1609 cp = si_max(1L,p_GetComp(h, R)); // if used for ideals too
1610 //cp = p_GetComp(h,R);
1611 p_SetComp(h,0,R);
1612 p_SetmComp(h,R);
1613#ifdef TEST
1614 if (cp>mod->rank)
1615 {
1616 Print("## inv. rank %ld -> %ld\n",mod->rank,cp);
1617 int k,l,o=mod->rank;
1618 mod->rank=cp;
1619 matrix d=mpNew(mod->rank,IDELEMS(mod));
1620 for (l=0; l<o; l++)
1621 {
1622 for (k=0; k<IDELEMS(mod); k++)
1623 {
1626 }
1627 }
1628 id_Delete((ideal *)&result,R);
1629 result=d;
1630 }
1631#endif
1632 MATELEM0(result,cp-1,i) = p_Add_q(MATELEM0(result,cp-1,i),h,R);
1633 }
1634 }
1635 // obachman 10/99: added the following line, otherwise memory leak!
1636 id_Delete(&mod,R);
1637 return result;
1638}
1639
1640matrix id_Module2formatedMatrix(ideal mod,int rows, int cols, const ring R)
1641{
1642 matrix result = mpNew(rows,cols);
1643 int i,cp,r=id_RankFreeModule(mod,R),c=IDELEMS(mod);
1644 poly p,h;
1645
1646 if (r>rows) r = rows;
1647 if (c>cols) c = cols;
1648 for(i=0;i<c;i++)
1649 {
1650 p=pReverse(mod->m[i]);
1651 mod->m[i]=NULL;
1652 while (p!=NULL)
1653 {
1654 h=p;
1655 pIter(p);
1656 pNext(h)=NULL;
1657 cp = p_GetComp(h,R);
1658 if (cp<=r)
1659 {
1660 p_SetComp(h,0,R);
1661 p_SetmComp(h,R);
1662 MATELEM0(result,cp-1,i) = p_Add_q(MATELEM0(result,cp-1,i),h,R);
1663 }
1664 else
1665 p_Delete(&h,R);
1666 }
1667 }
1668 id_Delete(&mod,R);
1669 return result;
1670}
1671
1672ideal id_ResizeModule(ideal mod,int rows, int cols, const ring R)
1673{
1674 // columns?
1675 if (cols!=IDELEMS(mod))
1676 {
1677 for(int i=IDELEMS(mod)-1;i>=cols;i--) p_Delete(&mod->m[i],R);
1678 pEnlargeSet(&(mod->m),IDELEMS(mod),cols-IDELEMS(mod));
1679 IDELEMS(mod)=cols;
1680 }
1681 // rows?
1682 if (rows<mod->rank)
1683 {
1684 for(int i=IDELEMS(mod)-1;i>=0;i--)
1685 {
1686 if (mod->m[i]!=NULL)
1687 {
1688 while((mod->m[i]!=NULL) && (p_GetComp(mod->m[i],R)>rows))
1689 mod->m[i]=p_LmDeleteAndNext(mod->m[i],R);
1690 poly p=mod->m[i];
1691 while(pNext(p)!=NULL)
1692 {
1693 if (p_GetComp(pNext(p),R)>rows)
1695 else
1696 pIter(p);
1697 }
1698 }
1699 }
1700 }
1701 mod->rank=rows;
1702 return mod;
1703}
1704
1705/*2
1706* substitute the n-th variable by the monomial e in id
1707* destroy id
1708*/
1709ideal id_Subst(ideal id, int n, poly e, const ring r)
1710{
1711 int k=MATROWS((matrix)id)*MATCOLS((matrix)id);
1712 ideal res=(ideal)mpNew(MATROWS((matrix)id),MATCOLS((matrix)id));
1713
1714 res->rank = id->rank;
1715 for(k--;k>=0;k--)
1716 {
1717 res->m[k]=p_Subst(id->m[k],n,e,r);
1718 id->m[k]=NULL;
1719 }
1720 id_Delete(&id,r);
1721 return res;
1722}
1723
1724BOOLEAN id_HomModule(ideal m, ideal Q, intvec **w, const ring R)
1725{
1726 if (w!=NULL) *w=NULL;
1727 if ((Q!=NULL) && (!id_HomIdeal(Q,NULL,R))) return FALSE;
1728 if (idIs0(m))
1729 {
1730 if (w!=NULL) (*w)=new intvec(m->rank);
1731 return TRUE;
1732 }
1733
1734 long cmax=1,order=0,ord,* diff,diffmin=32000;
1735 int *iscom;
1736 int i;
1737 poly p=NULL;
1738 pFDegProc d;
1739 if (R->pLexOrder && (R->order[0]==ringorder_lp))
1740 d=p_Totaldegree;
1741 else
1742 d=R->pFDeg;
1743 int length=IDELEMS(m);
1744 poly* P=m->m;
1745 poly* F=(poly*)omAlloc(length*sizeof(poly));
1746 for (i=length-1;i>=0;i--)
1747 {
1748 p=F[i]=P[i];
1749 cmax=si_max(cmax,p_MaxComp(p,R));
1750 }
1751 cmax++;
1752 diff = (long *)omAlloc0(cmax*sizeof(long));
1753 if (w!=NULL) *w=new intvec(cmax-1);
1754 iscom = (int *)omAlloc0(cmax*sizeof(int));
1755 i=0;
1756 while (i<=length)
1757 {
1758 if (i<length)
1759 {
1760 p=F[i];
1761 while ((p!=NULL) && (iscom[__p_GetComp(p,R)]==0)) pIter(p);
1762 }
1763 if ((p==NULL) && (i<length))
1764 {
1765 i++;
1766 }
1767 else
1768 {
1769 if (p==NULL) /* && (i==length) */
1770 {
1771 i=0;
1772 while ((i<length) && (F[i]==NULL)) i++;
1773 if (i>=length) break;
1774 p = F[i];
1775 }
1776 //if (pLexOrder && (currRing->order[0]==ringorder_lp))
1777 // order=pTotaldegree(p);
1778 //else
1779 // order = p->order;
1780 // order = pFDeg(p,currRing);
1781 order = d(p,R) +diff[__p_GetComp(p,R)];
1782 //order += diff[pGetComp(p)];
1783 p = F[i];
1784//Print("Actual p=F[%d]: ",i);pWrite(p);
1785 F[i] = NULL;
1786 i=0;
1787 }
1788 while (p!=NULL)
1789 {
1790 if (R->pLexOrder && (R->order[0]==ringorder_lp))
1791 ord=p_Totaldegree(p,R);
1792 else
1793 // ord = p->order;
1794 ord = R->pFDeg(p,R);
1795 if (iscom[__p_GetComp(p,R)]==0)
1796 {
1797 diff[__p_GetComp(p,R)] = order-ord;
1798 iscom[__p_GetComp(p,R)] = 1;
1799/*
1800*PrintS("new diff: ");
1801*for (j=0;j<cmax;j++) Print("%d ",diff[j]);
1802*PrintLn();
1803*PrintS("new iscom: ");
1804*for (j=0;j<cmax;j++) Print("%d ",iscom[j]);
1805*PrintLn();
1806*Print("new set %d, order %d, ord %d, diff %d\n",pGetComp(p),order,ord,diff[pGetComp(p)]);
1807*/
1808 }
1809 else
1810 {
1811/*
1812*PrintS("new diff: ");
1813*for (j=0;j<cmax;j++) Print("%d ",diff[j]);
1814*PrintLn();
1815*Print("order %d, ord %d, diff %d\n",order,ord,diff[pGetComp(p)]);
1816*/
1817 if (order != (ord+diff[__p_GetComp(p,R)]))
1818 {
1819 omFreeSize((ADDRESS) iscom,cmax*sizeof(int));
1820 omFreeSize((ADDRESS) diff,cmax*sizeof(long));
1821 omFreeSize((ADDRESS) F,length*sizeof(poly));
1822 delete *w;*w=NULL;
1823 return FALSE;
1824 }
1825 }
1826 pIter(p);
1827 }
1828 }
1829 omFreeSize((ADDRESS) iscom,cmax*sizeof(int));
1830 omFreeSize((ADDRESS) F,length*sizeof(poly));
1831 for (i=1;i<cmax;i++) (**w)[i-1]=(int)(diff[i]);
1832 for (i=1;i<cmax;i++)
1833 {
1834 if (diff[i]<diffmin) diffmin=diff[i];
1835 }
1836 if (w!=NULL)
1837 {
1838 for (i=1;i<cmax;i++)
1839 {
1840 (**w)[i-1]=(int)(diff[i]-diffmin);
1841 }
1842 }
1843 omFreeSize((ADDRESS) diff,cmax*sizeof(long));
1844 return TRUE;
1845}
1846
1847ideal id_Jet(const ideal i,int d, const ring R)
1848{
1849 ideal r=idInit((i->nrows)*(i->ncols),i->rank);
1850 r->nrows = i-> nrows;
1851 r->ncols = i-> ncols;
1852 //r->rank = i-> rank;
1853
1854 for(long k=((long)(i->nrows))*((long)(i->ncols))-1;k>=0; k--)
1855 r->m[k]=pp_Jet(i->m[k],d,R);
1856
1857 return r;
1858}
1859
1860ideal id_Jet0(const ideal i, const ring R)
1861{
1862 ideal r=idInit((i->nrows)*(i->ncols),i->rank);
1863 r->nrows = i-> nrows;
1864 r->ncols = i-> ncols;
1865 //r->rank = i-> rank;
1866
1867 for(long k=((long)(i->nrows))*((long)(i->ncols))-1;k>=0; k--)
1868 r->m[k]=pp_Jet0(i->m[k],R);
1869
1870 return r;
1871}
1872
1873ideal id_JetW(const ideal i,int d, intvec * iv, const ring R)
1874{
1875 ideal r=idInit(IDELEMS(i),i->rank);
1876 if (ecartWeights!=NULL)
1877 {
1878 WerrorS("cannot compute weighted jets now");
1879 }
1880 else
1881 {
1882 int *w=iv2array(iv,R);
1883 int k;
1884 for(k=0; k<IDELEMS(i); k++)
1885 {
1886 r->m[k]=pp_JetW(i->m[k],d,w,R);
1887 }
1888 omFreeSize((ADDRESS)w,(rVar(R)+1)*sizeof(int));
1889 }
1890 return r;
1891}
1892
1893#if 0
1894static void idDeleteComp(ideal arg,int red_comp)
1895{
1896 int i,j;
1897 poly p;
1898
1899 for (i=IDELEMS(arg)-1;i>=0;i--)
1900 {
1901 p = arg->m[i];
1902 while (p!=NULL)
1903 {
1904 j = pGetComp(p);
1905 if (j>red_comp)
1906 {
1907 pSetComp(p,j-1);
1908 pSetm(p);
1909 }
1910 pIter(p);
1911 }
1912 }
1913 (arg->rank)--;
1914}
1915#endif
1916
1917intvec * id_QHomWeight(ideal id, const ring r)
1918{
1919 poly head, tail;
1920 int k;
1921 int in=IDELEMS(id)-1, ready=0, all=0,
1922 coldim=rVar(r), rowmax=2*coldim;
1923 if (in<0) return NULL;
1924 intvec *imat=new intvec(rowmax+1,coldim,0);
1925
1926 do
1927 {
1928 head = id->m[in--];
1929 if (head!=NULL)
1930 {
1931 tail = pNext(head);
1932 while (tail!=NULL)
1933 {
1934 all++;
1935 for (k=1;k<=coldim;k++)
1936 IMATELEM(*imat,all,k) = p_GetExpDiff(head,tail,k,r);
1937 if (all==rowmax)
1938 {
1939 ivTriangIntern(imat, ready, all);
1940 if (ready==coldim)
1941 {
1942 delete imat;
1943 return NULL;
1944 }
1945 }
1946 pIter(tail);
1947 }
1948 }
1949 } while (in>=0);
1950 if (all>ready)
1951 {
1952 ivTriangIntern(imat, ready, all);
1953 if (ready==coldim)
1954 {
1955 delete imat;
1956 return NULL;
1957 }
1958 }
1959 intvec *result = ivSolveKern(imat, ready);
1960 delete imat;
1961 return result;
1962}
1963
1964BOOLEAN id_IsZeroDim(ideal I, const ring r)
1965{
1966 BOOLEAN *UsedAxis=(BOOLEAN *)omAlloc0(rVar(r)*sizeof(BOOLEAN));
1967 int i,n;
1968 poly po;
1970 for(i=IDELEMS(I)-1;i>=0;i--)
1971 {
1972 po=I->m[i];
1973 if ((po!=NULL) &&((n=p_IsPurePower(po,r))!=0)) UsedAxis[n-1]=TRUE;
1974 }
1975 for(i=rVar(r)-1;i>=0;i--)
1976 {
1977 if(UsedAxis[i]==FALSE) {res=FALSE; break;} // not zero-dim.
1978 }
1979 omFreeSize(UsedAxis,rVar(r)*sizeof(BOOLEAN));
1980 return res;
1981}
1982
1983void id_Normalize(ideal I,const ring r) /* for ideal/matrix */
1984{
1985 if (rField_has_simple_inverse(r)) return; /* Z/p, GF(p,n), R, long R/C */
1986 int i;
1987 for(i=I->nrows*I->ncols-1;i>=0;i--)
1988 {
1989 poly p=I->m[i];
1990 if (p!=NULL) p_Normalize(p,r);
1991 }
1992}
1993
1994int id_MinDegW(ideal M,intvec *w, const ring r)
1995{
1996 int d=-1;
1997 for(int i=0;i<IDELEMS(M);i++)
1998 {
1999 if (M->m[i]!=NULL)
2000 {
2001 int d0=p_MinDeg(M->m[i],w,r);
2002 if(-1<d0&&((d0<d)||(d==-1)))
2003 d=d0;
2004 }
2005 }
2006 return d;
2007}
2008
2009// #include "kernel/clapsing.h"
2010
2011/*2
2012* transpose a module
2013*/
2014ideal id_Transp(ideal a, const ring rRing)
2015{
2016 int r = a->rank, c = IDELEMS(a);
2017 ideal b = idInit(r,c);
2018
2019 int i;
2020 for (i=c; i>0; i--)
2021 {
2022 poly p=a->m[i-1];
2023 while(p!=NULL)
2024 {
2025 poly h=p_Head(p, rRing);
2026 int co=__p_GetComp(h, rRing)-1;
2027 p_SetComp(h, i, rRing);
2028 p_Setm(h, rRing);
2029 h->next=b->m[co];
2030 b->m[co]=h;
2031 pIter(p);
2032 }
2033 }
2034 for (i=IDELEMS(b)-1; i>=0; i--)
2035 {
2036 poly p=b->m[i];
2037 if(p!=NULL)
2038 {
2039 b->m[i]=p_SortMerge(p,rRing,TRUE);
2040 }
2041 }
2042 return b;
2043}
2044
2045/*2
2046* The following is needed to compute the image of certain map used in
2047* the computation of cohomologies via BGG
2048* let M = { w_1, ..., w_k }, k = size(M) == ncols(M), n = nvars(currRing).
2049* assuming that nrows(M) <= m*n; the procedure computes:
2050* transpose(M) * transpose( var(1) I_m | ... | var(n) I_m ) :== transpose(module{f_1, ... f_k}),
2051* where f_i = \sum_{j=1}^{m} (w_i, v_j) gen(j), (w_i, v_j) is a `scalar` multiplication.
2052* that is, if w_i = (a^1_1, ... a^1_m) | (a^2_1, ..., a^2_m) | ... | (a^n_1, ..., a^n_m) then
2053
2054 (a^1_1, ... a^1_m) | (a^2_1, ..., a^2_m) | ... | (a^n_1, ..., a^n_m)
2055* var_1 ... var_1 | var_2 ... var_2 | ... | var_n ... var(n)
2056* gen_1 ... gen_m | gen_1 ... gen_m | ... | gen_1 ... gen_m
2057+ =>
2058 f_i =
2059
2060 a^1_1 * var(1) * gen(1) + ... + a^1_m * var(1) * gen(m) +
2061 a^2_1 * var(2) * gen(1) + ... + a^2_m * var(2) * gen(m) +
2062 ...
2063 a^n_1 * var(n) * gen(1) + ... + a^n_m * var(n) * gen(m);
2064
2065 NOTE: for every f_i we run only ONCE along w_i saving partial sums into a temporary array of polys of size m
2066*/
2067ideal id_TensorModuleMult(const int m, const ideal M, const ring rRing)
2068{
2069// #ifdef DEBU
2070// WarnS("tensorModuleMult!!!!");
2071
2072 assume(m > 0);
2073 assume(M != NULL);
2074
2075 const int n = rRing->N;
2076
2077 assume(M->rank <= m * n);
2078
2079 const int k = IDELEMS(M);
2080
2081 ideal idTemp = idInit(k,m); // = {f_1, ..., f_k }
2082
2083 for( int i = 0; i < k; i++ ) // for every w \in M
2084 {
2085 poly pTempSum = NULL;
2086
2087 poly w = M->m[i];
2088
2089 while(w != NULL) // for each term of w...
2090 {
2091 poly h = p_Head(w, rRing);
2092
2093 const int gen = __p_GetComp(h, rRing); // 1 ...
2094
2095 assume(gen > 0);
2096 assume(gen <= n*m);
2097
2098 // TODO: write a formula with %, / instead of while!
2099 /*
2100 int c = gen;
2101 int v = 1;
2102 while(c > m)
2103 {
2104 c -= m;
2105 v++;
2106 }
2107 */
2108
2109 int cc = gen % m;
2110 if( cc == 0) cc = m;
2111 int vv = 1 + (gen - cc) / m;
2112
2113// assume( cc == c );
2114// assume( vv == v );
2115
2116 // 1<= c <= m
2117 assume( cc > 0 );
2118 assume( cc <= m );
2119
2120 assume( vv > 0 );
2121 assume( vv <= n );
2122
2123 assume( (cc + (vv-1)*m) == gen );
2124
2125 p_IncrExp(h, vv, rRing); // h *= var(j) && // p_AddExp(h, vv, 1, rRing);
2126 p_SetComp(h, cc, rRing);
2127
2128 p_Setm(h, rRing); // adjust degree after the previous steps!
2129
2130 pTempSum = p_Add_q(pTempSum, h, rRing); // it is slow since h will be usually put to the back of pTempSum!!!
2131
2132 pIter(w);
2133 }
2134
2135 idTemp->m[i] = pTempSum;
2136 }
2137
2138 // simplify idTemp???
2139
2140 ideal idResult = id_Transp(idTemp, rRing);
2141
2142 id_Delete(&idTemp, rRing);
2143
2144 return(idResult);
2145}
2146
2147ideal id_ChineseRemainder(ideal *xx, number *q, int rl, const ring r)
2148{
2149 int cnt=0;int rw=0; int cl=0;
2150 int i,j;
2151 // find max. size of xx[.]:
2152 for(j=rl-1;j>=0;j--)
2153 {
2154 i=IDELEMS(xx[j])*xx[j]->nrows;
2155 if (i>cnt) cnt=i;
2156 if (xx[j]->nrows >rw) rw=xx[j]->nrows; // for lifting matrices
2157 if (xx[j]->ncols >cl) cl=xx[j]->ncols; // for lifting matrices
2158 }
2159 if (rw*cl !=cnt)
2160 {
2161 WerrorS("format mismatch in CRT");
2162 return NULL;
2163 }
2164 ideal result=idInit(cnt,xx[0]->rank);
2165 result->nrows=rw; // for lifting matrices
2166 result->ncols=cl; // for lifting matrices
2167 number *x=(number *)omAlloc(rl*sizeof(number));
2168 poly *p=(poly *)omAlloc(rl*sizeof(poly));
2169 CFArray inv_cache(rl);
2170 EXTERN_VAR int n_SwitchChinRem; //TEST
2171 int save_n_SwitchChinRem=n_SwitchChinRem;
2173 for(i=cnt-1;i>=0;i--)
2174 {
2175 for(j=rl-1;j>=0;j--)
2176 {
2177 if(i>=IDELEMS(xx[j])*xx[j]->nrows) // out of range of this ideal
2178 p[j]=NULL;
2179 else
2180 p[j]=xx[j]->m[i];
2181 }
2182 result->m[i]=p_ChineseRemainder(p,x,q,rl,inv_cache,r);
2183 for(j=rl-1;j>=0;j--)
2184 {
2185 if(i<IDELEMS(xx[j])*xx[j]->nrows) xx[j]->m[i]=p[j];
2186 }
2187 }
2188 n_SwitchChinRem=save_n_SwitchChinRem;
2189 omFreeSize(p,rl*sizeof(poly));
2190 omFreeSize(x,rl*sizeof(number));
2191 for(i=rl-1;i>=0;i--) id_Delete(&(xx[i]),r);
2192 omFreeSize(xx,rl*sizeof(ideal));
2193 return result;
2194}
2195
2196void id_Shift(ideal M, int s, const ring r)
2197{
2198// id_Test( M, r );
2199
2200// assume( s >= 0 ); // negative is also possible // TODO: verify input ideal in such a case!?
2201
2202 for(int i=IDELEMS(M)-1; i>=0;i--)
2203 p_Shift(&(M->m[i]),s,r);
2204
2205 M->rank += s;
2206
2207// id_Test( M, r );
2208}
2209
2210ideal id_Delete_Pos(const ideal I, const int p, const ring r)
2211{
2212 if ((p<0)||(p>=IDELEMS(I))) return NULL;
2213 ideal ret=idInit(IDELEMS(I)-1,I->rank);
2214 for(int i=0;i<p;i++) ret->m[i]=p_Copy(I->m[i],r);
2215 for(int i=p+1;i<IDELEMS(I);i++) ret->m[i-1]=p_Copy(I->m[i],r);
2216 return ret;
2217}
2218
2219ideal id_PermIdeal(ideal I,int R, int C,const int *perm, const ring src, const ring dst,
2220 nMapFunc nMap, const int *par_perm, int P, BOOLEAN use_mult)
2221{
2222 ideal II=(ideal)mpNew(R,C);
2223 II->rank=I->rank;
2224 for(int i=R*C-1; i>=0; i--)
2225 {
2226 II->m[i]=p_PermPoly(I->m[i],perm,src,dst,nMap,par_perm,P,use_mult);
2227 }
2228 return II;
2229}
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
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:3074
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:4484
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:4730
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:4084
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: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_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:3939
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:4512
int p_MinDeg(poly p, intvec *w, const ring R)
Definition p_polys.cc:4602
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition p_polys.cc:4934
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:4557
poly p_CopyPowerProduct0(const poly p, number n, const ring r)
like p_Head, but with coefficient n
Definition p_polys.cc:5122
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:4666
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:598
static BOOLEAN rField_has_simple_inverse(const ring r)
Definition ring.h:554
#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)
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)
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