1 | // -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
---|
2 | /*****************************************************************************\ |
---|
3 | * Computer Algebra System SINGULAR |
---|
4 | \*****************************************************************************/ |
---|
5 | /** @file DebugPrint.cc |
---|
6 | * |
---|
7 | * Here we implement dPrint-s. |
---|
8 | * |
---|
9 | * ABSTRACT: debug-detailed-printing |
---|
10 | * |
---|
11 | * @author Oleksandr Motsak |
---|
12 | * |
---|
13 | * |
---|
14 | **/ |
---|
15 | /*****************************************************************************/ |
---|
16 | |
---|
17 | #ifdef HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif /* HAVE_CONFIG_H */ |
---|
20 | |
---|
21 | // include header file |
---|
22 | #include <kernel/mod2.h> |
---|
23 | |
---|
24 | |
---|
25 | #include <omalloc/omalloc.h> |
---|
26 | |
---|
27 | #include <misc/intvec.h> |
---|
28 | |
---|
29 | #include <misc/options.h> |
---|
30 | |
---|
31 | #include <polys/monomials/p_polys.h> |
---|
32 | #include <polys/kbuckets.h> |
---|
33 | |
---|
34 | |
---|
35 | #include <kernel/structs.h> |
---|
36 | #include <kernel/febase.h> |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | #include <kernel/ideals.h> |
---|
41 | |
---|
42 | #include <kernel/syz.h> |
---|
43 | // #include <kernel/longrat.h> |
---|
44 | #include <kernel/kutil.h> |
---|
45 | #include <kernel/kstd1.h> |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | #include <kernel/polys.h> |
---|
50 | // #include <kernel/pInline2.h> |
---|
51 | |
---|
52 | #include "myNF.h" |
---|
53 | |
---|
54 | |
---|
55 | #ifdef HAVE_PLURAL |
---|
56 | #define PLURAL_INTERNAL_DECLARATIONS 1 |
---|
57 | #endif |
---|
58 | |
---|
59 | #include <polys/nc/sca.h> |
---|
60 | #include <polys/nc/nc.h> |
---|
61 | #include <kernel/nc.h> |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | BEGIN_NAMESPACE() |
---|
66 | |
---|
67 | /// reduction procedure for the normal form, which uses pLength instead of pSize! |
---|
68 | static poly redNFLength (poly h,int &max_ind,int nonorm,kStrategy strat) |
---|
69 | { |
---|
70 | if (h==NULL) return NULL; |
---|
71 | int j; |
---|
72 | max_ind=strat->sl; |
---|
73 | |
---|
74 | if (0 > strat->sl) |
---|
75 | { |
---|
76 | return h; |
---|
77 | } |
---|
78 | LObject P(h); |
---|
79 | P.SetShortExpVector(); |
---|
80 | P.bucket = kBucketCreate(currRing); |
---|
81 | kBucketInit(P.bucket,P.p,pLength(P.p)); |
---|
82 | kbTest(P.bucket); |
---|
83 | #ifdef HAVE_RINGS |
---|
84 | BOOLEAN is_ring = rField_is_Ring(currRing); |
---|
85 | #endif |
---|
86 | #ifdef KDEBUG |
---|
87 | if (TEST_OPT_DEBUG) |
---|
88 | { |
---|
89 | PrintS("redNF: starting S: "); |
---|
90 | for( j = 0; j <= max_ind; j++ ) |
---|
91 | { |
---|
92 | Print("S[%d] (of size: %d): ", j, pLength(strat->S[j])); |
---|
93 | wrp(strat->S[j]); |
---|
94 | } |
---|
95 | }; |
---|
96 | #endif |
---|
97 | |
---|
98 | loop |
---|
99 | { |
---|
100 | j=kFindDivisibleByInS(strat,&max_ind,&P); |
---|
101 | if (j>=0) |
---|
102 | { |
---|
103 | #ifdef HAVE_RINGS |
---|
104 | if (!is_ring) |
---|
105 | { |
---|
106 | #endif |
---|
107 | int sl=pLength(strat->S[j]); |
---|
108 | int jj=j; |
---|
109 | loop |
---|
110 | { |
---|
111 | int sll; |
---|
112 | jj=kFindNextDivisibleByInS(strat,jj+1,max_ind,&P); |
---|
113 | if (jj<0) break; |
---|
114 | sll=pLength(strat->S[jj]); |
---|
115 | if (sll<sl) |
---|
116 | { |
---|
117 | #ifdef KDEBUG |
---|
118 | if (TEST_OPT_DEBUG) Print("better(S%d:%d -> S%d:%d)\n",j,sl,jj,sll); |
---|
119 | #endif |
---|
120 | //else if (TEST_OPT_PROT) { PrintS("b"); mflush(); } |
---|
121 | j=jj; |
---|
122 | sl=sll; |
---|
123 | } |
---|
124 | } |
---|
125 | if ((nonorm==0) && (!nIsOne(pGetCoeff(strat->S[j])))) |
---|
126 | { |
---|
127 | pNorm(strat->S[j]); |
---|
128 | //if (TEST_OPT_PROT) { PrintS("n"); mflush(); } |
---|
129 | } |
---|
130 | #ifdef HAVE_RINGS |
---|
131 | } |
---|
132 | #endif |
---|
133 | nNormalize(pGetCoeff(P.p)); |
---|
134 | #ifdef KDEBUG |
---|
135 | if (TEST_OPT_DEBUG) |
---|
136 | { |
---|
137 | PrintS("red:"); |
---|
138 | wrp(h); |
---|
139 | PrintS(" with "); |
---|
140 | wrp(strat->S[j]); |
---|
141 | } |
---|
142 | #endif |
---|
143 | #ifdef HAVE_PLURAL |
---|
144 | if (rIsPluralRing(currRing)) |
---|
145 | { |
---|
146 | number coef; |
---|
147 | nc_kBucketPolyRed(P.bucket,strat->S[j],&coef); |
---|
148 | nDelete(&coef); |
---|
149 | } |
---|
150 | else |
---|
151 | #endif |
---|
152 | { |
---|
153 | number coef; |
---|
154 | coef=kBucketPolyRed(P.bucket,strat->S[j],pLength(strat->S[j]),strat->kNoether); |
---|
155 | nDelete(&coef); |
---|
156 | } |
---|
157 | h = kBucketGetLm(P.bucket); // FRAGE OLIVER |
---|
158 | if (h==NULL) |
---|
159 | { |
---|
160 | kBucketDestroy(&P.bucket); |
---|
161 | |
---|
162 | #ifdef KDEBUG |
---|
163 | if (TEST_OPT_DEBUG) |
---|
164 | { |
---|
165 | PrintS("redNF: starting S: "); |
---|
166 | for( j = 0; j <= max_ind; j++ ) |
---|
167 | { |
---|
168 | Print("S[%d] (of size: %d): ", j, pLength(strat->S[j])); |
---|
169 | wrp(strat->S[j]); |
---|
170 | } |
---|
171 | }; |
---|
172 | #endif |
---|
173 | |
---|
174 | return NULL; |
---|
175 | } |
---|
176 | kbTest(P.bucket); |
---|
177 | P.p=h; |
---|
178 | P.t_p=NULL; |
---|
179 | P.SetShortExpVector(); |
---|
180 | #ifdef KDEBUG |
---|
181 | if (TEST_OPT_DEBUG) |
---|
182 | { |
---|
183 | PrintS("\nto:"); |
---|
184 | wrp(h); |
---|
185 | PrintLn(); |
---|
186 | } |
---|
187 | #endif |
---|
188 | } |
---|
189 | else |
---|
190 | { |
---|
191 | P.p=kBucketClear(P.bucket); |
---|
192 | kBucketDestroy(&P.bucket); |
---|
193 | pNormalize(P.p); |
---|
194 | |
---|
195 | #ifdef KDEBUG |
---|
196 | if (TEST_OPT_DEBUG) |
---|
197 | { |
---|
198 | PrintS("redNF: starting S: "); |
---|
199 | for( j = 0; j <= max_ind; j++ ) |
---|
200 | { |
---|
201 | Print("S[%d] (of size: %d): ", j, pLength(strat->S[j])); |
---|
202 | wrp(strat->S[j]); |
---|
203 | } |
---|
204 | }; |
---|
205 | #endif |
---|
206 | |
---|
207 | return P.p; |
---|
208 | } |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | poly kNF2Length (ideal F,ideal Q,poly q,kStrategy strat, int lazyReduce) |
---|
214 | { |
---|
215 | assume(q!=NULL); |
---|
216 | assume(!(idIs0(F)&&(Q==NULL))); // NF(q, std(0) in polynomial ring? |
---|
217 | |
---|
218 | // lazy_reduce flags: can be combined by | |
---|
219 | //#define KSTD_NF_LAZY 1 |
---|
220 | // do only a reduction of the leading term |
---|
221 | //#define KSTD_NF_NONORM 4 |
---|
222 | // only global: avoid normalization, return a multiply of NF |
---|
223 | poly p; |
---|
224 | // int i; |
---|
225 | |
---|
226 | //if ((idIs0(F))&&(Q==NULL)) |
---|
227 | // return pCopy(q); /*F=0*/ |
---|
228 | //strat->ak = id_RankFreeModule(F, RING!); |
---|
229 | /*- creating temp data structures------------------- -*/ |
---|
230 | BITSET save1; |
---|
231 | SI_SAVE_OPT1(save1); |
---|
232 | si_opt_1|=Sy_bit(OPT_REDTAIL); |
---|
233 | initBuchMoraCrit(strat); |
---|
234 | strat->initEcart = initEcartBBA; |
---|
235 | strat->enterS = enterSBba; |
---|
236 | #ifndef NO_BUCKETS |
---|
237 | strat->use_buckets = (!TEST_OPT_NOT_BUCKETS) && (!rIsPluralRing(currRing)); |
---|
238 | #endif |
---|
239 | /*- set S -*/ |
---|
240 | strat->sl = -1; |
---|
241 | /*- init local data struct.---------------------------------------- -*/ |
---|
242 | /*Shdl=*/initS(F,Q,strat); |
---|
243 | /*- compute------------------------------------------------------- -*/ |
---|
244 | //if ((TEST_OPT_INTSTRATEGY)&&(lazyReduce==0)) |
---|
245 | //{ |
---|
246 | // for (i=strat->sl;i>=0;i--) |
---|
247 | // pNorm(strat->S[i]); |
---|
248 | //} |
---|
249 | assume(kTest(strat)); |
---|
250 | if (TEST_OPT_PROT) { PrintS("r"); mflush(); } |
---|
251 | |
---|
252 | if (BVERBOSE(23)) kDebugPrint(strat); |
---|
253 | |
---|
254 | int max_ind; |
---|
255 | p = redNFLength(pCopy(q),max_ind,lazyReduce & KSTD_NF_NONORM,strat); |
---|
256 | if ((p!=NULL)&&((lazyReduce & KSTD_NF_LAZY)==0)) |
---|
257 | { |
---|
258 | if (TEST_OPT_PROT) { PrintS("t"); mflush(); } |
---|
259 | #ifdef HAVE_RINGS |
---|
260 | if (rField_is_Ring(currRing)) |
---|
261 | { |
---|
262 | p = redtailBba_Z(p,max_ind,strat); |
---|
263 | } |
---|
264 | else |
---|
265 | #endif |
---|
266 | { |
---|
267 | si_opt_1 &= ~Sy_bit(OPT_INTSTRATEGY); |
---|
268 | p = redtailBba(p,max_ind,strat,(lazyReduce & KSTD_NF_NONORM)==0); |
---|
269 | } |
---|
270 | } |
---|
271 | /*- release temp data------------------------------- -*/ |
---|
272 | omfree(strat->sevS); |
---|
273 | omfree(strat->ecartS); |
---|
274 | omfree(strat->T); |
---|
275 | omfree(strat->sevT); |
---|
276 | omfree(strat->R); |
---|
277 | omfree(strat->S_2_R); |
---|
278 | omfree(strat->L); |
---|
279 | omfree(strat->B); |
---|
280 | omfree(strat->fromQ); |
---|
281 | idDelete(&strat->Shdl); |
---|
282 | SI_RESTORE_OPT1(save1); |
---|
283 | if (TEST_OPT_PROT) PrintLn(); |
---|
284 | return p; |
---|
285 | } |
---|
286 | |
---|
287 | END_NAMESPACE |
---|
288 | |
---|
289 | |
---|
290 | BEGIN_NAMESPACE_SINGULARXX BEGIN_NAMESPACE(NF) |
---|
291 | |
---|
292 | poly kNFLength(ideal F, ideal Q, poly p,int syzComp, int lazyReduce) |
---|
293 | { |
---|
294 | if (p==NULL) |
---|
295 | return NULL; |
---|
296 | |
---|
297 | poly pp = p; |
---|
298 | |
---|
299 | #ifdef HAVE_PLURAL |
---|
300 | if(rIsSCA(currRing)) |
---|
301 | { |
---|
302 | const unsigned int m_iFirstAltVar = scaFirstAltVar(currRing); |
---|
303 | const unsigned int m_iLastAltVar = scaLastAltVar(currRing); |
---|
304 | pp = p_KillSquares(pp, m_iFirstAltVar, m_iLastAltVar, currRing); |
---|
305 | |
---|
306 | if(Q == currQuotient) |
---|
307 | Q = SCAQuotient(currRing); |
---|
308 | } |
---|
309 | #endif |
---|
310 | |
---|
311 | if ((idIs0(F))&&(Q==NULL)) |
---|
312 | { |
---|
313 | #ifdef HAVE_PLURAL |
---|
314 | if(p != pp) |
---|
315 | return pp; |
---|
316 | #endif |
---|
317 | return pCopy(p); /*F+Q=0*/ |
---|
318 | } |
---|
319 | |
---|
320 | kStrategy strat=new skStrategy; |
---|
321 | strat->syzComp = syzComp; |
---|
322 | strat->ak = si_max(id_RankFreeModule(F, currRing),pMaxComp(p)); |
---|
323 | poly res; |
---|
324 | |
---|
325 | if (rHasLocalOrMixedOrdering(currRing)==-1) |
---|
326 | res=kNF1(F,Q,pp,strat,lazyReduce); |
---|
327 | else |
---|
328 | res=kNF2Length(F,Q,pp,strat,lazyReduce); |
---|
329 | delete(strat); |
---|
330 | |
---|
331 | #ifdef HAVE_PLURAL |
---|
332 | if(pp != p) |
---|
333 | p_Delete(&pp, currRing); |
---|
334 | #endif |
---|
335 | return res; |
---|
336 | } |
---|
337 | |
---|
338 | END_NAMESPACE END_NAMESPACE_SINGULARXX |
---|
339 | |
---|
340 | // Vi-modeline: vim: filetype=c:syntax:shiftwidth=2:tabstop=8:textwidth=0:expandtab |
---|