Topology, Limits, and Continuity
local graph
In the previous chapter, we learned all (that’s relevant to us) about numbers, sequences, and series. These are the foundational objects of calculus: numbers define sequences, sequences define limits, and limits define almost every quantity that interests us. However, there’s a snag. Let’s look ahead and take a look at the definition of the derivative:

If you’re feeling a sense of déjà vu, don’t be surprised. We looked at this exact formula in the introduction of the previous chapter as well, and we are much closer to understanding it. We have learned about limits, but there seems to be an issue: limits were defined in terms of sequences, and the expression limx→ywhatever(x) does not seem to be it.
What is it, then? This is what we’ll learn in this chapter, starting with the topology of real numbers. Let’s go!
Bookmark
11.1 Topology
Section titled “11.1 Topology”According to the Cambridge English Dictionary, the word “topology” means
the way the parts of something are organized or connected.
From a mathematical perspective, topology studies the local properties of structures and spaces.
In machine learning, we are often interested in global properties like minima and maxima but only have local tools to search for them. One example is the derivative of functions. Derivatives describe the slope of the tangent plane, and as Figure 11.1 illustrates, this doesn’t change if the function is modified away from the point where the derivative is taken.

Figure 11.1: The derivatives of two functions are equal if the functions are equal in any small interval around the point
In mathematics, local properties are handled in terms of sequences and neighborhoods. We learned about sequences in the last chapter, and now we will tackle the subject of neighborhoods.
We are going to focus on three fundamental aspects:
- open and closed sets,
- the behavior of sequences within sets,
- and their smallest and largest elements, upper and lower bounds.
Our main goal with mathematical analysis is to understand gradient descent, a fundamental tool for training models. To do that, we need to understand limits. For that, we need understand sequences and real numbers, leading us deep into the rabbit hole where we are now.
Think of it as learning the Python language versus learning TensorFlow or PyTorch. Since we want to do machine learning, we ultimately want to learn a high-level framework. However, if we lack the understanding of the basic keywords in Python, like import or def, we are not ready to learn and productively use advanced tools. Sequences, open and closed sets, limits, and others are the fundamental building blocks of mathematical analysis, the language of optimization.
11.1.1 Open and closed sets
Section titled “11.1.1 Open and closed sets”Let’s start our discussion with open and closed sets! (In this chapter, when we refer to something as a subset or set, it is implicitly assumed to be within ℝ.)
Definition 45. (Open and closed sets)
Let A ⊆ℝ be a subset of the real numbers.
(a) A is open if for every x ∈A, there is a 𝜀>0 such that (x−𝜀,x + 𝜀) ⊆A.
(b) A is closed if its complement ℝ ∖A is open.
Before we start analyzing the properties of open and closed sets, here are some key examples for building up useful mental models.
Example 1. Intervals of the form (a,b) = {x ∈ℝ : a>x>b} are open. This can be easily seen by picking any x ∈ (a,b) and letting 𝜀 = min{jx −aj∕2,jx −bj∕2}. Essentially, we take the distance from the closest endpoint and cut that in half. Any point that is closer to x than the half-distance of the closest endpoint will also be in (a,b).
Example 2. Intervals of the form [a,b] = {x ∈ℝ : a ≤x ≤b} are closed. Indeed, its complement is ℝ ∖ [a,b] = (−∞,a) ∪ (b,∞). Using the reasoning above, it is easy to see that (−∞,a) ∪ (b,∞) is open.
Example 3. Intervals of the form (a,b] = {x ∈ℝ : a>x ≤b} are neither open nor closed. To see that it is not open, observe that no interval containing b is fully within (a,b], since b is an endpoint. For similar reasons, its complement ℝ ∖ (a,b] = (−∞,a] ∪ (b,∞) is not open.
An important takeaway from the last example is that if a set is not closed, it doesn’t mean that it is open and vice versa.
We can rephrase the definition of openness by introducing the concept of neighborhoods. The neighborhoods of a given point x are the open intervals (a,b) containing x. With this terminology, any set A is open if, for any x ∈A, there exists a neighborhood of x that is fully contained within A. From this aspect, openness means that there is still “room to move” from any point.
The most fundamental property of open and closed sets is their behavior under union and intersection. As this holds for any collection of open and closed sets, we need to introduce a new notation here. Recall that if we have the sets A1,…,An, their union can be abbreviated as

