— 13 min read

Stirling approximation for factorials

[Part 1] Testing the convergence of series.

When evaluating distribution functions for statistics, it is often necessary to evaluate the factorials of sizable numbers. Stirling formula is an approximation for factorials that leads to a very accurate results of the factorials. In this series of posts, we will try to get a mathematical intuition of this formula.

In this first part we will try to have a closer look at the behavior of infinite series and some of their properties. The motivation behind is to have a better intuition about some very interesting concepts and tools used in everyday mathematics, physics and computer science.


We call a series associated with sequence and noted or , the couple:


is called the partial sum of the series

Convergence and divergence

Let be normed vector space, a series defined in and the sequence of partial sums.

  • We say that the series converges (respectively diverges) in if the sequence converges (respectively diverges) in .
  • In this case, the limit of the sequence is called the sum of the series , and is noted:


  • the geometric series for complex numbers.

We have the following,

Meaning that the series converges iff

and in this case

The result is simple yet so impressive, a lot of philosophers struggled to resolve Zeno’s paradoxes because they lacked the mathematical tools to correctly model the problem.

  • another example

Hence the series converges, and the infinite sum is 1.

Convergence tests

1- The n-th term test (convergence’s necessary condition)

Let be normed vector space, a series defined in


Let be the partial sums of the series, we know that the series converges if the

Hence, we have

N.B. 1

A direct conclusion from this test is that, if the general term does not converge to 0, then the series diverges.

Again if we look at the geometric series which converges only if , we can see that if

N.B. 2

having the general term converging to 0, does not guarantee the convergence of the series.

Let’s study the series

We have the following

Hence the series diverges.

2- Cauchy’s condition

Let be normed vector space, a series defined in


The proof is quite simple if we consider the sequence of partial sums . The series converges implies that converges, which means that it’s a Cauchy sequence.


Let’s consider the harmonic series

Hence the series does not verify the Cauchy’s condition, and so it does not converge.


This condition is important, and most of the time is used to study series in Banach spaces.

Let be a Banach space:

  • A series converges it verifies the Cauchy’s condition.
  • A series converges absolutely it converges.

In the second property the convergence does not imply the absolute convergence, as an example let’s consider the following series

And since

It follows that

Hence the series converges to but it does not converge absolutely.

Let’s check this result in python, we will use the symbolic library sympy

 1 from sympy import symbols, Sum, oo
 3 k, n = symbols('k n', integer=True)
 4 ps = Sum((-1)**(k+1)/k, (k, 1, n))
 6 #  lets calculate the partial sum
 7 ps.doit()
 8 > (-1)**(n + 1)*lerchphi(exp_polar(I*pi), 1, n + 1) + log(2)
10 #  the infinite sum
11 s = ps.subs(n, oo)
12 s.doit()
13 > log(2)
14 s.evalf()
15 > 0.693147180559945


A series that converges but does not converge absolutely, is called semi-convergent or conditionally convergent.

3- Leibnitz rule for testing the convergence of alternating series

Let be a series over reals, if is an alternating series, i.e. or , and is decreasing and converges to 0, then the series converges and


Let’s suppose that and

Hence is decreasing. The same way we can show that is increasing. And since , both and converge to the same limit , then we find that .

Also, since


4- Comparison test


We know that and that the sequence is increasing.

Based on this property we can deduce many other properties related to comparing series in different ways, i.e. using

Example: Riemann series

We cal a Riemann series, a series of the form

  • Case when

The series obviously diverges.

  • Case when

We saw that diverges.

  • Case when

The series diverges, because

  • Case when

Let’s consider the application

The application is of class , and by applying the Mean value theorem over , we have the following result such that

And since

It follows that

Which means that

We know that the series converges, because

Finally converges if .

 1 from sympy import symbols, Sum, oo
 3 a = symbols('a')
 4 n, k  = symbols('n k', integer=True)
 5 ps = Sum(1/(k**a), (k, 1, n))
 6 s = ps.subs(n, oo)
 8 #  the infinite sum for a < 0
 9 s.subs(a, -2).doit()
10 > oo
12 #  the infinite sum for a == 1
13 s.subs(a, 1).doit()
14 > oo
16 #  the infinite sum for a > 1
17 s.subs(a, 2).doit()
18 > pi**2/6
20 s.subs(a, 3).doit()
21 > zeta(3)
23 s.subs(a, 4).doit()
24 > pi**4/90
26 s.subs(a, 5).doit()
27 > zeta(5)