My Project  UNKNOWN_GIT_VERSION
Macros | Functions | Variables
ffields.cc File Reference
#include "misc/auxiliary.h"
#include "omalloc/omalloc.h"
#include "misc/mylimits.h"
#include "misc/sirandom.h"
#include "misc/prime.h"
#include "reporter/reporter.h"
#include "coeffs/coeffs.h"
#include "coeffs/numbers.h"
#include "coeffs/longrat.h"
#include "coeffs/ffields.h"
#include <cmath>
#include <errno.h>

Go to the source code of this file.

Macros

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

Functions

BOOLEAN nfDBTest (number a, const char *f, const int l, const coeffs r)
 
static BOOLEAN nfIsZero (number a, const coeffs r)
 
static BOOLEAN nfIsMOne (number a, const coeffs r)
 
static BOOLEAN nfGreaterZero (number k, const coeffs r)
 
static number nfMult (number a, number b, const coeffs r)
 
static number nfInit (long i, const coeffs r)
 
static number nfParameter (int i, const coeffs)
 
static int nfParDeg (number n, const coeffs r)
 
static long nfInt (number &n, const coeffs r)
 
static number nfAdd (number a, number b, const coeffs R)
 
static number nfNeg (number c, const coeffs r)
 
static number nfSub (number a, number b, const coeffs r)
 
static BOOLEAN nfIsOne (number a, const coeffs r)
 
static number nfDiv (number a, number b, const coeffs r)
 
static number nfInvers (number c, const coeffs r)
 
static BOOLEAN nfGreater (number a, number b, const coeffs r)
 
static BOOLEAN nfEqual (number a, number b, const coeffs r)
 
static void nfWriteLong (number a, const coeffs r)
 
static void nfWriteShort (number a, const coeffs r)
 
static void nfPower (number a, int i, number *result, const coeffs r)
 
static const char * nfEati (const char *s, int *i, const coeffs r)
 
static const char * nfRead (const char *s, number *a, const coeffs r)
 
int gf_tab_numdigits62 (int q)
 
int convertback62 (char *p, int n)
 
void nfShowMipo (const coeffs r)
 Show the mininimal polynom.... NOTE: this is used by char * sleftv::String(void *d, BOOLEAN typed, int dim) (from Singular/subexpr.cc) for printing minpoly. More...
 
static void nfReadMipo (char *s)
 
static void nfReadTable (const int c, const coeffs r)
 
static number nfMapP (number c, const coeffs, const coeffs dst)
 
static number nfMapGG (number c, const coeffs src, const coeffs)
 
static number nfMapGGrev (number c, const coeffs src, const coeffs)
 
static nMapFunc nfSetMap (const coeffs src, const coeffs dst)
 
static BOOLEAN nfCoeffIsEqual (const coeffs, n_coeffType, void *)
 
static void nfKillChar (coeffs r)
 
static char * nfCoeffString (const coeffs r)
 
static char * nfCoeffName (const coeffs r)
 
static number nfRandom (siRandProc p, number, number, const coeffs cf)
 
static void nfCoeffWrite (const coeffs r, BOOLEAN details)
 
BOOLEAN nfInitChar (coeffs r, void *parameter)
 

Variables

const unsigned short fftable []
 
static int nfMinPoly [16]
 
static int nfMapGG_factor
 

Macro Definition Documentation

◆ nfTest

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

Definition at line 131 of file ffields.cc.

◆ sixteenlog2

#define sixteenlog2   11.09035489

Function Documentation

◆ convertback62()

int convertback62 ( char *  p,
int  n 
)

Definition at line 50 of file gf_tabutil.cc.

51 {
52  int r = 0;
53  for ( int j = 0; j < n; j++ )
54  r = r * 62 + convback62( p[j] );
55  return r;
56 }

◆ gf_tab_numdigits62()

int gf_tab_numdigits62 ( int  q)