This is denoted similarly for the intersection. If we have countable sets, we can even write

but what can we do if we have an uncountable collection of sets? Say,
for all
. In this case, we use the expression

For a general set
, we talk about the collection of sets defined by
, and the union/intersection

Now, let’s see our first theorem!
Theorem 66.
Let
be an arbitrary collection of sets.
(a) If each
is open, then

is also open.
(b) If each
is closed, then

is also closed.
Proof. (a) Suppose that Aγ,γ ∈ Γ are open sets and let x ∈∪γ∈ΓAγ. Because x is in the union, there is some γ0 ∈ Γ such that x ∈ Aγ0. Because Aγ0 is open, there is a small neighborhood (a,b) of x such that (a,b) ⊆Aγ0. Because of this, (a,b) ⊆∪γ∈ΓAγ, which is what we had to show.
(b) Now let Aγ,γ ∈ Γ be closed sets. In this case, De Morgan’s laws (Theorem 153) imply that ℝ ∖ (∩γ∈ΓAγ) = ∪γ∈Γ(ℝ ∖Aγ). Since each Aγ is closed, ℝ ∖Aγ is open. As we have previously seen, the union of open sets is open.
The closedness and openness of a set influence its behavior regarding set sequences. The first fundamental result regarding this is Cantor’s axiom.
Theorem 67. (Cantor’s axiom)
Let In = [an,bn] ⊆ ℝ be a sequence of intervals such that In+1 ⊆ In for every n ∈ℕ. Then, the intersection ∩n=1∞In is nonempty.
This seemingly simple proposition is a profound property of real numbers, one that ultimately follows from their mathematical construction. Cantor’s axiom is not true, for instance, if we talk about subsets of ℚ instead of ℝ. Think about a sequence of rational numbers an →π that approximates π from below, and another sequence bn →π that approximates π from above, that is,

The intersection of the intervals [an,bn] only contains π, which is not rational. Thus, in the space of rational numbers, ∩n=1∞[an,bn] = ∅, therefore Cantor’s axiom doesn’t hold there.
There is an old proverb about losing the war because of a nail in a horseshoe. It goes something like this:
For want of a nail the shoe was lost. For want of a shoe the horse was lost. For want of a horse the rider was lost. For want of a rider the message was lost. For want of a message the battle was lost. For want of a battle the kingdom was lost. And all for the want of a horseshoe nail.
Think about Cantor’s axiom as the nail in the horseshoe. Without it, we can’t talk about taking limits of sequences. Without limits, there are no gradients. Without gradients, there is no gradient descent, and consequently, we can’t fit machine learning models.
11.1.2 Distance and topology
Section titled “11.1.2 Distance and topology”Originally, we defined open sets in terms of small open intervals like (x −𝜀,x + 𝜀). We called a set open if you could squeeze in such a small interval for each of its points. By taking a step of abstraction, we can rephrase the definition in terms of norms (Definition 7).
From this viewpoint, an interval (x−𝜀,x + 𝜀) is the same as a one-dimensional open ball. Given a normed space V with the norm j ⋅j, the ball of radius r>0 centered at x is defined by

Equivalently, a ball of radius r is the set of points with distance less than r from the center point. In the Euclidean spaces ℝn, with the norm ∥x∥ =
, this matches our intuitive understanding. This is illustrated in Figure 11.2.

Figure 11.2: Balls, from one to three dimensions
However, in one dimension, the Euclidean norm simplifies to ∥x∥ = jxj. Thus, we have

