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