source: git/libpolys/coeffs/ffields.cc @ 613174

fieker-DuValspielwiese
Last change on this file since 613174 was 014b65, checked in by Mohamed Barakat <mohamed.barakat@…>, 13 years ago
- moved misc,reporter,resources,coeffs,polys -> (new) libpolys (Hans agreed) - migrated to automake in coeffs, misc status: everything builds (except polys) todo: . migrate resources and reporter to automake . create autoconf macros for omalloc, factory, and libpolys
  • Property mode set to 100644
File size: 17.1 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id$ */
5/*
6* ABSTRACT: finite fields with a none-prime number of elements (via tables)
7*/
8
9#include <misc/auxiliary.h>
10#include <string.h>
11#include <coeffs/coeffs.h>
12#include <misc/mylimits.h>
13#include <omalloc/omalloc.h>
14#include <reporter/reporter.h>
15#include <coeffs/numbers.h>
16#include <coeffs/ffields.h>
17#include <resources/feFopen.h>
18#include <math.h>
19
20
21//unsigned short *nfPlus1Table=NULL; /* the table i=log(z^i) -> log(z^i+1) */
22
23const double sixteenlog2= 11.09035489;
24/* the q's from the table 'fftable' */
25unsigned short fftable[]={
26    4,  8, 16, 32, 64, 128, 256, 512,1024,2048,4096,8192,16384, 32768,
27/*2^2 2^3 2^4 2^5 2^6  2^7  2^8  2^9 2^10 2^11 2^12 2^13  2^14  2^15*/
28    9, 27, 81,243,729,2187, 6561,19683,59049,
29/*3^2 3^3 3^4 3^5 3^6  3^7  3^8   3^9  3^10*/
30   25,125,625,3125,15625,
31/*5^2 5^3 5^4 5^5  5^6*/
32   49,343,2401,16807,
33/*7^2 7^3  7^4 7^5*/
34   121,1331, 14641,
35/*11^2 11^3  11^4*/
36  169, 2197, 28561,
37/*13^2 13^3  13^4*/
38  289, 4913,
39/*17^2 17^3*/
40  361, 6859,
41/*19^2 19^3*/
42  529, 12167,
43/*23^2 23^3*/
44  841, 24389,
45/*29^2 29^3*/
46  961, 29791,
47/*31^2 31^3*/
48  1369, 50653,
49/*37^2  37^3*/
50  1681, /*41^2*/
51  1849, /*43^2*/
52  2209, /*47^2*/
53  2809, /*53^2*/
54  3481, /*59^2*/
55  3721, /*61^2*/
56  4489, /*67^2*/
57  5041, /*71^2*/
58  5329, /*73^2*/
59  6241, /*79^2*/
60  6889, /*83^2*/
61  7921, /*89^2*/
62  9409, /*97^2*/
63  10201, /*101^2*/
64  10609, /*103^2*/
65  11449, /*107^2*/
66  11881, /*109^2*/
67  12769, /*113^2*/
68  16129, /*127^2*/
69  17161, /*131^2*/
70  18769, /*137^2*/
71  19321, /*139^2*/
72  22201, /*149^2*/
73  22801, /*151^2*/
74  24649, /*157^2*/
75  26569, /*163^2*/
76  27889, /*167^2*/
77  29929, /*173^2*/
78  32041, /*179^2*/
79  32761, /*181^2*/
80  36481, /*191^2*/
81  37249, /*193^2*/
82  38809, /*197^2*/
83  39601, /*199^2*/
84  49729, /*223^2*/
85  44521, /*211^2*/
86  51529, /*227^2*/
87  52441, /*229^2*/
88  54289, /*233^2*/
89  57121, /*239^2*/
90  58081, /*241^2*/
91  63001, /*251^2*/
92  0 };
93
94const char* eati(const char *s, int *i)
95{
96  int l=0;
97
98  if    (*s >= '0' && *s <= '9')
99  {
100    *i = 0;
101    while (*s >= '0' && *s <= '9')
102    {
103      *i *= 10;
104      *i += *s++ - '0';
105      l++;
106      if ((l>=MAX_INT_LEN)||((*i) <0))
107      {
108        s-=l;
109        Werror("`%s` greater than %d(max. integer representation)",
110                s,INT_MAX);
111        return s;
112      }
113    }
114  }
115  else *i = 1;
116  return s;
117}
118
119/*1
120* numbers in GF(p^n):
121* let nfCharQ=q=nfCharP^n=p^n
122* GF(q)\{0} will be generated by powers of an element Z
123* Z^i will be represented by the int i, 1 by the int 0, 0 by the int q=nfChar
124*/
125
126#ifdef LDEBUG
127/*2
128* debugging: is a a valid representation of a number ?
129*/
130BOOLEAN nfDBTest (number a, const char *f, const int l, const coeffs r)
131{
132  assume( r->m_nfPlus1Table != NULL );
133  if (((long)a<0L) || ((long)a>(long)r->m_nfCharQ))
134  {
135    Print("wrong %d in %s:%d\n",(int)((long)a),f,l);
136    return FALSE;
137  }
138  int i=0;
139  do
140  {
141    if (r->m_nfPlus1Table[i]>r->m_nfCharQ)
142    {
143      Print("wrong table %d=%d in %s:%d\n",i,r->m_nfPlus1Table[i],f,l);
144      return FALSE;
145    }
146    i++;
147  } while (i<r->m_nfCharQ);
148  return TRUE;
149}
150#define nfTest(N, R) nfDBTest(N,__FILE__,__LINE__, R)
151#endif
152
153/*2
154* k >= 0 ?
155*/
156BOOLEAN nfGreaterZero (number k, const coeffs r)
157{
158#ifdef LDEBUG
159  nfTest(k, r);
160#endif
161  return !nfIsZero(k, r) && !nfIsMOne(k, r);
162}
163
164/*2
165* a*b
166*/
167number nfMult (number a,number b, const coeffs r)
168{
169#ifdef LDEBUG
170  nfTest(a, r);
171  nfTest(b, r);
172#endif
173  if (((long)a == (long)r->m_nfCharQ) || ((long)b == (long)r->m_nfCharQ))
174    return (number)(long)r->m_nfCharQ;
175  /*else*/
176  int i=(int)((long)a+(long)b);
177  if (i>=r->m_nfCharQ1) i-=r->m_nfCharQ1;
178#ifdef LDEBUG
179  nfTest((number)(long)i, r);
180#endif
181  return (number)(long)i;
182}
183
184/*2
185* int -> number
186*/
187number nfInit (int i, const coeffs r)
188{
189  assume( r->m_nfPlus1Table != NULL );
190  // Hmm .. this is just to prevent initialization
191  // from nfInitChar to go into an infinite loop
192  if (i==0) return (number)(long)r->m_nfCharQ;
193  while (i <  0)    i += r->m_nfCharP;
194  while (i >= r->m_nfCharP) i -= r->m_nfCharP;
195  if (i==0) return (number)(long)r->m_nfCharQ;
196  unsigned short c=0;
197  while (i>1)
198  {
199    c=r->m_nfPlus1Table[c];
200    i--;
201  }
202#ifdef LDEBUG
203  nfTest((number)(long)c, r);
204#endif
205  return (number)(long)c;
206}
207
208/*
209* the generating element `z`
210*/
211number nfPar (int i, const coeffs r)
212{
213  return (number)1;
214}
215
216/*2
217* the degree of the "alg. number"
218*/
219int nfParDeg(number n, const coeffs r)
220{
221#ifdef LDEBUG
222  nfTest(n, r);
223#endif
224  if((long)r->m_nfCharQ == (long)n) return -1;
225  return (int)((long)n);
226}
227
228/*2
229* number -> int
230*/
231int nfInt (number &n, const coeffs r)
232{
233  return 0;
234}
235
236/*2
237* a + b
238*/
239number nfAdd (number a, number b, const coeffs R)
240{
241/*4 z^a+z^b=z^b*(z^(a-b)+1), if a>=b; *
242*          =z^a*(z^(b-a)+1)  if a<b  */
243#ifdef LDEBUG
244  nfTest(a, R);
245  nfTest(b, R);
246#endif
247  if ((long)R->m_nfCharQ == (long)a) return b;
248  if ((long)R->m_nfCharQ == (long)b) return a;
249  long zb,zab,r;
250  if ((long)a >= (long)b)
251  {
252    zb = (long)b;
253    zab = (long)a-(long)b;
254  }
255  else
256  {
257    zb = (long)a;
258    zab = (long)b-(long)a;
259  }
260#ifdef LDEBUG
261  nfTest((number)zab, R);
262#endif
263  if (R->m_nfPlus1Table[zab]==R->m_nfCharQ) r=(long)R->m_nfCharQ; /*if z^(a-b)+1 =0*/
264  else
265  {
266    r= zb+(long)R->m_nfPlus1Table[zab];
267    if(r>=(long)R->m_nfCharQ1) r-=(long)R->m_nfCharQ1;
268  }
269#ifdef LDEBUG
270  nfTest((number)r, R);
271#endif
272  return (number)r;
273}
274
275/*2
276* a - b
277*/
278number nfSub (number a, number b, const coeffs r)
279{
280  number mb = nfNeg(b, r);
281  return nfAdd(a,mb,r);
282}
283
284/*2
285* a == 0 ?
286*/
287BOOLEAN nfIsZero (number  a, const coeffs r)
288{
289#ifdef LDEBUG
290  nfTest(a, r);
291#endif
292  return (long)r->m_nfCharQ == (long)a;
293}
294
295/*2
296* a == 1 ?
297*/
298BOOLEAN nfIsOne (number a, const coeffs r)
299{
300#ifdef LDEBUG
301  nfTest(a, r);
302#endif
303  return 0L == (long)a;
304}
305
306/*2
307* a == -1 ?
308*/
309BOOLEAN nfIsMOne (number a, const coeffs r)
310{
311#ifdef LDEBUG
312  nfTest(a, r);
313#endif
314  if (0L == (long)a) return FALSE; /* special handling of char 2*/
315  return (long)r->m_nfM1 == (long)a;
316}
317
318/*2
319* a / b
320*/
321number nfDiv (number a,number b, const coeffs r)
322{
323#ifdef LDEBUG
324  nfTest(b, r);
325#endif
326  if ((long)b==(long)r->m_nfCharQ)
327  {
328    WerrorS(nDivBy0);
329    return (number)((long)r->m_nfCharQ);
330  }
331#ifdef LDEBUG
332  nfTest(a, r);
333#endif
334  if ((long)a==(long)r->m_nfCharQ)
335    return (number)((long)r->m_nfCharQ);
336  /*else*/
337  long s = (long)a - (long)b;
338  if (s < 0L)
339    s += (long)r->m_nfCharQ1;
340#ifdef LDEBUG
341  nfTest((number)s, r);
342#endif
343  return (number)s;
344}
345
346/*2
347* 1 / c
348*/
349number  nfInvers (number c, const coeffs r)
350{
351#ifdef LDEBUG
352  nfTest(c, r);
353#endif
354  if ((long)c==(long)r->m_nfCharQ)
355  {
356    WerrorS(nDivBy0);
357    return (number)((long)r->m_nfCharQ);
358  }
359#ifdef LDEBUG
360  nfTest(((number)((long)r->m_nfCharQ1-(long)c)), r);
361#endif
362  return (number)((long)r->m_nfCharQ1-(long)c);
363}
364
365/*2
366* -c
367*/
368number nfNeg (number c, const coeffs r)
369{
370/*4 -z^c=z^c*(-1)=z^c*nfM1*/
371#ifdef LDEBUG
372  nfTest(c, r);
373#endif
374  if ((long)r->m_nfCharQ == (long)c) return c;
375  long i=(long)c+(long)r->m_nfM1;
376  if (i>=(long)r->m_nfCharQ1) i-=(long)r->m_nfCharQ1;
377#ifdef LDEBUG
378  nfTest((number)i, r);
379#endif
380  return (number)i;
381}
382
383/*2
384* a > b ?
385*/
386BOOLEAN nfGreater (number a,number b, const coeffs r)
387{
388#ifdef LDEBUG
389  nfTest(a, r);
390  nfTest(b, r);
391#endif
392  return (long)a != (long)b;
393}
394
395/*2
396* a == b ?
397*/
398BOOLEAN nfEqual (number a,number b, const coeffs r)
399{
400#ifdef LDEBUG
401  nfTest(a, r);
402  nfTest(b, r);
403#endif
404  return (long)a == (long)b;
405}
406
407/*2
408* write via StringAppend
409*/
410void nfWrite (number &a, const coeffs r)
411{
412#ifdef LDEBUG
413  nfTest(a, r);
414#endif
415  if ((long)a==(long)r->m_nfCharQ)  StringAppendS("0");
416  else if ((long)a==0L)   StringAppendS("1");
417  else if (nfIsMOne(a, r))   StringAppendS("-1");
418  else
419  {
420    StringAppendS(r->m_nfParameter);
421    if ((long)a!=1L)
422    {
423      if(r->ShortOut==0)  StringAppendS("^");
424      StringAppend("%d",(int)((long)a));
425    }
426  }
427}
428
429/*2
430*
431*/
432char * nfName(number a, const coeffs r)
433{
434#ifdef LDEBUG
435  nfTest(a, r);
436#endif
437  char *s;
438  char *nfParameter=r->m_nfParameter;
439  if (((long)a==(long)r->m_nfCharQ) || ((long)a==0L)) return NULL;
440  else if ((long)a==1L)
441  {
442    return omStrDup(nfParameter);
443  }
444  else
445  {
446    s=(char *)omAlloc(4+strlen(nfParameter));
447    sprintf(s,"%s%d",nfParameter,(int)((long)a));
448  }
449  return s;
450}
451/*2
452* c ^ i with i>=0
453*/
454void nfPower (number a, int i, number * result, const coeffs r)
455{
456#ifdef LDEBUG
457  nfTest(a, r);
458#endif
459  if (i==0)
460  {
461    //*result=nfInit(1);
462    *result = (number)0L;
463  }
464  else if (i==1)
465  {
466    *result = a;
467  }
468  else
469  {
470    nfPower(a,i-1,result, r);
471    *result = nfMult(a,*result, r);
472  }
473#ifdef LDEBUG
474  nfTest(*result, r);
475#endif
476}
477
478/*4
479* read an integer (with reduction mod p)
480*/
481static const char* nfEati(const char *s, int *i, const coeffs r)
482{
483  if (*s >= '0' && *s <= '9')
484  {
485    *i = 0;
486    do
487    {
488      *i *= 10;
489      *i += *s++ - '0';
490      if (*i > (INT_MAX / 10)) *i = *i % r->m_nfCharP;
491    }
492    while (*s >= '0' && *s <= '9');
493    if (*i >= r->m_nfCharP) *i = *i % r->m_nfCharP;
494  }
495  else *i = 1;
496  return s;
497}
498
499/*2
500* read a number
501*/
502const char * nfRead (const char *s, number *a, const coeffs r)
503{
504  int i;
505  number z;
506  number n;
507
508  s = nfEati(s, &i, r);
509  z=nfInit(i, r);
510  *a=z;
511  if (*s == '/')
512  {
513    s++;
514    s = nfEati(s, &i, r);
515    n=nfInit(i, r);
516    *a = nfDiv(z,n,r);
517  }
518  char *nfParameter=r->m_nfParameter;
519  if (strncmp(s,nfParameter,strlen(nfParameter))==0)
520  {
521    s+=strlen(nfParameter);
522    if ((*s >= '0') && (*s <= '9'))
523    {
524      s=eati(s,&i);
525      while (i>=r->m_nfCharQ1) i-=r->m_nfCharQ1;
526    }
527    else
528      i=1;
529    z=(number)(long)i;
530    *a=nfMult(*a,z,r);
531  }
532#ifdef LDEBUG
533  nfTest(*a, r);
534#endif
535  return s;
536}
537
538#ifdef HAVE_FACTORY
539int gf_tab_numdigits62 ( int q );
540int convertback62 ( char * p, int n );
541#else
542static int gf_tab_numdigits62 ( int q )
543{
544    if ( q < 62 )          return 1;
545    else  if ( q < 62*62 ) return 2;
546    /*else*/               return 3;
547}
548
549static int convback62 ( char c )
550{
551    if ( c >= '0' && c <= '9' )
552        return int(c) - int('0');
553    else  if ( c >= 'A' && c <= 'Z' )
554        return int(c) - int('A') + 10;
555    else
556        return int(c) - int('a') + 36;
557}
558
559static int convertback62 ( char * p, int n )
560{
561    int r = 0;
562    for ( int j = 0; j < n; j++ )
563        r = r * 62 + convback62( p[j] );
564    return r;
565}
566#endif
567
568int nfMinPoly[16];
569
570void nfShowMipo(const coeffs r)
571{
572  int i=nfMinPoly[0];
573  int j=0;
574  loop
575  {
576    j++;
577    if (nfMinPoly[j]!=0)
578      StringAppend("%d*%s^%d",nfMinPoly[j],r->m_nfParameter,i);
579    i--;
580    if(i<0) break;
581    if (nfMinPoly[j]!=0)
582      StringAppendS("+");
583  }
584}
585
586static void nfReadMipo(char *s)
587{
588  const char *l=strchr(s,';')+1;
589  char *n;
590  int i=strtol(l,&n,10);
591  l=n;
592  int j=1;
593  nfMinPoly[0]=i;
594  while(i>=0)
595  {
596    nfMinPoly[j]=strtol(l,&n,10);
597    if (l==n) break;
598    l=n;
599    j++;
600    i--;
601  }
602  if (i>=0)
603  {
604    WerrorS("error in reading minpoly from gftables");
605  }
606}
607
608/*2
609* init global variables from files 'gftables/%d'
610*/
611void nfReadTable(const int c, const coeffs r)
612{
613  //Print("GF(%d)\n",c);
614  if ((c==r->m_nfCharQ)||(c==-r->m_nfCharQ))
615    /*this field is already set*/  return;
616  int i=0;
617 
618  while ((fftable[i]!=c) && (fftable[i]!=0)) 
619    i++;
620 
621  if (fftable[i]==0)
622  {
623    Werror("illegal GF-table size: %d", c);
624    return;
625  }
626
627  if (r->m_nfCharQ > 1)
628  {
629    omFreeSize( (ADDRESS)r->m_nfPlus1Table,r->m_nfCharQ*sizeof(unsigned short) );
630    r->m_nfPlus1Table=NULL;
631  }
632  if ((c>1) || (c<0))
633  {
634    if (c>1) r->m_nfCharQ = c;
635    else     r->m_nfCharQ = -c;
636    char buf[100];
637    sprintf(buf,"gftables/%d",r->m_nfCharQ);
638    FILE * fp = feFopen(buf,"r",NULL,TRUE);
639    if (fp==NULL)
640    {
641      return;
642    }
643    if(!fgets( buf, sizeof(buf), fp)) return;
644    if(strcmp(buf,"@@ factory GF(q) table @@\n")!=0)
645    {
646      goto err;
647    }
648    if(!fgets( buf, sizeof(buf), fp))
649    {
650      goto err;
651    }
652    int q;
653    sscanf(buf,"%d %d",&r->m_nfCharP,&q);
654    nfReadMipo(buf);
655    r->m_nfCharQ1=r->m_nfCharQ-1;
656    //Print("nfCharQ=%d,nfCharQ1=%d,mipo=>>%s<<\n",nfCharQ,nfCharQ1,buf);
657    r->m_nfPlus1Table= (unsigned short *)omAlloc( (r->m_nfCharQ)*sizeof(unsigned short) );
658    int digs = gf_tab_numdigits62( r->m_nfCharQ );
659    char * bufptr;
660    int i = 1;
661    int k;
662    while ( i < r->m_nfCharQ )
663    {
664      fgets( buf, sizeof(buf), fp);
665      //( strlen( buffer ) == (size_t)digs * 30, "illegal table" );
666      bufptr = buf;
667      k = 0;
668      while ( (i < r->m_nfCharQ) && (k < 30) )
669      {
670        r->m_nfPlus1Table[i] = convertback62( bufptr, digs );
671        if(r->m_nfPlus1Table[i]>r->m_nfCharQ)
672        {
673          Print("wrong entry %d: %d(%c%c%c)\n",i,r->m_nfPlus1Table[i],bufptr[0],bufptr[1],bufptr[2]);
674        }
675        bufptr += digs;
676        if (r->m_nfPlus1Table[i]==r->m_nfCharQ)
677        {
678          if(i==r->m_nfCharQ1)
679          {
680            r->m_nfM1=0;
681          }
682          else
683          {
684            r->m_nfM1=i;
685          }
686        }
687        i++; k++;
688      }
689    }
690    r->m_nfPlus1Table[0]=r->m_nfPlus1Table[r->m_nfCharQ1];
691  }
692  else
693    r->m_nfCharQ=0;
694#ifdef LDEBUG
695  nfTest((number)0, r);
696#endif
697  return;
698err:
699  Werror("illegal GF-table %d",r->m_nfCharQ);
700}
701
702/*2
703* map Z/p -> GF(p,n)
704*/
705number nfMapP(number c, const coeffs, const coeffs dst)
706{
707  return nfInit((int)((long)c), dst);
708}
709
710/*2
711* map GF(p,n1) -> GF(p,n2), n1 < n2, n1 | n2
712*/
713int nfMapGG_factor;
714number nfMapGG(number c, const coeffs src, const coeffs)
715{
716  int i=(long)c;
717  i*= nfMapGG_factor;
718  while (i >src->m_nfCharQ1) i-=src->m_nfCharQ1;
719  return (number)((long)i);
720}
721/*2
722* map GF(p,n1) -> GF(p,n2), n1 > n2, n2 | n1
723*/
724number nfMapGGrev(number c, const coeffs src, const coeffs)
725{
726  int ex=(int)((long)c);
727  if ((ex % nfMapGG_factor)==0)
728    return (number)(((long)ex) / ((long)nfMapGG_factor));
729  else
730    return (number)(long)src->m_nfCharQ; /* 0 */
731}
732
733/*2
734* set map function nMap ... -> GF(p,n)
735*/
736nMapFunc nfSetMap(const coeffs src, const coeffs dst)
737{
738  if (nCoeff_is_GF(src,src->m_nfCharQ))
739  {
740    return ndCopyMap;   /* GF(p,n) -> GF(p,n) */
741  }
742  if (nCoeff_is_GF(src))
743  {
744    const coeffs r = dst;
745    int q=src->ch;
746    if ((src->m_nfCharQ % q)==0) /* GF(p,n1) -> GF(p,n2), n2 > n1 */
747    {
748      // check if n2 is a multiple of n1
749      int n1=1;
750      int qq=r->m_nfCharP;
751      while(qq!=q) { qq *= r->m_nfCharP; n1++; }
752      int n2=1;
753      qq=r->m_nfCharP;
754      while(qq!=src->m_nfCharQ) { qq *= r->m_nfCharP; n2++; }
755      Print("map %d^%d -> %d^%d\n",r->m_nfCharP,n1,r->m_nfCharP,n2);
756      if ((n2 % n1)==0)
757      {
758        int save_ch=r->ch;
759        nfReadTable(src->ch, r);
760        int nn=r->m_nfPlus1Table[0];
761        nfReadTable(save_ch, r);
762        nfMapGG_factor= r->m_nfPlus1Table[0] / nn;
763        Print("nfMapGG_factor=%d (%d / %d)\n",nfMapGG_factor, r->m_nfPlus1Table[0], nn);
764        return nfMapGG;
765      }
766      else if ((n1 % n2)==0)
767      {
768        nfMapGG_factor= (n1/n2);
769        return nfMapGGrev;
770      }
771      else
772        return NULL;
773    }
774  }
775  if (nCoeff_is_Zp(src,src->m_nfCharP))
776  {
777    return nfMapP;    /* Z/p -> GF(p,n) */
778  }
779  return NULL;     /* default */
780}
781
782BOOLEAN nfInitChar(coeffs r,  void * parameter)
783{
784
785
786  //r->cfInitChar=npInitChar;
787  //r->cfKillChar=nfKillChar;
788  r->cfSetChar= NULL;
789  //r->nCoeffIsEqual=nfCoeffsEqual;
790
791  r->cfMult  = nfMult;
792  r->cfSub   = nfSub;
793  r->cfAdd   = nfAdd;
794  r->cfDiv   = nfDiv;
795  r->cfIntDiv= nfDiv;
796  //r->cfIntMod= ndIntMod;
797  r->cfExactDiv= nfDiv;
798  r->cfInit = nfInit;
799  //r->cfPar = ndPar;
800  //r->cfParDeg = ndParDeg;
801  //r->cfSize  = ndSize;
802  r->cfInt  = nfInt;
803  #ifdef HAVE_RINGS
804  //r->cfDivComp = NULL; // only for ring stuff
805  //r->cfIsUnit = NULL; // only for ring stuff
806  //r->cfGetUnit = NULL; // only for ring stuff
807  //r->cfExtGcd = NULL; // only for ring stuff
808  // r->cfDivBy = NULL; // only for ring stuff
809  #endif
810  r->cfNeg   = nfNeg;
811  r->cfInvers= nfInvers;
812  //r->cfCopy  = ndCopy;
813  //r->cfRePart = ndCopy;
814  //r->cfImPart = ndReturn0;
815  r->cfWrite = nfWrite;
816  r->cfRead = nfRead;
817  //r->cfNormalize=ndNormalize;
818  r->cfGreater = nfGreater;
819  r->cfEqual = nfEqual;
820  r->cfIsZero = nfIsZero;
821  r->cfIsOne = nfIsOne;
822  r->cfIsMOne = nfIsMOne;
823  r->cfGreaterZero = nfGreaterZero;
824  r->cfPower = nfPower;
825  //r->cfGcd  = ndGcd;
826  //r->cfLcm  = ndGcd;
827  //r->cfDelete= ndDelete;
828  r->cfSetMap = nfSetMap;
829  //r->cfName = ndName;
830  // debug stuff
831
832#ifdef LDEBUG
833  r->cfDBTest=nfDBTest;
834#endif
835 
836  // the variables:
837  r->nNULL = (number)0;
838  assume( r->type == n_GF );
839
840  GFInfo* p = (GFInfo *)(parameter); 
841  const char * name = p->GFPar_name;
842  r->m_nfCharQ = 0;
843  r->m_nfCharP = p->GFChar;
844  r->m_nfCharQ1 = 0;
845  r->m_nfParameter= strdup(name); //TODO use omAlloc for allocating memory and use strcpy?
846  r->m_nfPlus1Table= NULL;
847
848  r->has_simple_Alloc=TRUE;
849  r->has_simple_Inverse=TRUE;
850
851  assume (p->GFChar > 0);
852  assume (p->GFDegree > 0);
853
854  if(p->GFChar > (2<<15))
855  {
856    Werror("illegal characteristic");
857    return TRUE;
858  }
859
860  const double check= log ((double) (p->GFChar)); 
861
862  if( (p->GFDegree * check) > sixteenlog2 )
863  {
864    Werror("Sorry: illegal size: %u ^ %u", p->GFChar, p->GFDegree );
865    return TRUE;
866  }
867
868  int c = pow (p->GFChar, p->GFDegree);
869
870  nfReadTable(c, r);
871 
872  if( r->m_nfPlus1Table == NULL )
873  {
874    Werror("Sorry: cannot init lookup table!");
875    return TRUE;
876  }
877 
878 
879  assume (r -> m_nfCharQ > 0);
880
881  r->ch = r->m_nfCharP; 
882  assume( r->m_nfPlus1Table != NULL );
883 
884  return FALSE;
885 
886}
Note: See TracBrowser for help on using the repository browser.