I need to initialize a vector with the binomial coefficients. The code is like the following: for(size_t i=1; i<n;i++){ nl[i]=cln::binomial(m,m-i); } where are involved very big number, something like m=10^10 and n=10^6. My purpose is to optimize the preceding optimization by using the result of the preceding iteration, i.e. binomial(n, n-(i+1))=binomial(n, i)* (n-i)/(i+1) I tried to implement the multiplication by storing the result of of (n-i)/(i+1) in one cl_RA number, but unfortunately the performance are worst than the direct calculation. Do you have any idea how to initialize efficiently this vector? Thank you for your help, Silvestre Abruzzo
Hi, Silvestre Abruzzo wrote:
binomial(n, n-(i+1))=binomial(n, i)* (n-i)/(i+1)
I tried to implement the multiplication by storing the result of of (n-i)/(i+1) in one cl_RA number, but unfortunately the performance are worst than the direct calculation.
It should be faster if you write it as (binomial(n, i) * (n-i)) / (i+1) The multiplication is a multiplication of integers, and the division can be written as an 'exquo' call. Bruno
participants (2)
-
Bruno Haible
-
Silvestre Abruzzo