We don’t often think about the interval (x −𝜀,x + 𝜀) as the one-dimensional ball B(x,𝜀). However, making this connection will make it easy to later extend the topology of ℝ to ℝn, which is where we want to work eventually.
With norms and balls, we can rephrase the definition of open sets in the following way.
Definition 46. (Open sets, second take)
Let A ⊆ℝ be a subset of the real numbers.
A is open if for every x ∈A, there is a one-dimensional ball B(x,𝜀) of radius 𝜀 centered around x such that B(x,𝜀) ⊆A.
Thus, in a sense, open sets are determined by open balls.
11.1.3 Sets and sequences
Section titled “11.1.3 Sets and sequences”Closed sets can be characterized in terms of their sequences. The following theorem shows an equivalent definition of closed sets, giving us a helpful way of thinking about them.
Theorem 68. (Characterization of closed sets with sequences)
Let A ⊆ℝ be a set. The following are equivalent.
(a) A is closed.
(b) If {an}n=1∞⊆A is a convergent sequence, then limn→∞an ∈A.
Proof. To prove that the two statements are equivalent, we have to show two things: that (a) implies (b) and that (b) implies (a). Don’t worry if this proof seems too complicated when you read it the first time. If you don’t understand it right away, I suggest thinking about A as a closed interval and drawing a figure. You can also skip it since I will refer back to this fact every time we need it later.
First, let’s see that (a) implies (b). Thus, suppose that A is closed and {an}n=1∞ ⊆ A is a convergent sequence, a := limn→∞an. We have to show that a ∈A, and we are going to do this by contradiction. The plan is the following: assume that a
A and deduce that {an} must eventually leave A.
Indeed, suppose that a ∈ℝ ∖A. Because A is closed, ℝ ∖A is open, so there is a small neighborhood (a −𝜀,a + 𝜀) ⊆ℝ ∖A. In plain English, this means that we can separate a from A. This contradicts the fact that {an} ⊆ A and an → a, because according to the definition of convergence (Definition 39), eventually all members of the sequence have to fall into (a −𝜀,a + 𝜀). This is a contradiction, so a ∈A.
Second, we will show that (b) implies (a), that is, if the limit of every convergent sequence of A is also in A, then the set is closed. Our goal is to show that ℝ ∖A is open. More precisely, if x ∈ ℝ ∖A, we want to find a small neighborhood (x −𝜀,x + 𝜀) that is disjointed from A. Again, we can show this via contradiction.
Suppose that no matter how small 𝜀 > 0 is, we can find an a ∈ A∩(x−𝜀,x+𝜀). Thus, we can define a sequence {an}n=1∞ such that an ∈A ∩ (x − 1∕n,x + 1∕n). Due to the construction limn→∞an = a, and as A is closed to taking limits according to the premise (b), this would imply that a ∈A, which is a contradiction. This is what we had to show.
This result also explains the origins of the terminology closed. A closed set is such because it is closed to limits.
11.1.4 Bounded sets
Section titled “11.1.4 Bounded sets”From a (very) high-level view, machine learning can be described as an optimization problem. For inputs x and predictions y, we are looking at a parametrized family of functions f(x,w), where our parameters are condensed in the variable w.
Given a set of samples and observations, our goal is to find the minimum of the set
{Loss(f(x, w), y) : w ∈ ℝa very large number} ⊆ ℝ, (11.1)
and the parameter configuration w where the optimum is attained. To make sure that our foundations are not missing this building block, we are going to take some time to study this.
Definition 47. (Bounded sets)
Let A ⊆ℝ.
(a) A is bounded from below if there is an m ∈ ℝ such that m>x for all x ∈A. The number m is called a lower bound.
(b) A is bounded from above if there is an M ∈ ℝ such that x>M for all x ∈A. Similar to before, M is called an upper bound.
(c) A is bounded if it is bounded from above and below.
Being bounded means that we can include the set in a large interval [m,M]. For optimization, there are a few essential quantities that are related to bounds: minimal and maximal elements, smallest upper bounds, and largest lower bounds.
Let’s start with formalizing the concept of the smallest and largest elements within a set.
Definition 48. (Minimal and maximal elements)
Let A ⊆ℝ.
(a) m ∈ A is called the minimal element of A if for every a ∈ A, m ≤ a holds. The minimal element is denoted by m = minA.
(b) M ∈A is called the maximal element of A if for every a ∈A, a ≤M holds. The maximal element is denoted by M = maxA.
As usual, let’s see some examples.
Example 1. The set A = [0,1] ∪ [2,3] has both minimal and maximal elements. Its minimal element is 0, and its maximal element is 3.
Example 2. The set A = {
: n ∈ℕ} has no minimal element. 0 is the largest lower bound, but since it is not in the set, it is not a minimal element.
The key takeaway is that minimal and maximal elements do not necessarily exist. To avoid the inconvenience, we need related quantities that always exist.
These will be the infimum and supremum.
Definition 49. (Infimum and supremum)
Let A ⊆ℝ.
(a) inf A ∈ℝ is the largest lower bound of A if m ≤ inf A holds for every lower bound m. This is called the infimum.
(b) supA ∈ℝ is the smallest upper bound of A if M ≥ supA holds for every upper bound M. This is called the supremum.
We won’t go into great detail here, but the infimum and supremum always exist. However, it is essential to note that there is a sequence {an}n=1∞⊆A such that an → inf A. (This is true for the supremum as well.)
11.1.5 Compact sets
Section titled “11.1.5 Compact sets”With the concept of infimum and supremum, we can formalize the optimization problem for machine learning described by (11.1) as

