#include #include #include //for multithreading #include #include #include //getLine #include "misc.h" #define DOUBLEMODE 0 #define DOUBLEERRORMODE 1 #define RATIOMODE 2 #ifndef MODE #define MODE DOUBLEMODE #endif #define NUM_THREADS 7 #if MODE == DOUBLEERRORMODE #include "double-error.h" #define VALUETYPE double_error #define EXPTYPE double_error #elif MODE == RATIOMODE #include "ratio.h" #define VALUETYPE rational #define EXPTYPE unsigned int #else #include "double.h" #define VALUETYPE double #define EXPTYPE double #endif #define STRING_SIZE 65536 /*maximum length of the support of f*/ #define N 32 /*maximal order of derivative*/ #define K 32 /*maximal number of exponents*/ #define P 5 /*given function df[0] on domain [0,M-1], compute derivatives f' until f^{(K)} and store f^{(K)} in df*/ void differentiate(VALUETYPE* f, VALUETYPE* df, int D, int k){ VALUETYPE df0[D]; /*Set zeroth derivative to be f.*/ for(int i=0; i0; l--) { for(int i=0; i= powd){ s += powd; d++; } else { int t = i-s; /*Set f to the values encoded in bit string t which is a value between 1 and powd = (1<> n) & 1); return d+2; } } return -1; } int generate_triangle(VALUETYPE* f, int i){ int j = i+1; if(j <= N/2){ for(int n=0; n < N; n++) f[n] = int_to_valuetype(0); for(int n=0; n < j; n++) f[n] = int_to_valuetype(j-n); for(int n=1; n < j; n++) f[N-n] = int_to_valuetype(j-n); return N; } else return -1; } int generate_random(VALUETYPE* f, int 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); return N; } /*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){ return generate_each_charf(f,i); //return generate_random(f,i); //return generate_triangle(f,i); } #define FORMAT_TEXT 0 #define FORMAT_LATEX 1 void format_result(char* s, int index, int k, EXPTYPE p, VALUETYPE r, int format){ VALUETYPE f[N]; int d = generate_function(f,index); if(format == FORMAT_TEXT){ strcpy(s,"f: "); int l = 3; for(int i=0; i=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]){ VALUETYPE f[N]; int D = generate_function(f,index); /*Immediately abort if index is out of bounds.*/ if(D <= 0) return D; VALUETYPE Mf[N]; /*This is the only O(D^2) operation in here so makes a lot of sense to only compute once and avoid repeating it.*/ compute_maximalfunction(f,Mf,D); /*Allocate memory for derivatives.*/ VALUETYPE df[2][N]; VALUETYPE dMf[2][N]; for(int i=0; i<=1; i++){ for(int n=0; n=1){ /*Compute kth derivative of f and Mf from (k-1)th derivative*/ differentiate(df[(k+1)%2],df[k%2],D,1); differentiate(dMf[(k+1)%2],dMf[k%2],D,1); } for(int p=0; p num_thread; int* domain_current = args -> domain_current; int d = 0; while(d >= 0){ d = compute(i, args -> exponents, args -> records_ratio, args -> records_index); if(d > *domain_current){ *domain_current = d; printf("Start considering length: %d\n",d); } i += NUM_THREADS; } (*(args -> cont))++; if(*(args -> cont) >= NUM_THREADS) printf("Calculation finished. Press any button to stop.\n"); return NULL; } int main() { EXPTYPE exponents[P]; exponents[0] = int_to_exptype(1); exponents[1] = int_to_exptype(2); exponents[2] = int_to_exptype(4); exponents[3] = int_to_exptype(8); exponents[4] = infinity_to_exptype(); pthread_t threads[NUM_THREADS]; Args args[NUM_THREADS]; VALUETYPE records_ratio[K+1][P]; int records_index[K+1][P]; for(int k=0; k<=K; k++) for(int p=0; p