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 <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)
 

Functions

BOOLEAN nfGreaterZero (number k, const coeffs r)
 
number nfMult (number a, number b, const coeffs r)
 
number nfInit (long i, const coeffs r)
 
number nfParameter (int i, const coeffs r)
 
long nfInt (number &n, const coeffs r)
 
number nfAdd (number a, number b, const coeffs r)
 
number nfSub (number a, number b, const coeffs r)
 
void nfPower (number a, int i, number *result, const coeffs r)
 
BOOLEAN nfIsZero (number a, const coeffs r)
 
BOOLEAN nfIsOne (number a, const coeffs r)
 
BOOLEAN nfIsMOne (number a, const coeffs r)
 
number nfDiv (number a, number b, const coeffs r)
 
number nfNeg (number c, const coeffs r)
 
number nfInvers (number c, const coeffs r)
 
BOOLEAN nfGreater (number a, number b, const coeffs r)
 
BOOLEAN nfEqual (number a, number b, const coeffs r)
 
const char * nfRead (const char *s, number *a, const coeffs r)
 
BOOLEAN nfDBTest (number a, const char *f, const int l, const coeffs r)
 
nMapFunc nfSetMap (const coeffs src, const coeffs dst)
 
char * nfName (number n, const coeffs r)
 
void nfReadTable (const int c, const coeffs r)
 
void nfCoeffWrite (const coeffs r, BOOLEAN details)
 
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 int nfParDeg (number n, const coeffs r)
 
static void nfWriteLong (number a, const coeffs r)
 
static void nfWriteShort (number a, const coeffs r)
 
static const char * nfEati (const char *s, int *i, const coeffs r)
 
int gf_tab_numdigits62 (int q)
 
int convertback62 (char *p, int n)
 
static void nfReadMipo (char *s)
 
number nfMapP (number c, const coeffs, const coeffs dst)
 
number nfMapGG (number c, const coeffs src, const coeffs)
 
number nfMapGGrev (number c, const coeffs src, const coeffs)
 
static BOOLEAN nfCoeffIsEqual (const coeffs, n_coeffType, void *)
 
static void nfKillChar (coeffs r)
 
static char * nfCoeffString (const coeffs r)
 
static number nfRandom (siRandProc p, number, number, const coeffs cf)
 
BOOLEAN nfInitChar (coeffs r, void *parameter)
 

Variables

static const n_coeffType ID = n_GF
 Our Type! More...
 
const double sixteenlog2 = 11.09035489
 
const unsigned short fftable []
 
int nfMinPoly [16]
 
int nfMapGG_factor
 

Macro Definition Documentation

§ nfTest

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

Definition at line 161 of file ffields.cc.

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()

number nfAdd ( number  a,
number  b,
const coeffs  r 
)

Definition at line 255 of file ffields.cc.

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

§ nfCoeffIsEqual()

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

Definition at line 982 of file ffields.cc.

983 {
984  if (n==n_GF) {
985  GFInfo* p = (GFInfo *)(parameter);
986  int c = pow (p->GFChar, p->GFDegree);
987  if ((c == r->m_nfCharQ) && (strcmp(n_ParameterNames(r)[0], p->GFPar_name) == 0))
988  return TRUE;
989  }
990  return FALSE;
991 }
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
const char * GFPar_name
Definition: coeffs.h:96
#define TRUE
Definition: auxiliary.h:98
Creation data needed for finite fields.
Definition: coeffs.h:92
int GFDegree
Definition: coeffs.h:95
int GFChar
Definition: coeffs.h:94
{p^n < 2^16}
Definition: coeffs.h:33
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:418

§ nfCoeffString()

static char* nfCoeffString ( const coeffs  r)
static

Definition at line 821 of file ffields.cc.

822 {
823  const char *p=n_ParameterNames(r)[0];
824  char *s=(char*)omAlloc(11+1+strlen(p));
825  sprintf(s,"%d,%s",r->m_nfCharQ,p);
826  return s;
827 }
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

§ nfCoeffWrite()

void nfCoeffWrite ( const coeffs  r,
BOOLEAN  details 
)

