-
Notifications
You must be signed in to change notification settings - Fork 0
/
baker.C
123 lines (102 loc) · 2.03 KB
/
baker.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
/*
* baker.C
*
* Show invariants and eigenvectors of Baker's map.
*
* Linas Vepstas Sept 2006
*/
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "brat.h"
/* Ising model nerest-neighbor interaction */
double ising(double x, double y)
{
/* higher energy if pair of spins is aligned, else, energy is lower */
if ((x<0.25) || (x>=0.75)) return 0.3;
return -0.3;
}
double parabola(double x, double y)
{
x -= 0.5;
y -= 0.5;
return 1.5*(x*x+y*y-0.125);
}
double b1(double x, double y)
{
return y-0.5;
}
/* =============================================================== */
static int niter=10;
static double tee = 0.3;
void backshift (double *re, double *im,
double x, double y)
{
int i;
double hre = 0.0;
double him = 0.0;
/* shift right */
for (i=0; i<niter+1; i++)
{
int ty = (int) floor(2.0*y);
x = 0.5*(x+ty);
y = 2.0*y-ty;
}
/* Bernoulli_1(x) */
// hre = x - 0.5;
// hre = x*x - x + 1.0/6.0;
hre = x*x*x - 1.5*x*x + 0.5*x;
// hre = x*x*x*x - 2.0*x*x*x + x*x - 1.0/30.0;
*re = hre;
*im = him;
}
void eigenvec (double *re, double *im, double (*func)(double, double),
double x, double y)
{
int i;
double hre = 0.0;
double him = 0.0;
double xo = x;
double yo = y;
double w = 1.0;
#if 1
/* shift right */
for (i=0; i<niter+1; i++)
{
// w = 1.0/(i-tee);
hre += w*func (x,y);
int ty = (int) floor(2.0*y);
x = 0.5*(x+ty);
y = 2.0*y-ty;
}
#endif
/* shift left */
x = yo;
y = xo;
for (i=0; i<niter; i++)
{
int ty = (int) floor(2.0*y);
x = 0.5*(x+ty);
y = 2.0*y-ty;
// w = 1.0/(-(i+1)-tee);
hre += w*func (y,x);
w *= tee;
}
*re = hre;
*im = him;
}
static double
density (double x, double y, int itermax, double param)
{
double re, im;
niter = itermax;
tee = param;
// eigenvec (&re, &im, ising, x, y);
// eigenvec (&re, &im, parabola, x, y);
// eigenvec (&re, &im, b1, x, y);
backshift (&re, &im, x, y);
// re = exp (-re);
return re;
}
DECL_MAKE_HEIGHT(density);
/* --------------------------- END OF LIFE ------------------------- */