My Project
Loading...
Searching...
No Matches
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#include "misc/distrib.h"
23
24
25#ifdef PDEBUG
26
27// do the following to always enforce checking of pSetm
28// #undef PDEBUG
29// #define PDEBUG 2
30
33
34#include "coeffs/coeffs.h"
35
36/***************************************************************
37 *
38 * Error reporting
39 *
40 ***************************************************************/
41// avoid recursive calls
43BOOLEAN dPolyReportError(poly p, ring r, const char* fmt, ...)
44{
45 if (d_poly_error_reporting) return FALSE;
47 va_list ap;
48 va_start(ap, fmt);
49
50 fprintf(stderr, "\n// ***dPolyReportError: ");
51 vfprintf(stderr, fmt, ap);
52 fprintf(stderr, "\n occurred at\n");
53 #ifdef HAVE_OMALLOC
55 #endif
56 if (p != NULL)
57 {
58 fprintf(stderr, " occurred for poly: ");
59 p_wrp(p, r);
60 omPrintAddrInfo(stderr, p, " ");
61 }
62 #ifndef MAKE_DISTRIBUTION
64 #endif
66 return FALSE;
67}
68
69/***************************************************************
70 *
71 * checking for ring stuff
72 *
73 ***************************************************************/
75{
76 if (p != NULL)
77 {
78 #if (OM_TRACK > 0) && defined(OM_TRACK_CUSTOM)
79 void* custom = omGetCustomOfAddr(p);
80 if (custom != NULL)
81 {
82 pPolyAssumeReturnMsg(custom == r ||
83 // be more sloppy for qrings
84 (r->qideal != NULL &&
86 omSizeWOfAddr(p)==omSizeWOfBin(r->PolyBin)) ||
87 rSamePolyRep((ring) custom, r),
88 "monomial not from specified ring",p,r);
89 return TRUE;
90 }
91 else
92 #endif
93 #ifndef X_OMALLOC
94 {
97 return TRUE;
98 }
99 return FALSE;
100 #endif
101 }
102 return TRUE;
103}
104
106{
107 while (p!=NULL)
108 {
110 pIter(p);
111 }
112 return TRUE;
113}
114
116{
117 #ifndef X_OMALLOC
118 pAssumeReturn(r != NULL && r->PolyBin != NULL);
119 #endif
120 return p_CheckIsFromRing(p, r);
121}
122
124{
125 #ifndef X_OMALLOC
126 pAssumeReturn(r != NULL && r->PolyBin != NULL);
127 #endif
128 pAssumeReturn(p != NULL);
129 return p_LmCheckIsFromRing(p, r);
130}
132{
133 #ifndef X_OMALLOC
134 pAssumeReturn(r != NULL && r->PolyBin != NULL);
135 #endif
136 return TRUE;
137}
138
139/***************************************************************
140 *
141 * Debugging/statistics of pDivisibleBy
142 *
143 ***************************************************************/
145{
146 int i=r->N;
147
148 do
149 {
150 if (p_GetExp(a,i,r) > p_GetExp(b,i,r))
151 return FALSE;
152 i--;
153 }
154 while (i);
155#ifdef HAVE_RINGS
156 return n_DivBy(pGetCoeff(b), pGetCoeff(a), r->cf);
157#else
158 return TRUE;
159#endif
160 }
161
162
163/***************************************************************
164 *
165 * Misc things helpful for debugging
166 *
167 ***************************************************************/
169{
170 if (m == NULL) return TRUE;
171 while (p != NULL)
172 {
173 if (p == m) return TRUE;
174 pIter(p);
175 }
176 return FALSE;
177}
179{
180 while (p != NULL)
181 {
182 if (pIsMonomOf(q, p))
183 {
184 return TRUE;
185 }
186 pIter(p);
187 }
188 return FALSE;
189}
190
191/***************************************************************
192 *
193 * Testing of polys
194 *
195 ***************************************************************/
196extern void p_Setm_General(poly p, ring r);
197
198static poly p_DebugInit(poly p, ring src_ring, ring dest_ring)
199{
200 poly d_p = p_Init(dest_ring);
201 int i;
202 assume(dest_ring->N == src_ring->N);
203
204 for (i=1; i<= src_ring->N; i++)
205 {
206 p_SetExp(d_p, i, p_GetExp(p, i, src_ring), dest_ring);
207 }
208 if (rRing_has_Comp(dest_ring))
209 p_SetComp(d_p, p_GetComp(p, src_ring), dest_ring);
210
211 p_Setm_General(d_p, dest_ring);
212 return d_p;
213}
214
215BOOLEAN _p_Test(poly p, ring r, int level)
216{
217 assume(r->cf !=NULL);
218
219 if (PDEBUG > level) level = PDEBUG;
220 if (level < 0 || p == NULL) return TRUE;
221
222 poly p_prev = NULL;
223
224 #ifndef OM_NDEBUG
225 #ifndef X_OMALLOC
226 // check addr with level+1 so as to check bin/page of addr
227 _pPolyAssumeReturnMsg(omTestBinAddrSize(p, (omSizeWOfBin(r->PolyBin))*SIZEOF_LONG, level+1)
228 == omError_NoError, "memory error",p,r);
229 #endif
230 #endif
231
233
234 // this checks that p does not contain a loop: rather expensive O(length^2)
235 #ifndef OM_NDEBUG
236 if (level > 1)
238 #endif
239
240 int ismod = p_GetComp(p, r) != 0;
241
242 while (p != NULL)
243 {
244 // ring check
246 #ifndef OM_NDEBUG
247 #ifndef X_OMALLOC
248 // omAddr check
249 _pPolyAssumeReturnMsg(omTestBinAddrSize(p, (omSizeWOfBin(r->PolyBin))*SIZEOF_LONG, 1)
250 == omError_NoError, "memory error",p,r);
251 #endif
252 #endif
253 // number/coef check
254 _pPolyAssumeReturnMsg(p->coef != NULL || (n_GetChar(r->cf) >= 2), "NULL coef",p,r);
255
256 #ifdef LDEBUG
257 _pPolyAssumeReturnMsg(n_Test(p->coef,r->cf),"coeff err",p,r);
258 #endif
259 _pPolyAssumeReturnMsg(!n_IsZero(p->coef, r->cf), "Zero coef",p,r);
260
261 // check for valid comp
262 _pPolyAssumeReturnMsg(p_GetComp(p, r) >= 0 && (p_GetComp(p, r)<65000), "component out of range ?",p,r);
263 // check for mix poly/vec representation
264 _pPolyAssumeReturnMsg(ismod == (p_GetComp(p, r) != 0), "mixed poly/vector",p,r);
265
266 // special check for ringorder_s/S
267 if ((r->typ!=NULL) && (r->typ[0].ord_typ == ro_syzcomp))
268 {
269 long c1, cc1, ccc1, ec1;
270 sro_ord* o = &(r->typ[0]);
271
272 c1 = p_GetComp(p, r);
273 if (o->data.syzcomp.Components!=NULL)
274 {
275 cc1 = o->data.syzcomp.Components[c1];
276 ccc1 = o->data.syzcomp.ShiftedComponents[cc1];
277 }
278 else { cc1=0; ccc1=0; }
279 _pPolyAssumeReturnMsg(c1 == 0 || cc1 != 0, "Component <-> TrueComponent zero mismatch",p,r);
280 _pPolyAssumeReturnMsg(c1 == 0 || ccc1 != 0,"Component <-> ShiftedComponent zero mismatch",p,r);
281 ec1 = p->exp[o->data.syzcomp.place];
282 //pPolyAssumeReturnMsg(ec1 == ccc1, "Shifted comp out of sync. should %d, is %d");
283 if (ec1 != ccc1)
284 {
285 dPolyReportError(p,r,"Shifted comp out of sync. should %d, is %d",ccc1,ec1);
286 return FALSE;
287 }
288 }
289
290 // check that p_Setm works ok
291 if (level > 0)
292 {
293 poly p_should_equal = p_DebugInit(p, r, r);
294 _pPolyAssumeReturnMsg(p_ExpVectorEqual(p, p_should_equal, r), "p_Setm field(s) out of sync",p,r);
295 p_LmFree(p_should_equal, r);
296 }
297
298 // check order
299 if (p_prev != NULL)
300 {
301 int cmp = p_LmCmp(p_prev, p, r);
302 if (cmp == 0)
303 {
304 _pPolyAssumeReturnMsg(0, "monoms p and p->next are equal", p_prev, r);
305 }
306 else
307 _pPolyAssumeReturnMsg(p_LmCmp(p_prev, p, r) == 1, "wrong order", p_prev, r);
308
309 // check that compare worked sensibly
310 if (level > 1 && p_GetComp(p_prev, r) == p_GetComp(p, r))
311 {
312 int i;
313 for (i=r->N; i>0; i--)
314 {
315 if (p_GetExp(p_prev, i, r) != p_GetExp(p, i, r)) break;
316 }
317 _pPolyAssumeReturnMsg(i > 0, "Exponents equal but compare different", p_prev, r);
318 }
319 }
320 p_prev = p;
321 pIter(p);
322 }
323 return TRUE;
324}
325
326BOOLEAN _p_LmTest(poly p, ring r, int level)
327{
328 if (level < 0 || p == NULL) return TRUE;
329 poly pnext = pNext(p);
330 pNext(p) = NULL;
331 BOOLEAN test_res = _p_Test(p, r, level);
332 pNext(p) = pnext;
333 return test_res;
334}
335
336BOOLEAN _pp_Test(poly p, ring lmRing, ring tailRing, int level)
337{
338 if (PDEBUG > level) level = PDEBUG;
339 if (level < 0 || p == NULL) return TRUE;
340 if (pNext(p) == NULL || lmRing == tailRing) return _p_Test(p, lmRing, level);
341
342 pFalseReturn(_p_LmTest(p, lmRing, level));
343 pFalseReturn(_p_Test(pNext(p), tailRing, level));
344
345 // check that lm > Lm(tail)
346 if (level > 1)
347 {
348 poly lm = p;
349 poly tail = p_DebugInit(pNext(p), tailRing, lmRing);
350 poly pnext = pNext(lm);
351 pNext(lm) = tail;
352 BOOLEAN cmp = p_LmCmp(lm, tail, lmRing);
353 if (cmp != 1)
354 dPolyReportError(lm, lmRing, "wrong order: lm <= Lm(tail)");
355 p_LmFree(tail, lmRing);
356 pNext(lm) = pnext;
357 return (cmp == 1);
358 }
359 return TRUE;
360}
361
362#endif // PDEBUG
363
364#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)
#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:198
BOOLEAN pIsMonomOf(poly p, poly m)
Definition: pDebug.cc:168
BOOLEAN p_LmCheckPolyRing(poly p, ring r)
Definition: pDebug.cc:123
BOOLEAN _p_Test(poly p, ring r, int level)
Definition: pDebug.cc:215
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:105
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:144
STATIC_VAR BOOLEAN d_poly_error_reporting
Definition: pDebug.cc:42
BOOLEAN _p_LmTest(poly p, ring r, int level)
Definition: pDebug.cc:326
BOOLEAN dPolyReportError(poly p, ring r, const char *fmt,...)
Definition: pDebug.cc:43
BOOLEAN p_CheckRing(ring r)
Definition: pDebug.cc:131
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition: pDebug.cc:74
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition: pDebug.cc:115
BOOLEAN pHaveCommonMonoms(poly p, poly q)
Definition: pDebug.cc:178
BOOLEAN _pp_Test(poly p, ring lmRing, ring tailRing, int level)
Definition: pDebug.cc:336
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition: p_polys.cc:4526
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