My Project
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 *CanonicalForm B
Definition facBivar.cc:52
#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()

static number npAddM ( number a,
number b,
const coeffs r )
inlinestatic

Definition at line 124 of file modulop.h.

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

◆ npInitChar()

BOOLEAN npInitChar ( coeffs r,
void * p )

Definition at line 338 of file modulop.cc.

339{
340 assume( getCoeffType(r) == n_Zp );
341 const int c = (int) (long) p;
342
343 assume( c > 0 );
344
345 int i, w;
346
347 r->is_field=TRUE;
348 r->is_domain=TRUE;
349 r->rep=n_rep_int;
350
351 r->ch = c;
352 r->npPminus1M = c /*r->ch*/ - 1;
353
354 //r->cfInitChar=npInitChar;
355 r->cfKillChar=npKillChar;
356 r->nCoeffIsEqual=npCoeffsEqual;
357 r->cfCoeffName=npCoeffName;
358
359 r->cfMult = npMult;
360 r->cfInpMult = npInpMult;
361 r->cfSub = npSubM;
362 r->cfAdd = npAddM;
363 r->cfInpAdd = npInpAddM;
364 r->cfDiv = npDiv;
365 r->cfInit = npInit;
366 //r->cfSize = ndSize;
367 r->cfInt = npInt;
368 r->cfInitMPZ = npInitMPZ;
369 //r->cfDivComp = NULL; // only for ring stuff
370 //r->cfIsUnit = NULL; // only for ring stuff
371 //r->cfGetUnit = NULL; // only for ring stuff
372 //r->cfExtGcd = NULL; // only for ring stuff
373 // r->cfDivBy = NULL; // only for ring stuff
374 r->cfInpNeg = npNeg;
375 r->cfInvers= npInvers;
376 //r->cfCopy = ndCopy;
377 //r->cfRePart = ndCopy;
378 //r->cfImPart = ndReturn0;
379 r->cfWriteLong = npWrite;
380 r->cfRead = npRead;
381 //r->cfNormalize=ndNormalize;
382 r->cfGreater = npGreater;
383 r->cfEqual = npEqual;
384 r->cfIsZero = npIsZero;
385 r->cfIsOne = npIsOne;
386 r->cfIsMOne = npIsMOne;
387 r->cfGreaterZero = npGreaterZero;
388 //r->cfPower = npPower;
389 //r->cfGetDenom = ndGetDenom;
390 //r->cfGetNumerator = ndGetNumerator;
391 //r->cfGcd = ndGcd;
392 //r->cfLcm = ndGcd;
393 //r->cfDelete= ndDelete;
394 r->cfSetMap = npSetMap;
395 //r->cfName = ndName;
396 //r->cfInpMult=ndInpMult;
397 r->convSingNFactoryN=npConvSingNFactoryN;
398 r->convFactoryNSingN=npConvFactoryNSingN;
399 r->cfRandom=npRandom;
400#ifdef LDEBUG
401 // debug stuff
402 r->cfDBTest=npDBTest;
403#endif
404
405 // io via ssi
406 r->cfWriteFd=npWriteFd;
407 r->cfReadFd=npReadFd;
408
409 // the variables:
410 r->type = n_Zp;
411 r->has_simple_Alloc=TRUE;
412 r->has_simple_Inverse=TRUE;
413
414 // the tables
415#ifdef NV_OPS
416 if (r->ch <=NV_MAX_PRIME)
417#endif
418 {
419#ifdef HAVE_INVTABLE
420 r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
421#endif
422#ifndef HAVE_GENERIC_MULT
423 r->cfParameter=npPar; /* Singular.jl */
424 r->npExpTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
425 r->npLogTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
426 r->npExpTable[0] = 1;
427 r->npLogTable[0] = 0;
428 if (r->ch > 2)
429 {
430 w = 1;
431 loop
432 {
433 r->npLogTable[1] = 0;
434 w++;
435 i = 0;
436 loop
437 {
438 i++;
439 r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
440 r->npLogTable[r->npExpTable[i]] = i;
441 if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
442 break;
443 }
444 if (i == r->ch - 1)
445 break;
446 }
447 }
448 else
449 {
450 r->npExpTable[1] = 1;
451 r->npLogTable[1] = 0;
452 }
453#endif
454 }
455#ifdef NV_OPS
456 else /*if (c>NV_MAX_PRIME)*/
457 {
458 r->cfMult = nvMult;
459 r->cfDiv = nvDiv;
460 r->cfExactDiv = nvDiv;
461 r->cfInvers = nvInvers;
462 r->cfInpMult = nvInpMult;
463 //r->cfPower= nvPower;
464 //if (c>FACTORY_MAX_PRIME) // factory will catch this error
465 //{
466 // r->convSingNFactoryN=ndConvSingNFactoryN;
467 //}
468 }
469#endif
470 return FALSE;
471}
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
int i
Definition cfEzgcd.cc:132
int p
Definition cfModGcd.cc:4086
@ n_Zp
\F{p < 2^31}
Definition coeffs.h:29
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:429
@ n_rep_int
(int), see modulop.h
Definition coeffs.h:117
const CanonicalForm & w
Definition facAbsFact.cc:51
#define assume(x)
Definition mod2.h:389
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition modulop.cc:276
static const char * npRead(const char *s, number *a, const coeffs r)
Definition modulop.cc:219
static number npInitMPZ(mpz_t m, const coeffs r)
Definition modulop.cc:333
static void npWrite(number a, const coeffs r)
Definition modulop.cc:184
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition modulop.cc:281
static void npWriteFd(number n, const ssiInfo *d, const coeffs)
Definition modulop.cc:307
static number nvDiv(number a, number b, const coeffs r)
Definition modulop.cc:652
static number npDiv(number a, number b, const coeffs r)
Definition modulop.cc:98
number nvInvers(number c, const coeffs r)
Definition modulop.cc:667
static number npPar(int, coeffs r)
Definition modulop.cc:327
static number npInvers(number c, const coeffs r)
Definition modulop.cc:133
static BOOLEAN npEqual(number a, number b, const coeffs r)
Definition modulop.cc:174
static char * npCoeffName(const coeffs cf)
Definition modulop.cc:300
static number npNeg(number c, const coeffs r)
Definition modulop.cc:148
static BOOLEAN npGreater(number a, number b, const coeffs r)
Definition modulop.cc:165
void npInpMult(number &a, number b, const coeffs r)
Definition modulop.cc:68
static BOOLEAN npIsMOne(number a, const coeffs r)
Definition modulop.cc:91
static BOOLEAN npGreaterZero(number k, const coeffs r)
Definition modulop.cc:51
static BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition modulop.cc:474
static nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition modulop.cc:603
static number npReadFd(const ssiInfo *d, const coeffs)
Definition modulop.cc:312
static void nvInpMult(number &a, number b, const coeffs r)
Definition modulop.cc:640
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition modulop.cc:320
long npInt(number &n, const coeffs r)
Definition modulop.cc:83
void npKillChar(coeffs r)
Definition modulop.cc:257
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition modulop.cc:287
static BOOLEAN npIsOne(number a, const coeffs)
Definition modulop.h:179
static number npAddM(number a, number b, const coeffs r)
Definition modulop.h:124
#define NV_MAX_PRIME
Definition modulop.h:37
static void npInpAddM(number &a, number b, const coeffs r)
Definition modulop.h:129
static number npSubM(number a, number b, const coeffs r)
Definition modulop.h:134
static number npInit(long i, const coeffs r)
Definition modulop_inl.h:27
static number nvMult(number a, number b, const coeffs r)
Definition modulop_inl.h:50
static number npMult(number a, number b, const coeffs r)
Definition modulop_inl.h:12
static BOOLEAN npIsZero(number a, const coeffs r)
Definition modulop_inl.h:38
#define omAlloc0(size)
#define loop
Definition structs.h:71