Definition at line 12 of file gf_tabutil.cc.

13 {
14  if ( q < 62 )
15  return 1;
16  else if ( q < 62*62 )
17  return 2;
18  else
19  return 3;
20 }

◆ nfAdd()

static number nfAdd ( number  a,
number  b,
const coeffs  R 
)
static

Definition at line 258 of file ffields.cc.

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

◆ nfCoeffIsEqual()

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

Definition at line 829 of file ffields.cc.

830 {
831  if (n==n_GF) {
832  GFInfo* p = (GFInfo *)(parameter);
833  int c = (int)pow ((double)p->GFChar, (double)p->GFDegree);
834  if ((c == r->m_nfCharQ) && (strcmp(n_ParameterNames(r)[0], p->GFPar_name) == 0))
835  return TRUE;
836  }
837  return FALSE;
838 }

◆ nfCoeffName()

static char* nfCoeffName ( const coeffs  r)
static

Definition at line 801 of file ffields.cc.

802 {
803  static char nfCoeffName_buf[32];
804  const char *p=n_ParameterNames(r)[0];
805  nfCoeffName_buf[31]='\0';
806  snprintf(nfCoeffName_buf,31,"ZZ/%d[%s]",r->m_nfCharQ,p);
807  return nfCoeffName_buf;
808 }

◆ nfCoeffString()

static char* nfCoeffString ( const coeffs  r)
static

Definition at line 793 of file ffields.cc.

794 {
795  const char *p=n_ParameterNames(r)[0];
796  char *s=(char*)omAlloc(11+1+strlen(p));
797  sprintf(s,"%d,%s",r->m_nfCharQ,p);
798  return s;
799 }

◆ nfCoeffWrite()

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

Definition at line 815 of file ffields.cc.

816 {
817  // m_nfCharQ = p^k where p is the characteristic (r->CharP) and k is GFDegree
818  Print("ZZ/%d[%s]",r->m_nfCharQ,n_ParameterNames(r)[0]);
819  if ( details )
820  {
821  StringSetS("\n// minpoly : ");
822  nfShowMipo(r);
823  StringAppendS("");
824  char *s=StringEndS(); PrintS(s); omFree(s);
825  }
826  else PrintS("// minpoly : ...");
827 }

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

◆ nfDiv()

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

Definition at line 335 of file ffields.cc.

336 {
337 #ifdef LDEBUG
338  nfTest(b, r);
339 #endif
340  if ((long)b==(long)r->m_nfCharQ)
341  {
342  WerrorS(nDivBy0);
343  return (number)((long)r->m_nfCharQ);
344  }
345 #ifdef LDEBUG
346  nfTest(a, r);
347 #endif
348  if ((long)a==(long)r->m_nfCharQ)
349  return (number)((long)r->m_nfCharQ);
350  /*else*/
351  long s = (long)a - (long)b;
352  if (s < 0L)
353  s += (long)r->m_nfCharQ1;
354 #ifdef LDEBUG
355  nfTest((number)s, r);
356 #endif
357  return (number)s;
358 }

◆ nfEati()

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

Definition at line 501 of file ffields.cc.

502 {
503  return nEati((char *)s,i,r->m_nfCharP);
504 }

◆ nfEqual()

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

Definition at line 394 of file ffields.cc.

395 {
396 #ifdef LDEBUG
397  nfTest(a, r);
398  nfTest(b, r);
399 #endif
400  return (long)a == (long)b;
401 }

◆ nfGreater()

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

Definition at line 382 of file ffields.cc.

383 {
384 #ifdef LDEBUG
385  nfTest(a, r);
386  nfTest(b, r);
387 #endif
388  return (long)a != (long)b;
389 }

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

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

◆ nfInitChar()

BOOLEAN nfInitChar ( coeffs  r,
void *  parameter 
)

Definition at line 839 of file ffields.cc.

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

◆ nfInt()

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

