My Project
Loading...
Searching...
No Matches
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

static BOOLEAN npGreaterZero (number k, const coeffs r)
static BOOLEAN npIsMOne (number a, const coeffs r)
static number npDiv (number a, number b, const coeffs r)
static number npNeg (number c, const coeffs r)
static number npInvers (number c, const coeffs r)
static BOOLEAN npGreater (number a, number b, const coeffs r)
static BOOLEAN npEqual (number a, number b, const coeffs r)
static void npWrite (number a, const coeffs r)
static const char * npRead (const char *s, number *a, const coeffs r)
static void nvInpMult (number &a, number b, const coeffs r)
static BOOLEAN npDBTest (number a, const char *f, const int l, const coeffs r)
static nMapFunc npSetMap (const coeffs src, const coeffs dst)
static 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)
long npInt (number &n, 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 void npWriteFd_S (number n, const coeffs)
static number npReadFd (const ssiInfo *d, const coeffs)
static number npReadFd_S (char **s, 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()

char * npCoeffName ( const coeffs cf)
static

Definition at line 300 of file modulop.cc.

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

◆ npCoeffsEqual()

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

Definition at line 276 of file modulop.cc.

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

◆ npConvFactoryNSingN()

number npConvFactoryNSingN ( const CanonicalForm n,
const coeffs r )

Definition at line 287 of file modulop.cc.

288{
289 if (n.isImm())
290 {
291 return npInit(n.intval(),r);
292 }
293 else
294 {
295 assume(0);
296 return NULL;
297 }
298}
long intval() const
conversion functions
bool isImm() const
#define assume(x)
Definition mod2.h:389
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 281 of file modulop.cc.

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

◆ npDBTest()

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

Definition at line 489 of file modulop.cc.

490{
491 if (((long)a<0L) || ((long)a>(long)r->ch))
492 {
493 Print("wrong mod p number %ld at %s,%d\n",(long)a,f,l);
494 return FALSE;
495 }
496 return TRUE;
497}
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
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 )
static

Definition at line 98 of file modulop.cc.

99{
100 n_Test(a, r);
101 n_Test(b, r);
102
103 if ((long)b==0L)
104 {
106 return (number)0L;
107 }
108 if ((long)a==0) return (number)0L;
109
110 number d;
111#ifndef HAVE_GENERIC_MULT
112 int s = r->npLogTable[(long)a] - r->npLogTable[(long)b];
113 #ifdef HAVE_GENERIC_ADD
114 if (s < 0)
115 s += r->npPminus1M;
116 #else
117 #if SIZEOF_LONG == 8
118 s += ((long)s >> 63) & r->npPminus1M;
119 #else
120 s += ((long)s >> 31) & r->npPminus1M;
121 #endif
122 #endif
123 d = (number)(long)r->npExpTable[s];
124#else
125 number inv=npInversM(b,r);
126 d = npMultM(a,inv,r);
127#endif
128
129 n_Test(d, r);
130 return d;
131
132}
CanonicalForm b
Definition cfModGcd.cc:4111
#define n_Test(a, r)
BOOLEAN n_Test(number a, const coeffs r).
Definition coeffs.h:715
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:90

◆ npEati()

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

Definition at line 214 of file modulop.cc.

215{
216 return nEati((char *)s,i,(int)r->ch);
217}
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:672

◆ npEqual()

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

Definition at line 174 of file modulop.cc.

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

◆ npGreater()

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

Definition at line 165 of file modulop.cc.

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

◆ npGreaterZero()

BOOLEAN npGreaterZero ( number k,
const coeffs r )
static

Definition at line 51 of file modulop.cc.

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

◆ npInitChar()

BOOLEAN npInitChar ( coeffs r,
void * p )

Definition at line 351 of file modulop.cc.

352{
353 assume( getCoeffType(r) == n_Zp );
354 const int c = (int) (long) p;
355
356 assume( c > 0 );
357
358 int i, w;
359
360 r->is_field=TRUE;
361 r->is_domain=TRUE;
362 r->rep=n_rep_int;
363
364 r->ch = c;
365 r->npPminus1M = c /*r->ch*/ - 1;
366
367 //r->cfInitChar=npInitChar;
368 r->cfKillChar=npKillChar;
369 r->nCoeffIsEqual=npCoeffsEqual;
370 r->cfCoeffName=npCoeffName;
371
372 r->cfMult = npMult;
373 r->cfInpMult = npInpMult;
374 r->cfSub = npSubM;
375 r->cfAdd = npAddM;
376 r->cfInpAdd = npInpAddM;
377 r->cfDiv = npDiv;
378 r->cfInit = npInit;
379 //r->cfSize = ndSize;
380 r->cfInt = npInt;
381 r->cfInitMPZ = npInitMPZ;
382 //r->cfDivComp = NULL; // only for ring stuff
383 //r->cfIsUnit = NULL; // only for ring stuff
384 //r->cfGetUnit = NULL; // only for ring stuff
385 //r->cfExtGcd = NULL; // only for ring stuff
386 // r->cfDivBy = NULL; // only for ring stuff
387 r->cfInpNeg = npNeg;
388 r->cfInvers= npInvers;
389 //r->cfCopy = ndCopy;
390 //r->cfRePart = ndCopy;
391 //r->cfImPart = ndReturn0;
392 r->cfWriteLong = npWrite;
393 r->cfRead = npRead;
394 //r->cfNormalize=ndNormalize;
395 r->cfGreater = npGreater;
396 r->cfEqual = npEqual;
397 r->cfIsZero = npIsZero;
398 r->cfIsOne = npIsOne;
399 r->cfIsMOne = npIsMOne;
400 r->cfGreaterZero = npGreaterZero;
401 //r->cfPower = npPower;
402 //r->cfGetDenom = ndGetDenom;
403 //r->cfGetNumerator = ndGetNumerator;
404 //r->cfGcd = ndGcd;
405 //r->cfLcm = ndGcd;
406 //r->cfDelete= ndDelete;
407 r->cfSetMap = npSetMap;
408 //r->cfName = ndName;
409 //r->cfInpMult=ndInpMult;
410 r->convSingNFactoryN=npConvSingNFactoryN;
411 r->convFactoryNSingN=npConvFactoryNSingN;
412 r->cfRandom=npRandom;
413#ifdef LDEBUG
414 // debug stuff
415 r->cfDBTest=npDBTest;
416#endif
417
418 // io via ssi
419 r->cfWriteFd=npWriteFd;
420 r->cfWriteFd_S=npWriteFd_S;
421 r->cfReadFd=npReadFd;
422 r->cfReadFd_S=npReadFd_S;
423
424 // the variables:
425 r->type = n_Zp;
426 r->has_simple_Alloc=TRUE;
427 r->has_simple_Inverse=TRUE;
428
429 // the tables
430#ifdef NV_OPS
431 if (r->ch <=NV_MAX_PRIME)
432#endif
433 {
434#ifdef HAVE_INVTABLE
435 r->npInvTable=(unsigned short*)omAlloc0( r->ch*sizeof(unsigned short) );
436#endif
437#ifndef HAVE_GENERIC_MULT
438 r->cfParameter=npPar; /* Singular.jl */
439 r->npExpTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
440 r->npLogTable=(unsigned short *)omAlloc0( r->ch*sizeof(unsigned short) );
441 r->npExpTable[0] = 1;
442 r->npLogTable[0] = 0;
443 if (r->ch > 2)
444 {
445 w = 1;
446 loop
447 {
448 r->npLogTable[1] = 0;
449 w++;
450 i = 0;
451 loop
452 {
453 i++;
454 r->npExpTable[i] =(int)(((long)w * (long)r->npExpTable[i-1]) % r->ch);
455 r->npLogTable[r->npExpTable[i]] = i;
456 if /*(i == r->ch - 1 ) ||*/ (/*(*/ r->npExpTable[i] == 1 /*)*/)
457 break;
458 }
459 if (i == r->ch - 1)
460 break;
461 }
462 }
463 else
464 {
465 r->npExpTable[1] = 1;
466 r->npLogTable[1] = 0;
467 }
468#endif
469 }
470#ifdef NV_OPS
471 else /*if (c>NV_MAX_PRIME)*/
472 {
473 r->cfMult = nvMult;
474 r->cfDiv = nvDiv;
475 r->cfExactDiv = nvDiv;
476 r->cfInvers = nvInvers;
477 r->cfInpMult = nvInpMult;
478 //r->cfPower= nvPower;
479 //if (c>FACTORY_MAX_PRIME) // factory will catch this error
480 //{
481 // r->convSingNFactoryN=ndConvSingNFactoryN;
482 //}
483 }
484#endif
485 return FALSE;
486}
int p
Definition cfModGcd.cc:4086
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:431
@ n_rep_int
(int), see modulop.h
Definition coeffs.h:117
const CanonicalForm & w
Definition facAbsFact.cc:51
static BOOLEAN npCoeffsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition modulop.cc:276
static const char * npRead(const char *s, number *a, const coeffs r)
Definition modulop.cc:219
static number npInitMPZ(mpz_t m, const coeffs r)
Definition modulop.cc:346
static void npWrite(number a, const coeffs r)
Definition modulop.cc:184
static number npReadFd_S(char **s, const coeffs)
Definition modulop.cc:325
CanonicalForm npConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition modulop.cc:281
static void npWriteFd(number n, const ssiInfo *d, const coeffs)
Definition modulop.cc:307
static number nvDiv(number a, number b, const coeffs r)
Definition modulop.cc:667
static number npDiv(number a, number b, const coeffs r)
Definition modulop.cc:98
number nvInvers(number c, const coeffs r)
Definition modulop.cc:682
static number npPar(int, coeffs r)
Definition modulop.cc:340
static number npInvers(number c, const coeffs r)
Definition modulop.cc:133
static BOOLEAN npEqual(number a, number b, const coeffs r)
Definition modulop.cc:174
static char * npCoeffName(const coeffs cf)
Definition modulop.cc:300
static number npNeg(number c, const coeffs r)
Definition modulop.cc:148
static BOOLEAN npGreater(number a, number b, const coeffs r)
Definition modulop.cc:165
void npInpMult(number &a, number b, const coeffs r)
Definition modulop.cc:68
static BOOLEAN npIsMOne(number a, const coeffs r)
Definition modulop.cc:91
static BOOLEAN npGreaterZero(number k, const coeffs r)
Definition modulop.cc:51
static BOOLEAN npDBTest(number a, const char *f, const int l, const coeffs r)
Definition modulop.cc:489
static nMapFunc npSetMap(const coeffs src, const coeffs dst)
Definition modulop.cc:618
static number npReadFd(const ssiInfo *d, const coeffs)
Definition modulop.cc:317
static void npWriteFd_S(number n, const coeffs)
Definition modulop.cc:312
static void nvInpMult(number &a, number b, const coeffs r)
Definition modulop.cc:655
static number npRandom(siRandProc p, number, number, const coeffs cf)
Definition modulop.cc:333
void npKillChar(coeffs r)
Definition modulop.cc:257
number npConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition modulop.cc:287
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)
#define loop
Definition structs.h:71

