Macros | Functions | Variables
ffields.cc File Reference
#include <misc/auxiliary.h>
#include <omalloc/omalloc.h>
#include <misc/mylimits.h>
#include <misc/sirandom.h>
#include <reporter/reporter.h>
#include "coeffs.h"
#include "numbers.h"
#include "longrat.h"
#include "ffields.h"
#include <string.h>
#include <math.h>
#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)
 
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
 
static char nfCoeffName_buf [32]
 

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 }
return P p
Definition: myNF.cc:203
int convback62(char c)
Definition: gf_tabutil.cc:40
const ring r
Definition: syzextra.cc:208
int j
Definition: myNF.cc:70

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

249 {
250 /*4 z^a+z^b=z^b*(z^(a-b)+1), if a>=b; *
251 * =z^a*(z^(b-a)+1) if a<b */
252 #ifdef LDEBUG
253  nfTest(a, R);
254  nfTest(b, R);
255 #endif
256  if ((long)R->m_nfCharQ == (long)a) return b;
257  if ((long)R->m_nfCharQ == (long)b) return a;
258  long zb,zab,r;
259  if ((long)a >= (long)b)
260  {
261  zb = (long)b;
262  zab = (long)a-(long)b;
263  }
264  else
265  {
266  zb = (long)a;
267  zab = (long)b-(long)a;
268  }
269 #ifdef LDEBUG
270  nfTest((number)zab, R);
271 #endif
272  if (R->m_nfPlus1Table[zab]==R->m_nfCharQ) r=(long)R->m_nfCharQ; /*if z^(a-b)+1 =0*/
273  else
274  {
275  r= zb+(long)R->m_nfPlus1Table[zab];
276  if(r>=(long)R->m_nfCharQ1) r-=(long)R->m_nfCharQ1;
277  }
278 #ifdef LDEBUG
279  nfTest((number)r, R);
280 #endif
281  return (number)r;
282 }
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
const ring R
Definition: DebugPrint.cc:36
#define nfTest(N, R)
Definition: ffields.cc:131
const poly b
Definition: syzextra.cc:213

◆ nfCoeffIsEqual()

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

Definition at line 805 of file ffields.cc.

