time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (3827B)


      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 # Gamma Function
     22 
     23 > [Gamma][gamma-function] function.
     24 
     25 <section class="intro">
     26 
     27 The [gamma function][gamma-function] extends the [factorial function][@stdlib/math/base/special/factorial] to [real][real] and [complex][complex] numbers. If `n` is a positive `integer`,
     28 
     29 <!-- <equation class="equation" label="eq:gamma_function_positive_integers" align="center" raw="\Gamma ( n ) = (n-1)!" alt="Gamma function for positive integers."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="\Gamma ( n ) = (n-1)!" data-equation="eq:gamma_function_positive_integers">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gamma/docs/img/equation_gamma_function_positive_integers.svg" alt="Gamma function for positive integers.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 Generalized to all complex numbers `z`, except for nonpositive integers, the [gamma function][gamma-function] can be expressed as an infinite product
     39 
     40 <!-- <equation class="equation" label="eq:gamma_function_infinite_product" align="center" raw="\Gamma ( z ) = \frac{e^{-\gamma z}}{z} \prod^{\infty}_{n=1} \left ( 1+\frac{z}{n}\right )^{-1} e^{z/n}" alt="Gamma function for all complex numbers."> -->
     41 
     42 <div class="equation" align="center" data-raw-text="\Gamma ( z ) = \frac{e^{-\gamma z}}{z} \prod^{\infty}_{n=1} \left ( 1+\frac{z}{n}\right )^{-1} e^{z/n}" data-equation="eq:gamma_function_infinite_product">
     43     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@591cf9d5c3a0cd3c1ceec961e5c49d73a68374cb/lib/node_modules/@stdlib/math/base/special/gamma/docs/img/equation_gamma_function_infinite_product.svg" alt="Gamma function for all complex numbers.">
     44     <br>
     45 </div>
     46 
     47 <!-- </equation> -->
     48 
     49 where `γ ≈ 0.577216` is the  [Euler–Mascheroni constant][@stdlib/constants/float64/eulergamma].
     50 
     51 </section>
     52 
     53 <!-- /.intro -->
     54 
     55 <section class="usage">
     56 
     57 ## Usage
     58 
     59 ```javascript
     60 var gamma = require( '@stdlib/math/base/special/gamma' );
     61 ```
     62 
     63 #### gamma( x )
     64 
     65 Evaluates the [gamma function][gamma-function].
     66 
     67 ```javascript
     68 var v = gamma( 4.0 );
     69 // returns 6.0
     70 
     71 v = gamma( -1.5 );
     72 // returns ~2.363
     73 
     74 v = gamma( -0.5 );
     75 // returns ~-3.545
     76 
     77 v = gamma( 0.5 );
     78 // returns ~1.772
     79 
     80 v = gamma( 0.0 );
     81 // returns Infinity
     82 
     83 v = gamma( -0.0 );
     84 // returns -Infinity
     85 
     86 v = gamma( NaN );
     87 // returns NaN
     88 ```
     89 
     90 </section>
     91 
     92 <!-- /.usage -->
     93 
     94 <section class="examples">
     95 
     96 ## Examples
     97 
     98 <!-- eslint no-undef: "error" -->
     99 
    100 ```javascript
    101 var linspace = require( '@stdlib/array/linspace' );
    102 var gamma = require( '@stdlib/math/base/special/gamma' );
    103 
    104 var x = linspace( -10.0, 10.0, 100 );
    105 var v;
    106 var i;
    107 
    108 for ( i = 0; i < x.length; i++ ) {
    109     v = gamma( x[ i ] );
    110     console.log( 'x: %d, f(x): %d', x[ i ], v );
    111 }
    112 ```
    113 
    114 </section>
    115 
    116 <!-- /.examples -->
    117 
    118 <section class="links">
    119 
    120 [gamma-function]: https://en.wikipedia.org/wiki/Gamma_function
    121 
    122 [@stdlib/math/base/special/factorial]: https://www.npmjs.com/package/@stdlib/math/tree/main/base/special/factorial
    123 
    124 [real]: https://en.wikipedia.org/wiki/Real_number
    125 
    126 [complex]: https://en.wikipedia.org/wiki/Complex_number
    127 
    128 [@stdlib/constants/float64/eulergamma]: https://www.npmjs.com/package/@stdlib/constants-float64-eulergamma
    129 
    130 </section>
    131 
    132 <!-- /.links -->