◆ npInitMPZ()

number npInitMPZ ( mpz_t m,
const coeffs r )
static

Definition at line 346 of file modulop.cc.

347{
348 return (number)mpz_fdiv_ui(m, r->ch);
349}
int m
Definition cfEzgcd.cc:128

◆ npInpMult()

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

Definition at line 68 of file modulop.cc.

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

◆ npInt()

long npInt ( number & n,
const coeffs r )

Definition at line 83 of file modulop.cc.

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

◆ npInvers()

number npInvers ( number c,
const coeffs r )
static

Definition at line 133 of file modulop.cc.

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

◆ npIsMOne()

BOOLEAN npIsMOne ( number a,
const coeffs r )
static

Definition at line 91 of file modulop.cc.

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

◆ npKillChar()

void npKillChar ( coeffs r)

Definition at line 257 of file modulop.cc.

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

◆ npMapCanonicalForm()

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

Definition at line 611 of file modulop.cc.

612{
613 setCharacteristic (dst ->ch);
615 return (number) (f.intval());
616}
virtual class for internal CanonicalForm's
Definition int_cf.h:47

◆ npMapGMP()

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

Definition at line 587 of file modulop.cc.

588{
589 return (number)mpz_fdiv_ui((mpz_ptr) from, dst->ch);
590}

