GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include "typedef.h"1#include "gmp.h"2/* #include "gmp-impl.h" */3#include "longtools.h"4#include "matrix.h"5/**************************************************************************\6@---------------------------------------------------------------------------7@---------------------------------------------------------------------------8@ FILE: long_hnf.c9@---------------------------------------------------------------------------10@---------------------------------------------------------------------------11@ The function to the same as the functions in long_gauss.c,12@ they additionaly clear the columns upwards and transform 'Mat'13@ to a matrix in Hermite-normal-form14\**************************************************************************/151617/**************************************************************************\18@---------------------------------------------------------------------------19@ int long_row_hnf(Mat)20@ matrix_TYP *Mat;21@22@---------------------------------------------------------------------------23\**************************************************************************/24int long_row_hnf(Mat)25matrix_TYP *Mat;26{27int rang;28MP_INT **M;2930M = matrix_to_MP_mat(Mat);31rang = MP_hnf(M, Mat->rows, Mat->cols);32write_MP_mat_to_matrix(Mat, M);33free_MP_mat(M, Mat->rows, Mat->cols);34free(M);35return(rang);36}3738int long_col_hnf(Mat)39matrix_TYP *Mat;40{41int i,42j,43rang;4445matrix_TYP *Mattr;4647Mattr = tr_pose(Mat);4849rang = long_row_hnf(Mattr);5051/* transpose the array */52for (i=0;i<Mat->cols;i++)53for (j=0;j<Mat->rows;j++)54Mat->array.SZ[j][i] = Mattr->array.SZ[i][j];5556Check_mat(Mat);57free_mat(Mattr);5859return rang;60}6162/**************************************************************************\63@---------------------------------------------------------------------------64@ int long_row_trf_hnf(Mat, T)65@ matrix_TYP *Mat, *T;66@67@---------------------------------------------------------------------------68\**************************************************************************/69int long_row_trf_hnf(M, T)70matrix_TYP *M, *T;71{72int rang;73MP_INT **N, **S;7475N = matrix_to_MP_mat(M);76S = init_MP_mat(M->rows, M->rows);77rang = MP_trf_hnf(N, S, M->rows, M->cols);78write_MP_mat_to_matrix(M, N);79write_MP_mat_to_matrix(T, S);80free_MP_mat(N, M->rows, M->cols); free_MP_mat(S, M->rows, M->rows);81free(N); free(S);82return(rang);83}8485868788/**************************************************************************\89@---------------------------------------------------------------------------90@ int long_row_hnf_simultaneous(A, B)91@ matrix_TYP *A, *B;92@93@---------------------------------------------------------------------------94\**************************************************************************/95int long_row_hnf_simultaneous(A, B)96matrix_TYP *A, *B;97{98int rang;99MP_INT **MA, **MB;100101MA = matrix_to_MP_mat(A);102MB = matrix_to_MP_mat(B);103rang = MP_hnf_simultaneous(MA, A->rows, A->cols, MB, B->cols);104write_MP_mat_to_matrix(A, MA);105write_MP_mat_to_matrix(B, MB);106free_MP_mat(MA, A->rows, A->cols); free_MP_mat(MB, B->rows, B->cols);107free(MA); free(MB);108return(rang);109}110111112