Chapter 5: Functions II: Operations and Composition
Chapter 4 introduced individual functions, their representations, and several common function classes. This chapter develops ways to build new functions from existing ones: first through arithmetic operations, then through composition, and finally by decomposing complex expressions into simpler inner and outer functions.
Combining Functions
Up to this point, we have explored the basic characteristics of individual functions. We now turn to what happens when functions are combined using standard mathematical operations to create new ones. Just as numbers can be added, subtracted, multiplied, or divided, functions can also be combined in similar ways to form new functions with related behaviors.
Suppose and are real-valued functions. The following operations define new functions:
Table 5.1. Standard arithmetic operations for combining two functions.
| Operation | Notation | Definition |
|---|---|---|
| Sum | ||
| Difference | ||
| Product | ||
| Quotient |
The sum, difference, and product have domain . The quotient has domain
These operations let us construct more complex relationships from simpler ones while preserving the input restrictions of the original functions.
In machine learning, the loss function used to train a model often combines several components that measure different aspects of performance.
Suppose we define:
- : The prediction error
- : A regularization term that penalizes overly complex models
Note that may represent several model parameters, but the idea of combining functions, i.e., adding terms that capture different effects, follows the same principle as in the single-variable case.
The resulting loss function balances accuracy (how well predictions match the observed data) with simplicity (how small the model parameters are):
where controls how strongly the regularization term influences the model.
In many real-world models, new relationships are created by combining existing quantities using arithmetic operations.
Suppose we define:
- : the temperature (in °C)
- : the humidity (in %)
A new function can be defined to estimate a heat index (a perceived temperature) as follows:
Here, is obtained by adding a weighted contribution from humidity to the temperature. Such combinations describe how different quantities together determine a result. In this case, both temperature and humidity contribute to the perceived heat.
In this example, we explore how subtraction and division affect the relationship between two functions. For this purpose, let
We will now find and simplify both and to see how these operations transform the expressions.
First, subtract from :
Then, divide by :
We can see that subtraction and division lead to very different results, i.e., is a quadratic expression, while agrees with the linear expression only on its domain . It is not the same function as on all of because its graph has a hole at .
Even though both start from the same and , the way we combine them changes the type of function we obtain.
In this example, we explore how multiplication and subtraction affect the relationship between two functions. For this purpose, let
We will now find and simplify both and to see how these operations transform the expressions.
First, multiply and :
Then, subtract from :
Again, the two resulting functions are very different, i.e., is cubic, while is quadratic.
Function Composition
In the previous examples, we combined functions using arithmetic operations such as addition and multiplication. We now explore a different kind of combination, called function composition, where the output of one function becomes the input of another.
Function composition allows us to describe multi-step relationships between quantities that depend on one another.
In many real-world situations, one variable influences a second, which in turn affects a third. By composing functions, we can express such a chain of dependencies as a single mathematical expression. Formally, composition means applying one function after another.
Let and be functions, so every output of is a valid input for . The composition of and , denoted , is the function
defined by
Suppose we want to calculate how much electricity is used to cool a house on a particular day of the year. The electricity usage depends on the average indoor-outdoor temperature difference, which in turn depends on the average daily temperature outside.
Thus, we have two relationships:
- : describes the electricity (in kWh) required to maintain a desired indoor temperature for a given outdoor temperature (°C)
- : describes the average outdoor temperature (°C) on day of the year
For any given day , the electricity use depends on the temperature, which itself depends on the day. We can therefore evaluate at the temperature given by :
This expression represents the electricity used on day . For example, to find the electricity usage on the 10th day of the year, we first compute and then use that value as the input to . Thus, gives the electricity required to cool the house on the 10th day of the year.
-
Composition is not multiplication:
The composition of two functions is denoted by and defined as
In contrast, the product of two functions is denoted by and defined as
The first applies one function inside another, while the second multiplies their outputs.
-
Composition need not be commutative:
In general, the two compositions may differ, or one of them may not be defined. Thus, we cannot assume that
Often,
In other words, the order matters because the output of one function becomes the input of the other. Some particular functions do commute, but this must be checked rather than assumed.
A quick calculation shows why the order of composition matters.
Using the following functions, find both and to determine whether composition is commutative.
First, substitute into :
Next, substitute into :
Because , we see that function composition is not commutative.
Decomposing Functions
The idea of composition naturally leads to its reverse process, i.e., decomposition. While composition builds complex relationships by applying one function after another, decomposition involves expressing a single, complicated function in terms of simpler ones:
This approach makes functions easier to understand and, more importantly, easier to work with. It will play an important role later, particularly in Chapter 10, where recognizing how a function is composed of simpler parts becomes essential for applying the chain rule of differentiation.
Note that a single function may have more than one possible decomposition. In practice, we choose the one that makes the problem easier.
To decompose a function as :
- Identify the expression that is evaluated first; this becomes the inner function .
- Identify the operation applied to that expression; this becomes the outer function .
- Check the decomposition by recomposing: verify that .
When decomposing a function, the goal is to identify an inner expression and an outer operation.
Express as the composition of two simpler functions.
We are looking for functions and such that
To identify these functions, notice that appears inside the square root. This suggests the inner function produces , and the outer function takes the square root of its input. Thus, we can define
We can verify our decomposition by recomposing the functions:
Therefore, with
The domain of is . On this domain, , so its outputs are valid inputs for the square-root function .
For a more nested expression, we use the same idea but may group a larger inner expression first.
Express as the composition of two simpler functions.
We are looking for functions and such that
Here, the expression appears inside the denominator. We can treat that as the output of the inner function , and then let the outer function operate on that result. Thus, we can define
We can verify our decomposition by recomposing the functions:
Therefore, with
The denominator is zero when , which occurs at . Therefore, the domain of is .