Numbers, Sequences, and Series
local graph
”It’s like asking why is Ludwig van Beethoven’s Ninth Symphony beautiful. If you don’t see why, someone can’t tell you. I know numbers are beautiful. If they aren’t beautiful, nothing is.”
— Paul Erdős
When I was about to take my first mathematical analysis course at the university, coming straight from high school, I wondered why we would spend several lectures on real numbers. At the time, I was confident in my knowledge and thought that I knew what numbers were. This was my first painful encounter with the Dunning–Kruger effect: the less you know, the more confident you are. Suffice to say, after a few classes, I was left confused about numbers, taking a while to finally understand them.
If you look at numbers under a magnifying glass, they become extremely complex. In this chapter, we are going to make sense of them. To look ahead and keep machine learning in our sights, consider that gradient descent (you know, the optimization algorithm that is used everywhere) is not possible for functions that are not differentiable. In turn, a function f is differentiable at x if the limit

exists. To understand limits, we must understand real numbers first.
Another good reason to dig deep into the patterns and structures of numbers: they are beautiful (as said above by Paul Erdős, one of the greatest mathematicians ever). There is a particular joy to understanding seemingly familiar things on a deep level. Even though you might not use this knowledge every day, it teaches you perspective about the objects you encounter during your work.
So, let’s get started!
Bookmark
10.1 Numbers
Section titled “10.1 Numbers”There are five famous classes of numbers that one has to know in order to become adept in mathematics:
- natural numbers, denoted by ℕ,
- integers, denoted by ℤ,
- rational numbers, denoted by ℚ,
- real numbers, denoted by ℝ,
- and finally, complex numbers, denoted by ℂ.
These classes increase in order, that is,

In this section, we are going to concern ourselves with the first four. (Complex numbers will get their own chapter.)
10.1.1 Natural numbers and integers
Section titled “10.1.1 Natural numbers and integers”Natural numbers are simply defined as

Sometimes 0 is included; sometimes it is not. Believe it or not, after a few thousand years, mathematicians still cannot decide whether or not 0 is a natural number. This problem might sound comical, but trust me, I have seen senior professors almost get into a fistfight upon debating this issue. For some people, this is a religious question.
I don’t particularly care, and neither should you. I propose using the more common and practical definition, which is the one without 0. When we really need to talk about the natural numbers AND 0, I will use the notation ℕ0 = {0,1,2,…}.
The cardinality of the set of natural numbers is countably infinite. In fact, countability is defined as jℕj. (If you are not familiar with the concept of cardinality, check out Appendix C.)
To be able to express negative and zero quantities, we extend natural numbers to obtain the set of integers, defined by

So far, so good. Integers are also countable: one can enumerate all of its elements by

One significant advantage of integers over natural numbers is that they contain the additive inverse for each element. In plain English, if n ∈ℤ, then so does −n ∈ℤ. This makes it possible to define all kinds of algebraic structures over the integers, giving us mathematical tools to reason about phenomena modeled by them.
Note that if n,m ∈ℤ, then n + m ∈ℤ. In mathematical terminology, we say that ℤ is closed to addition.
To summarize, ℤ is
- closed to addition,
- and every element has an additive inverse.
These two properties will guide us on how to go from natural numbers to real numbers. Each extension is constructed so that these two properties hold, but for different operations.
10.1.2 Rational numbers
Section titled “10.1.2 Rational numbers”So, we obtained ℤ from ℕ by extending it with 0 and the additive inverses for each element. What about the multiplicative inverses? This idea leads us to the concept of rational numbers, numbers that can be written as a ratio of two integers. It is defined by

It is both closed to multiplication and every element (except 0) has a multiplicative inverse. This is not just a l’art pour l’art mathematical construction: rational numbers model quantities that are all around us. ”7.9 seconds” to ”100.0 km/h”. 78.4 kilograms to carry. 0.5 pizza to eat. You get it.
It might be surprising, but ℚ is also countable.
One easy way to prove this is to notice that it can be obtained as the countable union of countable sets:

(If you are not familiar with the basic set operations like union and setminus, check out Appendix C.)
Since the union of countable sets is countable, ℚ is countable as well. Another (and perhaps more visual) way to see this is to simply enumerate them in the sequence, illustrated by Figure 10.1.

Figure 10.1: Enumeration of rational numbers, where the arrows indicate the ordering
Rational numbers can be written in decimal form, like
= 0.5, for example. In general, the following is true.
Theorem 55.
Any rational number x can be represented as a:
(a) finite decimal

