GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/* last change: 02.11.00 by Oliver Heidbuechel */1234#include <typedef.h>5#include <matrix.h>6#include <bravais.h>7#include <base.h>8#include <graph.h>9#include <zass.h>10#include <datei.h>11#include <longtools.h>12131415/* ----------------------------------------------------------------------------- */16/* this is a function which make the same as the program same_generators */17/* the code is taken out of the main-function of same_generators */18/* ----------------------------------------------------------------------------- */19matrix_TYP *sg(bravais_TYP *R,20bravais_TYP *P)21{22matrix_TYP **RG, *coz;2324int **words, denominator,25j, k;26272829RG = (matrix_TYP **)calloc(R->gen_no, sizeof(matrix_TYP *));30words = (int **)calloc(P->gen_no, sizeof(int *));31denominator = 1;32for (j = 0; j < R->gen_no; j++){33RG[j] = copy_mat(R->gen[j]);34RG[j]->cols--;35RG[j]->rows--;36Check_mat(RG[j]);37if (!RG[j]->flags.Integral){38fprintf(stderr,"The point group has to be integral\n");39exit(3);40}41rat2kgv(R->gen[j]);42denominator *= (R->gen[j]->kgv / GGT(R->gen[j]->kgv, denominator));43}4445/* stick the rigth INTEGRAL cozycle at the end of the RG[j] */46for (j = 0; j < R->gen_no; j++){47RG[j]->cols++;48RG[j]->rows++;49for (k = 0; k < RG[j]->rows-1; k++){50RG[j]->array.SZ[k][R->dim-1] = (denominator / R->gen[j]->kgv) *51R->gen[j]->array.SZ[k][R->dim-1];52RG[j]->array.SZ[R->dim-1][R->dim-1] = 1;53Check_mat(RG[j]);54}55}5657/* get the cozycle on the right generators */58coz = reget_gen(RG, R->gen_no, P, words, TRUE);5960/* the cozykle has to become the right denominator */61coz->kgv = denominator;62Check_mat(coz);6364for (j = 0; j < R->gen_no; j++){65free_mat(RG[j]);66}67for (j = 0; j < P->gen_no; j++){68free(words[j]);69}70free(words);71free(RG);7273return(coz);74}75767778/* ----------------------------------------------------------------------------- */79/* GL = <gl_1, ..., gl_m> = <s1, ..., s_m> = standard */80/* X: informations about the cohomology group of standard */81/* calculate the cocycles for g1_1, ..., gl_m */82/* ----------------------------------------------------------------------------- */83matrix_TYP *H1_of_standard_to_GL(bravais_TYP *GL,84bravais_TYP *standard,85matrix_TYP **X)86{87int i, j, X_first;8889matrix_TYP *coz, *help;9091bravais_TYP *RG;92939495for (X_first = 0; X_first < X[1]->cols && X[1]->array.SZ[X_first][X_first] == 1; X_first++);96coz = init_mat(X[0]->rows, X[0]->cols, "");9798for (i = 0; i < X[0]->cols; i++){99help = init_mat(X[0]->rows, 1, "");100for (j = 0; j < X[0]->rows; j++){101help->array.SZ[j][0] = X[0]->array.SZ[j][i];102}103help->kgv = X[1]->array.SZ[i + X_first][i + X_first];104help->flags.Integral = FALSE;105RG = extract_r(standard, help);106free_mat(help);107help = sg(RG, GL);108if (help->kgv != X[1]->array.SZ[i + X_first][i + X_first]){109fprintf(stderr, "ERROR in H1_of_standard_to_GL!\n");110exit(17);111}112for (j = 0; j < X[0]->rows; j++){113coz->array.SZ[j][i] = help->array.SZ[j][0];114}115free_mat(help);116free_bravais(RG);117}118119return(coz);120}121122123124/* ----------------------------------------------------------------------------- */125/* calculate the kernel and H^1/Ker for phi */126/* ----------------------------------------------------------------------------- */127static void kernel_fkt(matrix_TYP *phi,128matrix_TYP *A,129int A_first,130matrix_TYP *B,131matrix_TYP **kernel,132H1_mod_ker_TYP *H1_mod_ker)133{134int i, j, rows, cols, B_first, counter = 0, flagge, zahl,135D_first, D_last, D_diff;136137matrix_TYP *ker, *L, *R, *D, *Li;138139140for (B_first = 0; B_first < B->cols && B->array.SZ[B_first][B_first] == 1; B_first++);141142/* expand phi */143rows = phi->rows;144cols = phi->cols;145real_mat(phi, rows, cols + rows);146for (i = 0; i < rows; i++){147phi->array.SZ[i][i + cols] = B->array.SZ[i + B_first][i + B_first];148}149150/* calculate kernel */151ker = long_kernel_mat(phi);152kernel[0] = init_mat(cols, ker->cols, "");153for (i = 0; i < ker->cols; i++){154flagge = 0;155for (j = 0; j < cols; j++){156zahl = ker->array.SZ[j][i] % A->array.SZ[j + A_first][j + A_first];157if (zahl < 0)158zahl += A->array.SZ[j + A_first][j + A_first];159if (zahl != 0)160flagge = 1;161kernel[0]->array.SZ[j][counter] = zahl;162}163if (flagge == 1){164counter++;165}166}167free_mat(ker);168169/* calculate A/ker(phi) */170if (counter == 0){171/* trivial part: ker(phi) = 0 */172H1_mod_ker[0].D = init_mat(cols, cols, "");173H1_mod_ker[0].M = (matrix_TYP **)calloc(cols, sizeof(matrix_TYP *));174H1_mod_ker[0].i = init_mat(cols, cols, "1");175for (i = 0; i < cols; i++){176H1_mod_ker[0].D->array.SZ[i][i] = A->array.SZ[i + A_first][i + A_first];177H1_mod_ker[0].M[i] = init_mat(cols, 1, "");178H1_mod_ker[0].M[i]->array.SZ[i][0] = 1;179}180H1_mod_ker[0].erz_no = cols;181H1_mod_ker[0].D_first = 0;182}183else{184real_mat(kernel[0], cols, counter + cols);185for (i = 0; i < cols; i++){186kernel[0]->array.SZ[i][i + counter] = A->array.SZ[i + A_first][i + A_first];187}188L = init_mat(cols, cols, "1");189R = init_mat(counter + cols, counter + cols, "1");190D = long_elt_mat(L, kernel[0], R);191Li = mat_inv(L);192/*193standard_form(L, A, A_first);194Li = graph_mat_inv(L, A, A_first);195*/196for (D_first = 0; D_first < D->rows && D->array.SZ[D_first][D_first] == 1; D_first++);197for (D_last = D_first; D_last < D->rows && D->array.SZ[D_last][D_last] != 0; D_last++);198D_diff = D_last - D_first;199H1_mod_ker[0].M = (matrix_TYP **)calloc(D_diff, sizeof(matrix_TYP *));200for (i = 0; i < D_diff; i++){201H1_mod_ker[0].M[i] = init_mat(cols, 1, "");202for (j = 0; j < cols; j++){203H1_mod_ker[0].M[i]->array.SZ[j][0] = Li->array.SZ[j][i + D_first] %204A->array.SZ[j + A_first][j + A_first];205if (H1_mod_ker[0].M[i]->array.SZ[j][0] < 0)206H1_mod_ker[0].M[i]->array.SZ[j][0] += A->array.SZ[j + A_first][j + A_first];207}208}209H1_mod_ker[0].erz_no = D_diff;210H1_mod_ker[0].D = D;211H1_mod_ker[0].D_first = D_first;212213H1_mod_ker[0].i = L;214free_mat(Li);215free_mat(R);216D = NULL;217Li = NULL;218}219220/* clean */221real_mat(phi, rows, cols);222real_mat(kernel[0], cols, counter);223}224225226227/* -------------------------------------------------------------------------------- */228/* calculate phi: H^1(G, Q^n/L) -> H^1(G,Q^n/Z^n), i.e. */229/* calculate phi: H^1(given by Xi) -> H^1(given by Xj) */230/* -------------------------------------------------------------------------------- */231void calculate_phi(matrix_TYP *diag,232matrix_TYP *coz,233matrix_TYP **Xi,234matrix_TYP **Xj,235matrix_TYP *GLS,236matrix_TYP **phi,237matrix_TYP **kernel,238matrix_TYP ***image,239int *image_gen_no,240H1_mod_ker_TYP *H1_mod_ker)241{242matrix_TYP *H1_L,243*tmp,244*test;245246int i, j,247dim_i, dim_j, first;248249250251for (first = 0; first < Xj[1]->cols && Xj[1]->array.SZ[first][first] == 1; first++);252253/* calculate cohomology group for the lattice */254if (coz->cols > 0)255H1_L = mat_mul(diag, coz);256else257H1_L = init_mat(diag->rows, 0, "");258259dim_j = H1_L->cols;260dim_i = Xi[0]->cols;261phi[0] = init_mat(dim_i, dim_j, "");262263/* calculate phi, kernel and image */264if (dim_i > 0 && dim_j > 0){265image[0] = (matrix_TYP **)calloc(dim_j, sizeof(matrix_TYP *));266/* some functions need the generating set for the image in the following form */267for (i = 0; i < dim_j; i++){268tmp = init_mat(H1_L->rows, 1, "");269for (j = 0; j < tmp->rows; j++)270tmp->array.SZ[j][0] = H1_L->array.SZ[j][i];271tmp->kgv = Xj[1]->array.SZ[i + first][i + first];272tmp->flags.Integral = 0;273Check_mat(tmp);274image[0][i] = standard_rep(tmp, GLS, Xi[1]);275free_mat(tmp);276for (j = 0; j < dim_i; j++){277phi[0]->array.SZ[j][i] = image[0][i]->array.SZ[j][0];278}279}280kernel_fkt(phi[0], Xj[1], first, Xi[1], kernel, H1_mod_ker);281image_gen_no[0] = dim_j;282H1_mod_ker[0].flag = 0;283}284else{285/* trivial part */286if (dim_i == 0){287kernel[0] = init_mat(dim_j, dim_j, "1");288}289else{290kernel[0] = init_mat(dim_j, 0, "");291}292image[0] = (matrix_TYP **)calloc(1, sizeof(matrix_TYP *));293image_gen_no[0] = 0;294if (dim_i == 0 && dim_j == 0)295H1_mod_ker[0].flag = 3;296else{297if (dim_i == 0)298H1_mod_ker[0].flag = 2;299else300H1_mod_ker[0].flag = 1;301}302}303304/* clean */305free_mat(H1_L);306307}308309310311312313314