Skip to content

Commit

Permalink
updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
assaferan committed Jun 16, 2023
1 parent ee78622 commit 999353e
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 4 deletions.
191 changes: 189 additions & 2 deletions include/fq_nmod_mat.h
Original file line number Diff line number Diff line change
@@ -1,25 +1,212 @@
/***********************************************************
*
* Package : omf5 - orthogonal modular forms of rank 5
* Filename : fq_nmod_mat.h
*
* Description: functions for handling the type fq_nmod_mat
* from FLINT, matrices over finite fields.
*
***********************************************************
*/

#ifndef __FQ_NMOD_MAT_H__
#define __FQ_NMOD_MAT_H__

#include "flint/fq_nmod.h"
#include "flint/fq_nmod_mat.h"
// Required packages dependencies

#include <flint/fq_nmod.h>
#include <flint/fq_nmod_mat.h>

// Self dependencies

#include "typedefs.h"

/*******************************************************************
*
* Function: fq_nmod_mat_is_zero_row
*
* Description: Check if a certain row is all zeros.
*
* Arguments:
* + mat (const fq_nmod_mat_t) - the matrix
* + row (slong) - the index of the row
* + F (const fq_nmod_ctx_t) - the finite field
*
* Returns:
* + (bool) - true if the row is a zero row
*
******************************************************************
*/

bool fq_nmod_mat_is_zero_row(const fq_nmod_mat_t mat, slong row, const fq_nmod_ctx_t F);

// These basic functions are no longer needed as they have analogues implemented in FLINT
// void fq_nmod_mat_swap_rows(fq_nmod_mat_t mat, slong row1, slong row2, const fq_nmod_ctx_t F);
// void fq_nmod_mat_swap_cols(fq_nmod_mat_t mat, slong col1, slong col2, const fq_nmod_ctx_t F);

/*******************************************************************
*
* Function: fq_nmod_mat_add_row
*
* Description: add a multiple of a row to another row,
* (R_i <- R_i + scalar * R_j).
*
* Arguments:
* + mat (fq_nmod_mat_t) - the matrix
* + dst_row (slong) - the index of the destination row (i)
* + src_row (slong) - the index of the source row (j)
* + scalar (const fq_nmod_t) - the scalar we multiply by
* + F (const fq_nmod_ctx_t) - the finite field
*
* Returns:
* + mat (fq_nmod_mat_t) - the matrix
*
******************************************************************
*/

void fq_nmod_mat_add_row(fq_nmod_mat_t mat, slong dst_row, slong src_row, const fq_nmod_t scalar, const fq_nmod_ctx_t F);

/*******************************************************************
*
* Function: fq_nmod_mat_add_col
*
* Description: add a multiple of a column to another column,
* (C_i <- C_i + scalar * C_j).
*
* Arguments:
* + mat (fq_nmod_mat_t) - the matrix
* + dst_col (slong) - the index of the destination column (i)
* + src_col (slong) - the index of the source column (j)
* + scalar (const fq_nmod_t) - the scalar we multiply by
* + F (const fq_nmod_ctx_t) - the finite field
*
* Returns:
* + mat (fq_nmod_mat_t) - the matrix
*
******************************************************************
*/

void fq_nmod_mat_add_col(fq_nmod_mat_t mat, slong dst_col, slong src_col, const fq_nmod_t scalar, const fq_nmod_ctx_t F);

/*******************************************************************
*
* Function: fq_nmod_mat_mul_row
*
* Description: multiply a row by a scalar,
* (R_i <- scalar * R_i).
*
* Arguments:
* + mat (fq_nmod_mat_t) - the matrix
* + row (slong) - the index of the row (i)
* + scalar (const fq_nmod_t) - the scalar we multiply by
* + F (const fq_nmod_ctx_t) - the finite field
*
* Returns:
* + mat (fq_nmod_mat_t) - the matrix
*
******************************************************************
*/

void fq_nmod_mat_mul_row(fq_nmod_mat_t mat, slong row, const fq_nmod_t scalar, const fq_nmod_ctx_t F);

/*******************************************************************
*
* Function: fq_nmod_mat_mul_col
*
* Description: multiply a column by a scalar,
* (C_i <- scalar * C_i).
*
* Arguments:
* + mat (fq_nmod_mat_t) - the matrix
* + col (slong) - the index of the column (i)
* + scalar (const fq_nmod_t) - the scalar we multiply by
* + F (const fq_nmod_ctx_t) - the finite field
*
* Returns:
* + mat (fq_nmod_mat_t) - the matrix
*
******************************************************************
*/

void fq_nmod_mat_mul_col(fq_nmod_mat_t mat, slong col, const fq_nmod_t scalar, const fq_nmod_ctx_t F);

/*******************************************************************
*
* Function: fq_nmod_mat_init_set_fmpz_mat
*
* Description: Reduce an integer matrix modulo a prime p.
* Assumes F = F_p is a prime field.
*
* Arguments:
* + mat (const fmpz_mat_t) - the integral matrix to be reduced
* + F (const fq_nmod_ctx_t) - the finite field
*
* Returns:
* + dest (fq_nmod_mat_t) - the reduced matrix
*
******************************************************************
*/

void fq_nmod_mat_init_set_fmpz_mat(fq_nmod_mat_t dest, const fmpz_mat_t mat, const fq_nmod_ctx_t F);

/*******************************************************************
*
* Function: fq_nmod_mat_transpose
*
* Description: Transpose a matrix.
*
* Arguments:
* + mat (const fq_nmod_mat_t) - the matrix to be transposed
* + F (const fq_nmod_ctx_t) - the finite field
*
* Returns:
* + mat_t (fq_nmod_mat_t) - the transposed matrix
*
******************************************************************
*/

