Loading...
Searching...
No Matches
polys0.cc
Go to the documentation of this file.
/****************************************
* Computer Algebra System SINGULAR *
****************************************/
/*
* ABSTRACT - all basic methods to convert polynomials to strings
*/
/* includes */
#include "misc/auxiliary.h"
#include "coeffs/numbers.h"
#include "polys/monomials/ring.h"
#include "polys/monomials/p_polys.h"
#ifdef HAVE_SHIFTBBA
#include "polys/shiftop.h"
#endif
/*2
* writes a monomial (p),
* uses form x*gen(.) if ko != column number of p
*/
static void writemon(poly p, int ko, const ring r)
{
assume(r != NULL);
const coeffs C = r->cf;
assume(C != NULL);
BOOLEAN wroteCoef=FALSE,writeGen=FALSE;
const BOOLEAN bNotShortOut = (rShortOut(r) == FALSE);
if (((p_GetComp(p,r) == ko)
&&(p_LmIsConstantComp(p, r)))
|| ((!n_IsOne(pGetCoeff(p),C))
&& (!n_IsMOne(pGetCoeff(p),C))
)
)
{
if( bNotShortOut )
n_WriteLong(pGetCoeff(p),C);
else
n_WriteShort(pGetCoeff(p),C);
wroteCoef=(bNotShortOut)
|| (rParameter(r)!=NULL)
|| rField_is_R(r) || (rField_is_long_R(r)) || (rField_is_long_C(r));
writeGen=TRUE;
}
else if (n_IsMOne(pGetCoeff(p),C))
{
if (n_GreaterZero(pGetCoeff(p),C))
{
if( bNotShortOut )
n_WriteLong(pGetCoeff(p),C);
else
n_WriteShort(pGetCoeff(p),C);
wroteCoef=(bNotShortOut)
|| (rParameter(r)!=NULL)
|| rField_is_R(r) || (rField_is_long_R(r)) || (rField_is_long_C(r));
writeGen=TRUE;
}
else
StringAppendS("-");
}
int i;
{
for (i=0; i<rVar(r); i++)
{
{
long ee = p_GetExp(p,i+1,r);
if (ee!=0L)
{
if (wroteCoef)
StringAppendS("*");
//else
wroteCoef=(bNotShortOut);
writeGen=TRUE;
StringAppendS(rRingVar(i, r));
if (ee != 1L)
{
if (bNotShortOut) StringAppendS("^");
StringAppend("%ld", ee);
}
}
}
}
}
//StringAppend("{%d}",p->Order);
if (p_GetComp(p, r) != (long)ko)
{
if (writeGen) StringAppendS("*");
StringAppend("gen(%d)", p_GetComp(p, r));
}
}
/*2
* writes a monomial (p),
* uses form x*gen(.) if ko != column number of p
*/
#ifdef HAVE_SHIFTBBA
static void writemonLP(poly p, int ko, const ring r)
{
assume(r != NULL);
const coeffs C = r->cf;
assume(C != NULL);
BOOLEAN wroteCoef=FALSE,writeGen=FALSE;
if (((p_GetComp(p,r) == ko)
&&(p_LmIsConstantComp(p, r)))
|| ((!n_IsOne(pGetCoeff(p),C))
&& (!n_IsMOne(pGetCoeff(p),C))
)
)
{
n_WriteLong(pGetCoeff(p),C);
wroteCoef=TRUE;
writeGen=TRUE;
}
else if (n_IsMOne(pGetCoeff(p),C))
{
if (n_GreaterZero(pGetCoeff(p),C))
{
n_WriteLong(pGetCoeff(p),C);
wroteCoef=TRUE;
writeGen=TRUE;
}
else
StringAppendS("-");
}
int i;
{
int lV = r->isLPring;
int lastVar = p_mLastVblock(p, r) * lV;
BOOLEAN wroteBlock = FALSE;
for (i=0; i<rVar(r); i++)
{
{
long ee = p_GetExp(p,i+1,r);
BOOLEAN endOfBlock = ((i+1) % lV) == 0;
BOOLEAN writeEmptyBlock = ee==0L && endOfBlock && !wroteBlock && i < lastVar;
if (ee!=0L || writeEmptyBlock)
{
if (wroteBlock)
StringAppendS("&");
else if (wroteCoef)
StringAppendS("*");
//else
wroteCoef=TRUE; //(bNotShortOut);
writeGen=TRUE;
if (writeEmptyBlock)
StringAppendS("_");
else
{
StringAppendS(rRingVar(i, r));
if (ee != 1L)
{
StringAppend("^%ld", ee);
}
wroteBlock = TRUE;
}
}
if (endOfBlock)
wroteBlock = FALSE;
}
}
}
//StringAppend("{%d}",p->Order);
if (p_GetComp(p, r) != (long)ko)
{
if (writeGen) StringAppendS("*");
StringAppend("gen(%d)", p_GetComp(p, r));
}
}
#endif
/// if possible print p in a short way...
void p_String0Short(const poly p, ring lmRing, ring tailRing)
{
// NOTE: the following (non-thread-safe!) UGLINESS
// (changing naRing->ShortOut for a while) is due to Hans!
// Just think of other ring using the VERY SAME naRing and possible
// side-effects...
const BOOLEAN bLMShortOut = rShortOut(lmRing);
const BOOLEAN bTAILShortOut = rShortOut(tailRing);
lmRing->ShortOut = rCanShortOut(lmRing);
tailRing->ShortOut = rCanShortOut(tailRing);
p_String0(p, lmRing, tailRing);
lmRing->ShortOut = bLMShortOut;
tailRing->ShortOut = bTAILShortOut;
}
/// print p in a long way...
void p_String0Long(const poly p, ring lmRing, ring tailRing)
{
// NOTE: the following (non-thread-safe!) UGLINESS
// (changing naRing->ShortOut for a while) is due to Hans!
// Just think of other ring using the VERY SAME naRing and possible
// side-effects...
// but this is not a problem: i/o is not thread-safe anyway.
const BOOLEAN bLMShortOut = rShortOut(lmRing);
const BOOLEAN bTAILShortOut = rShortOut(tailRing);
lmRing->ShortOut = FALSE;
tailRing->ShortOut = FALSE;
p_String0(p, lmRing, tailRing);
lmRing->ShortOut = bLMShortOut;
tailRing->ShortOut = bTAILShortOut;
}
void p_String0(poly p, ring lmRing, ring tailRing)
{
if (p == NULL)
{
StringAppendS("0");
return;
}
p_Normalize(p,lmRing);
if ((n_GetChar(lmRing->cf) == 0)
&& (nCoeff_is_transExt(lmRing->cf)))
p_Normalize(p,lmRing); /* Manual/absfact.tst */
#ifdef HAVE_SHIFTBBA
if(lmRing->isLPring)
{
if ((p_GetComp(p, lmRing) == 0) || (!lmRing->VectorOut))
{
writemonLP(p,0, lmRing);
p = pNext(p);
while (p!=NULL)
{
assume((p->coef==NULL)||(!n_IsZero(p->coef,tailRing->cf)));
if ((p->coef==NULL)||n_GreaterZero(p->coef,tailRing->cf))
StringAppendS("+");
writemonLP(p,0, tailRing);
p = pNext(p);
}
return;
}
}
else
#endif
{
if ((p_GetComp(p, lmRing) == 0) || (!lmRing->VectorOut))
{
writemon(p,0, lmRing);
p = pNext(p);
while (p!=NULL)
{
assume((p->coef==NULL)||(!n_IsZero(p->coef,tailRing->cf)));
if ((p->coef==NULL)||n_GreaterZero(p->coef,tailRing->cf))
StringAppendS("+");
writemon(p,0, tailRing);
p = pNext(p);
}
return;
}
}
long k = 1;
StringAppendS("[");
#ifdef HAVE_SHIFTBBA
if(lmRing->isLPring)
{
loop
{
while (k < p_GetComp(p,lmRing))
{
StringAppendS("0,");
k++;
}
writemonLP(p,k,lmRing);
pIter(p);
while ((p!=NULL) && (k == p_GetComp(p, tailRing)))
{
if (n_GreaterZero(p->coef,tailRing->cf)) StringAppendS("+");
writemonLP(p,k,tailRing);
pIter(p);
}
if (p == NULL) break;
StringAppendS(",");
k++;
}
}
else
#endif
{
loop
{
while (k < p_GetComp(p,lmRing))
{
StringAppendS("0,");
k++;
}
writemon(p,k,lmRing);
pIter(p);
while ((p!=NULL) && (k == p_GetComp(p, tailRing)))
{
if (n_GreaterZero(p->coef,tailRing->cf)) StringAppendS("+");
writemon(p,k,tailRing);
pIter(p);
}
if (p == NULL) break;
StringAppendS(",");
k++;
}
}
StringAppendS("]");
}
char* p_String(poly p, ring lmRing, ring tailRing)
{
StringSetS("");
p_String0(p, lmRing, tailRing);
return StringEndS();
}
/*2
* writes a polynomial p to stdout
*/
void p_Write0(poly p, ring lmRing, ring tailRing)
{
char *s=p_String(p, lmRing, tailRing);
PrintS(s);
omFree(s);
}
/*2
* writes a polynomial p to stdout followed by \n
*/
void p_Write(poly p, ring lmRing, ring tailRing)
{
p_Write0(p, lmRing, tailRing);
PrintLn();
}
#if !defined(__OPTIMIZE__) || defined(KDEBUG)
/*2
*the standard debugging output:
*print the first two monomials of the poly (wrp) or only the lead term (wrp0),
*possibly followed by the string "+..."
*/
void p_wrp0(poly p, ring ri)
{
poly r;
if (p==NULL) PrintS("NULL");
else if (pNext(p)==NULL) p_Write0(p, ri);
else
{
r = pNext(p);
pNext(p) = NULL;
p_Write0(p, ri);
if (r!=NULL)
{
PrintS("+...");
pNext(p) = r;
}
}
}
#endif
void p_wrp(poly p, ring lmRing, ring tailRing)
{
poly r;
if (p==NULL) PrintS("NULL");
else if (pNext(p)==NULL) p_Write0(p, lmRing);
else
{
r = pNext(pNext(p));
pNext(pNext(p)) = NULL;
p_Write0(p, tailRing);
if (r!=NULL)
{
PrintS("+...");
pNext(pNext(p)) = r;
}
}
}
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
i
int i
Definition cfEzgcd.cc:132
k
int k
Definition cfEzgcd.cc:99
p
int p
Definition cfModGcd.cc:4086
n_GreaterZero
static FORCE_INLINE BOOLEAN n_GreaterZero(number n, const coeffs r)
ordered fields: TRUE iff 'n' is positive; in Z/pZ: TRUE iff 0 < m <= roundedBelow(p/2),...
Definition coeffs.h:500
n_IsMOne
static FORCE_INLINE BOOLEAN n_IsMOne(number n, const coeffs r)
TRUE iff 'n' represents the additive inverse of the one element, i.e. -1.
Definition coeffs.h:478
n_WriteLong
static FORCE_INLINE void n_WriteLong(number n, const coeffs r)
write to the output buffer of the currently used reporter
Definition coeffs.h:586
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_WriteShort
static FORCE_INLINE void n_WriteShort(number n, const coeffs r)
write to the output buffer of the currently used reporter in a shortest possible way,...
Definition coeffs.h:591
n_IsOne
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
Definition coeffs.h:474
nCoeff_is_transExt
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
Definition coeffs.h:913
StringAppend
#define StringAppend
Definition emacs.cc:79
s
const CanonicalForm int s
Definition facAbsFact.cc:51
assume
#define assume(x)
Definition mod2.h:389
p_GetComp
#define p_GetComp(p, r)
Definition monomials.h:64
pIter
#define pIter(p)
Definition monomials.h:37
pNext
#define pNext(p)
Definition monomials.h:36
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
coeffs
The main handler for Singular numbers which are suitable for Singular polynomials.
numbers.h
omFree
#define omFree(addr)
Definition omAllocDecl.h:261
NULL
#define NULL
Definition omList.c:12
p_Normalize
void p_Normalize(poly p, const ring r)
Definition p_polys.cc:3939
p_polys.h
p_LmIsConstantComp
static BOOLEAN p_LmIsConstantComp(const poly p, const ring r)
Definition p_polys.h:1008
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_String
char * p_String(poly p, ring lmRing, ring tailRing)
Definition polys0.cc:322
p_String0
void p_String0(poly p, ring lmRing, ring tailRing)
print p according to ShortOut in lmRing & tailRing
Definition polys0.cc:223
p_Write
void p_Write(poly p, ring lmRing, ring tailRing)
Definition polys0.cc:342
writemon
static void writemon(poly p, int ko, const ring r)
Definition polys0.cc:24
p_String0Long
void p_String0Long(const poly p, ring lmRing, ring tailRing)
print p in a long way...
Definition polys0.cc:203
p_String0Short
void p_String0Short(const poly p, ring lmRing, ring tailRing)
if possible print p in a short way...
Definition polys0.cc:184
p_wrp0
void p_wrp0(poly p, ring ri)
Definition polys0.cc:354
writemonLP
static void writemonLP(poly p, int ko, const ring r)
Definition polys0.cc:104
p_Write0
void p_Write0(poly p, ring lmRing, ring tailRing)
Definition polys0.cc:332
p_wrp
void p_wrp(poly p, ring lmRing, ring tailRing)
Definition polys0.cc:373
StringSetS
void StringSetS(const char *st)
Definition reporter.cc:128
StringAppendS
void StringAppendS(const char *st)
Definition reporter.cc:107
PrintS
void PrintS(const char *s)
Definition reporter.cc:288
StringEndS
char * StringEndS()
Definition reporter.cc:151
PrintLn
void PrintLn()
Definition reporter.cc:314
ring.h
rField_is_R
static BOOLEAN rField_is_R(const ring r)
Definition ring.h:524
rField_is_long_C
static BOOLEAN rField_is_long_C(const ring r)
Definition ring.h:551
rRingVar
static char * rRingVar(short i, const ring r)
Definition ring.h:583
rShortOut
static BOOLEAN rShortOut(const ring r)
Definition ring.h:587
rParameter
static char const ** rParameter(const ring r)
(r->cf->parameter)
Definition ring.h:631
rField_is_long_R
static BOOLEAN rField_is_long_R(const ring r)
Definition ring.h:548
rCanShortOut
static BOOLEAN rCanShortOut(const ring r)
Definition ring.h:592
rVar
static short rVar(const ring r)
define rVar(r) (r->N)
Definition ring.h:598
p_mLastVblock
int p_mLastVblock(poly p, const ring ri)
Definition shiftop.cc:421
shiftop.h
loop
#define loop
Definition structs.h:71