◆ npMapLongR()

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

Definition at line 512 of file modulop.cc.

513{
514 gmp_float *ff=(gmp_float*)from;
515 mpf_t *f=ff->_mpfp();
516 number res;
517 mpz_ptr dest,ndest;
518 int size,i;
519 int e,al,bl;
520 long iz;
521 mp_ptr qp,dd,nn;
522
523 size = (*f)[0]._mp_size;
524 if (size == 0)
525 return npInit(0,dst_r);
526 if(size<0)
527 size = -size;
528
529 qp = (*f)[0]._mp_d;
530 while(qp[0]==0)
531 {
532 qp++;
533 size--;
534 }
535
536 if(dst_r->ch>2)
537 e=(*f)[0]._mp_exp-size;
538 else
539 e=0;
540 res = ALLOC_RNUMBER();
541#if defined(LDEBUG)
542 res->debug=123456;
543#endif
544 dest = res->z;
545
546 long in=0;
547 if (e<0)
548 {
549 al = dest->_mp_size = size;
550 if (al<2) al = 2;
551 dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
552 for (i=0;i<size;i++) dd[i] = qp[i];
553 bl = 1-e;
554 nn = (mp_ptr)omAlloc(sizeof(mp_limb_t)*bl);
555 nn[bl-1] = 1;
556 for (i=bl-2;i>=0;i--) nn[i] = 0;
557 ndest = res->n;
558 ndest->_mp_d = nn;
559 ndest->_mp_alloc = ndest->_mp_size = bl;
560 res->s = 0;
561 in=mpz_fdiv_ui(ndest,dst_r->ch);
562 mpz_clear(ndest);
563 }
564 else
565 {
566 al = dest->_mp_size = size+e;
567 if (al<2) al = 2;
568 dd = (mp_ptr)omAlloc(sizeof(mp_limb_t)*al);
569 for (i=0;i<size;i++) dd[i+e] = qp[i];
570 for (i=0;i<e;i++) dd[i] = 0;
571 res->s = 3;
572 }
573
574 dest->_mp_d = dd;
575 dest->_mp_alloc = al;
576 iz=mpz_fdiv_ui(dest,dst_r->ch);
577 mpz_clear(dest);
578 if(res->s==0)
579 iz=(long)npDiv((number)iz,(number)in,dst_r);
580 FREE_RNUMBER(res); // Q!?
581 return (number)iz;
582}
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
mpf_t * _mpfp()
#define ALLOC_RNUMBER()
Definition coeffs.h:94
#define FREE_RNUMBER(x)
Definition coeffs.h:93
CanonicalForm res
Definition facAbsFact.cc:60
#define omAlloc(size)

