My Project  debian-1:4.1.1-p2+ds-4build1
Macros | Functions
modulop.h File Reference
#include "misc/auxiliary.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 npIsZeroM (number a, const coeffs)
 
long npInt (number &n, const coeffs r)
 
nMapFunc npSetMap (const coeffs src, const coeffs dst)
 

Macro Definition Documentation

◆ FACTORY_MAX_PRIME

#define FACTORY_MAX_PRIME   536870909

Definition at line 29 of file modulop.h.

◆ npEqualM

#define npEqualM (   A,
  B,
 
)    ((A)==(B))

Definition at line 186 of file modulop.h.

◆ NV_MAX_PRIME

#define NV_MAX_PRIME   32749

Definition at line 28 of file modulop.h.

◆ NV_OPS

#define NV_OPS

Definition at line 27 of file modulop.h.

Function Documentation

◆ npAddM()

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

Definition at line 115 of file modulop.h.

117 {
118  unsigned long R = (unsigned long)a + (unsigned long)b;
119  return (number)(R >= r->ch ? R - r->ch : R);

◆ npInitChar()

BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 487 of file modulop.cc.

489 {
490  assume( getCoeffType(r) == n_Zp );
491  const int c = (int) (long) p;
492 
493  assume( c > 0 );
494 
495  int i, w;
496 
497  r->is_field=TRUE;
498  r->is_domain=TRUE;
499  r->rep=n_rep_int;
500 
501  r->ch = c;
502  r->npPminus1M = c /*r->ch*/ - 1;
503 
504  //r->cfInitChar=npInitChar;
505  r->cfKillChar=npKillChar;
506  r->nCoeffIsEqual=npCoeffsEqual;
507  r->cfCoeffString=npCoeffString;
508  r->cfCoeffName=npCoeffName;
509  r->cfCoeffWrite=npCoeffWrite;
510 
511  r->cfMult = npMult;
512  r->cfInpMult = npInpMult;
513  r->cfSub = npSubM;
514  r->cfAdd = npAddM;
515  r->cfInpAdd = npInpAddM;
516  r->cfDiv = npDiv;
517  r->cfInit = npInit;
518  //r->cfSize = ndSize;
519  r->cfInt = npInt;
520  #ifdef HAVE_RINGS
521  //r->cfDivComp = NULL; // only for ring stuff
522  //r->cfIsUnit = NULL; // only for ring stuff
523  //r->cfGetUnit = NULL; // only for ring stuff
524  //r->cfExtGcd = NULL; // only for ring stuff
525  // r->cfDivBy = NULL; // only for ring stuff
526  #endif
527  r->cfInpNeg = npNeg;
528  r->cfInvers= npInvers;
529  //r->cfCopy = ndCopy;
530  //r->cfRePart = ndCopy;
531  //r->cfImPart = ndReturn0;
532  r->cfWriteLong = npWrite;
533  r->cfRead = npRead;
534  //r->cfNormalize=ndNormalize;
535  r->cfGreater = npGreater;
536  r->cfEqual = npEqual;
537  r->cfIsZero = npIsZero;
538  r->cfIsOne = npIsOne;
539  r->cfIsMOne = npIsMOne;
540  r->cfGreaterZero = npGreaterZero;
541  //r->cfPower = npPower;
542  //r->cfGetDenom = ndGetDenom;
543  //r->cfGetNumerator = ndGetNumerator;
544  //r->cfGcd = ndGcd;
545  //r->cfLcm = ndGcd;
546  //r->cfDelete= ndDelete;
547  r->cfSetMap = npSetMap;
548  //r->cfName = ndName;
549  //r->cfInpMult=ndInpMult;
550  r->convSingNFactoryN=npConvSingNFactoryN;
551  r->convFactoryNSingN=npConvFactoryNSingN;
552  r->cfRandom=npRandom;
553 #ifdef LDEBUG
554  // debug stuff
555  r->cfDBTest=npDBTest;
556 #endif
557 
558  // io via ssi
559  r->cfWriteFd=npWriteFd;
560  r->cfReadFd=npReadFd;
561 
562  // the variables:
563  r->type = n_Zp;
564  r->has_simple_Alloc=TRUE;
565  r->has_simple_Inverse=TRUE;
566 
567  // the tables
568 #ifdef NV_OPS
569  if (r->ch <=NV_MAX_PRIME)
570 #endif
571  {
572 #ifdef HAVE_INVTABLE
573  r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
574 #endif
575 #ifndef HAVE_GENERIC_MULT
576  r->npExpTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
577  r->npLogTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
578  r->npExpTable[0] = 1;
579  r->npLogTable[0] = 0;
580  if (r->ch > 2)
581  {
582  w = 1;
583  loop
584  {
585  r->npLogTable[1] = 0;
586  w++;
587  i = 0;
588  loop
589  {
590  i++;
591  r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
592  r->npLogTable[r->npExpTable[i]] = i;
593  if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
594  break;
595  }
596  if (i == r->ch - 1)
597  break;
598  }
599  }
600  else
601  {
602  r->npExpTable[1] = 1;
603  r->npLogTable[1] = 0;
604  }
605 #endif
606  }
607 #ifdef NV_OPS
608  else /*if (c>NV_MAX_PRIME)*/
609  {
610  r->cfMult = nvMult;
611  r->cfDiv = nvDiv;
612  r->cfExactDiv = nvDiv;
613  r->cfInvers = nvInvers;
614  r->cfInpMult = nvInpMult;
615  //r->cfPower= nvPower;
616  //if (c>FACTORY_MAX_PRIME) // factory will catch this error
617  //{
618  // r->convSingNFactoryN=ndConvSingNFactoryN;
619  //}
620  }
621 #endif
622  return FALSE;

◆ npInpAddM()

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

Definition at line 120 of file modulop.h.

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

◆ npInpMultM()

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

Definition at line 77 of file modulop.h.

79 {
80  long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
81  #ifdef HAVE_GENERIC_ADD
82  if (x>r->npPminus1M) x-=r->npPminus1M;
83  #else
84  x-=r->npPminus1M;
85  #if SIZEOF_LONG == 8
86  x += (x >> 63) & r->npPminus1M;
87  #else
88  x += (x >> 31) & r->npPminus1M;
89  #endif
90  #endif
91  a=(number)(long)r->npExpTable[x];

◆ npInt()

long npInt ( number &  n,
const coeffs  r 
)

Definition at line 127 of file modulop.cc.

129 {
130  n_Test(n, r);
131 
132  if ((long)n > (((long)r->ch) >>1)) return ((long)n -((long)r->ch));
133  else return ((long)n);

◆ npIsZeroM()

static BOOLEAN npIsZeroM ( number  a,
const  coeffs 
)
inlinestatic

Definition at line 170 of file modulop.h.

172 {
173  return 0 == (long)a;

◆ npMultM()

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

Definition at line 62 of file modulop.h.

64 {
65  long x = (long)r->npLogTable[(long)a]+ r->npLogTable[(long)b];
66  #ifdef HAVE_GENERIC_ADD
67  if (x>r->npPminus1M) x-=r->npPminus1M;
68  #else
69  x-=r->npPminus1M;
70  #if SIZEOF_LONG == 8
71  x += (x >> 63) & r->npPminus1M;
72  #else
73  x += (x >> 31) & r->npPminus1M;
74  #endif
75  #endif
76  return (number)(long)r->npExpTable[x];

◆ npNegM()

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

Definition at line 165 of file modulop.h.

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

◆ npSetMap()

nMapFunc npSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 764 of file modulop.cc.

766 {
767 #ifdef HAVE_RINGS
768  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
769  {
770  return npMapMachineInt;
771  }
772  if (src->rep==n_rep_gmp) //nCoeff_is_Ring_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Ring_ModN(src))
773  {
774  return npMapGMP;
775  }
776  if (src->rep==n_rep_gap_gmp) //nCoeff_is_Ring_Z(src)
777  {
778  return npMapZ;
779  }
780 #endif
781  if (src->rep==n_rep_gap_rat) /* Q, Z */
782  {
783  return nlModP; // npMap0; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
784  }
785  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) )
786  {
787  if (n_GetChar(src) == n_GetChar(dst))
788  {
789  return ndCopyMap;
790  }
791  else
792  {
793  return npMapP;
794  }
795  }
796  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
797  {
798  return npMapLongR;
799  }
800  if (nCoeff_is_CF (src))
801  {
802  return npMapCanonicalForm;
803  }
804  return NULL; /* default */

◆ npSubM()

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

Definition at line 125 of file modulop.h.

127 {
128  return (number)((long)a<(long)b ?
129  r->ch-(long)b+(long)a : (long)a-(long)b);
getCoeffType
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:111
FALSE
#define FALSE
Definition: auxiliary.h:94
n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
nvMult
number nvMult(number a, number b, const coeffs r)
Definition: modulop.cc:811
npWrite
void npWrite(number a, const coeffs r)
Definition: modulop.cc:330
nCoeff_is_Zp
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:830
nCoeff_is_Ring_2toM
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:746
x
Variable x
Definition: cfModGcd.cc:4023
npWriteFd
static void npWriteFd(number n, FILE *f, const coeffs)
Definition: modulop.cc:469
npSetMap
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:764
n_GetChar
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
npCoeffString
static char * npCoeffString(const coeffs cf)
Definition: modulop.cc:464
npIsOne
BOOLEAN npIsOne(number a, const coeffs r)
Definition: modulop.cc:142
npRead
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:379
ndCopyMap
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:251
nvInvers
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:846
npReadFd
static number npReadFd(s_buff f, const coeffs)
Definition: modulop.cc:474
n_rep_int
(int), see modulop.h
Definition: coeffs.h:110
loop
#define loop
Definition: structs.h:77
npMapCanonicalForm
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:757
w
const CanonicalForm & w
Definition: facAbsFact.cc:55
b
CanonicalForm b
Definition: cfModGcd.cc:4044
npInit
number npInit(long i, const coeffs r)
Definition: modulop.cc:113
npCoeffWrite
void npCoeffWrite(const coeffs r, BOOLEAN details)
Definition: modulop.cc:876
npInvers
number npInvers(number c, const coeffs r)
Definition: modulop.cc:279
npMapZ
static number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:737
nvDiv
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:831
npCoeffName
static char * npCoeffName(const coeffs cf)
Definition: modulop.cc:457
npEqual
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:320
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
npAddM
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:115
npSubM
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:125
nCoeff_is_long_R
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:904
npMult
number npMult(number a, number b, const coeffs r)
Definition: modulop.cc:86
nlModP
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1434
nCoeff_is_CF
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:910
npInpAddM
static void npInpAddM(number &a, number b, const coeffs r)
Definition: modulop.h:120
npInpMult
void npInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:98
npGreaterZero
BOOLEAN npGreaterZero(number k, const coeffs r)
Definition: modulop.cc:70
npDiv
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:244
npIsMOne
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:149
npCoeffsEqual
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:432
npInt
long npInt(number &n, const coeffs r)
Definition: modulop.cc:127
npMapP
static number npMapP(number from, const coeffs src, const coeffs dst_r)
Definition: modulop.cc:636
npMapGMP
static number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:724
npKillChar
void npKillChar(coeffs r)
Definition: modulop.cc:413
n_Zp
\F{p < 2^31}
Definition: coeffs.h:29
n_rep_gmp_float
(gmp_float), see
Definition: coeffs.h:117
NV_MAX_PRIME
#define NV_MAX_PRIME
Definition: modulop.h:28
npMapLongR
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:648
assume
#define assume(x)
Definition: mod2.h:384
NULL
#define NULL
Definition: omList.c:9
R
#define R
Definition: sirandom.c:26
p
int p
Definition: cfModGcd.cc:4019
npRandom
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition: modulop.cc:482
npConvSingNFactoryN
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:437
npDBTest
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:625
n_Test
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:738
npNeg
number npNeg(number c, const coeffs r)
Definition: modulop.cc:294
npIsZero
BOOLEAN npIsZero(number a, const coeffs r)
Definition: modulop.cc:135
omAlloc0
#define omAlloc0(size)
Definition: omAllocDecl.h:209
npConvFactoryNSingN
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:444
nvInpMult
void nvInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:819
npMapMachineInt
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:750
npGreater
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:311
n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition: coeffs.h:112