My Project  debian-1:4.1.2-p1+ds-2
Macros | Functions
modulop.cc File Reference
#include "misc/auxiliary.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 "coeffs/longrat.h"
#include "coeffs/modulop.h"
#include <string.h>

Go to the source code of this file.

Macros

#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)
 
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)
 
void nvInpMult (number &a, number b, const coeffs r)
 
BOOLEAN npDBTest (number a, const char *f, const int l, const coeffs r)
 
nMapFunc npSetMap (const coeffs src, const coeffs dst)
 
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)
 
void npInpMult (number &a, number b, 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 * npCoeffName (const coeffs cf)
 
static char * npCoeffString (const coeffs cf)
 
static void npWriteFd (number n, const ssiInfo *d, const coeffs)
 
static number npReadFd (const ssiInfo *d, const coeffs)
 
static number npRandom (siRandProc p, number, number, const coeffs cf)
 
BOOLEAN npInitChar (coeffs r, void *p)
 
static number npMapP (number from, const coeffs src, const coeffs dst_r)
 
static number npMapLongR (number from, const coeffs, const coeffs dst_r)
 
static number npMapGMP (number from, const coeffs, const coeffs dst)
 
static number npMapZ (number from, const coeffs src, const coeffs dst)
 
static number npMapMachineInt (number from, const coeffs, const coeffs dst)
 
static number npMapCanonicalForm (number a, const coeffs, const coeffs dst)
 
static number nvInversM (number c, const coeffs r)
 

Macro Definition Documentation

◆ ULONG64

#define ULONG64   (unsigned long)

Function Documentation

◆ npCoeffName()

static char* npCoeffName ( const coeffs  cf)
static

Definition at line 347 of file modulop.cc.

348 {
349  STATIC_VAR char npCoeffName_buf[15];
350  snprintf(npCoeffName_buf,14,"ZZ/%d",cf->ch);
351  return npCoeffName_buf;
352 }
CanonicalForm cf
Definition: cfModGcd.cc:4024
#define STATIC_VAR
Definition: globaldefs.h:7

◆ npCoeffsEqual()

static BOOLEAN npCoeffsEqual ( const coeffs  r,
n_coeffType  n,
void *  parameter 
)
static

Definition at line 323 of file modulop.cc.

324 {
325  /* test, if r is an instance of nInitCoeffs(n,parameter) */
326  return (n==n_Zp) && (r->ch==(int)(long)parameter);
327 }
@ n_Zp
\F{p < 2^31}
Definition: coeffs.h:30

◆ npCoeffString()

static char* npCoeffString ( const coeffs  cf)
static

Definition at line 354 of file modulop.cc.

355 {
356  return omStrDup(npCoeffName(cf));
357 }
static char * npCoeffName(const coeffs cf)
Definition: modulop.cc:347
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ npCoeffWrite()

void npCoeffWrite ( const coeffs  r,
BOOLEAN  details 
)

Definition at line 766 of file modulop.cc.

767 {
768  Print("ZZ/%d",r->ch);
769 }
#define Print
Definition: emacs.cc:80

◆ npConvFactoryNSingN()

number npConvFactoryNSingN ( const CanonicalForm  n,
const coeffs  r 
)

Definition at line 334 of file modulop.cc.

335 {
336  if (n.isImm())
337  {
338  return npInit(n.intval(),r);
339  }
340  else
341  {
342  assume(0);
343  return NULL;
344  }
345 }
long intval() const
conversion functions
bool isImm() const
#define assume(x)
Definition: mod2.h:390
number npInit(long i, const coeffs r)
Definition: modulop.cc:113
#define NULL
Definition: omList.c:12

◆ npConvSingNFactoryN()

CanonicalForm npConvSingNFactoryN ( number  n,
BOOLEAN  setChar,
const coeffs  r 
)

Definition at line 328 of file modulop.cc.

329 {
330  if (setChar) setCharacteristic( r->ch );
331  return CanonicalForm(npInt( n,r ));
332 }
void setCharacteristic(int c)
Definition: cf_char.cc:23
factory's main class
Definition: canonicalform.h:83
long npInt(number &n, const coeffs r)
Definition: modulop.cc:127

◆ npDBTest()

BOOLEAN npDBTest ( number  a,
const char *  f,
const int  l,
const coeffs  r 
)

Definition at line 515 of file modulop.cc.

516 {
517  if (((long)a<0L) || ((long)a>(long)r->ch))
518  {
519  Print("wrong mod p number %ld at %s,%d\n",(long)a,f,l);
520  return FALSE;
521  }
522  return TRUE;
523 }
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
int l
Definition: cfEzgcd.cc:93
FILE * f
Definition: checklibs.c:9

◆ npDiv()

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

Definition at line 149 of file modulop.cc.

150 {
151  n_Test(a, r);
152  n_Test(b, r);
153 
154  if ((long)b==0L)
155  {
156  WerrorS(nDivBy0);
157  return (number)0L;
158  }
159  if ((long)a==0) return (number)0L;
160 
161  number d;
162 #ifndef HAVE_GENERIC_MULT
163  int s = r->npLogTable[(long)a] - r->npLogTable[(long)b];
164  #ifdef HAVE_GENERIC_ADD
165  if (s < 0)
166  s += r->npPminus1M;
167  #else
168  #if SIZEOF_LONG == 8
169  s += ((long)s >> 63) & r->npPminus1M;
170  #else
171  s += ((long)s >> 31) & r->npPminus1M;
172  #endif
173  #endif
174  d = (number)(long)r->npExpTable[s];
175 #else
176  number inv=npInversM(b,r);
177  d = npMultM(a,inv,r);
178 #endif
179 
180  n_Test(d, r);
181  return d;
182 
183 }
CanonicalForm b
Definition: cfModGcd.cc:4044
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:738
const CanonicalForm int s
Definition: facAbsFact.cc:55
void WerrorS(const char *s)
Definition: feFopen.cc:24
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:68
static number npInversM(number c, const coeffs r)
Definition: modulop.h:230
const char *const nDivBy0
Definition: numbers.h:88

◆ npEati()

static const char* npEati ( const char *  s,
int *  i,
const coeffs  r 
)
inlinestatic

Definition at line 265 of file modulop.cc.

266 {
267  return nEati((char *)s,i,(int)r->ch);
268 }
int i
Definition: cfEzgcd.cc:125
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition: numbers.cc:630

◆ npEqual()

BOOLEAN npEqual ( number  a,
number  b,
const coeffs  r 
)

Definition at line 225 of file modulop.cc.

226 {
227  n_Test(a, r);
228  n_Test(b, r);
229 
230 // return (long)a == (long)b;
231 
232  return npEqualM(a,b,r);
233 }
#define npEqualM(A, B, r)
Definition: modulop.h:271

◆ npGreater()

BOOLEAN npGreater ( number  a,
number  b,
const coeffs  r 
)

Definition at line 216 of file modulop.cc.

217 {
218  n_Test(a, r);
219  n_Test(b, r);
220 
221  //return (long)a != (long)b;
222  return ((long)a) > ((long)b);
223 }

◆ npGreaterZero()

BOOLEAN npGreaterZero ( number  k,
const coeffs  r 
)

Definition at line 70 of file modulop.cc.

71 {
72  n_Test(k, r);
73 
74  int h = (int)((long) k);
75  return ((int)h !=0) && (h <= (r->ch>>1));
76 }
int k
Definition: cfEzgcd.cc:92
STATIC_VAR Poly * h
Definition: janet.cc:971

◆ npInit()

number npInit ( long  i,
const coeffs  r 
)

Definition at line 113 of file modulop.cc.

114 {
115  long ii=i % (long)r->ch;
116  if (ii < 0L) ii += (long)r->ch;
117 
118  number c = (number)ii;
119  n_Test(c, r);
120  return c;
121 }
if(yy_init)
Definition: libparse.cc:1420

◆ npInitChar()

BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 377 of file modulop.cc.

378 {
379  assume( getCoeffType(r) == n_Zp );
380  const int c = (int) (long) p;
381 
382  assume( c > 0 );
383 
384  int i, w;
385 
386  r->is_field=TRUE;
387  r->is_domain=TRUE;
388  r->rep=n_rep_int;
389 
390  r->ch = c;
391  r->npPminus1M = c /*r->ch*/ - 1;
392 
393  //r->cfInitChar=npInitChar;
394  r->cfKillChar=npKillChar;
395  r->nCoeffIsEqual=npCoeffsEqual;
396  r->cfCoeffString=npCoeffString;
397  r->cfCoeffName=npCoeffName;
398  r->cfCoeffWrite=npCoeffWrite;
399 
400  r->cfMult = npMult;
401  r->cfInpMult = npInpMult;
402  r->cfSub = npSubM;
403  r->cfAdd = npAddM;
404  r->cfInpAdd = npInpAddM;
405  r->cfDiv = npDiv;
406  r->cfInit = npInit;
407  //r->cfSize = ndSize;
408  r->cfInt = npInt;
409  #ifdef HAVE_RINGS
410  //r->cfDivComp = NULL; // only for ring stuff
411  //r->cfIsUnit = NULL; // only for ring stuff
412  //r->cfGetUnit = NULL; // only for ring stuff
413  //r->cfExtGcd = NULL; // only for ring stuff
414  // r->cfDivBy = NULL; // only for ring stuff
415  #endif
416  r->cfInpNeg = npNeg;
417  r->cfInvers= npInvers;
418  //r->cfCopy = ndCopy;
419  //r->cfRePart = ndCopy;
420  //r->cfImPart = ndReturn0;
421  r->cfWriteLong = npWrite;
422  r->cfRead = npRead;
423  //r->cfNormalize=ndNormalize;
424  r->cfGreater = npGreater;
425  r->cfEqual = npEqual;
426  r->cfIsZero = npIsZero;
427  r->cfIsOne = npIsOne;
428  r->cfIsMOne = npIsMOne;
429  r->cfGreaterZero = npGreaterZero;
430  //r->cfPower = npPower;
431  //r->cfGetDenom = ndGetDenom;
432  //r->cfGetNumerator = ndGetNumerator;
433  //r->cfGcd = ndGcd;
434  //r->cfLcm = ndGcd;
435  //r->cfDelete= ndDelete;
436  r->cfSetMap = npSetMap;
437  //r->cfName = ndName;
438  //r->cfInpMult=ndInpMult;
439  r->convSingNFactoryN=npConvSingNFactoryN;
440  r->convFactoryNSingN=npConvFactoryNSingN;
441  r->cfRandom=npRandom;
442 #ifdef LDEBUG
443  // debug stuff
444  r->cfDBTest=npDBTest;
445 #endif
446 
447  // io via ssi
448  r->cfWriteFd=npWriteFd;
449  r->cfReadFd=npReadFd;
450 
451  // the variables:
452  r->type = n_Zp;
453  r->has_simple_Alloc=TRUE;
454  r->has_simple_Inverse=TRUE;
455 
456  // the tables
457 #ifdef NV_OPS
458  if (r->ch <=NV_MAX_PRIME)
459 #endif
460  {
461 #ifdef HAVE_INVTABLE
462  r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
463 #endif
464 #ifndef HAVE_GENERIC_MULT
465  r->npExpTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
466  r->npLogTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
467  r->npExpTable[0] = 1;
468  r->npLogTable[0] = 0;
469  if (r->ch > 2)
470  {
471  w = 1;
472  loop
473  {
474  r->npLogTable[1] = 0;
475  w++;
476  i = 0;
477  loop
478  {
479  i++;
480  r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
481  r->npLogTable[r->npExpTable[i]] = i;
482  if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
483  break;
484  }
485  if (i == r->ch - 1)
486  break;
487  }
488  }
489  else
490  {
491  r->npExpTable[1] = 1;
492  r->npLogTable[1] = 0;
493  }
494 #endif
495  }
496 #ifdef NV_OPS
497  else /*if (c>NV_MAX_PRIME)*/
498  {
499  r->cfMult = nvMult;
500  r->cfDiv = nvDiv;
501  r->cfExactDiv = nvDiv;
502  r->cfInvers = nvInvers;
503  r->cfInpMult = nvInpMult;
504  //r->cfPower= nvPower;
505  //if (c>FACTORY_MAX_PRIME) // factory will catch this error
506  //{
507  // r->convSingNFactoryN=ndConvSingNFactoryN;
508  //}
509  }
510 #endif
511  return FALSE;
512 }
int p
Definition: cfModGcd.cc:4019
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
@ n_rep_int
(int), see modulop.h
Definition: coeffs.h:110
const CanonicalForm & w
Definition: facAbsFact.cc:55
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:323
void nvInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:709
number npInvers(number c, const coeffs r)
Definition: modulop.cc:184
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:721
void npCoeffWrite(const coeffs r, BOOLEAN details)
Definition: modulop.cc:766
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:142
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:328
BOOLEAN npIsOne(number a, const coeffs r)
static void npWriteFd(number n, const ssiInfo *d, const coeffs)
Definition: modulop.cc:359
number npNeg(number c, const coeffs r)
Definition: modulop.cc:199
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:654
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:270
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:736
void npInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:98
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:515
number npMult(number a, number b, const coeffs r)
Definition: modulop.cc:86
number nvMult(number a, number b, const coeffs r)
Definition: modulop.cc:701
BOOLEAN npIsZero(number a, const coeffs r)
Definition: modulop.cc:135
void npWrite(number a, const coeffs r)
Definition: modulop.cc:235
static char * npCoeffString(const coeffs cf)
Definition: modulop.cc:354
static number npReadFd(const ssiInfo *d, const coeffs)
Definition: modulop.cc:364
BOOLEAN npGreaterZero(number k, const coeffs r)
Definition: modulop.cc:70
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:225
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition: modulop.cc:372
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:149
void npKillChar(coeffs r)
Definition: modulop.cc:304
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:334
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:216
static number npAddM(number a, number b, const coeffs r)
Definition: modulop.h:121
#define NV_MAX_PRIME
Definition: modulop.h:29
static void npInpAddM(number &a, number b, const coeffs r)
Definition: modulop.h:126
static number npSubM(number a, number b, const coeffs r)
Definition: modulop.h:131
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define loop
Definition: structs.h:80

◆ npInpMult()

void npInpMult ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 98 of file modulop.cc.

99 {
100  n_Test(a, r);
101  n_Test(b, r);
102 
103  if (((long)a == 0) || ((long)b == 0))
104  a=(number)0;
105  else
106  a = npMultM(a,b, r);
107  n_Test(a, r);
108 }

◆ npInt()

long npInt ( number &  n,
const coeffs  r 
)

Definition at line 127 of file modulop.cc.

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

◆ npInvers()

number npInvers ( number  c,
const coeffs  r 
)

Definition at line 184 of file modulop.cc.

185 {
186  n_Test(c, r);
187 
188  if ((long)c==0L)
189  {
190  WerrorS("1/0");
191  return (number)0L;
192  }
193  number d = npInversM(c,r);
194 
195  n_Test(d, r);
196  return d;
197 }

◆ npIsMOne()

BOOLEAN npIsMOne ( number  a,
const coeffs  r 
)

Definition at line 142 of file modulop.cc.

143 {
144  n_Test(a, r);
145 
146  return ((r->npPminus1M == (long)a) &&(1L!=(long)a))/*for char 2*/;
147 }

◆ npIsOne()

BOOLEAN npIsOne ( number  a,
const coeffs  r 
)

◆ npIsZero()

BOOLEAN npIsZero ( number  a,
const coeffs  r 
)

Definition at line 135 of file modulop.cc.

136 {
137  n_Test(a, r);
138 
139  return 0 == (long)a;
140 }

◆ npKillChar()

void npKillChar ( coeffs  r)

Definition at line 304 of file modulop.cc.

305 {
306  #ifdef HAVE_INVTABLE
307  if (r->npInvTable!=NULL)
308  {
309  omFreeSize( (void *)r->npInvTable, r->ch*sizeof(unsigned short) );
310  r->npInvTable=NULL;
311  }
312  #endif
313  #ifndef HAVE_GENERIC_MULT
314  if (r->npExpTable!=NULL)
315  {
316  omFreeSize( (void *)r->npExpTable, r->ch*sizeof(unsigned short) );
317  omFreeSize( (void *)r->npLogTable, r->ch*sizeof(unsigned short) );
318  r->npExpTable=NULL; r->npLogTable=NULL;
319  }
320  #endif
321 }
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260

◆ npMapCanonicalForm()

static number npMapCanonicalForm ( number  a,
const  coeffs,
const coeffs  dst 
)
static

Definition at line 647 of file modulop.cc.

648 {
649  setCharacteristic (dst ->ch);
651  return (number) (f.intval());
652 }
virtual class for internal CanonicalForm's
Definition: int_cf.h:47

◆ npMapGMP()

static number npMapGMP ( number  from,
const  coeffs,
const coeffs  dst 
)
static

Definition at line 614 of file modulop.cc.

615 {
616  mpz_ptr erg = (mpz_ptr) omAlloc(sizeof(mpz_t)); // evtl. spaeter mit bin
617  mpz_init(erg);
618 
619  mpz_mod_ui(erg, (mpz_ptr) from, dst->ch);
620  number r = (number) mpz_get_si(erg);
621 
622  mpz_clear(erg);
623  omFree((void *) erg);
624  return (number) r;
625 }
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFree(addr)
Definition: omAllocDecl.h:261

◆ npMapLongR()

static number npMapLongR ( number  from,
const  coeffs,
const coeffs  dst_r 
)
static

Definition at line 538 of file modulop.cc.

539 {
540  gmp_float *ff=(gmp_float*)from;
541  mpf_t *f=ff->_mpfp();
542  number res;
543  mpz_ptr dest,ndest;
544  int size,i;
545  int e,al,bl;
546  long iz;
547  mp_ptr qp,dd,nn;
548 
549  size = (*f)[0]._mp_size;
550  if (size == 0)
551  return npInit(0,dst_r);
552  if(size<0)
553  size = -size;
554 
555  qp = (*f)[0]._mp_d;
556  while(qp[0]==0)
557  {
558  qp++;
559  size--;
560  }
561 
562  if(dst_r->ch>2)
563  e=(*f)[0]._mp_exp-size;
564  else
565  e=0;
566  res = ALLOC_RNUMBER();
567 #if defined(LDEBUG)
568  res->debug=123456;
569 #endif
570  dest = res->z;
571 
572  long in=0;
573  if (e<0)
574  {
575  al = dest->_mp_size = size;
576  if (al<2) al = 2;
577  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
578  for (i=0;i<size;i++) dd[i] = qp[i];
579  bl = 1-e;
580  nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl);
581  nn[bl-1] = 1;
582  for (i=bl-2;i>=0;i--) nn[i] = 0;
583  ndest = res->n;
584  ndest->_mp_d = nn;
585  ndest->_mp_alloc = ndest->_mp_size = bl;
586  res->s = 0;
587  in=mpz_fdiv_ui(ndest,dst_r->ch);
588  mpz_clear(ndest);
589  }
590  else
591  {
592  al = dest->_mp_size = size+e;
593  if (al<2) al = 2;
594  dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
595  for (i=0;i<size;i++) dd[i+e] = qp[i];
596  for (i=0;i<e;i++) dd[i] = 0;
597  res->s = 3;
598  }
599 
600  dest->_mp_d = dd;
601  dest->_mp_alloc = al;
602  iz=mpz_fdiv_ui(dest,dst_r->ch);
603  mpz_clear(dest);
604  if(res->s==0)
605  iz=(long)npDiv((number)iz,(number)in,dst_r);
606  FREE_RNUMBER(res); // Q!?
607  return (number)iz;
608 }
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition: cf_ops.cc:600
mpf_t * _mpfp()
Definition: mpr_complex.h:134
#define ALLOC_RNUMBER()
Definition: coeffs.h:87
#define FREE_RNUMBER(x)
Definition: coeffs.h:86
CanonicalForm res
Definition: facAbsFact.cc:64

