1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: polys-impl.cc,v 1.12 1998-03-23 22:51:03 obachman Exp $ */ |
---|
5 | |
---|
6 | /*************************************************************** |
---|
7 | * |
---|
8 | * File: polys-impl.cc |
---|
9 | * Purpose: low-level procuders for polys. |
---|
10 | * |
---|
11 | * If you touch anything here, you better know what you are doing. |
---|
12 | * What is here should not be used directly from other routines -- the |
---|
13 | * encapsulations in polys.[h,cc] should be used, instead. |
---|
14 | * |
---|
15 | ***************************************************************/ |
---|
16 | #ifndef POLYS_IMPL_CC |
---|
17 | #define POLYS_IMPL_CC |
---|
18 | |
---|
19 | #include <stdio.h> |
---|
20 | #include <string.h> |
---|
21 | #include "mod2.h" |
---|
22 | #include "tok.h" |
---|
23 | #include "structs.h" |
---|
24 | #include "mmemory.h" |
---|
25 | #include "febase.h" |
---|
26 | #include "numbers.h" |
---|
27 | #include "polys.h" |
---|
28 | #include "ring.h" |
---|
29 | #include "ipid.h" |
---|
30 | |
---|
31 | /*************************************************************** |
---|
32 | * |
---|
33 | * Low - level routines for which deal with var indicies |
---|
34 | * |
---|
35 | ***************************************************************/ |
---|
36 | // gets var indicies w.r.t. the ring r |
---|
37 | void pGetVarIndicies(ring r, int &VarOffset, int &VarCompIndex, |
---|
38 | int &VarLowIndex, int &VarHighIndex) |
---|
39 | { |
---|
40 | // at the moment, non-default var indicies are only used for simple orderings |
---|
41 | if (rHasSimpleOrder(r)) |
---|
42 | { |
---|
43 | short s_order; |
---|
44 | if (r->order[0] == ringorder_c || r->order[0] == ringorder_C) |
---|
45 | s_order = r->order[1]; |
---|
46 | else |
---|
47 | s_order = r->order[0]; |
---|
48 | |
---|
49 | switch(s_order) |
---|
50 | { |
---|
51 | case ringorder_dp: |
---|
52 | case ringorder_wp: |
---|
53 | case ringorder_ds: |
---|
54 | case ringorder_ws: |
---|
55 | case ringorder_unspec: |
---|
56 | pGetVarIndicies_RevLex(r->N, VarOffset, VarCompIndex, |
---|
57 | VarLowIndex, VarHighIndex); |
---|
58 | break; |
---|
59 | |
---|
60 | #ifdef PDEBUG |
---|
61 | case ringorder_lp: |
---|
62 | case ringorder_Dp: |
---|
63 | case ringorder_Wp: |
---|
64 | case ringorder_Ds: |
---|
65 | case ringorder_Ws: |
---|
66 | case ringorder_ls: |
---|
67 | #else |
---|
68 | default: |
---|
69 | #endif |
---|
70 | pGetVarIndicies_Lex(r->N, VarOffset, VarCompIndex, |
---|
71 | VarLowIndex, VarHighIndex); |
---|
72 | #ifdef PDEBUG |
---|
73 | break; |
---|
74 | default: |
---|
75 | Werror("wrong internal ordering:%d at %s, l:%d\n", |
---|
76 | s_order,__FILE__,__LINE__); |
---|
77 | #endif |
---|
78 | } |
---|
79 | } |
---|
80 | else |
---|
81 | // default var indicies are used |
---|
82 | pGetVarIndicies(r->N, VarOffset, VarCompIndex, VarLowIndex, VarHighIndex); |
---|
83 | } |
---|
84 | |
---|
85 | |
---|
86 | inline void RingCopy2ExpV(poly dest, poly src, ring src_r) |
---|
87 | { |
---|
88 | for (int i=pVariables; i; i--) |
---|
89 | pSetExp(dest, i, pRingGetExp(src_r, src, i)); |
---|
90 | pSetComp(dest, pRingGetComp(src_r, src)); |
---|
91 | } |
---|
92 | |
---|
93 | // Returns a converted copy (in the sense that the returned poly is |
---|
94 | // poly of currRing) of poly p which is from ring r -- assumes that |
---|
95 | // currRing and r have the same number of variables, i.e. that polys |
---|
96 | // from r can be "fetched" into currRing |
---|
97 | #ifdef PDEBUG |
---|
98 | poly pDBFetchCopy(ring r, poly p,char *f,int l) |
---|
99 | #else |
---|
100 | poly _pFetchCopy(ring r, poly p) |
---|
101 | #endif |
---|
102 | { |
---|
103 | poly res; |
---|
104 | poly a; |
---|
105 | if (p==NULL) return NULL; |
---|
106 | #ifdef PDEBUG |
---|
107 | res = a = pDBNew(f,l); |
---|
108 | #else |
---|
109 | res = a = pNew(); |
---|
110 | #endif |
---|
111 | if (r->VarOffset == pVarOffset) |
---|
112 | { |
---|
113 | pCopy2(a,p); |
---|
114 | a->coef=nCopy(p->coef); |
---|
115 | pSetm(a); |
---|
116 | if (pNext(p)!=NULL) |
---|
117 | { |
---|
118 | pIter(p); |
---|
119 | do |
---|
120 | { |
---|
121 | #ifdef PDEBUG |
---|
122 | a = pNext(a) = pDBNew(f,l); |
---|
123 | #else |
---|
124 | a = pNext(a) = pNew(); |
---|
125 | #endif |
---|
126 | pCopy2(a,p); |
---|
127 | a->coef=nCopy(p->coef); |
---|
128 | pSetm(a); |
---|
129 | pIter(p); |
---|
130 | } |
---|
131 | while (p!=NULL); |
---|
132 | } |
---|
133 | pNext(a) = NULL; |
---|
134 | } |
---|
135 | else |
---|
136 | { |
---|
137 | #ifdef PDEBUG |
---|
138 | a = res = pDBInit(f,l); |
---|
139 | #else |
---|
140 | a = res = pInit(); |
---|
141 | #endif |
---|
142 | res->coef = nCopy(p->coef); |
---|
143 | RingCopy2ExpV(res, p, r); |
---|
144 | pSetm(res); |
---|
145 | if (pNext(p) != NULL) |
---|
146 | { |
---|
147 | pIter(p); |
---|
148 | do |
---|
149 | { |
---|
150 | // the VarOffset's are different: Hence we |
---|
151 | // convert betweeen a lex order and a revlex order -- to speed |
---|
152 | // up the sorting, we assemble new poly in inverse order |
---|
153 | #ifdef PDEBUG |
---|
154 | res = pDBInit(f,l); |
---|
155 | #else |
---|
156 | res = pInit(); |
---|
157 | #endif |
---|
158 | pNext(res) = a; |
---|
159 | a = res; |
---|
160 | res->coef = nCopy(p->coef); |
---|
161 | RingCopy2ExpV(res, p, r); |
---|
162 | pSetm(res); |
---|
163 | pIter(p); |
---|
164 | } |
---|
165 | while (p != NULL); |
---|
166 | } |
---|
167 | } |
---|
168 | #ifdef PDEBUG |
---|
169 | res = pOrdPolyMerge(res); |
---|
170 | pTest(res); |
---|
171 | return res; |
---|
172 | #else |
---|
173 | return pOrdPolyMerge(res); |
---|
174 | #endif |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | /*************************************************************** |
---|
179 | * |
---|
180 | * Storage Managament Routines |
---|
181 | * |
---|
182 | ***************************************************************/ |
---|
183 | |
---|
184 | #ifdef PDEBUG |
---|
185 | poly pDBNew(char *f, int l) |
---|
186 | { |
---|
187 | #ifdef MDEBUG |
---|
188 | poly p = (poly) mmDBAllocBlock(pMonomSize,f,l); |
---|
189 | #else |
---|
190 | poly p = (poly) mmAllocBlock(pMonomSize); |
---|
191 | #endif |
---|
192 | memset(p,0,pMonomSize); |
---|
193 | return p; |
---|
194 | } |
---|
195 | #endif |
---|
196 | |
---|
197 | /*2 |
---|
198 | * create a new monomial and init |
---|
199 | */ |
---|
200 | #ifdef PDEBUG |
---|
201 | poly pDBInit(char * f, int l) |
---|
202 | { |
---|
203 | poly p=pDBNew(f,l); |
---|
204 | memset(p,0, pMonomSize); |
---|
205 | nNew(&(p->coef)); |
---|
206 | return p; |
---|
207 | } |
---|
208 | #endif |
---|
209 | |
---|
210 | /*2 |
---|
211 | * delete a poly, resets pointer |
---|
212 | * put the monomials in the freelist |
---|
213 | */ |
---|
214 | #ifdef PDEBUG |
---|
215 | void pDBDelete(poly * p, char * f, int l) |
---|
216 | { |
---|
217 | poly h = *p; |
---|
218 | |
---|
219 | while (h!=NULL) |
---|
220 | { |
---|
221 | #ifdef LDEBUG |
---|
222 | nDBDelete(&(h->coef),f,l); |
---|
223 | #else |
---|
224 | nDelete(&(h->coef)); |
---|
225 | #endif |
---|
226 | pIter(h); |
---|
227 | #ifdef MDEBUG |
---|
228 | mmDBFreeBlock((ADDRESS)*p,pMonomSize,f,l); |
---|
229 | #else |
---|
230 | mmFreeBlock((ADDRESS)*p,pMonomSize); |
---|
231 | #endif |
---|
232 | *p=h; |
---|
233 | if (l>0) l= -l; |
---|
234 | } |
---|
235 | *p = NULL; |
---|
236 | } |
---|
237 | #else |
---|
238 | void _pDelete(poly* p) |
---|
239 | { |
---|
240 | poly h = *p; |
---|
241 | poly pp; |
---|
242 | |
---|
243 | while (h!=NULL) |
---|
244 | { |
---|
245 | nDelete(&(h->coef)); |
---|
246 | pp=h; |
---|
247 | pIter(h); |
---|
248 | mmFreeSpecialized((ADDRESS)pp); |
---|
249 | } |
---|
250 | *p = NULL; |
---|
251 | } |
---|
252 | #endif |
---|
253 | |
---|
254 | /*2 |
---|
255 | * remove first monom |
---|
256 | */ |
---|
257 | #ifdef PDEBUG |
---|
258 | void pDBDelete1(poly * p, char * f, int l) |
---|
259 | { |
---|
260 | poly h = *p; |
---|
261 | |
---|
262 | if (h==NULL) return; |
---|
263 | nDelete(&(h->coef)); |
---|
264 | *p = pNext(h); |
---|
265 | #ifdef MDEBUG |
---|
266 | mmDBFreeBlock((ADDRESS)h,pMonomSize,f,l); |
---|
267 | #else |
---|
268 | mmFreeBlock((ADDRESS)h,pMonomSize); |
---|
269 | #endif |
---|
270 | } |
---|
271 | #else |
---|
272 | void _pDelete1(poly* p) |
---|
273 | { |
---|
274 | poly h = *p; |
---|
275 | |
---|
276 | if (h==NULL) return; |
---|
277 | nDelete(&(h->coef)); |
---|
278 | *p = pNext(h); |
---|
279 | mmFreeSpecialized((ADDRESS)h); |
---|
280 | } |
---|
281 | #endif |
---|
282 | |
---|
283 | void ppDelete(poly* p, ring rg) |
---|
284 | { |
---|
285 | ring origRing = currRing; |
---|
286 | rChangeCurrRing(rg, FALSE); |
---|
287 | pDelete(p); |
---|
288 | rChangeCurrRing(origRing, FALSE); |
---|
289 | } |
---|
290 | |
---|
291 | /*2 |
---|
292 | * remove first monom |
---|
293 | */ |
---|
294 | #ifdef PDEBUG |
---|
295 | void pDBFree1(poly p, char * f, int l) |
---|
296 | { |
---|
297 | if (p!=NULL) |
---|
298 | { |
---|
299 | p->coef=NULL;//nDelete(&(p->coef)); |
---|
300 | #ifdef MDEBUG |
---|
301 | mmDBFreeBlock((ADDRESS)p,pMonomSize,f,l); |
---|
302 | #else |
---|
303 | mmFreeBlock((ADDRESS)p,pMonomSize); |
---|
304 | #endif |
---|
305 | } |
---|
306 | } |
---|
307 | #endif |
---|
308 | |
---|
309 | /*2 |
---|
310 | * creates a copy of p |
---|
311 | */ |
---|
312 | #ifdef PDEBUG |
---|
313 | poly pDBCopy(poly p,char *f,int l) |
---|
314 | #else |
---|
315 | poly _pCopy(poly p) |
---|
316 | #endif |
---|
317 | { |
---|
318 | poly w, a; |
---|
319 | |
---|
320 | if (p==NULL) return NULL; |
---|
321 | pDBTest(p,f,l); |
---|
322 | #ifdef PDEBUG |
---|
323 | w = a = pDBNew(f,l); |
---|
324 | #else |
---|
325 | w = a = pNew(); |
---|
326 | #endif |
---|
327 | memcpy(w,p,pMonomSize); |
---|
328 | w->coef=nCopy(p->coef); |
---|
329 | if (pNext(p)!=NULL) |
---|
330 | { |
---|
331 | pIter(p); |
---|
332 | do |
---|
333 | { |
---|
334 | #ifdef PDEBUG |
---|
335 | a = pNext(a) = pDBNew(f,l); |
---|
336 | #else |
---|
337 | a = pNext(a) = pNew(); |
---|
338 | #endif |
---|
339 | memcpy(a,p,pMonomSize); |
---|
340 | a->coef=nCopy(p->coef); |
---|
341 | pIter(p); |
---|
342 | } |
---|
343 | while (p!=NULL); |
---|
344 | } |
---|
345 | pNext(a) = NULL; |
---|
346 | return w; |
---|
347 | } |
---|
348 | |
---|
349 | |
---|
350 | /*2 |
---|
351 | * creates a copy of the initial monomial of p |
---|
352 | * sets the coeff of the copy to a defined value |
---|
353 | */ |
---|
354 | #ifdef PDEBUG |
---|
355 | poly pDBCopy1(poly p,char *f,int l) |
---|
356 | #else |
---|
357 | poly _pCopy1(poly p) |
---|
358 | #endif |
---|
359 | { |
---|
360 | poly w; |
---|
361 | #ifdef PDEBUG |
---|
362 | w = pDBNew(f,l); |
---|
363 | #else |
---|
364 | w = pNew(); |
---|
365 | #endif |
---|
366 | pCopy2(w,p); |
---|
367 | nNew(&(w->coef)); |
---|
368 | pNext(w) = NULL; |
---|
369 | return w; |
---|
370 | } |
---|
371 | |
---|
372 | /*2 |
---|
373 | * returns (a copy of) the head term of a |
---|
374 | */ |
---|
375 | #ifdef PDEBUG |
---|
376 | poly pDBHead(poly p,char *f, int l) |
---|
377 | #else |
---|
378 | poly _pHead(poly p) |
---|
379 | #endif |
---|
380 | { |
---|
381 | poly w=NULL; |
---|
382 | |
---|
383 | if (p!=NULL) |
---|
384 | { |
---|
385 | #ifdef PDEBUG |
---|
386 | w = pDBNew(f,l); |
---|
387 | #else |
---|
388 | w = pNew(); |
---|
389 | #endif |
---|
390 | pCopy2(w,p); |
---|
391 | pSetCoeff0(w,nCopy(pGetCoeff(p))); |
---|
392 | pNext(w) = NULL; |
---|
393 | } |
---|
394 | return w; |
---|
395 | } |
---|
396 | |
---|
397 | poly pHeadProc(poly p) |
---|
398 | { |
---|
399 | return pHead(p); |
---|
400 | } |
---|
401 | |
---|
402 | /*2 |
---|
403 | * returns (a copy of) the head term of a without the coef |
---|
404 | */ |
---|
405 | #ifdef PDEBUG |
---|
406 | poly pDBHead0(poly p,char *f, int l) |
---|
407 | #else |
---|
408 | poly _pHead0(poly p) |
---|
409 | #endif |
---|
410 | { |
---|
411 | poly w=NULL; |
---|
412 | |
---|
413 | if (p!=NULL) |
---|
414 | { |
---|
415 | #ifdef PDEBUG |
---|
416 | w = pDBNew(f,l); |
---|
417 | #else |
---|
418 | w = pNew(); |
---|
419 | #endif |
---|
420 | pCopy2(w,p); |
---|
421 | pSetCoeff0(w,NULL); |
---|
422 | pNext(w) = NULL; |
---|
423 | } |
---|
424 | return w; |
---|
425 | } |
---|
426 | |
---|
427 | |
---|
428 | /*************************************************************** |
---|
429 | * |
---|
430 | * Routines for turned on debugging |
---|
431 | * |
---|
432 | ***************************************************************/ |
---|
433 | |
---|
434 | #ifdef PDEBUG |
---|
435 | |
---|
436 | #if PDEBUG != 0 |
---|
437 | Exponent_t pPDSetExp(poly p, int v, Exponent_t e, char* f, int l) |
---|
438 | { |
---|
439 | if (v == 0) |
---|
440 | { |
---|
441 | Print("zero index to exponent in %s:%d\n", f, l); |
---|
442 | } |
---|
443 | if (v > pVariables) |
---|
444 | { |
---|
445 | Print("index %d to exponent too large in %s:%d\n", v, f, l); |
---|
446 | } |
---|
447 | return (p)->exp[_pExpIndex(v)]=(e); |
---|
448 | } |
---|
449 | |
---|
450 | Exponent_t pPDGetExp(poly p, int v, char* f, int l) |
---|
451 | { |
---|
452 | if (v == 0) |
---|
453 | { |
---|
454 | Print("zero index to exponent in %s:%d\n", f, l); |
---|
455 | } |
---|
456 | if (v > pVariables) |
---|
457 | { |
---|
458 | Print("index %d to exponent too large in %s:%d\n", v, f, l); |
---|
459 | } |
---|
460 | return (p)->exp[_pExpIndex(v)]; |
---|
461 | } |
---|
462 | |
---|
463 | Exponent_t pPDRingSetExp(ring r, poly p, int v, Exponent_t e, char* f, int l) |
---|
464 | { |
---|
465 | if (v == 0) |
---|
466 | { |
---|
467 | Print("zero index to exponent in %s:%d\n", f, l); |
---|
468 | } |
---|
469 | if (v > r->N) |
---|
470 | { |
---|
471 | Print("index %d to exponent too large in %s:%d\n", v, f, l); |
---|
472 | } |
---|
473 | return (p)->exp[_pRingExpIndex(r, v)]=(e); |
---|
474 | } |
---|
475 | |
---|
476 | Exponent_t pPDRingGetExp(ring r, poly p, int v, char* f, int l) |
---|
477 | { |
---|
478 | if (v == 0) |
---|
479 | { |
---|
480 | Print("zero index to exponent in %s:%d\n", f, l); |
---|
481 | } |
---|
482 | if (v > r->N) |
---|
483 | { |
---|
484 | Print("index %d to exponent too large in %s:%d\n", v, f, l); |
---|
485 | } |
---|
486 | return (p)->exp[_pRingExpIndex(r,v)]; |
---|
487 | } |
---|
488 | |
---|
489 | Exponent_t pPDIncrExp(poly p, int v, char* f, int l) |
---|
490 | { |
---|
491 | if (v == 0) |
---|
492 | { |
---|
493 | Print("zero index to exponent in %s:%d\n", f, l); |
---|
494 | } |
---|
495 | if (v > pVariables) |
---|
496 | { |
---|
497 | Print("index %d to exponent too large in %s:%d\n", v, f, l); |
---|
498 | } |
---|
499 | return ((p)->exp[_pExpIndex(v)])++; |
---|
500 | } |
---|
501 | |
---|
502 | Exponent_t pPDDecrExp(poly p, int v, char* f, int l) |
---|
503 | { |
---|
504 | if (v == 0) |
---|
505 | { |
---|
506 | Print("zero index to exponent in %s:%d\n", f, l); |
---|
507 | } |
---|
508 | if (v > pVariables) |
---|
509 | { |
---|
510 | Print("index %d to exponent too large in %s:%d\n", v, f, l); |
---|
511 | } |
---|
512 | return ((p)->exp[_pExpIndex(v)])--; |
---|
513 | } |
---|
514 | |
---|
515 | Exponent_t pPDAddExp(poly p, int v, Exponent_t e, char* f, int l) |
---|
516 | { |
---|
517 | if (v == 0) |
---|
518 | { |
---|
519 | Print("zero index to exponent in %s:%d\n", f, l); |
---|
520 | } |
---|
521 | if (v > pVariables) |
---|
522 | { |
---|
523 | Print("index %d to exponent too large in %s:%d\n", v, f, l); |
---|
524 | } |
---|
525 | return ((p)->exp[_pExpIndex(v)]) += (e); |
---|
526 | } |
---|
527 | |
---|
528 | Exponent_t pPDSubExp(poly p, int v, Exponent_t e, char* f, int l) |
---|
529 | { |
---|
530 | if (v == 0) |
---|
531 | { |
---|
532 | Print("zero index to exponent in %s:%d\n", f, l); |
---|
533 | } |
---|
534 | if (v > pVariables) |
---|
535 | { |
---|
536 | Print("index %d to exponent too large in %s:%d\n", v, f, l); |
---|
537 | } |
---|
538 | return ((p)->exp[_pExpIndex(v)]) -= (e); |
---|
539 | } |
---|
540 | |
---|
541 | Exponent_t pPDMultExp(poly p, int v, Exponent_t e, char* f, int l) |
---|
542 | { |
---|
543 | if (v == 0) |
---|
544 | { |
---|
545 | Print("zero index to exponent in %s:%d\n", f, l); |
---|
546 | } |
---|
547 | if (v > pVariables) |
---|
548 | { |
---|
549 | Print("index %d to exponent too large in %s:%d\n", v, f, l); |
---|
550 | } |
---|
551 | return ((p)->exp[_pExpIndex(v)]) *= (e); |
---|
552 | } |
---|
553 | |
---|
554 | // checks whether fast monom add did not overflow |
---|
555 | void pDBMonAddFast(poly p1, poly p2, char* f, int l) |
---|
556 | { |
---|
557 | poly ptemp = pNew(); |
---|
558 | pCopy2(ptemp, p1); |
---|
559 | |
---|
560 | __pMonAddFast(p1, p2); |
---|
561 | |
---|
562 | for (int i=1; i<=pVariables; i++) |
---|
563 | { |
---|
564 | pAddExp(ptemp, i, pGetExp(p2, i)); |
---|
565 | } |
---|
566 | pGetOrder(ptemp) += pGetOrder(p2); |
---|
567 | |
---|
568 | if (! pEqual(ptemp, p1)) |
---|
569 | { |
---|
570 | Print("Error in pMonAddFast in %s:%d\n", f, l); |
---|
571 | } |
---|
572 | |
---|
573 | pFree1(ptemp); |
---|
574 | } |
---|
575 | |
---|
576 | void pDBCopyAddFast(poly p1, poly p2, poly p3, char* f, int l) |
---|
577 | { |
---|
578 | if (p2 == p1 || p3 == p1) |
---|
579 | { |
---|
580 | Print("Error in pCopyAddFast: Destination equals source in %s:%d\n", f, l); |
---|
581 | } |
---|
582 | poly ptemp = pNew(); |
---|
583 | __pCopyAddFast(ptemp, p2, p3); |
---|
584 | |
---|
585 | pCopy2(p1, p2); |
---|
586 | pDBMonAddFast(p1, p3, f, l); |
---|
587 | |
---|
588 | if (! pEqual(ptemp, p1)) |
---|
589 | Print("Error in pCopyMonAddFast in %s:%d\n", f, l); |
---|
590 | pFree1(ptemp); |
---|
591 | } |
---|
592 | |
---|
593 | void pDBCopyAddFastHomog(poly p1, poly p2, poly p3, Order_t Order, |
---|
594 | char* f, int l) |
---|
595 | { |
---|
596 | pDBCopyAddFast(p1, p2, p3, f, l); |
---|
597 | if (p1->Order != Order) |
---|
598 | Print("Error in pCopyAddFastHomog: Order is different from sum\n"); |
---|
599 | } |
---|
600 | |
---|
601 | |
---|
602 | |
---|
603 | static BOOLEAN OldpDivisibleBy(poly a, poly b) |
---|
604 | { |
---|
605 | if ((a!=NULL)&&((pGetComp(a)==0) || (pGetComp(a) == pGetComp(b)))) |
---|
606 | { |
---|
607 | for (int i = 1; i<=pVariables; i++) |
---|
608 | if (pGetExp(a, i) > pGetExp(b,i)) return FALSE; |
---|
609 | return TRUE; |
---|
610 | } |
---|
611 | return FALSE; |
---|
612 | } |
---|
613 | |
---|
614 | |
---|
615 | BOOLEAN pDBDivisibleBy(poly a, poly b, char* f, int l) |
---|
616 | { |
---|
617 | BOOLEAN istrue = OldpDivisibleBy(a,b); |
---|
618 | BOOLEAN f_istrue = _pDivisibleBy_orig(a, b); |
---|
619 | |
---|
620 | if (istrue != f_istrue) |
---|
621 | { |
---|
622 | Print("Error in pDivisibleBy in %s:%d\n", f, l); |
---|
623 | _pDivisibleBy_orig(a, b); |
---|
624 | } |
---|
625 | return f_istrue; |
---|
626 | } |
---|
627 | |
---|
628 | BOOLEAN pDBDivisibleBy1(poly a, poly b, char* f, int l) |
---|
629 | { |
---|
630 | BOOLEAN istrue = OldpDivisibleBy(a,b); |
---|
631 | BOOLEAN f_istrue = _pDivisibleBy1_orig(a, b); |
---|
632 | |
---|
633 | if (istrue != f_istrue) |
---|
634 | { |
---|
635 | Print("Error in pDivisibleBy1 in %s:%d\n", f, l); |
---|
636 | _pDivisibleBy1_orig(a, b); |
---|
637 | } |
---|
638 | return f_istrue; |
---|
639 | } |
---|
640 | |
---|
641 | BOOLEAN pDBDivisibleBy2(poly a, poly b, char* f, int l) |
---|
642 | { |
---|
643 | BOOLEAN istrue = OldpDivisibleBy(a,b); |
---|
644 | BOOLEAN f_istrue = __pDivisibleBy(a, b); |
---|
645 | |
---|
646 | if (istrue != f_istrue) |
---|
647 | { |
---|
648 | Print("Error in pDivisibleBy2 in %s:%d\n", f, l); |
---|
649 | __pDivisibleBy(a, b); |
---|
650 | } |
---|
651 | return f_istrue; |
---|
652 | } |
---|
653 | |
---|
654 | #endif // PDEBUG != 0 |
---|
655 | |
---|
656 | |
---|
657 | BOOLEAN pDBTest(poly p, char *f, int l) |
---|
658 | { |
---|
659 | poly old=NULL; |
---|
660 | BOOLEAN ismod=FALSE; |
---|
661 | while (p!=NULL) |
---|
662 | { |
---|
663 | #ifdef MDEBUG |
---|
664 | if (!mmDBTestBlock(p,pMonomSize,f,l)) |
---|
665 | return FALSE; |
---|
666 | #endif |
---|
667 | #ifdef LDEBUG |
---|
668 | if (!nDBTest(p->coef,f,l)) |
---|
669 | return FALSE; |
---|
670 | #endif |
---|
671 | if ((p->coef==NULL)&&(nGetChar()<2)) |
---|
672 | { |
---|
673 | Print("NULL coef in poly in %s:%d\n",f,l); |
---|
674 | return FALSE; |
---|
675 | } |
---|
676 | if (nIsZero(p->coef)) |
---|
677 | { |
---|
678 | Print("zero coef in poly in %s:%d\n",f,l); |
---|
679 | return FALSE; |
---|
680 | } |
---|
681 | int i=pVariables; |
---|
682 | #ifndef DRING |
---|
683 | for(;i;i--) |
---|
684 | { |
---|
685 | if (pGetExp(p,i)<0) |
---|
686 | { |
---|
687 | Print("neg. Exponent in %s:%d\n",f,l); |
---|
688 | return FALSE; |
---|
689 | } |
---|
690 | } |
---|
691 | if (pGetComp(p)<0) |
---|
692 | { |
---|
693 | Print("neg Component in %s:%d\n",f,l); |
---|
694 | return FALSE; |
---|
695 | } |
---|
696 | #endif |
---|
697 | if (ismod==0) |
---|
698 | { |
---|
699 | if (pGetComp(p)>0) ismod=1; |
---|
700 | else ismod=2; |
---|
701 | } |
---|
702 | else if (ismod==1) |
---|
703 | { |
---|
704 | if (pGetComp(p)==0) |
---|
705 | { |
---|
706 | Print("mix vec./poly in %s:%d\n",f,l); |
---|
707 | return FALSE; |
---|
708 | } |
---|
709 | } |
---|
710 | else if (ismod==2) |
---|
711 | { |
---|
712 | if (pGetComp(p)!=0) |
---|
713 | { |
---|
714 | Print("mix poly/vec. in %s:%d\n",f,l); |
---|
715 | return FALSE; |
---|
716 | } |
---|
717 | } |
---|
718 | i=p->Order; |
---|
719 | pSetm(p); |
---|
720 | if(i!=p->Order) |
---|
721 | { |
---|
722 | Print("wrong ord-field in %s:%d\n",f,l); |
---|
723 | return FALSE; |
---|
724 | } |
---|
725 | old=p; |
---|
726 | pIter(p); |
---|
727 | if (pComp(old,p)!=1) |
---|
728 | { |
---|
729 | PrintS("wrong order ("); |
---|
730 | wrp(old); |
---|
731 | Print(") in %s:%d\n",f,l); |
---|
732 | return FALSE; |
---|
733 | } |
---|
734 | } |
---|
735 | return TRUE; |
---|
736 | } |
---|
737 | #endif // PDEBUG |
---|
738 | |
---|
739 | |
---|
740 | #endif // POLYS_IMPL_CC |
---|