void fq_nmod_mat_transpose(fq_nmod_mat_t mat_t, const fq_nmod_mat_t mat, const fq_nmod_ctx_t F);

/*******************************************************************
*
* Function: fq_nmod_mat_rref_trans
*
* Description: Bring to a row reduce echelon form, together with
* the transformation matrix.
*
* Arguments:
* + mat (fq_nmod_mat_t) - the matrix to be echelonized, M
* + F (const fq_nmod_ctx_t) - the finite field
*
* Returns:
* + mat (fq_nmod_mat_t) - the echelonized matrix, E
* + trans (fq_nmod_mat_t) - the transformation marix T, such
* that T*E = M
*
******************************************************************
*/

void fq_nmod_mat_rref_trans(fq_nmod_mat_t mat, fq_nmod_mat_t trans, const fq_nmod_ctx_t F);

/*******************************************************************
*
* Function: fq_nmod_mat_kernel
*
* Description: Find the kernel of a matrix.
*
* Arguments:
* + mat (fq_nmod_mat_t) - the matrix
* + F (const fq_nmod_ctx_t) - the finite field
*
* Returns:
* + ker (fq_nmod_mat_t) - a matrix whose rows form a basis for
* the null space of the matrix mat.
* its size is initialized inside the
* function.
*
******************************************************************
*/

void fq_nmod_mat_kernel(fq_nmod_mat_t ker, const fq_nmod_mat_t mat, const fq_nmod_ctx_t F);

#endif // __FQ_NMOD_MAT_H__
29 changes: 27 additions & 2 deletions src/fq_nmod_mat.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
/***********************************************************
*
* Package : omf5 - orthogonal modular forms of rank 5
* Filename : fq_nmod_mat.c
*
* Description: functions for handling the type fq_nmod_mat
* from FLINT, matrices over finite fields.
*
***********************************************************
*/

// System dependencies

#include <assert.h>

#include "flint/fq_nmod_mat.h"
// Required packages dependencies

#include <flint/fq_nmod_mat.h>

// Self dependencies

#include "fq_nmod_mat.h"
#include "typedefs.h"

// This file implements additional utilities for performing linear algebra with fq_nmod_mat

// check if a row is a zero row
bool fq_nmod_mat_is_zero_row(const fq_nmod_mat_t mat, slong row, const fq_nmod_ctx_t F)
{
slong col;
Expand Down Expand Up @@ -56,6 +74,7 @@ bool fq_nmod_mat_is_zero_row(const fq_nmod_mat_t mat, slong row, const fq_nmod_c
/* return; */
/* } */

// add a multiple of a row to another row
void fq_nmod_mat_add_row(fq_nmod_mat_t mat, slong dst_row, slong src_row, const fq_nmod_t scalar, const fq_nmod_ctx_t F)
{
slong col;
Expand All @@ -73,6 +92,7 @@ void fq_nmod_mat_add_row(fq_nmod_mat_t mat, slong dst_row, slong src_row, const
return;
}

// add a multiple of a column to another column
void fq_nmod_mat_add_col(fq_nmod_mat_t mat, slong dst_col, slong src_col, const fq_nmod_t scalar, const fq_nmod_ctx_t F)
{
slong row;
Expand All @@ -90,6 +110,7 @@ void fq_nmod_mat_add_col(fq_nmod_mat_t mat, slong dst_col, slong src_col, const
return;
}

// multiply a row by a scalar
void fq_nmod_mat_mul_row(fq_nmod_mat_t mat, slong row, const fq_nmod_t scalar, const fq_nmod_ctx_t F)
{
slong col;
Expand All @@ -101,6 +122,7 @@ void fq_nmod_mat_mul_row(fq_nmod_mat_t mat, slong row, const fq_nmod_t scalar, c
return;
}

// multiply a column by a scalar
void fq_nmod_mat_mul_col(fq_nmod_mat_t mat, slong col, const fq_nmod_t scalar, const fq_nmod_ctx_t F)
{
slong row;
Expand All @@ -112,6 +134,7 @@ void fq_nmod_mat_mul_col(fq_nmod_mat_t mat, slong col, const fq_nmod_t scalar, c
return;
}

// reduce amatrix mod p
void fq_nmod_mat_init_set_fmpz_mat(fq_nmod_mat_t dest, const fmpz_mat_t mat, const fq_nmod_ctx_t F)
{
slong row, col;
Expand All @@ -125,7 +148,7 @@ void fq_nmod_mat_init_set_fmpz_mat(fq_nmod_mat_t dest, const fmpz_mat_t mat, con
return;
}


// transpose a matrix
void fq_nmod_mat_transpose(fq_nmod_mat_t mat_t, const fq_nmod_mat_t mat, const fq_nmod_ctx_t F)
{
slong row,col;
Expand All @@ -141,6 +164,7 @@ void fq_nmod_mat_transpose(fq_nmod_mat_t mat_t, const fq_nmod_mat_t mat, const f
return;
}

// echelonize a matrix, keeping track of the transformation
void fq_nmod_mat_rref_trans(fq_nmod_mat_t mat, fq_nmod_mat_t trans, const fq_nmod_ctx_t F)
{
slong* P;
Expand Down Expand Up @@ -229,6 +253,7 @@ void fq_nmod_mat_rref_trans(fq_nmod_mat_t mat, fq_nmod_mat_t trans, const fq_nmo
return;
}

// computing the kernel of a matrix
// !! TODO - reuse the code from above
void fq_nmod_mat_kernel(fq_nmod_mat_t ker, const fq_nmod_mat_t mat, const fq_nmod_ctx_t F)
{
Expand Down

0 comments on commit 999353e

Please sign in to comment.