◆ npMapMachineInt()

static number npMapMachineInt ( number  from,
const  coeffs,
const coeffs  dst 
)
static

Definition at line 640 of file modulop.cc.

641 {
642  long i = (long) (((unsigned long) from) % dst->ch);
643  return (number) i;
644 }

◆ npMapP()

static number npMapP ( number  from,
const coeffs  src,
const coeffs  dst_r 
)
static

Definition at line 526 of file modulop.cc.

527 {
528  long i = (long)from;
529  if (i>src->ch/2)
530  {
531  i-=src->ch;
532  while (i < 0) i+=dst_r->ch;
533  }
534  i%=dst_r->ch;
535  return (number)i;
536 }

◆ npMapZ()

static number npMapZ ( number  from,
const coeffs  src,
const coeffs  dst 
)
static

Definition at line 627 of file modulop.cc.

628 {
629  if (SR_HDL(from) & SR_INT)
630  {
631  long f_i=SR_TO_INT(from);
632  return npInit(f_i,dst);
633  }
634  return npMapGMP(from,src,dst);
635 }
#define SR_INT
Definition: longrat.h:66
#define SR_TO_INT(SR)
Definition: longrat.h:68
static number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:614
#define SR_HDL(A)
Definition: tgb.cc:35

◆ npMult()

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

