Loading...
Searching...
No Matches
modulop.h File Reference
`#include "misc/auxiliary.h"`
`#include "factory/factory.h"`
`#include <NTL/config.h>`

Go to the source code of this file.

## Macros

#define | NV_OPS
#define | NV_MAX_PRIME 32749
#define | FACTORY_MAX_PRIME 536870909
#define | npEqualM(A, B, r)

## Functions

BOOLEAN | npInitChar (coeffs r, void *p)
static number | npMultM (number a, number b, const coeffs r)
static void | npInpMultM (number &a, number b, const coeffs r)
static number | npAddM (number a, number b, 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 | npNegM (number a, const coeffs r)
static BOOLEAN | npIsOne (number a, const coeffs)
static long | npInvMod (long a, const coeffs R)
static number | npInversM (number c, const coeffs r)
long | npInt (number &n, const coeffs r)

## Macro Definition Documentation

## FACTORY_MAX_PRIME

#define FACTORY_MAX_PRIME 536870909

Definition at line 38 of file modulop.h.

## npEqualM

#define npEqualM | ( |  | A,
|  |  | B,
|  |  | r )

Value:
((A)==(B))
B
b *CanonicalForm B
Definition facBivar.cc:52
A
#define A
Definition sirandom.c:24

Definition at line 259 of file modulop.h.

## NV_MAX_PRIME

#define NV_MAX_PRIME 32749

Definition at line 37 of file modulop.h.

## NV_OPS

#define NV_OPS

Definition at line 36 of file modulop.h.

## Function Documentation

## npAddM()

number npAddM | ( | number | a,
|  | number | b,
|  | const coeffs | r )

inline static

Definition at line 124 of file modulop.h.

{
unsigned long R = (unsigned long)a + (unsigned long)b;
return (number)(R >= (unsigned long)r->ch ? R - (unsigned long)r->ch : R);
}
b
CanonicalForm b
Definition cfModGcd.cc:4111
R
#define R
Definition sirandom.c:27

## npInitChar()

BOOLEAN npInitChar | ( | coeffs | r,
|  | void * | p )

Definition at line 351 of file modulop.cc.