where this number represents the smallest possible value of the loss function and w is the parameter of our model.
However, there is a significant issue with the w ∈ℝn part. First, our parameter space is high-dimensional. In practice, n can be in the millions. Besides that, we are looking at an unbounded parameter space, where such an optimum might not even exist. Finally, is there even a parameter w where the infimum is attained? After all, this is what we are primarily interested in.
We can restrict the parameter space to a closed and bounded set to fix these issues. These sets are so prevalent that they have their own name: compact sets.
Definition 50. (Compact sets)
The set A ⊆ℝ is compact if it is bounded and closed.
We love compact sets. Even though their definition seems straightforward, these two properties have profound consequences regarding optimization. At this point, we are not ready to talk about this in detail, but we can find minima or maxima in practice because continuous functions behave nicely on compact sets.
There is a key result about compact sets that will constantly resurface during our studies of functions: the Bolzano-Weierstrass theorem.
Theorem 69. (Bolzano-Weierstrass)
In a compact set, every sequence has a convergent subsequence.
Proof. Let A ⊆ ℝ be a compact set, and {an}n=1∞ be an arbitrary sequence in A.
Because A is compact, there exists an interval I1 := [m,M] that contains A in its entirety. By cutting this interval in half, we obtain [m,(m+M)∕2] and [(m+M)∕2,M]. At least one of these will contain infinitely many points from {an}; let that be I2. Repeating this process will yield a sequence of closed intervals I1 ⊇I2 ⊇I3…. The length of Ik is (M −m)∕2k−1, so eventually these will get really small.
Due to the construction of these intervals, we can also define a subsequence {ank}k=1∞ by selecting ank such that ank ∈Ik.
According to Cantor’s axiom (Theorem 67), ∩k=1∞Ik is nonempty, so let a ∈∩k=1∞Ik. Because both ank and a are elements of Ik, we have

This shows that limk→∞ank = a, which is what we had to show.
The technique we used here is called lion catching. How does a mathematician catch a lion in the desert? By cutting the desert in half. The lion will be located in one half or the other. This section can be cut in half repeatedly until the area becomes smaller. Thus, the lion will be trapped there eventually.
Now that we understand the topological structure of real numbers and the relation to convergent sequences, we can move forward and finally talk about the limit of functions!
11.2 Limits
Section titled “11.2 Limits”Recall that in Section 10.2 about sequences, we defined limits of convergent sequences. Intuitively, limits capture the notion that eventually, all elements get as close to the limit as we wish. This concept can be extended to functions as well.
Definition 51. (Limits of functions)
Let f : ℝ →ℝ be an arbitrary function. We say that