Definition at line 967 of file ffields.cc.

968 {
969  // m_nfCharQ = p^k where p is the characteristic (r->CharP) and k is GFDegree
970  Print("// # ground field : %d\n",r->m_nfCharQ);
971  Print("// primitive element : %s\n", n_ParameterNames(r)[0]);
972  if ( details )
973  {
974  StringSetS("// minpoly : ");
975  nfShowMipo(r);
976  StringAppendS("\n");
977  char *s=StringEndS(); PrintS(s); omFree(s);
978  }
979  else PrintS("// minpoly : ...\n");
980 }
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:582
#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 141 of file ffields.cc.

142 {
143  assume( r->m_nfPlus1Table != NULL );
144  if (((long)a<0L) || ((long)a>(long)r->m_nfCharQ))
145  {
146  Print("wrong %d in %s:%d\n",(int)((long)a),f,l);
147  return FALSE;
148  }
149  int i=0;
150  do
151  {
152  if (r->m_nfPlus1Table[i]>r->m_nfCharQ)
153  {
154  Print("wrong table %d=%d in %s:%d\n",i,r->m_nfPlus1Table[i],f,l);
155  return FALSE;
156  }
157  i++;
158  } while (i<r->m_nfCharQ);
159  return TRUE;
160 }
const poly a
Definition: syzextra.cc:212
#define Print
Definition: emacs.cc:83
#define FALSE
Definition: auxiliary.h:94
f
Definition: cfModGcd.cc:4022
#define TRUE
Definition: auxiliary.h:98
#define assume(x)
Definition: mod2.h:394
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
int l
Definition: cfEzgcd.cc:94

§ nfDiv()

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

Definition at line 337 of file ffields.cc.

338 {
339 #ifdef LDEBUG
340  nfTest(b, r);
341 #endif
342  if ((long)b==(long)r->m_nfCharQ)
343  {
344  WerrorS(nDivBy0);
345  return (number)((long)r->m_nfCharQ);
346  }
347 #ifdef LDEBUG
348  nfTest(a, r);
349 #endif
350  if ((long)a==(long)r->m_nfCharQ)
351  return (number)((long)r->m_nfCharQ);
352  /*else*/
353  long s = (long)a - (long)b;
354  if (s < 0L)
355  s += (long)r->m_nfCharQ1;
356 #ifdef LDEBUG
357  nfTest((number)s, r);
358 #endif
359  return (number)s;
360 }
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:161
const poly b
Definition: syzextra.cc:213

§ nfEati()

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

Definition at line 519 of file ffields.cc.

520 {
521  if (*s >= '0' && *s <= '9')
522  {
523  *i = 0;
524  do
525  {
526  *i *= 10;
527  *i += *s++ - '0';
528  if (*i > (MAX_INT_VAL / 10)) *i = *i % r->m_nfCharP;
529  }
530  while (*s >= '0' && *s <= '9');
531  if (*i >= r->m_nfCharP) *i = *i % r->m_nfCharP;
532  }
533  else *i = 1;
534  return s;
535 }
const CanonicalForm int s
Definition: facAbsFact.cc:55
const int MAX_INT_VAL
Definition: mylimits.h:12
int i
Definition: cfEzgcd.cc:123

§ nfEqual()

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

Definition at line 414 of file ffields.cc.

415 {
416 #ifdef LDEBUG
417  nfTest(a, r);
418  nfTest(b, r);
419 #endif
420  return (long)a == (long)b;
421 }
const poly a
Definition: syzextra.cc:212
#define nfTest(N, R)
Definition: ffields.cc:161
const poly b
Definition: syzextra.cc:213

§ nfGreater()

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

Definition at line 402 of file ffields.cc.

403 {
404 #ifdef LDEBUG
405  nfTest(a, r);
406  nfTest(b, r);
407 #endif
408  return (long)a != (long)b;
409 }
const poly a
Definition: syzextra.cc:212
#define nfTest(N, R)
Definition: ffields.cc:161
const poly b
Definition: syzextra.cc:213

§ nfGreaterZero()

