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"bravais.h"3#include"longtools.h"4/**************************************************************************\5@---------------------------------------------------------------------------6@---------------------------------------------------------------------------7@ FILE: invar_space.c8@---------------------------------------------------------------------------9@---------------------------------------------------------------------------10@11\**************************************************************************/1213/**************************************************************************\14@---------------------------------------------------------------------------15@ matrix_TYP **invar_space(B, Banz, fodim, symm_opt, epsilon, anz)16@ matrix_TYP **B;17@ int Banz, fodim, symm_opt, epsilon, *anz;18@19@ calculates a basis of the lattices of integral matrices X20@ with B[i]^{tr} * X * B[i] = X for 0<=i<Banz21@22@ the number of basis elements must be given to the function by the23@ integer 'fodim'24@ Then 'fodim'+1 random elements of the lattice are calculated with25@ the function 'rform' and26@ a basis of the integral matrices in the subspace generated by these27@ elements is constructed with 'long_rein_mat'.28@ This basis is the result and the number of elements is returned29@ via (int *anz)30@ The argument 'epsilon' is the only needed argument for 'rform', that31@ is called in the function.32@ the number of basis elements is returned via (int *anz).33@34@ 'symm_opt' must be 0, 1 or -1.35@ symm_opt = 0: the full lattice is calculated.36@ symm_opt = 1: a basis for the symmetric matrices is calculated37@ symm_opt =-1: a basis for the skewsymmetric matrices is calculated38@---------------------------------------------------------------------------39@40\**************************************************************************/414243matrix_TYP **invar_space(B, Banz, fodim, symm_opt, epsilon, anz)44matrix_TYP **B;45int Banz, fodim, symm_opt, epsilon, *anz;46{47int i,j,k,l, dim, ff, dd;48matrix_TYP *pm, *pm1, **erg, *startmat, *invar;49int r;5051dim = B[0]->cols;52if(B[0]->rows != dim)53{54printf("error in formspace: non-square matrix in group 'B'\n");55exit(3);56}57for(i=1;i<Banz;i++)58{59if(B[i]->rows != dim || B[i]->cols != dim)60{61printf("error in formspace: different dimesion of group elements\n");62exit(3);63}64}65if(symm_opt == 1)66dd = (dim *(dim+1))/2;67if(symm_opt == -1)68dd = (dim *(dim-1))/2;69if(symm_opt == 0)70dd = dim * dim;7172if(fodim <= 0)73{ *anz = 0; return(NULL);}7475if(fodim == 1)76{77if( (erg = (matrix_TYP **)malloc(1 *sizeof(matrix_TYP *))) == NULL)78{79printf("malloc of 'erg' in 'invar_space' failed\n");80exit(2);81}82erg[0] = init_mat(dim,dim,"");83startmat = init_mat(dim,dim,"");84if(symm_opt == -1 && dim > 1)85{ startmat->array.SZ[0][1] = -1;86startmat->array.SZ[1][0] = 1;87}88else89startmat->array.SZ[0][0] = 1;90erg[0] = rform(B, Banz, startmat, epsilon);91free_mat(startmat);92*anz = 1;93return(erg);94}9596pm = init_mat(fodim+1, dd, "");97startmat = init_mat(dim, dim, "");98for(i=0;i<fodim+1;i++)99{100if(symm_opt == 0)101{102for(j=0;j<dim;j++)103for(k=0;k<dim;k++)104{105r = rand();106r %= 2;107startmat->array.SZ[j][k] = r;108}109}110if(symm_opt == 1)111{112for(j=0;j<dim;j++)113/* tilman: changed 14/5/97 from114for(k=0;k<=i;k++) to: */115for(k=0;k<=j;k++)116{117r = rand();118r %= 2;119startmat->array.SZ[j][k] = r;120startmat->array.SZ[k][j] = r;121}122}123if(symm_opt == -1)124{125for(j=0;j<dim;j++)126for(k=0;k<i;k++)127{128r = rand();129r %= 2;130startmat->array.SZ[j][k] = r;131startmat->array.SZ[k][j] = -r;132}133for(j=0;j<dim;j++)134startmat->array.SZ[j][j] = 0;135}136invar = rform(B, Banz, startmat, epsilon);137if(symm_opt == 0)138{139l = 0;140for(j=0;j<dim;j++)141for(k=0;k<dim;k++)142{ pm->array.SZ[i][l] = invar->array.SZ[j][k]; l++;}143}144if(symm_opt == 1)145{146l = 0;147for(j=0;j<dim;j++)148for(k=0;k<=j;k++)149{ pm->array.SZ[i][l] = invar->array.SZ[j][k]; l++;}150}151152/* changed 18/12/96 tilman from:153if(symm_opt == 1)154to: */155if(symm_opt == (-1))156{157l = 0;158for(j=0;j<dim;j++)159for(k=0;k<j;k++)160{ pm->array.SZ[i][l] = invar->array.SZ[j][k]; l++;}161}162free_mat(invar);163}164free_mat(startmat);165166/* output for debugging purposes167put_mat(pm,NULL,"in invar_space, pm",2); */168169pm1 = long_rein_mat(pm);170171/* output for debugging purposes172put_mat(pm1,NULL,"in invar_space, pm1",2); */173174free_mat(pm);175176/* changed 18/12/96 tilman from177ff = pm->rows;178to */179ff = pm1->rows;180181*anz = ff;182if( (erg = (matrix_TYP **)malloc(ff *sizeof(matrix_TYP *))) == NULL)183{184printf("malloc of 'erg' in 'invar_space' failed\n");185exit(2);186}187for(i=0; i<ff;i++)188{189erg[i] = init_mat(dim,dim,"");190l=0;191if(symm_opt == 0)192{193for(j=0;j<dim;j++)194for(k=0;k<dim;k++)195{ erg[i]->array.SZ[j][k] = pm1->array.SZ[i][l]; l++;}196}197if(symm_opt == 1)198{199for(j=0;j<dim;j++)200for(k=0;k<=j;k++)201{202erg[i]->array.SZ[j][k] = pm1->array.SZ[i][l];203erg[i]->array.SZ[k][j] = pm1->array.SZ[i][l];204l++;205}206}207if(symm_opt == -1)208{209for(j=0;j<dim;j++)210for(k=0;k<j;k++)211{212erg[i]->array.SZ[j][k] = pm1->array.SZ[i][l];213erg[i]->array.SZ[k][j] = pm1->array.SZ[i][l];214l++;215}216for(j=0;j<dim;j++)217erg[i]->array.SZ[j][j] = 0;218}219Check_mat(erg[i]);220}221for(i=0;i<ff;i++)222{223for(j=0;j<dim && erg[i]->array.SZ[j][j] == 0; j++);224if(j<dim && erg[i]->array.SZ[j][j] < 0)225{226for(k=0;k<dim;k++)227for(l=0;l<dim;l++)228erg[i]->array.SZ[k][l] = -erg[i]->array.SZ[k][l];229}230}231free_mat(pm1);232return(erg);233}234235236