MeatAxe
2.4
Programs for working with modular representations

The finite field part of the kernel provides finite field arithmetic and basic operations with vectors and matrices over finite fields.
The kernel cannot operate simultaneously with different finite fields, because there is a global row size and a global field order which must be maintained by the higher layers.
There are two finite field modules available: one for small fields (up to 256) and one for larger fields (up to 2^{16}). The finite field module is selected at compile time.
As a consequence of the different representations of field elements in the small and big version, there are some rules which should be respected by all programs:
*FEL
, but this is not mandatory. Macros  
#define  FF_ZERO ((FEL)0) 
The zero field element.  
#define  FF_ONE ((FEL)1) 
The unit element.  
Typedefs  
typedef unsigned char  FEL 
A finite field element.  
typedef FEL *  PTR 
A pointer to a row vector.  
Functions  
int  FfReadRows (FILE *f, PTR buf, int n) 
Read Rows This function reads 1 or more rows from a file. More...  
int  FfWriteRows (FILE *f, PTR buf, int n) 
Write rows This function writes 1 or more rows to a file. More...  
int  FfSeekRow (FILE *f, int pos) 
Move to a Row. More...  
FILE *  FfReadHeader (const char *name, int *field, int *nor, int *noc) 
Open File and Read Header. More...  
FILE *  FfWriteHeader (const char *name, int field, int nor, int noc) 
Open file and write header. More...  
FEL  FfAdd (FEL a, FEL b) 
Finite field addition. More...  
FEL  FfSub (FEL a, FEL b) 
Finite field subtraction. More...  
FEL  FfMul (FEL a, FEL b) 
Finite field multiplication. More...  
FEL  FfDiv (FEL a, FEL b) 
Finite field division. More...  
FEL  FfNeg (FEL a) 
Finite field negative. More...  
FEL  FfInv (FEL a) 
Finite field inversion. More...  
int  FfSetField (int field) 
Sets the field order. More...  
int  FfSetNoc (int noc) 
Set the row length. More...  
void  FfAddMulRow (PTR dest, PTR src, FEL f) 
Add a multiple of a row. More...  
PTR  FfAddRow (PTR dest, PTR src) 
Add two rows. More...  
PTR  FfAddRowPartial (PTR dest, PTR src, int first, int len) 
Add a part two rows. More...  
PTR  FfAlloc (int nor) 
Allocate memory and initialize This function allocates a block of memory for a vector (if nrows is 1) or a matrix. More...  
int  FfCmpRows (PTR p1, PTR p2) 
Compare two rows. More...  
void  FfCleanRow (PTR row, PTR matrix, int nor, const int *piv) 
Clean Row. More...  
void  FfCleanRow2 (PTR row, PTR mat, int nor, const int *piv, PTR row2) 
Clean Row and Record Operations. More...  
void  FfCleanRowAndRepeat (PTR row, PTR mat, int nor, const int *piv, PTR row2, PTR mat2) 
Clean Row and Repeat Operations. More...  
void  FfCopyRow (PTR dest, PTR src) 
Copy a row. More...  
FEL  FfEmbed (FEL a, int subfield) 
Embed a subfield. More...  
FEL  FfExtract (PTR row, int col) 
Extract a mark from a row This function returns the entry at position col of row. More...  
void  FfExtractColumn (PTR mat, int nor, int col, PTR result) 
Extract one column of a matrix. More...  
int  FfFindPivot (PTR row, FEL *mark) 
Find pivot column. More...  
void  FfFree (PTR x) 
Free memory. More...  
FEL  FfFromInt (int l) 
Convert integer to field element. More...  
PTR  FfGetPtr (PTR base, int row) 
Get row pointer. More...  
void  FfInsert (PTR row, int col, FEL mark) 
Insert a mark into a row This function inserts the field element mark at position col into row. More...  
void  FfMulRow (PTR row, FEL mark) 
Multiply a row by a coefficient. More...  
FEL  FfRestrict (FEL a, int subfield) 
Restrict to a subfield. More...  
size_t  FfRowSize (int noc) 
Calculate row size. More...  
FEL  FfScalarProduct (PTR a, PTR b) 
Scalar Product of Two Vectors. More...  
int  FfStepPtr (PTR *x) 
Advance to next row. More...  
void  FfSwapRows (PTR dest, PTR src) 
Exchange two rows This function exchanges the contents of two rows. More...  
const char *  FfToGap (FEL f) 
Convert to GAP format. More...  
int  FfToInt (FEL f) 
Convert field element to integer. More...  
size_t  FfTrueRowSize (int noc) 
Number of used bytes in a row. More...  
int  FfSumAndIntersection (PTR wrk1, int *nor1, int *nor2, PTR wrk2, int *piv) 
Sum and Intersection of Two Vector Spaces. More...  
void  FfPermRow (PTR row, const long *perm, PTR result) 
Multiply a Vector by a Permutation. More...  
Variables  
int  FfOrder 
The current field order. More...  
int  FfChar 
Characteristic of the current field. More...  
FEL  FfGen 
Field generator. More...  
int  FfNoc 
Current row size. More...  
size_t  FfCurrentRowSize 
The number of bytes occupied by a single row in memory. More...  
Finite field addition.
This function returns the sum of two field elements. Before calling FfAdd(), the field must have been selected with FfSetField(). The arguments are not checked. If either argument is not in the allowed range the result is undefined and the program may crash. FfAdd() may be implemented as a macro. In this case, it is guaranteed that both arguments are evaluated exactly once.
Add a multiple of a row.
This function adds a multiple of src to dest.
Add two rows.
This function adds src to dest. Field order and row size must have been set before.
dest  The row to add to. 
src  The row to add. 
Add a part two rows.
This works like FfAddRow(), but the operation is performed only on a given range of columns. Note that the working range is not specified as column indexes but in units of long integers!
dest  The row to add to. 
src  The row to add. 
first  Number of long integers to skip. 
len  Number of long integers to add. 
PTR FfAlloc  (  int  nrows  ) 
Allocate memory and initialize This function allocates a block of memory for a vector (if nrows is 1) or a matrix.
Memory is initialized to zero. Field order and row size must have been set with FfSetField() and FfSetNoc(), respectively. nrows may be zero zero, i which case the functin returns a memory block of size zero which must be freed using FfFree().
nrows  Number of rows. 
Clean Row.
This function performs a Gaussian elimination, i.e., it adds suitable multiples of the rows of matrix to row such that all pivot positions are zero. piv is the pivot table for matrix. As usual, all indexes are 0based, i.e., piv[0]
is the pivot column of the first row, and for a unit matrix we have piv[0]==0
. The field and row size must have been set before calling this function.
row  The row to be cleaned. 
matrix  Pointer to the matrix. 
nor  Number of rows of the matrix. 
piv  The pivot table. 
Clean Row and Record Operations.
This function works like FfCleanRow(), but it stores a record of the operations performed in row2. row2 must be a row of at least nor entries. On return, row2 contains the coefficients by which the rows of mat were multiplied and then subtracted from row. Before calling FfCleanRow2(), the caller must initialize row2 to zero. Otherwise the results are undefined.
row  Pointer to row to be cleaned. 
mat  Matrix to clean with. 
nor  Number of rows. 
piv  Pivot table for matrix. 
row2  Pointer to row where the operations are recorded. 
Clean Row and Repeat Operations.
This function works like FfCleanRow(), but repeats all operations on a second row/matrix.
row  Pointer to row to be cleaned. 
mat  Matrix to clean with. 
nor  Number of rows. 
piv  Pivot table for mat. 
row2  Pointer to the second row to be cleaned. 
mat2  Matrix to the second matrix. 
Compare two rows.
This function compares two row vectors. As with all row operations, the row length must have been set before with FfSetNoc(). The return value is negative if the first row is "less" than the second row, and it is positive if the first row is "greater" than the second row. However, the ordering defined by FfCmpRows() depends on the internal representation of finite field elements and can differ between dirrerent kernels or between different hardware architectures.
p1  Pointer to the first matrix. 
p2  Pointer to the second matrix. 
Copy a row.
This function copies the contents of one row to another row. As with all row operations, the row length must have been set before with FfSetNoc().
dest  Pointer to the destination. 
src  Pointer to the source. 
Finite field division.
This function returns the quotient of two field elements. Before calling FfDiv(), the field must have been selected with FfSetField(). The arguments are not checked. If either argument is not in the allowed range or if the denominator is zero, the result is undefined and the program may crash. FfDiv() may be implemented as a macro. In this case, it is guaranteed that both arguments are evaluated exactly once.
Embed a subfield.
a  Element of the subfield field. 
subfield  Subfield order. Must be a divisor of the current field order. 
Extract a mark from a row This function returns the entry at position col of row.
Note that column indexes start with 0, i.e., FfExtract(row,0) returns the first entry. Like FfInsert(), this function does not depend on the current row size. The index, col, is not checked. Reading at negative positions or beyond the end of the row results in undefined behaviour.
row  Pointer to the row. 
col  Index of mark to extract (0 based). 
Extract one column of a matrix.
This function extracts one column out of a matrix and converts it into a row vector. The number of columns of the matrix must have been set with FfSetNoc(), and the number of rows must be passed in the call. The result is a row with nor entries, and the output buffer, result, must be large enough to store a vector of this size. mat and result must not overlap. If they do, the result is undefined.
mat  Pointer to the matrix. 
nor  Number of rows in matrix. 
col  Column to extract (starting with 0). 
result  Pointer to buffer for the extracted column. 
Find pivot column.
This function finds the first nonzero mark in a row vector. The mark is stored into *mark
and its position (counting from 0) is returned. If the whole vector is zero, FfFindPivot() returns 1 and leaves *mark
unchanged.
row  Pointer to the row. 
mark  Buffer for pivot element. 
void FfFree  (  PTR  x  ) 
Free memory.
This function frees a block of memory that has been allocated with FfAlloc() before. If the argument is 0, FfFree() does nothing.
x  Pointer to memory. 
FEL FfFromInt  (  int  l  ) 
Convert integer to field element.
This function converts an integer to a field element using the same mapping as explained under FfToInt(). Both functions are inverse in the sense that the expression f == FfFromInt(FfToInt(f))
is always true for valid field elements. FfFromInt() should be used whenever field elements are to be read with scanf().
Get row pointer.
This function returns a pointer to the north row of a matrix, assuming the current row size. base must be a pointer to the beginning of a row, but this need not be the first row of the matrix. For example, the following code steps through the odd rows of a matrix:
Note: The function does not check if the resulting pointer is still inside the matrix.
base  Pointer to the first row of the matrix. 
row  Row index. 
Insert a mark into a row This function inserts the field element mark at position col into row.
Column indexes start with 0. Before this function can be used, the field must be selected with FfSetField(). FfInsert() does not need the row size beeing set correctly. For example, if you are working with rows of different size, you do not have to call FfSetNoc() prior to each FfInsert(). On the other hand, there is no protection against writing beyond the end of a row.
If the MeatAxe is compiled with the DEBUG option FfInsert() checks that mark is a valid field element and col is not negative. If also the PARANOID option was in effect during compilation, FfInsert() also checks if col is less than or equal to the current row size.
row  Pointer to the row. 
col  Insert position (0based). 
mark  Value to insert. 
FfInv  (  FEL  a  ) 
Finite field inversion.
This function returns the multiplicative inverse a field element. Before calling FfInv(), the field must have been selected with FfSetField(). The argument is not checked. If you pass an invalid value or zero, the result is undefined and the program may crash. FfInv() may be implemented as a macro. In this case, it is guaranteed that the argument is evaluated exactly once.
Finite field multiplication.
This function returns the product of two field elements. Before calling FfMul(), the field must have been selected with FfSetField(). The arguments are not checked. If either argument is not in the allowed range the result is undefined and the program may crash. FfMul() may be implemented as a macro. In this case, it is guaranteed that both arguments are evaluated exactly once.
Multiply a row by a coefficient.
This function multiplies each element of row by mark. The row size and field order must have been set before. Multiplying a row with zero (FF_ZERO) initializes all elements to zero and is permitted even if row points into uninitialized memory.
FfNeg  (  FEL  a  ) 
Finite field negative.
This function returns the additive inverse a field element. Before calling FfInv(), the field must have been selected with FfSetField(). The argument is not checked. If you pass an invalid value, the result is undefined and the program may crash. FfNeg() may be implemented as a macro. In this case, it is guaranteed that the argument is evaluated exactly once.
Multiply a Vector by a Permutation.
This function multiplies the vector row from the right with the permutation perm and stores the result in result. Multiplication of vectors by permutations is defined as follows: if the permutation maps i to k, then the iith mark of the vector is stored in the kth position of the result.
Note: result and row must not overlap. Otherwise the result is undefined.
FILE * FfReadHeader  (  const char *  name, 
int *  field,  
int *  nor,  
int *  noc  
) 
Open File and Read Header.
This function opens a data file for input and reads the file header (3 integers). The exact meaning of the header values depends on the file type. For a matrix they are field order, number of rows and number of columns. See File Formats for details.
name  File name. 
field  Pointer to buffer for first header entry (usually the field order). 
nor  Pointer to buffer for second header entry (usually the number of rows). 
noc  Pointer to buffer for third header entry (usually the number of columns). 
int FfReadRows  (  FILE *  f, 
PTR  buf,  
int  n  
) 
Read Rows This function reads 1 or more rows from a file.
The row size must have been set before.
f  Pointer to File. 
buf  Pointer to data buffer. 
n  Number of rows to read. 
Restrict to a subfield.
This function restricts a field element from the current field to a subfield. The return value represents the same element as a but with respect to the subfield. In general, the element has a different integer representation in the subfield. Consequently, you cannot use the return value for field arithmetic until you change to the subfield with Of course, the argument must be an element of the subfield. Otherwise the result is undefined. FfSetField(subfield)
.
a  Element of the current field. 
subfield  Subfield order. Must be a divisor of the current field order. 
size_t FfRowSize  (  int  noc  ) 
Calculate row size.
Returns the number of bytes occupied in memory by a row of noc Elements. The row size is always a multiple of sizeof(long)
. Depending on the number of columns there may be unused padding bytes at the end of the row.
Scalar Product of Two Vectors.
Given two vectors \(a=(a_i)\) and \(b=(b_i)\), this function calculates the scalar product \(p=\sum_ia_ib_i\).
a  The first vector. 
b  The second vector. 
int FfSeekRow  (  FILE *  f, 
int  pos  
) 
Move to a Row.
This function sets the read/write pointer of file f to position pos. I.e., the next FfReadRows() or FfWriteRows() will start at the specified row. Note that row numbers start with 0. If pos is different from 0, the row size must have been set before with FfSetNoc().
You should always use FfSeekRow() rather than fseek() because FfSeekRow() knows about MeatAxe file headers and adjusts the file pointer appropriately.
f  Pointer to File. 
pos  Row number (0based). 
int FfSetField  (  int  field  ) 
Sets the field order.
This function sets the current field to GF(field) and initializes the field arithmetic. Most kernel functions require that a field has been selected before they are used.
field  Field order. 
int FfSetNoc  (  int  noc  ) 
Set the row length.
This function sets the current row size, which is used for lowlevel row operations such as FfAddRow().
noc  Number of columns. 
int FfStepPtr  (  PTR *  x  ) 
Advance to next row.
This function increments a pointer by 1 row. The row size must have been set before with FfSetNoc(). FfStepPtr(&x) is equivalent to x = FfGetPtr(x,1). It is typically used to step through the rows of a matrix. Here is an example with a 100 by 40 matrix:
x  Pointer to the row pointer. 
Finite field subtraction.
This function returns the difference of two field elements. Before calling FfSub(), the field must have been selected with FfSetField(). The arguments are not checked. If either argument is not in the allowed range the result is undefined and the program may crash. FfSub() may be implemented as a macro. In this case, it is guaranteed that both arguments are evaluated exactly once.
Sum and Intersection of Two Vector Spaces.
Given two vector spaces V,W∊F^{n}, this function calculates the sum and the intersection of the spaces, using the Zassenhaus algorithm. Each of the two spaces is given by a set of generating vectors, which need not be linearly independent. Before calling SumAndIntersection() the caller must allocate and initialize two workspaces and a pivot table:
The variables pointed to by nor1 and nor2 must contain the numbers n₁ and n₂, respectively. On return, *nor1 contains the dimension of V+W, and *nor2 contains the dimension of V∩W. The first dim(V+W) rows of wrk1 contain a basis of V+W, and a basis of V∩W can be found in wrk2 starting at position dim(V+W). Both bases are in echelon form, and piv contains the pivot table for the bases.
wrk1  Workspace 1. 
nor1  Input: number of generators for V, output: dim(V+W). 
nor2  Input: number of generators for W, output: dim(V∩W). 
wrk2  Workspace 2. 
piv  Pivot table. 
Exchange two rows This function exchanges the contents of two rows.
As with all row operations, the row length must have been set before with FfSetNoc().
dest  Pointer to the first row 
src  Pointer to the second row 
const char* FfToGap  (  FEL  f  ) 
Convert to GAP format.
This function takes a field element and returns the GAP representation of this element. The return value is a pointer to a static buffer which is overwritten on each call.
f  Field element. 
int FfToInt  (  FEL  f  ) 
Convert field element to integer.
This function converts a field element to an integer, using a "canonical" representation of field elements as integers which may be different from the internal representation. In particular, the prime field is mapped on {0,...p1} with 0 representing the zero element and 1 the unit element. FfToInt() should be used whenever field elements are to be written with printf().
size_t FfTrueRowSize  (  int  noc  ) 
Number of used bytes in a row.
This function returns the number of bytes that are actually used by a row of noc Elements, i.e., without counting the padding bytes. This number is less than or equal to FfRowSize(noc)
.
FILE * FfWriteHeader  (  const char *  name, 
int  field,  
int  nor,  
int  noc  
) 
Open file and write header.
This function opens a data file for input and writes the the file header. If the file does not exist, a new file is created. If the file exists it is overwritten.
name  File name. 
field  First header entry (usually the field order). 
nor  Second header entry (usually the number of rows). 
noc  Third header entry (usually the number of columns). 
int FfWriteRows  (  FILE *  f, 
PTR  buf,  
int  n  
) 
Write rows This function writes 1 or more rows to a file.
The row size must have been set before.
f  Pointer to File. 
buf  Pointer to data buffer. 
n  Number of rows to write. 
int FfChar 
Characteristic of the current field.
Like FfOrder, this variable may be used anywhere, but it must not be modified directly.
size_t FfCurrentRowSize 
The number of bytes occupied by a single row in memory.
Equal to FfRowSize(FfNoc)
and always a multiple of sizeof(long).
FEL FfGen 
Field generator.
This variable contains a generator for the multiplicative group of the current field.
int FfNoc 
Current row size.
Used by all lowlevel row operations. FfNoc is updated automatically when the row size is changed with FfSetNoc().
int FfOrder 
The current field order.
May be used in expressions but must never modified directly. To change the field, use FfSetField().