-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhardy.C
151 lines (117 loc) · 2.8 KB
/
hardy.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* hardy.C
*
* Poisson integral of the Minkowski measure (i.e. of the
* distribution of the Farey Numbers on the unit interval)
* The Poisson ingtegral takes the form of a so-called
* "singular inner function" in the theory of Hardy spaces.
*
* See directory fractal/experiments/fdist for more details.
*
* Linas October 2004
* Linas October 2008
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "brat.h"
#include "Farey.h"
#include "FareyTree.h"
static int nbins = 0;
static double *bin, *si, *co;
void bincount(int nb, int depth)
{
int i;
int max = 1 << depth;
FareyIterator fi;
bin = (double *) malloc (nbins * sizeof (double));
for (i=0; i<nbins; i++)
{
bin[i] = 0.0;
}
bin[0] = 1.0;
bin[nbins-1] = 1.0;
/* Compute the distribution by bining */
int cnt = 2;
for (i=0; i<max; i++)
{
int n,d;
fi.GetNextFarey (&n, &d);
// GetNextDyadic (&n, &d);
double x = ((double) n)/ ((double) d);
x *= nbins;
int ib = (int) x;
bin [ib] += 1.0;
cnt ++;
}
/* renormalize */
for (i=0; i<nbins; i++)
{
bin[i] *= ((double) nbins) / ((double) cnt);
}
}
static void init(int nb)
{
int i;
nbins = nb;
bincount(nb, 18); // XXX hardcoded depth
si = (double *) malloc (nbins * sizeof (double));
co = (double *) malloc (nbins * sizeof (double));
ContinuedFraction f;
for (i=0; i<nbins; i++)
{
/* x is the midpoint of the bin */
double x = ((double) 2*i+1) / ((double) 2*nbins);
/* Likewise, the midpoint */
f.SetRatio (2*i+1, 2*nbins);
double far = f.ToFarey ();
far = x;
si[i] = sin(2.0*M_PI*far);
co[i] = cos(2.0*M_PI*far);
if(i%2==0) bin[i]=2000.0; else bin[i] = -2000.0;
}
}
void hardy(double re, double im, double *reh, double *imh)
{
int i;
/* Compute the integral of the distribution */
double resum = 0.0;
double imsum = 0.0;
for (i=0; i<nbins; i++)
{
double red = co[i] - re;
double imd = si[i] - im;
double deno = red*red + imd*imd;
double ren = co[i] + re;
double imn = si[i] + im;
double regr = ren*red + imn*imd;
double imgr = imn*red - imd*ren;
regr /= deno;
imgr /= deno;
double distrib = bin[i];
// distrib = 1.0;
resum += regr * distrib;
imsum += imgr * distrib;
}
/* renormalize */
resum /= (double) nbins;
imsum /= (double) nbins;
*reh = resum;
*imh = imsum;
}
static double hardy_series (double re_q, double im_q, int itermax, double param)
{
double rep, imp;
rep = re_q;
imp = im_q;
if (0 == nbins) init(itermax);
hardy (re_q, im_q, &rep, &imp);
// if (1.0 < re_q*re_q+im_q*im_q) rep += 1.0;
// else rep -= 1.0;
// printf("duude q=%g f(q)= (%g %g)\n", re_q*re_q+im_q*im_q, rep, imp);
// return sqrt (rep*rep+imp*imp);
// return rep;
return (atan2 (imp,rep)+M_PI)/(2.0*M_PI);
}
DECL_MAKE_HEIGHT(hardy_series);
/* --------------------------- END OF LIFE ------------------------- */