Definition at line 86 of file modulop.cc.

87 {
88  n_Test(a, r);
89  n_Test(b, r);
90 
91  if (((long)a == 0) || ((long)b == 0))
92  return (number)0;
93  number c = npMultM(a,b, r);
94  n_Test(c, r);
95  return c;
96 }

◆ npNeg()

number npNeg ( number  c,
const coeffs  r 
)

Definition at line 199 of file modulop.cc.

200 {
201  n_Test(c, r);
202 
203  if ((long)c==0L) return c;
204 
205 #if 0
206  number d = npNegM(c,r);
207  n_Test(d, r);
208  return d;
209 #else
210  c = npNegM(c,r);
211  n_Test(c, r);
212  return c;
213 #endif
214 }
static number npNegM(number a, const coeffs r)
Definition: modulop.h:171

◆ npPower()

void npPower ( number  a,
int  i,
number *  result,
const coeffs  r 
)

◆ npRandom()

static number npRandom ( siRandProc  p,
number  ,
number  ,
const coeffs  cf 
)
static

Definition at line 372 of file modulop.cc.

373 {
374  return npInit(p(),cf);
375 }

◆ npRead()

const char * npRead ( const char *  s,
number *  a,
const coeffs  r 
)

Definition at line 270 of file modulop.cc.