Definition at line 240 of file ffields.cc.

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

◆ nfInvers()

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

Definition at line 363 of file ffields.cc.

364 {
365 #ifdef LDEBUG
366  nfTest(c, r);
367 #endif
368  if ((long)c==(long)r->m_nfCharQ)
369  {
370  WerrorS(nDivBy0);
371  return (number)((long)r->m_nfCharQ);
372  }
373 #ifdef LDEBUG
374  nfTest(((number)((long)r->m_nfCharQ1-(long)c)), r);
375 #endif
376  return (number)((long)r->m_nfCharQ1-(long)c);
377 }

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

◆ nfIsOne()

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

Definition at line 324 of file ffields.cc.

325 {
326 #ifdef LDEBUG
327  nfTest(a, r);
328 #endif
329  return 0L == (long)a;
330 }

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

◆ nfKillChar()

static void nfKillChar ( coeffs  r)
static

Definition at line 780 of file ffields.cc.

781 {
782  char** p = (char**)n_ParameterNames(r);
783 
784  const int P = n_NumberOfParameters(r);
785 
786  for( int i = 1; i <= P; i++ )
787  if (p[i-1] != NULL)
788  omFree( (ADDRESS)p[i-1] );
789 
790  omFreeSize((ADDRESS)p, P * sizeof(char*));
791 }

◆ nfMapGG()

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

Definition at line 704 of file ffields.cc.

705 {
706  int i=(long)c;
707  i*= nfMapGG_factor;
708  while (i >src->m_nfCharQ1) i-=src->m_nfCharQ1;
709  return (number)((long)i);
710 }

◆ nfMapGGrev()

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

Definition at line 714 of file ffields.cc.

715 {
716  int ex=(int)((long)c);
717  if ((ex % nfMapGG_factor)==0)
718  return (number)(((long)ex) / ((long)nfMapGG_factor));
719  else
720  return (number)(long)src->m_nfCharQ; /* 0 */
721 }

◆ nfMapP()

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

Definition at line 695 of file ffields.cc.

696 {
697  return nfInit((int)((long)c), dst);
698 }

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

◆ nfNeg()

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

Definition at line 297 of file ffields.cc.

298 {
299 /*4 -z^c=z^c*(-1)=z^c*nfM1*/
300 #ifdef LDEBUG
301  nfTest(c, r);
302 #endif
303  if ((long)r->m_nfCharQ == (long)c) return c;
304  long i=(long)c+(long)r->m_nfM1;
305  if (i>=(long)r->m_nfCharQ1) i-=(long)r->m_nfCharQ1;
306 #ifdef LDEBUG
307  nfTest((number)i, r);
308 #endif
309  return (number)i;
310 }

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

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

◆ nfPower()

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

Definition at line 473 of file ffields.cc.

474 {
475 #ifdef LDEBUG
476  nfTest(a, r);
477 #endif
478  if (i==0)
479  {
480  *result = (number)0L;
481  }
482  else if (i==1)
483  {
484  *result = a;
485  }
486  else
487  {
488  long rl;
489  if ((long)a == (long)r->m_nfCharQ) rl=(long)r->m_nfCharQ;
490  else rl=((long)a*(long)i) % (long)r->m_nfCharQ1;
491  *result = (number)rl;
492  }
493 #ifdef LDEBUG
494  nfTest(*result, r);
495 #endif
496 }

◆ nfRandom()

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

Definition at line 810 of file ffields.cc.

811 {
812  return (number)(long)(p() %(cf->m_nfCharQ+1));
813 }

◆ nfRead()

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

Definition at line 509 of file ffields.cc.

