10#include "factory/factory.h"
34static const char *
npRead (
const char *
s, number *a,
const coeffs r);
55 int h = (int)((
long)
k);
56 return ((
int)
h !=0) && (
h <= (r->ch>>1));
73 if (((
long)a == 0) || ((
long)
b == 0))
87 if ((
long)n > (((
long)r->ch) >>1))
return ((
long)n -((
long)r->ch));
88 else return ((
long)n);
95 return ((r->npPminus1M == (
long)a) &&(1L!=(
long)a));
108 if ((
long)a==0)
return (number)0L;
111#ifndef HAVE_GENERIC_MULT
112 int s = r->npLogTable[(long)a] - r->npLogTable[(
long)
b];
113 #ifdef HAVE_GENERIC_ADD
118 s += ((long)
s >> 63) & r->npPminus1M;
120 s += ((long)
s >> 31) & r->npPminus1M;
123 d = (number)(
long)r->npExpTable[
s];
152 if ((
long)c==0L)
return c;
171 return ((
long)a) > ((long)
b);
188 if ((
long)a>(((
long)r->ch) >>1))
StringAppend(
"-%d",(
int)(((
long)r->ch)-((
long)a)));
193static void npPower (number a,
int i, number *
result,
const coeffs r)
216 return nEati((
char *)
s,
i,(
int)r->ch);
231 *a = (number)(
long)z;
243 *a =
nvDiv((number)(
long)z,(number)(
long)n,r);
246 *a =
npDiv((number)(
long)z,(number)(
long)n,r);
260 if (r->npInvTable!=
NULL)
262 omFreeSize( (
void *)r->npInvTable, r->ch*
sizeof(
unsigned short) );
266 #ifndef HAVE_GENERIC_MULT
267 if (r->npExpTable!=
NULL)
269 omFreeSize( (
void *)r->npExpTable, r->ch*
sizeof(
unsigned short) );
270 omFreeSize( (
void *)r->npLogTable, r->ch*
sizeof(
unsigned short) );
271 r->npExpTable=
NULL; r->npLogTable=
NULL;
279 return (n==
n_Zp) && (r->ch==(int)(
long)parameter);
303 snprintf(npCoeffName_buf,14,
"ZZ/%d",
cf->ch);
304 return npCoeffName_buf;
309 fprintf(d->
f_write,
"%d ",(
int)(
long)n);
317 return (number)(long)dd;
326#ifndef HAVE_GENERIC_MULT
329 return (number)(long)r->npExpTable[1];
335 return (number)mpz_fdiv_ui(
m, r->ch);
341 const int c = (int) (
long)
p;
352 r->npPminus1M = c - 1;
413 r->has_simple_Alloc=
TRUE;
414 r->has_simple_Inverse=
TRUE;
422 r->npInvTable=(
unsigned short*)
omAlloc0( r->ch*
sizeof(
unsigned short) );
424#ifndef HAVE_GENERIC_MULT
425 r->cfParameter=
npPar;
426 r->npExpTable=(
unsigned short *)
omAlloc0( r->ch*
sizeof(
unsigned short) );
427 r->npLogTable=(
unsigned short *)
omAlloc0( r->ch*
sizeof(
unsigned short) );
428 r->npExpTable[0] = 1;
429 r->npLogTable[0] = 0;
435 r->npLogTable[1] = 0;
441 r->npExpTable[
i] =(int)(((
long)
w * (long)r->npExpTable[
i-1]) % r->ch);
442 r->npLogTable[r->npExpTable[
i]] =
i;
443 if ( r->npExpTable[
i] == 1 )
452 r->npExpTable[1] = 1;
453 r->npLogTable[1] = 0;
462 r->cfExactDiv =
nvDiv;
478 if (((
long)a<0L) || ((
long)a>(
long)r->ch))
480 Print(
"wrong mod p number %ld at %s,%d\n",(
long)a,
f,
l);
493 while (
i < 0)
i+=dst_r->ch;
510 size = (*f)[0]._mp_size;
524 e=(*f)[0]._mp_exp-
size;
536 al = dest->_mp_size =
size;
538 dd = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*al);
541 nn = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*bl);
543 for (
i=bl-2;
i>=0;
i--) nn[
i] = 0;
546 ndest->_mp_alloc = ndest->_mp_size = bl;
548 in=mpz_fdiv_ui(ndest,dst_r->ch);
553 al = dest->_mp_size =
size+e;
555 dd = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*al);
557 for (
i=0;
i<e;
i++) dd[
i] = 0;
562 dest->_mp_alloc = al;
563 iz=mpz_fdiv_ui(dest,dst_r->ch);
566 iz=(long)
npDiv((number)iz,(number)in,dst_r);
577 return (number)mpz_fdiv_ui((mpz_ptr) from, dst->ch);
595 long i = (long) (((
unsigned long) from) % dst->ch);
604 return (number) (
f.intval());
662 else if ((
long)
b==0L)
683void nvPower (number a,
int i, number *
result,
const coeffs r)
virtual class for internal CanonicalForm's
Coefficient rings, fields and other domains suitable for Singular polynomials.
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
@ n_rep_gap_rat
(number), see longrat.h
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
@ n_rep_int
(int), see modulop.h
@ n_rep_gmp_float
(gmp_float), see
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
number(* nMapFunc)(number a, const coeffs src, const coeffs dst)
maps "a", which lives in src, into dst
const CanonicalForm int s
void WerrorS(const char *s)
number nlModP(number q, const coeffs, const coeffs Zp)
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
static const char * npRead(const char *s, number *a, const coeffs r)
static number npInitMPZ(mpz_t m, const coeffs r)
static void npWrite(number a, const coeffs r)
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
static void npWriteFd(number n, const ssiInfo *d, const coeffs)
BOOLEAN npInitChar(coeffs r, void *p)
static number nvDiv(number a, number b, const coeffs r)
static number npDiv(number a, number b, const coeffs r)
static number npMapP(number from, const coeffs src, const coeffs dst_r)
number nvInvers(number c, const coeffs r)
static number npPar(int, coeffs r)
static number npInvers(number c, const coeffs r)
static BOOLEAN npEqual(number a, number b, const coeffs r)
static char * npCoeffName(const coeffs cf)
static number npNeg(number c, const coeffs r)
static BOOLEAN npGreater(number a, number b, const coeffs r)
void npInpMult(number &a, number b, const coeffs r)
static BOOLEAN npIsMOne(number a, const coeffs r)
static BOOLEAN npGreaterZero(number k, const coeffs r)
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
static BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
static nMapFunc npSetMap(const coeffs src, const coeffs dst)
static number npMapZ(number from, const coeffs src, const coeffs dst)
static number npMapGMP(number from, const coeffs, const coeffs dst)
static number npReadFd(const ssiInfo *d, const coeffs)
static const char * npEati(const char *s, int *i, const coeffs r)
static void nvInpMult(number &a, number b, const coeffs r)
static number nvInversM(number c, const coeffs r)
static number npRandom(siRandProc p, number, number, const coeffs cf)
long npInt(number &n, const coeffs r)
void npKillChar(coeffs r)
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
static BOOLEAN npIsOne(number a, const coeffs)
static number npAddM(number a, number b, const coeffs r)
static number npMultM(number a, number b, const coeffs r)
static number npNegM(number a, const coeffs r)
#define npEqualM(A, B, r)
static long npInvMod(long a, const coeffs R)
static number npInversM(number c, const coeffs r)
static void npInpAddM(number &a, number b, const coeffs r)
static number npSubM(number a, number b, const coeffs r)
static number npInit(long i, const coeffs r)
static number nvMult(number a, number b, const coeffs r)
static number npMult(number a, number b, const coeffs r)
static BOOLEAN npIsZero(number a, const coeffs r)
The main handler for Singular numbers which are suitable for Singular polynomials.
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
const char *const nDivBy0
#define omFreeSize(addr, size)