Macros | Functions | Variables
modulop.cc File Reference
#include <misc/auxiliary.h>
#include <omalloc/omalloc.h>
#include <factory/factory.h>
#include <misc/mylimits.h>
#include <misc/sirandom.h>
#include <reporter/reporter.h>
#include <coeffs/coeffs.h>
#include <coeffs/numbers.h>
#include <coeffs/mpr_complex.h>
#include "longrat.h"
#include "modulop.h"
#include <string.h>

Go to the source code of this file.

Macros

#define npTest(A, r)   npDBTest(A,__FILE__,__LINE__, r)
 
#define ULONG64   (unsigned long)
 

Functions

BOOLEAN npGreaterZero (number k, const coeffs r)
 
number npMult (number a, number b, const coeffs r)
 
number npInit (long i, const coeffs r)
 
long npInt (number &n, const coeffs r)
 
number npAdd (number a, number b, const coeffs r)
 
number npSub (number a, number b, const coeffs r)
 
void npPower (number a, int i, number *result, const coeffs r)
 
BOOLEAN npIsZero (number a, const coeffs r)
 
BOOLEAN npIsOne (number a, const coeffs r)
 
BOOLEAN npIsMOne (number a, const coeffs r)
 
number npDiv (number a, number b, const coeffs r)
 
number npNeg (number c, const coeffs r)
 
number npInvers (number c, const coeffs r)
 
BOOLEAN npGreater (number a, number b, const coeffs r)
 
BOOLEAN npEqual (number a, number b, const coeffs r)
 
void npWrite (number &a, const coeffs r)
 
void npCoeffWrite (const coeffs r, BOOLEAN details)
 
const char * npRead (const char *s, number *a, const coeffs r)
 
BOOLEAN npDBTest (number a, const char *f, const int l, const coeffs r)
 
nMapFunc npSetMap (const coeffs src, const coeffs dst)
 
number npMapP (number from, const coeffs src, const coeffs r)
 
static number nvMultM (number a, number b, const coeffs r)
 
number nvMult (number a, number b, const coeffs r)
 
number nvDiv (number a, number b, const coeffs r)
 
number nvInvers (number c, const coeffs r)
 
number npInversM (number c, const coeffs r)
 
static const char * npEati (const char *s, int *i, const coeffs r)
 
void npKillChar (coeffs r)
 
static BOOLEAN npCoeffsEqual (const coeffs r, n_coeffType n, void *parameter)
 
CanonicalForm npConvSingNFactoryN (number n, BOOLEAN setChar, const coeffs r)
 
number npConvFactoryNSingN (const CanonicalForm n, const coeffs r)
 
static char * npCoeffString (const coeffs r)
 
static void npWriteFd (number n, FILE *f, const coeffs r)
 
static number npReadFd (s_buff f, const coeffs r)
 
static number npRandom (siRandProc p, number, number, const coeffs cf)
 
BOOLEAN npInitChar (coeffs r, void *p)
 
static number npMapLongR (number from, const coeffs, const coeffs dst_r)
 
number npMapGMP (number from, const coeffs, const coeffs dst)
 
number npMapZ (number from, const coeffs src, const coeffs dst)
 
number npMapMachineInt (number from, const coeffs, const coeffs dst)
 
number npMapCanonicalForm (number a, const coeffs, const coeffs dst)
 
void nvInpMult (number &a, number b, const coeffs r)
 
long nvInvMod (long a, const coeffs R)
 
number nvInversM (number c, const coeffs r)
 

Variables

static const n_coeffType ID = n_Zp
 Our Type! More...
 
long npPminus1M
 
unsigned short * npExpTable
 
unsigned short * npLogTable
 

Macro Definition Documentation

#define npTest (   A,
  r 
)    npDBTest(A,__FILE__,__LINE__, r)

Definition at line 50 of file modulop.cc.

#define ULONG64   (unsigned long)

Function Documentation

number npAdd ( number  a,
number  b,
const coeffs  r 
)

Definition at line 153 of file modulop.cc.