510 {
511  int i;
512  number z;
513  number n;
514 
515  s = nfEati(s, &i, r);
516  z=nfInit(i, r);
517  *a=z;
518  if (*s == '/')
519  {
520  s++;
521  s = nfEati(s, &i, r);
522  n=nfInit(i, r);
523  *a = nfDiv(z,n,r);
524  }
525  const char * const nf_Parameter = n_ParameterNames(r)[0];
526  const int N = strlen(nf_Parameter);
527  if (strncmp(s,nf_Parameter, N)==0)
528  {
529  s += N;
530  if ((*s >= '0') && (*s <= '9'))
531  {
532  s=eati(s,&i);
533  while (i>=r->m_nfCharQ1) i-=r->m_nfCharQ1;
534  }
535  else
536  i=1;
537  z=(number)(long)i;
538  *a=nfMult(*a,z,r);
539  }
540 #ifdef LDEBUG
541  nfTest(*a, r);
542 #endif
543  return s;
544 }

◆ nfReadMipo()

static void nfReadMipo ( char *  s)
static

Definition at line 567 of file ffields.cc.

568 {
569  const char *l=strchr(s,';')+1;
570  char *n;
571  int i=strtol(l,&n,10);
572  l=n;
573  int j=1;
574  nfMinPoly[0]=i;
575  while(i>=0)
576  {
577  nfMinPoly[j]=strtol(l,&n,10);
578  if (l==n) break;
579  l=n;
580  j++;
581  i--;
582  }
583  if (i>=0)
584  {
585  WerrorS("error in reading minpoly from gftables");
586  }
587 }

◆ nfReadTable()

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

Definition at line 592 of file ffields.cc.

593 {
594  //Print("GF(%d)\n",c);
595  if ((c==r->m_nfCharQ)||(c== -r->m_nfCharQ))
596  /*this field is already set*/ return;
597  int i=0;
598 
599  if ((c>255) ||(c!=IsPrime(c)))
600  {
601  while ((fftable[i]!=c) && (fftable[i]!=0))
602  i++;
603 
604  if (fftable[i]==0)
605  {
606  // illegal GF-table size: c
607  return;
608  }
609  }
610 
611  if (r->m_nfCharQ > 1)
612  {
613  omFreeSize( (ADDRESS)r->m_nfPlus1Table,(r->m_nfCharQ+1)*sizeof(unsigned short) );
614  r->m_nfPlus1Table=NULL;
615  }
616  if ((c>1) || (c<0))
617  {
618  if (c>1) r->m_nfCharQ = c;
619  else r->m_nfCharQ = -c;
620  char buf[100];
621  sprintf(buf,"gftables/%d",r->m_nfCharQ);
622  FILE * fp = feFopen(buf,"r",NULL,TRUE);
623  if (fp==NULL)
624  {
625  return;
626  }
627  if(!fgets( buf, sizeof(buf), fp)) return;
628  if(strcmp(buf,"@@ factory GF(q) table @@\n")!=0)
629  {
630  goto err;
631  }
632  if(!fgets( buf, sizeof(buf), fp))
633  {
634  goto err;
635  }
636  int q;
637  int res = -1;
638  do
639  {
640  res = sscanf(buf,"%d %d",&r->m_nfCharP,&q);
641  }
642  while((res < 0) and (errno == EINTR));
643 
644  nfReadMipo(buf);
645  r->m_nfCharQ1=r->m_nfCharQ-1;
646  //Print("nfCharQ=%d,nfCharQ1=%d,mipo=>>%s<<\n",nfCharQ,nfCharQ1,buf);
647  r->m_nfPlus1Table= (unsigned short *)omAlloc0( (r->m_nfCharQ+1)*sizeof(unsigned short) );
648  int digs = gf_tab_numdigits62( r->m_nfCharQ );
649  char * bufptr;
650  int i = 1;
651  int k;
652  while ( i < r->m_nfCharQ )
653  {
654  (void)fgets( buf, sizeof(buf), fp);
655  //( strlen( buffer ) == (size_t)digs * 30, "illegal table" );
656  bufptr = buf;
657  k = 0;
658  while ( (i < r->m_nfCharQ) && (k < 30) )
659  {
660  r->m_nfPlus1Table[i] = convertback62( bufptr, digs );
661  if(r->m_nfPlus1Table[i]>r->m_nfCharQ)
662  {
663  Print("wrong entry %d: %d(%c%c%c)\n",i,r->m_nfPlus1Table[i],bufptr[0],bufptr[1],bufptr[2]);
664  }
665  bufptr += digs;
666  if (r->m_nfPlus1Table[i]==r->m_nfCharQ)
667  {
668  if(i==r->m_nfCharQ1)
669  {
670  r->m_nfM1=0;
671  }
672  else
673  {
674  r->m_nfM1=i;
675  }
676  }
677  i++; k++;
678  }
679  }
680  r->m_nfPlus1Table[0]=r->m_nfPlus1Table[r->m_nfCharQ1];
681  }
682  else
683  r->m_nfCharQ=0;
684 #ifdef LDEBUG
685  nfTest((number)0, r);
686 #endif
687  return;
688 err:
689  Werror("illegal GF-table %d",r->m_nfCharQ);
690 }

