My Project
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>
#include "coeffs/modulop_inl.h"

Go to the source code of this file.

Functions

BOOLEAN npGreaterZero (number k, const coeffs r)
 
long npInt (number &n, const coeffs r)
 
void npPower (number a, int i, number *result, 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)
 
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)
 
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 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)
 
static number npPar (int, coeffs r)
 
static number npInitMPZ (mpz_t m, const coeffs r)
 
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)
 

Function Documentation

◆ npCoeffName()

static char * npCoeffName ( const coeffs  cf)
static

Definition at line 302 of file modulop.cc.

303{
304 STATIC_VAR char npCoeffName_buf[15];
305 snprintf(npCoeffName_buf,14,"ZZ/%d",cf->ch);
306 return npCoeffName_buf;
307}
CanonicalForm cf
Definition: cfModGcd.cc:4083
#define STATIC_VAR
Definition: globaldefs.h:7

◆ npCoeffsEqual()

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

Definition at line 278 of file modulop.cc.

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

◆ npConvFactoryNSingN()

number npConvFactoryNSingN ( const CanonicalForm  n,
const coeffs  r 
)

Definition at line 289 of file modulop.cc.

290{
291 if (n.isImm())
292 {
293 return npInit(n.intval(),r);
294 }
295 else
296 {
297 assume(0);
298 return NULL;
299 }
300}
long intval() const
conversion functions
bool isImm() const
#define assume(x)
Definition: mod2.h:387
static number npInit(long i, const coeffs r)
Definition: modulop_inl.h:27
#define NULL
Definition: omList.c:12

◆ npConvSingNFactoryN()

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

Definition at line 283 of file modulop.cc.

284{
285 if (setChar) setCharacteristic( r->ch );
286 return CanonicalForm(npInt( n,r ));
287}
void FACTORY_PUBLIC setCharacteristic(int c)
Definition: cf_char.cc:28
factory's main class
Definition: canonicalform.h:86
long npInt(number &n, const coeffs r)
Definition: modulop.cc:85

◆ npDBTest()

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

Definition at line 478 of file modulop.cc.

479{
480 if (((long)a<0L) || ((long)a>(long)r->ch))
481 {
482 Print("wrong mod p number %ld at %s,%d\n",(long)a,f,l);
483 return FALSE;
484 }
485 return TRUE;
486}
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
int l
Definition: cfEzgcd.cc:100
FILE * f
Definition: checklibs.c:9
#define Print
Definition: emacs.cc:80

◆ npDiv()

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

Definition at line 100 of file modulop.cc.

101{
102 n_Test(a, r);
103 n_Test(b, r);
104
105 if ((long)b==0L)
106 {
108 return (number)0L;
109 }
110 if ((long)a==0) return (number)0L;
111
112 number d;
113#ifndef HAVE_GENERIC_MULT
114 int s = r->npLogTable[(long)a] - r->npLogTable[(long)b];
115 #ifdef HAVE_GENERIC_ADD
116 if (s < 0)
117 s += r->npPminus1M;
118 #else
119 #if SIZEOF_LONG == 8
120 s += ((long)s >> 63) & r->npPminus1M;
121 #else
122 s += ((long)s >> 31) & r->npPminus1M;
123 #endif
124 #endif
125 d = (number)(long)r->npExpTable[s];
126#else
127 number inv=npInversM(b,r);
128 d = npMultM(a,inv,r);
129#endif
130
131 n_Test(d, r);
132 return d;
133
134}
CanonicalForm b
Definition: cfModGcd.cc:4103
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r)
Definition: coeffs.h:712
const CanonicalForm int s
Definition: facAbsFact.cc:51
void WerrorS(const char *s)
Definition: feFopen.cc:24
static number npMultM(number a, number b, const coeffs r)
Definition: modulop.h:71
static number npInversM(number c, const coeffs r)
Definition: modulop.h:223
const char *const nDivBy0
Definition: numbers.h:87

◆ npEati()

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

Definition at line 216 of file modulop.cc.

217{
218 return nEati((char *)s,i,(int)r->ch);
219}
int i
Definition: cfEzgcd.cc:132
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition: numbers.cc:631

◆ npEqual()

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

Definition at line 176 of file modulop.cc.

177{
178 n_Test(a, r);
179 n_Test(b, r);
180
181// return (long)a == (long)b;
182
183 return npEqualM(a,b,r);
184}
#define npEqualM(A, B, r)
Definition: modulop.h:259

◆ npGreater()

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

