Macros | Functions | Variables
ffields.cc File Reference
#include "misc/auxiliary.h"
#include "omalloc/omalloc.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 <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

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 nMapFunc nfSetMap (const coeffs src, const coeffs dst)
 
static BOOLEAN nfCoeffIsEqual (const coeffs, n_coeffType, void *)
 
static void nfKillChar (coeffs r)
 
static char * nfCoeffString (const 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 int nfMinPoly [16]
 
static int nfMapGG_factor
 

Macro Definition Documentation

◆ nfTest

#define nfTest (   N,
  R 
)    nfDBTest(N,__FILE__,__LINE__, R)

Definition at line 131 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 j
Definition: facHensel.cc:105
int convback62(char c)
Definition: gf_tabutil.cc:40
int p
Definition: cfModGcd.cc:4019

◆ 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 258 of file ffields.cc.

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

◆ nfCoeffIsEqual()

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

Definition at line 842 of file ffields.cc.

843 {
844  if (n==n_GF) {
845  GFInfo* p = (GFInfo *)(parameter);
846  int c = (int)pow ((double)p->GFChar, (double)p->GFDegree);
847  if ((c == r->m_nfCharQ) && (strcmp(n_ParameterNames(r)[0], p->GFPar_name) == 0))
848  return TRUE;
849  }
850  return FALSE;
851 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:809
#define FALSE
Definition: auxiliary.h:94
const char * GFPar_name
Definition: coeffs.h:97
#define TRUE
Definition: auxiliary.h:98
Creation data needed for finite fields.
Definition: coeffs.h:93
int GFDegree
Definition: coeffs.h:96
int GFChar
Definition: coeffs.h:95
{p^n < 2^16}
Definition: coeffs.h:33
int p
Definition: cfModGcd.cc:4019
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:414

◆ nfCoeffName()

static char* nfCoeffName ( const coeffs  r)
static

Definition at line 814 of file ffields.cc.

815 {
816  static char nfCoeffName_buf[32];
817  const char *p=n_ParameterNames(r)[0];
818  nfCoeffName_buf[31]='\0';
819  snprintf(nfCoeffName_buf,31,"ZZ/%d[%s]",r->m_nfCharQ,p);
820  return nfCoeffName_buf;
821 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:809
int p
Definition: cfModGcd.cc:4019

◆ nfCoeffString()

static char* nfCoeffString ( const coeffs  r)
static

Definition at line 806 of file ffields.cc.

807 {
808  const char *p=n_ParameterNames(r)[0];
809  char *s=(char*)omAlloc(11+1+strlen(p));
810  sprintf(s,"%d,%s",r->m_nfCharQ,p);
811  return s;
812 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:809
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define omAlloc(size)
Definition: omAllocDecl.h:210
int p
Definition: cfModGcd.cc:4019

◆ nfCoeffWrite()

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

Definition at line 828 of file ffields.cc.

829 {
830  // m_nfCharQ = p^k where p is the characteristic (r->CharP) and k is GFDegree
831  Print("ZZ/%d[%s]",r->m_nfCharQ,n_ParameterNames(r)[0]);
832  if ( details )
833  {
834  StringSetS("\n// minpoly : ");
835  nfShowMipo(r);
836  StringAppendS("");
837  char *s=StringEndS(); PrintS(s); omFree(s);
838  }
839  else PrintS("// minpoly : ...");
840 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:809
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define Print
Definition: emacs.cc:80
char * StringEndS()
Definition: reporter.cc:151
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: ffields.cc:564
#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

◆ nfDBTest()

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

Definition at line 111 of file ffields.cc.

112 {
113  assume( r->m_nfPlus1Table != NULL );
114  if (((long)a<0L) || ((long)a>(long)r->m_nfCharQ))
115  {
116  Print("wrong %d in %s:%d\n",(int)((long)a),f,l);
117  return FALSE;
118  }
119  int i=0;
120  do
121  {
122  if (r->m_nfPlus1Table[i]>r->m_nfCharQ)
123  {
124  Print("wrong table %d=%d in %s:%d\n",i,r->m_nfPlus1Table[i],f,l);
125  return FALSE;
126  }
127  i++;
128  } while (i<r->m_nfCharQ);
129  return TRUE;
130 }
#define Print
Definition: emacs.cc:80
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
#define assume(x)
Definition: mod2.h:390
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:125
#define NULL
Definition: omList.c:10
int l
Definition: cfEzgcd.cc:93

◆ nfDiv()

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

Definition at line 335 of file ffields.cc.

336 {
337 #ifdef LDEBUG
338  nfTest(b, r);
339 #endif
340  if ((long)b==(long)r->m_nfCharQ)
341  {
342  WerrorS(nDivBy0);
343  return (number)((long)r->m_nfCharQ);
344  }
345 #ifdef LDEBUG
346  nfTest(a, r);
347 #endif
348  if ((long)a==(long)r->m_nfCharQ)
349  return (number)((long)r->m_nfCharQ);
350  /*else*/
351  long s = (long)a - (long)b;
352  if (s < 0L)
353  s += (long)r->m_nfCharQ1;
354 #ifdef LDEBUG
355  nfTest((number)s, r);
356 #endif
357  return (number)s;
358 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
void WerrorS(const char *s)
Definition: feFopen.cc:24
CanonicalForm b
Definition: cfModGcd.cc:4044
#define LDEBUG
Definition: mod2.h:308
const char *const nDivBy0
Definition: numbers.h:89
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfEati()

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

Definition at line 501 of file ffields.cc.

502 {
503  if (*s >= '0' && *s <= '9')
504  {
505  *i = 0;
506  do
507  {
508  *i *= 10;
509  *i += *s++ - '0';
510  if (*i > (MAX_INT_VAL / 10)) *i = *i % r->m_nfCharP;
511  }
512  while (*s >= '0' && *s <= '9');
513  if (*i >= r->m_nfCharP) *i = *i % r->m_nfCharP;
514  }
515  else *i = 1;
516  return s;
517 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const int MAX_INT_VAL
Definition: mylimits.h:12
int i
Definition: cfEzgcd.cc:125

◆ nfEqual()

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

Definition at line 394 of file ffields.cc.

395 {
396 #ifdef LDEBUG
397  nfTest(a, r);
398  nfTest(b, r);
399 #endif
400  return (long)a == (long)b;
401 }
CanonicalForm b
Definition: cfModGcd.cc:4044
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfGreater()

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

Definition at line 382 of file ffields.cc.

383 {
384 #ifdef LDEBUG
385  nfTest(a, r);
386  nfTest(b, r);
387 #endif
388  return (long)a != (long)b;
389 }
CanonicalForm b
Definition: cfModGcd.cc:4044
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfGreaterZero()

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

Definition at line 160 of file ffields.cc.

161 {
162 #ifdef LDEBUG
163  nfTest(k, r);
164 #endif
165  return !nfIsZero(k, r) && !nfIsMOne(k, r);
166 }
int k
Definition: cfEzgcd.cc:92
static BOOLEAN nfIsZero(number a, const coeffs r)
Definition: ffields.cc:137
#define nfTest(N, R)
Definition: ffields.cc:131
static BOOLEAN nfIsMOne(number a, const coeffs r)
Definition: ffields.cc:148

◆ nfInit()

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

Definition at line 191 of file ffields.cc.

192 {
193  assume( r->m_nfPlus1Table != NULL );
194  // Hmm .. this is just to prevent initialization
195  // from nfInitChar to go into an infinite loop
196  if (i==0) return (number)(long)r->m_nfCharQ;
197  while (i < 0) i += r->m_nfCharP;
198  while (i >= r->m_nfCharP) i -= r->m_nfCharP;
199  if (i==0) return (number)(long)r->m_nfCharQ;
200  unsigned short c=0;
201  while (i>1)
202  {
203  c=r->m_nfPlus1Table[c];
204  i--;
205  }
206 #ifdef LDEBUG
207  nfTest((number)(long)c, r);
208 #endif
209  return (number)(long)c;
210 }
#define assume(x)
Definition: mod2.h:390
while(1)
Definition: libparse.cc:1442
int i
Definition: cfEzgcd.cc:125
#define nfTest(N, R)
Definition: ffields.cc:131
#define NULL
Definition: omList.c:10

◆ nfInitChar()

BOOLEAN nfInitChar ( coeffs  r,
void *  parameter 
)

Definition at line 852 of file ffields.cc.

853 {
854  r->is_field=TRUE;
855  r->is_domain=TRUE;
856  r->rep=n_rep_gf;
857  //r->cfInitChar=npInitChar;
858  r->cfKillChar=nfKillChar;
859  r->nCoeffIsEqual=nfCoeffIsEqual;
860  r->cfCoeffString=nfCoeffString;
861  r->cfCoeffName=nfCoeffName;
862 
863  r->cfMult = nfMult;
864  r->cfSub = nfSub;
865  r->cfAdd = nfAdd;
866  r->cfDiv = nfDiv;
867  //r->cfIntMod= ndIntMod;
868  r->cfExactDiv= nfDiv;
869  r->cfInit = nfInit;
870  //r->cfSize = ndSize;
871  r->cfInt = nfInt;
872  #ifdef HAVE_RINGS
873  //r->cfDivComp = NULL; // only for ring stuff
874  //r->cfIsUnit = NULL; // only for ring stuff
875  //r->cfGetUnit = NULL; // only for ring stuff
876  //r->cfExtGcd = NULL; // only for ring stuff
877  // r->cfDivBy = NULL; // only for ring stuff
878  #endif
879  r->cfInpNeg = nfNeg;
880  r->cfInvers= nfInvers;
881  //r->cfCopy = ndCopy;
882  //r->cfRePart = ndCopy;
883  //r->cfImPart = ndReturn0;
884 
885  r->cfWriteLong = nfWriteLong;
886  r->cfRead = nfRead;
887  //r->cfNormalize=ndNormalize;
888  r->cfGreater = nfGreater;
889  r->cfEqual = nfEqual;
890  r->cfIsZero = nfIsZero;
891  r->cfIsOne = nfIsOne;
892  r->cfIsMOne = nfIsMOne;
893  r->cfGreaterZero = nfGreaterZero;
894  r->cfPower = nfPower;
895  //r->cfGcd = ndGcd;
896  //r->cfLcm = ndGcd;
897  //r->cfDelete= ndDelete;
898  r->cfSetMap = nfSetMap;
899  //r->cfName = ndName;
900  // debug stuff
901  r->cfCoeffWrite=nfCoeffWrite;
902 
903  r->cfParDeg = nfParDeg;
904 
905  r->cfRandom = nfRandom;
906 
907 #ifdef LDEBUG
908  r->cfDBTest=nfDBTest;
909 #endif
910 
911  // the variables:
912  assume( getCoeffType(r) == n_GF );
913 
914  GFInfo* p = (GFInfo *)(parameter);
915  assume (p->GFChar > 0);
916  assume (p->GFDegree > 0);
917 
918  const char * name = p->GFPar_name;
919 
920  r->m_nfCharQ = 0;
921  r->m_nfCharP = p->GFChar;
922  r->m_nfCharQ1 = 0;
923 
924  r->iNumberOfParameters = 1;
925  r->cfParameter = nfParameter;
926 
927  char ** pParameterNames = (char **) omAlloc0(sizeof(char *));
928  pParameterNames[0] = omStrDup(name); //TODO use omAlloc for allocating memory and use strcpy?
929 
930  assume( pParameterNames != NULL );
931  assume( pParameterNames[0] != NULL );
932 
933  r->pParameterNames = (const char**)pParameterNames;
934  // NOTE: r->m_nfParameter was replaced by n_ParameterNames(r)[0]
935 
936  // TODO: nfKillChar MUST destroy r->pParameterNames[0] (0-term. string) && r->pParameterNames (array of size 1)
937 
938  r->m_nfPlus1Table= NULL;
939 
940  if (strlen(name) > 1)
941  r->cfWriteShort = nfWriteLong;
942  else
943  r->cfWriteShort = nfWriteShort;
944 
945  r->has_simple_Alloc=TRUE;
946  r->has_simple_Inverse=TRUE;
947 
948  if(p->GFChar > (2<<15))
949  {
950 #ifndef SING_NDEBUG
951  WarnS("illegal characteristic");
952 #endif
953  return TRUE;
954  }
955 
956  const double check= log ((double) (p->GFChar));
957 
958  #define sixteenlog2 11.09035489
959  if( (p->GFDegree * check) > sixteenlog2 )
960  {
961 #ifndef SING_NDEBUG
962  Warn("Sorry: illegal size: %u ^ %u", p->GFChar, p->GFDegree );
963 #endif
964  return TRUE;
965  }
966 
967  int c = (int)pow ((double)p->GFChar, (double)p->GFDegree);
968 
969  nfReadTable(c, r);
970 
971  if( r->m_nfPlus1Table == NULL )
972  {
973  return TRUE;
974  }
975 
976 
977  assume (r -> m_nfCharQ > 0);
978 
979  r->ch = r->m_nfCharP;
980  assume( r->m_nfPlus1Table != NULL );
981 
982  return FALSE;
983 
984 }
static BOOLEAN nfCoeffIsEqual(const coeffs, n_coeffType, void *)
Definition: ffields.cc:842
static number nfRandom(siRandProc p, number, number, const coeffs cf)
Definition: ffields.cc:823
int check
Definition: libparse.cc:1104
#define FALSE
Definition: auxiliary.h:94
static number nfDiv(number a, number b, const coeffs r)
Definition: ffields.cc:335
static BOOLEAN nfGreaterZero(number k, const coeffs r)
Definition: ffields.cc:160
static const char * nfRead(const char *s, number *a, const coeffs r)
Definition: ffields.cc:522
const char * GFPar_name
Definition: coeffs.h:97
gmp_float log(const gmp_float &a)
Definition: mpr_complex.cc:344
#define TRUE
Definition: auxiliary.h:98
BOOLEAN nfDBTest(number a, const char *f, const int l, const coeffs r)
Definition: ffields.cc:111
static number nfSub(number a, number b, const coeffs r)
Definition: ffields.cc:315
static BOOLEAN nfIsOne(number a, const coeffs r)
Definition: ffields.cc:324
static number nfParameter(int i, const coeffs)
Definition: ffields.cc:215
static number nfNeg(number c, const coeffs r)
Definition: ffields.cc:297
#define WarnS
Definition: emacs.cc:78
static void nfKillChar(coeffs r)
Definition: ffields.cc:793
Creation data needed for finite fields.
Definition: coeffs.h:93
static void nfPower(number a, int i, number *result, const coeffs r)
Definition: ffields.cc:473
static char * nfCoeffString(const coeffs r)
Definition: ffields.cc:806
#define assume(x)
Definition: mod2.h:390
static void nfWriteShort(number a, const coeffs r)
Definition: ffields.cc:440
static BOOLEAN nfIsZero(number a, const coeffs r)
Definition: ffields.cc:137
static number nfAdd(number a, number b, const coeffs R)
Definition: ffields.cc:258
int GFDegree
Definition: coeffs.h:96
static nMapFunc nfSetMap(const coeffs src, const coeffs dst)
Definition: ffields.cc:739
char name(const Variable &v)
Definition: factory.h:180
static number nfMult(number a, number b, const coeffs r)
Definition: ffields.cc:171
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:422
static int nfParDeg(number n, const coeffs r)
Definition: ffields.cc:228
int GFChar
Definition: coeffs.h:95
#define NULL
Definition: omList.c:10
static number nfInvers(number c, const coeffs r)
Definition: ffields.cc:363
{p^n < 2^16}
Definition: coeffs.h:33
static void nfWriteLong(number a, const coeffs r)
Definition: ffields.cc:406
static number nfInit(long i, const coeffs r)
Definition: ffields.cc:191
static char * nfCoeffName(const coeffs r)
Definition: ffields.cc:814
static void nfReadTable(const int c, const coeffs r)
Definition: ffields.cc:605
static void nfCoeffWrite(const coeffs r, BOOLEAN details)
Definition: ffields.cc:828
int p
Definition: cfModGcd.cc:4019
(int), see ffields.h
Definition: coeffs.h:120
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:414
static BOOLEAN nfEqual(number a, number b, const coeffs r)
Definition: ffields.cc:394
static BOOLEAN nfIsMOne(number a, const coeffs r)
Definition: ffields.cc:148
static long nfInt(number &n, const coeffs r)
Definition: ffields.cc:240
static BOOLEAN nfGreater(number a, number b, const coeffs r)
Definition: ffields.cc:382
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define sixteenlog2
#define Warn
Definition: emacs.cc:77
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ nfInt()

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

Definition at line 240 of file ffields.cc.

241 {
242  unsigned short c=0;
243  unsigned short nn=(unsigned short)(long)n;
244  if (nn==r->m_nfCharQ) return 0;
245  long i=1; /* 1==a^0 */
246  while ((c!=nn)&&(i<r->m_nfCharP))
247  {
248  c=r->m_nfPlus1Table[c];
249  i++;
250  }
251  if (c==nn) return i;
252  else return 0;
253 }
int i
Definition: cfEzgcd.cc:125

◆ nfInvers()

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

Definition at line 363 of file ffields.cc.

364 {
365 #ifdef LDEBUG
366  nfTest(c, r);
367 #endif
368  if ((long)c==(long)r->m_nfCharQ)
369  {
370  WerrorS(nDivBy0);
371  return (number)((long)r->m_nfCharQ);
372  }
373 #ifdef LDEBUG
374  nfTest(((number)((long)r->m_nfCharQ1-(long)c)), r);
375 #endif
376  return (number)((long)r->m_nfCharQ1-(long)c);
377 }
void WerrorS(const char *s)
Definition: feFopen.cc:24
const char *const nDivBy0
Definition: numbers.h:89
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfIsMOne()

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

Definition at line 148 of file ffields.cc.

149 {
150 #ifdef LDEBUG
151  nfTest(a, r);
152 #endif
153  if (0L == (long)a) return FALSE; /* special handling of char 2*/
154  return (long)r->m_nfM1 == (long)a;
155 }
#define FALSE
Definition: auxiliary.h:94
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfIsOne()

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

Definition at line 324 of file ffields.cc.

325 {
326 #ifdef LDEBUG
327  nfTest(a, r);
328 #endif
329  return 0L == (long)a;
330 }
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfIsZero()

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

Definition at line 137 of file ffields.cc.

138 {
139 #ifdef LDEBUG
140  nfTest(a, r);
141 #endif
142  return (long)r->m_nfCharQ == (long)a;
143 }
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfKillChar()

static void nfKillChar ( coeffs  r)
static

Definition at line 793 of file ffields.cc.

794 {
795  char** p = (char**)n_ParameterNames(r);
796 
797  const int P = n_NumberOfParameters(r);
798 
799  for( int i = 1; i <= P; i++ )
800  if (p[i-1] != NULL)
801  omFree( (ADDRESS)p[i-1] );
802 
803  omFreeSize((ADDRESS)p, P * sizeof(char*));
804 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:809
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
void * ADDRESS
Definition: auxiliary.h:133
static FORCE_INLINE int n_NumberOfParameters(const coeffs r)
Returns the number of parameters.
Definition: coeffs.h:805
#define omFree(addr)
Definition: omAllocDecl.h:261
int i
Definition: cfEzgcd.cc:125
#define NULL
Definition: omList.c:10
int p
Definition: cfModGcd.cc:4019

◆ nfMapGG()

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

Definition at line 717 of file ffields.cc.

718 {
719  int i=(long)c;
720  i*= nfMapGG_factor;
721  while (i >src->m_nfCharQ1) i-=src->m_nfCharQ1;
722  return (number)((long)i);
723 }
static int nfMapGG_factor
Definition: ffields.cc:716
int i
Definition: cfEzgcd.cc:125

◆ nfMapGGrev()

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

Definition at line 727 of file ffields.cc.

728 {
729  int ex=(int)((long)c);
730  if ((ex % nfMapGG_factor)==0)
731  return (number)(((long)ex) / ((long)nfMapGG_factor));
732  else
733  return (number)(long)src->m_nfCharQ; /* 0 */
734 }
static int nfMapGG_factor
Definition: ffields.cc:716

◆ nfMapP()

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

Definition at line 708 of file ffields.cc.

709 {
710  return nfInit((int)((long)c), dst);
711 }
static number nfInit(long i, const coeffs r)
Definition: ffields.cc:191

◆ nfMult()

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

Definition at line 171 of file ffields.cc.

172 {
173 #ifdef LDEBUG
174  nfTest(a, r);
175  nfTest(b, r);
176 #endif
177  if (((long)a == (long)r->m_nfCharQ) || ((long)b == (long)r->m_nfCharQ))
178  return (number)(long)r->m_nfCharQ;
179  /*else*/
180  int i=(int)((long)a+(long)b);
181  if (i>=r->m_nfCharQ1) i-=r->m_nfCharQ1;
182 #ifdef LDEBUG
183  nfTest((number)(long)i, r);
184 #endif
185  return (number)(long)i;
186 }
CanonicalForm b
Definition: cfModGcd.cc:4044
int i
Definition: cfEzgcd.cc:125
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfNeg()

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

Definition at line 297 of file ffields.cc.

298 {
299 /*4 -z^c=z^c*(-1)=z^c*nfM1*/
300 #ifdef LDEBUG
301  nfTest(c, r);
302 #endif
303  if ((long)r->m_nfCharQ == (long)c) return c;
304  long i=(long)c+(long)r->m_nfM1;
305  if (i>=(long)r->m_nfCharQ1) i-=(long)r->m_nfCharQ1;
306 #ifdef LDEBUG
307  nfTest((number)i, r);
308 #endif
309  return (number)i;
310 }
int i
Definition: cfEzgcd.cc:125
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfParameter()

static number nfParameter ( int  i,
const coeffs   
)
static

Definition at line 215 of file ffields.cc.

216 {
217  assume(i==1);
218 
219  if( i == 1 )
220  return (number)1;
221 
222  return NULL;
223 }
#define assume(x)
Definition: mod2.h:390
int i
Definition: cfEzgcd.cc:125
#define NULL
Definition: omList.c:10

◆ nfParDeg()

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

Definition at line 228 of file ffields.cc.

229 {
230 #ifdef LDEBUG
231  nfTest(n, r);
232 #endif
233  if((long)r->m_nfCharQ == (long)n) return -1;
234  return (int)((long)n);
235 }
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfPower()

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

Definition at line 473 of file ffields.cc.

474 {
475 #ifdef LDEBUG
476  nfTest(a, r);
477 #endif
478  if (i==0)
479  {
480  *result = (number)0L;
481  }
482  else if (i==1)
483  {
484  *result = a;
485  }
486  else
487  {
488  long rl;
489  if ((long)a == (long)r->m_nfCharQ) rl=(long)r->m_nfCharQ;
490  else rl=((long)a*(long)i) % (long)r->m_nfCharQ1;
491  *result = (number)rl;
492  }
493 #ifdef LDEBUG
494  nfTest(*result, r);
495 #endif
496 }
int i
Definition: cfEzgcd.cc:125
#define nfTest(N, R)
Definition: ffields.cc:131
return result
Definition: facAbsBiFact.cc:76

◆ nfRandom()

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

Definition at line 823 of file ffields.cc.

824 {
825  return (number)(long)(p() %(cf->m_nfCharQ+1));
826 }
int p
Definition: cfModGcd.cc:4019

◆ nfRead()

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

Definition at line 522 of file ffields.cc.

523 {
524  int i;
525  number z;
526  number n;
527 
528  s = nfEati(s, &i, r);
529  z=nfInit(i, r);
530  *a=z;
531  if (*s == '/')
532  {
533  s++;
534  s = nfEati(s, &i, r);
535  n=nfInit(i, r);
536  *a = nfDiv(z,n,r);
537  }
538  const char * const nf_Parameter = n_ParameterNames(r)[0];
539  const int N = strlen(nf_Parameter);
540  if (strncmp(s,nf_Parameter, N)==0)
541  {
542  s += N;
543  if ((*s >= '0') && (*s <= '9'))
544  {
545  s=eati(s,&i);
546  while (i>=r->m_nfCharQ1) i-=r->m_nfCharQ1;
547  }
548  else
549  i=1;
550  z=(number)(long)i;
551  *a=nfMult(*a,z,r);
552  }
553 #ifdef LDEBUG
554  nfTest(*a, r);
555 #endif
556  return s;
557 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:809
const CanonicalForm int s
Definition: facAbsFact.cc:55
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:501
static number nfDiv(number a, number b, const coeffs r)
Definition: ffields.cc:335
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:48
int i
Definition: cfEzgcd.cc:125
static number nfMult(number a, number b, const coeffs r)
Definition: ffields.cc:171
#define nfTest(N, R)
Definition: ffields.cc:131
static number nfInit(long i, const coeffs r)
Definition: ffields.cc:191

◆ nfReadMipo()

static void nfReadMipo ( char *  s)
static

Definition at line 580 of file ffields.cc.

581 {
582  const char *l=strchr(s,';')+1;
583  char *n;
584  int i=strtol(l,&n,10);
585  l=n;
586  int j=1;
587  nfMinPoly[0]=i;
588  while(i>=0)
589  {
590  nfMinPoly[j]=strtol(l,&n,10);
591  if (l==n) break;
592  l=n;
593  j++;
594  i--;
595  }
596  if (i>=0)
597  {
598  WerrorS("error in reading minpoly from gftables");
599  }
600 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
int j
Definition: facHensel.cc:105
void WerrorS(const char *s)
Definition: feFopen.cc:24
int i
Definition: cfEzgcd.cc:125
int l
Definition: cfEzgcd.cc:93
static int nfMinPoly[16]
Definition: ffields.cc:562

◆ nfReadTable()

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

Definition at line 605 of file ffields.cc.

606 {
607  //Print("GF(%d)\n",c);
608  if ((c==r->m_nfCharQ)||(c== -r->m_nfCharQ))
609  /*this field is already set*/ return;
610  int i=0;
611 
612  if ((c>255) ||(c!=IsPrime(c)))
613  {
614  while ((fftable[i]!=c) && (fftable[i]!=0))
615  i++;
616 
617  if (fftable[i]==0)
618  {
619  // illegal GF-table size: c
620  return;
621  }
622  }
623 
624  if (r->m_nfCharQ > 1)
625  {
626  omFreeSize( (ADDRESS)r->m_nfPlus1Table,(r->m_nfCharQ+1)*sizeof(unsigned short) );
627  r->m_nfPlus1Table=NULL;
628  }
629  if ((c>1) || (c<0))
630  {
631  if (c>1) r->m_nfCharQ = c;
632  else r->m_nfCharQ = -c;
633  char buf[100];
634  sprintf(buf,"gftables/%d",r->m_nfCharQ);
635  FILE * fp = feFopen(buf,"r",NULL,TRUE);
636  if (fp==NULL)
637  {
638  return;
639  }
640  if(!fgets( buf, sizeof(buf), fp)) return;
641  if(strcmp(buf,"@@ factory GF(q) table @@\n")!=0)
642  {
643  goto err;
644  }
645  if(!fgets( buf, sizeof(buf), fp))
646  {
647  goto err;
648  }
649  int q;
650  int res = -1;
651  do
652  {
653  res = sscanf(buf,"%d %d",&r->m_nfCharP,&q);
654  }
655  while((res < 0) and (errno == EINTR));
656 
657  nfReadMipo(buf);
658  r->m_nfCharQ1=r->m_nfCharQ-1;
659  //Print("nfCharQ=%d,nfCharQ1=%d,mipo=>>%s<<\n",nfCharQ,nfCharQ1,buf);
660  r->m_nfPlus1Table= (unsigned short *)omAlloc0( (r->m_nfCharQ+1)*sizeof(unsigned short) );
661  int digs = gf_tab_numdigits62( r->m_nfCharQ );
662  char * bufptr;
663  int i = 1;
664  int k;
665  while ( i < r->m_nfCharQ )
666  {
667  (void)fgets( buf, sizeof(buf), fp);
668  //( strlen( buffer ) == (size_t)digs * 30, "illegal table" );
669  bufptr = buf;
670  k = 0;
671  while ( (i < r->m_nfCharQ) && (k < 30) )
672  {
673  r->m_nfPlus1Table[i] = convertback62( bufptr, digs );
674  if(r->m_nfPlus1Table[i]>r->m_nfCharQ)
675  {
676  Print("wrong entry %d: %d(%c%c%c)\n",i,r->m_nfPlus1Table[i],bufptr[0],bufptr[1],bufptr[2]);
677  }
678  bufptr += digs;
679  if (r->m_nfPlus1Table[i]==r->m_nfCharQ)
680  {
681  if(i==r->m_nfCharQ1)
682  {
683  r->m_nfM1=0;
684  }
685  else
686  {
687  r->m_nfM1=i;
688  }
689  }
690  i++; k++;
691  }
692  }
693  r->m_nfPlus1Table[0]=r->m_nfPlus1Table[r->m_nfCharQ1];
694  }
695  else
696  r->m_nfCharQ=0;
697 #ifdef LDEBUG
698  nfTest((number)0, r);
699 #endif
700  return;
701 err:
702  Werror("illegal GF-table %d",r->m_nfCharQ);
703 }
#define Print
Definition: emacs.cc:80
CanonicalForm fp
Definition: cfModGcd.cc:4043
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
#define TRUE
Definition: auxiliary.h:98
void * ADDRESS
Definition: auxiliary.h:133
int k
Definition: cfEzgcd.cc:92
static void nfReadMipo(char *s)
Definition: ffields.cc:580
CanonicalForm res
Definition: facAbsFact.cc:64
int gf_tab_numdigits62(int q)
Definition: gf_tabutil.cc:12
int status int void * buf
Definition: si_signals.h:59
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
int i
Definition: cfEzgcd.cc:125
int IsPrime(int p)
Definition: prime.cc:61
const unsigned short fftable[]
Definition: ffields.cc:31
#define nfTest(N, R)
Definition: ffields.cc:131
#define NULL
Definition: omList.c:10
int convertback62(char *p, int n)
Definition: gf_tabutil.cc:50
void Werror(const char *fmt,...)
Definition: reporter.cc:189
#define omAlloc0(size)
Definition: omAllocDecl.h:211

◆ nfSetMap()

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

Definition at line 739 of file ffields.cc.

740 {
741  if (nCoeff_is_GF(src,src->m_nfCharQ))
742  {
743  return ndCopyMap; /* GF(p,n) -> GF(p,n) */
744  }
745  if (nCoeff_is_GF(src))
746  {
747  const coeffs r = dst;
748  int q=src->ch;
749  if ((src->m_nfCharQ % q)==0) /* GF(p,n1) -> GF(p,n2), n2 > n1 */
750  {
751  // check if n2 is a multiple of n1
752  int n1=1;
753  int qq=r->m_nfCharP;
754  while(qq!=q) { qq *= r->m_nfCharP; n1++; }
755  int n2=1;
756  qq=r->m_nfCharP;
757  while(qq!=src->m_nfCharQ) { qq *= r->m_nfCharP; n2++; }
758  //Print("map %d^%d -> %d^%d\n",r->m_nfCharP,n1,r->m_nfCharP,n2);
759  if ((n2 % n1)==0)
760  {
761  int save_ch=r->m_nfCharQ;
762  nfReadTable(src->m_nfCharQ, r);
763  int nn=r->m_nfPlus1Table[0];
764  nfReadTable(save_ch, r);
765  nfMapGG_factor= r->m_nfPlus1Table[0] / nn;
766  //Print("nfMapGG_factor=%d (%d / %d)\n",nfMapGG_factor, r->m_nfPlus1Table[0], nn);
767  return nfMapGG;
768  }
769  else if ((n1 % n2)==0)
770  {
771  nfMapGG_factor= (n1/n2);
772  return nfMapGGrev;
773  }
774  else
775  return NULL;
776  }
777  }
778  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src,dst->m_nfCharP))
779  {
780  return nfMapP; /* Z/p -> GF(p,n) */
781  }
782 
783  if (src->rep==n_rep_gap_rat) /*Q, Z */
784  {
785  return nlModP; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
786  }
787 
788  return NULL; /* default */
789 }
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:831
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1436
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:251
static int nfMapGG_factor
Definition: ffields.cc:716
static number nfMapGG(number c, const coeffs src, const coeffs)
Definition: ffields.cc:717
static number nfMapP(number c, const coeffs, const coeffs dst)
Definition: ffields.cc:708
The main handler for Singular numbers which are suitable for Singular polynomials.
static FORCE_INLINE BOOLEAN nCoeff_is_GF(const coeffs r)
Definition: coeffs.h:853
(number), see longrat.h
Definition: coeffs.h:112
#define NULL
Definition: omList.c:10
static number nfMapGGrev(number c, const coeffs src, const coeffs)
Definition: ffields.cc:727
static void nfReadTable(const int c, const coeffs r)
Definition: ffields.cc:605
(int), see modulop.h
Definition: coeffs.h:111

◆ 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 564 of file ffields.cc.

565 {
566  int i=nfMinPoly[0];
567  int j=0;
568  loop
569  {
570  j++;
571  if (nfMinPoly[j]!=0)
572  StringAppend("%d*%s^%d",nfMinPoly[j],n_ParameterNames(r)[0],i);
573  i--;
574  if(i<0) break;
575  if (nfMinPoly[j]!=0)
576  StringAppendS("+");
577  }
578 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:809
int j
Definition: facHensel.cc:105
#define loop
Definition: structs.h:78
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define StringAppend
Definition: emacs.cc:79
int i
Definition: cfEzgcd.cc:125
static int nfMinPoly[16]
Definition: ffields.cc:562

◆ nfSub()

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

Definition at line 315 of file ffields.cc.

316 {
317  number mb = nfNeg(b, r);
318  return nfAdd(a,mb,r);
319 }
static number nfNeg(number c, const coeffs r)
Definition: ffields.cc:297
CanonicalForm b
Definition: cfModGcd.cc:4044
static number nfAdd(number a, number b, const coeffs R)
Definition: ffields.cc:258

◆ nfWriteLong()

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

Definition at line 406 of file ffields.cc.

407 {
408 #ifdef LDEBUG
409  nfTest(a, r);
410 #endif
411  if ((long)a==(long)r->m_nfCharQ) StringAppendS("0");
412  else if ((long)a==0L) StringAppendS("1");
413  else if (nfIsMOne(a, r)) StringAppendS("-1");
414  else
415  {
416  int i=1; /* 1==a^0 */
417  unsigned short c=0;
418  unsigned short nn=(unsigned short)(long)a;
419  while ((c!=nn)&&(i<r->m_nfCharQ))
420  {
421  c=r->m_nfPlus1Table[c];
422  i++;
423  }
424  if (c==nn) StringAppend("%d",i);
425  else
426  {
428  if ((long)a!=1L)
429  {
430  StringAppend("^%d",(int)((long)a)); // long output!
431  }
432  }
433  }
434 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:809
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define StringAppend
Definition: emacs.cc:79
int i
Definition: cfEzgcd.cc:125
#define nfTest(N, R)
Definition: ffields.cc:131
static BOOLEAN nfIsMOne(number a, const coeffs r)
Definition: ffields.cc:148

◆ nfWriteShort()

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

Definition at line 440 of file ffields.cc.

441 {
442 #ifdef LDEBUG
443  nfTest(a, r);
444 #endif
445  if ((long)a==(long)r->m_nfCharQ) StringAppendS("0");
446  else if ((long)a==0L) StringAppendS("1");
447  else if (nfIsMOne(a, r)) StringAppendS("-1");
448  else
449  {
450  int i=1; /* 1==a^0 */
451  unsigned short c=0;
452  unsigned short nn=(unsigned short)(long)a;
453  while ((c!=nn)&&(i<r->m_nfCharQ))
454  {
455  c=r->m_nfPlus1Table[c];
456  i++;
457  }
458  if (c==nn) StringAppend("%d",i);
459  else
460  {
462  if ((long)a!=1L)
463  {
464  StringAppend("%d",(int)((long)a));
465  }
466  }
467  }
468 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:809
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define StringAppend
Definition: emacs.cc:79
int i
Definition: cfEzgcd.cc:125
#define nfTest(N, R)
Definition: ffields.cc:131
static BOOLEAN nfIsMOne(number a, const coeffs r)
Definition: ffields.cc:148

Variable Documentation

◆ fftable

const unsigned short fftable[]

Definition at line 31 of file ffields.cc.

◆ nfMapGG_factor

int nfMapGG_factor
static

Definition at line 716 of file ffields.cc.

◆ nfMinPoly

int nfMinPoly[16]
static

Definition at line 562 of file ffields.cc.