My Project
Macros | Functions | Variables
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)   nfDBTest(N,__FILE__,__LINE__, 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. More...
 
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 
)    nfDBTest(N,__FILE__,__LINE__, R)

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:4078
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:4103
#define nfTest(N, R)
Definition: ffields.cc:127
#define R
Definition: sirandom.c:27

◆ nfCoeffIsEqual()

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

Definition at line 844 of file ffields.cc.

845 {
846  if (n==n_GF) {
847  GFInfo* p = (GFInfo *)(parameter);
848  int c = (int)pow ((double)p->GFChar, (double)p->GFDegree);
849  if ((c == r->m_nfCharQ) && (strcmp(n_ParameterNames(r)[0], p->GFPar_name) == 0))
850  return TRUE;
851  }
852  return FALSE;
853 }
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:411
#define TRUE
Definition: auxiliary.h:100
#define FALSE
Definition: auxiliary.h:96
@ 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:775
Creation data needed for finite fields.
Definition: coeffs.h:93

◆ nfCoeffName()

static char* nfCoeffName ( const coeffs  r)
static

Definition at line 816 of file ffields.cc.

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

◆ nfCoeffWrite()

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

Definition at line 830 of file ffields.cc.

831 {
832  // m_nfCharQ = p^k where p is the characteristic (r->CharP) and k is GFDegree
833  Print("ZZ/%d[%s]",r->m_nfCharQ,n_ParameterNames(r)[0]);
834  if ( details )
835  {
836  StringSetS("\n// minpoly : ");
837  nfShowMipo(r);
838  StringAppendS("");
839  char *s=StringEndS(); PrintS(s); omFree(s);
840  }
841  else PrintS("// minpoly : ...");
842 }
#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)
Definition: omAllocDecl.h:261
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  {
338  WerrorS(nDivBy0);
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
#define LDEBUG
Definition: mod2.h:307
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:677

◆ 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 }
while(1)
Definition: libparse.cc:1444

◆ nfInitChar()

BOOLEAN nfInitChar ( coeffs  r,
void *  parameter 
)

Definition at line 854 of file ffields.cc.

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

◆ 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:4083

◆ 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  {
366  WerrorS(nDivBy0);
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 808 of file ffields.cc.

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

◆ 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;
703  i*= nfMapGG_factor;
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
Definition: facAbsBiFact.cc:75

◆ nfRandom()

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

Definition at line 825 of file ffields.cc.

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

◆ 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 CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:56
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 
640  nfReadMipo(buf);
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  (void)fgets( buf, sizeof(buf), fp);
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;
684 err:
685  Werror("illegal GF-table %d",r->m_nfCharQ);
686 }
CanonicalForm fp
Definition: cfModGcd.cc:4102
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
const unsigned short fftable[]
Definition: ffields.cc:27
#define omAlloc0(size)
Definition: omAllocDecl.h:211
int IsPrime(int p)
Definition: prime.cc:61
int status int void * buf
Definition: si_signals.h:59

◆ 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  return nfMapGG;
774  }
775  else if ((n1 % n2)==0)
776  {
777  nfMapGG_factor= (n1/n2);
778  return nfMapGGrev;
779  }
780  else
781  return NULL;
782  }
783  }
784  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src,dst->m_nfCharP))
785  {
786  return nfMapP; /* Z/p -> GF(p,n) */
787  }
788 
789  if (src->rep==n_rep_gap_rat) /*Q, bigint */
790  {
791  return nlModP; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
792  }
793  if (nCoeff_is_Z(src)) /* Z*/
794  {
795  return nfMapMPZ;
796  }
797  if (nCoeff_is_Zp(src) && (src->ch==dst->m_nfCharP)) /* Zp*/
798  {
799  return nfMapViaInt;
800  }
801 
802 
803  return NULL; /* default */
804 }
static FORCE_INLINE BOOLEAN nCoeff_is_GF(const coeffs r)
Definition: coeffs.h:836
static FORCE_INLINE BOOLEAN nCoeff_is_Z(const coeffs r)
Definition: coeffs.h:813
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:797
@ n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:111
@ n_rep_int
(int), see modulop.h
Definition: coeffs.h:110
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:1577
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:75

◆ 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.

◆ 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.