Definition at line 167 of file modulop.cc.

168{
169 n_Test(a, r);
170 n_Test(b, r);
171
172 //return (long)a != (long)b;
173 return ((long)a) > ((long)b);
174}

◆ npGreaterZero()

BOOLEAN npGreaterZero ( number  k,
const coeffs  r 
)

Definition at line 53 of file modulop.cc.

54{
55 n_Test(k, r);
56
57 int h = (int)((long) k);
58 return ((int)h !=0) && (h <= (r->ch>>1));
59}
int k
Definition: cfEzgcd.cc:99
STATIC_VAR Poly * h
Definition: janet.cc:971

◆ npInitChar()

BOOLEAN npInitChar ( coeffs  r,
void *  p 
)

Definition at line 340 of file modulop.cc.

341{
342 assume( getCoeffType(r) == n_Zp );
343 const int c = (int) (long) p;
344
345 assume( c > 0 );
346
347 int i, w;
348
349 r->is_field=TRUE;
350 r->is_domain=TRUE;
351 r->rep=n_rep_int;
352
353 r->ch = c;
354 r->npPminus1M = c /*r->ch*/ - 1;
355
356 //r->cfInitChar=npInitChar;
357 r->cfKillChar=npKillChar;
358 r->nCoeffIsEqual=npCoeffsEqual;
359 r->cfCoeffName=npCoeffName;
360
361 r->cfMult = npMult;
362 r->cfInpMult = npInpMult;
363 r->cfSub = npSubM;
364 r->cfAdd = npAddM;
365 r->cfInpAdd = npInpAddM;
366 r->cfDiv = npDiv;
367 r->cfInit = npInit;
368 //r->cfSize = ndSize;
369 r->cfInt = npInt;
370 r->cfInitMPZ = npInitMPZ;
371 #ifdef HAVE_RINGS
372 //r->cfDivComp = NULL; // only for ring stuff
373 //r->cfIsUnit = NULL; // only for ring stuff
374 //r->cfGetUnit = NULL; // only for ring stuff
375 //r->cfExtGcd = NULL; // only for ring stuff
376 // r->cfDivBy = NULL; // only for ring stuff
377 #endif
378 r->cfInpNeg = npNeg;
379 r->cfInvers= npInvers;
380 //r->cfCopy = ndCopy;
381 //r->cfRePart = ndCopy;
382 //r->cfImPart = ndReturn0;
383 r->cfWriteLong = npWrite;
384 r->cfRead = npRead;
385 //r->cfNormalize=ndNormalize;
386 r->cfGreater = npGreater;
387 r->cfEqual = npEqual;
388 r->cfIsZero = npIsZero;
389 r->cfIsOne = npIsOne;
390 r->cfIsMOne = npIsMOne;
391 r->cfGreaterZero = npGreaterZero;
392 //r->cfPower = npPower;
393 //r->cfGetDenom = ndGetDenom;
394 //r->cfGetNumerator = ndGetNumerator;
395 //r->cfGcd = ndGcd;
396 //r->cfLcm = ndGcd;
397 //r->cfDelete= ndDelete;
398 r->cfSetMap = npSetMap;
399 //r->cfName = ndName;
400 //r->cfInpMult=ndInpMult;
401 r->convSingNFactoryN=npConvSingNFactoryN;
402 r->convFactoryNSingN=npConvFactoryNSingN;
403 r->cfRandom=npRandom;
404#ifdef LDEBUG
405 // debug stuff
406 r->cfDBTest=npDBTest;
407#endif
408
409 // io via ssi
410 r->cfWriteFd=npWriteFd;
411 r->cfReadFd=npReadFd;
412
413 // the variables:
414 r->type = n_Zp;
415 r->has_simple_Alloc=TRUE;
416 r->has_simple_Inverse=TRUE;
417
418 // the tables
419#ifdef NV_OPS
420 if (r->ch <=NV_MAX_PRIME)
421#endif
422 {
423#ifdef HAVE_INVTABLE
424 r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
425#endif
426#ifndef HAVE_GENERIC_MULT
427 r->cfParameter=npPar; /* Singular.jl */
428 r->npExpTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
429 r->npLogTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
430 r->npExpTable[0] = 1;
431 r->npLogTable[0] = 0;
432 if (r->ch > 2)
433 {
434 w = 1;
435 loop
436 {
437 r->npLogTable[1] = 0;
438 w++;
439 i = 0;
440 loop
441 {
442 i++;
443 r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
444 r->npLogTable[r->npExpTable[i]] = i;
445 if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
446 break;
447 }
448 if (i == r->ch - 1)
449 break;
450 }
451 }
452 else
453 {
454 r->npExpTable[1] = 1;
455 r->npLogTable[1] = 0;
456 }
457#endif
458 }
459#ifdef NV_OPS
460 else /*if (c>NV_MAX_PRIME)*/
461 {
462 r->cfMult = nvMult;
463 r->cfDiv = nvDiv;
464 r->cfExactDiv = nvDiv;
465 r->cfInvers = nvInvers;
466 r->cfInpMult = nvInpMult;
467 //r->cfPower= nvPower;
468 //if (c>FACTORY_MAX_PRIME) // factory will catch this error
469 //{
470 // r->convSingNFactoryN=ndConvSingNFactoryN;
471 //}
472 }
473#endif
474 return FALSE;
475}
int p
Definition: cfModGcd.cc:4078
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:51
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: modulop.cc:278
void nvInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:648
number npInvers(number c, const coeffs r)
Definition: modulop.cc:135
number nvDiv(number a, number b, const coeffs r)
Definition: modulop.cc:660
static number npInitMPZ(mpz_t m, const coeffs r)
Definition: modulop.cc:335
BOOLEAN npIsMOne(number a, const coeffs r)
Definition: modulop.cc:93
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: modulop.cc:283
static void npWriteFd(number n, const ssiInfo *d, const coeffs)
Definition: modulop.cc:309
number npNeg(number c, const coeffs r)
Definition: modulop.cc:150
nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition: modulop.cc:609
const char * npRead(const char *s, number *a, const coeffs r)
Definition: modulop.cc:221
number nvInvers(number c, const coeffs r)
Definition: modulop.cc:675
static number npPar(int, coeffs r)
Definition: modulop.cc:329
static char * npCoeffName(const coeffs cf)
Definition: modulop.cc:302
void npInpMult(number &a, number b, const coeffs r)
Definition: modulop.cc:70
BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition: modulop.cc:478
void npWrite(number a, const coeffs r)
Definition: modulop.cc:186
static number npReadFd(const ssiInfo *d, const coeffs)
Definition: modulop.cc:314
BOOLEAN npGreaterZero(number k, const coeffs r)
Definition: modulop.cc:53
BOOLEAN npEqual(number a, number b, const coeffs r)
Definition: modulop.cc:176
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition: modulop.cc:322
number npDiv(number a, number b, const coeffs r)
Definition: modulop.cc:100
void npKillChar(coeffs r)
Definition: modulop.cc:259
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: modulop.cc:289
BOOLEAN npGreater(number a, number b, const coeffs r)
Definition: modulop.cc:167
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 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