271 {
272  int z;
273  int n=1;
274 
275  s = npEati(s, &z, r);
276  if ((*s) == '/')
277  {
278  s++;
279  s = npEati(s, &n, r);
280  }
281  if (n == 1)
282  *a = (number)(long)z;
283  else
284  {
285  if ((z==0)&&(n==0)) WerrorS(nDivBy0);
286  else
287  {
288 #ifdef NV_OPS
289  if (r->ch>NV_MAX_PRIME)
290  *a = nvDiv((number)(long)z,(number)(long)n,r);
291  else
292 #endif
293  *a = npDiv((number)(long)z,(number)(long)n,r);
294  }
295  }
296  n_Test(*a, r);
297  return s;
298 }
static const char * npEati(const char *s, int *i, const coeffs r)
Definition: modulop.cc:265

◆ npReadFd()

static number npReadFd ( const ssiInfo d,
const  coeffs 
)
static

Definition at line 364 of file modulop.cc.

365 {
366  // read int
367  int dd;
368  dd=s_readint(d->f_read);
369  return (number)(long)dd;
370 }
int s_readint(s_buff F)
Definition: s_buff.cc:112
s_buff f_read
Definition: s_buff.h:22

◆ npSetMap()

nMapFunc npSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 654 of file modulop.cc.

