From 3f9df34e01f3d1fd4ebae9aa4a127713a14397dd Mon Sep 17 00:00:00 2001 From: Florian Stecker Date: Mon, 20 Jun 2016 10:37:21 +0200 Subject: [PATCH] List thickenings when found --- thickenings.c | 167 ++++++++++++++++++++++++++++---------------------- 1 file changed, 94 insertions(+), 73 deletions(-) diff --git a/thickenings.c b/thickenings.c index 1fe34f1..b0cd0dd 100644 --- a/thickenings.c +++ b/thickenings.c @@ -11,6 +11,8 @@ #define DEBUG(msg, ...) do{fprintf(stderr, msg, ##__VA_ARGS__); }while(0) +#define MAX_THICKENINGS 10000 + typedef struct _edgelist { int to; struct _edgelist *next; @@ -37,6 +39,32 @@ static char *alphabetize(int *word, int len, const char *alphabet, char *buffer) return buffer; } +static void print_balanced_thickening(int rank, int order, const int *thickening, const int *left_invariant, const int *right_invariant, const char *alphabet) +{ + for(int i = 0; i < order; i++) { + if(thickening[i]) + printf("x"); + else + printf("0"); + } + + printf(" left: "); + for(int j = 0; j < rank; j++) + if(left_invariant[j]) + printf("%c", alphabet[j]); + else + printf(" "); + + printf(" right: "); + for(int j = 0; j < rank; j++) + if(right_invariant[j]) + printf("%c", alphabet[j]); + else + printf(" "); + + printf("\n"); +} + static int compare_wordlength(const void *a, const void *b, void *gr) { int i = *((int*)a); @@ -67,6 +95,8 @@ int main(int argc, const char *argv[]) int is_fat, is_slim; int thickenings_count, fat_count, slim_count, balanced_count; + int *balanced_thickenings; + char *string_buffer1, *string_buffer2; const char *alphabet = "abcdefghijklmnopqrstuvwxyz"; @@ -86,7 +116,7 @@ int main(int argc, const char *argv[]) ERROR(strlen(alphabet) < rank, "The alphabet has too few letters\n"); - DEBUG("The group has rank %d and order %d\n", rank, order); + // DEBUG("The group has rank %d and order %d\n", rank, order); graph = (node_t*)malloc(order*sizeof(node_t)); graph_unsorted = (node_t*)malloc(order*sizeof(node_t)); @@ -99,8 +129,9 @@ int main(int argc, const char *argv[]) right = (int*)malloc(order*rank*sizeof(int)); left_invariant = (int*)malloc(rank*sizeof(int)); right_invariant = (int*)malloc(rank*sizeof(int)); + balanced_thickenings = (int*)malloc(MAX_THICKENINGS*order*sizeof(int)); - DEBUG("Generate Cayley graph\n"); + // DEBUG("Generate Cayley graph\n"); generate_coxeter_graph(type, graph_data); @@ -116,7 +147,7 @@ int main(int argc, const char *argv[]) graph_unsorted[i].is_hyperplane_reflection = 0; } - DEBUG("Find wordlengths\n"); + // DEBUG("Find wordlengths\n"); graph_unsorted[0].wordlength = 0; queue_init(&queue); @@ -139,7 +170,7 @@ int main(int argc, const char *argv[]) string_buffer1 = (char*)malloc((max_wordlength+1)*sizeof(char)); string_buffer2 = (char*)malloc((max_wordlength+1)*sizeof(char)); - DEBUG("Sort by wordlength\n"); + // DEBUG("Sort by wordlength\n"); for(int i = 0; i < order; i++) wordlength_order[i] = i; @@ -152,7 +183,7 @@ int main(int argc, const char *argv[]) graph[i].left[j] = reverse_wordlength_order[graph[i].left[j]]; // rewrite references } - DEBUG("Find words\n"); + // DEBUG("Find words\n"); words = (int*)malloc(order*max_wordlength*sizeof(int)); memset(words, 0, order*max_wordlength*sizeof(int)); @@ -171,7 +202,7 @@ int main(int argc, const char *argv[]) } } - DEBUG("Generate right edges\n"); + // DEBUG("Generate right edges\n"); for(int i = 0; i < order; i++) { for(int j = 0; j < rank; j++) { @@ -183,7 +214,7 @@ int main(int argc, const char *argv[]) } } - DEBUG("Find opposites\n"); + // DEBUG("Find opposites\n"); node_t *longest = &graph[order-1]; for(int i = 0; i < order; i++) { @@ -193,7 +224,7 @@ int main(int argc, const char *argv[]) graph[i].opposite = current; } - DEBUG("Enumerate hyperplanes\n"); // every right edge is a reflection along a hyperplane; calculate what this reflection does to the identity + // DEBUG("Enumerate hyperplanes\n"); // every right edge is a reflection along a hyperplane; calculate what this reflection does to the identity hyperplane_count = 0; for(int i = 0; i < order; i++) { @@ -214,8 +245,8 @@ int main(int argc, const char *argv[]) } } - DEBUG("We have %d hyperplanes\n", hyperplane_count); - DEBUG("Generate folding order\n"); + // DEBUG("The Weyl chambers are bounded by %d hyperplanes\n", hyperplane_count); + // DEBUG("Generate folding order\n"); edgelists = (edgelist_t*)malloc(order*hyperplane_count*sizeof(edgelist_t)); for(int i = 0; i < order; i++) { @@ -239,7 +270,7 @@ int main(int argc, const char *argv[]) } } - DEBUG("Remove redundant edges\n"); + // DEBUG("Remove redundant edges\n"); for(int i = 0; i < order; i++) { memset(seen, 0, order*sizeof(int)); @@ -277,7 +308,7 @@ int main(int argc, const char *argv[]) } } - DEBUG("Reverse folding order\n"); + // DEBUG("Reverse folding order\n"); for(int i = 0; i < order; i++) { edge = graph[i].bruhat_lower; @@ -290,17 +321,21 @@ int main(int argc, const char *argv[]) } } - printf("The group is: \n"); - for(int i =0; i < order; i++) { - if(graph[i].wordlength == 0) - printf("1 "); - else + printf("Rank: %d\t\tOrder: %d\t\tHyperplanes: %d\n", rank, order, hyperplane_count); + printf("\n"); + printf("Group elements: \n"); + for(int i = 0, wl = 0; i < order; i++) { + if(i == 0) { + printf("1"); + } else if(graph[i].wordlength > wl) { + printf("\n%s ", alphabetize(graph[i].word, graph[i].wordlength, alphabet, string_buffer1)); + wl = graph[i].wordlength; + } else printf("%s ", alphabetize(graph[i].word, graph[i].wordlength, alphabet, string_buffer1)); } - printf("\n"); + printf("\n\n"); - DEBUG("Enumerate thickenings\n"); - DEBUG("\n"); + // DEBUG("Enumerate thickenings\n"); thickenings_count = fat_count = slim_count = balanced_count = 0; memset(level, 0, order*sizeof(int)); @@ -339,51 +374,33 @@ int main(int argc, const char *argv[]) fat_count++; if(is_slim) slim_count++; - if(is_slim && is_fat) + if(is_slim && is_fat) { + ERROR(balanced_count >= MAX_THICKENINGS, "Too many balanced thickenings! Increase MAX_THICKENINGS\n"); + memcpy(&balanced_thickenings[balanced_count*order], level, order*sizeof(int)); balanced_count++; + } - // print out levels if(is_fat && is_slim) { // check for invariances for(int j = 0; j < rank; j++) { - left_invariant[j] = 1; - right_invariant[j] = 1; + left_invariant[j] = 1; + right_invariant[j] = 1; } - for(int i = 0; i < order; i++) { - for(int j = 0; j < rank; j++) { - if(level[i] == 0 && level[graph[i].left[j]] != 0 || level[i] != 0 && level[graph[i].left[j]] == 0) - left_invariant[j] = 0; - if(level[i] == 0 && level[graph[i].right[j]] != 0 || level[i] != 0 && level[graph[i].right[j]] == 0) - right_invariant[j] = 0; - } + for(int j = 0; j < rank; j++) { + if(level[i] == 0 && level[graph[i].left[j]] != 0 || level[i] != 0 && level[graph[i].left[j]] == 0) + left_invariant[j] = 0; + if(level[i] == 0 && level[graph[i].right[j]] != 0 || level[i] != 0 && level[graph[i].right[j]] == 0) + right_invariant[j] = 0; + } } - - for(int i = 0; i < order; i++) { - if(level[i] != 0) - printf("x"); - else - printf("%d", level[i]); - } - printf(" left: "); - for(int j = 0; j < rank; j++) - if(left_invariant[j]) - printf("%c", alphabet[j]); - else - printf(" "); - printf(" right: "); - for(int j = 0; j < rank; j++) - if(right_invariant[j]) - printf("%c", alphabet[j]); - else - printf(" "); - printf("\n"); + print_balanced_thickening(rank, order, level, left_invariant, right_invariant, alphabet); } // try to find empty spot to the left of "head" for(i = head - 1; i >= 0; i--) if(level[i] == 0) - break; + break; if(i >= 0) { head = i; level[head] = -1; @@ -414,38 +431,41 @@ int main(int argc, const char *argv[]) for(int i = 0; i < head; i++) if(level[i] >= current_level) level[i] = 0; - - // print out levels - /* for(int i = 0; i < order; i++) { */ - /* if(level[i] == -1) */ - /* printf("x"); */ - /* else */ - /* printf("%d", level[i]); */ - /* } */ - /* printf(" %d\n", current_level); */ } printf("\n"); - printf("Found %d thickenings, %d fat, %d slim, %d balanced\n", thickenings_count, fat_count, slim_count, balanced_count); + printf("Found %d thickenings, %d fat, %d slim, %d balanced\n\n", thickenings_count, fat_count, slim_count, balanced_count); /* - printf("\n"); - - for(int i = 0; i < order; i++) { - printf("%-6s ", alphabetize(graph[i].word, graph[i].wordlength, alphabet, string_buffer1)); - - edge = graph[i].bruhat_higher; - while(edge) { - printf("-> %-6s ", alphabetize(graph[edge->to].word, graph[edge->to].wordlength, alphabet, string_buffer1)); - edge = edge->next; + for(int i = 0; i < balanced_count; i++) { + // figure out invariances + for(int j = 0; j < rank; j++) { + left_invariant[j] = 1; + right_invariant[j] = 1; } - //printf("Bruhat: %6s -> %-6s\n", alphabetize(graph[current].word, graph[current].wordlength, alphabet, string_buffer1), alphabetize(graph[j].word, graph[j].wordlength, alphabet, string_buffer2)); + int *current_thickening = balanced_thickenings + i*order; + + for(int k = 0; k < order; k++) { + for(int j = 0; j < rank; j++) { + if(current_thickening[k] == 0 && current_thickening[graph[k].left[j]] != 0 || current_thickening[k] != 0 && current_thickening[graph[k].left[j]] == 0) + left_invariant[j] = 0; + if(current_thickening[k] == 0 && current_thickening[graph[k].right[j]] != 0 || current_thickening[k] != 0 && current_thickening[graph[k].right[j]] == 0) + right_invariant[j] = 0; + } + } + + printf("left: "); + for(int k = 0; k < rank; k++) + printf("%c", left_invariant[k] ? alphabet[k] : ' '); + printf(" right: "); + for(int k = 0; k < rank; k++) + printf("%c", right_invariant[k] ? alphabet[k] : ' '); printf("\n"); } - printf("\n"); */ + free(edgelists); free(words); free(string_buffer1); @@ -462,6 +482,7 @@ int main(int argc, const char *argv[]) free(left_invariant); free(right_invariant); free(type.factors); + free(balanced_thickenings); return 0; }