My Project
Loading...
Searching...
No Matches
Functions | Variables
gfops.cc File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cf_assert.h"
#include "cf_defs.h"
#include "gf_tabutil.h"
#include "cf_util.h"
#include "canonicalform.h"
#include "variable.h"
#include "gfops.h"
#include "singext.h"

Go to the source code of this file.

Functions

static CanonicalForm intVec2CF (int degree, int *coeffs, int level)
 
void set_gftable_dir (char *d)
 
static void gf_get_table (int p, int n)
 
void gf_setcharacteristic (int p, int n, char name)
 
long gf_gf2ff (long a)
 
int gf_gf2ff (int a)
 
bool gf_isff (long a)
 
bool gf_isff (int a)
 

Variables

const int gf_maxtable = 63001
 
const int gf_maxbuffer = 200
 
const int gf_primes_len = 42
 
VAR int gf_q = 0
 
VAR int gf_p = 0
 
VAR int gf_n = 0
 
VAR int gf_q1 = 0
 
VAR int gf_m1 = 0
 
VAR char gf_name = 'Z'
 
VAR unsigned short * gf_table = 0
 
INST_VAR CanonicalForm gf_mipo =0L
 
STATIC_VAR char * gftable_dir
 

Function Documentation

◆ gf_get_table()

static void gf_get_table ( int  p,
int  n 
)
static

Definition at line 76 of file gfops.cc.

77{
78 char buffer[gf_maxbuffer];
79 int q = ipower( p, n );
80
81 // do not read the table a second time
82 if ( gf_q == q )
83 {
84 return;
85 }
86
87 if ( gf_table == 0 )
88 gf_table = new unsigned short[gf_maxtable];
89
90 // try to open file
91 char *gffilename;
92 FILE * inputfile;
93 if (gftable_dir)
94 {
95 sprintf( buffer, "gftables/%d", q);
96 gffilename = (char *)malloc(strlen(gftable_dir) + strlen(buffer) + 1);
97 STICKYASSERT(gffilename,"out of memory");
98 strcpy(gffilename,gftable_dir);
99 strcat(gffilename,buffer);
100 inputfile = fopen( gffilename, "r" );
101 }
102 else
103 {
104 sprintf( buffer, "gftables/%d", q );
105 gffilename = buffer;
106#ifndef SINGULAR
107 inputfile = fopen( buffer, "r" );
108#else
109 inputfile = feFopen( buffer, "r" );
110#endif
111 }
112 if (!inputfile)
113 {
114 fprintf(stderr,"can not open GF(q) addition table: %s\n",gffilename);
115 STICKYASSERT(inputfile, "can not open GF(q) table");
116 }
117
118 // read ID
119 char * bufptr;
120 char * success;
121 success = fgets( buffer, gf_maxbuffer, inputfile );
122 STICKYASSERT( success, "illegal table (reading ID)" );
123 STICKYASSERT( strcmp( buffer, "@@ factory GF(q) table @@\n" ) == 0, "illegal table" );
124 // read p and n from file
125 int pFile, nFile;
126 success = fgets( buffer, gf_maxbuffer, inputfile );
127 STICKYASSERT( success, "illegal table (reading p and n)" );
128 sscanf( buffer, "%d %d", &pFile, &nFile );
129 STICKYASSERT( p == pFile && n == nFile, "illegal table" );
130 // skip (sic!) factory-representation of mipo
131 // and terminating "; "
132 bufptr = (char *)strchr( buffer, ';' ) + 2;
133 // read simple representation of mipo
134 int i, degree;
135 sscanf( bufptr, "%d", &degree );
136 bufptr = (char *)strchr( bufptr, ' ' ) + 1;
137 int * mipo = NEW_ARRAY(int,degree+1);
138 for ( i = 0; i <= degree; i++ )
139 {
140 sscanf( bufptr, "%d", mipo + i );
141 bufptr = (char *)strchr( bufptr, ' ' ) + 1;
142 }
143
144 gf_p = p; gf_n = n;
145 gf_q = q; gf_q1 = q-1;
146 gf_mipo = intVec2CF( degree, mipo, 1 );
148
149 // now for the table
150 int k, digs = gf_tab_numdigits62( gf_q );
151 i = 1;
152 while ( i < gf_q )
153 {
154 success = fgets( buffer, gf_maxbuffer, inputfile );
155 STICKYASSERT( strlen( buffer ) - 1 == (size_t)digs * 30, "illegal table" );
156 bufptr = buffer;
157 k = 0;
158 while ( i < gf_q && k < 30 )
159 {
160 gf_table[i] = convertback62( bufptr, digs );
161 bufptr += digs;
162 if ( gf_table[i] == gf_q )
163 {
164 if ( i == gf_q1 )
165 gf_m1 = 0;
166 else
167 gf_m1 = i;
168 }
169 i++; k++;
170 }
171 }
172 gf_table[0] = gf_table[gf_q1];
173 gf_table[gf_q] = 0;
174
175 (void)fclose( inputfile );
176}
int degree(const CanonicalForm &f)
int i
Definition: cfEzgcd.cc:132
int k
Definition: cfEzgcd.cc:99
int p
Definition: cfModGcd.cc:4078
#define STICKYASSERT(expression, message)
Definition: cf_assert.h:64
#define DELETE_ARRAY(P)
Definition: cf_defs.h:65
#define NEW_ARRAY(T, N)
Definition: cf_defs.h:64
int ipower(int b, int m)
int ipower ( int b, int m )
Definition: cf_util.cc:27
CanonicalForm mipo
Definition: facAlgExt.cc:57
FILE * feFopen(const char *path, const char *mode, char *where, short useWerror, short path_only)
Definition: feFopen.cc:47
int convertback62(char *p, int n)
Definition: gf_tabutil.cc:50
int gf_tab_numdigits62(int q)
Definition: gf_tabutil.cc:12
const int gf_maxtable
Definition: gfops.cc:30
VAR int gf_m1
Definition: gfops.cc:51
VAR int gf_q
Definition: gfops.cc:47
VAR int gf_n
Definition: gfops.cc:49
STATIC_VAR char * gftable_dir
Definition: gfops.cc:69
VAR unsigned short * gf_table
Definition: gfops.cc:54
static CanonicalForm intVec2CF(int degree, int *coeffs, int level)
Definition: gfops.cc:58
const int gf_maxbuffer
Definition: gfops.cc:31
VAR int gf_p
Definition: gfops.cc:48
INST_VAR CanonicalForm gf_mipo
Definition: gfops.cc:56
VAR int gf_q1
Definition: gfops.cc:50
#define malloc
Definition: omAllocFunc.c:12

