My Project
Loading...
Searching...
No Matches
Macros | Functions | Variables
rmodulon.cc File Reference
#include "misc/auxiliary.h"
#include "misc/mylimits.h"
#include "misc/prime.h"
#include "reporter/reporter.h"
#include "coeffs/si_gmp.h"
#include "coeffs/coeffs.h"
#include "coeffs/modulop.h"
#include "coeffs/rintegers.h"
#include "coeffs/numbers.h"
#include "coeffs/mpr_complex.h"
#include "coeffs/longrat.h"
#include "coeffs/rmodulon.h"
#include <string.h>

Go to the source code of this file.

Macros

#define nrnDelete   nrzDelete
 
#define nrnSize   nrzSize
 

Functions

void nrnWrite (number a, const coeffs)
 
static BOOLEAN nrnDBTest (number a, const char *f, const int l, const coeffs r)
 
coeffs nrnInitCfByName (char *s, n_coeffType)
 
static char * nrnCoeffName (const coeffs r)
 
static BOOLEAN nrnCoeffIsEqual (const coeffs r, n_coeffType n, void *parameter)
 
static void nrnKillChar (coeffs r)
 
static coeffs nrnQuot1 (number c, const coeffs r)
 
static number nrnCopy (number a, const coeffs)
 
static number nrnInit (long i, const coeffs r)
 
static long nrnInt (number &n, const coeffs)
 
static number nrnMult (number a, number b, const coeffs r)
 
static void nrnInpMult (number &a, number b, const coeffs r)
 
static void nrnPower (number a, int i, number *result, const coeffs r)
 
static number nrnAdd (number a, number b, const coeffs r)
 
static void nrnInpAdd (number &a, number b, const coeffs r)
 
static number nrnSub (number a, number b, const coeffs r)
 
static BOOLEAN nrnIsZero (number a, const coeffs)
 
static number nrnNeg (number c, const coeffs r)
 
static number nrnInvers (number c, const coeffs r)
 
static number nrnGcd (number a, number b, const coeffs r)
 
static number nrnLcm (number a, number b, const coeffs r)
 
static number nrnExtGcd (number a, number b, number *s, number *t, const coeffs r)
 
static BOOLEAN nrnIsOne (number a, const coeffs)
 
static BOOLEAN nrnEqual (number a, number b, const coeffs)
 
static number nrnGetUnit (number k, const coeffs r)
 