BOOLEAN nfGreaterZero ( number  k,
const coeffs  r 
)

Definition at line 167 of file ffields.cc.

168 {
169 #ifdef LDEBUG
170  nfTest(k, r);
171 #endif
172  return !nfIsZero(k, r) && !nfIsMOne(k, r);
173 }
BOOLEAN nfIsZero(number a, const coeffs r)
Definition: ffields.cc:303
int k
Definition: cfEzgcd.cc:93
BOOLEAN nfIsMOne(number a, const coeffs r)
Definition: ffields.cc:325
#define nfTest(N, R)
Definition: ffields.cc:161

§ nfInit()

number nfInit ( long  i,
const coeffs  r 
)

Definition at line 198 of file ffields.cc.

199 {
200  assume( r->m_nfPlus1Table != NULL );
201  // Hmm .. this is just to prevent initialization
202  // from nfInitChar to go into an infinite loop
203  if (i==0) return (number)(long)r->m_nfCharQ;
204  while (i < 0) i += r->m_nfCharP;
205  while (i >= r->m_nfCharP) i -= r->m_nfCharP;
206  if (i==0) return (number)(long)r->m_nfCharQ;
207  unsigned short c=0;
208  while (i>1)
209  {
210  c=r->m_nfPlus1Table[c];
211  i--;
212  }
213 #ifdef LDEBUG
214  nfTest((number)(long)c, r);
215 #endif
216  return (number)(long)c;
217 }
#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:161
#define NULL
Definition: omList.c:10

§ nfInitChar()

BOOLEAN nfInitChar ( coeffs  r,
void *  parameter 
)

Definition at line 834 of file ffields.cc.

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

§ nfInt()

long nfInt ( number &  n,
const coeffs  r 
)

Definition at line 247 of file ffields.cc.

248 {
249  return (long)n;
250 }

§ nfInvers()

number nfInvers ( number  c,
const coeffs  r 
)

Definition at line 365 of file ffields.cc.

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

§ nfIsMOne()

BOOLEAN nfIsMOne ( number  a,
const coeffs  r 
)

Definition at line 325 of file ffields.cc.

326 {
327 #ifdef LDEBUG
328  nfTest(a, r);
329 #endif
330  if (0L == (long)a) return FALSE; /* special handling of char 2*/
331  return (long)r->m_nfM1 == (long)a;
332 }
const poly a
Definition: syzextra.cc:212
#define FALSE
Definition: auxiliary.h:94
#define nfTest(N, R)
Definition: ffields.cc:161

§ nfIsOne()

BOOLEAN nfIsOne ( number  a,
const coeffs  r 
)

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
#define nfTest(N, R)
Definition: ffields.cc:161

§ nfIsZero()

BOOLEAN nfIsZero ( number  a,
const coeffs  r 
)

Definition at line 303 of file ffields.cc.

304 {
305 #ifdef LDEBUG
306  nfTest(a, r);
307 #endif
308  return (long)r->m_nfCharQ == (long)a;
309 }
const poly a
Definition: syzextra.cc:212
#define nfTest(N, R)
Definition: ffields.cc:161

§ nfKillChar()

static void nfKillChar ( coeffs  r)
static

Definition at line 808 of file ffields.cc.

809 {
810  char** p = (char**)n_ParameterNames(r);
811 
812  const int P = n_NumberOfParameters(r);
813 
814  for( int i = 1; i <= P; i++ )
815  if (p[i-1] != NULL)
816  omFree( (ADDRESS)p[i-1] );
817 
818  omFreeSize((ADDRESS)p, P * sizeof(char*));
819 }
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
#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()

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

Definition at line 732 of file ffields.cc.

733 {
734  int i=(long)c;
735  i*= nfMapGG_factor;
736  while (i >src->m_nfCharQ1) i-=src->m_nfCharQ1;
737  return (number)((long)i);
738 }
int nfMapGG_factor
Definition: ffields.cc:731
int i
Definition: cfEzgcd.cc:123

§ nfMapGGrev()

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

Definition at line 742 of file ffields.cc.

