1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: shiftgb.cc,v 1.3 2007-11-06 12:58:35 Singular Exp $ */ |
---|
5 | /* |
---|
6 | * ABSTRACT: kernel: utils for shift GB and free GB |
---|
7 | */ |
---|
8 | |
---|
9 | #include "mod2.h" |
---|
10 | |
---|
11 | #ifdef HAVE_PLURAL |
---|
12 | #include "febase.h" |
---|
13 | #include "ring.h" |
---|
14 | #include "polys.h" |
---|
15 | #include "numbers.h" |
---|
16 | #include "ideals.h" |
---|
17 | #include "matpol.h" |
---|
18 | #include "kbuckets.h" |
---|
19 | #include "kstd1.h" |
---|
20 | #include "sbuckets.h" |
---|
21 | #include "p_Mult_q.h" |
---|
22 | #include "kutil.h" |
---|
23 | #include "structs.h" |
---|
24 | #include "omalloc.h" |
---|
25 | #include "khstd.h" |
---|
26 | #include "kbuckets.h" |
---|
27 | #include "weight.h" |
---|
28 | #include "intvec.h" |
---|
29 | #include "structs.h" |
---|
30 | #include "kInline.cc" |
---|
31 | #include "stairc.h" |
---|
32 | #include "weight.h" |
---|
33 | #include "intvec.h" |
---|
34 | #include "timer.h" |
---|
35 | #include "shiftgb.h" |
---|
36 | #include "sca.h" |
---|
37 | |
---|
38 | |
---|
39 | #define freeT(A,v) omFreeSize((ADDRESS)A,(v+1)*sizeof(int)) |
---|
40 | |
---|
41 | poly pLPshift(poly p, int sh, int uptodeg, int lV) |
---|
42 | { |
---|
43 | /* assume shift takes place */ |
---|
44 | /* shifts the poly p by sh */ |
---|
45 | |
---|
46 | /* assume sh and uptodeg agree */ |
---|
47 | |
---|
48 | if (sh == 0) return(p); /* the zero shift */ |
---|
49 | |
---|
50 | poly q = NULL; |
---|
51 | poly pp = pCopy(p); |
---|
52 | while (pp!=NULL) |
---|
53 | { |
---|
54 | q = p_Add_q(q, pmLPshift(pp,sh,uptodeg,lV),currRing); |
---|
55 | pIter(pp); |
---|
56 | } |
---|
57 | /* delete pp? */ |
---|
58 | /* int version: returns TRUE if it was successful */ |
---|
59 | return(q); |
---|
60 | } |
---|
61 | |
---|
62 | poly pmLPshift(poly p, int sh, int uptodeg, int lV) |
---|
63 | { |
---|
64 | /* pm is a monomial */ |
---|
65 | |
---|
66 | if (sh == 0) return(p); /* the zero shift */ |
---|
67 | |
---|
68 | if (sh < 0 ) |
---|
69 | { |
---|
70 | #ifdef PDEBUG |
---|
71 | Print("pmLPshift: negative shift requested"); |
---|
72 | #endif |
---|
73 | return(NULL); /* violation, 2check */ |
---|
74 | } |
---|
75 | |
---|
76 | int L = pmLastVblock(p,lV); |
---|
77 | if (L+sh-1 > uptodeg) |
---|
78 | { |
---|
79 | #ifdef PDEBUG |
---|
80 | Print("pmLPshift: too big shift requested"); |
---|
81 | #endif |
---|
82 | return(NULL); /* violation, 2check */ |
---|
83 | } |
---|
84 | int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
85 | int *s=(int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
86 | pGetExpV(p,e); |
---|
87 | number c = pGetCoeff(p); |
---|
88 | int j; |
---|
89 | for (j=1; j<=currRing->N; j++) |
---|
90 | { |
---|
91 | if (e[j]) |
---|
92 | { |
---|
93 | s[j + (sh*lV)] = e[j]; /* actually 1 */ |
---|
94 | } |
---|
95 | } |
---|
96 | poly m = pOne(); |
---|
97 | pSetExpV(m,s); |
---|
98 | /* pSetm(m); */ /* done in the pSetExpV */ |
---|
99 | pSetCoeff0(m,c); |
---|
100 | freeT(e, currRing->N); |
---|
101 | freeT(s, currRing->N); |
---|
102 | return(m); |
---|
103 | } |
---|
104 | |
---|
105 | int pLastVblock(poly p, int lV) |
---|
106 | { |
---|
107 | /* returns the number of maximal block */ |
---|
108 | /* appearing among the monomials of p */ |
---|
109 | poly q = pCopy(p); /* need it ? */ |
---|
110 | int ans = 0; |
---|
111 | int ansnew = 0; |
---|
112 | while (q!=NULL) |
---|
113 | { |
---|
114 | ansnew = pmLastVblock(q,lV); |
---|
115 | ans = si_max(ans,ansnew); |
---|
116 | pIter(q); |
---|
117 | } |
---|
118 | /* do not need to delete q */ |
---|
119 | return(ans); |
---|
120 | } |
---|
121 | |
---|
122 | int pmLastVblock(poly p, int lV) |
---|
123 | { |
---|
124 | /* for a monomial p, returns the number of the last block */ |
---|
125 | /* where a nonzero exponent is sitting */ |
---|
126 | int *e=(int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
127 | pGetExpV(p,e); |
---|
128 | int j,b; |
---|
129 | j = currRing->N; |
---|
130 | while ( (!e[j]) && (j>=1) ) j--; |
---|
131 | if (j==0) |
---|
132 | { |
---|
133 | #ifdef PDEBUG |
---|
134 | Print("pmLastVblock: unexpected zero exponent"); |
---|
135 | #endif |
---|
136 | return(j); |
---|
137 | } |
---|
138 | b = (int)(j/lV) + 1; /* the number of the block, >=1 */ |
---|
139 | return (b); |
---|
140 | } |
---|
141 | |
---|
142 | int isInV(poly p, int lV) |
---|
143 | { |
---|
144 | if (lV <= 0) return(0); |
---|
145 | /* returns 1 iff p is in V */ |
---|
146 | /* that is in each block up to a certain one there is only one nonzero exponent */ |
---|
147 | /* lV = the length of V = the number of orig vars */ |
---|
148 | int *e = (int *)omAlloc0((currRing->N+1)*sizeof(int)); |
---|
149 | int b = (int)(currRing->N)/lV; /* the number of blocks */ |
---|
150 | int *B = (int *)omAlloc0((b+1)*sizeof(int)); /* the num of elements in a block */ |
---|
151 | pGetExpV(p,e); |
---|
152 | int i,j; |
---|
153 | for (j=1; j<=b; j++) |
---|
154 | { |
---|
155 | /* we go through all the vars */ |
---|
156 | /* by blocks in lV vars */ |
---|
157 | for (i=(j-1)*lV + 1; i<= j*lV; i++) |
---|
158 | { |
---|
159 | if (!e[i]) B[j] = B[j]+1; |
---|
160 | } |
---|
161 | } |
---|
162 | j = b; |
---|
163 | while ( (!B[j]) && (j>=1)) j--; |
---|
164 | if (j==0) |
---|
165 | { |
---|
166 | /* it is a zero exp vector, which is in V */ |
---|
167 | return(1); |
---|
168 | } |
---|
169 | /* now B[j] != 0 */ |
---|
170 | for (j; j>=1; j--) |
---|
171 | { |
---|
172 | if (B[j]!=1) |
---|
173 | { |
---|
174 | return(0); |
---|
175 | } |
---|
176 | } |
---|
177 | return(1); |
---|
178 | } |
---|
179 | |
---|
180 | /* shiftgb stuff */ |
---|
181 | |
---|
182 | void initBbaShift(ideal F,kStrategy strat) |
---|
183 | { |
---|
184 | int i; |
---|
185 | idhdl h; |
---|
186 | /* setting global variables ------------------- */ |
---|
187 | strat->enterS = enterSBba; |
---|
188 | |
---|
189 | strat->red = redFirstShift; |
---|
190 | |
---|
191 | /* perhaps the following? |
---|
192 | * strat->LazyPass *=4; |
---|
193 | * strat->red = redHomogShift; |
---|
194 | */ |
---|
195 | |
---|
196 | /* strat->red = redHoney; |
---|
197 | * if (strat->honey) |
---|
198 | * strat->red = redHoney; |
---|
199 | * else if (pLexOrder && !strat->homog) |
---|
200 | * strat->red = redLazy; |
---|
201 | * else |
---|
202 | * { |
---|
203 | * strat->LazyPass *=4; |
---|
204 | * strat->red = redHomog; |
---|
205 | * } |
---|
206 | *#ifdef HAVE_RINGS //TODO Oliver |
---|
207 | * if (rField_is_Ring(currRing)) { |
---|
208 | * strat->red = redRing2toM; |
---|
209 | * } |
---|
210 | *#endif |
---|
211 | */ |
---|
212 | |
---|
213 | if (pLexOrder && strat->honey) |
---|
214 | strat->initEcart = initEcartNormal; |
---|
215 | else |
---|
216 | strat->initEcart = initEcartBBA; |
---|
217 | if (strat->honey) |
---|
218 | strat->initEcartPair = initEcartPairMora; |
---|
219 | else |
---|
220 | strat->initEcartPair = initEcartPairBba; |
---|
221 | strat->kIdeal = NULL; |
---|
222 | //if (strat->ak==0) strat->kIdeal->rtyp=IDEAL_CMD; |
---|
223 | //else strat->kIdeal->rtyp=MODUL_CMD; |
---|
224 | //strat->kIdeal->data=(void *)strat->Shdl; |
---|
225 | if ((TEST_OPT_WEIGHTM)&&(F!=NULL)) |
---|
226 | { |
---|
227 | //interred machen Aenderung |
---|
228 | pFDegOld=pFDeg; |
---|
229 | pLDegOld=pLDeg; |
---|
230 | //h=ggetid("ecart"); |
---|
231 | //if ((h!=NULL) /*&& (IDTYP(h)==INTVEC_CMD)*/) |
---|
232 | //{ |
---|
233 | // ecartWeights=iv2array(IDINTVEC(h)); |
---|
234 | //} |
---|
235 | //else |
---|
236 | { |
---|
237 | ecartWeights=(short *)omAlloc((pVariables+1)*sizeof(short)); |
---|
238 | /*uses automatic computation of the ecartWeights to set them*/ |
---|
239 | kEcartWeights(F->m,IDELEMS(F)-1,ecartWeights); |
---|
240 | } |
---|
241 | pRestoreDegProcs(totaldegreeWecart, maxdegreeWecart); |
---|
242 | if (TEST_OPT_PROT) |
---|
243 | { |
---|
244 | for(i=1; i<=pVariables; i++) |
---|
245 | Print(" %d",ecartWeights[i]); |
---|
246 | PrintLn(); |
---|
247 | mflush(); |
---|
248 | } |
---|
249 | } |
---|
250 | } |
---|
251 | #endif |
---|