◆ npInitMPZ()

static number npInitMPZ ( mpz_t  m,
const coeffs  r 
)
static

Definition at line 335 of file modulop.cc.

336{
337 return (number)mpz_fdiv_ui(m, r->ch);
338}
int m
Definition: cfEzgcd.cc:128

◆ npInpMult()

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

Definition at line 70 of file modulop.cc.

71{
72 n_Test(a, r);
73 n_Test(b, r);
74
75 if (((long)a == 0) || ((long)b == 0))
76 a=(number)0;
77 else
78 a = npMultM(a,b, r);
79 n_Test(a, r);
80}

◆ npInt()

long npInt ( number &  n,
const coeffs  r 
)

Definition at line 85 of file modulop.cc.

86{
87 n_Test(n, r);
88
89 if ((long)n > (((long)r->ch) >>1)) return ((long)n -((long)r->ch));
90 else return ((long)n);
91}

◆ npInvers()

number npInvers ( number  c,
const coeffs  r 
)

Definition at line 135 of file modulop.cc.

136{
137 n_Test(c, r);
138
139 if ((long)c==0L)
140 {
141 WerrorS("1/0");
142 return (number)0L;
143 }
144 number d = npInversM(c,r);
145
146 n_Test(d, r);
147 return d;
148}

◆ npIsMOne()

BOOLEAN npIsMOne ( number  a,
const coeffs  r 
)

Definition at line 93 of file modulop.cc.

94{
95 n_Test(a, r);
96
97 return ((r->npPminus1M == (long)a) &&(1L!=(long)a))/*for char 2*/;
98}

◆ npKillChar()

void npKillChar ( coeffs  r)

Definition at line 259 of file modulop.cc.