655 {
656 #ifdef HAVE_RINGS
657  if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
658  {
659  return npMapMachineInt;
660  }
661  if (src->rep==n_rep_gmp) //nCoeff_is_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Zn(src))
662  {
663  return npMapGMP;
664  }
665  if (src->rep==n_rep_gap_gmp) //nCoeff_is_Z(src)
666  {
667  return npMapZ;
668  }
669 #endif
670  if (src->rep==n_rep_gap_rat) /* Q, Z */
671  {
672  return nlModP; // npMap0; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
673  }
674  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) )
675  {
676  if (n_GetChar(src) == n_GetChar(dst))
677  {
678  return ndCopyMap;
679  }
680  else
681  {
682  return npMapP;
683  }
684  }
685  if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
686  {
687  return npMapLongR;
688  }
689  if (nCoeff_is_CF (src))
690  {
691  return npMapCanonicalForm;
692  }
693  return NULL; /* default */
694 }
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:913
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:919
static FORCE_INLINE int n_GetChar(const coeffs r)
Return the characteristic of the coeff. domain.
Definition: coeffs.h:444
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:822
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:746
@ n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:111
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition: coeffs.h:112
@ n_rep_gmp_float
(gmp_float), see
Definition: coeffs.h:117
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1435
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:640
static number npMapP(number from, const coeffs src, const coeffs dst_r)
Definition: modulop.cc:526
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:538
static number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:627
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:647
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:251