◆ nfSetMap()

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

Definition at line 726 of file ffields.cc.

727 {
728  if (nCoeff_is_GF(src,src->m_nfCharQ))
729  {
730  return ndCopyMap; /* GF(p,n) -> GF(p,n) */
731  }
732  if (nCoeff_is_GF(src))
733  {
734  const coeffs r = dst;
735  int q=src->ch;
736  if ((src->m_nfCharQ % q)==0) /* GF(p,n1) -> GF(p,n2), n2 > n1 */
737  {
738  // check if n2 is a multiple of n1
739  int n1=1;
740  int qq=r->m_nfCharP;
741  while(qq!=q) { qq *= r->m_nfCharP; n1++; }
742  int n2=1;
743  qq=r->m_nfCharP;
744  while(qq!=src->m_nfCharQ) { qq *= r->m_nfCharP; n2++; }
745  //Print("map %d^%d -> %d^%d\n",r->m_nfCharP,n1,r->m_nfCharP,n2);
746  if ((n2 % n1)==0)
747  {
748  int save_ch=r->m_nfCharQ;
749  nfReadTable(src->m_nfCharQ, r);
750  int nn=r->m_nfPlus1Table[0];
751  nfReadTable(save_ch, r);
752  nfMapGG_factor= r->m_nfPlus1Table[0] / nn;
753  //Print("nfMapGG_factor=%d (%d / %d)\n",nfMapGG_factor, r->m_nfPlus1Table[0], nn);
754  return nfMapGG;
755  }
756  else if ((n1 % n2)==0)
757  {
758  nfMapGG_factor= (n1/n2);
759  return nfMapGGrev;
760  }
761  else
762  return NULL;
763  }
764  }
765  if ((src->rep==n_rep_int) && nCoeff_is_Zp(src,dst->m_nfCharP))
766  {
767  return nfMapP; /* Z/p -> GF(p,n) */
768  }
769 
770  if (src->rep==n_rep_gap_rat) /*Q, Z */
771  {
772  return nlModP; // FIXME? TODO? // extern number nlModP(number q, const coeffs Q, const coeffs Zp); // Map q \in QQ \to Zp // FIXME!
773  }
774 
775  return NULL; /* default */
776 }

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

552 {
553  int i=nfMinPoly[0];
554  int j=0;
555  loop
556  {
557  j++;
558  if (nfMinPoly[j]!=0)
559  StringAppend("%d*%s^%d",nfMinPoly[j],n_ParameterNames(r)[0],i);
560  i--;
561  if(i<0) break;
562  if (nfMinPoly[j]!=0)
563  StringAppendS("+");
564  }
565 }

◆ nfSub()

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

Definition at line 315 of file ffields.cc.

316 {
317  number mb = nfNeg(b, r);
318  return nfAdd(a,mb,r);
319 }