(b) or a repeating decimal

where the decimals between the two dots repeat infinitely. (This can be just a single digit as well.)
Note that the decimal representation is not unique: for example, 1.0 0.˙9 are equal.
The above theorem fully characterizes rational numbers. But what about numbers with an infinite decimal form that does not repeat?
Like the famous mathematical constant π describing the half circumference of the unit circle, that is,

with no repeating patterns. These are called irrational numbers, and together with rationals, they make up the real numbers.
10.1.3 Real numbers
Section titled “10.1.3 Real numbers”The simplest way to imagine real numbers is a line, where each point represents a number.

Figure 10.2: The real number line
If we temporarily let mathematical correctness slide, we can say that
ℝ = finite decimals∪in finite repeating decimals∪infinite nonrepeating decimals
Real numbers are also the first we have encountered in our journey that are not countable, and we will prove this! Its proof is so beautiful that it belongs in The Book, a collection of the most elegant and beautiful mathematical proofs.
Theorem 56.
ℝ is not countable.
Proof. To show that ℝ is not countable, let’s take an indirect approach: assume that it is countable and deduce a contradiction. This method is called an indirect proof, a top-tier tool in a mathematician’s toolkit.
Since [0,1) ⊆ℝ, it is enough to show that [0,1) is not countable. If it is countable, we can enumerate it:
We can write out the decimal forms of these:

Let’s focus on the diagonal! By changing the digits there, we define

Can the number

be found in the sequence {a1,a2,…}? No, because the i-th decimal of ai and â must be different for all i ∈ ℕ! We have constructed â by changing the i-th decimal of ai.
To summarize, our assumption that [0,1) can be enumerated leads to a contradiction because we have found an element that cannot possibly be in our enumeration. So, [0,1) is not countable, hence ℝ is not countable as well. This is what we needed to show!
The method of proof that you have seen above is called Cantor’s diagonal argument. This is a beautiful and powerful idea, and although we won’t encounter it anymore, it is the key to proving several difficult theorems. (Like Gödel’s famous incompleteness theorems, essentially stating that an axiomatic system is either inexpressive or inconsistent. These threw a huge monkey wrench into the machinery of mathematics at the beginning of the 20th century.)
Notice that real numbers break the pattern we observed previously. Integers were constructed by extending the natural numbers with additive inverses and closing them to addition; rationals were obtained the same way, except doing it for multiplication. As we shall see later, real numbers follow a similar process: we obtain them from rationals by closing them to limits.
But what are limits? Let’s see – by studying sequences, the objects that provide the context of limits!
Bookmark
10.2 Sequences
Section titled “10.2 Sequences”Sequences lie at the very heart of mathematics. Sequences and their limits describe long-term behavior, like the (occasional) convergence of gradient descent to a local optimum. By definition, a sequence is an enumeration of mathematical objects.
The elements of a sequence can be any mathematical object, like sets, functions, or Hilbert spaces. (Whatever those might be.) For us, sequences are composed of numbers. We formally denote them as

For simplicity, the subscripts and the superscripts are often omitted, so don’t panic if you see {an}, as it is just an abbreviation. (Or an. Mathematicians love abbreviations.) If all elements of the sequence belong to a set A, we often write {an}⊆A.
Sequences can be bidirectional as well. Those are denoted as {an}n=−∞∞. We don’t need them for now, but they will frequently come up in the context of probability distributions later.
Sometimes we don’t need an entire sequence, just a subsequence. We will not do anything special with them just yet, but here is the formal definition.
Definition 38. (Subsequences)
Let ann=1∞, and let nkk=1∞⊆ℕ be a strictly increasing sequence of natural numbers. Then, the sequence {ank}k=1∞ is a subsequence of {an}.
Think of it as throwing elements away from a sequence.
10.2.1 Convergence
Section titled “10.2.1 Convergence”One of the most important aspects of sequences is their asymptotic behavior, or in other words, what they do in the long term. A particular property we often look for is convergence. In plain English, the sequence {an} converges to a if no matter how small of an interval (a−𝜀,a + 𝜀) we define (where 𝜀 can be really small), eventually all of the elements of {an} fall into it.
The following is the mathematically precise definition of convergence.
Definition 39. (Convergence of sequences)
The sequence {an}⊆ℝ is said to converge to some a ∈ℝ if for every 𝜀>0, there is a cutoff index n0 ∈ℕ such that