743 {
744  int ex=(int)((long)c);
745  if ((ex % nfMapGG_factor)==0)
746  return (number)(((long)ex) / ((long)nfMapGG_factor));
747  else
748  return (number)(long)src->m_nfCharQ; /* 0 */
749 }
int nfMapGG_factor
Definition: ffields.cc:731

§ nfMapP()

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

Definition at line 723 of file ffields.cc.

724 {
725  return nfInit((int)((long)c), dst);
726 }
number nfInit(long i, const coeffs r)
Definition: ffields.cc:198

§ nfMult()

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

Definition at line 178 of file ffields.cc.

179 {
180 #ifdef LDEBUG
181  nfTest(a, r);
182  nfTest(b, r);
183 #endif
184  if (((long)a == (long)r->m_nfCharQ) || ((long)b == (long)r->m_nfCharQ))
185  return (number)(long)r->m_nfCharQ;
186  /*else*/
187  int i=(int)((long)a+(long)b);
188  if (i>=r->m_nfCharQ1) i-=r->m_nfCharQ1;
189 #ifdef LDEBUG
190  nfTest((number)(long)i, r);
191 #endif
192  return (number)(long)i;
193 }
const poly a
Definition: syzextra.cc:212
int i
Definition: cfEzgcd.cc:123
#define nfTest(N, R)
Definition: ffields.cc:161
const poly b
Definition: syzextra.cc:213

§ nfName()

char * nfName ( number  n,
const coeffs  r 
)

Definition at line 469 of file ffields.cc.

470 {
471 #ifdef LDEBUG
472  nfTest(a, r);
473 #endif
474  char *s;
475  const char * const nf_Parameter=n_ParameterNames(r)[0];
476  if (((long)a==(long)r->m_nfCharQ) || ((long)a==0L)) return NULL;
477  else if ((long)a==1L)
478  {
479  return omStrDup(nf_Parameter);
480  }
481  else
482  {
483  s=(char *)omAlloc(4+strlen(nf_Parameter));
484  sprintf(s,"%s%d",nf_Parameter,(int)((long)a));
485  }
486  return s;
487 }
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 poly a
Definition: syzextra.cc:212
#define omAlloc(size)
Definition: omAllocDecl.h:210
#define nfTest(N, R)
Definition: ffields.cc:161
#define NULL
Definition: omList.c:10
#define omStrDup(s)
Definition: omAllocDecl.h:263

§ nfNeg()

number nfNeg ( number  c,
const coeffs  r 
)

Definition at line 384 of file ffields.cc.

385 {
386 /*4 -z^c=z^c*(-1)=z^c*nfM1*/
387 #ifdef LDEBUG
388  nfTest(c, r);
389 #endif
390  if ((long)r->m_nfCharQ == (long)c) return c;
391  long i=(long)c+(long)r->m_nfM1;
392  if (i>=(long)r->m_nfCharQ1) i-=(long)r->m_nfCharQ1;
393 #ifdef LDEBUG
394  nfTest((number)i, r);
395 #endif
396  return (number)i;
397 }
int i
Definition: cfEzgcd.cc:123
#define nfTest(N, R)
Definition: ffields.cc:161

§ nfParameter()

number nfParameter ( int  i,
const coeffs  r 
)

Definition at line 222 of file ffields.cc.

223 {
224  assume(i==1);
225 
226  if( i == 1 )
227  return (number)1;
228 
229  return NULL;
230 }
#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 235 of file ffields.cc.

236 {
237 #ifdef LDEBUG
238  nfTest(n, r);
239 #endif
240  if((long)r->m_nfCharQ == (long)n) return -1;
241  return (int)((long)n);
242 }
#define nfTest(N, R)
Definition: ffields.cc:161

§ nfPower()

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

Definition at line 491 of file ffields.cc.