if for every sequence xn →x0, where xn does not equal x0 for all n,

holds.
Right off the bat, there are two essential things to note.
- The limit of a function is defined in terms of limits of sequences. If all possible sequences of the form {f(xn)} with xn → x0 have the same limit, then limx→x0f(x) is defined as the common limit.
- With ∞-divergent sequences, limits at ±∞ are defined.
Here is a figure that helps visualize the process.

Figure 11.3: Illustration of limits: as xn gets closer to 0, f(xn) gets closer to limn→∞f(xn)
To further illustrate the concept of limits for functions, let’s see some examples.
Example 1. Define the function

illustrated by Figure 11.4. In other words, f(x) is 0 everywhere except at 0, where it is 1.

Figure 11.4: Plot of f(x)
Does limx→0f(x) exist? Yes. Because for any sequence xn → 0 that is not 0, the limit limn→∞f(xn) = 0. On the other hand, note that limx→0f(x)≠f(0).
Example 2. For our second example, define
.png)
(11.2)
This is the (in)famous Dirichlet function, which is hard to imagine and impossible to plot: its value is 1 at rationals and 0 at irrationals. Not surprisingly, limx→x0D(x) does not exist for all x0, because rational and irrational numbers are “dense”: every number x0 can be obtained as a limit of rationals and as a limit of irrationals.
Since limits of functions are defined as the common limit of sequences, many of its properties are inherited from sequences. How sequences behave under operations (Theorem 57) determines how function limits behave.
Theorem 70. (Operations and limits)
Let f and g be two functions.
(a)

(b)

(c)

(d) If f(x)≠0 in some small interval (x0 − 𝜀,x0 + 𝜀) around x0 and limx→x0f(x)≠0, then

Proof. This follows directly from Theorem 57.
Similarly as we have seen for convergent sequences, (a) and (b) above are referred to as the linearity of limits.
Remember how the big and small O notation (Definition 41) expressed asymptotic properties of sequences? We have a similar tool for functions as well.
Definition 52. (Big and small O notation for functions)
Let f : ℝ →ℝ and g : ℝ →ℝ be two arbitrary functions. We say that
(a) g(x) = O(f(x)) as x → a if there is a constant C such that for some δ>0, we have jg(x)j ≤Cf(x) for all x ∈ (a −δ,a) ∪ (a,a + δ). Similarly, g(x) = O(f(x)) as x →∞ if there is a constant C and a cutoff number N such that jg(x)j ≤Cf(x) holds for all x>N.
(b) g(x) = o(f(x)) as x →a if for any 𝜀>0, there is a δ>0 such that we have jg(x)j ≤𝜀f(x) for all x ∈ (a−δ,a) ∪ (a,a + δ). Similarly, g(x) = o(f(x)) as x →∞ if for any 𝜀>0, there is a cutoff number N such that jg(x)j ≤𝜀f(x) for all x>N.
11.2.1 Equivalent definitions of limits
Section titled “11.2.1 Equivalent definitions of limits”If you have a sharp eye (and some experience in mathematics), you might have already posed the question: won’t showing convergence of {f(xn)} for all sequences xn →x0 be difficult?
Indeed, it is often not the most convenient way to think about function limits. Another equivalent definition expresses limits in terms of smaller and smaller neighborhoods around the point in question.
Theorem 71. (Limits as error terms)
Let f : ℝ →ℝ be an arbitrary function and x0 ∈ℝ. Then, the following are equivalent.
(a) limx→x0f(x) = a.
(b) For every 𝜀>0, there exists a small neighborhood (x0 −δ,x0 + δ) around x0 such that for every x ∈ (x0 −δ,x0) ∪ (x0,x0 + δ),