holds for all indices n>n0. The value a is said to be the limit of {an}, and we write

or

Note that the cutoff index n0 depends on 𝜀. We could write n0(𝜀) to emphasize this dependency, but we rarely do so. To avoid referencing and naming the cutoff index n0 all the time, we often simply say that a given property “holds for all n large enough.” (Did I mention that mathematicians love abbreviations?)
In plain English, the definition means that no matter how small of an interval you enclose a in, all members of the sequence will eventually fall into it.
Although mathematically extremely precise and correct, this definition doesn’t give us a lot of tools to show if a sequence is convergent or not. First, we have to conjure up the limit a and then construct the cutoff indexes. For example, consider an :=
.
To make our job easier, we can plot this to visualize the situation.
import numpy as npimport matplotlib.pyplot as plt
with plt.style.context("seaborn-v0_8"): plt.figure(figsize=(8, 5)) plt.scatter(range(1, 21), [1/n for n in range(1, 21)]) plt.xticks(range(1, 21, 2)) plt.title("the 1/n sequence") plt.show()
Figure 10.3: The 1∕n sequence
Here, we can explicitly construct the cutoff index n0 for every 𝜀. Since we want to have

we can reorganize the inequality to obtain

So,

will do the job.
We had it easy in this example, but this is pretty much as far as we can go with the definition. For example, how do you show the convergence of

with the definition only? You don’t.
There are more advanced tools for this, as we shall see. (By the way, limn→∞an =
). For sequences that are defined recursively and there is no analytic formula available, like

where L is the loss function for a neural network with weights
n and training data (
,
), we have even more complications. There is no need to worry about them yet; let’s focus on one thing at a time.
10.2.2 Properties of convergence
Section titled “10.2.2 Properties of convergence”In essence, the study of convergence for a particular sequence comes down to breaking it into simpler and simpler parts until the limit is known.
- Is this a “famous” sequence where the limit is known? If yes, we are done. If not, go to the next step.
- Can you decompose it into simpler parts? If yes, is the convergence known for them? If the convergence is unknown, can you simplify it further?
We can do this because convergence has some particularly nice properties, as summarized in the theorem below.
Theorem 57. (Properties of convergence)
Let {an}and {bn}be two convergent sequences with

Then:
(a)

(b)

(c)

(d) and if an≠0 and a≠0, then

The properties (a) and (b) together are called linearity of convergence.
As we shall see later, the continuity of functions also provides a great tool to study convergence properties of a sequence. In fact, continuity is nothing more than the interchangeability of limits and functions:

One essential property of convergent sequences is that under certain circumstances, they preserve inequalities. This is true of function limits as well, so it is important for us.
Theorem 58. (The transfer principle)
Let {an}n=1∞ be a convergent sequence. If an ≥α holds for all n ∈ℕ, where α ∈ℝ is some lower bound, then limn→∞an ≥α.
Proof. We are going to do this indirectly. If limn→∞an α, then by the definition of convergence,
|an −a|>
for all large n. This means that those an-s are actually below α, contradicting our assumptions.
This proof is straightforward to understand if you draw a figure and visualize what happens, so I encourage you to do so. The identical result is true if we replace ≥ with ≤ in the above, with the wording of the proof staying the same.
Note that if an>α for all n, limn→∞an>α is not guaranteed! The best example to show this is an := 1∕n, which converges to 0, although all of its terms are positive.
As a corollary, we obtain a tool that will be very useful for showing the convergence of particular sequences.
Corollary 3. (The squeeze principle)
Let
,
, and
be three sequences such that
for all large enough
. If

then

In other words, squeezing {bn} between two convergent sequences that have the same limit implies convergence of bn to the joint limit.
10.2.3 Famous convergent sequences
Section titled “10.2.3 Famous convergent sequences”Because convergence behaves nicely with respect to certain operations (Section 10.2.2), we study sequences by decomposing them into building blocks. Let’s see the most important ones that will be useful for us later!
Example 1. For any x ≥ 0,
.png)
(10.1)
If you think about it for a minute, this is easy to see. The x = 0 and x = 1 cases are trivial. Regarding the others, because taking the logarithm turns exponentiation into multiplication, we have log xn = nlog x. So,

Since the logarithm is increasing and invertible, (10.1) follows.
Example 2. For any x ≥ 0,
.png)
(10.2)
Similarly to the previous example, this can be shown with the use of logarithms.
Example 3. Let’s consider the sequences