492 {
493 #ifdef LDEBUG
494  nfTest(a, r);
495 #endif
496  if (i==0)
497  {
498  *result = (number)0L;
499  }
500  else if (i==1)
501  {
502  *result = a;
503  }
504  else
505  {
506  long rl;
507  if ((long)a == (long)r->m_nfCharQ) rl=(long)r->m_nfCharQ;
508  else rl=((long)a*(long)i) % (long)r->m_nfCharQ1;
509  *result = (number)rl;
510  }
511 #ifdef LDEBUG
512  nfTest(*result, r);
513 #endif
514 }
const poly a
Definition: syzextra.cc:212
int i
Definition: cfEzgcd.cc:123
#define nfTest(N, R)
Definition: ffields.cc:161
return result
Definition: facAbsBiFact.cc:76

§ nfRandom()

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

Definition at line 829 of file ffields.cc.

830 {
831  return (number)(long)(p() %(cf->m_nfCharQ+1));
832 }
return P p
Definition: myNF.cc:203

§ nfRead()

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

Definition at line 540 of file ffields.cc.

541 {
542  int i;
543  number z;
544  number n;
545 
546  s = nfEati(s, &i, r);
547  z=nfInit(i, r);
548  *a=z;
549  if (*s == '/')
550  {
551  s++;
552  s = nfEati(s, &i, r);
553  n=nfInit(i, r);
554  *a = nfDiv(z,n,r);
555  }
556  const char * const nf_Parameter = n_ParameterNames(r)[0];
557  const int N = strlen(nf_Parameter);
558  if (strncmp(s,nf_Parameter, N)==0)
559  {
560  s += N;
561  if ((*s >= '0') && (*s <= '9'))
562  {
563  s=eati(s,&i);
564  while (i>=r->m_nfCharQ1) i-=r->m_nfCharQ1;
565  }
566  else
567  i=1;
568  z=(number)(long)i;
569  *a=nfMult(*a,z,r);
570  }
571 #ifdef LDEBUG
572  nfTest(*a, r);
573 #endif
574  return s;
575 }
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:519
const poly a
Definition: syzextra.cc:212
number nfInit(long i, const coeffs r)
Definition: ffields.cc:198
number nfDiv(number a, number b, const coeffs r)
Definition: ffields.cc:337
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
int i
Definition: cfEzgcd.cc:123
#define nfTest(N, R)
Definition: ffields.cc:161
number nfMult(number a, number b, const coeffs r)
Definition: ffields.cc:178

§ nfReadMipo()

static void nfReadMipo ( char *  s)
static

Definition at line 598 of file ffields.cc.

599 {
600  const char *l=strchr(s,';')+1;
601  char *n;
602  int i=strtol(l,&n,10);
603  l=n;
604  int j=1;
605  nfMinPoly[0]=i;
606  while(i>=0)
607  {
608  nfMinPoly[j]=strtol(l,&n,10);
609  if (l==n) break;
610  l=n;
611  j++;
612  i--;
613  }
614  if (i>=0)
615  {
616  WerrorS("error in reading minpoly from gftables");
617  }
618 }
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
int nfMinPoly[16]
Definition: ffields.cc:580

§ nfReadTable()

void nfReadTable ( const int  c,
const coeffs  r 
)

Definition at line 623 of file ffields.cc.

