Loading...
Searching...
No Matches
pDebug.cc
Go to the documentation of this file.
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/***************************************************************
* File: pDebug.h
* Purpose: implementation of debug related poly routines
* Author: obachman (Olaf Bachmann)
* Created: 8/00
*******************************************************************/
#ifndef PDEBUG_CC
#define PDEBUG_CC
#include <stdarg.h>
#include <stdio.h>
#include "misc/auxiliary.h"
#include "misc/distrib.h"
#ifdef PDEBUG
// do the following to always enforce checking of pSetm
// #undef PDEBUG
// #define PDEBUG 2
#include "polys/monomials/ring.h"
#include "polys/monomials/p_polys.h"
#include "coeffs/coeffs.h"
/***************************************************************
*
* Error reporting
*
***************************************************************/
// avoid recursive calls
STATIC_VAR BOOLEAN d_poly_error_reporting = FALSE;
BOOLEAN dPolyReportError(poly p, ring r, const char* fmt, ...)
{
if (d_poly_error_reporting) return FALSE;
d_poly_error_reporting = TRUE;
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "\n// ***dPolyReportError: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n occurred at\n");
#ifdef HAVE_OMALLOC
omPrintCurrentBackTraceMax(stderr, 8);
#endif
if (p != NULL)
{
fprintf(stderr, " occurred for poly: ");
p_wrp(p, r);
omPrintAddrInfo(stderr, p, " ");
}
#ifndef MAKE_DISTRIBUTION
dErrorBreak();
#endif
d_poly_error_reporting = FALSE;
return FALSE;
}
/***************************************************************
*
* checking for ring stuff
*
***************************************************************/
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
{
if (p != NULL)
{
#if (OM_TRACK > 0) && defined(OM_TRACK_CUSTOM)
void* custom = omGetCustomOfAddr(p);
if (custom != NULL)
{
pPolyAssumeReturnMsg(custom == r ||
// be more sloppy for qrings
(r->qideal != NULL &&
omIsBinPageAddr(p) &&
omSizeWOfAddr(p)==omSizeWOfBin(r->PolyBin)) ||
rSamePolyRep((ring) custom, r),
"monomial not from specified ring",p,r);
return TRUE;
}
else
#endif
#ifndef X_OMALLOC
{
_pPolyAssumeReturn(omIsBinPageAddr(p),p,r);
_pPolyAssumeReturn(omSizeWOfAddr(p)==omSizeWOfBin(r->PolyBin),p,r);
return TRUE;
}
return FALSE;
#endif
}
return TRUE;
}
BOOLEAN p_CheckIsFromRing(poly p, ring r)
{
while (p!=NULL)
{
pFalseReturn(p_LmCheckIsFromRing(p, r));
pIter(p);
}
return TRUE;
}
BOOLEAN p_CheckPolyRing(poly p, ring r)
{
#ifndef X_OMALLOC
pAssumeReturn(r != NULL && r->PolyBin != NULL);
#endif
return p_CheckIsFromRing(p, r);
}
BOOLEAN p_LmCheckPolyRing(poly p, ring r)
{
#ifndef X_OMALLOC
pAssumeReturn(r != NULL && r->PolyBin != NULL);
#endif
pAssumeReturn(p != NULL);
return p_LmCheckIsFromRing(p, r);
}
BOOLEAN p_CheckRing(ring r)
{
#ifndef X_OMALLOC
pAssumeReturn(r != NULL && r->PolyBin != NULL);
#endif
return TRUE;
}
/***************************************************************
*
* Debugging/statistics of pDivisibleBy
*
***************************************************************/
BOOLEAN p_DebugLmDivisibleByNoComp(poly a, poly b, ring r)
{
int i=r->N;
do
{
if (p_GetExp(a,i,r) > p_GetExp(b,i,r))
return FALSE;
i--;
}
while (i);
return n_DivBy(pGetCoeff(b), pGetCoeff(a), r->cf);
}
/***************************************************************
*
* Misc things helpful for debugging
*
***************************************************************/
BOOLEAN pIsMonomOf(poly p, poly m)
{
if (m == NULL) return TRUE;
while (p != NULL)
{
if (p == m) return TRUE;
pIter(p);
}
return FALSE;
}
BOOLEAN pHaveCommonMonoms(poly p, poly q)
{
while (p != NULL)
{
if (pIsMonomOf(q, p))
{
return TRUE;
}
pIter(p);
}
return FALSE;
}
/***************************************************************
*
* Testing of polys
*
***************************************************************/
extern void p_Setm_General(poly p, ring r);
static poly p_DebugInit(poly p, ring src_ring, ring dest_ring)
{
poly d_p = p_Init(dest_ring);
int i;
assume(dest_ring->N == src_ring->N);
for (i=1; i<= src_ring->N; i++)
{
p_SetExp(d_p, i, p_GetExp(p, i, src_ring), dest_ring);
}
if (rRing_has_Comp(dest_ring))
p_SetComp(d_p, p_GetComp(p, src_ring), dest_ring);
p_Setm_General(d_p, dest_ring);
return d_p;
}
BOOLEAN _p_Test(poly p, ring r, int level)
{
assume(r->cf !=NULL);
if (PDEBUG > level) level = PDEBUG;
if (level < 0 || p == NULL) return TRUE;
poly p_prev = NULL;
#ifndef OM_NDEBUG
#ifndef X_OMALLOC
// check addr with level+1 so as to check bin/page of addr
_pPolyAssumeReturnMsg(omTestBinAddrSize(p, (omSizeWOfBin(r->PolyBin))*SIZEOF_LONG, level+1)
== omError_NoError, "memory error",p,r);
#endif
#endif
pFalseReturn(p_CheckRing(r));
// this checks that p does not contain a loop: rather expensive O(length^2)
#ifndef OM_NDEBUG
if (level > 1)
pFalseReturn(omTestList(p, level) == omError_NoError);
#endif
int ismod = p_GetComp(p, r) != 0;
while (p != NULL)
{
// ring check
pFalseReturn(p_LmCheckIsFromRing(p, r));
#ifndef OM_NDEBUG
#ifndef X_OMALLOC
// omAddr check
_pPolyAssumeReturnMsg(omTestBinAddrSize(p, (omSizeWOfBin(r->PolyBin))*SIZEOF_LONG, 1)
== omError_NoError, "memory error",p,r);
#endif
#endif
// number/coef check
_pPolyAssumeReturnMsg(p->coef != NULL || (n_GetChar(r->cf) >= 2), "NULL coef",p,r);
#ifdef LDEBUG
_pPolyAssumeReturnMsg(n_Test(p->coef,r->cf),"coeff err",p,r);
#endif
_pPolyAssumeReturnMsg(!n_IsZero(p->coef, r->cf), "Zero coef",p,r);
// check for valid comp
_pPolyAssumeReturnMsg(p_GetComp(p, r) >= 0 && (p_GetComp(p, r)<65000), "component out of range ?",p,r);
// check for mix poly/vec representation
_pPolyAssumeReturnMsg(ismod == (p_GetComp(p, r) != 0), "mixed poly/vector",p,r);
// special check for ringorder_s/S
if ((r->typ!=NULL) && (r->typ[0].ord_typ == ro_syzcomp))
{
long c1, cc1, ccc1, ec1;
sro_ord* o = &(r->typ[0]);
c1 = p_GetComp(p, r);
if (o->data.syzcomp.Components!=NULL)
{
cc1 = o->data.syzcomp.Components[c1];
ccc1 = o->data.syzcomp.ShiftedComponents[cc1];
}
else { cc1=0; ccc1=0; }
_pPolyAssumeReturnMsg(c1 == 0 || cc1 != 0, "Component <-> TrueComponent zero mismatch",p,r);
_pPolyAssumeReturnMsg(c1 == 0 || ccc1 != 0,"Component <-> ShiftedComponent zero mismatch",p,r);
ec1 = p->exp[o->data.syzcomp.place];
//pPolyAssumeReturnMsg(ec1 == ccc1, "Shifted comp out of sync. should %d, is %d");
if (ec1 != ccc1)
{
dPolyReportError(p,r,"Shifted comp out of sync. should %d, is %d",ccc1,ec1);
return FALSE;
}
}
// check that p_Setm works ok
if (level > 0)
{
poly p_should_equal = p_DebugInit(p, r, r);
_pPolyAssumeReturnMsg(p_ExpVectorEqual(p, p_should_equal, r), "p_Setm field(s) out of sync",p,r);
p_LmFree(p_should_equal, r);
}
// check order
if (p_prev != NULL)
{
int cmp = p_LmCmp(p_prev, p, r);
if (cmp == 0)
{
_pPolyAssumeReturnMsg(0, "monoms p and p->next are equal", p_prev, r);
}
else
_pPolyAssumeReturnMsg(p_LmCmp(p_prev, p, r) == 1, "wrong order", p_prev, r);
// check that compare worked sensibly
if (level > 1 && p_GetComp(p_prev, r) == p_GetComp(p, r))
{
int i;
for (i=r->N; i>0; i--)
{
if (p_GetExp(p_prev, i, r) != p_GetExp(p, i, r)) break;
}
_pPolyAssumeReturnMsg(i > 0, "Exponents equal but compare different", p_prev, r);
}
}
p_prev = p;
pIter(p);
}
return TRUE;
}
BOOLEAN _p_LmTest(poly p, ring r, int level)
{
if (level < 0 || p == NULL) return TRUE;
poly pnext = pNext(p);
pNext(p) = NULL;
BOOLEAN test_res = _p_Test(p, r, level);
pNext(p) = pnext;
return test_res;
}
BOOLEAN _pp_Test(poly p, ring lmRing, ring tailRing, int level)
{
if (PDEBUG > level) level = PDEBUG;
if (level < 0 || p == NULL) return TRUE;
if (pNext(p) == NULL || lmRing == tailRing) return _p_Test(p, lmRing, level);
pFalseReturn(_p_LmTest(p, lmRing, level));
pFalseReturn(_p_Test(pNext(p), tailRing, level));
// check that lm > Lm(tail)
if (level > 1)
{
poly lm = p;
poly tail = p_DebugInit(pNext(p), tailRing, lmRing);
poly pnext = pNext(lm);
pNext(lm) = tail;
BOOLEAN cmp = p_LmCmp(lm, tail, lmRing);
if (cmp != 1)
dPolyReportError(lm, lmRing, "wrong order: lm <= Lm(tail)");
p_LmFree(tail, lmRing);
pNext(lm) = pnext;
return (cmp == 1);
}
return TRUE;
}
#endif // PDEBUG
#endif // PDEBUG_CC
auxiliary.h
All the auxiliary stuff.
BOOLEAN
int BOOLEAN
Definition auxiliary.h:88
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
PDEBUG
#define PDEBUG
Definition auxiliary.h:171
level
int level(const CanonicalForm &f)
Definition canonicalform.h:331
m
int m
Definition cfEzgcd.cc:128
i
int i
Definition cfEzgcd.cc:132
p
int p
Definition cfModGcd.cc:4086
b
CanonicalForm b
Definition cfModGcd.cc:4111
coeffs.h
Coefficient rings, fields and other domains suitable for Singular polynomials.
n_Test
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r).
Definition coeffs.h:715
n_IsZero
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
Definition coeffs.h:470
n_GetChar
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition coeffs.h:450
n_DivBy
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
distrib.h
STATIC_VAR
#define STATIC_VAR
Definition globaldefs.h:7
dErrorBreak
void dErrorBreak(void)
Definition dError.cc:140
assume
#define assume(x)
Definition mod2.h:389
pPolyAssumeReturnMsg
#define pPolyAssumeReturnMsg(cond, msg)
Definition monomials.h:137
p_GetComp
#define p_GetComp(p, r)
Definition monomials.h:64
pFalseReturn
#define pFalseReturn(cond)
Definition monomials.h:139
pIter
#define pIter(p)
Definition monomials.h:37
pNext
#define pNext(p)
Definition monomials.h:36
pAssumeReturn
#define pAssumeReturn(cond)
Definition monomials.h:78
_pPolyAssumeReturnMsg
#define _pPolyAssumeReturnMsg(cond, msg, p, r)
Definition monomials.h:124
_pPolyAssumeReturn
#define _pPolyAssumeReturn(cond, p, r)
Definition monomials.h:101
pGetCoeff
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
rRing_has_Comp
#define rRing_has_Comp(r)
Definition monomials.h:266
ap
Definition ap.h:40
omSizeWOfBin
#define omSizeWOfBin(bin_ptr)
Definition omAllocPrivate.h:100
omIsBinPageAddr
#define omIsBinPageAddr(addr)
Definition omBinPage.h:68
omError_NoError
@ omError_NoError
Definition omError.h:18
NULL
#define NULL
Definition omList.c:12
omTestList
#define omTestList(ptr, level)
Definition omList.h:81
p_DebugInit
static poly p_DebugInit(poly p, ring src_ring, ring dest_ring)
Definition pDebug.cc:194
pIsMonomOf
BOOLEAN pIsMonomOf(poly p, poly m)
Definition pDebug.cc:164
p_LmCheckPolyRing
BOOLEAN p_LmCheckPolyRing(poly p, ring r)
Definition pDebug.cc:123
_p_Test
BOOLEAN _p_Test(poly p, ring r, int level)
Definition pDebug.cc:211
p_CheckIsFromRing
BOOLEAN p_CheckIsFromRing(poly p, ring r)
Definition pDebug.cc:105
p_Setm_General
void p_Setm_General(poly p, ring r)
Definition p_polys.cc:158
p_DebugLmDivisibleByNoComp
BOOLEAN p_DebugLmDivisibleByNoComp(poly a, poly b, ring r)
Definition pDebug.cc:144
d_poly_error_reporting
STATIC_VAR BOOLEAN d_poly_error_reporting
Definition pDebug.cc:42
_p_LmTest
BOOLEAN _p_LmTest(poly p, ring r, int level)
Definition pDebug.cc:322
dPolyReportError
BOOLEAN dPolyReportError(poly p, ring r, const char *fmt,...)
Definition pDebug.cc:43
p_CheckRing
BOOLEAN p_CheckRing(ring r)
Definition pDebug.cc:131
p_LmCheckIsFromRing
BOOLEAN p_LmCheckIsFromRing(poly p, ring r)
Definition pDebug.cc:74
p_CheckPolyRing
BOOLEAN p_CheckPolyRing(poly p, ring r)
Definition pDebug.cc:115
pHaveCommonMonoms
BOOLEAN pHaveCommonMonoms(poly p, poly q)
Definition pDebug.cc:174
_pp_Test
BOOLEAN _pp_Test(poly p, ring lmRing, ring tailRing, int level)
Definition pDebug.cc:332
p_ExpVectorEqual
static BOOLEAN p_ExpVectorEqual(poly p1, poly p2, const ring r1, const ring r2)
Definition p_polys.cc:4680
p_polys.h
p_SetExp
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:490
p_SetComp
static unsigned long p_SetComp(poly p, unsigned long c, ring r)
Definition p_polys.h:249
p_LmCmp
static int p_LmCmp(poly p, poly q, const ring r)
Definition p_polys.h:1601
p_GetExp
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:471
p_LmFree
static void p_LmFree(poly p, ring)
Definition p_polys.h:685
p_Init
static poly p_Init(const ring r, omBin bin)
Definition p_polys.h:1341
p_wrp
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition polys0.cc:373
rSamePolyRep
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:1805
ring.h
ro_syzcomp
@ ro_syzcomp
Definition ring.h:60
sro_ord::data
union sro_ord::@006200034235045362245112336324125006204215012002 data
sro_ord
Definition ring.h:225
omTestBinAddrSize
#define omTestBinAddrSize(A, B, C)
Definition xalloc.h:272
omPrintAddrInfo
#define omPrintAddrInfo(A, B, C)
Definition xalloc.h:270
omPrintCurrentBackTraceMax
#define omPrintCurrentBackTraceMax(A, B)
Definition xalloc.h:265
omSizeWOfAddr
#define omSizeWOfAddr(P)
Definition xalloc.h:223