Line drawing algorithm: Difference between revisions

From formulasearchengine
Jump to navigation Jump to search
No edit summary
en>Dexbot
m Removing Link FA template (handled by wikidata)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
[[Image:Stirling's Approximation.svg|thumb|right|400px|The ratio of (ln ''n''!) to (''n'' ln ''n'' − ''n'') approaches unity as ''n'' increases.]]
I'm Richelle (26) from Trewint, Great Britain. <br>I'm learning Arabic literature at a local college and I'm just about to graduate.<br>I have a part time job in a university.<br><br>Also visit my homepage [http://tianhesd.com/plus/guestbook.php FIFA 15 coin hack]
In [[mathematics]], '''Stirling's approximation''' (or '''Stirling's formula''') is an approximation for [[factorial]]s. It is a very powerful approximation, leading to accurate results for even small values of n. It is named after [[James Stirling (mathematician)|James Stirling]].
 
The formula as typically used in applications is
 
:<math>\ln(n!) = n\ln(n) - n +O(\ln(n))</math>
 
The next term in the ''O''(ln(''n'')) is (1/2)ln(2π''n''); a more precise variant of the formula is therefore
 
:<math>n! \sim \sqrt{2 \pi n}\left(\frac{n}{e}\right)^n</math>
 
Being an [[asymptotic formula]], Stirling's approximation has the property that
 
:<math>\lim_{n \to \infty} \frac{n!}{\sqrt{2\pi n} \left(\frac{n}{e}\right)^n} = 1.</math>
 
Sometimes, bounds for <math>n!</math> rather than asymptotics are required: one has, for all <math> n\in\N _ + </math>
 
:<math>\sqrt{2\pi}\ n^{n+1/2}e^{-n} \le n! \le e\ n^{n+1/2}e^{-n} , </math>
 
so for all <math>n \ge 1</math> the ratio <math>\frac{n!}{n^{n+1/2}e^{-n}}</math> is always e.g. between 2.5 and 3.
 
== Derivation ==
The formula, together with precise estimates of its error, can be derived as follows. Instead of approximating ''n''!, one considers its [[natural logarithm]] as this is a slowly varying function:
 
:<math>\ln(n!) = \ln(1) + \ln(2) + \cdots + \ln(n).</math>
 
The right-hand side of this equation minus
 
:<math>\tfrac{1}{2}(\ln(1)+\ln(n)) = \tfrac{1}{2}\ln(n),</math>
 
is the approximation by the [[trapezoid rule]] of the integral
 
:<math>\ln(n!) - \tfrac{1}{2}\ln(n) \approx \int_1^n \ln(x)\,{\rm d}x = n \ln(n) - n + 1,</math>
 
and the error in this approximation is given by the [[Euler–Maclaurin formula]]:
 
:<math>\begin{align}
\ln (n!) - \tfrac{1}{2}\ln(n) & = \tfrac{1}{2}\ln(1) + \ln(2) + \ln(3) + \cdots + \ln(n-1) + \tfrac{1}{2}\ln(n)\\
& = n \ln(n) - n + 1 + \sum_{k=2}^{m} \frac{(-1)^k B_k}{k(k-1)} \left( \frac{1}{n^{k-1}} - 1 \right) + R_{m,n},
\end{align}</math>
 
where ''B''<sub>''k''</sub> is a [[Bernoulli number]] and ''R''<sub>''m'',''n''</sub> is the remainder term in the Euler–Maclaurin formula. Take limits to find that
 
:<math>\lim_{n \to \infty} \left( \ln(n!) - n \ln(n) + n - \tfrac{1}{2}\ln(n) \right) = 1 - \sum_{k=2}^{m} \frac{(-1)^k B_k}{k(k-1)} + \lim_{n \to \infty} R_{m,n}.</math>
 
Denote this limit by ''y''.  Because the remainder ''R''<sub>''m'',''n''</sub> in the [[Euler–Maclaurin formula]] satisfies
 
:<math>R_{m,n} = \lim_{n \to \infty} R_{m,n} + O \left( \frac{1}{n^m} \right),</math>
 
where we use [[Big-O notation]], combining the equations above yields the approximation formula in its logarithmic form:
 
:<math>\ln(n!) = n \ln \left( \frac{n}{e} \right) + \tfrac{1}{2}\ln(n) + y + \sum_{k=2}^{m} \frac{(-1)^k B_k}{k(k-1)n^{k-1}} + O \left( \frac{1}{n^m} \right).</math>
 
Taking the exponential of both sides, and choosing any positive integer ''m'', we get a formula involving an unknown quantity ''e''<sup>''y''</sup>. For ''m'' = 1, the formula is
 
:<math>n! = e^{y} \sqrt{n} \left( \frac{n}{e} \right)^n \left( 1 + O \left( \frac{1}{n} \right) \right).</math>
 
The quantity ''e''<sup>''y''</sup> can be found by taking the limit on both sides as ''n'' tends to infinity and using [[Wallis product|Wallis' product]], which shows that <math>e^y = \sqrt{2 \pi}</math>.  Therefore, we get Stirling's formula:
 
:<math>n! = \sqrt{2 \pi n} \left( \frac{n}{e} \right)^n \left( 1 + O \left( \frac{1}{n} \right) \right).</math>
 
The formula may also be obtained by repeated [[integration by parts]], and the leading term can be found through [[Laplace's method]]. Stirling's formula, without the factor <math>\sqrt{2 \pi n}</math> that is often irrelevant in applications, can be quickly obtained by approximating the sum
 
:<math>\ln(n!) = \sum_{j=1}^n \ln(j)</math>
 
with an integral:
 
:<math>\sum_{j=1}^n \ln(j) \approx \int_1^n \ln(x) \,{\rm d}x = n\ln(n) - n + 1.</math>
 
== An alternative derivation ==
An alternative formula for <math>n!</math> using the [[Gamma function]] is
:<math> n! = \int_0^\infty x^n e^{-x} dx.</math>
(as can be seen by repeated integration by parts). Rewriting and changing variables <math>x=ny</math> one gets
:<math> n! = \int_0^\infty e^{n\ln x-x} dx = e^{n \ln n} n \int_0^\infty e^{n(\ln y -y)} dy.</math>
Applying [[Laplace's method]] we have:
:<math>\int_0^\infty e^{n(\ln y -y)} dy \sim  \sqrt{\frac{2\pi}{n}} e^{-n}</math>
which recovers the Stirling's formula,
:<math> n! \sim  e^{n \ln n} n \sqrt{\frac{2\pi}{n}} e^{-n}
\sim \sqrt{2\pi n}\left(\frac{n}{e}\right)^n.
</math>
In fact further corrections can also be obtained using Laplace's method. For example, computing two-order expansion using Laplace's method yields
:<math>\int_0^\infty e^{n(\ln y-y)} dy \sim  \sqrt{\frac{2\pi}{n}} e^{-n}
\left(1+\frac{1}{12 n}\right)</math>
and gives Stirling's formula to two orders,
:<math> n! \sim  e^{n \ln n} n \sqrt{\frac{2\pi}{n}} e^{-n}\left(1+\frac{1}{12 n}\right)
\sim \sqrt{2\pi n}\left(\frac{n}{e}\right)^n \left(1+ \frac{1}{12 n}\right).
</math>
 
== Speed of convergence and error estimates ==
[[Image:StirlingErrorGraphBB.svg|right|thumb|300px|The relative error in a truncated Stirling series vs. ''n'', for 1 to 5 terms]]
 
Stirling's formula is in fact the first approximation to the following series (now called the '''Stirling series'''):
 
:<math>\begin{align}
n! &\sim \sqrt{2\pi n}\left(\frac{n}{e}\right)^n \left(1 +{1\over12n}+{1\over288n^2} - {139\over51840n^3} -{571\over2488320n^4}+ \cdots \right) \\
&= \sqrt{2\pi n}\left(\frac{n}{e}\right)^n \left(1+\frac{1}{(2^1)(6n)^1}+{1\over(2^3)(6n)^2}-{139\over(2^3)(2\cdot3\cdot5)(6n)^3} \right. \\
&\qquad\left. -{571\over(2^6)(2\cdot3\cdot5)(6n)^4} + \cdots  \right).
\end{align}</math>
 
An explicit formula for the coefficients in this series was given by G. Nemes.<ref name="Nemes2010-2">{{Citation|last=Nemes|first=Gergő|year=2010|title=On the Coefficients of the Asymptotic Expansion of n!|journal=Journal of Integer Sequences|volume=13|issue=6|pages=5 pp.|issn=|doi=|postscript=}}</ref> The first graph in this section shows the [[Approximation error|relative error]] vs. ''n'', for 1 through all 5 terms listed above.
 
[[Image:StirlingError1.svg|right|thumb|300px|The relative error in a truncated Stirling series vs. the number of terms used]]
 
As ''n'' → ∞, the error in the truncated series is asymptotically equal to the first omitted term. This is an example of an [[asymptotic expansion]]. It is not a [[convergent series]]; for any ''particular'' value of ''n'' there are only so many terms of the series that improve accuracy, after which point accuracy actually gets worse.  This is shown in the next graph, which shows the relative error versus the number of terms in the series, for larger numbers of terms. More precisely, let ''S''(''n'', ''t'') be the Stirling series to ''t'' terms evaluated at&nbsp;''n''.  The graphs show
:<math>\left | \ln \left (\frac{S(n, t)}{n!} \right) \right |, </math>
which, when small, is essentially the relative error.
 
Writing Stirling's series in the form:
 
:<math>\begin{align}
\ln(n!) &\sim n\ln(n) - n + \tfrac{1}{2}\ln(2\pi n)  +{1\over12n}  -{1\over360n^3}  +{1\over1260n^5}  -{1\over 1680n^7}  +\cdots \\
&= n\ln(n)-n+\tfrac{1}{2}\ln(2\pi n)+{1\over(2^2\cdot3^1)n}-{1\over(2^3\cdot3^2\cdot5^1)n^3}+{1\over(2^2\cdot3^2\cdot5^1\cdot7^1)n^5}\\
&\qquad - \frac{1}{(2^4 \cdot3^1 \cdot5^1\cdot7^1)n^7} +\cdots.
\end{align} </math>
 
it is known that the error in truncating the series is always of the same sign and at most the same magnitude as the first omitted term.
 
==Stirling's formula for the gamma function==
For all positive integers,
 
:<math>n! = \Pi(n) = \Gamma(n+1),</math>
 
where Γ denotes the [[gamma function]].
 
However, the [[Gamma function#Pi function|Pi function]], unlike the factorial, is more broadly defined for all complex numbers other than non-positive integers; nevertheless, Stirling's formula may still be applied. If Re(''z'') > 0 then
 
:<math>\ln (\Gamma (z)) = \left(z-\tfrac{1}{2}\right)\ln(z) -z + \tfrac{1}{2}\ln(2 \pi) + 2 \int_0^\infty \frac{\arctan (\frac{t}{z})}{\exp(2 \pi t)-1}\,{\rm d}t.</math>
 
Repeated integration by parts gives
 
:<math>\ln (\Gamma (z)) \sim \left(z-\tfrac{1}{2}\right)\ln(z) -z + \tfrac{1}{2}\ln(2 \pi) + \sum_{n=1}^\infty \frac{B_{2n}}{2n(2n-1)z^{2n-1}}</math>
 
where ''B<sub>n</sub>'' is the ''n''-th [[Bernoulli number]] (note that the infinite sum is not convergent, so this formula is just an [[asymptotic expansion]]). The formula is valid for ''z'' large enough in absolute value when |arg(''z'')| < π−ε, where ε is positive, with an error term of <math>O(z^{-m - 1/2})</math> when the first ''m'' terms are used. The corresponding approximation may now be written:
 
:<math>\Gamma(z) = \sqrt{\frac{2 \pi}{z}}~{\left( \frac{z}{e} \right)}^z \left( 1 + O \left( \frac{1}{z} \right) \right).</math>
 
A further application of this asymptotic expansion is for complex argument ''z'' with constant Re(''z''). See for example the Stirling formula applied in Im(''z'') = ''t'' of the [[Riemann-Siegel theta function]] on the straight line 1/4 + ''it''.
 
==A convergent version of Stirling's formula==
[[Thomas Bayes]] showed, in a letter to [[John Canton]] published by the [[Royal Society]] in 1763, that Stirling's formula did not give a [[convergent series]].<ref>http://www.york.ac.uk/depts/maths/histstat/letter.pdf</ref>
 
Obtaining a convergent version of Stirling's formula entails evaluating
 
:<math>\int_0^\infty \frac{2\arctan (\tfrac{t}{z})}{\exp(2 \pi t)-1}\,{\rm d}t = \ln(\Gamma (z)) - \left( z-\tfrac{1}{2} \right) \ln(z) +z - \tfrac{1}{2}\ln(2\pi). </math>
 
One way to do this is by means of a convergent series of inverted [[Pochhammer symbol#Alternate notations|rising exponentials]]. If
 
:<math>z^{\bar n} = z(z+1) \cdots (z+n-1);</math>
 
then
 
:<math>\int_0^\infty \frac{2\arctan (\tfrac{t}{z})}{\exp(2 \pi t)-1} \,{\rm d}t = \sum_{n=1}^\infty \frac{c_n}{(z+1)^{\bar n}}</math>
 
where
 
:<math> c_n = \frac{1}{n} \int_0^1 x^{\bar n} \left( x-\tfrac{1}{2} \right) \,{\rm d}x = \frac{1}{2n}\sum_{k = 1}^n \frac{k|s(n,k)|}{(k + 1)(k + 2)}</math>
 
where ''s''(''n'',&nbsp;''k'') denotes the [[Stirling numbers of the first kind]]. From this we obtain a version of Stirling's series
 
:<math>\begin{align}
\ln(\Gamma (z)) & = \left( z-\tfrac{1}{2}\right) \ln(z) -z + \tfrac{1}{2}\ln(2 \pi)  + \frac{1}{12(z+1)} + \frac{1}{12(z+1)(z+2)} + \\
& \qquad \qquad + \frac{59}{360(z+1)(z+2)(z+3)} + \frac{29}{60(z+1)(z+2)(z+3)(z+4)} + \cdots
\end{align} </math>
 
which converges when Re(''z'') > 0.
 
==Versions suitable for calculators==
The approximation:
 
:<math>\Gamma(z) \approx \sqrt{\frac{2 \pi}{z} } \left( \frac{z}{e} \sqrt{ z \sinh \frac{1}{z}  + \frac{1}{810z^6} } \right)^{z},</math>
 
or equivalently,
 
:<math>2 \ln(\Gamma(z)) \approx \ln(2 \pi) - \ln(z) + z \left(2 \ln(z) + \ln \left( z \sinh \frac{1}{z}  + \frac{1}{810z^6} \right) - 2 \right),</math>
 
can be obtained by rearranging Stirling's extended formula and observing a coincidence between the resultant power series and the [[Taylor series]] expansion of the [[hyperbolic sine]] function. This approximation is good to more than 8 decimal digits for ''z'' with a real part greater than 8. Robert H. Windschitl suggested it in 2002 for computing the Gamma function with fair accuracy on calculators with limited program or register memory.<ref>[http://www.rskey.org/gamma.htm Toth, V. T. ''Programmable Calculators: Calculators and the Gamma Function'' (2006)]</ref>
 
Gergő Nemes proposed in 2007 an approximation which gives the same number of exact digits as the Windschitl approximation but is much simpler:<ref name="Nemes2010">{{Citation|last=Nemes|first=Gergő|year=2010|title=New asymptotic expansion for the Gamma function|journal=Archiv der Mathematik|volume=95|issue=2|pages=161–169|issn=0003-889X|doi=10.1007/s00013-010-0146-9|postscript=.}}</ref>
 
:<math>\Gamma(z) \approx \sqrt{\frac{2 \pi}{z} } \left( \frac{1}{e} \left( z + \frac{1}{12z- \frac{1}{10z}} \right) \right)^{z},</math>
 
or equivalently,
 
:<math> \ln(\Gamma(z)) \approx \tfrac{1}{2} \left[\ln(2 \pi) - \ln(z) \right] + z \left[\ln \left( z + \frac{1}{12z- \frac{1}{10z}} \right)-1\right]. </math>
 
An alternative approximation for {{nowrap|ln ''n''!}} was also given by [[Srinivasa Ramanujan]] ([[Ramanujan's lost notebook#References|Ramanujan 1988]])
 
:<math>\ln(n!) \approx n\ln(n) - n + \tfrac{1}{6}\ln(n(1+4n(1+2n))) + \tfrac{1}{2}\ln(\pi).</math>
 
== History ==
The formula was first discovered by [[Abraham de Moivre]]<ref>{{citation |doi=10.1214/ss/1177013818 |last=Le Cam |first=L. |title=The central limit theorem around 1935 |journal=Statistical Science |volume=1 |issue=1 |pages=78–96 [p. 81] |year=1986 |quote=The result, obtained using a formula originally proved by de Moivre but now called Sterling's formula, occurs in his `Doctrine of Chances' of 1733. }}.{{Verify credibility|date=May 2009}}</ref><ref>{{citation |last=Pearson |first=Karl |title=Historical note on the origin of the normal curve of errors |journal=Biometrika |volume=16 |pages=402–404 [p. 403] |quote=I consider that the fact that Stirling showed that De Moivre's arithmetical constant was <math>\sqrt{2\pi}</math> does not entitle him to claim the theorem, [...] }}</ref> in the form
 
:<math>n!\sim [{\rm constant}]\cdot n^{n+1/2} e^{-n}.</math>
 
De Moivre gave an expression for the constant in terms of its natural logarithm. Stirling's contribution consisted of showing that the constant is <math>\sqrt{2\pi}</math>. The more precise versions are due to [[Jacques Binet]].
 
==Recent improvements==
 
In 2011, Cristinel Mortici introduced several refinements of the Stirling formula,<ref>[http://www.sciencedirect.com/science/article/pii/S0893965911001066 ''A substantial improvement of the Stirling Formula''], Cristinel Mortici, 2011, Applied Mathematics Letters, volume 24 issue 8</ref> notably:
 
<math>n! \sim \sqrt{2\pi n}\left(\frac{n}{e} + \frac{1}{12 e n}\right)^n</math>
 
Although this formula presents similarities with the second order version of the Stirling formula, such as the <math>\frac{1}{12n}</math> term, it is yet different and is about two digits more accurate.  Here are numerical results for <math>n = 20</math>:
 
<math>
\begin{align}
n! & = 2432902008176640000\\
\sqrt{2\pi n}\left(\frac{n}{e}\right)^n & = 2.422786847e18\\
\sqrt{2\pi n}\left(\frac{n}{e}\right)^n\left(1+\frac{1}{12n}\right) & = 2.432881792e18\\
\sqrt{2\pi n}\left(\frac{n}{e} + \frac{1}{12 e n}\right)^n & = 2.43290180e18\\
\end{align}
</math>
 
==See also==
* [[Factorial]]
* [[Lanczos approximation]]
* [[Spouge's approximation]]
 
==Notes==
{{Reflist|30em}}
 
==References==
*{{citation |last=Abramowitz |first=M. |last2=Stegun |first2=I. |lastauthoramp=yes |title=Handbook of Mathematical Functions |year=2002 |url=http://www.math.hkbu.edu.hk/support/aands/toc.htm }}
*{{citation
| last = Nemes
| first = G.
| title = New asymptotic expansion for the Gamma function
| journal = Archiv der Mathematik
| volume = 95
| year = 2010
| issue = 2
| pages = 161–169
| doi = 10.1007/s00013-010-0146-9}}
*{{citation |last=Paris |first=R. B. |last2=Kaminsky |first2=D. |lastauthoramp=yes |chapter= |title=Asymptotics and the Mellin–Barnes Integrals |year=2001 |publisher=Cambridge University Press |location=New York |isbn=0-521-79001-8 }}
*{{citation |last=Whittaker |first=E. T. |last2=Watson |first2=G. N. |lastauthoramp=yes |title=A Course in Modern Analysis |year=1996 |edition=4th |publisher=Cambridge University Press |location=New York |isbn=0-521-58807-3 }}
* Dan Romik, ''Stirling’s Approximation for n!: The Ultimate Short Proof?'', The American Mathematical Monthly, Vol. 107, No. 6 (Jun. – Jul., 2000), 556–557.
* Y.-C. Li, ''A Note on an Identity of The Gamma Function and Stirling’s Formula'', Real Analysis Exchang, Vol. 32(1), 2006/2007, pp.&nbsp;267–272.
 
==External links==
* {{springer|title=Stirling formula|id=p/s087830}}
* [http://www.luschny.de/math/factorial/approx/SimpleCases.html Peter Luschny, ''Approximation formulas for the factorial function n!'']
* {{MathWorld | urlname=StirlingsApproximation | title=Stirling's Approximation}}
* {{PlanetMath | urlname=StirlingsApproximation | title=Stirling's approximation}}
 
[[Category:Approximations]]
[[Category:Asymptotic analysis]]
[[Category:Analytic number theory]]
[[Category:Gamma and related functions]]
[[Category:Theorems in analysis]]

Latest revision as of 11:16, 2 September 2014

I'm Richelle (26) from Trewint, Great Britain.
I'm learning Arabic literature at a local college and I'm just about to graduate.
I have a part time job in a university.

Also visit my homepage FIFA 15 coin hack