GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include"typedef.h"1/**************************************************************************\2@---------------------------------------------------------------------------3@---------------------------------------------------------------------------4@ FILE: hyp_isom.c5@---------------------------------------------------------------------------6@---------------------------------------------------------------------------7@8\**************************************************************************/9101112/**************************************************************************\13@---------------------------------------------------------------------------14@ matrix_TYP *hyperbolic_isometry(x1, x2, S)15@ matrix_TYP *x1, *x2, *S;16@17@ The first row in the matrix x1 (resp. x2) is interpreted as a vector18@ v1 (resp. v2) in Z^n.19@ The function calculates a matrix A in GL_n(Q) (if exists) with20@ v1A = v2 and ASA^{tr} = S21@ Any integral matrix with this property must be of the form BA where22@ B is a matrix of the group that can be caluclated with23@ B = hyperbolic_stabilizer(x1, S)24@---------------------------------------------------------------------------25@26\**************************************************************************/27matrix_TYP *hyperbolic_isometry(x1, x2, S)28matrix_TYP *x1, *x2, *S;29{30matrix_TYP *x1S, *x2S, *x1SO, *x2SO, **S1red, **S2red, *T1,*T1i, *T2;31matrix_TYP *Y1, *Y1i, *Y2, *Y;32int i,j,k, n;3334extern matrix_TYP *solve_mat();35extern matrix_TYP *mat_mul();36extern matrix_TYP *mat_inv();37extern matrix_TYP *scal_pr();38extern matrix_TYP *pr_isom();39extern matrix_TYP *init_mat();4041n = x1->cols;42if((S1red = (matrix_TYP **)malloc(1 *sizeof(matrix_TYP *))) == NULL)43{44printf("malloc of 'S1red' in 'hyperbolic_isometry' failed\n");45exit(2);46}47if((S2red = (matrix_TYP **)malloc(1 *sizeof(matrix_TYP *))) == NULL)48{49printf("malloc of 'S2red' in 'hyperbolic_isometry' failed\n");50exit(2);51}52x1S = mat_mul(x1, S);53x1SO = solve_mat(x1S);54S1red[0] = scal_pr(x1SO, S, 1);55x2S = mat_mul(x2, S);56x2SO = solve_mat(x2S);57S2red[0] = scal_pr(x2SO, S, 1);58Y1 = pr_isom(S1red, S2red, 1, NULL, 0, NULL);59free_mat(S1red[0]); free(S1red);60free_mat(S2red[0]); free(S2red);61free_mat(x1S); free_mat(x2S);62if(Y1 == NULL)63{64free_mat(x1SO); free_mat(x2SO);65return(NULL);66}67T1 = init_mat(n,n,"");68for(i=0;i<n-1;i++)69for(j=0;j<n;j++)70T1->array.SZ[i][j] = x1SO->array.SZ[i][j];71for(i=0;i<n;i++)72T1->array.SZ[n-1][i] = x1->array.SZ[0][i];73T1i = mat_inv(T1);74free_mat(T1);75free_mat(x1SO);7677T2 = init_mat(n,n,"");78Y1i = mat_inv(Y1);79Y2 = mat_mul(Y1i, x2SO);80for(i=0;i<n-1;i++)81for(j=0;j<n;j++)82T2->array.SZ[i][j] = Y2->array.SZ[i][j];83for(i=0;i<n;i++)84T2->array.SZ[n-1][i] = x2->array.SZ[0][i];85free_mat(x2SO);86free_mat(Y2);87free_mat(Y1);88free_mat(Y1i);8990Y = mat_mul(T1i, T2);91free_mat(T1i); free_mat(T2);92return(Y);93}949596