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

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

Definition at line 161 of file ffields.cc.

Function Documentation

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
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 }
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
static BOOLEAN nfCoeffIsEqual ( const coeffs  r,
n_coeffType  n,
void *  parameter 
)
static

Definition at line 987 of file ffields.cc.

988 {
989  if (n==n_GF) {
990  GFInfo* p = (GFInfo *)(parameter);
991  int c = pow (p->GFChar, p->GFDegree);
992  if ((c == r->m_nfCharQ) && (strcmp(n_ParameterNames(r)[0], p->GFPar_name) == 0))
993  return TRUE;
994  }
995  return FALSE;
996 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:801
#define FALSE
Definition: auxiliary.h:140
return P p
Definition: myNF.cc:203
const char * GFPar_name
Definition: coeffs.h:95
#define TRUE
Definition: auxiliary.h:144
Creation data needed for finite fields.
Definition: coeffs.h:91
int GFDegree
Definition: coeffs.h:94
int GFChar
Definition: coeffs.h:93
{p^n < 2^16}
Definition: coeffs.h:33
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:418
static char* nfCoeffString ( const coeffs  r)
static

Definition at line 823 of file ffields.cc.

824 {
825  const char *p=n_ParameterNames(r)[0];
826  char *s=(char*)omAlloc(11+1+strlen(p));
827  sprintf(s,"%d,%s",r->m_nfCharQ,p);
828  return s;
829 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:801
const CanonicalForm int s
Definition: facAbsFact.cc:55
return P p
Definition: myNF.cc:203
#define omAlloc(size)
Definition: omAllocDecl.h:210
void nfCoeffWrite ( const coeffs  r,
BOOLEAN  details 
)

Definition at line 972 of file ffields.cc.

973 {
974  // m_nfCharQ = p^k where p is the characteristic (r->CharP) and k is GFDegree
975  Print("// # ground field : %d\n",r->m_nfCharQ);
976  Print("// primitive element : %s\n", n_ParameterNames(r)[0]);
977  if ( details )
978  {
979  StringSetS("// minpoly : ");
980  nfShowMipo(r);
981  StringAppendS("\n");
982  char *s=StringEndS(); PrintS(s); omFree(s);
983  }
984  else PrintS("// minpoly : ...\n");
985 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:801
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:294
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:140
#define TRUE
Definition: auxiliary.h:144
#define assume(x)
Definition: mod2.h:405
FILE * f
Definition: checklibs.c:7
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
int l
Definition: cfEzgcd.cc:94
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:323
const char *const nDivBy0
Definition: numbers.h:83
#define nfTest(N, R)
Definition: ffields.cc:161
const poly b
Definition: syzextra.cc:213
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
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
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
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
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:405
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
BOOLEAN nfInitChar ( coeffs  r,
void *  parameter 
)

Definition at line 836 of file ffields.cc.

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

Definition at line 247 of file ffields.cc.

248 {
249  return (long)n;
250 }
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
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:140
#define nfTest(N, R)
Definition: ffields.cc:161
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
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
static void nfKillChar ( coeffs  r)
static

Definition at line 810 of file ffields.cc.

811 {
812  char** p = (char**)n_ParameterNames(r);
813 
814  const int P = n_NumberOfParameters(r);
815 
816  for( int i = 1; i <= P; i++ )
817  if (p[i-1] != NULL)
818  omFree( (ADDRESS)p[i-1] );
819 
820  omFreeSize((ADDRESS)p, P * sizeof(char*));
821 }
static FORCE_INLINE char const ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:801
return P p
Definition: myNF.cc:203
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
void * ADDRESS
Definition: auxiliary.h:161
static FORCE_INLINE int n_NumberOfParameters(const coeffs r)
Returns the number of parameters.
Definition: coeffs.h:797
#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
number nfMapGG ( number  c,
const coeffs  src,
const coeffs   
)

Definition at line 734 of file ffields.cc.

735 {
736  int i=(long)c;
737  i*= nfMapGG_factor;
738  while (i >src->m_nfCharQ1) i-=src->m_nfCharQ1;
739  return (number)((long)i);
740 }
int nfMapGG_factor
Definition: ffields.cc:733
int i
Definition: cfEzgcd.cc:123
number nfMapGGrev ( number  c,
const coeffs  src,
const coeffs   
)

Definition at line 744 of file ffields.cc.

745 {
746  int ex=(int)((long)c);
747  if ((ex % nfMapGG_factor)==0)
748  return (number)(((long)ex) / ((long)nfMapGG_factor));
749  else
750  return (number)(long)src->m_nfCharQ; /* 0 */
751 }
int nfMapGG_factor
Definition: ffields.cc:733
number nfMapP ( number  c,
const coeffs  ,
const coeffs  dst 
)

Definition at line 725 of file ffields.cc.

726 {
727  return nfInit((int)((long)c), dst);
728 }
number nfInit(long i, const coeffs r)
Definition: ffields.cc:198
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
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:801
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
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
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:405
int i
Definition: cfEzgcd.cc:123
#define NULL
Definition: omList.c:10
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
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
static number nfRandom ( siRandProc  p,
number  ,
number  ,
const coeffs  cf 
)
static

Definition at line 831 of file ffields.cc.

832 {
833  return (number)(long)(p() %(cf->m_nfCharQ+1));
834 }
return P p
Definition: myNF.cc:203
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:801
const CanonicalForm int s
Definition: facAbsFact.cc:55
const char * eati(const char *s, int *i)
Definition: reporter.cc:390
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
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
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 #ifndef SING_NDEBUG
636  Warn("illegal GF-table size: %d", c);
637 #endif
638  return;
639  }
640 
641  if (r->m_nfCharQ > 1)
642  {
643  omFreeSize( (ADDRESS)r->m_nfPlus1Table,r->m_nfCharQ*sizeof(unsigned short) );
644  r->m_nfPlus1Table=NULL;
645  }
646  if ((c>1) || (c<0))
647  {
648  if (c>1) r->m_nfCharQ = c;
649  else r->m_nfCharQ = -c;
650  char buf[100];
651  sprintf(buf,"gftables/%d",r->m_nfCharQ);
652  FILE * fp = feFopen(buf,"r",NULL,TRUE);
653  if (fp==NULL)
654  {
655  return;
656  }
657  if(!fgets( buf, sizeof(buf), fp)) return;
658  if(strcmp(buf,"@@ factory GF(q) table @@\n")!=0)
659  {
660  goto err;
661  }
662  if(!fgets( buf, sizeof(buf), fp))
663  {
664  goto err;
665  }
666  int q;
667  int res = -1;
668  do
669  {
670  res = sscanf(buf,"%d %d",&r->m_nfCharP,&q);
671  }
672  while((res < 0) and (errno == EINTR));
673 
674  nfReadMipo(buf);
675  r->m_nfCharQ1=r->m_nfCharQ-1;
676  //Print("nfCharQ=%d,nfCharQ1=%d,mipo=>>%s<<\n",nfCharQ,nfCharQ1,buf);
677  r->m_nfPlus1Table= (unsigned short *)omAlloc( (r->m_nfCharQ)*sizeof(unsigned short) );
678  int digs = gf_tab_numdigits62( r->m_nfCharQ );
679  char * bufptr;
680  int i = 1;
681  int k;
682  while ( i < r->m_nfCharQ )
683  {
684  (void)fgets( buf, sizeof(buf), fp);
685  //( strlen( buffer ) == (size_t)digs * 30, "illegal table" );
686  bufptr = buf;
687  k = 0;
688  while ( (i < r->m_nfCharQ) && (k < 30) )
689  {
690  r->m_nfPlus1Table[i] = convertback62( bufptr, digs );
691  if(r->m_nfPlus1Table[i]>r->m_nfCharQ)
692  {
693  Print("wrong entry %d: %d(%c%c%c)\n",i,r->m_nfPlus1Table[i],bufptr[0],bufptr[1],bufptr[2]);
694  }
695  bufptr += digs;
696  if (r->m_nfPlus1Table[i]==r->m_nfCharQ)
697  {
698  if(i==r->m_nfCharQ1)
699  {
700  r->m_nfM1=0;
701  }
702  else
703  {
704  r->m_nfM1=i;
705  }
706  }
707  i++; k++;
708  }
709  }
710  r->m_nfPlus1Table[0]=r->m_nfPlus1Table[r->m_nfCharQ1];
711  }
712  else
713  r->m_nfCharQ=0;
714 #ifdef LDEBUG
715  nfTest((number)0, r);
716 #endif
717  return;
718 err:
719  Werror("illegal GF-table %d",r->m_nfCharQ);
720 }
#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:144
void * ADDRESS
Definition: auxiliary.h:161
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:199
#define Warn
Definition: emacs.cc:80
nMapFunc nfSetMap ( const coeffs  src,
const coeffs  dst 
)

Definition at line 756 of file ffields.cc.

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

const unsigned short fftable[]

Definition at line 61 of file ffields.cc.

const n_coeffType ID = n_GF
static

Our Type!

Definition at line 55 of file ffields.cc.

int nfMapGG_factor

Definition at line 733 of file ffields.cc.

int nfMinPoly[16]

Definition at line 580 of file ffields.cc.

const double sixteenlog2 = 11.09035489

Definition at line 59 of file ffields.cc.