From b54caf5830bc5d67d403dadd4903c5a54ec91eb0 Mon Sep 17 00:00:00 2001 From: Julian Weigt Date: Mon, 9 Feb 2026 15:12:35 +0100 Subject: Add more comments to code. --- charf.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 71 insertions(+), 25 deletions(-) diff --git a/charf.c b/charf.c index 1948971..6908832 100644 --- a/charf.c +++ b/charf.c @@ -12,12 +12,16 @@ #define DOUBLEERRORMODE 1 #define RATIOMODE 2 +/*Determines if computations are done with floating point type, floating point with error bounds or fractions. +Floating point without error bounds are the default.*/ #ifndef MODE #define MODE DOUBLEMODE #endif +/*number of threads for parallel execution.*/ #define NUM_THREADS 7 +/*Make sure the appropriate files are included for the type of computation and sets the data types accordingly.*/ #if MODE == DOUBLEERRORMODE #include "double-error.h" #define VALUETYPE double_error @@ -36,7 +40,7 @@ typedef unsigned long index_t; -/*maximum length of the support of f*/ +/*maximum length of the circle*/ #define N 36 /*maximal order of derivative*/ @@ -45,7 +49,7 @@ typedef unsigned long index_t; /*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*/ +/*Given function f on domain [0,D-1], compute derivative of order k and store result in df.*/ void differentiate(VALUETYPE* f, VALUETYPE* df, int D, int k){ VALUETYPE df0[D]; /*Set zeroth derivative to be f.*/ @@ -66,7 +70,8 @@ void differentiate(VALUETYPE* f, VALUETYPE* df, int D, int k){ */ } -/*given function f on domain [0,D-1] compute pth root of integral of |f|^p*/ +/*Given function f on domain [0,D-1] compute pth root of integral of |f|^p.*/ +/*For p=∞ instead compute the maximum, i.e. ||f||_∞.*/ VALUETYPE integratep(VALUETYPE* f, EXPTYPE p, int D){ VALUETYPE integralp = int_to_valuetype(0); for(int i=0; i0; l--) { + /*Go through all intervals [i,i+l).*/ for(int i=0; iD it suffices to go until i+D-1.*/ + int intervalend = fmin(i+l,i+D); int n=i; - while(n= powd){ + /*Increment s,d,powd to correspond to functions of length d+1.*/ s += powd; d++; powd = powd << 1; } + /*If our index i corresponds to a function on a circle of length larger than N then return -1 which will causo the program to stop.*/ if(d>N) return -1; - /*t starts with 1, then comes i-s and then 0.*/ + /*t encodes a characteristic function on the circle of length d. + Since we only consider functions with f[0]=0 and f[d-1]=1, set its places accordingly.*/ index_t t = ( (i-s) << 1 ) + 1UL; - /*Indicates if we want to consider this t.*/ + /*This variable indicates if we want to consider this t. + Next we will perform test to determine if it should be set to false.*/ bool is_representative = true; - /*Check if t encodes a function that is made up of translations of a shorter function.*/ + /*Check if t encodes a function that is made up of multiple copies of a shorter function. + We skip those because they and their maximal function are periodic and thus should be considered on a smaller circle instead.*/ + /*Go through all possible lenghts r of that shorter function.*/ for(int r = 1; r < d; r++){ + /*r has to be a divisor of d.*/ if(d % r == 0){ bool is_r_copy = true; + /*bit mask of length r*/ index_t ones = 0; for(int o = 0; o>n*r) & ones ) != tail ) is_r_copy = false; if(is_r_copy) is_representative = false; } } - /*Check if t encodes the strictly largest of its equivalent translates.*/ - /*Such t which may equal its translates have already been filtered out by the previous step because they are copies of at least two shorter functions.*/ - index_t ones = 0; - for(int o = 0; o= ( (t<>(d-n)) & ones) ) is_representative = false; + /*We aim to filter out equivalent translates. + The representative we pick is the one which represents the smallest integer. + Every function which is a nontrivial translate of itself must in fact consist of multiplie copies of a shorter array (right?). + Those we already filtered out in the previous step, so every nontrivial translate of that representative indeed represents a strictly smaller integer. + */ + if(is_representative){ + index_t ones = 0; + for(int o = 0; o= ( (t<>(d-n)) & ones) ) is_representative = false; + } - /*Set f to the values encoded in bit string t which is a value between 1 and powd = (1<> n) & 1UL); return d; -- cgit v1.2.3