My Project
Loading...
Searching...
No Matches
Macros | Functions
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)   ((A)==(B))
 

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,
 
)    ((A)==(B))

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:4103
#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 #ifdef HAVE_RINGS
370 //r->cfDivComp = NULL; // only for ring stuff
371 //r->cfIsUnit = NULL; // only for ring stuff
372 //r->cfGetUnit = NULL; // only for ring stuff
373 //r->cfExtGcd = NULL; // only for ring stuff
374 // r->cfDivBy = NULL; // only for ring stuff
375 #endif
376 r->cfInpNeg = npNeg;
377 r->cfInvers= npInvers;
378 //r->cfCopy = ndCopy;
379 //r->cfRePart = ndCopy;
380 //r->cfImPart = ndReturn0;
381 r->cfWriteLong = npWrite;
382 r->cfRead = npRead;
383 //r->cfNormalize=ndNormalize;
384 r->cfGreater = npGreater;
385 r->cfEqual = npEqual;
386 r->cfIsZero = npIsZero;
387 r->cfIsOne = npIsOne;
388 r->cfIsMOne = npIsMOne;
389 r->cfGreaterZero = npGreaterZero;
390 //r->cfPower = npPower;
391 //r->cfGetDenom = ndGetDenom;
392 //r->cfGetNumerator = ndGetNumerator;
393 //r->cfGcd = ndGcd;
394 //r->cfLcm = ndGcd;
395 //r->cfDelete= ndDelete;
396 r->cfSetMap = npSetMap;
397 //r->cfName = ndName;
398 //r->cfInpMult=ndInpMult;
399 r->convSingNFactoryN=npConvSingNFactoryN;
400 r->convFactoryNSingN=npConvFactoryNSingN;
401 r->cfRandom=npRandom;
402#ifdef LDEBUG
403 // debug stuff
404 r->cfDBTest=npDBTest;
405#endif
406
407 // io via ssi
408 r->cfWriteFd=npWriteFd;
409 r->cfReadFd=npReadFd;
410
411 // the variables:
412 r->type = n_Zp;
413 r->has_simple_Alloc=TRUE;
414 r->has_simple_Inverse=TRUE;
415
416 // the tables
417#ifdef NV_OPS
418 if (r->ch <=NV_MAX_PRIME)
419#endif
420 {
421#ifdef HAVE_INVTABLE
422 r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
423#endif
424#ifndef HAVE_GENERIC_MULT
425 r->cfParameter=npPar; /* Singular.jl */
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;
430 if (r->ch > 2)
431 {
432 w = 1;
433 loop
434 {
435 r->npLogTable[1] = 0;
436 w++;
437 i = 0;
438 loop
439 {
440 i++;
441 r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
442 r->npLogTable[r->npExpTable[i]] = i;
443 if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
444 break;
445 }
446 if (i == r->ch - 1)
447 break;
448 }
449 }
450 else
451 {
452 r->npExpTable[1] = 1;
453 r->npLogTable[1] = 0;
454 }
455#endif
456 }
457#ifdef NV_OPS
458 else /*if (c>NV_MAX_PRIME)*/
459 {
460 r->cfMult = nvMult;
461 r->cfDiv = nvDiv;
462 r->cfExactDiv = nvDiv;
463 r->cfInvers = nvInvers;
464 r->cfInpMult = nvInpMult;
465 //r->cfPower= nvPower;
466 //if (c>FACTORY_MAX_PRIME) // factory will catch this error
467 //{
468 // r->convSingNFactoryN=ndConvSingNFactoryN;
469 //}
470 }
471#endif
472 return FALSE;
473}
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
int i
Definition: cfEzgcd.cc:132
int p
Definition: cfModGcd.cc:4078
@ 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:422
@ n_rep_int
(int), see modulop.h
Definition: coeffs.h:110
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:658
static number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:98
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:673
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:476
static nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:607
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:646
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)
Definition: omAllocDecl.h:211
#define loop
Definition: structs.h:75

◆ 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:4082

◆ 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:709

◆ 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}