My Project
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:354
const CanonicalForm int s
Definition: facAbsFact.cc:51
const ExtensionInfo & info
< [in] sqrfree poly
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
char * nEatLong(char *s, mpz_ptr i)
extracts a long integer from s, returns the rest
Definition: numbers.cc:652
#define NULL
Definition: omList.c:12

◆ nrnInitChar()

BOOLEAN nrnInitChar ( coeffs  r,
void *  p 
)

Definition at line 984 of file rmodulon.cc.

985{
986 assume( (getCoeffType(r) == n_Zn) || (getCoeffType (r) == n_Znm) );
987 ZnmInfo * info= (ZnmInfo *) p;
988 r->modBase= (mpz_ptr)nrnCopy((number)info->base, r); //this circumvents the problem
989 //in bigintmat.cc where we cannot create a "legal" nrn that can be freed.
990 //If we take a copy, we can do whatever we want.
991
992 nrnInitExp (info->exp, r);
993
994 /* next computation may yield wrong characteristic as r->modNumber
995 is a GMP number */
996 r->ch = mpz_get_ui(r->modNumber);
997
998 r->is_field=FALSE;
999 r->is_domain=FALSE;
1000 r->rep=n_rep_gmp;
1001
1002 r->cfInit = nrnInit;
1003 r->cfDelete = nrnDelete;
1004 r->cfCopy = nrnCopy;
1005 r->cfSize = nrnSize;
1006 r->cfInt = nrnInt;
1007 r->cfAdd = nrnAdd;
1008 r->cfSub = nrnSub;
1009 r->cfMult = nrnMult;
1010 r->cfDiv = nrnDiv;
1011 r->cfAnn = nrnAnn;
1012 r->cfIntMod = nrnMod;
1013 r->cfExactDiv = nrnDiv;
1014 r->cfInpNeg = nrnNeg;
1015 r->cfInvers = nrnInvers;
1016 r->cfDivBy = nrnDivBy;
1017 r->cfDivComp = nrnDivComp;
1018 r->cfGreater = nrnGreater;
1019 r->cfEqual = nrnEqual;
1020 r->cfIsZero = nrnIsZero;
1021 r->cfIsOne = nrnIsOne;
1022 r->cfIsMOne = nrnIsMOne;
1023 r->cfGreaterZero = nrnGreaterZero;
1024 r->cfWriteLong = nrnWrite;
1025 r->cfRead = nrnRead;
1026 r->cfPower = nrnPower;
1027 r->cfSetMap = nrnSetMap;
1028 //r->cfNormalize = ndNormalize;
1029 r->cfLcm = nrnLcm;
1030 r->cfGcd = nrnGcd;
1031 r->cfIsUnit = nrnIsUnit;
1032 r->cfGetUnit = nrnGetUnit;
1033 r->cfExtGcd = nrnExtGcd;
1034 r->cfXExtGcd = nrnXExtGcd;
1035 r->cfQuotRem = nrnQuotRem;
1036 r->cfCoeffName = nrnCoeffName;
1037 r->nCoeffIsEqual = nrnCoeffIsEqual;
1038 r->cfKillChar = nrnKillChar;
1039 r->cfQuot1 = nrnQuot1;
1040 r->cfInitMPZ = nrnInitMPZ;
1041 r->cfMPZ = nrnMPZ;
1042#if SI_INTEGER_VARIANT==2
1043 r->cfWriteFd = nrzWriteFd;
1044 r->cfReadFd = nrzReadFd;
1045#endif
1046
1047#ifdef LDEBUG
1048 r->cfDBTest = nrnDBTest;
1049#endif
1050 if ((r->modExponent==1)&&(mpz_size1(r->modBase)==1))
1051 {
1052 long p=mpz_get_si(r->modBase);
1053 if ((p<=FACTORY_MAX_PRIME)&&(p==IsPrime(p))) /*factory limit: <2^29*/
1054 {
1055 r->convFactoryNSingN=nrnConvFactoryNSingN;
1056 r->convSingNFactoryN=nrnConvSingNFactoryN;
1057 }
1058 }
1059 return FALSE;
1060}
#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:421
@ n_rep_gmp
(mpz_ptr), see rmodulon,h
Definition: coeffs.h:115
#define assume(x)
Definition: mod2.h:387
#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 void nrnKillChar(coeffs r)
Definition: rmodulon.cc:97
BOOLEAN nrnDBTest(number a, const char *f, const int l, const coeffs r)
Definition: rmodulon.cc:908
#define nrnSize
Definition: rmodulon.cc:178
static BOOLEAN nrnGreater(number a, number b, const coeffs)
Definition: rmodulon.cc:493
static BOOLEAN nrnIsZero(number a, const coeffs)
Definition: rmodulon.cc:235
static CanonicalForm nrnConvSingNFactoryN(number n, BOOLEAN setChar, const coeffs r)
Definition: rmodulon.cc:977
static number nrnExtGcd(number a, number b, number *s, number *t, const coeffs r)
Definition: rmodulon.cc:320
static void nrnMPZ(mpz_t m, number &n, const coeffs)
Definition: rmodulon.cc:876
static BOOLEAN nrnCoeffIsEqual(const coeffs r, n_coeffType n, void *parameter)
Definition: rmodulon.cc:89
void nrnWrite(number a, const coeffs)
Definition: rmodulon.cc:770
static number nrnMod(number a, number b, const coeffs r)
Definition: rmodulon.cc:617
static number nrnInitMPZ(mpz_t m, const coeffs r)
Definition: rmodulon.cc:868
static void nrnInitExp(unsigned long m, coeffs r)
Definition: rmodulon.cc:897
static number nrnAnn(number k, const coeffs r)
Definition: rmodulon.cc:542
static BOOLEAN nrnIsUnit(number a, const coeffs r)
Definition: rmodulon.cc:534
#define nrnDelete
Definition: rmodulon.cc:177
nMapFunc nrnSetMap(const coeffs src, const coeffs dst)
Definition: rmodulon.cc:787
static number nrnInvers(number c, const coeffs r)
Definition: rmodulon.cc:248
static number nrnConvFactoryNSingN(const CanonicalForm n, const coeffs r)
Definition: rmodulon.cc:972
static int nrnDivComp(number a, number b, const coeffs r)
Definition: rmodulon.cc:566
static const char * nrnRead(const char *s, number *a, const coeffs r)
Definition: rmodulon.cc:946
static number nrnXExtGcd(number a, number b, number *s, number *t, number *u, number *v, const coeffs r)
Definition: rmodulon.cc:392
static BOOLEAN nrnEqual(number a, number b, const coeffs)
Definition: rmodulon.cc:341
static number nrnQuotRem(number a, number b, number *rem, const coeffs r)
Definition: rmodulon.cc:664
static long nrnInt(number &n, const coeffs)
Definition: rmodulon.cc:171
static BOOLEAN nrnIsOne(number a, const coeffs)
Definition: rmodulon.cc:336
static number nrnCopy(number a, const coeffs)
Definition: rmodulon.cc:150
static number nrnSub(number a, number b, const coeffs r)
Definition: rmodulon.cc:226
static number nrnLcm(number a, number b, const coeffs r)
Definition: rmodulon.cc:287
static void nrnPower(number a, int i, number *result, const coeffs r)
Definition: rmodulon.cc:209
static number nrnMult(number a, number b, const coeffs r)
Definition: rmodulon.cc:200
static number nrnNeg(number c, const coeffs r)
Definition: rmodulon.cc:240
static number nrnGetUnit(number k, const coeffs r)
Definition: rmodulon.cc:346
static char * nrnCoeffName(const coeffs r)
Definition: rmodulon.cc:66
static number nrnDiv(number a, number b, const coeffs r)
Definition: rmodulon.cc:574
static BOOLEAN nrnIsMOne(number a, const coeffs r)
Definition: rmodulon.cc:483
static BOOLEAN nrnDivBy(number a, number b, const coeffs r)
Definition: rmodulon.cc:556
static BOOLEAN nrnGreaterZero(number k, const coeffs cf)
Definition: rmodulon.cc:498
static number nrnAdd(number a, number b, const coeffs r)
Definition: rmodulon.cc:217
static number nrnGcd(number a, number b, const coeffs r)
Definition: rmodulon.cc:268
#define mpz_size1(A)
Definition: si_gmp.h:17

◆ nrnMapGMP()

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

Definition at line 726 of file rmodulon.cc.

727{
728 mpz_ptr erg = (mpz_ptr)omAllocBin(gmp_nrz_bin);
729 mpz_init(erg);
730 mpz_mod(erg, (mpz_ptr)from, dst->modNumber);
731 return (number)erg;
732}
#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 787 of file rmodulon.cc.

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