154 {
155  n_Test(a, r);
156  n_Test(b, r);
157 
158  number c = npAddM(a,b, r);
159 
160  n_Test(c, r);
161 
162  return c;
163 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:77
const poly b
Definition: syzextra.cc:213
static BOOLEAN npCoeffsEqual ( const coeffs  r,
n_coeffType  n,
void *  parameter 
)
static

Definition at line 450 of file modulop.cc.

451 {
452  /* test, if r is an instance of nInitCoeffs(n,parameter) */
453  return (n==n_Zp) && (r->ch==(int)(long)parameter);
454 }
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
Definition: gb_hack.h:53
{p < 2^31}
Definition: coeffs.h:29
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
static char* npCoeffString ( const coeffs  r)
static

Definition at line 475 of file modulop.cc.

476 {
477  char *s=(char*)omAlloc(11);
478  snprintf(s,11,"%d",r->ch);
479  return s;
480 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define omAlloc(size)
Definition: omAllocDecl.h:210
void npCoeffWrite ( const coeffs  r,
BOOLEAN  details 
)

Definition at line 926 of file modulop.cc.

927 {
928  Print("// characteristic : %d\n",r->ch);
929 }
#define Print
Definition: emacs.cc:83
number npConvFactoryNSingN ( const CanonicalForm  n,
const coeffs  r 
)

Definition at line 462 of file modulop.cc.

463 {
464  if (n.isImm())
465  {
466  return npInit(n.intval(),r);
467  }
468  else
469  {
470  assume(0);
471  return NULL;
472  }
473 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:130
long intval() const
conversion functions
const ring r
Definition: syzextra.cc:208
#define assume(x)
Definition: mod2.h:405
bool isImm() const
Definition: canonicalform.h:97
#define NULL
Definition: omList.c:10
CanonicalForm npConvSingNFactoryN ( number  n,
BOOLEAN  setChar,
const coeffs  r 
)

Definition at line 455 of file modulop.cc.

456 {
457  if (setChar) setCharacteristic( r->ch );
458  CanonicalForm term(npInt( n,r ));
459  return term;
460 }
long npInt(number &n, const coeffs r)
Definition: modulop.cc:145
Definition: int_poly.h:36
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
factory's main class
Definition: canonicalform.h:72
void setCharacteristic(int c)
Definition: cf_char.cc:23
BOOLEAN npDBTest ( number  a,
const char *  f,
const int  l,
const coeffs  r 
)

Definition at line 634 of file modulop.cc.

635 {
636  if (((long)a<0) || ((long)a>r->ch))
637  {
638  Print("wrong mod p number %ld at %s,%d\n",(long)a,f,l);
639  return FALSE;
640  }
641  return TRUE;
642 }
const poly a
Definition: syzextra.cc:212
#define Print
Definition: emacs.cc:83
#define FALSE
Definition: auxiliary.h:140
f
Definition: cfModGcd.cc:4022
#define TRUE
Definition: auxiliary.h:144
int l
Definition: cfEzgcd.cc:94
number npDiv ( number  a,
number  b,
const coeffs  r 
)

Definition at line 265 of file modulop.cc.

266 {
267  n_Test(a, r);
268  n_Test(b, r);
269 
270 //#ifdef NV_OPS
271 // if (r->ch>NV_MAX_PRIME)
272 // return nvDiv(a,b);
273 //#endif
274  if ((long)a==0)
275  return (number)0;
276  number d;
277 
278 #ifndef HAVE_DIV_MOD
279  if ((long)b==0)
280  {
281  WerrorS(nDivBy0);
282  return (number)0;
283  }
284 
285  int s = r->npLogTable[(long)a] - r->npLogTable[(long)b];
286  if (s < 0)
287  s += r->npPminus1M;
288  d = (number)(long)r->npExpTable[s];
289 #else
290  number inv=npInversM(b,r);
291  d = npMultM(a,inv,r);
292 #endif
293 
294  n_Test(d, r);
295  return d;
296 
297 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:49
void WerrorS(const char *s)
Definition: feFopen.cc:23
number npInversM(number c, const coeffs r)
Definition: modulop.cc:246
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
const char *const nDivBy0
Definition: numbers.h:83
const poly b
Definition: syzextra.cc:213
static const char* npEati ( const char *  s,
int i,
const coeffs  r 
)
static

Definition at line 380 of file modulop.cc.

381 {
382 
383  if (((*s) >= '0') && ((*s) <= '9'))
384  {
385  unsigned long ii=0L;
386  do
387  {
388  ii *= 10;
389  ii += *s++ - '0';
390  if (ii >= (MAX_INT_VAL / 10)) ii = ii % r->ch;
391  }
392  while (((*s) >= '0') && ((*s) <= '9'));
393  if (ii >= (unsigned long)r->ch) ii = ii % r->ch;
394  *i=(int)ii;
395  }
396  else (*i) = 1;
397  return s;
398 }
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
Definition: gb_hack.h:53
const CanonicalForm int s
Definition: facAbsFact.cc:55
const int MAX_INT_VAL
Definition: mylimits.h:12
int i
Definition: cfEzgcd.cc:123
BOOLEAN npEqual ( number  a,
number  b,
const coeffs  r 
)

Definition at line 340 of file modulop.cc.

341 {
342  n_Test(a, r);
343  n_Test(b, r);
344 
345 // return (long)a == (long)b;
346 
347  return npEqualM(a,b,r);
348 }
const poly a
Definition: syzextra.cc:212
#define npEqualM(A, B, r)
Definition: modulop.h:132
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
const poly b
Definition: syzextra.cc:213
BOOLEAN npGreater ( number  a,
number  b,
const coeffs  r 
)

Definition at line 331 of file modulop.cc.

332 {
333  n_Test(a, r);
334  n_Test(b, r);
335 
336  //return (long)a != (long)b;
337  return (long)a > (long)b;
338 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
const poly b
Definition: syzextra.cc:213
BOOLEAN npGreaterZero ( number  k,
const coeffs  r 
)

Definition at line 99 of file modulop.cc.

100 {
101  n_Test(k, r);
102 
103  int h = (int)((long) k);
104  return ((int)h !=0) && (h <= (r->ch>>1));
105 }
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
Definition: gb_hack.h:53
int k
Definition: cfEzgcd.cc:93
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
static Poly * h
Definition: janet.cc:978
number npInit ( long  i,
const coeffs  r 
)

Definition at line 130 of file modulop.cc.

131 {
132  long ii=i % (long)r->ch;
133  if (ii < 0L) ii += (long)r->ch;
134 
135  number c = (number)ii;
136  n_Test(c, r);
137  return c;
138 
139 }
int int kStrategy strat if(h==NULL) return NULL
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
int i
Definition: cfEzgcd.cc:123
BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 500 of file modulop.cc.

501 {
502  assume( getCoeffType(r) == ID );
503  const int c = (int) (long) p;
504 
505  assume( c > 0 );
506 
507  int i, w;
508 
509  r->is_field=TRUE;
510  r->is_domain=TRUE;
511  r->rep=n_rep_int;
512 
513  r->ch = c;
514  r->npPminus1M = c /*r->ch*/ - 1;
515 
516  //r->cfInitChar=npInitChar;
517  r->cfKillChar=npKillChar;
518  r->nCoeffIsEqual=npCoeffsEqual;
519  r->cfCoeffString=npCoeffString;
520 
521  r->cfMult = npMult;
522  r->cfSub = npSub;
523  r->cfAdd = npAdd;
524  r->cfDiv = npDiv;
525  r->cfInit = npInit;
526  //r->cfSize = ndSize;
527  r->cfInt = npInt;
528  #ifdef HAVE_RINGS
529  //r->cfDivComp = NULL; // only for ring stuff
530  //r->cfIsUnit = NULL; // only for ring stuff
531  //r->cfGetUnit = NULL; // only for ring stuff
532  //r->cfExtGcd = NULL; // only for ring stuff
533  // r->cfDivBy = NULL; // only for ring stuff
534  #endif
535  r->cfInpNeg = npNeg;
536  r->cfInvers= npInvers;
537  //r->cfCopy = ndCopy;
538  //r->cfRePart = ndCopy;
539  //r->cfImPart = ndReturn0;
540  r->cfWriteLong = npWrite;
541  r->cfRead = npRead;
542  //r->cfNormalize=ndNormalize;
543  r->cfGreater = npGreater;
544  r->cfEqual = npEqual;
545  r->cfIsZero = npIsZero;
546  r->cfIsOne = npIsOne;
547  r->cfIsMOne = npIsMOne;
548  r->cfGreaterZero = npGreaterZero;
549  //r->cfPower = npPower;
550  //r->cfGetDenom = ndGetDenom;
551  //r->cfGetNumerator = ndGetNumerator;
552  //r->cfGcd = ndGcd;
553  //r->cfLcm = ndGcd;
554  //r->cfDelete= ndDelete;
555  r->cfSetMap = npSetMap;
556  //r->cfName = ndName;
557  //r->cfInpMult=ndInpMult;
558 #ifdef NV_OPS
559  if (c>NV_MAX_PRIME)
560  {
561  r->cfMult = nvMult;
562  r->cfDiv = nvDiv;
563  r->cfExactDiv= nvDiv;
564  r->cfInvers= nvInvers;
565  //r->cfPower= nvPower;
566  }
567 #endif
568  r->cfCoeffWrite=npCoeffWrite;
569 #ifdef LDEBUG
570  // debug stuff
571  r->cfDBTest=npDBTest;
572 #endif
573 
574  r->convSingNFactoryN=npConvSingNFactoryN;
575  r->convFactoryNSingN=npConvFactoryNSingN;
576 
577  r->cfRandom=npRandom;
578 
579  // io via ssi
580  r->cfWriteFd=npWriteFd;
581  r->cfReadFd=npReadFd;
582 
583  // the variables:
584  r->nNULL = (number)0;
585  r->type = n_Zp;
586  r->ch = c;
587  r->has_simple_Alloc=TRUE;
588  r->has_simple_Inverse=TRUE;
589 
590  // the tables
591 #ifdef NV_OPS
592  if (r->ch <=NV_MAX_PRIME)
593 #endif
594  {
595 #if !defined(HAVE_DIV_MOD) || !defined(HAVE_MULT_MOD)
596  r->npExpTable=(unsigned short *)omAlloc( r->ch*sizeof(unsigned short) );
597  r->npLogTable=(unsigned short *)omAlloc( r->ch*sizeof(unsigned short) );
598  r->npExpTable[0] = 1;
599  r->npLogTable[0] = 0;
600  if (r->ch > 2)
601  {
602  w = 1;
603  loop
604  {
605  r->npLogTable[1] = 0;
606  w++;
607  i = 0;
608  loop
609  {
610  i++;
611  r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
612  r->npLogTable[r->npExpTable[i]] = i;
613  if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
614  break;
615  }
616  if (i == r->ch - 1)
617  break;
618  }
619  }
620  else
621  {
622  r->npExpTable[1] = 1;
623  r->npLogTable[1] = 0;
624  }
625 #endif
626 #ifdef HAVE_DIV_MOD
627  r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
628 #endif
629  }
630  return FALSE;
631 }
const const intvec const intvec const ring _currRing const const intvec const intvec const ring _currRing int
Definition: gb_hack.h:53
number npInit(long i, const coeffs r)
Definition: modulop.cc:130
long npInt(number &n, const coeffs r)
Definition: modulop.cc:145
loop
Definition: myNF.cc:98
#define FALSE
Definition: auxiliary.h:140
return P p
Definition: myNF.cc:203
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:896
number npInvers(number c, const coeffs r)
Definition: modulop.cc:298
number nvMult(number a, number b, const coeffs r)
Definition: modulop.cc:820
{p < 2^31}
Definition: coeffs.h:29
number npAdd(number a, number b, const coeffs r)
Definition: modulop.cc:153
#define TRUE
Definition: auxiliary.h:144
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:265
static number npReadFd(s_buff f, const coeffs r)
Definition: modulop.cc:487
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:340
#define omAlloc(size)
Definition: omAllocDecl.h:210
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:634
static void npWriteFd(number n, FILE *f, const coeffs r)
Definition: modulop.cc:482
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition: modulop.cc:495
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:331
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:881
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:191
void npCoeffWrite(const coeffs r, BOOLEAN details)
Definition: modulop.cc:926
static const n_coeffType ID
Our Type!
Definition: modulop.cc:28
#define assume(x)
Definition: mod2.h:405
BOOLEAN npGreaterZero(number k, const coeffs r)
Definition: modulop.cc:99
int i
Definition: cfEzgcd.cc:123
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:773
static char * npCoeffString(const coeffs r)
Definition: modulop.cc:475
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
void npWrite(number &a, const coeffs r)
Definition: modulop.cc:350
number npSub(number a, number b, const coeffs r)
Definition: modulop.cc:165
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:462
#define NV_MAX_PRIME
Definition: modulop.h:21
number npNeg(number c, const coeffs r)
Definition: modulop.cc:314
const CanonicalForm & w
Definition: facAbsFact.cc:55
number npMult(number a, number b, const coeffs r)
Definition: modulop.cc:115
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:455
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:450
(int), see modulop.h
Definition: coeffs.h:108
void npKillChar(coeffs r)
Definition: modulop.cc:434
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:400
BOOLEAN npIsOne(number a, const coeffs r)
Definition: modulop.cc:184
BOOLEAN npIsZero(number a, const coeffs r)
Definition: modulop.cc:177
#define omAlloc0(size)
Definition: omAllocDecl.h:211
long npInt ( number &  n,
const coeffs  r 
)

Definition at line 145 of file modulop.cc.

146 {
147  n_Test(n, r);
148 
149  if ((long)n > (((long)r->ch) >>1)) return ((long)n -((long)r->ch));
150  else return ((long)n);
151 }
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
number npInvers ( number  c,
const coeffs  r 
)

Definition at line 298 of file modulop.cc.

299 {
300  n_Test(c, r);
301 
302  if ((long)c==0)
303  {
304  WerrorS("1/0");
305  return (number)0;
306  }
307  number d = npInversM(c,r);
308 
309  n_Test(d, r);
310  return d;
311 
312 }
void WerrorS(const char *s)
Definition: feFopen.cc:23
number npInversM(number c, const coeffs r)
Definition: modulop.cc:246
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
number npInversM ( number  c,
const coeffs  r 
)
inline

Definition at line 246 of file modulop.cc.

247 {
248  n_Test(c, r);
249 #ifndef HAVE_DIV_MOD
250  number d = (number)(long)r->npExpTable[r->npPminus1M - r->npLogTable[(long)c]];
251 #else
252  long inv=(long)r->npInvTable[(long)c];
253  if (inv==0)
254  {
255  inv=InvMod((long)c,r);
256  r->npInvTable[(long)c]=inv;
257  }
258  number d = (number)inv;
259 #endif
260  n_Test(d, r);
261  return d;
262 
263 }
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
unsigned long InvMod(unsigned long a, const coeffs r)
Definition: rmodulo2m.cc:529
BOOLEAN npIsMOne ( number  a,
const coeffs  r 
)

Definition at line 191 of file modulop.cc.

192 {
193  n_Test(a, r);
194 
195  return ((r->npPminus1M == (long)a)&&((long)1!=(long)a));
196 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
BOOLEAN npIsOne ( number  a,
const coeffs  r 
)

Definition at line 184 of file modulop.cc.

185 {
186  n_Test(a, r);
187 
188  return 1 == (long)a;
189 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
BOOLEAN npIsZero ( number  a,
const coeffs  r 
)

Definition at line 177 of file modulop.cc.

178 {
179  n_Test(a, r);
180 
181  return 0 == (long)a;
182 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
void npKillChar ( coeffs  r)

Definition at line 434 of file modulop.cc.

435 {
436  #ifdef HAVE_DIV_MOD
437  if (r->npInvTable!=NULL)
438  omFreeSize( (void *)r->npInvTable, r->ch*sizeof(unsigned short) );
439  r->npInvTable=NULL;
440  #else
441  if (r->npExpTable!=NULL)
442  {
443  omFreeSize( (void *)r->npExpTable, r->ch*sizeof(unsigned short) );
444  omFreeSize( (void *)r->npLogTable, r->ch*sizeof(unsigned short) );
445  r->npExpTable=NULL; r->npLogTable=NULL;
446  }
447  #endif
448 }
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define NULL
Definition: omList.c:10
number npMapCanonicalForm ( number  a,
const coeffs  ,
const coeffs  dst 
)

Definition at line 766 of file modulop.cc.

767 {
768  setCharacteristic (dst ->ch);
770  return (number) (f.intval());
771 }
const poly a
Definition: syzextra.cc:212
f
Definition: cfModGcd.cc:4022
factory's main class
Definition: canonicalform.h:72
long intval() const
conversion functions
void setCharacteristic(int c)
Definition: cf_char.cc:23
virtual class for internal CanonicalForm's
Definition: int_cf.h:35
number npMapGMP ( number  from,
const coeffs  ,
const coeffs  dst 
)

Definition at line 733 of file modulop.cc.

734 {
735  mpz_ptr erg = (mpz_ptr) omAlloc(sizeof(mpz_t)); // evtl. spaeter mit bin
736  mpz_init(erg);
737 
738  mpz_mod_ui(erg, (mpz_ptr) from, dst->ch);
739  number r = (number) mpz_get_si(erg);
740 
741  mpz_clear(erg);
742  omFree((void *) erg);
743  return (number) r;
744 }
#define omAlloc(size)
Definition: omAllocDecl.h:210
const ring r
Definition: syzextra.cc:208
#define omFree(addr)
Definition: omAllocDecl.h:261
static number npMapLongR ( number  from,
const coeffs  ,
const coeffs  dst_r 
)
static

Definition at line 657 of file modulop.cc.

658 {
659  gmp_float *ff=(gmp_float*)from;
660  mpf_t *f=ff->_mpfp();
661  number res;
662  mpz_ptr dest,ndest;
663  int size,i;
664  int e,al,bl;
665  long iz;
666  mp_ptr qp,dd,nn;
667 
668  size = (*f)[0]._mp_size;
669  if (size == 0)
670  return npInit(0,dst_r);
671  if(size<0)
672  size = -size;
673 
674  qp = (*f)[0]._mp_d;
675  while(qp[0]==0)
676  {
677  qp++;
678  size--;
679  }
680 
681  if(dst_r->ch>2)
682  e=(*f)[0]._mp_exp-size;
683  else
684  e=0;
685  res = ALLOC_RNUMBER();
686 #if defined(LDEBUG)
687  res->debug=123456;
688 #endif
689  dest = res->z;
690 
691  long in=0;
692  if (e<0)
693  {
694  al = dest->_mp_size = size;
695  if (al<2) al = 2;
696  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
697  for (i=0;i<size;i++) dd[i] = qp[i];
698  bl = 1-e;
699  nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl);
700  nn[bl-1] = 1;
701  for (i=bl-2;i>=0;i--) nn[i] = 0;
702  ndest = res->n;
703  ndest->_mp_d = nn;
704  ndest->_mp_alloc = ndest->_mp_size = bl;
705  res->s = 0;
706  in=mpz_fdiv_ui(ndest,dst_r->ch);
707  mpz_clear(ndest);
708  }
709  else
710  {
711  al = dest->_mp_size = size+e;
712  if (al<2) al = 2;
713  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
714  for (i=0;i<size;i++) dd[i+e] = qp[i];
715  for (i=0;i<e;i++) dd[i] = 0;
716  res->s = 3;
717  }
718 
719  dest->_mp_d = dd;
720  dest->_mp_alloc = al;
721  iz=mpz_fdiv_ui(dest,dst_r->ch);
722  mpz_clear(dest);
723  if(res->s==0)
724  iz=(long)npDiv((number)iz,(number)in,dst_r);
725  FREE_RNUMBER(res); // Q!?
726  return (number)iz;
727 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:130
mpf_t * _mpfp()
Definition: mpr_complex.h:134
f
Definition: cfModGcd.cc:4022
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:265
#define FREE_RNUMBER(x)
Definition: coeffs.h:84
#define omAlloc(size)
Definition: omAllocDecl.h:210
poly res
Definition: myNF.cc:322
int i
Definition: cfEzgcd.cc:123
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
#define ALLOC_RNUMBER()
Definition: coeffs.h:85
number npMapMachineInt ( number  from,
const coeffs  ,
const coeffs  dst 
)

Definition at line 759 of file modulop.cc.

760 {
761  long i = (long) (((unsigned long) from) % dst->ch);
762  return (number) i;
763 }
int i
Definition: cfEzgcd.cc:123
number npMapP ( number  from,
const coeffs  src,
const coeffs  r 
)

Definition at line 645 of file modulop.cc.

646 {
647  long i = (long)from;
648  if (i>src->ch/2)
649  {
650  i-=src->ch;
651  while (i < 0) i+=dst_r->ch;
652  }
653  i%=dst_r->ch;
654  return (number)i;
655 }
int i
Definition: cfEzgcd.cc:123
number npMapZ ( number  from,
const coeffs  src,
const coeffs  dst 
)

Definition at line 746 of file modulop.cc.

747 {
748  if (SR_HDL(from) & SR_INT)
749  {
750  long f_i=SR_TO_INT(from);
751  return npInit(f_i,dst);
752  }
753  return npMapGMP(from,src,dst);
754 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:130
#define SR_TO_INT(SR)
Definition: longrat.h:67
#define SR_INT
Definition: longrat.h:65
#define SR_HDL(A)
Definition: tgb.cc:35
number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:733
number npMult ( number  a,
number  b,
const coeffs  r 
)

Definition at line 115 of file modulop.cc.

116 {
117  n_Test(a, r);
118  n_Test(b, r);
119 
120  if (((long)a == 0) || ((long)b == 0))
121  return (number)0;
122  number c = npMultM(a,b, r);
123  n_Test(c, r);
124  return c;
125 }
const poly a
Definition: syzextra.cc:212
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:49
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
const poly b
Definition: syzextra.cc:213
number npNeg ( number  c,
const coeffs  r 
)

Definition at line 314 of file modulop.cc.

315 {
316  n_Test(c, r);
317 
318  if ((long)c==0) return c;
319 
320 #if 0
321  number d = npNegM(c,r);
322  n_Test(d, r);
323  return d;
324 #else
325  c = npNegM(c,r);
326  n_Test(c, r);
327  return c;
328 #endif
329 }
static number npNegM(number a, const coeffs r)
Definition: modulop.h:111
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
void npPower ( number  a,
int  i,
number *  result,
const coeffs  r 
)
static number npRandom ( siRandProc  p,
number  ,
number  ,
const coeffs  cf 
)
static

Definition at line 495 of file modulop.cc.

496 {
497  return npInit(p(),cf);
498 }
number npInit(long i, const coeffs r)
Definition: modulop.cc:130
return P p
Definition: myNF.cc:203
const char * npRead ( const char *  s,
number *  a,
const coeffs  r 
)

Definition at line 400 of file modulop.cc.

401 {
402  int z;
403  int n=1;
404 
405  s = npEati(s, &z, r);
406  if ((*s) == '/')
407  {
408  s++;
409  s = npEati(s, &n, r);
410  }
411  if (n == 1)
412  *a = (number)(long)z;
413  else
414  {
415  if ((z==0)&&(n==0)) WerrorS(nDivBy0);
416  else
417  {
418 #ifdef NV_OPS
419  if (r->ch>NV_MAX_PRIME)
420  *a = nvDiv((number)(long)z,(number)(long)n,r);
421  else
422 #endif
423  *a = npDiv((number)(long)z,(number)(long)n,r);
424  }
425  }
426  n_Test(*a, r);
427  return s;
428 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:265
void WerrorS(const char *s)
Definition: feFopen.cc:23
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:881
static const char * npEati(const char *s, int *i, const coeffs r)
Definition: modulop.cc:380
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
const char *const nDivBy0
Definition: numbers.h:83
#define NV_MAX_PRIME
Definition: modulop.h:21
static number npReadFd ( s_buff  f,
const coeffs  r 
)
static

Definition at line 487 of file modulop.cc.

488 {
489  // read int
490  int dd;
491  dd=s_readint(f);
492  return (number)(long)dd;
493 }
f
Definition: cfModGcd.cc:4022
int s_readint(s_buff F)
Definition: s_buff.cc:120
nMapFunc npSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 773 of file modulop.cc.

774 {
775 #ifdef HAVE_RINGS
776  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
777  {
778  return npMapMachineInt;
779  }
780  if (src->rep==n_rep_gmp) //nCoeff_is_Ring_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Ring_ModN(src))
781  {
782  return npMapGMP;
783  }
784  if (src->rep==n_rep_gap_gmp) //nCoeff_is_Ring_Z(src)
785  {
786  return npMapZ;
787  }
788 #endif
789  if (src->rep==n_rep_gap_rat) /* Q, Z */
790  {
791  return nlModP; // npMap0; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
792  }
793  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) )
794  {
795  if (n_GetChar(src) == n_GetChar(dst))
796  {
797  return ndCopyMap;
798  }
799  else
800  {
801  return npMapP;
802  }
803  }
804  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
805  {
806  return npMapLongR;
807  }
808  if (nCoeff_is_CF (src))
809  {
810  return npMapCanonicalForm;
811  }
812  return NULL; /* default */
813 }
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:816
number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:746
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:228
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:887
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:739
(), see rinteger.h, new impl.
Definition: coeffs.h:110
number npMapP(number from, const coeffs src, const coeffs r)
Definition: modulop.cc:645
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:759
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:893
number nlModP(number q, const coeffs Q, const coeffs Zp)
Definition: longrat.cc:1355
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:113
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:657
(number), see longrat.h
Definition: coeffs.h:109
#define NULL
Definition: omList.c:10
(gmp_float), see
Definition: coeffs.h:115
(int), see modulop.h
Definition: coeffs.h:108
number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:733
number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:766
number npSub ( number  a,
number  b,
const coeffs  r 
)

Definition at line 165 of file modulop.cc.

166 {
167  n_Test(a, r);
168  n_Test(b, r);
169 
170  number c = npSubM(a,b,r);
171 
172  n_Test(c, r);
173 
174  return c;
175 }
const poly a
Definition: syzextra.cc:212
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:82
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
const poly b
Definition: syzextra.cc:213
void npWrite ( number &  a,
const coeffs  r 
)

Definition at line 350 of file modulop.cc.

351 {
352  n_Test(a, r);
353 
354  if ((long)a>(((long)r->ch) >>1)) StringAppend("-%d",(int)(((long)r->ch)-((long)a)));
355  else StringAppend("%d",(int)((long)a));
356 }
const poly a
Definition: syzextra.cc:212
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:918
#define StringAppend
Definition: emacs.cc:82
static void npWriteFd ( number  n,
FILE *  f,
const coeffs  r 
)
static

Definition at line 482 of file modulop.cc.

483 {
484  fprintf(f,"%d ",(int)(long)n);
485 }
f
Definition: cfModGcd.cc:4022
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
number nvDiv ( number  a,
number  b,
const coeffs  r 
)

Definition at line 881 of file modulop.cc.

882 {
883  if ((long)a==0)
884  return (number)0;
885  else if ((long)b==0)
886  {
887  WerrorS(nDivBy0);
888  return (number)0;
889  }
890  else
891  {
892  number inv=nvInversM(b,r);
893  return nvMultM(a,inv,r);
894  }
895 }
const poly a
Definition: syzextra.cc:212
void WerrorS(const char *s)
Definition: feFopen.cc:23
const char *const nDivBy0
Definition: numbers.h:83
number nvInversM(number c, const coeffs r)
Definition: modulop.cc:875
const poly b
Definition: syzextra.cc:213
static number nvMultM(number a, number b, const coeffs r)
Definition: modulop.cc:78
void nvInpMult ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 828 of file modulop.cc.

829 {
830  number n=nvMultM(a,b,r);
831  a=n;
832 }
const poly a
Definition: syzextra.cc:212
const CanonicalForm CFMap CFMap int &both_non_zero int n
Definition: cfEzgcd.cc:52
const poly b
Definition: syzextra.cc:213
static number nvMultM(number a, number b, const coeffs r)
Definition: modulop.cc:78
number nvInvers ( number  c,
const coeffs  r 
)

Definition at line 896 of file modulop.cc.

897 {
898  if ((long)c==0)
899  {
900  WerrorS(nDivBy0);
901  return (number)0;
902  }
903  return nvInversM(c,r);
904 }
void WerrorS(const char *s)
Definition: feFopen.cc:23
const char *const nDivBy0
Definition: numbers.h:83
number nvInversM(number c, const coeffs r)
Definition: modulop.cc:875
number nvInversM ( number  c,
const coeffs  r 
)
inline

Definition at line 875 of file modulop.cc.

876 {
877  long inv=nvInvMod((long)c,r);
878  return (number)inv;
879 }
long nvInvMod(long a, const coeffs R)
Definition: modulop.cc:835
long nvInvMod ( long  a,
const coeffs  R 
)
inline

TODO: use "long InvMod(long a, const coeffs R)"?!

Definition at line 835 of file modulop.cc.

836 {
837 #ifdef HAVE_DIV_MOD
838  return InvMod(a, R);
839 #else
840 /// TODO: use "long InvMod(long a, const coeffs R)"?!
841 
842  long s;
843 
844  long u, u0, u1, u2, q, r; // v0, v1, v2,
845 
846  u1=1; // v1=0;
847  u2=0; // v2=1;
848  u = a;
849 
850  long v = R->ch;
851 
852  while (v != 0)
853  {
854  q = u / v;
855  r = u % v;
856  u = v;
857  v = r;
858  u0 = u2;
859 // v0 = v2;
860  u2 = u1 - q*u2;
861 // v2 = v1 - q*v2;
862  u1 = u0;
863 // v1 = v0;
864  }
865 
866  s = u1;
867  //t = v1;
868  if (s < 0)
869  return s + R->ch;
870  else
871  return s;
872 #endif
873 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:37
unsigned long InvMod(unsigned long a, const coeffs r)
Definition: rmodulo2m.cc:529
number nvMult ( number  a,
number  b,
const coeffs  r 
)

Definition at line 820 of file modulop.cc.

821 {
822  //if (((long)a == 0) || ((long)b == 0))
823  // return (number)0;
824  //else
825  return nvMultM(a,b,r);
826 }
const poly a
Definition: syzextra.cc:212
const poly b
Definition: syzextra.cc:213
static number nvMultM(number a, number b, const coeffs r)
Definition: modulop.cc:78
static number nvMultM ( number  a,
number  b,
const coeffs  r 
)
inlinestatic

Definition at line 78 of file modulop.cc.

79 {
80  assume( getCoeffType(r) == ID );
81 
82 #if SIZEOF_LONG == 4
83 #define ULONG64 (unsigned long long)(unsigned long)
84 #else
85 #define ULONG64 (unsigned long)
86 #endif
87  return (number)
88  (unsigned long)((ULONG64 a)*(ULONG64 b) % (ULONG64 r->ch));
89 }
const poly a
Definition: syzextra.cc:212
static const n_coeffType ID
Our Type!
Definition: modulop.cc:28
#define assume(x)
Definition: mod2.h:405
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
#define ULONG64
const poly b
Definition: syzextra.cc:213

Variable Documentation

const n_coeffType ID = n_Zp
static

Our Type!

Definition at line 28 of file modulop.cc.

unsigned short* npExpTable
unsigned short* npLogTable
long npPminus1M