FUNCTION
log_binomial
Calculates the logarithm of the binomial coefficient with given arguments.
Interface
#include <codecogs/maths/combinatorics/arithmetic/log_binomial.h>
using namespace Maths::Combinatorics::Arithmetic;
This function calculates the following expression
(1)
In the given example, values of this function are returned for various arguments. The algorithm is designed in such a way to permit large values of the arguments, without creating overflow errors during the calculations. The example also demonstrates this feature, with n equal to 100 and k taking values from 70 up to 80.
Example 1
#include <codecogs/maths/combinatorics/arithmetic/log_binomial.h>
#include <iostream>
#include <iomanip>
int main()
{
std::cout << std::setprecision(10);
for (int i = 70; i <= 80; i++)
{
std::cout << "log_binomial(100, " << i << ") = ";
std::cout << Maths::Combinatorics::Arithmetic::log_binomial(100, i);
std::cout << std::endl;
}
return 0;
}Output
log_binomial(100, 70) = 58.64209564
log_binomial(100, 71) = 57.78061315
log_binomial(100, 72) = 56.87124286
log_binomial(100, 73) = 55.91298793
log_binomial(100, 74) = 54.9047597
log_binomial(100, 75) = 53.84536812
log_binomial(100, 76) = 52.73351061
log_binomial(100, 77) = 51.56775902
log_binomial(100, 78) = 50.34654441
log_binomial(100, 79) = 49.06813901
log_binomial(100, 80) = 47.73063481Parameters
n
the first argument of the binomial coefficient (the number of objects)
k
the second argument of the binomial coefficient (the number of choices)
Returns
the logarithm of the binomial coefficient with given arguments n and k
Interactive Calculator
n
k
Result
Computing…
Set a range above first to export a graph.
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.