diff options
| author | Julian Weigt <juw@posteo.de> | 2026-01-21 13:49:02 +0100 |
|---|---|---|
| committer | Julian Weigt <juw@posteo.de> | 2026-02-04 15:56:59 +0100 |
| commit | a77a26bb356b70684be89d86b95713daa5db8b3f (patch) | |
| tree | 5c84c6b6460be70cfee6cab900abd3d5661e6d68 /charf.c | |
| parent | 0042fb6e41e5201b39f57351ad33e7f940095775 (diff) | |
Change type of index to index_t and make it unsinged long.
Diffstat (limited to 'charf.c')
| -rw-r--r-- | charf.c | 46 |
1 files changed, 27 insertions, 19 deletions
@@ -34,11 +34,13 @@ #define STRING_SIZE 65536 +typedef unsigned long index_t; + /*maximum length of the support of f*/ #define N 32 /*maximal order of derivative*/ -#define K 32 +#define K 64 /*maximal number of exponents*/ #define P 5 @@ -153,16 +155,22 @@ void compute_maximalfunction(VALUETYPE* f, VALUETYPE* Mf, int D){ } /*Generates all characteristic functions of length up N.*/ -int generate_each_charf(VALUETYPE* f, int i){ - int s=0; - int d=2; +int generate_each_charf(VALUETYPE* f, index_t i){ + index_t s=0; + int d=1; + /*number of strings of length d that begin with 1*/ + index_t powd = 1; /*number of strings of length d that begin with 1 but are not all 1*/ - for(s=0; i-s >= (1<<(d-1))-1; d++) s += (1<<(d-1))-1; + while(i-s >= powd-1){ + s += powd-1; + d++; + powd = powd << 1; + } if(d>N) return -1; /*t starts with 1 and then comes i-s.*/ - int t = (1 << d-1) + i-s; + index_t t = (1 << d-1) + i-s; /*Indicates if we want to consider this t.*/ bool is_representative = true; @@ -171,9 +179,9 @@ int generate_each_charf(VALUETYPE* f, int i){ for(int r = 1; r < d; r++){ if(d % r == 0){ bool is_r_copy = true; - int ones = 0; - for(int o = 0; o<r; o++) ones += 1<<o; - int tail = t & ones; + index_t ones = 0; + for(int o = 0; o<r; o++) ones += ((index_t)1)<<o; + index_t tail = t & ones; for(int n = 1; n < d/r; n++) if( ( (t>>n*r) & ones ) != tail ) is_r_copy = false; if(is_r_copy) is_representative = false; } @@ -193,7 +201,7 @@ int generate_each_charf(VALUETYPE* f, int i){ else return 0; } -int generate_triangle(VALUETYPE* f, int i){ +int generate_triangle(VALUETYPE* f, index_t i){ int j = i+1; if(j <= N/2){ for(int n=0; n < N; n++) f[n] = int_to_valuetype(0); @@ -204,7 +212,7 @@ int generate_triangle(VALUETYPE* f, int i){ else return -1; } -int generate_random(VALUETYPE* f, int i){ +int generate_random(VALUETYPE* f, index_t i){ f[0] = int_to_valuetype(1); f[1] = int_to_valuetype(0); for(int n=2; n < N; n++) f[n] = int_to_valuetype(rand() % 2); @@ -212,7 +220,7 @@ int generate_random(VALUETYPE* f, int i){ } /*Writes into f the values of the function indexed by i. Returns the size of the support of f, or -1 if there is no function with that index.*/ -int generate_function(VALUETYPE* f, int i){ +int generate_function(VALUETYPE* f, index_t i){ return generate_each_charf(f,i); //return generate_random(f,i); //return generate_triangle(f,i); @@ -220,7 +228,7 @@ int generate_function(VALUETYPE* f, int i){ #define FORMAT_TEXT 0 #define FORMAT_LATEX 1 -void format_result(char* s, int index, int k, EXPTYPE p, VALUETYPE r, int format){ +void format_result(char* s, index_t index, int k, EXPTYPE p, VALUETYPE r, int format){ VALUETYPE f[N]; int d = generate_function(f,index); if(format == FORMAT_TEXT){ @@ -291,7 +299,7 @@ bool over_threshold_charf(double t, int k){ return (k==1 && t>=1) || (k==2 && t>=.5) || (k==3 && t>.53) || (k==4 && t>=.5) || (k==5 && t>=.58) || (k==6 && t>=.58) || (k==7 && t>=.69) || (k==8 && t>=.83) || (k==9 && t>=.8699) || (k==10 && t>=.919) || (k==11 && t>=.97) || (k==12 && t>=.97) || (k==13 && t>=.98) || (k==14 && t>=.98) || (k==15 && t>=.9817) || (k==16 && t>=.9817) || (k==17 && t>=.987) || (k==18 && t>=.991) || (k==19 && t>=.994) || (k==20 && t>=1.001) || (k==21 && t>=1.009) || (k==22 && t>=1.009) || (k==23 && t>=1.003) || (k==24 && t>=1.174) ; } -int compute(int index, EXPTYPE exponents[P], VALUETYPE (*records_ratio)[K+1][P], int (*records_index)[K+1][P]){ +int compute(index_t index, EXPTYPE exponents[P], VALUETYPE (*records_ratio)[K+1][P], index_t (*records_index)[K+1][P]){ VALUETYPE f[N]; int D = generate_function(f,index); /*Immediately abort if index is out of bounds.*/ @@ -360,7 +368,7 @@ int compute(int index, EXPTYPE exponents[P], VALUETYPE (*records_ratio)[K+1][P], return D; } -void format_results(char* text, EXPTYPE exponents[P], VALUETYPE ratios[K+1][P], int indeces[K+1][P], int format){ +void format_results(char* text, EXPTYPE exponents[P], VALUETYPE ratios[K+1][P], index_t indeces[K+1][P], int format){ char beginning[1024]; char end[1024]; char beginningp[P][1024]; @@ -418,13 +426,13 @@ void format_results(char* text, EXPTYPE exponents[P], VALUETYPE ratios[K+1][P], l += sprintf(text+l, "%s\n", end); } -void print_records(EXPTYPE exponents[P], VALUETYPE ratios[K+1][P], int indeces[K+1][P]){ +void print_records(EXPTYPE exponents[P], VALUETYPE ratios[K+1][P], index_t indeces[K+1][P]){ char s[STRING_SIZE]; format_results(s, exponents, ratios, indeces, FORMAT_TEXT); printf("%s\n",s); } -void print_latex_records_to_file(EXPTYPE exponents[P], VALUETYPE ratios[K+1][P], int indeces[K+1][P], char* filename){ +void print_latex_records_to_file(EXPTYPE exponents[P], VALUETYPE ratios[K+1][P], index_t indeces[K+1][P], char* filename){ char s[STRING_SIZE]; format_results(s, exponents, ratios, indeces, FORMAT_LATEX); @@ -434,7 +442,7 @@ void print_latex_records_to_file(EXPTYPE exponents[P], VALUETYPE ratios[K+1][P], fclose(fptr); } -typedef struct { EXPTYPE exponents[P]; VALUETYPE (*records_ratio)[K+1][P]; int (*records_index)[K+1][P]; int num_thread; int* domain_current; int* cont; } Args; +typedef struct { EXPTYPE exponents[P]; VALUETYPE (*records_ratio)[K+1][P]; index_t (*records_index)[K+1][P]; int num_thread; int* domain_current; int* cont; } Args; /*Goes through all functions indexed by those numbers which equal the thread number module NUM_THREADS.*/ void* compute_chunk(void* arguments){ @@ -466,7 +474,7 @@ int main() { pthread_t threads[NUM_THREADS]; Args args[NUM_THREADS]; VALUETYPE records_ratio[K+1][P]; - int records_index[K+1][P]; + index_t records_index[K+1][P]; for(int k=0; k<=K; k++) for(int p=0; p<P; p++) records_ratio[k][p] = int_to_valuetype(0); int domain_current = 0; int cont = 0; |
