README.md (5750B)
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 # factorialln 22 23 > Natural logarithm of the [factorial function][factorial-function]. 24 25 <section class="intro"> 26 27 The natural logarithm of the factorial function may be expressed 28 29 <!-- <equation class="equation" label="eq:factorialln_function" align="center" raw="f(n)=\ln (n!)" alt="Equation of the natural logarithm of the factorial."> --> 30 31 <div class="equation" align="center" data-raw-text="f(n)=\ln (n!)" data-equation="eq:factorialln_function"> 32 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/factorialln/docs/img/equation_factorialln_function.svg" alt="Equation of the natural logarithm of the factorial."> 33 <br> 34 </div> 35 36 <!-- </equation> --> 37 38 The [factorial function][factorial-function] may be defined as the product 39 40 <!-- <equation class="equation" label="eq:factorial_function" align="center" raw="n! = \prod_{k=1}^n k" alt="Factorial function definition"> --> 41 42 <div class="equation" align="center" data-raw-text="n! = \prod_{k=1}^n k" data-equation="eq:factorial_function"> 43 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/factorialln/docs/img/equation_factorial_function.svg" alt="Factorial function definition"> 44 <br> 45 </div> 46 47 <!-- </equation> --> 48 49 or according to the recurrence relation 50 51 <!-- <equation class="equation" label="eq:factorial_recurrence_relation" align="center" raw="n! = \begin{cases}1 & \textrm{if } n = 0,\\(n-1)! \times n & \textrm{if } n > 1\end{cases}" alt="Factorial function recurrence relation"> --> 52 53 <div class="equation" align="center" data-raw-text="n! = \begin{cases}1 & \textrm{if } n = 0,\\(n-1)! \times n & \textrm{if } n > 1\end{cases}" data-equation="eq:factorial_recurrence_relation"> 54 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/factorialln/docs/img/equation_factorial_recurrence_relation.svg" alt="Factorial function recurrence relation"> 55 <br> 56 </div> 57 58 <!-- </equation> --> 59 60 Following the convention for an [empty product][empty-product], in all definitions, 61 62 <!-- <equation class="equation" label="eq:zero_factorial" align="center" raw="0! = 1" alt="Zero factorial"> --> 63 64 <div class="equation" align="center" data-raw-text="0! = 1" data-equation="eq:zero_factorial"> 65 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/factorialln/docs/img/equation_zero_factorial.svg" alt="Zero factorial"> 66 <br> 67 </div> 68 69 <!-- </equation> --> 70 71 The [Gamma][gamma-function] function extends the [factorial function][factorial-function] for non-integer values. 72 73 <!-- <equation class="equation" label="eq:factorial_function_and_gamma" align="center" raw="n! = \Gamma(n+1)" alt="Factorial function extension via the Gamma function"> --> 74 75 <div class="equation" align="center" data-raw-text="n! = \Gamma(n+1)" data-equation="eq:factorial_function_and_gamma"> 76 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/factorialln/docs/img/equation_factorial_function_and_gamma.svg" alt="Factorial function extension via the Gamma function"> 77 <br> 78 </div> 79 80 <!-- </equation> --> 81 82 The [factorial][factorial-function] of a **negative** integer is not defined. 83 84 Evaluating the natural logarithm of [factorial function][factorial-function] is useful as the [factorial function][factorial-function] can overflow for large `n`. Thus, `factorialln( n )` is generally preferred to `ln( n! )`. 85 86 </section> 87 88 <!-- /.intro --> 89 90 <section class="usage"> 91 92 ## Usage 93 94 ```javascript 95 var factorialln = require( '@stdlib/math/base/special/factorialln' ); 96 ``` 97 98 #### factorialln( x ) 99 100 Evaluates the natural logarithm of the [factorial function][factorial-function]. For input values other than negative integers, the function returns `ln( x! ) = ln( Γ(x+1) )`, where `Γ` is the [Gamma][gamma-function] function. For negative integers, the function returns `NaN`. 101 102 ```javascript 103 var v = factorialln( 3.0 ); 104 // returns ~1.792 105 106 v = factorialln( 2.4 ); 107 // returns ~1.092 108 109 v = factorialln( -1.0 ); 110 // returns NaN 111 112 v = factorialln( -1.5 ); 113 // returns ~1.266 114 ``` 115 116 If provided `NaN`, the function returns `NaN`. 117 118 ```javascript 119 var v = factorialln( NaN ); 120 // returns NaN 121 ``` 122 123 </section> 124 125 <!-- /.usage --> 126 127 <section class="examples"> 128 129 ## Examples 130 131 <!-- eslint no-undef: "error" --> 132 133 ```javascript 134 var incrspace = require( '@stdlib/array/incrspace' ); 135 var factorialln = require( '@stdlib/math/base/special/factorialln' ); 136 137 var x; 138 var v; 139 var i; 140 141 x = incrspace( -10.0, 50.0, 0.5 ); 142 for ( i = 0; i < x.length; i++ ) { 143 v = factorialln( x[ i ] ); 144 console.log( 'x: %d, f(x): %d', x[ i ], v ); 145 } 146 ``` 147 148 </section> 149 150 <!-- /.examples --> 151 152 <section class="links"> 153 154 [gamma-function]: https://en.wikipedia.org/wiki/Gamma_Function 155 156 [factorial-function]: https://en.wikipedia.org/wiki/Factorial 157 158 [empty-product]: https://en.wikipedia.org/wiki/Empty_product 159 160 </section> 161 162 <!-- /.links -->