{
assume( getCoeffType(r) == n_Zp );
const int c = (int) (long) p;
assume( c > 0 );
int i, w;
r->is_field=TRUE;
r->is_domain=TRUE;
r->rep=n_rep_int;
r->ch = c;
r->npPminus1M = c /*r->ch*/ - 1;
//r->cfInitChar=npInitChar;
r->cfKillChar=npKillChar;
r->nCoeffIsEqual=npCoeffsEqual;
r->cfCoeffName=npCoeffName;
r->cfMult = npMult;
r->cfInpMult = npInpMult;
r->cfSub = npSubM;
r->cfAdd = npAddM;
r->cfInpAdd = npInpAddM;
r->cfDiv = npDiv;
r->cfInit = npInit;
//r->cfSize = ndSize;
r->cfInt = npInt;
r->cfInitMPZ = npInitMPZ;
//r->cfDivComp = NULL; // only for ring stuff
//r->cfIsUnit = NULL; // only for ring stuff
//r->cfGetUnit = NULL; // only for ring stuff
//r->cfExtGcd = NULL; // only for ring stuff
// r->cfDivBy = NULL; // only for ring stuff
r->cfInpNeg = npNeg;
r->cfInvers= npInvers;
//r->cfCopy = ndCopy;
//r->cfRePart = ndCopy;
//r->cfImPart = ndReturn0;
r->cfWriteLong = npWrite;
r->cfRead = npRead;
//r->cfNormalize=ndNormalize;
r->cfGreater = npGreater;
r->cfEqual = npEqual;
r->cfIsZero = npIsZero;
r->cfIsOne = npIsOne;
r->cfIsMOne = npIsMOne;
r->cfGreaterZero = npGreaterZero;
//r->cfPower = npPower;
//r->cfGetDenom = ndGetDenom;
//r->cfGetNumerator = ndGetNumerator;
//r->cfGcd = ndGcd;
//r->cfLcm = ndGcd;
//r->cfDelete= ndDelete;
r->cfSetMap = npSetMap;
//r->cfName = ndName;
//r->cfInpMult=ndInpMult;
r->convSingNFactoryN=npConvSingNFactoryN;
r->convFactoryNSingN=npConvFactoryNSingN;
r->cfRandom=npRandom;
#ifdef LDEBUG
// debug stuff
r->cfDBTest=npDBTest;
#endif
// io via ssi
r->cfWriteFd=npWriteFd;
r->cfWriteFd_S=npWriteFd_S;
r->cfReadFd=npReadFd;
r->cfReadFd_S=npReadFd_S;
// the variables:
r->type = n_Zp;
r->has_simple_Alloc=TRUE;
r->has_simple_Inverse=TRUE;
// the tables
#ifdef NV_OPS
if (r->ch <=NV_MAX_PRIME)
#endif
{
#ifdef HAVE_INVTABLE
r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
#endif
#ifndef HAVE_GENERIC_MULT
r->cfParameter=npPar; /* Singular.jl */
r->npExpTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
r->npLogTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
r->npExpTable[0] = 1;
r->npLogTable[0] = 0;
if (r->ch > 2)
{
w = 1;
loop
{
r->npLogTable[1] = 0;
w++;
i = 0;
loop
{
i++;
r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
r->npLogTable[r->npExpTable[i]] = i;
if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
break;
}
if (i == r->ch - 1)
break;
}
}
else
{
r->npExpTable[1] = 1;
r->npLogTable[1] = 0;
}
#endif
}
#ifdef NV_OPS
else /*if (c>NV_MAX_PRIME)*/
{
r->cfMult = nvMult;
r->cfDiv = nvDiv;
r->cfExactDiv = nvDiv;
r->cfInvers = nvInvers;
r->cfInpMult = nvInpMult;
//r->cfPower= nvPower;
//if (c>FACTORY_MAX_PRIME) // factory will catch this error
//{
// r->convSingNFactoryN=ndConvSingNFactoryN;
//}
}
#endif
return FALSE;
}
TRUE
#define TRUE
Definition auxiliary.h:101
FALSE
#define FALSE
Definition auxiliary.h:97
i
int i
Definition cfEzgcd.cc:132
p
int p
Definition cfModGcd.cc:4086
n_Zp
@ n_Zp
\F{p < 2^31}
Definition coeffs.h:29
getCoeffType
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:431
n_rep_int
@ n_rep_int
(int), see modulop.h
Definition coeffs.h:117
w
const CanonicalForm & w
Definition facAbsFact.cc:51
assume
#define assume(x)
Definition mod2.h:389
npCoeffsEqual
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition modulop.cc:276
npRead
static const char * npRead(const char *s, number *a, const coeffs r)
Definition modulop.cc:219
npInitMPZ
static number npInitMPZ(mpz_t m, const coeffs r)
Definition modulop.cc:346
npWrite
static void npWrite(number a, const coeffs r)
Definition modulop.cc:184
npReadFd_S
static number npReadFd_S(char **s, const coeffs)
Definition modulop.cc:325
npConvSingNFactoryN
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition modulop.cc:281
npWriteFd
static void npWriteFd(number n, const ssiInfo *d, const coeffs)
Definition modulop.cc:307
nvDiv
static number nvDiv(number a, number b, const coeffs r)
Definition modulop.cc:667
npDiv
static number npDiv(number a, number b, const coeffs r)
Definition modulop.cc:98
nvInvers
number nvInvers(number c, const coeffs r)
Definition modulop.cc:682
npPar
static number npPar(int, coeffs r)
Definition modulop.cc:340
npInvers
static number npInvers(number c, const coeffs r)
Definition modulop.cc:133
npEqual
static BOOLEAN npEqual(number a, number b, const coeffs r)
Definition modulop.cc:174
npCoeffName
static char * npCoeffName(const coeffs cf)
Definition modulop.cc:300
npNeg
static number npNeg(number c, const coeffs r)
Definition modulop.cc:148
npGreater
static BOOLEAN npGreater(number a, number b, const coeffs r)
Definition modulop.cc:165
npInpMult
void npInpMult(number &a, number b, const coeffs r)
Definition modulop.cc:68
npIsMOne
static BOOLEAN npIsMOne(number a, const coeffs r)
Definition modulop.cc:91
npGreaterZero
static BOOLEAN npGreaterZero(number k, const coeffs r)
Definition modulop.cc:51
npDBTest
static BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition modulop.cc:489
npSetMap
static nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition modulop.cc:618
npReadFd
static number npReadFd(const ssiInfo *d, const coeffs)
Definition modulop.cc:317
npWriteFd_S
static void npWriteFd_S(number n, const coeffs)
Definition modulop.cc:312
nvInpMult
static void nvInpMult(number &a, number b, const coeffs r)
Definition modulop.cc:655
npRandom
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition modulop.cc:333
npInt
long npInt(number &n, const coeffs r)
Definition modulop.cc:83
npKillChar
void npKillChar(coeffs r)
Definition modulop.cc:257
npConvFactoryNSingN
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition modulop.cc:287
npIsOne
static BOOLEAN npIsOne(number a, const coeffs)
Definition modulop.h:179
npAddM
static number npAddM(number a, number b, const coeffs r)
Definition modulop.h:124
NV_MAX_PRIME
#define NV_MAX_PRIME
Definition modulop.h:37
npInpAddM
static void npInpAddM(number &a, number b, const coeffs r)
Definition modulop.h:129
npSubM
static number npSubM(number a, number b, const coeffs r)
Definition modulop.h:134
npInit
static number npInit(long i, const coeffs r)
Definition modulop_inl.h:27
nvMult
static number nvMult(number a, number b, const coeffs r)
Definition modulop_inl.h:50
npMult
static number npMult(number a, number b, const coeffs r)
Definition modulop_inl.h:12
npIsZero
static BOOLEAN npIsZero(number a, const coeffs r)
Definition modulop_inl.h:38
omAlloc0
#define omAlloc0(size)
Definition omAllocDecl.h:211
loop
#define loop
Definition structs.h:71