holds.
Proof. (a) ⇒ (b). We are going to do this indirectly, so we assume that (a) holds and (b) is not true. The negation of (b) states that there is a 𝜀 >0 such that for every δ >0, there is an x ∈ (x0 −δ,x0) ∪ (x0,x0 + δ) such that |f(x) −a|𝜀. (If you don’t see why this is the negation, check out the Appendix A about logic.)
Now we define a sequence that will contradict (a). If we select δ = 1∕n, we can let xn be the one in (x0 −δ,x0) ∪ (x0,x0 + δ) such that |f(xn) −a| 𝜀, as guaranteed by our assumption that (b) is false. Due to its construction, {f(xn)}n=1∞ does not converge to a. This contradicts (a), which completes our indirect proof.
(b) ⇒ (a). Let {xn}n=1∞ be an arbitrary sequence that converges to x0. If n is large enough (that is, larger than some cutoff index N), xn will fall into (x0 −δ,x0 + δ), where δ >0 is an arbitrary small constant. Since (b) says that |f(xn) −a| 𝜀 here for all such n, we have limn→∞f(xn) = a by the definition of convergence (Definition 39).
In plain English, this theorem says that f(x) gets arbitrarily close to limx→x0f(x) if x is close enough to x0. Definitions similar to (b) are called epsilon-delta definitions.
There is yet another equivalent definition that, although it might seem trivial, is a useful mental model when thinking about limits.
Theorem 72.
Let f : ℝ →ℝ be an arbitrary function and x0 ∈ℝ. Then, the following are equivalent.
(a) limx→x0f(x) = a.
(b) There exists a function error(x) such that limx→x0error(x) = 0 and

Proof. (a) ⇒ (b). Due to how limits behave with respect to operations (Theorem 70), it is easy to see that

satisfies the requirements.
(b) ⇒ (a). Again, this is trivial because of the linearity of the limit operation:

This is what we had to show.
Often, we don’t need to know the exact limits of a function; it is enough to know that the limit is above or below a specific bound.
To give a specific example, we will look slightly ahead and talk about differentiation. I’ll explain everything in detail in the next chapter, but the derivative of a function f at the point x0 is defined as the limit

If the function is increasing, we have

which, given the things we are about to see, implies that the derivative is positive.
Without any further ado, let’s see the result!
Theorem 73. (The transfer principle for functions)
Let f : ℝ → ℝ be an arbitrary function. If f(x) ≥ α for all x ∈ (a −δ,a) ∪ (a,a + δ) and some δ> constant and α ∈ℝ lower bound, then limx→af(x) ≥α if the limit exists.
Proof. Due to the definition of function limits, this is the immediate consequence of the transfer principle for convergent sequences (Theorem 58).
There are a couple of special limits that come up all the time in calculations. These are the building blocks for calculating more complicated limits, as they can often be reduced to a form for which the limit is known.
We won’t include the proofs here, as they are not that useful for our purposes (which is understanding how machine learning algorithms work).
Theorem 74. (a)
limx→0 sin x x = 1. (11.3)
(b)
limx → 0 x log x = 0. (11.4)
(c)
limx → ∞ xk e−ax = 0, a ∈ (0, ∞), k = 0, 1, 2, … (11.5)
With the extension of limits from sequences to functions, we saw that if the limit exists, it is not necessarily equal to the function’s value at the given point. However, when it does, the function is much easier to handle. This is called continuity, and this is what we’ll discuss next.
Bookmark
11.3 Continuity
Section titled “11.3 Continuity”If I asked you to conjure up a random function from your mind, I am almost certain that you would come up with one that is both continuous and differentiable. (unless you have weird tastes, as many mathematicians do).
However, the vast majority of functions are neither. In terms of cardinality, if you count all real functions f : ℝ→ℝ, it turns out that there are 2c of them in total, but the subset of continuous ones have cardinality c. It is hard to imagine such quantities: c and 2c are both infinite, but, well, 2c is more infinite. Yeah, I know. Set theory is weird. (Recall that c denotes the cardinality of the set of real numbers. If you would like a refresher on the topic, check out the set theory appendix Appendix C.)
Overall, as we shall see, continuity and differentiability allow us to do meaningful work with functions. For instance, the usual gradient descent-based optimization for neural networks doesn’t work if the loss function and the layers are not differentiable. That alone would throw a huge wrench into the cogs of machine learning since this is used all the time in the deep learning part of the field.
This section explores how these concepts work together and ultimately enable us to train neural networks. So, let’s dive straight into the deep water and precisely define the notion of continuity!
Definition 53. (Continuity)
Let f : ℝ →ℝ be an arbitrary function. We say that f is continuous at a if