◆ nfWriteLong()

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

Definition at line 406 of file ffields.cc.

407 {
408 #ifdef LDEBUG
409  nfTest(a, r);
410 #endif
411  if ((long)a==(long)r->m_nfCharQ) StringAppendS("0");
412  else if ((long)a==0L) StringAppendS("1");
413  else if (nfIsMOne(a, r)) StringAppendS("-1");
414  else
415  {
416  int i=1; /* 1==a^0 */
417  unsigned short c=0;
418  unsigned short nn=(unsigned short)(long)a;
419  while ((c!=nn)&&(i<r->m_nfCharQ))
420  {
421  c=r->m_nfPlus1Table[c];
422  i++;
423  }
424  if (c==nn) StringAppend("%d",i);
425  else
426  {
428  if ((long)a!=1L)
429  {
430  StringAppend("^%d",(int)((long)a)); // long output!
431  }
432  }
433  }
434 }

◆ nfWriteShort()

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

Definition at line 440 of file ffields.cc.

441 {
442 #ifdef LDEBUG
443  nfTest(a, r);
444 #endif
445  if ((long)a==(long)r->m_nfCharQ) StringAppendS("0");
446  else if ((long)a==0L) StringAppendS("1");
447  else if (nfIsMOne(a, r)) StringAppendS("-1");
448  else
449  {
450  int i=1; /* 1==a^0 */
451  unsigned short c=0;
452  unsigned short nn=(unsigned short)(long)a;
453  while ((c!=nn)&&(i<r->m_nfCharQ))
454  {
455  c=r->m_nfPlus1Table[c];
456  i++;
457  }
458  if (c==nn) StringAppend("%d",i);
459  else
460  {
462  if ((long)a!=1L)
463  {
464  StringAppend("%d",(int)((long)a));
465  }
466  }
467  }
468 }

Variable Documentation

◆ fftable

const unsigned short fftable[]

Definition at line 31 of file ffields.cc.

◆ nfMapGG_factor

int nfMapGG_factor
static

Definition at line 703 of file ffields.cc.

◆ nfMinPoly

int nfMinPoly[16]
static

Definition at line 549 of file ffields.cc.

