Skip to content

Chapter 2 — Functions

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 R\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

Section titled “§1. Arithmetic operations between functions”

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

(f+g)(x)=f(x)+g(x)(f−g)(x)=f(x)−g(x)(f + g)(x) = f(x) + g(x) \qquad\qquad (f - g)(x) = f(x) - g(x) (f⋅g)(x)=f(x)⋅g(x)(fg)(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)f(x) and g(x)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:

Dom⁡(f±g)=Dom⁡(f⋅g)=Dom⁡(f)∩Dom⁡(g)\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:

Dom⁡(fg)=(Dom⁡(f)∩Dom⁡(g))∖{x∣g(x)=0}\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)=xf(x) = \sqrt{x}, with domain [0,∞)[0, \infty) by §2.4, and g(x)=1x−2g(x) = \dfrac{1}{x - 2}, with domain R∖{2}\mathbb{R} \setminus \{2\} by §2.2. Then

Dom⁡(f+g)=[0,∞)∖{2}=[0,2)∪(2,∞)\operatorname{Dom}(f + g) = [0, \infty) \setminus \{2\} = [0, 2) \cup (2, \infty)

The value x=2x = 2 is excluded not because some numerator vanishes, but because gg 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)=xf(x) = \sqrt{x} and g(x)=−xg(x) = -\sqrt{x}, the sum f+gf + g equals 00 at each point, but its domain is [0,∞)[0, \infty), not R\mathbb{R}: it is the zero function restricted to [0,∞)[0, \infty), in the sense of §2.2, and not the zero function on R\mathbb{R}.


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 ff and gg be two functions. The composition of gg with ff, written g∘fg \circ f and read ”gg composed with ff”, is the function defined by

(g∘f)(x)=g(f(x))(g \circ f)(x) = g\big(f(x)\big)

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

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

Dom⁡(g∘f)={x∈Dom⁡(f)∣f(x)∈Dom⁡(g)}\operatorname{Dom}(g \circ f) = \{x \in \operatorname{Dom}(f) \mid f(x) \in \operatorname{Dom}(g)\}

By the form of this definition, Dom⁡(g∘f)⊆Dom⁡(f)\operatorname{Dom}(g \circ f) \subseteq \operatorname{Dom}(f): the composition never has a larger domain than that of ff, 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 AA whose image under ff falls outside Dom⁡(g)\operatorname{Dom}(g) is excluded from Dom⁡(g∘f)\operatorname{Dom}(g\circ f), even though it belongs to Dom⁡(f)\operatorname{Dom}(f).

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

{x∈R∣x−4∈[0,∞)}={x∈R∣x−4≥0}=[4,∞)\{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 x−4\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 x−4\sqrt{x - 4} as the composition of two simpler pieces.


§3. Associativity and lack of commutativity

Section titled “§3. Associativity and lack of commutativity”

Addition and multiplication of functions inherit from R\mathbb{R} the commutativity of §1.1, because f(x)+g(x)=g(x)+f(x)f(x) + g(x) = g(x) + f(x) at each point. Composition does not have this property: in general, g∘f≠f∘gg \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−4f(x) = x - 4 and g(x)=xg(x) = \sqrt{x}, we already saw that (g∘f)(x)=x−4(g \circ f)(x) = \sqrt{x - 4}, with domain [4,∞)[4, \infty). On the other hand, (f∘g)(x)=f(x)=x−4(f \circ g)(x) = f(\sqrt{x}) = \sqrt{x} - 4, with domain [0,∞)[0, \infty), that of gg, because ff imposes no restrictions. The two compositions have different formulas and different domains. The first is never negative, whereas the second is: for example, (f∘g)(0)=−4(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 44 and then taking the square root is not the same as taking the root and then subtracting 44, 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 R\mathbb{R}: it is associative.

Proposition. If ff, gg and hh are functions, then h∘(g∘f)=(h∘g)∘fh \circ (g \circ f) = (h \circ g) \circ f.

Proof. Let us look at the domains first. A number xx is in the domain of h∘(g∘f)h \circ (g \circ f) if x∈Dom⁡(g∘f)x \in \operatorname{Dom}(g \circ f) and (g∘f)(x)∈Dom⁡(h)(g \circ f)(x) \in \operatorname{Dom}(h), that is, if x∈Dom⁡(f)x \in \operatorname{Dom}(f), f(x)∈Dom⁡(g)f(x) \in \operatorname{Dom}(g) and g(f(x))∈Dom⁡(h)g(f(x)) \in \operatorname{Dom}(h). On the other hand, xx is in the domain of (h∘g)∘f(h \circ g) \circ f if x∈Dom⁡(f)x \in \operatorname{Dom}(f) and f(x)∈Dom⁡(h∘g)f(x) \in \operatorname{Dom}(h \circ g), that is, if x∈Dom⁡(f)x \in \operatorname{Dom}(f), f(x)∈Dom⁡(g)f(x) \in \operatorname{Dom}(g) and g(f(x))∈Dom⁡(h)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(g(f(x)))h\big(g(f(x))\big). ■\blacksquare

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


§4. Decomposition into elementary functions

Section titled “§4. Decomposition into elementary functions”

The relation between x−4\sqrt{x - 4} and its two pieces, x−4x - 4 and x\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)=1(x+1)2h(x) = \dfrac{1}{(x + 1)^2}. To compute h(x)h(x) by hand, the order of the operations is: add 11, square, and finally take the reciprocal. If p(x)=x+1p(x) = x + 1, q(x)=x2q(x) = x^2 and r(x)=1xr(x) = \frac{1}{x}, the last two from the catalog of §2.4, then

h=r∘q∘p,that is,h(x)=r(q(p(x)))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)p(x) is always in the domain of qq, and q(p(x))=(x+1)2q(p(x)) = (x + 1)^2 is in the domain of rr if and only if it is nonzero, that is, if x≠−1x \neq -1, which is precisely the implicit domain of hh.

The decomposition is not unique. The square and the reciprocal could also be gathered into a single function, s(x)=1x2s(x) = \frac{1}{x^2}, giving h=s∘ph = 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 hh.


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: cf(a(x−h))+kc f\big(a(x - h)\big) + k is the composition of ff with two functions of the form mx+nmx + n, one applied before, x↦a(x−h)x \mapsto a(x - h), and another after, y↦cy+ky \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.