README.md (4687B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Logarithm of Binomial Coefficient 22 23 > Compute the natural logarithm of the [binomial coefficient][binomial-coefficient]. 24 25 <section class="intro"> 26 27 The natural logarithm of the [binomial coefficient][binomial-coefficient] is 28 29 <!-- <equation class="equation" label="eq:binomcoefln_function" align="center" raw="f(n,k) = \ln {n \choose k}" alt="Natural logarithm of the binomial coefficient."> --> 30 31 <div class="equation" align="center" data-raw-text="f(n,k) = \ln {n \choose k}" data-equation="eq:binomcoefln_function"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/binomcoefln/docs/img/equation_binomcoefln_function.svg" alt="Natural logarithm of the binomial coefficient."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 The [binomial coefficient][binomial-coefficient] of two nonnegative integers `n` and `k` is defined as 39 40 <!-- <equation class="equation" label="eq:binomial_coefficient" align="center" raw="\binom {n}{k} = \frac{n!}{k!\,(n-k)!} \quad \text{for }\ 0\leq k\leq n" alt="Factorial formula for the Binomial coefficient."> --> 41 42 <div class="equation" align="center" data-raw-text="\binom {n}{k} = \frac{n!}{k!\,(n-k)!} \quad \text{for }\ 0\leq k\leq n" data-equation="eq:binomial_coefficient"> 43 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/binomcoefln/docs/img/equation_binomial_coefficient.svg" alt="Factorial formula for the Binomial coefficient."> 44 <br> 45 </div> 46 47 <!-- </equation> --> 48 49 The [binomial coefficient][binomial-coefficient] can be generalized to negative integers `n` as follows: 50 51 <!-- <equation class="equation" label="eq:binomial_coefficient_negative_integers" align="center" raw="\binom {-n}{k} = (-1)^{k} \binom{n + k - 1}{k} = (-1)^{k} \left(\!\!{\binom {n}{k}}\!\!\right)" alt="Generalization of the binomial coefficient to negative n."> --> 52 53 <div class="equation" align="center" data-raw-text="\binom {-n}{k} = (-1)^{k} \binom{n + k - 1}{k} = (-1)^{k} \left(\!\!{\binom {n}{k}}\!\!\right)" data-equation="eq:binomial_coefficient_negative_integers"> 54 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@591cf9d5c3a0cd3c1ceec961e5c49d73a68374cb/lib/node_modules/@stdlib/math/base/special/binomcoefln/docs/img/equation_binomial_coefficient_negative_integers.svg" alt="Generalization of the binomial coefficient to negative n."> 55 <br> 56 </div> 57 58 <!-- </equation> --> 59 60 </section> 61 62 <!-- /.intro --> 63 64 <section class="usage"> 65 66 ## Usage 67 68 ```javascript 69 var binomcoefln = require( '@stdlib/math/base/special/binomcoefln' ); 70 ``` 71 72 #### binomcoefln( n, k ) 73 74 Evaluates the [binomial coefficient][binomial-coefficient] of two integers `n` and `k`. 75 76 ```javascript 77 var v = binomcoefln( 8, 2 ); 78 // returns ~3.332 79 80 v = binomcoefln( 0, 0 ); 81 // returns 0.0 82 83 v = binomcoefln( -4, 2 ); 84 // returns ~2.303 85 86 v = binomcoefln( 88, 3 ); 87 // returns ~11.606 88 89 v = binomcoefln( NaN, 3 ); 90 // returns NaN 91 92 v = binomcoefln( 5, NaN ); 93 // returns NaN 94 95 v = binomcoefln( NaN, NaN ); 96 // returns NaN 97 ``` 98 99 For negative `k`, the function returns `-Infinity`. 100 101 ```javascript 102 var v = binomcoefln( 2, -1 ); 103 // returns -Infinity 104 105 v = binomcoefln( -3, -1 ); 106 // returns -Infinity 107 ``` 108 109 The function returns `NaN` for non-integer `n` or `k`. 110 111 ```javascript 112 var v = binomcoefln( 2, 1.5 ); 113 // returns NaN 114 115 v = binomcoefln( 5.5, 2 ); 116 // returns NaN 117 ``` 118 119 </section> 120 121 <!-- /.usage --> 122 123 <section class="examples"> 124 125 ## Examples 126 127 <!-- eslint no-undef: "error" --> 128 129 ```javascript 130 var randu = require( '@stdlib/random/base/randu' ); 131 var round = require( '@stdlib/math/base/special/round' ); 132 var binomcoefln = require( '@stdlib/math/base/special/binomcoefln' ); 133 134 var n; 135 var k; 136 var i; 137 138 for ( i = 0; i < 100; i++ ) { 139 n = round( (randu()*40.0) - 10.0 ); 140 k = round( randu()*20.0 ); 141 console.log( 'ln( %d choose %d ) = %d', n, k, binomcoefln( n, k ) ); 142 } 143 ``` 144 145 </section> 146 147 <!-- /.examples --> 148 149 <section class="links"> 150 151 [binomial-coefficient]: https://en.wikipedia.org/wiki/Binomial_coefficient 152 153 </section> 154 155 <!-- /.links -->