806 {
807  if (n==n_GF) {
808  GFInfo* p = (GFInfo *)(parameter);
809  int c = pow (p->GFChar, p->GFDegree);
810  if ((c == r->m_nfCharQ) && (strcmp(n_ParameterNames(r)[0], p->GFPar_name) == 0))
811  return TRUE;
812  }
813  return FALSE;
814 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:812
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
#define TRUE
Definition: auxiliary.h:98
Creation data needed for finite fields.
Definition: coeffs.h:92
const ring r
Definition: syzextra.cc:208
{p^n < 2^16}
Definition: coeffs.h:33
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:418

◆ nfCoeffName()

static char* nfCoeffName ( const coeffs  r)
static

Definition at line 778 of file ffields.cc.

779 {
780  const char *p=n_ParameterNames(r)[0];
781  nfCoeffName_buf[31]='\0';
782  snprintf(nfCoeffName_buf,31,"ZZ/%d[%s]",r->m_nfCharQ,p);
783  return nfCoeffName_buf;
784 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:812
static char nfCoeffName_buf[32]
Definition: ffields.cc:777
return P p
Definition: myNF.cc:203
const ring r
Definition: syzextra.cc:208

◆ nfCoeffString()

static char* nfCoeffString ( const coeffs  r)
static

Definition at line 769 of file ffields.cc.

770 {
771  const char *p=n_ParameterNames(r)[0];
772  char *s=(char*)omAlloc(11+1+strlen(p));
773  sprintf(s,"%d,%s",r->m_nfCharQ,p);
774  return s;
775 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:812
const CanonicalForm int s
Definition: facAbsFact.cc:55
return P p
Definition: myNF.cc:203
#define omAlloc(size)
Definition: omAllocDecl.h:210
const ring r
Definition: syzextra.cc:208

◆ nfCoeffWrite()

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

Definition at line 791 of file ffields.cc.

792 {
793  // m_nfCharQ = p^k where p is the characteristic (r->CharP) and k is GFDegree
794  Print("ZZ/%d[%s]",r->m_nfCharQ,n_ParameterNames(r)[0]);
795  if ( details )
796  {
797  StringSetS("\n// minpoly : ");
798  nfShowMipo(r);
799  StringAppendS("");
800  char *s=StringEndS(); PrintS(s); omFree(s);
801  }
802  else PrintS("// minpoly : ...");
803 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:812
const CanonicalForm int s
Definition: facAbsFact.cc:55
#define Print
Definition: emacs.cc:83
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:530
const ring r
Definition: syzextra.cc:208
#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 }
const poly a
Definition: syzextra.cc:212
#define Print
Definition: emacs.cc:83
#define FALSE
Definition: auxiliary.h:94
#define TRUE
Definition: auxiliary.h:98
const ring r
Definition: syzextra.cc:208
#define assume(x)
Definition: mod2.h:394
FILE * f
Definition: checklibs.c:9
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
int l
Definition: cfEzgcd.cc:94

◆ nfDiv()

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

Definition at line 325 of file ffields.cc.

326 {
327 #ifdef LDEBUG
328  nfTest(b, r);
329 #endif
330  if ((long)b==(long)r->m_nfCharQ)
331  {
332  WerrorS(nDivBy0);
333  return (number)((long)r->m_nfCharQ);
334  }
335 #ifdef LDEBUG
336  nfTest(a, r);
337 #endif
338  if ((long)a==(long)r->m_nfCharQ)
339  return (number)((long)r->m_nfCharQ);
340  /*else*/
341  long s = (long)a - (long)b;
342  if (s < 0L)
343  s += (long)r->m_nfCharQ1;
344 #ifdef LDEBUG
345  nfTest((number)s, r);
346 #endif
347  return (number)s;
348 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const poly a
Definition: syzextra.cc:212
void WerrorS(const char *s)
Definition: feFopen.cc:24
const ring r
Definition: syzextra.cc:208
#define LDEBUG
Definition: mod2.h:312
const char *const nDivBy0
Definition: numbers.h:83
#define nfTest(N, R)
Definition: ffields.cc:131
const poly b
Definition: syzextra.cc:213

◆ nfEati()

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

Definition at line 467 of file ffields.cc.

468 {
469  if (*s >= '0' && *s <= '9')
470  {
471  *i = 0;
472  do
473  {
474  *i *= 10;
475  *i += *s++ - '0';
476  if (*i > (MAX_INT_VAL / 10)) *i = *i % r->m_nfCharP;
477  }
478  while (*s >= '0' && *s <= '9');
479  if (*i >= r->m_nfCharP) *i = *i % r->m_nfCharP;
480  }
481  else *i = 1;
482  return s;
483 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const ring r
Definition: syzextra.cc:208
const int MAX_INT_VAL
Definition: mylimits.h:12
int i
Definition: cfEzgcd.cc:123

◆ nfEqual()

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

Definition at line 384 of file ffields.cc.

385 {
386 #ifdef LDEBUG
387  nfTest(a, r);
388  nfTest(b, r);
389 #endif
390  return (long)a == (long)b;
391 }
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
#define nfTest(N, R)
Definition: ffields.cc:131
const poly b
Definition: syzextra.cc:213

◆ nfGreater()

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

Definition at line 372 of file ffields.cc.

373 {
374 #ifdef LDEBUG
375  nfTest(a, r);
376  nfTest(b, r);
377 #endif
378  return (long)a != (long)b;
379 }
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
#define nfTest(N, R)
Definition: ffields.cc:131
const poly b
Definition: syzextra.cc:213

◆ 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:93
const ring r
Definition: syzextra.cc:208
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 }
const ring r
Definition: syzextra.cc:208
#define assume(x)
Definition: mod2.h:394
while(1)
Definition: libparse.cc:1442
int i
Definition: cfEzgcd.cc:123
#define nfTest(N, R)
Definition: ffields.cc:131
#define NULL
Definition: omList.c:10

◆ nfInitChar()

BOOLEAN nfInitChar ( coeffs  r,
void *  parameter 
)

Definition at line 815 of file ffields.cc.

816 {
817  r->is_field=TRUE;
818  r->is_domain=TRUE;
819  r->rep=n_rep_gf;
820  //r->cfInitChar=npInitChar;
821  r->cfKillChar=nfKillChar;
822  r->nCoeffIsEqual=nfCoeffIsEqual;
823  r->cfCoeffString=nfCoeffString;
824  r->cfCoeffName=nfCoeffName;
825 
826  r->cfMult = nfMult;
827  r->cfSub = nfSub;
828  r->cfAdd = nfAdd;
829  r->cfDiv = nfDiv;
830  //r->cfIntMod= ndIntMod;
831  r->cfExactDiv= nfDiv;
832  r->cfInit = nfInit;
833  //r->cfSize = ndSize;
834  r->cfInt = nfInt;
835  #ifdef HAVE_RINGS
836  //r->cfDivComp = NULL; // only for ring stuff
837  //r->cfIsUnit = NULL; // only for ring stuff
838  //r->cfGetUnit = NULL; // only for ring stuff
839  //r->cfExtGcd = NULL; // only for ring stuff
840  // r->cfDivBy = NULL; // only for ring stuff
841  #endif
842  r->cfInpNeg = nfNeg;
843  r->cfInvers= nfInvers;
844  //r->cfCopy = ndCopy;
845  //r->cfRePart = ndCopy;
846  //r->cfImPart = ndReturn0;
847 
848  r->cfWriteLong = nfWriteLong;
849  r->cfRead = nfRead;
850  //r->cfNormalize=ndNormalize;
851  r->cfGreater = nfGreater;
852  r->cfEqual = nfEqual;
853  r->cfIsZero = nfIsZero;
854  r->cfIsOne = nfIsOne;
855  r->cfIsMOne = nfIsMOne;
856  r->cfGreaterZero = nfGreaterZero;
857  r->cfPower = nfPower;
858  //r->cfGcd = ndGcd;
859  //r->cfLcm = ndGcd;
860  //r->cfDelete= ndDelete;
861  r->cfSetMap = nfSetMap;
862  //r->cfName = ndName;
863  // debug stuff
864  r->cfCoeffWrite=nfCoeffWrite;
865 
866  r->cfParDeg = nfParDeg;
867 
868  r->cfRandom = nfRandom;
869 
870 #ifdef LDEBUG
871  r->cfDBTest=nfDBTest;
872 #endif
873 
874  // the variables:
875  r->nNULL = (number)0;
876  assume( getCoeffType(r) == n_GF );
877 
878  GFInfo* p = (GFInfo *)(parameter);
879  assume (p->GFChar > 0);
880  assume (p->GFDegree > 0);
881 
882  const char * name = p->GFPar_name;
883 
884  r->m_nfCharQ = 0;
885  r->m_nfCharP = p->GFChar;
886  r->m_nfCharQ1 = 0;
887 
888  r->iNumberOfParameters = 1;
889  r->cfParameter = nfParameter;
890 
891  char ** pParameterNames = (char **) omAlloc0(sizeof(char *));
892  pParameterNames[0] = omStrDup(name); //TODO use omAlloc for allocating memory and use strcpy?
893 
894  assume( pParameterNames != NULL );
895  assume( pParameterNames[0] != NULL );
896 
897  r->pParameterNames = (const char**)pParameterNames;
898  // NOTE: r->m_nfParameter was replaced by n_ParameterNames(r)[0]
899 
900  // TODO: nfKillChar MUST destroy r->pParameterNames[0] (0-term. string) && r->pParameterNames (array of size 1)
901 
902  r->m_nfPlus1Table= NULL;
903 
904  if (strlen(name) > 1)
905  r->cfWriteShort = nfWriteLong;
906  else
907  r->cfWriteShort = nfWriteShort;
908 
909  r->has_simple_Alloc=TRUE;
910  r->has_simple_Inverse=TRUE;
911 
912  if(p->GFChar > (2<<15))
913  {
914 #ifndef SING_NDEBUG
915  Warn("illegal characteristic");
916 #endif
917  return TRUE;
918  }
919 
920  const double check= log ((double) (p->GFChar));
921 
922  #define sixteenlog2 11.09035489
923  if( (p->GFDegree * check) > sixteenlog2 )
924  {
925 #ifndef SING_NDEBUG
926  Warn("Sorry: illegal size: %u ^ %u", p->GFChar, p->GFDegree );
927 #endif
928  return TRUE;
929  }
930 
931  int c = pow (p->GFChar, p->GFDegree);
932 
933  nfReadTable(c, r);
934 
935  if( r->m_nfPlus1Table == NULL )
936  {
937  return TRUE;
938  }
939 
940 
941  assume (r -> m_nfCharQ > 0);
942 
943  r->ch = r->m_nfCharP;
944  assume( r->m_nfPlus1Table != NULL );
945 
946  return FALSE;
947 
948 }
static long nfInt(number &n, const coeffs)
Definition: ffields.cc:240
static BOOLEAN nfCoeffIsEqual(const coeffs, n_coeffType, void *)
Definition: ffields.cc:805
static number nfRandom(siRandProc p, number, number, const coeffs cf)
Definition: ffields.cc:786
int check
Definition: libparse.cc:1104
#define FALSE
Definition: auxiliary.h:94
return P p
Definition: myNF.cc:203
static number nfDiv(number a, number b, const coeffs r)
Definition: ffields.cc:325
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:488
gmp_float log(const gmp_float &a)
Definition: mpr_complex.cc:345
#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:305
static BOOLEAN nfIsOne(number a, const coeffs r)
Definition: ffields.cc:314
static number nfParameter(int i, const coeffs)
Definition: ffields.cc:215
static number nfNeg(number c, const coeffs r)
Definition: ffields.cc:287
static void nfKillChar(coeffs r)
Definition: ffields.cc:756
Creation data needed for finite fields.
Definition: coeffs.h:92
static void nfPower(number a, int i, number *result, const coeffs r)
Definition: ffields.cc:439
const ring r
Definition: syzextra.cc:208
static char * nfCoeffString(const coeffs r)
Definition: ffields.cc:769
#define assume(x)
Definition: mod2.h:394
static void nfWriteShort(number a, const coeffs r)
Definition: ffields.cc:418
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:248
static nMapFunc nfSetMap(const coeffs src, const coeffs dst)
Definition: ffields.cc:702
char name(const Variable &v)
Definition: factory.h:178
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:425
static int nfParDeg(number n, const coeffs r)
Definition: ffields.cc:228
#define NULL
Definition: omList.c:10
static number nfInvers(number c, const coeffs r)
Definition: ffields.cc:353
{p^n < 2^16}
Definition: coeffs.h:33
static void nfWriteLong(number a, const coeffs r)
Definition: ffields.cc:396
static number nfInit(long i, const coeffs r)
Definition: ffields.cc:191
static char * nfCoeffName(const coeffs r)
Definition: ffields.cc:778
static void nfReadTable(const int c, const coeffs r)
Definition: ffields.cc:571
static void nfCoeffWrite(const coeffs r, BOOLEAN details)
Definition: ffields.cc:791
(int), see ffields.h
Definition: coeffs.h:119
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:418
static BOOLEAN nfEqual(number a, number b, const coeffs r)
Definition: ffields.cc:384
static BOOLEAN nfIsMOne(number a, const coeffs r)
Definition: ffields.cc:148
static BOOLEAN nfGreater(number a, number b, const coeffs r)
Definition: ffields.cc:372
#define omAlloc0(size)
Definition: omAllocDecl.h:211
#define sixteenlog2
#define Warn
Definition: emacs.cc:80
#define omStrDup(s)
Definition: omAllocDecl.h:263

◆ nfInt()

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

Definition at line 240 of file ffields.cc.

241 {
242  return (long)n;
243 }

◆ nfInvers()

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

Definition at line 353 of file ffields.cc.

354 {
355 #ifdef LDEBUG
356  nfTest(c, r);
357 #endif
358  if ((long)c==(long)r->m_nfCharQ)
359  {
360  WerrorS(nDivBy0);
361  return (number)((long)r->m_nfCharQ);
362  }
363 #ifdef LDEBUG
364  nfTest(((number)((long)r->m_nfCharQ1-(long)c)), r);
365 #endif
366  return (number)((long)r->m_nfCharQ1-(long)c);
367 }
void WerrorS(const char *s)
Definition: feFopen.cc:24
const ring r
Definition: syzextra.cc:208
const char *const nDivBy0
Definition: numbers.h:83
#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 }
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:94
const ring r
Definition: syzextra.cc:208
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfIsOne()

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

Definition at line 314 of file ffields.cc.

315 {
316 #ifdef LDEBUG
317  nfTest(a, r);
318 #endif
319  return 0L == (long)a;
320 }
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
#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 }
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
#define nfTest(N, R)
Definition: ffields.cc:131

◆ nfKillChar()

static void nfKillChar ( coeffs  r)
static

Definition at line 756 of file ffields.cc.

757 {
758  char** p = (char**)n_ParameterNames(r);
759 
760  const int P = n_NumberOfParameters(r);
761 
762  for( int i = 1; i <= P; i++ )
763  if (p[i-1] != NULL)
764  omFree( (ADDRESS)p[i-1] );
765 
766  omFreeSize((ADDRESS)p, P * sizeof(char*));
767 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:812
return P p
Definition: myNF.cc:203
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
void * ADDRESS
Definition: auxiliary.h:115
static FORCE_INLINE int n_NumberOfParameters(const coeffs r)
Returns the number of parameters.
Definition: coeffs.h:808
const ring r
Definition: syzextra.cc:208
#define omFree(addr)
Definition: omAllocDecl.h:261
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
kBucketDestroy & P
Definition: myNF.cc:191

◆ nfMapGG()

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

Definition at line 680 of file ffields.cc.

681 {
682  int i=(long)c;
683  i*= nfMapGG_factor;
684  while (i >src->m_nfCharQ1) i-=src->m_nfCharQ1;
685  return (number)((long)i);
686 }
static int nfMapGG_factor
Definition: ffields.cc:679
int i
Definition: cfEzgcd.cc:123

◆ nfMapGGrev()

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

Definition at line 690 of file ffields.cc.

691 {
692  int ex=(int)((long)c);
693  if ((ex % nfMapGG_factor)==0)
694  return (number)(((long)ex) / ((long)nfMapGG_factor));
695  else
696  return (number)(long)src->m_nfCharQ; /* 0 */
697 }
static int nfMapGG_factor
Definition: ffields.cc:679

◆ nfMapP()

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

Definition at line 671 of file ffields.cc.

672 {
673  return nfInit((int)((long)c), dst);
674 }
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 }
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
int i
Definition: cfEzgcd.cc:123
#define nfTest(N, R)
Definition: ffields.cc:131
const poly b
Definition: syzextra.cc:213

◆ nfNeg()

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

Definition at line 287 of file ffields.cc.

288 {
289 /*4 -z^c=z^c*(-1)=z^c*nfM1*/
290 #ifdef LDEBUG
291  nfTest(c, r);
292 #endif
293  if ((long)r->m_nfCharQ == (long)c) return c;
294  long i=(long)c+(long)r->m_nfM1;
295  if (i>=(long)r->m_nfCharQ1) i-=(long)r->m_nfCharQ1;
296 #ifdef LDEBUG
297  nfTest((number)i, r);
298 #endif
299  return (number)i;
300 }
const ring r
Definition: syzextra.cc:208
int i
Definition: cfEzgcd.cc:123
#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:394
int i
Definition: cfEzgcd.cc:123
#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 }
const ring r
Definition: syzextra.cc:208
#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 439 of file ffields.cc.

440 {
441 #ifdef LDEBUG
442  nfTest(a, r);
443 #endif
444  if (i==0)
445  {
446  *result = (number)0L;
447  }
448  else if (i==1)
449  {
450  *result = a;
451  }
452  else
453  {
454  long rl;
455  if ((long)a == (long)r->m_nfCharQ) rl=(long)r->m_nfCharQ;
456  else rl=((long)a*(long)i) % (long)r->m_nfCharQ1;
457  *result = (number)rl;
458  }
459 #ifdef LDEBUG
460  nfTest(*result, r);
461 #endif
462 }
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
int i
Definition: cfEzgcd.cc:123
#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 786 of file ffields.cc.

787 {
788  return (number)(long)(p() %(cf->m_nfCharQ+1));
789 }
return P p
Definition: myNF.cc:203
CanonicalForm cf
Definition: cfModGcd.cc:4024

◆ nfRead()

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

Definition at line 488 of file ffields.cc.

489 {
490  int i;
491  number z;
492  number n;
493 
494  s = nfEati(s, &i, r);
495  z=nfInit(i, r);
496  *a=z;
497  if (*s == '/')
498  {
499  s++;
500  s = nfEati(s, &i, r);
501  n=nfInit(i, r);
502  *a = nfDiv(z,n,r);
503  }
504  const char * const nf_Parameter = n_ParameterNames(r)[0];
505  const int N = strlen(nf_Parameter);
506  if (strncmp(s,nf_Parameter, N)==0)
507  {
508  s += N;
509  if ((*s >= '0') && (*s <= '9'))
510  {
511  s=eati(s,&i);
512  while (i>=r->m_nfCharQ1) i-=r->m_nfCharQ1;
513  }
514  else
515  i=1;
516  z=(number)(long)i;
517  *a=nfMult(*a,z,r);
518  }
519 #ifdef LDEBUG
520  nfTest(*a, r);
521 #endif
522  return s;
523 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:812
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:467
const poly a
Definition: syzextra.cc:212
static number nfDiv(number a, number b, const coeffs r)
Definition: ffields.cc:325
const ring r
Definition: syzextra.cc:208
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
int i
Definition: cfEzgcd.cc:123
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 546 of file ffields.cc.

547 {
548  const char *l=strchr(s,';')+1;
549  char *n;
550  int i=strtol(l,&n,10);
551  l=n;
552  int j=1;
553  nfMinPoly[0]=i;
554  while(i>=0)
555  {
556  nfMinPoly[j]=strtol(l,&n,10);
557  if (l==n) break;
558  l=n;
559  j++;
560  i--;
561  }
562  if (i>=0)
563  {
564  WerrorS("error in reading minpoly from gftables");
565  }
566 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
void WerrorS(const char *s)
Definition: feFopen.cc:24
int j
Definition: myNF.cc:70
int i
Definition: cfEzgcd.cc:123
int l
Definition: cfEzgcd.cc:94
static int nfMinPoly[16]
Definition: ffields.cc:528

◆ nfReadTable()

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

Definition at line 571 of file ffields.cc.

572 {
573  //Print("GF(%d)\n",c);
574  if ((c==r->m_nfCharQ)||(c==-r->m_nfCharQ))
575  /*this field is already set*/ return;
576  int i=0;
577 
578  while ((fftable[i]!=c) && (fftable[i]!=0))
579  i++;
580 
581  if (fftable[i]==0)
582  {
583  // illegal GF-table size: c
584  return;
585  }
586 
587  if (r->m_nfCharQ > 1)
588  {
589  omFreeSize( (ADDRESS)r->m_nfPlus1Table,r->m_nfCharQ*sizeof(unsigned short) );
590  r->m_nfPlus1Table=NULL;
591  }
592  if ((c>1) || (c<0))
593  {
594  if (c>1) r->m_nfCharQ = c;
595  else r->m_nfCharQ = -c;
596  char buf[100];
597  sprintf(buf,"gftables/%d",r->m_nfCharQ);
598  FILE * fp = feFopen(buf,"r",NULL,TRUE);
599  if (fp==NULL)
600  {
601  return;
602  }
603  if(!fgets( buf, sizeof(buf), fp)) return;
604  if(strcmp(buf,"@@ factory GF(q) table @@\n")!=0)
605  {
606  goto err;
607  }
608  if(!fgets( buf, sizeof(buf), fp))
609  {
610  goto err;
611  }
612  int q;
613  int res = -1;
614  do
615  {
616  res = sscanf(buf,"%d %d",&r->m_nfCharP,&q);
617  }
618  while((res < 0) and (errno == EINTR));
619 
620  nfReadMipo(buf);
621  r->m_nfCharQ1=r->m_nfCharQ-1;
622  //Print("nfCharQ=%d,nfCharQ1=%d,mipo=>>%s<<\n",nfCharQ,nfCharQ1,buf);
623  r->m_nfPlus1Table= (unsigned short *)omAlloc( (r->m_nfCharQ)*sizeof(unsigned short) );
624  int digs = gf_tab_numdigits62( r->m_nfCharQ );
625  char * bufptr;
626  int i = 1;
627  int k;
628  while ( i < r->m_nfCharQ )
629  {
630  (void)fgets( buf, sizeof(buf), fp);
631  //( strlen( buffer ) == (size_t)digs * 30, "illegal table" );
632  bufptr = buf;
633  k = 0;
634  while ( (i < r->m_nfCharQ) && (k < 30) )
635  {
636  r->m_nfPlus1Table[i] = convertback62( bufptr, digs );
637  if(r->m_nfPlus1Table[i]>r->m_nfCharQ)
638  {
639  Print("wrong entry %d: %d(%c%c%c)\n",i,r->m_nfPlus1Table[i],bufptr[0],bufptr[1],bufptr[2]);
640  }
641  bufptr += digs;
642  if (r->m_nfPlus1Table[i]==r->m_nfCharQ)
643  {
644  if(i==r->m_nfCharQ1)
645  {
646  r->m_nfM1=0;
647  }
648  else
649  {
650  r->m_nfM1=i;
651  }
652  }
653  i++; k++;
654  }
655  }
656  r->m_nfPlus1Table[0]=r->m_nfPlus1Table[r->m_nfCharQ1];
657  }
658  else
659  r->m_nfCharQ=0;
660 #ifdef LDEBUG
661  nfTest((number)0, r);
662 #endif
663  return;
664 err:
665  Werror("illegal GF-table %d",r->m_nfCharQ);
666 }
#define Print
Definition: emacs.cc:83
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:115
int k
Definition: cfEzgcd.cc:93
#define omAlloc(size)
Definition: omAllocDecl.h:210
poly res
Definition: myNF.cc:322
static void nfReadMipo(char *s)
Definition: ffields.cc:546
const ring r
Definition: syzextra.cc:208
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:123
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

◆ nfSetMap()

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

Definition at line 702 of file ffields.cc.

703 {
704  if (nCoeff_is_GF(src,src->m_nfCharQ))
705  {
706  return ndCopyMap; /* GF(p,n) -> GF(p,n) */
707  }
708  if (nCoeff_is_GF(src))
709  {
710  const coeffs r = dst;
711  int q=src->ch;
712  if ((src->m_nfCharQ % q)==0) /* GF(p,n1) -> GF(p,n2), n2 > n1 */
713  {
714  // check if n2 is a multiple of n1
715  int n1=1;
716  int qq=r->m_nfCharP;
717  while(qq!=q) { qq *= r->m_nfCharP; n1++; }
718  int n2=1;
719  qq=r->m_nfCharP;
720  while(qq!=src->m_nfCharQ) { qq *= r->m_nfCharP; n2++; }
721  //Print("map %d^%d -> %d^%d\n",r->m_nfCharP,n1,r->m_nfCharP,n2);
722  if ((n2 % n1)==0)
723  {
724  int save_ch=r->m_nfCharQ;
725  nfReadTable(src->m_nfCharQ, r);
726  int nn=r->m_nfPlus1Table[0];
727  nfReadTable(save_ch, r);
728  nfMapGG_factor= r->m_nfPlus1Table[0] / nn;
729  //Print("nfMapGG_factor=%d (%d / %d)\n",nfMapGG_factor, r->m_nfPlus1Table[0], nn);
730  return nfMapGG;
731  }
732  else if ((n1 % n2)==0)
733  {
734  nfMapGG_factor= (n1/n2);
735  return nfMapGGrev;
736  }
737  else
738  return NULL;
739  }
740  }
741  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src,dst->m_nfCharP))
742  {
743  return nfMapP; /* Z/p -> GF(p,n) */
744  }
745 
746  if (src->rep==n_rep_gap_rat) /*Q, Z */
747  {
748  return nlModP; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
749  }
750 
751  return NULL; /* default */
752 }
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:834
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1440
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:244
static int nfMapGG_factor
Definition: ffields.cc:679
static number nfMapGG(number c, const coeffs src, const coeffs)
Definition: ffields.cc:680
static number nfMapP(number c, const coeffs, const coeffs dst)
Definition: ffields.cc:671
const ring r
Definition: syzextra.cc:208
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:856
(number), see longrat.h
Definition: coeffs.h:111
#define NULL
Definition: omList.c:10
static number nfMapGGrev(number c, const coeffs src, const coeffs)
Definition: ffields.cc:690
static void nfReadTable(const int c, const coeffs r)
Definition: ffields.cc:571
(int), see modulop.h
Definition: coeffs.h:110

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

531 {
532  int i=nfMinPoly[0];
533  int j=0;
534  loop
535  {
536  j++;
537  if (nfMinPoly[j]!=0)
538  StringAppend("%d*%s^%d",nfMinPoly[j],n_ParameterNames(r)[0],i);
539  i--;
540  if(i<0) break;
541  if (nfMinPoly[j]!=0)
542  StringAppendS("+");
543  }
544 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:812
loop
Definition: myNF.cc:98
const ring r
Definition: syzextra.cc:208
int j
Definition: myNF.cc:70
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define StringAppend
Definition: emacs.cc:82
int i
Definition: cfEzgcd.cc:123
static int nfMinPoly[16]
Definition: ffields.cc:528

◆ nfSub()

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

Definition at line 305 of file ffields.cc.

306 {
307  number mb = nfNeg(b, r);
308  return nfAdd(a,mb,r);
309 }
const poly a
Definition: syzextra.cc:212
static number nfNeg(number c, const coeffs r)
Definition: ffields.cc:287
const ring r
Definition: syzextra.cc:208
static number nfAdd(number a, number b, const coeffs R)
Definition: ffields.cc:248
const poly b
Definition: syzextra.cc:213

◆ nfWriteLong()

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

Definition at line 396 of file ffields.cc.

397 {
398 #ifdef LDEBUG
399  nfTest(a, r);
400 #endif
401  if ((long)a==(long)r->m_nfCharQ) StringAppendS("0");
402  else if ((long)a==0L) StringAppendS("1");
403  else if (nfIsMOne(a, r)) StringAppendS("-1");
404  else
405  {
407  if ((long)a!=1L)
408  {
409  StringAppend("^%d",(int)((long)a)); // long output!
410  }
411  }
412 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:812
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define StringAppend
Definition: emacs.cc:82
#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 418 of file ffields.cc.

419 {
420 #ifdef LDEBUG
421  nfTest(a, r);
422 #endif
423  if ((long)a==(long)r->m_nfCharQ) StringAppendS("0");
424  else if ((long)a==0L) StringAppendS("1");
425  else if (nfIsMOne(a, r)) StringAppendS("-1");
426  else
427  {
429  if ((long)a!=1L)
430  {
431  StringAppend("%d",(int)((long)a));
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:812
const poly a
Definition: syzextra.cc:212
const ring r
Definition: syzextra.cc:208
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define StringAppend
Definition: emacs.cc:82
#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.

◆ nfCoeffName_buf

char nfCoeffName_buf[32]
static

Definition at line 777 of file ffields.cc.

◆ nfMapGG_factor

int nfMapGG_factor
static

Definition at line 679 of file ffields.cc.

◆ nfMinPoly

int nfMinPoly[16]
static

Definition at line 528 of file ffields.cc.