Can you order them according to the speed of growth? This is quite important throughout computer science, as these could represent time complexities. It’s almost folklore that logarithmic time complexity beats linear, which beats exponential, which beats factorial. In other terms,

Example 4. We have just learned that n grows faster than log n. From this, it follows that

a surprising result (at least, it surprised me as a young student)! To show this, we apply the good old logarithm trick:

10.2.4 The role of convergence in machine learning
Section titled “10.2.4 The role of convergence in machine learning”Convergence is everywhere. You’ve just come across this concept for the first time, so you might not realize its importance just yet. However, it is central to mathematics and machine learning.
Just to look ahead and give a few examples, differentiation is defined by a limit:

Regarding derivatives, integrals (the “inverse” of differentiation) are limits of convergent sequences. For instance,

Because integrals are limits, so is every quantity calculated with integration, such as expected values, like for the standard normal distribution,
![∫ ∞ 𝔼[𝒩 (0,1)] = x √1--e−x2∕2dx. −∞ 2π](https://static.packt-cdn.com/products/9781837027873/graphics/media/file951.png)
Convergence is also central to probability and statistics.
There are two famous theorems: the law of large numbers, stating that

holds; and the central limit theorem, which says

in distribution, for independent and identically distributed random variables X1,X2,… with finite expected value 𝔼[Xi] = μ and variance var(Xi) = σ2. They are both very important in machine learning and neural networks; for instance, the law of large numbers is one of the fundamental ideas behind stochastic gradient descent.
Even the gradient descent optimization process is a recursively defined sequence of model weights, converging toward an optimum where the model best fits the data.
We will talk about all of these in detail. So, even if you don’t understand these right now, don’t worry. It’ll become clear soon. Before finishing up with sequences, we shall discuss what happens when a sequence is not convergent.
10.2.5 Divergent sequences
Section titled “10.2.5 Divergent sequences”We have talked about how convergent sequences are everywhere, and they are at the core of mathematics and machine learning. However, not all sequences are convergent.
Think about the following example:

When plotted, this is how it looks.
with plt.style.context("seaborn-v0_8"): plt.figure(figsize=(8, 5)) plt.scatter(range(1, 21), [np.sin(n) for n in range(1, 21)]) plt.xticks(range(1, 21, 2)) plt.title("the sin(n) sequence") plt.show()
Figure 10.4: The sin(n) sequence
Although it is hard to prove, this sequence does not converge. Its value is constantly oscillating in [ − 1,1]. We call non-convergent sequences divergent. Among these, there is a special kind of divergence: approaching infinity.
Definition 40. (∞-divergence)
The sequence {an} is said to be ∞-divergent if for every arbitrarily large number x, there is a cutoff index n0 such that

holds for all indices n>n0.
We denote ∞-divergence by writing xn →∞. Analogously, (−∞)-divergent sequences can be defined.
An obvious example is {n} or {nlog n}. These are all across computer science as well: the runtime of algorithms given the number of steps or the size of the input is ∞-divergent.
When you see something like an = O(n), it means that there is a constant c such that

holds for all large enough n.
10.2.6 The big and small O notation
Section titled “10.2.6 The big and small O notation”If you have some experience with computer science, you are probably familiar with the big O small O notation. There, it is used to express the runtime of algorithms, but it is not limited to that. In general, it is used to compare the long-term behavior of sequences. Let’s start with the definitions first, and then I’ll explain the intuition and some use cases.
Definition 41. (Big and small O notation)
Let
and
be two arbitrary sequences. We say that:
- , if there is a constant such that for all sufficiently large
- , if for every , there exists a cutoff index such that for every .
In plain English, “bn is big O of an” means that bn grows roughly at the same rate as an, while “bn is small O of an” means that bn is an order of magnitude smaller than an.
So, when we say that the runtime of an algorithm is O(n) steps where n is the input size, we mean that the algorithm will finish in Cn steps. Often, we don’t care about the constant multiplier since it doesn’t mean an order of magnitude difference in the long run.
10.2.7 Real numbers are sequences
Section titled “10.2.7 Real numbers are sequences”Now that we have familiarized ourselves with the concept of convergent sequences, we shall take another look at rational and real numbers. When extending the classes of numbers going from ℕ to ℝ, we pick an operation, close the set with respect to it, and add inverse elements to that operation.
Extending ℕ with additive inverses −n for all n ∈ℕ yields ℤ. Extending ℤ with multiplicative inverses 1∕n for all n and closing it for multiplication yields ℚ. The pattern is seemingly different in the case of ℝ, but this is not the case. After understanding what convergence is, we have the tools to see why.
Consider the following sequence:

Since rational numbers are closed to addition and multiplication, we see that an is rational. However,

which is the famous Euler constant, is not rational.
Thus, we have found what is missing: ℚ is not closed to taking limits. So, we can obtain the set of real numbers by closing ℚ to taking limits.
The fact that every irrational number can be approximated with rational numbers as close as possible is often under-appreciated. Think about this: can you represent all real numbers with a computer? Nope. This follows from a simple cardinality argument: the number of possible floats is finite, but there are uncountably many real numbers. However, certain numbers (like π or e) are essential in engineering calculations and simulations. Without approximations, working with irrational numbers would be unfeasible.
Speaking of e: how would you approximate it for computational purposes? In theory, it is enough to take a large enough n and use the value (1 + 1∕n)n. In practice, there are several potential problems: the convergence might be slow, and taking a large power of a quantity so close to 1 can be numerically unstable.
However, there is a solution: the form

solves both of these problems! From a numerical point of view, addition is much better than multiplication. Moreover, as n! grows extremely rapidly, the term
becomes negligible even for small n-s. Thus, the convergence is fast. Check this out.
from math import factorial
x = range(1, 21)
e_def = [(1 + 1/n)**n for n in x]e_sum = [np.sum([1/factorial(k) for k in range(n)]) for n in x]with plt.style.context("seaborn-v0_8": plt.figure(figsize=(8, 5)) plt.scatter(x, e_def, label="1 + 1/n) ** n ") plt.scatter(x, e_sum, label="sum approximation") plt.xticks(range(1, 21, 2)) plt.title("Approximating the value of e ") plt.legend() plt.show()
Figure 10.5: Approximating e: Definition vs. series
Expressions of form ∑ n=0∞an are called series, and they are one of the most important mathematical objects, both in theory and practice. Let’s see what they are and how can we work with them!
Bookmark
10.3 Series
Section titled “10.3 Series”There is a great pizza place in my hometown that I used to visit quite a lot. There, each pizza is packed in a box that contains a pizza coupon. Ten pizza coupons can be exchanged for a free pizza. This begs the question: how much pizza do you get with a single purchase?
Immediately, you’ll receive a pizza. You’ll also get 1∕10-th of a pizza in the form of a coupon, making the “value” of the purchase at least 1 +
pizzas.
However, upon exchanging ten coupons, you get another one. Thus, a coupon represents
+
pizzas. Continuing with this logic, we’ll obtain that the true value of each purchase is

What is the value of this number? To find out, we’ll take a look at infinite series, a main pillar of mathematics. Infinite series (or series for short) are sums of the form

Adding infinitely many terms together might seem like a trivial matter, but I assure you, this is far from the truth. For instance, consider the sum

On one hand,

but on the other,

Which one is it? Zero or one? It is neither. We’ll see why in this section.
10.3.1 Convergent and divergent series
Section titled “10.3.1 Convergent and divergent series”The natural way to make sense of the infinite series

is by taking the limit of the so-called partial sums

This is formalized by the following definition.
Definition 42.
(Convergent and divergent series)
Let
be an arbitrary real sequence. The infinite series
is defined by

If the above limit exists, we say that
is convergent. Otherwise, it is divergent.
Sounds simple enough. Let’s see some examples!
Example 1. The geometric series, given by

As SN + qN+1 = SN+1 = 1 + qSN, it follows that SN =
. Thus,

This is where the famous formula ∑ n=1∞
= 1 comes from. (Figure 10.6 illustrates this fact as well.)

Figure 10.6: The visual proof of the convergence of a geometric series for q = 1∕2
The geometric series is also the one that appears in our introductory pizza coupon example. Now, we can see that the value of a single purchase is

pizzas.
Example 2. The harmonic series, given by

Why is the harmonic series divergent? To see why, first notice that

Thus, by grouping the terms appropriately, we obtain that

If you are having trouble imagining this, here is the plot.
xs = range(1, 41)an = [1/n for n in xs]ys = np.cumsum(an)
with plt.style.context("seaborn-v0_8"): plt.figure(figsize=(8, 5)) plt.scatter(xs, ys) plt.xticks(range(1, 41, 5)) plt.title("the harmonic series") plt.show()
Figure 10.7: The harmonic series
According to the Euler-Maclaurin formula,

where γ ≈ 0.5772156649… is the famous Euler–Mascheroni constant. Check it out. (When the base is omitted, log denotes the natural logarithm, also often denoted by ln.)
with plt.style.context("seaborn-v0_8"): plt.figure(figsize=(8, 5)) plt.plot(xs, np.log(xs) + np.euler_gamma, c="r" linewidth=5, zorder=1, label="log(x + y)") plt.scatter(xs[::2], ys[::2], label="harmonic series") plt.xticks(range(1, 41, 5)) plt.title("the harmonic series") plt.legend() plt.show()
Figure 10.8: The harmonic series and the log(x + γ) function
Example 3. The alternating harmonic series, given by

Surprisingly, the alternating harmonic series is convergent, with the sum log 2.
Example 4. The Basel problem. Believe it or not, solving polynomial equations and evaluating infinite sums were some kind of sport for mathematicians of previous eras. One of the most famous ones was the Basel problem, concerning the infinite sum of inverse squares. In 1735, the legendary Euler showed that

which is a stunning result. What on Earth is π doing there? The constant π is defined as the half circumference of a circle of radius 1, and seeing it pop up in the infinite sum of inverse squares is puzzling to say the least. (There is an explanation: the numbers 1∕n2 are the (scaled) Fourier coefficients of the function f(x) = x, and the sum of the Fourier coefficients always evaluates to the integral of the function over the interval [ −π,π]. However, this method is beyond the scope of this book.)
On a personal note, ∑ n=1∞
=
was the favorite identity of my calculus professor, a teacher who I loved so much that I ended up specializing in mathematical analysis. Once, he hit his head in an accident. Upon arrival of the ambulance, he was asked by the paramedic to talk, just to gauge if his cognitive capabilities were intact. So, he started to explain the Basel problem to the medical staff. He was almost shipped to the trauma center, but fortunately, his wife was there to explain that he is normal; he’s just a mathematician.
Example 5. Apéry’s constant. We’ve seen the harmonic series and the Basel problem, so what about the sum of inverse cubes? Although it is known that the series

is convergent and its value is irrational, we don’t have a closed-form solution just yet!
Example 6. The alternating series

This is the first example of a divergent series: as

the limit limN→∞∑ n=0N(−1)n doesn’t exist. This is the resolution of the seemingly paradoxical result from the introduction: as ∑ n=0∞(−1)n is divergent, associativity breaks down.
Example 7. The famous Euler number, defined by e = limn→∞(1 +
)n, is also given by the infinite series
e = ∑ n=0∞
.
Currently, this is beyond our scope, but later, we’ll see why this is true. (Spoiler alert: This is a so-called Taylor series, which we’ll talk about in Chapter 12.)
This leads to the following question: is there a method that tells if a series is convergent or not? Finding a closed formula for the partial sums is not always possible. I urge you to try finding one for ∑ n=0N1∕n!, if you don’t believe me.
10.3.2 Properties of series
Section titled “10.3.2 Properties of series”Let’s take a look at some of the most important properties of series. First, it is immediately clear that the general term of a convergent series should converge to 0 as well.
Proposition 2.
Let ∑ n = 1∞an be a convergent series. Then limN→∞aN = 0.
Proof. As aN = ∑ n=1Nan −∑ n=1N−1an, we have

which is what we had to show.
Proposition 2 can be used to quickly gauge the convergence of certain series. For instance, ∑ n=1∞
cannot be convergent, as limn→∞
= 1.
On the other hand, note that the reverse of Proposition 2 is not true: there are divergent series with a general term converging to 0. One immediate example is the harmonic series ∑ n=1∞
.
Just like sequences, convergent series behave with respect to addition and scalar multiplication, as we expect.
Theorem 59. (Linearity of convergent series)
Let ∑ n = 1∞an and ∑ n = 1∞bn be two convergent series, and let α,β ∈ℝ be two arbitrary real numbers. Then,

The proof is a direct consequence of Theorem 57. Feel free to work it out by hand for practice!
Note that Theorem 59 does not apply to divergent series. For instance,
![∑∞ n n+1 [(− 1) + (− 1) ] = 0, n=0](https://static.packt-cdn.com/products/9781837027873/graphics/media/file1016.png)
However,

are both divergent.
The product of a series is slightly more convoluted. We’ll deal with this later in the chapter, I promise.
10.3.3 Conditional and absolute convergence
Section titled “10.3.3 Conditional and absolute convergence”Let’s turn the weirdness up a notch. Recall the alternating harmonic series ∑ n=1∞(−1)n+1
, whose sum is log 2. What happens if we rearrange its terms?
Instead of alternating between one odd and one even term, let’s do one odd and two even. (Odd and even with respect to their indices.)
This is illustrated by Figure 10.9.

Figure 10.9: A rearrangement of the alternating harmonic series
The change is small, but carries a profound impact. As it turns out, by simply rearranging the terms, we change the value of the sum! Check out Figure 10.10 to see why.

Figure 10.10: A rearrangement of the alternating harmonic series, explained
This happens because rearrangements are not valid operations in the world of series. However, the notion of convergence can be refined in a way that’ll enable us to differentiate between rearrangeable and non-rearrangeable series.
Enter absolute and conditional convergence.
Definition 43. (Absolute and conditional convergence)
Let ∑ n=1∞an be an infinite series.
(a) If ∑ n=1∞janj is convergent, then ∑ n=1∞an is called absolutely convergent.
(b) If ∑ n=1∞an is convergent but not absolutely convergent, then it is called conditionally convergent.
For example, the geometric series ∑ n=0∞
n is absolutely convergent, while the alternating harmonic series ∑ n=1∞(−1)n
is only conditionally convergent.
If a series is absolutely convergent, then it is convergent as well. (We’ll skip the proof, as the minute technical details are not that important for us.)
10.3.4 Revisiting rearrangements
Section titled “10.3.4 Revisiting rearrangements”Being absolutely or conditionally convergent has a profound impact on the behavior of the series. One prime example is its rearrangeability. As it turns out, absolutely convergent series can be rearranged, while conditionally convergent series go crazy.
Mathematically speaking, rearrangements can be formalized via permutations of the index set.
Definition 44. (Permutations)
Let A be an arbitrary set. The mapping σ : A →A is called a permutation of A if it is bijective.
It seems quite abstract, but permutations are easy to grasp. Think about the index set as the increasing sequence

(It may include 0, or might even start from a larger number.) The simple permutation

swaps the neighboring even and odd numbers, turning the index set into

For a general series ∑ n=1∞an, its rearrangement given by the permutation σ is ∑ n=1∞aσ(n).
So, can you rearrange a convergent series? If it is absolutely convergent, without a doubt.
Theorem 60.
Let
be an absolutely convergent series and
be an arbitrary permutation. Then, the rearrangement
is convergent as well and

We are not going to prove this here, but the essence is, convergent series absolutely behave as we expect: we can change the order of terms without affecting the result.
What about conditionally convergent series? We have seen that rearranging can change the value, but the situation is much more interesting. Meet the Riemann rearrangement theorem.
Theorem 61. (The Riemann rearrangement theorem)
Let ∑ n=1∞an be a conditionally convergent series and let c ∈ ℝ be an arbitrary real number. Then, there exists a permutation σ : ℕ →ℕ such that

This is quite wild. The Riemann rearrangement theorem states that if you give me an arbitrary real number, I can conjure a rearrangement that’ll change the value to the number you gave me.
We won’t prove this either, but here is an intuitive explanation. Suppose that you want to rearrange the series to change its sum to 10. You start putting the positive terms in descending order to the front, and when the partial sum overshoots 10, you continue with the negative terms. When the partial sum undershoots 10, you turn to positive values once more, and you keep repeating this until infinity. The property of conditional convergence guarantees that this method works.
Now that we are familiar with the subtle differences between absolute and conditional convergence, let’s turn to one of the burning questions we should have asked already: how do we know if a series is convergent or not?
10.3.5 Convergence tests for series
Section titled “10.3.5 Convergence tests for series”Showing if a series is convergent or not is a hard task. Finding a closed form for the partial sums is often impossible, even in the seemingly simplest cases, such as ∑ n=1∞
.
What to do, then? The simplest way is to compare the series with another one that we are familiar with.
Theorem 62. (The direct comparison test)
Let
be an arbitrary series.
(a) If ∑ n=1∞bn is absolutely convergent and janj ≤jbnj for all n after a certain cutoff, ∑ n=1∞an is absolutely convergent.
(a) If ∑ n=1∞bn = ∞and jbnj ≤janj for all n after a certain cutoff, then ∑ n=1∞an = ∞.
Here is a simple use case for Theorem 62: the series

For
, since
, the series

is convergent via comparison to

On the other hand, for α>1, as
>
, ∑ n=1∞
is divergent via comparison to the harmonic series.
Although the direct comparison test is powerful, it has a significant downside: you have to conjure up a series for comparison. This is not always simple. Thus, we need other tests to show convergence. We’ll talk about two of them: the root test and the alternating series test.
Theorem 63.
(The root test)
Let ∑ n=1∞an be an arbitrary series. If there exists a positive integer N such that

for all n ≥N, then ∑ n=1∞an is absolutely convergent.
The most important use case for the root test is showing the convergence of
(which sums up to the Euler constant
, but we have no way to evaluate the sum yet). We’ll have one soon, coming from the most unexpected place. But I don’t want to spoil the fun yet.
About that sum. As
(which, trust me, it really is),
. Thus, the conditions of Theorem 63 are satisfied, hence
is convergent.
The disadvantage of the root test is that studying the behavior of
can be surprisingly hard. We have to be true calculus ninjas to handle all the bounds and limits the root test will throw at us. So, we’ll take a look at one more convergence test.
Theorem 64.
(The alternating test, a.k.a. the Leibniz criterion)
Let
be a sequence whose terms are either all nonnegative or all negative. If
(a) janj decreases monotonically
(b) and
,
then ∑ n=0∞(−1)nan is conditionally convergent.
It’s that simple. The alternating test is the easiest to apply, but in turn, it only implies conditional convergence. With this, we can finally see that the alternating harmonic series ∑ n=1∞(−1)n+1
is conditionally convergent.
10.3.6 The Cauchy product of series
Section titled “10.3.6 The Cauchy product of series”To close this chapter, let’s talk about the product of two series. We’ve seen that the linear combination of convergent series behaves nicely, but what about the product? This is slightly more complicated than addition. Here is the exact result.
Theorem 65. (Mertens’ theorem)
Let
and
be two convergent series, and assume that at least one of them converges absolutely. Then, the series
∑n=0∞ ( ∑k=0n akbn−k ) (10.3)
is convergent and

The series (65) is called the Cauchy product of
and
. Note that in the sum
, the indices of each term
sum up to
.
Instead of an exact proof, here is an intuitive explanation. Let’s unpack what is going on when we take the product of sums.
As the product is calculated term by term, we have

After spelling out the product term by term, the terms akbl are arranged in a table. Upon taking the product of ∑ n=0∞an and ∑ n=0∞bn, we simply take the terms in this table and sum them up, row by row.
However, we can sum the terms diagonally. By taking a look at the table

you can notice that the diagonals sum up to ∑ k=0nakbn−k. Thus, by taking all of them into account, we obtain

Of course, this is not an exact proof, as we’ve used rearrangements without showing absolute convergence.
Bookmark
10.4 Summary
Section titled “10.4 Summary”Until this chapter, our mathematical study was quite close to machine learning. Vectors, matrices, functions: they are all there at the ground zero of theory and practice.
This time, however, we’ve gone far below the surface. We rarely work directly with sequences in practice, but despite appearances, they are all over the place, providing a solid theoretical foundation for everything that is quantitative.
So, what did we learn? What numbers are, for one. Going from natural numbers to real numbers is nothing short of a revelation, allowing us to see the evolution of the concept of a number. But deep down, sequences hold the concept of numbers together. And whenever we talk about sequences, limits and convergence enter the picture.
To summarize, gradient descent is about the limit of the sequence

converging to a local minima of f if the stars are aligned. In the following chapters, our main goal is to understand xn+1 = xn −hf′(xn). What is f′(x), and why does xn converge to a local minimum? To see the full picture, we need to study differentiation and integration, or in other words, calculus.
However, to get there, there’s one more step to take. It’s time to move beyond sequences and study the concept of limits in the context of functions!
Bookmark
10.5 Problems
Section titled “10.5 Problems”Problem 1. Which sequences are convergent, ∞-divergent, or neither?
(a) an = 2−n2 (b) bn =
(c) cn =
(d) dn = sin(1∕n) (e) en = en(−1)n
Problem 2. Calculate the following limits.
(a) 
(b) 
(c) 
(d) 
(e) limn→∞(1 +
)n
Problem 3. Which series are absolute convergent, conditionally convergent, or divergent? (Use the direct comparison test, the root test, and the alternating series test.)
(a) 
(b) 
(c) 
(d) 
(e) ∑ n=0∞