GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include"typedef.h"1#include"matrix.h"2#include"symm.h"3/**************************************************************************\4@---------------------------------------------------------------------------5@---------------------------------------------------------------------------6@ FILE: short_reduce.c7@---------------------------------------------------------------------------8@---------------------------------------------------------------------------9@10\**************************************************************************/11121314/**************************************************************************\15@---------------------------------------------------------------------------16@ matrix_TYP *short_reduce(A, SV, Trf)17@ matrix_TYP *A, *SV, *Trf;18@19@ short_reduce make a reduction of the matrix A using the shortvectors20@ given in SV.21@ If an entry in SV is 1 or -1 the vector is used to make A better22@ afterwards the vectors in SV are transformed and the same is tried23@ again.24@ A and SV are not changed in this function.25@ the result is the reduced matrix and the transformation is26@ applied to the matrix Trf.27@---------------------------------------------------------------------------28@29\**************************************************************************/30matrix_TYP *short_reduce(A, SV, Trf)31matrix_TYP *A, *SV, *Trf;32{3334int step, i,j,k,l, dim;35int min, min1, max, anz;36int **B, **Titr ,**T, **S ;37matrix_TYP *Aneu;38int abbruch, lastchange, merk, *mp;39int *v;4041dim = A->cols;42min = SV->array.SZ[0][dim];43anz = SV->rows;44if( (v = (int *)malloc(dim *sizeof(int ))) == NULL){45printf("malloc of 'v' in short_reduce failed\n");46exit(2);47}48Aneu = copy_mat(A);49B = Aneu->array.SZ;50if(Trf != NULL)51T = Trf->array.SZ;52else53T = NULL;54S = SV->array.SZ;55if( (Titr = (int **)malloc(dim *sizeof(int *))) == NULL){56printf("malloc of 'Titr' in short_reduce failed\n");57exit(2);58}59for(i=0;i<dim;i++)60{61if( (Titr[i] = (int *)malloc(dim *sizeof(int))) == NULL)62{63printf("malloc of 'Titr[%d]' in short_reduce failed\n", i);64exit(2);65}66for(j=0;j<dim;j++)67Titr[i][j] = 0;68Titr[i][i] = 1;69}70min1 = B[0][0];71max = B[0][0];72for(i=1; i<dim;i++)73{74if(B[i][i] < min1)75min1 = B[i][i];76if(B[i][i] > max)77max = B[i][i];78}79if(max == min)80{ for(i=0;i<dim;i++)81free(Titr[i]);82free(Titr);83return(Aneu);84}85if(min1 == min)86{87abbruch = FALSE;88for(step=0;step<dim && abbruch == FALSE;step++)89{90if(B[step][step] != min)91{92for(i=step+1;i<dim && B[i][i] != min ;i++);93if(i == dim)94abbruch = TRUE;95else96{97if(T != NULL)98{99mp = T[step];100T[step] = T[i];101T[i] = mp;102}103mp = Titr[step];104Titr[step] = Titr[i];105Titr[i] = mp;106mp = B[step];107B[step] = B[i];108B[i] = mp;109for(j=0;j<dim;j++)110{111merk = B[j][step];112B[j][step] = B[j][i];113B[j][i] = merk;114}115}116}117}118}119for(step = 0;step<dim && B[step][step] == min; step++);120lastchange = anz;121abbruch = FALSE;122while(step < dim && abbruch == FALSE)123{124for(i=0;i<anz && step < dim && i != lastchange ;i++)125{126/*----------------------------------------------------*\127| Calculate S[i] * Titr^{tr}128\*----------------------------------------------------*/129for(k=step;k<dim;k++)130{131v[k] = 0;132for(l=0;l<dim;l++)133v[k] += S[i][l] * Titr[k][l];134}135for(k=step;k<dim && v[k] != 1 && v[k] != -1; k++);136if(k<dim)137{138lastchange = i;139for(j = 0;j<step;j++)140{141v[j] = 0;142for(l=0;l<dim;l++)143v[j] += S[i][l] * Titr[j][l];144}145if(v[k] == -1)146{147for(j=0;j<dim;j++)148v[j] = -v[j];149}150if(k != step)151{152if(T != NULL)153{154mp = T[step];155T[step] = T[k];156T[k] = mp;157}158mp = Titr[step];159Titr[step] = Titr[k];160Titr[k] = mp;161mp = B[step];162B[step] = B[k];163B[k] = mp;164for(l=0;l<dim;l++)165{ merk = B[l][step]; B[l][step] = B[l][k]; B[l][k] = merk;}166merk = v[step]; v[step] = v[k]; v[k] = merk;167}168for(j=0;j<step;j++)169{170if(v[j] != 0)171{172for(l=0;l<dim;l++)173{174if(T != NULL)175T[step][l] += T[j][l] * v[j];176Titr[j][l] -= Titr[step][l] * v[j];177B[step][l] += B[j][l] * v[j];178}179}180}181for(j=step+1;j<dim;j++)182{183if(v[j] != 0)184{185for(l=0;l<dim;l++)186{187if(T != NULL)188T[step][l] += T[j][l] * v[j];189Titr[j][l] -= Titr[step][l] * v[j];190/*191Titr[l][step] -= Titr[l][j] * v[j];192*/193B[step][l] += B[j][l] * v[j];194}195}196}197for(j=0;j<step;j++)198{199if(v[j] != 0)200{201for(l=0;l<dim;l++)202B[l][step] += B[l][j] * v[j];203}204}205for(j=step+1;j<dim;j++)206{207if(v[j] != 0)208{209for(l=0;l<dim;l++)210B[l][step] += B[l][j] * v[j];211}212}213step++;214}215}216if(i == lastchange)217abbruch = TRUE;218}219for(i=0;i<dim;i++)220free(Titr[i]);221free(Titr);222free(v);223return(Aneu);224}225226227228/**************************************************************************\229@---------------------------------------------------------------------------230@ matrix_TYP *pr_short_red(A, Trf)231@ matrix_TYP *A, *Trf;232@233@ The same as short_reduce but before and after using this function234@ a pair_redduction is used.235@ The shortest vectors are calculated by the function itsself.236@---------------------------------------------------------------------------237@238\**************************************************************************/239matrix_TYP *pr_short_red(A, Trf)240matrix_TYP *A, *Trf;241{242matrix_TYP *Aneu, *Aneu1, *Aneu2, *SV;243int i,j,k, min, max, min1, dim;244int anz, len;245int is_even;246247dim = A->cols;248Aneu = copy_mat(A);249is_even = TRUE;250for(i=0;i<dim && is_even == TRUE; i++)251{252if( (A->array.SZ[i][i]%2) != 0)253is_even = FALSE;254}255pr_red(Aneu->array.SZ, Trf->array.SZ, dim);256min1 = Aneu->array.SZ[0][0];257max = Aneu->array.SZ[0][0];258for(i=1;i<dim;i++)259{260if(Aneu->array.SZ[i][i] < min1)261min1 = A->array.SZ[i][i];262if(Aneu->array.SZ[i][i] > max)263max = A->array.SZ[i][i];264}265if(is_even == TRUE)266len = min1 - 2;267else268len = min1 -1;269270/* changed 17/1/97 from:271short_vectors(Aneu, len, 0, 1, 1, &anz);272to: */273SV = short_vectors(Aneu, len, 0, 1, 1, &anz);274free_mat(SV);275276if(anz == 0 && max == min1)277return(Aneu);278SV = shortest(Aneu, &min);279Aneu1 = short_reduce(Aneu, SV, Trf);280free_mat(SV);281free_mat(Aneu);282if(Aneu1->array.SZ[dim-1][dim-1] == min)283return(Aneu1);284pr_red(Aneu1->array.SZ, Trf->array.SZ, dim);285return(Aneu1);286}287288289