My Project
pDebug.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4/***************************************************************
5 * File: pDebug.h
6 * Purpose: implementation of debug related poly routines
7 * Author: obachman (Olaf Bachmann)
8 * Created: 8/00
9 *******************************************************************/
10
11#ifndef PDEBUG_CC
12#define PDEBUG_CC
13
14#include <stdarg.h>
15#include <stdio.h>
16
17
18
19
20
21#include "misc/auxiliary.h"
22
23
24#ifdef PDEBUG
25
26// do the following to always enforce checking of pSetm
27// #undef PDEBUG
28// #define PDEBUG 2
29
32
33#include "coeffs/coeffs.h"
34
35/***************************************************************
36 *
37 * Error reporting
38 *
39 ***************************************************************/
40// avoid recursive calls
42BOOLEAN dPolyReportError(poly p, ring r, const char* fmt, ...)
43{
44 if (d_poly_error_reporting) return FALSE;
46 va_list ap;
47 va_start(ap, fmt);
48
49 fprintf(stderr, "\n// ***dPolyReportError: ");
50 vfprintf(stderr, fmt, ap);
51 fprintf(stderr, "\n occurred at\n");
52 #ifdef HAVE_OMALLOC
54 #endif
55 if (p != NULL)
56 {
57 fprintf(stderr, " occurred for poly: ");
58 p_wrp(p, r);
59 omPrintAddrInfo(stderr, p, " ");
60 }
63 return FALSE;
64}
65
66/***************************************************************
67 *
68 * checking for ring stuff
69 *
70 ***************************************************************/
72{
73 if (p != NULL)
74 {
75 #if (OM_TRACK > 0) && defined(OM_TRACK_CUSTOM)
76 void* custom = omGetCustomOfAddr(p);
77 if (custom != NULL)
78 {
79 pPolyAssumeReturnMsg(custom == r ||
80 // be more sloppy for qrings
81 (r->qideal != NULL &&
83 omSizeWOfAddr(p)==omSizeWOfBin(r->PolyBin)) ||
84 rSamePolyRep((ring) custom, r),
85 "monomial not from specified ring",p,r);
86 return TRUE;
87 }
88 else
89 #endif
90 #ifndef X_OMALLOC
91 {
94 return TRUE;
95 }
96 return FALSE;
97 #endif
98 }
99 return TRUE;
100}
101
103{
104 while (p!=NULL)
105 {
107 pIter(p);
108 }
109 return TRUE;
110}
111
113{
114 #ifndef X_OMALLOC
115 pAssumeReturn(r != NULL && r->PolyBin != NULL);
116 #endif
117 return p_CheckIsFromRing(p, r);
118}
119
121{
122 #ifndef X_OMALLOC
123 pAssumeReturn(r != NULL && r->PolyBin != NULL);
124 #endif
125 pAssumeReturn(p != NULL);
126 return p_LmCheckIsFromRing(p, r);
127}
129{
130 #ifndef X_OMALLOC
131 pAssumeReturn(r != NULL && r->PolyBin != NULL);
132 #endif
133 return TRUE;
134}
135
136/***************************************************************
137 *
138 * Debugging/statistics of pDivisibleBy
139 *
140 ***************************************************************/
142{
143 int i=r->N;
144
145 do
146 {
147 if (p_GetExp(a,i,r) > p_GetExp(b,i,r))
148 return FALSE;
149 i--;
150 }
151 while (i);
152#ifdef HAVE_RINGS
153 return n_DivBy(pGetCoeff(b), pGetCoeff(a), r->cf);
154#else
155 return TRUE;
156#endif
157 }
158
159
160/***************************************************************
161 *
162 * Misc things helpful for debugging
163 *
164 ***************************************************************/
166{
167 if (m == NULL) return TRUE;
168 while (p != NULL)
169 {
170 if (p == m) return TRUE;
171 pIter(p);
172 }
173 return FALSE;
174}
176{
177 while (p != NULL)
178 {
179 if (pIsMonomOf(q, p))
180 {
181 return TRUE;
182 }
183 pIter(p);
184 }
185 return FALSE;
186}
187
188/***************************************************************
189 *
190 * Testing of polys
191 *
192 ***************************************************************/
193extern void p_Setm_General(poly p, ring r);
194
195static poly p_DebugInit(poly p, ring src_ring, ring dest_ring)
196{
197 poly d_p = p_Init(dest_ring);
198 int i;
199 assume(dest_ring->N == src_ring->N);
200
201 for (i=1; i<= src_ring->N; i++)
202 {
203 p_SetExp(d_p, i, p_GetExp(p, i, src_ring), dest_ring);
204 }
205 if (rRing_has_Comp(dest_ring))
206 p_SetComp(d_p, p_GetComp(p, src_ring), dest_ring);
207
208 p_Setm_General(d_p, dest_ring);
209 return d_p;
210}
211
212BOOLEAN _p_Test(poly p, ring r, int level)
213{
214 assume(r->cf !=NULL);
215
216 if (PDEBUG > level) level = PDEBUG;
217 if (level < 0 || p == NULL) return TRUE;
218
219 poly p_prev = NULL;
220
221 #ifndef OM_NDEBUG
222 #ifndef X_OMALLOC
223 // check addr with level+1 so as to check bin/page of addr
224 _pPolyAssumeReturnMsg(omTestBinAddrSize(p, (omSizeWOfBin(r->PolyBin))*SIZEOF_LONG, level+1)
225 == omError_NoError, "memory error",p,r);
226 #endif
227 #endif
228
230
231 // this checks that p does not contain a loop: rather expensive O(length^2)
232 #ifndef OM_NDEBUG
233 if (level > 1)
235 #endif
236
237 int ismod = p_GetComp(p, r) != 0;
238
239 while (p != NULL)
240 {
241 // ring check
243 #ifndef OM_NDEBUG
244 #ifndef X_OMALLOC
245 // omAddr check
246 _pPolyAssumeReturnMsg(omTestBinAddrSize(p, (omSizeWOfBin(r->PolyBin))*SIZEOF_LONG, 1)
247 == omError_NoError, "memory error",p,r);
248 #endif
249 #endif
250 // number/coef check
251 _pPolyAssumeReturnMsg(p->coef != NULL || (n_GetChar(r->cf) >= 2), "NULL coef",p,r);
252
253 #ifdef LDEBUG
254 _pPolyAssumeReturnMsg(n_Test(p->coef,r->cf),"coeff err",p,r);
255 #endif
256 _pPolyAssumeReturnMsg(!n_IsZero(p->coef, r->cf), "Zero coef",p,r);
257
258 // check for valid comp
259 _pPolyAssumeReturnMsg(p_GetComp(p, r) >= 0 && (p_GetComp(p, r)<65000), "component out of range ?",p,r);
260 // check for mix poly/vec representation
261 _pPolyAssumeReturnMsg(ismod == (p_GetComp(p, r) != 0), "mixed poly/vector",p,r);
262
263 // special check for ringorder_s/S
264 if ((r->typ!=NULL) && (r->typ[0].ord_typ == ro_syzcomp))
265 {
266 long c1, cc1, ccc1, ec1;
267 sro_ord* o = &(r->typ[0]);
268
269 c1 = p_GetComp(p, r);
270 if (o->data.syzcomp.Components!=NULL)
271 {
272 cc1 = o->data.syzcomp.Components[c1];
273 ccc1 = o->data.syzcomp.ShiftedComponents[cc1];
274 }
275 else { cc1=0; ccc1=0; }
276 _pPolyAssumeReturnMsg(c1 == 0 || cc1 != 0, "Component <-> TrueComponent zero mismatch",p,r);
277 _pPolyAssumeReturnMsg(c1 == 0 || ccc1 != 0,"Component <-> ShiftedComponent zero mismatch",p,r);
278 ec1 = p->exp[o->data.syzcomp.place];
279 //pPolyAssumeReturnMsg(ec1 == ccc1, "Shifted comp out of sync. should %d, is %d");
280 if (ec1 != ccc1)
281 {
282 dPolyReportError(p,r,"Shifted comp out of sync. should %d, is %d",ccc1,ec1);
283 return FALSE;
284 }
285 }
286
287 // check that p_Setm works ok
288 if (level > 0)
289 {
290 poly p_should_equal = p_DebugInit(p, r, r);
291 _pPolyAssumeReturnMsg(p_ExpVectorEqual(p, p_should_equal, r), "p_Setm field(s) out of sync",p,r);
292 p_LmFree(p_should_equal, r);
293 }
294
295 // check order
296 if (p_prev != NULL)
297 {
298 int cmp = p_LmCmp(p_prev, p, r);
299 if (cmp == 0)
300 {
301 _pPolyAssumeReturnMsg(0, "monoms p and p->next are equal", p_prev, r);
302 }
303 else
304 _pPolyAssumeReturnMsg(p_LmCmp(p_prev, p, r) == 1, "wrong order", p_prev, r);
305
306 // check that compare worked sensibly
307 if (level > 1 && p_GetComp(p_prev, r) == p_GetComp(p, r))
308 {
309 int i;
310 for (i=r->N; i>0; i--)
311 {
312 if (p_GetExp(p_prev, i, r) != p_GetExp(p, i, r)) break;
313 }
314 _pPolyAssumeReturnMsg(i > 0, "Exponents equal but compare different", p_prev, r);
315 }
316 }
317 p_prev = p;
318 pIter(p);
319 }
320 return TRUE;
321}
322
323BOOLEAN _p_LmTest(poly p, ring r, int level)
324{
325 if (level < 0 || p == NULL) return TRUE;
326 poly pnext = pNext(p);
327 pNext(p) = NULL;
328 BOOLEAN test_res = _p_Test(p, r, level);
329 pNext(p) = pnext;
330 return test_res;
331}
332
333BOOLEAN _pp_Test(poly p, ring lmRing, ring tailRing, int level)
334{
335 if (PDEBUG > level) level = PDEBUG;
336 if (level < 0 || p == NULL) return TRUE;
337 if (pNext(p) == NULL || lmRing == tailRing) return _p_Test(p, lmRing, level);
338
339 pFalseReturn(_p_LmTest(p, lmRing, level));
340 pFalseReturn(_p_Test(pNext(p), tailRing, level));
341
342 // check that lm > Lm(tail)
343 if (level > 1)
344 {
345 poly lm = p;
346 poly tail = p_DebugInit(pNext(p), tailRing, lmRing);
347 poly pnext = pNext(lm);
348 pNext(lm) = tail;
349 BOOLEAN cmp = p_LmCmp(lm, tail, lmRing);
350 if (cmp != 1)
351 dPolyReportError(lm, lmRing, "wrong order: lm <= Lm(tail)");
352 p_LmFree(tail, lmRing);
353 pNext(lm) = pnext;
354 return (cmp == 1);
355 }
356 return TRUE;
357}
358
359#endif // PDEBUG
360
361#endif // PDEBUG_CC
All the auxiliary stuff.
int BOOLEAN
Definition: auxiliary.h:87
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
#define PDEBUG
Definition: auxiliary.h:170
int level(const CanonicalForm &f)
int m
Definition: cfEzgcd.cc:128
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4078
CanonicalForm b
Definition: cfModGcd.cc:4103
Coefficient rings, fields and other domains suitable for Singular polynomials.
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:709
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition: coeffs.h:461
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:441
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:750
#define STATIC_VAR
Definition: globaldefs.h:7
void dErrorBreak(void)
Definition: dError.cc:140
#define assume(x)
Definition: mod2.h:389
#define pPolyAssumeReturnMsg(cond, msg)
Definition: monomials.h:137
#define p_GetComp(p, r)
Definition: monomials.h:64
#define pFalseReturn(cond)
Definition: monomials.h:139
#define pIter(p)
Definition: monomials.h:37
#define pNext(p)
Definition: monomials.h:36
#define pAssumeReturn(cond)
Definition: monomials.h:78
#define _pPolyAssumeReturnMsg(cond, msg, p, r)
Definition: monomials.h:124
#define _pPolyAssumeReturn(cond, p, r)
Definition: monomials.h:101
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
#define rRing_has_Comp(r)
Definition: monomials.h:266
Definition: ap.h:40
#define omSizeWOfBin(bin_ptr)
#define omIsBinPageAddr(addr)
Definition: omBinPage.h:68
@ omError_NoError
Definition: omError.h:18
#define NULL
Definition: omList.c:12
#define omTestList(ptr, level)
Definition: omList.h:81
static poly p_DebugInit(poly p, ring src_ring, ring dest_ring)
Definition: pDebug.cc:195
BOOLEAN pIsMonomOf(poly p, poly m)
Definition: pDebug.cc:165
BOOLEAN p_LmCheckPolyRing(poly p, ring r)
Definition: pDebug.cc:120
BOOLEAN _p_Test(poly p, ring r, int level)
Definition: pDebug.cc:212
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:102
void p_Setm_General(poly p, ring r)
Definition: p_polys.cc:158
BOOLEAN p_DebugLmDivisibleByNoComp(poly a, poly b, ring r)
Definition: pDebug.cc:141
STATIC_VAR BOOLEAN d_poly_error_reporting
Definition: pDebug.cc:41
BOOLEAN _p_LmTest(poly p, ring r, int level)
Definition: pDebug.cc:323
BOOLEAN dPolyReportError(poly p, ring r, const char *fmt,...)
Definition: pDebug.cc:42
BOOLEAN p_CheckRing(ring r)
Definition: pDebug.cc:128
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:71
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition: pDebug.cc:112
BOOLEAN pHaveCommonMonoms(poly p, poly q)
Definition: pDebug.cc:175
BOOLEAN _pp_Test(poly p, ring lmRing, ring tailRing, int level)
Definition: pDebug.cc:333
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition: p_polys.cc:4522
static unsigned long p_SetExp(poly p, const unsigned long e, const unsigned long iBitmask, const int VarOffset)
set a single variable exponent @Note: VarOffset encodes the position in p->exp
Definition: p_polys.h:486
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition: p_polys.h:245
static int p_LmCmp(poly p, poly q, const ring r)
Definition: p_polys.h:1578
static long p_GetExp(const poly p, const unsigned long iBitmask, const int VarOffset)
get a single variable exponent @Note: the integer VarOffset encodes:
Definition: p_polys.h:467
static void p_LmFree(poly p, ring)
Definition: p_polys.h:681
static poly p_Init(const ring r, omBin bin)
Definition: p_polys.h:1318
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition: polys0.cc:373
BOOLEAN rSamePolyRep(ring r1, ring r2)
returns TRUE, if r1 and r2 represents the monomials in the same way FALSE, otherwise this is an analo...
Definition: ring.cc:1799
@ ro_syzcomp
Definition: ring.h:59
union sro_ord::@1 data
Definition: ring.h:219
#define omTestBinAddrSize(A, B, C)
Definition: xalloc.h:272
#define omPrintAddrInfo(A, B, C)
Definition: xalloc.h:270
#define omPrintCurrentBackTraceMax(A, B)
Definition: xalloc.h:265
#define omSizeWOfAddr(P)
Definition: xalloc.h:223