My Project
Loading...
Searching...
No Matches
hdegree.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/*
5* ABSTRACT - dimension, multiplicity, HC, kbase
6*/
7
8#include "kernel/mod2.h"
9
10#include "misc/intvec.h"
11#include "coeffs/numbers.h"
12
13#include "kernel/structs.h"
14#include "kernel/ideals.h"
15#include "kernel/polys.h"
16
20#include "reporter/reporter.h"
21
22#ifdef HAVE_SHIFTBBA
23#include <vector>
24#include "misc/options.h"
25#endif
26
28VAR long hMu;
29VAR omBin indlist_bin = omGetSpecBin(sizeof(indlist));
30
31/*0 implementation*/
32
33// dimension
34
35void hDimSolve(scmon pure, int Npure, scfmon rad, int Nrad,
36 varset var, int Nvar)
37{
38 int dn, iv, rad0, b, c, x;
39 scmon pn;
40 scfmon rn;
41 if (Nrad < 2)
42 {
43 dn = Npure + Nrad;
44 if (dn < hCo)
45 hCo = dn;
46 return;
47 }
48 if (Npure+1 >= hCo)
49 return;
50 iv = Nvar;
51 while(pure[var[iv]]) iv--;
52 hStepR(rad, Nrad, var, iv, &rad0);
53 if (rad0!=0)
54 {
55 iv--;
56 if (rad0 < Nrad)
57 {
58 pn = hGetpure(pure);
59 rn = hGetmem(Nrad, rad, radmem[iv]);
60 hDimSolve(pn, Npure + 1, rn, rad0, var, iv);
61 b = rad0;
62 c = Nrad;
63 hElimR(rn, &rad0, b, c, var, iv);
64 hPure(rn, b, &c, var, iv, pn, &x);
65 hLex2R(rn, rad0, b, c, var, iv, hwork);
66 rad0 += (c - b);
67 hDimSolve(pn, Npure + x, rn, rad0, var, iv);
68 }
69 else
70 {
71 hDimSolve(pure, Npure, rad, Nrad, var, iv);
72 }
73 }
74 else
75 hCo = Npure + 1;
76}
77
78int scDimInt(ideal S, ideal Q)
79{
80 id_Test(S, currRing);
81 if( Q!=NULL ) id_Test(Q, currRing);
82
83 int mc;
84 hexist = hInit(S, Q, &hNexist);
85 if (!hNexist)
86 return (currRing->N);
87 hwork = (scfmon)omAlloc(hNexist * sizeof(scmon));
88 hvar = (varset)omAlloc(((currRing->N) + 1) * sizeof(int));
89 hpure = (scmon)omAlloc((1 + ((currRing->N) * (currRing->N))) * sizeof(int));
90 mc = hisModule;
91 if (!mc)
92 {
93 hrad = hexist;
94 hNrad = hNexist;
95 }
96 else
97 hrad = (scfmon)omAlloc(hNexist * sizeof(scmon));
98 radmem = hCreate((currRing->N) - 1);
99 hCo = (currRing->N) + 1;
100 loop
101 {
102 if (mc)
103 hComp(hexist, hNexist, mc, hrad, &hNrad);
104 if (hNrad)
105 {
106 hNvar = (currRing->N);
109 if (hNvar)
110 {
111 memset(hpure, 0, ((currRing->N) + 1) * sizeof(int));
112 hPure(hrad, 0, &hNrad, hvar, hNvar, hpure, &hNpure);
115 }
116 }
117 else
118 {
119 hCo = 0;
120 break;
121 }
122 mc--;
123 if (mc <= 0)
124 break;
125 }
126 hKill(radmem, (currRing->N) - 1);
127 omFreeSize((ADDRESS)hpure, (1 + ((currRing->N) * (currRing->N))) * sizeof(int));
128 omFreeSize((ADDRESS)hvar, ((currRing->N) + 1) * sizeof(int));
129 omFreeSize((ADDRESS)hwork, hNexist * sizeof(scmon));
131 if (hisModule)
132 omFreeSize((ADDRESS)hrad, hNexist * sizeof(scmon));
133 return (currRing->N) - hCo;
134}
135
136int scDimIntRing(ideal vid, ideal Q)
137{
139 {
140 int i = idPosConstant(vid);
141 if ((i != -1) && (n_IsUnit(pGetCoeff(vid->m[i]),currRing->cf)))
142 { /* ideal v contains unit; dim = -1 */
143 return(-1);
144 }
145 ideal vv = id_Head(vid,currRing);
146 idSkipZeroes(vv);
147 i = idPosConstant(vid);
148 int d;
149 if(i == -1)
150 {
151 d = scDimInt(vv, Q);
153 d++;
154 }
155 else
156 {
157 if(n_IsUnit(pGetCoeff(vv->m[i]),currRing->cf))
158 d = -1;
159 else
160 d = scDimInt(vv, Q);
161 }
162 //Anne's Idea for std(4,2x) = 0 bug
163 int dcurr = d;
164 for(unsigned ii=0;ii<(unsigned)IDELEMS(vv);ii++)
165 {
166 if(vv->m[ii] != NULL && !n_IsUnit(pGetCoeff(vv->m[ii]),currRing->cf))
167 {
168 ideal vc = idCopy(vv);
169 poly c = pInit();
170 pSetCoeff0(c,nCopy(pGetCoeff(vv->m[ii])));
171 idInsertPoly(vc,c);
172 idSkipZeroes(vc);
173 for(unsigned jj = 0;jj<(unsigned)IDELEMS(vc)-1;jj++)
174 {
175 if((vc->m[jj]!=NULL)
176 && (n_DivBy(pGetCoeff(vc->m[jj]),pGetCoeff(c),currRing->cf)))
177 {
178 pDelete(&vc->m[jj]);
179 }
180 }
181 idSkipZeroes(vc);
182 i = idPosConstant(vc);
183 if (i != -1) pDelete(&vc->m[i]);
184 dcurr = scDimInt(vc, Q);
185 // the following assumes the ground rings to be either zero- or one-dimensional
186 if((i==-1) && rField_is_Z(currRing))
187 {
188 // should also be activated for other euclidean domains as groundfield
189 dcurr++;
190 }
191 idDelete(&vc);
192 }
193 if(dcurr > d)
194 d = dcurr;
195 }
196 idDelete(&vv);
197 return d;
198 }
199 return scDimInt(vid,Q);
200}
201
202// independent set
204
205static void hIndSolve(scmon pure, int Npure, scfmon rad, int Nrad,
206 varset var, int Nvar)
207{
208 int dn, iv, rad0, b, c, x;
209 scmon pn;
210 scfmon rn;
211 if (Nrad < 2)
212 {
213 dn = Npure + Nrad;
214 if (dn < hCo)
215 {
216 hCo = dn;
217 for (iv=(currRing->N); iv; iv--)
218 {
219 if (pure[iv])
220 hInd[iv] = 0;
221 else
222 hInd[iv] = 1;
223 }
224 if (Nrad)
225 {
226 pn = *rad;
227 iv = Nvar;
228 loop
229 {
230 x = var[iv];
231 if (pn[x])
232 {
233 hInd[x] = 0;
234 break;
235 }
236 iv--;
237 }
238 }
239 }
240 return;
241 }
242 if (Npure+1 >= hCo)
243 return;
244 iv = Nvar;
245 while(pure[var[iv]]) iv--;
246 hStepR(rad, Nrad, var, iv, &rad0);
247 if (rad0)
248 {
249 iv--;
250 if (rad0 < Nrad)
251 {
252 pn = hGetpure(pure);
253 rn = hGetmem(Nrad, rad, radmem[iv]);
254 pn[var[iv + 1]] = 1;
255 hIndSolve(pn, Npure + 1, rn, rad0, var, iv);
256 pn[var[iv + 1]] = 0;
257 b = rad0;
258 c = Nrad;
259 hElimR(rn, &rad0, b, c, var, iv);
260 hPure(rn, b, &c, var, iv, pn, &x);
261 hLex2R(rn, rad0, b, c, var, iv, hwork);
262 rad0 += (c - b);
263 hIndSolve(pn, Npure + x, rn, rad0, var, iv);
264 }
265 else
266 {
267 hIndSolve(pure, Npure, rad, Nrad, var, iv);
268 }
269 }
270 else
271 {
272 hCo = Npure + 1;
273 for (x=(currRing->N); x; x--)
274 {
275 if (pure[x])
276 hInd[x] = 0;
277 else
278 hInd[x] = 1;
279 }
280 hInd[var[iv]] = 0;
281 }
282}
283
284intvec * scIndIntvec(ideal S, ideal Q)
285{
286 id_Test(S, currRing);
287 if( Q!=NULL ) id_Test(Q, currRing);
288
289 intvec *Set=new intvec((currRing->N));
290 int mc,i;
291 hexist = hInit(S, Q, &hNexist);
292 if (hNexist==0)
293 {
294 for(i=0; i<(currRing->N); i++)
295 (*Set)[i]=1;
296 return Set;
297 }
298 hwork = (scfmon)omAlloc(hNexist * sizeof(scmon));
299 hvar = (varset)omAlloc(((currRing->N) + 1) * sizeof(int));
300 hpure = (scmon)omAlloc((1 + ((currRing->N) * (currRing->N))) * sizeof(int));
301 hInd = (scmon)omAlloc0((1 + (currRing->N)) * sizeof(int));
302 mc = hisModule;
303 if (mc==0)
304 {
305 hrad = hexist;
306 hNrad = hNexist;
307 }
308 else
309 hrad = (scfmon)omAlloc(hNexist * sizeof(scmon));
310 radmem = hCreate((currRing->N) - 1);
311 hCo = (currRing->N) + 1;
312 loop
313 {
314 if (mc!=0)
315 hComp(hexist, hNexist, mc, hrad, &hNrad);
316 if (hNrad!=0)
317 {
318 hNvar = (currRing->N);
321 if (hNvar!=0)
322 {
323 memset(hpure, 0, ((currRing->N) + 1) * sizeof(int));
324 hPure(hrad, 0, &hNrad, hvar, hNvar, hpure, &hNpure);
327 }
328 }
329 else
330 {
331 hCo = 0;
332 break;
333 }
334 mc--;
335 if (mc <= 0)
336 break;
337 }
338 for(i=0; i<(currRing->N); i++)
339 (*Set)[i] = hInd[i+1];
340 hKill(radmem, (currRing->N) - 1);
341 omFreeSize((ADDRESS)hpure, (1 + ((currRing->N) * (currRing->N))) * sizeof(int));
342 omFreeSize((ADDRESS)hInd, (1 + (currRing->N)) * sizeof(int));
343 omFreeSize((ADDRESS)hvar, ((currRing->N) + 1) * sizeof(int));
344 omFreeSize((ADDRESS)hwork, hNexist * sizeof(scmon));
346 if (hisModule)
347 omFreeSize((ADDRESS)hrad, hNexist * sizeof(scmon));
348 return Set;
349}
350
352
353static BOOLEAN hNotZero(scfmon rad, int Nrad, varset var, int Nvar)
354{
355 int k1, i;
356 k1 = var[Nvar];
357 i = 0;
358 loop
359 {
360 if (rad[i][k1]==0)
361 return FALSE;
362 i++;
363 if (i == Nrad)
364 return TRUE;
365 }
366}
367
368static void hIndep(scmon pure)
369{
370 int iv;
371 intvec *Set;
372
373 Set = ISet->set = new intvec((currRing->N));
374 for (iv=(currRing->N); iv!=0 ; iv--)
375 {
376 (*Set)[iv-1] = (pure[iv]==0);
377 }
379 hMu++;
380}
381
382void hIndMult(scmon pure, int Npure, scfmon rad, int Nrad,
383 varset var, int Nvar)
384{
385 int dn, iv, rad0, b, c, x;
386 scmon pn;
387 scfmon rn;
388 if (Nrad < 2)
389 {
390 dn = Npure + Nrad;
391 if (dn == hCo)
392 {
393 if (Nrad==0)
394 hIndep(pure);
395 else
396 {
397 pn = *rad;
398 for (iv = Nvar; iv!=0; iv--)
399 {
400 x = var[iv];
401 if (pn[x])
402 {
403 pure[x] = 1;
404 hIndep(pure);
405 pure[x] = 0;
406 }
407 }
408 }
409 }
410 return;
411 }
412 iv = Nvar;
413 dn = Npure+1;
414 if (dn >= hCo)
415 {
416 if (dn > hCo)
417 return;
418 loop
419 {
420 if(!pure[var[iv]])
421 {
422 if(hNotZero(rad, Nrad, var, iv))
423 {
424 pure[var[iv]] = 1;
425 hIndep(pure);
426 pure[var[iv]] = 0;
427 }
428 }
429 iv--;
430 if (!iv)
431 return;
432 }
433 }
434 while(pure[var[iv]]) iv--;
435 hStepR(rad, Nrad, var, iv, &rad0);
436 iv--;
437 if (rad0 < Nrad)
438 {
439 pn = hGetpure(pure);
440 rn = hGetmem(Nrad, rad, radmem[iv]);
441 pn[var[iv + 1]] = 1;
442 hIndMult(pn, Npure + 1, rn, rad0, var, iv);
443 pn[var[iv + 1]] = 0;
444 b = rad0;
445 c = Nrad;
446 hElimR(rn, &rad0, b, c, var, iv);
447 hPure(rn, b, &c, var, iv, pn, &x);
448 hLex2R(rn, rad0, b, c, var, iv, hwork);
449 rad0 += (c - b);
450 hIndMult(pn, Npure + x, rn, rad0, var, iv);
451 }
452 else
453 {
454 hIndMult(pure, Npure, rad, Nrad, var, iv);
455 }
456}
457
458/*3
459* consider indset x := !pure
460* (for all i) (if(sm(i) > x) return FALSE)
461* else return TRUE
462*/
463static BOOLEAN hCheck1(indset sm, scmon pure)
464{
465 int iv;
466 intvec *Set;
467 while (sm->nx != NULL)
468 {
469 Set = sm->set;
470 iv=(currRing->N);
471 loop
472 {
473 if (((*Set)[iv-1] == 0) && (pure[iv] == 0))
474 break;
475 iv--;
476 if (iv == 0)
477 return FALSE;
478 }
479 sm = sm->nx;
480 }
481 return TRUE;
482}
483
484/*3
485* consider indset x := !pure
486* (for all i) if(x > sm(i)) delete sm(i))
487* return (place for x)
488*/
489static indset hCheck2(indset sm, scmon pure)
490{
491 int iv;
492 intvec *Set;
493 indset be, a1 = NULL;
494 while (sm->nx != NULL)
495 {
496 Set = sm->set;
497 iv=(currRing->N);
498 loop
499 {
500 if ((pure[iv] == 1) && ((*Set)[iv-1] == 1))
501 break;
502 iv--;
503 if (iv == 0)
504 {
505 if (a1 == NULL)
506 {
507 a1 = sm;
508 }
509 else
510 {
511 hMu2--;
512 be->nx = sm->nx;
513 delete Set;
515 sm = be;
516 }
517 break;
518 }
519 }
520 be = sm;
521 sm = sm->nx;
522 }
523 if (a1 != NULL)
524 {
525 return a1;
526 }
527 else
528 {
529 hMu2++;
530 sm->set = new intvec((currRing->N));
531 sm->nx = (indset)omAlloc0Bin(indlist_bin);
532 return sm;
533 }
534}
535
536/*2
537* definition x >= y
538* x(i) == 0 => y(i) == 0
539* > ex. j with x(j) == 1 and y(j) == 0
540*/
541static void hCheckIndep(scmon pure)
542{
543 intvec *Set;
544 indset res;
545 int iv;
546 if (hCheck1(ISet, pure))
547 {
548 if (hCheck1(JSet, pure))
549 {
550 res = hCheck2(JSet,pure);
551 if (res == NULL)
552 return;
553 Set = res->set;
554 for (iv=(currRing->N); iv; iv--)
555 {
556 (*Set)[iv-1] = (pure[iv]==0);
557 }
558 }
559 }
560}
561
562void hIndAllMult(scmon pure, int Npure, scfmon rad, int Nrad,
563 varset var, int Nvar)
564{
565 int dn, iv, rad0, b, c, x;
566 scmon pn;
567 scfmon rn;
568 if (Nrad < 2)
569 {
570 dn = Npure + Nrad;
571 if (dn > hCo)
572 {
573 if (!Nrad)
574 hCheckIndep(pure);
575 else
576 {
577 pn = *rad;
578 for (iv = Nvar; iv; iv--)
579 {
580 x = var[iv];
581 if (pn[x])
582 {
583 pure[x] = 1;
584 hCheckIndep(pure);
585 pure[x] = 0;
586 }
587 }
588 }
589 }
590 return;
591 }
592 iv = Nvar;
593 while(pure[var[iv]]) iv--;
594 hStepR(rad, Nrad, var, iv, &rad0);
595 iv--;
596 if (rad0 < Nrad)
597 {
598 pn = hGetpure(pure);
599 rn = hGetmem(Nrad, rad, radmem[iv]);
600 pn[var[iv + 1]] = 1;
601 hIndAllMult(pn, Npure + 1, rn, rad0, var, iv);
602 pn[var[iv + 1]] = 0;
603 b = rad0;
604 c = Nrad;
605 hElimR(rn, &rad0, b, c, var, iv);
606 hPure(rn, b, &c, var, iv, pn, &x);
607 hLex2R(rn, rad0, b, c, var, iv, hwork);
608 rad0 += (c - b);
609 hIndAllMult(pn, Npure + x, rn, rad0, var, iv);
610 }
611 else
612 {
613 hIndAllMult(pure, Npure, rad, Nrad, var, iv);
614 }
615}
616
617// multiplicity
618
619static long hZeroMult(scmon pure, scfmon stc, int Nstc, varset var, int Nvar)
620{
621 int iv = Nvar -1, a, a0, a1, b, i;
622 long sum;
623 int x, x0;
624 scmon pn;
625 scfmon sn;
626 if (!iv)
627 return pure[var[1]];
628 else if (!Nstc)
629 {
630 sum = 1;
631 for (i = Nvar; i; i--)
632 sum *= pure[var[i]];
633 return sum;
634 }
635 x = a = 0;
636 pn = hGetpure(pure);
637 sn = hGetmem(Nstc, stc, stcmem[iv]);
638 hStepS(sn, Nstc, var, Nvar, &a, &x);
639 if (a == Nstc)
640 {
641 #if SIZEOF_LONG==8
642 return (long)pure[var[Nvar]] * hZeroMult(pn, sn, a, var, iv);
643 #else
644 int64 t=hZeroMult(pn, sn, a, var, iv);
645 t *= pure[var[Nvar]];
646 if ((t>=INT_MIN)&&(t<=INT_MAX)) sum=t;
647 else if (!errorreported) WerrorS("int overflow in vdim 3");
648 return sum;
649 #endif
650 }
651 else
652 {
653 #if SIZEOF_LONG==8
654 sum = x * hZeroMult(pn, sn, a, var, iv);
655 #else
656 int64 t=hZeroMult(pn, sn, a, var, iv);
657 t *= x;
658 if ((t>=INT_MIN)&&(t<=INT_MAX)) sum=t;
659 else if (!errorreported) WerrorS("int overflow in vdim 4");
660 #endif
661 }
662 b = a;
663 loop
664 {
665 a0 = a;
666 x0 = x;
667 hStepS(sn, Nstc, var, Nvar, &a, &x);
668 hElimS(sn, &b, a0, a, var, iv);
669 a1 = a;
670 hPure(sn, a0, &a1, var, iv, pn, &i);
671 hLex2S(sn, b, a0, a1, var, iv, hwork);
672 b += (a1 - a0);
673 if (a < Nstc)
674 {
675 #if SIZEOF_LONG==8
676 sum += (long)(x - x0) * hZeroMult(pn, sn, b, var, iv);
677 #else
678 int64 t=hZeroMult(pn, sn, b, var, iv);
679 t *= (x-x0);
680 t += sum;
681 if ((t>=INT_MIN)&&(t<=INT_MAX)) sum=t;
682 else if (!errorreported) WerrorS("int overflow in vdim 1");
683 #endif
684 }
685 else
686 {
687 #if SIZEOF_LONG==8
688 sum += (long)(pure[var[Nvar]] - x0) * hZeroMult(pn, sn, b, var, iv);
689 #else
690 int64 t=hZeroMult(pn, sn, b, var, iv);
691 t *= (pure[var[Nvar]]-x0);
692 t += sum;
693 if ((t>=INT_MIN)&&(t<=INT_MAX)) sum=t;
694 else if (!errorreported) WerrorS("int overflow in vdim 2");
695 #endif
696 return sum;
697 }
698 }
699}
700
701static void hProject(scmon pure, varset sel)
702{
703 int i, i0, k;
704 i0 = 0;
705 for (i = 1; i <= (currRing->N); i++)
706 {
707 if (pure[i])
708 {
709 i0++;
710 sel[i0] = i;
711 }
712 }
713 i = hNstc;
714 memcpy(hwork, hstc, i * sizeof(scmon));
715 hStaircase(hwork, &i, sel, i0);
716 if ((i0 > 2) && (i > 10))
717 hOrdSupp(hwork, i, sel, i0);
718 memset(hpur0, 0, ((currRing->N) + 1) * sizeof(int));
719 hPure(hwork, 0, &i, sel, i0, hpur0, &k);
720 hLexS(hwork, i, sel, i0);
721 hMu += hZeroMult(hpur0, hwork, i, sel, i0);
722}
723
724static void hDimMult(scmon pure, int Npure, scfmon rad, int Nrad,
725 varset var, int Nvar)
726{
727 int dn, iv, rad0, b, c, x;
728 scmon pn;
729 scfmon rn;
730 if (Nrad < 2)
731 {
732 dn = Npure + Nrad;
733 if (dn == hCo)
734 {
735 if (!Nrad)
736 hProject(pure, hsel);
737 else
738 {
739 pn = *rad;
740 for (iv = Nvar; iv; iv--)
741 {
742 x = var[iv];
743 if (pn[x])
744 {
745 pure[x] = 1;
746 hProject(pure, hsel);
747 pure[x] = 0;
748 }
749 }
750 }
751 }
752 return;
753 }
754 iv = Nvar;
755 dn = Npure+1;
756 if (dn >= hCo)
757 {
758 if (dn > hCo)
759 return;
760 loop
761 {
762 if(!pure[var[iv]])
763 {
764 if(hNotZero(rad, Nrad, var, iv))
765 {
766 pure[var[iv]] = 1;
767 hProject(pure, hsel);
768 pure[var[iv]] = 0;
769 }
770 }
771 iv--;
772 if (!iv)
773 return;
774 }
775 }
776 while(pure[var[iv]]) iv--;
777 hStepR(rad, Nrad, var, iv, &rad0);
778 iv--;
779 if (rad0 < Nrad)
780 {
781 pn = hGetpure(pure);
782 rn = hGetmem(Nrad, rad, radmem[iv]);
783 pn[var[iv + 1]] = 1;
784 hDimMult(pn, Npure + 1, rn, rad0, var, iv);
785 pn[var[iv + 1]] = 0;
786 b = rad0;
787 c = Nrad;
788 hElimR(rn, &rad0, b, c, var, iv);
789 hPure(rn, b, &c, var, iv, pn, &x);
790 hLex2R(rn, rad0, b, c, var, iv, hwork);
791 rad0 += (c - b);
792 hDimMult(pn, Npure + x, rn, rad0, var, iv);
793 }
794 else
795 {
796 hDimMult(pure, Npure, rad, Nrad, var, iv);
797 }
798}
799
800static void hDegree(ideal S, ideal Q)
801{
802 id_Test(S, currRing);
803 if( Q!=NULL ) id_Test(Q, currRing);
804
805 int di;
806 int mc;
807 hexist = hInit(S, Q, &hNexist);
808 if (!hNexist)
809 {
810 hCo = 0;
811 hMu = 1;
812 return;
813 }
814 //hWeight();
815 hwork = (scfmon)omAlloc(hNexist * sizeof(scmon));
816 hvar = (varset)omAlloc(((currRing->N) + 1) * sizeof(int));
817 hsel = (varset)omAlloc(((currRing->N) + 1) * sizeof(int));
818 hpure = (scmon)omAlloc((1 + ((currRing->N) * (currRing->N))) * sizeof(int));
819 hpur0 = (scmon)omAlloc((1 + ((currRing->N) * (currRing->N))) * sizeof(int));
820 mc = hisModule;
821 hrad = (scfmon)omAlloc(hNexist * sizeof(scmon));
822 if (!mc)
823 {
824 memcpy(hrad, hexist, hNexist * sizeof(scmon));
825 hstc = hexist;
826 hNrad = hNstc = hNexist;
827 }
828 else
829 hstc = (scfmon)omAlloc(hNexist * sizeof(scmon));
830 radmem = hCreate((currRing->N) - 1);
831 stcmem = hCreate((currRing->N) - 1);
832 hCo = (currRing->N) + 1;
833 di = hCo + 1;
834 loop
835 {
836 if (mc)
837 {
838 hComp(hexist, hNexist, mc, hrad, &hNrad);
839 hNstc = hNrad;
840 memcpy(hstc, hrad, hNrad * sizeof(scmon));
841 }
842 if (hNrad)
843 {
844 hNvar = (currRing->N);
847 if (hNvar)
848 {
849 hCo = hNvar;
850 memset(hpure, 0, ((currRing->N) + 1) * sizeof(int));
851 hPure(hrad, 0, &hNrad, hvar, hNvar, hpure, &hNpure);
854 }
855 }
856 else
857 {
858 hNvar = 1;
859 hCo = 0;
860 }
861 if (hCo < di)
862 {
863 di = hCo;
864 hMu = 0;
865 }
866 if (hNvar && (hCo == di))
867 {
868 if (di && (di < (currRing->N)))
870 else if (!di)
871 hMu++;
872 else
873 {
875 if ((hNvar > 2) && (hNstc > 10))
877 memset(hpur0, 0, ((currRing->N) + 1) * sizeof(int));
878 hPure(hstc, 0, &hNstc, hvar, hNvar, hpur0, &hNpure);
881 }
882 }
883 mc--;
884 if (mc <= 0)
885 break;
886 }
887 hCo = di;
888 hKill(stcmem, (currRing->N) - 1);
889 hKill(radmem, (currRing->N) - 1);
890 omFreeSize((ADDRESS)hpur0, (1 + ((currRing->N) * (currRing->N))) * sizeof(int));
891 omFreeSize((ADDRESS)hpure, (1 + ((currRing->N) * (currRing->N))) * sizeof(int));
892 omFreeSize((ADDRESS)hsel, ((currRing->N) + 1) * sizeof(int));
893 omFreeSize((ADDRESS)hvar, ((currRing->N) + 1) * sizeof(int));
894 omFreeSize((ADDRESS)hwork, hNexist * sizeof(scmon));
895 omFreeSize((ADDRESS)hrad, hNexist * sizeof(scmon));
897 if (hisModule)
898 omFreeSize((ADDRESS)hstc, hNexist * sizeof(scmon));
899}
900
901int scMultInt(ideal S, ideal Q)
902{
903 id_Test(S, currRing);
904 if( Q!=NULL ) id_Test(Q, currRing);
905
906 hDegree(S, Q);
907 return hMu;
908}
909
910void scPrintDegree(int co, int mu)
911{
912 int di = (currRing->N)-co;
913 if (currRing->OrdSgn == 1)
914 {
915 if (di>0)
916 Print("// dimension (proj.) = %d\n// degree (proj.) = %d\n", di-1, mu);
917 else
918 Print("// dimension (affine) = 0\n// degree (affine) = %d\n", mu);
919 }
920 else
921 Print("// dimension (local) = %d\n// multiplicity = %d\n", di, mu);
922}
923
924long scMult0Int(ideal S, ideal Q)
925{
927 if (Q!=NULL) id_LmTest(Q, currRing);
928
929 int mc;
930 hexist = hInit(S, Q, &hNexist);
931 if (!hNexist)
932 {
933 hMu = -1;
934 return -1;
935 }
936 else
937 hMu = 0;
938
939 const ring r = currRing;
940
941 hwork = (scfmon)omAlloc(hNexist * sizeof(scmon));
942 hvar = (varset)omAlloc(((r->N) + 1) * sizeof(int));
943 hpur0 = (scmon)omAlloc((1 + ((r->N) * (r->N))) * sizeof(int));
944 mc = hisModule;
945 if (!mc)
946 {
947 hstc = hexist;
948 hNstc = hNexist;
949 }
950 else
951 hstc = (scfmon)omAlloc(hNexist * sizeof(scmon));
952 stcmem = hCreate((r->N) - 1);
953 loop
954 {
955 if (mc)
956 {
957 hComp(hexist, hNexist, mc, hstc, &hNstc);
958 if (!hNstc)
959 {
960 hMu = -1;
961 break;
962 }
963 }
964 hNvar = (r->N);
965 for (int i = hNvar; i; i--)
966 hvar[i] = i;
969 if ((hNvar == (r->N)) && (hNstc >= (r->N)))
970 {
971 if ((hNvar > 2) && (hNstc > 10))
973 memset(hpur0, 0, ((r->N) + 1) * sizeof(int));
974 hPure(hstc, 0, &hNstc, hvar, hNvar, hpur0, &hNpure);
975 if (hNpure == hNvar)
976 {
979 }
980 else
981 hMu = -1;
982 }
983 else if (hNvar)
984 hMu = -1;
985 mc--;
986 if (mc <= 0 || hMu < 0)
987 break;
988 }
989 hKill(stcmem, (r->N) - 1);
990 omFreeSize((ADDRESS)hpur0, (1 + ((r->N) * (r->N))) * sizeof(int));
991 omFreeSize((ADDRESS)hvar, ((r->N) + 1) * sizeof(int));
992 omFreeSize((ADDRESS)hwork, hNexist * sizeof(scmon));
994 if (hisModule)
995 omFreeSize((ADDRESS)hstc, hNexist * sizeof(scmon));
996 return hMu;
997}
998
999// HC
1000
1002
1003static void hHedge(poly hEdge)
1004{
1005 pSetm(pWork);
1006 if (pLmCmp(pWork, hEdge) == currRing->OrdSgn)
1007 {
1008 for (int i = hNvar; i>0; i--)
1009 pSetExp(hEdge,i, pGetExp(pWork,i));
1010 pSetm(hEdge);
1011 }
1012}
1013
1014static void hHedgeStep(scmon pure, scfmon stc,
1015 int Nstc, varset var, int Nvar,poly hEdge)
1016{
1017 int iv = Nvar -1, k = var[Nvar], a, a0, a1, b, i;
1018 int x/*, x0*/;
1019 scmon pn;
1020 scfmon sn;
1021 if (iv==0)
1022 {
1023 pSetExp(pWork, k, pure[k]);
1024 hHedge(hEdge);
1025 return;
1026 }
1027 else if (Nstc==0)
1028 {
1029 for (i = Nvar; i>0; i--)
1030 pSetExp(pWork, var[i], pure[var[i]]);
1031 hHedge(hEdge);
1032 return;
1033 }
1034 x = a = 0;
1035 pn = hGetpure(pure);
1036 sn = hGetmem(Nstc, stc, stcmem[iv]);
1037 hStepS(sn, Nstc, var, Nvar, &a, &x);
1038 if (a == Nstc)
1039 {
1040 pSetExp(pWork, k, pure[k]);
1041 hHedgeStep(pn, sn, a, var, iv,hEdge);
1042 return;
1043 }
1044 else
1045 {
1046 pSetExp(pWork, k, x);
1047 hHedgeStep(pn, sn, a, var, iv,hEdge);
1048 }
1049 b = a;
1050 loop
1051 {
1052 a0 = a;
1053 // x0 = x;
1054 hStepS(sn, Nstc, var, Nvar, &a, &x);
1055 hElimS(sn, &b, a0, a, var, iv);
1056 a1 = a;
1057 hPure(sn, a0, &a1, var, iv, pn, &i);
1058 hLex2S(sn, b, a0, a1, var, iv, hwork);
1059 b += (a1 - a0);
1060 if (a < Nstc)
1061 {
1062 pSetExp(pWork, k, x);
1063 hHedgeStep(pn, sn, b, var, iv,hEdge);
1064 }
1065 else
1066 {
1067 pSetExp(pWork, k, pure[k]);
1068 hHedgeStep(pn, sn, b, var, iv,hEdge);
1069 return;
1070 }
1071 }
1072}
1073
1074void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge)
1075{
1076 if(idElem(S) == 0)
1077 return;
1078 id_LmTest(S, currRing);
1079 if (Q!=NULL) id_LmTest(Q, currRing);
1080
1081 int i;
1082 int k = ak;
1083 ideal SS=id_Head(S,currRing);
1084 if (rField_is_Ring(currRing) && (currRing->OrdSgn == -1))
1085 {
1086 //consider just monic generators (over rings with zero-divisors)
1087 for(i=0;i<=idElem(S);i++)
1088 {
1089 if((SS->m[i]!=NULL)
1090 && ((p_IsPurePower(SS->m[i],currRing)==0)
1091 ||(!n_IsUnit(pGetCoeff(SS->m[i]), currRing->cf))))
1092 {
1093 p_Delete(&SS->m[i],currRing);
1094 }
1095 }
1096 }
1097 S=SS;
1098 idSkipZeroes(S);
1099 hNvar = (currRing->N);
1100 hexist = hInit(S, Q, &hNexist);
1101 if (hNexist==0) return;
1102 if (k!=0)
1104 else
1105 hNstc = hNexist;
1106 assume(hNexist > 0);
1107 hwork = (scfmon)omAlloc(hNexist * sizeof(scmon));
1108 hvar = (varset)omAlloc((hNvar + 1) * sizeof(int));
1109 hpure = (scmon)omAlloc((1 + (hNvar * hNvar)) * sizeof(int));
1110 stcmem = hCreate(hNvar - 1);
1111 for (i = hNvar; i>0; i--)
1112 hvar[i] = i;
1114 if ((hNvar > 2) && (hNstc > 10))
1116 memset(hpure, 0, (hNvar + 1) * sizeof(int));
1117 hPure(hexist, 0, &hNstc, hvar, hNvar, hpure, &hNpure);
1119 if (hEdge!=NULL)
1120 pLmFree(hEdge);
1121 hEdge = pInit();
1122 pWork = pInit();
1124 pSetComp(hEdge,ak);
1125 hKill(stcmem, hNvar - 1);
1126 omFreeSize((ADDRESS)hwork, hNexist * sizeof(scmon));
1127 omFreeSize((ADDRESS)hvar, (hNvar + 1) * sizeof(int));
1128 omFreeSize((ADDRESS)hpure, (1 + (hNvar * hNvar)) * sizeof(int));
1130 pLmFree(pWork);
1131 idDelete(&S);
1132}
1133
1134
1135
1136// kbase
1137
1140
1141static void scElKbase()
1142{
1143 poly q = pInit();
1144 pSetCoeff0(q,nInit(1));
1145 pSetExpV(q,act);
1146 pNext(q) = NULL;
1147 last = pNext(last) = q;
1148}
1149
1150static int scMax( int i, scfmon stc, int Nvar)
1151{
1152 int x, y=stc[0][Nvar];
1153 for (; i;)
1154 {
1155 i--;
1156 x = stc[i][Nvar];
1157 if (x > y) y = x;
1158 }
1159 return y;
1160}
1161
1162static int scMin( int i, scfmon stc, int Nvar)
1163{
1164 int x, y=stc[0][Nvar];
1165 for (; i;)
1166 {
1167 i--;
1168 x = stc[i][Nvar];
1169 if (x < y) y = x;
1170 }
1171 return y;
1172}
1173
1174static int scRestrict( int &Nstc, scfmon stc, int Nvar)
1175{
1176 int x, y;
1177 int i, j, Istc = Nstc;
1178
1179 y = MAX_INT_VAL;
1180 for (i=Nstc-1; i>=0; i--)
1181 {
1182 j = Nvar-1;
1183 loop
1184 {
1185 if(stc[i][j] != 0) break;
1186 j--;
1187 if (j == 0)
1188 {
1189 Istc--;
1190 x = stc[i][Nvar];
1191 if (x < y) y = x;
1192 stc[i] = NULL;
1193 break;
1194 }
1195 }
1196 }
1197 if (Istc < Nstc)
1198 {
1199 for (i=Nstc-1; i>=0; i--)
1200 {
1201 if (stc[i] && (stc[i][Nvar] >= y))
1202 {
1203 Istc--;
1204 stc[i] = NULL;
1205 }
1206 }
1207 j = 0;
1208 while (stc[j]) j++;
1209 i = j+1;
1210 for(; i<Nstc; i++)
1211 {
1212 if (stc[i])
1213 {
1214 stc[j] = stc[i];
1215 j++;
1216 }
1217 }
1218 Nstc = Istc;
1219 return y;
1220 }
1221 else
1222 return -1;
1223}
1224
1225static void scAll( int Nvar, int deg)
1226{
1227 int i;
1228 int d = deg;
1229 if (d == 0)
1230 {
1231 for (i=Nvar; i; i--) act[i] = 0;
1232 scElKbase();
1233 return;
1234 }
1235 if (Nvar == 1)
1236 {
1237 act[1] = d;
1238 scElKbase();
1239 return;
1240 }
1241 do
1242 {
1243 act[Nvar] = d;
1244 scAll(Nvar-1, deg-d);
1245 d--;
1246 } while (d >= 0);
1247}
1248
1249static void scAllKbase( int Nvar, int ideg, int deg)
1250{
1251 do
1252 {
1253 act[Nvar] = ideg;
1254 scAll(Nvar-1, deg-ideg);
1255 ideg--;
1256 } while (ideg >= 0);
1257}
1258
1259static void scDegKbase( scfmon stc, int Nstc, int Nvar, int deg)
1260{
1261 int Ivar, Istc, i, j;
1262 scfmon sn;
1263 int x, ideg;
1264
1265 if (deg == 0)
1266 {
1267 for (i=Nstc-1; i>=0; i--)
1268 {
1269 for (j=Nvar;j;j--){ if(stc[i][j]) break; }
1270 if (j==0){return;}
1271 }
1272 for (i=Nvar; i; i--) act[i] = 0;
1273 scElKbase();
1274 return;
1275 }
1276 if (Nvar == 1)
1277 {
1278 for (i=Nstc-1; i>=0; i--) if(deg >= stc[i][1]) return;
1279 act[1] = deg;
1280 scElKbase();
1281 return;
1282 }
1283 Ivar = Nvar-1;
1284 sn = hGetmem(Nstc, stc, stcmem[Ivar]);
1285 x = scRestrict(Nstc, sn, Nvar);
1286 if (x <= 0)
1287 {
1288 if (x == 0) return;
1289 ideg = deg;
1290 }
1291 else
1292 {
1293 if (deg < x) ideg = deg;
1294 else ideg = x-1;
1295 if (Nstc == 0)
1296 {
1297 scAllKbase(Nvar, ideg, deg);
1298 return;
1299 }
1300 }
1301 loop
1302 {
1303 x = scMax(Nstc, sn, Nvar);
1304 while (ideg >= x)
1305 {
1306 act[Nvar] = ideg;
1307 scDegKbase(sn, Nstc, Ivar, deg-ideg);
1308 ideg--;
1309 }
1310 if (ideg < 0) return;
1311 Istc = Nstc;
1312 for (i=Nstc-1; i>=0; i--)
1313 {
1314 if (ideg < sn[i][Nvar])
1315 {
1316 Istc--;
1317 sn[i] = NULL;
1318 }
1319 }
1320 if (Istc == 0)
1321 {
1322 scAllKbase(Nvar, ideg, deg);
1323 return;
1324 }
1325 j = 0;
1326 while (sn[j]) j++;
1327 i = j+1;
1328 for (; i<Nstc; i++)
1329 {
1330 if (sn[i])
1331 {
1332 sn[j] = sn[i];
1333 j++;
1334 }
1335 }
1336 Nstc = Istc;
1337 }
1338}
1339
1340static void scInKbase( scfmon stc, int Nstc, int Nvar)
1341{
1342 int Ivar, Istc, i, j;
1343 scfmon sn;
1344 int x, ideg;
1345
1346 if (Nvar == 1)
1347 {
1348 ideg = scMin(Nstc, stc, 1);
1349 while (ideg > 0)
1350 {
1351 ideg--;
1352 act[1] = ideg;
1353 scElKbase();
1354 }
1355 return;
1356 }
1357 Ivar = Nvar-1;
1358 sn = hGetmem(Nstc, stc, stcmem[Ivar]);
1359 x = scRestrict(Nstc, sn, Nvar);
1360 if (x == 0) return;
1361 ideg = x-1;
1362 loop
1363 {
1364 x = scMax(Nstc, sn, Nvar);
1365 while (ideg >= x)
1366 {
1367 act[Nvar] = ideg;
1368 scInKbase(sn, Nstc, Ivar);
1369 ideg--;
1370 }
1371 if (ideg < 0) return;
1372 Istc = Nstc;
1373 for (i=Nstc-1; i>=0; i--)
1374 {
1375 if (ideg < sn[i][Nvar])
1376 {
1377 Istc--;
1378 sn[i] = NULL;
1379 }
1380 }
1381 j = 0;
1382 while (sn[j]) j++;
1383 i = j+1;
1384 for (; i<Nstc; i++)
1385 {
1386 if (sn[i])
1387 {
1388 sn[j] = sn[i];
1389 j++;
1390 }
1391 }
1392 Nstc = Istc;
1393 }
1394}
1395
1396static ideal scIdKbase(poly q, const int rank)
1397{
1398 ideal res = idInit(pLength(q), rank);
1399 polyset mm = res->m;
1400 do
1401 {
1402 *mm = q; ++mm;
1403
1404 const poly p = pNext(q);
1405 pNext(q) = NULL;
1406 q = p;
1407
1408 } while (q!=NULL);
1409
1410 id_Test(res, currRing); // WRONG RANK!!!???
1411 return res;
1412}
1413
1414ideal scKBase(int deg, ideal s, ideal Q, intvec * mv)
1415{
1416 if( Q!=NULL) id_Test(Q, currRing);
1417
1418 int i, di;
1419 poly p;
1420
1421 if (deg < 0)
1422 {
1423 di = scDimInt(s, Q);
1424 if (di != 0)
1425 {
1426 //Werror("KBase not finite");
1427 return idInit(1,s->rank);
1428 }
1429 }
1430 stcmem = hCreate((currRing->N) - 1);
1431 hexist = hInit(s, Q, &hNexist);
1432 p = last = pInit();
1433 /*pNext(p) = NULL;*/
1434 act = (scmon)omAlloc(((currRing->N) + 1) * sizeof(int));
1435 *act = 0;
1436 if (!hNexist)
1437 {
1438 scAll((currRing->N), deg);
1439 goto ende;
1440 }
1441 if (!hisModule)
1442 {
1443 if (deg < 0) scInKbase(hexist, hNexist, (currRing->N));
1444 else scDegKbase(hexist, hNexist, (currRing->N), deg);
1445 }
1446 else
1447 {
1448 hstc = (scfmon)omAlloc(hNexist * sizeof(scmon));
1449 for (i = 1; i <= hisModule; i++)
1450 {
1451 *act = i;
1453 int deg_ei=deg;
1454 if (mv!=NULL) deg_ei -= (*mv)[i-1];
1455 if ((deg < 0) || (deg_ei>=0))
1456 {
1457 if (hNstc)
1458 {
1459 if (deg < 0) scInKbase(hstc, hNstc, (currRing->N));
1460 else scDegKbase(hstc, hNstc, (currRing->N), deg_ei);
1461 }
1462 else
1463 scAll((currRing->N), deg_ei);
1464 }
1465 }
1466 omFreeSize((ADDRESS)hstc, hNexist * sizeof(scmon));
1467 }
1468ende:
1470 omFreeSize((ADDRESS)act, ((currRing->N) + 1) * sizeof(int));
1471 hKill(stcmem, (currRing->N) - 1);
1472 pLmFree(&p);
1473 if (p == NULL)
1474 return idInit(1,s->rank);
1475
1476 last = p;
1477 return scIdKbase(p, s->rank);
1478}
1479
1480#if 0 //-- alternative implementation of scComputeHC
1481/*
1482void scComputeHCw(ideal ss, ideal Q, int ak, poly &hEdge)
1483{
1484 id_LmTest(ss, currRing);
1485 if (Q!=NULL) id_LmTest(Q, currRing);
1486
1487 int i, di;
1488 poly p;
1489
1490 if (hEdge!=NULL)
1491 pLmFree(hEdge);
1492
1493 ideal s=idInit(IDELEMS(ss),ak);
1494 for(i=IDELEMS(ss)-1;i>=0;i--)
1495 {
1496 if (ss->m[i]!=NULL) s->m[i]=pHead(ss->m[i]);
1497 }
1498 di = scDimInt(s, Q);
1499 stcmem = hCreate((currRing->N) - 1);
1500 hexist = hInit(s, Q, &hNexist);
1501 p = last = pInit();
1502 // pNext(p) = NULL;
1503 act = (scmon)omAlloc(((currRing->N) + 1) * sizeof(int));
1504 *act = 0;
1505 if (!hNexist)
1506 {
1507 scAll((currRing->N), -1);
1508 goto ende;
1509 }
1510 if (!hisModule)
1511 {
1512 scInKbase(hexist, hNexist, (currRing->N));
1513 }
1514 else
1515 {
1516 hstc = (scfmon)omAlloc(hNexist * sizeof(scmon));
1517 for (i = 1; i <= hisModule; i++)
1518 {
1519 *act = i;
1520 hComp(hexist, hNexist, i, hstc, &hNstc);
1521 if (hNstc)
1522 {
1523 scInKbase(hstc, hNstc, (currRing->N));
1524 }
1525 else
1526 scAll((currRing->N), -1);
1527 }
1528 omFreeSize((ADDRESS)hstc, hNexist * sizeof(scmon));
1529 }
1530ende:
1531 hDelete(hexist, hNexist);
1532 omFreeSize((ADDRESS)act, ((currRing->N) + 1) * sizeof(int));
1533 hKill(stcmem, (currRing->N) - 1);
1534 pDeleteLm(&p);
1535 idDelete(&s);
1536 if (p == NULL)
1537 {
1538 return; // no HEdge
1539 }
1540 else
1541 {
1542 last = p;
1543 ideal res=scIdKbase(p, ss->rank);
1544 poly p_ind=res->m[0]; int ind=0;
1545 for(i=IDELEMS(res)-1;i>0;i--)
1546 {
1547 if (pCmp(res->m[i],p_ind)==-1) { p_ind=res->m[i]; ind=i; }
1548 }
1549 assume(p_ind!=NULL);
1550 assume(res->m[ind]==p_ind);
1551 hEdge=p_ind;
1552 res->m[ind]=NULL;
1553 nDelete(&pGetCoeff(hEdge));
1554 pGetCoeff(hEdge)=NULL;
1555 for(i=(currRing->N);i>0;i--)
1556 pIncrExp(hEdge,i);
1557 pSetm(hEdge);
1558
1559 idDelete(&res);
1560 return;
1561 }
1562}
1563 */
1564#endif
1565
1566#ifdef HAVE_SHIFTBBA
1567
1568/*
1569 * Computation of the Gel'fand-Kirillov Dimension
1570 */
1571
1572#include "polys/shiftop.h"
1573#include <vector>
1574
1575static std::vector<int> countCycles(const intvec* _G, int v, std::vector<int> path, std::vector<BOOLEAN> visited, std::vector<BOOLEAN> cyclic, std::vector<int> cache)
1576{
1577 intvec* G = ivCopy(_G); // modifications must be local
1578
1579 if (cache[v] != -2) return cache; // value is already cached
1580
1581 visited[v] = TRUE;
1582 path.push_back(v);
1583
1584 int cycles = 0;
1585 for (int w = 0; w < G->cols(); w++)
1586 {
1587 if (IMATELEM(*G, v + 1, w + 1)) // edge v -> w exists in G
1588 {
1589 if (!visited[w])
1590 { // continue with w
1591 cache = countCycles(G, w, path, visited, cyclic, cache);
1592 if (cache[w] == -1)
1593 {
1594 cache[v] = -1;
1595 return cache;
1596 }
1597 cycles = si_max(cycles, cache[w]);
1598 }
1599 else
1600 { // found new cycle
1601 int pathIndexOfW = -1;
1602 for (int i = path.size() - 1; i >= 0; i--) {
1603 if (cyclic[path[i]] == 1) { // found an already cyclic vertex
1604 cache[v] = -1;
1605 return cache;
1606 }
1607 cyclic[path[i]] = TRUE;
1608
1609 if (path[i] == w) { // end of the cycle
1610 assume(IMATELEM(*G, v + 1, w + 1) != 0);
1611 IMATELEM(*G, v + 1, w + 1) = 0; // remove edge v -> w
1612 pathIndexOfW = i;
1613 break;
1614 } else {
1615 assume(IMATELEM(*G, path[i - 1] + 1, path[i] + 1) != 0);
1616 IMATELEM(*G, path[i - 1] + 1, path[i] + 1) = 0; // remove edge vi-1 -> vi
1617 }
1618 }
1619 assume(pathIndexOfW != -1); // should never happen
1620 for (int i = path.size() - 1; i >= pathIndexOfW; i--) {
1621 cache = countCycles(G, path[i], path, visited, cyclic, cache);
1622 if (cache[path[i]] == -1)
1623 {
1624 cache[v] = -1;
1625 return cache;
1626 }
1627 cycles = si_max(cycles, cache[path[i]] + 1);
1628 }
1629 }
1630 }
1631 }
1632 cache[v] = cycles;
1633
1634 delete G;
1635 return cache;
1636}
1637
1638// -1 is infinity
1639static int graphGrowth(const intvec* G)
1640{
1641 // init
1642 int n = G->cols();
1643 std::vector<int> path;
1644 std::vector<BOOLEAN> visited;
1645 std::vector<BOOLEAN> cyclic;
1646 std::vector<int> cache;
1647 visited.resize(n, FALSE);
1648 cyclic.resize(n, FALSE);
1649 cache.resize(n, -2);
1650
1651 // get max number of cycles
1652 int cycles = 0;
1653 for (int v = 0; v < n; v++)
1654 {
1655 cache = countCycles(G, v, path, visited, cyclic, cache);
1656 if (cache[v] == -1)
1657 return -1;
1658 cycles = si_max(cycles, cache[v]);
1659 }
1660 return cycles;
1661}
1662
1663// ATTENTION:
1664// - `words` contains the words normal modulo M of length n
1665// - `numberOfNormalWords` contains the number of words normal modulo M of length 0 ... n
1666static void _lp_computeNormalWords(ideal words, int& numberOfNormalWords, int length, ideal M, int minDeg, int& last)
1667{
1668 if (length <= 0){
1669 poly one = pOne();
1670 if (p_LPDivisibleBy(M, one, currRing)) // 1 \in M => no normal words at all
1671 {
1672 pDelete(&one);
1673 last = -1;
1674 numberOfNormalWords = 0;
1675 }
1676 else
1677 {
1678 words->m[0] = one;
1679 last = 0;
1680 numberOfNormalWords = 1;
1681 }
1682 return;
1683 }
1684
1685 _lp_computeNormalWords(words, numberOfNormalWords, length - 1, M, minDeg, last);
1686
1687 int nVars = currRing->isLPring - currRing->LPncGenCount;
1688 int numberOfNewNormalWords = 0;
1689
1690 for (int j = nVars - 1; j >= 0; j--)
1691 {
1692 for (int i = last; i >= 0; i--)
1693 {
1694 int index = (j * (last + 1)) + i;
1695
1696 if (words->m[i] != NULL)
1697 {
1698 if (j > 0) {
1699 words->m[index] = pCopy(words->m[i]);
1700 }
1701
1702 int varOffset = ((length - 1) * currRing->isLPring) + 1;
1703 pSetExp(words->m[index], varOffset + j, 1);
1704 pSetm(words->m[index]);
1705 pTest(words->m[index]);
1706
1707 if (length >= minDeg && p_LPDivisibleBy(M, words->m[index], currRing))
1708 {
1709 pDelete(&words->m[index]);
1710 words->m[index] = NULL;
1711 }
1712 else
1713 {
1714 numberOfNewNormalWords++;
1715 }
1716 }
1717 }
1718 }
1719
1720 last = nVars * last + nVars - 1;
1721
1722 numberOfNormalWords += numberOfNewNormalWords;
1723}
1724
1725static ideal lp_computeNormalWords(int length, ideal M)
1726{
1727 long minDeg = IDELEMS(M) > 0 ? pTotaldegree(M->m[0]) : 0;
1728 for (int i = 1; i < IDELEMS(M); i++)
1729 {
1730 minDeg = si_min(minDeg, pTotaldegree(M->m[i]));
1731 }
1732
1733 int nVars = currRing->isLPring - currRing->LPncGenCount;
1734
1735 int maxElems = 1;
1736 for (int i = 0; i < length; i++) // maxElems = nVars^n
1737 maxElems *= nVars;
1738 ideal words = idInit(maxElems);
1739 int last, numberOfNormalWords;
1740 _lp_computeNormalWords(words, numberOfNormalWords, length, M, minDeg, last);
1741 idSkipZeroes(words);
1742 return words;
1743}
1744
1745static int lp_countNormalWords(int upToLength, ideal M)
1746{
1747 long minDeg = IDELEMS(M) > 0 ? pTotaldegree(M->m[0]) : 0;
1748 for (int i = 1; i < IDELEMS(M); i++)
1749 {
1750 minDeg = si_min(minDeg, pTotaldegree(M->m[i]));
1751 }
1752
1753 int nVars = currRing->isLPring - currRing->LPncGenCount;
1754
1755 int maxElems = 1;
1756 for (int i = 0; i < upToLength; i++) // maxElems = nVars^n
1757 maxElems *= nVars;
1758 ideal words = idInit(maxElems);
1759 int last, numberOfNormalWords;
1760 _lp_computeNormalWords(words, numberOfNormalWords, upToLength, M, minDeg, last);
1761 idDelete(&words);
1762 return numberOfNormalWords;
1763}
1764
1765// NULL if graph is undefined
1766intvec* lp_ufnarovskiGraph(ideal G, ideal &standardWords)
1767{
1768 long l = 0;
1769 for (int i = 0; i < IDELEMS(G); i++)
1770 l = si_max(pTotaldegree(G->m[i]), l);
1771 l--;
1772 if (l <= 0)
1773 {
1774 WerrorS("Ufnarovski graph not implemented for l <= 0");
1775 return NULL;
1776 }
1777 int lV = currRing->isLPring;
1778
1779 standardWords = lp_computeNormalWords(l, G);
1780
1781 int n = IDELEMS(standardWords);
1782 intvec* UG = new intvec(n, n, 0);
1783 for (int i = 0; i < n; i++)
1784 {
1785 for (int j = 0; j < n; j++)
1786 {
1787 poly v = standardWords->m[i];
1788 poly w = standardWords->m[j];
1789
1790 // check whether v*x1 = x2*w (overlap)
1791 bool overlap = true;
1792 for (int k = 1; k <= (l - 1) * lV; k++)
1793 {
1794 if (pGetExp(v, k + lV) != pGetExp(w, k)) {
1795 overlap = false;
1796 break;
1797 }
1798 }
1799
1800 if (overlap)
1801 {
1802 // create the overlap
1803 poly p = pMult(pCopy(v), p_LPVarAt(w, l, currRing));
1804
1805 // check whether the overlap is normal
1806 bool normal = true;
1807 for (int k = 0; k < IDELEMS(G); k++)
1808 {
1809 if (p_LPDivisibleBy(G->m[k], p, currRing))
1810 {
1811 normal = false;
1812 break;
1813 }
1814 }
1815
1816 if (normal)
1817 {
1818 IMATELEM(*UG, i + 1, j + 1) = 1;
1819 }
1820 }
1821 }
1822 }
1823 return UG;
1824}
1825
1826// -1 is infinity, -2 is error
1827int lp_gkDim(const ideal _G)
1828{
1829 id_Test(_G, currRing);
1830
1831 if (rField_is_Ring(currRing)) {
1832 WerrorS("GK-Dim not implemented for rings");
1833 return -2;
1834 }
1835
1836 for (int i=IDELEMS(_G)-1;i>=0; i--)
1837 {
1838 if (_G->m[i] != NULL)
1839 {
1840 if (pGetComp(_G->m[i]) != 0)
1841 {
1842 WerrorS("GK-Dim not implemented for modules");
1843 return -2;
1844 }
1845 if (pGetNCGen(_G->m[i]) != 0)
1846 {
1847 WerrorS("GK-Dim not implemented for bi-modules");
1848 return -2;
1849 }
1850 }
1851 }
1852
1853 ideal G = id_Head(_G, currRing); // G = LM(G) (and copy)
1854 idSkipZeroes(G); // remove zeros
1855 id_DelLmEquals(G, currRing); // remove duplicates
1856
1857 // check if G is the zero ideal
1858 if (IDELEMS(G) == 1 && G->m[0] == NULL)
1859 {
1860 // NOTE: this is needed because if the ideal is <0>, then idSkipZeroes keeps this element, and IDELEMS is still 1!
1861 int lV = currRing->isLPring;
1862 int ncGenCount = currRing->LPncGenCount;
1863 if (lV - ncGenCount == 0)
1864 {
1865 idDelete(&G);
1866 return 0;
1867 }
1868 if (lV - ncGenCount == 1)
1869 {
1870 idDelete(&G);
1871 return 1;
1872 }
1873 if (lV - ncGenCount >= 2)
1874 {
1875 idDelete(&G);
1876 return -1;
1877 }
1878 }
1879
1880 // get the max deg
1881 long maxDeg = 0;
1882 for (int i = 0; i < IDELEMS(G); i++)
1883 {
1884 maxDeg = si_max(maxDeg, pTotaldegree(G->m[i]));
1885
1886 // also check whether G = <1>
1887 if (pIsConstantComp(G->m[i]))
1888 {
1889 WerrorS("GK-Dim not defined for 0-ring");
1890 idDelete(&G);
1891 return -2;
1892 }
1893 }
1894
1895 // early termination if G \subset X
1896 if (maxDeg <= 1)
1897 {
1898 int lV = currRing->isLPring;
1899 int ncGenCount = currRing->LPncGenCount;
1900 if (IDELEMS(G) == lV - ncGenCount) // V = {1} no edges
1901 {
1902 idDelete(&G);
1903 return 0;
1904 }
1905 if (IDELEMS(G) == lV - ncGenCount - 1) // V = {1} with loop
1906 {
1907 idDelete(&G);
1908 return 1;
1909 }
1910 if (IDELEMS(G) <= lV - ncGenCount - 2) // V = {1} with more than one loop
1911 {
1912 idDelete(&G);
1913 return -1;
1914 }
1915 }
1916
1917 ideal standardWords;
1918 intvec* UG = lp_ufnarovskiGraph(G, standardWords);
1919 if (UG == NULL)
1920 {
1921 idDelete(&G);
1922 return -2;
1923 }
1924 if (errorreported)
1925 {
1926 delete UG;
1927 idDelete(&G);
1928 return -2;
1929 }
1930 int gkDim = graphGrowth(UG);
1931 delete UG;
1932 idDelete(&G);
1933 return gkDim;
1934}
1935
1936// converts an intvec matrix to a vector<vector<int> >
1937static std::vector<std::vector<int> > iv2vv(intvec* M)
1938{
1939 int rows = M->rows();
1940 int cols = M->cols();
1941
1942 std::vector<std::vector<int> > mat(rows, std::vector<int>(cols));
1943
1944 for (int i = 0; i < rows; i++)
1945 {
1946 for (int j = 0; j < cols; j++)
1947 {
1948 mat[i][j] = IMATELEM(*M, i + 1, j + 1);
1949 }
1950 }
1951
1952 return mat;
1953}
1954
1955#if 0
1956static void vvPrint(const std::vector<std::vector<int> >& mat)
1957{
1958 for (std::vector<std::vector<int> >::size_type i = 0; i < mat.size(); i++)
1959 {
1960 for (std::vector<std::vector<int> >::size_type j = 0; j < mat[i].size(); j++)
1961 {
1962 Print("%d ", mat[i][j]);
1963 }
1964 PrintLn();
1965 }
1966}
1967#endif
1968
1969#if 0
1970static void vvTest(const std::vector<std::vector<int> >& mat)
1971{
1972 if (mat.size() > 0)
1973 {
1974 std::vector<std::vector<int> >::size_type cols = mat[0].size();
1975 for (std::vector<std::vector<int> >::size_type i = 1; i < mat.size(); i++)
1976 {
1977 if (cols != mat[i].size())
1978 WerrorS("number of cols in matrix inconsistent");
1979 }
1980 }
1981}
1982#endif
1983
1984static void vvDeleteRow(std::vector<std::vector<int> >& mat, int row)
1985{
1986 mat.erase(mat.begin() + row);
1987}
1988
1989static void vvDeleteColumn(std::vector<std::vector<int> >& mat, int col)
1990{
1991 for (std::vector<std::vector<int> >::size_type i = 0; i < mat.size(); i++)
1992 {
1993 mat[i].erase(mat[i].begin() + col);
1994 }
1995}
1996
1997static BOOLEAN vvIsRowZero(const std::vector<std::vector<int> >& mat, int row)
1998{
1999 for (std::vector<std::vector<int> >::size_type i = 0; i < mat[row].size(); i++)
2000 {
2001 if (mat[row][i] != 0)
2002 return FALSE;
2003 }
2004 return TRUE;
2005}
2006
2007static BOOLEAN vvIsColumnZero(const std::vector<std::vector<int> >& mat, int col)
2008{
2009 for (std::vector<std::vector<int> >::size_type i = 0; i < mat.size(); i++)
2010 {
2011 if (mat[i][col] != 0)
2012 return FALSE;
2013 }
2014 return TRUE;
2015}
2016
2017static BOOLEAN vvIsZero(const std::vector<std::vector<int> >& mat)
2018{
2019 for (std::vector<std::vector<int> >::size_type i = 0; i < mat.size(); i++)
2020 {
2021 if (!vvIsRowZero(mat, i))
2022 return FALSE;
2023 }
2024 return TRUE;
2025}
2026
2027static std::vector<std::vector<int> > vvMult(const std::vector<std::vector<int> >& a, const std::vector<std::vector<int> >& b)
2028{
2029 std::vector<std::vector<int> >::size_type ra = a.size();
2030 std::vector<std::vector<int> >::size_type rb = b.size();
2031 std::vector<std::vector<int> >::size_type ca = a.size() > 0 ? a[0].size() : 0;
2032 std::vector<std::vector<int> >::size_type cb = b.size() > 0 ? b[0].size() : 0;
2033
2034 if (ca != rb)
2035 {
2036 WerrorS("matrix dimensions do not match");
2037 return std::vector<std::vector<int> >();
2038 }
2039
2040 std::vector<std::vector<int> > res(ra, std::vector<int>(cb));
2041 for (std::vector<std::vector<int> >::size_type i = 0; i < ra; i++)
2042 {
2043 for (std::vector<std::vector<int> >::size_type j = 0; j < cb; j++)
2044 {
2045 int sum = 0;
2046 for (std::vector<std::vector<int> >::size_type k = 0; k < ca; k++)
2047 sum += a[i][k] * b[k][j];
2048 res[i][j] = sum;
2049 }
2050 }
2051 return res;
2052}
2053
2055{
2056 // init
2057 int n = G->cols();
2058 std::vector<int> path;
2059 std::vector<BOOLEAN> visited;
2060 std::vector<BOOLEAN> cyclic;
2061 std::vector<int> cache;
2062 visited.resize(n, FALSE);
2063 cyclic.resize(n, FALSE);
2064 cache.resize(n, -2);
2065
2066 for (int v = 0; v < n; v++)
2067 {
2068 cache = countCycles(G, v, path, visited, cyclic, cache);
2069 // check that there are 0 cycles from v
2070 if (cache[v] != 0)
2071 return FALSE;
2072 }
2073 return TRUE;
2074}
2075
2076/*
2077 * Computation of the K-Dimension
2078 */
2079
2080// -1 is infinity, -2 is error
2081int lp_kDim(const ideal _G)
2082{
2083 if (rField_is_Ring(currRing)) {
2084 WerrorS("K-Dim not implemented for rings");
2085 return -2;
2086 }
2087
2088 for (int i=IDELEMS(_G)-1;i>=0; i--)
2089 {
2090 if (_G->m[i] != NULL)
2091 {
2092 if (pGetComp(_G->m[i]) != 0)
2093 {
2094 WerrorS("K-Dim not implemented for modules");
2095 return -2;
2096 }
2097 if (pGetNCGen(_G->m[i]) != 0)
2098 {
2099 WerrorS("K-Dim not implemented for bi-modules");
2100 return -2;
2101 }
2102 }
2103 }
2104
2105 ideal G = id_Head(_G, currRing); // G = LM(G) (and copy)
2106 if (TEST_OPT_PROT)
2107 Print("%d original generators\n", IDELEMS(G));
2108 idSkipZeroes(G); // remove zeros
2109 id_DelLmEquals(G, currRing); // remove duplicates
2110 if (TEST_OPT_PROT)
2111 Print("%d non-zero unique generators\n", IDELEMS(G));
2112
2113 // check if G is the zero ideal
2114 if (IDELEMS(G) == 1 && G->m[0] == NULL)
2115 {
2116 // NOTE: this is needed because if the ideal is <0>, then idSkipZeroes keeps this element, and IDELEMS is still 1!
2117 int lV = currRing->isLPring;
2118 int ncGenCount = currRing->LPncGenCount;
2119 if (lV - ncGenCount == 0)
2120 {
2121 idDelete(&G);
2122 return 1;
2123 }
2124 if (lV - ncGenCount == 1)
2125 {
2126 idDelete(&G);
2127 return -1;
2128 }
2129 if (lV - ncGenCount >= 2)
2130 {
2131 idDelete(&G);
2132 return -1;
2133 }
2134 }
2135
2136 // get the max deg
2137 long maxDeg = 0;
2138 for (int i = 0; i < IDELEMS(G); i++)
2139 {
2140 maxDeg = si_max(maxDeg, pTotaldegree(G->m[i]));
2141
2142 // also check whether G = <1>
2143 if (pIsConstantComp(G->m[i]))
2144 {
2145 WerrorS("K-Dim not defined for 0-ring"); // TODO is it minus infinity ?
2146 idDelete(&G);
2147 return -2;
2148 }
2149 }
2150 if (TEST_OPT_PROT)
2151 Print("max deg: %ld\n", maxDeg);
2152
2153
2154 // for normal words of length minDeg ... maxDeg-1
2155 // brute-force the normal words
2156 if (TEST_OPT_PROT)
2157 PrintS("Computing normal words normally...\n");
2158 long numberOfNormalWords = lp_countNormalWords(maxDeg - 1, G);
2159
2160 if (TEST_OPT_PROT)
2161 Print("%ld normal words up to length %ld\n", numberOfNormalWords, maxDeg - 1);
2162
2163 // early termination if G \subset X
2164 if (maxDeg <= 1)
2165 {
2166 int lV = currRing->isLPring;
2167 int ncGenCount = currRing->LPncGenCount;
2168 if (IDELEMS(G) == lV - ncGenCount) // V = {1} no edges
2169 {
2170 idDelete(&G);
2171 return numberOfNormalWords;
2172 }
2173 if (IDELEMS(G) == lV - ncGenCount - 1) // V = {1} with loop
2174 {
2175 idDelete(&G);
2176 return -1;
2177 }
2178 if (IDELEMS(G) <= lV - ncGenCount - 2) // V = {1} with more than one loop
2179 {
2180 idDelete(&G);
2181 return -1;
2182 }
2183 }
2184
2185 if (TEST_OPT_PROT)
2186 PrintS("Computing Ufnarovski graph...\n");
2187
2188 ideal standardWords;
2189 intvec* UG = lp_ufnarovskiGraph(G, standardWords);
2190 if (UG == NULL)
2191 {
2192 idDelete(&G);
2193 return -2;
2194 }
2195 if (errorreported)
2196 {
2197 delete UG;
2198 idDelete(&G);
2199 return -2;
2200 }
2201
2202 if (TEST_OPT_PROT)
2203 Print("Ufnarovski graph is %dx%d.\n", UG->rows(), UG->cols());
2204
2205 if (TEST_OPT_PROT)
2206 PrintS("Checking whether Ufnarovski graph is acyclic...\n");
2207
2208 if (!isAcyclic(UG))
2209 {
2210 // in this case we have infinitely many normal words
2211 return -1;
2212 }
2213
2214 std::vector<std::vector<int> > vvUG = iv2vv(UG);
2215 for (std::vector<std::vector<int> >::size_type i = 0; i < vvUG.size(); i++)
2216 {
2217 if (vvIsRowZero(vvUG, i) && vvIsColumnZero(vvUG, i)) // i is isolated vertex
2218 {
2219 vvDeleteRow(vvUG, i);
2220 vvDeleteColumn(vvUG, i);
2221 i--;
2222 }
2223 }
2224 if (TEST_OPT_PROT)
2225 Print("Simplified Ufnarovski graph to %dx%d.\n", (int)vvUG.size(), (int)vvUG.size());
2226
2227 // for normal words of length >= maxDeg
2228 // use Ufnarovski graph
2229 if (TEST_OPT_PROT)
2230 PrintS("Computing normal words via Ufnarovski graph...\n");
2231 std::vector<std::vector<int> > UGpower = vvUG;
2232 long nUGpower = 1;
2233 while (!vvIsZero(UGpower))
2234 {
2235 if (TEST_OPT_PROT)
2236 PrintS("Start count graph entries.\n");
2237 for (std::vector<std::vector<int> >::size_type i = 0; i < UGpower.size(); i++)
2238 {
2239 for (std::vector<std::vector<int> >::size_type j = 0; j < UGpower[i].size(); j++)
2240 {
2241 numberOfNormalWords += UGpower[i][j];
2242 }
2243 }
2244
2245 if (TEST_OPT_PROT)
2246 {
2247 PrintS("Done count graph entries.\n");
2248 Print("%ld normal words up to length %ld\n", numberOfNormalWords, maxDeg - 1 + nUGpower);
2249 }
2250
2251 if (TEST_OPT_PROT)
2252 PrintS("Start mat mult.\n");
2253 UGpower = vvMult(UGpower, vvUG); // TODO: avoid creation of new intvec
2254 if (TEST_OPT_PROT)
2255 PrintS("Done mat mult.\n");
2256 nUGpower++;
2257 }
2258
2259 delete UG;
2260 idDelete(&G);
2261 return numberOfNormalWords;
2262}
2263#endif
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
static int si_min(const int a, const int b)
Definition auxiliary.h:126
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
int k
Definition cfEzgcd.cc:99
Variable x
Definition cfModGcd.cc:4090
int p
Definition cfModGcd.cc:4086
CanonicalForm b
Definition cfModGcd.cc:4111
int cols() const
Definition intvec.h:96
int rows() const
Definition intvec.h:97
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_DivBy(number a, number b, const coeffs r)
test whether 'a' is divisible 'b'; for r encoding a field: TRUE iff 'b' does not represent zero in Z:...
Definition coeffs.h:747
#define Print
Definition emacs.cc:80
const CanonicalForm int s
Definition facAbsFact.cc:51
const CanonicalForm int const CFList const Variable & y
Definition facAbsFact.cc:53
CanonicalForm res
Definition facAbsFact.cc:60
const CanonicalForm & w
Definition facAbsFact.cc:51
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
int j
Definition facHensel.cc:110
VAR short errorreported
Definition feFopen.cc:23
void WerrorS(const char *s)
Definition feFopen.cc:24
#define STATIC_VAR
Definition globaldefs.h:7
#define VAR
Definition globaldefs.h:5
static long hZeroMult(scmon pure, scfmon stc, int Nstc, varset var, int Nvar)
Definition hdegree.cc:619
static ideal lp_computeNormalWords(int length, ideal M)
Definition hdegree.cc:1725
void scComputeHC(ideal S, ideal Q, int ak, poly &hEdge)
Definition hdegree.cc:1074
STATIC_VAR scmon hInd
Definition hdegree.cc:203
static void hHedgeStep(scmon pure, scfmon stc, int Nstc, varset var, int Nvar, poly hEdge)
Definition hdegree.cc:1014
static void hDimMult(scmon pure, int Npure, scfmon rad, int Nrad, varset var, int Nvar)
Definition hdegree.cc:724
ideal scKBase(int deg, ideal s, ideal Q, intvec *mv)
Definition hdegree.cc:1414
int scDimIntRing(ideal vid, ideal Q)
scDimInt for ring-coefficients
Definition hdegree.cc:136
static std::vector< int > countCycles(const intvec *_G, int v, std::vector< int > path, std::vector< BOOLEAN > visited, std::vector< BOOLEAN > cyclic, std::vector< int > cache)
Definition hdegree.cc:1575
long scMult0Int(ideal S, ideal Q)
Definition hdegree.cc:924
void hIndMult(scmon pure, int Npure, scfmon rad, int Nrad, varset var, int Nvar)
Definition hdegree.cc:382
static std::vector< std::vector< int > > vvMult(const std::vector< std::vector< int > > &a, const std::vector< std::vector< int > > &b)
Definition hdegree.cc:2027
static int scMin(int i, scfmon stc, int Nvar)
Definition hdegree.cc:1162
intvec * scIndIntvec(ideal S, ideal Q)
Definition hdegree.cc:284
static void vvDeleteRow(std::vector< std::vector< int > > &mat, int row)
Definition hdegree.cc:1984
static indset hCheck2(indset sm, scmon pure)
Definition hdegree.cc:489
STATIC_VAR poly last
Definition hdegree.cc:1138
static BOOLEAN hCheck1(indset sm, scmon pure)
Definition hdegree.cc:463
static int graphGrowth(const intvec *G)
Definition hdegree.cc:1639
static BOOLEAN vvIsColumnZero(const std::vector< std::vector< int > > &mat, int col)
Definition hdegree.cc:2007
VAR omBin indlist_bin
Definition hdegree.cc:29
STATIC_VAR poly pWork
Definition hdegree.cc:1001
VAR int hMu2
Definition hdegree.cc:27
static void hDegree(ideal S, ideal Q)
Definition hdegree.cc:800
static void vvDeleteColumn(std::vector< std::vector< int > > &mat, int col)
Definition hdegree.cc:1989
static BOOLEAN hNotZero(scfmon rad, int Nrad, varset var, int Nvar)
Definition hdegree.cc:353
int lp_kDim(const ideal _G)
Definition hdegree.cc:2081
static void scElKbase()
Definition hdegree.cc:1141
static void hHedge(poly hEdge)
Definition hdegree.cc:1003
static void hIndSolve(scmon pure, int Npure, scfmon rad, int Nrad, varset var, int Nvar)
Definition hdegree.cc:205
VAR int hCo
Definition hdegree.cc:27
intvec * lp_ufnarovskiGraph(ideal G, ideal &standardWords)
Definition hdegree.cc:1766
static int scRestrict(int &Nstc, scfmon stc, int Nvar)
Definition hdegree.cc:1174
int lp_gkDim(const ideal _G)
Definition hdegree.cc:1827
VAR indset ISet
Definition hdegree.cc:351
static std::vector< std::vector< int > > iv2vv(intvec *M)
Definition hdegree.cc:1937
static void scAllKbase(int Nvar, int ideg, int deg)
Definition hdegree.cc:1249
VAR long hMu
Definition hdegree.cc:28
static void scAll(int Nvar, int deg)
Definition hdegree.cc:1225
int scMultInt(ideal S, ideal Q)
Definition hdegree.cc:901
static void scDegKbase(scfmon stc, int Nstc, int Nvar, int deg)
Definition hdegree.cc:1259
STATIC_VAR scmon act
Definition hdegree.cc:1139
static void hCheckIndep(scmon pure)
Definition hdegree.cc:541
void scPrintDegree(int co, int mu)
Definition hdegree.cc:910
VAR indset JSet
Definition hdegree.cc:351
static int lp_countNormalWords(int upToLength, ideal M)
Definition hdegree.cc:1745
static BOOLEAN isAcyclic(const intvec *G)
Definition hdegree.cc:2054
static int scMax(int i, scfmon stc, int Nvar)
Definition hdegree.cc:1150
static ideal scIdKbase(poly q, const int rank)
Definition hdegree.cc:1396
static void hIndep(scmon pure)
Definition hdegree.cc:368
static void scInKbase(scfmon stc, int Nstc, int Nvar)
Definition hdegree.cc:1340
static void hProject(scmon pure, varset sel)
Definition hdegree.cc:701
static BOOLEAN vvIsZero(const std::vector< std::vector< int > > &mat)
Definition hdegree.cc:2017
int scDimInt(ideal S, ideal Q)
ideal dimension
Definition hdegree.cc:78
static BOOLEAN vvIsRowZero(const std::vector< std::vector< int > > &mat, int row)
Definition hdegree.cc:1997
static void _lp_computeNormalWords(ideal words, int &numberOfNormalWords, int length, ideal M, int minDeg, int &last)
Definition hdegree.cc:1666
void hDimSolve(scmon pure, int Npure, scfmon rad, int Nrad, varset var, int Nvar)
Definition hdegree.cc:35
void hIndAllMult(scmon pure, int Npure, scfmon rad, int Nrad, varset var, int Nvar)
Definition hdegree.cc:562
monf hCreate(int Nvar)
Definition hutil.cc:996
void hComp(scfmon exist, int Nexist, int ak, scfmon stc, int *Nstc)
Definition hutil.cc:154
void hLex2S(scfmon rad, int e1, int a2, int e2, varset var, int Nvar, scfmon w)
Definition hutil.cc:812
VAR scfmon hstc
Definition hutil.cc:16
VAR varset hvar
Definition hutil.cc:18
void hKill(monf xmem, int Nvar)
Definition hutil.cc:1010
VAR int hNexist
Definition hutil.cc:19
void hElimS(scfmon stc, int *e1, int a2, int e2, varset var, int Nvar)
Definition hutil.cc:672
void hLexS(scfmon stc, int Nstc, varset var, int Nvar)
Definition hutil.cc:506
void hDelete(scfmon ev, int ev_length)
Definition hutil.cc:140
VAR scmon hpur0
Definition hutil.cc:17
VAR monf stcmem
Definition hutil.cc:21
scfmon hGetmem(int lm, scfmon old, monp monmem)
Definition hutil.cc:1023
void hPure(scfmon stc, int a, int *Nstc, varset var, int Nvar, scmon pure, int *Npure)
Definition hutil.cc:621
VAR scfmon hwork
Definition hutil.cc:16
void hSupp(scfmon stc, int Nstc, varset var, int *Nvar)
Definition hutil.cc:174
void hLexR(scfmon rad, int Nrad, varset var, int Nvar)
Definition hutil.cc:565
VAR scmon hpure
Definition hutil.cc:17
void hStepR(scfmon rad, int Nrad, varset var, int Nvar, int *a)
Definition hutil.cc:974
void hLex2R(scfmon rad, int e1, int a2, int e2, varset var, int Nvar, scfmon w)
Definition hutil.cc:880
VAR scfmon hrad
Definition hutil.cc:16
VAR int hisModule
Definition hutil.cc:20
void hStepS(scfmon stc, int Nstc, varset var, int Nvar, int *a, int *x)
Definition hutil.cc:949
void hStaircase(scfmon stc, int *Nstc, varset var, int Nvar)
Definition hutil.cc:313
void hElimR(scfmon rad, int *e1, int a2, int e2, varset var, int Nvar)
Definition hutil.cc:742
VAR monf radmem
Definition hutil.cc:21
void hOrdSupp(scfmon stc, int Nstc, varset var, int Nvar)
Definition hutil.cc:202
VAR varset hsel
Definition hutil.cc:18
VAR int hNpure
Definition hutil.cc:19
VAR int hNrad
Definition hutil.cc:19
scfmon hInit(ideal S, ideal Q, int *Nexist)
Definition hutil.cc:31
VAR scfmon hexist
Definition hutil.cc:16
void hRadical(scfmon rad, int *Nrad, int Nvar)
Definition hutil.cc:411
scmon hGetpure(scmon p)
Definition hutil.cc:1052
VAR int hNstc
Definition hutil.cc:19
VAR int hNvar
Definition hutil.cc:19
scmon * scfmon
Definition hutil.h:15
indlist * indset
Definition hutil.h:28
int * varset
Definition hutil.h:16
int * scmon
Definition hutil.h:14
#define idDelete(H)
delete an ideal
Definition ideals.h:29
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 idCopy(ideal A)
Definition ideals.h:60
#define idPosConstant(I)
index of generator with leading term in ground ring (if any); otherwise -1
Definition ideals.h:37
static BOOLEAN length(leftv result, leftv arg)
Definition interval.cc:257
intvec * ivCopy(const intvec *o)
Definition intvec.h:146
#define IMATELEM(M, I, J)
Definition intvec.h:86
STATIC_VAR TreeM * G
Definition janet.cc:31
static matrix mu(matrix A, const ring R)
Definition matpol.cc:2028
#define assume(x)
Definition mod2.h:389
#define pNext(p)
Definition monomials.h:36
#define pSetCoeff0(p, n)
Definition monomials.h:59
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
const int MAX_INT_VAL
Definition mylimits.h:12
#define nCopy(n)
Definition numbers.h:15
#define nInit(i)
Definition numbers.h:24
#define omFreeSize(addr, size)
#define omAlloc(size)
#define omAlloc0Bin(bin)
#define omAlloc0(size)
#define omFreeBin(addr, bin)
#define omGetSpecBin(size)
Definition omBin.h:11
#define NULL
Definition omList.c:12
omBin_t * omBin
Definition omStructs.h:12
#define TEST_OPT_PROT
Definition options.h:105
static int index(p_Length length, p_Ord ord)
int p_IsPurePower(const poly p, const ring r)
return i, if head depends only on var(i)
Definition p_polys.cc:1227
static int pLength(poly a)
Definition p_polys.h:190
static void p_Delete(poly *p, const ring r)
Definition p_polys.h:903
VAR ring currRing
Widely used global variable which specifies the current polynomial ring for Singular interpreter and ...
Definition polys.cc:13
Compatibility layer for legacy polynomial operations (over currRing).
static long pTotaldegree(poly p)
Definition polys.h:283
#define pTest(p)
Definition polys.h:415
#define pDelete(p_ptr)
Definition polys.h:187
#define pSetm(p)
Definition polys.h:272
#define pGetComp(p)
Component.
Definition polys.h:38
#define pIsConstantComp(p)
return true if p is either NULL, or if all exponents of p are 0, Comp of p might be !...
Definition polys.h:237
#define pSetExpV(p, e)
Definition polys.h:98
#define pSetComp(p, v)
Definition polys.h:39
#define pMult(p, q)
Definition polys.h:208
static void pLmFree(poly p)
frees the space of the monomial m, assumes m != NULL coef is not freed, m is not advanced
Definition polys.h:71
#define pGetExp(p, i)
Exponent.
Definition polys.h:42
#define pInit()
allocates a new monomial and initializes everything to 0
Definition polys.h:62
#define pSetExp(p, i, v)
Definition polys.h:43
#define pLmCmp(p, q)
returns 0|1|-1 if p=q|p>q|p<q w.r.t monomial ordering
Definition polys.h:106
#define pCopy(p)
return a copy of the poly
Definition polys.h:186
#define pOne()
Definition polys.h:316
poly * polyset
Definition polys.h:260
void PrintS(const char *s)
Definition reporter.cc:288
void PrintLn()
Definition reporter.cc:314
static BOOLEAN rField_is_Z(const ring r)
Definition ring.h:520
#define rField_is_Ring(R)
Definition ring.h:491
BOOLEAN p_LPDivisibleBy(poly a, poly b, const ring r)
Definition shiftop.cc:776
poly p_LPVarAt(poly p, int pos, const ring r)
Definition shiftop.cc:845
#define pGetNCGen(p)
Definition shiftop.h:65
ideal idInit(int idsize, int rank)
initialise an ideal / module
ideal id_Head(ideal h, const ring r)
returns the ideals of initial terms
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.
void idSkipZeroes(ideal ide)
gives an ideal/module the minimal possible size
#define IDELEMS(i)
#define id_Test(A, lR)
static int idElem(const ideal F)
number of non-zero polys in F
#define id_LmTest(A, lR)
#define M
Definition sirandom.c:25
#define Q
Definition sirandom.c:26
#define loop
Definition structs.h:71