GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
#include "typedef.h"1/***** This file contains routines to calculate2and compare Bacher-polynomials *****/345/******************************************************************\6| the Bacher-polynomial for v[I] with scalar product S7| is defined as follows: let list be the vectors which8| have the same length as v[I] and with scalar product S9| with v[I], for each vector w in list let n_w be the10| number of pairs (y,z) of vectors in list, such that all11| scalar products between w,y and z are S,12| then the Bacher-polynomial is the sum over the w in list13| of the monomials X^n_w14\******************************************************************/15static void bacher(pol, I, S, V, Fv)16bachpol *pol;17veclist V;18int I, S, **Fv;19{20int *list, nlist, *listxy, nxy, *counts;21int i, j, k, s, dim, sign1, sign2, *vI;2223/* the Bacher-polynomials of v[I] and -v[I] are equal */24I = abs(I);25dim = V.dim;26vI = V.v[I];27/* list of vectors that have scalar product S with v[I] */28if ((list = (int*)malloc(2*V.n * sizeof(int))) == 0)29exit (2);30for (i = 0; i < 2*V.n; ++i)31list[i] = 0;32nlist = 0;33for (i = 1; i <= V.n; ++i)34{35if (V.v[i][dim] == vI[dim])36{37s = sscp(vI, Fv[i], dim);38if (s == S)39{40list[nlist] = i;41++nlist;42}43if (-s == S)44{45list[nlist] = -i;46++nlist;47}48}49}50/* there are nlist vectors that have scalar product S with v[I] */51pol->sum = nlist;52if ((counts = (int*)malloc(nlist * sizeof(int))) == 0)53exit (2);54if ((listxy = (int*)malloc(nlist * sizeof(int))) == 0)55exit (2);56for (i = 0; i < nlist; ++i)57{58/* listxy is the list of the nxy vectors from list that have scalar product S59with v[list[i]] */60for (j = 0; j < nlist; ++j)61listxy[j] = 0;62nxy = 0;63sign1 = list[i] > 0 ? 1 : -1;64for (j = 0; j < nlist; ++j)65{66sign2 = list[j] > 0 ? 1 : -1;67/* note: for i > 0 is v[-i] = -v[i] */68if (sign1*sign2 * sscp(V.v[sign1*list[i]], Fv[sign2*list[j]], dim) == S)69{70listxy[nxy] = list[j];71nxy += 1;72}73}74/* counts[i] is the number of pairs for the vector v[list[i]] */75counts[i] = 0;76for (j = 0; j < nxy; ++j)77{78sign1 = listxy[j] > 0 ? 1 : -1;79for (k = j+1; k < nxy; ++k)80{81sign2 = listxy[k] > 0 ? 1 : -1;82if (sign1*sign2 * sscp(V.v[sign1*listxy[j]], Fv[sign2*listxy[k]], dim) == S)83counts[i] += 1;84}85}86}87/* pol->maxd is the maximal degree of the Bacher-polynomial,88pol->mind the minimal degree */89pol->maxd = counts[0];90pol->mind = counts[0];91for (i = 1; i < nlist; ++i)92{93if (counts[i] > pol->maxd)94pol->maxd = counts[i];95else if (counts[i] < pol->mind)96pol->mind = counts[i];97}98if ((pol->coef = (int*)malloc((pol->maxd - pol->mind + 1) * sizeof(int))) == 0)99exit (2);100for (i = 0; i <= pol->maxd - pol->mind; ++i)101pol->coef[i] = 0;102for (i = 0; i < nlist; ++i)103pol->coef[counts[i] - pol->mind] += 1;104/* the Bacher-polynomial is now: sum from i=pol->mind to pol->maxd over105pol->coef[i - pol->mind] * X^i */106free(listxy);107free(counts);108free(list);109}110111/******************************************************************\112| checks, whether the vector v[I] has the Bacher-polynomial pol113\******************************************************************/114static int bachcomp(pol, I, S, V, Fv)115bachpol pol;116veclist V;117int I, S, **Fv;118{119int *co, *list, nlist, *listxy, nxy, count;120int i, j, k, s, dim, sign1, sign2, *vI;121122I = abs(I);123dim = V.dim;124vI = V.v[I];125if ((co = (int*)malloc((pol.maxd - pol.mind + 1) * sizeof(int))) == 0)126exit (2);127for (i = 0; i <= pol.maxd-pol.mind; ++i)128co[i] = 0;129if ((list = (int*)malloc(pol.sum * sizeof(int))) == 0)130exit (2);131for (i = 0; i < pol.sum; ++i)132list[i] = 0;133/* nlist should be equal to pol.sum */134nlist = 0;135for (i = 1; i <= V.n && nlist <= pol.sum; ++i)136{137if (V.v[i][dim] == vI[dim])138{139s = sscp(vI, Fv[i], dim);140if (s == S)141{142if (nlist < pol.sum)143list[nlist] = i;144nlist += 1;145}146if (-s == S)147{148if (nlist < pol.sum)149list[nlist] = -i;150nlist += 1;151}152}153}154if (nlist != pol.sum)155/* the number of vectors with scalar product S is already different */156{157free(co);158free(list);159return(0);160}161/* listxy is the list of the nxy vectors from list that have scalar product S162with v[list[i]] */163if ((listxy = (int*)malloc(nlist * sizeof(int))) == 0)164exit (2);165for (i = 0; i < nlist; ++i)166{167for (j = 0; j < nlist; ++j)168listxy[j] = 0;169nxy = 0;170sign1 = list[i] > 0 ? 1 : -1;171for (j = 0; j < nlist; ++j)172{173sign2 = list[j] > 0 ? 1 : -1;174if (sign1*sign2 * sscp(V.v[sign1*list[i]], Fv[sign2*list[j]], dim) == S)175{176listxy[nxy] = list[j];177nxy += 1;178}179}180/* count is the number of pairs */181count = 0;182for (j = 0; j < nxy && count <= pol.maxd; ++j)183{184sign1 = listxy[j] > 0 ? 1 : -1;185for (k = j+1; k < nxy && count <= pol.maxd; ++k)186{187sign2 = listxy[k] > 0 ? 1 : -1;188if (sign1*sign2 * sscp(V.v[sign1*listxy[j]], Fv[sign2*listxy[k]], dim) == S)189count += 1;190}191}192if (count < pol.mind || count > pol.maxd ||193co[count-pol.mind] >= pol.coef[count-pol.mind])194/* if the number of pairs is smaller than pol.mind or larger than pol.maxd195or if the coefficient of X^count becomes now larger than the one in pol,196then the Bacher-polynomials can not be equal */197{198free(listxy);199free(co);200free(list);201return(0);202}203else204co[count-pol.mind] += 1;205}206free(listxy);207free(co);208free(list);209/* the Bacher-polynomials are equal */210return(1);211}212213/*************************************************\214| prints a Bacher-polynomial215\*************************************************/216static void fputbach(outfile, pol)217FILE *outfile;218bachpol pol;219{220int i;221222for (i = pol.mind; i <= pol.maxd; ++i)223{224if (pol.coef[i-pol.mind] != 0)225fprintf(outfile, "%d*x^%d ", pol.coef[i-pol.mind], i);226}227fprintf(outfile, "\n");228}229230231