<title>The Lanczos Approximation</title>
<link rel="stylesheet" href="../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
-<link rel="home" href="../index.html" title="Math Toolkit 2.10.0">
-<link rel="up" href="../backgrounders.html" title="Chapter 21. Backgrounders">
+<link rel="home" href="../index.html" title="Math Toolkit 2.11.0">
+<link rel="up" href="../backgrounders.html" title="Chapter 22. Backgrounders">
<link rel="prev" href="relative_error.html" title="Relative Error">
<link rel="next" href="remez.html" title="The Remez Method">
</head>
<p>
The Lanczos Approximation to the Gamma Function is given by:
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../equations/lanczos0.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../equations/lanczos0.svg"></span>
+
+ </p></blockquote></div>
<p>
Where S<sub>g</sub>(z) is an infinite sum, that is convergent for all z > 0, and <span class="emphasis"><em>g</em></span>
is an arbitrary parameter that controls the "shape" of the terms
in the sum which is given by:
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../equations/lanczos0a.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../equations/lanczos0a.svg"></span>
+
+ </p></blockquote></div>
<p>
With individual coefficients defined in closed form by:
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../equations/lanczos0b.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../equations/lanczos0b.svg"></span>
+
+ </p></blockquote></div>
<p>
However, evaluation of the sum in that form can lead to numerical instability
in the computation of the ratios of rising and falling factorials (effectively
The Lanczos approximation is therefore often written in partial fraction form
with the leading constants absorbed by the coefficients in the sum:
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../equations/lanczos1.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../equations/lanczos1.svg"></span>
+
+ </p></blockquote></div>
<p>
where:
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../equations/lanczos2.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../equations/lanczos2.svg"></span>
+
+ </p></blockquote></div>
<p>
Again parameter <span class="emphasis"><em>g</em></span> is an arbitrarily chosen constant, and
<span class="emphasis"><em>N</em></span> is an arbitrarily chosen number of terms to evaluate
<p>
where B is an NxN matrix:
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../equations/lanczos4.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../equations/lanczos4.svg"></span>
+
+ </p></blockquote></div>
<p>
D is an NxN matrix:
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../equations/lanczos3.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../equations/lanczos3.svg"></span>
+
+ </p></blockquote></div>
<p>
C is an NxN matrix:
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../equations/lanczos5.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../equations/lanczos5.svg"></span>
+
+ </p></blockquote></div>
<p>
and F is an N element column vector:
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../equations/lanczos6.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../equations/lanczos6.svg"></span>
+
+ </p></blockquote></div>
<p>
Note than the matrices B, D and C contain all integer terms and depend only
on <span class="emphasis"><em>N</em></span>, this product should be computed first, and then
to float precision with double precision arithmetic.
</p>
<div class="table">
-<a name="math_toolkit.lanczos.optimal_choices_for_n_and_g_when"></a><p class="title"><b>Table 21.1. Optimal choices for N and g when computing with guard digits (source:
+<a name="math_toolkit.lanczos.optimal_choices_for_n_and_g_when"></a><p class="title"><b>Table 22.1. Optimal choices for N and g when computing with guard digits (source:
Pugh)</b></p>
<div class="table-contents"><table class="table" summary="Optimal choices for N and g when computing with guard digits (source:
Pugh)">
epsilon for the type in question.
</p>
<div class="table">
-<a name="math_toolkit.lanczos.optimum_value_for_n_and_g_when_c"></a><p class="title"><b>Table 21.2. Optimum value for N and g when computing at fixed precision</b></p>
+<a name="math_toolkit.lanczos.optimum_value_for_n_and_g_when_c"></a><p class="title"><b>Table 22.2. Optimum value for N and g when computing at fixed precision</b></p>
<div class="table-contents"><table class="table" summary="Optimum value for N and g when computing at fixed precision">
<colgroup>
<col>
a factor of exp(g) from the denominator, and then dividing all the coefficients
by exp(g):
</p>
-<p>
- <span class="inlinemediaobject"><img src="../../equations/lanczos7.svg"></span>
- </p>
+<div class="blockquote"><blockquote class="blockquote"><p>
+ <span class="inlinemediaobject"><img src="../../equations/lanczos7.svg"></span>
+
+ </p></blockquote></div>
<p>
This form is more convenient for calculating lgamma, but for the gamma function
the division by <span class="emphasis"><em>e</em></span> turns a possibly exact quality into