◆ npWrite()

void npWrite ( number  a,
const coeffs  r 
)

Definition at line 235 of file modulop.cc.

236 {
237  n_Test(a, r);
238 
239  if ((long)a>(((long)r->ch) >>1)) StringAppend("-%d",(int)(((long)r->ch)-((long)a)));
240  else StringAppend("%d",(int)((long)a));
241 }
#define StringAppend
Definition: emacs.cc:79

◆ npWriteFd()

static void npWriteFd ( number  n,
const ssiInfo d,
const  coeffs 
)
static

Definition at line 359 of file modulop.cc.

360 {
361  fprintf(d->f_write,"%d ",(int)(long)n);
362 }
FILE * f_write
Definition: s_buff.h:23

◆ nvDiv()

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

Definition at line 721 of file modulop.cc.

722 {
723  if ((long)a==0L)
724  return (number)0L;
725  else if ((long)b==0L)
726  {
727  WerrorS(nDivBy0);
728  return (number)0L;
729  }
730  else
731  {
732  number inv=nvInversM(b,r);
733  return nvMultM(a,inv,r);
734  }
735 }
static number nvMultM(number a, number b, const coeffs r)
Definition: modulop.cc:52
static number nvInversM(number c, const coeffs r)
Definition: modulop.cc:715

