10#include "factory/factory.h"
57 int h = (int)((
long)
k);
58 return ((
int)
h !=0) && (
h <= (r->ch>>1));
75 if (((
long)a == 0) || ((
long)
b == 0))
89 if ((
long)n > (((
long)r->ch) >>1))
return ((
long)n -((
long)r->ch));
90 else return ((
long)n);
97 return ((r->npPminus1M == (
long)a) &&(1L!=(
long)a));
110 if ((
long)a==0)
return (number)0L;
113#ifndef HAVE_GENERIC_MULT
114 int s = r->npLogTable[(long)a] - r->npLogTable[(
long)
b];
115 #ifdef HAVE_GENERIC_ADD
120 s += ((long)
s >> 63) & r->npPminus1M;
122 s += ((long)
s >> 31) & r->npPminus1M;
125 d = (number)(
long)r->npExpTable[
s];
154 if ((
long)c==0L)
return c;
173 return ((
long)a) > ((long)
b);
190 if ((
long)a>(((
long)r->ch) >>1))
StringAppend(
"-%d",(
int)(((
long)r->ch)-((
long)a)));
218 return nEati((
char *)
s,
i,(
int)r->ch);
233 *a = (number)(
long)z;
245 *a =
nvDiv((number)(
long)z,(number)(
long)n,r);
248 *a =
npDiv((number)(
long)z,(number)(
long)n,r);
262 if (r->npInvTable!=
NULL)
264 omFreeSize( (
void *)r->npInvTable, r->ch*
sizeof(
unsigned short) );
268 #ifndef HAVE_GENERIC_MULT
269 if (r->npExpTable!=
NULL)
271 omFreeSize( (
void *)r->npExpTable, r->ch*
sizeof(
unsigned short) );
272 omFreeSize( (
void *)r->npLogTable, r->ch*
sizeof(
unsigned short) );
273 r->npExpTable=
NULL; r->npLogTable=
NULL;
281 return (n==
n_Zp) && (r->ch==(int)(
long)parameter);
305 snprintf(npCoeffName_buf,14,
"ZZ/%d",
cf->ch);
306 return npCoeffName_buf;
311 fprintf(d->
f_write,
"%d ",(
int)(
long)n);
319 return (number)(long)dd;
328#ifndef HAVE_GENERIC_MULT
331 return (number)(long)r->npExpTable[1];
337 return (number)mpz_fdiv_ui(
m, r->ch);
343 const int c = (int) (
long)
p;
354 r->npPminus1M = c - 1;
415 r->has_simple_Alloc=
TRUE;
416 r->has_simple_Inverse=
TRUE;
424 r->npInvTable=(
unsigned short*)
omAlloc0( r->ch*
sizeof(
unsigned short) );
426#ifndef HAVE_GENERIC_MULT
427 r->cfParameter=
npPar;
428 r->npExpTable=(
unsigned short *)
omAlloc0( r->ch*
sizeof(
unsigned short) );
429 r->npLogTable=(
unsigned short *)
omAlloc0( r->ch*
sizeof(
unsigned short) );
430 r->npExpTable[0] = 1;
431 r->npLogTable[0] = 0;
437 r->npLogTable[1] = 0;
443 r->npExpTable[
i] =(int)(((
long)
w * (long)r->npExpTable[
i-1]) % r->ch);
444 r->npLogTable[r->npExpTable[
i]] =
i;
445 if ( r->npExpTable[
i] == 1 )
454 r->npExpTable[1] = 1;
455 r->npLogTable[1] = 0;
464 r->cfExactDiv =
nvDiv;
480 if (((
long)a<0L) || ((
long)a>(
long)r->ch))
482 Print(
"wrong mod p number %ld at %s,%d\n",(
long)a,
f,
l);
495 while (
i < 0)
i+=dst_r->ch;
512 size = (*f)[0]._mp_size;
526 e=(*f)[0]._mp_exp-
size;
538 al = dest->_mp_size =
size;
540 dd = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*al);
543 nn = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*bl);
545 for (
i=bl-2;
i>=0;
i--) nn[
i] = 0;
548 ndest->_mp_alloc = ndest->_mp_size = bl;
550 in=mpz_fdiv_ui(ndest,dst_r->ch);
555 al = dest->_mp_size =
size+e;
557 dd = (mp_ptr)
omAlloc(
sizeof(mp_limb_t)*al);
559 for (
i=0;
i<e;
i++) dd[
i] = 0;
564 dest->_mp_alloc = al;
565 iz=mpz_fdiv_ui(dest,dst_r->ch);
568 iz=(long)
npDiv((number)iz,(number)in,dst_r);
579 return (number)mpz_fdiv_ui((mpz_ptr) from, dst->ch);
597 long i = (long) (((
unsigned long) from) % dst->ch);
606 return (number) (
f.intval());
664 else if ((
long)
b==0L)
685void 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)
void nvInpMult(number &a, number b, const coeffs r)
number npInvers(number c, const coeffs r)
number nvDiv(number a, number b, const coeffs r)
void npPower(number a, int i, number *result, const coeffs r)
static number npInitMPZ(mpz_t m, const coeffs r)
BOOLEAN npIsMOne(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)
number npNeg(number c, const coeffs r)
static number npMapP(number from, const coeffs src, const coeffs dst_r)
nMapFunc npSetMap(const coeffs src, const coeffs dst)
const char * npRead(const char *s, number *a, const coeffs r)
number nvInvers(number c, const coeffs r)
static number npPar(int, coeffs r)
static char * npCoeffName(const coeffs cf)
void npInpMult(number &a, number b, const coeffs r)
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
void npWrite(number a, const coeffs r)
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)
BOOLEAN npGreaterZero(number k, const coeffs r)
BOOLEAN npEqual(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)
number npDiv(number a, number b, 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)
BOOLEAN npGreater(number a, number b, 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)