holds.
In other words, continuity means that if x is close to y, then f(x) will also be close to f(y). This is how most of our mental models work. This is also what we want from many machine learning models. For example, if f is a model that takes images and decides if they feature a cat or not, we would expect that after changing a few pixels on x, the prediction would stay the same. (However, this is definitely not the case in general, which is exploited by certain adversarial attacks.)
We can rephrase the above definition by unpacking the limits. If you think it through a bit, it is easy to see that continuity of f at a is equivalent to

for all convergent sequences an →a. In other words, the limit and function application are interchangeable. We are going to use this very frequently.
As usual, we’ll see some examples first. We’ll revisit the ones we saw Section 11.2.
Example 1. Let’s revisit

While f(x) is not continuous at 0 since limx→0f(x) = 0≠f(0), as we have seen before, f(x) is continuous everywhere else (since it is constant 0).
Note that even though the function is not continuous at 0, the limit does exist!
Example 2. What about the Dirichlet function D(x)? (See (11.2) for the definition.) Since the limit doesn’t even exist, this is a nowhere near a continuous function.
Example 3. Define

Surprisingly, f(x) is continuous at 0, but nowhere else. As you can see, (almost) nothing is off the table with continuity. Functions, in general, can be wild objects, and without certain regularity conditions, optimizing them is extremely hard. In essence, this chapter aims to understand when and how we can optimize functions that we used to do when training a machine learning model.
One final example!
Example 4. We call a function an elementary function if it can be obtained by taking a finite sum, product, and combination of
- constant functions,
- power functions x,x2,x3,…,
- n-th root functions x1∕2,x1∕3,x1∕4,…,
- exponential functions ax,
- logarithms log ax,
- trigonometric and inverse trigonometric functions sinx,cosx,arcsinx,arccosx,
- hyperbolic and inverse hyperbolic functions sinhx,coshx,sinh−1x,cosh−1x.
For instance,

is an elementary function. Elementary functions are continuous wherever they are defined. This is going to be extremely useful for us since showing the continuity of a complicated function like f(x) is hard with the definition alone. This way, if it is elementary, we know it is continuous. This will also be true for multivariate functions (like a neural network).
11.3.1 Properties of continuous functions
Section titled “11.3.1 Properties of continuous functions”A typical pattern in mathematics, as you have seen when discussing the properties of convergent sequences in Theorem 57, is to study certain properties on basic building blocks first, then show how it behaves with respect to operations.
We are going to follow a similar pattern to the previous example regarding the continuity of elementary functions.
Theorem 75.
Let f and g be two functions.
(a) If f and g are continuous at a, then f + g and fg are also continuous at a.
(b) If f and g are continuous at a and g(a)≠0, then f∕g is also continuous at a.
(c) If g is continuous at a and f is continuous at g(a), then f ∘g is also continuous at a.
Proof. (a) and (b) follow directly from the properties of limits (Theorem 70).
To see (c), we simply let {an}n=1∞ be a sequence that converges to a. Then, assuming that f is continuous at g(a) and g is continuous at a, we have

