34#ifdef HAVE_POLYEXTENSIONS
58 snprintf(
s,11,
"Coeffs(%d)",r->type);
63 number n=r->cfMult(a,
b,r);
69 number n=r->cfAdd(a,
b,r);
78 *
res = r->cfInit(1, r);
82 *
res = r->cfCopy(a, r);
86 *
res = r->cfMult(a, a, r);
90 number
b = r->cfInvers(a, r);
97 r->cfInpMult(*
res, *
res, r);
100 r->cfInpMult(*
res, a, r);
106 number one=r->cfInit(1,r);
107 number
res=r->cfDiv(one,a,r);
113 if (!r->cfIsUnit(a,r))
Print(
"ndInvers_Ring used with non-unit\n");
114 number one=r->cfInit(1,r);
115 number
res=r->cfDiv(one,a,r);
121{
return r->cfIsOne(a,r)|| r->cfIsMOne(a,r); }
123{
return !r->cfIsZero(a,r); }
125{
return r->cfInit(1,r); }
127{
return cf->cfInit(
p(),
cf); }
129{
return cf->cfInit(
cf->cfSize(a,
cf),
cf); }
137 Werror(
"farey not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
140static number
ndXExtGcd(number, number, number *, number *, number *, number *,
const coeffs r)
142 Werror(
"XExtGcd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
147 Werror(
"ChineseRemainder not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
148 return r->cfInit(0,r);
152 Warn(
"ReadFd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
158 Warn(
"ReadFd_S not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
164 Warn(
"WriteFd not implemented for %s (c=%d)",r->cfCoeffName(r),getCoeffType(r));
169 return (-r->cfIsZero(n,r));
174 return r->cfInit(1,r);
180 int c = n_GetChar(r);
181 if (ret || (c==0) || (r->is_field))
183 number ch = n_Init( c, r );
184 number
g = n_Gcd( ch, a, r );
185 ret = !n_IsOne (
g, r);
193number
ndGcd(number, number,
const coeffs r) {
return r->cfInit(1,r); }
197 return R->cfInit(0,
R);
200 number d=n_Div(a,
b,
R);
201 number
p=n_Mult(
b,d,
R);
202 number r=n_Sub(a,
p,
R);
220 numberCollectionEnumerator.
Reset();
222 if( !numberCollectionEnumerator.
MoveNext() )
228 number &curr = numberCollectionEnumerator.
Current();
231 if (nCoeff_is_Ring(r))
239 number inv = n_Invers(c, r);
241 n_InpMult(curr, inv, r);
243 while( numberCollectionEnumerator.
MoveNext() )
245 number &n = numberCollectionEnumerator.
Current();
247 n_InpMult(n, inv, r);
252 }
else c = n_Init(1, r);
257 assume(!nCoeff_is_Ring(r));
260 n_Normalize(curr, r);
262 if (!n_IsOne(curr, r))
268 number inv = n_Invers(t, r);
270 while( numberCollectionEnumerator.
MoveNext() )
272 number &n = numberCollectionEnumerator.
Current();
273 n_InpMult(n, inv, r);
296 assume(aRing->rep==r->rep);
300 return r->cfCopy(a, r);
311static 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 *n,
const coeffs r)
354 return (n==r->type) &&(r->data==d);
368 number d=n_Div(a,
b,
R);
369 number
p=n_Mult(
b,d,
R);
383 #ifdef HAVE_POLYEXTENSIONS
492 Werror(
"Sorry: the coeff type [%d] was not registered: it is missing in nInitCharTable", (
int)t);
579 assume (r->cfKillChar!=
NULL); r->cfKillChar(r);
585 WarnS(
"cf_root list destroyed");
628 nFindCoeffByName_p
next;
634 nFindCoeffByName_p
h=(nFindCoeffByName_p)
omAlloc0(
sizeof(*
h));
648 && (strcmp(cf_name,n->
cfCoeffName(n))==0))
return n;
676 if (((*
s) >=
'0') && ((*
s) <=
'9'))
685 while (((*
s) >=
'0') && ((*
s) <=
'9'));
686 if ((
m!=0) && (ii>=(
unsigned)
m)) ii=ii%
m;
696 if (((*
s) >=
'0') && ((*
s) <=
'9'))
703 if ((
m!=0) && (ii > (LONG_MAX / 10))) ii = ii %
m;
705 while (((*
s) >=
'0') && ((*
s) <=
'9'));
706 if ((
m!=0) && (ii>=(
unsigned long)
m)) ii=ii%(
unsigned long)
m;
716 const char * start=
s;
718 while (*
s >=
'0' && *
s <=
'9')
s++;
721 mpz_set_str(
i,start,10);
727 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...
Coefficient rings, fields and other domains suitable for Singular polynomials.
IEnumerator< number > ICoeffsEnumerator
Abstract interface for an enumerator of number coefficients for an object, e.g. a polynomial.
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)
number ndCopyMap(number a, const coeffs src, const coeffs dst)
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r).
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)
void n_Print(number &a, const coeffs r)
print a number (BEWARE of string buffers!) mostly for debugging
static FORCE_INLINE BOOLEAN nCoeff_is_Q(const coeffs r)
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
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 BOOLEAN nCoeff_is_algExt(const coeffs r)
TRUE iff r represents an algebraic extension field.
number(*) nMapFunc(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
void nKillChar(coeffs r)
undo all initialisations
static FORCE_INLINE BOOLEAN nCoeff_is_transExt(const coeffs r)
TRUE iff r represents a transcendental extension field.
static FORCE_INLINE BOOLEAN nCoeff_is_Q_algExt(const coeffs r)
is it an alg. ext. of Q?
const CanonicalForm int s
factory.h' is the user interface to Factory.
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 ndCoeffIsEqual(const coeffs r, n_coeffType n, void *d)
static BOOLEAN ndDBTest(number, const char *, const int, const coeffs)
number ndGcd(number, number, const coeffs r)
static void ndKillChar(coeffs)
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 ndIsUnit_Ring(number a, const coeffs r)
void ndNormalize(number &, const coeffs)
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)
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)
number ndReadFd_S(char **, 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 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 ndConvFactoryNSingN(const CanonicalForm, const coeffs r)
[in, out] a bigint number >= 0
static number ndReturn0(number, const coeffs r)
static number ndExtGcd(number, number, number *, number *, const coeffs r)
static const char * ndRead(const char *s, number *n, const coeffs r)
static char * ndCoeffName(const coeffs r)
static void ndSetChar(const coeffs)
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)
BOOLEAN(*) cfInitCharProc(coeffs, void *)
initialize an object of type coeff, return FALSE in case of success
coeffs(*) cfInitCfByNameProc(char *s, n_coeffType n)
initialize an object of type coeffs by its name, return NULL otherwise
#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.
const char *(*) cfRead(const char *s, number *a, const coeffs r)
number(*) cfReadFd_S(char **s, const coeffs r)
int(*) cfParDeg(number x, const coeffs r)
degree for coefficients: -1 for 0, 0 for "constants", ...
void(*) cfWriteLong(number a, const coeffs r)
print a given number (long format)
int(*) cfSize(number n, const coeffs r)
how complicated, (0) => 0, or positive
number(*) cfNormalizeHelper(number a, number b, const coeffs r)
long(*) cfInt(number &n, const coeffs r)
conversion to long, 0 if impossible
int iNumberOfParameters
Number of Parameters in the coeffs (default 0).
number(*) cfInit(long i, const coeffs r)
init with an integer
void(*) cfPower(number a, int i, number *result, const coeffs r)
number(*) cfGetDenom(number &n, const coeffs r)
number(*) cfSubringGcd(number a, number b, const coeffs r)
number(*) convFactoryNSingN(const CanonicalForm n, const coeffs r)
conversion to CanonicalForm(factory) to number
number(*) cfImPart(number a, const coeffs r)
BOOLEAN(*) cfGreater(number a, number b, const coeffs r)
char *(*) cfCoeffName(const coeffs r)
default name of cf, should substitute cfCoeffWrite, cfCoeffString
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
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
BOOLEAN(*) cfIsMOne(number a, const coeffs r)
nMapFunc(*) cfSetMap(const coeffs src, const coeffs dst)
void(*) cfSetChar(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
int(*) cfDivComp(number a, number b, const coeffs r)
number(*) cfGetNumerator(number &n, const coeffs r)
nCoeffsEnumeratorFunc cfClearContent
function pointer behind n_ClearContent
number(*) cfGetUnit(number a, const coeffs r)
number(*) cfCopy(number a, const coeffs r)
return a copy of a
BOOLEAN(*) cfIsZero(number a, const coeffs r)
BOOLEAN(*) cfIsOne(number a, const coeffs r)
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...
nCoeffsEnumeratorFunc cfClearDenominators
function pointer behind n_ClearDenominators
char const ** pParameterNames
array containing the names of Parameters (default NULL)
number(*) cfFarey(number p, number n, const coeffs)
rational reconstruction: "best" rational a/b with a/b = p mod n
number(*) cfGcd(number a, number b, const coeffs r)
BOOLEAN is_field
TRUE, if cf is a field.
BOOLEAN(*) cfGreaterZero(number a, const coeffs r)
void(*) cfWriteFd(number a, const ssiInfo *f, const coeffs r)
number(*) cfParameter(const int i, const coeffs r)
create i^th parameter or NULL if not possible
number(*) cfQuotRem(number a, number b, number *rem, const coeffs r)
number(*) cfInvers(number a, const coeffs r)
return 1/a
BOOLEAN(*) cfEqual(number a, number b, const coeffs r)
tests
char *(*) cfCoeffString(const coeffs r)
string output of coeff description
void(*) cfKillChar(coeffs r)
void(*) cfNormalize(number &a, const coeffs r)
void(*) cfInpAdd(number &a, number b, const coeffs r)
Inplace: a += b.
number(*) cfEucNorm(number a, const coeffs r)
void(*) cfDelete(number *a, const coeffs r)
number(*) cfReadFd(const ssiInfo *f, const coeffs r)
number(*) cfRePart(number a, const coeffs r)
CanonicalForm(*) convSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
BOOLEAN(*) cfIsUnit(number a, const coeffs r)
void(*) cfInpMult(number &a, number b, const coeffs r)
Inplace: a *= b.
number(*) cfInitMPZ(mpz_t i, const coeffs r)
init with a GMP integer
number(*) cfExtGcd(number a, number b, number *s, number *t, const coeffs r)
number(*) cfRandom(siRandProc p, number p1, number p2, const coeffs cf)
a function returning random elements
number(*) cfLcm(number a, number b, const coeffs r)
BOOLEAN(*) cfDBTest(number a, const char *f, const int l, const coeffs r)
Test: is "a" a correct number?
void(*) cfMPZ(mpz_t result, number &n, const coeffs r)
Converts a (integer) number n into a GMP number, 0 if impossible.
number(*) cfXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
void(*) cfCoeffWrite(const coeffs r, BOOLEAN details)
output of coeff description via Print
BOOLEAN(*) nCoeffIsEqual(const coeffs r, n_coeffType n, void *parameter)
number(*) cfAnn(number a, const coeffs r)
BOOLEAN ntInitChar(coeffs cf, void *infoStruct)
Initialize the coeffs object.