624 {
625  //Print("GF(%d)\n",c);
626  if ((c==r->m_nfCharQ)||(c==-r->m_nfCharQ))
627  /*this field is already set*/ return;
628  int i=0;
629 
630  while ((fftable[i]!=c) && (fftable[i]!=0))
631  i++;
632 
633  if (fftable[i]==0)
634  {
635  // illegal GF-table size: c
636  return;
637  }
638 
639  if (r->m_nfCharQ > 1)
640  {
641  omFreeSize( (ADDRESS)r->m_nfPlus1Table,r->m_nfCharQ*sizeof(unsigned short) );
642  r->m_nfPlus1Table=NULL;
643  }
644  if ((c>1) || (c<0))
645  {
646  if (c>1) r->m_nfCharQ = c;
647  else r->m_nfCharQ = -c;
648  char buf[100];
649  sprintf(buf,"gftables/%d",r->m_nfCharQ);
650  FILE * fp = feFopen(buf,"r",NULL,TRUE);
651  if (fp==NULL)
652  {
653  return;
654  }
655  if(!fgets( buf, sizeof(buf), fp)) return;
656  if(strcmp(buf,"@@ factory GF(q) table @@\n")!=0)
657  {
658  goto err;
659  }
660  if(!fgets( buf, sizeof(buf), fp))
661  {
662  goto err;
663  }
664  int q;
665  int res = -1;
666  do
667  {
668  res = sscanf(buf,"%d %d",&r->m_nfCharP,&q);
669  }
670  while((res < 0) and (errno == EINTR));
671 
672  nfReadMipo(buf);
673  r->m_nfCharQ1=r->m_nfCharQ-1;
674  //Print("nfCharQ=%d,nfCharQ1=%d,mipo=>>%s<<\n",nfCharQ,nfCharQ1,buf);
675  r->m_nfPlus1Table= (unsigned short *)omAlloc( (r->m_nfCharQ)*sizeof(unsigned short) );
676  int digs = gf_tab_numdigits62( r->m_nfCharQ );
677  char * bufptr;
678  int i = 1;
679  int k;
680  while ( i < r->m_nfCharQ )
681  {
682  (void)fgets( buf, sizeof(buf), fp);
683  //( strlen( buffer ) == (size_t)digs * 30, "illegal table" );
684  bufptr = buf;
685  k = 0;
686  while ( (i < r->m_nfCharQ) && (k < 30) )
687  {
688  r->m_nfPlus1Table[i] = convertback62( bufptr, digs );
689  if(r->m_nfPlus1Table[i]>r->m_nfCharQ)
690  {
691  Print("wrong entry %d: %d(%c%c%c)\n",i,r->m_nfPlus1Table[i],bufptr[0],bufptr[1],bufptr[2]);
692  }
693  bufptr += digs;
694  if (r->m_nfPlus1Table[i]==r->m_nfCharQ)
695  {
696  if(i==r->m_nfCharQ1)
697  {
698  r->m_nfM1=0;
699  }
700  else
701  {
702  r->m_nfM1=i;
703  }
704  }
705  i++; k++;
706  }
707  }
708  r->m_nfPlus1Table[0]=r->m_nfPlus1Table[r->m_nfCharQ1];
709  }
710  else
711  r->m_nfCharQ=0;
712 #ifdef LDEBUG
713  nfTest((number)0, r);
714 #endif
715  return;
716 err:
717  Werror("illegal GF-table %d",r->m_nfCharQ);
718 }
#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:598
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:61
#define nfTest(N, R)
Definition: ffields.cc:161
#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()

nMapFunc nfSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 754 of file ffields.cc.

755 {
756  if (nCoeff_is_GF(src,src->m_nfCharQ))
757  {
758  return ndCopyMap; /* GF(p,n) -> GF(p,n) */
759  }
760  if (nCoeff_is_GF(src))
761  {
762  const coeffs r = dst;
763  int q=src->ch;
764  if ((src->m_nfCharQ % q)==0) /* GF(p,n1) -> GF(p,n2), n2 > n1 */
765  {
766  // check if n2 is a multiple of n1
767  int n1=1;
768  int qq=r->m_nfCharP;
769  while(qq!=q) { qq *= r->m_nfCharP; n1++; }
770  int n2=1;
771  qq=r->m_nfCharP;
772  while(qq!=src->m_nfCharQ) { qq *= r->m_nfCharP; n2++; }
773  //Print("map %d^%d -> %d^%d\n",r->m_nfCharP,n1,r->m_nfCharP,n2);
774  if ((n2 % n1)==0)
775  {
776  int save_ch=r->m_nfCharQ;
777  nfReadTable(src->m_nfCharQ, r);
778  int nn=r->m_nfPlus1Table[0];
779  nfReadTable(save_ch, r);
780  nfMapGG_factor= r->m_nfPlus1Table[0] / nn;
781  //Print("nfMapGG_factor=%d (%d / %d)\n",nfMapGG_factor, r->m_nfPlus1Table[0], nn);
782  return nfMapGG;
783  }
784  else if ((n1 % n2)==0)
785  {
786  nfMapGG_factor= (n1/n2);
787  return nfMapGGrev;
788  }
789  else
790  return NULL;
791  }
792  }
793  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src,dst->m_nfCharP))
794  {
795  return nfMapP; /* Z/p -> GF(p,n) */
796  }
797 
798  if (src->rep==n_rep_gap_rat) /*Q, Z */
799  {
800  return nlModP; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
801  }
802 
803  return NULL; /* default */
804 }
void nfReadTable(const int c, const coeffs r)
Definition: ffields.cc:623
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:1425
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:244
int nfMapGG_factor
Definition: ffields.cc:731
const ring r
Definition: syzextra.cc:208
number nfMapP(number c, const coeffs, const coeffs dst)
Definition: ffields.cc:723
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
number nfMapGGrev(number c, const coeffs src, const coeffs)
Definition: ffields.cc:742
#define NULL
Definition: omList.c:10
(int), see modulop.h
Definition: coeffs.h:110
number nfMapGG(number c, const coeffs src, const coeffs)
Definition: ffields.cc:732