getCoeffType
static FORCE_INLINE n_coeffType getCoeffType(const coeffs r)
Returns the type of coeffs domain.
Definition: coeffs.h:421
n_rep_gap_rat
@ n_rep_gap_rat
(number), see longrat.h
Definition: coeffs.h:111
nfSetMap
static nMapFunc nfSetMap(const coeffs src, const coeffs dst)
Definition: ffields.cc:726
FALSE
#define FALSE
Definition: auxiliary.h:94
nCoeff_is_Zp
static FORCE_INLINE BOOLEAN nCoeff_is_Zp(const coeffs r)
Definition: coeffs.h:822
StringAppendS
void StringAppendS(const char *st)
Definition: reporter.cc:107
nfCoeffString
static char * nfCoeffString(const coeffs r)
Definition: ffields.cc:793
IsPrime
int IsPrime(int p)
Definition: prime.cc:61
j
int j
Definition: facHensel.cc:105
f
FILE * f
Definition: checklibs.c:9
feFopen
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
omFree
#define omFree(addr)
Definition: omAllocDecl.h:261
k
int k
Definition: cfEzgcd.cc:92
nfCoeffWrite
static void nfCoeffWrite(const coeffs r, BOOLEAN details)
Definition: ffields.cc:815
result
return result
Definition: facAbsBiFact.cc:76
GFInfo
Creation data needed for finite fields.
Definition: coeffs.h:92
ADDRESS
void * ADDRESS
Definition: auxiliary.h:133
LDEBUG
#define LDEBUG
Definition: mod2.h:308
nfIsMOne
static BOOLEAN nfIsMOne(number a, const coeffs r)
Definition: ffields.cc:148
cf
CanonicalForm cf
Definition: cfModGcd.cc:4024
nfParDeg
static int nfParDeg(number n, const coeffs r)
Definition: ffields.cc:228
fftable
const unsigned short fftable[]
Definition: ffields.cc:31
omStrDup
#define omStrDup(s)
Definition: omAllocDecl.h:263
nfPower
static void nfPower(number a, int i, number *result, const coeffs r)
Definition: ffields.cc:473
ndCopyMap
number ndCopyMap(number a, const coeffs aRing, const coeffs r)
Definition: numbers.cc:252
n_GF
@ n_GF
\GF{p^n < 2^16}
Definition: coeffs.h:33
nfEati
static const char * nfEati(const char *s, int *i, const coeffs r)
Definition: ffields.cc:501
N
const CanonicalForm CFMap CFMap & N
Definition: cfEzgcd.cc:49
nCoeff_is_GF
static FORCE_INLINE BOOLEAN nCoeff_is_GF(const coeffs r)
Definition: coeffs.h:861
n_NumberOfParameters
static FORCE_INLINE int n_NumberOfParameters(const coeffs r)
Returns the number of parameters.
Definition: coeffs.h:796
nfRandom
static number nfRandom(siRandProc p, number, number, const coeffs cf)
Definition: ffields.cc:810
nfMapGGrev
static number nfMapGGrev(number c, const coeffs src, const coeffs)
Definition: ffields.cc:714
StringEndS
char * StringEndS()
Definition: reporter.cc:151
n_rep_int
@ n_rep_int
(int), see modulop.h
Definition: coeffs.h:110
gf_tab_numdigits62
int gf_tab_numdigits62(int q)
Definition: gf_tabutil.cc:12
loop
#define loop
Definition: structs.h:78
b
CanonicalForm b
Definition: cfModGcd.cc:4044
nfInvers
static number nfInvers(number c, const coeffs r)
Definition: ffields.cc:363
nfWriteLong
static void nfWriteLong(number a, const coeffs r)
Definition: ffields.cc:406
convertback62
int convertback62(char *p, int n)
Definition: gf_tabutil.cc:50
nfMapGG_factor
static int nfMapGG_factor
Definition: ffields.cc:703
nfIsZero
static BOOLEAN nfIsZero(number a, const coeffs r)
Definition: ffields.cc:137
nfDiv
static number nfDiv(number a, number b, const coeffs r)
Definition: ffields.cc:335
nfCoeffName
static char * nfCoeffName(const coeffs r)
Definition: ffields.cc:801
nfRead
static const char * nfRead(const char *s, number *a, const coeffs r)
Definition: ffields.cc:509
TRUE
#define TRUE
Definition: auxiliary.h:98
i
int i
Definition: cfEzgcd.cc:125
res
CanonicalForm res
Definition: facAbsFact.cc:64
fp
CanonicalForm fp
Definition: cfModGcd.cc:4043
nfEqual
static BOOLEAN nfEqual(number a, number b, const coeffs r)
Definition: ffields.cc:394
buf
int status int void * buf
Definition: si_signals.h:59
nDivBy0
const char *const nDivBy0
Definition: numbers.h:89
PrintS
void PrintS(const char *s)
Definition: reporter.cc:284
omFreeSize
#define omFreeSize(addr, size)
Definition: omAllocDecl.h:260
nfSub
static number nfSub(number a, number b, const coeffs r)
Definition: ffields.cc:315
nfGreater
static BOOLEAN nfGreater(number a, number b, const coeffs r)
Definition: ffields.cc:382
nfIsOne
static BOOLEAN nfIsOne(number a, const coeffs r)
Definition: ffields.cc:324
sixteenlog2
#define sixteenlog2
nfTest
#define nfTest(N, R)
Definition: ffields.cc:131
nfMinPoly
static int nfMinPoly[16]
Definition: ffields.cc:549
coeffs
omAlloc
#define omAlloc(size)
Definition: omAllocDecl.h:210
nlModP
number nlModP(number q, const coeffs, const coeffs Zp)
Definition: longrat.cc:1436
nfShowMipo
void nfShowMipo(const coeffs r)
Show the mininimal polynom.... NOTE: this is used by char * sleftv::String(void *d,...
Definition: ffields.cc:551
nfInit
static number nfInit(long i, const coeffs r)
Definition: ffields.cc:191
nfReadTable
static void nfReadTable(const int c, const coeffs r)
Definition: ffields.cc:592
n_ParameterNames
static FORCE_INLINE const char ** n_ParameterNames(const coeffs r)
Returns a (const!) pointer to (const char*) names of parameters.
Definition: coeffs.h:800
nfAdd
static number nfAdd(number a, number b, const coeffs R)
Definition: ffields.cc:258
nfGreaterZero
static BOOLEAN nfGreaterZero(number k, const coeffs r)
Definition: ffields.cc:160
StringSetS
void StringSetS(const char *st)
Definition: reporter.cc:128
log
gmp_float log(const gmp_float &a)
Definition: mpr_complex.cc:344
Print
#define Print
Definition: emacs.cc:80
convback62
int convback62(char c)
Definition: gf_tabutil.cc:40
nfNeg
static number nfNeg(number c, const coeffs r)
Definition: ffields.cc:297
Werror
void Werror(const char *fmt,...)
Definition: reporter.cc:189
while
while(1)
Definition: libparse.cc:1442
name
char name(const Variable &v)
Definition: factory.h:180
pow
Rational pow(const Rational &a, int e)
Definition: GMPrat.cc:414
WerrorS
void WerrorS(const char *s)
Definition: feFopen.cc:24
nfDBTest
BOOLEAN nfDBTest(number a, const char *f, const int l, const coeffs r)
Definition: ffields.cc:111
n_rep_gf
@ n_rep_gf
(int), see ffields.h
Definition: coeffs.h:119
WarnS
#define WarnS
Definition: emacs.cc:78
assume
#define assume(x)
Definition: mod2.h:390
NULL
#define NULL
Definition: omList.c:10
check
int check
Definition: libparse.cc:1104
nfInt
static long nfInt(number &n, const coeffs r)
Definition: ffields.cc:240
eati
const char * eati(const char *s, int *i)
Definition: reporter.cc:373
nfMult
static number nfMult(number a, number b, const coeffs r)
Definition: ffields.cc:171
l
int l
Definition: cfEzgcd.cc:93
nfMapGG
static number nfMapGG(number c, const coeffs src, const coeffs)
Definition: ffields.cc:704
R
#define R
Definition: sirandom.c:26
nEati
char * nEati(char *s, int *i, int m)
divide by the first (leading) number and return it, i.e. make monic
Definition: numbers.cc:631
Warn
#define Warn
Definition: emacs.cc:77
StringAppend
#define StringAppend
Definition: emacs.cc:79
p
int p
Definition: cfModGcd.cc:4019
nfParameter
static number nfParameter(int i, const coeffs)
Definition: ffields.cc:215
s
const CanonicalForm int s
Definition: facAbsFact.cc:55
nfKillChar
static void nfKillChar(coeffs r)
Definition: ffields.cc:780
nfMapP
static number nfMapP(number c, const coeffs, const coeffs dst)
Definition: ffields.cc:695
nfReadMipo
static void nfReadMipo(char *s)
Definition: ffields.cc:567
nfCoeffIsEqual
static BOOLEAN nfCoeffIsEqual(const coeffs, n_coeffType, void *)
Definition: ffields.cc:829
omAlloc0
#define omAlloc0(size)
Definition: omAllocDecl.h:211
nfWriteShort
static void nfWriteShort(number a, const coeffs r)
Definition: ffields.cc:440