◆ nvInpMult()

void nvInpMult ( number &  a,
number  b,
const coeffs  r 
)

Definition at line 709 of file modulop.cc.

710 {
711  number n=nvMultM(a,b,r);
712  a=n;
713 }

◆ nvInvers()

number nvInvers ( number  c,
const coeffs  r 
)

Definition at line 736 of file modulop.cc.

737 {
738  if ((long)c==0L)
739  {
740  WerrorS(nDivBy0);
741  return (number)0L;
742  }
743  return nvInversM(c,r);
744 }

◆ nvInversM()

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

Definition at line 715 of file modulop.cc.

716 {
717  long inv=npInvMod((long)c,r);
718  return (number)inv;
719 }
static long npInvMod(long a, const coeffs R)
Definition: modulop.h:185

◆ nvMult()

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

Definition at line 701 of file modulop.cc.

702 {
703  //if (((long)a == 0) || ((long)b == 0))
704  // return (number)0;
705  //else
706  return nvMultM(a,b,r);
707 }

◆ nvMultM()

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

Definition at line 52 of file modulop.cc.

53 {
54  assume( getCoeffType(r) == n_Zp );
55 
56 #if SIZEOF_LONG == 4
57 #define ULONG64 (unsigned long long)(unsigned long)
58 #else
59 #define ULONG64 (unsigned long)
60 #endif
61  return (number)
62  (unsigned long)((ULONG64 a)*(ULONG64 b) % (ULONG64 r->ch));
63 }
#define ULONG64