My Project
Loading...
Searching...
No Matches
Data Structures | Functions
rmodulon.h File Reference
#include "misc/auxiliary.h"
#include "coeffs/coeffs.h"
#include "coeffs/rintegers.h"

Go to the source code of this file.

Data Structures

struct  ZnmInfo
 

Functions

BOOLEAN nrnInitChar (coeffs r, void *)
 
number nrnMapGMP (number from, const coeffs, const coeffs dst)
 
nMapFunc nrnSetMap (const coeffs src, const coeffs dst)
 
coeffs nrnInitCfByName (char *name, n_coeffType n)
 

Data Structure Documentation

◆ ZnmInfo

struct ZnmInfo

Definition at line 18 of file rmodulon.h.

Data Fields
mpz_ptr base
unsigned long exp

Function Documentation

◆ nrnInitCfByName()

coeffs nrnInitCfByName ( char *  name,
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}
int i
Definition: cfEzgcd.cc:132
@ 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
const CanonicalForm int s
Definition: facAbsFact.cc:51
#define info
Definition: libparse.cc:1256
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
#define NULL
Definition: omList.c:12

◆ 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}
#define FALSE
Definition: auxiliary.h:96
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 assume(x)
Definition: mod2.h:389
#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 number nrnInit(long i, const coeffs r)
Definition: rmodulon.cc:160
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 BOOLEAN nrnIsZero(number a, const coeffs)
Definition: rmodulon.cc:244
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
static BOOLEAN nrnIsUnit(number a, const coeffs r)
Definition: rmodulon.cc:543
#define nrnDelete
Definition: rmodulon.cc:177
nMapFunc nrnSetMap(const coeffs src, const coeffs dst)
Definition: rmodulon.cc:796
static number nrnInvers(number c, const coeffs r)
Definition: rmodulon.cc:257
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 BOOLEAN nrnEqual(number a, number b, const coeffs)
Definition: rmodulon.cc:350
static number nrnQuotRem(number a, number b, number *rem, const coeffs r)
Definition: rmodulon.cc:673
static long nrnInt(number &n, const coeffs)
Definition: rmodulon.cc:171
static BOOLEAN nrnIsOne(number a, const coeffs)
Definition: rmodulon.cc:345
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 nrnMult(number a, number b, const coeffs r)
Definition: rmodulon.cc:197
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 number nrnGcd(number a, number b, const coeffs r)
Definition: rmodulon.cc:277
static void nrnInpAdd(number &a, number b, const coeffs r)
Definition: rmodulon.cc:229
#define mpz_size1(A)
Definition: si_gmp.h:17

◆ 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}
#define omAllocBin(bin)
Definition: omAllocDecl.h:205
EXTERN_VAR omBin gmp_nrz_bin
Definition: rmodulon.cc:33

◆ 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_Ring_PtoM(const coeffs r)
Definition: coeffs.h:724
static FORCE_INLINE BOOLEAN nCoeff_is_Zn(const coeffs r)
Definition: coeffs.h:823
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_VAR mpz_ptr nrnMapCoef
Definition: rmodulon.cc:709
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