gamma
This page explains how to use the gamma function in APL.
Use the gamma function in APL to compute the gamma function of a numeric value. For positive integers, gamma(n) equals (n-1)!. The gamma function generalizes the factorial to real and complex numbers.
gamma is useful in statistical calculations such as computing combinatorial coefficients, probability distributions, and Bayesian models. In observability, you might use it in custom anomaly scoring or when implementing statistical tests directly in APL.
Usage
Syntax
APL
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
x | real | Yes | The input value. Must not be zero or a negative integer. |
Returns
- The gamma function of
x. - Returns
nullwhenxis zero or a negative integer. - For large inputs, the result may overflow to infinity.
Example
Use gamma to compute the gamma function value for a request duration in seconds.
Query
Output
| _time | id | req_duration_ms | gamma_val |
|---|---|---|---|
| 2024-11-14 10:00:00 | user-1 | 1000.0 | 1.0000 |
| 2024-11-14 10:01:00 | user-2 | 2000.0 | 1.0000 |
| 2024-11-14 10:02:00 | user-3 | 3000.0 | 2.0000 |
List of related functions
- loggamma: Returns the natural log of the absolute gamma function value. Use it to avoid numeric overflow when working with large inputs.
- log: Returns the natural logarithm. Use it when you want to work in log space rather than applying
gammadirectly. - exp: Returns e^x. Use it to exponentiate log-space results from
loggammaback to the original scale. - pow: Raises a value to a power. Use it for simpler power calculations that don't require the general gamma function.
- isfinite: Returns whether a value is finite. Use it to filter out overflow results from
gammaon large inputs.