◆ npMapMachineInt()

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

Definition at line 605 of file modulop.cc.

606{
607 long i = (long) (((unsigned long) from) % dst->ch);
608 return (number) i;
609}

◆ npMapP()

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

Definition at line 500 of file modulop.cc.

501{
502 long i = (long)from;
503 if (i>src->ch/2)
504 {
505 i-=src->ch;
506 while (i < 0) i+=dst_r->ch;
507 }
508 i%=dst_r->ch;
509 return (number)i;
510}

◆ npMapZ()

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

Definition at line 592 of file modulop.cc.

593{
594 if (SR_HDL(from) & SR_INT)
595 {
596 long f_i=SR_TO_INT(from);
597 return npInit(f_i,dst);
598 }
599 return npMapGMP(from,src,dst);
600}
#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:587
#define SR_HDL(A)
Definition tgb.cc:35

◆ npNeg()

number npNeg ( number c,
const coeffs r )
static

Definition at line 148 of file modulop.cc.

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

◆ npPar()

number npPar ( int ,
coeffs r )
static

Definition at line 340 of file modulop.cc.

341{
342 return (number)(long)r->npExpTable[1];
343}

◆ npRandom()

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

Definition at line 333 of file modulop.cc.

334{
335 return npInit(p(),cf);
336}

◆ npRead()

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

Definition at line 219 of file modulop.cc.

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

◆ npReadFd()

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

Definition at line 317 of file modulop.cc.

318{
319 // read int
320 int dd;
321 dd=s_readint(d->f_read);
322 return (number)(long)dd;
323}
int s_readint(s_buff F)
Definition s_buff.cc:113
s_buff f_read
Definition s_buff.h:22

◆ npReadFd_S()

