GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include"typedef.h"1/**************************************************************************\2@---------------------------------------------------------------------------3@---------------------------------------------------------------------------4@ FILE: pair_red.c5@---------------------------------------------------------------------------6@---------------------------------------------------------------------------7@8\**************************************************************************/91011static void two_reduce(G, T, i, j, n)12int **G, **T, i, j, n;13{14int k, f;1516if(G[i][j] > 0)17f = (G[i][j] + G[i][i]/2)/G[i][i];18else19f = (G[i][j] - G[i][i]/2)/G[i][i];2021for(k=0;k<n;k++)22G[j][k] -= f * G[i][k];23G[j][j] -= f * G[j][i];24for(k=0;k<n;k++)25{26if(k != j)27{28G[k][j] = G[j][k];29}30}31for(k=0;k<n && T != NULL;k++)32T[j][k] -= f * T[i][k];33}343536/**************************************************************************\37@---------------------------------------------------------------------------38@ void pr_red(G, T, n)39@ int **G, **T, n;40@41@ applies a pair_reduction to the 2-dimensional array G of size n x n42@ and makes the simutaneous row operations on the array T of the same size43@ The function can be called with T = NULL44@---------------------------------------------------------------------------45@46\**************************************************************************/47void pr_red(G, T, n)48int **G, **T, n;49{50int i,j,k, a;51int reduced, red2;52int merk, s, p1, p2;5354reduced = FALSE;55reduction_sort(G,T,n);56while(reduced == FALSE)57{58reduced = TRUE;59for(i=0;i<n;i++)60for(j=0;j<i;j++)61{62red2 = FALSE;63while(red2 == FALSE && (G[i][i] != 0 || G[j][j] != 0))64{65if(G[i][i] > 0 && G[i][i] <= G[j][j])66{67a = 2*G[i][j];68if(abs(a) > G[i][i])69{70two_reduce(G, T, i, j, n);71reduced = FALSE;72}73else74red2 = TRUE;75}76if(G[j][j] > 0 && G[j][j] <= G[i][i])77{78a = 2*G[i][j];79if(a > G[j][j] || -a > G[j][j])80{81two_reduce(G, T, j, i, n);82reduced = FALSE;83}84else85red2 = TRUE;86}87if(G[i][i] < 0 || G[j][j] < 0)88return;89}90}91reduction_sort(G, T, n);92for(i=0;i<n;i++)93for(j=i+1;j<n;j++)94{95if(G[i][i] <= G[j][j])96{ p1 = i; p2 = j;}97else98{ p1 = j; p2 = i;}99if(2*abs(G[p1][p2]) == G[p1][p1])100{101s = signum(G[p1][p2]);102for(k=0; k<n;k++)103{104if(k != p2)105G[p2][k] -= s * G[p1][k];106if(T != NULL)107T[p2][k] -= s * T[p1][k];108}109for(k=0;k<n;k++)110{111G[k][p2] = G[p2][k];112}113for(k=0;k<n;k++)114{115if(k != p1 && k != p2)116{117red2 = FALSE;118while(red2 == FALSE && G[k][k] > 0 && G[p2][p2] > 0)119{120a = 2*abs(G[k][p2]);121if(a > G[k][k] || a > G[p2][p2])122{123if(a > G[k][k] && G[k][k] < G[p2][p2])124two_reduce(G, T, k, p2, n);125else126two_reduce(G, T, p2, k, n);127reduced = FALSE;128}129else130red2 = TRUE;131}132if(G[k][k] < 0 || G[p2][p2] < 0)133return;134}135}136}137if(G[i][i] < 0 || G[j][j] < 0)138return;139}140}141}142143144145/**************************************************************************\146@---------------------------------------------------------------------------147@ matrix_TYP *pair_red(Gram, Tr)148@ matrix_TYP *Gram, *Tr;149@150@ calculates matrices A and Tr such that A = Tr * Gram * Tr^{tr}151@ is pair_reduced.152@ The function can be called with Tr = NULL153@---------------------------------------------------------------------------154@155\**************************************************************************/156matrix_TYP *pair_red(Gram, Tr)157matrix_TYP *Gram, *Tr;158{159int i,j;160int **G, **T;161matrix_TYP *Gerg;162163extern matrix_TYP *copy_mat();164165Gerg = copy_mat(Gram);166G = Gerg->array.SZ;167if(Tr != NULL)168{169T = Tr->array.SZ;170for(i=0;i<Gram->cols;i++)171{172for(j=0;j<Gram->cols;j++)173T[i][j] = 0;174T[i][i] = 1;175}176}177else178T = NULL;179pr_red(G, T, Gram->cols);180return(Gerg);181}182183184