time-to-botec

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

README.md (3026B)


      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 Lanczos Sum
     22 
     23 > Calculate the Lanczos sum for the approximation of the [gamma function][gamma-function].
     24 
     25 <section class="intro">
     26 
     27 The [Lanczos approximation][lanczos-approximation] for the [gamma function][gamma-function] can be written in partial fraction form as follows:
     28 
     29 <!-- <equation class="equation" label="eq:lanczos_approximation" align="center" raw="\Gamma ( n ) = \frac{(n+g-0.5)^{n-0.5}}{e^{n+g-0.5}} L_g(n)" alt="Lanczos approximation for gamma function."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="\Gamma ( n ) = \frac{(n+g-0.5)^{n-0.5}}{e^{n+g-0.5}} L_g(n)" data-equation="eq:lanczos_approximation">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@bb29798906e119fcb2af99e94b60407a270c9b32/lib/node_modules/@stdlib/math/base/special/gamma-lanczos-sum/docs/img/equation_lanczos_approximation.svg" alt="Lanczos approximation for gamma function.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 where `g` is an [arbitrary constant][@stdlib/constants/float64/gamma-lanczos-g] and `L_g(n)` is the Lanczos sum.
     39 
     40 </section>
     41 
     42 <!-- /.intro -->
     43 
     44 <section class="usage">
     45 
     46 ## Usage
     47 
     48 ```javascript
     49 var gammaLanczosSum = require( '@stdlib/math/base/special/gamma-lanczos-sum' );
     50 ```
     51 
     52 #### gammaLanczosSum( x )
     53 
     54 Calculates the Lanczos sum for the approximation of the [gamma function][gamma-function].
     55 
     56 ```javascript
     57 var v = gammaLanczosSum( 4.0 );
     58 // returns ~950.366
     59 
     60 v = gammaLanczosSum( -1.5 );
     61 // returns ~1373366.245
     62 
     63 v = gammaLanczosSum( -0.5 );
     64 // returns ~-699841.735
     65 
     66 v = gammaLanczosSum( 0.5 );
     67 // returns ~96074.186
     68 
     69 v = gammaLanczosSum( 0.0 );
     70 // returns Infinity
     71 
     72 v = gammaLanczosSum( NaN );
     73 // returns NaN
     74 ```
     75 
     76 </section>
     77 
     78 <!-- /.usage -->
     79 
     80 <section class="examples">
     81 
     82 ## Examples
     83 
     84 <!-- eslint no-undef: "error" -->
     85 
     86 ```javascript
     87 var linspace = require( '@stdlib/array/linspace' );
     88 var gammaLanczosSum = require( '@stdlib/math/base/special/gamma-lanczos-sum' );
     89 
     90 var x = linspace( -10.0, 10.0, 100 );
     91 var v;
     92 var i;
     93 
     94 for ( i = 0; i < x.length; i++ ) {
     95     v = gammaLanczosSum( x[ i ] );
     96     console.log( 'x: %d, f(x): %d', x[ i ], v );
     97 }
     98 ```
     99 
    100 </section>
    101 
    102 <!-- /.examples -->
    103 
    104 <section class="links">
    105 
    106 [@stdlib/constants/float64/gamma-lanczos-g]: https://www.npmjs.com/package/@stdlib/constants-float64-gamma-lanczos-g
    107 
    108 [gamma-function]: https://en.wikipedia.org/wiki/Gamma_function
    109 
    110 [lanczos-approximation]: https://en.wikipedia.org/wiki/Lanczos_approximation
    111 
    112 </section>
    113 
    114 <!-- /.links -->