some cleanup -> sent to david dumas

This commit is contained in:
Florian Stecker 2016-10-14 18:49:20 +02:00
parent 76783124e2
commit 5bcb30b5c1
6 changed files with 41 additions and 182 deletions

View File

@ -1,7 +1,7 @@
HEADERS=coxeter.h thickenings.h queue.h HEADERS=coxeter.h thickenings.h queue.h
OPTIONS=-O3 -std=gnu99 OPTIONS=-O3 -m64 -flto -funroll-loops -std=gnu99
all: generate process test all: generate process
generate: generate.o coxeter.o thickenings.o generate: generate.o coxeter.o thickenings.o
gcc $(OPTIONS) -o generate generate.o thickenings.o coxeter.o -lgsl -lcblas gcc $(OPTIONS) -o generate generate.o thickenings.o coxeter.o -lgsl -lcblas
@ -9,9 +9,6 @@ generate: generate.o coxeter.o thickenings.o
process: process.o coxeter.o thickenings.o process: process.o coxeter.o thickenings.o
gcc $(OPTIONS) -o process process.o thickenings.o coxeter.o -lgsl -lcblas gcc $(OPTIONS) -o process process.o thickenings.o coxeter.o -lgsl -lcblas
test: test.o coxeter.o thickenings.o
gcc $(OPTIONS) -o test test.o thickenings.o coxeter.o -lgsl -lcblas
generate.o: generate.c $(HEADERS) generate.o: generate.c $(HEADERS)
gcc $(OPTIONS) -c generate.c gcc $(OPTIONS) -c generate.c
@ -24,8 +21,5 @@ thickenings.o: thickenings.c $(HEADERS)
coxeter.o: coxeter.c $(HEADERS) coxeter.o: coxeter.c $(HEADERS)
gcc $(OPTIONS) -c coxeter.c gcc $(OPTIONS) -c coxeter.c
test.o: test.c $(HEADERS)
gcc $(OPTIONS) -c test.c
clean: clean:
rm -f generate process test thickenings.o coxeter.o generate.o process.o test.o rm -f generate process thickenings.o coxeter.o generate.o process.o

View File

