|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 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 | +```math |
| 32 | +\Gamma ( n ) = \frac{(n+g-0.5)^{n-0.5}}{e^{n+g-0.5}} L_g(n) |
| 33 | +``` |
| 34 | + |
| 35 | +<!-- <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"> |
| 36 | + <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."> |
| 37 | + <br> |
| 38 | +</div> --> |
| 39 | + |
| 40 | +<!-- </equation> --> |
| 41 | + |
| 42 | +where `g` is an [arbitrary constant][@stdlib/constants/float32/gamma-lanczos-g] and `L_g(n)` is the Lanczos sum. |
| 43 | + |
| 44 | +</section> |
| 45 | + |
| 46 | +<!-- /.intro --> |
| 47 | + |
| 48 | +<section class="usage"> |
| 49 | + |
| 50 | +## Usage |
| 51 | + |
| 52 | +```javascript |
| 53 | +var gammaLanczosSumf = require( '@stdlib/math/base/special/gamma-lanczos-sumf' ); |
| 54 | +``` |
| 55 | + |
| 56 | +#### gammaLanczosSumf( x ) |
| 57 | + |
| 58 | +Calculates the Lanczos sum for the approximation of the [gamma function][gamma-function] for single-precision floating-point number. |
| 59 | + |
| 60 | +```javascript |
| 61 | +var v = gammaLanczosSumf( 4.0 ); |
| 62 | +// returns ~950.366 |
| 63 | + |
| 64 | +v = gammaLanczosSumf( -1.5 ); |
| 65 | +// returns ~1373366.245 |
| 66 | + |
| 67 | +v = gammaLanczosSumf( -0.5 ); |
| 68 | +// returns ~-699841.735 |
| 69 | + |
| 70 | +v = gammaLanczosSumf( 0.5 ); |
| 71 | +// returns ~96074.186 |
| 72 | + |
| 73 | +v = gammaLanczosSumf( 0.0 ); |
| 74 | +// returns Infinity |
| 75 | + |
| 76 | +v = gammaLanczosSumf( NaN ); |
| 77 | +// returns NaN |
| 78 | +``` |
| 79 | + |
| 80 | +</section> |
| 81 | + |
| 82 | +<!-- /.usage --> |
| 83 | + |
| 84 | +<section class="examples"> |
| 85 | + |
| 86 | +## Examples |
| 87 | + |
| 88 | +<!-- eslint no-undef: "error" --> |
| 89 | + |
| 90 | +```javascript |
| 91 | +var linspace = require( '@stdlib/array/base/linspace' ); |
| 92 | +var gammaLanczosSumf = require( '@stdlib/math/base/special/gamma-lanczos-sumf' ); |
| 93 | + |
| 94 | +var x = linspace( -10.0, 10.0, 100 ); |
| 95 | + |
| 96 | +var i; |
| 97 | +for ( i = 0; i < x.length; i++ ) { |
| 98 | + console.log( 'x: %d, f(x): %d', x[ i ], gammaLanczosSumf( x[ i ] ) ); |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +</section> |
| 103 | + |
| 104 | +<!-- /.examples --> |
| 105 | + |
| 106 | +<!-- C interface documentation. --> |
| 107 | + |
| 108 | +* * * |
| 109 | + |
| 110 | +<section class="c"> |
| 111 | + |
| 112 | +## C APIs |
| 113 | + |
| 114 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 115 | + |
| 116 | +<section class="intro"> |
| 117 | + |
| 118 | +</section> |
| 119 | + |
| 120 | +<!-- /.intro --> |
| 121 | + |
| 122 | +<!-- C usage documentation. --> |
| 123 | + |
| 124 | +<section class="usage"> |
| 125 | + |
| 126 | +### Usage |
| 127 | + |
| 128 | +```c |
| 129 | +#include "stdlib/math/base/special/gamma_lanczos_sumf.h" |
| 130 | +``` |
| 131 | + |
| 132 | +#### stdlib_base_gamma_lanczos_sumf( x ) |
| 133 | + |
| 134 | +Calculates the Lanczos sum for the approximation of the [gamma function][gamma-function] for single-precision floating-point number. |
| 135 | + |
| 136 | +```c |
| 137 | +float out = stdlib_base_gamma_lanczos_sumf( 4.0f ); |
| 138 | +// returns ~950.366f |
| 139 | + |
| 140 | +out = stdlib_base_gamma_lanczos_sumf( -1.5f ); |
| 141 | +// returns ~1373366.245f |
| 142 | +``` |
| 143 | + |
| 144 | +The function accepts the following arguments: |
| 145 | + |
| 146 | +- **x**: `[in] float` input value. |
| 147 | + |
| 148 | +```c |
| 149 | +float stdlib_base_gamma_lanczos_sumf( const float x ); |
| 150 | +``` |
| 151 | +
|
| 152 | +</section> |
| 153 | +
|
| 154 | +<!-- /.usage --> |
| 155 | +
|
| 156 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 157 | +
|
| 158 | +<section class="notes"> |
| 159 | +
|
| 160 | +</section> |
| 161 | +
|
| 162 | +<!-- /.notes --> |
| 163 | +
|
| 164 | +<!-- C API usage examples. --> |
| 165 | +
|
| 166 | +<section class="examples"> |
| 167 | +
|
| 168 | +### Examples |
| 169 | +
|
| 170 | +```c |
| 171 | +#include "stdlib/math/base/special/gamma_lanczos_sumf.h" |
| 172 | +#include <stdlib.h> |
| 173 | +#include <stdio.h> |
| 174 | +
|
| 175 | +int main( void ) { |
| 176 | + const float x[] = { 4.0f, -1.5f, -0.5f, 0.5f }; |
| 177 | +
|
| 178 | + float y; |
| 179 | + int i; |
| 180 | + for ( i = 0; i < 4; i++ ) { |
| 181 | + y = stdlib_base_gamma_lanczos_sumf( x[ i ] ); |
| 182 | + printf( "gamma_lanczos_sumf(%f) = %f\n", x[ i ], y ); |
| 183 | + } |
| 184 | +} |
| 185 | +``` |
| 186 | + |
| 187 | +</section> |
| 188 | + |
| 189 | +<!-- /.examples --> |
| 190 | + |
| 191 | +</section> |
| 192 | + |
| 193 | +<!-- /.c --> |
| 194 | + |
| 195 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 196 | + |
| 197 | +<section class="related"> |
| 198 | + |
| 199 | +* * * |
| 200 | + |
| 201 | +## See Also |
| 202 | + |
| 203 | +- <span class="package-name">[`@stdlib/math/base/special/gamma-lanczos-sum`][@stdlib/math/base/special/gamma-lanczos-sum]</span><span class="delimiter">: </span><span class="description">gamma function.</span> |
| 204 | +- <span class="package-name">[`@stdlib/math/base/special/gamma`][@stdlib/math/base/special/gamma]</span><span class="delimiter">: </span><span class="description">gamma function.</span> |
| 205 | +- <span class="package-name">[`@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled`][@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled]</span><span class="delimiter">: </span><span class="description">calculate a scaled Lanczos sum for the approximation of the gamma function.</span> |
| 206 | + |
| 207 | +</section> |
| 208 | + |
| 209 | +<!-- /.related --> |
| 210 | + |
| 211 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 212 | + |
| 213 | +<section class="links"> |
| 214 | + |
| 215 | +[@stdlib/constants/float64/gamma-lanczos-g]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/constants/float64/gamma-lanczos-g |
| 216 | + |
| 217 | +[gamma-function]: https://en.wikipedia.org/wiki/Gamma_function |
| 218 | + |
| 219 | +[lanczos-approximation]: https://en.wikipedia.org/wiki/Lanczos_approximation |
| 220 | + |
| 221 | +<!-- <related-links> --> |
| 222 | + |
| 223 | +[@stdlib/math/base/special/gamma-lanczos-sum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/gamma-lanczos-sum |
| 224 | + |
| 225 | +[@stdlib/math/base/special/gamma]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/gamma |
| 226 | + |
| 227 | +[@stdlib/math/base/special/gamma-lanczos-sum-expg-scaled]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/math/base/special/gamma-lanczos-sum-expg-scaled |
| 228 | + |
| 229 | +<!-- </related-links> --> |
| 230 | + |
| 231 | +</section> |
| 232 | + |
| 233 | +<!-- /.links --> |
0 commit comments