My Project
Loading...
Searching...
No Matches
ffields.cc File Reference
#include "misc/auxiliary.h"
#include "misc/mylimits.h"
#include "misc/sirandom.h"
#include "misc/prime.h"
#include "reporter/reporter.h"
#include "coeffs/coeffs.h"
#include "coeffs/numbers.h"
#include "coeffs/longrat.h"
#include "coeffs/ffields.h"
#include "coeffs/modulop.h"
#include <cmath>
#include <errno.h>

Go to the source code of this file.

Macros

#define nfTest(N, R)
 
#define sixteenlog2   11.09035489
 

Functions

static BOOLEAN nfDBTest (number a, const char *f, const int l, const coeffs r)
 
static BOOLEAN nfIsZero (number a, const coeffs r)
 
static BOOLEAN nfIsMOne (number a, const coeffs r)
 
static BOOLEAN nfGreaterZero (number k, const coeffs r)
 
static number nfMult (number a, number b, const coeffs r)
 
static number nfInit (long i, const coeffs r)
 
static number nfParameter (int i, const coeffs)
 
static int nfParDeg (number n, const coeffs r)
 
static long nfInt (number &n, const coeffs r)
 
static number nfAdd (number a, number b, const coeffs R)
 
static number nfNeg (number c, const coeffs r)
 
static number nfSub (number a, number b, const coeffs r)
 
static BOOLEAN nfIsOne (number a, const coeffs r)
 
static number nfDiv (number a, number b, const coeffs r)
 
static number nfInvers (number c, const coeffs r)
 
static BOOLEAN nfGreater (number a, number b, const coeffs r)
 
static BOOLEAN nfEqual (number a, number b, const coeffs r)
 
static void nfWriteLong (number a, const coeffs r)
 
static void nfWriteShort (number a, const coeffs r)
 
static void nfPower (number a, int i, number *result, const coeffs r)
 
static const char * nfEati (const char *s, int *i, const coeffs r)
 
static const char * nfRead (const char *s, number *a, const coeffs r)
 
int gf_tab_numdigits62 (int q)
 
int convertback62 (char *p, int n)
 
void nfShowMipo (const coeffs r)
 Show the mininimal polynom.... NOTE: this is used by char * sleftv::String(void *d, BOOLEAN typed, int dim) (from Singular/subexpr.cc) for printing minpoly.
 
static void nfReadMipo (char *s)
 
static void nfReadTable (const int c, const coeffs r)
 
static number nfMapP (number c, const coeffs, const coeffs dst)
 
static number nfMapGG (number c, const coeffs src, const coeffs)
 
static number nfMapGGrev (number c, const coeffs src, const coeffs)
 
static number nfMapMPZ (number c, const coeffs, const coeffs dst)
 
static number nfInitMPZ (mpz_t m, const coeffs cf)
 
static number nfMapViaInt (number c, const coeffs src, const coeffs dst)
 
static nMapFunc nfSetMap (const coeffs src, const coeffs dst)
 
static BOOLEAN nfCoeffIsEqual (const coeffs, n_coeffType, void *)
 
static void nfKillChar (coeffs r)
 
static char * nfCoeffName (const coeffs r)
 
static number nfRandom (siRandProc p, number, number, const coeffs cf)
 
static void nfCoeffWrite (const coeffs r, BOOLEAN details)
 
BOOLEAN nfInitChar (coeffs r, void *parameter)
 

Variables

const unsigned short fftable []
 
STATIC_VAR int nfMinPoly [16]
 
STATIC_VAR int nfMapGG_factor
 

Macro Definition Documentation

◆ nfTest

#define nfTest ( N,
R )
Value:
nfDBTest(N,__FILE__,__LINE__, R)
const CanonicalForm CFMap CFMap & N
Definition cfEzgcd.cc:56
static BOOLEAN nfDBTest(number a, const char *f, const int l, const coeffs r)
Definition ffields.cc:107
#define R
Definition sirandom.c:27

Definition at line 127 of file ffields.cc.

◆ sixteenlog2

#define sixteenlog2   11.09035489

Function Documentation

◆ convertback62()

int convertback62 ( char * p,
int n )

Definition at line 50 of file gf_tabutil.cc.

51{
52 int r = 0;
53 for ( int j = 0; j < n; j++ )
54 r = r * 62 + convback62( p[j] );
55 return r;
56}
int p
Definition cfModGcd.cc:4086
int j
Definition facHensel.cc:110
int convback62(char c)
Definition gf_tabutil.cc:40

◆ gf_tab_numdigits62()

int gf_tab_numdigits62 ( int q)

Definition at line 12 of file gf_tabutil.cc.

13{
14 if ( q < 62 )
15 return 1;
16 else if ( q < 62*62 )
17 return 2;
18 else
19 return 3;
20}

◆ nfAdd()

static number nfAdd ( number a,
number b,
const coeffs R )
static

Definition at line 254 of file ffields.cc.