## npInpAddM()

void npInpAddM | ( | number & | a,
|  | number | b,
|  | const coeffs | r )

inline static

Definition at line 129 of file modulop.h.

{
unsigned long R = (unsigned long)a + (unsigned long)b;
a=(number)(R >= (unsigned long)r->ch ? R - (unsigned long)r->ch : R);
}

## npInpMultM()

void npInpMultM | ( | number & | a,
|  | number | b,
|  | const coeffs | r )

inline static

Definition at line 86 of file modulop.h.

{
long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
#ifdef HAVE_GENERIC_ADD
if (x>=r->npPminus1M) x-=r->npPminus1M;
#else
x-=r->npPminus1M;
#if SIZEOF_LONG == 8
x += (x >> 63) & r->npPminus1M;
#else
x += (x >> 31) & r->npPminus1M;
#endif
#endif
a=(number)(long)r->npExpTable[x];
}
x
Variable x
Definition cfModGcd.cc:4090

## npInt()

long npInt | ( | number & | n,
|  | const coeffs | r )

Definition at line 83 of file modulop.cc.

{
n_Test(n, r);
if ((long)n > (((long)r->ch) >>1)) return ((long)n -((long)r->ch));
else return ((long)n);
}
n_Test
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r).
Definition coeffs.h:715

## npInversM()

number npInversM | ( | number | c,
|  | const coeffs | r )

inline static

Definition at line 223 of file modulop.h.

{
n_Test(c, r);
#ifndef HAVE_GENERIC_MULT
#ifndef HAVE_INVTABLE
number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
#else
long inv=(long)r->npInvTable[(long)c];
if (inv==0)
{
inv = (long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
r->npInvTable[(long)c]=inv;
}
number d = (number)inv;
#endif
#else
#ifdef HAVE_INVTABLE
long inv=(long)r->npInvTable[(long)c];
if (inv==0)
{
inv=npInvMod((long)c,r);
r->npInvTable[(long)c]=inv;
}
#else
long inv=npInvMod((long)c,r);
#endif
number d = (number)inv;
#endif
n_Test(d, r);
return d;
}
npInvMod
static long npInvMod(long a, const coeffs R)
Definition modulop.h:184

## npInvMod()

long npInvMod | ( | long | a,
|  | const coeffs | R )

inline static

Definition at line 184 of file modulop.h.

{
long s;
long u, v, u0, u1, u2, q, r;
assume(a>0);
u1=1; u2=0;
u = a; v = R->ch;
do
{
q = u / v;
//r = u % v;
r = u - q*v;
u = v;
v = r;
u0 = u2;
u2 = u1 - q*u2;
u1 = u0;
} while (v != 0);
assume(u==1);
s = u1;
#ifdef HAVE_GENERIC_ADD
if (s < 0)
return s + R->ch;
else
return s;
#else
#if SIZEOF_LONG == 8
s += (s >> 63) & R->ch;
#else
s += (s >> 31) & R->ch;
#endif
return s;
#endif
}
s
const CanonicalForm int s
Definition facAbsFact.cc:51
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39

## npIsOne()

BOOLEAN npIsOne | ( | number | a,
|  | const coeffs | )

inline static

Definition at line 179 of file modulop.h.

{
return 1 == (long)a;
}

## npMultM()

number npMultM | ( | number | a,
|  | number | b,
|  | const coeffs | r )

inline static

Definition at line 71 of file modulop.h.

{
long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
#ifdef HAVE_GENERIC_ADD
if (x>=r->npPminus1M) x-=r->npPminus1M;
#else
x-=r->npPminus1M;
#if SIZEOF_LONG == 8
x += (x >> 63) & r->npPminus1M;
#else
x += (x >> 31) & r->npPminus1M;
#endif
#endif
return (number)(long)r->npExpTable[x];
}

## npNegM()

number npNegM | ( | number | a,
|  | const coeffs | r )

inline static

Definition at line 174 of file modulop.h.

{
return (number)((long)(r->ch)-(long)(a));
}

## npSubM()

number npSubM | ( | number | a,
|  | number | b,
|  | const coeffs | r )

inline static

Definition at line 134 of file modulop.h.

{
return (number)((long)a<(long)b ?
r->ch-(long)b+(long)a : (long)a-(long)b);
}