Введение
В математике аппроксимация Ланчоса — это метод численного вычисления гамма-функции, опубликованный Корнелиусом Ланчосом в 1964 году. Она является практичной альтернативой более известной аппроксимации Стирлинга для вычисления гамма-функции с заданной точностью.
Введение
Приближение Ланчоса состоит из формулы для гамма-функции, где g — вещественная константа, которую можно выбрать произвольно при условии, что Re(z + g) > 0. Коэффициенты p, зависящие от g, немного сложнее вычислить (см. ниже). Хотя формула, представленная здесь, действительна только для аргументов в правой полуплоскости комплексной плоскости, её можно расширить на всю комплексную плоскость с помощью формулы отражения:
for the gamma function, with
Here g is a real constant that may be chosen arbitrarily subject to the restriction that Re(z+g+) > 0. The coefficients p, which depend on g, are slightly more difficult to calculate (see below). Although the formula as stated here is only valid for arguments in the right complex half plane, it can be extended to the entire complex plane by the reflection formula,
The series A is convergent, and may be truncated to obtain an approximation with the desired precision. By choosing an appropriate g (typically a small integer), only some 5–10 terms of the series are needed to compute the gamma function with typical single or double floating point precision. If a fixed g is chosen, the coefficients can be calculated in advance and, thanks to partial fraction decomposition, the sum is recast into the following form:
Thus computing the gamma function becomes a matter of evaluating only a small number of elementary functions and multiplying by stored constants. The Lanczos approximation was popularized by Numerical Recipes, according to which computing the gamma function becomes "not much more difficult than other built in functions that we take for granted, such as sin x or ex." The method is also implemented in the GNU Scientific Library, Boost, CPython and musl.
Ряд A сходится и может быть усечён для получения приближения с требуемой точностью. Выбирая подходящее g (обычно небольшое целое число), для вычисления гамма-функции с типичной одинарной или двойной точностью требуется лишь около 5–10 членов ряда. Если выбрать фиксированное g, коэффициенты можно вычислить заранее, и благодаря разложению на простейшие дроби сумма приводится к следующему виду:
for the gamma function, with
Here g is a real constant that may be chosen arbitrarily subject to the restriction that Re(z+g+) > 0. The coefficients p, which depend on g, are slightly more difficult to calculate (see below). Although the formula as stated here is only valid for arguments in the right complex half plane, it can be extended to the entire complex plane by the reflection formula,
The series A is convergent, and may be truncated to obtain an approximation with the desired precision. By choosing an appropriate g (typically a small integer), only some 5–10 terms of the series are needed to compute the gamma function with typical single or double floating point precision. If a fixed g is chosen, the coefficients can be calculated in advance and, thanks to partial fraction decomposition, the sum is recast into the following form:
Thus computing the gamma function becomes a matter of evaluating only a small number of elementary functions and multiplying by stored constants. The Lanczos approximation was popularized by Numerical Recipes, according to which computing the gamma function becomes "not much more difficult than other built in functions that we take for granted, such as sin x or ex." The method is also implemented in the GNU Scientific Library, Boost, CPython and musl.
Таким образом, вычисление гамма-функции сводится к вычислению лишь небольшого числа элементарных функций и умножению на сохранённые константы. Приближение Ланчоса стало популярным благодаря книге «Численные методы», в которой говорится, что вычисление гамма-функции становится «не намного сложнее, чем вычисление других встроенных функций, которые мы воспринимаем как должное, таких как sin x или e^x». Метод также реализован в GNU Scientific Library, Boost, CPython и musl.
for the gamma function, with
Here g is a real constant that may be chosen arbitrarily subject to the restriction that Re(z+g+) > 0. The coefficients p, which depend on g, are slightly more difficult to calculate (see below). Although the formula as stated here is only valid for arguments in the right complex half plane, it can be extended to the entire complex plane by the reflection formula,
The series A is convergent, and may be truncated to obtain an approximation with the desired precision. By choosing an appropriate g (typically a small integer), only some 5–10 terms of the series are needed to compute the gamma function with typical single or double floating point precision. If a fixed g is chosen, the coefficients can be calculated in advance and, thanks to partial fraction decomposition, the sum is recast into the following form:
Thus computing the gamma function becomes a matter of evaluating only a small number of elementary functions and multiplying by stored constants. The Lanczos approximation was popularized by Numerical Recipes, according to which computing the gamma function becomes "not much more difficult than other built in functions that we take for granted, such as sin x or ex." The method is also implemented in the GNU Scientific Library, Boost, CPython and musl.