255{
256/*4 z^a+z^b=z^b*(z^(a-b)+1), if a>=b; *
257* =z^a*(z^(b-a)+1) if a<b */
258#ifdef LDEBUG
259 nfTest(a, R);
260 nfTest(b, R);
261#endif
262 if ((long)R->m_nfCharQ == (long)a) return b;
263 if ((long)R->m_nfCharQ == (long)b) return a;
264 long zb,zab,r;
265 if ((long)a >= (long)b)
266 {
267 zb = (long)b;
268 zab = (long)a-(long)b;
269 }
270 else
271 {
272 zb = (long)a;
273 zab = (long)b-(long)a;
274 }
275#ifdef LDEBUG
276 nfTest((number)zab, R);
277#endif
278 if (R->m_nfPlus1Table[zab]==R->m_nfCharQ) r=(long)R->m_nfCharQ; /*if z^(a-b)+1 =0*/
279 else
280 {
281 r= zb+(long)R->m_nfPlus1Table[zab];
282 if(r>=(long)R->m_nfCharQ1) r-=(long)R->m_nfCharQ1;
283 }
284#ifdef LDEBUG
285 nfTest((number)r, R);
286#endif
287 return (number)r;
288}
CanonicalForm b
Definition cfModGcd.cc:4111
#define nfTest(N, R)
Definition ffields.cc:127

◆ nfCoeffIsEqual()

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

Definition at line 845 of file ffields.cc.

846{
847 if (n==n_GF) {
848 GFInfo* p = (GFInfo *)(parameter);
849 int c = (int)pow ((double)p->GFChar, (double)p->GFDegree);
850 if ((c == r->m_nfCharQ) && (strcmp(n_ParameterNames(r)[0], p->GFPar_name) == 0))
851 return TRUE;
852 }
853 return FALSE;
854}
Rational pow(const Rational &a, int e)
Definition GMPrat.cc:411
#define TRUE
Definition auxiliary.h:101
#define FALSE
Definition auxiliary.h:97
@ n_GF
\GF{p^n < 2^16}
Definition coeffs.h:32
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition coeffs.h:771
Creation data needed for finite fields.
Definition coeffs.h:100

◆ nfCoeffName()

static char * nfCoeffName ( const coeffs r)
static

Definition at line 817 of file ffields.cc.

818{
819 STATIC_VAR char nfCoeffName_buf[32];
820 const char *p=n_ParameterNames(r)[0];
821 nfCoeffName_buf[31]='\0';
822 snprintf(nfCoeffName_buf,31,"%d,%s",r->m_nfCharQ,p);
823 return nfCoeffName_buf;
824}
#define STATIC_VAR
Definition globaldefs.h:7

◆ nfCoeffWrite()

static void nfCoeffWrite ( const coeffs r,
BOOLEAN details )
static

Definition at line 831 of file ffields.cc.