§ 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 582 of file ffields.cc.

583 {
584  int i=nfMinPoly[0];
585  int j=0;
586  loop
587  {
588  j++;
589  if (nfMinPoly[j]!=0)
590  StringAppend("%d*%s^%d",nfMinPoly[j],n_ParameterNames(r)[0],i);
591  i--;
592  if(i<0) break;
593  if (nfMinPoly[j]!=0)
594  StringAppendS("+");
595  }
596 }
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
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
int nfMinPoly[16]
Definition: ffields.cc:580

§ nfSub()

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

Definition at line 294 of file ffields.cc.

295 {
296  number mb = nfNeg(b, r);
297  return nfAdd(a,mb,r);
298 }
const poly a
Definition: syzextra.cc:212
number nfNeg(number c, const coeffs r)
Definition: ffields.cc:384
number nfAdd(number a, number b, const coeffs r)
Definition: ffields.cc:255
const poly b
Definition: syzextra.cc:213

§ nfWriteLong()

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

Definition at line 426 of file ffields.cc.

427 {
428 #ifdef LDEBUG
429  nfTest(a, r);
430 #endif
431  if ((long)a==(long)r->m_nfCharQ) StringAppendS("0");
432  else if ((long)a==0L) StringAppendS("1");
433  else if (nfIsMOne(a, r)) StringAppendS("-1");
434  else
435  {
437  if ((long)a!=1L)
438  {
439  StringAppend("^%d",(int)((long)a)); // long output!
440  }
441  }
442 }
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
BOOLEAN nfIsMOne(number a, const coeffs r)
Definition: ffields.cc:325
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define StringAppend
Definition: emacs.cc:82
#define nfTest(N, R)
Definition: ffields.cc:161

§ nfWriteShort()

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

Definition at line 448 of file ffields.cc.

449 {
450 #ifdef LDEBUG
451  nfTest(a, r);
452 #endif
453  if ((long)a==(long)r->m_nfCharQ) StringAppendS("0");
454  else if ((long)a==0L) StringAppendS("1");
455  else if (nfIsMOne(a, r)) StringAppendS("-1");
456  else
457  {
459  if ((long)a!=1L)
460  {
461  StringAppend("%d",(int)((long)a));
462  }
463  }
464 }
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
BOOLEAN nfIsMOne(number a, const coeffs r)
Definition: ffields.cc:325
void StringAppendS(const char *st)
Definition: reporter.cc:107
#define StringAppend
Definition: emacs.cc:82
#define nfTest(N, R)
Definition: ffields.cc:161

Variable Documentation

§ fftable

const unsigned short fftable[]

Definition at line 61 of file ffields.cc.

§ ID

const n_coeffType ID = n_GF
static

Our Type!

Definition at line 55 of file ffields.cc.

§ nfMapGG_factor

int nfMapGG_factor

Definition at line 731 of file ffields.cc.

§ nfMinPoly

int nfMinPoly[16]

Definition at line 580 of file ffields.cc.

§ sixteenlog2

const double sixteenlog2 = 11.09035489

Definition at line 59 of file ffields.cc.