◆ npInpAddM()

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

Definition at line 129 of file modulop.h.

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

◆ npInpMultM()

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

Definition at line 86 of file modulop.h.

87{
88 long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
89 #ifdef HAVE_GENERIC_ADD
90 if (x>=r->npPminus1M) x-=r->npPminus1M;
91 #else
92 x-=r->npPminus1M;
93 #if SIZEOF_LONG == 8
94 x += (x >> 63) & r->npPminus1M;
95 #else
96 x += (x >> 31) & r->npPminus1M;
97 #endif
98 #endif
99 a=(number)(long)r->npExpTable[x];
100}
Variable x
Definition cfModGcd.cc:4090

◆ npInt()

long npInt ( number & n,
const coeffs r )

Definition at line 83 of file modulop.cc.

84{
85 n_Test(n, r);
86
87 if ((long)n > (((long)r->ch) >>1)) return ((long)n -((long)r->ch));
88 else return ((long)n);
89}
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition coeffs.h:713

◆ npInversM()

static number npInversM ( number c,
const coeffs r )
inlinestatic

Definition at line 223 of file modulop.h.

224{
225 n_Test(c, r);
226#ifndef HAVE_GENERIC_MULT
227 #ifndef HAVE_INVTABLE
228 number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
229 #else
230 long inv=(long)r->npInvTable[(long)c];
231 if (inv==0)
232 {
233 inv = (long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
234 r->npInvTable[(long)c]=inv;
235 }
236 number d = (number)inv;
237 #endif
238#else
239 #ifdef HAVE_INVTABLE
240 long inv=(long)r->npInvTable[(long)c];
241 if (inv==0)
242 {
243 inv=npInvMod((long)c,r);
244 r->npInvTable[(long)c]=inv;
245 }
246 #else
247 long inv=npInvMod((long)c,r);
248 #endif
249 number d = (number)inv;
250#endif
251 n_Test(d, r);
252 return d;
253}
static long npInvMod(long a, const coeffs R)
Definition modulop.h:184

◆ npInvMod()

static long npInvMod ( long a,
const coeffs R )
inlinestatic

Definition at line 184 of file modulop.h.

185{
186 long s;
187
188 long u, v, u0, u1, u2, q, r;
189
190 assume(a>0);
191 u1=1; u2=0;
192 u = a; v = R->ch;
193
194 do
195 {
196 q = u / v;
197 //r = u % v;
198 r = u - q*v;
199 u = v;
200 v = r;
201 u0 = u2;
202 u2 = u1 - q*u2;
203 u1 = u0;
204 } while (v != 0);
205
206 assume(u==1);
207 s = u1;
208#ifdef HAVE_GENERIC_ADD
209 if (s < 0)
210 return s + R->ch;
211 else
212 return s;
213#else
214 #if SIZEOF_LONG == 8
215 s += (s >> 63) & R->ch;
216 #else
217 s += (s >> 31) & R->ch;
218 #endif
219 return s;
220#endif
221}
const CanonicalForm int s
Definition facAbsFact.cc:51
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39

◆ npIsOne()

static BOOLEAN npIsOne ( number a,
const coeffs  )
inlinestatic

Definition at line 179 of file modulop.h.

180{
181 return 1 == (long)a;
182}

◆ npMultM()

static number npMultM ( number a,
number b,
const coeffs r )
inlinestatic

Definition at line 71 of file modulop.h.

72{
73 long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
74 #ifdef HAVE_GENERIC_ADD
75 if (x>=r->npPminus1M) x-=r->npPminus1M;
76 #else
77 x-=r->npPminus1M;
78 #if SIZEOF_LONG == 8
79 x += (x >> 63) & r->npPminus1M;
80 #else
81 x += (x >> 31) & r->npPminus1M;
82 #endif
83 #endif
84 return (number)(long)r->npExpTable[x];
85}

◆ npNegM()

static number npNegM ( number a,
const coeffs r )
inlinestatic

Definition at line 174 of file modulop.h.

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

◆ npSubM()

static number npSubM ( number a,
number b,
const coeffs r )
inlinestatic

Definition at line 134 of file modulop.h.

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