260{
261 #ifdef HAVE_INVTABLE
262 if (r->npInvTable!=NULL)
263 {
264 omFreeSize( (void *)r->npInvTable, r->ch*sizeof(unsigned short) );
265 r->npInvTable=NULL;
266 }
267 #endif
268 #ifndef HAVE_GENERIC_MULT
269 if (r->npExpTable!=NULL)
270 {
271 omFreeSize( (void *)r->npExpTable, r->ch*sizeof(unsigned short) );
272 omFreeSize( (void *)r->npLogTable, r->ch*sizeof(unsigned short) );
273 r->npExpTable=NULL; r->npLogTable=NULL;
274 }
275 #endif
276}
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260

◆ npMapCanonicalForm()

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

Definition at line 602 of file modulop.cc.

603{
604 setCharacteristic (dst ->ch);
606 return (number) (f.intval());
607}
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 577 of file modulop.cc.

578{
579 return (number)mpz_fdiv_ui((mpz_ptr) from, dst->ch);
580}

◆ npMapLongR()

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

Definition at line 501 of file modulop.cc.

502{
503 gmp_float *ff=(gmp_float*)from;
504 mpf_t *f=ff->_mpfp();
505 number res;
506 mpz_ptr dest,ndest;
507 int size,i;
508 int e,al,bl;
509 long iz;
510 mp_ptr qp,dd,nn;
511
512 size = (*f)[0]._mp_size;
513 if (size == 0)
514 return npInit(0,dst_r);
515 if(size<0)
516 size = -size;
517
518 qp = (*f)[0]._mp_d;
519 while(qp[0]==0)
520 {
521 qp++;
522 size--;
523 }
524
525 if(dst_r->ch>2)
526 e=(*f)[0]._mp_exp-size;
527 else
528 e=0;
529 res = ALLOC_RNUMBER();
530#if defined(LDEBUG)
531 res->debug=123456;
532#endif
533 dest = res->z;
534
535 long in=0;
536 if (e<0)
537 {
538 al = dest->_mp_size = size;
539 if (al<2) al = 2;
540 dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
541 for (i=0;i<size;i++) dd[i] = qp[i];
542 bl = 1-e;
543 nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl);
544 nn[bl-1] = 1;
545 for (i=bl-2;i>=0;i--) nn[i] = 0;
546 ndest = res->n;
547 ndest->_mp_d = nn;
548 ndest->_mp_alloc = ndest->_mp_size = bl;
549 res->s = 0;
550 in=mpz_fdiv_ui(ndest,dst_r->ch);
551 mpz_clear(ndest);
552 }
553 else
554 {
555 al = dest->_mp_size = size+e;
556 if (al<2) al = 2;
557 dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
558 for (i=0;i<size;i++) dd[i+e] = qp[i];
559 for (i=0;i<e;i++) dd[i] = 0;
560 res->s = 3;
561 }
562
563 dest->_mp_d = dd;
564 dest->_mp_alloc = al;
565 iz=mpz_fdiv_ui(dest,dst_r->ch);
566 mpz_clear(dest);
567 if(res->s==0)
568 iz=(long)npDiv((number)iz,(number)in,dst_r);
569 FREE_RNUMBER(res); // Q!?
570 return (number)iz;
571}
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:60
#define omAlloc(size)
Definition: omAllocDecl.h:210

◆ npMapMachineInt()

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

Definition at line 595 of file modulop.cc.

596{
597 long i = (long) (((unsigned long) from) % dst->ch);
598 return (number) i;
599}

◆ npMapP()

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

Definition at line 489 of file modulop.cc.

490{
491 long i = (long)from;
492 if (i>src->ch/2)
493 {
494 i-=src->ch;
495 while (i < 0) i+=dst_r->ch;
496 }
497 i%=dst_r->ch;
498 return (number)i;
499}

◆ npMapZ()

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

Definition at line 582 of file modulop.cc.

