coeffs.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #include "coeffs.hpp"
  2. //*****************************
  3. //* Defintion of externs data *
  4. //****************************
  5. Reel coeffs[num_coeffs];
  6. fmpz_poly_t coeffs_poly[num_coeffs];
  7. fmpz_t coeffs_den;
  8. //******************
  9. //* compute_coeffs *
  10. //******************
  11. void compute_coeffs(){
  12. CoeffAnalytic ca[num_coeffs];
  13. for(size_t i=0;i<num_coeffs;++i){
  14. fmpz_poly_init(coeffs_poly[i]);
  15. fmpq_init(ca[i].a);
  16. fmpq_init(ca[i].b);
  17. }
  18. //C_(0,0)=0
  19. fmpq_zero(ca[pos(0,0)].a);
  20. fmpq_zero(ca[pos(0,0)].b);
  21. //C_(0,1)=-1
  22. fmpq_set_si(ca[pos(0,1)].a,-1,1);
  23. fmpq_zero(ca[pos(0,1)].b);
  24. //Compute C_(i,i)
  25. fmpq_t r,t,q;
  26. fmpq_init(r);
  27. fmpq_init(t);
  28. fmpq_init(q);
  29. fmpq_zero(r);
  30. fmpq_set_si(q,-4,1);
  31. for(size_t i=1;i<=max_ind_coeffs;++i){
  32. fmpq_set_si(t,1,2*i-1);
  33. fmpq_add(r,r,t);
  34. fmpq_zero(ca[pos(i,i)].a);
  35. fmpq_mul(t,r,q);
  36. fmpq_set(ca[pos(i,i)].b,t);
  37. }
  38. fmpz_init(coeffs_den);
  39. fmpz_set(coeffs_den,fmpq_denref(ca[pos(max_ind_coeffs,max_ind_coeffs)].b));
  40. for(size_t j=2;j<=max_ind_coeffs;++j){
  41. //C(0,j)=4*C(0,j-1)-C(0,j-2)-2*C(1,j-1)
  42. fmpq* dest=ca[pos(0,j)].a;
  43. fmpq_zero(dest);
  44. fmpq_add(dest,ca[pos(0,j-1)].a,ca[pos(0,j-1)].a);
  45. fmpq_sub(dest,dest,ca[pos(1,j-1)].a);
  46. fmpq_add(dest,dest,dest);
  47. fmpq_sub(dest,dest,ca[pos(0,j-2)].a);
  48. dest=ca[pos(0,j)].b;
  49. fmpq_zero(dest);
  50. fmpq_add(dest,ca[pos(0,j-1)].b,ca[pos(0,j-1)].b);
  51. fmpq_sub(dest,dest,ca[pos(1,j-1)].b);
  52. fmpq_add(dest,dest,dest);
  53. fmpq_sub(dest,dest,ca[pos(0,j-2)].b);
  54. for(size_t i=1;i<=j-2;++i){
  55. //C(i,j)=4*C(i,j-1)-C(i,j-2)-C(i-1,j-1)-C(i+1,j-1)
  56. fmpq_set_si(r,4,1);
  57. dest=ca[pos(i,j)].a;
  58. fmpq_zero(dest);
  59. fmpq_mul(dest,r,ca[pos(i,j-1)].a);
  60. fmpq_sub(dest,dest,ca[pos(i,j-2)].a);
  61. fmpq_sub(dest,dest,ca[pos(i-1,j-1)].a);
  62. fmpq_sub(dest,dest,ca[pos(i+1,j-1)].a);
  63. dest=ca[pos(i,j)].b;
  64. fmpq_zero(dest);
  65. fmpq_mul(dest,r,ca[pos(i,j-1)].b);
  66. fmpq_sub(dest,dest,ca[pos(i,j-2)].b);
  67. fmpq_sub(dest,dest,ca[pos(i-1,j-1)].b);
  68. fmpq_sub(dest,dest,ca[pos(i+1,j-1)].b);
  69. }
  70. //C(j-1,j)=2*C(j-1,j-1)-C(j-2,j-1)
  71. dest=ca[pos(j-1,j)].a;
  72. fmpq_zero(dest);
  73. fmpq_add(dest,ca[pos(j-1,j-1)].a,ca[pos(j-1,j-1)].a);
  74. fmpq_sub(dest,dest,ca[pos(j-2,j-1)].a);
  75. dest=ca[pos(j-1,j)].b;
  76. fmpq_zero(dest);
  77. fmpq_add(dest,ca[pos(j-1,j-1)].b,ca[pos(j-1,j-1)].b);
  78. fmpq_sub(dest,dest,ca[pos(j-2,j-1)].b);
  79. }
  80. fmpz_t temp;
  81. fmpz_init(temp);
  82. for(size_t i=0;i<num_coeffs;++i){
  83. fmpz_mul(temp,fmpq_numref(ca[i].a),coeffs_den);
  84. fmpz_divexact(temp,temp,fmpq_denref(ca[i].a));
  85. fmpz_poly_set_coeff_fmpz(coeffs_poly[i],0,temp);
  86. fmpz_mul(temp,fmpq_numref(ca[i].b),coeffs_den);
  87. fmpz_divexact(temp,temp,fmpq_denref(ca[i].b));
  88. fmpz_poly_set_coeff_fmpz(coeffs_poly[i],1,temp);
  89. }
  90. }