Skip to content

Chapter 2 — Functions and Dynamic Relations

2.6 — Algebra and Composition of Functions

Adding two functions combines their values; composing them combines their processes.


Section 2.5 obtained new functions by deforming a single function. This section explores another route: combining two functions. There are two ways of doing it, and it is worth distinguishing them from the start. The first, with addition, subtraction, multiplication and division, operates on the output values, and extends the algebra of \(\mathbb{R}\) from §1.1. The second, composition, operates on the process: it uses the output of one function as the input of the other, and it has, as we will see, a different nature.


§1. Arithmetic operations between functions

Given two functions \(f\) and \(g\), each operation of \(\mathbb{R}\) extends pointwise: at each \(x\) where both are defined, one operates with the numbers \(f(x)\) and \(g(x)\).

\[(f + g)(x) = f(x) + g(x) \qquad\qquad (f - g)(x) = f(x) - g(x)\]
\[(f \cdot g)(x) = f(x) \cdot g(x) \qquad\qquad \left(\frac{f}{g}\right)(x) = \frac{f(x)}{g(x)}\]

Each of these definitions requires \(f(x)\) and \(g(x)\) to exist at the same time: it makes no sense to add two values if one of them is not defined. That is why the domain of each operation is not declared separately, but deduced from that requirement:

\[\operatorname{Dom}(f \pm g) = \operatorname{Dom}(f \cdot g) = \operatorname{Dom}(f) \cap \operatorname{Dom}(g)\]

where \(\cap\) is the intersection of §1.1, the set of common elements. The quotient also requires, as in §2.2, that the denominator not vanish:

\[\operatorname{Dom}\left(\frac{f}{g}\right) = \big(\operatorname{Dom}(f) \cap \operatorname{Dom}(g)\big) \setminus \{x \mid g(x) = 0\}\]

Example. Let \(f(x) = \sqrt{x}\), with domain \([0, \infty)\) by §2.4, and \(g(x) = \dfrac{1}{x - 2}\), with domain \(\mathbb{R} \setminus \{2\}\) by §2.2. Then

\[\operatorname{Dom}(f + g) = [0, \infty) \setminus \{2\} = [0, 2) \cup (2, \infty)\]

The value \(x = 2\) is excluded not because some numerator vanishes, but because \(g\) is not defined there; the intersection of domains rules it out before the sum is formed.

The domain of a combination is decided by the domains of the parts, not by the simplified formula of the result. If \(f(x) = \sqrt{x}\) and \(g(x) = -\sqrt{x}\), the sum \(f + g\) equals \(0\) at each point, but its domain is \([0, \infty)\), not \(\mathbb{R}\): it is the zero function restricted to \([0, \infty)\), in the sense of §2.2, and not the zero function on \(\mathbb{R}\).

Reminder. Arithmetic operations between functions act pointwise on the values. The domain of the sum, the difference and the product is exactly the intersection of the domains, never the union, and that of the quotient also excludes the zeros of the divisor.



§2. Composition of functions

There is a way of combining two functions that is not arithmetic: using the output value of one as the input value of the other. This operation, the most important of the section and one of those Calculus uses most, is called composition.

Definition. Let \(f\) and \(g\) be two functions. The composition of \(g\) with \(f\), written \(g \circ f\) and read "\(g\) composed with \(f\)", is the function defined by

\[(g \circ f)(x) = g\big(f(x)\big)\]

for every \(x\) such that \(x \in \operatorname{Dom}(f)\) and, moreover, \(f(x) \in \operatorname{Dom}(g)\).

Let us note the order of the notation: in \(g \circ f\), \(f\), the function on the right, is applied first, and then \(g\). The second condition is the one that demands the most care. It is not enough for \(x\) to be in the domain of \(f\): in addition, the value that \(f\) produces at that point, and not \(x\) itself, must be admissible for \(g\). The domain of the composition is therefore

\[\operatorname{Dom}(g \circ f) = \{x \in \operatorname{Dom}(f) \mid f(x) \in \operatorname{Dom}(g)\}\]

By the form of this definition, \(\operatorname{Dom}(g \circ f) \subseteq \operatorname{Dom}(f)\): the composition never has a larger domain than that of \(f\), and it may have a smaller one.

Diagram of three sets A, B and C with arrows f and g; an element of A whose image under f falls outside Dom(g) is excluded and marked with a cross

Figure 2.4 — An element of \(A\) whose image under \(f\) falls outside \(\operatorname{Dom}(g)\) is excluded from \(\operatorname{Dom}(g\circ f)\), even though it belongs to \(\operatorname{Dom}(f)\).

Example. Let \(f(x) = x - 4\), with domain \(\mathbb{R}\), and \(g(x) = \sqrt{x}\), with domain \([0, \infty)\). Then \((g \circ f)(x) = \sqrt{x - 4}\), and its domain is not \(\mathbb{R}\), that of \(f\), but

\[\{x \in \mathbb{R} \mid x - 4 \in [0, \infty)\} = \{x \in \mathbb{R} \mid x - 4 \ge 0\} = [4, \infty)\]

It is the same result the analysis of §2.2 gives when applied to the formula \(\sqrt{x - 4}\), obtained here from the structure of the composition. That the two routes agree is no accident: it is what authorizes us to treat \(\sqrt{x - 4}\) as the composition of two simpler pieces.

