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
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)
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
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
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
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
202{
203 assume (ide != NULL);
204
205 int k;
206 int j = -1;
207 int idelems=IDELEMS(ide);
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
236int idSkipZeroes0 (ideal ide) /*idSkipZeroes without realloc*/
237{
238 assume (ide != NULL);
239
240 int k;
241 int j = -1;
242 int idelems=IDELEMS(ide);
243
244 k=0;
245 while((k<idelems)&&(ide->m[k] != NULL)) k++;
246 if (k==idelems) return idelems;
247 // now: k: pos of first NULL entry
248 j=k; k=k+1;
249 for (; k<idelems; k++)
250 {
251 if (ide->m[k] != NULL)
252 {
253 ide->m[j] = ide->m[k];
254 ide->m[k] = NULL;
255 j++;
256 }
257 }
258 if (j<=1) return 1;
259 return j;
260}
261
262/// copies the first k (>= 1) entries of the given ideal/module
263/// and returns these as a new ideal/module
264/// (Note that the copied entries may be zero.)
265ideal id_CopyFirstK (const ideal ide, const int k,const ring r)
266{
267 id_Test(ide, r);
268
269 assume( ide != NULL );
270 assume( k <= IDELEMS(ide) );
271
272 ideal newI = idInit(k, ide->rank);
273
274 for (int i = 0; i < k; i++)
275 newI->m[i] = p_Copy(ide->m[i],r);
276
277 return newI;
278}
279
280/// ideal id = (id[i]), result is leadcoeff(id[i]) = 1
281void id_Norm(ideal id, const ring r)
282{
283 id_Test(id, r);
284 for (int i=IDELEMS(id)-1; i>=0; i--)
285 {
286 if (id->m[i] != NULL)
287 {
288 p_Norm(id->m[i],r);
289 }
290 }
291}
292
293/// ideal id = (id[i]), c any unit
294/// if id[i] = c*id[j] then id[j] is deleted for j > i
295void id_DelMultiples(ideal id, const ring r)
296{
297 id_Test(id, r);
298
299 int i, j;
300 int k = IDELEMS(id)-1;
301 for (i=k; i>=0; i--)
302 {
303 if (id->m[i]!=NULL)
304 {
305 for (j=k; j>i; j--)
306 {
307 if (id->m[j]!=NULL)
308 {
309 if (rField_is_Ring(r))
310 {
311 /* if id[j] = c*id[i] then delete id[j].
312 In the below cases of a ground field, we
313 check whether id[i] = c*id[j] and, if so,
314 delete id[j] for historical reasons (so
315 that previous output does not change) */
316 if (p_ComparePolys(id->m[j], id->m[i],r)) p_Delete(&id->m[j],r);
317 }
318 else
319 {
320 if (p_ComparePolys(id->m[i], id->m[j],r)) p_Delete(&id->m[j],r);
321 }
322 }
323 }
324 }
325 }
326}
327
328/// ideal id = (id[i])
329/// if id[i] = id[j] then id[j] is deleted for j > i
330void id_DelEquals(ideal id, const ring r)
331{
332 id_Test(id, r);
333
334 int i, j;
335 int k = IDELEMS(id)-1;
336 for (i=k; i>=0; i--)
337 {
338 if (id->m[i]!=NULL)
339 {
340 for (j=k; j>i; j--)
341 {
342 if ((id->m[j]!=NULL)
343 && (p_EqualPolys(id->m[i], id->m[j],r)))
344 {
345 p_Delete(&id->m[j],r);
346 }
347 }
348 }
349 }
350}
351
352/// Delete id[j], if Lm(j) == Lm(i) and both LC(j), LC(i) are units and j > i
353void id_DelLmEquals(ideal id, const ring r)
354{
355 id_Test(id, r);
356
357 int i, j;
358 int k = IDELEMS(id)-1;
359 for (i=k; i>=0; i--)
360 {
361 if (id->m[i] != NULL)
362 {
363 for (j=k; j>i; j--)
364 {
365 if ((id->m[j] != NULL)
366 && p_LmEqual(id->m[i], id->m[j],r)
368 && n_IsUnit(pGetCoeff(id->m[i]),r->cf) && n_IsUnit(pGetCoeff(id->m[j]),r->cf)
369#endif
370 )
371 {
372 p_Delete(&id->m[j],r);
373 }
374 }
375 }
376 }
377}
378
379/// delete id[j], if LT(j) == coeff*mon*LT(i)
380static void id_DelDiv_SEV(ideal id, int k,const ring r)
381{
382 int kk = k+1;
383 long *sev=(long*)omAlloc0(kk*sizeof(long));
384 while(id->m[k]==NULL) k--;
385 BOOLEAN only_lm=r->cf->has_simple_Alloc;
386 if (only_lm)
387 {
388 for (int i=k; i>=0; i--)
389 {
390 if((id->m[i]!=NULL) && (pNext(id->m[i])!=NULL))
391 {
393 break;
394 }
395 }
396 }
397 for (int i=k; i>=0; i--)
398 {
399 if(id->m[i]!=NULL)
400 {
401 sev[i]=p_GetShortExpVector(id->m[i],r);
402 }
403 }
404 if (only_lm)
405 {
406 for (int i=0; i<k; i++)
407 {
408 if (id->m[i] != NULL)
409 {
410 poly m_i=id->m[i];
411 long sev_i=sev[i];
412 for (int j=i+1; j<=k; j++)
413 {
414 if (id->m[j]!=NULL)
415 {
416 if (p_LmShortDivisibleBy(m_i, sev_i,id->m[j],~sev[j],r))
417 {
418 p_LmFree(&id->m[j],r);
419 }
420 else if (p_LmShortDivisibleBy(id->m[j],sev[j], m_i,~sev_i,r))
421 {
422 p_LmFree(&id->m[i],r);
423 break;
424 }
425 }
426 }
427 }
428 }
429 }
430 else
431 {
432 for (int i=0; i<k; i++)
433 {
434 if (id->m[i] != NULL)
435 {
436 poly m_i=id->m[i];
437 long sev_i=sev[i];
438 for (int j=i+1; j<=k; j++)
439 {
440 if (id->m[j]!=NULL)
441 {
442 if (p_LmShortDivisibleBy(m_i, sev_i, id->m[j],~sev[j],r))
443 {
444 p_Delete(&id->m[j],r);
445 }
446 else if (p_LmShortDivisibleBy(id->m[j],sev[j], m_i,~sev_i,r))
447 {
448 p_Delete(&id->m[i],r);
449 break;
450 }
451 }
452 }
453 }
454 }
455 }
456 omFreeSize(sev,kk*sizeof(long));
457}
458
459
460/// delete id[j], if LT(j) == coeff*mon*LT(i) and vice versa, i.e.,
461/// delete id[i], if LT(i) == coeff*mon*LT(j)
462void id_DelDiv(ideal id, const ring r)
463{
464 id_Test(id, r);
465
466 int i, j;
467 int k = IDELEMS(id)-1;
468#ifdef HAVE_RINGS
469 if (rField_is_Ring(r))
470 {
471 for (i=k-1; i>=0; i--)
472 {
473 if (id->m[i] != NULL)
474 {
475 for (j=k; j>i; j--)
476 {
477 if (id->m[j]!=NULL)
478 {
479 if (p_DivisibleByRingCase(id->m[i], id->m[j],r))
480 {
481 p_Delete(&id->m[j],r);
482 }
483 else if (p_DivisibleByRingCase(id->m[j], id->m[i],r))
484 {
485 p_Delete(&id->m[i],r);
486 break;
487 }
488 }
489 }
490 }
491 }
492 }
493 else
494#endif
495 {
496 /* the case of a coefficient field: */
497 if (k>9)
498 {
499 id_DelDiv_SEV(id,k,r);
500 return;
501 }
502 for (i=k-1; i>=0; i--)
503 {
504 if (id->m[i] != NULL)
505 {
506 for (j=k; j>i; j--)
507 {
508 if (id->m[j]!=NULL)
509 {
510 if (p_LmDivisibleBy(id->m[i], id->m[j],r))
511 {
512 p_Delete(&id->m[j],r);
513 }
514 else if (p_LmDivisibleBy(id->m[j], id->m[i],r))
515 {
516 p_Delete(&id->m[i],r);
517 break;
518 }
519 }
520 }
521 }
522 }
523 }
524}
525
526/// test if the ideal has only constant polynomials
527/// NOTE: zero ideal/module is also constant
529{
530 id_Test(id, r);
531
532 for (int k = IDELEMS(id)-1; k>=0; k--)
533 {
534 if (!p_IsConstantPoly(id->m[k],r))
535 return FALSE;
536 }
537 return TRUE;
538}
539
540/// copy an ideal
542{
543 id_Test(h1, r);
544
545 ideal h2 = idInit(IDELEMS(h1), h1->rank);
546 for (int i=IDELEMS(h1)-1; i>=0; i--)
547 h2->m[i] = p_Copy(h1->m[i],r);
548 return h2;
549}
550
551#ifdef PDEBUG
552/// Internal verification for ideals/modules and dense matrices!
553void id_DBTest(ideal h1, int level, const char *f,const int l, const ring r, const ring tailRing)
554{
555 if (h1 != NULL)
556 {
557 // assume(IDELEMS(h1) > 0); for ideal/module, does not apply to matrix
558 omCheckAddrSize(h1,sizeof(*h1));
559
560 assume( h1->ncols >= 0 );
561 assume( h1->nrows >= 0 ); // matrix case!
562
563 assume( h1->rank >= 0 );
564
565 const long n = ((long)h1->ncols * (long)h1->nrows);
566
567 assume( !( n > 0 && h1->m == NULL) );
568
569 if( h1->m != NULL && n > 0 )
570 omdebugAddrSize(h1->m, n * sizeof(poly));
571
572 long new_rk = 0; // inlining id_RankFreeModule(h1, r, tailRing);
573
574 /* to be able to test matrices: */
575 for (long i=n - 1; i >= 0; i--)
576 {
577 _pp_Test(h1->m[i], r, tailRing, level);
578 const long k = p_MaxComp(h1->m[i], r, tailRing);
579 if (k > new_rk) new_rk = k;
580 }
581
582 // dense matrices only contain polynomials:
583 // h1->nrows == h1->rank > 1 && new_rk == 0!
584 assume( !( h1->nrows == h1->rank && h1->nrows > 1 && new_rk > 0 ) ); //
585
586 if(new_rk > h1->rank)
587 {
588 dReportError("wrong rank %d (should be %d) in %s:%d\n",
589 h1->rank, new_rk, f,l);
590 omPrintAddrInfo(stderr, h1, " for ideal");
591 h1->rank = new_rk;
592 }
593 }
594 else
595 {
596 Print("error: ideal==NULL in %s:%d\n",f,l);
597 assume( h1 != NULL );
598 }
599}
600#endif
601
602#ifdef PDEBUG
603/// Internal verification for ideals/modules and dense matrices!
604void id_DBLmTest(ideal h1, int level, const char *f,const int l, const ring r)
605{
606 if (h1 != NULL)
607 {
608 // assume(IDELEMS(h1) > 0); for ideal/module, does not apply to matrix
609 omCheckAddrSize(h1,sizeof(*h1));
610
611 assume( h1->ncols >= 0 );
612 assume( h1->nrows >= 0 ); // matrix case!
613
614 assume( h1->rank >= 0 );
615
616 const long n = ((long)h1->ncols * (long)h1->nrows);
617
618 assume( !( n > 0 && h1->m == NULL) );
619
620 if( h1->m != NULL && n > 0 )
621 omdebugAddrSize(h1->m, n * sizeof(poly));
622
623 long new_rk = 0; // inlining id_RankFreeModule(h1, r, tailRing);
624
625 /* to be able to test matrices: */
626 for (long i=n - 1; i >= 0; i--)
627 {
628 if (h1->m[i]!=NULL)
629 {
630 _p_LmTest(h1->m[i], r, level);
631 const long k = p_GetComp(h1->m[i], r);
632 if (k > new_rk) new_rk = k;
633 }
634 }
635
636 // dense matrices only contain polynomials:
637 // h1->nrows == h1->rank > 1 && new_rk == 0!
638 assume( !( h1->nrows == h1->rank && h1->nrows > 1 && new_rk > 0 ) ); //
639
640 if(new_rk > h1->rank)
641 {
642 dReportError("wrong rank %d (should be %d) in %s:%d\n",
643 h1->rank, new_rk, f,l);
644 omPrintAddrInfo(stderr, h1, " for ideal");
645 h1->rank = new_rk;
646 }
647 }
648 else
649 {
650 Print("error: ideal==NULL in %s:%d\n",f,l);
651 assume( h1 != NULL );
652 }
653}
654#endif
655
656/// for idSort: compare a and b revlex inclusive module comp.
657static int p_Comp_RevLex(poly a, poly b,BOOLEAN nolex, const ring R)
658{
659 if (b==NULL) return 1;
660 if (a==NULL) return -1;
661
662 if (nolex)
663 {
664 int r=p_LtCmp(a,b,R);
665 return r;
666 #if 0
667 if (r!=0) return r;
669 r = -1+n_IsZero(h,R->cf)+2*n_GreaterZero(h,R->cf); /* -1: <, 0:==, 1: > */
670 n_Delete(&h, R->cf);
671 return r;
672 #endif
673 }
674 int l=rVar(R);
675 while ((l>0) && (p_GetExp(a,l,R)==p_GetExp(b,l,R))) l--;
676 if (l==0)
677 {
678 if (p_GetComp(a,R)==p_GetComp(b,R))
679 {
681 int r = -1+n_IsZero(h,R->cf)+2*n_GreaterZero(h,R->cf); /* -1: <, 0:==, 1: > */
682 n_Delete(&h,R->cf);
683 return r;
684 }
685 if (p_GetComp(a,R)>p_GetComp(b,R)) return 1;
686 }
687 else if (p_GetExp(a,l,R)>p_GetExp(b,l,R))
688 return 1;
689 return -1;
690}
691
692// sorts the ideal w.r.t. the actual ringordering
693// uses lex-ordering when nolex = FALSE
694intvec *id_Sort(const ideal id, const BOOLEAN nolex, const ring r)
695{
696 id_Test(id, r);
697
698 intvec * result = new intvec(IDELEMS(id));
699 int i, j, actpos=0, newpos;
702
703 for (i=0;i<IDELEMS(id);i++)
704 {
705 if (id->m[i]!=NULL)
706 {
707 notFound = TRUE;
708 newpos = actpos / 2;
709 diff = (actpos+1) / 2;
710 diff = (diff+1) / 2;
711 lastcomp = p_Comp_RevLex(id->m[i],id->m[(*result)[newpos]],nolex,r);
712 if (lastcomp<0)
713 {
714 newpos -= diff;
715 }
716 else if (lastcomp>0)
717 {
718 newpos += diff;
719 }
720 else
721 {
722 notFound = FALSE;
723 }
724 //while ((newpos>=0) && (newpos<actpos) && (notFound))
725 while (notFound && (newpos>=0) && (newpos<actpos))
726 {
727 newcomp = p_Comp_RevLex(id->m[i],id->m[(*result)[newpos]],nolex,r);
728 olddiff = diff;
729 if (diff>1)
730 {
731 diff = (diff+1) / 2;
732 if ((newcomp==1)
733 && (actpos-newpos>1)
734 && (diff>1)
735 && (newpos+diff>=actpos))
736 {
737 diff = actpos-newpos-1;
738 }
739 else if ((newcomp==-1)
740 && (diff>1)
741 && (newpos<diff))
742 {
743 diff = newpos;
744 }
745 }
746 if (newcomp<0)
747 {
748 if ((olddiff==1) && (lastcomp>0))
749 notFound = FALSE;
750 else
751 newpos -= diff;
752 }
753 else if (newcomp>0)
754 {
755 if ((olddiff==1) && (lastcomp<0))
756 {
757 notFound = FALSE;
758 newpos++;
759 }
760 else
761 {
762 newpos += diff;
763 }
764 }
765 else
766 {
767 notFound = FALSE;
768 }
770 if (diff==0) notFound=FALSE; /*hs*/
771 }
772 if (newpos<0) newpos = 0;
773 if (newpos>actpos) newpos = actpos;
774 while ((newpos<actpos) && (p_Comp_RevLex(id->m[i],id->m[(*result)[newpos]],nolex,r)==0))
775 newpos++;
776 for (j=actpos;j>newpos;j--)
777 {
778 (*result)[j] = (*result)[j-1];
779 }
780 (*result)[newpos] = i;
781 actpos++;
782 }
783 }
784 for (j=0;j<actpos;j++) (*result)[j]++;
785 return result;
786}
787
788/// concat the lists h1 and h2 without zeros
790{
791 id_Test(h1, R);
792 id_Test(h2, R);
793
794 if ( idIs0(h1) )
795 {
797 if (res->rank<h1->rank) res->rank=h1->rank;
798 return res;
799 }
800 if ( idIs0(h2) )
801 {
803 if (res->rank<h2->rank) res->rank=h2->rank;
804 return res;
805 }
806
807 int j = IDELEMS(h1)-1;
808 while ((j >= 0) && (h1->m[j] == NULL)) j--;
809
810 int i = IDELEMS(h2)-1;
811 while ((i >= 0) && (h2->m[i] == NULL)) i--;
812
813 const int r = si_max(h1->rank, h2->rank);
814
815 ideal result = idInit(i+j+2,r);
816
817 int l;
818
819 for (l=j; l>=0; l--)
820 result->m[l] = p_Copy(h1->m[l],R);
821
822 j = i+j+1;
823 for (l=i; l>=0; l--, j--)
824 result->m[j] = p_Copy(h2->m[l],R);
825
826 return result;
827}
828
829/// insert h2 into h1 (if h2 is not the zero polynomial)
830/// return TRUE iff h2 was indeed inserted
832{
833 if (h2==NULL) return FALSE;
834 assume (h1 != NULL);
835
836 int j = IDELEMS(h1) - 1;
837
838 while ((j >= 0) && (h1->m[j] == NULL)) j--;
839 j++;
840 if (j==IDELEMS(h1))
841 {
842 pEnlargeSet(&(h1->m),IDELEMS(h1),16);
843 IDELEMS(h1)+=16;
844 }
845 h1->m[j]=h2;
846 return TRUE;
847}
848
849/// insert p into I on position pos
851{
852 if (p==NULL) return FALSE;
853 assume (I != NULL);
854
855 int j = IDELEMS(I) - 1;
856
857 while ((j >= 0) && (I->m[j] == NULL)) j--;
858 j++;
859 if (j==IDELEMS(I))
860 {
861 pEnlargeSet(&(I->m),IDELEMS(I),IDELEMS(I)+1);
862 IDELEMS(I)+=1;
863 }
864 for(j = IDELEMS(I)-1;j>pos;j--)
865 I->m[j] = I->m[j-1];
866 I->m[pos]=p;
867 return TRUE;
868}
869
870
871/*! insert h2 into h1 depending on the two boolean parameters:
872 * - if zeroOk is true, then h2 will also be inserted when it is zero
873 * - if duplicateOk is true, then h2 will also be inserted when it is
874 * already present in h1
875 * return TRUE iff h2 was indeed inserted
876 */
878 const poly h2, const bool zeroOk, const bool duplicateOk, const ring r)
879{
880 id_Test(h1, r);
881 p_Test(h2, r);
882
883 if ((!zeroOk) && (h2 == NULL)) return FALSE;
884 if (!duplicateOk)
885 {
886 bool h2FoundInH1 = false;
887 int i = 0;
888 while ((i < validEntries) && (!h2FoundInH1))
889 {
890 h2FoundInH1 = p_EqualPolys(h1->m[i], h2,r);
891 i++;
892 }
893 if (h2FoundInH1) return FALSE;
894 }
895 if (validEntries == IDELEMS(h1))
896 {
897 pEnlargeSet(&(h1->m), IDELEMS(h1), 16);
898 IDELEMS(h1) += 16;
899 }
900 h1->m[validEntries] = h2;
901 return TRUE;
902}
903
904/// h1 + h2
906{
907 id_Test(h1, r);
908 id_Test(h2, r);
909
912 return result;
913}
914
915/// h1 * h2
916/// one h_i must be an ideal (with at least one column)
917/// the other h_i may be a module (with no columns at all)
919{
920 id_Test(h1, R);
921 id_Test(h2, R);
922
923 int j = IDELEMS(h1);
924 while ((j > 0) && (h1->m[j-1] == NULL)) j--;
925
926 int i = IDELEMS(h2);
927 while ((i > 0) && (h2->m[i-1] == NULL)) i--;
928
929 j *= i;
930 int r = si_max( h2->rank, h1->rank );
931 if (j==0)
932 {
933 if ((IDELEMS(h1)>0) && (IDELEMS(h2)>0)) j=1;
934 return idInit(j, r);
935 }
936 ideal hh = idInit(j, r);
937
938 int k = 0;
939 for (i=0; i<IDELEMS(h1); i++)
940 {
941 if (h1->m[i] != NULL)
942 {
943 for (j=0; j<IDELEMS(h2); j++)
944 {
945 if (h2->m[j] != NULL)
946 {
947 hh->m[k] = pp_Mult_qq(h1->m[i],h2->m[j],R);
948 k++;
949 }
950 }
951 }
952 }
953
955 return hh;
956}
957
958/// returns true if h is the zero ideal
960{
961 assume (h != NULL); // will fail :(
962
963 if (h->m!=NULL)
964 {
965 for( int i = IDELEMS(h)-1; i >= 0; i-- )
966 if(h->m[i] != NULL)
967 return FALSE;
968 }
969 return TRUE;
970}
971
972/// returns true if h is generated by monomials
974{
975 assume (h != NULL);
976
978 if (h->m!=NULL)
979 {
980 for( int i = IDELEMS(h)-1; i >= 0; i-- )
981 {
982 if(h->m[i] != NULL)
983 {
984 if(pNext(h->m[i])!=NULL) return FALSE;
986 }
987 }
988 }
989 return found_mon;
990}
991
992/// return the maximal component number found in any polynomial in s
994{
995 long j = 0;
996
997 if (rRing_has_Comp(tailRing) && rRing_has_Comp(lmRing))
998 {
999 poly *p=s->m;
1000 for (unsigned int l=IDELEMS(s); l > 0; --l, ++p)
1001 if (*p != NULL)
1002 {
1003 pp_Test(*p, lmRing, tailRing);
1004 const long k = p_MaxComp(*p, lmRing, tailRing);
1005 if (k>j) j = k;
1006 }
1007 }
1008
1009 return j; // return -1;
1010}
1011
1013{
1014 if ((src->VarOffset[0]== -1)
1015 || (src->pCompIndex<0))
1016 return FALSE; // ring without components
1017 for (int i=IDELEMS(A)-1;i>=0;i--)
1018 {
1019 if (A->m[i]!=NULL)
1020 {
1021 if (p_GetComp(A->m[i],src)>0)
1022 return TRUE;
1023 else
1024 return FALSE;
1025 }
1026 }
1027 return A->rank>1;
1028}
1029
1030
1031/*2
1032*returns true if id is homogeneous with respect to the actual weights
1033*/
1035{
1036 int i;
1037 BOOLEAN b;
1038 i = 0;
1039 b = TRUE;
1040 while ((i < IDELEMS(id)) && b)
1041 {
1042 b = p_IsHomogeneous(id->m[i],r);
1043 i++;
1044 }
1045 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1046 {
1047 i=0;
1048 while ((i < IDELEMS(Q)) && b)
1049 {
1050 b = p_IsHomogeneous(Q->m[i],r);
1051 i++;
1052 }
1053 }
1054 return b;
1055}
1056
1057/*2
1058*returns true if id is homogeneous with respect to totaldegree
1059*/
1061{
1062 int i;
1063 BOOLEAN b;
1064 i = 0;
1065 b = TRUE;
1066 while ((i < IDELEMS(id)) && b)
1067 {
1068 b = p_IsHomogeneousDP(id->m[i],r);
1069 i++;
1070 }
1071 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1072 {
1073 i=0;
1074 while ((i < IDELEMS(Q)) && b)
1075 {
1076 b = p_IsHomogeneousDP(Q->m[i],r);
1077 i++;
1078 }
1079 }
1080 return b;
1081}
1082
1084{
1085 int i;
1086 BOOLEAN b;
1087 i = 0;
1088 b = TRUE;
1089 while ((i < IDELEMS(id)) && b)
1090 {
1091 b = p_IsHomogeneousW(id->m[i],w,r);
1092 i++;
1093 }
1094 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1095 {
1096 i=0;
1097 while ((i < IDELEMS(Q)) && b)
1098 {
1099 b = p_IsHomogeneousW(Q->m[i],w,r);
1100 i++;
1101 }
1102 }
1103 return b;
1104}
1105
1107{
1108 int i;
1109 BOOLEAN b;
1110 i = 0;
1111 b = TRUE;
1112 while ((i < IDELEMS(id)) && b)
1113 {
1114 b = p_IsHomogeneousW(id->m[i],w,module_w,r);
1115 i++;
1116 }
1117 if ((b) && (Q!=NULL) && (IDELEMS(Q)>0))
1118 {
1119 i=0;
1120 while ((i < IDELEMS(Q)) && b)
1121 {
1122 b = p_IsHomogeneousW(Q->m[i],w,r);
1123 i++;
1124 }
1125 }
1126 return b;
1127}
1128
1129/*2
1130*initialized a field with r numbers between beg and end for the
1131*procedure idNextChoise
1132*/
1133void idInitChoise (int r,int beg,int end,BOOLEAN *endch,int * choise)
1134{
1135 /*returns the first choise of r numbers between beg and end*/
1136 int i;
1137 for (i=0; i<r; i++)
1138 {
1139 choise[i] = 0;
1140 }
1141 if (r <= end-beg+1)
1142 for (i=0; i<r; i++)
1143 {
1144 choise[i] = beg+i;
1145 }
1146 if (r > end-beg+1)
1147 *endch = TRUE;
1148 else
1149 *endch = FALSE;
1150}
1151
1152/*2
1153*returns the next choise of r numbers between beg and end
1154*/
1155void idGetNextChoise (int r,int end,BOOLEAN *endch,int * choise)
1156{
1157 int i = r-1,j;
1158 while ((i >= 0) && (choise[i] == end))
1159 {
1160 i--;
1161 end--;
1162 }
1163 if (i == -1)
1164 *endch = TRUE;
1165 else
1166 {
1167 choise[i]++;
1168 for (j=i+1; j<r; j++)
1169 {
1170 choise[j] = choise[i]+j-i;
1171 }
1172 *endch = FALSE;
1173 }
1174}
1175
1176/*2
1177*takes the field choise of d numbers between beg and end, cancels the t-th
1178*entree and searches for the ordinal number of that d-1 dimensional field
1179* w.r.t. the algorithm of construction
1180*/
1181int idGetNumberOfChoise(int t, int d, int begin, int end, int * choise)
1182{
1183 int * localchoise,i,result=0;
1184 BOOLEAN b=FALSE;
1185
1186 if (d<=1) return 1;
1187 localchoise=(int*)omAlloc((d-1)*sizeof(int));
1188 idInitChoise(d-1,begin,end,&b,localchoise);
1189 while (!b)
1190 {
1191 result++;
1192 i = 0;
1193 while ((i<t) && (localchoise[i]==choise[i])) i++;
1194 if (i>=t)
1195 {
1196 i = t+1;
1197 while ((i<d) && (localchoise[i-1]==choise[i])) i++;
1198 if (i>=d)
1199 {
1200 omFreeSize((ADDRESS)localchoise,(d-1)*sizeof(int));
1201 return result;
1202 }
1203 }
1204 idGetNextChoise(d-1,end,&b,localchoise);
1205 }
1206 omFreeSize((ADDRESS)localchoise,(d-1)*sizeof(int));
1207 return 0;
1208}
1209
1210/*2
1211*computes the binomial coefficient
1212*/
1213int binom (int n,int r)
1214{
1215 int i;
1216 int64 result;
1217
1218 if (r==0) return 1;
1219 if (n-r<r) return binom(n,n-r);
1220 result = n-r+1;
1221 for (i=2;i<=r;i++)
1222 {
1223 result *= n-r+i;
1224 result /= i;
1225 }
1226 if (result>MAX_INT_VAL)
1227 {
1228 WarnS("overflow in binomials");
1229 result=0;
1230 }
1231 return (int)result;
1232}
1233
1234
1235/// the free module of rank i
1237{
1238 assume(i >= 0);
1239 if (r->isLPring)
1240 {
1241 PrintS("In order to address bimodules, the command freeAlgebra should be used.");
1242 }
1243 ideal h = idInit(i, i);
1244
1245 for (int j=0; j<i; j++)
1246 {
1247 h->m[j] = p_One(r);
1248 p_SetComp(h->m[j],j+1,r);
1249 p_SetmComp(h->m[j],r);
1250 }
1251
1252 return h;
1253}
1254
1255/*2
1256*computes recursively all monomials of a certain degree
1257*in every step the actvar-th entry in the exponential
1258*vector is incremented and the other variables are
1259*computed by recursive calls of makemonoms
1260*if the last variable is reached, the difference to the
1261*degree is computed directly
1262*vars is the number variables
1263*actvar is the actual variable to handle
1264*deg is the degree of the monomials to compute
1265*monomdeg is the actual degree of the monomial in consideration
1266*/
1267static void makemonoms(int vars,int actvar,int deg,int monomdeg, const ring r)
1268{
1269 poly p;
1270 int i=0;
1271
1272 if ((idpowerpoint == 0) && (actvar ==1))
1273 {
1275 monomdeg = 0;
1276 }
1277 while (i<=deg)
1278 {
1279 if (deg == monomdeg)
1280 {
1282 idpowerpoint++;
1283 return;
1284 }
1285 if (actvar == vars)
1286 {
1290 idpowerpoint++;
1291 return;
1292 }
1293 else
1294 {
1296 makemonoms(vars,actvar+1,deg,monomdeg,r);
1298 }
1299 monomdeg++;
1303 i++;
1304 }
1305}
1306
1307#ifdef HAVE_SHIFTBBA
1308/*2
1309*computes recursively all letterplace monomials of a certain degree
1310*vars is the number of original variables (lV)
1311*deg is the degree of the monomials to compute
1312*
1313*NOTE: We use idpowerpoint as the last index of the previous call
1314*/
1315static void lpmakemonoms(int vars, int deg, const ring r)
1316{
1317 assume(deg <= r->N/r->isLPring);
1318 if (deg == 0)
1319 {
1320 idpower[0] = p_One(r);
1321 return;
1322 }
1323 else
1324 {
1325 lpmakemonoms(vars, deg - 1, r);
1326 }
1327
1328 int size = idpowerpoint + 1;
1329 for (int j = 2; j <= vars; j++)
1330 {
1331 for (int i = 0; i < size; i++)
1332 {
1333 idpowerpoint = (j-1)*size + i;
1335 }
1336 }
1337 for (int j = 1; j <= vars; j++)
1338 {
1339 for (int i = 0; i < size; i++)
1340 {
1341 idpowerpoint = (j-1)*size + i;
1342 p_SetExp(idpower[idpowerpoint], ((deg - 1) * r->isLPring) + j, 1, r);
1345 }
1346 }
1347}
1348#endif
1349
1350/*2
1351*returns the deg-th power of the maximal ideal of 0
1352*/
1353ideal id_MaxIdeal(int deg, const ring r)
1354{
1355 if (deg < 1)
1356 {
1357 ideal I=idInit(1,1);
1358 I->m[0]=p_One(r);
1359 return I;
1360 }
1361 if (deg == 1
1363 && !r->isLPring
1364#endif
1365 )
1366 {
1367 return id_MaxIdeal(r);
1368 }
1369
1370 int vars, i;
1371#ifdef HAVE_SHIFTBBA
1372 if (r->isLPring)
1373 {
1374 vars = r->isLPring - r->LPncGenCount;
1375 i = 1;
1376 // i = vars^deg
1377 for (int j = 0; j < deg; j++)
1378 {
1379 i *= vars;
1380 }
1381 }
1382 else
1383#endif
1384 {
1385 vars = rVar(r);
1386 i = binom(vars+deg-1,deg);
1387 }
1388 if (i<=0) return idInit(1,1);
1389 ideal id=idInit(i,1);
1390 idpower = id->m;
1391 idpowerpoint = 0;
1392#ifdef HAVE_SHIFTBBA
1393 if (r->isLPring)
1394 {
1395 lpmakemonoms(vars, deg, r);
1396 }
1397 else
1398#endif
1399 {
1400 makemonoms(vars,1,deg,0,r);
1401 }
1402 idpower = NULL;
1403 idpowerpoint = 0;
1404 return id;
1405}
1406
1408 int begin, int end, int deg, int restdeg, poly ap, const ring r)
1409{
1410 poly p;
1411 int i;
1412
1413 p = p_Power(p_Copy(given->m[begin],r),restdeg,r);
1414 i = result->nrows;
1415 result->m[i] = p_Mult_q(p_Copy(ap,r),p,r);
1416//PrintS(".");
1417 (result->nrows)++;
1418 if (result->nrows >= IDELEMS(result))
1419 {
1420 pEnlargeSet(&(result->m),IDELEMS(result),16);
1421 IDELEMS(result) += 16;
1422 }
1423 if (begin == end) return;
1424 for (i=restdeg-1;i>0;i--)
1425 {
1426 p = p_Power(p_Copy(given->m[begin],r),i,r);
1427 p = p_Mult_q(p_Copy(ap,r),p,r);
1428 id_NextPotence(given, result, begin+1, end, deg, restdeg-i, p,r);
1429 p_Delete(&p,r);
1430 }
1431 id_NextPotence(given, result, begin+1, end, deg, restdeg, ap,r);
1432}
1433
1435{
1437 poly p1;
1438 int i;
1439
1440 if (idIs0(given)) return idInit(1,1);
1441 temp = id_Copy(given,r);
1443 i = binom(IDELEMS(temp)+exp-1,exp);
1444 result = idInit(i,1);
1445 result->nrows = 0;
1446//Print("ideal contains %d elements\n",i);
1447 p1=p_One(r);
1449 p_Delete(&p1,r);
1450 id_Delete(&temp,r);
1451 result->nrows = 1;
1454 return result;
1455}
1456
1457/*2
1458*skips all zeroes and double elements, searches also for units
1459*/
1460void id_Compactify(ideal id, const ring r)
1461{
1462 int i;
1463 BOOLEAN b=FALSE;
1464
1465 i = IDELEMS(id)-1;
1466 while ((! b) && (i>=0))
1467 {
1468 b=p_IsUnit(id->m[i],r);
1469 i--;
1470 }
1471 if (b)
1472 {
1473 for(i=IDELEMS(id)-1;i>=0;i--) p_Delete(&id->m[i],r);
1474 id->m[0]=p_One(r);
1475 }
1476 else
1477 {
1478 id_DelMultiples(id,r);
1479 }
1480 idSkipZeroes(id);
1481}
1482
1483/// returns the ideals of initial terms
1485{
1486 ideal m = idInit(IDELEMS(h),h->rank);
1487
1488 if (r->cf->has_simple_Alloc)
1489 {
1490 for (int i=IDELEMS(h)-1;i>=0; i--)
1491 if (h->m[i]!=NULL)
1492 m->m[i]=p_CopyPowerProduct0(h->m[i],pGetCoeff(h->m[i]),r);
1493 }
1494 else
1495 {
1496 for (int i=IDELEMS(h)-1;i>=0; i--)
1497 if (h->m[i]!=NULL)
1498 m->m[i]=p_Head(h->m[i],r);
1499 }
1500
1501 return m;
1502}
1503
1505{
1506 ideal m = idInit(IDELEMS(h),h->rank);
1507 int i;
1508
1509 for (i=IDELEMS(h)-1;i>=0; i--)
1510 {
1511 m->m[i]=p_Homogen(h->m[i],varnum,r);
1512 }
1513 return m;
1514}
1515
1517{
1518 ideal m = idInit(IDELEMS(h),h->rank);
1519 int i;
1520
1521 for (i=IDELEMS(h)-1;i>=0; i--)
1522 {
1523 m->m[i]=p_HomogenDP(h->m[i],varnum,r);
1524 }
1525 return m;
1526}
1527
1528/*------------------type conversions----------------*/
1530{
1531 ideal result=idInit(1,1);
1533 p_Vec2Polys(vec, &(result->m), &(IDELEMS(result)),R);
1534 return result;
1535}
1536
1537/// for julia: convert an array of poly to vector
1538poly id_Array2Vector(poly *m, unsigned n, const ring R)
1539{
1540 poly h;
1541 int l;
1542 sBucket_pt bucket = sBucketCreate(R);
1543
1544 for(unsigned j=0;j<n ;j++)
1545 {
1546 h = m[j];
1547 if (h!=NULL)
1548 {
1549 h=p_Copy(h, R);
1550 l=pLength(h);
1551 p_SetCompP(h,j+1, R);
1552 sBucket_Merge_p(bucket, h, l);
1553 }
1554 }
1555 sBucketClearMerge(bucket, &h, &l);
1556 sBucketDestroy(&bucket);
1557 return h;
1558}
1559
1560/// converts mat to module, destroys mat
1562{
1563 int mc=MATCOLS(mat);
1564 int mr=MATROWS(mat);
1565 ideal result = idInit(mc,mr);
1566 int i,j,l;
1567 poly h;
1568 sBucket_pt bucket = sBucketCreate(R);
1569
1570 for(j=0;j<mc /*MATCOLS(mat)*/;j++) /* j is also index in result->m */
1571 {
1572 for (i=0;i<mr /*MATROWS(mat)*/;i++)
1573 {
1574 h = MATELEM0(mat,i,j);
1575 if (h!=NULL)
1576 {
1577 l=pLength(h);
1578 MATELEM0(mat,i,j)=NULL;
1579 p_SetCompP(h,i+1, R);
1580 sBucket_Merge_p(bucket, h, l);
1581 }
1582 }
1583 sBucketClearMerge(bucket, &(result->m[j]), &l);
1584 }
1585 sBucketDestroy(&bucket);
1586
1587 // obachman: need to clean this up
1588 id_Delete((ideal*) &mat,R);
1589 return result;
1590}
1591
1592/*2
1593* converts a module into a matrix, destroys the input
1594*/
1596{
1597 matrix result = mpNew(mod->rank,IDELEMS(mod));
1598 long i; long cp;
1599 poly p,h;
1600
1601 for(i=0;i<IDELEMS(mod);i++)
1602 {
1603 p=pReverse(mod->m[i]);
1604 mod->m[i]=NULL;
1605 while (p!=NULL)
1606 {
1607 h=p;
1608 pIter(p);
1609 pNext(h)=NULL;
1610 cp = si_max(1L,p_GetComp(h, R)); // if used for ideals too
1611 //cp = p_GetComp(h,R);
1612 p_SetComp(h,0,R);
1613 p_SetmComp(h,R);
1614#ifdef TEST
1615 if (cp>mod->rank)
1616 {
1617 Print("## inv. rank %ld -> %ld\n",mod->rank,cp);
1618 int k,l,o=mod->rank;
1619 mod->rank=cp;
1620 matrix d=mpNew(mod->rank,IDELEMS(mod));
1621 for (l=0; l<o; l++)
1622 {
1623 for (k=0; k<IDELEMS(mod); k++)
1624 {
1627 }
1628 }
1629 id_Delete((ideal *)&result,R);
1630 result=d;
1631 }
1632#endif
1633 MATELEM0(result,cp-1,i) = p_Add_q(MATELEM0(result,cp-1,i),h,R);
1634 }
1635 }
1636 // obachman 10/99: added the following line, otherwise memory leak!
1637 id_Delete(&mod,R);
1638 return result;
1639}
1640
1641matrix id_Module2formatedMatrix(ideal mod,int rows, int cols, const ring R)
1642{
1643 matrix result = mpNew(rows,cols);
1644 int i,cp,r=id_RankFreeModule(mod,R),c=IDELEMS(mod);
1645 poly p,h;
1646
1647 if (r>rows) r = rows;
1648 if (c>cols) c = cols;
1649 for(i=0;i<c;i++)
1650 {
1651 p=pReverse(mod->m[i]);
1652 mod->m[i]=NULL;
1653 while (p!=NULL)
1654 {
1655 h=p;
1656 pIter(p);
1657 pNext(h)=NULL;
1658 cp = p_GetComp(h,R);
1659 if (cp<=r)
1660 {
1661 p_SetComp(h,0,R);
1662 p_SetmComp(h,R);
1663 MATELEM0(result,cp-1,i) = p_Add_q(MATELEM0(result,cp-1,i),h,R);
1664 }
1665 else
1666 p_Delete(&h,R);
1667 }
1668 }
1669 id_Delete(&mod,R);
1670 return result;
1671}
1672
1673ideal id_ResizeModule(ideal mod,int rows, int cols, const ring R)
1674{
1675 // columns?
1676 if (cols!=IDELEMS(mod))
1677 {
1678 for(int i=IDELEMS(mod)-1;i>=cols;i--) p_Delete(&mod->m[i],R);
1679 pEnlargeSet(&(mod->m),IDELEMS(mod),cols-IDELEMS(mod));
1680 IDELEMS(mod)=cols;
1681 }
1682 // rows?
1683 if (rows<mod->rank)
1684 {
1685 for(int i=IDELEMS(mod)-1;i>=0;i--)
1686 {
1687 if (mod->m[i]!=NULL)
1688 {
1689 while((mod->m[i]!=NULL) && (p_GetComp(mod->m[i],R)>rows))
1690 mod->m[i]=p_LmDeleteAndNext(mod->m[i],R);
1691 poly p=mod->m[i];
1692 while(pNext(p)!=NULL)
1693 {
1694 if (p_GetComp(pNext(p),R)>rows)
1696 else
1697 pIter(p);
1698 }
1699 }
1700 }
1701 }
1702 mod->rank=rows;
1703 return mod;
1704}
1705
1706/*2
1707* substitute the n-th variable by the monomial e in id
1708* destroy id
1709*/
1710ideal id_Subst(ideal id, int n, poly e, const ring r)
1711{
1712 int k=MATROWS((matrix)id)*MATCOLS((matrix)id);
1714
1715 res->rank = id->rank;
1716 for(k--;k>=0;k--)
1717 {
1718 res->m[k]=p_Subst(id->m[k],n,e,r);
1719 id->m[k]=NULL;
1720 }
1721 id_Delete(&id,r);
1722 return res;
1723}
1724
1726{
1727 if (w!=NULL) *w=NULL;
1728 if ((Q!=NULL) && (!id_HomIdeal(Q,NULL,R))) return FALSE;
1729 if (idIs0(m))
1730 {
1731 if (w!=NULL) (*w)=new intvec(m->rank);
1732 return TRUE;
1733 }
1734
1735 long cmax=1,order=0,ord,* diff,diffmin=32000;
1736 int *iscom;
1737 int i;
1738 poly p=NULL;
1739 pFDegProc d;
1740 if (R->pLexOrder && (R->order[0]==ringorder_lp))
1741 d=p_Totaldegree;
1742 else
1743 d=R->pFDeg;
1744 int length=IDELEMS(m);
1745 poly* P=m->m;
1746 poly* F=(poly*)omAlloc(length*sizeof(poly));
1747 for (i=length-1;i>=0;i--)
1748 {
1749 p=F[i]=P[i];
1751 }
1752 cmax++;
1753 diff = (long *)omAlloc0(cmax*sizeof(long));
1754 if (w!=NULL) *w=new intvec(cmax-1);
1755 iscom = (int *)omAlloc0(cmax*sizeof(int));
1756 i=0;
1757 while (i<=length)
1758 {
1759 if (i<length)
1760 {
1761 p=F[i];
1762 while ((p!=NULL) && (iscom[__p_GetComp(p,R)]==0)) pIter(p);
1763 }
1764 if ((p==NULL) && (i<length))
1765 {
1766 i++;
1767 }
1768 else
1769 {
1770 if (p==NULL) /* && (i==length) */
1771 {
1772 i=0;
1773 while ((i<length) && (F[i]==NULL)) i++;
1774 if (i>=length) break;
1775 p = F[i];
1776 }
1777 //if (pLexOrder && (currRing->order[0]==ringorder_lp))
1778 // order=pTotaldegree(p);
1779 //else
1780 // order = p->order;
1781 // order = pFDeg(p,currRing);
1782 order = d(p,R) +diff[__p_GetComp(p,R)];
1783 //order += diff[pGetComp(p)];
1784 p = F[i];
1785//Print("Actual p=F[%d]: ",i);pWrite(p);
1786 F[i] = NULL;
1787 i=0;
1788 }
1789 while (p!=NULL)
1790 {
1791 if (R->pLexOrder && (R->order[0]==ringorder_lp))
1792 ord=p_Totaldegree(p,R);
1793 else
1794 // ord = p->order;
1795 ord = R->pFDeg(p,R);
1796 if (iscom[__p_GetComp(p,R)]==0)
1797 {
1798 diff[__p_GetComp(p,R)] = order-ord;
1799 iscom[__p_GetComp(p,R)] = 1;
1800/*
1801*PrintS("new diff: ");
1802*for (j=0;j<cmax;j++) Print("%d ",diff[j]);
1803*PrintLn();
1804*PrintS("new iscom: ");
1805*for (j=0;j<cmax;j++) Print("%d ",iscom[j]);
1806*PrintLn();
1807*Print("new set %d, order %d, ord %d, diff %d\n",pGetComp(p),order,ord,diff[pGetComp(p)]);
1808*/
1809 }
1810 else
1811 {
1812/*
1813*PrintS("new diff: ");
1814*for (j=0;j<cmax;j++) Print("%d ",diff[j]);
1815*PrintLn();
1816*Print("order %d, ord %d, diff %d\n",order,ord,diff[pGetComp(p)]);
1817*/
1818 if (order != (ord+diff[__p_GetComp(p,R)]))
1819 {
1820 omFreeSize((ADDRESS) iscom,cmax*sizeof(int));
1821 omFreeSize((ADDRESS) diff,cmax*sizeof(long));
1822 omFreeSize((ADDRESS) F,length*sizeof(poly));
1823 delete *w;*w=NULL;
1824 return FALSE;
1825 }
1826 }
1827 pIter(p);
1828 }
1829 }
1830 omFreeSize((ADDRESS) iscom,cmax*sizeof(int));
1831 omFreeSize((ADDRESS) F,length*sizeof(poly));
1832 for (i=1;i<cmax;i++) (**w)[i-1]=(int)(diff[i]);
1833 for (i=1;i<cmax;i++)
1834 {
1835 if (diff[i]<diffmin) diffmin=diff[i];
1836 }
1837 if (w!=NULL)
1838 {
1839 for (i=1;i<cmax;i++)
1840 {
1841 (**w)[i-1]=(int)(diff[i]-diffmin);
1842 }
1843 }
1844 omFreeSize((ADDRESS) diff,cmax*sizeof(long));
1845 return TRUE;
1846}
1847
1848ideal id_Jet(const ideal i,int d, const ring R)
1849{
1850 ideal r=idInit((i->nrows)*(i->ncols),i->rank);
1851 r->nrows = i-> nrows;
1852 r->ncols = i-> ncols;
1853 //r->rank = i-> rank;
1854
1855 for(long k=((long)(i->nrows))*((long)(i->ncols))-1;k>=0; k--)
1856 r->m[k]=pp_Jet(i->m[k],d,R);
1857
1858 return r;
1859}
1860
1861ideal id_Jet0(const ideal i, const ring R)
1862{
1863 ideal r=idInit((i->nrows)*(i->ncols),i->rank);
1864 r->nrows = i-> nrows;
1865 r->ncols = i-> ncols;
1866 //r->rank = i-> rank;
1867
1868 for(long k=((long)(i->nrows))*((long)(i->ncols))-1;k>=0; k--)
1869 r->m[k]=pp_Jet0(i->m[k],R);
1870
1871 return r;
1872}
1873
1874ideal id_JetW(const ideal i,int d, intvec * iv, const ring R)
1875{
1876 ideal r=idInit(IDELEMS(i),i->rank);
1877 if (ecartWeights!=NULL)
1878 {
1879 WerrorS("cannot compute weighted jets now");
1880 }
1881 else
1882 {
1883 int *w=iv2array(iv,R);
1884 int k;
1885 for(k=0; k<IDELEMS(i); k++)
1886 {
1887 r->m[k]=pp_JetW(i->m[k],d,w,R);
1888 }
1889 omFreeSize((ADDRESS)w,(rVar(R)+1)*sizeof(int));
1890 }
1891 return r;
1892}
1893
1894#if 0
1895static void idDeleteComp(ideal arg,int red_comp)
1896{
1897 int i,j;
1898 poly p;
1899
1900 for (i=IDELEMS(arg)-1;i>=0;i--)
1901 {
1902 p = arg->m[i];
1903 while (p!=NULL)
1904 {
1905 j = pGetComp(p);
1906 if (j>red_comp)
1907 {
1908 pSetComp(p,j-1);
1909 pSetm(p);
1910 }
1911 pIter(p);
1912 }
1913 }
1914 (arg->rank)--;
1915}
1916#endif
1917
1919{
1920 poly head, tail;
1921 int k;
1922 int in=IDELEMS(id)-1, ready=0, all=0,
1923 coldim=rVar(r), rowmax=2*coldim;
1924 if (in<0) return NULL;
1925 intvec *imat=new intvec(rowmax+1,coldim,0);
1926
1927 do
1928 {
1929 head = id->m[in--];
1930 if (head!=NULL)
1931 {
1932 tail = pNext(head);
1933 while (tail!=NULL)
1934 {
1935 all++;
1936 for (k=1;k<=coldim;k++)
1937 IMATELEM(*imat,all,k) = p_GetExpDiff(head,tail,k,r);
1938 if (all==rowmax)
1939 {
1940 ivTriangIntern(imat, ready, all);
1941 if (ready==coldim)
1942 {
1943 delete imat;
1944 return NULL;
1945 }
1946 }
1947 pIter(tail);
1948 }
1949 }
1950 } while (in>=0);
1951 if (all>ready)
1952 {
1953 ivTriangIntern(imat, ready, all);
1954 if (ready==coldim)
1955 {
1956 delete imat;
1957 return NULL;
1958 }
1959 }
1960 intvec *result = ivSolveKern(imat, ready);
1961 delete imat;
1962 return result;
1963}
1964
1966{
1967 BOOLEAN *UsedAxis=(BOOLEAN *)omAlloc0(rVar(r)*sizeof(BOOLEAN));
1968 int i,n;
1969 poly po;
1971 for(i=IDELEMS(I)-1;i>=0;i--)
1972 {
1973 po=I->m[i];
1974 if ((po!=NULL) &&((n=p_IsPurePower(po,r))!=0)) UsedAxis[n-1]=TRUE;
1975 }
1976 for(i=rVar(r)-1;i>=0;i--)
1977 {
1978 if(UsedAxis[i]==FALSE) {res=FALSE; break;} // not zero-dim.
1979 }
1980 omFreeSize(UsedAxis,rVar(r)*sizeof(BOOLEAN));
1981 return res;
1982}
1983
1984void id_Normalize(ideal I,const ring r) /* for ideal/matrix */
1985{
1986 if (rField_has_simple_inverse(r)) return; /* Z/p, GF(p,n), R, long R/C */
1987 int i;
1988 for(i=I->nrows*I->ncols-1;i>=0;i--)
1989 {
1990 p_Normalize(I->m[i],r);
1991 }
1992}
1993
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*/
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
2141
2143
2144 return(idResult);
2145}
2146
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));
2170 EXTERN_VAR int n_SwitchChinRem; //TEST
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 }
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 }
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
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
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
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:519
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:498
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition coeffs.h:468
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:656
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
Definition coeffs.h:459
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:85
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:3085
matrix mpNew(int r, int c)
create a r x c zero-matrix
Definition matpol.cc:37
#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:4439
poly p_HomogenDP(poly p, int varnum, const ring r)
Definition p_polys.cc:3320
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:4685
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:3274
poly p_Subst(poly p, int n, poly e, const ring r)
Definition p_polys.cc:4039
void p_Vec2Polys(poly v, poly **p, int *len, const ring r)
Definition p_polys.cc:3705
void p_Shift(poly *p, int i, const ring r)
shifts components of the vector p by i
Definition p_polys.cc:4815
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:4211
poly p_Power(poly p, int i, const ring r)
Definition p_polys.cc:2201
void p_Normalize(poly p, const ring r)
Definition p_polys.cc:3894
void p_Norm(poly p1, const ring r)
Definition p_polys.cc:3799
poly pp_Jet0(poly p, const ring R)
Definition p_polys.cc:4467
int p_MinDeg(poly p, intvec *w, const ring R)
Definition p_polys.cc:4557
unsigned long p_GetShortExpVector(const poly p, const ring r)
Definition p_polys.cc:4889
BOOLEAN p_IsHomogeneousW(poly p, const intvec *w, const ring r)
Definition p_polys.cc:3406
poly p_One(const ring r)
Definition p_polys.cc:1314
void pEnlargeSet(poly **p, int l, int increment)
Definition p_polys.cc:3776
BOOLEAN p_IsHomogeneous(poly p, const ring r)
Definition p_polys.cc:3363
poly pp_JetW(poly p, int m, int *w, const ring R)
Definition p_polys.cc:4512
poly p_CopyPowerProduct0(const poly p, number n, const ring r)
like p_Head, but with coefficient n
Definition p_polys.cc:5077
BOOLEAN p_IsHomogeneousDP(poly p, const ring r)
Definition p_polys.cc:3387
BOOLEAN p_EqualPolys(poly p1, poly p2, const ring r)
Definition p_polys.cc:4621
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:1120
#define p_LmEqual(p1, p2, r)
Definition p_polys.h:1739
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:1245
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:1637
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:1926
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:1907
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:1162
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:2007
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:1523
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:1994
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:284
void PrintLn()
Definition reporter.cc:310
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
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