10 #include <gsl/gsl_math.h>
11 #include <gsl/gsl_sf.h>
27 double PI = 3.141592653589793;
28 double *sbesselslag = (
double*)calloc(N*Nk,
sizeof(
double));
33 for(k = 0; k < Nk; k++){
34 for(n = 0; n < N; n++){
35 flk[k] += sqrt(2.0/PI) * fn[n] * sbesselslag[n * Nk + k];
71 void flag_sbesselslag(
double *sbesselslag,
int ell,
double *kvalues,
int Nk,
int N,
double tau)
74 long double hold, result, temp, y, fac, corrfac, f_jl2bis;
75 long double cw_jp, c_jp, w_jl, ktilde, a, b, c, z, f_jl2_even, f_jl2_odd, f_jl1_even, f_jl1_odd, f_jl0, f_jl1, f_jl2, T0, T1, T2;
76 long double PI = 3.141592653589793;
78 double *mulk_coefs = (
double*)calloc(N+2,
sizeof(
double));
79 long double *vals = (
double*)calloc(N,
sizeof(
long double));
81 for(k = 0; k < Nk; k++){
85 ktilde = tau * kvalues[k];
87 for(n = 0; n < N; n++){
90 for(j = 0; j <= n; j++){
93 m = (
long double)j / 2.0;
94 a = ((
long double)ell + 1) / 2.0;
95 b = (
long double)ell / 2.0 + 1;
96 c = (
long double)ell + 1.5;
97 z = - 4.0 * pow(ktilde, 2.0);
102 m = ((
long double)j - 1) / 2.0;
103 a = (
long double)ell / 2.0 + 1.0;
104 b = ((
long double)ell + 3) / 2.0;
105 c = (
long double)ell + 1.5;
106 z = - (
long double)4 * pow(ktilde, 2.0);
114 c_jp = ((
long double)n + 2) * (n + 1) / 2.0 ;
115 w_jl = sqrt(PI) * pow(ktilde, ell) * pow(tau, 3.0) * gsl_sf_fact(ell + 2) ;
118 f_jl1_even = pow(1-z,-a) * gsl_sf_hyperg_2F1_renorm(c-b,a,c,z/(z-1)) / corrfac;
119 f_jl2_even = pow(1-z, -a-1) * gsl_sf_hyperg_2F1_renorm(a+1, c-b-1, c, z/(z-1)) / corrfac;
121 sbesselslag[n * Nk + k] += pow((n+1)*(n+2), -0.5) * corrfac * pow(2,j+2) * fac * cw_jp * f_jl2 ;
122 printf(
"k=%f n=%i j=%i difference=%Le\n", kvalues[k], n, j, pow((n+1)*(n+2), -0.5) * corrfac * pow(2,j+2) * fac * cw_jp * f_jl2 );
125 fac = ((
long double)ell + 2 + j) * (-1) * ((
long double)n - j + 1.0) / ((
long double)j * (j + 2.0));
127 f_jl2_odd = pow(1-z, -b) * gsl_sf_hyperg_2F1_renorm(b, c-a, c, z/(z-1)) / corrfac;
128 f_jl1_odd = pow(1-z, -a-1) * gsl_sf_hyperg_2F1_renorm(a+1, c-b-1, c, z/(z-1)) / corrfac;
129 f_jl2bis = f_jl1_odd;
130 sbesselslag[n * Nk + k] += pow((n+1)*(n+2), -0.5) * corrfac * pow(2,j+1) * cw_jp * (f_jl2 + 2 * fac * f_jl2bis);
131 printf(
"k=%f n=%i j=%i difference=%Le\n", kvalues[k], n, j, pow((n+1)*(n+2), -0.5) * corrfac * pow(2,j+1) * cw_jp * (f_jl2 + 2 * fac * f_jl2bis) );
134 T0 = (c - a - m) * (c - b - m) * (c - a - b - 2*m - 1.0);
135 T1 = (c-a-b-2*m)*( c*(a+b-c+2*m) + c - 2*(a+m)*(b+m) + z*( (a+b+2*m)*(c-a-b-2*m) + 2*(a+m)*(b+m) - c + 1.0 ) );
136 T2 = (a + m) * (b + m) * (c - a - b - 2*m + 1.0) * pow(1 - z, 2.0) ;
138 f_jl2 = (-T1/T2) * f_jl1 + (-T0/T2) * f_jl0 ;
140 sbesselslag[n * Nk + k] += pow((n+1)*(n+2), -0.5) * corrfac * pow(2,j+2) * fac * cw_jp * f_jl2 ;
141 printf(
"k=%f n=%i j=%i difference=%Le\n", kvalues[k], n, j, pow((n+1)*(n+2), -0.5) * corrfac * pow(2,j+2) * fac * cw_jp * f_jl2 );
144 f_jl2bis = ( (-T1/T2) * f_jl1 + (-T0/T2) * f_jl0 ) ;
145 sbesselslag[n * Nk + k] += pow((n+1)*(n+2), -0.5) * corrfac * pow(2,j+1) * cw_jp * (f_jl2 + 2 * fac * f_jl2bis);
146 printf(
"k=%f n=%i j=%i difference=%Le\n", kvalues[k], n, j, pow((n+1)*(n+2), -0.5) * pow(2,j+1) * cw_jp * (f_jl2 + 2 * fac * f_jl2bis) );
150 cw_jp = fac * cw_jp ;
151 c_jp = - ((
long double)n - j + 1.0) / ((
long double)j * (j + 2.0)) * c_jp ;
152 w_jl = ((
long double)ell + 2 + j) * w_jl;
156 f_jl1_even = f_jl2_even;
159 f_jl1_odd = f_jl2_odd;
169 printf(
"sbesselslag[n * Nk + k] = %e\n", sbesselslag[n * Nk + k]);
180 void flag_mulk(
double *mulk,
int n,
int ell,
double k,
double tau)
182 double PI = 3.141592653589793;
184 double a, b, fac1, fac2, fac3, rec0, rec1, rec2;
185 double c = (double)ell + 1.5;
186 double ktilde = tau * k;
187 double d = - 4.0 * ktilde * ktilde;
188 double fac = pow(tau, 3.0) * sqrt(PI) * pow(ktilde, ell);
191 a = (ell + 1.0) / 2.0;
193 for(j = 0; j <= n/2; j++){
196 rec1 = pow(1-d, -b) * gsl_sf_hyperg_2F1_renorm(b, c-a, c, d/(d-1)) ;
201 rec0 = pow(1-d, -a-1) * gsl_sf_hyperg_2F1_renorm(a+1, c-b-1, c, d/(d-1)) ;
207 fac1 = (c-a-j+1)*(c-b-j+1)*(c-a-b-2*j+1) * rec2 ;
208 fac2 = (c-a-b-2*j+2)*( c*(a+b-c+2*j-2) + c - 2.0*(a+j-1)*(b+j-1)
209 + d*( (a+b+2*j-2)*(c-a-b-2*j+2) + 2.0*(a+j-1)*(b+j-1) - c + 1 ) ) * rec1 ;
210 fac3 = ( (a+j-1)*(b+j-1)*(c-a-b-2*j+3)*(1.0-d)*(1.0-d) );
211 rec0 = -1.0 * (fac1 + fac2) / fac3 ;
221 for(j = 0; j <= n/2-1; j++){
224 rec1 = pow(1-d, -b) * gsl_sf_hyperg_2F1_renorm(b, c-a, c, d/(d-1)) ;
229 rec0 = pow(1-d, -a-1) * gsl_sf_hyperg_2F1_renorm(a+1, c-b-1, c, d/(d-1)) ;
235 fac1 = (c-a-j+1)*(c-b-j+1)*(c-a-b-2*j+1) * rec2 ;
236 fac2 = (c-a-b-2*j+2)*( c*(a+b-c+2*j-2) + c - 2.0*(a+j-1)*(b+j-1)
237 + d*( (a+b+2*j-2)*(c-a-b-2*j+2) + 2.0*(a+j-1)*(b+j-1) - c + 1 ) ) * rec1 ;
238 fac3 = ( (a+j-1)*(b+j-1)*(c-a-b-2*j+3)*(1.0-d)*(1.0-d) );
239 rec0 = -1.0 * (fac1 + fac2) / fac3 ;
246 for(j = 0; j <= n; j++){
258 for (i = (array_size - 1); i > 0; i--)
260 for (j = 1; j <= i; j++)
262 if ( numbers[j-1] > numbers[j] )
265 numbers[j-1] = numbers[j];
276 double weight, hold, result, temp, y;
278 double *mulk_coefs = (
double*)calloc(N+2,
sizeof(
double));
279 double *vals = (
double*)calloc(N,
sizeof(
double));
281 for(k = 0; k < Nk; k++){
282 flag_mulk(mulk_coefs, N+2, ell, kvalues[k], tau);
283 for(n = 0; n < N; n++){
285 for(j = 0; j <= n; j++){
287 weight = pow(2, 2) * gsl_sf_fact(ell + 2) * (n + 1.0) * (n + 2.0) / 2.0 ;
289 weight = - 2 * (ell + 2 + j) * (n - j + 1) * weight / (j * (j + 2));
291 sbesselslag[n * Nk + k] += pow((n+1)*(n+2), -0.5) * weight * mulk_coefs[j+2] ;
292 printf(
" %3.0e ",weight);
293 vals[j] = pow((n+1)*(n+2), -0.5) * ( weight * mulk_coefs[j+2] );
295 result = 0.0, hold = 0.0, temp = 0.0, y = 0.0;
296 for(j = 0; j <= n/2; j++){
298 y = (vals[2*j] + vals[2*j+1]) - hold;
300 hold = (temp - result) - y;
303 y = vals[2*j] - hold;
305 hold = (temp - result) - y;
331 sbesselslag[n * Nk + k] = result ;
354 double hold, result, temp, y;
355 double c_jp, w_jl, ktilde, a, b, c, z, f_jl2_even, f_jl2_odd, f_jl1_even, f_jl1_odd, f_jl0, f_jl1, f_jl2, T0, T1, T2;
356 double PI = 3.141592653589793;
358 double *mulk_coefs = (
double*)calloc(N+2,
sizeof(
double));
359 double *vals = (
double*)calloc(N,
sizeof(
double));
361 for(k = 0; k < Nk; k++){
363 flag_mulk(mulk_coefs, N+2, ell, kvalues[k], tau);
365 ktilde = tau * kvalues[k];
367 for(n = 0; n < N; n++){
369 printf(
"\n n = %i", n);
371 for(j = 0; j <= n; j++){
378 z = - 4.0 * pow(ktilde, 2.0);
383 m = ((double)j - 1) / 2.0;
384 a = (double)ell / 2.0 + 1.0;
385 b = ((double)ell + 3) / 2.0;
386 c = (double)ell + 1.5;
387 z = - (double)4 * pow(ktilde, 2.0);
394 c_jp = (n + 2) * (n + 1) / 2.0 ;
395 w_jl = 4 * sqrt(PI) * pow(ktilde, ell) * pow(tau, 1.5) * gsl_sf_fact(ell + 2) ;
396 f_jl1_even = pow(1-z, -b) * gsl_sf_hyperg_2F1_renorm(b, c-a, c, z/(z-1));
397 f_jl2_even = pow(1-z, -a-1) * gsl_sf_hyperg_2F1_renorm(a+1, c-b-1, c, z/(z-1));
400 c_jp = - (n - j + 1) * c_jp / (j * (j + 2));
401 w_jl = 2 * (ell + 2 + j) * w_jl;
403 f_jl2_odd = pow(1-z, -b) * gsl_sf_hyperg_2F1_renorm(b, c-a, c, z/(z-1));
404 f_jl1_odd = pow(1-z, -a-1) * gsl_sf_hyperg_2F1_renorm(a+1, c-b-1, c, z/(z-1)) ;
408 T0 = (c - a - m) * (c - b - m) * (c - a - b - 2*m - 1.0);
409 T1 = (c-a-b-2*m)*( c*(a+b-c+2*m) + c - 2*(a+m)*(b+m) + z*( (a+b+2*m)*(c-a-b-2*m) + 2*(a+m)*(b+m) - c + 1.0 ) );
410 T2 = (a + m) * (b + m) * (c - a - b - 2*m + 1.0) * pow(1 - z, 2.0) ;
411 f_jl2 = (-T1/T2) * f_jl1 + (-T0/T2) * f_jl0 ;
415 f_jl1_even = f_jl2_even;
418 f_jl1_odd = f_jl2_odd;
422 vals[j] = c_jp * w_jl * f_jl2 ;
423 printf(
"\n c_jp = %e w_jl = %e f_jl2 = %e mu = %e val = %f", c_jp, w_jl, f_jl2);
424 sbesselslag[n * Nk + k] += vals[j];
425 sbesselslag[n * Nk + k] *= pow((n+1)*(n+2), -0.5);
460 long double hold, result, temp, y, fac, corrfac, f_jl2bis;
461 long double cw_jp, c_jp, w_jl, ktilde, a, b, c, z, f_jl2_even, f_jl2_odd, f_jl1_even, f_jl1_odd, f_jl0, f_jl1, f_jl2, T0, T1, T2;
462 long double PI = 3.141592653589793;
464 double *mulk_coefs = (
double*)calloc(N+2,
sizeof(
double));
465 long double *vals = (
double*)calloc(N,
sizeof(
long double));
467 for(k = 0; k < Nk; k++){
471 ktilde = tau * kvalues[k];
473 for(n = 0; n < N; n++){
477 for(j = 0; j <= n; j++){
480 m = (
long double)j / 2.0;
481 a = ((
long double)ell + 1) / 2.0;
482 b = (
long double)ell / 2.0 + 1;
483 c = (
long double)ell + 1.5;
484 z = - 4.0 * pow(ktilde, 2.0);
489 m = ((
long double)j - 1) / 2.0;
490 a = (
long double)ell / 2.0 + 1.0;
491 b = ((
long double)ell + 3) / 2.0;
492 c = (
long double)ell + 1.5;
493 z = - (
long double)4 * pow(ktilde, 2.0);
501 c_jp = ((
long double)n + 2) * (n + 1) / 2.0 ;
502 w_jl = sqrt(PI) * pow(ktilde, ell) * pow(tau, 3.0) * gsl_sf_fact(ell + 2) ;
505 f_jl1_even = pow(1-z,-a) * gsl_sf_hyperg_2F1_renorm(c-b,a,c,z/(z-1)) / corrfac;
506 f_jl2_even = pow(1-z, -a-1) * gsl_sf_hyperg_2F1_renorm(a+1, c-b-1, c, z/(z-1)) / corrfac;
509 fac = ((
long double)ell + 2 + j) * (-1) * ((
long double)n - j + 1.0) / ((
long double)j * (j + 2.0));
511 f_jl2_odd = pow(1-z, -b) * gsl_sf_hyperg_2F1_renorm(b, c-a, c, z/(z-1)) / corrfac;
512 f_jl1_odd = pow(1-z, -a-1) * gsl_sf_hyperg_2F1_renorm(a+1, c-b-1, c, z/(z-1)) / corrfac;
513 f_jl2bis = f_jl1_odd;
514 sbesselslag[n * Nk + k] += pow((n+1)*(n+2), -0.5) * corrfac * pow(2,j+1) * cw_jp * (f_jl2 + 2 * fac * f_jl2bis);
517 T0 = (c - a - m) * (c - b - m) * (c - a - b - 2*m - 1.0);
518 T1 = (c-a-b-2*m)*( c*(a+b-c+2*m) + c - 2*(a+m)*(b+m) + z*( (a+b+2*m)*(c-a-b-2*m) + 2*(a+m)*(b+m) - c + 1.0 ) );
519 T2 = (a + m) * (b + m) * (c - a - b - 2*m + 1.0) * pow(1 - z, 2.0) ;
521 f_jl2 = (-T1/T2) * f_jl1 + (-T0/T2) * f_jl0 ;
523 sbesselslag[n * Nk + k] += pow((n+1)*(n+2), -0.5) * corrfac * pow(2,j+2) * fac * cw_jp * f_jl2 ;
526 f_jl2bis = ( (-T1/T2) * f_jl1 + (-T0/T2) * f_jl0 ) ;
527 sbesselslag[n * Nk + k] += pow((n+1)*(n+2), -0.5) * corrfac * pow(2,j+1) * cw_jp * (f_jl2 + 2 * fac * f_jl2bis);
528 printf(
"n=%i j=%i difference=%Le\n", n, j, pow((n+1)*(n+2), -0.5) * pow(2,j+1) * cw_jp * (f_jl2 + 2 * fac * f_jl2bis) );
532 cw_jp = fac * cw_jp ;
533 c_jp = - ((
long double)n - j + 1.0) / ((
long double)j * (j + 2.0)) * c_jp ;
534 w_jl = ((
long double)ell + 2 + j) * w_jl;
538 f_jl1_even = f_jl2_even;
541 f_jl1_odd = f_jl2_odd;
552 printf(
"sbesselslag[n * Nk + k] = %e\n", sbesselslag[n * Nk + k]);
void flag_sbesselslag(double *sbesselslag, int ell, double *kvalues, int Nk, int N, double tau)
void flag_mulk(double *mulk, int n, int ell, double k, double tau)
void flag_sbesselslag_backup2(double *sbesselslag, int ell, double *kvalues, int Nk, int N, double tau)
void flag_spherlaguerre2spherbessel(double *flk, const double *fn, double *kvalues, int Nk, int N, int ell, double tau)
void flag_fourierlaguerre2fourierbessel(complex double *flmk, complex double *flmn, double *kvalues, int Nk, int N, int L, double tau)
void flag_sbesselslag_backup3(double *sbesselslag, int ell, double *kvalues, int Nk, int N, double tau)
void flag_sbesselslag_backup(double *sbesselslag, int ell, double *kvalues, int Nk, int N, double tau)
void bubbleSort(double numbers[], int array_size)