Reminder. \((g \circ f)(x) = g(f(x))\) requires two conditions: \(x \in \operatorname{Dom}(f)\) and \(f(x) \in \operatorname{Dom}(g)\). In \(g \circ f\), \(f\) is applied first. The domain of \(g \circ f\) is never larger than that of \(f\).



§3. Associativity and lack of commutativity

Addition and multiplication of functions inherit from \(\mathbb{R}\) the commutativity of §1.1, because \(f(x) + g(x) = g(x) + f(x)\) at each point. Composition does not have this property: in general, \(g \circ f \neq f \circ g\), and the two compositions may differ in their values, in their domains, or one of them may not even be defined.

Example. With the functions of §2, \(f(x) = x - 4\) and \(g(x) = \sqrt{x}\), we already saw that \((g \circ f)(x) = \sqrt{x - 4}\), with domain \([4, \infty)\). On the other hand, \((f \circ g)(x) = f(\sqrt{x}) = \sqrt{x} - 4\), with domain \([0, \infty)\), that of \(g\), because \(f\) imposes no restrictions. The two compositions have different formulas and different domains. The first is never negative, whereas the second is: for example, \((f \circ g)(0) = -4\).

The asymmetry is not surprising if one thinks of composition as what it is: a chain process, where the order of the stages matters. Subtracting \(4\) and then taking the square root is not the same as taking the root and then subtracting \(4\), just as putting on socks and then shoes is not the same as doing it the other way around.

Composition does have another property of the operations of \(\mathbb{R}\): it is associative.

Proposition. If \(f\), \(g\) and \(h\) are functions, then \(h \circ (g \circ f) = (h \circ g) \circ f\).

Proof. Let us look at the domains first. A number \(x\) is in the domain of \(h \circ (g \circ f)\) if \(x \in \operatorname{Dom}(g \circ f)\) and \((g \circ f)(x) \in \operatorname{Dom}(h)\), that is, if \(x \in \operatorname{Dom}(f)\), \(f(x) \in \operatorname{Dom}(g)\) and \(g(f(x)) \in \operatorname{Dom}(h)\). On the other hand, \(x\) is in the domain of \((h \circ g) \circ f\) if \(x \in \operatorname{Dom}(f)\) and \(f(x) \in \operatorname{Dom}(h \circ g)\), that is, if \(x \in \operatorname{Dom}(f)\), \(f(x) \in \operatorname{Dom}(g)\) and \(g(f(x)) \in \operatorname{Dom}(h)\). They are the same three conditions, and the domains coincide. At each of those points, both functions equal \(h\big(g(f(x))\big)\). \(\blacksquare\)

Thanks to associativity we can write \(h \circ g \circ f\) without parentheses: either way of grouping it gives the same function, which applies \(f\), then \(g\) and finally \(h\).

Reminder. Composition is not commutative, \(g \circ f\) and \(f \circ g\) are in general different, but it is associative, and that is why \(h \circ g \circ f\) needs no parentheses.



§4. Decomposition into elementary functions

The relation between \(\sqrt{x - 4}\) and its two pieces, \(x - 4\) and \(\sqrt{x}\), suggests an operation inverse to composition: given a function built from several chained operations, identifying the pieces. This decomposition follows no single algorithm, but it does follow a principle of order: the outermost piece, which is the last operation one would apply when computing a value by hand, is the one written first, on the left, in the composition.

Example. Let \(h(x) = \dfrac{1}{(x + 1)^2}\). To compute \(h(x)\) by hand, the order of the operations is: add \(1\), square, and finally take the reciprocal. If \(p(x) = x + 1\), \(q(x) = x^2\) and \(r(x) = \frac{1}{x}\), the last two from the catalog of §2.4, then

\[h = r \circ q \circ p, \qquad \text{that is,} \qquad h(x) = r\big(q(p(x))\big)\]

The order of computation goes from the inside out, and the notation records it from the outside in. The domains also agree: \(p(x)\) is always in the domain of \(q\), and \(q(p(x)) = (x + 1)^2\) is in the domain of \(r\) if and only if it is nonzero, that is, if \(x \neq -1\), which is precisely the implicit domain of \(h\).

The decomposition is not unique. The square and the reciprocal could also be gathered into a single function, \(s(x) = \frac{1}{x^2}\), giving \(h = s \circ p\) with only two pieces. That lack of uniqueness is not a defect: different decompositions serve different purposes, and how finely to decompose depends on what one wants to do with \(h\).

Reminder. Decomposing is identifying the chained elementary functions. The piece that would be applied at the end of the computation is the one written first in the composition.



The operations of this section complete, in a sense, a toolkit for building functions: §2.5 showed how to deform one, and this section how to combine several. But the two ideas are closer than they seem. The transformations of §2.5 are particular compositions: \(c f\big(a(x - h)\big) + k\) is the composition of \(f\) with two functions of the form \(mx + n\), one applied before, \(x \mapsto a(x - h)\), and another after, \(y \mapsto cy + k\). Deforming a graph is composing with linear functions, and that is why it preserves the shape of the prototype. Composing with arbitrary functions, on the other hand, can produce an object whose behavior is no longer recognizable in any of its pieces: it is the construction of a new complexity from simple blocks, with no need for any symbol that did not already exist in them.

Among all the functions that can be built by composition, there is one case that deserves attention of its own: the one in which the composition can be undone, recovering the input from the output. That reversibility, and the inverse function that makes it possible, is the topic of the next section.