@ -227,7 +227,7 @@ void generate_coxeter_graph(semisimple_type_t type, int *result)
} }
} }
ERROR(element_count != order, "Somethink went wrong building the Coxeter group. Found %d elements, %d expected\n", element_count, order); ERROR(element_count != order, "Something went wrong building the Coxeter group. Found %d elements, %d expected\n", element_count, order);
/* /*
for(int i = 0; i < order; i++) { for(int i = 0; i < order; i++) {

View File

@ -75,7 +75,10 @@ int main(int argc, const char *argv[])
fwrite(&type.n, sizeof(int), 1, stdout); fwrite(&type.n, sizeof(int), 1, stdout);
fwrite(type.factors, sizeof(simple_type_t), type.n, stdout); fwrite(type.factors, sizeof(simple_type_t), type.n, stdout);
enumerate_balanced_thickenings(type, graph, alphabet, stdout); long count = enumerate_balanced_thickenings(type, graph, alphabet, stdout);
fprintf(stderr, "\n");
fprintf(stderr, "Found %ld balanced thickenings\n\n", count);
free(graph); free(graph);
free(left); free(left);

120
test.c
View File

@ -1,120 +0,0 @@
#include <stdio.h>
#include "thickenings.h"
#include "queue.h"
#define SWAP(t, a, b) do {t tmp = a; a = b; b = tmp;} while(0)
char *stringify_Sp2n_permutation(int *word, int wordlength, int rank, int len, char *str)
{
for(int i = 0; i < rank*2; i++)
str[i] = '1' + i;
str[2*rank] = 0;
for(int i = 0; i < wordlength; i++) {
if(word[i] == 0)
SWAP(char, str[rank-1], str[2*rank-1]);
else {
SWAP(char, str[rank-word[i]], str[rank-word[i]-1]);
SWAP(char, str[2*rank-word[i]], str[2*rank-word[i]-1]);
}
}
str[len] = 0;
return str;
}
int main(int argc, const char *argv[])
{
semisimple_type_t type;
node_t *graph;
int *leftbuf, *rightbuf;
edgelist_t *edgelists;
int *words;
int rank, order;
int *reduced, *group;
int current;
queue_t queue;
char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
char buffer[1024];
int left = ~(1 << (atoi(argv[1]) - atoi(argv[3])));
int right = ~(1 << (atoi(argv[1]) - atoi(argv[2])));
type.n = 1;
type.factors = (simple_type_t*)malloc(type.n*sizeof(simple_type_t));
type.factors[0].series = 'B';
type.factors[0].rank = atoi(argv[1]);
rank = coxeter_rank(type);
order = coxeter_order(type);
graph = (node_t*)malloc(order*sizeof(node_t));
leftbuf = (int*)malloc(rank*order*sizeof(int));
rightbuf = (int*)malloc(rank*order*sizeof(int));
for(int i = 0; i < order; i++) {
graph[i].left = &leftbuf[i*rank];
graph[i].right = &rightbuf[i*rank];
}
prepare_graph(type, graph, &edgelists, &words);
reduced = (int*)malloc(order*sizeof(int));
group = (int*)malloc(order*sizeof(int));
for(int i = 0; i < order; i++) {
group[i] = -1;
reduced[i] = i;
}
// step 1: group
for(int i = 0; i < order; i++) {
if(group[i] != -1)
continue;
queue_init(&queue);
queue_put(&queue, i);
while((current = queue_get(&queue)) != -1) {
if(group[current] != -1)
continue;
group[current] = i;
for(int j = 0; j < rank; j++) {
if(left & (1 << j))
queue_put(&queue, graph[current].left[j]);
if(right & (1 << j))
queue_put(&queue, graph[current].right[j]);
}
}
}
// step 2: find minimum
for(int i = 0; i < order; i++)
if(graph[i].wordlength < graph[reduced[group[i]]].wordlength)
reduced[group[i]] = i;
// step 3: assign minimum to all
for(int i = 0; i < order; i++)
reduced[i] = reduced[group[i]];
for(int i = 0; i < order; i++)
if(reduced[i] == i) {
if(i == 0)
printf("1 ");
else
printf("%s ", alphabetize(graph[i].word, graph[i].wordlength, alphabet, buffer));
// printf("%s ", stringify_Sp2n_permutation(graph[i].word, graph[i].wordlength, rank, atoi(argv[2]), buffer));
}
printf("\n");
free(type.factors);
free(graph);
free(edgelists);
free(words);
free(reduced);
free(group);
free(leftbuf);
free(rightbuf);
return 0;
}

View File

@ -20,57 +20,26 @@ char *alphabetize(int *word, int len, const char *alphabet, char *buffer)
return buffer; return buffer;
} }
void print_thickening(int rank, int order, const signed char *thickening, int is_fat, int is_slim, int conflict, const char *alphabet, FILE *f) void print_thickening(int rank, int order, const signed char *thickening, int upto_level, const char *alphabet, FILE *f)
{ {
for(int i = 0; i < order; i++) { for(int i = 0; i < order; i++) {
if(thickening[i] == HEAD_MARKER) if(thickening[i] == HEAD_MARKER)
fprintf(f, "\e[41mx\e[39m\e[49m"); fprintf(f, "\e[41;37mx\e[0m");
else if(thickening[i] < - upto_level || thickening[i] > upto_level)
fprintf(f, " ");
else if(thickening[i] < 0 && thickening[i] > -10) else if(thickening[i] < 0 && thickening[i] > -10)
fprintf(f, "\e[47m\e[30m%d\e[39m\e[49m", -thickening[i]); fprintf(f, "\e[47;30m%d\e[0m", -thickening[i]);
else if(thickening[i] <= -10) else if(thickening[i] <= -10)
fprintf(f, "\e[47m\e[30m+\e[39m\e[49m"); fprintf(f, "\e[47;30m+\e[0m");
else if(thickening[i] > 0 && thickening[i] < 10) else if(thickening[i] > 0 && thickening[i] < 10)
fprintf(f, "%d", thickening[i]); fprintf(f, "\e[40;37m%d\e[0m", thickening[i]);
else if(thickening[i] >= 10) else if(thickening[i] >= 10)
fprintf(f, "+"); fprintf(f, "\e[40;37m+\e[0m");
else else
fprintf(f, " "); fprintf(f, " ");
} }
if(is_fat) fprintf(f, "\e[K");
fprintf(f, " F");
if(is_slim)
fprintf(f, " S");
if(conflict)
fprintf(f, " C");
fprintf(f, "\e[K\n");
}
void print_balanced_thickening(int rank, int order, const signed char *thickening, const int *left_invariant, const int *right_invariant, const char *alphabet, FILE *f)
{
for(int i = 0; i < order; i++) {
if(thickening[i])
fprintf(f, "x");
else
fprintf(f, "0");
}
fprintf(f, " left: ");
for(int j = 0; j < rank; j++)
if(left_invariant[j])
fprintf(f, "%c", alphabet[j]);
else
fprintf(f, " ");
fprintf(f, " right: ");
for(int j = 0; j < rank; j++)
if(right_invariant[j])
fprintf(f, "%c", alphabet[j]);
else
fprintf(f, " ");
fprintf(f, "\n");
} }
static int compare_wordlength(const void *a, const void *b, void *gr) static int compare_wordlength(const void *a, const void *b, void *gr)
@ -306,7 +275,7 @@ void prepare_graph(semisimple_type_t type, node_t *graph, edgelist_t **edgelists
free(seen); free(seen);
} }
void enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const char *alphabet, FILE *outfile) long enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const char *alphabet, FILE *outfile)
{ {
int rank, order; int rank, order;
signed char *level; signed char *level;
@ -367,7 +336,7 @@ void enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const
} }
} }
// now we have something, check if it is a balanced thickening // now we have something, check if it is a balanced thickening; if so, write to stdout
if(is_slim) { if(is_slim) {
is_fat = 1; is_fat = 1;
for(int i = 0; i < order; i++) { for(int i = 0; i < order; i++) {
@ -379,13 +348,27 @@ void enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const
if(is_fat) { if(is_fat) {
// ERROR(count >= MAX_THICKENINGS, "Too many balanced thickenings! Increase MAX_THICKENINGS\n"); // ERROR(count >= MAX_THICKENINGS, "Too many balanced thickenings! Increase MAX_THICKENINGS\n");
if(printstep && (count+1) % printstep == 0)
print_thickening(rank, order, level, 0, 0, 0, alphabet, stderr);
fwrite(level, sizeof(signed char), order, outfile); fwrite(level, sizeof(signed char), order, outfile);
count++; count++;
} }
} }
// if printstep is set accordingly, write state to stderr
if(is_slim && is_fat && printstep > 0 && (count + 1) % printstep == 0) {
print_thickening(rank, order, level, current_level, alphabet, stderr);
fprintf(stderr, "\n");
}
else if(printstep < 0) {
print_thickening(rank, order, level, current_level - !is_slim, alphabet, stderr);
fprintf(stderr, " ");
if(is_slim) {
fprintf(stderr, "S");
if(is_fat)
fprintf(stderr, "F");
}
fprintf(stderr, "\n");
}
// now find the next one! // now find the next one!
// try to find empty spot to the left of "head", but only if it is slim, as otherwise there is no point in adding even more // try to find empty spot to the left of "head", but only if it is slim, as otherwise there is no point in adding even more
@ -427,8 +410,7 @@ void enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const
level[i] = 0; level[i] = 0;
} }
fprintf(stderr, "\n");
fprintf(stderr, "Found %ld balanced thickenings\n\n", count);
free(level); free(level);
return count;
} }

View File

@ -5,7 +5,7 @@
#define DEBUG(msg, ...) do{fprintf(stderr, msg, ##__VA_ARGS__); }while(0) #define DEBUG(msg, ...) do{fprintf(stderr, msg, ##__VA_ARGS__); }while(0)
#define MAX_THICKENINGS 10000000 #define MAX_THICKENINGS 0 // 0 means infinite
#define HEAD_MARKER 127 #define HEAD_MARKER 127
typedef struct _edgelist { typedef struct _edgelist {
@ -13,6 +13,7 @@ typedef struct _edgelist {
struct _edgelist *next; struct _edgelist *next;
} edgelist_t; } edgelist_t;
// describes an element of the Coxeter group; only "opposite" and "bruhat_lower" are being used for enumerating thickenings; everything else is just needed for initialization or output
typedef struct { typedef struct {
int *word; int *word;
int wordlength; int wordlength;
@ -25,10 +26,9 @@ typedef struct {
} node_t; } node_t;
char *alphabetize(int *word, int len, const char *alphabet, char *buffer); char *alphabetize(int *word, int len, const char *alphabet, char *buffer);
void print_balanced_thickening(int rank, int order, const signed char *thickening, const int *left_invariant, const int *right_invariant, const char *alphabet, FILE *f); void print_thickening(int rank, int order, const signed char *thickening, int level, const char *alphabet, FILE *f);
void print_thickening(int rank, int order, const signed char *thickening, int fat, int slim, int conflict, const char *alphabet, FILE *f);
static int compare_wordlength(const void *a, const void *b, void *gr); static int compare_wordlength(const void *a, const void *b, void *gr);
void prepare_graph(semisimple_type_t type, node_t *graph, edgelist_t **edgelists_pointer, int **words_pointer); void prepare_graph(semisimple_type_t type, node_t *graph, edgelist_t **edgelists_pointer, int **words_pointer);
void enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const char *alphabet, FILE *outfile); long enumerate_balanced_thickenings(semisimple_type_t type, node_t *graph, const char *alphabet, FILE *outfile);
#endif #endif