Lesson 4 of 15
Gamma Function
Gamma Function
The Gamma function generalizes the factorial to real (and complex) numbers:
For positive integers:
Key Properties
- Recurrence:
- Half-integer: ,
- Reflection formula:
Stirling's Approximation
For large , the log-gamma function is approximated by:
This is the basis for log_gamma(n).
Lanczos Approximation
The Lanczos approximation computes accurately for positive reals using a set of precomputed coefficients. For , let :
where and:
For , use the reflection formula:
Beta Function
The Beta function is defined as:
It arises in probability (Beta distribution), combinatorics, and integration.
Your Task
Implement gamma using the Lanczos approximation with and the 9-coefficient vector below. Implement log_gamma using Stirling's approximation. Implement beta_function using the Gamma function.
Lanczos coefficients (g=7):
[0.99999999999980993, 676.5203681218851, -1259.1392167224028,
771.32342877765313, -176.61502916214059, 12.507343278686905,
-0.13857109526572012, 9.9843695780195716e-6, 1.5056327351493116e-7]Python runtime loading...
Loading...
Click "Run" to execute your code.