◆ gf_gf2ff() [1/2]

int gf_gf2ff ( int  a)

Definition at line 231 of file gfops.cc.

232{
233 if ( gf_iszero( a ) )
234 return 0;
235 else
236 {
237 // starting from z^0=1, step through the table
238 // counting the steps until we hit z^a or z^0
239 // again. since we are working in char(p), the
240 // latter is guaranteed to be fulfilled.
241 int i = 0, ff = 1;
242 do
243 {
244 if ( i == a )
245 return ff;
246 ff++;
247 i = gf_table[i];
248 } while ( i != 0 );
249 return -1;
250 }
251}
bool gf_iszero(int a)
Definition: gfops.h:43

◆ gf_gf2ff() [2/2]

long gf_gf2ff ( long  a)

Definition at line 209 of file gfops.cc.

210{
211 if ( gf_iszero( a ) )
212 return 0;
213 else
214 {
215 // starting from z^0=1, step through the table
216 // counting the steps until we hit z^a or z^0
217 // again. since we are working in char(p), the
218 // latter is guaranteed to be fulfilled.
219 long i = 0, ff = 1;
220 do
221 {
222 if ( i == a )
223 return ff;
224 ff++;
225 i = gf_table[i];
226 } while ( i != 0 );
227 return -1;
228 }
229}

◆ gf_isff() [1/2]

bool gf_isff ( int  a)

Definition at line 264 of file gfops.cc.

265{
266 if ( gf_iszero( a ) )
267 return true;
268 else
269 {
270 // z^a in GF(p) iff (z^a)^p-1=1
271 return gf_isone( gf_power( a, gf_p - 1 ) );
272 }
273}
bool gf_isone(int a)
Definition: gfops.h:53
int gf_power(int a, int n)
Definition: gfops.h:222

◆ gf_isff() [2/2]

bool gf_isff ( long  a)

Definition at line 253 of file gfops.cc.

254{
255 if ( gf_iszero( a ) )
256 return true;
257 else
258 {
259 // z^a in GF(p) iff (z^a)^p-1=1
260 return gf_isone( gf_power( a, gf_p - 1 ) );
261 }
262}

◆ gf_setcharacteristic()

void gf_setcharacteristic ( int  p,
int  n,
char  name 
)

Definition at line 202 of file gfops.cc.

203{
204 ASSERT( gf_valid_combination( p, n ), "illegal immediate GF(q)" );
205 gf_name = name;
206 gf_get_table( p, n );
207}
#define ASSERT(expression, message)
Definition: cf_assert.h:99
VAR char gf_name
Definition: gfops.cc:52
static void gf_get_table(int p, int n)
Definition: gfops.cc:76
int name
New type name for int.
Definition: templateForC.h:21

◆ intVec2CF()

static CanonicalForm intVec2CF ( int  degree,
int *  coeffs,
int  level 
)
static

Definition at line 58 of file gfops.cc.

59{
60 int i;
62 for ( i = 0; i <= degree; i++ )
63 {
65 }
66 return result;
67}
CanonicalForm power(const CanonicalForm &f, int n)
exponentiation
int level(const CanonicalForm &f)
factory's main class
Definition: canonicalform.h:86
factory's class for variables
Definition: variable.h:33
return result
Definition: facAbsBiFact.cc:75
The main handler for Singular numbers which are suitable for Singular polynomials.

◆ set_gftable_dir()

void set_gftable_dir ( char *  d)

Definition at line 71 of file gfops.cc.

71 {
72 gftable_dir = d;
73 }

Variable Documentation

◆ gf_m1

VAR int gf_m1 = 0

Definition at line 51 of file gfops.cc.

◆ gf_maxbuffer

const int gf_maxbuffer = 200

Definition at line 31 of file gfops.cc.

◆ gf_maxtable

const int gf_maxtable = 63001

Definition at line 30 of file gfops.cc.

◆ gf_mipo

INST_VAR CanonicalForm gf_mipo =0L

Definition at line 56 of file gfops.cc.

◆ gf_n

VAR int gf_n = 0

Definition at line 49 of file gfops.cc.

◆ gf_name

VAR char gf_name = 'Z'

Definition at line 52 of file gfops.cc.

◆ gf_p

VAR int gf_p = 0

Definition at line 48 of file gfops.cc.

◆ gf_primes_len

const int gf_primes_len = 42

Definition at line 33 of file gfops.cc.

◆ gf_q

VAR int gf_q = 0

Definition at line 47 of file gfops.cc.

◆ gf_q1

VAR int gf_q1 = 0

Definition at line 50 of file gfops.cc.

◆ gf_table

VAR unsigned short* gf_table = 0

Definition at line 54 of file gfops.cc.

◆ gftable_dir

STATIC_VAR char* gftable_dir

Definition at line 69 of file gfops.cc.