summaryrefslogtreecommitdiff
path: root/charf.c
diff options
context:
space:
mode:
authorJulian Weigt <juw@posteo.de>2026-01-09 17:13:57 +0000
committerJulian Weigt <juw@posteo.de>2026-02-04 15:55:51 +0100
commitde4326889c83ebebc8d880e2b4331dfa9d462674 (patch)
tree2cfb1ae6d30912772150098b8a40f3e174f4706f /charf.c
parent81eb3bc9abce433d9324badc40bf1b7ce6f24baf (diff)
Improve formulations and abstraction in c code.
Diffstat (limited to 'charf.c')
-rw-r--r--charf.c85
1 files changed, 18 insertions, 67 deletions
diff --git a/charf.c b/charf.c
index 97bc2a5..17b4b08 100644
--- a/charf.c
+++ b/charf.c
@@ -58,7 +58,7 @@ 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*/
VALUETYPE integratep(VALUETYPE* f, EXPTYPE p, int D){
VALUETYPE integralp = int_to_valuetype(0);
- for(int i=0;i<D;i++){
+ for(int i=0; i<D; i++){
VALUETYPE padd = power(absolute(f[i]),p);
integralp = sum(integralp,padd);
}
@@ -73,9 +73,9 @@ void compute_maximalfunction(VALUETYPE* f, VALUETYPE* Mf, int D){
/*Apparently may become too big for stack or something so have to use malloc instead.*/
VALUETYPE* Sf[N];
VALUETYPE* Af[N];
- for(int i=0; i<D;i++){
- Sf[i] = malloc(N*sizeof(VALUETYPE));
- Af[i] = malloc(N*sizeof(VALUETYPE));
+ for(int i=0; i<D; i++){
+ Sf[i] = malloc(D*sizeof(VALUETYPE));
+ Af[i] = malloc(D*sizeof(VALUETYPE));
}
for(int i=0; i<D; i++) {
@@ -112,11 +112,15 @@ void compute_maximalfunction(VALUETYPE* f, VALUETYPE* Mf, int D){
*/
for(int i=0; i<D; i++){
- free(Sf[i]);
free(Af[i]);
+ free(Sf[i]);
}
}
+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) ;
+}
+
void compute(EXPTYPE p, int D, VALUETYPE* f, VALUETYPE* records){
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.*/
@@ -126,14 +130,13 @@ void compute(EXPTYPE p, int D, VALUETYPE* f, VALUETYPE* records){
VALUETYPE df[2][N];
VALUETYPE dMf[2][N];
- for(int i=0; i<D; i++){
- df[1][i] = f[i];
- df[0][i] = f[i];
- dMf[0][i] = Mf[i];
- dMf[1][i] = Mf[i];
- }
+ for(int i=0; i<=1; i++){
+ for(int n=0; n<D; n++){
+ df[i][n] = f[n];
+ dMf[i][n] = Mf[n];
+ }
- VALUETYPE tmp[N];
+ }
for(int k=1; k<=K; k++){
/*Compute kth derivative of f and Mf from (k-1)th derivative*/
@@ -163,59 +166,7 @@ void compute(EXPTYPE p, int D, VALUETYPE* f, VALUETYPE* records){
VALUETYPE r = ratio(intdMfp, intdfp);
double t = to_double(r);
- if(
- (
- (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)
- )
- &&
- (is_greater(r,records[k]))
- ){
+ if(over_threshold_charf(t,k) && is_greater(r,records[k])){
/*extra check for printing only because in error mode for some reason floats randomly seem to increase by tiny amounts*/
if(t>to_double(records[k])){
char s[256];
@@ -269,8 +220,8 @@ void* compute_chunk(void* arguments){
VALUETYPE f[N];
int d = generate_function(f,i);
while(d >= 0){
- if(d>*domain_current){
- *domain_current=d;
+ if(d > *domain_current){
+ *domain_current = d;
printf("Start considering length: %d\n",d);
}
compute(p,d,f,records);