14#include "factory/factory.h"
36#ifdef HAVE_POLYEXTENSIONS
60 snprintf(
s,11,
"Coeffs(%d)",r->type);
65 number n=r->cfMult(a,
b,r);
71 number n=r->cfAdd(a,
b,r);
80 *
res = r->cfInit(1, r);
84 *
res = r->cfCopy(a, r);
88 *
res = r->cfMult(a, a, r);
92 number
b = r->cfInvers(a, r);
99 r->cfInpMult(*
res, *
res, r);
102 r->cfInpMult(*
res, a, r);
108 number one=r->cfInit(1,r);
109 number
res=r->cfDiv(one,a,r);
115 if (!r->cfIsUnit(a,r))
Print(
"ndInvers_Ring used with non-unit\n");
116 number one=r->cfInit(1,r);
117 number
res=r->cfDiv(one,a,r);
123{
return r->cfIsOne(a,r)|| r->cfIsMOne(a,r); }
125{
return !r->cfIsZero(a,r); }
127{
return r->cfInit(1,r); }
129{
return cf->cfInit(
p(),
cf); }
131{
return cf->cfInit(
cf->cfSize(a,
cf),
cf); }
142static number
ndXExtGcd(number, number, number *, number *, number *, number *,
const coeffs r)
149 Werror(
"ChineseRemainder not implemented for %s (c=%d)",r->cfCoeffName(r),
getCoeffType(r));
150 return r->cfInit(0,r);
154 Warn(
"ReadFd not implemented for %s (c=%d)",r->cfCoeffName(r),
getCoeffType(r));
160 Warn(
"WriteFd not implemented for %s (c=%d)",r->cfCoeffName(r),
getCoeffType(r));
165 return (-r->cfIsZero(n,r));
170 return r->cfInit(1,r);
177 if (ret || (c==0) || (r->is_field))
179 number ch =
n_Init( c, r );
180 number
g =
n_Gcd( ch, a, r );
189number
ndGcd(number, number,
const coeffs r) {
return r->cfInit(1,r); }
193 return R->cfInit(0,
R);
216 numberCollectionEnumerator.
Reset();
218 if( !numberCollectionEnumerator.
MoveNext() )
224 number &curr = numberCollectionEnumerator.
Current();
240 while( numberCollectionEnumerator.
MoveNext() )
242 number &n = numberCollectionEnumerator.
Current();
268 while( numberCollectionEnumerator.
MoveNext() )
270 number &n = numberCollectionEnumerator.
Current();
294 assume(aRing->rep==r->rep);
298 return r->cfCopy(a, r);
310static number
ndExtGcd (number, number, number *, number *,
const coeffs r) {
return r->cfInit(1,r); }
316 WerrorS(
"no conversion to factory");
322 WerrorS(
"no conversion from factory");
331 mpz_init_set_si(
result, r->cfInt(n, r) );
336 return r->cfInit( mpz_get_si(
m), r);
339static const char *
ndRead(
const char *
s, number *,
const coeffs r)
384 #ifdef HAVE_POLYEXTENSIONS
494 Werror(
"Sorry: the coeff type [%d] was not registered: it is missing in nInitCharTable", (
int)t);
584 assume (r->cfKillChar!=
NULL); r->cfKillChar(r);
590 WarnS(
"cf_root list destroyed");
633 nFindCoeffByName_p
next;
639 nFindCoeffByName_p
h=(nFindCoeffByName_p)
omAlloc0(
sizeof(*
h));
653 && (strcmp(cf_name,n->
cfCoeffName(n))==0))
return n;
681 if (((*
s) >=
'0') && ((*
s) <=
'9'))
690 while (((*
s) >=
'0') && ((*
s) <=
'9'));
691 if ((
m!=0) && (ii>=(
unsigned)
m)) ii=ii%
m;
701 if (((*
s) >=
'0') && ((*
s) <=
'9'))
708 if ((
m!=0) && (ii > (LONG_MAX / 10))) ii = ii %
m;
710 while (((*
s) >=
'0') && ((*
s) <=
'9'));
711 if ((
m!=0) && (ii>=(
long)
m)) ii=ii%
m;
721 const char * start=
s;
723 while (*
s >=
'0' && *
s <=
'9')
s++;
726 mpz_set_str(
i,start,10);
732 mpz_set_str(
i,start,10);
BOOLEAN naInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.
BOOLEAN n2pInitChar(coeffs cf, void *infoStruct)
virtual reference Current()=0
Gets the current element in the collection (read and write).
virtual void Reset()=0
Sets the enumerator to its initial position: -1, which is before the first element in the collection.
virtual bool MoveNext()=0
Advances the enumerator to the next element of the collection. returns true if the enumerator was suc...
Templated enumerator interface for simple iteration over a generic collection of T's.
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE number n_Mult(number a, number b, const coeffs r)
return the product of 'a' and 'b', i.e., a*b
static FORCE_INLINE number n_Copy(number n, const coeffs r)
return a copy of 'n'
static FORCE_INLINE BOOLEAN nCoeff_has_Units(const coeffs r)
returns TRUE, if r is not a field and r has non-trivial units
static FORCE_INLINE BOOLEAN nCoeff_is_GF(const coeffs r)
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
static FORCE_INLINE number n_Gcd(number a, number b, const coeffs r)
in Z: return the gcd of 'a' and 'b' in Z/nZ, Z/2^kZ: computed as in the case Z in Z/pZ,...
static FORCE_INLINE number n_Invers(number a, const coeffs r)
return the multiplicative inverse of 'a'; raise an error if 'a' is not invertible
static FORCE_INLINE BOOLEAN nCoeff_is_numeric(const coeffs r)
static FORCE_INLINE char * nCoeffString(const coeffs cf)
TODO: make it a virtual method of coeffs, together with: Decompose & Compose, rParameter & rPar.
static FORCE_INLINE BOOLEAN nCoeff_is_Zp_a(const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_Q_algext(const coeffs r)
is it an alg. ext. of Q?
static FORCE_INLINE number n_Div(number a, number b, const coeffs r)
return the quotient of 'a' and 'b', i.e., a/b; raises an error if 'b' is not invertible in r exceptio...
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
static FORCE_INLINE BOOLEAN n_IsZero(number n, const coeffs r)
TRUE iff 'n' represents the zero element.
static FORCE_INLINE number n_GetUnit(number n, const coeffs r)
in Z: 1 in Z/kZ (where k is not a prime): largest divisor of n (taken in Z) that is co-prime with k i...
static FORCE_INLINE BOOLEAN nCoeff_has_simple_Alloc(const coeffs r)
TRUE if n_Delete is empty operation.
static FORCE_INLINE number n_Sub(number a, number b, const coeffs r)
return the difference of 'a' and 'b', i.e., a-b
static FORCE_INLINE BOOLEAN nCoeff_is_Ring(const coeffs r)
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
static FORCE_INLINE void n_Delete(number *p, const coeffs r)
delete 'p'
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
static FORCE_INLINE number n_Init(long i, const coeffs r)
a number representing i in the given coeff field/ring r
static FORCE_INLINE BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
static FORCE_INLINE void n_InpMult(number &a, number b, const coeffs r)
multiplication of 'a' and 'b'; replacement of 'a' by the product a*b
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
static FORCE_INLINE void n_Normalize(number &n, const coeffs r)
inplace-normalization of n; produces some canonical representation of n;
static FORCE_INLINE BOOLEAN n_IsOne(number n, const coeffs r)
TRUE iff 'n' represents the one element.
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
const CanonicalForm int s
void WerrorS(const char *s)
BOOLEAN nfInitChar(coeffs r, void *parameter)
BOOLEAN flintQrat_InitChar(coeffs cf, void *infoStruct)
BOOLEAN ngcInitChar(coeffs n, void *parameter)
Initialize r (n_long_C)
BOOLEAN ngfInitChar(coeffs n, void *parameter)
Initialize r.
BOOLEAN nlInitChar(coeffs r, void *p)
BOOLEAN npInitChar(coeffs r, void *p)
The main handler for Singular numbers which are suitable for Singular polynomials.
BOOLEAN nnInitChar(coeffs n, void *p)
Initialize r.
static void ndPower(number a, int i, number *res, const coeffs r)
static BOOLEAN ndIsUnit_Field(number a, const coeffs r)
void nRegisterCfByName(cfInitCfByNameProc p, n_coeffType n)
CanonicalForm ndConvSingNFactoryN(number, BOOLEAN, const coeffs)
number ndReadFd(const ssiInfo *, const coeffs r)
static int ndDivComp(number, number, const coeffs)
static number ndEucNorm(number a, const coeffs cf)
VAR nFindCoeffByName_p nFindCoeffByName_Root
static number ndGetUnit_Ring(number, const coeffs r)
static BOOLEAN ndDBTest(number, const char *, const int, const coeffs)
number ndGcd(number, number, const coeffs r)
static void ndKillChar(coeffs)
static number ndConvFactoryNSingN(const CanonicalForm, const coeffs)
[in, out] a bigint number >= 0
static void ndClearDenominators(ICoeffsEnumerator &, number &d, const coeffs r)
static void ndClearContent(ICoeffsEnumerator &numberCollectionEnumerator, number &c, const coeffs r)
static int ndParDeg(number n, const coeffs r)
static BOOLEAN ndCoeffIsEqual(const coeffs r, n_coeffType n, void *)
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
static BOOLEAN ndIsUnit_Ring(number a, const coeffs r)
void ndNormalize(number &, const coeffs)
void n_Print(number &a, const coeffs r)
print a number (BEWARE of string buffers!) mostly for debugging
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
static int ndSize(number a, const coeffs r)
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
static number ndFarey(number, number, const coeffs r)
static number ndRandom(siRandProc p, number, number, const coeffs cf)
static void ndMPZ(mpz_t result, number &n, const coeffs r)
Converts a non-negative bigint number into a GMP number.
STATIC_VAR n_coeffType nLastCoeffs
static number ndGetDenom(number &, const coeffs r)
static void ndDelete(number *d, const coeffs)
STATIC_VAR cfInitCharProc * nInitCharTable
static number ndInvers_Ring(number a, const coeffs r)
static number ndParameter(const int, const coeffs r)
static number ndCopy(number a, const coeffs)
static void ndInpMult(number &a, number b, const coeffs r)
VAR cfInitCharProc nInitCharTableDefault[]
static void ndWriteFd(number, const ssiInfo *, const coeffs r)
static number ndChineseRemainder(number *, number *, int, BOOLEAN, CFArray &, const coeffs r)
static char * ndCoeffString(const coeffs r)
coeffs nFindCoeffByName(char *cf_name)
find an existing coeff by its "CoeffName"
static number ndGetNumerator(number &a, const coeffs r)
static BOOLEAN ndDivBy(number, number, const coeffs)
static number ndInitMPZ(mpz_t m, const coeffs r)
static void ndInpAdd(number &a, number b, const coeffs r)
number nd_Copy(number a, const coeffs r)
static nMapFunc ndSetMap(const coeffs src, const coeffs dst)
static number ndAnn(number, const coeffs cf)
static const char * ndRead(const char *s, number *, const coeffs r)
static number ndInvers(number a, const coeffs r)
BOOLEAN n_IsZeroDivisor(number a, const coeffs r)
Test whether a is a zero divisor in r i.e. not coprime with char. of r very inefficient implementatio...
static number ndIntMod(number a, number b, const coeffs R)
static void ndCoeffWrite(const coeffs r, BOOLEAN)
n_coeffType nRegister(n_coeffType n, cfInitCharProc p)
static number ndReturn0(number, const coeffs r)
static number ndExtGcd(number, number, number *, number *, const coeffs r)
static char * ndCoeffName(const coeffs r)
static void ndSetChar(const coeffs)
void nKillChar(coeffs r)
undo all initialisations
static number ndXExtGcd(number, number, number *, number *, number *, number *, const coeffs r)
char * nEatLong(char *s, mpz_ptr i)
extracts a long integer from s, returns the rest
number ndQuotRem(number a, number b, number *r, const coeffs R)
coeffs(* cfInitCfByNameProc)(char *s, n_coeffType n)
initialize an object of type coeffs by its name, return NULL otherwise
BOOLEAN(* cfInitCharProc)(coeffs, void *)
initialize an object of type coeff, return FALSE in case of success
#define omFreeSize(addr, size)
#define omReallocSize(addr, o_size, size)
void StringSetS(const char *st)
void PrintS(const char *s)
void Werror(const char *fmt,...)
BOOLEAN nrzInitChar(coeffs r, void *parameter)
BOOLEAN nr2mInitChar(coeffs r, void *p)
BOOLEAN nrnInitChar(coeffs r, void *p)
BOOLEAN nrInitChar(coeffs n, void *p)
Initialize r.
BOOLEAN(* cfIsUnit)(number a, const coeffs r)
number(* cfChineseRemainder)(number *x, number *q, int rl, BOOLEAN sym, CFArray &inv_cache, const coeffs)
chinese remainder returns X with X mod q[i]=x[i], i=0..rl-1
number(* cfNormalizeHelper)(number a, number b, const coeffs r)
int(* cfDivComp)(number a, number b, const coeffs r)
BOOLEAN(*)(*)(*)(*)(*)(*) cfGreaterZero(number a, const coeffs r)
number(* cfExtGcd)(number a, number b, number *s, number *t, const coeffs r)
number(* cfGetUnit)(number a, const coeffs r)
number(* cfLcm)(number a, number b, const coeffs r)
number(* cfGetNumerator)(number &n, const coeffs r)
number(* cfInvers)(number a, const coeffs r)
return 1/a
number(* cfInit)(long i, const coeffs r)
init with an integer
int iNumberOfParameters
Number of Parameters in the coeffs (default 0)
number(* cfInpNeg)(number a, const coeffs r)
changes argument inline: a:= -a return -a! (no copy is returned) the result should be assigned to the...
number(* cfInitMPZ)(mpz_t i, const coeffs r)
init with a GMP integer
BOOLEAN is_field
TRUE, if cf is a field.
nMapFunc(* cfSetMap)(const coeffs src, const coeffs dst)
number(* cfParameter)(const int i, const coeffs r)
create i^th parameter or NULL if not possible
void(* cfSetChar)(const coeffs r)
number(* convFactoryNSingN)(const CanonicalForm n, const coeffs r)
conversion to CanonicalForm(factory) to number
number(* cfGcd)(number a, number b, const coeffs r)
number(* cfImPart)(number a, const coeffs r)
number(* cfFarey)(number p, number n, const coeffs)
rational reconstruction: "best" rational a/b with a/b = p mod n
number(* cfCopy)(number a, const coeffs r)
return a copy of a
BOOLEAN(*)(*)(*) cfIsZero(number a, const coeffs r)
void(* cfKillChar)(coeffs r)
BOOLEAN(*)(*) cfEqual(number a, number b, const coeffs r)
tests
void(* cfMPZ)(mpz_t result, number &n, const coeffs r)
Converts a (integer) number n into a GMP number, 0 if impossible.
BOOLEAN(* nCoeffIsEqual)(const coeffs r, n_coeffType n, void *parameter)
number(* cfXExtGcd)(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
void(* cfWriteShort)(number a, const coeffs r)
print a given number in a shorter way, if possible e.g. in K(a): a2 instead of a^2
number(* cfRePart)(number a, const coeffs r)
void(* cfNormalize)(number &a, const coeffs r)
number(* cfGetDenom)(number &n, const coeffs r)
void(* cfWriteLong)(number a, const coeffs r)
print a given number (long format)
number(* cfSubringGcd)(number a, number b, const coeffs r)
BOOLEAN(*)(*)(*)(*) cfIsOne(number a, const coeffs r)
number(* cfEucNorm)(number a, const coeffs r)
number(* cfAnn)(number a, const coeffs r)
char *(* cfCoeffString)(const coeffs r)
string output of coeff description
number(* cfReadFd)(const ssiInfo *f, const coeffs r)
void(* cfPower)(number a, int i, number *result, const coeffs r)
CanonicalForm(* convSingNFactoryN)(number n, BOOLEAN setChar, const coeffs r)
long(* cfInt)(number &n, const coeffs r)
convertion to long, 0 if impossible
BOOLEAN(* cfGreater)(number a, number b, const coeffs r)
number(* cfQuotRem)(number a, number b, number *rem, const coeffs r)
void(* cfCoeffWrite)(const coeffs r, BOOLEAN details)
output of coeff description via Print
void(* cfDelete)(number *a, const coeffs r)
BOOLEAN(* cfDBTest)(number a, const char *f, const int l, const coeffs r)
Test: is "a" a correct number?
void(* cfWriteFd)(number a, const ssiInfo *f, const coeffs r)
number(* cfRandom)(siRandProc p, number p1, number p2, const coeffs cf)
a function returning random elements
BOOLEAN(*)(*)(*)(*)(*) cfIsMOne(number a, const coeffs r)
char const ** pParameterNames
array containing the names of Parameters (default NULL)
char *(* cfCoeffName)(const coeffs r)
default name of cf, should substitue cfCoeffWrite, cfCoeffString
int(* cfParDeg)(number x, const coeffs r)
degree for coeffcients: -1 for 0, 0 for "constants", ...
void(* cfInpMult)(number &a, number b, const coeffs r)
Inplace: a *= b.
int(* cfSize)(number n, const coeffs r)
how complicated, (0) => 0, or positive
void(* cfInpAdd)(number &a, number b, const coeffs r)
Inplace: a += b.
BOOLEAN(* cfDivBy)(number a, number b, const coeffs r)
test if b divides a cfDivBy(zero,b,r) is true, if b is a zero divisor
nCoeffsEnumeratorFunc cfClearContent
function pointer behind n_ClearContent
nCoeffsEnumeratorFunc cfClearDenominators
function pointer behind n_ClearDenominators
const char *(* cfRead)(const char *s, number *a, const coeffs r)
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.