static number nrnXExtGcd (number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
 
static BOOLEAN nrnIsMOne (number a, const coeffs r)
 
static BOOLEAN nrnGreater (number a, number b, const coeffs)
 
static BOOLEAN nrnGreaterZero (number k, const coeffs cf)
 
static BOOLEAN nrnIsUnit (number a, const coeffs r)
 
static number nrnAnn (number k, const coeffs r)
 
static BOOLEAN nrnDivBy (number a, number b, const coeffs r)
 
static int nrnDivComp (number a, number b, const coeffs r)
 
static number nrnDiv (number a, number b, const coeffs r)
 
static number nrnMod (number a, number b, const coeffs r)
 
static number nrnQuotRem (number a, number b, number *rem, const coeffs r)
 
static number nrnMapModN (number from, const coeffs, const coeffs dst)
 
static number nrnMap2toM (number from, const coeffs, const coeffs dst)
 
static number nrnMapZp (number from, const coeffs, const coeffs dst)
 
number nrnMapGMP (number from, const coeffs, const coeffs dst)
 
static number nrnMapQ (number from, const coeffs src, const coeffs dst)
 
static number nrnMapZ (number from, const coeffs src, const coeffs dst)
 
nMapFunc nrnSetMap (const coeffs src, const coeffs dst)
 
static number nrnInitMPZ (mpz_t m, const coeffs r)
 
static void nrnMPZ (mpz_t m, number &n, const coeffs)
 
static void nrnSetExp (unsigned long m, coeffs r)
 
static void nrnInitExp (unsigned long m, coeffs r)
 
static const char * nlCPEatLongC (char *s, mpz_ptr i)
 
static const char * nrnRead (const char *s, number *a, const coeffs r)
 
static number nrnConvFactoryNSingN (const CanonicalForm n, const coeffs r)
 
static CanonicalForm nrnConvSingNFactoryN (number n, BOOLEAN setChar, const coeffs r)
 
BOOLEAN nrnInitChar (coeffs r, void *p)
 

Variables

EXTERN_VAR omBin gmp_nrz_bin
 
STATIC_VAR char * nrnCoeffName_buff =NULL
 
STATIC_VAR mpz_ptr nrnMapCoef = NULL
 

Macro Definition Documentation

◆ nrnDelete

#define nrnDelete   nrzDelete

Definition at line 177 of file rmodulon.cc.

◆ nrnSize

#define nrnSize   nrzSize

Definition at line 178 of file rmodulon.cc.

Function Documentation

◆ nlCPEatLongC()

static const char * nlCPEatLongC ( char *  s,
mpz_ptr  i 
)
static

Definition at line 931 of file rmodulon.cc.

932{
933 const char * start=s;
934 if (!(*s >= '0' && *s <= '9'))
935 {
936 mpz_init_set_ui(i, 1);
937 return s;
938 }
939 mpz_init(i);
940 while (*s >= '0' && *s <= '9') s++;
941 if (*s=='\0')
942 {
943 mpz_set_str(i,start,10);
944 }
945 else
946 {
947 char c=*s;
948 *s='\0';
949 mpz_set_str(i,start,10);
950 *s=c;
951 }
952 return s;
953}
int i
Definition: cfEzgcd.cc:132
const CanonicalForm int s
Definition: facAbsFact.cc:51

◆ nrnAdd()

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

Definition at line 220 of file rmodulon.cc.

221{
222 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
223 mpz_init(erg);
224 mpz_add(erg, (mpz_ptr)a, (mpz_ptr) b);
225 mpz_mod(erg, erg, r->modNumber);
226 return (number) erg;
227}
CanonicalForm b
Definition: cfModGcd.cc:4103
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
EXTERN_VAR omBin gmp_nrz_bin
Definition: rmodulon.cc:33

◆ nrnAnn()

static number nrnAnn ( number  k,
const coeffs  r 
)
static

Definition at line 551 of file rmodulon.cc.

552{
553 mpz_ptr tmp = (mpz_ptr) omAllocBin(gmp_nrz_bin);
554 mpz_init(tmp);
555 mpz_gcd(tmp, (mpz_ptr) k, r->modNumber);
556 if (mpz_cmp_si(tmp, 1)==0)
557 {
558 mpz_set_ui(tmp, 0);
559 return (number) tmp;
560 }
561 mpz_divexact(tmp, r->modNumber, tmp);
562 return (number) tmp;
563}
int k
Definition: cfEzgcd.cc:99

◆ nrnCoeffIsEqual()

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

Definition at line 89 of file rmodulon.cc.

90{
91 /* test, if r is an instance of nInitCoeffs(n,parameter) */
92 ZnmInfo *info=(ZnmInfo*)parameter;
93 return (n==r->type) && (r->modExponent==info->exp)
94 && (mpz_cmp(r->modBase,info->base)==0);
95}
#define info
Definition: libparse.cc:1256

◆ nrnCoeffName()

static char * nrnCoeffName ( const coeffs  r)
static

Definition at line 66 of file rmodulon.cc.

67{
69 size_t l = (size_t)mpz_sizeinbase(r->modBase, 10) + 2;
70 char* s = (char*) omAlloc(l);
71 l+=24;
73 s= mpz_get_str (s, 10, r->modBase);
74 int ll;
75 if (nCoeff_is_Zn(r))
76 {
77 if (strlen(s)<10)
78 ll=snprintf(nrnCoeffName_buff,l,"ZZ/(%s)",s);
79 else
80 ll=snprintf(nrnCoeffName_buff,l,"ZZ/bigint(%s)",s);
81 }
82 else if (nCoeff_is_Ring_PtoM(r))
83 ll=snprintf(nrnCoeffName_buff,l,"ZZ/(bigint(%s)^%lu)",s,r->modExponent);
84 assume(ll<(int)l); // otherwise nrnCoeffName_buff too small
85 omFreeSize((ADDRESS)s, l-22);
86 return nrnCoeffName_buff;
87}
void * ADDRESS
Definition: auxiliary.h:119
int l
Definition: cfEzgcd.cc:100
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_PtoM(const coeffs r)
Definition: coeffs.h:724
static FORCE_INLINE BOOLEAN nCoeff_is_Zn(const coeffs r)
Definition: coeffs.h:823
#define assume(x)
Definition: mod2.h:389
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define omFree(addr)
Definition: omAllocDecl.h:261
#define NULL
Definition: omList.c:12
STATIC_VAR char * nrnCoeffName_buff
Definition: rmodulon.cc:65

◆ nrnConvFactoryNSingN()

static number nrnConvFactoryNSingN ( const CanonicalForm  n,
const coeffs  r 
)
static

Definition at line 981 of file rmodulon.cc.

982{
983 return nrnInit(n.intval(),r);
984}
long intval() const
conversion functions
static number nrnInit(long i, const coeffs r)
Definition: rmodulon.cc:160

◆ nrnConvSingNFactoryN()

static CanonicalForm nrnConvSingNFactoryN ( number  n,
BOOLEAN  setChar,
const coeffs  r 
)
static

Definition at line 986 of file rmodulon.cc.

987{
988 if (setChar) setCharacteristic( r->ch );
989 return CanonicalForm(nrnInt( n,r ));
990}
void FACTORY_PUBLIC setCharacteristic(int c)
Definition: cf_char.cc:28
factory's main class
Definition: canonicalform.h:86
static long nrnInt(number &n, const coeffs)
Definition: rmodulon.cc:171

◆ nrnCopy()

static number nrnCopy ( number  a,
const  coeffs 
)
static

Definition at line 150 of file rmodulon.cc.

151{
152 mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
153 mpz_init_set(erg, (mpz_ptr) a);
154 return (number) erg;
155}

◆ nrnDBTest()

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

Definition at line 917 of file rmodulon.cc.

918{
919 if ( (mpz_sgn1((mpz_ptr) a) < 0) || (mpz_cmp((mpz_ptr) a, r->modNumber) > 0) )
920 {
921 Warn("mod-n: out of range at %s:%d\n",f,l);
922 return FALSE;
923 }
924 return TRUE;
925}
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
FILE * f
Definition: checklibs.c:9
#define Warn
Definition: emacs.cc:77
#define mpz_sgn1(A)
Definition: si_gmp.h:18

◆ nrnDiv()

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

Definition at line 583 of file rmodulon.cc.

584{
585 if (nrnIsZero(b,r))
586 {
588 return nrnInit(0,r);
589 }
590 else if (r->is_field)
591 {
592 number inv=nrnInvers(b,r);
593 number erg=nrnMult(a,inv,r);
594 nrnDelete(&inv,r);
595 return erg;
596 }
597 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
598 mpz_init(erg);
599 if (mpz_divisible_p((mpz_ptr)a, (mpz_ptr)b))
600 {
601 mpz_divexact(erg, (mpz_ptr)a, (mpz_ptr)b);
602 return (number)erg;
603 }
604 else
605 {
606 mpz_ptr gcd = (mpz_ptr)nrnGcd(a, b, r);
607 mpz_divexact(erg, (mpz_ptr)b, gcd);
608 if (!nrnIsUnit((number)erg, r))
609 {
610 WerrorS("Division not possible, even by cancelling zero divisors.");
611 nrnDelete((number*) &gcd, r);
612 nrnDelete((number*) &erg, r);
613 return (number)NULL;
614 }
615 // a / gcd(a,b) * [b / gcd (a,b)]^(-1)
616 mpz_ptr tmp = (mpz_ptr)nrnInvers((number) erg,r);
617 mpz_divexact(erg, (mpz_ptr)a, gcd);
618 mpz_mul(erg, erg, tmp);
619 nrnDelete((number*) &gcd, r);
620 nrnDelete((number*) &tmp, r);
621 mpz_mod(erg, erg, r->modNumber);
622 return (number)erg;
623 }
624}
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char *const nDivBy0
Definition: numbers.h:89
static BOOLEAN nrnIsZero(number a, const coeffs)
Definition: rmodulon.cc:244
static BOOLEAN nrnIsUnit(number a, const coeffs r)
Definition: rmodulon.cc:543
#define nrnDelete
Definition: rmodulon.cc:177
static number nrnInvers(number c, const coeffs r)
Definition: rmodulon.cc:257
static number nrnMult(number a, number b, const coeffs r)
Definition: rmodulon.cc:197
static number nrnGcd(number a, number b, const coeffs r)
Definition: rmodulon.cc:277
int gcd(int a, int b)
Definition: walkSupport.cc:836

◆ nrnDivBy()

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

Definition at line 565 of file rmodulon.cc.

566{
567 /* b divides a iff b/gcd(a, b) is a unit in the given ring: */
568 number n = nrnGcd(a, b, r);
569 mpz_tdiv_q((mpz_ptr)n, (mpz_ptr)b, (mpz_ptr)n);
570 bool result = nrnIsUnit(n, r);
571 nrnDelete(&n, NULL);
572 return result;
573}
return result
Definition: facAbsBiFact.cc:75

◆ nrnDivComp()

static int nrnDivComp ( number  a,
number  b,
const coeffs  r 
)
static

Definition at line 575 of file rmodulon.cc.

576{
577 if (nrnEqual(a, b,r)) return 2;
578 if (mpz_divisible_p((mpz_ptr) a, (mpz_ptr) b)) return -1;
579 if (mpz_divisible_p((mpz_ptr) b, (mpz_ptr) a)) return 1;
580 return 0;
581}
static BOOLEAN nrnEqual(number a, number b, const coeffs)
Definition: rmodulon.cc:350

◆ nrnEqual()

static BOOLEAN nrnEqual ( number  a,
number  b,
const  coeffs 
)
static

Definition at line 350 of file rmodulon.cc.

351{
352 return 0 == mpz_cmp((mpz_ptr)a, (mpz_ptr)b);
353}

◆ nrnExtGcd()

static number nrnExtGcd ( number  a,
number  b,
number *  s,
number *  t,
const coeffs  r 
)
static

Definition at line 329 of file rmodulon.cc.

330{
331 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
332 mpz_ptr bs = (mpz_ptr)omAllocBin(gmp_nrz_bin);
333 mpz_ptr bt = (mpz_ptr)omAllocBin(gmp_nrz_bin);
334 mpz_init(erg);
335 mpz_init(bs);
336 mpz_init(bt);
337 mpz_gcdext(erg, bs, bt, (mpz_ptr)a, (mpz_ptr)b);
338 mpz_mod(bs, bs, r->modNumber);
339 mpz_mod(bt, bt, r->modNumber);
340 *s = (number)bs;
341 *t = (number)bt;
342 return (number)erg;
343}

◆ nrnGcd()

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

Definition at line 277 of file rmodulon.cc.

278{
279 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
280 mpz_init_set(erg, r->modNumber);
281 if (a != NULL) mpz_gcd(erg, erg, (mpz_ptr)a);
282 mpz_gcd(erg, erg, (mpz_ptr)b);
283 if(mpz_cmp(erg,r->modNumber)==0)
284 {
285 mpz_clear(erg);
287 return nrnInit(0,r);
288 }
289 return (number)erg;
290}
#define omFreeBin(addr, bin)
Definition: omAllocDecl.h:259

◆ nrnGetUnit()

static number nrnGetUnit ( number  k,
const coeffs  r 
)
static

Definition at line 355 of file rmodulon.cc.

356{
357 if (mpz_divisible_p(r->modNumber, (mpz_ptr)k)) return nrnInit(1,r);
358
359 mpz_ptr unit = (mpz_ptr)nrnGcd(NULL, k, r);
360 mpz_tdiv_q(unit, (mpz_ptr)k, unit);
361 mpz_ptr gcd = (mpz_ptr)nrnGcd(NULL, (number)unit, r);
362 if (!nrnIsOne((number)gcd,r))
363 {
364 mpz_ptr ctmp;
365 // tmp := unit^2
366 mpz_ptr tmp = (mpz_ptr) nrnMult((number) unit,(number) unit,r);
367 // gcd_new := gcd(tmp, 0)
368 mpz_ptr gcd_new = (mpz_ptr) nrnGcd(NULL, (number) tmp, r);
369 while (!nrnEqual((number) gcd_new,(number) gcd,r))
370 {
371 // gcd := gcd_new
372 ctmp = gcd;
373 gcd = gcd_new;
374 gcd_new = ctmp;
375 // tmp := tmp * unit
376 mpz_mul(tmp, tmp, unit);
377 mpz_mod(tmp, tmp, r->modNumber);
378 // gcd_new := gcd(tmp, 0)
379 mpz_gcd(gcd_new, tmp, r->modNumber);
380 }
381 // unit := unit + modNumber / gcd_new
382 mpz_tdiv_q(tmp, r->modNumber, gcd_new);
383 mpz_add(unit, unit, tmp);
384 mpz_mod(unit, unit, r->modNumber);
385 nrnDelete((number*) &gcd_new, r);
386 nrnDelete((number*) &tmp, r);
387 }
388 nrnDelete((number*) &gcd, r);
389 return (number)unit;
390}
static BOOLEAN nrnIsOne(number a, const coeffs)
Definition: rmodulon.cc:345

◆ nrnGreater()

static BOOLEAN nrnGreater ( number  a,
number  b,
const  coeffs 
)
static

Definition at line 502 of file rmodulon.cc.

503{
504 return 0 < mpz_cmp((mpz_ptr)a, (mpz_ptr)b);
505}

◆ nrnGreaterZero()

static BOOLEAN nrnGreaterZero ( number  k,
const coeffs  cf 
)
static

Definition at line 507 of file rmodulon.cc.

508{
509 if (cf->is_field)
510 {
511 if (mpz_cmp_ui(cf->modBase,2)==0)
512 {
513 return TRUE;
514 }
515 #if 0
516 mpz_t ch2; mpz_init_set(ch2, cf->modBase);
517 mpz_sub_ui(ch2,ch2,1); //cf->modBase is odd
518 mpz_divexact_ui(ch2,ch2,2);
519 if (mpz_cmp(ch2,(mpz_ptr)k)<0)
520 {
521 mpz_clear(ch2);
522 return FALSE;
523 }
524 mpz_clear(ch2);
525 #endif
526 }
527 #if 0
528 else
529 {
530 mpz_t ch2; mpz_init_set(ch2, cf->modBase);
531 mpz_tdiv_q_ui(ch2,ch2,2);
532 if (mpz_cmp(ch2,(mpz_ptr)k)<0)
533 {
534 mpz_clear(ch2);
535 return FALSE;
536 }
537 mpz_clear(ch2);
538 }
539 #endif
540 return 0 < mpz_sgn1((mpz_ptr)k);
541}
CanonicalForm cf
Definition: cfModGcd.cc:4083

◆ nrnInit()

static number nrnInit ( long  i,
const coeffs  r 
)
static

Definition at line 160 of file rmodulon.cc.

161{
162 mpz_ptr erg = (mpz_ptr) omAllocBin(gmp_nrz_bin);
163 mpz_init_set_si(erg, i);
164 mpz_mod(erg, erg, r->modNumber);
165 return (number) erg;
166}

◆ nrnInitCfByName()

coeffs nrnInitCfByName ( char *  s,
n_coeffType  n 
)

Definition at line 35 of file rmodulon.cc.

36{
37 const char start[]="ZZ/bigint(";
38 const int start_len=strlen(start);
39 if (strncmp(s,start,start_len)==0)
40 {
41 s+=start_len;
42 mpz_t z;
43 mpz_init(z);
44 s=nEatLong(s,z);
46 info.base=z;
47 info.exp= 1;
48 while ((*s!='\0') && (*s!=')')) s++;
49 // expect ")" or ")^exp"
50 if (*s=='\0') { mpz_clear(z); return NULL; }
51 if (((*s)==')') && (*(s+1)=='^'))
52 {
53 s=s+2;
54 int i;
55 s=nEati(s,&i,0);
56 info.exp=(unsigned long)i;
57 return nInitChar(n_Znm,(void*) &info);
58 }
59 else
60 return nInitChar(n_Zn,(void*) &info);
61 }
62 else return NULL;
63}
@ n_Znm
only used if HAVE_RINGS is defined
Definition: coeffs.h:45
@ n_Zn
only used if HAVE_RINGS is defined
Definition: coeffs.h:44
coeffs nInitChar(n_coeffType t, void *parameter)
one-time initialisations for new coeffs in case of an error return NULL
Definition: numbers.cc:413
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition: numbers.cc:677
char * nEatLong(char *s, mpz_ptr i)
extracts a long integer from s, returns the rest
Definition: numbers.cc:718

◆ nrnInitChar()

BOOLEAN nrnInitChar ( coeffs  r,
void *  p 
)

Definition at line 993 of file rmodulon.cc.

994{
995 assume( (getCoeffType(r) == n_Zn) || (getCoeffType (r) == n_Znm) );
996 ZnmInfo * info= (ZnmInfo *) p;
997 r->modBase= (mpz_ptr)nrnCopy((number)info->base, r); //this circumvents the problem
998 //in bigintmat.cc where we cannot create a "legal" nrn that can be freed.
999 //If we take a copy, we can do whatever we want.
1000
1001 nrnInitExp (info->exp, r);
1002
1003 /* next computation may yield wrong characteristic as r->modNumber
1004 is a GMP number */
1005 r->ch = mpz_get_ui(r->modNumber);
1006
1007 r->is_field=FALSE;
1008 r->is_domain=FALSE;
1009 r->rep=n_rep_gmp;
1010
1011 r->cfInit = nrnInit;
1012 r->cfDelete = nrnDelete;
1013 r->cfCopy = nrnCopy;
1014 r->cfSize = nrnSize;
1015 r->cfInt = nrnInt;
1016 r->cfAdd = nrnAdd;
1017 r->cfInpAdd = nrnInpAdd;
1018 r->cfSub = nrnSub;
1019 r->cfMult = nrnMult;
1020 r->cfInpMult = nrnInpMult;
1021 r->cfDiv = nrnDiv;
1022 r->cfAnn = nrnAnn;
1023 r->cfIntMod = nrnMod;
1024 r->cfExactDiv = nrnDiv;
1025 r->cfInpNeg = nrnNeg;
1026 r->cfInvers = nrnInvers;
1027 r->cfDivBy = nrnDivBy;
1028 r->cfDivComp = nrnDivComp;
1029 r->cfGreater = nrnGreater;
1030 r->cfEqual = nrnEqual;
1031 r->cfIsZero = nrnIsZero;
1032 r->cfIsOne = nrnIsOne;
1033 r->cfIsMOne = nrnIsMOne;
1034 r->cfGreaterZero = nrnGreaterZero;
1035 r->cfWriteLong = nrnWrite;
1036 r->cfRead = nrnRead;
1037 r->cfPower = nrnPower;
1038 r->cfSetMap = nrnSetMap;
1039 //r->cfNormalize = ndNormalize;
1040 r->cfLcm = nrnLcm;
1041 r->cfGcd = nrnGcd;
1042 r->cfIsUnit = nrnIsUnit;
1043 r->cfGetUnit = nrnGetUnit;
1044 r->cfExtGcd = nrnExtGcd;
1045 r->cfXExtGcd = nrnXExtGcd;
1046 r->cfQuotRem = nrnQuotRem;
1047 r->cfCoeffName = nrnCoeffName;
1048 r->nCoeffIsEqual = nrnCoeffIsEqual;
1049 r->cfKillChar = nrnKillChar;
1050 r->cfQuot1 = nrnQuot1;
1051 r->cfInitMPZ = nrnInitMPZ;
1052 r->cfMPZ = nrnMPZ;
1053#if SI_INTEGER_VARIANT==2
1054 r->cfWriteFd = nrzWriteFd;
1055 r->cfReadFd = nrzReadFd;
1056#endif
1057
1058#ifdef LDEBUG
1059 r->cfDBTest = nrnDBTest;
1060#endif
1061 if ((r->modExponent==1)&&(mpz_size1(r->modBase)==1))
1062 {
1063 long p=mpz_get_si(r->modBase);
1064 if ((p<=FACTORY_MAX_PRIME)&&(p==IsPrime(p))) /*factory limit: <2^29*/
1065 {
1066 r->convFactoryNSingN=nrnConvFactoryNSingN;
1067 r->convSingNFactoryN=nrnConvSingNFactoryN;
1068 }
1069 }
1070 return FALSE;
1071}
int p
Definition: cfModGcd.cc:4078
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
#define FACTORY_MAX_PRIME
Definition: modulop.h:38
int IsPrime(int p)
Definition: prime.cc:61
number nrzReadFd(const ssiInfo *d, const coeffs)
void nrzWriteFd(number n, const ssiInfo *d, const coeffs)
static coeffs nrnQuot1(number c, const coeffs r)
Definition: rmodulon.cc:105
static BOOLEAN nrnDBTest(number a, const char *f, const int l, const coeffs r)
Definition: rmodulon.cc:917
static void nrnKillChar(coeffs r)
Definition: rmodulon.cc:97
#define nrnSize
Definition: rmodulon.cc:178
static BOOLEAN nrnGreater(number a, number b, const coeffs)
Definition: rmodulon.cc:502
static CanonicalForm nrnConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: rmodulon.cc:986
static number nrnExtGcd(number a, number b, number *s, number *t, const coeffs r)
Definition: rmodulon.cc:329
static void nrnMPZ(mpz_t m, number &n, const coeffs)
Definition: rmodulon.cc:885
static BOOLEAN nrnCoeffIsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: rmodulon.cc:89
static void nrnInpMult(number &a, number b, const coeffs r)
Definition: rmodulon.cc:206
void nrnWrite(number a, const coeffs)
Definition: rmodulon.cc:779
static number nrnMod(number a, number b, const coeffs r)
Definition: rmodulon.cc:626
static number nrnInitMPZ(mpz_t m, const coeffs r)
Definition: rmodulon.cc:877
static void nrnInitExp(unsigned long m, coeffs r)
Definition: rmodulon.cc:906
static number nrnAnn(number k, const coeffs r)
Definition: rmodulon.cc:551
nMapFunc nrnSetMap(const coeffs src, const coeffs dst)
Definition: rmodulon.cc:796
static number nrnConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: rmodulon.cc:981
static int nrnDivComp(number a, number b, const coeffs r)
Definition: rmodulon.cc:575
static const char * nrnRead(const char *s, number *a, const coeffs r)
Definition: rmodulon.cc:955
static number nrnXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition: rmodulon.cc:401
static number nrnQuotRem(number a, number b, number *rem, const coeffs r)
Definition: rmodulon.cc:673
static number nrnCopy(number a, const coeffs)
Definition: rmodulon.cc:150
static number nrnSub(number a, number b, const coeffs r)
Definition: rmodulon.cc:235
static number nrnLcm(number a, number b, const coeffs r)
Definition: rmodulon.cc:296
static void nrnPower(number a, int i, number *result, const coeffs r)
Definition: rmodulon.cc:212
static number nrnNeg(number c, const coeffs r)
Definition: rmodulon.cc:249
static number nrnGetUnit(number k, const coeffs r)
Definition: rmodulon.cc:355
static char * nrnCoeffName(const coeffs r)
Definition: rmodulon.cc:66
static number nrnDiv(number a, number b, const coeffs r)
Definition: rmodulon.cc:583
static BOOLEAN nrnIsMOne(number a, const coeffs r)
Definition: rmodulon.cc:492
static BOOLEAN nrnDivBy(number a, number b, const coeffs r)
Definition: rmodulon.cc:565
static BOOLEAN nrnGreaterZero(number k, const coeffs cf)
Definition: rmodulon.cc:507
static number nrnAdd(number a, number b, const coeffs r)
Definition: rmodulon.cc:220
static void nrnInpAdd(number &a, number b, const coeffs r)
Definition: rmodulon.cc:229
#define mpz_size1(A)
Definition: si_gmp.h:17

◆ nrnInitExp()

static void nrnInitExp ( unsigned long  m,
coeffs  r 
)
static

Definition at line 906 of file rmodulon.cc.

907{
908 nrnSetExp(m, r);
909 assume (r->modNumber != NULL);
910//CF: in general, the modulus is computed somewhere. I don't want to
911// check it's size before I construct the best ring.
912// if (mpz_cmp_ui(r->modNumber,2) <= 0)
913// WarnS("nrnInitExp failed (m in Z/m too small)");
914}
int m
Definition: cfEzgcd.cc:128
static void nrnSetExp(unsigned long m, coeffs r)
Definition: rmodulon.cc:894

◆ nrnInitMPZ()

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

Definition at line 877 of file rmodulon.cc.

878{
879 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
880 mpz_init_set(erg,m);
881 mpz_mod(erg, erg, r->modNumber);
882 return (number) erg;
883}

◆ nrnInpAdd()

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

Definition at line 229 of file rmodulon.cc.

230{
231 mpz_add((mpz_ptr)a, (mpz_ptr)a, (mpz_ptr) b);
232 mpz_mod((mpz_ptr)a, (mpz_ptr)a, r->modNumber);
233}

◆ nrnInpMult()

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

Definition at line 206 of file rmodulon.cc.

207{
208 mpz_mul((mpz_ptr)a, (mpz_ptr)a, (mpz_ptr) b);
209 mpz_mod((mpz_ptr)a, (mpz_ptr)a, r->modNumber);
210}

◆ nrnInt()

static long nrnInt ( number &  n,
const  coeffs 
)
static

Definition at line 171 of file rmodulon.cc.

172{
173 return mpz_get_si((mpz_ptr) n);
174}

◆ nrnInvers()

static number nrnInvers ( number  c,
const coeffs  r 
)
static

Definition at line 257 of file rmodulon.cc.

258{
259 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
260 mpz_init(erg);
261 if (nrnIsZero(c,r))
262 {
264 }
265 else
266 {
267 mpz_invert(erg, (mpz_ptr)c, r->modNumber);
268 }
269 return (number) erg;
270}

◆ nrnIsMOne()

static BOOLEAN nrnIsMOne ( number  a,
const coeffs  r 
)
static

Definition at line 492 of file rmodulon.cc.

493{
494 if((r->ch==2) && (nrnIsOne(a,r))) return FALSE;
495 mpz_t t; mpz_init_set(t, (mpz_ptr)a);
496 mpz_add_ui(t, t, 1);
497 bool erg = (0 == mpz_cmp(t, r->modNumber));
498 mpz_clear(t);
499 return erg;
500}

◆ nrnIsOne()

static BOOLEAN nrnIsOne ( number  a,
const  coeffs 
)
static

Definition at line 345 of file rmodulon.cc.

346{
347 return 0 == mpz_cmp_si((mpz_ptr)a, 1);
348}

◆ nrnIsUnit()

static BOOLEAN nrnIsUnit ( number  a,
const coeffs  r 
)
static

Definition at line 543 of file rmodulon.cc.

544{
545 number tmp = nrnGcd(a, (number)r->modNumber, r);
546 bool res = nrnIsOne(tmp, r);
547 nrnDelete(&tmp, r);
548 return res;
549}
CanonicalForm res
Definition: facAbsFact.cc:60

◆ nrnIsZero()

static BOOLEAN nrnIsZero ( number  a,
const  coeffs 
)
static

Definition at line 244 of file rmodulon.cc.

245{
246 return 0 == mpz_sgn1((mpz_ptr)a);
247}

◆ nrnKillChar()

static void nrnKillChar ( coeffs  r)
static

Definition at line 97 of file rmodulon.cc.

98{
99 mpz_clear(r->modNumber);
100 mpz_clear(r->modBase);
101 omFreeBin((void *) r->modBase, gmp_nrz_bin);
102 omFreeBin((void *) r->modNumber, gmp_nrz_bin);
103}

◆ nrnLcm()

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

Definition at line 296 of file rmodulon.cc.

297{
298 number erg = nrnGcd(NULL, a, r);
299 number tmp = nrnGcd(NULL, b, r);
300 mpz_lcm((mpz_ptr)erg, (mpz_ptr)erg, (mpz_ptr)tmp);
301 nrnDelete(&tmp, r);
302 return (number)erg;
303}

◆ nrnMap2toM()

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

Definition at line 716 of file rmodulon.cc.

717{
718 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
719 mpz_init(erg);
720 mpz_mul_ui(erg, nrnMapCoef, (unsigned long)from);
721 mpz_mod(erg, erg, dst->modNumber);
722 return (number)erg;
723}
STATIC_VAR mpz_ptr nrnMapCoef
Definition: rmodulon.cc:709

◆ nrnMapGMP()

number nrnMapGMP ( number  from,
const  coeffs,
const coeffs  dst 
)

Definition at line 735 of file rmodulon.cc.

736{
737 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
738 mpz_init(erg);
739 mpz_mod(erg, (mpz_ptr)from, dst->modNumber);
740 return (number)erg;
741}

◆ nrnMapModN()

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

Definition at line 711 of file rmodulon.cc.

712{
713 return nrnMult(from, (number) nrnMapCoef, dst);
714}

◆ nrnMapQ()

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

Definition at line 743 of file rmodulon.cc.

744{
745 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
746 nlMPZ(erg, from, src);
747 mpz_mod(erg, erg, dst->modNumber);
748 return (number)erg;
749}
void nlMPZ(mpz_t m, number &n, const coeffs r)
Definition: longrat.cc:2819

◆ nrnMapZ()

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

Definition at line 764 of file rmodulon.cc.

765{
766 if (SR_HDL(from) & SR_INT)
767 {
768 long f_i=SR_TO_INT(from);
769 return nrnInit(f_i,dst);
770 }
771 return nrnMapGMP(from,src,dst);
772}
#define SR_INT
Definition: longrat.h:67
#define SR_TO_INT(SR)
Definition: longrat.h:69
number nrnMapGMP(number from, const coeffs, const coeffs dst)
Definition: rmodulon.cc:735
#define SR_HDL(A)
Definition: tgb.cc:35

◆ nrnMapZp()

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

Definition at line 725 of file rmodulon.cc.

726{
727 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
728 mpz_init(erg);
729 // TODO: use npInt(...)
730 mpz_mul_si(erg, nrnMapCoef, (unsigned long)from);
731 mpz_mod(erg, erg, dst->modNumber);
732 return (number)erg;
733}
void mpz_mul_si(mpz_ptr r, mpz_srcptr s, long int si)
Definition: longrat.cc:177

◆ nrnMod()

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

Definition at line 626 of file rmodulon.cc.

627{
628 /*
629 We need to return the number rr which is uniquely determined by the
630 following two properties:
631 (1) 0 <= rr < |b| (with respect to '<' and '<=' performed in Z x Z)
632 (2) There exists some k in the integers Z such that a = k * b + rr.
633 Consider g := gcd(n, |b|). Note that then |b|/g is a unit in Z/n.
634 Now, there are three cases:
635 (a) g = 1
636 Then |b| is a unit in Z/n, i.e. |b| (and also b) divides a.
637 Thus rr = 0.
638 (b) g <> 1 and g divides a
639 Then a = (a/g) * (|b|/g)^(-1) * b (up to sign), i.e. again rr = 0.
640 (c) g <> 1 and g does not divide a
641 Then denote the division with remainder of a by g as this:
642 a = s * g + t. Then t = a - s * g = a - s * (|b|/g)^(-1) * |b|
643 fulfills (1) and (2), i.e. rr := t is the correct result. Hence
644 in this third case, rr is the remainder of division of a by g in Z.
645 Remark: according to mpz_mod: a,b are always non-negative
646 */
647 mpz_ptr g = (mpz_ptr)omAllocBin(gmp_nrz_bin);
648 mpz_ptr rr = (mpz_ptr)omAllocBin(gmp_nrz_bin);
649 mpz_init(g);
650 mpz_init_set_ui(rr, 0);
651 mpz_gcd(g, (mpz_ptr)r->modNumber, (mpz_ptr)b); // g is now as above
652 if (mpz_cmp_si(g, 1L) != 0) mpz_mod(rr, (mpz_ptr)a, g); // the case g <> 1
653 mpz_clear(g);
655 return (number)rr;
656}
g
Definition: cfModGcd.cc:4090

◆ nrnMPZ()

static void nrnMPZ ( mpz_t  m,
number &  n,
const  coeffs 
)
static

Definition at line 885 of file rmodulon.cc.

886{
887 mpz_init_set(m, (mpz_ptr)n);
888}

◆ nrnMult()

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

Definition at line 197 of file rmodulon.cc.

198{
199 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
200 mpz_init(erg);
201 mpz_mul(erg, (mpz_ptr)a, (mpz_ptr) b);
202 mpz_mod(erg, erg, r->modNumber);
203 return (number) erg;
204}

◆ nrnNeg()

static number nrnNeg ( number  c,
const coeffs  r 
)
static

Definition at line 249 of file rmodulon.cc.

250{
251 if( !nrnIsZero(c, r) )
252 // Attention: This method operates in-place.
253 mpz_sub((mpz_ptr)c, r->modNumber, (mpz_ptr)c);
254 return c;
255}

◆ nrnPower()

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

Definition at line 212 of file rmodulon.cc.

213{
214 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
215 mpz_init(erg);
216 mpz_powm_ui(erg, (mpz_ptr)a, i, r->modNumber);
217 *result = (number) erg;
218}

◆ nrnQuot1()

static coeffs nrnQuot1 ( number  c,
const coeffs  r 
)
static

Definition at line 105 of file rmodulon.cc.

106{
107 coeffs rr;
108 long ch = r->cfInt(c, r);
109 mpz_t a,b;
110 mpz_init_set(a, r->modNumber);
111 mpz_init_set_ui(b, ch);
112 mpz_t gcd;
113 mpz_init(gcd);
114 mpz_gcd(gcd, a,b);
115 if(mpz_cmp_ui(gcd, 1) == 0)
116 {
117 WerrorS("constant in q-ideal is coprime to modulus in ground ring");
118 WerrorS("Unable to create qring!");
119 return NULL;
120 }
121 if(r->modExponent == 1)
122 {
124 info.base = gcd;
125 info.exp = (unsigned long) 1;
126 rr = nInitChar(n_Zn, (void*)&info);
127 }
128 else
129 {
131 info.base = r->modBase;
132 int kNew = 1;
133 mpz_t baseTokNew;
134 mpz_init(baseTokNew);
135 mpz_set(baseTokNew, r->modBase);
136 while(mpz_cmp(gcd, baseTokNew) > 0)
137 {
138 kNew++;
139 mpz_mul(baseTokNew, baseTokNew, r->modBase);
140 }
141 //printf("\nkNew = %i\n",kNew);
142 info.exp = kNew;
143 mpz_clear(baseTokNew);
144 rr = nInitChar(n_Znm, (void*)&info);
145 }
146 mpz_clear(gcd);
147 return(rr);
148}
The main handler for Singular numbers which are suitable for Singular polynomials.

◆ nrnQuotRem()

static number nrnQuotRem ( number  a,
number  b,
number *  rem,
const coeffs  r 
)
static

Definition at line 673 of file rmodulon.cc.

674{
675 mpz_t g, aa, bb;
676 mpz_ptr qq = (mpz_ptr)omAllocBin(gmp_nrz_bin);
677 mpz_ptr rr = (mpz_ptr)omAllocBin(gmp_nrz_bin);
678 mpz_init(qq);
679 mpz_init(rr);
680 mpz_init(g);
681 mpz_init_set(aa, (mpz_ptr)a);
682 mpz_init_set(bb, (mpz_ptr)b);
683
684 mpz_gcd(g, bb, r->modNumber);
685 mpz_mod(rr, aa, g);
686 mpz_sub(aa, aa, rr);
687 mpz_gcd(g, aa, g);
688 mpz_div(aa, aa, g);
689 mpz_div(bb, bb, g);
690 mpz_div(g, r->modNumber, g);
691 mpz_invert(g, bb, g);
692 mpz_mul(qq, aa, g);
693 if (rem)
694 *rem = (number)rr;
695 else {
696 mpz_clear(rr);
698 }
699 mpz_clear(g);
700 mpz_clear(aa);
701 mpz_clear(bb);
702 return (number) qq;
703}
void rem(unsigned long *a, unsigned long *q, unsigned long p, int &dega, int degq)
Definition: minpoly.cc:572

◆ nrnRead()

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

Definition at line 955 of file rmodulon.cc.

956{
957 mpz_ptr z = (mpz_ptr) omAllocBin(gmp_nrz_bin);
958 {
959 s = nlCPEatLongC((char *)s, z);
960 }
961 mpz_mod(z, z, r->modNumber);
962 if ((*s)=='/')
963 {
964 mpz_ptr n = (mpz_ptr) omAllocBin(gmp_nrz_bin);
965 s++;
966 s=nlCPEatLongC((char*)s,n);
967 if (!nrnIsOne((number)n,r))
968 {
969 *a=nrnDiv((number)z,(number)n,r);
970 mpz_clear(z);
971 omFreeBin((void *)z, gmp_nrz_bin);
972 mpz_clear(n);
973 omFreeBin((void *)n, gmp_nrz_bin);
974 }
975 }
976 else
977 *a = (number) z;
978 return s;
979}
static const char * nlCPEatLongC(char *s, mpz_ptr i)
Definition: rmodulon.cc:931

◆ nrnSetExp()

static void nrnSetExp ( unsigned long  m,
coeffs  r 
)
static

Definition at line 894 of file rmodulon.cc.

895{
896 /* clean up former stuff */
897 if (r->modNumber != NULL) mpz_clear(r->modNumber);
898
899 r->modExponent= m;
900 r->modNumber = (mpz_ptr)omAllocBin(gmp_nrz_bin);
901 mpz_init_set (r->modNumber, r->modBase);
902 mpz_pow_ui (r->modNumber, r->modNumber, m);
903}

◆ nrnSetMap()

nMapFunc nrnSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 796 of file rmodulon.cc.

797{
798 /* dst = nrn */
799 if ((src->rep==n_rep_gmp) && nCoeff_is_Z(src))
800 {
801 return nrnMapZ;
802 }
803 if ((src->rep==n_rep_gap_gmp) /*&& nCoeff_is_Z(src)*/)
804 {
805 return nrnMapZ;
806 }
807 if (src->rep==n_rep_gap_rat) /*&& nCoeff_is_Q(src)) or Z*/
808 {
809 return nrnMapQ;
810 }
811 // Some type of Z/n ring / field
812 if (nCoeff_is_Zn(src) || nCoeff_is_Ring_PtoM(src) ||
814 {
815 if ( (!nCoeff_is_Zp(src))
816 && (mpz_cmp(src->modBase, dst->modBase) == 0)
817 && (src->modExponent == dst->modExponent)) return ndCopyMap;
818 else
819 {
820 mpz_ptr nrnMapModul = (mpz_ptr) omAllocBin(gmp_nrz_bin);
821 // Computing the n of Z/n
822 if (nCoeff_is_Zp(src))
823 {
824 mpz_init_set_si(nrnMapModul, src->ch);
825 }
826 else
827 {
828 mpz_init(nrnMapModul);
829 mpz_set(nrnMapModul, src->modNumber);
830 }
831 // nrnMapCoef = 1 in dst if dst is a subring of src
832 // nrnMapCoef = 0 in dst / src if src is a subring of dst
833 if (nrnMapCoef == NULL)
834 {
835 nrnMapCoef = (mpz_ptr) omAllocBin(gmp_nrz_bin);
836 mpz_init(nrnMapCoef);
837 }
838 if (mpz_divisible_p(nrnMapModul, dst->modNumber))
839 {
840 mpz_set_ui(nrnMapCoef, 1);
841 }
842 else
843 if (mpz_divisible_p(dst->modNumber,nrnMapModul))
844 {
845 mpz_divexact(nrnMapCoef, dst->modNumber, nrnMapModul);
846 mpz_ptr tmp = dst->modNumber;
847 dst->modNumber = nrnMapModul;
848 if (!nrnIsUnit((number) nrnMapCoef,dst))
849 {
850 dst->modNumber = tmp;
851 nrnDelete((number*) &nrnMapModul, dst);
852 return NULL;
853 }
854 mpz_ptr inv = (mpz_ptr) nrnInvers((number) nrnMapCoef,dst);
855 dst->modNumber = tmp;
856 mpz_mul(nrnMapCoef, nrnMapCoef, inv);
857 mpz_mod(nrnMapCoef, nrnMapCoef, dst->modNumber);
858 nrnDelete((number*) &inv, dst);
859 }
860 else
861 {
862 nrnDelete((number*) &nrnMapModul, dst);
863 return NULL;
864 }
865 nrnDelete((number*) &nrnMapModul, dst);
866 if (nCoeff_is_Ring_2toM(src))
867 return nrnMap2toM;
868 else if (nCoeff_is_Zp(src))
869 return nrnMapZp;
870 else
871 return nrnMapModN;
872 }
873 }
874 return NULL; // default
875}
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition: coeffs.h:813
number ndCopyMap(number a, const coeffs src, const coeffs dst)
Definition: numbers.cc:291
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:797
static FORCE_INLINE BOOLEAN nCoeff_is_Ring_2toM(const coeffs r)
Definition: coeffs.h:721
@ 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
static number nrnMap2toM(number from, const coeffs, const coeffs dst)
Definition: rmodulon.cc:716
static number nrnMapZ(number from, const coeffs src, const coeffs dst)
Definition: rmodulon.cc:764
static number nrnMapZp(number from, const coeffs, const coeffs dst)
Definition: rmodulon.cc:725
static number nrnMapQ(number from, const coeffs src, const coeffs dst)
Definition: rmodulon.cc:743
static number nrnMapModN(number from, const coeffs, const coeffs dst)
Definition: rmodulon.cc:711

◆ nrnSub()

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

Definition at line 235 of file rmodulon.cc.

236{
237 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
238 mpz_init(erg);
239 mpz_sub(erg, (mpz_ptr)a, (mpz_ptr) b);
240 mpz_mod(erg, erg, r->modNumber);
241 return (number) erg;
242}

◆ nrnWrite()

void nrnWrite ( number  a,
const  coeffs 
)

Definition at line 779 of file rmodulon.cc.

780{
781 char *s,*z;
782 if (a==NULL)
783 {
784 StringAppendS("o");
785 }
786 else
787 {
788 int l=mpz_sizeinbase((mpz_ptr) a, 10) + 2;
789 s=(char*)omAlloc(l);
790 z=mpz_get_str(s,10,(mpz_ptr) a);
791 StringAppendS(z);
793 }
794}
void StringAppendS(const char *st)
Definition: reporter.cc:107

◆ nrnXExtGcd()

static number nrnXExtGcd ( number  a,
number  b,
number *  s,
number *  t,
number *  u,
number *  v,
const coeffs  r 
)
static

Definition at line 401 of file rmodulon.cc.

402{
403 number xx;
404#ifdef CF_DEB
405 StringSetS("XExtGcd of ");
406 nrnWrite(a, r);
407 StringAppendS("\t");
408 nrnWrite(b, r);
409 StringAppendS(" modulo ");
410 nrnWrite(xx = (number)r->modNumber, r);
411 Print("%s\n", StringEndS());
412#endif
413
414 mpz_ptr one = (mpz_ptr)omAllocBin(gmp_nrz_bin);
415 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
416 mpz_ptr bs = (mpz_ptr)omAllocBin(gmp_nrz_bin);
417 mpz_ptr bt = (mpz_ptr)omAllocBin(gmp_nrz_bin);
418 mpz_ptr bu = (mpz_ptr)omAllocBin(gmp_nrz_bin);
419 mpz_ptr bv = (mpz_ptr)omAllocBin(gmp_nrz_bin);
420 mpz_init(erg);
421 mpz_init(one);
422 mpz_init_set(bs, (mpz_ptr) a);
423 mpz_init_set(bt, (mpz_ptr) b);
424 mpz_init(bu);
425 mpz_init(bv);
426 mpz_gcd(erg, bs, bt);
427
428#ifdef CF_DEB
429 StringSetS("1st gcd:");
430 nrnWrite(xx= (number)erg, r);
431#endif
432
433 mpz_gcd(erg, erg, r->modNumber);
434
435 mpz_div(bs, bs, erg);
436 mpz_div(bt, bt, erg);
437
438#ifdef CF_DEB
439 Print("%s\n", StringEndS());
440 StringSetS("xgcd: ");
441#endif
442
443 mpz_gcdext(one, bu, bv, bs, bt);
444 number ui = nrnGetUnit(xx = (number) one, r);
445#ifdef CF_DEB
446 n_Write(xx, r);
447 StringAppendS("\t");
448 n_Write(ui, r);
449 Print("%s\n", StringEndS());
450#endif
451 nrnDelete(&xx, r);
452 if (!nrnIsOne(ui, r))
453 {
454#ifdef CF_DEB
455 PrintS("Scaling\n");
456#endif
457 number uii = nrnInvers(ui, r);
458 nrnDelete(&ui, r);
459 ui = uii;
460 mpz_ptr uu = (mpz_ptr)omAllocBin(gmp_nrz_bin);
461 mpz_init_set(uu, (mpz_ptr)ui);
462 mpz_mul(bu, bu, uu);
463 mpz_mul(bv, bv, uu);
464 mpz_clear(uu);
466 }
467 nrnDelete(&ui, r);
468#ifdef CF_DEB
469 StringSetS("xgcd");
470 nrnWrite(xx= (number)bs, r);
471 StringAppendS("*");
472 nrnWrite(xx= (number)bu, r);
473 StringAppendS(" + ");
474 nrnWrite(xx= (number)bt, r);
475 StringAppendS("*");
476 nrnWrite(xx= (number)bv, r);
477 Print("%s\n", StringEndS());
478#endif
479
480 mpz_mod(bs, bs, r->modNumber);
481 mpz_mod(bt, bt, r->modNumber);
482 mpz_mod(bu, bu, r->modNumber);
483 mpz_mod(bv, bv, r->modNumber);
484 *s = (number)bu;
485 *t = (number)bv;
486 *u = (number)bt;
487 *u = nrnNeg(*u, r);
488 *v = (number)bs;
489 return (number)erg;
490}
static FORCE_INLINE void n_Write(number n, const coeffs r, const BOOLEAN bShortOut=TRUE)
Definition: coeffs.h:588
#define Print
Definition: emacs.cc:80
const Variable & v
< [in] a sqrfree bivariate poly
Definition: facBivar.h:39
void StringSetS(const char *st)
Definition: reporter.cc:128
void PrintS(const char *s)
Definition: reporter.cc:284
char * StringEndS()
Definition: reporter.cc:151

Variable Documentation

◆ gmp_nrz_bin

EXTERN_VAR omBin gmp_nrz_bin

Definition at line 33 of file rmodulon.cc.

◆ nrnCoeffName_buff

STATIC_VAR char* nrnCoeffName_buff =NULL

Definition at line 65 of file rmodulon.cc.

◆ nrnMapCoef

STATIC_VAR mpz_ptr nrnMapCoef = NULL

Definition at line 709 of file rmodulon.cc.