number npReadFd_S ( char ** s,
const coeffs  )
static

Definition at line 325 of file modulop.cc.

326{
327 // read int
328 int dd;
329 dd=s_readint_S(s);
330 return (number)(long)dd;
331}
int s_readint_S(char **s)
Definition s_buff.cc:141

◆ npSetMap()

nMapFunc npSetMap ( const coeffs src,
const coeffs dst )
static

Definition at line 618 of file modulop.cc.

619{
620 if ((src->rep==n_rep_int) && nCoeff_is_Ring_2toM(src))
621 {
622 return npMapMachineInt;
623 }
624 if (src->rep==n_rep_gmp) //nCoeff_is_Z(src) || nCoeff_is_Ring_PtoM(src) || nCoeff_is_Zn(src))
625 {
626 return npMapGMP;
627 }
628 if (src->rep==n_rep_gap_gmp) //nCoeff_is_Z(src)
629 {
630 return npMapZ;
631 }
632 if (src->rep==n_rep_gap_rat) /* Q, Z */
633 {
634 return nlModP; // npMap0; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
635 }
636 if ((src->rep==n_rep_int) && nCoeff_is_Zp(src) )
637 {
638 return npMapP;
639 }
640 if ((src->rep==n_rep_gmp_float) && nCoeff_is_long_R(src))
641 {
642 return npMapLongR;
643 }
644 if (nCoeff_is_CF (src))
645 {
646 return npMapCanonicalForm;
647 }
648 return NULL; /* default */
649}
static FORCE_INLINE BOOLEAN nCoeff_is_long_R(const coeffs r)
Definition coeffs.h:889
static FORCE_INLINE BOOLEAN nCoeff_is_CF(const coeffs r)
Definition coeffs.h:895
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition coeffs.h:794
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition coeffs.h:726
@ n_rep_gap_rat
(number), see longrat.h
Definition coeffs.h:118
@ n_rep_gap_gmp
(), see rinteger.h, new impl.
Definition coeffs.h:119
@ n_rep_gmp_float
(gmp_float), see
Definition coeffs.h:124
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition coeffs.h:122
number nlModP(number q, const coeffs, const coeffs Zp)
Definition longrat.cc:1573
static number npMapMachineInt(number from, const coeffs, const coeffs dst)
Definition modulop.cc:605
static number npMapP(number from, const coeffs src, const coeffs dst_r)
Definition modulop.cc:500
static number npMapLongR(number from, const coeffs, const coeffs dst_r)
Definition modulop.cc:512
static number npMapZ(number from, const coeffs src, const coeffs dst)
Definition modulop.cc:592
static number npMapCanonicalForm(number a, const coeffs, const coeffs dst)
Definition modulop.cc:611

◆ npWrite()

void npWrite ( number a,
const coeffs r )
static

Definition at line 184 of file modulop.cc.

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

◆ npWriteFd()

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

Definition at line 307 of file modulop.cc.

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

◆ npWriteFd_S()

void npWriteFd_S ( number n,
const coeffs  )
static

Definition at line 312 of file modulop.cc.

313{
314 StringAppend("%d ",(int)(long)n);
315}

◆ nvDiv()

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

Definition at line 667 of file modulop.cc.

668{
669 if ((long)a==0L)
670 return (number)0L;
671 else if ((long)b==0L)
672 {
674 return (number)0L;
675 }
676 else
677 {
678 number inv=nvInversM(b,r);
679 return nvMult(a,inv,r);
680 }
681}
static number nvInversM(number c, const coeffs r)
Definition modulop.cc:661

◆ nvInpMult()

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

Definition at line 655 of file modulop.cc.

656{
657 number n=nvMult(a,b,r);
658 a=n;
659}

◆ nvInvers()

number nvInvers ( number c,
const coeffs r )

Definition at line 682 of file modulop.cc.

683{
684 if ((long)c==0L)
685 {
687 return (number)0L;
688 }
689 return nvInversM(c,r);
690}

◆ nvInversM()

number nvInversM ( number c,
const coeffs r )
inlinestatic

Definition at line 661 of file modulop.cc.

662{
663 long inv=npInvMod((long)c,r);
664 return (number)inv;
665}
static long npInvMod(long a, const coeffs R)
Definition modulop.h:184