583{
584 if (SR_HDL(from) & SR_INT)
585 {
586 long f_i=SR_TO_INT(from);
587 return npInit(f_i,dst);
588 }
589 return npMapGMP(from,src,dst);
590}
#define SR_INT
Definition: longrat.h:67
#define SR_TO_INT(SR)
Definition: longrat.h:69
static number npMapGMP(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:577
#define SR_HDL(A)
Definition: tgb.cc:35

◆ npNeg()

number npNeg ( number  c,
const coeffs  r 
)

Definition at line 150 of file modulop.cc.

151{
152 n_Test(c, r);
153
154 if ((long)c==0L) return c;
155
156#if 0
157 number d = npNegM(c,r);
158 n_Test(d, r);
159 return d;
160#else
161 c = npNegM(c,r);
162 n_Test(c, r);
163 return c;
164#endif
165}
static number npNegM(number a, const coeffs r)
Definition: modulop.h:174

◆ npPar()

static number npPar ( int  ,
coeffs  r 
)
static

Definition at line 329 of file modulop.cc.

330{
331 return (number)(long)r->npExpTable[1];
332}

◆ 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 322 of file modulop.cc.

323{
324 return npInit(p(),cf);
325}

◆ npRead()

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

Definition at line 221 of file modulop.cc.

222{
223 int z;
224 int n=1;
225
226 s = npEati(s, &z, r);
227 if ((*s) == '/')
228 {
229 s++;
230 s = npEati(s, &n, r);
231 }
232 if (n == 1)
233 *a = (number)(long)z;
234 else
235 {
236 if ((z==0)&&(n==0))
237 {
239 *a=(number)0L;
240 }
241 else
242 {
243#ifdef NV_OPS
244 if (r->ch>NV_MAX_PRIME)
245 *a = nvDiv((number)(long)z,(number)(long)n,r);
246 else
247#endif
248 *a = npDiv((number)(long)z,(number)(long)n,r);
249 }
250 }
251 n_Test(*a, r);
252 return s;
253}
static const char * npEati(const char *s, int *i, const coeffs r)
Definition: modulop.cc:216

◆ npReadFd()

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

Definition at line 314 of file modulop.cc.

315{
316 // read int
317 int dd;
318 dd=s_readint(d->f_read);
319 return (number)(long)dd;
320}
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 609 of file modulop.cc.

610{
611#ifdef HAVE_RINGS
612 if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
613 {
614 return npMapMachineInt;
615 }
616 if (src->rep==n_rep_gmp) //nCoeff_is_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Zn(src))
617 {
618 return npMapGMP;
619 }
620 if (src->rep==n_rep_gap_gmp) //nCoeff_is_Z(src)
621 {
622 return npMapZ;
623 }
624#endif
625 if (src->rep==n_rep_gap_rat) /* Q, Z */
626 {
627 return nlModP; // npMap0; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
628 }
629 if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) )
630 {
631 return npMapP;
632 }
633 if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
634 {
635 return npMapLongR;
636 }
637 if (nCoeff_is_CF (src))
638 {
639 return npMapCanonicalForm;
640 }
641 return NULL; /* default */
642}
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition: coeffs.h:891
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition: coeffs.h:897
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:800
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:724
@ 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:1577
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition: modulop.cc:595
static number npMapP(number from, const coeffs src, const coeffs dst_r)
Definition: modulop.cc:489
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition: modulop.cc:501
static number npMapZ(number from, const coeffs src, const coeffs dst)
Definition: modulop.cc:582
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition: modulop.cc:602

◆ npWrite()

void npWrite ( number  a,
const coeffs  r 
)

Definition at line 186 of file modulop.cc.

187{
188 n_Test(a, r);
189
190 if ((long)a>(((long)r->ch) >>1)) StringAppend("-%d",(int)(((long)r->ch)-((long)a)));
191 else StringAppend("%d",(int)((long)a));
192}
#define StringAppend
Definition: emacs.cc:79

◆ npWriteFd()

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

Definition at line 309 of file modulop.cc.

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

◆ nvDiv()

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

Definition at line 660 of file modulop.cc.

661{
662 if ((long)a==0L)
663 return (number)0L;
664 else if ((long)b==0L)
665 {
667 return (number)0L;
668 }
669 else
670 {
671 number inv=nvInversM(b,r);
672 return nvMult(a,inv,r);
673 }
674}
static number nvInversM(number c, const coeffs r)
Definition: modulop.cc:654

◆ nvInpMult()

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

Definition at line 648 of file modulop.cc.

649{
650 number n=nvMult(a,b,r);
651 a=n;
652}

◆ nvInvers()

number nvInvers ( number  c,
const coeffs  r 
)

Definition at line 675 of file modulop.cc.

676{
677 if ((long)c==0L)
678 {
680 return (number)0L;
681 }
682 return nvInversM(c,r);
683}

◆ nvInversM()

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

Definition at line 654 of file modulop.cc.

655{
656 long inv=npInvMod((long)c,r);
657 return (number)inv;
658}
static long npInvMod(long a, const coeffs R)
Definition: modulop.h:184