compute_binomial_coefficients Subroutine

private subroutine compute_binomial_coefficients()

Calculate binomial coefficients using recursive algorithm by Sten Rettrup and Ruben Pauncz, Int. J. Quantum Chem., 60: 91–98 (1996) DOI: 10.1002/(SICI)1097-461X(1996)60:1<91::AID-QUA10>3.0.CO;2-A

Arguments

None

Contents


Source Code

subroutine compute_binomial_coefficients()

    integer :: i, j
    integer :: n, k, nk
    real(dp), dimension(0:3*MAX_ORDER) :: weights

    do n = 0, 3*MAX_ORDER
        do k = 0, MAX_ORDER
            if (k == n .or. k == 0) then
                binomial(n,k) = 1.0_dp
            end if
            weights(:) = 0.0_dp
            nk = n - k
            do i = 0, nk
                weights(i) = 1.0_dp
            end do
            do i = 1, k
                binomial(n,k) = 0.0_dp
                do j = 0, nk
                    binomial(n,k) = binomial(n,k) + weights(j)
                    weights(j) = binomial(n,k)
                end do
            end do
        end do
    end do

end subroutine compute_binomial_coefficients