GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/* last change: 14.09.2000 by Oliver Heidbuechel */123#include <typedef.h>4#include <getput.h>5#include <matrix.h>6#include <base.h>7#include <gmp.h>8#include <zass.h>9#include <longtools.h>10#include <orbit.h>11#include <bravais.h>12#include <graph.h>13141516matrix_TYP **extensions_o(matrix_TYP *cozycle,17matrix_TYP *D,18matrix_TYP *R,19bravais_TYP *G,20int **lengths,21MP_INT **names,22int *number_of_orbits,23int ****WORDS,24int **NUMBER_OF_WORDS,25matrix_TYP ***N,26MP_INT coho_size,27int option,28int *list_of_names);293031/* -------------------------------------------------------------------- */32/* matrix_on_diagonal: */33/* Creates the matrix M = diag(mat, ... , mat) */34/* -------------------------------------------------------------------- */35matrix_TYP *matrix_on_diagonal(matrix_TYP *mat,36int anz)37{38int i, j, k;3940matrix_TYP *M;414243M = init_mat(mat->rows * anz, mat->cols * anz, "");44for (i = 0; i < anz; i++){45for (j = 0; j < mat->rows; j++){46for (k = 0; k < mat->cols; k++){47M->array.SZ[i*mat->rows + j][i*mat->cols + k] = mat->array.SZ[j][k];48}49}50}51M->kgv = mat->kgv;52M->flags.Integral = mat->flags.Integral;53Check_mat(M);5455return(M);56}57585960/* -------------------------------------------------------------------- */61/* extract_r */62/* returns the spacegroup to the pointgroup G and the cozykel X */63/* code is taken out of extract.c */64/* -------------------------------------------------------------------- */65bravais_TYP *extract_r(bravais_TYP *G,66matrix_TYP *X)67{68bravais_TYP *H;6970int i, j;7172char comment[1000];737475rat2kgv(X);76Check_mat(X);7778/* is it a valid cozycle? */79if ((G->dim * G->gen_no != X->rows) || (X->cols != 1)){80fprintf(stderr,"The cozycle is not compatible to this point group\n");81fprintf(stderr,"It should have %d * %d = %d rows\n",G->dim,G->gen_no,82G->dim*G->gen_no);83exit(3);84}8586H = init_bravais(G->dim+1);87H->gen_no = G->gen_no;88H->gen = (matrix_TYP **) malloc(G->gen_no * sizeof(matrix_TYP *));8990for (i=0;i<H->gen_no;i++){91H->gen[i] = copy_mat(G->gen[i]);92rat2kgv(H->gen[i]);93Check_mat(H->gen[i]);94real_mat(H->gen[i],H->dim,H->dim);95iscal_mul(H->gen[i],X->kgv);96H->gen[i]->kgv = H->gen[i]->kgv * X->kgv;97for (j=0;j<H->dim-1;j++)98H->gen[i]->array.SZ[j][H->dim-1] = X->array.SZ[i*(H->dim-1)+j][0];99H->gen[i]->array.SZ[H->dim-1][H->dim-1] = X->kgv;100Check_mat(H->gen[i]);101}102sprintf(comment,"space group to the point group of %s and cozycle %s",103FILENAMES[0],FILENAMES[1]);104105return(H);106}107108109110/* -------------------------------------------------------------------- */111/* all_cocycles: */112/* Calculates the coycles for the spacegroup in the Z-class given by */113/* the pointgroup G. */114/* -------------------------------------------------------------------- */115/* relator_input: presentation of G */116/* G : pointgroup representing the Z-class */117/* CAUTION: the programm will only work correctly, if */118/* the correct normalizer of the pointgroup is given. */119/* anzahl : the function will set anzahl = number of affine */120/* classes */121/* The following code is a part of the mainfunction of the programm */122/* Extensions! */123/* -------------------------------------------------------------------- */124125matrix_TYP **all_cocycles(matrix_TYP *relator_input,126bravais_TYP *G,127int *anzahl,128matrix_TYP **matinv,129matrix_TYP ***X,130MP_INT **names,131int ****WORDS,132int **NUMBER_OF_WORDS,133matrix_TYP ***N,134int *coho_size,135int **list_of_names,136boolean l_option)137{138matrix_TYP **Y;139140word *relator;141142int *len, i;143144long dim;145146char comment[1000];147148MP_INT cohom_size;149150151/* we have to have at least the identity to generate the normalizer */152if (G->normal_no == 0){153G->normal_no = 1;154G->normal = (matrix_TYP **) malloc(1 * sizeof(matrix_TYP *));155G->normal[0] = init_mat(G->dim,G->dim,"1");156}157158/* speicher fuer die worte */159relator = (word *) calloc(relator_input->rows,sizeof(word));160161/* konvertieren der inputmatrix in relator-format */162for (i=0;i<relator_input->rows;i++){163matrix_2_word(relator_input,relator+i,i);164}165166X[0] = cohomology(&dim,G->gen,matinv,relator,G->gen_no,relator_input->rows);167168/* there is a special case to handle, which is the case that there169isn't a cohomology group at all */170if (X[0][0]->cols <1){171Y = (matrix_TYP **)malloc(sizeof(matrix_TYP));172Y[0] = init_mat(G->gen_no * G->dim,1,"");173anzahl[0] = 1;174N[0] = NULL;175coho_size[0] = 1;176names[0] = (MP_INT *) malloc(sizeof(MP_INT));177mpz_init_set_si(names[0], 0);178}179else {180cohom_size = cohomology_size(X[0][1]);181coho_size[0] = mpz_get_ui(&cohom_size);182183if (l_option){184list_of_names[0] = NULL;185}186else{187if (coho_size[0] < TWOTO21){188list_of_names[0] = (int *)calloc(coho_size[0], sizeof(int));189}190else{191fprintf(stderr, "The cohomology group is too big!\n");192fprintf(stderr, "If you are really interested in the graph of group - subgroup relations\n");193fprintf(stderr, "please start the program again with the option -l!\n");194exit(9);195}196}197198Y = extensions_o(X[0][0],X[0][1],X[0][2],G,&len,names,anzahl,199WORDS, NUMBER_OF_WORDS, N, cohom_size, 0, list_of_names[0]);200free(len);201mpz_clear(&cohom_size);202}203204for (i=0;i<relator_input->rows;i++) wordfree(relator+i);205free(relator);206207if (INFO_LEVEL & 12){208pointer_statistics(0,0);209}210211return(Y);212}213214215216/* -------------------------------------------------------------------- */217/* transform a representative into the representation of */218/* C_d1 x ... x C_dn */219/* -------------------------------------------------------------------- */220/* coz: cocycle in question */221/* GLS: inverse of the third matrix returned by cohomology */222/* D: second matrix returned by cohomology */223/* -------------------------------------------------------------------- */224matrix_TYP *standard_rep(matrix_TYP *coz,225matrix_TYP *GLS,226matrix_TYP *D)227{228int i, j,229denominator,230first, last, diff;231232matrix_TYP *tmp,233*rep;234235236for (first = 0; first < D->cols && D->array.SZ[first][first] == 1; first++);237for (last = first; last < D->cols && D->array.SZ[last][last] != 0; last++);238diff = last - first;239tmp = mat_mul(GLS, coz);240if (diff == 0)241rep = init_mat(0, 0, "");242else243rep = init_mat(diff, 1, "");244denominator = tmp->kgv;245246for (i = 0; i < diff; i++){247j = tmp->array.SZ[i + first][0] * D->array.SZ[i + first][i + first];248if ((j % denominator) != 0){249fprintf(stderr,"ERROR in standard_rep: are you sure this is a cozycle?\n");250fprintf(stderr,"If so, please report to the authors: [email protected]\n");251exit(3);252}253else{254rep->array.SZ[i][0] = (j / denominator) % D->array.SZ[i + first][i + first];255while (rep->array.SZ[i][0] < 0)256rep->array.SZ[i][0] += D->array.SZ[i + first][i + first];257}258}259260free_mat(tmp);261262return(rep);263}264265266267/* -------------------------------------------------------------------- */268/* returns 1, if m in list; returns 0 otherwise */269/* -------------------------------------------------------------------- */270int yet_there(matrix_TYP *m,271matrix_TYP **list,272int no)273{274int i;275276for (i = 0; i < no; i++)277if (cmp_mat(m, list[i]) == 0)278return(1);279return(0);280}281282283284/* -------------------------------------------------------------------- */285/* returns 1, if m = (0)_i,j, returns 0 otherwise */286/* -------------------------------------------------------------------- */287int equal_zero(matrix_TYP *m)288{289int i, j;290291for (i = 0; i < m->rows; i++)292for (j = 0; j < m->cols; j++)293if (m->array.SZ[i][j] != 0)294return(0);295return(1);296}297298299/* -------------------------------------------------------------------- */300/* Generate list of matrices with the columns of M */301/* only the entries in M->array.SZ are copied */302/* -------------------------------------------------------------------- */303matrix_TYP **col_to_list(matrix_TYP *M)304{305matrix_TYP **list;306307int i, j, rows, cols;308309310cols = M->cols;311rows = M->rows;312list = (matrix_TYP **)calloc(cols, sizeof(matrix_TYP *));313314for (i = 0; i < cols; i++){315list[i] = init_mat(rows, 1, "");316for (j = 0; j < rows; j++){317list[i]->array.SZ[j][0] = M->array.SZ[j][i];318}319}320321return(list);322}323324325326/* -------------------------------------------------------------------- */327void free_H1_mod_ker_TYP(H1_mod_ker_TYP H1_mod_ker)328{329int i, j;330331if (H1_mod_ker.flag == 0){332for (i = 0; i < H1_mod_ker.erz_no; i++){333free_mat(H1_mod_ker.M[i]);334}335free(H1_mod_ker.M);336free_mat(H1_mod_ker.D);337free_mat(H1_mod_ker.i);338}339}340341342343/* -------------------------------------------------------------------- */344static void mod(int *a, int b)345{346a[0] = a[0] % b;347if (a[0]<0) a[0] += b;348}349350351352/* -------------------------------------------------------------------- */353/* return the number of the affine class for the cocylce coz */354/* -------------------------------------------------------------------- */355/* data: Informationen ueber die Q-Klasse */356/* coz: Cozykel als Element von H^1 */357/* i: Nummer der Z-Klasse */358/* flag: true => gebe -(Nummer der aff. Klasse) zurueck, falls nicht */359/* Standardvertreter der affinen Klasse */360/* wortflag: speichere ein Wort fuer Normalisatorelement, welches */361/* coz zu Standardverterter konjugiert */362/* wort: speicher Wort hier */363/* -------------------------------------------------------------------- */364int number_of_affine_class(Q_data_TYP *data,365matrix_TYP *coz,366int i,367int flag,368boolean wortflag,369int **wort)370{371matrix_TYP *rep;372373MP_INT nummer;374375int anz, n, first, last, zahl, pos;376377char *B;378379380381mpz_init(&nummer);382for (first = 0; first < data->X[i][1]->cols && data->X[i][1]->array.SZ[first][first] == 1; first++);383for (last = first; last < data->X[i][1]->cols && data->X[i][1]->array.SZ[last][last] != 0; last++);384for (n = first; n < last; n++){385mod(coz->array.SZ[n - first], data->X[i][1]->array.SZ[n][n]);386}387388389if (data->l_option == TRUE || wortflag){390B = (char *)calloc(data->coho_size[i], sizeof(char));391rep = orbit_rep(coz, data->N[i], data->Z[i]->normal_no, data->X[i][1], 0,392B, &nummer, &anz, wort, wortflag, NULL, NULL);393394pos = mpz_get_ui(&nummer);395for (n = 0; n < data->aff_no[i]; n++){396if (mpz_cmp(&nummer, &data->names[i][n]) == 0){397break;398}399}400if (n == data->aff_no[i]){401fprintf(stderr, "ERROR in number_of_affine_class!\n");402exit(6);403}404405free_mat(rep);406free(B);407408if (flag == 1){409valuation(coz, data->X[i][1], &nummer);410if (pos != mpz_get_ui(&nummer)){411mpz_clear(&nummer);412return(-n);413}414}415mpz_clear(&nummer);416}417else{418valuation(coz, data->X[i][1], &nummer);419pos = mpz_get_ui(&nummer);420zahl = data->list_of_names[i][pos];421mpz_clear(&nummer);422423for (n = 0; n < data->aff_no[i]; n++){424if (zahl == data->names_int[i][n]){425break;426}427}428if (n == data->aff_no[i]){429fprintf(stderr, "ERROR in number_of_affine_class!\n");430exit(6);431}432if (flag == 1 && pos != zahl)433return(-n);434}435436return(n);437}438439440441/* -------------------------------------------------------------------- */442/* adds to all elements a row with "1" */443/* -------------------------------------------------------------------- */444void kernel_elements_2_affine(matrix_TYP **elem,445int coho_size)446{447int i, rows;448449450rows = elem[0]->rows;451452for (i = 0; i < coho_size; i++){453if (elem[i] != NULL){454real_mat(elem[i], rows + 1, 1);455elem[i]->array.SZ[rows][0] = 1;456}457}458}459460461462/* -------------------------------------------------------------------- */463/* append G->cen to G->normal and set G->cen = NULL */464/* -------------------------------------------------------------------- */465void cen_to_norm(bravais_TYP *G)466{467int i;468469if (G->cen_no > 0){470G->normal = (matrix_TYP **)realloc(G->normal,471(G->cen_no + G->normal_no) * sizeof(matrix_TYP));472for (i = 0; i < G->cen_no; i++){473G->normal[G->normal_no + i] = G->cen[i];474}475free(G->cen);476G->cen = NULL;477G->normal_no += G->cen_no;478G->cen_no = 0;479}480}481482483484485486487488489490491492493494495