which shows the continuity of f ∘g at a.
So far, we have only defined continuity at a single point. In general, a function f : ℝ →ℝ is continuous on the set A simply if it is continuous at its every point.
We have arrived at the point that partly explains why we love continuous functions and compact sets.
The reason is simple: functions that are continuous on compact sets are bounded there and attain their optima.
Theorem 76.
Let f be continuous on a compact set K. There exists α,β ∈K such that f(α) ≤f(x) ≤f(β) holds for all x ∈K.
Let {αn}n=1∞ ⊆ K be a sequence such that f(αn) → inf{f(x) : x ∈K}. (This is guaranteed to exist, as follows from the properties of infimum and supremum.)
Now, according to the Bolzano-Weierstrass theorem (Theorem 69), {αn}n=1∞ has a convergent subsequence {αnk}k=1∞ with limk→∞αnk = α. Since K is compact, α ∈K. (Recall that a compact set is closed, and closed sets contain the limits of their convergent sequences, as Theorem 68 implies.)
Because f is continuous, we have

which is what we had to show. An identical argument shows the existence of a β ∈K such that f(x) ≤f(β) for all x ∈K.
This statement is not true for sets that are not closed and bounded. For example, f(x) =
is continuous on (0,1], but has no upper bound.
Bookmark
11.4 Summary
Section titled “11.4 Summary”I admit, the fine details of topology, limits, and continuity can feel complex and abstract. However, in my experience, taking the hardest path is the most rewarding, especially when learning technical topics. To sum up, we’ve learned
- what topology is,
- what it has to do with sequences and limits,
- how to take limits of functions,
- and finally, what a continuous function is.
Now that we are familiar with all the above, we are ready to tackle a subject at the heart of machine learning: differentiation. We’ll look at how to analyze functions and what makes a function “behave nicely.”
If you think through what machine learning is really about, you’ll find that it is quite straightforward from a bird’s eye view. In essence, all we want to do is 1. Design parameterized functions to explain the relationships between data and observations and 2. Find the parameters that best fit our data.
To find models that are expressive enough yet easy to work with, we need to restrict ourselves to functions that satisfy certain properties. The two most important are continuity and differentiability. Now that we have seen what continuity is, we can move on to study differentiable functions.
In the following chapters, we will exclusively deal with univariate real functions. This is to introduce concepts without adding many layers of complexity at once. In later chapters, we will slowly turn toward multivariate functions, and by the time we get to machine learning, we will have mastered their use.
Bookmark
11.5 Problems
Section titled “11.5 Problems”Problem 1. Which of the following subsets of ℝ are open, closed, or neither?
(a) ℤ (b) ℚ (c) ∩n=1∞(−
,
) (d) ∪n=1∞[0,1 −
]
Problem 2. Let
be an arbitrary set. Show that there exists a sequence
such that

(An identical statement is true for
as well, which can be shown in the same way.)
Problem 3. Let D(x) be the Dirichlet function, defined by

Give a mathematically rigorous proof that the limit limx→x0D(x) does not exist for any x0 ∈ℝ.
Problem 4. Let X be an arbitrary set, and let τ ⊆P(X) be a collection of its subsets. (Recall that P(A) denotes all subsets of A.) The structure (X,τ) is called a topological space, if
- ∅∈τ and X ∈τ,
- For any collection of sets in τ, the union is also in τ,
- For any finite collection of sets in τ, the intersection is also in τ.
The sets in τ are called open sets. Show that the following are topological spaces.
(a) X is any set, τ = {∅,X}. (b) X is any set, τ = P(X). (c) (ℕ,τ), where τ = {S ⊆ℕ : 0
τ}.
Problem 5. Let f : ℝ →ℝ be an arbitrary function. Show that f is continuous at x0 if and only if for every 𝜀>0 there exists a δ>0 such that for any x ∈ (x0 −δ,x0 + δ), jf(x) −f(x0)j>𝜀.
The above is an equivalent definition of continuity, called the epsilon-delta definition.
Problem 6. Let f : ℝ →ℝ be an arbitrary function. Show that f is continuous everywhere if and only if the set

is open for every open set X!