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 30 of file modulop.h.

◆ npEqualM

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

Definition at line 187 of file modulop.h.

◆ NV_MAX_PRIME

#define NV_MAX_PRIME   32749

Definition at line 29 of file modulop.h.

◆ NV_OPS

#define NV_OPS

Definition at line 28 of file modulop.h.

Function Documentation

◆ npAddM()

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

Definition at line 116 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);
120 }
CanonicalForm b
Definition: cfModGcd.cc:4044
#define R
Definition: sirandom.c:26

◆ npInitChar()

BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 488 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;
623 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:114
long npInt(number &n, const coeffs r)
Definition: modulop.cc:128
#define FALSE
Definition: auxiliary.h:94
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:847
static void npWriteFd(number n, FILE *f, const coeffs)
Definition: modulop.cc:470
number npInvers(number c, const coeffs r)
Definition: modulop.cc:280
static char * npCoeffName(const coeffs cf)
Definition: modulop.cc:458
number nvMult(number a, number b, const coeffs r)
Definition: modulop.cc:812
{p < 2^31}
Definition: coeffs.h:30
void nvInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:820
void npWrite(number a, const coeffs r)
Definition: modulop.cc:331
#define TRUE
Definition: auxiliary.h:98
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:245
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:321
#define loop
Definition: structs.h:78
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:626
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:126
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition: modulop.cc:483
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:312
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:832
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:150
void npCoeffWrite(const coeffs r, BOOLEAN details)
Definition: modulop.cc:877
#define assume(x)
Definition: mod2.h:390
BOOLEAN npGreaterZero(number k, const coeffs r)
Definition: modulop.cc:71
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:116
int i
Definition: cfEzgcd.cc:125
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:765
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:445
#define NV_MAX_PRIME
Definition: modulop.h:29
static void npInpAddM(number &a, number b, const coeffs r)
Definition: modulop.h:121
void npInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:99
static char * npCoeffString(const coeffs cf)
Definition: modulop.cc:465
number npNeg(number c, const coeffs r)
Definition: modulop.cc:295
const CanonicalForm & w
Definition: facAbsFact.cc:55
number npMult(number a, number b, const coeffs r)
Definition: modulop.cc:87
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:438
static number npReadFd(s_buff f, const coeffs)
Definition: modulop.cc:475
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:433
(int), see modulop.h
Definition: coeffs.h:111
int p
Definition: cfModGcd.cc:4019
void npKillChar(coeffs r)
Definition: modulop.cc:414
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:380
BOOLEAN npIsOne(number a, const coeffs r)
Definition: modulop.cc:143
BOOLEAN npIsZero(number a, const coeffs r)
Definition: modulop.cc:136
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ npInpAddM()

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

Definition at line 121 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);
125 }
CanonicalForm b
Definition: cfModGcd.cc:4044
#define R
Definition: sirandom.c:26

◆ npInpMultM()

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

Definition at line 78 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];
92 }
CanonicalForm b
Definition: cfModGcd.cc:4044
Variable x
Definition: cfModGcd.cc:4023

◆ npInt()

long npInt ( number &  n,
const coeffs  r 
)

Definition at line 128 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);
134 }
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:739

◆ npIsZeroM()

static BOOLEAN npIsZeroM ( number  a,
const coeffs   
)
inlinestatic

Definition at line 171 of file modulop.h.

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

◆ npMultM()

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

Definition at line 63 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];
77 }
CanonicalForm b
Definition: cfModGcd.cc:4044
Variable x
Definition: cfModGcd.cc:4023

◆ npNegM()

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

Definition at line 166 of file modulop.h.

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

◆ npSetMap()

nMapFunc npSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 765 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 */
805 }
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:751
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:831
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1436
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:251
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:905
static number npMapP(number from, const coeffs src, const coeffs dst_r)
Definition: modulop.cc:637
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:747
(), see rinteger.h, new impl.
Definition: coeffs.h:113
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:445
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:911
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:116
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:649
(number), see longrat.h
Definition: coeffs.h:112
#define NULL
Definition: omList.c:10
(gmp_float), see
Definition: coeffs.h:118
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:758
static number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:738
static number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:725
(int), see modulop.h
Definition: coeffs.h:111

◆ npSubM()

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

Definition at line 126 of file modulop.h.

127 {
128  return (number)((long)a<(long)b ?
129  r->ch-(long)b+(long)a : (long)a-(long)b);
130 }
CanonicalForm b
Definition: cfModGcd.cc:4044