832{
833 // m_nfCharQ = p^k where p is the characteristic (r->CharP) and k is GFDegree
834 Print("ZZ/%d[%s]",r->m_nfCharQ,n_ParameterNames(r)[0]);
835 if ( details )
836 {
837 StringSetS("\n// minpoly : ");
838 nfShowMipo(r);
839 StringAppendS("");
840 char *s=StringEndS(); PrintS(s); omFree(s);
841 }
842 else PrintS("// minpoly : ...");
843}
#define Print
Definition emacs.cc:80
const CanonicalForm int s
Definition facAbsFact.cc:51
void nfShowMipo(const coeffs r)
Show the mininimal polynom.... NOTE: this is used by char * sleftv::String(void *d,...
Definition ffields.cc:547
#define omFree(addr)
void StringSetS(const char *st)
Definition reporter.cc:128
void StringAppendS(const char *st)
Definition reporter.cc:107
void PrintS(const char *s)
Definition reporter.cc:284
char * StringEndS()
Definition reporter.cc:151

◆ nfDBTest()

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

Definition at line 107 of file ffields.cc.

108{
109 assume( r->m_nfPlus1Table != NULL );
110 if (((long)a<0L) || ((long)a>(long)r->m_nfCharQ))
111 {
112 Print("wrong %d in %s:%d\n",(int)((long)a),f,l);
113 return FALSE;
114 }
115 int i=0;
116 do
117 {
118 if (r->m_nfPlus1Table[i]>r->m_nfCharQ)
119 {
120 Print("wrong table %d=%d in %s:%d\n",i,r->m_nfPlus1Table[i],f,l);
121 return FALSE;
122 }
123 i++;
124 } while (i<r->m_nfCharQ);
125 return TRUE;
126}
int l
Definition cfEzgcd.cc:100
int i
Definition cfEzgcd.cc:132
FILE * f
Definition checklibs.c:9
#define assume(x)
Definition mod2.h:389
#define NULL
Definition omList.c:12

◆ nfDiv()

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

Definition at line 331 of file ffields.cc.

332{
333#ifdef LDEBUG
334 nfTest(b, r);
335#endif
336 if ((long)b==(long)r->m_nfCharQ)
337 {
339 return (number)((long)r->m_nfCharQ);
340 }
341#ifdef LDEBUG
342 nfTest(a, r);
343#endif
344 if ((long)a==(long)r->m_nfCharQ)
345 return (number)((long)r->m_nfCharQ);
346 /*else*/
347 long s = (long)a - (long)b;
348 if (s < 0L)
349 s += (long)r->m_nfCharQ1;
350#ifdef LDEBUG
351 nfTest((number)s, r);
352#endif
353 return (number)s;
354}
void WerrorS(const char *s)
Definition feFopen.cc:24
const char *const nDivBy0
Definition numbers.h:89

◆ nfEati()

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

Definition at line 497 of file ffields.cc.

498{
499 return nEati((char *)s,i,r->m_nfCharP);
500}
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition numbers.cc:665

◆ nfEqual()

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

Definition at line 390 of file ffields.cc.

391{
392#ifdef LDEBUG
393 nfTest(a, r);
394 nfTest(b, r);
395#endif
396 return (long)a == (long)b;
397}

◆ nfGreater()

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

Definition at line 378 of file ffields.cc.

379{
380#ifdef LDEBUG
381 nfTest(a, r);
382 nfTest(b, r);
383#endif
384 return (long)a > (long)b;
385}

◆ nfGreaterZero()

static BOOLEAN nfGreaterZero ( number k,
const coeffs r )
static

Definition at line 156 of file ffields.cc.

157{
158#ifdef LDEBUG
159 nfTest(k, r);
160#endif
161 return !nfIsZero(k, r) && !nfIsMOne(k, r);
162}
int k
Definition cfEzgcd.cc:99
static BOOLEAN nfIsMOne(number a, const coeffs r)
Definition ffields.cc:144
static BOOLEAN nfIsZero(number a, const coeffs r)
Definition ffields.cc:133

◆ nfInit()

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

Definition at line 187 of file ffields.cc.

188{
189 assume( r->m_nfPlus1Table != NULL );
190 // Hmm .. this is just to prevent initialization
191 // from nfInitChar to go into an infinite loop
192 if (i==0) return (number)(long)r->m_nfCharQ;
193 while (i < 0) i += r->m_nfCharP;
194 while (i >= r->m_nfCharP) i -= r->m_nfCharP;
195 if (i==0) return (number)(long)r->m_nfCharQ;
196 unsigned short c=0;
197 while (i>1)
198 {
199 c=r->m_nfPlus1Table[c];
200 i--;
201 }
202#ifdef LDEBUG
203 nfTest((number)(long)c, r);
204#endif
205 return (number)(long)c;
206}

◆ nfInitChar()

BOOLEAN nfInitChar ( coeffs r,
void * parameter )

Definition at line 855 of file ffields.cc.

856{
857 // the variables:
858 assume( getCoeffType(r) == n_GF );
859
860 GFInfo* p = (GFInfo *)(parameter);
861 assume (p->GFChar > 0);
862 assume (p->GFDegree > 0);
863 if(p->GFChar > (2<<15))
864 {
865#ifndef SING_NDEBUG
866 WarnS("illegal characteristic");
867#endif
868 return TRUE;
869 }
870
871 const double check= log ((double) (p->GFChar));
872
873 #define sixteenlog2 11.09035489
874 if( (p->GFDegree * check) > sixteenlog2 )
875 {
876#ifndef SING_NDEBUG
877 Warn("Sorry: illegal size: %u ^ %u", p->GFChar, p->GFDegree );
878#endif
879 return TRUE;
880 }
881
882 r->is_field=TRUE;
883 r->is_domain=TRUE;
884 r->rep=n_rep_gf;
885 //r->cfInitChar=npInitChar;
886 r->cfKillChar=nfKillChar;
887 r->nCoeffIsEqual=nfCoeffIsEqual;
888 r->cfCoeffName=nfCoeffName;
889
890 r->cfMult = nfMult;
891 r->cfSub = nfSub;
892 r->cfAdd = nfAdd;
893 r->cfDiv = nfDiv;
894 //r->cfIntMod= ndIntMod;
895 r->cfExactDiv= nfDiv;
896 r->cfInit = nfInit;
897 r->cfInitMPZ = nfInitMPZ;
898 //r->cfSize = ndSize;
899 r->cfInt = nfInt;
900 //r->cfDivComp = NULL; // only for ring stuff
901 //r->cfIsUnit = NULL; // only for ring stuff
902 //r->cfGetUnit = NULL; // only for ring stuff
903 //r->cfExtGcd = NULL; // only for ring stuff
904 // r->cfDivBy = NULL; // only for ring stuff
905 r->cfInpNeg = nfNeg;
906 r->cfInvers= nfInvers;
907 //r->cfCopy = ndCopy;
908 //r->cfRePart = ndCopy;
909 //r->cfImPart = ndReturn0;
910
911 r->cfWriteLong = nfWriteLong;
912 r->cfRead = nfRead;
913 //r->cfNormalize=ndNormalize;
914 r->cfGreater = nfGreater;
915 r->cfEqual = nfEqual;
916 r->cfIsZero = nfIsZero;
917 r->cfIsOne = nfIsOne;
918 r->cfIsMOne = nfIsMOne;
919 r->cfGreaterZero = nfGreaterZero;
920 r->cfPower = nfPower;
921 //r->cfGcd = ndGcd;
922 //r->cfLcm = ndGcd;
923 //r->cfDelete= ndDelete;
924 r->cfSetMap = nfSetMap;
925 //r->cfName = ndName;
926 // debug stuff
927 r->cfCoeffWrite=nfCoeffWrite;
928
929 r->cfParDeg = nfParDeg;
930
931 r->cfRandom = nfRandom;
932
933#ifdef LDEBUG
934 r->cfDBTest=nfDBTest;
935#endif
936
937
938 const char * name = p->GFPar_name;
939
940 r->m_nfCharQ = 0;
941 r->m_nfCharP = p->GFChar;
942 r->m_nfCharQ1 = 0;
943
944 r->iNumberOfParameters = 1;
945 r->cfParameter = nfParameter;
946
947 char ** pParameterNames = (char **) omAlloc(sizeof(char *));
948 assume( pParameterNames != NULL );
949 pParameterNames[0] = omStrDup(name);
950 assume( pParameterNames[0] != NULL );
951
952 r->pParameterNames = (const char**)pParameterNames;
953
954 r->m_nfPlus1Table= NULL;
955
956 if (strlen(name) > 1)
957 r->cfWriteShort = nfWriteLong;
958 else
959 r->cfWriteShort = nfWriteShort;
960
961 r->has_simple_Alloc=TRUE;
962 r->has_simple_Inverse=TRUE;
963
964 int c = (int)pow ((double)p->GFChar, (double)p->GFDegree);
965
966 nfReadTable(c, r);
967
968 if( r->m_nfPlus1Table == NULL )
969 {
970 Werror("reading table for field with %d elements failed",c);
971 return TRUE;
972 }
973
974
975 assume (r -> m_nfCharQ > 0);
976
977 r->ch = r->m_nfCharP;
978 assume( r->m_nfPlus1Table != NULL );
979
980 return FALSE;
981}
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition coeffs.h:429
@ n_rep_gf
(int), see ffields.h
Definition coeffs.h:126
#define Warn
Definition emacs.cc:77
#define WarnS
Definition emacs.cc:78
static number nfInitMPZ(mpz_t m, const coeffs cf)
Definition ffields.cc:728
static number nfAdd(number a, number b, const coeffs R)
Definition ffields.cc:254
static nMapFunc nfSetMap(const coeffs src, const coeffs dst)
Definition ffields.cc:749
static number nfInit(long i, const coeffs r)
Definition ffields.cc:187
static void nfKillChar(coeffs r)
Definition ffields.cc:809
static int nfParDeg(number n, const coeffs r)
Definition ffields.cc:224
static long nfInt(number &n, const coeffs r)
Definition ffields.cc:236
#define sixteenlog2
static number nfMult(number a, number b, const coeffs r)
Definition ffields.cc:167
static BOOLEAN nfGreaterZero(number k, const coeffs r)
Definition ffields.cc:156
static char * nfCoeffName(const coeffs r)
Definition ffields.cc:817
static void nfWriteShort(number a, const coeffs r)
Definition ffields.cc:436
static number nfSub(number a, number b, const coeffs r)
Definition ffields.cc:311
static number nfRandom(siRandProc p, number, number, const coeffs cf)
Definition ffields.cc:826
static BOOLEAN nfIsOne(number a, const coeffs r)
Definition ffields.cc:320
static void nfCoeffWrite(const coeffs r, BOOLEAN details)
Definition ffields.cc:831
static const char * nfRead(const char *s, number *a, const coeffs r)
Definition ffields.cc:505
static BOOLEAN nfGreater(number a, number b, const coeffs r)
Definition ffields.cc:378
static number nfNeg(number c, const coeffs r)
Definition ffields.cc:293
static BOOLEAN nfCoeffIsEqual(const coeffs, n_coeffType, void *)
Definition ffields.cc:845
static BOOLEAN nfEqual(number a, number b, const coeffs r)
Definition ffields.cc:390
static void nfReadTable(const int c, const coeffs r)
Definition ffields.cc:588
static void nfWriteLong(number a, const coeffs r)
Definition ffields.cc:402
static number nfDiv(number a, number b, const coeffs r)
Definition ffields.cc:331
static number nfParameter(int i, const coeffs)
Definition ffields.cc:211
static number nfInvers(number c, const coeffs r)
Definition ffields.cc:359
static void nfPower(number a, int i, number *result, const coeffs r)
Definition ffields.cc:469
VAR int check
Definition libparse.cc:1106
gmp_float log(const gmp_float &a)
#define omStrDup(s)
#define omAlloc(size)
void Werror(const char *fmt,...)
Definition reporter.cc:189
int name
New type name for int.

◆ nfInitMPZ()

static number nfInitMPZ ( mpz_t m,
const coeffs cf )
static

Definition at line 728 of file ffields.cc.

729{
730 mpz_t tmp;
731 mpz_init(tmp);
732 mpz_mod_ui(tmp,m,cf->m_nfCharP);
733 long l=mpz_get_si(tmp);
734 return nfInit(l,cf);
735}
int m
Definition cfEzgcd.cc:128
CanonicalForm cf
Definition cfModGcd.cc:4091

◆ nfInt()

static long nfInt ( number & n,
const coeffs r )
static

Definition at line 236 of file ffields.cc.

237{
238 unsigned short c=0;
239 unsigned short nn=(unsigned short)(long)n;
240 if (nn==r->m_nfCharQ) return 0;
241 long i=1; /* 1==a^0 */
242 while ((c!=nn)&&(i<r->m_nfCharP))
243 {
244 c=r->m_nfPlus1Table[c];
245 i++;
246 }
247 if (c==nn) return i;
248 else return 0;
249}

◆ nfInvers()

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

Definition at line 359 of file ffields.cc.

360{
361#ifdef LDEBUG
362 nfTest(c, r);
363#endif
364 if ((long)c==(long)r->m_nfCharQ)
365 {
367 return (number)((long)r->m_nfCharQ);
368 }
369#ifdef LDEBUG
370 nfTest(((number)((long)r->m_nfCharQ1-(long)c)), r);
371#endif
372 return (number)((long)r->m_nfCharQ1-(long)c);
373}

◆ nfIsMOne()

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

Definition at line 144 of file ffields.cc.

145{
146#ifdef LDEBUG
147 nfTest(a, r);
148#endif
149 if (0L == (long)a) return FALSE; /* special handling of char 2*/
150 return (long)r->m_nfM1 == (long)a;
151}

◆ nfIsOne()

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

Definition at line 320 of file ffields.cc.

321{
322#ifdef LDEBUG
323 nfTest(a, r);
324#endif
325 return 0L == (long)a;
326}

◆ nfIsZero()

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

Definition at line 133 of file ffields.cc.

134{
135#ifdef LDEBUG
136 nfTest(a, r);
137#endif
138 return (long)r->m_nfCharQ == (long)a;
139}

◆ nfKillChar()

static void nfKillChar ( coeffs r)
static

Definition at line 809 of file ffields.cc.

810{
811 char** p = (char**)n_ParameterNames(r);
812 /* only one parameter */
813 omFree( (ADDRESS)p[0] );
814 omFreeSize((ADDRESS)p, sizeof(char*));
815}
void * ADDRESS
Definition auxiliary.h:120
#define omFreeSize(addr, size)

◆ nfMapGG()

static number nfMapGG ( number c,
const coeffs src,
const coeffs  )
static

Definition at line 700 of file ffields.cc.

701{
702 int i=(long)c;
704 while (i >src->m_nfCharQ1) i-=src->m_nfCharQ1;
705 return (number)((long)i);
706}
STATIC_VAR int nfMapGG_factor
Definition ffields.cc:699

◆ nfMapGGrev()

static number nfMapGGrev ( number c,
const coeffs src,
const coeffs  )
static

Definition at line 710 of file ffields.cc.

711{
712 int ex=(int)((long)c);
713 if ((ex % nfMapGG_factor)==0)
714 return (number)(((long)ex) / ((long)nfMapGG_factor));
715 else
716 return (number)(long)src->m_nfCharQ; /* 0 */
717}

◆ nfMapMPZ()

static number nfMapMPZ ( number c,
const coeffs ,
const coeffs dst )
static

Definition at line 719 of file ffields.cc.

720{
721 mpz_t tmp;
722 mpz_init(tmp);
723 mpz_mod_ui(tmp,(mpz_ptr)c,dst->m_nfCharP);
724 long l=mpz_get_si(tmp);
725 return nfInit(l,dst);
726}

◆ nfMapP()

static number nfMapP ( number c,
const coeffs ,
const coeffs dst )
static

Definition at line 691 of file ffields.cc.

692{
693 return nfInit((int)((long)c), dst);
694}

◆ nfMapViaInt()

static number nfMapViaInt ( number c,
const coeffs src,
const coeffs dst )
static

Definition at line 737 of file ffields.cc.

738{
739 long i=src->cfInt(c,src);
740 if (i==0) return (number)(long)dst->m_nfCharQ;
741 while (i < 0) i += dst->m_nfCharP;
742 while (i >= dst->m_nfCharP) i -= dst->m_nfCharP;
743 return nfInit(i,dst);
744}

◆ nfMult()

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

Definition at line 167 of file ffields.cc.

168{
169#ifdef LDEBUG
170 nfTest(a, r);
171 nfTest(b, r);
172#endif
173 if (((long)a == (long)r->m_nfCharQ) || ((long)b == (long)r->m_nfCharQ))
174 return (number)(long)r->m_nfCharQ;
175 /*else*/
176 int i=(int)((long)a+(long)b);
177 if (i>=r->m_nfCharQ1) i-=r->m_nfCharQ1;
178#ifdef LDEBUG
179 nfTest((number)(long)i, r);
180#endif
181 return (number)(long)i;
182}

◆ nfNeg()

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

Definition at line 293 of file ffields.cc.

294{
295/*4 -z^c=z^c*(-1)=z^c*nfM1*/
296#ifdef LDEBUG
297 nfTest(c, r);
298#endif
299 if ((long)r->m_nfCharQ == (long)c) return c;
300 long i=(long)c+(long)r->m_nfM1;
301 if (i>=(long)r->m_nfCharQ1) i-=(long)r->m_nfCharQ1;
302#ifdef LDEBUG
303 nfTest((number)i, r);
304#endif
305 return (number)i;
306}

◆ nfParameter()

static number nfParameter ( int i,
const coeffs  )
static

Definition at line 211 of file ffields.cc.

212{
213 assume(i==1);
214
215 if( i == 1 )
216 return (number)1;
217
218 return NULL;
219}

◆ nfParDeg()

static int nfParDeg ( number n,
const coeffs r )
static

Definition at line 224 of file ffields.cc.

225{
226#ifdef LDEBUG
227 nfTest(n, r);
228#endif
229 if((long)r->m_nfCharQ == (long)n) return -1;
230 return (int)((long)n);
231}

◆ nfPower()

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

Definition at line 469 of file ffields.cc.

470{
471#ifdef LDEBUG
472 nfTest(a, r);
473#endif
474 if (i==0)
475 {
476 *result = (number)0L;
477 }
478 else if (i==1)
479 {
480 *result = a;
481 }
482 else
483 {
484 long rl;
485 if ((long)a == (long)r->m_nfCharQ) rl=(long)r->m_nfCharQ;
486 else rl=((long)a*(long)i) % (long)r->m_nfCharQ1;
487 *result = (number)rl;
488 }
489#ifdef LDEBUG
490 nfTest(*result, r);
491#endif
492}
return result

◆ nfRandom()

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

Definition at line 826 of file ffields.cc.

827{
828 return (number)(long)(p() %(cf->m_nfCharQ+1));
829}

◆ nfRead()

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

Definition at line 505 of file ffields.cc.

506{
507 int i;
508 number z;
509 number n;
510
511 s = nfEati(s, &i, r);
512 z=nfInit(i, r);
513 *a=z;
514 if (*s == '/')
515 {
516 s++;
517 s = nfEati(s, &i, r);
518 n=nfInit(i, r);
519 *a = nfDiv(z,n,r);
520 }
521 const char * const nf_Parameter = n_ParameterNames(r)[0];
522 const int N = strlen(nf_Parameter);
523 if (strncmp(s,nf_Parameter, N)==0)
524 {
525 s += N;
526 if ((*s >= '0') && (*s <= '9'))
527 {
528 s=eati(s,&i);
529 while (i>=r->m_nfCharQ1) i-=r->m_nfCharQ1;
530 }
531 else
532 i=1;
533 z=(number)(long)i;
534 *a=nfMult(*a,z,r);
535 }
536#ifdef LDEBUG
537 nfTest(*a, r);
538#endif
539 return s;
540}
const char * eati(const char *s, int *i)
Definition reporter.cc:373
static const char * nfEati(const char *s, int *i, const coeffs r)
Definition ffields.cc:497

◆ nfReadMipo()

static void nfReadMipo ( char * s)
static

Definition at line 563 of file ffields.cc.

564{
565 const char *l=strchr(s,';')+1;
566 char *n;
567 int i=strtol(l,&n,10);
568 l=n;
569 int j=1;
570 nfMinPoly[0]=i;
571 while(i>=0)
572 {
573 nfMinPoly[j]=strtol(l,&n,10);
574 if (l==n) break;
575 l=n;
576 j++;
577 i--;
578 }
579 if (i>=0)
580 {
581 WerrorS("error in reading minpoly from gftables");
582 }
583}
STATIC_VAR int nfMinPoly[16]
Definition ffields.cc:545

◆ nfReadTable()

static void nfReadTable ( const int c,
const coeffs r )
static

Definition at line 588 of file ffields.cc.

589{
590 //Print("GF(%d)\n",c);
591 if ((c==r->m_nfCharQ)||(c== -r->m_nfCharQ))
592 /*this field is already set*/ return;
593 int i=0;
594
595 if ((c>255) ||(c!=IsPrime(c)))
596 {
597 while ((fftable[i]!=c) && (fftable[i]!=0))
598 i++;
599
600 if (fftable[i]==0)
601 {
602 // illegal GF-table size: c
603 return;
604 }
605 }
606
607 if (r->m_nfCharQ > 1)
608 {
609 omFreeSize( (ADDRESS)r->m_nfPlus1Table,(r->m_nfCharQ+1)*sizeof(unsigned short) );
610 r->m_nfPlus1Table=NULL;
611 }
612 if ((c>1) || (c<0))
613 {
614 if (c>1) r->m_nfCharQ = c;
615 else r->m_nfCharQ = -c;
616 char buf[100];
617 sprintf(buf,"gftables/%d",r->m_nfCharQ);
618 FILE * fp = feFopen(buf,"r",NULL,TRUE);
619 if (fp==NULL)
620 {
621 return;
622 }
623 if(!fgets( buf, sizeof(buf), fp)) return;
624 if(strcmp(buf,"@@ factory GF(q) table @@\n")!=0)
625 {
626 goto err;
627 }
628 if(!fgets( buf, sizeof(buf), fp))
629 {
630 goto err;
631 }
632 int q;
633 int res = -1;
634 do
635 {
636 res = sscanf(buf,"%d %d",&r->m_nfCharP,&q);
637 }
638 while((res < 0) and (errno == EINTR));
639
641 r->m_nfCharQ1=r->m_nfCharQ-1;
642 //Print("nfCharQ=%d,nfCharQ1=%d,mipo=>>%s<<\n",nfCharQ,nfCharQ1,buf);
643 r->m_nfPlus1Table= (unsigned short *)omAlloc0( (r->m_nfCharQ+1)*sizeof(unsigned short) );
644 int digs = gf_tab_numdigits62( r->m_nfCharQ );
645 char * bufptr;
646 int i = 1;
647 int k;
648 while ( i < r->m_nfCharQ )
649 {
650 if (fgets( buf, sizeof(buf), fp)==NULL) goto err;
651 //( strlen( buffer ) == (size_t)digs * 30, "illegal table" );
652 bufptr = buf;
653 k = 0;
654 while ( (i < r->m_nfCharQ) && (k < 30) )
655 {
656 r->m_nfPlus1Table[i] = convertback62( bufptr, digs );
657 if(r->m_nfPlus1Table[i]>r->m_nfCharQ)
658 {
659 Print("wrong entry %d: %d(%c%c%c)\n",i,r->m_nfPlus1Table[i],bufptr[0],bufptr[1],bufptr[2]);
660 }
661 bufptr += digs;
662 if (r->m_nfPlus1Table[i]==r->m_nfCharQ)
663 {
664 if(i==r->m_nfCharQ1)
665 {
666 r->m_nfM1=0;
667 }
668 else
669 {
670 r->m_nfM1=i;
671 }
672 }
673 i++; k++;
674 }
675 }
676 r->m_nfPlus1Table[0]=r->m_nfPlus1Table[r->m_nfCharQ1];
677 }
678 else
679 r->m_nfCharQ=0;
680#ifdef LDEBUG
681 nfTest((number)0, r);
682#endif
683 return;
684err:
685 Werror("illegal GF-table %d",r->m_nfCharQ);
686}
CanonicalForm fp
Definition cfModGcd.cc:4110
const unsigned short fftable[]
Definition ffields.cc:27
CanonicalForm res
Definition facAbsFact.cc:60
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition feFopen.cc:47
int convertback62(char *p, int n)
Definition gf_tabutil.cc:50
static void nfReadMipo(char *s)
Definition ffields.cc:563
int gf_tab_numdigits62(int q)
Definition gf_tabutil.cc:12
#define omAlloc0(size)
int IsPrime(int p)
Definition prime.cc:61
int status int void * buf
Definition si_signals.h:69

◆ nfSetMap()

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

Definition at line 749 of file ffields.cc.

750{
751 if (nCoeff_is_GF(src))
752 {
753 const coeffs r = dst;
754 int q=src->ch;
755 if ((src->m_nfCharQ % q)==0) /* GF(p,n1) -> GF(p,n2), n2 > n1 */
756 {
757 // check if n2 is a multiple of n1
758 int n1=1;
759 int qq=r->m_nfCharP;
760 while(qq!=q) { qq *= r->m_nfCharP; n1++; }
761 int n2=1;
762 qq=r->m_nfCharP;
763 while(qq!=src->m_nfCharQ) { qq *= r->m_nfCharP; n2++; }
764 //Print("map %d^%d -> %d^%d\n",r->m_nfCharP,n1,r->m_nfCharP,n2);
765 if ((n2 % n1)==0)
766 {
767 int save_ch=r->m_nfCharQ;
768 nfReadTable(src->m_nfCharQ, r);
769 int nn=r->m_nfPlus1Table[0];
770 nfReadTable(save_ch, r);
771 nfMapGG_factor= r->m_nfPlus1Table[0] / nn;
772 //Print("nfMapGG_factor=%d (%d / %d)\n",nfMapGG_factor, r->m_nfPlus1Table[0], nn);
773 if (errorreported) return NULL;
774 else return nfMapGG;
775 }
776 else if ((n1 % n2)==0)
777 {
778 nfMapGG_factor= (n1/n2);
779 return nfMapGGrev;
780 }
781 else
782 return NULL;
783 }
784 }
785 if ((src->rep==n_rep_int) && nCoeff_is_Zp(src,dst->m_nfCharP))
786 {
787 return nfMapP; /* Z/p -> GF(p,n) */
788 }
789
790 if (src->rep==n_rep_gap_rat) /*Q, bigint */
791 {
792 return nlModP; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
793 }
794 if (nCoeff_is_Z(src)) /* Z*/
795 {
796 return nfMapMPZ;
797 }
798 if (nCoeff_is_Zp(src) && (src->ch==dst->m_nfCharP)) /* Zp*/
799 {
800 return nfMapViaInt;
801 }
802
803
804 return NULL; /* default */
805}
static FORCE_INLINE BOOLEAN nCoeff_is_GF(const coeffs r)
Definition coeffs.h:832
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition coeffs.h:809
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition coeffs.h:793
@ n_rep_gap_rat
(number), see longrat.h
Definition coeffs.h:118
@ n_rep_int
(int), see modulop.h
Definition coeffs.h:117
VAR short errorreported
Definition feFopen.cc:23
static number nfMapViaInt(number c, const coeffs src, const coeffs dst)
Definition ffields.cc:737
static number nfMapMPZ(number c, const coeffs, const coeffs dst)
Definition ffields.cc:719
static number nfMapGGrev(number c, const coeffs src, const coeffs)
Definition ffields.cc:710
static number nfMapP(number c, const coeffs, const coeffs dst)
Definition ffields.cc:691
static number nfMapGG(number c, const coeffs src, const coeffs)
Definition ffields.cc:700
number nlModP(number q, const coeffs, const coeffs Zp)
Definition longrat.cc:1573
The main handler for Singular numbers which are suitable for Singular polynomials.

◆ nfShowMipo()

void nfShowMipo ( const coeffs r)

Show the mininimal polynom.... NOTE: this is used by char * sleftv::String(void *d, BOOLEAN typed, int dim) (from Singular/subexpr.cc) for printing minpoly.

Definition at line 547 of file ffields.cc.

548{
549 int i=nfMinPoly[0];
550 int j=0;
551 loop
552 {
553 j++;
554 if (nfMinPoly[j]!=0)
555 StringAppend("%d*%s^%d",nfMinPoly[j],n_ParameterNames(r)[0],i);
556 i--;
557 if(i<0) break;
558 if (nfMinPoly[j]!=0)
559 StringAppendS("+");
560 }
561}
#define StringAppend
Definition emacs.cc:79
#define loop
Definition structs.h:71

◆ nfSub()

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

Definition at line 311 of file ffields.cc.

312{
313 number mb = nfNeg(b, r);
314 return nfAdd(a,mb,r);
315}

◆ nfWriteLong()

static void nfWriteLong ( number a,
const coeffs r )
static

Definition at line 402 of file ffields.cc.

403{
404#ifdef LDEBUG
405 nfTest(a, r);
406#endif
407 if ((long)a==(long)r->m_nfCharQ) StringAppendS("0");
408 else if ((long)a==0L) StringAppendS("1");
409 else if (nfIsMOne(a, r)) StringAppendS("-1");
410 else
411 {
412 int i=1; /* 1==a^0 */
413 unsigned short c=0;
414 unsigned short nn=(unsigned short)(long)a;
415 while ((c!=nn)&&(i<r->m_nfCharQ))
416 {
417 c=r->m_nfPlus1Table[c];
418 i++;
419 }
420 if (c==nn) StringAppend("%d",i);
421 else
422 {
424 if ((long)a!=1L)
425 {
426 StringAppend("^%d",(int)((long)a)); // long output!
427 }
428 }
429 }
430}

◆ nfWriteShort()

static void nfWriteShort ( number a,
const coeffs r )
static

Definition at line 436 of file ffields.cc.

437{
438#ifdef LDEBUG
439 nfTest(a, r);
440#endif
441 if ((long)a==(long)r->m_nfCharQ) StringAppendS("0");
442 else if ((long)a==0L) StringAppendS("1");
443 else if (nfIsMOne(a, r)) StringAppendS("-1");
444 else
445 {
446 int i=1; /* 1==a^0 */
447 unsigned short c=0;
448 unsigned short nn=(unsigned short)(long)a;
449 while ((c!=nn)&&(i<r->m_nfCharQ))
450 {
451 c=r->m_nfPlus1Table[c];
452 i++;
453 }
454 if (c==nn) StringAppend("%d",i);
455 else
456 {
458 if ((long)a!=1L)
459 {
460 StringAppend("%d",(int)((long)a));
461 }
462 }
463 }
464}

Variable Documentation

◆ fftable

const unsigned short fftable[]

Definition at line 27 of file ffields.cc.

27 {
28 4, 8, 16, 32, 64, 128, 256, 512,1024,2048,4096,8192,16384, 32768,
29/*2^2 2^3 2^4 2^5 2^6 2^7 2^8 2^9 2^10 2^11 2^12 2^13 2^14 2^15*/
30 9, 27, 81,243,729,2187, 6561,19683,59049,
31/*3^2 3^3 3^4 3^5 3^6 3^7 3^8 3^9 3^10*/
32 25,125,625,3125,15625,
33/*5^2 5^3 5^4 5^5 5^6*/
34 49,343,2401,16807,
35/*7^2 7^3 7^4 7^5*/
36 121,1331, 14641,
37/*11^2 11^3 11^4*/
38 169, 2197, 28561,
39/*13^2 13^3 13^4*/
40 289, 4913,
41/*17^2 17^3*/
42 361, 6859,
43/*19^2 19^3*/
44 529, 12167,
45/*23^2 23^3*/
46 841, 24389,
47/*29^2 29^3*/
48 961, 29791,
49/*31^2 31^3*/
50 1369, 50653,
51/*37^2 37^3*/
52 1681, /*41^2*/
53 1849, /*43^2*/
54 2209, /*47^2*/
55 2809, /*53^2*/
56 3481, /*59^2*/
57 3721, /*61^2*/
58 4489, /*67^2*/
59 5041, /*71^2*/
60 5329, /*73^2*/
61 6241, /*79^2*/
62 6889, /*83^2*/
63 7921, /*89^2*/
64 9409, /*97^2*/
65 10201, /*101^2*/
66 10609, /*103^2*/
67 11449, /*107^2*/
68 11881, /*109^2*/
69 12769, /*113^2*/
70 16129, /*127^2*/
71 17161, /*131^2*/
72 18769, /*137^2*/
73 19321, /*139^2*/
74 22201, /*149^2*/
75 22801, /*151^2*/
76 24649, /*157^2*/
77 26569, /*163^2*/
78 27889, /*167^2*/
79 29929, /*173^2*/
80 32041, /*179^2*/
81 32761, /*181^2*/
82 36481, /*191^2*/
83 37249, /*193^2*/
84 38809, /*197^2*/
85 39601, /*199^2*/
86 49729, /*223^2*/
87 44521, /*211^2*/
88 51529, /*227^2*/
89 52441, /*229^2*/
90 54289, /*233^2*/
91 57121, /*239^2*/
92 58081, /*241^2*/
93 63001, /*251^2*/
94 0 };

◆ nfMapGG_factor

STATIC_VAR int nfMapGG_factor

Definition at line 699 of file ffields.cc.

◆ nfMinPoly

STATIC_VAR int nfMinPoly[16]

Definition at line 545 of file ffields.cc.