GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
/* last change: 13.02.2001 by Oliver Heidbuechel */123#include <typedef.h>4#include <presentation.h>5#include <matrix.h>6#include <bravais.h>7#include <base.h>8#include <datei.h>9#include <graph.h>10#include <gmp.h>11#include <zass.h>12#include <longtools.h>13141516/* -------------------------------------------------------------------------- */17/* Test if S is a proper k-subgroup of R */18/* T(R) = Z^n */19/* P = P(R) has to be P(S) (generators don't have to be equal) */20/* (generating set without Id's from translations of the space group) */21/* n: the last n matrices generate the translationlattice of S */22/* (we need this, if the presentation includes no information for this */23/* matrices) */24/* pres: presentation of P(R) */25/* -------------------------------------------------------------------------- */26boolean is_k_subgroup(bravais_TYP *S,27bravais_TYP *R,28bravais_TYP *P,29int n,30matrix_TYP *pres)31{32matrix_TYP *coz_s_neu, *coz_r, *diff, **INV, *ID, **Id, *T;3334rational eins, minuseins;3536int i, j, k, d = S->gen[0]->rows - 1;3738word *relator;3940boolean FLAG = TRUE;4142bravais_TYP *S_neu;4344454647/* sublattice check for the last n generators */48for (i = 1; i <= n; i++){49Check_mat(S->gen[S->gen_no - i]);50if (S->gen[S->gen_no - i]->kgv != 1)51return(FALSE);52}5354/* compare cocycles */55coz_s_neu = sg(S, P);56S_neu = extract_r(P, coz_s_neu);57eins.z = eins.n = minuseins.n = 1; minuseins.z = -1;58coz_r = extract_c(R);59diff = mat_add(coz_s_neu, coz_r, eins, minuseins);60Check_mat(diff);61if (diff->kgv != 1){62free_mat(coz_r);63free_mat(coz_s_neu);64free_mat(diff);65free_bravais(S_neu);66return(FALSE);67}68free_mat(diff);69free_mat(coz_r);70free_mat(coz_s_neu);7172/* compare translation lattices */73INV = (matrix_TYP **)calloc(S_neu->gen_no, sizeof(matrix_TYP *));74Id = (matrix_TYP **)calloc(pres->rows, sizeof(matrix_TYP *));75relator = (word *)calloc(pres->rows, sizeof(word));76for (i = 0; i < pres->rows; i++){77matrix_2_word(pres, relator + i, i);78}79for (i = 0; i < pres->rows; i++){80Id[i] = matrizen_in_word(S_neu->gen, INV, relator[i]);81}82T = init_mat(d, n + pres->rows, "");83for (i = 0; i < n; i++){84for (j = 0; j < d; j++)85T->array.SZ[j][i] = S->gen[S->gen_no - 1 - i]->array.SZ[j][d];86}87for (i = 0; i < pres->rows && FLAG; i++){88if (Id[i]->kgv != 1)89FLAG = FALSE;90for (j = 0; j < d && FLAG; j++){ /* rows */91for (k = 0; k < d && FLAG; k++){ /* colums */92if (j == k){93if (Id[i]->array.SZ[j][k] != 1)94FLAG = FALSE;95}96else{97if (Id[i]->array.SZ[j][k] != 0)98FLAG = FALSE;99}100}101}102for (j = 0; j < d && FLAG; j++){ /* last column */103T->array.SZ[j][i + n] = Id[i]->array.SZ[j][d];104}105}106ID = init_mat(d, d, "1");107if (FLAG == TRUE){108long_col_hnf(T);109real_mat(T, T->rows, T->rows);110111if (cmp_mat(T, ID) != 0)112FLAG = TRUE;113else114FLAG = FALSE;115}116117/* clean */118free_mat(ID);119free_mat(T);120for (i = 0; i < S_neu->gen_no; i++){121if (INV[i] != NULL)122free_mat(INV[i]);123}124free(INV);125free_bravais(S_neu);126for (i = 0; i < pres->rows; i++)127free_mat(Id[i]);128free(Id);129for (i = 0; i < pres->rows; i++)130wordfree(relator + i);131free(relator);132133return(FLAG);134}135136137